dolphincss 1.2.8 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dolphincss",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "DolphinCSS - World-class TailwindCSS + React component library",
6
6
  "main": "dolphin-css.css",
package/vite-plugin.js CHANGED
@@ -27,21 +27,18 @@ export default function dolphincssPlugin() {
27
27
  let newOriginalCode = originalCode;
28
28
 
29
29
  for (const [marker, replacement] of Object.entries(components)) {
30
- const cases = [
31
- `<div className="${marker}"></div>`,
32
- `<div class="${marker}"></div>`,
33
- `<div className="${marker}" />`,
34
- `<div class="${marker}" />`,
35
- `<div className='${marker}'></div>`,
36
- `<div class='${marker}'></div>`
37
- ];
30
+ // Regex to match <div className="marker"></div> with any spacing/newlines inside
31
+ // Using [\"'] instead of capture groups to simplify and avoid backreference issues
32
+ const regex = new RegExp(
33
+ `<div\\s+class(?:Name)?=[\"']${marker}[\"']\\s*>\\s*</div>|<div\\s+class(?:Name)?=[\"']${marker}[\"']\\s*/>`,
34
+ 'g'
35
+ );
38
36
 
39
- for (const pattern of cases) {
40
- if (newOriginalCode.includes(pattern)) {
41
- newOriginalCode = newOriginalCode.split(pattern).join(replacement);
42
- modified = true;
43
- console.log(`\n✨ DolphinCSS: Injected '${marker}' into ${path.basename(id)}`);
44
- }
37
+ if (regex.test(newOriginalCode)) {
38
+ // IMPORTANT: Use () => replacement to avoid $1, $2 substitution from things like $120.50
39
+ newOriginalCode = newOriginalCode.replace(regex, () => replacement);
40
+ modified = true;
41
+ console.log(`\n✨ DolphinCSS: Injected '${marker}' into ${path.basename(id)}`);
45
42
  }
46
43
  }
47
44
 
@@ -58,18 +55,12 @@ export default function dolphincssPlugin() {
58
55
  // Also apply the replacement to the current transform stream
59
56
  let newCode = code;
60
57
  for (const [marker, replacement] of Object.entries(components)) {
61
- const cases = [
62
- `<div className="${marker}"></div>`,
63
- `<div class="${marker}"></div>`,
64
- `<div className="${marker}" />`,
65
- `<div class="${marker}" />`,
66
- `<div className='${marker}'></div>`,
67
- `<div class='${marker}'></div>`
68
- ];
69
- for (const pattern of cases) {
70
- if (newCode.includes(pattern)) {
71
- newCode = newCode.split(pattern).join(replacement);
72
- }
58
+ const regex = new RegExp(
59
+ `<div\\s+class(?:Name)?=[\"']${marker}[\"']\\s*>\\s*</div>|<div\\s+class(?:Name)?=[\"']${marker}[\"']\\s*/>`,
60
+ 'g'
61
+ );
62
+ if (regex.test(newCode)) {
63
+ newCode = newCode.replace(regex, () => replacement);
73
64
  }
74
65
  }
75
66