@olenbetong/synergi-course 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/chrome/CategoryHeader.css +28 -0
- package/es/completion/CourseCompletion.css +53 -0
- package/es/completion/CourseCompletion.d.ts +32 -0
- package/es/completion/CourseCompletion.js +60 -0
- package/es/document/cues.d.ts +51 -6
- package/es/document/cues.js +115 -14
- package/es/document/effects.d.ts +30 -0
- package/es/document/effects.js +74 -0
- package/es/document/schema.d.ts +924 -136
- package/es/document/schema.js +139 -5
- package/es/document/validate.d.ts +2 -1
- package/es/document/validate.js +73 -2
- package/es/index.d.ts +6 -2
- package/es/index.js +6 -2
- package/es/media/Media.css +16 -0
- package/es/media/icons.d.ts +1 -0
- package/es/media/icons.js +3 -0
- package/es/player/CoursePlayer.css +58 -0
- package/es/player/CoursePlayer.js +27 -13
- package/es/player/useFullScreen.d.ts +17 -0
- package/es/player/useFullScreen.js +83 -0
- package/es/player/useMediaQuery.d.ts +7 -0
- package/es/player/useMediaQuery.js +16 -0
- package/es/steps/Blocks.d.ts +20 -1
- package/es/steps/Blocks.js +103 -22
- package/es/steps/Markdown.d.ts +7 -1
- package/es/steps/Markdown.js +31 -4
- package/es/steps/RevealMotion.d.ts +29 -0
- package/es/steps/RevealMotion.js +55 -0
- package/es/steps/SlideStepView.d.ts +5 -3
- package/es/steps/SlideStepView.js +38 -15
- package/es/steps/StepBodyProps.d.ts +7 -1
- package/es/steps/StepView.css +328 -12
- package/es/steps/StepView.d.ts +8 -2
- package/es/steps/StepView.js +2 -2
- package/es/steps/motion.d.ts +59 -0
- package/es/steps/motion.js +136 -0
- package/es/transitions/Transitions.css +114 -0
- package/es/transitions/plan.d.ts +66 -0
- package/es/transitions/plan.js +185 -0
- package/es/transitions/playStepTransition.d.ts +23 -0
- package/es/transitions/playStepTransition.js +131 -0
- package/es/types.d.ts +3 -1
- package/package.json +4 -4
- package/src/chrome/CategoryHeader.css +28 -0
- package/src/completion/CourseCompletion.css +53 -0
- package/src/completion/CourseCompletion.test.tsx +45 -0
- package/src/completion/CourseCompletion.tsx +98 -0
- package/src/document/cues.ts +142 -13
- package/src/document/document.test.ts +1 -1
- package/src/document/effects.ts +105 -0
- package/src/document/reveal.test.ts +263 -0
- package/src/document/schema.ts +161 -5
- package/src/document/validate.ts +77 -3
- package/src/index.ts +35 -0
- package/src/media/Media.css +16 -0
- package/src/media/icons.tsx +8 -0
- package/src/player/CoursePlayer.css +58 -0
- package/src/player/CoursePlayer.test.tsx +70 -6
- package/src/player/CoursePlayer.tsx +68 -17
- package/src/player/fullScreen.test.tsx +70 -0
- package/src/player/useFullScreen.ts +91 -0
- package/src/player/useMediaQuery.ts +21 -0
- package/src/steps/Blocks.test.ts +34 -0
- package/src/steps/Blocks.tsx +166 -26
- package/src/steps/Markdown.test.tsx +43 -0
- package/src/steps/Markdown.tsx +42 -4
- package/src/steps/Presence.test.tsx +82 -0
- package/src/steps/RevealMotion.ts +66 -0
- package/src/steps/SlideStepView.tsx +67 -17
- package/src/steps/StepBodyProps.ts +7 -1
- package/src/steps/StepView.css +328 -12
- package/src/steps/StepView.test.tsx +41 -0
- package/src/steps/StepView.tsx +9 -1
- package/src/steps/motion.test.ts +98 -0
- package/src/steps/motion.ts +178 -0
- package/src/steps/visibility.test.ts +24 -0
- package/src/transitions/Transitions.css +114 -0
- package/src/transitions/plan.ts +258 -0
- package/src/transitions/playStepTransition.ts +162 -0
- package/src/transitions/transitions.test.ts +274 -0
- package/src/types.ts +3 -1
- package/es/Transitions.css +0 -55
- package/es/Transitions.d.ts +0 -10
- package/es/Transitions.js +0 -24
- package/src/Transitions.css +0 -55
- package/src/Transitions.ts +0 -35
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import "./Transitions.css";
|
|
2
|
+
|
|
3
|
+
import { flushSync } from "react-dom";
|
|
4
|
+
import type { Step } from "../document/schema";
|
|
5
|
+
import {
|
|
6
|
+
type NamedTarget,
|
|
7
|
+
planStepTransition,
|
|
8
|
+
type TransitionDirection,
|
|
9
|
+
type TransitionSide,
|
|
10
|
+
type TransitionStep,
|
|
11
|
+
type TransitionTarget,
|
|
12
|
+
} from "./plan";
|
|
13
|
+
|
|
14
|
+
export interface StepTransitionOptions {
|
|
15
|
+
/** The step's box (`.ob-course-step`) or an element around it. Only elements inside it are named. */
|
|
16
|
+
scope: Element | null | undefined;
|
|
17
|
+
/** The step that leaves; its `exit` transitions run. Left out, nothing leaves. */
|
|
18
|
+
from?: TransitionStep | Step | null;
|
|
19
|
+
/** The step that comes; its `enter` transitions run. Left out, nothing comes. */
|
|
20
|
+
to?: TransitionStep | Step | null;
|
|
21
|
+
direction?: TransitionDirection;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Running {
|
|
25
|
+
transition: ViewTransition;
|
|
26
|
+
cleanup(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** One view transition runs at a time in a document, so one is tracked for the whole module. */
|
|
30
|
+
let running: Running | null = null;
|
|
31
|
+
|
|
32
|
+
function noop() {}
|
|
33
|
+
|
|
34
|
+
function toStep(step: TransitionStep | Step | null | undefined): TransitionStep | null {
|
|
35
|
+
if (step == null) return null;
|
|
36
|
+
return "document" in step ? step : { document: step };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function canAnimate() {
|
|
40
|
+
if (typeof document === "undefined" || typeof document.startViewTransition !== "function") return false;
|
|
41
|
+
return !(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function findBox(scope: Element | null | undefined) {
|
|
45
|
+
if (!scope) return null;
|
|
46
|
+
return scope.matches(".ob-course-step") ? scope : scope.querySelector(".ob-course-step");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function findTarget(box: Element, target: TransitionTarget): HTMLElement | null {
|
|
50
|
+
let element: Element | null;
|
|
51
|
+
switch (target.kind) {
|
|
52
|
+
case "step":
|
|
53
|
+
element = box;
|
|
54
|
+
break;
|
|
55
|
+
case "header":
|
|
56
|
+
element = box.querySelector(".ob-course-category-header");
|
|
57
|
+
break;
|
|
58
|
+
case "content":
|
|
59
|
+
element = box.querySelector(".ob-course-slide__content");
|
|
60
|
+
break;
|
|
61
|
+
case "background":
|
|
62
|
+
element = box.querySelector(".ob-course-slide__background, .ob-course-banner");
|
|
63
|
+
break;
|
|
64
|
+
case "part":
|
|
65
|
+
element = box.querySelector(`[data-part="${CSS.escape(target.id)}"]`);
|
|
66
|
+
// A part waiting for its cue or its press of Next, or fading out, is not on show: nothing to animate
|
|
67
|
+
if (element?.closest(".is-pending, .is-leaving")) element = null;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
return element instanceof HTMLElement ? element : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Runs `run`, the change of step, inside a view transition: the outgoing step's `exit`
|
|
75
|
+
* transitions animate what it showed, the incoming step's `enter` transitions what it shows, and
|
|
76
|
+
* the category band stays or slides. Names are set on the elements inside `scope` only for as
|
|
77
|
+
* long as the transition runs, so other steps on the page (an editor's previews) are never part
|
|
78
|
+
* of it. A transition still running is skipped first. Without the API, or when the learner
|
|
79
|
+
* prefers reduced motion, `run` is called at once.
|
|
80
|
+
*
|
|
81
|
+
* Resolves when the transition has finished.
|
|
82
|
+
*/
|
|
83
|
+
export function playStepTransition(run: () => void, options: StepTransitionOptions): Promise<void> {
|
|
84
|
+
if (!canAnimate()) {
|
|
85
|
+
run();
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (running) {
|
|
90
|
+
let previous = running;
|
|
91
|
+
running = null;
|
|
92
|
+
previous.transition.skipTransition();
|
|
93
|
+
// The change it was making must be in the page before this one names what is there
|
|
94
|
+
let start = () => {
|
|
95
|
+
previous.cleanup();
|
|
96
|
+
return startTransition(run, options);
|
|
97
|
+
};
|
|
98
|
+
return previous.transition.updateCallbackDone.then(start, start);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return startTransition(run, options);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function startTransition(run: () => void, { scope, from, to, direction = "forward" }: StepTransitionOptions) {
|
|
105
|
+
let plan = planStepTransition({ from: toStep(from), to: toStep(to), direction });
|
|
106
|
+
if (plan.duration === 0 || !findBox(scope)) {
|
|
107
|
+
run();
|
|
108
|
+
return Promise.resolve();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let style = document.createElement("style");
|
|
112
|
+
style.dataset.obCourseTransition = "";
|
|
113
|
+
style.textContent = plan.css;
|
|
114
|
+
document.head.append(style);
|
|
115
|
+
|
|
116
|
+
let named: HTMLElement[] = [];
|
|
117
|
+
let name = (side: TransitionSide) => {
|
|
118
|
+
let box = findBox(scope);
|
|
119
|
+
if (!box) return;
|
|
120
|
+
for (let target of plan.names.filter((item: NamedTarget) => item.side === side)) {
|
|
121
|
+
let element = findTarget(box, target.target);
|
|
122
|
+
if (!element) continue;
|
|
123
|
+
element.style.setProperty("view-transition-name", target.name);
|
|
124
|
+
named.push(element);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
let unname = () => {
|
|
128
|
+
for (let element of named) element.style.removeProperty("view-transition-name");
|
|
129
|
+
named = [];
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
let entry: Running;
|
|
133
|
+
let cleaned = false;
|
|
134
|
+
let skip = () => entry.transition.skipTransition();
|
|
135
|
+
let cleanup = () => {
|
|
136
|
+
if (cleaned) return;
|
|
137
|
+
cleaned = true;
|
|
138
|
+
unname();
|
|
139
|
+
style.remove();
|
|
140
|
+
document.documentElement.removeEventListener("pointerdown", skip);
|
|
141
|
+
if (running === entry) running = null;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
name("old");
|
|
145
|
+
let transition = document.startViewTransition(() => {
|
|
146
|
+
if (running !== entry) {
|
|
147
|
+
// Skipped for a newer change before it got here: only the change itself is still owed
|
|
148
|
+
flushSync(run);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
unname();
|
|
152
|
+
flushSync(run);
|
|
153
|
+
name("new");
|
|
154
|
+
});
|
|
155
|
+
entry = { transition, cleanup };
|
|
156
|
+
running = entry;
|
|
157
|
+
|
|
158
|
+
// The page takes no clicks while a transition runs, so a click ends it instead
|
|
159
|
+
document.documentElement.addEventListener("pointerdown", skip);
|
|
160
|
+
|
|
161
|
+
return transition.finished.then(cleanup, cleanup).then(noop);
|
|
162
|
+
}
|
|
@@ -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
|
}
|
package/es/Transitions.css
DELETED
|
@@ -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
|
-
}
|
package/es/Transitions.d.ts
DELETED
|
@@ -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
|
-
}
|
package/src/Transitions.css
DELETED
|
@@ -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
|
-
}
|
package/src/Transitions.ts
DELETED
|
@@ -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
|
-
}
|