@cssints/fluid

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

fluid() for cssints: clamp() between two widths, computed at build time, with the WCAG 1.4.4 zoom check

原始使用文档
文档目录3 节
  1. Rules
  2. Limits
  3. Credits

@cssints/fluid

Fluid lengths for cssints: fluid(min, max) is a length that is min on a narrow viewport, max on a wide one, and grows linearly between. The clamp() is computed at build time, and a range that breaks text resizing (WCAG 1.4.4) fails the build. Two value members of cssints/plugin scope() (fn({ args, value }), positional arguments and an options object). No runtime.

import { fontSize, padding } from "cssints" with { type: "cssints" };
import { fluid } from "@cssints/fluid" with { type: "cssints" };

// fluid(min, max, { from?, to?, zoom? }): from and to are the widths, 20rem and 80rem when left out
export const title = fontSize(fluid("1rem", "1.5rem"));
export const lead = fontSize(fluid("16px", "24px", { from: "40rem", to: "90rem" }));
// against the inline size of the nearest container instead of the viewport
export const card = padding(fluid.container("1rem", "2rem", { to: "60rem" }));

export const hero = fontSize(fluid("1rem", "4rem")); // build error: fails WCAG 1.4.4
._bkcdcr {
  font-size: clamp(1rem, 0.8333vw + 0.8333rem, 1.5rem);
}
._1wkr2lu {
  font-size: clamp(16px, 1vw + 0.6rem, 24px);
}
._ekb8uj {
  padding: clamp(1rem, 2.5cqi + 0.5rem, 2rem);
}

Rules

  • The math. The slope is (max - min) / (to - from) and the intercept min - slope × from, written clamp(min, <slope × 100>vw + <intercept>rem, max), rounded to 4 decimals. The intercept is in rem, so the value follows the user's font size. A max below min makes a value that shrinks: the bounds are sorted for clamp() and the slope is negative.
  • Units. min, max, from and to are px or rem, at 16px to the rem; the bounds keep the unit you wrote. Other units (em, vw, %, calc(), tokens) cannot be computed at build time: the build rejects them (the types check a non-negative <length>, and a grammar cannot name units).
  • WCAG 1.4.4. The check of fluid-tailwind: at 500% zoom the viewport is a fifth as wide and the rem five times larger, and the value must still reach twice its size at 100%, or text cannot be resized to 200%. It is checked at every width (at the four kinks of the two curves), and a failure is a build error at the call that names the width: cssints: fluid: 1rem to 4rem between 20rem and 80rem fails WCAG 1.4.4: at 80rem wide, 500% zoom gives 5rem, under twice 4rem; narrow the range of sizes or widen the widths. A ratio of max to min up to about 2.5 passes with the default widths.
  • A length. The result is a Typed OM length (CSSStyleValue<"length">): it goes where a length goes, in the types, and color(fluid(...)) is an error. It can be an argument of clamp(), min() and max() of cssints.
  • Build errors (at the call): a unit that is not px or rem, min equal to max, from not below to, a failed 1.4.4 check, and the grammar of the arguments, by position (fluid.container(2): unexpected "red" in "red", expected <length>).

Limits

  • The 1.4.4 check runs on every call unless { zoom: false } is passed, which is for lengths that are not text (a padding, a gap): padding(fluid("1rem", "4rem", { zoom: false })).
  • fluid.container() uses the same check with the container's width in place of the viewport's, which holds when the container scales with the viewport.
  • No defaults from a token set, and no token as an argument: a token is a var(), which the build cannot compute with.
cd packages/fluid && bun run test   # fixtures through the engine (output, errors), and the type test via bun run typecheck

Credits

The WCAG 1.4.4 check follows fluid-tailwind (MIT, Maxwell Barvian). The check is written here; no code is copied.

版本与发布记录

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

版本发布日期距今
0.35.1latest2026/11/073 天前
0.35.02026/11/073 天前
0.34.02026/11/073 天前
0.33.02026/11/046 天前
0.32.02026/11/046 天前
0.31.02026/11/047 天前

关于 @cssints/fluid 的常见问题

@cssints/fluid 是什么?

fluid() for cssints: clamp() between two widths, computed at build time, with the WCAG 1.4.4 zoom check

如何安装 @cssints/fluid?

在项目目录运行 npm install @cssints/fluid,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:cssints(^0.35.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cssints/fluid 支持 TypeScript 吗?

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

@cssints/fluid 支持 ESM 还是 CommonJS?

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

@cssints/fluid 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cssints/fluid 可以商用吗?

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

@cssints/fluid 的下载量有多少?

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

@cssints/fluid 还在维护吗?

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