@pathscale/ui 1.1.0 → 1.1.1
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/components/color-area/ColorArea.css +54 -0
- package/dist/components/color-area/ColorArea.d.ts +15 -0
- package/dist/components/color-area/ColorArea.js +211 -0
- package/dist/components/color-area/index.d.ts +3 -0
- package/dist/components/color-area/index.js +3 -0
- package/dist/components/color-field/ColorField.css +88 -0
- package/dist/components/color-field/ColorField.d.ts +15 -0
- package/dist/components/color-field/ColorField.js +165 -0
- package/dist/components/color-field/index.d.ts +3 -0
- package/dist/components/color-field/index.js +3 -0
- package/dist/components/color-picker/ColorPicker.css +28 -0
- package/dist/components/color-picker/ColorPicker.d.ts +33 -0
- package/dist/components/color-picker/ColorPicker.js +369 -0
- package/dist/components/color-picker/index.d.ts +2 -0
- package/dist/components/color-picker/index.js +8 -0
- package/dist/components/color-slider/ColorSlider.css +57 -0
- package/dist/components/color-slider/ColorSlider.d.ts +13 -0
- package/dist/components/color-slider/ColorSlider.js +178 -0
- package/dist/components/color-slider/index.d.ts +3 -0
- package/dist/components/color-slider/index.js +3 -0
- package/dist/components/color-swatch/ColorSwatch.css +84 -0
- package/dist/components/color-swatch/ColorSwatch.d.ts +17 -0
- package/dist/components/color-swatch/ColorSwatch.js +143 -0
- package/dist/components/color-swatch/index.d.ts +3 -0
- package/dist/components/color-swatch/index.js +3 -0
- package/dist/components/color-swatch-picker/ColorSwatchPicker.css +12 -0
- package/dist/components/color-swatch-picker/ColorSwatchPicker.d.ts +18 -0
- package/dist/components/color-swatch-picker/ColorSwatchPicker.js +109 -0
- package/dist/components/color-swatch-picker/index.d.ts +3 -0
- package/dist/components/color-swatch-picker/index.js +5 -0
- package/dist/components/colorpicker/ColorWheelFlower.css +147 -0
- package/dist/components/colorpicker/ColorWheelFlower.d.ts +1 -0
- package/dist/components/colorpicker/ColorWheelFlower.js +302 -243
- package/dist/components/tabs/Tabs.css +1 -0
- package/dist/components/theme-color-picker/ThemeColorPicker.js +50 -29
- package/dist/index.d.ts +14 -2
- package/dist/index.js +14 -2
- package/package.json +1 -1
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__ from "solid-js/web";
|
|
2
|
+
import "./ColorPicker.css";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__ from "solid-js";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__ from "tailwind-merge";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__color_area_index_js_f79642f5__ from "../color-area/index.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__color_field_index_js_d63b754b__ from "../color-field/index.js";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__color_slider_index_js_89667266__ from "../color-slider/index.js";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE__colorpicker_ColorUtils_js_79ac07b0__ from "../colorpicker/ColorUtils.js";
|
|
9
|
+
var _tmpl$ = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.template)("<div>");
|
|
10
|
+
const DEFAULT_COLOR = "#3B82F6";
|
|
11
|
+
const ColorPickerContext = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createContext)();
|
|
12
|
+
const clamp = (value, min, max)=>Math.min(max, Math.max(min, value));
|
|
13
|
+
const normalizeHue = (value)=>(value % 360 + 360) % 360;
|
|
14
|
+
const normalizeHsv = (value)=>({
|
|
15
|
+
h: normalizeHue(value.h),
|
|
16
|
+
s: clamp(value.s, 0, 100),
|
|
17
|
+
v: clamp(value.v, 0, 100)
|
|
18
|
+
});
|
|
19
|
+
const normalizeAlpha = (value)=>clamp(value, 0, 1);
|
|
20
|
+
const normalizeHex = (value)=>{
|
|
21
|
+
const trimmed = value.trim();
|
|
22
|
+
if (!trimmed) return "";
|
|
23
|
+
const prefixed = trimmed.startsWith("#") ? trimmed : `#${trimmed}`;
|
|
24
|
+
return prefixed.toUpperCase();
|
|
25
|
+
};
|
|
26
|
+
const rgbToHsv = (r, g, b)=>{
|
|
27
|
+
const rNorm = clamp(r, 0, 255) / 255;
|
|
28
|
+
const gNorm = clamp(g, 0, 255) / 255;
|
|
29
|
+
const bNorm = clamp(b, 0, 255) / 255;
|
|
30
|
+
const max = Math.max(rNorm, gNorm, bNorm);
|
|
31
|
+
const min = Math.min(rNorm, gNorm, bNorm);
|
|
32
|
+
const delta = max - min;
|
|
33
|
+
let hue = 0;
|
|
34
|
+
if (0 !== delta) hue = max === rNorm ? ((gNorm - bNorm) / delta + (gNorm < bNorm ? 6 : 0)) * 60 : max === gNorm ? ((bNorm - rNorm) / delta + 2) * 60 : ((rNorm - gNorm) / delta + 4) * 60;
|
|
35
|
+
const saturation = 0 === max ? 0 : delta / max * 100;
|
|
36
|
+
const brightness = 100 * max;
|
|
37
|
+
return normalizeHsv({
|
|
38
|
+
h: hue,
|
|
39
|
+
s: saturation,
|
|
40
|
+
v: brightness
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const hsvToRgb = (h, s, v)=>{
|
|
44
|
+
const hue = normalizeHue(h);
|
|
45
|
+
const saturation = clamp(s, 0, 100) / 100;
|
|
46
|
+
const brightness = clamp(v, 0, 100) / 100;
|
|
47
|
+
const chroma = brightness * saturation;
|
|
48
|
+
const huePrime = hue / 60;
|
|
49
|
+
const x = chroma * (1 - Math.abs(huePrime % 2 - 1));
|
|
50
|
+
const match = brightness - chroma;
|
|
51
|
+
let rPrime = 0;
|
|
52
|
+
let gPrime = 0;
|
|
53
|
+
let bPrime = 0;
|
|
54
|
+
if (huePrime >= 0 && huePrime < 1) {
|
|
55
|
+
rPrime = chroma;
|
|
56
|
+
gPrime = x;
|
|
57
|
+
} else if (huePrime < 2) {
|
|
58
|
+
rPrime = x;
|
|
59
|
+
gPrime = chroma;
|
|
60
|
+
} else if (huePrime < 3) {
|
|
61
|
+
gPrime = chroma;
|
|
62
|
+
bPrime = x;
|
|
63
|
+
} else if (huePrime < 4) {
|
|
64
|
+
gPrime = x;
|
|
65
|
+
bPrime = chroma;
|
|
66
|
+
} else if (huePrime < 5) {
|
|
67
|
+
rPrime = x;
|
|
68
|
+
bPrime = chroma;
|
|
69
|
+
} else {
|
|
70
|
+
rPrime = chroma;
|
|
71
|
+
bPrime = x;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
r: Math.round((rPrime + match) * 255),
|
|
75
|
+
g: Math.round((gPrime + match) * 255),
|
|
76
|
+
b: Math.round((bPrime + match) * 255)
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const formatOutputColor = (value)=>{
|
|
80
|
+
if (value.alpha >= 1) return value.hex;
|
|
81
|
+
const rgb = hsvToRgb(value.hsv.h, value.hsv.s, value.hsv.v);
|
|
82
|
+
const alpha = Number(value.alpha.toFixed(2));
|
|
83
|
+
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${alpha})`;
|
|
84
|
+
};
|
|
85
|
+
const toColorState = (value)=>{
|
|
86
|
+
if (!value) return null;
|
|
87
|
+
const parsed = (0, __WEBPACK_EXTERNAL_MODULE__colorpicker_ColorUtils_js_79ac07b0__.parseColor)(value);
|
|
88
|
+
if (!parsed) return null;
|
|
89
|
+
const hex = normalizeHex((0, __WEBPACK_EXTERNAL_MODULE__colorpicker_ColorUtils_js_79ac07b0__.formatColor)(parsed, "hex"));
|
|
90
|
+
const hsv = rgbToHsv(parsed.rgb.r, parsed.rgb.g, parsed.rgb.b);
|
|
91
|
+
const alpha = normalizeAlpha(parsed.rgb.a ?? 1);
|
|
92
|
+
return {
|
|
93
|
+
hex,
|
|
94
|
+
hsv,
|
|
95
|
+
alpha
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const fallbackState = ()=>{
|
|
99
|
+
const parsed = toColorState(DEFAULT_COLOR);
|
|
100
|
+
if (parsed) return parsed;
|
|
101
|
+
return {
|
|
102
|
+
hex: DEFAULT_COLOR,
|
|
103
|
+
hsv: {
|
|
104
|
+
h: 0,
|
|
105
|
+
s: 75,
|
|
106
|
+
v: 96
|
|
107
|
+
},
|
|
108
|
+
alpha: 1
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const ColorPickerArea = (props)=>{
|
|
112
|
+
const ctx = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.useContext)(ColorPickerContext);
|
|
113
|
+
const [local, others] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.splitProps)(props, [
|
|
114
|
+
"class",
|
|
115
|
+
"className",
|
|
116
|
+
"onChange",
|
|
117
|
+
"dataTheme"
|
|
118
|
+
]);
|
|
119
|
+
if (!ctx) return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(__WEBPACK_EXTERNAL_MODULE__color_area_index_js_f79642f5__["default"], (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
120
|
+
get ["class"] () {
|
|
121
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-picker__area", local.class, local.className);
|
|
122
|
+
},
|
|
123
|
+
get dataTheme () {
|
|
124
|
+
return local.dataTheme;
|
|
125
|
+
},
|
|
126
|
+
get onChange () {
|
|
127
|
+
return local.onChange;
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
const handleChange = (next)=>{
|
|
131
|
+
ctx.setFromArea(next);
|
|
132
|
+
local.onChange?.(next);
|
|
133
|
+
};
|
|
134
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(__WEBPACK_EXTERNAL_MODULE__color_area_index_js_f79642f5__["default"], (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
135
|
+
get value () {
|
|
136
|
+
return ctx.value().hsv;
|
|
137
|
+
},
|
|
138
|
+
get isDisabled () {
|
|
139
|
+
return ctx.isDisabled();
|
|
140
|
+
},
|
|
141
|
+
get ["class"] () {
|
|
142
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-picker__area", local.class, local.className);
|
|
143
|
+
},
|
|
144
|
+
get dataTheme () {
|
|
145
|
+
return local.dataTheme;
|
|
146
|
+
},
|
|
147
|
+
onChange: handleChange
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
const ColorPickerSlider = (props)=>{
|
|
151
|
+
const ctx = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.useContext)(ColorPickerContext);
|
|
152
|
+
const [local, others] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.splitProps)(props, [
|
|
153
|
+
"class",
|
|
154
|
+
"className",
|
|
155
|
+
"onChange",
|
|
156
|
+
"type",
|
|
157
|
+
"style",
|
|
158
|
+
"dataTheme"
|
|
159
|
+
]);
|
|
160
|
+
const sliderType = ()=>local.type ?? "hue";
|
|
161
|
+
if (!ctx) return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(__WEBPACK_EXTERNAL_MODULE__color_slider_index_js_89667266__["default"], (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
162
|
+
get type () {
|
|
163
|
+
return sliderType();
|
|
164
|
+
},
|
|
165
|
+
get ["class"] () {
|
|
166
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-picker__slider", local.class, local.className);
|
|
167
|
+
},
|
|
168
|
+
get dataTheme () {
|
|
169
|
+
return local.dataTheme;
|
|
170
|
+
},
|
|
171
|
+
get style () {
|
|
172
|
+
return local.style;
|
|
173
|
+
},
|
|
174
|
+
get onChange () {
|
|
175
|
+
return local.onChange;
|
|
176
|
+
}
|
|
177
|
+
}));
|
|
178
|
+
const value = ()=>"alpha" === sliderType() ? ctx.value().alpha : ctx.value().hsv.h;
|
|
179
|
+
const handleChange = (next)=>{
|
|
180
|
+
ctx.setFromSlider(sliderType(), next);
|
|
181
|
+
local.onChange?.(next);
|
|
182
|
+
};
|
|
183
|
+
const sliderStyle = ()=>{
|
|
184
|
+
const userStyle = local.style;
|
|
185
|
+
if ("alpha" !== sliderType()) return {
|
|
186
|
+
...userStyle
|
|
187
|
+
};
|
|
188
|
+
const rgb = hsvToRgb(ctx.value().hsv.h, ctx.value().hsv.s, ctx.value().hsv.v);
|
|
189
|
+
return {
|
|
190
|
+
"--color-slider-alpha-color": `rgb(${rgb.r} ${rgb.g} ${rgb.b})`,
|
|
191
|
+
...userStyle
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(__WEBPACK_EXTERNAL_MODULE__color_slider_index_js_89667266__["default"], (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
195
|
+
get type () {
|
|
196
|
+
return sliderType();
|
|
197
|
+
},
|
|
198
|
+
get value () {
|
|
199
|
+
return value();
|
|
200
|
+
},
|
|
201
|
+
get isDisabled () {
|
|
202
|
+
return ctx.isDisabled();
|
|
203
|
+
},
|
|
204
|
+
get ["class"] () {
|
|
205
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-picker__slider", local.class, local.className);
|
|
206
|
+
},
|
|
207
|
+
get dataTheme () {
|
|
208
|
+
return local.dataTheme;
|
|
209
|
+
},
|
|
210
|
+
get style () {
|
|
211
|
+
return sliderStyle();
|
|
212
|
+
},
|
|
213
|
+
onChange: handleChange
|
|
214
|
+
}));
|
|
215
|
+
};
|
|
216
|
+
const ColorPickerField = (props)=>{
|
|
217
|
+
const ctx = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.useContext)(ColorPickerContext);
|
|
218
|
+
const [local, others] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.splitProps)(props, [
|
|
219
|
+
"class",
|
|
220
|
+
"className",
|
|
221
|
+
"onChange",
|
|
222
|
+
"fullWidth",
|
|
223
|
+
"format",
|
|
224
|
+
"dataTheme"
|
|
225
|
+
]);
|
|
226
|
+
if (!ctx) return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(__WEBPACK_EXTERNAL_MODULE__color_field_index_js_d63b754b__["default"], (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
227
|
+
get ["class"] () {
|
|
228
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-picker__field", local.class, local.className);
|
|
229
|
+
},
|
|
230
|
+
get dataTheme () {
|
|
231
|
+
return local.dataTheme;
|
|
232
|
+
},
|
|
233
|
+
get format () {
|
|
234
|
+
return local.format;
|
|
235
|
+
},
|
|
236
|
+
get fullWidth () {
|
|
237
|
+
return local.fullWidth ?? true;
|
|
238
|
+
},
|
|
239
|
+
get onChange () {
|
|
240
|
+
return local.onChange;
|
|
241
|
+
}
|
|
242
|
+
}));
|
|
243
|
+
const handleChange = (next)=>{
|
|
244
|
+
ctx.setFromField(next);
|
|
245
|
+
local.onChange?.(next);
|
|
246
|
+
};
|
|
247
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(__WEBPACK_EXTERNAL_MODULE__color_field_index_js_d63b754b__["default"], (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
248
|
+
get value () {
|
|
249
|
+
return ctx.value().hex;
|
|
250
|
+
},
|
|
251
|
+
get isDisabled () {
|
|
252
|
+
return ctx.isDisabled();
|
|
253
|
+
},
|
|
254
|
+
get ["class"] () {
|
|
255
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-picker__field", local.class, local.className);
|
|
256
|
+
},
|
|
257
|
+
get dataTheme () {
|
|
258
|
+
return local.dataTheme;
|
|
259
|
+
},
|
|
260
|
+
get format () {
|
|
261
|
+
return local.format;
|
|
262
|
+
},
|
|
263
|
+
get fullWidth () {
|
|
264
|
+
return local.fullWidth ?? true;
|
|
265
|
+
},
|
|
266
|
+
onChange: handleChange
|
|
267
|
+
}));
|
|
268
|
+
};
|
|
269
|
+
const ColorPickerRoot = (props)=>{
|
|
270
|
+
const [local, others] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.splitProps)(props, [
|
|
271
|
+
"class",
|
|
272
|
+
"className",
|
|
273
|
+
"children",
|
|
274
|
+
"value",
|
|
275
|
+
"defaultValue",
|
|
276
|
+
"onChange",
|
|
277
|
+
"isDisabled",
|
|
278
|
+
"dataTheme"
|
|
279
|
+
]);
|
|
280
|
+
const [internalState, setInternalState] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createSignal)(toColorState(local.value ?? local.defaultValue) ?? fallbackState());
|
|
281
|
+
const isControlled = ()=>void 0 !== local.value;
|
|
282
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createEffect)(()=>{
|
|
283
|
+
if (!isControlled()) return;
|
|
284
|
+
const next = toColorState(local.value);
|
|
285
|
+
if (next) setInternalState(next);
|
|
286
|
+
});
|
|
287
|
+
const currentState = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>{
|
|
288
|
+
if (!isControlled()) return internalState();
|
|
289
|
+
return toColorState(local.value) ?? internalState();
|
|
290
|
+
});
|
|
291
|
+
const emitChange = (next)=>{
|
|
292
|
+
if (!isControlled()) setInternalState(next);
|
|
293
|
+
local.onChange?.(formatOutputColor(next));
|
|
294
|
+
};
|
|
295
|
+
const setFromArea = (nextValue)=>{
|
|
296
|
+
const hsv = normalizeHsv(nextValue);
|
|
297
|
+
const rgb = hsvToRgb(hsv.h, hsv.s, hsv.v);
|
|
298
|
+
const hex = normalizeHex((0, __WEBPACK_EXTERNAL_MODULE__colorpicker_ColorUtils_js_79ac07b0__.rgbToHex)(rgb.r, rgb.g, rgb.b));
|
|
299
|
+
emitChange({
|
|
300
|
+
hex,
|
|
301
|
+
hsv,
|
|
302
|
+
alpha: currentState().alpha
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
const setFromSlider = (type, value)=>{
|
|
306
|
+
if ("alpha" === type) return void emitChange({
|
|
307
|
+
...currentState(),
|
|
308
|
+
alpha: normalizeAlpha(value)
|
|
309
|
+
});
|
|
310
|
+
const hsv = normalizeHsv({
|
|
311
|
+
...currentState().hsv,
|
|
312
|
+
h: value
|
|
313
|
+
});
|
|
314
|
+
const rgb = hsvToRgb(hsv.h, hsv.s, hsv.v);
|
|
315
|
+
const hex = normalizeHex((0, __WEBPACK_EXTERNAL_MODULE__colorpicker_ColorUtils_js_79ac07b0__.rgbToHex)(rgb.r, rgb.g, rgb.b));
|
|
316
|
+
emitChange({
|
|
317
|
+
hex,
|
|
318
|
+
hsv,
|
|
319
|
+
alpha: currentState().alpha
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
const setFromField = (nextValue)=>{
|
|
323
|
+
const next = toColorState(nextValue);
|
|
324
|
+
if (!next) return;
|
|
325
|
+
emitChange(next);
|
|
326
|
+
};
|
|
327
|
+
const context = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>({
|
|
328
|
+
value: currentState,
|
|
329
|
+
isDisabled: ()=>Boolean(local.isDisabled),
|
|
330
|
+
setFromArea,
|
|
331
|
+
setFromField,
|
|
332
|
+
setFromSlider
|
|
333
|
+
}));
|
|
334
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(ColorPickerContext.Provider, {
|
|
335
|
+
get value () {
|
|
336
|
+
return context();
|
|
337
|
+
},
|
|
338
|
+
get children () {
|
|
339
|
+
var _el$ = _tmpl$();
|
|
340
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.spread)(_el$, (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
341
|
+
get ["class"] () {
|
|
342
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-picker", local.class, local.className);
|
|
343
|
+
},
|
|
344
|
+
get ["data-theme"] () {
|
|
345
|
+
return local.dataTheme;
|
|
346
|
+
},
|
|
347
|
+
"data-slot": "color-picker",
|
|
348
|
+
get ["data-disabled"] () {
|
|
349
|
+
return local.isDisabled ? "true" : "false";
|
|
350
|
+
}
|
|
351
|
+
}), false, true);
|
|
352
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.insert)(_el$, ()=>local.children ?? [
|
|
353
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(ColorPickerArea, {}),
|
|
354
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(ColorPickerSlider, {
|
|
355
|
+
type: "hue"
|
|
356
|
+
}),
|
|
357
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.createComponent)(ColorPickerField, {})
|
|
358
|
+
]);
|
|
359
|
+
return _el$;
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
const ColorPicker = Object.assign(ColorPickerRoot, {
|
|
364
|
+
Root: ColorPickerRoot,
|
|
365
|
+
Area: ColorPickerArea,
|
|
366
|
+
Slider: ColorPickerSlider,
|
|
367
|
+
Field: ColorPickerField
|
|
368
|
+
});
|
|
369
|
+
export { ColorPicker, ColorPickerArea, ColorPickerField, ColorPickerRoot, ColorPickerSlider, ColorPicker as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__ColorPicker_js_c381c0c3__ from "./ColorPicker.js";
|
|
2
|
+
var __webpack_exports__ColorPicker = __WEBPACK_EXTERNAL_MODULE__ColorPicker_js_c381c0c3__.ColorPicker;
|
|
3
|
+
var __webpack_exports__ColorPickerArea = __WEBPACK_EXTERNAL_MODULE__ColorPicker_js_c381c0c3__.ColorPickerArea;
|
|
4
|
+
var __webpack_exports__ColorPickerField = __WEBPACK_EXTERNAL_MODULE__ColorPicker_js_c381c0c3__.ColorPickerField;
|
|
5
|
+
var __webpack_exports__ColorPickerRoot = __WEBPACK_EXTERNAL_MODULE__ColorPicker_js_c381c0c3__.ColorPickerRoot;
|
|
6
|
+
var __webpack_exports__ColorPickerSlider = __WEBPACK_EXTERNAL_MODULE__ColorPicker_js_c381c0c3__.ColorPickerSlider;
|
|
7
|
+
var __webpack_exports__default = __WEBPACK_EXTERNAL_MODULE__ColorPicker_js_c381c0c3__["default"];
|
|
8
|
+
export { __webpack_exports__ColorPicker as ColorPicker, __webpack_exports__ColorPickerArea as ColorPickerArea, __webpack_exports__ColorPickerField as ColorPickerField, __webpack_exports__ColorPickerRoot as ColorPickerRoot, __webpack_exports__ColorPickerSlider as ColorPickerSlider, __webpack_exports__default as default };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
@layer components {
|
|
2
|
+
.color-slider {
|
|
3
|
+
position: relative;
|
|
4
|
+
width: 100%;
|
|
5
|
+
min-width: 10rem;
|
|
6
|
+
height: 1.25rem;
|
|
7
|
+
border-radius: 9999px;
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
outline: none;
|
|
10
|
+
user-select: none;
|
|
11
|
+
-webkit-tap-highlight-color: transparent;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.color-slider[data-disabled="true"] {
|
|
15
|
+
cursor: not-allowed;
|
|
16
|
+
opacity: 0.55;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.color-slider__track {
|
|
20
|
+
position: absolute;
|
|
21
|
+
inset: 0;
|
|
22
|
+
border-radius: inherit;
|
|
23
|
+
background: var(--color-slider-track-background);
|
|
24
|
+
box-shadow: inset 0 0 0 1px oklch(0% 0 0 / 0.12);
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.color-slider__thumb {
|
|
29
|
+
position: absolute;
|
|
30
|
+
top: 50%;
|
|
31
|
+
width: 1rem;
|
|
32
|
+
height: 1rem;
|
|
33
|
+
border-radius: 9999px;
|
|
34
|
+
border: 2px solid #ffffff;
|
|
35
|
+
box-shadow:
|
|
36
|
+
0 1px 2px oklch(0% 0 0 / 0.24),
|
|
37
|
+
0 0 0 1px oklch(0% 0 0 / 0.18);
|
|
38
|
+
transform: translate(-50%, -50%);
|
|
39
|
+
transition:
|
|
40
|
+
width 140ms ease,
|
|
41
|
+
height 140ms ease,
|
|
42
|
+
box-shadow 140ms ease;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
z-index: 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.color-slider--dragging .color-slider__thumb,
|
|
48
|
+
.color-slider__thumb[data-dragging="true"] {
|
|
49
|
+
width: 1.125rem;
|
|
50
|
+
height: 1.125rem;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.color-slider:focus-visible,
|
|
54
|
+
.color-slider[data-focus-visible="true"] {
|
|
55
|
+
box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-accent) 22%, transparent);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./ColorSlider.css";
|
|
2
|
+
import { type Component, type JSX } from "solid-js";
|
|
3
|
+
import type { IComponentBaseProps } from "../types";
|
|
4
|
+
export type ColorSliderType = "hue" | "alpha";
|
|
5
|
+
export type ColorSliderProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> & IComponentBaseProps & {
|
|
6
|
+
value?: number;
|
|
7
|
+
defaultValue?: number;
|
|
8
|
+
onChange?: (value: number) => void;
|
|
9
|
+
type?: ColorSliderType;
|
|
10
|
+
isDisabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare const ColorSlider: Component<ColorSliderProps>;
|
|
13
|
+
export default ColorSlider;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__ from "solid-js/web";
|
|
2
|
+
import "./ColorSlider.css";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__ from "solid-js";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__ from "tailwind-merge";
|
|
5
|
+
var _tmpl$ = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.template)("<div><div class=color-slider__track data-slot=color-slider-track></div><div class=color-slider__thumb data-slot=color-slider-thumb>");
|
|
6
|
+
const clamp = (value, min, max)=>Math.min(max, Math.max(min, value));
|
|
7
|
+
const normalizeValue = (type, value)=>{
|
|
8
|
+
if ("alpha" === type) return clamp(value, 0, 1);
|
|
9
|
+
return clamp(value, 0, 360);
|
|
10
|
+
};
|
|
11
|
+
const toPercent = (type, value)=>{
|
|
12
|
+
if ("alpha" === type) return 100 * clamp(value, 0, 1);
|
|
13
|
+
return clamp(value, 0, 360) / 360 * 100;
|
|
14
|
+
};
|
|
15
|
+
const fromPercent = (type, percent)=>{
|
|
16
|
+
const clamped = clamp(percent, 0, 100);
|
|
17
|
+
if ("alpha" === type) return clamped / 100;
|
|
18
|
+
return clamped / 100 * 360;
|
|
19
|
+
};
|
|
20
|
+
const ColorSlider = (props)=>{
|
|
21
|
+
const [local, others] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.splitProps)(props, [
|
|
22
|
+
"class",
|
|
23
|
+
"className",
|
|
24
|
+
"value",
|
|
25
|
+
"defaultValue",
|
|
26
|
+
"onChange",
|
|
27
|
+
"type",
|
|
28
|
+
"isDisabled",
|
|
29
|
+
"style",
|
|
30
|
+
"dataTheme",
|
|
31
|
+
"aria-label"
|
|
32
|
+
]);
|
|
33
|
+
const sliderType = ()=>local.type ?? "hue";
|
|
34
|
+
const isDisabled = ()=>Boolean(local.isDisabled);
|
|
35
|
+
const initialValue = ()=>{
|
|
36
|
+
const fallback = "alpha" === sliderType() ? 1 : 0;
|
|
37
|
+
return normalizeValue(sliderType(), local.value ?? local.defaultValue ?? fallback);
|
|
38
|
+
};
|
|
39
|
+
const [internalValue, setInternalValue] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createSignal)(initialValue());
|
|
40
|
+
const [isDragging, setIsDragging] = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createSignal)(false);
|
|
41
|
+
let sliderRef;
|
|
42
|
+
const isControlled = ()=>void 0 !== local.value;
|
|
43
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createEffect)(()=>{
|
|
44
|
+
const nextType = sliderType();
|
|
45
|
+
const nextValue = local.value;
|
|
46
|
+
if (void 0 === nextValue) {
|
|
47
|
+
if (!isControlled()) setInternalValue((current)=>normalizeValue(nextType, current));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setInternalValue(normalizeValue(nextType, nextValue));
|
|
51
|
+
});
|
|
52
|
+
const currentValue = (0, __WEBPACK_EXTERNAL_MODULE_solid_js_aeefcc6d__.createMemo)(()=>{
|
|
53
|
+
if (isControlled()) return normalizeValue(sliderType(), local.value ?? internalValue());
|
|
54
|
+
return normalizeValue(sliderType(), internalValue());
|
|
55
|
+
});
|
|
56
|
+
const emitChange = (next)=>{
|
|
57
|
+
const normalized = normalizeValue(sliderType(), next);
|
|
58
|
+
if (!isControlled()) setInternalValue(normalized);
|
|
59
|
+
local.onChange?.(normalized);
|
|
60
|
+
};
|
|
61
|
+
const updateFromPointer = (clientX)=>{
|
|
62
|
+
if (!sliderRef || isDisabled()) return;
|
|
63
|
+
const rect = sliderRef.getBoundingClientRect();
|
|
64
|
+
if (rect.width <= 0) return;
|
|
65
|
+
const percent = (clientX - rect.left) / rect.width * 100;
|
|
66
|
+
emitChange(fromPercent(sliderType(), percent));
|
|
67
|
+
};
|
|
68
|
+
const handlePointerDown = (event)=>{
|
|
69
|
+
if (isDisabled()) return;
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
72
|
+
setIsDragging(true);
|
|
73
|
+
updateFromPointer(event.clientX);
|
|
74
|
+
};
|
|
75
|
+
const handlePointerMove = (event)=>{
|
|
76
|
+
if (!isDragging()) return;
|
|
77
|
+
updateFromPointer(event.clientX);
|
|
78
|
+
};
|
|
79
|
+
const handlePointerUp = (event)=>{
|
|
80
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
|
|
81
|
+
setIsDragging(false);
|
|
82
|
+
};
|
|
83
|
+
const handleLostPointerCapture = ()=>{
|
|
84
|
+
setIsDragging(false);
|
|
85
|
+
};
|
|
86
|
+
const handleKeyDown = (event)=>{
|
|
87
|
+
if (isDisabled()) return;
|
|
88
|
+
const key = event.key;
|
|
89
|
+
const isDecrease = "ArrowLeft" === key || "ArrowDown" === key;
|
|
90
|
+
const isIncrease = "ArrowRight" === key || "ArrowUp" === key;
|
|
91
|
+
if (!isDecrease && !isIncrease) return;
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
const step = "alpha" === sliderType() ? event.shiftKey ? 0.1 : 0.01 : event.shiftKey ? 10 : 1;
|
|
94
|
+
const direction = isIncrease ? 1 : -1;
|
|
95
|
+
emitChange(currentValue() + direction * step);
|
|
96
|
+
};
|
|
97
|
+
const percent = ()=>toPercent(sliderType(), currentValue());
|
|
98
|
+
const sliderStyle = ()=>{
|
|
99
|
+
const userStyle = local.style;
|
|
100
|
+
if ("hue" === sliderType()) return {
|
|
101
|
+
"--color-slider-track-background": "linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%)",
|
|
102
|
+
"--color-slider-thumb-color": `hsl(${currentValue()} 100% 50%)`,
|
|
103
|
+
...userStyle
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
"--color-slider-track-background": "linear-gradient(to right, transparent, var(--color-slider-alpha-color, #000000)), repeating-conic-gradient(#cfd3da 0% 25%, #f3f4f6 0% 50%) 50% / 0.5rem 0.5rem",
|
|
107
|
+
"--color-slider-thumb-color": "var(--color-slider-alpha-color, #000000)",
|
|
108
|
+
...userStyle
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const valueText = ()=>{
|
|
112
|
+
if ("alpha" === sliderType()) return `Opacity ${Math.round(100 * currentValue())}%`;
|
|
113
|
+
return `Hue ${Math.round(currentValue())} degrees`;
|
|
114
|
+
};
|
|
115
|
+
return (()=>{
|
|
116
|
+
var _el$ = _tmpl$(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling;
|
|
117
|
+
var _ref$ = sliderRef;
|
|
118
|
+
"function" == typeof _ref$ ? (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.use)(_ref$, _el$) : sliderRef = _el$;
|
|
119
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.spread)(_el$, (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.mergeProps)(others, {
|
|
120
|
+
get ["class"] () {
|
|
121
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_tailwind_merge_e05e3e95__.twMerge)("color-slider", "alpha" === sliderType() && "color-slider--alpha", isDragging() && "color-slider--dragging", local.class, local.className);
|
|
122
|
+
},
|
|
123
|
+
get ["data-theme"] () {
|
|
124
|
+
return local.dataTheme;
|
|
125
|
+
},
|
|
126
|
+
"data-slot": "color-slider",
|
|
127
|
+
get ["data-type"] () {
|
|
128
|
+
return sliderType();
|
|
129
|
+
},
|
|
130
|
+
get ["data-disabled"] () {
|
|
131
|
+
return isDisabled() ? "true" : "false";
|
|
132
|
+
},
|
|
133
|
+
role: "slider",
|
|
134
|
+
get tabIndex () {
|
|
135
|
+
return isDisabled() ? -1 : 0;
|
|
136
|
+
},
|
|
137
|
+
get ["aria-label"] () {
|
|
138
|
+
return local["aria-label"] ?? ("alpha" === sliderType() ? "Alpha" : "Hue");
|
|
139
|
+
},
|
|
140
|
+
get ["aria-valuemin"] () {
|
|
141
|
+
return "alpha" === sliderType() ? 0 : 0;
|
|
142
|
+
},
|
|
143
|
+
get ["aria-valuemax"] () {
|
|
144
|
+
return "alpha" === sliderType() ? 1 : 360;
|
|
145
|
+
},
|
|
146
|
+
get ["aria-valuenow"] () {
|
|
147
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.memo)(()=>"alpha" === sliderType())() ? Number(currentValue().toFixed(2)) : Math.round(currentValue());
|
|
148
|
+
},
|
|
149
|
+
get ["aria-valuetext"] () {
|
|
150
|
+
return valueText();
|
|
151
|
+
},
|
|
152
|
+
get ["aria-disabled"] () {
|
|
153
|
+
return isDisabled() ? "true" : "false";
|
|
154
|
+
},
|
|
155
|
+
get style () {
|
|
156
|
+
return sliderStyle();
|
|
157
|
+
},
|
|
158
|
+
onPointerDown: handlePointerDown,
|
|
159
|
+
onPointerMove: handlePointerMove,
|
|
160
|
+
onPointerUp: handlePointerUp,
|
|
161
|
+
onLostPointerCapture: handleLostPointerCapture,
|
|
162
|
+
onKeyDown: handleKeyDown
|
|
163
|
+
}), false, true);
|
|
164
|
+
_el$3.style.setProperty("background-color", "var(--color-slider-thumb-color)");
|
|
165
|
+
(0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.effect)((_p$)=>{
|
|
166
|
+
var _v$ = isDragging() ? "true" : "false", _v$2 = `${percent()}%`;
|
|
167
|
+
_v$ !== _p$.e && (0, __WEBPACK_EXTERNAL_MODULE_solid_js_web_35d951b7__.setAttribute)(_el$3, "data-dragging", _p$.e = _v$);
|
|
168
|
+
_v$2 !== _p$.t && (null != (_p$.t = _v$2) ? _el$3.style.setProperty("left", _v$2) : _el$3.style.removeProperty("left"));
|
|
169
|
+
return _p$;
|
|
170
|
+
}, {
|
|
171
|
+
e: void 0,
|
|
172
|
+
t: void 0
|
|
173
|
+
});
|
|
174
|
+
return _el$;
|
|
175
|
+
})();
|
|
176
|
+
};
|
|
177
|
+
const color_slider_ColorSlider = ColorSlider;
|
|
178
|
+
export { color_slider_ColorSlider as default };
|