daisyui 4.3.0-alpha.11 → 4.3.0-alpha.3

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