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