@zuude-ui/video 0.1.35 → 0.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
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,KAAK,MAAOF,EAAe,KAAQ,EAAE,EAC/CG,EAAUH,EAAe,GACzBI,EAAe,KAAK,MAAOb,EAAO,EAAK,GAAI,EAE3Cc,EAAM,CAACC,EAAaC,EAAe,IACvCX,EAAmBU,EAAI,SAAS,EAAE,SAASC,EAAM,GAAG,EAAID,EAAI,SAAS,EAEvE,OAAQZ,EAAQ,CACd,IAAK,UACH,MAAO,GAAGW,EAAIJ,CAAK,CAAC,IAAII,EAAIH,CAAO,CAAC,IAAIG,EAAIF,CAAO,CAAC,GACtD,IAAK,QACH,OAAOR,GAAaM,EAAQ,EACxB,GAAGI,EAAIJ,CAAK,CAAC,IAAII,EAAIH,CAAO,CAAC,IAAIG,EAAIF,CAAO,CAAC,GAC7C,GAAGE,EAAIH,CAAO,CAAC,IAAIG,EAAIF,CAAO,CAAC,GACr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AAMoB,EAAY,KAAK,IAAI,EAAGD,EAAQD,CAAO,EAC7C,OAAO7B,EAAW+B,EAAWpB,CAAM,CACrC,CAKA,SAAST,EACP2B,EACAC,EACAnB,EAAqB,QACb,CACR,IAAMqB,EAAaF,EAAQ,EAAI,KAAK,MAAOD,EAAUC,EAAS,GAAG,EAAI,EACrE,MAAO,GAAG9B,EAAW6B,EAASlB,CAAM,CAAC,KAAKqB,CAAU,IACtD,CAKA,SAAS7B,EAAgB8B,EAAkBC,EAAmB,GAAc,CAC1E,OAAO,MAAM,KACX,CAAE,OAAQA,EAAW,CAAE,EACvB,CAACC,EAAGC,IAAOH,EAAWC,EAAYE,CACpC,CACF,CAKA,SAASnC,EAA2BO,EAAsB,CACxD,IAAMS,EAAe,KAAK,MAAMT,CAAI,EAC9BU,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":["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,EAA0C,QAClC,CACR,IAAMC,EAAO,OAAOD,GAAY,SAAW,CAAE,OAAQA,CAAQ,EAAIA,EAC3D,CACJ,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C,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,26 +3,31 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.35",
6
+ "version": "0.1.42",
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,14 +37,14 @@
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
- "@types/react": "^19.0.10"
48
+ "@types/react": "^19.1.12"
44
49
  }
45
50
  }
@@ -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,S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ideoContext","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,IAAI,EAGtD,OAAAD,EAAU,IAAM,CACdO,GAAA,MAAAA,EAAUI,EACZ,EAAG,CAACA,CAAK,CAAC,EAGRT,EAACC,EAAa,SAAb,CACC,MAAO,CACL,SAAAM,EACA,YAAAC,EACA,OAAQ,CAAE,YAAa,GAAM,GAAGJ,CAAO,EACvC,MAAAK,EACA,SAAAC,CACF,EAEA,SAAAV,EAAC,OAAK,GAAGM,EAAQ,SAAAH,EAAS,EAC5B,CAEJ,EAEaQ,EAAW,IAAM,CAC5B,IAAMC,EAAUf,EAAWI,CAAY,EACvC,GAAI,CAACW,EACH,MAAM,IAAI,MAAM,8CAA8C,EAEhE,OAAOA,CACT,ECnEA,OAAgB,cAAAC,EAAuB,aAAAC,EAAW,UAAAC,MAAc,QA6C1D,mBAAAC,EACE,OAAAC,EADF,QAAAC,MAAA,oBAlCC,IAAMC,EAAQC,EACnB,CAAC,CAAE,IAAAC,EAAK,SAAAC,EAAU,aAAAC,EAAc,GAAGC,CAAM,EAAGC,IAAQ,CAClD,GAAM,CAAE,SAAAC,EAAU,YAAAC,EAAa,OAAAC,EAAQ,SAAAC,EAAU,MAAAC,CAAM,EAAIC,EAAS,EAE9DC,EAAWC,EAAyB,IAAI,EAE9CC,EAAU,IAAM,CACd,IAAMC,EAAQH,EAAS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EAAS,GAAGC,CAAM,IAAa,CACnE,IAAMC,EAAUF,EAAUG,EAAO,SAC3B,CAAE,SAAAC,CAAS,EAAIC,EAAS,EAQ9B,OACET,EAACM,EAAA,CAAS,GAAGD,EAAO,QAPF,IAAM,CA/B5B,IAAAK,EAgCQF,GAAA,MAAAA,EAAU,WACZE,EAAAF,EAAS,UAAT,MAAAE,EAAkB,QAEtB,EAIK,SAAAP,EACH,CAEJ,CAAC,EAEKU,EAAU,IACPb,EAAC,OAAI,mBAAO,EC7CrB,OAAoB,aAAAc,EAAW,YAAAC,MAAgB,QAE/C,IAAMC,GAAiBC,GAAiD,CACtE,GAAM,CAACC,EAAWC,CAAY,EAAIJ,EAAS,EAAK,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"]}