aliascss 1.5.1 → 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.
@@ -84,6 +84,7 @@ export let classPrinter = {
84
84
  [...el.attributes].map((each) => {
85
85
  // ------------
86
86
  // Raw-CSS Statement
87
+ var _a;
87
88
  // class-group
88
89
  if (testRegExp.test(each.name)) {
89
90
  let value = each.value;
@@ -110,22 +111,29 @@ export let classPrinter = {
110
111
  // }
111
112
  // }
112
113
  if (testRegExpKF.test(each.name)) {
113
- const key = each.name.replace(testRegExpKF, '');
114
- let kfStatement = '@keyframes ' + this.kfNames[key] + "{\n";
115
- const returnPnV = (e) => e.map((i) => statementMaker.make(i, undefined, true)).join(";");
116
- const split = each.value.trim().split(/\s+/);
117
- split.forEach((each) => {
118
- try {
119
- const [at, pNv] = each.replace(/\]\[/, ']-[').replace("-", "=").split("=");
120
- // const result=returnPnV(pNv.replace(/^\[|\]$/g,'').split(','));
121
- const result = returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, '')));
122
- kfStatement += ` ${at.replace('@', '').replace(/:/g, ',').replace(/,/g, "%,").replace(/[\[|\]]/g, '')}% {${result ? result : ''}}`;
123
- }
124
- catch (error) {
125
- console.log('invalid Entry for AliasCSS keyframes processor : ' + each, error);
126
- }
127
- });
128
- this.appendToStyleTag(kfStatement + "\n}");
114
+ const key = each.name.replace(testRegExpKF, ''); // already lower-case (HTML does that)
115
+ const name = (_a = this.kfNames[key]) !== null && _a !== void 0 ? _a : key;
116
+ const doneKey = name + '\u0000' + each.value;
117
+ if (!this.doneKeyframes.has(doneKey)) { // add once, like doneGroups
118
+ this.doneKeyframes.add(doneKey);
119
+ const returnPnV = (e) => e.map((i) => statementMaker.make(i, undefined, true)).join(';');
120
+ let steps = '';
121
+ each.value.trim().split(/\s+/).forEach((step) => {
122
+ try {
123
+ // @0[…] @0-[…] @50%[…] @[0,25,50][…] @[0,25,50]-[…]
124
+ const m = step.match(/^@(\[[\d.,%]+\]|[\d.]+%?)-?(\[.*\])$/);
125
+ if (!m)
126
+ throw new Error('expected @50[...] or @[0,50][...]');
127
+ const at = m[1].replace(/[\[\]%]/g, ''); // "0,25,50"
128
+ steps += ` ${at.split(',').map((s) => s + '%').join(',')} {${returnPnV(splitByCommaOutsideParens(m[2].replace(/^\[|\]$/g, '')))}}`;
129
+ }
130
+ catch (error) {
131
+ console.log('invalid Entry for AliasCSS keyframes processor : ' + step, error);
132
+ }
133
+ });
134
+ if (steps)
135
+ this.appendToStyleTag('@keyframes ' + name + '{\n' + steps + '\n}');
136
+ }
129
137
  }
130
138
  });
131
139
  // if has value to process
@@ -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: (value) => value.replace(/--([\d])/g, '-Minus$1').replace(/^-/, '').replace(/-by-/g, " / ").replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ').replace(/[-]?Minus[\s]*/g, '-'),
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: (value) => value.replace(/--([\d])/g, '-Minus$1').replace(/^-/, '').replace(/-by-/g, " / ").replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ').replace(/[-]?Minus[\s]*/g, '-'),
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: (value) => value.replace(/--([\d])/g, '-Minus$1').replace(/^-/, '').replace(/-by-/g, " / ").replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ').replace(/[-]?Minus[\s]*/g, '-'),
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: (value) => value.replace(/--([\d])/g, '-Minus$1').replace(/^-/, '').replace(/-by-/g, " / ").replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ').replace(/[-]?Minus[\s]*/g, '-'),
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: (value) => value.replace(/--([\d])/g, '-Minus$1').replace(/^-/, '').replace(/-by-/g, " / ").replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ').replace(/[-]?Minus[\s]*/g, '-'),
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: (value) => value.replace(/--([\d])/g, '-Minus$1').replace(/^-/, '').replace(/-by-/g, " / ").replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ').replace(/[-]?Minus[\s]*/g, '-'),
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: (value) => value.replace(/--([\d])/g, '-Minus$1').replace(/^-/, '').replace(/-by-/g, " / ").replace(/[-]?(span|[-]?[\d]+)[-]?/g, ' $1 ').replace(/[-]?Minus[\s]*/g, '-'),
1301
+ compiler: gridBy,
1294
1302
  values: ['auto:a'],
1295
1303
  },
1296
1304
  'grid-template': {
@@ -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
- const [at, pNv] = each.replace(/\]\[/, "]-[").replace("-", "=").split("=");
154
- kfStatement += ` ${at.replace("@", "").replace(/:/g, ",").replace(/,/g, "%,").replace(/[\[|\]]/g, "")}% {${returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, "")))}}`;
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
- const data = fs.readFileSync(file, "utf-8");
193
- const plugins = [...plugin, sortMediaQueries({ sort })];
194
- if (minify)
195
- plugins.push(cssnano);
196
- const result = yield postcss(plugins).process(data, { from: undefined });
197
- fs.writeFileSync(file, result.css);
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) {
@@ -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})*\\])$`);
@@ -268,9 +269,15 @@ export const compiler = {
268
269
  else {
269
270
  stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
270
271
  }
271
- if (isSafeCss(stm))
272
+ try {
273
+ postcss.parse(stm);
272
274
  return stm;
273
- console.warn(`AliasCSS: "${as ? as : className}" produced invalid CSS:`, stm);
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);
274
281
  }
275
282
  else {
276
283
  // extractProperty returns [property, key] even when nothing matched, so test the property itself
@@ -412,9 +419,16 @@ export const compiler = {
412
419
  else {
413
420
  stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
414
421
  }
415
- if (isSafeCss(stm))
422
+ // Check if the generated statement is valid CSS using PostCSS parser
423
+ try {
424
+ postcss.parse(stm);
416
425
  return stm;
417
- console.log('Not a Valid CSS Statement:', stm);
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);
418
432
  }
419
433
  else {
420
434
  console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`);
@@ -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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aliascss",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "AliasCSS is a CSS post processor.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",