@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.
@@ -1,391 +1,376 @@
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
- flex: string;
71
- display: "flex" | "block";
72
- flexDirection: "row" | "colum";
73
- flexWrap: "nowrap" | "wrap";
74
- justifyContent:
75
- | "flex-start"
76
- | "flex-end"
77
- | "center"
78
- | "space-around"
79
- | "space-evenly"
80
- | "space-between";
81
- alignItems: "stretch" | "baseline" | "center" | "flex-start" | "flex-end";
82
- gap: DCss.Px;
83
- alignContent:
84
- | "stretch"
85
- | "center"
86
- | "flex-start"
87
- | "flex-end"
88
- | "space-around"
89
- | "space-evenly"
90
- | "space-between";
91
- }
92
-
93
- export namespace DStyle {
94
- // import isNumber = DUtil.isNumber;
95
- import isLengthUnit = DCss.isLengthUnit;
96
- export const normalize = <T extends HTMLElement>(el: T): T => {
97
- const s = el.style;
98
- s.position = "absolute";
99
- s.boxSizing = "border-box";
100
- s.padding = "0px";
101
- s.margin = "0px";
102
-
103
- s.height = "";
104
- s.width = "fit-content";
105
-
106
- s.bottom = "";
107
- s.top = "";
108
- s.left = "";
109
- s.right = "";
110
- s.flex = "none";
111
-
112
- s.boxShadow = "";
113
- s.fontSize = "12px";
114
- s.lineHeight = "1";
115
- s.textAlign = "center";
116
- s.textDecoration = "none";
117
- s.boxShadow = "";
118
- s.boxSizing = "border-box";
119
- s.fontWeight = "500";
120
- s.borderStyle = "";
121
- s.borderRadius = "";
122
- s.borderWidth = "";
123
- s.borderWidth = "0px";
124
- s.borderColor = "black";
125
- s.backgroundColor = "";
126
- s.border = "";
127
- s.borderStyle = "none";
128
- s.outline = "";
129
- s.wordSpacing = "";
130
- s.userSelect = "none";
131
- s.textShadow = "";
132
- return el;
133
- };
134
-
135
- export const applyStyles = <T extends HTMLElement>(
136
- el: T,
137
- style: Partial<DStyle>,
138
- scale: number,
139
- ): T => {
140
- const { isNumber, isString } = DUtil;
141
- // const scalePx = DCss.toStringCre(this.scale);
142
- const {
143
- x,
144
- y,
145
- left,
146
- right,
147
- top,
148
- bottom,
149
- backgroundColor,
150
- borderColor,
151
- borderWidth,
152
- borderRadius,
153
- borderStyle,
154
- w,
155
- opacity,
156
- cursor,
157
- fontSize,
158
- fontWeight,
159
- lineHeight,
160
- textColor,
161
- textAlign,
162
- translate,
163
- flex,
164
- margin,
165
- padding,
166
- letterSpacing,
167
- h,
168
- height,
169
- width,
170
-
171
- transform,
172
-
173
- visibility,
174
- justifyContent,
175
- alignContent,
176
- flexWrap,
177
- display,
178
- flexDirection,
179
-
180
- alignItems,
181
- position,
182
- paddingLeft,
183
- paddingTop,
184
- paddingRight,
185
- paddingBottom,
186
- gap,
187
-
188
- zIndex,
189
- //
190
- boxShadow,
191
- minWidth,
192
- maxWidth,
193
- minHeight,
194
- maxHeight,
195
- } = style;
196
-
197
- if (isNumber(zIndex)) {
198
- el.style.zIndex = "" + zIndex;
199
- }
200
-
201
- if (isString(translate)) {
202
- el.style.transform = translate;
203
- }
204
-
205
- if (isString(flex)) {
206
- el.style.flex = flex;
207
- }
208
-
209
- if (DCss.isLengthUnit(minWidth)) {
210
- el.style.minWidth = DCss.toString(minWidth, scale);
211
- }
212
-
213
- if (DCss.isLengthUnit(maxWidth)) {
214
- el.style.maxWidth = DCss.toString(maxWidth, scale);
215
- }
216
-
217
- if (typeof lineHeight === "number") {
218
- el.style.lineHeight = "" + lineHeight;
219
- }
220
-
221
- if (DCss.isLengthUnit(minHeight)) {
222
- el.style.minHeight = DCss.toString(minHeight, scale);
223
- }
224
-
225
- if (DCss.isLengthUnit(maxHeight)) {
226
- el.style.maxHeight = DCss.toString(maxHeight, scale);
227
- }
228
-
229
- if (boxShadow) {
230
- el.style.boxShadow = boxShadow;
231
- }
232
-
233
- if (gap) {
234
- el.style.gap = DCss.toString(gap, scale);
235
- }
236
-
237
- if (paddingLeft) {
238
- el.style.paddingLeft = DCss.toString(paddingLeft, scale);
239
- }
240
-
241
- if (paddingRight) {
242
- el.style.paddingRight = DCss.toString(paddingRight, scale);
243
- }
244
-
245
- if (paddingTop) {
246
- el.style.paddingTop = DCss.toString(paddingTop, scale);
247
- }
248
-
249
- if (paddingBottom) {
250
- el.style.paddingBottom = DCss.toString(paddingBottom, scale);
251
- }
252
-
253
- if (position) {
254
- el.style.position = position;
255
- }
256
-
257
- if (justifyContent) {
258
- el.style.justifyContent = justifyContent;
259
- }
260
-
261
- if (alignContent) {
262
- el.style.alignContent = alignContent;
263
- }
264
-
265
- if (flexWrap) {
266
- el.style.flexWrap = flexWrap;
267
- }
268
-
269
- if (display) {
270
- el.style.display = display;
271
- }
272
-
273
- if (flexDirection) {
274
- el.style.flexDirection = flexDirection;
275
- }
276
-
277
- if (alignItems) {
278
- el.style.alignItems = alignItems;
279
- }
280
-
281
- // this.el.style.fontWeight = '900';
282
- if (backgroundColor) {
283
- el.style.backgroundColor = backgroundColor;
284
- }
285
-
286
- if (cursor) {
287
- el.style.cursor = cursor;
288
- }
289
-
290
- if (transform) {
291
- el.style.transform = transform;
292
- }
293
-
294
- if (textColor) {
295
- el.style.color = textColor;
296
- }
297
-
298
- if (textAlign) {
299
- el.style.textAlign = textAlign;
300
- }
301
-
302
- if (borderColor) {
303
- el.style.borderColor = borderColor;
304
- }
305
-
306
- if (borderWidth) {
307
- el.style.borderWidth = DCss.toString(borderWidth, scale);
308
- }
309
-
310
- if (fontWeight) {
311
- el.style.fontWeight = fontWeight + "";
312
- }
313
-
314
- if (borderStyle) {
315
- el.style.borderStyle = borderStyle;
316
- }
317
-
318
- if (fontSize) {
319
- el.style.fontSize = DCss.toString(fontSize, scale);
320
- }
321
-
322
- if (DUtil.isNumber(x)) {
323
- el.style.left = x + "%";
324
- }
325
-
326
- if (DUtil.isNumber(y)) {
327
- el.style.bottom = y + "%";
328
- }
329
-
330
- if (DCss.isLengthUnit(height)) {
331
- el.style.height = DCss.toString(height, scale);
332
- }
333
-
334
- if (DCss.isLengthUnit(width)) {
335
- el.style.width = DCss.toString(width, scale);
336
- }
337
-
338
- if (DCss.isLengthUnit(left)) {
339
- el.style.left = DCss.toString(left, scale);
340
- }
341
-
342
- if (DCss.isLengthUnit(right)) {
343
- el.style.right = DCss.toString(right, scale);
344
- }
345
-
346
- if (DCss.isLengthUnit(bottom)) {
347
- el.style.bottom = DCss.toString(bottom, scale);
348
- }
349
-
350
- if (DCss.isLengthUnit(top)) {
351
- el.style.top = DCss.toString(top, scale);
352
- }
353
-
354
- if (DUtil.isNumber(h)) {
355
- el.style.height = DCss.toString(h, scale);
356
- }
357
-
358
- if (isNumber(w)) {
359
- el.style.width = DCss.toString(w, scale);
360
- }
361
-
362
- if (DCss.isLengthUnit(borderRadius)) {
363
- el.style.borderRadius = DCss.toString(borderRadius, scale);
364
- }
365
-
366
- if (letterSpacing) {
367
- el.style.letterSpacing = DCss.toString(letterSpacing, scale);
368
- }
369
-
370
- if (margin) {
371
- el.style.margin = DCss.toString(margin, scale);
372
- }
373
-
374
- if (padding) {
375
- el.style.padding = DCss.toString(padding, scale);
376
- }
377
-
378
- if (isNumber(opacity)) {
379
- el.style.opacity = opacity + "";
380
- }
381
-
382
- if (visibility) {
383
- el.style.visibility = visibility;
384
- }
385
-
386
- return el;
387
- };
388
-
389
- // const propNames = new Set(...ElementKeyNames);
390
- // export const validKey = (keyName: string) => propNames.has(keyName);
391
- }
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
+ flex: string;
71
+ display: "flex" | "block";
72
+ flexDirection: "row" | "colum";
73
+ flexWrap: "nowrap" | "wrap";
74
+ justifyContent:
75
+ | "flex-start"
76
+ | "flex-end"
77
+ | "center"
78
+ | "space-around"
79
+ | "space-evenly"
80
+ | "space-between";
81
+ alignItems: "stretch" | "baseline" | "center" | "flex-start" | "flex-end";
82
+ gap: DCss.Px;
83
+ alignContent:
84
+ | "stretch"
85
+ | "center"
86
+ | "flex-start"
87
+ | "flex-end"
88
+ | "space-around"
89
+ | "space-evenly"
90
+ | "space-between";
91
+ }
92
+
93
+ export namespace DStyle {
94
+ // import isNumber = DUtil.isNumber;
95
+ import isLengthUnit = DCss.isLengthUnit;
96
+ export const normalize = <T extends HTMLElement>(el: T): T => {
97
+ const s = el.style;
98
+ s.position = "absolute";
99
+ s.boxSizing = "border-box";
100
+ s.padding = "0px";
101
+ s.margin = "0px";
102
+
103
+ s.height = "";
104
+ s.width = "fit-content";
105
+
106
+ s.bottom = "";
107
+ s.top = "";
108
+ s.left = "";
109
+ s.right = "";
110
+ s.flex = "none";
111
+
112
+ s.boxShadow = "";
113
+ s.fontSize = "12px";
114
+ s.lineHeight = "1";
115
+ s.textAlign = "center";
116
+ s.textDecoration = "none";
117
+ s.boxShadow = "";
118
+ s.boxSizing = "border-box";
119
+ s.fontWeight = "500";
120
+ s.borderStyle = "";
121
+ s.borderRadius = "";
122
+ s.borderWidth = "";
123
+ s.borderWidth = "0px";
124
+ s.borderColor = "black";
125
+ s.backgroundColor = "";
126
+ s.border = "";
127
+ s.borderStyle = "none";
128
+ s.outline = "";
129
+ s.wordSpacing = "";
130
+ s.userSelect = "none";
131
+ s.textShadow = "";
132
+ return el;
133
+ };
134
+
135
+ export const applyStyles = <T extends HTMLElement>(
136
+ el: T,
137
+ style: Partial<DStyle>,
138
+ scale: number,
139
+ ): T => {
140
+ const { isNumber, isString } = DUtil;
141
+ // const scalePx = DCss.toStringCre(this.scale);
142
+ const {
143
+ x,
144
+ y,
145
+ left,
146
+ right,
147
+ top,
148
+ bottom,
149
+ backgroundColor,
150
+ borderColor,
151
+ borderWidth,
152
+ borderRadius,
153
+ borderStyle,
154
+ w,
155
+ opacity,
156
+ cursor,
157
+ fontSize,
158
+ fontWeight,
159
+ lineHeight,
160
+ textColor,
161
+ textAlign,
162
+ translate,
163
+ flex,
164
+ margin,
165
+ padding,
166
+ letterSpacing,
167
+ h,
168
+ height,
169
+ width,
170
+ transform,
171
+ visibility,
172
+ justifyContent,
173
+ alignContent,
174
+ flexWrap,
175
+ display,
176
+ flexDirection,
177
+ alignItems,
178
+ position,
179
+ paddingLeft,
180
+ paddingTop,
181
+ paddingRight,
182
+ paddingBottom,
183
+ gap,
184
+
185
+ zIndex,
186
+ //
187
+ boxShadow,
188
+ minWidth,
189
+ maxWidth,
190
+ minHeight,
191
+ maxHeight,
192
+ } = style;
193
+
194
+ if (isNumber(zIndex)) {
195
+ el.style.zIndex = "" + zIndex;
196
+ }
197
+ if (isString(flex)) {
198
+ el.style.flex = flex;
199
+ }
200
+
201
+ if (DCss.isLengthUnit(minWidth)) {
202
+ el.style.minWidth = DCss.toString(minWidth, scale);
203
+ }
204
+
205
+ if (DCss.isLengthUnit(maxWidth)) {
206
+ el.style.maxWidth = DCss.toString(maxWidth, scale);
207
+ }
208
+
209
+ if (typeof lineHeight === "number") {
210
+ el.style.lineHeight = "" + lineHeight;
211
+ }
212
+
213
+ if (DCss.isLengthUnit(minHeight)) {
214
+ el.style.minHeight = DCss.toString(minHeight, scale);
215
+ }
216
+
217
+ if (DCss.isLengthUnit(maxHeight)) {
218
+ el.style.maxHeight = DCss.toString(maxHeight, scale);
219
+ }
220
+
221
+ if (boxShadow) {
222
+ el.style.boxShadow = boxShadow;
223
+ }
224
+
225
+ if (gap) {
226
+ el.style.gap = DCss.toString(gap, scale);
227
+ }
228
+
229
+ if (paddingLeft) {
230
+ el.style.paddingLeft = DCss.toString(paddingLeft, scale);
231
+ }
232
+
233
+ if (paddingRight) {
234
+ el.style.paddingRight = DCss.toString(paddingRight, scale);
235
+ }
236
+
237
+ if (paddingTop) {
238
+ el.style.paddingTop = DCss.toString(paddingTop, scale);
239
+ }
240
+
241
+ if (paddingBottom) {
242
+ el.style.paddingBottom = DCss.toString(paddingBottom, scale);
243
+ }
244
+
245
+ if (position) {
246
+ el.style.position = position;
247
+ }
248
+ if (justifyContent) {
249
+ el.style.justifyContent = justifyContent;
250
+ }
251
+
252
+ if (alignContent) {
253
+ el.style.alignContent = alignContent;
254
+ }
255
+ if (flexWrap) {
256
+ el.style.flexWrap = flexWrap;
257
+ }
258
+ if (display) {
259
+ el.style.display = display;
260
+ }
261
+ if (flexDirection) {
262
+ el.style.flexDirection = flexDirection;
263
+ }
264
+ if (alignItems) {
265
+ el.style.alignItems = alignItems;
266
+ }
267
+
268
+ // this.el.style.fontWeight = '900';
269
+ if (backgroundColor) {
270
+ el.style.backgroundColor = backgroundColor;
271
+ }
272
+
273
+ if (cursor) {
274
+ el.style.cursor = cursor;
275
+ }
276
+
277
+ if (transform) {
278
+ el.style.transform = transform;
279
+ }
280
+
281
+ if (textColor) {
282
+ el.style.color = textColor;
283
+ }
284
+ if (textAlign) {
285
+ el.style.textAlign = textAlign;
286
+ }
287
+
288
+ if (borderColor) {
289
+ el.style.borderColor = borderColor;
290
+ }
291
+
292
+ if (borderWidth) {
293
+ el.style.borderWidth = DCss.toString(borderWidth, scale);
294
+ }
295
+
296
+ if (fontWeight) {
297
+ el.style.fontWeight = fontWeight + "";
298
+ }
299
+
300
+ if (borderStyle) {
301
+ el.style.borderStyle = borderStyle;
302
+ }
303
+
304
+ if (fontSize) {
305
+ el.style.fontSize = DCss.toString(fontSize, scale);
306
+ }
307
+
308
+ if (DUtil.isNumber(x)) {
309
+ el.style.left = x + "%";
310
+ }
311
+
312
+ if (DUtil.isNumber(y)) {
313
+ el.style.bottom = y + "%";
314
+ }
315
+
316
+ if (DCss.isLengthUnit(height)) {
317
+ el.style.height = DCss.toString(height, scale);
318
+ }
319
+
320
+ if (DCss.isLengthUnit(width)) {
321
+ el.style.width = DCss.toString(width, scale);
322
+ }
323
+
324
+ if (DCss.isLengthUnit(left)) {
325
+ el.style.left = DCss.toString(left, scale);
326
+ }
327
+
328
+ if (DCss.isLengthUnit(right)) {
329
+ el.style.right = DCss.toString(right, scale);
330
+ }
331
+
332
+ if (DCss.isLengthUnit(bottom)) {
333
+ el.style.bottom = DCss.toString(bottom, scale);
334
+ }
335
+
336
+ if (DCss.isLengthUnit(top)) {
337
+ el.style.top = DCss.toString(top, scale);
338
+ }
339
+
340
+ if (DUtil.isNumber(h)) {
341
+ el.style.height = DCss.toString(h, scale);
342
+ }
343
+
344
+ if (isNumber(w)) {
345
+ el.style.width = DCss.toString(w, scale);
346
+ }
347
+
348
+ if (DCss.isLengthUnit(borderRadius)) {
349
+ el.style.borderRadius = DCss.toString(borderRadius, scale);
350
+ }
351
+
352
+ if (letterSpacing) {
353
+ el.style.letterSpacing = DCss.toString(letterSpacing, scale);
354
+ }
355
+
356
+ if (margin) {
357
+ el.style.margin = DCss.toString(margin, scale);
358
+ }
359
+
360
+ if (padding) {
361
+ el.style.padding = DCss.toString(padding, scale);
362
+ }
363
+
364
+ if (isNumber(opacity)) {
365
+ el.style.opacity = opacity + "";
366
+ }
367
+
368
+ if (visibility) {
369
+ el.style.visibility = visibility;
370
+ }
371
+ return el;
372
+ };
373
+
374
+ // const propNames = new Set(...ElementKeyNames);
375
+ // export const validKey = (keyName: string) => propNames.has(keyName);
376
+ }