@aurouscia/au-color-picker 0.1.0 → 0.1.2

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