@zuzjs/ui 0.5.3 → 0.5.5
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/bin.js +29 -3
- package/dist/comps/accordion.d.ts +12 -0
- package/dist/comps/accordion.js +13 -0
- package/dist/comps/alert.d.ts +15 -0
- package/dist/comps/alert.js +15 -0
- package/dist/comps/animate.d.ts +1 -1
- package/dist/comps/avatar.d.ts +13 -0
- package/dist/comps/avatar.js +11 -0
- package/dist/comps/base.d.ts +4 -13
- package/dist/comps/base.js +3 -2
- package/dist/comps/box.d.ts +2 -2
- package/dist/comps/box.js +10 -3
- package/dist/comps/button.d.ts +3 -5
- package/dist/comps/button.js +12 -3
- package/dist/comps/checkbox.d.ts +1 -1
- package/dist/comps/checkbox.js +19 -0
- package/dist/comps/contextmenu.d.ts +1 -1
- package/dist/comps/cover.d.ts +1 -1
- package/dist/comps/cover.js +15 -0
- package/dist/comps/drawer.js +5 -1
- package/dist/comps/editor.js +8 -1
- package/dist/comps/form.d.ts +35 -5
- package/dist/comps/form.js +67 -21
- package/dist/comps/heading.js +13 -0
- package/dist/comps/icon.d.ts +4 -5
- package/dist/comps/icon.js +15 -3
- package/dist/comps/image.d.ts +1 -1
- package/dist/comps/input.d.ts +2 -8
- package/dist/comps/input.js +5 -5
- package/dist/comps/password.d.ts +3 -0
- package/dist/comps/password.js +30 -0
- package/dist/comps/select.d.ts +2 -1
- package/dist/comps/select.js +28 -3
- package/dist/comps/sheet.js +3 -0
- package/dist/comps/spinner.d.ts +1 -1
- package/dist/comps/spinner.js +1 -0
- package/dist/comps/tabview.js +8 -1
- package/dist/comps/textwheel.d.ts +1 -1
- package/dist/comps/textwheel.js +2 -0
- package/dist/comps/useBase/base.types.d.ts +64 -0
- package/dist/comps/useBase/base.types.js +1 -0
- package/dist/comps/useBase/index.d.ts +10 -0
- package/dist/comps/useBase/index.js +62 -0
- package/dist/funs/colors.d.ts +6 -0
- package/dist/funs/colors.js +6 -0
- package/dist/funs/css.d.ts +3 -1
- package/dist/funs/css.js +183 -15
- package/dist/funs/events.js +3 -0
- package/dist/funs/index.d.ts +6 -0
- package/dist/funs/index.js +36 -2
- package/dist/funs/stylesheet.d.ts +1 -0
- package/dist/funs/stylesheet.js +66 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useImage.d.ts +2 -0
- package/dist/hooks/useImage.js +22 -0
- package/dist/hooks/useKeyBind.d.ts +3 -0
- package/dist/hooks/useKeyBind.js +4 -0
- package/dist/hooks/useMounted.d.ts +15 -0
- package/dist/hooks/useMounted.js +16 -1
- package/dist/hooks/useToast.d.ts +1 -1
- package/dist/hooks/useToast.js +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/styles.css +1 -1
- package/dist/types/enums.d.ts +115 -1
- package/dist/types/enums.js +137 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/interfaces.d.ts +11 -2
- package/package.json +1 -1
package/dist/funs/css.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __SALT, FIELNAME_KEY, isColor, isHexColor, isNumber, LINE_KEY, setDeep } from "./index.js";
|
|
2
|
-
import { cssAnimationCurves, cssDirect, cssProps, cssTransformKeys, cssWithKeys } from "./stylesheet.js";
|
|
2
|
+
import { cssAnimationCurves, cssDirect, cssProps, cssPropsWithColor, cssTransformKeys, cssWithKeys } from "./stylesheet.js";
|
|
3
3
|
import Hashids from "hashids";
|
|
4
4
|
import { TRANSITION_CURVES, TRANSITIONS } from "../types/enums.js";
|
|
5
5
|
import md5 from "md5";
|
|
6
|
+
import pc from "picocolors";
|
|
6
7
|
class CSS {
|
|
7
8
|
cx;
|
|
8
9
|
cache;
|
|
@@ -26,6 +27,7 @@ class CSS {
|
|
|
26
27
|
_cli;
|
|
27
28
|
DIRECT_VALUES;
|
|
28
29
|
PROPS_VALUES;
|
|
30
|
+
_currentFile;
|
|
29
31
|
constructor(options) {
|
|
30
32
|
const opts = options || {};
|
|
31
33
|
this._cli = false;
|
|
@@ -38,14 +40,15 @@ class CSS {
|
|
|
38
40
|
xl: `Extra Large Devices (Large Desktops)`,
|
|
39
41
|
};
|
|
40
42
|
this.mediaQueries = {
|
|
41
|
-
ph: `(max-width: 599px)`,
|
|
42
|
-
sm: `(min-width: 600px) and (max-width: 767px)`,
|
|
43
|
-
md: `(min-width: 768px) and (max-width: 991px)`,
|
|
44
|
-
lg: `(min-width: 992px) and (max-width: 1199px)`,
|
|
45
|
-
xl: `(min-width: 1200px)`,
|
|
43
|
+
ph: `(max-width: 599px)`, /* Extra Small Devices (Phones) */
|
|
44
|
+
sm: `(min-width: 600px) and (max-width: 767px)`, /* Small Devices (Tablets) */
|
|
45
|
+
md: `(min-width: 768px) and (max-width: 991px)`, /* Medium Devices (Small Laptops) */
|
|
46
|
+
lg: `(min-width: 992px) and (max-width: 1199px)`, /* Large Devices (Laptops and Desktops) */
|
|
47
|
+
xl: `(min-width: 1200px)`, /* Extra Large Devices (Large Desktops) */
|
|
46
48
|
};
|
|
47
49
|
this.cx = [];
|
|
48
50
|
this.cache = {};
|
|
51
|
+
this._currentFile = `?`;
|
|
49
52
|
this.unit = opts.unit || `px`;
|
|
50
53
|
this.seperator = `__@@__`;
|
|
51
54
|
this.hashids = new Hashids(__SALT, 5);
|
|
@@ -58,9 +61,9 @@ class CSS {
|
|
|
58
61
|
`flex`, `opacity`, `z-index`, `zIndex`, `color`, `line-height`, `anim`, `scale`, `saturate`
|
|
59
62
|
];
|
|
60
63
|
this.keysWithoutCommaToSpace = [
|
|
61
|
-
`transform`, `translate`, `color`, `background`, `background-color`, `backgroundColor`,
|
|
64
|
+
`transform`, `translate`, `color`, `background`, `background-color`, `backgroundColor`, `backgroundImage`, `background-image`,
|
|
62
65
|
`border`, `border-bottom`, `border-top`, `border-left`, `border-right`,
|
|
63
|
-
`grid-template-rows`, `grid-template-columns`
|
|
66
|
+
`grid-template-rows`, `grid-template-columns`, `clip-path`, `clipPath`,
|
|
64
67
|
];
|
|
65
68
|
this.propCounter = {};
|
|
66
69
|
this.ids = [];
|
|
@@ -77,6 +80,7 @@ class CSS {
|
|
|
77
80
|
arr.push(cssDirect[k].replace(/\s+/g, ``));
|
|
78
81
|
return arr;
|
|
79
82
|
}, []);
|
|
83
|
+
// extendGlobals()
|
|
80
84
|
}
|
|
81
85
|
buildMediaQueries(queries) {
|
|
82
86
|
const self = this;
|
|
@@ -92,7 +96,9 @@ class CSS {
|
|
|
92
96
|
styleSheet(cache, pseudo = ``) {
|
|
93
97
|
const self = this;
|
|
94
98
|
const scss = [];
|
|
99
|
+
// console.log(cache)
|
|
95
100
|
const build = (key, value) => {
|
|
101
|
+
// console.log(`build`, key, value)
|
|
96
102
|
const __build = (_key, _value) => {
|
|
97
103
|
let _css = `${self.pseudoList.includes(`@${_key}`) ? `&:` : `.`}${_key}{`;
|
|
98
104
|
if (`object` == typeof _value) {
|
|
@@ -114,6 +120,7 @@ class CSS {
|
|
|
114
120
|
let css = ``;
|
|
115
121
|
if (`object` == typeof value && Object.keys(value)[0] in this.mediaQueries) {
|
|
116
122
|
const mq = Object.keys(value)[0];
|
|
123
|
+
// css += `@media screen and ${this.mediaQueries[mq]}{`
|
|
117
124
|
let __css = `.${key}{`;
|
|
118
125
|
const _value = value[mq];
|
|
119
126
|
for (const prop in _value) {
|
|
@@ -128,6 +135,8 @@ class CSS {
|
|
|
128
135
|
this._mediaQueries[mq] = this._mediaQueries[mq] || [];
|
|
129
136
|
this._mediaQueries[mq].push(__css);
|
|
130
137
|
}
|
|
138
|
+
// else if ( key in self.mediaQueries ){
|
|
139
|
+
// }
|
|
131
140
|
else {
|
|
132
141
|
css += __build(key, value);
|
|
133
142
|
}
|
|
@@ -151,7 +160,9 @@ class CSS {
|
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
162
|
}
|
|
154
|
-
return scss
|
|
163
|
+
return scss
|
|
164
|
+
.filter(x => x.trim() != `.{}`)
|
|
165
|
+
.join(`\n`);
|
|
155
166
|
}
|
|
156
167
|
_styleSheet(cache) {
|
|
157
168
|
const self = this;
|
|
@@ -179,9 +190,11 @@ class CSS {
|
|
|
179
190
|
for (const prop in value) {
|
|
180
191
|
if (`string` === typeof value[prop]) {
|
|
181
192
|
_extend.push(`.${prop}`);
|
|
193
|
+
// _extend.push(self.buildCache[prop])
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
196
|
if (_extend.length > 0)
|
|
197
|
+
// css += _extend.join(``)
|
|
185
198
|
css += `@extend ${_extend.join(`, `)};`;
|
|
186
199
|
for (const prop in value) {
|
|
187
200
|
if (`object` === typeof value[prop]) {
|
|
@@ -192,6 +205,9 @@ class CSS {
|
|
|
192
205
|
css += `}`;
|
|
193
206
|
return css;
|
|
194
207
|
};
|
|
208
|
+
/**
|
|
209
|
+
* Build Master Keys
|
|
210
|
+
*/
|
|
195
211
|
for (const key in cache) {
|
|
196
212
|
if (key == FIELNAME_KEY) {
|
|
197
213
|
scss.push(`/**\n* @file ${cache[key]}\n*/`);
|
|
@@ -199,17 +215,24 @@ class CSS {
|
|
|
199
215
|
}
|
|
200
216
|
extractMasterKeys(key, cache[key]);
|
|
201
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Extract LINE_KEY
|
|
220
|
+
*/
|
|
202
221
|
for (const key in cache) {
|
|
203
222
|
if (key.startsWith(LINE_KEY)) {
|
|
204
223
|
scss.push(cache[key]);
|
|
205
224
|
delete cache[key];
|
|
206
225
|
}
|
|
207
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Build Extends
|
|
229
|
+
*/
|
|
208
230
|
for (const key in cache) {
|
|
209
231
|
if (`object` == typeof cache[key]) {
|
|
210
232
|
scss.push(build(key, cache[key]));
|
|
211
233
|
}
|
|
212
234
|
}
|
|
235
|
+
// scss.push(self.classLine)
|
|
213
236
|
return scss.join(`\n`);
|
|
214
237
|
}
|
|
215
238
|
cleanKey(key) {
|
|
@@ -232,6 +255,7 @@ class CSS {
|
|
|
232
255
|
const __k = self.cleanKey(_k);
|
|
233
256
|
if (`object` == typeof cache[_k]) {
|
|
234
257
|
const _d = oid(_k, cache[_k]);
|
|
258
|
+
// console.log(_d)
|
|
235
259
|
let _indices = 0;
|
|
236
260
|
for (let i = 0; i < _d.length; i++) {
|
|
237
261
|
_indices += self.chars.indexOf(_d.charAt(i));
|
|
@@ -255,6 +279,7 @@ class CSS {
|
|
|
255
279
|
return _;
|
|
256
280
|
}
|
|
257
281
|
makeUnit(k, v) {
|
|
282
|
+
// console.log(`unit`, k, v)
|
|
258
283
|
if (k == `rotate`) {
|
|
259
284
|
return `deg`;
|
|
260
285
|
}
|
|
@@ -264,7 +289,26 @@ class CSS {
|
|
|
264
289
|
return ``;
|
|
265
290
|
return this.unit;
|
|
266
291
|
}
|
|
292
|
+
makeColor(v) {
|
|
293
|
+
if (v.charAt(0) == `#`) {
|
|
294
|
+
v = v.substring(1);
|
|
295
|
+
}
|
|
296
|
+
if (v.charAt(0) == `$`) {
|
|
297
|
+
return `var(--${v.replace(`$`, ``)})`;
|
|
298
|
+
}
|
|
299
|
+
if (/^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(`#${v}`) ||
|
|
300
|
+
/^#([0-9A-F]{3}){1,2}$/i.test(`#${v}`)) {
|
|
301
|
+
return `#${v}`;
|
|
302
|
+
}
|
|
303
|
+
else if (v.includes(`rgb`) || v.includes(`rgba`)) {
|
|
304
|
+
return v.replace(`[`, `(`).replace(`]`, `)`);
|
|
305
|
+
}
|
|
306
|
+
else
|
|
307
|
+
return v.trim();
|
|
308
|
+
}
|
|
267
309
|
makeValue(k, v) {
|
|
310
|
+
// const hasGradient = v.includes(`gradient`)
|
|
311
|
+
const self = this;
|
|
268
312
|
if (k in this.PROPS) {
|
|
269
313
|
const key = this.PROPS[k];
|
|
270
314
|
let value;
|
|
@@ -272,18 +316,54 @@ class CSS {
|
|
|
272
316
|
let hasImportant = v.charAt(v.length - 1) == `!`;
|
|
273
317
|
v = hasImportant ? v.slice(0, -1) : v;
|
|
274
318
|
let important = hasImportant ? ` !important` : ``;
|
|
275
|
-
|
|
319
|
+
let isGradient = v.startsWith(`gradient`) || v.startsWith(`linear-gradient`) || v.startsWith(`radial-gradient`);
|
|
320
|
+
/**
|
|
321
|
+
* Gradients
|
|
322
|
+
*/
|
|
323
|
+
if (isGradient) {
|
|
324
|
+
if (v.startsWith(`gradient`)) {
|
|
325
|
+
v = `linear-${v}`;
|
|
326
|
+
}
|
|
327
|
+
//linear-gradient-to-bottom-blue-green
|
|
328
|
+
const [_gtype, _xyz, _gto, _gdeg, ..._colors] = v.split(`-`);
|
|
329
|
+
// const _gdegree = _gdeg.isNumber() ? `${_gdeg}deg` : `to ${_gto}`
|
|
330
|
+
const _gdegree = /^[+-]?\d+(\.\d+)?$/.test(_gdeg) ? `${_gdeg}deg` : `to ${_gdeg}`;
|
|
331
|
+
const _gcolors = _colors.reduce((arr, val) => {
|
|
332
|
+
arr.push(self.makeColor(val));
|
|
333
|
+
return arr;
|
|
334
|
+
}, []).join(`, `);
|
|
335
|
+
switch (_gtype) {
|
|
336
|
+
case `linear`:
|
|
337
|
+
value = `linear-gradient(${_gdegree}, ${_gcolors})`;
|
|
338
|
+
break;
|
|
339
|
+
case `radial`:
|
|
340
|
+
// value = `radial-gradient(${_gparts[1]})`
|
|
341
|
+
break;
|
|
342
|
+
default:
|
|
343
|
+
value = v;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Variable
|
|
349
|
+
*/
|
|
350
|
+
else if (v.charAt(0) == `$`) {
|
|
276
351
|
value = `var(--${v.replace(`$`, ``)})`;
|
|
277
352
|
}
|
|
278
353
|
else if (v.trim() == `transparent`) {
|
|
279
354
|
value = `rgba(0,0,0,0)`;
|
|
280
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* border
|
|
358
|
+
*/
|
|
281
359
|
else if ([`border`, `borderBottom`, `borderTop`, `borderLeft`, `borderRight`].includes(k)) {
|
|
282
360
|
const _parts = [];
|
|
361
|
+
// console.log(`--border`, key, v)
|
|
283
362
|
if (v.match(this.rgbaRegex)) {
|
|
284
363
|
_parts.push(v.match(this.rgbaRegex)[0].replace(`[`, `(`).replace(`]`, `)`));
|
|
285
364
|
v = v.replace(this.rgbaRegex, ``).trim().replace(`,,`, `,`);
|
|
286
365
|
}
|
|
366
|
+
// console.log(`-border`, key, v, _parts)
|
|
287
367
|
v.split(`,`).map((p) => {
|
|
288
368
|
if (p.includes(`rgb`) || p.includes(`rgba`) || isColor(`#${p}`) || p.startsWith(`$`)) {
|
|
289
369
|
if (p.includes(`rgb`) || p.includes(`rgba`)) {
|
|
@@ -305,8 +385,13 @@ class CSS {
|
|
|
305
385
|
}
|
|
306
386
|
});
|
|
307
387
|
value = _parts.join(` `);
|
|
388
|
+
// console.log(`border`, value)
|
|
308
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* Color
|
|
392
|
+
*/
|
|
309
393
|
else if ([`color`, `bg`, `background`, `background-color`, `backgroundColor`].includes(key)) {
|
|
394
|
+
// else if ( [`color`].includes( key ) ){
|
|
310
395
|
if (v.charAt(0) == `#`) {
|
|
311
396
|
v = v.substring(1);
|
|
312
397
|
}
|
|
@@ -320,9 +405,15 @@ class CSS {
|
|
|
320
405
|
else
|
|
321
406
|
value = v.trim();
|
|
322
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* FontWeight
|
|
410
|
+
*/
|
|
323
411
|
else if (key == `font-weight`) {
|
|
324
412
|
value = v;
|
|
325
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* value with brackets like calc(), var() should be passed as calc[value]
|
|
416
|
+
*/
|
|
326
417
|
else if (v.match(/\[(.*?)\]/g)) {
|
|
327
418
|
try {
|
|
328
419
|
const vs = v.match(/\[(.*?)\]/g)[0].slice(1, -1);
|
|
@@ -332,16 +423,22 @@ class CSS {
|
|
|
332
423
|
catch (e) { }
|
|
333
424
|
}
|
|
334
425
|
else {
|
|
426
|
+
// ${v.charAt(0) == `$` ? `var(--${v.substring(1)})` : v}
|
|
427
|
+
// if ( key.includes(`padding`) ) console.log(`->padding`, v)
|
|
335
428
|
if (v.includes(`,`)) {
|
|
429
|
+
// console.log(`vwithcomma`, v)
|
|
336
430
|
let __v = [];
|
|
337
431
|
v.split(`,`).map((_) => {
|
|
338
432
|
if (_.charAt(0) == `#`) {
|
|
339
433
|
_ = _.substring(1);
|
|
340
434
|
}
|
|
435
|
+
//Variable
|
|
341
436
|
if (_.startsWith(`$`)) {
|
|
342
437
|
__v.push(`var(--${_.substring(1)})`);
|
|
343
438
|
}
|
|
344
|
-
|
|
439
|
+
//Color
|
|
440
|
+
else if (cssPropsWithColor.includes(_) && isColor(`#${_}`)) {
|
|
441
|
+
// else if ( isColor(_) ){
|
|
345
442
|
if (_.includes(`rgb`) || _.includes(`rgba`)) {
|
|
346
443
|
__v.push(_.replace(`[`, `(`).replace(`]`, `)`));
|
|
347
444
|
}
|
|
@@ -350,19 +447,28 @@ class CSS {
|
|
|
350
447
|
}
|
|
351
448
|
}
|
|
352
449
|
else {
|
|
450
|
+
// console.log(`comma`, key, v, this.makeUnit(key, v))
|
|
353
451
|
__v.push(`${_}${this.makeUnit(key, _)}`);
|
|
354
452
|
}
|
|
355
453
|
});
|
|
356
454
|
value = __v.join(` `);
|
|
455
|
+
// console.log(key, value)
|
|
456
|
+
// if( k == `shadow` || k == `box-shadow` ) console.log(value)
|
|
357
457
|
}
|
|
358
458
|
else
|
|
359
459
|
value = `${v}${this.makeUnit(key, v)}`;
|
|
360
460
|
}
|
|
361
461
|
if (!value)
|
|
362
462
|
return ``;
|
|
463
|
+
// if ( key == `clip` || key == `clip-path` ) console.log(`makevalue`, key, value)
|
|
464
|
+
// if ( key.includes(`border`) ) console.log(`--border`, `${key}: ${value}${important};`)
|
|
363
465
|
value = value.includes(`,`) && !this.keysWithoutCommaToSpace.includes(key) ? value.replace(`,`, ` `) : value;
|
|
466
|
+
// if ( key.includes(`padding`) ) console.log(`->padding`, `${key}: ${value}${important};`)
|
|
364
467
|
if (key == `content`)
|
|
365
468
|
value = `"${value}"`;
|
|
469
|
+
// if ( key == `extend` ){
|
|
470
|
+
// value = value.split(`,`).reduce((acc: string[], v: string) => acc.push(`${v.startsWith(`.`) ? `` : `.`}${v}`) && acc, []).join(`,`)
|
|
471
|
+
// }
|
|
366
472
|
return `${key}: ${value}${important};`;
|
|
367
473
|
}
|
|
368
474
|
return ``;
|
|
@@ -379,7 +485,9 @@ class CSS {
|
|
|
379
485
|
const md = md5(_out);
|
|
380
486
|
let _ = [];
|
|
381
487
|
const _mi = (_k, _v) => {
|
|
488
|
+
// console.log(_k, _v, Math.abs(self.DIRECT_KEYS.indexOf(_k)) + Math.abs(self.PROPS_VALUES.indexOf(_k)))
|
|
382
489
|
let i = Math.abs(self.DIRECT_KEYS.indexOf(_k)) + Math.abs(self.PROPS_VALUES.indexOf(_k));
|
|
490
|
+
// _k in self.DIRECT ? self.DIRECT_KEYS.indexOf(_k) : _k in self.PROPS_VALUES ? self.PROPS_VALUES.indexOf(_k) : 0
|
|
383
491
|
_.push(i);
|
|
384
492
|
const nums = _v.match(/[0-9]/g);
|
|
385
493
|
if (nums) {
|
|
@@ -400,8 +508,11 @@ class CSS {
|
|
|
400
508
|
const ok = _ok.trim();
|
|
401
509
|
const ov = _ov ? _ov.trim() : v;
|
|
402
510
|
if (ov == ``) {
|
|
403
|
-
|
|
511
|
+
console.log(pc.yellow(`[${self._currentFile}]`), pc.cyan(k), pc.red(`value is empty.`));
|
|
512
|
+
return ``;
|
|
513
|
+
// throw new TypeError()
|
|
404
514
|
}
|
|
515
|
+
/**Prefix */
|
|
405
516
|
let _cp = ok.charAt(0);
|
|
406
517
|
if (self.PROPS[ok]?.indexOf("-") > -1) {
|
|
407
518
|
_cp = "";
|
|
@@ -424,6 +535,9 @@ class CSS {
|
|
|
424
535
|
word = word.replace(/\s+/g, ``);
|
|
425
536
|
if (word == ``)
|
|
426
537
|
return;
|
|
538
|
+
if (word[word.length - 1] == `:`) {
|
|
539
|
+
word = word.slice(0, -1);
|
|
540
|
+
}
|
|
427
541
|
const _kw = word in self.propCounter ? ++self.propCounter[word] : self.propCounter[word] = 1;
|
|
428
542
|
if (isLevel) {
|
|
429
543
|
levels.push(`${word}${self.seperator}${_kw}`);
|
|
@@ -451,15 +565,23 @@ class CSS {
|
|
|
451
565
|
processWord();
|
|
452
566
|
}
|
|
453
567
|
else {
|
|
568
|
+
//SKIPABLE
|
|
569
|
+
// if([`(`].includes(char) && level == 0 ){
|
|
570
|
+
// //DON'T ADD
|
|
571
|
+
// }
|
|
454
572
|
if ([`&`].includes(char)) {
|
|
455
573
|
isLevel = true;
|
|
456
574
|
}
|
|
575
|
+
//Level Start
|
|
457
576
|
else if ([`(`].includes(char) && isLevel) {
|
|
458
577
|
processWord();
|
|
459
578
|
}
|
|
579
|
+
//Level End
|
|
460
580
|
else if ([`)`].includes(char)) {
|
|
461
581
|
processWord();
|
|
582
|
+
// console.log(`before->`, levels)
|
|
462
583
|
levels.splice(-1, 1);
|
|
584
|
+
// console.log(`after->`, levels)
|
|
463
585
|
isLevel = false;
|
|
464
586
|
}
|
|
465
587
|
else {
|
|
@@ -498,8 +620,10 @@ class CSS {
|
|
|
498
620
|
if (key in self.PROPS) {
|
|
499
621
|
const _out = self.makeValue(key, _val);
|
|
500
622
|
const _id = self.makeID(key, _val + pseudo, _out);
|
|
623
|
+
// console.log(`props`, _k, _id)
|
|
501
624
|
if (pseudo == ``)
|
|
502
625
|
self.cx.push(_id);
|
|
626
|
+
// console.log(`_build`, key, _val, _id, _out)
|
|
503
627
|
if (_mediaQuery) {
|
|
504
628
|
self.mediaQueries[_mediaQuery].push({ [_id]: _out });
|
|
505
629
|
return {};
|
|
@@ -511,6 +635,9 @@ class CSS {
|
|
|
511
635
|
const important = hasImportant ? ` !important` : ``;
|
|
512
636
|
let val = hasImportant ? _val.slice(0, -1) : _val;
|
|
513
637
|
var _out = ``;
|
|
638
|
+
// if ( key == `ratio` ){
|
|
639
|
+
// console.log(`RatioFound`, key, val)
|
|
640
|
+
// }
|
|
514
641
|
if (key == `extend`) {
|
|
515
642
|
val = val.split(`,`).reduce((acc, v) => {
|
|
516
643
|
acc.push(`${v.startsWith(`.`) ? `` : `.`}${v.trim()}`);
|
|
@@ -530,6 +657,8 @@ class CSS {
|
|
|
530
657
|
const [_duration, ..._rest] = val.split(`,`);
|
|
531
658
|
let rest = _rest.join(",").trim();
|
|
532
659
|
duration = _duration;
|
|
660
|
+
// if ( rest.includes(`],`) ){
|
|
661
|
+
// }
|
|
533
662
|
if (rest.includes(`[`) && rest.includes(`]`)) {
|
|
534
663
|
for (const curv in cssAnimationCurves) {
|
|
535
664
|
if (rest.startsWith(curv)) {
|
|
@@ -546,11 +675,14 @@ class CSS {
|
|
|
546
675
|
_out = _out.replace(`;`, `${important};`);
|
|
547
676
|
}
|
|
548
677
|
else {
|
|
678
|
+
// const __value = `${val}${key == `extend` ? `` : self.makeUnit(key, val)}`
|
|
549
679
|
const __value = `${val}${self.IGNORE.includes(key) ? `` : self.makeUnit(key, val)}`;
|
|
550
680
|
_out = self.DIRECT[key].includes(`__VALUE__`) ?
|
|
551
681
|
self.DIRECT[key].replace(/__VALUE__/g, __value).replace(`;`, `${important};`) : self.DIRECT[key];
|
|
552
682
|
}
|
|
683
|
+
// console.log(`_build`, key, _val)
|
|
553
684
|
const _id = self.makeID(key, key + pseudo, _out);
|
|
685
|
+
// console.log(`_buildid`, key, _id)
|
|
554
686
|
if (pseudo == ``)
|
|
555
687
|
self.cx.push(_id);
|
|
556
688
|
if (_mediaQuery) {
|
|
@@ -563,6 +695,7 @@ class CSS {
|
|
|
563
695
|
else if (_k in self.DIRECT) {
|
|
564
696
|
const _out = self.DIRECT[_k];
|
|
565
697
|
const _id = self.makeID(_k, _k + pseudo, _out);
|
|
698
|
+
// console.log(_k, _id)
|
|
566
699
|
if (pseudo == ``)
|
|
567
700
|
self.cx.push(_id);
|
|
568
701
|
if (_mediaQuery) {
|
|
@@ -573,6 +706,7 @@ class CSS {
|
|
|
573
706
|
}
|
|
574
707
|
else if (_k.trim().match(/^[a-zA-Z0-9\-]+$/g)) {
|
|
575
708
|
self.cx.push(_k.trim());
|
|
709
|
+
// self.cx.push(`--${_k.trim()}`)
|
|
576
710
|
}
|
|
577
711
|
return {};
|
|
578
712
|
};
|
|
@@ -589,15 +723,18 @@ class CSS {
|
|
|
589
723
|
return out;
|
|
590
724
|
};
|
|
591
725
|
const _built = build(self.lexer(line));
|
|
726
|
+
// console.log(line, _built)
|
|
727
|
+
// console.log(line, self.lexer(line))
|
|
592
728
|
self.cache = { ...self.cache, ..._built };
|
|
593
729
|
}
|
|
594
730
|
}
|
|
595
|
-
Build(css, cli = false) {
|
|
731
|
+
Build(css, cli = false, ff = ``) {
|
|
596
732
|
let self = this;
|
|
597
733
|
self._cli = cli;
|
|
598
734
|
self.cx = [];
|
|
599
735
|
self.cache = {};
|
|
600
736
|
self._mediaQueries = {};
|
|
737
|
+
self._currentFile = ff;
|
|
601
738
|
if (undefined == css)
|
|
602
739
|
return {
|
|
603
740
|
cx: self.cx,
|
|
@@ -612,13 +749,31 @@ class CSS {
|
|
|
612
749
|
self.processLine(line);
|
|
613
750
|
});
|
|
614
751
|
});
|
|
752
|
+
// console.log(self.deepClean(self.cache))
|
|
753
|
+
// const _ = cli ? {
|
|
754
|
+
// cx: [],
|
|
755
|
+
// sheet: self.styleSheet(self.deepClean(self.cache))
|
|
756
|
+
// } : {
|
|
757
|
+
// cx: self.cx,
|
|
758
|
+
// sheet: ``
|
|
759
|
+
// }
|
|
615
760
|
const _cleaned = self.deepClean(self.cache);
|
|
616
761
|
const _stylesheet = self.styleSheet(_cleaned);
|
|
762
|
+
// const _mediaQueries : dynamicObject = {}
|
|
763
|
+
// if ( !cli ){
|
|
764
|
+
// console.log(css, self.cx, self.styleSheet(_cleaned))
|
|
765
|
+
// }
|
|
766
|
+
// console.log(`[${cli}]`, self.cx)
|
|
767
|
+
// console.log(`[${cli}]`, self.cache)
|
|
768
|
+
// console.log(`[${cli}]`, _cleaned)
|
|
769
|
+
// console.log(_stylesheet)
|
|
770
|
+
// console.log(self._mediaQueries)
|
|
617
771
|
const _ = {
|
|
618
772
|
cx: self.cx,
|
|
619
773
|
sheet: _stylesheet,
|
|
620
774
|
mediaQuery: self._mediaQueries
|
|
621
775
|
};
|
|
776
|
+
// console.log(css, _)
|
|
622
777
|
return _;
|
|
623
778
|
}
|
|
624
779
|
}
|
|
@@ -647,6 +802,7 @@ export const buildWithStyles = (source) => {
|
|
|
647
802
|
if (_transform.length > 0) {
|
|
648
803
|
_.transform = _transform.join(` `);
|
|
649
804
|
}
|
|
805
|
+
// console.log(_, _transform)
|
|
650
806
|
}
|
|
651
807
|
return _;
|
|
652
808
|
};
|
|
@@ -654,11 +810,23 @@ export const getAnimationCurve = (curve) => {
|
|
|
654
810
|
if (!curve)
|
|
655
811
|
return `linear`;
|
|
656
812
|
switch (curve.toUpperCase()) {
|
|
813
|
+
case TRANSITION_CURVES.Bounce:
|
|
814
|
+
return `var(--bounce)`;
|
|
815
|
+
// return `linear( 0, 0.0039, 0.0157, 0.0352, 0.0625 9.09%,
|
|
816
|
+
// 0.1407, 0.25, 0.3908, 0.5625, 0.7654,
|
|
817
|
+
// 1, 0.8907, 0.8125 45.45%, 0.7852, 0.7657,
|
|
818
|
+
// 0.7539, 0.75, 0.7539, 0.7657, 0.7852,
|
|
819
|
+
// 0.8125 63.64%, 0.8905, 1 72.73%, 0.9727, 0.9532,
|
|
820
|
+
// 0.9414, 0.9375, 0.9414, 0.9531, 0.9726,
|
|
821
|
+
// 1, 0.9883, 0.9844, 0.9883, 1 )`
|
|
822
|
+
break;
|
|
657
823
|
case TRANSITION_CURVES.Spring:
|
|
658
|
-
return `cubic-bezier(0.2, -0.36, 0, 1.46)
|
|
824
|
+
// return `cubic-bezier(0.2, -0.36, 0, 1.46)`
|
|
825
|
+
return `var(--spring)`;
|
|
659
826
|
break;
|
|
660
827
|
case TRANSITION_CURVES.EaseInOut:
|
|
661
|
-
return `cubic-bezier(0.42, 0, 0.58, 1)
|
|
828
|
+
// return `cubic-bezier(0.42, 0, 0.58, 1)`
|
|
829
|
+
return `ease-in-out`;
|
|
662
830
|
break;
|
|
663
831
|
default:
|
|
664
832
|
return `linear`;
|
package/dist/funs/events.js
CHANGED
|
@@ -4,6 +4,7 @@ class Events {
|
|
|
4
4
|
this._events = [];
|
|
5
5
|
}
|
|
6
6
|
addEvent(event, fun, context) {
|
|
7
|
+
// console.log(`addEvent`, context)
|
|
7
8
|
const evt = this._events.find(x => x.event == event);
|
|
8
9
|
if (!evt) {
|
|
9
10
|
return this._events.push({ event: event, listeners: [fun], context });
|
|
@@ -27,8 +28,10 @@ class Events {
|
|
|
27
28
|
emit(event, ...args) {
|
|
28
29
|
const evt = this._events.find(x => x.event == event);
|
|
29
30
|
if (evt) {
|
|
31
|
+
// console.log(evt)
|
|
30
32
|
evt.listeners.forEach((f) => {
|
|
31
33
|
try {
|
|
34
|
+
// f(args)
|
|
32
35
|
f.apply(evt.context || self, args);
|
|
33
36
|
}
|
|
34
37
|
catch (e) {
|
package/dist/funs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import CSS from './css.js';
|
|
2
2
|
import { dynamicObject, sortOptions } from "../types/index.js";
|
|
3
3
|
import { FormatNumberParams } from "../types/interfaces.js";
|
|
4
|
+
import { KeyCode } from "../types/enums.js";
|
|
4
5
|
export declare const __SALT: string;
|
|
5
6
|
export declare const FIELNAME_KEY = "__FILENAME__";
|
|
6
7
|
export declare const LINE_KEY = "__LINE__";
|
|
@@ -41,4 +42,9 @@ export declare const arrayRand: (arr: any[]) => any;
|
|
|
41
42
|
export declare const formatNumber: ({ number, locale, style, decimal, currency }: FormatNumberParams) => string;
|
|
42
43
|
export declare const formatSize: (bytes: number | string) => string;
|
|
43
44
|
export declare const copyToClipboard: (text: string) => Promise<unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* Borrowed from https://github.com/bubkoo/natsort
|
|
47
|
+
* So we don't have to install a package for this
|
|
48
|
+
*/
|
|
44
49
|
export declare const natsort: (options?: sortOptions) => (a: string | number, b: string | number) => number;
|
|
50
|
+
export declare const bindKey: (key: KeyCode, fun: () => void, element?: HTMLElement) => void;
|
package/dist/funs/index.js
CHANGED
|
@@ -19,12 +19,17 @@ export const numberInRange = (min, max) => {
|
|
|
19
19
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
20
20
|
};
|
|
21
21
|
export const toLowerCase = String.prototype.toLocaleLowerCase || String.prototype.toLowerCase;
|
|
22
|
+
// Hex color regex (#RGB, #RRGGBB)
|
|
22
23
|
export const hexColorRegex = /^#([A-Fa-f0-9]{3}){1,2}$/;
|
|
24
|
+
// export const hexColorRegex3 = /^#([A-Fa-f0-9]{3}){1,2}$/;
|
|
25
|
+
// RGBA color regex (rgba(255, 255, 255, 1))
|
|
23
26
|
export const rgbaColorRegex = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*((0|1|0?\.\d+)\s*))?\)$/;
|
|
27
|
+
// HSL color regex (hsl(360, 100%, 100%))
|
|
24
28
|
export const hslColorRegex = /^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/;
|
|
25
29
|
export const isHexColor = (color) => hexColorRegex.test(color);
|
|
26
30
|
export const isRgbaColor = (color) => rgbaColorRegex.test(color);
|
|
27
31
|
export const isHslColor = (color) => hslColorRegex.test(color);
|
|
32
|
+
// Function to validate a color string
|
|
28
33
|
export const isColor = (color) => colorNames.includes(color) || isHexColor(color) || isRgbaColor(color) || isHslColor(color);
|
|
29
34
|
export const isUrl = (u) => {
|
|
30
35
|
let url;
|
|
@@ -41,11 +46,15 @@ export const isIPv4 = (ipaddress) => {
|
|
|
41
46
|
return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress);
|
|
42
47
|
};
|
|
43
48
|
export const isNumber = (v) => /\d+(\.\d+)?$/g.test(v);
|
|
49
|
+
// Convert hex to rgba
|
|
44
50
|
export const hexToRgba = (hex, alpha = 1) => {
|
|
51
|
+
// Remove the hash symbol if present
|
|
45
52
|
hex = hex.replace(/^#/, '');
|
|
53
|
+
// If shorthand hex (#RGB), expand it to full form (#RRGGBB)
|
|
46
54
|
if (hex.length === 3) {
|
|
47
55
|
hex = hex.split('').map(char => char + char).join('');
|
|
48
56
|
}
|
|
57
|
+
// Convert to integer values for RGB
|
|
49
58
|
const bigint = parseInt(hex, 16);
|
|
50
59
|
const r = (bigint >> 16) & 255;
|
|
51
60
|
const g = (bigint >> 8) & 255;
|
|
@@ -67,6 +76,10 @@ export const cleanProps = (props, withProps = []) => {
|
|
|
67
76
|
_extras.map(x => x in _props && delete _props[x]);
|
|
68
77
|
return _props;
|
|
69
78
|
};
|
|
79
|
+
// export const withZuz = (cx : string | string[]) : string => {
|
|
80
|
+
// console.log(cx)
|
|
81
|
+
// return ``
|
|
82
|
+
// }
|
|
70
83
|
export const withZuz = (cx) => css().Build([[`string` == typeof cx ? cx : cx.join(` `)]]).cx.join(` `);
|
|
71
84
|
export const setDeep = (object, path, value, seperator = `.`) => {
|
|
72
85
|
const _path = path.split(seperator);
|
|
@@ -77,6 +90,7 @@ export const setDeep = (object, path, value, seperator = `.`) => {
|
|
|
77
90
|
if (!object.hasOwnProperty(base)) {
|
|
78
91
|
object[base] = {};
|
|
79
92
|
}
|
|
93
|
+
// Determine if there is still layers to traverse
|
|
80
94
|
value = _path.length <= 1 ? value : setDeep(object[base], _path.slice(1).join(seperator), value, seperator);
|
|
81
95
|
return {
|
|
82
96
|
...object,
|
|
@@ -213,7 +227,7 @@ export const copyToClipboard = (text) => {
|
|
|
213
227
|
return new Promise((resolve, reject) => {
|
|
214
228
|
const textarea = document.createElement("textarea");
|
|
215
229
|
textarea.value = text;
|
|
216
|
-
textarea.style.position = "fixed";
|
|
230
|
+
textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
|
|
217
231
|
document.body.appendChild(textarea);
|
|
218
232
|
textarea.focus();
|
|
219
233
|
textarea.select();
|
|
@@ -222,12 +236,17 @@ export const copyToClipboard = (text) => {
|
|
|
222
236
|
resolve(`Copied to clipboard`);
|
|
223
237
|
}
|
|
224
238
|
catch (err) {
|
|
239
|
+
// console.error("Fallback: Oops, unable to copy", err);
|
|
225
240
|
reject(err);
|
|
226
241
|
}
|
|
227
242
|
document.body.removeChild(textarea);
|
|
228
243
|
});
|
|
229
244
|
}
|
|
230
245
|
};
|
|
246
|
+
/**
|
|
247
|
+
* Borrowed from https://github.com/bubkoo/natsort
|
|
248
|
+
* So we don't have to install a package for this
|
|
249
|
+
*/
|
|
231
250
|
export const natsort = (options = {
|
|
232
251
|
direction: SORT.Asc,
|
|
233
252
|
caseSensitive: false,
|
|
@@ -235,10 +254,14 @@ export const natsort = (options = {
|
|
|
235
254
|
const ore = /^0/;
|
|
236
255
|
const sre = /\s+/g;
|
|
237
256
|
const tre = /^\s+|\s+$/g;
|
|
257
|
+
// unicode
|
|
238
258
|
const ure = /[^\x00-\x80]/;
|
|
259
|
+
// hex
|
|
239
260
|
const hre = /^0x[0-9a-f]+$/i;
|
|
261
|
+
// numeric
|
|
240
262
|
const nre = /(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g;
|
|
241
|
-
|
|
263
|
+
// datetime
|
|
264
|
+
const dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/; // tslint:disable-line
|
|
242
265
|
const GREATER = options.direction == SORT.Desc ? -1 : 1;
|
|
243
266
|
const SMALLER = -GREATER;
|
|
244
267
|
const _normalize = !options.caseSensitive
|
|
@@ -270,12 +293,14 @@ export const natsort = (options = {
|
|
|
270
293
|
}
|
|
271
294
|
const aArr = _tokenize(aa);
|
|
272
295
|
const bArr = _tokenize(bb);
|
|
296
|
+
// hex or date detection
|
|
273
297
|
const aHex = aa.match(hre);
|
|
274
298
|
const bHex = bb.match(hre);
|
|
275
299
|
const av = (aHex && bHex) ? parseInt(aHex[0], 16) : (aArr.length !== 1 && Date.parse(aa));
|
|
276
300
|
const bv = (aHex && bHex)
|
|
277
301
|
? parseInt(bHex[0], 16)
|
|
278
302
|
: av && bb.match(dre) && Date.parse(bb) || null;
|
|
303
|
+
// try and sort Hex codes or Dates
|
|
279
304
|
if (bv) {
|
|
280
305
|
if (av === bv) {
|
|
281
306
|
return 0;
|
|
@@ -289,6 +314,7 @@ export const natsort = (options = {
|
|
|
289
314
|
}
|
|
290
315
|
const al = aArr.length;
|
|
291
316
|
const bl = bArr.length;
|
|
317
|
+
// handle numeric strings and default strings
|
|
292
318
|
for (let i = 0, l = Math.max(al, bl); i < l; i += 1) {
|
|
293
319
|
const af = _parse(aArr[i] || '', al);
|
|
294
320
|
const bf = _parse(bArr[i] || '', bl);
|
|
@@ -323,3 +349,11 @@ export const natsort = (options = {
|
|
|
323
349
|
return 0;
|
|
324
350
|
};
|
|
325
351
|
};
|
|
352
|
+
export const bindKey = (key, fun, element) => {
|
|
353
|
+
const handleKeydown = (event) => {
|
|
354
|
+
if (key === event.keyCode) {
|
|
355
|
+
fun();
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
(element || document.documentElement).addEventListener('keydown', handleKeydown);
|
|
359
|
+
};
|