Skip to content

Commit

Permalink
feat: expose provider id for successful font resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 4, 2024
1 parent dff3577 commit ff5345b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export interface UnifontOptions {

export type { ResolveFontOptions } from './types'
export interface Unifont {
resolveFont: (fontFamily: string, options?: ResolveFontOptions, providers?: string[]) => Promise<{ fonts: FontFaceData[] }>
resolveFont: (fontFamily: string, options?: ResolveFontOptions, providers?: string[]) => Promise<{
provider?: string
fonts: FontFaceData[]
}>
}

export const defaultResolveOptions: ResolveFontOptions = {
Expand Down Expand Up @@ -64,8 +67,12 @@ export async function createUnifont(providers: Provider[], options?: UnifontOpti

try {
const result = await provider.resolveFont(fontFamily, options)
if (result)
return result
if (result) {
return {
provider: id,
...result,
}
}
}
catch (err) {
console.error(`Could not resolve font face for \`${fontFamily}\` from \`${id}\` provider.`, err)
Expand Down

0 comments on commit ff5345b

Please sign in to comment.