@@ -13,16 +13,16 @@ export class DeckdeckgoLazyImg {
1313
1414 @Event ( ) lazyImgDidLoad : EventEmitter ;
1515
16- @Prop ( { reflectToAttr : true } )
16+ @Prop ( { reflect : true } )
1717 imgSrc : string ;
1818
19- @Prop ( { reflectToAttr : true } )
19+ @Prop ( { reflect : true } )
2020 imgSrcSet : string ;
2121
22- @Prop ( { reflectToAttr : true } )
22+ @Prop ( { reflect : true } )
2323 imgAlt : string ;
2424
25- @Prop ( { reflectToAttr : true } )
25+ @Prop ( { reflect : true } )
2626 imgSizes : string ;
2727
2828 @Prop ( )
@@ -34,12 +34,15 @@ export class DeckdeckgoLazyImg {
3434 @Prop ( )
3535 imgErrorSrc : string ;
3636
37- @Prop ( { reflectToAttr : true } )
37+ @Prop ( { reflect : true } )
3838 svgSrc : string ;
3939
40- @Prop ( { reflectToAttr : true } )
40+ @Prop ( { reflect : true } )
4141 ariaLabel : string ;
4242
43+ @Prop ( )
44+ intrinsicsize : string ;
45+
4346 @State ( )
4447 private svgContent : string ;
4548
@@ -60,8 +63,11 @@ export class DeckdeckgoLazyImg {
6063 }
6164
6265 private async init ( ) {
63- if ( window && 'IntersectionObserver' in window ) {
64- await this . deferLoad ( ) ;
66+ if ( 'loading' in HTMLImageElement . prototype ) {
67+ // In this case, loadImmediately apply the attributes but the platform will takes care of lazy loading the images
68+ await this . loadImmediately ( ) ;
69+ } else if ( window && 'IntersectionObserver' in window ) {
70+ await this . deferIntersectionObserverLoad ( ) ;
6571 } else {
6672 await this . loadImmediately ( ) ;
6773 }
@@ -71,7 +77,7 @@ export class DeckdeckgoLazyImg {
7177 return this . load ( ) ;
7278 }
7379
74- private deferLoad ( ) : Promise < void > {
80+ private deferIntersectionObserverLoad ( ) : Promise < void > {
7581 return new Promise < void > ( ( resolve ) => {
7682 this . observer = new IntersectionObserver ( this . onIntersection , {
7783 rootMargin : this . observerRootMargin ,
@@ -189,9 +195,14 @@ export class DeckdeckgoLazyImg {
189195 </ Host >
190196 } else {
191197 return < Host >
192- < img alt = { this . imgLoaded ? ( this . imgAlt ? this . imgAlt : this . imgSrc ) : '' } sizes = { this . imgSizes ? this . imgSizes : undefined }
193- onLoad = { ( ) => this . imgLoaded = true } onError = { ( ) => this . loadError ( ) } />
198+ { this . renderImage ( ) }
194199 </ Host > ;
195200 }
196201 }
202+
203+ private renderImage ( ) {
204+ // @ts -ignore
205+ return < img alt = { this . imgLoaded ? ( this . imgAlt ? this . imgAlt : this . imgSrc ) : '' } loading = "lazy" sizes = { this . imgSizes ? this . imgSizes : undefined } intrinsicsize = { this . intrinsicsize }
206+ onLoad = { ( ) => this . imgLoaded = true } onError = { ( ) => this . loadError ( ) } />
207+ }
197208}
0 commit comments