dolphincss 1.2.8 → 1.2.9

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/package.json +1 -1
  2. package/vite-plugin.js +15 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dolphincss",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
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,16 @@ 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 matches <div className="marker"></div> with optional spaces/newlines inside, or self-closing <div className="marker" />
31
+ const regex = new RegExp(
32
+ `<div\\s+class(?:Name)?=(["'])${marker}\\1\\s*>\\s*</div>|<div\\s+class(?:Name)?=(["'])${marker}\\2\\s*/>`,
33
+ 'g'
34
+ );
38
35
 
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
- }
36
+ if (regex.test(newOriginalCode)) {
37
+ newOriginalCode = newOriginalCode.replace(regex, replacement);
38
+ modified = true;
39
+ console.log(`\n✨ DolphinCSS: Injected '${marker}' into ${path.basename(id)}`);
45
40
  }
46
41
  }
47
42
 
@@ -58,18 +53,12 @@ export default function dolphincssPlugin() {
58
53
  // Also apply the replacement to the current transform stream
59
54
  let newCode = code;
60
55
  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
- }
56
+ const regex = new RegExp(
57
+ `<div\\s+class(?:Name)?=(["'])${marker}\\1\\s*>\\s*</div>|<div\\s+class(?:Name)?=(["'])${marker}\\2\\s*/>`,
58
+ 'g'
59
+ );
60
+ if (regex.test(newCode)) {
61
+ newCode = newCode.replace(regex, replacement);
73
62
  }
74
63
  }
75
64