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