next-cloudinary 7.0.0-beta.11 → 7.0.0-beta.13

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.
Files changed (32) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +17 -5
  3. package/dist/{CldImage-ca9114a8.cjs.js → CldImage-7889010b.cjs.js} +6 -6
  4. package/dist/{CldImage-e19c2455.esm.js → CldImage-aa471276.esm.js} +2 -2
  5. package/dist/CldUploadButton-196b419b.esm.js +1 -1
  6. package/dist/CldUploadButton-db9b095b.cjs.js +1 -1
  7. package/dist/{CldUploadWidget-91685b20.cjs.js → CldUploadWidget-1d4a6e0e.cjs.js} +28 -12
  8. package/dist/{CldUploadWidget-17958387.esm.js → CldUploadWidget-7ea51225.esm.js} +22 -7
  9. package/dist/{CldVideoPlayer-4b47ff9b.esm.js → CldVideoPlayer-5e118d70.esm.js} +63 -25
  10. package/dist/{CldVideoPlayer-f03be2a8.cjs.js → CldVideoPlayer-f4e9d781.cjs.js} +65 -27
  11. package/dist/cld-video-player.css +5 -2
  12. package/dist/{cloudinary-8a433217.cjs.js → cloudinary-60840067.cjs.js} +28 -9
  13. package/dist/{cloudinary-3487906c.esm.js → cloudinary-921aa922.esm.js} +28 -9
  14. package/dist/{cloudinary-loader-636b4b15.cjs.js → cloudinary-loader-42e7d6e4.cjs.js} +1 -1
  15. package/dist/{cloudinary-loader-fc483562.esm.js → cloudinary-loader-d3996c49.esm.js} +1 -1
  16. package/dist/declarations/src/components/CldOgImage/CldOgImage.d.ts +1 -1
  17. package/dist/declarations/src/components/CldOgImage/CldOgImage.d.ts.map +1 -1
  18. package/dist/declarations/src/components/CldUploadButton/CldUploadButton.d.ts +3 -2
  19. package/dist/declarations/src/components/CldUploadButton/CldUploadButton.d.ts.map +1 -1
  20. package/dist/declarations/src/components/CldUploadWidget/CldUploadWidget.d.ts +2 -1
  21. package/dist/declarations/src/components/CldUploadWidget/CldUploadWidget.d.ts.map +1 -1
  22. package/dist/declarations/src/components/CldUploadWidget/CldUploadWidget.types.d.ts +2 -1
  23. package/dist/declarations/src/components/CldUploadWidget/CldUploadWidget.types.d.ts.map +1 -1
  24. package/dist/declarations/src/components/CldVideoPlayer/CldVideoPlayer.d.ts +1 -1
  25. package/dist/declarations/src/components/CldVideoPlayer/CldVideoPlayer.d.ts.map +1 -1
  26. package/dist/declarations/src/components/CldVideoPlayer/CldVideoPlayer.types.d.ts +1 -0
  27. package/dist/declarations/src/components/CldVideoPlayer/CldVideoPlayer.types.d.ts.map +1 -1
  28. package/dist/fonts/cloudinary_icon_for_black_bg.svg +1 -1
  29. package/dist/fonts/cloudinary_icon_for_white_bg.svg +1 -1
  30. package/dist/next-cloudinary.cjs.js +5 -5
  31. package/dist/next-cloudinary.esm.js +6 -6
  32. package/package.json +23 -15
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Colby Fayock
3
+ Copyright (c) 2023 Cloudinary
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -11,10 +11,6 @@
11
11
 
12
12
  # Next Cloudinary
13
13
 
14
- <!-- doc-gen PKGJSON optionOne="hey" -->
15
- undefined
16
- <!-- end-doc-gen -->
17
-
18
14
  High-performance image delivery and uploading at scale in Next.js powered by Cloudinary.
19
15
 
20
16
  <a href="#-features">Features</a> • <a href="#-getting-started">Getting Started</a> • <a href="#%EF%B8%8F-community--support">Community & Support</a> • <a href="#-contributing">Contributing</a>
@@ -79,7 +75,7 @@ import { CldImage } from 'next-cloudinary';
79
75
  ## ❤️ Community & Support
80
76
 
81
77
  * [GitHub: Create an Issue](https://github.com/cloudinary-community/next-cloudinary/issues)
82
- * [Twitter: @colbyfayock](https://twitter.com/colbyfayock)
78
+ * [Twitter: @cloudinary](https://twitter.com/cloudinary)
83
79
 
84
80
  ## 🛠 Contributing
85
81
 
@@ -207,6 +203,22 @@ pnpm test
207
203
  <td align="center" valign="top" width="14.28%"><a href="http://neilblaze.live"><img src="https://avatars.githubusercontent.com/u/48355572?v=4?s=100" width="100px;" alt="Pratyay Banerjee"/><br /><sub><b>Pratyay Banerjee</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=Neilblaze" title="Documentation">📖</a></td>
208
204
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/saai-syvendra"><img src="https://avatars.githubusercontent.com/u/157691467?v=4?s=100" width="100px;" alt="Saai Syvendra"/><br /><sub><b>Saai Syvendra</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=saai-syvendra" title="Documentation">📖</a></td>
209
205
  </tr>
206
+ <tr>
207
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Zaki-Mohd"><img src="https://avatars.githubusercontent.com/u/181067270?v=4?s=100" width="100px;" alt="Mohammad Zaki"/><br /><sub><b>Mohammad Zaki</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=Zaki-Mohd" title="Documentation">📖</a></td>
208
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/thinkverse"><img src="https://avatars.githubusercontent.com/u/2221746?v=4?s=100" width="100px;" alt="Kim Hallberg"/><br /><sub><b>Kim Hallberg</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=thinkverse" title="Documentation">📖</a></td>
209
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Waqibsk"><img src="https://avatars.githubusercontent.com/u/162541991?v=4?s=100" width="100px;" alt="Md Waqib Sk"/><br /><sub><b>Md Waqib Sk</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=Waqibsk" title="Documentation">📖</a></td>
210
+ <td align="center" valign="top" width="14.28%"><a href="https://arjuncodess.is-a.dev/"><img src="https://avatars.githubusercontent.com/u/137415649?v=4?s=100" width="100px;" alt="Arjun Vijay Prakash"/><br /><sub><b>Arjun Vijay Prakash</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=ArjunCodess" title="Code">💻</a></td>
211
+ <td align="center" valign="top" width="14.28%"><a href="https://musaddiq625.carrd.co"><img src="https://avatars.githubusercontent.com/u/37911054?v=4?s=100" width="100px;" alt="Musaddiq Ahmed Khan"/><br /><sub><b>Musaddiq Ahmed Khan</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=Musaddiq625" title="Documentation">📖</a></td>
212
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/SarthakJain29"><img src="https://avatars.githubusercontent.com/u/93116216?v=4?s=100" width="100px;" alt="Sarthak Jain"/><br /><sub><b>Sarthak Jain</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=SarthakJain29" title="Code">💻</a></td>
213
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/HRIDYANSHU054"><img src="https://avatars.githubusercontent.com/u/124202756?v=4?s=100" width="100px;" alt="Hridyanshu"/><br /><sub><b>Hridyanshu</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=HRIDYANSHU054" title="Documentation">📖</a></td>
214
+ </tr>
215
+ <tr>
216
+ <td align="center" valign="top" width="14.28%"><a href="https://anurag2787.vercel.app/"><img src="https://avatars.githubusercontent.com/u/143180737?v=4?s=100" width="100px;" alt="Anurag Yadav"/><br /><sub><b>Anurag Yadav</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=anurag2787" title="Code">💻</a></td>
217
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/error9098x"><img src="https://avatars.githubusercontent.com/u/43810146?v=4?s=100" width="100px;" alt="ProCodec"/><br /><sub><b>ProCodec</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=error9098x" title="Code">💻</a> <a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=error9098x" title="Documentation">📖</a></td>
218
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/chawdamrunal"><img src="https://avatars.githubusercontent.com/u/32319538?v=4?s=100" width="100px;" alt="chawda mrunal"/><br /><sub><b>chawda mrunal</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=chawdamrunal" title="Code">💻</a></td>
219
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/dharamghevariya"><img src="https://avatars.githubusercontent.com/u/144807441?v=4?s=100" width="100px;" alt="Dharam Ghevariya"/><br /><sub><b>Dharam Ghevariya</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=dharamghevariya" title="Code">💻</a></td>
220
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Meghana-2124"><img src="https://avatars.githubusercontent.com/u/204466699?v=4?s=100" width="100px;" alt="Meghana"/><br /><sub><b>Meghana</b></sub></a><br /><a href="https://github.com/cloudinary-community/next-cloudinary/commits?author=Meghana-2124" title="Documentation">📖</a></td>
221
+ </tr>
210
222
  </tbody>
211
223
  </table>
212
224
 
@@ -3,20 +3,20 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var react = require('react');
6
+ var React = require('react');
7
7
  var Image = require('next/image');
8
8
  var util = require('@cloudinary-util/util');
9
9
  var urlLoader = require('@cloudinary-util/url-loader');
10
- var cloudinaryLoader = require('./cloudinary-loader-636b4b15.cjs.js');
10
+ var cloudinaryLoader = require('./cloudinary-loader-42e7d6e4.cjs.js');
11
11
  var jsxRuntime = require('react/jsx-runtime');
12
- require('./cloudinary-8a433217.cjs.js');
12
+ require('./cloudinary-60840067.cjs.js');
13
13
  require('next/package.json');
14
14
 
15
15
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
16
16
 
17
17
  var Image__default = /*#__PURE__*/_interopDefault(Image);
18
18
 
19
- const CldImage = /*#__PURE__*/react.forwardRef(function CldImage(props, ref) {
19
+ const CldImage = /*#__PURE__*/React.forwardRef(function CldImage(props, ref) {
20
20
  let hasThrownError = false;
21
21
 
22
22
  // Add props here that are intended to only be used for
@@ -35,7 +35,7 @@ const CldImage = /*#__PURE__*/react.forwardRef(function CldImage(props, ref) {
35
35
  };
36
36
  Object.keys(props).filter(key => typeof key === 'string' && !CLD_OPTIONS.includes(key)).forEach(key => imageProps[key] = props[key]);
37
37
  const defaultImgKey = Object.keys(imageProps).map(key => `${key}:${imageProps[key]}`).join(';');
38
- const [imgKey, setImgKey] = react.useState(defaultImgKey);
38
+ const [imgKey, setImgKey] = React.useState(defaultImgKey);
39
39
 
40
40
  // The unoptimized flag is intended to remove all optimizations including quality, format, and sizing
41
41
  // via responsive sizing. When passing this in, it also prevents the `loader` from running, thus
@@ -95,7 +95,7 @@ const CldImage = /*#__PURE__*/react.forwardRef(function CldImage(props, ref) {
95
95
  setImgKey(`${defaultImgKey};${Date.now()}`);
96
96
  }
97
97
  }
98
- const handleOnError = react.useCallback(onError, [util.pollForProcessingImage, defaultImgKey]);
98
+ const handleOnError = React.useCallback(onError, [util.pollForProcessingImage, defaultImgKey]);
99
99
 
100
100
  // Copypasta from https://github.com/prismicio/prismic-next/pull/79/files
101
101
  // Thanks Angelo!
@@ -3,9 +3,9 @@ import { forwardRef, useState, useCallback } from 'react';
3
3
  import Image from 'next/image';
4
4
  import { pollForProcessingImage } from '@cloudinary-util/util';
5
5
  import { cloudinaryPluginKeys } from '@cloudinary-util/url-loader';
6
- import { g as getCldImageUrl, c as cloudinaryLoader } from './cloudinary-loader-fc483562.esm.js';
6
+ import { g as getCldImageUrl, c as cloudinaryLoader } from './cloudinary-loader-d3996c49.esm.js';
7
7
  import { jsx } from 'react/jsx-runtime';
8
- import './cloudinary-3487906c.esm.js';
8
+ import './cloudinary-921aa922.esm.js';
9
9
  import 'next/package.json';
10
10
 
11
11
  const CldImage = /*#__PURE__*/forwardRef(function CldImage(props, ref) {
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import 'react';
3
- import CldUploadWidget from './CldUploadWidget-17958387.esm.js';
3
+ import CldUploadWidget from './CldUploadWidget-7ea51225.esm.js';
4
4
  import { jsx, Fragment } from 'react/jsx-runtime';
5
5
 
6
6
  const CldUploadButton = ({
@@ -4,7 +4,7 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  require('react');
7
- var CldUploadWidget = require('./CldUploadWidget-91685b20.cjs.js');
7
+ var CldUploadWidget = require('./CldUploadWidget-1d4a6e0e.cjs.js');
8
8
  var jsxRuntime = require('react/jsx-runtime');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -3,15 +3,16 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var react = require('react');
6
+ var React = require('react');
7
7
  var Script = require('next/script');
8
8
  var urlLoader = require('@cloudinary-util/url-loader');
9
- var cloudinary = require('./cloudinary-8a433217.cjs.js');
9
+ var cloudinary = require('./cloudinary-60840067.cjs.js');
10
10
  var jsxRuntime = require('react/jsx-runtime');
11
11
  require('next/package.json');
12
12
 
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
14
 
15
+ var React__default = /*#__PURE__*/_interopDefault(React);
15
16
  var Script__default = /*#__PURE__*/_interopDefault(Script);
16
17
 
17
18
  /**
@@ -26,6 +27,16 @@ function triggerOnIdle(callback) {
26
27
  return setTimeout(() => callback(), 1);
27
28
  }
28
29
 
30
+ const useUploadWidgetId = () => {
31
+ const reactId = React__default["default"].useId?.() ?? null;
32
+
33
+ // Preserve the original random ID behavior for React < 18
34
+ const fallbackId = React__default["default"].useRef(Math.floor(Math.random() * 100)).current;
35
+
36
+ // Remove colons from React useId() output (e.g., ":r1:" -> "r1") to avoid issues with CSS selectors and HTML IDs
37
+ const sanitizedId = reactId ? reactId.replace(/:/g, '') : fallbackId;
38
+ return `cloudinary-uploadwidget-${sanitizedId}`;
39
+ };
29
40
  const CldUploadWidget = ({
30
41
  children,
31
42
  config,
@@ -37,11 +48,13 @@ const CldUploadWidget = ({
37
48
  uploadPreset,
38
49
  ...props
39
50
  }) => {
40
- const cloudinary$1 = react.useRef();
41
- const widget = react.useRef();
42
- const [error, setError] = react.useState(undefined);
43
- const [results, setResults] = react.useState(undefined);
44
- const [isScriptLoading, setIsScriptLoading] = react.useState(true);
51
+ const uploadWidgetId = useUploadWidgetId();
52
+ const cloudinary$1 = React.useRef(undefined);
53
+ const widget = React.useRef(undefined);
54
+ const isMounted = React.useRef(false);
55
+ const [error, setError] = React.useState(undefined);
56
+ const [results, setResults] = React.useState(undefined);
57
+ const [isScriptLoading, setIsScriptLoading] = React.useState(true);
45
58
 
46
59
  // When creating a signed upload, you need to provide both your Cloudinary API Key
47
60
  // as well as a signature generator function that will sign any paramters
@@ -89,7 +102,7 @@ const CldUploadWidget = ({
89
102
 
90
103
  // Handle result states and callbacks
91
104
 
92
- react.useEffect(() => {
105
+ React.useEffect(() => {
93
106
  if (typeof results === 'undefined') return;
94
107
  const isSuccess = results.event === 'success';
95
108
  if (isSuccess && typeof onUpload === 'function') {
@@ -106,6 +119,7 @@ const CldUploadWidget = ({
106
119
  */
107
120
 
108
121
  function handleOnLoad() {
122
+ if (!isMounted.current) return;
109
123
  setIsScriptLoading(false);
110
124
  if (!cloudinary$1.current) {
111
125
  cloudinary$1.current = window.cloudinary;
@@ -115,13 +129,15 @@ const CldUploadWidget = ({
115
129
  // to trigger widget creation. Optional.
116
130
 
117
131
  triggerOnIdle(() => {
118
- if (!widget.current) {
132
+ if (isMounted.current && !widget.current) {
119
133
  widget.current = createWidget();
120
134
  }
121
135
  });
122
136
  }
123
- react.useEffect(() => {
137
+ React.useEffect(() => {
138
+ isMounted.current = true;
124
139
  return () => {
140
+ isMounted.current = false;
125
141
  widget.current?.destroy();
126
142
  widget.current = undefined;
127
143
  };
@@ -137,7 +153,7 @@ const CldUploadWidget = ({
137
153
  if (!widget.current) {
138
154
  widget.current = createWidget();
139
155
  }
140
- if (typeof widget?.current[method] === "function") {
156
+ if (typeof widget.current?.[method] === "function") {
141
157
  return widget.current[method](...options);
142
158
  }
143
159
  }
@@ -204,7 +220,7 @@ const CldUploadWidget = ({
204
220
  isLoading: isScriptLoading,
205
221
  ...instanceMethods
206
222
  }), /*#__PURE__*/jsxRuntime.jsx(Script__default["default"], {
207
- id: `cloudinary-uploadwidget-${Math.floor(Math.random() * 100)}`,
223
+ id: uploadWidgetId,
208
224
  src: "https://upload-widget.cloudinary.com/global/all.js",
209
225
  onLoad: handleOnLoad,
210
226
  onError: e => console.error(`Failed to load Cloudinary Upload Widget: ${e.message}`)
@@ -1,8 +1,8 @@
1
1
  'use client';
2
- import { useRef, useState, useEffect } from 'react';
2
+ import React, { useRef, useState, useEffect } from 'react';
3
3
  import Script from 'next/script';
4
4
  import { generateSignatureCallback, getUploadWidgetOptions, generateUploadWidgetResultCallback, UPLOAD_WIDGET_EVENTS } from '@cloudinary-util/url-loader';
5
- import { g as getCloudinaryConfig } from './cloudinary-3487906c.esm.js';
5
+ import { g as getCloudinaryConfig } from './cloudinary-921aa922.esm.js';
6
6
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
7
7
  import 'next/package.json';
8
8
 
@@ -18,6 +18,16 @@ function triggerOnIdle(callback) {
18
18
  return setTimeout(() => callback(), 1);
19
19
  }
20
20
 
21
+ const useUploadWidgetId = () => {
22
+ const reactId = React.useId?.() ?? null;
23
+
24
+ // Preserve the original random ID behavior for React < 18
25
+ const fallbackId = React.useRef(Math.floor(Math.random() * 100)).current;
26
+
27
+ // Remove colons from React useId() output (e.g., ":r1:" -> "r1") to avoid issues with CSS selectors and HTML IDs
28
+ const sanitizedId = reactId ? reactId.replace(/:/g, '') : fallbackId;
29
+ return `cloudinary-uploadwidget-${sanitizedId}`;
30
+ };
21
31
  const CldUploadWidget = ({
22
32
  children,
23
33
  config,
@@ -29,8 +39,10 @@ const CldUploadWidget = ({
29
39
  uploadPreset,
30
40
  ...props
31
41
  }) => {
32
- const cloudinary = useRef();
33
- const widget = useRef();
42
+ const uploadWidgetId = useUploadWidgetId();
43
+ const cloudinary = useRef(undefined);
44
+ const widget = useRef(undefined);
45
+ const isMounted = useRef(false);
34
46
  const [error, setError] = useState(undefined);
35
47
  const [results, setResults] = useState(undefined);
36
48
  const [isScriptLoading, setIsScriptLoading] = useState(true);
@@ -98,6 +110,7 @@ const CldUploadWidget = ({
98
110
  */
99
111
 
100
112
  function handleOnLoad() {
113
+ if (!isMounted.current) return;
101
114
  setIsScriptLoading(false);
102
115
  if (!cloudinary.current) {
103
116
  cloudinary.current = window.cloudinary;
@@ -107,13 +120,15 @@ const CldUploadWidget = ({
107
120
  // to trigger widget creation. Optional.
108
121
 
109
122
  triggerOnIdle(() => {
110
- if (!widget.current) {
123
+ if (isMounted.current && !widget.current) {
111
124
  widget.current = createWidget();
112
125
  }
113
126
  });
114
127
  }
115
128
  useEffect(() => {
129
+ isMounted.current = true;
116
130
  return () => {
131
+ isMounted.current = false;
117
132
  widget.current?.destroy();
118
133
  widget.current = undefined;
119
134
  };
@@ -129,7 +144,7 @@ const CldUploadWidget = ({
129
144
  if (!widget.current) {
130
145
  widget.current = createWidget();
131
146
  }
132
- if (typeof widget?.current[method] === "function") {
147
+ if (typeof widget.current?.[method] === "function") {
133
148
  return widget.current[method](...options);
134
149
  }
135
150
  }
@@ -196,7 +211,7 @@ const CldUploadWidget = ({
196
211
  isLoading: isScriptLoading,
197
212
  ...instanceMethods
198
213
  }), /*#__PURE__*/jsx(Script, {
199
- id: `cloudinary-uploadwidget-${Math.floor(Math.random() * 100)}`,
214
+ id: uploadWidgetId,
200
215
  src: "https://upload-widget.cloudinary.com/global/all.js",
201
216
  onLoad: handleOnLoad,
202
217
  onError: e => console.error(`Failed to load Cloudinary Upload Widget: ${e.message}`)
@@ -1,18 +1,19 @@
1
1
  'use client';
2
- import { useId, useRef, useEffect } from 'react';
2
+ import { useId, useState, useRef, useEffect } from 'react';
3
3
  import Script from 'next/script';
4
4
  import Head from 'next/head';
5
5
  import { getVideoPlayerOptions } from '@cloudinary-util/url-loader';
6
- import { g as getCloudinaryConfig } from './cloudinary-3487906c.esm.js';
6
+ import { g as getCloudinaryConfig } from './cloudinary-921aa922.esm.js';
7
7
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
8
8
  import 'next/package.json';
9
9
 
10
10
  let playerInstances = [];
11
- const PLAYER_VERSION = '1.11.1';
11
+ const PLAYER_VERSION = '4.1.2';
12
12
  const CldVideoPlayer = props => {
13
13
  const {
14
14
  className,
15
15
  config,
16
+ disableRemotePlayback,
16
17
  height,
17
18
  id,
18
19
  onDataLoad,
@@ -24,6 +25,8 @@ const CldVideoPlayer = props => {
24
25
  width
25
26
  } = props;
26
27
  const uniqueId = useId();
28
+ const [isScriptLoaded, setIsScriptLoaded] = useState(false);
29
+ const [playerInitialized, setPlayerInitialized] = useState(false);
27
30
  const cloudinaryConfig = getCloudinaryConfig(config);
28
31
  const playerOptions = getVideoPlayerOptions(props, cloudinaryConfig);
29
32
  const {
@@ -36,26 +39,16 @@ const CldVideoPlayer = props => {
36
39
  // Setup the refs and allow for the caller to pass through their
37
40
  // own ref instance
38
41
 
39
- const cloudinaryRef = useRef();
40
- const defaultVideoRef = useRef();
42
+ const cloudinaryRef = useRef(undefined);
43
+ const defaultVideoRef = useRef(null);
41
44
  const videoRef = props.videoRef || defaultVideoRef;
42
- const defaultPlayerRef = useRef();
45
+ const defaultPlayerRef = useRef(null);
43
46
  const playerRef = props.playerRef || defaultPlayerRef;
44
47
  const playerId = id || `player-${uniqueId.replace(/:/g, '')}`;
45
48
  let playerClassName = 'cld-video-player cld-fluid';
46
49
  if (className) {
47
50
  playerClassName = `${playerClassName} ${className}`;
48
51
  }
49
-
50
- // Check if the same id is being used for multiple video instances.
51
- const checkForMultipleInstance = playerInstances.filter(id => id === playerId).length > 1;
52
- if (checkForMultipleInstance) {
53
- console.warn(`Multiple instances of the same video detected on the
54
- page which may cause some features to not work.
55
- Try adding a unique id to each player.`);
56
- } else {
57
- playerInstances.push(playerId);
58
- }
59
52
  const events = {
60
53
  error: onError,
61
54
  loadeddata: onDataLoad,
@@ -78,28 +71,73 @@ const CldVideoPlayer = props => {
78
71
  }
79
72
 
80
73
  /**
81
- * handleOnLoad
82
- * @description Stores the Cloudinary window instance to a ref when the widget script loads
74
+ * disposePlayer
75
+ * @description Properly dispose of the player instance and clean up
83
76
  */
84
77
 
85
- function handleOnLoad() {
86
- if ('cloudinary' in window) {
78
+ const disposePlayer = () => {
79
+ if (playerRef.current?.videojs?.cloudinary) {
80
+ playerRef.current.videojs.cloudinary.dispose();
81
+ }
82
+ // remove from global instances array
83
+ playerInstances = playerInstances.filter(instanceId => instanceId !== playerId);
84
+ playerRef.current = null;
85
+ setPlayerInitialized(false);
86
+ };
87
+
88
+ /**
89
+ * initializePlayer
90
+ * @description Initialize the Cloudinary video player
91
+ */
92
+
93
+ const initializePlayer = () => {
94
+ if (typeof window !== 'undefined' && 'cloudinary' in window && videoRef.current && !playerInitialized) {
87
95
  cloudinaryRef.current = window.cloudinary;
96
+
97
+ // dispose any existing player instance first to prevent conflicts
98
+ if (playerRef.current) {
99
+ disposePlayer();
100
+ }
88
101
  playerRef.current = cloudinaryRef.current.videoPlayer(videoRef.current, playerOptions);
102
+ setPlayerInitialized(true);
89
103
  Object.keys(events).forEach(key => {
90
104
  if (typeof events[key] === 'function') {
91
105
  playerRef.current?.on(key, handleEvent);
92
106
  }
93
107
  });
94
108
  }
109
+ };
110
+
111
+ /**
112
+ * handleOnLoad
113
+ * @description Stores the Cloudinary window instance to a ref when the widget script loads
114
+ */
115
+
116
+ function handleOnLoad() {
117
+ setIsScriptLoaded(true);
118
+ if ('cloudinary' in window) {
119
+ initializePlayer();
120
+ }
95
121
  }
122
+
123
+ // effect to handle component mounting and cleanup
96
124
  useEffect(() => {
125
+ // initialize player if script is already loaded
126
+ if (isScriptLoaded && typeof window !== 'undefined' && 'cloudinary' in window) {
127
+ initializePlayer();
128
+ }
97
129
  return () => {
98
- playerRef.current?.videojs.cloudinary.dispose();
99
- playerInstances = playerInstances.filter(id => id !== playerId);
130
+ disposePlayer();
100
131
  };
101
132
  }, []);
102
133
 
134
+ // effect to handle script loading after mount
135
+ useEffect(() => {
136
+ if (isScriptLoaded && !playerInitialized && typeof window !== 'undefined' && 'cloudinary' in window) {
137
+ initializePlayer();
138
+ }
139
+ }, [isScriptLoaded, playerInitialized]);
140
+
103
141
  /**
104
142
  *getPlayerRefs
105
143
  */
@@ -118,15 +156,15 @@ const CldVideoPlayer = props => {
118
156
  })
119
157
  }), /*#__PURE__*/jsxs("div", {
120
158
  style: {
121
- width: '100%',
122
- aspectRatio: `${width} / ${height}`
159
+ width: '100%'
123
160
  },
124
161
  children: [/*#__PURE__*/jsx("video", {
125
162
  ref: videoRef,
126
163
  id: playerId,
127
164
  className: playerClassName,
128
165
  width: width,
129
- height: height
166
+ height: height,
167
+ disableRemotePlayback: disableRemotePlayback
130
168
  }), /*#__PURE__*/jsx(Script, {
131
169
  id: `cloudinary-videoplayer-${playerId}`,
132
170
  src: `https://unpkg.com/cloudinary-video-player@${PLAYER_VERSION}/dist/cld-video-player.min.js`,
@@ -3,11 +3,11 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var react = require('react');
6
+ var React = require('react');
7
7
  var Script = require('next/script');
8
8
  var Head = require('next/head');
9
9
  var urlLoader = require('@cloudinary-util/url-loader');
10
- var cloudinary = require('./cloudinary-8a433217.cjs.js');
10
+ var cloudinary = require('./cloudinary-60840067.cjs.js');
11
11
  var jsxRuntime = require('react/jsx-runtime');
12
12
  require('next/package.json');
13
13
 
@@ -17,11 +17,12 @@ var Script__default = /*#__PURE__*/_interopDefault(Script);
17
17
  var Head__default = /*#__PURE__*/_interopDefault(Head);
18
18
 
19
19
  let playerInstances = [];
20
- const PLAYER_VERSION = '1.11.1';
20
+ const PLAYER_VERSION = '4.1.2';
21
21
  const CldVideoPlayer = props => {
22
22
  const {
23
23
  className,
24
24
  config,
25
+ disableRemotePlayback,
25
26
  height,
26
27
  id,
27
28
  onDataLoad,
@@ -32,7 +33,9 @@ const CldVideoPlayer = props => {
32
33
  onEnded,
33
34
  width
34
35
  } = props;
35
- const uniqueId = react.useId();
36
+ const uniqueId = React.useId();
37
+ const [isScriptLoaded, setIsScriptLoaded] = React.useState(false);
38
+ const [playerInitialized, setPlayerInitialized] = React.useState(false);
36
39
  const cloudinaryConfig = cloudinary.getCloudinaryConfig(config);
37
40
  const playerOptions = urlLoader.getVideoPlayerOptions(props, cloudinaryConfig);
38
41
  const {
@@ -45,26 +48,16 @@ const CldVideoPlayer = props => {
45
48
  // Setup the refs and allow for the caller to pass through their
46
49
  // own ref instance
47
50
 
48
- const cloudinaryRef = react.useRef();
49
- const defaultVideoRef = react.useRef();
51
+ const cloudinaryRef = React.useRef(undefined);
52
+ const defaultVideoRef = React.useRef(null);
50
53
  const videoRef = props.videoRef || defaultVideoRef;
51
- const defaultPlayerRef = react.useRef();
54
+ const defaultPlayerRef = React.useRef(null);
52
55
  const playerRef = props.playerRef || defaultPlayerRef;
53
56
  const playerId = id || `player-${uniqueId.replace(/:/g, '')}`;
54
57
  let playerClassName = 'cld-video-player cld-fluid';
55
58
  if (className) {
56
59
  playerClassName = `${playerClassName} ${className}`;
57
60
  }
58
-
59
- // Check if the same id is being used for multiple video instances.
60
- const checkForMultipleInstance = playerInstances.filter(id => id === playerId).length > 1;
61
- if (checkForMultipleInstance) {
62
- console.warn(`Multiple instances of the same video detected on the
63
- page which may cause some features to not work.
64
- Try adding a unique id to each player.`);
65
- } else {
66
- playerInstances.push(playerId);
67
- }
68
61
  const events = {
69
62
  error: onError,
70
63
  loadeddata: onDataLoad,
@@ -87,28 +80,73 @@ const CldVideoPlayer = props => {
87
80
  }
88
81
 
89
82
  /**
90
- * handleOnLoad
91
- * @description Stores the Cloudinary window instance to a ref when the widget script loads
83
+ * disposePlayer
84
+ * @description Properly dispose of the player instance and clean up
92
85
  */
93
86
 
94
- function handleOnLoad() {
95
- if ('cloudinary' in window) {
87
+ const disposePlayer = () => {
88
+ if (playerRef.current?.videojs?.cloudinary) {
89
+ playerRef.current.videojs.cloudinary.dispose();
90
+ }
91
+ // remove from global instances array
92
+ playerInstances = playerInstances.filter(instanceId => instanceId !== playerId);
93
+ playerRef.current = null;
94
+ setPlayerInitialized(false);
95
+ };
96
+
97
+ /**
98
+ * initializePlayer
99
+ * @description Initialize the Cloudinary video player
100
+ */
101
+
102
+ const initializePlayer = () => {
103
+ if (typeof window !== 'undefined' && 'cloudinary' in window && videoRef.current && !playerInitialized) {
96
104
  cloudinaryRef.current = window.cloudinary;
105
+
106
+ // dispose any existing player instance first to prevent conflicts
107
+ if (playerRef.current) {
108
+ disposePlayer();
109
+ }
97
110
  playerRef.current = cloudinaryRef.current.videoPlayer(videoRef.current, playerOptions);
111
+ setPlayerInitialized(true);
98
112
  Object.keys(events).forEach(key => {
99
113
  if (typeof events[key] === 'function') {
100
114
  playerRef.current?.on(key, handleEvent);
101
115
  }
102
116
  });
103
117
  }
118
+ };
119
+
120
+ /**
121
+ * handleOnLoad
122
+ * @description Stores the Cloudinary window instance to a ref when the widget script loads
123
+ */
124
+
125
+ function handleOnLoad() {
126
+ setIsScriptLoaded(true);
127
+ if ('cloudinary' in window) {
128
+ initializePlayer();
129
+ }
104
130
  }
105
- react.useEffect(() => {
131
+
132
+ // effect to handle component mounting and cleanup
133
+ React.useEffect(() => {
134
+ // initialize player if script is already loaded
135
+ if (isScriptLoaded && typeof window !== 'undefined' && 'cloudinary' in window) {
136
+ initializePlayer();
137
+ }
106
138
  return () => {
107
- playerRef.current?.videojs.cloudinary.dispose();
108
- playerInstances = playerInstances.filter(id => id !== playerId);
139
+ disposePlayer();
109
140
  };
110
141
  }, []);
111
142
 
143
+ // effect to handle script loading after mount
144
+ React.useEffect(() => {
145
+ if (isScriptLoaded && !playerInitialized && typeof window !== 'undefined' && 'cloudinary' in window) {
146
+ initializePlayer();
147
+ }
148
+ }, [isScriptLoaded, playerInitialized]);
149
+
112
150
  /**
113
151
  *getPlayerRefs
114
152
  */
@@ -127,15 +165,15 @@ const CldVideoPlayer = props => {
127
165
  })
128
166
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
129
167
  style: {
130
- width: '100%',
131
- aspectRatio: `${width} / ${height}`
168
+ width: '100%'
132
169
  },
133
170
  children: [/*#__PURE__*/jsxRuntime.jsx("video", {
134
171
  ref: videoRef,
135
172
  id: playerId,
136
173
  className: playerClassName,
137
174
  width: width,
138
- height: height
175
+ height: height,
176
+ disableRemotePlayback: disableRemotePlayback
139
177
  }), /*#__PURE__*/jsxRuntime.jsx(Script__default["default"], {
140
178
  id: `cloudinary-videoplayer-${playerId}`,
141
179
  src: `https://unpkg.com/cloudinary-video-player@${PLAYER_VERSION}/dist/cld-video-player.min.js`,