@olenbetong/synergi-course 0.0.0-stage → 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/README.md +27 -2
- package/es/chrome/CategoryHeader.css +122 -0
- package/es/chrome/CategoryHeader.d.ts +8 -0
- package/es/chrome/CategoryHeader.js +37 -0
- package/es/chrome/ProgressBar.css +16 -0
- package/es/chrome/ProgressBar.d.ts +9 -0
- package/es/chrome/ProgressBar.js +7 -0
- package/es/chrome/themeIconSets.d.ts +11 -0
- package/es/chrome/themeIconSets.js +25 -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 +77 -0
- package/es/document/cues.js +173 -0
- package/es/document/effects.d.ts +30 -0
- package/es/document/effects.js +74 -0
- package/es/document/schema.d.ts +2161 -0
- package/es/document/schema.js +336 -0
- package/es/document/validate.d.ts +22 -0
- package/es/document/validate.js +171 -0
- package/es/i18n.d.ts +6 -0
- package/es/i18n.js +8 -0
- package/es/icons/BetongelementIcon.d.ts +2 -0
- package/es/icons/BetongelementIcon.js +4 -0
- package/es/icons/BetongvarerIcon.d.ts +2 -0
- package/es/icons/BetongvarerIcon.js +4 -0
- package/es/icons/FerdigbetongIcon.d.ts +2 -0
- package/es/icons/FerdigbetongIcon.js +4 -0
- package/es/icons/LogoElementIcon.d.ts +2 -0
- package/es/icons/LogoElementIcon.js +4 -0
- package/es/index.d.ts +12 -0
- package/es/index.js +11 -0
- package/es/media/Media.css +112 -0
- package/es/media/MediaControls.d.ts +25 -0
- package/es/media/MediaControls.js +30 -0
- package/es/media/Narration.d.ts +23 -0
- package/es/media/Narration.js +32 -0
- package/es/media/VideoPlayer.d.ts +16 -0
- package/es/media/VideoPlayer.js +65 -0
- package/es/media/icons.d.ts +12 -0
- package/es/media/icons.js +31 -0
- package/es/media/mediaHandle.d.ts +30 -0
- package/es/media/mediaHandle.js +123 -0
- package/es/media/useCueClock.d.ts +19 -0
- package/es/media/useCueClock.js +40 -0
- package/es/player/CoursePlayer.css +215 -0
- package/es/player/CoursePlayer.d.ts +29 -0
- package/es/player/CoursePlayer.js +213 -0
- package/es/player/LanguageMenu.d.ts +8 -0
- package/es/player/LanguageMenu.js +11 -0
- package/es/player/StartScreen.d.ts +6 -0
- package/es/player/StartScreen.js +12 -0
- 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/player/useNavigationKeys.d.ts +7 -0
- package/es/player/useNavigationKeys.js +43 -0
- package/es/steps/Blocks.d.ts +33 -0
- package/es/steps/Blocks.js +150 -0
- package/es/steps/Markdown.d.ts +10 -0
- package/es/steps/Markdown.js +40 -0
- package/es/steps/PdfStepView.d.ts +6 -0
- package/es/steps/PdfStepView.js +14 -0
- package/es/steps/QuizStepView.css +18 -0
- package/es/steps/QuizStepView.d.ts +11 -0
- package/es/steps/QuizStepView.js +124 -0
- package/es/steps/RevealMotion.d.ts +29 -0
- package/es/steps/RevealMotion.js +55 -0
- package/es/steps/SlideStepView.d.ts +11 -0
- package/es/steps/SlideStepView.js +65 -0
- package/es/steps/StepBodyProps.d.ts +22 -0
- package/es/steps/StepBodyProps.js +1 -0
- package/es/steps/StepView.css +696 -0
- package/es/steps/StepView.d.ts +44 -0
- package/es/steps/StepView.js +44 -0
- package/es/steps/VideoStepView.d.ts +6 -0
- package/es/steps/VideoStepView.js +23 -0
- 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 +103 -0
- package/es/types.js +1 -0
- package/package.json +60 -3
- package/src/chrome/CategoryHeader.css +122 -0
- package/src/chrome/CategoryHeader.test.tsx +150 -0
- package/src/chrome/CategoryHeader.tsx +70 -0
- package/src/chrome/ProgressBar.css +16 -0
- package/src/chrome/ProgressBar.tsx +18 -0
- package/src/chrome/themeIconSets.tsx +33 -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 +216 -0
- package/src/document/document.test.ts +251 -0
- package/src/document/effects.ts +105 -0
- package/src/document/reveal.test.ts +263 -0
- package/src/document/schema.ts +419 -0
- package/src/document/validate.ts +191 -0
- package/src/i18n.ts +11 -0
- package/src/icons/BetongelementIcon.tsx +53 -0
- package/src/icons/BetongvarerIcon.tsx +40 -0
- package/src/icons/FerdigbetongIcon.tsx +53 -0
- package/src/icons/LogoElementIcon.tsx +23 -0
- package/src/index.ts +94 -0
- package/src/media/Media.css +112 -0
- package/src/media/MediaControls.tsx +100 -0
- package/src/media/Narration.tsx +77 -0
- package/src/media/VideoPlayer.tsx +128 -0
- package/src/media/icons.tsx +84 -0
- package/src/media/mediaHandle.test.ts +90 -0
- package/src/media/mediaHandle.ts +152 -0
- package/src/media/useCueClock.ts +55 -0
- package/src/player/CoursePlayer.css +215 -0
- package/src/player/CoursePlayer.test.tsx +516 -0
- package/src/player/CoursePlayer.tsx +400 -0
- package/src/player/LanguageMenu.tsx +40 -0
- package/src/player/StartScreen.tsx +33 -0
- package/src/player/fullScreen.test.tsx +70 -0
- package/src/player/useFullScreen.ts +91 -0
- package/src/player/useMediaQuery.ts +21 -0
- package/src/player/useNavigationKeys.ts +49 -0
- package/src/steps/Blocks.test.ts +34 -0
- package/src/steps/Blocks.tsx +309 -0
- package/src/steps/Markdown.test.tsx +43 -0
- package/src/steps/Markdown.tsx +56 -0
- package/src/steps/PdfStepView.tsx +43 -0
- package/src/steps/Presence.test.tsx +82 -0
- package/src/steps/QuizStepView.css +18 -0
- package/src/steps/QuizStepView.test.tsx +201 -0
- package/src/steps/QuizStepView.tsx +292 -0
- package/src/steps/RevealMotion.ts +66 -0
- package/src/steps/SlideStepView.tsx +134 -0
- package/src/steps/StepBodyProps.ts +23 -0
- package/src/steps/StepView.css +696 -0
- package/src/steps/StepView.test.tsx +78 -0
- package/src/steps/StepView.tsx +122 -0
- package/src/steps/VideoStepView.tsx +52 -0
- 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/test/setup.ts +28 -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 +115 -0
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @olenbetong/synergi-course
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The course player. A course is an ordered list of steps; each step is a **step document**, the
|
|
4
|
+
content of one slide in one language (`slide`, `video`, `pdf` or `quiz`). The package validates
|
|
5
|
+
step documents and plays them responsively.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { CoursePlayer, StepView, validateStep } from "@olenbetong/synergi-course";
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- `CoursePlayer` plays a course: navigation, gating on the step being done and its minimum time,
|
|
12
|
+
language choice, subtitles, quizzes. Progress and quiz answers go through a `ProgressAdapter`
|
|
13
|
+
and a `QuizAdapter` the app implements; `resolveAsset` turns media addresses into URLs.
|
|
14
|
+
- `StepView` shows one step without the course chrome, for the editor.
|
|
15
|
+
- `validateStep`, `getStepJsonSchema` and the cue helpers describe the format.
|
|
16
|
+
|
|
17
|
+
Full reference: [`docs/reference/synergi-course`](../../docs/reference/synergi-course/README.md).
|
|
18
|
+
Stories: `stories/synergi-course`.
|
|
19
|
+
|
|
20
|
+
## Development
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm --filter @olenbetong/synergi-course build
|
|
24
|
+
pnpm --filter @olenbetong/synergi-course test
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Labels are English base strings in the `synergi-course` globalization project, bound in
|
|
28
|
+
`src/i18n.ts`. Styles are plain CSS files beside the components, using Designsystemet tokens.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/* The band carries the company's colours: they come from the theme stylesheet the page links. */
|
|
2
|
+
.ob-course-category-header {
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: 1em;
|
|
6
|
+
padding: clamp(0.5rem, 2cqi, 1rem) clamp(1rem, 4cqi, 3rem);
|
|
7
|
+
border-bottom: 1px solid var(--ds-color-brand-border-subtle);
|
|
8
|
+
font-size: clamp(0.9rem, 0.8rem + 0.6cqi, 1.3rem);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.ob-course-category-header__titles {
|
|
12
|
+
flex: 1;
|
|
13
|
+
min-width: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.ob-course-category-header__title,
|
|
17
|
+
.ob-course-category-header__subtitle {
|
|
18
|
+
margin: 0;
|
|
19
|
+
line-height: 1.25;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ob-course-category-header__title {
|
|
23
|
+
font-size: 1.3em;
|
|
24
|
+
font-weight: 600;
|
|
25
|
+
color: var(--ds-color-brand-text-default);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.ob-course-category-header__subtitle {
|
|
29
|
+
color: var(--ds-color-neutral-text-subtle);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.ob-course-category-header__images {
|
|
33
|
+
flex: 0 0 auto;
|
|
34
|
+
display: flex;
|
|
35
|
+
gap: 0.4em;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.ob-course-category-header__image {
|
|
39
|
+
width: 2.5em;
|
|
40
|
+
height: 2.5em;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.ob-course-category-header__brand {
|
|
44
|
+
flex: 0 0 auto;
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
margin: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.ob-course-category-header__brand-name {
|
|
51
|
+
font-weight: 600;
|
|
52
|
+
white-space: nowrap;
|
|
53
|
+
color: var(--ds-color-brand-text-default);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* Logos come in every shape; the height matches the product logos and a wide one stops at a third of the band. */
|
|
57
|
+
.ob-course-category-header__logo {
|
|
58
|
+
display: block;
|
|
59
|
+
width: auto;
|
|
60
|
+
height: auto;
|
|
61
|
+
max-height: 2.5em;
|
|
62
|
+
max-width: min(12em, 33cqi);
|
|
63
|
+
object-fit: contain;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.ob-course-category-header__logo--dark {
|
|
67
|
+
display: none;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
[data-color-scheme="dark"] .ob-course-category-header__logo--light {
|
|
71
|
+
display: none;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
[data-color-scheme="dark"] .ob-course-category-header__logo--dark {
|
|
75
|
+
display: block;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@media (prefers-color-scheme: dark) {
|
|
79
|
+
[data-color-scheme="auto"] .ob-course-category-header__logo--light {
|
|
80
|
+
display: none;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[data-color-scheme="auto"] .ob-course-category-header__logo--dark {
|
|
84
|
+
display: block;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* On a phone the logos take the room the title needs. */
|
|
89
|
+
@container (max-width: 30rem) {
|
|
90
|
+
.ob-course-category-header__images,
|
|
91
|
+
.ob-course-category-header__brand {
|
|
92
|
+
display: none;
|
|
93
|
+
}
|
|
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,8 @@
|
|
|
1
|
+
import type { PlayerBranding, PlayerCategory } from "../types";
|
|
2
|
+
import "./CategoryHeader.css";
|
|
3
|
+
export interface CategoryHeaderProps extends PlayerCategory {
|
|
4
|
+
/** The company to show. Without it the band shows the group's four product logos. */
|
|
5
|
+
branding?: PlayerBranding | null;
|
|
6
|
+
}
|
|
7
|
+
/** The band above a step that names the part of the course it belongs to. */
|
|
8
|
+
export declare function CategoryHeader({ title, subTitle, branding }: CategoryHeaderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { defaultIconSet, getThemeIconSet } from "./themeIconSets";
|
|
3
|
+
import "./CategoryHeader.css";
|
|
4
|
+
/** The band above a step that names the part of the course it belongs to. */
|
|
5
|
+
export function CategoryHeader({ title, subTitle, branding }) {
|
|
6
|
+
return (_jsxs("div", { className: "ob-course-category-header", children: [_jsxs("div", { className: "ob-course-category-header__titles", children: [_jsx("p", { className: "ob-course-category-header__title", children: title }), subTitle && _jsx("p", { className: "ob-course-category-header__subtitle", children: subTitle })] }), branding ? _jsx(BrandMark, { branding: branding }) : _jsx(IconSet, { icons: defaultIconSet })] }));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A logo made for courses wins. Otherwise a theme the package has icons for shows those, since most
|
|
10
|
+
* website logos are drawn for the toolbar and not for the band; then the website logo, then the name.
|
|
11
|
+
*/
|
|
12
|
+
function BrandMark({ branding }) {
|
|
13
|
+
let light = branding.logoUrl || branding.logoUrlDark;
|
|
14
|
+
let dark = branding.logoUrlDark || branding.logoUrl;
|
|
15
|
+
let logo = light && dark ? _jsx(Logo, { name: branding.name, light: light, dark: dark }) : null;
|
|
16
|
+
let icons = getThemeIconSet(branding.themeKey);
|
|
17
|
+
if (logo && branding.hasCourseLogo) {
|
|
18
|
+
return logo;
|
|
19
|
+
}
|
|
20
|
+
if (icons) {
|
|
21
|
+
return _jsx(IconSet, { icons: icons });
|
|
22
|
+
}
|
|
23
|
+
if (logo) {
|
|
24
|
+
return logo;
|
|
25
|
+
}
|
|
26
|
+
return _jsx("p", { className: "ob-course-category-header__brand ob-course-category-header__brand-name", children: branding.name });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Both logos are in the page and the stylesheet shows the one for the colour scheme, so switching
|
|
30
|
+
* the scheme needs no re-render and the right logo is there on the first paint.
|
|
31
|
+
*/
|
|
32
|
+
function Logo({ name, light, dark }) {
|
|
33
|
+
return (_jsxs("div", { className: "ob-course-category-header__brand", children: [_jsx("img", { className: "ob-course-category-header__logo ob-course-category-header__logo--light", src: light, alt: name }), _jsx("img", { className: "ob-course-category-header__logo ob-course-category-header__logo--dark", src: dark, alt: name })] }));
|
|
34
|
+
}
|
|
35
|
+
function IconSet({ icons }) {
|
|
36
|
+
return (_jsx("div", { className: "ob-course-category-header__images", children: icons.map((Icon, index) => (_jsx(Icon, { className: "ob-course-category-header__image" }, index))) }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.ob-course-progress-bar {
|
|
2
|
+
height: 0.3rem;
|
|
3
|
+
background: var(--ds-color-neutral-surface-tinted);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.ob-course-progress-bar__bar {
|
|
7
|
+
height: 100%;
|
|
8
|
+
background: var(--ds-color-brand-base-default);
|
|
9
|
+
transition: width 0.3s ease;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@media (prefers-reduced-motion: reduce) {
|
|
13
|
+
.ob-course-progress-bar__bar {
|
|
14
|
+
transition: none;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "./ProgressBar.css";
|
|
2
|
+
interface ProgressBarProps {
|
|
3
|
+
/** Number of steps. */
|
|
4
|
+
length: number;
|
|
5
|
+
currentIndex: number;
|
|
6
|
+
}
|
|
7
|
+
/** A thin bar for how far through the course the learner is. The "3 / 12" beside the buttons says the same in words. */
|
|
8
|
+
export declare function ProgressBar({ length, currentIndex }: ProgressBarProps): import("react").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import "./ProgressBar.css";
|
|
3
|
+
/** A thin bar for how far through the course the learner is. The "3 / 12" beside the buttons says the same in words. */
|
|
4
|
+
export function ProgressBar({ length, currentIndex }) {
|
|
5
|
+
let percent = length > 0 ? ((currentIndex + 1) / length) * 100 : 0;
|
|
6
|
+
return (_jsx("div", { className: "ob-course-progress-bar", "aria-hidden": true, children: _jsx("div", { className: "ob-course-progress-bar__bar", style: { width: `${percent}%` } }) }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
type IconComponent = (props: React.SVGProps<SVGSVGElement>) => React.ReactElement;
|
|
3
|
+
/**
|
|
4
|
+
* The icons the category band shows for a website theme, keyed by the theme's `Key`, in the order they
|
|
5
|
+
* are drawn. A theme with its own course logo shows that instead; a theme not listed here shows its logo.
|
|
6
|
+
*/
|
|
7
|
+
export declare const themeIconSets: Record<string, readonly IconComponent[]>;
|
|
8
|
+
/** The set shown when no branding is given at all. */
|
|
9
|
+
export declare const defaultIconSet: readonly IconComponent[];
|
|
10
|
+
export declare function getThemeIconSet(themeKey: string | null | undefined): readonly IconComponent[] | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import BetongelementIcon from "../icons/BetongelementIcon";
|
|
2
|
+
import BetongvarerIcon from "../icons/BetongvarerIcon";
|
|
3
|
+
import FerdigbetongIcon from "../icons/FerdigbetongIcon";
|
|
4
|
+
import LogoElementIcon from "../icons/LogoElementIcon";
|
|
5
|
+
const olenbetongIcons = [
|
|
6
|
+
LogoElementIcon,
|
|
7
|
+
FerdigbetongIcon,
|
|
8
|
+
BetongvarerIcon,
|
|
9
|
+
BetongelementIcon,
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* The icons the category band shows for a website theme, keyed by the theme's `Key`, in the order they
|
|
13
|
+
* are drawn. A theme with its own course logo shows that instead; a theme not listed here shows its logo.
|
|
14
|
+
*/
|
|
15
|
+
export const themeIconSets = {
|
|
16
|
+
olenbetong: olenbetongIcons,
|
|
17
|
+
};
|
|
18
|
+
/** The set shown when no branding is given at all. */
|
|
19
|
+
export const defaultIconSet = olenbetongIcons;
|
|
20
|
+
export function getThemeIconSet(themeKey) {
|
|
21
|
+
if (!themeKey || !Object.hasOwn(themeIconSets, themeKey)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return themeIconSets[themeKey] ?? null;
|
|
25
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import "./CourseCompletion.css";
|
|
3
|
+
export interface CourseCompletionProps {
|
|
4
|
+
/** The course's title, the screen's heading. */
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
/** The course's completion text (HTML written by the course editors). Blank counts as none. */
|
|
7
|
+
html?: string | null;
|
|
8
|
+
/** What the learner reads when the course has no completion text. */
|
|
9
|
+
emptyText: ReactNode;
|
|
10
|
+
/** The buttons under the text (the diploma, back to the course list). */
|
|
11
|
+
actions?: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Strip scripts, event handlers, embedded frames and `javascript:` links before showing the
|
|
14
|
+
* text. For an editor's preview of text being written; the player shows the saved text as it is.
|
|
15
|
+
*/
|
|
16
|
+
sanitize?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Whether the completion text has anything to show; the course feed treats blank text as none. */
|
|
20
|
+
export declare function hasCompletionText(html: string | null | undefined): html is string;
|
|
21
|
+
/**
|
|
22
|
+
* The completion text without anything that runs code: script and frame elements, `on*`
|
|
23
|
+
* attributes and `javascript:` (or `data:` outside images) URLs. Parsed in an inert document, so
|
|
24
|
+
* nothing in it runs or loads while it is cleaned.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sanitizeCompletionHtml(html: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* The screen a learner sees when the course is completed: the title, the course's completion
|
|
29
|
+
* text (or the default text) and the actions. The completion texts were written for the old
|
|
30
|
+
* full-page completion article; the stylesheet keeps them inside the panel.
|
|
31
|
+
*/
|
|
32
|
+
export declare function CourseCompletion({ title, html, emptyText, actions, sanitize, className }: CourseCompletionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Heading, Paragraph } from "@digdir/designsystemet-react";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import "./CourseCompletion.css";
|
|
6
|
+
/** Whether the completion text has anything to show; the course feed treats blank text as none. */
|
|
7
|
+
export function hasCompletionText(html) {
|
|
8
|
+
return !!html?.trim();
|
|
9
|
+
}
|
|
10
|
+
const REMOVED_ELEMENTS = "script, iframe, frame, frameset, object, embed, base, meta, link, form";
|
|
11
|
+
const URL_ATTRIBUTES = new Set(["href", "src", "action", "formaction", "xlink:href", "srcdoc"]);
|
|
12
|
+
/**
|
|
13
|
+
* The completion text without anything that runs code: script and frame elements, `on*`
|
|
14
|
+
* attributes and `javascript:` (or `data:` outside images) URLs. Parsed in an inert document, so
|
|
15
|
+
* nothing in it runs or loads while it is cleaned.
|
|
16
|
+
*/
|
|
17
|
+
export function sanitizeCompletionHtml(html) {
|
|
18
|
+
let document = new DOMParser().parseFromString(`<body>${html}</body>`, "text/html");
|
|
19
|
+
for (let element of document.body.querySelectorAll(REMOVED_ELEMENTS))
|
|
20
|
+
element.remove();
|
|
21
|
+
for (let element of document.body.querySelectorAll("*")) {
|
|
22
|
+
// A copy, since removing attributes changes the live list
|
|
23
|
+
for (let attribute of Array.from(element.attributes)) {
|
|
24
|
+
let name = attribute.name.toLowerCase();
|
|
25
|
+
if (name.startsWith("on")) {
|
|
26
|
+
element.removeAttribute(attribute.name);
|
|
27
|
+
}
|
|
28
|
+
else if (URL_ATTRIBUTES.has(name)) {
|
|
29
|
+
// Browsers skip control characters and spaces in a scheme ("java\tscript:")
|
|
30
|
+
let value = [...attribute.value]
|
|
31
|
+
.filter((char) => char.charCodeAt(0) > 32)
|
|
32
|
+
.join("")
|
|
33
|
+
.toLowerCase();
|
|
34
|
+
let imageData = value.startsWith("data:image/") && name === "src" && element.tagName === "IMG";
|
|
35
|
+
if (name === "srcdoc" ||
|
|
36
|
+
value.startsWith("javascript:") ||
|
|
37
|
+
value.startsWith("vbscript:") ||
|
|
38
|
+
(value.startsWith("data:") && !imageData)) {
|
|
39
|
+
element.removeAttribute(attribute.name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return document.body.innerHTML;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The screen a learner sees when the course is completed: the title, the course's completion
|
|
48
|
+
* text (or the default text) and the actions. The completion texts were written for the old
|
|
49
|
+
* full-page completion article; the stylesheet keeps them inside the panel.
|
|
50
|
+
*/
|
|
51
|
+
export function CourseCompletion({ title, html, emptyText, actions, sanitize, className }) {
|
|
52
|
+
let shown = useMemo(() => {
|
|
53
|
+
if (!hasCompletionText(html))
|
|
54
|
+
return null;
|
|
55
|
+
return sanitize ? sanitizeCompletionHtml(html) : html;
|
|
56
|
+
}, [html, sanitize]);
|
|
57
|
+
return (_jsx("div", { className: clsx("ob-course-completion", className), children: _jsxs("div", { className: "ob-course-completion__panel", children: [_jsx(Heading, { level: 1, "data-size": "xl", children: title }), shown !== null ? (_jsx("div", { className: "ob-course-completion__text ds-paragraph",
|
|
58
|
+
// oxlint-disable-next-line react/no-danger -- written by the course editors; sanitize for previews
|
|
59
|
+
dangerouslySetInnerHTML: { __html: shown } })) : (_jsx(Paragraph, { "data-size": "lg", children: emptyText })), actions && _jsx("div", { className: "ob-course-completion__actions", children: actions })] }) }));
|
|
60
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Block, Cue, Step, Timed } from "./schema";
|
|
2
|
+
/** The cues of a step: a video's own, or a slide's or quiz's narration. */
|
|
3
|
+
export declare function getCues(step: Step): Cue[];
|
|
4
|
+
/**
|
|
5
|
+
* When the cue at `index` stops: its own `end`, else where the next cue starts. `Infinity` for a
|
|
6
|
+
* last cue without an end, which lasts until the media ends.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getCueEnd(cues: Cue[], index: number): number;
|
|
9
|
+
/** The cue being spoken at `time`. It may be a marker without text, which shows no subtitle. */
|
|
10
|
+
export declare function getActiveCue(cues: Cue[], time: number): Cue | undefined;
|
|
11
|
+
/** Whether any cue has a subtitle to show. */
|
|
12
|
+
export declare function hasCueText(cues: Cue[]): boolean;
|
|
13
|
+
/** The ids of every cue that has started at `time`. */
|
|
14
|
+
export declare function getStartedCueIds(cues: Cue[], time: number): Set<string>;
|
|
15
|
+
/** Every block, list item and canvas item of a slide in document order, columns flattened. */
|
|
16
|
+
export declare function getTimedParts(blocks: Block[]): Timed[];
|
|
17
|
+
/**
|
|
18
|
+
* The ids of the parts that wait for a press of Next, in the order they are shown. None on a
|
|
19
|
+
* narrated slide: there only the narration shows and hides parts, and Next goes to the next step.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getRevealSteps(blocks: Block[], narrated?: boolean): string[];
|
|
22
|
+
export interface RevealState {
|
|
23
|
+
/** How many of the `reveal: "step"` parts have been shown. */
|
|
24
|
+
stepsShown: number;
|
|
25
|
+
/** From `getRevealSteps`. */
|
|
26
|
+
revealSteps: string[];
|
|
27
|
+
/** From `getStartedCueIds`. */
|
|
28
|
+
startedCues: Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* From `getRevealLeaders`: the part each `reveal: "with-previous"` part follows. Left out, such a
|
|
31
|
+
* part is there from the start.
|
|
32
|
+
*/
|
|
33
|
+
leaders?: ReadonlyMap<string, Timed>;
|
|
34
|
+
/**
|
|
35
|
+
* The slide has narration. `reveal: "step"` then waits for nothing: a part with only that shows
|
|
36
|
+
* from the start, and one that also has `revealAt` follows its cue.
|
|
37
|
+
*/
|
|
38
|
+
narrated?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Whether a part waits to be shown by anything: Next, a cue, or the part it goes with. */
|
|
41
|
+
export declare function hasTrigger(part: Timed): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The part each `reveal: "with-previous"` part follows: the nearest part above it in document
|
|
44
|
+
* order that waits to be shown itself. A with-previous part with none is not in the map.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getRevealLeaders(blocks: Block[]): Map<string, Timed>;
|
|
47
|
+
/** Whether what a part waits for has happened, its `hideAt` aside. */
|
|
48
|
+
export declare function isDue(part: Timed, state: RevealState, seen?: Set<string>): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The reveal state of a slide after `stepsShown` presses of Next, with the narration at
|
|
51
|
+
* `startedCues`. On a narrated slide presses count for nothing; the cues decide.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getRevealState(blocks: Block[], stepsShown: number, startedCues: Set<string>, narrated?: boolean): RevealState;
|
|
54
|
+
export interface RevealNavigation {
|
|
55
|
+
/** The `stepsShown` a press of Next goes to, or null when no press would change what is shown. */
|
|
56
|
+
next: number | null;
|
|
57
|
+
/** The `stepsShown` a press of Back goes to, or null when going back would change nothing. */
|
|
58
|
+
previous: number | null;
|
|
59
|
+
/** How many presses change what is shown, from the first one; the count the stepper shows. */
|
|
60
|
+
presses: number;
|
|
61
|
+
/** How many of those are behind the learner. */
|
|
62
|
+
pressed: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Where Next and Back take a slide, so that every press shows something: a press that would change
|
|
66
|
+
* nothing is skipped. What is shown is every part's visibility, effects included. Back lands on
|
|
67
|
+
* the first press that shows what it goes back to, so Next and Back meet at the same places. On a
|
|
68
|
+
* narrated slide there are no presses: Next and Back go to the next and the previous step.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getRevealNavigation(blocks: Block[], stepsShown: number, startedCues: Set<string>, narrated?: boolean): RevealNavigation;
|
|
71
|
+
/**
|
|
72
|
+
* Whether a block or list item shows right now: what it waits for has happened (Next on a slide
|
|
73
|
+
* without narration, its cue, or the part it goes with), and its `hideAt` cue has not started.
|
|
74
|
+
*/
|
|
75
|
+
export declare function isVisible(part: Timed, state: RevealState): boolean;
|
|
76
|
+
/** Whether a step is a slide with narration, where only the narration shows and hides parts. */
|
|
77
|
+
export declare function isNarratedSlide(step: Step | null | undefined): boolean;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/** The cues of a step: a video's own, or a slide's or quiz's narration. */
|
|
2
|
+
export function getCues(step) {
|
|
3
|
+
if (step.type === "video")
|
|
4
|
+
return step.cues ?? [];
|
|
5
|
+
if (step.type === "slide" || step.type === "quiz")
|
|
6
|
+
return step.narration?.cues ?? [];
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* When the cue at `index` stops: its own `end`, else where the next cue starts. `Infinity` for a
|
|
11
|
+
* last cue without an end, which lasts until the media ends.
|
|
12
|
+
*/
|
|
13
|
+
export function getCueEnd(cues, index) {
|
|
14
|
+
return cues[index].end ?? cues[index + 1]?.start ?? Number.POSITIVE_INFINITY;
|
|
15
|
+
}
|
|
16
|
+
/** The cue being spoken at `time`. It may be a marker without text, which shows no subtitle. */
|
|
17
|
+
export function getActiveCue(cues, time) {
|
|
18
|
+
return cues.find((cue, index) => time >= cue.start && time < getCueEnd(cues, index));
|
|
19
|
+
}
|
|
20
|
+
/** Whether any cue has a subtitle to show. */
|
|
21
|
+
export function hasCueText(cues) {
|
|
22
|
+
return cues.some((cue) => cue.text != null && cue.text.trim() !== "");
|
|
23
|
+
}
|
|
24
|
+
/** The ids of every cue that has started at `time`. */
|
|
25
|
+
export function getStartedCueIds(cues, time) {
|
|
26
|
+
let started = new Set();
|
|
27
|
+
for (let cue of cues) {
|
|
28
|
+
if (time >= cue.start)
|
|
29
|
+
started.add(cue.id);
|
|
30
|
+
}
|
|
31
|
+
return started;
|
|
32
|
+
}
|
|
33
|
+
/** Every block, list item and canvas item of a slide in document order, columns flattened. */
|
|
34
|
+
export function getTimedParts(blocks) {
|
|
35
|
+
let parts = [];
|
|
36
|
+
function add(block) {
|
|
37
|
+
parts.push(block);
|
|
38
|
+
if (block.type === "list")
|
|
39
|
+
parts.push(...block.items);
|
|
40
|
+
if (block.type === "canvas")
|
|
41
|
+
parts.push(...block.items);
|
|
42
|
+
if (block.type === "columns") {
|
|
43
|
+
for (let column of block.columns)
|
|
44
|
+
column.blocks.forEach(add);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
blocks.forEach(add);
|
|
48
|
+
return parts;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The ids of the parts that wait for a press of Next, in the order they are shown. None on a
|
|
52
|
+
* narrated slide: there only the narration shows and hides parts, and Next goes to the next step.
|
|
53
|
+
*/
|
|
54
|
+
export function getRevealSteps(blocks, narrated = false) {
|
|
55
|
+
if (narrated)
|
|
56
|
+
return [];
|
|
57
|
+
return getTimedParts(blocks)
|
|
58
|
+
.filter((part) => part.reveal === "step")
|
|
59
|
+
.map((part) => part.id);
|
|
60
|
+
}
|
|
61
|
+
/** Whether a part waits to be shown by anything: Next, a cue, or the part it goes with. */
|
|
62
|
+
export function hasTrigger(part) {
|
|
63
|
+
return part.reveal != null || part.revealAt != null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The part each `reveal: "with-previous"` part follows: the nearest part above it in document
|
|
67
|
+
* order that waits to be shown itself. A with-previous part with none is not in the map.
|
|
68
|
+
*/
|
|
69
|
+
export function getRevealLeaders(blocks) {
|
|
70
|
+
let leaders = new Map();
|
|
71
|
+
let previous;
|
|
72
|
+
for (let part of getTimedParts(blocks)) {
|
|
73
|
+
if (part.reveal === "with-previous" && previous)
|
|
74
|
+
leaders.set(part.id, previous);
|
|
75
|
+
if (hasTrigger(part))
|
|
76
|
+
previous = part;
|
|
77
|
+
}
|
|
78
|
+
return leaders;
|
|
79
|
+
}
|
|
80
|
+
/** Whether what a part waits for has happened, its `hideAt` aside. */
|
|
81
|
+
export function isDue(part, state, seen = new Set()) {
|
|
82
|
+
if (!hasTrigger(part))
|
|
83
|
+
return true;
|
|
84
|
+
if (part.reveal === "step") {
|
|
85
|
+
// On a narrated slide Next shows nothing: only a cue can hold the part back
|
|
86
|
+
if (state.narrated)
|
|
87
|
+
return part.revealAt == null || state.startedCues.has(part.revealAt);
|
|
88
|
+
let index = state.revealSteps.indexOf(part.id);
|
|
89
|
+
if (index !== -1 && index < state.stepsShown)
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (part.revealAt != null && state.startedCues.has(part.revealAt))
|
|
93
|
+
return true;
|
|
94
|
+
if (part.reveal === "with-previous") {
|
|
95
|
+
let leader = state.leaders?.get(part.id);
|
|
96
|
+
if (!leader)
|
|
97
|
+
return true;
|
|
98
|
+
// The map only points up the document, but a hand-made one must not loop
|
|
99
|
+
if (seen.has(part.id))
|
|
100
|
+
return false;
|
|
101
|
+
seen.add(part.id);
|
|
102
|
+
return isDue(leader, state, seen);
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The reveal state of a slide after `stepsShown` presses of Next, with the narration at
|
|
108
|
+
* `startedCues`. On a narrated slide presses count for nothing; the cues decide.
|
|
109
|
+
*/
|
|
110
|
+
export function getRevealState(blocks, stepsShown, startedCues, narrated = false) {
|
|
111
|
+
return {
|
|
112
|
+
stepsShown: narrated ? 0 : stepsShown,
|
|
113
|
+
revealSteps: getRevealSteps(blocks, narrated),
|
|
114
|
+
startedCues,
|
|
115
|
+
leaders: getRevealLeaders(blocks),
|
|
116
|
+
narrated,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Where Next and Back take a slide, so that every press shows something: a press that would change
|
|
121
|
+
* nothing is skipped. What is shown is every part's visibility, effects included. Back lands on
|
|
122
|
+
* the first press that shows what it goes back to, so Next and Back meet at the same places. On a
|
|
123
|
+
* narrated slide there are no presses: Next and Back go to the next and the previous step.
|
|
124
|
+
*/
|
|
125
|
+
export function getRevealNavigation(blocks, stepsShown, startedCues, narrated = false) {
|
|
126
|
+
let parts = getTimedParts(blocks);
|
|
127
|
+
let total = getRevealSteps(blocks, narrated).length;
|
|
128
|
+
let at = Math.max(0, Math.min(stepsShown, total));
|
|
129
|
+
let shown = (count) => {
|
|
130
|
+
let state = getRevealState(blocks, count, startedCues, narrated);
|
|
131
|
+
return parts.map((part) => (isVisible(part, state) ? "1" : "0")).join("");
|
|
132
|
+
};
|
|
133
|
+
let states = Array.from({ length: total + 1 }, (_value, count) => shown(count));
|
|
134
|
+
let next = null;
|
|
135
|
+
for (let count = at + 1; count <= total; count++) {
|
|
136
|
+
if (states[count] !== states[at]) {
|
|
137
|
+
next = count;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
let previous = null;
|
|
142
|
+
for (let count = at - 1; count >= 0; count--) {
|
|
143
|
+
if (states[count] !== states[at]) {
|
|
144
|
+
previous = count;
|
|
145
|
+
while (previous > 0 && states[previous - 1] === states[previous])
|
|
146
|
+
previous -= 1;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
let presses = 0;
|
|
151
|
+
let pressed = 0;
|
|
152
|
+
for (let count = 1; count <= total; count++) {
|
|
153
|
+
if (states[count] === states[count - 1])
|
|
154
|
+
continue;
|
|
155
|
+
presses += 1;
|
|
156
|
+
if (count <= at)
|
|
157
|
+
pressed += 1;
|
|
158
|
+
}
|
|
159
|
+
return { next, previous, presses, pressed };
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Whether a block or list item shows right now: what it waits for has happened (Next on a slide
|
|
163
|
+
* without narration, its cue, or the part it goes with), and its `hideAt` cue has not started.
|
|
164
|
+
*/
|
|
165
|
+
export function isVisible(part, state) {
|
|
166
|
+
if (part.hideAt && state.startedCues.has(part.hideAt))
|
|
167
|
+
return false;
|
|
168
|
+
return isDue(part, state);
|
|
169
|
+
}
|
|
170
|
+
/** Whether a step is a slide with narration, where only the narration shows and hides parts. */
|
|
171
|
+
export function isNarratedSlide(step) {
|
|
172
|
+
return step?.type === "slide" && step.narration != null;
|
|
173
|
+
}
|