daisyui 2.52.0 → 3.0.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.
- package/README.md +20 -20
- package/dist/base.js +1 -1
- package/dist/full.css +52294 -1
- package/dist/styled.css +1487 -1568
- package/dist/styled.js +1 -1
- package/dist/styled.rtl.js +1 -1
- package/dist/themes.css +602 -700
- package/dist/unstyled.css +316 -431
- package/dist/unstyled.js +1 -1
- package/dist/unstyled.rtl.js +1 -1
- package/dist/utilities-styled.js +1 -1
- package/dist/utilities-unstyled.js +1 -1
- package/dist/utilities.js +1 -1
- package/package.json +18 -22
- package/src/index.js +119 -78
- package/src/lib/addPrefix.js +104 -0
- package/src/lib/responsiveRegex.js +5 -14
- package/src/{colors → theming}/colorNames.js +9 -9
- package/src/theming/functions.js +269 -0
- package/src/theming/index.js +39 -0
- package/src/theming/themeDefaults.js +45 -0
- package/src/{colors → theming}/themes.js +161 -163
- package/src/colors/functions.js +0 -313
- package/src/colors/index.js +0 -52
- package/src/lib/postcss-prefixer/index.js +0 -87
- package/src/lib/postcss-prefixer/utils.js +0 -29
package/src/colors/functions.js
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
const Color = require("color");
|
|
2
|
-
const colorNames = require("./colorNames");
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
|
|
6
|
-
generateForegroundColorFrom: function (input, percentage = 0.8) {
|
|
7
|
-
if (Color(input).isDark()) {
|
|
8
|
-
let arr = Color(input).mix(Color("white"), percentage).saturate(10).hsl().array()
|
|
9
|
-
return arr[0].toPrecision(5).replace(/\.?0+$/,"") + " " + arr[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + arr[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
10
|
-
} else {
|
|
11
|
-
let arr = Color(input).mix(Color("black"), percentage).saturate(10).hsl().array()
|
|
12
|
-
return arr[0].toPrecision(5).replace(/\.?0+$/,"") + " " + arr[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + arr[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
convertToHsl: function (input) {
|
|
17
|
-
let resultObj = {};
|
|
18
|
-
if (typeof input === "object" && input !== null) {
|
|
19
|
-
Object.entries(input).forEach(([rule, value]) => {
|
|
20
|
-
if (colorNames.hasOwnProperty(rule)) {
|
|
21
|
-
const hslArray = Color(value).hsl().array();
|
|
22
|
-
resultObj[colorNames[rule]] = hslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + hslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + hslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
23
|
-
} else {
|
|
24
|
-
resultObj[rule] = value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// auto generate focus colors
|
|
28
|
-
if (!input.hasOwnProperty("primary-focus")) {
|
|
29
|
-
const darkerHslArray = Color(input["primary"]).darken(0.2).hsl().array();
|
|
30
|
-
resultObj["--pf"] = darkerHslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + darkerHslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + darkerHslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!input.hasOwnProperty("secondary-focus")) {
|
|
34
|
-
const darkerHslArray = Color(input["secondary"]).darken(0.2).hsl().array();
|
|
35
|
-
resultObj["--sf"] = darkerHslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + darkerHslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + darkerHslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!input.hasOwnProperty("accent-focus")) {
|
|
39
|
-
const darkerHslArray = Color(input["accent"]).darken(0.2).hsl().array();
|
|
40
|
-
resultObj["--af"] = darkerHslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + darkerHslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + darkerHslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!input.hasOwnProperty("neutral-focus")) {
|
|
44
|
-
const darkerHslArray = Color(input["neutral"]).darken(0.2).hsl().array();
|
|
45
|
-
resultObj["--nf"] = darkerHslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + darkerHslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + darkerHslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// auto generate base colors
|
|
49
|
-
if (!input.hasOwnProperty("base-100")) {
|
|
50
|
-
resultObj["--b1"] = 0 + " " + 0 + "%" + " " + 100 + "%";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!input.hasOwnProperty("base-200")) {
|
|
54
|
-
const darkerHslArray = Color(input["base-100"]).darken(0.1).hsl().array();
|
|
55
|
-
resultObj["--b2"] = darkerHslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + darkerHslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + darkerHslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!input.hasOwnProperty("base-300")) {
|
|
59
|
-
if (input.hasOwnProperty("base-200")) {
|
|
60
|
-
const darkerHslArray = Color(input["base-200"]).darken(0.1).hsl().array();
|
|
61
|
-
resultObj["--b3"] = darkerHslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + darkerHslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + darkerHslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
62
|
-
} else {
|
|
63
|
-
const darkerHslArray = Color(input["base-100"]).darken(0.1).darken(0.1).hsl().array();
|
|
64
|
-
resultObj["--b3"] = darkerHslArray[0].toPrecision(5).replace(/\.?0+$/,"") + " " + darkerHslArray[1].toPrecision(5).replace(/\.?0+$/,"") + "%" + " " + darkerHslArray[2].toPrecision(5).replace(/\.?0+$/,"") + "%";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// auto generate state colors
|
|
69
|
-
if (!input.hasOwnProperty("info")) {
|
|
70
|
-
resultObj["--in"] = 198 + " " + 93 + "%" + " " + 60 + "%";
|
|
71
|
-
}
|
|
72
|
-
if (!input.hasOwnProperty("success")) {
|
|
73
|
-
resultObj["--su"] = 158 + " " + 64 + "%" + " " + 52 + "%";
|
|
74
|
-
}
|
|
75
|
-
if (!input.hasOwnProperty("warning")) {
|
|
76
|
-
resultObj["--wa"] = 43 + " " + 96 + "%" + " " + 56 + "%";
|
|
77
|
-
}
|
|
78
|
-
if (!input.hasOwnProperty("error")) {
|
|
79
|
-
resultObj["--er"] = 0 + " " + 91 + "%" + " " + 71 + "%";
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// auto generate content colors
|
|
83
|
-
if (!input.hasOwnProperty("base-content")) {
|
|
84
|
-
resultObj["--bc"] = this.generateForegroundColorFrom(input["base-100"])
|
|
85
|
-
}
|
|
86
|
-
if (!input.hasOwnProperty("primary-content")) {
|
|
87
|
-
resultObj["--pc"] = this.generateForegroundColorFrom(input["primary"])
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!input.hasOwnProperty("secondary-content")) {
|
|
91
|
-
resultObj["--sc"] = this.generateForegroundColorFrom(input["secondary"])
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!input.hasOwnProperty("accent-content")) {
|
|
95
|
-
resultObj["--ac"] = this.generateForegroundColorFrom(input["accent"])
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!input.hasOwnProperty("neutral-content")) {
|
|
99
|
-
resultObj["--nc"] = this.generateForegroundColorFrom(input["neutral"])
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (!input.hasOwnProperty("info-content")) {
|
|
103
|
-
if (input.hasOwnProperty("info")) {
|
|
104
|
-
resultObj["--inc"] = this.generateForegroundColorFrom(input["info"])
|
|
105
|
-
} else {
|
|
106
|
-
resultObj["--inc"] = 198 + " " + 100 + "%" + " " + 12 + "%";
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!input.hasOwnProperty("success-content")) {
|
|
111
|
-
if (input.hasOwnProperty("success")) {
|
|
112
|
-
resultObj["--suc"] = this.generateForegroundColorFrom(input["success"])
|
|
113
|
-
} else {
|
|
114
|
-
resultObj["--suc"] = 158 + " " + 100 + "%" + " " + 10 + "%";
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (!input.hasOwnProperty("warning-content")) {
|
|
119
|
-
if (input.hasOwnProperty("warning")) {
|
|
120
|
-
resultObj["--wac"] = this.generateForegroundColorFrom(input["warning"])
|
|
121
|
-
} else {
|
|
122
|
-
resultObj["--wac"] = 43 + " " + 100 + "%" + " " + 11 + "%";
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!input.hasOwnProperty("error-content")) {
|
|
127
|
-
if (input.hasOwnProperty("error")) {
|
|
128
|
-
resultObj["--erc"] = this.generateForegroundColorFrom(input["error"])
|
|
129
|
-
} else {
|
|
130
|
-
resultObj["--erc"] = 0 + " " + 100 + "%" + " " + 14 + "%";
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// auto generate css variables
|
|
135
|
-
if (!input.hasOwnProperty("--rounded-box")) {
|
|
136
|
-
resultObj["--rounded-box"] = "1rem";
|
|
137
|
-
}
|
|
138
|
-
if (!input.hasOwnProperty("--rounded-btn")) {
|
|
139
|
-
resultObj["--rounded-btn"] = "0.5rem";
|
|
140
|
-
}
|
|
141
|
-
if (!input.hasOwnProperty("--rounded-badge")) {
|
|
142
|
-
resultObj["--rounded-badge"] = "1.9rem";
|
|
143
|
-
}
|
|
144
|
-
if (!input.hasOwnProperty("--animation-btn")) {
|
|
145
|
-
resultObj["--animation-btn"] = "0.25s";
|
|
146
|
-
}
|
|
147
|
-
if (!input.hasOwnProperty("--animation-input")) {
|
|
148
|
-
resultObj["--animation-input"] = ".2s";
|
|
149
|
-
}
|
|
150
|
-
if (!input.hasOwnProperty("--btn-text-case")) {
|
|
151
|
-
resultObj["--btn-text-case"] = "uppercase";
|
|
152
|
-
}
|
|
153
|
-
if (!input.hasOwnProperty("--btn-focus-scale")) {
|
|
154
|
-
resultObj["--btn-focus-scale"] = "0.95";
|
|
155
|
-
}
|
|
156
|
-
if (!input.hasOwnProperty("--border-btn")) {
|
|
157
|
-
resultObj["--border-btn"] = "1px";
|
|
158
|
-
}
|
|
159
|
-
if (!input.hasOwnProperty("--tab-border")) {
|
|
160
|
-
resultObj["--tab-border"] = "1px";
|
|
161
|
-
}
|
|
162
|
-
if (!input.hasOwnProperty("--tab-radius")) {
|
|
163
|
-
resultObj["--tab-radius"] = "0.5rem";
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
return resultObj;
|
|
168
|
-
}
|
|
169
|
-
return input;
|
|
170
|
-
},
|
|
171
|
-
|
|
172
|
-
injectThemes: function (addBase, config, themes) {
|
|
173
|
-
let includedThemesObj = new Object();
|
|
174
|
-
|
|
175
|
-
// add light themes
|
|
176
|
-
if (config("daisyui.themes") == false) {
|
|
177
|
-
Object.entries(themes).forEach(([theme, index]) => {
|
|
178
|
-
includedThemesObj[theme] = this.convertToHsl(themes[theme]);
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// add default themes
|
|
183
|
-
if (config("daisyui.themes") != false) {
|
|
184
|
-
Object.entries(themes).forEach(([theme, index]) => {
|
|
185
|
-
includedThemesObj[theme] = this.convertToHsl(themes[theme]);
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// add custom themes
|
|
190
|
-
if (Array.isArray(config("daisyui.themes"))) {
|
|
191
|
-
config("daisyui.themes").forEach((item, index) => {
|
|
192
|
-
if (typeof item === "object" && item !== null) {
|
|
193
|
-
Object.entries(item).forEach(([customThemeName, customThemevalue]) => {
|
|
194
|
-
includedThemesObj["[data-theme=" + customThemeName + "]"] =
|
|
195
|
-
this.convertToHsl(customThemevalue);
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
let themeOrder = [];
|
|
204
|
-
if (Array.isArray(config("daisyui.themes"))) {
|
|
205
|
-
config("daisyui.themes").forEach((theme, index) => {
|
|
206
|
-
if (typeof theme === "object" && theme !== null) {
|
|
207
|
-
Object.entries(theme).forEach(([customThemeName, customThemevalue]) => {
|
|
208
|
-
themeOrder.push(customThemeName);
|
|
209
|
-
});
|
|
210
|
-
} else if (
|
|
211
|
-
includedThemesObj.hasOwnProperty("[data-theme=" + theme + "]")
|
|
212
|
-
) {
|
|
213
|
-
themeOrder.push(theme);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
} else if (config("daisyui.themes") != false) {
|
|
217
|
-
themeOrder = [
|
|
218
|
-
"light",
|
|
219
|
-
"dark",
|
|
220
|
-
"cupcake",
|
|
221
|
-
"bumblebee",
|
|
222
|
-
"emerald",
|
|
223
|
-
"corporate",
|
|
224
|
-
"synthwave",
|
|
225
|
-
"retro",
|
|
226
|
-
"cyberpunk",
|
|
227
|
-
"valentine",
|
|
228
|
-
"halloween",
|
|
229
|
-
"garden",
|
|
230
|
-
"forest",
|
|
231
|
-
"aqua",
|
|
232
|
-
"lofi",
|
|
233
|
-
"pastel",
|
|
234
|
-
"fantasy",
|
|
235
|
-
"wireframe",
|
|
236
|
-
"black",
|
|
237
|
-
"luxury",
|
|
238
|
-
"dracula",
|
|
239
|
-
"cmyk",
|
|
240
|
-
"autumn",
|
|
241
|
-
"business",
|
|
242
|
-
"acid",
|
|
243
|
-
"lemonade",
|
|
244
|
-
"night",
|
|
245
|
-
"coffee",
|
|
246
|
-
"winter",
|
|
247
|
-
];
|
|
248
|
-
} else if (config("daisyui.themes") == false) {
|
|
249
|
-
themeOrder.push("light");
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// inject themes in order
|
|
253
|
-
themeOrder.forEach((themeName, index) => {
|
|
254
|
-
if (index === 0) {
|
|
255
|
-
// first theme as root
|
|
256
|
-
addBase({
|
|
257
|
-
[":root"]: includedThemesObj["[data-theme=" + themeName + "]"],
|
|
258
|
-
});
|
|
259
|
-
} else if (index === 1) {
|
|
260
|
-
// auto dark
|
|
261
|
-
if (config("daisyui.darkTheme")) {
|
|
262
|
-
if (
|
|
263
|
-
themeOrder[0] != config("daisyui.darkTheme") &&
|
|
264
|
-
themeOrder.includes(config("daisyui.darkTheme"))
|
|
265
|
-
) {
|
|
266
|
-
addBase({
|
|
267
|
-
["@media (prefers-color-scheme: dark)"]: {
|
|
268
|
-
[":root"]:
|
|
269
|
-
includedThemesObj[
|
|
270
|
-
`[data-theme=${config("daisyui.darkTheme")}]`
|
|
271
|
-
],
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
else if (config("daisyui.darkTheme") === false ) {
|
|
277
|
-
// disables prefers-color-scheme: dark
|
|
278
|
-
} else {
|
|
279
|
-
if (themeOrder[0] != "dark" && themeOrder.includes("dark")) {
|
|
280
|
-
addBase({
|
|
281
|
-
["@media (prefers-color-scheme: dark)"]: {
|
|
282
|
-
[":root"]: includedThemesObj["[data-theme=dark]"],
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
// theme 0 with name
|
|
288
|
-
addBase({
|
|
289
|
-
["[data-theme=" + themeOrder[0] + "]"]:
|
|
290
|
-
includedThemesObj["[data-theme=" + themeOrder[0] + "]"],
|
|
291
|
-
});
|
|
292
|
-
// theme 1 with name
|
|
293
|
-
addBase({
|
|
294
|
-
["[data-theme=" + themeOrder[1] + "]"]:
|
|
295
|
-
includedThemesObj["[data-theme=" + themeOrder[1] + "]"],
|
|
296
|
-
});
|
|
297
|
-
} else {
|
|
298
|
-
addBase({
|
|
299
|
-
["[data-theme=" + themeName + "]"]:
|
|
300
|
-
includedThemesObj["[data-theme=" + themeName + "]"],
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
includedThemesObj: includedThemesObj,
|
|
309
|
-
themeOrder: themeOrder,
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
}
|
package/src/colors/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
function withOpacityValue(variable, fallbackColor) {
|
|
2
|
-
return ({ opacityValue }) => {
|
|
3
|
-
let fallbackColorValue = "";
|
|
4
|
-
if (fallbackColor) {
|
|
5
|
-
fallbackColorValue = `, var(${fallbackColor})`;
|
|
6
|
-
}
|
|
7
|
-
if (opacityValue === undefined) {
|
|
8
|
-
return `hsl(var(${variable}${fallbackColorValue}))`;
|
|
9
|
-
}
|
|
10
|
-
return `hsl(var(${variable}${fallbackColorValue}) / ${opacityValue})`;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let colorObject = {
|
|
15
|
-
transparent: "transparent",
|
|
16
|
-
current: "currentColor",
|
|
17
|
-
|
|
18
|
-
primary: withOpacityValue("--p"),
|
|
19
|
-
"primary-focus": withOpacityValue("--pf", "--p"),
|
|
20
|
-
"primary-content": withOpacityValue("--pc"),
|
|
21
|
-
|
|
22
|
-
secondary: withOpacityValue("--s"),
|
|
23
|
-
"secondary-focus": withOpacityValue("--sf", "--s"),
|
|
24
|
-
"secondary-content": withOpacityValue("--sc"),
|
|
25
|
-
|
|
26
|
-
accent: withOpacityValue("--a"),
|
|
27
|
-
"accent-focus": withOpacityValue("--af", "--a"),
|
|
28
|
-
"accent-content": withOpacityValue("--ac"),
|
|
29
|
-
|
|
30
|
-
neutral: withOpacityValue("--n"),
|
|
31
|
-
"neutral-focus": withOpacityValue("--nf", "--n"),
|
|
32
|
-
"neutral-content": withOpacityValue("--nc"),
|
|
33
|
-
|
|
34
|
-
"base-100": withOpacityValue("--b1"),
|
|
35
|
-
"base-200": withOpacityValue("--b2", "--b1"),
|
|
36
|
-
"base-300": withOpacityValue("--b3", "--b2"),
|
|
37
|
-
"base-content": withOpacityValue("--bc"),
|
|
38
|
-
|
|
39
|
-
info: withOpacityValue("--in"),
|
|
40
|
-
"info-content": withOpacityValue("--inc", "--nc"),
|
|
41
|
-
|
|
42
|
-
success: withOpacityValue("--su"),
|
|
43
|
-
"success-content": withOpacityValue("--suc", "--nc"),
|
|
44
|
-
|
|
45
|
-
warning: withOpacityValue("--wa"),
|
|
46
|
-
"warning-content": withOpacityValue("--wac", "--nc"),
|
|
47
|
-
|
|
48
|
-
error: withOpacityValue("--er"),
|
|
49
|
-
"error-content": withOpacityValue("--erc", "--nc"),
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
module.exports = colorObject;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
const Tokenizer = require('css-selector-tokenizer');
|
|
2
|
-
const {
|
|
3
|
-
parseAttrSelector,
|
|
4
|
-
attrStringify,
|
|
5
|
-
itMatchesOne,
|
|
6
|
-
} = require('./utils');
|
|
7
|
-
|
|
8
|
-
function prefixNode(node, prefix) {
|
|
9
|
-
if (['class', 'id'].includes(node.type)) {
|
|
10
|
-
return {
|
|
11
|
-
...node,
|
|
12
|
-
name: `${prefix}${node.name}`,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (['attribute'].includes(node.type) && node.content) {
|
|
17
|
-
const {
|
|
18
|
-
type, operator, head, classes, foot,
|
|
19
|
-
} = parseAttrSelector(node);
|
|
20
|
-
|
|
21
|
-
if (!['class', 'id'].includes(type)) return node;
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
...node,
|
|
25
|
-
content: attrStringify({
|
|
26
|
-
type,
|
|
27
|
-
operator,
|
|
28
|
-
head,
|
|
29
|
-
classes: classes.map((cls) => `${prefix}${cls}`),
|
|
30
|
-
foot,
|
|
31
|
-
}),
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return node;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function iterateSelectorNodes(selector, options) {
|
|
39
|
-
const { prefix, ignore } = options;
|
|
40
|
-
return {
|
|
41
|
-
...selector,
|
|
42
|
-
nodes: selector.nodes.map((node) => {
|
|
43
|
-
if (['selector', 'nested-pseudo-class'].includes(node.type)) {
|
|
44
|
-
return iterateSelectorNodes(node, options);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (itMatchesOne(ignore, Tokenizer.stringify(node))) return node;
|
|
48
|
-
|
|
49
|
-
return prefixNode(node, prefix);
|
|
50
|
-
}),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @type {import('postcss').PluginCreator}
|
|
56
|
-
*/
|
|
57
|
-
module.exports = (opts = {}) => {
|
|
58
|
-
const { prefix, ignore } = {
|
|
59
|
-
prefix: '',
|
|
60
|
-
ignore: [],
|
|
61
|
-
...opts,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
if (typeof prefix !== 'string') {
|
|
65
|
-
throw new Error('@postcss-prefix: prefix option should be of type string.');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!Array.isArray(ignore)) {
|
|
69
|
-
throw new Error('@postcss-prefix: ignore options should be an Array.');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!prefix.length) return;
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
postcssPlugin: 'postcss-prefixer',
|
|
76
|
-
Root(root, postcss) {
|
|
77
|
-
root.walkRules((rule) => {
|
|
78
|
-
const parsed = Tokenizer.parse(rule.selector);
|
|
79
|
-
const selector = iterateSelectorNodes(parsed, { prefix, ignore });
|
|
80
|
-
|
|
81
|
-
rule.selector = Tokenizer.stringify(selector);
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
module.exports.postcss = true
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
|
|
3
|
-
itMatchesOne(arr, term) {
|
|
4
|
-
return arr.some((i) => term.search(i) >= 0);
|
|
5
|
-
},
|
|
6
|
-
|
|
7
|
-
parseAttrSelector(node) {
|
|
8
|
-
const { content } = node;
|
|
9
|
-
const regex = /(^class|^id)([*^?~|$=]*)+(?:("\s*)([^"\\]*?(?:\\.[^"\\]*)*?)(\s*")|('\s*)([^'\\]*?(?:\\.[^'\\]*)*?)(\s*'))/i;
|
|
10
|
-
|
|
11
|
-
const [type, operator, head, classes, foot] = content
|
|
12
|
-
.split(regex)
|
|
13
|
-
.filter((part) => part);
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
type,
|
|
17
|
-
operator,
|
|
18
|
-
head,
|
|
19
|
-
classes: classes ? classes.split(' ').map((c) => c.replace(/"|'/g, '')) : [],
|
|
20
|
-
foot,
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
attrStringify({
|
|
25
|
-
type, operator, head, classes, foot,
|
|
26
|
-
}) {
|
|
27
|
-
return `${type}${operator || ''}${head || ''}${classes.join(' ')}${foot || ''}`;
|
|
28
|
-
},
|
|
29
|
-
};
|