@zuude-ui/video 0.1.3 → 0.1.5
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 +223 -0
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -90
- package/dist/index.d.ts +36 -90
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/new/index.cjs +1 -1
- package/dist/new/index.cjs.map +1 -1
- package/dist/new/index.d.cts +18 -1
- package/dist/new/index.d.ts +18 -1
- package/dist/new/index.js +1 -1
- package/dist/new/index.js.map +1 -1
- package/dist/utils/index.cjs +2 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +51 -0
- package/dist/utils/index.d.ts +51 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +20 -3
package/dist/new/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,IAAI,EAGtD,OAAAD,EAAU,IAAM,CACdO,GAAA,MAAAA,EAAUI,EACZ,EAAG,CAACA,CAAK,CAAC,EAGRT,EAACC,EAAa,SAAb,CACC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,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"]}
|
|
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 data-zuude-video-wrapper {...props}>\n {children}\n </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 onClick={config?.clickToPlay ? onPlay : undefined}\n autoPlay={autoPlay === \"force\" ? true : autoPlay}\n {...props}\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\";\nimport { useFullscreen } from \"./hook\";\n\ninterface ControlsProps extends React.ComponentProps<\"div\"> {\n children: React.ReactNode;\n asChild?: boolean;\n}\n\nconst Controls = React.memo(\n ({ children, asChild, ...props }: ControlsProps) => {\n return <div {...props}>{children}</div>;\n }\n);\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 Mute = 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.muted = true;\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst Unmute = 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.muted = false;\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst SeekForward = 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.currentTime += 10;\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst SeekBackward = 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.currentTime -= 10;\n }\n };\n\n return (\n <Element {...props} onClick={handleClick}>\n {children}\n </Element>\n );\n});\n\nconst Fullscreen = React.memo(({ children, asChild, ...props }: Props) => {\n const Element = asChild ? Slot : \"button\";\n const { videoRef } = useVideo();\n\n const { toggleFullscreen } = useFullscreen(\n videoRef?.current as HTMLVideoElement | null\n );\n\n return (\n <Element {...props} onClick={toggleFullscreen}>\n {children}\n </Element>\n );\n});\n\nconst ExitFullscreen = React.memo(({ children, asChild, ...props }: Props) => {\n const Element = asChild ? Slot : \"button\";\n const { videoRef } = useVideo();\n\n const { toggleFullscreen } = useFullscreen(\n videoRef?.current as HTMLVideoElement | null\n );\n\n return (\n <Element {...props} onClick={toggleFullscreen}>\n {children}\n </Element>\n );\n});\n\nconst Loading = () => {\n return <div>Loading</div>;\n};\n\nexport {\n Controls,\n Play,\n Pause,\n Mute,\n Unmute,\n SeekForward,\n SeekBackward,\n Fullscreen,\n ExitFullscreen,\n Loading,\n};\n","import { RefObject, useEffect, useState } from \"react\";\n\nconst useVideoState = (videoRef: RefObject<HTMLVideoElement | null>) => {\n const [isPlaying, setIsPlaying] = useState(false);\n const [isMuted, setIsMuted] = useState(false);\n const [isFullscreen, setIsFullscreen] = 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 useEffect(() => {\n if (!videoRef?.current) return;\n\n // Set the initial state\n setIsMuted(videoRef.current.muted);\n\n const handleVolumeChange = () => {\n if (videoRef.current) {\n setIsMuted(videoRef.current.muted);\n }\n };\n\n videoRef.current.addEventListener(\"volumechange\", handleVolumeChange);\n\n return () => {\n videoRef.current?.removeEventListener(\"volumechange\", handleVolumeChange);\n };\n }, [videoRef]);\n\n useEffect(() => {\n if (!videoRef?.current) return;\n\n const handleFullscreenChange = () => {\n setIsFullscreen(!!document.fullscreenElement);\n };\n\n document.addEventListener(\"fullscreenchange\", handleFullscreenChange);\n return () =>\n document.removeEventListener(\"fullscreenchange\", handleFullscreenChange);\n }, [videoRef]);\n\n return { isPlaying, isMuted, isFullscreen };\n};\n\nimport React from \"react\";\n\nconst useFullscreen = (videoRef: HTMLVideoElement | null) => {\n const [isFullscreen, setIsFullscreen] = React.useState(false);\n\n React.useEffect(() => {\n const handleFullscreenChange = () => {\n setIsFullscreen?.(!!document.fullscreenElement);\n toggleFullscreen();\n };\n\n document.addEventListener(\"fullscreenchange\", handleFullscreenChange);\n return () =>\n document.removeEventListener(\"fullscreenchange\", handleFullscreenChange);\n }, [isFullscreen]);\n\n const toggleFullscreen = () => {\n console.log(\"toggleFullscreen\");\n const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n const video = videoRef;\n\n if (video && isSafari) {\n if ((video as any).webkitEnterFullscreen) {\n (video as any).webkitEnterFullscreen();\n return;\n } else if (video.requestFullscreen) {\n video.requestFullscreen();\n return;\n }\n }\n\n const videoContainer = video?.closest(\n \"[data-zuude-video-wrapper]\"\n ) as HTMLElement;\n\n if (videoContainer) {\n if (!isFullscreen) {\n videoContainer.requestFullscreen();\n if (video) {\n video.style.objectFit = \"contain\";\n }\n } else {\n document.exitFullscreen();\n if (video) {\n video.style.objectFit = \"cover\";\n }\n }\n }\n };\n\n return { isFullscreen: isFullscreen ?? false, toggleFullscreen };\n};\n\nexport { useVideoState, useFullscreen };\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,E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c,EAC1B,SAAAhB,EACH,CAEJ,CAAC,EAEKkB,GAAiBnB,EAAM,KAAK,CAAC,CAAE,SAAAC,EAAU,QAAAC,EAAS,GAAGC,CAAM,IAAa,CAC5E,IAAME,EAAUH,EAAUI,EAAO,SAC3B,CAAE,SAAAC,CAAS,EAAIC,EAAS,EAExB,CAAE,iBAAAS,CAAiB,EAAIC,EAC3BX,GAAA,YAAAA,EAAU,OACZ,EAEA,OACET,EAACO,EAAA,CAAS,GAAGF,EAAO,QAASc,EAC1B,SAAAhB,EACH,CAEJ,CAAC,EAEKmB,GAAU,IACPtB,EAAC,OAAI,mBAAO","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","useEffect","useState","React","useVideoState","videoRef","isPlaying","setIsPlaying","isMuted","setIsMuted","isFullscreen","setIsFullscreen","video","handleVolumeChange","_a","handleFullscreenChange","useFullscreen","toggleFullscreen","isSafari","videoContainer","jsx","Controls","React","children","asChild","props","Play","Element","Slot","videoRef","useVideo","_a","_b","Pause","Mute","Unmute","SeekForward","SeekBackward","Fullscreen","toggleFullscreen","useFullscreen","ExitFullscreen","Loading"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var d=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var x=(o,t)=>{for(var s in t)d(o,s,{get:t[s],enumerable:!0})},y=(o,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of F(t))!w.call(o,r)&&r!==s&&d(o,r,{get:()=>t[r],enumerable:!(n=T(t,r))||n.enumerable});return o};var L=o=>y(d({},"__esModule",{value:!0}),o);var Z={};x(Z,{compactTime:()=>b,detailedTime:()=>M,formatTime:()=>$,formatTimeForAccessibility:()=>O,formatTimeWithPercentage:()=>A,getTimeSegments:()=>H,humanizeTime:()=>g,parseTime:()=>W,timeRemaining:()=>z});module.exports=L(Z);function $(o,t="mm:ss"){let s=typeof t=="string"?{format:t}:t,{format:n="mm:ss",showHours:r=!0,showLeadingZeros:i=!0,showMilliseconds:c=!1,humanize:a=!1,compact:m=!1}=s;if(a)return g(o,{compact:m});let u=Math.floor(o),h=Math.floor(u/3600),l=Math.floor(u%3600/60),f=u%60,j=Math.floor(o%1*1e3),e=(p,S=2)=>i?p.toString().padStart(S,"0"):p.toString();switch(n){case"h:mm:ss":return`${e(h)}:${e(l)}:${e(f)}`;case"mm:ss":return r&&h>0?`${e(h)}:${e(l)}:${e(f)}`:`${e(l)}:${e(f)}`;case"ss":return`${u}s`;case"compact":return b(o);case"detailed":return M(o,{showMilliseconds:c});default:return`${e(l)}:${e(f)}`}}function g(o,t={}){let{compact:s=!1}=t,n=Math.floor(o);if(n<60)return`${n} second${n!==1?"s":""}`;let r=Math.floor(n/3600),i=Math.floor(n%3600/60),c=n%60,a=[];return r>0&&a.push(`${r} hour${r!==1?"s":""}`),i>0&&a.push(`${i} minute${i!==1?"s":""}`),c>0&&!s&&a.push(`${c} second${c!==1?"s":""}`),a.join(" ")}function b(o){let t=Math.floor(o),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}:${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${n}:${r.toString().padStart(2,"0")}`}function M(o,t={}){let{showMilliseconds:s=!1}=t,n=Math.floor(o),r=Math.floor(n/3600),i=Math.floor(n%3600/60),c=n%60,a=Math.floor(o%1*1e3),m=`${r.toString().padStart(2,"0")}:${i.toString().padStart(2,"0")}:${c.toString().padStart(2,"0")}`;return s&&(m+=`.${a.toString().padStart(3,"0")}`),m}function W(o){let t=o.toLowerCase().trim();if(t.endsWith("s"))return parseFloat(t.slice(0,-1));if(t.endsWith("m"))return parseFloat(t.slice(0,-1))*60;if(t.endsWith("h"))return parseFloat(t.slice(0,-1))*3600;let s=o.split(":").map(Number);return s.length===2?(s[0]||0)*60+(s[1]||0):s.length===3?(s[0]||0)*3600+(s[1]||0)*60+(s[2]||0):parseFloat(o)||0}function z(o,t,s="mm:ss"){let n=Math.max(0,t-o);return $(n,s)}function A(o,t,s="mm:ss"){let n=t>0?Math.round(o/t*100):0;return`${$(o,s)} (${n}%)`}function H(o,t=10){return Array.from({length:t+1},(s,n)=>o/t*n)}function O(o){let t=Math.floor(o),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s} hours, ${n} minutes, ${r} seconds`:n>0?`${n} minutes, ${r} seconds`:`${r} seconds`}0&&(module.exports={compactTime,detailedTime,formatTime,formatTimeForAccessibility,formatTimeWithPercentage,getTimeSegments,humanizeTime,parseTime,timeRemaining});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Video Time Formatting Utilities - Similar to date-fns but for video durations\n\nexport type TimeFormat =\n | \"h:mm:ss\"\n | \"mm:ss\"\n | \"ss\"\n | \"human\"\n | \"compact\"\n | \"detailed\";\n\nexport interface TimeFormatOptions {\n format?: TimeFormat;\n showHours?: boolean;\n showLeadingZeros?: boolean;\n showMilliseconds?: boolean;\n humanize?: boolean;\n compact?: boolean;\n}\n\n/**\n * Format time in seconds to various formats\n */\nfunction formatTime(\n time: number,\n options: TimeFormatOptions | TimeFormat = \"mm:ss\"\n): string {\n const opts = typeof options === \"string\" ? { format: options } : options;\n const {\n format = \"mm:ss\",\n showHours = true,\n showLeadingZeros = true,\n showMilliseconds = false,\n humanize = false,\n compact = false,\n } = opts;\n\n if (humanize) {\n return humanizeTime(time, { compact });\n }\n\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n const milliseconds = Math.floor((time % 1) * 1000);\n\n const pad = (num: number, size: number = 2) =>\n showLeadingZeros ? num.toString().padStart(size, \"0\") : num.toString();\n\n switch (format) {\n case \"h:mm:ss\":\n return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;\n case \"mm:ss\":\n return showHours && hours > 0\n ? `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`\n : `${pad(minutes)}:${pad(seconds)}`;\n case \"ss\":\n return `${totalSeconds}s`;\n case \"compact\":\n return compactTime(time);\n case \"detailed\":\n return detailedTime(time, { showMilliseconds });\n default:\n return `${pad(minutes)}:${pad(seconds)}`;\n }\n}\n\n/**\n * Humanize time duration (e.g., \"2 minutes 30 seconds\")\n */\nfunction humanizeTime(\n time: number,\n options: { compact?: boolean } = {}\n): string {\n const { compact = false } = options;\n const totalSeconds = Math.floor(time);\n\n if (totalSeconds < 60) {\n return `${totalSeconds} second${totalSeconds !== 1 ? \"s\" : \"\"}`;\n }\n\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n const parts: string[] = [];\n\n if (hours > 0) {\n parts.push(`${hours} hour${hours !== 1 ? \"s\" : \"\"}`);\n }\n\n if (minutes > 0) {\n parts.push(`${minutes} minute${minutes !== 1 ? \"s\" : \"\"}`);\n }\n\n if (seconds > 0 && !compact) {\n parts.push(`${seconds} second${seconds !== 1 ? \"s\" : \"\"}`);\n }\n\n return parts.join(\" \");\n}\n\n/**\n * Compact time format (e.g., \"2:30\" for 2 minutes 30 seconds)\n */\nfunction compactTime(time: number): string {\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n if (hours > 0) {\n return `${hours}:${minutes.toString().padStart(2, \"0\")}:${seconds.toString().padStart(2, \"0\")}`;\n }\n\n return `${minutes}:${seconds.toString().padStart(2, \"0\")}`;\n}\n\n/**\n * Detailed time format with milliseconds\n */\nfunction detailedTime(\n time: number,\n options: { showMilliseconds?: boolean } = {}\n): string {\n const { showMilliseconds = false } = options;\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n const milliseconds = Math.floor((time % 1) * 1000);\n\n let result = `${hours.toString().padStart(2, \"0\")}:${minutes.toString().padStart(2, \"0\")}:${seconds.toString().padStart(2, \"0\")}`;\n\n if (showMilliseconds) {\n result += `.${milliseconds.toString().padStart(3, \"0\")}`;\n }\n\n return result;\n}\n\n/**\n * Parse time string to seconds\n */\nfunction parseTime(timeString: string): number {\n // Handle formats like \"2:30\", \"1:23:45\", \"90s\", \"1.5m\"\n const timeStringLower = timeString.toLowerCase().trim();\n\n // Handle seconds format \"90s\"\n if (timeStringLower.endsWith(\"s\")) {\n return parseFloat(timeStringLower.slice(0, -1));\n }\n\n // Handle minutes format \"1.5m\"\n if (timeStringLower.endsWith(\"m\")) {\n return parseFloat(timeStringLower.slice(0, -1)) * 60;\n }\n\n // Handle hours format \"1.5h\"\n if (timeStringLower.endsWith(\"h\")) {\n return parseFloat(timeStringLower.slice(0, -1)) * 3600;\n }\n\n // Handle HH:MM:SS or MM:SS format\n const parts = timeString.split(\":\").map(Number);\n\n if (parts.length === 2) {\n // MM:SS format\n return (parts[0] || 0) * 60 + (parts[1] || 0);\n } else if (parts.length === 3) {\n // HH:MM:SS format\n return (parts[0] || 0) * 3600 + (parts[1] || 0) * 60 + (parts[2] || 0);\n }\n\n // Fallback to parsing as seconds\n return parseFloat(timeString) || 0;\n}\n\n/**\n * Calculate time remaining\n */\nfunction timeRemaining(\n current: number,\n total: number,\n format: TimeFormat = \"mm:ss\"\n): string {\n const remaining = Math.max(0, total - current);\n return formatTime(remaining, format);\n}\n\n/**\n * Format time with percentage\n */\nfunction formatTimeWithPercentage(\n current: number,\n total: number,\n format: TimeFormat = \"mm:ss\"\n): string {\n const percentage = total > 0 ? Math.round((current / total) * 100) : 0;\n return `${formatTime(current, format)} (${percentage}%)`;\n}\n\n/**\n * Get time segments for timeline\n */\nfunction getTimeSegments(duration: number, segments: number = 10): number[] {\n return Array.from(\n { length: segments + 1 },\n (_, i) => (duration / segments) * i\n );\n}\n\n/**\n * Format time for accessibility (screen readers)\n */\nfunction formatTimeForAccessibility(time: number): string {\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n if (hours > 0) {\n return `${hours} hours, ${minutes} minutes, ${seconds} seconds`;\n } else if (minutes > 0) {\n return `${minutes} minutes, ${seconds} seconds`;\n } else {\n return `${seconds} seconds`;\n }\n}\n\nexport {\n formatTime,\n humanizeTime,\n compactTime,\n detailedTime,\n parseTime,\n timeRemaining,\n formatTimeWithPercentage,\n getTimeSegments,\n formatTimeForAccessibility,\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,EAAA,iBAAAC,EAAA,eAAAC,EAAA,+BAAAC,EAAA,6BAAAC,EAAA,oBAAAC,EAAA,iBAAAC,EAAA,cAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAX,GAsBA,SAASI,EACPQ,EACAC,EAA0C,QAClC,CACR,IAAMC,EAAO,OAAOD,GAAY,SAAW,CAAE,OAAQA,CAAQ,EAAIA,EAC3D,CACJ,OAAAE,EAAS,QACT,UAAAC,EAAY,GACZ,iBAAAC,EAAmB,GACnB,iBAAAC,EAAmB,GACnB,SAAAC,EAAW,GACX,QAAAC,EAAU,EACZ,EAAIN,EAEJ,GAAIK,EACF,OAAOX,EAAaI,EAAM,CAAE,QAAAQ,CAAQ,CAAC,EAGvC,IAAMC,EAAe,KAAK,MAAMT,CAAI,EAC9BU,EAAQ,KAAK,MAAMD,EAAe,IAAI,EACtCE,EAAU,KAA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AGA,CAAO,UAErB","names":["utils_exports","__export","compactTime","detailedTime","formatTime","formatTimeForAccessibility","formatTimeWithPercentage","getTimeSegments","humanizeTime","parseTime","timeRemaining","__toCommonJS","time","options","opts","format","showHours","showLeadingZeros","showMilliseconds","humanize","compact","totalSeconds","hours","minutes","seconds","milliseconds","pad","num","size","parts","result","timeString","timeStringLower","current","total","remaining","percentage","duration","segments","_","i"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type TimeFormat = "h:mm:ss" | "mm:ss" | "ss" | "human" | "compact" | "detailed";
|
|
2
|
+
interface TimeFormatOptions {
|
|
3
|
+
format?: TimeFormat;
|
|
4
|
+
showHours?: boolean;
|
|
5
|
+
showLeadingZeros?: boolean;
|
|
6
|
+
showMilliseconds?: boolean;
|
|
7
|
+
humanize?: boolean;
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Format time in seconds to various formats
|
|
12
|
+
*/
|
|
13
|
+
declare function formatTime(time: number, options?: TimeFormatOptions | TimeFormat): string;
|
|
14
|
+
/**
|
|
15
|
+
* Humanize time duration (e.g., "2 minutes 30 seconds")
|
|
16
|
+
*/
|
|
17
|
+
declare function humanizeTime(time: number, options?: {
|
|
18
|
+
compact?: boolean;
|
|
19
|
+
}): string;
|
|
20
|
+
/**
|
|
21
|
+
* Compact time format (e.g., "2:30" for 2 minutes 30 seconds)
|
|
22
|
+
*/
|
|
23
|
+
declare function compactTime(time: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* Detailed time format with milliseconds
|
|
26
|
+
*/
|
|
27
|
+
declare function detailedTime(time: number, options?: {
|
|
28
|
+
showMilliseconds?: boolean;
|
|
29
|
+
}): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parse time string to seconds
|
|
32
|
+
*/
|
|
33
|
+
declare function parseTime(timeString: string): number;
|
|
34
|
+
/**
|
|
35
|
+
* Calculate time remaining
|
|
36
|
+
*/
|
|
37
|
+
declare function timeRemaining(current: number, total: number, format?: TimeFormat): string;
|
|
38
|
+
/**
|
|
39
|
+
* Format time with percentage
|
|
40
|
+
*/
|
|
41
|
+
declare function formatTimeWithPercentage(current: number, total: number, format?: TimeFormat): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get time segments for timeline
|
|
44
|
+
*/
|
|
45
|
+
declare function getTimeSegments(duration: number, segments?: number): number[];
|
|
46
|
+
/**
|
|
47
|
+
* Format time for accessibility (screen readers)
|
|
48
|
+
*/
|
|
49
|
+
declare function formatTimeForAccessibility(time: number): string;
|
|
50
|
+
|
|
51
|
+
export { type TimeFormat, type TimeFormatOptions, compactTime, detailedTime, formatTime, formatTimeForAccessibility, formatTimeWithPercentage, getTimeSegments, humanizeTime, parseTime, timeRemaining };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type TimeFormat = "h:mm:ss" | "mm:ss" | "ss" | "human" | "compact" | "detailed";
|
|
2
|
+
interface TimeFormatOptions {
|
|
3
|
+
format?: TimeFormat;
|
|
4
|
+
showHours?: boolean;
|
|
5
|
+
showLeadingZeros?: boolean;
|
|
6
|
+
showMilliseconds?: boolean;
|
|
7
|
+
humanize?: boolean;
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Format time in seconds to various formats
|
|
12
|
+
*/
|
|
13
|
+
declare function formatTime(time: number, options?: TimeFormatOptions | TimeFormat): string;
|
|
14
|
+
/**
|
|
15
|
+
* Humanize time duration (e.g., "2 minutes 30 seconds")
|
|
16
|
+
*/
|
|
17
|
+
declare function humanizeTime(time: number, options?: {
|
|
18
|
+
compact?: boolean;
|
|
19
|
+
}): string;
|
|
20
|
+
/**
|
|
21
|
+
* Compact time format (e.g., "2:30" for 2 minutes 30 seconds)
|
|
22
|
+
*/
|
|
23
|
+
declare function compactTime(time: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* Detailed time format with milliseconds
|
|
26
|
+
*/
|
|
27
|
+
declare function detailedTime(time: number, options?: {
|
|
28
|
+
showMilliseconds?: boolean;
|
|
29
|
+
}): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parse time string to seconds
|
|
32
|
+
*/
|
|
33
|
+
declare function parseTime(timeString: string): number;
|
|
34
|
+
/**
|
|
35
|
+
* Calculate time remaining
|
|
36
|
+
*/
|
|
37
|
+
declare function timeRemaining(current: number, total: number, format?: TimeFormat): string;
|
|
38
|
+
/**
|
|
39
|
+
* Format time with percentage
|
|
40
|
+
*/
|
|
41
|
+
declare function formatTimeWithPercentage(current: number, total: number, format?: TimeFormat): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get time segments for timeline
|
|
44
|
+
*/
|
|
45
|
+
declare function getTimeSegments(duration: number, segments?: number): number[];
|
|
46
|
+
/**
|
|
47
|
+
* Format time for accessibility (screen readers)
|
|
48
|
+
*/
|
|
49
|
+
declare function formatTimeForAccessibility(time: number): string;
|
|
50
|
+
|
|
51
|
+
export { type TimeFormat, type TimeFormatOptions, compactTime, detailedTime, formatTime, formatTimeForAccessibility, formatTimeWithPercentage, getTimeSegments, humanizeTime, parseTime, timeRemaining };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function $(o,t="mm:ss"){let n=typeof t=="string"?{format:t}:t,{format:s="mm:ss",showHours:r=!0,showLeadingZeros:i=!0,showMilliseconds:c=!1,humanize:a=!1,compact:m=!1}=n;if(a)return g(o,{compact:m});let u=Math.floor(o),h=Math.floor(u/3600),l=Math.floor(u%3600/60),f=u%60,S=Math.floor(o%1*1e3),e=(d,p=2)=>i?d.toString().padStart(p,"0"):d.toString();switch(s){case"h:mm:ss":return`${e(h)}:${e(l)}:${e(f)}`;case"mm:ss":return r&&h>0?`${e(h)}:${e(l)}:${e(f)}`:`${e(l)}:${e(f)}`;case"ss":return`${u}s`;case"compact":return b(o);case"detailed":return M(o,{showMilliseconds:c});default:return`${e(l)}:${e(f)}`}}function g(o,t={}){let{compact:n=!1}=t,s=Math.floor(o);if(s<60)return`${s} second${s!==1?"s":""}`;let r=Math.floor(s/3600),i=Math.floor(s%3600/60),c=s%60,a=[];return r>0&&a.push(`${r} hour${r!==1?"s":""}`),i>0&&a.push(`${i} minute${i!==1?"s":""}`),c>0&&!n&&a.push(`${c} second${c!==1?"s":""}`),a.join(" ")}function b(o){let t=Math.floor(o),n=Math.floor(t/3600),s=Math.floor(t%3600/60),r=t%60;return n>0?`${n}:${s.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${s}:${r.toString().padStart(2,"0")}`}function M(o,t={}){let{showMilliseconds:n=!1}=t,s=Math.floor(o),r=Math.floor(s/3600),i=Math.floor(s%3600/60),c=s%60,a=Math.floor(o%1*1e3),m=`${r.toString().padStart(2,"0")}:${i.toString().padStart(2,"0")}:${c.toString().padStart(2,"0")}`;return n&&(m+=`.${a.toString().padStart(3,"0")}`),m}function T(o){let t=o.toLowerCase().trim();if(t.endsWith("s"))return parseFloat(t.slice(0,-1));if(t.endsWith("m"))return parseFloat(t.slice(0,-1))*60;if(t.endsWith("h"))return parseFloat(t.slice(0,-1))*3600;let n=o.split(":").map(Number);return n.length===2?(n[0]||0)*60+(n[1]||0):n.length===3?(n[0]||0)*3600+(n[1]||0)*60+(n[2]||0):parseFloat(o)||0}function F(o,t,n="mm:ss"){let s=Math.max(0,t-o);return $(s,n)}function w(o,t,n="mm:ss"){let s=t>0?Math.round(o/t*100):0;return`${$(o,n)} (${s}%)`}function x(o,t=10){return Array.from({length:t+1},(n,s)=>o/t*s)}function y(o){let t=Math.floor(o),n=Math.floor(t/3600),s=Math.floor(t%3600/60),r=t%60;return n>0?`${n} hours, ${s} minutes, ${r} seconds`:s>0?`${s} minutes, ${r} seconds`:`${r} seconds`}export{b as compactTime,M as detailedTime,$ as formatTime,y as formatTimeForAccessibility,w as formatTimeWithPercentage,x as getTimeSegments,g as humanizeTime,T as parseTime,F as timeRemaining};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Video Time Formatting Utilities - Similar to date-fns but for video durations\n\nexport type TimeFormat =\n | \"h:mm:ss\"\n | \"mm:ss\"\n | \"ss\"\n | \"human\"\n | \"compact\"\n | \"detailed\";\n\nexport interface TimeFormatOptions {\n format?: TimeFormat;\n showHours?: boolean;\n showLeadingZeros?: boolean;\n showMilliseconds?: boolean;\n humanize?: boolean;\n compact?: boolean;\n}\n\n/**\n * Format time in seconds to various formats\n */\nfunction formatTime(\n time: number,\n options: TimeFormatOptions | TimeFormat = \"mm:ss\"\n): string {\n const opts = typeof options === \"string\" ? { format: options } : options;\n const {\n format = \"mm:ss\",\n showHours = true,\n showLeadingZeros = true,\n showMilliseconds = false,\n humanize = false,\n compact = false,\n } = opts;\n\n if (humanize) {\n return humanizeTime(time, { compact });\n }\n\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n const milliseconds = Math.floor((time % 1) * 1000);\n\n const pad = (num: number, size: number = 2) =>\n showLeadingZeros ? num.toString().padStart(size, \"0\") : num.toString();\n\n switch (format) {\n case \"h:mm:ss\":\n return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;\n case \"mm:ss\":\n return showHours && hours > 0\n ? `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`\n : `${pad(minutes)}:${pad(seconds)}`;\n case \"ss\":\n return `${totalSeconds}s`;\n case \"compact\":\n return compactTime(time);\n case \"detailed\":\n return detailedTime(time, { showMilliseconds });\n default:\n return `${pad(minutes)}:${pad(seconds)}`;\n }\n}\n\n/**\n * Humanize time duration (e.g., \"2 minutes 30 seconds\")\n */\nfunction humanizeTime(\n time: number,\n options: { compact?: boolean } = {}\n): string {\n const { compact = false } = options;\n const totalSeconds = Math.floor(time);\n\n if (totalSeconds < 60) {\n return `${totalSeconds} second${totalSeconds !== 1 ? \"s\" : \"\"}`;\n }\n\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n const parts: string[] = [];\n\n if (hours > 0) {\n parts.push(`${hours} hour${hours !== 1 ? \"s\" : \"\"}`);\n }\n\n if (minutes > 0) {\n parts.push(`${minutes} minute${minutes !== 1 ? \"s\" : \"\"}`);\n }\n\n if (seconds > 0 && !compact) {\n parts.push(`${seconds} second${seconds !== 1 ? \"s\" : \"\"}`);\n }\n\n return parts.join(\" \");\n}\n\n/**\n * Compact time format (e.g., \"2:30\" for 2 minutes 30 seconds)\n */\nfunction compactTime(time: number): string {\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n if (hours > 0) {\n return `${hours}:${minutes.toString().padStart(2, \"0\")}:${seconds.toString().padStart(2, \"0\")}`;\n }\n\n return `${minutes}:${seconds.toString().padStart(2, \"0\")}`;\n}\n\n/**\n * Detailed time format with milliseconds\n */\nfunction detailedTime(\n time: number,\n options: { showMilliseconds?: boolean } = {}\n): string {\n const { showMilliseconds = false } = options;\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n const milliseconds = Math.floor((time % 1) * 1000);\n\n let result = `${hours.toString().padStart(2, \"0\")}:${minutes.toString().padStart(2, \"0\")}:${seconds.toString().padStart(2, \"0\")}`;\n\n if (showMilliseconds) {\n result += `.${milliseconds.toString().padStart(3, \"0\")}`;\n }\n\n return result;\n}\n\n/**\n * Parse time string to seconds\n */\nfunction parseTime(timeString: string): number {\n // Handle formats like \"2:30\", \"1:23:45\", \"90s\", \"1.5m\"\n const timeStringLower = timeString.toLowerCase().trim();\n\n // Handle seconds format \"90s\"\n if (timeStringLower.endsWith(\"s\")) {\n return parseFloat(timeStringLower.slice(0, -1));\n }\n\n // Handle minutes format \"1.5m\"\n if (timeStringLower.endsWith(\"m\")) {\n return parseFloat(timeStringLower.slice(0, -1)) * 60;\n }\n\n // Handle hours format \"1.5h\"\n if (timeStringLower.endsWith(\"h\")) {\n return parseFloat(timeStringLower.slice(0, -1)) * 3600;\n }\n\n // Handle HH:MM:SS or MM:SS format\n const parts = timeString.split(\":\").map(Number);\n\n if (parts.length === 2) {\n // MM:SS format\n return (parts[0] || 0) * 60 + (parts[1] || 0);\n } else if (parts.length === 3) {\n // HH:MM:SS format\n return (parts[0] || 0) * 3600 + (parts[1] || 0) * 60 + (parts[2] || 0);\n }\n\n // Fallback to parsing as seconds\n return parseFloat(timeString) || 0;\n}\n\n/**\n * Calculate time remaining\n */\nfunction timeRemaining(\n current: number,\n total: number,\n format: TimeFormat = \"mm:ss\"\n): string {\n const remaining = Math.max(0, total - current);\n return formatTime(remaining, format);\n}\n\n/**\n * Format time with percentage\n */\nfunction formatTimeWithPercentage(\n current: number,\n total: number,\n format: TimeFormat = \"mm:ss\"\n): string {\n const percentage = total > 0 ? Math.round((current / total) * 100) : 0;\n return `${formatTime(current, format)} (${percentage}%)`;\n}\n\n/**\n * Get time segments for timeline\n */\nfunction getTimeSegments(duration: number, segments: number = 10): number[] {\n return Array.from(\n { length: segments + 1 },\n (_, i) => (duration / segments) * i\n );\n}\n\n/**\n * Format time for accessibility (screen readers)\n */\nfunction formatTimeForAccessibility(time: number): string {\n const totalSeconds = Math.floor(time);\n const hours = Math.floor(totalSeconds / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n if (hours > 0) {\n return `${hours} hours, ${minutes} minutes, ${seconds} seconds`;\n } else if (minutes > 0) {\n return `${minutes} minutes, ${seconds} seconds`;\n } else {\n return `${seconds} seconds`;\n }\n}\n\nexport {\n formatTime,\n humanizeTime,\n compactTime,\n detailedTime,\n parseTime,\n timeRemaining,\n formatTimeWithPercentage,\n getTimeSegments,\n formatTimeForAccessibility,\n};\n"],"mappings":"AAsBA,SAASA,EACPC,EACAC,EAA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AQA,EAAW,CAAE,EACvB,CAACC,EAAGC,IAAOH,EAAWC,EAAYE,CACpC,CACF,CAKA,SAASC,EAA2BpC,EAAsB,CACxD,IAAMU,EAAe,KAAK,MAAMV,CAAI,EAC9BW,EAAQ,KAAK,MAAMD,EAAe,IAAI,EACtCE,EAAU,KAAK,MAAOF,EAAe,KAAQ,EAAE,EAC/CG,EAAUH,EAAe,GAE/B,OAAIC,EAAQ,EACH,GAAGA,CAAK,WAAWC,CAAO,aAAaC,CAAO,WAC5CD,EAAU,EACZ,GAAGA,CAAO,aAAaC,CAAO,WAE9B,GAAGA,CAAO,UAErB","names":["formatTime","time","options","opts","format","showHours","showLeadingZeros","showMilliseconds","humanize","compact","humanizeTime","totalSeconds","hours","minutes","seconds","milliseconds","pad","num","size","compactTime","detailedTime","parts","result","parseTime","timeString","timeStringLower","timeRemaining","current","total","remaining","formatTimeWithPercentage","percentage","getTimeSegments","duration","segments","_","i","formatTimeForAccessibility"]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.5",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
@@ -11,6 +11,23 @@
|
|
|
11
11
|
"dist/**"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
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"
|
|
24
|
+
},
|
|
25
|
+
"./utils": {
|
|
26
|
+
"types": "./dist/utils/index.d.ts",
|
|
27
|
+
"import": "./dist/utils/index.cjs",
|
|
28
|
+
"require": "./dist/utils/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
14
31
|
"scripts": {
|
|
15
32
|
"build": "tsup",
|
|
16
33
|
"lint": "tsc"
|
|
@@ -20,12 +37,12 @@
|
|
|
20
37
|
"license": "ISC",
|
|
21
38
|
"description": "",
|
|
22
39
|
"dependencies": {
|
|
23
|
-
"@radix-ui/react-slot": "^1.1.2",
|
|
24
40
|
"tsup": "^8.5.0",
|
|
25
41
|
"typescript": "^5.8.3"
|
|
26
42
|
},
|
|
27
43
|
"peerDependencies": {
|
|
28
|
-
"react": "^19.0.0"
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"@radix-ui/react-slot": "^1.1.2"
|
|
29
46
|
},
|
|
30
47
|
"devDependencies": {
|
|
31
48
|
"@types/react": "^19.0.10"
|