Skip to content

Commit 81b1817

Browse files
committed
add pixelate toJson
1 parent 41c2f03 commit 81b1817

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Transformation} from "../../../src";
22
import {Effect} from "../../../src/actions/effect";
33
import {halftone4x4Orthogonal} from "../../../src/qualifiers/dither";
44
import {rodMonochromacy} from "../../../src/qualifiers/simulateColorBlind";
5+
import {Region} from "../../../src/qualifiers";
56

67

78
describe('Effect toJson()', () => {
@@ -268,4 +269,17 @@ describe('Effect toJson()', () => {
268269
}
269270
]);
270271
});
272+
273+
274+
it('effect.pixelate', () => {
275+
const transformation = new Transformation()
276+
.addAction(Effect.pixelate().squareSize(15).region(Region.faces()));
277+
expect(transformation.toJson()).toStrictEqual( [
278+
{
279+
actionType: 'pixelate',
280+
squareSize: 15,
281+
region: { RegionType: 'faces' }
282+
}
283+
]);
284+
});
271285
});

src/actions/effect/pixelate/Pixelate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {NamedRegion} from "../../../qualifiers/region/NamedRegion.js";
22
import {Qualifier} from "../../../internal/qualifier/Qualifier.js";
33
import {Action} from "../../../internal/Action.js";
4+
import {IPixelateModel} from "../../../internal/models/IEffectActionModel.js";
45

56
/**
67
* @description The Action class of the pixelate Builder
@@ -11,10 +12,13 @@ import {Action} from "../../../internal/Action.js";
1112
class Pixelate extends Action {
1213
private _region?: NamedRegion;
1314
private _squareSize: number | string;
15+
protected _actionModel: IPixelateModel = {};
1416

1517
constructor(squareSize: number | string) {
1618
super();
1719
this._squareSize = squareSize;
20+
this._actionModel.actionType = 'pixelate';
21+
this._actionModel.squareSize = squareSize as number;
1822
}
1923

2024
/**
@@ -23,6 +27,7 @@ class Pixelate extends Action {
2327
*/
2428
region(pixelateRegion: NamedRegion): this {
2529
this._region = pixelateRegion;
30+
this._actionModel.region = {RegionType: this._region.regionType}
2631
return this;
2732
}
2833

@@ -32,6 +37,7 @@ class Pixelate extends Action {
3237
*/
3338
squareSize(squareSize: number | string): this {
3439
this._squareSize = squareSize;
40+
this._actionModel.squareSize = squareSize as number;
3541
return this;
3642
}
3743

src/internal/models/IEffectActionModel.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ interface IDeshakeEffectModel extends IActionModel{
6868
pixels?: number;
6969
}
7070

71+
interface IPixelateModel extends IActionModel{
72+
squareSize?: number;
73+
region?: {RegionType?: string};
74+
}
75+
7176
export {
7277
IEffectActionWithLevelModel,
7378
ISimpleEffectActionModel,
@@ -81,5 +86,6 @@ export {
8186
IGradientFadeEffecModel,
8287
IAssistColorBlindEffectModel,
8388
ISimulateColorBlindEffectModel,
84-
IDeshakeEffectModel
89+
IDeshakeEffectModel,
90+
IPixelateModel
8591
};

0 commit comments

Comments
 (0)