@knotx/plugins-canvas-scrollbar 0.4.11 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +190 -0
- package/README.md +190 -0
- package/package.json +10 -10
package/README.en.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# @knotx/plugins-canvas-scrollbar
|
|
2
|
+
|
|
3
|
+
Canvas scrollbar plugin that provides custom scrollbar functionality for the canvas.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @knotx/plugins-canvas-scrollbar
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
`@knotx/plugins-canvas-scrollbar` is a canvas scrollbar plugin for the KnotX framework that provides custom scrollbar functionality for the canvas. When canvas content exceeds the visible area, scrollbars are automatically displayed, allowing users to quickly navigate to different areas of the canvas by dragging the scrollbars.
|
|
14
|
+
|
|
15
|
+
## Implementation Principles
|
|
16
|
+
|
|
17
|
+
The plugin dynamically calculates scrollbar position and size by monitoring canvas transform state and content dimensions:
|
|
18
|
+
|
|
19
|
+
1. **Scrollbar Calculation**: Calculates scrollbar position and size based on canvas content dimensions, visible area, and transform state
|
|
20
|
+
2. **Interaction Handling**: Supports clicking scrollbar tracks and dragging scrollbar thumbs
|
|
21
|
+
3. **Auto-hide**: Supports configurable auto-hide delay time for scrollbars
|
|
22
|
+
4. **Style Customization**: Supports custom scrollbar styles and dimensions
|
|
23
|
+
|
|
24
|
+
## Dependencies
|
|
25
|
+
|
|
26
|
+
This plugin depends on the following packages:
|
|
27
|
+
|
|
28
|
+
- `@knotx/core` - Core functionality
|
|
29
|
+
- `@knotx/decorators` - Decorator support
|
|
30
|
+
- `@knotx/plugins-canvas` - Canvas plugin (peer dependency)
|
|
31
|
+
- `@knotx/jsx` - JSX support (peer dependency)
|
|
32
|
+
- `react` - React framework (peer dependency)
|
|
33
|
+
|
|
34
|
+
## API Usage
|
|
35
|
+
|
|
36
|
+
### Basic Usage
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { CanvasScrollbar } from '@knotx/plugins-canvas-scrollbar'
|
|
40
|
+
|
|
41
|
+
// Create scrollbar plugin instance
|
|
42
|
+
const scrollbar = new CanvasScrollbar()
|
|
43
|
+
|
|
44
|
+
// Register plugin in engine
|
|
45
|
+
engine.use(scrollbar)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Configuration Options
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const scrollbar = new CanvasScrollbar().init({
|
|
52
|
+
style: {
|
|
53
|
+
track: {
|
|
54
|
+
backgroundColor: '#f0f0f0',
|
|
55
|
+
borderRadius: '4px'
|
|
56
|
+
},
|
|
57
|
+
thumb: {
|
|
58
|
+
backgroundColor: '#999',
|
|
59
|
+
borderRadius: '4px'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
size: 12,
|
|
63
|
+
offset: 5,
|
|
64
|
+
minThumbSize: 40,
|
|
65
|
+
hideTimeout: 2000
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Complete Example
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Engine } from '@knotx/core'
|
|
73
|
+
import { Canvas } from '@knotx/plugins-canvas'
|
|
74
|
+
import { CanvasScrollbar } from '@knotx/plugins-canvas-scrollbar'
|
|
75
|
+
|
|
76
|
+
const engine = new Engine()
|
|
77
|
+
|
|
78
|
+
// Register canvas plugin
|
|
79
|
+
engine.use(new Canvas())
|
|
80
|
+
|
|
81
|
+
// Register scrollbar plugin
|
|
82
|
+
engine.use(new CanvasScrollbar().init({
|
|
83
|
+
style: {
|
|
84
|
+
track: {
|
|
85
|
+
backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
|
86
|
+
borderRadius: '6px'
|
|
87
|
+
},
|
|
88
|
+
thumb: {
|
|
89
|
+
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
|
90
|
+
borderRadius: '6px'
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
size: 10,
|
|
94
|
+
offset: 8,
|
|
95
|
+
minThumbSize: 50,
|
|
96
|
+
hideTimeout: 3000
|
|
97
|
+
}))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Configuration Interface
|
|
101
|
+
|
|
102
|
+
### CanvasScrollbarConfig
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
interface CanvasScrollbarConfig {
|
|
106
|
+
/**
|
|
107
|
+
* CSS styles for track and thumb
|
|
108
|
+
*/
|
|
109
|
+
style?: ScrollbarStyle
|
|
110
|
+
/**
|
|
111
|
+
* Width/height of track and thumb
|
|
112
|
+
*/
|
|
113
|
+
size?: number
|
|
114
|
+
/**
|
|
115
|
+
* Distance from boundary
|
|
116
|
+
*/
|
|
117
|
+
offset?: number
|
|
118
|
+
/**
|
|
119
|
+
* Minimum width/height of thumb
|
|
120
|
+
*/
|
|
121
|
+
minThumbSize?: number
|
|
122
|
+
/**
|
|
123
|
+
* Scrollbar hide timeout
|
|
124
|
+
*/
|
|
125
|
+
hideTimeout?: number
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### ScrollbarStyle
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
interface ScrollbarStyle {
|
|
133
|
+
track: CSSProperties
|
|
134
|
+
thumb: CSSProperties
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Default Configuration
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const defaultConfig = {
|
|
142
|
+
style: {
|
|
143
|
+
track: {},
|
|
144
|
+
thumb: {}
|
|
145
|
+
},
|
|
146
|
+
offset: 3,
|
|
147
|
+
size: 8,
|
|
148
|
+
minThumbSize: 30,
|
|
149
|
+
hideTimeout: 0
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Interactive Features
|
|
154
|
+
|
|
155
|
+
### Scrollbar Dragging
|
|
156
|
+
|
|
157
|
+
- Support for dragging horizontal and vertical scrollbar thumbs
|
|
158
|
+
- Real-time canvas view position updates
|
|
159
|
+
- Smooth dragging experience
|
|
160
|
+
|
|
161
|
+
### Track Clicking
|
|
162
|
+
|
|
163
|
+
- Support for clicking scrollbar tracks for quick navigation
|
|
164
|
+
- Automatic target position calculation
|
|
165
|
+
- Smooth scrolling animation
|
|
166
|
+
|
|
167
|
+
### Auto Show/Hide
|
|
168
|
+
|
|
169
|
+
- Show scrollbars when mouse enters canvas area
|
|
170
|
+
- Delay-hide scrollbars when mouse leaves canvas area
|
|
171
|
+
- Configurable hide delay time
|
|
172
|
+
|
|
173
|
+
## File Directory Structure
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
packages/plugins-canvas-scrollbar/
|
|
177
|
+
├── src/
|
|
178
|
+
│ ├── canvas-scrollbar.tsx # Canvas scrollbar plugin main file
|
|
179
|
+
│ └── index.ts # Export file
|
|
180
|
+
├── dist/ # Build output directory
|
|
181
|
+
├── CHANGELOG.md # Change log
|
|
182
|
+
├── package.json # Package configuration
|
|
183
|
+
├── build.config.ts # Build configuration
|
|
184
|
+
├── eslint.config.mjs # ESLint configuration
|
|
185
|
+
└── tsconfig.json # TypeScript configuration
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# @knotx/plugins-canvas-scrollbar
|
|
2
|
+
|
|
3
|
+
画布滚动条插件,为画布提供自定义滚动条功能。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @knotx/plugins-canvas-scrollbar
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 基本概述
|
|
12
|
+
|
|
13
|
+
`@knotx/plugins-canvas-scrollbar` 是 KnotX 框架的画布滚动条插件,为画布提供自定义的滚动条功能。当画布内容超出可视区域时,会自动显示滚动条,用户可以通过拖拽滚动条来快速导航到画布的不同区域。
|
|
14
|
+
|
|
15
|
+
## 实现原理
|
|
16
|
+
|
|
17
|
+
该插件通过监听画布的变换状态和内容尺寸,动态计算滚动条的位置和大小:
|
|
18
|
+
|
|
19
|
+
1. **滚动条计算**:基于画布内容尺寸、可视区域和变换状态计算滚动条的位置和大小
|
|
20
|
+
2. **交互处理**:支持点击滚动条轨道和拖拽滚动条滑块
|
|
21
|
+
3. **自动隐藏**:支持配置滚动条的自动隐藏延迟时间
|
|
22
|
+
4. **样式定制**:支持自定义滚动条的样式和尺寸
|
|
23
|
+
|
|
24
|
+
## 依赖插件
|
|
25
|
+
|
|
26
|
+
该插件依赖以下包:
|
|
27
|
+
|
|
28
|
+
- `@knotx/core` - 核心功能
|
|
29
|
+
- `@knotx/decorators` - 装饰器支持
|
|
30
|
+
- `@knotx/plugins-canvas` - 画布插件(peer dependency)
|
|
31
|
+
- `@knotx/jsx` - JSX 支持(peer dependency)
|
|
32
|
+
- `react` - React 框架(peer dependency)
|
|
33
|
+
|
|
34
|
+
## API 使用
|
|
35
|
+
|
|
36
|
+
### 基本使用
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { CanvasScrollbar } from '@knotx/plugins-canvas-scrollbar'
|
|
40
|
+
|
|
41
|
+
// 创建滚动条插件实例
|
|
42
|
+
const scrollbar = new CanvasScrollbar()
|
|
43
|
+
|
|
44
|
+
// 在引擎中注册插件
|
|
45
|
+
engine.use(scrollbar)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 配置选项
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const scrollbar = new CanvasScrollbar().init({
|
|
52
|
+
style: {
|
|
53
|
+
track: {
|
|
54
|
+
backgroundColor: '#f0f0f0',
|
|
55
|
+
borderRadius: '4px'
|
|
56
|
+
},
|
|
57
|
+
thumb: {
|
|
58
|
+
backgroundColor: '#999',
|
|
59
|
+
borderRadius: '4px'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
size: 12,
|
|
63
|
+
offset: 5,
|
|
64
|
+
minThumbSize: 40,
|
|
65
|
+
hideTimeout: 2000
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 完整示例
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Engine } from '@knotx/core'
|
|
73
|
+
import { Canvas } from '@knotx/plugins-canvas'
|
|
74
|
+
import { CanvasScrollbar } from '@knotx/plugins-canvas-scrollbar'
|
|
75
|
+
|
|
76
|
+
const engine = new Engine()
|
|
77
|
+
|
|
78
|
+
// 注册画布插件
|
|
79
|
+
engine.use(new Canvas())
|
|
80
|
+
|
|
81
|
+
// 注册滚动条插件
|
|
82
|
+
engine.use(new CanvasScrollbar().init({
|
|
83
|
+
style: {
|
|
84
|
+
track: {
|
|
85
|
+
backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
|
86
|
+
borderRadius: '6px'
|
|
87
|
+
},
|
|
88
|
+
thumb: {
|
|
89
|
+
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
|
90
|
+
borderRadius: '6px'
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
size: 10,
|
|
94
|
+
offset: 8,
|
|
95
|
+
minThumbSize: 50,
|
|
96
|
+
hideTimeout: 3000
|
|
97
|
+
}))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 配置接口
|
|
101
|
+
|
|
102
|
+
### CanvasScrollbarConfig
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
interface CanvasScrollbarConfig {
|
|
106
|
+
/**
|
|
107
|
+
* 轨道以及滑块的css样式
|
|
108
|
+
*/
|
|
109
|
+
style?: ScrollbarStyle
|
|
110
|
+
/**
|
|
111
|
+
* 轨道以及滑块的宽度/高度
|
|
112
|
+
*/
|
|
113
|
+
size?: number
|
|
114
|
+
/**
|
|
115
|
+
* 距离边界的距离
|
|
116
|
+
*/
|
|
117
|
+
offset?: number
|
|
118
|
+
/**
|
|
119
|
+
* 滑块的最小宽度/高度
|
|
120
|
+
*/
|
|
121
|
+
minThumbSize?: number
|
|
122
|
+
/**
|
|
123
|
+
* 滚动条消失延迟
|
|
124
|
+
*/
|
|
125
|
+
hideTimeout?: number
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### ScrollbarStyle
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
interface ScrollbarStyle {
|
|
133
|
+
track: CSSProperties
|
|
134
|
+
thumb: CSSProperties
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 默认配置
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const defaultConfig = {
|
|
142
|
+
style: {
|
|
143
|
+
track: {},
|
|
144
|
+
thumb: {}
|
|
145
|
+
},
|
|
146
|
+
offset: 3,
|
|
147
|
+
size: 8,
|
|
148
|
+
minThumbSize: 30,
|
|
149
|
+
hideTimeout: 0
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 交互功能
|
|
154
|
+
|
|
155
|
+
### 滚动条拖拽
|
|
156
|
+
|
|
157
|
+
- 支持拖拽水平和垂直滚动条滑块
|
|
158
|
+
- 实时更新画布视图位置
|
|
159
|
+
- 平滑的拖拽体验
|
|
160
|
+
|
|
161
|
+
### 轨道点击
|
|
162
|
+
|
|
163
|
+
- 支持点击滚动条轨道快速跳转
|
|
164
|
+
- 自动计算目标位置
|
|
165
|
+
- 平滑的滚动动画
|
|
166
|
+
|
|
167
|
+
### 自动显示/隐藏
|
|
168
|
+
|
|
169
|
+
- 鼠标进入画布区域时显示滚动条
|
|
170
|
+
- 鼠标离开画布区域时延迟隐藏滚动条
|
|
171
|
+
- 支持配置隐藏延迟时间
|
|
172
|
+
|
|
173
|
+
## 文件目录结构
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
packages/plugins-canvas-scrollbar/
|
|
177
|
+
├── src/
|
|
178
|
+
│ ├── canvas-scrollbar.tsx # 画布滚动条插件主文件
|
|
179
|
+
│ └── index.ts # 导出文件
|
|
180
|
+
├── dist/ # 编译输出目录
|
|
181
|
+
├── CHANGELOG.md # 变更日志
|
|
182
|
+
├── package.json # 包配置
|
|
183
|
+
├── build.config.ts # 构建配置
|
|
184
|
+
├── eslint.config.mjs # ESLint 配置
|
|
185
|
+
└── tsconfig.json # TypeScript 配置
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## 许可证
|
|
189
|
+
|
|
190
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-canvas-scrollbar",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "Canvas Scrollbar Plugin for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,21 +29,21 @@
|
|
|
29
29
|
],
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": ">=17.0.0",
|
|
32
|
-
"@knotx/jsx": "0.4.
|
|
33
|
-
"@knotx/plugins-canvas": "0.4.
|
|
32
|
+
"@knotx/jsx": "0.4.13",
|
|
33
|
+
"@knotx/plugins-canvas": "0.4.13"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@knotx/core": "0.4.
|
|
37
|
-
"@knotx/decorators": "0.4.
|
|
36
|
+
"@knotx/core": "0.4.13",
|
|
37
|
+
"@knotx/decorators": "0.4.13"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/react": "^17.0.0",
|
|
41
41
|
"react": "^17.0.0",
|
|
42
|
-
"@knotx/build-config": "0.4.
|
|
43
|
-
"@knotx/eslint-config": "0.4.
|
|
44
|
-
"@knotx/jsx": "0.4.
|
|
45
|
-
"@knotx/plugins-canvas": "0.4.
|
|
46
|
-
"@knotx/typescript-config": "0.4.
|
|
42
|
+
"@knotx/build-config": "0.4.13",
|
|
43
|
+
"@knotx/eslint-config": "0.4.13",
|
|
44
|
+
"@knotx/jsx": "0.4.13",
|
|
45
|
+
"@knotx/plugins-canvas": "0.4.13",
|
|
46
|
+
"@knotx/typescript-config": "0.4.13"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "unbuild",
|