diff --git a/.vitepress/theme/components/Identicon.vue b/.vitepress/theme/components/Identicon.vue new file mode 100644 index 00000000..ada63e44 --- /dev/null +++ b/.vitepress/theme/components/Identicon.vue @@ -0,0 +1,44 @@ + + + diff --git a/.vitepress/theme/components/IdenticonBuilder.vue b/.vitepress/theme/components/IdenticonBuilder.vue new file mode 100644 index 00000000..5d8f0855 --- /dev/null +++ b/.vitepress/theme/components/IdenticonBuilder.vue @@ -0,0 +1,208 @@ + + + diff --git a/.vitepress/theme/style.css b/.vitepress/theme/style.css index 9cd9d653..75da8324 100644 --- a/.vitepress/theme/style.css +++ b/.vitepress/theme/style.css @@ -101,7 +101,7 @@ h2 { } .nq-subline { - --uno: nq-subline text-neutral-700 mt-24; + --uno: nq-subline text-neutral-700 mt-24 text-20|22; } .VPHome { diff --git a/build/ui/identicons.md b/build/ui/identicons.md new file mode 100644 index 00000000..c2cca57c --- /dev/null +++ b/build/ui/identicons.md @@ -0,0 +1,159 @@ +# Nimiq Identicons + +
+ +
+ Blog Post + + +
+ Source code + +
+ +A simple, visually recognizable way to verify addresses.{.nq-subline} + + + +## More than 9 Million combintations! + +Each Identicon is a unique combination of colors and shapes based on an account's hash, providing instant visual confirmation. + + + + + +## Installation + +To start using Nimiq Identicons in your project, run: + +::: code-group + +```bash [npm] +npm install identicons-esm +``` + +```bash [yarn] +yarn add identicons-esm +``` + +```bash [pnpm] +pnpm add identicons-esm +``` + +```bash [bun] +bun add identicons-esm +``` +::: + +## Basic Usage + +Import and create an identicon using `createIdenticon`: + +```ts +import { createIdenticon } from 'identicons-esm' + +const input = 'Your input here' +const svg = await createIdenticon(input) +``` + +## Customization + +For specific colors or sections of the identicon, use `getIdenticonsParams`: + +```ts +import { ensambleSvg, formatIdenticon, getIdenticonsParams } from 'identicons-esm' + +const input = 'Your input here' +const { colors, sections } = await getIdenticonsParams(input) + +// You can modify any parameter as you wish +// colors.background, colors.main, colors.accent +// sections.top, sections.bottom, sections.sides, sections.face (SVG paths) + +// Generate SVG string +const customSvg = ensambleSvg({ colors, sections, /* Other optional values to overwrite default backgroundShape, innerShadow, circleShape */ }) + +// Also possible to change the Identicon format +const formatted = formatIdenticon(customSvg, { format: 'image/svg+xml' }) +``` + +## Migration from Legacy + +This module has updated performance and packaging over the legacy version. + +
+ + + +### Generating a SVG {.nq-no-prose} + + + +
+ +#### Old {.mt-0} + +```js +import Identicons from '@nimiq/identicons/dist/identicons.min.js' +IdenticonsLegacy.svgPath = '@nimiq/identicons/dist/identicons.min.svg' + +const input = 'Your input here' +const svg = await Identicons.svg(input) +``` + +#### New {.mt-0} + +```js +import { createIdenticon } from 'identicons-esm' + +const input = 'Your input here' +const svg = await createIdenticon(input) +``` + +
+ +
+ +
+ + + +### Generating a Data URI {.nq-no-prose} + + + +
+ +#### Old {.mt-0} + +```js +import Identicons from '@nimiq/identicons/dist/identicons.min.js' +IdenticonsLegacy.svgPath = '@nimiq/identicons/dist/identicons.min.svg' + +const input = 'Your input here' +const svg = await Identicons.toDataUri(input) +``` + +#### New {.mt-0} + +```ts +import { createIdenticon } from 'identicons-esm' + +const input = 'Your input here' +const svg = await createIdenticon(input, { format: 'image/svg+xml' }) +``` + +
+ +
+ +### Discontiuned functions + +There are functions in the original library that are not included in this implementation due to lack of use. These functions are: + +- `makeLetterHash` +- `wordsByEntropy` +- `Identicons.render` +- `Identicons.image` +- `Identicons.placeholder` diff --git a/package.json b/package.json index 6da6fdbb..042d0f66 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,9 @@ "@unhead/vue": "^1.11.10", "@unocss/reset": "^0.63.6", "@vueuse/core": "^11.1.0", + "canvas-confetti": "^1.9.3", "iconify-icon": "^2.1.0", + "identicons-esm": "^0.0.9", "json2md": "^2.0.1", "jszip": "^3.10.1", "markdown-it-mathjax3": "^4.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9cb72ef8..d10b73c5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,9 +23,15 @@ importers: '@vueuse/core': specifier: ^11.1.0 version: 11.1.0(vue@3.5.12(typescript@5.6.3)) + canvas-confetti: + specifier: ^1.9.3 + version: 1.9.3 iconify-icon: specifier: ^2.1.0 version: 2.1.0 + identicons-esm: + specifier: ^0.0.9 + version: 0.0.9 json2md: specifier: ^2.0.1 version: 2.0.1 @@ -1685,6 +1691,9 @@ packages: caniuse-lite@1.0.30001669: resolution: {integrity: sha512-DlWzFDJqstqtIVx1zeSpIMLjunf5SmwOw0N2Ck/QSQdS8PLS4+9HrLaYei4w8BIAL7IB/UEDu889d8vhCTPA0w==} + canvas-confetti@1.9.3: + resolution: {integrity: sha512-rFfTURMvmVEX1gyXFgn5QMn81bYk70qa0HLzcIOSVEyl57n6o9ItHeBtUSWdvKAPY0xlvBHno4/v3QPrT83q9g==} + caseless@0.12.0: resolution: {integrity: sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==} @@ -2696,6 +2705,9 @@ packages: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} engines: {node: '>=0.10.0'} + identicons-esm@0.0.9: + resolution: {integrity: sha512-X3ltGKmsAVnruBUZ80Px0cSizNvGJLSFsEBd9194ODTclYQuZhfXX0J5/qR62dj87fcfMS+9YJRvGGzC/WXxZQ==} + ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} @@ -6222,6 +6234,8 @@ snapshots: caniuse-lite@1.0.30001669: {} + canvas-confetti@1.9.3: {} + caseless@0.12.0: {} ccount@2.0.1: {} @@ -7425,6 +7439,8 @@ snapshots: dependencies: safer-buffer: 2.1.2 + identicons-esm@0.0.9: {} + ieee754@1.2.1: {} ignore@5.3.2: {}