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