@twick/timeline 0.14.2 → 0.14.3

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.
@@ -1,55 +1,192 @@
1
+ /**
2
+ * Player state constants for timeline playback control.
3
+ * Defines the different states that a timeline player can be in during playback.
4
+ *
5
+ * @example
6
+ * ```js
7
+ * import { PLAYER_STATE } from '@twick/timeline';
8
+ *
9
+ * if (playerState === PLAYER_STATE.PLAYING) {
10
+ * console.log('Timeline is currently playing');
11
+ * }
12
+ * ```
13
+ */
1
14
  export declare const PLAYER_STATE: {
2
- REFRESH: string;
3
- PLAYING: string;
4
- PAUSED: string;
15
+ /** Player is refreshing/reloading content */
16
+ readonly REFRESH: "Refresh";
17
+ /** Player is actively playing content */
18
+ readonly PLAYING: "Playing";
19
+ /** Player is paused */
20
+ readonly PAUSED: "Paused";
5
21
  };
22
+ /**
23
+ * Caption styling options for text elements.
24
+ * Defines different visual styles for caption text rendering.
25
+ *
26
+ * @example
27
+ * ```js
28
+ * import { CAPTION_STYLE } from '@twick/timeline';
29
+ *
30
+ * const captionElement = new CaptionElement({
31
+ * style: CAPTION_STYLE.WORD_BY_WORD
32
+ * });
33
+ * ```
34
+ */
6
35
  export declare const CAPTION_STYLE: {
7
- WORD_BG_HIGHLIGHT: string;
8
- WORD_BY_WORD: string;
9
- WORD_BY_WORD_WITH_BG: string;
36
+ /** Highlights background of each word */
37
+ readonly WORD_BG_HIGHLIGHT: "highlight_bg";
38
+ /** Animates text word by word */
39
+ readonly WORD_BY_WORD: "word_by_word";
40
+ /** Animates text word by word with background highlighting */
41
+ readonly WORD_BY_WORD_WITH_BG: "word_by_word_with_bg";
10
42
  };
43
+ /**
44
+ * Human-readable options for caption styles.
45
+ * Provides user-friendly labels for caption style selection.
46
+ *
47
+ * @example
48
+ * ```js
49
+ * import { CAPTION_STYLE_OPTIONS } from '@twick/timeline';
50
+ *
51
+ * const options = Object.values(CAPTION_STYLE_OPTIONS);
52
+ * // Returns array of style options with labels
53
+ * ```
54
+ */
11
55
  export declare const CAPTION_STYLE_OPTIONS: {
12
- [CAPTION_STYLE.WORD_BG_HIGHLIGHT]: {
13
- label: string;
14
- value: string;
56
+ readonly highlight_bg: {
57
+ readonly label: "Highlight Background";
58
+ readonly value: "highlight_bg";
15
59
  };
16
- [CAPTION_STYLE.WORD_BY_WORD]: {
17
- label: string;
18
- value: string;
60
+ readonly word_by_word: {
61
+ readonly label: "Word by Word";
62
+ readonly value: "word_by_word";
19
63
  };
20
- [CAPTION_STYLE.WORD_BY_WORD_WITH_BG]: {
21
- label: string;
22
- value: string;
64
+ readonly word_by_word_with_bg: {
65
+ readonly label: "Word with Background";
66
+ readonly value: "word_by_word_with_bg";
23
67
  };
24
68
  };
69
+ /**
70
+ * Default font settings for caption elements.
71
+ * Defines the standard typography configuration for captions.
72
+ *
73
+ * @example
74
+ * ```js
75
+ * import { CAPTION_FONT } from '@twick/timeline';
76
+ *
77
+ * const fontSize = CAPTION_FONT.size; // 40
78
+ * ```
79
+ */
25
80
  export declare const CAPTION_FONT: {
26
- size: number;
81
+ /** Font size in pixels */
82
+ readonly size: 40;
27
83
  };
84
+ /**
85
+ * Default color scheme for caption elements.
86
+ * Defines the standard color palette for caption text and backgrounds.
87
+ *
88
+ * @example
89
+ * ```js
90
+ * import { CAPTION_COLOR } from '@twick/timeline';
91
+ *
92
+ * const textColor = CAPTION_COLOR.text; // "#ffffff"
93
+ * const highlightColor = CAPTION_COLOR.highlight; // "#ff4081"
94
+ * ```
95
+ */
28
96
  export declare const CAPTION_COLOR: {
29
- text: string;
30
- highlight: string;
31
- bgColor: string;
97
+ /** Text color in hex format */
98
+ readonly text: "#ffffff";
99
+ /** Highlight color in hex format */
100
+ readonly highlight: "#ff4081";
101
+ /** Background color in hex format */
102
+ readonly bgColor: "#8C52FF";
32
103
  };
104
+ /**
105
+ * Number of words to display per phrase in caption animations.
106
+ * Controls the chunking of text for word-by-word animations.
107
+ *
108
+ * @example
109
+ * ```js
110
+ * import { WORDS_PER_PHRASE } from '@twick/timeline';
111
+ *
112
+ * const phraseLength = WORDS_PER_PHRASE; // 4
113
+ * ```
114
+ */
33
115
  export declare const WORDS_PER_PHRASE = 4;
116
+ /**
117
+ * Timeline action types for state management.
118
+ * Defines the different actions that can be performed on the timeline.
119
+ *
120
+ * @example
121
+ * ```js
122
+ * import { TIMELINE_ACTION } from '@twick/timeline';
123
+ *
124
+ * if (action.type === TIMELINE_ACTION.SET_PLAYER_STATE) {
125
+ * // Handle player state change
126
+ * }
127
+ * ```
128
+ */
34
129
  export declare const TIMELINE_ACTION: {
35
- NONE: string;
36
- SET_PLAYER_STATE: string;
37
- UPDATE_PLAYER_DATA: string;
38
- ON_PLAYER_UPDATED: string;
130
+ /** No action being performed */
131
+ readonly NONE: "none";
132
+ /** Setting the player state (play/pause) */
133
+ readonly SET_PLAYER_STATE: "setPlayerState";
134
+ /** Updating player data */
135
+ readonly UPDATE_PLAYER_DATA: "updatePlayerData";
136
+ /** Player has been updated */
137
+ readonly ON_PLAYER_UPDATED: "onPlayerUpdated";
39
138
  };
139
+ /**
140
+ * Element type constants for timeline elements.
141
+ * Defines the different types of elements that can be added to timeline tracks.
142
+ *
143
+ * @example
144
+ * ```js
145
+ * import { TIMELINE_ELEMENT_TYPE } from '@twick/timeline';
146
+ *
147
+ * if (element.type === TIMELINE_ELEMENT_TYPE.VIDEO) {
148
+ * // Handle video element
149
+ * }
150
+ * ```
151
+ */
40
152
  export declare const TIMELINE_ELEMENT_TYPE: {
41
- VIDEO: string;
42
- CAPTION: string;
43
- IMAGE: string;
44
- AUDIO: string;
45
- TEXT: string;
46
- RECT: string;
47
- CIRCLE: string;
48
- ICON: string;
153
+ /** Video element type */
154
+ readonly VIDEO: "video";
155
+ /** Caption element type */
156
+ readonly CAPTION: "caption";
157
+ /** Image element type */
158
+ readonly IMAGE: "image";
159
+ /** Audio element type */
160
+ readonly AUDIO: "audio";
161
+ /** Text element type */
162
+ readonly TEXT: "text";
163
+ /** Rectangle element type */
164
+ readonly RECT: "rect";
165
+ /** Circle element type */
166
+ readonly CIRCLE: "circle";
167
+ /** Icon element type */
168
+ readonly ICON: "icon";
49
169
  };
170
+ /**
171
+ * Process state constants for async operations.
172
+ * Defines the different states of background processing operations.
173
+ *
174
+ * @example
175
+ * ```js
176
+ * import { PROCESS_STATE } from '@twick/timeline';
177
+ *
178
+ * if (processState === PROCESS_STATE.PROCESSING) {
179
+ * // Show loading indicator
180
+ * }
181
+ * ```
182
+ */
50
183
  export declare const PROCESS_STATE: {
51
- IDLE: string;
52
- PROCESSING: string;
53
- COMPLETED: string;
54
- FAILED: string;
184
+ /** Process is idle */
185
+ readonly IDLE: "Idle";
186
+ /** Process is currently running */
187
+ readonly PROCESSING: "Processing";
188
+ /** Process has completed successfully */
189
+ readonly COMPLETED: "Completed";
190
+ /** Process has failed */
191
+ readonly FAILED: "Failed";
55
192
  };
@@ -2,11 +2,123 @@ import { TrackElement } from '../core/elements/base.element';
2
2
  import { Track } from '../core/track/track';
3
3
  import { TrackJSON } from '../types';
4
4
 
5
+ /**
6
+ * Rounds a number to a specified decimal precision.
7
+ * Useful for ensuring consistent decimal places in timeline calculations.
8
+ *
9
+ * @param num - The number to round
10
+ * @param precision - The number of decimal places to round to
11
+ * @returns The rounded number
12
+ *
13
+ * @example
14
+ * ```js
15
+ * const rounded = getDecimalNumber(3.14159, 2);
16
+ * // rounded = 3.14
17
+ * ```
18
+ */
5
19
  export declare const getDecimalNumber: (num: number, precision?: number) => number;
20
+ /**
21
+ * Calculates the total duration of all tracks in a timeline.
22
+ * Finds the maximum end time across all elements in all tracks
23
+ * to determine the overall timeline duration.
24
+ *
25
+ * @param tracks - Array of track data containing elements
26
+ * @returns The total duration in seconds
27
+ *
28
+ * @example
29
+ * ```js
30
+ * const duration = getTotalDuration(tracks);
31
+ * // duration = 120.5 (2 minutes and 0.5 seconds)
32
+ * ```
33
+ */
6
34
  export declare const getTotalDuration: (tracks: TrackJSON[]) => number;
35
+ /**
36
+ * Generates a short UUID for element and track identification.
37
+ * Creates a 12-character unique identifier using a simplified
38
+ * UUID generation algorithm.
39
+ *
40
+ * @returns A 12-character unique identifier string
41
+ *
42
+ * @example
43
+ * ```js
44
+ * const id = generateShortUuid();
45
+ * // id = "a1b2c3d4e5f6"
46
+ * ```
47
+ */
7
48
  export declare const generateShortUuid: () => string;
49
+ /**
50
+ * Gets all elements that are currently active at the specified time.
51
+ * Searches through all tracks to find elements whose time range
52
+ * includes the current playback time.
53
+ *
54
+ * @param currentTime - The current playback time in seconds
55
+ * @param tracks - Array of track objects to search through
56
+ * @returns Array of elements currently active at the specified time
57
+ *
58
+ * @example
59
+ * ```js
60
+ * const activeElements = getCurrentElements(5.5, tracks);
61
+ * // Returns all elements active at 5.5 seconds
62
+ * ```
63
+ */
8
64
  export declare const getCurrentElements: (currentTime: number, tracks: Track[]) => Array<Readonly<TrackElement>>;
65
+ /**
66
+ * Checks if an element can be split at the specified time.
67
+ * Determines if the current time falls within the element's
68
+ * start and end time range.
69
+ *
70
+ * @param element - The element to check for splitting
71
+ * @param currentTime - The time at which to check if splitting is possible
72
+ * @returns True if the element can be split at the specified time
73
+ *
74
+ * @example
75
+ * ```js
76
+ * const canSplit = canSplitElement(videoElement, 10.5);
77
+ * // canSplit = true if element spans across 10.5 seconds
78
+ * ```
79
+ */
9
80
  export declare const canSplitElement: (element: TrackElement, currentTime: number) => boolean;
81
+ /**
82
+ * Checks if an ID represents an element.
83
+ * Validates if the ID follows the element naming convention.
84
+ *
85
+ * @param id - The ID to check
86
+ * @returns True if the ID represents an element
87
+ *
88
+ * @example
89
+ * ```js
90
+ * const isElement = isElementId("e-abc123");
91
+ * // isElement = true
92
+ * ```
93
+ */
10
94
  export declare const isElementId: (id: string) => boolean;
95
+ /**
96
+ * Checks if an ID represents a track.
97
+ * Validates if the ID follows the track naming convention.
98
+ *
99
+ * @param id - The ID to check
100
+ * @returns True if the ID represents a track
101
+ *
102
+ * @example
103
+ * ```js
104
+ * const isTrack = isTrackId("t-xyz789");
105
+ * // isTrack = true
106
+ * ```
107
+ */
11
108
  export declare const isTrackId: (id: string) => boolean;
109
+ /**
110
+ * Extracts and stitches audio from video elements across all tracks.
111
+ * Processes all video elements in the timeline, extracts their audio segments,
112
+ * and combines them into a single audio file with proper timing.
113
+ *
114
+ * @param tracks - Array of track objects containing video elements
115
+ * @param duration - The total duration of the output audio
116
+ * @returns Promise resolving to a Blob URL of the combined audio
117
+ *
118
+ * @example
119
+ * ```js
120
+ * const audioUrl = await extractVideoAudio(tracks, 120);
121
+ * // audioUrl = "blob:http://localhost:3000/abc123"
122
+ * ```
123
+ */
12
124
  export declare const extractVideoAudio: (tracks: Track[], duration: number) => Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twick/timeline",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -8,7 +8,7 @@
8
8
  "sideEffects": [
9
9
  "**/*.css"
10
10
  ],
11
- "license": "Apache-2.0",
11
+ "license": "SEE LICENSE IN LICENSE.md",
12
12
  "files": [
13
13
  "dist"
14
14
  ],
@@ -20,10 +20,10 @@
20
20
  "dev": "vite build --watch",
21
21
  "lint": "eslint src/",
22
22
  "clean": "rimraf .turbo node_modules dist",
23
- "docs": "typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts"
23
+ "docs": "typedoc"
24
24
  },
25
25
  "dependencies": {
26
- "@twick/media-utils": "0.14.2",
26
+ "@twick/media-utils": "0.14.3",
27
27
  "posthog-js": "^1.258.5"
28
28
  },
29
29
  "devDependencies": {