aliascss 1.4.0 → 1.4.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.
@@ -1,4 +1,6 @@
1
1
  import { compiler as statementMaker } from './returnStatement.js';
2
+ import config from './config.js';
3
+ // import mapRawAttributeNames from './utils/browser-helper.js';
2
4
  export default statementMaker;
3
5
  export let classPrinter = {
4
6
  invalidLists: [],
@@ -6,6 +8,8 @@ export let classPrinter = {
6
8
  styleTagExists: false,
7
9
  customCheck: false,
8
10
  useColon: true,
11
+ cls: {},
12
+ kfs: {},
9
13
  kfNames: {},
10
14
  styleTag: null,
11
15
  createStyleTag() {
@@ -15,6 +19,9 @@ export let classPrinter = {
15
19
  const styleTag = document.createElement('style');
16
20
  styleTag.id = 'styleAlias';
17
21
  document.getElementsByTagName('head')[0].appendChild(styleTag);
22
+ // initialize @layer for reset, base, theme, components and utilities
23
+ const initLayer = document.createTextNode(`@layer ${config.layers.join(', ')};`);
24
+ styleTag.appendChild(initLayer);
18
25
  this.styleTag = styleTag;
19
26
  this.styleTagExists = true;
20
27
  return styleTag;
@@ -45,7 +52,7 @@ export let classPrinter = {
45
52
  let attrValue = '';
46
53
  const testRegExp = this.useColon ? /class[-_:]/ : /class[-_]/;
47
54
  const testRegExpKF = this.useColon ? /keyframes[-_:]/ : /keyframes[-_]/;
48
- const rawCSS = /data-raw-css/;
55
+ // const rawCSS=/data-raw-css/;
49
56
  // if class
50
57
  if (el.getAttribute('class'))
51
58
  attrValue += ' ' + el.getAttribute('class');
@@ -219,11 +226,18 @@ export let classPrinter = {
219
226
  return statement;
220
227
  },
221
228
  run(el) {
222
- // const event = new Event('acss:init');
223
229
  var _a;
224
230
  const $root = el || document;
225
231
  // $root.dispatchEvent(event);
226
232
  $root.dispatchEvent(new CustomEvent('acss:init', { bubbles: true, detail: { aliascss: this } }));
233
+ // mapRawAttributeNames().then(({ kfs, cls }) => {
234
+ // // Use the variables inside this block
235
+ // this.cls = cls;
236
+ // this.kfs = kfs;
237
+ // }).catch(error => {
238
+ // console.error("cannot initialize keyframes and class-grouping for case free names:", error);
239
+ // });
240
+ // const event = new Event('acss:init');
227
241
  // create a keyframes object to fix case-sensitive issue
228
242
  (_a = (el || document.body).outerHTML.match(/keyframes-[a-z0-9_-]+(?==)/gi)) === null || _a === void 0 ? void 0 : _a.forEach((each) => {
229
243
  this.kfNames[each.replace('keyframes-', '').toLowerCase()] = each.replace('keyframes-', '');
package/lib/config.d.ts CHANGED
@@ -18,6 +18,7 @@ declare const config: {
18
18
  remUnitsNegative: string[];
19
19
  widths: string[];
20
20
  modes: string[];
21
+ layers: string[];
21
22
  makeStaticGlobalValues?: (a: string, b: string) => string[];
22
23
  };
23
24
  export default config;
package/lib/config.js CHANGED
@@ -2,6 +2,7 @@ const config = {
2
2
  prefix: null,
3
3
  useColon: false,
4
4
  ignore: [],
5
+ layers: ['reset', 'base', 'theme', 'components', 'utilities', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'],
5
6
  useExtractorFunction: false, // (?<=x(`|\(['"]))([\s\w-\(\)]+)[^`"']
6
7
  matchExtractorFunction: new RegExp('(?:' + 'x|@' + ')' + "[\\s*]?(`|\\([" + `"'])` + "([^)`]+)" + "(`|" + `["']` + "\\))"),
7
8
  useCSSModule: false,
@@ -13,7 +14,8 @@ const config = {
13
14
  matchRegExpWithColonKeyFrame: /[\s](?:(keyframes[-_:][\w-]+))=[\s*]?(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/,
14
15
  createExtractorRegex: (fname) => new RegExp('(?:' + fname + ')' + "[\\s*]?(`|\\([" + `"'])` + "([^'`" + '"]+)' + "(`|" + `["']` + "\\))"),
15
16
  createCSSModuleRegex: (fname) => new RegExp("(?:" + fname + ")\\[[`'" + '"]([^`"' + "']+)(?:[`'" + '"]\\])'),
16
- globalValues: ['initial:ini', 'inherit:in', 'unset:un', 'revert:re', 'revert-layer:rl'],
17
+ // globalValues:['initial:ini','inherit:in','unset:un', 'revert:re','revert-layer:rl'],
18
+ globalValues: ['initial', 'inherit', 'unset', 'revert', 'revert-layer'],
17
19
  // makeStaticGlobalValues:(property:string,alias?:string)=>{
18
20
  // },
19
21
  styles: ['dotted:d', 'dashed:da', 'solid:s', 'double:db', 'groove:g', 'ridge:ri', 'inset:i', 'outset:o', 'none:n', 'hidden:h'],
@@ -441,7 +441,7 @@ const cssProps = {
441
441
  'border-boundary': {
442
442
  alias: '',
443
443
  type: 's',
444
- 'values': ['none:n', 'patent:p', 'display:d']
444
+ 'values': ['none:n', 'parent:p', 'display:d']
445
445
  },
446
446
  'border-collapse': {
447
447
  alias: '',
@@ -1157,8 +1157,8 @@ const cssProps = {
1157
1157
  },
1158
1158
  'font-weight': {
1159
1159
  alias: 'fw',
1160
- type: 's',
1161
- // compiler:'',
1160
+ type: 'd',
1161
+ compiler: (value, custom) => value.replace(/^-/, ''),
1162
1162
  values: ['bolder:b2:blr', 'lighter:l:ltr', '100:1:thin', '200:2:extra-light', '300:3:light', '400:4:normal:nl:regular', '500:5:medium', '600:6:semi-bold', '700:7:bold', '800:8:extra-bold', '900:9:black'],
1163
1163
  },
1164
1164
  'forced-color-adjust': {
@@ -2757,10 +2757,10 @@ const cssProps = {
2757
2757
  alias: 'slj',
2758
2758
  type: 's',
2759
2759
  // compiler:'',
2760
- values: ['arcs', 'bevel', 'iter', 'miter-clip', 'round'],
2760
+ values: ['arcs', 'bevel', 'miter', 'miter-clip', 'round'],
2761
2761
  },
2762
2762
  // -------------webkit---
2763
- 'webkit-line-cramp': {
2763
+ 'webkit-line-clamp': {
2764
2764
  alias: '',
2765
2765
  property: '-webkit-line-clamp',
2766
2766
  type: 'd',
@@ -19,6 +19,7 @@ const init = {
19
19
  config,
20
20
  '--module': false,
21
21
  rawCSS: '',
22
+ layers: [],
22
23
  customGroupStatement: '',
23
24
  minify: false,
24
25
  globPattern: '', // Use this to check valid new created file to add to watch during watch.on
@@ -49,7 +50,8 @@ export function globalCSSCompiler() {
49
50
  input.forEach((file) => {
50
51
  const [gbContent,] = compileFile(file, config, statementMaker, classList);
51
52
  try {
52
- fs.writeFileSync(init.output, `\n/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${gbContent}
53
+ fs.writeFileSync(init.output, `@layer ${init.layers.join(', ')};
54
+ \n/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${gbContent}
53
55
  \n/* End :-----------ACSS ${path.relative('.', file)}----------------------------*/\n
54
56
  `, { flag: 'a+' });
55
57
  console.log('AliasCSS compiled', path.relative('.', file), 'to main css file :' + init.output);
@@ -226,6 +228,13 @@ export function initialize(configFile) {
226
228
  init.input = configFile.input;
227
229
  init.globPattern = configFile.input;
228
230
  }
231
+ // ----------------input-------------------
232
+ if (configFile.hasOwnProperty('layers') && Array.isArray(configFile.layers)) {
233
+ init.layers = configFile.layers;
234
+ }
235
+ else {
236
+ init.layers = config.layers;
237
+ }
229
238
  // ----------------Prefix-------------------
230
239
  if (configFile.hasOwnProperty('prefix')) {
231
240
  init.config.prefix = configFile.prefix;
@@ -302,6 +311,7 @@ export function initialize(configFile) {
302
311
  else {
303
312
  if (fs.existsSync(init.output))
304
313
  fs.truncateSync(path.resolve(init.output));
314
+ writeStatementToFile(init.output, `@layer ${init.layers.join(', ')};`, 'Initializating @layer,');
305
315
  }
306
316
  // Custom CSS statement
307
317
  if (configFile.hasOwnProperty('statement')) {
@@ -8,7 +8,7 @@ export default function extractMediaPrefix(className, prefix, match, bool = fals
8
8
  const prefixMedia = (_a = className.match(match)) === null || _a === void 0 ? void 0 : _a[0];
9
9
  if (prefixMedia) {
10
10
  if (prefix.hasOwnProperty(prefixMedia)) {
11
- medias.push(prefix[prefixMedia]);
11
+ medias.push(prefix[prefixMedia] + '::::' + prefixMedia);
12
12
  cls = className.replace(prefixMedia, '');
13
13
  // return [[], ]
14
14
  }
@@ -22,11 +22,14 @@ export default function extractMediaPrefix(className, prefix, match, bool = fals
22
22
  const prefixMedia = ((_a = suffixedMatch.match(match)) === null || _a === void 0 ? void 0 : _a[0]) || ((_b = ('@' + suffixedMatch).match(match)) === null || _b === void 0 ? void 0 : _b[0]);
23
23
  if (prefixMedia) {
24
24
  if (prefix.hasOwnProperty(prefixMedia)) {
25
- medias.push(prefix[prefixMedia]);
25
+ medias.push(prefix[prefixMedia] + '::::' + prefixMedia);
26
26
  // return [[], ]
27
27
  }
28
28
  }
29
29
  }
30
+ else {
31
+ medias.push('@' + e + '::::' + 'Custom');
32
+ }
30
33
  });
31
34
  if (medias.length) {
32
35
  cls = className.replace(matchNestedMedia, '');
@@ -60,7 +60,7 @@ export default function extractPrefix(className) {
60
60
  match = true;
61
61
  }
62
62
  else if (fallbackSelector.test.test(workingClassName)) {
63
- console.log('=-=-=-=-=-=--=', workingClassName);
63
+ // console.log('=-=-=-=-=-=--=',workingClassName);
64
64
  const [replacedClassName, selector] = fallbackSelector.process(workingClassName);
65
65
  if (result.match(/:(not|where|has|is)[)]?$/)) {
66
66
  const m = result.match(/:(not|where|has|is)([)])?$/);
@@ -3,16 +3,16 @@ const media = {
3
3
  test: new RegExp("^(" + "print|xs|sm|md|lg|xl|xxl|-xs|-sm|-md|-lg|-xl|-xxl|-2xl" + ")(?=[-|_])"),
4
4
  target: {
5
5
  print: '@media print',
6
- '@hover': '@media screen and (hover: hover)',
7
6
  '@print': '@media print',
7
+ '@hover-capable': '@media screen and (hover: hover)',
8
8
  '@landscape': '@media (orientation: landscape)',
9
9
  '@portrait': '@media (orientation: portrait)',
10
- '@container-xs': '@container (max-width : 576px)',
11
- '@container-sm': '@container (min-width : 576px)',
12
- '@container-md': '@container (min-width : 768px)',
13
- '@container-lg': '@container (min-width : 992px)',
14
- '@container-xl': '@container (min-width : 1200px)',
15
- '@container-2xl': '@container (min-width : 1408px)',
10
+ '@container-xs': '@container (max-width: 576px)',
11
+ '@container-sm': '@container (min-width: 576px)',
12
+ '@container-md': '@container (min-width: 768px)',
13
+ '@container-lg': '@container (min-width: 992px)',
14
+ '@container-xl': '@container (min-width: 1200px)',
15
+ '@container-xxl': '@container (min-width: 1408px)',
16
16
  '@forced-color-active': '@media (forced-colors: active)',
17
17
  '@fca': '@media (forced-colors: active)',
18
18
  '@standalone': '@media (display-mode: standalone)',
@@ -27,45 +27,32 @@ const media = {
27
27
  '@resolution-xl': '@media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 288dpi)',
28
28
  '@contrast-more': '@media (prefers-contrast: more)',
29
29
  '@data-reduce': '@media (prefers-reduced-data: reduce)',
30
- xs: '@media (max-width : 576px)',
31
- '@xs': '@media (max-width : 576px)',
32
- sm: '@media (min-width : 576px)',
33
- '@sm': '@media (min-width : 576px)',
34
- md: '@media (min-width : 768px)',
35
- '@md': '@media (min-width : 768px)',
36
- lg: '@media (min-width : 992px)',
37
- '@lg': '@media (min-width : 992px)',
38
- xl: '@media (min-width : 1200px)',
39
- '@xl': '@media (min-width : 1200px)',
40
- // xxl: '@media (min-width : 1408px)',
41
- '@2xl': '@media (min-width : 1408px)',
42
- '2xl': '@media (min-width : 1408px)',
43
- '-xs': '@media (min-width : 576px)',
44
- '-@xs': '@media (min-width : 576px)',
45
- '-@sm': '@media (max-width : 576px)',
46
- '-sm': '@media (max-width : 576px)',
47
- '-@md': '@media (max-width : 768px)',
48
- '-md': '@media (max-width : 768px)',
49
- '-@lg': '@media (max-width : 992px)',
50
- '-lg': '@media (max-width : 992px)',
51
- '-@xl': '@media (max-width : 1200px)',
52
- '-xl': '@media (max-width : 1200px)',
53
- // '-@xxl': '@media (max-width : 1408px)',
54
- // '-xxl': '@media (max-width : 1408px)',
55
- '-@2xl': '@media (max-width : 1408px)',
56
- '-2xl': '@media (max-width : 1408px)',
57
- 'dark': '@media (prefers-color-scheme: dark)',
30
+ xs: '@media (max-width: 575.99px)',
31
+ '@xs': '@media (max-width: 575.99px)',
32
+ sm: '@media (min-width: 576px)',
33
+ '@sm': '@media (min-width: 576px)',
34
+ md: '@media (min-width: 768px)',
35
+ '@md': '@media (min-width: 768px)',
36
+ lg: '@media (min-width: 992px)',
37
+ '@lg': '@media (min-width: 992px)',
38
+ xl: '@media (min-width: 1200px)',
39
+ '@xl': '@media (min-width: 1200px)',
40
+ xxl: '@media (min-width: 1408px)',
41
+ '@xxl': '@media (min-width: 1408px)',
42
+ dark: '@media (prefers-color-scheme: dark)',
58
43
  '@dark': '@media (prefers-color-scheme: dark)',
59
- 'light': '@media (prefers-color-scheme: light)',
44
+ light: '@media (prefers-color-scheme: light)',
60
45
  '@light': '@media (prefers-color-scheme: light)',
61
46
  '@theme': '@layer theme',
62
47
  '@base': '@layer base',
48
+ '@reset': '@layer reset',
49
+ '@rs': '@layer reset',
63
50
  '@components': '@layer components',
64
51
  '@comps': '@layer components',
65
52
  '@utils': '@layer utilities',
66
53
  '@utilities': '@layer utilities',
67
54
  '@starting-style': '@starting-style',
68
- '@ss': '@starting-style',
55
+ '@ss': '@starting-style'
69
56
  },
70
57
  };
71
58
  export function createRegexForMedia(prefix) {
@@ -34,13 +34,13 @@ bool = false) {
34
34
  if (/^\(.+\)[_]?$/.test(value)) {
35
35
  if (value.match(/_$/)) {
36
36
  // replace --[name] with var(--[name])
37
- const val = value.replace(/(--[\w-]+)/g, 'var($1)')
37
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
38
38
  .replace(/^[(]/, '').replace(/_$/, '').replace(/[)]$/, '')
39
39
  .replace(/,/g, ', ');
40
40
  value = val.replace(/_/g, ' ');
41
41
  }
42
42
  else {
43
- const val = value.replace(/(--[\w-]+)/g, 'var($1)')
43
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
44
44
  .replace(/^[(]/, '').replace(/[)]$/, '')
45
45
  .replace(/,/g, ' ');
46
46
  value = val.replace(/_/g, ' ');
@@ -131,14 +131,14 @@ bool = false) {
131
131
  // New Update function value
132
132
  if (/^\(.+\)[_]?$/.test(valuePortion)) {
133
133
  if (valuePortion.match(/_$/)) {
134
- const val = valuePortion.replace(/(--[\w-]+)/g, 'var($1)')
134
+ const val = valuePortion.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
135
135
  .replace(/^[(]/, '').replace(/_$/, '').replace(/[)]$/, '')
136
136
  .replace(/,/g, ', ')
137
137
  .replace(/[_]/g, ' ');
138
138
  return bool ? [prop, val] : prop + ":" + val;
139
139
  }
140
140
  else {
141
- const val = valuePortion.replace(/(--[\w-]+)/g, 'var($1)')
141
+ const val = valuePortion.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
142
142
  .replace(/^[(]/, '').replace(/[)]$/, '')
143
143
  .replace(/,/g, ' ')
144
144
  .replace(/[_]/g, ' ');
@@ -157,13 +157,13 @@ bool = false) {
157
157
  // check if has :()
158
158
  if (/^\(.+\)[_]?$/.test(value)) {
159
159
  if (value.match(/_$/)) {
160
- const val = value.replace(/(--[\w-]+)/g, 'var($1)')
160
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
161
161
  .replace(/^[(]/, '').replace(/_$/, '').replace(/[)]$/, '')
162
162
  .replace(/,/g, ', ');
163
163
  value = val;
164
164
  }
165
165
  else {
166
- const val = value.replace(/(--[\w-]+)/g, 'var($1)')
166
+ const val = value.replace(/(?<!var\()(--[\w-]+)/g, 'var($1)')
167
167
  .replace(/^[(]/, '').replace(/[)]$/, '')
168
168
  .replace(/,/g, ' ');
169
169
  value = val;
@@ -155,15 +155,23 @@ export const compiler = {
155
155
  // ------------PostCSSParse
156
156
  if (result) {
157
157
  let stm = '';
158
- className = (as ? as : className).replace(/([$.&%=\]\[@~,:*#+\(\)\/^])/g, '\\$1');
158
+ className = (as ? as : className).replace(/([$.&%=\]\[@~,:*#+\(\)\/^/</>])/g, '\\$1');
159
159
  if (bool === true)
160
160
  return result;
161
161
  this.cache.propertyAndValue[pnv] = result;
162
162
  if (mediaEX.length) {
163
163
  let [bf, af] = ['', ''];
164
164
  mediaEX.map((e) => {
165
- bf = bf + e + "{ ";
166
- af = af + "}";
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
+ }
167
175
  });
168
176
  stm = `${bf}${beforeClassNameSelector + '.' + className + elementAndPseudo}{${result}${important}}${af}`;
169
177
  }
@@ -182,6 +190,9 @@ export const compiler = {
182
190
  console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`);
183
191
  }
184
192
  },
193
+ // groupSingle(str:string, as:string){
194
+ // let pnv='';
195
+ // },
185
196
  group(str, as) {
186
197
  let statement = '';
187
198
  [...str.trim().split(/\s+/)].forEach((e) => {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ // async function mapRawAttributeNames() {
2
+ // const maps = {
3
+ // kfs: Object.create(null),
4
+ // cls: Object.create(null),
5
+ // };
6
+ export {};
7
+ // const response = await fetch(window.location.href);
8
+ // const html = await response.text();
9
+ // const tagRegex = /<([A-Za-z][A-Za-z0-9:_-]*)(?:\s+[\s\S]*?)?>/g;
10
+ // const attributeRegex =
11
+ // /([A-Za-z_:][A-Za-z0-9_.:-]*)(?=\s*(?:=|$))/g;
12
+ // const prefixes = [
13
+ // ["keyframes", maps.kfs],
14
+ // ["class", maps.cls],
15
+ // ];
16
+ // let tag;
17
+ // while ((tag = tagRegex.exec(html))) {
18
+ // attributeRegex.lastIndex = 0;
19
+ // let match;
20
+ // while ((match = attributeRegex.exec(tag[0]))) {
21
+ // const rawName = match[1];
22
+ // const name = rawName.toLowerCase();
23
+ // for (const [prefix, map] of prefixes) {
24
+ // if (
25
+ // name.startsWith(`${prefix}-`) ||
26
+ // name.startsWith(`${prefix}_`) ||
27
+ // name.startsWith(`${prefix}:`)
28
+ // ) {
29
+ // map[name] = rawName;
30
+ // break;
31
+ // }
32
+ // }
33
+ // }
34
+ // }
35
+ // return maps;
36
+ // }
37
+ // export default mapRawAttributeNames;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aliascss",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "AliasCSS is a CSS post processor.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/tsconfig.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "es6",
4
4
  "module": "nodenext",
5
+ "rootDir": "./src",
5
6
  "declaration": true,
6
7
  "outDir": "./lib",
7
8
  "esModuleInterop": true,