1 | "use strict";
|
2 |
|
3 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
4 |
|
5 | var _ = require('lodash');
|
6 | exports.config = require("./config");
|
7 | exports.utils = require("./utils");
|
8 | exports.uploader = require("./uploader");
|
9 | exports.api = require("./api");
|
10 | var account = require("./provisioning/account");
|
11 |
|
12 | exports.provisioning = {
|
13 | account: account
|
14 | };
|
15 | exports.PreloadedFile = require("./preloaded_file");
|
16 | exports.Cache = require('./cache');
|
17 |
|
18 | var cloudinary = module.exports;
|
19 |
|
20 | var optionConsume = cloudinary.utils.option_consume;
|
21 |
|
22 | exports.url = function url(public_id, options) {
|
23 | options = _.extend({}, options);
|
24 | return cloudinary.utils.url(public_id, options);
|
25 | };
|
26 |
|
27 | var _require = require('./utils/srcsetUtils'),
|
28 | generateImageResponsiveAttributes = _require.generateImageResponsiveAttributes,
|
29 | generateMediaAttr = _require.generateMediaAttr;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function chainTransformations(options) {
|
43 | var transformation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
44 |
|
45 |
|
46 | var urlOptions = cloudinary.utils.extractUrlParams(options);
|
47 | var currentTransformation = cloudinary.utils.extractTransformationParams(options);
|
48 | transformation = cloudinary.utils.build_array(transformation);
|
49 | urlOptions.transformation = [currentTransformation].concat(_toConsumableArray(transformation));
|
50 | return urlOptions;
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | exports.image = function image(source, options) {
|
70 | var localOptions = _.extend({}, options);
|
71 | var srcsetParam = optionConsume(localOptions, 'srcset');
|
72 | var attributes = optionConsume(localOptions, 'attributes', {});
|
73 | var src = cloudinary.utils.url(source, localOptions);
|
74 | if ("html_width" in localOptions) localOptions.width = optionConsume(localOptions, "html_width");
|
75 | if ("html_height" in localOptions) localOptions.height = optionConsume(localOptions, "html_height");
|
76 |
|
77 | var client_hints = optionConsume(localOptions, "client_hints", cloudinary.config().client_hints);
|
78 | var responsive = optionConsume(localOptions, "responsive");
|
79 | var hidpi = optionConsume(localOptions, "hidpi");
|
80 |
|
81 | if ((responsive || hidpi) && !client_hints) {
|
82 | localOptions["data-src"] = src;
|
83 | var classes = [responsive ? "cld-responsive" : "cld-hidpi"];
|
84 | var current_class = optionConsume(localOptions, "class");
|
85 | if (current_class) classes.push(current_class);
|
86 | localOptions.class = classes.join(" ");
|
87 | src = optionConsume(localOptions, "responsive_placeholder", cloudinary.config().responsive_placeholder);
|
88 | if (src === "blank") {
|
89 | src = cloudinary.BLANK;
|
90 | }
|
91 | }
|
92 | var html = "<img ";
|
93 | if (src) html += "src='" + src + "' ";
|
94 | var responsiveAttributes = {};
|
95 | if (cloudinary.utils.isString(srcsetParam)) {
|
96 | responsiveAttributes.srcset = srcsetParam;
|
97 | } else {
|
98 | responsiveAttributes = generateImageResponsiveAttributes(source, attributes, srcsetParam, options);
|
99 | }
|
100 | if (!cloudinary.utils.isEmpty(responsiveAttributes)) {
|
101 | delete localOptions.width;
|
102 | delete localOptions.height;
|
103 | }
|
104 | html += cloudinary.utils.html_attrs(_.extend(localOptions, responsiveAttributes, attributes)) + "/>";
|
105 | return html;
|
106 | };
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | exports.video = function video(public_id, options) {
|
127 | options = _.extend({}, options);
|
128 | public_id = public_id.replace(/\.(mp4|ogv|webm)$/, '');
|
129 | var source_types = optionConsume(options, 'source_types', []);
|
130 | var source_transformation = optionConsume(options, 'source_transformation', {});
|
131 | var sources = optionConsume(options, 'sources', []);
|
132 | var fallback = optionConsume(options, 'fallback_content', '');
|
133 |
|
134 | if (source_types.length === 0) source_types = cloudinary.utils.DEFAULT_VIDEO_SOURCE_TYPES;
|
135 | var video_options = _.cloneDeep(options);
|
136 |
|
137 | if (video_options.hasOwnProperty('poster')) {
|
138 | if (_.isPlainObject(video_options.poster)) {
|
139 | if (video_options.poster.hasOwnProperty('public_id')) {
|
140 | video_options.poster = cloudinary.utils.url(video_options.poster.public_id, video_options.poster);
|
141 | } else {
|
142 | video_options.poster = cloudinary.utils.url(public_id, _.extend({}, cloudinary.utils.DEFAULT_POSTER_OPTIONS, video_options.poster));
|
143 | }
|
144 | }
|
145 | } else {
|
146 | video_options.poster = cloudinary.utils.url(public_id, _.extend({}, cloudinary.utils.DEFAULT_POSTER_OPTIONS, options));
|
147 | }
|
148 |
|
149 | if (!video_options.poster) delete video_options.poster;
|
150 |
|
151 | var html = '<video ';
|
152 |
|
153 | if (!video_options.hasOwnProperty('resource_type')) video_options.resource_type = 'video';
|
154 | var multi_source_types = _.isArray(source_types) && source_types.length > 1;
|
155 | var has_sources = _.isArray(sources) && sources.length > 0;
|
156 | var source = public_id;
|
157 | if (!multi_source_types && !has_sources) {
|
158 | source = source + '.' + cloudinary.utils.build_array(source_types)[0];
|
159 | }
|
160 | var src = cloudinary.utils.url(source, video_options);
|
161 | if (!multi_source_types && !has_sources) video_options.src = src;
|
162 | if (video_options.hasOwnProperty("html_width")) video_options.width = optionConsume(video_options, 'html_width');
|
163 | if (video_options.hasOwnProperty("html_height")) video_options.height = optionConsume(video_options, 'html_height');
|
164 | html = html + cloudinary.utils.html_attrs(video_options) + '>';
|
165 | if (multi_source_types && !has_sources) {
|
166 | sources = source_types.map(function (source_type) {
|
167 | return {
|
168 | type: source_type,
|
169 | transformations: source_transformation[source_type] || {}
|
170 | };
|
171 | });
|
172 | }
|
173 | if (_.isArray(sources) && sources.length > 0) {
|
174 | html += sources.map(function (source_data) {
|
175 | var source_type = source_data.type;
|
176 | var codecs = source_data.codecs;
|
177 | var transformation = source_data.transformations || {};
|
178 | src = cloudinary.utils.url(source + "." + source_type, _.extend({ resource_type: 'video' }, _.cloneDeep(options), _.cloneDeep(transformation)));
|
179 | return cloudinary.utils.create_source_tag(src, source_type, codecs);
|
180 | }).join('');
|
181 | }
|
182 | return `${html}${fallback}</video>`;
|
183 | };
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | exports.source = function source(public_id) {
|
194 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
195 |
|
196 | var srcsetParam = cloudinary.utils.extend({}, options.srcset, cloudinary.config().srcset);
|
197 | var attributes = options.attributes || {};
|
198 |
|
199 | cloudinary.utils.extend(attributes, generateImageResponsiveAttributes(public_id, attributes, srcsetParam, options));
|
200 | if (!attributes.srcset) {
|
201 | attributes.srcset = cloudinary.url(public_id, options);
|
202 | }
|
203 | if (!attributes.media && options.media) {
|
204 | attributes.media = generateMediaAttr(options.media);
|
205 | }
|
206 | return `<source ${cloudinary.utils.html_attrs(attributes)}>`;
|
207 | };
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | exports.picture = function picture(public_id) {
|
231 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
232 |
|
233 | var sources = options.sources || [];
|
234 | options = cloudinary.utils.clone(options);
|
235 | delete options.sources;
|
236 | cloudinary.utils.patchFetchFormat(options);
|
237 | return "<picture>" + sources.map(function (source) {
|
238 | var sourceOptions = chainTransformations(options, source.transformation);
|
239 | sourceOptions.media = source;
|
240 | return cloudinary.source(public_id, sourceOptions);
|
241 | }).join('') + cloudinary.image(public_id, options) + "</picture>";
|
242 | };
|
243 |
|
244 | exports.cloudinary_js_config = cloudinary.utils.cloudinary_js_config;
|
245 | exports.CF_SHARED_CDN = cloudinary.utils.CF_SHARED_CDN;
|
246 | exports.AKAMAI_SHARED_CDN = cloudinary.utils.AKAMAI_SHARED_CDN;
|
247 | exports.SHARED_CDN = cloudinary.utils.SHARED_CDN;
|
248 | exports.BLANK = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
249 | exports.v2 = require('./v2'); |
\ | No newline at end of file |