@twick/timeline 0.14.6 → 0.14.8
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/dist/core/editor/timeline.editor.d.ts +1 -0
- package/dist/core/elements/text.element.d.ts +3 -1
- package/dist/core/track/track.d.ts +4 -0
- package/dist/core/visitor/element-validator.d.ts +8 -0
- package/dist/index.js +61 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -13
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +8 -1
- package/package.json +4 -4
|
@@ -40,6 +40,7 @@ export declare class TimelineEditor {
|
|
|
40
40
|
addTrack(name: string, type?: string): Track;
|
|
41
41
|
getTrackById(id: string): Track | null;
|
|
42
42
|
getTrackByName(name: string): Track | null;
|
|
43
|
+
getSubtiltesTrack(): Track | null;
|
|
43
44
|
removeTrackById(id: string): void;
|
|
44
45
|
removeTrack(track: Track): void;
|
|
45
46
|
/**
|
|
@@ -6,11 +6,12 @@ import { ElementTextEffect } from '../addOns/text-effect';
|
|
|
6
6
|
export declare class TextElement extends TrackElement {
|
|
7
7
|
protected textEffect?: ElementTextEffect;
|
|
8
8
|
protected props: TextProps;
|
|
9
|
-
constructor(text: string);
|
|
9
|
+
constructor(text: string, props?: Omit<TextProps, 'text'>);
|
|
10
10
|
getTextEffect(): ElementTextEffect | undefined;
|
|
11
11
|
getText(): string;
|
|
12
12
|
getStrokeColor(): string | undefined;
|
|
13
13
|
getLineWidth(): number | undefined;
|
|
14
|
+
getProps(): TextProps;
|
|
14
15
|
setText(text: string): this;
|
|
15
16
|
setFill(fill: string): this;
|
|
16
17
|
setRotation(rotation: number): this;
|
|
@@ -22,5 +23,6 @@ export declare class TextElement extends TrackElement {
|
|
|
22
23
|
setTextAlign(textAlign: TextAlign): this;
|
|
23
24
|
setStrokeColor(stroke: string): this;
|
|
24
25
|
setLineWidth(lineWidth: number): this;
|
|
26
|
+
setProps(props: TextProps): this;
|
|
25
27
|
accept<T>(visitor: ElementVisitor<T>): T;
|
|
26
28
|
}
|
|
@@ -32,6 +32,7 @@ export declare class Track {
|
|
|
32
32
|
private id;
|
|
33
33
|
private name;
|
|
34
34
|
private type;
|
|
35
|
+
private props;
|
|
35
36
|
private elements;
|
|
36
37
|
private validator;
|
|
37
38
|
/**
|
|
@@ -174,6 +175,8 @@ export declare class Track {
|
|
|
174
175
|
* ```
|
|
175
176
|
*/
|
|
176
177
|
getElements(): ReadonlyArray<TrackElement>;
|
|
178
|
+
getProps(): Record<string, any>;
|
|
179
|
+
setProps(props: Record<string, any>): this;
|
|
177
180
|
/**
|
|
178
181
|
* Validates a single element using the track's validator.
|
|
179
182
|
* Checks if the element meets all validation requirements.
|
|
@@ -234,6 +237,7 @@ export declare class Track {
|
|
|
234
237
|
* ```
|
|
235
238
|
*/
|
|
236
239
|
protected addElement(element: TrackElement, skipValidation?: boolean): boolean;
|
|
240
|
+
isElementColliding(element: TrackElement): boolean;
|
|
237
241
|
/**
|
|
238
242
|
* Removes an element from the track.
|
|
239
243
|
* Protected method that should be accessed through TrackFriend.
|
|
@@ -8,6 +8,14 @@ import { IconElement } from '../elements/icon.element';
|
|
|
8
8
|
import { CircleElement } from '../elements/circle.element';
|
|
9
9
|
import { RectElement } from '../elements/rect.element';
|
|
10
10
|
|
|
11
|
+
export declare const VALIDATION_ERROR_CODE: {
|
|
12
|
+
ELEMENT_NOT_FOUND: string;
|
|
13
|
+
ELEMENT_NOT_ADDED: string;
|
|
14
|
+
ELEMENT_NOT_UPDATED: string;
|
|
15
|
+
ELEMENT_NOT_REMOVED: string;
|
|
16
|
+
COLLISION_ERROR: string;
|
|
17
|
+
INVALID_TIMING: string;
|
|
18
|
+
};
|
|
11
19
|
export declare class ValidationError extends Error {
|
|
12
20
|
errors: string[];
|
|
13
21
|
warnings: string[];
|
package/dist/index.js
CHANGED
|
@@ -993,13 +993,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
993
993
|
}
|
|
994
994
|
}
|
|
995
995
|
class TextElement extends TrackElement {
|
|
996
|
-
constructor(text) {
|
|
996
|
+
constructor(text, props) {
|
|
997
997
|
super(TIMELINE_ELEMENT_TYPE.TEXT);
|
|
998
998
|
__publicField(this, "textEffect");
|
|
999
999
|
this.props = {
|
|
1000
1000
|
text,
|
|
1001
|
-
fill: "#888888"
|
|
1002
|
-
//default-grey
|
|
1001
|
+
fill: "#888888",
|
|
1002
|
+
//default-grey,
|
|
1003
|
+
...props || {}
|
|
1003
1004
|
};
|
|
1004
1005
|
}
|
|
1005
1006
|
getTextEffect() {
|
|
@@ -1014,6 +1015,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1014
1015
|
getLineWidth() {
|
|
1015
1016
|
return this.props.lineWidth;
|
|
1016
1017
|
}
|
|
1018
|
+
getProps() {
|
|
1019
|
+
return this.props;
|
|
1020
|
+
}
|
|
1017
1021
|
setText(text) {
|
|
1018
1022
|
this.props.text = text;
|
|
1019
1023
|
return this;
|
|
@@ -1058,6 +1062,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1058
1062
|
this.props.lineWidth = lineWidth;
|
|
1059
1063
|
return this;
|
|
1060
1064
|
}
|
|
1065
|
+
setProps(props) {
|
|
1066
|
+
this.props = structuredClone(props);
|
|
1067
|
+
return this;
|
|
1068
|
+
}
|
|
1061
1069
|
accept(visitor) {
|
|
1062
1070
|
return visitor.visitTextElement(this);
|
|
1063
1071
|
}
|
|
@@ -1120,6 +1128,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1120
1128
|
super(TIMELINE_ELEMENT_TYPE.CIRCLE);
|
|
1121
1129
|
this.props = {
|
|
1122
1130
|
radius,
|
|
1131
|
+
height: radius * 2,
|
|
1132
|
+
width: radius * 2,
|
|
1123
1133
|
fill,
|
|
1124
1134
|
strokeColor: fill,
|
|
1125
1135
|
lineWidth: 1
|
|
@@ -1143,6 +1153,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1143
1153
|
}
|
|
1144
1154
|
setRadius(radius) {
|
|
1145
1155
|
this.props.radius = radius;
|
|
1156
|
+
this.props.width = radius * 2;
|
|
1157
|
+
this.props.height = radius * 2;
|
|
1146
1158
|
return this;
|
|
1147
1159
|
}
|
|
1148
1160
|
setStrokeColor(strokeColor) {
|
|
@@ -1562,6 +1574,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1562
1574
|
};
|
|
1563
1575
|
}
|
|
1564
1576
|
}
|
|
1577
|
+
const VALIDATION_ERROR_CODE = {
|
|
1578
|
+
ELEMENT_NOT_FOUND: "ELEMENT_NOT_FOUND",
|
|
1579
|
+
ELEMENT_NOT_ADDED: "ELEMENT_NOT_ADDED",
|
|
1580
|
+
ELEMENT_NOT_UPDATED: "ELEMENT_NOT_UPDATED",
|
|
1581
|
+
ELEMENT_NOT_REMOVED: "ELEMENT_NOT_REMOVED",
|
|
1582
|
+
COLLISION_ERROR: "COLLISION_ERROR",
|
|
1583
|
+
INVALID_TIMING: "INVALID_TIMING"
|
|
1584
|
+
};
|
|
1565
1585
|
class ValidationError extends Error {
|
|
1566
1586
|
constructor(message, errors, warnings = []) {
|
|
1567
1587
|
super(message);
|
|
@@ -1664,8 +1684,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1664
1684
|
const basicValidation = this.validateBasicProperties(element);
|
|
1665
1685
|
const errors = [...basicValidation.errors];
|
|
1666
1686
|
const warnings = [...basicValidation.warnings];
|
|
1667
|
-
const
|
|
1668
|
-
if (!
|
|
1687
|
+
const text = element.getText();
|
|
1688
|
+
if (!text || text.trim() === "") {
|
|
1669
1689
|
errors.push("Caption element must have text content");
|
|
1670
1690
|
}
|
|
1671
1691
|
return { errors, warnings };
|
|
@@ -1842,11 +1862,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1842
1862
|
__publicField(this, "id");
|
|
1843
1863
|
__publicField(this, "name");
|
|
1844
1864
|
__publicField(this, "type");
|
|
1865
|
+
__publicField(this, "props");
|
|
1845
1866
|
__publicField(this, "elements");
|
|
1846
1867
|
__publicField(this, "validator");
|
|
1847
1868
|
this.name = name;
|
|
1848
1869
|
this.id = id ?? `t-${generateShortUuid}`;
|
|
1849
1870
|
this.type = type;
|
|
1871
|
+
this.props = {};
|
|
1850
1872
|
this.elements = [];
|
|
1851
1873
|
this.validator = new ElementValidator();
|
|
1852
1874
|
}
|
|
@@ -1992,6 +2014,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1992
2014
|
getElements() {
|
|
1993
2015
|
return [...this.elements];
|
|
1994
2016
|
}
|
|
2017
|
+
getProps() {
|
|
2018
|
+
return this.props;
|
|
2019
|
+
}
|
|
2020
|
+
setProps(props) {
|
|
2021
|
+
this.props = structuredClone(props);
|
|
2022
|
+
return this;
|
|
2023
|
+
}
|
|
1995
2024
|
/**
|
|
1996
2025
|
* Validates a single element using the track's validator.
|
|
1997
2026
|
* Checks if the element meets all validation requirements.
|
|
@@ -2065,17 +2094,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2065
2094
|
try {
|
|
2066
2095
|
const isValid = this.validateElement(element);
|
|
2067
2096
|
if (isValid) {
|
|
2068
|
-
this.
|
|
2069
|
-
|
|
2097
|
+
if (this.isElementColliding(element)) {
|
|
2098
|
+
throw new ValidationError("Element is colliding with another element", ["COLLISION_ERROR"]);
|
|
2099
|
+
} else {
|
|
2100
|
+
this.elements.push(element);
|
|
2101
|
+
return true;
|
|
2102
|
+
}
|
|
2070
2103
|
}
|
|
2071
2104
|
} catch (error) {
|
|
2072
|
-
if (error instanceof ValidationError) {
|
|
2073
|
-
throw error;
|
|
2074
|
-
}
|
|
2075
2105
|
throw error;
|
|
2076
2106
|
}
|
|
2077
2107
|
return false;
|
|
2078
2108
|
}
|
|
2109
|
+
isElementColliding(element) {
|
|
2110
|
+
return this.elements.some((e2) => e2.getStart() < element.getEnd() && e2.getEnd() > element.getStart());
|
|
2111
|
+
}
|
|
2079
2112
|
/**
|
|
2080
2113
|
* Removes an element from the track.
|
|
2081
2114
|
* Protected method that should be accessed through TrackFriend.
|
|
@@ -2244,6 +2277,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2244
2277
|
id: this.id,
|
|
2245
2278
|
name: this.name,
|
|
2246
2279
|
type: this.type,
|
|
2280
|
+
props: this.props,
|
|
2247
2281
|
elements: this.elements.map(
|
|
2248
2282
|
(element) => element.accept(serializer)
|
|
2249
2283
|
)
|
|
@@ -2281,6 +2315,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2281
2315
|
static fromJSON(json) {
|
|
2282
2316
|
const track = new Track(json.name, json.type ?? "element", json.id);
|
|
2283
2317
|
track.type = json.type;
|
|
2318
|
+
track.props = json.props;
|
|
2284
2319
|
track.elements = (json.elements || []).map(ElementDeserializer.fromJSON);
|
|
2285
2320
|
return track;
|
|
2286
2321
|
}
|
|
@@ -2921,6 +2956,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2921
2956
|
const track = prevTimelineData == null ? void 0 : prevTimelineData.tracks.find((t2) => t2.getName() === name);
|
|
2922
2957
|
return track;
|
|
2923
2958
|
}
|
|
2959
|
+
getSubtiltesTrack() {
|
|
2960
|
+
const prevTimelineData = this.getTimelineData();
|
|
2961
|
+
const track = prevTimelineData == null ? void 0 : prevTimelineData.tracks.find((t2) => t2.getType() === "caption");
|
|
2962
|
+
return track;
|
|
2963
|
+
}
|
|
2924
2964
|
removeTrackById(id) {
|
|
2925
2965
|
var _a;
|
|
2926
2966
|
const tracks = ((_a = this.getTimelineData()) == null ? void 0 : _a.tracks) || [];
|
|
@@ -2949,8 +2989,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2949
2989
|
* @returns Promise<boolean> true if element was added successfully
|
|
2950
2990
|
*/
|
|
2951
2991
|
async addElementToTrack(track, element) {
|
|
2992
|
+
var _a;
|
|
2952
2993
|
if (!track) {
|
|
2953
|
-
|
|
2994
|
+
throw new Error("TRACK_NOT_FOUND");
|
|
2954
2995
|
}
|
|
2955
2996
|
try {
|
|
2956
2997
|
const elementAdder = new ElementAdder(track);
|
|
@@ -2960,10 +3001,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2960
3001
|
if (currentData) {
|
|
2961
3002
|
this.setTimelineData({ tracks: currentData.tracks, updatePlayerData: true });
|
|
2962
3003
|
}
|
|
3004
|
+
return true;
|
|
3005
|
+
} else {
|
|
3006
|
+
return false;
|
|
2963
3007
|
}
|
|
2964
|
-
return result;
|
|
2965
3008
|
} catch (error) {
|
|
2966
|
-
|
|
3009
|
+
if (error instanceof ValidationError && ((_a = error.errors) == null ? void 0 : _a.length) > 0) {
|
|
3010
|
+
throw error;
|
|
3011
|
+
} else {
|
|
3012
|
+
throw new Error("ELEMENT_NOT_ADDED");
|
|
3013
|
+
}
|
|
2967
3014
|
}
|
|
2968
3015
|
}
|
|
2969
3016
|
/**
|
|
@@ -22975,6 +23022,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22975
23022
|
exports2.TimelineProvider = TimelineProvider;
|
|
22976
23023
|
exports2.Track = Track;
|
|
22977
23024
|
exports2.TrackElement = TrackElement;
|
|
23025
|
+
exports2.VALIDATION_ERROR_CODE = VALIDATION_ERROR_CODE;
|
|
22978
23026
|
exports2.ValidationError = ValidationError;
|
|
22979
23027
|
exports2.VideoElement = VideoElement;
|
|
22980
23028
|
exports2.WORDS_PER_PHRASE = WORDS_PER_PHRASE;
|