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