@unocss/transformer-compile-class 0.57.6 → 0.58.0
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 +5 -2
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +5 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,8 @@ function transformerCompileClass(options = {}) {
|
|
|
7
7
|
trigger = /(["'`]):uno(?:-)?(?<name>[^\s\1]+)?:\s([^\1]*?)\1/g,
|
|
8
8
|
classPrefix = "uno-",
|
|
9
9
|
hashFn = hash,
|
|
10
|
-
keepUnknown = true
|
|
10
|
+
keepUnknown = true,
|
|
11
|
+
alwaysHash = false
|
|
11
12
|
} = options;
|
|
12
13
|
const compiledClass = /* @__PURE__ */ new Set();
|
|
13
14
|
const regexp = typeof trigger === "string" ? RegExp(`(["'\`])${core.escapeRegExp(trigger)}\\s([^\\1]*?)\\1`, "g") : trigger;
|
|
@@ -36,6 +37,8 @@ function transformerCompileClass(options = {}) {
|
|
|
36
37
|
let explicitName = false;
|
|
37
38
|
if (match.groups && match.groups.name) {
|
|
38
39
|
hash2 = match.groups.name;
|
|
40
|
+
if (alwaysHash)
|
|
41
|
+
hash2 += `-${hashFn(body)}`;
|
|
39
42
|
explicitName = true;
|
|
40
43
|
} else {
|
|
41
44
|
hash2 = hashFn(body);
|
|
@@ -44,7 +47,7 @@ function transformerCompileClass(options = {}) {
|
|
|
44
47
|
if (tokens && tokens.has(className) && explicitName) {
|
|
45
48
|
const existing = uno.config.shortcuts.find((i) => i[0] === className);
|
|
46
49
|
if (existing && existing[1] !== body)
|
|
47
|
-
throw new Error(`Duplicated compile class name "${className}". One is "${body}" and the other is "${existing[1]}" Please choose different class name
|
|
50
|
+
throw new Error(`Duplicated compile class name "${className}". One is "${body}" and the other is "${existing[1]}". Please choose different class name or set 'alwaysHash' to 'true'.`);
|
|
48
51
|
}
|
|
49
52
|
compiledClass.add(className);
|
|
50
53
|
replacements.unshift(className);
|
package/dist/index.d.cts
CHANGED
|
@@ -40,6 +40,12 @@ interface CompileClassOptions {
|
|
|
40
40
|
* Hash function
|
|
41
41
|
*/
|
|
42
42
|
hashFn?: (str: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Allow add hash to class name even if the class name is explicitly defined
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
alwaysHash?: boolean;
|
|
43
49
|
/**
|
|
44
50
|
* Left unknown classes inside the string
|
|
45
51
|
*
|
package/dist/index.d.mts
CHANGED
|
@@ -40,6 +40,12 @@ interface CompileClassOptions {
|
|
|
40
40
|
* Hash function
|
|
41
41
|
*/
|
|
42
42
|
hashFn?: (str: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Allow add hash to class name even if the class name is explicitly defined
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
alwaysHash?: boolean;
|
|
43
49
|
/**
|
|
44
50
|
* Left unknown classes inside the string
|
|
45
51
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ interface CompileClassOptions {
|
|
|
40
40
|
* Hash function
|
|
41
41
|
*/
|
|
42
42
|
hashFn?: (str: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Allow add hash to class name even if the class name is explicitly defined
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
alwaysHash?: boolean;
|
|
43
49
|
/**
|
|
44
50
|
* Left unknown classes inside the string
|
|
45
51
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,8 @@ function transformerCompileClass(options = {}) {
|
|
|
5
5
|
trigger = /(["'`]):uno(?:-)?(?<name>[^\s\1]+)?:\s([^\1]*?)\1/g,
|
|
6
6
|
classPrefix = "uno-",
|
|
7
7
|
hashFn = hash,
|
|
8
|
-
keepUnknown = true
|
|
8
|
+
keepUnknown = true,
|
|
9
|
+
alwaysHash = false
|
|
9
10
|
} = options;
|
|
10
11
|
const compiledClass = /* @__PURE__ */ new Set();
|
|
11
12
|
const regexp = typeof trigger === "string" ? RegExp(`(["'\`])${escapeRegExp(trigger)}\\s([^\\1]*?)\\1`, "g") : trigger;
|
|
@@ -34,6 +35,8 @@ function transformerCompileClass(options = {}) {
|
|
|
34
35
|
let explicitName = false;
|
|
35
36
|
if (match.groups && match.groups.name) {
|
|
36
37
|
hash2 = match.groups.name;
|
|
38
|
+
if (alwaysHash)
|
|
39
|
+
hash2 += `-${hashFn(body)}`;
|
|
37
40
|
explicitName = true;
|
|
38
41
|
} else {
|
|
39
42
|
hash2 = hashFn(body);
|
|
@@ -42,7 +45,7 @@ function transformerCompileClass(options = {}) {
|
|
|
42
45
|
if (tokens && tokens.has(className) && explicitName) {
|
|
43
46
|
const existing = uno.config.shortcuts.find((i) => i[0] === className);
|
|
44
47
|
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
|
|
48
|
+
throw new Error(`Duplicated compile class name "${className}". One is "${body}" and the other is "${existing[1]}". Please choose different class name or set 'alwaysHash' to 'true'.`);
|
|
46
49
|
}
|
|
47
50
|
compiledClass.add(className);
|
|
48
51
|
replacements.unshift(className);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-compile-class",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
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.
|
|
36
|
+
"@unocss/core": "0.58.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"magic-string": "^0.30.5"
|