daisyui 4.0.0-alpha.2 → 4.0.0-alpha.20

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