import { FaviconFile , FaviconHtmlElement , FaviconImage , FaviconResponse , } from "../index.js" ; import { FaviconOptions , IconOptions } from "../config/defaults.js" ; import { asString , Dictionary , filterKeys , Images , mapValues , relativeTo , SourceImage , } from "../helpers.js" ; import { Logger } from "../logger.js" ; export function uniformIconOptions < T extends IconOptions > ( options , iconsChoice , platformConfig ) { let result = platformConfig ; if ( Array . isArray ( iconsChoice ) ) { result = filterKeys ( platformConfig , ( name ) => iconsChoice . includes ( name ) ) ; } else if ( typeof iconsChoice === "object" ) { result = mapValues ( platformConfig , ( iconOptions ) => ( { ... iconOptions , ... iconsChoice , } ) ) ; } result = mapValues ( result , ( iconOptions ) => ( { pixelArt : options . pixel_art , ... iconOptions , background : iconOptions . background === true ? options . background : asString ( iconOptions . background ) , } ) ) ; return result ; } export class Platform < IO extends IconOptions = IconOptions > { protected options : FaviconOptions ; protected iconOptions : Dictionary < IO > ; protected log : Logger ; constructor ( options , iconOptions , logger ) { this . options = options ; this . iconOptions = iconOptions ; this . log = logger ; } async create ( sourceset ) { const { output } = this . options ; return { images : output . images ? await this . createImages ( sourceset ) : [ ] , files : output . files ? await this . createFiles ( ) : [ ] , html : output . html ? await this . createHtml ( ) : [ ] , } ; } async createImages ( sourceset ) { const images = new Images ( this . log ) ; return await Promise . all ( Object . entries ( this . iconOptions ) . map ( ( [ iconName , iconOption ] ) => images . createFavicon ( sourceset , iconName , iconOption ) ) ) ; } async createFiles ( ) { return [ ] ; } async createHtml ( ) { return [ ] ; } protected relative ( path ) { return relativeTo ( this . options . path , path ) ; } }