next-cloudinary 1.12.3 → 2.0.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.
- package/README.md +2 -1
- package/dist/next-cloudinary.js +80 -956
- package/dist/next-cloudinary.js.map +1 -1
- package/dist/next-cloudinary.modern.mjs +70 -961
- package/dist/next-cloudinary.modern.mjs.map +1 -1
- package/dist/next-cloudinary.module.js +77 -948
- package/dist/next-cloudinary.module.js.map +1 -1
- package/dist/next-cloudinary.umd.js +82 -959
- package/dist/next-cloudinary.umd.js.map +1 -1
- package/package.json +3 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState, useRef } from 'react';
|
|
2
2
|
import Image from 'next/image';
|
|
3
|
-
import {
|
|
3
|
+
import { getPublicId, getTransformations } from '@cloudinary-util/util';
|
|
4
|
+
import { constructCloudinaryUrl, transformationPlugins } from '@cloudinary-util/url-loader';
|
|
4
5
|
import nextPkg from 'next/package.json';
|
|
5
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
7
|
import Head from 'next/head';
|
|
@@ -33,849 +34,8 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
33
34
|
return target;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
var cropsGravityAuto = ['crop', 'fill', 'lfill', 'fill_pad', 'thumb'];
|
|
37
|
-
var cropsWithZoom = ['crop', 'thumb'];
|
|
38
|
-
var props$7 = ['crop', 'gravity', 'zoom'];
|
|
39
|
-
function plugin$7(_temp) {
|
|
40
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
41
|
-
cldImage = _ref.cldImage,
|
|
42
|
-
options = _ref.options;
|
|
43
|
-
var overrides = {};
|
|
44
|
-
var width = options.width,
|
|
45
|
-
height = options.height,
|
|
46
|
-
widthResize = options.widthResize,
|
|
47
|
-
_options$crop = options.crop,
|
|
48
|
-
crop = _options$crop === void 0 ? 'limit' : _options$crop;
|
|
49
|
-
var transformationString = '';
|
|
50
|
-
if (width) {
|
|
51
|
-
transformationString = "c_" + crop + ",w_" + width;
|
|
52
|
-
}
|
|
53
|
-
if (!options.gravity && cropsGravityAuto.includes(crop)) {
|
|
54
|
-
options.gravity = 'auto';
|
|
55
|
-
}
|
|
56
|
-
if (!['limit'].includes(crop)) {
|
|
57
|
-
transformationString = transformationString + ",h_" + height;
|
|
58
|
-
}
|
|
59
|
-
if (options.gravity) {
|
|
60
|
-
if (options.gravity === 'auto' && !cropsGravityAuto.includes(crop)) {
|
|
61
|
-
console.warn("Auto gravity can only be used with crop modes: " + cropsGravityAuto.join(', ') + ". Not applying gravity.");
|
|
62
|
-
} else {
|
|
63
|
-
transformationString = transformationString + ",g_" + options.gravity;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (options.zoom) {
|
|
67
|
-
if (options.zoom === 'auto' && !cropsWithZoom.includes(crop)) {
|
|
68
|
-
console.warn("Zoom can only be used with crop modes: " + cropsWithZoom.join(', ') + ". Not applying zoom.");
|
|
69
|
-
} else {
|
|
70
|
-
transformationString = transformationString + ",z_" + options.zoom;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
cldImage.effect(transformationString);
|
|
74
|
-
|
|
75
|
-
// If we have a resize width that's smaller than the user-defined width, we want to give the
|
|
76
|
-
// ability to perform a final resize on the image without impacting any of the effects like text
|
|
77
|
-
// overlays that may depend on the size to work properly
|
|
78
|
-
|
|
79
|
-
if (typeof widthResize === 'number' && widthResize < width) {
|
|
80
|
-
overrides.width = widthResize;
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
options: overrides
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
var croppingPlugin = {
|
|
88
|
-
__proto__: null,
|
|
89
|
-
props: props$7,
|
|
90
|
-
plugin: plugin$7
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// aspectRatio
|
|
94
|
-
|
|
95
|
-
var primary = {
|
|
96
|
-
aspectRatio: {
|
|
97
|
-
qualifier: 'ar'
|
|
98
|
-
},
|
|
99
|
-
crop: {
|
|
100
|
-
qualifier: 'c'
|
|
101
|
-
},
|
|
102
|
-
gravity: {
|
|
103
|
-
qualifier: 'g'
|
|
104
|
-
},
|
|
105
|
-
height: {
|
|
106
|
-
qualifier: 'h'
|
|
107
|
-
},
|
|
108
|
-
width: {
|
|
109
|
-
qualifier: 'w'
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
var position = {
|
|
113
|
-
angle: {
|
|
114
|
-
qualifier: 'a'
|
|
115
|
-
},
|
|
116
|
-
gravity: {
|
|
117
|
-
qualifier: 'g'
|
|
118
|
-
},
|
|
119
|
-
x: {
|
|
120
|
-
qualifier: 'x'
|
|
121
|
-
},
|
|
122
|
-
y: {
|
|
123
|
-
qualifier: 'y'
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
var text = {
|
|
127
|
-
alignment: {
|
|
128
|
-
qualifier: 'alignment'
|
|
129
|
-
},
|
|
130
|
-
border: {
|
|
131
|
-
qualifier: 'bo',
|
|
132
|
-
location: 'primary'
|
|
133
|
-
},
|
|
134
|
-
color: {
|
|
135
|
-
qualifier: 'co',
|
|
136
|
-
location: 'primary'
|
|
137
|
-
},
|
|
138
|
-
fontFamily: {
|
|
139
|
-
qualifier: false
|
|
140
|
-
},
|
|
141
|
-
fontSize: {
|
|
142
|
-
qualifier: false
|
|
143
|
-
},
|
|
144
|
-
fontWeight: {
|
|
145
|
-
qualifier: false
|
|
146
|
-
},
|
|
147
|
-
letterSpacing: {
|
|
148
|
-
qualifier: 'letter_spacing'
|
|
149
|
-
},
|
|
150
|
-
lineSpacing: {
|
|
151
|
-
qualifier: 'line_spacing'
|
|
152
|
-
},
|
|
153
|
-
stroke: {
|
|
154
|
-
qualifier: 'self'
|
|
155
|
-
},
|
|
156
|
-
textDecoration: {
|
|
157
|
-
qualifier: false
|
|
158
|
-
}
|
|
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
|
-
background: {
|
|
182
|
-
qualifier: 'b'
|
|
183
|
-
},
|
|
184
|
-
blackwhite: {
|
|
185
|
-
prefix: 'e',
|
|
186
|
-
qualifier: 'blackwhite'
|
|
187
|
-
},
|
|
188
|
-
blur: {
|
|
189
|
-
prefix: 'e',
|
|
190
|
-
qualifier: 'blur'
|
|
191
|
-
},
|
|
192
|
-
blurFaces: {
|
|
193
|
-
prefix: 'e',
|
|
194
|
-
qualifier: 'blur_faces'
|
|
195
|
-
},
|
|
196
|
-
blurRegion: {
|
|
197
|
-
prefix: 'e',
|
|
198
|
-
qualifier: 'blur_region'
|
|
199
|
-
},
|
|
200
|
-
border: {
|
|
201
|
-
qualifier: 'bo'
|
|
202
|
-
},
|
|
203
|
-
brightness: {
|
|
204
|
-
prefix: 'e',
|
|
205
|
-
qualifier: 'brightness'
|
|
206
|
-
},
|
|
207
|
-
brightnessHSB: {
|
|
208
|
-
prefix: 'e',
|
|
209
|
-
qualifier: 'brightness_hsb'
|
|
210
|
-
},
|
|
211
|
-
cartoonify: {
|
|
212
|
-
prefix: 'e',
|
|
213
|
-
qualifier: 'cartoonify'
|
|
214
|
-
},
|
|
215
|
-
color: {
|
|
216
|
-
qualifier: 'co'
|
|
217
|
-
},
|
|
218
|
-
colorize: {
|
|
219
|
-
prefix: 'e',
|
|
220
|
-
qualifier: 'colorize'
|
|
221
|
-
},
|
|
222
|
-
contrast: {
|
|
223
|
-
prefix: 'e',
|
|
224
|
-
qualifier: 'contrast'
|
|
225
|
-
},
|
|
226
|
-
distort: {
|
|
227
|
-
prefix: 'e',
|
|
228
|
-
qualifier: 'distort'
|
|
229
|
-
},
|
|
230
|
-
fillLight: {
|
|
231
|
-
prefix: 'e',
|
|
232
|
-
qualifier: 'fill_light'
|
|
233
|
-
},
|
|
234
|
-
gamma: {
|
|
235
|
-
prefix: 'e',
|
|
236
|
-
qualifier: 'gamma'
|
|
237
|
-
},
|
|
238
|
-
gradientFade: {
|
|
239
|
-
prefix: 'e',
|
|
240
|
-
qualifier: 'gradient_fade'
|
|
241
|
-
},
|
|
242
|
-
grayscale: {
|
|
243
|
-
prefix: 'e',
|
|
244
|
-
qualifier: 'grayscale'
|
|
245
|
-
},
|
|
246
|
-
improve: {
|
|
247
|
-
prefix: 'e',
|
|
248
|
-
qualifier: 'improve'
|
|
249
|
-
},
|
|
250
|
-
multiply: {
|
|
251
|
-
prefix: 'e',
|
|
252
|
-
qualifier: 'multiply'
|
|
253
|
-
},
|
|
254
|
-
negate: {
|
|
255
|
-
prefix: 'e',
|
|
256
|
-
qualifier: 'negate'
|
|
257
|
-
},
|
|
258
|
-
oilPaint: {
|
|
259
|
-
prefix: 'e',
|
|
260
|
-
qualifier: 'oil_paint'
|
|
261
|
-
},
|
|
262
|
-
opacity: {
|
|
263
|
-
qualifier: 'o'
|
|
264
|
-
},
|
|
265
|
-
outline: {
|
|
266
|
-
prefix: 'e',
|
|
267
|
-
qualifier: 'outline'
|
|
268
|
-
},
|
|
269
|
-
overlay: {
|
|
270
|
-
prefix: 'e',
|
|
271
|
-
qualifier: 'overlay'
|
|
272
|
-
},
|
|
273
|
-
pixelate: {
|
|
274
|
-
prefix: 'e',
|
|
275
|
-
qualifier: 'pixelate'
|
|
276
|
-
},
|
|
277
|
-
pixelateFaces: {
|
|
278
|
-
prefix: 'e',
|
|
279
|
-
qualifier: 'pixelate_faces'
|
|
280
|
-
},
|
|
281
|
-
pixelateRegion: {
|
|
282
|
-
prefix: 'e',
|
|
283
|
-
qualifier: 'pixelate_region'
|
|
284
|
-
},
|
|
285
|
-
redeye: {
|
|
286
|
-
prefix: 'e',
|
|
287
|
-
qualifier: 'redeye'
|
|
288
|
-
},
|
|
289
|
-
replaceColor: {
|
|
290
|
-
prefix: 'e',
|
|
291
|
-
qualifier: 'replace_color'
|
|
292
|
-
},
|
|
293
|
-
saturation: {
|
|
294
|
-
prefix: 'e',
|
|
295
|
-
qualifier: 'saturation'
|
|
296
|
-
},
|
|
297
|
-
screen: {
|
|
298
|
-
prefix: 'e',
|
|
299
|
-
qualifier: 'screen'
|
|
300
|
-
},
|
|
301
|
-
sepia: {
|
|
302
|
-
prefix: 'e',
|
|
303
|
-
qualifier: 'sepia'
|
|
304
|
-
},
|
|
305
|
-
shadow: {
|
|
306
|
-
prefix: 'e',
|
|
307
|
-
qualifier: 'shadow'
|
|
308
|
-
},
|
|
309
|
-
sharpen: {
|
|
310
|
-
prefix: 'e',
|
|
311
|
-
qualifier: 'sharpen'
|
|
312
|
-
},
|
|
313
|
-
shear: {
|
|
314
|
-
prefix: 'e',
|
|
315
|
-
qualifier: 'shear'
|
|
316
|
-
},
|
|
317
|
-
simulateColorblind: {
|
|
318
|
-
prefix: 'e',
|
|
319
|
-
qualifier: 'simulate_colorblind'
|
|
320
|
-
},
|
|
321
|
-
tint: {
|
|
322
|
-
prefix: 'e',
|
|
323
|
-
qualifier: 'tint'
|
|
324
|
-
},
|
|
325
|
-
unsharpMask: {
|
|
326
|
-
prefix: 'e',
|
|
327
|
-
qualifier: 'unsharp_mask'
|
|
328
|
-
},
|
|
329
|
-
vectorize: {
|
|
330
|
-
prefix: 'e',
|
|
331
|
-
qualifier: 'vectorize'
|
|
332
|
-
},
|
|
333
|
-
vibrance: {
|
|
334
|
-
prefix: 'e',
|
|
335
|
-
qualifier: 'vibrance'
|
|
336
|
-
},
|
|
337
|
-
vignette: {
|
|
338
|
-
prefix: 'e',
|
|
339
|
-
qualifier: 'vignette'
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
var flags = {
|
|
343
|
-
relative: {
|
|
344
|
-
prefix: 'fl',
|
|
345
|
-
qualifier: 'relative',
|
|
346
|
-
location: 'primary'
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* constructTransformation
|
|
352
|
-
*/
|
|
353
|
-
|
|
354
|
-
function constructTransformation(_ref) {
|
|
355
|
-
var prefix = _ref.prefix,
|
|
356
|
-
qualifier = _ref.qualifier,
|
|
357
|
-
value = _ref.value;
|
|
358
|
-
var transformation = '';
|
|
359
|
-
if (prefix) {
|
|
360
|
-
transformation = prefix + "_";
|
|
361
|
-
}
|
|
362
|
-
if (value === true || value === 'true') {
|
|
363
|
-
return "" + transformation + qualifier;
|
|
364
|
-
}
|
|
365
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
366
|
-
if (prefix) {
|
|
367
|
-
return "" + transformation + qualifier + ":" + value;
|
|
368
|
-
} else {
|
|
369
|
-
return qualifier + "_" + value;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Retrieves the transformations added to a cloudiary image url. If no transformation is recognized it returns an empty array.
|
|
376
|
-
*
|
|
377
|
-
* @param {string} src The cloudiary url.
|
|
378
|
-
*
|
|
379
|
-
* @return {array} The array of transformations
|
|
380
|
-
*/
|
|
381
|
-
|
|
382
|
-
function getTransformations(src, preserveTransformations) {
|
|
383
|
-
if (typeof src !== "string") {
|
|
384
|
-
throw new Error("Invalid src of type " + typeof src);
|
|
385
|
-
}
|
|
386
|
-
if (src.includes("res.cloudinary.com") && preserveTransformations) {
|
|
387
|
-
var regex = new RegExp("(https?)://(res.cloudinary.com)/([^/]+)/(image|video|raw)/(upload|authenticated)/(.*)/(v[0-9]+)/(.+)(?:.[a-z]{3})?", "gi");
|
|
388
|
-
var groups = regex.exec(src);
|
|
389
|
-
var transformationStr = groups.slice(1).find(function (i) {
|
|
390
|
-
return i.includes("_");
|
|
391
|
-
});
|
|
392
|
-
if (transformationStr) {
|
|
393
|
-
return transformationStr.split(",").join("/").split("/");
|
|
394
|
-
} else {
|
|
395
|
-
return [];
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return [];
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
var props$6 = [].concat(Object.keys(effects), ['effects']);
|
|
402
|
-
function plugin$6(_temp) {
|
|
403
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
404
|
-
cldImage = _ref.cldImage,
|
|
405
|
-
options = _ref.options;
|
|
406
|
-
// Handle any top-level effect props
|
|
407
|
-
|
|
408
|
-
constructTransformationString({
|
|
409
|
-
effects: effects,
|
|
410
|
-
options: options
|
|
411
|
-
}).filter(function (t) {
|
|
412
|
-
return !!t;
|
|
413
|
-
}).forEach(function (transformation) {
|
|
414
|
-
return cldImage.effect(transformation);
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
// If we're passing in an effects prop explicitly, treat it as an array of
|
|
418
|
-
// effects that we need to process
|
|
419
|
-
|
|
420
|
-
if (Array.isArray(options.effects)) {
|
|
421
|
-
options.effects.forEach(function (effectsSet) {
|
|
422
|
-
var transformationString = constructTransformationString({
|
|
423
|
-
effects: effects,
|
|
424
|
-
options: effectsSet
|
|
425
|
-
}).filter(function (t) {
|
|
426
|
-
return !!t;
|
|
427
|
-
}).join(',');
|
|
428
|
-
cldImage.effect(transformationString);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
function constructTransformationString(_ref2) {
|
|
432
|
-
var effects = _ref2.effects,
|
|
433
|
-
options = _ref2.options;
|
|
434
|
-
return Object.keys(effects).map(function (key) {
|
|
435
|
-
var _effects$key = effects[key],
|
|
436
|
-
prefix = _effects$key.prefix,
|
|
437
|
-
qualifier = _effects$key.qualifier;
|
|
438
|
-
return constructTransformation({
|
|
439
|
-
qualifier: qualifier,
|
|
440
|
-
prefix: prefix,
|
|
441
|
-
value: options[key]
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
var effectsPlugin = {
|
|
448
|
-
__proto__: null,
|
|
449
|
-
props: props$6,
|
|
450
|
-
plugin: plugin$6
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* encodeBase64
|
|
455
|
-
*/
|
|
456
|
-
|
|
457
|
-
function encodeBase64(value) {
|
|
458
|
-
if (typeof btoa === 'function') {
|
|
459
|
-
return btoa(value);
|
|
460
|
-
}
|
|
461
|
-
if (typeof Buffer !== 'undefined') {
|
|
462
|
-
return Buffer.from(value).toString('base64');
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
var _excluded$3 = ["publicId", "url", "position", "text", "effects", "appliedEffects"];
|
|
467
|
-
var props$5 = ['text', 'overlays'];
|
|
468
|
-
var DEFAULT_TEXT_OPTIONS = {
|
|
469
|
-
color: 'black',
|
|
470
|
-
fontFamily: 'Arial',
|
|
471
|
-
fontSize: 200,
|
|
472
|
-
fontWeight: 'bold'
|
|
473
|
-
};
|
|
474
|
-
function plugin$5(_temp) {
|
|
475
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
476
|
-
cldImage = _ref.cldImage,
|
|
477
|
-
options = _ref.options;
|
|
478
|
-
var text$1 = options.text,
|
|
479
|
-
_options$overlays = options.overlays,
|
|
480
|
-
overlays = _options$overlays === void 0 ? [] : _options$overlays;
|
|
481
|
-
var type = 'overlay';
|
|
482
|
-
var typeQualifier = 'l';
|
|
483
|
-
if (Array.isArray(overlays)) {
|
|
484
|
-
overlays.forEach(applyOverlay);
|
|
485
|
-
}
|
|
486
|
-
if (typeof text$1 === 'string') {
|
|
487
|
-
applyOverlay({
|
|
488
|
-
text: _extends({}, DEFAULT_TEXT_OPTIONS, {
|
|
489
|
-
text: text$1
|
|
490
|
-
})
|
|
491
|
-
});
|
|
492
|
-
} else if (typeof text$1 === 'object') {
|
|
493
|
-
applyOverlay({
|
|
494
|
-
text: _extends({}, DEFAULT_TEXT_OPTIONS, text$1)
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* applyOverlay
|
|
500
|
-
*/
|
|
501
|
-
|
|
502
|
-
function applyOverlay(_ref2) {
|
|
503
|
-
var publicId = _ref2.publicId,
|
|
504
|
-
url = _ref2.url,
|
|
505
|
-
position$1 = _ref2.position,
|
|
506
|
-
text$1 = _ref2.text,
|
|
507
|
-
_ref2$effects = _ref2.effects,
|
|
508
|
-
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
509
|
-
_ref2$appliedEffects = _ref2.appliedEffects,
|
|
510
|
-
appliedEffects = _ref2$appliedEffects === void 0 ? [] : _ref2$appliedEffects,
|
|
511
|
-
options = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
512
|
-
var hasPublicId = typeof publicId === 'string';
|
|
513
|
-
var hasUrl = typeof url === 'string';
|
|
514
|
-
var hasText = typeof text$1 === 'object' || typeof text$1 === 'string';
|
|
515
|
-
var hasPosition = typeof position$1 === 'object';
|
|
516
|
-
if (!hasPublicId && !hasUrl && !hasText) {
|
|
517
|
-
console.warn("An " + type + " is missing Public ID, URL, or Text");
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// Start to construct the transformation string using text or the public ID
|
|
522
|
-
// if it's image-based
|
|
523
|
-
|
|
524
|
-
var layerTransformation;
|
|
525
|
-
if (hasText) {
|
|
526
|
-
layerTransformation = typeQualifier + "_text";
|
|
527
|
-
} else if (hasPublicId) {
|
|
528
|
-
layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
|
|
529
|
-
} else if (hasUrl) {
|
|
530
|
-
layerTransformation = typeQualifier + "_fetch:" + encodeBase64(url);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// Begin organizing transformations based on what it is and the location
|
|
534
|
-
// it needs to be placed in the URL
|
|
535
|
-
|
|
536
|
-
var primary$1 = [];
|
|
537
|
-
var applied = [];
|
|
538
|
-
|
|
539
|
-
// Gemeral options
|
|
540
|
-
|
|
541
|
-
Object.keys(options).forEach(function (key) {
|
|
542
|
-
if (!primary[key]) return;
|
|
543
|
-
var qualifier = primary[key].qualifier;
|
|
544
|
-
var transformation = constructTransformation({
|
|
545
|
-
qualifier: qualifier,
|
|
546
|
-
value: options[key]
|
|
547
|
-
});
|
|
548
|
-
primary$1.push(transformation);
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
// Layer effects
|
|
552
|
-
// For layer effects we allow both the standard effects to be applied as well
|
|
553
|
-
// as the primary ones like width and height as those can be used to modify
|
|
554
|
-
// the layer after it's created
|
|
555
|
-
|
|
556
|
-
layerEffects.forEach(function (effect) {
|
|
557
|
-
Object.keys(effect).forEach(function (key) {
|
|
558
|
-
var _ref3 = primary[key] || effects[key] || {},
|
|
559
|
-
qualifier = _ref3.qualifier,
|
|
560
|
-
prefix = _ref3.prefix;
|
|
561
|
-
var transformation = constructTransformation({
|
|
562
|
-
qualifier: qualifier,
|
|
563
|
-
prefix: prefix,
|
|
564
|
-
value: effect[key]
|
|
565
|
-
});
|
|
566
|
-
primary$1.push(transformation);
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
// Applied Layer effects
|
|
571
|
-
// Similar to layer effects but they get appended to an additional transformation
|
|
572
|
-
// along with fl_layer_applied
|
|
573
|
-
|
|
574
|
-
appliedEffects.forEach(function (effect) {
|
|
575
|
-
Object.keys(effect).forEach(function (key) {
|
|
576
|
-
var _ref4 = primary[key] || effects[key] || {},
|
|
577
|
-
qualifier = _ref4.qualifier,
|
|
578
|
-
prefix = _ref4.prefix;
|
|
579
|
-
var transformation = constructTransformation({
|
|
580
|
-
qualifier: qualifier,
|
|
581
|
-
prefix: prefix,
|
|
582
|
-
value: effect[key]
|
|
583
|
-
});
|
|
584
|
-
applied.push(transformation);
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
// Text styling
|
|
589
|
-
|
|
590
|
-
if (hasText) {
|
|
591
|
-
if (typeof text$1 === 'string') {
|
|
592
|
-
text$1 = _extends({}, DEFAULT_TEXT_OPTIONS, {
|
|
593
|
-
text: text$1
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
var textTransformations = [];
|
|
597
|
-
Object.keys(text$1).forEach(function (key) {
|
|
598
|
-
if (!text[key]) return;
|
|
599
|
-
var _qualifiersText$key = text[key],
|
|
600
|
-
qualifier = _qualifiersText$key.qualifier,
|
|
601
|
-
location = _qualifiersText$key.location;
|
|
602
|
-
if (location === 'primary') {
|
|
603
|
-
primary$1.push(qualifier + "_" + text$1[key]);
|
|
604
|
-
} else if (qualifier === 'self') {
|
|
605
|
-
textTransformations.push(key);
|
|
606
|
-
} else if (qualifier) {
|
|
607
|
-
textTransformations.push(qualifier + "_" + text$1[key]);
|
|
608
|
-
} else {
|
|
609
|
-
textTransformations.push(text$1[key]);
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
layerTransformation = layerTransformation + ":" + textTransformations.join('_') + ":" + text$1.text;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
// Positioning
|
|
616
|
-
|
|
617
|
-
if (hasPosition) {
|
|
618
|
-
Object.keys(position$1).forEach(function (key) {
|
|
619
|
-
if (!position[key]) return;
|
|
620
|
-
var qualifier = position[key].qualifier;
|
|
621
|
-
var transformation = constructTransformation({
|
|
622
|
-
qualifier: qualifier,
|
|
623
|
-
value: position$1[key]
|
|
624
|
-
});
|
|
625
|
-
applied.push(transformation);
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
// Add all primary transformations
|
|
630
|
-
|
|
631
|
-
if (primary$1.length > 0) {
|
|
632
|
-
layerTransformation = layerTransformation + "," + primary$1.join(',');
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
// Add all applied transformations
|
|
636
|
-
|
|
637
|
-
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
638
|
-
if (applied.length > 0) {
|
|
639
|
-
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
// Finally add it to the image
|
|
643
|
-
|
|
644
|
-
cldImage.addTransformation(layerTransformation);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
var overlaysPlugin = {
|
|
649
|
-
__proto__: null,
|
|
650
|
-
props: props$5,
|
|
651
|
-
DEFAULT_TEXT_OPTIONS: DEFAULT_TEXT_OPTIONS,
|
|
652
|
-
plugin: plugin$5
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
var props$4 = ['transformations'];
|
|
656
|
-
function plugin$4(_temp) {
|
|
657
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
658
|
-
cldImage = _ref.cldImage,
|
|
659
|
-
options = _ref.options;
|
|
660
|
-
var _options$transformati = options.transformations,
|
|
661
|
-
transformations = _options$transformati === void 0 ? [] : _options$transformati;
|
|
662
|
-
if (!Array.isArray(transformations)) {
|
|
663
|
-
transformations = [transformations];
|
|
664
|
-
}
|
|
665
|
-
transformations.forEach(function (transformation) {
|
|
666
|
-
cldImage.addTransformation("t_" + transformation);
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
var namedTransformationsPlugin = {
|
|
671
|
-
__proto__: null,
|
|
672
|
-
props: props$4,
|
|
673
|
-
plugin: plugin$4
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
var props$3 = ['rawTransformations'];
|
|
677
|
-
function plugin$3(_temp) {
|
|
678
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
679
|
-
cldImage = _ref.cldImage,
|
|
680
|
-
options = _ref.options;
|
|
681
|
-
var _options$rawTransform = options.rawTransformations,
|
|
682
|
-
rawTransformations = _options$rawTransform === void 0 ? [] : _options$rawTransform;
|
|
683
|
-
rawTransformations.forEach(function (transformation) {
|
|
684
|
-
cldImage.addTransformation(transformation);
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
var rawTransformationsPlugin = {
|
|
689
|
-
__proto__: null,
|
|
690
|
-
props: props$3,
|
|
691
|
-
plugin: plugin$3
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
var props$2 = ['removeBackground'];
|
|
695
|
-
function plugin$2(_temp) {
|
|
696
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
697
|
-
cldImage = _ref.cldImage,
|
|
698
|
-
options = _ref.options;
|
|
699
|
-
var _options$removeBackgr = options.removeBackground,
|
|
700
|
-
removeBackground = _options$removeBackgr === void 0 ? false : _options$removeBackgr;
|
|
701
|
-
if (removeBackground) {
|
|
702
|
-
cldImage.effect('e_background_removal');
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
var removeBackgroundPlugin = {
|
|
707
|
-
__proto__: null,
|
|
708
|
-
props: props$2,
|
|
709
|
-
plugin: plugin$2
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
var _excluded$2 = ["publicId", "type", "position", "text", "effects", "flags"];
|
|
713
|
-
var props$1 = ['underlay', 'underlays'];
|
|
714
|
-
function plugin$1(_temp) {
|
|
715
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
716
|
-
cldImage = _ref.cldImage,
|
|
717
|
-
options = _ref.options;
|
|
718
|
-
var underlay = options.underlay,
|
|
719
|
-
_options$underlays = options.underlays,
|
|
720
|
-
underlays = _options$underlays === void 0 ? [] : _options$underlays;
|
|
721
|
-
var typeQualifier = 'u';
|
|
722
|
-
if (Array.isArray(underlays)) {
|
|
723
|
-
underlays.forEach(applyUnderlay);
|
|
724
|
-
}
|
|
725
|
-
if (typeof underlay === 'string') {
|
|
726
|
-
var underlayOptions = {
|
|
727
|
-
publicId: underlay,
|
|
728
|
-
crop: 'fill',
|
|
729
|
-
width: '1.0',
|
|
730
|
-
height: '1.0',
|
|
731
|
-
flags: ['relative']
|
|
732
|
-
};
|
|
733
|
-
applyUnderlay(underlayOptions);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
/**
|
|
737
|
-
* applyUnderlay
|
|
738
|
-
*/
|
|
739
|
-
|
|
740
|
-
function applyUnderlay(_ref2) {
|
|
741
|
-
var publicId = _ref2.publicId,
|
|
742
|
-
type = _ref2.type,
|
|
743
|
-
position$1 = _ref2.position,
|
|
744
|
-
_ref2$effects = _ref2.effects,
|
|
745
|
-
layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
|
|
746
|
-
_ref2$flags = _ref2.flags,
|
|
747
|
-
flags$1 = _ref2$flags === void 0 ? [] : _ref2$flags,
|
|
748
|
-
options = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
|
|
749
|
-
var hasPublicId = typeof publicId === 'string';
|
|
750
|
-
var hasPosition = typeof position$1 === 'object';
|
|
751
|
-
if (!hasPublicId) {
|
|
752
|
-
console.warn("An " + type + " is missing a Public ID");
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
// Start to construct the transformation string using text or the public ID
|
|
757
|
-
// if it's image-based
|
|
758
|
-
|
|
759
|
-
var layerTransformation = typeQualifier + "_" + publicId.replace(/\//g, ':');
|
|
760
|
-
|
|
761
|
-
// Begin organizing transformations based on what it is and the location
|
|
762
|
-
// it needs to be placed in the URL
|
|
763
|
-
|
|
764
|
-
var primary$1 = [];
|
|
765
|
-
var applied = [];
|
|
766
|
-
|
|
767
|
-
// Gemeral options
|
|
768
|
-
|
|
769
|
-
Object.keys(options).forEach(function (key) {
|
|
770
|
-
if (!primary[key]) return;
|
|
771
|
-
var qualifier = primary[key].qualifier;
|
|
772
|
-
primary$1.push(qualifier + "_" + options[key]);
|
|
773
|
-
});
|
|
774
|
-
|
|
775
|
-
// Layer effects
|
|
776
|
-
|
|
777
|
-
layerEffects.forEach(function (effect) {
|
|
778
|
-
Object.keys(effect).forEach(function (key) {
|
|
779
|
-
if (!primary[key]) return;
|
|
780
|
-
var qualifier = primary[key].qualifier;
|
|
781
|
-
primary$1.push(qualifier + "_" + effect[key]);
|
|
782
|
-
});
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
// Positioning
|
|
786
|
-
|
|
787
|
-
if (hasPosition) {
|
|
788
|
-
Object.keys(position$1).forEach(function (key) {
|
|
789
|
-
if (!position[key]) return;
|
|
790
|
-
var qualifier = position[key].qualifier;
|
|
791
|
-
applied.push(qualifier + "_" + position$1[key]);
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
// Positioning
|
|
796
|
-
|
|
797
|
-
flags$1.forEach(function (key) {
|
|
798
|
-
if (!flags[key]) return;
|
|
799
|
-
var _qualifiersFlags$key = flags[key],
|
|
800
|
-
qualifier = _qualifiersFlags$key.qualifier,
|
|
801
|
-
prefix = _qualifiersFlags$key.prefix;
|
|
802
|
-
primary$1.push(prefix + "_" + qualifier);
|
|
803
|
-
});
|
|
804
|
-
|
|
805
|
-
// Add all primary transformations
|
|
806
|
-
|
|
807
|
-
layerTransformation = layerTransformation + "," + primary$1.join(',');
|
|
808
|
-
|
|
809
|
-
// Add all applied transformations
|
|
810
|
-
|
|
811
|
-
layerTransformation = layerTransformation + "/fl_layer_apply,fl_no_overflow";
|
|
812
|
-
if (applied.length > 0) {
|
|
813
|
-
layerTransformation = layerTransformation + "," + applied.join(',');
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
// Finally add it to the image
|
|
817
|
-
|
|
818
|
-
cldImage.addTransformation(layerTransformation);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
var underlaysPlugin = {
|
|
823
|
-
__proto__: null,
|
|
824
|
-
props: props$1,
|
|
825
|
-
plugin: plugin$1
|
|
826
|
-
};
|
|
827
|
-
|
|
828
|
-
var props = ['zoompan'];
|
|
829
|
-
function plugin(_temp) {
|
|
830
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
831
|
-
cldImage = _ref.cldImage,
|
|
832
|
-
options = _ref.options;
|
|
833
|
-
var _options$zoompan = options.zoompan,
|
|
834
|
-
zoompan = _options$zoompan === void 0 ? false : _options$zoompan;
|
|
835
|
-
var overrides = {};
|
|
836
|
-
if (zoompan === true) {
|
|
837
|
-
cldImage.effect('e_zoompan');
|
|
838
|
-
} else if (typeof zoompan === 'string') {
|
|
839
|
-
if (zoompan === 'loop') {
|
|
840
|
-
cldImage.effect('e_zoompan');
|
|
841
|
-
cldImage.effect('e_loop');
|
|
842
|
-
} else {
|
|
843
|
-
cldImage.effect("e_zoompan:" + zoompan);
|
|
844
|
-
}
|
|
845
|
-
} else if (typeof zoompan === 'object') {
|
|
846
|
-
var zoompanEffect = 'e_zoompan';
|
|
847
|
-
if (typeof zoompan.options === 'string') {
|
|
848
|
-
zoompanEffect = "" + zoompanEffect + zoompan.options;
|
|
849
|
-
}
|
|
850
|
-
cldImage.effect(zoompanEffect);
|
|
851
|
-
var loopEffect;
|
|
852
|
-
if (zoompan.loop === true) {
|
|
853
|
-
loopEffect = 'e_loop';
|
|
854
|
-
} else if (typeof zoompan.loop === 'string') {
|
|
855
|
-
loopEffect = "e_loop" + zoompan.loop;
|
|
856
|
-
}
|
|
857
|
-
if (loopEffect) {
|
|
858
|
-
cldImage.effect(loopEffect);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
if (zoompan !== false) {
|
|
862
|
-
overrides.format = 'gif';
|
|
863
|
-
}
|
|
864
|
-
return {
|
|
865
|
-
options: overrides
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
var zoompanPlugin = {
|
|
870
|
-
__proto__: null,
|
|
871
|
-
props: props,
|
|
872
|
-
plugin: plugin
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
|
|
876
|
-
|
|
877
37
|
var name = "next-cloudinary";
|
|
878
|
-
var version = "
|
|
38
|
+
var version = "2.0.1";
|
|
879
39
|
var main = "dist/next-cloudinary.umd.js";
|
|
880
40
|
var module = "dist/next-cloudinary.module.js";
|
|
881
41
|
var source = "src/index.ts";
|
|
@@ -887,6 +47,8 @@ var scripts = {
|
|
|
887
47
|
test: "jest"
|
|
888
48
|
};
|
|
889
49
|
var dependencies = {
|
|
50
|
+
"@cloudinary-util/url-loader": "^1.2.4",
|
|
51
|
+
"@cloudinary-util/util": "^1.2.0",
|
|
890
52
|
"@cloudinary/url-gen": "^1.8.6"
|
|
891
53
|
};
|
|
892
54
|
var devDependencies = {
|
|
@@ -918,6 +80,14 @@ var pkg = {
|
|
|
918
80
|
peerDependencies: peerDependencies
|
|
919
81
|
};
|
|
920
82
|
|
|
83
|
+
var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
|
|
84
|
+
var NEXT_CLOUDINARY_VERSION = pkg.version;
|
|
85
|
+
var NEXT_VERSION = nextPkg.version;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* createPlaceholderUrl
|
|
89
|
+
*/
|
|
90
|
+
|
|
921
91
|
/**
|
|
922
92
|
* pollForProcessingImage
|
|
923
93
|
*/
|
|
@@ -970,95 +140,10 @@ var pollForProcessingImage = function pollForProcessingImage(options) {
|
|
|
970
140
|
return Promise.reject(e);
|
|
971
141
|
}
|
|
972
142
|
};
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
// it's always expected to applied the same way
|
|
978
|
-
rawTransformationsPlugin];
|
|
979
|
-
var cld;
|
|
980
|
-
/**
|
|
981
|
-
* constructCloudinaryUrl
|
|
982
|
-
*/
|
|
983
|
-
function constructCloudinaryUrl(_ref) {
|
|
984
|
-
var options = _ref.options,
|
|
985
|
-
config = _ref.config;
|
|
986
|
-
if (!cld) {
|
|
987
|
-
cld = new Cloudinary(_extends({
|
|
988
|
-
cloud: {
|
|
989
|
-
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
990
|
-
}
|
|
991
|
-
}, config));
|
|
992
|
-
}
|
|
993
|
-
var publicId = getPublicId(options == null ? void 0 : options.src);
|
|
994
|
-
var cldImage = cld.image(publicId);
|
|
995
|
-
transformationPlugins.forEach(function (_ref2) {
|
|
996
|
-
var plugin = _ref2.plugin;
|
|
997
|
-
// @ts-ignore
|
|
998
|
-
var _ref3 = plugin({
|
|
999
|
-
cldImage: cldImage,
|
|
1000
|
-
options: options
|
|
1001
|
-
}) || {},
|
|
1002
|
-
pluginOptions = _ref3.options;
|
|
1003
|
-
if (pluginOptions != null && pluginOptions.format && options) {
|
|
1004
|
-
options.format = pluginOptions.format;
|
|
1005
|
-
}
|
|
1006
|
-
if (pluginOptions != null && pluginOptions.width && options) {
|
|
1007
|
-
options.resize = {
|
|
1008
|
-
width: pluginOptions == null ? void 0 : pluginOptions.width
|
|
1009
|
-
};
|
|
1010
|
-
}
|
|
1011
|
-
});
|
|
1012
|
-
if (options != null && options.resize) {
|
|
1013
|
-
var _options$resize = options.resize,
|
|
1014
|
-
width = _options$resize.width,
|
|
1015
|
-
_options$resize$crop = _options$resize.crop,
|
|
1016
|
-
crop = _options$resize$crop === void 0 ? 'scale' : _options$resize$crop;
|
|
1017
|
-
cldImage.effect("c_" + crop + ",w_" + width);
|
|
1018
|
-
}
|
|
1019
|
-
return cldImage.setDeliveryType((options == null ? void 0 : options.deliveryType) || 'upload').format((options == null ? void 0 : options.format) || 'auto').delivery("q_" + ((options == null ? void 0 : options.quality) || 'auto')).toURL({
|
|
1020
|
-
trackedAnalytics: {
|
|
1021
|
-
sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
|
|
1022
|
-
sdkSemver: pkg.version,
|
|
1023
|
-
techVersion: nextPkg.version
|
|
1024
|
-
}
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
|
|
1029
|
-
* If it's recognized that is a url and it's not possible to get the public id, it warns the user.
|
|
1030
|
-
*
|
|
1031
|
-
* @param {string} src The cloudiary url or public id.
|
|
1032
|
-
*
|
|
1033
|
-
* @return {string} The images public id
|
|
1034
|
-
*/
|
|
1035
|
-
function getPublicId(src) {
|
|
1036
|
-
if (typeof src !== 'string') {
|
|
1037
|
-
throw new Error("Invalid src of type " + typeof src);
|
|
1038
|
-
}
|
|
1039
|
-
if (src.includes('res.cloudinary.com')) {
|
|
1040
|
-
var regexWithTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
1041
|
-
var regexWithoutTransformations = /(https?)\:\/\/(res.cloudinary.com)\/([^\/]+)\/(image|video|raw)\/(upload|authenticated)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?/;
|
|
1042
|
-
var withTransformations = src.match(regexWithTransformations);
|
|
1043
|
-
var withoutTransformations = src.match(regexWithoutTransformations);
|
|
1044
|
-
if (withTransformations) {
|
|
1045
|
-
return withTransformations[withTransformations.length - 1];
|
|
1046
|
-
} else if (withoutTransformations) {
|
|
1047
|
-
return withoutTransformations[withoutTransformations.length - 1];
|
|
1048
|
-
} else {
|
|
1049
|
-
console.warn("Not possible to retrieve the publicUrl from " + src + ", make sure it's a valid cloudinary image url.");
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
return src;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* createPlaceholderUrl
|
|
1056
|
-
*/
|
|
1057
|
-
function createPlaceholderUrl(_ref4) {
|
|
1058
|
-
var src = _ref4.src,
|
|
1059
|
-
_ref4$placeholder = _ref4.placeholder,
|
|
1060
|
-
placeholder = _ref4$placeholder === void 0 ? true : _ref4$placeholder,
|
|
1061
|
-
config = _ref4.config;
|
|
143
|
+
function createPlaceholderUrl(_ref) {
|
|
144
|
+
var src = _ref.src,
|
|
145
|
+
_ref$placeholder = _ref.placeholder,
|
|
146
|
+
placeholder = _ref$placeholder === void 0 ? true : _ref$placeholder;
|
|
1062
147
|
var rawTransformations = [];
|
|
1063
148
|
if (placeholder === 'grayscale') {
|
|
1064
149
|
rawTransformations.push('e_grayscale');
|
|
@@ -1075,7 +160,17 @@ function createPlaceholderUrl(_ref4) {
|
|
|
1075
160
|
quality: 1,
|
|
1076
161
|
rawTransformations: rawTransformations
|
|
1077
162
|
},
|
|
1078
|
-
config:
|
|
163
|
+
config: {
|
|
164
|
+
cloud: {
|
|
165
|
+
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
analytics: {
|
|
169
|
+
sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
|
|
170
|
+
sdkSemver: NEXT_CLOUDINARY_VERSION,
|
|
171
|
+
techVersion: NEXT_VERSION,
|
|
172
|
+
feature: ''
|
|
173
|
+
}
|
|
1079
174
|
});
|
|
1080
175
|
}
|
|
1081
176
|
|
|
@@ -1101,7 +196,17 @@ function cloudinaryLoader(_ref) {
|
|
|
1101
196
|
}
|
|
1102
197
|
return constructCloudinaryUrl({
|
|
1103
198
|
options: options,
|
|
1104
|
-
config:
|
|
199
|
+
config: _extends({
|
|
200
|
+
cloud: {
|
|
201
|
+
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
202
|
+
}
|
|
203
|
+
}, cldConfig),
|
|
204
|
+
analytics: {
|
|
205
|
+
sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
|
|
206
|
+
sdkSemver: NEXT_CLOUDINARY_VERSION,
|
|
207
|
+
techVersion: NEXT_VERSION,
|
|
208
|
+
feature: ''
|
|
209
|
+
}
|
|
1105
210
|
});
|
|
1106
211
|
}
|
|
1107
212
|
|
|
@@ -1122,7 +227,7 @@ var CldImage = function CldImage(props) {
|
|
|
1122
227
|
return Promise.reject(e);
|
|
1123
228
|
}
|
|
1124
229
|
};
|
|
1125
|
-
var CLD_OPTIONS = ['deliveryType'];
|
|
230
|
+
var CLD_OPTIONS = ['deliveryType', 'preserveTransformations'];
|
|
1126
231
|
transformationPlugins.forEach(function (_ref) {
|
|
1127
232
|
var _ref$props = _ref.props,
|
|
1128
233
|
props = _ref$props === void 0 ? [] : _ref$props;
|
|
@@ -1133,7 +238,6 @@ var CldImage = function CldImage(props) {
|
|
|
1133
238
|
CLD_OPTIONS.push(prop);
|
|
1134
239
|
});
|
|
1135
240
|
});
|
|
1136
|
-
// Construct the base Image component props by filtering out Cloudinary-specific props
|
|
1137
241
|
var imageProps = {
|
|
1138
242
|
alt: props.alt,
|
|
1139
243
|
src: props.src
|
|
@@ -1149,11 +253,10 @@ var CldImage = function CldImage(props) {
|
|
|
1149
253
|
var _useState = useState(defaultImgKey),
|
|
1150
254
|
imgKey = _useState[0],
|
|
1151
255
|
setImgKey = _useState[1];
|
|
1152
|
-
// Construct Cloudinary-specific props by looking for values for any of the supported prop keys
|
|
1153
256
|
var cldOptions = {};
|
|
1154
257
|
CLD_OPTIONS.forEach(function (key) {
|
|
1155
258
|
if (props[key]) {
|
|
1156
|
-
cldOptions[key] = props[key];
|
|
259
|
+
cldOptions[key] = props[key] || undefined;
|
|
1157
260
|
}
|
|
1158
261
|
});
|
|
1159
262
|
// If we see a placeholder option, configure a Cloudinary-based URL.
|
|
@@ -1165,7 +268,15 @@ var CldImage = function CldImage(props) {
|
|
|
1165
268
|
//
|
|
1166
269
|
// https://nextjs.org/docs/api-reference/next/image#blurdataurl
|
|
1167
270
|
if (imageProps.placeholder) {
|
|
1168
|
-
var publicId
|
|
271
|
+
var publicId;
|
|
272
|
+
if (props.src.startsWith('https://')) {
|
|
273
|
+
try {
|
|
274
|
+
publicId = getPublicId(props.src);
|
|
275
|
+
} catch (e) {}
|
|
276
|
+
}
|
|
277
|
+
if (!publicId) {
|
|
278
|
+
publicId = props.src;
|
|
279
|
+
}
|
|
1169
280
|
imageProps.blurDataURL = createPlaceholderUrl({
|
|
1170
281
|
src: publicId,
|
|
1171
282
|
placeholder: props.placeholder
|
|
@@ -1174,10 +285,16 @@ var CldImage = function CldImage(props) {
|
|
|
1174
285
|
imageProps.placeholder = 'blur';
|
|
1175
286
|
}
|
|
1176
287
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
288
|
+
// Try to preserve the original transformations from the Cloudinary URL passed in
|
|
289
|
+
// to the component. This only works if the URL has a version number on it and otherwise
|
|
290
|
+
// will fail to load
|
|
291
|
+
if (props.preserveTransformations) {
|
|
292
|
+
try {
|
|
293
|
+
var transformations = getTransformations(props.src);
|
|
294
|
+
cldOptions.rawTransformations = [].concat(transformations.flat(), props.rawTransformations || []);
|
|
295
|
+
} catch (e) {
|
|
296
|
+
console.warn("Failed to preserve transformations: " + e.message);
|
|
297
|
+
}
|
|
1181
298
|
}
|
|
1182
299
|
return /*#__PURE__*/jsx(Image, _extends({}, imageProps, {
|
|
1183
300
|
loader: function loader(loaderOptions) {
|
|
@@ -1201,14 +318,26 @@ var CldOgImage = function CldOgImage(_ref) {
|
|
|
1201
318
|
twitterTitle = _ref.twitterTitle,
|
|
1202
319
|
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
1203
320
|
var options = _extends({}, props, {
|
|
1204
|
-
|
|
1205
|
-
height: props.height || IMAGE_HEIGHT,
|
|
321
|
+
alt: props.alt,
|
|
1206
322
|
crop: props.crop || 'fill',
|
|
1207
323
|
gravity: props.gravity || 'center',
|
|
1208
|
-
|
|
324
|
+
height: props.height || IMAGE_HEIGHT,
|
|
325
|
+
src: props.src,
|
|
326
|
+
width: props.width || IMAGE_WIDTH
|
|
1209
327
|
});
|
|
1210
328
|
var ogImageUrl = constructCloudinaryUrl({
|
|
1211
|
-
options: options
|
|
329
|
+
options: options,
|
|
330
|
+
config: {
|
|
331
|
+
cloud: {
|
|
332
|
+
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
analytics: {
|
|
336
|
+
sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
|
|
337
|
+
sdkSemver: NEXT_CLOUDINARY_VERSION,
|
|
338
|
+
techVersion: NEXT_VERSION,
|
|
339
|
+
feature: ''
|
|
340
|
+
}
|
|
1212
341
|
});
|
|
1213
342
|
// We need to include the tags within the Next.js Head component rather than
|
|
1214
343
|
// direcly adding them inside of the Head otherwise we get unexpected results
|
|
@@ -1373,5 +502,5 @@ var CldUploadButton = function CldUploadButton(_ref) {
|
|
|
1373
502
|
});
|
|
1374
503
|
};
|
|
1375
504
|
|
|
1376
|
-
export { CldImage, CldOgImage, CldUploadButton, CldUploadWidget, cloudinaryLoader
|
|
505
|
+
export { CldImage, CldOgImage, CldUploadButton, CldUploadWidget, cloudinaryLoader };
|
|
1377
506
|
//# sourceMappingURL=next-cloudinary.module.js.map
|