daisyui 4.0.8 → 4.1.0-alpha.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.
@@ -4,7 +4,7 @@
4
4
  // regex for all Tailwind CSS color utilities
5
5
  // (bg|to|via|from|text|ring|fill|caret|stroke|border|divide|accent|shadow|outline|decoration|placeholder|ring-offset)
6
6
 
7
- module.exports = [
7
+ export const responsiveRegex = [
8
8
  {
9
9
  pattern: /.*/,
10
10
  },
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export const utilityClasses = {
2
2
  borderRadius: {
3
3
  badge: "var(--rounded-badge, 1.9rem)",
4
4
  btn: "var(--rounded-btn, 0.5rem)",
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export const colorNames = {
2
2
  "primary": "--p",
3
3
  "primary-content": "--pc",
4
4
 
@@ -1,229 +1,219 @@
1
- const colorNames = require("./colorNames")
2
- const themeDefaults = require("./themeDefaults")
1
+ import { colorNames } from "./colorNames"
2
+ import { variables, themesOrder } from "./themeDefaults"
3
3
 
4
- const { toGamut, interpolate, wcagContrast } = require("culori")
4
+ import { toGamut, interpolate, wcagContrast } from "culori"
5
5
 
6
- module.exports = {
7
- isDark: (color) => {
8
- if (wcagContrast(color, "black") < wcagContrast(color, "white")) {
9
- return true
10
- }
11
- return false
12
- },
13
-
14
- colorObjToString: function (input) {
15
- const cut = (number) => {
16
- if (!number) {
17
- return 0
18
- }
19
- return +number.toFixed(6)
6
+ export function isDark(color) {
7
+ if (wcagContrast(color, "black") < wcagContrast(color, "white")) {
8
+ return true
9
+ }
10
+ return false
11
+ }
12
+ export function colorObjToString(input) {
13
+ const cut = (number) => {
14
+ if (!number) {
15
+ return 0
20
16
  }
21
- const { l, c, h } = input
22
- return `${cut(l)} ${cut(c)} ${cut(h)}`
23
- },
24
-
25
- generateForegroundColorFrom: function (input, percentage = 0.8) {
26
- const result = interpolate([input, this.isDark(input) ? "white" : "black"], "oklch")(percentage)
27
- return this.colorObjToString(result)
28
- },
17
+ return +number.toFixed(6)
18
+ }
19
+ const { l, c, h } = input
20
+ return `${cut(l)} ${cut(c)} ${cut(h)}`
21
+ }
22
+ export function generateForegroundColorFrom(input, percentage = 0.8) {
23
+ const result = interpolate([input, isDark(input) ? "white" : "black"], "oklch")(percentage)
24
+ return colorObjToString(result)
25
+ }
26
+ export function generateDarkenColorFrom(input, percentage = 0.07) {
27
+ const result = interpolate([input, "black"], "oklch")(percentage)
28
+ return colorObjToString(result)
29
+ }
30
+ export function convertColorFormat(input) {
31
+ if (typeof input !== "object" || input === null) {
32
+ return input
33
+ }
29
34
 
30
- generateDarkenColorFrom: function (input, percentage = 0.07) {
31
- const result = interpolate([input, "black"], "oklch")(percentage)
32
- return this.colorObjToString(result)
33
- },
35
+ const resultObj = {}
34
36
 
35
- convertColorFormat: function (input) {
36
- if (typeof input !== "object" || input === null) {
37
- return input
37
+ Object.entries(input).forEach(([rule, value]) => {
38
+ if (colorNames.hasOwnProperty(rule)) {
39
+ const colorObj = toGamut("oklch")(value)
40
+ resultObj[colorNames[rule]] = colorObjToString(colorObj)
41
+ } else {
42
+ resultObj[rule] = value
38
43
  }
39
44
 
40
- const resultObj = {}
41
-
42
- Object.entries(input).forEach(([rule, value]) => {
43
- if (colorNames.hasOwnProperty(rule)) {
44
- const colorObj = toGamut("oklch")(value)
45
- resultObj[colorNames[rule]] = this.colorObjToString(colorObj)
45
+ // auto generate base colors
46
+ if (!Object.hasOwn(input, "base-100")) {
47
+ resultObj["--b1"] = "100 0 0"
48
+ }
49
+ if (!Object.hasOwn(input, "base-200")) {
50
+ resultObj["--b2"] = generateDarkenColorFrom(input["base-100"], 0.07)
51
+ }
52
+ if (!Object.hasOwn(input, "base-300")) {
53
+ if (Object.hasOwn(input, "base-200")) {
54
+ resultObj["--b3"] = generateDarkenColorFrom(input["base-200"], 0.07)
46
55
  } else {
47
- resultObj[rule] = value
48
- }
49
-
50
- // auto generate base colors
51
- if (!Object.hasOwn(input, "base-100")) {
52
- resultObj["--b1"] = "100 0 0"
53
- }
54
- if (!Object.hasOwn(input, "base-200")) {
55
- resultObj["--b2"] = this.generateDarkenColorFrom(input["base-100"], 0.07)
56
- }
57
- if (!Object.hasOwn(input, "base-300")) {
58
- if (Object.hasOwn(input, "base-200")) {
59
- resultObj["--b3"] = this.generateDarkenColorFrom(input["base-200"], 0.07)
60
- } else {
61
- resultObj["--b3"] = this.generateDarkenColorFrom(input["base-100"], 0.14)
62
- }
56
+ resultObj["--b3"] = generateDarkenColorFrom(input["base-100"], 0.14)
63
57
  }
58
+ }
64
59
 
65
- // auto generate state colors
60
+ // auto generate state colors
61
+ if (!Object.hasOwn(input, "info")) {
62
+ resultObj["--in"] = "0.7206 0.191 231.6"
63
+ }
64
+ if (!Object.hasOwn(input, "success")) {
65
+ resultObj["--su"] = "0.7441 0.213 164.75"
66
+ }
67
+ if (!Object.hasOwn(input, "warning")) {
68
+ resultObj["--wa"] = "0.8471 0.199 83.87"
69
+ }
70
+ if (!Object.hasOwn(input, "error")) {
71
+ resultObj["--er"] = "0.7176 0.221 22.18"
72
+ }
66
73
 
67
- if (!Object.hasOwn(input, "info")) {
68
- resultObj["--in"] = "0.7206 0.191 231.6"
74
+ // auto generate content colors
75
+ if (!Object.hasOwn(input, "base-content")) {
76
+ resultObj["--bc"] = generateForegroundColorFrom(input["base-100"], 0.8)
77
+ }
78
+ if (!Object.hasOwn(input, "primary-content")) {
79
+ resultObj["--pc"] = generateForegroundColorFrom(input["primary"], 0.8)
80
+ }
81
+ if (!Object.hasOwn(input, "secondary-content")) {
82
+ resultObj["--sc"] = generateForegroundColorFrom(input["secondary"], 0.8)
83
+ }
84
+ if (!Object.hasOwn(input, "accent-content")) {
85
+ resultObj["--ac"] = generateForegroundColorFrom(input["accent"], 0.8)
86
+ }
87
+ if (!Object.hasOwn(input, "neutral-content")) {
88
+ resultObj["--nc"] = generateForegroundColorFrom(input["neutral"], 0.8)
89
+ }
90
+ if (!Object.hasOwn(input, "info-content")) {
91
+ if (Object.hasOwn(input, "info")) {
92
+ resultObj["--inc"] = generateForegroundColorFrom(input["info"], 0.8)
93
+ } else {
94
+ resultObj["--inc"] = "0 0 0"
69
95
  }
70
- if (!Object.hasOwn(input, "success")) {
71
- resultObj["--su"] = "0.7441 0.213 164.75"
96
+ }
97
+ if (!Object.hasOwn(input, "success-content")) {
98
+ if (Object.hasOwn(input, "success")) {
99
+ resultObj["--suc"] = generateForegroundColorFrom(input["success"], 0.8)
100
+ } else {
101
+ resultObj["--suc"] = "0 0 0"
72
102
  }
73
- if (!Object.hasOwn(input, "warning")) {
74
- resultObj["--wa"] = "0.8471 0.199 83.87"
103
+ }
104
+ if (!Object.hasOwn(input, "warning-content")) {
105
+ if (Object.hasOwn(input, "warning")) {
106
+ resultObj["--wac"] = generateForegroundColorFrom(input["warning"], 0.8)
107
+ } else {
108
+ resultObj["--wac"] = "0 0 0"
75
109
  }
76
- if (!Object.hasOwn(input, "error")) {
77
- resultObj["--er"] = "0.7176 0.221 22.18"
110
+ }
111
+ if (!Object.hasOwn(input, "error-content")) {
112
+ if (Object.hasOwn(input, "error")) {
113
+ resultObj["--erc"] = generateForegroundColorFrom(input["error"], 0.8)
114
+ } else {
115
+ resultObj["--erc"] = "0 0 0"
78
116
  }
117
+ }
79
118
 
80
- // auto generate content colors
81
- if (!Object.hasOwn(input, "base-content")) {
82
- resultObj["--bc"] = this.generateForegroundColorFrom(input["base-100"], 0.8)
83
- }
84
- if (!Object.hasOwn(input, "primary-content")) {
85
- resultObj["--pc"] = this.generateForegroundColorFrom(input["primary"], 0.8)
86
- }
87
- if (!Object.hasOwn(input, "secondary-content")) {
88
- resultObj["--sc"] = this.generateForegroundColorFrom(input["secondary"], 0.8)
89
- }
90
- if (!Object.hasOwn(input, "accent-content")) {
91
- resultObj["--ac"] = this.generateForegroundColorFrom(input["accent"], 0.8)
92
- }
93
- if (!Object.hasOwn(input, "neutral-content")) {
94
- resultObj["--nc"] = this.generateForegroundColorFrom(input["neutral"], 0.8)
95
- }
96
- if (!Object.hasOwn(input, "info-content")) {
97
- if (Object.hasOwn(input, "info")) {
98
- resultObj["--inc"] = this.generateForegroundColorFrom(input["info"], 0.8)
99
- } else {
100
- resultObj["--inc"] = "0 0 0"
101
- }
102
- }
103
- if (!Object.hasOwn(input, "success-content")) {
104
- if (Object.hasOwn(input, "success")) {
105
- resultObj["--suc"] = this.generateForegroundColorFrom(input["success"], 0.8)
106
- } else {
107
- resultObj["--suc"] = "0 0 0"
108
- }
109
- }
110
- if (!Object.hasOwn(input, "warning-content")) {
111
- if (Object.hasOwn(input, "warning")) {
112
- resultObj["--wac"] = this.generateForegroundColorFrom(input["warning"], 0.8)
113
- } else {
114
- resultObj["--wac"] = "0 0 0"
115
- }
116
- }
117
- if (!Object.hasOwn(input, "error-content")) {
118
- if (Object.hasOwn(input, "error")) {
119
- resultObj["--erc"] = this.generateForegroundColorFrom(input["error"], 0.8)
120
- } else {
121
- resultObj["--erc"] = "0 0 0"
122
- }
119
+ // add css variables if not exist
120
+ Object.entries(variables).forEach((item) => {
121
+ const [variable, value] = item
122
+ if (!Object.hasOwn(input, variable)) {
123
+ resultObj[variable] = value
123
124
  }
125
+ })
124
126
 
125
- // add css variables if not exist
126
- Object.entries(themeDefaults.variables).forEach((item) => {
127
- const [variable, value] = item
128
- if (!Object.hasOwn(input, variable)) {
129
- resultObj[variable] = value
130
- }
131
- })
127
+ // add other custom styles
128
+ if (!colorNames.hasOwnProperty(rule)) {
129
+ resultObj[rule] = value
130
+ }
131
+ })
132
132
 
133
- // add other custom styles
134
- if (!colorNames.hasOwnProperty(rule)) {
135
- resultObj[rule] = value
133
+ return resultObj
134
+ }
135
+ export function injectThemes(addBase, config, themes) {
136
+ const includedThemesObj = {}
137
+ // add default themes
138
+ const themeRoot = config("daisyui.themeRoot") ?? ":root"
139
+ Object.entries(themes).forEach(([theme, value]) => {
140
+ includedThemesObj[theme] = convertColorFormat(value)
141
+ })
142
+
143
+ // add custom themes
144
+ if (Array.isArray(config("daisyui.themes"))) {
145
+ config("daisyui.themes").forEach((item) => {
146
+ if (typeof item === "object" && item !== null) {
147
+ Object.entries(item).forEach(([customThemeName, customThemevalue]) => {
148
+ includedThemesObj[customThemeName] = convertColorFormat(customThemevalue)
149
+ })
136
150
  }
137
151
  })
138
-
139
- return resultObj
140
- },
141
-
142
- injectThemes: function (addBase, config, themes) {
143
- const includedThemesObj = {}
144
- // add default themes
145
- const themeRoot = config("daisyui.themeRoot") ?? ":root"
146
- Object.entries(themes).forEach(([theme, value]) => {
147
- includedThemesObj[theme] = this.convertColorFormat(value)
152
+ }
153
+
154
+ let themeOrder = []
155
+ if (Array.isArray(config("daisyui.themes"))) {
156
+ config("daisyui.themes").forEach((theme) => {
157
+ if (typeof theme === "object" && theme !== null) {
158
+ Object.keys(theme).forEach((customThemeName) => {
159
+ themeOrder.push(customThemeName)
160
+ })
161
+ } else if (Object.hasOwn(includedThemesObj, theme)) {
162
+ themeOrder.push(theme)
163
+ }
148
164
  })
149
-
150
- // add custom themes
151
- if (Array.isArray(config("daisyui.themes"))) {
152
- config("daisyui.themes").forEach((item) => {
153
- if (typeof item === "object" && item !== null) {
154
- Object.entries(item).forEach(([customThemeName, customThemevalue]) => {
155
- includedThemesObj[customThemeName] = this.convertColorFormat(customThemevalue)
156
- })
157
- }
158
- })
159
- }
160
-
161
- let themeOrder = []
162
- if (Array.isArray(config("daisyui.themes"))) {
163
- config("daisyui.themes").forEach((theme) => {
164
- if (typeof theme === "object" && theme !== null) {
165
- Object.keys(theme).forEach((customThemeName) => {
166
- themeOrder.push(customThemeName)
167
- })
168
- } else if (Object.hasOwn(includedThemesObj, theme)) {
169
- themeOrder.push(theme)
170
- }
171
- })
172
- } else if (config("daisyui.themes") === true) {
173
- themeOrder = themeDefaults.themeOrder
174
- } else {
175
- themeOrder = ["light", "dark"]
176
- }
177
-
178
- // inject themes in order
179
- const themesToInject = {}
180
- themeOrder.forEach((themeName, index) => {
181
- if (index === 0) {
182
- // first theme as root
183
- themesToInject[themeRoot] = includedThemesObj[themeName]
184
- } else if (index === 1) {
185
- // auto dark
186
- if (config("daisyui.darkTheme")) {
187
- if (
188
- themeOrder[0] !== config("daisyui.darkTheme") &&
189
- themeOrder.includes(config("daisyui.darkTheme"))
190
- ) {
191
- themesToInject["@media (prefers-color-scheme: dark)"] = {
192
- [themeRoot]: includedThemesObj[`${config("daisyui.darkTheme")}`],
193
- }
194
- }
195
- } else if (config("daisyui.darkTheme") === false) {
196
- // disables prefers-color-scheme: dark
197
- } else {
198
- if (themeOrder[0] !== "dark" && themeOrder.includes("dark")) {
199
- themesToInject["@media (prefers-color-scheme: dark)"] = {
200
- [themeRoot]: includedThemesObj["dark"],
201
- }
165
+ } else if (config("daisyui.themes") === true) {
166
+ themeOrder = themesOrder
167
+ } else {
168
+ themeOrder = ["light", "dark"]
169
+ }
170
+
171
+ // inject themes in order
172
+ const themesToInject = {}
173
+ themeOrder.forEach((themeName, index) => {
174
+ if (index === 0) {
175
+ // first theme as root
176
+ themesToInject[themeRoot] = includedThemesObj[themeName]
177
+ } else if (index === 1) {
178
+ // auto dark
179
+ if (config("daisyui.darkTheme")) {
180
+ if (
181
+ themeOrder[0] !== config("daisyui.darkTheme") &&
182
+ themeOrder.includes(config("daisyui.darkTheme"))
183
+ ) {
184
+ themesToInject["@media (prefers-color-scheme: dark)"] = {
185
+ [themeRoot]: includedThemesObj[`${config("daisyui.darkTheme")}`],
202
186
  }
203
187
  }
204
- // theme 0 with name
205
- themesToInject["[data-theme=" + themeOrder[0] + "]"] = includedThemesObj[themeOrder[0]]
206
- themesToInject[
207
- themeRoot + ":has(input.theme-controller[value=" + themeOrder[0] + "]:checked)"
208
- ] = includedThemesObj[themeOrder[0]]
209
- // theme 1 with name
210
- themesToInject["[data-theme=" + themeOrder[1] + "]"] = includedThemesObj[themeOrder[1]]
211
- themesToInject[
212
- themeRoot + ":has(input.theme-controller[value=" + themeOrder[1] + "]:checked)"
213
- ] = includedThemesObj[themeOrder[1]]
188
+ } else if (config("daisyui.darkTheme") === false) {
214
189
  } else {
215
- themesToInject["[data-theme=" + themeName + "]"] = includedThemesObj[themeName]
216
- themesToInject[
217
- themeRoot + ":has(input.theme-controller[value=" + themeName + "]:checked)"
218
- ] = includedThemesObj[themeName]
190
+ if (themeOrder[0] !== "dark" && themeOrder.includes("dark")) {
191
+ themesToInject["@media (prefers-color-scheme: dark)"] = {
192
+ [themeRoot]: includedThemesObj["dark"],
193
+ }
194
+ }
219
195
  }
220
- })
196
+ // theme 0 with name
197
+ themesToInject["[data-theme=" + themeOrder[0] + "]"] = includedThemesObj[themeOrder[0]]
198
+ themesToInject[
199
+ themeRoot + ":has(input.theme-controller[value=" + themeOrder[0] + "]:checked)"
200
+ ] = includedThemesObj[themeOrder[0]]
201
+ // theme 1 with name
202
+ themesToInject["[data-theme=" + themeOrder[1] + "]"] = includedThemesObj[themeOrder[1]]
203
+ themesToInject[
204
+ themeRoot + ":has(input.theme-controller[value=" + themeOrder[1] + "]:checked)"
205
+ ] = includedThemesObj[themeOrder[1]]
206
+ } else {
207
+ themesToInject["[data-theme=" + themeName + "]"] = includedThemesObj[themeName]
208
+ themesToInject[themeRoot + ":has(input.theme-controller[value=" + themeName + "]:checked)"] =
209
+ includedThemesObj[themeName]
210
+ }
211
+ })
221
212
 
222
- addBase(themesToInject)
213
+ addBase(themesToInject)
223
214
 
224
- return {
225
- includedThemesObj,
226
- themeOrder,
227
- }
228
- },
215
+ return {
216
+ includedThemesObj,
217
+ themeOrder,
218
+ }
229
219
  }
@@ -1,4 +1,4 @@
1
- const colorNames = require("./colorNames")
1
+ import colorNames from "./colorNames"
2
2
 
3
3
  const colorObject = {
4
4
  "transparent": "transparent",
@@ -34,4 +34,4 @@ const colorObject = {
34
34
  "error-content": "var(--fallback-erc,oklch(var(--erc)/<alpha-value>))",
35
35
  }
36
36
 
37
- module.exports = colorObject
37
+ export default colorObject
@@ -1,47 +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
- "dim",
33
- "nord",
34
- "sunset",
35
- ],
36
- variables: {
37
- "--rounded-box": "1rem",
38
- "--rounded-btn": "0.5rem",
39
- "--rounded-badge": "1.9rem",
40
- "--animation-btn": "0.25s",
41
- "--animation-input": ".2s",
42
- "--btn-focus-scale": "0.95",
43
- "--border-btn": "1px",
44
- "--tab-border": "1px",
45
- "--tab-radius": "0.5rem",
46
- },
1
+ export const themesOrder = [
2
+ "light",
3
+ "dark",
4
+ "cupcake",
5
+ "bumblebee",
6
+ "emerald",
7
+ "corporate",
8
+ "synthwave",
9
+ "retro",
10
+ "cyberpunk",
11
+ "valentine",
12
+ "halloween",
13
+ "garden",
14
+ "forest",
15
+ "aqua",
16
+ "lofi",
17
+ "pastel",
18
+ "fantasy",
19
+ "wireframe",
20
+ "black",
21
+ "luxury",
22
+ "dracula",
23
+ "cmyk",
24
+ "autumn",
25
+ "business",
26
+ "acid",
27
+ "lemonade",
28
+ "night",
29
+ "coffee",
30
+ "winter",
31
+ "dim",
32
+ "nord",
33
+ "sunset",
34
+ ]
35
+ export const variables = {
36
+ "--rounded-box": "1rem",
37
+ "--rounded-btn": "0.5rem",
38
+ "--rounded-badge": "1.9rem",
39
+ "--animation-btn": "0.25s",
40
+ "--animation-input": ".2s",
41
+ "--btn-focus-scale": "0.95",
42
+ "--border-btn": "1px",
43
+ "--tab-border": "1px",
44
+ "--tab-radius": "0.5rem",
47
45
  }
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export const themes = {
2
2
  aqua: {
3
3
  "color-scheme": "dark",
4
4
  "primary": "#09ecf3",