timeline-canvas 1.4.0 → 1.4.1
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.md +183 -183
- package/README_CN.md +185 -185
- package/dist/ContextMenuPlugin-DkjzERie.mjs +1 -0
- package/dist/{ContextMenuPlugin-Ce29-J1v.d.mts → ContextMenuPlugin-erWC3clR.d.mts} +1 -1
- package/dist/{DarkThemePlugin-CLhvSrRp.d.mts → DarkThemePlugin-DSeernWS.d.mts} +1 -1
- package/dist/DarkThemePlugin-oE6DVEib.mjs +1 -0
- package/dist/EventMediaPlugin-Co_Fr3CX.mjs +1 -0
- package/dist/{EventMediaPlugin-DOIU5CZW.d.mts → EventMediaPlugin-DpK2xquj.d.mts} +1 -1
- package/dist/{EventTooltipPlugin-BtU0ZtyW.d.mts → EventTooltipPlugin-B2lXP9uu.d.mts} +1 -1
- package/dist/EventTooltipPlugin-mbadM95i.mjs +1 -0
- package/dist/LightThemePlugin-BigH_oWz.mjs +1 -0
- package/dist/{LightThemePlugin-KFUJdO1V.d.mts → LightThemePlugin-CXkW_Wpg.d.mts} +1 -1
- package/dist/{PerformanceOverlayPlugin-BmjL92Bg.d.mts → PerformanceOverlayPlugin-CnfsbiMK.d.mts} +1 -1
- package/dist/PerformanceOverlayPlugin-o5al1GSm.mjs +1 -0
- package/dist/builtin-plugin/ContextMenuPlugin.d.mts +1 -2
- package/dist/builtin-plugin/ContextMenuPlugin.mjs +1 -1
- package/dist/builtin-plugin/DarkThemePlugin.d.mts +1 -2
- package/dist/builtin-plugin/DarkThemePlugin.mjs +1 -1
- package/dist/builtin-plugin/EventMediaPlugin.d.mts +1 -2
- package/dist/builtin-plugin/EventMediaPlugin.mjs +1 -1
- package/dist/builtin-plugin/EventTooltipPlugin.d.mts +1 -2
- package/dist/builtin-plugin/EventTooltipPlugin.mjs +1 -1
- package/dist/builtin-plugin/LightThemePlugin.d.mts +1 -2
- package/dist/builtin-plugin/LightThemePlugin.mjs +1 -1
- package/dist/builtin-plugin/MutexGuardPlugin.d.mts +1 -1
- package/dist/builtin-plugin/MutexGuardPlugin.mjs +1 -1
- package/dist/builtin-plugin/PerformanceOverlayPlugin.d.mts +1 -2
- package/dist/builtin-plugin/PerformanceOverlayPlugin.mjs +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +1 -1
- package/dist/{types-BovVI9wC.d.mts → types-Do4sfz9k.d.mts} +15 -18
- package/package.json +2 -2
- package/dist/ContextMenuPlugin-1N7od2I9.mjs +0 -1
- package/dist/DarkThemePlugin-CqLyur3d.mjs +0 -1
- package/dist/EventMediaPlugin-C2MC2ruT.mjs +0 -1
- package/dist/EventTooltipPlugin-Ch_xSklt.mjs +0 -1
- package/dist/LightThemePlugin-pQcTWONZ.mjs +0 -1
- package/dist/PerformanceOverlayPlugin-BjEF-I5h.mjs +0 -1
- /package/dist/{Logger-CfVK3yFL.mjs → Logger-BTKQPGDj.mjs} +0 -0
- /package/dist/{performanceMonitor-BBherdD8.mjs → performanceMonitor-Cb_v1gAo.mjs} +0 -0
- /package/dist/{types-Dc2ct_CM.mjs → types-NnKZYB1U.mjs} +0 -0
package/README.md
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
# Timeline Canvas
|
|
2
|
-
|
|
3
|
-
A powerful, high-performance timeline component built with HTML5 Canvas and TypeScript.
|
|
4
|
-
|
|
5
|
-
[document Chinese Only](https://umbrella22.github.io/timeline-canvas/index.html)
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- 🚀 **High Performance**: Built with Canvas API for smooth rendering of large datasets.
|
|
10
|
-
- 🎨 **Themable**: Built-in Light and Dark themes, with support for custom themes.
|
|
11
|
-
- 🖱️ **Interactive**:
|
|
12
|
-
- Drag and drop events to move them.
|
|
13
|
-
- Resize events from both ends.
|
|
14
|
-
- Split events with double-click.
|
|
15
|
-
- Zooming (Ctrl/Cmd + Scroll) and Panning.
|
|
16
|
-
- Context menu support.
|
|
17
|
-
- 📏 **Smart Guides**: Alignment guides and snapping for precise event placement.
|
|
18
|
-
- ⏱️ **Time Indicator**: Draggable time head with snapping support.
|
|
19
|
-
- 🔌 **Plugin System**: Extensible architecture with built-in plugins for themes, context menus, and more.
|
|
20
|
-
- 📝 **TypeScript**: Written in TypeScript with full type definitions.
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install timeline-canvas
|
|
26
|
-
# or
|
|
27
|
-
pnpm add timeline-canvas
|
|
28
|
-
# or
|
|
29
|
-
yarn add timeline-canvas
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Basic Usage
|
|
33
|
-
|
|
34
|
-
1. Create a container with a canvas element in your HTML:
|
|
35
|
-
|
|
36
|
-
```html
|
|
37
|
-
<div style="width: 100%; height: 500px;">
|
|
38
|
-
<canvas id="timeline-canvas"></canvas>
|
|
39
|
-
</div>
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
1. Initialize the Timeline:
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import { Timeline } from "timeline-canvas";
|
|
46
|
-
|
|
47
|
-
// Initialize
|
|
48
|
-
const timeline = new Timeline("timeline-canvas", {
|
|
49
|
-
startTime: 0,
|
|
50
|
-
endTime: 100,
|
|
51
|
-
trackHeight: 40,
|
|
52
|
-
// ... other options
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Add a track
|
|
56
|
-
timeline.addTrack();
|
|
57
|
-
|
|
58
|
-
// Add an event (trackIndex, startTime, endTime, title)
|
|
59
|
-
timeline.addEvent(0, 10, 30, "My Event", "Description");
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Configuration
|
|
63
|
-
|
|
64
|
-
The `Timeline` constructor accepts an options object:
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
interface TimelineOptions {
|
|
68
|
-
// Localization
|
|
69
|
-
locale?: "en" | "zh" | "zh-CN";
|
|
70
|
-
messages?: Partial<TimelineI18nMessages>;
|
|
71
|
-
|
|
72
|
-
// Dimensions
|
|
73
|
-
canvasHeight?: number;
|
|
74
|
-
trackHeight?: number;
|
|
75
|
-
trackMargin?: number;
|
|
76
|
-
timelineHeight?: number;
|
|
77
|
-
|
|
78
|
-
// Time Settings
|
|
79
|
-
startTime?: number;
|
|
80
|
-
endTime?: number;
|
|
81
|
-
secondWidth?: number; // Pixels per second
|
|
82
|
-
snapInterval?: number;
|
|
83
|
-
snapToSeconds?: boolean;
|
|
84
|
-
|
|
85
|
-
// Features
|
|
86
|
-
enableTimeIndicator?: boolean;
|
|
87
|
-
enableEventResize?: boolean;
|
|
88
|
-
enableEventSplit?: boolean;
|
|
89
|
-
enableContextMenu?: boolean;
|
|
90
|
-
readOnly?: boolean;
|
|
91
|
-
autoAddTrack?: boolean;
|
|
92
|
-
|
|
93
|
-
// Styling
|
|
94
|
-
colors?: Partial<TimelineColors>;
|
|
95
|
-
eventTextStyle?: Partial<EventTextStyle>;
|
|
96
|
-
theme?: TimelinePlugin; // Initial theme
|
|
97
|
-
|
|
98
|
-
// Callbacks
|
|
99
|
-
onEventAdd?: (data: EventAddData) => void;
|
|
100
|
-
onEventUpdate?: (data: EventUpdateData) => void;
|
|
101
|
-
onEventClick?: (data: EventClickData) => void;
|
|
102
|
-
// ... and more
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Localization
|
|
107
|
-
|
|
108
|
-
Built-in status text, default context menu labels, and performance overlay labels can be localized with `locale` or overridden with `messages`:
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
import { Timeline } from "timeline-canvas";
|
|
112
|
-
|
|
113
|
-
const timeline = new Timeline("timeline-canvas", {
|
|
114
|
-
locale: "zh-CN",
|
|
115
|
-
messages: {
|
|
116
|
-
statusReady: "已准备",
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Built-in plugin metadata also supports localized descriptions via `descriptionI18n`. If you need to render the right description for the current language, use `getPluginMetadataDescription(metadata, locale)`.
|
|
122
|
-
|
|
123
|
-
## API Reference
|
|
124
|
-
|
|
125
|
-
### Core Methods
|
|
126
|
-
|
|
127
|
-
- **`addTrack()`**: Adds a new empty track.
|
|
128
|
-
- **`removeTrack()`**: Removes the last track.
|
|
129
|
-
- **`addEvent(trackIndex, startTime, endTime, title, ...)`**: Adds an event to a specific track.
|
|
130
|
-
- **`updateEvent(trackIndex, eventIndex, updates)`**: Updates an existing event.
|
|
131
|
-
- **`deleteEvent(trackIndex, eventIndex)`**: Deletes an event.
|
|
132
|
-
- **`loadData(data)`**: Loads tracks and events from a JSON object.
|
|
133
|
-
- **`setZoomLevel(level)`**: Sets the zoom level (1.0 is default).
|
|
134
|
-
- **`setTimeIndicator(seconds)`**: Moves the time indicator to a specific time.
|
|
135
|
-
- **`setTheme('light' | 'dark')`**: Switches between built-in themes.
|
|
136
|
-
|
|
137
|
-
### Plugins
|
|
138
|
-
|
|
139
|
-
The library comes with several built-in plugins:
|
|
140
|
-
|
|
141
|
-
- **`DarkThemePlugin`**: Dark mode theme.
|
|
142
|
-
- **`LightThemePlugin`**: Light mode theme (default).
|
|
143
|
-
- **`ContextMenuPlugin`**: Adds right-click context menu support.
|
|
144
|
-
- **`PerformanceOverlayPlugin`**: Displays FPS and render time for debugging.
|
|
145
|
-
- **`EventMediaPlugin`**: Support for rendering media (images, waveforms) inside events.
|
|
146
|
-
|
|
147
|
-
Usage:
|
|
148
|
-
|
|
149
|
-
```typescript
|
|
150
|
-
import { Timeline, PerformanceOverlayPlugin } from "timeline-canvas";
|
|
151
|
-
|
|
152
|
-
const timeline = new Timeline("canvas-id");
|
|
153
|
-
timeline.usePlugin(
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Development
|
|
157
|
-
|
|
158
|
-
```bash
|
|
159
|
-
# Run these from the repo root (monorepo)
|
|
160
|
-
# Install dependencies
|
|
161
|
-
pnpm install
|
|
162
|
-
|
|
163
|
-
# Start development server
|
|
164
|
-
pnpm dev
|
|
165
|
-
|
|
166
|
-
# Build the library
|
|
167
|
-
pnpm build
|
|
168
|
-
|
|
169
|
-
# Run documentation site
|
|
170
|
-
pnpm docs:dev
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## MCP (for VS Code Copilot Chat)
|
|
174
|
-
|
|
175
|
-
This repo includes a minimal MCP server (stdio) so an AI agent can scaffold builtin plugins, wire exports, run basic validation, and trigger a small allowlisted set of pnpm scripts.
|
|
176
|
-
|
|
177
|
-
- Install & start (recommended): `pnpm install` then `pnpm mcp`
|
|
178
|
-
- VS Code sample config: see .vscode/mcp.json
|
|
179
|
-
- Docs: see packages/mcp-service/README.md (or README_CN.md)
|
|
180
|
-
|
|
181
|
-
## License
|
|
182
|
-
|
|
183
|
-
MIT
|
|
1
|
+
# Timeline Canvas
|
|
2
|
+
|
|
3
|
+
A powerful, high-performance timeline component built with HTML5 Canvas and TypeScript.
|
|
4
|
+
|
|
5
|
+
[document Chinese Only](https://umbrella22.github.io/timeline-canvas/index.html)
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 🚀 **High Performance**: Built with Canvas API for smooth rendering of large datasets.
|
|
10
|
+
- 🎨 **Themable**: Built-in Light and Dark themes, with support for custom themes.
|
|
11
|
+
- 🖱️ **Interactive**:
|
|
12
|
+
- Drag and drop events to move them.
|
|
13
|
+
- Resize events from both ends.
|
|
14
|
+
- Split events with double-click.
|
|
15
|
+
- Zooming (Ctrl/Cmd + Scroll) and Panning.
|
|
16
|
+
- Context menu support.
|
|
17
|
+
- 📏 **Smart Guides**: Alignment guides and snapping for precise event placement.
|
|
18
|
+
- ⏱️ **Time Indicator**: Draggable time head with snapping support.
|
|
19
|
+
- 🔌 **Plugin System**: Extensible architecture with built-in plugins for themes, context menus, and more.
|
|
20
|
+
- 📝 **TypeScript**: Written in TypeScript with full type definitions.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install timeline-canvas
|
|
26
|
+
# or
|
|
27
|
+
pnpm add timeline-canvas
|
|
28
|
+
# or
|
|
29
|
+
yarn add timeline-canvas
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Basic Usage
|
|
33
|
+
|
|
34
|
+
1. Create a container with a canvas element in your HTML:
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<div style="width: 100%; height: 500px;">
|
|
38
|
+
<canvas id="timeline-canvas"></canvas>
|
|
39
|
+
</div>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
1. Initialize the Timeline:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { Timeline } from "timeline-canvas";
|
|
46
|
+
|
|
47
|
+
// Initialize
|
|
48
|
+
const timeline = new Timeline("timeline-canvas", {
|
|
49
|
+
startTime: 0,
|
|
50
|
+
endTime: 100,
|
|
51
|
+
trackHeight: 40,
|
|
52
|
+
// ... other options
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Add a track
|
|
56
|
+
timeline.addTrack();
|
|
57
|
+
|
|
58
|
+
// Add an event (trackIndex, startTime, endTime, title)
|
|
59
|
+
timeline.addEvent(0, 10, 30, "My Event", "Description");
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Configuration
|
|
63
|
+
|
|
64
|
+
The `Timeline` constructor accepts an options object:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
interface TimelineOptions {
|
|
68
|
+
// Localization
|
|
69
|
+
locale?: "en" | "zh" | "zh-CN";
|
|
70
|
+
messages?: Partial<TimelineI18nMessages>;
|
|
71
|
+
|
|
72
|
+
// Dimensions
|
|
73
|
+
canvasHeight?: number;
|
|
74
|
+
trackHeight?: number;
|
|
75
|
+
trackMargin?: number;
|
|
76
|
+
timelineHeight?: number;
|
|
77
|
+
|
|
78
|
+
// Time Settings
|
|
79
|
+
startTime?: number;
|
|
80
|
+
endTime?: number;
|
|
81
|
+
secondWidth?: number; // Pixels per second
|
|
82
|
+
snapInterval?: number;
|
|
83
|
+
snapToSeconds?: boolean;
|
|
84
|
+
|
|
85
|
+
// Features
|
|
86
|
+
enableTimeIndicator?: boolean;
|
|
87
|
+
enableEventResize?: boolean;
|
|
88
|
+
enableEventSplit?: boolean;
|
|
89
|
+
enableContextMenu?: boolean;
|
|
90
|
+
readOnly?: boolean;
|
|
91
|
+
autoAddTrack?: boolean;
|
|
92
|
+
|
|
93
|
+
// Styling
|
|
94
|
+
colors?: Partial<TimelineColors>;
|
|
95
|
+
eventTextStyle?: Partial<EventTextStyle>;
|
|
96
|
+
theme?: TimelinePlugin; // Initial theme
|
|
97
|
+
|
|
98
|
+
// Callbacks
|
|
99
|
+
onEventAdd?: (data: EventAddData) => void;
|
|
100
|
+
onEventUpdate?: (data: EventUpdateData) => void;
|
|
101
|
+
onEventClick?: (data: EventClickData) => void;
|
|
102
|
+
// ... and more
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Localization
|
|
107
|
+
|
|
108
|
+
Built-in status text, default context menu labels, and performance overlay labels can be localized with `locale` or overridden with `messages`:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { Timeline } from "timeline-canvas";
|
|
112
|
+
|
|
113
|
+
const timeline = new Timeline("timeline-canvas", {
|
|
114
|
+
locale: "zh-CN",
|
|
115
|
+
messages: {
|
|
116
|
+
statusReady: "已准备",
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Built-in plugin metadata also supports localized descriptions via `descriptionI18n`. If you need to render the right description for the current language, use `getPluginMetadataDescription(metadata, locale)`.
|
|
122
|
+
|
|
123
|
+
## API Reference
|
|
124
|
+
|
|
125
|
+
### Core Methods
|
|
126
|
+
|
|
127
|
+
- **`addTrack()`**: Adds a new empty track.
|
|
128
|
+
- **`removeTrack()`**: Removes the last track.
|
|
129
|
+
- **`addEvent(trackIndex, startTime, endTime, title, ...)`**: Adds an event to a specific track.
|
|
130
|
+
- **`updateEvent(trackIndex, eventIndex, updates)`**: Updates an existing event.
|
|
131
|
+
- **`deleteEvent(trackIndex, eventIndex)`**: Deletes an event.
|
|
132
|
+
- **`loadData(data)`**: Loads tracks and events from a JSON object.
|
|
133
|
+
- **`setZoomLevel(level)`**: Sets the zoom level (1.0 is default).
|
|
134
|
+
- **`setTimeIndicator(seconds)`**: Moves the time indicator to a specific time.
|
|
135
|
+
- **`setTheme('light' | 'dark')`**: Switches between built-in themes.
|
|
136
|
+
|
|
137
|
+
### Plugins
|
|
138
|
+
|
|
139
|
+
The library comes with several built-in plugins:
|
|
140
|
+
|
|
141
|
+
- **`DarkThemePlugin`**: Dark mode theme.
|
|
142
|
+
- **`LightThemePlugin`**: Light mode theme (default).
|
|
143
|
+
- **`ContextMenuPlugin`**: Adds right-click context menu support.
|
|
144
|
+
- **`PerformanceOverlayPlugin`**: Displays FPS and render time for debugging.
|
|
145
|
+
- **`EventMediaPlugin`**: Support for rendering media (images, waveforms) inside events.
|
|
146
|
+
|
|
147
|
+
Usage:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { Timeline, PerformanceOverlayPlugin } from "timeline-canvas";
|
|
151
|
+
|
|
152
|
+
const timeline = new Timeline("canvas-id");
|
|
153
|
+
timeline.usePlugin(PerformanceOverlayPlugin);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Development
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# Run these from the repo root (monorepo)
|
|
160
|
+
# Install dependencies
|
|
161
|
+
pnpm install
|
|
162
|
+
|
|
163
|
+
# Start development server
|
|
164
|
+
pnpm dev
|
|
165
|
+
|
|
166
|
+
# Build the library
|
|
167
|
+
pnpm build
|
|
168
|
+
|
|
169
|
+
# Run documentation site
|
|
170
|
+
pnpm docs:dev
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## MCP (for VS Code Copilot Chat)
|
|
174
|
+
|
|
175
|
+
This repo includes a minimal MCP server (stdio) so an AI agent can scaffold builtin plugins, wire exports, run basic validation, and trigger a small allowlisted set of pnpm scripts.
|
|
176
|
+
|
|
177
|
+
- Install & start (recommended): `pnpm install` then `pnpm mcp`
|
|
178
|
+
- VS Code sample config: see .vscode/mcp.json
|
|
179
|
+
- Docs: see packages/mcp-service/README.md (or README_CN.md)
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT
|