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