@zuzjs/ui 0.3.9 → 0.4.1

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/funs/css.js CHANGED
@@ -1,122 +1,194 @@
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;
17
- pseudoCounter;
18
- pseudoPattern;
19
- pseudoReg;
20
- propCounter;
21
- keysWithoutCommaToSpace;
10
+ chars;
22
11
  rgbaRegex;
12
+ IGNORE;
13
+ unit;
14
+ keysWithoutCommaToSpace;
15
+ propCounter;
16
+ seperator;
17
+ pseudoList;
18
+ ids;
23
19
  constructor(options) {
24
20
  const opts = options || {};
21
+ this.cx = [];
22
+ this.cache = {};
25
23
  this.unit = opts.unit || `px`;
26
- this.hashids = new Hashids('', 4);
27
- this.chars = "#abcdefghijklmnopqrstuvwxyz0123456789";
28
- this.PROPS = cssProps;
24
+ this.seperator = `__@@__`;
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
+ ];
29
31
  this.IGNORE = [
30
- `flex`, `opacity`, `z-index`, `zIndex`, `color`, `line-height`, `anim`
32
+ `flex`, `opacity`, `z-index`, `zIndex`, `color`, `line-height`, `anim`, `scale`
31
33
  ];
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
34
  this.keysWithoutCommaToSpace = [
68
35
  `transform`, `translate`, `color`, `background`, `background-color`, `backgroundColor`,
69
- `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`
70
38
  ];
71
39
  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
40
+ this.ids = [];
41
+ this.PROPS = cssProps;
42
+ this.DIRECT = cssDirect;
85
43
  }
86
- getStyleSheet(cache, indentLevel = 0, pseudo = false) {
44
+ styleSheet(cache, pseudo = ``) {
87
45
  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}}`;
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
+ }
98
58
  }
99
59
  else {
100
- if (pseudo) {
101
- 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(_);
102
80
  }
103
- else {
104
- scss += `\n${indent}.${key}{`;
105
- scss += `${indent}${cache[key]}`;
106
- 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);
107
95
  }
108
96
  }
109
- });
110
- 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`);
143
+ }
144
+ cleanKey(key) {
145
+ return key.split(this.seperator)[0].replace(`@`, ``);
111
146
  }
112
- makeColor() {
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 _;
113
184
  }
114
185
  makeUnit(k, v) {
115
- // console.log(`unit`, k, v)
116
186
  if (k == `rotate`) {
117
187
  return `deg`;
118
188
  }
119
- if (typeof v == "string" && !isNumber(v) || this.IGNORE.indexOf(k) > -1)
189
+ if (cssTransformKeys.includes(k))
190
+ return ``;
191
+ if (typeof v == "string" && (!isNumber(v) || this.IGNORE.indexOf(k) > -1))
120
192
  return ``;
121
193
  return this.unit;
122
194
  }
@@ -124,31 +196,22 @@ class CSS {
124
196
  if (k in this.PROPS) {
125
197
  const key = this.PROPS[k];
126
198
  let value;
127
- v = v.trim().replace(`\``, ``);
199
+ v = v.trim();
128
200
  let hasImportant = v.charAt(v.length - 1) == `!`;
129
201
  v = hasImportant ? v.slice(0, -1) : v;
130
202
  let important = hasImportant ? ` !important` : ``;
131
- // if ( key.includes(`border`)) console.log(`makevalue`, key, k, v)
132
- /**
133
- * Variable
134
- */
135
203
  if (v.charAt(0) == `$`) {
136
204
  value = `var(--${v.replace(`$`, ``)})`;
137
205
  }
138
206
  else if (v.trim() == `transparent`) {
139
207
  value = `rgba(0,0,0,0)`;
140
208
  }
141
- /**
142
- * border
143
- */
144
209
  else if ([`border`, `borderBottom`, `borderTop`, `borderLeft`, `borderRight`].includes(k)) {
145
210
  const _parts = [];
146
- // console.log(`--border`, key, v)
147
211
  if (v.match(this.rgbaRegex)) {
148
212
  _parts.push(v.match(this.rgbaRegex)[0].replace(`[`, `(`).replace(`]`, `)`));
149
213
  v = v.replace(this.rgbaRegex, ``).trim().replace(`,,`, `,`);
150
214
  }
151
- // console.log(`-border`, key, v, _parts)
152
215
  v.split(`,`).map((p) => {
153
216
  if (p.includes(`rgb`) || p.includes(`rgba`) || isColor(`#${p}`) || p.startsWith(`$`)) {
154
217
  if (p.includes(`rgb`) || p.includes(`rgba`)) {
@@ -170,13 +233,8 @@ class CSS {
170
233
  }
171
234
  });
172
235
  value = _parts.join(` `);
173
- // console.log(`border`, value)
174
236
  }
175
- /**
176
- * Color
177
- */
178
237
  else if ([`color`, `bg`, `background`, `background-color`, `backgroundColor`].includes(key)) {
179
- // else if ( [`color`].includes( key ) ){
180
238
  if (v.charAt(0) == `#`) {
181
239
  v = v.substring(1);
182
240
  }
@@ -187,17 +245,12 @@ class CSS {
187
245
  else if (v.includes(`rgb`) || v.includes(`rgba`)) {
188
246
  value = v.replace(`[`, `(`).replace(`]`, `)`);
189
247
  }
248
+ else
249
+ value = v.trim();
190
250
  }
191
- /**
192
- * FontWeight
193
- */
194
251
  else if (key == `font-weight`) {
195
252
  value = v;
196
253
  }
197
- /**
198
- * calc
199
- * passed as calc[value]
200
- */
201
254
  else if (v.match(/\[(.*?)\]/g)) {
202
255
  try {
203
256
  const vs = v.match(/\[(.*?)\]/g)[0].slice(1, -1);
@@ -207,19 +260,44 @@ class CSS {
207
260
  catch (e) { }
208
261
  }
209
262
  else {
210
- // ${v.charAt(0) == `$` ? `var(--${v.substring(1)})` : v}
211
- value = `${v}${this.makeUnit(key, v)}`;
263
+ if (v.includes(`,`)) {
264
+ let __v = [];
265
+ v.split(`,`).map((_) => {
266
+ if (_.startsWith(`$`)) {
267
+ __v.push(`var(--${_.substring(1)})`);
268
+ }
269
+ else {
270
+ __v.push(`${_}${this.makeUnit(key, _)}`);
271
+ }
272
+ });
273
+ value = __v.join(` `);
274
+ }
275
+ else
276
+ value = `${v}${this.makeUnit(key, v)}`;
212
277
  }
213
278
  if (!value)
214
279
  return ``;
215
- // if ( key == `background` ) console.log(`makevalue`, key, value)
216
- // if ( key.includes(`border`) ) console.log(`--border`, `${key}: ${value}${important};`)
217
280
  value = value.includes(`,`) && !this.keysWithoutCommaToSpace.includes(key) ? value.replace(`,`, ` `) : value;
218
- // if ( key.includes(`border`) ) console.log(`->border`, `${key}: ${value}${important};`)
281
+ if (key == `content`)
282
+ value = `"${value}"`;
219
283
  return `${key}: ${value}${important};`;
220
284
  }
221
285
  return ``;
222
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
+ }
223
301
  makeID(k, v, _out) {
224
302
  const self = this;
225
303
  const _css = _out.toString().replace(/;|:|\s/g, "");
@@ -235,153 +313,164 @@ class CSS {
235
313
  if (v.toString().indexOf("-") > -1) {
236
314
  v.toString().split("-").map(c => _cp += c.substring(0, 1));
237
315
  }
238
- 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;
239
319
  }
240
- makeIDFromObject(key, obj) {
320
+ lexer(line) {
241
321
  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]);
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;
337
+ }
338
+ else {
339
+ let _keyWord = `${word}${_kw}`.trim();
340
+ if (word.includes(`:`)) {
341
+ const [key, value] = word.split(`:`);
342
+ const _kk = key in self.propCounter ? ++self.propCounter[key] : self.propCounter[key] = 1;
343
+ _keyWord = `${key}${_kk}${value}`.trim();
253
344
  }
254
- });
345
+ classes = setDeep(classes, `${levels.join(`^`)}${levels.length > 0 ? `^` : ``}${word}`, word, `^`);
346
+ }
347
+ word = ``;
255
348
  };
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));
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();
263
358
  }
264
- if (ot.indexOf("-") > -1) {
265
- ot.split("-").map((c) => _cp += c.substring(0, 1));
359
+ else {
360
+ if ([`&`].includes(char)) {
361
+ isLevel = true;
362
+ }
363
+ else if ([`(`].includes(char) && isLevel) {
364
+ processWord();
365
+ }
366
+ else if ([`)`].includes(char)) {
367
+ processWord();
368
+ levels.splice(-1, 1);
369
+ isLevel = false;
370
+ }
371
+ else {
372
+ word += char;
373
+ if (char == `[`)
374
+ hasBracket = true;
375
+ if (char == `]` && hasBracket)
376
+ hasBracket = false;
377
+ }
266
378
  }
267
- }
268
- return `${_cp}${self.hashids.encode(_indices)}`.replace(/\s/g, '-');
379
+ });
380
+ if (word != ``)
381
+ processWord();
382
+ return classes;
269
383
  }
270
- parseRawLine(line) {
384
+ processLine(line) {
271
385
  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]);
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 };
281
399
  }
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}`;
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(`,`);
298
410
  }
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;
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 };
305
443
  }
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
444
  }
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);
445
+ else if (_k in self.DIRECT) {
446
+ const _out = self.DIRECT[_k];
447
+ const _id = self.makeID(_k, _k + pseudo, _out);
343
448
  if (pseudo == ``)
344
449
  self.cx.push(_id);
345
450
  return { [_id]: _out };
346
451
  }
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) };
452
+ else if (_k.trim().match(/^[a-zA-Z0-9\-]+$/g)) {
453
+ self.cx.push(_k.trim());
362
454
  }
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 _;
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
+ }
383
472
  }
384
- Build(css) {
473
+ Build(css, cli = false) {
385
474
  let self = this;
386
475
  self.cx = [];
387
476
  self.cache = {};
@@ -395,19 +484,42 @@ class CSS {
395
484
  }
396
485
  css.map((arr) => {
397
486
  arr.map((line) => {
398
- self.makeCSS(line);
487
+ self.processLine(line);
399
488
  });
400
489
  });
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 {
490
+ const _cleaned = self.deepClean(self.cache);
491
+ const _ = {
408
492
  cx: self.cx,
409
- sheet: self.getStyleSheet(self.cleanPseudo(self.cache))
493
+ sheet: self.styleSheet(_cleaned)
410
494
  };
495
+ return _;
411
496
  }
412
497
  }
413
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
+ };