@aurouscia/au-color-picker 0.1.1 → 0.2.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/README.md
CHANGED
|
@@ -1,2 +1,75 @@
|
|
|
1
1
|
# au-color-picker
|
|
2
|
-
vue3
|
|
2
|
+
vue3颜色选择控件,支持鼠标/手指的点击和拖动
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
## 用法
|
|
7
|
+
```shell
|
|
8
|
+
npm i @aurouscia/au-color-picker
|
|
9
|
+
```
|
|
10
|
+
```ts
|
|
11
|
+
//main.ts(必须导入样式)
|
|
12
|
+
import '@aurouscia/au-color-picker/style.css'
|
|
13
|
+
|
|
14
|
+
//xxx.vue
|
|
15
|
+
import { AuColorPicker } from '@aurouscia/au-color-picker';
|
|
16
|
+
import { AuColorPickerPresetsNested } from '@aurouscia/au-color-picker';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 仅自定义
|
|
20
|
+
```vue
|
|
21
|
+
<AuColorPicker
|
|
22
|
+
:initial="初始值"
|
|
23
|
+
@change="值变化回调"
|
|
24
|
+
@done="面板关闭回调"
|
|
25
|
+
></AuColorPicker>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 预设+自定义
|
|
29
|
+
```ts
|
|
30
|
+
const presets:NamedPreset[] = [
|
|
31
|
+
{
|
|
32
|
+
name: '水系',
|
|
33
|
+
colorHex: '#c3e5eb'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: '绿地',
|
|
37
|
+
colorHex: '#ceeda4'
|
|
38
|
+
},
|
|
39
|
+
]
|
|
40
|
+
```
|
|
41
|
+
```vue
|
|
42
|
+
<AuColorPickerPresetsNested
|
|
43
|
+
:initial="初始值"
|
|
44
|
+
:presets="预设列表"
|
|
45
|
+
:initial-selected-preset="初始选择预设"
|
|
46
|
+
@change="值变化回调" @done="面板关闭回调"
|
|
47
|
+
@presetSwitched="预设切换回调"
|
|
48
|
+
></AuColorPickerPresetsNested>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 组件属性定义
|
|
52
|
+
```ts
|
|
53
|
+
//AuColorPicker的属性
|
|
54
|
+
export interface PickerProps{
|
|
55
|
+
initial?: string //初始值
|
|
56
|
+
entryStyles?: CSSProperties //入口按钮的样式
|
|
57
|
+
entryActiveStyles?: CSSProperties //入口按钮的样式(当面板展开)
|
|
58
|
+
entryClassName?: string //入口按钮的类名
|
|
59
|
+
pos?: 'left'|'right', //面板靠左还是靠右
|
|
60
|
+
panelBaseZIndex?:number, //面板的zIndex基础值
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//AuColorPickerPresetsNested的属性
|
|
64
|
+
export interface PickerWithPresetsProps extends PickerProps{
|
|
65
|
+
initialSelectedPreset?:string //初始选择预设名称(undefined即为自定义)
|
|
66
|
+
presets?: NamedPreset[] //预设列表
|
|
67
|
+
}
|
|
68
|
+
export interface NamedPreset{
|
|
69
|
+
colorHex:string, //预设值
|
|
70
|
+
name:string //预设名称
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 许可证
|
|
75
|
+
MIT
|
|
@@ -1,431 +1,450 @@
|
|
|
1
|
-
import { defineComponent as
|
|
1
|
+
import { defineComponent as Q, ref as b, onMounted as ge, onUnmounted as me, openBlock as N, createElementBlock as _, normalizeStyle as O, isRef as ye, createElementVNode as r, computed as K, onBeforeMount as re, watch as Y, normalizeClass as he, unref as P, createVNode as ue, withDirectives as G, vModelSelect as xe, createCommentVNode as J, vModelRadio as te, Fragment as Pe, renderList as ke, toDisplayString as Ce } from "vue";
|
|
2
2
|
import A from "color-convert";
|
|
3
|
-
function
|
|
4
|
-
const
|
|
5
|
-
return
|
|
3
|
+
function we(m, f) {
|
|
4
|
+
const g = m.x - f.x, d = m.y - f.y;
|
|
5
|
+
return g ** 2 + d ** 2;
|
|
6
6
|
}
|
|
7
|
-
function Se(
|
|
8
|
-
const
|
|
9
|
-
return Math.atan2(
|
|
7
|
+
function Se(m, f) {
|
|
8
|
+
const g = m.x - f.x, d = m.y - f.y;
|
|
9
|
+
return Math.atan2(d, g);
|
|
10
10
|
}
|
|
11
|
-
function Ie(
|
|
12
|
-
let
|
|
13
|
-
for (;
|
|
14
|
-
|
|
15
|
-
return { y, x:
|
|
11
|
+
function Ie(m) {
|
|
12
|
+
let f = m, g = 0, d = 0;
|
|
13
|
+
for (; f !== null; )
|
|
14
|
+
g += f.offsetTop, d += f.offsetLeft, f = f.offsetParent;
|
|
15
|
+
return { y: g, x: d };
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const H = 400, q = 400, F = 200, be = 200, ne = 190, se = 150, L = 200, oe = 16, ae = 3, Be = /* @__PURE__ */ Q({
|
|
18
18
|
__name: "AuColorPickerRing",
|
|
19
19
|
props: {
|
|
20
20
|
initialHex: {}
|
|
21
21
|
},
|
|
22
22
|
emits: ["changed"],
|
|
23
|
-
setup(
|
|
24
|
-
const
|
|
25
|
-
let
|
|
26
|
-
const $ = { x: 199, y: 199 },
|
|
27
|
-
let
|
|
28
|
-
function
|
|
29
|
-
var
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
23
|
+
setup(m, { expose: f, emit: g }) {
|
|
24
|
+
const d = b(), C = b();
|
|
25
|
+
let c, l;
|
|
26
|
+
const $ = { x: 199, y: 199 }, w = (ne + se) / 2, U = ne ** 2, D = se ** 2, h = (H - L) / 2, B = h + L, S = b(0), M = b(100), i = b(100), p = m;
|
|
27
|
+
let o;
|
|
28
|
+
function R() {
|
|
29
|
+
var a, v;
|
|
30
|
+
const n = (a = d.value) == null ? void 0 : a.getContext("2d"), s = (v = C.value) == null ? void 0 : v.getContext("2d");
|
|
31
|
+
if (!n || !s)
|
|
32
32
|
throw Error("canvas context getting error");
|
|
33
|
-
if (
|
|
34
|
-
const x = A.hex.hsv(
|
|
35
|
-
S.value = x[0],
|
|
33
|
+
if (p.initialHex) {
|
|
34
|
+
const x = A.hex.hsv(p.initialHex);
|
|
35
|
+
S.value = x[0], M.value = x[1], i.value = x[2];
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
c = n, l = s, o = c.getImageData(0, 0, H, q), j(), e(), X(), c.putImageData(o, 0, 0);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
for (let
|
|
41
|
-
for (let
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
|
|
39
|
+
function j() {
|
|
40
|
+
for (let n = 0; n < H; n++)
|
|
41
|
+
for (let s = 0; s < q; s++) {
|
|
42
|
+
const a = { x: n, y: s };
|
|
43
|
+
if (y(a)) {
|
|
44
|
+
const v = a.y * H * 4 + a.x * 4, x = z(a), E = A.hsv.rgb([x, 100, 100]);
|
|
45
|
+
o.data[v] = E[0], o.data[v + 1] = E[1], o.data[v + 2] = E[2], o.data[v + 3] = 255;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
function z(
|
|
50
|
-
return 360 * ((Se(
|
|
49
|
+
function z(n) {
|
|
50
|
+
return 360 * ((Se(n, $) + Math.PI) / (2 * Math.PI));
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
const
|
|
54
|
-
return
|
|
52
|
+
function y(n) {
|
|
53
|
+
const s = we($, n);
|
|
54
|
+
return s > D && s < U;
|
|
55
55
|
}
|
|
56
56
|
function e() {
|
|
57
|
-
for (let
|
|
58
|
-
for (let
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
62
|
-
|
|
57
|
+
for (let n = 0; n < H; n++)
|
|
58
|
+
for (let s = 0; s < q; s++) {
|
|
59
|
+
const a = { x: n, y: s };
|
|
60
|
+
if (I(a)) {
|
|
61
|
+
const v = a.y * H * 4 + a.x * 4, { s: x, v: E } = t(a), V = A.hsv.rgb([S.value, x, E]);
|
|
62
|
+
o.data[v] = V[0], o.data[v + 1] = V[1], o.data[v + 2] = V[2], o.data[v + 3] = 255;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
let
|
|
69
|
-
return
|
|
66
|
+
function t(n) {
|
|
67
|
+
const s = n.x - h, a = n.y - h;
|
|
68
|
+
let v = s / L, x = 1 - a / L;
|
|
69
|
+
return v > 1 ? v = 1 : v < 0 && (v = 0), x > 1 ? x = 1 : x < 0 && (x = 0), { s: 100 * v, v: 100 * x };
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
return !(
|
|
71
|
+
function I(n) {
|
|
72
|
+
return !(n.x < h || n.x > B || n.y < h || n.y > B);
|
|
73
73
|
}
|
|
74
|
-
let
|
|
75
|
-
function Z(
|
|
76
|
-
if (
|
|
74
|
+
let T = !1, u = "none", k = !1;
|
|
75
|
+
function Z(n, s) {
|
|
76
|
+
if (T || s && !k)
|
|
77
77
|
return;
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
78
|
+
T = !0;
|
|
79
|
+
const a = ve(n);
|
|
80
|
+
if (u === "none" && (I(a) ? u = "square" : y(a) && (u = "ring")), u === "ring" && (n.preventDefault(), S.value = z(a), e(), c.putImageData(o, 0, 0)), u === "square") {
|
|
81
|
+
n.preventDefault();
|
|
82
|
+
const v = t(a);
|
|
83
|
+
M.value = v.s, i.value = v.v;
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
u !== "none" && X(!0), T = !1;
|
|
86
86
|
}
|
|
87
87
|
function W() {
|
|
88
|
-
|
|
88
|
+
u = "none", k = !1;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
let
|
|
92
|
-
if ("touches" in
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
90
|
+
function ve(n) {
|
|
91
|
+
let s, a;
|
|
92
|
+
if ("touches" in n) {
|
|
93
|
+
s = n.touches[0].pageX, a = n.touches[0].pageY;
|
|
94
|
+
const v = Ie(d.value);
|
|
95
|
+
s -= v.x, a -= v.y;
|
|
96
96
|
} else
|
|
97
|
-
|
|
98
|
-
return
|
|
97
|
+
s = n.offsetX, a = n.offsetY;
|
|
98
|
+
return s = s * H / F, a = a * H / F, { x: s, y: a };
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
if (
|
|
102
|
-
const
|
|
103
|
-
|
|
100
|
+
function X(n) {
|
|
101
|
+
if (n) {
|
|
102
|
+
const pe = A.hsv.hex([S.value, M.value, i.value]);
|
|
103
|
+
de("changed", pe);
|
|
104
104
|
}
|
|
105
|
-
const
|
|
106
|
-
l.reset(), l.lineWidth = 4, l.strokeStyle = "black", l.beginPath(), l.arc(
|
|
107
|
-
const
|
|
108
|
-
l.strokeStyle =
|
|
105
|
+
const s = (S.value / 360 * 2 + 1) * Math.PI, a = Math.cos(s) * w + H / 2, v = Math.sin(s) * w + q / 2, x = M.value / 100 * L + h, E = (1 - i.value / 100) * L + h;
|
|
106
|
+
l.reset(), l.lineWidth = 4, l.strokeStyle = "black", l.beginPath(), l.arc(a, v, oe - 2, 0, 2 * Math.PI), l.stroke(), l.beginPath(), l.arc(a, v, ae, 0, 2 * Math.PI), l.fill();
|
|
107
|
+
const V = i.value > 50 ? "black" : "#ddd";
|
|
108
|
+
l.strokeStyle = V, l.fillStyle = V, l.beginPath(), l.arc(x, E, oe - 2, 0, 2 * Math.PI), l.stroke(), l.beginPath(), l.arc(x, E, ae, 0, 2 * Math.PI), l.fill();
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
const
|
|
112
|
-
S.value =
|
|
110
|
+
function fe(n) {
|
|
111
|
+
const s = A.hex.hsv(n);
|
|
112
|
+
S.value = s[0], M.value = s[1], i.value = s[2], e(), c.putImageData(o, 0, 0), X();
|
|
113
113
|
}
|
|
114
|
-
const
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
}),
|
|
114
|
+
const de = g;
|
|
115
|
+
return f({ enforceTo: fe }), ge(() => {
|
|
116
|
+
R(), window.addEventListener("touchend", W), window.addEventListener("mouseup", W);
|
|
117
|
+
}), me(() => {
|
|
118
118
|
window.removeEventListener("touchend", W), window.removeEventListener("mouseup", W);
|
|
119
|
-
}), (
|
|
119
|
+
}), (n, s) => (N(), _("div", {
|
|
120
120
|
class: "acpRingBody",
|
|
121
|
-
style:
|
|
121
|
+
style: O({ width: F + "px", height: be + "px" }),
|
|
122
122
|
onTouchstart: Z,
|
|
123
123
|
onTouchmove: Z,
|
|
124
124
|
onTouchend: W,
|
|
125
|
-
onMousemove:
|
|
126
|
-
onMousedown:
|
|
127
|
-
Z(
|
|
125
|
+
onMousemove: s[0] || (s[0] = (a) => Z(a, !0)),
|
|
126
|
+
onMousedown: s[1] || (s[1] = (a) => {
|
|
127
|
+
Z(a), ye(k) ? k.value = !0 : k = !0;
|
|
128
128
|
})
|
|
129
129
|
}, [
|
|
130
|
-
|
|
131
|
-
width:
|
|
132
|
-
height:
|
|
130
|
+
r("canvas", {
|
|
131
|
+
width: H,
|
|
132
|
+
height: q,
|
|
133
133
|
ref_key: "cvs",
|
|
134
|
-
ref:
|
|
134
|
+
ref: d
|
|
135
135
|
}, null, 512),
|
|
136
|
-
|
|
137
|
-
width:
|
|
138
|
-
height:
|
|
136
|
+
r("canvas", {
|
|
137
|
+
width: H,
|
|
138
|
+
height: q,
|
|
139
139
|
ref_key: "cursorCvs",
|
|
140
|
-
ref:
|
|
140
|
+
ref: C
|
|
141
141
|
}, null, 512)
|
|
142
142
|
], 36));
|
|
143
143
|
}
|
|
144
|
-
}),
|
|
145
|
-
const
|
|
146
|
-
for (const [
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
},
|
|
150
|
-
function
|
|
151
|
-
return /^#([0-9A-F]{3}){1,2}$/i.test(
|
|
144
|
+
}), ee = (m, f) => {
|
|
145
|
+
const g = m.__vccOpts || m;
|
|
146
|
+
for (const [d, C] of f)
|
|
147
|
+
g[d] = C;
|
|
148
|
+
return g;
|
|
149
|
+
}, He = /* @__PURE__ */ ee(Be, [["__scopeId", "data-v-505caf85"]]);
|
|
150
|
+
function le(m) {
|
|
151
|
+
return /^#([0-9A-F]{3}){1,2}$/i.test(m);
|
|
152
152
|
}
|
|
153
|
-
function
|
|
154
|
-
const
|
|
153
|
+
function ce(m) {
|
|
154
|
+
const f = b(!1), g = b("#ff0000"), d = K(() => {
|
|
155
155
|
let l = {};
|
|
156
|
-
return
|
|
156
|
+
return f.value || (l.boxShadow = "none"), m.entryStyles && Object.assign(l, m.entryStyles), f.value && (l.transition = "0s", Object.assign(l, m.entryActiveStyles)), l.backgroundColor = g.value, m.pos === "right" ? l.right = "0px" : l.left = "0px", l;
|
|
157
157
|
});
|
|
158
|
-
function
|
|
159
|
-
|
|
158
|
+
function C() {
|
|
159
|
+
f.value = !1;
|
|
160
160
|
}
|
|
161
|
-
function
|
|
162
|
-
|
|
161
|
+
function c() {
|
|
162
|
+
f.value = !f.value;
|
|
163
163
|
}
|
|
164
|
-
return { hexValue:
|
|
164
|
+
return { hexValue: g, panelShow: f, closePanel: C, togglePanel: c, entryStylesActual: d };
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
function ie() {
|
|
167
|
+
window.alert("https://www.npmjs.com/package/@aurouscia/au-color-picker");
|
|
168
|
+
}
|
|
169
|
+
const Ne = { class: "acpRing" }, _e = { class: "acpParams" }, De = {
|
|
167
170
|
key: 0,
|
|
168
171
|
class: "acpSingleInput"
|
|
169
172
|
}, Me = ["value"], Re = {
|
|
170
173
|
key: 1,
|
|
171
174
|
class: "acpTripleInputs"
|
|
172
|
-
}, Te = ["value"],
|
|
175
|
+
}, Te = ["value"], Ae = ["value"], $e = ["value"], Ee = {
|
|
173
176
|
key: 2,
|
|
174
177
|
class: "acpTripleInputs"
|
|
175
|
-
},
|
|
178
|
+
}, Ve = ["value"], qe = ["value"], Le = ["value"], Oe = { class: "acpDoneBtn" }, Ue = /* @__PURE__ */ Q({
|
|
176
179
|
__name: "AuColorPicker",
|
|
177
180
|
props: {
|
|
178
|
-
|
|
181
|
+
initial: {},
|
|
179
182
|
entryStyles: {},
|
|
180
183
|
entryActiveStyles: {},
|
|
181
184
|
entryClassName: {},
|
|
182
185
|
pos: {},
|
|
183
186
|
panelBaseZIndex: {},
|
|
184
|
-
|
|
187
|
+
showPackageName: { type: Boolean }
|
|
185
188
|
},
|
|
186
189
|
emits: ["change", "done"],
|
|
187
|
-
setup(
|
|
188
|
-
const
|
|
189
|
-
function
|
|
190
|
-
|
|
190
|
+
setup(m, { expose: f, emit: g }) {
|
|
191
|
+
const d = m, C = b(), { hexValue: c, panelShow: l, closePanel: $, togglePanel: w, entryStylesActual: U } = ce(d);
|
|
192
|
+
function D(y) {
|
|
193
|
+
c.value = o(y), R();
|
|
191
194
|
}
|
|
192
|
-
const h = b("hex"),
|
|
193
|
-
function
|
|
194
|
-
var
|
|
195
|
-
const e =
|
|
195
|
+
const h = b("hex"), B = K(() => A.hex.rgb(c.value)), S = K(() => A.hex.hsv(c.value));
|
|
196
|
+
function M(y) {
|
|
197
|
+
var t;
|
|
198
|
+
const e = y.target;
|
|
196
199
|
if ("value" in e) {
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
+
const I = e.value;
|
|
201
|
+
if (I && le(I)) {
|
|
202
|
+
c.value = o(I), (t = C.value) == null || t.enforceTo(c.value), R();
|
|
200
203
|
return;
|
|
201
204
|
}
|
|
202
|
-
e.value =
|
|
205
|
+
e.value = c.value;
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
|
-
function
|
|
206
|
-
var
|
|
207
|
-
const
|
|
208
|
-
if ("value" in
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
let
|
|
212
|
-
if (isNaN(
|
|
213
|
-
|
|
208
|
+
function i(y, e) {
|
|
209
|
+
var I;
|
|
210
|
+
const t = y.target;
|
|
211
|
+
if ("value" in t) {
|
|
212
|
+
const T = t.value;
|
|
213
|
+
if (T) {
|
|
214
|
+
let u = parseInt(T);
|
|
215
|
+
if (isNaN(u))
|
|
216
|
+
t.value = "0";
|
|
214
217
|
else {
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
e == "r" ?
|
|
218
|
+
u > 255 ? u = 255 : u < 0 && (u = 0);
|
|
219
|
+
const k = [...B.value];
|
|
220
|
+
e == "r" ? k[0] = u : e == "g" ? k[1] = u : k[2] = u, c.value = o(A.rgb.hex(k)), (I = C.value) == null || I.enforceTo(c.value), t.value = u.toString(), R();
|
|
218
221
|
return;
|
|
219
222
|
}
|
|
220
223
|
}
|
|
221
224
|
}
|
|
222
225
|
}
|
|
223
|
-
function
|
|
224
|
-
var
|
|
225
|
-
const
|
|
226
|
-
if ("value" in
|
|
227
|
-
const
|
|
228
|
-
if (
|
|
229
|
-
let
|
|
230
|
-
if (isNaN(
|
|
231
|
-
|
|
226
|
+
function p(y, e) {
|
|
227
|
+
var I;
|
|
228
|
+
const t = y.target;
|
|
229
|
+
if ("value" in t) {
|
|
230
|
+
const T = t.value;
|
|
231
|
+
if (T) {
|
|
232
|
+
let u = parseInt(T);
|
|
233
|
+
if (isNaN(u))
|
|
234
|
+
t.value = "0";
|
|
232
235
|
else {
|
|
233
|
-
e === "h" ?
|
|
234
|
-
const
|
|
235
|
-
e == "h" ?
|
|
236
|
+
e === "h" ? u > 359 && (u = 359) : u > 100 && (u = 100), u < 0 && (u = 0);
|
|
237
|
+
const k = [...S.value];
|
|
238
|
+
e == "h" ? k[0] = u : e == "s" ? k[1] = u : k[2] = u, c.value = o(A.hsv.hex(k)), t.value = u.toString(), (I = C.value) == null || I.enforceTo(c.value), R();
|
|
236
239
|
return;
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
}
|
|
240
243
|
}
|
|
241
|
-
function
|
|
242
|
-
return
|
|
244
|
+
function o(y) {
|
|
245
|
+
return y.startsWith("#") ? y.toUpperCase() : "#" + y.toUpperCase();
|
|
243
246
|
}
|
|
244
|
-
function
|
|
245
|
-
z("change",
|
|
247
|
+
function R() {
|
|
248
|
+
z("change", c.value);
|
|
246
249
|
}
|
|
247
|
-
function
|
|
248
|
-
return
|
|
250
|
+
function j() {
|
|
251
|
+
return c.value;
|
|
249
252
|
}
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
re(() => {
|
|
254
|
+
d.initial && le(d.initial) && (c.value = o(d.initial));
|
|
252
255
|
});
|
|
253
|
-
const z =
|
|
254
|
-
return
|
|
255
|
-
|
|
256
|
-
}), (
|
|
256
|
+
const z = g;
|
|
257
|
+
return f({ closePanel: $, getCurrentHex: j }), Y(l, (y) => {
|
|
258
|
+
y === !1 && z("done", c.value);
|
|
259
|
+
}), (y, e) => (N(), _("div", {
|
|
257
260
|
class: "acp",
|
|
258
|
-
onClick: e[
|
|
261
|
+
onClick: e[10] || (e[10] = (t) => t.stopPropagation())
|
|
259
262
|
}, [
|
|
260
|
-
|
|
261
|
-
class:
|
|
262
|
-
style:
|
|
263
|
+
r("div", {
|
|
264
|
+
class: he(y.entryClassName || "acpEntry"),
|
|
265
|
+
style: O(P(U)),
|
|
263
266
|
onClick: e[0] || (e[0] = //@ts-ignore
|
|
264
|
-
(...
|
|
267
|
+
(...t) => P(w) && P(w)(...t))
|
|
265
268
|
}, null, 6),
|
|
266
|
-
|
|
269
|
+
P(l) ? (N(), _("div", {
|
|
267
270
|
key: 0,
|
|
268
271
|
class: "acpPanel",
|
|
269
|
-
style:
|
|
272
|
+
style: O({ zIndex: (y.panelBaseZIndex || 0) + 100 })
|
|
270
273
|
}, [
|
|
271
|
-
|
|
272
|
-
|
|
274
|
+
r("div", Ne, [
|
|
275
|
+
ue(He, {
|
|
273
276
|
ref_key: "ring",
|
|
274
|
-
ref:
|
|
275
|
-
|
|
276
|
-
onChanged:
|
|
277
|
-
|
|
277
|
+
ref: C,
|
|
278
|
+
"initial-hex": P(c),
|
|
279
|
+
onChanged: D,
|
|
280
|
+
"show-package-name": y.showPackageName
|
|
281
|
+
}, null, 8, ["initial-hex", "show-package-name"])
|
|
278
282
|
]),
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
"onUpdate:modelValue": e[1] || (e[1] = (
|
|
282
|
-
}, e[
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
r("div", _e, [
|
|
284
|
+
G(r("select", {
|
|
285
|
+
"onUpdate:modelValue": e[1] || (e[1] = (t) => h.value = t)
|
|
286
|
+
}, e[11] || (e[11] = [
|
|
287
|
+
r("option", { value: "hex" }, "HEX", -1),
|
|
288
|
+
r("option", { value: "rgb" }, "RGB", -1),
|
|
289
|
+
r("option", { value: "hsv" }, "HSV", -1)
|
|
286
290
|
]), 512), [
|
|
287
291
|
[xe, h.value]
|
|
288
292
|
]),
|
|
289
|
-
h.value == "hex" ? (
|
|
290
|
-
|
|
291
|
-
value:
|
|
292
|
-
onBlur:
|
|
293
|
+
h.value == "hex" ? (N(), _("div", De, [
|
|
294
|
+
r("input", {
|
|
295
|
+
value: P(c),
|
|
296
|
+
onBlur: M,
|
|
293
297
|
spellcheck: "false",
|
|
294
298
|
maxlength: "7"
|
|
295
299
|
}, null, 40, Me)
|
|
296
|
-
])) : h.value == "rgb" ? (
|
|
297
|
-
|
|
298
|
-
value:
|
|
299
|
-
onBlur: e[2] || (e[2] = (
|
|
300
|
+
])) : h.value == "rgb" ? (N(), _("div", Re, [
|
|
301
|
+
r("input", {
|
|
302
|
+
value: B.value[0],
|
|
303
|
+
onBlur: e[2] || (e[2] = (t) => i(t, "r"))
|
|
300
304
|
}, null, 40, Te),
|
|
301
|
-
|
|
302
|
-
value:
|
|
303
|
-
onBlur: e[3] || (e[3] = (
|
|
304
|
-
}, null, 40,
|
|
305
|
-
|
|
306
|
-
value:
|
|
307
|
-
onBlur: e[4] || (e[4] = (
|
|
308
|
-
}, null, 40,
|
|
309
|
-
])) : (
|
|
310
|
-
|
|
305
|
+
r("input", {
|
|
306
|
+
value: B.value[1],
|
|
307
|
+
onBlur: e[3] || (e[3] = (t) => i(t, "g"))
|
|
308
|
+
}, null, 40, Ae),
|
|
309
|
+
r("input", {
|
|
310
|
+
value: B.value[2],
|
|
311
|
+
onBlur: e[4] || (e[4] = (t) => i(t, "b"))
|
|
312
|
+
}, null, 40, $e)
|
|
313
|
+
])) : (N(), _("div", Ee, [
|
|
314
|
+
r("input", {
|
|
311
315
|
value: S.value[0],
|
|
312
|
-
onBlur: e[5] || (e[5] = (
|
|
313
|
-
}, null, 40, Ee),
|
|
314
|
-
i("input", {
|
|
315
|
-
value: S.value[1],
|
|
316
|
-
onBlur: e[6] || (e[6] = (s) => g(s, "s"))
|
|
316
|
+
onBlur: e[5] || (e[5] = (t) => p(t, "h"))
|
|
317
317
|
}, null, 40, Ve),
|
|
318
|
-
|
|
318
|
+
r("input", {
|
|
319
|
+
value: S.value[1],
|
|
320
|
+
onBlur: e[6] || (e[6] = (t) => p(t, "s"))
|
|
321
|
+
}, null, 40, qe),
|
|
322
|
+
r("input", {
|
|
319
323
|
value: S.value[2],
|
|
320
|
-
onBlur: e[7] || (e[7] = (
|
|
321
|
-
}, null, 40,
|
|
324
|
+
onBlur: e[7] || (e[7] = (t) => p(t, "v"))
|
|
325
|
+
}, null, 40, Le)
|
|
322
326
|
]))
|
|
323
327
|
]),
|
|
324
|
-
|
|
325
|
-
|
|
328
|
+
r("div", Oe, [
|
|
329
|
+
r("button", {
|
|
326
330
|
onClick: e[8] || (e[8] = //@ts-ignore
|
|
327
|
-
(...
|
|
331
|
+
(...t) => P($) && P($)(...t))
|
|
328
332
|
}, "OK")
|
|
329
|
-
])
|
|
330
|
-
|
|
333
|
+
]),
|
|
334
|
+
y.showPackageName ? (N(), _("div", {
|
|
335
|
+
key: 0,
|
|
336
|
+
class: "acpPackageName",
|
|
337
|
+
onClick: e[9] || (e[9] = //@ts-ignore
|
|
338
|
+
(...t) => P(ie) && P(ie)(...t))
|
|
339
|
+
}, " au-color-picker ")) : J("", !0)
|
|
340
|
+
], 4)) : J("", !0)
|
|
331
341
|
]));
|
|
332
342
|
}
|
|
333
|
-
}),
|
|
343
|
+
}), ze = /* @__PURE__ */ ee(Ue, [["__scopeId", "data-v-9b887c0d"]]), We = { class: "acp" }, Ze = { class: "acpNamedPresets" }, je = { for: "acpColorPresetCustom" }, Xe = ["for"], Fe = ["id", "value", "onClick"], Ke = { class: "acpPresetName" }, Ye = { class: "acpDoneBtn" }, Ge = /* @__PURE__ */ Q({
|
|
334
344
|
__name: "AuColorPickerPresetsNested",
|
|
335
345
|
props: {
|
|
336
|
-
|
|
346
|
+
initialSelectedPreset: {},
|
|
347
|
+
presets: {},
|
|
348
|
+
initial: {},
|
|
337
349
|
entryStyles: {},
|
|
338
350
|
entryActiveStyles: {},
|
|
339
351
|
entryClassName: {},
|
|
340
352
|
pos: {},
|
|
341
353
|
panelBaseZIndex: {},
|
|
342
|
-
|
|
354
|
+
showPackageName: { type: Boolean }
|
|
343
355
|
},
|
|
344
|
-
emits: ["change", "done"],
|
|
345
|
-
setup(
|
|
346
|
-
const
|
|
347
|
-
function h(
|
|
348
|
-
|
|
356
|
+
emits: ["change", "done", "presetSwitched"],
|
|
357
|
+
setup(m, { emit: f }) {
|
|
358
|
+
const g = m, { hexValue: d, panelShow: C, closePanel: c, togglePanel: l, entryStylesActual: $ } = ce(g), w = b(), U = b(), D = b("#ff0000");
|
|
359
|
+
function h(i) {
|
|
360
|
+
i ? (w.value = i.name, d.value = i.colorHex) : (w.value = void 0, d.value = D.value);
|
|
349
361
|
}
|
|
350
|
-
const
|
|
351
|
-
function S(
|
|
352
|
-
|
|
362
|
+
const B = f;
|
|
363
|
+
function S(i) {
|
|
364
|
+
d.value = i, D.value = i, B("change", i);
|
|
353
365
|
}
|
|
354
|
-
function
|
|
355
|
-
|
|
366
|
+
function M(i) {
|
|
367
|
+
d.value = i, D.value = i, c();
|
|
356
368
|
}
|
|
357
|
-
return
|
|
358
|
-
|
|
359
|
-
}),
|
|
360
|
-
|
|
361
|
-
}), (
|
|
362
|
-
i
|
|
369
|
+
return Y(C, (i) => {
|
|
370
|
+
i === !1 && B("done", d.value);
|
|
371
|
+
}), Y(w, (i) => {
|
|
372
|
+
B("presetSwitched", i);
|
|
373
|
+
}), re(() => {
|
|
374
|
+
var i;
|
|
375
|
+
if (g.initial && (d.value = g.initial, D.value = g.initial), g.initialSelectedPreset) {
|
|
376
|
+
const p = (i = g.presets) == null ? void 0 : i.find((o) => o.name === g.initialSelectedPreset);
|
|
377
|
+
p && h(p);
|
|
378
|
+
}
|
|
379
|
+
}), (i, p) => (N(), _("div", We, [
|
|
380
|
+
r("div", {
|
|
363
381
|
class: "acpEntry",
|
|
364
|
-
style:
|
|
365
|
-
onClick:
|
|
366
|
-
(...
|
|
382
|
+
style: O(P($)),
|
|
383
|
+
onClick: p[0] || (p[0] = //@ts-ignore
|
|
384
|
+
(...o) => P(l) && P(l)(...o))
|
|
367
385
|
}, null, 4),
|
|
368
|
-
|
|
386
|
+
P(C) ? (N(), _("div", {
|
|
369
387
|
key: 0,
|
|
370
388
|
class: "acpPanel",
|
|
371
|
-
style:
|
|
389
|
+
style: O({ zIndex: (i.panelBaseZIndex || 0) + 100 })
|
|
372
390
|
}, [
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
391
|
+
r("div", Ze, [
|
|
392
|
+
r("label", je, [
|
|
393
|
+
ue(ze, {
|
|
394
|
+
initial: D.value,
|
|
377
395
|
onChange: S,
|
|
378
|
-
onDone:
|
|
396
|
+
onDone: M,
|
|
379
397
|
"entry-class-name": "acpPresetBody",
|
|
380
398
|
ref_key: "customPicker",
|
|
381
|
-
ref:
|
|
382
|
-
|
|
383
|
-
|
|
399
|
+
ref: U,
|
|
400
|
+
"show-package-name": i.showPackageName
|
|
401
|
+
}, null, 8, ["initial", "show-package-name"]),
|
|
402
|
+
G(r("input", {
|
|
384
403
|
name: "colorType",
|
|
385
404
|
type: "radio",
|
|
386
405
|
id: "acpColorPresetCustom",
|
|
387
406
|
value: void 0,
|
|
388
|
-
"onUpdate:modelValue":
|
|
389
|
-
onClick:
|
|
407
|
+
"onUpdate:modelValue": p[1] || (p[1] = (o) => w.value = o),
|
|
408
|
+
onClick: p[2] || (p[2] = (o) => h())
|
|
390
409
|
}, null, 512), [
|
|
391
|
-
[
|
|
410
|
+
[te, w.value]
|
|
392
411
|
]),
|
|
393
|
-
|
|
412
|
+
p[5] || (p[5] = r("div", { class: "acpPresetName" }, "自定义", -1))
|
|
394
413
|
]),
|
|
395
|
-
|
|
396
|
-
(
|
|
397
|
-
for: `acpColorPreset${
|
|
414
|
+
p[6] || (p[6] = r("div", { class: "acpSep" }, null, -1)),
|
|
415
|
+
(N(!0), _(Pe, null, ke(i.presets, (o) => (N(), _("label", {
|
|
416
|
+
for: `acpColorPreset${o.name}`
|
|
398
417
|
}, [
|
|
399
|
-
|
|
418
|
+
r("div", {
|
|
400
419
|
class: "acpPresetBody",
|
|
401
|
-
style:
|
|
420
|
+
style: O({ backgroundColor: o.colorHex })
|
|
402
421
|
}, null, 4),
|
|
403
|
-
|
|
422
|
+
G(r("input", {
|
|
404
423
|
name: "colorType",
|
|
405
424
|
type: "radio",
|
|
406
|
-
id: `acpColorPreset${
|
|
407
|
-
value:
|
|
408
|
-
"onUpdate:modelValue":
|
|
409
|
-
onClick: (
|
|
410
|
-
}, null, 8,
|
|
411
|
-
[
|
|
425
|
+
id: `acpColorPreset${o.name}`,
|
|
426
|
+
value: o.name,
|
|
427
|
+
"onUpdate:modelValue": p[3] || (p[3] = (R) => w.value = R),
|
|
428
|
+
onClick: (R) => h(o)
|
|
429
|
+
}, null, 8, Fe), [
|
|
430
|
+
[te, w.value]
|
|
412
431
|
]),
|
|
413
|
-
|
|
432
|
+
r("div", Ke, Ce(o.name), 1)
|
|
414
433
|
], 8, Xe))), 256)),
|
|
415
|
-
|
|
434
|
+
p[7] || (p[7] = r("div", { class: "acpSep" }, null, -1))
|
|
416
435
|
]),
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
onClick:
|
|
420
|
-
(...
|
|
436
|
+
r("div", Ye, [
|
|
437
|
+
r("button", {
|
|
438
|
+
onClick: p[4] || (p[4] = //@ts-ignore
|
|
439
|
+
(...o) => P(c) && P(c)(...o))
|
|
421
440
|
}, "OK")
|
|
422
441
|
])
|
|
423
|
-
], 4)) :
|
|
442
|
+
], 4)) : J("", !0)
|
|
424
443
|
]));
|
|
425
444
|
}
|
|
426
|
-
}),
|
|
445
|
+
}), et = /* @__PURE__ */ ee(Ge, [["__scopeId", "data-v-e312908b"]]);
|
|
427
446
|
export {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
447
|
+
ze as AuColorPicker,
|
|
448
|
+
et as AuColorPickerPresetsNested,
|
|
449
|
+
He as AuColorPickerRing
|
|
431
450
|
};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.acpRingBody[data-v-505caf85]{position:relative}canvas[data-v-505caf85]{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%}[data-v-
|
|
1
|
+
.acpRingBody[data-v-505caf85]{position:relative}canvas[data-v-505caf85]{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%}[data-v-9b887c0d]{margin:0;padding:0}.acpSep[data-v-9b887c0d]{height:2px;border-radius:100px;flex-grow:0;flex-shrink:0;background-color:#ddd}.acpPresetBody[data-v-9b887c0d]{width:25px;height:25px;border-radius:1000px;cursor:pointer}.acpDoneBtn[data-v-9b887c0d]{display:flex;justify-content:center;align-items:center;margin:8px}.acpDoneBtn button[data-v-9b887c0d]{background:none;border:none;font-weight:700;color:gray;font-size:16px;cursor:pointer}.acpDoneBtn button[data-v-9b887c0d]:hover{color:#000}.acpEntry[data-v-9b887c0d]{width:30px;height:30px;cursor:pointer;border-radius:5px;box-shadow:0 0 5px #000;background-color:#fff}.acpPanel[data-v-9b887c0d]{border-radius:5px;box-shadow:0 0 5px #000;background-color:#fff;margin-top:3px;position:absolute}.acp[data-v-9b887c0d]{position:relative;width:fit-content}.acp label[data-v-9b887c0d]{-webkit-user-select:none;user-select:none;white-space:nowrap;cursor:pointer}.acp input[type=radio][data-v-9b887c0d]{cursor:pointer}.acpPackageName[data-v-9b887c0d]{position:absolute;left:2px;bottom:3px;font-size:8px;color:#ccc;text-align:right;cursor:pointer}.acpParams[data-v-9b887c0d]{display:flex;justify-content:space-between;align-items:center;padding:5px}.acpParams select[data-v-9b887c0d],.acpParams input[data-v-9b887c0d]{margin:0;padding:2px;display:block;font-size:16px;box-sizing:border-box;height:24px;line-height:24px}.acpParams input[data-v-9b887c0d]{text-align:center}.acpParams .acpSingleInput input[data-v-9b887c0d]{width:120px}.acpParams .acpTripleInputs[data-v-9b887c0d]{display:flex;justify-content:space-around}.acpParams .acpTripleInputs input[data-v-9b887c0d]{width:40px}[data-v-e312908b]{margin:0;padding:0}.acpSep[data-v-e312908b]{height:2px;border-radius:100px;flex-grow:0;flex-shrink:0;background-color:#ddd}.acpPresetBody[data-v-e312908b]{width:25px;height:25px;border-radius:1000px;cursor:pointer}.acpDoneBtn[data-v-e312908b]{display:flex;justify-content:center;align-items:center;margin:8px}.acpDoneBtn button[data-v-e312908b]{background:none;border:none;font-weight:700;color:gray;font-size:16px;cursor:pointer}.acpDoneBtn button[data-v-e312908b]:hover{color:#000}.acpEntry[data-v-e312908b]{width:30px;height:30px;cursor:pointer;border-radius:5px;box-shadow:0 0 5px #000;background-color:#fff}.acpPanel[data-v-e312908b]{border-radius:5px;box-shadow:0 0 5px #000;background-color:#fff;margin-top:3px;position:absolute}.acp[data-v-e312908b]{position:relative;width:fit-content}.acp label[data-v-e312908b]{-webkit-user-select:none;user-select:none;white-space:nowrap;cursor:pointer}.acp input[type=radio][data-v-e312908b]{cursor:pointer}.acpNamedPresets[data-v-e312908b]{margin:5px;display:flex;flex-direction:column;gap:4px}.acpNamedPresets[data-v-e312908b]>*{display:flex;justify-content:flex-start;align-items:center;gap:5px}.acpNamedPresets>* .acpPresetName[data-v-e312908b]{color:#666}.acpNamedPresets>* .acpPresetName[data-v-e312908b]:hover{color:#000}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const _default: import('vue').DefineComponent<
|
|
1
|
+
import { PickerWithPresetsProps } from './common/pickerProps';
|
|
2
|
+
declare const _default: import('vue').DefineComponent<PickerWithPresetsProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
3
3
|
done: (hexStr: string) => any;
|
|
4
4
|
change: (hexStr: string) => any;
|
|
5
|
-
|
|
5
|
+
presetSwitched: (name: string | undefined) => any;
|
|
6
|
+
}, string, import('vue').PublicProps, Readonly<PickerWithPresetsProps> & Readonly<{
|
|
6
7
|
onDone?: ((hexStr: string) => any) | undefined;
|
|
7
8
|
onChange?: ((hexStr: string) => any) | undefined;
|
|
9
|
+
onPresetSwitched?: ((name: string | undefined) => any) | undefined;
|
|
8
10
|
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
9
11
|
export default _default;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { CSSProperties } from 'vue';
|
|
2
2
|
export interface PickerProps {
|
|
3
|
-
|
|
3
|
+
initial?: string;
|
|
4
4
|
entryStyles?: CSSProperties;
|
|
5
5
|
entryActiveStyles?: CSSProperties;
|
|
6
6
|
entryClassName?: string;
|
|
7
7
|
pos?: 'left' | 'right';
|
|
8
8
|
panelBaseZIndex?: number;
|
|
9
|
+
showPackageName?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface PickerWithPresetsProps extends PickerProps {
|
|
12
|
+
initialSelectedPreset?: string;
|
|
9
13
|
presets?: NamedPreset[];
|
|
10
14
|
}
|
|
11
15
|
export interface NamedPreset {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { default as AuColorPicker } from './components/AuColorPicker.vue';
|
|
2
2
|
export { default as AuColorPickerRing } from './components/AuColorPickerRing.vue';
|
|
3
3
|
export { default as AuColorPickerPresetsNested } from './components/AuColorPickerPresetsNested.vue';
|
|
4
|
+
export type * from './components/common/pickerProps';
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"color",
|
|
15
15
|
"component"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.2.0",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/color-convert": "^2.0.4",
|
|
44
|
-
"@types/node": "^22.10.
|
|
45
|
-
"@vitejs/plugin-vue": "^5.2.
|
|
44
|
+
"@types/node": "^22.10.1",
|
|
45
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
46
46
|
"sass": "^1.81.0",
|
|
47
|
-
"typescript": "5.
|
|
47
|
+
"typescript": "^5.7.2",
|
|
48
48
|
"vite": "^5.4.11",
|
|
49
49
|
"vite-plugin-dts": "^4.3.0"
|
|
50
50
|
}
|