@talismn/orb 0.3.4 → 0.3.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.
@@ -1,40 +0,0 @@
1
- import { FC } from "react"
2
-
3
- import { TalismanOrbProps } from "./types"
4
- import { useTalismanOrb } from "./useTalismanOrb"
5
-
6
- export const TalismanOrbRectangle: FC<TalismanOrbProps> = ({ width, height, seed, className }) => {
7
- const { id, bgColor1, bgColor2, transform, glowColor, cx, cy } = useTalismanOrb(seed)
8
-
9
- return (
10
- <svg
11
- width={width}
12
- height={height}
13
- viewBox={`0 0 64 64`}
14
- preserveAspectRatio="none"
15
- className={className}
16
- version="1.1"
17
- xmlns="http://www.w3.org/2000/svg"
18
- >
19
- <defs>
20
- <linearGradient id={`${id}-bg`}>
21
- <stop offset="20%" stopColor={bgColor1} />
22
- <stop offset="100%" stopColor={bgColor2} />
23
- </linearGradient>
24
- <radialGradient id={`${id}-circle`}>
25
- <stop offset="10%" stopColor={glowColor} />
26
- <stop offset="100%" stopColor="transparent" />
27
- </radialGradient>
28
- <clipPath id={`${id}-clip`}>
29
- <circle cx="32" cy="32" r="48" />
30
- </clipPath>
31
- </defs>
32
- <g clipPath={`url(#${id}-clip)`}>
33
- <g transform={transform}>
34
- <rect fill={`url(#${id}-bg)`} x={-16} y={-16} width={96} height={96} />
35
- <circle fill={`url(#${id}-circle)`} cx={cx} cy={cy} r={45} opacity={0.7} />
36
- </g>
37
- </g>
38
- </svg>
39
- )
40
- }
@@ -1,4 +0,0 @@
1
- export * from "./types"
2
- export * from "./useTalismanOrb"
3
- export * from "./TalismanOrb"
4
- export * from "./TalismanOrbRectangle"
@@ -1 +0,0 @@
1
- export type TalismanOrbProps = { seed: string; width?: number; height?: number; className?: string }
@@ -1,70 +0,0 @@
1
- import { getAccountPlatformFromAddress, normalizeAddress } from "@talismn/crypto"
2
- import md5 from "blueimp-md5"
3
- import Color from "color"
4
- import { useId, useMemo } from "react"
5
-
6
- const djb2 = (str: string) => {
7
- let hash = 5381
8
- for (let i = 0; i < str.length; i++) hash = (hash << 5) + hash + str.charCodeAt(i)
9
- return hash
10
- }
11
-
12
- const valueFromHash = (hash: string, max: number) => {
13
- return (max + djb2(hash)) % max
14
- }
15
-
16
- const colorFromHash = (hash: string) => {
17
- const hue = valueFromHash(hash, 360)
18
- return Color.hsv(hue, 100, 100)
19
- }
20
-
21
- const rotateText = (text: string, nbChars = 0) => text.slice(nbChars) + text.slice(0, nbChars)
22
-
23
- export const useTalismanOrb = (seed: string) => {
24
- const id = useId()
25
-
26
- return useMemo(() => {
27
- try {
28
- // those break if seed is empty or an invalid address
29
-
30
- // eslint-disable-next-line no-var
31
- var platform = getAccountPlatformFromAddress(seed)
32
-
33
- // seed may be specific to a ss58 prefix, get the base address
34
- // eslint-disable-next-line no-var
35
- var address = normalizeAddress(seed)
36
- } catch (err) {
37
- platform = "polkadot"
38
- address = seed
39
- }
40
-
41
- // derive 3 hashs from the seed, used to generate the 3 colors
42
- const hash1 = md5(address)
43
- const hash2 = rotateText(hash1, 1)
44
- const hash3 = rotateText(hash1, 2)
45
-
46
- // the 2 darkest ones will be used as gradient BG
47
- // the lightest one will be used as gradient circle, to mimic a 3D lighting effect
48
- const colors = [colorFromHash(hash1), colorFromHash(hash2), colorFromHash(hash3)].sort(
49
- (c1, c2) => c1.lightness() - c2.lightness(),
50
- )
51
-
52
- // random location in top left corner, avoid beeing to close from the center
53
- const dotX = 10 + valueFromHash(hash1, 10)
54
- const dotY = 10 + valueFromHash(hash2, 10)
55
-
56
- // global rotation
57
- const rotation = valueFromHash(hash1, 360)
58
-
59
- return {
60
- id, //multiple avatars should cohabit on the same page
61
- bgColor1: colors[0].hex(),
62
- bgColor2: colors[1].hex(),
63
- glowColor: colors[2].hex(),
64
- transform: `rotate(${rotation} 32 32)`,
65
- cx: dotX,
66
- cy: dotY,
67
- platform,
68
- }
69
- }, [id, seed])
70
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./components"
2
- export * from "./util"
@@ -1,14 +0,0 @@
1
- import ReactDOMServer from "react-dom/server"
2
-
3
- import { TalismanOrb } from "../components"
4
-
5
- /**
6
- * Returns a base64 encoded data url for the Talisman Orb svg
7
- */
8
- export const getTalismanOrbDataUrl = (address: string): `data:image/svg+xml;base64,${string}` => {
9
- // render the TalismanOrb component and output the SVG as text
10
- const svg = ReactDOMServer.renderToStaticMarkup(<TalismanOrb seed={address} />)
11
-
12
- // convert to data url
13
- return `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`
14
- }
package/src/util/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./getTalismanOrbDataUrl"
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "@talismn/tsconfig/es6-react.json",
3
- "include": ["src"],
4
- "exclude": ["**/node_modules", "**/.*/", "**/*.spec.ts", "**/*.test.ts"]
5
- }