daisyui 4.12.2 → 4.12.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.
package/src/index.js CHANGED
@@ -16,11 +16,11 @@ const utilitiesStyled = require("../dist/utilities-styled")
16
16
  const themes = require("./theming/themes")
17
17
  const colorFunctions = require("./theming/functions")
18
18
  const utilityClasses = require("./lib/utility-classes")
19
- let colorObject = require("./theming/index")
19
+ const colorObject = require("./theming/index")
20
20
 
21
21
  const mainFunction = ({ addBase, addComponents, config }) => {
22
22
  let logs = false
23
- if (config("daisyui.logs") != false) {
23
+ if (config("daisyui.logs") !== false) {
24
24
  logs = true
25
25
  }
26
26
  if (logs) {
@@ -29,13 +29,13 @@ const mainFunction = ({ addBase, addComponents, config }) => {
29
29
  }
30
30
 
31
31
  // inject @base style
32
- if (config("daisyui.base") != false) {
32
+ if (config("daisyui.base") !== false) {
33
33
  addBase(base)
34
34
  }
35
35
 
36
36
  // inject components
37
37
  let file = styled
38
- if (config("daisyui.styled") == false) {
38
+ if (config("daisyui.styled") === false) {
39
39
  file = unstyled
40
40
  }
41
41
 
@@ -60,7 +60,7 @@ const mainFunction = ({ addBase, addComponents, config }) => {
60
60
  themeInjector
61
61
 
62
62
  // inject @utilities style needed by components
63
- if (config("daisyui.utils") != false) {
63
+ if (config("daisyui.utils") !== false) {
64
64
  addComponents(utilities, { variants: ["responsive"] })
65
65
 
66
66
  let toAdd = utilitiesUnstyled // shadow clone here to avoid mutate the original
@@ -77,14 +77,14 @@ const mainFunction = ({ addBase, addComponents, config }) => {
77
77
  }
78
78
 
79
79
  if (logs) {
80
- if (config("daisyui.styled") == false) {
80
+ if (config("daisyui.styled") === false) {
81
81
  console.log(
82
82
  `├─ ${pc.yellow("ℹ︎")} ${pc.blue("styled")} ${pc.reset("config is")} ${pc.blue(
83
83
  "false"
84
84
  )} ${pc.dim("\tcomponents won't have design decisions")}`
85
85
  )
86
86
  }
87
- if (config("daisyui.utils") == false) {
87
+ if (config("daisyui.utils") === false) {
88
88
  console.log(
89
89
  `├─ ${pc.yellow("ℹ︎")} ${pc.blue("utils")} ${pc.reset("config is")} ${pc.blue(
90
90
  "false"
@@ -112,7 +112,7 @@ const mainFunction = ({ addBase, addComponents, config }) => {
112
112
  )}`
113
113
  )
114
114
  }
115
- let messages = [
115
+ const messages = [
116
116
  `${pc.green("❤︎")} ${pc.reset("Support daisyUI project:")}\t${pc.dim(
117
117
  daisyuiInfo.funding.url
118
118
  )}`,
@@ -4,14 +4,12 @@ function createPlugin(plugin, config) {
4
4
  config,
5
5
  }
6
6
  }
7
- createPlugin.withOptions = function (pluginFunction, configFunction = () => ({})) {
8
- const optionsFunction = function (options) {
9
- return {
10
- __options: options,
11
- handler: pluginFunction(options),
12
- config: configFunction(options),
13
- }
14
- }
7
+ createPlugin.withOptions = (pluginFunction, configFunction = () => ({})) => {
8
+ const optionsFunction = (options) => ({
9
+ __options: options,
10
+ handler: pluginFunction(options),
11
+ config: configFunction(options),
12
+ })
15
13
  optionsFunction.__isOptionsFunction = true
16
14
  optionsFunction.__pluginFunction = pluginFunction
17
15
  optionsFunction.__configFunction = configFunction
@@ -15,9 +15,8 @@ const cutNumber = (number) => {
15
15
  try {
16
16
  if (number) {
17
17
  return +number.toFixed(6)
18
- } else {
19
- return 0
20
18
  }
19
+ return 0
21
20
  } catch (e) {
22
21
  // colorIsInvalid(number)
23
22
  return false
@@ -36,9 +35,9 @@ module.exports = {
36
35
  }
37
36
  },
38
37
 
39
- colorObjToString: function (input) {
38
+ colorObjToString: (input) => {
40
39
  const { l, c, h } = input
41
- return `${parseFloat((cutNumber(l) * 100).toFixed(6))}% ${cutNumber(c)} ${cutNumber(h)}`
40
+ return `${Number.parseFloat((cutNumber(l) * 100).toFixed(6))}% ${cutNumber(c)} ${cutNumber(h)}`
42
41
  },
43
42
 
44
43
  generateForegroundColorFrom: function (input, percentage = 0.8) {
@@ -71,7 +70,7 @@ module.exports = {
71
70
 
72
71
  const resultObj = {}
73
72
 
74
- Object.entries(input).forEach(([rule, value]) => {
73
+ for (const [rule, value] of Object.entries(input)) {
75
74
  if (Object.hasOwn(colorNames, rule)) {
76
75
  try {
77
76
  const colorObj = oklch(value)
@@ -119,59 +118,59 @@ module.exports = {
119
118
  resultObj["--bc"] = this.generateForegroundColorFrom(input["base-100"], 0.8)
120
119
  }
121
120
  if (!Object.hasOwn(input, "primary-content")) {
122
- resultObj["--pc"] = this.generateForegroundColorFrom(input["primary"], 0.8)
121
+ resultObj["--pc"] = this.generateForegroundColorFrom(input.primary, 0.8)
123
122
  }
124
123
  if (!Object.hasOwn(input, "secondary-content")) {
125
- resultObj["--sc"] = this.generateForegroundColorFrom(input["secondary"], 0.8)
124
+ resultObj["--sc"] = this.generateForegroundColorFrom(input.secondary, 0.8)
126
125
  }
127
126
  if (!Object.hasOwn(input, "accent-content")) {
128
- resultObj["--ac"] = this.generateForegroundColorFrom(input["accent"], 0.8)
127
+ resultObj["--ac"] = this.generateForegroundColorFrom(input.accent, 0.8)
129
128
  }
130
129
  if (!Object.hasOwn(input, "neutral-content")) {
131
- resultObj["--nc"] = this.generateForegroundColorFrom(input["neutral"], 0.8)
130
+ resultObj["--nc"] = this.generateForegroundColorFrom(input.neutral, 0.8)
132
131
  }
133
132
  if (!Object.hasOwn(input, "info-content")) {
134
133
  if (Object.hasOwn(input, "info")) {
135
- resultObj["--inc"] = this.generateForegroundColorFrom(input["info"], 0.8)
134
+ resultObj["--inc"] = this.generateForegroundColorFrom(input.info, 0.8)
136
135
  } else {
137
136
  resultObj["--inc"] = "0% 0 0"
138
137
  }
139
138
  }
140
139
  if (!Object.hasOwn(input, "success-content")) {
141
140
  if (Object.hasOwn(input, "success")) {
142
- resultObj["--suc"] = this.generateForegroundColorFrom(input["success"], 0.8)
141
+ resultObj["--suc"] = this.generateForegroundColorFrom(input.success, 0.8)
143
142
  } else {
144
143
  resultObj["--suc"] = "0% 0 0"
145
144
  }
146
145
  }
147
146
  if (!Object.hasOwn(input, "warning-content")) {
148
147
  if (Object.hasOwn(input, "warning")) {
149
- resultObj["--wac"] = this.generateForegroundColorFrom(input["warning"], 0.8)
148
+ resultObj["--wac"] = this.generateForegroundColorFrom(input.warning, 0.8)
150
149
  } else {
151
150
  resultObj["--wac"] = "0% 0 0"
152
151
  }
153
152
  }
154
153
  if (!Object.hasOwn(input, "error-content")) {
155
154
  if (Object.hasOwn(input, "error")) {
156
- resultObj["--erc"] = this.generateForegroundColorFrom(input["error"], 0.8)
155
+ resultObj["--erc"] = this.generateForegroundColorFrom(input.error, 0.8)
157
156
  } else {
158
157
  resultObj["--erc"] = "0% 0 0"
159
158
  }
160
159
  }
161
160
 
162
161
  // add css variables if not exist
163
- Object.entries(themeDefaults.variables).forEach((item) => {
162
+ for (const item of Object.entries(themeDefaults.variables)) {
164
163
  const [variable, value] = item
165
164
  if (!Object.hasOwn(input, variable)) {
166
165
  resultObj[variable] = value
167
166
  }
168
- })
167
+ }
169
168
 
170
169
  // add other custom styles
171
170
  if (!Object.hasOwn(colorNames, rule)) {
172
171
  resultObj[rule] = value
173
172
  }
174
- })
173
+ }
175
174
 
176
175
  return resultObj
177
176
  },
@@ -180,32 +179,32 @@ module.exports = {
180
179
  const includedThemesObj = {}
181
180
  // add default themes
182
181
  const themeRoot = config("daisyui.themeRoot") ?? ":root"
183
- Object.entries(themes).forEach(([theme, value]) => {
182
+ for (const [theme, value] of Object.entries(themes)) {
184
183
  includedThemesObj[theme] = this.convertColorFormat(value)
185
- })
184
+ }
186
185
 
187
186
  // add custom themes
188
187
  if (Array.isArray(config("daisyui.themes"))) {
189
- config("daisyui.themes").forEach((item) => {
188
+ for (const item of config("daisyui.themes")) {
190
189
  if (typeof item === "object" && item !== null) {
191
- Object.entries(item).forEach(([customThemeName, customThemevalue]) => {
190
+ for (const [customThemeName, customThemevalue] of Object.entries(item)) {
192
191
  includedThemesObj[customThemeName] = this.convertColorFormat(customThemevalue)
193
- })
192
+ }
194
193
  }
195
- })
194
+ }
196
195
  }
197
196
 
198
197
  let themeOrder = []
199
198
  if (Array.isArray(config("daisyui.themes"))) {
200
- config("daisyui.themes").forEach((theme) => {
199
+ for (const item of config("daisyui.themes")) {
201
200
  if (typeof theme === "object" && theme !== null) {
202
- Object.keys(theme).forEach((customThemeName) => {
201
+ for (const customThemeName of Object.keys(item)) {
203
202
  themeOrder.push(customThemeName)
204
- })
203
+ }
205
204
  } else if (Object.hasOwn(includedThemesObj, theme)) {
206
205
  themeOrder.push(theme)
207
206
  }
208
- })
207
+ }
209
208
  } else if (config("daisyui.themes") === true) {
210
209
  themeOrder = themeDefaults.themeOrder
211
210
  } else {
@@ -234,25 +233,22 @@ module.exports = {
234
233
  } else {
235
234
  if (themeOrder[0] !== "dark" && themeOrder.includes("dark")) {
236
235
  themesToInject["@media (prefers-color-scheme: dark)"] = {
237
- [themeRoot]: includedThemesObj["dark"],
236
+ [themeRoot]: includedThemesObj.dark,
238
237
  }
239
238
  }
240
239
  }
241
240
  // theme 0 with name
242
- themesToInject["[data-theme=" + themeOrder[0] + "]"] = includedThemesObj[themeOrder[0]]
243
- themesToInject[
244
- themeRoot + ":has(input.theme-controller[value=" + themeOrder[0] + "]:checked)"
245
- ] = includedThemesObj[themeOrder[0]]
241
+ themesToInject[`[data-theme=${themeOrder[0]}]`] = includedThemesObj[themeOrder[0]]
242
+ themesToInject[`${themeRoot}:has(input.theme-controller[value=${themeOrder[0]}]:checked)`] =
243
+ includedThemesObj[themeOrder[0]]
246
244
  // theme 1 with name
247
- themesToInject["[data-theme=" + themeOrder[1] + "]"] = includedThemesObj[themeOrder[1]]
248
- themesToInject[
249
- themeRoot + ":has(input.theme-controller[value=" + themeOrder[1] + "]:checked)"
250
- ] = includedThemesObj[themeOrder[1]]
245
+ themesToInject[`[data-theme=${themeOrder[1]}]`] = includedThemesObj[themeOrder[1]]
246
+ themesToInject[`${themeRoot}:has(input.theme-controller[value=${themeOrder[1]}]:checked)`] =
247
+ includedThemesObj[themeOrder[1]]
251
248
  } else {
252
- themesToInject["[data-theme=" + themeName + "]"] = includedThemesObj[themeName]
253
- themesToInject[
254
- themeRoot + ":has(input.theme-controller[value=" + themeName + "]:checked)"
255
- ] = includedThemesObj[themeName]
249
+ themesToInject[`[data-theme=${themeName}]`] = includedThemesObj[themeName]
250
+ themesToInject[`${themeRoot}:has(input.theme-controller[value=${themeName}]:checked)`] =
251
+ includedThemesObj[themeName]
256
252
  }
257
253
  })
258
254
 
@@ -1,4 +1,4 @@
1
- import { CustomTheme, Theme } from "../index"
1
+ import type { CustomTheme, Theme } from "../index"
2
2
 
3
3
  declare const themes: Record<`${Theme}`, CustomTheme[string]>
4
4