Skip to content

Commit 5bd543b

Browse files
committed
add simulateColorBlind toJson
1 parent ba25148 commit 5bd543b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Transformation} from "../../../src";
22
import {Effect} from "../../../src/actions/effect";
33
import {halftone4x4Orthogonal} from "../../../src/qualifiers/dither";
4+
import {rodMonochromacy} from "../../../src/qualifiers/simulateColorBlind";
45

56

67
describe('Effect toJson()', () => {
@@ -246,4 +247,14 @@ describe('Effect toJson()', () => {
246247
}
247248
]);
248249
});
250+
251+
it('effect.simulateColorBlind', () => {
252+
const transformation = new Transformation()
253+
.addAction(Effect.simulateColorBlind().condition(rodMonochromacy()));
254+
expect(transformation.toJson()).toStrictEqual( [
255+
{ actionType: 'simulateColorblind',
256+
condition: 'rod_monochromacy'
257+
}
258+
]);
259+
});
249260
});

src/actions/effect/SimulateColorBlind.ts

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

56
/**
67
* @description Simulates the way an image would appear to someone with the specified color blind condition
@@ -9,8 +10,10 @@ import {SimulateColorBlindType} from "../../types/types.js";
910
* @see Visit {@link Actions.Effect|Effect} for an example
1011
*/
1112
class SimulateColorBlindEffectAction extends Action {
13+
protected _actionModel: ISimulateColorBlindEffectModel = {};
1214
constructor() {
1315
super();
16+
this._actionModel.actionType = 'simulateColorblind';
1417
this.addQualifier(new Qualifier('e', `simulate_colorblind`));
1518
}
1619

@@ -28,6 +31,7 @@ class SimulateColorBlindEffectAction extends Action {
2831
* @return {this}
2932
*/
3033
condition(cond: SimulateColorBlindType | string): this {
34+
this._actionModel.condition = cond;
3135
return this.setQualifier(cond);
3236
}
3337
}

src/internal/models/IEffectActionModel.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ interface IAssistColorBlindEffectModel extends IActionModel{
6060
type?: string;
6161
}
6262

63+
interface ISimulateColorBlindEffectModel extends IActionModel{
64+
condition?: string;
65+
}
66+
6367
export {
6468
IEffectActionWithLevelModel,
6569
ISimpleEffectActionModel,
@@ -71,5 +75,6 @@ export {
7175
IDitherModel,
7276
IVectorizeEffectModel,
7377
IGradientFadeEffecModel,
74-
IAssistColorBlindEffectModel
78+
IAssistColorBlindEffectModel,
79+
ISimulateColorBlindEffectModel
7580
};

0 commit comments

Comments
 (0)