UNPKG

@cloudinary/url-gen

Version:

Cloudinary URL-Gen SDK ========================= [![Build Status](https://api.travis-ci.com/cloudinary/js-url-gen.svg?branch=master)](https://app.travis-ci.com/github/cloudinary/js-url-gen) ## About The Cloudinary URL-Gen SDK allows you to quickly and eas

72 lines (68 loc) 2.17 kB
'use strict'; var flag = require('./flag-16e9dd5f.cjs'); var DeliveryAction = require('./DeliveryAction-958d8fb5.cjs'); var progressive = require('./progressive-47125d1f.cjs'); /** * @memberOf Actions.Delivery * @extends {Actions.Delivery.DeliveryAction} * @see Visit {@link Actions.Delivery|Delivery} for an example */ class DeliveryFormatAction extends DeliveryAction.DeliveryAction { constructor(deliveryKey, deliveryType) { super(deliveryKey, deliveryType, 'formatType'); } /** * @description Uses lossy compression when delivering animated GIF files. * @return {this} */ lossy() { this._actionModel.lossy = true; this.addFlag(flag.lossy()); return this; } /** * @description Uses progressive compression when delivering JPG file format. * @return {this} */ progressive(mode) { if (mode instanceof progressive.ProgressiveQualifier) { this._actionModel.progressive = { mode: mode.getFlagValue() }; this.addFlag(mode); } else { this._actionModel.progressive = { mode: mode }; this.addFlag(flag.progressive(mode)); } return this; } /** * @description Ensures that images with a transparency channel are delivered in PNG format. */ preserveTransparency() { this._actionModel.preserveTransparency = true; this.addFlag(flag.preserveTransparency()); return this; } static fromJson(actionModel) { const { formatType, lossy, progressive, preserveTransparency } = actionModel; let result; if (formatType) { result = new this('f', formatType); } else { result = new this('f'); } if (progressive) { if (progressive.mode) { result.progressive(progressive.mode); } else { result.progressive(); } } lossy && result.lossy(); preserveTransparency && result.preserveTransparency(); return result; } } exports.DeliveryFormatAction = DeliveryFormatAction;