next-cloudinary 1.10.0 → 1.12.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
@@ -179,6 +179,7 @@ yarn test
179
179
  <td align="center" valign="top" width="14.28%"><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
180
  <td align="center" valign="top" width="14.28%"><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>
181
181
  <td align="center" valign="top" width="14.28%"><a href="https://leeconlin.co.uk"><img src="https://avatars.githubusercontent.com/u/1023581?v=4?s=100" width="100px;" alt="Lee Conlin"/><br /><sub><b>Lee Conlin</b></sub></a><br /><a href="https://github.com/colbyfayock/next-cloudinary/commits?author=hades200082" title="Code">💻</a></td>
182
+ <td align="center" valign="top" width="14.28%"><a href="https://wannabe-polyglot.com"><img src="https://avatars.githubusercontent.com/u/1134611?v=4?s=100" width="100px;" alt="Ryan Smith"/><br /><sub><b>Ryan Smith</b></sub></a><br /><a href="https://github.com/colbyfayock/next-cloudinary/commits?author=tanzoniteblack" title="Code">💻</a></td>
182
183
  </tr>
183
184
  </tbody>
184
185
  </table>
@@ -1,6 +1,7 @@
1
1
  var react = require('react');
2
2
  var Image = require('next/image');
3
3
  var urlGen = require('@cloudinary/url-gen');
4
+ var nextPkg = require('next/package.json');
4
5
  var jsxRuntime = require('react/jsx-runtime');
5
6
  var Head = require('next/head');
6
7
  var Script = require('next/script');
@@ -8,6 +9,7 @@ var Script = require('next/script');
8
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
10
 
10
11
  var Image__default = /*#__PURE__*/_interopDefaultLegacy(Image);
12
+ var nextPkg__default = /*#__PURE__*/_interopDefaultLegacy(nextPkg);
11
13
  var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
12
14
  var Script__default = /*#__PURE__*/_interopDefaultLegacy(Script);
13
15
 
@@ -874,8 +876,56 @@ var zoompanPlugin = {
874
876
  plugin: plugin
875
877
  };
876
878
 
877
- /**
878
- * pollForProcessingImage
879
+ var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
880
+
881
+ var name = "next-cloudinary";
882
+ var version = "1.12.0";
883
+ var main = "dist/next-cloudinary.umd.js";
884
+ var module$1 = "dist/next-cloudinary.module.js";
885
+ var source = "src/index.ts";
886
+ var types = "dist/index.d.ts";
887
+ var scripts = {
888
+ build: "microbundle --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
889
+ dev: "microbundle watch --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
890
+ prepublishOnly: "cp ../README.md . && yarn build",
891
+ postpublish: "rm ./README.md",
892
+ test: "jest"
893
+ };
894
+ var dependencies = {
895
+ "@cloudinary/url-gen": "^1.8.6"
896
+ };
897
+ var devDependencies = {
898
+ "@babel/core": "^7.19.6",
899
+ "@babel/preset-env": "^7.19.4",
900
+ "@types/jest": "^29.2.0",
901
+ "babel-jest": "^29.2.2",
902
+ dotenv: "^16.0.3",
903
+ jest: "^29.2.2",
904
+ "jest-environment-jsdom": "^29.2.2",
905
+ microbundle: "^0.15.1",
906
+ "ts-jest": "^29.0.3",
907
+ typescript: "^4.9.4"
908
+ };
909
+ var peerDependencies = {
910
+ next: "^12 || ^13",
911
+ react: "^17 || ^18"
912
+ };
913
+ var pkg = {
914
+ name: name,
915
+ version: version,
916
+ main: main,
917
+ module: module$1,
918
+ "umd:main": "dist/next-cloudinary.umd.js",
919
+ source: source,
920
+ types: types,
921
+ scripts: scripts,
922
+ dependencies: dependencies,
923
+ devDependencies: devDependencies,
924
+ peerDependencies: peerDependencies
925
+ };
926
+
927
+ /**
928
+ * pollForProcessingImage
879
929
  */
880
930
 
881
931
  function _catch(body, recover) {
@@ -931,14 +981,11 @@ var transformationPlugins = [
931
981
  removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, namedTransformationsPlugin, underlaysPlugin, zoompanPlugin,
932
982
  // Raw transformations needs to be last simply to make sure
933
983
  // it's always expected to applied the same way
934
-
935
984
  rawTransformationsPlugin];
936
985
  var cld;
937
-
938
- /**
939
- * constructCloudinaryUrl
986
+ /**
987
+ * constructCloudinaryUrl
940
988
  */
941
-
942
989
  function constructCloudinaryUrl(_ref) {
943
990
  var options = _ref.options,
944
991
  config = _ref.config;
@@ -946,50 +993,51 @@ function constructCloudinaryUrl(_ref) {
946
993
  cld = new urlGen.Cloudinary(_extends({
947
994
  cloud: {
948
995
  cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
949
- },
950
- url: {
951
- // Used to avoid issues with SSR particularly for the blurred placeholder
952
- analytics: false
953
996
  }
954
997
  }, config));
955
998
  }
956
- var publicId = getPublicId(options.src);
999
+ var publicId = getPublicId(options == null ? void 0 : options.src);
957
1000
  var cldImage = cld.image(publicId);
958
1001
  transformationPlugins.forEach(function (_ref2) {
959
1002
  var plugin = _ref2.plugin;
1003
+ // @ts-ignore
960
1004
  var _ref3 = plugin({
961
1005
  cldImage: cldImage,
962
1006
  options: options
963
1007
  }) || {},
964
1008
  pluginOptions = _ref3.options;
965
- if (pluginOptions != null && pluginOptions.format) {
1009
+ if (pluginOptions != null && pluginOptions.format && options) {
966
1010
  options.format = pluginOptions.format;
967
1011
  }
968
- if (pluginOptions != null && pluginOptions.width) {
1012
+ if (pluginOptions != null && pluginOptions.width && options) {
969
1013
  options.resize = {
970
1014
  width: pluginOptions == null ? void 0 : pluginOptions.width
971
1015
  };
972
1016
  }
973
1017
  });
974
- if (options.resize) {
1018
+ if (options != null && options.resize) {
975
1019
  var _options$resize = options.resize,
976
1020
  width = _options$resize.width,
977
1021
  _options$resize$crop = _options$resize.crop,
978
1022
  crop = _options$resize$crop === void 0 ? 'scale' : _options$resize$crop;
979
1023
  cldImage.effect("c_" + crop + ",w_" + width);
980
1024
  }
981
- return cldImage.setDeliveryType(options.deliveryType || 'upload').format(options.format || 'auto').delivery("q_" + (options.quality || 'auto')).toURL();
1025
+ 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({
1026
+ trackedAnalytics: {
1027
+ sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
1028
+ sdkSemver: pkg.version,
1029
+ techVersion: nextPkg__default["default"].version
1030
+ }
1031
+ });
982
1032
  }
983
-
984
- /**
985
- * Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
986
- * If it's recognized that is a url and it's not possible to get the public id, it warns the user.
987
- *
988
- * @param {string} src The cloudiary url or public id.
989
- *
990
- * @return {string} The images public id
1033
+ /**
1034
+ * Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
1035
+ * If it's recognized that is a url and it's not possible to get the public id, it warns the user.
1036
+ *
1037
+ * @param {string} src The cloudiary url or public id.
1038
+ *
1039
+ * @return {string} The images public id
991
1040
  */
992
-
993
1041
  function getPublicId(src) {
994
1042
  if (typeof src !== 'string') {
995
1043
  throw new Error("Invalid src of type " + typeof src);
@@ -1009,11 +1057,9 @@ function getPublicId(src) {
1009
1057
  }
1010
1058
  return src;
1011
1059
  }
1012
-
1013
- /**
1014
- * createPlaceholderUrl
1060
+ /**
1061
+ * createPlaceholderUrl
1015
1062
  */
1016
-
1017
1063
  function createPlaceholderUrl(_ref4) {
1018
1064
  var src = _ref4.src,
1019
1065
  _ref4$placeholder = _ref4.placeholder,
@@ -1066,8 +1112,8 @@ function cloudinaryLoader(_ref) {
1066
1112
  }
1067
1113
 
1068
1114
  var CldImage = function CldImage(props) {
1069
- /**
1070
- * handleOnError
1115
+ /**
1116
+ * handleOnError
1071
1117
  */
1072
1118
  var handleOnError = function handleOnError(options) {
1073
1119
  try {
@@ -1093,10 +1139,11 @@ var CldImage = function CldImage(props) {
1093
1139
  CLD_OPTIONS.push(prop);
1094
1140
  });
1095
1141
  });
1096
-
1097
1142
  // Construct the base Image component props by filtering out Cloudinary-specific props
1098
-
1099
- var imageProps = {};
1143
+ var imageProps = {
1144
+ alt: props.alt,
1145
+ src: props.src
1146
+ };
1100
1147
  Object.keys(props).filter(function (key) {
1101
1148
  return !CLD_OPTIONS.includes(key);
1102
1149
  }).forEach(function (key) {
@@ -1108,16 +1155,13 @@ var CldImage = function CldImage(props) {
1108
1155
  var _useState = react.useState(defaultImgKey),
1109
1156
  imgKey = _useState[0],
1110
1157
  setImgKey = _useState[1];
1111
-
1112
1158
  // Construct Cloudinary-specific props by looking for values for any of the supported prop keys
1113
-
1114
1159
  var cldOptions = {};
1115
1160
  CLD_OPTIONS.forEach(function (key) {
1116
1161
  if (props[key]) {
1117
1162
  cldOptions[key] = props[key];
1118
1163
  }
1119
1164
  });
1120
-
1121
1165
  // If we see a placeholder option, configure a Cloudinary-based URL.
1122
1166
  // The resulting image will always be blurred per Next.js, so we're
1123
1167
  // limited on options for placeholders.
@@ -1126,7 +1170,6 @@ var CldImage = function CldImage(props) {
1126
1170
  // an Image component prop as opposed to simply the URL
1127
1171
  //
1128
1172
  // https://nextjs.org/docs/api-reference/next/image#blurdataurl
1129
-
1130
1173
  if (imageProps.placeholder) {
1131
1174
  var publicId = getPublicId(props.src);
1132
1175
  imageProps.blurDataURL = createPlaceholderUrl({
@@ -1139,7 +1182,8 @@ var CldImage = function CldImage(props) {
1139
1182
  }
1140
1183
  if (props.src && props.preserveTransformations) {
1141
1184
  var transformations = getTransformations(props.src, props.preserveTransformations);
1142
- imageProps.rawTransformations = [].concat(imageProps.rawTransformations, transformations);
1185
+ var rawTransformations = imageProps.rawTransformations ? [].concat(imageProps.rawTransformations) : [];
1186
+ imageProps.rawTransformations = [].concat(rawTransformations, transformations);
1143
1187
  }
1144
1188
  return /*#__PURE__*/jsxRuntime.jsx(Image__default["default"], _extends({}, imageProps, {
1145
1189
  loader: function loader(loaderOptions) {
@@ -1166,15 +1210,14 @@ var CldOgImage = function CldOgImage(_ref) {
1166
1210
  width: props.width || IMAGE_WIDTH,
1167
1211
  height: props.height || IMAGE_HEIGHT,
1168
1212
  crop: props.crop || 'fill',
1169
- gravity: props.gravity || 'center'
1213
+ gravity: props.gravity || 'center',
1214
+ alt: props.alt
1170
1215
  });
1171
1216
  var ogImageUrl = constructCloudinaryUrl({
1172
1217
  options: options
1173
1218
  });
1174
-
1175
1219
  // We need to include the tags within the Next.js Head component rather than
1176
1220
  // direcly adding them inside of the Head otherwise we get unexpected results
1177
-
1178
1221
  return /*#__PURE__*/jsxRuntime.jsxs(Head__default["default"], {
1179
1222
  children: [/*#__PURE__*/jsxRuntime.jsx("meta", {
1180
1223
  property: "og:image",
@@ -1213,12 +1256,10 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1213
1256
  var cloudinary = react.useRef();
1214
1257
  var widget = react.useRef();
1215
1258
  var signed = !!signatureEndpoint;
1216
-
1217
- /**
1218
- * generateSignature
1219
- * @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
1259
+ /**
1260
+ * generateSignature
1261
+ * @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
1220
1262
  */
1221
-
1222
1263
  function generateSignature(callback, paramsToSign) {
1223
1264
  fetch(signatureEndpoint, {
1224
1265
  method: "POST",
@@ -1232,19 +1273,16 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1232
1273
  callback(signature);
1233
1274
  });
1234
1275
  }
1235
-
1236
- /**
1237
- * createWidget
1238
- * @description Creates a new instance of the Cloudinary widget and stores in a ref
1276
+ /**
1277
+ * createWidget
1278
+ * @description Creates a new instance of the Cloudinary widget and stores in a ref
1239
1279
  */
1240
-
1241
1280
  function createWidget() {
1242
1281
  var _cloudinary$current;
1243
1282
  // When creating a signed upload, you need to provide both your Cloudinary API Key
1244
1283
  // as well as a signature generator function that will sign any paramters
1245
1284
  // either on page load or during the upload process. Read more about signed uploads at:
1246
1285
  // https://cloudinary.com/documentation/upload_widget#signed_uploads
1247
-
1248
1286
  var uploadOptions = _extends({
1249
1287
  cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
1250
1288
  uploadPreset: uploadPreset || process.env.NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET,
@@ -1252,13 +1290,12 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1252
1290
  }, options);
1253
1291
  if (signed) {
1254
1292
  uploadOptions.uploadSignature = generateSignature;
1255
-
1256
1293
  // No need for apiSecret here because of api/sign-cloudinary-params
1257
-
1258
1294
  if (!uploadOptions.apiKey) {
1259
1295
  return new Error("Signed Upload needs apiKey!");
1260
1296
  }
1261
1297
  }
1298
+ // @ts-ignore
1262
1299
  return (_cloudinary$current = cloudinary.current) == null ? void 0 : _cloudinary$current.createUploadWidget(uploadOptions, function (error, result) {
1263
1300
  // The callback is a bit more chatty than failed or success so
1264
1301
  // only trigger when one of those are the case. You can additionally
@@ -1269,25 +1306,23 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1269
1306
  }
1270
1307
  });
1271
1308
  }
1272
-
1273
- /**
1274
- * open
1275
- * @description When triggered, uses the current widget instance to open the upload modal
1309
+ /**
1310
+ * open
1311
+ * @description When triggered, uses the current widget instance to open the upload modal
1276
1312
  */
1277
-
1278
1313
  function open() {
1279
1314
  if (!(widget != null && widget.current)) {
1280
1315
  widget.current = createWidget();
1281
1316
  }
1317
+ // @ts-ignore
1282
1318
  (widget == null ? void 0 : widget.current) && widget.current.open();
1283
1319
  }
1284
-
1285
- /**
1286
- * handleOnLoad
1287
- * @description Stores the Cloudinary window instance to a ref when the widget script loads
1320
+ /**
1321
+ * handleOnLoad
1322
+ * @description Stores the Cloudinary window instance to a ref when the widget script loads
1288
1323
  */
1289
-
1290
1324
  function handleOnLoad() {
1325
+ // @ts-ignore
1291
1326
  cloudinary.current = window.cloudinary;
1292
1327
  }
1293
1328
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {