Skip to content

fix antiremoval from to json #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __TESTS_BUNDLE_SIZE__/bundleSizeTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const bundleSizeTestCases:ITestCase[] = [
},
{
name: 'Import all of the SDK',
sizeLimitInKB: 127,
sizeLimitInKB: 128,
importsArray: [
importFromPackage('* as CloudinaryURLGEN')
]
Expand All @@ -88,7 +88,7 @@ const bundleSizeTestCases:ITestCase[] = [
},
{
name: 'Import All Actions',
sizeLimitInKB: 54,
sizeLimitInKB: 55,
importsArray: [
importFromPackage('Actions')
]
Expand Down
14 changes: 7 additions & 7 deletions __TESTS__/unit/fromJson/overlayUnderlay.fromJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Overlay & Underlay fromJson', () => {
actionType: 'overlay',
source,
position,
blendMode: 'multiply'
blendMode: {blendModeType: 'multiply'}
};

const overlayTransformation = fromJson({actions: [overlayModel]});
Expand Down Expand Up @@ -62,14 +62,14 @@ describe('Overlay & Underlay fromJson', () => {
source,
position,
timelinePosition,
blendMode: 'multiply'
blendMode: {blendModeType: 'antiRemoval', level: '96'}
};

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

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');
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');
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');
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');
});

it('Should generate Overlay for fetch source', () => {
Expand All @@ -88,14 +88,14 @@ describe('Overlay & Underlay fromJson', () => {
actionType: 'overlay',
source,
position,
blendMode: 'multiply'
blendMode: {blendModeType: 'antiRemoval'}
};

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

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');
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');
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');
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');
});

it('Should generate Overlay for text source', () => {
Expand Down
38 changes: 36 additions & 2 deletions __TESTS__/unit/toJson/overlayUnderlay.toJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Overlay & Underlay toJson', () => {
allowOverflow: true,
gravity: {gravityType: 'direction', compass: 'north_east'}
},
blendMode: 'multiply'
blendMode: { blendModeType:'multiply' }
}
]
});
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('Overlay & Underlay toJson', () => {
allowOverflow: true,
gravity: {gravityType: 'direction', compass: 'north_east'}
},
blendMode: 'multiply'
blendMode: {blendModeType: 'multiply'}
}
]
});
Expand Down Expand Up @@ -228,4 +228,38 @@ describe('Overlay & Underlay toJson', () => {
]
});
});

it('Should generate Overlay model for source with Blendmode.antiRemoval', () => {
const transformation = new Transformation();
transformation.addAction(
Overlay.source(Source.fetch('https://some/image.jpg').transformation(new Transformation().resize(scale(100).aspectRatio(7))))
.position(new Position().offsetX(1).offsetY(2).tiled().allowOverflow().gravity(Gravity.compass(Compass.northEast())))
.blendMode(BlendMode.antiRemoval(95))
);

expect(transformation.toJson()).toStrictEqual({
actions: [
{
actionType: 'overlay',
source: {
sourceType: 'fetch',
url: 'https://some/image.jpg',
transformation: {
actions: [
{actionType: 'scale', dimensions: {width: 100, aspectRatio: '7.0'}}
]
}
},
position: {
offsetX: 1,
offsetY: 2,
tiled: true,
allowOverflow: true,
gravity: {gravityType: 'direction', compass: 'north_east'}
},
blendMode: {blendModeType: 'antiRemoval', level: '95'}
}
]
});
});
});
15 changes: 13 additions & 2 deletions src/actions/layer/LayerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {createTimelinePositionFromModel} from "../../internal/models/createTimel
import {ISourceModel} from "../../internal/models/ISourceModel.js";
import {ITimelinePositionModel} from "../../internal/models/ITimelinePositionModel.js";
import {IPositionModel} from "../../internal/models/IPositionModel.js";
import {ACTION_TYPE_TO_BLEND_MODE_MAP} from "../../internal/internalConstants.js";


/**
Expand Down Expand Up @@ -91,8 +92,13 @@ class LayerAction extends Action {
*/
blendMode(blendMode: BlendModeType|BlendModeQualifier): this {
this._blendMode = blendMode;
this._actionModel.blendMode = `${blendMode}`.replace('e_', '');

const [mode, level] = `${blendMode}`.replace('e_', '').split(":");
if (mode === 'anti_removal') {
this._actionModel.blendMode = level ? {blendModeType: 'antiRemoval', level: level} : {blendModeType: 'antiRemoval'};
}else {
this._actionModel.blendMode = {blendModeType: mode};
}
return this;
}

Expand Down Expand Up @@ -171,7 +177,12 @@ class LayerAction extends Action {
}

if (blendMode) {
result.blendMode(blendMode as unknown as BlendModeQualifier);
const blendModeType = ACTION_TYPE_TO_BLEND_MODE_MAP[blendMode.blendModeType] || blendMode.blendModeType;
if(blendMode?.level) {
result.blendMode(new BlendModeQualifier(blendModeType, blendMode.level as number));
}else{
result.blendMode(new BlendModeQualifier(blendModeType));
}
}

return result;
Expand Down
4 changes: 4 additions & 0 deletions src/internal/internalConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export const COLOR_SPACE_MODEL_MODE_TO_COLOR_SPACE_MODE_MAP: Record<string, stri
'srgbTrueColor': 'srgb:truecolor'
};

export const ACTION_TYPE_TO_BLEND_MODE_MAP: Record<string, string> = {
'antiRemoval': 'anti_removal'
};

export const CHROMA_MODEL_ENUM_TO_CHROMA_VALUE = objectFlip(CHROMA_VALUE_TO_CHROMA_MODEL_ENUM);

export const COLOR_SPACE_MODE_TO_COLOR_SPACE_MODEL_MODE_MAP = objectFlip(COLOR_SPACE_MODEL_MODE_TO_COLOR_SPACE_MODE_MAP);
Expand Down
2 changes: 1 addition & 1 deletion src/internal/models/IOverlayActionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface IOverlayActionModel extends IActionModel {
source: ISourceModel;
position?: IPositionModel;
timelinePosition?: ITimelinePositionModel;
blendMode?: string;
blendMode?: {blendModeType?: string, level?: number|string};
}