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