@@ -7,6 +7,7 @@ import { Filename } from "./filename";
77import { Image } from "./image" ;
88import brokenImage from "~/shared/images/broken-image-placeholder.svg" ;
99import { theme } from "@webstudio-is/design-system" ;
10+ import { isVideoFormat } from "../assets/asset-utils" ;
1011
1112const StyledWebstudioImage = styled ( Image , {
1213 position : "absolute" ,
@@ -34,6 +35,32 @@ const StyledWebstudioImage = styled(Image, {
3435 } ,
3536} ) ;
3637
38+ const StyledWebstudioVideo = styled ( "video" , {
39+ position : "absolute" ,
40+ width : "100%" ,
41+ height : "100%" ,
42+ objectFit : "contain" ,
43+
44+ // This is shown only if an image was not loaded and broken
45+ // From the spec:
46+ // - The pseudo-elements generated by ::before and ::after are contained by the element's formatting box,
47+ // and thus don't apply to "replaced" elements such as <img>, or to <br> elements
48+ // Not in spec but supported by all browsers:
49+ // - broken image is not a "replaced" element so this style is applied
50+ "&::after" : {
51+ content : "' '" ,
52+ position : "absolute" ,
53+ width : "100%" ,
54+ height : "100%" ,
55+ left : 0 ,
56+ top : 0 ,
57+ backgroundSize : "contain" ,
58+ backgroundRepeat : "no-repeat" ,
59+ backgroundPosition : "center" ,
60+ backgroundImage : `url(${ brokenImage } )` ,
61+ } ,
62+ } ) ;
63+
3764const ThumbnailContainer = styled ( Box , {
3865 position : "relative" ,
3966 display : "flex" ,
@@ -120,18 +147,29 @@ export const ImageThumbnail = ({
120147 onChange ?.( assetContainer ) ;
121148 } }
122149 >
123- < StyledWebstudioImage
124- assetId = { assetContainer . asset . id }
125- name = { assetContainer . asset . name }
126- objectURL = {
127- assetContainer . status === "uploading"
128- ? assetContainer . objectURL
129- : undefined
130- }
131- alt = { description ?? name }
132- // width={64} used for Image optimizations it should be approximately equal to the width of the picture on the screen in px
133- width = { 64 }
134- />
150+ { isVideoFormat ( assetContainer . asset . format ) ? (
151+ < StyledWebstudioVideo
152+ width = { 64 }
153+ src = {
154+ assetContainer . status === "uploading"
155+ ? assetContainer . objectURL
156+ : `/cgi/image/${ assetContainer . asset . name } ?format=raw`
157+ }
158+ />
159+ ) : (
160+ < StyledWebstudioImage
161+ assetId = { assetContainer . asset . id }
162+ name = { assetContainer . asset . name }
163+ objectURL = {
164+ assetContainer . status === "uploading"
165+ ? assetContainer . objectURL
166+ : undefined
167+ }
168+ alt = { description ?? name }
169+ // width={64} used for Image optimizations it should be approximately equal to the width of the picture on the screen in px
170+ width = { 64 }
171+ />
172+ ) }
135173 </ Thumbnail >
136174 < Box
137175 css = { {
0 commit comments