@blobatar/svelte

中文文档
2.7.0发布于 2026/08/29MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 5269

Svelte adapter for blobatar — deterministic geometric avatars.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Following the pointer
  4. What this package ships
  5. Props
  6. License

@blobatar/svelte

Svelte adapter for blobatar — deterministic geometric avatars.

Installation

bun add @blobatar/svelte blobatar

Usage

<script>
  import { Blobatar } from "@blobatar/svelte";
</script>

<Blobatar name="username" />

Following the pointer

The eyes can track the cursor. That layer is the one part of the motion system that needs JavaScript, so it is a separate subpath and costs nothing in your bundle unless you import it:

<script>
  import { Blobatar } from "@blobatar/svelte";
  import { gaze } from "@blobatar/svelte/gaze";
  import "blobatar/motion.css";
  import "blobatar/gaze.css"; // required — the eyes hold still without it

  const eyes = gaze({ travel: 3, target: "pointer" });
</script>

<Blobatar {@attach eyes} name="[email protected]" animate="always" size={200} />

An attachment rather than an action, and it needs Svelte 5.29 or newer: an action can only be written on the element it applies to, and the element here belongs to <Blobatar>. Attachments cross that boundary, which is what makes this a two-line integration instead of a reason to stop using the component.

travel is the excursion, and it is what opts a blobatar into the layer: --mo-track-travel starts at 0px, so a page with the stylesheet loaded and the excursion set nowhere has a driver running and no eyes moving. It is in viewBox units — the blobatar is 100 across, so 3 is 3% of the face — and about 1.5 to 4 reads well. Leave it out and the stylesheet owns it instead, which is the better route for a whole field of blobatars, since the property inherits, or for anything responsive:

.hero .mo-eyes { --mo-track-travel: 3px; }

Pick one, not both. travel is written inline on the eyes themselves, so here it beats a rule like that one — the opposite of what the React hook does, and for a Svelte-specific reason: Svelte rewrites the <svg>'s whole style attribute whenever a prop changes, so a property written there would vanish the first time the name did.

Everything in the options is read once, when the blobatar mounts. Aiming that changes is lookAt, in an effect of your own:

const eyes = gaze({ travel: 3 });
$effect(() => eyes.lookAt(watching ? "pointer" : "rest"));

Both take the same things: a point in client coordinates, an element (eyes.lookAt(button)), "pointer" for the cursor, "rest" to park the eyes in the middle without resuming the idle glance, or null for nothing, which hands it back. The last thing asked for wins, whichever asked, and aiming before the blobatar has mounted is remembered rather than dropped — so a caret can be driven straight through lookAt with no re-render per keystroke.

Hold the result in a const. Calling gaze() inline in the template rebuilds the driver whenever the state it reads changes, and a new driver starts with the eyes at centre.

What this package ships

Svelte, not JavaScript. A Svelte component only becomes renderable code inside your compiler, so there is no build output here and none is invented — the package is reachable through the svelte export condition, which every Svelte toolchain applies (vite-plugin-svelte, SvelteKit, svelte-check). A bundler configured without it will fail to resolve this package rather than hand you a file it cannot execute.

Svelte 5 is required: the component is written with runes.

Props

PropTypeDescription
namestringRequired. Who the blobatar is for.
sizenumberWidth and height in pixels.
animate"always" | "hover"Enable animation.
backgroundstring | falseBackground style.
palettestring[]Color palette.
huenumberPin the hue.
tonenumberPin the tone.
normalizebooleanNormalize the name.
contrastbooleanEnable contrast.
titlestringAccessible title.
expressionExpressionExpression to render.
traitsTraitOverridesOverride specific traits.

License

MIT

版本与发布记录

@blobatar/svelte 共发布 6 个版本,首次发布于 2026/08/20;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.7.0latest2026/08/292 个月前
2.6.02026/08/292 个月前
2.5.02026/08/242 个月前
2.4.02026/08/212 个月前
2.3.12026/08/212 个月前
2.3.02026/08/202 个月前

关于 @blobatar/svelte 的常见问题

@blobatar/svelte 是什么?

Svelte adapter for blobatar — deterministic geometric avatars.

如何安装 @blobatar/svelte?

在项目目录运行 npm install @blobatar/svelte,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:blobatar(2.x)、svelte(>=5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@blobatar/svelte 支持 TypeScript 吗?

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

@blobatar/svelte 支持 ESM 还是 CommonJS?

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

@blobatar/svelte 可以商用吗?

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

@blobatar/svelte 的下载量有多少?

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

@blobatar/svelte 还在维护吗?

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