Skip to content

Commit 7ebbeb7

Browse files
committed
add improve fromJson
1 parent cbf66e2 commit 7ebbeb7

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {fromJson} from "../../../src/internal/fromJson";
2+
3+
describe('adjust.fromJson', () => {
4+
it('should generate a url with adjust actions from array of models', function () {
5+
const transformation = fromJson([
6+
{ actionType: 'improve', mode: 'outdoor', blend: 30}
7+
]);
8+
9+
expect(transformation.toString()).toStrictEqual([
10+
'e_improve:outdoor:30',
11+
].join('/'));
12+
});
13+
});

src/actions/adjust/ImproveAction.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {Action} from "../../internal/Action.js";
22
import {QualifierValue} from "../../internal/qualifier/QualifierValue.js";
33
import {Qualifier} from "../../internal/qualifier/Qualifier.js";
44
import {stringOrNumber} from "../../types/types.js";
5-
import {ImproveActionModel} from "../../internal/models/IAdjustActionModel";
5+
import {ImproveActionModel} from "../../internal/models/IAdjustActionModel.js";
6+
import {IActionModel} from "../../internal/models/IActionModel.js";
67

78
/**
89
* @description Defines how to improve an image by automatically adjusting image colors, contrast and brightness.</br>
@@ -43,6 +44,18 @@ class ImproveAction extends Action {
4344
this.addQualifier(new Qualifier('e', qualifierValue));
4445
return this;
4546
}
47+
48+
static fromJson(actionModel: IActionModel): ImproveAction{
49+
const {mode, blend} = (actionModel as ImproveActionModel);
50+
51+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
52+
// This allows the inheriting classes to determine the class to be created
53+
const result = new this();
54+
mode && result.mode(mode);
55+
blend && result.blend(blend);
56+
57+
return result;
58+
}
4659
}
4760

4861
export {ImproveAction};

src/internal/fromJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {SimulateColorBlindEffectAction} from "../actions/effect/SimulateColorBli
3838
import {DeshakeEffectAction} from "../actions/effect/leveled/Deshake.js";
3939
import {Pixelate} from "../actions/effect/pixelate/Pixelate.js";
4040
import {BlurAction} from "../actions/effect/blur/Blur.js";
41+
import {ImproveAction} from "../actions/adjust/ImproveAction.js";
4142

4243
const ActionModelMap: Record<string, IHasFromJson> = {
4344
scale: ResizeScaleAction,
@@ -81,7 +82,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
8182
simulateColorblind: SimulateColorBlindEffectAction,
8283
deshake: DeshakeEffectAction,
8384
pixelate: Pixelate,
84-
blur: BlurAction
85+
blur: BlurAction,
86+
improve: ImproveAction
8587
};
8688

8789
/**

0 commit comments

Comments
 (0)