aliascss 1.4.7 → 1.5.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/bin/aliascss.js +118 -1
  3. package/dist/aliascss.js +1 -1
  4. package/jestconfig.json +1 -3
  5. package/lib/build/index.js +136 -19
  6. package/lib/classPrinter.d.ts +1 -1
  7. package/lib/classPrinter.js +351 -23
  8. package/lib/compilers/border.js +106 -27
  9. package/lib/compilers/clipPath.js +79 -6
  10. package/lib/compilers/color.js +150 -21
  11. package/lib/compilers/filter.js +90 -3
  12. package/lib/compilers/font.js +39 -11
  13. package/lib/compilers/gradient.js +43 -27
  14. package/lib/compilers/length.js +34 -9
  15. package/lib/compilers/shadow.js +60 -26
  16. package/lib/compilers/stringAndContent.js +39 -2
  17. package/lib/compilers/timingFunction.js +57 -6
  18. package/lib/compilers/transform.js +118 -48
  19. package/lib/compilers/transition.js +79 -11
  20. package/lib/compilers/url.js +53 -3
  21. package/lib/config.d.ts +1 -0
  22. package/lib/config.js +1 -0
  23. package/lib/custom-css-compilers.js +1 -68
  24. package/lib/index.d.ts +9 -9
  25. package/lib/node/compileFile-BK-291026.d.ts +27 -0
  26. package/lib/node/compileFile-BK-291026.js +309 -0
  27. package/lib/node/compileFile-bk.d.ts +14 -12
  28. package/lib/node/compileFile-bk.js +263 -252
  29. package/lib/node/compileFile.js +1 -1
  30. package/lib/node/extractClassNamesFromFile.js +208 -86
  31. package/lib/prebuild.d.ts +26 -0
  32. package/lib/prebuild.js +0 -6
  33. package/lib/prefix/element-selector.js +93 -20
  34. package/lib/prefix/extractPrefix.d.ts +1 -1
  35. package/lib/prefix/extractPrefix.js +113 -70
  36. package/lib/returnPropertyAndValue-bk-301026.d.ts +30 -0
  37. package/lib/returnPropertyAndValue-bk-301026.js +219 -0
  38. package/lib/returnPropertyAndValue.js +26 -25
  39. package/lib/returnStatement-bk-291026.d.ts +5 -0
  40. package/lib/returnStatement-bk-291026.js +470 -0
  41. package/lib/returnStatement.d.ts +1 -0
  42. package/lib/returnStatement.js +120 -29
  43. package/lib/utils/helper.js +16 -2
  44. package/lib/x-classes/x-bundle.d.ts +26 -0
  45. package/lib/x-classes/x-bundle.js +2 -1
  46. package/lib/x-classes/x-extras.js +1 -1
  47. package/lib/x-classes/x-form-components.js +2 -1
  48. package/lib/x-classes/x-row-col.d.ts +29 -0
  49. package/lib/x-classes/x-row-col.js +52 -0
  50. package/llms.txt +326 -0
  51. package/package.json +3 -1
  52. package/tsconfig.json +1 -0
  53. package/tsconfig.test.json +10 -0
package/jestconfig.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "transform": {
3
- "^.+\\.(t|j)sx?$": "ts-jest"
3
+ "^.+\\.(t|j)sx?$": ["ts-jest", { "tsconfig": "tsconfig.test.json" }]
4
4
  },
5
5
  "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6
6
  "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
7
7
  "resolver": "jest-ts-webcompat-resolver"
8
-
9
8
  }
10
-
@@ -41,31 +41,148 @@ if (!window.AliasCSS) {
41
41
  window.AliasCSS = AliasCSS;
42
42
  }
43
43
  (() => {
44
- const runScript = () => {
45
- AliasCSS.classPrinter.run();
44
+ const printer = AliasCSS.classPrinter;
45
+ // Watch the whole document (not just <body>): class changes on <html>, such as a
46
+ // dark-mode toggle, are picked up too.
47
+ const OPTIONS = { childList: true, subtree: true, attributes: true };
48
+ // Attributes AliasCSS reads: class, class:group / class-group, keyframes-name, data-raw-css
49
+ const RELEVANT_ATTR = /^(class|keyframes[-_:]|data-raw-css$)/;
50
+ const rawDone = new Set();
51
+ const addRawCSS = (el) => {
52
+ const raw = el.getAttribute('data-raw-css');
53
+ if (raw && !rawDone.has(raw)) {
54
+ rawDone.add(raw);
55
+ printer.appendToStyleTag(raw);
56
+ }
57
+ };
58
+ // Compile a single element: class, class groups, keyframes, raw CSS
59
+ const compileOne = (el) => {
60
+ // keyframes names keep their case (attribute names are lowercased by the browser)
61
+ for (const attr of el.attributes) {
62
+ const m = attr.name.match(/^keyframes[-_:](.+)$/i);
63
+ if (m && !printer.kfNames[m[1].toLowerCase()])
64
+ printer.kfNames[m[1].toLowerCase()] = m[1];
65
+ }
66
+ printer.print(el);
67
+ addRawCSS(el);
68
+ };
69
+ // Compile an added element and everything inside it. Only new/changed nodes are
70
+ // scanned, instead of re-running the whole page on every mutation.
71
+ const scan = (root) => {
72
+ compileOne(root);
73
+ root.querySelectorAll('*').forEach(compileOne);
74
+ root.querySelectorAll('template').forEach((t) => t.content.querySelectorAll('*').forEach(compileOne));
46
75
  };
47
- // 1. Run after initial DOM is ready
76
+ const start = () => {
77
+ printer.run(); // first full pass (also fires acss:init)
78
+ const observer = new MutationObserver((mutations) => {
79
+ observer.disconnect(); // our own writes must not trigger another pass
80
+ for (const m of mutations) {
81
+ const target = m.target;
82
+ // skip AliasCSS's own <style id="styleAlias">
83
+ if (printer.styleTag && (target === printer.styleTag || printer.styleTag.contains(target)))
84
+ continue;
85
+ if (m.type === 'attributes') {
86
+ if (m.attributeName && RELEVANT_ATTR.test(m.attributeName))
87
+ compileOne(target); // only this element changed
88
+ }
89
+ else {
90
+ m.addedNodes.forEach((n) => { if (n.nodeType === Node.ELEMENT_NODE)
91
+ scan(n); });
92
+ }
93
+ }
94
+ printer.flush(); // write everything found in this batch at once
95
+ observer.observe(document.documentElement, OPTIONS);
96
+ });
97
+ observer.observe(document.documentElement, OPTIONS);
98
+ };
99
+ // Works with or without `defer`: in <head> without defer, <body> doesn't exist yet,
100
+ // so nothing touches the DOM until it has been parsed.
48
101
  if (document.readyState === 'loading') {
49
- document.addEventListener('DOMContentLoaded', runScript);
102
+ document.addEventListener('DOMContentLoaded', start, { once: true });
50
103
  }
51
104
  else {
52
- runScript(); // DOM already parsed, run immediately
105
+ start();
53
106
  }
54
- // 2. Re-run on every DOM change and attribute change
55
- const observer = new MutationObserver(() => {
56
- observer.disconnect(); // pause to avoid infinite loop
57
- runScript();
58
- observer.observe(document.body, {
59
- childList: true,
60
- subtree: true,
61
- attributes: true,
62
- attributeOldValue: true,
63
- });
107
+ })(); /*
108
+ import statementMaker, { classPrinter } from '../classPrinter.js'
109
+ const AliasCSS = {
110
+ pushURL: null,
111
+ // compile class and returns class statement i.e .br5px{.br5px{border-radius:5px ;}}
112
+ compile(className: string) {
113
+ return this.statementMaker.make(className);
114
+ },
115
+
116
+ print() {
117
+ return this.classPrinter.compile();
118
+ },
119
+ // style="{AliasCSS.inline('fs10px br5px)}"
120
+ // inline(str: string) {
121
+ // return this.statementMaker.groupForStyle(str);
122
+ // },
123
+ run(el: any) {
124
+ if (typeof el === 'string') el = document.querySelector(el);
125
+ if (el && el.toString().includes('HTML')) {
126
+ AliasCSS.classPrinter.run(el);
127
+ }
128
+ },
129
+
130
+
131
+ toString() {
132
+ return 'AliasCSS Object';
133
+ },
134
+ classPrinter,
135
+
136
+ // takes custom className and defination key,value or {key:value} //{'outline-color':'outline-color: blue;'}
137
+ // no Psedu or anythings
138
+ extend(a: any, b: any, c: any) {
139
+ this.statementMaker.prebuild(a, b, c);
140
+ },
141
+
142
+ addCustom(custom: { [key: string]: any }) {
143
+ Object.keys(custom).forEach((key) => {
144
+ this.statementMaker.addCustom(key, custom[key]);
64
145
  });
146
+ },
147
+ statementMaker,
148
+ };
149
+
150
+ // @ts-ignore
151
+ if (!window.AliasCSS) {
152
+ // @ts-ignore
153
+ window.AliasCSS = AliasCSS;
154
+ }
155
+
156
+
157
+ (() => {
158
+ const runScript = () => {
159
+ AliasCSS.classPrinter.run();
160
+ };
161
+
162
+ // 1. Run after initial DOM is ready
163
+ if (document.readyState === 'loading') {
164
+ document.addEventListener('DOMContentLoaded', runScript);
165
+ } else {
166
+ runScript(); // DOM already parsed, run immediately
167
+ }
168
+
169
+ // 2. Re-run on every DOM change and attribute change
170
+ const observer = new MutationObserver(() => {
171
+ observer.disconnect(); // pause to avoid infinite loop
172
+ runScript();
65
173
  observer.observe(document.body, {
66
- childList: true,
67
- subtree: true,
68
- attributes: true,
69
- attributeOldValue: true,
174
+ childList: true,
175
+ subtree: true,
176
+ attributes: true,
177
+ attributeOldValue: true,
70
178
  });
179
+ });
180
+
181
+ observer.observe(document.body, {
182
+ childList: true,
183
+ subtree: true,
184
+ attributes: true,
185
+ attributeOldValue: true,
186
+ });
71
187
  })();
188
+ */
@@ -1,4 +1,4 @@
1
- import { compiler as statementMaker } from './returnStatement.js';
1
+ import { compiler as statementMaker } from './returnStatement-bk-291026.js';
2
2
  export default statementMaker;
3
3
  type ClassPrinter = {
4
4
  [key: string]: any;
@@ -1,11 +1,14 @@
1
- import { compiler as statementMaker } from './returnStatement.js';
1
+ import { compiler as statementMaker } from './returnStatement-bk-291026.js';
2
2
  import config from './config.js';
3
3
  import { splitByCommaOutsideParens } from './utils/helper.js';
4
4
  // import mapRawAttributeNames from './utils/browser-helper.js';
5
5
  export default statementMaker;
6
6
  export let classPrinter = {
7
- invalidLists: [],
8
- classLists: [],
7
+ invalidLists: new Set(), // was arrays + indexOf: O(n) per lookup
8
+ classLists: new Set(),
9
+ doneGroups: new Set(), // class:name="…" groups already emitted
10
+ buffer: [], // CSS waiting to be written
11
+ flushQueued: false,
9
12
  styleTagExists: false,
10
13
  customCheck: false,
11
14
  useColon: true,
@@ -21,16 +24,34 @@ export let classPrinter = {
21
24
  styleTag.id = 'styleAlias';
22
25
  document.getElementsByTagName('head')[0].appendChild(styleTag);
23
26
  // initialize @layer for reset, base, theme, components and utilities
24
- const initLayer = document.createTextNode(`@layer ${config.layers.join(', ')};`);
27
+ // [hidden] must win over any class that sets display (x-stack, d-flex…). !important in the
28
+ // first layer beats every later layer and unlayered CSS; until-found keeps its own behaviour.
29
+ const initLayer = document.createTextNode(`@layer ${config.layers.join(', ')};\n@layer reset{[hidden]:not([hidden="until-found"]){display:none!important}}`);
25
30
  styleTag.appendChild(initLayer);
26
31
  this.styleTag = styleTag;
27
32
  this.styleTagExists = true;
28
33
  return styleTag;
29
34
  },
30
35
  // you can always append a class if you like modify the look here if you want
36
+ // Buffered: every append used to add a text node, and each one makes the browser
37
+ // re-parse the whole <style> (slow on big pages). Now statements are collected and
38
+ // written in one text node per microtask: still before the next paint, so no flash.
31
39
  appendToStyleTag(classStatement) {
32
- const createNewClass = document.createTextNode(classStatement);
33
- this.createStyleTag().appendChild(createNewClass);
40
+ if (!classStatement)
41
+ return;
42
+ this.buffer.push(classStatement);
43
+ if (!this.flushQueued) {
44
+ this.flushQueued = true;
45
+ queueMicrotask(() => this.flush());
46
+ }
47
+ },
48
+ flush() {
49
+ this.flushQueued = false;
50
+ if (!this.buffer.length)
51
+ return;
52
+ const css = this.buffer.join('\n');
53
+ this.buffer = [];
54
+ this.createStyleTag().appendChild(document.createTextNode(css));
34
55
  },
35
56
  // compile dom stylesheet
36
57
  // show current style statement
@@ -51,8 +72,8 @@ export let classPrinter = {
51
72
  print(el) {
52
73
  // initialize class or acss-class value container
53
74
  let attrValue = '';
54
- const testRegExp = this.useColon ? /class[-_:]/ : /class[-_]/;
55
- const testRegExpKF = this.useColon ? /keyframes[-_:]/ : /keyframes[-_]/;
75
+ const testRegExp = this.useColon ? /^class[-_:]/ : /^class[-_]/;
76
+ const testRegExpKF = this.useColon ? /^keyframes[-_:]/ : /^keyframes[-_]/;
56
77
  // const rawCSS=/data-raw-css/;
57
78
  // if class
58
79
  if (el.getAttribute('class'))
@@ -72,10 +93,12 @@ export let classPrinter = {
72
93
  group = group.replace(match[0], '');
73
94
  value = value.trim().split(/\s+/).map(e => match[0].replace(/^\[/, '').replace(/\]$/, '') + (/^[_-]/.test(e) ? '' : '-') + e).join(" ");
74
95
  }
75
- const result = statementMaker.group(value, group);
76
- if (result) {
77
- this.appendToStyleTag(result);
78
- // return true;
96
+ const key = group + '\u0000' + value;
97
+ if (!this.doneGroups.has(key)) {
98
+ this.doneGroups.add(key);
99
+ const result = statementMaker.group(value, group);
100
+ if (result)
101
+ this.appendToStyleTag(result);
79
102
  }
80
103
  }
81
104
  // -------
@@ -133,9 +156,9 @@ export let classPrinter = {
133
156
  // looping class
134
157
  tmpClassList.forEach((eachClass) => {
135
158
  // escape repeated class name
136
- if (this.classLists.indexOf(eachClass) === -1 && this.invalidLists.indexOf(eachClass) === -1) {
159
+ if (!this.classLists.has(eachClass) && !this.invalidLists.has(eachClass)) {
137
160
  // add to classlist for reference
138
- this.classLists.push(eachClass);
161
+ this.classLists.add(eachClass);
139
162
  // var result=compiler.main(eachClass);
140
163
  const result = statementMaker.make(eachClass);
141
164
  // console.log(result);
@@ -144,7 +167,7 @@ export let classPrinter = {
144
167
  }
145
168
  else {
146
169
  // not a valid ACSS classNames
147
- this.invalidLists.push(eachClass);
170
+ this.invalidLists.add(eachClass);
148
171
  }
149
172
  }
150
173
  });
@@ -155,7 +178,7 @@ export let classPrinter = {
155
178
  let statement = ' ';
156
179
  // initialize class or acss-class value container
157
180
  let attrValue = '';
158
- const testRegExp = this.useColon ? /class[-_:]/ : /class[-_]/;
181
+ const testRegExp = this.useColon ? /^class[-_:]/ : /^class[-_]/;
159
182
  // matchRegExp:/(?:(class|className|class[-_][\w-\[\]=_]+))=[\s*]?(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/,
160
183
  // matchRegExpWithColon:/(?:(class|className|class[-_:][\w-\[\]=_]+))=[\s*]?(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/,
161
184
  // if class
@@ -197,10 +220,6 @@ export let classPrinter = {
197
220
  statement += result + ' ';
198
221
  // this.appendToStyleTag(result);
199
222
  }
200
- else {
201
- // not a valid ACSS classNames
202
- console.log('Not a valid Aliascss class name:' + eachClass);
203
- }
204
223
  }
205
224
  });
206
225
  return statement;
@@ -228,7 +247,6 @@ export let classPrinter = {
228
247
  return statement;
229
248
  },
230
249
  run(el) {
231
- var _a;
232
250
  const $root = el || document;
233
251
  // $root.dispatchEvent(event);
234
252
  $root.dispatchEvent(new CustomEvent('acss:init', { bubbles: true, detail: { aliascss: this } }));
@@ -241,8 +259,16 @@ export let classPrinter = {
241
259
  // });
242
260
  // const event = new Event('acss:init');
243
261
  // create a keyframes object to fix case-sensitive issue
244
- (_a = (el || document.body).outerHTML.match(/keyframes-[a-z0-9_-]+(?==)/gi)) === null || _a === void 0 ? void 0 : _a.forEach((each) => {
245
- this.kfNames[each.replace('keyframes-', '').toLowerCase()] = each.replace('keyframes-', '');
262
+ // (was: outerHTML of the whole page + regex, which serialises the entire document)
263
+ const kfRoot = (el || document.body);
264
+ const kfNodes = [kfRoot, ...kfRoot.querySelectorAll('*')];
265
+ kfRoot.querySelectorAll('template').forEach((t) => kfNodes.push(...t.content.querySelectorAll('*')));
266
+ kfNodes.forEach((node) => {
267
+ for (const attr of node.attributes) {
268
+ const m = attr.name.match(/^keyframes[-_:](.+)$/i);
269
+ if (m)
270
+ this.kfNames[m[1].toLowerCase()] = m[1];
271
+ }
246
272
  });
247
273
  // <template> element
248
274
  Array.prototype.forEach.call($root.querySelectorAll('template'), (template) => {
@@ -262,5 +288,307 @@ export let classPrinter = {
262
288
  Array.prototype.forEach.call($root.querySelectorAll('[data-raw-css]'), (e) => {
263
289
  this.appendToStyleTag(e.getAttribute('data-raw-css'));
264
290
  });
291
+ this.flush(); // write the whole first pass in one go
265
292
  },
266
293
  };
294
+ /*
295
+ import { compiler as statementMaker} from './returnStatement.js';
296
+ import config from './config.js';
297
+ import { splitByCommaOutsideParens} from './utils/helper.js';
298
+ // import mapRawAttributeNames from './utils/browser-helper.js';
299
+ export default statementMaker;
300
+ type ClassPrinter = { [key: string]: any };
301
+ export let classPrinter: ClassPrinter = {
302
+ invalidLists: [],
303
+ classLists: [],
304
+ styleTagExists: false,
305
+ customCheck: false,
306
+ useColon:true,
307
+ cls: {},
308
+ kfs: {},
309
+ kfNames:{},
310
+
311
+ styleTag: null,
312
+ createStyleTag() {
313
+ if (this.styleTagExists === true) {
314
+ return this.styleTag;
315
+ }
316
+ const styleTag = document.createElement('style');
317
+ styleTag.id = 'styleAlias';
318
+ document.getElementsByTagName('head')[0].appendChild(styleTag);
319
+ // initialize @layer for reset, base, theme, components and utilities
320
+ const initLayer = document.createTextNode(
321
+ `@layer ${config.layers.join(', ')};`
322
+ );
323
+ styleTag.appendChild(initLayer);
324
+ this.styleTag = styleTag;
325
+ this.styleTagExists = true;
326
+ return styleTag;
327
+ },
328
+ // you can always append a class if you like modify the look here if you want
329
+ appendToStyleTag(classStatement: string) {
330
+ const createNewClass = document.createTextNode(classStatement);
331
+ this.createStyleTag().appendChild(createNewClass);
332
+ },
333
+ // compile dom stylesheet
334
+ // show current style statement
335
+ compile() {
336
+ const classes = document.getElementById('styleAlias');
337
+ if (classes) {
338
+ const prettyPrint = classes.innerHTML
339
+ .replace(/\}/g, '</br>}</br>')
340
+ .replace(/\{/g, '{</br>&nbsp;&nbsp;&nbsp;&nbsp;');
341
+ document.write(prettyPrint);
342
+ } else {
343
+ console.warn('There is not ACSS used in this document!!');
344
+ alert('Could not found acss statements in this Document!');
345
+ }
346
+ },
347
+
348
+ // print className of el to style tag; gets statement from statementMaker.make(eachClass);
349
+ print(el: HTMLElement) {
350
+
351
+ // initialize class or acss-class value container
352
+ let attrValue = '';
353
+ const testRegExp=this.useColon? /class[-_:]/: /class[-_]/;
354
+ const testRegExpKF=this.useColon? /keyframes[-_:]/: /keyframes[-_]/;
355
+ // const rawCSS=/data-raw-css/;
356
+
357
+ // if class
358
+ if (el.getAttribute('class')) attrValue += ' ' + el.getAttribute('class');
359
+
360
+ // if acss-class
361
+ // if (el.getAttribute('acss-class')) attrValue += ' ' + el.getAttribute('acss-class');
362
+ // new Update
363
+ [...el.attributes].map((each)=>{
364
+ // ------------
365
+ // Raw-CSS Statement
366
+
367
+ // class-group
368
+ if( testRegExp.test(each.name)){
369
+ let value=each.value;
370
+ let group=each.name.replace(testRegExp,'');
371
+ const match=group.match(/\[(.)+\]/);
372
+ if(match){
373
+ group=group.replace(match[0],'');
374
+ value=value.trim().split(/\s+/).map(e=>match[0].replace(/^\[/,'').replace(/\]$/,'')+(/^[_-]/.test(e)?'':'-')+e).join(" ");
375
+ }
376
+ const result = statementMaker.group(value, group);
377
+ if (result) {
378
+ this.appendToStyleTag(result);
379
+ // return true;
380
+ }
381
+ }
382
+ // -------
383
+ // if( testRegExp.test(each.name)){
384
+ // const result = statementMaker.group(each.value, each.name.replace(testRegExp,''));
385
+ // if (result) {
386
+ // this.appendToStyleTag(result);
387
+ // // return true;
388
+ // }
389
+ // }
390
+ if( testRegExpKF.test(each.name)){
391
+ const key=each.name.replace(testRegExpKF,'');
392
+ let kfStatement='@keyframes '+ this.kfNames[key] +"{\n";
393
+ const returnPnV=(e:string[])=>e.map((i)=>statementMaker.make(i,undefined,true)).join(";");
394
+ const split=each.value.trim().split(/\s+/);
395
+ split.forEach((each:string) => {
396
+ try {
397
+ const[at,pNv]=each.replace(/\]\[/,']-[').replace("-","=").split("=");
398
+ // const result=returnPnV(pNv.replace(/^\[|\]$/g,'').split(','));
399
+ const result=returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g,'')));
400
+ kfStatement+=` ${at.replace('@','').replace(/:/g,',').replace(/,/g,"%,").replace(/[\[|\]]/g,'')}% {${result?result:''}}`
401
+ } catch (error) {
402
+ console.log('invalid Entry for AliasCSS keyframes processor : '+each,error);
403
+ }
404
+
405
+ });
406
+ this.appendToStyleTag(kfStatement+ "\n}");
407
+ }
408
+
409
+ })
410
+
411
+ // if has value to process
412
+ if (!attrValue.trim()) return;
413
+
414
+ // has-test-group(for live update only)
415
+ /* if (el.getAttribute('acss-group-test')) {
416
+ const result = statementMaker.group(attrValue, el.getAttribute('acss-group-test')||'');
417
+ const styleTag = document.querySelector('style#' + el.getAttribute('acss-group-test'));
418
+ if (result) {
419
+ if (styleTag) {
420
+ styleTag.innerHTML = '';
421
+ const createNewGroup = document.createTextNode(result);
422
+ styleTag.appendChild(createNewGroup);
423
+ // return true;
424
+ } else {
425
+ const styleTag: any = document.createElement('style');
426
+ styleTag.id = el.getAttribute('acss-group-test');
427
+ document.getElementsByTagName('head')[0].appendChild(styleTag);
428
+ const createNewGroup = document.createTextNode(result);
429
+ styleTag.appendChild(createNewGroup);
430
+ }
431
+ }
432
+ } */
433
+ // -----------------------end of for live update
434
+ /*
435
+ // get class and trim out white spaces
436
+ const tmpClassList = attrValue.trim().split(/\s+/);
437
+
438
+ // looping class
439
+ tmpClassList.forEach((eachClass: string) => {
440
+ // escape repeated class name
441
+
442
+ if (this.classLists.indexOf(eachClass) === -1 && this.invalidLists.indexOf(eachClass) === -1) {
443
+ // add to classlist for reference
444
+ this.classLists.push(eachClass);
445
+
446
+ // var result=compiler.main(eachClass);
447
+ const result = statementMaker.make(eachClass);
448
+ // console.log(result);
449
+
450
+ if (result) {
451
+ this.appendToStyleTag(result);
452
+ } else {
453
+ // not a valid ACSS classNames
454
+ this.invalidLists.push(eachClass);
455
+ }
456
+ }
457
+ });
458
+ }, // end-of-main
459
+ // returns css statement from current element
460
+ compileElement(el: HTMLElement, list: [] = []) {
461
+ const classList: string[] = list;
462
+ let statement = ' ';
463
+ // initialize class or acss-class value container
464
+ let attrValue = '';
465
+ const testRegExp=this.useColon? /class[-_:]/: /class[-_]/;
466
+ // matchRegExp:/(?:(class|className|class[-_][\w-\[\]=_]+))=[\s*]?(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/,
467
+ // matchRegExpWithColon:/(?:(class|className|class[-_:][\w-\[\]=_]+))=[\s*]?(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/,
468
+
469
+ // if class
470
+ if (el.getAttribute('class')) attrValue += ' ' + el.getAttribute('class');
471
+ // New update 2023-aug-03
472
+
473
+ [...el.attributes].map((each)=>{
474
+
475
+ if( testRegExp.test(each.name)){
476
+ let value=each.value;
477
+ let group=each.name.replace(testRegExp,'');
478
+ const match=group.match(/\[(.)+\]/);
479
+ if(match){
480
+ group=group.replace(match[0],'');
481
+ value=value.trim().split(/\s+/).map(e=>match[0].replace(/^\[/,'').replace(/\]$/,'')+(/^[_-]/.test(e)?'':'-')+e).join(" ");
482
+ }
483
+ const result = statementMaker.group(value, group);
484
+ if (result) {
485
+ this.appendToStyleTag(result);
486
+ // return true;
487
+ }
488
+ }
489
+
490
+ })
491
+ // if acss-class
492
+ // if (el.getAttribute('acss-class')) attrValue += ' ' + el.getAttribute('acss-class');
493
+
494
+ // if has value to process
495
+ if (!attrValue.trim()) return;
496
+
497
+ // get class and trim out whitespace
498
+ const tmpClassList = attrValue.trim().split(/\s+/);
499
+
500
+ // looping class
501
+ tmpClassList.forEach((eachClass) => {
502
+ // escape repeated className
503
+ if (classList.indexOf(eachClass) === -1) {
504
+ classList.push(eachClass);
505
+ // var result=compiler.main(eachClass);
506
+ const result = statementMaker.make(eachClass);
507
+ // console.log(result);
508
+
509
+ if (result) {
510
+ statement += result + ' ';
511
+ // this.appendToStyleTag(result);
512
+ } else {
513
+ // not a valid ACSS classNames
514
+ console.log('Not a valid Aliascss class name:' + eachClass);
515
+ }
516
+ }
517
+ });
518
+
519
+ return statement;
520
+ },
521
+ // returns css statement from given element and child
522
+ returnStatement($el: HTMLElement) {
523
+ let statement = '';
524
+ const classList: [] = [];
525
+ const processOuterHtml= this.compileElement($el, classList);
526
+ statement+=processOuterHtml ? processOuterHtml : '';
527
+
528
+ // <template> element
529
+ Array.prototype.forEach.call($el.querySelectorAll('template'), (template) => {
530
+ // Array.prototype.forEach.call(template.content.querySelectorAll('[class],[acss-class]'), (e) => {
531
+ Array.prototype.forEach.call(template.content.querySelectorAll('[class]'), (e) => {
532
+ const result = this.compileElement(e, classList);
533
+ statement += result ? result : '';
534
+ });
535
+ });
536
+
537
+ // <html>
538
+
539
+ // Array.prototype.forEach.call($el.querySelectorAll('[class],[acss-class]'), (e) => {
540
+ Array.prototype.forEach.call($el.querySelectorAll('[class]'), (e) => {
541
+ const result = this.compileElement(e, classList);
542
+ statement += result ? result : '';
543
+ });
544
+
545
+ return statement;
546
+ },
547
+ run(el: HTMLElement) {
548
+ const $root = el || document;
549
+
550
+ // $root.dispatchEvent(event);
551
+ $root.dispatchEvent(new CustomEvent('acss:init', { bubbles: true , detail:{aliascss:this}}));
552
+ // mapRawAttributeNames().then(({ kfs, cls }) => {
553
+ // // Use the variables inside this block
554
+ // this.cls = cls;
555
+ // this.kfs = kfs;
556
+ // }).catch(error => {
557
+ // console.error("cannot initialize keyframes and class-grouping for case free names:", error);
558
+ // });
559
+
560
+ // const event = new Event('acss:init');
561
+
562
+
563
+
564
+ // create a keyframes object to fix case-sensitive issue
565
+ (el||document.body).outerHTML.match(/keyframes-[a-z0-9_-]+(?==)/gi)?.forEach((each)=>{
566
+ this.kfNames[each.replace('keyframes-','').toLowerCase()]=each.replace('keyframes-','');
567
+
568
+ })
569
+
570
+
571
+
572
+ // <template> element
573
+ Array.prototype.forEach.call($root.querySelectorAll('template'), (template) => {
574
+ // Array.prototype.forEach.call(template.content.querySelectorAll('[class],[acss-class]'), (e) => {
575
+ Array.prototype.forEach.call(template.content.querySelectorAll('[class]'), (e) => {
576
+ this.print(e);
577
+ });
578
+ Array.prototype.forEach.call(template.content.querySelectorAll('[data-raw-css]'), (e) => {
579
+ this.appendToStyleTag(e.getAttribute('data-raw-css'));
580
+ });
581
+ });
582
+
583
+ // <html>
584
+
585
+ // Array.prototype.forEach.call($root.querySelectorAll('[class],[acss-class]'), (e) => {
586
+ Array.prototype.forEach.call($root.querySelectorAll('[class]'), (e) => {
587
+ this.print(e);
588
+ });
589
+ Array.prototype.forEach.call($root.querySelectorAll('[data-raw-css]'), (e) => {
590
+ this.appendToStyleTag(e.getAttribute('data-raw-css'));
591
+ });
592
+ },
593
+
594
+ };*/