} Transformation.PARAM_NAMES
* @private
* @ignore
* @see toHtmlAttributes
*/
var transformation_Transformation =
/*#__PURE__*/
function (_TransformationBase) {
transformation_inherits(Transformation, _TransformationBase);
/**
* Represents a single transformation.
* @class Transformation
* @example
* t = new cloudinary.Transformation();
* t.angle(20).crop("scale").width("auto");
*
* // or
*
* t = new cloudinary.Transformation( {angle: 20, crop: "scale", width: "auto"});
* @see Available image transformations
* @see Available video transformations
*/
function Transformation(options) {
transformation_classCallCheck(this, Transformation);
return transformation_possibleConstructorReturn(this, transformation_getPrototypeOf(Transformation).call(this, options));
}
/**
* Convenience constructor
* @param {Object} options
* @return {Transformation}
* @example cl = cloudinary.Transformation.new( {angle: 20, crop: "scale", width: "auto"})
*/
transformation_createClass(Transformation, [{
key: "angle",
/*
Transformation Parameters
*/
value: function angle(value) {
return this.arrayParam(value, "angle", "a", ".", expression.normalize);
}
}, {
key: "audioCodec",
value: function audioCodec(value) {
return this.param(value, "audio_codec", "ac");
}
}, {
key: "audioFrequency",
value: function audioFrequency(value) {
return this.param(value, "audio_frequency", "af");
}
}, {
key: "aspectRatio",
value: function aspectRatio(value) {
return this.param(value, "aspect_ratio", "ar", expression.normalize);
}
}, {
key: "background",
value: function background(value) {
return this.param(value, "background", "b", parameters_Param.norm_color);
}
}, {
key: "bitRate",
value: function bitRate(value) {
return this.param(value, "bit_rate", "br");
}
}, {
key: "border",
value: function border(value) {
return this.param(value, "border", "bo", function (border) {
if (isPlainObject(border)) {
border = jquery_assign({}, {
color: "black",
width: 2
}, border);
return "".concat(border.width, "px_solid_").concat(parameters_Param.norm_color(border.color));
} else {
return border;
}
});
}
}, {
key: "color",
value: function color(value) {
return this.param(value, "color", "co", parameters_Param.norm_color);
}
}, {
key: "colorSpace",
value: function colorSpace(value) {
return this.param(value, "color_space", "cs");
}
}, {
key: "crop",
value: function crop(value) {
return this.param(value, "crop", "c");
}
}, {
key: "customFunction",
value: function customFunction(value) {
return this.param(value, "custom_function", "fn", function () {
return processCustomFunction(value);
});
}
}, {
key: "customPreFunction",
value: function customPreFunction(value) {
if (this.get('custom_function')) {
return;
}
return this.rawParam(value, "custom_function", "", function () {
value = processCustomFunction(value);
return value ? "fn_pre:".concat(value) : value;
});
}
}, {
key: "defaultImage",
value: function defaultImage(value) {
return this.param(value, "default_image", "d");
}
}, {
key: "delay",
value: function delay(value) {
return this.param(value, "delay", "dl");
}
}, {
key: "density",
value: function density(value) {
return this.param(value, "density", "dn");
}
}, {
key: "duration",
value: function duration(value) {
return this.rangeParam(value, "duration", "du");
}
}, {
key: "dpr",
value: function dpr(value) {
return this.param(value, "dpr", "dpr", function (dpr) {
dpr = dpr.toString();
if (dpr != null ? dpr.match(/^\d+$/) : void 0) {
return dpr + ".0";
} else {
return expression.normalize(dpr);
}
});
}
}, {
key: "effect",
value: function effect(value) {
return this.arrayParam(value, "effect", "e", ":", expression.normalize);
}
}, {
key: "else",
value: function _else() {
return this["if"]('else');
}
}, {
key: "endIf",
value: function endIf() {
return this["if"]('end');
}
}, {
key: "endOffset",
value: function endOffset(value) {
return this.rangeParam(value, "end_offset", "eo");
}
}, {
key: "fallbackContent",
value: function fallbackContent(value) {
return this.param(value, "fallback_content");
}
}, {
key: "fetchFormat",
value: function fetchFormat(value) {
return this.param(value, "fetch_format", "f");
}
}, {
key: "format",
value: function format(value) {
return this.param(value, "format");
}
}, {
key: "flags",
value: function flags(value) {
return this.arrayParam(value, "flags", "fl", ".");
}
}, {
key: "gravity",
value: function gravity(value) {
return this.param(value, "gravity", "g");
}
}, {
key: "fps",
value: function fps(value) {
return this.param(value, "fps", "fps", function (fps) {
if (isString(fps)) {
return fps;
} else if (isArray(fps)) {
return fps.join("-");
} else {
return fps;
}
});
}
}, {
key: "height",
value: function height(value) {
var _this3 = this;
return this.param(value, "height", "h", function () {
if (_this3.getValue("crop") || _this3.getValue("overlay") || _this3.getValue("underlay")) {
return expression.normalize(value);
} else {
return null;
}
});
}
}, {
key: "htmlHeight",
value: function htmlHeight(value) {
return this.param(value, "html_height");
}
}, {
key: "htmlWidth",
value: function htmlWidth(value) {
return this.param(value, "html_width");
}
}, {
key: "if",
value: function _if() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var i, ifVal, j, ref, trIf, trRest;
switch (value) {
case "else":
this.chain();
return this.param(value, "if", "if");
case "end":
this.chain();
for (i = j = ref = this.chained.length - 1; j >= 0; i = j += -1) {
ifVal = this.chained[i].getValue("if");
if (ifVal === "end") {
break;
} else if (ifVal != null) {
trIf = Transformation["new"]()["if"](ifVal);
this.chained[i].remove("if");
trRest = this.chained[i];
this.chained[i] = Transformation["new"]().transformation([trIf, trRest]);
if (ifVal !== "else") {
break;
}
}
}
return this.param(value, "if", "if");
case "":
return condition["new"]().setParent(this);
default:
return this.param(value, "if", "if", function (value) {
return condition["new"](value).toString();
});
}
}
}, {
key: "keyframeInterval",
value: function keyframeInterval(value) {
return this.param(value, "keyframe_interval", "ki");
}
}, {
key: "offset",
value: function offset(value) {
var end_o, start_o;
var _ref = isFunction(value != null ? value.split : void 0) ? value.split('..') : isArray(value) ? value : [null, null];
var _ref2 = transformation_slicedToArray(_ref, 2);
start_o = _ref2[0];
end_o = _ref2[1];
if (start_o != null) {
this.startOffset(start_o);
}
if (end_o != null) {
return this.endOffset(end_o);
}
}
}, {
key: "opacity",
value: function opacity(value) {
return this.param(value, "opacity", "o", expression.normalize);
}
}, {
key: "overlay",
value: function overlay(value) {
return this.layerParam(value, "overlay", "l");
}
}, {
key: "page",
value: function page(value) {
return this.param(value, "page", "pg");
}
}, {
key: "poster",
value: function poster(value) {
return this.param(value, "poster");
}
}, {
key: "prefix",
value: function prefix(value) {
return this.param(value, "prefix", "p");
}
}, {
key: "quality",
value: function quality(value) {
return this.param(value, "quality", "q", expression.normalize);
}
}, {
key: "radius",
value: function radius(value) {
return this.arrayParam(value, "radius", "r", ":", expression.normalize);
}
}, {
key: "rawTransformation",
value: function rawTransformation(value) {
return this.rawParam(value, "raw_transformation");
}
}, {
key: "size",
value: function size(value) {
var height, width;
if (isFunction(value != null ? value.split : void 0)) {
var _value$split = value.split('x');
var _value$split2 = transformation_slicedToArray(_value$split, 2);
width = _value$split2[0];
height = _value$split2[1];
this.width(width);
return this.height(height);
}
}
}, {
key: "sourceTypes",
value: function sourceTypes(value) {
return this.param(value, "source_types");
}
}, {
key: "sourceTransformation",
value: function sourceTransformation(value) {
return this.param(value, "source_transformation");
}
}, {
key: "startOffset",
value: function startOffset(value) {
return this.rangeParam(value, "start_offset", "so");
}
}, {
key: "streamingProfile",
value: function streamingProfile(value) {
return this.param(value, "streaming_profile", "sp");
}
}, {
key: "transformation",
value: function transformation(value) {
return this.transformationParam(value, "transformation", "t");
}
}, {
key: "underlay",
value: function underlay(value) {
return this.layerParam(value, "underlay", "u");
}
}, {
key: "variable",
value: function variable(name, value) {
return this.param(value, name, name);
}
}, {
key: "variables",
value: function variables(values) {
return this.arrayParam(values, "variables");
}
}, {
key: "videoCodec",
value: function videoCodec(value) {
return this.param(value, "video_codec", "vc", parameters_Param.process_video_params);
}
}, {
key: "videoSampling",
value: function videoSampling(value) {
return this.param(value, "video_sampling", "vs");
}
}, {
key: "width",
value: function width(value) {
var _this4 = this;
return this.param(value, "width", "w", function () {
if (_this4.getValue("crop") || _this4.getValue("overlay") || _this4.getValue("underlay")) {
return expression.normalize(value);
} else {
return null;
}
});
}
}, {
key: "x",
value: function x(value) {
return this.param(value, "x", "x", expression.normalize);
}
}, {
key: "y",
value: function y(value) {
return this.param(value, "y", "y", expression.normalize);
}
}, {
key: "zoom",
value: function zoom(value) {
return this.param(value, "zoom", "z", expression.normalize);
}
}], [{
key: "new",
value: function _new(options) {
return new Transformation(options);
}
}]);
return Transformation;
}(transformation_TransformationBase);
/**
* Transformation Class methods.
* This is a list of the parameters defined in Transformation.
* Values are camelCased.
*/
transformation_Transformation.methods = ["angle", "audioCodec", "audioFrequency", "aspectRatio", "background", "bitRate", "border", "color", "colorSpace", "crop", "customFunction", "customPreFunction", "defaultImage", "delay", "density", "duration", "dpr", "effect", "else", "endIf", "endOffset", "fallbackContent", "fetchFormat", "format", "flags", "gravity", "fps", "height", "htmlHeight", "htmlWidth", "if", "keyframeInterval", "offset", "opacity", "overlay", "page", "poster", "prefix", "quality", "radius", "rawTransformation", "size", "sourceTypes", "sourceTransformation", "startOffset", "streamingProfile", "transformation", "underlay", "variable", "variables", "videoCodec", "videoSampling", "width", "x", "y", "zoom"];
/**
* Parameters that are filtered out before passing the options to an HTML tag.
*
* The list of parameters is a combination of `Transformation::methods` and `Configuration::CONFIG_PARAMS`
*/
transformation_Transformation.PARAM_NAMES = transformation_Transformation.methods.map(snakeCase).concat(src_configuration.CONFIG_PARAMS);
/* harmony default export */ var src_transformation = (transformation_Transformation);
// CONCATENATED MODULE: ./src/tags/htmltag.js
function htmltag_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function htmltag_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function htmltag_createClass(Constructor, protoProps, staticProps) { if (protoProps) htmltag_defineProperties(Constructor.prototype, protoProps); if (staticProps) htmltag_defineProperties(Constructor, staticProps); return Constructor; }
/**
* Generic HTML tag
* Depends on 'transformation', 'util'
*/
/**
* Represents an HTML (DOM) tag
* @constructor HtmlTag
* @param {string} name - the name of the tag
* @param {string} [publicId]
* @param {Object} options
* @example tag = new HtmlTag( 'div', { 'width': 10})
*/
var htmltag_HtmlTag =
/*#__PURE__*/
function () {
function HtmlTag(name, publicId, options) {
htmltag_classCallCheck(this, HtmlTag);
var transformation;
this.name = name;
this.publicId = publicId;
if (options == null) {
if (isPlainObject(publicId)) {
options = publicId;
this.publicId = void 0;
} else {
options = {};
}
}
transformation = new src_transformation(options);
transformation.setParent(this);
this.transformation = function () {
return transformation;
};
}
/**
* Convenience constructor
* Creates a new instance of an HTML (DOM) tag
* @function HtmlTag.new
* @param {string} name - the name of the tag
* @param {string} [publicId]
* @param {Object} options
* @return {HtmlTag}
* @example tag = HtmlTag.new( 'div', { 'width': 10})
*/
htmltag_createClass(HtmlTag, [{
key: "htmlAttrs",
/**
* combine key and value from the `attr` to generate an HTML tag attributes string.
* `Transformation::toHtmlTagOptions` is used to filter out transformation and configuration keys.
* @protected
* @param {Object} attrs
* @return {string} the attributes in the format `'key1="value1" key2="value2"'`
* @ignore
*/
value: function htmlAttrs(attrs) {
var key, pairs, value;
return pairs = function () {
var results;
results = [];
for (key in attrs) {
value = escapeQuotes(attrs[key]);
if (value) {
results.push(toAttribute(key, value));
}
}
return results;
}().sort().join(' ');
}
/**
* Get all options related to this tag.
* @function HtmlTag#getOptions
* @returns {Object} the options
*
*/
}, {
key: "getOptions",
value: function getOptions() {
return this.transformation().toOptions();
}
/**
* Get the value of option `name`
* @function HtmlTag#getOption
* @param {string} name - the name of the option
* @returns {*} Returns the value of the option
*
*/
}, {
key: "getOption",
value: function getOption(name) {
return this.transformation().getValue(name);
}
/**
* Get the attributes of the tag.
* @function HtmlTag#attributes
* @returns {Object} attributes
*/
}, {
key: "attributes",
value: function attributes() {
// The attributes are be computed from the options every time this method is invoked.
var htmlAttributes = this.transformation().toHtmlAttributes();
Object.keys(htmlAttributes).forEach(function (key) {
if (isPlainObject(htmlAttributes[key])) {
delete htmlAttributes[key];
}
});
if (htmlAttributes.attributes) {
// Currently HTML attributes are defined both at the top level and under 'attributes'
jquery_merge(htmlAttributes, htmlAttributes.attributes);
delete htmlAttributes.attributes;
}
return htmlAttributes;
}
/**
* Set a tag attribute named `name` to `value`
* @function HtmlTag#setAttr
* @param {string} name - the name of the attribute
* @param {string} value - the value of the attribute
*/
}, {
key: "setAttr",
value: function setAttr(name, value) {
this.transformation().set("html_".concat(name), value);
return this;
}
/**
* Get the value of the tag attribute `name`
* @function HtmlTag#getAttr
* @param {string} name - the name of the attribute
* @returns {*}
*/
}, {
key: "getAttr",
value: function getAttr(name) {
return this.attributes()["html_".concat(name)] || this.attributes()[name];
}
/**
* Remove the tag attributed named `name`
* @function HtmlTag#removeAttr
* @param {string} name - the name of the attribute
* @returns {*}
*/
}, {
key: "removeAttr",
value: function removeAttr(name) {
var ref;
return (ref = this.transformation().remove("html_".concat(name))) != null ? ref : this.transformation().remove(name);
}
/**
* @function HtmlTag#content
* @protected
* @ignore
*/
}, {
key: "content",
value: function content() {
return "";
}
/**
* @function HtmlTag#openTag
* @protected
* @ignore
*/
}, {
key: "openTag",
value: function openTag() {
var tag = "<" + this.name;
var htmlAttrs = this.htmlAttrs(this.attributes());
if (htmlAttrs && htmlAttrs.length > 0) {
tag += " " + htmlAttrs;
}
return tag + ">";
}
/**
* @function HtmlTag#closeTag
* @protected
* @ignore
*/
}, {
key: "closeTag",
value: function closeTag() {
return "".concat(this.name, ">");
}
/**
* Generates an HTML representation of the tag.
* @function HtmlTag#toHtml
* @returns {string} Returns HTML in string format
*/
}, {
key: "toHtml",
value: function toHtml() {
return this.openTag() + this.content() + this.closeTag();
}
/**
* Creates a DOM object representing the tag.
* @function HtmlTag#toDOM
* @returns {Element}
*/
}, {
key: "toDOM",
value: function toDOM() {
var element, name, ref, value;
if (!isFunction(typeof document !== "undefined" && document !== null ? document.createElement : void 0)) {
throw "Can't create DOM if document is not present!";
}
element = document.createElement(this.name);
ref = this.attributes();
for (name in ref) {
value = ref[name];
element.setAttribute(name, value);
}
return element;
}
}], [{
key: "new",
value: function _new(name, publicId, options) {
return new this(name, publicId, options);
}
}, {
key: "isResponsive",
value: function isResponsive(tag, responsiveClass) {
var dataSrc;
dataSrc = getData(tag, 'src-cache') || getData(tag, 'src');
return hasClass(tag, responsiveClass) && /\bw_auto\b/.exec(dataSrc);
}
}]);
return HtmlTag;
}();
;
/**
* Represent the given key and value as an HTML attribute.
* @function toAttribute
* @protected
* @param {string} key - attribute name
* @param {*|boolean} value - the value of the attribute. If the value is boolean `true`, return the key only.
* @returns {string} the attribute
*
*/
function toAttribute(key, value) {
if (!value) {
return void 0;
} else if (value === true) {
return key;
} else {
return "".concat(key, "=\"").concat(value, "\"");
}
}
/**
* If given value is a string, replaces quotes with character entities (", ')
* @param value - value to change
* @returns {*} changed value
*/
function escapeQuotes(value) {
return isString(value) ? value.replace('"', '"').replace("'", ''') : value;
}
/* harmony default export */ var htmltag = (htmltag_HtmlTag);
// CONCATENATED MODULE: ./src/constants.js
var VERSION = "2.5.0";
var CF_SHARED_CDN = "d3jpl91pxevbkh.cloudfront.net";
var OLD_AKAMAI_SHARED_CDN = "cloudinary-a.akamaihd.net";
var AKAMAI_SHARED_CDN = "res.cloudinary.com";
var SHARED_CDN = AKAMAI_SHARED_CDN;
var DEFAULT_POSTER_OPTIONS = {
format: 'jpg',
resource_type: 'video'
};
var DEFAULT_VIDEO_SOURCE_TYPES = ['webm', 'mp4', 'ogv'];
var SEO_TYPES = {
"image/upload": "images",
"image/private": "private_images",
"image/authenticated": "authenticated_images",
"raw/upload": "files",
"video/upload": "videos"
};
/**
* @const {Object} Cloudinary.DEFAULT_IMAGE_PARAMS
* Defaults values for image parameters.
*
* (Previously defined using option_consume() )
*/
var DEFAULT_IMAGE_PARAMS = {
resource_type: "image",
transformation: [],
type: 'upload'
};
/**
* Defaults values for video parameters.
* @const {Object} Cloudinary.DEFAULT_VIDEO_PARAMS
* (Previously defined using option_consume() )
*/
var DEFAULT_VIDEO_PARAMS = {
fallback_content: '',
resource_type: "video",
source_transformation: {},
source_types: DEFAULT_VIDEO_SOURCE_TYPES,
transformation: [],
type: 'upload'
};
/**
* Recommended sources for video tag
* @const {Object} Cloudinary.DEFAULT_VIDEO_SOURCES
*/
var DEFAULT_VIDEO_SOURCES = [{
type: "mp4",
codecs: "hev1",
transformations: {
video_codec: "h265"
}
}, {
type: "webm",
codecs: "vp9",
transformations: {
video_codec: "vp9"
}
}, {
type: "mp4",
transformations: {
video_codec: "auto"
}
}, {
type: "webm",
transformations: {
video_codec: "auto"
}
}];
/**
* The resource storage type
* @typedef type
* @enum {string}
* @property {string} 'upload' A resource uploaded directly to Cloudinary
* @property {string} 'fetch' A resource fetched by Cloudinary from a 3rd party storage
* @property {string} 'private'
* @property {string} 'authenticated'
* @property {string} 'sprite'
* @property {string} 'facebook'
* @property {string} 'twitter'
* @property {string} 'youtube'
* @property {string} 'vimeo'
*
*/
/**
* The resource type
* @typedef resourceType
* @enum {string}
* @property {string} 'image' An image file
* @property {string} 'video' A video file
* @property {string} 'raw' A raw file
*/
// CONCATENATED MODULE: ./src/url.js
/**
* Adds protocol, host, pathname prefixes to given string
* @param str
* @returns {string}
*/
function makeUrl(str) {
var prefix = document.location.protocol + '//' + document.location.host;
if (str[0] === '?') {
prefix += document.location.pathname;
} else if (str[0] !== '/') {
prefix += document.location.pathname.replace(/\/[^\/]*$/, '/');
}
return prefix + str;
}
/**
* Check is given string is a url
* @param str
* @returns {boolean}
*/
function isUrl(str) {
return str ? !!str.match(/^https?:\//) : false;
} // Produce a number between 1 and 5 to be used for cdn sub domains designation
function cdnSubdomainNumber(publicId) {
return src_crc32(publicId) % 5 + 1;
}
/**
* Removes signature from options and returns the signature
* Makes sure signature is empty or of this format: s--signature--
* @param {object} options
* @returns {string} the formatted signature
*/
function handleSignature(options) {
var signature = options.signature;
var isFormatted = !signature || signature.startsWith('s--') && signature.endsWith('--');
delete options.signature;
return isFormatted ? signature : "s--".concat(signature, "--");
}
/**
* Create the URL prefix for Cloudinary resources.
* @param {string} publicId the resource public ID
* @param {object} options additional options
* @param {string} options.cloud_name - the cloud name.
* @param {boolean} [options.cdn_subdomain=false] - Whether to automatically build URLs with
* multiple CDN sub-domains.
* @param {string} [options.private_cdn] - Boolean (default: false). Should be set to true for Advanced plan's users
* that have a private CDN distribution.
* @param {string} [options.protocol="http://"] - the URI protocol to use. If options.secure is true,
* the value is overridden to "https://"
* @param {string} [options.secure_distribution] - The domain name of the CDN distribution to use for building HTTPS URLs.
* Relevant only for Advanced plan's users that have a private CDN distribution.
* @param {string} [options.cname] - Custom domain name to use for building HTTP URLs.
* Relevant only for Advanced plan's users that have a private CDN distribution and a custom CNAME.
* @param {boolean} [options.secure_cdn_subdomain=true] - When options.secure is true and this parameter is false,
* the subdomain is set to "res".
* @param {boolean} [options.secure=false] - Force HTTPS URLs of images even if embedded in non-secure HTTP pages.
* When this value is true, options.secure_distribution will be used as host if provided, and options.protocol is set
* to "https://".
* @returns {string} the URL prefix for the resource.
* @private
*/
function handlePrefix(publicId, options) {
if (options.cloud_name && options.cloud_name[0] === '/') {
return '/res' + options.cloud_name;
} // defaults
var protocol = "http://";
var cdnPart = "";
var subdomain = "res";
var host = ".cloudinary.com";
var path = "/" + options.cloud_name; // modifications
if (options.protocol) {
protocol = options.protocol + '//';
}
if (options.private_cdn) {
cdnPart = options.cloud_name + "-";
path = "";
}
if (options.cdn_subdomain) {
subdomain = "res-" + cdnSubdomainNumber(publicId);
}
if (options.secure) {
protocol = "https://";
if (options.secure_cdn_subdomain === false) {
subdomain = "res";
}
if (options.secure_distribution != null && options.secure_distribution !== OLD_AKAMAI_SHARED_CDN && options.secure_distribution !== SHARED_CDN) {
cdnPart = "";
subdomain = "";
host = options.secure_distribution;
}
} else if (options.cname) {
protocol = "http://";
cdnPart = "";
subdomain = options.cdn_subdomain ? 'a' + (src_crc32(publicId) % 5 + 1) + '.' : '';
host = options.cname;
}
return [protocol, cdnPart, subdomain, host, path].join("");
}
/**
* Return the resource type and action type based on the given configuration
* @function Cloudinary#handleResourceType
* @param {Object|string} resource_type
* @param {string} [type='upload']
* @param {string} [url_suffix]
* @param {boolean} [use_root_path]
* @param {boolean} [shorten]
* @returns {string} resource_type/type
* @ignore
*/
function handleResourceType(_ref) {
var _ref$resource_type = _ref.resource_type,
resource_type = _ref$resource_type === void 0 ? "image" : _ref$resource_type,
_ref$type = _ref.type,
type = _ref$type === void 0 ? "upload" : _ref$type,
url_suffix = _ref.url_suffix,
use_root_path = _ref.use_root_path,
shorten = _ref.shorten;
var options,
resourceType = resource_type;
if (isPlainObject(resourceType)) {
options = resourceType;
resourceType = options.resource_type;
type = options.type;
shorten = options.shorten;
}
if (type == null) {
type = 'upload';
}
if (url_suffix != null) {
resourceType = SEO_TYPES["".concat(resourceType, "/").concat(type)];
type = null;
if (resourceType == null) {
throw new Error("URL Suffix only supported for ".concat(Object.keys(SEO_TYPES).join(', ')));
}
}
if (use_root_path) {
if (resourceType === 'image' && type === 'upload' || resourceType === "images") {
resourceType = null;
type = null;
} else {
throw new Error("Root path only supported for image/upload");
}
}
if (shorten && resourceType === 'image' && type === 'upload') {
resourceType = 'iu';
type = null;
}
return [resourceType, type].join("/");
}
/**
* Encode publicId
* @param publicId
* @returns {string} encoded publicId
*/
function encodePublicId(publicId) {
return encodeURIComponent(publicId).replace(/%3A/g, ':').replace(/%2F/g, '/');
}
/**
* Encode and format publicId
* @param publicId
* @param options
* @returns {string} publicId
*/
function formatPublicId(publicId, options) {
if (isUrl(publicId)) {
publicId = encodePublicId(publicId);
} else {
try {
// Make sure publicId is URI encoded.
publicId = decodeURIComponent(publicId);
} catch (error) {}
publicId = encodePublicId(publicId);
if (options.url_suffix) {
publicId = publicId + '/' + options.url_suffix;
}
if (options.format) {
if (!options.trust_public_id) {
publicId = publicId.replace(/\.(jpg|png|gif|webp)$/, '');
}
publicId = publicId + '.' + options.format;
}
}
return publicId;
}
/**
* Get any error with url options
* @param options
* @returns {string} if error, otherwise return undefined
*/
function validate(options) {
var cloud_name = options.cloud_name,
url_suffix = options.url_suffix;
if (!cloud_name) {
return 'Unknown cloud_name';
}
if (url_suffix && url_suffix.match(/[\.\/]/)) {
return 'url_suffix should not include . or /';
}
}
/**
* Get version part of the url
* @param publicId
* @param options
* @returns {string}
*/
function handleVersion(publicId, options) {
// force_version param means to make sure there is a version in the url (Default is true)
var isForceVersion = options.force_version || typeof options.force_version === 'undefined'; // Is version included in publicId or in options, or publicId is a url (doesn't need version)
var isVersionExist = publicId.indexOf('/') < 0 || publicId.match(/^v[0-9]+/) || isUrl(publicId) || options.version;
if (isForceVersion && !isVersionExist) {
options.version = 1;
}
return options.version ? "v".concat(options.version) : '';
}
/**
* Get final transformation component for url string
* @param options
* @returns {string}
*/
function handleTransformation(options) {
return new src_transformation(options).serialize();
}
/**
* If type is 'fetch', update publicId to be a url
* @param publicId
* @param type
* @returns {string}
*/
function preparePublicId(publicId, _ref2) {
var type = _ref2.type;
return !isUrl(publicId) && type === 'fetch' ? makeUrl(publicId) : publicId;
}
/**
* Generate url string
* @param publicId
* @param options
* @returns {string} final url
*/
function urlString(publicId, options) {
if (isUrl(publicId) && (options.type === 'upload' || options.type === 'asset')) {
return publicId;
}
var version = handleVersion(publicId, options);
var transformationString = handleTransformation(options);
var prefix = handlePrefix(publicId, options);
var signature = handleSignature(options);
var resourceType = handleResourceType(options);
publicId = formatPublicId(publicId, options);
return compact([prefix, resourceType, signature, transformationString, version, publicId]).join('/').replace(/([^:])\/+/g, '$1/');
}
/**
* Merge options and config with defaults
* update options fetch_format according to 'type' param
* @param options
* @param config
* @returns {*} updated options
*/
function prepareOptions(options, config) {
if (options instanceof src_transformation) {
options = options.toOptions();
}
options = defaults({}, options, config, DEFAULT_IMAGE_PARAMS);
if (options.type === 'fetch') {
options.fetch_format = options.fetch_format || options.format;
}
return options;
}
/**
* Generates a URL for any asset in your Media library.
* @function url
* @ignore
* @param {string} publicId - The public ID of the media asset.
* @param {Object} [options={}] - The {@link Transformation} parameters to include in the URL.
* @param {object} [config={}] - URL configuration parameters
* @param {type} [options.type='upload'] - The asset's storage type.
* For details on all fetch types, see
* Fetch types.
* @param {Object} [options.resource_type='image'] - The type of asset. Possible values:
* - `image`
* - `video`
* - `raw`
* @param {signature} [options.signature='s--12345678--'] - The signature component of a
* signed delivery URL of the format: /s--SIGNATURE--/.
* For details on signatures, see
* Signatures.
* @return {string} The media asset URL.
* @see
* Available image transformations
* @see
* Available video transformations
*/
function url_url(publicId) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!publicId) {
return publicId;
}
options = prepareOptions(options, config);
publicId = preparePublicId(publicId, options);
var error = validate(options);
if (error) {
throw error;
}
return urlString(publicId, options);
}
;
// CONCATENATED MODULE: ./src/util/generateBreakpoints.js
function generateBreakpoints_slicedToArray(arr, i) { return generateBreakpoints_arrayWithHoles(arr) || generateBreakpoints_iterableToArrayLimit(arr, i) || generateBreakpoints_nonIterableRest(); }
function generateBreakpoints_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function generateBreakpoints_iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function generateBreakpoints_arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
* Helper function. Gets or populates srcset breakpoints using provided parameters
* Either the breakpoints or min_width, max_width, max_images must be provided.
*
* @private
* @param {srcset} srcset Options with either `breakpoints` or `min_width`, `max_width`, and `max_images`
*
* @return {number[]} Array of breakpoints
*
*/
function generateBreakpoints(srcset) {
var breakpoints = srcset.breakpoints || [];
if (breakpoints.length) {
return breakpoints;
}
var _map = [srcset.min_width, srcset.max_width, srcset.max_images].map(Number),
_map2 = generateBreakpoints_slicedToArray(_map, 3),
min_width = _map2[0],
max_width = _map2[1],
max_images = _map2[2];
if ([min_width, max_width, max_images].some(isNaN)) {
throw 'Either (min_width, max_width, max_images) ' + 'or breakpoints must be provided to the image srcset attribute';
}
if (min_width > max_width) {
throw 'min_width must be less than max_width';
}
if (max_images <= 0) {
throw 'max_images must be a positive integer';
} else if (max_images === 1) {
min_width = max_width;
}
var stepSize = Math.ceil((max_width - min_width) / Math.max(max_images - 1, 1));
for (var current = min_width; current < max_width; current += stepSize) {
breakpoints.push(current);
}
breakpoints.push(max_width);
return breakpoints;
}
// CONCATENATED MODULE: ./src/util/srcsetUtils.js
var srcsetUtils_isEmpty = isEmpty;
/**
* Options used to generate the srcset attribute.
* @typedef {object} srcset
* @property {(number[]|string[])} [breakpoints] An array of breakpoints.
* @property {number} [min_width] Minimal width of the srcset images.
* @property {number} [max_width] Maximal width of the srcset images.
* @property {number} [max_images] Number of srcset images to generate.
* @property {object|string} [transformation] The transformation to use in the srcset urls.
* @property {boolean} [sizes] Whether to calculate and add the sizes attribute.
*/
/**
* Helper function. Generates a single srcset item url
*
* @private
* @param {string} public_id Public ID of the resource.
* @param {number} width Width in pixels of the srcset item.
* @param {object|string} transformation
* @param {object} options Additional options.
*
* @return {string} Resulting URL of the item
*/
function scaledUrl(public_id, width, transformation) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var configParams = extractUrlParams(options);
transformation = transformation || options;
configParams.raw_transformation = new src_transformation([jquery_merge({}, transformation), {
crop: 'scale',
width: width
}]).toString();
return url_url(public_id, configParams);
}
/**
* If cache is enabled, get the breakpoints from the cache. If the values were not found in the cache,
* or cache is not enabled, generate the values.
* @param {srcset} srcset The srcset configuration parameters
* @param {string} public_id
* @param {object} options
* @return {*|Array}
*/
function getOrGenerateBreakpoints(public_id) {
var srcset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return generateBreakpoints(srcset);
}
/**
* Helper function. Generates srcset attribute value of the HTML img tag
* @private
*
* @param {string} public_id Public ID of the resource
* @param {number[]} breakpoints An array of breakpoints (in pixels)
* @param {object} transformation The transformation
* @param {object} options Includes html tag options, transformation options
* @return {string} Resulting srcset attribute value
*/
function generateSrcsetAttribute(public_id, breakpoints, transformation, options) {
options = cloneDeep(options);
patchFetchFormat(options);
return breakpoints.map(function (width) {
return "".concat(scaledUrl(public_id, width, transformation, options), " ").concat(width, "w");
}).join(', ');
}
/**
* Helper function. Generates sizes attribute value of the HTML img tag
* @private
* @param {number[]} breakpoints An array of breakpoints.
* @return {string} Resulting sizes attribute value
*/
function generateSizesAttribute(breakpoints) {
if (breakpoints == null) {
return '';
}
return breakpoints.map(function (width) {
return "(max-width: ".concat(width, "px) ").concat(width, "px");
}).join(', ');
}
/**
* Helper function. Generates srcset and sizes attributes of the image tag
*
* Generated attributes are added to attributes argument
*
* @private
* @param {string} publicId The public ID of the resource
* @param {object} attributes Existing HTML attributes.
* @param {srcset} srcsetData
* @param {object} options Additional options.
*
* @return array The responsive attributes
*/
function generateImageResponsiveAttributes(publicId) {
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var srcsetData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
// Create both srcset and sizes here to avoid fetching breakpoints twice
var responsiveAttributes = {};
if (srcsetUtils_isEmpty(srcsetData)) {
return responsiveAttributes;
}
var generateSizes = !attributes.sizes && srcsetData.sizes === true;
var generateSrcset = !attributes.srcset;
if (generateSrcset || generateSizes) {
var breakpoints = getOrGenerateBreakpoints(publicId, srcsetData, options);
if (generateSrcset) {
var transformation = srcsetData.transformation;
var srcsetAttr = generateSrcsetAttribute(publicId, breakpoints, transformation, options);
if (!srcsetUtils_isEmpty(srcsetAttr)) {
responsiveAttributes.srcset = srcsetAttr;
}
}
if (generateSizes) {
var sizesAttr = generateSizesAttribute(breakpoints);
if (!srcsetUtils_isEmpty(sizesAttr)) {
responsiveAttributes.sizes = sizesAttr;
}
}
}
return responsiveAttributes;
}
/**
* Generate a media query
*
* @private
* @param {object} options configuration options
* @param {number|string} options.min_width
* @param {number|string} options.max_width
* @return {string} a media query string
*/
function generateMediaAttr(options) {
var mediaQuery = [];
if (options != null) {
if (options.min_width != null) {
mediaQuery.push("(min-width: ".concat(options.min_width, "px)"));
}
if (options.max_width != null) {
mediaQuery.push("(max-width: ".concat(options.max_width, "px)"));
}
}
return mediaQuery.join(' and ');
}
var srcsetUrl = scaledUrl;
// CONCATENATED MODULE: ./src/tags/imagetag.js
function imagetag_typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { imagetag_typeof = function _typeof(obj) { return typeof obj; }; } else { imagetag_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return imagetag_typeof(obj); }
function imagetag_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function imagetag_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function imagetag_createClass(Constructor, protoProps, staticProps) { if (protoProps) imagetag_defineProperties(Constructor.prototype, protoProps); if (staticProps) imagetag_defineProperties(Constructor, staticProps); return Constructor; }
function imagetag_possibleConstructorReturn(self, call) { if (call && (imagetag_typeof(call) === "object" || typeof call === "function")) { return call; } return imagetag_assertThisInitialized(self); }
function imagetag_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function imagetag_get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { imagetag_get = Reflect.get; } else { imagetag_get = function _get(target, property, receiver) { var base = imagetag_superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return imagetag_get(target, property, receiver || target); }
function imagetag_superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = imagetag_getPrototypeOf(object); if (object === null) break; } return object; }
function imagetag_getPrototypeOf(o) { imagetag_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return imagetag_getPrototypeOf(o); }
function imagetag_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) imagetag_setPrototypeOf(subClass, superClass); }
function imagetag_setPrototypeOf(o, p) { imagetag_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return imagetag_setPrototypeOf(o, p); }
/**
* Image Tag
* Depends on 'tags/htmltag', 'cloudinary'
*/
/**
* Creates an HTML (DOM) Image tag using Cloudinary as the source.
* @constructor ImageTag
* @extends HtmlTag
* @param {string} [publicId]
* @param {Object} [options]
*/
var imagetag_ImageTag =
/*#__PURE__*/
function (_HtmlTag) {
imagetag_inherits(ImageTag, _HtmlTag);
function ImageTag(publicId) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
imagetag_classCallCheck(this, ImageTag);
return imagetag_possibleConstructorReturn(this, imagetag_getPrototypeOf(ImageTag).call(this, "img", publicId, options));
}
/** @override */
imagetag_createClass(ImageTag, [{
key: "closeTag",
value: function closeTag() {
return "";
}
/** @override */
}, {
key: "attributes",
value: function attributes() {
var attr, options, srcAttribute;
attr = imagetag_get(imagetag_getPrototypeOf(ImageTag.prototype), "attributes", this).call(this) || {};
options = this.getOptions();
var srcsetParam = this.getOption('srcset');
var attributes = this.getOption('attributes') || {};
var responsiveAttributes = {};
if (isString(srcsetParam)) {
responsiveAttributes.srcset = srcsetParam;
} else {
responsiveAttributes = generateImageResponsiveAttributes(this.publicId, attributes, srcsetParam, options);
}
if (!isEmpty(responsiveAttributes)) {
delete options.width;
delete options.height;
}
jquery_merge(attr, responsiveAttributes);
srcAttribute = options.responsive && !options.client_hints ? 'data-src' : 'src';
if (attr[srcAttribute] == null) {
attr[srcAttribute] = url_url(this.publicId, this.getOptions());
}
return attr;
}
}]);
return ImageTag;
}(htmltag);
;
/* harmony default export */ var imagetag = (imagetag_ImageTag);
// CONCATENATED MODULE: ./src/tags/sourcetag.js
function sourcetag_typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { sourcetag_typeof = function _typeof(obj) { return typeof obj; }; } else { sourcetag_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return sourcetag_typeof(obj); }
function sourcetag_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function sourcetag_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function sourcetag_createClass(Constructor, protoProps, staticProps) { if (protoProps) sourcetag_defineProperties(Constructor.prototype, protoProps); if (staticProps) sourcetag_defineProperties(Constructor, staticProps); return Constructor; }
function sourcetag_possibleConstructorReturn(self, call) { if (call && (sourcetag_typeof(call) === "object" || typeof call === "function")) { return call; } return sourcetag_assertThisInitialized(self); }
function sourcetag_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function sourcetag_get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { sourcetag_get = Reflect.get; } else { sourcetag_get = function _get(target, property, receiver) { var base = sourcetag_superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return sourcetag_get(target, property, receiver || target); }
function sourcetag_superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = sourcetag_getPrototypeOf(object); if (object === null) break; } return object; }
function sourcetag_getPrototypeOf(o) { sourcetag_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return sourcetag_getPrototypeOf(o); }
function sourcetag_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) sourcetag_setPrototypeOf(subClass, superClass); }
function sourcetag_setPrototypeOf(o, p) { sourcetag_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return sourcetag_setPrototypeOf(o, p); }
/**
* Image Tag
* Depends on 'tags/htmltag', 'cloudinary'
*/
/**
* Creates an HTML (DOM) Image tag using Cloudinary as the source.
* @constructor SourceTag
* @extends HtmlTag
* @param {string} [publicId]
* @param {Object} [options]
*/
var sourcetag_SourceTag =
/*#__PURE__*/
function (_HtmlTag) {
sourcetag_inherits(SourceTag, _HtmlTag);
function SourceTag(publicId) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
sourcetag_classCallCheck(this, SourceTag);
return sourcetag_possibleConstructorReturn(this, sourcetag_getPrototypeOf(SourceTag).call(this, "source", publicId, options));
}
/** @override */
sourcetag_createClass(SourceTag, [{
key: "closeTag",
value: function closeTag() {
return "";
}
/** @override */
}, {
key: "attributes",
value: function attributes() {
var srcsetParam = this.getOption('srcset');
var attr = sourcetag_get(sourcetag_getPrototypeOf(SourceTag.prototype), "attributes", this).call(this) || {};
var options = this.getOptions();
jquery_merge(attr, generateImageResponsiveAttributes(this.publicId, attr, srcsetParam, options));
if (!attr.srcset) {
attr.srcset = url_url(this.publicId, options);
}
if (!attr.media && options.media) {
attr.media = generateMediaAttr(options.media);
}
return attr;
}
}]);
return SourceTag;
}(htmltag);
;
/* harmony default export */ var sourcetag = (sourcetag_SourceTag);
// CONCATENATED MODULE: ./src/tags/picturetag.js
function picturetag_typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { picturetag_typeof = function _typeof(obj) { return typeof obj; }; } else { picturetag_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return picturetag_typeof(obj); }
function picturetag_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function picturetag_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function picturetag_createClass(Constructor, protoProps, staticProps) { if (protoProps) picturetag_defineProperties(Constructor.prototype, protoProps); if (staticProps) picturetag_defineProperties(Constructor, staticProps); return Constructor; }
function picturetag_possibleConstructorReturn(self, call) { if (call && (picturetag_typeof(call) === "object" || typeof call === "function")) { return call; } return picturetag_assertThisInitialized(self); }
function picturetag_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function picturetag_get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { picturetag_get = Reflect.get; } else { picturetag_get = function _get(target, property, receiver) { var base = picturetag_superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return picturetag_get(target, property, receiver || target); }
function picturetag_superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = picturetag_getPrototypeOf(object); if (object === null) break; } return object; }
function picturetag_getPrototypeOf(o) { picturetag_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return picturetag_getPrototypeOf(o); }
function picturetag_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) picturetag_setPrototypeOf(subClass, superClass); }
function picturetag_setPrototypeOf(o, p) { picturetag_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return picturetag_setPrototypeOf(o, p); }
var picturetag_PictureTag =
/*#__PURE__*/
function (_HtmlTag) {
picturetag_inherits(PictureTag, _HtmlTag);
function PictureTag(publicId) {
var _this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var sources = arguments.length > 2 ? arguments[2] : undefined;
picturetag_classCallCheck(this, PictureTag);
_this = picturetag_possibleConstructorReturn(this, picturetag_getPrototypeOf(PictureTag).call(this, 'picture', publicId, options));
_this.widthList = sources;
return _this;
}
/** @override */
picturetag_createClass(PictureTag, [{
key: "content",
value: function content() {
var _this2 = this;
return this.widthList.map(function (_ref) {
var min_width = _ref.min_width,
max_width = _ref.max_width,
transformation = _ref.transformation;
var options = _this2.getOptions();
var sourceTransformation = new src_transformation(options);
sourceTransformation.chain().fromOptions(typeof transformation === 'string' ? {
raw_transformation: transformation
} : transformation);
options = extractUrlParams(options);
options.media = {
min_width: min_width,
max_width: max_width
};
options.transformation = sourceTransformation;
return new sourcetag(_this2.publicId, options).toHtml();
}).join('') + new imagetag(this.publicId, this.getOptions()).toHtml();
}
/** @override */
}, {
key: "attributes",
value: function attributes() {
var attr = picturetag_get(picturetag_getPrototypeOf(PictureTag.prototype), "attributes", this).call(this);
delete attr.width;
delete attr.height;
return attr;
}
/** @override */
}, {
key: "closeTag",
value: function closeTag() {
return "" + this.name + ">";
}
}]);
return PictureTag;
}(htmltag);
;
/* harmony default export */ var picturetag = (picturetag_PictureTag);
// CONCATENATED MODULE: ./src/tags/videotag.js
function videotag_typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { videotag_typeof = function _typeof(obj) { return typeof obj; }; } else { videotag_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return videotag_typeof(obj); }
function videotag_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function videotag_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function videotag_createClass(Constructor, protoProps, staticProps) { if (protoProps) videotag_defineProperties(Constructor.prototype, protoProps); if (staticProps) videotag_defineProperties(Constructor, staticProps); return Constructor; }
function videotag_possibleConstructorReturn(self, call) { if (call && (videotag_typeof(call) === "object" || typeof call === "function")) { return call; } return videotag_assertThisInitialized(self); }
function videotag_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function videotag_get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { videotag_get = Reflect.get; } else { videotag_get = function _get(target, property, receiver) { var base = videotag_superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return videotag_get(target, property, receiver || target); }
function videotag_superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = videotag_getPrototypeOf(object); if (object === null) break; } return object; }
function videotag_getPrototypeOf(o) { videotag_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return videotag_getPrototypeOf(o); }
function videotag_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) videotag_setPrototypeOf(subClass, superClass); }
function videotag_setPrototypeOf(o, p) { videotag_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return videotag_setPrototypeOf(o, p); }
/**
* Video Tag
* Depends on 'tags/htmltag', 'util', 'cloudinary'
*/
var VIDEO_TAG_PARAMS = ['source_types', 'source_transformation', 'fallback_content', 'poster', 'sources'];
var videotag_DEFAULT_VIDEO_SOURCE_TYPES = ['webm', 'mp4', 'ogv'];
var videotag_DEFAULT_POSTER_OPTIONS = {
format: 'jpg',
resource_type: 'video'
};
/**
* Creates an HTML (DOM) Video tag using Cloudinary as the source.
* @constructor VideoTag
* @extends HtmlTag
* @param {string} [publicId]
* @param {Object} [options]
*/
var videotag_VideoTag =
/*#__PURE__*/
function (_HtmlTag) {
videotag_inherits(VideoTag, _HtmlTag);
function VideoTag(publicId) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
videotag_classCallCheck(this, VideoTag);
options = defaults({}, options, DEFAULT_VIDEO_PARAMS);
return videotag_possibleConstructorReturn(this, videotag_getPrototypeOf(VideoTag).call(this, "video", publicId.replace(/\.(mp4|ogv|webm)$/, ''), options));
}
/**
* Set the transformation to apply on each source
* @function VideoTag#setSourceTransformation
* @param {Object} an object with pairs of source type and source transformation
* @returns {VideoTag} Returns this instance for chaining purposes.
*/
videotag_createClass(VideoTag, [{
key: "setSourceTransformation",
value: function setSourceTransformation(value) {
this.transformation().sourceTransformation(value);
return this;
}
/**
* Set the source types to include in the video tag
* @function VideoTag#setSourceTypes
* @param {Array} an array of source types
* @returns {VideoTag} Returns this instance for chaining purposes.
*/
}, {
key: "setSourceTypes",
value: function setSourceTypes(value) {
this.transformation().sourceTypes(value);
return this;
}
/**
* Set the poster to be used in the video tag
* @function VideoTag#setPoster
* @param {string|Object} value
* - string: a URL to use for the poster
* - Object: transformation parameters to apply to the poster. May optionally include a public_id to use instead of the video public_id.
* @returns {VideoTag} Returns this instance for chaining purposes.
*/
}, {
key: "setPoster",
value: function setPoster(value) {
this.transformation().poster(value);
return this;
}
/**
* Set the content to use as fallback in the video tag
* @function VideoTag#setFallbackContent
* @param {string} value - the content to use, in HTML format
* @returns {VideoTag} Returns this instance for chaining purposes.
*/
}, {
key: "setFallbackContent",
value: function setFallbackContent(value) {
this.transformation().fallbackContent(value);
return this;
}
}, {
key: "content",
value: function content() {
var _this = this;
var sourceTypes = this.transformation().getValue('source_types');
var sourceTransformation = this.transformation().getValue('source_transformation');
var fallback = this.transformation().getValue('fallback_content');
var sources = this.getOption('sources');
var innerTags = [];
if (isArray(sources) && !isEmpty(sources)) {
innerTags = sources.map(function (source) {
var src = url_url(_this.publicId, defaults({}, source.transformations || {}, {
resource_type: 'video',
format: source.type
}), _this.getOptions());
return _this.createSourceTag(src, source.type, source.codecs);
});
} else {
if (isEmpty(sourceTypes)) {
sourceTypes = videotag_DEFAULT_VIDEO_SOURCE_TYPES;
}
if (isArray(sourceTypes)) {
innerTags = sourceTypes.map(function (srcType) {
var src = url_url(_this.publicId, defaults({}, sourceTransformation[srcType] || {}, {
resource_type: 'video',
format: srcType
}), _this.getOptions());
return _this.createSourceTag(src, srcType);
});
}
}
return innerTags.join('') + fallback;
}
}, {
key: "attributes",
value: function attributes() {
var sourceTypes = this.getOption('source_types');
var poster = this.getOption('poster');
if (poster === undefined) {
poster = {};
}
if (isPlainObject(poster)) {
var defaultOptions = poster.public_id != null ? DEFAULT_IMAGE_PARAMS : videotag_DEFAULT_POSTER_OPTIONS;
poster = url_url(poster.public_id || this.publicId, defaults({}, poster, defaultOptions, this.getOptions()));
}
var attr = videotag_get(videotag_getPrototypeOf(VideoTag.prototype), "attributes", this).call(this) || {};
attr = omit(attr, VIDEO_TAG_PARAMS);
var sources = this.getOption('sources'); // In case of empty sourceTypes - fallback to default source types is used.
var hasSourceTags = !isEmpty(sources) || isEmpty(sourceTypes) || isArray(sourceTypes);
if (!hasSourceTags) {
attr["src"] = url_url(this.publicId, this.getOptions(), {
resource_type: 'video',
format: sourceTypes
});
}
if (poster != null) {
attr["poster"] = poster;
}
return attr;
}
}, {
key: "createSourceTag",
value: function createSourceTag(src, sourceType) {
var codecs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var mimeType = null;
if (!isEmpty(sourceType)) {
var videoType = sourceType === 'ogv' ? 'ogg' : sourceType;
mimeType = 'video/' + videoType;
if (!isEmpty(codecs)) {
var codecsStr = isArray(codecs) ? codecs.join(', ') : codecs;
mimeType += '; codecs=' + codecsStr;
}
}
return "