daisyui 4.3.2-alpha.0 → 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.2-alpha.0",
3
+ "version": "4.4.0",
4
4
  "description": "daisyUI - Tailwind CSS Components",
5
5
  "author": "Pouya Saadeghi",
6
6
  "license": "MIT",
@@ -1,16 +1,39 @@
1
+ const pc = require("picocolors")
1
2
  const colorNames = require("./colorNames")
2
3
  const themeDefaults = require("./themeDefaults")
3
4
 
4
5
  const { oklch, interpolate, wcagContrast } = require("culori/require")
5
6
 
6
- const cutNumber = (number) => (number ? +number.toFixed(6) : 0)
7
-
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
+ }
8
26
  module.exports = {
9
27
  isDark: (color) => {
10
- if (wcagContrast(color, "black") < wcagContrast(color, "white")) {
11
- 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
12
36
  }
13
- return false
14
37
  },
15
38
 
16
39
  colorObjToString: function (input) {
@@ -19,13 +42,26 @@ module.exports = {
19
42
  },
20
43
 
21
44
  generateForegroundColorFrom: function (input, percentage = 0.8) {
22
- const result = interpolate([input, this.isDark(input) ? "white" : "black"], "oklch")(percentage)
23
- 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
+ }
24
55
  },
25
56
 
26
57
  generateDarkenColorFrom: function (input, percentage = 0.07) {
27
- const result = interpolate([input, "black"], "oklch")(percentage)
28
- 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
+ }
29
65
  },
30
66
 
31
67
  convertColorFormat: function (input) {
@@ -37,8 +73,13 @@ module.exports = {
37
73
 
38
74
  Object.entries(input).forEach(([rule, value]) => {
39
75
  if (Object.hasOwn(colorNames, rule)) {
40
- const colorObj = oklch(value)
41
- 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
+ }
42
83
  } else {
43
84
  resultObj[rule] = value
44
85
  }