next-cloudinary 1.9.0 → 1.11.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.
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const CldImage: (props: any) => JSX.Element;
3
+ export default CldImage;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ declare const CldOgImage: ({ excludeTags, twitterTitle, ...props }: {
3
+ [x: string]: any;
4
+ excludeTags?: string[] | undefined;
5
+ twitterTitle: any;
6
+ }) => JSX.Element;
7
+ export default CldOgImage;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ declare const CldUploadButton: ({ children, onClick, onUpload, options, signatureEndpoint, uploadPreset, ...props }: {
3
+ [x: string]: any;
4
+ children: any;
5
+ onClick: any;
6
+ onUpload: any;
7
+ options: any;
8
+ signatureEndpoint: any;
9
+ uploadPreset: any;
10
+ }) => JSX.Element;
11
+ export default CldUploadButton;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ declare const CldUploadWidget: ({ children, onUpload, options, signatureEndpoint, uploadPreset, }: {
3
+ children: any;
4
+ onUpload: any;
5
+ options: any;
6
+ signatureEndpoint: any;
7
+ uploadPreset: any;
8
+ }) => JSX.Element;
9
+ export default CldUploadWidget;
@@ -0,0 +1,7 @@
1
+ export { default as CldImage } from './components/CldImage';
2
+ export { default as CldOgImage } from './components/CldOgImage';
3
+ export { default as CldUploadButton } from './components/CldUploadButton';
4
+ export { default as CldUploadWidget } from './components/CldUploadWidget';
5
+ export { cloudinaryLoader } from './loaders/cloudinary-loader';
6
+ export { primary, position, text, effects } from './constants/qualifiers';
7
+ export { constructCloudinaryUrl } from './lib/cloudinary';
@@ -0,0 +1,45 @@
1
+ import * as effectsPlugin from '../plugins/effects';
2
+ import ICloudinaryConfigurations from '@cloudinary/url-gen/config/interfaces/Config/ICloudinaryConfigurations';
3
+ export declare const transformationPlugins: (typeof effectsPlugin)[];
4
+ interface ImageUrlOptions {
5
+ src?: string;
6
+ width?: number;
7
+ quality?: number;
8
+ deliveryType?: string;
9
+ format?: string;
10
+ rawTransformations?: string[];
11
+ resize?: {
12
+ crop?: string;
13
+ width?: number;
14
+ };
15
+ }
16
+ interface ConstructUrlProps {
17
+ options?: ImageUrlOptions;
18
+ config?: ICloudinaryConfigurations;
19
+ }
20
+ /**
21
+ * constructCloudinaryUrl
22
+ */
23
+ export declare function constructCloudinaryUrl({ options, config }: ConstructUrlProps): string;
24
+ /**
25
+ * Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
26
+ * If it's recognized that is a url and it's not possible to get the public id, it warns the user.
27
+ *
28
+ * @param {string} src The cloudiary url or public id.
29
+ *
30
+ * @return {string} The images public id
31
+ */
32
+ export declare function getPublicId(src: any): string;
33
+ /**
34
+ * createPlaceholderUrl
35
+ */
36
+ export declare function createPlaceholderUrl({ src, placeholder, config }: {
37
+ src?: any;
38
+ placeholder?: boolean | string;
39
+ config?: any;
40
+ }): string;
41
+ /**
42
+ * pollForProcessingImage
43
+ */
44
+ export declare function pollForProcessingImage(options: any): Promise<boolean>;
45
+ export {};
@@ -1,7 +1,6 @@
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');
5
4
  var jsxRuntime = require('react/jsx-runtime');
6
5
  var Head = require('next/head');
7
6
  var Script = require('next/script');
@@ -9,7 +8,6 @@ var Script = require('next/script');
9
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
9
 
11
10
  var Image__default = /*#__PURE__*/_interopDefaultLegacy(Image);
12
- var nextPkg__default = /*#__PURE__*/_interopDefaultLegacy(nextPkg);
13
11
  var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
14
12
  var Script__default = /*#__PURE__*/_interopDefaultLegacy(Script);
15
13
 
@@ -876,52 +874,8 @@ var zoompanPlugin = {
876
874
  plugin: plugin
877
875
  };
878
876
 
879
- var NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
880
-
881
- var name = "next-cloudinary";
882
- var version = "1.9.0";
883
- var main = "dist/next-cloudinary.umd.js";
884
- var module$1 = "dist/next-cloudinary.module.js";
885
- var source = "src/index.js";
886
- var scripts = {
887
- build: "microbundle --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
888
- dev: "microbundle watch --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
889
- prepublishOnly: "cp ../README.md . && yarn build",
890
- postpublish: "rm ./README.md",
891
- test: "jest"
892
- };
893
- var dependencies = {
894
- "@cloudinary/url-gen": "^1.8.6"
895
- };
896
- var devDependencies = {
897
- "@babel/core": "^7.19.6",
898
- "@babel/preset-env": "^7.19.4",
899
- "@types/jest": "^29.2.0",
900
- "babel-jest": "^29.2.2",
901
- dotenv: "^16.0.3",
902
- jest: "^29.2.2",
903
- "jest-environment-jsdom": "^29.2.2",
904
- microbundle: "^0.15.1"
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$1,
915
- "umd:main": "dist/next-cloudinary.umd.js",
916
- source: source,
917
- scripts: scripts,
918
- dependencies: dependencies,
919
- devDependencies: devDependencies,
920
- peerDependencies: peerDependencies
921
- };
922
-
923
- /**
924
- * pollForProcessingImage
877
+ /**
878
+ * pollForProcessingImage
925
879
  */
926
880
 
927
881
  function _catch(body, recover) {
@@ -977,14 +931,11 @@ var transformationPlugins = [
977
931
  removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, namedTransformationsPlugin, underlaysPlugin, zoompanPlugin,
978
932
  // Raw transformations needs to be last simply to make sure
979
933
  // it's always expected to applied the same way
980
-
981
934
  rawTransformationsPlugin];
982
935
  var cld;
983
-
984
- /**
985
- * constructCloudinaryUrl
936
+ /**
937
+ * constructCloudinaryUrl
986
938
  */
987
-
988
939
  function constructCloudinaryUrl(_ref) {
989
940
  var options = _ref.options,
990
941
  config = _ref.config;
@@ -992,52 +943,49 @@ function constructCloudinaryUrl(_ref) {
992
943
  cld = new urlGen.Cloudinary(_extends({
993
944
  cloud: {
994
945
  cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
946
+ },
947
+ url: {
948
+ // Used to avoid issues with SSR particularly for the blurred placeholder
949
+ analytics: false
995
950
  }
996
951
  }, config));
997
952
  }
998
- var publicId = getPublicId(options.src);
953
+ var publicId = getPublicId(options == null ? void 0 : options.src);
999
954
  var cldImage = cld.image(publicId);
1000
955
  transformationPlugins.forEach(function (_ref2) {
1001
956
  var plugin = _ref2.plugin;
957
+ // @ts-ignore
1002
958
  var _ref3 = plugin({
1003
959
  cldImage: cldImage,
1004
960
  options: options
1005
961
  }) || {},
1006
962
  pluginOptions = _ref3.options;
1007
- if (pluginOptions != null && pluginOptions.format) {
963
+ if (pluginOptions != null && pluginOptions.format && options) {
1008
964
  options.format = pluginOptions.format;
1009
965
  }
1010
- if (pluginOptions != null && pluginOptions.width) {
966
+ if (pluginOptions != null && pluginOptions.width && options) {
1011
967
  options.resize = {
1012
968
  width: pluginOptions == null ? void 0 : pluginOptions.width
1013
969
  };
1014
970
  }
1015
971
  });
1016
- if (options.resize) {
972
+ if (options != null && options.resize) {
1017
973
  var _options$resize = options.resize,
1018
974
  width = _options$resize.width,
1019
975
  _options$resize$crop = _options$resize.crop,
1020
976
  crop = _options$resize$crop === void 0 ? 'scale' : _options$resize$crop;
1021
977
  cldImage.effect("c_" + crop + ",w_" + width);
1022
978
  }
1023
- return cldImage.setDeliveryType(options.deliveryType || 'upload').format(options.format || 'auto').delivery("q_" + (options.quality || 'auto')).toURL({
1024
- trackedAnalytics: {
1025
- sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
1026
- sdkSemver: pkg.version,
1027
- techVersion: nextPkg__default["default"].version
1028
- }
1029
- });
979
+ 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();
1030
980
  }
1031
-
1032
- /**
1033
- * Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
1034
- * If it's recognized that is a url and it's not possible to get the public id, it warns the user.
1035
- *
1036
- * @param {string} src The cloudiary url or public id.
1037
- *
1038
- * @return {string} The images public id
981
+ /**
982
+ * Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
983
+ * If it's recognized that is a url and it's not possible to get the public id, it warns the user.
984
+ *
985
+ * @param {string} src The cloudiary url or public id.
986
+ *
987
+ * @return {string} The images public id
1039
988
  */
1040
-
1041
989
  function getPublicId(src) {
1042
990
  if (typeof src !== 'string') {
1043
991
  throw new Error("Invalid src of type " + typeof src);
@@ -1057,11 +1005,9 @@ function getPublicId(src) {
1057
1005
  }
1058
1006
  return src;
1059
1007
  }
1060
-
1061
- /**
1062
- * createPlaceholderUrl
1008
+ /**
1009
+ * createPlaceholderUrl
1063
1010
  */
1064
-
1065
1011
  function createPlaceholderUrl(_ref4) {
1066
1012
  var src = _ref4.src,
1067
1013
  _ref4$placeholder = _ref4.placeholder,
@@ -1114,8 +1060,8 @@ function cloudinaryLoader(_ref) {
1114
1060
  }
1115
1061
 
1116
1062
  var CldImage = function CldImage(props) {
1117
- /**
1118
- * handleOnError
1063
+ /**
1064
+ * handleOnError
1119
1065
  */
1120
1066
  var handleOnError = function handleOnError(options) {
1121
1067
  try {
@@ -1141,10 +1087,11 @@ var CldImage = function CldImage(props) {
1141
1087
  CLD_OPTIONS.push(prop);
1142
1088
  });
1143
1089
  });
1144
-
1145
1090
  // Construct the base Image component props by filtering out Cloudinary-specific props
1146
-
1147
- var imageProps = {};
1091
+ var imageProps = {
1092
+ alt: props.alt,
1093
+ src: props.src
1094
+ };
1148
1095
  Object.keys(props).filter(function (key) {
1149
1096
  return !CLD_OPTIONS.includes(key);
1150
1097
  }).forEach(function (key) {
@@ -1156,16 +1103,13 @@ var CldImage = function CldImage(props) {
1156
1103
  var _useState = react.useState(defaultImgKey),
1157
1104
  imgKey = _useState[0],
1158
1105
  setImgKey = _useState[1];
1159
-
1160
1106
  // Construct Cloudinary-specific props by looking for values for any of the supported prop keys
1161
-
1162
1107
  var cldOptions = {};
1163
1108
  CLD_OPTIONS.forEach(function (key) {
1164
1109
  if (props[key]) {
1165
1110
  cldOptions[key] = props[key];
1166
1111
  }
1167
1112
  });
1168
-
1169
1113
  // If we see a placeholder option, configure a Cloudinary-based URL.
1170
1114
  // The resulting image will always be blurred per Next.js, so we're
1171
1115
  // limited on options for placeholders.
@@ -1174,7 +1118,6 @@ var CldImage = function CldImage(props) {
1174
1118
  // an Image component prop as opposed to simply the URL
1175
1119
  //
1176
1120
  // https://nextjs.org/docs/api-reference/next/image#blurdataurl
1177
-
1178
1121
  if (imageProps.placeholder) {
1179
1122
  var publicId = getPublicId(props.src);
1180
1123
  imageProps.blurDataURL = createPlaceholderUrl({
@@ -1187,7 +1130,8 @@ var CldImage = function CldImage(props) {
1187
1130
  }
1188
1131
  if (props.src && props.preserveTransformations) {
1189
1132
  var transformations = getTransformations(props.src, props.preserveTransformations);
1190
- imageProps.rawTransformations = [].concat(imageProps.rawTransformations, transformations);
1133
+ var rawTransformations = imageProps.rawTransformations ? [].concat(imageProps.rawTransformations) : [];
1134
+ imageProps.rawTransformations = [].concat(rawTransformations, transformations);
1191
1135
  }
1192
1136
  return /*#__PURE__*/jsxRuntime.jsx(Image__default["default"], _extends({}, imageProps, {
1193
1137
  loader: function loader(loaderOptions) {
@@ -1214,15 +1158,14 @@ var CldOgImage = function CldOgImage(_ref) {
1214
1158
  width: props.width || IMAGE_WIDTH,
1215
1159
  height: props.height || IMAGE_HEIGHT,
1216
1160
  crop: props.crop || 'fill',
1217
- gravity: props.gravity || 'center'
1161
+ gravity: props.gravity || 'center',
1162
+ alt: props.alt
1218
1163
  });
1219
1164
  var ogImageUrl = constructCloudinaryUrl({
1220
1165
  options: options
1221
1166
  });
1222
-
1223
1167
  // We need to include the tags within the Next.js Head component rather than
1224
1168
  // direcly adding them inside of the Head otherwise we get unexpected results
1225
-
1226
1169
  return /*#__PURE__*/jsxRuntime.jsxs(Head__default["default"], {
1227
1170
  children: [/*#__PURE__*/jsxRuntime.jsx("meta", {
1228
1171
  property: "og:image",
@@ -1261,12 +1204,10 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1261
1204
  var cloudinary = react.useRef();
1262
1205
  var widget = react.useRef();
1263
1206
  var signed = !!signatureEndpoint;
1264
-
1265
- /**
1266
- * generateSignature
1267
- * @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
1207
+ /**
1208
+ * generateSignature
1209
+ * @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
1268
1210
  */
1269
-
1270
1211
  function generateSignature(callback, paramsToSign) {
1271
1212
  fetch(signatureEndpoint, {
1272
1213
  method: "POST",
@@ -1280,19 +1221,16 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1280
1221
  callback(signature);
1281
1222
  });
1282
1223
  }
1283
-
1284
- /**
1285
- * createWidget
1286
- * @description Creates a new instance of the Cloudinary widget and stores in a ref
1224
+ /**
1225
+ * createWidget
1226
+ * @description Creates a new instance of the Cloudinary widget and stores in a ref
1287
1227
  */
1288
-
1289
1228
  function createWidget() {
1290
1229
  var _cloudinary$current;
1291
1230
  // When creating a signed upload, you need to provide both your Cloudinary API Key
1292
1231
  // as well as a signature generator function that will sign any paramters
1293
1232
  // either on page load or during the upload process. Read more about signed uploads at:
1294
1233
  // https://cloudinary.com/documentation/upload_widget#signed_uploads
1295
-
1296
1234
  var uploadOptions = _extends({
1297
1235
  cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
1298
1236
  uploadPreset: uploadPreset || process.env.NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET,
@@ -1300,13 +1238,12 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1300
1238
  }, options);
1301
1239
  if (signed) {
1302
1240
  uploadOptions.uploadSignature = generateSignature;
1303
-
1304
1241
  // No need for apiSecret here because of api/sign-cloudinary-params
1305
-
1306
1242
  if (!uploadOptions.apiKey) {
1307
1243
  return new Error("Signed Upload needs apiKey!");
1308
1244
  }
1309
1245
  }
1246
+ // @ts-ignore
1310
1247
  return (_cloudinary$current = cloudinary.current) == null ? void 0 : _cloudinary$current.createUploadWidget(uploadOptions, function (error, result) {
1311
1248
  // The callback is a bit more chatty than failed or success so
1312
1249
  // only trigger when one of those are the case. You can additionally
@@ -1317,25 +1254,23 @@ var CldUploadWidget = function CldUploadWidget(_ref) {
1317
1254
  }
1318
1255
  });
1319
1256
  }
1320
-
1321
- /**
1322
- * open
1323
- * @description When triggered, uses the current widget instance to open the upload modal
1257
+ /**
1258
+ * open
1259
+ * @description When triggered, uses the current widget instance to open the upload modal
1324
1260
  */
1325
-
1326
1261
  function open() {
1327
1262
  if (!(widget != null && widget.current)) {
1328
1263
  widget.current = createWidget();
1329
1264
  }
1265
+ // @ts-ignore
1330
1266
  (widget == null ? void 0 : widget.current) && widget.current.open();
1331
1267
  }
1332
-
1333
- /**
1334
- * handleOnLoad
1335
- * @description Stores the Cloudinary window instance to a ref when the widget script loads
1268
+ /**
1269
+ * handleOnLoad
1270
+ * @description Stores the Cloudinary window instance to a ref when the widget script loads
1336
1271
  */
1337
-
1338
1272
  function handleOnLoad() {
1273
+ // @ts-ignore
1339
1274
  cloudinary.current = window.cloudinary;
1340
1275
  }
1341
1276
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {