@cssints/layout

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

Layout primitives for cssints: stack, cluster, sidebar, switcher, cover and autoGrid as chain members

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

@cssints/layout

Layout primitives for cssints, after Every Layout and smolcss: stack(), cluster(), sidebar(), switcher(), cover() and autoGrid(). Each one is a chain member of cssints/plugin scope(): a call gives the primitive's kernel classes, and each method sets one custom property. No runtime, no media queries: the layouts respond to the space they have.

import { cn, p } from "cssints" with { type: "cssints" };
import {
  autoGrid,
  cluster,
  sidebar,
  stack,
  switcher,
} from "@cssints/layout" with { type: "cssints" };

export const page = cn(stack().gap(6), p(4));
export const toolbar = cluster().gap(2).justify("space-between");
export const layout = sidebar().width("20rem").content("50%").gap(4);
export const buttons = switcher().threshold("30rem");
export const cards = autoGrid().min("16rem").gap(4);
@layer _.k {
  ._layout-stack-core {
    gap: var(--layout-stack-gap);
    --layout-stack-gap: 1rem;
    display: flex;
    flex-direction: column;
  }
  ._layout-sidebar-core {
    gap: var(--layout-sidebar-gap);
    --layout-sidebar-gap: 1rem;
    --layout-sidebar-width: auto;
    --layout-sidebar-content: 50%;
    --layout-sidebar-ff: 1 1 var(--layout-sidebar-width);
    --layout-sidebar-fm: auto;
    --layout-sidebar-lf: 999 1 0;
    --layout-sidebar-lm: var(--layout-sidebar-content);
    display: flex;
    flex-wrap: wrap;
  }
  ._layout-sidebar-core > :first-child {
    flex: var(--layout-sidebar-ff);
    min-inline-size: var(--layout-sidebar-fm);
  }
  ._layout-sidebar-core > :last-child {
    flex: var(--layout-sidebar-lf);
    min-inline-size: var(--layout-sidebar-lm);
  }
  ._layout-switcher-core > * {
    flex-grow: 1;
    flex-basis: calc((var(--layout-switcher-threshold) - 100%) * 999);
  }
  ._layout-grid-core {
    gap: var(--layout-grid-gap);
    --layout-grid-min: 16rem;
    --layout-grid-gap: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(var(--layout-grid-min), 100%), 1fr));
  }
  /* ... the other kernels */
}
@layer _.a {
  ._x {
    --layout-stack-gap: 1.5rem;
  }
  ._y {
    --layout-sidebar-width: 20rem;
  }
  /* ... one class per method and value */
}

The primitives

PrimitiveMethods (each once, in any order)What it is
stack()gap (1rem)a flex column with a gap
cluster()gap (1rem), justify (flex-start), align (center)a wrapping row: tags, buttons, a toolbar
sidebar()side (left), width (auto, its content), content (50%), gap (1rem)two children side by side; they stack when the content child would be narrower than content of the container
switcher()threshold (30rem), gap (1rem)its children in one row while the container is wider than threshold, else one column (Heydon Pickering's Flexbox Holy Albatross)
cover()minHeight (100vh), gap (1rem)a flex column of a min height with its content centred vertically
autoGrid()min (16rem), gap (1rem)as many columns of at least min as fit, repeat(auto-fit, minmax(min(min, 100%), 1fr)), which never overflows
  • Values. gap takes a length or a percentage, and a lone number is a step of the spacing scale (0.25rem), as in padding. width, minHeight and min take a length or a percentage, threshold a length, content a percentage from 0 to 100. justify is start | end | center | space-between | space-around | space-evenly, align is start | end | center | baseline | stretch, side is left | right. Tokens go where a length does. The types check each method, and the build checks it again (ranges included: content("120%") fails at the call).
  • Conditions. A method in media(), hover() and the others sets the custom property under that condition: media("(width >= 40rem)")(stack().gap(8)).

Rules

  • Kernels. Each primitive is one kernel in layer _.k, once, written as styles: the defaults of its custom properties on the element (vars()), the container's properties and, for sidebar() and switcher(), the rules of the children (nest("& > *")). A call is its class (_layout-stack-core), and each method one class in _.a (or _.b under a condition), which wins over the defaults.
  • Conflicts. A cn() that holds a primitive and a property its core sets is a build error at the call, derived from the kernel: cn(stack(), display("grid")) is cssints: layout: kernel stack-core sets display, flex-direction, gap (this style also sets display), and cn(autoGrid(), rowGap("1rem")) fails as well (a longhand of gap). Padding, sizes and colours do not conflict, nor do the properties the kernel sets on the children (cn(switcher(), flexGrow(0)) is fine). Conflicts with an opaque runtime string in cn() are not seen, as for any plugin.
  • No leak into nested primitives. The defaults are set on every primitive, so a stack() inside a stack().gap(8) has a gap of 1rem, not 2rem.
  • The children. sidebar() sizes its first and last child (the first is the sidebar, or the last with side("right"); the order in the DOM stays the reading order), switcher() every child. Those rules are one class strong in _.k, so a class on a child wins over them.

Limits

  • sidebar() and switcher() pass their settings to the children by inheritance. A child that is itself a sidebar (or a switcher) reads its own defaults or settings in its role as a child, not its parent's: wrap it in a plain element when the parent's values are not the defaults.
  • cover() centres all its content; Every Layout's centred child between a header and a footer is margin-block: auto on that child, which you write yourself.
  • Not here: Every Layout's center, box, frame, reel, imposter and icon (box and center are a few plain properties; frame() in cssints is the concentric radius), and the switcher's limit on the number of items.
cd packages/layout && bun run test   # fixtures through the engine (output, conflicts, build errors), and the type test via bun run typecheck

Credits

The primitives are those of Every Layout (Heydon Pickering and Andy Bell) and smolcss (Stephanie Eckles); the switcher is Heydon Pickering's Flexbox Holy Albatross. The CSS is written here as styles of scope(); no code is copied.

版本与发布记录

@cssints/layout 共发布 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/layout 的常见问题

@cssints/layout 是什么?

Layout primitives for cssints: stack, cluster, sidebar, switcher, cover and autoGrid as chain members

如何安装 @cssints/layout?

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

@cssints/layout 支持 TypeScript 吗?

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

@cssints/layout 支持 ESM 还是 CommonJS?

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

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

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

@cssints/layout 可以商用吗?

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

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

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

@cssints/layout 还在维护吗?

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