unocss-transformer-alias 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -16,7 +16,7 @@ export default defineConfig({
16
16
  // ...
17
17
  shortcuts: [
18
18
  ['btn', 'px-2 py-3 bg-blue-500 text-white rounded'],
19
- [/^btn-(.*)$/, ([, c]) => `bg-${c}4:10 text-${c}5 rounded`],
19
+ [/^btn-(.*)$/, ([, c]) => `btn bg-${c}4:10 text-${c}5 rounded`],
20
20
  ],
21
21
  transformers: [
22
22
  transformerAlias(),
@@ -29,13 +29,15 @@ export default defineConfig({
29
29
  ```html
30
30
  <div *btn />
31
31
  <div class="*btn-red" />
32
+ <div class="+btn-blue" />
32
33
  ```
33
34
 
34
35
  Will be transformed to:
35
36
 
36
37
  ```html
37
38
  <div px-2 py-3 bg-blue-500 text-white rounded>
38
- <div class="bg-red4:10 text-red5 rounded" />
39
+ <div class="px-2 py-3 bg-blue-500 text-white rounded bg-red4:10 text-red5 rounded" />
40
+ <div class="btn-blue px-2 py-3 bg-blue-500 text-white rounded bg-blue4:10 text-blue5 rounded" />
39
41
  ```
40
42
 
41
43
  ## Options
@@ -44,9 +46,34 @@ Will be transformed to:
44
46
 
45
47
  ```ts
46
48
  transformerAlias({
47
- // default: '*'
49
+ /**
50
+ * Prefix for your alias.
51
+ *
52
+ * @default "*"
53
+ */
48
54
  prefix?: string
55
+ /**
56
+ * Prefix for your alias and keep the original class.
57
+ *
58
+ * @default '+'
59
+ */
60
+ keep?: string | KeepOption
49
61
  })
62
+
63
+ interface KeepOption {
64
+ /**
65
+ * keep prefix for your alias.
66
+ *
67
+ * @default '+'
68
+ */
69
+ prefix: string
70
+ /**
71
+ * Decedide whether to put it in `blocklist`.
72
+ *
73
+ * @default true
74
+ */
75
+ block: boolean
76
+ }
50
77
  ```
51
78
 
52
79
  ## About
package/dist/index.cjs CHANGED
@@ -17,7 +17,9 @@ async function transformAlias(code, uno, {
17
17
  prefix = "*",
18
18
  keep = "+"
19
19
  } = {}) {
20
- const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep)})([\\w-]+)`, "g");
20
+ if (typeof keep === "string")
21
+ keep = { prefix: keep, block: true };
22
+ const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep.prefix)})([\\w-]+)`, "g");
21
23
  const map = /* @__PURE__ */ new Map();
22
24
  for (const item of Array.from(code.original.matchAll(extraRE))) {
23
25
  let result = map.get(item[0]);
@@ -33,8 +35,11 @@ async function transformAlias(code, uno, {
33
35
  continue;
34
36
  }
35
37
  }
36
- if (item[1] === keep)
38
+ if (item[1] === keep.prefix) {
37
39
  result = `${item[2]} ${result}`;
40
+ if (keep.block)
41
+ uno.config.blocklist = [.../* @__PURE__ */ new Set([...uno.config.blocklist, item[2]])];
42
+ }
38
43
  code.overwrite(item.index, item.index + item[0].length, result);
39
44
  }
40
45
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,20 @@
1
1
  import { SourceCodeTransformer, UnoGenerator, ShortcutValue } from '@unocss/core';
2
2
  import MagicString from 'magic-string';
3
3
 
4
+ interface KeepOption {
5
+ /**
6
+ * keep prefix for your alias.
7
+ *
8
+ * @default '+'
9
+ */
10
+ prefix: string;
11
+ /**
12
+ * Decedide whether to put it in `blocklist`.
13
+ *
14
+ * @default true
15
+ */
16
+ block: boolean;
17
+ }
4
18
  interface TransformerAliasOptions {
5
19
  /**
6
20
  * Prefix for your alias.
@@ -13,10 +27,10 @@ interface TransformerAliasOptions {
13
27
  *
14
28
  * @default '+'
15
29
  */
16
- keep?: string;
30
+ keep?: string | KeepOption;
17
31
  }
18
32
  declare function transformerAlias(options?: TransformerAliasOptions): SourceCodeTransformer;
19
33
  declare function transformAlias(code: MagicString, uno: UnoGenerator, { prefix, keep, }?: TransformerAliasOptions): Promise<void>;
20
34
  declare function expandShortcut(input: string, uno: UnoGenerator, depth?: number): Promise<[ShortcutValue[]] | undefined>;
21
35
 
22
- export { TransformerAliasOptions, transformerAlias as default, expandShortcut, transformAlias };
36
+ export { KeepOption, TransformerAliasOptions, transformerAlias as default, expandShortcut, transformAlias };
package/dist/index.mjs CHANGED
@@ -13,7 +13,9 @@ async function transformAlias(code, uno, {
13
13
  prefix = "*",
14
14
  keep = "+"
15
15
  } = {}) {
16
- const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep)})([\\w-]+)`, "g");
16
+ if (typeof keep === "string")
17
+ keep = { prefix: keep, block: true };
18
+ const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep.prefix)})([\\w-]+)`, "g");
17
19
  const map = /* @__PURE__ */ new Map();
18
20
  for (const item of Array.from(code.original.matchAll(extraRE))) {
19
21
  let result = map.get(item[0]);
@@ -29,8 +31,11 @@ async function transformAlias(code, uno, {
29
31
  continue;
30
32
  }
31
33
  }
32
- if (item[1] === keep)
34
+ if (item[1] === keep.prefix) {
33
35
  result = `${item[2]} ${result}`;
36
+ if (keep.block)
37
+ uno.config.blocklist = [.../* @__PURE__ */ new Set([...uno.config.blocklist, item[2]])];
38
+ }
34
39
  code.overwrite(item.index, item.index + item[0].length, result);
35
40
  }
36
41
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unocss-transformer-alias",
3
3
  "type": "module",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "description": "Transform alias for UnoCSS shortcuts",
6
6
  "author": "Chris <https://github.com/zyyv>",
7
7
  "license": "MIT",