@memobit/libs 3.1.3 → 3.1.5

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.
@@ -1 +1 @@
1
- .color-picker{gap:var(--spacing-12);border:1px solid var(--delimiter-color);border-radius:var(--radius);padding:var(--spacing-16);background:var(--card-background-color);flex-direction:column;width:320px;display:flex}.color-picker__preview{border-radius:var(--radius);border:1px solid var(--delimiter-color);width:100%;height:40px}.color-picker__controls{gap:var(--spacing-12);flex-direction:column;display:flex}.color-picker__sv{border-radius:var(--radius);cursor:crosshair;touch-action:none;-webkit-user-select:none;user-select:none;width:100%;height:180px;position:relative;overflow:hidden}.color-picker__sv-white,.color-picker__sv-black{position:absolute;inset:0}.color-picker__sv-white{background:linear-gradient(90deg,#fff,#fff0)}.color-picker__sv-black{background:linear-gradient(#0000,#000)}.color-picker__sv-handle{border:2px solid #fff;border-radius:50%;width:12px;height:12px;position:absolute;transform:translate(-6px,-6px);box-shadow:0 0 0 1px #0000004d}.color-picker__slider input[type=range]{width:100%}.color-picker__mode-toggle{gap:var(--spacing-8);display:flex}.color-picker__mode-toggle .button{padding:6px 10px}.color-picker__mode-toggle .button.is-active{border:1px solid var(--body-accent-color);color:var(--body-accent-color)}.color-picker__fields{gap:var(--spacing-8);grid-template-columns:1fr;display:grid}.color-picker__fields .input-text-wrapper,.color-picker__fields .input-number-wrapper{width:100%}.color-picker__fields--rgb,.color-picker__fields--hsl,.color-picker__fields--hex{grid-template-columns:repeat(3,1fr)}.color-picker__fields--hex .input-text-wrapper{grid-column:span 3}
1
+ .color-picker{gap:var(--spacing-12);border:1px solid var(--delimiter-color);border-radius:var(--radius);padding:var(--spacing-16);background:var(--card-background-color);flex-direction:column;width:320px;display:flex}.color-picker__swatches{gap:var(--spacing-6);flex-direction:column;display:flex}.color-picker__swatches-label{font-size:var(--font-size-xxs);color:var(--body-sub-title-color)}.color-picker__swatches-row{gap:var(--spacing-6);flex-wrap:wrap;display:flex}.color-picker__swatch{width:var(--spacing-20);height:var(--spacing-20);border:1px solid var(--delimiter-color);cursor:pointer;transition:transform var(--transition-fast);border-radius:50%;padding:0}.color-picker__swatch:hover{transform:scale(1.15)}.color-picker__swatch.is-selected{outline:2px solid var(--body-accent-color);outline-offset:2px}.color-picker__preview{border-radius:var(--radius);border:1px solid var(--delimiter-color);width:100%;height:40px}.color-picker__controls{gap:var(--spacing-12);flex-direction:column;display:flex}.color-picker__sv{border-radius:var(--radius);cursor:crosshair;touch-action:none;-webkit-user-select:none;user-select:none;width:100%;height:180px;position:relative;overflow:hidden}.color-picker__sv-white,.color-picker__sv-black{position:absolute;inset:0}.color-picker__sv-white{background:linear-gradient(90deg,#fff,#fff0)}.color-picker__sv-black{background:linear-gradient(#0000,#000)}.color-picker__sv-handle{border:2px solid #fff;border-radius:50%;width:12px;height:12px;position:absolute;transform:translate(-6px,-6px);box-shadow:0 0 0 1px #0000004d}.color-picker__slider input[type=range]{width:100%}.color-picker__mode-toggle{gap:var(--spacing-8);display:flex}.color-picker__mode-toggle .button{padding:6px 10px}.color-picker__mode-toggle .button.is-active{border:1px solid var(--body-accent-color);color:var(--body-accent-color)}.color-picker__fields{gap:var(--spacing-8);grid-template-columns:1fr;display:grid}.color-picker__fields .input-text-wrapper,.color-picker__fields .input-number-wrapper{width:100%}.color-picker__fields--rgb,.color-picker__fields--hsl,.color-picker__fields--hex{grid-template-columns:repeat(3,1fr)}.color-picker__fields--hex .input-text-wrapper{grid-column:span 3}
@@ -1,250 +1,280 @@
1
1
  import './ColorPicker.css';
2
- import { Button as N } from "../Button/Button2.js";
3
- import { InputNumber as b } from "../InputNumber/InputNumber2.js";
4
- import { InputText as j } from "../InputText/InputText2.js";
2
+ import { Button as H } from "../Button/Button2.js";
3
+ import { Tooltip as G } from "../Tooltip/Tooltip2.js";
4
+ import { InputNumber as N } from "../InputNumber/InputNumber2.js";
5
+ import { InputText as X } from "../InputText/InputText2.js";
5
6
  /* empty css */
6
- import { useEffect as B, useRef as R, useState as H } from "react";
7
- import { jsx as m, jsxs as x } from "react/jsx-runtime";
8
- var _ = (s, h, i) => Math.min(i, Math.max(h, s)), k = (s) => {
9
- const h = s.replace("#", "").trim();
10
- if (![3, 6].includes(h.length)) return null;
11
- const i = h.length === 3 ? h.split("").map((o) => o + o).join("") : h, l = parseInt(i, 16);
12
- return Number.isNaN(l) ? null : {
13
- r: l >> 16 & 255,
14
- g: l >> 8 & 255,
15
- b: l & 255
7
+ import { useEffect as Y, useMemo as A, useRef as B, useState as y } from "react";
8
+ import { jsx as d, jsxs as b } from "react/jsx-runtime";
9
+ var k = (t, i, h) => Math.min(h, Math.max(i, t)), x = (t) => {
10
+ const i = t.replace("#", "").trim();
11
+ if (![3, 6].includes(i.length)) return null;
12
+ const h = i.length === 3 ? i.split("").map((s) => s + s).join("") : i, c = parseInt(h, 16);
13
+ return Number.isNaN(c) ? null : {
14
+ r: c >> 16 & 255,
15
+ g: c >> 8 & 255,
16
+ b: c & 255
16
17
  };
17
- }, L = ({ r: s, g: h, b: i }) => `#${[
18
- s,
19
- h,
20
- i
21
- ].map((l) => _(Math.round(l), 0, 255).toString(16).padStart(2, "0")).join("")}`, g = ({ r: s, g: h, b: i }) => {
22
- const l = s / 255, o = h / 255, t = i / 255, r = Math.max(l, o, t), c = r - Math.min(l, o, t);
23
- let e = 0;
24
- c !== 0 && (r === l ? e = (o - t) / c % 6 : r === o ? e = (t - l) / c + 2 : e = (l - o) / c + 4, e = Math.round(e * 60), e < 0 && (e += 360));
25
- const a = r === 0 ? 0 : c / r, d = r;
18
+ }, L = (t) => {
19
+ const i = t.trim().replace("#", "").toLowerCase();
20
+ return `#${i.length === 3 ? i.split("").map((h) => h + h).join("") : i}`;
21
+ }, R = ({ r: t, g: i, b: h }) => `#${[
22
+ t,
23
+ i,
24
+ h
25
+ ].map((c) => k(Math.round(c), 0, 255).toString(16).padStart(2, "0")).join("")}`, v = ({ r: t, g: i, b: h }) => {
26
+ const c = t / 255, s = i / 255, r = h / 255, o = Math.max(c, s, r), l = o - Math.min(c, s, r);
27
+ let n = 0;
28
+ l !== 0 && (o === c ? n = (s - r) / l % 6 : o === s ? n = (r - c) / l + 2 : n = (c - s) / l + 4, n = Math.round(n * 60), n < 0 && (n += 360));
29
+ const a = o === 0 ? 0 : l / o, m = o;
26
30
  return {
27
- h: e,
31
+ h: n,
28
32
  s: Math.round(a * 100),
29
- v: Math.round(d * 100)
33
+ v: Math.round(m * 100)
30
34
  };
31
- }, T = ({ h: s, s: h, v: i }) => {
32
- const l = h / 100, o = i / 100, t = o * l, r = t * (1 - Math.abs(s / 60 % 2 - 1)), c = o - t;
33
- let e = 0, a = 0, d = 0;
34
- return s < 60 ? (e = t, a = r) : s < 120 ? (e = r, a = t) : s < 180 ? (a = t, d = r) : s < 240 ? (a = r, d = t) : s < 300 ? (e = r, d = t) : (e = t, d = r), {
35
- r: Math.round((e + c) * 255),
36
- g: Math.round((a + c) * 255),
37
- b: Math.round((d + c) * 255)
35
+ }, E = ({ h: t, s: i, v: h }) => {
36
+ const c = i / 100, s = h / 100, r = s * c, o = r * (1 - Math.abs(t / 60 % 2 - 1)), l = s - r;
37
+ let n = 0, a = 0, m = 0;
38
+ return t < 60 ? (n = r, a = o) : t < 120 ? (n = o, a = r) : t < 180 ? (a = r, m = o) : t < 240 ? (a = o, m = r) : t < 300 ? (n = o, m = r) : (n = r, m = o), {
39
+ r: Math.round((n + l) * 255),
40
+ g: Math.round((a + l) * 255),
41
+ b: Math.round((m + l) * 255)
38
42
  };
39
- }, I = ({ r: s, g: h, b: i }) => {
40
- const l = s / 255, o = h / 255, t = i / 255, r = Math.max(l, o, t), c = Math.min(l, o, t), e = r - c;
43
+ }, F = ({ r: t, g: i, b: h }) => {
44
+ const c = t / 255, s = i / 255, r = h / 255, o = Math.max(c, s, r), l = Math.min(c, s, r), n = o - l;
41
45
  let a = 0;
42
- e !== 0 && (r === l ? a = (o - t) / e % 6 : r === o ? a = (t - l) / e + 2 : a = (l - o) / e + 4, a = Math.round(a * 60), a < 0 && (a += 360));
43
- const d = (r + c) / 2, p = e === 0 ? 0 : e / (1 - Math.abs(2 * d - 1));
46
+ n !== 0 && (o === c ? a = (s - r) / n % 6 : o === s ? a = (r - c) / n + 2 : a = (c - s) / n + 4, a = Math.round(a * 60), a < 0 && (a += 360));
47
+ const m = (o + l) / 2, M = n === 0 ? 0 : n / (1 - Math.abs(2 * m - 1));
44
48
  return {
45
49
  h: a,
46
- s: Math.round(p * 100),
47
- l: Math.round(d * 100)
50
+ s: Math.round(M * 100),
51
+ l: Math.round(m * 100)
48
52
  };
49
- }, w = ({ h: s, s: h, l: i }) => {
50
- const l = h / 100, o = i / 100, t = (1 - Math.abs(2 * o - 1)) * l, r = t * (1 - Math.abs(s / 60 % 2 - 1)), c = o - t / 2;
51
- let e = 0, a = 0, d = 0;
52
- return s < 60 ? (e = t, a = r) : s < 120 ? (e = r, a = t) : s < 180 ? (a = t, d = r) : s < 240 ? (a = r, d = t) : s < 300 ? (e = r, d = t) : (e = t, d = r), {
53
- r: Math.round((e + c) * 255),
54
- g: Math.round((a + c) * 255),
55
- b: Math.round((d + c) * 255)
53
+ }, T = ({ h: t, s: i, l: h }) => {
54
+ const c = i / 100, s = h / 100, r = (1 - Math.abs(2 * s - 1)) * c, o = r * (1 - Math.abs(t / 60 % 2 - 1)), l = s - r / 2;
55
+ let n = 0, a = 0, m = 0;
56
+ return t < 60 ? (n = r, a = o) : t < 120 ? (n = o, a = r) : t < 180 ? (a = r, m = o) : t < 240 ? (a = o, m = r) : t < 300 ? (n = o, m = r) : (n = r, m = o), {
57
+ r: Math.round((n + l) * 255),
58
+ g: Math.round((a + l) * 255),
59
+ b: Math.round((m + l) * 255)
56
60
  };
57
- }, F = ({ value: s = "#4e79a7", onChange: h }) => {
58
- const [i, l] = H("hex"), [o, t] = H(() => {
59
- const n = k(s) || {
61
+ }, Z = ({ value: t = "#4e79a7", onChange: i, swatches: h, swatchesLabel: c = "Already in use" }) => {
62
+ const [s, r] = y("hex"), o = A(() => {
63
+ const e = /* @__PURE__ */ new Set();
64
+ return (h ?? []).forEach((p) => {
65
+ const u = x(p);
66
+ u && e.add(R(u));
67
+ }), [...e];
68
+ }, [h]), [l, n] = y(() => {
69
+ const e = x(t) || {
60
70
  r: 78,
61
71
  g: 121,
62
72
  b: 167
63
73
  };
64
- return g(n);
65
- }), r = R(null), c = R(o);
66
- c.current = o, B(() => {
67
- const n = k(s);
68
- n && t(g(n));
69
- }, [s]);
70
- const e = (n) => {
71
- const v = {
72
- h: _(n.h, 0, 360),
73
- s: _(n.s, 0, 100),
74
- v: _(n.v, 0, 100)
74
+ return v(e);
75
+ }), [a, m] = y(() => x(t) ? L(t) : null), M = B(null), S = B(l);
76
+ S.current = l, Y(() => {
77
+ const e = x(t);
78
+ e && (n(v(e)), m(L(t)));
79
+ }, [t]);
80
+ const g = (e) => {
81
+ const p = {
82
+ h: k(e.h, 0, 360),
83
+ s: k(e.s, 0, 100),
84
+ v: k(e.v, 0, 100)
75
85
  };
76
- t(v);
77
- const u = L(T(v));
78
- h?.(u);
79
- }, a = (n, v) => {
80
- const u = r.current?.getBoundingClientRect();
86
+ n(p), m(null);
87
+ const u = R(E(p));
88
+ i?.(u);
89
+ }, $ = (e) => {
90
+ const p = x(e);
91
+ p && (n(v(p)), m(L(e)), i?.(e));
92
+ }, j = (e, p) => {
93
+ const u = M.current?.getBoundingClientRect();
81
94
  if (!u) return;
82
- const M = _(n - u.left, 0, u.width), y = _(v - u.top, 0, u.height), S = Math.round(M / u.width * 100), E = Math.round(100 - y / u.height * 100);
83
- e({
84
- h: c.current.h,
85
- s: S,
86
- v: E
95
+ const w = k(e - u.left, 0, u.width), P = k(p - u.top, 0, u.height), z = Math.round(w / u.width * 100), D = Math.round(100 - P / u.height * 100);
96
+ g({
97
+ h: S.current.h,
98
+ s: z,
99
+ v: D
87
100
  });
88
- }, d = (n) => {
89
- n.preventDefault();
101
+ }, I = (e) => {
102
+ e.preventDefault();
90
103
  try {
91
- n.currentTarget.setPointerCapture(n.pointerId);
104
+ e.currentTarget.setPointerCapture(e.pointerId);
92
105
  } catch {
93
106
  }
94
- a(n.clientX, n.clientY);
95
- const v = (M) => a(M.clientX, M.clientY), u = () => {
96
- window.removeEventListener("pointermove", v), window.removeEventListener("pointerup", u), window.removeEventListener("pointercancel", u);
107
+ j(e.clientX, e.clientY);
108
+ const p = (w) => j(w.clientX, w.clientY), u = () => {
109
+ window.removeEventListener("pointermove", p), window.removeEventListener("pointerup", u), window.removeEventListener("pointercancel", u);
97
110
  };
98
- window.addEventListener("pointermove", v), window.addEventListener("pointerup", u), window.addEventListener("pointercancel", u);
99
- }, p = T(o), C = L(p), f = I(p);
100
- return /* @__PURE__ */ x("div", {
111
+ window.addEventListener("pointermove", p), window.addEventListener("pointerup", u), window.addEventListener("pointercancel", u);
112
+ }, f = a ? x(a) ?? E(l) : E(l), C = a ?? R(f), _ = F(f);
113
+ return /* @__PURE__ */ b("div", {
101
114
  className: "color-picker",
102
115
  children: [
103
- /* @__PURE__ */ m("div", {
116
+ o.length > 0 && /* @__PURE__ */ b("div", {
117
+ className: "color-picker__swatches",
118
+ children: [/* @__PURE__ */ d("span", {
119
+ className: "color-picker__swatches-label",
120
+ children: c
121
+ }), /* @__PURE__ */ d("div", {
122
+ className: "color-picker__swatches-row",
123
+ children: o.map((e) => /* @__PURE__ */ d(G, {
124
+ title: e,
125
+ children: /* @__PURE__ */ d("button", {
126
+ className: `color-picker__swatch${e === C.toLowerCase() ? " is-selected" : ""}`,
127
+ onClick: () => $(e),
128
+ style: { backgroundColor: e },
129
+ type: "button"
130
+ })
131
+ }, e))
132
+ })]
133
+ }),
134
+ /* @__PURE__ */ d("div", {
104
135
  className: "color-picker__preview",
105
136
  style: { backgroundColor: C }
106
137
  }),
107
- /* @__PURE__ */ x("div", {
138
+ /* @__PURE__ */ b("div", {
108
139
  className: "color-picker__controls",
109
- children: [/* @__PURE__ */ x("div", {
140
+ children: [/* @__PURE__ */ b("div", {
110
141
  className: "color-picker__sv",
111
- ref: r,
112
- style: { backgroundColor: `hsl(${o.h}, 100%, 50%)` },
113
- onPointerDown: d,
142
+ ref: M,
143
+ style: { backgroundColor: `hsl(${l.h}, 100%, 50%)` },
144
+ onPointerDown: I,
114
145
  children: [
115
- /* @__PURE__ */ m("div", { className: "color-picker__sv-white" }),
116
- /* @__PURE__ */ m("div", { className: "color-picker__sv-black" }),
117
- /* @__PURE__ */ m("div", {
146
+ /* @__PURE__ */ d("div", { className: "color-picker__sv-white" }),
147
+ /* @__PURE__ */ d("div", { className: "color-picker__sv-black" }),
148
+ /* @__PURE__ */ d("div", {
118
149
  className: "color-picker__sv-handle",
119
150
  style: {
120
- left: `${o.s}%`,
121
- top: `${100 - o.v}%`
151
+ left: `${l.s}%`,
152
+ top: `${100 - l.v}%`
122
153
  }
123
154
  })
124
155
  ]
125
- }), /* @__PURE__ */ m("div", {
156
+ }), /* @__PURE__ */ d("div", {
126
157
  className: "color-picker__slider",
127
- children: /* @__PURE__ */ m("input", {
158
+ children: /* @__PURE__ */ d("input", {
128
159
  type: "range",
129
160
  min: 0,
130
161
  max: 360,
131
- value: o.h,
132
- onChange: (n) => e({
133
- ...o,
134
- h: Number(n.target.value)
162
+ value: l.h,
163
+ onChange: (e) => g({
164
+ ...l,
165
+ h: Number(e.target.value)
135
166
  })
136
167
  })
137
168
  })]
138
169
  }),
139
- /* @__PURE__ */ x("div", {
170
+ /* @__PURE__ */ b("div", {
140
171
  className: "color-picker__mode-toggle",
141
172
  children: [
142
- /* @__PURE__ */ m(N, {
173
+ /* @__PURE__ */ d(H, {
143
174
  variant: "plain",
144
- className: i === "hex" ? "is-active" : "",
145
- onClick: () => l("hex"),
175
+ className: s === "hex" ? "is-active" : "",
176
+ onClick: () => r("hex"),
146
177
  children: "Hex"
147
178
  }),
148
- /* @__PURE__ */ m(N, {
179
+ /* @__PURE__ */ d(H, {
149
180
  variant: "plain",
150
- className: i === "rgb" ? "is-active" : "",
151
- onClick: () => l("rgb"),
181
+ className: s === "rgb" ? "is-active" : "",
182
+ onClick: () => r("rgb"),
152
183
  children: "RGB"
153
184
  }),
154
- /* @__PURE__ */ m(N, {
185
+ /* @__PURE__ */ d(H, {
155
186
  variant: "plain",
156
- className: i === "hsl" ? "is-active" : "",
157
- onClick: () => l("hsl"),
187
+ className: s === "hsl" ? "is-active" : "",
188
+ onClick: () => r("hsl"),
158
189
  children: "HSL"
159
190
  })
160
191
  ]
161
192
  }),
162
- i === "hex" && /* @__PURE__ */ m("div", {
193
+ s === "hex" && /* @__PURE__ */ d("div", {
163
194
  className: "color-picker__fields color-picker__fields--hex",
164
- children: /* @__PURE__ */ m(j, {
195
+ children: /* @__PURE__ */ d(X, {
165
196
  label: "Hex",
166
197
  value: C,
167
- onChange: (n) => {
168
- const v = k(n);
169
- v && e(g(v));
198
+ onChange: (e) => {
199
+ x(e) && $(e.startsWith("#") ? e : `#${e}`);
170
200
  }
171
201
  })
172
202
  }),
173
- i === "rgb" && /* @__PURE__ */ x("div", {
203
+ s === "rgb" && /* @__PURE__ */ b("div", {
174
204
  className: "color-picker__fields color-picker__fields--rgb",
175
205
  children: [
176
- /* @__PURE__ */ m(b, {
206
+ /* @__PURE__ */ d(N, {
177
207
  label: "R",
178
208
  min: 0,
179
209
  max: 255,
180
- value: p.r,
181
- onChange: (n) => e(g({
182
- ...p,
183
- r: n ?? 0
210
+ value: f.r,
211
+ onChange: (e) => g(v({
212
+ ...f,
213
+ r: e ?? 0
184
214
  }))
185
215
  }),
186
- /* @__PURE__ */ m(b, {
216
+ /* @__PURE__ */ d(N, {
187
217
  label: "G",
188
218
  min: 0,
189
219
  max: 255,
190
- value: p.g,
191
- onChange: (n) => e(g({
192
- ...p,
193
- g: n ?? 0
220
+ value: f.g,
221
+ onChange: (e) => g(v({
222
+ ...f,
223
+ g: e ?? 0
194
224
  }))
195
225
  }),
196
- /* @__PURE__ */ m(b, {
226
+ /* @__PURE__ */ d(N, {
197
227
  label: "B",
198
228
  min: 0,
199
229
  max: 255,
200
- value: p.b,
201
- onChange: (n) => e(g({
202
- ...p,
203
- b: n ?? 0
230
+ value: f.b,
231
+ onChange: (e) => g(v({
232
+ ...f,
233
+ b: e ?? 0
204
234
  }))
205
235
  })
206
236
  ]
207
237
  }),
208
- i === "hsl" && /* @__PURE__ */ x("div", {
238
+ s === "hsl" && /* @__PURE__ */ b("div", {
209
239
  className: "color-picker__fields color-picker__fields--hsl",
210
240
  children: [
211
- /* @__PURE__ */ m(b, {
241
+ /* @__PURE__ */ d(N, {
212
242
  label: "H",
213
243
  min: 0,
214
244
  max: 360,
215
- value: f.h,
216
- onChange: (n) => {
217
- const v = w({
218
- ...f,
219
- h: n ?? 0
245
+ value: _.h,
246
+ onChange: (e) => {
247
+ const p = T({
248
+ ..._,
249
+ h: e ?? 0
220
250
  });
221
- e(g(v));
251
+ g(v(p));
222
252
  }
223
253
  }),
224
- /* @__PURE__ */ m(b, {
254
+ /* @__PURE__ */ d(N, {
225
255
  label: "S",
226
256
  min: 0,
227
257
  max: 100,
228
- value: f.s,
229
- onChange: (n) => {
230
- const v = w({
231
- ...f,
232
- s: n ?? 0
258
+ value: _.s,
259
+ onChange: (e) => {
260
+ const p = T({
261
+ ..._,
262
+ s: e ?? 0
233
263
  });
234
- e(g(v));
264
+ g(v(p));
235
265
  }
236
266
  }),
237
- /* @__PURE__ */ m(b, {
267
+ /* @__PURE__ */ d(N, {
238
268
  label: "L",
239
269
  min: 0,
240
270
  max: 100,
241
- value: f.l,
242
- onChange: (n) => {
243
- const v = w({
244
- ...f,
245
- l: n ?? 0
271
+ value: _.l,
272
+ onChange: (e) => {
273
+ const p = T({
274
+ ..._,
275
+ l: e ?? 0
246
276
  });
247
- e(g(v));
277
+ g(v(p));
248
278
  }
249
279
  })
250
280
  ]
@@ -253,5 +283,5 @@ var _ = (s, h, i) => Math.min(i, Math.max(h, s)), k = (s) => {
253
283
  });
254
284
  };
255
285
  export {
256
- F as ColorPicker
286
+ Z as ColorPicker
257
287
  };