@elastic/emotion-sheet

中文文档
1.4.1发布于 2026/03/05MITTypeScriptESM + CJS零依赖近 30 天下载 5.7万

准备用在Kibana的@emotion/sheet的伪造版本

中文使用文档
文档目录4 节
  1. 样式表
  2. 选项
  3. 方法
  4. 所有选项的示例

@ 有弹性/情绪表

一个叉子 @emotion/sheet 打算用在基巴纳.

Cs-in-js 库的样式表

yarn add @emotion/sheet
import { StyleSheet } from '@emotion/sheet'

const sheet = new StyleSheet({ key: '', container: document.head })

sheet.insert('html { color: hotpink; }')

说明: 这对服务器侧渲染没有用, 您应该单独执行 SSR

样式表

选项

type Options = {
  nonce?: string
  key: string
  container: Node
  speedy?: boolean
  prepend?: boolean
}

无

在工作表插入的每个样式标签上设置一个非ce 内容 安全政策。 。 。 .

集装箱

工作表会插入所有样式标记的 DOM 节点, 这对于向 Iframes 插入样式很有用 .

键

这将设定为 data-emotion 属性在被插入的样式标签上。 这有助于识别不同的工作表.

快点

这定义了规则的插入方式。 如果这是真的,规则将插入 insertRule 它非常快,但不允许规则在 DevTools 中编辑。 如果错误, 规则将被添加到样式元素的文本节点中, 它比插入规则慢得多, 但允许规则在 DevTools 中编辑 。 默认情况下,能够迅速生产,在发展中丧失能力.

预选

折旧: 请使用 insertionPoint 选项.

这定义了规则插入到 container。默认情况下,它们会被附加,但可以通过使用 prepend: true 选项.

插入点

这定义了特定的多姆节点,然后规则插入到 container您可以使用一个 meta 指定具体位置的标签 :

const head = document.querySelector('head')

// <meta name="emotion-insertion-point" content="">
const emotionInsertionPoint = document.createElement('meta')
emotionInsertionPoint.setAttribute('name', 'emotion-insertion-point')
emotionInsertionPoint.setAttribute('content', '')

head.appendChild(emotionInsertionPoint)

// the emotion sheets should be inserted right after the meta tag
const cache = createCache({
  key: 'my-app',
  insertionPoint: emotionInsertionPoint
})

function App() {
  return (
    <CacheProvider value={cache}>
      <Main />
    </CacheProvider>
  )
}

方法

插入

这种方法在文档中插入了一条规则。 这个 必须 否则,错误将会被抛入快速模式,在生产过程中默认允许.

冲出

此方法将删除插入文档的所有样式标记 .

水合盐

这种方法将给定的样式元素移入工作表的容器,并放入内部标签收集中。 可用于SSRed风格.

所有选项的示例

import { StyleSheet } from '@emotion/sheet'

const container = document.createElement('div')

document.head.appendChild(container)

const sheet = new StyleSheet({
  nonce: 'some-nonce',
  key: 'some-key',
  container
})

sheet.insert('html { color: hotpink; }')

sheet.flush()

谢谢

此样式表基于 闪光板样式 撰写人: 苏尼尔派。 。 。

版本与发布记录

@elastic/emotion-sheet 共发布 1 个版本,首次发布于 2026/03/05;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.4.1latest2026/03/058 个月前

关于 @elastic/emotion-sheet 的常见问题

@elastic/emotion-sheet 是什么?

准备用在Kibana的@emotion/sheet的伪造版本

如何安装 @elastic/emotion-sheet?

在项目目录运行 npm install @elastic/emotion-sheet,或使用 pnpm add / yarn add / bun add。

@elastic/emotion-sheet 支持 TypeScript 吗?

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

@elastic/emotion-sheet 支持 ESM 还是 CommonJS?

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

@elastic/emotion-sheet 可以商用吗?

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

@elastic/emotion-sheet 的下载量有多少?

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

@elastic/emotion-sheet 还在维护吗?

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