next-cloudinary 1.3.0 → 1.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.
@@ -1,8 +1,8 @@
1
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) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('next/image'), require('@cloudinary/url-gen'), require('react/jsx-runtime'), require('next/head'), require('next/script')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'next/image', '@cloudinary/url-gen', 'react/jsx-runtime', 'next/head', 'next/script'], factory) :
4
+ (global = global || self, factory(global.nextCloudinary = {}, global.react, global.Image, global.urlGen, global.jsxRuntime, global.Head, global.Script));
5
+ })(this, (function (exports, react, Image, urlGen, 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);
@@ -90,89 +90,6 @@
90
90
  plugin: plugin$7
91
91
  };
92
92
 
93
- var params = ['art', {
94
- prop: 'autoBrightness',
95
- effect: 'auto_brightness'
96
- }, {
97
- prop: 'autoColor',
98
- effect: 'auto_color'
99
- }, {
100
- prop: 'autoContrast',
101
- effect: 'auto_contrast'
102
- }, {
103
- prop: 'assistColorblind',
104
- effect: 'assist_colorblind'
105
- }, 'blackwhite', 'blur', {
106
- prop: 'blurFaces',
107
- effect: 'blur_faces'
108
- }, {
109
- prop: 'blurRegion',
110
- effect: 'blur_region'
111
- }, 'brightness', {
112
- prop: 'brightnessHSB',
113
- effect: 'brightness_hsb'
114
- }, 'cartoonify', 'colorize', 'contrast', 'distort', {
115
- prop: 'fillLight',
116
- effect: 'fill_light'
117
- }, 'gamma', {
118
- prop: 'gradientFade',
119
- effect: 'gradient_fade'
120
- }, 'grayscale', 'improve', 'negate', {
121
- prop: 'oilPaint',
122
- effect: 'oil_paint'
123
- }, 'outline', 'pixelate', {
124
- prop: 'pixelateFaces',
125
- effect: 'pixelate_faces'
126
- }, {
127
- prop: 'pixelateRegion',
128
- effect: 'pixelate_region'
129
- }, 'redeye', {
130
- prop: 'replaceColor',
131
- effect: 'replace_color'
132
- }, 'saturation', 'sepia', 'shadow', 'sharpen', 'shear', {
133
- prop: 'simulateColorblind',
134
- effect: 'simulate_colorblind'
135
- }, 'tint', {
136
- prop: 'unsharpMask',
137
- effect: 'unsharp_mask'
138
- }, 'vectorize', 'vibrance', 'vignette'];
139
- var props$6 = params.map(function (param) {
140
- return param.prop || param;
141
- });
142
- function plugin$6(_temp) {
143
- var _ref = _temp === void 0 ? {} : _temp,
144
- cldImage = _ref.cldImage,
145
- options = _ref.options;
146
- params.forEach(function (key) {
147
- var prop = key.prop || key;
148
- var effect = key.effect || key;
149
- if (options[prop] === true) {
150
- cldImage.effect("e_" + effect);
151
- } else if (typeof options[prop] === 'string') {
152
- cldImage.effect("e_" + effect + ":" + options[prop]);
153
- }
154
- });
155
- }
156
-
157
- var effectsPlugin = {
158
- __proto__: null,
159
- props: props$6,
160
- plugin: plugin$6
161
- };
162
-
163
- /**
164
- * encodeBase64
165
- */
166
-
167
- function encodeBase64(value) {
168
- if (typeof btoa === 'function') {
169
- return btoa(value);
170
- }
171
- if (typeof Buffer !== 'undefined') {
172
- return Buffer.from(value).toString('base64');
173
- }
174
- }
175
-
176
93
  // aspectRatio
177
94
 
178
95
  var primary = {
@@ -240,6 +157,211 @@
240
157
  qualifier: false
241
158
  }
242
159
  };
160
+ var effects = {
161
+ art: {
162
+ prefix: 'e',
163
+ qualifier: 'art'
164
+ },
165
+ autoBrightness: {
166
+ prefix: 'e',
167
+ qualifier: 'auto_brightness'
168
+ },
169
+ autoColor: {
170
+ prefix: 'e',
171
+ qualifier: 'auto_color'
172
+ },
173
+ autoContrast: {
174
+ prefix: 'e',
175
+ qualifier: 'auto_contrast'
176
+ },
177
+ assistColorblind: {
178
+ prefix: 'e',
179
+ qualifier: 'assist_colorblind'
180
+ },
181
+ blackwhite: {
182
+ prefix: 'e',
183
+ qualifier: 'blackwhite'
184
+ },
185
+ blur: {
186
+ prefix: 'e',
187
+ qualifier: 'blur'
188
+ },
189
+ blurFaces: {
190
+ prefix: 'e',
191
+ qualifier: 'blur_faces'
192
+ },
193
+ blurRegion: {
194
+ prefix: 'e',
195
+ qualifier: 'blur_region'
196
+ },
197
+ brightness: {
198
+ prefix: 'e',
199
+ qualifier: 'brightness'
200
+ },
201
+ brightnessHSB: {
202
+ prefix: 'e',
203
+ qualifier: 'brightness_hsb'
204
+ },
205
+ cartoonify: {
206
+ prefix: 'e',
207
+ qualifier: 'cartoonify'
208
+ },
209
+ colorize: {
210
+ prefix: 'e',
211
+ qualifier: 'colorize'
212
+ },
213
+ contrast: {
214
+ prefix: 'e',
215
+ qualifier: 'contrast'
216
+ },
217
+ distort: {
218
+ prefix: 'e',
219
+ qualifier: 'distort'
220
+ },
221
+ fillLight: {
222
+ prefix: 'e',
223
+ qualifier: 'fill_light'
224
+ },
225
+ gamma: {
226
+ prefix: 'e',
227
+ qualifier: 'gamma'
228
+ },
229
+ gradientFade: {
230
+ prefix: 'e',
231
+ qualifier: 'gradient_fade'
232
+ },
233
+ grayscale: {
234
+ prefix: 'e',
235
+ qualifier: 'grayscale'
236
+ },
237
+ improve: {
238
+ prefix: 'e',
239
+ qualifier: 'improve'
240
+ },
241
+ negate: {
242
+ prefix: 'e',
243
+ qualifier: 'negate'
244
+ },
245
+ oilPaint: {
246
+ prefix: 'e',
247
+ qualifier: 'oil_paint'
248
+ },
249
+ opacity: {
250
+ qualifier: 'o'
251
+ },
252
+ outline: {
253
+ prefix: 'e',
254
+ qualifier: 'outline'
255
+ },
256
+ pixelate: {
257
+ prefix: 'e',
258
+ qualifier: 'pixelate'
259
+ },
260
+ pixelateFaces: {
261
+ prefix: 'e',
262
+ qualifier: 'pixelate_faces'
263
+ },
264
+ pixelateRegion: {
265
+ prefix: 'e',
266
+ qualifier: 'pixelate_region'
267
+ },
268
+ redeye: {
269
+ prefix: 'e',
270
+ qualifier: 'redeye'
271
+ },
272
+ replaceColor: {
273
+ prefix: 'e',
274
+ qualifier: 'replace_color'
275
+ },
276
+ saturation: {
277
+ prefix: 'e',
278
+ qualifier: 'saturation'
279
+ },
280
+ sepia: {
281
+ prefix: 'e',
282
+ qualifier: 'sepia'
283
+ },
284
+ shadow: {
285
+ prefix: 'e',
286
+ qualifier: 'shadow'
287
+ },
288
+ sharpen: {
289
+ prefix: 'e',
290
+ qualifier: 'sharpen'
291
+ },
292
+ shear: {
293
+ prefix: 'e',
294
+ qualifier: 'shear'
295
+ },
296
+ simulateColorblind: {
297
+ prefix: 'e',
298
+ qualifier: 'simulate_colorblind'
299
+ },
300
+ tint: {
301
+ prefix: 'e',
302
+ qualifier: 'tint'
303
+ },
304
+ unsharpMask: {
305
+ prefix: 'e',
306
+ qualifier: 'unsharp_mask'
307
+ },
308
+ vectorize: {
309
+ prefix: 'e',
310
+ qualifier: 'vectorize'
311
+ },
312
+ vibrance: {
313
+ prefix: 'e',
314
+ qualifier: 'vibrance'
315
+ },
316
+ vignette: {
317
+ prefix: 'e',
318
+ qualifier: 'vignette'
319
+ }
320
+ };
321
+
322
+ var props$6 = Object.keys(effects);
323
+ function plugin$6(_temp) {
324
+ var _ref = _temp === void 0 ? {} : _temp,
325
+ cldImage = _ref.cldImage,
326
+ options = _ref.options;
327
+ Object.keys(effects).forEach(function (key) {
328
+ var _effects$key = effects[key],
329
+ prefix = _effects$key.prefix,
330
+ qualifier = _effects$key.qualifier;
331
+ var transformation = '';
332
+ if (prefix) {
333
+ transformation = prefix + "_";
334
+ }
335
+ if (options[key] === true) {
336
+ cldImage.effect("" + transformation + qualifier);
337
+ } else if (typeof options[key] === 'string') {
338
+ if (prefix) {
339
+ cldImage.effect("" + transformation + qualifier + ":" + options[key]);
340
+ } else {
341
+ cldImage.effect(qualifier + "_" + options[key]);
342
+ }
343
+ }
344
+ });
345
+ }
346
+
347
+ var effectsPlugin = {
348
+ __proto__: null,
349
+ props: props$6,
350
+ plugin: plugin$6
351
+ };
352
+
353
+ /**
354
+ * encodeBase64
355
+ */
356
+
357
+ function encodeBase64(value) {
358
+ if (typeof btoa === 'function') {
359
+ return btoa(value);
360
+ }
361
+ if (typeof Buffer !== 'undefined') {
362
+ return Buffer.from(value).toString('base64');
363
+ }
364
+ }
243
365
 
244
366
  var _excluded$3 = ["publicId", "url", "position", "text", "effects"];
245
367
  var props$5 = ['text', 'overlays'];
@@ -321,12 +443,33 @@
321
443
  });
322
444
 
323
445
  // Layer effects
446
+ // For layer effects we allow both the standard effects to be applied as well
447
+ // as the primary ones like width and height as those can be used to modify
448
+ // the layer after it's created
324
449
 
325
450
  layerEffects.forEach(function (effect) {
326
451
  Object.keys(effect).forEach(function (key) {
327
- if (!primary[key]) return;
328
- var qualifier = primary[key].qualifier;
329
- primary$1.push(qualifier + "_" + effect[key]);
452
+ if (primary[key]) {
453
+ var qualifier = primary[key].qualifier;
454
+ primary$1.push(qualifier + "_" + effect[key]);
455
+ } else if (effects[key]) {
456
+ var _qualifiersEffects$ke = effects[key],
457
+ _qualifier = _qualifiersEffects$ke.qualifier,
458
+ prefix = _qualifiersEffects$ke.prefix;
459
+ var transformation = '';
460
+ if (prefix) {
461
+ transformation = prefix + "_";
462
+ }
463
+ if (effect[key] === true) {
464
+ primary$1.push("" + transformation + _qualifier);
465
+ } else if (typeof effect[key] === 'string' || typeof effect[key] === 'number') {
466
+ if (prefix) {
467
+ primary$1.push("" + transformation + _qualifier + ":" + effect[key]);
468
+ } else {
469
+ primary$1.push(_qualifier + "_" + effect[key]);
470
+ }
471
+ }
472
+ }
330
473
  });
331
474
  });
332
475
 
@@ -602,6 +745,58 @@
602
745
  plugin: plugin
603
746
  };
604
747
 
748
+ /**
749
+ * pollForProcessingImage
750
+ */
751
+
752
+ function _catch(body, recover) {
753
+ try {
754
+ var result = body();
755
+ } catch (e) {
756
+ return recover(e);
757
+ }
758
+ if (result && result.then) {
759
+ return result.then(void 0, recover);
760
+ }
761
+ return result;
762
+ }
763
+ var pollForProcessingImage = function pollForProcessingImage(options) {
764
+ try {
765
+ var _exit2;
766
+ var src = options.src;
767
+ var _temp4 = _catch(function () {
768
+ return Promise.resolve(new Promise(function (resolve, reject) {
769
+ fetch(src).then(function (res) {
770
+ if (!res.ok) {
771
+ reject(res);
772
+ return;
773
+ }
774
+ resolve(res);
775
+ });
776
+ })).then(function () {});
777
+ }, function (e) {
778
+ function _temp2(_result2) {
779
+ if (_exit2) return _result2;
780
+ _exit2 = 1;
781
+ return false;
782
+ }
783
+ var _temp = function () {
784
+ if (e.status === 423) {
785
+ return Promise.resolve(pollForProcessingImage(options)).then(function (_await$pollForProcess) {
786
+ _exit2 = 1;
787
+ return _await$pollForProcess;
788
+ });
789
+ }
790
+ }();
791
+ return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
792
+ });
793
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function (_result) {
794
+ return _exit2 ? _result : true;
795
+ }) : _exit2 ? _temp4 : true);
796
+ } catch (e) {
797
+ return Promise.reject(e);
798
+ }
799
+ };
605
800
  var transformationPlugins = [
606
801
  // Background Removal must always come first
607
802
  removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, namedTransformationsPlugin, underlaysPlugin, zoompanPlugin,
@@ -769,6 +964,22 @@
769
964
  }
770
965
 
771
966
  var CldImage = function CldImage(props) {
967
+ /**
968
+ * handleOnError
969
+ */
970
+ var handleOnError = function handleOnError(options) {
971
+ try {
972
+ return Promise.resolve(pollForProcessingImage({
973
+ src: options.target.src
974
+ })).then(function (result) {
975
+ if (result) {
976
+ setImgKey(defaultImgKey + ";" + Date.now());
977
+ }
978
+ });
979
+ } catch (e) {
980
+ return Promise.reject(e);
981
+ }
982
+ };
772
983
  var CLD_OPTIONS = ['deliveryType'];
773
984
  transformationPlugins.forEach(function (_ref) {
774
985
  var _ref$props = _ref.props,
@@ -789,6 +1000,12 @@
789
1000
  }).forEach(function (key) {
790
1001
  return imageProps[key] = props[key];
791
1002
  });
1003
+ var defaultImgKey = Object.keys(imageProps).map(function (key) {
1004
+ return key + ":" + imageProps[key];
1005
+ }).join(';');
1006
+ var _useState = react.useState(defaultImgKey),
1007
+ imgKey = _useState[0],
1008
+ setImgKey = _useState[1];
792
1009
 
793
1010
  // Construct Cloudinary-specific props by looking for values for any of the supported prop keys
794
1011
 
@@ -829,8 +1046,9 @@
829
1046
  imageProps: imageProps,
830
1047
  cldOptions: cldOptions
831
1048
  });
832
- }
833
- }));
1049
+ },
1050
+ onError: handleOnError
1051
+ }), imgKey);
834
1052
  };
835
1053
 
836
1054
  var _excluded$1 = ["excludeTags", "twitterTitle"];