@olenbetong/synergi-course 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) 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 +117 -14
  7. package/es/document/effects.d.ts +30 -0
  8. package/es/document/effects.js +76 -0
  9. package/es/document/schema.d.ts +2722 -346
  10. package/es/document/schema.js +172 -5
  11. package/es/document/validate.d.ts +2 -1
  12. package/es/document/validate.js +83 -16
  13. package/es/index.d.ts +8 -3
  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 +76 -0
  19. package/es/player/CoursePlayer.js +28 -13
  20. package/es/player/PlayerBars.d.ts +32 -0
  21. package/es/player/PlayerBars.js +14 -0
  22. package/es/player/useFullScreen.d.ts +17 -0
  23. package/es/player/useFullScreen.js +83 -0
  24. package/es/player/useMediaQuery.d.ts +7 -0
  25. package/es/player/useMediaQuery.js +16 -0
  26. package/es/steps/Blocks.d.ts +43 -3
  27. package/es/steps/Blocks.js +114 -26
  28. package/es/steps/Markdown.d.ts +7 -1
  29. package/es/steps/Markdown.js +31 -4
  30. package/es/steps/QuizStepView.d.ts +2 -1
  31. package/es/steps/QuizStepView.js +20 -10
  32. package/es/steps/RevealMotion.d.ts +29 -0
  33. package/es/steps/RevealMotion.js +55 -0
  34. package/es/steps/SlideStepView.d.ts +5 -3
  35. package/es/steps/SlideStepView.js +43 -10
  36. package/es/steps/StepBodyProps.d.ts +16 -1
  37. package/es/steps/StepView.css +390 -16
  38. package/es/steps/StepView.d.ts +36 -4
  39. package/es/steps/StepView.js +21 -5
  40. package/es/steps/motion.d.ts +59 -0
  41. package/es/steps/motion.js +136 -0
  42. package/es/transitions/Transitions.css +114 -0
  43. package/es/transitions/plan.d.ts +66 -0
  44. package/es/transitions/plan.js +185 -0
  45. package/es/transitions/playStepTransition.d.ts +23 -0
  46. package/es/transitions/playStepTransition.js +131 -0
  47. package/es/types.d.ts +16 -3
  48. package/package.json +4 -4
  49. package/src/chrome/CategoryHeader.css +28 -0
  50. package/src/completion/CourseCompletion.css +53 -0
  51. package/src/completion/CourseCompletion.test.tsx +45 -0
  52. package/src/completion/CourseCompletion.tsx +98 -0
  53. package/src/document/box.test.ts +234 -0
  54. package/src/document/cues.ts +143 -13
  55. package/src/document/document.test.ts +1 -1
  56. package/src/document/effects.ts +106 -0
  57. package/src/document/reveal.test.ts +263 -0
  58. package/src/document/schema.ts +203 -5
  59. package/src/document/validate.ts +88 -18
  60. package/src/index.ts +46 -1
  61. package/src/media/Media.css +16 -0
  62. package/src/media/icons.tsx +8 -0
  63. package/src/player/CoursePlayer.css +76 -0
  64. package/src/player/CoursePlayer.test.tsx +70 -6
  65. package/src/player/CoursePlayer.tsx +91 -60
  66. package/src/player/PlayerBars.tsx +106 -0
  67. package/src/player/fullScreen.test.tsx +70 -0
  68. package/src/player/useFullScreen.ts +91 -0
  69. package/src/player/useMediaQuery.ts +21 -0
  70. package/src/steps/Blocks.test.ts +34 -0
  71. package/src/steps/Blocks.tsx +219 -32
  72. package/src/steps/Box.test.tsx +95 -0
  73. package/src/steps/Markdown.test.tsx +46 -0
  74. package/src/steps/Markdown.tsx +42 -4
  75. package/src/steps/Presence.test.tsx +82 -0
  76. package/src/steps/QuizStepView.test.tsx +79 -0
  77. package/src/steps/QuizStepView.tsx +34 -12
  78. package/src/steps/RevealMotion.ts +66 -0
  79. package/src/steps/SlideStepView.tsx +74 -12
  80. package/src/steps/StepBodyProps.ts +16 -1
  81. package/src/steps/StepView.css +390 -16
  82. package/src/steps/StepView.test.tsx +157 -0
  83. package/src/steps/StepView.tsx +108 -19
  84. package/src/steps/motion.test.ts +98 -0
  85. package/src/steps/motion.ts +178 -0
  86. package/src/steps/visibility.test.ts +24 -0
  87. package/src/transitions/Transitions.css +114 -0
  88. package/src/transitions/plan.ts +258 -0
  89. package/src/transitions/playStepTransition.ts +162 -0
  90. package/src/transitions/transitions.test.ts +274 -0
  91. package/src/types.ts +16 -3
  92. package/es/Transitions.css +0 -55
  93. package/es/Transitions.d.ts +0 -10
  94. package/es/Transitions.js +0 -24
  95. package/src/Transitions.css +0 -55
  96. package/src/Transitions.ts +0 -35
@@ -0,0 +1,274 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { SlideStep, Step, StepTransition } from "../document/schema";
3
+ import { validateStep } from "../document/validate";
4
+ import { getAnimations, getStepTransitions, planStepTransition, type SnapshotRule, type TransitionStep } from "./plan";
5
+
6
+ let slide = (transitions?: StepTransition[]): SlideStep => ({
7
+ schemaVersion: 2,
8
+ type: "slide",
9
+ background: "/media/course/bg.jpg",
10
+ blocks: [
11
+ { id: "h", type: "heading", text: "Tittel" },
12
+ { id: "l", type: "list", items: [{ id: "i 1", text: "Punkt" }] },
13
+ {
14
+ id: "cols",
15
+ type: "columns",
16
+ columns: [
17
+ { id: "left", blocks: [] },
18
+ { id: "right", blocks: [] },
19
+ ],
20
+ },
21
+ ],
22
+ ...(transitions ? { transitions } : {}),
23
+ });
24
+
25
+ let video: Step = { schemaVersion: 2, type: "video", media: { src: "/media/course/a.mp4" } };
26
+
27
+ function issuesOf(input: unknown) {
28
+ let result = validateStep(input);
29
+ return result.ok ? [] : result.issues;
30
+ }
31
+
32
+ function rule(rules: SnapshotRule[], pseudo: "old" | "new", name: string) {
33
+ return rules.find((item) => item.pseudo === pseudo && item.name === name)?.animations;
34
+ }
35
+
36
+ describe("the transitions field", () => {
37
+ it("is accepted on every step type", () => {
38
+ let transitions: StepTransition[] = [{ on: "enter", effect: "fade", delay: 100, duration: 500 }];
39
+ expect(issuesOf(slide(transitions))).toEqual([]);
40
+ expect(issuesOf({ ...video, transitions })).toEqual([]);
41
+ expect(issuesOf({ schemaVersion: 2, type: "pdf", file: "resource:1", confirm: "Ok", transitions })).toEqual([]);
42
+ expect(issuesOf({ schemaVersion: 2, type: "quiz", transitions: [] })).toEqual([]);
43
+ });
44
+
45
+ it("refuses an unknown effect, side or direction, and times out of range", () => {
46
+ expect(issuesOf(slide([{ on: "enter", effect: "spin" } as never]))).not.toEqual([]);
47
+ expect(issuesOf(slide([{ on: "during", effect: "fade" } as never]))).not.toEqual([]);
48
+ expect(issuesOf(slide([{ effect: "fade" } as never]))).not.toEqual([]);
49
+ expect(issuesOf(slide([{ on: "enter", effect: "slide", from: "up" } as never]))).not.toEqual([]);
50
+ expect(issuesOf(slide([{ on: "enter", effect: "fade", delay: 5001 }]))).not.toEqual([]);
51
+ expect(issuesOf(slide([{ on: "enter", effect: "fade", delay: -1 }]))).not.toEqual([]);
52
+ expect(issuesOf(slide([{ on: "enter", effect: "fade", duration: 40 }]))).not.toEqual([]);
53
+ expect(issuesOf(slide([{ on: "enter", effect: "fade", duration: 3001 }]))).not.toEqual([]);
54
+ expect(issuesOf(slide([{ on: "enter", effect: "fade", speed: 2 } as never]))).not.toEqual([]);
55
+ });
56
+
57
+ it("checks that a target is on the step", () => {
58
+ expect(
59
+ issuesOf(
60
+ slide([
61
+ { on: "enter", effect: "zoom", target: "h" },
62
+ { on: "enter", effect: "fade", target: "i 1" },
63
+ { on: "exit", effect: "fade", target: "left" },
64
+ { on: "enter", effect: "slide", target: "content", from: "bottom" },
65
+ { on: "exit", effect: "fade", target: "background" },
66
+ { on: "exit", effect: "fade", target: "step" },
67
+ ]),
68
+ ),
69
+ ).toEqual([]);
70
+
71
+ expect(issuesOf(slide([{ on: "enter", effect: "zoom", target: "missing" }]))).toEqual([
72
+ { path: "transitions.0.target", message: 'There is no part with the id "missing".' },
73
+ ]);
74
+ expect(issuesOf({ ...video, transitions: [{ on: "enter", effect: "fade", target: "content" }] })).toEqual([
75
+ { path: "transitions.0.target", message: 'Only a slide has a "content" to animate.' },
76
+ ]);
77
+ expect(issuesOf(slide([{ on: "enter", effect: "fade", from: "left" }]))).toEqual([
78
+ { path: "transitions.0.from", message: 'Only the "slide" effect has a direction.' },
79
+ ]);
80
+ });
81
+ });
82
+
83
+ describe("getAnimations", () => {
84
+ it("slides in from the right and out to the left, mirrored going back", () => {
85
+ expect(getAnimations({ on: "enter", effect: "slide" }, "forward")[0].keyframes).toBe(
86
+ "ob-course-slide-in-from-right",
87
+ );
88
+ expect(getAnimations({ on: "exit", effect: "slide" }, "forward")[0].keyframes).toBe("ob-course-slide-out-to-left");
89
+ expect(getAnimations({ on: "enter", effect: "slide" }, "backward")[0].keyframes).toBe(
90
+ "ob-course-slide-in-from-left",
91
+ );
92
+ expect(getAnimations({ on: "exit", effect: "slide" }, "backward")[0].keyframes).toBe(
93
+ "ob-course-slide-out-to-right",
94
+ );
95
+ expect(getAnimations({ on: "enter", effect: "slide", from: "left" }, "backward")[0].keyframes).toBe(
96
+ "ob-course-slide-in-from-right",
97
+ );
98
+ expect(getAnimations({ on: "enter", effect: "slide", from: "top" }, "backward")[0].keyframes).toBe(
99
+ "ob-course-slide-in-from-top",
100
+ );
101
+ });
102
+
103
+ it("zooms with a scale that adds up and a fade, and jumps for none", () => {
104
+ expect(getAnimations({ on: "enter", effect: "zoom", delay: 400 }, "forward")).toEqual([
105
+ { keyframes: "ob-course-scale-in", delay: 400, duration: 300, composition: "add" },
106
+ { keyframes: "ob-course-fade-in", delay: 400, duration: 300, composition: "replace" },
107
+ ]);
108
+ expect(getAnimations({ on: "exit", effect: "none", delay: 200, duration: 900 }, "forward")).toEqual([
109
+ { keyframes: "ob-course-fade-out", delay: 200, duration: 0, composition: "replace" },
110
+ ]);
111
+ });
112
+ });
113
+
114
+ describe("planStepTransition", () => {
115
+ let from: TransitionStep = { document: slide() };
116
+ let to: TransitionStep = { document: slide() };
117
+
118
+ it("cross-fades the step by default", () => {
119
+ expect(getStepTransitions(slide())).toHaveLength(2);
120
+ expect(getStepTransitions(null)).toHaveLength(2);
121
+
122
+ let plan = planStepTransition({ from, to });
123
+ expect(plan.names).toEqual([
124
+ { side: "old", target: { kind: "step" }, name: "ob-course-step" },
125
+ { side: "new", target: { kind: "step" }, name: "ob-course-step" },
126
+ ]);
127
+ expect(rule(plan.rules, "old", "ob-course-step")).toEqual([
128
+ { keyframes: "ob-course-fade-out", delay: 0, duration: 300, composition: "replace" },
129
+ ]);
130
+ expect(rule(plan.rules, "new", "ob-course-step")).toEqual([
131
+ { keyframes: "ob-course-fade-in", delay: 0, duration: 300, composition: "replace" },
132
+ ]);
133
+ expect(plan.duration).toBe(300);
134
+ expect(plan.css).toContain("::view-transition-old(ob-course-step) {\n\tanimation-name: ob-course-fade-out;");
135
+ expect(plan.css).toContain("::view-transition-group(ob-course-step) { animation: none; }");
136
+ expect(plan.css).toContain("::view-transition-old(root) { animation: none; opacity: 0; }");
137
+ });
138
+
139
+ it("changes at once when both steps have an empty list", () => {
140
+ let plan = planStepTransition({ from: { document: slide([]) }, to: { document: slide([]) } });
141
+ expect(plan.duration).toBe(0);
142
+ expect(rule(plan.rules, "old", "ob-course-step")).toBe("hidden");
143
+ expect(rule(plan.rules, "new", "ob-course-step")).toBe("shown");
144
+ });
145
+
146
+ it("replaces the default on both sides once a list is given", () => {
147
+ let plan = planStepTransition({
148
+ from: { document: slide([{ on: "enter", effect: "zoom" }]) },
149
+ to: { document: slide([{ on: "exit", effect: "zoom" }]) },
150
+ });
151
+ expect(rule(plan.rules, "old", "ob-course-step")).toBe("hidden");
152
+ expect(rule(plan.rules, "new", "ob-course-step")).toBe("shown");
153
+ });
154
+
155
+ it("names content, background and parts with unique, valid names per side", () => {
156
+ let plan = planStepTransition({
157
+ from: { document: slide([{ on: "exit", effect: "fade", target: "i 1" }]) },
158
+ to: {
159
+ document: slide([
160
+ { on: "enter", effect: "fade" },
161
+ { on: "enter", effect: "slide", target: "content", from: "bottom", delay: 200 },
162
+ { on: "enter", effect: "zoom", target: "i 1", delay: 400, duration: 500 },
163
+ { on: "enter", effect: "fade", target: "background" },
164
+ ]),
165
+ },
166
+ });
167
+ expect(plan.names).toEqual([
168
+ { side: "old", target: { kind: "step" }, name: "ob-course-step" },
169
+ { side: "old", target: { kind: "part", id: "i 1" }, name: "ob-course-exit-0-i_1" },
170
+ { side: "new", target: { kind: "step" }, name: "ob-course-step" },
171
+ { side: "new", target: { kind: "content" }, name: "ob-course-enter-content" },
172
+ { side: "new", target: { kind: "part", id: "i 1" }, name: "ob-course-enter-0-i_1" },
173
+ { side: "new", target: { kind: "background" }, name: "ob-course-enter-background" },
174
+ ]);
175
+ expect(rule(plan.rules, "old", "ob-course-step")).toBe("hidden");
176
+ expect(rule(plan.rules, "new", "ob-course-enter-content")).toEqual([
177
+ { keyframes: "ob-course-slide-in-from-bottom", delay: 200, duration: 300, composition: "add" },
178
+ ]);
179
+ expect(plan.duration).toBe(900);
180
+ });
181
+
182
+ it("runs several items on one target together, the one that ends last listed last", () => {
183
+ let plan = planStepTransition({
184
+ to: {
185
+ document: slide([
186
+ { on: "enter", effect: "zoom", delay: 400 },
187
+ { on: "enter", effect: "fade" },
188
+ { on: "enter", effect: "slide", from: "top", duration: 100 },
189
+ ]),
190
+ },
191
+ });
192
+ let animations = rule(plan.rules, "new", "ob-course-step");
193
+ expect(animations).toEqual([
194
+ { keyframes: "ob-course-slide-in-from-top", delay: 0, duration: 100, composition: "add" },
195
+ { keyframes: "ob-course-fade-in", delay: 0, duration: 300, composition: "replace" },
196
+ { keyframes: "ob-course-scale-in", delay: 400, duration: 300, composition: "add" },
197
+ { keyframes: "ob-course-fade-in", delay: 400, duration: 300, composition: "replace" },
198
+ ]);
199
+ expect(plan.css).toContain(
200
+ "\tanimation-name: ob-course-slide-in-from-top, ob-course-fade-in, ob-course-scale-in, ob-course-fade-in;",
201
+ );
202
+ expect(plan.css).toContain("\tanimation-delay: 0ms, 0ms, 400ms, 400ms;");
203
+ expect(plan.css).toContain("\tanimation-composition: add, replace, add, replace;");
204
+ // Nothing leaves, so no old snapshot is named
205
+ expect(plan.names.every((name) => name.side === "new")).toBe(true);
206
+ });
207
+
208
+ it("mirrors slides when going back", () => {
209
+ let plan = planStepTransition({
210
+ from: { document: slide([{ on: "exit", effect: "slide" }]) },
211
+ to: { document: slide([{ on: "enter", effect: "slide" }]) },
212
+ direction: "backward",
213
+ });
214
+ expect(rule(plan.rules, "old", "ob-course-step")).toMatchObject([{ keyframes: "ob-course-slide-out-to-right" }]);
215
+ expect(rule(plan.rules, "new", "ob-course-step")).toMatchObject([{ keyframes: "ob-course-slide-in-from-left" }]);
216
+ });
217
+
218
+ describe("the category band", () => {
219
+ let safety = { title: "Sikkerhet", subTitle: "Del 1" };
220
+
221
+ it("stands still within a category", () => {
222
+ let plan = planStepTransition({
223
+ from: { ...from, category: safety },
224
+ to: { ...to, category: { ...safety } },
225
+ });
226
+ expect(plan.names.filter((name) => name.target.kind === "header")).toHaveLength(2);
227
+ expect(rule(plan.rules, "old", "ob-course-category")).toBe("hidden");
228
+ expect(rule(plan.rules, "new", "ob-course-category")).toBe("shown");
229
+ });
230
+
231
+ it("slides sideways into another category, the way the learner goes", () => {
232
+ let other = { title: "Sikkerhet", subTitle: "Del 2" };
233
+ let forward = planStepTransition({ from: { ...from, category: safety }, to: { ...to, category: other } });
234
+ expect(rule(forward.rules, "old", "ob-course-category")).toMatchObject([
235
+ { keyframes: "ob-course-slide-out-to-left" },
236
+ ]);
237
+ expect(rule(forward.rules, "new", "ob-course-category")).toMatchObject([
238
+ { keyframes: "ob-course-slide-in-from-right" },
239
+ ]);
240
+
241
+ let backward = planStepTransition({
242
+ from: { ...from, category: other },
243
+ to: { ...to, category: safety },
244
+ direction: "backward",
245
+ });
246
+ expect(rule(backward.rules, "old", "ob-course-category")).toMatchObject([
247
+ { keyframes: "ob-course-slide-out-to-right" },
248
+ ]);
249
+ });
250
+
251
+ it("comes from and leaves to the top when only one side has a band", () => {
252
+ let coming = planStepTransition({ from, to: { ...to, category: safety }, direction: "backward" });
253
+ expect(rule(coming.rules, "new", "ob-course-category")).toMatchObject([
254
+ { keyframes: "ob-course-slide-in-from-top" },
255
+ ]);
256
+ expect(coming.names.filter((name) => name.target.kind === "header")).toEqual([
257
+ { side: "new", target: { kind: "header" }, name: "ob-course-category" },
258
+ ]);
259
+
260
+ let leaving = planStepTransition({ from: { ...from, category: safety }, to });
261
+ expect(rule(leaving.rules, "old", "ob-course-category")).toMatchObject([
262
+ { keyframes: "ob-course-slide-out-to-top" },
263
+ ]);
264
+ });
265
+
266
+ it("still slides when the steps themselves change at once", () => {
267
+ let plan = planStepTransition({
268
+ from: { document: slide([]), category: safety },
269
+ to: { document: slide([]) },
270
+ });
271
+ expect(plan.duration).toBe(300);
272
+ });
273
+ });
274
+ });
package/src/types.ts CHANGED
@@ -7,8 +7,10 @@ export interface PlayerLanguage {
7
7
 
8
8
  export interface PlayerCourse {
9
9
  title: string;
10
- /** The learner's language. `null` until the learner has chosen one. */
10
+ /** The learner's language. `null` for the main language, and until the learner has chosen one. */
11
11
  cultureId: string | null;
12
+ /** The course's main language: the one a learner without a stored language takes the course in. */
13
+ mainCultureId?: string | null;
12
14
  /** The languages the course can be taken in. */
13
15
  languages: PlayerLanguage[];
14
16
  }
@@ -68,7 +70,10 @@ export interface QuizQuestion {
68
70
  text: string;
69
71
  /** Several options may be right: shown as checkboxes instead of radio buttons. */
70
72
  multiple: boolean;
71
- /** Already answered in this attempt. Set when an open attempt is resumed; the quiz continues at the first question without it. */
73
+ /**
74
+ * Already answered in this attempt. Set when an open attempt is resumed; the quiz continues at the first question
75
+ * without it. With `retryUntilCorrect`, only a correct answer counts, so a question last answered wrong is asked again.
76
+ */
72
77
  answered?: boolean;
73
78
  options: QuizOption[];
74
79
  }
@@ -77,6 +82,11 @@ export interface QuizAttempt {
77
82
  attemptId: string;
78
83
  /** Percent of correct answers needed to pass. `null` means every answer must be correct. */
79
84
  passPercent: number | null;
85
+ /**
86
+ * Each question must be answered correctly before the next one: a wrong answer only says so, and the learner
87
+ * answers the same question again. The attempt passes once every question is right; `passPercent` is not used.
88
+ */
89
+ retryUntilCorrect?: boolean;
80
90
  questions: QuizQuestion[];
81
91
  /** The learner has passed this quiz before; the player shows it as passed without asking again. */
82
92
  alreadyPassed?: boolean;
@@ -84,7 +94,8 @@ export interface QuizAttempt {
84
94
 
85
95
  export interface QuizAnswerResult {
86
96
  correct: boolean;
87
- explanation?: string;
97
+ /** Left out after a wrong answer when the quiz has `retryUntilCorrect`; the player then never shows one. */
98
+ explanation?: string | null;
88
99
  }
89
100
 
90
101
  export interface QuizResult {
@@ -93,6 +104,8 @@ export interface QuizResult {
93
104
  correctCount: number;
94
105
  questionCount: number;
95
106
  passPercent: number | null;
107
+ /** The quiz had to be answered correctly question by question, so a passed attempt is every question right. */
108
+ retryUntilCorrect?: boolean;
96
109
  /** The ids of the must-be-correct questions that were answered wrong. */
97
110
  missedRequired: string[];
98
111
  }
@@ -1,55 +0,0 @@
1
- .ob-course-player .ob-course-step {
2
- view-transition-name: ob-course-step;
3
- }
4
-
5
- html[data-ob-course-direction="forward"]::view-transition-old(ob-course-step) {
6
- animation: ob-course-slide-out-left var(--ob-course-transition-duration, 300ms) ease forwards;
7
- }
8
-
9
- html[data-ob-course-direction="forward"]::view-transition-new(ob-course-step) {
10
- animation: ob-course-slide-in-right var(--ob-course-transition-duration, 300ms) ease forwards;
11
- }
12
-
13
- html[data-ob-course-direction="backward"]::view-transition-old(ob-course-step) {
14
- animation: ob-course-slide-out-right var(--ob-course-transition-duration, 300ms) ease forwards;
15
- }
16
-
17
- html[data-ob-course-direction="backward"]::view-transition-new(ob-course-step) {
18
- animation: ob-course-slide-in-left var(--ob-course-transition-duration, 300ms) ease forwards;
19
- }
20
-
21
- @keyframes ob-course-slide-in-right {
22
- from {
23
- transform: translateX(100%);
24
- }
25
- to {
26
- transform: translateX(0);
27
- }
28
- }
29
-
30
- @keyframes ob-course-slide-out-left {
31
- from {
32
- transform: translateX(0);
33
- }
34
- to {
35
- transform: translateX(-100%);
36
- }
37
- }
38
-
39
- @keyframes ob-course-slide-in-left {
40
- from {
41
- transform: translateX(-100%);
42
- }
43
- to {
44
- transform: translateX(0);
45
- }
46
- }
47
-
48
- @keyframes ob-course-slide-out-right {
49
- from {
50
- transform: translateX(0);
51
- }
52
- to {
53
- transform: translateX(100%);
54
- }
55
- }
@@ -1,10 +0,0 @@
1
- import "./Transitions.css";
2
- export interface TransitionOptions {
3
- duration?: number;
4
- direction?: "forward" | "backward";
5
- }
6
- /**
7
- * Wraps a change of step in a view transition, so the old step slides out as the new one comes
8
- * in. Updates at once where the API is missing or the learner prefers reduced motion.
9
- */
10
- export declare function runViewTransition(callback: () => void, options?: TransitionOptions): void;
package/es/Transitions.js DELETED
@@ -1,24 +0,0 @@
1
- import "./Transitions.css";
2
- import { flushSync } from "react-dom";
3
- /**
4
- * Wraps a change of step in a view transition, so the old step slides out as the new one comes
5
- * in. Updates at once where the API is missing or the learner prefers reduced motion.
6
- */
7
- export function runViewTransition(callback, options = {}) {
8
- let { duration = 300, direction = "forward" } = options;
9
- let reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
10
- if (typeof document?.startViewTransition !== "function" || reduced) {
11
- callback();
12
- return;
13
- }
14
- let root = document.documentElement;
15
- root.style.setProperty("--ob-course-transition-duration", `${duration}ms`);
16
- root.dataset.obCourseDirection = direction;
17
- let transition = document.startViewTransition(() => {
18
- flushSync(callback);
19
- });
20
- transition.finished.finally(() => {
21
- root.style.removeProperty("--ob-course-transition-duration");
22
- delete root.dataset.obCourseDirection;
23
- });
24
- }
@@ -1,55 +0,0 @@
1
- .ob-course-player .ob-course-step {
2
- view-transition-name: ob-course-step;
3
- }
4
-
5
- html[data-ob-course-direction="forward"]::view-transition-old(ob-course-step) {
6
- animation: ob-course-slide-out-left var(--ob-course-transition-duration, 300ms) ease forwards;
7
- }
8
-
9
- html[data-ob-course-direction="forward"]::view-transition-new(ob-course-step) {
10
- animation: ob-course-slide-in-right var(--ob-course-transition-duration, 300ms) ease forwards;
11
- }
12
-
13
- html[data-ob-course-direction="backward"]::view-transition-old(ob-course-step) {
14
- animation: ob-course-slide-out-right var(--ob-course-transition-duration, 300ms) ease forwards;
15
- }
16
-
17
- html[data-ob-course-direction="backward"]::view-transition-new(ob-course-step) {
18
- animation: ob-course-slide-in-left var(--ob-course-transition-duration, 300ms) ease forwards;
19
- }
20
-
21
- @keyframes ob-course-slide-in-right {
22
- from {
23
- transform: translateX(100%);
24
- }
25
- to {
26
- transform: translateX(0);
27
- }
28
- }
29
-
30
- @keyframes ob-course-slide-out-left {
31
- from {
32
- transform: translateX(0);
33
- }
34
- to {
35
- transform: translateX(-100%);
36
- }
37
- }
38
-
39
- @keyframes ob-course-slide-in-left {
40
- from {
41
- transform: translateX(-100%);
42
- }
43
- to {
44
- transform: translateX(0);
45
- }
46
- }
47
-
48
- @keyframes ob-course-slide-out-right {
49
- from {
50
- transform: translateX(0);
51
- }
52
- to {
53
- transform: translateX(100%);
54
- }
55
- }
@@ -1,35 +0,0 @@
1
- import "./Transitions.css";
2
-
3
- import { flushSync } from "react-dom";
4
-
5
- export interface TransitionOptions {
6
- duration?: number;
7
- direction?: "forward" | "backward";
8
- }
9
-
10
- /**
11
- * Wraps a change of step in a view transition, so the old step slides out as the new one comes
12
- * in. Updates at once where the API is missing or the learner prefers reduced motion.
13
- */
14
- export function runViewTransition(callback: () => void, options: TransitionOptions = {}) {
15
- let { duration = 300, direction = "forward" } = options;
16
-
17
- let reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
18
- if (typeof document?.startViewTransition !== "function" || reduced) {
19
- callback();
20
- return;
21
- }
22
-
23
- let root = document.documentElement;
24
- root.style.setProperty("--ob-course-transition-duration", `${duration}ms`);
25
- root.dataset.obCourseDirection = direction;
26
-
27
- let transition = document.startViewTransition(() => {
28
- flushSync(callback);
29
- });
30
-
31
- transition.finished.finally(() => {
32
- root.style.removeProperty("--ob-course-transition-duration");
33
- delete root.dataset.obCourseDirection;
34
- });
35
- }