aliascss 1.4.5 → 1.5.0

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 (75) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bin/aliascss.js +118 -1
  3. package/dist/aliascss.js +1 -1
  4. package/lib/classPrinter.js +347 -21
  5. package/lib/compilers/color.js +5 -5
  6. package/lib/compilers/gradient.js +3 -3
  7. package/lib/compilers/stringAndContent.js +2 -1
  8. package/lib/component-elements.d.ts +155 -0
  9. package/lib/component-elements.js +223 -0
  10. package/lib/config.d.ts +2 -0
  11. package/lib/config.js +3 -1
  12. package/lib/css-properties-all.js +337 -202
  13. package/lib/custom-css-compilers.js +49 -116
  14. package/lib/extras-elements.d.ts +87 -0
  15. package/lib/extras-elements.js +184 -0
  16. package/lib/form-elements.d.ts +75 -0
  17. package/lib/form-elements.js +186 -0
  18. package/lib/layout-elements.d.ts +59 -0
  19. package/lib/layout-elements.js +113 -0
  20. package/lib/nav-elements.d.ts +71 -0
  21. package/lib/nav-elements.js +243 -0
  22. package/lib/node/compileFile-BK-291026.d.ts +27 -0
  23. package/lib/node/compileFile-BK-291026.js +309 -0
  24. package/lib/node/compileFile-bk.d.ts +14 -12
  25. package/lib/node/compileFile-bk.js +263 -252
  26. package/lib/node/compileFile.js +1 -1
  27. package/lib/node/extractClassNamesFromFile.js +208 -86
  28. package/lib/prebuild.d.ts +546 -12
  29. package/lib/prebuild.js +3 -852
  30. package/lib/prefix/PseudoPrefixNew.js +301 -16
  31. package/lib/prefix/attribute-selector.js +4 -2
  32. package/lib/prefix/element-selector.js +93 -20
  33. package/lib/prefix/extractPrefix.d.ts +1 -1
  34. package/lib/prefix/extractPrefix.js +113 -70
  35. package/lib/prefix/pseudoSelectorNew.js +184 -49
  36. package/lib/prefix/responsive.d.ts +13 -9
  37. package/lib/prefix/responsive.js +131 -9
  38. package/lib/returnPropertyAndValue.js +9 -4
  39. package/lib/returnStatement-bk-291026.d.ts +5 -0
  40. package/lib/returnStatement-bk-291026.js +470 -0
  41. package/lib/returnStatement-bk.d.ts +5 -0
  42. package/lib/returnStatement-bk.js +311 -0
  43. package/lib/returnStatement.d.ts +1 -0
  44. package/lib/returnStatement.js +262 -12
  45. package/lib/static/customStaticClassNames.js +35 -35
  46. package/lib/static/staticClassNamesAlias.js +18 -16
  47. package/lib/table-elements.d.ts +39 -0
  48. package/lib/table-elements.js +90 -0
  49. package/lib/utils/helper.d.ts +6 -0
  50. package/lib/utils/helper.js +52 -0
  51. package/lib/x-classes/x-bundle.d.ts +589 -0
  52. package/lib/x-classes/x-bundle.js +12 -0
  53. package/lib/x-classes/x-comps.d.ts +87 -0
  54. package/lib/x-classes/x-comps.js +189 -0
  55. package/lib/x-classes/x-extras.d.ts +155 -0
  56. package/lib/x-classes/x-extras.js +223 -0
  57. package/lib/x-classes/x-form-components.d.ts +75 -0
  58. package/lib/x-classes/x-form-components.js +186 -0
  59. package/lib/x-classes/x-helper-components.d.ts +63 -0
  60. package/lib/x-classes/x-helper-components.js +91 -0
  61. package/lib/x-classes/x-layout-components.d.ts +59 -0
  62. package/lib/x-classes/x-layout-components.js +113 -0
  63. package/lib/x-classes/x-menu.d.ts +23 -0
  64. package/lib/x-classes/x-menu.js +55 -0
  65. package/lib/x-classes/x-navs.d.ts +71 -0
  66. package/lib/x-classes/x-navs.js +243 -0
  67. package/lib/x-classes/x-row-col.d.ts +29 -0
  68. package/lib/x-classes/x-row-col.js +52 -0
  69. package/lib/x-classes/x-table.d.ts +39 -0
  70. package/lib/x-classes/x-table.js +90 -0
  71. package/lib/x-classes/x-theme.d.ts +15 -0
  72. package/lib/x-classes/x-theme.js +32 -0
  73. package/lib/x-imports.d.ts +31 -0
  74. package/lib/x-imports.js +748 -0
  75. package/package.json +1 -1
@@ -0,0 +1,311 @@
1
+ import getPropertyAndValue from "./returnPropertyAndValue.js";
2
+ import { customStaticClassNames } from "./static/customStaticClassNames.js";
3
+ import media, { createRegexForMedia } from "./prefix/responsive.js";
4
+ import { customColors } from './static/customColors.js';
5
+ import { customColorsRa } from './static/customColorsRA.js';
6
+ // import {customColors as customColors2} from './static/customColors2.js'
7
+ import { customColorsRadixUi } from './static/customColorsRadix.js';
8
+ import extractPrefix from './prefix/extractPrefix.js';
9
+ import extractMediaPrefix from './prefix/extractMediaPrefix.js';
10
+ import { createCompilerObj, extractProperty } from "./utils/createCompilerObj.js";
11
+ import config from "./config.js";
12
+ import cssProps from "./css-properties-all.js";
13
+ import { staticClassNamesAlias } from "./static/staticClassNamesAlias.js";
14
+ import postcss from "postcss";
15
+ import { splitByCommaOutsideParens } from "./utils/helper.js";
16
+ import cssCustomCompilers from "./custom-css-compilers.js";
17
+ // import customGroups from './prebuild.js';
18
+ const [staticClassNamesWithAlias, cssPropsWithAlias] = createCompilerObj(cssProps, config.globalValues);
19
+ export const compiler = {
20
+ // cache will cache propertyAndValue
21
+ cache: { propertyAndValue: Object.assign({}, customStaticClassNames) },
22
+ // custom:{...{colors:{...customColors,...customColors2,...customColorsRadix}}},
23
+ custom: Object.assign({ colors: Object.assign(Object.assign(Object.assign({}, customColors), customColorsRadixUi), customColorsRa) }),
24
+ mediaSelector: Object.assign({}, media.target),
25
+ mediaTest: null,
26
+ staticClassNames: Object.assign(Object.assign({}, staticClassNamesAlias), staticClassNamesWithAlias),
27
+ cssProps: Object.assign(Object.assign({}, cssPropsWithAlias), cssCustomCompilers),
28
+ prefix: null,
29
+ rawCSS: null,
30
+ customGroupStatement: null,
31
+ extend(data) {
32
+ Object.keys(data).forEach((key) => {
33
+ if (data[key].hasOwnProperty('extend')) {
34
+ if (cssProps.hasOwnProperty(data[key].extend)) {
35
+ Object.keys(cssProps[data[key].extend]).forEach((each) => {
36
+ if (each === 'values') {
37
+ data[key].values = [...cssProps[data[key].extend].values || [], ...data[key].values || []];
38
+ }
39
+ else if (each === 'compiler') {
40
+ data[key].compiler = cssProps[data[key].extend].compiler;
41
+ }
42
+ });
43
+ }
44
+ }
45
+ });
46
+ const [staticClassNames, compiler] = createCompilerObj(data, config.globalValues);
47
+ this.cssProps = Object.assign(Object.assign({}, this.cssProps), compiler);
48
+ this.staticClassNames = Object.assign(Object.assign({}, this.staticClassNames), staticClassNames);
49
+ },
50
+ // className as another-name, bool->only return property and value
51
+ make(className, as, bool) {
52
+ var _a;
53
+ // --Group Statement
54
+ if (this.cssProps.hasOwnProperty(className)) {
55
+ if (this.cssProps[className].hasOwnProperty('type') && (this.cssProps[className].type === 'statement')) {
56
+ return this.group(this.cssProps[className].statement, className);
57
+ }
58
+ if (this.cssProps[className].hasOwnProperty('type') && (this.cssProps[className].type === 'raw')) {
59
+ return this.cssProps[className].statement;
60
+ }
61
+ }
62
+ if (/--as-[a-zA-Z0-9-_]+$/.test(className)) {
63
+ const asMatch = (_a = className.match(/--as-([a-zA-Z0-9-_]+)$/)) !== null && _a !== void 0 ? _a : [null, null];
64
+ if (asMatch[0] && asMatch[1]) {
65
+ return this.group(className.replace(asMatch[0], ''), asMatch[1]);
66
+ }
67
+ }
68
+ let unPrefixedClassName = className;
69
+ // check for [group-acss,]
70
+ const matchGroupCSS = className.match(/\[([^[]*)\]$/);
71
+ if (matchGroupCSS) {
72
+ const asString = splitByCommaOutsideParens(matchGroupCSS[1])
73
+ // .split(',')
74
+ .map(e => (className.replace(matchGroupCSS[0], '') + "-").replace(/--$/, '-') + e.replace(/^--/, '-'))
75
+ .join(' ');
76
+ return this.group(asString, as ? as : className);
77
+ }
78
+ //
79
+ let beforeClassNameSelector = '';
80
+ if (this.prefix && !className.match(new RegExp('^' + this.prefix + "[-]"))) {
81
+ return null;
82
+ }
83
+ else if (this.prefix) {
84
+ unPrefixedClassName = className.replace(new RegExp('^' + this.prefix + "[-]"), '');
85
+ }
86
+ if (!this.mediaTest)
87
+ this.mediaTest = createRegexForMedia(this.mediaSelector);
88
+ // 1. check and extract Media prefix and return className with prefix treatment,
89
+ let [extractedMedia, workingClassName] = extractMediaPrefix(unPrefixedClassName, this.mediaSelector, this.mediaTest);
90
+ const mediaEX = extractedMedia;
91
+ // lint escape for const
92
+ extractedMedia = extractedMedia;
93
+ // 2. search for '&' which tells us to use selector before or after className
94
+ if (workingClassName.match(/[&]/)) {
95
+ const [before, after] = workingClassName.split('&');
96
+ beforeClassNameSelector = extractPrefix(before + "-display-none")[0] + " ";
97
+ if (!beforeClassNameSelector.trim()) {
98
+ console.error('Not a valid AliasCSS className:' + className, 'Make sure to provide valid css aliascss selector before "&" identifier');
99
+ return null;
100
+ }
101
+ else {
102
+ beforeClassNameSelector = beforeClassNameSelector.replace(/^([\s]?[+~>])(.*)/, "$2$1 ");
103
+ }
104
+ workingClassName = workingClassName.replace(before, '').replace('&', '');
105
+ }
106
+ let [elementAndPseudo, important] = ['', ''];
107
+ // workingClassName=workingClassName.replace(/[_][\.]([a-zA-Z])/g,(s,e)=>"_"+'ACSS').replace(/[.]/g,"d").replace(/[%]/g,'p')
108
+ // 3. Process --important flag
109
+ if (/(-i|--important)$/.test(className)) {
110
+ important = ' !important';
111
+ workingClassName = workingClassName.replace(/(-i|--important)$/, '');
112
+ }
113
+ // 4. process Pseudo State
114
+ const prefixPseudoElementAttribute = extractPrefix(workingClassName);
115
+ workingClassName = prefixPseudoElementAttribute[1];
116
+ elementAndPseudo = prefixPseudoElementAttribute[0];
117
+ // ---------------------------------------------------------------------
118
+ const pnv = workingClassName.replace(/^-([a-zA-Z])/, '$1');
119
+ let result = '';
120
+ // x-class
121
+ // if(/^(x-width|x-height)/.test(pnv)){
122
+ // const extract=getPropertyAndValue(pnv.replace('x-',''), this.cssProps, this.staticClassNames, this.custom,extractProperty);
123
+ // if(typeof extract === 'string'){
124
+ // const [p,v]=extract.split(':');
125
+ // if(p && v){
126
+ // result=`${p}:calc(${v} + var(--x-${p}-grow,0px) - var(--x-${p}-shrink,0px));`
127
+ // }
128
+ // }
129
+ // }else
130
+ if (this.cache.propertyAndValue.hasOwnProperty(pnv)) {
131
+ result = this.cache.propertyAndValue[pnv];
132
+ }
133
+ else {
134
+ try {
135
+ result = getPropertyAndValue(pnv, this.cssProps, this.staticClassNames, this.custom, extractProperty);
136
+ }
137
+ catch (error) {
138
+ console.log(error);
139
+ }
140
+ }
141
+ // if(result){
142
+ // className=className.replace(/([$.&%=\]\[@~:*#+\(\)\/^])/g,'\\$1');
143
+ // if(bool===true) return result;
144
+ // this.cache.propertyAndValue[pnv]=result;
145
+ // if(media){
146
+ // return `${media}{${
147
+ // beforeClassNameSelector+'.'+(as?as:className)+ elementAndPseudo
148
+ // }{${result}${important}}}`;
149
+ // }else{
150
+ // return `${beforeClassNameSelector}.${(as?as:className)}${elementAndPseudo}{${result}${important}}`;
151
+ // }
152
+ // }else{
153
+ // console.log(`Unable to process ${className} [media:${media},pseudoSelector:${elementAndPseudo},imp:${important}]`)
154
+ // }
155
+ // ------------PostCSSParse
156
+ if (result) {
157
+ let stm = '';
158
+ className = (as ? as : className).replace(/([$.&%=\]\[@~,:*#+\(\)\/^/</>])/g, '\\$1');
159
+ if (bool === true)
160
+ return result;
161
+ this.cache.propertyAndValue[pnv] = result;
162
+ if (mediaEX.length) {
163
+ let [bf, af] = ['', ''];
164
+ mediaEX.map((e) => {
165
+ const mediaQuery = e.split('::::')[0];
166
+ const mediaPrefix = e.split('::::')[1].replace(/^@/, '');
167
+ if (['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].indexOf(mediaPrefix) !== -1) {
168
+ bf = bf + `@layer ${mediaPrefix}{ ${mediaQuery} {`;
169
+ af = af + "}}";
170
+ }
171
+ else {
172
+ bf = bf + mediaQuery + "{ ";
173
+ af = af + "}";
174
+ }
175
+ });
176
+ stm = `${bf}${beforeClassNameSelector + '.' + className + elementAndPseudo}{${result}${important}}${af}`;
177
+ }
178
+ else {
179
+ stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
180
+ }
181
+ try {
182
+ postcss.parse(stm);
183
+ return stm;
184
+ }
185
+ catch (error) {
186
+ console.log('Not a Valid CSS Statement, PostCSS Parse:', stm);
187
+ }
188
+ }
189
+ else {
190
+ console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`);
191
+ }
192
+ },
193
+ // groupSingle(str:string, as:string){
194
+ // let pnv='';
195
+ // },
196
+ group(str, as) {
197
+ let statement = '';
198
+ [...str.trim().split(/\s+/)].forEach((e) => {
199
+ const getEachClassNameCompiled = this.make(e, as);
200
+ if (getEachClassNameCompiled)
201
+ statement += getEachClassNameCompiled + ' \n';
202
+ });
203
+ return statement;
204
+ },
205
+ groupMulti(str, as) {
206
+ let statement = '.' + as + '{\n';
207
+ [...str.trim().split(/\s+/)].forEach((e) => {
208
+ const getEachClassNameCompiled = this.make(e, as, true);
209
+ if (getEachClassNameCompiled)
210
+ statement += getEachClassNameCompiled + '; \n';
211
+ });
212
+ return statement + '}';
213
+ },
214
+ prebuild(a, b) {
215
+ if (typeof a === 'object') {
216
+ for (const key in a) {
217
+ if (a.hasOwnProperty(key))
218
+ this.cache.propertyAndValue[key] = a[key];
219
+ }
220
+ }
221
+ else {
222
+ if (a && b) {
223
+ this.cache.propertyAndValue[a] = b;
224
+ }
225
+ }
226
+ },
227
+ groupForJs(str, bool) {
228
+ if (!str.trim())
229
+ return '';
230
+ const jsStyle = {};
231
+ const list = str.trim().split(/\s+/);
232
+ list.forEach((e) => {
233
+ let pNv = '';
234
+ if (this.cache.propertyAndValue.hasOwnProperty(e)) {
235
+ pNv = this.cache.propertyAndValue[e];
236
+ }
237
+ else {
238
+ pNv = getPropertyAndValue(e, this.cssProps, this.staticClassNames, this.custom, extractProperty);
239
+ if (pNv)
240
+ this.cache.propertyAndValue[e] = pNv;
241
+ }
242
+ if (!pNv)
243
+ return '';
244
+ const result = pNv.split(':');
245
+ if (result.length === 2) {
246
+ const key = result[0].replace(/-([a-z])/g, (e, a) => {
247
+ return a.toUpperCase();
248
+ });
249
+ let value = bool === true ? result[1].replace(/px$/g, '') : result[1];
250
+ if (typeof value === 'string' && value.trim().match(/^[\d\.]+$/)) {
251
+ value = parseFloat(value.toString());
252
+ }
253
+ jsStyle[key] = value;
254
+ }
255
+ });
256
+ return jsStyle;
257
+ },
258
+ // obj:{'container':'p20px m-12pxx, 'section':'mt16px'}
259
+ groupObj(obj) {
260
+ if (typeof obj !== 'object')
261
+ return false;
262
+ let statement = '';
263
+ for (const key in obj) {
264
+ if (obj.hasOwnProperty(key)) {
265
+ const result = this.group(obj[key], key);
266
+ if (result) {
267
+ statement += result + '\n';
268
+ }
269
+ }
270
+ }
271
+ return statement;
272
+ },
273
+ addCustom(name, obj) {
274
+ name = (name === 'color' ? 'colors' : name);
275
+ if (typeof obj === 'object') {
276
+ if (!this.custom[name])
277
+ this.custom[name] = {};
278
+ for (const key in obj) {
279
+ if (obj.hasOwnProperty(key))
280
+ this.custom[name][key] = obj[key];
281
+ }
282
+ }
283
+ },
284
+ addMedia(obj) {
285
+ this.mediaSelector = Object.assign(Object.assign({}, this.mediaSelector), obj);
286
+ },
287
+ addPseudo(obj) {
288
+ // this.mediaSelector={...this.mediaSelector,...obj}
289
+ },
290
+ // styleToAliascss(value:string,bool:boolean){
291
+ // let classValue='';
292
+ // let styleValue='';
293
+ // value.split(/\s*;\s*/).forEach((each)=>{
294
+ // const [property,value]=each.match(/:/)?each.split(':'):['',''];
295
+ // if(property && value){
296
+ // if(cssProps.hasOwnProperty(property.trim())){
297
+ // classValue+=`${(bool===true && cssProps[property.trim()].alias)?cssProps[property.trim()].alias:property}-${
298
+ // value.trim().replace(/['"]/g, '').replace(/#/g, '').replace(/\((^\()\)/g, (m,s)=>'-'+s.replace(/[\s]*,[\s]*/g,'-'))
299
+ // .replace(/\s/g, '-').replace(/^var---/g,'-').replace(/-var-/g,'')
300
+ // }`
301
+ // }else{
302
+ // styleValue+=each+'; ';
303
+ // }
304
+ // }else {
305
+ // styleValue+=each+'; ';
306
+ // }
307
+ // })
308
+ // }
309
+ };
310
+ // compiler.staticClassNames={...helper().generateStaticClassNames(compiler.cssProps,config['css-global-values'])};
311
+ // compiler.addCustom('color',customColors)
@@ -1,3 +1,4 @@
1
+ export declare function isSafeCss(css: string): boolean;
1
2
  export declare const compiler: {
2
3
  make: (a: string, b?: string, c?: boolean) => string;
3
4
  group: (a: string, b: string) => string;
@@ -11,11 +11,82 @@ import { createCompilerObj, extractProperty } from "./utils/createCompilerObj.js
11
11
  import config from "./config.js";
12
12
  import cssProps from "./css-properties-all.js";
13
13
  import { staticClassNamesAlias } from "./static/staticClassNamesAlias.js";
14
- import postcss from "postcss";
15
- import { splitByCommaOutsideParens } from "./utils/helper.js";
14
+ import { splitByCommaOutsideParens, matchTrailingGroup, splitTopLevel, joinGroupItem } from "./utils/helper.js";
16
15
  import cssCustomCompilers from "./custom-css-compilers.js";
17
16
  // import customGroups from './prebuild.js';
18
17
  const [staticClassNamesWithAlias, cssPropsWithAlias] = createCompilerObj(cssProps, config.globalValues);
18
+ const NAME = '[a-zA-Z_][\\w-]*(?:\\/[a-zA-Z_][\\w-]*)*';
19
+ const AS_EXPORT = new RegExp(`--as-(?<names>${NAME}|\\[${NAME}(?:,${NAME})*\\])$`);
20
+ // Built once per prefix value instead of on every class
21
+ let prefixCache = null;
22
+ const prefixRegex = (prefix) => {
23
+ if (!prefixCache || prefixCache.prefix !== prefix) {
24
+ prefixCache = { prefix, re: new RegExp('^' + prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '-') };
25
+ }
26
+ return prefixCache.re;
27
+ };
28
+ // Classes that clearly tried to be AliasCSS (used for warnings only)
29
+ const ACSS_SYNTAX = /^[@_\[]|^--|--as-|\[.*\]$/;
30
+ // Safety check for a generated statement before it is emitted.
31
+ // A single bad statement must never damage the CSS that comes after it, so we reject:
32
+ // - unbalanced (), [], {} → would swallow or close the following rules / layers
33
+ // - an unclosed quote → the rest of the stylesheet becomes part of a string
34
+ // - "/*" outside quotes → opens a comment that hides everything after it
35
+ // - "</style" anywhere → ends an inline <style> tag in server-rendered HTML
36
+ // - no "property:value" in {} → empty or meaningless rule
37
+ // Escaped characters (\( \[ \{ …) in selectors are skipped.
38
+ // (postcss.parse checked only syntax too, but put the whole parser in the browser bundle.)
39
+ export function isSafeCss(css) {
40
+ if (/<\/style/i.test(css))
41
+ return false;
42
+ const stack = [];
43
+ const pairs = { ')': '(', ']': '[', '}': '{' };
44
+ let quote = '';
45
+ for (let i = 0; i < css.length; i++) {
46
+ const c = css[i];
47
+ if (c === '\\') {
48
+ i++;
49
+ continue;
50
+ }
51
+ if (quote) {
52
+ if (c === quote)
53
+ quote = '';
54
+ else if (c === '\n')
55
+ return false; // CSS strings can't span lines
56
+ continue;
57
+ }
58
+ if (c === '"' || c === "'") {
59
+ quote = c;
60
+ continue;
61
+ }
62
+ if (c === '/' && css[i + 1] === '*')
63
+ return false;
64
+ if (c === '(' || c === '[' || c === '{')
65
+ stack.push(c);
66
+ else if (c in pairs && stack.pop() !== pairs[c])
67
+ return false;
68
+ }
69
+ return !quote && stack.length === 0 && /\{[^{}]*:[^{}]*\}/.test(css);
70
+ }
71
+ // ---- Authoring warnings (the CSS is still emitted; these point at likely mistakes) ----
72
+ // "+" or "-" without spaces inside calc()/min()/max()/clamp(): calc(100%-32px) is invalid CSS.
73
+ // var(...) is removed first so names like --space-2-5 don't trigger it.
74
+ const CALC_FN = /\b(?:calc|min|max|clamp)\(/;
75
+ const NO_SPACE_MATH = /(?:\d(?:%|[a-z]+)?|\))[+-](?=[\d.(]|var\b)/i;
76
+ function calcSpacingProblem(declaration) {
77
+ if (!CALC_FN.test(declaration))
78
+ return false;
79
+ let d = declaration;
80
+ let prev = '';
81
+ while (d !== prev) {
82
+ prev = d;
83
+ d = d.replace(/var\([^()]*\)/g, '0');
84
+ } // innermost var() first, kept as a number
85
+ return NO_SPACE_MATH.test(d);
86
+ }
87
+ // A pseudo-class after these pseudo-elements never matches (::before:hover).
88
+ // Not included on purpose: ::file-selector-button, ::-webkit-scrollbar*, ::part() — those allow it.
89
+ const PSEUDO_ELEMENT_THEN_CLASS = /::(?:before|after|placeholder|marker|selection|first-line|first-letter|backdrop)(?=:[a-z])/;
19
90
  export const compiler = {
20
91
  // cache will cache propertyAndValue
21
92
  cache: { propertyAndValue: Object.assign({}, customStaticClassNames) },
@@ -59,6 +130,165 @@ export const compiler = {
59
130
  return this.cssProps[className].statement;
60
131
  }
61
132
  }
133
+ // Budle atomice class name in new
134
+ const asMatch = className.match(AS_EXPORT);
135
+ if ((_a = asMatch === null || asMatch === void 0 ? void 0 : asMatch.groups) === null || _a === void 0 ? void 0 : _a.names) {
136
+ return this.group(className.slice(0, asMatch.index), asMatch.groups.names);
137
+ }
138
+ let unPrefixedClassName = className;
139
+ // check for [group-acss,]
140
+ // old
141
+ // const matchGroupCSS=className.match(/\[([^[]*)\]$/);
142
+ // if(matchGroupCSS){
143
+ // const asString=splitByCommaOutsideParens(matchGroupCSS[1])
144
+ // // .split(',')
145
+ // .map(e=>(className.replace(matchGroupCSS[0],'')+"-").replace(/--$/,'-')+e.replace(/^--/,'-'))
146
+ // .join(' ');
147
+ // return this.group(asString,as?as:className);
148
+ // }
149
+ // --end old
150
+ // New
151
+ const grp = matchTrailingGroup(className);
152
+ if (grp) {
153
+ const asString = splitTopLevel(grp.body).map(e => joinGroupItem(grp.prefix, e)).join(' ');
154
+ return this.group(asString, as ? as : className);
155
+ }
156
+ // EONEW
157
+ let beforeClassNameSelector = '';
158
+ if (this.prefix) {
159
+ const re = prefixRegex(this.prefix);
160
+ if (!re.test(className))
161
+ return null;
162
+ unPrefixedClassName = className.replace(re, '');
163
+ }
164
+ if (!this.mediaTest)
165
+ this.mediaTest = createRegexForMedia(this.mediaSelector);
166
+ // 1. check and extract Media prefix and return className with prefix treatment,
167
+ let [extractedMedia, workingClassName] = extractMediaPrefix(unPrefixedClassName, this.mediaSelector, this.mediaTest);
168
+ const mediaEX = extractedMedia;
169
+ // lint escape for const
170
+ extractedMedia = extractedMedia;
171
+ // 2. search for '&' which tells us to use selector before or after className
172
+ if (workingClassName.match(/[&]/)) {
173
+ const [before, after] = workingClassName.split('&');
174
+ beforeClassNameSelector = extractPrefix(before + "-display-none")[0] + " ";
175
+ if (!beforeClassNameSelector.trim()) {
176
+ console.error('Not a valid AliasCSS className:' + className, 'Make sure to provide valid css aliascss selector before "&" identifier');
177
+ return null;
178
+ }
179
+ else {
180
+ beforeClassNameSelector = beforeClassNameSelector.replace(/^([\s]?[+~>])(.*)/, "$2$1 ");
181
+ }
182
+ workingClassName = workingClassName.replace(before, '').replace('&', '');
183
+ }
184
+ let [elementAndPseudo, important] = ['', ''];
185
+ // workingClassName=workingClassName.replace(/[_][\.]([a-zA-Z])/g,(s,e)=>"_"+'ACSS').replace(/[.]/g,"d").replace(/[%]/g,'p')
186
+ // 3. Process --important flag
187
+ if (/(-i|--important)$/.test(className)) {
188
+ important = ' !important';
189
+ workingClassName = workingClassName.replace(/(-i|--important)$/, '');
190
+ }
191
+ // 4. process Pseudo State
192
+ const prefixPseudoElementAttribute = extractPrefix(workingClassName);
193
+ workingClassName = prefixPseudoElementAttribute[1];
194
+ elementAndPseudo = prefixPseudoElementAttribute[0];
195
+ // ---------------------------------------------------------------------
196
+ const pnv = workingClassName.replace(/^-([a-zA-Z])/, '$1');
197
+ let result = '';
198
+ // x-class
199
+ // if(/^(x-width|x-height)/.test(pnv)){
200
+ // const extract=getPropertyAndValue(pnv.replace('x-',''), this.cssProps, this.staticClassNames, this.custom,extractProperty);
201
+ // if(typeof extract === 'string'){
202
+ // const [p,v]=extract.split(':');
203
+ // if(p && v){
204
+ // result=`${p}:calc(${v} + var(--x-${p}-grow,0px) - var(--x-${p}-shrink,0px));`
205
+ // }
206
+ // }
207
+ // }else
208
+ if (this.cache.propertyAndValue.hasOwnProperty(pnv)) {
209
+ result = this.cache.propertyAndValue[pnv];
210
+ }
211
+ else {
212
+ try {
213
+ result = getPropertyAndValue(pnv, this.cssProps, this.staticClassNames, this.custom, extractProperty);
214
+ }
215
+ catch (error) {
216
+ console.log(error);
217
+ }
218
+ }
219
+ // if(result){
220
+ // className=className.replace(/([$.&%=\]\[@~:*#+\(\)\/^])/g,'\\$1');
221
+ // if(bool===true) return result;
222
+ // this.cache.propertyAndValue[pnv]=result;
223
+ // if(media){
224
+ // return `${media}{${
225
+ // beforeClassNameSelector+'.'+(as?as:className)+ elementAndPseudo
226
+ // }{${result}${important}}}`;
227
+ // }else{
228
+ // return `${beforeClassNameSelector}.${(as?as:className)}${elementAndPseudo}{${result}${important}}`;
229
+ // }
230
+ // }else{
231
+ // console.log(`Unable to process ${className} [media:${media},pseudoSelector:${elementAndPseudo},imp:${important}]`)
232
+ // }
233
+ // ------------PostCSSParse
234
+ if (result) {
235
+ let stm = '';
236
+ if (bool !== true) {
237
+ const shown = as ? `${as} (${className})` : className;
238
+ if (calcSpacingProblem(result)) {
239
+ console.warn(`AliasCSS: "${shown}": "+" and "-" need spaces in calc(), write _-_ e.g. calc(100%_-_32px)`);
240
+ }
241
+ if (PSEUDO_ELEMENT_THEN_CLASS.test(elementAndPseudo)) {
242
+ console.warn(`AliasCSS: "${shown}": "${elementAndPseudo.trim()}" never matches; put the state first, e.g. --hover--before`);
243
+ }
244
+ }
245
+ className = (as ? as : className).replace(/([$.&%=\]\[@~,:*#+\(\)\/^/</>\\|])/g, '\\$1');
246
+ if (bool === true)
247
+ return result;
248
+ this.cache.propertyAndValue[pnv] = result;
249
+ if (mediaEX.length) {
250
+ let [bf, af] = ['', ''];
251
+ mediaEX.map((e) => {
252
+ const mediaQuery = e.split('::::')[0];
253
+ const mediaPrefix = e.split('::::')[1].replace(/^@/, '');
254
+ if (['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].indexOf(mediaPrefix) !== -1) {
255
+ bf = bf + `@layer ${mediaPrefix}{ ${mediaQuery} {`;
256
+ af = af + "}}";
257
+ }
258
+ else {
259
+ bf = bf + mediaQuery + "{ ";
260
+ af = af + "}";
261
+ }
262
+ });
263
+ stm = `${bf}${beforeClassNameSelector + '.' + className + elementAndPseudo}{${result}${important}}${af}`;
264
+ }
265
+ else {
266
+ stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
267
+ }
268
+ if (isSafeCss(stm))
269
+ return stm;
270
+ console.warn(`AliasCSS: "${as ? as : className}" produced invalid CSS:`, stm);
271
+ }
272
+ else {
273
+ const looksLikeAcss = ACSS_SYNTAX.test(className) || !!extractProperty(pnv, this.cssProps);
274
+ if (!this.groupDepth && (looksLikeAcss || config.debug)) {
275
+ console.warn(`AliasCSS: can't compile "${className}"`);
276
+ }
277
+ // console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`)
278
+ }
279
+ },
280
+ makeNested(className, as, bool) {
281
+ var _a;
282
+ // --Group Statement
283
+ if (this.cssProps.hasOwnProperty(className)) {
284
+ if (this.cssProps[className].hasOwnProperty('type') && (this.cssProps[className].type === 'statement')) {
285
+ return this.group(this.cssProps[className].statement, className);
286
+ }
287
+ if (this.cssProps[className].hasOwnProperty('type') && (this.cssProps[className].type === 'raw')) {
288
+ return this.cssProps[className].statement;
289
+ }
290
+ }
291
+ // inline-group
62
292
  if (/--as-[a-zA-Z0-9-_]+$/.test(className)) {
63
293
  const asMatch = (_a = className.match(/--as-([a-zA-Z0-9-_]+)$/)) !== null && _a !== void 0 ? _a : [null, null];
64
294
  if (asMatch[0] && asMatch[1]) {
@@ -155,7 +385,7 @@ export const compiler = {
155
385
  // ------------PostCSSParse
156
386
  if (result) {
157
387
  let stm = '';
158
- className = (as ? as : className).replace(/([$.&%=\]\[@~,:*#+\(\)\/^/</>])/g, '\\$1');
388
+ className = (as ? as : className).replace(/([$.&%=\]\[@~,:*#+\(\)\/^/</>\\])/g, '\\$1');
159
389
  if (bool === true)
160
390
  return result;
161
391
  this.cache.propertyAndValue[pnv] = result;
@@ -178,13 +408,9 @@ export const compiler = {
178
408
  else {
179
409
  stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
180
410
  }
181
- try {
182
- postcss.parse(stm);
411
+ if (isSafeCss(stm))
183
412
  return stm;
184
- }
185
- catch (error) {
186
- console.log('Not a Valid CSS Statement, PostCSS Parse:', stm);
187
- }
413
+ console.log('Not a Valid CSS Statement:', stm);
188
414
  }
189
415
  else {
190
416
  console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`);
@@ -195,12 +421,36 @@ export const compiler = {
195
421
  // },
196
422
  group(str, as) {
197
423
  let statement = '';
424
+ const failed = [];
425
+ this.groupDepth = (this.groupDepth || 0) + 1;
426
+ try {
427
+ [...str.trim().split(/\s+/)].forEach((e) => {
428
+ if (!e)
429
+ return;
430
+ const getEachClassNameCompiled = this.make(e, as);
431
+ if (getEachClassNameCompiled)
432
+ statement += getEachClassNameCompiled + ' \n';
433
+ else
434
+ failed.push(e);
435
+ });
436
+ }
437
+ finally {
438
+ this.groupDepth--;
439
+ }
440
+ // Items inside a group or statement are always meant as AliasCSS, so always report them
441
+ if (failed.length) {
442
+ console.warn(`AliasCSS: in "${as}", could not compile: ${failed.join(', ')}`);
443
+ }
444
+ return statement;
445
+ },
446
+ groupMulti(str, as) {
447
+ let statement = '.' + as + '{\n';
198
448
  [...str.trim().split(/\s+/)].forEach((e) => {
199
- const getEachClassNameCompiled = this.make(e, as);
449
+ const getEachClassNameCompiled = this.make(e, as, true);
200
450
  if (getEachClassNameCompiled)
201
- statement += getEachClassNameCompiled + ' \n';
451
+ statement += getEachClassNameCompiled + '; \n';
202
452
  });
203
- return statement;
453
+ return statement + '}';
204
454
  },
205
455
  prebuild(a, b) {
206
456
  if (typeof a === 'object') {