@pezkuwi/ui-shared 3.16.6
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 +3 -0
- package/build/LICENSE +201 -0
- package/build/README.md +3 -0
- package/build/bundle.d.ts +2 -0
- package/build/bundle.js +2 -0
- package/build/cjs/bundle.d.ts +2 -0
- package/build/cjs/bundle.js +7 -0
- package/build/cjs/icons/beachball/colors.d.ts +2 -0
- package/build/cjs/icons/beachball/colors.js +16 -0
- package/build/cjs/icons/beachball/container.d.ts +1 -0
- package/build/cjs/icons/beachball/container.js +22 -0
- package/build/cjs/icons/beachball/defaults.d.ts +2 -0
- package/build/cjs/icons/beachball/defaults.js +8 -0
- package/build/cjs/icons/beachball/demo.d.ts +1 -0
- package/build/cjs/icons/beachball/demo.js +21 -0
- package/build/cjs/icons/beachball/index.d.ts +2 -0
- package/build/cjs/icons/beachball/index.js +24 -0
- package/build/cjs/icons/beachball/seeder.d.ts +2 -0
- package/build/cjs/icons/beachball/seeder.js +21 -0
- package/build/cjs/icons/beachball/shape/circle.d.ts +2 -0
- package/build/cjs/icons/beachball/shape/circle.js +16 -0
- package/build/cjs/icons/beachball/shape/square.d.ts +2 -0
- package/build/cjs/icons/beachball/shape/square.js +19 -0
- package/build/cjs/icons/beachball/svg/circle.d.ts +1 -0
- package/build/cjs/icons/beachball/svg/circle.js +11 -0
- package/build/cjs/icons/beachball/svg/element.d.ts +1 -0
- package/build/cjs/icons/beachball/svg/element.js +12 -0
- package/build/cjs/icons/beachball/svg/rect.d.ts +1 -0
- package/build/cjs/icons/beachball/svg/rect.js +10 -0
- package/build/cjs/icons/beachball/svg/svg.d.ts +1 -0
- package/build/cjs/icons/beachball/svg/svg.js +7 -0
- package/build/cjs/icons/beachball/types.d.ts +2 -0
- package/build/cjs/icons/beachball/types.js +2 -0
- package/build/cjs/icons/index.d.ts +2 -0
- package/build/cjs/icons/index.js +7 -0
- package/build/cjs/icons/polkadot.d.ts +5 -0
- package/build/cjs/icons/polkadot.js +116 -0
- package/build/cjs/icons/types.d.ts +10 -0
- package/build/cjs/icons/types.js +2 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.js +5 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/packageDetect.d.ts +1 -0
- package/build/cjs/packageDetect.js +5 -0
- package/build/cjs/packageInfo.d.ts +6 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/icons/beachball/README.md +19 -0
- package/build/icons/beachball/colors.d.ts +2 -0
- package/build/icons/beachball/colors.js +13 -0
- package/build/icons/beachball/container.d.ts +1 -0
- package/build/icons/beachball/container.js +19 -0
- package/build/icons/beachball/defaults.d.ts +2 -0
- package/build/icons/beachball/defaults.js +5 -0
- package/build/icons/beachball/demo.d.ts +1 -0
- package/build/icons/beachball/demo.js +19 -0
- package/build/icons/beachball/index.d.ts +2 -0
- package/build/icons/beachball/index.js +21 -0
- package/build/icons/beachball/seeder.d.ts +2 -0
- package/build/icons/beachball/seeder.js +18 -0
- package/build/icons/beachball/shape/circle.d.ts +2 -0
- package/build/icons/beachball/shape/circle.js +13 -0
- package/build/icons/beachball/shape/square.d.ts +2 -0
- package/build/icons/beachball/shape/square.js +16 -0
- package/build/icons/beachball/svg/circle.d.ts +1 -0
- package/build/icons/beachball/svg/circle.js +8 -0
- package/build/icons/beachball/svg/element.d.ts +1 -0
- package/build/icons/beachball/svg/element.js +9 -0
- package/build/icons/beachball/svg/rect.d.ts +1 -0
- package/build/icons/beachball/svg/rect.js +7 -0
- package/build/icons/beachball/svg/svg.d.ts +1 -0
- package/build/icons/beachball/svg/svg.js +4 -0
- package/build/icons/beachball/types.d.ts +2 -0
- package/build/icons/beachball/types.js +1 -0
- package/build/icons/index.d.ts +2 -0
- package/build/icons/index.js +2 -0
- package/build/icons/polkadot.d.ts +5 -0
- package/build/icons/polkadot.js +113 -0
- package/build/icons/types.d.ts +10 -0
- package/build/icons/types.js +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/package.json +336 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +3 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build-tsc/bundle.d.ts +2 -0
- package/build-tsc/icons/beachball/colors.d.ts +2 -0
- package/build-tsc/icons/beachball/container.d.ts +1 -0
- package/build-tsc/icons/beachball/defaults.d.ts +2 -0
- package/build-tsc/icons/beachball/demo.d.ts +1 -0
- package/build-tsc/icons/beachball/index.d.ts +2 -0
- package/build-tsc/icons/beachball/seeder.d.ts +2 -0
- package/build-tsc/icons/beachball/shape/circle.d.ts +2 -0
- package/build-tsc/icons/beachball/shape/square.d.ts +2 -0
- package/build-tsc/icons/beachball/svg/circle.d.ts +1 -0
- package/build-tsc/icons/beachball/svg/element.d.ts +1 -0
- package/build-tsc/icons/beachball/svg/rect.d.ts +1 -0
- package/build-tsc/icons/beachball/svg/svg.d.ts +1 -0
- package/build-tsc/icons/beachball/types.d.ts +2 -0
- package/build-tsc/icons/index.d.ts +2 -0
- package/build-tsc/icons/polkadot.d.ts +5 -0
- package/build-tsc/icons/types.d.ts +10 -0
- package/build-tsc/index.d.ts +2 -0
- package/build-tsc/packageDetect.d.ts +1 -0
- package/build-tsc/packageInfo.d.ts +6 -0
- package/build-tsc-cjs/bundle.js +7 -0
- package/build-tsc-cjs/icons/beachball/colors.js +16 -0
- package/build-tsc-cjs/icons/beachball/container.js +22 -0
- package/build-tsc-cjs/icons/beachball/defaults.js +8 -0
- package/build-tsc-cjs/icons/beachball/demo.js +21 -0
- package/build-tsc-cjs/icons/beachball/index.js +24 -0
- package/build-tsc-cjs/icons/beachball/seeder.js +21 -0
- package/build-tsc-cjs/icons/beachball/shape/circle.js +16 -0
- package/build-tsc-cjs/icons/beachball/shape/square.js +19 -0
- package/build-tsc-cjs/icons/beachball/svg/circle.js +11 -0
- package/build-tsc-cjs/icons/beachball/svg/element.js +12 -0
- package/build-tsc-cjs/icons/beachball/svg/rect.js +10 -0
- package/build-tsc-cjs/icons/beachball/svg/svg.js +7 -0
- package/build-tsc-cjs/icons/beachball/types.js +2 -0
- package/build-tsc-cjs/icons/index.js +7 -0
- package/build-tsc-cjs/icons/polkadot.js +116 -0
- package/build-tsc-cjs/icons/types.js +2 -0
- package/build-tsc-cjs/index.js +5 -0
- package/build-tsc-cjs/packageDetect.js +5 -0
- package/build-tsc-cjs/packageInfo.js +4 -0
- package/build-tsc-esm/bundle.js +2 -0
- package/build-tsc-esm/icons/beachball/colors.js +13 -0
- package/build-tsc-esm/icons/beachball/container.js +19 -0
- package/build-tsc-esm/icons/beachball/defaults.js +5 -0
- package/build-tsc-esm/icons/beachball/demo.js +19 -0
- package/build-tsc-esm/icons/beachball/index.js +21 -0
- package/build-tsc-esm/icons/beachball/seeder.js +18 -0
- package/build-tsc-esm/icons/beachball/shape/circle.js +13 -0
- package/build-tsc-esm/icons/beachball/shape/square.js +16 -0
- package/build-tsc-esm/icons/beachball/svg/circle.js +8 -0
- package/build-tsc-esm/icons/beachball/svg/element.js +9 -0
- package/build-tsc-esm/icons/beachball/svg/rect.js +7 -0
- package/build-tsc-esm/icons/beachball/svg/svg.js +4 -0
- package/build-tsc-esm/icons/beachball/types.js +1 -0
- package/build-tsc-esm/icons/index.js +2 -0
- package/build-tsc-esm/icons/polkadot.js +113 -0
- package/build-tsc-esm/icons/types.js +1 -0
- package/build-tsc-esm/index.js +2 -0
- package/build-tsc-esm/packageDetect.js +3 -0
- package/build-tsc-esm/packageInfo.js +1 -0
- package/package.json +37 -0
- package/src/bundle.ts +5 -0
- package/src/icons/beachball/LICENSE +16 -0
- package/src/icons/beachball/README.md +19 -0
- package/src/icons/beachball/colors.spec.ts +67 -0
- package/src/icons/beachball/colors.ts +28 -0
- package/src/icons/beachball/container.spec.ts +46 -0
- package/src/icons/beachball/container.ts +27 -0
- package/src/icons/beachball/defaults.ts +11 -0
- package/src/icons/beachball/demo.ts +35 -0
- package/src/icons/beachball/index.spec.ts +36 -0
- package/src/icons/beachball/index.ts +33 -0
- package/src/icons/beachball/seeder.spec.ts +30 -0
- package/src/icons/beachball/seeder.ts +30 -0
- package/src/icons/beachball/shape/circle.spec.ts +20 -0
- package/src/icons/beachball/shape/circle.ts +23 -0
- package/src/icons/beachball/shape/square.ts +26 -0
- package/src/icons/beachball/svg/circle.spec.ts +19 -0
- package/src/icons/beachball/svg/circle.ts +14 -0
- package/src/icons/beachball/svg/element.spec.ts +19 -0
- package/src/icons/beachball/svg/element.ts +17 -0
- package/src/icons/beachball/svg/rect.spec.ts +19 -0
- package/src/icons/beachball/svg/rect.ts +13 -0
- package/src/icons/beachball/svg/svg.spec.ts +19 -0
- package/src/icons/beachball/svg/svg.ts +10 -0
- package/src/icons/beachball/types.ts +6 -0
- package/src/icons/index.ts +5 -0
- package/src/icons/polkadot.spec.ts +35 -0
- package/src/icons/polkadot.ts +154 -0
- package/src/icons/types.ts +14 -0
- package/src/index.ts +6 -0
- package/src/packageDetect.ts +11 -0
- package/src/packageInfo.ts +6 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +16 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Copyright 2018-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2018 Paritytech via paritytech/oo7/polkadot-identicon
|
|
5
|
+
|
|
6
|
+
// This has been converted from the original version that can be found at
|
|
7
|
+
//
|
|
8
|
+
// https://github.com/paritytech/oo7/blob/251ba2b7c45503b68eab4320c270b5afa9bccb60/packages/polkadot-identicon/src/index.jsx
|
|
9
|
+
|
|
10
|
+
import type { Circle, Options } from './types.js';
|
|
11
|
+
|
|
12
|
+
import { blake2AsU8a, decodeAddress } from '@pezkuwi/util-crypto';
|
|
13
|
+
|
|
14
|
+
interface Scheme {
|
|
15
|
+
freq: number;
|
|
16
|
+
colors: readonly number[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const S = 64;
|
|
20
|
+
const C = S / 2;
|
|
21
|
+
const Z = S / 64 * 5;
|
|
22
|
+
|
|
23
|
+
const SCHEMES: readonly Scheme[] = [
|
|
24
|
+
/* target */ { colors: [0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 1], freq: 1 },
|
|
25
|
+
/* cube */ { colors: [0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 5], freq: 20 },
|
|
26
|
+
/* quazar */ { colors: [1, 2, 3, 1, 2, 4, 5, 5, 4, 1, 2, 3, 1, 2, 4, 5, 5, 4, 0], freq: 16 },
|
|
27
|
+
/* flower */ { colors: [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3], freq: 32 },
|
|
28
|
+
/* cyclic */ { colors: [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6], freq: 32 },
|
|
29
|
+
/* vmirror */ { colors: [0, 1, 2, 3, 4, 5, 3, 4, 2, 0, 1, 6, 7, 8, 9, 7, 8, 6, 10], freq: 128 },
|
|
30
|
+
/* hmirror */ { colors: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 8, 6, 7, 5, 3, 4, 2, 11], freq: 128 }
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const SCHEMES_TOTAL = SCHEMES
|
|
34
|
+
.map((s): number => s.freq)
|
|
35
|
+
.reduce((a, b): number => a + b);
|
|
36
|
+
|
|
37
|
+
const OUTER_CIRCLE: Circle = {
|
|
38
|
+
cx: C,
|
|
39
|
+
cy: C,
|
|
40
|
+
fill: '#eee',
|
|
41
|
+
r: C
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let zeroHash: Uint8Array = new Uint8Array();
|
|
45
|
+
|
|
46
|
+
function getRotation (isSixPoint: boolean): { r: number; ro2: number; r3o4: number; ro4: number; rroot3o2: number; rroot3o4: number } {
|
|
47
|
+
const r = isSixPoint
|
|
48
|
+
? (C / 8 * 5)
|
|
49
|
+
: (C / 4 * 3);
|
|
50
|
+
const rroot3o2 = r * Math.sqrt(3) / 2;
|
|
51
|
+
const ro2 = r / 2;
|
|
52
|
+
const rroot3o4 = r * Math.sqrt(3) / 4;
|
|
53
|
+
const ro4 = r / 4;
|
|
54
|
+
const r3o4 = r * 3 / 4;
|
|
55
|
+
|
|
56
|
+
return { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getCircleXY (isSixPoint = false): [number, number][] {
|
|
60
|
+
const { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 } = getRotation(isSixPoint);
|
|
61
|
+
|
|
62
|
+
return [
|
|
63
|
+
[C, C - r],
|
|
64
|
+
[C, C - ro2],
|
|
65
|
+
[C - rroot3o4, C - r3o4],
|
|
66
|
+
[C - rroot3o2, C - ro2],
|
|
67
|
+
[C - rroot3o4, C - ro4],
|
|
68
|
+
[C - rroot3o2, C],
|
|
69
|
+
[C - rroot3o2, C + ro2],
|
|
70
|
+
[C - rroot3o4, C + ro4],
|
|
71
|
+
[C - rroot3o4, C + r3o4],
|
|
72
|
+
[C, C + r],
|
|
73
|
+
[C, C + ro2],
|
|
74
|
+
[C + rroot3o4, C + r3o4],
|
|
75
|
+
[C + rroot3o2, C + ro2],
|
|
76
|
+
[C + rroot3o4, C + ro4],
|
|
77
|
+
[C + rroot3o2, C],
|
|
78
|
+
[C + rroot3o2, C - ro2],
|
|
79
|
+
[C + rroot3o4, C - ro4],
|
|
80
|
+
[C + rroot3o4, C - r3o4],
|
|
81
|
+
[C, C]
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function findScheme (d: number): Scheme {
|
|
86
|
+
let cum = 0;
|
|
87
|
+
const schema = SCHEMES.find((schema): boolean => {
|
|
88
|
+
cum += schema.freq;
|
|
89
|
+
|
|
90
|
+
return d < cum;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!schema) {
|
|
94
|
+
throw new Error('Unable to find schema');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return schema;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function addressToId (address: string): Uint8Array {
|
|
101
|
+
if (!zeroHash.length) {
|
|
102
|
+
zeroHash = blake2AsU8a(new Uint8Array(32), 512);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return blake2AsU8a(decodeAddress(address), 512).map((x, i) => (x + 256 - zeroHash[i]) % 256);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getColors (address: string): string[] {
|
|
109
|
+
const id = addressToId(address);
|
|
110
|
+
const d = Math.floor((id[30] + id[31] * 256) % SCHEMES_TOTAL);
|
|
111
|
+
const rot = (id[28] % 6) * 3;
|
|
112
|
+
const sat = (Math.floor(id[29] * 70 / 256 + 26) % 80) + 30;
|
|
113
|
+
const scheme = findScheme(d);
|
|
114
|
+
const palette = Array.from(id).map((x, i): string => {
|
|
115
|
+
const b = (x + i % 28 * 58) % 256;
|
|
116
|
+
|
|
117
|
+
if (b === 0) {
|
|
118
|
+
return '#444';
|
|
119
|
+
} else if (b === 255) {
|
|
120
|
+
return 'transparent';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const h = Math.floor(b % 64 * 360 / 64);
|
|
124
|
+
const l = [53, 15, 35, 75][Math.floor(b / 64)];
|
|
125
|
+
|
|
126
|
+
return `hsl(${h}, ${sat}%, ${l}%)`;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return scheme.colors.map((_, i): string =>
|
|
130
|
+
palette[scheme.colors[i < 18 ? (i + rot) % 18 : 18]]
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @description Generates an array of the circles that make up an identicon
|
|
136
|
+
*/
|
|
137
|
+
export function polkadotIcon (address: string, { isAlternative }: Options): Circle[] {
|
|
138
|
+
const xy = getCircleXY(isAlternative);
|
|
139
|
+
let colors: string[];
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
// in some cases, e.g. RN where crypto may not be initialized, chaos can
|
|
143
|
+
// happen when hashing, in these cases we just fill with a placeholder
|
|
144
|
+
colors = getColors(address);
|
|
145
|
+
} catch {
|
|
146
|
+
colors = new Array<string>(xy.length).fill('#ddd');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return [OUTER_CIRCLE].concat(
|
|
150
|
+
xy.map(([cx, cy], index): Circle => ({
|
|
151
|
+
cx, cy, fill: colors[index], r: Z
|
|
152
|
+
}))
|
|
153
|
+
);
|
|
154
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2018-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export interface Circle {
|
|
5
|
+
cx: number;
|
|
6
|
+
cy: number;
|
|
7
|
+
fill: string;
|
|
8
|
+
r: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Options {
|
|
12
|
+
isAlternative?: boolean;
|
|
13
|
+
size?: number;
|
|
14
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2017-2026 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Do not edit, auto-generated by @pezkuwi/dev
|
|
5
|
+
// (packageInfo imports will be kept as-is, user-editable)
|
|
6
|
+
|
|
7
|
+
import { detectPackage } from '@pezkuwi/util';
|
|
8
|
+
|
|
9
|
+
import { packageInfo } from './packageInfo.js';
|
|
10
|
+
|
|
11
|
+
detectPackage(packageInfo, null, []);
|