Skip to content
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
2 changes: 1 addition & 1 deletion __TESTS_BUNDLE_SIZE__/bundleSizeTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const bundleSizeTestCases:ITestCase[] = [
},
{
name: 'Tests CloudinaryImage with Resize and Adjust',
sizeLimitInKB: 22,
sizeLimitInKB: 23,
importsArray: [
importFromDist('assets/CloudinaryImage', 'CloudinaryImage'),
importFromDist('instance/Cloudinary', 'Cloudinary'),
Expand Down
24 changes: 24 additions & 0 deletions __TESTS__/unit/fromJson/delivery.fromJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,28 @@ describe('delivery.fromJson', () => {

expect(transformation.toString()).toStrictEqual('cs_icc:sample');
});

it('jpg.progressive.semi()', () => {
const transformation = fromJson([
{
progressive: { mode: 'semi' },
actionType: 'format',
formatType: 'jpg'
}
]);

expect(transformation.toString()).toStrictEqual('f_jpg,fl_progressive:semi');
});

it('gif.lossy()', () => {
const transformation = fromJson([
{
actionType: 'format',
formatType: 'gif',
lossy: true
}
]);

expect(transformation.toString()).toStrictEqual('f_gif,fl_lossy');
});
});
2 changes: 1 addition & 1 deletion __TESTS__/unit/toJson/delivery.toJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Delivery.toJson()', () => {
]);
});

it('jpg.progressive.semi()', () => {
it('jpg.progressive("semi")', () => {
const transformation = new Transformation()
.addAction(Delivery.format(Format.jpg()).progressive('semi'));
expect(transformation.toJson()).toStrictEqual([
Expand Down
6 changes: 3 additions & 3 deletions src/actions/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* See the examples under every method
*/

import {DeliveryFormat} from "./delivery/DeliveryFormat.js";
import {DeliveryFormatAction} from "./delivery/DeliveryFormatAction.js";
import {DeliveryQualityAction} from "./delivery/DeliveryQuality.js";
import {FormatQualifier} from "../qualifiers/format/FormatQualifier.js";
import {toFloatAsString} from "../internal/utils/toFloatAsString.js";
Expand Down Expand Up @@ -42,8 +42,8 @@ export type IDeliveryAction = DeliveryAction | DeliveryColorSpaceAction | Delive
* );
*
*/
function format(format:FormatQualifier | ImageFormatType | VideoFormatType | string) :DeliveryFormat {
return new DeliveryFormat('f', format);
function format(format:FormatQualifier | ImageFormatType | VideoFormatType | string) :DeliveryFormatAction {
return new DeliveryFormatAction('f', format);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {DeliveryAction} from "./DeliveryAction.js";
import {ProgressiveQualifier} from "../../qualifiers/progressive.js";
import {FormatQualifier} from "../../qualifiers/format/FormatQualifier.js";
import {ProgressiveType} from "../../types/types.js";
import {IActionModel} from "../../internal/models/IActionModel.js";
import {IDeliveryFormatModel} from "../../internal/models/IDeliveryActionModel.js";

/**
* @memberOf Actions.Delivery
* @extends {Actions.Delivery.DeliveryAction}
* @see Visit {@link Actions.Delivery|Delivery} for an example
*/
class DeliveryFormat extends DeliveryAction {
class DeliveryFormatAction extends DeliveryAction {
constructor(deliveryKey?: string, deliveryType?: FormatQualifier|string|number) {
super(deliveryKey, deliveryType, 'formatType');
}
Expand Down Expand Up @@ -46,6 +48,30 @@ class DeliveryFormat extends DeliveryAction {
this.addFlag(preserveTransparency());
return this;
}

static fromJson(actionModel: IActionModel): DeliveryFormatAction {
const {formatType, lossy, progressive, preserveTransparency} = (actionModel as IDeliveryFormatModel);
let result: DeliveryFormatAction;

if (formatType) {
result = new this('f', formatType);
} else{
result = new this('f');
}

if (progressive){
if (progressive.mode){
result.progressive(progressive.mode as unknown as ProgressiveQualifier);
} else{
result.progressive();
}
}

lossy && result.lossy();
preserveTransparency && result.preserveTransparency();

return result;
}
}

export {DeliveryFormat};
export {DeliveryFormatAction};
7 changes: 3 additions & 4 deletions src/assets/CloudinaryTransformable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import IURLConfig from "../config/interfaces/Config/IURLConfig.js";
import ICloudConfig from "../config/interfaces/Config/ICloudConfig.js";
import {IDeliveryAction} from "../actions/delivery.js";
import {IAdjustAction} from "../actions/adjust.js";
import {DeliveryQualityAction} from "../actions/delivery/DeliveryQuality.js";
import {ITrackedPropertiesThroughAnalytics} from "../sdkAnalytics/interfaces/ITrackedPropertiesThroughAnalytics.js";
import {AnimatedAction} from "../actions/animated.js";
import {DeliveryFormat} from "../actions/delivery/DeliveryFormat.js";
import {DeliveryFormatAction} from "../actions/delivery/DeliveryFormatAction.js";

/**
* @desc Cloudinary Transformable interface, extended by any class that needs a Transformation Interface
Expand Down Expand Up @@ -86,7 +85,7 @@ class CloudinaryTransformable extends CloudinaryFile {
* @return {this}
*/
quality(quality: string|number): this {
this.addAction(new DeliveryFormat('q', quality));
this.addAction(new DeliveryFormatAction('q', quality));
return this;
}

Expand All @@ -96,7 +95,7 @@ class CloudinaryTransformable extends CloudinaryFile {
* @return {this}
*/
format(format: string): this {
this.addAction(new DeliveryFormat('f', format));
this.addAction(new DeliveryFormatAction('f', format));
return this;
}

Expand Down
4 changes: 3 additions & 1 deletion src/internal/fromJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {ResizeLimitPadAction} from "../actions/resize/ResizeLimitPadAction.js";
import {ResizeMinimumPadAction} from "../actions/resize/ResizeMinimumPadAction.js";
import {DeliveryColorSpaceAction} from "../actions/delivery/DeliveryColorSpaceAction.js";
import {DeliveryColorSpaceFromICCAction} from "../actions/delivery/DeliveryColorSpaceFromICCAction.js";
import {DeliveryFormatAction} from "../actions/delivery/DeliveryFormatAction.js";

const ActionModelMap: Record<string, IHasFromJson> = {
scale: ResizeScaleAction,
Expand All @@ -31,7 +32,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
limitPad: ResizeLimitPadAction,
minimumPad: ResizeMinimumPadAction,
colorSpace: DeliveryColorSpaceAction,
colorSpaceFromICC: DeliveryColorSpaceFromICCAction
colorSpaceFromICC: DeliveryColorSpaceFromICCAction,
format: DeliveryFormatAction
};

/**
Expand Down