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,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('next/image'), require('@cloudinary/url-gen'), require('next/package.json'), require('react/jsx-runtime'), require('next/head'), require('next/script')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', 'next/image', '@cloudinary/url-gen', 'next/package.json', 'react/jsx-runtime', 'next/head', 'next/script'], factory) :
4
- (global = global || self, factory(global.nextCloudinary = {}, global.react, global.Image, global.urlGen, global.nextPkg, global.jsxRuntime, global.Head, global.Script));
5
- })(this, (function (exports, react, Image, urlGen, nextPkg, jsxRuntime, Head, Script) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('next/image'), require('@cloudinary-util/util'), require('@cloudinary-util/url-loader'), require('next/package.json'), require('react/jsx-runtime'), require('next/head'), require('next/script')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'next/image', '@cloudinary-util/util', '@cloudinary-util/url-loader', 'next/package.json', 'react/jsx-runtime', 'next/head', 'next/script'], factory) :
4
+ (global = global || self, factory(global.nextCloudinary = {}, global.react, global.Image, global.util, global.urlLoader, global.nextPkg, global.jsxRuntime, global.Head, global.Script));
5
+ })(this, (function (exports, react, Image, util, urlLoader, nextPkg, jsxRuntime, Head, Script) {
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
8
8
  var Image__default = /*#__PURE__*/_interopDefaultLegacy(Image);
@@ -37,846 +37,8 @@
37
37
  return target;
38
38
  }
39
39
 
40
- var cropsGravityAuto = ['crop', 'fill', 'lfill', 'fill_pad', 'thumb'];
41
- var cropsWithZoom = ['crop', 'thumb'];
42
- var props$7 = ['crop', 'gravity', 'zoom'];
43
- function plugin$7(_temp) {
44
- var _ref = _temp === void 0 ? {} : _temp,
45
- cldImage = _ref.cldImage,
46
- options = _ref.options;
47
- var overrides = {};
48
- var width = options.width,
49
- height = options.height,
50
- widthResize = options.widthResize,
51
- _options$crop = options.crop,
52
- crop = _options$crop === void 0 ? 'limit' : _options$crop;
53
- var transformationString = "c_" + crop + ",w_" + width;
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
- var 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
- var 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
- var 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
- var 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
- var flags = {
344
- relative: {
345
- prefix: 'fl',
346
- qualifier: 'relative',
347
- location: 'primary'
348
- }
349
- };
350
-
351
- /**
352
- * constructTransformation
353
- */
354
-
355
- function constructTransformation(_ref) {
356
- var prefix = _ref.prefix,
357
- qualifier = _ref.qualifier,
358
- value = _ref.value;
359
- var transformation = '';
360
- if (prefix) {
361
- transformation = prefix + "_";
362
- }
363
- if (value === true || value === 'true') {
364
- return "" + transformation + qualifier;
365
- }
366
- if (typeof value === 'string' || typeof value === 'number') {
367
- if (prefix) {
368
- return "" + transformation + qualifier + ":" + value;
369
- } else {
370
- return qualifier + "_" + value;
371
- }
372
- }
373
- }
374
-
375
- /**
376
- * Retrieves the transformations added to a cloudiary image url. If no transformation is recognized it returns an empty array.
377
- *
378
- * @param {string} src The cloudiary url.
379
- *
380
- * @return {array} The array of transformations
381
- */
382
-
383
- function getTransformations(src, preserveTransformations) {
384
- if (typeof src !== "string") {
385
- throw new Error("Invalid src of type " + typeof src);
386
- }
387
- if (src.includes("res.cloudinary.com") && preserveTransformations) {
388
- var regex = new RegExp("(https?)://(res.cloudinary.com)/([^/]+)/(image|video|raw)/(upload|authenticated)/(.*)/(v[0-9]+)/(.+)(?:.[a-z]{3})?", "gi");
389
- var groups = regex.exec(src);
390
- var transformationStr = groups.slice(1).find(function (i) {
391
- return i.includes("_");
392
- });
393
- if (transformationStr) {
394
- return transformationStr.split(",").join("/").split("/");
395
- } else {
396
- return [];
397
- }
398
- }
399
- return [];
400
- }
401
-
402
- var props$6 = [].concat(Object.keys(effects), ['effects']);
403
- function plugin$6(_temp) {
404
- var _ref = _temp === void 0 ? {} : _temp,
405
- cldImage = _ref.cldImage,
406
- options = _ref.options;
407
- // Handle any top-level effect props
408
-
409
- constructTransformationString({
410
- effects: effects,
411
- options: options
412
- }).filter(function (t) {
413
- return !!t;
414
- }).forEach(function (transformation) {
415
- return cldImage.effect(transformation);
416
- });
417
-
418
- // If we're passing in an effects prop explicitly, treat it as an array of
419
- // effects that we need to process
420
-
421
- if (Array.isArray(options.effects)) {
422
- options.effects.forEach(function (effectsSet) {
423
- var transformationString = constructTransformationString({
424
- effects: effects,
425
- options: effectsSet
426
- }).filter(function (t) {
427
- return !!t;
428
- }).join(',');
429
- cldImage.effect(transformationString);
430
- });
431
- }
432
- function constructTransformationString(_ref2) {
433
- var effects = _ref2.effects,
434
- options = _ref2.options;
435
- return Object.keys(effects).map(function (key) {
436
- var _effects$key = effects[key],
437
- prefix = _effects$key.prefix,
438
- qualifier = _effects$key.qualifier;
439
- return constructTransformation({
440
- qualifier: qualifier,
441
- prefix: prefix,
442
- value: options[key]
443
- });
444
- });
445
- }
446
- }
447
-
448
- var effectsPlugin = {
449
- __proto__: null,
450
- props: props$6,
451
- plugin: plugin$6
452
- };
453
-
454
- /**
455
- * encodeBase64
456
- */
457
-
458
- function encodeBase64(value) {
459
- if (typeof btoa === 'function') {
460
- return btoa(value);
461
- }
462
- if (typeof Buffer !== 'undefined') {
463
- return Buffer.from(value).toString('base64');
464
- }
465
- }
466
-
467
- var _excluded$3 = ["publicId", "url", "position", "text", "effects", "appliedEffects"];
468
- var props$5 = ['text', 'overlays'];
469
- var DEFAULT_TEXT_OPTIONS = {
470
- color: 'black',
471
- fontFamily: 'Arial',
472
- fontSize: 200,
473
- fontWeight: 'bold'
474
- };
475
- function plugin$5(_temp) {
476
- var _ref = _temp === void 0 ? {} : _temp,
477
- cldImage = _ref.cldImage,
478
- options = _ref.options;
479
- var text$1 = options.text,
480
- _options$overlays = options.overlays,
481
- overlays = _options$overlays === void 0 ? [] : _options$overlays;
482
- var type = 'overlay';
483
- var typeQualifier = 'l';
484
- if (Array.isArray(overlays)) {
485
- overlays.forEach(applyOverlay);
486
- }
487
- if (typeof text$1 === 'string') {
488
- applyOverlay({
489
- text: _extends({}, DEFAULT_TEXT_OPTIONS, {
490
- text: text$1
491
- })
492
- });
493
- } else if (typeof text$1 === 'object') {
494
- applyOverlay({
495
- text: _extends({}, DEFAULT_TEXT_OPTIONS, text$1)
496
- });
497
- }
498
-
499
- /**
500
- * applyOverlay
501
- */
502
-
503
- function applyOverlay(_ref2) {
504
- var publicId = _ref2.publicId,
505
- url = _ref2.url,
506
- position$1 = _ref2.position,
507
- text$1 = _ref2.text,
508
- _ref2$effects = _ref2.effects,
509
- layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
510
- _ref2$appliedEffects = _ref2.appliedEffects,
511
- appliedEffects = _ref2$appliedEffects === void 0 ? [] : _ref2$appliedEffects,
512
- options = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
513
- var hasPublicId = typeof publicId === 'string';
514
- var hasUrl = typeof url === 'string';
515
- var hasText = typeof text$1 === 'object' || typeof text$1 === 'string';
516
- var hasPosition = typeof position$1 === 'object';
517
- if (!hasPublicId && !hasUrl && !hasText) {
518
- console.warn("An " + type + " is missing Public ID, URL, or Text");
519
- return;
520
- }
521
-
522
- // Start to construct the transformation string using text or the public ID
523
- // if it's image-based
524
-
525
- var layerTransformation;
526
- if (hasText) {
527
- layerTransformation = typeQualifier + "_text";
528
- } else if (hasPublicId) {
529
- layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
530
- } else if (hasUrl) {
531
- layerTransformation = typeQualifier + "_fetch:" + encodeBase64(url);
532
- }
533
-
534
- // Begin organizing transformations based on what it is and the location
535
- // it needs to be placed in the URL
536
-
537
- var primary$1 = [];
538
- var applied = [];
539
-
540
- // Gemeral options
541
-
542
- Object.keys(options).forEach(function (key) {
543
- if (!primary[key]) return;
544
- var qualifier = primary[key].qualifier;
545
- var transformation = constructTransformation({
546
- qualifier: qualifier,
547
- value: options[key]
548
- });
549
- primary$1.push(transformation);
550
- });
551
-
552
- // Layer effects
553
- // For layer effects we allow both the standard effects to be applied as well
554
- // as the primary ones like width and height as those can be used to modify
555
- // the layer after it's created
556
-
557
- layerEffects.forEach(function (effect) {
558
- Object.keys(effect).forEach(function (key) {
559
- var _ref3 = primary[key] || effects[key] || {},
560
- qualifier = _ref3.qualifier,
561
- prefix = _ref3.prefix;
562
- var transformation = constructTransformation({
563
- qualifier: qualifier,
564
- prefix: prefix,
565
- value: effect[key]
566
- });
567
- primary$1.push(transformation);
568
- });
569
- });
570
-
571
- // Applied Layer effects
572
- // Similar to layer effects but they get appended to an additional transformation
573
- // along with fl_layer_applied
574
-
575
- appliedEffects.forEach(function (effect) {
576
- Object.keys(effect).forEach(function (key) {
577
- var _ref4 = primary[key] || effects[key] || {},
578
- qualifier = _ref4.qualifier,
579
- prefix = _ref4.prefix;
580
- var transformation = constructTransformation({
581
- qualifier: qualifier,
582
- prefix: 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
- var textTransformations = [];
598
- Object.keys(text$1).forEach(function (key) {
599
- if (!text[key]) return;
600
- var _qualifiersText$key = text[key],
601
- qualifier = _qualifiersText$key.qualifier,
602
- location = _qualifiersText$key.location;
603
- if (location === 'primary') {
604
- primary$1.push(qualifier + "_" + text$1[key]);
605
- } else if (qualifier === 'self') {
606
- textTransformations.push(key);
607
- } else if (qualifier) {
608
- textTransformations.push(qualifier + "_" + text$1[key]);
609
- } else {
610
- textTransformations.push(text$1[key]);
611
- }
612
- });
613
- layerTransformation = layerTransformation + ":" + textTransformations.join('_') + ":" + text$1.text;
614
- }
615
-
616
- // Positioning
617
-
618
- if (hasPosition) {
619
- Object.keys(position$1).forEach(function (key) {
620
- if (!position[key]) return;
621
- var qualifier = position[key].qualifier;
622
- var transformation = constructTransformation({
623
- qualifier: qualifier,
624
- value: position$1[key]
625
- });
626
- applied.push(transformation);
627
- });
628
- }
629
-
630
- // Add all primary transformations
631
-
632
- if (primary$1.length > 0) {
633
- layerTransformation = layerTransformation + "," + primary$1.join(',');
634
- }
635
-
636
- // Add all applied transformations
637
-
638
- layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
639
- if (applied.length > 0) {
640
- layerTransformation = layerTransformation + "," + applied.join(',');
641
- }
642
-
643
- // Finally add it to the image
644
-
645
- cldImage.addTransformation(layerTransformation);
646
- }
647
- }
648
-
649
- var overlaysPlugin = {
650
- __proto__: null,
651
- props: props$5,
652
- DEFAULT_TEXT_OPTIONS: DEFAULT_TEXT_OPTIONS,
653
- plugin: plugin$5
654
- };
655
-
656
- var props$4 = ['transformations'];
657
- function plugin$4(_temp) {
658
- var _ref = _temp === void 0 ? {} : _temp,
659
- cldImage = _ref.cldImage,
660
- options = _ref.options;
661
- var _options$transformati = options.transformations,
662
- transformations = _options$transformati === void 0 ? [] : _options$transformati;
663
- if (!Array.isArray(transformations)) {
664
- transformations = [transformations];
665
- }
666
- transformations.forEach(function (transformation) {
667
- cldImage.addTransformation("t_" + transformation);
668
- });
669
- }
670
-
671
- var namedTransformationsPlugin = {
672
- __proto__: null,
673
- props: props$4,
674
- plugin: plugin$4
675
- };
676
-
677
- var props$3 = ['rawTransformations'];
678
- function plugin$3(_temp) {
679
- var _ref = _temp === void 0 ? {} : _temp,
680
- cldImage = _ref.cldImage,
681
- options = _ref.options;
682
- var _options$rawTransform = options.rawTransformations,
683
- rawTransformations = _options$rawTransform === void 0 ? [] : _options$rawTransform;
684
- rawTransformations.forEach(function (transformation) {
685
- cldImage.addTransformation(transformation);
686
- });
687
- }
688
-
689
- var rawTransformationsPlugin = {
690
- __proto__: null,
691
- props: props$3,
692
- plugin: plugin$3
693
- };
694
-
695
- var props$2 = ['removeBackground'];
696
- function plugin$2(_temp) {
697
- var _ref = _temp === void 0 ? {} : _temp,
698
- cldImage = _ref.cldImage,
699
- options = _ref.options;
700
- var _options$removeBackgr = options.removeBackground,
701
- removeBackground = _options$removeBackgr === void 0 ? false : _options$removeBackgr;
702
- if (removeBackground) {
703
- cldImage.effect('e_background_removal');
704
- }
705
- }
706
-
707
- var removeBackgroundPlugin = {
708
- __proto__: null,
709
- props: props$2,
710
- plugin: plugin$2
711
- };
712
-
713
- var _excluded$2 = ["publicId", "type", "position", "text", "effects", "flags"];
714
- var props$1 = ['underlay', 'underlays'];
715
- function plugin$1(_temp) {
716
- var _ref = _temp === void 0 ? {} : _temp,
717
- cldImage = _ref.cldImage,
718
- options = _ref.options;
719
- var underlay = options.underlay,
720
- _options$underlays = options.underlays,
721
- underlays = _options$underlays === void 0 ? [] : _options$underlays;
722
- var typeQualifier = 'u';
723
- if (Array.isArray(underlays)) {
724
- underlays.forEach(applyUnderlay);
725
- }
726
- if (typeof underlay === 'string') {
727
- var underlayOptions = {
728
- publicId: underlay,
729
- crop: 'fill',
730
- width: '1.0',
731
- height: '1.0',
732
- flags: ['relative']
733
- };
734
- applyUnderlay(underlayOptions);
735
- }
736
-
737
- /**
738
- * applyUnderlay
739
- */
740
-
741
- function applyUnderlay(_ref2) {
742
- var publicId = _ref2.publicId,
743
- type = _ref2.type,
744
- position$1 = _ref2.position,
745
- _ref2$effects = _ref2.effects,
746
- layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
747
- _ref2$flags = _ref2.flags,
748
- flags$1 = _ref2$flags === void 0 ? [] : _ref2$flags,
749
- options = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
750
- var hasPublicId = typeof publicId === 'string';
751
- var hasPosition = typeof position$1 === 'object';
752
- if (!hasPublicId) {
753
- console.warn("An " + type + " is missing a Public ID");
754
- return;
755
- }
756
-
757
- // Start to construct the transformation string using text or the public ID
758
- // if it's image-based
759
-
760
- var layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
761
-
762
- // Begin organizing transformations based on what it is and the location
763
- // it needs to be placed in the URL
764
-
765
- var primary$1 = [];
766
- var applied = [];
767
-
768
- // Gemeral options
769
-
770
- Object.keys(options).forEach(function (key) {
771
- if (!primary[key]) return;
772
- var qualifier = primary[key].qualifier;
773
- primary$1.push(qualifier + "_" + options[key]);
774
- });
775
-
776
- // Layer effects
777
-
778
- layerEffects.forEach(function (effect) {
779
- Object.keys(effect).forEach(function (key) {
780
- if (!primary[key]) return;
781
- var qualifier = primary[key].qualifier;
782
- primary$1.push(qualifier + "_" + effect[key]);
783
- });
784
- });
785
-
786
- // Positioning
787
-
788
- if (hasPosition) {
789
- Object.keys(position$1).forEach(function (key) {
790
- if (!position[key]) return;
791
- var qualifier = position[key].qualifier;
792
- applied.push(qualifier + "_" + position$1[key]);
793
- });
794
- }
795
-
796
- // Positioning
797
-
798
- flags$1.forEach(function (key) {
799
- if (!flags[key]) return;
800
- var _qualifiersFlags$key = flags[key],
801
- qualifier = _qualifiersFlags$key.qualifier,
802
- prefix = _qualifiersFlags$key.prefix;
803
- primary$1.push(prefix + "_" + qualifier);
804
- });
805
-
806
- // Add all primary transformations
807
-
808
- layerTransformation = layerTransformation + "," + primary$1.join(',');
809
-
810
- // Add all applied transformations
811
-
812
- layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
813
- if (applied.length > 0) {
814
- layerTransformation = layerTransformation + "," + applied.join(',');
815
- }
816
-
817
- // Finally add it to the image
818
-
819
- cldImage.addTransformation(layerTransformation);
820
- }
821
- }
822
-
823
- var underlaysPlugin = {
824
- __proto__: null,
825
- props: props$1,
826
- plugin: plugin$1
827
- };
828
-
829
- var props = ['zoompan'];
830
- function plugin(_temp) {
831
- var _ref = _temp === void 0 ? {} : _temp,
832
- cldImage = _ref.cldImage,
833
- options = _ref.options;
834
- var _options$zoompan = options.zoompan,
835
- zoompan = _options$zoompan === void 0 ? false : _options$zoompan;
836
- var overrides = {};
837
- if (zoompan === true) {
838
- cldImage.effect('e_zoompan');
839
- } else if (typeof zoompan === 'string') {
840
- if (zoompan === 'loop') {
841
- cldImage.effect('e_zoompan');
842
- cldImage.effect('e_loop');
843
- } else {
844
- cldImage.effect("e_zoompan:" + zoompan);
845
- }
846
- } else if (typeof zoompan === 'object') {
847
- var zoompanEffect = 'e_zoompan';
848
- if (typeof zoompan.options === 'string') {
849
- zoompanEffect = "" + zoompanEffect + zoompan.options;
850
- }
851
- cldImage.effect(zoompanEffect);
852
- var loopEffect;
853
- if (zoompan.loop === true) {
854
- loopEffect = 'e_loop';
855
- } else if (typeof zoompan.loop === 'string') {
856
- loopEffect = "e_loop" + zoompan.loop;
857
- }
858
- if (loopEffect) {
859
- cldImage.effect(loopEffect);
860
- }
861
- }
862
- if (zoompan !== false) {
863
- overrides.format = 'gif';
864
- }
865
- return {
866
- options: overrides
867
- };
868
- }
869
-
870
- var zoompanPlugin = {
871
- __proto__: null,
872
- props: props,
873
- plugin: plugin
874
- };
875
-
876
- var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
877
-
878
40
  var name = "next-cloudinary";
879
- var version = "1.12.2";
41
+ var version = "2.0.0";
880
42
  var main = "dist/next-cloudinary.umd.js";
881
43
  var module = "dist/next-cloudinary.module.js";
882
44
  var source = "src/index.ts";
@@ -888,6 +50,8 @@
888
50
  test: "jest"
889
51
  };
890
52
  var dependencies = {
53
+ "@cloudinary-util/url-loader": "^1.2.4",
54
+ "@cloudinary-util/util": "^1.1.1",
891
55
  "@cloudinary/url-gen": "^1.8.6"
892
56
  };
893
57
  var devDependencies = {
@@ -919,6 +83,14 @@
919
83
  peerDependencies: peerDependencies
920
84
  };
921
85
 
86
+ var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
87
+ var NEXT_CLOUDINARY_VERSION = pkg.version;
88
+ var NEXT_VERSION = nextPkg__default["default"].version;
89
+
90
+ /**
91
+ * createPlaceholderUrl
92
+ */
93
+
922
94
  /**
923
95
  * pollForProcessingImage
924
96
  */
@@ -971,95 +143,10 @@
971
143
  return Promise.reject(e);
972
144
  }
973
145
  };
974
- var transformationPlugins = [
975
- // Background Removal must always come first
976
- removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, namedTransformationsPlugin, underlaysPlugin, zoompanPlugin,
977
- // Raw transformations needs to be last simply to make sure
978
- // it's always expected to applied the same way
979
- rawTransformationsPlugin];
980
- var cld;
981
- /**
982
- * constructCloudinaryUrl
983
- */
984
- function constructCloudinaryUrl(_ref) {
985
- var options = _ref.options,
986
- config = _ref.config;
987
- if (!cld) {
988
- cld = new urlGen.Cloudinary(_extends({
989
- cloud: {
990
- cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
991
- }
992
- }, config));
993
- }
994
- var publicId = getPublicId(options == null ? void 0 : options.src);
995
- var cldImage = cld.image(publicId);
996
- transformationPlugins.forEach(function (_ref2) {
997
- var plugin = _ref2.plugin;
998
- // @ts-ignore
999
- var _ref3 = plugin({
1000
- cldImage: cldImage,
1001
- options: options
1002
- }) || {},
1003
- pluginOptions = _ref3.options;
1004
- if (pluginOptions != null && pluginOptions.format && options) {
1005
- options.format = pluginOptions.format;
1006
- }
1007
- if (pluginOptions != null && pluginOptions.width && options) {
1008
- options.resize = {
1009
- width: pluginOptions == null ? void 0 : pluginOptions.width
1010
- };
1011
- }
1012
- });
1013
- if (options != null && options.resize) {
1014
- var _options$resize = options.resize,
1015
- width = _options$resize.width,
1016
- _options$resize$crop = _options$resize.crop,
1017
- crop = _options$resize$crop === void 0 ? 'scale' : _options$resize$crop;
1018
- cldImage.effect("c_" + crop + ",w_" + width);
1019
- }
1020
- 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({
1021
- trackedAnalytics: {
1022
- sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
1023
- sdkSemver: pkg.version,
1024
- techVersion: nextPkg__default["default"].version
1025
- }
1026
- });
1027
- }
1028
- /**
1029
- * Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
1030
- * If it's recognized that is a url and it's not possible to get the public id, it warns the user.
1031
- *
1032
- * @param {string} src The cloudiary url or public id.
1033
- *
1034
- * @return {string} The images public id
1035
- */
1036
- function getPublicId(src) {
1037
- if (typeof src !== 'string') {
1038
- throw new Error("Invalid src of type " + typeof src);
1039
- }
1040
- if (src.includes('res.cloudinary.com')) {
1041
- var regexWithTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
1042
- var regexWithoutTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
1043
- var withTransformations = src.match(regexWithTransformations);
1044
- var withoutTransformations = src.match(regexWithoutTransformations);
1045
- if (withTransformations) {
1046
- return withTransformations[withTransformations.length - 1];
1047
- } else if (withoutTransformations) {
1048
- return withoutTransformations[withoutTransformations.length - 1];
1049
- } else {
1050
- console.warn("Not possible to retrieve the publicUrl from " + src + ", make sure it's a valid cloudinary image url.");
1051
- }
1052
- }
1053
- return src;
1054
- }
1055
- /**
1056
- * createPlaceholderUrl
1057
- */
1058
- function createPlaceholderUrl(_ref4) {
1059
- var src = _ref4.src,
1060
- _ref4$placeholder = _ref4.placeholder,
1061
- placeholder = _ref4$placeholder === void 0 ? true : _ref4$placeholder,
1062
- config = _ref4.config;
146
+ function createPlaceholderUrl(_ref) {
147
+ var src = _ref.src,
148
+ _ref$placeholder = _ref.placeholder,
149
+ placeholder = _ref$placeholder === void 0 ? true : _ref$placeholder;
1063
150
  var rawTransformations = [];
1064
151
  if (placeholder === 'grayscale') {
1065
152
  rawTransformations.push('e_grayscale');
@@ -1069,14 +156,24 @@
1069
156
  rawTransformations.push('e_grayscale');
1070
157
  rawTransformations.push("e_colorize:60,co_" + color);
1071
158
  }
1072
- return constructCloudinaryUrl({
159
+ return urlLoader.constructCloudinaryUrl({
1073
160
  options: {
1074
161
  src: src,
1075
162
  width: 100,
1076
163
  quality: 1,
1077
164
  rawTransformations: rawTransformations
1078
165
  },
1079
- config: config
166
+ config: {
167
+ cloud: {
168
+ cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
169
+ }
170
+ },
171
+ analytics: {
172
+ sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
173
+ sdkSemver: NEXT_CLOUDINARY_VERSION,
174
+ techVersion: NEXT_VERSION,
175
+ feature: ''
176
+ }
1080
177
  });
1081
178
  }
1082
179
 
@@ -1100,9 +197,19 @@
1100
197
  options.widthResize = loaderOptions.width;
1101
198
  options.heightResize = Math.round(options.height * multiplier);
1102
199
  }
1103
- return constructCloudinaryUrl({
200
+ return urlLoader.constructCloudinaryUrl({
1104
201
  options: options,
1105
- config: cldConfig
202
+ config: _extends({
203
+ cloud: {
204
+ cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
205
+ }
206
+ }, cldConfig),
207
+ analytics: {
208
+ sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
209
+ sdkSemver: NEXT_CLOUDINARY_VERSION,
210
+ techVersion: NEXT_VERSION,
211
+ feature: ''
212
+ }
1106
213
  });
1107
214
  }
1108
215
 
@@ -1124,7 +231,7 @@
1124
231
  }
1125
232
  };
1126
233
  var CLD_OPTIONS = ['deliveryType'];
1127
- transformationPlugins.forEach(function (_ref) {
234
+ urlLoader.transformationPlugins.forEach(function (_ref) {
1128
235
  var _ref$props = _ref.props,
1129
236
  props = _ref$props === void 0 ? [] : _ref$props;
1130
237
  props.forEach(function (prop) {
@@ -1166,7 +273,15 @@
1166
273
  //
1167
274
  // https://nextjs.org/docs/api-reference/next/image#blurdataurl
1168
275
  if (imageProps.placeholder) {
1169
- var publicId = getPublicId(props.src);
276
+ var publicId;
277
+ if (props.src.startsWith('https://')) {
278
+ try {
279
+ publicId = util.getPublicId(props.src);
280
+ } catch (e) {}
281
+ }
282
+ if (!publicId) {
283
+ publicId = props.src;
284
+ }
1170
285
  imageProps.blurDataURL = createPlaceholderUrl({
1171
286
  src: publicId,
1172
287
  placeholder: props.placeholder
@@ -1176,7 +291,7 @@
1176
291
  }
1177
292
  }
1178
293
  if (props.src && props.preserveTransformations) {
1179
- var transformations = getTransformations(props.src, props.preserveTransformations);
294
+ var transformations = util.getTransformations(props.src, props.preserveTransformations);
1180
295
  var rawTransformations = imageProps.rawTransformations ? [].concat(imageProps.rawTransformations) : [];
1181
296
  imageProps.rawTransformations = [].concat(rawTransformations, transformations);
1182
297
  }
@@ -1202,14 +317,26 @@
1202
317
  twitterTitle = _ref.twitterTitle,
1203
318
  props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
1204
319
  var options = _extends({}, props, {
1205
- width: props.width || IMAGE_WIDTH,
1206
- height: props.height || IMAGE_HEIGHT,
320
+ alt: props.alt,
1207
321
  crop: props.crop || 'fill',
1208
322
  gravity: props.gravity || 'center',
1209
- alt: props.alt
323
+ height: props.height || IMAGE_HEIGHT,
324
+ src: props.src,
325
+ width: props.width || IMAGE_WIDTH
1210
326
  });
1211
- var ogImageUrl = constructCloudinaryUrl({
1212
- options: options
327
+ var ogImageUrl = urlLoader.constructCloudinaryUrl({
328
+ options: options,
329
+ config: {
330
+ cloud: {
331
+ cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
332
+ }
333
+ },
334
+ analytics: {
335
+ sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
336
+ sdkSemver: NEXT_CLOUDINARY_VERSION,
337
+ techVersion: NEXT_VERSION,
338
+ feature: ''
339
+ }
1213
340
  });
1214
341
  // We need to include the tags within the Next.js Head component rather than
1215
342
  // direcly adding them inside of the Head otherwise we get unexpected results
@@ -1379,11 +506,6 @@
1379
506
  exports.CldUploadButton = CldUploadButton;
1380
507
  exports.CldUploadWidget = CldUploadWidget;
1381
508
  exports.cloudinaryLoader = cloudinaryLoader;
1382
- exports.constructCloudinaryUrl = constructCloudinaryUrl;
1383
- exports.effects = effects;
1384
- exports.position = position;
1385
- exports.primary = primary;
1386
- exports.text = text;
1387
509
 
1388
510
  }));
1389
511
  //# sourceMappingURL=next-cloudinary.umd.js.map