Skip to content

Commit 6d5a6d5

Browse files
authored
fix antiremoval from to json (#525)
1 parent 3099c62 commit 6d5a6d5

File tree

6 files changed

+63
-14
lines changed

6 files changed

+63
-14
lines changed

__TESTS_BUNDLE_SIZE__/bundleSizeTestCases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const bundleSizeTestCases:ITestCase[] = [
7474
},
7575
{
7676
name: 'Import all of the SDK',
77-
sizeLimitInKB: 127,
77+
sizeLimitInKB: 128,
7878
importsArray: [
7979
importFromPackage('* as CloudinaryURLGEN')
8080
]
@@ -88,7 +88,7 @@ const bundleSizeTestCases:ITestCase[] = [
8888
},
8989
{
9090
name: 'Import All Actions',
91-
sizeLimitInKB: 54,
91+
sizeLimitInKB: 55,
9292
importsArray: [
9393
importFromPackage('Actions')
9494
]

__TESTS__/unit/fromJson/overlayUnderlay.fromJson.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Overlay & Underlay fromJson', () => {
3131
actionType: 'overlay',
3232
source,
3333
position,
34-
blendMode: 'multiply'
34+
blendMode: {blendModeType: 'multiply'}
3535
};
3636

3737
const overlayTransformation = fromJson({actions: [overlayModel]});
@@ -62,14 +62,14 @@ describe('Overlay & Underlay fromJson', () => {
6262
source,
6363
position,
6464
timelinePosition,
65-
blendMode: 'multiply'
65+
blendMode: {blendModeType: 'antiRemoval', level: '96'}
6666
};
6767

6868
const overlayTransformation = fromJson({actions: [overlayModel]});
6969
const underlayTransformation = fromJson({actions: [{...overlayModel, actionType: 'underlay'}]});
7070

71-
expect(overlayTransformation.toString()).toStrictEqual('l_video:dog.mp4/ar_7.0,c_scale,w_100/du_2,e_multiply,fl_layer_apply,fl_tiled,g_north_east,so_1,x_1,y_2');
72-
expect(underlayTransformation.toString()).toStrictEqual('u_video:dog.mp4/ar_7.0,c_scale,w_100/du_2,e_multiply,fl_layer_apply,fl_tiled,g_north_east,so_1,x_1,y_2');
71+
expect(overlayTransformation.toString()).toStrictEqual('l_video:dog.mp4/ar_7.0,c_scale,w_100/du_2,e_anti_removal:96,fl_layer_apply,fl_tiled,g_north_east,so_1,x_1,y_2');
72+
expect(underlayTransformation.toString()).toStrictEqual('u_video:dog.mp4/ar_7.0,c_scale,w_100/du_2,e_anti_removal:96,fl_layer_apply,fl_tiled,g_north_east,so_1,x_1,y_2');
7373
});
7474

7575
it('Should generate Overlay for fetch source', () => {
@@ -88,14 +88,14 @@ describe('Overlay & Underlay fromJson', () => {
8888
actionType: 'overlay',
8989
source,
9090
position,
91-
blendMode: 'multiply'
91+
blendMode: {blendModeType: 'antiRemoval'}
9292
};
9393

9494
const overlayTransformation = fromJson({actions: [overlayModel]});
9595
const underlayTransformation = fromJson({actions: [{...overlayModel, actionType: 'underlay'}]});
9696

97-
expect(overlayTransformation.toString()).toStrictEqual('l_fetch:aHR0cHM6Ly9zb21lL2ltYWdlLmpwZw==/ar_7.0,c_scale,w_100/e_multiply,fl_layer_apply,fl_tiled,g_north_east,x_1,y_2');
98-
expect(underlayTransformation.toString()).toStrictEqual('u_fetch:aHR0cHM6Ly9zb21lL2ltYWdlLmpwZw==/ar_7.0,c_scale,w_100/e_multiply,fl_layer_apply,fl_tiled,g_north_east,x_1,y_2');
97+
expect(overlayTransformation.toString()).toStrictEqual('l_fetch:aHR0cHM6Ly9zb21lL2ltYWdlLmpwZw==/ar_7.0,c_scale,w_100/e_anti_removal,fl_layer_apply,fl_tiled,g_north_east,x_1,y_2');
98+
expect(underlayTransformation.toString()).toStrictEqual('u_fetch:aHR0cHM6Ly9zb21lL2ltYWdlLmpwZw==/ar_7.0,c_scale,w_100/e_anti_removal,fl_layer_apply,fl_tiled,g_north_east,x_1,y_2');
9999
});
100100

101101
it('Should generate Overlay for text source', () => {

__TESTS__/unit/toJson/overlayUnderlay.toJson.test.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Overlay & Underlay toJson', () => {
4848
allowOverflow: true,
4949
gravity: {gravityType: 'direction', compass: 'north_east'}
5050
},
51-
blendMode: 'multiply'
51+
blendMode: { blendModeType:'multiply' }
5252
}
5353
]
5454
});
@@ -119,7 +119,7 @@ describe('Overlay & Underlay toJson', () => {
119119
allowOverflow: true,
120120
gravity: {gravityType: 'direction', compass: 'north_east'}
121121
},
122-
blendMode: 'multiply'
122+
blendMode: {blendModeType: 'multiply'}
123123
}
124124
]
125125
});
@@ -228,4 +228,38 @@ describe('Overlay & Underlay toJson', () => {
228228
]
229229
});
230230
});
231+
232+
it('Should generate Overlay model for source with Blendmode.antiRemoval', () => {
233+
const transformation = new Transformation();
234+
transformation.addAction(
235+
Overlay.source(Source.fetch('https://some/image.jpg').transformation(new Transformation().resize(scale(100).aspectRatio(7))))
236+
.position(new Position().offsetX(1).offsetY(2).tiled().allowOverflow().gravity(Gravity.compass(Compass.northEast())))
237+
.blendMode(BlendMode.antiRemoval(95))
238+
);
239+
240+
expect(transformation.toJson()).toStrictEqual({
241+
actions: [
242+
{
243+
actionType: 'overlay',
244+
source: {
245+
sourceType: 'fetch',
246+
url: 'https://some/image.jpg',
247+
transformation: {
248+
actions: [
249+
{actionType: 'scale', dimensions: {width: 100, aspectRatio: '7.0'}}
250+
]
251+
}
252+
},
253+
position: {
254+
offsetX: 1,
255+
offsetY: 2,
256+
tiled: true,
257+
allowOverflow: true,
258+
gravity: {gravityType: 'direction', compass: 'north_east'}
259+
},
260+
blendMode: {blendModeType: 'antiRemoval', level: '95'}
261+
}
262+
]
263+
});
264+
});
231265
});

src/actions/layer/LayerAction.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {createTimelinePositionFromModel} from "../../internal/models/createTimel
1717
import {ISourceModel} from "../../internal/models/ISourceModel.js";
1818
import {ITimelinePositionModel} from "../../internal/models/ITimelinePositionModel.js";
1919
import {IPositionModel} from "../../internal/models/IPositionModel.js";
20+
import {ACTION_TYPE_TO_BLEND_MODE_MAP} from "../../internal/internalConstants.js";
2021

2122

2223
/**
@@ -91,8 +92,13 @@ class LayerAction extends Action {
9192
*/
9293
blendMode(blendMode: BlendModeType|BlendModeQualifier): this {
9394
this._blendMode = blendMode;
94-
this._actionModel.blendMode = `${blendMode}`.replace('e_', '');
9595

96+
const [mode, level] = `${blendMode}`.replace('e_', '').split(":");
97+
if (mode === 'anti_removal') {
98+
this._actionModel.blendMode = level ? {blendModeType: 'antiRemoval', level: level} : {blendModeType: 'antiRemoval'};
99+
}else {
100+
this._actionModel.blendMode = {blendModeType: mode};
101+
}
96102
return this;
97103
}
98104

@@ -171,7 +177,12 @@ class LayerAction extends Action {
171177
}
172178

173179
if (blendMode) {
174-
result.blendMode(blendMode as unknown as BlendModeQualifier);
180+
const blendModeType = ACTION_TYPE_TO_BLEND_MODE_MAP[blendMode.blendModeType] || blendMode.blendModeType;
181+
if(blendMode?.level) {
182+
result.blendMode(new BlendModeQualifier(blendModeType, blendMode.level as number));
183+
}else{
184+
result.blendMode(new BlendModeQualifier(blendModeType));
185+
}
175186
}
176187

177188
return result;

src/internal/internalConstants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export const COLOR_SPACE_MODEL_MODE_TO_COLOR_SPACE_MODE_MAP: Record<string, stri
139139
'srgbTrueColor': 'srgb:truecolor'
140140
};
141141

142+
export const ACTION_TYPE_TO_BLEND_MODE_MAP: Record<string, string> = {
143+
'antiRemoval': 'anti_removal'
144+
};
145+
142146
export const CHROMA_MODEL_ENUM_TO_CHROMA_VALUE = objectFlip(CHROMA_VALUE_TO_CHROMA_MODEL_ENUM);
143147

144148
export const COLOR_SPACE_MODE_TO_COLOR_SPACE_MODEL_MODE_MAP = objectFlip(COLOR_SPACE_MODEL_MODE_TO_COLOR_SPACE_MODE_MAP);

src/internal/models/IOverlayActionModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export interface IOverlayActionModel extends IActionModel {
88
source: ISourceModel;
99
position?: IPositionModel;
1010
timelinePosition?: ITimelinePositionModel;
11-
blendMode?: string;
11+
blendMode?: {blendModeType?: string, level?: number|string};
1212
}

0 commit comments

Comments
 (0)