daisyui 2.52.0 → 3.0.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.
@@ -1,17 +1,17 @@
1
1
  module.exports = {
2
- primary: "--p",
2
+ "primary": "--p",
3
3
  "primary-focus": "--pf",
4
4
  "primary-content": "--pc",
5
5
 
6
- secondary: "--s",
6
+ "secondary": "--s",
7
7
  "secondary-focus": "--sf",
8
8
  "secondary-content": "--sc",
9
9
 
10
- accent: "--a",
10
+ "accent": "--a",
11
11
  "accent-focus": "--af",
12
12
  "accent-content": "--ac",
13
13
 
14
- neutral: "--n",
14
+ "neutral": "--n",
15
15
  "neutral-focus": "--nf",
16
16
  "neutral-content": "--nc",
17
17
 
@@ -20,15 +20,15 @@ module.exports = {
20
20
  "base-300": "--b3",
21
21
  "base-content": "--bc",
22
22
 
23
- info: "--in",
23
+ "info": "--in",
24
24
  "info-content": "--inc",
25
25
 
26
- success: "--su",
26
+ "success": "--su",
27
27
  "success-content": "--suc",
28
28
 
29
- warning: "--wa",
29
+ "warning": "--wa",
30
30
  "warning-content": "--wac",
31
31
 
32
- error: "--er",
32
+ "error": "--er",
33
33
  "error-content": "--erc",
34
- };
34
+ }
@@ -0,0 +1,269 @@
1
+ const colorNames = require("./colorNames")
2
+ const themeDefaults = require("./themeDefaults")
3
+
4
+ const { colord, getFormat, extend } = require("colord")
5
+ const mixPlugin = require("colord/plugins/mix")
6
+ const namesPlugin = require("colord/plugins/names")
7
+ const lchPlugin = require("colord/plugins/lch")
8
+ const hwbPlugin = require("colord/plugins/hwb")
9
+ const labPlugin = require("colord/plugins/lab")
10
+ const xyzPlugin = require("colord/plugins/xyz")
11
+
12
+ extend([mixPlugin, namesPlugin, lchPlugin, hwbPlugin, labPlugin, xyzPlugin])
13
+
14
+ module.exports = {
15
+ changeColorValuesToObject: function (input) {
16
+ const [h, s, l] = input.match(/\d+(\.\d+)?%|\d+(\.\d+)?/g).map(parseFloat)
17
+ return { h, s, l, a: 1 }
18
+ },
19
+
20
+ turnColorValuesToString: function (input) {
21
+ const [h, s, l] = input.match(/\d+(\.\d+)?%|\d+(\.\d+)?/g).map(parseFloat)
22
+ return `${h} ${s}% ${l}%`
23
+ },
24
+
25
+ generateForegroundColorFrom: function (input, percentage = 0.8) {
26
+ const str = colord(input)
27
+ .mix(colord(input).isDark() ? "white" : "black", percentage)
28
+ .toHslString()
29
+ return this.turnColorValuesToString(str)
30
+ },
31
+
32
+ generateDarkenColorFrom: function (input, percentage = 0.07) {
33
+ const str = colord(input).darken(percentage).toHslString()
34
+ return this.turnColorValuesToString(str)
35
+ },
36
+
37
+ convertColorFormat: function (input, colorFunction = "hsl") {
38
+ if (typeof input !== "object" || input === null) {
39
+ return input
40
+ }
41
+
42
+ const resultObj = {}
43
+
44
+ Object.entries(input).forEach(([rule, value]) => {
45
+ // if (!Object.hasOwn(colorNames, rule)) {
46
+ // resultObj[rule] = value
47
+ // } else {
48
+ // let arr
49
+ // if (getFormat(value) === "lch") {
50
+ // arr = this.changeColorValuesToObject(value)
51
+ // } else {
52
+ // arr = colord(value).toLch()
53
+ // }
54
+ // resultObj[colorNames[rule]] = arr.l + " " + arr.c + " " + arr.h
55
+ // }
56
+
57
+ if (colorNames.hasOwnProperty(rule)) {
58
+ const hslArray = colord(value).toHsl()
59
+ resultObj[colorNames[rule]] = `${hslArray.h} ${hslArray.s}% ${hslArray.l}%`
60
+ } else {
61
+ resultObj[rule] = value
62
+ }
63
+
64
+ // if (getFormat("lch(" + value + ")") === "lch") {
65
+ // resultObj[rule] = value
66
+ // if (colorFunction === "hsl") {
67
+ // let arr = colord("lch(" + value + ")").toHsl()
68
+ // resultObj[rule] = arr.h + " " + arr.s + "% " + arr.l + "%"
69
+ // }
70
+ // }
71
+
72
+ // auto generate focus colors
73
+ if (!Object.hasOwn(input, "primary-focus")) {
74
+ resultObj["--pf"] = this.generateDarkenColorFrom(input["primary"])
75
+ }
76
+ if (!Object.hasOwn(input, "secondary-focus")) {
77
+ resultObj["--sf"] = this.generateDarkenColorFrom(input["secondary"])
78
+ }
79
+ if (!Object.hasOwn(input, "accent-focus")) {
80
+ resultObj["--af"] = this.generateDarkenColorFrom(input["accent"])
81
+ }
82
+ if (!Object.hasOwn(input, "neutral-focus")) {
83
+ resultObj["--nf"] = this.generateDarkenColorFrom(input["neutral"])
84
+ }
85
+
86
+ // auto generate base colors
87
+ if (!Object.hasOwn(input, "base-100")) {
88
+ resultObj["--b1"] = "100 0 0"
89
+ }
90
+ if (!Object.hasOwn(input, "base-200")) {
91
+ resultObj["--b2"] = this.generateDarkenColorFrom(input["base-100"])
92
+ }
93
+ if (!Object.hasOwn(input, "base-300")) {
94
+ if (Object.hasOwn(input, "base-200")) {
95
+ resultObj["--b3"] = this.generateDarkenColorFrom(input["base-200"])
96
+ } else {
97
+ resultObj["--b3"] = this.generateDarkenColorFrom(input["base-100"], 0.14)
98
+ }
99
+ }
100
+
101
+ // auto generate state colors
102
+
103
+ if (!Object.hasOwn(input, "info")) {
104
+ resultObj["--in"] = 198 + " " + 93 + "%" + " " + 60 + "%"
105
+ }
106
+ if (!Object.hasOwn(input, "success")) {
107
+ resultObj["--su"] = 158 + " " + 64 + "%" + " " + 52 + "%"
108
+ }
109
+ if (!Object.hasOwn(input, "warning")) {
110
+ resultObj["--wa"] = 43 + " " + 96 + "%" + " " + 56 + "%"
111
+ }
112
+ if (!Object.hasOwn(input, "error")) {
113
+ resultObj["--er"] = 0 + " " + 91 + "%" + " " + 71 + "%"
114
+ }
115
+
116
+ // auto generate content colors
117
+ if (!Object.hasOwn(input, "base-content")) {
118
+ resultObj["--bc"] = this.generateForegroundColorFrom(input["base-100"])
119
+ }
120
+ if (!Object.hasOwn(input, "primary-content")) {
121
+ resultObj["--pc"] = this.generateForegroundColorFrom(input["primary"])
122
+ }
123
+ if (!Object.hasOwn(input, "secondary-content")) {
124
+ resultObj["--sc"] = this.generateForegroundColorFrom(input["secondary"])
125
+ }
126
+ if (!Object.hasOwn(input, "accent-content")) {
127
+ resultObj["--ac"] = this.generateForegroundColorFrom(input["accent"])
128
+ }
129
+ if (!Object.hasOwn(input, "neutral-content")) {
130
+ resultObj["--nc"] = this.generateForegroundColorFrom(input["neutral"])
131
+ }
132
+ if (!Object.hasOwn(input, "info-content")) {
133
+ if (Object.hasOwn(input, "info")) {
134
+ resultObj["--inc"] = this.generateForegroundColorFrom(input["info"])
135
+ } else {
136
+ resultObj["--inc"] = 198 + " " + 100 + "%" + " " + 12 + "%"
137
+ }
138
+ }
139
+ if (!Object.hasOwn(input, "success-content")) {
140
+ if (Object.hasOwn(input, "success")) {
141
+ resultObj["--suc"] = this.generateForegroundColorFrom(input["success"])
142
+ } else {
143
+ resultObj["--suc"] = 158 + " " + 100 + "%" + " " + 10 + "%"
144
+ }
145
+ }
146
+ if (!Object.hasOwn(input, "warning-content")) {
147
+ if (Object.hasOwn(input, "warning")) {
148
+ resultObj["--wac"] = this.generateForegroundColorFrom(input["warning"])
149
+ } else {
150
+ resultObj["--wac"] = 43 + " " + 100 + "%" + " " + 11 + "%"
151
+ }
152
+ }
153
+ if (!Object.hasOwn(input, "error-content")) {
154
+ if (Object.hasOwn(input, "error")) {
155
+ resultObj["--erc"] = this.generateForegroundColorFrom(input["error"])
156
+ } else {
157
+ resultObj["--erc"] = 0 + " " + 100 + "%" + " " + 14 + "%"
158
+ }
159
+ }
160
+
161
+ // add css variables if not exist
162
+ Object.entries(themeDefaults.variables).forEach((item) => {
163
+ const [variable, value] = item
164
+ if (!Object.hasOwn(input, variable)) {
165
+ resultObj[variable] = value
166
+ }
167
+ })
168
+
169
+ // add other custom styles
170
+ if (!colorNames.hasOwnProperty(rule)) {
171
+ resultObj[rule] = value
172
+ }
173
+ })
174
+
175
+ return resultObj
176
+ },
177
+
178
+ injectThemes: function (addBase, config, themes, colorFunction) {
179
+ const includedThemesObj = {}
180
+ // includedThemesObj["@supports (not(color: lch(0 0 0)))"] = {}
181
+ // add default themes
182
+ Object.entries(themes).forEach(([theme, value]) => {
183
+ if (colorFunction === "lch") {
184
+ includedThemesObj[theme] = this.convertColorFormat(value)
185
+ }
186
+ if (colorFunction === "hsl") {
187
+ includedThemesObj[theme] = this.convertColorFormat(value, "hsl")
188
+ }
189
+ })
190
+
191
+ // add custom themes
192
+ if (Array.isArray(config("daisyui.themes"))) {
193
+ config("daisyui.themes").forEach((item) => {
194
+ if (typeof item === "object" && item !== null) {
195
+ Object.entries(item).forEach(([customThemeName, customThemevalue]) => {
196
+ includedThemesObj["[data-theme=" + customThemeName + "]"] =
197
+ this.convertColorFormat(customThemevalue)
198
+ })
199
+ }
200
+ })
201
+ }
202
+
203
+ let themeOrder = []
204
+ if (Array.isArray(config("daisyui.themes"))) {
205
+ config("daisyui.themes").forEach((theme) => {
206
+ if (typeof theme === "object" && theme !== null) {
207
+ Object.keys(theme).forEach((customThemeName) => {
208
+ themeOrder.push(customThemeName)
209
+ })
210
+ } else if (Object.hasOwn(includedThemesObj, "[data-theme=" + theme + "]")) {
211
+ themeOrder.push(theme)
212
+ }
213
+ })
214
+ } else if (config("daisyui.themes") === true) {
215
+ themeOrder = themeDefaults.themeOrder
216
+ } else {
217
+ themeOrder = ["light", "dark"]
218
+ }
219
+
220
+ // inject themes in order
221
+ const themesToInject = {}
222
+ themeOrder.forEach((themeName, index) => {
223
+ if (index === 0) {
224
+ // first theme as root
225
+ themesToInject[":root"] = includedThemesObj["[data-theme=" + themeName + "]"]
226
+ } else if (index === 1) {
227
+ // auto dark
228
+ if (config("daisyui.darkTheme")) {
229
+ if (
230
+ themeOrder[0] !== config("daisyui.darkTheme") &&
231
+ themeOrder.includes(config("daisyui.darkTheme"))
232
+ ) {
233
+ themesToInject["@media (prefers-color-scheme: dark)"] = {
234
+ [":root"]: includedThemesObj[`[data-theme=${config("daisyui.darkTheme")}]`],
235
+ }
236
+ }
237
+ } else if (config("daisyui.darkTheme") === false) {
238
+ // disables prefers-color-scheme: dark
239
+ } else {
240
+ if (themeOrder[0] !== "dark" && themeOrder.includes("dark")) {
241
+ themesToInject["@media (prefers-color-scheme: dark)"] = {
242
+ [":root"]: includedThemesObj["[data-theme=dark]"],
243
+ }
244
+ }
245
+ }
246
+ // theme 0 with name
247
+ themesToInject["[data-theme=" + themeOrder[0] + "]"] =
248
+ includedThemesObj["[data-theme=" + themeOrder[0] + "]"]
249
+ // theme 1 with name
250
+ themesToInject["[data-theme=" + themeOrder[1] + "]"] =
251
+ includedThemesObj["[data-theme=" + themeOrder[1] + "]"]
252
+ } else {
253
+ themesToInject["[data-theme=" + themeName + "]"] =
254
+ includedThemesObj["[data-theme=" + themeName + "]"]
255
+ }
256
+ })
257
+ if (colorFunction === "lch") {
258
+ addBase({ "@supports (color: lch(0 0 0))": themesToInject })
259
+ }
260
+ if (colorFunction === "hsl") {
261
+ addBase(themesToInject)
262
+ }
263
+
264
+ return {
265
+ includedThemesObj,
266
+ themeOrder,
267
+ }
268
+ },
269
+ }
@@ -0,0 +1,39 @@
1
+ let colorObject = {
2
+ "transparent": "transparent",
3
+ "current": "currentColor",
4
+
5
+ "primary": "hsl(var(--p) / <alpha-value>)",
6
+ "primary-focus": "hsl(var(--pf) / <alpha-value>)",
7
+ "primary-content": "hsl(var(--pc) / <alpha-value>)",
8
+
9
+ "secondary": "hsl(var(--s) / <alpha-value>)",
10
+ "secondary-focus": "hsl(var(--sf) / <alpha-value>)",
11
+ "secondary-content": "hsl(var(--sc) / <alpha-value>)",
12
+
13
+ "accent": "hsl(var(--a) / <alpha-value>)",
14
+ "accent-focus": "hsl(var(--af) / <alpha-value>)",
15
+ "accent-content": "hsl(var(--ac) / <alpha-value>)",
16
+
17
+ "neutral": "hsl(var(--n) / <alpha-value>)",
18
+ "neutral-focus": "hsl(var(--nf) / <alpha-value>)",
19
+ "neutral-content": "hsl(var(--nc) / <alpha-value>)",
20
+
21
+ "base-100": "hsl(var(--b1) / <alpha-value>)",
22
+ "base-200": "hsl(var(--b2) / <alpha-value>)",
23
+ "base-300": "hsl(var(--b3) / <alpha-value>)",
24
+ "base-content": "hsl(var(--bc) / <alpha-value>)",
25
+
26
+ "info": "hsl(var(--in) / <alpha-value>)",
27
+ "info-content": "hsl(var(--inc) / <alpha-value>)",
28
+
29
+ "success": "hsl(var(--su) / <alpha-value>)",
30
+ "success-content": "hsl(var(--suc) / <alpha-value>)",
31
+
32
+ "warning": "hsl(var(--wa) / <alpha-value>)",
33
+ "warning-content": "hsl(var(--wac) / <alpha-value>)",
34
+
35
+ "error": "hsl(var(--er) / <alpha-value>)",
36
+ "error-content": "hsl(var(--erc) / <alpha-value>)",
37
+ }
38
+
39
+ module.exports = colorObject
@@ -0,0 +1,45 @@
1
+ module.exports = {
2
+ themeOrder: [
3
+ "light",
4
+ "dark",
5
+ "cupcake",
6
+ "bumblebee",
7
+ "emerald",
8
+ "corporate",
9
+ "synthwave",
10
+ "retro",
11
+ "cyberpunk",
12
+ "valentine",
13
+ "halloween",
14
+ "garden",
15
+ "forest",
16
+ "aqua",
17
+ "lofi",
18
+ "pastel",
19
+ "fantasy",
20
+ "wireframe",
21
+ "black",
22
+ "luxury",
23
+ "dracula",
24
+ "cmyk",
25
+ "autumn",
26
+ "business",
27
+ "acid",
28
+ "lemonade",
29
+ "night",
30
+ "coffee",
31
+ "winter",
32
+ ],
33
+ variables: {
34
+ "--rounded-box": "1rem",
35
+ "--rounded-btn": "0.5rem",
36
+ "--rounded-badge": "1.9rem",
37
+ "--animation-btn": "0.25s",
38
+ "--animation-input": ".2s",
39
+ "--btn-text-case": "uppercase",
40
+ "--btn-focus-scale": "0.95",
41
+ "--border-btn": "1px",
42
+ "--tab-border": "1px",
43
+ "--tab-radius": "0.5rem",
44
+ },
45
+ }