@xylabs/react-identicon 7.1.16 → 7.1.20
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 +6 -46
- package/package.json +25 -16
- package/src/components/Identicon.tsx +0 -105
- package/src/components/index.ts +0 -1
- package/src/index.ts +0 -1
package/README.md
CHANGED
|
@@ -1,67 +1,27 @@
|
|
|
1
|
-
[![logo][]](https://xylabs.com)
|
|
2
|
-
|
|
3
1
|
# @xylabs/react-identicon
|
|
4
2
|
|
|
5
|
-
[![npm-badge]
|
|
6
|
-
[![npm-downloads-badge][]][npm-link]
|
|
7
|
-
[![jsdelivr-badge][]][jsdelivr-link]
|
|
8
|
-
[![npm-license-badge][]](LICENSE)
|
|
9
|
-
|
|
10
|
-
> XY Labs generalized React library
|
|
11
|
-
|
|
12
|
-
## Table of Contents
|
|
3
|
+
[![npm][npm-badge]][npm-link]
|
|
13
4
|
|
|
14
|
-
|
|
15
|
-
- [Install](#install)
|
|
16
|
-
- [Maintainers](#maintainers)
|
|
17
|
-
- [License](#license)
|
|
18
|
-
- [Credits](#credits)
|
|
19
|
-
|
|
20
|
-
## Description
|
|
21
|
-
|
|
22
|
-
Common React code that is used throughout XYO projects that use React.
|
|
5
|
+
> Common React library for all XY Labs projects that use React
|
|
23
6
|
|
|
24
7
|
## Install
|
|
25
8
|
|
|
26
|
-
Using npm:
|
|
27
|
-
|
|
28
9
|
```sh
|
|
29
|
-
npm
|
|
10
|
+
npm install {{name}}
|
|
30
11
|
```
|
|
31
12
|
|
|
32
|
-
|
|
13
|
+
or
|
|
33
14
|
|
|
34
15
|
```sh
|
|
35
|
-
yarn add
|
|
16
|
+
yarn add {{name}}
|
|
36
17
|
```
|
|
37
18
|
|
|
38
|
-
## Documentation
|
|
39
|
-
[Developer Reference](https://xylabs.github.io/sdk-react)
|
|
40
|
-
|
|
41
|
-
[Storybook](https://xylabs.github.io/sdk-react/storybook)
|
|
42
|
-
|
|
43
|
-
## Maintainers
|
|
44
|
-
|
|
45
|
-
- [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
|
|
46
|
-
- [Matt Jones](https://github.com/jonesmac)
|
|
47
|
-
- [Joel Carter](https://github.com/JoelBCarter)
|
|
48
|
-
- [Jordan Trouw](https://github.com/jordantrouw)
|
|
49
19
|
|
|
50
20
|
## License
|
|
51
21
|
|
|
52
|
-
See the [LICENSE](LICENSE) file for license
|
|
22
|
+
See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
|
|
53
23
|
|
|
54
|
-
## Credits
|
|
55
24
|
|
|
56
|
-
[Made with 🔥and ❄️ by XY Labs](https://xylabs.com)
|
|
57
|
-
|
|
58
|
-
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
|
|
59
25
|
|
|
60
26
|
[npm-badge]: https://img.shields.io/npm/v/@xylabs/react-identicon.svg
|
|
61
27
|
[npm-link]: https://www.npmjs.com/package/@xylabs/react-identicon
|
|
62
|
-
|
|
63
|
-
[npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/react-identicon
|
|
64
|
-
[npm-license-badge]: https://img.shields.io/npm/l/@xylabs/react-identicon
|
|
65
|
-
|
|
66
|
-
[jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/react-identicon/badge
|
|
67
|
-
[jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/react-identicon
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/react-identicon",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.20",
|
|
4
4
|
"description": "Common React library for all XY Labs projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"utility",
|
|
@@ -27,41 +27,50 @@
|
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"types": "./dist/browser/index.d.ts",
|
|
30
|
+
"import": "./dist/browser/index.mjs",
|
|
30
31
|
"default": "./dist/browser/index.mjs"
|
|
31
32
|
},
|
|
32
33
|
"./package.json": "./package.json"
|
|
33
34
|
},
|
|
34
|
-
"module": "./dist/browser/index.mjs",
|
|
35
35
|
"types": "dist/browser/index.d.ts",
|
|
36
36
|
"files": [
|
|
37
37
|
"dist",
|
|
38
|
-
"
|
|
38
|
+
"README.md"
|
|
39
39
|
],
|
|
40
40
|
"workspaces": [
|
|
41
41
|
"packages/*"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"
|
|
45
|
-
"
|
|
44
|
+
"md5": "~2.3.0",
|
|
45
|
+
"@xylabs/react-flexbox": "~7.1.20"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@
|
|
48
|
+
"@opentelemetry/api": "^1",
|
|
49
49
|
"@types/md5": "~2.3.6",
|
|
50
|
-
"@types/react": "^19.2.
|
|
51
|
-
"@xylabs/ts-scripts-
|
|
52
|
-
"@xylabs/
|
|
53
|
-
"@xylabs/tsconfig
|
|
54
|
-
"@xylabs/tsconfig-
|
|
50
|
+
"@types/react": "^19.2.14",
|
|
51
|
+
"@xylabs/ts-scripts-common": "~7.8.5",
|
|
52
|
+
"@xylabs/ts-scripts-pnpm": "~7.8.5",
|
|
53
|
+
"@xylabs/tsconfig": "~7.8",
|
|
54
|
+
"@xylabs/tsconfig-dom": "~7.8.5",
|
|
55
|
+
"@xylabs/tsconfig-react": "~7.8.5",
|
|
56
|
+
"axios": "^1",
|
|
57
|
+
"pako": "~2.1.0",
|
|
55
58
|
"react": "^19.2.4",
|
|
56
|
-
"react-dom": "^19.
|
|
57
|
-
"typescript": "^5.9.3"
|
|
59
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
60
|
+
"typescript": "^5.9.3",
|
|
61
|
+
"zod": "^4",
|
|
62
|
+
"@xylabs/react-async-effect": "~7.1.20",
|
|
63
|
+
"@xylabs/react-promise": "~7.1.20"
|
|
58
64
|
},
|
|
59
65
|
"peerDependencies": {
|
|
60
|
-
"@
|
|
66
|
+
"@opentelemetry/api": "^1",
|
|
67
|
+
"axios": "^1",
|
|
61
68
|
"react": "^19",
|
|
62
|
-
"react-dom": "^19"
|
|
69
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
70
|
+
"zod": "^4",
|
|
71
|
+
"@xylabs/react-async-effect": "~7.1.20"
|
|
63
72
|
},
|
|
64
73
|
"publishConfig": {
|
|
65
74
|
"access": "public"
|
|
66
75
|
}
|
|
67
|
-
}
|
|
76
|
+
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type { FlexBoxProps } from '@xylabs/react-flexbox'
|
|
2
|
-
import { FlexRow } from '@xylabs/react-flexbox'
|
|
3
|
-
import md5 from 'md5'
|
|
4
|
-
import React, { useEffect, useRef } from 'react'
|
|
5
|
-
|
|
6
|
-
const range = (n: number, in_min: number, in_max: number, out_min: number, out_max: number) => {
|
|
7
|
-
return ((n - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface IdenticonProps extends FlexBoxProps {
|
|
11
|
-
bg?: string
|
|
12
|
-
className?: string
|
|
13
|
-
count?: number
|
|
14
|
-
fg?: string
|
|
15
|
-
iconPadding?: number
|
|
16
|
-
palette?: string[]
|
|
17
|
-
size?: number
|
|
18
|
-
value?: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const updateCanvas = (canvas: React.RefObject<HTMLCanvasElement | null>, props: IdenticonProps) => {
|
|
22
|
-
const {
|
|
23
|
-
value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0,
|
|
24
|
-
} = props
|
|
25
|
-
let { fg } = props
|
|
26
|
-
const hash = md5(value)
|
|
27
|
-
const block = Math.floor(size / count)
|
|
28
|
-
const hashColor = hash.slice(0, 6)
|
|
29
|
-
|
|
30
|
-
const current = canvas?.current
|
|
31
|
-
|
|
32
|
-
if (!current) {
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (palette && palette.length > 0) {
|
|
37
|
-
const index = Math.floor(range(Number.parseInt(hash.slice(-3), 16), 0, 4095, 0, palette.length))
|
|
38
|
-
fg = palette[index]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
current.width = block * count + iconPadding
|
|
42
|
-
current.height = block * count + iconPadding
|
|
43
|
-
const arr = [...hash].map((el) => {
|
|
44
|
-
const parsedEl = Number.parseInt(el, 16)
|
|
45
|
-
return parsedEl < 8 ? 0 : 1
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const map = []
|
|
49
|
-
|
|
50
|
-
map[0] = map[4] = arr.slice(0, 5)
|
|
51
|
-
map[1] = map[3] = arr.slice(5, 10)
|
|
52
|
-
map[2] = arr.slice(10, 15)
|
|
53
|
-
|
|
54
|
-
const ctx = current.getContext('2d')
|
|
55
|
-
if (ctx) {
|
|
56
|
-
ctx.imageSmoothingEnabled = false
|
|
57
|
-
ctx.clearRect(0, 0, current.width, current.height)
|
|
58
|
-
|
|
59
|
-
for (const [i, row] of map.entries()) {
|
|
60
|
-
for (const [j, el] of row.entries()) {
|
|
61
|
-
if (el) {
|
|
62
|
-
ctx.fillStyle = fg ?? '#' + hashColor
|
|
63
|
-
ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding)
|
|
64
|
-
} else {
|
|
65
|
-
ctx.fillStyle = bg
|
|
66
|
-
ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const Identicon: React.FC<IdenticonProps> = ({
|
|
74
|
-
size = 400,
|
|
75
|
-
className = 'identicon',
|
|
76
|
-
bg,
|
|
77
|
-
count,
|
|
78
|
-
fg,
|
|
79
|
-
iconPadding,
|
|
80
|
-
palette,
|
|
81
|
-
value,
|
|
82
|
-
...props
|
|
83
|
-
}) => {
|
|
84
|
-
const canvasRef = useRef<HTMLCanvasElement>(null)
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
updateCanvas(canvasRef, {
|
|
88
|
-
bg, className, count, fg, iconPadding, palette, size, value,
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<FlexRow {...props}>
|
|
94
|
-
{value
|
|
95
|
-
? (
|
|
96
|
-
<canvas
|
|
97
|
-
className={className}
|
|
98
|
-
ref={canvasRef}
|
|
99
|
-
style={{ height: size, width: size }}
|
|
100
|
-
/>
|
|
101
|
-
)
|
|
102
|
-
: null}
|
|
103
|
-
</FlexRow>
|
|
104
|
-
)
|
|
105
|
-
}
|
package/src/components/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Identicon.tsx'
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './components/index.ts'
|