@opentiny/vue-renderless 3.26.0 → 3.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autocomplete/index.js +7 -2
- package/autocomplete/vue.js +1 -1
- package/base-select/index.js +189 -86
- package/base-select/vue.js +82 -20
- package/calendar-view/index.js +6 -3
- package/calendar-view/vue.js +9 -5
- package/color-picker/vue.js +4 -0
- package/color-select-panel/alpha-select/index.js +17 -12
- package/color-select-panel/alpha-select/vue.js +4 -2
- package/color-select-panel/hue-select/index.js +42 -11
- package/color-select-panel/hue-select/vue.js +32 -6
- package/color-select-panel/index.js +223 -39
- package/color-select-panel/linear-gradient/index.js +131 -0
- package/color-select-panel/linear-gradient/vue.js +21 -0
- package/color-select-panel/sv-select/index.js +12 -9
- package/color-select-panel/sv-select/vue.js +4 -2
- package/color-select-panel/utils/color-map.js +154 -0
- package/color-select-panel/utils/color-points.js +86 -0
- package/color-select-panel/utils/color.js +1 -1
- package/color-select-panel/utils/context.js +14 -0
- package/color-select-panel/vue.js +3 -3
- package/common/deps/infinite-scroll.js +1 -1
- package/dialog-box/index.js +3 -3
- package/dialog-box/vue.js +1 -0
- package/drawer/index.js +20 -0
- package/drawer/vue.js +9 -1
- package/dropdown/index.js +10 -4
- package/file-upload/index.js +18 -4
- package/form-item/index.js +28 -16
- package/form-item/vue.js +50 -11
- package/grid/static/array/eachTree.js +1 -0
- package/grid/utils/common.js +10 -3
- package/grid-select/index.js +418 -32
- package/grid-select/vue.js +103 -9
- package/guide/index.js +3 -3
- package/guide/vue.js +11 -1
- package/input/vue.js +2 -1
- package/package.json +3 -3
- package/picker/index.js +30 -13
- package/picker/vue.js +10 -0
- package/popover/index.js +1 -1
- package/rich-text/index.js +42 -0
- package/select/index.js +32 -15
- package/select/vue.js +31 -10
- package/select-dropdown/vue.js +8 -3
- package/select-wrapper/vue.js +134 -0
- package/slider/vue.js +7 -0
- package/space/index.js +30 -0
- package/space/vue.js +39 -0
- package/switch/vue.js +19 -0
- package/tab-nav/index.js +2 -2
- package/tabs-mf/index.js +9 -1
- package/tabs-mf/vue-nav.js +70 -22
- package/tabs-mf/vue-slider-bar.js +24 -0
- package/tabs-mf/vue.js +23 -5
- package/tag/index.js +1 -1
- package/transfer-panel/index.js +2 -1
- package/tree-menu/index.js +4 -0
- package/tree-menu/vue.js +3 -0
- package/tree-select/index.js +13 -4
- package/tree-select/vue.js +19 -3
- package/types/autocomplete.type.d.ts +2 -1
- package/types/color-select-panel.type.d.ts +197 -1
- package/types/date-picker.type.d.ts +38 -2
- package/types/file-upload.type.d.ts +1 -1
- package/types/form-item.type.d.ts +1 -1
- package/types/{form.type-dd403065.d.ts → form.type-a54e1c06.d.ts} +2 -2
- package/types/form.type.d.ts +1 -1
- package/types/input.type.d.ts +1 -1
- package/types/modal.type.d.ts +4 -0
- package/types/numeric.type.d.ts +1 -1
- package/types/picker.type.d.ts +42 -2
- package/types/popeditor.type.d.ts +76 -4
- package/types/popover.type.d.ts +1 -1
- package/types/space.type.d.ts +31 -0
- package/types/switch.type.d.ts +2 -1
- package/types/transfer.type.d.ts +3 -3
- package/types/tree-menu.type.d.ts +38 -2
- package/types/upload-dragger.type.d.ts +1 -1
- package/types/{upload-list.type-36a8374a.d.ts → upload-list.type-d5ff675d.d.ts} +1 -1
- package/types/upload-list.type.d.ts +1 -1
- package/types/upload.type.d.ts +1 -1
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import
|
|
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
|
|
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.
|
|
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.
|
|
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,34 +288,9 @@ const initApi = (props, state, { emit, nextTick }) => {
|
|
|
114
288
|
onClickOutside
|
|
115
289
|
};
|
|
116
290
|
};
|
|
117
|
-
const
|
|
118
|
-
if (!str || typeof str !== "string") {
|
|
119
|
-
return [0, 0, 0, 0];
|
|
120
|
-
}
|
|
121
|
-
let content = "";
|
|
122
|
-
let match = null;
|
|
123
|
-
if (type === "hsl") {
|
|
124
|
-
match = str.match(/hsla?\(([^)]+)\)/);
|
|
125
|
-
} else if (type === "rgb") {
|
|
126
|
-
match = str.match(/rgba?\(([^)]+)\)/);
|
|
127
|
-
} else if (type === "hsv") {
|
|
128
|
-
match = str.match(/hsva?\(([^)]+)\)/);
|
|
129
|
-
}
|
|
130
|
-
if (!match || !match[1]) {
|
|
131
|
-
return [0, 0, 0, 0];
|
|
132
|
-
}
|
|
133
|
-
content = match[1];
|
|
134
|
-
const parts = content.split(",").map((item) => item.trim());
|
|
135
|
-
const result = parts.map((item, index) => {
|
|
136
|
-
if (index === 0 || index === parts.length - 1 && parts.length === 4) {
|
|
137
|
-
return parseFloat(item);
|
|
138
|
-
}
|
|
139
|
-
return item;
|
|
140
|
-
});
|
|
141
|
-
return result;
|
|
142
|
-
};
|
|
143
|
-
const initState = (props, { reactive, ref, computed }) => {
|
|
291
|
+
const initState = (props, hooks, utils, ext) => {
|
|
144
292
|
var _a, _b;
|
|
293
|
+
const { reactive, ref, computed } = hooks;
|
|
145
294
|
const stack = ref([...(_a = props.history) != null ? _a : []]);
|
|
146
295
|
const predefineStack = computed(() => props.predefine);
|
|
147
296
|
const hue = ref();
|
|
@@ -155,6 +304,33 @@ const initState = (props, { reactive, ref, computed }) => {
|
|
|
155
304
|
value: props.modelValue
|
|
156
305
|
})
|
|
157
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);
|
|
158
334
|
const input = ref("");
|
|
159
335
|
const hexInput1 = ref();
|
|
160
336
|
const hexInput2 = ref();
|
|
@@ -192,7 +368,10 @@ const initState = (props, { reactive, ref, computed }) => {
|
|
|
192
368
|
enablePredefineColor: computed(() => props.enablePredefineColor),
|
|
193
369
|
enableHistory: computed(() => props.enableHistory),
|
|
194
370
|
currentFormat,
|
|
195
|
-
formats: props.format
|
|
371
|
+
formats: props.format,
|
|
372
|
+
ctx,
|
|
373
|
+
isLinearGradient: computed(() => ctx.colorMode.value === "linear-gradient"),
|
|
374
|
+
linearGradient: computed(() => ctx.linearGardientValue.value)
|
|
196
375
|
});
|
|
197
376
|
return state;
|
|
198
377
|
};
|
|
@@ -230,14 +409,19 @@ const initWatch = (state, props, { nextTick, watch }, { emit }) => {
|
|
|
230
409
|
}
|
|
231
410
|
);
|
|
232
411
|
watch(
|
|
233
|
-
() => state.currentColor,
|
|
412
|
+
() => [state.currentColor, state.linearGradient],
|
|
234
413
|
() => {
|
|
235
|
-
state.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
+
}
|
|
241
425
|
triggerColorUpdate(state.input, emit);
|
|
242
426
|
},
|
|
243
427
|
{ flush: "sync" }
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import "../../chunk-G2ADBYYC.js";
|
|
2
|
+
import { ColorPoint } from "../utils/color-points";
|
|
3
|
+
import { getClientXY } from "../utils/getClientXY";
|
|
4
|
+
import { Color } from "../utils/color";
|
|
5
|
+
import { draggable } from "../utils/use-drag";
|
|
6
|
+
import { isNullOrEmpty } from "@opentiny/utils";
|
|
7
|
+
const LINEAR_GRADIENT_BAR = "linearGradientBar";
|
|
8
|
+
const THUMB = "thumb";
|
|
9
|
+
const useLinearGradient = (state, hooks, utils, context) => {
|
|
10
|
+
const { vm } = utils;
|
|
11
|
+
const { nextTick } = hooks;
|
|
12
|
+
const activePoint = context.activeColor;
|
|
13
|
+
const addPoint = (point) => {
|
|
14
|
+
context.colorPoints.value.push(point);
|
|
15
|
+
};
|
|
16
|
+
const getPos = (event) => {
|
|
17
|
+
if (!vm) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
const el = vm.$refs[LINEAR_GRADIENT_BAR];
|
|
21
|
+
const rect = el.getBoundingClientRect();
|
|
22
|
+
const { clientX } = getClientXY(event);
|
|
23
|
+
return Math.min(Math.max(clientX - rect.left, 0), rect.width);
|
|
24
|
+
};
|
|
25
|
+
const onDrag = (event) => {
|
|
26
|
+
if (!vm) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
activePoint.value.cursorLeft = getPos(event);
|
|
30
|
+
};
|
|
31
|
+
const getActivePoint = () => {
|
|
32
|
+
return activePoint;
|
|
33
|
+
};
|
|
34
|
+
const onClickBar = (event) => {
|
|
35
|
+
const active = getActivePoint();
|
|
36
|
+
const newPoint = new ColorPoint(
|
|
37
|
+
new Color({
|
|
38
|
+
enableAlpha: active.value.color.enableAlpha,
|
|
39
|
+
format: active.value.color.format,
|
|
40
|
+
value: active.value.color.value
|
|
41
|
+
}),
|
|
42
|
+
active.value.cursorLeft
|
|
43
|
+
);
|
|
44
|
+
const left = getPos(event);
|
|
45
|
+
newPoint.cursorLeft = left;
|
|
46
|
+
addPoint(newPoint);
|
|
47
|
+
setActivePoint(newPoint);
|
|
48
|
+
nextTick(() => {
|
|
49
|
+
const lastColorPointElement = vm.$refs[THUMB].at(-1);
|
|
50
|
+
if (!lastColorPointElement) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
draggable(lastColorPointElement, {
|
|
54
|
+
drag(event2) {
|
|
55
|
+
onDrag(event2);
|
|
56
|
+
},
|
|
57
|
+
end(event2) {
|
|
58
|
+
onDrag(event2);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const setActivePoint = (point) => {
|
|
64
|
+
activePoint.value = point;
|
|
65
|
+
};
|
|
66
|
+
const onThumbMouseDown = (event, point) => {
|
|
67
|
+
setActivePoint(point);
|
|
68
|
+
const el = event.target;
|
|
69
|
+
draggable(el, {
|
|
70
|
+
drag(event2) {
|
|
71
|
+
onDrag(event2);
|
|
72
|
+
},
|
|
73
|
+
end(event2) {
|
|
74
|
+
onDrag(event2);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const getRelativePos = (points) => {
|
|
79
|
+
const bar = vm.$refs[LINEAR_GRADIENT_BAR];
|
|
80
|
+
if (!bar) {
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
const rect = bar.getBoundingClientRect();
|
|
84
|
+
return Number.parseInt((points.cursorLeft / rect.width * 100).toFixed(0));
|
|
85
|
+
};
|
|
86
|
+
const toString = () => {
|
|
87
|
+
const colors = context.colorPoints.value.map((point) => {
|
|
88
|
+
return [point.color.value, getRelativePos(point)];
|
|
89
|
+
}).sort((a, b) => a[1] - b[1]).map(([colorValue, pos]) => {
|
|
90
|
+
return [colorValue, `${pos}%`].join(" ");
|
|
91
|
+
}).join(",");
|
|
92
|
+
return `linear-gradient(${context.deg.value}deg, ${colors})`;
|
|
93
|
+
};
|
|
94
|
+
hooks.watchEffect(() => {
|
|
95
|
+
if (isNullOrEmpty(context.deg.value)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
context.linearGardientValue.value = toString();
|
|
99
|
+
state.linearGradientBarBackground = toString().replace(`${context.deg.value}deg`, "90deg");
|
|
100
|
+
});
|
|
101
|
+
hooks.onMounted(() => {
|
|
102
|
+
const elements = vm.$refs[THUMB];
|
|
103
|
+
if (!elements || !elements.length) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
elements.forEach((el) => {
|
|
107
|
+
draggable(el, {
|
|
108
|
+
drag(event) {
|
|
109
|
+
onDrag(event);
|
|
110
|
+
},
|
|
111
|
+
end(event) {
|
|
112
|
+
onDrag(event);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
context.bar.value = vm.$refs[LINEAR_GRADIENT_BAR];
|
|
117
|
+
});
|
|
118
|
+
return { onClickBar, onThumbMouseDown, toString };
|
|
119
|
+
};
|
|
120
|
+
const initState = (hooks) => {
|
|
121
|
+
const { ref, reactive } = hooks;
|
|
122
|
+
const linearGradientBarBackground = ref("");
|
|
123
|
+
const state = reactive({ linearGradientBarBackground });
|
|
124
|
+
return state;
|
|
125
|
+
};
|
|
126
|
+
export {
|
|
127
|
+
LINEAR_GRADIENT_BAR,
|
|
128
|
+
THUMB,
|
|
129
|
+
initState,
|
|
130
|
+
useLinearGradient
|
|
131
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../../chunk-G2ADBYYC.js";
|
|
2
|
+
import { useContext } from "../utils/context";
|
|
3
|
+
import { initState, useLinearGradient } from ".";
|
|
4
|
+
const api = ["context", "onClickBar", "onThumbMouseDown", "state"];
|
|
5
|
+
const renderless = (_, hooks, utils) => {
|
|
6
|
+
const { reactive } = hooks;
|
|
7
|
+
const context = useContext(hooks);
|
|
8
|
+
const state = initState(hooks);
|
|
9
|
+
const { onClickBar, onThumbMouseDown } = useLinearGradient(state, hooks, utils, context);
|
|
10
|
+
const api2 = reactive({
|
|
11
|
+
state,
|
|
12
|
+
context,
|
|
13
|
+
onClickBar,
|
|
14
|
+
onThumbMouseDown
|
|
15
|
+
});
|
|
16
|
+
return api2;
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
api,
|
|
20
|
+
renderless
|
|
21
|
+
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import "../../chunk-G2ADBYYC.js";
|
|
2
2
|
import { getClientXY } from "../utils/getClientXY";
|
|
3
|
-
|
|
3
|
+
import { useContext } from "../utils/context";
|
|
4
|
+
const initState = (props, hooks) => {
|
|
5
|
+
const { ref, computed, reactive } = hooks;
|
|
6
|
+
const context = useContext(hooks);
|
|
4
7
|
const cursorTop = ref(0);
|
|
5
8
|
const cursorLeft = ref(0);
|
|
6
9
|
const bg = ref("hsl(0, 100%, 50%)");
|
|
7
10
|
const colorValue = computed(() => {
|
|
8
|
-
const hue =
|
|
9
|
-
const value =
|
|
11
|
+
const hue = context.activeColor.value.color.get("hue");
|
|
12
|
+
const value = context.activeColor.value.color.get("value");
|
|
10
13
|
return { hue, value };
|
|
11
14
|
});
|
|
12
15
|
const state = reactive({
|
|
@@ -17,21 +20,21 @@ const initState = (props, { ref, computed, reactive }) => {
|
|
|
17
20
|
});
|
|
18
21
|
return state;
|
|
19
22
|
};
|
|
20
|
-
const useUpdate = (state, props, wrapper) => {
|
|
23
|
+
const useUpdate = (state, props, wrapper, context) => {
|
|
21
24
|
return () => {
|
|
22
25
|
const el = wrapper.value;
|
|
23
26
|
if (!el) {
|
|
24
27
|
return;
|
|
25
28
|
}
|
|
26
|
-
const sat =
|
|
27
|
-
const value =
|
|
29
|
+
const sat = context.activeColor.value.color.get("sat");
|
|
30
|
+
const value = context.activeColor.value.color.get("value");
|
|
28
31
|
const { clientWidth: width, clientHeight: height } = el;
|
|
29
32
|
state.cursorLeft = sat * width / 100;
|
|
30
33
|
state.cursorTop = (100 - value) * height / 100;
|
|
31
|
-
state.bg = `hsl(${
|
|
34
|
+
state.bg = `hsl(${context.activeColor.value.color.get("hue")}, 100%, 50%)`;
|
|
32
35
|
};
|
|
33
36
|
};
|
|
34
|
-
const useDrag = (state, wrapper, props, { emit }) => {
|
|
37
|
+
const useDrag = (state, wrapper, props, { emit }, context) => {
|
|
35
38
|
return (event) => {
|
|
36
39
|
const el = wrapper.value;
|
|
37
40
|
const rect = el.getBoundingClientRect();
|
|
@@ -47,7 +50,7 @@ const useDrag = (state, wrapper, props, { emit }) => {
|
|
|
47
50
|
const s = left / rect.width * 100;
|
|
48
51
|
const v = 100 - top / rect.height * 100;
|
|
49
52
|
emit("svUpdate", { s, v });
|
|
50
|
-
|
|
53
|
+
context.activeColor.value.color.set({
|
|
51
54
|
sat: s,
|
|
52
55
|
value: v
|
|
53
56
|
});
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import "../../chunk-G2ADBYYC.js";
|
|
2
2
|
import { draggable } from "../utils/use-drag";
|
|
3
3
|
import { initState, initWatch, useDrag, useUpdate } from "./index";
|
|
4
|
+
import { useContext } from "../utils/context";
|
|
4
5
|
const api = ["state", "wrapper", "cursor"];
|
|
5
6
|
const renderless = (props, hooks, utils) => {
|
|
7
|
+
const ctx = useContext(hooks);
|
|
6
8
|
const state = initState(props, hooks);
|
|
7
9
|
const { ref, onMounted } = hooks;
|
|
8
10
|
const { emit } = utils;
|
|
9
11
|
const wrapper = ref();
|
|
10
|
-
const update = useUpdate(state, props, wrapper);
|
|
11
|
-
const onDrag = useDrag(state, wrapper, props, utils);
|
|
12
|
+
const update = useUpdate(state, props, wrapper, ctx);
|
|
13
|
+
const onDrag = useDrag(state, wrapper, props, utils, ctx);
|
|
12
14
|
initWatch(state, update, hooks);
|
|
13
15
|
onMounted(() => {
|
|
14
16
|
const drag = {
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import "../../chunk-G2ADBYYC.js";
|
|
2
|
+
var color_map_default = {
|
|
3
|
+
"black": "#000000",
|
|
4
|
+
"silver": "#c0c0c0",
|
|
5
|
+
"gray": "#808080",
|
|
6
|
+
"white": "#ffffff",
|
|
7
|
+
"maroon": "#800000",
|
|
8
|
+
"red": "#ff0000",
|
|
9
|
+
"purple": "#800080",
|
|
10
|
+
"fuchsia": "#ff00ff",
|
|
11
|
+
"green": "#008000",
|
|
12
|
+
"lime": "#00ff00",
|
|
13
|
+
"olive": "#808000",
|
|
14
|
+
"yellow": "#ffff00",
|
|
15
|
+
"navy": "#000080",
|
|
16
|
+
"blue": "#0000ff",
|
|
17
|
+
"teal": "#008080",
|
|
18
|
+
"aqua": "#00ffff",
|
|
19
|
+
"aliceblue": "#f0f8ff",
|
|
20
|
+
"antiquewhite": "#faebd7",
|
|
21
|
+
"aquamarine": "#7fffd4",
|
|
22
|
+
"azure": "#f0ffff",
|
|
23
|
+
"beige": "#f5f5dc",
|
|
24
|
+
"bisque": "#ffe4c4",
|
|
25
|
+
"blanchedalmond": "#ffebcd",
|
|
26
|
+
"blueviolet": "#8a2be2",
|
|
27
|
+
"brown": "#a52a2a",
|
|
28
|
+
"burlywood": "#deb887",
|
|
29
|
+
"cadetblue": "#5f9ea0",
|
|
30
|
+
"chartreuse": "#7fff00",
|
|
31
|
+
"chocolate": "#d2691e",
|
|
32
|
+
"coral": "#ff7f50",
|
|
33
|
+
"cornflowerblue": "#6495ed",
|
|
34
|
+
"cornsilk": "#fff8dc",
|
|
35
|
+
"crimson": "#dc143c",
|
|
36
|
+
"cyan": "#00ffff",
|
|
37
|
+
"darkblue": "#00008b",
|
|
38
|
+
"darkcyan": "#008b8b",
|
|
39
|
+
"darkgoldenrod": "#b8860b",
|
|
40
|
+
"darkgray": "#a9a9a9",
|
|
41
|
+
"darkgreen": "#006400",
|
|
42
|
+
"darkgrey": "#a9a9a9",
|
|
43
|
+
"darkkhaki": "#bdb76b",
|
|
44
|
+
"darkmagenta": "#8b008b",
|
|
45
|
+
"darkolivegreen": "#556b2f",
|
|
46
|
+
"darkorange": "#ff8c00",
|
|
47
|
+
"darkorchid": "#9932cc",
|
|
48
|
+
"darkred": "#8b0000",
|
|
49
|
+
"darksalmon": "#e9967a",
|
|
50
|
+
"darkseagreen": "#8fbc8f",
|
|
51
|
+
"darkslateblue": "#483d8b",
|
|
52
|
+
"darkslategray": "#2f4f4f",
|
|
53
|
+
"darkslategrey": "#2f4f4f",
|
|
54
|
+
"darkturquoise": "#00ced1",
|
|
55
|
+
"darkviolet": "#9400d3",
|
|
56
|
+
"deeppink": "#ff1493",
|
|
57
|
+
"deepskyblue": "#00bfff",
|
|
58
|
+
"dimgray": "#696969",
|
|
59
|
+
"dimgrey": "#696969",
|
|
60
|
+
"dodgerblue": "#1e90ff",
|
|
61
|
+
"firebrick": "#b22222",
|
|
62
|
+
"floralwhite": "#fffaf0",
|
|
63
|
+
"forestgreen": "#228b22",
|
|
64
|
+
"gainsboro": "#dcdcdc",
|
|
65
|
+
"ghostwhite": "#f8f8ff",
|
|
66
|
+
"gold": "#ffd700",
|
|
67
|
+
"goldenrod": "#daa520",
|
|
68
|
+
"greenyellow": "#adff2f",
|
|
69
|
+
"grey": "#808080",
|
|
70
|
+
"honeydew": "#f0fff0",
|
|
71
|
+
"hotpink": "#ff69b4",
|
|
72
|
+
"indianred": "#cd5c5c",
|
|
73
|
+
"indigo": "#4b0082",
|
|
74
|
+
"ivory": "#fffff0",
|
|
75
|
+
"khaki": "#f0e68c",
|
|
76
|
+
"lavender": "#e6e6fa",
|
|
77
|
+
"lavenderblush": "#fff0f5",
|
|
78
|
+
"lawngreen": "#7cfc00",
|
|
79
|
+
"lemonchiffon": "#fffacd",
|
|
80
|
+
"lightblue": "#add8e6",
|
|
81
|
+
"lightcoral": "#f08080",
|
|
82
|
+
"lightcyan": "#e0ffff",
|
|
83
|
+
"lightgoldenrodyellow": "#fafad2",
|
|
84
|
+
"lightgray": "#d3d3d3",
|
|
85
|
+
"lightgreen": "#90ee90",
|
|
86
|
+
"lightgrey": "#d3d3d3",
|
|
87
|
+
"lightpink": "#ffb6c1",
|
|
88
|
+
"lightsalmon": "#ffa07a",
|
|
89
|
+
"lightseagreen": "#20b2aa",
|
|
90
|
+
"lightskyblue": "#87cefa",
|
|
91
|
+
"lightslategray": "#778899",
|
|
92
|
+
"lightslategrey": "#778899",
|
|
93
|
+
"lightsteelblue": "#b0c4de",
|
|
94
|
+
"lightyellow": "#ffffe0",
|
|
95
|
+
"limegreen": "#32cd32",
|
|
96
|
+
"linen": "#faf0e6",
|
|
97
|
+
"magenta": "#ff00ff",
|
|
98
|
+
"mediumaquamarine": "#66cdaa",
|
|
99
|
+
"mediumblue": "#0000cd",
|
|
100
|
+
"mediumorchid": "#ba55d3",
|
|
101
|
+
"mediumpurple": "#9370db",
|
|
102
|
+
"mediumseagreen": "#3cb371",
|
|
103
|
+
"mediumslateblue": "#7b68ee",
|
|
104
|
+
"mediumspringgreen": "#00fa9a",
|
|
105
|
+
"mediumturquoise": "#48d1cc",
|
|
106
|
+
"mediumvioletred": "#c71585",
|
|
107
|
+
"midnightblue": "#191970",
|
|
108
|
+
"mintcream": "#f5fffa",
|
|
109
|
+
"mistyrose": "#ffe4e1",
|
|
110
|
+
"moccasin": "#ffe4b5",
|
|
111
|
+
"navajowhite": "#ffdead",
|
|
112
|
+
"oldlace": "#fdf5e6",
|
|
113
|
+
"olivedrab": "#6b8e23",
|
|
114
|
+
"orange": "#ffa500",
|
|
115
|
+
"orangered": "#ff4500",
|
|
116
|
+
"orchid": "#da70d6",
|
|
117
|
+
"palegoldenrod": "#eee8aa",
|
|
118
|
+
"palegreen": "#98fb98",
|
|
119
|
+
"paleturquoise": "#afeeee",
|
|
120
|
+
"palevioletred": "#db7093",
|
|
121
|
+
"papayawhip": "#ffefd5",
|
|
122
|
+
"peachpuff": "#ffdab9",
|
|
123
|
+
"peru": "#cd853f",
|
|
124
|
+
"pink": "#ffc0cb",
|
|
125
|
+
"plum": "#dda0dd",
|
|
126
|
+
"powderblue": "#b0e0e6",
|
|
127
|
+
"rebeccapurple": "#663399",
|
|
128
|
+
"rosybrown": "#bc8f8f",
|
|
129
|
+
"royalblue": "#4169e1",
|
|
130
|
+
"saddlebrown": "#8b4513",
|
|
131
|
+
"salmon": "#fa8072",
|
|
132
|
+
"sandybrown": "#f4a460",
|
|
133
|
+
"seagreen": "#2e8b57",
|
|
134
|
+
"seashell": "#fff5ee",
|
|
135
|
+
"sienna": "#a0522d",
|
|
136
|
+
"skyblue": "#87ceeb",
|
|
137
|
+
"slateblue": "#6a5acd",
|
|
138
|
+
"slategray": "#708090",
|
|
139
|
+
"slategrey": "#708090",
|
|
140
|
+
"snow": "#fffafa",
|
|
141
|
+
"springgreen": "#00ff7f",
|
|
142
|
+
"steelblue": "#4682b4",
|
|
143
|
+
"tan": "#d2b48c",
|
|
144
|
+
"thistle": "#d8bfd8",
|
|
145
|
+
"tomato": "#ff6347",
|
|
146
|
+
"turquoise": "#40e0d0",
|
|
147
|
+
"violet": "#ee82ee",
|
|
148
|
+
"wheat": "#f5deb3",
|
|
149
|
+
"whitesmoke": "#f5f5f5",
|
|
150
|
+
"yellowgreen": "#9acd32"
|
|
151
|
+
};
|
|
152
|
+
export {
|
|
153
|
+
color_map_default as default
|
|
154
|
+
};
|