// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Web Fonts Developer API Client for Deno * ======================================= * * The Google Web Fonts Developer API lets you retrieve information about web fonts served by Google. * * Docs: https://developers.google.com/fonts/docs/developer_api * Source: https://googleapis.deno.dev/v1/webfonts:v1.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; /** * The Google Web Fonts Developer API lets you retrieve information about web * fonts served by Google. */ export class WebFonts { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://webfonts.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Retrieves the list of fonts currently served by the Google Fonts Developer * API. * */ async webfontsList(opts: WebfontsListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/webfonts`); if (opts.capability !== undefined) { url.searchParams.append("capability", String(opts.capability)); } if (opts.family !== undefined) { url.searchParams.append("family", String(opts.family)); } if (opts.sort !== undefined) { url.searchParams.append("sort", String(opts.sort)); } if (opts.subset !== undefined) { url.searchParams.append("subset", String(opts.subset)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as WebfontList; } } /** * Metadata for a variable font axis. */ export interface Axis { /** * maximum value */ end?: number; /** * minimum value */ start?: number; /** * tag name. */ tag?: string; } /** * Metadata describing a family of fonts. */ export interface Webfont { /** * Axis for variable fonts. */ axes?: Axis[]; /** * The category of the font. */ category?: string; /** * The color format(s) available for this family. */ colorCapabilities?: string[]; /** * The name of the font. */ family?: string; /** * The font files (with all supported scripts) for each one of the available * variants, as a key : value map. */ files?: { [key: string]: string }; /** * This kind represents a webfont object in the webfonts service. */ kind?: string; /** * The date (format "yyyy-MM-dd") the font was modified for the last time. */ lastModified?: string; /** * Font URL for menu subset, a subset of the font that is enough to display * the font name */ menu?: string; /** * The scripts supported by the font. */ subsets?: string[]; /** * The available variants for the font. */ variants?: string[]; /** * The font version. */ version?: string; } /** * Response containing the list of fonts currently served by the Google Fonts * API. */ export interface WebfontList { /** * The list of fonts currently served by the Google Fonts API. */ items?: Webfont[]; /** * This kind represents a list of webfont objects in the webfonts service. */ kind?: string; } /** * Additional options for WebFonts#webfontsList. */ export interface WebfontsListOptions { /** * Controls the font urls in `Webfont.files`, by default, static ttf fonts * are sent. */ capability?: | "CAPABILITY_UNSPECIFIED" | "WOFF2" | "VF"; /** * Filters by Webfont.family, using literal match. If not set, returns all * families */ family?: string; /** * Enables sorting of the list. */ sort?: | "SORT_UNDEFINED" | "ALPHA" | "DATE" | "POPULARITY" | "STYLE" | "TRENDING"; /** * Filters by Webfont.subset, if subset is found in Webfont.subsets. If not * set, returns all families. */ subset?: string; }