@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,165 +1,165 @@
1
1
  import { DCss } from "./css";
2
- import { ElementKeyNames } from "./DStyle-utils";
3
2
  import { DUtil } from "../utils/DUtil";
4
3
 
5
4
  type DStyle2 = CSSStyleDeclaration;
5
+ export type PStyle = Partial<DStyle>;
6
6
  export interface DStyle {
7
- opacity: number;
8
- backgroundColor: string;
9
- visibility: "visible" | "hidden";
10
- cursor:
11
- | "pointer"
12
- | "help"
13
- | "copy"
14
- | "wait"
15
- | "not-allowed"
16
- | "context-menu"
17
- | "move"
18
- | "grabbing"
19
- | "grab"
20
- | "zoom-in"
21
- | "zoom-out"
22
- | "none"
23
- | "auto"
24
- | "default";
25
-
26
- // POSITION
27
- h: number;
28
- w: number;
29
- x: number;
30
- y: number;
31
-
32
- // BORDERS
33
- borderStyle: "solid" | "none" | "dotted" | "dashed";
34
- borderRadius: DCss.Px | DCss.Percent;
35
- borderWidth: DCss.Px;
36
- borderColor: string;
37
-
38
- margin: DCss.Px | DCss.Percent;
39
- padding: DCss.Px | DCss.Percent;
40
-
41
- // Translate
42
- transform: string;
43
- translate: string;
44
-
45
- // TEXT
46
- fontSize: DCss.Px;
47
- textColor: string;
48
- fontWeight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
49
- textAlign: "right" | "left" | "center";
50
- letterSpacing: DCss.Px;
7
+ opacity: number;
8
+ backgroundColor: string;
9
+ visibility: "visible" | "hidden";
10
+ cursor:
11
+ | "pointer"
12
+ | "help"
13
+ | "copy"
14
+ | "wait"
15
+ | "not-allowed"
16
+ | "context-menu"
17
+ | "move"
18
+ | "grabbing"
19
+ | "grab"
20
+ | "zoom-in"
21
+ | "zoom-out"
22
+ | "none"
23
+ | "auto"
24
+ | "default";
25
+
26
+ // POSITION
27
+ h: number;
28
+ w: number;
29
+ x: number;
30
+ y: number;
31
+
32
+ // BORDERS
33
+ borderStyle: "solid" | "none" | "dotted" | "dashed";
34
+ borderRadius: DCss.Px | DCss.Percent;
35
+ borderWidth: DCss.Px;
36
+ borderColor: string;
37
+
38
+ margin: DCss.Px | DCss.Percent;
39
+ padding: DCss.Px | DCss.Percent;
40
+
41
+ // Translate
42
+ transform: string;
43
+ translate: string;
44
+
45
+ // TEXT
46
+ fontSize: DCss.Px;
47
+ textColor: string;
48
+ fontWeight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
49
+ textAlign: "right" | "left" | "center";
50
+ letterSpacing: DCss.Px;
51
51
  }
52
52
 
53
53
  export namespace DStyle {
54
- export const normalize = <T extends HTMLElement>(el: T): T => {
55
- el.style.padding = "0";
56
- el.style.margin = "0";
57
- el.style.position = "absolute";
58
- el.style.boxSizing = "border-box";
59
- return el;
60
- };
61
-
62
- export const applyStyles = <T extends HTMLElement>(el: T, style: Partial<DStyle>, scale: number): T => {
63
- // const scalePx = DCss.toStringCre(this.scale);
64
- const {
65
- x,
66
- y,
67
- backgroundColor,
68
- borderColor,
69
- borderWidth,
70
- borderRadius,
71
- borderStyle,
72
- w,
73
- opacity,
74
- cursor,
75
- fontSize,
76
- fontWeight,
77
- textColor,
78
- textAlign,
79
- translate,
80
- margin,
81
- padding,
82
- letterSpacing,
83
- h,
84
- transform,
85
- visibility,
86
- } = style;
87
-
88
- // this.el.style.fontWeight = '900';
89
- if (backgroundColor) {
90
- el.style.backgroundColor = backgroundColor;
91
- }
92
-
93
- if (cursor) {
94
- el.style.cursor = cursor;
95
- }
96
-
97
- if (transform) {
98
- el.style.transform = transform;
99
- }
100
-
101
- if (textColor) {
102
- el.style.color = textColor;
103
- }
104
- if (textAlign) {
105
- el.style.textAlign = textAlign;
106
- }
107
-
108
- if (borderColor) {
109
- el.style.borderColor = borderColor;
110
- }
111
-
112
- if (borderWidth) {
113
- el.style.borderWidth = DCss.toString(borderWidth, scale);
114
- }
115
- if (fontWeight) {
116
- el.style.fontWeight = fontWeight + "";
117
- }
118
- if (borderStyle) {
119
- el.style.borderStyle = borderStyle;
120
- }
121
- if (fontSize) {
122
- el.style.fontSize = DCss.toString(fontSize, scale);
123
- }
124
-
125
- if (DUtil.isNumber(x)) {
126
- el.style.left = x + "%";
127
- }
128
- if (DUtil.isNumber(y)) {
129
- el.style.bottom = y + "%";
130
- }
131
-
132
- if (DUtil.isNumber(h)) {
133
- el.style.height = h + "%";
134
- }
135
- if (DUtil.isNumber(w)) {
136
- el.style.width = w + "%";
137
- }
138
-
139
- if (DCss.isLengthUnit(borderRadius)) {
140
- el.style.borderRadius = DCss.toString(borderRadius, scale);
141
- }
142
-
143
- if (letterSpacing) {
144
- el.style.letterSpacing = DCss.toString(letterSpacing, scale);
145
- }
146
- if (margin) {
147
- el.style.margin = DCss.toString(margin, scale);
148
- }
149
- if (padding) {
150
- el.style.padding = DCss.toString(padding, scale);
151
- }
152
-
153
- if (DUtil.isNumber(opacity)) {
154
- el.style.opacity = opacity + "";
155
- }
156
-
157
- if (visibility) {
158
- el.style.visibility = visibility;
159
- }
160
-
161
- return el;
162
- };
163
- // const propNames = new Set(...ElementKeyNames);
164
- // export const validKey = (keyName: string) => propNames.has(keyName);
54
+ export const normalize = <T extends HTMLElement>(el: T): T => {
55
+ el.style.padding = "0";
56
+ el.style.margin = "0";
57
+ el.style.position = "absolute";
58
+ el.style.boxSizing = "border-box";
59
+ return el;
60
+ };
61
+
62
+ export const applyStyles = <T extends HTMLElement>(el: T, style: Partial<DStyle>, scale: number): T => {
63
+ // const scalePx = DCss.toStringCre(this.scale);
64
+ const {
65
+ x,
66
+ y,
67
+ backgroundColor,
68
+ borderColor,
69
+ borderWidth,
70
+ borderRadius,
71
+ borderStyle,
72
+ w,
73
+ opacity,
74
+ cursor,
75
+ fontSize,
76
+ fontWeight,
77
+ textColor,
78
+ textAlign,
79
+ translate,
80
+ margin,
81
+ padding,
82
+ letterSpacing,
83
+ h,
84
+ transform,
85
+ visibility,
86
+ } = style;
87
+
88
+ // this.el.style.fontWeight = '900';
89
+ if (backgroundColor) {
90
+ el.style.backgroundColor = backgroundColor;
91
+ }
92
+
93
+ if (cursor) {
94
+ el.style.cursor = cursor;
95
+ }
96
+
97
+ if (transform) {
98
+ el.style.transform = transform;
99
+ }
100
+
101
+ if (textColor) {
102
+ el.style.color = textColor;
103
+ }
104
+ if (textAlign) {
105
+ el.style.textAlign = textAlign;
106
+ }
107
+
108
+ if (borderColor) {
109
+ el.style.borderColor = borderColor;
110
+ }
111
+
112
+ if (borderWidth) {
113
+ el.style.borderWidth = DCss.toString(borderWidth, scale);
114
+ }
115
+ if (fontWeight) {
116
+ el.style.fontWeight = fontWeight + "";
117
+ }
118
+ if (borderStyle) {
119
+ el.style.borderStyle = borderStyle;
120
+ }
121
+ if (fontSize) {
122
+ el.style.fontSize = DCss.toString(fontSize, scale);
123
+ }
124
+
125
+ if (DUtil.isNumber(x)) {
126
+ el.style.left = x + "%";
127
+ }
128
+ if (DUtil.isNumber(y)) {
129
+ el.style.bottom = y + "%";
130
+ }
131
+
132
+ if (DUtil.isNumber(h)) {
133
+ el.style.height = h + "%";
134
+ }
135
+ if (DUtil.isNumber(w)) {
136
+ el.style.width = w + "%";
137
+ }
138
+
139
+ if (DCss.isLengthUnit(borderRadius)) {
140
+ el.style.borderRadius = DCss.toString(borderRadius, scale);
141
+ }
142
+
143
+ if (letterSpacing) {
144
+ el.style.letterSpacing = DCss.toString(letterSpacing, scale);
145
+ }
146
+ if (margin) {
147
+ el.style.margin = DCss.toString(margin, scale);
148
+ }
149
+ if (padding) {
150
+ el.style.padding = DCss.toString(padding, scale);
151
+ }
152
+
153
+ if (DUtil.isNumber(opacity)) {
154
+ el.style.opacity = opacity + "";
155
+ }
156
+
157
+ if (visibility) {
158
+ el.style.visibility = visibility;
159
+ }
160
+
161
+ return el;
162
+ };
163
+ // const propNames = new Set(...ElementKeyNames);
164
+ // export const validKey = (keyName: string) => propNames.has(keyName);
165
165
  }
@@ -1,29 +1,13 @@
1
- import { DElement } from "./DElement";
2
- import { DTextDto } from "../dto/DElement.dto";
3
- import { DCommandBus } from "../commands/DCommandBus";
4
- import { EventBus } from "../events/event-bus";
1
+ import { DElement, DElementBaseDto } from "./DElement";
5
2
  import { ScaleService } from "../engine/scale";
6
3
 
7
- export class DText extends DElement<HTMLParagraphElement> {
8
- private readonly TAG = "[ DParagraph ]: ";
9
- protected defaultStyle = {};
10
-
11
- constructor(dto: DTextDto, eventBus: EventBus, actionService: DCommandBus, scale: ScaleService) {
12
- super(document.createElement("p"), eventBus, actionService, dto, scale);
13
- this.el.style.position = "absolute";
14
- this.el.innerText = "" + dto.text;
15
- this.setStyle(dto.style);
16
- }
17
-
18
- setScale(scale: number) {
19
- this.setStyle(this.currStyle);
20
- const fontSize = this.el.style.fontSize;
21
- console.log(this.TAG + "scale: " + scale + " Fontsize: " + fontSize);
22
- }
4
+ export interface DTextDto extends DElementBaseDto {
5
+ readonly _tag: "p";
6
+ readonly innerText: string;
7
+ }
23
8
 
24
- destroy() {
25
- this.subscriptions.forEach((unsubscribe) => {
26
- unsubscribe();
27
- });
28
- }
9
+ export class DText extends DElement<HTMLParagraphElement> {
10
+ constructor(dto: DTextDto, scale: ScaleService) {
11
+ super(document.createElement("p"), dto, scale);
12
+ }
29
13
  }
@@ -1,38 +1,25 @@
1
- import { DElement } from "./DElement";
2
- import { DDivDto } from "../dto/DElement.dto";
3
- import { DText } from "./DText";
4
- import { DImg } from "./DImg";
5
- import { DCommandBus } from "../commands/DCommandBus";
6
- import { EventBus } from "../events/event-bus";
1
+ import { DElement, DElementBaseDto } from "./DElement";
2
+ import { DText, DTextDto } from "./DText";
3
+ import { DImg, DImgDto } from "./DImg";
7
4
  import { ScaleService } from "../engine/scale";
8
5
 
6
+ export interface DDivDto extends DElementBaseDto {
7
+ readonly _tag: "div";
8
+ readonly children: Array<DTextDto | DImgDto>;
9
+ }
10
+
9
11
  export class DDiv extends DElement<HTMLDivElement> {
10
12
  private readonly TAG = "[ DDiv ]: ";
11
13
  protected readonly defaultStyle = { x: 22, y: 4 };
12
14
  private children: Array<DText | DImg> = [];
13
15
 
14
- constructor(
15
- dto: DDivDto,
16
- eventBus: EventBus,
17
- actionService: DCommandBus,
18
- scale: ScaleService,
19
- children: Array<DText | DImg>,
20
- ) {
16
+ constructor(dto: DDivDto, scale: ScaleService, children: Array<DText | DImg>) {
21
17
  const d = document.createElement("div");
22
- super(d, eventBus, actionService, dto, scale);
18
+ super(d, dto, scale);
23
19
  this.children = children;
24
20
 
25
21
  this.children.forEach((child) => {
26
22
  child.appendYourself(this.el);
27
23
  });
28
24
  }
29
-
30
- destroy(): void {
31
- this.subscriptions.forEach((unsubscribe) => {
32
- unsubscribe();
33
- });
34
- this.children.forEach((child) => {
35
- child.destroy();
36
- });
37
- }
38
25
  }
@@ -0,0 +1,11 @@
1
+ import { PlayAudioTask, PlayVideoTask } from "../page/task";
2
+ import { Fact } from "../rules/fact";
3
+
4
+ export type ButtonClickAction =
5
+ | { kind: "play-audio"; task: PlayAudioTask }
6
+ | { kind: "pause-audio" }
7
+ | { kind: "play-video"; task: PlayVideoTask }
8
+ | { kind: "pause-video" }
9
+ | { kind: "submit-fact"; fact: Fact }
10
+ | { kind: "next-page" }
11
+ | { kind: "submit-form" };
@@ -0,0 +1,40 @@
1
+ import { DElement } from "./DElement";
2
+ import { DDiv, DDivDto } from "./Ddiv";
3
+ import { DImg } from "./DImg";
4
+ import { DText } from "./DText";
5
+ import { ScaleService } from "../engine/scale";
6
+ import { DElementDto } from "./DElement.dto";
7
+
8
+ export const createDElement = (dto: DElementDto, scale: ScaleService): DElement<any> => {
9
+ switch (dto._tag) {
10
+ case "div":
11
+ const childEls = createChildrenForDiv(dto, scale);
12
+ const newDiv = new DDiv(dto, scale, childEls);
13
+ return newDiv;
14
+ case "img":
15
+ return new DImg(dto, scale);
16
+ case "p":
17
+ return new DText(dto, scale);
18
+ default:
19
+ const check: never = dto;
20
+ throw new Error("Unknown dto given to the createDElement function.");
21
+ // TODO LOGGING or create any HTML-ELEMENT??
22
+ }
23
+ };
24
+
25
+ const createChildrenForDiv = (dto: DDivDto, scale: ScaleService): DDiv["children"] => {
26
+ const childDto = dto.children;
27
+ const childEls: Array<DImg | DText> = [];
28
+ // console.log(childElements);
29
+ childDto.forEach((dto) => {
30
+ if (dto._tag === "p") {
31
+ const newText = new DText(dto, scale);
32
+ childEls.push(newText);
33
+ }
34
+ if (dto._tag === "img") {
35
+ const newImage = new DImg(dto, scale);
36
+ childEls.push(newImage);
37
+ }
38
+ });
39
+ return childEls;
40
+ };
@@ -0,0 +1,21 @@
1
+ import { PageID } from "../utils/ID";
2
+
3
+ type CommandTarget = "PAGE_QUE";
4
+ type CommandKind = `${Uppercase<CommandTarget>}_${Uppercase<string>}_COMMAND`;
5
+
6
+ export type NavigationCommand =
7
+ // | CommandDto<"PAGE_QUE_NEXT_PAGE_COMMAND", "PAGE_QUE", {}>
8
+ | CommandDto<"PAGE_QUE_GO_TO_SEQUENCE_COMMAND", "PAGE_QUE", { sequenceId: string }>
9
+ | CommandDto<"PAGE_QUE_GO_TO_PAGE_COMMAND", "PAGE_QUE", { pageId: string }>;
10
+
11
+ interface CommandDto<K extends CommandKind, T extends CommandTarget, P> {
12
+ readonly kind: K;
13
+ readonly target: T;
14
+ readonly targetId: T | Omit<string, T>;
15
+ readonly payload: P;
16
+ }
17
+
18
+ export type PageQueCommand =
19
+ | CommandDto<"PAGE_QUE_EXCLUDE_BY_TAG_COMMAND", "PAGE_QUE", { tagIds: string[] }>
20
+ | CommandDto<"PAGE_QUE_EXCLUDE_BY_PAGE_ID_COMMAND", "PAGE_QUE", { pageIds: Array<PageID> }>
21
+ | CommandDto<"PAGE_QUE_JUMP_TO_PAGE_COMMAND", "PAGE_QUE", { readonly pageId: string }>;
@@ -0,0 +1,24 @@
1
+ import { Rule } from "../rules/rule";
2
+ import { Fact } from "../rules/fact";
3
+ import { PageQueCommand } from "./DCommand";
4
+ import { SchemaID } from "../utils/ID";
5
+ import { PageDto } from "../page/Page";
6
+
7
+ export type PageQueRules = Rule<PageQueCommand, never>;
8
+
9
+ export interface PageSequenceDto {
10
+ readonly id: string;
11
+ readonly rules: Array<PageQueRules>;
12
+ readonly pages: Array<PageDto>;
13
+ }
14
+
15
+ export interface SchemaDto {
16
+ readonly id: SchemaID;
17
+ readonly baseHeight: number;
18
+ readonly baseWidth: number;
19
+ readonly backgroundColor: string;
20
+ readonly pages: Array<PageDto>;
21
+ readonly rules: Array<PageQueRules>;
22
+ readonly pageSequences?: Array<PageSequenceDto>;
23
+ readonly predefinedFacts?: ReadonlyArray<Fact>;
24
+ }