Skip to content

Commit bd3d13a

Browse files
committed
add makeTransparent toJson
1 parent 76ab868 commit bd3d13a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,17 @@ describe('Effect toJson()', () => {
159159
}
160160
]);
161161
});
162+
163+
it('effect.make_transparent', () => {
164+
const transformation = new Transformation()
165+
.addAction(Effect.makeTransparent().tolerance(5).colorToReplace('red'));
166+
expect(transformation.toJson()).toStrictEqual( [
167+
{
168+
actionType: 'makeTransparent',
169+
tolerance: 5,
170+
level: 5,
171+
color: 'red'
172+
}
173+
]);
174+
});
162175
});

src/actions/effect/leveled/MakeTransparent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Qualifier} from "../../../internal/qualifier/Qualifier.js";
33
import {QualifierValue} from "../../../internal/qualifier/QualifierValue.js";
44
import {prepareColor} from "../../../internal/utils/prepareColor.js";
55
import {SystemColors} from "../../../qualifiers/color.js";
6+
import {IMakeTransparentEffectModel} from "../../../internal/models/IEffectActionModel.js";
67

78
/**
89
* @description Makes the background of the image transparent (or solid white for formats that do not support transparency).
@@ -11,11 +12,13 @@ import {SystemColors} from "../../../qualifiers/color.js";
1112
* @see Visit {@link Actions.Effect|Effect} for an example
1213
*/
1314
class MakeTransparentEffectAction extends LeveledEffectAction {
15+
protected _actionModel: IMakeTransparentEffectModel = {actionType: 'makeTransparent'};
1416
/**
1517
* @description Sets the tolerance used to accommodate variance in the background color.
1618
* @param {number | string} value The tolerance used to accommodate variance in the background color. (Range: 0 to 100, Server default: 10)
1719
*/
1820
tolerance(value: number | string): this {
21+
this._actionModel.tolerance = value as number;
1922
return this.setLevel(value);
2023
}
2124

@@ -25,6 +28,7 @@ class MakeTransparentEffectAction extends LeveledEffectAction {
2528
* @return {this}
2629
*/
2730
colorToReplace(color: SystemColors): this {
31+
this._actionModel.color = color;
2832
return this.addQualifier(new Qualifier('co', new QualifierValue(prepareColor(color))));
2933
}
3034
}

src/internal/models/IEffectActionModel.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ interface IEffectOutlineModel extends IActionModel{
3232
width?: number;
3333
blurLevel?: number;
3434
}
35-
export {IEffectActionWithLevelModel, ISimpleEffectActionModel, IShadowEffectActionModel, IColorizeModel, ICartoonifyEffectModel, IEffectOutlineModel};
35+
36+
interface IMakeTransparentEffectModel extends IActionModel{
37+
tolerance?: number;
38+
color?: string;
39+
}
40+
export {IEffectActionWithLevelModel, ISimpleEffectActionModel, IShadowEffectActionModel, IColorizeModel, ICartoonifyEffectModel, IEffectOutlineModel, IMakeTransparentEffectModel};

0 commit comments

Comments
 (0)