1- import React , { useMemo } from 'react' ;
1+ import React , { useCallback , useMemo , useState } from 'react' ;
22import { Internals } from 'remotion' ;
33import { WHITE_ALPHA_30 } from '../../helpers/colors' ;
4+ import { formatMediaDuration } from '../../helpers/format-media-duration' ;
5+ import { useImageMetadata } from '../../helpers/use-image-metadata' ;
6+ import { useMediaMetadata } from '../../helpers/use-media-metadata' ;
7+ import { ActionTooltip } from '../ActionTooltip' ;
48import { getTimelineAssetLinkInfo } from './timeline-asset-link' ;
59
610const lineStyle : React . CSSProperties = {
711 whiteSpace : 'nowrap' ,
812 overflow : 'hidden' ,
9- textOverflow : 'ellipsis' ,
13+ paddingRight : 10 ,
14+ maskImage : 'linear-gradient(to right, black calc(100% - 10px), transparent)' ,
15+ WebkitMaskImage :
16+ 'linear-gradient(to right, black calc(100% - 10px), transparent)' ,
1017 minWidth : 0 ,
1118 fontSize : 12 ,
19+ lineHeight : '14px' ,
1220 color : WHITE_ALPHA_30 ,
1321 display : 'inline-block' ,
1422} ;
@@ -24,7 +32,6 @@ const useAssetLink = (src: string) => {
2432 display : 'inline-block' ,
2533 overflow : 'hidden' ,
2634 whiteSpace : 'pre' ,
27- textOverflow : 'ellipsis' ,
2835 userSelect : 'none' ,
2936 WebkitUserSelect : 'none' ,
3037 } ) ,
@@ -39,18 +46,79 @@ const useAssetLink = (src: string) => {
3946
4047export const TimelineMediaInfo : React . FC < {
4148 readonly src : string ;
42- } > = ( { src} ) => {
49+ readonly isImage : boolean ;
50+ } > = ( { src, isImage} ) => {
4351 const fileName = useMemo ( ( ) => Internals . getAssetDisplayName ( src ) , [ src ] ) ;
4452
4553 const { linkInfo, fileNameStyle} = useAssetLink ( src ) ;
54+ // Share the asset inspector's caches, but only load metadata after hovering.
55+ const [ requestedSrc , setRequestedSrc ] = useState < string | null > ( null ) ;
56+ const metadataSrc = requestedSrc === src ? src : null ;
57+ const mediaMetadata = useMediaMetadata ( isImage ? null : metadataSrc ) ;
58+ const imageMetadata = useImageMetadata ( isImage ? metadataSrc : null ) ;
59+ const onPointerEnter = useCallback ( ( ) => setRequestedSrc ( src ) , [ src ] ) ;
60+ const visualDetails : string [ ] = [ ] ;
61+ const fileDetails : string [ ] = [ ] ;
62+ if ( mediaMetadata && Number . isFinite ( mediaMetadata . duration ) ) {
63+ fileDetails . push ( formatMediaDuration ( mediaMetadata . duration ) ) ;
64+ }
65+
66+ const dimensions = isImage ? imageMetadata : mediaMetadata ;
67+ if ( dimensions ?. width && dimensions . height ) {
68+ visualDetails . push ( `${ dimensions . width } × ${ dimensions . height } ` ) ;
69+ }
70+
71+ if ( mediaMetadata ?. fps && Number . isFinite ( mediaMetadata . fps ) ) {
72+ visualDetails . push ( `${ Number ( mediaMetadata . fps . toFixed ( 2 ) ) } fps` ) ;
73+ }
74+
75+ const format = isImage ? imageMetadata ?. format : mediaMetadata ?. format ;
76+ if ( format ) {
77+ ( isImage ? visualDetails : fileDetails ) . push ( format ) ;
78+ }
79+
80+ const metadataLines = [ visualDetails , fileDetails ]
81+ . filter ( ( details ) => details . length > 0 )
82+ . map ( ( details ) => details . join ( ' · ' ) ) ;
83+
84+ const source =
85+ linkInfo ?. kind === 'local'
86+ ? linkInfo . assetPath
87+ : linkInfo ?. kind === 'remote'
88+ ? linkInfo . href
89+ : null ;
4690
4791 return (
48- < div
49- role = "group"
50- style = { fileNameStyle }
51- aria-label = { linkInfo ? linkInfo . title : fileName }
92+ < ActionTooltip
93+ label = {
94+ < span
95+ style = { {
96+ display : 'inline-block' ,
97+ font : 'inherit' ,
98+ color : 'inherit' ,
99+ maxWidth : 360 ,
100+ } }
101+ >
102+ < strong style = { { font : 'inherit' , fontWeight : 600 , color : 'inherit' } } >
103+ { fileName }
104+ </ strong >
105+ { source !== null && source !== fileName ? `\n${ source } ` : null }
106+ { metadataLines . length > 0 ? `\n${ metadataLines . join ( '\n' ) } ` : null }
107+ </ span >
108+ }
109+ shortcut = { null }
110+ delay = { 800 }
111+ dismissOnClick
112+ triggerStyle = { { minWidth : 0 , maxWidth : '100%' } }
52113 >
53- { fileName }
54- </ div >
114+ < div
115+ role = "group"
116+ style = { fileNameStyle }
117+ aria-label = { linkInfo ? linkInfo . title : fileName }
118+ onPointerEnter = { onPointerEnter }
119+ >
120+ { fileName }
121+ </ div >
122+ </ ActionTooltip >
55123 ) ;
56124} ;
0 commit comments