next-cloudinary 1.6.0 → 1.8.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.
@@ -249,6 +249,10 @@ var effects = {
249
249
  prefix: 'e',
250
250
  qualifier: 'improve'
251
251
  },
252
+ multiply: {
253
+ prefix: 'e',
254
+ qualifier: 'multiply'
255
+ },
252
256
  negate: {
253
257
  prefix: 'e',
254
258
  qualifier: 'negate'
@@ -264,6 +268,10 @@ var effects = {
264
268
  prefix: 'e',
265
269
  qualifier: 'outline'
266
270
  },
271
+ overlay: {
272
+ prefix: 'e',
273
+ qualifier: 'overlay'
274
+ },
267
275
  pixelate: {
268
276
  prefix: 'e',
269
277
  qualifier: 'pixelate'
@@ -288,6 +296,10 @@ var effects = {
288
296
  prefix: 'e',
289
297
  qualifier: 'saturation'
290
298
  },
299
+ screen: {
300
+ prefix: 'e',
301
+ qualifier: 'screen'
302
+ },
291
303
  sepia: {
292
304
  prefix: 'e',
293
305
  qualifier: 'sepia'
@@ -330,6 +342,57 @@ var effects = {
330
342
  }
331
343
  };
332
344
 
345
+ /**
346
+ * constructTransformation
347
+ */
348
+
349
+ function constructTransformation(_ref) {
350
+ var prefix = _ref.prefix,
351
+ qualifier = _ref.qualifier,
352
+ value = _ref.value;
353
+ var transformation = '';
354
+ if (prefix) {
355
+ transformation = prefix + "_";
356
+ }
357
+ if (value === true || value === 'true') {
358
+ return "" + transformation + qualifier;
359
+ }
360
+ if (typeof value === 'string' || typeof value === 'number') {
361
+ if (prefix) {
362
+ return "" + transformation + qualifier + ":" + value;
363
+ } else {
364
+ return qualifier + "_" + value;
365
+ }
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Retrieves the transformations added to a cloudiary image url. If no transformation is recognized it returns an empty array.
371
+ *
372
+ * @param {string} src The cloudiary url.
373
+ *
374
+ * @return {array} The array of transformations
375
+ */
376
+
377
+ function getTransformations(src, preserveTransformations) {
378
+ if (typeof src !== "string") {
379
+ throw new Error("Invalid src of type " + typeof src);
380
+ }
381
+ if (src.includes("res.cloudinary.com") && preserveTransformations) {
382
+ var regex = new RegExp("(https?)://(res.cloudinary.com)/([^/]+)/(image|video|raw)/(upload|authenticated)/(.*)/(v[0-9]+)/(.+)(?:.[a-z]{3})?", "gi");
383
+ var groups = regex.exec(src);
384
+ var transformationStr = groups.slice(1).find(function (i) {
385
+ return i.includes("_");
386
+ });
387
+ if (transformationStr) {
388
+ return transformationStr.split(",").join("/").split("/");
389
+ } else {
390
+ return [];
391
+ }
392
+ }
393
+ return [];
394
+ }
395
+
333
396
  var props$6 = [].concat(Object.keys(effects), ['effects']);
334
397
  function plugin$6(_temp) {
335
398
  var _ref = _temp === void 0 ? {} : _temp,
@@ -360,36 +423,16 @@ function plugin$6(_temp) {
360
423
  cldImage.effect(transformationString);
361
424
  });
362
425
  }
363
-
364
- /**
365
- * constructEffect
366
- */
367
-
368
- function constructEffect(_ref2) {
369
- var effect = _ref2.effect,
370
- value = _ref2.value;
371
- var prefix = effect.prefix,
372
- qualifier = effect.qualifier;
373
- var transformation = '';
374
- if (prefix) {
375
- transformation = prefix + "_";
376
- }
377
- if (value === true) {
378
- return "" + transformation + qualifier;
379
- } else if (typeof value === 'string' || typeof value === 'number') {
380
- if (prefix) {
381
- return "" + transformation + qualifier + ":" + value;
382
- } else {
383
- return qualifier + "_" + value;
384
- }
385
- }
386
- }
387
- function constructTransformationString(_ref3) {
388
- var effects = _ref3.effects,
389
- options = _ref3.options;
426
+ function constructTransformationString(_ref2) {
427
+ var effects = _ref2.effects,
428
+ options = _ref2.options;
390
429
  return Object.keys(effects).map(function (key) {
391
- return constructEffect({
392
- effect: effects[key],
430
+ var _effects$key = effects[key],
431
+ prefix = _effects$key.prefix,
432
+ qualifier = _effects$key.qualifier;
433
+ return constructTransformation({
434
+ qualifier: qualifier,
435
+ prefix: prefix,
393
436
  value: options[key]
394
437
  });
395
438
  });
@@ -415,7 +458,7 @@ function encodeBase64(value) {
415
458
  }
416
459
  }
417
460
 
418
- var _excluded$3 = ["publicId", "url", "position", "text", "effects"];
461
+ var _excluded$3 = ["publicId", "url", "position", "text", "effects", "appliedEffects"];
419
462
  var props$5 = ['text', 'overlays'];
420
463
  var DEFAULT_TEXT_OPTIONS = {
421
464
  color: 'black',
@@ -458,6 +501,8 @@ function plugin$5(_temp) {
458
501
  text$1 = _ref2.text,
459
502
  _ref2$effects = _ref2.effects,
460
503
  layerEffects = _ref2$effects === void 0 ? [] : _ref2$effects,
504
+ _ref2$appliedEffects = _ref2.appliedEffects,
505
+ appliedEffects = _ref2$appliedEffects === void 0 ? [] : _ref2$appliedEffects,
461
506
  options = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
462
507
  var hasPublicId = typeof publicId === 'string';
463
508
  var hasUrl = typeof url === 'string';
@@ -491,7 +536,11 @@ function plugin$5(_temp) {
491
536
  Object.keys(options).forEach(function (key) {
492
537
  if (!primary[key]) return;
493
538
  var qualifier = primary[key].qualifier;
494
- primary$1.push(qualifier + "_" + options[key]);
539
+ var transformation = constructTransformation({
540
+ qualifier: qualifier,
541
+ value: options[key]
542
+ });
543
+ primary$1.push(transformation);
495
544
  });
496
545
 
497
546
  // Layer effects
@@ -501,27 +550,33 @@ function plugin$5(_temp) {
501
550
 
502
551
  layerEffects.forEach(function (effect) {
503
552
  Object.keys(effect).forEach(function (key) {
504
- if (primary[key]) {
505
- var qualifier = primary[key].qualifier;
506
- primary$1.push(qualifier + "_" + effect[key]);
507
- } else if (effects[key]) {
508
- var _qualifiersEffects$ke = effects[key],
509
- _qualifier = _qualifiersEffects$ke.qualifier,
510
- prefix = _qualifiersEffects$ke.prefix;
511
- var transformation = '';
512
- if (prefix) {
513
- transformation = prefix + "_";
514
- }
515
- if (effect[key] === true) {
516
- primary$1.push("" + transformation + _qualifier);
517
- } else if (typeof effect[key] === 'string' || typeof effect[key] === 'number') {
518
- if (prefix) {
519
- primary$1.push("" + transformation + _qualifier + ":" + effect[key]);
520
- } else {
521
- primary$1.push(_qualifier + "_" + effect[key]);
522
- }
523
- }
524
- }
553
+ var _ref3 = primary[key] || effects[key] || {},
554
+ qualifier = _ref3.qualifier,
555
+ prefix = _ref3.prefix;
556
+ var transformation = constructTransformation({
557
+ qualifier: qualifier,
558
+ prefix: prefix,
559
+ value: effect[key]
560
+ });
561
+ primary$1.push(transformation);
562
+ });
563
+ });
564
+
565
+ // Applied Layer effects
566
+ // Similar to layer effects but they get appended to an additional transformation
567
+ // along with fl_layer_applied
568
+
569
+ appliedEffects.forEach(function (effect) {
570
+ Object.keys(effect).forEach(function (key) {
571
+ var _ref4 = primary[key] || effects[key] || {},
572
+ qualifier = _ref4.qualifier,
573
+ prefix = _ref4.prefix;
574
+ var transformation = constructTransformation({
575
+ qualifier: qualifier,
576
+ prefix: prefix,
577
+ value: effect[key]
578
+ });
579
+ applied.push(transformation);
525
580
  });
526
581
  });
527
582
 
@@ -558,7 +613,11 @@ function plugin$5(_temp) {
558
613
  Object.keys(position$1).forEach(function (key) {
559
614
  if (!position[key]) return;
560
615
  var qualifier = position[key].qualifier;
561
- applied.push(qualifier + "_" + position$1[key]);
616
+ var transformation = constructTransformation({
617
+ qualifier: qualifier,
618
+ value: position$1[key]
619
+ });
620
+ applied.push(transformation);
562
621
  });
563
622
  }
564
623
 
@@ -933,33 +992,6 @@ function getPublicId(src) {
933
992
  return src;
934
993
  }
935
994
 
936
- /**
937
- * Retrieves the transformations added to a cloudiary image url. If no transformation is recognized it returns an empty array.
938
- *
939
- * @param {string} src The cloudiary url.
940
- *
941
- * @return {array} The array of transformations
942
- */
943
-
944
- function getTransformations(src, preserveTransformations) {
945
- if (typeof src !== "string") {
946
- throw new Error("Invalid src of type " + typeof src);
947
- }
948
- if (src.includes("res.cloudinary.com") && preserveTransformations) {
949
- var regex = new RegExp("(https?)://(res.cloudinary.com)/([^/]+)/(image|video|raw)/(upload|authenticated)/(.*)/(v[0-9]+)/(.+)(?:.[a-z]{3})?", "gi");
950
- var groups = regex.exec(src);
951
- var transformationStr = groups.slice(1).find(function (i) {
952
- return i.includes("_");
953
- });
954
- if (transformationStr) {
955
- return transformationStr.split(",").join("/").split("/");
956
- } else {
957
- return [];
958
- }
959
- }
960
- return [];
961
- }
962
-
963
995
  /**
964
996
  * createPlaceholderUrl
965
997
  */
@@ -1294,6 +1326,8 @@ exports.CldOgImage = CldOgImage;
1294
1326
  exports.CldUploadButton = CldUploadButton;
1295
1327
  exports.CldUploadWidget = CldUploadWidget;
1296
1328
  exports.cloudinaryLoader = cloudinaryLoader;
1329
+ exports.constructCloudinaryUrl = constructCloudinaryUrl;
1330
+ exports.effects = effects;
1297
1331
  exports.position = position;
1298
1332
  exports.primary = primary;
1299
1333
  exports.text = text;