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

@vita-site/theme-default

v1.0.0

Published

default theme for VitaSite

Readme

@vita-site/theme-default

VitaSite 默认主题插件,提供开箱即用的文档站点外观与交互。

安装

pnpm add @vita-site/theme-default

快速开始

在 VitaSite 配置文件中使用默认主题:

import { defineConfig } from 'vita-site/server'
import { defaultTheme } from '@vita-site/theme-default/server'

export default defineConfig({
  plugins: [
    defaultTheme({
      title: 'My Docs',
      color: '#3b82f6'
    })
  ]
})

配置选项

DefaultThemeOptions

| 选项 | 类型 | 默认值 | 说明 | |-----------------|--------------------------------------------------------|--------|----------------------------------------| | title | string | - | 必填,站点标题,支持 i18n 翻译标识符 | | color | AnyColor | - | 必填,主题主色调,支持 HEX / RGB / HSL 等格式 | | schemeOptions | SchemeOptions | - | 配色方案选项,由 @zmaui/color 提供 | | useContainer | boolean | true | 是否启用容器插件(info/success/warning/error 块) | | logo | string \| null | null | 站点 Logo 图片地址 | | edit | string \| null | null | 仓库编辑地址前缀,配置后文档页显示"帮助改进此文档"链接 | | footer | string \| null | null | 站点页脚,支持 HTML 字符串 | | libLink | string \| null | null | 代码仓库链接,配置后导航栏显示 GitHub 图标 | | navLinks | NavLink[] \| { [lang: string]: NavLink[] } | [] | 导航栏链接,支持普通链接和下拉菜单 | | hero | HeroConfig \| { [lang: string]: HeroConfig } \| null | null | 首页 Hero 区域配置 | | features | Feature[] \| { [lang: string]: Feature[] } | [] | 首页 Features 区域配置 | | useSearch | boolean | true | 是否启用搜索插件 |

完整配置示例

defaultTheme({
  title: 'VitaSite',
  color: '#3b82f6',
  logo: '/logo.png',
  edit: 'https://github.com/username/repo/edit/main/docs/',
  footer: '<p>Released under the MIT License.</p>',
  libLink: 'https://github.com/username/repo',
  useContainer: true,
  useSearch: true,
  navLinks: [
    { text: '首页', link: '/' },
    { text: '指南', link: '/guide/quick-start' },
    {
      text: '资源',
      children: [
        { text: '组件', link: '/components/' },
        { text: 'GitHub', link: 'https://github.com/username/repo', isExternal: true }
      ]
    }
  ],
  hero: {
    name: 'VitaSite',
    text: '下一代文档站点框架',
    actions: [
      { text: '快速开始', link: '/guide/', theme: 'primary' },
      { text: 'GitHub', link: 'https://github.com/username/repo', theme: 'secondary' }
    ]
  },
  features: [
    { icon: '⚡', title: '极速构建', details: '基于 Vite 的即时热更新' },
    { icon: '📝', title: 'Markdown 驱动', details: '用 Markdown 编写文档,专注内容' },
    { icon: '🎨', title: '主题定制', details: '灵活的主题系统,轻松定制外观' }
  ]
})

多语言配置

navLinksherofeatures 均支持按语言分别配置:

defaultTheme({
  title: 'VitaSite',
  color: '#3b82f6',
  navLinks: {
    zh: [
      { text: '首页', link: '/' },
      { text: '指南', link: '/guide/' }
    ],
    en: [
      { text: 'Home', link: '/' },
      { text: 'Guide', link: '/guide/' }
    ]
  },
  hero: {
    zh: { name: 'VitaSite', text: '下一代文档站点框架' },
    en: { name: 'VitaSite', text: 'Next-gen doc site framework' }
  },
  features: {
    zh: [{ icon: '⚡', title: '极速构建', details: '基于 Vite 的即时热更新' }],
    en: [{ icon: '⚡', title: 'Fast Build', details: 'Instant HMR powered by Vite' }]
  }
})

类型定义

NavLink

interface NavLink {
  text: string
  link?: string
  children?: NavLinkChild[]
}

interface NavLinkChild {
  text: string
  link: string
  isExternal?: boolean // 是否新窗口打开,默认 false
}

HeroConfig

interface HeroConfig {
  name?: string   // Hero 标题,不配置则使用站点标题
  text?: string   // Hero 描述文本
  actions?: HeroAction[]
}

interface HeroAction {
  text: string
  link: string
  theme?: 'primary' | 'secondary' // 默认 'primary'
}

Feature

interface Feature {
  icon?: string    // 支持 emoji 或 HTML 字符串
  title: string
  details: string
  link?: string    // 点击后跳转
}

客户端 API

@vita-site/theme-default 导入客户端 API:

import { useTheme, setLangSelector } from '@vita-site/theme-default'
import type { ThemeManager, HeroConfig, Feature, NavLink, SiteData } from '@vita-site/theme-default'

useTheme()

获取主题管理器实例(单例),用于读取和切换明暗模式。

const theme = useTheme()

// 读取当前模式
theme.mode   // 'light' | 'dark' | 'system'
theme.bright // 'light' | 'dark'(实际亮度)

// 设置模式
theme.setMode('light')  // 切换到浅色模式
theme.setMode('dark')   // 切换到深色模式
theme.setMode('system') // 跟随系统

// 切换亮度(light ↔ dark)
theme.toggleBright()

注意:调用 toggleBright() 后主题不再跟随系统变化,需手动 setMode('system') 恢复。

setLangSelector(app, props)

自定义语言选择器,适用于多语言分别部署的场景。

import { defineConfig } from 'vita-site'
import { setLangSelector } from '@vita-site/theme-default'

export default defineConfig({
  enhanceApp(app, { i18n }) {
    const locales = [
      { name: 'English', id: 'https://en.example.com/' },
      { name: 'Chinese', id: 'https://zh.example.com/' }
    ]
    setLangSelector(app, {
      locales,
      // 必须使用 getter 保持响应性
      get activeId() {
        return i18n.lang.value === 'en' ? locales[0].id : locales[1].id
      },
      onSelect(id) {
        window.open(id, '_blank')
      }
    })
  }
})

内置功能

主题切换

默认提供明暗模式切换按钮,支持 light / dark / system 三种模式,用户偏好自动持久化到 localStorage(key: __THEME_MODE__)。

搜索

默认启用搜索功能(基于 @vita-site/plugin-search),支持:

  • 输入即搜
  • 搜索结果高亮
  • 键盘导航(↑↓ 选择、Enter 跳转、Esc 关闭)

通过 useSearch: false 可禁用。

容器块

默认启用容器插件(基于 @vita-site/plugin-container),支持在 Markdown 中使用:

::: info
信息提示
:::

::: success
成功提示
:::

::: warning
警告提示
:::

::: error
错误提示
:::

::: info:自定义标题
自定义标题的信息提示
:::

通过 useContainer: false 可禁用。

404 页面

自动注册 404 页面,当路由未匹配时显示,提供"返回首页"和"回退页面"操作。

导出入口

| 路径 | 说明 | |-----------------------------------|--------------------------------------------| | @vita-site/theme-default | 客户端 API(useThemesetLangSelector、类型导出) | | @vita-site/theme-default/server | 服务端插件(defaultTheme) |

License

MIT