@twick/timeline 0.14.2 → 0.14.4
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 +86 -0
- package/dist/context/timeline-context.d.ts +111 -2
- package/dist/core/addOns/animation.d.ts +3 -0
- package/dist/core/editor/timeline.editor.d.ts +3 -3
- package/dist/core/elements/base.element.d.ts +4 -0
- package/dist/core/elements/circle.element.d.ts +4 -0
- package/dist/core/elements/icon.element.d.ts +8 -3
- package/dist/core/elements/rect.element.d.ts +8 -0
- package/dist/core/track/track.d.ts +325 -19
- package/dist/core/visitor/element-adder.d.ts +122 -2
- package/dist/index.js +562 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +562 -40
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +12 -157
- package/dist/types.d.ts +128 -0
- package/dist/utils/constants.d.ts +172 -35
- package/dist/utils/timeline.utils.d.ts +112 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @twick/timeline
|
|
2
2
|
|
|
3
|
+
Timeline management and editing capabilities for video projects.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a comprehensive timeline editor with CRUD operations for managing video tracks and elements. It uses the visitor pattern to handle different element types consistently and offers a fluent interface for timeline manipulation.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @twick/timeline
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @twick/timeline
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { TimelineEditor, TimelineOperationContext } from '@twick/timeline';
|
|
21
|
+
|
|
22
|
+
// Create editor with context
|
|
23
|
+
const context: TimelineOperationContext = {
|
|
24
|
+
contextId: 'my-editor',
|
|
25
|
+
setTotalDuration: (duration) => console.log('Duration:', duration),
|
|
26
|
+
setPresent: (data) => console.log('Present:', data),
|
|
27
|
+
handleUndo: () => console.log('Undo'),
|
|
28
|
+
handleRedo: () => console.log('Redo'),
|
|
29
|
+
handleResetHistory: () => console.log('Reset History'),
|
|
30
|
+
setLatestProjectVersion: (version) => console.log('Version:', version),
|
|
31
|
+
setTimelineAction: (action, payload) => console.log('Action:', action, payload),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const editor = new TimelineEditor(context);
|
|
35
|
+
const track = editor.addTrack('My Video Track');
|
|
36
|
+
```
|
|
37
|
+
|
|
3
38
|
## Timeline Editor CRUD Operations
|
|
4
39
|
|
|
5
40
|
The TimelineEditor provides a clean interface for managing tracks and elements using the visitor pattern.
|
|
@@ -172,4 +207,55 @@ function MyComponent() {
|
|
|
172
207
|
}
|
|
173
208
|
```
|
|
174
209
|
|
|
210
|
+
## API Reference
|
|
211
|
+
|
|
212
|
+
### Core Classes
|
|
213
|
+
|
|
214
|
+
- `TimelineEditor`: Main timeline editor class
|
|
215
|
+
- `TextElement`: Text element implementation
|
|
216
|
+
- `VideoElement`: Video element implementation
|
|
217
|
+
- `ImageElement`: Image element implementation
|
|
218
|
+
- `AudioElement`: Audio element implementation
|
|
219
|
+
|
|
220
|
+
### Hooks
|
|
221
|
+
|
|
222
|
+
- `useTimelineContext`: React hook for timeline context
|
|
223
|
+
|
|
224
|
+
### Utility Functions
|
|
225
|
+
|
|
226
|
+
- `getCurrentElements`: Get elements at specific time
|
|
227
|
+
- `getTotalDuration`: Calculate total timeline duration
|
|
228
|
+
- `generateShortUuid`: Generate unique IDs
|
|
229
|
+
- `isElementId`: Check if ID is element type
|
|
230
|
+
- `isTrackId`: Check if ID is track type
|
|
231
|
+
|
|
232
|
+
### Types
|
|
233
|
+
|
|
234
|
+
- `TimelineOperationContext`: Context interface for timeline operations
|
|
235
|
+
- `TrackElement`: Base track element interface
|
|
236
|
+
|
|
237
|
+
For complete API documentation, refer to the generated documentation.
|
|
238
|
+
|
|
239
|
+
## Browser Support
|
|
240
|
+
|
|
241
|
+
This package requires a browser environment with support for:
|
|
242
|
+
- Modern JavaScript features (ES2020+)
|
|
243
|
+
- Promise and async/await support
|
|
244
|
+
|
|
245
|
+
## Documentation
|
|
246
|
+
|
|
247
|
+
For complete documentation, refer to the project documentation site.
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
This package is licensed under the **Sustainable Use License (SUL) Version 1.0**.
|
|
252
|
+
|
|
253
|
+
- Free for use in commercial and non-commercial apps
|
|
254
|
+
- Can be modified and self-hosted
|
|
255
|
+
- Cannot be sold, rebranded, or distributed as a standalone SDK
|
|
256
|
+
|
|
257
|
+
For commercial licensing inquiries, contact: contact@kifferai.com
|
|
258
|
+
|
|
259
|
+
For full license terms, see the main LICENSE.md file in the project root.
|
|
260
|
+
|
|
175
261
|
|
|
@@ -1,33 +1,142 @@
|
|
|
1
1
|
import { Track } from '../core/track/track';
|
|
2
2
|
import { TrackElement } from '../core/elements/base.element';
|
|
3
|
-
import { ProjectJSON, TrackJSON } from '../types';
|
|
3
|
+
import { ProjectJSON, Size, TrackJSON } from '../types';
|
|
4
4
|
import { TimelineEditor } from '../core/editor/timeline.editor';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Type definition for the Timeline context.
|
|
8
|
+
* Contains all the state and functions needed to manage a timeline instance.
|
|
9
|
+
* Provides access to the timeline editor, selected items, undo/redo functionality,
|
|
10
|
+
* and timeline actions.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```js
|
|
14
|
+
* const {
|
|
15
|
+
* editor,
|
|
16
|
+
* selectedItem,
|
|
17
|
+
* totalDuration,
|
|
18
|
+
* canUndo,
|
|
19
|
+
* canRedo,
|
|
20
|
+
* setSelectedItem,
|
|
21
|
+
* setTimelineAction
|
|
22
|
+
* } = useTimelineContext();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
6
25
|
export type TimelineContextType = {
|
|
26
|
+
/** Unique identifier for this timeline context */
|
|
7
27
|
contextId: string;
|
|
28
|
+
/** The timeline editor instance for this context */
|
|
8
29
|
editor: TimelineEditor;
|
|
30
|
+
/** Currently selected track or element */
|
|
9
31
|
selectedItem: Track | TrackElement | null;
|
|
32
|
+
/** Change counter for tracking modifications */
|
|
10
33
|
changeLog: number;
|
|
34
|
+
/** Current timeline action being performed */
|
|
11
35
|
timelineAction: {
|
|
12
36
|
type: string;
|
|
13
37
|
payload: any;
|
|
14
38
|
};
|
|
39
|
+
/** Resolution of the video */
|
|
40
|
+
videoResolution: Size;
|
|
41
|
+
/** Total duration of the timeline in seconds */
|
|
15
42
|
totalDuration: number;
|
|
43
|
+
/** Current project state */
|
|
16
44
|
present: ProjectJSON | null;
|
|
45
|
+
/** Whether undo operation is available */
|
|
17
46
|
canUndo: boolean;
|
|
47
|
+
/** Whether redo operation is available */
|
|
18
48
|
canRedo: boolean;
|
|
49
|
+
/** Function to set the selected item */
|
|
19
50
|
setSelectedItem: (item: Track | TrackElement | null) => void;
|
|
51
|
+
/** Function to set timeline actions */
|
|
20
52
|
setTimelineAction: (type: string, payload: any) => void;
|
|
53
|
+
/** Function to set the video resolution */
|
|
54
|
+
setVideoResolution: (size: Size) => void;
|
|
21
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Props for the TimelineProvider component.
|
|
58
|
+
* Defines the configuration options for timeline context initialization.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```jsx
|
|
62
|
+
* <TimelineProvider
|
|
63
|
+
* contextId="my-timeline"
|
|
64
|
+
* initialData={{ tracks: [], version: 1 }}
|
|
65
|
+
* undoRedoPersistenceKey="timeline-state"
|
|
66
|
+
* maxHistorySize={50}
|
|
67
|
+
* >
|
|
68
|
+
* <YourApp />
|
|
69
|
+
* </TimelineProvider>
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
22
72
|
export interface TimelineProviderProps {
|
|
73
|
+
/** React children to wrap with timeline context */
|
|
23
74
|
children: React.ReactNode;
|
|
75
|
+
/** Unique identifier for this timeline context */
|
|
24
76
|
contextId: string;
|
|
77
|
+
/** resolution of the video */
|
|
78
|
+
resolution?: Size;
|
|
79
|
+
/** Initial timeline data to load */
|
|
25
80
|
initialData?: {
|
|
26
81
|
tracks: TrackJSON[];
|
|
27
82
|
version: number;
|
|
28
83
|
};
|
|
84
|
+
/** Key for persisting undo/redo state */
|
|
29
85
|
undoRedoPersistenceKey?: string;
|
|
86
|
+
/** Maximum number of history states to keep */
|
|
30
87
|
maxHistorySize?: number;
|
|
31
88
|
}
|
|
32
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Provider component for the Timeline context.
|
|
91
|
+
* Wraps the timeline functionality with PostHog analytics and undo/redo support.
|
|
92
|
+
* Manages the global state for timeline instances including tracks, elements,
|
|
93
|
+
* playback state, and history management.
|
|
94
|
+
*
|
|
95
|
+
* @param props - Timeline provider configuration
|
|
96
|
+
* @returns Context provider with timeline state management
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```jsx
|
|
100
|
+
* <TimelineProvider
|
|
101
|
+
* contextId="my-timeline"
|
|
102
|
+
* initialData={{ tracks: [], version: 1 }}
|
|
103
|
+
* undoRedoPersistenceKey="timeline-state"
|
|
104
|
+
* >
|
|
105
|
+
* <YourApp />
|
|
106
|
+
* </TimelineProvider>
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare const TimelineProvider: ({ contextId, children, resolution, initialData, undoRedoPersistenceKey, maxHistorySize, }: TimelineProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
110
|
+
/**
|
|
111
|
+
* Hook to access the Timeline context.
|
|
112
|
+
* Provides access to timeline state, editor instance, and timeline management functions.
|
|
113
|
+
* Must be used within a TimelineProvider component.
|
|
114
|
+
*
|
|
115
|
+
* @returns TimelineContextType object with all timeline state and controls
|
|
116
|
+
* @throws Error if used outside of TimelineProvider
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```js
|
|
120
|
+
* const {
|
|
121
|
+
* editor,
|
|
122
|
+
* selectedItem,
|
|
123
|
+
* totalDuration,
|
|
124
|
+
* canUndo,
|
|
125
|
+
* canRedo,
|
|
126
|
+
* setSelectedItem,
|
|
127
|
+
* setTimelineAction
|
|
128
|
+
* } = useTimelineContext();
|
|
129
|
+
*
|
|
130
|
+
* // Access the timeline editor
|
|
131
|
+
* const tracks = editor.getTracks();
|
|
132
|
+
*
|
|
133
|
+
* // Check if undo is available
|
|
134
|
+
* if (canUndo) {
|
|
135
|
+
* editor.undo();
|
|
136
|
+
* }
|
|
137
|
+
*
|
|
138
|
+
* // Set timeline action
|
|
139
|
+
* setTimelineAction(TIMELINE_ACTION.SET_PLAYER_STATE, { playing: true });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
33
142
|
export declare const useTimelineContext: () => TimelineContextType;
|
|
@@ -3,6 +3,7 @@ import { Animation } from '../../types';
|
|
|
3
3
|
export declare class ElementAnimation {
|
|
4
4
|
private name;
|
|
5
5
|
private interval?;
|
|
6
|
+
private duration?;
|
|
6
7
|
private intensity?;
|
|
7
8
|
private animate?;
|
|
8
9
|
private mode?;
|
|
@@ -10,11 +11,13 @@ export declare class ElementAnimation {
|
|
|
10
11
|
constructor(name: string);
|
|
11
12
|
getName(): string;
|
|
12
13
|
getInterval(): number | undefined;
|
|
14
|
+
getDuration(): number | undefined;
|
|
13
15
|
getIntensity(): number | undefined;
|
|
14
16
|
getAnimate(): "enter" | "exit" | "both" | undefined;
|
|
15
17
|
getMode(): "in" | "out" | undefined;
|
|
16
18
|
getDirection(): "left" | "center" | "right" | "up" | "down" | undefined;
|
|
17
19
|
setInterval(interval?: number): this;
|
|
20
|
+
setDuration(duration?: number): this;
|
|
18
21
|
setIntensity(intensity?: number): this;
|
|
19
22
|
setAnimate(animate?: "enter" | "exit" | "both"): this;
|
|
20
23
|
setMode(mode?: "in" | "out"): this;
|
|
@@ -33,7 +33,7 @@ export declare class TimelineEditor {
|
|
|
33
33
|
getTimelineData(): TimelineTrackData | null;
|
|
34
34
|
getLatestVersion(): number;
|
|
35
35
|
protected setTimelineData(tracks: Track[], version?: number): TimelineTrackData;
|
|
36
|
-
addTrack(name: string): Track;
|
|
36
|
+
addTrack(name: string, type?: string): Track;
|
|
37
37
|
getTrackById(id: string): Track | null;
|
|
38
38
|
getTrackByName(name: string): Track | null;
|
|
39
39
|
removeTrackById(id: string): void;
|
|
@@ -58,9 +58,9 @@ export declare class TimelineEditor {
|
|
|
58
58
|
/**
|
|
59
59
|
* Update an element in a specific track using the visitor pattern
|
|
60
60
|
* @param element The updated element
|
|
61
|
-
* @returns
|
|
61
|
+
* @returns TrackElement the updated element
|
|
62
62
|
*/
|
|
63
|
-
updateElement(element: TrackElement):
|
|
63
|
+
updateElement(element: TrackElement): TrackElement;
|
|
64
64
|
/**
|
|
65
65
|
* Split an element at a specific time point using the visitor pattern
|
|
66
66
|
* @param element The element to split
|
|
@@ -23,6 +23,8 @@ export declare abstract class TrackElement {
|
|
|
23
23
|
getName(): string;
|
|
24
24
|
getAnimation(): ElementAnimation | undefined;
|
|
25
25
|
getPosition(): Position;
|
|
26
|
+
getRotation(): number;
|
|
27
|
+
getOpacity(): number;
|
|
26
28
|
setId(id: string): this;
|
|
27
29
|
setType(type: string): this;
|
|
28
30
|
setStart(s: number): this;
|
|
@@ -31,5 +33,7 @@ export declare abstract class TrackElement {
|
|
|
31
33
|
setName(name: string): this;
|
|
32
34
|
setAnimation(animation?: ElementAnimation): this;
|
|
33
35
|
setPosition(position: Position): this;
|
|
36
|
+
setRotation(rotation: number): this;
|
|
37
|
+
setOpacity(opacity: number): this;
|
|
34
38
|
setProps(props: Record<string, any>): this;
|
|
35
39
|
}
|
|
@@ -7,7 +7,11 @@ export declare class CircleElement extends TrackElement {
|
|
|
7
7
|
constructor(fill: string, radius: number);
|
|
8
8
|
getFill(): string;
|
|
9
9
|
getRadius(): number;
|
|
10
|
+
getStrokeColor(): string;
|
|
11
|
+
getLineWidth(): number;
|
|
10
12
|
setFill(fill: string): this;
|
|
11
13
|
setRadius(radius: number): this;
|
|
14
|
+
setStrokeColor(strokeColor: string): this;
|
|
15
|
+
setLineWidth(lineWidth: number): this;
|
|
12
16
|
accept<T>(visitor: ElementVisitor<T>): T;
|
|
13
17
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { TrackElement } from './base.element';
|
|
2
2
|
import { ElementVisitor } from '../visitor/element-visitor';
|
|
3
|
-
import {
|
|
3
|
+
import { Size } from '../../types';
|
|
4
4
|
|
|
5
5
|
export declare class IconElement extends TrackElement {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
constructor(src: string, size: Size, fill?: string);
|
|
7
|
+
getSrc(): string;
|
|
8
|
+
getFill(): string;
|
|
9
|
+
getSize(): Size | undefined;
|
|
10
|
+
setSrc(src: string): this;
|
|
11
|
+
setFill(fill: string): this;
|
|
12
|
+
setSize(size: Size): this;
|
|
8
13
|
accept<T>(visitor: ElementVisitor<T>): T;
|
|
9
14
|
}
|
|
@@ -5,7 +5,15 @@ import { ElementVisitor } from '../visitor/element-visitor';
|
|
|
5
5
|
export declare class RectElement extends TrackElement {
|
|
6
6
|
protected props: RectProps;
|
|
7
7
|
constructor(fill: string, size: Size);
|
|
8
|
+
getFill(): string;
|
|
8
9
|
setFill(fill: string): this;
|
|
10
|
+
getSize(): Size;
|
|
11
|
+
getCornerRadius(): number;
|
|
12
|
+
getStrokeColor(): string;
|
|
13
|
+
getLineWidth(): number;
|
|
9
14
|
setSize(size: Size): this;
|
|
15
|
+
setCornerRadius(cornerRadius: number): this;
|
|
16
|
+
setStrokeColor(strokeColor: string): this;
|
|
17
|
+
setLineWidth(lineWidth: number): this;
|
|
10
18
|
accept<T>(visitor: ElementVisitor<T>): T;
|
|
11
19
|
}
|