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