Skip to content

Commit 11f61bf

Browse files
committed
added position to caption preset config values
1 parent 4993c5d commit 11f61bf

File tree

10 files changed

+45
-16
lines changed

10 files changed

+45
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@diffusionstudio/core",
33
"private": false,
4-
"version": "1.4.1",
4+
"version": "1.4.2",
55
"type": "module",
66
"description": "Build bleeding edge video processing applications",
77
"files": [

src/tracks/caption/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './preset.interface';
1515
export * from './preset.solar';
1616
export * from './preset.whisper';
1717
export * from './preset.verdant';
18+
export * from './preset.types';

src/tracks/caption/preset.cascade.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { GeneratorOptions } from '../../models';
1414
import type { DefaultCaptionPresetConfig } from './preset.types';
1515
import type { CaptionTrack } from './caption';
1616
import type { CaptionPresetStrategy } from './preset.interface';
17+
import type { Position } from '../../types';
1718

1819
export class CascadeCaptionPreset extends Serializer implements CaptionPresetStrategy {
1920
@serializable()
@@ -22,10 +23,14 @@ export class CascadeCaptionPreset extends Serializer implements CaptionPresetStr
2223
@serializable()
2324
public readonly type = 'CASCADE';
2425

26+
@serializable()
27+
public position: Position;
28+
2529
public constructor(config: Partial<DefaultCaptionPresetConfig> = {}) {
2630
super();
2731

2832
this.generatorOptions = config.generatorOptions ?? { duration: [1.4] };
33+
this.position = config.position ?? { x: '12%', y: '44%' };
2934
}
3035

3136
public async applyTo(track: CaptionTrack): Promise<void> {
@@ -70,10 +75,7 @@ export class CascadeCaptionPreset extends Serializer implements CaptionPresetStr
7075
angle: Math.PI / 4,
7176
distance: 2,
7277
},
73-
position: {
74-
x: '12%',
75-
y: '44%',
76-
},
78+
position: this.position,
7779
stop: sequence.words[i].stop.add(offset),
7880
start: sequence.words[i].start.add(offset),
7981
})

src/tracks/caption/preset.classic.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { CaptionPresetType, DefaultCaptionPresetConfig } from './preset.typ
1414
import type { GeneratorOptions } from '../../models';
1515
import type { CaptionTrack } from './caption';
1616
import type { CaptionPresetStrategy } from './preset.interface';
17+
import type { Position } from '../../types';
1718

1819
export class ClassicCaptionPreset extends Serializer implements CaptionPresetStrategy {
1920
@serializable()
@@ -22,11 +23,14 @@ export class ClassicCaptionPreset extends Serializer implements CaptionPresetStr
2223
@serializable()
2324
public readonly type: CaptionPresetType = 'CLASSIC';
2425

26+
@serializable()
27+
public position: Position;
2528

2629
public constructor(config: Partial<DefaultCaptionPresetConfig> = {}) {
2730
super();
2831

2932
this.generatorOptions = config.generatorOptions ?? { duration: [0.2] };
33+
this.position = config.position ?? { x: '50%', y: '50%' };
3034
}
3135

3236
public async applyTo(track: CaptionTrack): Promise<void> {
@@ -63,7 +67,7 @@ export class ClassicCaptionPreset extends Serializer implements CaptionPresetStr
6367
angle: Math.PI * 0.40,
6468
alpha: 1,
6569
},
66-
position: 'center',
70+
position: this.position,
6771
stop: sequence.stop.add(offset),
6872
start: sequence.start.add(offset),
6973
scale: new Keyframe([0, 8], [0.96, 1], { easing: 'easeOut' }),

src/tracks/caption/preset.guinea.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { MultiColorCaptionPresetConfig, CaptionPresetType } from './preset.
1515
import type { CaptionPresetStrategy } from './preset.interface';
1616
import type { WordGroup, Word } from '../../models';
1717
import type { CaptionTrack } from './caption';
18-
import type { hex } from '../../types';
18+
import type { hex, Position } from '../../types';
1919

2020
export class GuineaCaptionPreset extends Serializer implements CaptionPresetStrategy {
2121
@serializable()
@@ -24,10 +24,14 @@ export class GuineaCaptionPreset extends Serializer implements CaptionPresetStra
2424
@serializable()
2525
public colors: hex[];
2626

27+
@serializable()
28+
public position: Position;
29+
2730
public constructor(config: Partial<MultiColorCaptionPresetConfig> = {}) {
2831
super();
2932

3033
this.colors = config.colors ?? ['#1BD724', '#FFEE0C', '#FF2E17'];
34+
this.position = config.position ?? { x: '50%', y: '50%' };
3135
}
3236

3337
public async applyTo(track: CaptionTrack): Promise<void> {
@@ -73,7 +77,7 @@ export class GuineaCaptionPreset extends Serializer implements CaptionPresetStra
7377
leading: 1.3,
7478
font,
7579
textCase: 'upper',
76-
position: 'center',
80+
position: this.position,
7781
stop: stop.add(offset),
7882
start: start.add(offset),
7983
styles: [

src/tracks/caption/preset.solar.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { CaptionPresetType, DefaultCaptionPresetConfig } from './preset.typ
1515
import type { CaptionTrack } from './caption';
1616
import type { GeneratorOptions } from '../../models';
1717
import type { CaptionPresetStrategy } from './preset.interface';
18+
import type { Position } from '../../types';
1819

1920
export class SolarCaptionPreset extends Serializer implements CaptionPresetStrategy {
2021
@serializable()
@@ -23,10 +24,14 @@ export class SolarCaptionPreset extends Serializer implements CaptionPresetStrat
2324
@serializable()
2425
public readonly type: CaptionPresetType = 'SOLAR';
2526

27+
@serializable()
28+
public position: Position;
29+
2630
public constructor(config: Partial<DefaultCaptionPresetConfig> = {}) {
2731
super();
2832

2933
this.generatorOptions = config.generatorOptions ?? { duration: [0.2] };
34+
this.position = config.position ?? { x: '50%', y: '50%' };
3035
}
3136

3237
public async applyTo(track: CaptionTrack): Promise<void> {
@@ -65,7 +70,7 @@ export class SolarCaptionPreset extends Serializer implements CaptionPresetStrat
6570
angle: Math.PI / 2.5,
6671
alpha: 1,
6772
},
68-
position: 'center',
73+
position: this.position,
6974
stop: sequence.stop.add(offset),
7075
start: sequence.start.add(offset),
7176
scale: new Keyframe([0, 8], [0.96, 1], { easing: 'easeOut' }),

src/tracks/caption/preset.spotlight.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { SingleColorCaptionPresetConfig } from './preset.types';
1414
import type { CaptionPresetStrategy } from './preset.interface';
1515
import type { GeneratorOptions } from '../../models';
1616
import type { CaptionTrack } from './caption';
17-
import type { hex } from '../../types';
17+
import type { hex, Position } from '../../types';
1818

1919
export class SpotlightCaptionPreset extends Serializer implements CaptionPresetStrategy {
2020
@serializable()
@@ -26,11 +26,15 @@ export class SpotlightCaptionPreset extends Serializer implements CaptionPresetS
2626
@serializable()
2727
public color: hex;
2828

29+
@serializable()
30+
public position: Position;
31+
2932
public constructor(config: Partial<SingleColorCaptionPresetConfig> = {}) {
3033
super();
3134

3235
this.generatorOptions = config.generatorOptions ?? { duration: [0.2] };
3336
this.color = config.color ?? '#00FF4C';
37+
this.position = config.position ?? { x: '50%', y: '50%' };
3438
}
3539

3640
public async applyTo(track: CaptionTrack): Promise<void> {
@@ -69,7 +73,7 @@ export class SpotlightCaptionPreset extends Serializer implements CaptionPresetS
6973
angle: Math.PI / 4,
7074
distance: 2,
7175
},
72-
position: 'center',
76+
position: this.position,
7377
styles: [{
7478
fillStyle: this.color,
7579
}],

src/tracks/caption/preset.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import type { GeneratorOptions } from '../../models';
9-
import type { hex } from '../../types';
9+
import type { hex, Position } from '../../types';
1010

1111
export type CaptionPresetType =
1212
| 'CLASSIC'
@@ -20,6 +20,7 @@ export type CaptionPresetType =
2020

2121
export type DefaultCaptionPresetConfig = {
2222
generatorOptions: GeneratorOptions;
23+
position: Position;
2324
};
2425

2526
export type SingleColorCaptionPresetConfig = {

src/tracks/caption/preset.verdant.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { SingleColorCaptionPresetConfig, CaptionPresetType } from './preset
1414
import type { CaptionPresetStrategy } from './preset.interface';
1515
import type { GeneratorOptions } from '../../models';
1616
import type { CaptionTrack } from './caption';
17-
import type { hex } from '../../types';
17+
import type { hex, Position } from '../../types';
1818

1919
export class VerdantCaptionPreset extends Serializer implements CaptionPresetStrategy {
2020
@serializable()
@@ -26,11 +26,15 @@ export class VerdantCaptionPreset extends Serializer implements CaptionPresetStr
2626
@serializable()
2727
public color: hex;
2828

29+
@serializable()
30+
public position: Position;
31+
2932
public constructor(config: Partial<SingleColorCaptionPresetConfig> = {}) {
3033
super();
3134

3235
this.generatorOptions = config.generatorOptions ?? { duration: [1] };
3336
this.color = config.color ?? '#69E34C';
37+
this.position = config.position ?? { x: '50%', y: '50%' };
3438
}
3539

3640
public async applyTo(track: CaptionTrack): Promise<void> {
@@ -75,7 +79,7 @@ export class VerdantCaptionPreset extends Serializer implements CaptionPresetStr
7579
fillStyle: this.color,
7680
fontSize: 19,
7781
}],
78-
position: 'center',
82+
position: this.position,
7983
stop: sequence.words[i].stop.add(offset),
8084
start: sequence.words[i].start.add(offset),
8185
segments: [{

src/tracks/caption/preset.whisper.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { SingleColorCaptionPresetConfig } from './preset.types';
1414
import type { CaptionTrack } from './caption';
1515
import type { CaptionPresetStrategy } from './preset.interface';
1616
import type { GeneratorOptions } from '../../models';
17-
import type { hex } from '../../types';
17+
import type { hex, Position } from '../../types';
1818

1919
export class WhisperCaptionPreset extends Serializer implements CaptionPresetStrategy {
2020
@serializable()
@@ -26,11 +26,15 @@ export class WhisperCaptionPreset extends Serializer implements CaptionPresetStr
2626
@serializable()
2727
public color: hex;
2828

29+
@serializable()
30+
public position: Position;
31+
2932
public constructor(config: Partial<SingleColorCaptionPresetConfig> = {}) {
3033
super();
3134

3235
this.generatorOptions = config.generatorOptions ?? { length: [20] };
3336
this.color = config.color ?? '#8c8c8c';
37+
this.position = config.position ?? { x: '50%', y: '50%' };
3438
}
3539

3640
public async applyTo(track: CaptionTrack): Promise<void> {
@@ -65,7 +69,7 @@ export class WhisperCaptionPreset extends Serializer implements CaptionPresetStr
6569
},
6670
maxWidth: track.composition.width * 0.8,
6771
font,
68-
position: 'center',
72+
position: this.position,
6973
styles: [{
7074
fillStyle: this.color,
7175
}],

0 commit comments

Comments
 (0)