@zuzjs/ui 0.3.7 → 0.3.9
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.d.ts +2 -0
- package/dist/bin.js +107 -0
- package/dist/comps/base.d.ts +10 -0
- package/dist/comps/base.js +12 -0
- package/dist/comps/box.d.ts +4 -0
- package/dist/comps/box.js +15 -0
- package/dist/comps/button.d.ts +4 -0
- package/dist/comps/button.js +19 -0
- package/dist/comps/checkbox.d.ts +4 -0
- package/dist/comps/checkbox.js +28 -0
- package/dist/comps/cover.d.ts +11 -0
- package/dist/comps/cover.js +36 -0
- package/dist/comps/form.d.ts +18 -0
- package/dist/comps/form.js +287 -0
- package/dist/comps/heading.d.ts +7 -0
- package/dist/comps/heading.js +21 -0
- package/dist/comps/icon.d.ts +5 -0
- package/dist/comps/icon.js +18 -0
- package/dist/comps/input.d.ts +6 -0
- package/dist/comps/input.js +23 -0
- package/dist/comps/sheet.d.ts +13 -0
- package/dist/comps/sheet.js +102 -0
- package/dist/comps/spinner.d.ts +14 -0
- package/dist/comps/spinner.js +42 -0
- package/dist/funs/colors.d.ts +7 -0
- package/dist/funs/colors.js +9 -0
- package/dist/funs/css.d.ts +269 -0
- package/dist/funs/css.js +413 -0
- package/dist/funs/index.d.ts +20 -0
- package/dist/funs/index.js +125 -0
- package/dist/funs/stylesheet.d.ts +242 -0
- package/dist/funs/stylesheet.js +249 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/styles.css +1 -460
- package/dist/types/enums.d.ts +19 -0
- package/dist/types/enums.js +23 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/index.js +1 -0
- package/dist/types/interfaces.d.ts +4 -0
- package/dist/types/interfaces.js +1 -0
- package/package.json +50 -44
- package/README.md +0 -1
- package/dist/hooks.js +0 -89
- package/dist/ui.js +0 -688
package/dist/funs/css.js
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import Hashids from "hashids";
|
|
2
|
+
import { cssProps } from "./stylesheet.js";
|
|
3
|
+
import { isColor, isHexColor, isNumber } from "./index.js";
|
|
4
|
+
class CSS {
|
|
5
|
+
unit;
|
|
6
|
+
PROPS;
|
|
7
|
+
DIRECT;
|
|
8
|
+
IGNORE;
|
|
9
|
+
chars;
|
|
10
|
+
hashids;
|
|
11
|
+
cx;
|
|
12
|
+
cache;
|
|
13
|
+
pseudoRegExp;
|
|
14
|
+
// pseudoPattern: string;
|
|
15
|
+
pseudoList;
|
|
16
|
+
baseRegex;
|
|
17
|
+
pseudoCounter;
|
|
18
|
+
pseudoPattern;
|
|
19
|
+
pseudoReg;
|
|
20
|
+
propCounter;
|
|
21
|
+
keysWithoutCommaToSpace;
|
|
22
|
+
rgbaRegex;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
const opts = options || {};
|
|
25
|
+
this.unit = opts.unit || `px`;
|
|
26
|
+
this.hashids = new Hashids('', 4);
|
|
27
|
+
this.chars = "#abcdefghijklmnopqrstuvwxyz0123456789";
|
|
28
|
+
this.PROPS = cssProps;
|
|
29
|
+
this.IGNORE = [
|
|
30
|
+
`flex`, `opacity`, `z-index`, `zIndex`, `color`, `line-height`, `anim`
|
|
31
|
+
];
|
|
32
|
+
this.DIRECT = {
|
|
33
|
+
"content": "content:'';",
|
|
34
|
+
"bold": "font-weight: bold;",
|
|
35
|
+
"flex": "display:flex;",
|
|
36
|
+
"cols": "flex-direction:column;",
|
|
37
|
+
"ass": "align-self:flex-start;",
|
|
38
|
+
"ais": "align-items:flex-start;",
|
|
39
|
+
"aic": "align-items:center;",
|
|
40
|
+
"aie": "align-items:flex-end;",
|
|
41
|
+
"jcs": "justify-content:flex-start;",
|
|
42
|
+
"jcc": "justify-content:center;",
|
|
43
|
+
"jce": "justify-content:flex-end;",
|
|
44
|
+
"tal": "text-align: left;",
|
|
45
|
+
"tac": "text-align: center;",
|
|
46
|
+
"tar": "text-align: right;",
|
|
47
|
+
"tas": "text-align: justify;",
|
|
48
|
+
"fill": "top: 0px;left: 0px;right: 0px;bottom: 0px;",
|
|
49
|
+
"rel": "position:relative;",
|
|
50
|
+
"abs": "position:absolute;",
|
|
51
|
+
"fixed": "position:fixed;",
|
|
52
|
+
"abc": "top: 50%;left: 50%;transform: translate(-50%, -50%);",
|
|
53
|
+
"tdn": "text-decoration:none;",
|
|
54
|
+
"tdu": "text-decoration:underline;",
|
|
55
|
+
"nous": "user-select:none;",
|
|
56
|
+
"nope": "pointer-events:none;",
|
|
57
|
+
"ph": "padding-left:__VALUE__;padding-right:__VALUE__;",
|
|
58
|
+
"pv": "padding-top:__VALUE__;padding-bottom:__VALUE__;",
|
|
59
|
+
"mh": "margin-left:__VALUE__;margin-right:__VALUE__;",
|
|
60
|
+
"mv": "margin-top:__VALUE__;margin-bottom:__VALUE__;",
|
|
61
|
+
"translate": "transform:translate(__VALUE__);",
|
|
62
|
+
"translateX": "transform:translateX(__VALUE__);",
|
|
63
|
+
"translateY": "transform:translateY(__VALUE__);",
|
|
64
|
+
"rotate": "transform: rotate(__VALUE__);",
|
|
65
|
+
"anim": "transition: all __VALUE__ linear 0s;",
|
|
66
|
+
};
|
|
67
|
+
this.keysWithoutCommaToSpace = [
|
|
68
|
+
`transform`, `translate`, `color`, `background`, `background-color`, `backgroundColor`,
|
|
69
|
+
`border`, `border-bottom`, `border-top`, `border-left`, `border-right`
|
|
70
|
+
];
|
|
71
|
+
this.propCounter = {};
|
|
72
|
+
this.cx = [];
|
|
73
|
+
this.cache = {};
|
|
74
|
+
// 1. this.baseRegex = /(\$?[\w%!-]+:\$?[\w%!-]+(?:,[-\w%!.]+)*)|(\$?[\w%!-]+:\$?[-\w%,.!]+)/g;
|
|
75
|
+
// 2. this.baseRegex = /(\$?[\w%!-]+:\$?\w+\[(.*?)\]+)|(\$?[\w%!-]+:\$?[-\w%,.!]+|\$?[-\w%,.!]+)/g;
|
|
76
|
+
this.baseRegex = /(\$?[\w%!-]+:\$?[\w%!-]+(?:\[[^\]]*\])?(?:,[^\s,]+)*)|(\$?[\w%!-]+:\$?[-\w%,.!]+|\$?[-\w%,.!]+)/g;
|
|
77
|
+
this.rgbaRegex = /\b\w+\[\d+,\d+,\d+(?:,\d+)?\]/g;
|
|
78
|
+
this.pseudoList = [`hover`, `before`, `after`, `focus`, `blur`];
|
|
79
|
+
this.pseudoCounter = {};
|
|
80
|
+
this.pseudoList.map((p) => this.pseudoCounter[p] = 0);
|
|
81
|
+
this.pseudoPattern = this.pseudoList.map((word) => word).join('|');
|
|
82
|
+
this.pseudoReg = new RegExp(this.pseudoPattern, `g`);
|
|
83
|
+
this.pseudoRegExp = /&(\w+)\(\s*([^()]*?(?:\([^()]*\))*[^()]*)\s*\)/g;
|
|
84
|
+
// /&(\w+)\(([^()]+(?:\([^()]*\))*[^()]*)\)/g
|
|
85
|
+
}
|
|
86
|
+
getStyleSheet(cache, indentLevel = 0, pseudo = false) {
|
|
87
|
+
const self = this;
|
|
88
|
+
const indent = ``; //` `.repeat(indentLevel)
|
|
89
|
+
let scss = ``;
|
|
90
|
+
// for( const key in cache){
|
|
91
|
+
Object.keys(cache).map((key) => {
|
|
92
|
+
// console.log(`kc`, key, cache[key])
|
|
93
|
+
if (`object` == typeof cache[key]) {
|
|
94
|
+
const _key = self.pseudoList.filter(x => key.indexOf(x) > -1);
|
|
95
|
+
scss += `${indent}${_key.length > 0 ? `&:${_key[0]}` : `\n.${key}`}{`;
|
|
96
|
+
scss += self.getStyleSheet(cache[key], indentLevel + 1, _key.length > 0 ? true : false);
|
|
97
|
+
scss += `${indent}}`;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
if (pseudo) {
|
|
101
|
+
scss += `${indent}${cache[key]}`;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
scss += `\n${indent}.${key}{`;
|
|
105
|
+
scss += `${indent}${cache[key]}`;
|
|
106
|
+
scss += `${indent}}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return scss;
|
|
111
|
+
}
|
|
112
|
+
makeColor() {
|
|
113
|
+
}
|
|
114
|
+
makeUnit(k, v) {
|
|
115
|
+
// console.log(`unit`, k, v)
|
|
116
|
+
if (k == `rotate`) {
|
|
117
|
+
return `deg`;
|
|
118
|
+
}
|
|
119
|
+
if (typeof v == "string" && !isNumber(v) || this.IGNORE.indexOf(k) > -1)
|
|
120
|
+
return ``;
|
|
121
|
+
return this.unit;
|
|
122
|
+
}
|
|
123
|
+
makeValue(k, v) {
|
|
124
|
+
if (k in this.PROPS) {
|
|
125
|
+
const key = this.PROPS[k];
|
|
126
|
+
let value;
|
|
127
|
+
v = v.trim().replace(`\``, ``);
|
|
128
|
+
let hasImportant = v.charAt(v.length - 1) == `!`;
|
|
129
|
+
v = hasImportant ? v.slice(0, -1) : v;
|
|
130
|
+
let important = hasImportant ? ` !important` : ``;
|
|
131
|
+
// if ( key.includes(`border`)) console.log(`makevalue`, key, k, v)
|
|
132
|
+
/**
|
|
133
|
+
* Variable
|
|
134
|
+
*/
|
|
135
|
+
if (v.charAt(0) == `$`) {
|
|
136
|
+
value = `var(--${v.replace(`$`, ``)})`;
|
|
137
|
+
}
|
|
138
|
+
else if (v.trim() == `transparent`) {
|
|
139
|
+
value = `rgba(0,0,0,0)`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* border
|
|
143
|
+
*/
|
|
144
|
+
else if ([`border`, `borderBottom`, `borderTop`, `borderLeft`, `borderRight`].includes(k)) {
|
|
145
|
+
const _parts = [];
|
|
146
|
+
// console.log(`--border`, key, v)
|
|
147
|
+
if (v.match(this.rgbaRegex)) {
|
|
148
|
+
_parts.push(v.match(this.rgbaRegex)[0].replace(`[`, `(`).replace(`]`, `)`));
|
|
149
|
+
v = v.replace(this.rgbaRegex, ``).trim().replace(`,,`, `,`);
|
|
150
|
+
}
|
|
151
|
+
// console.log(`-border`, key, v, _parts)
|
|
152
|
+
v.split(`,`).map((p) => {
|
|
153
|
+
if (p.includes(`rgb`) || p.includes(`rgba`) || isColor(`#${p}`) || p.startsWith(`$`)) {
|
|
154
|
+
if (p.includes(`rgb`) || p.includes(`rgba`)) {
|
|
155
|
+
_parts.push(p.replace(`[`, `(`).replace(`]`, `)`));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
if (p.charAt(0) == `#`) {
|
|
159
|
+
p = p.substring(1);
|
|
160
|
+
}
|
|
161
|
+
_parts.push(isHexColor(`#${p}`) ? `#${p}`
|
|
162
|
+
: p.startsWith(`$`) ? `var(--${p.replace(`$`, ``)})` : p);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (isNumber(p)) {
|
|
166
|
+
_parts.push(`${p}${this.makeUnit(`border`, p)}`);
|
|
167
|
+
}
|
|
168
|
+
else if (['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'].includes(p)) {
|
|
169
|
+
_parts.push(p);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
value = _parts.join(` `);
|
|
173
|
+
// console.log(`border`, value)
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Color
|
|
177
|
+
*/
|
|
178
|
+
else if ([`color`, `bg`, `background`, `background-color`, `backgroundColor`].includes(key)) {
|
|
179
|
+
// else if ( [`color`].includes( key ) ){
|
|
180
|
+
if (v.charAt(0) == `#`) {
|
|
181
|
+
v = v.substring(1);
|
|
182
|
+
}
|
|
183
|
+
if (/^#[0-9A-F]{6}[0-9a-f]{0,2}$/i.test(`#${v}`) ||
|
|
184
|
+
/^#([0-9A-F]{3}){1,2}$/i.test(`#${v}`)) {
|
|
185
|
+
value = `#${v}`;
|
|
186
|
+
}
|
|
187
|
+
else if (v.includes(`rgb`) || v.includes(`rgba`)) {
|
|
188
|
+
value = v.replace(`[`, `(`).replace(`]`, `)`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* FontWeight
|
|
193
|
+
*/
|
|
194
|
+
else if (key == `font-weight`) {
|
|
195
|
+
value = v;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* calc
|
|
199
|
+
* passed as calc[value]
|
|
200
|
+
*/
|
|
201
|
+
else if (v.match(/\[(.*?)\]/g)) {
|
|
202
|
+
try {
|
|
203
|
+
const vs = v.match(/\[(.*?)\]/g)[0].slice(1, -1);
|
|
204
|
+
const [_vc] = v.split(`[`);
|
|
205
|
+
value = `${_vc.trim()}(${vs})`;
|
|
206
|
+
}
|
|
207
|
+
catch (e) { }
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
// ${v.charAt(0) == `$` ? `var(--${v.substring(1)})` : v}
|
|
211
|
+
value = `${v}${this.makeUnit(key, v)}`;
|
|
212
|
+
}
|
|
213
|
+
if (!value)
|
|
214
|
+
return ``;
|
|
215
|
+
// if ( key == `background` ) console.log(`makevalue`, key, value)
|
|
216
|
+
// if ( key.includes(`border`) ) console.log(`--border`, `${key}: ${value}${important};`)
|
|
217
|
+
value = value.includes(`,`) && !this.keysWithoutCommaToSpace.includes(key) ? value.replace(`,`, ` `) : value;
|
|
218
|
+
// if ( key.includes(`border`) ) console.log(`->border`, `${key}: ${value}${important};`)
|
|
219
|
+
return `${key}: ${value}${important};`;
|
|
220
|
+
}
|
|
221
|
+
return ``;
|
|
222
|
+
}
|
|
223
|
+
makeID(k, v, _out) {
|
|
224
|
+
const self = this;
|
|
225
|
+
const _css = _out.toString().replace(/;|:|\s/g, "");
|
|
226
|
+
let _indices = 0;
|
|
227
|
+
for (let i = 0; i < _css.length; i++) {
|
|
228
|
+
_indices += self.chars.indexOf(_out.charAt(i));
|
|
229
|
+
}
|
|
230
|
+
let _cp = k.substring(0, 1);
|
|
231
|
+
if (self.PROPS[k]?.indexOf("-") > -1) {
|
|
232
|
+
_cp = "";
|
|
233
|
+
self.PROPS[k].split("-").map((c) => _cp += c.substring(0, 1));
|
|
234
|
+
}
|
|
235
|
+
if (v.toString().indexOf("-") > -1) {
|
|
236
|
+
v.toString().split("-").map(c => _cp += c.substring(0, 1));
|
|
237
|
+
}
|
|
238
|
+
return `${_cp}${self.hashids.encode((self.PROPS[k] ? self.PROPS[k].length : 0) + _indices + (isNaN(parseInt(v)) ? 0 : parseInt(v)))}`.replace(/\s|\$/g, '-');
|
|
239
|
+
}
|
|
240
|
+
makeIDFromObject(key, obj) {
|
|
241
|
+
const self = this;
|
|
242
|
+
const out = [key];
|
|
243
|
+
const fcs = [key.charAt(0)];
|
|
244
|
+
const vals = [];
|
|
245
|
+
const build = (o) => {
|
|
246
|
+
Object.keys(o).map((n) => {
|
|
247
|
+
if (`object` == typeof o[n]) {
|
|
248
|
+
build(o[n]);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
fcs.push(n.charAt(0));
|
|
252
|
+
vals.push(o[n]);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
build(obj);
|
|
257
|
+
let _indices = 0;
|
|
258
|
+
let _cp = "";
|
|
259
|
+
for (const ot of vals) {
|
|
260
|
+
const _css = ot.toString().replace(/;|:|\s/g, "");
|
|
261
|
+
for (let i = 0; i < _css.length; i++) {
|
|
262
|
+
_indices += self.chars.indexOf(ot.charAt(i));
|
|
263
|
+
}
|
|
264
|
+
if (ot.indexOf("-") > -1) {
|
|
265
|
+
ot.split("-").map((c) => _cp += c.substring(0, 1));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return `${_cp}${self.hashids.encode(_indices)}`.replace(/\s/g, '-');
|
|
269
|
+
}
|
|
270
|
+
parseRawLine(line) {
|
|
271
|
+
const self = this;
|
|
272
|
+
const result = {};
|
|
273
|
+
try {
|
|
274
|
+
const matches = line.match(self.pseudoRegExp);
|
|
275
|
+
if (matches) {
|
|
276
|
+
matches.map((m) => {
|
|
277
|
+
const pseudo = self.pseudoRegExp.exec(m); ///&\w+/g.exec(m)
|
|
278
|
+
if (pseudo) {
|
|
279
|
+
const psd = `${pseudo[1]}${++self.pseudoCounter[pseudo[1]]}`;
|
|
280
|
+
result[psd] = self.parseRawLine(pseudo[2]);
|
|
281
|
+
}
|
|
282
|
+
line = line.replace(self.pseudoRegExp, ``);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
// line = line.charAt(0) == `\`` ? line.substring(1) : line
|
|
286
|
+
// line = line.charAt(line.length - 1) == `\`` ? line.substring(0,) : line
|
|
287
|
+
const baseProperties = line.match(self.baseRegex);
|
|
288
|
+
if (baseProperties) {
|
|
289
|
+
// console.log(line, baseProperties)
|
|
290
|
+
baseProperties.forEach(prop => {
|
|
291
|
+
const [key, value] = prop.split(':');
|
|
292
|
+
// if ( line.includes(`borderBottom`) )
|
|
293
|
+
// console.log(key, value)
|
|
294
|
+
if (value) {
|
|
295
|
+
if (result[key]) {
|
|
296
|
+
const _kk = key in self.propCounter ? ++self.propCounter[key] : self.propCounter[key] = 1;
|
|
297
|
+
result[`${key}${_kk}`] = `${key}:${value}`;
|
|
298
|
+
}
|
|
299
|
+
else
|
|
300
|
+
result[key] = `${key}:${value}`;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const _kk = prop in self.propCounter ? ++self.propCounter[prop] : self.propCounter[prop] = 1;
|
|
304
|
+
result[`${prop}${_kk}`] = prop; // true;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
// console.log(e)
|
|
311
|
+
}
|
|
312
|
+
// console.log(result)
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
makeCSS(line) {
|
|
316
|
+
const self = this;
|
|
317
|
+
// console.log(line)
|
|
318
|
+
const rest = self.parseRawLine(line);
|
|
319
|
+
const value = (_k, pseudo = ``) => {
|
|
320
|
+
if (_k in self.DIRECT) {
|
|
321
|
+
const _out = self.DIRECT[_k];
|
|
322
|
+
const _id = self.makeID(_k, _k + pseudo, _out);
|
|
323
|
+
if (pseudo == ``)
|
|
324
|
+
self.cx.push(_id);
|
|
325
|
+
return { [_id]: _out };
|
|
326
|
+
}
|
|
327
|
+
else if (_k.includes(`:`)) {
|
|
328
|
+
const [key, _val] = _k.split(`:`);
|
|
329
|
+
if (key in self.PROPS) {
|
|
330
|
+
const _out = self.makeValue(key, _val);
|
|
331
|
+
const _id = self.makeID(key, _val + pseudo, _out);
|
|
332
|
+
if (pseudo == ``)
|
|
333
|
+
self.cx.push(_id);
|
|
334
|
+
return { [_id]: _out };
|
|
335
|
+
}
|
|
336
|
+
else if (key in self.DIRECT) {
|
|
337
|
+
const hasImportant = _val.endsWith(`!`);
|
|
338
|
+
const val = hasImportant ? _val.slice(0, -1) : _val;
|
|
339
|
+
const important = hasImportant ? ` !important` : ``;
|
|
340
|
+
const _out = self.DIRECT[key].includes(`__VALUE__`) ?
|
|
341
|
+
self.DIRECT[key].replace(/__VALUE__/g, `${val}${self.makeUnit(key, val)}${important}`) : self.DIRECT[key];
|
|
342
|
+
const _id = self.makeID(key, key + pseudo, _out);
|
|
343
|
+
if (pseudo == ``)
|
|
344
|
+
self.cx.push(_id);
|
|
345
|
+
return { [_id]: _out };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
self.cx.push(_k.trim());
|
|
350
|
+
}
|
|
351
|
+
return {};
|
|
352
|
+
};
|
|
353
|
+
const build = (o, pseudo = ``) => {
|
|
354
|
+
let out = {};
|
|
355
|
+
Object.keys(o).map((_k) => {
|
|
356
|
+
if (`object` == typeof o[_k]) {
|
|
357
|
+
out = { ...out, [_k]: build(o[_k], _k) };
|
|
358
|
+
// self.makeIDFromObject(_k, cache[_k])
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
out = { ...out, ...value(o[_k], pseudo) };
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
return out;
|
|
365
|
+
};
|
|
366
|
+
// console.log(rest)
|
|
367
|
+
self.cache = { ...self.cache, ...build(rest) };
|
|
368
|
+
}
|
|
369
|
+
cleanPseudo(cache) {
|
|
370
|
+
const self = this;
|
|
371
|
+
const _ = {};
|
|
372
|
+
Object.keys(cache).map((_k) => {
|
|
373
|
+
if (`object` == typeof cache[_k]) {
|
|
374
|
+
const _id = self.makeIDFromObject(_k, cache[_k]);
|
|
375
|
+
self.cx.push(_id);
|
|
376
|
+
_[_id] = { [_k]: cache[_k] };
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
_[_k] = cache[_k];
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
return _;
|
|
383
|
+
}
|
|
384
|
+
Build(css) {
|
|
385
|
+
let self = this;
|
|
386
|
+
self.cx = [];
|
|
387
|
+
self.cache = {};
|
|
388
|
+
if (undefined == css)
|
|
389
|
+
return {
|
|
390
|
+
cx: self.cx,
|
|
391
|
+
sheet: ``
|
|
392
|
+
};
|
|
393
|
+
if (`string` == typeof css) {
|
|
394
|
+
css = [[css]];
|
|
395
|
+
}
|
|
396
|
+
css.map((arr) => {
|
|
397
|
+
arr.map((line) => {
|
|
398
|
+
self.makeCSS(line);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
// console.log({
|
|
402
|
+
// cx: self.cx,
|
|
403
|
+
// sheet: self.getStyleSheet(self.cleanPseudo(self.cache))
|
|
404
|
+
// })
|
|
405
|
+
// console.log(self.cache)
|
|
406
|
+
// console.log(self.getStyleSheet(self.cleanPseudo(self.cache)))
|
|
407
|
+
return {
|
|
408
|
+
cx: self.cx,
|
|
409
|
+
sheet: self.getStyleSheet(self.cleanPseudo(self.cache))
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
export default CSS;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import CSS from './css.js';
|
|
2
|
+
import { dynamicObject } from "../types/index.js";
|
|
3
|
+
export { CSS as css };
|
|
4
|
+
export declare const hexColorRegex: RegExp;
|
|
5
|
+
export declare const rgbaColorRegex: RegExp;
|
|
6
|
+
export declare const hslColorRegex: RegExp;
|
|
7
|
+
export declare const isHexColor: (color: string) => boolean;
|
|
8
|
+
export declare const isRgbaColor: (color: string) => boolean;
|
|
9
|
+
export declare const isHslColor: (color: string) => boolean;
|
|
10
|
+
export declare const isColor: (color: string) => boolean;
|
|
11
|
+
export declare const isUrl: (u: string) => boolean;
|
|
12
|
+
export declare const isEmail: (e: string) => boolean;
|
|
13
|
+
export declare const isIPv4: (ipaddress: string) => boolean;
|
|
14
|
+
export declare const isNumber: (v: any) => boolean;
|
|
15
|
+
export declare const hexToRgba: (hex: string, alpha?: number) => string;
|
|
16
|
+
export declare const ucfirst: (str: string) => string;
|
|
17
|
+
export declare const cleanProps: <T extends dynamicObject>(props: T, withProps?: string[]) => T;
|
|
18
|
+
export declare const withZuz: (cx: string) => string;
|
|
19
|
+
export declare const extendGlobals: () => void;
|
|
20
|
+
export declare const withPost: (uri: string, data: dynamicObject, timeout?: number, fd?: dynamicObject) => Promise<unknown>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { cssProps } from "./stylesheet.js";
|
|
2
|
+
import CSS from './css.js';
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import { colorNames } from "./colors.js";
|
|
5
|
+
export { CSS as css };
|
|
6
|
+
// export const css = new CSS()
|
|
7
|
+
// Hex color regex (#RGB, #RRGGBB)
|
|
8
|
+
export const hexColorRegex = /^#([A-Fa-f0-9]{3}){1,2}$/;
|
|
9
|
+
// export const hexColorRegex3 = /^#([A-Fa-f0-9]{3}){1,2}$/;
|
|
10
|
+
// RGBA color regex (rgba(255, 255, 255, 1))
|
|
11
|
+
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*))?\)$/;
|
|
12
|
+
// HSL color regex (hsl(360, 100%, 100%))
|
|
13
|
+
export const hslColorRegex = /^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/;
|
|
14
|
+
export const isHexColor = (color) => hexColorRegex.test(color);
|
|
15
|
+
export const isRgbaColor = (color) => rgbaColorRegex.test(color);
|
|
16
|
+
export const isHslColor = (color) => hslColorRegex.test(color);
|
|
17
|
+
// Function to validate a color string
|
|
18
|
+
export const isColor = (color) => colorNames.includes(color) || isHexColor(color) || isRgbaColor(color) || isHslColor(color);
|
|
19
|
+
export const isUrl = (u) => {
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(u);
|
|
23
|
+
}
|
|
24
|
+
catch (_) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
28
|
+
};
|
|
29
|
+
export const isEmail = (e) => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(e);
|
|
30
|
+
export const isIPv4 = (ipaddress) => {
|
|
31
|
+
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);
|
|
32
|
+
};
|
|
33
|
+
export const isNumber = (v) => /\d+(\.\d+)?$/g.test(v);
|
|
34
|
+
// Convert hex to rgba
|
|
35
|
+
export const hexToRgba = (hex, alpha = 1) => {
|
|
36
|
+
// Remove the hash symbol if present
|
|
37
|
+
hex = hex.replace(/^#/, '');
|
|
38
|
+
// If shorthand hex (#RGB), expand it to full form (#RRGGBB)
|
|
39
|
+
if (hex.length === 3) {
|
|
40
|
+
hex = hex.split('').map(char => char + char).join('');
|
|
41
|
+
}
|
|
42
|
+
// Convert to integer values for RGB
|
|
43
|
+
const bigint = parseInt(hex, 16);
|
|
44
|
+
const r = (bigint >> 16) & 255;
|
|
45
|
+
const g = (bigint >> 8) & 255;
|
|
46
|
+
const b = bigint & 255;
|
|
47
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
48
|
+
};
|
|
49
|
+
export const ucfirst = (str) => `${str.charAt(0).toUpperCase()}${str.substring(1, str.length)}`;
|
|
50
|
+
export const cleanProps = (props, withProps = []) => {
|
|
51
|
+
let _extras = [`as`, ...withProps];
|
|
52
|
+
let _props = { ...props };
|
|
53
|
+
Object.keys(_props).map(k => {
|
|
54
|
+
if (k in cssProps) {
|
|
55
|
+
delete _props[k];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
_extras.map(x => x in _props && delete _props[x]);
|
|
59
|
+
return _props;
|
|
60
|
+
};
|
|
61
|
+
export const withZuz = (cx) => new CSS().Build([[cx]]).cx.join(` `);
|
|
62
|
+
export const extendGlobals = () => {
|
|
63
|
+
Object.prototype.is = function (v) { return typeof this === v; };
|
|
64
|
+
Object.prototype.typeof = function (v) { return typeof this === typeof v; };
|
|
65
|
+
Object.prototype.equals = function (v) { return this === v; };
|
|
66
|
+
Object.prototype.isNull = function () { return this === null; };
|
|
67
|
+
Object.prototype.isString = function () { return typeof this == `string`; };
|
|
68
|
+
Object.prototype.isNumber = function () { return /^[+-]?\d+(\.\d+)?$/.test(this); };
|
|
69
|
+
Object.prototype.isObject = function () { return typeof this == `object` && !Array.isArray(this) && this !== null; };
|
|
70
|
+
Object.prototype.isArray = function () { return Array.isArray(this); };
|
|
71
|
+
Object.prototype.isEmpty = function () {
|
|
72
|
+
if (Array.isArray(this))
|
|
73
|
+
return this.length === 0;
|
|
74
|
+
else if (`object` === typeof this)
|
|
75
|
+
return Object.keys(this).length == 0;
|
|
76
|
+
else
|
|
77
|
+
return this == "" || this.length == 0;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export const withPost = async (uri, data, timeout = 60, fd = {}) => {
|
|
81
|
+
if (Object.keys(fd).length > 0) {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
axios({
|
|
84
|
+
method: 'post',
|
|
85
|
+
url: uri,
|
|
86
|
+
data: data,
|
|
87
|
+
timeout: timeout * 1000,
|
|
88
|
+
headers: {
|
|
89
|
+
'Content-Type': 'multipart/form-data',
|
|
90
|
+
},
|
|
91
|
+
onUploadProgress: ev => {
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
.then(resp => {
|
|
95
|
+
if (resp.data && "kind" in resp.data) {
|
|
96
|
+
resolve(resp.data);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
reject(resp.data);
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
.catch(err => reject(err));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
axios.post(uri, {
|
|
107
|
+
...data,
|
|
108
|
+
__stmp: new Date().getTime() / 1000
|
|
109
|
+
}, {
|
|
110
|
+
timeout: 1000 * timeout,
|
|
111
|
+
headers: {
|
|
112
|
+
'Content-Type': 'application/json',
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
.then(resp => {
|
|
116
|
+
if (resp.data && "kind" in resp.data) {
|
|
117
|
+
resolve(resp.data);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
reject(resp.data);
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.catch(err => reject(err));
|
|
124
|
+
});
|
|
125
|
+
};
|