@botharness/pixel-avatar

中文文档
0.10.2发布于 2026/10/09MITTypeScriptES Module近 30 天下载 4941

Seeded, editable 32×32 chibi pixel avatars with state symbols that morph in and out

原始使用文档

@botharness/pixel-avatar

Seeded, editable 32×32 chibi pixel avatars with state symbols they can morph into.

import {
  pixelAvatarSvg,
  seededRecipe,
  faceCells,
  pixelSymbolCells,
} from '@botharness/pixel-avatar';

const recipe = seededRecipe('DeepSeekBot');
const svg = pixelAvatarSvg(recipe); // 32×32 viewBox, crisp edges, no ids or scripts
  • seededRecipe(name): the same name always gives the same face. createSeededRecipe(namespace) makes a factory with its own set of faces.
  • AVATAR_PARTS, AVATAR_SWATCHES, AVATAR_PRESETS, DEFAULT_RECIPE: everything an editor needs.
  • isPixelAvatarRecipe, canonicalRecipe: validate and normalise saved recipes.
  • AVATAR_HAIR_PARTS, AVATAR_RANGES, detailedRecipe(recipe): optional finer controls. A recipe may carry bangs, sideHair, backHair, spacing, height and hairLength, all six or none; detailedRecipe derives them from the plain hair so an editor can start from what is on screen. Recipes without them render exactly as before.
  • AVATAR_SPECIES, AVATAR_SPECIES_SWATCHES, AVATAR_PIECE_COLORS, withSpecies(recipe, species): Avatar Species (human, goblin) on the same rig, as asset version 2. withSpecies keeps every choice, splits side hair into sideHair (left) and rightSideHair, and accepts optional leftSideHairColor/rightSideHairColor, where left and right are as seen on screen. Consumers built before version 2 reject these recipes with isPixelAvatarRecipe and can show a saved snapshot instead.
  • AVATAR_PARTS_V2, AVATAR_EXTRA_PARTS, hiddenChoices(recipe): version 2 adds elf, dwarf, orc and flower species, armor/robe/tunic/cloak outfits, helmet/hood headwear, an optional beard, and a flower's petals and flowerBase. hiddenChoices names saved choices the current species or headwear keeps but does not draw, so an editor can say so instead of discarding them.
  • PixelCustomPart, withHeadpiece(recipe, part), customPartId, isPixelCustomPart: a Human-drawn Custom Part in the headpiece slot (the top 32×16 of the tile). Its back layer is drawn behind the hair and its front layer over it, and both follow the head through turns. Each cell is [x, y, color, tone], where color is an appearance color slot (hairColor, skinColor, eyeColor, shirtColor), so the part recolors with the Avatar, or a fixed #rrggbb, and tone is a step from −2 to 2 on the rig's shade ramp (partToneColor). A recipe wearing a part embeds its own copy as asset version 3. customPartId is the SHA-256 of the canonical content; names, authors and origins belong to the consumer's library.
  • HAIR_PART_SLOTS, hairPieceStart(recipe, slot), withCustomPart(recipe, slot, part), wornPart: drawn hair pieces. bangs, leftSideHair, rightSideHair and backHair each take a Custom Part (front layer only) that replaces the built-in piece while it stays saved underneath. In a hair part, a hairColor cell at tone 0 is live hair: it is shaded with the rest of the hair exactly like the built-in piece, so hairPieceStart flattens the worn built-in piece into such cells and an unchanged copy renders identically. Other cells show their own color. Drawn hair follows turns and is hidden under a helmet or hood and on a flower, like built-in hair.
  • REPLACE_PART_SLOTS, replacePartStart(recipe, slot): drawn outfit, accessory, beard, glasses, nose, cheeks, petals and flowerBase parts (front layer only). A drawn part replaces the built-in part pixel for pixel in the layer that part paints into, while the built-in choice stays saved underneath. replacePartStart flattens the worn built-in part for this recipe: pixels that are exactly an appearance color at a tone become that color slot, and the rest become fixed colors, so an unchanged copy renders identically. Drawn face parts never cover the speaking mouth, and drawn parts are hidden wherever the species or headwear hides the built-in part. A drawn accessory replacing a helmet or hood no longer hides the hair.
  • emptyPartLayer, paintPartLayer, fillPartLayer, mirrorPartX, partLayer, partCells, createCustomPart: drawing on dense layers, with pencil and eraser strokes, 4-connected flood fill and mirroring across the Avatar centerline.
  • partLinePoints, partRectPoints, gradientPartLayer, ditherThreshold, noisePartLayer, shadePartLayer: line (with 0°/45°/90° snap), rectangle (with square), tone gradient with 4×4 or 2×2 ordered dithering inside the start region, seeded ±1 tone noise, and a shade stroke that moves each colored cell one tone. All mirror, and all produce ordinary cells: the seed and the tool are not part of the part.
  • AVATAR_PIECE_COLORS_V4, AVATAR_STRANDS, AVATAR_HEADPIECES, withPieces, withBuiltInHeadpiece, builtInHeadpiece, headpieceStart: asset version 4. Bangs, back hair and a single strand each take an optional color (bangsColor, backHairColor, strandColor) that defaults to hairColor, like the side hair colors. The headpiece slot holds a built-in headpiece (ears, horns, halo or small head wings) or a Custom Part, worn together with any accessory. The base sits behind the hair and the rest in front, and the far side hides when the head turns. withPieces upgrades a recipe when the Human edits and moves an accessory that is now a headpiece into the empty headpiece slot. Saved recipes are never migrated on their own, so they keep rendering as before. headpieceStart flattens the worn headpiece into a Custom Part to start drawing from.
  • AVATAR_ANIMAL_SPECIES, AVATAR_PATTERNS, isAnimalSpecies: animal species in asset version 4. Each has a muzzle, an animal nose and its own ears, uses the skin color as fur, and takes an optional fur pattern drawn in fur tones. A drawn pattern Custom Part replaces the built-in one. Ear headpieces and ear accessories are kept but hidden on an animal.
  • faceCells, pixelSymbolCells, symbolArtCells: pixels for @botharness/pixel-morph.
  • pixelAvatarSvg(recipe, { turns, classPrefix }): optional pre-rendered head turns, and rig layer classes (<prefix>-body, -head, -face, -gaze, -blink) for CSS animation.
  • pixelAvatarSvg(recipe, { mouthLayers: true, speechMouthVersion: 2 }): saved/closed/half-open/open speech layers, with a flatter fully open mouth. Omit speechMouthVersion (or use 1) for the original round opening. Version 2 only changes the open layer, including each head turn; the accepted half-open, closed and saved face remain identical. This is a rendering-only speech artwork version, not a stored recipe migration. pixelFigure takes the same options. Text pacing and layer opacity stay with the consumer.

版本与发布记录

@botharness/pixel-avatar 共发布 12 个版本,首次发布于 2026/10/05;过去 12 个月发布了 12 个版本。

版本发布日期距今
0.10.2latest2026/10/0930 天前
0.10.12026/10/0930 天前
0.10.02026/10/0930 天前
0.9.02026/10/0930 天前
0.8.02026/10/0930 天前
0.7.02026/10/0930 天前

关于 @botharness/pixel-avatar 的常见问题

@botharness/pixel-avatar 是什么?

Seeded, editable 32×32 chibi pixel avatars with state symbols that morph in and out

如何安装 @botharness/pixel-avatar?

在项目目录运行 npm install @botharness/pixel-avatar,或使用 pnpm add / yarn add / bun add。

@botharness/pixel-avatar 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@botharness/pixel-avatar 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@botharness/pixel-avatar 可以商用吗?

@botharness/pixel-avatar 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@botharness/pixel-avatar 的下载量有多少?

根据 npm 官方下载统计,@botharness/pixel-avatar 在 2026/10/09 – 2026/11/07 这 30 天内被下载 4,941 次,日均约 165 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@botharness/pixel-avatar 还在维护吗?

最新版本 0.10.2 发布于 2026/10/09(30 天前);至今共发布 12 个版本,其中过去 12 个月发布了 12 个;首次发布于 2026/10/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。