next-cloudinary 0.1.1 → 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 +23 -3
- package/dist/next-cloudinary.js +384 -130
- package/dist/next-cloudinary.js.map +1 -1
- package/dist/next-cloudinary.modern.mjs +371 -121
- package/dist/next-cloudinary.modern.mjs.map +1 -1
- package/dist/next-cloudinary.module.js +381 -132
- package/dist/next-cloudinary.module.js.map +1 -1
- package/dist/next-cloudinary.umd.js +385 -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 +23 -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,13 @@
|
|
|
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')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'next/image', '@cloudinary/url-gen', 'react/jsx-runtime'], factory) :
|
|
4
|
-
(global = global || self, factory(global.nextCloudinary = {}, global.Image, global.urlGen, global.jsxRuntime));
|
|
5
|
-
})(this, (function (exports, Image, urlGen, jsxRuntime) {
|
|
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);
|
|
10
|
+
var Script__default = /*#__PURE__*/_interopDefaultLegacy(Script);
|
|
9
11
|
|
|
10
12
|
function _extends() {
|
|
11
13
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -39,96 +41,32 @@
|
|
|
39
41
|
return target;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
function _readOnlyError(name) {
|
|
43
|
-
throw new TypeError("\"" + name + "\" is read-only");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var cld$1 = new urlGen.Cloudinary({
|
|
47
|
-
cloud: {
|
|
48
|
-
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
49
|
-
},
|
|
50
|
-
url: {
|
|
51
|
-
// Used to avoid issues with SSR particularly for the blurred placeholder
|
|
52
|
-
analytics: false
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
|
|
57
|
-
* If it's recognized that is a url and it's not possible to get the public id, it warns the user.
|
|
58
|
-
*
|
|
59
|
-
* @param {string} src The cloudiary url or public id.
|
|
60
|
-
*
|
|
61
|
-
* @return {string} The images public id
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
function getPublicId(src) {
|
|
65
|
-
if (src.includes('res.cloudinary.com')) {
|
|
66
|
-
var regexWithTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
67
|
-
var regexWithoutTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
68
|
-
var withTransformations = src.match(regexWithTransformations);
|
|
69
|
-
var withoutTransformations = src.match(regexWithoutTransformations);
|
|
70
|
-
|
|
71
|
-
if (withTransformations) {
|
|
72
|
-
return withTransformations[withTransformations.length - 1];
|
|
73
|
-
} else if (withoutTransformations) {
|
|
74
|
-
return withoutTransformations[withoutTransformations.length - 1];
|
|
75
|
-
} else {
|
|
76
|
-
console.warn("Not possible to retrieve the publicUrl from " + src + ", make sure it's a valid cloudinary image url.");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return src;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* createPlaceholderUrl
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
function createPlaceholderUrl(_ref) {
|
|
87
|
-
var src = _ref.src,
|
|
88
|
-
placeholder = _ref.placeholder;
|
|
89
|
-
var cldImage = cld$1.image(src).resize('c_limit,w_100').delivery('q_1').format('auto');
|
|
90
|
-
|
|
91
|
-
if (placeholder === 'grayscale') {
|
|
92
|
-
cldImage.effect('e_grayscale');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (placeholder.includes('color:')) {
|
|
96
|
-
var color = placeholder.split(':').splice(1).join(':');
|
|
97
|
-
cldImage.effect('e_grayscale');
|
|
98
|
-
cldImage.effect("e_colorize:60,co_" + color);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return cldImage.toURL();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
44
|
var cropsGravityAuto = ['crop', 'fill', 'lfill', 'fill_pad', 'thumb'];
|
|
105
45
|
var props$6 = ['crop', 'gravity'];
|
|
106
46
|
function plugin$6(_temp) {
|
|
107
47
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
108
48
|
cldImage = _ref.cldImage,
|
|
109
|
-
options = _ref.options
|
|
110
|
-
cldOptions = _ref.cldOptions;
|
|
49
|
+
options = _ref.options;
|
|
111
50
|
|
|
112
51
|
var width = options.width,
|
|
113
|
-
height = options.height
|
|
114
|
-
|
|
115
|
-
crop =
|
|
116
|
-
gravity = cldOptions.gravity;
|
|
52
|
+
height = options.height,
|
|
53
|
+
_options$crop = options.crop,
|
|
54
|
+
crop = _options$crop === void 0 ? 'limit' : _options$crop;
|
|
117
55
|
var transformationString = "c_" + crop + ",w_" + width;
|
|
118
56
|
|
|
119
|
-
if (!gravity && cropsGravityAuto.includes(crop)) {
|
|
120
|
-
|
|
57
|
+
if (!options.gravity && cropsGravityAuto.includes(crop)) {
|
|
58
|
+
options.gravity = 'auto';
|
|
121
59
|
}
|
|
122
60
|
|
|
123
61
|
if (!['limit'].includes(crop)) {
|
|
124
62
|
transformationString = transformationString + ",h_" + height;
|
|
125
63
|
}
|
|
126
64
|
|
|
127
|
-
if (gravity) {
|
|
128
|
-
if (gravity === 'auto' && !cropsGravityAuto.includes(crop)) {
|
|
65
|
+
if (options.gravity) {
|
|
66
|
+
if (options.gravity === 'auto' && !cropsGravityAuto.includes(crop)) {
|
|
129
67
|
console.warn('Auto gravity can only be used with crop, fill, lfill, fill_pad or thumb. Not applying gravity.');
|
|
130
68
|
} else {
|
|
131
|
-
transformationString = transformationString + ",g_" + gravity;
|
|
69
|
+
transformationString = transformationString + ",g_" + options.gravity;
|
|
132
70
|
}
|
|
133
71
|
}
|
|
134
72
|
|
|
@@ -193,20 +131,16 @@
|
|
|
193
131
|
function plugin$5(_temp) {
|
|
194
132
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
195
133
|
cldImage = _ref.cldImage,
|
|
196
|
-
|
|
134
|
+
options = _ref.options;
|
|
197
135
|
|
|
198
136
|
params.forEach(function (key) {
|
|
199
137
|
var prop = key.prop || key;
|
|
200
138
|
var effect = key.effect || key;
|
|
201
139
|
|
|
202
|
-
if (prop ===
|
|
203
|
-
console.log('cldOptions[prop]', cldOptions[prop]);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (cldOptions[prop] === true) {
|
|
140
|
+
if (options[prop] === true) {
|
|
207
141
|
cldImage.effect("e_" + effect);
|
|
208
|
-
} else if (typeof
|
|
209
|
-
cldImage.effect("e_" + effect + ":" +
|
|
142
|
+
} else if (typeof options[prop] === 'string') {
|
|
143
|
+
cldImage.effect("e_" + effect + ":" + options[prop]);
|
|
210
144
|
}
|
|
211
145
|
});
|
|
212
146
|
}
|
|
@@ -271,27 +205,55 @@
|
|
|
271
205
|
}
|
|
272
206
|
};
|
|
273
207
|
|
|
274
|
-
var _excluded$
|
|
275
|
-
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
|
+
};
|
|
276
216
|
function plugin$4(_temp) {
|
|
277
217
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
278
218
|
cldImage = _ref.cldImage,
|
|
279
|
-
|
|
219
|
+
options = _ref.options;
|
|
280
220
|
|
|
281
|
-
var
|
|
282
|
-
overlays =
|
|
221
|
+
var text$1 = options.text,
|
|
222
|
+
_options$overlays = options.overlays,
|
|
223
|
+
overlays = _options$overlays === void 0 ? [] : _options$overlays;
|
|
283
224
|
var type = 'overlay';
|
|
284
225
|
var typeQualifier = 'l';
|
|
285
|
-
|
|
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) {
|
|
286
248
|
var publicId = _ref2.publicId,
|
|
287
249
|
position$1 = _ref2.position,
|
|
288
250
|
text$1 = _ref2.text,
|
|
289
251
|
_ref2$effects = _ref2.effects,
|
|
290
252
|
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
291
|
-
options = _objectWithoutPropertiesLoose(_ref2, _excluded$
|
|
253
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
292
254
|
|
|
293
255
|
var hasPublicId = typeof publicId === 'string';
|
|
294
|
-
var hasText = typeof text$1 === 'object';
|
|
256
|
+
var hasText = typeof text$1 === 'object' || typeof text$1 === 'string';
|
|
295
257
|
var hasPosition = typeof position$1 === 'object';
|
|
296
258
|
|
|
297
259
|
if (!hasPublicId && !hasText) {
|
|
@@ -329,6 +291,12 @@
|
|
|
329
291
|
}); // Text styling
|
|
330
292
|
|
|
331
293
|
if (hasText) {
|
|
294
|
+
if (typeof text$1 === 'string') {
|
|
295
|
+
text$1 = _extends({}, DEFAULT_TEXT_OPTIONS, {
|
|
296
|
+
text: text$1
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
332
300
|
var textTransformations = [];
|
|
333
301
|
Object.keys(text$1).forEach(function (key) {
|
|
334
302
|
if (!text[key]) return;
|
|
@@ -357,7 +325,7 @@
|
|
|
357
325
|
|
|
358
326
|
layerTransformation = layerTransformation + "," + primary$1.join(','); // Add all applied transformations
|
|
359
327
|
|
|
360
|
-
layerTransformation = layerTransformation + "/fl_layer_apply";
|
|
328
|
+
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
361
329
|
|
|
362
330
|
if (applied.length > 0) {
|
|
363
331
|
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
@@ -365,12 +333,13 @@
|
|
|
365
333
|
|
|
366
334
|
|
|
367
335
|
cldImage.addTransformation(layerTransformation);
|
|
368
|
-
}
|
|
336
|
+
}
|
|
369
337
|
}
|
|
370
338
|
|
|
371
339
|
var overlaysPlugin = {
|
|
372
340
|
__proto__: null,
|
|
373
341
|
props: props$4,
|
|
342
|
+
DEFAULT_TEXT_OPTIONS: DEFAULT_TEXT_OPTIONS,
|
|
374
343
|
plugin: plugin$4
|
|
375
344
|
};
|
|
376
345
|
|
|
@@ -378,10 +347,10 @@
|
|
|
378
347
|
function plugin$3(_temp) {
|
|
379
348
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
380
349
|
cldImage = _ref.cldImage,
|
|
381
|
-
|
|
350
|
+
options = _ref.options;
|
|
382
351
|
|
|
383
|
-
var
|
|
384
|
-
rawTransformations =
|
|
352
|
+
var _options$rawTransform = options.rawTransformations,
|
|
353
|
+
rawTransformations = _options$rawTransform === void 0 ? [] : _options$rawTransform;
|
|
385
354
|
rawTransformations.forEach(function (transformation) {
|
|
386
355
|
cldImage.addTransformation(transformation);
|
|
387
356
|
});
|
|
@@ -397,10 +366,10 @@
|
|
|
397
366
|
function plugin$2(_temp) {
|
|
398
367
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
399
368
|
cldImage = _ref.cldImage,
|
|
400
|
-
|
|
369
|
+
options = _ref.options;
|
|
401
370
|
|
|
402
|
-
var
|
|
403
|
-
removeBackground =
|
|
371
|
+
var _options$removeBackgr = options.removeBackground,
|
|
372
|
+
removeBackground = _options$removeBackgr === void 0 ? false : _options$removeBackgr;
|
|
404
373
|
|
|
405
374
|
if (removeBackground) {
|
|
406
375
|
cldImage.effect('e_background_removal');
|
|
@@ -413,23 +382,50 @@
|
|
|
413
382
|
plugin: plugin$2
|
|
414
383
|
};
|
|
415
384
|
|
|
416
|
-
var _excluded = ["publicId", "type", "position", "text", "effects"];
|
|
417
|
-
var props$1 = ['underlays'];
|
|
385
|
+
var _excluded$2 = ["publicId", "type", "position", "text", "effects"];
|
|
386
|
+
var props$1 = ['underlay', 'underlays'];
|
|
418
387
|
function plugin$1(_temp) {
|
|
419
388
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
420
389
|
cldImage = _ref.cldImage,
|
|
421
|
-
|
|
390
|
+
options = _ref.options;
|
|
422
391
|
|
|
423
|
-
var
|
|
424
|
-
underlays =
|
|
392
|
+
var underlay = options.underlay,
|
|
393
|
+
_options$underlays = options.underlays,
|
|
394
|
+
underlays = _options$underlays === void 0 ? [] : _options$underlays;
|
|
425
395
|
var typeQualifier = 'u';
|
|
426
|
-
|
|
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) {
|
|
427
423
|
var publicId = _ref2.publicId,
|
|
428
424
|
type = _ref2.type,
|
|
429
425
|
position$1 = _ref2.position,
|
|
430
426
|
_ref2$effects = _ref2.effects,
|
|
431
427
|
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
432
|
-
options = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
428
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
|
|
433
429
|
|
|
434
430
|
var hasPublicId = typeof publicId === 'string';
|
|
435
431
|
var hasPosition = typeof position$1 === 'object';
|
|
@@ -472,7 +468,7 @@
|
|
|
472
468
|
|
|
473
469
|
layerTransformation = layerTransformation + "," + primary$1.join(','); // Add all applied transformations
|
|
474
470
|
|
|
475
|
-
layerTransformation = layerTransformation + "/fl_layer_apply";
|
|
471
|
+
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
476
472
|
|
|
477
473
|
if (applied.length > 0) {
|
|
478
474
|
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
@@ -480,7 +476,7 @@
|
|
|
480
476
|
|
|
481
477
|
|
|
482
478
|
cldImage.addTransformation(layerTransformation);
|
|
483
|
-
}
|
|
479
|
+
}
|
|
484
480
|
}
|
|
485
481
|
|
|
486
482
|
var underlaysPlugin = {
|
|
@@ -493,11 +489,11 @@
|
|
|
493
489
|
function plugin(_temp) {
|
|
494
490
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
495
491
|
cldImage = _ref.cldImage,
|
|
496
|
-
|
|
492
|
+
options = _ref.options;
|
|
497
493
|
|
|
498
|
-
var
|
|
499
|
-
zoompan =
|
|
500
|
-
var
|
|
494
|
+
var _options$zoompan = options.zoompan,
|
|
495
|
+
zoompan = _options$zoompan === void 0 ? false : _options$zoompan;
|
|
496
|
+
var overrides = {};
|
|
501
497
|
|
|
502
498
|
if (zoompan === true) {
|
|
503
499
|
cldImage.effect('e_zoompan');
|
|
@@ -530,11 +526,11 @@
|
|
|
530
526
|
}
|
|
531
527
|
|
|
532
528
|
if (zoompan !== false) {
|
|
533
|
-
|
|
529
|
+
overrides.format = 'gif';
|
|
534
530
|
}
|
|
535
531
|
|
|
536
532
|
return {
|
|
537
|
-
options:
|
|
533
|
+
options: overrides
|
|
538
534
|
};
|
|
539
535
|
}
|
|
540
536
|
|
|
@@ -544,15 +540,18 @@
|
|
|
544
540
|
plugin: plugin
|
|
545
541
|
};
|
|
546
542
|
|
|
547
|
-
var cld;
|
|
548
543
|
var transformationPlugins = [// Background Removal must always come first
|
|
549
544
|
removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, underlaysPlugin, zoompanPlugin, // Raw transformations needs to be last simply to make sure
|
|
550
545
|
// it's always expected to applied the same way
|
|
551
546
|
rawTransformationsPlugin];
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
547
|
+
var cld;
|
|
548
|
+
/**
|
|
549
|
+
* constructCloudinaryUrl
|
|
550
|
+
*/
|
|
551
|
+
|
|
552
|
+
function constructCloudinaryUrl(_ref) {
|
|
553
|
+
var options = _ref.options,
|
|
554
|
+
config = _ref.config;
|
|
556
555
|
|
|
557
556
|
if (!cld) {
|
|
558
557
|
cld = new urlGen.Cloudinary(_extends({
|
|
@@ -563,31 +562,98 @@
|
|
|
563
562
|
// Used to avoid issues with SSR particularly for the blurred placeholder
|
|
564
563
|
analytics: false
|
|
565
564
|
}
|
|
566
|
-
},
|
|
565
|
+
}, config));
|
|
567
566
|
}
|
|
568
567
|
|
|
569
|
-
var options = _extends({
|
|
570
|
-
format: 'auto',
|
|
571
|
-
quality: 'auto'
|
|
572
|
-
}, defaultOptions);
|
|
573
|
-
|
|
574
568
|
var publicId = getPublicId(options.src);
|
|
575
569
|
var cldImage = cld.image(publicId);
|
|
576
|
-
transformationPlugins.forEach(function (
|
|
577
|
-
var plugin =
|
|
570
|
+
transformationPlugins.forEach(function (_ref2) {
|
|
571
|
+
var plugin = _ref2.plugin;
|
|
578
572
|
|
|
579
|
-
var
|
|
573
|
+
var _ref3 = plugin({
|
|
580
574
|
cldImage: cldImage,
|
|
581
|
-
options: options
|
|
582
|
-
cldOptions: cldOptions
|
|
575
|
+
options: options
|
|
583
576
|
}) || {},
|
|
584
|
-
pluginOptions =
|
|
577
|
+
pluginOptions = _ref3.options;
|
|
585
578
|
|
|
586
579
|
if (pluginOptions != null && pluginOptions.format) {
|
|
587
580
|
options.format = pluginOptions.format;
|
|
588
581
|
}
|
|
589
582
|
});
|
|
590
|
-
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
|
+
});
|
|
591
657
|
}
|
|
592
658
|
|
|
593
659
|
var CldImage = function CldImage(props) {
|
|
@@ -646,7 +712,192 @@
|
|
|
646
712
|
}));
|
|
647
713
|
};
|
|
648
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
|
+
|
|
767
|
+
var CldUploadWidget = function CldUploadWidget(_ref) {
|
|
768
|
+
var children = _ref.children,
|
|
769
|
+
onUpload = _ref.onUpload,
|
|
770
|
+
options = _ref.options,
|
|
771
|
+
signed = _ref.signed,
|
|
772
|
+
signatureEndpoint = _ref.signatureEndpoint;
|
|
773
|
+
var cloudinary = react.useRef();
|
|
774
|
+
var widget = react.useRef();
|
|
775
|
+
/**
|
|
776
|
+
* generateSignature
|
|
777
|
+
* @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
|
|
778
|
+
*/
|
|
779
|
+
|
|
780
|
+
function generateSignature(callback, paramsToSign) {
|
|
781
|
+
fetch(signatureEndpoint, {
|
|
782
|
+
method: "POST",
|
|
783
|
+
body: JSON.stringify({
|
|
784
|
+
paramsToSign: paramsToSign
|
|
785
|
+
})
|
|
786
|
+
}).then(function (r) {
|
|
787
|
+
return r.json();
|
|
788
|
+
}).then(function (_ref2) {
|
|
789
|
+
var signature = _ref2.signature;
|
|
790
|
+
callback(signature);
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* createWidget
|
|
795
|
+
* @description Creates a new instance of the Cloudinary widget and stores in a ref
|
|
796
|
+
*/
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
function createWidget() {
|
|
800
|
+
var _cloudinary$current;
|
|
801
|
+
|
|
802
|
+
// When creating a signed upload, you need to provide both your Cloudinary API Key
|
|
803
|
+
// as well as a signature generator function that will sign any paramters
|
|
804
|
+
// either on page load or during the upload process. Read more about signed uploads at:
|
|
805
|
+
// https://cloudinary.com/documentation/upload_widget#signed_uploads
|
|
806
|
+
var totalOptions = _extends({}, options, !!signed && {
|
|
807
|
+
uploadSignature: generateSignature
|
|
808
|
+
}); // no need for apiSecret because of api/sign-cloudinary-params
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
if (signed && !totalOptions.apiKey) {
|
|
812
|
+
return new Error("Signed Upload needs apiKey!");
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
return (_cloudinary$current = cloudinary.current) == null ? void 0 : _cloudinary$current.createUploadWidget(totalOptions, function (error, result) {
|
|
816
|
+
// The callback is a bit more chatty than failed or success so
|
|
817
|
+
// only trigger when one of those are the case. You can additionally
|
|
818
|
+
// create a separate handler such as onEvent and trigger it on
|
|
819
|
+
// ever occurance
|
|
820
|
+
if (error || result.event === "success") {
|
|
821
|
+
onUpload(error, result, widget == null ? void 0 : widget.current);
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* open
|
|
827
|
+
* @description When triggered, uses the current widget instance to open the upload modal
|
|
828
|
+
*/
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
function open() {
|
|
832
|
+
if (!(widget != null && widget.current)) {
|
|
833
|
+
widget.current = createWidget();
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
(widget == null ? void 0 : widget.current) && widget.current.open();
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* handleOnLoad
|
|
840
|
+
* @description Stores the Cloudinary window instance to a ref when the widget script loads
|
|
841
|
+
*/
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
function handleOnLoad() {
|
|
845
|
+
cloudinary.current = window.cloudinary;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
849
|
+
children: [children({
|
|
850
|
+
cloudinary: cloudinary.current,
|
|
851
|
+
widget: widget.current,
|
|
852
|
+
open: open
|
|
853
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Script__default["default"], {
|
|
854
|
+
id: "cloudinary-" + Math.floor(Math.random() * 100),
|
|
855
|
+
src: "https://widget.cloudinary.com/v2.0/global/all.js",
|
|
856
|
+
onLoad: handleOnLoad,
|
|
857
|
+
onError: function onError(e) {
|
|
858
|
+
console.error("Script failed to load", e);
|
|
859
|
+
}
|
|
860
|
+
})]
|
|
861
|
+
});
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
var _excluded = ["onUpload", "options", "signed", "label", "children"];
|
|
865
|
+
|
|
866
|
+
var CldUploadButton = function CldUploadButton(_ref) {
|
|
867
|
+
var onUpload = _ref.onUpload,
|
|
868
|
+
options = _ref.options,
|
|
869
|
+
signed = _ref.signed,
|
|
870
|
+
_children = _ref.children,
|
|
871
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
872
|
+
|
|
873
|
+
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
874
|
+
children: /*#__PURE__*/jsxRuntime.jsx(CldUploadWidget, {
|
|
875
|
+
signed: signed,
|
|
876
|
+
options: options,
|
|
877
|
+
onUpload: onUpload,
|
|
878
|
+
signatureEndpoint: signed != null ? signed : props.signatureEndpoint,
|
|
879
|
+
children: function children(_ref2) {
|
|
880
|
+
var open = _ref2.open;
|
|
881
|
+
|
|
882
|
+
function handleOnClick(e) {
|
|
883
|
+
e.preventDefault();
|
|
884
|
+
open();
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
return /*#__PURE__*/jsxRuntime.jsx("button", _extends({
|
|
888
|
+
onClick: handleOnClick
|
|
889
|
+
}, props, {
|
|
890
|
+
children: _children
|
|
891
|
+
}));
|
|
892
|
+
}
|
|
893
|
+
})
|
|
894
|
+
});
|
|
895
|
+
};
|
|
896
|
+
|
|
649
897
|
exports.CldImage = CldImage;
|
|
898
|
+
exports.CldOgImage = CldOgImage;
|
|
899
|
+
exports.CldUploadButton = CldUploadButton;
|
|
900
|
+
exports.CldUploadWidget = CldUploadWidget;
|
|
650
901
|
exports.cloudinaryLoader = cloudinaryLoader;
|
|
651
902
|
exports.position = position;
|
|
652
903
|
exports.primary = primary;
|