@mekari/pixel3-color-picker 0.0.1-dev.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/chunk-36OXI4E3.mjs +347 -0
- package/dist/chunk-5FWKSVUW.mjs +89 -0
- package/dist/chunk-AEUPCATZ.mjs +156 -0
- package/dist/chunk-DVRBDVR4.mjs +63 -0
- package/dist/chunk-L5BRB7ES.mjs +64 -0
- package/dist/chunk-PULVLME3.mjs +196 -0
- package/dist/chunk-QZ7VFGWC.mjs +6 -0
- package/dist/chunk-YLUI3RMF.mjs +116 -0
- package/dist/color-picker.d.mts +129 -0
- package/dist/color-picker.d.ts +129 -0
- package/dist/color-picker.js +1006 -0
- package/dist/color-picker.mjs +13 -0
- package/dist/hue.d.mts +27 -0
- package/dist/hue.d.ts +27 -0
- package/dist/hue.js +217 -0
- package/dist/hue.mjs +7 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1008 -0
- package/dist/index.mjs +13 -0
- package/dist/input.d.mts +41 -0
- package/dist/input.d.ts +41 -0
- package/dist/input.js +110 -0
- package/dist/input.mjs +7 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/modules/color-picker.hooks.d.mts +206 -0
- package/dist/modules/color-picker.hooks.d.ts +206 -0
- package/dist/modules/color-picker.hooks.js +378 -0
- package/dist/modules/color-picker.hooks.mjs +7 -0
- package/dist/modules/color-picker.props.d.mts +62 -0
- package/dist/modules/color-picker.props.d.ts +62 -0
- package/dist/modules/color-picker.props.js +89 -0
- package/dist/modules/color-picker.props.mjs +9 -0
- package/dist/preset.d.mts +26 -0
- package/dist/preset.d.ts +26 -0
- package/dist/preset.js +94 -0
- package/dist/preset.mjs +7 -0
- package/dist/saturation.d.mts +16 -0
- package/dist/saturation.d.ts +16 -0
- package/dist/saturation.js +187 -0
- package/dist/saturation.mjs +7 -0
- package/package.json +53 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-QZ7VFGWC.mjs";
|
|
4
|
+
|
|
5
|
+
// src/modules/color-picker.hooks.ts
|
|
6
|
+
import { computed, watch, ref, toRefs, onMounted } from "vue";
|
|
7
|
+
import tinycolor from "tinycolor2";
|
|
8
|
+
import { getUniqueId } from "@mekari/pixel3-utils";
|
|
9
|
+
import { colorPickerSlotRecipe } from "@mekari/pixel3-styled-system/recipes";
|
|
10
|
+
import { css, cx } from "@mekari/pixel3-styled-system/css";
|
|
11
|
+
import { token } from "@mekari/pixel3-styled-system/tokens";
|
|
12
|
+
function useColorPicker(props, emit) {
|
|
13
|
+
const {
|
|
14
|
+
id,
|
|
15
|
+
value,
|
|
16
|
+
placeholder,
|
|
17
|
+
variant,
|
|
18
|
+
placement,
|
|
19
|
+
isShowPopover,
|
|
20
|
+
isInvalid
|
|
21
|
+
} = toRefs(props);
|
|
22
|
+
const val = ref(_colorChange(value.value));
|
|
23
|
+
const colorInput = ref("");
|
|
24
|
+
const isPopoverOpen = ref(false);
|
|
25
|
+
const getId = id.value || getUniqueId("", "color-picker").value;
|
|
26
|
+
const colors = computed({
|
|
27
|
+
get() {
|
|
28
|
+
return val.value;
|
|
29
|
+
},
|
|
30
|
+
set(newVal) {
|
|
31
|
+
val.value = newVal;
|
|
32
|
+
emit("change", newVal);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const hex = computed(() => {
|
|
36
|
+
const hex2 = colors.value.hex;
|
|
37
|
+
return hex2.replace("#", "");
|
|
38
|
+
});
|
|
39
|
+
const borderColor = computed(() => {
|
|
40
|
+
if (isInvalid.value) {
|
|
41
|
+
return "red.400";
|
|
42
|
+
}
|
|
43
|
+
if (!isInvalid.value && isFocused.value) {
|
|
44
|
+
return "blue.400";
|
|
45
|
+
}
|
|
46
|
+
return "gray.100";
|
|
47
|
+
});
|
|
48
|
+
const isFocused = computed(() => {
|
|
49
|
+
return isPopoverOpen.value;
|
|
50
|
+
});
|
|
51
|
+
const rootAttrs = computed(() => {
|
|
52
|
+
return {
|
|
53
|
+
"data-pixel-component": "MpColorPicker",
|
|
54
|
+
id: getId,
|
|
55
|
+
class: colorPickerSlotRecipe().root,
|
|
56
|
+
style: {
|
|
57
|
+
width: variant.value === "advance" ? "280px" : "72px"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
const popoverAttrs = computed(() => {
|
|
62
|
+
return {
|
|
63
|
+
id: `popover-${getId}`,
|
|
64
|
+
placement: placement.value,
|
|
65
|
+
defaultIsOpen: isShowPopover.value,
|
|
66
|
+
initialFocusRef: `#input-${getId}`,
|
|
67
|
+
onOpen: handleOpenPopover,
|
|
68
|
+
onClose: handleClosePopover
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
const popoverTriggerAttrs = computed(() => {
|
|
72
|
+
return {
|
|
73
|
+
tabindex: "0",
|
|
74
|
+
class: cx(css({
|
|
75
|
+
boxShadow: isPopoverOpen.value && !isInvalid.value ? "outline" : "none",
|
|
76
|
+
_hover: {
|
|
77
|
+
borderColor: isPopoverOpen.value && !isInvalid.value ? "blue.500 !important" : "gray.400 !important"
|
|
78
|
+
}
|
|
79
|
+
}), colorPickerSlotRecipe().popoverTrigger),
|
|
80
|
+
style: {
|
|
81
|
+
borderColor: token(`colors.${borderColor.value}`)
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const boxColorAttrs = computed(() => {
|
|
86
|
+
return {
|
|
87
|
+
class: colorPickerSlotRecipe().boxColor,
|
|
88
|
+
style: {
|
|
89
|
+
background: colors.value.hex
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
const inputTriggerAttrs = computed(() => {
|
|
94
|
+
return {
|
|
95
|
+
id: `input-${getId}`,
|
|
96
|
+
type: "text",
|
|
97
|
+
autocomplete: "off",
|
|
98
|
+
variant: "unstyled",
|
|
99
|
+
maxlength: "6",
|
|
100
|
+
value: colorInput.value,
|
|
101
|
+
placeholder: placeholder.value,
|
|
102
|
+
class: colorPickerSlotRecipe().inputTrigger,
|
|
103
|
+
onInput: handleInputTrigger
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
const iconDropDownAttrs = computed(() => {
|
|
107
|
+
return {
|
|
108
|
+
name: "chevrons-down",
|
|
109
|
+
size: "sm",
|
|
110
|
+
class: colorPickerSlotRecipe().iconDropdown
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
const popoverContentAttrs = computed(() => {
|
|
114
|
+
return {
|
|
115
|
+
class: colorPickerSlotRecipe().popoverContent,
|
|
116
|
+
style: {
|
|
117
|
+
width: variant.value === "advance" ? "280px" : "188px"
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
const wrapperAdvanceAttrs = computed(() => {
|
|
122
|
+
return {
|
|
123
|
+
class: colorPickerSlotRecipe().wrapperAdvance
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
const wrapperBasicAttrs = computed(() => {
|
|
127
|
+
return {
|
|
128
|
+
class: colorPickerSlotRecipe().wrapperBasic
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
const wrapperSaturationAttrs = computed(() => {
|
|
132
|
+
return {
|
|
133
|
+
class: colorPickerSlotRecipe().wrapperSaturation
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
const saturationAttrs = computed(() => {
|
|
137
|
+
return {
|
|
138
|
+
value: colors.value,
|
|
139
|
+
onChange: childChange
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
const wrapperHueAttrs = computed(() => {
|
|
143
|
+
return {
|
|
144
|
+
class: colorPickerSlotRecipe().wrapperHue
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
const hueAttrs = computed(() => {
|
|
148
|
+
return {
|
|
149
|
+
value: colors.value,
|
|
150
|
+
onChange: childChange
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
const wrapperInputAttrs = computed(() => {
|
|
154
|
+
return {
|
|
155
|
+
class: colorPickerSlotRecipe().wrapperInput
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
const inputHexAttrs = computed(() => {
|
|
159
|
+
return {
|
|
160
|
+
label: "hex",
|
|
161
|
+
width: "88px",
|
|
162
|
+
value: hex.value,
|
|
163
|
+
onChange: inputChange
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
const inputFullAttrs = computed(() => {
|
|
167
|
+
return {
|
|
168
|
+
label: "hex",
|
|
169
|
+
width: "full",
|
|
170
|
+
value: hex.value,
|
|
171
|
+
onChange: inputChange
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const inputRedAttrs = computed(() => {
|
|
175
|
+
return {
|
|
176
|
+
label: "r",
|
|
177
|
+
width: "48px",
|
|
178
|
+
value: colors.value.rgba.r,
|
|
179
|
+
onChange: inputChange
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
const inputGreenAttrs = computed(() => {
|
|
183
|
+
return {
|
|
184
|
+
label: "g",
|
|
185
|
+
width: "48px",
|
|
186
|
+
value: colors.value.rgba.g,
|
|
187
|
+
onChange: inputChange
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
const inputBlueAttrs = computed(() => {
|
|
191
|
+
return {
|
|
192
|
+
label: "b",
|
|
193
|
+
width: "48px",
|
|
194
|
+
value: colors.value.rgba.b,
|
|
195
|
+
onChange: inputChange
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
const boxPresetAttrs = computed(() => {
|
|
199
|
+
return {
|
|
200
|
+
class: colorPickerSlotRecipe().boxPreset
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
const wrapperPresetAttrs = computed(() => {
|
|
204
|
+
return {
|
|
205
|
+
class: colorPickerSlotRecipe().wrapperPreset
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
const wrapperBasicPresetAttrs = computed(() => {
|
|
209
|
+
return {
|
|
210
|
+
class: colorPickerSlotRecipe().wrapperBasicPreset
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
const presetBoxAttrs = /* @__PURE__ */ __name((item) => {
|
|
214
|
+
return {
|
|
215
|
+
value: item,
|
|
216
|
+
isActive: item.toLowerCase() === colors.value.hex.toLowerCase(),
|
|
217
|
+
onClick: childChange
|
|
218
|
+
};
|
|
219
|
+
}, "presetBoxAttrs");
|
|
220
|
+
function isValidHex(hex2) {
|
|
221
|
+
return tinycolor(hex2).isValid();
|
|
222
|
+
}
|
|
223
|
+
__name(isValidHex, "isValidHex");
|
|
224
|
+
function childChange(data) {
|
|
225
|
+
colorChange(data);
|
|
226
|
+
}
|
|
227
|
+
__name(childChange, "childChange");
|
|
228
|
+
function colorChange(data, oldHue) {
|
|
229
|
+
colors.value = _colorChange(data, oldHue);
|
|
230
|
+
}
|
|
231
|
+
__name(colorChange, "colorChange");
|
|
232
|
+
function _colorChange(data, oldHue) {
|
|
233
|
+
let color;
|
|
234
|
+
if (data && data.hsl) {
|
|
235
|
+
color = tinycolor(data.hsl);
|
|
236
|
+
} else if (data && data.hex && data.hex.length > 0) {
|
|
237
|
+
color = tinycolor(data.hex);
|
|
238
|
+
} else if (data && data.hsv) {
|
|
239
|
+
color = tinycolor(data.hsv);
|
|
240
|
+
} else if (data && data.rgba) {
|
|
241
|
+
color = tinycolor(data.rgba);
|
|
242
|
+
} else if (data && data.rgb) {
|
|
243
|
+
color = tinycolor(data.rgb);
|
|
244
|
+
} else {
|
|
245
|
+
color = tinycolor(data);
|
|
246
|
+
}
|
|
247
|
+
const hsl = color.toHsl();
|
|
248
|
+
const hsv = color.toHsv();
|
|
249
|
+
if (hsl.s === 0) {
|
|
250
|
+
hsv.h = hsl.h = data.h || data.hsl && data.hsl.h || oldHue || 0;
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
hsl,
|
|
254
|
+
hex: color.toHexString().toUpperCase(),
|
|
255
|
+
hex8: color.toHex8String().toUpperCase(),
|
|
256
|
+
rgba: color.toRgb(),
|
|
257
|
+
hsv,
|
|
258
|
+
oldHue: data.h || oldHue || hsl.h,
|
|
259
|
+
source: data.source
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
__name(_colorChange, "_colorChange");
|
|
263
|
+
function inputChange(data) {
|
|
264
|
+
if (!data) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (data.hex) {
|
|
268
|
+
isValidHex(data.hex) && colorChange({
|
|
269
|
+
hex: data.hex,
|
|
270
|
+
source: "hex"
|
|
271
|
+
});
|
|
272
|
+
} else if (data.r || data.g || data.b || data.a) {
|
|
273
|
+
colorChange({
|
|
274
|
+
r: data.r || colors.value.rgba.r,
|
|
275
|
+
g: data.g || colors.value.rgba.g,
|
|
276
|
+
b: data.b || colors.value.rgba.b,
|
|
277
|
+
a: data.a || colors.value.rgba.a,
|
|
278
|
+
source: "rgba"
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
__name(inputChange, "inputChange");
|
|
283
|
+
function handleInputTrigger(e) {
|
|
284
|
+
const target = e.target;
|
|
285
|
+
const value2 = target.value;
|
|
286
|
+
const data = {
|
|
287
|
+
hex: "",
|
|
288
|
+
"#": ""
|
|
289
|
+
};
|
|
290
|
+
data["hex"] = value2;
|
|
291
|
+
if (data.hex === void 0 && data["#"] === void 0) {
|
|
292
|
+
inputChange(data);
|
|
293
|
+
} else if (value2.length > 5) {
|
|
294
|
+
inputChange(data);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
__name(handleInputTrigger, "handleInputTrigger");
|
|
298
|
+
function handleOpenPopover() {
|
|
299
|
+
isPopoverOpen.value = true;
|
|
300
|
+
colorInput.value = hex.value;
|
|
301
|
+
}
|
|
302
|
+
__name(handleOpenPopover, "handleOpenPopover");
|
|
303
|
+
function handleClosePopover() {
|
|
304
|
+
isPopoverOpen.value = false;
|
|
305
|
+
colorInput.value = hex.value;
|
|
306
|
+
}
|
|
307
|
+
__name(handleClosePopover, "handleClosePopover");
|
|
308
|
+
watch(() => value.value, (newValue, oldValue) => {
|
|
309
|
+
if (newValue !== oldValue) {
|
|
310
|
+
val.value = _colorChange(newValue);
|
|
311
|
+
colorInput.value = hex.value;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
onMounted(() => {
|
|
315
|
+
colorInput.value = hex.value;
|
|
316
|
+
});
|
|
317
|
+
return {
|
|
318
|
+
rootAttrs,
|
|
319
|
+
popoverAttrs,
|
|
320
|
+
popoverTriggerAttrs,
|
|
321
|
+
boxColorAttrs,
|
|
322
|
+
inputTriggerAttrs,
|
|
323
|
+
iconDropDownAttrs,
|
|
324
|
+
popoverContentAttrs,
|
|
325
|
+
wrapperAdvanceAttrs,
|
|
326
|
+
wrapperBasicAttrs,
|
|
327
|
+
wrapperSaturationAttrs,
|
|
328
|
+
saturationAttrs,
|
|
329
|
+
wrapperHueAttrs,
|
|
330
|
+
hueAttrs,
|
|
331
|
+
wrapperInputAttrs,
|
|
332
|
+
inputHexAttrs,
|
|
333
|
+
inputRedAttrs,
|
|
334
|
+
inputGreenAttrs,
|
|
335
|
+
inputBlueAttrs,
|
|
336
|
+
inputFullAttrs,
|
|
337
|
+
boxPresetAttrs,
|
|
338
|
+
wrapperPresetAttrs,
|
|
339
|
+
wrapperBasicPresetAttrs,
|
|
340
|
+
presetBoxAttrs
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
__name(useColorPicker, "useColorPicker");
|
|
344
|
+
|
|
345
|
+
export {
|
|
346
|
+
useColorPicker
|
|
347
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-QZ7VFGWC.mjs";
|
|
4
|
+
|
|
5
|
+
// src/input.tsx
|
|
6
|
+
import { createVNode as _createVNode } from "vue";
|
|
7
|
+
import { defineComponent, computed } from "vue";
|
|
8
|
+
import { MpText } from "@mekari/pixel3-text";
|
|
9
|
+
import { MpInput } from "@mekari/pixel3-input";
|
|
10
|
+
import { css } from "@mekari/pixel3-styled-system/css";
|
|
11
|
+
var MpColorInput = defineComponent({
|
|
12
|
+
name: "MpColorInput",
|
|
13
|
+
props: {
|
|
14
|
+
value: {
|
|
15
|
+
type: [String, Number],
|
|
16
|
+
default: ""
|
|
17
|
+
},
|
|
18
|
+
label: {
|
|
19
|
+
type: String,
|
|
20
|
+
default: "hex"
|
|
21
|
+
},
|
|
22
|
+
width: {
|
|
23
|
+
type: String
|
|
24
|
+
},
|
|
25
|
+
max: {
|
|
26
|
+
type: Number
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
emits: ["change"],
|
|
30
|
+
setup(props, {
|
|
31
|
+
emit
|
|
32
|
+
}) {
|
|
33
|
+
const val = computed({
|
|
34
|
+
get() {
|
|
35
|
+
return props.value;
|
|
36
|
+
},
|
|
37
|
+
set(v) {
|
|
38
|
+
if (!(props.max === void 0) && +v > props.max) {
|
|
39
|
+
return props.max;
|
|
40
|
+
} else {
|
|
41
|
+
return v;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
function handleInput(e) {
|
|
46
|
+
console.log("asdad", e);
|
|
47
|
+
const target = e.target;
|
|
48
|
+
const value = target.value;
|
|
49
|
+
const data = {};
|
|
50
|
+
data[props.label] = value;
|
|
51
|
+
if (data.hex === void 0 && data["#"] === void 0) {
|
|
52
|
+
emit("change", data);
|
|
53
|
+
} else if (value.length > 5) {
|
|
54
|
+
emit("change", data);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__name(handleInput, "handleInput");
|
|
58
|
+
return () => {
|
|
59
|
+
return _createVNode("div", {
|
|
60
|
+
"data-pixel-component": "MpColorPickerInput",
|
|
61
|
+
"class": css({
|
|
62
|
+
display: "flex",
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
gap: "1"
|
|
65
|
+
})
|
|
66
|
+
}, [_createVNode("div", null, [_createVNode(MpText, {
|
|
67
|
+
"size": "label-small",
|
|
68
|
+
"class": css({
|
|
69
|
+
textTransform: "capitalize"
|
|
70
|
+
})
|
|
71
|
+
}, {
|
|
72
|
+
default: () => [props.label]
|
|
73
|
+
})]), _createVNode(MpInput, {
|
|
74
|
+
"value": val.value,
|
|
75
|
+
"size": "sm",
|
|
76
|
+
"maxlength": props.label === "hex" ? "7" : "3",
|
|
77
|
+
"style": {
|
|
78
|
+
width: props.width,
|
|
79
|
+
minWidth: props.width
|
|
80
|
+
},
|
|
81
|
+
"onInput": handleInput
|
|
82
|
+
}, null)]);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
MpColorInput
|
|
89
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-QZ7VFGWC.mjs";
|
|
4
|
+
|
|
5
|
+
// src/saturation.tsx
|
|
6
|
+
import { createVNode as _createVNode } from "vue";
|
|
7
|
+
import { defineComponent, ref, computed } from "vue";
|
|
8
|
+
import clamp from "clamp";
|
|
9
|
+
import throttle from "lodash.throttle";
|
|
10
|
+
import { css } from "@mekari/pixel3-styled-system/css";
|
|
11
|
+
var MpColorSaturation = defineComponent({
|
|
12
|
+
name: "MpColorSaturation",
|
|
13
|
+
props: {
|
|
14
|
+
value: {
|
|
15
|
+
type: Object
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
emits: ["change"],
|
|
19
|
+
setup(props, {
|
|
20
|
+
emit
|
|
21
|
+
}) {
|
|
22
|
+
const containerNode = ref();
|
|
23
|
+
const colors = computed(() => {
|
|
24
|
+
return props.value;
|
|
25
|
+
});
|
|
26
|
+
const bgColor = computed(() => {
|
|
27
|
+
var _a;
|
|
28
|
+
return `hsl(${(_a = colors.value) == null ? void 0 : _a.hsv.h}, 100%, 50%)`;
|
|
29
|
+
});
|
|
30
|
+
const pointerTop = computed(() => {
|
|
31
|
+
var _a;
|
|
32
|
+
return -(((_a = colors.value) == null ? void 0 : _a.hsv.v) * 100) + 1 + 100 + "%";
|
|
33
|
+
});
|
|
34
|
+
const pointerLeft = computed(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
return ((_a = colors.value) == null ? void 0 : _a.hsv.s) * 100 + "%";
|
|
37
|
+
});
|
|
38
|
+
const handleThrottle = throttle((fn, data) => {
|
|
39
|
+
fn(data);
|
|
40
|
+
}, 20, {
|
|
41
|
+
leading: true,
|
|
42
|
+
trailing: false
|
|
43
|
+
});
|
|
44
|
+
function handleChange(e, skip) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
!skip && e.preventDefault();
|
|
47
|
+
const container = containerNode.value;
|
|
48
|
+
if (!container) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const containerWidth = container.clientWidth;
|
|
52
|
+
const containerHeight = container.clientHeight;
|
|
53
|
+
const xOffset = container.getBoundingClientRect().left + window.scrollX;
|
|
54
|
+
const yOffset = container.getBoundingClientRect().top + window.scrollY;
|
|
55
|
+
const pageX = e.pageX || (e.touches ? e.touches[0].pageX : 0);
|
|
56
|
+
const pageY = e.pageY || (e.touches ? e.touches[0].pageY : 0);
|
|
57
|
+
const left = clamp(pageX - xOffset, 0, containerWidth);
|
|
58
|
+
const top = clamp(pageY - yOffset, 0, containerHeight);
|
|
59
|
+
const saturation = left / containerWidth;
|
|
60
|
+
const bright = clamp(-(top / containerHeight) + 1, 0, 1);
|
|
61
|
+
handleThrottle(onChange, {
|
|
62
|
+
h: (_a = colors.value) == null ? void 0 : _a.hsv.h,
|
|
63
|
+
s: saturation,
|
|
64
|
+
v: bright,
|
|
65
|
+
a: (_b = colors.value) == null ? void 0 : _b.hsv.a,
|
|
66
|
+
source: "hsva"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
__name(handleChange, "handleChange");
|
|
70
|
+
function onChange(param) {
|
|
71
|
+
emit("change", param);
|
|
72
|
+
}
|
|
73
|
+
__name(onChange, "onChange");
|
|
74
|
+
function handleMouseDown() {
|
|
75
|
+
window.addEventListener("mousemove", handleChange);
|
|
76
|
+
window.addEventListener("mouseup", handleChange);
|
|
77
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
78
|
+
}
|
|
79
|
+
__name(handleMouseDown, "handleMouseDown");
|
|
80
|
+
function handleMouseUp() {
|
|
81
|
+
unbindEventListeners();
|
|
82
|
+
}
|
|
83
|
+
__name(handleMouseUp, "handleMouseUp");
|
|
84
|
+
function unbindEventListeners() {
|
|
85
|
+
window.removeEventListener("mousemove", handleChange);
|
|
86
|
+
window.removeEventListener("mouseup", handleChange);
|
|
87
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
88
|
+
}
|
|
89
|
+
__name(unbindEventListeners, "unbindEventListeners");
|
|
90
|
+
return () => {
|
|
91
|
+
return _createVNode("div", {
|
|
92
|
+
"ref": containerNode,
|
|
93
|
+
"data-pixel-component": "MpColorPickerSaturation",
|
|
94
|
+
"id": "saturation-container",
|
|
95
|
+
"class": css({
|
|
96
|
+
cursor: "pointer",
|
|
97
|
+
position: "absolute",
|
|
98
|
+
top: "0",
|
|
99
|
+
right: "0",
|
|
100
|
+
bottom: "0",
|
|
101
|
+
left: "0"
|
|
102
|
+
}),
|
|
103
|
+
"style": {
|
|
104
|
+
background: bgColor.value
|
|
105
|
+
},
|
|
106
|
+
"onMousedown": handleMouseDown,
|
|
107
|
+
"onTouchmove": handleChange,
|
|
108
|
+
"onTouchstart": handleChange
|
|
109
|
+
}, [_createVNode("div", {
|
|
110
|
+
"id": "saturation-white",
|
|
111
|
+
"class": css({
|
|
112
|
+
position: "absolute",
|
|
113
|
+
top: "0",
|
|
114
|
+
right: "0",
|
|
115
|
+
bottom: "0",
|
|
116
|
+
left: "0",
|
|
117
|
+
background: "linear-gradient(to right, #fff, rgba(255,255,255,0))"
|
|
118
|
+
})
|
|
119
|
+
}, null), _createVNode("div", {
|
|
120
|
+
"id": "saturation-black",
|
|
121
|
+
"class": css({
|
|
122
|
+
position: "absolute",
|
|
123
|
+
top: "0",
|
|
124
|
+
right: "0",
|
|
125
|
+
bottom: "0",
|
|
126
|
+
left: "0",
|
|
127
|
+
background: "linear-gradient(to top, #000, rgba(0,0,0,0))"
|
|
128
|
+
})
|
|
129
|
+
}, null), _createVNode("div", {
|
|
130
|
+
"id": "saturation-pointer",
|
|
131
|
+
"class": css({
|
|
132
|
+
cursor: "pointer",
|
|
133
|
+
position: "absolute"
|
|
134
|
+
}),
|
|
135
|
+
"style": {
|
|
136
|
+
top: pointerTop.value,
|
|
137
|
+
left: pointerLeft.value
|
|
138
|
+
}
|
|
139
|
+
}, [_createVNode("div", {
|
|
140
|
+
"id": "saturation-circle",
|
|
141
|
+
"class": css({
|
|
142
|
+
cursor: "pointer",
|
|
143
|
+
width: "6px",
|
|
144
|
+
height: "6px",
|
|
145
|
+
boxShadow: "0 0 0 1.5px #fff, inset 0 0 1px 1px rgba(0,0,0,.3), 0 0 1px 2px rgba(0,0,0,.4)",
|
|
146
|
+
borderRadius: "50%",
|
|
147
|
+
transform: "translate(-2px, -2px)"
|
|
148
|
+
})
|
|
149
|
+
}, null)])]);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export {
|
|
155
|
+
MpColorSaturation
|
|
156
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-QZ7VFGWC.mjs";
|
|
4
|
+
|
|
5
|
+
// src/preset.tsx
|
|
6
|
+
import { createVNode as _createVNode } from "vue";
|
|
7
|
+
import { defineComponent } from "vue";
|
|
8
|
+
import tinycolor from "tinycolor2";
|
|
9
|
+
import { MpIcon } from "@mekari/pixel3-icon";
|
|
10
|
+
import { css } from "@mekari/pixel3-styled-system/css";
|
|
11
|
+
var MpColorPreset = defineComponent({
|
|
12
|
+
name: "MpColorPreset",
|
|
13
|
+
props: {
|
|
14
|
+
value: {
|
|
15
|
+
type: String
|
|
16
|
+
},
|
|
17
|
+
isActive: {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
default: false
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
emits: ["click"],
|
|
23
|
+
setup(props, {
|
|
24
|
+
emit
|
|
25
|
+
}) {
|
|
26
|
+
function handleClick() {
|
|
27
|
+
emit("click", props.value);
|
|
28
|
+
}
|
|
29
|
+
__name(handleClick, "handleClick");
|
|
30
|
+
return () => {
|
|
31
|
+
return _createVNode("div", {
|
|
32
|
+
"data-pixel-component": "MpColorPickerPreset",
|
|
33
|
+
"class": css({
|
|
34
|
+
display: "flex",
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
justifyContent: "center",
|
|
37
|
+
position: "relative",
|
|
38
|
+
width: "6",
|
|
39
|
+
height: "6",
|
|
40
|
+
borderWidth: "1px",
|
|
41
|
+
borderColor: "gray.50",
|
|
42
|
+
borderRadius: "sm",
|
|
43
|
+
cursor: "pointer"
|
|
44
|
+
}),
|
|
45
|
+
"style": {
|
|
46
|
+
background: props.value
|
|
47
|
+
},
|
|
48
|
+
"onClick": handleClick
|
|
49
|
+
}, [props.isActive && _createVNode(MpIcon, {
|
|
50
|
+
"name": "check",
|
|
51
|
+
"size": "sm",
|
|
52
|
+
"color": tinycolor(props.value).isDark() ? "white" : "dark",
|
|
53
|
+
"style": {
|
|
54
|
+
position: "absolute"
|
|
55
|
+
}
|
|
56
|
+
}, null)]);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
MpColorPreset
|
|
63
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/modules/color-picker.props.ts
|
|
2
|
+
var PRESET_DEFAULT = ["#3B82F6", "#14B8A6", "#8B5CF6", "#F59E0B", "#EF4444", "#71717A", "#84CC16", "#EC4899", "#232933", "#60A5FA", "#2DD4BF", "#A78BFA", "#FBBF24", "#F87171", "#A1A1AA", "#A3E635", "#F472B6", "#FFFFFF"];
|
|
3
|
+
var colorPickerProps = {
|
|
4
|
+
id: {
|
|
5
|
+
type: String,
|
|
6
|
+
default: ""
|
|
7
|
+
},
|
|
8
|
+
title: {
|
|
9
|
+
type: String,
|
|
10
|
+
default: "Pick a color"
|
|
11
|
+
},
|
|
12
|
+
value: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: "#3B82F6"
|
|
15
|
+
},
|
|
16
|
+
placeholder: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: "3B82F6"
|
|
19
|
+
},
|
|
20
|
+
variant: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: "advance"
|
|
23
|
+
},
|
|
24
|
+
placement: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: "bottom"
|
|
27
|
+
},
|
|
28
|
+
preset: {
|
|
29
|
+
type: Array,
|
|
30
|
+
default() {
|
|
31
|
+
return PRESET_DEFAULT;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
isShowPopover: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: false
|
|
37
|
+
},
|
|
38
|
+
isShowSaturation: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: true
|
|
41
|
+
},
|
|
42
|
+
isShowHue: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
default: true
|
|
45
|
+
},
|
|
46
|
+
isShowInput: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: true
|
|
49
|
+
},
|
|
50
|
+
isShowPreset: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: true
|
|
53
|
+
},
|
|
54
|
+
isInvalid: {
|
|
55
|
+
type: Boolean,
|
|
56
|
+
default: false
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var colorPickerEmit = ["change"];
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
colorPickerProps,
|
|
63
|
+
colorPickerEmit
|
|
64
|
+
};
|