seedance-video-sdk
Version:
Seedance AI Video Generation SDK - Create professional videos from text and images using ByteDance's advanced AI technology
168 lines (162 loc) • 9.64 kB
JavaScript
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var react = require('react');
/**
* Seedance Video Player Component
*
* A customizable video player optimized for AI-generated videos
* with built-in loading states and error handling.
*/
const VideoPlayer = ({ src, poster, controls = true, autoplay = false, loop = false, muted = false, className = '', onLoadStart, onLoadedData, onError, }) => {
const videoRef = react.useRef(null);
const [isLoading, setIsLoading] = react.useState(true);
const [hasError, setHasError] = react.useState(false);
const [errorMessage, setErrorMessage] = react.useState('');
react.useEffect(() => {
const video = videoRef.current;
if (!video)
return;
const handleLoadStart = () => {
setIsLoading(true);
setHasError(false);
onLoadStart?.();
};
const handleLoadedData = () => {
setIsLoading(false);
onLoadedData?.();
};
const handleError = (event) => {
setIsLoading(false);
setHasError(true);
const error = new Error('Video failed to load');
setErrorMessage(error.message);
onError?.(error);
};
video.addEventListener('loadstart', handleLoadStart);
video.addEventListener('loadeddata', handleLoadedData);
video.addEventListener('error', handleError);
return () => {
video.removeEventListener('loadstart', handleLoadStart);
video.removeEventListener('loadeddata', handleLoadedData);
video.removeEventListener('error', handleError);
};
}, [onLoadStart, onLoadedData, onError]);
const baseStyles = `
relative w-full h-auto rounded-lg overflow-hidden bg-gray-900
`;
const videoStyles = `
w-full h-full object-cover
`;
const loadingStyles = `
absolute inset-0 flex items-center justify-center bg-gray-900 text-white
`;
const errorStyles = `
absolute inset-0 flex flex-col items-center justify-center bg-gray-900 text-white p-4 text-center
`;
return (jsxRuntime.jsxs("div", { className: `${baseStyles} ${className}`, children: [jsxRuntime.jsx("video", { ref: videoRef, src: src, poster: poster, controls: controls, autoPlay: autoplay, loop: loop, muted: muted, className: videoStyles, playsInline: true }), isLoading && (jsxRuntime.jsxs("div", { className: loadingStyles, children: [jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-white" }), jsxRuntime.jsx("p", { className: "mt-2 text-sm", children: "Loading video..." })] })), hasError && (jsxRuntime.jsxs("div", { className: errorStyles, children: [jsxRuntime.jsx("svg", { className: "w-12 h-12 text-red-400 mb-2", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }), jsxRuntime.jsx("p", { className: "text-sm font-medium", children: "Failed to load video" }), jsxRuntime.jsx("p", { className: "text-xs text-gray-400 mt-1", children: errorMessage })] }))] }));
};
/**
* Utility functions for Seedance Video SDK
*/
/**
* Convert video resolution to dimensions
*/
/**
* Format duration in human readable format
*/
function formatDuration(seconds) {
if (seconds < 60) {
return `${seconds}s`;
}
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
if (remainingSeconds === 0) {
return `${minutes}m`;
}
return `${minutes}m ${remainingSeconds}s`;
}
/**
* Get status color for UI components
*/
function getStatusColor(status) {
switch (status) {
case 'pending':
return '#f59e0b'; // amber
case 'processing':
return '#3b82f6'; // blue
case 'completed':
return '#10b981'; // green
case 'failed':
return '#ef4444'; // red
case 'cancelled':
return '#6b7280'; // gray
default:
return '#6b7280';
}
}
/**
* Get status display text
*/
function getStatusText(status) {
switch (status) {
case 'pending':
return 'Pending';
case 'processing':
return 'Processing';
case 'completed':
return 'Completed';
case 'failed':
return 'Failed';
case 'cancelled':
return 'Cancelled';
default:
return 'Unknown';
}
}
/**
* Progress Indicator Component
*
* Displays the progress and status of video generation tasks
* with visual indicators and estimated time remaining.
*/
const ProgressIndicator = ({ progress, status, estimatedTime, className = '', showPercentage = true, showStatus = true, }) => {
const statusColor = getStatusColor(status);
const statusText = getStatusText(status);
const getProgressBarColor = (status) => {
switch (status) {
case 'processing':
return 'bg-blue-500';
case 'completed':
return 'bg-green-500';
case 'failed':
return 'bg-red-500';
case 'cancelled':
return 'bg-gray-500';
default:
return 'bg-yellow-500';
}
};
const getIcon = (status) => {
switch (status) {
case 'pending':
return (jsxRuntime.jsx("svg", { className: "w-4 h-4 animate-pulse", fill: "currentColor", viewBox: "0 0 20 20", children: jsxRuntime.jsx("path", { fillRule: "evenodd", d: "M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z", clipRule: "evenodd" }) }));
case 'processing':
return (jsxRuntime.jsx("svg", { className: "w-4 h-4 animate-spin", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" }) }));
case 'completed':
return (jsxRuntime.jsx("svg", { className: "w-4 h-4", fill: "currentColor", viewBox: "0 0 20 20", children: jsxRuntime.jsx("path", { fillRule: "evenodd", d: "M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z", clipRule: "evenodd" }) }));
case 'failed':
return (jsxRuntime.jsx("svg", { className: "w-4 h-4", fill: "currentColor", viewBox: "0 0 20 20", children: jsxRuntime.jsx("path", { fillRule: "evenodd", d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z", clipRule: "evenodd" }) }));
case 'cancelled':
return (jsxRuntime.jsx("svg", { className: "w-4 h-4", fill: "currentColor", viewBox: "0 0 20 20", children: jsxRuntime.jsx("path", { fillRule: "evenodd", d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z", clipRule: "evenodd" }) }));
default:
return null;
}
};
const baseStyles = `
w-full p-4 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700
`;
return (jsxRuntime.jsxs("div", { className: `${baseStyles} ${className}`, children: [jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-3", children: [jsxRuntime.jsxs("div", { className: "flex items-center space-x-2", children: [jsxRuntime.jsx("div", { style: { color: statusColor }, children: getIcon(status) }), showStatus && (jsxRuntime.jsx("span", { className: "text-sm font-medium text-gray-900 dark:text-white", children: statusText }))] }), showPercentage && (jsxRuntime.jsxs("span", { className: "text-sm text-gray-500 dark:text-gray-400", children: [Math.round(progress), "%"] }))] }), jsxRuntime.jsx("div", { className: "w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2 mb-3", children: jsxRuntime.jsx("div", { className: `h-2 rounded-full transition-all duration-300 ease-out ${getProgressBarColor(status)}`, style: { width: `${Math.min(100, Math.max(0, progress))}%` } }) }), jsxRuntime.jsxs("div", { className: "flex items-center justify-between text-xs text-gray-500 dark:text-gray-400", children: [jsxRuntime.jsxs("div", { children: [status === 'processing' && estimatedTime && (jsxRuntime.jsxs("span", { children: ["Estimated time: ", formatDuration(estimatedTime)] })), status === 'completed' && (jsxRuntime.jsx("span", { children: "Video generation completed" })), status === 'failed' && (jsxRuntime.jsx("span", { children: "Generation failed" })), status === 'pending' && (jsxRuntime.jsx("span", { children: "Waiting in queue..." })), status === 'cancelled' && (jsxRuntime.jsx("span", { children: "Generation cancelled" }))] }), status === 'processing' && (jsxRuntime.jsxs("div", { className: "flex items-center space-x-1", children: [jsxRuntime.jsx("div", { className: "w-1 h-1 bg-blue-500 rounded-full animate-pulse" }), jsxRuntime.jsx("div", { className: "w-1 h-1 bg-blue-500 rounded-full animate-pulse", style: { animationDelay: '0.2s' } }), jsxRuntime.jsx("div", { className: "w-1 h-1 bg-blue-500 rounded-full animate-pulse", style: { animationDelay: '0.4s' } })] }))] })] }));
};
exports.ProgressIndicator = ProgressIndicator;
exports.VideoPlayer = VideoPlayer;
//# sourceMappingURL=react.js.map