next-cloudinary 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/next-cloudinary.js +249 -130
- package/dist/next-cloudinary.js.map +1 -1
- package/dist/next-cloudinary.modern.mjs +236 -120
- package/dist/next-cloudinary.modern.mjs.map +1 -1
- package/dist/next-cloudinary.module.js +248 -131
- package/dist/next-cloudinary.module.js.map +1 -1
- package/dist/next-cloudinary.umd.js +252 -134
- package/dist/next-cloudinary.umd.js.map +1 -1
- package/package.json +1 -1
- package/tests/lib/cloudinary.spec.js +110 -9
- package/tests/loaders/cloudinary-loader.spec.js +7 -7
- package/tests/plugins/cropping.spec.js +27 -0
- package/tests/plugins/overlays.spec.js +112 -0
- package/tests/plugins/raw-transformations.spec.js +6 -6
- package/tests/plugins/underlays.spec.js +62 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('next/image'), require('@cloudinary/url-gen'), require('react/jsx-runtime'), require('react'), require('next/script')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'next/image', '@cloudinary/url-gen', 'react/jsx-runtime', 'react', 'next/script'], factory) :
|
|
4
|
-
(global = global || self, factory(global.nextCloudinary = {}, global.Image, global.urlGen, global.jsxRuntime, global.react, global.Script));
|
|
5
|
-
})(this, (function (exports, Image, urlGen, jsxRuntime, react, Script) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('next/image'), require('@cloudinary/url-gen'), require('react/jsx-runtime'), require('next/head'), require('react'), require('next/script')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'next/image', '@cloudinary/url-gen', 'react/jsx-runtime', 'next/head', 'react', 'next/script'], factory) :
|
|
4
|
+
(global = global || self, factory(global.nextCloudinary = {}, global.Image, global.urlGen, global.jsxRuntime, global.Head, global.react, global.Script));
|
|
5
|
+
})(this, (function (exports, Image, urlGen, jsxRuntime, Head, react, Script) {
|
|
6
6
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
7
7
|
|
|
8
8
|
var Image__default = /*#__PURE__*/_interopDefaultLegacy(Image);
|
|
9
|
+
var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
|
|
9
10
|
var Script__default = /*#__PURE__*/_interopDefaultLegacy(Script);
|
|
10
11
|
|
|
11
12
|
function _extends() {
|
|
@@ -40,96 +41,32 @@
|
|
|
40
41
|
return target;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
function _readOnlyError(name) {
|
|
44
|
-
throw new TypeError("\"" + name + "\" is read-only");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
var cld$1 = new urlGen.Cloudinary({
|
|
48
|
-
cloud: {
|
|
49
|
-
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
50
|
-
},
|
|
51
|
-
url: {
|
|
52
|
-
// Used to avoid issues with SSR particularly for the blurred placeholder
|
|
53
|
-
analytics: false
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
|
|
58
|
-
* If it's recognized that is a url and it's not possible to get the public id, it warns the user.
|
|
59
|
-
*
|
|
60
|
-
* @param {string} src The cloudiary url or public id.
|
|
61
|
-
*
|
|
62
|
-
* @return {string} The images public id
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
function getPublicId(src) {
|
|
66
|
-
if (src.includes('res.cloudinary.com')) {
|
|
67
|
-
var regexWithTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
68
|
-
var regexWithoutTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
69
|
-
var withTransformations = src.match(regexWithTransformations);
|
|
70
|
-
var withoutTransformations = src.match(regexWithoutTransformations);
|
|
71
|
-
|
|
72
|
-
if (withTransformations) {
|
|
73
|
-
return withTransformations[withTransformations.length - 1];
|
|
74
|
-
} else if (withoutTransformations) {
|
|
75
|
-
return withoutTransformations[withoutTransformations.length - 1];
|
|
76
|
-
} else {
|
|
77
|
-
console.warn("Not possible to retrieve the publicUrl from " + src + ", make sure it's a valid cloudinary image url.");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return src;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* createPlaceholderUrl
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
function createPlaceholderUrl(_ref) {
|
|
88
|
-
var src = _ref.src,
|
|
89
|
-
placeholder = _ref.placeholder;
|
|
90
|
-
var cldImage = cld$1.image(src).resize('c_limit,w_100').delivery('q_1').format('auto');
|
|
91
|
-
|
|
92
|
-
if (placeholder === 'grayscale') {
|
|
93
|
-
cldImage.effect('e_grayscale');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (placeholder.includes('color:')) {
|
|
97
|
-
var color = placeholder.split(':').splice(1).join(':');
|
|
98
|
-
cldImage.effect('e_grayscale');
|
|
99
|
-
cldImage.effect("e_colorize:60,co_" + color);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return cldImage.toURL();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
44
|
var cropsGravityAuto = ['crop', 'fill', 'lfill', 'fill_pad', 'thumb'];
|
|
106
45
|
var props$6 = ['crop', 'gravity'];
|
|
107
46
|
function plugin$6(_temp) {
|
|
108
47
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
109
48
|
cldImage = _ref.cldImage,
|
|
110
|
-
options = _ref.options
|
|
111
|
-
cldOptions = _ref.cldOptions;
|
|
49
|
+
options = _ref.options;
|
|
112
50
|
|
|
113
51
|
var width = options.width,
|
|
114
|
-
height = options.height
|
|
115
|
-
|
|
116
|
-
crop =
|
|
117
|
-
gravity = cldOptions.gravity;
|
|
52
|
+
height = options.height,
|
|
53
|
+
_options$crop = options.crop,
|
|
54
|
+
crop = _options$crop === void 0 ? 'limit' : _options$crop;
|
|
118
55
|
var transformationString = "c_" + crop + ",w_" + width;
|
|
119
56
|
|
|
120
|
-
if (!gravity && cropsGravityAuto.includes(crop)) {
|
|
121
|
-
|
|
57
|
+
if (!options.gravity && cropsGravityAuto.includes(crop)) {
|
|
58
|
+
options.gravity = 'auto';
|
|
122
59
|
}
|
|
123
60
|
|
|
124
61
|
if (!['limit'].includes(crop)) {
|
|
125
62
|
transformationString = transformationString + ",h_" + height;
|
|
126
63
|
}
|
|
127
64
|
|
|
128
|
-
if (gravity) {
|
|
129
|
-
if (gravity === 'auto' && !cropsGravityAuto.includes(crop)) {
|
|
65
|
+
if (options.gravity) {
|
|
66
|
+
if (options.gravity === 'auto' && !cropsGravityAuto.includes(crop)) {
|
|
130
67
|
console.warn('Auto gravity can only be used with crop, fill, lfill, fill_pad or thumb. Not applying gravity.');
|
|
131
68
|
} else {
|
|
132
|
-
transformationString = transformationString + ",g_" + gravity;
|
|
69
|
+
transformationString = transformationString + ",g_" + options.gravity;
|
|
133
70
|
}
|
|
134
71
|
}
|
|
135
72
|
|
|
@@ -194,20 +131,16 @@
|
|
|
194
131
|
function plugin$5(_temp) {
|
|
195
132
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
196
133
|
cldImage = _ref.cldImage,
|
|
197
|
-
|
|
134
|
+
options = _ref.options;
|
|
198
135
|
|
|
199
136
|
params.forEach(function (key) {
|
|
200
137
|
var prop = key.prop || key;
|
|
201
138
|
var effect = key.effect || key;
|
|
202
139
|
|
|
203
|
-
if (prop ===
|
|
204
|
-
console.log('cldOptions[prop]', cldOptions[prop]);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (cldOptions[prop] === true) {
|
|
140
|
+
if (options[prop] === true) {
|
|
208
141
|
cldImage.effect("e_" + effect);
|
|
209
|
-
} else if (typeof
|
|
210
|
-
cldImage.effect("e_" + effect + ":" +
|
|
142
|
+
} else if (typeof options[prop] === 'string') {
|
|
143
|
+
cldImage.effect("e_" + effect + ":" + options[prop]);
|
|
211
144
|
}
|
|
212
145
|
});
|
|
213
146
|
}
|
|
@@ -272,27 +205,55 @@
|
|
|
272
205
|
}
|
|
273
206
|
};
|
|
274
207
|
|
|
275
|
-
var _excluded$
|
|
276
|
-
var props$4 = ['overlays'];
|
|
208
|
+
var _excluded$3 = ["publicId", "position", "text", "effects"];
|
|
209
|
+
var props$4 = ['text', 'overlays'];
|
|
210
|
+
var DEFAULT_TEXT_OPTIONS = {
|
|
211
|
+
color: 'black',
|
|
212
|
+
fontFamily: 'Arial',
|
|
213
|
+
fontSize: 200,
|
|
214
|
+
fontWeight: 'bold'
|
|
215
|
+
};
|
|
277
216
|
function plugin$4(_temp) {
|
|
278
217
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
279
218
|
cldImage = _ref.cldImage,
|
|
280
|
-
|
|
219
|
+
options = _ref.options;
|
|
281
220
|
|
|
282
|
-
var
|
|
283
|
-
overlays =
|
|
221
|
+
var text$1 = options.text,
|
|
222
|
+
_options$overlays = options.overlays,
|
|
223
|
+
overlays = _options$overlays === void 0 ? [] : _options$overlays;
|
|
284
224
|
var type = 'overlay';
|
|
285
225
|
var typeQualifier = 'l';
|
|
286
|
-
|
|
226
|
+
|
|
227
|
+
if (Array.isArray(overlays)) {
|
|
228
|
+
overlays.forEach(applyOverlay);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (typeof text$1 === 'string') {
|
|
232
|
+
applyOverlay({
|
|
233
|
+
text: _extends({}, DEFAULT_TEXT_OPTIONS, {
|
|
234
|
+
text: text$1
|
|
235
|
+
})
|
|
236
|
+
});
|
|
237
|
+
} else if (typeof text$1 === 'object') {
|
|
238
|
+
applyOverlay({
|
|
239
|
+
text: _extends({}, DEFAULT_TEXT_OPTIONS, text$1)
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* applyOverlay
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
function applyOverlay(_ref2) {
|
|
287
248
|
var publicId = _ref2.publicId,
|
|
288
249
|
position$1 = _ref2.position,
|
|
289
250
|
text$1 = _ref2.text,
|
|
290
251
|
_ref2$effects = _ref2.effects,
|
|
291
252
|
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
292
|
-
options = _objectWithoutPropertiesLoose(_ref2, _excluded$
|
|
253
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
293
254
|
|
|
294
255
|
var hasPublicId = typeof publicId === 'string';
|
|
295
|
-
var hasText = typeof text$1 === 'object';
|
|
256
|
+
var hasText = typeof text$1 === 'object' || typeof text$1 === 'string';
|
|
296
257
|
var hasPosition = typeof position$1 === 'object';
|
|
297
258
|
|
|
298
259
|
if (!hasPublicId && !hasText) {
|
|
@@ -330,6 +291,12 @@
|
|
|
330
291
|
}); // Text styling
|
|
331
292
|
|
|
332
293
|
if (hasText) {
|
|
294
|
+
if (typeof text$1 === 'string') {
|
|
295
|
+
text$1 = _extends({}, DEFAULT_TEXT_OPTIONS, {
|
|
296
|
+
text: text$1
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
333
300
|
var textTransformations = [];
|
|
334
301
|
Object.keys(text$1).forEach(function (key) {
|
|
335
302
|
if (!text[key]) return;
|
|
@@ -358,7 +325,7 @@
|
|
|
358
325
|
|
|
359
326
|
layerTransformation = layerTransformation + "," + primary$1.join(','); // Add all applied transformations
|
|
360
327
|
|
|
361
|
-
layerTransformation = layerTransformation + "/fl_layer_apply";
|
|
328
|
+
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
362
329
|
|
|
363
330
|
if (applied.length > 0) {
|
|
364
331
|
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
@@ -366,12 +333,13 @@
|
|
|
366
333
|
|
|
367
334
|
|
|
368
335
|
cldImage.addTransformation(layerTransformation);
|
|
369
|
-
}
|
|
336
|
+
}
|
|
370
337
|
}
|
|
371
338
|
|
|
372
339
|
var overlaysPlugin = {
|
|
373
340
|
__proto__: null,
|
|
374
341
|
props: props$4,
|
|
342
|
+
DEFAULT_TEXT_OPTIONS: DEFAULT_TEXT_OPTIONS,
|
|
375
343
|
plugin: plugin$4
|
|
376
344
|
};
|
|
377
345
|
|
|
@@ -379,10 +347,10 @@
|
|
|
379
347
|
function plugin$3(_temp) {
|
|
380
348
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
381
349
|
cldImage = _ref.cldImage,
|
|
382
|
-
|
|
350
|
+
options = _ref.options;
|
|
383
351
|
|
|
384
|
-
var
|
|
385
|
-
rawTransformations =
|
|
352
|
+
var _options$rawTransform = options.rawTransformations,
|
|
353
|
+
rawTransformations = _options$rawTransform === void 0 ? [] : _options$rawTransform;
|
|
386
354
|
rawTransformations.forEach(function (transformation) {
|
|
387
355
|
cldImage.addTransformation(transformation);
|
|
388
356
|
});
|
|
@@ -398,10 +366,10 @@
|
|
|
398
366
|
function plugin$2(_temp) {
|
|
399
367
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
400
368
|
cldImage = _ref.cldImage,
|
|
401
|
-
|
|
369
|
+
options = _ref.options;
|
|
402
370
|
|
|
403
|
-
var
|
|
404
|
-
removeBackground =
|
|
371
|
+
var _options$removeBackgr = options.removeBackground,
|
|
372
|
+
removeBackground = _options$removeBackgr === void 0 ? false : _options$removeBackgr;
|
|
405
373
|
|
|
406
374
|
if (removeBackground) {
|
|
407
375
|
cldImage.effect('e_background_removal');
|
|
@@ -414,23 +382,50 @@
|
|
|
414
382
|
plugin: plugin$2
|
|
415
383
|
};
|
|
416
384
|
|
|
417
|
-
var _excluded$
|
|
418
|
-
var props$1 = ['underlays'];
|
|
385
|
+
var _excluded$2 = ["publicId", "type", "position", "text", "effects"];
|
|
386
|
+
var props$1 = ['underlay', 'underlays'];
|
|
419
387
|
function plugin$1(_temp) {
|
|
420
388
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
421
389
|
cldImage = _ref.cldImage,
|
|
422
|
-
|
|
390
|
+
options = _ref.options;
|
|
423
391
|
|
|
424
|
-
var
|
|
425
|
-
underlays =
|
|
392
|
+
var underlay = options.underlay,
|
|
393
|
+
_options$underlays = options.underlays,
|
|
394
|
+
underlays = _options$underlays === void 0 ? [] : _options$underlays;
|
|
426
395
|
var typeQualifier = 'u';
|
|
427
|
-
|
|
396
|
+
|
|
397
|
+
if (Array.isArray(underlays)) {
|
|
398
|
+
underlays.forEach(applyUnderlay);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (typeof underlay === 'string') {
|
|
402
|
+
var underlayOptions = {
|
|
403
|
+
publicId: underlay,
|
|
404
|
+
crop: 'fill'
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
if (options.width) {
|
|
408
|
+
underlayOptions.width = options.width;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (options.height) {
|
|
412
|
+
underlayOptions.height = options.height;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
applyUnderlay(underlayOptions);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* applyUnderlay
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
function applyUnderlay(_ref2) {
|
|
428
423
|
var publicId = _ref2.publicId,
|
|
429
424
|
type = _ref2.type,
|
|
430
425
|
position$1 = _ref2.position,
|
|
431
426
|
_ref2$effects = _ref2.effects,
|
|
432
427
|
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
433
|
-
options = _objectWithoutPropertiesLoose(_ref2, _excluded$
|
|
428
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
|
|
434
429
|
|
|
435
430
|
var hasPublicId = typeof publicId === 'string';
|
|
436
431
|
var hasPosition = typeof position$1 === 'object';
|
|
@@ -473,7 +468,7 @@
|
|
|
473
468
|
|
|
474
469
|
layerTransformation = layerTransformation + "," + primary$1.join(','); // Add all applied transformations
|
|
475
470
|
|
|
476
|
-
layerTransformation = layerTransformation + "/fl_layer_apply";
|
|
471
|
+
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
477
472
|
|
|
478
473
|
if (applied.length > 0) {
|
|
479
474
|
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
@@ -481,7 +476,7 @@
|
|
|
481
476
|
|
|
482
477
|
|
|
483
478
|
cldImage.addTransformation(layerTransformation);
|
|
484
|
-
}
|
|
479
|
+
}
|
|
485
480
|
}
|
|
486
481
|
|
|
487
482
|
var underlaysPlugin = {
|
|
@@ -494,11 +489,11 @@
|
|
|
494
489
|
function plugin(_temp) {
|
|
495
490
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
496
491
|
cldImage = _ref.cldImage,
|
|
497
|
-
|
|
492
|
+
options = _ref.options;
|
|
498
493
|
|
|
499
|
-
var
|
|
500
|
-
zoompan =
|
|
501
|
-
var
|
|
494
|
+
var _options$zoompan = options.zoompan,
|
|
495
|
+
zoompan = _options$zoompan === void 0 ? false : _options$zoompan;
|
|
496
|
+
var overrides = {};
|
|
502
497
|
|
|
503
498
|
if (zoompan === true) {
|
|
504
499
|
cldImage.effect('e_zoompan');
|
|
@@ -531,11 +526,11 @@
|
|
|
531
526
|
}
|
|
532
527
|
|
|
533
528
|
if (zoompan !== false) {
|
|
534
|
-
|
|
529
|
+
overrides.format = 'gif';
|
|
535
530
|
}
|
|
536
531
|
|
|
537
532
|
return {
|
|
538
|
-
options:
|
|
533
|
+
options: overrides
|
|
539
534
|
};
|
|
540
535
|
}
|
|
541
536
|
|
|
@@ -545,15 +540,18 @@
|
|
|
545
540
|
plugin: plugin
|
|
546
541
|
};
|
|
547
542
|
|
|
548
|
-
var cld;
|
|
549
543
|
var transformationPlugins = [// Background Removal must always come first
|
|
550
544
|
removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, underlaysPlugin, zoompanPlugin, // Raw transformations needs to be last simply to make sure
|
|
551
545
|
// it's always expected to applied the same way
|
|
552
546
|
rawTransformationsPlugin];
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
547
|
+
var cld;
|
|
548
|
+
/**
|
|
549
|
+
* constructCloudinaryUrl
|
|
550
|
+
*/
|
|
551
|
+
|
|
552
|
+
function constructCloudinaryUrl(_ref) {
|
|
553
|
+
var options = _ref.options,
|
|
554
|
+
config = _ref.config;
|
|
557
555
|
|
|
558
556
|
if (!cld) {
|
|
559
557
|
cld = new urlGen.Cloudinary(_extends({
|
|
@@ -564,31 +562,98 @@
|
|
|
564
562
|
// Used to avoid issues with SSR particularly for the blurred placeholder
|
|
565
563
|
analytics: false
|
|
566
564
|
}
|
|
567
|
-
},
|
|
565
|
+
}, config));
|
|
568
566
|
}
|
|
569
567
|
|
|
570
|
-
var options = _extends({
|
|
571
|
-
format: 'auto',
|
|
572
|
-
quality: 'auto'
|
|
573
|
-
}, defaultOptions);
|
|
574
|
-
|
|
575
568
|
var publicId = getPublicId(options.src);
|
|
576
569
|
var cldImage = cld.image(publicId);
|
|
577
|
-
transformationPlugins.forEach(function (
|
|
578
|
-
var plugin =
|
|
570
|
+
transformationPlugins.forEach(function (_ref2) {
|
|
571
|
+
var plugin = _ref2.plugin;
|
|
579
572
|
|
|
580
|
-
var
|
|
573
|
+
var _ref3 = plugin({
|
|
581
574
|
cldImage: cldImage,
|
|
582
|
-
options: options
|
|
583
|
-
cldOptions: cldOptions
|
|
575
|
+
options: options
|
|
584
576
|
}) || {},
|
|
585
|
-
pluginOptions =
|
|
577
|
+
pluginOptions = _ref3.options;
|
|
586
578
|
|
|
587
579
|
if (pluginOptions != null && pluginOptions.format) {
|
|
588
580
|
options.format = pluginOptions.format;
|
|
589
581
|
}
|
|
590
582
|
});
|
|
591
|
-
return cldImage.format(options.format).delivery("q_" + options.quality).toURL();
|
|
583
|
+
return cldImage.setDeliveryType(options.deliveryType || 'upload').format(options.format || 'auto').delivery("q_" + (options.quality || 'auto')).toURL();
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
|
|
587
|
+
* If it's recognized that is a url and it's not possible to get the public id, it warns the user.
|
|
588
|
+
*
|
|
589
|
+
* @param {string} src The cloudiary url or public id.
|
|
590
|
+
*
|
|
591
|
+
* @return {string} The images public id
|
|
592
|
+
*/
|
|
593
|
+
|
|
594
|
+
function getPublicId(src) {
|
|
595
|
+
if (typeof src !== 'string') {
|
|
596
|
+
throw new Error("Invalid src of type " + typeof src);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (src.includes('res.cloudinary.com')) {
|
|
600
|
+
var regexWithTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
601
|
+
var regexWithoutTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
602
|
+
var withTransformations = src.match(regexWithTransformations);
|
|
603
|
+
var withoutTransformations = src.match(regexWithoutTransformations);
|
|
604
|
+
|
|
605
|
+
if (withTransformations) {
|
|
606
|
+
return withTransformations[withTransformations.length - 1];
|
|
607
|
+
} else if (withoutTransformations) {
|
|
608
|
+
return withoutTransformations[withoutTransformations.length - 1];
|
|
609
|
+
} else {
|
|
610
|
+
console.warn("Not possible to retrieve the publicUrl from " + src + ", make sure it's a valid cloudinary image url.");
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
return src;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* createPlaceholderUrl
|
|
618
|
+
*/
|
|
619
|
+
|
|
620
|
+
function createPlaceholderUrl(_ref4) {
|
|
621
|
+
var src = _ref4.src,
|
|
622
|
+
_ref4$placeholder = _ref4.placeholder,
|
|
623
|
+
placeholder = _ref4$placeholder === void 0 ? true : _ref4$placeholder,
|
|
624
|
+
config = _ref4.config;
|
|
625
|
+
var rawTransformations = [];
|
|
626
|
+
|
|
627
|
+
if (placeholder === 'grayscale') {
|
|
628
|
+
rawTransformations.push('e_grayscale');
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
if (typeof placeholder === 'string' && placeholder.includes('color:')) {
|
|
632
|
+
var color = placeholder.split(':').splice(1).join(':');
|
|
633
|
+
rawTransformations.push('e_grayscale');
|
|
634
|
+
rawTransformations.push("e_colorize:60,co_" + color);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
return constructCloudinaryUrl({
|
|
638
|
+
options: {
|
|
639
|
+
src: src,
|
|
640
|
+
width: 100,
|
|
641
|
+
quality: 1,
|
|
642
|
+
rawTransformations: rawTransformations
|
|
643
|
+
},
|
|
644
|
+
config: config
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function cloudinaryLoader(defaultOptions, cldOptions, cldConfig) {
|
|
649
|
+
if (cldConfig === void 0) {
|
|
650
|
+
cldConfig = {};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return constructCloudinaryUrl({
|
|
654
|
+
options: _extends({}, defaultOptions, cldOptions),
|
|
655
|
+
config: cldConfig
|
|
656
|
+
});
|
|
592
657
|
}
|
|
593
658
|
|
|
594
659
|
var CldImage = function CldImage(props) {
|
|
@@ -647,6 +712,58 @@
|
|
|
647
712
|
}));
|
|
648
713
|
};
|
|
649
714
|
|
|
715
|
+
var _excluded$1 = ["excludeTags", "twitterTitle"];
|
|
716
|
+
var IMAGE_WIDTH = 2400;
|
|
717
|
+
var IMAGE_HEIGHT = 1200;
|
|
718
|
+
var TWITTER_CARD = 'summary_large_image';
|
|
719
|
+
|
|
720
|
+
var CldOgImage = function CldOgImage(_ref) {
|
|
721
|
+
var _ref$excludeTags = _ref.excludeTags,
|
|
722
|
+
excludeTags = _ref$excludeTags === void 0 ? [] : _ref$excludeTags,
|
|
723
|
+
twitterTitle = _ref.twitterTitle,
|
|
724
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
725
|
+
|
|
726
|
+
var options = _extends({}, props, {
|
|
727
|
+
width: props.width || IMAGE_WIDTH,
|
|
728
|
+
height: props.height || IMAGE_HEIGHT,
|
|
729
|
+
crop: props.crop || 'fill',
|
|
730
|
+
gravity: props.gravity || 'center'
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
var ogImageUrl = constructCloudinaryUrl({
|
|
734
|
+
options: options
|
|
735
|
+
}); // We need to include the tags within the Next.js Head component rather than
|
|
736
|
+
// direcly adding them inside of the Head otherwise we get unexpected results
|
|
737
|
+
|
|
738
|
+
return /*#__PURE__*/jsxRuntime.jsxs(Head__default["default"], {
|
|
739
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
740
|
+
property: "og:image",
|
|
741
|
+
content: ogImageUrl
|
|
742
|
+
}), /*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
743
|
+
property: "og:image:secure_url",
|
|
744
|
+
content: ogImageUrl
|
|
745
|
+
}), /*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
746
|
+
property: "og:image:width",
|
|
747
|
+
content: options.width
|
|
748
|
+
}), /*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
749
|
+
property: "og:image:height",
|
|
750
|
+
content: options.height
|
|
751
|
+
}), options.alt && /*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
752
|
+
property: "og:image:alt",
|
|
753
|
+
content: options.alt
|
|
754
|
+
}), !excludeTags.includes('twitter:title') && /*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
755
|
+
property: "twitter:title",
|
|
756
|
+
content: twitterTitle || ' '
|
|
757
|
+
}), /*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
758
|
+
property: "twitter:card",
|
|
759
|
+
content: TWITTER_CARD
|
|
760
|
+
}), /*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
761
|
+
property: "twitter:image",
|
|
762
|
+
content: ogImageUrl
|
|
763
|
+
})]
|
|
764
|
+
});
|
|
765
|
+
};
|
|
766
|
+
|
|
650
767
|
var CldUploadWidget = function CldUploadWidget(_ref) {
|
|
651
768
|
var children = _ref.children,
|
|
652
769
|
onUpload = _ref.onUpload,
|
|
@@ -778,6 +895,7 @@
|
|
|
778
895
|
};
|
|
779
896
|
|
|
780
897
|
exports.CldImage = CldImage;
|
|
898
|
+
exports.CldOgImage = CldOgImage;
|
|
781
899
|
exports.CldUploadButton = CldUploadButton;
|
|
782
900
|
exports.CldUploadWidget = CldUploadWidget;
|
|
783
901
|
exports.cloudinaryLoader = cloudinaryLoader;
|