@arcblock/nft-display 2.7.23 → 2.7.24
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/lib/color.d.ts +1 -0
- package/lib/color.js +35 -1
- package/lib/index.js +23 -20
- package/package.json +2 -2
package/lib/color.d.ts
CHANGED
package/lib/color.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNftBGColorFromDid = exports.getPassportColorFromDid = exports.getNftBGColor = exports.hslToRgb = exports.rgbToHsl = exports.DEFAULT_COLORS = void 0;
|
|
3
|
+
exports.getNftBGColorFromDid = exports.getPassportColorFromDid = exports.getNftBGColor = exports.hslToRgb = exports.rgbToHsl = exports.MOTIF_COLORS = exports.DEFAULT_COLORS = void 0;
|
|
4
4
|
const util_1 = require("@ocap/util");
|
|
5
5
|
const mcrypto_1 = require("@ocap/mcrypto");
|
|
6
6
|
exports.DEFAULT_COLORS = {
|
|
@@ -21,6 +21,40 @@ exports.DEFAULT_COLORS = {
|
|
|
21
21
|
end: '#7AB2F6',
|
|
22
22
|
},
|
|
23
23
|
};
|
|
24
|
+
exports.MOTIF_COLORS = [
|
|
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
|
+
];
|
|
24
58
|
/**
|
|
25
59
|
* Convert RGB color to HSL color.
|
|
26
60
|
* @param {string} rgbString - The RGB color value.
|
package/lib/index.js
CHANGED
|
@@ -10,29 +10,27 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
15
|
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
17
|
exports.getSvg = exports.nanoid = exports.getTagSvg = exports.getBadgesSvg = exports.getChainBadge = exports.getVerifiableBadge = exports.getDidSvg = exports.getExtraSvg = exports.getIssuerSvg = exports.getHeaderSvg = exports.getLayoutSvg = exports.formatDid = void 0;
|
|
30
|
-
const
|
|
18
|
+
const did_motif_1 = require("@arcblock/did-motif");
|
|
31
19
|
const color_1 = require("./color");
|
|
32
20
|
__exportStar(require("./color"), exports);
|
|
33
21
|
const getId = (id, suffix) => [id, suffix].join('-');
|
|
34
22
|
const DEFAULT_WIDTH = 228;
|
|
35
23
|
const DEFAULT_HEIGHT = 258;
|
|
24
|
+
const isEthereumDid = (addr) => /^(0x)?[0-9a-f]{40}$/i.test(addr);
|
|
25
|
+
const getEthereumColor = (did) => {
|
|
26
|
+
const index = Uint8Array.from(did
|
|
27
|
+
.slice(2)
|
|
28
|
+
.match(/.{1,2}/g)
|
|
29
|
+
.map((pair) => parseInt(pair, 16)))
|
|
30
|
+
.slice(0, 8)
|
|
31
|
+
.reduce((acc, val) => acc + val, 0) % color_1.MOTIF_COLORS.length;
|
|
32
|
+
return color_1.MOTIF_COLORS[index];
|
|
33
|
+
};
|
|
36
34
|
const formatDid = (did, length = 5) => did.length > 2 * length ? `${did.slice(0, length)}..${did.slice(-length)}` : did;
|
|
37
35
|
exports.formatDid = formatDid;
|
|
38
36
|
const getLayoutSvg = (variant, id, color) => {
|
|
@@ -507,7 +505,9 @@ const getExtraSvg = (extra, id, fontSize = 12) => {
|
|
|
507
505
|
};
|
|
508
506
|
exports.getExtraSvg = getExtraSvg;
|
|
509
507
|
const getDidSvg = (did, id, fontSize = 10) => {
|
|
510
|
-
const
|
|
508
|
+
const address = did.replace('did:abt:', '');
|
|
509
|
+
const isEth = isEthereumDid(address);
|
|
510
|
+
const color = isEth ? getEthereumColor(address) : (0, did_motif_1.getDIDMotifInfo)(address).color;
|
|
511
511
|
const prefix = `<g id="${getId(id, 'did-prefix')}" transform="translate(24, 210)" height="14">
|
|
512
512
|
<text
|
|
513
513
|
x="0"
|
|
@@ -529,10 +529,13 @@ const getDidSvg = (did, id, fontSize = 10) => {
|
|
|
529
529
|
dominant-baseline="middle">ABT:</tspan>
|
|
530
530
|
</text>
|
|
531
531
|
</g>`;
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
532
|
+
let motif = '';
|
|
533
|
+
if (isEth === false) {
|
|
534
|
+
motif = (0, did_motif_1.toSvg)(address)
|
|
535
|
+
.replace('<svg ', `<g id="${getId(id, 'did-motif')}" transform="translate(67, 211) scale(0.12, 0.12)" width="12" height="12" `)
|
|
536
|
+
.replace('</svg>', '</g>');
|
|
537
|
+
}
|
|
538
|
+
const suffix = `<g id="${getId(id, 'did-suffix')}" transform="translate(${isEth ? 67 : 80}, 210)" height="14">
|
|
536
539
|
<text
|
|
537
540
|
x="0"
|
|
538
541
|
y="8"
|
|
@@ -542,10 +545,10 @@ const getDidSvg = (did, id, fontSize = 10) => {
|
|
|
542
545
|
text-anchor="start"
|
|
543
546
|
alignment-baseline="middle"
|
|
544
547
|
dominant-baseline="middle">
|
|
545
|
-
${(0, exports.formatDid)(
|
|
548
|
+
${(0, exports.formatDid)(address)}
|
|
546
549
|
</text>
|
|
547
550
|
</g>`;
|
|
548
|
-
return [prefix, motif, suffix].join('');
|
|
551
|
+
return [prefix, motif, suffix].filter(Boolean).join('');
|
|
549
552
|
};
|
|
550
553
|
exports.getDidSvg = getDidSvg;
|
|
551
554
|
const getVerifiableBadge = (id) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/nft-display",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.24",
|
|
4
4
|
"description": "arcblock's nft display generic component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nft"
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"ts-node": "^10.9.1",
|
|
42
42
|
"typescript": "^5.0.4"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "a6e7be2c901fb69d0bbe7b350dab1d5af3fcd0af"
|
|
45
45
|
}
|