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

@knotx/plugins-canvas-scrollbar

v0.5.8

Published

Canvas Scrollbar Plugin for Knotx

Readme

@knotx/plugins-canvas-scrollbar

画布滚动条插件,为画布提供自定义滚动条功能。

安装

npm install @knotx/plugins-canvas-scrollbar

基本概述

@knotx/plugins-canvas-scrollbar 是 KnotX 框架的画布滚动条插件,为画布提供自定义的滚动条功能。当画布内容超出可视区域时,会自动显示滚动条,用户可以通过拖拽滚动条来快速导航到画布的不同区域。

实现原理

该插件通过监听画布的变换状态和内容尺寸,动态计算滚动条的位置和大小:

  1. 滚动条计算:基于画布内容尺寸、可视区域和变换状态计算滚动条的位置和大小
  2. 交互处理:支持点击滚动条轨道和拖拽滚动条滑块
  3. 自动隐藏:支持配置滚动条的自动隐藏延迟时间
  4. 样式定制:支持自定义滚动条的样式和尺寸

依赖插件

该插件依赖以下包:

  • @knotx/core - 核心功能
  • @knotx/decorators - 装饰器支持
  • @knotx/plugins-canvas - 画布插件(peer dependency)
  • @knotx/jsx - JSX 支持(peer dependency)
  • react - React 框架(peer dependency)

API 使用

基本使用

import { CanvasScrollbar } from '@knotx/plugins-canvas-scrollbar'

// 创建滚动条插件实例
const scrollbar = new CanvasScrollbar()

// 在引擎中注册插件
engine.use(scrollbar)

配置选项

const scrollbar = new CanvasScrollbar().init({
  style: {
    track: {
      backgroundColor: '#f0f0f0',
      borderRadius: '4px'
    },
    thumb: {
      backgroundColor: '#999',
      borderRadius: '4px'
    }
  },
  size: 12,
  offset: 5,
  minThumbSize: 40,
  hideTimeout: 2000
})

完整示例

import { Engine } from '@knotx/core'
import { Canvas } from '@knotx/plugins-canvas'
import { CanvasScrollbar } from '@knotx/plugins-canvas-scrollbar'

const engine = new Engine()

// 注册画布插件
engine.use(new Canvas())

// 注册滚动条插件
engine.use(new CanvasScrollbar().init({
  style: {
    track: {
      backgroundColor: 'rgba(0, 0, 0, 0.1)',
      borderRadius: '6px'
    },
    thumb: {
      backgroundColor: 'rgba(0, 0, 0, 0.3)',
      borderRadius: '6px'
    }
  },
  size: 10,
  offset: 8,
  minThumbSize: 50,
  hideTimeout: 3000
}))

配置接口

CanvasScrollbarConfig

interface CanvasScrollbarConfig {
  /**
   * 轨道以及滑块的css样式
   */
  style?: ScrollbarStyle
  /**
   * 轨道以及滑块的宽度/高度
   */
  size?: number
  /**
   * 距离边界的距离
   */
  offset?: number
  /**
   * 滑块的最小宽度/高度
   */
  minThumbSize?: number
  /**
   * 滚动条消失延迟
   */
  hideTimeout?: number
}

ScrollbarStyle

interface ScrollbarStyle {
  track: CSSProperties
  thumb: CSSProperties
}

默认配置

const defaultConfig = {
  style: {
    track: {},
    thumb: {}
  },
  offset: 3,
  size: 8,
  minThumbSize: 30,
  hideTimeout: 0
}

交互功能

滚动条拖拽

  • 支持拖拽水平和垂直滚动条滑块
  • 实时更新画布视图位置
  • 平滑的拖拽体验

轨道点击

  • 支持点击滚动条轨道快速跳转
  • 自动计算目标位置
  • 平滑的滚动动画

自动显示/隐藏

  • 鼠标进入画布区域时显示滚动条
  • 鼠标离开画布区域时延迟隐藏滚动条
  • 支持配置隐藏延迟时间

文件目录结构

packages/plugins-canvas-scrollbar/
├── src/
│   ├── canvas-scrollbar.tsx  # 画布滚动条插件主文件
│   └── index.ts             # 导出文件
├── dist/                    # 编译输出目录
├── CHANGELOG.md            # 变更日志
├── package.json            # 包配置
├── build.config.ts         # 构建配置
├── eslint.config.mjs       # ESLint 配置
└── tsconfig.json           # TypeScript 配置

许可证

MIT