@pezkuwi/ui-shared 3.16.8 → 3.17.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/build/README.md +3 -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.js +16 -0
- package/build/cjs/icons/beachball/container.js +22 -0
- package/build/cjs/icons/beachball/defaults.js +8 -0
- package/build/cjs/icons/beachball/demo.js +21 -0
- package/build/cjs/icons/beachball/index.js +24 -0
- package/build/cjs/icons/beachball/seeder.js +21 -0
- package/build/cjs/icons/beachball/shape/circle.js +16 -0
- package/build/cjs/icons/beachball/shape/square.js +19 -0
- package/build/cjs/icons/beachball/svg/circle.js +11 -0
- package/build/cjs/icons/beachball/svg/element.js +12 -0
- package/build/cjs/icons/beachball/svg/rect.js +10 -0
- package/build/cjs/icons/beachball/svg/svg.js +7 -0
- package/build/cjs/icons/beachball/types.js +2 -0
- package/{cjs → build/cjs}/icons/index.d.ts +1 -1
- package/build/cjs/icons/index.js +7 -0
- package/{icons/polkadot.d.ts → build/cjs/icons/pezkuwi.d.ts} +1 -1
- package/build/cjs/icons/pezkuwi.js +116 -0
- package/build/cjs/icons/types.js +2 -0
- package/build/cjs/index.js +5 -0
- package/build/cjs/packageDetect.js +5 -0
- package/build/cjs/packageInfo.js +4 -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/pezkuwi.d.ts +5 -0
- package/build/icons/pezkuwi.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/{icons → build-tsc/icons}/index.d.ts +1 -1
- package/{cjs/icons/polkadot.d.ts → build-tsc/icons/pezkuwi.d.ts} +1 -1
- package/{cjs → build-tsc-cjs}/icons/index.js +3 -3
- package/{cjs/icons/polkadot.js → build-tsc-cjs/icons/pezkuwi.js} +2 -2
- package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
- package/{icons → build-tsc-esm/icons}/index.js +1 -1
- package/{icons/polkadot.js → build-tsc-esm/icons/pezkuwi.js} +1 -1
- package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
- package/package.json +9 -308
- 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/pezkuwi.spec.ts +35 -0
- package/src/icons/pezkuwi.ts +151 -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
- /package/{LICENSE → build/LICENSE} +0 -0
- /package/{cjs → build}/bundle.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/colors.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/container.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/defaults.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/demo.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/index.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/seeder.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/shape/circle.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/shape/square.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/svg/circle.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/svg/element.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/svg/rect.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/svg/svg.d.ts +0 -0
- /package/{icons → build/cjs/icons}/beachball/types.d.ts +0 -0
- /package/{icons → build/cjs/icons}/types.d.ts +0 -0
- /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
- /package/{cjs → build/cjs}/package.json +0 -0
- /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
- /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
- /package/{icons → build/icons}/beachball/README.md +0 -0
- /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
- /package/{cjs → build-tsc}/icons/beachball/colors.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/container.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/defaults.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/demo.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/index.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/seeder.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/shape/circle.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/shape/square.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/svg/circle.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/svg/element.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/svg/rect.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/svg/svg.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/beachball/types.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/types.d.ts +0 -0
- /package/{cjs → build-tsc}/index.d.ts +0 -0
- /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
- /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
- /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/colors.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/container.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/defaults.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/demo.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/seeder.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/shape/circle.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/shape/square.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/svg/circle.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/svg/element.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/svg/rect.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/svg/svg.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/beachball/types.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/types.js +0 -0
- /package/{cjs → build-tsc-cjs}/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/packageDetect.js +0 -0
- /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/colors.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/container.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/defaults.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/demo.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/index.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/seeder.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/shape/circle.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/shape/square.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/svg/circle.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/svg/element.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/svg/rect.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/svg/svg.js +0 -0
- /package/{icons → build-tsc-esm/icons}/beachball/types.js +0 -0
- /package/{icons → build-tsc-esm/icons}/types.js +0 -0
- /package/{index.js → build-tsc-esm/index.js} +0 -0
- /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
package/build/README.md
ADDED
package/build/bundle.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.packageInfo = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./icons/index.js"), exports);
|
|
6
|
+
var packageInfo_js_1 = require("./packageInfo.js");
|
|
7
|
+
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.colors = colors;
|
|
4
|
+
const colord_1 = require("colord");
|
|
5
|
+
const defaults_js_1 = require("./defaults.js");
|
|
6
|
+
const WOBBLE = 30;
|
|
7
|
+
function colors(seeder) {
|
|
8
|
+
const amount = (seeder() * WOBBLE) - (WOBBLE / 2);
|
|
9
|
+
const all = defaults_js_1.COLORS.map((hex) => (0, colord_1.colord)(hex).rotate(amount));
|
|
10
|
+
return (alpha = 1) => {
|
|
11
|
+
const index = Math.floor(all.length * seeder());
|
|
12
|
+
return all.splice(index, 1)[0]
|
|
13
|
+
.alpha(alpha)
|
|
14
|
+
.toHslString();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.container = container;
|
|
4
|
+
function container(diameter, background = 'white', className = '', _style = {}) {
|
|
5
|
+
const element = document.createElement('div');
|
|
6
|
+
const style = Object.assign({
|
|
7
|
+
background,
|
|
8
|
+
borderRadius: `${diameter / 2}px`,
|
|
9
|
+
display: 'inline-block',
|
|
10
|
+
height: `${diameter}px`,
|
|
11
|
+
margin: '0px',
|
|
12
|
+
overflow: 'hidden',
|
|
13
|
+
padding: '0px',
|
|
14
|
+
width: `${diameter}px`
|
|
15
|
+
}, _style);
|
|
16
|
+
element.className = className;
|
|
17
|
+
element.style.background = background;
|
|
18
|
+
Object.keys(style).forEach((key) => {
|
|
19
|
+
element.style[key] = style[key];
|
|
20
|
+
});
|
|
21
|
+
return element;
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SHAPE_COUNT = exports.COLORS = void 0;
|
|
4
|
+
exports.COLORS = [
|
|
5
|
+
// https://sashat.me/2017/01/11/list-of-20-simple-distinct-colors/
|
|
6
|
+
'#ffe119', '#4363d8', '#f58231', '#fabebe', '#e6beff', '#800000', '#000075', '#a9a9a9', '#ffffff', '#000000'
|
|
7
|
+
];
|
|
8
|
+
exports.SHAPE_COUNT = 5;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("@pezkuwi/util");
|
|
4
|
+
const util_crypto_1 = require("@pezkuwi/util-crypto");
|
|
5
|
+
const index_js_1 = require("./index.js");
|
|
6
|
+
const element = document.getElementById('demo');
|
|
7
|
+
function generateIcon(seed = (0, util_crypto_1.encodeAddress)((0, util_crypto_1.randomAsU8a)(32))) {
|
|
8
|
+
const start = Date.now();
|
|
9
|
+
if ((0, util_1.isNull)(element)) {
|
|
10
|
+
throw new Error('Unable to find #demo element');
|
|
11
|
+
}
|
|
12
|
+
element.appendChild((0, index_js_1.beachballIcon)(seed, { isAlternative: false, size: 100 }, 'padded'));
|
|
13
|
+
console.log(`Icon generated in ${(Date.now() - start)}ms`);
|
|
14
|
+
}
|
|
15
|
+
function generateIcons(count = 512) {
|
|
16
|
+
generateIcon((0, util_crypto_1.encodeAddress)(new Uint8Array(32)));
|
|
17
|
+
for (let index = 1; index < count; index++) {
|
|
18
|
+
generateIcon();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
generateIcons();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.beachballIcon = beachballIcon;
|
|
4
|
+
const circle_js_1 = require("./shape/circle.js");
|
|
5
|
+
const element_js_1 = require("./svg/element.js");
|
|
6
|
+
const colors_js_1 = require("./colors.js");
|
|
7
|
+
const container_js_1 = require("./container.js");
|
|
8
|
+
const defaults_js_1 = require("./defaults.js");
|
|
9
|
+
const seeder_js_1 = require("./seeder.js");
|
|
10
|
+
function beachballIcon(seed, { size = 256 }, className = '', style) {
|
|
11
|
+
const seeder = (0, seeder_js_1.seeder)(seed);
|
|
12
|
+
const colorGen = (0, colors_js_1.colors)(seeder);
|
|
13
|
+
const outer = (0, container_js_1.container)(size, 'white', className, style);
|
|
14
|
+
const container = (0, container_js_1.container)(size, colorGen());
|
|
15
|
+
const svg = (0, element_js_1.element)(size);
|
|
16
|
+
outer.appendChild(container);
|
|
17
|
+
container.appendChild(svg);
|
|
18
|
+
for (let count = 0; count < defaults_js_1.SHAPE_COUNT; count++) {
|
|
19
|
+
const fill = colorGen();
|
|
20
|
+
const shape = (0, circle_js_1.circle)(seeder, fill, size, count);
|
|
21
|
+
svg.appendChild(shape);
|
|
22
|
+
}
|
|
23
|
+
return outer;
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.seeder = seeder;
|
|
4
|
+
const util_1 = require("@pezkuwi/util");
|
|
5
|
+
const DIVISOR = 256 * 256;
|
|
6
|
+
function seeder(_seed = new Uint8Array(32)) {
|
|
7
|
+
const seed = (0, util_1.isU8a)(_seed)
|
|
8
|
+
? _seed
|
|
9
|
+
: (0, util_1.stringToU8a)(_seed);
|
|
10
|
+
let index = (seed[Math.floor(seed.length / 2)] % seed.length) - 1;
|
|
11
|
+
const next = () => {
|
|
12
|
+
index += 1;
|
|
13
|
+
if (index === seed.length) {
|
|
14
|
+
index = 0;
|
|
15
|
+
}
|
|
16
|
+
return seed[index];
|
|
17
|
+
};
|
|
18
|
+
return () => {
|
|
19
|
+
return ((next() * 256) + next()) / DIVISOR;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.circle = circle;
|
|
4
|
+
const defaults_js_1 = require("../defaults.js");
|
|
5
|
+
const circle_js_1 = require("../svg/circle.js");
|
|
6
|
+
function circle(seeder, fill, diameter, count) {
|
|
7
|
+
const center = diameter / 2;
|
|
8
|
+
const angle = seeder() * 360;
|
|
9
|
+
const radius = (((defaults_js_1.SHAPE_COUNT - count) / defaults_js_1.SHAPE_COUNT) * (diameter / 2)) + ((diameter / 8) * seeder());
|
|
10
|
+
const offset = (diameter / 4) * (seeder() + ((count + 1) / defaults_js_1.SHAPE_COUNT));
|
|
11
|
+
const cx = (offset * Math.sin(angle)) + center;
|
|
12
|
+
const cy = (offset * Math.cos(angle)) + center;
|
|
13
|
+
const svg = (0, circle_js_1.circle)(radius, cx, cy);
|
|
14
|
+
svg.setAttributeNS('', 'fill', fill);
|
|
15
|
+
return svg;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.square = square;
|
|
4
|
+
const defaults_js_1 = require("../defaults.js");
|
|
5
|
+
const rect_js_1 = require("../svg/rect.js");
|
|
6
|
+
function square(seeder, fill, diameter, count) {
|
|
7
|
+
const center = diameter / 2;
|
|
8
|
+
const svg = (0, rect_js_1.rect)(diameter);
|
|
9
|
+
const firstRot = seeder();
|
|
10
|
+
const angle = Math.PI * 2 * firstRot;
|
|
11
|
+
const scale = count / defaults_js_1.SHAPE_COUNT;
|
|
12
|
+
const velocity = ((diameter / defaults_js_1.SHAPE_COUNT) * seeder()) + (scale * diameter);
|
|
13
|
+
const tx = (Math.cos(angle) * velocity).toFixed(3);
|
|
14
|
+
const ty = (Math.sin(angle) * velocity).toFixed(3);
|
|
15
|
+
const rot = ((firstRot * 360) + (seeder() * 180)).toFixed(1);
|
|
16
|
+
svg.setAttributeNS('', 'transform', `translate(${tx} ${ty}) rotate(${rot} ${center} ${center})`);
|
|
17
|
+
svg.setAttributeNS('', 'fill', fill);
|
|
18
|
+
return svg;
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.circle = circle;
|
|
4
|
+
const svg_js_1 = require("./svg.js");
|
|
5
|
+
function circle(r, cx, cy) {
|
|
6
|
+
const elem = (0, svg_js_1.svg)('circle');
|
|
7
|
+
elem.setAttributeNS('', 'cx', `${cx}`);
|
|
8
|
+
elem.setAttributeNS('', 'cy', `${cy}`);
|
|
9
|
+
elem.setAttributeNS('', 'r', `${r}`);
|
|
10
|
+
return elem;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.element = element;
|
|
4
|
+
const svg_js_1 = require("./svg.js");
|
|
5
|
+
function element(size, type = 'svg', x = 0, y = 0) {
|
|
6
|
+
const elem = (0, svg_js_1.svg)(type);
|
|
7
|
+
elem.setAttributeNS('', 'x', `${x}`);
|
|
8
|
+
elem.setAttributeNS('', 'y', `${y}`);
|
|
9
|
+
elem.setAttributeNS('', 'width', `${size}`);
|
|
10
|
+
elem.setAttributeNS('', 'height', `${size}`);
|
|
11
|
+
return elem;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rect = rect;
|
|
4
|
+
const element_js_1 = require("./element.js");
|
|
5
|
+
function rect(size) {
|
|
6
|
+
const elem = (0, element_js_1.element)(size, 'rect');
|
|
7
|
+
elem.setAttributeNS('', 'rx', `${size / 16}`);
|
|
8
|
+
elem.setAttributeNS('', 'ry', `${size / 16}`);
|
|
9
|
+
return elem;
|
|
10
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { beachballIcon } from './beachball/index.js';
|
|
2
|
-
export {
|
|
2
|
+
export { pezkuwiIcon } from './pezkuwi.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pezkuwiIcon = exports.beachballIcon = void 0;
|
|
4
|
+
var index_js_1 = require("./beachball/index.js");
|
|
5
|
+
Object.defineProperty(exports, "beachballIcon", { enumerable: true, get: function () { return index_js_1.beachballIcon; } });
|
|
6
|
+
var pezkuwi_js_1 = require("./pezkuwi.js");
|
|
7
|
+
Object.defineProperty(exports, "pezkuwiIcon", { enumerable: true, get: function () { return pezkuwi_js_1.pezkuwiIcon; } });
|
|
@@ -2,4 +2,4 @@ import type { Circle, Options } from './types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* @description Generates an array of the circles that make up an identicon
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function pezkuwiIcon(address: string, { isAlternative }: Options): Circle[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pezkuwiIcon = pezkuwiIcon;
|
|
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 pezkuwiIcon(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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function container(diameter: number, background?: string, className?: string, _style?: Record<string, string>): HTMLElement;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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();
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function circle(r: number, cx: number, cy: number): Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function element(size: number, type?: string, x?: number, y?: number): Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function rect(size: number): Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function svg(type: string): Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|