@arcblock/nft-display 3.0.8 → 3.0.10
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/es/color.js +120 -0
- package/es/index.js +843 -0
- package/lib/color.js +1 -120
- package/lib/index.js +77 -155
- package/package.json +8 -5
- /package/{lib → es}/color.d.ts +0 -0
- /package/{lib → es}/index.d.ts +0 -0
package/es/color.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { toHex as l } from "@ocap/util";
|
|
2
|
+
import { Hasher as f } from "@ocap/mcrypto";
|
|
3
|
+
const d = {
|
|
4
|
+
"did-space": {
|
|
5
|
+
start: "#7D3AC5",
|
|
6
|
+
end: "#9761D1"
|
|
7
|
+
},
|
|
8
|
+
"app-space": {
|
|
9
|
+
start: "#6CC68D",
|
|
10
|
+
end: "#47B871"
|
|
11
|
+
},
|
|
12
|
+
"app-purchase": {
|
|
13
|
+
start: "#DE7021",
|
|
14
|
+
end: "#E48D4E"
|
|
15
|
+
},
|
|
16
|
+
"app-passport": {
|
|
17
|
+
start: "#3882C7",
|
|
18
|
+
end: "#7AB2F6"
|
|
19
|
+
},
|
|
20
|
+
"app-kyc": {
|
|
21
|
+
start: "#3882C7",
|
|
22
|
+
end: "#7AB2F6"
|
|
23
|
+
}
|
|
24
|
+
}, b = [
|
|
25
|
+
"#E94E4E",
|
|
26
|
+
"#E41115",
|
|
27
|
+
"#E96B4E",
|
|
28
|
+
"#E5502E",
|
|
29
|
+
"#E98F4E",
|
|
30
|
+
"#E57A2E",
|
|
31
|
+
"#E98F4E",
|
|
32
|
+
"#E5A82E",
|
|
33
|
+
"#DACD5D",
|
|
34
|
+
"#DAC825",
|
|
35
|
+
"#BDD13D",
|
|
36
|
+
"#C8E31C",
|
|
37
|
+
"#AEE94E",
|
|
38
|
+
"#7FD558",
|
|
39
|
+
"#52CC19",
|
|
40
|
+
"#4FC469",
|
|
41
|
+
"#59DE9C",
|
|
42
|
+
"#19CC73",
|
|
43
|
+
"#5ED9D1",
|
|
44
|
+
"#19CCC0",
|
|
45
|
+
"#4ED7E9",
|
|
46
|
+
"#19B7CC",
|
|
47
|
+
"#45ACE8",
|
|
48
|
+
"#1C97DE",
|
|
49
|
+
"#4E68E9",
|
|
50
|
+
"#2E4DE5",
|
|
51
|
+
"#7F4EE9",
|
|
52
|
+
"#682EE5",
|
|
53
|
+
"#BE65E7",
|
|
54
|
+
"#AF40E2",
|
|
55
|
+
"#DF58C2",
|
|
56
|
+
"#E94E8F"
|
|
57
|
+
];
|
|
58
|
+
function h(r) {
|
|
59
|
+
const e = r.replace("#", ""), t = parseInt(e.slice(0, 2), 16) / 255, n = parseInt(e.slice(2, 4), 16) / 255, s = parseInt(e.slice(4, 6), 16) / 255, o = Math.max(t, n, s), a = Math.min(t, n, s);
|
|
60
|
+
let E, i;
|
|
61
|
+
const C = (o + a) / 2;
|
|
62
|
+
if (o === a)
|
|
63
|
+
E = 0, i = 0;
|
|
64
|
+
else {
|
|
65
|
+
const c = o - a;
|
|
66
|
+
switch (i = C > 0.5 ? c / (2 - o - a) : c / (o + a), o) {
|
|
67
|
+
case t:
|
|
68
|
+
E = (n - s) / c + (n < s ? 6 : 0);
|
|
69
|
+
break;
|
|
70
|
+
case n:
|
|
71
|
+
E = (s - t) / c + 2;
|
|
72
|
+
break;
|
|
73
|
+
case s:
|
|
74
|
+
E = (t - n) / c + 4;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
E /= 6;
|
|
78
|
+
}
|
|
79
|
+
return [E, i, C];
|
|
80
|
+
}
|
|
81
|
+
function u(r, e, t) {
|
|
82
|
+
let n, s, o;
|
|
83
|
+
if (e === 0)
|
|
84
|
+
n = t, s = t, o = t;
|
|
85
|
+
else {
|
|
86
|
+
const a = (C, c, D) => {
|
|
87
|
+
let p = D;
|
|
88
|
+
return p < 0 && (p += 1), p > 1 && (p -= 1), p < 0.16666666666666666 ? C + (c - C) * 6 * p : p < 0.5 ? c : p < 0.6666666666666666 ? C + (c - C) * (0.6666666666666666 - p) * 6 : C;
|
|
89
|
+
}, E = t < 0.5 ? t * (1 + e) : t + e - t * e, i = 2 * t - E;
|
|
90
|
+
n = a(i, E, r + 1 / 3), s = a(i, E, r), o = a(i, E, r - 1 / 3);
|
|
91
|
+
}
|
|
92
|
+
return `#${[Math.round(n * 255), Math.round(s * 255), Math.round(o * 255)].map((a) => a.toString(16).padStart(2, "0")).join("")}`;
|
|
93
|
+
}
|
|
94
|
+
function F(r) {
|
|
95
|
+
if (r) {
|
|
96
|
+
const e = h(r), t = [e[0]];
|
|
97
|
+
e[1] > 0.7 ? t.push(0.7) : t.push(e[1]), e[2] > 0.6 ? t.push(0.6) : e[2] < 0.3 ? t.push(0.3) : t.push(e[2]);
|
|
98
|
+
const n = [t[0], t[1], t[2] - 0.1], s = u(...t);
|
|
99
|
+
return {
|
|
100
|
+
start: u(...n),
|
|
101
|
+
end: s
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return d["app-passport"];
|
|
105
|
+
}
|
|
106
|
+
function A(r) {
|
|
107
|
+
return `#${l(f.SHA3.hash224(r)).slice(-6)}`;
|
|
108
|
+
}
|
|
109
|
+
function g(r) {
|
|
110
|
+
return F(A(r));
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
d as DEFAULT_COLORS,
|
|
114
|
+
b as MOTIF_COLORS,
|
|
115
|
+
F as getNftBGColor,
|
|
116
|
+
g as getNftBGColorFromDid,
|
|
117
|
+
A as getPassportColorFromDid,
|
|
118
|
+
u as hslToRgb,
|
|
119
|
+
h as rgbToHsl
|
|
120
|
+
};
|