@opentiny/vue-renderless 3.25.0 → 3.27.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 (67) hide show
  1. package/calendar-view/index.js +6 -3
  2. package/calendar-view/vue.js +9 -5
  3. package/color-picker/vue.js +4 -0
  4. package/color-select-panel/alpha-select/index.js +17 -12
  5. package/color-select-panel/alpha-select/vue.js +4 -2
  6. package/color-select-panel/hue-select/index.js +47 -16
  7. package/color-select-panel/hue-select/vue.js +32 -6
  8. package/color-select-panel/index.js +236 -8
  9. package/color-select-panel/linear-gradient/index.js +131 -0
  10. package/color-select-panel/linear-gradient/vue.js +21 -0
  11. package/color-select-panel/sv-select/index.js +12 -9
  12. package/color-select-panel/sv-select/vue.js +4 -2
  13. package/color-select-panel/utils/color-map.js +154 -0
  14. package/color-select-panel/utils/color-points.js +86 -0
  15. package/color-select-panel/utils/color.js +1 -1
  16. package/color-select-panel/utils/context.js +14 -0
  17. package/color-select-panel/vue.js +9 -4
  18. package/common/deps/infinite-scroll.js +1 -1
  19. package/dialog-box/index.js +3 -3
  20. package/dialog-box/vue.js +1 -0
  21. package/dropdown/vue.js +3 -1
  22. package/file-upload/index.js +3 -2
  23. package/file-upload/vue.js +1 -1
  24. package/fluent-editor/index.js +1 -1
  25. package/form-item/vue.js +1 -1
  26. package/guide/index.js +3 -3
  27. package/input/index.js +2 -1
  28. package/input/vue.js +2 -1
  29. package/package.json +3 -3
  30. package/pager/vue.js +1 -1
  31. package/picker/vue.js +10 -0
  32. package/popeditor/index.js +3 -3
  33. package/search/index.js +6 -2
  34. package/search/vue.js +1 -1
  35. package/select/index.js +30 -13
  36. package/select/vue.js +34 -10
  37. package/slider/vue.js +7 -0
  38. package/slider-button/vue.js +1 -0
  39. package/slider-button-group/vue.js +1 -0
  40. package/space/index.js +30 -0
  41. package/space/vue.js +39 -0
  42. package/tab-nav/index.js +2 -2
  43. package/tabs/vue.js +2 -1
  44. package/tabs-mf/index.js +4 -1
  45. package/tabs-mf/vue-nav.js +9 -18
  46. package/tabs-mf/vue-slider-bar.js +24 -0
  47. package/tabs-mf/vue.js +3 -1
  48. package/tag/index.js +1 -1
  49. package/tree-menu/index.js +4 -0
  50. package/tree-menu/vue.js +3 -0
  51. package/types/button-group.type.d.ts +2 -1
  52. package/types/button.type.d.ts +2 -1
  53. package/types/color-select-panel.type.d.ts +197 -1
  54. package/types/dialog-box.type.d.ts +4 -11
  55. package/types/numeric.type.d.ts +1 -1
  56. package/types/pager.type.d.ts +2 -1
  57. package/types/picker.type.d.ts +4 -0
  58. package/types/radio-button.type.d.ts +1 -0
  59. package/types/radio-group.type.d.ts +2 -1
  60. package/types/radio.type.d.ts +2 -1
  61. package/types/slider.type.d.ts +2 -1
  62. package/types/space.type.d.ts +31 -0
  63. package/types/switch.type.d.ts +1 -1
  64. package/types/tabs.type.d.ts +2 -0
  65. package/types/user-contact.type.d.ts +1 -11
  66. package/user/index.js +6 -5
  67. package/user/vue.js +1 -1
@@ -426,15 +426,18 @@ const toToday = ({ state, api, nextTick }) => () => {
426
426
  });
427
427
  }
428
428
  };
429
- const currentDateChange = ({ state, api }) => (date) => {
429
+ const currentDateChange = ({ state, api, nextTick }) => (date) => {
430
430
  const currentDate = new Date(date);
431
431
  const year = currentDate.getFullYear();
432
432
  const month = currentDate.getMonth() + 1;
433
+ const day = currentDate.getDate();
433
434
  state.activeMonth = month;
434
435
  state.activeYear = year;
436
+ state.currentDate = `${year}-${month}-${day}`;
435
437
  if (state.mode !== "month") {
436
- api.getAllWednesdaysInMonth(currentDate);
437
- api.getAllDatesOfCurrWeek(state.monthWednesdays[0]);
438
+ nextTick(() => {
439
+ api.initWeeklyCalendar(currentDate);
440
+ });
438
441
  }
439
442
  };
440
443
  const getAllWednesdaysInYear = ({ state }) => (year) => {
@@ -123,11 +123,12 @@ const initState = ({ reactive, props, computed, api: api2, images, modesIcon })
123
123
  multiSelect: computed(() => props.multiSelect),
124
124
  cascaderVisible: false,
125
125
  eventTipContent: {},
126
- activeYear: props.year,
126
+ activeYear: props.year || (/* @__PURE__ */ new Date()).getFullYear(),
127
127
  displayMode: props.mode,
128
- activeMonth: props.month,
129
- currentDate: props.year + "-" + props.month,
130
- cascaderCurrent: [props.year || (/* @__PURE__ */ new Date()).getFullYear(), props.month || (/* @__PURE__ */ new Date()).getMonth + 1],
128
+ activeMonth: props.month || (/* @__PURE__ */ new Date()).getMonth() + 1,
129
+ dateType: computed(() => !props.day ? "month" : "date"),
130
+ currentDate: props.year && props.month && props.day ? `${props.year}-${props.month}-${props.day}` : props.year && props.month ? `${props.year}-${props.month}` : `${(/* @__PURE__ */ new Date()).getFullYear()}-${(/* @__PURE__ */ new Date()).getMonth() + 1}-${(/* @__PURE__ */ new Date()).getDate()}`,
131
+ cascaderCurrent: [props.year || (/* @__PURE__ */ new Date()).getFullYear(), props.month || (/* @__PURE__ */ new Date()).getMonth() + 1],
131
132
  cascaderOptions: computed(() => api2.computeCascaderOptions()),
132
133
  calendar: computed(() => api2.computedCalendar("cur")),
133
134
  prevCalendar: computed(() => api2.computedCalendar("prev")),
@@ -153,6 +154,9 @@ const initWatch = ({ watch, props, state, emit, api: api2, nextTick }) => {
153
154
  () => state.mode,
154
155
  (val) => {
155
156
  emit("mode-change", val);
157
+ if (val !== "month") {
158
+ api2.getAllDatesOfCurrWeek(state.currentDate);
159
+ }
156
160
  if (val === "schedule") {
157
161
  api2.getCurWeekEvent();
158
162
  }
@@ -266,7 +270,7 @@ const initApi = ({ vm, api: api2, state, t, props, emit, nextTick }) => {
266
270
  initWeeklyCalendar: initWeeklyCalendar({ api: api2, state }),
267
271
  getDatesOfPreviousWeek: getDatesOfPreviousWeek({ api: api2, state }),
268
272
  getDatesOfNextWeek: getDatesOfNextWeek({ api: api2, state }),
269
- currentDateChange: currentDateChange({ api: api2, state }),
273
+ currentDateChange: currentDateChange({ api: api2, state, nextTick }),
270
274
  newSchedule: newSchedule({ emit }),
271
275
  getPrevWeek: throttle(50, true, getPrevWeek({ api: api2, state, emit })),
272
276
  getNextWeek: throttle(50, true, getNextWeek({ api: api2, state, emit })),
@@ -50,6 +50,10 @@ const renderless = (props, ctx, { emit }) => {
50
50
  ctx.watch(
51
51
  () => props.modelValue,
52
52
  () => {
53
+ if (props.colorMode === "linear-gradient") {
54
+ state.hex = props.modelValue;
55
+ return;
56
+ }
53
57
  color.fromString(props.modelValue);
54
58
  const { r, g, b, a } = color.toRgba();
55
59
  state.hex = `rgba(${r}, ${g}, ${b}, ${a})`;
@@ -1,12 +1,15 @@
1
1
  import "../../chunk-G2ADBYYC.js";
2
2
  import { getClientXY } from "../utils/getClientXY";
3
- const initState = ({ ref, reactive }) => {
4
- const background = ref("");
3
+ import { useContext } from "../utils/context";
4
+ const initState = (hooks) => {
5
+ const { ref, reactive } = hooks;
6
+ const ctx = useContext(hooks);
7
+ const background = ref(ctx.activeColor.value.color.value);
5
8
  const left = ref(0);
6
- const state = reactive({ background, left });
9
+ const state = reactive({ background, left, activeColor: ctx.activeColor });
7
10
  return state;
8
11
  };
9
- const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
12
+ const useEvent = (state, slider, alphaWrapper, alphaThumb, props, ctx) => {
10
13
  const onDrag = (event) => {
11
14
  if (!slider.value || !alphaThumb.value) {
12
15
  return;
@@ -20,7 +23,7 @@ const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
20
23
  const alpha = Math.round(
21
24
  (left - alphaThumb.value.offsetWidth / 2) / (rect.width - alphaThumb.value.offsetWidth) * 100
22
25
  );
23
- props.color.set("alpha", alpha);
26
+ ctx.activeColor.value.color.set("alpha", alpha);
24
27
  };
25
28
  const onClick = (event) => {
26
29
  if (event.target !== alphaThumb.value) {
@@ -36,12 +39,12 @@ const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
36
39
  if (!el) {
37
40
  return 0;
38
41
  }
39
- const alpha = props.color.get("alpha");
42
+ const alpha = ctx.activeColor.value.color.get("alpha");
40
43
  return alpha * (el.offsetWidth - thumb.offsetWidth / 2) / 100;
41
44
  };
42
45
  const getBackground = () => {
43
- if (props.color && props.color.value) {
44
- const { r, g, b } = props.color.toRgb();
46
+ if (ctx.activeColor && ctx.activeColor.value) {
47
+ const { r, g, b } = ctx.activeColor.value.color.toRgb();
45
48
  return `linear-gradient(to right, rgba(${r}, ${g}, ${b}, 0) 0%, rgba(${r}, ${g}, ${b}, 1) 100%)`;
46
49
  }
47
50
  return "";
@@ -52,14 +55,16 @@ const useEvent = (state, slider, alphaWrapper, alphaThumb, props) => {
52
55
  };
53
56
  return { onDrag, onClick, update };
54
57
  };
55
- const initWatch = (props, update, { watch }) => {
58
+ const initWatch = (props, update, { watch }, ctx) => {
56
59
  watch(
57
- () => props.color.get("alpha"),
58
- () => update(),
60
+ () => ctx.activeColor.value.color,
61
+ () => {
62
+ update();
63
+ },
59
64
  { deep: true }
60
65
  );
61
66
  watch(
62
- () => props.color,
67
+ () => ctx.activeColor,
63
68
  () => update(),
64
69
  { deep: true }
65
70
  );
@@ -1,6 +1,7 @@
1
1
  import "../../chunk-G2ADBYYC.js";
2
2
  import { draggable } from "../utils/use-drag";
3
3
  import { initState, initWatch, useEvent } from ".";
4
+ import { useContext } from "../utils/context";
4
5
  const api = ["state", "color", "slider", "alphaWrapper", "alphaThumb", "onClick"];
5
6
  const renderless = (props, hooks, utils) => {
6
7
  const { onMounted, ref } = hooks;
@@ -8,8 +9,9 @@ const renderless = (props, hooks, utils) => {
8
9
  const slider = ref();
9
10
  const alphaWrapper = ref();
10
11
  const alphaThumb = ref();
12
+ const ctx = useContext(hooks);
11
13
  const state = initState(hooks);
12
- const { update, onClick, onDrag } = useEvent(state, slider, alphaWrapper, alphaThumb, props);
14
+ const { update, onClick, onDrag } = useEvent(state, slider, alphaWrapper, alphaThumb, props, ctx);
13
15
  onMounted(() => {
14
16
  if (!slider.value || !alphaThumb.value) {
15
17
  return;
@@ -27,7 +29,7 @@ const renderless = (props, hooks, utils) => {
27
29
  update();
28
30
  emit("ready", update);
29
31
  });
30
- initWatch(props, update, hooks);
32
+ initWatch(props, update, hooks, ctx);
31
33
  const api2 = {
32
34
  state,
33
35
  slider,
@@ -1,9 +1,28 @@
1
1
  import "../../chunk-G2ADBYYC.js";
2
+ import { Color } from "../utils/color";
2
3
  import { getClientXY } from "../utils/getClientXY";
3
- const initState = (props, { reactive, ref, computed }) => {
4
+ import { useContext } from "../utils/context";
5
+ import { ColorPoint } from "../utils/color-points";
6
+ const useOnClickBar = ({ addPoint, setActivePoint, getActviePoint }, { bar }, getLeft) => {
7
+ return (event) => {
8
+ const activePoint = getActviePoint().value;
9
+ const color = new Color({
10
+ enableAlpha: activePoint.color.enableAlpha,
11
+ format: activePoint.color.format,
12
+ value: activePoint.color.value
13
+ });
14
+ const left = getLeft(bar.value, event);
15
+ const colorPoint = new ColorPoint(color, left);
16
+ addPoint(colorPoint);
17
+ setActivePoint(colorPoint);
18
+ };
19
+ };
20
+ const initState = (props, hooks) => {
21
+ const { reactive, ref, computed } = hooks;
22
+ const ctx = useContext(hooks);
4
23
  const hueValue = computed(() => props.color.get("hue"));
5
- const thumbTop = ref(0);
6
- const state = reactive({ hueValue, thumbTop });
24
+ const thumbLeft = ref(0);
25
+ const state = reactive({ hueValue, thumbLeft, ctx });
7
26
  return state;
8
27
  };
9
28
  const initDom = ({ ref }) => {
@@ -13,7 +32,7 @@ const initDom = ({ ref }) => {
13
32
  wrapper: ref()
14
33
  };
15
34
  };
16
- const useEvent = ({ thumb, bar }, state, props, { emit }) => {
35
+ const useEvent = ({ thumb, bar }, state, props, { emit }, ctx) => {
17
36
  const onSvReady = (update2) => {
18
37
  emit("svReady", update2);
19
38
  };
@@ -21,14 +40,28 @@ const useEvent = ({ thumb, bar }, state, props, { emit }) => {
21
40
  if (!thumb.value) {
22
41
  return 0;
23
42
  }
24
- const hue = props.color.get("hue");
43
+ const hue = ctx.activeColor.value.color.get("hue");
25
44
  if (!bar.value) {
26
45
  return 0;
27
46
  }
28
- return hue * (bar.value.offsetHeight - thumb.value.offsetHeight / 2) / 360;
47
+ return hue * (bar.value.offsetWidth - thumb.value.offsetWidth / 2) / 360;
29
48
  };
30
49
  const update = () => {
31
- state.thumbTop = getThumbTop();
50
+ state.thumbLeft = getThumbTop();
51
+ if (ctx.colorMode.value !== "linear-gradient") {
52
+ ctx.activeColor.value.cursorLeft = state.thumbLeft;
53
+ }
54
+ };
55
+ const getLeft = (barEl, event) => {
56
+ if (!thumb.value) {
57
+ return 0;
58
+ }
59
+ const rect = barEl == null ? void 0 : barEl.getBoundingClientRect();
60
+ const { clientX } = getClientXY(event);
61
+ let left = clientX - rect.left;
62
+ left = Math.min(left, rect.width - thumb.value.offsetWidth / 2);
63
+ left = Math.max(thumb.value.offsetWidth / 2, left);
64
+ return left;
32
65
  };
33
66
  const onDrag = (event) => {
34
67
  if (!bar.value || !thumb.value) {
@@ -38,20 +71,18 @@ const useEvent = ({ thumb, bar }, state, props, { emit }) => {
38
71
  if (!el) {
39
72
  return;
40
73
  }
74
+ const left = getLeft(el, event);
41
75
  const rect = el == null ? void 0 : el.getBoundingClientRect();
42
- const { clientY } = getClientXY(event);
43
- let top = clientY - rect.top;
44
- top = Math.min(top, rect.height - thumb.value.offsetHeight / 2);
45
- top = Math.max(thumb.value.offsetHeight / 2, top);
46
- const hue = Math.round((top - thumb.value.offsetHeight / 2) / (rect.height - thumb.value.offsetHeight) * 360);
47
- state.thumbTop = top;
76
+ const hue = Math.round((left - thumb.value.offsetWidth / 2) / (rect.width - thumb.value.offsetWidth) * 360);
77
+ state.thumbLeft = left;
48
78
  emit("hueUpdate", hue);
49
- props.color.set("hue", hue);
79
+ ctx.activeColor.value.color.set("hue", hue);
50
80
  };
51
- return { update, onDrag, onSvReady };
81
+ return { update, onDrag, onSvReady, getLeft, getThumbTop };
52
82
  };
53
83
  export {
54
84
  initDom,
55
85
  initState,
56
- useEvent
86
+ useEvent,
87
+ useOnClickBar
57
88
  };
@@ -1,19 +1,38 @@
1
- import "../../chunk-G2ADBYYC.js";
1
+ import {
2
+ __objRest,
3
+ __spreadValues
4
+ } from "../../chunk-G2ADBYYC.js";
2
5
  import { draggable } from "../utils/use-drag";
3
- import { initDom, initState, useEvent } from ".";
4
- const api = ["state", "onSvReady", "bar", "thumb", "wrapper"];
6
+ import { initDom, initState, useEvent, useOnClickBar } from ".";
7
+ import { useContext } from "../utils/context";
8
+ import { useColorPoints } from "../utils/color-points";
9
+ const api = ["state", "onSvReady", "bar", "thumb", "wrapper", "onClickBar"];
5
10
  const renderless = (props, hooks, utils) => {
6
- const { onMounted } = hooks;
11
+ const { onMounted, watch } = hooks;
7
12
  const { emit } = utils;
8
13
  const { thumb, bar, wrapper } = initDom(hooks);
9
14
  const state = initState(props, hooks);
10
- const { onSvReady, onDrag, update } = useEvent({ thumb, bar, wrapper }, state, props, utils);
15
+ const ctx = useContext(hooks);
16
+ const { onSvReady, onDrag, update, getLeft, getThumbTop } = useEvent(
17
+ { thumb, bar, wrapper },
18
+ state,
19
+ props,
20
+ utils,
21
+ ctx
22
+ );
23
+ const _a = useColorPoints(
24
+ { wrapper: bar, points: [ctx.activeColor.value] },
25
+ hooks,
26
+ ctx
27
+ ), { addPoint, setActivePoint } = _a, rest = __objRest(_a, ["addPoint", "setActivePoint"]);
28
+ const onClickBar = useOnClickBar(__spreadValues({ addPoint, setActivePoint }, rest), { bar, thumb, wrapper }, getLeft);
11
29
  const api2 = {
12
30
  state,
13
31
  onSvReady,
14
32
  bar,
15
33
  thumb,
16
- wrapper
34
+ wrapper,
35
+ onClickBar
17
36
  };
18
37
  onMounted(() => {
19
38
  if (!bar.value || !thumb.value) {
@@ -32,6 +51,13 @@ const renderless = (props, hooks, utils) => {
32
51
  emit("hueReady", update);
33
52
  update();
34
53
  });
54
+ watch(
55
+ () => ctx.activeColor.value.color,
56
+ () => {
57
+ state.thumbLeft = getThumbTop();
58
+ },
59
+ { immediate: true, deep: true }
60
+ );
35
61
  return api2;
36
62
  };
37
63
  export {
@@ -1,5 +1,11 @@
1
- import "../chunk-G2ADBYYC.js";
1
+ import {
2
+ __spreadProps,
3
+ __spreadValues
4
+ } from "../chunk-G2ADBYYC.js";
5
+ import colors from "./utils/color-map";
2
6
  import { Color } from "./utils/color";
7
+ import { createContext } from "./utils/context";
8
+ import { ColorPoint } from "./utils/color-points";
3
9
  const panelRgb = (color, alpha) => {
4
10
  const { r, g, b } = color.toRgb();
5
11
  return alpha ? `rgba(${r},${g},${b},${color.get("alpha") / 100})` : `rgb(${r},${g},${b})`;
@@ -16,7 +22,147 @@ const triggerColorUpdate = (value, emit) => {
16
22
  const triggerConfirm = (value, emit) => {
17
23
  emit("confirm", value);
18
24
  };
19
- const initApi = (props, state, { emit, nextTick }) => {
25
+ const parseCustomRGBA = (str, type) => {
26
+ if (!str || typeof str !== "string") {
27
+ return [0, 0, 0, 0];
28
+ }
29
+ let content = "";
30
+ let match = null;
31
+ if (type === "hsl") {
32
+ match = str.match(/hsla?\(([^)]+)\)/);
33
+ } else if (type === "rgb") {
34
+ match = str.match(/rgba?\(([^)]+)\)/);
35
+ } else if (type === "hsv") {
36
+ match = str.match(/hsva?\(([^)]+)\)/);
37
+ }
38
+ if (!match || !match[1]) {
39
+ return [0, 0, 0, 0];
40
+ }
41
+ content = match[1];
42
+ const parts = content.split(",").map((item) => item.trim());
43
+ const result = parts.map((item, index) => {
44
+ if (index === 0 || index === parts.length - 1 && parts.length === 4) {
45
+ return parseFloat(item);
46
+ }
47
+ return item;
48
+ });
49
+ return result;
50
+ };
51
+ const isGrandient = (val) => {
52
+ if (typeof val !== "string") {
53
+ return false;
54
+ }
55
+ return val.trim().startsWith("linear-gradient");
56
+ };
57
+ const sideCornerDegreeMap = {
58
+ top: 0,
59
+ right: 90,
60
+ bottom: 180,
61
+ left: 270,
62
+ "top left": 315,
63
+ "left top": 315,
64
+ "top right": 45,
65
+ "right top": 45,
66
+ "bottom left": 225,
67
+ "left bottom": 225,
68
+ "bottom right": 135,
69
+ "right bottom": 135
70
+ };
71
+ const createColorPoints = (val, props, hooks, ext, bar) => {
72
+ if (!isGrandient(val)) {
73
+ return { colorPoints: [], angular: 180 };
74
+ }
75
+ const nodes = ext.parse(val);
76
+ let angular = 180;
77
+ const parseAngular = (node2) => {
78
+ if (node2.type === "angular") {
79
+ return Number.parseInt(node2.value);
80
+ }
81
+ return sideCornerDegreeMap[node2.value] || 180;
82
+ };
83
+ const parseBehavior = {
84
+ hex: (node2) => {
85
+ return new ColorPoint(new Color({ value: `#${node2.value}`, format: "hex", enableAlpha: props.alpha }), 0);
86
+ },
87
+ rgb: (node2) => {
88
+ if (props.alpha) {
89
+ return parseBehavior.rgba(__spreadProps(__spreadValues({}, node2), { type: "rgba" }));
90
+ }
91
+ return new ColorPoint(new Color({ enableAlpha: false, format: "rgb", value: `rgb(${node2.value.join(",")})` }), 0);
92
+ },
93
+ rgba: (node2) => {
94
+ const color = new Color({ enableAlpha: props.alpha, format: "rgba", value: `rgba(${node2.value.join(",")})` });
95
+ return new ColorPoint(color, 0);
96
+ },
97
+ hsl: (node2) => {
98
+ if (props.alpha) {
99
+ return parseBehavior.hsla(__spreadProps(__spreadValues({}, node2), { type: "hsla" }));
100
+ }
101
+ const color = new Color({ enableAlpha: false, format: "hsl", value: `hsl(${node2.value.join(" ")})` });
102
+ return new ColorPoint(color, 0);
103
+ },
104
+ hsla: (node2) => {
105
+ const color = new Color({ enableAlpha: props.alpha, format: "hsl", value: `hsl(${node2.value.join(" ")})` });
106
+ return new ColorPoint(color, 0);
107
+ },
108
+ literal: (node2) => {
109
+ let value = colors[node2.value] || "#00000000";
110
+ const color = new Color({ enableAlpha: true, format: "hex", value });
111
+ return new ColorPoint(color, 0);
112
+ },
113
+ "var": (node2) => {
114
+ hooks.warn("unsupported var ref.");
115
+ return parseBehavior.hex({ type: "hex", value: "#000", length: node2.length });
116
+ }
117
+ };
118
+ const unsupportedLengthUnit = ["em", "calc"];
119
+ const parseLength = (node2) => {
120
+ if (!node2 || !bar) {
121
+ return 0;
122
+ }
123
+ if (unsupportedLengthUnit.includes(node2.type)) {
124
+ hooks.warn(`unsupported unit ${node2.type}`);
125
+ return 0;
126
+ }
127
+ const barRect = bar.getBoundingClientRect();
128
+ const { width } = barRect;
129
+ const numberValue = Number.parseFloat(node2.value);
130
+ if (node2.type === "%") {
131
+ return Number.parseInt(`${numberValue / 100 * width}`);
132
+ }
133
+ if (node2.type === "px") {
134
+ return Number.parseInt(`${numberValue / width}`);
135
+ }
136
+ return 0;
137
+ };
138
+ const parseColotStop = (colorStop) => {
139
+ if (!(colorStop.type in parseBehavior)) {
140
+ hooks.warn(`unknown behavior ${colorStop}`);
141
+ throw new Error(`unknown behavior ${colorStop}`);
142
+ }
143
+ const colorPoint = parseBehavior[colorStop.type](colorStop);
144
+ const cursorLeft = parseLength(colorStop.length);
145
+ colorPoint.cursorLeft = cursorLeft;
146
+ return colorPoint;
147
+ };
148
+ const [node] = nodes;
149
+ if (node.type !== "linear-gradient") {
150
+ hooks.warn(`Only support linear-gradient yet.`);
151
+ return { colorPoints: [], angular: 180 };
152
+ }
153
+ if (!node) {
154
+ return { colorPoints: [], angular: 180 };
155
+ }
156
+ if (node.orientation) {
157
+ angular = parseAngular(node.orientation);
158
+ } else {
159
+ angular = 180;
160
+ }
161
+ const colorPoints = node.colorStops.map((colorStop) => parseColotStop(colorStop));
162
+ return { colorPoints, angular };
163
+ };
164
+ const initApi = (props, state, utils, hooks, ext) => {
165
+ const { emit, nextTick } = utils;
20
166
  const setShowPicker = (value) => state.showPicker = value;
21
167
  const resetColor = () => {
22
168
  nextTick(() => {
@@ -31,6 +177,12 @@ const initApi = (props, state, { emit, nextTick }) => {
31
177
  });
32
178
  };
33
179
  const submitValue = () => {
180
+ if (state.ctx.colorMode === "linear-gradient") {
181
+ updateModelValue(state.ctx.linearGardientValue, emit);
182
+ triggerConfirm(state.ctx.linearGardientValue, emit);
183
+ setShowPicker(false);
184
+ return;
185
+ }
34
186
  const value = state.color.value;
35
187
  updateModelValue(value, emit);
36
188
  triggerConfirm(value, emit);
@@ -93,10 +245,32 @@ const initApi = (props, state, { emit, nextTick }) => {
93
245
  setShowPicker(false);
94
246
  };
95
247
  const onHistoryClick = (historyColor) => {
96
- state.color.fromString(historyColor);
248
+ if (state.ctx.colorMode === "monochrome") {
249
+ state.ctx.activeColor.color.fromString(historyColor);
250
+ return;
251
+ }
252
+ const colorString = isGrandient(historyColor) ? historyColor : `linear-gradient(90deg, #fff 0%, ${historyColor} 100%)`;
253
+ const colorPoints = createColorPoints(colorString, props, hooks, ext, state.ctx.bar);
254
+ state.ctx.colorPoints = colorPoints.colorPoints;
255
+ const lastPoint = colorPoints.colorPoints.at(-1);
256
+ if (lastPoint) {
257
+ state.ctx.activeColor = lastPoint;
258
+ }
259
+ state.ctx.deg = colorPoints.angular;
97
260
  };
98
261
  const onPredefineColorClick = (predefineColor) => {
99
- state.color.fromString(predefineColor);
262
+ if (state.ctx.colorMode === "monochrome") {
263
+ state.color.fromString(predefineColor);
264
+ return;
265
+ }
266
+ const colorString = isGrandient(predefineColor) ? predefineColor : `linear-gradient(180deg, #fff 0%, ${predefineColor} 100%)`;
267
+ const colorPoints = createColorPoints(colorString, props, hooks, ext, state.ctx.bar);
268
+ state.ctx.colorPoints = colorPoints.colorPoints;
269
+ const lastPoint = colorPoints.colorPoints.at(-1);
270
+ if (lastPoint) {
271
+ state.ctx.activeColor = lastPoint;
272
+ }
273
+ state.ctx.deg = colorPoints.angular;
100
274
  };
101
275
  return {
102
276
  open,
@@ -114,8 +288,9 @@ const initApi = (props, state, { emit, nextTick }) => {
114
288
  onClickOutside
115
289
  };
116
290
  };
117
- const initState = (props, { reactive, ref, computed }) => {
291
+ const initState = (props, hooks, utils, ext) => {
118
292
  var _a, _b;
293
+ const { reactive, ref, computed } = hooks;
119
294
  const stack = ref([...(_a = props.history) != null ? _a : []]);
120
295
  const predefineStack = computed(() => props.predefine);
121
296
  const hue = ref();
@@ -129,7 +304,40 @@ const initState = (props, { reactive, ref, computed }) => {
129
304
  value: props.modelValue
130
305
  })
131
306
  );
307
+ const bar = ref(null);
308
+ const ctx = {
309
+ colorMode: computed(() => {
310
+ var _a2;
311
+ return (_a2 = props.colorMode) != null ? _a2 : "monochrome";
312
+ }),
313
+ activeColor: ref(new ColorPoint(color, 0)),
314
+ colorPoints: ref([new ColorPoint(color, 0)]),
315
+ linearGardientValue: ref(""),
316
+ bar,
317
+ deg: ref(180)
318
+ };
319
+ if (isGrandient(props.modelValue)) {
320
+ hooks.watchEffect(() => {
321
+ if (!bar.value) {
322
+ return;
323
+ }
324
+ const { colorPoints, angular } = createColorPoints(props.modelValue, props, hooks, ext, bar.value);
325
+ ctx.deg.value = angular;
326
+ ctx.colorPoints.value = colorPoints;
327
+ const lastPoint = colorPoints.at(-1);
328
+ if (lastPoint) {
329
+ ctx.activeColor.value = lastPoint;
330
+ }
331
+ });
332
+ }
333
+ createContext(ctx, hooks);
132
334
  const input = ref("");
335
+ const hexInput1 = ref();
336
+ const hexInput2 = ref();
337
+ const hexInput4 = ref();
338
+ const hexInput5 = ref();
339
+ const hexInput6 = ref();
340
+ const hexInput7 = ref();
133
341
  const showPicker = ref(props.visible);
134
342
  const showPanel = ref(false);
135
343
  const panelColor = computed(() => {
@@ -142,6 +350,12 @@ const initState = (props, { reactive, ref, computed }) => {
142
350
  const state = reactive({
143
351
  color,
144
352
  input,
353
+ hexInput1,
354
+ hexInput2,
355
+ hexInput4,
356
+ hexInput5,
357
+ hexInput6,
358
+ hexInput7,
145
359
  showPicker,
146
360
  showPanel,
147
361
  panelColor,
@@ -154,7 +368,10 @@ const initState = (props, { reactive, ref, computed }) => {
154
368
  enablePredefineColor: computed(() => props.enablePredefineColor),
155
369
  enableHistory: computed(() => props.enableHistory),
156
370
  currentFormat,
157
- formats: props.format
371
+ formats: props.format,
372
+ ctx,
373
+ isLinearGradient: computed(() => ctx.colorMode.value === "linear-gradient"),
374
+ linearGradient: computed(() => ctx.linearGardientValue.value)
158
375
  });
159
376
  return state;
160
377
  };
@@ -192,9 +409,19 @@ const initWatch = (state, props, { nextTick, watch }, { emit }) => {
192
409
  }
193
410
  );
194
411
  watch(
195
- () => state.currentColor,
412
+ () => [state.currentColor, state.linearGradient],
196
413
  () => {
197
- state.input = state.currentColor;
414
+ if (state.isLinearGradient) {
415
+ state.input = state.linearGradient;
416
+ return;
417
+ } else {
418
+ state.input = state.currentColor;
419
+ const result = parseCustomRGBA(state.currentColor, state.currentFormat);
420
+ state.hexInput4 = Math.ceil(Number(result[0]));
421
+ state.hexInput5 = result[1];
422
+ state.hexInput6 = result[2];
423
+ state.hexInput7 = `${(Number(result[3]) || 1) * 100}%`;
424
+ }
198
425
  triggerColorUpdate(state.input, emit);
199
426
  },
200
427
  { flush: "sync" }
@@ -236,6 +463,7 @@ export {
236
463
  initState,
237
464
  initWatch,
238
465
  panelRgb,
466
+ parseCustomRGBA,
239
467
  triggerCancel,
240
468
  triggerColorUpdate,
241
469
  triggerConfirm,