Skip to content

Commit 754841f

Browse files
committed
add gradientFade toJson
1 parent a296597 commit 754841f

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,20 @@ describe('Effect toJson()', () => {
218218
}
219219
]);
220220
});
221+
222+
it('effect.gradientFade', () => {
223+
const transformation = new Transformation()
224+
.addAction(Effect.gradientFade()
225+
.strength(5)
226+
.horizontalStartPoint(10)
227+
.verticalStartPoint(20));
228+
expect(transformation.toJson()).toStrictEqual( [
229+
{
230+
actionType: 'GradientFade',
231+
strength: 5,
232+
horizontalStartPoint: 10,
233+
verticalStartPoint: 20
234+
}
235+
]);
236+
});
221237
});

src/actions/effect/GradientFade.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Action} from "../../internal/Action.js";
22
import {Qualifier} from "../../internal/qualifier/Qualifier.js";
3+
import {IGradientFadeEffecModel} from "../../internal/models/IEffectActionModel.js";
34

45
/**
56
* @description Applies a gradient fade effect from one edge of the image.
@@ -10,12 +11,14 @@ import {Qualifier} from "../../internal/qualifier/Qualifier.js";
1011
class GradientFadeEffectAction extends Action {
1112
private _strength: number;
1213
private _type: string;
14+
protected _actionModel: IGradientFadeEffecModel = {actionType: 'GradientFade'};
1315

1416
/**
1517
* @description Sets the strength of the fade effect.
1618
* @param {number} strength The strength of the fade effect. (Range: 0 to 100, Server default: 20)
1719
*/
1820
strength(strength:number): this {
21+
this._actionModel.strength = strength;
1922
this._strength = strength;
2023
return this;
2124
}
@@ -25,6 +28,7 @@ class GradientFadeEffectAction extends Action {
2528
* @param {string | Qualifiers.GradientFade} type The mode of gradient fade.
2629
*/
2730
type(type:string): this {
31+
this._actionModel.type = type;
2832
this._type = type;
2933
return this;
3034
}
@@ -34,6 +38,7 @@ class GradientFadeEffectAction extends Action {
3438
* @param {number | string} x The x dimension of the start point.
3539
*/
3640
horizontalStartPoint(x:number | string): this {
41+
this._actionModel.horizontalStartPoint = x as string;
3742
return this.addQualifier(new Qualifier('x', x));
3843
}
3944

@@ -42,6 +47,7 @@ class GradientFadeEffectAction extends Action {
4247
* @param {number | string} y The y dimension of the start point.
4348
*/
4449
verticalStartPoint(y:number | string): this {
50+
this._actionModel.verticalStartPoint = y as string;
4551
return this.addQualifier(new Qualifier('y', y));
4652
}
4753

src/internal/models/IEffectActionModel.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ interface IVectorizeEffectModel extends IActionModel{
4848
paths?: number;
4949
cornersLevel?: number;
5050
}
51+
52+
interface IGradientFadeEffecModel extends IActionModel{
53+
strength?: number;
54+
type?: string;
55+
verticalStartPoint?: string;
56+
horizontalStartPoint?: string;
57+
}
58+
5159
export {
5260
IEffectActionWithLevelModel,
5361
ISimpleEffectActionModel,
@@ -57,5 +65,6 @@ export {
5765
IEffectOutlineModel,
5866
IMakeTransparentEffectModel,
5967
IDitherModel,
60-
IVectorizeEffectModel
68+
IVectorizeEffectModel,
69+
IGradientFadeEffecModel
6170
};

0 commit comments

Comments
 (0)