@opentiny/vue-renderless 3.19.5 → 3.20.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.
Files changed (77) hide show
  1. package/base-select/index.js +11 -74
  2. package/base-select/vue.js +10 -10
  3. package/bulletin-board/index.js +5 -1
  4. package/bulletin-board/vue.js +5 -4
  5. package/button/index.js +11 -3
  6. package/button/vue.js +6 -2
  7. package/button-group/index.js +1 -1
  8. package/color-picker/index.js +4 -4
  9. package/color-picker/utils/color.js +358 -83
  10. package/color-picker/utils/hsv-to-rgb.js +59 -0
  11. package/color-picker/vue.js +27 -8
  12. package/color-select-panel/alpha-select/index.js +65 -14
  13. package/color-select-panel/alpha-select/vue.js +29 -44
  14. package/color-select-panel/hue-select/index.js +47 -61
  15. package/color-select-panel/hue-select/vue.js +29 -47
  16. package/color-select-panel/index.js +230 -80
  17. package/color-select-panel/sv-select/index.js +68 -0
  18. package/color-select-panel/sv-select/vue.js +32 -0
  19. package/color-select-panel/utils/color.js +345 -82
  20. package/color-select-panel/utils/getClientXY.js +54 -0
  21. package/color-select-panel/vue.js +47 -72
  22. package/common/deps/popper.js +1 -1
  23. package/common/deps/useUserAgent.js +16 -0
  24. package/common/event.js +21 -0
  25. package/common/index.js +1 -1
  26. package/common/runtime.js +1 -1
  27. package/date-picker-mobile/index.js +4 -4
  28. package/dialog-box/index.js +1 -1
  29. package/dropdown/index.js +5 -1
  30. package/dropdown/vue.js +2 -2
  31. package/file-upload/vue.js +1 -0
  32. package/flowchart/index.js +3 -2
  33. package/form/index.js +2 -2
  34. package/form-item/index.js +4 -1
  35. package/grid-select/index.js +82 -0
  36. package/grid-select/vue.js +30 -0
  37. package/input/index.js +2 -2
  38. package/menu/vue.js +5 -1
  39. package/modal/index.js +2 -0
  40. package/numeric/index.js +29 -9
  41. package/option/index.js +6 -0
  42. package/option/vue.js +12 -2
  43. package/package.json +1 -1
  44. package/picker/index.js +1 -1
  45. package/recycle-scroller/index.js +43 -27
  46. package/recycle-scroller/vue.js +9 -4
  47. package/rich-text/index.js +13 -0
  48. package/rich-text/vue.js +4 -2
  49. package/select/index.js +71 -23
  50. package/select/vue.js +12 -4
  51. package/select-dropdown/vue.js +1 -1
  52. package/tabbar/index.js +4 -1
  53. package/tabbar/vue.js +1 -1
  54. package/tabs/index.js +8 -5
  55. package/tabs/vue.js +4 -1
  56. package/time-panel/vue.js +1 -1
  57. package/tooltip/vue.js +1 -0
  58. package/tree-menu/index.js +5 -1
  59. package/tree-node/index.js +5 -4
  60. package/tree-select/index.js +77 -1
  61. package/tree-select/vue.js +21 -7
  62. package/types/button.type.d.ts +7 -3
  63. package/types/color-select-panel.type.d.ts +23 -1
  64. package/types/file-upload.type.d.ts +1 -1
  65. package/types/input.type.d.ts +1 -1
  66. package/types/numeric.type.d.ts +5 -5
  67. package/types/popover.type.d.ts +1 -1
  68. package/types/transfer.type.d.ts +3 -3
  69. package/types/tree-menu.type.d.ts +1 -1
  70. package/types/upload-dragger.type.d.ts +1 -1
  71. package/types/{upload-list.type-26173587.d.ts → upload-list.type-6189e4c9.d.ts} +7 -3
  72. package/types/upload-list.type.d.ts +1 -1
  73. package/types/upload.type.d.ts +1 -1
  74. package/types/user-head.type.d.ts +4 -0
  75. package/user-head/index.js +1 -1
  76. package/year-table/index.js +14 -29
  77. package/year-table/vue.js +17 -5
@@ -1,55 +1,40 @@
1
1
  import "../../chunk-G2ADBYYC.js";
2
2
  import { draggable } from "../utils/use-drag";
3
- import { onDrag, updateThumb } from ".";
4
- const api = ["state", "color", "slider", "alphaWrapper", "alphaThumb"];
5
- const renderless = (props, context, { emit }) => {
6
- const color = props.color;
7
- const [rr, gg, bb] = color.getRGB();
8
- const r = context.ref(rr);
9
- const g = context.ref(gg);
10
- const b = context.ref(bb);
11
- const slider = context.ref();
12
- const alphaWrapper = context.ref();
13
- const alphaThumb = context.ref();
14
- const alpha = context.ref(color.get("a"));
15
- context.watch(
16
- () => props.color,
17
- () => {
18
- const [rr2, gg2, bb2] = color.getRGB();
19
- r.value = rr2;
20
- g.value = gg2;
21
- b.value = bb2;
22
- alpha.value = color.get("a");
23
- },
24
- { deep: true }
25
- );
26
- context.watch(alpha, (newAlpha) => {
27
- updateThumb(newAlpha, alphaThumb.value, alphaWrapper.value);
28
- emit("alpha-update", alpha.value);
29
- });
30
- const background = context.computed(() => {
31
- return `linear-gradient(to right, rgba(${r.value}, ${g.value}, ${b.value}, 0) 0%, rgba(${r.value}, ${g.value}, ${b.value}, 1) 100%)`;
32
- });
33
- const state = context.reactive({
34
- background
3
+ import { initState, initWatch, useEvent } from ".";
4
+ const api = ["state", "color", "slider", "alphaWrapper", "alphaThumb", "onClick"];
5
+ const renderless = (props, hooks, utils) => {
6
+ const { onMounted, ref } = hooks;
7
+ const { emit } = utils;
8
+ const slider = ref();
9
+ const alphaWrapper = ref();
10
+ const alphaThumb = ref();
11
+ const state = initState(hooks);
12
+ const { update, onClick, onDrag } = useEvent(state, slider, alphaWrapper, alphaThumb, props);
13
+ onMounted(() => {
14
+ if (!slider.value || !alphaThumb.value) {
15
+ return;
16
+ }
17
+ const dragConfig = {
18
+ drag: (event) => {
19
+ onDrag(event);
20
+ },
21
+ end: (event) => {
22
+ onDrag(event);
23
+ }
24
+ };
25
+ draggable(slider.value, dragConfig);
26
+ draggable(alphaThumb.value, dragConfig);
27
+ update();
28
+ emit("ready", update);
35
29
  });
30
+ initWatch(props, update, hooks);
36
31
  const api2 = {
37
32
  state,
38
33
  slider,
39
34
  alphaWrapper,
40
- alphaThumb
35
+ alphaThumb,
36
+ onClick
41
37
  };
42
- context.onMounted(() => {
43
- updateThumb(alpha.value, alphaThumb.value, slider.value);
44
- draggable(slider.value, {
45
- drag(event) {
46
- onDrag(event, slider, alphaThumb, alpha);
47
- },
48
- start(event) {
49
- onDrag(event, slider, alphaThumb, alpha);
50
- }
51
- });
52
- });
53
38
  return api2;
54
39
  };
55
40
  export {
@@ -1,71 +1,57 @@
1
1
  import "../../chunk-G2ADBYYC.js";
2
- const setPosition = (el, x, y) => {
3
- el.style.top = `${y}px`;
4
- el.style.left = `${x}px`;
2
+ import { getClientXY } from "../utils/getClientXY";
3
+ const initState = (props, { reactive, ref, computed }) => {
4
+ const hueValue = computed(() => props.color.get("hue"));
5
+ const thumbTop = ref(0);
6
+ const state = reactive({ hueValue, thumbTop });
7
+ return state;
5
8
  };
6
- const getXBySaturation = (s, width) => s * width / 100;
7
- const getYByLight = (l, height) => (100 - l) * height / 100;
8
- const updatePosition = (event, rect, cursor) => {
9
- let x = event.clientX - rect.left;
10
- let y = event.clientY - rect.top;
11
- x = Math.max(0, x);
12
- x = Math.min(x, rect.width);
13
- y = Math.max(0, y);
14
- y = Math.min(y, rect.height);
15
- setPosition(cursor.value, x - 1 / 2 * cursor.value.offsetWidth, y - 1 / 2 * cursor.value.offsetWidth);
16
- return { x, y };
17
- };
18
- const calcSaturation = (x, width) => x / width;
19
- const calcBrightness = (y, height) => 100 - y / height * 100;
20
- const getThumbTop = (wrapper, thumb, hue) => {
21
- return Math.round(hue * (wrapper.offsetHeight - thumb.offsetHeight / 2) / 360);
22
- };
23
- const resetCursor = (s, v, wrapper, cursor, thumb, color, h) => {
24
- const { width, height } = wrapper.value.getBoundingClientRect();
25
- const x = getXBySaturation(s, width) - 1 / 2 * cursor.value.offsetWidth;
26
- const y = getYByLight(v, height) - 1 / 2 * cursor.value.offsetWidth;
27
- setPosition(cursor.value, x < 0 ? 0 : x, y < 0 ? 0 : y);
28
- const thummbTop = getThumbTop(wrapper.value, thumb.value, color.get("h"));
29
- thumb.value.style.top = `${thummbTop}px`;
30
- h.value = color.get("h");
31
- };
32
- const updateCursor = (wrapper, cursor, emit) => {
33
- return (color, event) => {
34
- const rect = wrapper.value.getBoundingClientRect();
35
- const { x, y } = updatePosition(event, rect, cursor);
36
- color.set({
37
- s: calcSaturation(x, rect.width) * 100,
38
- v: calcBrightness(y, rect.height),
39
- h: color.get("h")
40
- });
41
- emit("sv-update", {
42
- s: color.get("s"),
43
- v: color.get("v"),
44
- h: color.get("h")
45
- });
9
+ const initDom = ({ ref }) => {
10
+ return {
11
+ thumb: ref(),
12
+ bar: ref(),
13
+ wrapper: ref()
46
14
  };
47
15
  };
48
- const updateThumb = (bar, thumb, h, emit) => {
49
- return (event) => {
50
- const e = event;
51
- const rect = bar.value.getBoundingClientRect();
52
- let top = e.clientY - rect.top;
16
+ const useEvent = ({ thumb, bar }, state, props, { emit }) => {
17
+ const onSvReady = (update2) => {
18
+ emit("svReady", update2);
19
+ };
20
+ const getThumbTop = () => {
21
+ if (!thumb.value) {
22
+ return 0;
23
+ }
24
+ const hue = props.color.get("hue");
25
+ if (!bar.value) {
26
+ return 0;
27
+ }
28
+ return hue * (bar.value.offsetHeight - thumb.value.offsetHeight / 2) / 360;
29
+ };
30
+ const update = () => {
31
+ state.thumbTop = getThumbTop();
32
+ };
33
+ const onDrag = (event) => {
34
+ if (!bar.value || !thumb.value) {
35
+ return;
36
+ }
37
+ const el = bar.value;
38
+ if (!el) {
39
+ return;
40
+ }
41
+ const rect = el == null ? void 0 : el.getBoundingClientRect();
42
+ const { clientY } = getClientXY(event);
43
+ let top = clientY - rect.top;
53
44
  top = Math.min(top, rect.height - thumb.value.offsetHeight / 2);
54
45
  top = Math.max(thumb.value.offsetHeight / 2, top);
55
- thumb.value.style.top = `${top}px`;
56
- h.value = Math.round((top - thumb.value.offsetHeight / 2) / (rect.height - thumb.value.offsetHeight) * 360);
57
- emit("hue-update", h.value);
46
+ const hue = Math.round((top - thumb.value.offsetHeight / 2) / (rect.height - thumb.value.offsetHeight) * 360);
47
+ state.thumbTop = top;
48
+ emit("hueUpdate", hue);
49
+ props.color.set("hue", hue);
58
50
  };
51
+ return { update, onDrag, onSvReady };
59
52
  };
60
53
  export {
61
- calcBrightness,
62
- calcSaturation,
63
- getThumbTop,
64
- getXBySaturation,
65
- getYByLight,
66
- resetCursor,
67
- setPosition,
68
- updateCursor,
69
- updatePosition,
70
- updateThumb
54
+ initDom,
55
+ initState,
56
+ useEvent
71
57
  };
@@ -1,54 +1,36 @@
1
1
  import "../../chunk-G2ADBYYC.js";
2
2
  import { draggable } from "../utils/use-drag";
3
- import { getThumbTop, resetCursor, updateThumb, updateCursor } from "./index";
4
- const api = ["state", "cursor", "wrapper", "bar", "thumb"];
5
- const renderless = (props, context, { emit, expose }) => {
6
- const cursor = context.ref();
7
- const wrapper = context.ref();
8
- const thumb = context.ref();
9
- const bar = context.ref();
10
- const color = props.color;
11
- const h = context.ref(color.get("h"));
12
- const background = `hsl(${h.value}deg, 100%, 50%)`;
13
- const state = context.reactive({
14
- background
15
- });
16
- const api2 = { state, cursor, wrapper, bar, thumb };
17
- context.watch(
18
- () => props,
19
- () => {
20
- h.value = color.get("h");
21
- resetCursor(color.get("s"), color.get("v"), wrapper, cursor, thumb, color, h);
22
- },
23
- { deep: true }
24
- );
25
- context.watch(h, (newHue) => {
26
- state.background = `hsl(${newHue}deg, 100%, 50%)`;
27
- });
28
- context.onMounted(() => {
29
- const update = {
30
- thumb: updateThumb(bar, thumb, h, emit),
31
- cursor: updateCursor(wrapper, cursor, emit)
32
- };
33
- const thumbTop = getThumbTop(wrapper.value, thumb.value, h.value);
34
- thumb.value.style.top = `${thumbTop}px`;
35
- resetCursor(color.get("s"), color.get("v"), wrapper, cursor, thumb, color, h);
36
- draggable(wrapper.value, {
37
- drag(event) {
38
- update.cursor(color, event);
3
+ import { initDom, initState, useEvent } from ".";
4
+ const api = ["state", "onSvReady", "bar", "thumb", "wrapper"];
5
+ const renderless = (props, hooks, utils) => {
6
+ const { onMounted } = hooks;
7
+ const { emit } = utils;
8
+ const { thumb, bar, wrapper } = initDom(hooks);
9
+ const state = initState(props, hooks);
10
+ const { onSvReady, onDrag, update } = useEvent({ thumb, bar, wrapper }, state, props, utils);
11
+ const api2 = {
12
+ state,
13
+ onSvReady,
14
+ bar,
15
+ thumb,
16
+ wrapper
17
+ };
18
+ onMounted(() => {
19
+ if (!bar.value || !thumb.value) {
20
+ return;
21
+ }
22
+ const dragConfig = {
23
+ drag: (event) => {
24
+ onDrag(event);
39
25
  },
40
- start(event) {
41
- update.cursor(color, event);
26
+ end: (event) => {
27
+ onDrag(event);
42
28
  }
43
- });
44
- draggable(bar.value, {
45
- drag(event) {
46
- update.thumb(event);
47
- },
48
- start(event) {
49
- update.thumb(event);
50
- }
51
- });
29
+ };
30
+ draggable(bar.value, dragConfig);
31
+ draggable(thumb.value, dragConfig);
32
+ emit("hueReady", update);
33
+ update();
52
34
  });
53
35
  return api2;
54
36
  };
@@ -1,93 +1,243 @@
1
- import {
2
- __spreadProps,
3
- __spreadValues
4
- } from "../chunk-G2ADBYYC.js";
5
- import Color from "./utils/color";
6
- const onConfirm = (hex, pre, res, emit, stack, enableHistory, color) => {
7
- return () => {
8
- pre.value = hex.value;
9
- hex.value = res.value;
10
- if (enableHistory) {
11
- const itemIdx = Math.max(
12
- stack.value.indexOf(res.value),
13
- stack.value.indexOf(res.value.toLowerCase()),
14
- stack.value.indexOf(res.value.toUpperCase())
15
- );
16
- if (itemIdx !== -1) {
17
- stack.value.splice(itemIdx, 1);
1
+ import "../chunk-G2ADBYYC.js";
2
+ import { Color } from "./utils/color";
3
+ const panelRgb = (color, alpha) => {
4
+ const { r, g, b } = color.toRgb();
5
+ return alpha ? `rgba(${r},${g},${b},${color.get("alpha") / 100})` : `rgb(${r},${g},${b})`;
6
+ };
7
+ const updateModelValue = (value, emit) => {
8
+ emit("update:modelValue", value);
9
+ };
10
+ const triggerCancel = (value, emit) => {
11
+ emit("cancel");
12
+ };
13
+ const triggerColorUpdate = (value, emit) => {
14
+ emit("color-update", value);
15
+ };
16
+ const triggerConfirm = (value, emit) => {
17
+ emit("confirm", value);
18
+ };
19
+ const initApi = (props, state, { emit, nextTick }) => {
20
+ const setShowPicker = (value) => state.showPicker = value;
21
+ const resetColor = () => {
22
+ nextTick(() => {
23
+ if (props.modelValue) {
24
+ state.color.fromString(props.modelValue);
25
+ } else {
26
+ state.color.value = "";
27
+ nextTick(() => {
28
+ state.showPanel = false;
29
+ });
18
30
  }
19
- stack.value.unshift(res.value);
20
- }
21
- color.value.setPrevH(color.value.get("h"));
22
- emit("confirm", res.value);
23
- emit("update:modelValue", res.value);
31
+ });
24
32
  };
25
- };
26
- const onCancel = (res, pre, emit, isShow, hex, color) => {
27
- return () => {
28
- if (isShow.value) {
29
- res.value = pre.value;
30
- hex.value = pre.value;
31
- const tmpColor = new Color(pre.value);
32
- color.value.set(__spreadProps(__spreadValues({}, tmpColor.getHSV()), {
33
- h: color.value.get("preH")
34
- }));
35
- emit("cancel", color);
33
+ const submitValue = () => {
34
+ const value = state.color.value;
35
+ updateModelValue(value, emit);
36
+ triggerConfirm(value, emit);
37
+ setShowPicker(false);
38
+ nextTick(() => {
39
+ var _a;
40
+ const newColor = new Color({
41
+ enableAlpha: props.alpha,
42
+ format: (_a = state.currentFormat) != null ? _a : "",
43
+ value: props.modelValue
44
+ });
45
+ if (!state.color.compare(newColor)) {
46
+ resetColor();
47
+ }
48
+ });
49
+ };
50
+ const onConfirm = () => {
51
+ submitValue();
52
+ if (!state.enableHistory) {
53
+ return;
54
+ }
55
+ let index = state.stack.indexOf(state.input);
56
+ if (index === -1) {
57
+ state.stack.push(state.input);
58
+ } else {
59
+ state.stack = [state.input, ...state.stack.filter((c, i) => i !== index)];
36
60
  }
37
- emit("update:modelValue", hex.value);
38
61
  };
39
- };
40
- const onColorUpdate = (color, res, emit) => {
41
- res.value = color.value.getHex();
42
- emit("update:modelValue", res.value);
43
- };
44
- const onHSVUpdate = (color, res, hex, emit) => {
45
- return {
46
- onHueUpdate: (hue) => {
47
- color.value.set({ h: hue });
48
- onColorUpdate(color, res, emit);
49
- hex.value = color.value.getHex();
50
- emit("hue-update", hue);
51
- },
52
- onSVUpdate: ({ s, v }) => {
53
- hex.value = color.value.getHex();
54
- onColorUpdate(color, res, emit);
55
- emit("sv-update", { s, v });
62
+ const onCancel = () => {
63
+ resetColor();
64
+ close();
65
+ emit("cancel");
66
+ };
67
+ const clear = () => {
68
+ updateModelValue(null, emit);
69
+ triggerCancel(null, emit);
70
+ resetColor();
71
+ };
72
+ const onClickOutside = () => {
73
+ if (!state.showPicker) {
74
+ return;
56
75
  }
76
+ close();
77
+ resetColor();
78
+ emit("cancel");
79
+ };
80
+ const onHueReady = (update) => {
81
+ state.hue = { update };
82
+ };
83
+ const onSvReady = (update) => {
84
+ state.sv = { update };
85
+ };
86
+ const onAlphaReady = (update) => {
87
+ state.alpha = { update };
88
+ };
89
+ const open = () => {
90
+ setShowPicker(true);
91
+ };
92
+ const close = () => {
93
+ setShowPicker(false);
94
+ };
95
+ const onHistoryClick = (historyColor) => {
96
+ state.color.fromString(historyColor);
97
+ };
98
+ const onPredefineColorClick = (predefineColor) => {
99
+ state.color.fromString(predefineColor);
57
100
  };
58
- };
59
- const onAlphaUpdate = (color, res, emit) => {
60
101
  return {
61
- update: (alpha) => {
62
- color.value.set({ a: alpha });
63
- onColorUpdate(color, res, emit);
64
- }
102
+ open,
103
+ close,
104
+ resetColor,
105
+ onConfirm,
106
+ onCancel,
107
+ submitValue,
108
+ clear,
109
+ onHueReady,
110
+ onSvReady,
111
+ onAlphaReady,
112
+ onPredefineColorClick,
113
+ onHistoryClick,
114
+ onClickOutside
65
115
  };
66
116
  };
67
- const handleHistoryClick = (hex, res, color, emit) => {
68
- return (history) => {
69
- hex.value = history;
70
- res.value = history;
71
- const tmpColor = new Color(history);
72
- color.value.set(__spreadValues({}, tmpColor.getHSV()));
73
- emit("color-update", color);
74
- };
117
+ const initState = (props, { reactive, ref, computed }) => {
118
+ var _a, _b;
119
+ const stack = ref([...(_a = props.history) != null ? _a : []]);
120
+ const predefineStack = computed(() => props.predefine);
121
+ const hue = ref();
122
+ const sv = ref();
123
+ const alpha = ref();
124
+ const currentFormat = ref(props.format[0]);
125
+ const color = reactive(
126
+ new Color({
127
+ enableAlpha: props.alpha,
128
+ format: (_b = currentFormat.value) != null ? _b : "hex",
129
+ value: props.modelValue
130
+ })
131
+ );
132
+ const input = ref("");
133
+ const showPicker = ref(props.visible);
134
+ const showPanel = ref(false);
135
+ const panelColor = computed(() => {
136
+ if (!props.modelValue && !showPanel.value) {
137
+ return "transparent";
138
+ }
139
+ return panelRgb(color, props.alpha);
140
+ });
141
+ const currentColor = computed(() => !props.modelValue && !showPicker.value ? "" : color.value);
142
+ const state = reactive({
143
+ color,
144
+ input,
145
+ showPicker,
146
+ showPanel,
147
+ panelColor,
148
+ currentColor,
149
+ hue,
150
+ sv,
151
+ alpha,
152
+ stack,
153
+ predefineStack,
154
+ enablePredefineColor: computed(() => props.enablePredefineColor),
155
+ enableHistory: computed(() => props.enableHistory),
156
+ currentFormat,
157
+ formats: props.format
158
+ });
159
+ return state;
75
160
  };
76
- const handlePredefineClick = (hex, res, color, emit) => {
77
- return (selectedColor) => {
78
- hex.value = selectedColor;
79
- res.value = selectedColor;
80
- const tmpColor = new Color(selectedColor);
81
- color.value.set(__spreadValues({}, tmpColor.getHSV()));
82
- emit("color-update", color);
83
- };
161
+ const initWatch = (state, props, { nextTick, watch }, { emit }) => {
162
+ watch(
163
+ () => state.color,
164
+ () => {
165
+ emit("color-update", state.color);
166
+ }
167
+ );
168
+ watch(
169
+ () => props.visible,
170
+ () => {
171
+ state.showPicker = props.visible;
172
+ }
173
+ );
174
+ watch(
175
+ () => props.modelValue,
176
+ () => {
177
+ if (!props.modelValue) {
178
+ state.showPanel = false;
179
+ }
180
+ if (props.modelValue && props.modelValue !== state.color.value) {
181
+ state.color.fromString(props.modelValue);
182
+ }
183
+ }
184
+ );
185
+ watch(
186
+ () => [state.currentFormat, props.alpha],
187
+ () => {
188
+ state.color.enableAlpha = props.alpha;
189
+ state.color.format = state.currentFormat || state.color.format;
190
+ state.color.onChange();
191
+ updateModelValue(state.color.value, emit);
192
+ }
193
+ );
194
+ watch(
195
+ () => state.currentColor,
196
+ () => {
197
+ state.input = state.currentColor;
198
+ triggerColorUpdate(state.input, emit);
199
+ },
200
+ { flush: "sync" }
201
+ );
202
+ watch(state.color, () => {
203
+ if (!props.modelValue && !state.showPanel) {
204
+ state.showPanel = true;
205
+ }
206
+ });
207
+ watch(
208
+ () => state.showPicker,
209
+ () => {
210
+ nextTick(() => {
211
+ if (state.hue) {
212
+ state.hue.update();
213
+ }
214
+ if (state.sv) {
215
+ state.sv.update();
216
+ }
217
+ if (state.alpha) {
218
+ state.alpha.update();
219
+ }
220
+ });
221
+ }
222
+ );
223
+ watch(
224
+ () => props.history,
225
+ () => {
226
+ if (!state.enableHistory) {
227
+ return;
228
+ }
229
+ state.stack = props.history;
230
+ },
231
+ { deep: true }
232
+ );
84
233
  };
85
234
  export {
86
- handleHistoryClick,
87
- handlePredefineClick,
88
- onAlphaUpdate,
89
- onCancel,
90
- onColorUpdate,
91
- onConfirm,
92
- onHSVUpdate
235
+ initApi,
236
+ initState,
237
+ initWatch,
238
+ panelRgb,
239
+ triggerCancel,
240
+ triggerColorUpdate,
241
+ triggerConfirm,
242
+ updateModelValue
93
243
  };
@@ -0,0 +1,68 @@
1
+ import "../../chunk-G2ADBYYC.js";
2
+ import { getClientXY } from "../utils/getClientXY";
3
+ const initState = (props, { ref, computed, reactive }) => {
4
+ const cursorTop = ref(0);
5
+ const cursorLeft = ref(0);
6
+ const bg = ref("hsl(0, 100%, 50%)");
7
+ const colorValue = computed(() => {
8
+ const hue = props.color.get("hue");
9
+ const value = props.color.get("value");
10
+ return { hue, value };
11
+ });
12
+ const state = reactive({
13
+ colorValue,
14
+ bg,
15
+ cursorLeft,
16
+ cursorTop
17
+ });
18
+ return state;
19
+ };
20
+ const useUpdate = (state, props, wrapper) => {
21
+ return () => {
22
+ const el = wrapper.value;
23
+ if (!el) {
24
+ return;
25
+ }
26
+ const sat = props.color.get("sat");
27
+ const value = props.color.get("value");
28
+ const { clientWidth: width, clientHeight: height } = el;
29
+ state.cursorLeft = sat * width / 100;
30
+ state.cursorTop = (100 - value) * height / 100;
31
+ state.bg = `hsl(${props.color.get("hue")}, 100%, 50%)`;
32
+ };
33
+ };
34
+ const useDrag = (state, wrapper, props, { emit }) => {
35
+ return (event) => {
36
+ const el = wrapper.value;
37
+ const rect = el.getBoundingClientRect();
38
+ const { clientX, clientY } = getClientXY(event);
39
+ let left = clientX - rect.left;
40
+ let top = clientY - rect.top;
41
+ left = Math.max(0, left);
42
+ left = Math.min(left, rect.width);
43
+ top = Math.max(0, top);
44
+ top = Math.min(top, rect.height);
45
+ state.cursorLeft = Math.max(left, 0);
46
+ state.cursorTop = Math.max(top, 0);
47
+ const s = left / rect.width * 100;
48
+ const v = 100 - top / rect.height * 100;
49
+ emit("svUpdate", { s, v });
50
+ props.color.set({
51
+ sat: s,
52
+ value: v
53
+ });
54
+ };
55
+ };
56
+ const initWatch = (state, update, { watch }) => {
57
+ watch(
58
+ () => state.colorValue.value,
59
+ () => update(),
60
+ { deep: true }
61
+ );
62
+ };
63
+ export {
64
+ initState,
65
+ initWatch,
66
+ useDrag,
67
+ useUpdate
68
+ };