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
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
`<div
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
62
|
-
`<div
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|