diff --git a/packages/ui/components/ui/identicon/generate.ts b/packages/ui/components/ui/identicon/generate.ts index e87741de..500c5612 100644 --- a/packages/ui/components/ui/identicon/generate.ts +++ b/packages/ui/components/ui/identicon/generate.ts @@ -1,12 +1,12 @@ // Inspired by: https://github.com/vercel/avatar -import djb2a from 'djb2a'; import color from 'tinycolor2'; +import Murmur from 'murmurhash3js'; // Deterministically getting a gradient from a string for use as an identicon export const generateGradient = (str: string) => { // Get first color - const hash = djb2a(str); + const hash = Murmur.x86.hash32(str); const c = color({ h: hash % 360, s: 0.95, l: 0.5 }); const tetrad = c.tetrad(); // 4 colors spaced around the color wheel, the first being the input @@ -22,11 +22,10 @@ export const generateGradient = (str: string) => { export const generateSolidColor = (str: string) => { // Get color - const hash = djb2a(str); + const hash = Murmur.x86.hash32(str); const c = color({ h: hash % 360, s: 0.95, l: 0.5 }) .saturate(0) .darken(20); - return { bg: c.toHexString(), // get readable text color diff --git a/packages/ui/package.json b/packages/ui/package.json index 7c2d5e41..37e7e68a 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -61,6 +61,7 @@ "framer-motion": "^11.2.4", "humanize-duration": "^3.32.0", "lucide-react": "^0.378.0", + "murmurhash3js": "^3.0.1", "react": "^18.3.1", "react-dom": "^18.3.1", "react-loader-spinner": "^6.1.6", @@ -83,6 +84,7 @@ "@testing-library/dom": "^10.1.0", "@testing-library/react": "^15.0.7", "@types/humanize-duration": "^3.27.4", + "@types/murmurhash3js": "^3.0.7", "@types/react": "^18.3.2", "@types/react-dom": "^18.3.0", "@types/tinycolor2": "^1.4.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 82ce7d44..3a8b0bf4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -510,6 +510,9 @@ importers: lucide-react: specifier: ^0.378.0 version: 0.378.0(react@18.3.1) + murmurhash3js: + specifier: ^3.0.1 + version: 3.0.1 react: specifier: ^18.3.1 version: 18.3.1 @@ -571,6 +574,9 @@ importers: '@types/humanize-duration': specifier: ^3.27.4 version: 3.27.4 + '@types/murmurhash3js': + specifier: ^3.0.7 + version: 3.0.7 '@types/react': specifier: ^18.3.2 version: 18.3.3 @@ -3704,6 +3710,9 @@ packages: '@types/minimatch@5.1.2': resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==} + '@types/murmurhash3js@3.0.7': + resolution: {integrity: sha512-jN3Z37nILIW1DZyP6N/NK+aw/zjFHPVb7hjrmdw7jx7FayrhKgkNpo6ZDwAsH8HSANjebBOxoXXtA39gKwyeGw==} + '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} @@ -7254,6 +7263,10 @@ packages: resolution: {integrity: sha512-I7tSVxHGPlmPN/enE3mS1aOSo6bWBfls+3HmuEeCUBCE7gWnm3cBXCBkpurzFjVRwC6Kld8lLaZ1Iv5vOcjvcQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + murmurhash3js@3.0.1: + resolution: {integrity: sha512-KL8QYUaxq7kUbcl0Yto51rMcYt7E/4N4BG3/c96Iqw1PQrTRspu8Cpx4TZ4Nunib1d4bEkIH3gjCYlP2RLBdow==} + engines: {node: '>=0.10.0'} + mute-stream@0.0.8: resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} @@ -13855,6 +13868,8 @@ snapshots: '@types/minimatch@5.1.2': {} + '@types/murmurhash3js@3.0.7': {} + '@types/node@12.20.55': {} '@types/node@18.19.39': @@ -18071,6 +18086,8 @@ snapshots: array-union: 3.0.1 minimatch: 3.1.2 + murmurhash3js@3.0.1: {} + mute-stream@0.0.8: {} mv@2.1.1: