daisyui 4.3.1 → 4.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "daisyui",
3
- "version": "4.3.1",
3
+ "version": "4.4.0",
4
4
  "description": "daisyUI - Tailwind CSS Components",
5
5
  "author": "Pouya Saadeghi",
6
6
  "license": "MIT",
@@ -1,17 +1,39 @@
1
+ const pc = require("picocolors")
1
2
  const colorNames = require("./colorNames")
2
3
  const themeDefaults = require("./themeDefaults")
3
4
 
4
- const { toGamut, interpolate, wcagContrast } = require("culori/require")
5
-
6
- const cutNumber = (number) => (number ? +number.toFixed(6) : 0)
7
- const toGamutOKLCH = toGamut("oklch")
5
+ const { oklch, interpolate, wcagContrast } = require("culori/require")
8
6
 
7
+ const colorIsInvalid = (input) => {
8
+ console.error(
9
+ `├─ ${pc.red("⚠︎")} ${pc.bgRed(" Error ")} Invalid color ${pc.red(input)} in ${pc.green(
10
+ "tailwind.config.js"
11
+ )}`
12
+ )
13
+ }
14
+ const cutNumber = (number) => {
15
+ try {
16
+ if (number) {
17
+ return +number.toFixed(6)
18
+ } else {
19
+ return 0
20
+ }
21
+ } catch (e) {
22
+ // colorIsInvalid(number)
23
+ return false
24
+ }
25
+ }
9
26
  module.exports = {
10
27
  isDark: (color) => {
11
- if (wcagContrast(color, "black") < wcagContrast(color, "white")) {
12
- return true
28
+ try {
29
+ if (wcagContrast(color, "black") < wcagContrast(color, "white")) {
30
+ return true
31
+ }
32
+ return false
33
+ } catch (e) {
34
+ // colorIsInvalid(color)
35
+ return false
13
36
  }
14
- return false
15
37
  },
16
38
 
17
39
  colorObjToString: function (input) {
@@ -20,13 +42,26 @@ module.exports = {
20
42
  },
21
43
 
22
44
  generateForegroundColorFrom: function (input, percentage = 0.8) {
23
- const result = interpolate([input, this.isDark(input) ? "white" : "black"], "oklch")(percentage)
24
- return this.colorObjToString(result)
45
+ try {
46
+ const result = interpolate(
47
+ [input, this.isDark(input) ? "white" : "black"],
48
+ "oklch"
49
+ )(percentage)
50
+ return this.colorObjToString(result)
51
+ } catch (e) {
52
+ // colorIsInvalid(input)
53
+ return false
54
+ }
25
55
  },
26
56
 
27
57
  generateDarkenColorFrom: function (input, percentage = 0.07) {
28
- const result = interpolate([input, "black"], "oklch")(percentage)
29
- return this.colorObjToString(result)
58
+ try {
59
+ const result = interpolate([input, "black"], "oklch")(percentage)
60
+ return this.colorObjToString(result)
61
+ } catch (e) {
62
+ // colorIsInvalid(input)
63
+ return false
64
+ }
30
65
  },
31
66
 
32
67
  convertColorFormat: function (input) {
@@ -38,8 +73,13 @@ module.exports = {
38
73
 
39
74
  Object.entries(input).forEach(([rule, value]) => {
40
75
  if (Object.hasOwn(colorNames, rule)) {
41
- const colorObj = toGamutOKLCH(value)
42
- resultObj[colorNames[rule]] = this.colorObjToString(colorObj)
76
+ try {
77
+ const colorObj = oklch(value)
78
+ resultObj[colorNames[rule]] = this.colorObjToString(colorObj)
79
+ } catch (e) {
80
+ colorIsInvalid(value)
81
+ return false
82
+ }
43
83
  } else {
44
84
  resultObj[rule] = value
45
85
  }