[!WARNING]
This package highly experimental it needs a lot of work PR is appriciated :)
This library provides functionalities for generating and manipulating avatars in Svelte applications. It is heavly inspired by notion avatar
To install the library, run:
npm install svelte-faces
yarn add svelte-faces
or
pnpm add svelte-faces
import { avatarGenerator } from 'svelte-faces';
It's recommended to initialize the library once in your application, potentially in a top-level component or a dedicated initialization service.
await avatarGenerator.initialize();
const featureOptions = avatarGenerator.getFeatureOptions(['hair', 'eyes', 'mouth']);
featureOptions
will be an array of objects, each containing:max
: The maximum number of styles available for that feature.parts
: An array of available options for that feature, including their SVG content and path information.const randomConfig = await avatarGenerator.generateRandomAvatar();
randomConfig
will contain an object with keys corresponding to avatar parts and their corresponding chosen styles.const previewSvg = avatarGenerator.generatePreview(randomConfig);
randomConfig
with your desired avatar configuration object.previewSvg
will be a string containing the SVG code for the generated avatar preview.const avatarElement = document.getElementById('my-avatar'); // Replace with your element ID
const pngDataUrl = await avatarGenerator.getPng({ element: avatarElement, width: 150, height: 175 });
pngDataUrl
will be a string containing the base64 encoded data URL of the avatar PNG image.