@media-quest/engine 0.0.39 → 0.0.40
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 +3 -21
- package/dist/public-api.js +16 -29
- package/dist/public-api.js.map +1 -1
- package/package.json +26 -26
- package/src/Delement/DButton.ts +25 -25
- package/src/Delement/DElement.dto.ts +6 -6
- package/src/Delement/DElement.ts +190 -190
- package/src/Delement/DImg.ts +48 -48
- package/src/Delement/DStyle.ts +376 -391
- package/src/Delement/DText.ts +23 -23
- package/src/Delement/Ddiv.ts +44 -44
- package/src/Delement/button-click-action.ts +42 -42
- package/src/Delement/css.spec.ts +40 -40
- package/src/Delement/css.ts +56 -56
- package/src/Delement/element-factory.ts +49 -49
- package/src/engine/SchemaEngine.ts +155 -160
- package/src/engine/SchemaResult.ts +10 -12
- package/src/engine/dplayer.spec.ts +91 -92
- package/src/engine/dplayer.ts +104 -106
- package/src/engine/history-que.spec.ts +67 -69
- package/src/engine/history-que.ts +17 -21
- package/src/engine/next-que.spec.ts +121 -122
- package/src/engine/next-que.ts +101 -101
- package/src/events/mq-events.ts +63 -76
- package/src/page/Page.ts +190 -180
- package/src/page/page-result.ts +11 -12
- package/src/page/task-manager.ts +263 -263
- package/src/page/task-state.ts +65 -65
- package/src/public-api.ts +25 -26
- package/tsconfig.json +19 -19
package/src/Delement/DButton.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
-
import { ScaleService } from "../engine/scale";
|
|
3
|
-
import { ButtonClickAction } from "./button-click-action";
|
|
4
|
-
|
|
5
|
-
export interface DButtonDto extends DElementBaseDto {
|
|
6
|
-
readonly _tag: "button";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class DButton extends DElement<HTMLButtonElement> {
|
|
10
|
-
private readonly TAG = "[ DDiv ]: ";
|
|
11
|
-
protected readonly defaultStyle = { x: 40, y: 40 };
|
|
12
|
-
|
|
13
|
-
constructor(dto: DButtonDto, scale: ScaleService) {
|
|
14
|
-
const d = document.createElement("button");
|
|
15
|
-
super(d, dto, scale);
|
|
16
|
-
}
|
|
17
|
-
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
18
|
-
this.el.onclick = () => {
|
|
19
|
-
const action = this.dto.onClick;
|
|
20
|
-
if (action) {
|
|
21
|
-
clickHandler(action);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
+
import { ScaleService } from "../engine/scale";
|
|
3
|
+
import { ButtonClickAction } from "./button-click-action";
|
|
4
|
+
|
|
5
|
+
export interface DButtonDto extends DElementBaseDto {
|
|
6
|
+
readonly _tag: "button";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class DButton extends DElement<HTMLButtonElement> {
|
|
10
|
+
private readonly TAG = "[ DDiv ]: ";
|
|
11
|
+
protected readonly defaultStyle = { x: 40, y: 40 };
|
|
12
|
+
|
|
13
|
+
constructor(dto: DButtonDto, scale: ScaleService) {
|
|
14
|
+
const d = document.createElement("button");
|
|
15
|
+
super(d, dto, scale);
|
|
16
|
+
}
|
|
17
|
+
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
18
|
+
this.el.onclick = () => {
|
|
19
|
+
const action = this.dto.onClick;
|
|
20
|
+
if (action) {
|
|
21
|
+
clickHandler(action);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DImgDto } from "./DImg";
|
|
2
|
-
import { DTextDto } from "./DText";
|
|
3
|
-
import { DDivDto } from "./Ddiv";
|
|
4
|
-
import { DButtonDto } from "./DButton";
|
|
5
|
-
|
|
6
|
-
export type DElementDto = DTextDto | DImgDto | DDivDto | DButtonDto;
|
|
1
|
+
import { DImgDto } from "./DImg";
|
|
2
|
+
import { DTextDto } from "./DText";
|
|
3
|
+
import { DDivDto } from "./Ddiv";
|
|
4
|
+
import { DButtonDto } from "./DButton";
|
|
5
|
+
|
|
6
|
+
export type DElementDto = DTextDto | DImgDto | DDivDto | DButtonDto;
|
package/src/Delement/DElement.ts
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import { DStyle, PStyle } from "./DStyle";
|
|
2
|
-
import { ScaleService } from "../engine/scale";
|
|
3
|
-
import { ButtonClickAction } from "./button-click-action";
|
|
4
|
-
import { TaskState, TaskStateDiff } from "../page/task-state";
|
|
5
|
-
|
|
6
|
-
export interface DElementBaseDto {
|
|
7
|
-
readonly style: PStyle;
|
|
8
|
-
readonly onMouseEnter?: PStyle;
|
|
9
|
-
readonly onMouseLeave?: PStyle;
|
|
10
|
-
readonly onMouseDown?: PStyle;
|
|
11
|
-
readonly onMouseUp?: PStyle;
|
|
12
|
-
readonly innerText?: string;
|
|
13
|
-
|
|
14
|
-
// ACTIONS HANDLERS
|
|
15
|
-
readonly onClick?: ButtonClickAction;
|
|
16
|
-
|
|
17
|
-
// VIDEO STATED
|
|
18
|
-
readonly whenVideoPaused?: PStyle;
|
|
19
|
-
readonly whenVideoPausedAndMuted?: PStyle;
|
|
20
|
-
readonly whenVideoEnded?: PStyle;
|
|
21
|
-
readonly whenVideoEndedAndMuted?: PStyle;
|
|
22
|
-
readonly whenVideoPlaying?: PStyle;
|
|
23
|
-
readonly whenVideoPlayingAndMuted?: PStyle;
|
|
24
|
-
|
|
25
|
-
readonly whenAudioPlaying?: PStyle;
|
|
26
|
-
readonly whenAudioPaused?: PStyle;
|
|
27
|
-
readonly whenAudioBlocked?: PStyle;
|
|
28
|
-
readonly whenVideoBlocked?: PStyle;
|
|
29
|
-
readonly whenAudioUnblocked?: PStyle;
|
|
30
|
-
readonly whenVideoUnblocked?: PStyle;
|
|
31
|
-
readonly whenResponseBlocked?: PStyle;
|
|
32
|
-
readonly whenResponseUnblocked?: PStyle;
|
|
33
|
-
readonly whenFormInputBlocked?: PStyle;
|
|
34
|
-
readonly whenFormInputUnblocked?: PStyle;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const isFalse = (bool?: boolean): bool is false => bool === false;
|
|
38
|
-
const isTrue = (bool?: boolean): bool is true => bool === true;
|
|
39
|
-
|
|
40
|
-
export abstract class DElement<T extends HTMLElement> {
|
|
41
|
-
private prevState: TaskState | false = false;
|
|
42
|
-
|
|
43
|
-
protected currStyle: Partial<DStyle> = {
|
|
44
|
-
fontSize: { _unit: "px", value: 100 },
|
|
45
|
-
fontWeight: 500,
|
|
46
|
-
textColor: "black",
|
|
47
|
-
opacity: 1,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
protected constructor(
|
|
51
|
-
protected readonly el: T,
|
|
52
|
-
protected readonly dto: DElementBaseDto,
|
|
53
|
-
protected readonly scale: ScaleService,
|
|
54
|
-
) {
|
|
55
|
-
if (dto.innerText) {
|
|
56
|
-
this.el.innerText = dto.innerText;
|
|
57
|
-
}
|
|
58
|
-
this.setStyle = this.setStyle.bind(this);
|
|
59
|
-
// this.normalize = this.normalize.bind(this);
|
|
60
|
-
this.appendYourself = this.appendYourself.bind(this);
|
|
61
|
-
this.updateStyles = this.updateStyles.bind(this);
|
|
62
|
-
const { onMouseEnter, onMouseLeave } = dto;
|
|
63
|
-
|
|
64
|
-
if (onMouseEnter) {
|
|
65
|
-
this.el.onmouseenter = () => {
|
|
66
|
-
this.setStyle(onMouseEnter);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (onMouseLeave) {
|
|
70
|
-
this.el.onmouseleave = () => {
|
|
71
|
-
this.setStyle(onMouseLeave);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
DStyle.normalize(this.el);
|
|
76
|
-
|
|
77
|
-
if (dto) {
|
|
78
|
-
this.updateStyles(dto?.style);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* This method is called when the element is clicked.
|
|
84
|
-
* This method shall be overridden by the pageClass.
|
|
85
|
-
* @param style
|
|
86
|
-
*/
|
|
87
|
-
setStyle(style: PStyle) {
|
|
88
|
-
this.updateStyles(style);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
getElementByDangerousReference() {
|
|
92
|
-
return this.el;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
appendYourself(parent: { append: (el: HTMLElement) => void }) {
|
|
96
|
-
parent.append(this.el);
|
|
97
|
-
// console.log(parent);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
updateState(state: TaskStateDiff) {
|
|
101
|
-
this.handleStateChanges(state);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setState(state: TaskState) {
|
|
105
|
-
const prev = this.prevState;
|
|
106
|
-
const diff = TaskState.getDiff(state, prev);
|
|
107
|
-
this.prevState = state;
|
|
108
|
-
if (Object.keys(diff).length > 0) {
|
|
109
|
-
this.handleStateChanges(diff);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private handleStateChanges(diff: TaskStateDiff) {
|
|
114
|
-
const {
|
|
115
|
-
audioIsPlaying,
|
|
116
|
-
videoPlayState,
|
|
117
|
-
blockAudio,
|
|
118
|
-
blockVideo,
|
|
119
|
-
blockResponseButton,
|
|
120
|
-
blockFormInput,
|
|
121
|
-
isGifMode,
|
|
122
|
-
} = diff;
|
|
123
|
-
const {
|
|
124
|
-
whenAudioPaused,
|
|
125
|
-
whenVideoPaused,
|
|
126
|
-
whenAudioPlaying,
|
|
127
|
-
whenFormInputBlocked,
|
|
128
|
-
whenResponseBlocked,
|
|
129
|
-
|
|
130
|
-
whenVideoPlaying,
|
|
131
|
-
whenVideoEnded,
|
|
132
|
-
|
|
133
|
-
whenAudioBlocked,
|
|
134
|
-
whenVideoBlocked,
|
|
135
|
-
whenAudioUnblocked,
|
|
136
|
-
whenVideoUnblocked,
|
|
137
|
-
whenResponseUnblocked,
|
|
138
|
-
whenFormInputUnblocked,
|
|
139
|
-
whenVideoPausedAndMuted,
|
|
140
|
-
whenVideoEndedAndMuted,
|
|
141
|
-
whenVideoPlayingAndMuted,
|
|
142
|
-
} = this.dto;
|
|
143
|
-
|
|
144
|
-
if (isTrue(audioIsPlaying) && whenAudioPlaying) {
|
|
145
|
-
this.setStyle(whenAudioPlaying);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (isFalse(audioIsPlaying) && whenAudioPaused) {
|
|
149
|
-
this.setStyle(whenAudioPaused);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (videoPlayState === "playing" && whenVideoPlaying) {
|
|
153
|
-
this.setStyle(whenVideoPlaying);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (videoPlayState === "paused" && whenVideoPaused) {
|
|
157
|
-
this.setStyle(whenVideoPaused);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (videoPlayState === "ended" && whenVideoEnded) {
|
|
161
|
-
this.setStyle(whenVideoEnded);
|
|
162
|
-
}
|
|
163
|
-
if (videoPlayState === "playing-and-muted" && whenVideoPlayingAndMuted) {
|
|
164
|
-
this.setStyle(whenVideoPlayingAndMuted);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (videoPlayState === "paused-and-muted" && whenVideoPausedAndMuted) {
|
|
168
|
-
this.setStyle(whenVideoPausedAndMuted);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (videoPlayState === "ended-and-muted" && whenVideoEndedAndMuted) {
|
|
172
|
-
this.setStyle(whenVideoEndedAndMuted);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// private normalize() {
|
|
177
|
-
// this.el.style.padding = "0";
|
|
178
|
-
// this.el.style.margin = "0";
|
|
179
|
-
// this.el.style.position = "absolute";
|
|
180
|
-
// this.el.style.boxSizing = "border-box";
|
|
181
|
-
// }
|
|
182
|
-
|
|
183
|
-
abstract registerClickHandler(clickHandler: (action: ButtonClickAction) => void): void;
|
|
184
|
-
|
|
185
|
-
protected updateStyles(style: Partial<DStyle>) {
|
|
186
|
-
this.currStyle = Object.assign(this.currStyle, style);
|
|
187
|
-
DStyle.applyStyles(this.el, this.currStyle, this.scale.scale);
|
|
188
|
-
window.getComputedStyle(this.el);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
1
|
+
import { DStyle, PStyle } from "./DStyle";
|
|
2
|
+
import { ScaleService } from "../engine/scale";
|
|
3
|
+
import { ButtonClickAction } from "./button-click-action";
|
|
4
|
+
import { TaskState, TaskStateDiff } from "../page/task-state";
|
|
5
|
+
|
|
6
|
+
export interface DElementBaseDto {
|
|
7
|
+
readonly style: PStyle;
|
|
8
|
+
readonly onMouseEnter?: PStyle;
|
|
9
|
+
readonly onMouseLeave?: PStyle;
|
|
10
|
+
readonly onMouseDown?: PStyle;
|
|
11
|
+
readonly onMouseUp?: PStyle;
|
|
12
|
+
readonly innerText?: string;
|
|
13
|
+
|
|
14
|
+
// ACTIONS HANDLERS
|
|
15
|
+
readonly onClick?: ButtonClickAction;
|
|
16
|
+
|
|
17
|
+
// VIDEO STATED
|
|
18
|
+
readonly whenVideoPaused?: PStyle;
|
|
19
|
+
readonly whenVideoPausedAndMuted?: PStyle;
|
|
20
|
+
readonly whenVideoEnded?: PStyle;
|
|
21
|
+
readonly whenVideoEndedAndMuted?: PStyle;
|
|
22
|
+
readonly whenVideoPlaying?: PStyle;
|
|
23
|
+
readonly whenVideoPlayingAndMuted?: PStyle;
|
|
24
|
+
|
|
25
|
+
readonly whenAudioPlaying?: PStyle;
|
|
26
|
+
readonly whenAudioPaused?: PStyle;
|
|
27
|
+
readonly whenAudioBlocked?: PStyle;
|
|
28
|
+
readonly whenVideoBlocked?: PStyle;
|
|
29
|
+
readonly whenAudioUnblocked?: PStyle;
|
|
30
|
+
readonly whenVideoUnblocked?: PStyle;
|
|
31
|
+
readonly whenResponseBlocked?: PStyle;
|
|
32
|
+
readonly whenResponseUnblocked?: PStyle;
|
|
33
|
+
readonly whenFormInputBlocked?: PStyle;
|
|
34
|
+
readonly whenFormInputUnblocked?: PStyle;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isFalse = (bool?: boolean): bool is false => bool === false;
|
|
38
|
+
const isTrue = (bool?: boolean): bool is true => bool === true;
|
|
39
|
+
|
|
40
|
+
export abstract class DElement<T extends HTMLElement> {
|
|
41
|
+
private prevState: TaskState | false = false;
|
|
42
|
+
|
|
43
|
+
protected currStyle: Partial<DStyle> = {
|
|
44
|
+
fontSize: { _unit: "px", value: 100 },
|
|
45
|
+
fontWeight: 500,
|
|
46
|
+
textColor: "black",
|
|
47
|
+
opacity: 1,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
protected constructor(
|
|
51
|
+
protected readonly el: T,
|
|
52
|
+
protected readonly dto: DElementBaseDto,
|
|
53
|
+
protected readonly scale: ScaleService,
|
|
54
|
+
) {
|
|
55
|
+
if (dto.innerText) {
|
|
56
|
+
this.el.innerText = dto.innerText;
|
|
57
|
+
}
|
|
58
|
+
this.setStyle = this.setStyle.bind(this);
|
|
59
|
+
// this.normalize = this.normalize.bind(this);
|
|
60
|
+
this.appendYourself = this.appendYourself.bind(this);
|
|
61
|
+
this.updateStyles = this.updateStyles.bind(this);
|
|
62
|
+
const { onMouseEnter, onMouseLeave } = dto;
|
|
63
|
+
|
|
64
|
+
if (onMouseEnter) {
|
|
65
|
+
this.el.onmouseenter = () => {
|
|
66
|
+
this.setStyle(onMouseEnter);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (onMouseLeave) {
|
|
70
|
+
this.el.onmouseleave = () => {
|
|
71
|
+
this.setStyle(onMouseLeave);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
DStyle.normalize(this.el);
|
|
76
|
+
|
|
77
|
+
if (dto) {
|
|
78
|
+
this.updateStyles(dto?.style);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* This method is called when the element is clicked.
|
|
84
|
+
* This method shall be overridden by the pageClass.
|
|
85
|
+
* @param style
|
|
86
|
+
*/
|
|
87
|
+
setStyle(style: PStyle) {
|
|
88
|
+
this.updateStyles(style);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getElementByDangerousReference() {
|
|
92
|
+
return this.el;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
appendYourself(parent: { append: (el: HTMLElement) => void }) {
|
|
96
|
+
parent.append(this.el);
|
|
97
|
+
// console.log(parent);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
updateState(state: TaskStateDiff) {
|
|
101
|
+
this.handleStateChanges(state);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setState(state: TaskState) {
|
|
105
|
+
const prev = this.prevState;
|
|
106
|
+
const diff = TaskState.getDiff(state, prev);
|
|
107
|
+
this.prevState = state;
|
|
108
|
+
if (Object.keys(diff).length > 0) {
|
|
109
|
+
this.handleStateChanges(diff);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private handleStateChanges(diff: TaskStateDiff) {
|
|
114
|
+
const {
|
|
115
|
+
audioIsPlaying,
|
|
116
|
+
videoPlayState,
|
|
117
|
+
blockAudio,
|
|
118
|
+
blockVideo,
|
|
119
|
+
blockResponseButton,
|
|
120
|
+
blockFormInput,
|
|
121
|
+
isGifMode,
|
|
122
|
+
} = diff;
|
|
123
|
+
const {
|
|
124
|
+
whenAudioPaused,
|
|
125
|
+
whenVideoPaused,
|
|
126
|
+
whenAudioPlaying,
|
|
127
|
+
whenFormInputBlocked,
|
|
128
|
+
whenResponseBlocked,
|
|
129
|
+
|
|
130
|
+
whenVideoPlaying,
|
|
131
|
+
whenVideoEnded,
|
|
132
|
+
|
|
133
|
+
whenAudioBlocked,
|
|
134
|
+
whenVideoBlocked,
|
|
135
|
+
whenAudioUnblocked,
|
|
136
|
+
whenVideoUnblocked,
|
|
137
|
+
whenResponseUnblocked,
|
|
138
|
+
whenFormInputUnblocked,
|
|
139
|
+
whenVideoPausedAndMuted,
|
|
140
|
+
whenVideoEndedAndMuted,
|
|
141
|
+
whenVideoPlayingAndMuted,
|
|
142
|
+
} = this.dto;
|
|
143
|
+
|
|
144
|
+
if (isTrue(audioIsPlaying) && whenAudioPlaying) {
|
|
145
|
+
this.setStyle(whenAudioPlaying);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (isFalse(audioIsPlaying) && whenAudioPaused) {
|
|
149
|
+
this.setStyle(whenAudioPaused);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (videoPlayState === "playing" && whenVideoPlaying) {
|
|
153
|
+
this.setStyle(whenVideoPlaying);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (videoPlayState === "paused" && whenVideoPaused) {
|
|
157
|
+
this.setStyle(whenVideoPaused);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (videoPlayState === "ended" && whenVideoEnded) {
|
|
161
|
+
this.setStyle(whenVideoEnded);
|
|
162
|
+
}
|
|
163
|
+
if (videoPlayState === "playing-and-muted" && whenVideoPlayingAndMuted) {
|
|
164
|
+
this.setStyle(whenVideoPlayingAndMuted);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (videoPlayState === "paused-and-muted" && whenVideoPausedAndMuted) {
|
|
168
|
+
this.setStyle(whenVideoPausedAndMuted);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (videoPlayState === "ended-and-muted" && whenVideoEndedAndMuted) {
|
|
172
|
+
this.setStyle(whenVideoEndedAndMuted);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// private normalize() {
|
|
177
|
+
// this.el.style.padding = "0";
|
|
178
|
+
// this.el.style.margin = "0";
|
|
179
|
+
// this.el.style.position = "absolute";
|
|
180
|
+
// this.el.style.boxSizing = "border-box";
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
abstract registerClickHandler(clickHandler: (action: ButtonClickAction) => void): void;
|
|
184
|
+
|
|
185
|
+
protected updateStyles(style: Partial<DStyle>) {
|
|
186
|
+
this.currStyle = Object.assign(this.currStyle, style);
|
|
187
|
+
DStyle.applyStyles(this.el, this.currStyle, this.scale.scale);
|
|
188
|
+
window.getComputedStyle(this.el);
|
|
189
|
+
}
|
|
190
|
+
}
|
package/src/Delement/DImg.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
-
import { ScaleService } from "../engine/scale";
|
|
3
|
-
import { DTimestamp } from "../common/DTimestamp";
|
|
4
|
-
import { ButtonClickAction } from "./button-click-action";
|
|
5
|
-
|
|
6
|
-
export interface DImgDto extends DElementBaseDto {
|
|
7
|
-
readonly _tag: "img";
|
|
8
|
-
// readonly id: string;
|
|
9
|
-
readonly url: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class DImg extends DElement<HTMLImageElement> {
|
|
13
|
-
private static IMAGE_COUNT = 0;
|
|
14
|
-
private readonly imageCount: number;
|
|
15
|
-
readonly TAG: string;
|
|
16
|
-
readonly TIMING_TAG: string;
|
|
17
|
-
private readonly loadStart: DTimestamp;
|
|
18
|
-
registerClickHandler(clickHandler: (action: ButtonClickAction) => void): void {
|
|
19
|
-
this.el.onclick = () => {
|
|
20
|
-
const action = this.dto.onClick;
|
|
21
|
-
if (action) {
|
|
22
|
-
clickHandler(action);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
protected readonly dto: DImgDto,
|
|
29
|
-
readonly scaleService: ScaleService,
|
|
30
|
-
) {
|
|
31
|
-
super(document.createElement("img"), dto, scaleService);
|
|
32
|
-
DImg.IMAGE_COUNT += 1;
|
|
33
|
-
this.imageCount = DImg.IMAGE_COUNT;
|
|
34
|
-
this.TAG = "[D_IMG " + DImg.IMAGE_COUNT + " ]: ";
|
|
35
|
-
this.TIMING_TAG = "load-time (" + DImg.IMAGE_COUNT + ") ";
|
|
36
|
-
this.el.loading = "eager";
|
|
37
|
-
this.el.style.position = "absolute";
|
|
38
|
-
this.setStyle(dto.style);
|
|
39
|
-
|
|
40
|
-
this.loadStart = DTimestamp.now();
|
|
41
|
-
this.el.onload = () => {};
|
|
42
|
-
this.el.onerror = () => {};
|
|
43
|
-
this.el.src = dto.url;
|
|
44
|
-
console.time(this.TIMING_TAG);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
log(): void {}
|
|
48
|
-
}
|
|
1
|
+
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
+
import { ScaleService } from "../engine/scale";
|
|
3
|
+
import { DTimestamp } from "../common/DTimestamp";
|
|
4
|
+
import { ButtonClickAction } from "./button-click-action";
|
|
5
|
+
|
|
6
|
+
export interface DImgDto extends DElementBaseDto {
|
|
7
|
+
readonly _tag: "img";
|
|
8
|
+
// readonly id: string;
|
|
9
|
+
readonly url: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class DImg extends DElement<HTMLImageElement> {
|
|
13
|
+
private static IMAGE_COUNT = 0;
|
|
14
|
+
private readonly imageCount: number;
|
|
15
|
+
readonly TAG: string;
|
|
16
|
+
readonly TIMING_TAG: string;
|
|
17
|
+
private readonly loadStart: DTimestamp;
|
|
18
|
+
registerClickHandler(clickHandler: (action: ButtonClickAction) => void): void {
|
|
19
|
+
this.el.onclick = () => {
|
|
20
|
+
const action = this.dto.onClick;
|
|
21
|
+
if (action) {
|
|
22
|
+
clickHandler(action);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
protected readonly dto: DImgDto,
|
|
29
|
+
readonly scaleService: ScaleService,
|
|
30
|
+
) {
|
|
31
|
+
super(document.createElement("img"), dto, scaleService);
|
|
32
|
+
DImg.IMAGE_COUNT += 1;
|
|
33
|
+
this.imageCount = DImg.IMAGE_COUNT;
|
|
34
|
+
this.TAG = "[D_IMG " + DImg.IMAGE_COUNT + " ]: ";
|
|
35
|
+
this.TIMING_TAG = "load-time (" + DImg.IMAGE_COUNT + ") ";
|
|
36
|
+
this.el.loading = "eager";
|
|
37
|
+
this.el.style.position = "absolute";
|
|
38
|
+
this.setStyle(dto.style);
|
|
39
|
+
|
|
40
|
+
this.loadStart = DTimestamp.now();
|
|
41
|
+
this.el.onload = () => {};
|
|
42
|
+
this.el.onerror = () => {};
|
|
43
|
+
this.el.src = dto.url;
|
|
44
|
+
console.time(this.TIMING_TAG);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
log(): void {}
|
|
48
|
+
}
|