Skip to content

Commit 202224d

Browse files
authored
add fadeIn fadeOut from/to Json (#511)
1 parent 9e2dd8e commit 202224d

File tree

8 files changed

+119
-21
lines changed

8 files changed

+119
-21
lines changed

__TESTS_BUNDLE_SIZE__/bundleSizeTestCases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const bundleSizeTestCases:ITestCase[] = [
7474
},
7575
{
7676
name: 'Import all of the SDK',
77-
sizeLimitInKB: 125,
77+
sizeLimitInKB: 126,
7878
importsArray: [
7979
importFromPackage('* as CloudinaryURLGEN')
8080
]
@@ -88,7 +88,7 @@ const bundleSizeTestCases:ITestCase[] = [
8888
},
8989
{
9090
name: 'Import All Actions',
91-
sizeLimitInKB: 52,
91+
sizeLimitInKB: 53,
9292
importsArray: [
9393
importFromPackage('Actions')
9494
]

__TESTS__/unit/fromJson/effect.fromJson.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ describe('effect.fromJson', () => {
3030
{ actionType: 'simulateColorblind', condition: 'rod_monochromacy' },
3131
{ actionType: 'deshake', pixels: 16 },
3232
{ actionType: 'pixelate', squareSize: 15, region: { RegionType: 'faces' }},
33-
{ actionType: 'blur', strength: 5 }
33+
{ actionType: 'blur', strength: 5 },
34+
{ actionType: 'fadeIn', length: 13 },
35+
{ actionType: 'fadeOut', length: 13 }
3436
]});
3537

3638
expect(transformation.toString()).toStrictEqual([
@@ -61,7 +63,9 @@ describe('effect.fromJson', () => {
6163
'e_simulate_colorblind:rod_monochromacy',
6264
'e_deshake:16',
6365
'e_pixelate_faces:15',
64-
'e_blur:5'
66+
'e_blur:5',
67+
'e_fade:13',
68+
'e_fade:-13'
6569
].join('/'));
6670
});
6771
});

__TESTS__/unit/toJson/effect.toJson.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,30 @@ describe('Effect toJson()', () => {
346346
]
347347
});
348348
});
349+
350+
it('effect.FadeIn', () => {
351+
const transformation = new Transformation()
352+
.addAction(Effect.fadeIn(50));
353+
expect(transformation.toJson()).toStrictEqual({
354+
actions: [
355+
{
356+
actionType: 'fadeIn',
357+
length: 50,
358+
}
359+
]
360+
});
361+
});
362+
363+
it('effect.FadeOut', () => {
364+
const transformation = new Transformation()
365+
.addAction(Effect.fadeOut(50));
366+
expect(transformation.toJson()).toStrictEqual({
367+
actions: [
368+
{
369+
actionType: 'fadeOut',
370+
length: 50,
371+
}
372+
]
373+
});
374+
});
349375
});

src/actions/effect.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {SimulateColorBlindEffectAction} from "./effect/SimulateColorBlind.js";
1010
import {EffectActionWithLevel}from "./effect/EffectActions/EffectActionWithLevel.js";
1111
import {AssistColorBlindEffectAction} from "./effect/AssistColorBlind.js";
1212
import {GradientFadeEffectAction} from "./effect/GradientFade.js";
13-
import {FadeoutEffectAction} from "./effect/leveled/FadeOut.js";
13+
import {FadeOutEffectAction} from "./effect/leveled/FadeOut.js";
1414
import {ColorizeEffectAction} from "./effect/Colorize.js";
1515
import {ShadowEffectAction} from "./effect/Shadow.js";
1616
import {StyleTransfer} from "./effect/StyleTransfer.js";
@@ -240,7 +240,7 @@ function accelerate(speedIncreasePercent?: number): AccelerationEffectAction {
240240
* @return {Actions.Effect.FadeInEffectAction}
241241
*/
242242
function fadeIn(fadeLength?: number):FadeInEffectAction {
243-
return new FadeInEffectAction('fade', fadeLength);
243+
return new FadeInEffectAction(fadeLength);
244244
}
245245

246246

@@ -253,8 +253,8 @@ function fadeIn(fadeLength?: number):FadeInEffectAction {
253253
* @param {number} fadeLength The time in ms for the fade to occur. (Server default: 2000)
254254
* @return {Actions.Effect.FadeoutEffectAction}
255255
*/
256-
function fadeOut(fadeLength?: number):FadeoutEffectAction {
257-
return new FadeoutEffectAction('fade', -fadeLength);
256+
function fadeOut(fadeLength?: number):FadeOutEffectAction {
257+
return new FadeOutEffectAction(fadeLength);
258258
}
259259

260260

@@ -552,6 +552,8 @@ export declare type EffectActions =
552552
| BlurAction
553553
| Pixelate
554554
| RemoveBackgroundAction
555+
| FadeInEffectAction
556+
| FadeOutEffectAction
555557

556558

557559
export {

src/actions/effect/leveled/FadeIn.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1-
import {LeveledEffectAction} from "../EffectActions/LeveledEffectAction.js";
1+
import {Action} from "../../../internal/Action.js";
2+
import {Qualifier} from "../../../internal/qualifier/Qualifier.js";
3+
import {QualifierValue} from "../../../internal/qualifier/QualifierValue.js";
4+
import {IFadeInEffectActionModel} from "../../../internal/models/IEffectActionModel.js";
5+
import {IActionModel} from "../../../internal/models/IActionModel.js";
26

37

48
/**
59
* @description Fade out at the end of the video, use the length() method to set the time in ms for the fade to occur. (Server default: 2000)
6-
* @extends LeveledEffectAction
10+
* @extends Action
711
* @memberOf Actions.Effect
812
* @see Visit {@link Actions.Effect|Effect} for an example
913
*/
10-
class FadeInEffectAction extends LeveledEffectAction {
11-
// We can't use EffectActionWithLength because this `length` is reversing the sign
12-
duration(value: number | string): this {
13-
return this.setLevel(value);
14+
class FadeInEffectAction extends Action{
15+
protected _actionModel : IFadeInEffectActionModel = {actionType: 'fadeIn'};
16+
constructor(duration?: number) {
17+
super();
18+
this.addQualifier(new Qualifier('e', new QualifierValue(['fade', `${duration}`]).setDelimiter(':')));
19+
duration && (this._actionModel.length = duration);
20+
}
21+
22+
/**
23+
*
24+
* @description Sets the duration level for the action
25+
* @param {string | number} duration - The duration of the effect
26+
*/
27+
duration(duration: number | string): this {
28+
this._actionModel.length = duration as number;
29+
return this.addQualifier(new Qualifier('e', new QualifierValue(['fade', `${duration}`]).setDelimiter(':')));
30+
}
31+
32+
static fromJson(actionModel: IActionModel): FadeInEffectAction {
33+
const {length} = (actionModel as IFadeInEffectActionModel);
34+
35+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
36+
// This allows the inheriting classes to determine the class to be created
37+
const result = new this(length);
38+
39+
return result;
1440
}
1541
}
1642

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import {LeveledEffectAction} from "../EffectActions/LeveledEffectAction.js";
2+
import {Action} from "../../../internal/Action.js";
3+
import {Qualifier} from "../../../internal/qualifier/Qualifier.js";
4+
import {QualifierValue} from "../../../internal/qualifier/QualifierValue.js";
5+
import {IFadeOutEffectActionModel} from "../../../internal/models/IEffectActionModel.js";
6+
import {IActionModel} from "../../../internal/models/IActionModel.js";
27

38

49
/**
@@ -7,12 +12,33 @@ import {LeveledEffectAction} from "../EffectActions/LeveledEffectAction.js";
712
* @memberOf Actions.Effect
813
* @see Visit {@link Actions.Effect|Effect} for an example
914
*/
10-
class FadeoutEffectAction extends LeveledEffectAction {
11-
// We can't use EffectActionWithLength because this `length` is reversing the sign
12-
duration(value: number | string): this {
13-
return this.setLevel(-value);
15+
class FadeOutEffectAction extends Action {
16+
protected _actionModel : IFadeOutEffectActionModel = {actionType: 'fadeOut'};
17+
constructor(duration: number) {
18+
super();
19+
this.addQualifier(new Qualifier('e', new QualifierValue(['fade', `-${duration}`]).setDelimiter(':')));
20+
duration && (this._actionModel.length = duration);
21+
}
22+
/**
23+
*
24+
* @description Sets the duration level for the action
25+
* @param {string | number} duration - The duration of the effect
26+
*/
27+
duration(duration: number | string): this {
28+
this._actionModel.length = duration as number;
29+
return this.addQualifier(new Qualifier('e', new QualifierValue(['fade', `-${duration}`]).setDelimiter(':')));
30+
}
31+
32+
static fromJson(actionModel: IActionModel): FadeOutEffectAction {
33+
const {length} = (actionModel as IFadeOutEffectActionModel);
34+
35+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
36+
// This allows the inheriting classes to determine the class to be created
37+
const result = new this(length);
38+
39+
return result;
1440
}
1541
}
1642

1743

18-
export {FadeoutEffectAction};
44+
export {FadeOutEffectAction};

src/internal/fromJson.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import AudioCodecAction from "../actions/transcode/AudioCodecAction.js";
5353
import AudioFrequencyAction from "../actions/transcode/AudioFrequencyAction.js";
5454
import StreamingProfileAction from "../actions/transcode/StreamingProfile.js";
5555
import ToAnimatedAction from "../actions/transcode/ToAnimatedAction.js";
56+
import {FadeInEffectAction} from "../actions/effect/leveled/FadeIn.js";
57+
import {FadeOutEffectAction} from "../actions/effect/leveled/FadeOut.js";
5658

5759
const ActionModelMap: Record<string, IHasFromJson> = {
5860
scale: ResizeScaleAction,
@@ -116,7 +118,9 @@ const ActionModelMap: Record<string, IHasFromJson> = {
116118
audioCodec: AudioCodecAction,
117119
audioFrequency: AudioFrequencyAction,
118120
streamingProfile: StreamingProfileAction,
119-
toAnimated: ToAnimatedAction
121+
toAnimated: ToAnimatedAction,
122+
fadeIn: FadeInEffectAction,
123+
fadeOut: FadeOutEffectAction
120124
};
121125

122126
/**

src/internal/models/IEffectActionModel.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ interface IBlurModel extends IActionModel{
7878
region?: {RegionType?: string};
7979
}
8080

81+
interface IFadeInEffectActionModel extends IActionModel{
82+
length?: number;
83+
}
84+
85+
interface IFadeOutEffectActionModel extends IActionModel{
86+
length?: number;
87+
}
88+
8189
export {
8290
IEffectActionWithLevelModel,
8391
ISimpleEffectActionModel,
@@ -93,5 +101,7 @@ export {
93101
ISimulateColorBlindEffectModel,
94102
IDeshakeEffectModel,
95103
IPixelateModel,
96-
IBlurModel
104+
IBlurModel,
105+
IFadeInEffectActionModel,
106+
IFadeOutEffectActionModel
97107
};

0 commit comments

Comments
 (0)