@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.
Files changed (43) hide show
  1. package/dist/chunk-36OXI4E3.mjs +347 -0
  2. package/dist/chunk-5FWKSVUW.mjs +89 -0
  3. package/dist/chunk-AEUPCATZ.mjs +156 -0
  4. package/dist/chunk-DVRBDVR4.mjs +63 -0
  5. package/dist/chunk-L5BRB7ES.mjs +64 -0
  6. package/dist/chunk-PULVLME3.mjs +196 -0
  7. package/dist/chunk-QZ7VFGWC.mjs +6 -0
  8. package/dist/chunk-YLUI3RMF.mjs +116 -0
  9. package/dist/color-picker.d.mts +129 -0
  10. package/dist/color-picker.d.ts +129 -0
  11. package/dist/color-picker.js +1006 -0
  12. package/dist/color-picker.mjs +13 -0
  13. package/dist/hue.d.mts +27 -0
  14. package/dist/hue.d.ts +27 -0
  15. package/dist/hue.js +217 -0
  16. package/dist/hue.mjs +7 -0
  17. package/dist/index.d.mts +4 -0
  18. package/dist/index.d.ts +4 -0
  19. package/dist/index.js +1008 -0
  20. package/dist/index.mjs +13 -0
  21. package/dist/input.d.mts +41 -0
  22. package/dist/input.d.ts +41 -0
  23. package/dist/input.js +110 -0
  24. package/dist/input.mjs +7 -0
  25. package/dist/metafile-cjs.json +1 -0
  26. package/dist/metafile-esm.json +1 -0
  27. package/dist/modules/color-picker.hooks.d.mts +206 -0
  28. package/dist/modules/color-picker.hooks.d.ts +206 -0
  29. package/dist/modules/color-picker.hooks.js +378 -0
  30. package/dist/modules/color-picker.hooks.mjs +7 -0
  31. package/dist/modules/color-picker.props.d.mts +62 -0
  32. package/dist/modules/color-picker.props.d.ts +62 -0
  33. package/dist/modules/color-picker.props.js +89 -0
  34. package/dist/modules/color-picker.props.mjs +9 -0
  35. package/dist/preset.d.mts +26 -0
  36. package/dist/preset.d.ts +26 -0
  37. package/dist/preset.js +94 -0
  38. package/dist/preset.mjs +7 -0
  39. package/dist/saturation.d.mts +16 -0
  40. package/dist/saturation.d.ts +16 -0
  41. package/dist/saturation.js +187 -0
  42. package/dist/saturation.mjs +7 -0
  43. package/package.json +53 -0
@@ -0,0 +1,1006 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/color-picker.tsx
32
+ var color_picker_exports = {};
33
+ __export(color_picker_exports, {
34
+ MpColorPicker: () => MpColorPicker
35
+ });
36
+ module.exports = __toCommonJS(color_picker_exports);
37
+ var import_vue10 = require("vue");
38
+ var import_vue11 = require("vue");
39
+ var import_pixel3_text2 = require("@mekari/pixel3-text");
40
+ var import_pixel3_popover = require("@mekari/pixel3-popover");
41
+ var import_pixel3_input2 = require("@mekari/pixel3-input");
42
+ var import_pixel3_icon2 = require("@mekari/pixel3-icon");
43
+ var import_pixel3_divider = require("@mekari/pixel3-divider");
44
+ var import_css6 = require("@mekari/pixel3-styled-system/css");
45
+
46
+ // src/modules/color-picker.props.ts
47
+ var PRESET_DEFAULT = ["#3B82F6", "#14B8A6", "#8B5CF6", "#F59E0B", "#EF4444", "#71717A", "#84CC16", "#EC4899", "#232933", "#60A5FA", "#2DD4BF", "#A78BFA", "#FBBF24", "#F87171", "#A1A1AA", "#A3E635", "#F472B6", "#FFFFFF"];
48
+ var colorPickerProps = {
49
+ id: {
50
+ type: String,
51
+ default: ""
52
+ },
53
+ title: {
54
+ type: String,
55
+ default: "Pick a color"
56
+ },
57
+ value: {
58
+ type: String,
59
+ default: "#3B82F6"
60
+ },
61
+ placeholder: {
62
+ type: String,
63
+ default: "3B82F6"
64
+ },
65
+ variant: {
66
+ type: String,
67
+ default: "advance"
68
+ },
69
+ placement: {
70
+ type: String,
71
+ default: "bottom"
72
+ },
73
+ preset: {
74
+ type: Array,
75
+ default() {
76
+ return PRESET_DEFAULT;
77
+ }
78
+ },
79
+ isShowPopover: {
80
+ type: Boolean,
81
+ default: false
82
+ },
83
+ isShowSaturation: {
84
+ type: Boolean,
85
+ default: true
86
+ },
87
+ isShowHue: {
88
+ type: Boolean,
89
+ default: true
90
+ },
91
+ isShowInput: {
92
+ type: Boolean,
93
+ default: true
94
+ },
95
+ isShowPreset: {
96
+ type: Boolean,
97
+ default: true
98
+ },
99
+ isInvalid: {
100
+ type: Boolean,
101
+ default: false
102
+ }
103
+ };
104
+
105
+ // src/modules/color-picker.hooks.ts
106
+ var import_vue = require("vue");
107
+ var import_tinycolor2 = __toESM(require("tinycolor2"));
108
+ var import_pixel3_utils = require("@mekari/pixel3-utils");
109
+ var import_recipes = require("@mekari/pixel3-styled-system/recipes");
110
+ var import_css = require("@mekari/pixel3-styled-system/css");
111
+ var import_tokens = require("@mekari/pixel3-styled-system/tokens");
112
+ function useColorPicker(props, emit) {
113
+ const {
114
+ id,
115
+ value,
116
+ placeholder,
117
+ variant,
118
+ placement,
119
+ isShowPopover,
120
+ isInvalid
121
+ } = (0, import_vue.toRefs)(props);
122
+ const val = (0, import_vue.ref)(_colorChange(value.value));
123
+ const colorInput = (0, import_vue.ref)("");
124
+ const isPopoverOpen = (0, import_vue.ref)(false);
125
+ const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "color-picker").value;
126
+ const colors = (0, import_vue.computed)({
127
+ get() {
128
+ return val.value;
129
+ },
130
+ set(newVal) {
131
+ val.value = newVal;
132
+ emit("change", newVal);
133
+ }
134
+ });
135
+ const hex = (0, import_vue.computed)(() => {
136
+ const hex2 = colors.value.hex;
137
+ return hex2.replace("#", "");
138
+ });
139
+ const borderColor = (0, import_vue.computed)(() => {
140
+ if (isInvalid.value) {
141
+ return "red.400";
142
+ }
143
+ if (!isInvalid.value && isFocused.value) {
144
+ return "blue.400";
145
+ }
146
+ return "gray.100";
147
+ });
148
+ const isFocused = (0, import_vue.computed)(() => {
149
+ return isPopoverOpen.value;
150
+ });
151
+ const rootAttrs = (0, import_vue.computed)(() => {
152
+ return {
153
+ "data-pixel-component": "MpColorPicker",
154
+ id: getId,
155
+ class: (0, import_recipes.colorPickerSlotRecipe)().root,
156
+ style: {
157
+ width: variant.value === "advance" ? "280px" : "72px"
158
+ }
159
+ };
160
+ });
161
+ const popoverAttrs = (0, import_vue.computed)(() => {
162
+ return {
163
+ id: `popover-${getId}`,
164
+ placement: placement.value,
165
+ defaultIsOpen: isShowPopover.value,
166
+ initialFocusRef: `#input-${getId}`,
167
+ onOpen: handleOpenPopover,
168
+ onClose: handleClosePopover
169
+ };
170
+ });
171
+ const popoverTriggerAttrs = (0, import_vue.computed)(() => {
172
+ return {
173
+ tabindex: "0",
174
+ class: (0, import_css.cx)((0, import_css.css)({
175
+ boxShadow: isPopoverOpen.value && !isInvalid.value ? "outline" : "none",
176
+ _hover: {
177
+ borderColor: isPopoverOpen.value && !isInvalid.value ? "blue.500 !important" : "gray.400 !important"
178
+ }
179
+ }), (0, import_recipes.colorPickerSlotRecipe)().popoverTrigger),
180
+ style: {
181
+ borderColor: (0, import_tokens.token)(`colors.${borderColor.value}`)
182
+ }
183
+ };
184
+ });
185
+ const boxColorAttrs = (0, import_vue.computed)(() => {
186
+ return {
187
+ class: (0, import_recipes.colorPickerSlotRecipe)().boxColor,
188
+ style: {
189
+ background: colors.value.hex
190
+ }
191
+ };
192
+ });
193
+ const inputTriggerAttrs = (0, import_vue.computed)(() => {
194
+ return {
195
+ id: `input-${getId}`,
196
+ type: "text",
197
+ autocomplete: "off",
198
+ variant: "unstyled",
199
+ maxlength: "6",
200
+ value: colorInput.value,
201
+ placeholder: placeholder.value,
202
+ class: (0, import_recipes.colorPickerSlotRecipe)().inputTrigger,
203
+ onInput: handleInputTrigger
204
+ };
205
+ });
206
+ const iconDropDownAttrs = (0, import_vue.computed)(() => {
207
+ return {
208
+ name: "chevrons-down",
209
+ size: "sm",
210
+ class: (0, import_recipes.colorPickerSlotRecipe)().iconDropdown
211
+ };
212
+ });
213
+ const popoverContentAttrs = (0, import_vue.computed)(() => {
214
+ return {
215
+ class: (0, import_recipes.colorPickerSlotRecipe)().popoverContent,
216
+ style: {
217
+ width: variant.value === "advance" ? "280px" : "188px"
218
+ }
219
+ };
220
+ });
221
+ const wrapperAdvanceAttrs = (0, import_vue.computed)(() => {
222
+ return {
223
+ class: (0, import_recipes.colorPickerSlotRecipe)().wrapperAdvance
224
+ };
225
+ });
226
+ const wrapperBasicAttrs = (0, import_vue.computed)(() => {
227
+ return {
228
+ class: (0, import_recipes.colorPickerSlotRecipe)().wrapperBasic
229
+ };
230
+ });
231
+ const wrapperSaturationAttrs = (0, import_vue.computed)(() => {
232
+ return {
233
+ class: (0, import_recipes.colorPickerSlotRecipe)().wrapperSaturation
234
+ };
235
+ });
236
+ const saturationAttrs = (0, import_vue.computed)(() => {
237
+ return {
238
+ value: colors.value,
239
+ onChange: childChange
240
+ };
241
+ });
242
+ const wrapperHueAttrs = (0, import_vue.computed)(() => {
243
+ return {
244
+ class: (0, import_recipes.colorPickerSlotRecipe)().wrapperHue
245
+ };
246
+ });
247
+ const hueAttrs = (0, import_vue.computed)(() => {
248
+ return {
249
+ value: colors.value,
250
+ onChange: childChange
251
+ };
252
+ });
253
+ const wrapperInputAttrs = (0, import_vue.computed)(() => {
254
+ return {
255
+ class: (0, import_recipes.colorPickerSlotRecipe)().wrapperInput
256
+ };
257
+ });
258
+ const inputHexAttrs = (0, import_vue.computed)(() => {
259
+ return {
260
+ label: "hex",
261
+ width: "88px",
262
+ value: hex.value,
263
+ onChange: inputChange
264
+ };
265
+ });
266
+ const inputFullAttrs = (0, import_vue.computed)(() => {
267
+ return {
268
+ label: "hex",
269
+ width: "full",
270
+ value: hex.value,
271
+ onChange: inputChange
272
+ };
273
+ });
274
+ const inputRedAttrs = (0, import_vue.computed)(() => {
275
+ return {
276
+ label: "r",
277
+ width: "48px",
278
+ value: colors.value.rgba.r,
279
+ onChange: inputChange
280
+ };
281
+ });
282
+ const inputGreenAttrs = (0, import_vue.computed)(() => {
283
+ return {
284
+ label: "g",
285
+ width: "48px",
286
+ value: colors.value.rgba.g,
287
+ onChange: inputChange
288
+ };
289
+ });
290
+ const inputBlueAttrs = (0, import_vue.computed)(() => {
291
+ return {
292
+ label: "b",
293
+ width: "48px",
294
+ value: colors.value.rgba.b,
295
+ onChange: inputChange
296
+ };
297
+ });
298
+ const boxPresetAttrs = (0, import_vue.computed)(() => {
299
+ return {
300
+ class: (0, import_recipes.colorPickerSlotRecipe)().boxPreset
301
+ };
302
+ });
303
+ const wrapperPresetAttrs = (0, import_vue.computed)(() => {
304
+ return {
305
+ class: (0, import_recipes.colorPickerSlotRecipe)().wrapperPreset
306
+ };
307
+ });
308
+ const wrapperBasicPresetAttrs = (0, import_vue.computed)(() => {
309
+ return {
310
+ class: (0, import_recipes.colorPickerSlotRecipe)().wrapperBasicPreset
311
+ };
312
+ });
313
+ const presetBoxAttrs = /* @__PURE__ */ __name((item) => {
314
+ return {
315
+ value: item,
316
+ isActive: item.toLowerCase() === colors.value.hex.toLowerCase(),
317
+ onClick: childChange
318
+ };
319
+ }, "presetBoxAttrs");
320
+ function isValidHex(hex2) {
321
+ return (0, import_tinycolor2.default)(hex2).isValid();
322
+ }
323
+ __name(isValidHex, "isValidHex");
324
+ function childChange(data) {
325
+ colorChange(data);
326
+ }
327
+ __name(childChange, "childChange");
328
+ function colorChange(data, oldHue) {
329
+ colors.value = _colorChange(data, oldHue);
330
+ }
331
+ __name(colorChange, "colorChange");
332
+ function _colorChange(data, oldHue) {
333
+ let color;
334
+ if (data && data.hsl) {
335
+ color = (0, import_tinycolor2.default)(data.hsl);
336
+ } else if (data && data.hex && data.hex.length > 0) {
337
+ color = (0, import_tinycolor2.default)(data.hex);
338
+ } else if (data && data.hsv) {
339
+ color = (0, import_tinycolor2.default)(data.hsv);
340
+ } else if (data && data.rgba) {
341
+ color = (0, import_tinycolor2.default)(data.rgba);
342
+ } else if (data && data.rgb) {
343
+ color = (0, import_tinycolor2.default)(data.rgb);
344
+ } else {
345
+ color = (0, import_tinycolor2.default)(data);
346
+ }
347
+ const hsl = color.toHsl();
348
+ const hsv = color.toHsv();
349
+ if (hsl.s === 0) {
350
+ hsv.h = hsl.h = data.h || data.hsl && data.hsl.h || oldHue || 0;
351
+ }
352
+ return {
353
+ hsl,
354
+ hex: color.toHexString().toUpperCase(),
355
+ hex8: color.toHex8String().toUpperCase(),
356
+ rgba: color.toRgb(),
357
+ hsv,
358
+ oldHue: data.h || oldHue || hsl.h,
359
+ source: data.source
360
+ };
361
+ }
362
+ __name(_colorChange, "_colorChange");
363
+ function inputChange(data) {
364
+ if (!data) {
365
+ return;
366
+ }
367
+ if (data.hex) {
368
+ isValidHex(data.hex) && colorChange({
369
+ hex: data.hex,
370
+ source: "hex"
371
+ });
372
+ } else if (data.r || data.g || data.b || data.a) {
373
+ colorChange({
374
+ r: data.r || colors.value.rgba.r,
375
+ g: data.g || colors.value.rgba.g,
376
+ b: data.b || colors.value.rgba.b,
377
+ a: data.a || colors.value.rgba.a,
378
+ source: "rgba"
379
+ });
380
+ }
381
+ }
382
+ __name(inputChange, "inputChange");
383
+ function handleInputTrigger(e) {
384
+ const target = e.target;
385
+ const value2 = target.value;
386
+ const data = {
387
+ hex: "",
388
+ "#": ""
389
+ };
390
+ data["hex"] = value2;
391
+ if (data.hex === void 0 && data["#"] === void 0) {
392
+ inputChange(data);
393
+ } else if (value2.length > 5) {
394
+ inputChange(data);
395
+ }
396
+ }
397
+ __name(handleInputTrigger, "handleInputTrigger");
398
+ function handleOpenPopover() {
399
+ isPopoverOpen.value = true;
400
+ colorInput.value = hex.value;
401
+ }
402
+ __name(handleOpenPopover, "handleOpenPopover");
403
+ function handleClosePopover() {
404
+ isPopoverOpen.value = false;
405
+ colorInput.value = hex.value;
406
+ }
407
+ __name(handleClosePopover, "handleClosePopover");
408
+ (0, import_vue.watch)(() => value.value, (newValue, oldValue) => {
409
+ if (newValue !== oldValue) {
410
+ val.value = _colorChange(newValue);
411
+ colorInput.value = hex.value;
412
+ }
413
+ });
414
+ (0, import_vue.onMounted)(() => {
415
+ colorInput.value = hex.value;
416
+ });
417
+ return {
418
+ rootAttrs,
419
+ popoverAttrs,
420
+ popoverTriggerAttrs,
421
+ boxColorAttrs,
422
+ inputTriggerAttrs,
423
+ iconDropDownAttrs,
424
+ popoverContentAttrs,
425
+ wrapperAdvanceAttrs,
426
+ wrapperBasicAttrs,
427
+ wrapperSaturationAttrs,
428
+ saturationAttrs,
429
+ wrapperHueAttrs,
430
+ hueAttrs,
431
+ wrapperInputAttrs,
432
+ inputHexAttrs,
433
+ inputRedAttrs,
434
+ inputGreenAttrs,
435
+ inputBlueAttrs,
436
+ inputFullAttrs,
437
+ boxPresetAttrs,
438
+ wrapperPresetAttrs,
439
+ wrapperBasicPresetAttrs,
440
+ presetBoxAttrs
441
+ };
442
+ }
443
+ __name(useColorPicker, "useColorPicker");
444
+
445
+ // src/saturation.tsx
446
+ var import_vue2 = require("vue");
447
+ var import_vue3 = require("vue");
448
+ var import_clamp = __toESM(require("clamp"));
449
+ var import_lodash = __toESM(require("lodash.throttle"));
450
+ var import_css2 = require("@mekari/pixel3-styled-system/css");
451
+ var MpColorSaturation = (0, import_vue3.defineComponent)({
452
+ name: "MpColorSaturation",
453
+ props: {
454
+ value: {
455
+ type: Object
456
+ }
457
+ },
458
+ emits: ["change"],
459
+ setup(props, {
460
+ emit
461
+ }) {
462
+ const containerNode = (0, import_vue3.ref)();
463
+ const colors = (0, import_vue3.computed)(() => {
464
+ return props.value;
465
+ });
466
+ const bgColor = (0, import_vue3.computed)(() => {
467
+ var _a;
468
+ return `hsl(${(_a = colors.value) == null ? void 0 : _a.hsv.h}, 100%, 50%)`;
469
+ });
470
+ const pointerTop = (0, import_vue3.computed)(() => {
471
+ var _a;
472
+ return -(((_a = colors.value) == null ? void 0 : _a.hsv.v) * 100) + 1 + 100 + "%";
473
+ });
474
+ const pointerLeft = (0, import_vue3.computed)(() => {
475
+ var _a;
476
+ return ((_a = colors.value) == null ? void 0 : _a.hsv.s) * 100 + "%";
477
+ });
478
+ const handleThrottle = (0, import_lodash.default)((fn, data) => {
479
+ fn(data);
480
+ }, 20, {
481
+ leading: true,
482
+ trailing: false
483
+ });
484
+ function handleChange(e, skip) {
485
+ var _a, _b;
486
+ !skip && e.preventDefault();
487
+ const container = containerNode.value;
488
+ if (!container) {
489
+ return;
490
+ }
491
+ const containerWidth = container.clientWidth;
492
+ const containerHeight = container.clientHeight;
493
+ const xOffset = container.getBoundingClientRect().left + window.scrollX;
494
+ const yOffset = container.getBoundingClientRect().top + window.scrollY;
495
+ const pageX = e.pageX || (e.touches ? e.touches[0].pageX : 0);
496
+ const pageY = e.pageY || (e.touches ? e.touches[0].pageY : 0);
497
+ const left = (0, import_clamp.default)(pageX - xOffset, 0, containerWidth);
498
+ const top = (0, import_clamp.default)(pageY - yOffset, 0, containerHeight);
499
+ const saturation = left / containerWidth;
500
+ const bright = (0, import_clamp.default)(-(top / containerHeight) + 1, 0, 1);
501
+ handleThrottle(onChange, {
502
+ h: (_a = colors.value) == null ? void 0 : _a.hsv.h,
503
+ s: saturation,
504
+ v: bright,
505
+ a: (_b = colors.value) == null ? void 0 : _b.hsv.a,
506
+ source: "hsva"
507
+ });
508
+ }
509
+ __name(handleChange, "handleChange");
510
+ function onChange(param) {
511
+ emit("change", param);
512
+ }
513
+ __name(onChange, "onChange");
514
+ function handleMouseDown() {
515
+ window.addEventListener("mousemove", handleChange);
516
+ window.addEventListener("mouseup", handleChange);
517
+ window.addEventListener("mouseup", handleMouseUp);
518
+ }
519
+ __name(handleMouseDown, "handleMouseDown");
520
+ function handleMouseUp() {
521
+ unbindEventListeners();
522
+ }
523
+ __name(handleMouseUp, "handleMouseUp");
524
+ function unbindEventListeners() {
525
+ window.removeEventListener("mousemove", handleChange);
526
+ window.removeEventListener("mouseup", handleChange);
527
+ window.removeEventListener("mouseup", handleMouseUp);
528
+ }
529
+ __name(unbindEventListeners, "unbindEventListeners");
530
+ return () => {
531
+ return (0, import_vue2.createVNode)("div", {
532
+ "ref": containerNode,
533
+ "data-pixel-component": "MpColorPickerSaturation",
534
+ "id": "saturation-container",
535
+ "class": (0, import_css2.css)({
536
+ cursor: "pointer",
537
+ position: "absolute",
538
+ top: "0",
539
+ right: "0",
540
+ bottom: "0",
541
+ left: "0"
542
+ }),
543
+ "style": {
544
+ background: bgColor.value
545
+ },
546
+ "onMousedown": handleMouseDown,
547
+ "onTouchmove": handleChange,
548
+ "onTouchstart": handleChange
549
+ }, [(0, import_vue2.createVNode)("div", {
550
+ "id": "saturation-white",
551
+ "class": (0, import_css2.css)({
552
+ position: "absolute",
553
+ top: "0",
554
+ right: "0",
555
+ bottom: "0",
556
+ left: "0",
557
+ background: "linear-gradient(to right, #fff, rgba(255,255,255,0))"
558
+ })
559
+ }, null), (0, import_vue2.createVNode)("div", {
560
+ "id": "saturation-black",
561
+ "class": (0, import_css2.css)({
562
+ position: "absolute",
563
+ top: "0",
564
+ right: "0",
565
+ bottom: "0",
566
+ left: "0",
567
+ background: "linear-gradient(to top, #000, rgba(0,0,0,0))"
568
+ })
569
+ }, null), (0, import_vue2.createVNode)("div", {
570
+ "id": "saturation-pointer",
571
+ "class": (0, import_css2.css)({
572
+ cursor: "pointer",
573
+ position: "absolute"
574
+ }),
575
+ "style": {
576
+ top: pointerTop.value,
577
+ left: pointerLeft.value
578
+ }
579
+ }, [(0, import_vue2.createVNode)("div", {
580
+ "id": "saturation-circle",
581
+ "class": (0, import_css2.css)({
582
+ cursor: "pointer",
583
+ width: "6px",
584
+ height: "6px",
585
+ 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)",
586
+ borderRadius: "50%",
587
+ transform: "translate(-2px, -2px)"
588
+ })
589
+ }, null)])]);
590
+ };
591
+ }
592
+ });
593
+
594
+ // src/hue.tsx
595
+ var import_vue4 = require("vue");
596
+ var import_vue5 = require("vue");
597
+ var import_css3 = require("@mekari/pixel3-styled-system/css");
598
+ var MpColorHue = (0, import_vue5.defineComponent)({
599
+ name: "MpColorHue",
600
+ props: {
601
+ value: {
602
+ type: Object
603
+ },
604
+ direction: {
605
+ type: String,
606
+ default: "horizontal"
607
+ }
608
+ },
609
+ emits: ["change"],
610
+ setup(props, {
611
+ emit
612
+ }) {
613
+ const oldHue = (0, import_vue5.ref)(0);
614
+ const pullDirection = (0, import_vue5.ref)("");
615
+ const containerNode = (0, import_vue5.ref)();
616
+ (0, import_vue5.watch)(() => props.value, (oldValue, newValue) => {
617
+ if (oldValue !== newValue) {
618
+ handlePullDirection();
619
+ }
620
+ });
621
+ const colors = (0, import_vue5.computed)(() => {
622
+ return props.value;
623
+ });
624
+ const pointerTop = (0, import_vue5.computed)(() => {
625
+ var _a;
626
+ const h = (_a = props.value) == null ? void 0 : _a.hsl.h;
627
+ if (props.direction === "vertical") {
628
+ if (h === 0 && pullDirection.value === "right")
629
+ return 0;
630
+ return -(h * 100 / 360) + 100 + "%";
631
+ } else {
632
+ return 0;
633
+ }
634
+ });
635
+ const pointerLeft = (0, import_vue5.computed)(() => {
636
+ var _a;
637
+ const h = (_a = props.value) == null ? void 0 : _a.hsl.h;
638
+ if (props.direction === "vertical") {
639
+ return 0;
640
+ } else {
641
+ if (h === 0 && pullDirection.value === "right")
642
+ return "100%";
643
+ return h * 100 / 360 + "%";
644
+ }
645
+ });
646
+ function handlePullDirection() {
647
+ var _a;
648
+ const h = (_a = props.value) == null ? void 0 : _a.hsl.h;
649
+ if (h !== 0 && h - oldHue.value > 0)
650
+ pullDirection.value = "right";
651
+ if (h !== 0 && h - oldHue.value < 0)
652
+ pullDirection.value = "left";
653
+ oldHue.value = h;
654
+ }
655
+ __name(handlePullDirection, "handlePullDirection");
656
+ function handleChange(e, skip) {
657
+ var _a, _b, _c, _d, _e, _f, _g, _h;
658
+ !skip && e.preventDefault();
659
+ const container = containerNode.value;
660
+ if (!container) {
661
+ return;
662
+ }
663
+ const containerWidth = container.clientWidth;
664
+ const containerHeight = container.clientHeight;
665
+ const xOffset = container.getBoundingClientRect().left + window.scrollX;
666
+ const yOffset = container.getBoundingClientRect().top + window.scrollY;
667
+ const pageX = e.pageX || (e.touches ? e.touches[0].pageX : 0);
668
+ const pageY = e.pageY || (e.touches ? e.touches[0].pageY : 0);
669
+ const left = pageX - xOffset;
670
+ const top = pageY - yOffset;
671
+ let h;
672
+ let percent;
673
+ if (props.direction === "vertical") {
674
+ if (top < 0) {
675
+ h = 360;
676
+ } else if (top > containerHeight) {
677
+ h = 0;
678
+ } else {
679
+ percent = -(top * 100 / containerHeight) + 100;
680
+ h = 360 * percent / 100;
681
+ }
682
+ if (((_a = colors.value) == null ? void 0 : _a.hsl.h) !== h) {
683
+ emit("change", {
684
+ h,
685
+ s: (_b = colors.value) == null ? void 0 : _b.hsl.s,
686
+ l: (_c = colors.value) == null ? void 0 : _c.hsl.l,
687
+ a: (_d = colors.value) == null ? void 0 : _d.hsl.a,
688
+ source: "hsl"
689
+ });
690
+ }
691
+ } else {
692
+ if (left < 0) {
693
+ h = 0;
694
+ } else if (left > containerWidth) {
695
+ h = 360;
696
+ } else {
697
+ percent = left * 100 / containerWidth;
698
+ h = 360 * percent / 100;
699
+ }
700
+ if (((_e = colors.value) == null ? void 0 : _e.hsl.h) !== h) {
701
+ emit("change", {
702
+ h,
703
+ s: (_f = colors.value) == null ? void 0 : _f.hsl.s,
704
+ l: (_g = colors.value) == null ? void 0 : _g.hsl.l,
705
+ a: (_h = colors.value) == null ? void 0 : _h.hsl.a,
706
+ source: "hsl"
707
+ });
708
+ }
709
+ }
710
+ }
711
+ __name(handleChange, "handleChange");
712
+ function handleMouseDown(e) {
713
+ handleChange(e, true);
714
+ window.addEventListener("mousemove", handleChange);
715
+ window.addEventListener("mouseup", handleMouseUp);
716
+ }
717
+ __name(handleMouseDown, "handleMouseDown");
718
+ function handleMouseUp() {
719
+ unbindEventListeners();
720
+ }
721
+ __name(handleMouseUp, "handleMouseUp");
722
+ function unbindEventListeners() {
723
+ window.removeEventListener("mousemove", handleChange);
724
+ window.removeEventListener("mouseup", handleMouseUp);
725
+ }
726
+ __name(unbindEventListeners, "unbindEventListeners");
727
+ return () => {
728
+ var _a;
729
+ return (0, import_vue4.createVNode)("div", {
730
+ "data-pixel-component": "MpColorPickerHue",
731
+ "class": (0, import_css3.css)({
732
+ position: "absolute",
733
+ top: "0",
734
+ right: "0",
735
+ bottom: "0",
736
+ left: "0",
737
+ background: props.direction === "horizontal" ? "linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)" : "linear-gradient(to top, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)"
738
+ })
739
+ }, [(0, import_vue4.createVNode)("div", {
740
+ "ref": containerNode,
741
+ "id": "hue-container",
742
+ "role": "slider",
743
+ "aria-valuenow": (_a = colors.value) == null ? void 0 : _a.hsl.h,
744
+ "aria-valuemin": "0",
745
+ "aria-valuemax": "360",
746
+ "class": (0, import_css3.css)({
747
+ cursor: "pointer",
748
+ margin: "0 2px",
749
+ position: "relative",
750
+ height: "100%"
751
+ }),
752
+ "onMousedown": handleMouseDown,
753
+ "onTouchmove": handleChange,
754
+ "onTouchstart": handleChange
755
+ }, [(0, import_vue4.createVNode)("div", {
756
+ "id": "hue-pointer",
757
+ "role": "presentation",
758
+ "class": (0, import_css3.css)({
759
+ position: "absolute",
760
+ zIndex: "2"
761
+ }),
762
+ "style": {
763
+ top: pointerTop.value,
764
+ left: pointerLeft.value
765
+ }
766
+ }, [(0, import_vue4.createVNode)("div", {
767
+ "id": "hue-picker",
768
+ "class": (0, import_css3.css)({
769
+ cursor: "pointer",
770
+ marginTop: "-2px",
771
+ width: "32px",
772
+ height: "32px",
773
+ transform: "translateX(-16px)",
774
+ borderRadius: "24px",
775
+ boxShadow: "0px 10px 15px -3px rgba(0, 0, 0, 0.10), 0px 4px 6px -2px rgba(0, 0, 0, 0.05)",
776
+ background: "white"
777
+ })
778
+ }, null)])])]);
779
+ };
780
+ }
781
+ });
782
+
783
+ // src/input.tsx
784
+ var import_vue6 = require("vue");
785
+ var import_vue7 = require("vue");
786
+ var import_pixel3_text = require("@mekari/pixel3-text");
787
+ var import_pixel3_input = require("@mekari/pixel3-input");
788
+ var import_css4 = require("@mekari/pixel3-styled-system/css");
789
+ var MpColorInput = (0, import_vue7.defineComponent)({
790
+ name: "MpColorInput",
791
+ props: {
792
+ value: {
793
+ type: [String, Number],
794
+ default: ""
795
+ },
796
+ label: {
797
+ type: String,
798
+ default: "hex"
799
+ },
800
+ width: {
801
+ type: String
802
+ },
803
+ max: {
804
+ type: Number
805
+ }
806
+ },
807
+ emits: ["change"],
808
+ setup(props, {
809
+ emit
810
+ }) {
811
+ const val = (0, import_vue7.computed)({
812
+ get() {
813
+ return props.value;
814
+ },
815
+ set(v) {
816
+ if (!(props.max === void 0) && +v > props.max) {
817
+ return props.max;
818
+ } else {
819
+ return v;
820
+ }
821
+ }
822
+ });
823
+ function handleInput(e) {
824
+ console.log("asdad", e);
825
+ const target = e.target;
826
+ const value = target.value;
827
+ const data = {};
828
+ data[props.label] = value;
829
+ if (data.hex === void 0 && data["#"] === void 0) {
830
+ emit("change", data);
831
+ } else if (value.length > 5) {
832
+ emit("change", data);
833
+ }
834
+ }
835
+ __name(handleInput, "handleInput");
836
+ return () => {
837
+ return (0, import_vue6.createVNode)("div", {
838
+ "data-pixel-component": "MpColorPickerInput",
839
+ "class": (0, import_css4.css)({
840
+ display: "flex",
841
+ flexDirection: "column",
842
+ gap: "1"
843
+ })
844
+ }, [(0, import_vue6.createVNode)("div", null, [(0, import_vue6.createVNode)(import_pixel3_text.MpText, {
845
+ "size": "label-small",
846
+ "class": (0, import_css4.css)({
847
+ textTransform: "capitalize"
848
+ })
849
+ }, {
850
+ default: () => [props.label]
851
+ })]), (0, import_vue6.createVNode)(import_pixel3_input.MpInput, {
852
+ "value": val.value,
853
+ "size": "sm",
854
+ "maxlength": props.label === "hex" ? "7" : "3",
855
+ "style": {
856
+ width: props.width,
857
+ minWidth: props.width
858
+ },
859
+ "onInput": handleInput
860
+ }, null)]);
861
+ };
862
+ }
863
+ });
864
+
865
+ // src/preset.tsx
866
+ var import_vue8 = require("vue");
867
+ var import_vue9 = require("vue");
868
+ var import_tinycolor22 = __toESM(require("tinycolor2"));
869
+ var import_pixel3_icon = require("@mekari/pixel3-icon");
870
+ var import_css5 = require("@mekari/pixel3-styled-system/css");
871
+ var MpColorPreset = (0, import_vue9.defineComponent)({
872
+ name: "MpColorPreset",
873
+ props: {
874
+ value: {
875
+ type: String
876
+ },
877
+ isActive: {
878
+ type: Boolean,
879
+ default: false
880
+ }
881
+ },
882
+ emits: ["click"],
883
+ setup(props, {
884
+ emit
885
+ }) {
886
+ function handleClick() {
887
+ emit("click", props.value);
888
+ }
889
+ __name(handleClick, "handleClick");
890
+ return () => {
891
+ return (0, import_vue8.createVNode)("div", {
892
+ "data-pixel-component": "MpColorPickerPreset",
893
+ "class": (0, import_css5.css)({
894
+ display: "flex",
895
+ alignItems: "center",
896
+ justifyContent: "center",
897
+ position: "relative",
898
+ width: "6",
899
+ height: "6",
900
+ borderWidth: "1px",
901
+ borderColor: "gray.50",
902
+ borderRadius: "sm",
903
+ cursor: "pointer"
904
+ }),
905
+ "style": {
906
+ background: props.value
907
+ },
908
+ "onClick": handleClick
909
+ }, [props.isActive && (0, import_vue8.createVNode)(import_pixel3_icon.MpIcon, {
910
+ "name": "check",
911
+ "size": "sm",
912
+ "color": (0, import_tinycolor22.default)(props.value).isDark() ? "white" : "dark",
913
+ "style": {
914
+ position: "absolute"
915
+ }
916
+ }, null)]);
917
+ };
918
+ }
919
+ });
920
+
921
+ // src/color-picker.tsx
922
+ function _isSlot(s) {
923
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, import_vue10.isVNode)(s);
924
+ }
925
+ __name(_isSlot, "_isSlot");
926
+ var MpColorPicker = (0, import_vue11.defineComponent)({
927
+ name: "MpColorPicker",
928
+ props: colorPickerProps,
929
+ emits: ["change"],
930
+ setup(props, {
931
+ slots,
932
+ emit
933
+ }) {
934
+ const {
935
+ rootAttrs,
936
+ popoverAttrs,
937
+ popoverTriggerAttrs,
938
+ boxColorAttrs,
939
+ inputTriggerAttrs,
940
+ iconDropDownAttrs,
941
+ popoverContentAttrs,
942
+ wrapperAdvanceAttrs,
943
+ wrapperBasicAttrs,
944
+ wrapperSaturationAttrs,
945
+ saturationAttrs,
946
+ wrapperHueAttrs,
947
+ hueAttrs,
948
+ wrapperInputAttrs,
949
+ inputHexAttrs,
950
+ inputRedAttrs,
951
+ inputGreenAttrs,
952
+ inputBlueAttrs,
953
+ inputFullAttrs,
954
+ boxPresetAttrs,
955
+ wrapperBasicPresetAttrs,
956
+ wrapperPresetAttrs,
957
+ presetBoxAttrs
958
+ } = useColorPicker(props, emit);
959
+ return () => {
960
+ const children = slots.default && slots.default();
961
+ const {
962
+ variant,
963
+ title,
964
+ isShowSaturation,
965
+ isShowHue,
966
+ isShowInput,
967
+ isShowPreset
968
+ } = props;
969
+ return (0, import_vue10.createVNode)("div", rootAttrs.value, [(0, import_vue10.createVNode)(import_pixel3_popover.MpPopover, popoverAttrs.value, {
970
+ default: () => [(0, import_vue10.createVNode)(import_pixel3_popover.MpPopoverTrigger, null, {
971
+ default: () => [children ? (0, import_vue10.createVNode)("div", null, [children]) : (0, import_vue10.createVNode)("div", popoverTriggerAttrs.value, [(0, import_vue10.createVNode)("div", boxColorAttrs.value, null), variant === "advance" && (0, import_vue10.createVNode)(import_pixel3_text2.MpText, {
972
+ "color": "gray.400",
973
+ "style": "margin-top: 1px"
974
+ }, {
975
+ default: () => [(0, import_vue10.createTextVNode)("#")]
976
+ }), variant === "advance" && (0, import_vue10.createVNode)(import_pixel3_input2.MpInput, inputTriggerAttrs.value, null), (0, import_vue10.createVNode)(import_pixel3_icon2.MpIcon, iconDropDownAttrs.value, null)])]
977
+ }), (0, import_vue10.createVNode)(import_pixel3_popover.MpPopoverContent, popoverContentAttrs.value, {
978
+ default: () => [variant === "advance" && (0, import_vue10.createVNode)("div", wrapperAdvanceAttrs.value, [isShowSaturation && (0, import_vue10.createVNode)("div", wrapperSaturationAttrs.value, [(0, import_vue10.createVNode)(MpColorSaturation, saturationAttrs.value, null)]), isShowHue && (0, import_vue10.createVNode)("div", wrapperHueAttrs.value, [(0, import_vue10.createVNode)(MpColorHue, hueAttrs.value, null)]), isShowInput && (0, import_vue10.createVNode)("div", wrapperInputAttrs.value, [(0, import_vue10.createVNode)(MpColorInput, inputHexAttrs.value, null), (0, import_vue10.createVNode)(MpColorInput, inputRedAttrs.value, null), (0, import_vue10.createVNode)(MpColorInput, inputGreenAttrs.value, null), (0, import_vue10.createVNode)(MpColorInput, inputBlueAttrs.value, null)]), isShowPreset && (0, import_vue10.createVNode)(import_pixel3_divider.MpDivider, {
979
+ "class": (0, import_css6.css)({
980
+ marginTop: "0",
981
+ marginBottom: "0"
982
+ })
983
+ }, null), isShowPreset && (0, import_vue10.createVNode)("div", boxPresetAttrs.value, [(0, import_vue10.createVNode)("div", wrapperPresetAttrs.value, [(0, import_vue10.createVNode)(import_pixel3_text2.MpText, {
984
+ "size": "label-small",
985
+ "style": "width: 100%;"
986
+ }, {
987
+ default: () => [(0, import_vue10.createTextVNode)("Present")]
988
+ }), props.preset.map((item) => {
989
+ return (0, import_vue10.createVNode)(MpColorPreset, presetBoxAttrs(item), null);
990
+ })])])]), variant === "basic" && (0, import_vue10.createVNode)("div", wrapperBasicAttrs.value, [(0, import_vue10.createVNode)(import_pixel3_text2.MpText, {
991
+ "size": "body-small",
992
+ "color": "gray.600"
993
+ }, _isSlot(title) ? title : {
994
+ default: () => [title]
995
+ }), isShowPreset && (0, import_vue10.createVNode)("div", wrapperBasicPresetAttrs.value, [props.preset.map((item) => {
996
+ return (0, import_vue10.createVNode)(MpColorPreset, presetBoxAttrs(item), null);
997
+ })]), isShowInput && (0, import_vue10.createVNode)("div", wrapperInputAttrs.value, [(0, import_vue10.createVNode)(MpColorInput, inputFullAttrs.value, null)])])]
998
+ })]
999
+ })]);
1000
+ };
1001
+ }
1002
+ });
1003
+ // Annotate the CommonJS export names for ESM import in node:
1004
+ 0 && (module.exports = {
1005
+ MpColorPicker
1006
+ });