@media-quest/engine 0.0.22 → 0.0.23

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 (51) hide show
  1. package/package.json +1 -1
  2. package/src/Delement/DElement.dto.ts +5 -5
  3. package/src/Delement/DElement.ts +88 -88
  4. package/src/Delement/DImg.ts +39 -39
  5. package/src/Delement/DStyle-utils.ts +616 -616
  6. package/src/Delement/DStyle.ts +165 -165
  7. package/src/Delement/DText.ts +13 -13
  8. package/src/Delement/Ddiv.ts +25 -25
  9. package/src/Delement/button-click-action.ts +35 -35
  10. package/src/Delement/css.spec.ts +36 -36
  11. package/src/Delement/css.ts +46 -46
  12. package/src/Delement/element-factory.ts +40 -40
  13. package/src/common/DMaybe.ts +46 -46
  14. package/src/common/DTimestamp.ts +20 -20
  15. package/src/common/DTmestamp.spec.ts +11 -11
  16. package/src/common/result.ts +41 -41
  17. package/src/engine/SchemaDto.ts +24 -24
  18. package/src/engine/SchemaEngine.ts +150 -150
  19. package/src/engine/SchemaResult.ts +10 -10
  20. package/src/engine/dplayer.spec.ts +91 -91
  21. package/src/engine/dplayer.ts +104 -104
  22. package/src/engine/history-que.spec.ts +67 -67
  23. package/src/engine/history-que.ts +17 -17
  24. package/src/engine/next-que.spec.ts +121 -121
  25. package/src/engine/next-que.ts +101 -101
  26. package/src/engine/page-que-ruleengine-action.ts +6 -6
  27. package/src/engine/scale.spec.ts +38 -38
  28. package/src/engine/scale.ts +70 -70
  29. package/src/events/mq-events.ts +63 -63
  30. package/src/page/Page.ts +182 -182
  31. package/src/page/media-player.ts +117 -117
  32. package/src/page/page-component.ts +113 -113
  33. package/src/page/page-result.ts +11 -11
  34. package/src/page/task-manager.ts +240 -240
  35. package/src/page/task-state.ts +55 -55
  36. package/src/page/task.ts +90 -90
  37. package/src/public-api.ts +26 -26
  38. package/src/rules/__test__/complex-condition.spec.ts +15 -15
  39. package/src/rules/__test__/conditon.spec.ts +124 -124
  40. package/src/rules/__test__/numeric-condition.spec.ts +84 -84
  41. package/src/rules/__test__/rule-engine.spec.ts +348 -348
  42. package/src/rules/__test__/rule-evaluation.spec.ts +140 -140
  43. package/src/rules/__test__/string-condition.spec.ts +41 -41
  44. package/src/rules/condition.ts +191 -191
  45. package/src/rules/fact.ts +18 -18
  46. package/src/rules/rule-engine.ts +45 -45
  47. package/src/rules/rule.ts +40 -40
  48. package/src/utils/DUtil.ts +116 -116
  49. package/src/utils/ID.spec.ts +39 -39
  50. package/src/utils/ID.ts +73 -73
  51. package/tsconfig.json +19 -19
@@ -1,117 +1,117 @@
1
- import { DStyle, PStyle } from "../Delement/DStyle";
2
-
3
- type MediaPlayerEvent =
4
- | { kind: "video-ended"; url: string }
5
- | { kind: "audio-ended"; url: string }
6
- | { kind: "error"; message: string };
7
-
8
- export interface IMediaPlayer {
9
- playVideo(url: string, loop: boolean): void;
10
- playAudio(url: string, loop: boolean): void;
11
- pauseVideo(): void;
12
- pauseAudio(): void;
13
- clear(): void;
14
- hideVideo(): void;
15
- loadVideo(url: string): void;
16
- appendToParent(el: { appendChild: (el: HTMLElement) => void }): void;
17
- }
18
-
19
- export const createMediaPlayer = (onEvent: (mediaPlayerEvent: MediaPlayerEvent) => void): IMediaPlayer => {
20
- const videoElement = document.createElement("video");
21
- const audioElement = document.createElement("audio");
22
- const videoStyles: PStyle = { h: 40, w: 80, borderStyle: "solid", borderWidth: { _unit: "px", value: 5 } };
23
-
24
- DStyle.normalize(videoElement);
25
- DStyle.applyStyles(videoElement, videoStyles, 1);
26
- videoElement.onended = () => {
27
- console.log("VIDEO ENDED");
28
- };
29
- videoElement.onerror = () => {
30
- console.log("VIDEO ERROR WHY ?? ");
31
- };
32
- audioElement.onended = () => {
33
- console.log("AUDIO ENDED");
34
- };
35
-
36
- const playVideo = (url: string, loop = false) => {
37
- if (videoElement.src !== url) {
38
- videoElement.src = url;
39
- }
40
-
41
- try {
42
- videoElement.play();
43
- } catch (e) {
44
- console.log("VIDEO PLAY ERROR");
45
- console.log(e);
46
- }
47
- };
48
-
49
- const playAudio = (url: string, loop = false) => {
50
- audioElement.loop = loop;
51
- if (audioElement.src !== url) {
52
- audioElement.src = url;
53
- }
54
- // audioElement.play();
55
- try {
56
- audioElement.play();
57
- } catch (e) {
58
- console.log("AUDIO PLAY ERROR");
59
- console.log(e);
60
- }
61
- };
62
-
63
- const showVideo = () => {
64
- videoElement.style.visibility = "visible";
65
- };
66
-
67
- const pauseVideo = () => {
68
- try {
69
- videoElement.pause();
70
- } catch (e) {
71
- console.log("VIDEO PAUSE ERROR");
72
- console.log(e);
73
- }
74
- };
75
-
76
- const loadVideo = (url: string) => {
77
- if (videoElement.src !== url) {
78
- videoElement.src = url;
79
- }
80
- };
81
- const pauseAudio = () => {
82
- try {
83
- audioElement.pause();
84
- } catch (e) {
85
- console.log("AUDIO PAUSE ERROR");
86
- console.log(e);
87
- }
88
- };
89
- const appendToParent = (el: { appendChild: (el: HTMLElement) => void }) => {
90
- el.appendChild(videoElement);
91
- el.appendChild(audioElement);
92
- };
93
- const clear = () => {
94
- pauseVideo();
95
- pauseAudio();
96
- videoElement.src = "";
97
- audioElement.src = "";
98
- };
99
- const hideVideo = () => {
100
- videoElement.style.visibility = "hidden";
101
- };
102
-
103
- return {
104
- playVideo,
105
- playAudio,
106
- pauseVideo,
107
- loadVideo,
108
- clear,
109
- pauseAudio,
110
- hideVideo,
111
- appendToParent,
112
- // mediaLayer,
113
- // videoElement,
114
- // audioElement,
115
- // videoStyles,
116
- };
117
- };
1
+ import { DStyle, PStyle } from "../Delement/DStyle";
2
+
3
+ type MediaPlayerEvent =
4
+ | { kind: "video-ended"; url: string }
5
+ | { kind: "audio-ended"; url: string }
6
+ | { kind: "error"; message: string };
7
+
8
+ export interface IMediaPlayer {
9
+ playVideo(url: string, loop: boolean): void;
10
+ playAudio(url: string, loop: boolean): void;
11
+ pauseVideo(): void;
12
+ pauseAudio(): void;
13
+ clear(): void;
14
+ hideVideo(): void;
15
+ loadVideo(url: string): void;
16
+ appendToParent(el: { appendChild: (el: HTMLElement) => void }): void;
17
+ }
18
+
19
+ export const createMediaPlayer = (onEvent: (mediaPlayerEvent: MediaPlayerEvent) => void): IMediaPlayer => {
20
+ const videoElement = document.createElement("video");
21
+ const audioElement = document.createElement("audio");
22
+ const videoStyles: PStyle = { h: 40, w: 80, borderStyle: "solid", borderWidth: { _unit: "px", value: 5 } };
23
+
24
+ DStyle.normalize(videoElement);
25
+ DStyle.applyStyles(videoElement, videoStyles, 1);
26
+ videoElement.onended = () => {
27
+ console.log("VIDEO ENDED");
28
+ };
29
+ videoElement.onerror = () => {
30
+ console.log("VIDEO ERROR WHY ?? ");
31
+ };
32
+ audioElement.onended = () => {
33
+ console.log("AUDIO ENDED");
34
+ };
35
+
36
+ const playVideo = (url: string, loop = false) => {
37
+ if (videoElement.src !== url) {
38
+ videoElement.src = url;
39
+ }
40
+
41
+ try {
42
+ videoElement.play();
43
+ } catch (e) {
44
+ console.log("VIDEO PLAY ERROR");
45
+ console.log(e);
46
+ }
47
+ };
48
+
49
+ const playAudio = (url: string, loop = false) => {
50
+ audioElement.loop = loop;
51
+ if (audioElement.src !== url) {
52
+ audioElement.src = url;
53
+ }
54
+ // audioElement.play();
55
+ try {
56
+ audioElement.play();
57
+ } catch (e) {
58
+ console.log("AUDIO PLAY ERROR");
59
+ console.log(e);
60
+ }
61
+ };
62
+
63
+ const showVideo = () => {
64
+ videoElement.style.visibility = "visible";
65
+ };
66
+
67
+ const pauseVideo = () => {
68
+ try {
69
+ videoElement.pause();
70
+ } catch (e) {
71
+ console.log("VIDEO PAUSE ERROR");
72
+ console.log(e);
73
+ }
74
+ };
75
+
76
+ const loadVideo = (url: string) => {
77
+ if (videoElement.src !== url) {
78
+ videoElement.src = url;
79
+ }
80
+ };
81
+ const pauseAudio = () => {
82
+ try {
83
+ audioElement.pause();
84
+ } catch (e) {
85
+ console.log("AUDIO PAUSE ERROR");
86
+ console.log(e);
87
+ }
88
+ };
89
+ const appendToParent = (el: { appendChild: (el: HTMLElement) => void }) => {
90
+ el.appendChild(videoElement);
91
+ el.appendChild(audioElement);
92
+ };
93
+ const clear = () => {
94
+ pauseVideo();
95
+ pauseAudio();
96
+ videoElement.src = "";
97
+ audioElement.src = "";
98
+ };
99
+ const hideVideo = () => {
100
+ videoElement.style.visibility = "hidden";
101
+ };
102
+
103
+ return {
104
+ playVideo,
105
+ playAudio,
106
+ pauseVideo,
107
+ loadVideo,
108
+ clear,
109
+ pauseAudio,
110
+ hideVideo,
111
+ appendToParent,
112
+ // mediaLayer,
113
+ // videoElement,
114
+ // audioElement,
115
+ // videoStyles,
116
+ };
117
+ };
@@ -1,113 +1,113 @@
1
- import { PStyle } from "../Delement/DStyle";
2
- import { ScaleService } from "../engine/scale";
3
- import { DElement } from "../Delement/DElement";
4
- import { createDElement } from "../Delement/element-factory";
5
- import { ButtonClickAction } from "../Delement/button-click-action";
6
- import { DElementDto } from "../Delement/DElement.dto";
7
- import { TaskState, TaskStateDiff } from "./task-state";
8
-
9
- export interface PageComponentDto {
10
- readonly onClick?: ButtonClickAction;
11
- readonly el: DElementDto;
12
- readonly whenVideoPlay?: PStyle;
13
- readonly whenVideoPaused?: PStyle;
14
- readonly whenAudioPlaying?: PStyle;
15
- readonly whenAudioPaused?: PStyle;
16
- readonly whenAudioBlocked?: PStyle;
17
- readonly whenVideoBlocked?: PStyle;
18
- readonly whenAudioUnblocked?: PStyle;
19
- readonly whenVideoUnblocked?: PStyle;
20
- readonly whenResponseBlocked?: PStyle;
21
- readonly whenResponseUnblocked?: PStyle;
22
- readonly whenFormInputBlocked?: PStyle;
23
- readonly whenFormInputUnblocked?: PStyle;
24
- }
25
-
26
- const isFalse = (bool?: boolean): bool is false => bool === false;
27
- const isTrue = (bool?: boolean): bool is true => bool === true;
28
-
29
- export class PageComponent {
30
- private readonly TAG = "[ PageComponent ]: ";
31
- private el: DElement<HTMLElement>;
32
- private prevState: TaskState | false = false;
33
-
34
- constructor(
35
- readonly dto: PageComponentDto,
36
- readonly scale: ScaleService,
37
- ) {
38
- this.el = createDElement(dto.el, scale);
39
- this.el.onclick = () => {
40
- if (dto.onClick) {
41
- this.onClick(dto.onClick);
42
- } else {
43
- console.warn(this.TAG + "onClick not implemented");
44
- }
45
- };
46
- }
47
-
48
- onClick(action: ButtonClickAction) {
49
- console.warn(this.TAG + "onclick not implemented");
50
- }
51
-
52
- updateState(state: TaskStateDiff) {
53
- this.handleStateChanges(state);
54
- }
55
-
56
- setState(state: TaskState) {
57
- const prev = this.prevState;
58
- const diff = TaskState.getDiff(state, prev);
59
- this.prevState = state;
60
- if (Object.keys(diff).length > 0) {
61
- this.handleStateChanges(diff);
62
- }
63
- }
64
-
65
- private handleStateChanges(diff: TaskStateDiff) {
66
- const {
67
- videoIsPlaying,
68
- audioIsPlaying,
69
- blockAudio,
70
- blockVideo,
71
- blockResponseButton,
72
- blockFormInput,
73
- isGifMode,
74
- } = diff;
75
- const {
76
- whenAudioPaused,
77
- whenVideoPaused,
78
- whenAudioPlaying,
79
- whenFormInputBlocked,
80
- whenResponseBlocked,
81
- whenVideoPlay,
82
- whenAudioBlocked,
83
- whenVideoBlocked,
84
- whenAudioUnblocked,
85
- whenVideoUnblocked,
86
- whenResponseUnblocked,
87
- whenFormInputUnblocked,
88
- } = this.dto;
89
- if (isTrue(audioIsPlaying) && whenAudioPlaying) {
90
- this.el.setStyle(whenAudioPlaying);
91
- }
92
- if (isFalse(audioIsPlaying) && whenAudioPaused) {
93
- this.el.setStyle(whenAudioPaused);
94
- }
95
- if (isTrue(videoIsPlaying) && whenVideoPlay) {
96
- this.el.setStyle(whenVideoPlay);
97
- }
98
- if (isFalse(videoIsPlaying) && whenVideoPaused) {
99
- this.el.setStyle(whenVideoPaused);
100
- }
101
- // if (isTrue(blockAudio) && whenAudioBlocked) {
102
- // this.el.setStyle(whenAudioBlocked);
103
- // }
104
- // if (isTrue(blockVideo) && whenVideoBlocked) {
105
- // this.el.setStyle(whenVideoBlocked);
106
- // }
107
- }
108
-
109
- appendToParent(parent: { append: (el: HTMLElement) => void }) {
110
- // parent.appendChild(this.el.);
111
- this.el.appendYourself(parent);
112
- }
113
- }
1
+ import { PStyle } from "../Delement/DStyle";
2
+ import { ScaleService } from "../engine/scale";
3
+ import { DElement } from "../Delement/DElement";
4
+ import { createDElement } from "../Delement/element-factory";
5
+ import { ButtonClickAction } from "../Delement/button-click-action";
6
+ import { DElementDto } from "../Delement/DElement.dto";
7
+ import { TaskState, TaskStateDiff } from "./task-state";
8
+
9
+ export interface PageComponentDto {
10
+ readonly onClick?: ButtonClickAction;
11
+ readonly el: DElementDto;
12
+ readonly whenVideoPlay?: PStyle;
13
+ readonly whenVideoPaused?: PStyle;
14
+ readonly whenAudioPlaying?: PStyle;
15
+ readonly whenAudioPaused?: PStyle;
16
+ readonly whenAudioBlocked?: PStyle;
17
+ readonly whenVideoBlocked?: PStyle;
18
+ readonly whenAudioUnblocked?: PStyle;
19
+ readonly whenVideoUnblocked?: PStyle;
20
+ readonly whenResponseBlocked?: PStyle;
21
+ readonly whenResponseUnblocked?: PStyle;
22
+ readonly whenFormInputBlocked?: PStyle;
23
+ readonly whenFormInputUnblocked?: PStyle;
24
+ }
25
+
26
+ const isFalse = (bool?: boolean): bool is false => bool === false;
27
+ const isTrue = (bool?: boolean): bool is true => bool === true;
28
+
29
+ export class PageComponent {
30
+ private readonly TAG = "[ PageComponent ]: ";
31
+ private el: DElement<HTMLElement>;
32
+ private prevState: TaskState | false = false;
33
+
34
+ constructor(
35
+ readonly dto: PageComponentDto,
36
+ readonly scale: ScaleService,
37
+ ) {
38
+ this.el = createDElement(dto.el, scale);
39
+ this.el.onclick = () => {
40
+ if (dto.onClick) {
41
+ this.onClick(dto.onClick);
42
+ } else {
43
+ console.warn(this.TAG + "onClick not implemented");
44
+ }
45
+ };
46
+ }
47
+
48
+ onClick(action: ButtonClickAction) {
49
+ console.warn(this.TAG + "onclick not implemented");
50
+ }
51
+
52
+ updateState(state: TaskStateDiff) {
53
+ this.handleStateChanges(state);
54
+ }
55
+
56
+ setState(state: TaskState) {
57
+ const prev = this.prevState;
58
+ const diff = TaskState.getDiff(state, prev);
59
+ this.prevState = state;
60
+ if (Object.keys(diff).length > 0) {
61
+ this.handleStateChanges(diff);
62
+ }
63
+ }
64
+
65
+ private handleStateChanges(diff: TaskStateDiff) {
66
+ const {
67
+ videoIsPlaying,
68
+ audioIsPlaying,
69
+ blockAudio,
70
+ blockVideo,
71
+ blockResponseButton,
72
+ blockFormInput,
73
+ isGifMode,
74
+ } = diff;
75
+ const {
76
+ whenAudioPaused,
77
+ whenVideoPaused,
78
+ whenAudioPlaying,
79
+ whenFormInputBlocked,
80
+ whenResponseBlocked,
81
+ whenVideoPlay,
82
+ whenAudioBlocked,
83
+ whenVideoBlocked,
84
+ whenAudioUnblocked,
85
+ whenVideoUnblocked,
86
+ whenResponseUnblocked,
87
+ whenFormInputUnblocked,
88
+ } = this.dto;
89
+ if (isTrue(audioIsPlaying) && whenAudioPlaying) {
90
+ this.el.setStyle(whenAudioPlaying);
91
+ }
92
+ if (isFalse(audioIsPlaying) && whenAudioPaused) {
93
+ this.el.setStyle(whenAudioPaused);
94
+ }
95
+ if (isTrue(videoIsPlaying) && whenVideoPlay) {
96
+ this.el.setStyle(whenVideoPlay);
97
+ }
98
+ if (isFalse(videoIsPlaying) && whenVideoPaused) {
99
+ this.el.setStyle(whenVideoPaused);
100
+ }
101
+ // if (isTrue(blockAudio) && whenAudioBlocked) {
102
+ // this.el.setStyle(whenAudioBlocked);
103
+ // }
104
+ // if (isTrue(blockVideo) && whenVideoBlocked) {
105
+ // this.el.setStyle(whenVideoBlocked);
106
+ // }
107
+ }
108
+
109
+ appendToParent(parent: { append: (el: HTMLElement) => void }) {
110
+ // parent.appendChild(this.el.);
111
+ this.el.appendYourself(parent);
112
+ }
113
+ }
@@ -1,11 +1,11 @@
1
- import { DTimestamp } from "../common/DTimestamp";
2
- import { Fact } from "../rules/fact";
3
- import { MqEvent } from "../events/mq-events";
4
-
5
- export interface PageResult {
6
- readonly pageId: string;
7
- readonly pagePrefix: string;
8
- readonly eventLog: ReadonlyArray<MqEvent>;
9
- readonly pageTime: DTimestamp.Diff;
10
- readonly collectedFacts: Fact[];
11
- }
1
+ import { DTimestamp } from "../common/DTimestamp";
2
+ import { Fact } from "../rules/fact";
3
+ import { MqEvent } from "../events/mq-events";
4
+
5
+ export interface PageResult {
6
+ readonly pageId: string;
7
+ readonly pagePrefix: string;
8
+ readonly eventLog: ReadonlyArray<MqEvent>;
9
+ readonly pageTime: DTimestamp.Diff;
10
+ readonly collectedFacts: Fact[];
11
+ }