next-cloudinary 1.12.2 → 2.0.0

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