66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { Component , Input , ViewEncapsulation } from '@angular/core' ;
9+ import { Component , ViewEncapsulation , computed , input } from '@angular/core' ;
1010
1111/** Quality of the placeholder image. */
1212export type PlaceholderImageQuality = 'high' | 'standard' | 'low' ;
@@ -15,7 +15,7 @@ export type PlaceholderImageQuality = 'high' | 'standard' | 'low';
1515 selector : 'youtube-player-placeholder' ,
1616 encapsulation : ViewEncapsulation . None ,
1717 template : `
18- <button type="button" class="youtube-player-placeholder-button" [attr.aria-label]="buttonLabel">
18+ <button type="button" class="youtube-player-placeholder-button" [attr.aria-label]="buttonLabel() ">
1919 <svg
2020 height="100%"
2121 version="1.1"
@@ -30,43 +30,45 @@ export type PlaceholderImageQuality = 'high' | 'standard' | 'low';
3030 styleUrl : 'youtube-player-placeholder.css' ,
3131 host : {
3232 'class' : 'youtube-player-placeholder' ,
33- '[class.youtube-player-placeholder-loading]' : 'isLoading' ,
34- '[style.background-image]' : '_getBackgroundImage ()' ,
35- '[style.width.px]' : 'width' ,
36- '[style.height.px]' : 'height' ,
33+ '[class.youtube-player-placeholder-loading]' : 'isLoading() ' ,
34+ '[style.background-image]' : '_backgroundImage ()' ,
35+ '[style.width.px]' : 'width() ' ,
36+ '[style.height.px]' : 'height() ' ,
3737 } ,
3838} )
3939export class YouTubePlayerPlaceholder {
4040 /** ID of the video for which to show the placeholder. */
41- @ Input ( ) videoId ! : string ;
41+ readonly videoId = input . required < string > ( ) ;
4242
4343 /** Width of the video for which to show the placeholder. */
44- @ Input ( ) width ! : number ;
44+ readonly width = input . required < number > ( ) ;
4545
4646 /** Height of the video for which to show the placeholder. */
47- @ Input ( ) height ! : number ;
47+ readonly height = input . required < number > ( ) ;
4848
4949 /** Whether the video is currently being loaded. */
50- @ Input ( ) isLoading : boolean = false ;
50+ readonly isLoading = input . required < boolean > ( ) ;
5151
5252 /** Accessible label for the play button. */
53- @ Input ( ) buttonLabel ! : string ;
53+ readonly buttonLabel = input . required < string > ( ) ;
5454
5555 /** Quality of the placeholder image. */
56- @ Input ( ) quality ! : PlaceholderImageQuality ;
56+ readonly quality = input . required < PlaceholderImageQuality > ( ) ;
5757
5858 /** Gets the background image showing the placeholder. */
59- protected _getBackgroundImage ( ) : string | undefined {
59+ protected _backgroundImage = computed ( ( ) => {
60+ const quality = this . quality ( ) ;
61+ const videoId = this . videoId ( ) ;
6062 let url : string ;
6163
62- if ( this . quality === 'low' ) {
63- url = `https://i.ytimg.com/vi/${ this . videoId } /hqdefault.jpg` ;
64- } else if ( this . quality === 'high' ) {
65- url = `https://i.ytimg.com/vi/${ this . videoId } /maxresdefault.jpg` ;
64+ if ( quality === 'low' ) {
65+ url = `https://i.ytimg.com/vi/${ videoId } /hqdefault.jpg` ;
66+ } else if ( quality === 'high' ) {
67+ url = `https://i.ytimg.com/vi/${ videoId } /maxresdefault.jpg` ;
6668 } else {
67- url = `https://i.ytimg.com/vi_webp/${ this . videoId } /sddefault.webp` ;
69+ url = `https://i.ytimg.com/vi_webp/${ videoId } /sddefault.webp` ;
6870 }
6971
7072 return `url(${ url } )` ;
71- }
73+ } ) ;
7274}
0 commit comments