@media-quest/engine 0.0.14 → 0.0.15

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 (60) hide show
  1. package/package.json +1 -2
  2. package/src/Delement/DElement.dto.ts +5 -0
  3. package/src/Delement/DElement.ts +78 -253
  4. package/src/Delement/DImg.ts +31 -70
  5. package/src/Delement/DStyle.ts +156 -156
  6. package/src/Delement/DText.ts +9 -25
  7. package/src/Delement/Ddiv.ts +10 -23
  8. package/src/Delement/button-click-action.ts +11 -0
  9. package/src/Delement/element-factory.ts +40 -0
  10. package/src/engine/DCommand.ts +21 -0
  11. package/src/engine/SchemaDto.ts +24 -0
  12. package/src/engine/SchemaEngine.ts +48 -120
  13. package/src/{player → engine}/dplayer.spec.ts +20 -17
  14. package/src/{player → engine}/dplayer.ts +29 -16
  15. package/src/engine/history-que.spec.ts +59 -0
  16. package/src/engine/history-que.ts +39 -0
  17. package/src/{player → engine}/next-que.spec.ts +19 -8
  18. package/src/engine/next-que.ts +93 -0
  19. package/src/page/Page.ts +160 -0
  20. package/src/page/media-player.ts +117 -0
  21. package/src/page/page-component.ts +113 -0
  22. package/src/page/page-result.ts +11 -0
  23. package/src/page/task-manager.ts +203 -0
  24. package/src/page/task-state.ts +55 -0
  25. package/src/page/task.ts +87 -0
  26. package/src/public-api.ts +17 -13
  27. package/src/rules/__test__/rule-engine.spec.ts +1 -1
  28. package/src/utils/DUtil.ts +110 -103
  29. package/tsconfig.tsbuildinfo +1 -0
  30. package/dist/public-api.js +0 -2245
  31. package/dist/public-api.mjs +0 -2205
  32. package/src/Delement/AudioContainer.ts +0 -169
  33. package/src/Delement/DAuto-play.ts +0 -36
  34. package/src/Delement/VideoContainer.ts +0 -199
  35. package/src/commands/DCommand.ts +0 -63
  36. package/src/commands/DCommandBus.ts +0 -60
  37. package/src/dto/AnimationDto.ts +0 -4
  38. package/src/dto/DElement.dto.ts +0 -46
  39. package/src/dto/SchemaDto.ts +0 -65
  40. package/src/engine/DPage.ts +0 -60
  41. package/src/engine/element-factory.ts +0 -52
  42. package/src/event-handlers/DEventHandler.ts +0 -29
  43. package/src/events/DEvents.ts +0 -94
  44. package/src/events/event-bus.spec.ts +0 -21
  45. package/src/events/event-bus.ts +0 -81
  46. package/src/kladd/context-menu-manager.ts +0 -56
  47. package/src/player/history-que.spec.ts +0 -46
  48. package/src/player/history-que.ts +0 -38
  49. package/src/player/next-que.ts +0 -93
  50. package/src/services/DMedia-manager.spec.ts +0 -27
  51. package/src/services/DMedia-manager.ts +0 -179
  52. package/src/services/resource-provider.ts +0 -33
  53. package/src/services/sequence-manager.spec.ts +0 -168
  54. package/src/services/sequence-manager.ts +0 -133
  55. package/src/state/Dstate.spec.ts +0 -7
  56. package/src/state/Dstate.ts +0 -105
  57. package/src/state/boolean-property.ts +0 -69
  58. package/src/state/state-service.spec.ts +0 -307
  59. package/src/state/state-service.ts +0 -251
  60. package/src/state/state-testing-helpers.ts +0 -59
@@ -1,169 +0,0 @@
1
- import { CanPlayToEnd } from "./VideoContainer";
2
- import { DAudioDto } from "../dto/DElement.dto";
3
- import { DEventDispatcher } from "../events/event-bus";
4
- import { DTimestamp } from "../common/DTimestamp";
5
-
6
- export class AudioContainer implements CanPlayToEnd {
7
- private readonly TAG = "[ DAudio ]: ";
8
- protected dto: DAudioDto | null = null;
9
- private el: HTMLAudioElement;
10
- constructor(private readonly eventBus: DEventDispatcher) {
11
- this.el = document.createElement("audio");
12
- this.el.style.position = "absolute";
13
- this.el.style.visibility = "hidden";
14
- // this.el.on
15
- this.onLoad = this.onLoad.bind(this);
16
- this.el.onload = this.onLoad;
17
- this.onLoadedMetadata = this.onLoadedMetadata.bind(this);
18
- this.el.onloadedmetadata = this.onLoadedMetadata;
19
- this.el.onplay = () => {
20
- // TODO
21
- };
22
- this.onCanPlayThrough = this.onCanPlayThrough.bind(this);
23
- this.el.oncanplaythrough = this.onCanPlayThrough;
24
- this.el.onended = (_) => {
25
- const url = this.el.src;
26
- this.eventBus.emit({
27
- kind: "AUDIO_ENDED_EVENT",
28
- data: { url },
29
- producer: "DAudio",
30
- timestamp: DTimestamp.now(),
31
- producerId: this.id,
32
- });
33
- };
34
- this.el.ondurationchange = (_: Event) => {
35
- const duration = this.el.duration;
36
- const isInfinity = duration === Number.POSITIVE_INFINITY;
37
- this.eventBus.emit({
38
- kind: "AUDIO_DURATION_CHANGE_EVENT",
39
- timestamp: DTimestamp.now(),
40
- producer: "DAudio",
41
- producerId: this.id,
42
- data: { duration: this.el.duration, isInfinity },
43
- });
44
- };
45
- }
46
-
47
- setAudio(dto: DAudioDto) {
48
- this.dto = dto;
49
- this.el.src = dto.url;
50
- this.el.load();
51
- }
52
-
53
- destroy() {
54
- try {
55
- this.el.pause();
56
- this.el.src = "";
57
- this.el.load();
58
- } catch (e) {
59
- console.log(e);
60
- }
61
- }
62
-
63
- pause() {
64
- try {
65
- this.el.pause();
66
- } catch (e) {
67
- // TODO EMIT ERROR EVENT.
68
- console.log(e);
69
- }
70
- }
71
-
72
- play(url: string) {
73
- if (this.el.src !== url) {
74
- this.el.src = url;
75
- }
76
- this.eventBus.emit({
77
- kind: "AUDIO_PLAY_EVENT",
78
- producerId: this.id,
79
- data: {},
80
- producer: "DAudio",
81
- timestamp: DTimestamp.now(),
82
- });
83
- this.el
84
- .play()
85
- .then((res) => {
86
- console.log(res);
87
- })
88
- .catch((e) => {
89
- console.log(e);
90
- });
91
- }
92
-
93
- onLoadedMetadata(_: Event) {
94
- this.eventBus.emit({
95
- kind: "AUDIO_METADATA_LOADED_EVENT",
96
- timestamp: DTimestamp.now(),
97
- producer: "DAudio",
98
- producerId: this.id,
99
- data: {},
100
- });
101
- }
102
-
103
- onLoad(_: Event) {
104
- this.eventBus.emit({
105
- kind: "AUDIO_LOAD_EVENT",
106
- timestamp: DTimestamp.now(),
107
- producer: "DAudio",
108
- producerId: this.id,
109
- data: {},
110
- });
111
- // console.log(this.TAG + event.type);
112
- }
113
-
114
- get id() {
115
- return this.dto?.id ?? "DAudio";
116
- }
117
-
118
- private onCanPlayThrough(_: Event) {
119
- this.eventBus.emit({
120
- kind: "AUDIO_CAN_PLAY_THROUGH_EVENT",
121
- data: {},
122
- producer: "DAudio",
123
- timestamp: DTimestamp.now(),
124
- producerId: this.id,
125
- });
126
- }
127
-
128
- // private onPlay(_: Event) {}
129
-
130
- async playToEnd(): Promise<boolean> {
131
- const endedOrErrored = new Promise<boolean>((resolve) => {
132
- this.el.addEventListener(
133
- "ended",
134
- (_) => {
135
- // console.log(e);
136
- resolve(true);
137
- },
138
- { once: true }
139
- );
140
- this.el.addEventListener(
141
- "error",
142
- (_) => {
143
- // console.log(e);
144
- resolve(false);
145
- },
146
- { once: true }
147
- );
148
- });
149
- try {
150
- this.play(this.el.src);
151
- await endedOrErrored;
152
- return true;
153
- } catch (e) {
154
- // TODO LET PARENT DEAL WITH ERRORS? THE MANAGER?? MANAGERS CALL ABORT.
155
- console.log(e);
156
- this.eventBus.emit({
157
- kind: "AUDIO_ERROR_EVENT",
158
- timestamp: DTimestamp.now(),
159
- producer: "DAudio",
160
- producerId: this.id,
161
- data: { error: e },
162
- });
163
- return false;
164
- } finally {
165
- }
166
-
167
- return Promise.resolve(false);
168
- }
169
- }
@@ -1,36 +0,0 @@
1
- import { DCommand } from "../commands/DCommand";
2
-
3
- /**
4
- * Autoplay video by Id.
5
- */
6
- export interface AutoPlayVideo {
7
- readonly kind: "autoplay-video";
8
- readonly muted?: boolean;
9
- readonly startAt?: number;
10
- readonly videoId: string;
11
- }
12
-
13
- /**
14
- * Add a pause between auto-play elements.
15
- * TODO Not implemented
16
- */
17
- export interface AutoPlayPause {
18
- readonly kind: "autoplay-pause";
19
- readonly duration: number;
20
- }
21
-
22
- export interface AutoPlayAudio {
23
- readonly kind: "autoplay-audio";
24
- readonly audioId: string;
25
- readonly startAt?: number;
26
- }
27
-
28
- export type AutoPlayElement = AutoPlayVideo | AutoPlayAudio | AutoPlayPause;
29
-
30
- export interface DAutoPlaySequence {
31
- readonly id: string;
32
- readonly blockUserInput: boolean;
33
- readonly items: Array<AutoPlayAudio | AutoPlayVideo | AutoPlayPause>;
34
- readonly startCommands: ReadonlyArray<DCommand>;
35
- readonly endCommands: ReadonlyArray<DCommand>;
36
- }
@@ -1,199 +0,0 @@
1
- import { DVideoDto } from "../dto/DElement.dto";
2
- import { DTimestamp } from "../common/DTimestamp";
3
- import { DEventDispatcher } from "../events/event-bus";
4
- import { ScaleService } from "../engine/scale";
5
- import { DStyle } from "./DStyle";
6
- import { DUtil } from "../utils/DUtil";
7
-
8
- const ABORT_PLAY_TO_END = "ABORT_PLAY_TO_END";
9
- export interface CanPlayToEnd {
10
- playToEnd(): Promise<boolean>;
11
- }
12
-
13
- export class VideoContainer implements CanPlayToEnd {
14
- private readonly TAG: string;
15
- private dto?: DVideoDto;
16
- private defaultStyles: Partial<DStyle> = { h: 45, w: 100, visibility: "hidden", y: 55 };
17
-
18
- pause() {
19
- this.eventBus.emit({
20
- kind: "VIDEO_PAUSED_EVENT",
21
- data: {},
22
- producer: "DVideo",
23
- producerId: this.id,
24
- timestamp: DTimestamp.now(),
25
- });
26
- this.el.pause();
27
- }
28
-
29
- play(url: string) {
30
- if (this.el.src !== url) {
31
- this.el.src = url;
32
- }
33
- const producerId = this.dto?.id ?? "DVideo";
34
- this.eventBus.emit({
35
- kind: "VIDEO_PLAY_EVENT",
36
- data: {},
37
- producer: "DVideo",
38
- producerId,
39
- timestamp: DTimestamp.now(),
40
- });
41
- this.el
42
- .play()
43
- .then((res) => {
44
- console.log(res);
45
- })
46
- .catch((e) => {
47
- console.log(e);
48
- });
49
- // if(this.el.src !== url) {
50
- // this.
51
- // }
52
- }
53
-
54
- async playToEnd() {
55
- this.el.volume = 1;
56
- const url = this.dto?.url;
57
- if (!url) {
58
- return false;
59
- }
60
-
61
- try {
62
- const endedOrErrored = new Promise<boolean>((resolve, reject) => {
63
- this.el.addEventListener(
64
- "ended",
65
- (_) => {
66
- resolve(true);
67
- },
68
- { once: true }
69
- );
70
- this.el.addEventListener(
71
- "error",
72
- (_) => {
73
- resolve(false);
74
- },
75
- { once: true }
76
- );
77
- this.el.addEventListener(
78
- ABORT_PLAY_TO_END,
79
- () => {
80
- console.log("CATCHED ABBORT.");
81
- reject("Aborted");
82
- },
83
- { once: true }
84
- );
85
- });
86
- // console.log("PLAY");
87
- this.play(url);
88
- await endedOrErrored;
89
- return true;
90
- } catch (e) {
91
- console.log(e);
92
- return false;
93
- } finally {
94
- console.log(this.TAG + " finally block playToEnd() completed videoId: " + this.dto?.id);
95
- }
96
- }
97
-
98
- constructor(
99
- private readonly el: HTMLVideoElement,
100
- private readonly eventBus: DEventDispatcher,
101
- private readonly scale: ScaleService // dto?: DVideoDto
102
- ) {
103
- this.TAG = "[ D_Video ] : ";
104
- this.el.controls = false;
105
- DStyle.normalize(this.el);
106
- DStyle.applyStyles(this.el, this.defaultStyles, this.scale.scale);
107
-
108
- this.el.onended = () => {
109
- this.eventBus.emit({
110
- kind: "VIDEO_ENDED_EVENT",
111
- timestamp: DTimestamp.now(),
112
- producer: "DVideo",
113
- producerId: this.id,
114
- data: {},
115
- });
116
- };
117
- this.el.onplay = () => {
118
- // TODO LOGG INTERNAL STATE_CHANGES.
119
- };
120
-
121
- this.el.onpause = () => {};
122
- this.el.onerror = () => {};
123
- this.el.oncanplay = () => {
124
- // console.groupCollapsed(this.TAG + "READY TO PLAY");
125
- // console.log("Duration: " + this.el.duration);
126
- // console.log("Id: " + this.id);
127
- // console.log("Current Time: " + this.el.currentTime);
128
- // console.log("AudoPlay: " + this.el.autoplay);
129
- // console.groupEnd();
130
- };
131
- this.el.onloadedmetadata = () => {
132
- const duration = this.el.duration;
133
- const isInfinity = DUtil.isInfinity(duration);
134
- this.eventBus.emit({
135
- kind: "VIDEO_LOADED_METADATA_EVENT",
136
- timestamp: DTimestamp.now(),
137
- producer: "DVideo",
138
- producerId: this.id,
139
- data: { duration, isInfinity },
140
- });
141
- };
142
- // TODO USE THIS SYNTAX?
143
- this.el.ondurationchange = () => {
144
- const duration = this.el.duration;
145
- const isInfinity = DUtil.isInfinity(duration);
146
- this.eventBus.emit({
147
- kind: "VIDEO_DURATION_CHANGE_EVENT",
148
- producer: "DVideo",
149
- producerId: this.id,
150
- timestamp: DTimestamp.now(),
151
- data: { duration, isInfinity },
152
- });
153
- };
154
- }
155
-
156
- getStats() {
157
- const duration = this.el.duration;
158
- const currentTime = this.el.currentTime;
159
- const volume = this.el.volume;
160
- const isConnected = this.el.isConnected;
161
- const playbackQuality = this.el.getVideoPlaybackQuality();
162
- const defaultPlaybackRate = this.el.defaultPlaybackRate;
163
- const paused = this.el.paused;
164
- const played = this.el.played;
165
-
166
- return {
167
- duration,
168
- paused,
169
- played,
170
- currentTime,
171
- volume,
172
- isConnected,
173
- playbackQuality,
174
- defaultPlaybackRate,
175
- };
176
- }
177
-
178
- setDto(dto: DVideoDto) {
179
- this.dto = dto;
180
- this.el.volume = 1;
181
- this.setStyle(dto.style);
182
- this.el.src = dto.url;
183
- this.el.load();
184
- }
185
-
186
- getCurrentDto(): DVideoDto | false {
187
- return this.dto ?? false;
188
- }
189
-
190
- setStyle(styles: Partial<DStyle>) {
191
- DStyle.applyStyles(this.el, styles, this.scale.scale);
192
- }
193
-
194
- private get id() {
195
- return this.dto?.id ?? "DVideo";
196
- }
197
-
198
- destroy() {}
199
- }
@@ -1,63 +0,0 @@
1
- import { DStyle } from "../Delement/DStyle";
2
- import { AnimationDto } from "../dto/AnimationDto";
3
- import { Fact } from "../rules/fact";
4
- import { DState } from "../state/Dstate";
5
- import { PageID } from "../utils/ID";
6
-
7
- type CommandTarget = "VIDEO" | "AUDIO" | "ELEMENT" | "PAGE_QUE" | "ENGINE" | "STATE";
8
- type CommandKind = `${Uppercase<CommandTarget>}_${Uppercase<string>}_COMMAND`;
9
-
10
- export type StateCommand = CommandDto<"STATE_MUTATE_COMMAND", "STATE", { mutation: DState.StateMutation }>;
11
- // export type StateCommand = CommandDto<"STATE_MUTATE_COMMAND", "STATE", { mutation: DState.StateMutation }>;
12
-
13
- export type NavigationCommand =
14
- | CommandDto<"PAGE_QUE_NEXT_PAGE_COMMAND", "PAGE_QUE", {}>
15
- | CommandDto<"PAGE_QUE_GO_TO_SEQUENCE_COMMAND", "PAGE_QUE", { sequenceId: string }>
16
- | CommandDto<"PAGE_QUE_GO_TO_PAGE_COMMAND", "PAGE_QUE", { pageId: string }>;
17
-
18
- export type EngineCommand = CommandDto<
19
- "ENGINE_LEAVE_PAGE_COMMAND",
20
- "ENGINE",
21
- {
22
- readonly pageId: string;
23
- readonly factsCollected: ReadonlyArray<Fact>;
24
- }
25
- >;
26
-
27
- interface CommandDto<K extends CommandKind, T extends CommandTarget, P> {
28
- readonly kind: K;
29
- readonly target: T;
30
- readonly targetId: T | Omit<string, T>;
31
- readonly payload: P;
32
- }
33
-
34
- export type VideoCommand =
35
- | CommandDto<"VIDEO_PLAY_COMMAND", "VIDEO", { volume?: number }>
36
- | CommandDto<"VIDEO_SET_VOLUME_COMMAND", "VIDEO", { volume: number }>
37
- | CommandDto<"VIDEO_JUMP_TO_COMMAND", "VIDEO", { volume?: number; ms: number }>
38
- | CommandDto<"VIDEO_PAUSE_COMMAND", "VIDEO", {}>;
39
-
40
- export type AudioCommand =
41
- | CommandDto<"AUDIO_PAUSE_COMMAND", "AUDIO", {}>
42
- | CommandDto<"AUDIO_PLAY_COMMAND", "AUDIO", { volume?: number; startAt?: number }>
43
- | CommandDto<"AUDIO_SET_VOLUME_COMMAND", "AUDIO", { volume: number }>;
44
-
45
- export type ElementCommand =
46
- | CommandDto<"ELEMENT_ANIMATE_COMMAND", "ELEMENT", AnimationDto>
47
- | CommandDto<"ELEMENT_DISABLE_CLICK_COMMAND", "ELEMENT", {}>
48
- | CommandDto<"ELEMENT_ENABLE_CLICK_COMMAND", "ELEMENT", {}>
49
- | CommandDto<"ELEMENT_STYLE_COMMAND", "ELEMENT", { changes: Partial<DStyle>; clickIsAllowed?: boolean }>;
50
-
51
- export type PageQueCommand =
52
- | CommandDto<"PAGE_QUE_EXCLUDE_BY_TAG_COMMAND", "PAGE_QUE", { tagIds: string[] }>
53
- | CommandDto<"PAGE_QUE_EXCLUDE_BY_PAGE_ID_COMMAND", "PAGE_QUE", { pageIds: Array<PageID> }>
54
- | CommandDto<"PAGE_QUE_JUMP_TO_PAGE_COMMAND", "PAGE_QUE", { readonly pageId: string }>;
55
-
56
- export type DCommand =
57
- | StateCommand
58
- | NavigationCommand
59
- | VideoCommand
60
- | AudioCommand
61
- | ElementCommand
62
- | EngineCommand
63
- | PageQueCommand;
@@ -1,60 +0,0 @@
1
- import { DCommand } from "./DCommand";
2
- import { DTimestamp } from "../common/DTimestamp";
3
-
4
- export interface DCommandStore {
5
- subscribe(callback: () => void, subscriberId: string): void;
6
- }
7
-
8
- export interface DCommandDispatcher {
9
- emit(command: DCommand): void;
10
- }
11
-
12
- interface CommandSubscriberData {
13
- readonly subscriberId: string;
14
- readonly callback: (command: DCommand) => void;
15
- }
16
- export class DCommandBus implements DCommandStore, DCommandDispatcher {
17
- private readonly TAG = "[ COMMAND_BUS ] ";
18
- logCommands = false;
19
- private readonly commandLog: Array<DCommand & { timestamp: DTimestamp }> = [];
20
- readonly subscribers = new Set<CommandSubscriberData>();
21
- // readonly sub
22
-
23
- subscribe(cb: (command: DCommand) => void, subscriberId: string) {
24
- const sub: CommandSubscriberData = {
25
- subscriberId,
26
- callback: cb,
27
- };
28
-
29
- this.subscribers.add(sub);
30
- return () => {
31
- this.subscribers.delete(sub);
32
- };
33
- }
34
-
35
- emit(command: DCommand) {
36
- const timestamp = DTimestamp.now();
37
- this.commandLog.push({ ...command, timestamp });
38
- if (this.logCommands) {
39
- this.logCommand(command);
40
- }
41
- this.subscribers.forEach((subscriber) => {
42
- subscriber.callback(command);
43
- });
44
- }
45
-
46
- getStats() {
47
- return {
48
- commands: [...this.commandLog],
49
- subscribers: [...this.subscribers],
50
- subscribersCount: this.subscribers.size,
51
- };
52
- }
53
-
54
- private logCommand(command: DCommand) {
55
- console.groupCollapsed(this.TAG + " " + command.kind);
56
- console.log("TargetID : " + command.targetId);
57
- console.log(command.payload);
58
- console.groupEnd();
59
- }
60
- }
@@ -1,4 +0,0 @@
1
- export interface AnimationDto {
2
- readonly keyframes: Keyframe[];
3
- readonly options: { duration: number; startIn?: number };
4
- }
@@ -1,46 +0,0 @@
1
- import { DStyle } from "../Delement/DStyle";
2
- import { DEventHandler, QueryChangedHandler } from "../event-handlers/DEventHandler";
3
- import { DCommand } from "../commands/DCommand";
4
- export type DElementDto = DTextDto | DImgDto | DDivDto;
5
-
6
- interface DStateListener {
7
- readonly onStateChange?: ReadonlyArray<QueryChangedHandler>;
8
- }
9
-
10
- export interface DElementBaseDto extends DStateListener {
11
- readonly id: string;
12
- readonly style: Partial<DStyle>;
13
- readonly eventHandlers?: ReadonlyArray<DEventHandler>;
14
- readonly onClick?: ReadonlyArray<DCommand>;
15
- }
16
-
17
- export interface DTextDto extends DElementBaseDto {
18
- readonly _tag: "p";
19
- readonly text: string;
20
- }
21
-
22
- export interface DDivDto extends DElementBaseDto {
23
- readonly _tag: "div";
24
- readonly children: Array<DTextDto | DImgDto>;
25
- }
26
-
27
- export interface DImgDto extends DElementBaseDto {
28
- readonly _tag: "img";
29
- readonly url: string;
30
- }
31
-
32
- export interface DVideoDto extends DElementBaseDto {
33
- readonly _tag: "video";
34
- readonly url: string;
35
- // readonly mode: "gif" | "autoplay" | "on-demand";
36
- // readonly isMediaBlocking: boolean;
37
- }
38
-
39
- export interface DAudioDto {
40
- readonly id: string;
41
- readonly _tag: "audio";
42
- readonly url: string;
43
- // readonly eventHandlers: ReadonlyArray<DEventHandler>;
44
-
45
- // readonly isMediaBlocking: boolean;
46
- }
@@ -1,65 +0,0 @@
1
- import { DAutoPlaySequence } from "../Delement/DAuto-play";
2
- import { DAudioDto, DElementDto, DImgDto, DVideoDto } from "./DElement.dto";
3
- import { Rule } from "../rules/rule";
4
- import { Fact } from "../rules/fact";
5
- import { PageQueCommand } from "../commands/DCommand";
6
- import { DState } from "../state/Dstate";
7
- import { PageID, SchemaID } from "../utils/ID";
8
-
9
- export type PageQueRules = Rule<PageQueCommand, never>;
10
- export interface PageDto {
11
- readonly id: PageID;
12
- readonly elements: Array<DElementDto>;
13
- readonly tags?: string[];
14
- readonly mainVideoId?: string;
15
- readonly backgroundColor?: string;
16
- readonly video?: Array<DVideoDto>;
17
- readonly audio?: Array<DAudioDto>;
18
- readonly autoPlaySequence?: DAutoPlaySequence;
19
- }
20
-
21
- export interface PageSequenceDto {
22
- readonly id: string;
23
- readonly rules: Array<PageQueRules>;
24
- readonly pages: Array<PageDto>;
25
- }
26
-
27
- export interface SchemaDto {
28
- readonly id: SchemaID;
29
- readonly baseHeight: number;
30
- readonly baseWidth: number;
31
- readonly backgroundColor: string;
32
- readonly pages: PageDto[];
33
- readonly rules: Array<PageQueRules>;
34
- readonly stateProps?: ReadonlyArray<DState.Prop>;
35
- readonly stateQueries?: ReadonlyArray<DState.StateQuery>;
36
- readonly stateFromEvent: ReadonlyArray<DState.fromEventHandler>;
37
- readonly pageSequences?: Array<PageSequenceDto>;
38
- readonly predefinedFacts?: ReadonlyArray<Fact>;
39
- }
40
-
41
- export namespace SchemaDto {
42
- export const getResources = (
43
- schema: SchemaDto,
44
- ): {
45
- videoList: ReadonlyArray<DVideoDto>;
46
- audioList: ReadonlyArray<DAudioDto>;
47
- imageList: ReadonlyArray<DImgDto>;
48
- } => {
49
- const { pages } = schema;
50
- const videoList = pages.reduce<Array<DVideoDto>>((acc, curr) => {
51
- if (Array.isArray(curr.video)) {
52
- acc.push(...curr.video);
53
- }
54
- return acc;
55
- }, []);
56
- const audioList: Array<DAudioDto> = pages.reduce<Array<DAudioDto>>((acc, curr) => {
57
- if (Array.isArray(curr.audio)) {
58
- acc.push(...curr.audio);
59
- }
60
- return acc;
61
- }, []);
62
-
63
- return { videoList, audioList, imageList: [] };
64
- };
65
- }