@unocss/transformer-compile-class 0.52.5 → 0.52.7

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/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ const core = require('@unocss/core');
4
4
 
5
5
  function transformerCompileClass(options = {}) {
6
6
  const {
7
- trigger = /(["'`]):uno:\s([^\1]*?)\1/g,
7
+ trigger = /(["'`]):uno(?:-)?(?<name>[^\s\1]+)?:\s([^\1]*?)\1/g,
8
8
  classPrefix = "uno-",
9
9
  hashFn = hash,
10
10
  keepUnknown = true
@@ -30,9 +30,20 @@ function transformerCompileClass(options = {}) {
30
30
  }
31
31
  if (body) {
32
32
  body = body.split(/\s+/).sort().join(" ");
33
- const className = match.groups && match.groups.name ? `${classPrefix}${match.groups.name}` : `${classPrefix}${hashFn(body)}`;
34
- if (tokens && tokens.has(className))
35
- throw new Error(`duplicate compile class name '${className}', please choose different class name`);
33
+ let hash2;
34
+ let explicitName = false;
35
+ if (match.groups && match.groups.name) {
36
+ hash2 = match.groups.name;
37
+ explicitName = true;
38
+ } else {
39
+ hash2 = hashFn(body);
40
+ }
41
+ const className = `${classPrefix}${hash2}`;
42
+ if (tokens && tokens.has(className) && explicitName) {
43
+ const existing = uno.config.shortcuts.find((i) => i[0] === className);
44
+ if (existing && existing[1] !== body)
45
+ throw new Error(`Duplicated compile class name "${className}". One is "${body}" and the other is "${existing[1]}" Please choose different class name`);
46
+ }
36
47
  replacements.unshift(className);
37
48
  if (options.layer)
38
49
  uno.config.shortcuts.push([className, body, { layer: options.layer }]);
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ interface CompileClassOptions {
28
28
  * This parameter is backwards compatible. It accepts string only trigger
29
29
  * words, like `:uno:` or a regex literal.
30
30
  *
31
- * @default `/(["'`]):uno:\s([^\1]*?)\1/g`
31
+ * @default `/(["'`]):uno(?:-)?(?<name>[^\s\1]+)?:\s([^\1]*?)\1/g`
32
32
  */
33
33
  trigger?: string | RegExp;
34
34
  /**
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { escapeRegExp, expandVariantGroup } from '@unocss/core';
2
2
 
3
3
  function transformerCompileClass(options = {}) {
4
4
  const {
5
- trigger = /(["'`]):uno:\s([^\1]*?)\1/g,
5
+ trigger = /(["'`]):uno(?:-)?(?<name>[^\s\1]+)?:\s([^\1]*?)\1/g,
6
6
  classPrefix = "uno-",
7
7
  hashFn = hash,
8
8
  keepUnknown = true
@@ -28,9 +28,20 @@ function transformerCompileClass(options = {}) {
28
28
  }
29
29
  if (body) {
30
30
  body = body.split(/\s+/).sort().join(" ");
31
- const className = match.groups && match.groups.name ? `${classPrefix}${match.groups.name}` : `${classPrefix}${hashFn(body)}`;
32
- if (tokens && tokens.has(className))
33
- throw new Error(`duplicate compile class name '${className}', please choose different class name`);
31
+ let hash2;
32
+ let explicitName = false;
33
+ if (match.groups && match.groups.name) {
34
+ hash2 = match.groups.name;
35
+ explicitName = true;
36
+ } else {
37
+ hash2 = hashFn(body);
38
+ }
39
+ const className = `${classPrefix}${hash2}`;
40
+ if (tokens && tokens.has(className) && explicitName) {
41
+ const existing = uno.config.shortcuts.find((i) => i[0] === className);
42
+ if (existing && existing[1] !== body)
43
+ throw new Error(`Duplicated compile class name "${className}". One is "${body}" and the other is "${existing[1]}" Please choose different class name`);
44
+ }
34
45
  replacements.unshift(className);
35
46
  if (options.layer)
36
47
  uno.config.shortcuts.push([className, body, { layer: options.layer }]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/transformer-compile-class",
3
- "version": "0.52.5",
3
+ "version": "0.52.7",
4
4
  "description": "Compile group of classes into one class",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@unocss/core": "0.52.5"
36
+ "@unocss/core": "0.52.7"
37
37
  },
38
38
  "devDependencies": {
39
39
  "magic-string": "^0.30.0"