@zag-js/color-picker 0.20.0 → 0.22.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/dist/index.js +53 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/color-picker.connect.ts +23 -14
- package/src/color-picker.machine.ts +37 -26
- package/src/utils/get-channel-details.ts +2 -2
- package/src/utils/get-channel-input-value.ts +20 -0
- package/src/utils/generate-format-background.ts +0 -139
- package/src/utils/get-color-area-gradient.ts +0 -84
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
export const generateRGB_R = (orientation: [string, string], dir: boolean, zValue: number) => {
|
|
2
|
-
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`
|
|
3
|
-
const result = {
|
|
4
|
-
areaStyles: {
|
|
5
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`,
|
|
6
|
-
},
|
|
7
|
-
areaGradientStyles: {
|
|
8
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
|
|
9
|
-
WebkitMaskImage: maskImage,
|
|
10
|
-
maskImage,
|
|
11
|
-
},
|
|
12
|
-
}
|
|
13
|
-
return result
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const generateRGB_G = (orientation: [string, string], dir: boolean, zValue: number) => {
|
|
17
|
-
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`
|
|
18
|
-
const result = {
|
|
19
|
-
areaStyles: {
|
|
20
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`,
|
|
21
|
-
},
|
|
22
|
-
areaGradientStyles: {
|
|
23
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
|
|
24
|
-
WebkitMaskImage: maskImage,
|
|
25
|
-
maskImage,
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
return result
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const generateRGB_B = (orientation: [string, string], dir: boolean, zValue: number) => {
|
|
32
|
-
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`
|
|
33
|
-
const result = {
|
|
34
|
-
areaStyles: {
|
|
35
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`,
|
|
36
|
-
},
|
|
37
|
-
areaGradientStyles: {
|
|
38
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
|
|
39
|
-
WebkitMaskImage: maskImage,
|
|
40
|
-
maskImage,
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
return result
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const generateHSL_H = (orientation: [string, string], dir: boolean, zValue: number) => {
|
|
47
|
-
const result = {
|
|
48
|
-
areaStyles: {},
|
|
49
|
-
areaGradientStyles: {
|
|
50
|
-
background: [
|
|
51
|
-
`linear-gradient(to ${
|
|
52
|
-
orientation[Number(dir)]
|
|
53
|
-
}, hsla(0,0%,0%,1) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,1) 100%)`,
|
|
54
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
|
|
55
|
-
`hsl(${zValue}, 100%, 50%)`,
|
|
56
|
-
].join(","),
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
return result
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const generateHSL_S = (orientation: [string, string], dir: boolean, alphaValue: number) => {
|
|
63
|
-
const result = {
|
|
64
|
-
areaStyles: {},
|
|
65
|
-
areaGradientStyles: {
|
|
66
|
-
background: [
|
|
67
|
-
`linear-gradient(to ${
|
|
68
|
-
orientation[Number(!dir)]
|
|
69
|
-
}, hsla(0,0%,0%,${alphaValue}) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,${alphaValue}) 100%)`,
|
|
70
|
-
`linear-gradient(to ${
|
|
71
|
-
orientation[Number(dir)]
|
|
72
|
-
},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
73
|
-
"hsl(0, 0%, 50%)",
|
|
74
|
-
].join(","),
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
return result
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const generateHSL_L = (orientation: [string, string], dir: boolean, zValue: number) => {
|
|
81
|
-
const result = {
|
|
82
|
-
areaStyles: {},
|
|
83
|
-
areaGradientStyles: {
|
|
84
|
-
backgroundImage: [
|
|
85
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
|
|
86
|
-
`linear-gradient(to ${
|
|
87
|
-
orientation[Number(dir)]
|
|
88
|
-
},hsl(0,100%,${zValue}%),hsl(60,100%,${zValue}%),hsl(120,100%,${zValue}%),hsl(180,100%,${zValue}%),hsl(240,100%,${zValue}%),hsl(300,100%,${zValue}%),hsl(360,100%,${zValue}%))`,
|
|
89
|
-
].join(","),
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
return result
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const generateHSB_H = (orientation: [string, string], dir: boolean, zValue: number) => {
|
|
96
|
-
const result = {
|
|
97
|
-
areaStyles: {},
|
|
98
|
-
areaGradientStyles: {
|
|
99
|
-
background: [
|
|
100
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
|
|
101
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
|
|
102
|
-
`hsl(${zValue}, 100%, 50%)`,
|
|
103
|
-
].join(","),
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
return result
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const generateHSB_S = (orientation: [string, string], dir: boolean, alphaValue: number) => {
|
|
110
|
-
const result = {
|
|
111
|
-
areaStyles: {},
|
|
112
|
-
areaGradientStyles: {
|
|
113
|
-
background: [
|
|
114
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
|
|
115
|
-
`linear-gradient(to ${
|
|
116
|
-
orientation[Number(dir)]
|
|
117
|
-
},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
118
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`,
|
|
119
|
-
].join(","),
|
|
120
|
-
},
|
|
121
|
-
}
|
|
122
|
-
return result
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export const generateHSB_B = (orientation: [string, string], dir: boolean, alphaValue: number) => {
|
|
126
|
-
const result = {
|
|
127
|
-
areaStyles: {},
|
|
128
|
-
areaGradientStyles: {
|
|
129
|
-
background: [
|
|
130
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
|
|
131
|
-
`linear-gradient(to ${
|
|
132
|
-
orientation[Number(dir)]
|
|
133
|
-
},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
134
|
-
"#000",
|
|
135
|
-
].join(","),
|
|
136
|
-
},
|
|
137
|
-
}
|
|
138
|
-
return result
|
|
139
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { ColorChannel } from "@zag-js/color-utils"
|
|
2
|
-
import type { Style } from "@zag-js/types"
|
|
3
|
-
import type { MachineContext } from "../color-picker.types"
|
|
4
|
-
import {
|
|
5
|
-
generateHSB_B,
|
|
6
|
-
generateHSB_H,
|
|
7
|
-
generateHSB_S,
|
|
8
|
-
generateHSL_H,
|
|
9
|
-
generateHSL_L,
|
|
10
|
-
generateHSL_S,
|
|
11
|
-
generateRGB_B,
|
|
12
|
-
generateRGB_G,
|
|
13
|
-
generateRGB_R,
|
|
14
|
-
} from "./generate-format-background"
|
|
15
|
-
|
|
16
|
-
export function getColorAreaGradient(ctx: MachineContext, xChannel: ColorChannel, yChannel: ColorChannel) {
|
|
17
|
-
const value = ctx.valueAsColor
|
|
18
|
-
|
|
19
|
-
const { zChannel } = value.getColorSpaceAxes({ xChannel, yChannel })
|
|
20
|
-
const zValue = value.getChannelValue(zChannel)
|
|
21
|
-
|
|
22
|
-
const { minValue: zMin, maxValue: zMax } = value.getChannelRange(zChannel)
|
|
23
|
-
const orientation: [string, string] = ["top", ctx.dir === "rtl" ? "left" : "right"]
|
|
24
|
-
|
|
25
|
-
let dir = false
|
|
26
|
-
let background = { areaStyles: {} as Style, areaGradientStyles: {} as Style }
|
|
27
|
-
|
|
28
|
-
let alphaValue = (zValue - zMin) / (zMax - zMin)
|
|
29
|
-
let isHSL = value.getColorSpace() === "hsl"
|
|
30
|
-
|
|
31
|
-
switch (zChannel) {
|
|
32
|
-
case "red": {
|
|
33
|
-
dir = xChannel === "green"
|
|
34
|
-
background = generateRGB_R(orientation, dir, zValue)
|
|
35
|
-
break
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
case "green": {
|
|
39
|
-
dir = xChannel === "red"
|
|
40
|
-
background = generateRGB_G(orientation, dir, zValue)
|
|
41
|
-
break
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
case "blue": {
|
|
45
|
-
dir = xChannel === "red"
|
|
46
|
-
background = generateRGB_B(orientation, dir, zValue)
|
|
47
|
-
break
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
case "hue": {
|
|
51
|
-
dir = xChannel !== "saturation"
|
|
52
|
-
if (isHSL) {
|
|
53
|
-
background = generateHSL_H(orientation, dir, zValue)
|
|
54
|
-
} else {
|
|
55
|
-
background = generateHSB_H(orientation, dir, zValue)
|
|
56
|
-
}
|
|
57
|
-
break
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
case "saturation": {
|
|
61
|
-
dir = xChannel === "hue"
|
|
62
|
-
if (isHSL) {
|
|
63
|
-
background = generateHSL_S(orientation, dir, alphaValue)
|
|
64
|
-
} else {
|
|
65
|
-
background = generateHSB_S(orientation, dir, alphaValue)
|
|
66
|
-
}
|
|
67
|
-
break
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
case "brightness": {
|
|
71
|
-
dir = xChannel === "hue"
|
|
72
|
-
background = generateHSB_B(orientation, dir, alphaValue)
|
|
73
|
-
break
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
case "lightness": {
|
|
77
|
-
dir = xChannel === "hue"
|
|
78
|
-
background = generateHSL_L(orientation, dir, zValue)
|
|
79
|
-
break
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return background
|
|
84
|
-
}
|