aliascss 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/dist/aliascss.js +1 -1
- package/jestconfig.json +1 -3
- package/lib/build/index.js +136 -19
- package/lib/classPrinter.d.ts +1 -1
- package/lib/classPrinter.js +28 -18
- package/lib/compilers/border.js +106 -27
- package/lib/compilers/clipPath.js +79 -6
- package/lib/compilers/color.js +150 -21
- package/lib/compilers/filter.js +90 -3
- package/lib/compilers/font.js +39 -11
- package/lib/compilers/gradient.js +43 -27
- package/lib/compilers/length.js +34 -9
- package/lib/compilers/shadow.js +60 -26
- package/lib/compilers/stringAndContent.js +39 -2
- package/lib/compilers/timingFunction.js +57 -6
- package/lib/compilers/transform.js +118 -48
- package/lib/compilers/transition.js +79 -11
- package/lib/compilers/url.js +53 -3
- package/lib/css-properties-all.js +17 -9
- package/lib/index.d.ts +9 -9
- package/lib/node/compileFile.js +38 -11
- package/lib/returnPropertyAndValue-bk-301026.d.ts +30 -0
- package/lib/returnPropertyAndValue-bk-301026.js +219 -0
- package/lib/returnPropertyAndValue.js +26 -25
- package/lib/returnStatement.js +24 -6
- package/lib/utils/cssFunc.js +2 -0
- package/lib/utils/helper.js +16 -2
- package/lib/x-classes/x-form-components.js +2 -1
- package/llms.txt +326 -0
- package/package.json +3 -1
- package/tsconfig.json +1 -0
- package/tsconfig.test.json +10 -0
|
@@ -18,6 +18,13 @@ const width = config.widths; // ['medium:m','thin:t','thick:th:t2'];
|
|
|
18
18
|
const mode = config.modes; // ['normal:ml','multiply:m','screen:s','overlay:o','darken:d','lighten:l','color-dodge:cd','color-burn:cb','hard-light:hl','soft-light:sl','difference:di:d2','exclusion:e','hue:h','saturation:sa:s2','color:c','luminosity:lu:l2'];
|
|
19
19
|
const remUnits = config.remUnits; // [`${1/4}rem:1`,`${2/4}rem:2`,`${3/4}rem:3`,`${4/4}rem:4`,`${5/4}rem:5`,`${6/4}rem:6`,`${7/4}rem:7`,`${8/4}rem:8`,`${9/4}rem:9`,`${10/4}rem:10`,];
|
|
20
20
|
const remUnitsNegative = config.remUnitsNegative; // [`-${1/4}rem:-1`, `-${2/4}rem:-2`, `-${3/4}rem:-3`, `-${4/4}rem:-4`, `-${5/4}rem:-5`, `-${6/4}rem:-6`, `-${7/4}rem:-7`, `-${8/4}rem:-8`, `-${9/4}rem:-9`, `-${10/4}rem:-10`];
|
|
21
|
+
const gridBy = (value) => value
|
|
22
|
+
.replace(/--([\d])/g, '-Minus$1')
|
|
23
|
+
.replace(/\/-([\d])/g, '/Minus$1') // "/-1" is always negative: "/" is not a dash separator
|
|
24
|
+
.replace(/^-/, '')
|
|
25
|
+
.replace(/-by-/g, " / ")
|
|
26
|
+
.replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ')
|
|
27
|
+
.replace(/[-]?Minus[\s]*/g, '-');
|
|
21
28
|
const cssProps = {
|
|
22
29
|
// type:s=static,d=dynamic
|
|
23
30
|
// -----------------xc----------------
|
|
@@ -946,7 +953,7 @@ const cssProps = {
|
|
|
946
953
|
alias: 'cur',
|
|
947
954
|
type: '',
|
|
948
955
|
// compiler:'',
|
|
949
|
-
values: ['alias:al', 'all-scroll:as', 'auto:a', 'cell:c', 'col-resize:cr', 'context-menu:cm', 'copy:cp',
|
|
956
|
+
values: ['grab:gr:g', 'alias:al', 'all-scroll:as', 'auto:a', 'cell:c', 'col-resize:cr', 'context-menu:cm', 'copy:cp',
|
|
950
957
|
'crosshair:ch', 'default:d', 'e-resize:er', 'ew-resize:ewr', 'help:h', 'move:mo', 'n-resize:nr', 'ne-resize:ner', 'nesw-resize:neswr',
|
|
951
958
|
'no-drop:nd', 'none:n', 'not-allowed:na', 'ns-resize:nsr', 'nw-resize:nwr', 'nwse-resize:nwser',
|
|
952
959
|
'pointer:p', 'progress:pr', 'row-resize:rr', 's-resize:sr', 'se-resize:ser', 'sw-resize:swr',
|
|
@@ -1188,7 +1195,7 @@ const cssProps = {
|
|
|
1188
1195
|
alias: 'ga',
|
|
1189
1196
|
type: 'd',
|
|
1190
1197
|
// compiler:lenByNumPer,
|
|
1191
|
-
compiler:
|
|
1198
|
+
compiler: gridBy,
|
|
1192
1199
|
values: [''],
|
|
1193
1200
|
},
|
|
1194
1201
|
'grid-auto-columns': {
|
|
@@ -1201,6 +1208,7 @@ const cssProps = {
|
|
|
1201
1208
|
// }
|
|
1202
1209
|
// if(/^minmax-/.text(value:string)){
|
|
1203
1210
|
return value.replace(/[-]?(minmax)-(min-content|max-content|auto|\w+)-(min-content|max-content|auto|\w+)/g, " $1($2 , $3 ) ")
|
|
1211
|
+
.replace(/(\d)\.(\d)/g, '$1d$2').replace(/%/g, 'p')
|
|
1204
1212
|
.replace(/[-]?(fit-content)[-]([\w]+)/g, "$1( $2 ) ")
|
|
1205
1213
|
.replace(/-([\d|a|a|f|m])/g, ' $1')
|
|
1206
1214
|
.replace(/([\d])d([\d])/g, '$1.$2')
|
|
@@ -1225,7 +1233,7 @@ const cssProps = {
|
|
|
1225
1233
|
// }
|
|
1226
1234
|
// if(/^minmax-/.text(value:string)){
|
|
1227
1235
|
return value.replace(/[-]?(minmax)-(min-content|max-content|auto|\w+)-(min-content|max-content|auto|\w+)/g, " $1($2 , $3 ) ")
|
|
1228
|
-
.replace(/[-]?(fit-content)[-]([\w]+)/g, "$1( $2 ) ")
|
|
1236
|
+
.replace(/(\d)\.(\d)/g, '$1d$2').replace(/%/g, 'p').replace(/[-]?(fit-content)[-]([\w]+)/g, "$1( $2 ) ")
|
|
1229
1237
|
.replace(/-([\d|a|a|f|m])/g, ' $1')
|
|
1230
1238
|
.replace(/([\d])d([\d])/g, '$1.$2')
|
|
1231
1239
|
.replace(/([\d])p([\s])/g, "$1% ").replace(/p$/, "%");
|
|
@@ -1237,14 +1245,14 @@ const cssProps = {
|
|
|
1237
1245
|
alias: 'gc',
|
|
1238
1246
|
type: 'd',
|
|
1239
1247
|
// compiler:lenByNumPer,
|
|
1240
|
-
compiler:
|
|
1248
|
+
compiler: gridBy,
|
|
1241
1249
|
values: [],
|
|
1242
1250
|
},
|
|
1243
1251
|
'grid-column-end': {
|
|
1244
1252
|
alias: 'gce',
|
|
1245
1253
|
type: 'd',
|
|
1246
1254
|
// compiler:lenByNumPer,
|
|
1247
|
-
compiler:
|
|
1255
|
+
compiler: gridBy,
|
|
1248
1256
|
values: ['auto'],
|
|
1249
1257
|
},
|
|
1250
1258
|
'grid-column-gap': {
|
|
@@ -1257,7 +1265,7 @@ const cssProps = {
|
|
|
1257
1265
|
alias: 'gcs',
|
|
1258
1266
|
type: 'd',
|
|
1259
1267
|
// compiler:length,
|
|
1260
|
-
compiler:
|
|
1268
|
+
compiler: gridBy,
|
|
1261
1269
|
values: ['auto:a'],
|
|
1262
1270
|
},
|
|
1263
1271
|
'grid-gap': {
|
|
@@ -1270,14 +1278,14 @@ const cssProps = {
|
|
|
1270
1278
|
alias: 'gr',
|
|
1271
1279
|
type: 'd',
|
|
1272
1280
|
// compiler:lenByNumPer,
|
|
1273
|
-
compiler:
|
|
1281
|
+
compiler: gridBy,
|
|
1274
1282
|
values: ['auto:a', 'auto / auto:auto-auto'],
|
|
1275
1283
|
},
|
|
1276
1284
|
'grid-row-end': {
|
|
1277
1285
|
alias: 'gre',
|
|
1278
1286
|
type: 'd',
|
|
1279
1287
|
// compiler:lenByNumPer,
|
|
1280
|
-
compiler:
|
|
1288
|
+
compiler: gridBy,
|
|
1281
1289
|
values: ['auto:a'],
|
|
1282
1290
|
},
|
|
1283
1291
|
'grid-row-gap': {
|
|
@@ -1290,7 +1298,7 @@ const cssProps = {
|
|
|
1290
1298
|
alias: 'grs',
|
|
1291
1299
|
type: 'd',
|
|
1292
1300
|
// compiler:lenByNumPer,
|
|
1293
|
-
compiler:
|
|
1301
|
+
compiler: gridBy,
|
|
1294
1302
|
values: ['auto:a'],
|
|
1295
1303
|
},
|
|
1296
1304
|
'grid-template': {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import styleToAliascss from "./utils/stylesToAliascss.js";
|
|
2
2
|
export declare const getCompiler: (property: string) => {
|
|
3
|
-
alias?: string
|
|
4
|
-
property?: string
|
|
5
|
-
test?: RegExp
|
|
6
|
-
type?: string
|
|
7
|
-
values?: string[]
|
|
3
|
+
alias?: string;
|
|
4
|
+
property?: string;
|
|
5
|
+
test?: RegExp;
|
|
6
|
+
type?: string;
|
|
7
|
+
values?: string[];
|
|
8
8
|
groups?: {
|
|
9
9
|
[key: string]: string;
|
|
10
|
-
}
|
|
11
|
-
compiler?: (
|
|
10
|
+
};
|
|
11
|
+
compiler?: (a: string, b: {
|
|
12
12
|
[key: string]: {
|
|
13
13
|
[key: string]: string;
|
|
14
14
|
};
|
|
15
|
-
}) => any
|
|
15
|
+
}) => any;
|
|
16
16
|
} | null;
|
|
17
17
|
export declare const main: {
|
|
18
18
|
[key: string]: any;
|
|
19
|
-
make: (a: string, b?: string
|
|
19
|
+
make: (a: string, b?: string, c?: boolean) => string;
|
|
20
20
|
group: (a: string, b: string) => string;
|
|
21
21
|
};
|
|
22
22
|
export declare const styleJSX: (str: string, bool?: boolean) => any;
|
package/lib/node/compileFile.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import extractClassNamesFromFile from "./extractClassNamesFromFile.js";
|
|
11
|
-
import { compiler as statementMaker } from "../returnStatement
|
|
11
|
+
import { compiler as statementMaker } from "../returnStatement.js";
|
|
12
12
|
import config from "../config.js";
|
|
13
13
|
import fs from "fs";
|
|
14
14
|
import fg from "fast-glob";
|
|
@@ -62,7 +62,7 @@ export function globalCSSCompiler() {
|
|
|
62
62
|
let basePreamble = "";
|
|
63
63
|
// 1. Layer declaration
|
|
64
64
|
if (Array.isArray(init.layers) && init.layers.length > 0) {
|
|
65
|
-
basePreamble += `@layer ${init.layers.join(", ")};\n\n`;
|
|
65
|
+
basePreamble += `@layer ${init.layers.join(", ")};\n\n @layer reset{[hidden]:not([hidden="until-found"]){display:none!important}}\n\n`;
|
|
66
66
|
init.initializedLayer = true;
|
|
67
67
|
}
|
|
68
68
|
// 2. Custom CSS statements & group statements
|
|
@@ -144,14 +144,34 @@ export function compileFile(file, config, statementMaker, globalClassList) {
|
|
|
144
144
|
export function groupStatement(name, classNames, statementMaker) {
|
|
145
145
|
return statementMaker.group(classNames, name) + "\n";
|
|
146
146
|
}
|
|
147
|
+
// export function keyframesStatement(name: string, timeLine: string, statementMaker: { make: (a: string, b?: string | null, c?: boolean) => string }) {
|
|
148
|
+
// let kfStatement = "@keyframes " + name + "{\n";
|
|
149
|
+
// const returnPnV = (e: string[]) => e.map((i) => statementMaker.make(i, null, true)).join(";");
|
|
150
|
+
// const split = timeLine.split(/\s+/);
|
|
151
|
+
// split.forEach((each: string) => {
|
|
152
|
+
// try {
|
|
153
|
+
// const [at, pNv] = each.replace(/\]\[/, "]-[").replace("-", "=").split("=");
|
|
154
|
+
// kfStatement += ` ${at.replace("@", "").replace(/:/g, ",").replace(/,/g, "%,").replace(/[\[|\]]/g, "")}% {${returnPnV(
|
|
155
|
+
// splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, ""))
|
|
156
|
+
// )}}`;
|
|
157
|
+
// } catch (error) {
|
|
158
|
+
// console.error("Not a valid entry for AliasCSS keyframes processor : " + each, error);
|
|
159
|
+
// }
|
|
160
|
+
// });
|
|
161
|
+
// return kfStatement + "\n}\n";
|
|
162
|
+
// }
|
|
147
163
|
export function keyframesStatement(name, timeLine, statementMaker) {
|
|
148
164
|
let kfStatement = "@keyframes " + name + "{\n";
|
|
149
165
|
const returnPnV = (e) => e.map((i) => statementMaker.make(i, null, true)).join(";");
|
|
150
|
-
const split = timeLine.split(/\s+/);
|
|
166
|
+
const split = timeLine.trim().split(/\s+/);
|
|
151
167
|
split.forEach((each) => {
|
|
152
168
|
try {
|
|
153
|
-
|
|
154
|
-
|
|
169
|
+
// @0[…] @0-[…] @[0,25,50][…] @[0,25,50]-[…]
|
|
170
|
+
const m = each.match(/^@(\[[\d,\s%]+\]|[\d.]+)-?(\[.*\])$/);
|
|
171
|
+
if (!m)
|
|
172
|
+
throw new Error("expected @50[...] or @[0,50][...]");
|
|
173
|
+
const at = m[1].replace(/[\[\]\s%]/g, ""); // "0,25,50"
|
|
174
|
+
kfStatement += ` ${at.split(",").map((s) => s + "%").join(",")} {${returnPnV(splitByCommaOutsideParens(m[2].replace(/^\[|\]$/g, "")))}}`;
|
|
155
175
|
}
|
|
156
176
|
catch (error) {
|
|
157
177
|
console.error("Not a valid entry for AliasCSS keyframes processor : " + each, error);
|
|
@@ -187,14 +207,21 @@ export function createCSSFileByFile(file_1) {
|
|
|
187
207
|
}
|
|
188
208
|
export function postify(file_1, plugin_1) {
|
|
189
209
|
return __awaiter(this, arguments, void 0, function* (file, plugin, minify = false, sort = "mobile-first") {
|
|
210
|
+
// Ensure the file exists before attempting to read/write
|
|
190
211
|
if (!fs.existsSync(file))
|
|
191
212
|
return;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
213
|
+
try {
|
|
214
|
+
const data = fs.readFileSync(file, "utf-8");
|
|
215
|
+
const plugins = [...plugin, sortMediaQueries({ sort })];
|
|
216
|
+
if (minify) {
|
|
217
|
+
plugins.push(cssnano);
|
|
218
|
+
}
|
|
219
|
+
const result = yield postcss(plugins).process(data, { from: undefined });
|
|
220
|
+
fs.writeFileSync(file, result.css);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
console.error(`Failed to process CSS for ${file}:`, error);
|
|
224
|
+
}
|
|
198
225
|
});
|
|
199
226
|
}
|
|
200
227
|
export function writeStatementToFile(file, content, from) {
|
|
@@ -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
|
-
|
|
82
|
-
|
|
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
|
-
|
|
206
|
-
|
|
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
|
-
|
|
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
|
}
|
package/lib/returnStatement.js
CHANGED
|
@@ -14,6 +14,7 @@ import { staticClassNamesAlias } from "./static/staticClassNamesAlias.js";
|
|
|
14
14
|
import { splitByCommaOutsideParens, matchTrailingGroup, splitTopLevel, joinGroupItem } from "./utils/helper.js";
|
|
15
15
|
import cssCustomCompilers from "./custom-css-compilers.js";
|
|
16
16
|
// import customGroups from './prebuild.js';
|
|
17
|
+
import postcss from "postcss";
|
|
17
18
|
const [staticClassNamesWithAlias, cssPropsWithAlias] = createCompilerObj(cssProps, config.globalValues);
|
|
18
19
|
const NAME = '[a-zA-Z_][\\w-]*(?:\\/[a-zA-Z_][\\w-]*)*';
|
|
19
20
|
const AS_EXPORT = new RegExp(`--as-(?<names>${NAME}|\\[${NAME}(?:,${NAME})*\\])$`);
|
|
@@ -131,9 +132,12 @@ export const compiler = {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
// Budle atomice class name in new
|
|
135
|
+
// --as-name or --as-[name1,name2,…]: compile the group once per name
|
|
134
136
|
const asMatch = className.match(AS_EXPORT);
|
|
135
137
|
if ((_a = asMatch === null || asMatch === void 0 ? void 0 : asMatch.groups) === null || _a === void 0 ? void 0 : _a.names) {
|
|
136
|
-
|
|
138
|
+
const body = className.slice(0, asMatch.index);
|
|
139
|
+
const names = asMatch.groups.names.replace(/^\[|\]$/g, '').split(',');
|
|
140
|
+
return names.map((name) => this.group(body, name)).join('');
|
|
137
141
|
}
|
|
138
142
|
let unPrefixedClassName = className;
|
|
139
143
|
// check for [group-acss,]
|
|
@@ -265,12 +269,19 @@ export const compiler = {
|
|
|
265
269
|
else {
|
|
266
270
|
stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
|
|
267
271
|
}
|
|
268
|
-
|
|
272
|
+
try {
|
|
273
|
+
postcss.parse(stm);
|
|
269
274
|
return stm;
|
|
270
|
-
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
console.log('Not a Valid CSS Statement, PostCSS Parse:', className, " => ", stm);
|
|
278
|
+
}
|
|
279
|
+
// if (isSafeCss(stm)) return stm;
|
|
280
|
+
// console.warn(`AliasCSS: "${as ? as : className}" produced invalid CSS:`, stm);
|
|
271
281
|
}
|
|
272
282
|
else {
|
|
273
|
-
|
|
283
|
+
// extractProperty returns [property, key] even when nothing matched, so test the property itself
|
|
284
|
+
const looksLikeAcss = ACSS_SYNTAX.test(className) || !!extractProperty(pnv, this.cssProps)[0];
|
|
274
285
|
if (!this.groupDepth && (looksLikeAcss || config.debug)) {
|
|
275
286
|
console.warn(`AliasCSS: can't compile "${className}"`);
|
|
276
287
|
}
|
|
@@ -408,9 +419,16 @@ export const compiler = {
|
|
|
408
419
|
else {
|
|
409
420
|
stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
|
|
410
421
|
}
|
|
411
|
-
if
|
|
422
|
+
// Check if the generated statement is valid CSS using PostCSS parser
|
|
423
|
+
try {
|
|
424
|
+
postcss.parse(stm);
|
|
412
425
|
return stm;
|
|
413
|
-
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
console.log('Not a Valid CSS Statement, PostCSS Parse:', stm);
|
|
429
|
+
}
|
|
430
|
+
// if (isSafeCss(stm)) return stm;
|
|
431
|
+
// console.log('Not a Valid CSS Statement:', stm);
|
|
414
432
|
}
|
|
415
433
|
else {
|
|
416
434
|
console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`);
|
package/lib/utils/cssFunc.js
CHANGED
|
@@ -4,6 +4,8 @@ export function repeat(data) {
|
|
|
4
4
|
if (data.match(/-repeat[(]/)) {
|
|
5
5
|
return data.replace(/^-/, '');
|
|
6
6
|
}
|
|
7
|
+
// "." works like "d" and "%" like "p" (same rule as length/gradient)
|
|
8
|
+
data = data.replace(/(\d)\.(\d)/g, '$1d$2').replace(/%/g, 'p');
|
|
7
9
|
data = data.replace(/repeat/g, '===');
|
|
8
10
|
const matchRegex = /===-([\d]+|auto-fill|auto-fit)-([a-z0-9-]+)/;
|
|
9
11
|
while (data.match(matchRegex)) {
|