Home / File/ filter-and-transform-font-faces.ts — astro Source File

filter-and-transform-font-faces.ts — astro Source File

Architecture documentation for filter-and-transform-font-faces.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 4 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  58296d83_574c_3fee_6296_26c77d438c1b["filter-and-transform-font-faces.ts"]
  a2fc192c_cdf9_df62_81bf_9c18a80b317e["./fonts/constants.js"]
  58296d83_574c_3fee_6296_26c77d438c1b --> a2fc192c_cdf9_df62_81bf_9c18a80b317e
  e92fda44_4a5d_b83b_1a45_958cdae6c91b["./definitions.js"]
  58296d83_574c_3fee_6296_26c77d438c1b --> e92fda44_4a5d_b83b_1a45_958cdae6c91b
  ea387312_d0a2_bb52_dafc_3872f7307f95["../../src/assets/fonts/types.js"]
  58296d83_574c_3fee_6296_26c77d438c1b --> ea387312_d0a2_bb52_dafc_3872f7307f95
  07866fa4_1b50_10c2_1b6b_5b1f385406b5["unifont"]
  58296d83_574c_3fee_6296_26c77d438c1b --> 07866fa4_1b50_10c2_1b6b_5b1f385406b5
  style 58296d83_574c_3fee_6296_26c77d438c1b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type * as unifont from 'unifont';
import { FONT_FORMATS } from '../constants.js';
import type { FontFileIdGenerator, FontTypeExtractor, UrlResolver } from '../definitions.js';
import type { ResolvedFontFamily } from '../types.js';

export function filterAndTransformFontFaces({
	fonts,
	fontTypeExtractor,
	fontFileIdGenerator,
	urlResolver,
	family,
}: {
	fonts: Array<unifont.FontFaceData>;
	fontTypeExtractor: FontTypeExtractor;
	fontFileIdGenerator: FontFileIdGenerator;
	urlResolver: UrlResolver;
	family: Pick<ResolvedFontFamily, 'cssVariable'>;
}) {
	return (
		fonts
			// Avoid getting too much font files
			.filter((font) => (typeof font.meta?.priority === 'number' ? font.meta.priority <= 1 : true))
			// Collect URLs
			.map((font) => ({
				...font,
				src: font.src.map((source) => {
					if ('name' in source) {
						return source;
					}
					// We handle protocol relative URLs here, otherwise they're considered absolute by the font
					// fetcher which will try to read them from the file system
					const originalUrl = source.url.startsWith('//') ? `https:${source.url}` : source.url;
					let format = FONT_FORMATS.find((e) => e.format === source.format);
					if (!format) {
						format = FONT_FORMATS.find((e) => e.type === fontTypeExtractor.extract(source.url))!;
					}
					const id = fontFileIdGenerator.generate({
						cssVariable: family.cssVariable,
						font,
						originalUrl,
						type: format.type,
					});
					const url = urlResolver.resolve(id);

					const newSource: unifont.RemoteFontSource = {
						originalURL: originalUrl,
						url,
						format: format.format,
						tech: source.tech,
					};
					return newSource;
				}),
			}))
	);
}

Domain

Subdomains

Dependencies

  • ../../src/assets/fonts/types.js
  • ./definitions.js
  • ./fonts/constants.js
  • unifont

Frequently Asked Questions

What does filter-and-transform-font-faces.ts do?
filter-and-transform-font-faces.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in filter-and-transform-font-faces.ts?
filter-and-transform-font-faces.ts defines 1 function(s): filterAndTransformFontFaces.
What does filter-and-transform-font-faces.ts depend on?
filter-and-transform-font-faces.ts imports 4 module(s): ../../src/assets/fonts/types.js, ./definitions.js, ./fonts/constants.js, unifont.
Where is filter-and-transform-font-faces.ts in the architecture?
filter-and-transform-font-faces.ts is located at packages/astro/src/assets/fonts/core/filter-and-transform-font-faces.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets/fonts/core).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free