@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/Delement/DStyle.ts
CHANGED
|
@@ -1,165 +1,368 @@
|
|
|
1
|
-
import { DCss } from "./css";
|
|
2
|
-
import { DUtil } from "../utils/DUtil";
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| "
|
|
12
|
-
| "
|
|
13
|
-
| "
|
|
14
|
-
| "
|
|
15
|
-
| "
|
|
16
|
-
| "
|
|
17
|
-
| "
|
|
18
|
-
| "
|
|
19
|
-
| "
|
|
20
|
-
| "zoom-
|
|
21
|
-
| "
|
|
22
|
-
| "
|
|
23
|
-
| "
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// POSITION
|
|
27
|
-
h: number;
|
|
28
|
-
w: number;
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
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
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
1
|
+
import { DCss } from "./css";
|
|
2
|
+
import { DUtil } from "../utils/DUtil";
|
|
3
|
+
|
|
4
|
+
export type PStyle = Partial<DStyle>;
|
|
5
|
+
export interface DStyle {
|
|
6
|
+
opacity: number;
|
|
7
|
+
backgroundColor: string;
|
|
8
|
+
visibility: "visible" | "hidden";
|
|
9
|
+
cursor:
|
|
10
|
+
| "pointer"
|
|
11
|
+
| "help"
|
|
12
|
+
| "copy"
|
|
13
|
+
| "wait"
|
|
14
|
+
| "not-allowed"
|
|
15
|
+
| "context-menu"
|
|
16
|
+
| "move"
|
|
17
|
+
| "grabbing"
|
|
18
|
+
| "grab"
|
|
19
|
+
| "zoom-in"
|
|
20
|
+
| "zoom-out"
|
|
21
|
+
| "none"
|
|
22
|
+
| "auto"
|
|
23
|
+
| "default";
|
|
24
|
+
|
|
25
|
+
zIndex: number;
|
|
26
|
+
// POSITION
|
|
27
|
+
h: number;
|
|
28
|
+
w: number;
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
height: DCss.LengthUnit;
|
|
32
|
+
maxHeight: DCss.LengthUnit;
|
|
33
|
+
minHeight: DCss.LengthUnit;
|
|
34
|
+
width: DCss.LengthUnit;
|
|
35
|
+
maxWidth: DCss.LengthUnit;
|
|
36
|
+
minWidth: DCss.LengthUnit;
|
|
37
|
+
bottom: DCss.LengthUnit;
|
|
38
|
+
top: DCss.LengthUnit;
|
|
39
|
+
left: DCss.LengthUnit;
|
|
40
|
+
right: DCss.LengthUnit;
|
|
41
|
+
boxShadow: string;
|
|
42
|
+
|
|
43
|
+
// BORDERS
|
|
44
|
+
borderStyle: "solid" | "none" | "dotted" | "dashed";
|
|
45
|
+
borderRadius: DCss.Px | DCss.Percent;
|
|
46
|
+
borderWidth: DCss.Px;
|
|
47
|
+
borderColor: string;
|
|
48
|
+
|
|
49
|
+
margin: DCss.Px | DCss.Percent;
|
|
50
|
+
padding: DCss.Px | DCss.Percent;
|
|
51
|
+
paddingLeft: DCss.Px | DCss.Percent;
|
|
52
|
+
paddingRight: DCss.Px | DCss.Percent;
|
|
53
|
+
paddingTop: DCss.Px | DCss.Percent;
|
|
54
|
+
paddingBottom: DCss.Px | DCss.Percent;
|
|
55
|
+
|
|
56
|
+
// Translate
|
|
57
|
+
transform: string;
|
|
58
|
+
translate: string;
|
|
59
|
+
|
|
60
|
+
// TEXT
|
|
61
|
+
fontSize: DCss.Px;
|
|
62
|
+
textColor: string;
|
|
63
|
+
fontWeight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
64
|
+
textAlign: "right" | "left" | "center";
|
|
65
|
+
letterSpacing: DCss.Px;
|
|
66
|
+
lineHeight: number;
|
|
67
|
+
|
|
68
|
+
// LAYOUT & POSITIONING OVERRIDE
|
|
69
|
+
position: "absolute" | "relative";
|
|
70
|
+
display: "flex" | "block";
|
|
71
|
+
flexDirection: "row" | "colum";
|
|
72
|
+
flexWrap: "nowrap" | "wrap";
|
|
73
|
+
justifyContent:
|
|
74
|
+
| "flex-start"
|
|
75
|
+
| "flex-end"
|
|
76
|
+
| "center"
|
|
77
|
+
| "space-around"
|
|
78
|
+
| "space-evenly"
|
|
79
|
+
| "space-between";
|
|
80
|
+
alignItems: "stretch" | "baseline" | "center" | "flex-start" | "flex-end";
|
|
81
|
+
gap: DCss.Px;
|
|
82
|
+
alignContent:
|
|
83
|
+
| "stretch"
|
|
84
|
+
| "center"
|
|
85
|
+
| "flex-start"
|
|
86
|
+
| "flex-end"
|
|
87
|
+
| "space-around"
|
|
88
|
+
| "space-evenly"
|
|
89
|
+
| "space-between";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export namespace DStyle {
|
|
93
|
+
import isNumber = DUtil.isNumber;
|
|
94
|
+
import isLengthUnit = DCss.isLengthUnit;
|
|
95
|
+
export const normalize = <T extends HTMLElement>(el: T): T => {
|
|
96
|
+
const s = el.style;
|
|
97
|
+
// el.style.padding = "";
|
|
98
|
+
// el.style.margin = "";
|
|
99
|
+
// el.style.position = "absolute";
|
|
100
|
+
// el.style.boxSizing = "border-box";
|
|
101
|
+
s.position = "absolute";
|
|
102
|
+
s.boxSizing = "border-box";
|
|
103
|
+
s.bottom = "";
|
|
104
|
+
s.top = "";
|
|
105
|
+
s.left = "";
|
|
106
|
+
s.right = "";
|
|
107
|
+
s.boxShadow = "";
|
|
108
|
+
s.padding = "0px";
|
|
109
|
+
s.margin = "0px";
|
|
110
|
+
s.fontSize = "12px";
|
|
111
|
+
s.lineHeight = "1";
|
|
112
|
+
s.textAlign = "center";
|
|
113
|
+
s.textDecoration = "none";
|
|
114
|
+
s.boxShadow = "";
|
|
115
|
+
s.boxSizing = "border-box";
|
|
116
|
+
s.fontWeight = "500";
|
|
117
|
+
s.borderStyle = "";
|
|
118
|
+
s.borderRadius = "";
|
|
119
|
+
s.borderWidth = "";
|
|
120
|
+
s.borderWidth = "10px";
|
|
121
|
+
s.borderColor = "black";
|
|
122
|
+
s.backgroundColor = "";
|
|
123
|
+
s.border = "";
|
|
124
|
+
s.borderStyle = "none";
|
|
125
|
+
s.outline = "";
|
|
126
|
+
s.wordSpacing = "";
|
|
127
|
+
s.userSelect = "none";
|
|
128
|
+
s.textShadow = "";
|
|
129
|
+
return el;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const applyStyles = <T extends HTMLElement>(
|
|
133
|
+
el: T,
|
|
134
|
+
style: Partial<DStyle>,
|
|
135
|
+
scale: number,
|
|
136
|
+
): T => {
|
|
137
|
+
// const scalePx = DCss.toStringCre(this.scale);
|
|
138
|
+
const {
|
|
139
|
+
x,
|
|
140
|
+
y,
|
|
141
|
+
left,
|
|
142
|
+
right,
|
|
143
|
+
top,
|
|
144
|
+
bottom,
|
|
145
|
+
backgroundColor,
|
|
146
|
+
borderColor,
|
|
147
|
+
borderWidth,
|
|
148
|
+
borderRadius,
|
|
149
|
+
borderStyle,
|
|
150
|
+
w,
|
|
151
|
+
opacity,
|
|
152
|
+
cursor,
|
|
153
|
+
fontSize,
|
|
154
|
+
fontWeight,
|
|
155
|
+
lineHeight,
|
|
156
|
+
textColor,
|
|
157
|
+
textAlign,
|
|
158
|
+
translate,
|
|
159
|
+
margin,
|
|
160
|
+
padding,
|
|
161
|
+
letterSpacing,
|
|
162
|
+
h,
|
|
163
|
+
height,
|
|
164
|
+
width,
|
|
165
|
+
transform,
|
|
166
|
+
visibility,
|
|
167
|
+
justifyContent,
|
|
168
|
+
alignContent,
|
|
169
|
+
flexWrap,
|
|
170
|
+
display,
|
|
171
|
+
flexDirection,
|
|
172
|
+
alignItems,
|
|
173
|
+
position,
|
|
174
|
+
paddingLeft,
|
|
175
|
+
paddingTop,
|
|
176
|
+
paddingRight,
|
|
177
|
+
paddingBottom,
|
|
178
|
+
gap,
|
|
179
|
+
|
|
180
|
+
zIndex,
|
|
181
|
+
//
|
|
182
|
+
boxShadow,
|
|
183
|
+
minWidth,
|
|
184
|
+
maxWidth,
|
|
185
|
+
minHeight,
|
|
186
|
+
maxHeight,
|
|
187
|
+
} = style;
|
|
188
|
+
|
|
189
|
+
if (typeof zIndex === "number") {
|
|
190
|
+
el.style.zIndex = "" + zIndex;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (DCss.isLengthUnit(minWidth)) {
|
|
194
|
+
el.style.minWidth = DCss.toString(minWidth, scale);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (DCss.isLengthUnit(maxWidth)) {
|
|
198
|
+
el.style.maxWidth = DCss.toString(maxWidth, scale);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (typeof lineHeight === "number") {
|
|
202
|
+
el.style.lineHeight = "" + lineHeight;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (DCss.isLengthUnit(minHeight)) {
|
|
206
|
+
el.style.minHeight = DCss.toString(minHeight, scale);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (DCss.isLengthUnit(maxHeight)) {
|
|
210
|
+
el.style.maxHeight = DCss.toString(maxHeight, scale);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (boxShadow) {
|
|
214
|
+
el.style.boxShadow = boxShadow;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (gap) {
|
|
218
|
+
el.style.gap = DCss.toString(gap, scale);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (paddingLeft) {
|
|
222
|
+
el.style.paddingLeft = DCss.toString(paddingLeft, scale);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (paddingRight) {
|
|
226
|
+
el.style.paddingRight = DCss.toString(paddingRight, scale);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (paddingTop) {
|
|
230
|
+
el.style.paddingTop = DCss.toString(paddingTop, scale);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (paddingBottom) {
|
|
234
|
+
el.style.paddingBottom = DCss.toString(paddingBottom, scale);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (position) {
|
|
238
|
+
el.style.position = position;
|
|
239
|
+
}
|
|
240
|
+
if (justifyContent) {
|
|
241
|
+
el.style.justifyContent = justifyContent;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (alignContent) {
|
|
245
|
+
el.style.alignContent = alignContent;
|
|
246
|
+
}
|
|
247
|
+
if (flexWrap) {
|
|
248
|
+
el.style.flexWrap = flexWrap;
|
|
249
|
+
}
|
|
250
|
+
if (display) {
|
|
251
|
+
el.style.display = display;
|
|
252
|
+
}
|
|
253
|
+
if (flexDirection) {
|
|
254
|
+
el.style.flexDirection = flexDirection;
|
|
255
|
+
}
|
|
256
|
+
if (alignItems) {
|
|
257
|
+
el.style.alignItems = alignItems;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// this.el.style.fontWeight = '900';
|
|
261
|
+
if (backgroundColor) {
|
|
262
|
+
el.style.backgroundColor = backgroundColor;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (cursor) {
|
|
266
|
+
el.style.cursor = cursor;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (transform) {
|
|
270
|
+
el.style.transform = transform;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (textColor) {
|
|
274
|
+
el.style.color = textColor;
|
|
275
|
+
}
|
|
276
|
+
if (textAlign) {
|
|
277
|
+
el.style.textAlign = textAlign;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (borderColor) {
|
|
281
|
+
el.style.borderColor = borderColor;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (borderWidth) {
|
|
285
|
+
el.style.borderWidth = DCss.toString(borderWidth, scale);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (fontWeight) {
|
|
289
|
+
el.style.fontWeight = fontWeight + "";
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (borderStyle) {
|
|
293
|
+
el.style.borderStyle = borderStyle;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (fontSize) {
|
|
297
|
+
el.style.fontSize = DCss.toString(fontSize, scale);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (DUtil.isNumber(x)) {
|
|
301
|
+
el.style.left = x + "%";
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (DUtil.isNumber(y)) {
|
|
305
|
+
el.style.bottom = y + "%";
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (DCss.isLengthUnit(height)) {
|
|
309
|
+
el.style.height = DCss.toString(height, scale);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (DCss.isLengthUnit(width)) {
|
|
313
|
+
el.style.width = DCss.toString(width, scale);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (DCss.isLengthUnit(left)) {
|
|
317
|
+
el.style.left = DCss.toString(left, scale);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (DCss.isLengthUnit(right)) {
|
|
321
|
+
el.style.right = DCss.toString(right, scale);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (DCss.isLengthUnit(bottom)) {
|
|
325
|
+
el.style.bottom = DCss.toString(bottom, scale);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (DCss.isLengthUnit(top)) {
|
|
329
|
+
el.style.top = DCss.toString(top, scale);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (DUtil.isNumber(h)) {
|
|
333
|
+
el.style.height = DCss.toString(h, scale);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (isNumber(w)) {
|
|
337
|
+
el.style.width = DCss.toString(w, scale);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (DCss.isLengthUnit(borderRadius)) {
|
|
341
|
+
el.style.borderRadius = DCss.toString(borderRadius, scale);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (letterSpacing) {
|
|
345
|
+
el.style.letterSpacing = DCss.toString(letterSpacing, scale);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (margin) {
|
|
349
|
+
el.style.margin = DCss.toString(margin, scale);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (padding) {
|
|
353
|
+
el.style.padding = DCss.toString(padding, scale);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (isNumber(opacity)) {
|
|
357
|
+
el.style.opacity = opacity + "";
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (visibility) {
|
|
361
|
+
el.style.visibility = visibility;
|
|
362
|
+
}
|
|
363
|
+
return el;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// const propNames = new Set(...ElementKeyNames);
|
|
367
|
+
// export const validKey = (keyName: string) => propNames.has(keyName);
|
|
368
|
+
}
|
package/src/Delement/DText.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
-
import { ScaleService } from "../engine/scale";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
+
import { ScaleService } from "../engine/scale";
|
|
3
|
+
import { ButtonClickAction } from "./button-click-action";
|
|
4
|
+
|
|
5
|
+
export interface DTextDto extends DElementBaseDto {
|
|
6
|
+
readonly _tag: "p";
|
|
7
|
+
readonly innerText: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class DText extends DElement<HTMLParagraphElement> {
|
|
11
|
+
constructor(dto: DTextDto, scale: ScaleService) {
|
|
12
|
+
super(document.createElement("p"), dto, scale);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
16
|
+
this.el.onclick = () => {
|
|
17
|
+
const onClick = this.dto.onClick;
|
|
18
|
+
if (onClick) {
|
|
19
|
+
clickHandler(onClick);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/Delement/Ddiv.ts
CHANGED
|
@@ -1,25 +1,44 @@
|
|
|
1
|
-
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
-
import { DText, DTextDto } from "./DText";
|
|
3
|
-
import { DImg, DImgDto } from "./DImg";
|
|
4
|
-
import { ScaleService } from "../engine/scale";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
+
import { DText, DTextDto } from "./DText";
|
|
3
|
+
import { DImg, DImgDto } from "./DImg";
|
|
4
|
+
import { ScaleService } from "../engine/scale";
|
|
5
|
+
import { DButton, DButtonDto } from "./DButton";
|
|
6
|
+
import { ButtonClickAction } from "./button-click-action";
|
|
7
|
+
|
|
8
|
+
export interface DDivDto extends DElementBaseDto {
|
|
9
|
+
readonly _tag: "div";
|
|
10
|
+
readonly children: Array<DTextDto | DImgDto | DButtonDto>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class DDiv extends DElement<HTMLDivElement> {
|
|
14
|
+
private readonly TAG = "[ DDiv ]: ";
|
|
15
|
+
protected readonly defaultStyle = { x: 22, y: 4 };
|
|
16
|
+
private children: Array<DText | DImg | DButton> = [];
|
|
17
|
+
|
|
18
|
+
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
19
|
+
this.el.onclick = () => {
|
|
20
|
+
const action = this.dto.onClick;
|
|
21
|
+
if (action) {
|
|
22
|
+
clickHandler(action);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this.children.forEach((child) => {
|
|
26
|
+
child.registerClickHandler(clickHandler);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(dto: DDivDto, scale: ScaleService, children: Array<DText | DImg | DButton>) {
|
|
31
|
+
const d = document.createElement("div");
|
|
32
|
+
super(d, dto, scale);
|
|
33
|
+
this.children = children;
|
|
34
|
+
|
|
35
|
+
this.children.forEach((child) => {
|
|
36
|
+
child.appendYourself(this.el);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
protected whenConstructed() {
|
|
40
|
+
this.children.forEach((child) => {
|
|
41
|
+
console.log(child);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|