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
@@ -3,83 +3,126 @@ import pseudoSelector from './pseudoSelectorNew.js';
3
3
  import elementSelector from './element-selector.js';
4
4
  import attribute from './attribute-selector.js';
5
5
  import fallbackSelector from './fallback-selector.js';
6
+ const steps = [
7
+ name => pseudoSelector(name),
8
+ name => elementSelector.process(name),
9
+ name => (attribute.test.test(name) ? attribute.process(name) : null),
10
+ name => (fallbackSelector.test.test(name) ? fallbackSelector.process(name) : null),
11
+ ];
12
+ // A bare :not / :has / :is / :where (from forms like --not-[disabled]-…)
13
+ // takes the next selector piece as its argument.
14
+ const OPEN_FN = /:(not|where|has|is)([)])?$/;
15
+ function append(result, selector) {
16
+ const m = result.match(OPEN_FN);
17
+ if (!m)
18
+ return result + selector;
19
+ return m[2]
20
+ ? result.replace(/\)$/, '') + `(${selector}))`
21
+ : result + `(${selector})`;
22
+ }
6
23
  export default function extractPrefix(className) {
7
24
  let workingClassName = className;
8
25
  let result = '';
9
- let match = false;
10
- do {
11
- const matched = pseudoSelector(workingClassName);
12
- if (matched) {
13
- workingClassName = matched[0];
14
- if (result.match(/:(not|where|has|is)[)]?$/)) {
15
- const m = result.match(/:(not|where|has|is)([)])?$/);
16
- if (m === null || m === void 0 ? void 0 : m[2]) {
17
- result = result.replace(/\)$/, '') + `(${matched[1]}))`;
18
- }
19
- else {
20
- result += `(${matched[1]})`;
21
- }
22
- }
23
- else {
24
- result += matched[1];
25
- }
26
- match = true;
26
+ while (true) {
27
+ let progressed = false;
28
+ for (const step of steps) {
29
+ const matched = step(workingClassName);
30
+ if (!matched)
31
+ continue;
32
+ const [rest, selector] = matched;
33
+ if (rest === workingClassName)
34
+ continue; // no progress: avoid an infinite loop
35
+ result = append(result, selector);
36
+ workingClassName = rest;
37
+ progressed = true;
38
+ break; // restart from the first step, as before
27
39
  }
28
- else if (elementSelector.test.test(workingClassName)) {
29
- const [replacedClassName, selector] = elementSelector.process(workingClassName);
30
- if (result.match(/:(not|where|has|is)[)]?$/)) {
31
- const m = result.match(/:(not|where|has|is)([)])?$/);
32
- if (m === null || m === void 0 ? void 0 : m[2]) {
33
- result = result.replace(/\)$/, '') + `(${selector}))`;
34
- }
35
- else {
36
- result += `(${selector})`;
37
- }
38
- }
39
- else {
40
- result += selector;
41
- }
42
- workingClassName = replacedClassName;
43
- match = true;
44
- }
45
- else if (attribute.test.test(workingClassName)) {
46
- const [replacedClassName, selector] = attribute.process(workingClassName);
47
- if (result.match(/:(not|where|has|is)[)]?$/)) {
48
- const m = result.match(/:(not|where|has|is)([)])?$/);
49
- if (m === null || m === void 0 ? void 0 : m[2]) {
50
- result = result.replace(/\)$/, '') + `(${selector}))`;
40
+ if (!progressed)
41
+ break;
42
+ }
43
+ return [result, workingClassName];
44
+ }
45
+ /*
46
+ // import pseudoSelector from './selector.js'
47
+ import pseudoSelector from './pseudoSelectorNew.js'
48
+ import elementSelector from './element-selector.js'
49
+ import attribute from './attribute-selector.js';
50
+ import fallbackSelector from './fallback-selector.js';
51
+
52
+ export default function extractPrefix(className:string){
53
+ let workingClassName=className;
54
+ let result='';
55
+ let match=false;
56
+ do {
57
+ const matched=pseudoSelector(workingClassName);
58
+ if(matched){
59
+ workingClassName=matched[0];
60
+ if(result.match(/:(not|where|has|is)[)]?$/)){
61
+ const m=result.match(/:(not|where|has|is)([)])?$/);
62
+ if(m?.[2]){
63
+ result=result.replace(/\)$/,'')+ `(${matched[1]}))`;
64
+ }else{
65
+ result +=`(${matched[1]})`
66
+ }
67
+
68
+ }else{
69
+ result +=matched[1]
51
70
  }
52
- else {
53
- result += `(${selector})`;
71
+
72
+ match=true;
73
+
74
+ }else if(elementSelector.test.test(workingClassName)){
75
+ const [replacedClassName, selector]=elementSelector.process(workingClassName);
76
+ if(result.match(/:(not|where|has|is)[)]?$/)){
77
+ const m=result.match(/:(not|where|has|is)([)])?$/);
78
+ if(m?.[2]){
79
+ result=result.replace(/\)$/,'')+ `(${selector}))`;
80
+ }else{
81
+ result +=`(${selector})`
82
+ }
83
+
84
+ }else{
85
+ result +=selector
54
86
  }
55
- }
56
- else {
57
- result += selector;
58
- }
59
- workingClassName = replacedClassName;
60
- match = true;
61
- }
62
- else if (fallbackSelector.test.test(workingClassName)) {
63
- // console.log('=-=-=-=-=-=--=',workingClassName);
64
- const [replacedClassName, selector] = fallbackSelector.process(workingClassName);
65
- if (result.match(/:(not|where|has|is)[)]?$/)) {
66
- const m = result.match(/:(not|where|has|is)([)])?$/);
67
- if (m === null || m === void 0 ? void 0 : m[2]) {
68
- result = result.replace(/\)$/, '') + `(${selector}))`;
87
+ workingClassName=replacedClassName;
88
+ match=true;
89
+ }else if(attribute.test.test(workingClassName)){
90
+ const [replacedClassName, selector]=attribute.process(workingClassName);
91
+ if(result.match(/:(not|where|has|is)[)]?$/)){
92
+ const m=result.match(/:(not|where|has|is)([)])?$/);
93
+ if(m?.[2]){
94
+ result=result.replace(/\)$/,'')+ `(${selector}))`;
95
+ }else{
96
+ result +=`(${selector})`
97
+ }
98
+ }else{
99
+ result +=selector
69
100
  }
70
- else {
71
- result += `(${selector})`;
101
+ workingClassName=replacedClassName;
102
+ match=true;
103
+ }else if(fallbackSelector.test.test(workingClassName)){
104
+ // console.log('=-=-=-=-=-=--=',workingClassName);
105
+ const [replacedClassName, selector]=fallbackSelector.process(workingClassName);
106
+ if(result.match(/:(not|where|has|is)[)]?$/)){
107
+ const m=result.match(/:(not|where|has|is)([)])?$/);
108
+ if(m?.[2]){
109
+ result=result.replace(/\)$/,'')+ `(${selector}))`;
110
+ }else{
111
+ result +=`(${selector})`
112
+ }
113
+ }else{
114
+ result +=selector
72
115
  }
116
+ workingClassName=replacedClassName;
117
+ match=true;
118
+ }else{
119
+ match=false;
73
120
  }
74
- else {
75
- result += selector;
76
- }
77
- workingClassName = replacedClassName;
78
- match = true;
79
- }
80
- else {
81
- match = false;
82
- }
83
- } while (match);
84
- return [result, workingClassName];
121
+
122
+ } while (match);
123
+
124
+ return [result, workingClassName]
125
+
126
+
85
127
  }
128
+ */
@@ -0,0 +1,30 @@
1
+ type Property = {
2
+ alias?: string;
3
+ property?: string;
4
+ type?: string;
5
+ values?: string[];
6
+ groups?: {
7
+ [key: string]: string;
8
+ };
9
+ compiler?: (...args: any[]) => any;
10
+ };
11
+ /**
12
+ * @param className : string
13
+ * @param cssPropertiesWithAlias: Compiler Object
14
+ * @param staticClassNames : StaticClassNames
15
+ * @param custom : custom values for color, font, etc
16
+ * @param extractProperty :extractProperty(className:string,cssPropertiesWithAlias:{[key:string]:Property})=>[Property,string]
17
+ * @param bool : return[property,value] or property:value
18
+ * @returns {string[]|null|{}}
19
+ */
20
+ export default function getPropertyAndValue(className: string, cssPropertiesWithAlias: {
21
+ [key: string]: Property;
22
+ }, staticClassNames: {
23
+ [key: string]: string;
24
+ }, custom: {
25
+ [key: string]: {
26
+ [key: string]: string;
27
+ };
28
+ }, extractProperty: any, // (a:string,b:{[key:string]:Property})=>[Property,string],
29
+ bool?: boolean): string[] | null | {};
30
+ export {};
@@ -0,0 +1,219 @@
1
+ /**
2
+ * @param className : string
3
+ * @param cssPropertiesWithAlias: Compiler Object
4
+ * @param staticClassNames : StaticClassNames
5
+ * @param custom : custom values for color, font, etc
6
+ * @param extractProperty :extractProperty(className:string,cssPropertiesWithAlias:{[key:string]:Property})=>[Property,string]
7
+ * @param bool : return[property,value] or property:value
8
+ * @returns {string[]|null|{}}
9
+ */
10
+ export default function getPropertyAndValue(className, cssPropertiesWithAlias, staticClassNames, custom, extractProperty, // (a:string,b:{[key:string]:Property})=>[Property,string],
11
+ bool = false) {
12
+ var _a;
13
+ // Case 1 StaticClassNames
14
+ if (staticClassNames.hasOwnProperty(className)) {
15
+ return staticClassNames[className];
16
+ }
17
+ // case 2 defining css-variable as className
18
+ if (className.startsWith('--') && className.includes(':')) {
19
+ let value = className.slice(className.indexOf(':')).replace(':', '');
20
+ const property = className.replace(value, '').replace(':', '');
21
+ let possiblePropsName = '';
22
+ const camelCasePropertyHint = (_a = property.match(/[A-Z][a-z0-9]*$/)) === null || _a === void 0 ? void 0 : _a[0];
23
+ if (camelCasePropertyHint) {
24
+ possiblePropsName = camelCasePropertyHint.toLowerCase();
25
+ }
26
+ else {
27
+ possiblePropsName = property.slice(property.lastIndexOf('-') + 1);
28
+ }
29
+ let compiler = null;
30
+ if (cssPropertiesWithAlias.hasOwnProperty(possiblePropsName) && cssPropertiesWithAlias[possiblePropsName].hasOwnProperty('compiler') && typeof cssPropertiesWithAlias[possiblePropsName].compiler === 'function') {
31
+ compiler = cssPropertiesWithAlias[possiblePropsName].compiler;
32
+ }
33
+ // if value is function i.e --some-var:(12px,red,blue);
34
+ if (/^\(.+\)[_]?$/.test(value)) {
35
+ if (value.match(/_$/)) {
36
+ // replace --[name] with var(--[name])
37
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
38
+ .replace(/^[(]/, '').replace(/_$/, '').replace(/[)]$/, '')
39
+ .replace(/,/g, ', ');
40
+ value = val.replace(/_/g, ' ');
41
+ }
42
+ else {
43
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
44
+ .replace(/^[(]/, '').replace(/[)]$/, '')
45
+ // .replace(/,/g,' ');
46
+ .replace(/,/g, ', ');
47
+ // value=val.replace(/_/g,' ');
48
+ value = val.replace(/\\_|_/g, (m) => (m === '_' ? ' ' : '_'));
49
+ ;
50
+ }
51
+ return bool ? [property, value] : property + ":" + value;
52
+ }
53
+ //
54
+ // case 1: CSS Variable inside css variable
55
+ if (/^calc/.test(value)) {
56
+ return bool ? [property, value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2')] : property + ":" + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2');
57
+ }
58
+ // case 2: CSS variable in side css variable
59
+ if (/^--[a-zA-Z]/.test(value)) {
60
+ if (value.includes(':')) {
61
+ let val = value.slice(value.indexOf(':')).replace(':', '');
62
+ const cssVar = value.replace(val, '').replace(':', '');
63
+ if (compiler && typeof compiler === 'function') {
64
+ const v = compiler(val, custom);
65
+ val = v ? v : val;
66
+ }
67
+ return bool ? [property, "var(" + cssVar + ',' + val + ')'] : property + ": var(" + cssVar + ',' + val + ')';
68
+ }
69
+ else if (compiler && compiler.name === 'color') {
70
+ return bool ? [property, compiler(value)] : property + ":" + compiler(value);
71
+ }
72
+ return bool ? [property, "var(" + value + ')'] : property + ": var(" + value + ')';
73
+ }
74
+ else {
75
+ // If has text in end
76
+ if (/text$/.test(property)) {
77
+ const v = '"' + value.replace(/([_]?)[_]/g, '$1 ').replace(/_[\s]/g, '_') + '"';
78
+ return bool ? [property, v] : property + ":" + v;
79
+ }
80
+ // Rest
81
+ if (compiler && typeof compiler === 'function') {
82
+ const v = compiler(value, custom);
83
+ value = v ?
84
+ v
85
+ :
86
+ value.replace(/[-]([-]?[\w])/g, ' $1').replace(/([\d])d([\d])/g, '$1.$2').replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/[\s]by[\s]/g, ' / ')
87
+ .replace(/auto flow/g, 'auto-flow')
88
+ .replace(/__/g, " ")
89
+ .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g, '-$1');
90
+ }
91
+ else {
92
+ value = value.replace(/[-]([-]?[\w])/g, ' $1').replace(/([\d])d([\d])/g, '$1.$2').replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/[\s]by[\s]/g, ' / ')
93
+ .replace(/auto flow/g, 'auto-flow')
94
+ .replace(/__/g, " ")
95
+ .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g, '-$1');
96
+ }
97
+ return bool ? [property, value] : property + ":" + value;
98
+ }
99
+ }
100
+ // End of CSS-variable as a className
101
+ const [property, propertyKey] = extractProperty(className, cssPropertiesWithAlias);
102
+ // console.log(propertyKey,'ttt',property,className)
103
+ if (property) {
104
+ // check for type='group'
105
+ if (property.hasOwnProperty('type') && property.type === "group") {
106
+ const valuePortion = className.replace(propertyKey, '');
107
+ if (property.hasOwnProperty('groups') && property.groups.hasOwnProperty(valuePortion.replace(/^-/, ''))) {
108
+ return property.groups[valuePortion.replace(/^-/, '')];
109
+ }
110
+ return property.compiler(valuePortion, custom) || '';
111
+ }
112
+ // --End of Group type
113
+ const prop = property.property ? property.property : propertyKey;
114
+ // Case 2: CSS Variables
115
+ if (/--var--/.test(className)) {
116
+ const splits = className.split(/--var--/);
117
+ if (cssPropertiesWithAlias.hasOwnProperty(splits[0])) {
118
+ if (splits[1].includes(':')) {
119
+ let value = splits[1].slice(splits[1].indexOf(':')).replace(':', '');
120
+ const cssVar = splits[1].replace(value, '').replace(':', '');
121
+ if (/^calc\(/.test(value)) {
122
+ return bool ? [prop, "var(--" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')'] : prop + ": var(--" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')';
123
+ }
124
+ if (property.hasOwnProperty('compiler') && typeof property.compiler === 'function') {
125
+ const val = property.compiler(value, custom);
126
+ value = val ? val : value;
127
+ }
128
+ return bool ? [prop, "var(--" + cssVar + ',' + value + ')'] : prop + ": var(--" + cssVar + ',' + value + ')';
129
+ }
130
+ return bool ? [prop, "var(--" + splits[1] + ')'] : prop + ": var(--" + splits[1] + ')';
131
+ }
132
+ }
133
+ const valuePortion = className.replace(propertyKey, '');
134
+ // New Update function value
135
+ if (/^\(.+\)[_]?$/.test(valuePortion)) {
136
+ if (valuePortion.match(/_$/)) {
137
+ const val = valuePortion.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
138
+ .replace(/^[(]/, '').replace(/_$/, '').replace(/[)]$/, '')
139
+ .replace(/,/g, ', ')
140
+ .replace(/[_]/g, ' ');
141
+ return bool ? [prop, val] : prop + ":" + val;
142
+ }
143
+ else {
144
+ const val = valuePortion.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
145
+ .replace(/^[(]/, '').replace(/[)]$/, '')
146
+ // .replace(/,/g,' ')
147
+ .replace(/,/g, ', ')
148
+ // .replace(/[_]/g,' ');
149
+ .replace(/\\_|_/g, (m) => (m === '_' ? ' ' : '_'));
150
+ return bool ? [prop, val] : prop + ":" + val;
151
+ }
152
+ }
153
+ // case 3: calc function
154
+ if (/^-calc\(/.test(valuePortion)) {
155
+ return bool ? [prop, valuePortion.replace(/^-/, '').replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2')] : prop + ":" + valuePortion.replace(/^-/, '').replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2');
156
+ }
157
+ // case 4: CSS variable without --var keyword
158
+ if (/^--[a-zA-Z]/.test(valuePortion)) {
159
+ if (valuePortion.includes(':')) {
160
+ let value = valuePortion.slice(valuePortion.indexOf(':')).replace(':', '');
161
+ const cssVar = valuePortion.replace(value, '').replace(':', '');
162
+ // check if has :()
163
+ if (/^\(.+\)[_]?$/.test(value)) {
164
+ if (value.match(/_$/)) {
165
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
166
+ .replace(/^[(]/, '').replace(/_$/, '').replace(/[)]$/, '')
167
+ .replace(/,/g, ', ');
168
+ value = val;
169
+ }
170
+ else {
171
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
172
+ .replace(/^[(]/, '').replace(/[)]$/, '')
173
+ .replace(/,/g, ' ');
174
+ value = val;
175
+ }
176
+ return bool ? [prop, "var(" + cssVar + ',' + value + ')'] : prop + ": var(" + cssVar + ',' + value + ')';
177
+ }
178
+ //
179
+ if (/^calc\(/.test(value)) {
180
+ return bool ? [prop, "var(" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')'] : prop + ": var(" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')';
181
+ }
182
+ if (property.hasOwnProperty('compiler') && typeof property.compiler === 'function') {
183
+ const val = property.compiler(value, custom);
184
+ value = val ? val : value;
185
+ }
186
+ return bool ? [prop, "var(" + cssVar + ',' + value + ')'] : prop + ": var(" + cssVar + ',' + value + ')';
187
+ }
188
+ if (/(background|color)$/.test(prop)) {
189
+ if (cssPropertiesWithAlias.color.compiler && typeof cssPropertiesWithAlias.color.compiler === 'function') {
190
+ const value = cssPropertiesWithAlias.color.compiler(valuePortion, custom);
191
+ return bool ? [prop, value] : prop + ":" + value;
192
+ }
193
+ }
194
+ return bool ? [prop, "var(" + valuePortion + ')'] : prop + ": var(" + valuePortion + ')';
195
+ }
196
+ if (property.hasOwnProperty('compiler') && typeof property.compiler === 'function') {
197
+ // const value=property.compiler(valuePortion.replace(/^-/,'') ,custom);
198
+ const value = property.compiler(valuePortion, custom);
199
+ // console.log(value,valuePortion,property)
200
+ if (value && value !== '-') {
201
+ const val = value.replace(/([-]?)([\d]|10|11|12)col/g, (m, p1, p2) => `${p1}${parseFloat(((100 / 12) * parseFloat(p2)).toFixed(6))}%`);
202
+ return bool ? [prop, val] : prop + ":" + val;
203
+ }
204
+ else {
205
+ console.log(`${className}: '${propertyKey}' unable to compile value:${className.replace(propertyKey, '')} returning value as it is`);
206
+ return bool ? [prop, (valuePortion.replace(/^-/, '')) ? valuePortion.replace(/^-/, '') : 'initial' + ` /* ***Warning:Might not be Valid value *** */`] : prop + ":" + (valuePortion.replace(/^-/, '')) ? valuePortion.replace(/^-/, '') : 'initial' + ` /* ***Warning:Might not be Valid value *** */`;
207
+ }
208
+ }
209
+ else {
210
+ console.log("No Compiler found for:" + className + " invalidating static className definition, add compiler function to get as it is value.");
211
+ // Saving Static Value
212
+ // return bool?[prop,valuePortion.replace(/^-/,'')+` /* ***Warning:Might not be Valid value *** */`]:prop+":"+valuePortion.replace(/^-/,'')+` /* ***Warning:Might not be Valid value *** */`;
213
+ }
214
+ }
215
+ else {
216
+ console.log(`${className}: is not valid AliasCSS class name, property definition not found`);
217
+ }
218
+ return bool ? [null, null] : null;
219
+ }
@@ -1,3 +1,18 @@
1
+ /**
2
+ * A value written after ":" has no separator dash, but property compilers expect the value
3
+ * exactly as it follows the property in a normal class: "-8px" in m-8px (dash = separator),
4
+ * "--8px" in m--8px (negative). Put the separator back so ":-8px" compiles like m--8px.
5
+ * ":--8px" is accepted as negative too.
6
+ */
7
+ const asClassValue = (value) => '-' + value.replace(/^--(?=[\d.])/, '-');
8
+ /** Value clean-up used when no compiler handles the value (same rules as before, sign-safe). */
9
+ const fallbackValue = (value) => asClassValue(value)
10
+ .replace(/[-]([-]?[\w])/g, ' $1')
11
+ .trimStart() // drop the separator before keyword fixes below
12
+ .replace(/([\d])d([\d])/g, '$1.$2').replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/[\s]by[\s]/g, ' / ')
13
+ .replace(/auto flow/g, 'auto-flow')
14
+ .replace(/__/g, " ")
15
+ .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g, '-$1');
1
16
  /**
2
17
  * @param className : string
3
18
  * @param cssPropertiesWithAlias: Compiler Object
@@ -61,7 +76,7 @@ bool = false) {
61
76
  let val = value.slice(value.indexOf(':')).replace(':', '');
62
77
  const cssVar = value.replace(val, '').replace(':', '');
63
78
  if (compiler && typeof compiler === 'function') {
64
- const v = compiler(val, custom);
79
+ const v = compiler(asClassValue(val), custom);
65
80
  val = v ? v : val;
66
81
  }
67
82
  return bool ? [property, "var(" + cssVar + ',' + val + ')'] : property + ": var(" + cssVar + ',' + val + ')';
@@ -78,22 +93,8 @@ bool = false) {
78
93
  return bool ? [property, v] : property + ":" + v;
79
94
  }
80
95
  // Rest
81
- if (compiler && typeof compiler === 'function') {
82
- const v = compiler(value, custom);
83
- value = v ?
84
- v
85
- :
86
- value.replace(/[-]([-]?[\w])/g, ' $1').replace(/([\d])d([\d])/g, '$1.$2').replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/[\s]by[\s]/g, ' / ')
87
- .replace(/auto flow/g, 'auto-flow')
88
- .replace(/__/g, " ")
89
- .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g, '-$1');
90
- }
91
- else {
92
- value = value.replace(/[-]([-]?[\w])/g, ' $1').replace(/([\d])d([\d])/g, '$1.$2').replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/[\s]by[\s]/g, ' / ')
93
- .replace(/auto flow/g, 'auto-flow')
94
- .replace(/__/g, " ")
95
- .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g, '-$1');
96
- }
96
+ const v = compiler && typeof compiler === 'function' ? compiler(asClassValue(value), custom) : null;
97
+ value = v ? v : fallbackValue(value);
97
98
  return bool ? [property, value] : property + ":" + value;
98
99
  }
99
100
  }
@@ -122,7 +123,7 @@ bool = false) {
122
123
  return bool ? [prop, "var(--" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')'] : prop + ": var(--" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')';
123
124
  }
124
125
  if (property.hasOwnProperty('compiler') && typeof property.compiler === 'function') {
125
- const val = property.compiler(value, custom);
126
+ const val = property.compiler(asClassValue(value), custom);
126
127
  value = val ? val : value;
127
128
  }
128
129
  return bool ? [prop, "var(--" + cssVar + ',' + value + ')'] : prop + ": var(--" + cssVar + ',' + value + ')';
@@ -180,7 +181,7 @@ bool = false) {
180
181
  return bool ? [prop, "var(" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')'] : prop + ": var(" + cssVar + ',' + value.replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2') + ')';
181
182
  }
182
183
  if (property.hasOwnProperty('compiler') && typeof property.compiler === 'function') {
183
- const val = property.compiler(value, custom);
184
+ const val = property.compiler(asClassValue(value), custom);
184
185
  value = val ? val : value;
185
186
  }
186
187
  return bool ? [prop, "var(" + cssVar + ',' + value + ')'] : prop + ": var(" + cssVar + ',' + value + ')';
@@ -202,18 +203,18 @@ bool = false) {
202
203
  return bool ? [prop, val] : prop + ":" + val;
203
204
  }
204
205
  else {
205
- console.log(`${className}: '${propertyKey}' unable to compile value:${className.replace(propertyKey, '')} returning value as it is`);
206
- return bool ? [prop, (valuePortion.replace(/^-/, '')) ? valuePortion.replace(/^-/, '') : 'initial' + ` /* ***Warning:Might not be Valid value *** */`] : prop + ":" + (valuePortion.replace(/^-/, '')) ? valuePortion.replace(/^-/, '') : 'initial' + ` /* ***Warning:Might not be Valid value *** */`;
206
+ const asWritten = valuePortion.replace(/^-/, '');
207
+ console.warn(`AliasCSS: "${className}": couldn't compile the value "${asWritten}", used it as written`);
208
+ const v = asWritten ? asWritten : 'initial /* ***Warning:Might not be Valid value *** */';
209
+ // (the old one-liner returned only the value: `prop + ":" + x ? x : …` parses as `(prop + ":" + x) ? x : …`)
210
+ return bool ? [prop, v] : prop + ":" + v;
207
211
  }
208
212
  }
209
213
  else {
210
- console.log("No Compiler found for:" + className + " invalidating static className definition, add compiler function to get as it is value.");
211
214
  // Saving Static Value
212
215
  // return bool?[prop,valuePortion.replace(/^-/,'')+` /* ***Warning:Might not be Valid value *** */`]:prop+":"+valuePortion.replace(/^-/,'')+` /* ***Warning:Might not be Valid value *** */`;
213
216
  }
214
217
  }
215
- else {
216
- console.log(`${className}: is not valid AliasCSS class name, property definition not found`);
217
- }
218
+ // Not an AliasCSS class (e.g. a plain "card-title"): stay quiet, compiler.ts decides whether to warn
218
219
  return bool ? [null, null] : null;
219
220
  }
@@ -0,0 +1,5 @@
1
+ export declare const compiler: {
2
+ make: (a: string, b?: string, c?: boolean) => string;
3
+ group: (a: string, b: string) => string;
4
+ [key: string]: any;
5
+ };