@xylabs/react-identicon 3.4.2 → 4.0.1

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.
Files changed (68) hide show
  1. package/dist/browser/index.d.ts +16 -2
  2. package/dist/browser/index.mjs.map +1 -1
  3. package/package.json +5 -25
  4. package/src/components/Identicon.tsx +1 -0
  5. package/xy.config.ts +12 -0
  6. package/dist/browser/components/Identicon.d.cts +0 -14
  7. package/dist/browser/components/Identicon.d.cts.map +0 -1
  8. package/dist/browser/components/Identicon.d.mts +0 -14
  9. package/dist/browser/components/Identicon.d.mts.map +0 -1
  10. package/dist/browser/components/Identicon.d.ts +0 -14
  11. package/dist/browser/components/Identicon.d.ts.map +0 -1
  12. package/dist/browser/components/index.d.cts +0 -2
  13. package/dist/browser/components/index.d.cts.map +0 -1
  14. package/dist/browser/components/index.d.mts +0 -2
  15. package/dist/browser/components/index.d.mts.map +0 -1
  16. package/dist/browser/components/index.d.ts +0 -2
  17. package/dist/browser/components/index.d.ts.map +0 -1
  18. package/dist/browser/index.cjs +0 -111
  19. package/dist/browser/index.cjs.map +0 -1
  20. package/dist/browser/index.d.cts +0 -2
  21. package/dist/browser/index.d.cts.map +0 -1
  22. package/dist/browser/index.d.mts +0 -2
  23. package/dist/browser/index.d.mts.map +0 -1
  24. package/dist/browser/index.d.ts.map +0 -1
  25. package/dist/neutral/components/Identicon.d.cts +0 -14
  26. package/dist/neutral/components/Identicon.d.cts.map +0 -1
  27. package/dist/neutral/components/Identicon.d.mts +0 -14
  28. package/dist/neutral/components/Identicon.d.mts.map +0 -1
  29. package/dist/neutral/components/Identicon.d.ts +0 -14
  30. package/dist/neutral/components/Identicon.d.ts.map +0 -1
  31. package/dist/neutral/components/index.d.cts +0 -2
  32. package/dist/neutral/components/index.d.cts.map +0 -1
  33. package/dist/neutral/components/index.d.mts +0 -2
  34. package/dist/neutral/components/index.d.mts.map +0 -1
  35. package/dist/neutral/components/index.d.ts +0 -2
  36. package/dist/neutral/components/index.d.ts.map +0 -1
  37. package/dist/neutral/index.cjs +0 -111
  38. package/dist/neutral/index.cjs.map +0 -1
  39. package/dist/neutral/index.d.cts +0 -2
  40. package/dist/neutral/index.d.cts.map +0 -1
  41. package/dist/neutral/index.d.mts +0 -2
  42. package/dist/neutral/index.d.mts.map +0 -1
  43. package/dist/neutral/index.d.ts +0 -2
  44. package/dist/neutral/index.d.ts.map +0 -1
  45. package/dist/neutral/index.mjs +0 -80
  46. package/dist/neutral/index.mjs.map +0 -1
  47. package/dist/node/components/Identicon.d.cts +0 -14
  48. package/dist/node/components/Identicon.d.cts.map +0 -1
  49. package/dist/node/components/Identicon.d.mts +0 -14
  50. package/dist/node/components/Identicon.d.mts.map +0 -1
  51. package/dist/node/components/Identicon.d.ts +0 -14
  52. package/dist/node/components/Identicon.d.ts.map +0 -1
  53. package/dist/node/components/index.d.cts +0 -2
  54. package/dist/node/components/index.d.cts.map +0 -1
  55. package/dist/node/components/index.d.mts +0 -2
  56. package/dist/node/components/index.d.mts.map +0 -1
  57. package/dist/node/components/index.d.ts +0 -2
  58. package/dist/node/components/index.d.ts.map +0 -1
  59. package/dist/node/index.cjs +0 -115
  60. package/dist/node/index.cjs.map +0 -1
  61. package/dist/node/index.d.cts +0 -2
  62. package/dist/node/index.d.cts.map +0 -1
  63. package/dist/node/index.d.mts +0 -2
  64. package/dist/node/index.d.mts.map +0 -1
  65. package/dist/node/index.d.ts +0 -2
  66. package/dist/node/index.d.ts.map +0 -1
  67. package/dist/node/index.mjs +0 -80
  68. package/dist/node/index.mjs.map +0 -1
@@ -1,2 +1,16 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
1
+ import { FlexBoxProps } from '@xylabs/react-flexbox';
2
+ import React from 'react';
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 +1 @@
1
- {"version":3,"sources":["../../src/components/Identicon.tsx"],"sourcesContent":["import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'\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 { value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0 } = 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, { bg, className, count, fg, iconPadding, palette, size, value })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? <canvas className={className} ref={canvas} style={{ height: size, width: size }} />\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;AAAA,SAAuBA,eAAe;AACtC,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,EAAEC,QAAQ,IAAIC,OAAO,KAAKC,KAAK,eAAeC,QAAQ,GAAGC,SAASC,cAAc,EAAC,IAAKN;AAC5F,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,UAAQM,SAASX,QAAQN,QAAQE;AACjC,QAAMgB,MAAM;OAAId;IAAMe,IAAI,CAACC,OAAAA;AACzB,UAA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AACF,UAAAA;IAAOsC;IAAsBI,KAAK1C;IAAQ2C,OAAO;MAAErB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAC9E,IAAA;AAGV,GAxBmD;","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"]}
1
+ {"version":3,"sources":["../../src/components/Identicon.tsx"],"sourcesContent":["import { FlexBoxProps, 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 { value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0 } = 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, { bg, className, count, fg, iconPadding, palette, size, value })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? <canvas className={className} ref={canvas} style={{ height: size, width: size }} />\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;AAAA,SAAuBA,eAAe;AAEtC,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,EAAEC,QAAQ,IAAIC,OAAO,KAAKC,KAAK,eAAeC,QAAQ,GAAGC,SAASC,cAAc,EAAC,IAAKN;AAC5F,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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wBAAC,EAClDlC,OAAO,KACPmC,YAAY,aACZlC,IACAC,OACAG,IACAD,aACAD,SACAJ,OACA,GAAGD,MAAAA,MACJ;AACC,QAAMD,SAASuC,OAA0B,IAAA;AAEzCC,YAAU,MAAA;AACRzC,iBAAaC,QAAQ;MAAEI;MAAIkC;MAAWjC;MAAOG;MAAID;MAAaD;MAASH;MAAMD;IAAM,CAAA;EACrF,CAAA;AAEA,SACE,sBAAA,cAACuC,SAAYxC,OACVC,QACG,sBAAA,cAACF,UAAAA;IAAOsC;IAAsBI,KAAK1C;IAAQ2C,OAAO;MAAErB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAC9E,IAAA;AAGV,GAxBmD;","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
@@ -13,15 +13,15 @@
13
13
  "packages/*"
14
14
  ],
15
15
  "dependencies": {
16
- "@xylabs/react-flexbox": "^3.4.2",
16
+ "@xylabs/react-flexbox": "^4.0.1",
17
17
  "md5": "^2.3.0"
18
18
  },
19
19
  "description": "Common React library for all XY Labs projects that use React",
20
20
  "devDependencies": {
21
21
  "@types/md5": "^2.3.5",
22
22
  "@types/react": "^18.3.3",
23
- "@xylabs/ts-scripts-yarn3": "^3.15.16",
24
- "@xylabs/tsconfig-react": "^3.15.16",
23
+ "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.15",
24
+ "@xylabs/tsconfig-react": "^4.0.0-rc.15",
25
25
  "react": "^18.3.1",
26
26
  "typescript": "^5.5.4"
27
27
  },
@@ -31,32 +31,12 @@
31
31
  },
32
32
  "exports": {
33
33
  ".": {
34
- "node": {
35
- "import": {
36
- "types": "./dist/node/index.d.mts",
37
- "default": "./dist/node/index.mjs"
38
- },
39
- "require": {
40
- "types": "./dist/node/index.d.cts",
41
- "default": "./dist/node/index.cjs"
42
- }
43
- },
44
- "browser": {
45
- "import": {
46
- "types": "./dist/browser/index.d.mts",
47
- "default": "./dist/browser/index.mjs"
48
- },
49
- "require": {
50
- "types": "./dist/browser/index.d.cts",
51
- "default": "./dist/browser/index.cjs"
52
- }
53
- },
34
+ "types": "./dist/browser/index.d.ts",
54
35
  "default": "./dist/browser/index.mjs"
55
36
  },
56
37
  "./package.json": "./package.json"
57
38
  },
58
39
  "types": "dist/browser/index.d.ts",
59
- "main": "./dist/browser/index.cjs",
60
40
  "module": "./dist/browser/index.mjs",
61
41
  "homepage": "https://xylabs.com",
62
42
  "keywords": [
@@ -73,6 +53,6 @@
73
53
  "url": "https://github.com/xylabs/sdk-react.git"
74
54
  },
75
55
  "sideEffects": false,
76
- "version": "3.4.2",
56
+ "version": "4.0.1",
77
57
  "type": "module"
78
58
  }
@@ -1,4 +1,5 @@
1
1
  import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'
2
+ // eslint-disable-next-line depend/ban-dependencies
2
3
  import md5 from 'md5'
3
4
  import React, { useEffect, useRef } from 'react'
4
5
 
package/xy.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
+ const config: XyTsupConfig = {
3
+ compile: {
4
+ browser: {
5
+ src: {},
6
+ },
7
+ node: {},
8
+ neutral: {},
9
+ },
10
+ }
11
+
12
+ export default config
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,111 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/index.ts
32
- var src_exports = {};
33
- __export(src_exports, {
34
- Identicon: () => Identicon
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
- // src/components/Identicon.tsx
39
- var import_react_flexbox = require("@xylabs/react-flexbox");
40
- var import_md5 = __toESM(require("md5"), 1);
41
- var import_react = __toESM(require("react"), 1);
42
- var range = /* @__PURE__ */ __name((n, in_min, in_max, out_min, out_max) => {
43
- return (n - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
44
- }, "range");
45
- var updateCanvas = /* @__PURE__ */ __name((canvas, props) => {
46
- const { value = "", size = 400, bg = "transparent", count = 5, palette, iconPadding = 0 } = props;
47
- let { fg } = props;
48
- const hash = (0, import_md5.default)(value);
49
- const block = Math.floor(size / count);
50
- const hashColor = hash.slice(0, 6);
51
- const current = canvas.current;
52
- if (!current) {
53
- return;
54
- }
55
- if (palette && palette.length > 0) {
56
- const index = Math.floor(range(Number.parseInt(hash.slice(-3), 16), 0, 4095, 0, palette.length));
57
- fg = palette[index];
58
- }
59
- current.width = block * count + iconPadding;
60
- current.height = block * count + iconPadding;
61
- const arr = [
62
- ...hash
63
- ].map((el) => {
64
- const parsedEl = Number.parseInt(el, 16);
65
- return parsedEl < 8 ? 0 : 1;
66
- });
67
- const map = [];
68
- map[0] = map[4] = arr.slice(0, 5);
69
- map[1] = map[3] = arr.slice(5, 10);
70
- map[2] = arr.slice(10, 15);
71
- const ctx = current.getContext("2d");
72
- if (ctx) {
73
- ctx.imageSmoothingEnabled = false;
74
- ctx.clearRect(0, 0, current.width, current.height);
75
- for (const [i, row] of map.entries()) {
76
- for (const [j, el] of row.entries()) {
77
- if (el) {
78
- ctx.fillStyle = fg ?? "#" + hashColor;
79
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
80
- } else {
81
- ctx.fillStyle = bg;
82
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
83
- }
84
- }
85
- }
86
- }
87
- }, "updateCanvas");
88
- var Identicon = /* @__PURE__ */ __name(({ size = 400, className = "identicon", bg, count, fg, iconPadding, palette, value, ...props }) => {
89
- const canvas = (0, import_react.useRef)(null);
90
- (0, import_react.useEffect)(() => {
91
- updateCanvas(canvas, {
92
- bg,
93
- className,
94
- count,
95
- fg,
96
- iconPadding,
97
- palette,
98
- size,
99
- value
100
- });
101
- });
102
- return /* @__PURE__ */ import_react.default.createElement(import_react_flexbox.FlexRow, props, value ? /* @__PURE__ */ import_react.default.createElement("canvas", {
103
- className,
104
- ref: canvas,
105
- style: {
106
- height: size,
107
- width: size
108
- }
109
- }) : null);
110
- }, "Identicon");
111
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/components/Identicon.tsx"],"sourcesContent":["export * from './components/index.ts'\n","import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'\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 { value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0 } = 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, { bg, className, count, fg, iconPadding, palette, size, value })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? <canvas className={className} ref={canvas} style={{ height: size, width: size }} />\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,2BAAsC;AACtC,iBAAgB;AAChB,mBAAyC;AAEzC,IAAMA,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,EAAEC,QAAQ,IAAIC,OAAO,KAAKC,KAAK,eAAeC,QAAQ,GAAGC,SAASC,cAAc,EAAC,IAAKN;AAC5F,MAAI,EAAEO,GAAE,IAAKP;AACb,QAAMQ,WAAOC,WAAAA,SAAIR,KAAAA;AACjB,QAAMS,QAAQC,KAAKC,MAAMV,OAAOE,KAAAA;AAChC,QAAMS,YAAYL,KAAK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aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F;MACF;IACF;EACF;AACF,GAhDqB;AAkDd,IAAM8B,YAAsC,wBAAC,EAClDlC,OAAO,KACPmC,YAAY,aACZlC,IACAC,OACAG,IACAD,aACAD,SACAJ,OACA,GAAGD,MAAAA,MACJ;AACC,QAAMD,aAASuC,qBAA0B,IAAA;AAEzCC,8BAAU,MAAA;AACRzC,iBAAaC,QAAQ;MAAEI;MAAIkC;MAAWjC;MAAOG;MAAID;MAAaD;MAASH;MAAMD;IAAM,CAAA;EACrF,CAAA;AAEA,SACE,6BAAAuC,QAAA,cAACC,8BAAYzC,OACVC,QACG,6BAAAuC,QAAA,cAACzC,UAAAA;IAAOsC;IAAsBK,KAAK3C;IAAQ4C,OAAO;MAAEtB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAC9E,IAAA;AAGV,GAxBmD;","names":["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","React","FlexRow","ref","style"]}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,111 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/index.ts
32
- var src_exports = {};
33
- __export(src_exports, {
34
- Identicon: () => Identicon
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
- // src/components/Identicon.tsx
39
- var import_react_flexbox = require("@xylabs/react-flexbox");
40
- var import_md5 = __toESM(require("md5"), 1);
41
- var import_react = __toESM(require("react"), 1);
42
- var range = /* @__PURE__ */ __name((n, in_min, in_max, out_min, out_max) => {
43
- return (n - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
44
- }, "range");
45
- var updateCanvas = /* @__PURE__ */ __name((canvas, props) => {
46
- const { value = "", size = 400, bg = "transparent", count = 5, palette, iconPadding = 0 } = props;
47
- let { fg } = props;
48
- const hash = (0, import_md5.default)(value);
49
- const block = Math.floor(size / count);
50
- const hashColor = hash.slice(0, 6);
51
- const current = canvas.current;
52
- if (!current) {
53
- return;
54
- }
55
- if (palette && palette.length > 0) {
56
- const index = Math.floor(range(Number.parseInt(hash.slice(-3), 16), 0, 4095, 0, palette.length));
57
- fg = palette[index];
58
- }
59
- current.width = block * count + iconPadding;
60
- current.height = block * count + iconPadding;
61
- const arr = [
62
- ...hash
63
- ].map((el) => {
64
- const parsedEl = Number.parseInt(el, 16);
65
- return parsedEl < 8 ? 0 : 1;
66
- });
67
- const map = [];
68
- map[0] = map[4] = arr.slice(0, 5);
69
- map[1] = map[3] = arr.slice(5, 10);
70
- map[2] = arr.slice(10, 15);
71
- const ctx = current.getContext("2d");
72
- if (ctx) {
73
- ctx.imageSmoothingEnabled = false;
74
- ctx.clearRect(0, 0, current.width, current.height);
75
- for (const [i, row] of map.entries()) {
76
- for (const [j, el] of row.entries()) {
77
- if (el) {
78
- ctx.fillStyle = fg ?? "#" + hashColor;
79
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
80
- } else {
81
- ctx.fillStyle = bg;
82
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
83
- }
84
- }
85
- }
86
- }
87
- }, "updateCanvas");
88
- var Identicon = /* @__PURE__ */ __name(({ size = 400, className = "identicon", bg, count, fg, iconPadding, palette, value, ...props }) => {
89
- const canvas = (0, import_react.useRef)(null);
90
- (0, import_react.useEffect)(() => {
91
- updateCanvas(canvas, {
92
- bg,
93
- className,
94
- count,
95
- fg,
96
- iconPadding,
97
- palette,
98
- size,
99
- value
100
- });
101
- });
102
- return /* @__PURE__ */ import_react.default.createElement(import_react_flexbox.FlexRow, props, value ? /* @__PURE__ */ import_react.default.createElement("canvas", {
103
- className,
104
- ref: canvas,
105
- style: {
106
- height: size,
107
- width: size
108
- }
109
- }) : null);
110
- }, "Identicon");
111
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/components/Identicon.tsx"],"sourcesContent":["export * from './components/index.ts'\n","import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'\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 { value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0 } = 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, { bg, className, count, fg, iconPadding, palette, size, value })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? <canvas className={className} ref={canvas} style={{ height: size, width: size }} />\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,2BAAsC;AACtC,iBAAgB;AAChB,mBAAyC;AAEzC,IAAMA,QAAQ,wBAACC,GAAWC,QAAgBC,QAAgBC,SAAiBC,YAAAA;AACzE,UAASJ,IAAIC,WAAWG,UAAUD,YAAaD,SAASD,UAAUE;AACpE,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AACpC,iBAAW,CAACC,GAAGT,EAAAA,KAAOO,IAAIC,QAAO,GAAI;AACnC,YAAIR,IAAI;AACNE,cAAIQ,YAAY3B,MAAM,MAAMM;AAC5Ba,cAAIS,SAASzB,QAAQoB,IAAIxB,aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F,OAAO;AACLoB,cAAIQ,YAAY/B;AAChBuB,cAAIS,SAASzB,QAAQoB,IAAIxB,aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F;MACF;IACF;EACF;AACF,GAhDqB;AAkDd,IAAM8B,YAAsC,wBAAC,EAClDlC,OAAO,KACPmC,YAAY,aACZlC,IACAC,OACAG,IACAD,aACAD,SACAJ,OACA,GAAGD,MAAAA,MACJ;AACC,QAAMD,aAASuC,qBAA0B,IAAA;AAEzCC,8BAAU,MAAA;AACRzC,iBAAaC,QAAQ;MAAEI;MAAIkC;MAAWjC;MAAOG;MAAID;MAAaD;MAASH;MAAMD;IAAM,CAAA;EACrF,CAAA;AAEA,SACE,6BAAAuC,QAAA,cAACC,8BAAYzC,OACVC,QACG,6BAAAuC,QAAA,cAACzC,UAAAA;IAAOsC;IAAsBK,KAAK3C;IAAQ4C,OAAO;MAAEtB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAC9E,IAAA;AAGV,GAxBmD;","names":["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","React","FlexRow","ref","style"]}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,80 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/components/Identicon.tsx
5
- import { FlexRow } from "@xylabs/react-flexbox";
6
- import md5 from "md5";
7
- import React, { useEffect, useRef } from "react";
8
- var range = /* @__PURE__ */ __name((n, in_min, in_max, out_min, out_max) => {
9
- return (n - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
10
- }, "range");
11
- var updateCanvas = /* @__PURE__ */ __name((canvas, props) => {
12
- const { value = "", size = 400, bg = "transparent", count = 5, palette, iconPadding = 0 } = props;
13
- let { fg } = props;
14
- const hash = md5(value);
15
- const block = Math.floor(size / count);
16
- const hashColor = hash.slice(0, 6);
17
- const current = canvas.current;
18
- if (!current) {
19
- return;
20
- }
21
- if (palette && palette.length > 0) {
22
- const index = Math.floor(range(Number.parseInt(hash.slice(-3), 16), 0, 4095, 0, palette.length));
23
- fg = palette[index];
24
- }
25
- current.width = block * count + iconPadding;
26
- current.height = block * count + iconPadding;
27
- const arr = [
28
- ...hash
29
- ].map((el) => {
30
- const parsedEl = Number.parseInt(el, 16);
31
- return parsedEl < 8 ? 0 : 1;
32
- });
33
- const map = [];
34
- map[0] = map[4] = arr.slice(0, 5);
35
- map[1] = map[3] = arr.slice(5, 10);
36
- map[2] = arr.slice(10, 15);
37
- const ctx = current.getContext("2d");
38
- if (ctx) {
39
- ctx.imageSmoothingEnabled = false;
40
- ctx.clearRect(0, 0, current.width, current.height);
41
- for (const [i, row] of map.entries()) {
42
- for (const [j, el] of row.entries()) {
43
- if (el) {
44
- ctx.fillStyle = fg ?? "#" + hashColor;
45
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
46
- } else {
47
- ctx.fillStyle = bg;
48
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
49
- }
50
- }
51
- }
52
- }
53
- }, "updateCanvas");
54
- var Identicon = /* @__PURE__ */ __name(({ size = 400, className = "identicon", bg, count, fg, iconPadding, palette, value, ...props }) => {
55
- const canvas = useRef(null);
56
- useEffect(() => {
57
- updateCanvas(canvas, {
58
- bg,
59
- className,
60
- count,
61
- fg,
62
- iconPadding,
63
- palette,
64
- size,
65
- value
66
- });
67
- });
68
- return /* @__PURE__ */ React.createElement(FlexRow, props, value ? /* @__PURE__ */ React.createElement("canvas", {
69
- className,
70
- ref: canvas,
71
- style: {
72
- height: size,
73
- width: size
74
- }
75
- }) : null);
76
- }, "Identicon");
77
- export {
78
- Identicon
79
- };
80
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/Identicon.tsx"],"sourcesContent":["import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'\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 { value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0 } = 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, { bg, className, count, fg, iconPadding, palette, size, value })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? <canvas className={className} ref={canvas} style={{ height: size, width: size }} />\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;AAAA,SAAuBA,eAAe;AACtC,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,wBAAC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AAOO,IAAIC,QAAO,GAAI;AACnC,YAAIR,IAAI;AACNE,cAAIQ,YAAY3B,MAAM,MAAMM;AAC5Ba,cAAIS,SAASzB,QAAQoB,IAAIxB,aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F,OAAO;AACLoB,cAAIQ,YAAY/B;AAChBuB,cAAIS,SAASzB,QAAQoB,IAAIxB,aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F;MACF;IACF;EACF;AACF,GAhDqB;AAkDd,IAAM8B,YAAsC,wBAAC,EAClDlC,OAAO,KACPmC,YAAY,aACZlC,IACAC,OACAG,IACAD,aACAD,SACAJ,OACA,GAAGD,MAAAA,MACJ;AACC,QAAMD,SAASuC,OAA0B,IAAA;AAEzCC,YAAU,MAAA;AACRzC,iBAAaC,QAAQ;MAAEI;MAAIkC;MAAWjC;MAAOG;MAAID;MAAaD;MAASH;MAAMD;IAAM,CAAA;EACrF,CAAA;AAEA,SACE,sBAAA,cAACuC,SAAYxC,OACVC,QACG,sBAAA,cAACF,UAAAA;IAAOsC;IAAsBI,KAAK1C;IAAQ2C,OAAO;MAAErB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAC9E,IAAA;AAGV,GAxBmD;","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"]}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,14 +0,0 @@
1
- import { 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"Identicon.d.ts","sourceRoot":"","sources":["../../../src/components/Identicon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,uBAAuB,CAAA;AAE7D,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;AAoDD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAwB9C,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './Identicon.tsx';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/index.ts
32
- var src_exports = {};
33
- __export(src_exports, {
34
- Identicon: () => Identicon
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
- // src/components/Identicon.tsx
39
- var import_react_flexbox = require("@xylabs/react-flexbox");
40
- var import_md5 = __toESM(require("md5"), 1);
41
- var import_react = __toESM(require("react"), 1);
42
- var range = /* @__PURE__ */ __name((n, in_min, in_max, out_min, out_max) => {
43
- return (n - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
44
- }, "range");
45
- var updateCanvas = /* @__PURE__ */ __name((canvas, props) => {
46
- const { value = "", size = 400, bg = "transparent", count = 5, palette, iconPadding = 0 } = props;
47
- let { fg } = props;
48
- const hash = (0, import_md5.default)(value);
49
- const block = Math.floor(size / count);
50
- const hashColor = hash.slice(0, 6);
51
- const current = canvas.current;
52
- if (!current) {
53
- return;
54
- }
55
- if (palette && palette.length > 0) {
56
- const index = Math.floor(range(Number.parseInt(hash.slice(-3), 16), 0, 4095, 0, palette.length));
57
- fg = palette[index];
58
- }
59
- current.width = block * count + iconPadding;
60
- current.height = block * count + iconPadding;
61
- const arr = [
62
- ...hash
63
- ].map((el) => {
64
- const parsedEl = Number.parseInt(el, 16);
65
- return parsedEl < 8 ? 0 : 1;
66
- });
67
- const map = [];
68
- map[0] = map[4] = arr.slice(0, 5);
69
- map[1] = map[3] = arr.slice(5, 10);
70
- map[2] = arr.slice(10, 15);
71
- const ctx = current.getContext("2d");
72
- if (ctx) {
73
- ctx.imageSmoothingEnabled = false;
74
- ctx.clearRect(0, 0, current.width, current.height);
75
- for (const [i, row] of map.entries()) {
76
- for (const [j, el] of row.entries()) {
77
- if (el) {
78
- ctx.fillStyle = fg ?? "#" + hashColor;
79
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
80
- } else {
81
- ctx.fillStyle = bg;
82
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
83
- }
84
- }
85
- }
86
- }
87
- }, "updateCanvas");
88
- var Identicon = /* @__PURE__ */ __name(({ size = 400, className = "identicon", bg, count, fg, iconPadding, palette, value, ...props }) => {
89
- const canvas = (0, import_react.useRef)(null);
90
- (0, import_react.useEffect)(() => {
91
- updateCanvas(canvas, {
92
- bg,
93
- className,
94
- count,
95
- fg,
96
- iconPadding,
97
- palette,
98
- size,
99
- value
100
- });
101
- });
102
- return /* @__PURE__ */ import_react.default.createElement(import_react_flexbox.FlexRow, props, value ? /* @__PURE__ */ import_react.default.createElement("canvas", {
103
- className,
104
- ref: canvas,
105
- style: {
106
- height: size,
107
- width: size
108
- }
109
- }) : null);
110
- }, "Identicon");
111
- // Annotate the CommonJS export names for ESM import in node:
112
- 0 && (module.exports = {
113
- Identicon
114
- });
115
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/components/Identicon.tsx"],"sourcesContent":["export * from './components/index.ts'\n","import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'\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 { value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0 } = 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, { bg, className, count, fg, iconPadding, palette, size, value })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? <canvas className={className} ref={canvas} style={{ height: size, width: size }} />\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,2BAAsC;AACtC,iBAAgB;AAChB,mBAAyC;AAEzC,IAAMA,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,EAAEC,QAAQ,IAAIC,OAAO,KAAKC,KAAK,eAAeC,QAAQ,GAAGC,SAASC,cAAc,EAAC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B,QAAQoB,IAAIxB,aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F,OAAO;AACLoB,cAAIQ,YAAY/B;AAChBuB,cAAIS,SAASzB,QAAQoB,IAAIxB,aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F;MACF;IACF;EACF;AACF,GAhDqB;AAkDd,IAAM8B,YAAsC,wBAAC,EAClDlC,OAAO,KACPmC,YAAY,aACZlC,IACAC,OACAG,IACAD,aACAD,SACAJ,OACA,GAAGD,MAAAA,MACJ;AACC,QAAMD,aAASuC,qBAA0B,IAAA;AAEzCC,8BAAU,MAAA;AACRzC,iBAAaC,QAAQ;MAAEI;MAAIkC;MAAWjC;MAAOG;MAAID;MAAaD;MAASH;MAAMD;IAAM,CAAA;EACrF,CAAA;AAEA,SACE,6BAAAuC,QAAA,cAACC,8BAAYzC,OACVC,QACG,6BAAAuC,QAAA,cAACzC,UAAAA;IAAOsC;IAAsBK,KAAK3C;IAAQ4C,OAAO;MAAEtB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAC9E,IAAA;AAGV,GAxBmD;","names":["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","React","FlexRow","ref","style"]}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './components/index.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,80 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/components/Identicon.tsx
5
- import { FlexRow } from "@xylabs/react-flexbox";
6
- import md5 from "md5";
7
- import React, { useEffect, useRef } from "react";
8
- var range = /* @__PURE__ */ __name((n, in_min, in_max, out_min, out_max) => {
9
- return (n - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
10
- }, "range");
11
- var updateCanvas = /* @__PURE__ */ __name((canvas, props) => {
12
- const { value = "", size = 400, bg = "transparent", count = 5, palette, iconPadding = 0 } = props;
13
- let { fg } = props;
14
- const hash = md5(value);
15
- const block = Math.floor(size / count);
16
- const hashColor = hash.slice(0, 6);
17
- const current = canvas.current;
18
- if (!current) {
19
- return;
20
- }
21
- if (palette && palette.length > 0) {
22
- const index = Math.floor(range(Number.parseInt(hash.slice(-3), 16), 0, 4095, 0, palette.length));
23
- fg = palette[index];
24
- }
25
- current.width = block * count + iconPadding;
26
- current.height = block * count + iconPadding;
27
- const arr = [
28
- ...hash
29
- ].map((el) => {
30
- const parsedEl = Number.parseInt(el, 16);
31
- return parsedEl < 8 ? 0 : 1;
32
- });
33
- const map = [];
34
- map[0] = map[4] = arr.slice(0, 5);
35
- map[1] = map[3] = arr.slice(5, 10);
36
- map[2] = arr.slice(10, 15);
37
- const ctx = current.getContext("2d");
38
- if (ctx) {
39
- ctx.imageSmoothingEnabled = false;
40
- ctx.clearRect(0, 0, current.width, current.height);
41
- for (const [i, row] of map.entries()) {
42
- for (const [j, el] of row.entries()) {
43
- if (el) {
44
- ctx.fillStyle = fg ?? "#" + hashColor;
45
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
46
- } else {
47
- ctx.fillStyle = bg;
48
- ctx.fillRect(block * i + iconPadding, block * j + iconPadding, block - iconPadding, block - iconPadding);
49
- }
50
- }
51
- }
52
- }
53
- }, "updateCanvas");
54
- var Identicon = /* @__PURE__ */ __name(({ size = 400, className = "identicon", bg, count, fg, iconPadding, palette, value, ...props }) => {
55
- const canvas = useRef(null);
56
- useEffect(() => {
57
- updateCanvas(canvas, {
58
- bg,
59
- className,
60
- count,
61
- fg,
62
- iconPadding,
63
- palette,
64
- size,
65
- value
66
- });
67
- });
68
- return /* @__PURE__ */ React.createElement(FlexRow, props, value ? /* @__PURE__ */ React.createElement("canvas", {
69
- className,
70
- ref: canvas,
71
- style: {
72
- height: size,
73
- width: size
74
- }
75
- }) : null);
76
- }, "Identicon");
77
- export {
78
- Identicon
79
- };
80
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/Identicon.tsx"],"sourcesContent":["import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'\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 { value = '', size = 400, bg = 'transparent', count = 5, palette, iconPadding = 0 } = 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, { bg, className, count, fg, iconPadding, palette, size, value })\n })\n\n return (\n <FlexRow {...props}>\n {value\n ? <canvas className={className} ref={canvas} style={{ height: size, width: size }} />\n : null}\n </FlexRow>\n )\n}\n"],"mappings":";;;;AAAA,SAAuBA,eAAe;AACtC,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,EAAEC,QAAQ,IAAIC,OAAO,KAAKC,KAAK,eAAeC,QAAQ,GAAGC,SAASC,cAAc,EAAC,IAAKN;AAC5F,MAAI,EAAEO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IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F,OAAO;AACLoB,cAAIQ,YAAY/B;AAChBuB,cAAIS,SAASzB,QAAQoB,IAAIxB,aAAaI,QAAQuB,IAAI3B,aAAaI,QAAQJ,aAAaI,QAAQJ,WAAAA;QAC9F;MACF;IACF;EACF;AACF,GAhDqB;AAkDd,IAAM8B,YAAsC,wBAAC,EAClDlC,OAAO,KACPmC,YAAY,aACZlC,IACAC,OACAG,IACAD,aACAD,SACAJ,OACA,GAAGD,MAAAA,MACJ;AACC,QAAMD,SAASuC,OAA0B,IAAA;AAEzCC,YAAU,MAAA;AACRzC,iBAAaC,QAAQ;MAAEI;MAAIkC;MAAWjC;MAAOG;MAAID;MAAaD;MAASH;MAAMD;IAAM,CAAA;EACrF,CAAA;AAEA,SACE,sBAAA,cAACuC,SAAYxC,OACVC,QACG,sBAAA,cAACF,UAAAA;IAAOsC;IAAsBI,KAAK1C;IAAQ2C,OAAO;MAAErB,QAAQnB;MAAMkB,OAAOlB;IAAK;OAC9E,IAAA;AAGV,GAxBmD;","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"]}