1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
define(["exports","./../lazyloader/lazyloader-intersectionobserver.js","./../skinmanager.js"],function(_exports,_lazyloaderIntersectionobserver,_skinmanager){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var supportsNativeLazyLoading="loading"in HTMLImageElement.prototype,imageLoader=(supportsNativeLazyLoading||require(["css!modules/imageloader/imageloader.css"]),{});function fillImage(elem,source){!source&&supportsNativeLazyLoading||("IMG"===elem.tagName?(elem.setAttribute("src",source||elem.getAttribute("data-src")),elem.removeAttribute("data-src")):(source&&(elem.style.backgroundImage="url('"+source+"')"),elem.classList.remove("lazy")))}function compareNumbers(a,b){return a-b}function getPrimaryImageAspectRatio(items,options){for(var values=[],i=0,length=items.length;i<length;i++){var item=items[i],item=(options&&options.showCurrentProgramImage?item.CurrentProgram||item:item.ProgramInfo||item).PrimaryImageAspectRatio||0;item&&(values[values.length]=item)}if(!values.length)return null;values.sort(compareNumbers);var half=Math.floor(values.length/2),half=values.length%2?values[half]:(values[half-1]+values[half])/2;return Math.abs(2/3-half)<=.1666667?2/3:Math.abs(16/9-half)<=.222222?16/9:Math.abs(4/3-half)<=.2?4/3:Math.abs(1-half)<=.1666667?1:half}function getShapeFromAspect(primaryImageAspectRatio){return primaryImageAspectRatio?3<=primaryImageAspectRatio?"banner":1.4<=primaryImageAspectRatio?"backdrop":1.2<primaryImageAspectRatio?"fourThree":.71<primaryImageAspectRatio?"square":"portrait":null}imageLoader.fillImages=function(elems){if(!supportsNativeLazyLoading)for(var i=0,length=elems.length;i<length;i++)fillImage(elems[0])},imageLoader.lazyImage=fillImage,imageLoader.lazyChildren=function(elem){supportsNativeLazyLoading||_lazyloaderIntersectionobserver.default.lazyChildren(elem,fillImage)},imageLoader.getPrimaryImageAspectRatio=getPrimaryImageAspectRatio,imageLoader.getShape=function(items,options){return getShapeFromAspect(getPrimaryImageAspectRatio(items,options))||options.defaultShape||function(items){if(items=items[0])switch(items.Type){case"Movie":case"SeriesTimer":case"Timer":return"portrait";case"Episode":case"Program":case"Video":return"backdrop"}return"square"}(items)},imageLoader.getAspectFromShape=function(shape,options){if(shape){if(shape.includes("ortrait"))return{aspect:2/3,aspectCss:"2/3"};if(shape.includes("ackdrop"))return{aspect:16/9,aspectCss:"16/9"};if(shape.includes("quare"))return{aspect:1,aspectCss:"1"};if(shape.includes("ourThree"))return{aspect:4/3,aspectCss:"4/3"};if(shape.includes("anner"))return options.sideFooter?{aspect:1,aspectCss:"1"}:{aspect:1e3/185,aspectCss:"1000/185"}}return{}},imageLoader.getShapeFromAspect=getShapeFromAspect,imageLoader.getImageUrl=function(item,apiClient,options,shape){var imgUrl,height,primaryImageAspectRatio,forceName,imageAspect,imageTags,uiAspect,keepAnimation,preferThumb,width=options.width,adjustForPixelRatio=options.adjustForPixelRatio;return item.ImageUrl?(imgUrl=item.ImageUrl,options.addImageSizeToUrl&&options.width&&(imgUrl+="&maxWidth="+width),{imgUrl:imgUrl,aspect:item.PrimaryImageAspectRatio}):(height=null,primaryImageAspectRatio=item.PrimaryImageAspectRatio,forceName=!1,imageTags=item.ImageTags,uiAspect=options.uiAspect,keepAnimation=options.keepImageAnimation||null,(preferThumb=options.preferThumb)&&imageTags&&imageTags.Thumb?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Thumb",maxWidth:width,tag:imageTags.Thumb,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):(options.preferBanner||"banner"===shape)&&imageTags&&imageTags.Banner?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Banner",maxWidth:width,tag:imageTags.Banner,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=1e3/185):options.preferDisc&&imageTags&&imageTags.Disc?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Disc",maxWidth:width,tag:imageTags.Disc,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=1):options.preferLogo&&imageTags&&imageTags.Logo?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Logo",maxWidth:width,tag:imageTags.Logo,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):options.preferLogo&&item.ParentLogoImageTag&&item.ParentLogoItemId?(imgUrl=apiClient.getImageUrl(item.ParentLogoItemId,{type:"Logo",maxWidth:width,tag:item.ParentLogoImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):options.showChannelLogo&&item.ChannelPrimaryImageTag&&item.ChannelId?(imgUrl=apiClient.getImageUrl(item.ChannelId,{type:"Primary",maxWidth:width,tag:item.ChannelPrimaryImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):preferThumb&&item.ParentThumbItemId&&!1!==options.inheritThumb&&"Photo"!==item.MediaType?(imgUrl=apiClient.getImageUrl(item.ParentThumbItemId,{type:"Thumb",maxWidth:width,tag:item.ParentThumbImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):preferThumb&&item.BackdropImageTags&&item.BackdropImageTags.length?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Backdrop",maxWidth:width,tag:item.BackdropImageTags[0],adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),forceName=!0,imageAspect=16/9):preferThumb&&item.ParentBackdropImageTags&&item.ParentBackdropImageTags.length&&!1!==options.inheritThumb&&"Episode"===item.Type?(imgUrl=apiClient.getImageUrl(item.ParentBackdropItemId,{type:"Backdrop",maxWidth:width,tag:item.ParentBackdropImageTags[0],adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),preferThumb&&(forceName=!0),imageAspect=16/9):imageTags&&imageTags.Primary?(options.ignoreUIAspect||(height=width&&uiAspect?Math.round(width/uiAspect):null),imgUrl="TvChannel"===item.Type||"ChannelManagementInfo"===item.Type?apiClient.getLogoImageUrl(item,{maxHeight:height,maxWidth:width,blur:options.blur,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation},_skinmanager.default.getPreferredLogoImageTypes()):apiClient.getImageUrl(item.Id,{type:"Primary",maxHeight:height,maxWidth:width,tag:imageTags.Primary,blur:options.blur,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),preferThumb&&(forceName=!0),imageAspect=primaryImageAspectRatio):options.backdropAsSecondary&&item.ParentBackdropImageTags&&item.ParentBackdropImageTags.length?(imgUrl=apiClient.getImageUrl(item.ParentBackdropItemId,{type:"Backdrop",maxWidth:width,tag:item.ParentBackdropImageTags[0],adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),options.preferBackdrop&&(forceName=!0),imageAspect=16/9):item.ImageTag&&"Plugin"===item.Type?(imgUrl=apiClient.getUrl("Plugins/"+item.Id+"/Thumb",{maxHeight:height,maxWidth:width,tag:item.ImageTag,keepAnimation:keepAnimation}),imageAspect=16/9):item.ImageTag&&null!=item.ChapterIndex?(imgUrl=apiClient.getImageUrl(item.Id,{maxWidth:width,tag:item.ImageTag,type:"Chapter",index:item.ChapterIndex,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=primaryImageAspectRatio):item.PrimaryImageTag?(options.ignoreUIAspect||(height=width&&uiAspect?Math.round(width/uiAspect):null),"User"===item.Type?imgUrl=apiClient.getUserImageUrl(item.Id,{maxHeight:height,maxWidth:width,tag:item.PrimaryImageTag,type:"Primary",adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}):(imgUrl=apiClient.getImageUrl(item.PrimaryImageItemId||item.Id||item.ItemId,{type:"Primary",maxHeight:height,maxWidth:width,tag:item.PrimaryImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),preferThumb&&(forceName=!0)),imageAspect=primaryImageAspectRatio):item.AlbumId&&item.AlbumPrimaryImageTag?(options.ignoreUIAspect||(height=width&&uiAspect?Math.round(width/uiAspect):null),imgUrl=apiClient.getImageUrl(item.AlbumId,{type:"Primary",maxHeight:height,maxWidth:width,tag:item.AlbumPrimaryImageTag,blur:options.blur,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=1):item.ParentThumbItemId&&!1!==options.inheritThumb&&uiAspect&&1.4<=uiAspect&&"Photo"!==item.MediaType?(imgUrl=apiClient.getImageUrl(item.ParentThumbItemId,{type:"Thumb",maxWidth:width,tag:item.ParentThumbImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):item.ParentPrimaryImageTag?(imgUrl=apiClient.getImageUrl(item.ParentPrimaryImageItemId,{type:"Primary",maxWidth:width,tag:item.ParentPrimaryImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect="Episode"===item.Type?2/3:1):item.ChannelPrimaryImageTag&&item.ChannelId?(imgUrl=apiClient.getImageUrl(item.ChannelId,{type:"Primary",maxWidth:width,tag:item.ChannelPrimaryImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):item.SeriesPrimaryImageTag?(imgUrl=apiClient.getImageUrl(item.SeriesId,{type:"Primary",maxWidth:width,tag:item.SeriesPrimaryImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=2/3):"Season"===item.Type&&imageTags&&imageTags.Thumb?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Thumb",maxWidth:width,tag:imageTags.Thumb,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):item.BackdropImageTags&&item.BackdropImageTags.length?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Backdrop",maxWidth:width,tag:item.BackdropImageTags[0],adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):imageTags&&imageTags.Thumb?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Thumb",maxWidth:width,tag:imageTags.Thumb,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):item.ParentThumbItemId&&!1!==options.inheritThumb?(imgUrl=apiClient.getImageUrl(item.ParentThumbItemId,{type:"Thumb",maxWidth:width,tag:item.ParentThumbImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):item.ParentBackdropImageTags&&item.ParentBackdropImageTags.length&&!1!==options.inheritThumb?(imgUrl=apiClient.getImageUrl(item.ParentBackdropItemId,{type:"Backdrop",maxWidth:width,tag:item.ParentBackdropImageTags[0],adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):item.PrimaryImageItemId?(imgUrl=apiClient.getImageUrl(item.PrimaryImageItemId,{type:"Primary",maxHeight:height,maxWidth:width,adjustForPixelRatio:adjustForPixelRatio}),imageAspect=primaryImageAspectRatio):item.UserPrimaryImageTag&&"ActiveSession"!==item.Type&&(imgUrl=apiClient.getUserImageUrl(item.UserId,{maxHeight:height,maxWidth:width,tag:item.UserPrimaryImageTag,type:"Primary",adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=1),{imgUrl:imgUrl,forceName:forceName,aspect:imageAspect})};imageLoader.getCoveredImageClass=function(item,itemAspect,uiAspect,force){var imageClass;return null!=item.ChapterIndex?null:(imageClass=null,force||Math.abs(itemAspect-uiAspect)<=.28?(imageClass=" coveredImage","TvChannel"===(force=item.Type)?imageClass+=" coveredImage-contain":"PhotoAlbum"!==force&&"Person"!==force&&"ActivityLogEntry"!==force&&"Folder"!==force&&"Program"!==force&&"Recording"!==force&&"Photo"!==item.MediaType||(imageClass+=" coveredImage-noScale"),imageClass):void 0)},_exports.default=imageLoader}); |