Skip to content

Commit c3d119f

Browse files
committed
add GradientFade fromJson
1 parent 7c9c7d5 commit c3d119f

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe('effect.fromJson', () => {
2323
{ actionType: 'noise', level: 50 },
2424
{ actionType: 'vignette', level: 5 },
2525
{ actionType: 'dither', type: 9 },
26-
{ actionType: 'vectorize', numOfColors: 17, detailLevel: 100 }
26+
{ actionType: 'vectorize', numOfColors: 17, detailLevel: 100 },
27+
{ actionType: 'gradientFade', strength: 5, horizontalStartPoint: 10, verticalStartPoint: 20 }
2728

2829
]);
2930

@@ -48,7 +49,8 @@ describe('effect.fromJson', () => {
4849
'e_noise:50',
4950
'e_vignette:5',
5051
'e_dither:9',
51-
'e_vectorize:colors:17:detail:100'
52+
'e_vectorize:colors:17:detail:100',
53+
'e_gradient_fade:5,x_10,y_20'
5254
].join('/'));
5355
});
5456
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe('Effect toJson()', () => {
228228
.verticalStartPoint(20));
229229
expect(transformation.toJson()).toStrictEqual( [
230230
{
231-
actionType: 'GradientFade',
231+
actionType: 'gradientFade',
232232
strength: 5,
233233
horizontalStartPoint: 10,
234234
verticalStartPoint: 20

src/actions/effect/GradientFade.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Action} from "../../internal/Action.js";
22
import {Qualifier} from "../../internal/qualifier/Qualifier.js";
33
import {IGradientFadeEffecModel} from "../../internal/models/IEffectActionModel.js";
4+
import {IActionModel} from "../../internal/models/IActionModel.js";
45

56
/**
67
* @description Applies a gradient fade effect from one edge of the image.
@@ -11,7 +12,7 @@ import {IGradientFadeEffecModel} from "../../internal/models/IEffectActionModel.
1112
class GradientFadeEffectAction extends Action {
1213
private _strength: number;
1314
private _type: string;
14-
protected _actionModel: IGradientFadeEffecModel = {actionType: 'GradientFade'};
15+
protected _actionModel: IGradientFadeEffecModel = {actionType: 'gradientFade'};
1516

1617
/**
1718
* @description Sets the strength of the fade effect.
@@ -63,6 +64,20 @@ class GradientFadeEffectAction extends Action {
6364

6465
this.addQualifier(new Qualifier('e', str));
6566
}
67+
68+
static fromJson(actionModel: IActionModel): GradientFadeEffectAction {
69+
const {actionType, verticalStartPoint, horizontalStartPoint, type, strength} = (actionModel as IGradientFadeEffecModel);
70+
71+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
72+
// This allows the inheriting classes to determine the class to be created
73+
const result = new this();
74+
verticalStartPoint && result.verticalStartPoint(verticalStartPoint);
75+
horizontalStartPoint && result.horizontalStartPoint(horizontalStartPoint);
76+
type && result.type(type);
77+
strength && result.strength(strength);
78+
79+
return result;
80+
}
6681
}
6782

6883
export {GradientFadeEffectAction};

src/internal/fromJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {LoopEffectAction} from "../actions/effect/leveled/Loop.js";
3232
import {MakeTransparentEffectAction} from "../actions/effect/leveled/MakeTransparent.js";
3333
import {DitherEffectAction} from "../actions/effect/Dither.js";
3434
import {VectorizeEffectAction} from "../actions/effect/Vectorize.js";
35+
import {GradientFadeEffectAction} from "../actions/effect/GradientFade.js";
3536

3637
const ActionModelMap: Record<string, IHasFromJson> = {
3738
scale: ResizeScaleAction,
@@ -69,7 +70,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
6970
noise: EffectActionWithLevel,
7071
vignette: EffectActionWithStrength,
7172
dither: DitherEffectAction,
72-
vectorize: VectorizeEffectAction
73+
vectorize: VectorizeEffectAction,
74+
gradientFade: GradientFadeEffectAction
7375

7476
};
7577

0 commit comments

Comments
 (0)