@talismn/orb 0.3.5 → 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.
- package/dist/index.d.mts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +261 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +221 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +24 -15
- package/CHANGELOG.md +0 -69
- package/dist/declarations/src/components/TalismanOrb.d.ts +0 -3
- package/dist/declarations/src/components/TalismanOrbLogo.d.ts +0 -5
- package/dist/declarations/src/components/TalismanOrbRectangle.d.ts +0 -3
- package/dist/declarations/src/components/index.d.ts +0 -4
- package/dist/declarations/src/components/types.d.ts +0 -6
- package/dist/declarations/src/components/useTalismanOrb.d.ts +0 -10
- package/dist/declarations/src/index.d.ts +0 -2
- package/dist/declarations/src/util/getTalismanOrbDataUrl.d.ts +0 -4
- package/dist/declarations/src/util/index.d.ts +0 -1
- package/dist/talismn-orb.cjs.d.ts +0 -1
- package/dist/talismn-orb.cjs.dev.js +0 -291
- package/dist/talismn-orb.cjs.js +0 -7
- package/dist/talismn-orb.cjs.prod.js +0 -291
- package/dist/talismn-orb.esm.js +0 -280
- package/src/components/TalismanOrb.tsx +0 -46
- package/src/components/TalismanOrbLogo.tsx +0 -60
- package/src/components/TalismanOrbRectangle.tsx +0 -40
- package/src/components/index.ts +0 -4
- package/src/components/types.ts +0 -1
- package/src/components/useTalismanOrb.ts +0 -70
- package/src/index.ts +0 -2
- package/src/util/getTalismanOrbDataUrl.tsx +0 -14
- package/src/util/index.ts +0 -1
- package/tsconfig.json +0 -5
|
@@ -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
|
-
}
|
package/src/components/index.ts
DELETED
package/src/components/types.ts
DELETED
|
@@ -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,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"
|