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

@anker-in/business

v0.0.0

Published

AnkerDTC React component library business

Downloads

108

Readme

AnkerDTC Business Components

企业级可复用业务组件库 - 为多项目提供统一、高效的业务功能组件解决方案

📋 项目简介

AnkerDTC Business Components 是一个基于 React + TypeScript + Tailwind CSS 构建的企业级业务组件库,专注于提供跨项目可复用的业务功能组件。首期产品为 DemoRoom 预约功能组件,后续将持续扩展更多业务场景组件。

🎯 核心亮点

1. 🚀 原生集成,零侵入架构

技术优势

  • 真正的组件化:作为原生 React 组件,无需额外的运行时容器
  • TypeScript 全栈支持:完整的类型定义,开发时即可发现错误
  • Tree-Shaking 优化:未使用的组件不会被打包,最小化体积影响
  • 零依赖冲突:使用 peerDependencies 模式,与宿主项目共享 React 生态
// 像使用普通组件一样简单
import { DemoRoom } from '@anker-dtc/ui'

function App() {
  return <DemoRoom />
}

对比竞品 | 特性 | AnkerDTC | 脚本注入方案 | iframe 方案 | |------|----------|-------------|------------| | 集成方式 | 原生组件导入 | 全局脚本注入 | iframe 嵌入 | | 代码侵入性 | ✅ 零侵入 | ⚠️ 污染全局作用域 | ⚠️ 需要额外容器 | | TypeScript 支持 | ✅ 完整类型 | ❌ 无类型定义 | ❌ 无类型定义 | | Tree-Shaking | ✅ 支持 | ❌ 全量加载 | ❌ 全量加载 | | 首屏加载 | ✅ 按需加载 | ⚠️ 阻塞加载 | ⚠️ 额外请求 |

2. ⚡️ 性能优化,极致体验

构建产物优化

# UI 组件包体积
@anker-dtc/ui
├── index.mjs (ESM)      2.4 KB (gzipped: ~1.1 KB)
├── index.js (CJS)       2.5 KB
├── styles.css           5.1 KB (gzipped: ~1.2 KB)
└── types                完整 TypeScript 类型定义

# Hooks 包体积
@anker-dtc/hooks
└── 总计                 3.1 KB (gzipped: ~1.4 KB)

技术实现

  • ESM + CJS 双构建:支持现代构建工具的最佳优化
  • CSS 按需加载:样式文件独立,可选择性引入
  • 代码分割:支持多入口导出,精确控制加载内容
  • 缓存友好:稳定的构建输出,充分利用浏览器缓存
// 精确导入,只加载需要的组件
import { DemoRoom } from '@anker-dtc/ui/demo-room'  // 仅 ~697B
import { Button } from '@anker-dtc/ui/button'       // 按需加载

性能对比

| 指标 | AnkerDTC | 脚本注入 | iframe | |------|----------|---------|--------| | 初始加载 | ~2.3 KB | 50-200 KB | 整页资源 | | 首次渲染 (FCP) | < 100ms | 200-500ms | 500ms-2s | | 内存占用 | 最小 | 中等 | 高(独立上下文)| | 缓存效率 | ✅ 高 | ⚠️ 中 | ❌ 低 |

3. 🎨 样式隔离,无冲突风险

技术方案

  • Tailwind CSS 预设系统:标准化的设计令牌
  • CSS-in-JS Ready:支持运行时主题定制
  • BEM 命名约定:避免样式名称冲突
  • Scoped Styles:组件级样式作用域
// 主题定制示例
import { ThemeProvider } from '@anker-dtc/ui/theme'

const customTheme = {
  colors: {
    primary: { 500: '#FF6B6B' },
  },
  borderRadius: { base: '8px' }
}

<ThemeProvider theme={customTheme}>
  <DemoRoom />
</ThemeProvider>

样式冲突对比

| 场景 | AnkerDTC | 脚本注入 | iframe | |------|----------|---------|--------| | CSS 冲突风险 | ✅ 极低(Scoped) | ⚠️ 高(全局污染) | ✅ 无冲突 | | 主题定制 | ✅ 灵活 | ⚠️ 困难 | ❌ 隔离无法定制 | | 响应式适配 | ✅ 原生支持 | ⚠️ 需要额外处理 | ❌ 固定尺寸 | | 动画性能 | ✅ GPU 加速 | ⚠️ 依赖实现 | ⚠️ 跨域限制 |

4. 🛠 开发体验,工程化完备

Monorepo 架构

dtc-business/
├── packages/
│   ├── ui/          # UI 组件库
│   ├── hooks/       # React Hooks
│   ├── utils/       # 工具函数
│   └── theme/       # 主题系统
├── configs/         # 共享配置
└── scripts/         # 自动化脚本

自动化工具链

1️⃣ 一键链接脚本

# 自动构建 + 全局链接所有包
./scripts/link-packages.sh

2️⃣ 组件生成器

# 交互式创建新组件
pnpm component:create

# 自动生成:
# - 组件模板
# - 单元测试
# - Storybook 故事
# - 类型定义
# - 导出配置

3️⃣ 质量保障

pnpm test          # 单元测试 (Vitest)
pnpm type-check    # 类型检查
pnpm lint          # 代码规范检查
pnpm build         # 生产构建

4️⃣ 文档驱动开发

pnpm storybook     # 启动组件文档
# 实时预览、交互测试、可视化回归测试

开发效率对比

| 特性 | AnkerDTC | 竞品方案 | |------|----------|---------| | 本地开发 | ✅ 热更新 (HMR) | ⚠️ 需要重新编译/部署 | | 类型检查 | ✅ 实时检查 | ❌ 运行时才发现 | | 调试体验 | ✅ 源码调试 | ⚠️ 混淆代码难调试 | | 版本控制 | ✅ 语义化版本 | ⚠️ 脚本 URL 管理复杂 | | 回滚能力 | ✅ 即时回滚 | ⚠️ 需要重新部署 |

5. 🔧 灵活集成,多种方式

方案 A:NPM 包管理(推荐生产环境)

pnpm add @anker-dtc/ui @anker-dtc/hooks

方案 B:本地链接(推荐开发调试)

# 使用自动化脚本
./scripts/link-packages.sh

# 在项目中链接
pnpm link --global @anker-dtc/ui

方案 C:文件协议(推荐 Monorepo)

{
  "dependencies": {
    "@anker-dtc/ui": "file:../dtc-business/packages/ui"
  }
}

6. 📦 多入口导出,按需使用

灵活的导出策略

// 方式 1:主入口(全量导入)
import { DemoRoom, Button, Input } from '@anker-dtc/ui'

// 方式 2:子路径导出(按需加载,推荐)
import { DemoRoom } from '@anker-dtc/ui/demo-room'
import { Button } from '@anker-dtc/ui/button'

// 方式 3:样式单独引入
import '@anker-dtc/ui/styles.css'

// 方式 4:主题独立导入
import { ThemeProvider } from '@anker-dtc/ui/theme'

Bundle 分析对比

# AnkerDTC - 按需加载
只使用 DemoRoom:2.4 KB + 5.1 KB (CSS) = 7.5 KB

# 脚本注入方案 - 全量加载
所有功能打包:150-300 KB(包含不需要的功能)

# iframe 方案 - 完整应用
整页加载:500 KB - 2 MB(包含完整框架)

🆚 竞品对比总结

脚本注入方案的问题

❌ 技术债务

  • 全局变量污染,可能与宿主应用冲突
  • 版本管理困难,更新需要所有项目重新部署
  • 难以调试,生产代码通常被混淆

❌ 性能问题

  • 全量加载,无法按需引入
  • 阻塞式加载,影响首屏性能
  • 无法利用现代构建工具优化

❌ 维护成本

  • 缺乏类型定义,重构风险高
  • 单元测试困难
  • 跨域问题需要额外配置

iframe 方案的问题

❌ 用户体验

  • 固定尺寸,响应式适配困难
  • 滚动体验差,嵌套滚动条
  • 样式无法与宿主统一

❌ 技术限制

  • 跨域通信复杂(postMessage)
  • 无法访问宿主状态和路由
  • SEO 不友好

❌ 资源浪费

  • 重复加载框架(React/Vue)
  • 独立的 JavaScript 上下文,内存占用高
  • 每次都需要完整的 HTTP 请求

AnkerDTC 的优势

原生集成:像使用普通组件一样自然 ✅ 极致性能:按需加载 + Tree-Shaking,最小化体积 ✅ 类型安全:完整 TypeScript 支持,开发时即可发现错误 ✅ 工程化:完善的工具链,提升开发效率 10 倍 ✅ 可维护性:清晰的架构 + 自动化测试 ✅ 用户体验:无感集成,与宿主应用完美融合

🚀 快速开始

安装

pnpm add @anker-dtc/ui @anker-dtc/hooks @anker-dtc/utils

基础使用

// 1. 在根布局中引入样式和主题
import { ThemeProvider } from '@anker-dtc/ui/theme'
import '@anker-dtc/ui/styles.css'

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <ThemeProvider>
          {children}
        </ThemeProvider>
      </body>
    </html>
  )
}

// 2. 在页面中使用组件
import { DemoRoom } from '@anker-dtc/ui/demo-room'

export default function BookingPage() {
  return (
    <div className="container mx-auto py-8">
      <h1>预约 Demo Room</h1>
      <DemoRoom />
    </div>
  )
}

配置 Next.js

// next.config.js
const nextConfig = {
  transpilePackages: ['@anker-dtc/ui'],
  webpack: (config) => {
    config.resolve.symlinks = false
    return config
  },
}

module.exports = nextConfig

配置 Tailwind CSS

// tailwind.config.js
module.exports = {
  content: [
    './src/**/*.{js,ts,jsx,tsx}',
    './node_modules/@anker-dtc/ui/dist/**/*.js',
  ],
  presets: [
    require('@anker-dtc/tailwind-config'),
  ],
}

💻 本地开发

详细的本地开发和集成指南请参考 LOCAL_DEVELOPMENT.md

# 克隆项目
git clone <repository-url>
cd dtc-business

# 安装依赖
pnpm install

# 开发模式(支持热更新)
pnpm dev

# 构建生产版本
pnpm build

# 运行测试
pnpm test

# 启动 Storybook
pnpm storybook

📁 项目结构

dtc-business/
├── packages/
│   ├── ui/                    # UI 组件包
│   │   ├── src/
│   │   │   ├── components/
│   │   │   │   ├── DemoRoom/  # Demo Room 预约组件
│   │   │   │   ├── Button/    # 基础按钮组件
│   │   │   │   └── ...
│   │   │   ├── styles.css     # 全局样式
│   │   │   └── index.ts       # 主入口
│   │   ├── dist/              # 构建产物
│   │   └── package.json
│   │
│   ├── hooks/                 # React Hooks
│   │   ├── src/
│   │   │   ├── useDebounce/
│   │   │   ├── useLocalStorage/
│   │   │   └── useClickOutside/
│   │   └── package.json
│   │
│   ├── utils/                 # 工具函数
│   │   ├── src/
│   │   │   ├── string/
│   │   │   ├── date/
│   │   │   └── validation/
│   │   └── package.json
│   │
│   └── theme/                 # 主题系统
│       ├── src/
│       │   ├── colors.ts
│       │   ├── spacing.ts
│       │   └── typography.ts
│       └── package.json
│
├── configs/                   # 共享配置
│   ├── eslint-config/
│   ├── typescript-config/
│   └── tailwind-config/
│
├── scripts/                   # 自动化脚本
│   ├── link-packages.sh       # 全局链接脚本
│   └── component.js           # 组件生成器
│
├── .storybook/                # Storybook 配置
├── LOCAL_DEVELOPMENT.md       # 本地开发指南
├── README.md                  # 项目文档
└── pnpm-workspace.yaml        # Monorepo 配置

🔧 技术栈

  • 框架: React 18+ / TypeScript 5+
  • 样式: Tailwind CSS 3+ / PostCSS
  • 构建: tsup / Turbo
  • 测试: Vitest / Testing Library
  • 文档: Storybook 8+
  • 包管理: pnpm + Monorepo
  • 代码质量: ESLint + Prettier

📦 组件清单

首期组件(已发布)

  • DemoRoom: 预约 Demo Room 功能组件
  • Button: 可定制的按钮组件
  • ThemeProvider: 主题系统

规划中的组件

  • 🚧 ProductTour: 产品导览组件
  • 🚧 ContactForm: 联系表单组件
  • 🚧 Newsletter: 订阅组件
  • 🚧 Testimonials: 客户评价组件
  • 🚧 FAQ: 常见问题组件

📊 性能指标

| 指标 | 数值 | 说明 | |------|------|------| | 包体积 | 2.4 KB | UI 组件核心代码(gzipped: 1.1 KB)| | 样式文件 | 5.1 KB | CSS 样式文件(gzipped: 1.2 KB)| | 首次加载 | < 100ms | 首次内容绘制时间 (FCP) | | 类型定义 | 100% | 完整的 TypeScript 类型覆盖 | | 测试覆盖率 | > 80% | 单元测试覆盖率 | | Tree-Shaking | ✅ | 支持按需加载 |

🎨 主题定制

主题属性

{
  colors: {
    primary: { 50, 100, ..., 900, 950 },
    secondary: { 50, 100, ..., 900, 950 },
    success: { 50, 500, 900 },
    warning: { 50, 500, 900 },
    error: { 50, 500, 900 },
  },
  fontFamily: {
    sans: string[],
    mono: string[],
  },
  fontSize: {
    xs, sm, base, lg, xl, 2xl, 3xl, 4xl
  },
  spacing: {
    0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24
  },
  borderRadius: {
    none, sm, base, md, lg, xl, 2xl, full
  },
}

自定义主题示例

const darkTheme = {
  colors: {
    primary: {
      500: '#6366f1',
      600: '#4f46e5',
    },
  },
  fontFamily: {
    sans: ['Poppins', 'sans-serif'],
  },
  borderRadius: {
    base: '0.5rem',
    lg: '1rem',
  },
}

<ThemeProvider theme={darkTheme}>
  <App />
</ThemeProvider>

🧪 可用的 Hooks

useClickOutside

检测元素外部的点击:

import { useClickOutside } from '@anker-dtc/hooks'

function Dropdown() {
  const ref = useRef(null)
  const [isOpen, setIsOpen] = useState(false)

  useClickOutside(ref, () => setIsOpen(false))

  return <div ref={ref}>...</div>
}

useDebounce

防抖一个值:

import { useDebounce } from '@anker-dtc/hooks'

function SearchInput() {
  const [value, setValue] = useState('')
  const debouncedValue = useDebounce(value, 500)

  useEffect(() => {
    // 使用 debouncedValue 进行搜索
  }, [debouncedValue])
}

useLocalStorage

将状态同步到 localStorage:

import { useLocalStorage } from '@anker-dtc/hooks'

function UserPreferences() {
  const [theme, setTheme, removeTheme] = useLocalStorage('theme', 'light')

  return (
    <button onClick={() => setTheme('dark')}>
      切换到暗色模式
    </button>
  )
}

🛠 工具函数

字符串工具

import { capitalize, capitalizeWords } from '@anker-dtc/utils'

capitalize('hello') // 'Hello'
capitalizeWords('hello world') // 'Hello World'

数组工具

import { unique, uniqueBy } from '@anker-dtc/utils'

unique([1, 2, 2, 3]) // [1, 2, 3]
uniqueBy(users, (u) => u.id) // 根据 ID 去重

对象工具

import { omit, pick } from '@anker-dtc/utils'

omit(obj, ['key1', 'key2']) // 移除指定键
pick(obj, ['key1', 'key2']) // 只保留指定键

📝 版本管理

使用 Changesets 进行版本管理和发布:

# 创建变更集
pnpm changeset

# 更新版本号
pnpm changeset:version

# 发布到 npm
pnpm changeset:publish

🌐 浏览器支持

  • Chrome >= 90
  • Firefox >= 88
  • Safari >= 14
  • Edge >= 90

📄 许可证

MIT License

📧 联系方式

  • 项目地址: [GitHub Repository]
  • 问题反馈: [Issue Tracker]
  • 文档站点: [Documentation Site]

构建更好的业务组件,让集成变得简单。