@twick/timeline 0.14.0 → 0.14.2
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 +175 -175
- package/dist/core/addOns/animation.d.ts +5 -5
- package/dist/core/addOns/frame-effect.d.ts +3 -1
- package/dist/core/addOns/text-effect.d.ts +3 -4
- package/dist/core/editor/timeline.editor.d.ts +2 -0
- package/dist/core/elements/audio.element.d.ts +4 -0
- package/dist/core/elements/video.element.d.ts +4 -1
- package/dist/index-CXhwwSX--DHE9Xex3.js +14961 -0
- package/dist/index-CXhwwSX--DHE9Xex3.js.map +1 -0
- package/dist/index.js +19993 -190
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4953 -111
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/utils/timeline.utils.d.ts +1 -0
- package/package.json +41 -40
package/README.md
CHANGED
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
# @twick/timeline
|
|
2
|
-
|
|
3
|
-
## Timeline Editor CRUD Operations
|
|
4
|
-
|
|
5
|
-
The TimelineEditor provides a clean interface for managing tracks and elements using the visitor pattern.
|
|
6
|
-
|
|
7
|
-
### Track Operations
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import { TimelineEditor, TimelineOperationContext } from '@twick/timeline';
|
|
11
|
-
|
|
12
|
-
// Create editor with context
|
|
13
|
-
const context: TimelineOperationContext = {
|
|
14
|
-
contextId: 'my-editor',
|
|
15
|
-
setTotalDuration: (duration) => console.log('Duration:', duration),
|
|
16
|
-
setPresent: (data) => console.log('Present:', data),
|
|
17
|
-
handleUndo: () => console.log('Undo'),
|
|
18
|
-
handleRedo: () => console.log('Redo'),
|
|
19
|
-
handleResetHistory: () => console.log('Reset History'),
|
|
20
|
-
setLatestProjectVersion: (version) => console.log('Version:', version),
|
|
21
|
-
setTimelineAction: (action, payload) => console.log('Action:', action, payload),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const editor = new TimelineEditor(context);
|
|
25
|
-
|
|
26
|
-
// Create a new track
|
|
27
|
-
const track = editor.addTrack('My Video Track');
|
|
28
|
-
|
|
29
|
-
// Get track by ID
|
|
30
|
-
const trackById = editor.getTrackById(track.getId());
|
|
31
|
-
|
|
32
|
-
// Get track by name
|
|
33
|
-
const trackByName = editor.getTrackByName('My Video Track');
|
|
34
|
-
|
|
35
|
-
// Remove track
|
|
36
|
-
editor.removeTrackById(track.getId());
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Element Operations (Using Visitor Pattern)
|
|
40
|
-
|
|
41
|
-
The TimelineEditor uses the visitor pattern to handle different element types consistently:
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
import {
|
|
45
|
-
TimelineEditor,
|
|
46
|
-
TextElement,
|
|
47
|
-
VideoElement,
|
|
48
|
-
ImageElement,
|
|
49
|
-
AudioElement,
|
|
50
|
-
TrackElement
|
|
51
|
-
} from '@twick/timeline';
|
|
52
|
-
|
|
53
|
-
// Add elements to track
|
|
54
|
-
const textElement = new TextElement('Hello World')
|
|
55
|
-
.setStart(0)
|
|
56
|
-
.setEnd(5)
|
|
57
|
-
.setName('Welcome Text');
|
|
58
|
-
|
|
59
|
-
const videoElement = new VideoElement('video.mp4', { width: 720, height: 480 })
|
|
60
|
-
.setStart(0)
|
|
61
|
-
.setEnd(30)
|
|
62
|
-
.setName('Main Video');
|
|
63
|
-
|
|
64
|
-
// Add elements using visitor pattern
|
|
65
|
-
await editor.addElementToTrack(track.getId(), textElement);
|
|
66
|
-
await editor.addElementToTrack(track.getId(), videoElement);
|
|
67
|
-
|
|
68
|
-
// Update elements
|
|
69
|
-
const updatedTextElement = new TextElement('Updated Text')
|
|
70
|
-
.setId(textElement.getId()) // Keep same ID
|
|
71
|
-
.setStart(0)
|
|
72
|
-
.setEnd(8)
|
|
73
|
-
.setName('Updated Welcome Text');
|
|
74
|
-
|
|
75
|
-
editor.updateElementInTrack(track.getId(), updatedTextElement);
|
|
76
|
-
|
|
77
|
-
// Remove elements
|
|
78
|
-
editor.removeElementFromTrack(track.getId(), textElement);
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Complete CRUD Example
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
// Create editor and track
|
|
85
|
-
const editor = new TimelineEditor(context);
|
|
86
|
-
const track = editor.addTrack('Demo Track');
|
|
87
|
-
|
|
88
|
-
// Create elements
|
|
89
|
-
const textElement = new TextElement('Sample Text')
|
|
90
|
-
.setStart(0)
|
|
91
|
-
.setEnd(5)
|
|
92
|
-
.setName('Sample Text Element');
|
|
93
|
-
|
|
94
|
-
const imageElement = new ImageElement('image.jpg', { width: 300, height: 200 })
|
|
95
|
-
.setStart(5)
|
|
96
|
-
.setEnd(10)
|
|
97
|
-
.setName('Sample Image');
|
|
98
|
-
|
|
99
|
-
// Add elements
|
|
100
|
-
await editor.addElementToTrack(track.getId(), textElement);
|
|
101
|
-
await editor.addElementToTrack(track.getId(), imageElement);
|
|
102
|
-
|
|
103
|
-
// Update element
|
|
104
|
-
const updatedText = new TextElement('Updated Sample Text')
|
|
105
|
-
.setId(textElement.getId())
|
|
106
|
-
.setStart(0)
|
|
107
|
-
.setEnd(8)
|
|
108
|
-
.setName('Updated Text Element');
|
|
109
|
-
|
|
110
|
-
editor.updateElementInTrack(track.getId(), updatedText);
|
|
111
|
-
|
|
112
|
-
// Remove element
|
|
113
|
-
editor.removeElementFromTrack(track.getId(), imageElement);
|
|
114
|
-
|
|
115
|
-
// Get timeline data
|
|
116
|
-
const timelineData = editor.getTimelineData();
|
|
117
|
-
console.log('Timeline:', timelineData);
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Utility Functions
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
import {
|
|
124
|
-
getCurrentElements,
|
|
125
|
-
getTotalDuration,
|
|
126
|
-
generateShortUuid,
|
|
127
|
-
isElementId,
|
|
128
|
-
isTrackId
|
|
129
|
-
} from '@twick/timeline';
|
|
130
|
-
|
|
131
|
-
// Get elements currently playing at a specific time
|
|
132
|
-
const currentElements = getCurrentElements(currentTime, tracks);
|
|
133
|
-
|
|
134
|
-
// Get total duration of all tracks
|
|
135
|
-
const totalDuration = getTotalDuration(trackData);
|
|
136
|
-
|
|
137
|
-
// Generate unique IDs
|
|
138
|
-
const elementId = generateShortUuid(); // "e-xxxxxxxxxxxx"
|
|
139
|
-
const trackId = generateShortUuid(); // "t-xxxxxxxxxxxx"
|
|
140
|
-
|
|
141
|
-
// Check ID types
|
|
142
|
-
isElementId('e-123456789abc'); // true
|
|
143
|
-
isTrackId('t-123456789abc'); // true
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Visitor Pattern Benefits
|
|
147
|
-
|
|
148
|
-
- **Type Safety**: Each element type is handled specifically
|
|
149
|
-
- **Extensibility**: Easy to add new element types
|
|
150
|
-
- **Consistency**: Same pattern for all CRUD operations
|
|
151
|
-
- **Maintainability**: Clean separation of concerns
|
|
152
|
-
|
|
153
|
-
### React Hook Usage
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
import { useTimelineContext } from '@twick/timeline';
|
|
157
|
-
|
|
158
|
-
function MyComponent() {
|
|
159
|
-
const { editor } = useTimelineContext();
|
|
160
|
-
|
|
161
|
-
// Use editor methods
|
|
162
|
-
const track = editor.addTrack('My Track');
|
|
163
|
-
|
|
164
|
-
// Add elements
|
|
165
|
-
const textElement = new TextElement('Hello World')
|
|
166
|
-
.setStart(0)
|
|
167
|
-
.setEnd(5);
|
|
168
|
-
|
|
169
|
-
await editor.addElementToTrack(track.getId(), textElement);
|
|
170
|
-
|
|
171
|
-
return <div>Timeline Editor Ready</div>;
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
|
|
1
|
+
# @twick/timeline
|
|
2
|
+
|
|
3
|
+
## Timeline Editor CRUD Operations
|
|
4
|
+
|
|
5
|
+
The TimelineEditor provides a clean interface for managing tracks and elements using the visitor pattern.
|
|
6
|
+
|
|
7
|
+
### Track Operations
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { TimelineEditor, TimelineOperationContext } from '@twick/timeline';
|
|
11
|
+
|
|
12
|
+
// Create editor with context
|
|
13
|
+
const context: TimelineOperationContext = {
|
|
14
|
+
contextId: 'my-editor',
|
|
15
|
+
setTotalDuration: (duration) => console.log('Duration:', duration),
|
|
16
|
+
setPresent: (data) => console.log('Present:', data),
|
|
17
|
+
handleUndo: () => console.log('Undo'),
|
|
18
|
+
handleRedo: () => console.log('Redo'),
|
|
19
|
+
handleResetHistory: () => console.log('Reset History'),
|
|
20
|
+
setLatestProjectVersion: (version) => console.log('Version:', version),
|
|
21
|
+
setTimelineAction: (action, payload) => console.log('Action:', action, payload),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const editor = new TimelineEditor(context);
|
|
25
|
+
|
|
26
|
+
// Create a new track
|
|
27
|
+
const track = editor.addTrack('My Video Track');
|
|
28
|
+
|
|
29
|
+
// Get track by ID
|
|
30
|
+
const trackById = editor.getTrackById(track.getId());
|
|
31
|
+
|
|
32
|
+
// Get track by name
|
|
33
|
+
const trackByName = editor.getTrackByName('My Video Track');
|
|
34
|
+
|
|
35
|
+
// Remove track
|
|
36
|
+
editor.removeTrackById(track.getId());
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Element Operations (Using Visitor Pattern)
|
|
40
|
+
|
|
41
|
+
The TimelineEditor uses the visitor pattern to handle different element types consistently:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import {
|
|
45
|
+
TimelineEditor,
|
|
46
|
+
TextElement,
|
|
47
|
+
VideoElement,
|
|
48
|
+
ImageElement,
|
|
49
|
+
AudioElement,
|
|
50
|
+
TrackElement
|
|
51
|
+
} from '@twick/timeline';
|
|
52
|
+
|
|
53
|
+
// Add elements to track
|
|
54
|
+
const textElement = new TextElement('Hello World')
|
|
55
|
+
.setStart(0)
|
|
56
|
+
.setEnd(5)
|
|
57
|
+
.setName('Welcome Text');
|
|
58
|
+
|
|
59
|
+
const videoElement = new VideoElement('video.mp4', { width: 720, height: 480 })
|
|
60
|
+
.setStart(0)
|
|
61
|
+
.setEnd(30)
|
|
62
|
+
.setName('Main Video');
|
|
63
|
+
|
|
64
|
+
// Add elements using visitor pattern
|
|
65
|
+
await editor.addElementToTrack(track.getId(), textElement);
|
|
66
|
+
await editor.addElementToTrack(track.getId(), videoElement);
|
|
67
|
+
|
|
68
|
+
// Update elements
|
|
69
|
+
const updatedTextElement = new TextElement('Updated Text')
|
|
70
|
+
.setId(textElement.getId()) // Keep same ID
|
|
71
|
+
.setStart(0)
|
|
72
|
+
.setEnd(8)
|
|
73
|
+
.setName('Updated Welcome Text');
|
|
74
|
+
|
|
75
|
+
editor.updateElementInTrack(track.getId(), updatedTextElement);
|
|
76
|
+
|
|
77
|
+
// Remove elements
|
|
78
|
+
editor.removeElementFromTrack(track.getId(), textElement);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Complete CRUD Example
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Create editor and track
|
|
85
|
+
const editor = new TimelineEditor(context);
|
|
86
|
+
const track = editor.addTrack('Demo Track');
|
|
87
|
+
|
|
88
|
+
// Create elements
|
|
89
|
+
const textElement = new TextElement('Sample Text')
|
|
90
|
+
.setStart(0)
|
|
91
|
+
.setEnd(5)
|
|
92
|
+
.setName('Sample Text Element');
|
|
93
|
+
|
|
94
|
+
const imageElement = new ImageElement('image.jpg', { width: 300, height: 200 })
|
|
95
|
+
.setStart(5)
|
|
96
|
+
.setEnd(10)
|
|
97
|
+
.setName('Sample Image');
|
|
98
|
+
|
|
99
|
+
// Add elements
|
|
100
|
+
await editor.addElementToTrack(track.getId(), textElement);
|
|
101
|
+
await editor.addElementToTrack(track.getId(), imageElement);
|
|
102
|
+
|
|
103
|
+
// Update element
|
|
104
|
+
const updatedText = new TextElement('Updated Sample Text')
|
|
105
|
+
.setId(textElement.getId())
|
|
106
|
+
.setStart(0)
|
|
107
|
+
.setEnd(8)
|
|
108
|
+
.setName('Updated Text Element');
|
|
109
|
+
|
|
110
|
+
editor.updateElementInTrack(track.getId(), updatedText);
|
|
111
|
+
|
|
112
|
+
// Remove element
|
|
113
|
+
editor.removeElementFromTrack(track.getId(), imageElement);
|
|
114
|
+
|
|
115
|
+
// Get timeline data
|
|
116
|
+
const timelineData = editor.getTimelineData();
|
|
117
|
+
console.log('Timeline:', timelineData);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Utility Functions
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import {
|
|
124
|
+
getCurrentElements,
|
|
125
|
+
getTotalDuration,
|
|
126
|
+
generateShortUuid,
|
|
127
|
+
isElementId,
|
|
128
|
+
isTrackId
|
|
129
|
+
} from '@twick/timeline';
|
|
130
|
+
|
|
131
|
+
// Get elements currently playing at a specific time
|
|
132
|
+
const currentElements = getCurrentElements(currentTime, tracks);
|
|
133
|
+
|
|
134
|
+
// Get total duration of all tracks
|
|
135
|
+
const totalDuration = getTotalDuration(trackData);
|
|
136
|
+
|
|
137
|
+
// Generate unique IDs
|
|
138
|
+
const elementId = generateShortUuid(); // "e-xxxxxxxxxxxx"
|
|
139
|
+
const trackId = generateShortUuid(); // "t-xxxxxxxxxxxx"
|
|
140
|
+
|
|
141
|
+
// Check ID types
|
|
142
|
+
isElementId('e-123456789abc'); // true
|
|
143
|
+
isTrackId('t-123456789abc'); // true
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Visitor Pattern Benefits
|
|
147
|
+
|
|
148
|
+
- **Type Safety**: Each element type is handled specifically
|
|
149
|
+
- **Extensibility**: Easy to add new element types
|
|
150
|
+
- **Consistency**: Same pattern for all CRUD operations
|
|
151
|
+
- **Maintainability**: Clean separation of concerns
|
|
152
|
+
|
|
153
|
+
### React Hook Usage
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { useTimelineContext } from '@twick/timeline';
|
|
157
|
+
|
|
158
|
+
function MyComponent() {
|
|
159
|
+
const { editor } = useTimelineContext();
|
|
160
|
+
|
|
161
|
+
// Use editor methods
|
|
162
|
+
const track = editor.addTrack('My Track');
|
|
163
|
+
|
|
164
|
+
// Add elements
|
|
165
|
+
const textElement = new TextElement('Hello World')
|
|
166
|
+
.setStart(0)
|
|
167
|
+
.setEnd(5);
|
|
168
|
+
|
|
169
|
+
await editor.addElementToTrack(track.getId(), textElement);
|
|
170
|
+
|
|
171
|
+
return <div>Timeline Editor Ready</div>;
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
|
|
@@ -14,11 +14,11 @@ export declare class ElementAnimation {
|
|
|
14
14
|
getAnimate(): "enter" | "exit" | "both" | undefined;
|
|
15
15
|
getMode(): "in" | "out" | undefined;
|
|
16
16
|
getDirection(): "left" | "center" | "right" | "up" | "down" | undefined;
|
|
17
|
-
setInterval(interval?: number):
|
|
18
|
-
setIntensity(intensity?: number):
|
|
19
|
-
setAnimate(animate?: "enter" | "exit" | "both"):
|
|
20
|
-
setMode(mode?: "in" | "out"):
|
|
21
|
-
setDirection(direction?: "up" | "down" | "left" | "right" | "center"):
|
|
17
|
+
setInterval(interval?: number): this;
|
|
18
|
+
setIntensity(intensity?: number): this;
|
|
19
|
+
setAnimate(animate?: "enter" | "exit" | "both"): this;
|
|
20
|
+
setMode(mode?: "in" | "out"): this;
|
|
21
|
+
setDirection(direction?: "up" | "down" | "left" | "right" | "center"): this;
|
|
22
22
|
toJSON(): Animation;
|
|
23
23
|
static fromJSON(json: Animation): ElementAnimation;
|
|
24
24
|
}
|
|
@@ -5,10 +5,12 @@ export declare class ElementFrameEffect {
|
|
|
5
5
|
private e;
|
|
6
6
|
private props;
|
|
7
7
|
constructor(start: number, end: number);
|
|
8
|
-
setProps(props: FrameEffectProps):
|
|
8
|
+
setProps(props: FrameEffectProps): this;
|
|
9
9
|
getProps(): FrameEffectProps;
|
|
10
10
|
getStart(): number;
|
|
11
11
|
getEnd(): number;
|
|
12
|
+
setStart(start: number): this;
|
|
13
|
+
setEnd(end: number): this;
|
|
12
14
|
toJSON(): FrameEffect;
|
|
13
15
|
static fromJSON(json: FrameEffect): ElementFrameEffect;
|
|
14
16
|
}
|
|
@@ -10,10 +10,9 @@ export declare class ElementTextEffect {
|
|
|
10
10
|
getDuration(): number | undefined;
|
|
11
11
|
getDelay(): number | undefined;
|
|
12
12
|
getBufferTime(): number | undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setBufferTime(bufferTime?: number): void;
|
|
13
|
+
setDuration(duration?: number): this;
|
|
14
|
+
setDelay(delay?: number): this;
|
|
15
|
+
setBufferTime(bufferTime?: number): this;
|
|
17
16
|
toJSON(): TextEffect;
|
|
18
17
|
static fromJSON(json: TextEffect): ElementTextEffect;
|
|
19
18
|
}
|
|
@@ -26,6 +26,7 @@ export interface TimelineOperationContext {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class TimelineEditor {
|
|
28
28
|
private context;
|
|
29
|
+
private totalDuration;
|
|
29
30
|
constructor(context: TimelineOperationContext);
|
|
30
31
|
getContext(): TimelineOperationContext;
|
|
31
32
|
pauseVideo(): void;
|
|
@@ -91,4 +92,5 @@ export declare class TimelineEditor {
|
|
|
91
92
|
tracks: TrackJSON[];
|
|
92
93
|
version: number;
|
|
93
94
|
}): void;
|
|
95
|
+
getVideoAudio(): Promise<string>;
|
|
94
96
|
}
|
|
@@ -8,6 +8,10 @@ export declare class AudioElement extends TrackElement {
|
|
|
8
8
|
constructor(src: string);
|
|
9
9
|
getMediaDuration(): number;
|
|
10
10
|
getStartAt(): number;
|
|
11
|
+
getEndAt(): number;
|
|
12
|
+
getSrc(): string;
|
|
13
|
+
getPlaybackRate(): number;
|
|
14
|
+
getVolume(): number;
|
|
11
15
|
updateAudioMeta(): Promise<void>;
|
|
12
16
|
setSrc(src: string): Promise<this>;
|
|
13
17
|
setMediaDuration(mediaDuration: number): this;
|
|
@@ -20,6 +20,10 @@ export declare class VideoElement extends TrackElement {
|
|
|
20
20
|
getObjectFit(): ObjectFit;
|
|
21
21
|
getMediaDuration(): number;
|
|
22
22
|
getStartAt(): number;
|
|
23
|
+
getEndAt(): number;
|
|
24
|
+
getSrc(): string;
|
|
25
|
+
getPlaybackRate(): number;
|
|
26
|
+
getVolume(): number;
|
|
23
27
|
getPosition(): Position;
|
|
24
28
|
updateVideoMeta(updateFrame?: boolean): Promise<void>;
|
|
25
29
|
setPosition(position: Position): this;
|
|
@@ -28,7 +32,6 @@ export declare class VideoElement extends TrackElement {
|
|
|
28
32
|
setParentSize(parentSize: Size): this;
|
|
29
33
|
setObjectFit(objectFit: ObjectFit): this;
|
|
30
34
|
setFrame(frame: Frame): this;
|
|
31
|
-
setPlay(play: boolean): this;
|
|
32
35
|
setPlaybackRate(playbackRate: number): this;
|
|
33
36
|
setStartAt(time: number): this;
|
|
34
37
|
setMediaFilter(mediaFilter: string): this;
|