@unocss/transformer-attributify-jsx 0.45.21 → 0.45.22

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
@@ -13,6 +13,7 @@ function createFilter(include, exclude) {
13
13
  }
14
14
  const elementRE = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/gs;
15
15
  const attributeRE = /([a-zA-Z()#][\[?a-zA-Z0-9-_:()#%\]?]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
16
+ const classFilterRE = /(className|class)\s*=\s*\{[^\}]*\}/i;
16
17
  function transformerAttributifyJsx(options = {}) {
17
18
  const {
18
19
  blocklist = []
@@ -39,7 +40,11 @@ function transformerAttributifyJsx(options = {}) {
39
40
  async transform(code, _, { uno }) {
40
41
  const tasks = [];
41
42
  for (const item of Array.from(code.original.matchAll(elementRE))) {
42
- for (const attr of item[3].matchAll(attributeRE)) {
43
+ const classNamePart = item[3].match(classFilterRE);
44
+ let attributifyPart = item[3];
45
+ if (classNamePart)
46
+ attributifyPart = item[3].replace(classFilterRE, " ".repeat(classNamePart[0].length));
47
+ for (const attr of attributifyPart.matchAll(attributeRE)) {
43
48
  const matchedRule = attr[0].replace(/\:/i, "-");
44
49
  if (matchedRule.includes("=") || isBlocked(matchedRule))
45
50
  continue;
package/dist/index.mjs CHANGED
@@ -11,6 +11,7 @@ function createFilter(include, exclude) {
11
11
  }
12
12
  const elementRE = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/gs;
13
13
  const attributeRE = /([a-zA-Z()#][\[?a-zA-Z0-9-_:()#%\]?]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
14
+ const classFilterRE = /(className|class)\s*=\s*\{[^\}]*\}/i;
14
15
  function transformerAttributifyJsx(options = {}) {
15
16
  const {
16
17
  blocklist = []
@@ -37,7 +38,11 @@ function transformerAttributifyJsx(options = {}) {
37
38
  async transform(code, _, { uno }) {
38
39
  const tasks = [];
39
40
  for (const item of Array.from(code.original.matchAll(elementRE))) {
40
- for (const attr of item[3].matchAll(attributeRE)) {
41
+ const classNamePart = item[3].match(classFilterRE);
42
+ let attributifyPart = item[3];
43
+ if (classNamePart)
44
+ attributifyPart = item[3].replace(classFilterRE, " ".repeat(classNamePart[0].length));
45
+ for (const attr of attributifyPart.matchAll(attributeRE)) {
41
46
  const matchedRule = attr[0].replace(/\:/i, "-");
42
47
  if (matchedRule.includes("=") || isBlocked(matchedRule))
43
48
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/transformer-attributify-jsx",
3
- "version": "0.45.21",
3
+ "version": "0.45.22",
4
4
  "description": "Support valueless attributify in JSX/TSX.",
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.45.21"
36
+ "@unocss/core": "0.45.22"
37
37
  },
38
38
  "devDependencies": {
39
39
  "magic-string": "^0.26.3"