@xylabs/react-identicon 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
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,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,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AAA;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
+ {"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 { 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":";;;;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,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,QA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,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"]}
package/package.json CHANGED
@@ -7,22 +7,24 @@
7
7
  },
8
8
  "bugs": {
9
9
  "email": "support@xylabs.com",
10
- "url": "https://github.com/xylabs/sdk-react/issues"
10
+ "url": "git+https://github.com/xylabs/sdk-react/issues"
11
11
  },
12
12
  "workspaces": [
13
13
  "packages/*"
14
14
  ],
15
15
  "dependencies": {
16
- "@xylabs/react-flexbox": "^4.0.1",
16
+ "@xylabs/react-flexbox": "^4.0.3",
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
+ "@mui/material": "^5.16.7",
21
22
  "@types/md5": "^2.3.5",
22
23
  "@types/react": "^18.3.3",
23
- "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.15",
24
- "@xylabs/tsconfig-react": "^4.0.0-rc.15",
24
+ "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.20",
25
+ "@xylabs/tsconfig-react": "^4.0.0-rc.20",
25
26
  "react": "^18.3.1",
27
+ "react-dom": "^18.3.1",
26
28
  "typescript": "^5.5.4"
27
29
  },
28
30
  "peerDependencies": {
@@ -50,9 +52,9 @@
50
52
  },
51
53
  "repository": {
52
54
  "type": "git",
53
- "url": "https://github.com/xylabs/sdk-react.git"
55
+ "url": "git+https://github.com/xylabs/sdk-react.git"
54
56
  },
55
57
  "sideEffects": false,
56
- "version": "4.0.1",
58
+ "version": "4.0.3",
57
59
  "type": "module"
58
60
  }
@@ -1,4 +1,5 @@
1
- import { FlexBoxProps, FlexRow } from '@xylabs/react-flexbox'
1
+ import type { FlexBoxProps } from '@xylabs/react-flexbox'
2
+ import { FlexRow } from '@xylabs/react-flexbox'
2
3
  // eslint-disable-next-line depend/ban-dependencies
3
4
  import md5 from 'md5'
4
5
  import React, { useEffect, useRef } from 'react'
package/xy.config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
1
+ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
2
  const config: XyTsupConfig = {
3
3
  compile: {
4
4
  browser: {