npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@oiij/css-render

v0.0.13

Published

A Vue Composable for CssRender

Downloads

53

Readme

@oiij/css-render

NPM version MIT-license

简介

Use CssRender 是一个强大的 CSS 渲染工具,为 Vue 3 应用提供动态样式渲染能力,帮助开发者更灵活地管理组件样式。

特点

🎨 动态渲染

  • 🔧 支持动态生成和管理样式
  • 📡 提供简洁的 API 接口
  • ⚡ 高效的样式注入机制

🏗️ BEM 命名规范

  • ✅ 支持 BEM(Block-Element-Modifier)命名规范
  • ⚙️ 可自定义命名空间和前缀
  • 🔤 自动生成符合规范的类名

🔒 类型安全

  • 📝 完整的 TypeScript 类型定义
  • 💡 提供准确的类型推断和代码提示
  • ⚡ 支持 Vue 3 的 Composition API 类型系统

🖥️ SSR 支持

  • ✅ 支持服务端渲染(SSR)
  • 🔄 自动适配 SSR 环境

安装

# 使用 pnpm
pnpm add @oiij/css-render

# 使用 npm
npm install @oiij/css-render

# 使用 yarn
yarn add @oiij/css-render

依赖

  • vue: ^3.0.0
  • css-render: ^0.15.0
  • @css-render/plugin-bem: ^0.15.0
  • @css-render/vue3-ssr: ^0.15.0

示例

基础使用

<script setup>
import { useBem, useStyle } from '@oiij/css-render'

const { cssr, plugin } = useBem({
  namespace: 'my',
})
const { c, cB, cE, cM } = { ...cssr, ...plugin }

// 生成样式
const style = c([
  cB('button', {
    padding: '10px 20px',
    borderRadius: '4px',
    backgroundColor: '#409eff',
    color: '#fff',
  }, [
    cM('primary', {
      backgroundColor: '#67c23a',
    }),
    cM('danger', {
      backgroundColor: '#f56c6c',
    }),
  ]),
])

useStyle('my-button', style)
</script>

<template>
  <button class="my-button">
    默认按钮
  </button>
  <button class="my-button my-button--primary">
    主要按钮
  </button>
  <button class="my-button my-button--danger">
    危险按钮
  </button>
</template>

完整 BEM 示例

<script setup>
import { useBem, useStyle } from '@oiij/css-render'

const { cssr, plugin } = useBem({
  namespace: 'app',
  blockPrefix: '.app-',
  elementPrefix: '__',
  modifierPrefix: '--',
})
const { c, cB, cE, cM } = { ...cssr, ...plugin }

const style = c([
  cB('card', {
    padding: '20px',
    borderRadius: '8px',
    boxShadow: '0 2px 12px rgba(0, 0, 0, 0.1)',
  }, [
    cE('header', {
      marginBottom: '16px',
      fontSize: '18px',
      fontWeight: 'bold',
    }),
    cE('body', {
      fontSize: '14px',
      color: '#666',
    }),
    cE('footer', {
      marginTop: '16px',
      textAlign: 'right',
    }),
    cM('bordered', {
      border: '1px solid #eee',
    }),
  ]),
])

useStyle('app-card', style)
</script>

<template>
  <div class="app-card app-card--bordered">
    <div class="app-card__header">
      卡片标题
    </div>
    <div class="app-card__body">
      卡片内容
    </div>
    <div class="app-card__footer">
      卡片底部
    </div>
  </div>
</template>

API

useBem(options?)

创建 BEM 工具对象。

参数

| 参数 | 类型 | 默认值 | 说明 | | --------- | ------------ | ------ | ------------ | | options | BemOptions | - | BEM 配置选项 |

BemOptions

| 选项 | 类型 | 默认值 | 说明 | | ---------------- | -------- | ------------------ | ---------- | | namespace | string | 'n' | 命名空间 | | blockPrefix | string | '.${namespace}-' | 块前缀 | | elementPrefix | string | '__' | 元素前缀 | | modifierPrefix | string | '--' | 修饰符前缀 |

返回值

| 属性 | 类型 | 说明 | | ---------------- | -------------------- | --------------- | | namespace | string | 命名空间 | | blockPrefix | string | 块前缀 | | elementPrefix | string | 元素前缀 | | modifierPrefix | string | 修饰符前缀 | | cssr | CssRenderInstance | CSS Render 实例 | | plugin | CssRenderBemPlugin | BEM 插件 |

useStyle(mountId, style)

挂载样式。

参数

| 参数 | 类型 | 说明 | | --------- | -------- | --------------- | | mountId | string | 样式挂载的 ID | | style | CNode | CSS Render 节点 |

类型定义

import type { CNode, CssRenderInstance } from 'css-render'

export type CssRenderBemPlugin = ReturnType<typeof BemPlugin> & {
  __?: 'css-render-bem'
}

export type BemOptions = {
  /**
   * 命名空间
   * @default 'n'
   */
  namespace?: string
  /**
   * 块前缀
   * @default '.${namespace}-'
   */
  blockPrefix?: string
  /**
   * 元素前缀
   * @default '__'
   */
  elementPrefix?: string
  /**
   * 修饰符前缀
   * @default '--'
   */
  modifierPrefix?: string
}

export type UseBemReturn = {
  namespace: string
  blockPrefix: string
  elementPrefix: string
  modifierPrefix: string
  cssr: CssRenderInstance
  plugin: CssRenderBemPlugin
}

export declare function useBem(options?: BemOptions): UseBemReturn
export declare function useStyle(mountId: string, style: CNode): void

在线文档

在线文档