@pezkuwi/ui-shared 3.16.6 → 3.16.8

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.
Files changed (182) hide show
  1. package/package.json +308 -9
  2. package/build/README.md +0 -3
  3. package/build/bundle.js +0 -2
  4. package/build/cjs/bundle.d.ts +0 -2
  5. package/build/cjs/bundle.js +0 -7
  6. package/build/cjs/icons/beachball/colors.js +0 -16
  7. package/build/cjs/icons/beachball/container.js +0 -22
  8. package/build/cjs/icons/beachball/defaults.js +0 -8
  9. package/build/cjs/icons/beachball/demo.js +0 -21
  10. package/build/cjs/icons/beachball/index.js +0 -24
  11. package/build/cjs/icons/beachball/seeder.js +0 -21
  12. package/build/cjs/icons/beachball/shape/circle.js +0 -16
  13. package/build/cjs/icons/beachball/shape/square.js +0 -19
  14. package/build/cjs/icons/beachball/svg/circle.js +0 -11
  15. package/build/cjs/icons/beachball/svg/element.js +0 -12
  16. package/build/cjs/icons/beachball/svg/rect.js +0 -10
  17. package/build/cjs/icons/beachball/svg/svg.js +0 -7
  18. package/build/cjs/icons/beachball/types.js +0 -2
  19. package/build/cjs/icons/index.js +0 -7
  20. package/build/cjs/icons/polkadot.js +0 -116
  21. package/build/cjs/icons/types.js +0 -2
  22. package/build/cjs/index.js +0 -5
  23. package/build/cjs/packageDetect.js +0 -5
  24. package/build/cjs/packageInfo.js +0 -4
  25. package/build/icons/beachball/colors.d.ts +0 -2
  26. package/build/icons/beachball/colors.js +0 -13
  27. package/build/icons/beachball/container.d.ts +0 -1
  28. package/build/icons/beachball/container.js +0 -19
  29. package/build/icons/beachball/defaults.d.ts +0 -2
  30. package/build/icons/beachball/defaults.js +0 -5
  31. package/build/icons/beachball/demo.d.ts +0 -1
  32. package/build/icons/beachball/demo.js +0 -19
  33. package/build/icons/beachball/index.d.ts +0 -2
  34. package/build/icons/beachball/index.js +0 -21
  35. package/build/icons/beachball/seeder.d.ts +0 -2
  36. package/build/icons/beachball/seeder.js +0 -18
  37. package/build/icons/beachball/shape/circle.d.ts +0 -2
  38. package/build/icons/beachball/shape/circle.js +0 -13
  39. package/build/icons/beachball/shape/square.d.ts +0 -2
  40. package/build/icons/beachball/shape/square.js +0 -16
  41. package/build/icons/beachball/svg/circle.d.ts +0 -1
  42. package/build/icons/beachball/svg/circle.js +0 -8
  43. package/build/icons/beachball/svg/element.d.ts +0 -1
  44. package/build/icons/beachball/svg/element.js +0 -9
  45. package/build/icons/beachball/svg/rect.d.ts +0 -1
  46. package/build/icons/beachball/svg/rect.js +0 -7
  47. package/build/icons/beachball/svg/svg.d.ts +0 -1
  48. package/build/icons/beachball/svg/svg.js +0 -4
  49. package/build/icons/beachball/types.d.ts +0 -2
  50. package/build/icons/beachball/types.js +0 -1
  51. package/build/icons/index.d.ts +0 -2
  52. package/build/icons/index.js +0 -2
  53. package/build/icons/polkadot.d.ts +0 -5
  54. package/build/icons/polkadot.js +0 -113
  55. package/build/icons/types.d.ts +0 -10
  56. package/build/icons/types.js +0 -1
  57. package/build/index.d.ts +0 -2
  58. package/build/index.js +0 -2
  59. package/build/package.json +0 -336
  60. package/build/packageDetect.d.ts +0 -1
  61. package/build/packageDetect.js +0 -3
  62. package/build/packageInfo.d.ts +0 -6
  63. package/build/packageInfo.js +0 -1
  64. package/src/bundle.ts +0 -5
  65. package/src/icons/beachball/LICENSE +0 -16
  66. package/src/icons/beachball/README.md +0 -19
  67. package/src/icons/beachball/colors.spec.ts +0 -67
  68. package/src/icons/beachball/colors.ts +0 -28
  69. package/src/icons/beachball/container.spec.ts +0 -46
  70. package/src/icons/beachball/container.ts +0 -27
  71. package/src/icons/beachball/defaults.ts +0 -11
  72. package/src/icons/beachball/demo.ts +0 -35
  73. package/src/icons/beachball/index.spec.ts +0 -36
  74. package/src/icons/beachball/index.ts +0 -33
  75. package/src/icons/beachball/seeder.spec.ts +0 -30
  76. package/src/icons/beachball/seeder.ts +0 -30
  77. package/src/icons/beachball/shape/circle.spec.ts +0 -20
  78. package/src/icons/beachball/shape/circle.ts +0 -23
  79. package/src/icons/beachball/shape/square.ts +0 -26
  80. package/src/icons/beachball/svg/circle.spec.ts +0 -19
  81. package/src/icons/beachball/svg/circle.ts +0 -14
  82. package/src/icons/beachball/svg/element.spec.ts +0 -19
  83. package/src/icons/beachball/svg/element.ts +0 -17
  84. package/src/icons/beachball/svg/rect.spec.ts +0 -19
  85. package/src/icons/beachball/svg/rect.ts +0 -13
  86. package/src/icons/beachball/svg/svg.spec.ts +0 -19
  87. package/src/icons/beachball/svg/svg.ts +0 -10
  88. package/src/icons/beachball/types.ts +0 -6
  89. package/src/icons/index.ts +0 -5
  90. package/src/icons/polkadot.spec.ts +0 -35
  91. package/src/icons/polkadot.ts +0 -154
  92. package/src/icons/types.ts +0 -14
  93. package/src/index.ts +0 -6
  94. package/src/packageDetect.ts +0 -11
  95. package/src/packageInfo.ts +0 -6
  96. package/tsconfig.build.json +0 -12
  97. package/tsconfig.build.tsbuildinfo +0 -1
  98. package/tsconfig.spec.json +0 -16
  99. package/tsconfig.spec.tsbuildinfo +0 -1
  100. /package/{build/LICENSE → LICENSE} +0 -0
  101. /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
  102. /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
  103. /package/{build → cjs}/bundle.d.ts +0 -0
  104. /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
  105. /package/{build-tsc → cjs}/icons/beachball/colors.d.ts +0 -0
  106. /package/{build-tsc-cjs → cjs}/icons/beachball/colors.js +0 -0
  107. /package/{build-tsc → cjs}/icons/beachball/container.d.ts +0 -0
  108. /package/{build-tsc-cjs → cjs}/icons/beachball/container.js +0 -0
  109. /package/{build-tsc → cjs}/icons/beachball/defaults.d.ts +0 -0
  110. /package/{build-tsc-cjs → cjs}/icons/beachball/defaults.js +0 -0
  111. /package/{build-tsc → cjs}/icons/beachball/demo.d.ts +0 -0
  112. /package/{build-tsc-cjs → cjs}/icons/beachball/demo.js +0 -0
  113. /package/{build-tsc → cjs}/icons/beachball/index.d.ts +0 -0
  114. /package/{build-tsc-cjs → cjs}/icons/beachball/index.js +0 -0
  115. /package/{build-tsc → cjs}/icons/beachball/seeder.d.ts +0 -0
  116. /package/{build-tsc-cjs → cjs}/icons/beachball/seeder.js +0 -0
  117. /package/{build-tsc → cjs}/icons/beachball/shape/circle.d.ts +0 -0
  118. /package/{build-tsc-cjs → cjs}/icons/beachball/shape/circle.js +0 -0
  119. /package/{build-tsc → cjs}/icons/beachball/shape/square.d.ts +0 -0
  120. /package/{build-tsc-cjs → cjs}/icons/beachball/shape/square.js +0 -0
  121. /package/{build-tsc → cjs}/icons/beachball/svg/circle.d.ts +0 -0
  122. /package/{build-tsc-cjs → cjs}/icons/beachball/svg/circle.js +0 -0
  123. /package/{build-tsc → cjs}/icons/beachball/svg/element.d.ts +0 -0
  124. /package/{build-tsc-cjs → cjs}/icons/beachball/svg/element.js +0 -0
  125. /package/{build-tsc → cjs}/icons/beachball/svg/rect.d.ts +0 -0
  126. /package/{build-tsc-cjs → cjs}/icons/beachball/svg/rect.js +0 -0
  127. /package/{build-tsc → cjs}/icons/beachball/svg/svg.d.ts +0 -0
  128. /package/{build-tsc-cjs → cjs}/icons/beachball/svg/svg.js +0 -0
  129. /package/{build-tsc → cjs}/icons/beachball/types.d.ts +0 -0
  130. /package/{build-tsc-cjs → cjs}/icons/beachball/types.js +0 -0
  131. /package/{build-tsc → cjs}/icons/index.d.ts +0 -0
  132. /package/{build-tsc-cjs → cjs}/icons/index.js +0 -0
  133. /package/{build-tsc → cjs}/icons/polkadot.d.ts +0 -0
  134. /package/{build-tsc-cjs → cjs}/icons/polkadot.js +0 -0
  135. /package/{build-tsc → cjs}/icons/types.d.ts +0 -0
  136. /package/{build-tsc-cjs → cjs}/icons/types.js +0 -0
  137. /package/{build-tsc → cjs}/index.d.ts +0 -0
  138. /package/{build-tsc-cjs → cjs}/index.js +0 -0
  139. /package/{build/cjs → cjs}/package.json +0 -0
  140. /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
  141. /package/{build-tsc-cjs → cjs}/packageDetect.js +0 -0
  142. /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
  143. /package/{build-tsc-cjs → cjs}/packageInfo.js +0 -0
  144. /package/{build/icons → icons}/beachball/README.md +0 -0
  145. /package/{build/cjs/icons → icons}/beachball/colors.d.ts +0 -0
  146. /package/{build-tsc-esm/icons → icons}/beachball/colors.js +0 -0
  147. /package/{build/cjs/icons → icons}/beachball/container.d.ts +0 -0
  148. /package/{build-tsc-esm/icons → icons}/beachball/container.js +0 -0
  149. /package/{build/cjs/icons → icons}/beachball/defaults.d.ts +0 -0
  150. /package/{build-tsc-esm/icons → icons}/beachball/defaults.js +0 -0
  151. /package/{build/cjs/icons → icons}/beachball/demo.d.ts +0 -0
  152. /package/{build-tsc-esm/icons → icons}/beachball/demo.js +0 -0
  153. /package/{build/cjs/icons → icons}/beachball/index.d.ts +0 -0
  154. /package/{build-tsc-esm/icons → icons}/beachball/index.js +0 -0
  155. /package/{build/cjs/icons → icons}/beachball/seeder.d.ts +0 -0
  156. /package/{build-tsc-esm/icons → icons}/beachball/seeder.js +0 -0
  157. /package/{build/cjs/icons → icons}/beachball/shape/circle.d.ts +0 -0
  158. /package/{build-tsc-esm/icons → icons}/beachball/shape/circle.js +0 -0
  159. /package/{build/cjs/icons → icons}/beachball/shape/square.d.ts +0 -0
  160. /package/{build-tsc-esm/icons → icons}/beachball/shape/square.js +0 -0
  161. /package/{build/cjs/icons → icons}/beachball/svg/circle.d.ts +0 -0
  162. /package/{build-tsc-esm/icons → icons}/beachball/svg/circle.js +0 -0
  163. /package/{build/cjs/icons → icons}/beachball/svg/element.d.ts +0 -0
  164. /package/{build-tsc-esm/icons → icons}/beachball/svg/element.js +0 -0
  165. /package/{build/cjs/icons → icons}/beachball/svg/rect.d.ts +0 -0
  166. /package/{build-tsc-esm/icons → icons}/beachball/svg/rect.js +0 -0
  167. /package/{build/cjs/icons → icons}/beachball/svg/svg.d.ts +0 -0
  168. /package/{build-tsc-esm/icons → icons}/beachball/svg/svg.js +0 -0
  169. /package/{build/cjs/icons → icons}/beachball/types.d.ts +0 -0
  170. /package/{build-tsc-esm/icons → icons}/beachball/types.js +0 -0
  171. /package/{build/cjs/icons → icons}/index.d.ts +0 -0
  172. /package/{build-tsc-esm/icons → icons}/index.js +0 -0
  173. /package/{build/cjs/icons → icons}/polkadot.d.ts +0 -0
  174. /package/{build-tsc-esm/icons → icons}/polkadot.js +0 -0
  175. /package/{build/cjs/icons → icons}/types.d.ts +0 -0
  176. /package/{build-tsc-esm/icons → icons}/types.js +0 -0
  177. /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
  178. /package/{build-tsc-esm/index.js → index.js} +0 -0
  179. /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
  180. /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
  181. /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
  182. /package/{build-tsc-esm/packageInfo.js → packageInfo.js} +0 -0
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.polkadotIcon = polkadotIcon;
4
- const util_crypto_1 = require("@pezkuwi/util-crypto");
5
- const S = 64;
6
- const C = S / 2;
7
- const Z = S / 64 * 5;
8
- const SCHEMES = [
9
- /* target */ { colors: [0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 1], freq: 1 },
10
- /* cube */ { colors: [0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 5], freq: 20 },
11
- /* quazar */ { colors: [1, 2, 3, 1, 2, 4, 5, 5, 4, 1, 2, 3, 1, 2, 4, 5, 5, 4, 0], freq: 16 },
12
- /* flower */ { colors: [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3], freq: 32 },
13
- /* cyclic */ { colors: [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6], freq: 32 },
14
- /* vmirror */ { colors: [0, 1, 2, 3, 4, 5, 3, 4, 2, 0, 1, 6, 7, 8, 9, 7, 8, 6, 10], freq: 128 },
15
- /* hmirror */ { colors: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 8, 6, 7, 5, 3, 4, 2, 11], freq: 128 }
16
- ];
17
- const SCHEMES_TOTAL = SCHEMES
18
- .map((s) => s.freq)
19
- .reduce((a, b) => a + b);
20
- const OUTER_CIRCLE = {
21
- cx: C,
22
- cy: C,
23
- fill: '#eee',
24
- r: C
25
- };
26
- let zeroHash = new Uint8Array();
27
- function getRotation(isSixPoint) {
28
- const r = isSixPoint
29
- ? (C / 8 * 5)
30
- : (C / 4 * 3);
31
- const rroot3o2 = r * Math.sqrt(3) / 2;
32
- const ro2 = r / 2;
33
- const rroot3o4 = r * Math.sqrt(3) / 4;
34
- const ro4 = r / 4;
35
- const r3o4 = r * 3 / 4;
36
- return { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 };
37
- }
38
- function getCircleXY(isSixPoint = false) {
39
- const { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 } = getRotation(isSixPoint);
40
- return [
41
- [C, C - r],
42
- [C, C - ro2],
43
- [C - rroot3o4, C - r3o4],
44
- [C - rroot3o2, C - ro2],
45
- [C - rroot3o4, C - ro4],
46
- [C - rroot3o2, C],
47
- [C - rroot3o2, C + ro2],
48
- [C - rroot3o4, C + ro4],
49
- [C - rroot3o4, C + r3o4],
50
- [C, C + r],
51
- [C, C + ro2],
52
- [C + rroot3o4, C + r3o4],
53
- [C + rroot3o2, C + ro2],
54
- [C + rroot3o4, C + ro4],
55
- [C + rroot3o2, C],
56
- [C + rroot3o2, C - ro2],
57
- [C + rroot3o4, C - ro4],
58
- [C + rroot3o4, C - r3o4],
59
- [C, C]
60
- ];
61
- }
62
- function findScheme(d) {
63
- let cum = 0;
64
- const schema = SCHEMES.find((schema) => {
65
- cum += schema.freq;
66
- return d < cum;
67
- });
68
- if (!schema) {
69
- throw new Error('Unable to find schema');
70
- }
71
- return schema;
72
- }
73
- function addressToId(address) {
74
- if (!zeroHash.length) {
75
- zeroHash = (0, util_crypto_1.blake2AsU8a)(new Uint8Array(32), 512);
76
- }
77
- return (0, util_crypto_1.blake2AsU8a)((0, util_crypto_1.decodeAddress)(address), 512).map((x, i) => (x + 256 - zeroHash[i]) % 256);
78
- }
79
- function getColors(address) {
80
- const id = addressToId(address);
81
- const d = Math.floor((id[30] + id[31] * 256) % SCHEMES_TOTAL);
82
- const rot = (id[28] % 6) * 3;
83
- const sat = (Math.floor(id[29] * 70 / 256 + 26) % 80) + 30;
84
- const scheme = findScheme(d);
85
- const palette = Array.from(id).map((x, i) => {
86
- const b = (x + i % 28 * 58) % 256;
87
- if (b === 0) {
88
- return '#444';
89
- }
90
- else if (b === 255) {
91
- return 'transparent';
92
- }
93
- const h = Math.floor(b % 64 * 360 / 64);
94
- const l = [53, 15, 35, 75][Math.floor(b / 64)];
95
- return `hsl(${h}, ${sat}%, ${l}%)`;
96
- });
97
- return scheme.colors.map((_, i) => palette[scheme.colors[i < 18 ? (i + rot) % 18 : 18]]);
98
- }
99
- /**
100
- * @description Generates an array of the circles that make up an identicon
101
- */
102
- function polkadotIcon(address, { isAlternative }) {
103
- const xy = getCircleXY(isAlternative);
104
- let colors;
105
- try {
106
- // in some cases, e.g. RN where crypto may not be initialized, chaos can
107
- // happen when hashing, in these cases we just fill with a placeholder
108
- colors = getColors(address);
109
- }
110
- catch {
111
- colors = new Array(xy.length).fill('#ddd');
112
- }
113
- return [OUTER_CIRCLE].concat(xy.map(([cx, cy], index) => ({
114
- cx, cy, fill: colors[index], r: Z
115
- })));
116
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- require("./packageDetect.js");
5
- tslib_1.__exportStar(require("./bundle.js"), exports);
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("@pezkuwi/util");
4
- const packageInfo_js_1 = require("./packageInfo.js");
5
- (0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, []);
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packageInfo = void 0;
4
- exports.packageInfo = { name: '@pezkuwi/ui-shared', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '3.16.6' };
@@ -1,2 +0,0 @@
1
- import type { ColorGen, Seeder } from './types.js';
2
- export declare function colors(seeder: Seeder): ColorGen;
@@ -1,13 +0,0 @@
1
- import { colord } from 'colord';
2
- import { COLORS } from './defaults.js';
3
- const WOBBLE = 30;
4
- export function colors(seeder) {
5
- const amount = (seeder() * WOBBLE) - (WOBBLE / 2);
6
- const all = COLORS.map((hex) => colord(hex).rotate(amount));
7
- return (alpha = 1) => {
8
- const index = Math.floor(all.length * seeder());
9
- return all.splice(index, 1)[0]
10
- .alpha(alpha)
11
- .toHslString();
12
- };
13
- }
@@ -1 +0,0 @@
1
- export declare function container(diameter: number, background?: string, className?: string, _style?: Record<string, string>): HTMLElement;
@@ -1,19 +0,0 @@
1
- export function container(diameter, background = 'white', className = '', _style = {}) {
2
- const element = document.createElement('div');
3
- const style = Object.assign({
4
- background,
5
- borderRadius: `${diameter / 2}px`,
6
- display: 'inline-block',
7
- height: `${diameter}px`,
8
- margin: '0px',
9
- overflow: 'hidden',
10
- padding: '0px',
11
- width: `${diameter}px`
12
- }, _style);
13
- element.className = className;
14
- element.style.background = background;
15
- Object.keys(style).forEach((key) => {
16
- element.style[key] = style[key];
17
- });
18
- return element;
19
- }
@@ -1,2 +0,0 @@
1
- export declare const COLORS: readonly string[];
2
- export declare const SHAPE_COUNT: 5;
@@ -1,5 +0,0 @@
1
- export const COLORS = [
2
- // https://sashat.me/2017/01/11/list-of-20-simple-distinct-colors/
3
- '#ffe119', '#4363d8', '#f58231', '#fabebe', '#e6beff', '#800000', '#000075', '#a9a9a9', '#ffffff', '#000000'
4
- ];
5
- export const SHAPE_COUNT = 5;
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import { isNull } from '@pezkuwi/util';
2
- import { encodeAddress, randomAsU8a } from '@pezkuwi/util-crypto';
3
- import { beachballIcon } from './index.js';
4
- const element = document.getElementById('demo');
5
- function generateIcon(seed = encodeAddress(randomAsU8a(32))) {
6
- const start = Date.now();
7
- if (isNull(element)) {
8
- throw new Error('Unable to find #demo element');
9
- }
10
- element.appendChild(beachballIcon(seed, { isAlternative: false, size: 100 }, 'padded'));
11
- console.log(`Icon generated in ${(Date.now() - start)}ms`);
12
- }
13
- function generateIcons(count = 512) {
14
- generateIcon(encodeAddress(new Uint8Array(32)));
15
- for (let index = 1; index < count; index++) {
16
- generateIcon();
17
- }
18
- }
19
- generateIcons();
@@ -1,2 +0,0 @@
1
- import type { Options } from '../types.js';
2
- export declare function beachballIcon(seed: string | Uint8Array, { size }: Options, className?: string, style?: Record<string, string>): HTMLElement;
@@ -1,21 +0,0 @@
1
- import { circle } from './shape/circle.js';
2
- import { element } from './svg/element.js';
3
- import { colors } from './colors.js';
4
- import { container as newContainer } from './container.js';
5
- import { SHAPE_COUNT } from './defaults.js';
6
- import { seeder as newSeeder } from './seeder.js';
7
- export function beachballIcon(seed, { size = 256 }, className = '', style) {
8
- const seeder = newSeeder(seed);
9
- const colorGen = colors(seeder);
10
- const outer = newContainer(size, 'white', className, style);
11
- const container = newContainer(size, colorGen());
12
- const svg = element(size);
13
- outer.appendChild(container);
14
- container.appendChild(svg);
15
- for (let count = 0; count < SHAPE_COUNT; count++) {
16
- const fill = colorGen();
17
- const shape = circle(seeder, fill, size, count);
18
- svg.appendChild(shape);
19
- }
20
- return outer;
21
- }
@@ -1,2 +0,0 @@
1
- import type { Seeder } from './types.js';
2
- export declare function seeder(_seed?: string | Uint8Array): Seeder;
@@ -1,18 +0,0 @@
1
- import { isU8a, stringToU8a } from '@pezkuwi/util';
2
- const DIVISOR = 256 * 256;
3
- export function seeder(_seed = new Uint8Array(32)) {
4
- const seed = isU8a(_seed)
5
- ? _seed
6
- : stringToU8a(_seed);
7
- let index = (seed[Math.floor(seed.length / 2)] % seed.length) - 1;
8
- const next = () => {
9
- index += 1;
10
- if (index === seed.length) {
11
- index = 0;
12
- }
13
- return seed[index];
14
- };
15
- return () => {
16
- return ((next() * 256) + next()) / DIVISOR;
17
- };
18
- }
@@ -1,2 +0,0 @@
1
- import type { Seeder } from '../types.js';
2
- export declare function circle(seeder: Seeder, fill: string, diameter: number, count: number): Element;
@@ -1,13 +0,0 @@
1
- import { SHAPE_COUNT } from '../defaults.js';
2
- import { circle as newCircle } from '../svg/circle.js';
3
- export function circle(seeder, fill, diameter, count) {
4
- const center = diameter / 2;
5
- const angle = seeder() * 360;
6
- const radius = (((SHAPE_COUNT - count) / SHAPE_COUNT) * (diameter / 2)) + ((diameter / 8) * seeder());
7
- const offset = (diameter / 4) * (seeder() + ((count + 1) / SHAPE_COUNT));
8
- const cx = (offset * Math.sin(angle)) + center;
9
- const cy = (offset * Math.cos(angle)) + center;
10
- const svg = newCircle(radius, cx, cy);
11
- svg.setAttributeNS('', 'fill', fill);
12
- return svg;
13
- }
@@ -1,2 +0,0 @@
1
- import type { Seeder } from '../types.js';
2
- export declare function square(seeder: Seeder, fill: string, diameter: number, count: number): Element;
@@ -1,16 +0,0 @@
1
- import { SHAPE_COUNT } from '../defaults.js';
2
- import { rect as newRect } from '../svg/rect.js';
3
- export function square(seeder, fill, diameter, count) {
4
- const center = diameter / 2;
5
- const svg = newRect(diameter);
6
- const firstRot = seeder();
7
- const angle = Math.PI * 2 * firstRot;
8
- const scale = count / SHAPE_COUNT;
9
- const velocity = ((diameter / SHAPE_COUNT) * seeder()) + (scale * diameter);
10
- const tx = (Math.cos(angle) * velocity).toFixed(3);
11
- const ty = (Math.sin(angle) * velocity).toFixed(3);
12
- const rot = ((firstRot * 360) + (seeder() * 180)).toFixed(1);
13
- svg.setAttributeNS('', 'transform', `translate(${tx} ${ty}) rotate(${rot} ${center} ${center})`);
14
- svg.setAttributeNS('', 'fill', fill);
15
- return svg;
16
- }
@@ -1 +0,0 @@
1
- export declare function circle(r: number, cx: number, cy: number): Element;
@@ -1,8 +0,0 @@
1
- import { svg } from './svg.js';
2
- export function circle(r, cx, cy) {
3
- const elem = svg('circle');
4
- elem.setAttributeNS('', 'cx', `${cx}`);
5
- elem.setAttributeNS('', 'cy', `${cy}`);
6
- elem.setAttributeNS('', 'r', `${r}`);
7
- return elem;
8
- }
@@ -1 +0,0 @@
1
- export declare function element(size: number, type?: string, x?: number, y?: number): Element;
@@ -1,9 +0,0 @@
1
- import { svg } from './svg.js';
2
- export function element(size, type = 'svg', x = 0, y = 0) {
3
- const elem = svg(type);
4
- elem.setAttributeNS('', 'x', `${x}`);
5
- elem.setAttributeNS('', 'y', `${y}`);
6
- elem.setAttributeNS('', 'width', `${size}`);
7
- elem.setAttributeNS('', 'height', `${size}`);
8
- return elem;
9
- }
@@ -1 +0,0 @@
1
- export declare function rect(size: number): Element;
@@ -1,7 +0,0 @@
1
- import { element } from './element.js';
2
- export function rect(size) {
3
- const elem = element(size, 'rect');
4
- elem.setAttributeNS('', 'rx', `${size / 16}`);
5
- elem.setAttributeNS('', 'ry', `${size / 16}`);
6
- return elem;
7
- }
@@ -1 +0,0 @@
1
- export declare function svg(type: string): Element;
@@ -1,4 +0,0 @@
1
- const SVG_NS = 'http://www.w3.org/2000/svg';
2
- export function svg(type) {
3
- return document.createElementNS(SVG_NS, type);
4
- }
@@ -1,2 +0,0 @@
1
- export type Seeder = () => number;
2
- export type ColorGen = (alpha?: number) => string;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export { beachballIcon } from './beachball/index.js';
2
- export { polkadotIcon } from './polkadot.js';
@@ -1,2 +0,0 @@
1
- export { beachballIcon } from './beachball/index.js';
2
- export { polkadotIcon } from './polkadot.js';
@@ -1,5 +0,0 @@
1
- import type { Circle, Options } from './types.js';
2
- /**
3
- * @description Generates an array of the circles that make up an identicon
4
- */
5
- export declare function polkadotIcon(address: string, { isAlternative }: Options): Circle[];
@@ -1,113 +0,0 @@
1
- import { blake2AsU8a, decodeAddress } from '@pezkuwi/util-crypto';
2
- const S = 64;
3
- const C = S / 2;
4
- const Z = S / 64 * 5;
5
- const SCHEMES = [
6
- /* target */ { colors: [0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 1], freq: 1 },
7
- /* cube */ { colors: [0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 5], freq: 20 },
8
- /* quazar */ { colors: [1, 2, 3, 1, 2, 4, 5, 5, 4, 1, 2, 3, 1, 2, 4, 5, 5, 4, 0], freq: 16 },
9
- /* flower */ { colors: [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3], freq: 32 },
10
- /* cyclic */ { colors: [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6], freq: 32 },
11
- /* vmirror */ { colors: [0, 1, 2, 3, 4, 5, 3, 4, 2, 0, 1, 6, 7, 8, 9, 7, 8, 6, 10], freq: 128 },
12
- /* hmirror */ { colors: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 8, 6, 7, 5, 3, 4, 2, 11], freq: 128 }
13
- ];
14
- const SCHEMES_TOTAL = SCHEMES
15
- .map((s) => s.freq)
16
- .reduce((a, b) => a + b);
17
- const OUTER_CIRCLE = {
18
- cx: C,
19
- cy: C,
20
- fill: '#eee',
21
- r: C
22
- };
23
- let zeroHash = new Uint8Array();
24
- function getRotation(isSixPoint) {
25
- const r = isSixPoint
26
- ? (C / 8 * 5)
27
- : (C / 4 * 3);
28
- const rroot3o2 = r * Math.sqrt(3) / 2;
29
- const ro2 = r / 2;
30
- const rroot3o4 = r * Math.sqrt(3) / 4;
31
- const ro4 = r / 4;
32
- const r3o4 = r * 3 / 4;
33
- return { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 };
34
- }
35
- function getCircleXY(isSixPoint = false) {
36
- const { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 } = getRotation(isSixPoint);
37
- return [
38
- [C, C - r],
39
- [C, C - ro2],
40
- [C - rroot3o4, C - r3o4],
41
- [C - rroot3o2, C - ro2],
42
- [C - rroot3o4, C - ro4],
43
- [C - rroot3o2, C],
44
- [C - rroot3o2, C + ro2],
45
- [C - rroot3o4, C + ro4],
46
- [C - rroot3o4, C + r3o4],
47
- [C, C + r],
48
- [C, C + ro2],
49
- [C + rroot3o4, C + r3o4],
50
- [C + rroot3o2, C + ro2],
51
- [C + rroot3o4, C + ro4],
52
- [C + rroot3o2, C],
53
- [C + rroot3o2, C - ro2],
54
- [C + rroot3o4, C - ro4],
55
- [C + rroot3o4, C - r3o4],
56
- [C, C]
57
- ];
58
- }
59
- function findScheme(d) {
60
- let cum = 0;
61
- const schema = SCHEMES.find((schema) => {
62
- cum += schema.freq;
63
- return d < cum;
64
- });
65
- if (!schema) {
66
- throw new Error('Unable to find schema');
67
- }
68
- return schema;
69
- }
70
- function addressToId(address) {
71
- if (!zeroHash.length) {
72
- zeroHash = blake2AsU8a(new Uint8Array(32), 512);
73
- }
74
- return blake2AsU8a(decodeAddress(address), 512).map((x, i) => (x + 256 - zeroHash[i]) % 256);
75
- }
76
- function getColors(address) {
77
- const id = addressToId(address);
78
- const d = Math.floor((id[30] + id[31] * 256) % SCHEMES_TOTAL);
79
- const rot = (id[28] % 6) * 3;
80
- const sat = (Math.floor(id[29] * 70 / 256 + 26) % 80) + 30;
81
- const scheme = findScheme(d);
82
- const palette = Array.from(id).map((x, i) => {
83
- const b = (x + i % 28 * 58) % 256;
84
- if (b === 0) {
85
- return '#444';
86
- }
87
- else if (b === 255) {
88
- return 'transparent';
89
- }
90
- const h = Math.floor(b % 64 * 360 / 64);
91
- const l = [53, 15, 35, 75][Math.floor(b / 64)];
92
- return `hsl(${h}, ${sat}%, ${l}%)`;
93
- });
94
- return scheme.colors.map((_, i) => palette[scheme.colors[i < 18 ? (i + rot) % 18 : 18]]);
95
- }
96
- /**
97
- * @description Generates an array of the circles that make up an identicon
98
- */
99
- export function polkadotIcon(address, { isAlternative }) {
100
- const xy = getCircleXY(isAlternative);
101
- let colors;
102
- try {
103
- // in some cases, e.g. RN where crypto may not be initialized, chaos can
104
- // happen when hashing, in these cases we just fill with a placeholder
105
- colors = getColors(address);
106
- }
107
- catch {
108
- colors = new Array(xy.length).fill('#ddd');
109
- }
110
- return [OUTER_CIRCLE].concat(xy.map(([cx, cy], index) => ({
111
- cx, cy, fill: colors[index], r: Z
112
- })));
113
- }
@@ -1,10 +0,0 @@
1
- export interface Circle {
2
- cx: number;
3
- cy: number;
4
- fill: string;
5
- r: number;
6
- }
7
- export interface Options {
8
- isAlternative?: boolean;
9
- size?: number;
10
- }
@@ -1 +0,0 @@
1
- export {};
package/build/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import './packageDetect.js';
2
- export * from './bundle.js';
package/build/index.js DELETED
@@ -1,2 +0,0 @@
1
- import './packageDetect.js';
2
- export * from './bundle.js';