next-cloudinary 0.3.0 → 0.4.1
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 +84 -200
- package/dist/next-cloudinary.js +131 -154
- package/dist/next-cloudinary.js.map +1 -1
- package/dist/next-cloudinary.modern.mjs +97 -109
- package/dist/next-cloudinary.modern.mjs.map +1 -1
- package/dist/next-cloudinary.module.js +131 -154
- package/dist/next-cloudinary.module.js.map +1 -1
- package/dist/next-cloudinary.umd.js +131 -154
- package/dist/next-cloudinary.umd.js.map +1 -1
- package/package.json +10 -10
- package/babel.config.js +0 -9
- package/jest.config.js +0 -7
- package/tests/lib/cloudinary.spec.js +0 -129
- package/tests/loaders/cloudinary-loader.spec.js +0 -84
- package/tests/plugins/cropping.spec.js +0 -27
- package/tests/plugins/overlays.spec.js +0 -112
- package/tests/plugins/raw-transformations.spec.js +0 -54
- package/tests/plugins/underlays.spec.js +0 -62
|
@@ -9,31 +9,26 @@ function _extends() {
|
|
|
9
9
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
10
10
|
for (var i = 1; i < arguments.length; i++) {
|
|
11
11
|
var source = arguments[i];
|
|
12
|
-
|
|
13
12
|
for (var key in source) {
|
|
14
13
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
15
14
|
target[key] = source[key];
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
return target;
|
|
21
19
|
};
|
|
22
20
|
return _extends.apply(this, arguments);
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
26
23
|
if (source == null) return {};
|
|
27
24
|
var target = {};
|
|
28
25
|
var sourceKeys = Object.keys(source);
|
|
29
26
|
var key, i;
|
|
30
|
-
|
|
31
27
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
32
28
|
key = sourceKeys[i];
|
|
33
29
|
if (excluded.indexOf(key) >= 0) continue;
|
|
34
30
|
target[key] = source[key];
|
|
35
31
|
}
|
|
36
|
-
|
|
37
32
|
return target;
|
|
38
33
|
}
|
|
39
34
|
|
|
@@ -41,23 +36,19 @@ var cropsGravityAuto = ['crop', 'fill', 'lfill', 'fill_pad', 'thumb'];
|
|
|
41
36
|
var props$6 = ['crop', 'gravity'];
|
|
42
37
|
function plugin$6(_temp) {
|
|
43
38
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
cldImage = _ref.cldImage,
|
|
40
|
+
options = _ref.options;
|
|
47
41
|
var width = options.width,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
height = options.height,
|
|
43
|
+
_options$crop = options.crop,
|
|
44
|
+
crop = _options$crop === void 0 ? 'limit' : _options$crop;
|
|
51
45
|
var transformationString = "c_" + crop + ",w_" + width;
|
|
52
|
-
|
|
53
46
|
if (!options.gravity && cropsGravityAuto.includes(crop)) {
|
|
54
47
|
options.gravity = 'auto';
|
|
55
48
|
}
|
|
56
|
-
|
|
57
49
|
if (!['limit'].includes(crop)) {
|
|
58
50
|
transformationString = transformationString + ",h_" + height;
|
|
59
51
|
}
|
|
60
|
-
|
|
61
52
|
if (options.gravity) {
|
|
62
53
|
if (options.gravity === 'auto' && !cropsGravityAuto.includes(crop)) {
|
|
63
54
|
console.warn('Auto gravity can only be used with crop, fill, lfill, fill_pad or thumb. Not applying gravity.');
|
|
@@ -65,7 +56,6 @@ function plugin$6(_temp) {
|
|
|
65
56
|
transformationString = transformationString + ",g_" + options.gravity;
|
|
66
57
|
}
|
|
67
58
|
}
|
|
68
|
-
|
|
69
59
|
cldImage.resize(transformationString);
|
|
70
60
|
}
|
|
71
61
|
|
|
@@ -126,13 +116,11 @@ var props$5 = params.map(function (param) {
|
|
|
126
116
|
});
|
|
127
117
|
function plugin$5(_temp) {
|
|
128
118
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
cldImage = _ref.cldImage,
|
|
120
|
+
options = _ref.options;
|
|
132
121
|
params.forEach(function (key) {
|
|
133
122
|
var prop = key.prop || key;
|
|
134
123
|
var effect = key.effect || key;
|
|
135
|
-
|
|
136
124
|
if (options[prop] === true) {
|
|
137
125
|
cldImage.effect("e_" + effect);
|
|
138
126
|
} else if (typeof options[prop] === 'string') {
|
|
@@ -148,6 +136,7 @@ var effectsPlugin = {
|
|
|
148
136
|
};
|
|
149
137
|
|
|
150
138
|
// aspectRatio
|
|
139
|
+
|
|
151
140
|
var primary = {
|
|
152
141
|
aspectRatio: {
|
|
153
142
|
qualifier: 'ar'
|
|
@@ -211,19 +200,16 @@ var DEFAULT_TEXT_OPTIONS = {
|
|
|
211
200
|
};
|
|
212
201
|
function plugin$4(_temp) {
|
|
213
202
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
203
|
+
cldImage = _ref.cldImage,
|
|
204
|
+
options = _ref.options;
|
|
217
205
|
var text$1 = options.text,
|
|
218
|
-
|
|
219
|
-
|
|
206
|
+
_options$overlays = options.overlays,
|
|
207
|
+
overlays = _options$overlays === void 0 ? [] : _options$overlays;
|
|
220
208
|
var type = 'overlay';
|
|
221
209
|
var typeQualifier = 'l';
|
|
222
|
-
|
|
223
210
|
if (Array.isArray(overlays)) {
|
|
224
211
|
overlays.forEach(applyOverlay);
|
|
225
212
|
}
|
|
226
|
-
|
|
227
213
|
if (typeof text$1 === 'string') {
|
|
228
214
|
applyOverlay({
|
|
229
215
|
text: _extends({}, DEFAULT_TEXT_OPTIONS, {
|
|
@@ -235,48 +221,51 @@ function plugin$4(_temp) {
|
|
|
235
221
|
text: _extends({}, DEFAULT_TEXT_OPTIONS, text$1)
|
|
236
222
|
});
|
|
237
223
|
}
|
|
224
|
+
|
|
238
225
|
/**
|
|
239
226
|
* applyOverlay
|
|
240
227
|
*/
|
|
241
228
|
|
|
242
|
-
|
|
243
229
|
function applyOverlay(_ref2) {
|
|
244
230
|
var publicId = _ref2.publicId,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
231
|
+
position$1 = _ref2.position,
|
|
232
|
+
text$1 = _ref2.text,
|
|
233
|
+
_ref2$effects = _ref2.effects,
|
|
234
|
+
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
235
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
251
236
|
var hasPublicId = typeof publicId === 'string';
|
|
252
237
|
var hasText = typeof text$1 === 'object' || typeof text$1 === 'string';
|
|
253
238
|
var hasPosition = typeof position$1 === 'object';
|
|
254
|
-
|
|
255
239
|
if (!hasPublicId && !hasText) {
|
|
256
240
|
console.warn("An " + type + " is missing Public ID or Text");
|
|
257
241
|
return;
|
|
258
|
-
}
|
|
259
|
-
// if it's image-based
|
|
242
|
+
}
|
|
260
243
|
|
|
244
|
+
// Start to construct the transformation string using text or the public ID
|
|
245
|
+
// if it's image-based
|
|
261
246
|
|
|
262
247
|
var layerTransformation;
|
|
263
|
-
|
|
264
248
|
if (hasText) {
|
|
265
249
|
layerTransformation = typeQualifier + "_text";
|
|
266
250
|
} else {
|
|
267
251
|
layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
|
|
268
|
-
}
|
|
269
|
-
// it needs to be placed in the URL
|
|
252
|
+
}
|
|
270
253
|
|
|
254
|
+
// Begin organizing transformations based on what it is and the location
|
|
255
|
+
// it needs to be placed in the URL
|
|
271
256
|
|
|
272
257
|
var primary$1 = [];
|
|
273
|
-
var applied = [];
|
|
258
|
+
var applied = [];
|
|
259
|
+
|
|
260
|
+
// Gemeral options
|
|
274
261
|
|
|
275
262
|
Object.keys(options).forEach(function (key) {
|
|
276
263
|
if (!primary[key]) return;
|
|
277
264
|
var qualifier = primary[key].qualifier;
|
|
278
265
|
primary$1.push(qualifier + "_" + options[key]);
|
|
279
|
-
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// Layer effects
|
|
280
269
|
|
|
281
270
|
layerEffects.forEach(function (effect) {
|
|
282
271
|
Object.keys(effect).forEach(function (key) {
|
|
@@ -284,7 +273,9 @@ function plugin$4(_temp) {
|
|
|
284
273
|
var qualifier = primary[key].qualifier;
|
|
285
274
|
primary$1.push(qualifier + "_" + effect[key]);
|
|
286
275
|
});
|
|
287
|
-
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// Text styling
|
|
288
279
|
|
|
289
280
|
if (hasText) {
|
|
290
281
|
if (typeof text$1 === 'string') {
|
|
@@ -292,14 +283,12 @@ function plugin$4(_temp) {
|
|
|
292
283
|
text: text$1
|
|
293
284
|
});
|
|
294
285
|
}
|
|
295
|
-
|
|
296
286
|
var textTransformations = [];
|
|
297
287
|
Object.keys(text$1).forEach(function (key) {
|
|
298
288
|
if (!text[key]) return;
|
|
299
289
|
var _qualifiersText$key = text[key],
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
290
|
+
qualifier = _qualifiersText$key.qualifier,
|
|
291
|
+
location = _qualifiersText$key.location;
|
|
303
292
|
if (location === 'primary') {
|
|
304
293
|
primary$1.push(qualifier + "_" + text$1[key]);
|
|
305
294
|
} else {
|
|
@@ -307,8 +296,9 @@ function plugin$4(_temp) {
|
|
|
307
296
|
}
|
|
308
297
|
});
|
|
309
298
|
layerTransformation = layerTransformation + ":" + textTransformations.join('_') + ":" + text$1.text;
|
|
310
|
-
}
|
|
299
|
+
}
|
|
311
300
|
|
|
301
|
+
// Positioning
|
|
312
302
|
|
|
313
303
|
if (hasPosition) {
|
|
314
304
|
Object.keys(position$1).forEach(function (key) {
|
|
@@ -316,17 +306,20 @@ function plugin$4(_temp) {
|
|
|
316
306
|
var qualifier = position[key].qualifier;
|
|
317
307
|
applied.push(qualifier + "_" + position$1[key]);
|
|
318
308
|
});
|
|
319
|
-
}
|
|
309
|
+
}
|
|
320
310
|
|
|
311
|
+
// Add all primary transformations
|
|
321
312
|
|
|
322
|
-
layerTransformation = layerTransformation + "," + primary$1.join(',');
|
|
313
|
+
layerTransformation = layerTransformation + "," + primary$1.join(',');
|
|
323
314
|
|
|
324
|
-
|
|
315
|
+
// Add all applied transformations
|
|
325
316
|
|
|
317
|
+
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
326
318
|
if (applied.length > 0) {
|
|
327
319
|
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
328
|
-
}
|
|
320
|
+
}
|
|
329
321
|
|
|
322
|
+
// Finally add it to the image
|
|
330
323
|
|
|
331
324
|
cldImage.addTransformation(layerTransformation);
|
|
332
325
|
}
|
|
@@ -342,11 +335,10 @@ var overlaysPlugin = {
|
|
|
342
335
|
var props$3 = ['rawTransformations'];
|
|
343
336
|
function plugin$3(_temp) {
|
|
344
337
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
338
|
+
cldImage = _ref.cldImage,
|
|
339
|
+
options = _ref.options;
|
|
348
340
|
var _options$rawTransform = options.rawTransformations,
|
|
349
|
-
|
|
341
|
+
rawTransformations = _options$rawTransform === void 0 ? [] : _options$rawTransform;
|
|
350
342
|
rawTransformations.forEach(function (transformation) {
|
|
351
343
|
cldImage.addTransformation(transformation);
|
|
352
344
|
});
|
|
@@ -361,12 +353,10 @@ var rawTransformationsPlugin = {
|
|
|
361
353
|
var props$2 = ['removeBackground'];
|
|
362
354
|
function plugin$2(_temp) {
|
|
363
355
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
356
|
+
cldImage = _ref.cldImage,
|
|
357
|
+
options = _ref.options;
|
|
367
358
|
var _options$removeBackgr = options.removeBackground,
|
|
368
|
-
|
|
369
|
-
|
|
359
|
+
removeBackground = _options$removeBackgr === void 0 ? false : _options$removeBackgr;
|
|
370
360
|
if (removeBackground) {
|
|
371
361
|
cldImage.effect('e_background_removal');
|
|
372
362
|
}
|
|
@@ -382,68 +372,67 @@ var _excluded$2 = ["publicId", "type", "position", "text", "effects"];
|
|
|
382
372
|
var props$1 = ['underlay', 'underlays'];
|
|
383
373
|
function plugin$1(_temp) {
|
|
384
374
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
375
|
+
cldImage = _ref.cldImage,
|
|
376
|
+
options = _ref.options;
|
|
388
377
|
var underlay = options.underlay,
|
|
389
|
-
|
|
390
|
-
|
|
378
|
+
_options$underlays = options.underlays,
|
|
379
|
+
underlays = _options$underlays === void 0 ? [] : _options$underlays;
|
|
391
380
|
var typeQualifier = 'u';
|
|
392
|
-
|
|
393
381
|
if (Array.isArray(underlays)) {
|
|
394
382
|
underlays.forEach(applyUnderlay);
|
|
395
383
|
}
|
|
396
|
-
|
|
397
384
|
if (typeof underlay === 'string') {
|
|
398
385
|
var underlayOptions = {
|
|
399
386
|
publicId: underlay,
|
|
400
387
|
crop: 'fill'
|
|
401
388
|
};
|
|
402
|
-
|
|
403
389
|
if (options.width) {
|
|
404
390
|
underlayOptions.width = options.width;
|
|
405
391
|
}
|
|
406
|
-
|
|
407
392
|
if (options.height) {
|
|
408
393
|
underlayOptions.height = options.height;
|
|
409
394
|
}
|
|
410
|
-
|
|
411
395
|
applyUnderlay(underlayOptions);
|
|
412
396
|
}
|
|
397
|
+
|
|
413
398
|
/**
|
|
414
399
|
* applyUnderlay
|
|
415
400
|
*/
|
|
416
401
|
|
|
417
|
-
|
|
418
402
|
function applyUnderlay(_ref2) {
|
|
419
403
|
var publicId = _ref2.publicId,
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
404
|
+
type = _ref2.type,
|
|
405
|
+
position$1 = _ref2.position,
|
|
406
|
+
_ref2$effects = _ref2.effects,
|
|
407
|
+
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
408
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
|
|
426
409
|
var hasPublicId = typeof publicId === 'string';
|
|
427
410
|
var hasPosition = typeof position$1 === 'object';
|
|
428
|
-
|
|
429
411
|
if (!hasPublicId) {
|
|
430
412
|
console.warn("An " + type + " is missing a Public ID");
|
|
431
413
|
return;
|
|
432
|
-
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Start to construct the transformation string using text or the public ID
|
|
433
417
|
// if it's image-based
|
|
434
418
|
|
|
419
|
+
var layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
|
|
435
420
|
|
|
436
|
-
|
|
421
|
+
// Begin organizing transformations based on what it is and the location
|
|
437
422
|
// it needs to be placed in the URL
|
|
438
423
|
|
|
439
424
|
var primary$1 = [];
|
|
440
|
-
var applied = [];
|
|
425
|
+
var applied = [];
|
|
426
|
+
|
|
427
|
+
// Gemeral options
|
|
441
428
|
|
|
442
429
|
Object.keys(options).forEach(function (key) {
|
|
443
430
|
if (!primary[key]) return;
|
|
444
431
|
var qualifier = primary[key].qualifier;
|
|
445
432
|
primary$1.push(qualifier + "_" + options[key]);
|
|
446
|
-
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// Layer effects
|
|
447
436
|
|
|
448
437
|
layerEffects.forEach(function (effect) {
|
|
449
438
|
Object.keys(effect).forEach(function (key) {
|
|
@@ -451,7 +440,9 @@ function plugin$1(_temp) {
|
|
|
451
440
|
var qualifier = primary[key].qualifier;
|
|
452
441
|
primary$1.push(qualifier + "_" + effect[key]);
|
|
453
442
|
});
|
|
454
|
-
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// Positioning
|
|
455
446
|
|
|
456
447
|
if (hasPosition) {
|
|
457
448
|
Object.keys(position$1).forEach(function (key) {
|
|
@@ -459,17 +450,20 @@ function plugin$1(_temp) {
|
|
|
459
450
|
var qualifier = position[key].qualifier;
|
|
460
451
|
applied.push(qualifier + "_" + position$1[key]);
|
|
461
452
|
});
|
|
462
|
-
}
|
|
453
|
+
}
|
|
463
454
|
|
|
455
|
+
// Add all primary transformations
|
|
464
456
|
|
|
465
|
-
layerTransformation = layerTransformation + "," + primary$1.join(',');
|
|
457
|
+
layerTransformation = layerTransformation + "," + primary$1.join(',');
|
|
466
458
|
|
|
467
|
-
|
|
459
|
+
// Add all applied transformations
|
|
468
460
|
|
|
461
|
+
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
469
462
|
if (applied.length > 0) {
|
|
470
463
|
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
471
|
-
}
|
|
464
|
+
}
|
|
472
465
|
|
|
466
|
+
// Finally add it to the image
|
|
473
467
|
|
|
474
468
|
cldImage.addTransformation(layerTransformation);
|
|
475
469
|
}
|
|
@@ -484,13 +478,11 @@ var underlaysPlugin = {
|
|
|
484
478
|
var props = ['zoompan'];
|
|
485
479
|
function plugin(_temp) {
|
|
486
480
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
481
|
+
cldImage = _ref.cldImage,
|
|
482
|
+
options = _ref.options;
|
|
490
483
|
var _options$zoompan = options.zoompan,
|
|
491
|
-
|
|
484
|
+
zoompan = _options$zoompan === void 0 ? false : _options$zoompan;
|
|
492
485
|
var overrides = {};
|
|
493
|
-
|
|
494
486
|
if (zoompan === true) {
|
|
495
487
|
cldImage.effect('e_zoompan');
|
|
496
488
|
} else if (typeof zoompan === 'string') {
|
|
@@ -502,29 +494,23 @@ function plugin(_temp) {
|
|
|
502
494
|
}
|
|
503
495
|
} else if (typeof zoompan === 'object') {
|
|
504
496
|
var zoompanEffect = 'e_zoompan';
|
|
505
|
-
|
|
506
497
|
if (typeof zoompan.options === 'string') {
|
|
507
498
|
zoompanEffect = "" + zoompanEffect + zoompan.options;
|
|
508
499
|
}
|
|
509
|
-
|
|
510
500
|
cldImage.effect(zoompanEffect);
|
|
511
501
|
var loopEffect;
|
|
512
|
-
|
|
513
502
|
if (zoompan.loop === true) {
|
|
514
503
|
loopEffect = 'e_loop';
|
|
515
504
|
} else if (typeof zoompan.loop === 'string') {
|
|
516
505
|
loopEffect = "e_loop" + zoompan.loop;
|
|
517
506
|
}
|
|
518
|
-
|
|
519
507
|
if (loopEffect) {
|
|
520
508
|
cldImage.effect(loopEffect);
|
|
521
509
|
}
|
|
522
510
|
}
|
|
523
|
-
|
|
524
511
|
if (zoompan !== false) {
|
|
525
512
|
overrides.format = 'gif';
|
|
526
513
|
}
|
|
527
|
-
|
|
528
514
|
return {
|
|
529
515
|
options: overrides
|
|
530
516
|
};
|
|
@@ -536,19 +522,22 @@ var zoompanPlugin = {
|
|
|
536
522
|
plugin: plugin
|
|
537
523
|
};
|
|
538
524
|
|
|
539
|
-
var transformationPlugins = [
|
|
540
|
-
|
|
525
|
+
var transformationPlugins = [
|
|
526
|
+
// Background Removal must always come first
|
|
527
|
+
removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, underlaysPlugin, zoompanPlugin,
|
|
528
|
+
// Raw transformations needs to be last simply to make sure
|
|
541
529
|
// it's always expected to applied the same way
|
|
530
|
+
|
|
542
531
|
rawTransformationsPlugin];
|
|
543
532
|
var cld;
|
|
533
|
+
|
|
544
534
|
/**
|
|
545
535
|
* constructCloudinaryUrl
|
|
546
536
|
*/
|
|
547
537
|
|
|
548
538
|
function constructCloudinaryUrl(_ref) {
|
|
549
539
|
var options = _ref.options,
|
|
550
|
-
|
|
551
|
-
|
|
540
|
+
config = _ref.config;
|
|
552
541
|
if (!cld) {
|
|
553
542
|
cld = new Cloudinary(_extends({
|
|
554
543
|
cloud: {
|
|
@@ -560,24 +549,22 @@ function constructCloudinaryUrl(_ref) {
|
|
|
560
549
|
}
|
|
561
550
|
}, config));
|
|
562
551
|
}
|
|
563
|
-
|
|
564
552
|
var publicId = getPublicId(options.src);
|
|
565
553
|
var cldImage = cld.image(publicId);
|
|
566
554
|
transformationPlugins.forEach(function (_ref2) {
|
|
567
555
|
var plugin = _ref2.plugin;
|
|
568
|
-
|
|
569
556
|
var _ref3 = plugin({
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
557
|
+
cldImage: cldImage,
|
|
558
|
+
options: options
|
|
559
|
+
}) || {},
|
|
560
|
+
pluginOptions = _ref3.options;
|
|
575
561
|
if (pluginOptions != null && pluginOptions.format) {
|
|
576
562
|
options.format = pluginOptions.format;
|
|
577
563
|
}
|
|
578
564
|
});
|
|
579
565
|
return cldImage.setDeliveryType(options.deliveryType || 'upload').format(options.format || 'auto').delivery("q_" + (options.quality || 'auto')).toURL();
|
|
580
566
|
}
|
|
567
|
+
|
|
581
568
|
/**
|
|
582
569
|
* Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
|
|
583
570
|
* If it's recognized that is a url and it's not possible to get the public id, it warns the user.
|
|
@@ -591,13 +578,11 @@ function getPublicId(src) {
|
|
|
591
578
|
if (typeof src !== 'string') {
|
|
592
579
|
throw new Error("Invalid src of type " + typeof src);
|
|
593
580
|
}
|
|
594
|
-
|
|
595
581
|
if (src.includes('res.cloudinary.com')) {
|
|
596
582
|
var regexWithTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
597
583
|
var regexWithoutTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
598
584
|
var withTransformations = src.match(regexWithTransformations);
|
|
599
585
|
var withoutTransformations = src.match(regexWithoutTransformations);
|
|
600
|
-
|
|
601
586
|
if (withTransformations) {
|
|
602
587
|
return withTransformations[withTransformations.length - 1];
|
|
603
588
|
} else if (withoutTransformations) {
|
|
@@ -606,30 +591,27 @@ function getPublicId(src) {
|
|
|
606
591
|
console.warn("Not possible to retrieve the publicUrl from " + src + ", make sure it's a valid cloudinary image url.");
|
|
607
592
|
}
|
|
608
593
|
}
|
|
609
|
-
|
|
610
594
|
return src;
|
|
611
595
|
}
|
|
596
|
+
|
|
612
597
|
/**
|
|
613
598
|
* createPlaceholderUrl
|
|
614
599
|
*/
|
|
615
600
|
|
|
616
601
|
function createPlaceholderUrl(_ref4) {
|
|
617
602
|
var src = _ref4.src,
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
603
|
+
_ref4$placeholder = _ref4.placeholder,
|
|
604
|
+
placeholder = _ref4$placeholder === void 0 ? true : _ref4$placeholder,
|
|
605
|
+
config = _ref4.config;
|
|
621
606
|
var rawTransformations = [];
|
|
622
|
-
|
|
623
607
|
if (placeholder === 'grayscale') {
|
|
624
608
|
rawTransformations.push('e_grayscale');
|
|
625
609
|
}
|
|
626
|
-
|
|
627
610
|
if (typeof placeholder === 'string' && placeholder.includes('color:')) {
|
|
628
611
|
var color = placeholder.split(':').splice(1).join(':');
|
|
629
612
|
rawTransformations.push('e_grayscale');
|
|
630
613
|
rawTransformations.push("e_colorize:60,co_" + color);
|
|
631
614
|
}
|
|
632
|
-
|
|
633
615
|
return constructCloudinaryUrl({
|
|
634
616
|
options: {
|
|
635
617
|
src: src,
|
|
@@ -645,7 +627,6 @@ function cloudinaryLoader(defaultOptions, cldOptions, cldConfig) {
|
|
|
645
627
|
if (cldConfig === void 0) {
|
|
646
628
|
cldConfig = {};
|
|
647
629
|
}
|
|
648
|
-
|
|
649
630
|
return constructCloudinaryUrl({
|
|
650
631
|
options: _extends({}, defaultOptions, cldOptions),
|
|
651
632
|
config: cldConfig
|
|
@@ -656,29 +637,34 @@ var CldImage = function CldImage(props) {
|
|
|
656
637
|
var CLD_OPTIONS = [];
|
|
657
638
|
transformationPlugins.forEach(function (_ref) {
|
|
658
639
|
var _ref$props = _ref.props,
|
|
659
|
-
|
|
640
|
+
props = _ref$props === void 0 ? [] : _ref$props;
|
|
660
641
|
props.forEach(function (prop) {
|
|
661
642
|
if (CLD_OPTIONS.includes(prop)) {
|
|
662
643
|
throw new Error("Option " + prop + " already exists!");
|
|
663
644
|
}
|
|
664
|
-
|
|
665
645
|
CLD_OPTIONS.push(prop);
|
|
666
646
|
});
|
|
667
|
-
});
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// Construct the base Image component props by filtering out Cloudinary-specific props
|
|
668
650
|
|
|
669
651
|
var imageProps = {};
|
|
670
652
|
Object.keys(props).filter(function (key) {
|
|
671
653
|
return !CLD_OPTIONS.includes(key);
|
|
672
654
|
}).forEach(function (key) {
|
|
673
655
|
return imageProps[key] = props[key];
|
|
674
|
-
});
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// Construct Cloudinary-specific props by looking for values for any of the supported prop keys
|
|
675
659
|
|
|
676
660
|
var cldOptions = {};
|
|
677
661
|
CLD_OPTIONS.forEach(function (key) {
|
|
678
662
|
if (props[key]) {
|
|
679
663
|
cldOptions[key] = props[key];
|
|
680
664
|
}
|
|
681
|
-
});
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
// If we see a placeholder option, configure a Cloudinary-based URL.
|
|
682
668
|
// The resulting image will always be blurred per Next.js, so we're
|
|
683
669
|
// limited on options for placeholders.
|
|
684
670
|
//
|
|
@@ -693,12 +679,10 @@ var CldImage = function CldImage(props) {
|
|
|
693
679
|
src: publicId,
|
|
694
680
|
placeholder: props.placeholder
|
|
695
681
|
});
|
|
696
|
-
|
|
697
682
|
if (imageProps.placeholder !== 'blur') {
|
|
698
683
|
imageProps.placeholder = 'blur';
|
|
699
684
|
}
|
|
700
685
|
}
|
|
701
|
-
|
|
702
686
|
return /*#__PURE__*/jsx(Image, _extends({}, imageProps, {
|
|
703
687
|
loader: function loader(options) {
|
|
704
688
|
return cloudinaryLoader(_extends({}, imageProps, {
|
|
@@ -712,23 +696,22 @@ var _excluded$1 = ["excludeTags", "twitterTitle"];
|
|
|
712
696
|
var IMAGE_WIDTH = 2400;
|
|
713
697
|
var IMAGE_HEIGHT = 1200;
|
|
714
698
|
var TWITTER_CARD = 'summary_large_image';
|
|
715
|
-
|
|
716
699
|
var CldOgImage = function CldOgImage(_ref) {
|
|
717
700
|
var _ref$excludeTags = _ref.excludeTags,
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
701
|
+
excludeTags = _ref$excludeTags === void 0 ? [] : _ref$excludeTags,
|
|
702
|
+
twitterTitle = _ref.twitterTitle,
|
|
703
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
722
704
|
var options = _extends({}, props, {
|
|
723
705
|
width: props.width || IMAGE_WIDTH,
|
|
724
706
|
height: props.height || IMAGE_HEIGHT,
|
|
725
707
|
crop: props.crop || 'fill',
|
|
726
708
|
gravity: props.gravity || 'center'
|
|
727
709
|
});
|
|
728
|
-
|
|
729
710
|
var ogImageUrl = constructCloudinaryUrl({
|
|
730
711
|
options: options
|
|
731
|
-
});
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
// We need to include the tags within the Next.js Head component rather than
|
|
732
715
|
// direcly adding them inside of the Head otherwise we get unexpected results
|
|
733
716
|
|
|
734
717
|
return /*#__PURE__*/jsxs(Head, {
|
|
@@ -762,12 +745,13 @@ var CldOgImage = function CldOgImage(_ref) {
|
|
|
762
745
|
|
|
763
746
|
var CldUploadWidget = function CldUploadWidget(_ref) {
|
|
764
747
|
var children = _ref.children,
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
748
|
+
onUpload = _ref.onUpload,
|
|
749
|
+
options = _ref.options,
|
|
750
|
+
signed = _ref.signed,
|
|
751
|
+
signatureEndpoint = _ref.signatureEndpoint;
|
|
769
752
|
var cloudinary = useRef();
|
|
770
753
|
var widget = useRef();
|
|
754
|
+
|
|
771
755
|
/**
|
|
772
756
|
* generateSignature
|
|
773
757
|
* @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
|
|
@@ -786,28 +770,27 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
|
|
|
786
770
|
callback(signature);
|
|
787
771
|
});
|
|
788
772
|
}
|
|
773
|
+
|
|
789
774
|
/**
|
|
790
775
|
* createWidget
|
|
791
776
|
* @description Creates a new instance of the Cloudinary widget and stores in a ref
|
|
792
777
|
*/
|
|
793
778
|
|
|
794
|
-
|
|
795
779
|
function createWidget() {
|
|
796
780
|
var _cloudinary$current;
|
|
797
|
-
|
|
798
781
|
// When creating a signed upload, you need to provide both your Cloudinary API Key
|
|
799
782
|
// as well as a signature generator function that will sign any paramters
|
|
800
783
|
// either on page load or during the upload process. Read more about signed uploads at:
|
|
801
784
|
// https://cloudinary.com/documentation/upload_widget#signed_uploads
|
|
785
|
+
|
|
802
786
|
var totalOptions = _extends({}, options, !!signed && {
|
|
803
787
|
uploadSignature: generateSignature
|
|
804
|
-
});
|
|
805
|
-
|
|
788
|
+
});
|
|
806
789
|
|
|
790
|
+
// no need for apiSecret because of api/sign-cloudinary-params
|
|
807
791
|
if (signed && !totalOptions.apiKey) {
|
|
808
792
|
return new Error("Signed Upload needs apiKey!");
|
|
809
793
|
}
|
|
810
|
-
|
|
811
794
|
return (_cloudinary$current = cloudinary.current) == null ? void 0 : _cloudinary$current.createUploadWidget(totalOptions, function (error, result) {
|
|
812
795
|
// The callback is a bit more chatty than failed or success so
|
|
813
796
|
// only trigger when one of those are the case. You can additionally
|
|
@@ -818,29 +801,27 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
|
|
|
818
801
|
}
|
|
819
802
|
});
|
|
820
803
|
}
|
|
804
|
+
|
|
821
805
|
/**
|
|
822
806
|
* open
|
|
823
807
|
* @description When triggered, uses the current widget instance to open the upload modal
|
|
824
808
|
*/
|
|
825
809
|
|
|
826
|
-
|
|
827
810
|
function open() {
|
|
828
811
|
if (!(widget != null && widget.current)) {
|
|
829
812
|
widget.current = createWidget();
|
|
830
813
|
}
|
|
831
|
-
|
|
832
814
|
(widget == null ? void 0 : widget.current) && widget.current.open();
|
|
833
815
|
}
|
|
816
|
+
|
|
834
817
|
/**
|
|
835
818
|
* handleOnLoad
|
|
836
819
|
* @description Stores the Cloudinary window instance to a ref when the widget script loads
|
|
837
820
|
*/
|
|
838
821
|
|
|
839
|
-
|
|
840
822
|
function handleOnLoad() {
|
|
841
823
|
cloudinary.current = window.cloudinary;
|
|
842
824
|
}
|
|
843
|
-
|
|
844
825
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
845
826
|
children: [children({
|
|
846
827
|
cloudinary: cloudinary.current,
|
|
@@ -858,14 +839,12 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
|
|
|
858
839
|
};
|
|
859
840
|
|
|
860
841
|
var _excluded = ["onUpload", "options", "signed", "label", "children"];
|
|
861
|
-
|
|
862
842
|
var CldUploadButton = function CldUploadButton(_ref) {
|
|
863
843
|
var onUpload = _ref.onUpload,
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
844
|
+
options = _ref.options,
|
|
845
|
+
signed = _ref.signed,
|
|
846
|
+
_children = _ref.children,
|
|
847
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
869
848
|
return /*#__PURE__*/jsx(Fragment, {
|
|
870
849
|
children: /*#__PURE__*/jsx(CldUploadWidget, {
|
|
871
850
|
signed: signed,
|
|
@@ -874,12 +853,10 @@ var CldUploadButton = function CldUploadButton(_ref) {
|
|
|
874
853
|
signatureEndpoint: signed != null ? signed : props.signatureEndpoint,
|
|
875
854
|
children: function children(_ref2) {
|
|
876
855
|
var open = _ref2.open;
|
|
877
|
-
|
|
878
856
|
function handleOnClick(e) {
|
|
879
857
|
e.preventDefault();
|
|
880
858
|
open();
|
|
881
859
|
}
|
|
882
|
-
|
|
883
860
|
return /*#__PURE__*/jsx("button", _extends({
|
|
884
861
|
onClick: handleOnClick
|
|
885
862
|
}, props, {
|