@@ -7,7 +7,9 @@ import { icons } from "./icons.ts";
77import "./modal-dialog.ts" ;
88
99export type ImageLightboxItem = {
10+ kind ?: "image" | "video" ;
1011 src : string ;
12+ originalSrc ?: string ;
1113 title : string ;
1214 release ?: ( ) => void ;
1315} ;
@@ -33,11 +35,13 @@ function dataUrlMimeType(source: string): string | undefined {
3335}
3436
3537class OpenClawImageLightbox extends OpenClawLitElement {
38+ @property ( ) mediaKind : "image" | "video" = "image" ;
3639 @property ( ) src = "" ;
40+ @property ( ) originalSrc = "" ;
3741 @property ( { attribute : false } ) imageTitle = "" ;
3842 @query ( ".stage" ) private stage ?: HTMLDivElement ;
3943 @query ( ".image" ) private image ?: HTMLImageElement ;
40- @queryAll ( ".action" ) private actions ! : NodeListOf < HTMLElement > ;
44+ @queryAll ( ".action, video[controls] " ) private focusables ! : NodeListOf < HTMLElement > ;
4145 @state ( ) private openOriginalUrl = "" ;
4246 @state ( ) private scale = 1 ;
4347 @state ( ) private imageReady = false ;
@@ -182,19 +186,28 @@ class OpenClawImageLightbox extends OpenClawLitElement {
182186 overflow: hidden;
183187 }
184188
185- .image {
189+ .image,
190+ .video {
186191 display: block;
187192 min-width: 0;
188193 min-height: 0;
189194 max-width: 100%;
190195 max-height: 100%;
191- width: auto;
192196 height: auto;
193197 object-fit: contain;
198+ }
199+
200+ .image {
201+ width: auto;
194202 cursor: zoom-in;
195203 -webkit-user-drag: none;
196204 }
197205
206+ .video {
207+ width: min(1280px, 100%);
208+ background: var(--media-bg);
209+ }
210+
198211 .image.zoomed {
199212 cursor: grab;
200213 }
@@ -306,21 +319,28 @@ class OpenClawImageLightbox extends OpenClawLitElement {
306319 }
307320
308321 protected override updated ( changed : PropertyValues < this> ) {
309- if ( changed . has ( "src" ) ) {
322+ if ( changed . has ( "src" ) || changed . has ( "originalSrc" ) || changed . has ( "mediaKind" ) ) {
310323 this . destroyPanzoom ( ) ;
311324 this . scale = 1 ;
312- this . imageReady = false ;
313325 void this . resolveOriginalUrl ( ) ;
314326 }
315327 }
316328
317329 override render ( ) {
318330 const title = this . imageTitle . trim ( ) || t ( "chat.imageLightbox.untitled" ) ;
331+ const dialogLabel =
332+ this . mediaKind === "video"
333+ ? t ( "chat.mediaPlayer.videoPreview" , { title } )
334+ : t ( "chat.imageLightbox.label" , { title } ) ;
335+ const closeLabel =
336+ this . mediaKind === "video"
337+ ? t ( "chat.mediaPlayer.closeVideoPreview" )
338+ : t ( "chat.imageLightbox.close" ) ;
319339 const canZoom = this . imageReady && this . panzoom !== undefined ;
320340 return html `
321341 < openclaw-modal-dialog
322342 class ="mobile-edge-to-edge viewport-edge-to-edge "
323- label =${ t ( "chat.imageLightbox.label" , { title } ) }
343+ label =${ dialogLabel }
324344 @modal-cancel =${ this . emitClose }
325345 @keydown=${ this . handleKeydown }
326346 >
@@ -350,7 +370,7 @@ class OpenClawImageLightbox extends OpenClawLitElement {
350370 class ="action close "
351371 type ="button "
352372 autofocus
353- aria-label =${ t ( "chat.imageLightbox.close" ) }
373+ aria-label =${ closeLabel }
354374 @click =${ this . emitClose }
355375 >
356376 ${ icons . x }
@@ -364,44 +384,56 @@ class OpenClawImageLightbox extends OpenClawLitElement {
364384 @pointercancel=${ this . resetBackdropPointer }
365385 @dblclick=${ this . handleDoubleClick }
366386 >
367- < img
368- class =${ this . scale > 1 ? "image zoomed" : "image" }
369- src =${ this . src }
370- alt=${ title }
371- @load=${ this . handleImageLoad }
372- @error=${ this . handleImageError }
373- @dragstart=${ ( event : DragEvent ) => event . preventDefault ( ) }
374- />
375- </ div >
376- < div class ="zoom-controls ">
377- < button
378- class ="action zoom-control "
379- type ="button "
380- aria-label =${ t ( "chat.imageLightbox.zoomOut" ) }
381- ?disabled =${ ! canZoom || this . scale <= 1 }
382- @click=${ this . zoomOut }
383- >
384- −
385- </ button >
386- < button
387- class ="action zoom-control zoom-level "
388- type ="button "
389- aria-label =${ t ( "chat.imageLightbox.resetZoom" ) }
390- ?disabled =${ ! canZoom || this . scale === 1 }
391- @click=${ this . resetZoom }
392- >
393- ${ Math . round ( this . scale * 100 ) } %
394- </ button >
395- < button
396- class ="action zoom-control "
397- type ="button "
398- aria-label =${ t ( "chat.imageLightbox.zoomIn" ) }
399- ?disabled =${ ! canZoom || this . scale >= MAX_SCALE }
400- @click=${ this . zoomIn }
401- >
402- +
403- </ button >
387+ ${ this . mediaKind === "video"
388+ ? html `< video
389+ class ="video "
390+ src =${ this . src }
391+ aria-label =${ title }
392+ controls
393+ autoplay
394+ playsinline
395+ tabindex="0"
396+ > </ video > `
397+ : html `< img
398+ class =${ this . scale > 1 ? "image zoomed" : "image" }
399+ src =${ this . src }
400+ alt=${ title }
401+ @load=${ this . handleImageLoad }
402+ @error=${ this . handleImageError }
403+ @dragstart=${ ( event : DragEvent ) => event . preventDefault ( ) }
404+ /> ` }
404405 </ div >
406+ ${ this . mediaKind === "image"
407+ ? html `< div class ="zoom-controls ">
408+ < button
409+ class ="action zoom-control "
410+ type ="button "
411+ aria-label =${ t ( "chat.imageLightbox.zoomOut" ) }
412+ ?disabled =${ ! canZoom || this . scale <= 1 }
413+ @click=${ this . zoomOut }
414+ >
415+ −
416+ </ button >
417+ < button
418+ class ="action zoom-control zoom-level "
419+ type ="button "
420+ aria-label =${ t ( "chat.imageLightbox.resetZoom" ) }
421+ ?disabled =${ ! canZoom || this . scale === 1 }
422+ @click=${ this . resetZoom }
423+ >
424+ ${ Math . round ( this . scale * 100 ) } %
425+ </ button >
426+ < button
427+ class ="action zoom-control "
428+ type ="button "
429+ aria-label =${ t ( "chat.imageLightbox.zoomIn" ) }
430+ ?disabled =${ ! canZoom || this . scale >= MAX_SCALE }
431+ @click=${ this . zoomIn }
432+ >
433+ +
434+ </ button >
435+ </ div > `
436+ : nothing }
405437 </ section >
406438 </ openclaw-modal-dialog >
407439 ` ;
@@ -550,7 +582,7 @@ class OpenClawImageLightbox extends OpenClawLitElement {
550582 private async resolveOriginalUrl ( ) {
551583 const request = ++ this . originalUrlRequest ;
552584 this . revokeOriginalBlobUrl ( ) ;
553- const source = this . src . trim ( ) ;
585+ const source = ( this . originalSrc || this . src ) . trim ( ) ;
554586 if ( ! source ) {
555587 this . openOriginalUrl = "" ;
556588 return ;
@@ -609,7 +641,7 @@ class OpenClawImageLightbox extends OpenClawLitElement {
609641 if ( event . key !== "Tab" ) {
610642 return ;
611643 }
612- const actions = [ ...this . actions ] . filter (
644+ const actions = [ ...this . focusables ] . filter (
613645 ( action ) => ! ( action instanceof HTMLButtonElement && action . disabled ) ,
614646 ) ;
615647 const first = actions [ 0 ] ;
0 commit comments