Skip to content

Commit e097e96

Browse files
committed
feat: add text style properties
1 parent 3e8f96f commit e097e96

File tree

1 file changed

+113
-5
lines changed

1 file changed

+113
-5
lines changed

src/index.ts

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ export class Comp {
7070
const thisComp = new Comp();
7171

7272
export class PropertyGroup {
73-
name: string = "property group base";
73+
readonly name: string = "property group base";
74+
constructor(groupName: string) {
75+
this.name = groupName;
76+
}
7477
}
7578

7679
export type Value =
@@ -138,7 +141,7 @@ export class Property<T extends Value> {
138141
return new Key();
139142
}
140143
propertyGroup(countUp: number): PropertyGroup {
141-
return new PropertyGroup();
144+
return new PropertyGroup("property group from function");
142145
}
143146
constructor(readonly value: T) {}
144147
}
@@ -198,7 +201,10 @@ export class PathProperty<T> extends Property<T> {
198201

199202
export type loopType = "cycle" | "pingpong" | "offset" | "continue";
200203

201-
export class TransformGroup extends PropertyGroup {
204+
export class Transform extends PropertyGroup {
205+
constructor() {
206+
super("Transform");
207+
}
202208
readonly anchorPoint: Property<Vector> = new Property([0, 0]);
203209
readonly position: Property<Vector> = new Property([0, 0]);
204210
readonly scale: Property<Vector> = new Property([0, 0]);
@@ -209,7 +215,108 @@ export class TransformGroup extends PropertyGroup {
209215
readonly rotationZ?: Property<number> = new Property(0);
210216
}
211217

218+
export class TextStyle {
219+
fontSize: number = 0;
220+
setFontSize(fontSize: number): TextStyle {
221+
this.fontSize = fontSize;
222+
return this;
223+
}
224+
font: string = "Arial";
225+
setFont(font: string): TextStyle {
226+
this.font = font;
227+
return this;
228+
}
229+
setText(text: string): TextStyle {
230+
return this;
231+
}
232+
isFauxBold: boolean = false;
233+
setFauxBold(isFauxBold: boolean): TextStyle {
234+
this.isFauxBold = isFauxBold;
235+
return this;
236+
}
237+
isFauxItalic: boolean = false;
238+
setFauxItalic(isFauxItalic: boolean): TextStyle {
239+
this.isFauxItalic = isFauxItalic;
240+
return this;
241+
}
242+
isAllCaps: boolean = false;
243+
setAllCaps(isAllCaps: boolean): TextStyle {
244+
this.isAllCaps = isAllCaps;
245+
return this;
246+
}
247+
isSmallCaps: boolean = false;
248+
setSmallCaps(isSmallCaps: boolean): TextStyle {
249+
this.isSmallCaps = isSmallCaps;
250+
return this;
251+
}
252+
tracking: number = 0;
253+
setTracking(tracking: number): TextStyle {
254+
this.tracking = tracking;
255+
return this;
256+
}
257+
leading: number = 60;
258+
setLeading(leading: number): TextStyle {
259+
this.leading = leading;
260+
return this;
261+
}
262+
autoLeading: boolean = false;
263+
setAutoLeading(autoLeading: boolean): TextStyle {
264+
this.autoLeading = autoLeading;
265+
return this;
266+
}
267+
baselineShift: number = 0;
268+
setBaselineShift(baselineShift: number): TextStyle {
269+
this.baselineShift = baselineShift;
270+
return this;
271+
}
272+
applyFill: boolean = true;
273+
setApplyFill(applyFill: boolean): TextStyle {
274+
this.applyFill = applyFill;
275+
return this;
276+
}
277+
fillColor: [number, number, number] = [1, 1, 1];
278+
setFillColor(fillColor: [number, number, number]): TextStyle {
279+
this.fillColor = fillColor;
280+
return this;
281+
}
282+
applyStroke: boolean = false;
283+
setApplyStroke(applyStroke: boolean): TextStyle {
284+
this.applyStroke = applyStroke;
285+
return this;
286+
}
287+
strokeColor: [number, number, number] = [1, 1, 1];
288+
setStrokeColor(strokeColor: [number, number, number]): TextStyle {
289+
this.strokeColor = strokeColor;
290+
return this;
291+
}
292+
strokeWidth: number = 0;
293+
setStrokeWidth(strokeWidth: number): TextStyle {
294+
this.strokeWidth = strokeWidth;
295+
return this;
296+
}
297+
}
298+
299+
export class SourceText extends Property<string> {
300+
constructor(value: string) {
301+
super(value);
302+
}
303+
style = new TextStyle();
304+
getStyleAt(characterIndex: number, sampleTime: number = time) {
305+
return this.style;
306+
}
307+
}
308+
309+
export class Text extends PropertyGroup {
310+
constructor() {
311+
super("Text");
312+
}
313+
readonly sourceText: SourceText = new SourceText("Source text value");
314+
}
315+
212316
export class MaterialOptions extends PropertyGroup {
317+
constructor() {
318+
super("Material Options");
319+
}
213320
readonly lightTransmission: Property<number> = new Property(0);
214321
readonly castShadows: Property<boolean> = new Property(false);
215322
readonly acceptsShadows: Property<boolean> = new Property(false);
@@ -277,8 +384,9 @@ export class Layer {
277384
readonly audioLevels?: Property<number> = new Property(0);
278385
readonly timeRemap?: Property<number> = new Property(0);
279386
readonly marker?: MarkerProperty;
280-
readonly transform?: PropertyGroup = new TransformGroup();
281-
readonly materialOption?: PropertyGroup = new MaterialOptions();
387+
readonly transform?: Transform = new Transform();
388+
readonly text?: Text = new Text();
389+
readonly materialOption?: MaterialOptions = new MaterialOptions();
282390
toComp(vec: Vector, time?: number): Vector {
283391
return vec;
284392
}

0 commit comments

Comments
 (0)