@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,46 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import { container } from './container.js';
|
|
7
|
+
|
|
8
|
+
describe('container', (): void => {
|
|
9
|
+
it('applies default styles', (): void => {
|
|
10
|
+
expect(
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
|
|
12
|
+
(container(100).style as any)._values
|
|
13
|
+
).toMatchObject({
|
|
14
|
+
background: 'white',
|
|
15
|
+
'border-radius': '50px',
|
|
16
|
+
display: 'inline-block',
|
|
17
|
+
height: '100px',
|
|
18
|
+
margin: '0px',
|
|
19
|
+
overflow: 'hidden',
|
|
20
|
+
padding: '0px',
|
|
21
|
+
width: '100px'
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('overrides with supplied styles', (): void => {
|
|
26
|
+
expect(
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
|
|
28
|
+
(container(50, 'black', '', { display: 'block' }).style as any)._values
|
|
29
|
+
).toMatchObject({
|
|
30
|
+
background: 'black',
|
|
31
|
+
'border-radius': '25px',
|
|
32
|
+
display: 'block',
|
|
33
|
+
height: '50px',
|
|
34
|
+
margin: '0px',
|
|
35
|
+
overflow: 'hidden',
|
|
36
|
+
padding: '0px',
|
|
37
|
+
width: '50px'
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('applies the specified className', (): void => {
|
|
42
|
+
expect(
|
|
43
|
+
container(100, 'blue', 'testClass').className
|
|
44
|
+
).toEqual('testClass');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
export function container (diameter: number, background = 'white', className = '', _style: Record<string, string> = {}): HTMLElement {
|
|
7
|
+
const element = document.createElement('div');
|
|
8
|
+
const style = Object.assign({
|
|
9
|
+
background,
|
|
10
|
+
borderRadius: `${diameter / 2}px`,
|
|
11
|
+
display: 'inline-block',
|
|
12
|
+
height: `${diameter}px`,
|
|
13
|
+
margin: '0px',
|
|
14
|
+
overflow: 'hidden',
|
|
15
|
+
padding: '0px',
|
|
16
|
+
width: `${diameter}px`
|
|
17
|
+
}, _style);
|
|
18
|
+
|
|
19
|
+
element.className = className;
|
|
20
|
+
element.style.background = background;
|
|
21
|
+
|
|
22
|
+
Object.keys(style).forEach((key: unknown): void => {
|
|
23
|
+
element.style[key as number] = style[key as number];
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return element;
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
export const COLORS: readonly string[] = [
|
|
7
|
+
// https://sashat.me/2017/01/11/list-of-20-simple-distinct-colors/
|
|
8
|
+
'#ffe119', '#4363d8', '#f58231', '#fabebe', '#e6beff', '#800000', '#000075', '#a9a9a9', '#ffffff', '#000000'
|
|
9
|
+
] as const;
|
|
10
|
+
|
|
11
|
+
export const SHAPE_COUNT = 5 as const;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
import { isNull } from '@pezkuwi/util';
|
|
7
|
+
import { encodeAddress, randomAsU8a } from '@pezkuwi/util-crypto';
|
|
8
|
+
|
|
9
|
+
import { beachballIcon } from './index.js';
|
|
10
|
+
|
|
11
|
+
const element = document.getElementById('demo');
|
|
12
|
+
|
|
13
|
+
function generateIcon (seed: string = encodeAddress(randomAsU8a(32))): void {
|
|
14
|
+
const start = Date.now();
|
|
15
|
+
|
|
16
|
+
if (isNull(element)) {
|
|
17
|
+
throw new Error('Unable to find #demo element');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
element.appendChild(
|
|
21
|
+
beachballIcon(seed, { isAlternative: false, size: 100 }, 'padded')
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
console.log(`Icon generated in ${(Date.now() - start)}ms`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function generateIcons (count = 512): void {
|
|
28
|
+
generateIcon(encodeAddress(new Uint8Array(32)));
|
|
29
|
+
|
|
30
|
+
for (let index = 1; index < count; index++) {
|
|
31
|
+
generateIcon();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
generateIcons();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import xmlserializer from 'xmlserializer';
|
|
7
|
+
|
|
8
|
+
import { beachballIcon } from './index.js';
|
|
9
|
+
|
|
10
|
+
describe('identicon', (): void => {
|
|
11
|
+
it('generates a basic [0,..,0] identicon', (): void => {
|
|
12
|
+
expect(
|
|
13
|
+
xmlserializer.serializeToString(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
|
|
15
|
+
beachballIcon(new Uint8Array(32), { isAlternative: false, size: 256 }) as any
|
|
16
|
+
)
|
|
17
|
+
).toEqual(
|
|
18
|
+
// with original color ...
|
|
19
|
+
// '<div xmlns="http://www.w3.org/1999/xhtml" class="" style="background: white; border-radius: 128px; display: inline-block; height: 256px; margin: 0px; overflow: hidden; padding: 0px; width: 256px;"><div class="" style="background: rgb(20, 20, 20); border-radius: 128px; display: inline-block; height: 256px; margin: 0px; overflow: hidden; padding: 0px; width: 256px;"><svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="256" height="256"><circle cx="128" cy="140.8" r="128" fill="hsl(212.10000000000002, 65.6%, 55.5%)"/><circle cx="128" cy="153.6" r="102.4" fill="hsl(9.800000000000011, 90.7%, 57.6%)"/><circle cx="128" cy="166.4" r="76.8" fill="hsl(345, 85.7%, 86.3%)"/><circle cx="128" cy="179.2" r="51.2" fill="hsl(261.9, 100%, 87.3%)"/><circle cx="128" cy="192" r="25.6" fill="hsl(345, 100%, 25.1%)"/></svg></div></div>'
|
|
20
|
+
'<div xmlns="http://www.w3.org/1999/xhtml" class="" style="background: white; border-radius: 128px; display: inline-block; height: 256px; margin: 0px; overflow: hidden; padding: 0px; width: 256px;"><div class="" style="background: rgb(255, 167, 26); border-radius: 128px; display: inline-block; height: 256px; margin: 0px; overflow: hidden; padding: 0px; width: 256px;"><svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="256" height="256"><circle cx="128" cy="140.8" r="128" fill="hsl(212, 66%, 55%)"/><circle cx="128" cy="153.6" r="102.4" fill="hsl(10, 91%, 58%)"/><circle cx="128" cy="166.4" r="76.8" fill="hsl(345, 86%, 86%)"/><circle cx="128" cy="179.2" r="51.2" fill="hsl(262, 100%, 87%)"/><circle cx="128" cy="192" r="25.6" fill="hsl(345, 100%, 25%)"/></svg></div></div>'
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('allows overrides', (): void => {
|
|
25
|
+
expect(
|
|
26
|
+
xmlserializer.serializeToString(
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
|
|
28
|
+
beachballIcon(new Uint8Array(32), { isAlternative: false, size: 100 }, 'testClass', { display: 'block' }) as any
|
|
29
|
+
)
|
|
30
|
+
).toEqual(
|
|
31
|
+
// with original color ...
|
|
32
|
+
// '<div xmlns="http://www.w3.org/1999/xhtml" class="testClass" style="background: white; border-radius: 50px; display: block; height: 100px; margin: 0px; overflow: hidden; padding: 0px; width: 100px;"><div class="" style="background: rgb(20, 20, 20); border-radius: 50px; display: inline-block; height: 100px; margin: 0px; overflow: hidden; padding: 0px; width: 100px;"><svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="100" height="100"><circle cx="50" cy="55" r="50" fill="hsl(212.10000000000002, 65.6%, 55.5%)"/><circle cx="50" cy="60" r="40" fill="hsl(9.800000000000011, 90.7%, 57.6%)"/><circle cx="50" cy="65" r="30" fill="hsl(345, 85.7%, 86.3%)"/><circle cx="50" cy="70" r="20" fill="hsl(261.9, 100%, 87.3%)"/><circle cx="50" cy="75" r="10" fill="hsl(345, 100%, 25.1%)"/></svg></div></div>'
|
|
33
|
+
'<div xmlns="http://www.w3.org/1999/xhtml" class="testClass" style="background: white; border-radius: 50px; display: block; height: 100px; margin: 0px; overflow: hidden; padding: 0px; width: 100px;"><div class="" style="background: rgb(255, 167, 26); border-radius: 50px; display: inline-block; height: 100px; margin: 0px; overflow: hidden; padding: 0px; width: 100px;"><svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="100" height="100"><circle cx="50" cy="55" r="50" fill="hsl(212, 66%, 55%)"/><circle cx="50" cy="60" r="40" fill="hsl(10, 91%, 58%)"/><circle cx="50" cy="65" r="30" fill="hsl(345, 86%, 86%)"/><circle cx="50" cy="70" r="20" fill="hsl(262, 100%, 87%)"/><circle cx="50" cy="75" r="10" fill="hsl(345, 100%, 25%)"/></svg></div></div>'
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
import type { Options } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { circle } from './shape/circle.js';
|
|
9
|
+
import { element } from './svg/element.js';
|
|
10
|
+
import { colors } from './colors.js';
|
|
11
|
+
import { container as newContainer } from './container.js';
|
|
12
|
+
import { SHAPE_COUNT } from './defaults.js';
|
|
13
|
+
import { seeder as newSeeder } from './seeder.js';
|
|
14
|
+
|
|
15
|
+
export function beachballIcon (seed: string | Uint8Array, { size = 256 }: Options, className = '', style?: Record<string, string>): HTMLElement {
|
|
16
|
+
const seeder = newSeeder(seed);
|
|
17
|
+
const colorGen = colors(seeder);
|
|
18
|
+
const outer = newContainer(size, 'white', className, style);
|
|
19
|
+
const container = newContainer(size, colorGen());
|
|
20
|
+
const svg = element(size);
|
|
21
|
+
|
|
22
|
+
outer.appendChild(container);
|
|
23
|
+
container.appendChild(svg);
|
|
24
|
+
|
|
25
|
+
for (let count = 0; count < SHAPE_COUNT; count++) {
|
|
26
|
+
const fill = colorGen();
|
|
27
|
+
const shape = circle(seeder, fill, size, count);
|
|
28
|
+
|
|
29
|
+
svg.appendChild(shape);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return outer;
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import type { Seeder } from './types.js';
|
|
7
|
+
|
|
8
|
+
import { seeder as newSeeder } from './seeder.js';
|
|
9
|
+
|
|
10
|
+
describe('seeder', (): void => {
|
|
11
|
+
let seeder: Seeder;
|
|
12
|
+
|
|
13
|
+
beforeEach((): void => {
|
|
14
|
+
seeder = newSeeder(new Uint8Array([1, 2, 3, 4]));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('generates numbers using 2 spaces', (): void => {
|
|
18
|
+
expect(
|
|
19
|
+
seeder()
|
|
20
|
+
).toEqual(0.0156402587890625);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('generates numbers using 2 spaces (incremented)', (): void => {
|
|
24
|
+
seeder();
|
|
25
|
+
|
|
26
|
+
expect(
|
|
27
|
+
seeder()
|
|
28
|
+
).toEqual(0.0078582763671875);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Seeder } from './types.js';
|
|
5
|
+
|
|
6
|
+
import { isU8a, stringToU8a } from '@pezkuwi/util';
|
|
7
|
+
|
|
8
|
+
const DIVISOR = 256 * 256;
|
|
9
|
+
|
|
10
|
+
export function seeder (_seed: string | Uint8Array = new Uint8Array(32)): Seeder {
|
|
11
|
+
const seed: Uint8Array = isU8a(_seed)
|
|
12
|
+
? _seed
|
|
13
|
+
: stringToU8a(_seed);
|
|
14
|
+
|
|
15
|
+
let index = (seed[Math.floor(seed.length / 2)] % seed.length) - 1;
|
|
16
|
+
|
|
17
|
+
const next = (): number => {
|
|
18
|
+
index += 1;
|
|
19
|
+
|
|
20
|
+
if (index === seed.length) {
|
|
21
|
+
index = 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return seed[index];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (): number => {
|
|
28
|
+
return ((next() * 256) + next()) / DIVISOR;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import xmlserializer from 'xmlserializer';
|
|
7
|
+
|
|
8
|
+
import { seeder } from '../seeder.js';
|
|
9
|
+
import { circle } from './circle.js';
|
|
10
|
+
|
|
11
|
+
describe('circle', (): void => {
|
|
12
|
+
it('creates a circle shape', (): void => {
|
|
13
|
+
expect(
|
|
14
|
+
xmlserializer.serializeToString(
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
|
|
16
|
+
circle(seeder(), 'blue', 50, 2) as any
|
|
17
|
+
)
|
|
18
|
+
).toEqual('<circle xmlns="http://www.w3.org/2000/svg" cx="25" cy="32.5" r="15" fill="blue"/>');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
import type { Seeder } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { SHAPE_COUNT } from '../defaults.js';
|
|
9
|
+
import { circle as newCircle } from '../svg/circle.js';
|
|
10
|
+
|
|
11
|
+
export function circle (seeder: Seeder, fill: string, diameter: number, count: number): Element {
|
|
12
|
+
const center = diameter / 2;
|
|
13
|
+
const angle = seeder() * 360;
|
|
14
|
+
const radius = (((SHAPE_COUNT - count) / SHAPE_COUNT) * (diameter / 2)) + ((diameter / 8) * seeder());
|
|
15
|
+
const offset = (diameter / 4) * (seeder() + ((count + 1) / SHAPE_COUNT));
|
|
16
|
+
const cx = (offset * Math.sin(angle)) + center;
|
|
17
|
+
const cy = (offset * Math.cos(angle)) + center;
|
|
18
|
+
const svg = newCircle(radius, cx, cy);
|
|
19
|
+
|
|
20
|
+
svg.setAttributeNS('', 'fill', fill);
|
|
21
|
+
|
|
22
|
+
return svg;
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
import type { Seeder } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { SHAPE_COUNT } from '../defaults.js';
|
|
9
|
+
import { rect as newRect } from '../svg/rect.js';
|
|
10
|
+
|
|
11
|
+
export function square (seeder: Seeder, fill: string, diameter: number, count: number): Element {
|
|
12
|
+
const center = diameter / 2;
|
|
13
|
+
const svg = newRect(diameter);
|
|
14
|
+
const firstRot = seeder();
|
|
15
|
+
const angle = Math.PI * 2 * firstRot;
|
|
16
|
+
const scale = count / SHAPE_COUNT;
|
|
17
|
+
const velocity = ((diameter / SHAPE_COUNT) * seeder()) + (scale * diameter);
|
|
18
|
+
const tx = (Math.cos(angle) * velocity).toFixed(3);
|
|
19
|
+
const ty = (Math.sin(angle) * velocity).toFixed(3);
|
|
20
|
+
const rot = ((firstRot * 360) + (seeder() * 180)).toFixed(1);
|
|
21
|
+
|
|
22
|
+
svg.setAttributeNS('', 'transform', `translate(${tx} ${ty}) rotate(${rot} ${center} ${center})`);
|
|
23
|
+
svg.setAttributeNS('', 'fill', fill);
|
|
24
|
+
|
|
25
|
+
return svg;
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import xs from 'xmlserializer';
|
|
7
|
+
|
|
8
|
+
import { circle } from './circle.js';
|
|
9
|
+
|
|
10
|
+
describe('circle', (): void => {
|
|
11
|
+
it('creates a basic SVG circle element', (): void => {
|
|
12
|
+
expect(
|
|
13
|
+
xs.serializeToString(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
|
|
15
|
+
circle(123, 12, 34) as any
|
|
16
|
+
)
|
|
17
|
+
).toEqual('<circle xmlns="http://www.w3.org/2000/svg" cx="12" cy="34" r="123"/>');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { svg } from './svg.js';
|
|
5
|
+
|
|
6
|
+
export function circle (r: number, cx: number, cy: number): Element {
|
|
7
|
+
const elem = svg('circle');
|
|
8
|
+
|
|
9
|
+
elem.setAttributeNS('', 'cx', `${cx}`);
|
|
10
|
+
elem.setAttributeNS('', 'cy', `${cy}`);
|
|
11
|
+
elem.setAttributeNS('', 'r', `${r}`);
|
|
12
|
+
|
|
13
|
+
return elem;
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import xs from 'xmlserializer';
|
|
7
|
+
|
|
8
|
+
import { element } from './element.js';
|
|
9
|
+
|
|
10
|
+
describe('element', (): void => {
|
|
11
|
+
it('creates a basic SVG element', (): void => {
|
|
12
|
+
expect(
|
|
13
|
+
xs.serializeToString(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
|
|
15
|
+
element(123) as any
|
|
16
|
+
)
|
|
17
|
+
).toEqual('<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="123" height="123"/>');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
import { svg } from './svg.js';
|
|
7
|
+
|
|
8
|
+
export function element (size: number, type = 'svg', x = 0, y = 0): Element {
|
|
9
|
+
const elem = svg(type);
|
|
10
|
+
|
|
11
|
+
elem.setAttributeNS('', 'x', `${x}`);
|
|
12
|
+
elem.setAttributeNS('', 'y', `${y}`);
|
|
13
|
+
elem.setAttributeNS('', 'width', `${size}`);
|
|
14
|
+
elem.setAttributeNS('', 'height', `${size}`);
|
|
15
|
+
|
|
16
|
+
return elem;
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import xs from 'xmlserializer';
|
|
7
|
+
|
|
8
|
+
import { rect } from './rect.js';
|
|
9
|
+
|
|
10
|
+
describe('rect', (): void => {
|
|
11
|
+
it('creates a basic SVG rect element', (): void => {
|
|
12
|
+
expect(
|
|
13
|
+
xs.serializeToString(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
|
|
15
|
+
rect(123) as any
|
|
16
|
+
)
|
|
17
|
+
).toEqual('<rect xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="123" height="123" rx="7.6875" ry="7.6875"/>');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { element } from './element.js';
|
|
5
|
+
|
|
6
|
+
export function rect (size: number): Element {
|
|
7
|
+
const elem = element(size, 'rect');
|
|
8
|
+
|
|
9
|
+
elem.setAttributeNS('', 'rx', `${size / 16}`);
|
|
10
|
+
elem.setAttributeNS('', 'ry', `${size / 16}`);
|
|
11
|
+
|
|
12
|
+
return elem;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import xs from 'xmlserializer';
|
|
7
|
+
|
|
8
|
+
import { svg } from './svg.js';
|
|
9
|
+
|
|
10
|
+
describe('svg', (): void => {
|
|
11
|
+
it('creates a basic SVG element', (): void => {
|
|
12
|
+
expect(
|
|
13
|
+
xs.serializeToString(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
|
|
15
|
+
svg('rect') as any
|
|
16
|
+
)
|
|
17
|
+
).toEqual('<rect xmlns="http://www.w3.org/2000/svg"/>');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Copyright 2016 Dan Finlay
|
|
5
|
+
|
|
6
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
7
|
+
|
|
8
|
+
export function svg (type: string): Element {
|
|
9
|
+
return document.createElementNS(SVG_NS, type);
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2018-2025 @pezkuwi/ui-shared authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import { polkadotIcon } from './polkadot.js';
|
|
7
|
+
|
|
8
|
+
describe('polkadotIcon', (): void => {
|
|
9
|
+
it('generates the correct points from known', (): void => {
|
|
10
|
+
expect(
|
|
11
|
+
polkadotIcon('5Dqvi1p4C7EhPPFKCixpF3QiaJEaDwWrR9gfWR5eUsfC39TX', { isAlternative: false })
|
|
12
|
+
).toEqual([
|
|
13
|
+
{ cx: 32, cy: 32, fill: '#eee', r: 32 },
|
|
14
|
+
{ cx: 32, cy: 8, fill: 'hsl(196, 65%, 53%)', r: 5 },
|
|
15
|
+
{ cx: 32, cy: 20, fill: 'hsl(320, 65%, 53%)', r: 5 },
|
|
16
|
+
{ cx: 21.607695154586736, cy: 14, fill: 'transparent', r: 5 },
|
|
17
|
+
{ cx: 11.215390309173472, cy: 20, fill: 'hsl(112, 65%, 15%)', r: 5 },
|
|
18
|
+
{ cx: 21.607695154586736, cy: 26, fill: 'hsl(22, 65%, 15%)', r: 5 },
|
|
19
|
+
{ cx: 11.215390309173472, cy: 32, fill: 'hsl(213, 65%, 15%)', r: 5 },
|
|
20
|
+
{ cx: 11.215390309173472, cy: 44, fill: 'hsl(163, 65%, 53%)', r: 5 },
|
|
21
|
+
{ cx: 21.607695154586736, cy: 38, fill: 'hsl(213, 65%, 53%)', r: 5 },
|
|
22
|
+
{ cx: 21.607695154586736, cy: 50, fill: 'hsl(185, 65%, 75%)', r: 5 },
|
|
23
|
+
{ cx: 32, cy: 56, fill: 'hsl(163, 65%, 53%)', r: 5 },
|
|
24
|
+
{ cx: 32, cy: 44, fill: 'hsl(213, 65%, 53%)', r: 5 },
|
|
25
|
+
{ cx: 42.392304845413264, cy: 50, fill: 'hsl(213, 65%, 15%)', r: 5 },
|
|
26
|
+
{ cx: 52.78460969082653, cy: 44, fill: 'hsl(112, 65%, 15%)', r: 5 },
|
|
27
|
+
{ cx: 42.392304845413264, cy: 38, fill: 'hsl(22, 65%, 15%)', r: 5 },
|
|
28
|
+
{ cx: 52.78460969082653, cy: 32, fill: 'transparent', r: 5 },
|
|
29
|
+
{ cx: 52.78460969082653, cy: 20, fill: 'hsl(196, 65%, 53%)', r: 5 },
|
|
30
|
+
{ cx: 42.392304845413264, cy: 26, fill: 'hsl(320, 65%, 53%)', r: 5 },
|
|
31
|
+
{ cx: 42.392304845413264, cy: 14, fill: 'hsl(11, 65%, 35%)', r: 5 },
|
|
32
|
+
{ cx: 32, cy: 32, fill: 'hsl(309, 65%, 53%)', r: 5 }
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
});
|