full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -0,0 +1,10 @@
import type * as unifont from 'unifont';
import type { Hasher } from '../definitions.js';
import type { ResolvedFontFamily } from '../types.js';
export declare function extractUnifontProviders({ families, hasher, }: {
families: Array<ResolvedFontFamily>;
hasher: Hasher;
}): {
families: Array<ResolvedFontFamily>;
providers: Array<unifont.Provider>;
};

View File

@@ -0,0 +1,28 @@
import { LOCAL_PROVIDER_NAME } from "../constants.js";
function extractUnifontProviders({
families,
hasher
}) {
const hashes = /* @__PURE__ */ new Set();
const providers = [];
for (const { provider } of families) {
if (provider === LOCAL_PROVIDER_NAME) {
continue;
}
const unifontProvider = provider.provider(provider.config);
const hash = hasher.hashObject({
name: unifontProvider._name,
...provider.config
});
unifontProvider._name += `-${hash}`;
provider.name = unifontProvider._name;
if (!hashes.has(hash)) {
hashes.add(hash);
providers.push(unifontProvider);
}
}
return { families, providers };
}
export {
extractUnifontProviders
};

View File

@@ -0,0 +1,7 @@
import type * as unifont from 'unifont';
import type { FontTypeExtractor, UrlProxy } from '../definitions.js';
export declare function normalizeRemoteFontFaces({ fonts, urlProxy, fontTypeExtractor, }: {
fonts: Array<unifont.FontFaceData>;
urlProxy: UrlProxy;
fontTypeExtractor: FontTypeExtractor;
}): Array<unifont.FontFaceData>;

View File

@@ -0,0 +1,40 @@
import { FONT_FORMATS } from "../constants.js";
function normalizeRemoteFontFaces({
fonts,
urlProxy,
fontTypeExtractor
}) {
return fonts.filter((font) => typeof font.meta?.priority === "number" ? font.meta.priority === 0 : true).map((font) => {
let index = 0;
return {
...font,
src: font.src.map((source) => {
if ("name" in source) {
return source;
}
const url = source.url.startsWith("//") ? `https:${source.url}` : source.url;
const proxied = {
...source,
originalURL: url,
url: urlProxy.proxy({
url,
type: FONT_FORMATS.find((e) => e.format === source.format)?.type ?? fontTypeExtractor.extract(source.url),
// We only collect the first URL to avoid preloading fallback sources (eg. we only
// preload woff2 if woff is available)
collectPreload: index === 0,
data: {
weight: font.weight,
style: font.style
},
init: font.meta?.init ?? null
})
};
index++;
return proxied;
})
};
});
}
export {
normalizeRemoteFontFaces
};

View File

@@ -0,0 +1,17 @@
import type * as unifont from 'unifont';
import type { FontMetricsResolver, SystemFallbacksProvider } from '../definitions.js';
import type { FontFileData, ResolvedFontFamily } from '../types.js';
export interface CollectedFontForMetrics extends FontFileData {
data: Partial<unifont.FontFaceData>;
}
export declare function optimizeFallbacks({ family, fallbacks: _fallbacks, collectedFonts, enabled, systemFallbacksProvider, fontMetricsResolver, }: {
family: Pick<ResolvedFontFamily, 'name' | 'nameWithHash'>;
fallbacks: Array<string>;
collectedFonts: Array<CollectedFontForMetrics>;
enabled: boolean;
systemFallbacksProvider: SystemFallbacksProvider;
fontMetricsResolver: FontMetricsResolver;
}): Promise<null | {
css: string;
fallbacks: Array<string>;
}>;

View File

@@ -0,0 +1,47 @@
import { isGenericFontFamily, unifontFontFaceDataToProperties } from "../utils.js";
async function optimizeFallbacks({
family,
fallbacks: _fallbacks,
collectedFonts,
enabled,
systemFallbacksProvider,
fontMetricsResolver
}) {
let fallbacks = [..._fallbacks];
if (fallbacks.length === 0 || !enabled || collectedFonts.length === 0) {
return null;
}
const lastFallback = fallbacks[fallbacks.length - 1];
if (!isGenericFontFamily(lastFallback)) {
return null;
}
const localFonts = systemFallbacksProvider.getLocalFonts(lastFallback);
if (!localFonts || localFonts.length === 0) {
return null;
}
if (localFonts.includes(family.name)) {
return null;
}
const localFontsMappings = localFonts.map((font) => ({
font,
// We must't wrap in quote because that's handled by the CSS renderer
name: `${family.nameWithHash} fallback: ${font}`
}));
fallbacks = [...localFontsMappings.map((m) => m.name), ...fallbacks];
let css = "";
for (const { font, name } of localFontsMappings) {
for (const collected of collectedFonts) {
css += fontMetricsResolver.generateFontFace({
metrics: await fontMetricsResolver.getMetrics(family.name, collected),
fallbackMetrics: systemFallbacksProvider.getMetricsForLocalFont(font),
font,
name,
properties: unifontFontFaceDataToProperties(collected.data)
});
}
}
return { css, fallbacks };
}
export {
optimizeFallbacks
};

View File

@@ -0,0 +1,17 @@
import type { Hasher, LocalProviderUrlResolver, RemoteFontProviderResolver } from '../definitions.js';
import type { FontFamily, ResolvedFontFamily } from '../types.js';
/**
* Dedupes properties if applicable and resolves entrypoints.
*/
export declare function resolveFamily({ family, hasher, remoteFontProviderResolver, localProviderUrlResolver, }: {
family: FontFamily;
hasher: Hasher;
remoteFontProviderResolver: RemoteFontProviderResolver;
localProviderUrlResolver: LocalProviderUrlResolver;
}): Promise<ResolvedFontFamily>;
/**
* A function for convenience. The actual logic lives in resolveFamily
*/
export declare function resolveFamilies({ families, ...dependencies }: {
families: Array<FontFamily>;
} & Omit<Parameters<typeof resolveFamily>[0], 'family'>): Promise<Array<ResolvedFontFamily>>;

View File

@@ -0,0 +1,67 @@
import { LOCAL_PROVIDER_NAME } from "../constants.js";
import { dedupe, withoutQuotes } from "../utils.js";
function resolveVariants({
variants,
localProviderUrlResolver
}) {
return variants.map((variant) => ({
...variant,
weight: variant.weight?.toString(),
src: variant.src.map((value) => {
const isValue = typeof value === "string" || value instanceof URL;
const url = (isValue ? value : value.url).toString();
const tech = isValue ? void 0 : value.tech;
return {
url: localProviderUrlResolver.resolve(url),
tech
};
})
}));
}
async function resolveFamily({
family,
hasher,
remoteFontProviderResolver,
localProviderUrlResolver
}) {
const name = withoutQuotes(family.name);
const nameWithHash = `${name}-${hasher.hashObject(family)}`;
if (family.provider === LOCAL_PROVIDER_NAME) {
return {
...family,
name,
nameWithHash,
variants: resolveVariants({ variants: family.variants, localProviderUrlResolver }),
fallbacks: family.fallbacks ? dedupe(family.fallbacks) : void 0
};
}
return {
...family,
name,
nameWithHash,
weights: family.weights ? dedupe(family.weights.map((weight) => weight.toString())) : void 0,
styles: family.styles ? dedupe(family.styles) : void 0,
subsets: family.subsets ? dedupe(family.subsets) : void 0,
fallbacks: family.fallbacks ? dedupe(family.fallbacks) : void 0,
unicodeRange: family.unicodeRange ? dedupe(family.unicodeRange) : void 0,
// This will be Astro specific eventually
provider: await remoteFontProviderResolver.resolve(family.provider)
};
}
async function resolveFamilies({
families,
...dependencies
}) {
return await Promise.all(
families.map(
(family) => resolveFamily({
family,
...dependencies
})
)
);
}
export {
resolveFamilies,
resolveFamily
};