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