@media-quest/engine 0.0.30 → 0.0.32
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/dist/public-api.d.ts +86 -43
- package/dist/public-api.js +398 -198
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
- package/src/Delement/DButton.ts +25 -0
- package/src/Delement/DElement.dto.ts +6 -5
- package/src/Delement/DElement.ts +190 -88
- package/src/Delement/DImg.ts +48 -39
- package/src/Delement/DStyle.ts +368 -165
- package/src/Delement/DText.ts +23 -13
- package/src/Delement/Ddiv.ts +44 -25
- package/src/Delement/button-click-action.ts +42 -35
- package/src/Delement/css.spec.ts +40 -36
- package/src/Delement/css.ts +56 -46
- package/src/Delement/element-factory.ts +49 -40
- package/src/engine/SchemaEngine.ts +155 -150
- package/src/engine/history-que.spec.ts +67 -67
- package/src/engine/next-que.spec.ts +121 -121
- package/src/page/Page.ts +190 -182
- package/src/page/task-manager.ts +263 -240
- package/src/page/task-state.ts +65 -55
- package/src/public-api.ts +25 -26
- package/src/VERSION.ts +0 -1
- package/src/page/page-component.ts +0 -113
package/src/page/Page.ts
CHANGED
|
@@ -1,182 +1,190 @@
|
|
|
1
|
-
import { DElement } from "../Delement/DElement";
|
|
2
|
-
import { TaskManager } from "./task-manager";
|
|
3
|
-
import { createDElement } from "../Delement/element-factory";
|
|
4
|
-
import { ScaleService } from "../engine/scale";
|
|
5
|
-
import { Task } from "./task";
|
|
6
|
-
import { PStyle } from "../Delement/DStyle";
|
|
7
|
-
import { ButtonClickAction } from "../Delement/button-click-action";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
this.onCompleted(
|
|
150
|
-
break;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
1
|
+
import { DElement } from "../Delement/DElement";
|
|
2
|
+
import { TaskManager } from "./task-manager";
|
|
3
|
+
import { createDElement } from "../Delement/element-factory";
|
|
4
|
+
import { ScaleService } from "../engine/scale";
|
|
5
|
+
import { Task } from "./task";
|
|
6
|
+
import { PStyle } from "../Delement/DStyle";
|
|
7
|
+
import { ButtonClickAction } from "../Delement/button-click-action";
|
|
8
|
+
import { DElementDto } from "../Delement/DElement.dto";
|
|
9
|
+
import { Fact } from "../rules/fact";
|
|
10
|
+
import { DTimestamp } from "../common/DTimestamp";
|
|
11
|
+
import { PageResult } from "./page-result";
|
|
12
|
+
import { TaskState } from "./task-state";
|
|
13
|
+
import { MqEvent } from "../events/mq-events";
|
|
14
|
+
|
|
15
|
+
export interface VideoPlayerDto {
|
|
16
|
+
playUrl: string;
|
|
17
|
+
style?: PStyle;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PageDto {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly prefix: string;
|
|
23
|
+
readonly tags: string[];
|
|
24
|
+
background: string;
|
|
25
|
+
elements: Array<DElementDto>;
|
|
26
|
+
videoPlayer?: VideoPlayerDto;
|
|
27
|
+
initialTasks: Array<Task>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const PageDto = {
|
|
31
|
+
createDummy: (id: number): PageDto => {
|
|
32
|
+
return {
|
|
33
|
+
id: "id" + id,
|
|
34
|
+
prefix: "prefix" + id,
|
|
35
|
+
tags: [],
|
|
36
|
+
background: "white",
|
|
37
|
+
elements: [
|
|
38
|
+
{
|
|
39
|
+
_tag: "div",
|
|
40
|
+
style: { x: 10, y: 0, w: 40, h: 20, backgroundColor: "red" },
|
|
41
|
+
children: [],
|
|
42
|
+
innerText: "Next btn " + id,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
|
|
46
|
+
initialTasks: [],
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export class Page {
|
|
52
|
+
private readonly TAG = "[ DPage ]: ";
|
|
53
|
+
private elements: DElement<HTMLElement>[] = [];
|
|
54
|
+
// private elements: PageComponent[] = [];
|
|
55
|
+
// private layoutComponents: PageLayoutComponent[] = [];
|
|
56
|
+
private pageEntered: DTimestamp = DTimestamp.now();
|
|
57
|
+
private previousState: TaskState | false = false;
|
|
58
|
+
private eventLog = new Array<MqEvent>();
|
|
59
|
+
|
|
60
|
+
constructor(
|
|
61
|
+
private readonly dto: PageDto,
|
|
62
|
+
private readonly taskManager: TaskManager,
|
|
63
|
+
private readonly scaleService: ScaleService,
|
|
64
|
+
private readonly onCompleted: (result: PageResult) => void,
|
|
65
|
+
) {
|
|
66
|
+
dto.elements.forEach((el) => {
|
|
67
|
+
const element = createDElement(el, scaleService);
|
|
68
|
+
// if (element instanceof DDiv) {
|
|
69
|
+
// }
|
|
70
|
+
element.registerClickHandler((action) => {
|
|
71
|
+
this.handleButtonAction(action);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
this.elements.push(element);
|
|
75
|
+
|
|
76
|
+
// if(element.)
|
|
77
|
+
// element= (action) => {
|
|
78
|
+
// console.log("TODO ONCLICK ");
|
|
79
|
+
// this.handleButtonAction(action);
|
|
80
|
+
// };
|
|
81
|
+
// this.elements.push(element);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (dto.videoPlayer) {
|
|
85
|
+
this.taskManager.loadVideo(dto.videoPlayer.playUrl);
|
|
86
|
+
if (dto.videoPlayer.style) {
|
|
87
|
+
this.taskManager.setVideoStyles(dto.videoPlayer.style);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (dto.initialTasks.length) {
|
|
92
|
+
this.taskManager.autoPlaySequence(dto.initialTasks);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private createPageResult(facts: Fact[]): PageResult {
|
|
97
|
+
const pageExited = DTimestamp.now();
|
|
98
|
+
const pageTime = DTimestamp.diff(this.pageEntered, pageExited);
|
|
99
|
+
const pageExit = MqEvent.pageLeave(this.dto.id, this.dto.prefix);
|
|
100
|
+
this.eventLog.push(pageExit);
|
|
101
|
+
const eventLog = [...this.eventLog];
|
|
102
|
+
return {
|
|
103
|
+
pagePrefix: this.dto.prefix,
|
|
104
|
+
pageId: this.dto.id,
|
|
105
|
+
eventLog,
|
|
106
|
+
pageTime,
|
|
107
|
+
collectedFacts: facts,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
private handleButtonAction(a: ButtonClickAction) {
|
|
111
|
+
const event = MqEvent.userClicked({
|
|
112
|
+
pageId: this.dto.id,
|
|
113
|
+
pagePrefix: this.dto.prefix,
|
|
114
|
+
action: a.kind,
|
|
115
|
+
descriptions: ButtonClickAction.describe(a),
|
|
116
|
+
});
|
|
117
|
+
this.eventLog.push(event);
|
|
118
|
+
navigator.vibrate(200);
|
|
119
|
+
const { vibrateMs } = a;
|
|
120
|
+
if (vibrateMs) {
|
|
121
|
+
navigator.vibrate(vibrateMs);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
switch (a.kind) {
|
|
125
|
+
case "next-page":
|
|
126
|
+
const nextPageResult = this.createPageResult([]);
|
|
127
|
+
this.onCompleted(nextPageResult);
|
|
128
|
+
break;
|
|
129
|
+
case "play-video":
|
|
130
|
+
this.taskManager.execute(a.task);
|
|
131
|
+
break;
|
|
132
|
+
case "play-audio":
|
|
133
|
+
this.taskManager.execute(a.task);
|
|
134
|
+
break;
|
|
135
|
+
case "pause-video":
|
|
136
|
+
this.taskManager.pauseVideo();
|
|
137
|
+
break;
|
|
138
|
+
case "pause-audio":
|
|
139
|
+
this.taskManager.pauseAudio();
|
|
140
|
+
break;
|
|
141
|
+
case "mute-video":
|
|
142
|
+
this.taskManager.muteVideo();
|
|
143
|
+
break;
|
|
144
|
+
case "un-mute-video":
|
|
145
|
+
this.taskManager.unMuteVideo();
|
|
146
|
+
break;
|
|
147
|
+
case "submit-fact":
|
|
148
|
+
const submitFactResult = this.createPageResult([a.fact]);
|
|
149
|
+
this.onCompleted(submitFactResult);
|
|
150
|
+
break;
|
|
151
|
+
case "submit-form":
|
|
152
|
+
// TODO IMPLEMENT Collection of form-data // LOOP OVER ALL INPUTS
|
|
153
|
+
const submitFormResult = this.createPageResult([]);
|
|
154
|
+
this.onCompleted(submitFormResult);
|
|
155
|
+
break;
|
|
156
|
+
default:
|
|
157
|
+
const _exhaustiveCheck: never = a;
|
|
158
|
+
console.log(_exhaustiveCheck);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
appendYourself(parent: HTMLElement) {
|
|
163
|
+
const pageEnterEvent = MqEvent.pageEnter(this.dto.id, this.dto.prefix);
|
|
164
|
+
this.pageEntered = DTimestamp.now();
|
|
165
|
+
this.eventLog.push(pageEnterEvent);
|
|
166
|
+
this.elements.forEach((el) => {
|
|
167
|
+
el.appendYourself(parent);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// this.components.forEach((comp) => {
|
|
171
|
+
// comp.appendToParent(parent);
|
|
172
|
+
// });
|
|
173
|
+
// this.layoutComponents.forEach((comp) => {
|
|
174
|
+
// comp.appendToParent(parent);
|
|
175
|
+
// });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
destroy() {
|
|
179
|
+
this.taskManager.clear();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
tick() {
|
|
183
|
+
const prev = this.previousState;
|
|
184
|
+
const curr = this.taskManager.getState();
|
|
185
|
+
const diff = TaskState.getDiff(curr, prev);
|
|
186
|
+
this.elements.forEach((element) => {
|
|
187
|
+
element.updateState(diff);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|