@fungi.computer/sprite-zdog

中文文档
0.3.2发布于 2026/11/09MITTypeScriptES Module近 30 天下载 6999

Optional Zdog avatar renderer and portable scene authoring

原始使用文档
文档目录7 节
  1. Install or set up
  2. Quick start
  3. Core concepts
  4. API reference
  5. Examples and checks
  6. Limits and errors
  7. Contribute and license

Sprite Zdog (@fungi.computer/sprite-zdog)

Sprite Zdog is an optional Canvas renderer for characters built with Zdog. It also provides built-in characters and tools for authoring a portable character document that Sprite can load.

Install or set up

npm install @fungi.computer/sprite-zdog

The package ships ESM only and depends on Effect, Zod, animejs, zdog, and Sprite at runtime. Add it only to a host that already uses Sprite and renders with Zdog. The parent Sprite host still owns the player and asset policy. The root entrypoint exports the Zdog renderer. ./author and ./portable support scene authoring. ./builtins (and the individual ./builtins/base, ./builtins/mushroom, ./builtins/cat, and ./builtins/burger subpaths) expose the bundled authoring definitions. ./mushroom, ./cat and ./burger provide ready-to-load local characters, each with its document and renderer. ./catalog and ./avatar provide pure avatar validation and derivation without importing the Canvas renderer.

Quick start

This illustrative example installs the bundled mushroom as a local character and renders it with the Sprite React component:

import { createSprite } from "@fungi.computer/sprite";
import { Sprite } from "@fungi.computer/sprite/react";
import { builtinCharacters } from "@fungi.computer/sprite-zdog";

const service = createSprite({
  characters: builtinCharacters,
});

function Character() {
  return (
    <Sprite
      service={service}
      src={{ local: "mushroom" }}
      activity="thinking"
      role="img"
      aria-label="Mushroom character"
    />
  );
}

builtinCharacters provides lazy mushroom, cat and burger loaders without remote asset access. The bundled character supplies its document and Zdog renderer together. The tests cover built-in characters and player integration in src/builtins.test.ts and src/mushroom.test.ts.

Core concepts

The package root exports the Zdog renderer as the default export. To render a served character document whose renderer is zdog, register it with Sprite. This illustrative configuration uses assetPolicy as the host's configured Sprite asset policy:

const service = createSprite({
  assets: assetPolicy,
  renderers: {
    zdog: () => import("@fungi.computer/sprite-zdog"),
  },
});

assetPolicy stands for the host's configured Sprite asset policy. Admit the document's origin and set its byte and request limits. A local character does not need remote asset access.

For authoring, defineSprite validates a trusted scene definition, check returns a compact author-time summary, and toCharacter converts the definition into a JSON character document. The resulting document contains data, not executable authoring code. @fungi.computer/sprite-zdog/builtins exports the base, mushroom, cat, and burger characters.

For stored avatars, import avatarSchema or parseAvatar(data) from @fungi.computer/sprite-zdog/avatar. These validate against the built-in character controls and expressions, rather than checking only the envelope. deriveAgentAvatar(member, agentColors, seed, avoid?) uses that same catalog; agentColors is "keep" or "shift". avatarCatalog is also available from ./catalog for callers using Sprite's catalog-parameterized helpers. memberAvatarSchema validates the strict {avatar, agentColors} preference; defaultMemberAvatar supplies the uncustomized mushroom with colour shift on.

API reference

See the generated package API, authoring API, and portable document API. The package also exposes individual built-ins through @fungi.computer/sprite-zdog/builtins/<name>.

Examples and checks

The local Sprite stories live in src/*.stories.tsx. Run the package tests with:

pnpm --filter @fungi.computer/sprite-zdog test

The authoring and portable-runtime tests cover definition validation, serialization, decoding, and cleanup.

Limits and errors

The Zdog renderer requires a browser window and canvas. It decodes the character's Zdog data before creating a renderer and removes its canvas and animation resources when the player selection closes. Invalid scene data, missing expressions, or invalid palette colors fail the selection.

The authoring callback is trusted code that runs while creating the portable document. Runtime rendering reads the resulting JSON data. It does not execute the authoring callback. Served documents still use Sprite's host-owned origin and asset limits.

Contribute and license

Sprite Zdog is MIT licensed. See LICENSE and THIRD_PARTY_NOTICES.

版本与发布记录

@fungi.computer/sprite-zdog 共发布 7 个版本,首次发布于 2026/10/15;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.3.2latest2026/11/097 天前
0.3.12026/11/087 天前
0.3.02026/10/3016 天前
0.2.02026/10/2323 天前
0.1.02026/10/1729 天前
0.0.12026/10/151 个月前

关于 @fungi.computer/sprite-zdog 的常见问题

@fungi.computer/sprite-zdog 是什么?

Optional Zdog avatar renderer and portable scene authoring

如何安装 @fungi.computer/sprite-zdog?

在项目目录运行 npm install @fungi.computer/sprite-zdog,或使用 pnpm add / yarn add / bun add。

@fungi.computer/sprite-zdog 支持 TypeScript 吗?

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

@fungi.computer/sprite-zdog 支持 ESM 还是 CommonJS?

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

@fungi.computer/sprite-zdog 可以商用吗?

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

@fungi.computer/sprite-zdog 的下载量有多少?

根据 npm 官方下载统计,@fungi.computer/sprite-zdog 在 2026/10/16 – 2026/11/14 这 30 天内被下载 6,999 次,日均约 233 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fungi.computer/sprite-zdog 还在维护吗?

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