@cyca/react-timeline-editor 0.2.1-alpha.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 zdarcy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # react-timeline-editor
2
+ `@cyca/react-timeline-editor` is a React-based component for quickly building timeline editing capabilities.
3
+
4
+ This is a fork of the original [@xzdarcy/react-timeline-editor](https://github.com/xzdarcy/react-timeline-editor)
5
+
6
+ It can be mainly used to build animation editors, video editors, etc.
7
+
8
+ ## ✨ Features
9
+ - 🛠 Supports drag and scale modes, with convenient control hooks.
10
+ - 🔗 Provides grid snapping, auxiliary line snapping, and other interactive capabilities.
11
+ - 🏷 Automatically recognizes action length and infinite scrolling.
12
+ - 🎨 Easy and quick style customization.
13
+ - ❌ Removed Runner from the original library.
14
+
15
+ ## Changes from the original library
16
+ - Replaced react-virtualized with @tanstack/virtual
17
+ - Replaced Interact.js with @use-gesture/vanilla
18
+ - Uses React-19 as a base
19
+ - Compiled with react-compiler enabled
20
+ - Modern bundling via latest `vite` and docs powered by storybook
21
+
22
+ ## Quick Start
23
+
24
+ ```
25
+ npm install @cyca/react-timeline-editor
26
+ ```
27
+
28
+ ```js
29
+ import React from 'react';
30
+ import { Timeline } from '@cyca/react-timeline-editor';
31
+
32
+ export const TimelineEditor = () => {
33
+ return (
34
+ <Timeline
35
+ editorData={[]}
36
+ effects={{}}
37
+ />
38
+ )
39
+ }
40
+ ```
package/dist/flag.png ADDED
Binary file
package/dist/icon.png ADDED
Binary file
@@ -0,0 +1,352 @@
1
+ import { default as default_2 } from 'react';
2
+ import * as React_2 from 'react';
3
+
4
+ export declare interface EditData {
5
+ /**
6
+ * @description Timeline editing data
7
+ */
8
+ editorData: TimelineRow[];
9
+ /**
10
+ * @description Timeline action effects map
11
+ */
12
+ effects: Record<string, TimelineEffect>;
13
+ /**
14
+ * @description Single scale mark range (>0)
15
+ * @default 1
16
+ */
17
+ scale?: number;
18
+ /**
19
+ * @description Minimum number of scales (>=1)
20
+ * @default 20
21
+ */
22
+ minScaleCount?: number;
23
+ /**
24
+ * @description Maximum number of scales (>=minScaleCount)
25
+ * @default Infinity
26
+ */
27
+ maxScaleCount?: number;
28
+ /**
29
+ * @description Number of subdivision units per scale (>0 integer)
30
+ * @default 10
31
+ */
32
+ scaleSplitCount?: number;
33
+ /**
34
+ * @description Display width of a single scale (>0, unit: px)
35
+ * @default 160
36
+ */
37
+ scaleWidth?: number;
38
+ /**
39
+ * @description Distance from the left where the scale starts (>=0, unit: px)
40
+ * @default 20
41
+ */
42
+ startLeft?: number;
43
+ /**
44
+ * @description Default height of each editing row (>0, unit: px)
45
+ * @default 32
46
+ */
47
+ rowHeight?: number;
48
+ /**
49
+ * @description Whether to enable grid snap
50
+ * @default false
51
+ */
52
+ gridSnap?: boolean;
53
+ /**
54
+ * @description Enable drag line snap
55
+ * @default false
56
+ */
57
+ dragLine?: boolean;
58
+ /**
59
+ * @description Whether to hide cursor
60
+ * @default false
61
+ */
62
+ hideCursor?: boolean;
63
+ /**
64
+ * @description Disable dragging in all action areas
65
+ * @default false
66
+ */
67
+ disableDrag?: boolean;
68
+ /**
69
+ * @description Custom action area rendering
70
+ */
71
+ getActionRender?: (action: TimelineAction, row: TimelineRow) => React_2.ReactNode;
72
+ /**
73
+ * @description Custom scale rendering
74
+ */
75
+ getScaleRender?: (scale: number) => React_2.ReactNode;
76
+ /**
77
+ * @description Start move callback
78
+ */
79
+ onActionMoveStart?: (params: {
80
+ action: TimelineAction;
81
+ row: TimelineRow;
82
+ }) => void;
83
+ /**
84
+ * @description Move callback (return false to prevent movement)
85
+ */
86
+ onActionMoving?: (params: {
87
+ action: TimelineAction;
88
+ row: TimelineRow;
89
+ start: number;
90
+ end: number;
91
+ }) => void | boolean;
92
+ /**
93
+ * @description Move end callback (return false to prevent onChange trigger)
94
+ */
95
+ onActionMoveEnd?: (params: {
96
+ action: TimelineAction;
97
+ row: TimelineRow;
98
+ start: number;
99
+ end: number;
100
+ }) => void;
101
+ /**
102
+ * @description Start resize callback
103
+ */
104
+ onActionResizeStart?: (params: {
105
+ action: TimelineAction;
106
+ row: TimelineRow;
107
+ dir: 'right' | 'left';
108
+ }) => void;
109
+ /**
110
+ * @description Resize callback (return false to prevent resize)
111
+ */
112
+ onActionResizing?: (params: {
113
+ action: TimelineAction;
114
+ row: TimelineRow;
115
+ start: number;
116
+ end: number;
117
+ dir: 'right' | 'left';
118
+ }) => void | boolean;
119
+ /**
120
+ * @description Resize end callback (return false to prevent onChange trigger)
121
+ */
122
+ onActionResizeEnd?: (params: {
123
+ action: TimelineAction;
124
+ row: TimelineRow;
125
+ start: number;
126
+ end: number;
127
+ dir: 'right' | 'left';
128
+ }) => void;
129
+ /**
130
+ * @description Click row callback
131
+ */
132
+ onClickRow?: (e: React_2.MouseEvent<HTMLElement, MouseEvent>, param: {
133
+ row: TimelineRow;
134
+ time: number;
135
+ }) => void;
136
+ /**
137
+ * @description Click action callback
138
+ */
139
+ onClickAction?: (e: React_2.MouseEvent<HTMLElement, MouseEvent>, param: {
140
+ action: TimelineAction;
141
+ row: TimelineRow;
142
+ time: number;
143
+ }) => void;
144
+ /**
145
+ * @description Click action callback (not executed when drag is triggered)
146
+ */
147
+ onClickActionOnly?: (e: React_2.MouseEvent<HTMLElement, MouseEvent>, param: {
148
+ action: TimelineAction;
149
+ row: TimelineRow;
150
+ time: number;
151
+ }) => void;
152
+ /**
153
+ * @description Double click row callback
154
+ */
155
+ onDoubleClickRow?: (e: React_2.MouseEvent<HTMLElement, MouseEvent>, param: {
156
+ row: TimelineRow;
157
+ time: number;
158
+ }) => void;
159
+ /**
160
+ * @description Double click action callback
161
+ */
162
+ onDoubleClickAction?: (e: React_2.MouseEvent<HTMLElement, MouseEvent>, param: {
163
+ action: TimelineAction;
164
+ row: TimelineRow;
165
+ time: number;
166
+ }) => void;
167
+ /**
168
+ * @description Right click row callback
169
+ */
170
+ onContextMenuRow?: (e: React_2.MouseEvent<HTMLElement, MouseEvent>, param: {
171
+ row: TimelineRow;
172
+ time: number;
173
+ }) => void;
174
+ /**
175
+ * @description Right click action callback
176
+ */
177
+ onContextMenuAction?: (e: React_2.MouseEvent<HTMLElement, MouseEvent>, param: {
178
+ action: TimelineAction;
179
+ row: TimelineRow;
180
+ time: number;
181
+ }) => void;
182
+ /**
183
+ * @description Get the list of action ids to show assist drag lines, calculated at move/resize start, defaults to all actions except the currently moving action
184
+ */
185
+ getAssistDragLineActionIds?: (params: {
186
+ action: TimelineAction;
187
+ editorData: TimelineRow[];
188
+ row: TimelineRow;
189
+ }) => string[];
190
+ /**
191
+ * @description Cursor drag start event
192
+ */
193
+ onCursorDragStart?: (time: number) => void;
194
+ /**
195
+ * @description Cursor drag end event
196
+ */
197
+ onCursorDragEnd?: (time: number) => void;
198
+ /**
199
+ * @description Cursor drag event
200
+ */
201
+ onCursorDrag?: (time: number) => void;
202
+ /**
203
+ * @description Click time area event, return false to prevent setting time
204
+ */
205
+ onClickTimeArea?: (time: number, e: React_2.MouseEvent<HTMLDivElement, MouseEvent>) => boolean | undefined;
206
+ }
207
+
208
+ export declare interface EffectSourceParam {
209
+ /** Current time */
210
+ time: number;
211
+ /** Whether it is currently playing */
212
+ isPlaying: boolean;
213
+ /** Action */
214
+ action: TimelineAction;
215
+ /** Action effect */
216
+ effect: TimelineEffect;
217
+ }
218
+
219
+ /** Scroll parameters from virtualized container */
220
+ export declare type OnScrollParams = {
221
+ clientHeight: number;
222
+ clientWidth: number;
223
+ scrollHeight: number;
224
+ scrollLeft: number;
225
+ scrollTop: number;
226
+ scrollWidth: number;
227
+ };
228
+
229
+ export declare const Timeline: default_2.ForwardRefExoticComponent<TimelineEditor & default_2.RefAttributes<TimelineState>>;
230
+
231
+ /**
232
+ * Basic parameters of action
233
+ * @export
234
+ * @interface TimelineAction
235
+ */
236
+ export declare interface TimelineAction {
237
+ /** Action id */
238
+ id: string;
239
+ /** Action start time */
240
+ start: number;
241
+ /** Action end time */
242
+ end: number;
243
+ /** Effect ID corresponding to the action */
244
+ effectId: string;
245
+ /** Whether the action is selected */
246
+ selected?: boolean;
247
+ /** Whether the action is resizable */
248
+ flexible?: boolean;
249
+ /** Whether the action is movable */
250
+ movable?: boolean;
251
+ /** Whether the action is disabled */
252
+ disable?: boolean;
253
+ /** Minimum start time limit for the action */
254
+ minStart?: number;
255
+ /** Maximum end time limit for the action */
256
+ maxEnd?: number;
257
+ }
258
+
259
+ /**
260
+ * Animation editor parameters
261
+ * @export
262
+ * @interface TimelineProp
263
+ */
264
+ export declare interface TimelineEditor extends EditData {
265
+ /**
266
+ * @description Scroll distance from top of editing area (please use ref.setScrollTop instead)
267
+ * @deprecated
268
+ */
269
+ scrollTop?: number;
270
+ /**
271
+ * @description Editing area scroll callback (used to control synchronization with editing row scrolling)
272
+ */
273
+ onScroll?: (params: OnScrollParams) => void;
274
+ /**
275
+ * @description Whether to enable auto scroll when dragging
276
+ * @default false
277
+ */
278
+ autoScroll?: boolean;
279
+ /**
280
+ * @description Custom timeline style
281
+ */
282
+ style?: React_2.CSSProperties;
283
+ /**
284
+ * @description Whether to auto re-render (update tick when data changes or cursor time changes)
285
+ * @default true
286
+ */
287
+ autoReRender?: boolean;
288
+ /**
289
+ * @description Data change callback, triggered after action end changes data (return false to prevent automatic engine synchronization, used to reduce performance overhead)
290
+ */
291
+ onChange?: (editorData: TimelineRow[]) => void | boolean;
292
+ }
293
+
294
+ export declare interface TimelineEffect {
295
+ /** Effect id */
296
+ id: string;
297
+ /** Effect name */
298
+ name?: string;
299
+ /** Effect execution code */
300
+ source?: TimeLineEffectSource;
301
+ }
302
+
303
+ /**
304
+ * Effect execution callback
305
+ * @export
306
+ * @interface TimeLineEffectSource
307
+ */
308
+ export declare interface TimeLineEffectSource {
309
+ /** Callback when playback starts in the current action time region */
310
+ start?: (param: EffectSourceParam) => void;
311
+ /** Callback executed when time enters the action */
312
+ enter?: (param: EffectSourceParam) => void;
313
+ /** Callback when action updates */
314
+ update?: (param: EffectSourceParam) => void;
315
+ /** Callback executed when time leaves the action */
316
+ leave?: (param: EffectSourceParam) => void;
317
+ /** Callback when playback stops in the current action time region */
318
+ stop?: (param: EffectSourceParam) => void;
319
+ }
320
+
321
+ /**
322
+ * Basic parameters of action row
323
+ * @export
324
+ * @interface TimelineRow
325
+ */
326
+ export declare interface TimelineRow {
327
+ /** Action row id */
328
+ id: string;
329
+ /** List of actions in the row */
330
+ actions: TimelineAction[];
331
+ /** Custom row height */
332
+ rowHeight?: number;
333
+ /** Whether the row is selected */
334
+ selected?: boolean;
335
+ /** Extended class names of the row */
336
+ classNames?: string[];
337
+ }
338
+
339
+ export declare interface TimelineState {
340
+ /** DOM node */
341
+ target: HTMLElement;
342
+ /** Set current playback time */
343
+ set time(time: number);
344
+ /** Get current playback time */
345
+ get time(): number;
346
+ /** Set scroll left */
347
+ setScrollLeft: (val: number) => void;
348
+ /** Set scroll top */
349
+ setScrollTop: (val: number) => void;
350
+ }
351
+
352
+ export { }
@@ -0,0 +1,2 @@
1
+ .timeline-editor-cursor{cursor:ew-resize;box-sizing:border-box;border-left:1px solid #5297ff;border-right:1px solid #5297ff;height:calc(100% - 32px);position:absolute;top:32px;transform:translate(-25%)scaleX(.5)}.timeline-editor-cursor-top{margin:auto;position:absolute;top:0;left:50%;transform:translate(-50%)scaleX(2)}.timeline-editor-cursor-area{cursor:ew-resize;width:16px;height:100%;position:absolute;top:0;left:50%;transform:translate(-50%)}.timeline-editor-drag-line-container{height:100%;position:absolute;top:0;left:0}.timeline-editor-drag-line{border-left:1px dashed #5297ff99;width:0;height:99%;position:absolute;top:0}.timeline-editor:hover .timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar{height:4px}.timeline-editor-edit-area{flex:auto;margin-top:10px;position:relative;overflow:hidden}.timeline-editor-edit-area .ReactVirtualized__Grid{overflow:overlay!important;outline:none!important}.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar{width:0;height:0}.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar-track{background-color:#0000!important}.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar-thumb{background:#313132;border-radius:16px}.timeline-editor-action{background-color:#2f3134;position:absolute;top:0;left:0}.timeline-editor-action .timeline-editor-action-left-stretch,.timeline-editor-action .timeline-editor-action-right-stretch{border-radius:4px;width:10px;height:100%;position:absolute;top:0;overflow:hidden}.timeline-editor-action .timeline-editor-action-left-stretch:after,.timeline-editor-action .timeline-editor-action-right-stretch:after{border-top:28px solid #0000;border-bottom:28px solid #0000;border-radius:4px;margin:auto;position:absolute;top:0;bottom:0}.timeline-editor-action .timeline-editor-action-left-stretch{left:0}.timeline-editor-action .timeline-editor-action-left-stretch:after{content:"";border-left:7px solid #ffffff1a;border-right:7px solid #0000;left:0}.timeline-editor-action .timeline-editor-action-right-stretch{right:0}.timeline-editor-action .timeline-editor-action-right-stretch:after{content:"";border-left:7px solid #0000;border-right:7px solid #ffffff1a;right:0}.timeline-editor-edit-row{box-sizing:border-box;background-image:linear-gradient(#191b1d,#191b1d),linear-gradient(90deg,#ffffff14 1px,#0000 0);background-repeat:no-repeat,repeat;flex-direction:row;display:flex}.timeline-editor{background-color:#191b1d;flex-direction:column;width:600px;height:600px;min-height:32px;font-family:PingFang SC;font-size:12px;display:flex;position:relative;overflow:hidden}.timeline-editor-time-area{flex:none;height:32px;position:relative}.timeline-editor-time-area-virtual{outline:none}.timeline-editor-time-area-virtual::-webkit-scrollbar{display:none}.timeline-editor-time-area-interact{cursor:pointer;position:absolute;top:0;left:0}.timeline-editor-time-unit{box-sizing:content-box;border-right:1px solid #fff3;position:relative;height:4px!important;top:auto!important;bottom:0!important}.timeline-editor-time-unit-big{height:8px!important}.timeline-editor-time-unit-scale{color:#fff9;position:absolute;top:0;right:0;transform:translate(50%,-100%)}
2
+ /*$vite$:1*/