コンテンツにスキップ
Humation
日本語
Esc
移動開く⌘Jプレビュー
このページの内容

オプション

React コンポーネントと createAvatar に渡せるすべての値と、それを支えるヘルパーと型の一覧です。

<Avatar>

@humation/react<svg> 要素を描画する forwardRef コンポーネントです。

PropType
assetsHumationManifest

The asset set to draw with, e.g. humation1 from @humation/assets-humation-1.

TypeHumationManifest
seed?string

Picks a part for every slot deterministically. Explicit selections override the seeded picks.

Typestring
selections?Record<string, string>

Part selections by name, alias, or canonical ID, e.g. { head: 'braids' }.

TypeRecord<string, string>
colors?Record<string, string>

Color slot values. Applied as CSS custom properties on the <svg> element, so a color change never re-renders the content.

TypeRecord<string, string>
background?string | 'transparent'

Background fill. Defaults to the manifest default.

Typestring | 'transparent'
Default'#F6F5F4'
crop?string

Crop id. Humation 1 ships a single crop.

Typestring
Default'avatar'
size?number | string

Rendered size. Numbers keep the crop aspect ratio.

Typenumber | string
title?string

Accessible title. Without it the avatar is treated as decorative.

Typestring
...svgPropsOmit<SVGProps<SVGSVGElement>, 'children'>

Everything else is forwarded to the root <svg>, including className, style, and ref.

TypeOmit<SVGProps<SVGSVGElement>, 'children'>

createAvatar

@humation/core

createAvatar(manifest: HumationManifest, options?: CreateAvatarOptions)
PropType
seed?string

Deterministic picks per slot. Stable per asset package version; adding parts to a slot can change a pick.

Typestring
selections?Record<SelectionSlotId, string>

Canonical part IDs, global aliases, or slot-scoped names. Overrides seeded picks.

TypeRecord<SelectionSlotId, string>
colors?Record<ColorSlotId, HexColor>

Hex values, with or without a leading #.

TypeRecord<ColorSlotId, HexColor>
background?HexColor | 'transparent'

Overrides the manifest default background.

TypeHexColor | 'transparent'
crop?CropId

Overrides the manifest default crop.

TypeCropId
PropType
toString()string

A complete SVG document.

Typestring
toDataUri()string

A data:image/svg+xml URI, ready for an <img src>.

Typestring
toJSON()AvatarJson

The resolved selections, colors, background, and crop, with every part as a canonical ID.

TypeAvatarJson
toRenderData()AvatarRenderData

Composed fragments without the root element, for framework wrappers that build the <svg> themselves.

TypeAvatarRenderData

返されるオブジェクトには、4 種類の変換メソッドがあります。

ヘルパー

@humation/core

PropType
resolvePartId(input, manifest, slotId?)string

Resolves a name, alias, or ID to a canonical part ID. Pass slotId to scope a bare name to one slot.

Typestring
getPartsForSlot(manifest, slotId)PartOption[]

Every part in a selection slot (head, body, bottom, item, glasses).

TypePartOption[]
getPartsForUiGroup(manifest, groupId)PartOption[]

Every part in a UI group. Groups are what a picker renders as tabs.

TypePartOption[]
createPartPreview(manifest, part, options?){ toString, toDataUri }

A single-part preview for picker swatches. Options accept colors and background.

Type{ toString, toDataUri }
validateManifest(manifest)ManifestValidationIssue[]

Checks a manifest for structural problems. Useful when authoring a custom asset package.

TypeManifestValidationIssue[]

マニフェストの型

マニフェストはただのデータなので、スロット名や色の一覧をハードコードせずに、直接読み取れます。

type HumationManifest = {
  schemaVersion: '1.0';
  template: { id: string; shortId: string; name: string; version: string; license: string };
  defaults: {
    selections: Record<SelectionSlotId, PartOptionId>;
    colors: Record<ColorSlotId, HexColor>;
    background: HexColor | 'transparent';
    crop: CropId;
  };
  colors: ColorSlot[];
  crops: Record<CropId, ViewBox>;
  selectionSlots: SelectionSlot[];
  uiGroups: UiGroup[];
  layerSlots: LayerSlot[];
  parts: PartOption[];
  aliases: AliasEntry[];
};

type PartOption = {
  id: PartOptionId;
  name?: string;
  aliases?: string[];
  selectionSlot: SelectionSlotId;
  uiGroups: UiGroupId[];
  layers: LayerFragment[];
  tags?: string[];
  deprecated?: boolean;
};

type ColorSlot = {
  id: ColorSlotId;
  label: string;
  default: HexColor;
  cssVariable: `--hm-${string}`;
  allowTransparent?: boolean;
};

type AliasEntry = {
  alias: string;
  targetId: PartOptionId;
  status: 'active' | 'deprecated';
  replacementAlias?: string;
};

aliases があるおかげで、以前に保存した値も引き続き使えます。非推奨のエントリには、後継を指す replacementAlias が入っています。詳しくは状態の保存を参照してください。

このページは役に立ちましたか?