@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
@@ -0,0 +1,114 @@
1
+ /*
2
+ * The keyframes a step change is built from. Each animates one property of its own (`opacity`,
3
+ * `translate` or `scale`, never `transform`), so a fade, a slide and a zoom on one snapshot run
4
+ * together. Which snapshot runs which, with what delay and duration, is written per change by
5
+ * `playStepTransition`.
6
+ */
7
+
8
+ @keyframes ob-course-fade-in {
9
+ from {
10
+ opacity: 0;
11
+ }
12
+ to {
13
+ opacity: 1;
14
+ }
15
+ }
16
+
17
+ @keyframes ob-course-fade-out {
18
+ from {
19
+ opacity: 1;
20
+ }
21
+ to {
22
+ opacity: 0;
23
+ }
24
+ }
25
+
26
+ @keyframes ob-course-scale-in {
27
+ from {
28
+ scale: 0.5;
29
+ }
30
+ to {
31
+ scale: 1;
32
+ }
33
+ }
34
+
35
+ @keyframes ob-course-scale-out {
36
+ from {
37
+ scale: 1;
38
+ }
39
+ to {
40
+ scale: 0.5;
41
+ }
42
+ }
43
+
44
+ @keyframes ob-course-slide-in-from-left {
45
+ from {
46
+ translate: -100% 0;
47
+ }
48
+ to {
49
+ translate: 0 0;
50
+ }
51
+ }
52
+
53
+ @keyframes ob-course-slide-in-from-right {
54
+ from {
55
+ translate: 100% 0;
56
+ }
57
+ to {
58
+ translate: 0 0;
59
+ }
60
+ }
61
+
62
+ @keyframes ob-course-slide-in-from-top {
63
+ from {
64
+ translate: 0 -100%;
65
+ }
66
+ to {
67
+ translate: 0 0;
68
+ }
69
+ }
70
+
71
+ @keyframes ob-course-slide-in-from-bottom {
72
+ from {
73
+ translate: 0 100%;
74
+ }
75
+ to {
76
+ translate: 0 0;
77
+ }
78
+ }
79
+
80
+ @keyframes ob-course-slide-out-to-left {
81
+ from {
82
+ translate: 0 0;
83
+ }
84
+ to {
85
+ translate: -100% 0;
86
+ }
87
+ }
88
+
89
+ @keyframes ob-course-slide-out-to-right {
90
+ from {
91
+ translate: 0 0;
92
+ }
93
+ to {
94
+ translate: 100% 0;
95
+ }
96
+ }
97
+
98
+ @keyframes ob-course-slide-out-to-top {
99
+ from {
100
+ translate: 0 0;
101
+ }
102
+ to {
103
+ translate: 0 -100%;
104
+ }
105
+ }
106
+
107
+ @keyframes ob-course-slide-out-to-bottom {
108
+ from {
109
+ translate: 0 0;
110
+ }
111
+ to {
112
+ translate: 0 100%;
113
+ }
114
+ }
@@ -0,0 +1,66 @@
1
+ import type { Step, StepTransition } from "../document/schema";
2
+ import type { PlayerCategory } from "../types";
3
+ export type TransitionDirection = "forward" | "backward";
4
+ export type TransitionSide = "old" | "new";
5
+ /** A step on one side of a change: its document, and the category band above it. */
6
+ export interface TransitionStep {
7
+ document: Step | null;
8
+ category?: PlayerCategory | null;
9
+ }
10
+ export type TransitionTarget = {
11
+ kind: "step";
12
+ } | {
13
+ kind: "content";
14
+ } | {
15
+ kind: "background";
16
+ } | {
17
+ kind: "header";
18
+ } | {
19
+ kind: "part";
20
+ id: string;
21
+ };
22
+ /** An element to name before its side of the change is captured. */
23
+ export interface NamedTarget {
24
+ side: TransitionSide;
25
+ target: TransitionTarget;
26
+ name: string;
27
+ }
28
+ export interface TransitionAnimation {
29
+ /** One of the keyframes in `Transitions.css`. */
30
+ keyframes: string;
31
+ delay: number;
32
+ duration: number;
33
+ /** `add` for movement and scale, so several items on one target move together. */
34
+ composition: "replace" | "add";
35
+ }
36
+ /** What one snapshot does: animate, vanish at once (`hidden`) or stand still (`shown`). */
37
+ export interface SnapshotRule {
38
+ pseudo: TransitionSide;
39
+ name: string;
40
+ animations: TransitionAnimation[] | "hidden" | "shown";
41
+ }
42
+ export interface TransitionPlan {
43
+ names: NamedTarget[];
44
+ rules: SnapshotRule[];
45
+ /** Milliseconds until the last animation ends. 0 means there is nothing to animate. */
46
+ duration: number;
47
+ css: string;
48
+ }
49
+ export declare const DEFAULT_TRANSITION_DURATION = 300;
50
+ /** A cross-fade of the step: what a step without `transitions` does. */
51
+ export declare const DEFAULT_TRANSITIONS: readonly StepTransition[];
52
+ export declare const STEP_NAME = "ob-course-step";
53
+ export declare const HEADER_NAME = "ob-course-category";
54
+ /** The transitions a step runs: its own list, or the cross-fade when it has none. */
55
+ export declare function getStepTransitions(step: Step | null | undefined): readonly StepTransition[];
56
+ /** The keyframes of one item. Zoom is two animations, so its fade and its scale combine with others. */
57
+ export declare function getAnimations(transition: StepTransition, direction: TransitionDirection): TransitionAnimation[];
58
+ /**
59
+ * Plans a change from `from` to `to`. Either side may be missing: the outgoing step's `exit` items
60
+ * and the incoming step's `enter` items run, and what has no item changes at once.
61
+ */
62
+ export declare function planStepTransition({ from, to, direction, }: {
63
+ from?: TransitionStep | null;
64
+ to?: TransitionStep | null;
65
+ direction?: TransitionDirection;
66
+ }): TransitionPlan;
@@ -0,0 +1,185 @@
1
+ /*
2
+ * Turns a change of step into what a view transition needs: which elements get a
3
+ * `view-transition-name` on each side of the change, and the animations of their snapshots.
4
+ * Pure, so the rules can be tested without a browser; `playStepTransition` applies them.
5
+ */
6
+ export const DEFAULT_TRANSITION_DURATION = 300;
7
+ /** A cross-fade of the step: what a step without `transitions` does. */
8
+ export const DEFAULT_TRANSITIONS = [
9
+ { on: "exit", effect: "fade" },
10
+ { on: "enter", effect: "fade" },
11
+ ];
12
+ export const STEP_NAME = "ob-course-step";
13
+ export const HEADER_NAME = "ob-course-category";
14
+ /** The transitions a step runs: its own list, or the cross-fade when it has none. */
15
+ export function getStepTransitions(step) {
16
+ return step?.transitions ?? DEFAULT_TRANSITIONS;
17
+ }
18
+ function targetKey(transition) {
19
+ return transition.target ?? "step";
20
+ }
21
+ function toTarget(key) {
22
+ if (key === "step" || key === "content" || key === "background")
23
+ return { kind: key };
24
+ return { kind: "part", id: key };
25
+ }
26
+ /** A part id as the tail of a CSS identifier; the counter in front keeps names unique. */
27
+ function sanitize(id) {
28
+ return id.replace(/[^a-zA-Z0-9_-]/g, "_");
29
+ }
30
+ function mirror(edge, direction) {
31
+ if (direction === "forward")
32
+ return edge;
33
+ if (edge === "left")
34
+ return "right";
35
+ if (edge === "right")
36
+ return "left";
37
+ return edge;
38
+ }
39
+ /** The keyframes of one item. Zoom is two animations, so its fade and its scale combine with others. */
40
+ export function getAnimations(transition, direction) {
41
+ let way = transition.on === "enter" ? "in" : "out";
42
+ let delay = transition.delay ?? 0;
43
+ let duration = transition.duration ?? DEFAULT_TRANSITION_DURATION;
44
+ switch (transition.effect) {
45
+ case "fade":
46
+ return [{ keyframes: `ob-course-fade-${way}`, delay, duration, composition: "replace" }];
47
+ case "zoom":
48
+ return [
49
+ { keyframes: `ob-course-scale-${way}`, delay, duration, composition: "add" },
50
+ { keyframes: `ob-course-fade-${way}`, delay, duration, composition: "replace" },
51
+ ];
52
+ case "slide": {
53
+ let edge = mirror(transition.from ?? (transition.on === "enter" ? "right" : "left"), direction);
54
+ let keyframes = transition.on === "enter" ? `ob-course-slide-in-from-${edge}` : `ob-course-slide-out-to-${edge}`;
55
+ return [{ keyframes, delay, duration, composition: "add" }];
56
+ }
57
+ case "none":
58
+ // A jump at the delay: hidden until then on enter, there until then on exit
59
+ return [{ keyframes: `ob-course-fade-${way}`, delay, duration: 0, composition: "replace" }];
60
+ }
61
+ }
62
+ function sameCategory(a, b) {
63
+ return a != null && b != null && a.title === b.title && (a.subTitle ?? "") === (b.subTitle ?? "");
64
+ }
65
+ /**
66
+ * The band stays put between steps of one category. Into another category the old band slides out
67
+ * and the new one in, sideways in the direction of travel; a band with nothing on the other side
68
+ * comes in from or leaves to the top.
69
+ */
70
+ function headerRules(from, to, direction) {
71
+ let oldBand = from?.category ?? null;
72
+ let newBand = to?.category ?? null;
73
+ let names = [];
74
+ let rules = [];
75
+ if (oldBand)
76
+ names.push({ side: "old", target: { kind: "header" }, name: HEADER_NAME });
77
+ if (newBand)
78
+ names.push({ side: "new", target: { kind: "header" }, name: HEADER_NAME });
79
+ if (sameCategory(oldBand, newBand)) {
80
+ rules.push({ pseudo: "old", name: HEADER_NAME, animations: "hidden" });
81
+ rules.push({ pseudo: "new", name: HEADER_NAME, animations: "shown" });
82
+ return { names, rules };
83
+ }
84
+ let both = oldBand != null && newBand != null;
85
+ let slide = (on) => getAnimations({ on, effect: "slide", from: both ? undefined : "top" }, both ? direction : "forward");
86
+ if (oldBand)
87
+ rules.push({ pseudo: "old", name: HEADER_NAME, animations: slide("exit") });
88
+ if (newBand)
89
+ rules.push({ pseudo: "new", name: HEADER_NAME, animations: slide("enter") });
90
+ return { names, rules };
91
+ }
92
+ /** The names and rules of one side's own transitions. */
93
+ function sideRules(step, side, direction) {
94
+ let on = side === "old" ? "exit" : "enter";
95
+ let prefix = side === "old" ? "ob-course-exit" : "ob-course-enter";
96
+ let items = getStepTransitions(step.document).filter((transition) => transition.on === on);
97
+ let byTarget = new Map();
98
+ for (let item of items) {
99
+ let key = targetKey(item);
100
+ byTarget.set(key, [...(byTarget.get(key) ?? []), item]);
101
+ }
102
+ let names = [{ side, target: { kind: "step" }, name: STEP_NAME }];
103
+ let rules = [];
104
+ let count = 0;
105
+ for (let [key, list] of byTarget) {
106
+ let name = STEP_NAME;
107
+ if (key !== "step") {
108
+ let target = toTarget(key);
109
+ name = target.kind === "part" ? `${prefix}-${count++}-${sanitize(target.id)}` : `${prefix}-${key}`;
110
+ names.push({ side, target, name });
111
+ }
112
+ // The animation that ends last is listed last, so it decides a property both animate
113
+ let animations = list
114
+ .flatMap((item) => getAnimations(item, direction))
115
+ .sort((a, b) => a.delay + a.duration - (b.delay + b.duration));
116
+ rules.push({ pseudo: side, name, animations });
117
+ }
118
+ // Without an item of its own the step box changes at once, around whatever does animate
119
+ if (!byTarget.has("step"))
120
+ rules.push({ pseudo: side, name: STEP_NAME, animations: side === "old" ? "hidden" : "shown" });
121
+ return { names, rules };
122
+ }
123
+ /**
124
+ * Plans a change from `from` to `to`. Either side may be missing: the outgoing step's `exit` items
125
+ * and the incoming step's `enter` items run, and what has no item changes at once.
126
+ */
127
+ export function planStepTransition({ from, to, direction = "forward", }) {
128
+ let names = [];
129
+ let rules = [];
130
+ for (let [step, side] of [
131
+ [from, "old"],
132
+ [to, "new"],
133
+ ]) {
134
+ if (!step)
135
+ continue;
136
+ let result = sideRules(step, side, direction);
137
+ names.push(...result.names);
138
+ rules.push(...result.rules);
139
+ }
140
+ let header = headerRules(from ?? null, to ?? null, direction);
141
+ names.push(...header.names);
142
+ rules.push(...header.rules);
143
+ let duration = 0;
144
+ for (let rule of rules) {
145
+ if (typeof rule.animations === "string")
146
+ continue;
147
+ for (let animation of rule.animations)
148
+ duration = Math.max(duration, animation.delay + animation.duration);
149
+ }
150
+ return { names, rules, duration, css: toCss(rules) };
151
+ }
152
+ function snapshotCss(rule) {
153
+ let selector = `::view-transition-${rule.pseudo}(${rule.name})`;
154
+ if (rule.animations === "hidden")
155
+ return `${selector} { animation: none; opacity: 0; }`;
156
+ if (rule.animations === "shown")
157
+ return `${selector} { animation: none; opacity: 1; mix-blend-mode: normal; }`;
158
+ let list = rule.animations;
159
+ let join = (values) => values.join(", ");
160
+ return [
161
+ `${selector} {`,
162
+ `\tanimation-name: ${join(list.map((a) => a.keyframes))};`,
163
+ `\tanimation-duration: ${join(list.map((a) => `${a.duration}ms`))};`,
164
+ `\tanimation-delay: ${join(list.map((a) => `${a.delay}ms`))};`,
165
+ `\tanimation-timing-function: ease;`,
166
+ `\tanimation-fill-mode: both;`,
167
+ `\tanimation-composition: ${join(list.map((a) => a.composition))};`,
168
+ // Not the cross-fade blend: the effects of one side need not add up with the other's
169
+ `\tmix-blend-mode: normal;`,
170
+ `}`,
171
+ ].join("\n");
172
+ }
173
+ /**
174
+ * The stylesheet of one change. Groups do not move or resize, since every target stays in its
175
+ * place, and the rest of the page changes at once.
176
+ */
177
+ function toCss(rules) {
178
+ let groups = [...new Set(rules.map((rule) => rule.name))];
179
+ return [
180
+ "::view-transition-old(root) { animation: none; opacity: 0; }",
181
+ "::view-transition-new(root) { animation: none; mix-blend-mode: normal; }",
182
+ ...groups.map((name) => `::view-transition-group(${name}) { animation: none; }`),
183
+ ...rules.map(snapshotCss),
184
+ ].join("\n");
185
+ }
@@ -0,0 +1,23 @@
1
+ import "./Transitions.css";
2
+ import type { Step } from "../document/schema";
3
+ import { type TransitionDirection, type TransitionStep } from "./plan";
4
+ export interface StepTransitionOptions {
5
+ /** The step's box (`.ob-course-step`) or an element around it. Only elements inside it are named. */
6
+ scope: Element | null | undefined;
7
+ /** The step that leaves; its `exit` transitions run. Left out, nothing leaves. */
8
+ from?: TransitionStep | Step | null;
9
+ /** The step that comes; its `enter` transitions run. Left out, nothing comes. */
10
+ to?: TransitionStep | Step | null;
11
+ direction?: TransitionDirection;
12
+ }
13
+ /**
14
+ * Runs `run`, the change of step, inside a view transition: the outgoing step's `exit`
15
+ * transitions animate what it showed, the incoming step's `enter` transitions what it shows, and
16
+ * the category band stays or slides. Names are set on the elements inside `scope` only for as
17
+ * long as the transition runs, so other steps on the page (an editor's previews) are never part
18
+ * of it. A transition still running is skipped first. Without the API, or when the learner
19
+ * prefers reduced motion, `run` is called at once.
20
+ *
21
+ * Resolves when the transition has finished.
22
+ */
23
+ export declare function playStepTransition(run: () => void, options: StepTransitionOptions): Promise<void>;
@@ -0,0 +1,131 @@
1
+ import "./Transitions.css";
2
+ import { flushSync } from "react-dom";
3
+ import { planStepTransition, } from "./plan";
4
+ /** One view transition runs at a time in a document, so one is tracked for the whole module. */
5
+ let running = null;
6
+ function noop() { }
7
+ function toStep(step) {
8
+ if (step == null)
9
+ return null;
10
+ return "document" in step ? step : { document: step };
11
+ }
12
+ function canAnimate() {
13
+ if (typeof document === "undefined" || typeof document.startViewTransition !== "function")
14
+ return false;
15
+ return !(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
16
+ }
17
+ function findBox(scope) {
18
+ if (!scope)
19
+ return null;
20
+ return scope.matches(".ob-course-step") ? scope : scope.querySelector(".ob-course-step");
21
+ }
22
+ function findTarget(box, target) {
23
+ let element;
24
+ switch (target.kind) {
25
+ case "step":
26
+ element = box;
27
+ break;
28
+ case "header":
29
+ element = box.querySelector(".ob-course-category-header");
30
+ break;
31
+ case "content":
32
+ element = box.querySelector(".ob-course-slide__content");
33
+ break;
34
+ case "background":
35
+ element = box.querySelector(".ob-course-slide__background, .ob-course-banner");
36
+ break;
37
+ case "part":
38
+ element = box.querySelector(`[data-part="${CSS.escape(target.id)}"]`);
39
+ // A part waiting for its cue or its press of Next, or fading out, is not on show: nothing to animate
40
+ if (element?.closest(".is-pending, .is-leaving"))
41
+ element = null;
42
+ break;
43
+ }
44
+ return element instanceof HTMLElement ? element : null;
45
+ }
46
+ /**
47
+ * Runs `run`, the change of step, inside a view transition: the outgoing step's `exit`
48
+ * transitions animate what it showed, the incoming step's `enter` transitions what it shows, and
49
+ * the category band stays or slides. Names are set on the elements inside `scope` only for as
50
+ * long as the transition runs, so other steps on the page (an editor's previews) are never part
51
+ * of it. A transition still running is skipped first. Without the API, or when the learner
52
+ * prefers reduced motion, `run` is called at once.
53
+ *
54
+ * Resolves when the transition has finished.
55
+ */
56
+ export function playStepTransition(run, options) {
57
+ if (!canAnimate()) {
58
+ run();
59
+ return Promise.resolve();
60
+ }
61
+ if (running) {
62
+ let previous = running;
63
+ running = null;
64
+ previous.transition.skipTransition();
65
+ // The change it was making must be in the page before this one names what is there
66
+ let start = () => {
67
+ previous.cleanup();
68
+ return startTransition(run, options);
69
+ };
70
+ return previous.transition.updateCallbackDone.then(start, start);
71
+ }
72
+ return startTransition(run, options);
73
+ }
74
+ function startTransition(run, { scope, from, to, direction = "forward" }) {
75
+ let plan = planStepTransition({ from: toStep(from), to: toStep(to), direction });
76
+ if (plan.duration === 0 || !findBox(scope)) {
77
+ run();
78
+ return Promise.resolve();
79
+ }
80
+ let style = document.createElement("style");
81
+ style.dataset.obCourseTransition = "";
82
+ style.textContent = plan.css;
83
+ document.head.append(style);
84
+ let named = [];
85
+ let name = (side) => {
86
+ let box = findBox(scope);
87
+ if (!box)
88
+ return;
89
+ for (let target of plan.names.filter((item) => item.side === side)) {
90
+ let element = findTarget(box, target.target);
91
+ if (!element)
92
+ continue;
93
+ element.style.setProperty("view-transition-name", target.name);
94
+ named.push(element);
95
+ }
96
+ };
97
+ let unname = () => {
98
+ for (let element of named)
99
+ element.style.removeProperty("view-transition-name");
100
+ named = [];
101
+ };
102
+ let entry;
103
+ let cleaned = false;
104
+ let skip = () => entry.transition.skipTransition();
105
+ let cleanup = () => {
106
+ if (cleaned)
107
+ return;
108
+ cleaned = true;
109
+ unname();
110
+ style.remove();
111
+ document.documentElement.removeEventListener("pointerdown", skip);
112
+ if (running === entry)
113
+ running = null;
114
+ };
115
+ name("old");
116
+ let transition = document.startViewTransition(() => {
117
+ if (running !== entry) {
118
+ // Skipped for a newer change before it got here: only the change itself is still owed
119
+ flushSync(run);
120
+ return;
121
+ }
122
+ unname();
123
+ flushSync(run);
124
+ name("new");
125
+ });
126
+ entry = { transition, cleanup };
127
+ running = entry;
128
+ // The page takes no clicks while a transition runs, so a click ends it instead
129
+ document.documentElement.addEventListener("pointerdown", skip);
130
+ return transition.finished.then(cleanup, cleanup).then(noop);
131
+ }
package/es/types.d.ts CHANGED
@@ -5,8 +5,10 @@ export interface PlayerLanguage {
5
5
  }
6
6
  export interface PlayerCourse {
7
7
  title: string;
8
- /** The learner's language. `null` until the learner has chosen one. */
8
+ /** The learner's language. `null` for the main language, and until the learner has chosen one. */
9
9
  cultureId: string | null;
10
+ /** The course's main language: the one a learner without a stored language takes the course in. */
11
+ mainCultureId?: string | null;
10
12
  /** The languages the course can be taken in. */
11
13
  languages: PlayerLanguage[];
12
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olenbetong/synergi-course",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Course player: steps described as content, shown responsively",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,7 +20,7 @@
20
20
  "author": "Bjørnar Vister Hansen",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@olenbetong/appframe-core": "^2.16.1",
23
+ "@olenbetong/appframe-core": "^2.16.2",
24
24
  "@valibot/to-json-schema": "^1.8.0",
25
25
  "@vimeo/player": "^2.30.4",
26
26
  "clsx": "^2.1.1",
@@ -53,8 +53,8 @@
53
53
  },
54
54
  "scripts": {
55
55
  "dev": "vite",
56
- "build": "pnpm run build:tsc && pnpm test && pnpm run build:css",
57
- "build:tsc": "node --no-warnings ../../scripts/clean.ts ./es ./dist && tsc -p tsconfig.build.json",
56
+ "build": "pnpm run build:tsc && pnpm run build:css && pnpm test",
57
+ "build:tsc": "node --no-warnings ../../scripts/clean.ts ./dist && tsc -p tsconfig.build.json && node --no-warnings ../../scripts/prune-output.ts ./es ./src",
58
58
  "build:css": "node scripts/copyAssets.mjs",
59
59
  "lint": "oxlint .",
60
60
  "format": "oxfmt . && oxlint --fix .",
@@ -92,3 +92,31 @@
92
92
  display: none;
93
93
  }
94
94
  }
95
+
96
+ /* On a phone on its side the band is one slim line: the subtitle goes beside the title. */
97
+ @media (orientation: landscape) and (max-height: 500px) {
98
+ .ob-course-category-header {
99
+ padding-block: 0.2rem;
100
+ font-size: 0.75rem;
101
+ }
102
+
103
+ .ob-course-category-header__titles {
104
+ display: flex;
105
+ flex-wrap: wrap;
106
+ align-items: baseline;
107
+ column-gap: 0.75em;
108
+ }
109
+
110
+ .ob-course-category-header__title {
111
+ font-size: 1.15em;
112
+ }
113
+
114
+ .ob-course-category-header__image {
115
+ width: 1.75em;
116
+ height: 1.75em;
117
+ }
118
+
119
+ .ob-course-category-header__logo {
120
+ max-height: 1.75em;
121
+ }
122
+ }
@@ -0,0 +1,53 @@
1
+ .ob-course-completion {
2
+ display: grid;
3
+ place-items: center;
4
+ height: 100%;
5
+ padding: var(--ds-size-6) var(--ds-size-4);
6
+ overflow: auto;
7
+ }
8
+
9
+ .ob-course-completion__panel {
10
+ display: flex;
11
+ flex-direction: column;
12
+ align-items: center;
13
+ gap: var(--ds-size-6);
14
+ width: min(100%, 44rem);
15
+ text-align: center;
16
+ font-size: 1.25rem;
17
+ }
18
+
19
+ .ob-course-completion__actions {
20
+ display: flex;
21
+ flex-wrap: wrap;
22
+ justify-content: center;
23
+ gap: var(--ds-size-3);
24
+ }
25
+
26
+ /*
27
+ * The course's own completion text, written for the old full-page completion article. Keep it inside the
28
+ * panel: the old texts lift themselves with negative top margins and rely on Bootstrap's text-center.
29
+ */
30
+ .ob-course-completion__text {
31
+ overflow-wrap: anywhere;
32
+
33
+ & > * {
34
+ margin-block-start: 0 !important;
35
+ }
36
+
37
+ & :where(p) {
38
+ margin-block: 0 var(--ds-size-3);
39
+ }
40
+
41
+ & :where(img, video) {
42
+ max-width: 100%;
43
+ height: auto;
44
+ }
45
+
46
+ & :where(a) {
47
+ color: var(--ds-color-brand-text-subtle);
48
+ }
49
+
50
+ & :where(.text-center) {
51
+ text-align: center;
52
+ }
53
+ }