@zuude-ui/video 0.1.35 → 0.1.92

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/package.json CHANGED
@@ -3,26 +3,31 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.35",
6
+ "version": "0.1.92",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
10
10
  "files": [
11
11
  "dist/**"
12
12
  ],
13
+ "type": "module",
13
14
  "exports": {
14
15
  ".": {
15
- "import": "./dist/index.mjs",
16
- "require": "./dist/index.js",
17
- "types": "./dist/index.d.ts"
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.cjs",
18
+ "require": "./dist/index.js"
19
+ },
20
+ "./hooks": {
21
+ "types": "./dist/hooks/index.d.ts",
22
+ "import": "./dist/hooks/index.cjs",
23
+ "require": "./dist/hooks/index.js"
18
24
  },
19
- "./new": {
20
- "import": "./dist/new/index.mjs",
21
- "require": "./dist/new/index.js",
22
- "types": "./dist/new/index.d.ts"
25
+ "./utils": {
26
+ "types": "./dist/utils/index.d.ts",
27
+ "import": "./dist/utils/index.cjs",
28
+ "require": "./dist/utils/index.js"
23
29
  }
24
30
  },
25
- "type": "module",
26
31
  "scripts": {
27
32
  "build": "tsup",
28
33
  "lint": "tsc"
@@ -32,12 +37,12 @@
32
37
  "license": "ISC",
33
38
  "description": "",
34
39
  "dependencies": {
35
- "@radix-ui/react-slot": "^1.1.2",
36
40
  "tsup": "^8.5.0",
37
41
  "typescript": "^5.8.3"
38
42
  },
39
43
  "peerDependencies": {
40
- "react": "^19.0.0"
44
+ "react": "^19.0.0",
45
+ "@radix-ui/react-slot": "^1.1.2"
41
46
  },
42
47
  "devDependencies": {
43
48
  "@types/react": "^19.0.10"
@@ -1,2 +0,0 @@
1
- import a from"react";var u=(o,c,r)=>{a.useEffect(()=>{if(!(o!=null&&o.current)||!c)return;(async()=>{var l;try{await((l=o.current)==null?void 0:l.play())}catch(t){if(t instanceof Error&&t.name==="NotAllowedError"){if(r==null||r("NotAllowedError"),console.error("NotAllowedError"),o!=null&&o.current){o.current.muted=!0;try{await o.current.play()}catch(n){console.error(n)}}}else console.error(t)}})()},[c,o==null?void 0:o.current])};export{u as a};
2
- //# sourceMappingURL=chunk-WLYC6MHJ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-autoplay-by-force.tsx"],"sourcesContent":["import React from \"react\";\nimport { VideoRef } from \"../types.js\";\n\nexport const useAutoplayByForce = (\n ref: VideoRef | null,\n enabled: boolean,\n setError?: (error: string | null) => void\n) => {\n React.useEffect(() => {\n if (!ref?.current || !enabled) return;\n\n const playVideo = async () => {\n try {\n await ref.current?.play();\n } catch (error) {\n // If autoplay fails, try muting and playing again\n if (error instanceof Error && error.name === \"NotAllowedError\") {\n setError?.(\"NotAllowedError\");\n console.error(\"NotAllowedError\");\n if (ref?.current) {\n ref.current.muted = true;\n try {\n await ref.current.play();\n } catch (retryError) {\n console.error(retryError);\n }\n }\n } else {\n console.error(error);\n }\n }\n };\n\n playVideo();\n }, [enabled, ref?.current]);\n};\n"],"mappings":"AAAA,OAAOA,MAAW,QAGX,IAAMC,EAAqB,CAChCC,EACAC,EACAC,IACG,CACHJ,EAAM,UAAU,IAAM,CACpB,GAAI,EAACE,GAAA,MAAAA,EAAK,UAAW,CAACC,EAAS,QAEb,SAAY,CAXlC,IAAAE,EAYM,GAAI,CACF,OAAMA,EAAAH,EAAI,UAAJ,YAAAG,EAAa,OACrB,OAASC,EAAO,CAEd,GAAIA,aAAiB,OAASA,EAAM,OAAS,mBAG3C,GAFAF,GAAA,MAAAA,EAAW,mBACX,QAAQ,MAAM,iBAAiB,EAC3BF,GAAA,MAAAA,EAAK,QAAS,CAChBA,EAAI,QAAQ,MAAQ,GACpB,GAAI,CACF,MAAMA,EAAI,QAAQ,KAAK,CACzB,OAASK,EAAY,CACnB,QAAQ,MAAMA,CAAU,CAC1B,CACF,OAEA,QAAQ,MAAMD,CAAK,CAEvB,CACF,GAEU,CACZ,EAAG,CAACH,EAASD,GAAA,YAAAA,EAAK,OAAO,CAAC,CAC5B","names":["React","useAutoplayByForce","ref","enabled","setError","_a","error","retryError"]}
@@ -1,2 +0,0 @@
1
- "use strict";"use client";var O=Object.create;var m=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var B=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of H(t))!j.call(e,r)&&r!==o&&m(e,r,{get:()=>t[r],enumerable:!(i=M(t,r))||i.enumerable});return e};var b=(e,t,o)=>(o=e!=null?O(S(e)):{},h(t||!e||!e.__esModule?m(o,"default",{value:e,enumerable:!0}):o,e)),F=e=>h(m({},"__esModule",{value:!0}),e);var G={};B(G,{Loading:()=>z,Pause:()=>q,Play:()=>I,Video:()=>v,VideoProvider:()=>w,useVideoState:()=>D});module.exports=F(G);var l=require("react"),P=require("react/jsx-runtime"),k=(0,l.createContext)(void 0),w=({children:e,config:t,onError:o,...i})=>{let[r,n]=(0,l.useState)(null),[c,d]=(0,l.useState)(null);return(0,l.useEffect)(()=>{o==null||o(c)},[c]),(0,P.jsx)(k.Provider,{value:{videoRef:r,setVideoRef:n,config:{clickToPlay:!0,...t},error:c,setError:d},children:(0,P.jsx)("div",{...i,children:e})})},f=()=>{let e=(0,l.useContext)(k);if(!e)throw new Error("useVideo must be used within a VideoProvider");return e};var s=require("react");var L=b(require("react"),1),T=(e,t,o)=>{L.default.useEffect(()=>{if(!(e!=null&&e.current)||!t)return;(async()=>{var r;try{await((r=e.current)==null?void 0:r.play())}catch(n){if(n instanceof Error&&n.name==="NotAllowedError"){if(o==null||o("NotAllowedError"),console.error("NotAllowedError"),e!=null&&e.current){e.current.muted=!0;try{await e.current.play()}catch(c){console.error(c)}}}else console.error(n)}})()},[t,e==null?void 0:e.current])};var u=require("react/jsx-runtime"),v=(0,s.forwardRef)(({src:e,autoPlay:t,muteFallback:o,...i},r)=>{let{videoRef:n,setVideoRef:c,config:d,setError:E,error:A}=f(),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{let a=x.current,p=r;p?c(p):a&&c({current:a})},[e]),T(n,t==="force"&&i.muted===void 0,E);let N=()=>{var a,p,g;(a=n==null?void 0:n.current)!=null&&a.paused?(p=n.current)==null||p.play():(g=n==null?void 0:n.current)==null||g.pause()};return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("video",{ref:r||x,src:e,...i,onClick:d!=null&&d.clickToPlay?N:void 0}),A==="NotAllowedError"&&typeof o=="function"&&o(()=>{n!=null&&n.current&&(n.current.muted=!n.current.muted),E(null)})]})});v.displayName="Video";var R=b(require("react"),1),C=require("@radix-ui/react-slot");var V=require("react/jsx-runtime"),I=R.default.memo(({children:e,asChild:t,...o})=>{let i=t?C.Slot:"button",{videoRef:r}=f();return(0,V.jsx)(i,{...o,onClick:()=>{var c,d;(c=r==null?void 0:r.current)!=null&&c.paused&&((d=r.current)==null||d.play())},children:e})}),q=R.default.memo(({children:e,asChild:t,...o})=>{let i=t?C.Slot:"button",{videoRef:r}=f();return(0,V.jsx)(i,{...o,onClick:()=>{var c;r!=null&&r.current&&((c=r.current)==null||c.pause())},children:e})}),z=()=>(0,V.jsx)("div",{children:"Loading"});var y=require("react"),D=e=>{let[t,o]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let i=e.current;if(i)return i.addEventListener("play",()=>o(!0)),i.addEventListener("pause",()=>o(!1)),()=>{i.removeEventListener("play",()=>o(!0)),i.removeEventListener("pause",()=>o(!1))}},[e]),{isPlaying:t}};0&&(module.exports={Loading,Pause,Play,Video,VideoProvider,useVideoState});
2
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/new/index.ts","../../src/new/wrapper.tsx","../../src/new/video.tsx","../../src/hooks/use-autoplay-by-force.tsx","../../src/new/components.tsx","../../src/new/hook.tsx"],"sourcesContent":["\"use client\";\n\nexport { VideoProvider } from \"./wrapper\";\nexport { Video } from \"./video\";\nexport * from \"./components\";\nexport * from \"./hook\";\n","import {\n createContext,\n RefObject,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { VideoRef } from \"./types\";\n\ninterface VideoConfig {\n config?: Partial<{\n clickToPlay: boolean;\n }>;\n}\n\ninterface VideoContextType extends VideoConfig {\n videoRef: VideoRef | null;\n setVideoRef: (video: VideoRef | null) => void;\n error: string | null;\n setError: (error: string | null) => void;\n}\n\nexport const VideoContext = createContext<VideoContextType | undefined>(\n undefined\n);\n\ntype VideoProviderProps = React.ComponentProps<\"div\"> &\n VideoConfig & {\n children: React.ReactNode;\n onError?: (error: string | null) => void;\n };\n\nexport const VideoProvider = ({\n children,\n config,\n onError,\n ...props\n}: VideoProviderProps) => {\n const [videoRef, setVideoRef] = useState<VideoRef | null>(null);\n const [error, setError] = useState<string | null>(null);\n\n // Sending error to user if it exists\n useEffect(() => {\n onError?.(error);\n }, [error]);\n\n return (\n <VideoContext.Provider\n value={{\n videoRef,\n setVideoRef,\n config: { clickToPlay: true, ...config },\n error,\n setError,\n }}\n >\n <div {...props}>{children}</div>\n </VideoContext.Provider>\n );\n};\n\nexport const useVideo = () => {\n const context = useContext(VideoContext);\n if (!context) {\n throw new Error(\"useVideo must be used within a VideoProvider\");\n }\n return context;\n};\n","import React, { forwardRef, RefObject, useEffect, useRef } from \"react\";\nimport { useVideo } from \"./wrapper\";\nimport { VideoAutoplay } from \"./types\";\nimport { useAutoplayByForce } from \"../hooks/use-autoplay-by-force\";\n\ninterface Props extends Omit<React.ComponentProps<\"video\">, \"autoPlay\"> {\n src: string;\n autoPlay?: VideoAutoplay;\n muteFallback?: (onMute: () => void) => React.ReactNode;\n}\n\nexport const Video = forwardRef<HTMLVideoElement, Props>(\n ({ src, autoPlay, muteFallback, ...props }, ref) => {\n const { videoRef, setVideoRef, config, setError, error } = useVideo();\n\n const refVideo = useRef<HTMLVideoElement>(null);\n\n useEffect(() => {\n const video = refVideo.current;\n const thirdPartyRef = ref;\n\n if (thirdPartyRef) {\n setVideoRef(thirdPartyRef as RefObject<HTMLVideoElement>);\n } else {\n if (video) {\n setVideoRef({ current: video });\n }\n }\n }, [src]);\n\n useAutoplayByForce(\n videoRef,\n autoPlay === \"force\" && props.muted === undefined,\n setError\n );\n\n const onPlay = () => {\n if (videoRef?.current?.paused) {\n videoRef.current?.play();\n } else {\n videoRef?.current?.pause();\n }\n };\n\n return (\n <>\n <video\n ref={ref || refVideo}\n src={src}\n {...props}\n onClick={config?.clickToPlay ? onPlay : undefined}\n />\n\n {error === \"NotAllowedError\" &&\n typeof muteFallback === \"function\" &&\n muteFallback(() => {\n if (videoRef?.current) {\n videoRef.current.muted = !videoRef.current.muted;\n }\n setError(null);\n })}\n </>\n );\n }\n);\n\nVideo.displayName = \"Video\";\n","import React from \"react\";\nimport { VideoRef } from \"../types.js\";\n\nexport const useAutoplayByForce = (\n ref: VideoRef | null,\n enabled: boolean,\n setError?: (error: string | null) => void\n) => {\n React.useEffect(() => {\n if (!ref?.current || !enabled) return;\n\n const playVideo = async () => {\n try {\n await ref.current?.play();\n } catch (error) {\n // If autoplay fails, try muting and playing again\n if (error instanceof Error && error.name === \"NotAllowedError\") {\n setError?.(\"NotAllowedError\");\n console.error(\"NotAllowedError\");\n if (ref?.current) {\n ref.current.muted = true;\n try {\n await ref.current.play();\n } catch (retryError) {\n console.error(retryError);\n }\n }\n } else {\n console.error(error);\n }\n }\n };\n\n playVideo();\n }, [enabled, ref?.current]);\n};\n","import React from \"react\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { useVideo } from \"./wrapper\";\n\ninterface Props extends React.ComponentProps<\"button\"> {\n children: React.ReactNode;\n asChild?: boolean;\n}\n\nconst Play = React.memo(({ children, asChild, ...props }: Props) => {\n const Element = asChild ? Slot : \"button\";\n const { videoRef } = useVideo();\n\n const handleClick = () => {\n if (videoRef?.current?.paused) {\n videoRef.current?.play();\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst Pause = React.memo(({ children, asChild, ...props }: Props) => {\n const Element = asChild ? Slot : \"button\";\n const { videoRef } = useVideo();\n\n const handleClick = () => {\n if (videoRef?.current) {\n videoRef.current?.pause();\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst Loading = () => {\n return <div>Loading</div>;\n};\n\nexport { Play, Pause, Loading };\n","import { RefObject, useEffect, useState } from \"react\";\n\nconst useVideoState = (videoRef: RefObject<HTMLVideoElement | null>) => {\n const [isPlaying, setIsPlaying] = useState(false);\n\n useEffect(() => {\n const video = videoRef.current;\n\n if (video) {\n video.addEventListener(\"play\", () => setIsPlaying(true));\n video.addEventListener(\"pause\", () => setIsPlaying(false));\n\n return () => {\n video.removeEventListener(\"play\", () => setIsPlaying(true));\n video.removeEventListener(\"pause\", () => setIsPlaying(false));\n };\n }\n }, [videoRef]);\n\n return { isPlaying };\n};\n\nexport { useVideoState };\n"],"mappings":"ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,UAAAC,EAAA,SAAAC,EAAA,UAAAC,EAAA,kBAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAR,GCAA,IAAAS,EAMO,iBAkDDC,EAAA,6BAlCOC,KAAe,iBAC1B,MACF,EAQaC,EAAgB,CAAC,CAC5B,SAAAC,EACA,OAAAC,EACA,QAAAC,EACA,GAAGC,CACL,IAA0B,CACxB,GAAM,CAACC,EAAUC,CAAW,KAAI,YAA0B,IAAI,EACxD,CAACC,EAAOC,CAAQ,KAAI,YAAwB,IAAI,EAGtD,sBAAU,IAAM,CACdL,GAAA,MAAAA,EAAUI,EACZ,EAAG,CAACA,CAAK,CAAC,KAGR,OAACR,EAAa,SAAb,CACC,MAAO,CACL,SAAAM,E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,OAAO,SAC3B,CAAE,SAAAG,CAAS,EAAIC,EAAS,EAQ9B,SACE,OAACF,EAAA,CAAS,GAAGD,EAAO,QAPF,IAAM,CA/B5B,IAAAI,EAgCQF,GAAA,MAAAA,EAAU,WACZE,EAAAF,EAAS,UAAT,MAAAE,EAAkB,QAEtB,EAIK,SAAAN,EACH,CAEJ,CAAC,EAEKS,EAAU,OACP,OAAC,OAAI,mBAAO,EC7CrB,IAAAC,EAA+C,iBAEzCC,EAAiBC,GAAiD,CACtE,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAK,EAEhD,sBAAU,IAAM,CACd,IAAMC,EAAQH,EAAS,QAEvB,GAAIG,EACF,OAAAA,EAAM,iBAAiB,OAAQ,IAAMD,EAAa,EAAI,CAAC,EACvDC,EAAM,iBAAiB,QAAS,IAAMD,EAAa,EAAK,CAAC,EAElD,IAAM,CACXC,EAAM,oBAAoB,OAAQ,IAAMD,EAAa,EAAI,CAAC,EAC1DC,EAAM,oBAAoB,QAAS,IAAMD,EAAa,EAAK,CAAC,CAC9D,CAEJ,EAAG,CAACF,CAAQ,CAAC,EAEN,CAAE,UAAAC,CAAU,CACrB","names":["new_exports","__export","Loading","Pause","Play","Video","VideoProvider","useVideoState","__toCommonJS","import_react","import_jsx_runtime","VideoContext","VideoProvider","children","config","onError","props","videoRef","setVideoRef","error","setError","useVideo","context","import_react","import_react","useAutoplayByForce","ref","enabled","setError","React","_a","error","retryError","import_jsx_runtime","Video","src","autoPlay","muteFallback","props","ref","videoRef","setVideoRef","config","setError","error","useVideo","refVideo","video","thirdPartyRef","useAutoplayByForce","onPlay","_a","_b","_c","import_react","import_react_slot","import_jsx_runtime","Play","React","children","asChild","props","Element","videoRef","useVideo","_a","_b","Pause","Loading","import_react","useVideoState","videoRef","isPlaying","setIsPlaying","video"]}
@@ -1,36 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React$1, { RefObject } from 'react';
3
-
4
- type VideoAutoplay = boolean | "force";
5
-
6
- interface VideoConfig {
7
- config?: Partial<{
8
- clickToPlay: boolean;
9
- }>;
10
- }
11
- type VideoProviderProps = React.ComponentProps<"div"> & VideoConfig & {
12
- children: React.ReactNode;
13
- onError?: (error: string | null) => void;
14
- };
15
- declare const VideoProvider: ({ children, config, onError, ...props }: VideoProviderProps) => react_jsx_runtime.JSX.Element;
16
-
17
- interface Props$1 extends Omit<React$1.ComponentProps<"video">, "autoPlay"> {
18
- src: string;
19
- autoPlay?: VideoAutoplay;
20
- muteFallback?: (onMute: () => void) => React$1.ReactNode;
21
- }
22
- declare const Video: React$1.ForwardRefExoticComponent<Omit<Props$1, "ref"> & React$1.RefAttributes<HTMLVideoElement>>;
23
-
24
- interface Props extends React$1.ComponentProps<"button"> {
25
- children: React$1.ReactNode;
26
- asChild?: boolean;
27
- }
28
- declare const Play: React$1.MemoExoticComponent<({ children, asChild, ...props }: Props) => react_jsx_runtime.JSX.Element>;
29
- declare const Pause: React$1.MemoExoticComponent<({ children, asChild, ...props }: Props) => react_jsx_runtime.JSX.Element>;
30
- declare const Loading: () => react_jsx_runtime.JSX.Element;
31
-
32
- declare const useVideoState: (videoRef: RefObject<HTMLVideoElement | null>) => {
33
- isPlaying: boolean;
34
- };
35
-
36
- export { Loading, Pause, Play, Video, VideoProvider, useVideoState };
@@ -1,36 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React$1, { RefObject } from 'react';
3
-
4
- type VideoAutoplay = boolean | "force";
5
-
6
- interface VideoConfig {
7
- config?: Partial<{
8
- clickToPlay: boolean;
9
- }>;
10
- }
11
- type VideoProviderProps = React.ComponentProps<"div"> & VideoConfig & {
12
- children: React.ReactNode;
13
- onError?: (error: string | null) => void;
14
- };
15
- declare const VideoProvider: ({ children, config, onError, ...props }: VideoProviderProps) => react_jsx_runtime.JSX.Element;
16
-
17
- interface Props$1 extends Omit<React$1.ComponentProps<"video">, "autoPlay"> {
18
- src: string;
19
- autoPlay?: VideoAutoplay;
20
- muteFallback?: (onMute: () => void) => React$1.ReactNode;
21
- }
22
- declare const Video: React$1.ForwardRefExoticComponent<Omit<Props$1, "ref"> & React$1.RefAttributes<HTMLVideoElement>>;
23
-
24
- interface Props extends React$1.ComponentProps<"button"> {
25
- children: React$1.ReactNode;
26
- asChild?: boolean;
27
- }
28
- declare const Play: React$1.MemoExoticComponent<({ children, asChild, ...props }: Props) => react_jsx_runtime.JSX.Element>;
29
- declare const Pause: React$1.MemoExoticComponent<({ children, asChild, ...props }: Props) => react_jsx_runtime.JSX.Element>;
30
- declare const Loading: () => react_jsx_runtime.JSX.Element;
31
-
32
- declare const useVideoState: (videoRef: RefObject<HTMLVideoElement | null>) => {
33
- isPlaying: boolean;
34
- };
35
-
36
- export { Loading, Pause, Play, Video, VideoProvider, useVideoState };
package/dist/new/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use client";import{a as V}from"../chunk-WLYC6MHJ.js";import{createContext as b,useContext as h,useEffect as k,useState as P}from"react";import{jsx as y}from"react/jsx-runtime";var v=b(void 0),L=({children:t,config:d,onError:o,...r})=>{let[n,e]=P(null),[i,s]=P(null);return k(()=>{o==null||o(i)},[i]),y(v.Provider,{value:{videoRef:n,setVideoRef:e,config:{clickToPlay:!0,...d},error:i,setError:s},children:y("div",{...r,children:t})})},u=()=>{let t=h(v);if(!t)throw new Error("useVideo must be used within a VideoProvider");return t};import{forwardRef as T,useEffect as O,useRef as w}from"react";import{Fragment as N,jsx as M,jsxs as A}from"react/jsx-runtime";var C=T(({src:t,autoPlay:d,muteFallback:o,...r},n)=>{let{videoRef:e,setVideoRef:i,config:s,setError:f,error:E}=u(),p=w(null);O(()=>{let c=p.current,l=n;l?i(l):c&&i({current:c})},[t]),V(e,d==="force"&&r.muted===void 0,f);let g=()=>{var c,l,m;(c=e==null?void 0:e.current)!=null&&c.paused?(l=e.current)==null||l.play():(m=e==null?void 0:e.current)==null||m.pause()};return A(N,{children:[M("video",{ref:n||p,src:t,...r,onClick:s!=null&&s.clickToPlay?g:void 0}),E==="NotAllowedError"&&typeof o=="function"&&o(()=>{e!=null&&e.current&&(e.current.muted=!e.current.muted),f(null)})]})});C.displayName="Video";import R from"react";import{Slot as x}from"@radix-ui/react-slot";import{jsx as a}from"react/jsx-runtime";var Y=R.memo(({children:t,asChild:d,...o})=>{let r=d?x:"button",{videoRef:n}=u();return a(r,{...o,onClick:()=>{var i,s;(i=n==null?void 0:n.current)!=null&&i.paused&&((s=n.current)==null||s.play())},children:t})}),Z=R.memo(({children:t,asChild:d,...o})=>{let r=d?x:"button",{videoRef:n}=u();return a(r,{...o,onClick:()=>{var i;n!=null&&n.current&&((i=n.current)==null||i.pause())},children:t})}),_=()=>a("div",{children:"Loading"});import{useEffect as H,useState as S}from"react";var re=t=>{let[d,o]=S(!1);return H(()=>{let r=t.current;if(r)return r.addEventListener("play",()=>o(!0)),r.addEventListener("pause",()=>o(!1)),()=>{r.removeEventListener("play",()=>o(!0)),r.removeEventListener("pause",()=>o(!1))}},[t]),{isPlaying:d}};export{_ as Loading,Z as Pause,Y as Play,C as Video,L as VideoProvider,re as useVideoState};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/new/wrapper.tsx","../../src/new/video.tsx","../../src/new/components.tsx","../../src/new/hook.tsx"],"sourcesContent":["import {\n createContext,\n RefObject,\n useContext,\n useEffect,\n useState,\n} from \"react\";\nimport { VideoRef } from \"./types\";\n\ninterface VideoConfig {\n config?: Partial<{\n clickToPlay: boolean;\n }>;\n}\n\ninterface VideoContextType extends VideoConfig {\n videoRef: VideoRef | null;\n setVideoRef: (video: VideoRef | null) => void;\n error: string | null;\n setError: (error: string | null) => void;\n}\n\nexport const VideoContext = createContext<VideoContextType | undefined>(\n undefined\n);\n\ntype VideoProviderProps = React.ComponentProps<\"div\"> &\n VideoConfig & {\n children: React.ReactNode;\n onError?: (error: string | null) => void;\n };\n\nexport const VideoProvider = ({\n children,\n config,\n onError,\n ...props\n}: VideoProviderProps) => {\n const [videoRef, setVideoRef] = useState<VideoRef | null>(null);\n const [error, setError] = useState<string | null>(null);\n\n // Sending error to user if it exists\n useEffect(() => {\n onError?.(error);\n }, [error]);\n\n return (\n <VideoContext.Provider\n value={{\n videoRef,\n setVideoRef,\n config: { clickToPlay: true, ...config },\n error,\n setError,\n }}\n >\n <div {...props}>{children}</div>\n </VideoContext.Provider>\n );\n};\n\nexport const useVideo = () => {\n const context = useContext(VideoContext);\n if (!context) {\n throw new Error(\"useVideo must be used within a VideoProvider\");\n }\n return context;\n};\n","import React, { forwardRef, RefObject, useEffect, useRef } from \"react\";\nimport { useVideo } from \"./wrapper\";\nimport { VideoAutoplay } from \"./types\";\nimport { useAutoplayByForce } from \"../hooks/use-autoplay-by-force\";\n\ninterface Props extends Omit<React.ComponentProps<\"video\">, \"autoPlay\"> {\n src: string;\n autoPlay?: VideoAutoplay;\n muteFallback?: (onMute: () => void) => React.ReactNode;\n}\n\nexport const Video = forwardRef<HTMLVideoElement, Props>(\n ({ src, autoPlay, muteFallback, ...props }, ref) => {\n const { videoRef, setVideoRef, config, setError, error } = useVideo();\n\n const refVideo = useRef<HTMLVideoElement>(null);\n\n useEffect(() => {\n const video = refVideo.current;\n const thirdPartyRef = ref;\n\n if (thirdPartyRef) {\n setVideoRef(thirdPartyRef as RefObject<HTMLVideoElement>);\n } else {\n if (video) {\n setVideoRef({ current: video });\n }\n }\n }, [src]);\n\n useAutoplayByForce(\n videoRef,\n autoPlay === \"force\" && props.muted === undefined,\n setError\n );\n\n const onPlay = () => {\n if (videoRef?.current?.paused) {\n videoRef.current?.play();\n } else {\n videoRef?.current?.pause();\n }\n };\n\n return (\n <>\n <video\n ref={ref || refVideo}\n src={src}\n {...props}\n onClick={config?.clickToPlay ? onPlay : undefined}\n />\n\n {error === \"NotAllowedError\" &&\n typeof muteFallback === \"function\" &&\n muteFallback(() => {\n if (videoRef?.current) {\n videoRef.current.muted = !videoRef.current.muted;\n }\n setError(null);\n })}\n </>\n );\n }\n);\n\nVideo.displayName = \"Video\";\n","import React from \"react\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { useVideo } from \"./wrapper\";\n\ninterface Props extends React.ComponentProps<\"button\"> {\n children: React.ReactNode;\n asChild?: boolean;\n}\n\nconst Play = React.memo(({ children, asChild, ...props }: Props) => {\n const Element = asChild ? Slot : \"button\";\n const { videoRef } = useVideo();\n\n const handleClick = () => {\n if (videoRef?.current?.paused) {\n videoRef.current?.play();\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst Pause = React.memo(({ children, asChild, ...props }: Props) => {\n const Element = asChild ? Slot : \"button\";\n const { videoRef } = useVideo();\n\n const handleClick = () => {\n if (videoRef?.current) {\n videoRef.current?.pause();\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst Loading = () => {\n return <div>Loading</div>;\n};\n\nexport { Play, Pause, Loading };\n","import { RefObject, useEffect, useState } from \"react\";\n\nconst useVideoState = (videoRef: RefObject<HTMLVideoElement | null>) => {\n const [isPlaying, setIsPlaying] = useState(false);\n\n useEffect(() => {\n const video = videoRef.current;\n\n if (video) {\n video.addEventListener(\"play\", () => setIsPlaying(true));\n video.addEventListener(\"pause\", () => setIsPlaying(false));\n\n return () => {\n video.removeEventListener(\"play\", () => setIsPlaying(true));\n video.removeEventListener(\"pause\", () => setIsPlaying(false));\n };\n }\n }, [videoRef]);\n\n return { isPlaying };\n};\n\nexport { useVideoState };\n"],"mappings":"sDAAA,OACE,iBAAAA,EAEA,cAAAC,EACA,aAAAC,EACA,YAAAC,MACK,QAkDD,cAAAC,MAAA,oBAlCC,IAAMC,EAAeL,EAC1B,MACF,EAQaM,EAAgB,CAAC,CAC5B,SAAAC,EACA,OAAAC,EACA,QAAAC,EACA,GAAGC,CACL,IAA0B,CACxB,GAAM,CAACC,EAAUC,CAAW,EAAIT,EAA0B,IAAI,EACxD,CAACU,EAAOC,CAAQ,EAAIX,EAAwB,IA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AK,EAEhD,OAAAD,EAAU,IAAM,CACd,IAAMM,EAAQH,EAAS,QAEvB,GAAIG,EACF,OAAAA,EAAM,iBAAiB,OAAQ,IAAMD,EAAa,EAAI,CAAC,EACvDC,EAAM,iBAAiB,QAAS,IAAMD,EAAa,EAAK,CAAC,EAElD,IAAM,CACXC,EAAM,oBAAoB,OAAQ,IAAMD,EAAa,EAAI,CAAC,EAC1DC,EAAM,oBAAoB,QAAS,IAAMD,EAAa,EAAK,CAAC,CAC9D,CAEJ,EAAG,CAACF,CAAQ,CAAC,EAEN,CAAE,UAAAC,CAAU,CACrB","names":["createContext","useContext","useEffect","useState","jsx","VideoContext","VideoProvider","children","config","onError","props","videoRef","setVideoRef","error","setError","useVideo","context","forwardRef","useEffect","useRef","Fragment","jsx","jsxs","Video","forwardRef","src","autoPlay","muteFallback","props","ref","videoRef","setVideoRef","config","setError","error","useVideo","refVideo","useRef","useEffect","video","thirdPartyRef","useAutoplayByForce","onPlay","_a","_b","_c","React","Slot","jsx","Play","React","children","asChild","props","Element","Slot","videoRef","useVideo","_a","_b","Pause","Loading","useEffect","useState","useVideoState","videoRef","isPlaying","setIsPlaying","video"]}