@media-quest/engine 0.0.39 → 0.0.41

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