@zuzjs/ui 0.4.0 → 0.4.2

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.
Files changed (46) hide show
  1. package/dist/bin.js +34 -23
  2. package/dist/comps/base.d.ts +11 -1
  3. package/dist/comps/base.js +23 -3
  4. package/dist/comps/box.d.ts +2 -0
  5. package/dist/comps/box.js +0 -7
  6. package/dist/comps/button.d.ts +2 -0
  7. package/dist/comps/button.js +0 -11
  8. package/dist/comps/checkbox.d.ts +2 -0
  9. package/dist/comps/checkbox.js +0 -18
  10. package/dist/comps/contextmenu.d.ts +6 -1
  11. package/dist/comps/contextmenu.js +3 -2
  12. package/dist/comps/cover.d.ts +2 -0
  13. package/dist/comps/cover.js +1 -25
  14. package/dist/comps/dialog.d.ts +0 -0
  15. package/dist/comps/dialog.js +1 -0
  16. package/dist/comps/form.d.ts +6 -1
  17. package/dist/comps/form.js +10 -149
  18. package/dist/comps/heading.d.ts +2 -0
  19. package/dist/comps/heading.js +0 -13
  20. package/dist/comps/icon.d.ts +2 -0
  21. package/dist/comps/icon.js +0 -10
  22. package/dist/comps/image.d.ts +13 -0
  23. package/dist/comps/image.js +8 -0
  24. package/dist/comps/input.d.ts +2 -0
  25. package/dist/comps/input.js +0 -15
  26. package/dist/comps/select.d.ts +18 -0
  27. package/dist/comps/select.js +32 -0
  28. package/dist/comps/sheet.d.ts +4 -1
  29. package/dist/comps/sheet.js +39 -59
  30. package/dist/comps/spinner.d.ts +2 -0
  31. package/dist/comps/spinner.js +0 -1
  32. package/dist/funs/colors.d.ts +0 -6
  33. package/dist/funs/colors.js +0 -6
  34. package/dist/funs/css.d.ts +25 -251
  35. package/dist/funs/css.js +355 -325
  36. package/dist/funs/index.d.ts +10 -1
  37. package/dist/funs/index.js +35 -10
  38. package/dist/funs/stylesheet.d.ts +7 -242
  39. package/dist/funs/stylesheet.js +97 -7
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.js +2 -0
  42. package/dist/styles.css +1 -1
  43. package/dist/types/enums.d.ts +1 -0
  44. package/dist/types/enums.js +1 -0
  45. package/dist/types/index.d.ts +1 -0
  46. package/package.json +1 -1
package/dist/funs/css.js CHANGED
@@ -1,145 +1,193 @@
1
+ import { __SALT, FIELNAME_KEY, isColor, isHexColor, isNumber, LINE_KEY, setDeep } from "./index.js";
2
+ import { cssAnimationCurves, cssDirect, cssProps, cssTransformKeys, cssWithKeys } from "./stylesheet.js";
1
3
  import Hashids from "hashids";
2
- import { cssProps } from "./stylesheet.js";
3
- import { isColor, isHexColor, isNumber } from "./index.js";
4
4
  class CSS {
5
- unit;
5
+ cx;
6
+ cache;
6
7
  PROPS;
7
8
  DIRECT;
8
- IGNORE;
9
- chars;
10
9
  hashids;
11
- cx;
12
- cache;
13
- pseudoRegExp;
14
- // pseudoPattern: string;
15
- pseudoList;
16
- // baseRegex: RegExp;
17
- pseudoCounter;
18
- pseudoPattern;
19
- pseudoReg;
20
- propCounter;
21
- keysWithoutCommaToSpace;
10
+ chars;
22
11
  rgbaRegex;
12
+ IGNORE;
13
+ unit;
14
+ keysWithoutCommaToSpace;
15
+ propCounter;
23
16
  seperator;
17
+ pseudoList;
18
+ ids;
24
19
  constructor(options) {
25
20
  const opts = options || {};
21
+ this.cx = [];
22
+ this.cache = {};
26
23
  this.unit = opts.unit || `px`;
27
- this.hashids = new Hashids('', 4);
28
- this.chars = "#abcdefghijklmnopqrstuvwxyz0123456789";
29
24
  this.seperator = `__@@__`;
30
- this.PROPS = cssProps;
25
+ this.hashids = new Hashids(__SALT, 5);
26
+ this.chars = "#@_-[]{}();:^/!^&*+='\"`,.~abcdefghijklmnopqrstuvwxyz0123456789";
27
+ this.rgbaRegex = /\b\w+\[\d+,\d+,\d+(?:,\d+)?\]/g;
28
+ this.pseudoList = [
29
+ "@before", "@after", "@active", "@checked", "@default", "@disabled", "@empty", "@enabled", "@first", "@firstChild", "@firstOfType", "@focus", "@hover", "@indeterminate", "@inRange", "@invalid", "@lastChild", "@lastOfType", "@link", "@not", "@nthChild", "@nthLastChild", "@nthLastOfType", "@nthOfType", "@onlyChild", "@onlyOfType", "@optional", "@outOfRange", "@readOnly", "@readWrite", "@required", "@root", "@scope", "@target", "@valid", "@visited"
30
+ ];
31
31
  this.IGNORE = [
32
32
  `flex`, `opacity`, `z-index`, `zIndex`, `color`, `line-height`, `anim`, `scale`
33
33
  ];
34
- this.DIRECT = {
35
- "content": "content:'';",
36
- "bold": "font-weight: bold;",
37
- "flex": "display:flex;",
38
- "cols": "flex-direction:column;",
39
- "ass": "align-self:flex-start;",
40
- "ais": "align-items:flex-start;",
41
- "aib": "align-items:baseline;",
42
- "aic": "align-items:center;",
43
- "aie": "align-items:flex-end;",
44
- "jcs": "justify-content:flex-start;",
45
- "jcc": "justify-content:center;",
46
- "jce": "justify-content:flex-end;",
47
- "tal": "text-align: left;",
48
- "tac": "text-align: center;",
49
- "tar": "text-align: right;",
50
- "tas": "text-align: justify;",
51
- "fill": "top: 0px;left: 0px;right: 0px;bottom: 0px;",
52
- "rel": "position:relative;",
53
- "abs": "position:absolute;",
54
- "fixed": "position:fixed;",
55
- "abc": "top: 50%;left: 50%;transform: translate(-50%, -50%);",
56
- "tdn": "text-decoration:none;",
57
- "tdu": "text-decoration:underline;",
58
- "nous": "user-select:none;",
59
- "nope": "pointer-events:none;",
60
- "ph": "padding-left:__VALUE__;padding-right:__VALUE__;",
61
- "pv": "padding-top:__VALUE__;padding-bottom:__VALUE__;",
62
- "mh": "margin-left:__VALUE__;margin-right:__VALUE__;",
63
- "mv": "margin-top:__VALUE__;margin-bottom:__VALUE__;",
64
- "translate": "transform:translate(__VALUE__);",
65
- "translateX": "transform:translateX(__VALUE__);",
66
- "translateY": "transform:translateY(__VALUE__);",
67
- "rotate": "transform: rotate(__VALUE__);",
68
- "scale": "transform: scale(__VALUE__);",
69
- "anim": "transition: all __VALUE__ linear 0s;",
70
- };
71
34
  this.keysWithoutCommaToSpace = [
72
35
  `transform`, `translate`, `color`, `background`, `background-color`, `backgroundColor`,
73
- `border`, `border-bottom`, `border-top`, `border-left`, `border-right`
36
+ `border`, `border-bottom`, `border-top`, `border-left`, `border-right`,
37
+ `grid-template-rows`, `grid-template-columns`
74
38
  ];
75
39
  this.propCounter = {};
76
- this.cx = [];
77
- this.cache = {};
78
- // 1. this.baseRegex = /(\$?[\w%!-]+:\$?[\w%!-]+(?:,[-\w%!.]+)*)|(\$?[\w%!-]+:\$?[-\w%,.!]+)/g;
79
- // 2. this.baseRegex = /(\$?[\w%!-]+:\$?\w+\[(.*?)\]+)|(\$?[\w%!-]+:\$?[-\w%,.!]+|\$?[-\w%,.!]+)/g;
80
- // 3. this.baseRegex = /(\$?[\w%!-]+:\$?[\w%!-]+(?:\[[^\]]*\])?(?:,[^\s,]+)*)|(\$?[\w%!-]+:\$?[-\w%,.!]+|\$?[-\w%,.!]+)/g;
81
- // let __baseRegex = /\$?\b\w+:\$?(?:\d+(\.\d+)?%?|\w+\[[^\]]*\]|[-\w%!,.]+|[\w%!-]+)/g
82
- // const _any = `([^\\s]+)`
83
- // const _bracketWord = `\\w+\\[[^\\]]*\\]`
84
- // // const __number = `\\-?\\d+(\\.\\d+)?%?(?:[[a-z]+]?)?`
85
- // // (?:\.?|\d+)?
86
- // const _number = `\\-?\\d*(\\.\\d+)?%?(?:[[a-z]+]?)?`
87
- // const _baseRegex = `\\$?\\b\\w+:(?:`+
88
- // `\\$?${_number},?${_number}?` + // 50|50%|50.5
89
- // `|\\$?${_bracketWord}` + // calc[12 - 22] | color:rgba[255,255,255,0.5]
90
- // `|(?:${_any},${_any},${_any}\\b)` +
91
- // // `|(?:${_number},${_number},${_number},${_number})` +
92
- // // `|(?:${_number}[,${_number}]?)` +
93
- // `|\\$?[\\w-]+` +
94
- // `)!?`
95
- // console.log(_baseRegex)
96
- // this.baseRegex = new RegExp(_baseRegex, `g`)
97
- this.rgbaRegex = /\b\w+\[\d+,\d+,\d+(?:,\d+)?\]/g;
98
- this.pseudoList = ["before", "after", "active", "checked", "default", "disabled", "empty", "enabled", "first", "first-child", "first-of-type", "focus", "hover", "indeterminate", "in-range", "invalid", "last-child", "last-of-type", "link", "not", "nth-child", "nth-last-child", "nth-last-of-type", "nth-of-type", "only-child", "only-of-type", "optional", "out-of-range", "read-only", "read-write", "required", "root", "scope", "target", "valid", "visited"];
99
- this.pseudoCounter = {};
100
- this.pseudoList.map((p) => this.pseudoCounter[p] = 0);
101
- this.pseudoPattern = this.pseudoList.map((word) => word).join('|');
102
- this.pseudoReg = new RegExp(this.pseudoPattern, `g`);
103
- // this.pseudoRegExp = /&(\w+)\(\s*([^()]*?(?:\([^()]*\))*[^()]*)\s*\)/g
104
- this.pseudoRegExp = /(?:&|.)(\w+)\(\s*([^()]*?(?:\([^()]*\))*[^()]*)\s*\)/g;
40
+ this.ids = [];
41
+ this.PROPS = cssProps;
42
+ this.DIRECT = cssDirect;
105
43
  }
106
- getStyleSheet(cache, indentLevel = 0, pseudo = false) {
44
+ styleSheet(cache, pseudo = ``) {
107
45
  const self = this;
108
- const indent = ``; //` `.repeat(indentLevel)
109
- let scss = ``;
110
- // for( const key in cache){
111
- Object.keys(cache).map((key) => {
112
- // if ( key.includes(`actions`) )
113
- // console.log(`kc`, key, cache[key])
114
- if (`object` == typeof cache[key]) {
115
- const _key = self.pseudoList.filter(x => key.indexOf(x) > -1);
116
- scss += `${indent}${_key.length > 0 ? `&:${_key[0]}` : `\n.${key.split(self.seperator)[0]}`}{`;
117
- scss += self.getStyleSheet(cache[key], indentLevel + 1, true
118
- // _key.length > 0 ? true : false
119
- );
120
- scss += `${indent}}`;
46
+ const scss = [];
47
+ const build = (key, value) => {
48
+ let css = `${self.pseudoList.includes(`@${key}`) ? `&:` : `.`}${key}{`;
49
+ if (`object` == typeof value) {
50
+ for (const prop in value) {
51
+ if (`object` == typeof value[prop]) {
52
+ css += build(prop, value[prop]);
53
+ }
54
+ else {
55
+ css += value[prop];
56
+ }
57
+ }
121
58
  }
122
59
  else {
123
- // console.log(`getSheet`, key, cache[key])
124
- if (pseudo) {
125
- scss += `${indent}${cache[key]}`;
60
+ css += value;
61
+ }
62
+ css += `}`;
63
+ return css;
64
+ };
65
+ for (const key in cache) {
66
+ const base = cache[key];
67
+ if (key == FIELNAME_KEY) {
68
+ scss.push(`/**\n* @file ${base}\n*/`);
69
+ continue;
70
+ }
71
+ else if (key.startsWith(LINE_KEY)) {
72
+ scss.push(base);
73
+ delete cache[key];
74
+ }
75
+ else {
76
+ const _ = build(key, base);
77
+ if (!self.ids.includes(_)) {
78
+ self.ids.push(_);
79
+ scss.push(_);
126
80
  }
127
- else {
128
- scss += `\n${indent}.${key}{`;
129
- scss += `${indent}${cache[key]}`;
130
- scss += `${indent}}`;
81
+ }
82
+ }
83
+ return scss.join(`\n`);
84
+ }
85
+ _styleSheet(cache) {
86
+ const self = this;
87
+ const scss = [];
88
+ const mainKeys = [];
89
+ const extractMasterKeys = (key, value) => {
90
+ const baseKey = self.cleanKey(key);
91
+ if (`string` === typeof value) {
92
+ if (!mainKeys.includes(baseKey)) {
93
+ scss.push(`.${baseKey}{${value}}`);
94
+ mainKeys.push(baseKey);
131
95
  }
132
96
  }
133
- });
134
- return scss;
97
+ else {
98
+ for (const prop in value) {
99
+ extractMasterKeys(prop, value[prop]);
100
+ }
101
+ }
102
+ };
103
+ const build = (key, value, level = 0) => {
104
+ const baseKey = self.cleanKey(key);
105
+ let css = `${self.pseudoList.includes(`@${baseKey}`) ? `&:${baseKey}` : `${baseKey.includes(`.`) ? `` : `.`}${baseKey}`}{`;
106
+ if (`object` === typeof value) {
107
+ const _extend = [];
108
+ for (const prop in value) {
109
+ if (`string` === typeof value[prop]) {
110
+ _extend.push(`.${prop}`);
111
+ }
112
+ }
113
+ if (_extend.length > 0)
114
+ css += `@extend ${_extend.join(`, `)};`;
115
+ for (const prop in value) {
116
+ if (`object` === typeof value[prop]) {
117
+ css += build(prop, value[prop], level + 1);
118
+ }
119
+ }
120
+ }
121
+ css += `}`;
122
+ return css;
123
+ };
124
+ for (const key in cache) {
125
+ if (key == FIELNAME_KEY) {
126
+ scss.push(`/**\n* @file ${cache[key]}\n*/`);
127
+ continue;
128
+ }
129
+ extractMasterKeys(key, cache[key]);
130
+ }
131
+ for (const key in cache) {
132
+ if (key.startsWith(LINE_KEY)) {
133
+ scss.push(cache[key]);
134
+ delete cache[key];
135
+ }
136
+ }
137
+ for (const key in cache) {
138
+ if (`object` == typeof cache[key]) {
139
+ scss.push(build(key, cache[key]));
140
+ }
141
+ }
142
+ return scss.join(`\n`);
135
143
  }
136
- makeColor() {
144
+ cleanKey(key) {
145
+ return key.split(this.seperator)[0].replace(`@`, ``);
146
+ }
147
+ deepClean(cache, level = 0) {
148
+ const self = this;
149
+ const _ = {};
150
+ const oid = (k, value) => {
151
+ const [_a, _z] = k.split(self.seperator);
152
+ const keys = [_a];
153
+ if (`object` == typeof value) {
154
+ for (const o in value) {
155
+ keys.push(oid(o, value[o]));
156
+ }
157
+ }
158
+ return keys.join(`-`);
159
+ };
160
+ Object.keys(cache).map((_k) => {
161
+ const __k = self.cleanKey(_k);
162
+ if (`object` == typeof cache[_k]) {
163
+ const _d = oid(_k, cache[_k]);
164
+ let _indices = 0;
165
+ for (let i = 0; i < _d.length; i++) {
166
+ _indices += self.chars.indexOf(_d.charAt(i));
167
+ }
168
+ const _id = `z${self.hashids.encode(_indices)}`;
169
+ if (!_[_id]) {
170
+ const cleaned = self.deepClean(cache[_k], level + 1);
171
+ if (level == 0 && self.pseudoList.includes(`@${__k}`)) {
172
+ self.cx.push(_id);
173
+ _[_id] = { [__k]: cleaned };
174
+ }
175
+ else
176
+ _[__k] = cleaned;
177
+ }
178
+ }
179
+ else {
180
+ _[__k] = cache[_k];
181
+ }
182
+ });
183
+ return _;
137
184
  }
138
185
  makeUnit(k, v) {
139
- // console.log(`unit`, k, v)
140
186
  if (k == `rotate`) {
141
187
  return `deg`;
142
188
  }
189
+ if (cssTransformKeys.includes(k))
190
+ return ``;
143
191
  if (typeof v == "string" && (!isNumber(v) || this.IGNORE.indexOf(k) > -1))
144
192
  return ``;
145
193
  return this.unit;
@@ -148,31 +196,22 @@ class CSS {
148
196
  if (k in this.PROPS) {
149
197
  const key = this.PROPS[k];
150
198
  let value;
151
- v = v.trim(); //.replace(`\``, ``)
199
+ v = v.trim();
152
200
  let hasImportant = v.charAt(v.length - 1) == `!`;
153
201
  v = hasImportant ? v.slice(0, -1) : v;
154
202
  let important = hasImportant ? ` !important` : ``;
155
- // if ( key.includes(`opacity`)) console.log(`makevalue`, key, k, v)
156
- /**
157
- * Variable
158
- */
159
203
  if (v.charAt(0) == `$`) {
160
204
  value = `var(--${v.replace(`$`, ``)})`;
161
205
  }
162
206
  else if (v.trim() == `transparent`) {
163
207
  value = `rgba(0,0,0,0)`;
164
208
  }
165
- /**
166
- * border
167
- */
168
209
  else if ([`border`, `borderBottom`, `borderTop`, `borderLeft`, `borderRight`].includes(k)) {
169
210
  const _parts = [];
170
- // console.log(`--border`, key, v)
171
211
  if (v.match(this.rgbaRegex)) {
172
212
  _parts.push(v.match(this.rgbaRegex)[0].replace(`[`, `(`).replace(`]`, `)`));
173
213
  v = v.replace(this.rgbaRegex, ``).trim().replace(`,,`, `,`);
174
214
  }
175
- // console.log(`-border`, key, v, _parts)
176
215
  v.split(`,`).map((p) => {
177
216
  if (p.includes(`rgb`) || p.includes(`rgba`) || isColor(`#${p}`) || p.startsWith(`$`)) {
178
217
  if (p.includes(`rgb`) || p.includes(`rgba`)) {
@@ -194,13 +233,8 @@ class CSS {
194
233
  }
195
234
  });
196
235
  value = _parts.join(` `);
197
- // console.log(`border`, value)
198
236
  }
199
- /**
200
- * Color
201
- */
202
237
  else if ([`color`, `bg`, `background`, `background-color`, `backgroundColor`].includes(key)) {
203
- // else if ( [`color`].includes( key ) ){
204
238
  if (v.charAt(0) == `#`) {
205
239
  v = v.substring(1);
206
240
  }
@@ -214,16 +248,9 @@ class CSS {
214
248
  else
215
249
  value = v.trim();
216
250
  }
217
- /**
218
- * FontWeight
219
- */
220
251
  else if (key == `font-weight`) {
221
252
  value = v;
222
253
  }
223
- /**
224
- * calc
225
- * passed as calc[value]
226
- */
227
254
  else if (v.match(/\[(.*?)\]/g)) {
228
255
  try {
229
256
  const vs = v.match(/\[(.*?)\]/g)[0].slice(1, -1);
@@ -233,17 +260,13 @@ class CSS {
233
260
  catch (e) { }
234
261
  }
235
262
  else {
236
- // ${v.charAt(0) == `$` ? `var(--${v.substring(1)})` : v}
237
- // if ( key.includes(`padding`) ) console.log(`->padding`, v)
238
263
  if (v.includes(`,`)) {
239
- // console.log(`vwithcomma`, v)
240
264
  let __v = [];
241
265
  v.split(`,`).map((_) => {
242
266
  if (_.startsWith(`$`)) {
243
267
  __v.push(`var(--${_.substring(1)})`);
244
268
  }
245
269
  else {
246
- // console.log(`comma`, key, v, this.makeUnit(key, v))
247
270
  __v.push(`${_}${this.makeUnit(key, _)}`);
248
271
  }
249
272
  });
@@ -254,14 +277,27 @@ class CSS {
254
277
  }
255
278
  if (!value)
256
279
  return ``;
257
- // if ( key == `background` ) console.log(`makevalue`, key, value)
258
- // if ( key.includes(`border`) ) console.log(`--border`, `${key}: ${value}${important};`)
259
280
  value = value.includes(`,`) && !this.keysWithoutCommaToSpace.includes(key) ? value.replace(`,`, ` `) : value;
260
- // if ( key.includes(`padding`) ) console.log(`->padding`, `${key}: ${value}${important};`)
281
+ if (key == `content`)
282
+ value = `"${value}"`;
261
283
  return `${key}: ${value}${important};`;
262
284
  }
263
285
  return ``;
264
286
  }
287
+ calcIndexes(str) {
288
+ let _indices = [];
289
+ for (let i = 0; i < str.length; i++) {
290
+ _indices.push(this.chars.indexOf(str.charAt(i)).toString());
291
+ }
292
+ return _indices.join(``);
293
+ }
294
+ mmakeID(k, v, _out) {
295
+ const cs = [];
296
+ const out = this.calcIndexes(k) + this.calcIndexes(v) + this.calcIndexes(_out);
297
+ console.log(this.hashids.encode(out));
298
+ cs.push(out.charAt(0).match(/\d+/g) ? `z` : ``, out);
299
+ return cs.join(``);
300
+ }
265
301
  makeID(k, v, _out) {
266
302
  const self = this;
267
303
  const _css = _out.toString().replace(/;|:|\s/g, "");
@@ -277,80 +313,60 @@ class CSS {
277
313
  if (v.toString().indexOf("-") > -1) {
278
314
  v.toString().split("-").map(c => _cp += c.substring(0, 1));
279
315
  }
280
- return `${_cp}${self.hashids.encode((self.PROPS[k] ? self.PROPS[k].length : 0) + _indices + (isNaN(parseInt(v)) ? 0 : parseInt(v)))}`.replace(/\s|\$/g, '-');
316
+ const _id = `${_cp}${self.hashids.encode((self.PROPS[k] ? self.PROPS[k].length : 0) + _indices + (isNaN(parseInt(v)) ? 0 : parseInt(v)))}`.replace(/\s|\$/g, '-');
317
+ const _kw = _id in self.propCounter ? ++self.propCounter[_id] : self.propCounter[_id] = 1;
318
+ return _id;
281
319
  }
282
- makeIDFromObject(key, obj) {
320
+ lexer(line) {
283
321
  const self = this;
284
- const out = [key];
285
- const fcs = [key.charAt(0)];
286
- const vals = [];
287
- const build = (o) => {
288
- Object.keys(o).map((n) => {
289
- if (`object` == typeof o[n]) {
290
- build(o[n]);
291
- }
292
- else {
293
- fcs.push(n.charAt(0));
294
- vals.push(o[n]);
295
- }
296
- });
297
- };
298
- build(obj);
299
- let _indices = 0;
300
- let _cp = "";
301
- for (const ot of vals) {
302
- const _css = ot.toString().replace(/;|:|\s/g, "");
303
- for (let i = 0; i < _css.length; i++) {
304
- _indices += self.chars.indexOf(ot.charAt(i));
305
- }
306
- if (ot.indexOf("-") > -1) {
307
- ot.split("-").map((c) => _cp += c.substring(0, 1));
308
- }
309
- }
310
- return `${_cp}${self.hashids.encode(_indices)}`.replace(/\s/g, '-');
311
- }
312
- parseRawLine(line) {
313
- const self = this;
314
- const result = {};
315
- try {
316
- const matches = line.match(self.pseudoRegExp);
317
- if (matches) {
318
- // if ( line.includes(`opacity`) ) console.log(`matches`, matches)
319
- matches.map((m) => {
320
- const pseudo = self.pseudoRegExp.exec(m); ///&\w+/g.exec(m)
321
- // if ( m.includes(`opacity`) ) console.log(`pseudo`, m, pseudo)
322
- if (pseudo) {
323
- const _kw = pseudo[1] in self.propCounter ? ++self.propCounter[pseudo[1]] : self.propCounter[pseudo[1]] = 1;
324
- const psd = `${pseudo[1]}${this.seperator}${_kw}`;
325
- result[psd] = self.parseRawLine(pseudo[2]);
326
- }
327
- line = line.replace(self.pseudoRegExp, ``);
328
- });
322
+ let word = ``;
323
+ let levels = [];
324
+ let isLevel = false;
325
+ let classes = {};
326
+ let hasBracket = false;
327
+ const processWord = () => {
328
+ word = word.trim();
329
+ if (!word.includes(`[`))
330
+ word = word.replace(/\s+/g, ``);
331
+ if (word == ``)
332
+ return;
333
+ const _kw = word in self.propCounter ? ++self.propCounter[word] : self.propCounter[word] = 1;
334
+ if (isLevel) {
335
+ levels.push(`${word}${self.seperator}${_kw}`);
336
+ isLevel = false;
329
337
  }
330
- // if ( line.includes(`opacity`) ) console.log(`matches`, result)
331
- let word = ``;
332
- let hasBracket = false;
333
- const processWord = () => {
334
- word = word.replace(/(`|{|})/g, ``);
335
- const _kw = word in self.propCounter ? ++self.propCounter[word] : self.propCounter[word] = 1;
338
+ else {
339
+ let _keyWord = `${word}${_kw}`.trim();
336
340
  if (word.includes(`:`)) {
337
341
  const [key, value] = word.split(`:`);
338
342
  const _kk = key in self.propCounter ? ++self.propCounter[key] : self.propCounter[key] = 1;
339
- result[`${key}${_kk}${value}`.trim()] = `${key}:${value}`.trim();
340
- // if (value) {
341
- // } else {
342
- // result[`${word}${_kk}`] = word // true;
343
- // }
343
+ _keyWord = `${key}${_kk}${value}`.trim();
344
344
  }
345
- else {
346
- result[`${word}${_kw}`.trim()] = word.trim();
345
+ classes = setDeep(classes, `${levels.join(`^`)}${levels.length > 0 ? `^` : ``}${word}`, word, `^`);
346
+ }
347
+ word = ``;
348
+ };
349
+ line
350
+ .replace(/\`|\}|\{/g, ``)
351
+ .trim()
352
+ .replace(/\s+/g, ` `)
353
+ .split(``)
354
+ .map((char, i, arr) => {
355
+ const nextChar = arr[i + 1];
356
+ if (char == ` ` && word != `` && ![`(`, `)`, `[`, `]`, `:`].includes(nextChar) && !hasBracket) {
357
+ processWord();
358
+ }
359
+ else {
360
+ if ([`&`].includes(char)) {
361
+ isLevel = true;
347
362
  }
348
- word = ``;
349
- };
350
- line.trim().split(``)
351
- .map(char => {
352
- if (char == ` ` && word != `` && !hasBracket) {
363
+ else if ([`(`].includes(char) && isLevel) {
364
+ processWord();
365
+ }
366
+ else if ([`)`].includes(char)) {
353
367
  processWord();
368
+ levels.splice(-1, 1);
369
+ isLevel = false;
354
370
  }
355
371
  else {
356
372
  word += char;
@@ -359,124 +375,102 @@ class CSS {
359
375
  if (char == `]` && hasBracket)
360
376
  hasBracket = false;
361
377
  }
362
- });
363
- if (word != ``)
364
- processWord();
365
- // line = line.charAt(0) == `\`` ? line.substring(1) : line
366
- // line = line.charAt(line.length - 1) == `\`` ? line.substring(0,) : line
367
- // if ( line.includes(`opacity`) )
368
- // console.log(`oppc`, line)
369
- // const baseProperties = line.match(self.baseRegex);
370
- // if (baseProperties) {
371
- // // console.log(line, baseProperties)
372
- // baseProperties.forEach(prop => {
373
- // const [key, value] = prop.split(':');
374
- // if (value) {
375
- // if ( result[key] ){
376
- // const _kk = key in self.propCounter ? ++self.propCounter[key] : self.propCounter[key] = 1
377
- // result[`${key}${_kk}`] = `${key}:${value}`;
378
- // }else
379
- // result[key] = `${key}:${value}`;
380
- // } else {
381
- // const _kk = prop in self.propCounter ? ++self.propCounter[prop] : self.propCounter[prop] = 1
382
- // result[`${prop}${_kk}`] = prop // true;
383
- // }
384
- // });
385
- // }
386
- // const extraWords = line.replace(self.baseRegex, ``).match(/(?<!\w|\$|&)[a-zA-Z0-9-]+(?!\w)/g)
387
- // if ( extraWords ) {
388
- // extraWords.map(w => result[w] = w )
389
- // }
390
- }
391
- catch (e) {
392
- // console.log(e)
393
- }
394
- // if( line.includes(`gfile`))
395
- // console.log(result)
396
- return result;
378
+ }
379
+ });
380
+ if (word != ``)
381
+ processWord();
382
+ return classes;
397
383
  }
398
- makeCSS(line) {
384
+ processLine(line) {
399
385
  const self = this;
400
- // console.log(line)
401
- const rest = self.parseRawLine(line);
402
- // if ( line.includes(`opacity`) ) console.log(line, rest)
403
- // console.log(rest)
404
- const value = (_k, pseudo = ``) => {
405
- if (_k in self.DIRECT) {
406
- const _out = self.DIRECT[_k];
407
- const _id = self.makeID(_k, _k + pseudo, _out);
408
- if (pseudo == ``)
409
- self.cx.push(_id);
410
- return { [_id]: _out };
411
- }
412
- else if (_k.includes(`:`)) {
413
- const [key, _val] = _k.split(`:`);
414
- if (key in self.PROPS) {
415
- const _out = self.makeValue(key, _val);
416
- const _id = self.makeID(key, _val + pseudo, _out);
417
- if (pseudo == ``)
418
- self.cx.push(_id);
419
- return { [_id]: _out };
386
+ if (line.startsWith(FIELNAME_KEY)) {
387
+ self.cache = { ...self.cache, [FIELNAME_KEY]: line.split(`:`)[1] };
388
+ }
389
+ else {
390
+ const value = (_k, pseudo = ``) => {
391
+ if (_k.includes(`:`)) {
392
+ const [key, _val] = _k.split(`:`);
393
+ if (key in self.PROPS) {
394
+ const _out = self.makeValue(key, _val);
395
+ const _id = self.makeID(key, _val + pseudo, _out);
396
+ if (pseudo == ``)
397
+ self.cx.push(_id);
398
+ return { [_id]: _out };
399
+ }
400
+ else if (key in self.DIRECT) {
401
+ const hasImportant = _val.endsWith(`!`);
402
+ const important = hasImportant ? ` !important` : ``;
403
+ let val = hasImportant ? _val.slice(0, -1) : _val;
404
+ var _out = ``;
405
+ if (key == `extend`) {
406
+ val = val.split(`,`).reduce((acc, v) => {
407
+ acc.push(`${v.startsWith(`.`) ? `` : `.`}${v.trim()}`);
408
+ return acc;
409
+ }, []).join(`,`);
410
+ }
411
+ else if (key == `anim`) {
412
+ let delay = `0s`;
413
+ let curve = `linear`;
414
+ let duration = val;
415
+ if (val.includes(",")) {
416
+ _out = self.DIRECT[key];
417
+ const [_duration, ..._rest] = val.split(`,`);
418
+ let rest = _rest.join(",").trim();
419
+ duration = _duration;
420
+ if (rest.includes(`[`) && rest.includes(`]`)) {
421
+ for (const curv in cssAnimationCurves) {
422
+ if (rest.startsWith(curv)) {
423
+ curve = `${rest.replace(curv, cssAnimationCurves[curv]).replace(`[`, `(`).replace(`]`, `)`)}`;
424
+ break;
425
+ }
426
+ }
427
+ }
428
+ }
429
+ _out = self.DIRECT[key]
430
+ .replace(`__VALUE__`, duration)
431
+ .replace(`__CURVE__`, curve)
432
+ .replace(`__DELAY__`, delay);
433
+ }
434
+ else {
435
+ const __value = `${val}${key == `extend` ? `` : self.makeUnit(key, val)}`;
436
+ _out = self.DIRECT[key].includes(`__VALUE__`) ?
437
+ self.DIRECT[key].replace(/__VALUE__/g, __value).replace(`;`, `${important};`) : self.DIRECT[key];
438
+ }
439
+ const _id = self.makeID(key, key + pseudo, _out);
440
+ if (pseudo == ``)
441
+ self.cx.push(_id);
442
+ return { [_id]: _out };
443
+ }
420
444
  }
421
- else if (key in self.DIRECT) {
422
- const hasImportant = _val.endsWith(`!`);
423
- const val = hasImportant ? _val.slice(0, -1) : _val;
424
- const important = hasImportant ? ` !important` : ``;
425
- const _out = self.DIRECT[key].includes(`__VALUE__`) ?
426
- self.DIRECT[key].replace(/__VALUE__/g, `${val}${self.makeUnit(key, val)}${important}`) : self.DIRECT[key];
427
- const _id = self.makeID(key, key + pseudo, _out);
445
+ else if (_k in self.DIRECT) {
446
+ const _out = self.DIRECT[_k];
447
+ const _id = self.makeID(_k, _k + pseudo, _out);
428
448
  if (pseudo == ``)
429
449
  self.cx.push(_id);
430
450
  return { [_id]: _out };
431
451
  }
432
- }
433
- else {
434
- self.cx.push(_k.trim());
435
- }
436
- return {};
437
- };
438
- const build = (o, pseudo = ``) => {
439
- let out = {};
440
- Object.keys(o).map((_k) => {
441
- if (`object` == typeof o[_k]) {
442
- // console.log(_k, o[_k])
443
- out = { ...out, [_k]: build(o[_k], _k) };
444
- // self.makeIDFromObject(_k, cache[_k])
445
- }
446
- else {
447
- out = { ...out, ...value(o[_k], pseudo) };
448
- }
449
- });
450
- return out;
451
- };
452
- // console.log(rest)
453
- // console.log(`buildRest`, build(rest))
454
- self.cache = { ...self.cache, ...build(rest) };
455
- // console.log(self.cache)
456
- }
457
- cleanPseudo(cache) {
458
- const self = this;
459
- const _ = {};
460
- Object.keys(cache).map((_k) => {
461
- // console.log(`cleanPseudo`, _k, cache[_k])
462
- if (`object` == typeof cache[_k]) {
463
- const _id = self.makeIDFromObject(_k, cache[_k]);
464
- if (!_[_id]) {
465
- self.cx.push(_id);
466
- _[_id] = { [_k]: cache[_k] };
452
+ else if (_k.trim().match(/^[a-zA-Z0-9\-]+$/g)) {
453
+ self.cx.push(_k.trim());
467
454
  }
468
- // if ( _[_id] ) console.log(`cleanPseudo`, _id, `is duplicate`, _[_id])
469
- // console.log(`cleanPseudo`, _id, _k, cache[_k])
470
- }
471
- else {
472
- // console.log(`-cleanPseudo`, _k, cache[_k])
473
- _[_k] = cache[_k];
474
- }
475
- });
476
- // console.log(`cleanedPseudo`, _)
477
- return _;
455
+ return {};
456
+ };
457
+ const build = (o, pseudo = ``) => {
458
+ let out = {};
459
+ Object.keys(o).map((_k) => {
460
+ if (`object` == typeof o[_k]) {
461
+ out = { ...out, [_k]: build(o[_k], _k) };
462
+ }
463
+ else {
464
+ out = { ...out, ...value(o[_k], pseudo) };
465
+ }
466
+ });
467
+ return out;
468
+ };
469
+ const _built = build(self.lexer(line));
470
+ self.cache = { ...self.cache, ..._built };
471
+ }
478
472
  }
479
- Build(css) {
473
+ Build(css, cli = false) {
480
474
  let self = this;
481
475
  self.cx = [];
482
476
  self.cache = {};
@@ -490,21 +484,57 @@ class CSS {
490
484
  }
491
485
  css.map((arr) => {
492
486
  arr.map((line) => {
493
- self.makeCSS(line);
487
+ self.processLine(line);
494
488
  });
495
489
  });
496
- // console.log({
497
- // cx: self.cx,
498
- // sheet: self.getStyleSheet(self.cleanPseudo(self.cache))
499
- // })
500
- // console.log(self.cache)
501
- // console.log(self.cleanPseudo(self.cache))
502
- // console.log(self.getStyleSheet(self.cleanPseudo(self.cache)))
503
- // console.log(self.cache)
504
- return {
490
+ const _cleaned = self.deepClean(self.cache);
491
+ const _ = {
505
492
  cx: self.cx,
506
- sheet: self.getStyleSheet(self.cleanPseudo(self.cache))
493
+ sheet: self.styleSheet(_cleaned)
507
494
  };
495
+ return _;
508
496
  }
509
497
  }
510
498
  export default CSS;
499
+ export const buildWithStyles = (source) => {
500
+ const _ = {};
501
+ const _css = new CSS();
502
+ if (Object.keys(source).length > 0) {
503
+ const _transform = [];
504
+ for (const prop in source) {
505
+ if (prop in cssWithKeys) {
506
+ if (cssTransformKeys.includes(cssWithKeys[prop])) {
507
+ _transform.push(`${cssWithKeys[prop]}(${source[prop]}${_css.makeUnit(prop, source[prop])})`);
508
+ }
509
+ else
510
+ _[cssWithKeys[prop]] = source[prop];
511
+ }
512
+ else {
513
+ if (cssTransformKeys.includes(prop)) {
514
+ _transform.push(`${prop}(${source[prop]}${_css.makeUnit(prop, source[prop])})`);
515
+ }
516
+ else
517
+ _[prop] = source[prop];
518
+ }
519
+ }
520
+ if (_transform.length > 0) {
521
+ _.transform = _transform.join(` `);
522
+ }
523
+ }
524
+ return _;
525
+ };
526
+ export const getAnimationCurve = (curve) => {
527
+ if (!curve)
528
+ return `linear`;
529
+ const _curves = [`spring`];
530
+ if (_curves.includes(curve)) {
531
+ switch (curve) {
532
+ case "spring":
533
+ return `cubic-bezier(0.2, -0.36, 0, 1.46)`;
534
+ break;
535
+ default:
536
+ return `linear`;
537
+ }
538
+ }
539
+ return curve;
540
+ };