@dashadmin/dash-components 1.0.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 +0 -0
- package/color-thief-CTwGFhOB.js +272 -0
- package/index.d.ts +3 -0
- package/index.js +5569 -0
- package/package.json +62 -0
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
function q() {
|
|
2
|
+
return q = Object.assign ? Object.assign.bind() : function(a) {
|
|
3
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
4
|
+
var s = arguments[r];
|
|
5
|
+
for (var c in s) ({}).hasOwnProperty.call(s, c) && (a[c] = s[c]);
|
|
6
|
+
}
|
|
7
|
+
return a;
|
|
8
|
+
}, q.apply(null, arguments);
|
|
9
|
+
}
|
|
10
|
+
var D = function(a, r) {
|
|
11
|
+
return a < r ? -1 : a > r ? 1 : 0;
|
|
12
|
+
}, P = function(a) {
|
|
13
|
+
return a.reduce(function(r, s) {
|
|
14
|
+
return r + s;
|
|
15
|
+
}, 0);
|
|
16
|
+
}, k = /* @__PURE__ */ (function() {
|
|
17
|
+
function a(s) {
|
|
18
|
+
this.colors = s;
|
|
19
|
+
}
|
|
20
|
+
var r = a.prototype;
|
|
21
|
+
return r.palette = function() {
|
|
22
|
+
return this.colors;
|
|
23
|
+
}, r.map = function(s) {
|
|
24
|
+
return s;
|
|
25
|
+
}, a;
|
|
26
|
+
})(), H = (function() {
|
|
27
|
+
function a(t, e, i) {
|
|
28
|
+
return (t << 10) + (e << 5) + i;
|
|
29
|
+
}
|
|
30
|
+
function r(t) {
|
|
31
|
+
var e = [], i = !1;
|
|
32
|
+
function l() {
|
|
33
|
+
e.sort(t), i = !0;
|
|
34
|
+
}
|
|
35
|
+
return { push: function(u) {
|
|
36
|
+
e.push(u), i = !1;
|
|
37
|
+
}, peek: function(u) {
|
|
38
|
+
return i || l(), u === void 0 && (u = e.length - 1), e[u];
|
|
39
|
+
}, pop: function() {
|
|
40
|
+
return i || l(), e.pop();
|
|
41
|
+
}, size: function() {
|
|
42
|
+
return e.length;
|
|
43
|
+
}, map: function(u) {
|
|
44
|
+
return e.map(u);
|
|
45
|
+
}, debug: function() {
|
|
46
|
+
return i || l(), e;
|
|
47
|
+
} };
|
|
48
|
+
}
|
|
49
|
+
function s(t, e, i, l, u, o, f) {
|
|
50
|
+
var n = this;
|
|
51
|
+
n.r1 = t, n.r2 = e, n.g1 = i, n.g2 = l, n.b1 = u, n.b2 = o, n.histo = f;
|
|
52
|
+
}
|
|
53
|
+
function c() {
|
|
54
|
+
this.vboxes = new r(function(t, e) {
|
|
55
|
+
return D(t.vbox.count() * t.vbox.volume(), e.vbox.count() * e.vbox.volume());
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function b(t, e) {
|
|
59
|
+
if (e.count()) {
|
|
60
|
+
var i = e.r2 - e.r1 + 1, l = e.g2 - e.g1 + 1, u = Math.max.apply(null, [i, l, e.b2 - e.b1 + 1]);
|
|
61
|
+
if (e.count() == 1) return [e.copy()];
|
|
62
|
+
var o, f, n, m, w = 0, d = [], y = [];
|
|
63
|
+
if (u == i) for (o = e.r1; o <= e.r2; o++) {
|
|
64
|
+
for (m = 0, f = e.g1; f <= e.g2; f++) for (n = e.b1; n <= e.b2; n++) m += t[a(o, f, n)] || 0;
|
|
65
|
+
d[o] = w += m;
|
|
66
|
+
}
|
|
67
|
+
else if (u == l) for (o = e.g1; o <= e.g2; o++) {
|
|
68
|
+
for (m = 0, f = e.r1; f <= e.r2; f++) for (n = e.b1; n <= e.b2; n++) m += t[a(f, o, n)] || 0;
|
|
69
|
+
d[o] = w += m;
|
|
70
|
+
}
|
|
71
|
+
else for (o = e.b1; o <= e.b2; o++) {
|
|
72
|
+
for (m = 0, f = e.r1; f <= e.r2; f++) for (n = e.g1; n <= e.g2; n++) m += t[a(f, n, o)] || 0;
|
|
73
|
+
d[o] = w += m;
|
|
74
|
+
}
|
|
75
|
+
return d.forEach(function(C, h) {
|
|
76
|
+
y[h] = w - C;
|
|
77
|
+
}), (function(C) {
|
|
78
|
+
var h, v, g, p, x, E = C + "1", I = C + "2", T = 0;
|
|
79
|
+
for (o = e[E]; o <= e[I]; o++) if (d[o] > w / 2) {
|
|
80
|
+
for (g = e.copy(), p = e.copy(), x = (h = o - e[E]) <= (v = e[I] - o) ? Math.min(e[I] - 1, ~~(o + v / 2)) : Math.max(e[E], ~~(o - 1 - h / 2)); !d[x]; ) x++;
|
|
81
|
+
for (T = y[x]; !T && d[x - 1]; ) T = y[--x];
|
|
82
|
+
return g[I] = x, p[E] = g[I] + 1, [g, p];
|
|
83
|
+
}
|
|
84
|
+
})(u == i ? "r" : u == l ? "g" : "b");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return s.prototype = { volume: function(t) {
|
|
88
|
+
var e = this;
|
|
89
|
+
return e._volume && !t || (e._volume = (e.r2 - e.r1 + 1) * (e.g2 - e.g1 + 1) * (e.b2 - e.b1 + 1)), e._volume;
|
|
90
|
+
}, count: function(t) {
|
|
91
|
+
var e = this, i = e.histo;
|
|
92
|
+
if (!e._count_set || t) {
|
|
93
|
+
var l, u, o, f = 0;
|
|
94
|
+
for (l = e.r1; l <= e.r2; l++) for (u = e.g1; u <= e.g2; u++) for (o = e.b1; o <= e.b2; o++) f += i[a(l, u, o)] || 0;
|
|
95
|
+
e._count = f, e._count_set = !0;
|
|
96
|
+
}
|
|
97
|
+
return e._count;
|
|
98
|
+
}, copy: function() {
|
|
99
|
+
var t = this;
|
|
100
|
+
return new s(t.r1, t.r2, t.g1, t.g2, t.b1, t.b2, t.histo);
|
|
101
|
+
}, avg: function(t) {
|
|
102
|
+
var e = this, i = e.histo;
|
|
103
|
+
if (!e._avg || t) {
|
|
104
|
+
var l, u, o, f, n = 0, m = 0, w = 0, d = 0;
|
|
105
|
+
if (e.r1 === e.r2 && e.g1 === e.g2 && e.b1 === e.b2) e._avg = [e.r1 << 3, e.g1 << 3, e.b1 << 3];
|
|
106
|
+
else {
|
|
107
|
+
for (u = e.r1; u <= e.r2; u++) for (o = e.g1; o <= e.g2; o++) for (f = e.b1; f <= e.b2; f++) n += l = i[a(u, o, f)] || 0, m += l * (u + 0.5) * 8, w += l * (o + 0.5) * 8, d += l * (f + 0.5) * 8;
|
|
108
|
+
e._avg = n ? [~~(m / n), ~~(w / n), ~~(d / n)] : [~~(8 * (e.r1 + e.r2 + 1) / 2), ~~(8 * (e.g1 + e.g2 + 1) / 2), ~~(8 * (e.b1 + e.b2 + 1) / 2)];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return e._avg;
|
|
112
|
+
}, contains: function(t) {
|
|
113
|
+
var e = this, i = t[0] >> 3;
|
|
114
|
+
return gval = t[1] >> 3, bval = t[2] >> 3, i >= e.r1 && i <= e.r2 && gval >= e.g1 && gval <= e.g2 && bval >= e.b1 && bval <= e.b2;
|
|
115
|
+
} }, c.prototype = { push: function(t) {
|
|
116
|
+
this.vboxes.push({ vbox: t, color: t.avg() });
|
|
117
|
+
}, palette: function() {
|
|
118
|
+
return this.vboxes.map(function(t) {
|
|
119
|
+
return t.color;
|
|
120
|
+
});
|
|
121
|
+
}, size: function() {
|
|
122
|
+
return this.vboxes.size();
|
|
123
|
+
}, map: function(t) {
|
|
124
|
+
for (var e = this.vboxes, i = 0; i < e.size(); i++) if (e.peek(i).vbox.contains(t)) return e.peek(i).color;
|
|
125
|
+
return this.nearest(t);
|
|
126
|
+
}, nearest: function(t) {
|
|
127
|
+
for (var e, i, l, u = this.vboxes, o = 0; o < u.size(); o++) ((i = Math.sqrt(Math.pow(t[0] - u.peek(o).color[0], 2) + Math.pow(t[1] - u.peek(o).color[1], 2) + Math.pow(t[2] - u.peek(o).color[2], 2))) < e || e === void 0) && (e = i, l = u.peek(o).color);
|
|
128
|
+
return l;
|
|
129
|
+
}, forcebw: function() {
|
|
130
|
+
var t = this.vboxes;
|
|
131
|
+
t.sort(function(u, o) {
|
|
132
|
+
return D(P(u.color), P(o.color));
|
|
133
|
+
});
|
|
134
|
+
var e = t[0].color;
|
|
135
|
+
e[0] < 5 && e[1] < 5 && e[2] < 5 && (t[0].color = [0, 0, 0]);
|
|
136
|
+
var i = t.length - 1, l = t[i].color;
|
|
137
|
+
l[0] > 251 && l[1] > 251 && l[2] > 251 && (t[i].color = [255, 255, 255]);
|
|
138
|
+
} }, { quantize: function(t, e) {
|
|
139
|
+
if (!Number.isInteger(e) || e < 1 || e > 256) throw new Error("Invalid maximum color count. It must be an integer between 1 and 256.");
|
|
140
|
+
if (!t.length || e < 2 || e > 256 || !t.length || e < 2 || e > 256) return !1;
|
|
141
|
+
for (var i = [], l = /* @__PURE__ */ new Set(), u = 0; u < t.length; u++) {
|
|
142
|
+
var o = t[u], f = o.join(",");
|
|
143
|
+
l.has(f) || (l.add(f), i.push(o));
|
|
144
|
+
}
|
|
145
|
+
if (i.length <= e) return new k(i);
|
|
146
|
+
var n = (function(h) {
|
|
147
|
+
var v, g = new Array(32768);
|
|
148
|
+
return h.forEach(function(p) {
|
|
149
|
+
v = a(p[0] >> 3, p[1] >> 3, p[2] >> 3), g[v] = (g[v] || 0) + 1;
|
|
150
|
+
}), g;
|
|
151
|
+
})(t);
|
|
152
|
+
n.forEach(function() {
|
|
153
|
+
});
|
|
154
|
+
var m = (function(h, v) {
|
|
155
|
+
var g, p, x, E = 1e6, I = 0, T = 1e6, W = 0, _ = 1e6, S = 0;
|
|
156
|
+
return h.forEach(function(z) {
|
|
157
|
+
(g = z[0] >> 3) < E ? E = g : g > I && (I = g), (p = z[1] >> 3) < T ? T = p : p > W && (W = p), (x = z[2] >> 3) < _ ? _ = x : x > S && (S = x);
|
|
158
|
+
}), new s(E, I, T, W, _, S, v);
|
|
159
|
+
})(t, n), w = new r(function(h, v) {
|
|
160
|
+
return D(h.count(), v.count());
|
|
161
|
+
});
|
|
162
|
+
function d(h, v) {
|
|
163
|
+
for (var g, p = h.size(), x = 0; x < 1e3; ) {
|
|
164
|
+
if (p >= v || x++ > 1e3) return;
|
|
165
|
+
if ((g = h.pop()).count()) {
|
|
166
|
+
var E = b(n, g), I = E[0], T = E[1];
|
|
167
|
+
if (!I) return;
|
|
168
|
+
h.push(I), T && (h.push(T), p++);
|
|
169
|
+
} else h.push(g), x++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
w.push(m), d(w, 0.75 * e);
|
|
173
|
+
for (var y = new r(function(h, v) {
|
|
174
|
+
return D(h.count() * h.volume(), v.count() * v.volume());
|
|
175
|
+
}); w.size(); ) y.push(w.pop());
|
|
176
|
+
d(y, e);
|
|
177
|
+
for (var C = new c(); y.size(); ) C.push(y.pop());
|
|
178
|
+
return C;
|
|
179
|
+
} };
|
|
180
|
+
})().quantize, L = function(a, r, s, c) {
|
|
181
|
+
for (var b, t, e, i, l, u = c || {}, o = u.ignoreWhite, f = o === void 0 || o, n = u.whiteThreshold, m = n === void 0 ? 250 : n, w = u.alphaThreshold, d = w === void 0 ? 125 : w, y = u.minSaturation, C = y === void 0 ? 0 : y, h = a, v = [], g = 0; g < r; g += s) if (t = h[0 + (b = 4 * g)], e = h[b + 1], i = h[b + 2], !((l = h[b + 3]) !== void 0 && l < d || f && t > m && e > m && i > m)) {
|
|
182
|
+
if (C > 0) {
|
|
183
|
+
var p = Math.max(t, e, i);
|
|
184
|
+
if (p === 0 || (p - Math.min(t, e, i)) / p < C) continue;
|
|
185
|
+
}
|
|
186
|
+
v.push([t, e, i]);
|
|
187
|
+
}
|
|
188
|
+
return v;
|
|
189
|
+
}, j = function(a) {
|
|
190
|
+
var r = a.colorCount, s = a.quality;
|
|
191
|
+
if (r !== void 0 && Number.isInteger(r)) {
|
|
192
|
+
if (r === 1) throw new Error("colorCount should be between 2 and 20. To get one color, call getColor() instead of getPalette()");
|
|
193
|
+
r = Math.max(r, 2), r = Math.min(r, 20);
|
|
194
|
+
} else r = 10;
|
|
195
|
+
return (s === void 0 || !Number.isInteger(s) || s < 1) && (s = 10), { colorCount: r, quality: s, ignoreWhite: a.ignoreWhite === void 0 || !!a.ignoreWhite, whiteThreshold: typeof a.whiteThreshold == "number" ? a.whiteThreshold : 250, alphaThreshold: typeof a.alphaThreshold == "number" ? a.alphaThreshold : 125, minSaturation: typeof a.minSaturation == "number" ? Math.max(0, Math.min(1, a.minSaturation)) : 0 };
|
|
196
|
+
}, M = function() {
|
|
197
|
+
};
|
|
198
|
+
M.prototype.getColor = function(a, r) {
|
|
199
|
+
if (typeof r == "object" && r !== null) {
|
|
200
|
+
var s = this.getPalette(a, q({ colorCount: 5 }, r));
|
|
201
|
+
return s === null ? null : s[0];
|
|
202
|
+
}
|
|
203
|
+
var c = this.getPalette(a, 5, r);
|
|
204
|
+
return c === null ? null : c[0];
|
|
205
|
+
}, M.prototype.getPalette = function(a, r, s) {
|
|
206
|
+
var c, b, t, e = { ignoreWhite: (c = j(typeof r == "object" && r !== null ? { colorCount: r.colorCount, quality: r.quality, ignoreWhite: r.ignoreWhite, whiteThreshold: r.whiteThreshold, alphaThreshold: r.alphaThreshold, minSaturation: r.minSaturation } : { colorCount: r, quality: s })).ignoreWhite, whiteThreshold: c.whiteThreshold, alphaThreshold: c.alphaThreshold, minSaturation: c.minSaturation };
|
|
207
|
+
if (!a) throw new Error("sourceImage is required");
|
|
208
|
+
if (a instanceof HTMLImageElement) {
|
|
209
|
+
if (!a.complete) throw new Error('Image has not finished loading. Wait for the "load" event before calling getColor/getPalette.');
|
|
210
|
+
if (!a.naturalWidth) throw new Error("Image has no dimensions. It may not have loaded successfully.");
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
var i = (function(n) {
|
|
214
|
+
if (n instanceof HTMLImageElement) {
|
|
215
|
+
var m = document.createElement("canvas"), w = m.getContext("2d"), d = m.width = n.naturalWidth, y = m.height = n.naturalHeight;
|
|
216
|
+
return w.drawImage(n, 0, 0, d, y), { imageData: w.getImageData(0, 0, d, y), pixelCount: d * y };
|
|
217
|
+
}
|
|
218
|
+
if (n instanceof HTMLCanvasElement) {
|
|
219
|
+
var C = n.getContext("2d"), h = n.width, v = n.height;
|
|
220
|
+
return { imageData: C.getImageData(0, 0, h, v), pixelCount: h * v };
|
|
221
|
+
}
|
|
222
|
+
if (typeof ImageData < "u" && n instanceof ImageData) return { imageData: n, pixelCount: n.width * n.height };
|
|
223
|
+
if (typeof ImageBitmap < "u" && n instanceof ImageBitmap) {
|
|
224
|
+
var g = document.createElement("canvas"), p = g.getContext("2d");
|
|
225
|
+
return g.width = n.width, g.height = n.height, p.drawImage(n, 0, 0), { imageData: p.getImageData(0, 0, n.width, n.height), pixelCount: n.width * n.height };
|
|
226
|
+
}
|
|
227
|
+
throw new Error("Unsupported source type. Expected HTMLImageElement, HTMLCanvasElement, ImageData, or ImageBitmap.");
|
|
228
|
+
})(a);
|
|
229
|
+
b = i.imageData, t = i.pixelCount;
|
|
230
|
+
} catch (n) {
|
|
231
|
+
throw n.name === "SecurityError" ? new Error('Image is tainted by cross-origin data. Add crossorigin="anonymous" to the <img> tag and ensure the server sends appropriate CORS headers.', { cause: n }) : n;
|
|
232
|
+
}
|
|
233
|
+
var l = L(b.data, t, c.quality, e);
|
|
234
|
+
l.length === 0 && (l = L(b.data, t, c.quality, q({}, e, { ignoreWhite: !1 }))), l.length === 0 && (l = L(b.data, t, c.quality, q({}, e, { ignoreWhite: !1, alphaThreshold: 0 })));
|
|
235
|
+
var u = H(l, c.colorCount), o = u ? u.palette() : null;
|
|
236
|
+
if (o) return o;
|
|
237
|
+
var f = (function(n, m, w) {
|
|
238
|
+
for (var d = n, y = 0, C = 0, h = 0, v = 0, g = 0; g < m; g += w) {
|
|
239
|
+
var p = 4 * g;
|
|
240
|
+
y += d[p], C += d[p + 1], h += d[p + 2], v++;
|
|
241
|
+
}
|
|
242
|
+
return v === 0 ? null : [Math.round(y / v), Math.round(C / v), Math.round(h / v)];
|
|
243
|
+
})(b.data, t, c.quality);
|
|
244
|
+
return f ? [f] : null;
|
|
245
|
+
}, M.prototype.getColorFromUrl = function(a, r, s) {
|
|
246
|
+
var c = this, b = document.createElement("img");
|
|
247
|
+
b.addEventListener("load", function() {
|
|
248
|
+
var t = c.getPalette(b, 5, s);
|
|
249
|
+
r(t ? t[0] : null, a);
|
|
250
|
+
}), b.src = a;
|
|
251
|
+
}, M.prototype.getImageData = function(a, r) {
|
|
252
|
+
var s = new XMLHttpRequest();
|
|
253
|
+
s.open("GET", a, !0), s.responseType = "arraybuffer", s.onload = function() {
|
|
254
|
+
if (this.status == 200) {
|
|
255
|
+
for (var c = new Uint8Array(this.response), b = new Array(c.length), t = 0; t < c.length; t++) b[t] = String.fromCharCode(c[t]);
|
|
256
|
+
var e = b.join(""), i = window.btoa(e);
|
|
257
|
+
r("data:image/png;base64," + i);
|
|
258
|
+
}
|
|
259
|
+
}, s.send();
|
|
260
|
+
}, M.prototype.getColorAsync = function(a, r, s) {
|
|
261
|
+
var c = this;
|
|
262
|
+
this.getImageData(a, function(b) {
|
|
263
|
+
var t = document.createElement("img");
|
|
264
|
+
t.addEventListener("load", function() {
|
|
265
|
+
var e = c.getPalette(t, 5, s);
|
|
266
|
+
r(e ? e[0] : null, this);
|
|
267
|
+
}), t.src = b;
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
export {
|
|
271
|
+
M as default
|
|
272
|
+
};
|
package/index.d.ts
ADDED