@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.
- package/base-select/index.js +11 -74
- package/base-select/vue.js +10 -10
- package/bulletin-board/index.js +5 -1
- package/bulletin-board/vue.js +5 -4
- package/button/index.js +11 -3
- package/button/vue.js +6 -2
- package/button-group/index.js +1 -1
- package/color-picker/index.js +4 -4
- package/color-picker/utils/color.js +358 -83
- package/color-picker/utils/hsv-to-rgb.js +59 -0
- package/color-picker/vue.js +27 -8
- package/color-select-panel/alpha-select/index.js +65 -14
- package/color-select-panel/alpha-select/vue.js +29 -44
- package/color-select-panel/hue-select/index.js +47 -61
- package/color-select-panel/hue-select/vue.js +29 -47
- package/color-select-panel/index.js +230 -80
- package/color-select-panel/sv-select/index.js +68 -0
- package/color-select-panel/sv-select/vue.js +32 -0
- package/color-select-panel/utils/color.js +345 -82
- package/color-select-panel/utils/getClientXY.js +54 -0
- package/color-select-panel/vue.js +47 -72
- package/common/deps/popper.js +1 -1
- package/common/deps/useUserAgent.js +16 -0
- package/common/event.js +21 -0
- package/common/index.js +1 -1
- package/common/runtime.js +1 -1
- package/date-picker-mobile/index.js +4 -4
- package/dialog-box/index.js +1 -1
- package/dropdown/index.js +5 -1
- package/dropdown/vue.js +2 -2
- package/file-upload/vue.js +1 -0
- package/flowchart/index.js +3 -2
- package/form/index.js +2 -2
- package/form-item/index.js +4 -1
- package/grid-select/index.js +82 -0
- package/grid-select/vue.js +30 -0
- package/input/index.js +2 -2
- package/menu/vue.js +5 -1
- package/modal/index.js +2 -0
- package/numeric/index.js +29 -9
- package/option/index.js +6 -0
- package/option/vue.js +12 -2
- package/package.json +1 -1
- package/picker/index.js +1 -1
- package/recycle-scroller/index.js +43 -27
- package/recycle-scroller/vue.js +9 -4
- package/rich-text/index.js +13 -0
- package/rich-text/vue.js +4 -2
- package/select/index.js +71 -23
- package/select/vue.js +12 -4
- package/select-dropdown/vue.js +1 -1
- package/tabbar/index.js +4 -1
- package/tabbar/vue.js +1 -1
- package/tabs/index.js +8 -5
- package/tabs/vue.js +4 -1
- package/time-panel/vue.js +1 -1
- package/tooltip/vue.js +1 -0
- package/tree-menu/index.js +5 -1
- package/tree-node/index.js +5 -4
- package/tree-select/index.js +77 -1
- package/tree-select/vue.js +21 -7
- package/types/button.type.d.ts +7 -3
- package/types/color-select-panel.type.d.ts +23 -1
- package/types/file-upload.type.d.ts +1 -1
- package/types/input.type.d.ts +1 -1
- package/types/numeric.type.d.ts +5 -5
- package/types/popover.type.d.ts +1 -1
- package/types/transfer.type.d.ts +3 -3
- package/types/tree-menu.type.d.ts +1 -1
- package/types/upload-dragger.type.d.ts +1 -1
- package/types/{upload-list.type-26173587.d.ts → upload-list.type-6189e4c9.d.ts} +7 -3
- package/types/upload-list.type.d.ts +1 -1
- package/types/upload.type.d.ts +1 -1
- package/types/user-head.type.d.ts +4 -0
- package/user-head/index.js +1 -1
- package/year-table/index.js +14 -29
- 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 {
|
|
4
|
-
const api = ["state", "color", "slider", "alphaWrapper", "alphaThumb"];
|
|
5
|
-
const renderless = (props,
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
emit("
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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.
|
|
56
|
-
|
|
57
|
-
emit("
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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 {
|
|
4
|
-
const api = ["state", "
|
|
5
|
-
const renderless = (props,
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const thumb =
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
()
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
41
|
-
|
|
26
|
+
end: (event) => {
|
|
27
|
+
onDrag(event);
|
|
42
28
|
}
|
|
43
|
-
}
|
|
44
|
-
draggable(bar.value,
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
+
};
|