Skip to content

Commit e9e1666

Browse files
authored
Merge pull request #472 from cloudinary/feature/shadoweffect-tojson
2 parents 6770bb2 + 1e4441e commit e9e1666

File tree

8 files changed

+49
-30
lines changed

8 files changed

+49
-30
lines changed

__TESTS__/unit/toJson/simpleEffect.test.ts renamed to __TESTS__/unit/toJson/effect.toJson.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import {Transformation} from "../../../src";
22
import {Effect} from "../../../src/actions/effect";
33

4-
describe('SimpleEffect.toJson()', () => {
4+
5+
describe('Effect toJson()', () => {
6+
it('effect.sepia', () => {
7+
const transformation = new Transformation()
8+
.addAction(Effect.sepia());
9+
expect(transformation.toJson()).toStrictEqual( [
10+
{ actionType: 'sepia' }
11+
]);
12+
});
13+
514
it('effect.boomerang', () => {
615
const transformation = new Transformation()
716
.addAction(Effect.boomerang());
@@ -57,4 +66,17 @@ describe('SimpleEffect.toJson()', () => {
5766
{ actionType: 'transition' }
5867
]);
5968
});
69+
70+
it('effect.shadow', () => {
71+
const transformation = new Transformation()
72+
.addAction(Effect.shadow(4).offsetX(5).offsetY(8).color('red'));
73+
expect(transformation.toJson()).toStrictEqual( [
74+
{
75+
actionType: 'shadow',
76+
offsetX: 5,
77+
offsetY: 8,
78+
color: 'red'
79+
}
80+
]);
81+
});
6082
});

__TESTS__/unit/toJson/levelEffect.test.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/actions/effect/EffectActions/LeveledEffectAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {SimpleEffectAction} from "./SimpleEffectAction.js";
22
import {ExpressionQualifier} from "../../../qualifiers/expression/ExpressionQualifier.js";
3-
import {IEffectActionWithLevelModel} from "../../../internal/models/IEffectActionWithLevelModel.js";
3+
import {IEffectActionWithLevelModel} from "../../../internal/models/IEffectActionModel.js";
44

55
/**
66
* @description A base class for effects with a level, the extending class needs to implement a method that calls setLevel()

src/actions/effect/EffectActions/SimpleEffectAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {QualifierValue} from "../../../internal/qualifier/QualifierValue.js";
33
import {Qualifier} from "../../../internal/qualifier/Qualifier.js";
44
import {ExpressionQualifier} from "../../../qualifiers/expression/ExpressionQualifier.js";
55
import {EFFECT_MODE_TO_ACTION_TYPE_MAP} from "../../../internal/internalConstants.js";
6-
import {ISimpleEffectActionModel} from "../../../internal/models/ISimpleEffectActionModel.js";
6+
import {ISimpleEffectActionModel} from "../../../internal/models/IEffectActionModel.js";
77

88
/**
99
* @description A class that defines a simple effect of the type e_{effectName}

src/actions/effect/Shadow.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Qualifier} from "../../internal/qualifier/Qualifier.js";
44
import {prepareColor} from "../../internal/utils/prepareColor.js";
55
import {SystemColors} from "../../qualifiers/color.js";
66
import {ExpressionQualifier} from "../../qualifiers/expression/ExpressionQualifier.js";
7+
import {IShadowEffectActionModel} from "../../internal/models/IEffectActionModel.js";
78

89
/**
910
* @description Applies a shadow filter to the asset.
@@ -12,11 +13,12 @@ import {ExpressionQualifier} from "../../qualifiers/expression/ExpressionQualifi
1213
* @see Visit {@link Actions.Effect|Effect} for an example
1314
*/
1415
class ShadowEffectAction extends Action {
16+
protected _actionModel: IShadowEffectActionModel = {};
1517
private effectType: string;
1618

1719
constructor(effectType: string, strength: number) {
1820
super();
19-
21+
this._actionModel.actionType = effectType;
2022
this.effectType = effectType;
2123
this.addQualifier(new Qualifier('e', new QualifierValue(['shadow', strength])));
2224
}
@@ -27,6 +29,7 @@ class ShadowEffectAction extends Action {
2729
* @return {this}
2830
*/
2931
strength(strength: number): this {
32+
this._actionModel.strength = strength;
3033
return this.addQualifier(new Qualifier('e', new QualifierValue(['shadow', strength])));
3134
}
3235

@@ -36,6 +39,7 @@ class ShadowEffectAction extends Action {
3639
* @return {this}
3740
*/
3841
offsetX(x:number | ExpressionQualifier): this {
42+
this._actionModel.offsetX = x as number;
3943
return this.addQualifier(new Qualifier('x', new QualifierValue(x)));
4044
}
4145

@@ -45,6 +49,7 @@ class ShadowEffectAction extends Action {
4549
* @return {this}
4650
*/
4751
offsetY(y:number | ExpressionQualifier): this {
52+
this._actionModel.offsetY = y as number;
4853
return this.addQualifier(new Qualifier('y', new QualifierValue(y)));
4954
}
5055

@@ -54,6 +59,7 @@ class ShadowEffectAction extends Action {
5459
* @return {this}
5560
*/
5661
color(color:SystemColors): this {
62+
this._actionModel.color = color;
5763
return this.addQualifier(new Qualifier('co', new QualifierValue(prepareColor(color))));
5864
}
5965
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {IActionModel} from "./IActionModel.js";
2+
3+
interface IEffectActionWithLevelModel extends IActionModel{
4+
level?: number;
5+
}
6+
7+
interface ISimpleEffectActionModel extends IActionModel{
8+
9+
}
10+
11+
interface IShadowEffectActionModel extends IActionModel{
12+
strength?: number;
13+
offsetX?: string|number;
14+
offsetY?: string|number;
15+
color?: string
16+
}
17+
export {IEffectActionWithLevelModel, ISimpleEffectActionModel, IShadowEffectActionModel};

src/internal/models/IEffectActionWithLevelModel.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/internal/models/ISimpleEffectActionModel.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)