@debuffjp/ui

中文文档
0.33.0发布于 2026/11/11MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 8788

Screen transitions, menus and panels for debuff

原始使用文档
文档目录3 节
  1. Layout
  2. API
  3. Before 0.19

@debuffjp/ui

The screens around your game: fades between areas, title and pause menus, framed panels. No dependencies, and each export can be used on its own. Everything runs on update(dt), so replays and scenarios stay deterministic.

import { Menu, Transition } from "@debuffjp/ui";

const fade = new Transition({ duration: 0.35, color: "#1a1020" });
let volume = 10;
const pause = new Menu(
  [
    { label: "resume", onSelect: () => (paused = false) },
    { label: "volume", value: () => `${volume}`, change: (d) => (volume = Math.max(0, Math.min(10, volume + d))) },
    { label: "restart", onSelect: () => fade.run(reset) },
  ],
  { actions: { up: "up", down: "down", confirm: "jump", back: "pause", left: "left", right: "right" } },
);

// every step
fade.update(dt);
if (fade.blocking) return;
if (paused) pause.update(input);

// render, after the world
if (paused) pause.drawPanel(draw, game.width / 2, game.height / 2, { title: "paused" });
fade.draw(draw, 0, 0, game.width, game.height);

Layout

Text is measured with draw.measure, so nothing is positioned by guesswork:

  • The cursor has its own column. Labels never shift when focus moves.
  • Values (value: () => string) are right-aligned in a column of their own.
  • drawPanel centres the frame on a point, mirrors the cursor column so the labels and the title share a centre, and pads evenly on all sides.
  • Every position snaps to whole pixels, so pixel fonts stay crisp.

API

  • Transition: run(swap?) → covers the screen, calls swap once fully covered, then uncovers. update(dt), draw(draw, x, y, w, h), stop(), active, blocking, cover, inspect()
  • Menu: new Menu(items, { actions, onBack, wrap }), update(input) (with input.pointer, a tap selects the row under it; on a value row the left half lowers and the right half raises), tap(x, y), move(delta), select(), measure(draw, style), draw(draw, x, y, style), drawPanel(draw, cx, cy, style), focused, inspect()
    • items: { label, onSelect?, disabled?, value?, change? }
    • style: font, color, focusColor, disabledColor, gap (3), align (left/center), cursor (>), cursorGap (4), valueGap (12), highlight (a jelly pill behind the focused row; on with debuff's look, false turns it off); panel adds title, titleFont, titleColor, titleGap (6), borders, fill, padding, radius
  • panel(draw, x, y, w, h, borders, fill?, chamfer?, radius?): 1px rings, outermost first, then the fill; radius rounds each corner, chamfer cuts it by that many pixels instead
  • panelAround(draw, cx, cy, w, h, { borders, fill, padding, radius, chamfer, shadow, shadowOffset }): a panel fitted around content, centred and pixel-snapped; returns the content's top-left
  • bar(draw, x, y, w, h, value, { segments, gap, fill, empty }): a segmented meter; value (0-1) lights whole cells only, all the same width; returns the width used

Out of the box, panels, menus and bars use neutral: plain greys, a white focus, 4px corners and a thin border, so they sit under your game's art without bringing a style of their own. Set your own borders or fill, or your own color, and you get exactly what you set.

Looks are style objects you spread in:

LookWhat it isBars
neutralThe default: dark greys, white focusneutralBar
neutralLightThe same for light games: a white panel, dark textneutralLightBar
squishdebuff's own look: a round dark-olive panel with no outline, lime focus, and a highlight that squashes when focus movessquishBar
import { squish, squishBar } from "@debuffjp/ui";
pause.drawPanel(draw, game.width / 2, game.height / 2, { ...squish, title: "paused" });
bar(draw, 8, 8, 60, 4, hp / maxHp, squishBar);

Before 0.19

Up to 0.18, panels and menus used debuff's own look ("squish") out of the box: a soft, round-cornered dark panel with no outline, light labels, lime focus and a jelly highlight that squashes when focus moves. Bars defaulted to lime cells on dark olive. A style that set its own borders or fill kept exactly what it set. debuffFrame was that look as a style object, to spread into anything:

import { debuffFrame } from "@debuffjp/ui";
pause.drawPanel(draw, game.width / 2, game.height / 2, { ...debuffFrame, title: "paused" });

From 0.19, spread squish (and pass squishBar to bar) where you relied on that default. debuffFrame still works, deprecated, as squish's frame alone without its menu colours.

版本与发布记录

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

版本发布日期距今
0.33.0latest2026/11/11今天
0.32.02026/11/074 天前
0.31.12026/11/065 天前
0.31.02026/11/065 天前
0.30.02026/11/056 天前
0.29.22026/11/056 天前

关于 @debuffjp/ui 的常见问题

@debuffjp/ui 是什么?

Screen transitions, menus and panels for debuff

如何安装 @debuffjp/ui?

在项目目录运行 npm install @debuffjp/ui,或使用 pnpm add / yarn add / bun add。

@debuffjp/ui 支持 TypeScript 吗?

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

@debuffjp/ui 支持 ESM 还是 CommonJS?

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

@debuffjp/ui 可以商用吗?

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

@debuffjp/ui 的下载量有多少?

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

@debuffjp/ui 还在维护吗?

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