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 +2 -1
- package/dist/next-cloudinary.js +307 -89
- package/dist/next-cloudinary.js.map +1 -1
- package/dist/next-cloudinary.modern.mjs +279 -89
- package/dist/next-cloudinary.modern.mjs.map +1 -1
- package/dist/next-cloudinary.module.js +307 -89
- package/dist/next-cloudinary.module.js.map +1 -1
- package/dist/next-cloudinary.umd.js +310 -92
- package/dist/next-cloudinary.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { useState, useRef } from 'react';
|
|
1
2
|
import Image from 'next/image';
|
|
2
3
|
import { Cloudinary } from '@cloudinary/url-gen';
|
|
3
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
5
|
import Head from 'next/head';
|
|
5
|
-
import { useRef } from 'react';
|
|
6
6
|
import Script from 'next/script';
|
|
7
7
|
|
|
8
8
|
function _extends() {
|
|
@@ -88,87 +88,6 @@ var croppingPlugin = {
|
|
|
88
88
|
plugin: plugin$7
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
const params = ['art', {
|
|
92
|
-
prop: 'autoBrightness',
|
|
93
|
-
effect: 'auto_brightness'
|
|
94
|
-
}, {
|
|
95
|
-
prop: 'autoColor',
|
|
96
|
-
effect: 'auto_color'
|
|
97
|
-
}, {
|
|
98
|
-
prop: 'autoContrast',
|
|
99
|
-
effect: 'auto_contrast'
|
|
100
|
-
}, {
|
|
101
|
-
prop: 'assistColorblind',
|
|
102
|
-
effect: 'assist_colorblind'
|
|
103
|
-
}, 'blackwhite', 'blur', {
|
|
104
|
-
prop: 'blurFaces',
|
|
105
|
-
effect: 'blur_faces'
|
|
106
|
-
}, {
|
|
107
|
-
prop: 'blurRegion',
|
|
108
|
-
effect: 'blur_region'
|
|
109
|
-
}, 'brightness', {
|
|
110
|
-
prop: 'brightnessHSB',
|
|
111
|
-
effect: 'brightness_hsb'
|
|
112
|
-
}, 'cartoonify', 'colorize', 'contrast', 'distort', {
|
|
113
|
-
prop: 'fillLight',
|
|
114
|
-
effect: 'fill_light'
|
|
115
|
-
}, 'gamma', {
|
|
116
|
-
prop: 'gradientFade',
|
|
117
|
-
effect: 'gradient_fade'
|
|
118
|
-
}, 'grayscale', 'improve', 'negate', {
|
|
119
|
-
prop: 'oilPaint',
|
|
120
|
-
effect: 'oil_paint'
|
|
121
|
-
}, 'outline', 'pixelate', {
|
|
122
|
-
prop: 'pixelateFaces',
|
|
123
|
-
effect: 'pixelate_faces'
|
|
124
|
-
}, {
|
|
125
|
-
prop: 'pixelateRegion',
|
|
126
|
-
effect: 'pixelate_region'
|
|
127
|
-
}, 'redeye', {
|
|
128
|
-
prop: 'replaceColor',
|
|
129
|
-
effect: 'replace_color'
|
|
130
|
-
}, 'saturation', 'sepia', 'shadow', 'sharpen', 'shear', {
|
|
131
|
-
prop: 'simulateColorblind',
|
|
132
|
-
effect: 'simulate_colorblind'
|
|
133
|
-
}, 'tint', {
|
|
134
|
-
prop: 'unsharpMask',
|
|
135
|
-
effect: 'unsharp_mask'
|
|
136
|
-
}, 'vectorize', 'vibrance', 'vignette'];
|
|
137
|
-
const props$6 = params.map(param => param.prop || param);
|
|
138
|
-
function plugin$6({
|
|
139
|
-
cldImage,
|
|
140
|
-
options
|
|
141
|
-
} = {}) {
|
|
142
|
-
params.forEach(key => {
|
|
143
|
-
const prop = key.prop || key;
|
|
144
|
-
const effect = key.effect || key;
|
|
145
|
-
if (options[prop] === true) {
|
|
146
|
-
cldImage.effect(`e_${effect}`);
|
|
147
|
-
} else if (typeof options[prop] === 'string') {
|
|
148
|
-
cldImage.effect(`e_${effect}:${options[prop]}`);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
var effectsPlugin = {
|
|
154
|
-
__proto__: null,
|
|
155
|
-
props: props$6,
|
|
156
|
-
plugin: plugin$6
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* encodeBase64
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
function encodeBase64(value) {
|
|
164
|
-
if (typeof btoa === 'function') {
|
|
165
|
-
return btoa(value);
|
|
166
|
-
}
|
|
167
|
-
if (typeof Buffer !== 'undefined') {
|
|
168
|
-
return Buffer.from(value).toString('base64');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
91
|
// aspectRatio
|
|
173
92
|
|
|
174
93
|
const primary = {
|
|
@@ -236,6 +155,212 @@ const text = {
|
|
|
236
155
|
qualifier: false
|
|
237
156
|
}
|
|
238
157
|
};
|
|
158
|
+
const effects = {
|
|
159
|
+
art: {
|
|
160
|
+
prefix: 'e',
|
|
161
|
+
qualifier: 'art'
|
|
162
|
+
},
|
|
163
|
+
autoBrightness: {
|
|
164
|
+
prefix: 'e',
|
|
165
|
+
qualifier: 'auto_brightness'
|
|
166
|
+
},
|
|
167
|
+
autoColor: {
|
|
168
|
+
prefix: 'e',
|
|
169
|
+
qualifier: 'auto_color'
|
|
170
|
+
},
|
|
171
|
+
autoContrast: {
|
|
172
|
+
prefix: 'e',
|
|
173
|
+
qualifier: 'auto_contrast'
|
|
174
|
+
},
|
|
175
|
+
assistColorblind: {
|
|
176
|
+
prefix: 'e',
|
|
177
|
+
qualifier: 'assist_colorblind'
|
|
178
|
+
},
|
|
179
|
+
blackwhite: {
|
|
180
|
+
prefix: 'e',
|
|
181
|
+
qualifier: 'blackwhite'
|
|
182
|
+
},
|
|
183
|
+
blur: {
|
|
184
|
+
prefix: 'e',
|
|
185
|
+
qualifier: 'blur'
|
|
186
|
+
},
|
|
187
|
+
blurFaces: {
|
|
188
|
+
prefix: 'e',
|
|
189
|
+
qualifier: 'blur_faces'
|
|
190
|
+
},
|
|
191
|
+
blurRegion: {
|
|
192
|
+
prefix: 'e',
|
|
193
|
+
qualifier: 'blur_region'
|
|
194
|
+
},
|
|
195
|
+
brightness: {
|
|
196
|
+
prefix: 'e',
|
|
197
|
+
qualifier: 'brightness'
|
|
198
|
+
},
|
|
199
|
+
brightnessHSB: {
|
|
200
|
+
prefix: 'e',
|
|
201
|
+
qualifier: 'brightness_hsb'
|
|
202
|
+
},
|
|
203
|
+
cartoonify: {
|
|
204
|
+
prefix: 'e',
|
|
205
|
+
qualifier: 'cartoonify'
|
|
206
|
+
},
|
|
207
|
+
colorize: {
|
|
208
|
+
prefix: 'e',
|
|
209
|
+
qualifier: 'colorize'
|
|
210
|
+
},
|
|
211
|
+
contrast: {
|
|
212
|
+
prefix: 'e',
|
|
213
|
+
qualifier: 'contrast'
|
|
214
|
+
},
|
|
215
|
+
distort: {
|
|
216
|
+
prefix: 'e',
|
|
217
|
+
qualifier: 'distort'
|
|
218
|
+
},
|
|
219
|
+
fillLight: {
|
|
220
|
+
prefix: 'e',
|
|
221
|
+
qualifier: 'fill_light'
|
|
222
|
+
},
|
|
223
|
+
gamma: {
|
|
224
|
+
prefix: 'e',
|
|
225
|
+
qualifier: 'gamma'
|
|
226
|
+
},
|
|
227
|
+
gradientFade: {
|
|
228
|
+
prefix: 'e',
|
|
229
|
+
qualifier: 'gradient_fade'
|
|
230
|
+
},
|
|
231
|
+
grayscale: {
|
|
232
|
+
prefix: 'e',
|
|
233
|
+
qualifier: 'grayscale'
|
|
234
|
+
},
|
|
235
|
+
improve: {
|
|
236
|
+
prefix: 'e',
|
|
237
|
+
qualifier: 'improve'
|
|
238
|
+
},
|
|
239
|
+
negate: {
|
|
240
|
+
prefix: 'e',
|
|
241
|
+
qualifier: 'negate'
|
|
242
|
+
},
|
|
243
|
+
oilPaint: {
|
|
244
|
+
prefix: 'e',
|
|
245
|
+
qualifier: 'oil_paint'
|
|
246
|
+
},
|
|
247
|
+
opacity: {
|
|
248
|
+
qualifier: 'o'
|
|
249
|
+
},
|
|
250
|
+
outline: {
|
|
251
|
+
prefix: 'e',
|
|
252
|
+
qualifier: 'outline'
|
|
253
|
+
},
|
|
254
|
+
pixelate: {
|
|
255
|
+
prefix: 'e',
|
|
256
|
+
qualifier: 'pixelate'
|
|
257
|
+
},
|
|
258
|
+
pixelateFaces: {
|
|
259
|
+
prefix: 'e',
|
|
260
|
+
qualifier: 'pixelate_faces'
|
|
261
|
+
},
|
|
262
|
+
pixelateRegion: {
|
|
263
|
+
prefix: 'e',
|
|
264
|
+
qualifier: 'pixelate_region'
|
|
265
|
+
},
|
|
266
|
+
redeye: {
|
|
267
|
+
prefix: 'e',
|
|
268
|
+
qualifier: 'redeye'
|
|
269
|
+
},
|
|
270
|
+
replaceColor: {
|
|
271
|
+
prefix: 'e',
|
|
272
|
+
qualifier: 'replace_color'
|
|
273
|
+
},
|
|
274
|
+
saturation: {
|
|
275
|
+
prefix: 'e',
|
|
276
|
+
qualifier: 'saturation'
|
|
277
|
+
},
|
|
278
|
+
sepia: {
|
|
279
|
+
prefix: 'e',
|
|
280
|
+
qualifier: 'sepia'
|
|
281
|
+
},
|
|
282
|
+
shadow: {
|
|
283
|
+
prefix: 'e',
|
|
284
|
+
qualifier: 'shadow'
|
|
285
|
+
},
|
|
286
|
+
sharpen: {
|
|
287
|
+
prefix: 'e',
|
|
288
|
+
qualifier: 'sharpen'
|
|
289
|
+
},
|
|
290
|
+
shear: {
|
|
291
|
+
prefix: 'e',
|
|
292
|
+
qualifier: 'shear'
|
|
293
|
+
},
|
|
294
|
+
simulateColorblind: {
|
|
295
|
+
prefix: 'e',
|
|
296
|
+
qualifier: 'simulate_colorblind'
|
|
297
|
+
},
|
|
298
|
+
tint: {
|
|
299
|
+
prefix: 'e',
|
|
300
|
+
qualifier: 'tint'
|
|
301
|
+
},
|
|
302
|
+
unsharpMask: {
|
|
303
|
+
prefix: 'e',
|
|
304
|
+
qualifier: 'unsharp_mask'
|
|
305
|
+
},
|
|
306
|
+
vectorize: {
|
|
307
|
+
prefix: 'e',
|
|
308
|
+
qualifier: 'vectorize'
|
|
309
|
+
},
|
|
310
|
+
vibrance: {
|
|
311
|
+
prefix: 'e',
|
|
312
|
+
qualifier: 'vibrance'
|
|
313
|
+
},
|
|
314
|
+
vignette: {
|
|
315
|
+
prefix: 'e',
|
|
316
|
+
qualifier: 'vignette'
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const props$6 = Object.keys(effects);
|
|
321
|
+
function plugin$6({
|
|
322
|
+
cldImage,
|
|
323
|
+
options
|
|
324
|
+
} = {}) {
|
|
325
|
+
Object.keys(effects).forEach(key => {
|
|
326
|
+
const {
|
|
327
|
+
prefix,
|
|
328
|
+
qualifier
|
|
329
|
+
} = effects[key];
|
|
330
|
+
let transformation = '';
|
|
331
|
+
if (prefix) {
|
|
332
|
+
transformation = `${prefix}_`;
|
|
333
|
+
}
|
|
334
|
+
if (options[key] === true) {
|
|
335
|
+
cldImage.effect(`${transformation}${qualifier}`);
|
|
336
|
+
} else if (typeof options[key] === 'string') {
|
|
337
|
+
if (prefix) {
|
|
338
|
+
cldImage.effect(`${transformation}${qualifier}:${options[key]}`);
|
|
339
|
+
} else {
|
|
340
|
+
cldImage.effect(`${qualifier}_${options[key]}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
var effectsPlugin = {
|
|
347
|
+
__proto__: null,
|
|
348
|
+
props: props$6,
|
|
349
|
+
plugin: plugin$6
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* encodeBase64
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
function encodeBase64(value) {
|
|
357
|
+
if (typeof btoa === 'function') {
|
|
358
|
+
return btoa(value);
|
|
359
|
+
}
|
|
360
|
+
if (typeof Buffer !== 'undefined') {
|
|
361
|
+
return Buffer.from(value).toString('base64');
|
|
362
|
+
}
|
|
363
|
+
}
|
|
239
364
|
|
|
240
365
|
const _excluded$3 = ["publicId", "url", "position", "text", "effects"];
|
|
241
366
|
const props$5 = ['text', 'overlays'];
|
|
@@ -321,14 +446,36 @@ function plugin$5({
|
|
|
321
446
|
});
|
|
322
447
|
|
|
323
448
|
// Layer effects
|
|
449
|
+
// For layer effects we allow both the standard effects to be applied as well
|
|
450
|
+
// as the primary ones like width and height as those can be used to modify
|
|
451
|
+
// the layer after it's created
|
|
324
452
|
|
|
325
453
|
layerEffects.forEach(effect => {
|
|
326
454
|
Object.keys(effect).forEach(key => {
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
455
|
+
if (primary[key]) {
|
|
456
|
+
const {
|
|
457
|
+
qualifier
|
|
458
|
+
} = primary[key];
|
|
459
|
+
primary$1.push(`${qualifier}_${effect[key]}`);
|
|
460
|
+
} else if (effects[key]) {
|
|
461
|
+
const {
|
|
462
|
+
qualifier,
|
|
463
|
+
prefix
|
|
464
|
+
} = effects[key];
|
|
465
|
+
let transformation = '';
|
|
466
|
+
if (prefix) {
|
|
467
|
+
transformation = `${prefix}_`;
|
|
468
|
+
}
|
|
469
|
+
if (effect[key] === true) {
|
|
470
|
+
primary$1.push(`${transformation}${qualifier}`);
|
|
471
|
+
} else if (typeof effect[key] === 'string' || typeof effect[key] === 'number') {
|
|
472
|
+
if (prefix) {
|
|
473
|
+
primary$1.push(`${transformation}${qualifier}:${effect[key]}`);
|
|
474
|
+
} else {
|
|
475
|
+
primary$1.push(`${qualifier}_${effect[key]}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
332
479
|
});
|
|
333
480
|
});
|
|
334
481
|
|
|
@@ -760,6 +907,33 @@ function createPlaceholderUrl({
|
|
|
760
907
|
});
|
|
761
908
|
}
|
|
762
909
|
|
|
910
|
+
/**
|
|
911
|
+
* pollForProcessingImage
|
|
912
|
+
*/
|
|
913
|
+
|
|
914
|
+
async function pollForProcessingImage(options) {
|
|
915
|
+
const {
|
|
916
|
+
src
|
|
917
|
+
} = options;
|
|
918
|
+
try {
|
|
919
|
+
await new Promise((resolve, reject) => {
|
|
920
|
+
fetch(src).then(res => {
|
|
921
|
+
if (!res.ok) {
|
|
922
|
+
reject(res);
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
resolve(res);
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
} catch (e) {
|
|
929
|
+
if (e.status === 423) {
|
|
930
|
+
return await pollForProcessingImage(options);
|
|
931
|
+
}
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
return true;
|
|
935
|
+
}
|
|
936
|
+
|
|
763
937
|
function cloudinaryLoader({
|
|
764
938
|
loaderOptions,
|
|
765
939
|
imageProps,
|
|
@@ -803,6 +977,8 @@ const CldImage = props => {
|
|
|
803
977
|
|
|
804
978
|
const imageProps = {};
|
|
805
979
|
Object.keys(props).filter(key => !CLD_OPTIONS.includes(key)).forEach(key => imageProps[key] = props[key]);
|
|
980
|
+
const defaultImgKey = Object.keys(imageProps).map(key => `${key}:${imageProps[key]}`).join(';');
|
|
981
|
+
const [imgKey, setImgKey] = useState(defaultImgKey);
|
|
806
982
|
|
|
807
983
|
// Construct Cloudinary-specific props by looking for values for any of the supported prop keys
|
|
808
984
|
|
|
@@ -836,13 +1012,27 @@ const CldImage = props => {
|
|
|
836
1012
|
const transformations = getTransformations(props.src, props.preserveTransformations);
|
|
837
1013
|
imageProps.rawTransformations = [...imageProps.rawTransformations, ...transformations];
|
|
838
1014
|
}
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* handleOnError
|
|
1018
|
+
*/
|
|
1019
|
+
|
|
1020
|
+
async function handleOnError(options) {
|
|
1021
|
+
const result = await pollForProcessingImage({
|
|
1022
|
+
src: options.target.src
|
|
1023
|
+
});
|
|
1024
|
+
if (result) {
|
|
1025
|
+
setImgKey(`${defaultImgKey};${Date.now()}`);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
839
1028
|
return /*#__PURE__*/jsx(Image, _extends({}, imageProps, {
|
|
840
1029
|
loader: loaderOptions => cloudinaryLoader({
|
|
841
1030
|
loaderOptions,
|
|
842
1031
|
imageProps,
|
|
843
1032
|
cldOptions
|
|
844
|
-
})
|
|
845
|
-
|
|
1033
|
+
}),
|
|
1034
|
+
onError: handleOnError
|
|
1035
|
+
}), imgKey);
|
|
846
1036
|
};
|
|
847
1037
|
|
|
848
1038
|
const _excluded$1 = ["excludeTags", "twitterTitle"];
|