next-cloudinary 0.4.0 → 0.4.1

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