@olenbetong/synergi-course 0.0.0-stage → 2.0.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 (119) hide show
  1. package/README.md +27 -2
  2. package/es/Transitions.css +55 -0
  3. package/es/Transitions.d.ts +10 -0
  4. package/es/Transitions.js +24 -0
  5. package/es/chrome/CategoryHeader.css +94 -0
  6. package/es/chrome/CategoryHeader.d.ts +8 -0
  7. package/es/chrome/CategoryHeader.js +37 -0
  8. package/es/chrome/ProgressBar.css +16 -0
  9. package/es/chrome/ProgressBar.d.ts +9 -0
  10. package/es/chrome/ProgressBar.js +7 -0
  11. package/es/chrome/themeIconSets.d.ts +11 -0
  12. package/es/chrome/themeIconSets.js +25 -0
  13. package/es/document/cues.d.ts +32 -0
  14. package/es/document/cues.js +72 -0
  15. package/es/document/schema.d.ts +1373 -0
  16. package/es/document/schema.js +202 -0
  17. package/es/document/validate.d.ts +21 -0
  18. package/es/document/validate.js +100 -0
  19. package/es/i18n.d.ts +6 -0
  20. package/es/i18n.js +8 -0
  21. package/es/icons/BetongelementIcon.d.ts +2 -0
  22. package/es/icons/BetongelementIcon.js +4 -0
  23. package/es/icons/BetongvarerIcon.d.ts +2 -0
  24. package/es/icons/BetongvarerIcon.js +4 -0
  25. package/es/icons/FerdigbetongIcon.d.ts +2 -0
  26. package/es/icons/FerdigbetongIcon.js +4 -0
  27. package/es/icons/LogoElementIcon.d.ts +2 -0
  28. package/es/icons/LogoElementIcon.js +4 -0
  29. package/es/index.d.ts +8 -0
  30. package/es/index.js +7 -0
  31. package/es/media/Media.css +96 -0
  32. package/es/media/MediaControls.d.ts +25 -0
  33. package/es/media/MediaControls.js +30 -0
  34. package/es/media/Narration.d.ts +23 -0
  35. package/es/media/Narration.js +32 -0
  36. package/es/media/VideoPlayer.d.ts +16 -0
  37. package/es/media/VideoPlayer.js +65 -0
  38. package/es/media/icons.d.ts +11 -0
  39. package/es/media/icons.js +28 -0
  40. package/es/media/mediaHandle.d.ts +30 -0
  41. package/es/media/mediaHandle.js +123 -0
  42. package/es/media/useCueClock.d.ts +19 -0
  43. package/es/media/useCueClock.js +40 -0
  44. package/es/player/CoursePlayer.css +157 -0
  45. package/es/player/CoursePlayer.d.ts +29 -0
  46. package/es/player/CoursePlayer.js +199 -0
  47. package/es/player/LanguageMenu.d.ts +8 -0
  48. package/es/player/LanguageMenu.js +11 -0
  49. package/es/player/StartScreen.d.ts +6 -0
  50. package/es/player/StartScreen.js +12 -0
  51. package/es/player/useNavigationKeys.d.ts +7 -0
  52. package/es/player/useNavigationKeys.js +43 -0
  53. package/es/steps/Blocks.d.ts +14 -0
  54. package/es/steps/Blocks.js +69 -0
  55. package/es/steps/Markdown.d.ts +4 -0
  56. package/es/steps/Markdown.js +13 -0
  57. package/es/steps/PdfStepView.d.ts +6 -0
  58. package/es/steps/PdfStepView.js +14 -0
  59. package/es/steps/QuizStepView.css +18 -0
  60. package/es/steps/QuizStepView.d.ts +11 -0
  61. package/es/steps/QuizStepView.js +124 -0
  62. package/es/steps/SlideStepView.d.ts +9 -0
  63. package/es/steps/SlideStepView.js +42 -0
  64. package/es/steps/StepBodyProps.d.ts +16 -0
  65. package/es/steps/StepBodyProps.js +1 -0
  66. package/es/steps/StepView.css +380 -0
  67. package/es/steps/StepView.d.ts +38 -0
  68. package/es/steps/StepView.js +44 -0
  69. package/es/steps/VideoStepView.d.ts +6 -0
  70. package/es/steps/VideoStepView.js +23 -0
  71. package/es/types.d.ts +101 -0
  72. package/es/types.js +1 -0
  73. package/package.json +60 -3
  74. package/src/Transitions.css +55 -0
  75. package/src/Transitions.ts +35 -0
  76. package/src/chrome/CategoryHeader.css +94 -0
  77. package/src/chrome/CategoryHeader.test.tsx +150 -0
  78. package/src/chrome/CategoryHeader.tsx +70 -0
  79. package/src/chrome/ProgressBar.css +16 -0
  80. package/src/chrome/ProgressBar.tsx +18 -0
  81. package/src/chrome/themeIconSets.tsx +33 -0
  82. package/src/document/cues.ts +87 -0
  83. package/src/document/document.test.ts +251 -0
  84. package/src/document/schema.ts +263 -0
  85. package/src/document/validate.ts +117 -0
  86. package/src/i18n.ts +11 -0
  87. package/src/icons/BetongelementIcon.tsx +53 -0
  88. package/src/icons/BetongvarerIcon.tsx +40 -0
  89. package/src/icons/FerdigbetongIcon.tsx +53 -0
  90. package/src/icons/LogoElementIcon.tsx +23 -0
  91. package/src/index.ts +59 -0
  92. package/src/media/Media.css +96 -0
  93. package/src/media/MediaControls.tsx +100 -0
  94. package/src/media/Narration.tsx +77 -0
  95. package/src/media/VideoPlayer.tsx +128 -0
  96. package/src/media/icons.tsx +76 -0
  97. package/src/media/mediaHandle.test.ts +90 -0
  98. package/src/media/mediaHandle.ts +152 -0
  99. package/src/media/useCueClock.ts +55 -0
  100. package/src/player/CoursePlayer.css +157 -0
  101. package/src/player/CoursePlayer.test.tsx +452 -0
  102. package/src/player/CoursePlayer.tsx +349 -0
  103. package/src/player/LanguageMenu.tsx +40 -0
  104. package/src/player/StartScreen.tsx +33 -0
  105. package/src/player/useNavigationKeys.ts +49 -0
  106. package/src/steps/Blocks.tsx +169 -0
  107. package/src/steps/Markdown.tsx +18 -0
  108. package/src/steps/PdfStepView.tsx +43 -0
  109. package/src/steps/QuizStepView.css +18 -0
  110. package/src/steps/QuizStepView.test.tsx +201 -0
  111. package/src/steps/QuizStepView.tsx +292 -0
  112. package/src/steps/SlideStepView.tsx +84 -0
  113. package/src/steps/StepBodyProps.ts +17 -0
  114. package/src/steps/StepView.css +380 -0
  115. package/src/steps/StepView.test.tsx +37 -0
  116. package/src/steps/StepView.tsx +114 -0
  117. package/src/steps/VideoStepView.tsx +52 -0
  118. package/src/test/setup.ts +28 -0
  119. package/src/types.ts +113 -0
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
- # Temporary Holding Version
1
+ # @olenbetong/synergi-course
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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,55 @@
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
+ }
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,94 @@
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
+ }
@@ -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,32 @@
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 and list item of a slide in document order, columns flattened. */
16
+ export declare function getTimedParts(blocks: Block[]): Timed[];
17
+ /** The ids of the parts that wait for a press of Next, in the order they are shown. */
18
+ export declare function getRevealSteps(blocks: Block[]): string[];
19
+ export interface RevealState {
20
+ /** How many of the `reveal: "step"` parts have been shown. */
21
+ stepsShown: number;
22
+ /** From `getRevealSteps`. */
23
+ revealSteps: string[];
24
+ /** From `getStartedCueIds`. */
25
+ startedCues: Set<string>;
26
+ }
27
+ /**
28
+ * Whether a block or list item shows right now. A part that both waits for Next and has
29
+ * `revealAt` shows when either happens, so a narrated slide can still be stepped through
30
+ * without sound.
31
+ */
32
+ export declare function isVisible(part: Timed, state: RevealState): boolean;
@@ -0,0 +1,72 @@
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 and list 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 === "columns") {
41
+ for (let column of block.columns)
42
+ column.blocks.forEach(add);
43
+ }
44
+ }
45
+ blocks.forEach(add);
46
+ return parts;
47
+ }
48
+ /** The ids of the parts that wait for a press of Next, in the order they are shown. */
49
+ export function getRevealSteps(blocks) {
50
+ return getTimedParts(blocks)
51
+ .filter((part) => part.reveal === "step")
52
+ .map((part) => part.id);
53
+ }
54
+ /**
55
+ * Whether a block or list item shows right now. A part that both waits for Next and has
56
+ * `revealAt` shows when either happens, so a narrated slide can still be stepped through
57
+ * without sound.
58
+ */
59
+ export function isVisible(part, state) {
60
+ if (part.hideAt && state.startedCues.has(part.hideAt))
61
+ return false;
62
+ let waitsForStep = part.reveal === "step";
63
+ let waitsForCue = part.revealAt != null;
64
+ if (!waitsForStep && !waitsForCue)
65
+ return true;
66
+ if (waitsForStep) {
67
+ let index = state.revealSteps.indexOf(part.id);
68
+ if (index !== -1 && index < state.stepsShown)
69
+ return true;
70
+ }
71
+ return waitsForCue && state.startedCues.has(part.revealAt);
72
+ }