@unocss/transformer-attributify-jsx 0.59.4 → 0.60.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +22 -6
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -9,9 +9,9 @@ function createFilter(include, exclude) {
9
9
  return includePattern.some((p) => id.match(p));
10
10
  };
11
11
  }
12
- const elementRE = /(<\w[\w:\.$-]*\s)([\s\S]*?)(?=>[\s\S]?<\/[\s\w:\.$-]*>|\/>)/g;
12
+ const elementRE = /<([^\/?<>0-9$_!][^\s>]*)\s+((?:"[^"]*"|'[^"]*'|({[^}]*})|[^{>])+)>/g;
13
13
  const attributeRE = /(?<![~`!$%^&*()_+\-=[{;':"|,.<>/?]\s*)([a-zA-Z()#][\[?a-zA-Z0-9-_:()#%\]?]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
14
- const valuedAttributeRE = /((?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-.~<]+)=(?:["]([^"]*)["]|[']([^']*)[']|[{]((?:[`(](?:[^`)]*)[`)]|[^}])+)[}])/gms;
14
+ const valuedAttributeRE = /((?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-.~<]+)=(?:["](?:[^"]*)["]|['](?:[^']*)[']|([{])((?:[`(](?:[^`)]*)[`)]|[^}])+)([}]))/gms;
15
15
  function transformerAttributifyJsx(options = {}) {
16
16
  const {
17
17
  blocklist = []
@@ -39,16 +39,32 @@ function transformerAttributifyJsx(options = {}) {
39
39
  const tasks = [];
40
40
  for (const item of Array.from(code.original.matchAll(elementRE))) {
41
41
  let attributifyPart = item[2];
42
- if (valuedAttributeRE.test(attributifyPart))
43
- attributifyPart = attributifyPart.replace(valuedAttributeRE, (match) => " ".repeat(match.length));
42
+ if (valuedAttributeRE.test(attributifyPart)) {
43
+ attributifyPart = attributifyPart.replace(valuedAttributeRE, (match, _2, dynamicFlagStart) => {
44
+ if (!dynamicFlagStart)
45
+ return " ".repeat(match.length);
46
+ let preLastModifierIndex = 0;
47
+ let temp = match;
48
+ for (const _item of match.matchAll(elementRE)) {
49
+ const attrAttributePart = _item[2];
50
+ if (valuedAttributeRE.test(attrAttributePart))
51
+ attrAttributePart.replace(valuedAttributeRE, (m) => " ".repeat(m.length));
52
+ const pre = temp.slice(0, preLastModifierIndex) + " ".repeat(_item.index + _item[0].indexOf(_item[2]) - preLastModifierIndex) + attrAttributePart;
53
+ temp = pre + " ".repeat(_item.input.length - pre.length);
54
+ preLastModifierIndex = pre.length;
55
+ }
56
+ if (preLastModifierIndex !== 0)
57
+ return temp;
58
+ return " ".repeat(match.length);
59
+ });
60
+ }
44
61
  for (const attr of attributifyPart.matchAll(attributeRE)) {
45
62
  const matchedRule = attr[0].replace(/\:/i, "-");
46
63
  if (matchedRule.includes("=") || isBlocked(matchedRule))
47
64
  continue;
48
65
  tasks.push(uno.parseToken(matchedRule).then((matched) => {
49
66
  if (matched) {
50
- const tag = item[1];
51
- const startIdx = (item.index || 0) + (attr.index || 0) + tag.length;
67
+ const startIdx = (item.index || 0) + (attr.index || 0) + item[0].indexOf(item[2]);
52
68
  const endIdx = startIdx + matchedRule.length;
53
69
  code.overwrite(startIdx, endIdx, `${matchedRule}=""`);
54
70
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/transformer-attributify-jsx",
3
3
  "type": "module",
4
- "version": "0.59.4",
4
+ "version": "0.60.1",
5
5
  "description": "Support valueless attributify in JSX/TSX.",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@unocss/core": "0.59.4"
36
+ "@unocss/core": "0.60.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "magic-string": "^0.30.10"