# @guardian/src-foundations 中文文档

规范地址：https://npmcn.com/package/%40guardian/src-foundations/

版本：3\.13\.0
npm 元数据更新时间：2025-10-28T11:48:29.752Z
中文译文更新时间：2026-11-17T07:21:22.812Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40guardian/src-foundations
原文对照：https://npmcn.com/package/%40guardian/src-foundations/?lang=original
项目主页：https://github.com/guardian/source#readme
源码仓库：https://github.com/guardian/source

弃用说明：This package has been replaced by @guardian/source-foundations\.

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：299 kB，206 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2019-08-07T14:28:11.478Z
- 最新版本发布：2022-01-18T10:31:46.945Z
- 近 30 天下载量：5251（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：168（近 12 个月 0 个）

## 中文简介

守护神的地基就是我们所有视觉设计都是从这些地基上构建的原子. 它们打算与情感等CSS-in-JS图书馆一起使用.

## 安装

```sh
npm install @guardian/src-foundations
```

也可以使用：`pnpm add @guardian/src-foundations`、`yarn add @guardian/src-foundations`、`bun add @guardian/src-foundations`

## README

# 基金会

守护神的地基就是我们所有视觉设计都是从这些地基上构建的原子. 它们打算与情感等CSS-in-JS图书馆一起使用.

## 安装

```sh
$ yarn add @guardian/src-foundations
```

## 使用

### [调色板](https://www.theguardian.design/2a1e5182b/p/28d868-overview)

```ts
import { background } from '@guardian/src-foundations/palette';

const backgroundColor = css`
    background-color: ${background.primary};
`;
```

### [类型](https://www.theguardian.design/2a1e5182b/p/930d69-typography/b/78d0d9)

```ts
import { headline, body, textSans } from '@guardian/src-foundations/typography';

const h1 = css`
    ${headline.large({ fontWeight: 'bold' })};
`;

const p = css`
    ${body.main()};
`;

const copyright = css`
    ${textSans.xsmall()};
`;
```

### 媒体查询

```ts
import { from, until, between } from '@guardian/src-foundations/mq';

const styles = css`
    padding: 0 10px;

    ${from.mobileLandscape} {
        padding: 0 20px;
    }

    ${between.phablet.and.desktop} {
        padding: 0 32px;
    }

    ${until.wide} {
        padding: 0 40px;
    }
`;
```

### [大小](https://www.theguardian.design/2a1e5182b/p/38d9a9-overview)

```ts
import { width, height } from '@guardian/src-foundations/size';

const checkbox = css`
    width: ${width.inputXsmall}px;
    height: ${height.inputXsmall}px;
`;
```

### [可视隐藏](https://www.theguardian.design/2a1e5182b/p/6691bb-accessibility/t/1285a8)

对于不应在视觉用户看来,但对辅助技术用户有用的元素.

```ts
import { visuallyHidden } from '@guardian/src-foundations/accessibility';

const label = css`
    ${visuallyHidden};
`;
```

### [聚焦光环](https://www.theguardian.design/2a1e5182b/p/6691bb-accessibility/t/24562a)

此混音提供了 [明确焦点状态](https://theguardian.design/2a1e5182b/p/08dc26-interaction-states/t/314e46) 用于可能获得键盘焦点的元素.

```ts
import { focusHalo } from '@guardian/src-foundations/accessibility';

const input = css`
    ${focusHalo};
    width: 200px;
    height: 44px;
`;
```

### [说明 Id](https://theguardian.design/2a1e5182b/p/6691bb-accessibility/t/062b61)

使用元素的标识并生成新标识的函数。 这应定为 描述第一个元素的元素的标识 。 生成的ID也应传递给 页:1 [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute) 属性.

```tsx
import { descriptionId } from '@guardian/src-foundations/accessibility';

const Form = () => {
    const id = 'first_name';
    return (
        <form>
            <input id={id} type="text" aria-describedby={descriptionId(id)} />
            <p class="error" id={descriptionId(id)} />
        </form>
    );
};
```

## 常见问题

### @guardian/src-foundations 是什么？

守护神的地基就是我们所有视觉设计都是从这些地基上构建的原子\. 它们打算与情感等CSS-in-JS图书馆一起使用\.注意：该包已被作者标记为弃用——This package has been replaced by @guardian/source-foundations\.

### 如何安装 @guardian/src-foundations？

在项目目录运行 npm install @guardian/src-foundations，或使用 pnpm add / yarn add / bun add。

### @guardian/src-foundations 支持 TypeScript 吗？

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

### @guardian/src-foundations 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @guardian/src-foundations 可以商用吗？

@guardian/src-foundations 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @guardian/src-foundations 的下载量有多少？

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

### @guardian/src-foundations 还在维护吗？

最新版本 3\.13\.0 发布于 2022/01/18（4 年前）；至今共发布 168 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/08/07。作者已将其标记为弃用，新项目建议寻找替代方案。

