@xylabs/react-identicon 4.0.3 → 4.0.4
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/browser/components/Identicon.d.ts +14 -0
- package/dist/browser/components/Identicon.d.ts.map +1 -0
- package/dist/browser/components/index.d.ts +2 -0
- package/dist/browser/components/index.d.ts.map +1 -0
- package/dist/browser/index.d.ts +2 -16
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +33 -33
- package/src/components/Identicon.tsx +13 -3
- package/xy.config.ts +1 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FlexBoxProps } from '@xylabs/react-flexbox';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface IdenticonProps extends FlexBoxProps {
|
|
4
|
+
bg?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
count?: number;
|
|
7
|
+
fg?: string;
|
|
8
|
+
iconPadding?: number;
|
|
9
|
+
palette?: string[];
|
|
10
|
+
size?: number;
|
|
11
|
+
value?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const Identicon: React.FC<IdenticonProps>;
|
|
14
|
+
//# sourceMappingURL=Identicon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAIzD,OAAO,KAA4B,MAAM,OAAO,CAAA;AAMhD,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAsDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAgC9C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface IdenticonProps extends FlexBoxProps {
|
|
5
|
-
bg?: string;
|
|
6
|
-
className?: string;
|
|
7
|
-
count?: number;
|
|
8
|
-
fg?: string;
|
|
9
|
-
iconPadding?: number;
|
|
10
|
-
palette?: string[];
|
|
11
|
-
size?: number;
|
|
12
|
-
value?: string;
|
|
13
|
-
}
|
|
14
|
-
declare const Identicon: React.FC<IdenticonProps>;
|
|
15
|
-
|
|
16
|
-
export { Identicon, type IdenticonProps };
|
|
1
|
+
export * from './components/index.ts';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Identicon.tsx"],"sourcesContent":["import type { FlexBoxProps } from '@xylabs/react-flexbox'\nimport { FlexRow } from '@xylabs/react-flexbox'\n// eslint-disable-next-line depend/ban-dependencies\nimport md5 from 'md5'\nimport React, { useEffect, useRef } from 'react'\n\nconst range = (n: number, in_min: number, in_max: number, out_min: number, out_max: number) => {\n return ((n - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\n}\n\nexport interface IdenticonProps extends FlexBoxProps {\n bg?: string\n className?: string\n count?: number\n fg?: string\n iconPadding?: number\n palette?: string[]\n size?: number\n value?: string\n}\n\nconst updateCanvas = (canvas: React.RefObject<HTMLCanvasElement>, props: IdenticonProps) => {\n const {
|
|
1
|
+
{"version":3,"sources":["../../src/components/Identicon.tsx"],"sourcesContent":["import type { FlexBoxProps } from '@xylabs/react-flexbox'\nimport { FlexRow } from '@xylabs/react-flexbox'\n// eslint-disable-next-line depend/ban-dependencies\nimport md5 from 'md5'\nimport React, { useEffect, useRef } from 'react'\n\nconst range = (n: number, in_min: number, in_max: number, out_min: number, out_max: number) => {\n return ((n - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\n}\n\nexport interface IdenticonProps extends FlexBoxProps {\n bg?: string\n className?: string\n count?: number\n fg?: string\n iconPadding?: number\n palette?: string[]\n size?: number\n value?: string\n}\n\nconst updateCanvas = (canvas: React.RefObject<HTMLCanvasElement>, props: IdenticonProps) => {\n const {\n value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0,\n } = props\n let { fg } = props\n const hash = md5(value)\n const block = Math.floor(size / count)\n const hashColor = hash.slice(0, 6)\n\n const current = canvas.current\n\n if (!current) {\n return\n }\n\n if (palette && palette.length > 0) {\n const index = Math.floor(range(Number.parseInt(hash.slice(-3), 16), 0, 4095, 0, palette.length))\n fg = palette[index]\n }\n\n current.width = block * count + iconPadding\n current.height = block * count + iconPadding\n const arr = [...hash].map((el) => {\n const parsedEl = Number.parseInt(el, 16)\n return parsedEl < 8 ? 0 : 1\n })\n\n const map = []\n\n map[0] = map[4] = arr.slice(0, 5)\n map[1] = map[3] = arr.slice(5, 10)\n map[2] = arr.slice(10, 15)\n\n const ctx = current.getContext('2d')\n if (ctx) {\n ctx.imageSmoothingEnabled = false\n ctx.clearRect(0, 0, current.width, current.height)\n\n for (const [i, row] of map.entries()) {\n for (const [j, el] of row.entries()) {\n if (el) {\n ctx.fillStyle = fg ?? '#' + hashColor\n ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding)\n } else {\n ctx.fillStyle = bg\n ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding)\n }\n }\n }\n }\n}\n\nexport const Identicon: React.FC<IdenticonProps> = ({\n size = 400,\n className = 'identicon',\n bg,\n count,\n fg,\n iconPadding,\n palette,\n value,\n ...props\n}) => {\n const canvas = useRef<HTMLCanvasElement>(null)\n\n useEffect(() => {\n updateCanvas(canvas, {\n bg, className, count, fg, iconPadding, palette, size, value,\n })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? (\n <canvas\n className={className}\n ref={canvas}\n style={{ height: size, width: size }}\n />\n )\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;AACA,SAASA,eAAe;AAExB,OAAOC,SAAS;AAChB,OAAOC,SAASC,WAAWC,cAAc;AAEzC,IAAMC,QAAQ,wBAACC,GAAWC,QAAgBC,QAAgBC,SAAiBC,YAAAA;AACzE,UAASJ,IAAIC,WAAWG,UAAUD,YAAaD,SAASD,UAAUE;AACpE,GAFc;AAed,IAAME,eAAe,wBAACC,QAA4CC,UAAAA;AAChE,QAAM,EACJC,QAAQ,IAAIC,OAAO,KAAKC,KAAK,eAAeC,QAAQ,GAAGC,SAASC,cAAc,EAAC,IAC7EN;AACJ,MAAI,EAAEO,GAAE,IAAKP;AACb,QAAMQ,OAAOC,IAAIR,KAAAA;AACjB,QAAMS,QAAQC,KAAKC,MAAMV,OAAOE,KAAAA;AAChC,QAAMS,YAAYL,KAAKM,MAAM,GAAG,CAAA;AAEhC,QAAMC,UAAUhB,OAAOgB;AAEvB,MAAI,CAACA,SAAS;AACZ;EACF;AAEA,MAAIV,WAAWA,QAAQW,SAAS,GAAG;AACjC,UAAMC,QAAQN,KAAKC,MAAMpB,MAAM0B,OAAOC,SAASX,KAAKM,MAAM,EAAC,GAAI,EAAA,GAAK,GAAG,MAAM,GAAGT,QAAQW,MAAM,CAAA;AAC9FT,SAAKF,QAAQY,KAAAA;EACf;AAEAF,UAAQK,QAAQV,QAAQN,QAAQE;AAChCS,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MAASH;MAAMD;IACxD,CAAA;EACF,CAAA;AAEA,SACE,sBAAA,cAACuC,SAAYxC,OACVC,QAEK,sBAAA,cAACF,UAAAA;IACCsC;IACAI,KAAK1C;IACL2C,OAAO;MAAErB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAGvC,IAAA;AAGV,GAhCmD;","names":["FlexRow","md5","React","useEffect","useRef","range","n","in_min","in_max","out_min","out_max","updateCanvas","canvas","props","value","size","bg","count","palette","iconPadding","fg","hash","md5","block","Math","floor","hashColor","slice","current","length","index","Number","parseInt","width","height","arr","map","el","parsedEl","ctx","getContext","imageSmoothingEnabled","clearRect","i","row","entries","j","fillStyle","fillRect","Identicon","className","useRef","useEffect","FlexRow","ref","style"]}
|
package/package.json
CHANGED
|
@@ -1,28 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/react-identicon",
|
|
3
|
+
"version": "4.0.4",
|
|
4
|
+
"description": "Common React library for all XY Labs projects that use React",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"utility",
|
|
7
|
+
"typescript",
|
|
8
|
+
"react"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://xylabs.com",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "git+https://github.com/xylabs/sdk-react/issues",
|
|
13
|
+
"email": "support@xylabs.com"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/xylabs/sdk-react.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "LGPL-3.0-only",
|
|
3
20
|
"author": {
|
|
4
|
-
"email": "support@xylabs.com",
|
|
5
21
|
"name": "XY Labs Development Team",
|
|
22
|
+
"email": "support@xylabs.com",
|
|
6
23
|
"url": "https://xylabs.com"
|
|
7
24
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/browser/index.d.ts",
|
|
30
|
+
"default": "./dist/browser/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
11
33
|
},
|
|
34
|
+
"module": "./dist/browser/index.mjs",
|
|
35
|
+
"types": "dist/browser/index.d.ts",
|
|
12
36
|
"workspaces": [
|
|
13
37
|
"packages/*"
|
|
14
38
|
],
|
|
15
39
|
"dependencies": {
|
|
16
|
-
"@xylabs/react-flexbox": "^4.0.
|
|
40
|
+
"@xylabs/react-flexbox": "^4.0.4",
|
|
17
41
|
"md5": "^2.3.0"
|
|
18
42
|
},
|
|
19
|
-
"description": "Common React library for all XY Labs projects that use React",
|
|
20
43
|
"devDependencies": {
|
|
21
44
|
"@mui/material": "^5.16.7",
|
|
22
45
|
"@types/md5": "^2.3.5",
|
|
23
|
-
"@types/react": "^18.3.
|
|
24
|
-
"@xylabs/ts-scripts-yarn3": "^4.0.
|
|
25
|
-
"@xylabs/tsconfig-react": "^4.0.
|
|
46
|
+
"@types/react": "^18.3.4",
|
|
47
|
+
"@xylabs/ts-scripts-yarn3": "^4.0.7",
|
|
48
|
+
"@xylabs/tsconfig-react": "^4.0.7",
|
|
26
49
|
"react": "^18.3.1",
|
|
27
50
|
"react-dom": "^18.3.1",
|
|
28
51
|
"typescript": "^5.5.4"
|
|
@@ -31,30 +54,7 @@
|
|
|
31
54
|
"@mui/material": "^5",
|
|
32
55
|
"react": "^18"
|
|
33
56
|
},
|
|
34
|
-
"exports": {
|
|
35
|
-
".": {
|
|
36
|
-
"types": "./dist/browser/index.d.ts",
|
|
37
|
-
"default": "./dist/browser/index.mjs"
|
|
38
|
-
},
|
|
39
|
-
"./package.json": "./package.json"
|
|
40
|
-
},
|
|
41
|
-
"types": "dist/browser/index.d.ts",
|
|
42
|
-
"module": "./dist/browser/index.mjs",
|
|
43
|
-
"homepage": "https://xylabs.com",
|
|
44
|
-
"keywords": [
|
|
45
|
-
"utility",
|
|
46
|
-
"typescript",
|
|
47
|
-
"react"
|
|
48
|
-
],
|
|
49
|
-
"license": "LGPL-3.0-only",
|
|
50
57
|
"publishConfig": {
|
|
51
58
|
"access": "public"
|
|
52
|
-
}
|
|
53
|
-
"repository": {
|
|
54
|
-
"type": "git",
|
|
55
|
-
"url": "git+https://github.com/xylabs/sdk-react.git"
|
|
56
|
-
},
|
|
57
|
-
"sideEffects": false,
|
|
58
|
-
"version": "4.0.3",
|
|
59
|
-
"type": "module"
|
|
59
|
+
}
|
|
60
60
|
}
|
|
@@ -20,7 +20,9 @@ export interface IdenticonProps extends FlexBoxProps {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const updateCanvas = (canvas: React.RefObject<HTMLCanvasElement>, props: IdenticonProps) => {
|
|
23
|
-
const {
|
|
23
|
+
const {
|
|
24
|
+
value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0,
|
|
25
|
+
} = props
|
|
24
26
|
let { fg } = props
|
|
25
27
|
const hash = md5(value)
|
|
26
28
|
const block = Math.floor(size / count)
|
|
@@ -83,13 +85,21 @@ export const Identicon: React.FC<IdenticonProps> = ({
|
|
|
83
85
|
const canvas = useRef<HTMLCanvasElement>(null)
|
|
84
86
|
|
|
85
87
|
useEffect(() => {
|
|
86
|
-
updateCanvas(canvas, {
|
|
88
|
+
updateCanvas(canvas, {
|
|
89
|
+
bg, className, count, fg, iconPadding, palette, size, value,
|
|
90
|
+
})
|
|
87
91
|
})
|
|
88
92
|
|
|
89
93
|
return (
|
|
90
94
|
<FlexRow {...props}>
|
|
91
95
|
{value
|
|
92
|
-
?
|
|
96
|
+
? (
|
|
97
|
+
<canvas
|
|
98
|
+
className={className}
|
|
99
|
+
ref={canvas}
|
|
100
|
+
style={{ height: size, width: size }}
|
|
101
|
+
/>
|
|
102
|
+
)
|
|
93
103
|
: null}
|
|
94
104
|
</FlexRow>
|
|
95
105
|
)
|