daisyui 5.0.0-alpha.33 → 5.0.0-alpha.34
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/functions/addPrefix.js +47 -0
- package/package.json +2 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const addPrefix = (obj, prefix) => {
|
|
2
|
+
const result = {};
|
|
3
|
+
|
|
4
|
+
const getPrefixedKey = (key) => {
|
|
5
|
+
// class selectors like ".btn"
|
|
6
|
+
if (key.startsWith('.')) {
|
|
7
|
+
return `.${prefix}${key.slice(1)}`;
|
|
8
|
+
}
|
|
9
|
+
// nested class selectors like "&.btn"
|
|
10
|
+
if (key.startsWith('&.')) {
|
|
11
|
+
return `&.${prefix}${key.slice(2)}`;
|
|
12
|
+
}
|
|
13
|
+
if (key.includes(' ')) {
|
|
14
|
+
// compound selectors like ".btn .icon"
|
|
15
|
+
return key.split(' ').map(part => part.startsWith('.') ? `.${prefix}${part.slice(1)}` : part).join(' ');
|
|
16
|
+
}
|
|
17
|
+
if (key.includes(':')) {
|
|
18
|
+
// pseudo-classes like ":hover"
|
|
19
|
+
return key.split(':').map((part, index) => index === 0 && part.startsWith('.') ? `.${prefix}${part.slice(1)}` : part).join(':');
|
|
20
|
+
}
|
|
21
|
+
if (key.startsWith('@media') || key.startsWith('@keyframes') || key.startsWith('[')) {
|
|
22
|
+
// media queries, keyframes, and attribute selectors
|
|
23
|
+
return key;
|
|
24
|
+
}
|
|
25
|
+
return key;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
29
|
+
const newKey = getPrefixedKey(key);
|
|
30
|
+
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
// arrays within the CSS object
|
|
33
|
+
result[newKey] = value.map(item => {
|
|
34
|
+
if (typeof item === 'string' && item.startsWith('.')) {
|
|
35
|
+
return `.${prefix}${item.slice(1)}`;
|
|
36
|
+
}
|
|
37
|
+
return item;
|
|
38
|
+
});
|
|
39
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
40
|
+
result[newKey] = addPrefix(value, prefix);
|
|
41
|
+
} else {
|
|
42
|
+
result[newKey] = value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "daisyui",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.34",
|
|
5
5
|
"description": "daisyUI 5 - Tailwind CSS Component Library",
|
|
6
6
|
"author": "Pouya Saadeghi",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"base",
|
|
51
51
|
"colors",
|
|
52
52
|
"components",
|
|
53
|
+
"functions/addPrefix.js",
|
|
53
54
|
"functions/plugin.js",
|
|
54
55
|
"functions/pluginOptionsHandler.js",
|
|
55
56
|
"functions/variables.js",
|