Skip to content

Commit 14bba57

Browse files
committed
add blur fromJson
1 parent 4a087d9 commit 14bba57

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ describe('effect.fromJson', () => {
2929
{ actionType: 'assistColorblind', type: 'xray' },
3030
{ actionType: 'simulateColorblind', condition: 'rod_monochromacy' },
3131
{ actionType: 'deshake', pixels: 16 },
32-
{ actionType: 'pixelate', squareSize: 15, region: { RegionType: 'faces' }}
32+
{ actionType: 'pixelate', squareSize: 15, region: { RegionType: 'faces' }},
33+
{ actionType: 'blur', strength: 5 }
3334
]);
3435

3536
expect(transformation.toString()).toStrictEqual([
@@ -59,7 +60,8 @@ describe('effect.fromJson', () => {
5960
'e_assist_colorblind:xray',
6061
'e_simulate_colorblind:rod_monochromacy',
6162
'e_deshake:16',
62-
'e_pixelate_faces:15'
63+
'e_pixelate_faces:15',
64+
'e_blur:5'
6365
].join('/'));
6466
});
6567
});

src/actions/effect/blur/Blur.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {NamedRegion} from "../../../qualifiers/region/NamedRegion.js";
22
import {Qualifier} from "../../../internal/qualifier/Qualifier.js";
33
import {Action} from "../../../internal/Action.js";
44
import {IBlurModel} from "../../../internal/models/IEffectActionModel.js";
5+
import {IActionModel} from "../../../internal/models/IActionModel.js";
6+
import {custom, faces} from "../../../qualifiers/region.js";
57

68
/**
79
* @description The Action class of the blur Builder.
@@ -83,6 +85,24 @@ class BlurAction extends Action {
8385
this.addQualifier(new Qualifier('e', `blur${str}`));
8486
}
8587
}
88+
static fromJson(actionModel: IActionModel): BlurAction {
89+
const {actionType, strength, region} = (actionModel as IBlurModel);
90+
91+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
92+
// This allows the inheriting classes to determine the class to be created
93+
const result = new this(strength);
94+
strength && result.strength(strength);
95+
96+
if(region && region.RegionType === 'faces'){
97+
result.region(faces());
98+
}
99+
100+
if(region && region.RegionType === 'custom'){
101+
result.region(custom());
102+
}
103+
104+
return result;
105+
}
86106
}
87107

88108

src/actions/effect/pixelate/Pixelate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ class Pixelate extends Action {
9494
const result = new this(squareSize);
9595
squareSize && result.squareSize(squareSize);
9696

97-
if(region.RegionType === 'faces'){
97+
if(region && region.RegionType === 'faces'){
9898
result.region(faces());
9999
}
100100

101-
if(region.RegionType === 'custom'){
101+
if(region && region.RegionType === 'custom'){
102102
result.region(custom());
103103
}
104104

src/internal/fromJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {AssistColorBlindEffectAction} from "../actions/effect/AssistColorBlind.j
3737
import {SimulateColorBlindEffectAction} from "../actions/effect/SimulateColorBlind.js";
3838
import {DeshakeEffectAction} from "../actions/effect/leveled/Deshake.js";
3939
import {Pixelate} from "../actions/effect/pixelate/Pixelate.js";
40+
import {BlurAction} from "../actions/effect/blur/Blur.js";
4041

4142
const ActionModelMap: Record<string, IHasFromJson> = {
4243
scale: ResizeScaleAction,
@@ -79,7 +80,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
7980
assistColorblind: AssistColorBlindEffectAction,
8081
simulateColorblind: SimulateColorBlindEffectAction,
8182
deshake: DeshakeEffectAction,
82-
pixelate: Pixelate
83+
pixelate: Pixelate,
84+
blur: BlurAction
8385
};
8486

8587
/**

src/internal/models/IEffectActionModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {IActionModel} from "./IActionModel.js";
2-
import {ExpressionQualifier} from "../../qualifiers/expression/ExpressionQualifier.js";
32

43
interface IEffectActionWithLevelModel extends IActionModel{
54
level?: number;

0 commit comments

Comments
 (0)