next-cloudinary 1.12.3 → 2.0.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.
@@ -1,6 +1,7 @@
1
1
  var react = require('react');
2
2
  var Image = require('next/image');
3
- var urlGen = require('@cloudinary/url-gen');
3
+ var util = require('@cloudinary-util/util');
4
+ var urlLoader = require('@cloudinary-util/url-loader');
4
5
  var nextPkg = require('next/package.json');
5
6
  var jsxRuntime = require('react/jsx-runtime');
6
7
  var Head = require('next/head');
@@ -40,849 +41,8 @@ function _objectWithoutPropertiesLoose(source, excluded) {
40
41
  return target;
41
42
  }
42
43
 
43
- var cropsGravityAuto = ['crop', 'fill', 'lfill', 'fill_pad', 'thumb'];
44
- var cropsWithZoom = ['crop', 'thumb'];
45
- var props$7 = ['crop', 'gravity', 'zoom'];
46
- function plugin$7(_temp) {
47
- var _ref = _temp === void 0 ? {} : _temp,
48
- cldImage = _ref.cldImage,
49
- options = _ref.options;
50
- var overrides = {};
51
- var width = options.width,
52
- height = options.height,
53
- widthResize = options.widthResize,
54
- _options$crop = options.crop,
55
- crop = _options$crop === void 0 ? 'limit' : _options$crop;
56
- var transformationString = '';
57
- if (width) {
58
- transformationString = "c_" + crop + ",w_" + width;
59
- }
60
- if (!options.gravity && cropsGravityAuto.includes(crop)) {
61
- options.gravity = 'auto';
62
- }
63
- if (!['limit'].includes(crop)) {
64
- transformationString = transformationString + ",h_" + height;
65
- }
66
- if (options.gravity) {
67
- if (options.gravity === 'auto' && !cropsGravityAuto.includes(crop)) {
68
- console.warn("Auto gravity can only be used with crop modes: " + cropsGravityAuto.join(', ') + ". Not applying gravity.");
69
- } else {
70
- transformationString = transformationString + ",g_" + options.gravity;
71
- }
72
- }
73
- if (options.zoom) {
74
- if (options.zoom === 'auto' && !cropsWithZoom.includes(crop)) {
75
- console.warn("Zoom can only be used with crop modes: " + cropsWithZoom.join(', ') + ". Not applying zoom.");
76
- } else {
77
- transformationString = transformationString + ",z_" + options.zoom;
78
- }
79
- }
80
- cldImage.effect(transformationString);
81
-
82
- // If we have a resize width that's smaller than the user-defined width, we want to give the
83
- // ability to perform a final resize on the image without impacting any of the effects like text
84
- // overlays that may depend on the size to work properly
85
-
86
- if (typeof widthResize === 'number' && widthResize < width) {
87
- overrides.width = widthResize;
88
- }
89
- return {
90
- options: overrides
91
- };
92
- }
93
-
94
- var croppingPlugin = {
95
- __proto__: null,
96
- props: props$7,
97
- plugin: plugin$7
98
- };
99
-
100
- // aspectRatio
101
-
102
- var primary = {
103
- aspectRatio: {
104
- qualifier: 'ar'
105
- },
106
- crop: {
107
- qualifier: 'c'
108
- },
109
- gravity: {
110
- qualifier: 'g'
111
- },
112
- height: {
113
- qualifier: 'h'
114
- },
115
- width: {
116
- qualifier: 'w'
117
- }
118
- };
119
- var position = {
120
- angle: {
121
- qualifier: 'a'
122
- },
123
- gravity: {
124
- qualifier: 'g'
125
- },
126
- x: {
127
- qualifier: 'x'
128
- },
129
- y: {
130
- qualifier: 'y'
131
- }
132
- };
133
- var text = {
134
- alignment: {
135
- qualifier: 'alignment'
136
- },
137
- border: {
138
- qualifier: 'bo',
139
- location: 'primary'
140
- },
141
- color: {
142
- qualifier: 'co',
143
- location: 'primary'
144
- },
145
- fontFamily: {
146
- qualifier: false
147
- },
148
- fontSize: {
149
- qualifier: false
150
- },
151
- fontWeight: {
152
- qualifier: false
153
- },
154
- letterSpacing: {
155
- qualifier: 'letter_spacing'
156
- },
157
- lineSpacing: {
158
- qualifier: 'line_spacing'
159
- },
160
- stroke: {
161
- qualifier: 'self'
162
- },
163
- textDecoration: {
164
- qualifier: false
165
- }
166
- };
167
- var effects = {
168
- art: {
169
- prefix: 'e',
170
- qualifier: 'art'
171
- },
172
- autoBrightness: {
173
- prefix: 'e',
174
- qualifier: 'auto_brightness'
175
- },
176
- autoColor: {
177
- prefix: 'e',
178
- qualifier: 'auto_color'
179
- },
180
- autoContrast: {
181
- prefix: 'e',
182
- qualifier: 'auto_contrast'
183
- },
184
- assistColorblind: {
185
- prefix: 'e',
186
- qualifier: 'assist_colorblind'
187
- },
188
- background: {
189
- qualifier: 'b'
190
- },
191
- blackwhite: {
192
- prefix: 'e',
193
- qualifier: 'blackwhite'
194
- },
195
- blur: {
196
- prefix: 'e',
197
- qualifier: 'blur'
198
- },
199
- blurFaces: {
200
- prefix: 'e',
201
- qualifier: 'blur_faces'
202
- },
203
- blurRegion: {
204
- prefix: 'e',
205
- qualifier: 'blur_region'
206
- },
207
- border: {
208
- qualifier: 'bo'
209
- },
210
- brightness: {
211
- prefix: 'e',
212
- qualifier: 'brightness'
213
- },
214
- brightnessHSB: {
215
- prefix: 'e',
216
- qualifier: 'brightness_hsb'
217
- },
218
- cartoonify: {
219
- prefix: 'e',
220
- qualifier: 'cartoonify'
221
- },
222
- color: {
223
- qualifier: 'co'
224
- },
225
- colorize: {
226
- prefix: 'e',
227
- qualifier: 'colorize'
228
- },
229
- contrast: {
230
- prefix: 'e',
231
- qualifier: 'contrast'
232
- },
233
- distort: {
234
- prefix: 'e',
235
- qualifier: 'distort'
236
- },
237
- fillLight: {
238
- prefix: 'e',
239
- qualifier: 'fill_light'
240
- },
241
- gamma: {
242
- prefix: 'e',
243
- qualifier: 'gamma'
244
- },
245
- gradientFade: {
246
- prefix: 'e',
247
- qualifier: 'gradient_fade'
248
- },
249
- grayscale: {
250
- prefix: 'e',
251
- qualifier: 'grayscale'
252
- },
253
- improve: {
254
- prefix: 'e',
255
- qualifier: 'improve'
256
- },
257
- multiply: {
258
- prefix: 'e',
259
- qualifier: 'multiply'
260
- },
261
- negate: {
262
- prefix: 'e',
263
- qualifier: 'negate'
264
- },
265
- oilPaint: {
266
- prefix: 'e',
267
- qualifier: 'oil_paint'
268
- },
269
- opacity: {
270
- qualifier: 'o'
271
- },
272
- outline: {
273
- prefix: 'e',
274
- qualifier: 'outline'
275
- },
276
- overlay: {
277
- prefix: 'e',
278
- qualifier: 'overlay'
279
- },
280
- pixelate: {
281
- prefix: 'e',
282
- qualifier: 'pixelate'
283
- },
284
- pixelateFaces: {
285
- prefix: 'e',
286
- qualifier: 'pixelate_faces'
287
- },
288
- pixelateRegion: {
289
- prefix: 'e',
290
- qualifier: 'pixelate_region'
291
- },
292
- redeye: {
293
- prefix: 'e',
294
- qualifier: 'redeye'
295
- },
296
- replaceColor: {
297
- prefix: 'e',
298
- qualifier: 'replace_color'
299
- },
300
- saturation: {
301
- prefix: 'e',
302
- qualifier: 'saturation'
303
- },
304
- screen: {
305
- prefix: 'e',
306
- qualifier: 'screen'
307
- },
308
- sepia: {
309
- prefix: 'e',
310
- qualifier: 'sepia'
311
- },
312
- shadow: {
313
- prefix: 'e',
314
- qualifier: 'shadow'
315
- },
316
- sharpen: {
317
- prefix: 'e',
318
- qualifier: 'sharpen'
319
- },
320
- shear: {
321
- prefix: 'e',
322
- qualifier: 'shear'
323
- },
324
- simulateColorblind: {
325
- prefix: 'e',
326
- qualifier: 'simulate_colorblind'
327
- },
328
- tint: {
329
- prefix: 'e',
330
- qualifier: 'tint'
331
- },
332
- unsharpMask: {
333
- prefix: 'e',
334
- qualifier: 'unsharp_mask'
335
- },
336
- vectorize: {
337
- prefix: 'e',
338
- qualifier: 'vectorize'
339
- },
340
- vibrance: {
341
- prefix: 'e',
342
- qualifier: 'vibrance'
343
- },
344
- vignette: {
345
- prefix: 'e',
346
- qualifier: 'vignette'
347
- }
348
- };
349
- var flags = {
350
- relative: {
351
- prefix: 'fl',
352
- qualifier: 'relative',
353
- location: 'primary'
354
- }
355
- };
356
-
357
- /**
358
- * constructTransformation
359
- */
360
-
361
- function constructTransformation(_ref) {
362
- var prefix = _ref.prefix,
363
- qualifier = _ref.qualifier,
364
- value = _ref.value;
365
- var transformation = '';
366
- if (prefix) {
367
- transformation = prefix + "_";
368
- }
369
- if (value === true || value === 'true') {
370
- return "" + transformation + qualifier;
371
- }
372
- if (typeof value === 'string' || typeof value === 'number') {
373
- if (prefix) {
374
- return "" + transformation + qualifier + ":" + value;
375
- } else {
376
- return qualifier + "_" + value;
377
- }
378
- }
379
- }
380
-
381
- /**
382
- * Retrieves the transformations added to a cloudiary image url. If no transformation is recognized it returns an empty array.
383
- *
384
- * @param {string} src The cloudiary url.
385
- *
386
- * @return {array} The array of transformations
387
- */
388
-
389
- function getTransformations(src, preserveTransformations) {
390
- if (typeof src !== "string") {
391
- throw new Error("Invalid src of type " + typeof src);
392
- }
393
- if (src.includes("res.cloudinary.com") && preserveTransformations) {
394
- var regex = new RegExp("(https?)://(res.cloudinary.com)/([^/]+)/(image|video|raw)/(upload|authenticated)/(.*)/(v[0-9]+)/(.+)(?:.[a-z]{3})?", "gi");
395
- var groups = regex.exec(src);
396
- var transformationStr = groups.slice(1).find(function (i) {
397
- return i.includes("_");
398
- });
399
- if (transformationStr) {
400
- return transformationStr.split(",").join("/").split("/");
401
- } else {
402
- return [];
403
- }
404
- }
405
- return [];
406
- }
407
-
408
- var props$6 = [].concat(Object.keys(effects), ['effects']);
409
- function plugin$6(_temp) {
410
- var _ref = _temp === void 0 ? {} : _temp,
411
- cldImage = _ref.cldImage,
412
- options = _ref.options;
413
- // Handle any top-level effect props
414
-
415
- constructTransformationString({
416
- effects: effects,
417
- options: options
418
- }).filter(function (t) {
419
- return !!t;
420
- }).forEach(function (transformation) {
421
- return cldImage.effect(transformation);
422
- });
423
-
424
- // If we're passing in an effects prop explicitly, treat it as an array of
425
- // effects that we need to process
426
-
427
- if (Array.isArray(options.effects)) {
428
- options.effects.forEach(function (effectsSet) {
429
- var transformationString = constructTransformationString({
430
- effects: effects,
431
- options: effectsSet
432
- }).filter(function (t) {
433
- return !!t;
434
- }).join(',');
435
- cldImage.effect(transformationString);
436
- });
437
- }
438
- function constructTransformationString(_ref2) {
439
- var effects = _ref2.effects,
440
- options = _ref2.options;
441
- return Object.keys(effects).map(function (key) {
442
- var _effects$key = effects[key],
443
- prefix = _effects$key.prefix,
444
- qualifier = _effects$key.qualifier;
445
- return constructTransformation({
446
- qualifier: qualifier,
447
- prefix: prefix,
448
- value: options[key]
449
- });
450
- });
451
- }
452
- }
453
-
454
- var effectsPlugin = {
455
- __proto__: null,
456
- props: props$6,
457
- plugin: plugin$6
458
- };
459
-
460
- /**
461
- * encodeBase64
462
- */
463
-
464
- function encodeBase64(value) {
465
- if (typeof btoa === 'function') {
466
- return btoa(value);
467
- }
468
- if (typeof Buffer !== 'undefined') {
469
- return Buffer.from(value).toString('base64');
470
- }
471
- }
472
-
473
- var _excluded$3 = ["publicId", "url", "position", "text", "effects", "appliedEffects"];
474
- var props$5 = ['text', 'overlays'];
475
- var DEFAULT_TEXT_OPTIONS = {
476
- color: 'black',
477
- fontFamily: 'Arial',
478
- fontSize: 200,
479
- fontWeight: 'bold'
480
- };
481
- function plugin$5(_temp) {
482
- var _ref = _temp === void 0 ? {} : _temp,
483
- cldImage = _ref.cldImage,
484
- options = _ref.options;
485
- var text$1 = options.text,
486
- _options$overlays = options.overlays,
487
- overlays = _options$overlays === void 0 ? [] : _options$overlays;
488
- var type = 'overlay';
489
- var typeQualifier = 'l';
490
- if (Array.isArray(overlays)) {
491
- overlays.forEach(applyOverlay);
492
- }
493
- if (typeof text$1 === 'string') {
494
- applyOverlay({
495
- text: _extends({}, DEFAULT_TEXT_OPTIONS, {
496
- text: text$1
497
- })
498
- });
499
- } else if (typeof text$1 === 'object') {
500
- applyOverlay({
501
- text: _extends({}, DEFAULT_TEXT_OPTIONS, text$1)
502
- });
503
- }
504
-
505
- /**
506
- * applyOverlay
507
- */
508
-
509
- function applyOverlay(_ref2) {
510
- var publicId = _ref2.publicId,
511
- url = _ref2.url,
512
- position$1 = _ref2.position,
513
- text$1 = _ref2.text,
514
- _ref2$effects = _ref2.effects,
515
- layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
516
- _ref2$appliedEffects = _ref2.appliedEffects,
517
- appliedEffects = _ref2$appliedEffects === void 0 ? [] : _ref2$appliedEffects,
518
- options = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
519
- var hasPublicId = typeof publicId === 'string';
520
- var hasUrl = typeof url === 'string';
521
- var hasText = typeof text$1 === 'object' || typeof text$1 === 'string';
522
- var hasPosition = typeof position$1 === 'object';
523
- if (!hasPublicId && !hasUrl && !hasText) {
524
- console.warn("An " + type + " is missing Public ID, URL, or Text");
525
- return;
526
- }
527
-
528
- // Start to construct the transformation string using text or the public ID
529
- // if it's image-based
530
-
531
- var layerTransformation;
532
- if (hasText) {
533
- layerTransformation = typeQualifier + "_text";
534
- } else if (hasPublicId) {
535
- layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
536
- } else if (hasUrl) {
537
- layerTransformation = typeQualifier + "_fetch:" + encodeBase64(url);
538
- }
539
-
540
- // Begin organizing transformations based on what it is and the location
541
- // it needs to be placed in the URL
542
-
543
- var primary$1 = [];
544
- var applied = [];
545
-
546
- // Gemeral options
547
-
548
- Object.keys(options).forEach(function (key) {
549
- if (!primary[key]) return;
550
- var qualifier = primary[key].qualifier;
551
- var transformation = constructTransformation({
552
- qualifier: qualifier,
553
- value: options[key]
554
- });
555
- primary$1.push(transformation);
556
- });
557
-
558
- // Layer effects
559
- // For layer effects we allow both the standard effects to be applied as well
560
- // as the primary ones like width and height as those can be used to modify
561
- // the layer after it's created
562
-
563
- layerEffects.forEach(function (effect) {
564
- Object.keys(effect).forEach(function (key) {
565
- var _ref3 = primary[key] || effects[key] || {},
566
- qualifier = _ref3.qualifier,
567
- prefix = _ref3.prefix;
568
- var transformation = constructTransformation({
569
- qualifier: qualifier,
570
- prefix: prefix,
571
- value: effect[key]
572
- });
573
- primary$1.push(transformation);
574
- });
575
- });
576
-
577
- // Applied Layer effects
578
- // Similar to layer effects but they get appended to an additional transformation
579
- // along with fl_layer_applied
580
-
581
- appliedEffects.forEach(function (effect) {
582
- Object.keys(effect).forEach(function (key) {
583
- var _ref4 = primary[key] || effects[key] || {},
584
- qualifier = _ref4.qualifier,
585
- prefix = _ref4.prefix;
586
- var transformation = constructTransformation({
587
- qualifier: qualifier,
588
- prefix: prefix,
589
- value: effect[key]
590
- });
591
- applied.push(transformation);
592
- });
593
- });
594
-
595
- // Text styling
596
-
597
- if (hasText) {
598
- if (typeof text$1 === 'string') {
599
- text$1 = _extends({}, DEFAULT_TEXT_OPTIONS, {
600
- text: text$1
601
- });
602
- }
603
- var textTransformations = [];
604
- Object.keys(text$1).forEach(function (key) {
605
- if (!text[key]) return;
606
- var _qualifiersText$key = text[key],
607
- qualifier = _qualifiersText$key.qualifier,
608
- location = _qualifiersText$key.location;
609
- if (location === 'primary') {
610
- primary$1.push(qualifier + "_" + text$1[key]);
611
- } else if (qualifier === 'self') {
612
- textTransformations.push(key);
613
- } else if (qualifier) {
614
- textTransformations.push(qualifier + "_" + text$1[key]);
615
- } else {
616
- textTransformations.push(text$1[key]);
617
- }
618
- });
619
- layerTransformation = layerTransformation + ":" + textTransformations.join('_') + ":" + text$1.text;
620
- }
621
-
622
- // Positioning
623
-
624
- if (hasPosition) {
625
- Object.keys(position$1).forEach(function (key) {
626
- if (!position[key]) return;
627
- var qualifier = position[key].qualifier;
628
- var transformation = constructTransformation({
629
- qualifier: qualifier,
630
- value: position$1[key]
631
- });
632
- applied.push(transformation);
633
- });
634
- }
635
-
636
- // Add all primary transformations
637
-
638
- if (primary$1.length > 0) {
639
- layerTransformation = layerTransformation + "," + primary$1.join(',');
640
- }
641
-
642
- // Add all applied transformations
643
-
644
- layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
645
- if (applied.length > 0) {
646
- layerTransformation = layerTransformation + "," + applied.join(',');
647
- }
648
-
649
- // Finally add it to the image
650
-
651
- cldImage.addTransformation(layerTransformation);
652
- }
653
- }
654
-
655
- var overlaysPlugin = {
656
- __proto__: null,
657
- props: props$5,
658
- DEFAULT_TEXT_OPTIONS: DEFAULT_TEXT_OPTIONS,
659
- plugin: plugin$5
660
- };
661
-
662
- var props$4 = ['transformations'];
663
- function plugin$4(_temp) {
664
- var _ref = _temp === void 0 ? {} : _temp,
665
- cldImage = _ref.cldImage,
666
- options = _ref.options;
667
- var _options$transformati = options.transformations,
668
- transformations = _options$transformati === void 0 ? [] : _options$transformati;
669
- if (!Array.isArray(transformations)) {
670
- transformations = [transformations];
671
- }
672
- transformations.forEach(function (transformation) {
673
- cldImage.addTransformation("t_" + transformation);
674
- });
675
- }
676
-
677
- var namedTransformationsPlugin = {
678
- __proto__: null,
679
- props: props$4,
680
- plugin: plugin$4
681
- };
682
-
683
- var props$3 = ['rawTransformations'];
684
- function plugin$3(_temp) {
685
- var _ref = _temp === void 0 ? {} : _temp,
686
- cldImage = _ref.cldImage,
687
- options = _ref.options;
688
- var _options$rawTransform = options.rawTransformations,
689
- rawTransformations = _options$rawTransform === void 0 ? [] : _options$rawTransform;
690
- rawTransformations.forEach(function (transformation) {
691
- cldImage.addTransformation(transformation);
692
- });
693
- }
694
-
695
- var rawTransformationsPlugin = {
696
- __proto__: null,
697
- props: props$3,
698
- plugin: plugin$3
699
- };
700
-
701
- var props$2 = ['removeBackground'];
702
- function plugin$2(_temp) {
703
- var _ref = _temp === void 0 ? {} : _temp,
704
- cldImage = _ref.cldImage,
705
- options = _ref.options;
706
- var _options$removeBackgr = options.removeBackground,
707
- removeBackground = _options$removeBackgr === void 0 ? false : _options$removeBackgr;
708
- if (removeBackground) {
709
- cldImage.effect('e_background_removal');
710
- }
711
- }
712
-
713
- var removeBackgroundPlugin = {
714
- __proto__: null,
715
- props: props$2,
716
- plugin: plugin$2
717
- };
718
-
719
- var _excluded$2 = ["publicId", "type", "position", "text", "effects", "flags"];
720
- var props$1 = ['underlay', 'underlays'];
721
- function plugin$1(_temp) {
722
- var _ref = _temp === void 0 ? {} : _temp,
723
- cldImage = _ref.cldImage,
724
- options = _ref.options;
725
- var underlay = options.underlay,
726
- _options$underlays = options.underlays,
727
- underlays = _options$underlays === void 0 ? [] : _options$underlays;
728
- var typeQualifier = 'u';
729
- if (Array.isArray(underlays)) {
730
- underlays.forEach(applyUnderlay);
731
- }
732
- if (typeof underlay === 'string') {
733
- var underlayOptions = {
734
- publicId: underlay,
735
- crop: 'fill',
736
- width: '1.0',
737
- height: '1.0',
738
- flags: ['relative']
739
- };
740
- applyUnderlay(underlayOptions);
741
- }
742
-
743
- /**
744
- * applyUnderlay
745
- */
746
-
747
- function applyUnderlay(_ref2) {
748
- var publicId = _ref2.publicId,
749
- type = _ref2.type,
750
- position$1 = _ref2.position,
751
- _ref2$effects = _ref2.effects,
752
- layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
753
- _ref2$flags = _ref2.flags,
754
- flags$1 = _ref2$flags === void 0 ? [] : _ref2$flags,
755
- options = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
756
- var hasPublicId = typeof publicId === 'string';
757
- var hasPosition = typeof position$1 === 'object';
758
- if (!hasPublicId) {
759
- console.warn("An " + type + " is missing a Public ID");
760
- return;
761
- }
762
-
763
- // Start to construct the transformation string using text or the public ID
764
- // if it's image-based
765
-
766
- var layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
767
-
768
- // Begin organizing transformations based on what it is and the location
769
- // it needs to be placed in the URL
770
-
771
- var primary$1 = [];
772
- var applied = [];
773
-
774
- // Gemeral options
775
-
776
- Object.keys(options).forEach(function (key) {
777
- if (!primary[key]) return;
778
- var qualifier = primary[key].qualifier;
779
- primary$1.push(qualifier + "_" + options[key]);
780
- });
781
-
782
- // Layer effects
783
-
784
- layerEffects.forEach(function (effect) {
785
- Object.keys(effect).forEach(function (key) {
786
- if (!primary[key]) return;
787
- var qualifier = primary[key].qualifier;
788
- primary$1.push(qualifier + "_" + effect[key]);
789
- });
790
- });
791
-
792
- // Positioning
793
-
794
- if (hasPosition) {
795
- Object.keys(position$1).forEach(function (key) {
796
- if (!position[key]) return;
797
- var qualifier = position[key].qualifier;
798
- applied.push(qualifier + "_" + position$1[key]);
799
- });
800
- }
801
-
802
- // Positioning
803
-
804
- flags$1.forEach(function (key) {
805
- if (!flags[key]) return;
806
- var _qualifiersFlags$key = flags[key],
807
- qualifier = _qualifiersFlags$key.qualifier,
808
- prefix = _qualifiersFlags$key.prefix;
809
- primary$1.push(prefix + "_" + qualifier);
810
- });
811
-
812
- // Add all primary transformations
813
-
814
- layerTransformation = layerTransformation + "," + primary$1.join(',');
815
-
816
- // Add all applied transformations
817
-
818
- layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
819
- if (applied.length > 0) {
820
- layerTransformation = layerTransformation + "," + applied.join(',');
821
- }
822
-
823
- // Finally add it to the image
824
-
825
- cldImage.addTransformation(layerTransformation);
826
- }
827
- }
828
-
829
- var underlaysPlugin = {
830
- __proto__: null,
831
- props: props$1,
832
- plugin: plugin$1
833
- };
834
-
835
- var props = ['zoompan'];
836
- function plugin(_temp) {
837
- var _ref = _temp === void 0 ? {} : _temp,
838
- cldImage = _ref.cldImage,
839
- options = _ref.options;
840
- var _options$zoompan = options.zoompan,
841
- zoompan = _options$zoompan === void 0 ? false : _options$zoompan;
842
- var overrides = {};
843
- if (zoompan === true) {
844
- cldImage.effect('e_zoompan');
845
- } else if (typeof zoompan === 'string') {
846
- if (zoompan === 'loop') {
847
- cldImage.effect('e_zoompan');
848
- cldImage.effect('e_loop');
849
- } else {
850
- cldImage.effect("e_zoompan:" + zoompan);
851
- }
852
- } else if (typeof zoompan === 'object') {
853
- var zoompanEffect = 'e_zoompan';
854
- if (typeof zoompan.options === 'string') {
855
- zoompanEffect = "" + zoompanEffect + zoompan.options;
856
- }
857
- cldImage.effect(zoompanEffect);
858
- var loopEffect;
859
- if (zoompan.loop === true) {
860
- loopEffect = 'e_loop';
861
- } else if (typeof zoompan.loop === 'string') {
862
- loopEffect = "e_loop" + zoompan.loop;
863
- }
864
- if (loopEffect) {
865
- cldImage.effect(loopEffect);
866
- }
867
- }
868
- if (zoompan !== false) {
869
- overrides.format = 'gif';
870
- }
871
- return {
872
- options: overrides
873
- };
874
- }
875
-
876
- var zoompanPlugin = {
877
- __proto__: null,
878
- props: props,
879
- plugin: plugin
880
- };
881
-
882
- var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
883
-
884
44
  var name = "next-cloudinary";
885
- var version = "1.12.3";
45
+ var version = "2.0.1";
886
46
  var main = "dist/next-cloudinary.umd.js";
887
47
  var module$1 = "dist/next-cloudinary.module.js";
888
48
  var source = "src/index.ts";
@@ -894,6 +54,8 @@ var scripts = {
894
54
  test: "jest"
895
55
  };
896
56
  var dependencies = {
57
+ "@cloudinary-util/url-loader": "^1.2.4",
58
+ "@cloudinary-util/util": "^1.2.0",
897
59
  "@cloudinary/url-gen": "^1.8.6"
898
60
  };
899
61
  var devDependencies = {
@@ -925,6 +87,14 @@ var pkg = {
925
87
  peerDependencies: peerDependencies
926
88
  };
927
89
 
90
+ var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
91
+ var NEXT_CLOUDINARY_VERSION = pkg.version;
92
+ var NEXT_VERSION = nextPkg__default["default"].version;
93
+
94
+ /**
95
+ * createPlaceholderUrl
96
+ */
97
+
928
98
  /**
929
99
  * pollForProcessingImage
930
100
  */
@@ -977,95 +147,10 @@ var pollForProcessingImage = function pollForProcessingImage(options) {
977
147
  return Promise.reject(e);
978
148
  }
979
149
  };
980
- var transformationPlugins = [
981
- // Background Removal must always come first
982
- removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, namedTransformationsPlugin, underlaysPlugin, zoompanPlugin,
983
- // Raw transformations needs to be last simply to make sure
984
- // it's always expected to applied the same way
985
- rawTransformationsPlugin];
986
- var cld;
987
- /**
988
- * constructCloudinaryUrl
989
- */
990
- function constructCloudinaryUrl(_ref) {
991
- var options = _ref.options,
992
- config = _ref.config;
993
- if (!cld) {
994
- cld = new urlGen.Cloudinary(_extends({
995
- cloud: {
996
- cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
997
- }
998
- }, config));
999
- }
1000
- var publicId = getPublicId(options == null ? void 0 : options.src);
1001
- var cldImage = cld.image(publicId);
1002
- transformationPlugins.forEach(function (_ref2) {
1003
- var plugin = _ref2.plugin;
1004
- // @ts-ignore
1005
- var _ref3 = plugin({
1006
- cldImage: cldImage,
1007
- options: options
1008
- }) || {},
1009
- pluginOptions = _ref3.options;
1010
- if (pluginOptions != null && pluginOptions.format && options) {
1011
- options.format = pluginOptions.format;
1012
- }
1013
- if (pluginOptions != null && pluginOptions.width && options) {
1014
- options.resize = {
1015
- width: pluginOptions == null ? void 0 : pluginOptions.width
1016
- };
1017
- }
1018
- });
1019
- if (options != null && options.resize) {
1020
- var _options$resize = options.resize,
1021
- width = _options$resize.width,
1022
- _options$resize$crop = _options$resize.crop,
1023
- crop = _options$resize$crop === void 0 ? 'scale' : _options$resize$crop;
1024
- cldImage.effect("c_" + crop + ",w_" + width);
1025
- }
1026
- return cldImage.setDeliveryType((options == null ? void 0 : options.deliveryType) || 'upload').format((options == null ? void 0 : options.format) || 'auto').delivery("q_" + ((options == null ? void 0 : options.quality) || 'auto')).toURL({
1027
- trackedAnalytics: {
1028
- sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
1029
- sdkSemver: pkg.version,
1030
- techVersion: nextPkg__default["default"].version
1031
- }
1032
- });
1033
- }
1034
- /**
1035
- * Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
1036
- * If it's recognized that is a url and it's not possible to get the public id, it warns the user.
1037
- *
1038
- * @param {string} src The cloudiary url or public id.
1039
- *
1040
- * @return {string} The images public id
1041
- */
1042
- function getPublicId(src) {
1043
- if (typeof src !== 'string') {
1044
- throw new Error("Invalid src of type " + typeof src);
1045
- }
1046
- if (src.includes('res.cloudinary.com')) {
1047
- var regexWithTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
1048
- var regexWithoutTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
1049
- var withTransformations = src.match(regexWithTransformations);
1050
- var withoutTransformations = src.match(regexWithoutTransformations);
1051
- if (withTransformations) {
1052
- return withTransformations[withTransformations.length - 1];
1053
- } else if (withoutTransformations) {
1054
- return withoutTransformations[withoutTransformations.length - 1];
1055
- } else {
1056
- console.warn("Not possible to retrieve the publicUrl from " + src + ", make sure it's a valid cloudinary image url.");
1057
- }
1058
- }
1059
- return src;
1060
- }
1061
- /**
1062
- * createPlaceholderUrl
1063
- */
1064
- function createPlaceholderUrl(_ref4) {
1065
- var src = _ref4.src,
1066
- _ref4$placeholder = _ref4.placeholder,
1067
- placeholder = _ref4$placeholder === void 0 ? true : _ref4$placeholder,
1068
- config = _ref4.config;
150
+ function createPlaceholderUrl(_ref) {
151
+ var src = _ref.src,
152
+ _ref$placeholder = _ref.placeholder,
153
+ placeholder = _ref$placeholder === void 0 ? true : _ref$placeholder;
1069
154
  var rawTransformations = [];
1070
155
  if (placeholder === 'grayscale') {
1071
156
  rawTransformations.push('e_grayscale');
@@ -1075,14 +160,24 @@ function createPlaceholderUrl(_ref4) {
1075
160
  rawTransformations.push('e_grayscale');
1076
161
  rawTransformations.push("e_colorize:60,co_" + color);
1077
162
  }
1078
- return constructCloudinaryUrl({
163
+ return urlLoader.constructCloudinaryUrl({
1079
164
  options: {
1080
165
  src: src,
1081
166
  width: 100,
1082
167
  quality: 1,
1083
168
  rawTransformations: rawTransformations
1084
169
  },
1085
- config: config
170
+ config: {
171
+ cloud: {
172
+ cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
173
+ }
174
+ },
175
+ analytics: {
176
+ sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
177
+ sdkSemver: NEXT_CLOUDINARY_VERSION,
178
+ techVersion: NEXT_VERSION,
179
+ feature: ''
180
+ }
1086
181
  });
1087
182
  }
1088
183
 
@@ -1106,9 +201,19 @@ function cloudinaryLoader(_ref) {
1106
201
  options.widthResize = loaderOptions.width;
1107
202
  options.heightResize = Math.round(options.height * multiplier);
1108
203
  }
1109
- return constructCloudinaryUrl({
204
+ return urlLoader.constructCloudinaryUrl({
1110
205
  options: options,
1111
- config: cldConfig
206
+ config: _extends({
207
+ cloud: {
208
+ cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
209
+ }
210
+ }, cldConfig),
211
+ analytics: {
212
+ sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
213
+ sdkSemver: NEXT_CLOUDINARY_VERSION,
214
+ techVersion: NEXT_VERSION,
215
+ feature: ''
216
+ }
1112
217
  });
1113
218
  }
1114
219
 
@@ -1129,8 +234,8 @@ var CldImage = function CldImage(props) {
1129
234
  return Promise.reject(e);
1130
235
  }
1131
236
  };
1132
- var CLD_OPTIONS = ['deliveryType'];
1133
- transformationPlugins.forEach(function (_ref) {
237
+ var CLD_OPTIONS = ['deliveryType', 'preserveTransformations'];
238
+ urlLoader.transformationPlugins.forEach(function (_ref) {
1134
239
  var _ref$props = _ref.props,
1135
240
  props = _ref$props === void 0 ? [] : _ref$props;
1136
241
  props.forEach(function (prop) {
@@ -1140,7 +245,6 @@ var CldImage = function CldImage(props) {
1140
245
  CLD_OPTIONS.push(prop);
1141
246
  });
1142
247
  });
1143
- // Construct the base Image component props by filtering out Cloudinary-specific props
1144
248
  var imageProps = {
1145
249
  alt: props.alt,
1146
250
  src: props.src
@@ -1156,11 +260,10 @@ var CldImage = function CldImage(props) {
1156
260
  var _useState = react.useState(defaultImgKey),
1157
261
  imgKey = _useState[0],
1158
262
  setImgKey = _useState[1];
1159
- // Construct Cloudinary-specific props by looking for values for any of the supported prop keys
1160
263
  var cldOptions = {};
1161
264
  CLD_OPTIONS.forEach(function (key) {
1162
265
  if (props[key]) {
1163
- cldOptions[key] = props[key];
266
+ cldOptions[key] = props[key] || undefined;
1164
267
  }
1165
268
  });
1166
269
  // If we see a placeholder option, configure a Cloudinary-based URL.
@@ -1172,7 +275,15 @@ var CldImage = function CldImage(props) {
1172
275
  //
1173
276
  // https://nextjs.org/docs/api-reference/next/image#blurdataurl
1174
277
  if (imageProps.placeholder) {
1175
- var publicId = getPublicId(props.src);
278
+ var publicId;
279
+ if (props.src.startsWith('https://')) {
280
+ try {
281
+ publicId = util.getPublicId(props.src);
282
+ } catch (e) {}
283
+ }
284
+ if (!publicId) {
285
+ publicId = props.src;
286
+ }
1176
287
  imageProps.blurDataURL = createPlaceholderUrl({
1177
288
  src: publicId,
1178
289
  placeholder: props.placeholder
@@ -1181,10 +292,16 @@ var CldImage = function CldImage(props) {
1181
292
  imageProps.placeholder = 'blur';
1182
293
  }
1183
294
  }
1184
- if (props.src && props.preserveTransformations) {
1185
- var transformations = getTransformations(props.src, props.preserveTransformations);
1186
- var rawTransformations = imageProps.rawTransformations ? [].concat(imageProps.rawTransformations) : [];
1187
- imageProps.rawTransformations = [].concat(rawTransformations, transformations);
295
+ // Try to preserve the original transformations from the Cloudinary URL passed in
296
+ // to the component. This only works if the URL has a version number on it and otherwise
297
+ // will fail to load
298
+ if (props.preserveTransformations) {
299
+ try {
300
+ var transformations = util.getTransformations(props.src);
301
+ cldOptions.rawTransformations = [].concat(transformations.flat(), props.rawTransformations || []);
302
+ } catch (e) {
303
+ console.warn("Failed to preserve transformations: " + e.message);
304
+ }
1188
305
  }
1189
306
  return /*#__PURE__*/jsxRuntime.jsx(Image__default["default"], _extends({}, imageProps, {
1190
307
  loader: function loader(loaderOptions) {
@@ -1208,14 +325,26 @@ var CldOgImage = function CldOgImage(_ref) {
1208
325
  twitterTitle = _ref.twitterTitle,
1209
326
  props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
1210
327
  var options = _extends({}, props, {
1211
- width: props.width || IMAGE_WIDTH,
1212
- height: props.height || IMAGE_HEIGHT,
328
+ alt: props.alt,
1213
329
  crop: props.crop || 'fill',
1214
330
  gravity: props.gravity || 'center',
1215
- alt: props.alt
331
+ height: props.height || IMAGE_HEIGHT,
332
+ src: props.src,
333
+ width: props.width || IMAGE_WIDTH
1216
334
  });
1217
- var ogImageUrl = constructCloudinaryUrl({
1218
- options: options
335
+ var ogImageUrl = urlLoader.constructCloudinaryUrl({
336
+ options: options,
337
+ config: {
338
+ cloud: {
339
+ cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
340
+ }
341
+ },
342
+ analytics: {
343
+ sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
344
+ sdkSemver: NEXT_CLOUDINARY_VERSION,
345
+ techVersion: NEXT_VERSION,
346
+ feature: ''
347
+ }
1219
348
  });
1220
349
  // We need to include the tags within the Next.js Head component rather than
1221
350
  // direcly adding them inside of the Head otherwise we get unexpected results
@@ -1385,9 +514,4 @@ exports.CldOgImage = CldOgImage;
1385
514
  exports.CldUploadButton = CldUploadButton;
1386
515
  exports.CldUploadWidget = CldUploadWidget;
1387
516
  exports.cloudinaryLoader = cloudinaryLoader;
1388
- exports.constructCloudinaryUrl = constructCloudinaryUrl;
1389
- exports.effects = effects;
1390
- exports.position = position;
1391
- exports.primary = primary;
1392
- exports.text = text;
1393
517
  //# sourceMappingURL=next-cloudinary.js.map