astro 5.16.13 → 5.16.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Font.astro +4 -4
- package/dist/assets/fonts/config.d.ts +15 -145
- package/dist/assets/fonts/config.js +3 -22
- package/dist/assets/fonts/constants.d.ts +0 -1
- package/dist/assets/fonts/constants.js +0 -2
- package/dist/assets/fonts/core/collect-component-data.d.ts +9 -0
- package/dist/assets/fonts/core/collect-component-data.js +47 -0
- package/dist/assets/fonts/core/collect-font-assets-from-faces.d.ts +17 -0
- package/dist/assets/fonts/core/collect-font-assets-from-faces.js +71 -0
- package/dist/assets/fonts/core/collect-font-data.d.ts +4 -0
- package/dist/assets/fonts/core/collect-font-data.js +23 -0
- package/dist/assets/fonts/core/compute-font-families-assets.d.ts +20 -0
- package/dist/assets/fonts/core/compute-font-families-assets.js +67 -0
- package/dist/assets/fonts/core/filter-and-transform-font-faces.d.ts +20 -0
- package/dist/assets/fonts/core/filter-and-transform-font-faces.js +39 -0
- package/dist/assets/fonts/core/get-or-create-font-family-assets.d.ts +8 -0
- package/dist/assets/fonts/core/get-or-create-font-family-assets.js +34 -0
- package/dist/assets/fonts/core/optimize-fallbacks.d.ts +2 -3
- package/dist/assets/fonts/core/optimize-fallbacks.js +2 -3
- package/dist/assets/fonts/core/resolve-family.d.ts +6 -0
- package/dist/assets/fonts/core/resolve-family.js +23 -0
- package/dist/assets/fonts/definitions.d.ts +6 -28
- package/dist/assets/fonts/infra/build-font-file-id-generator.d.ts +13 -0
- package/dist/assets/fonts/infra/{build-url-proxy-hash-resolver.js → build-font-file-id-generator.js} +3 -6
- package/dist/assets/fonts/infra/build-url-resolver.d.ts +1 -1
- package/dist/assets/fonts/infra/build-url-resolver.js +4 -4
- package/dist/assets/fonts/infra/cached-font-fetcher.d.ts +1 -1
- package/dist/assets/fonts/infra/cached-font-fetcher.js +11 -3
- package/dist/assets/fonts/infra/capsize-font-metrics-resolver.d.ts +2 -2
- package/dist/assets/fonts/infra/dev-font-file-id-generator.d.ts +16 -0
- package/dist/assets/fonts/infra/{dev-url-proxy-hash-resolver.js → dev-font-file-id-generator.js} +8 -8
- package/dist/assets/fonts/infra/dev-url-resolver.d.ts +1 -1
- package/dist/assets/fonts/infra/dev-url-resolver.js +2 -2
- package/dist/assets/fonts/infra/fs-font-file-content-resolver.d.ts +10 -0
- package/dist/assets/fonts/infra/fs-font-file-content-resolver.js +21 -0
- package/dist/assets/fonts/infra/minifiable-css-renderer.d.ts +2 -1
- package/dist/assets/fonts/infra/{font-type-extractor.d.ts → node-font-type-extractor.d.ts} +1 -1
- package/dist/assets/fonts/infra/{font-type-extractor.js → node-font-type-extractor.js} +2 -2
- package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +5 -3
- package/dist/assets/fonts/infra/unifont-font-resolver.js +14 -17
- package/dist/assets/fonts/providers/index.d.ts +6 -1
- package/dist/assets/fonts/providers/index.js +9 -1
- package/dist/assets/fonts/providers/local.d.ts +41 -8
- package/dist/assets/fonts/providers/local.js +65 -48
- package/dist/assets/fonts/runtime/client.d.ts +1 -1
- package/dist/assets/fonts/runtime/client.js +1 -1
- package/dist/assets/fonts/runtime/server.d.ts +1 -1
- package/dist/assets/fonts/runtime/server.js +1 -1
- package/dist/assets/fonts/types.d.ts +61 -110
- package/dist/assets/fonts/utils.d.ts +1 -7
- package/dist/assets/fonts/utils.js +1 -15
- package/dist/assets/fonts/vite-plugin-fonts.js +149 -141
- package/dist/cli/add/index.js +39 -0
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/config/index.d.ts +1 -2
- package/dist/content/content-layer.js +3 -3
- package/dist/core/config/schemas/base.d.ts +60 -337
- package/dist/core/config/schemas/base.js +2 -2
- package/dist/core/config/schemas/relative.d.ts +80 -431
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +1 -1
- package/dist/core/errors/errors-data.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/types/public/config.d.ts +3 -4
- package/package.json +5 -5
- package/dist/assets/fonts/core/normalize-remote-font-faces.d.ts +0 -7
- package/dist/assets/fonts/core/normalize-remote-font-faces.js +0 -41
- package/dist/assets/fonts/core/resolve-families.d.ts +0 -16
- package/dist/assets/fonts/core/resolve-families.js +0 -63
- package/dist/assets/fonts/infra/build-url-proxy-hash-resolver.d.ts +0 -15
- package/dist/assets/fonts/infra/data-collector.d.ts +0 -10
- package/dist/assets/fonts/infra/data-collector.js +0 -35
- package/dist/assets/fonts/infra/dev-url-proxy-hash-resolver.d.ts +0 -15
- package/dist/assets/fonts/infra/local-url-proxy-content-resolver.d.ts +0 -4
- package/dist/assets/fonts/infra/local-url-proxy-content-resolver.js +0 -14
- package/dist/assets/fonts/infra/remote-url-proxy-content-resolver.d.ts +0 -4
- package/dist/assets/fonts/infra/remote-url-proxy-content-resolver.js +0 -9
- package/dist/assets/fonts/infra/require-local-provider-url-resolver.d.ts +0 -9
- package/dist/assets/fonts/infra/require-local-provider-url-resolver.js +0 -30
- package/dist/assets/fonts/infra/url-proxy.d.ts +0 -16
- package/dist/assets/fonts/infra/url-proxy.js +0 -50
- package/dist/assets/fonts/orchestrate.d.ts +0 -42
- package/dist/assets/fonts/orchestrate.js +0 -173
|
@@ -4,11 +4,10 @@ import type { FontFileData, ResolvedFontFamily } from '../types.js';
|
|
|
4
4
|
export interface CollectedFontForMetrics extends FontFileData {
|
|
5
5
|
data: Partial<unifont.FontFaceData>;
|
|
6
6
|
}
|
|
7
|
-
export declare function optimizeFallbacks({ family, fallbacks: _fallbacks, collectedFonts,
|
|
8
|
-
family: Pick<ResolvedFontFamily, 'name' | '
|
|
7
|
+
export declare function optimizeFallbacks({ family, fallbacks: _fallbacks, collectedFonts, systemFallbacksProvider, fontMetricsResolver, }: {
|
|
8
|
+
family: Pick<ResolvedFontFamily, 'name' | 'uniqueName'>;
|
|
9
9
|
fallbacks: Array<string>;
|
|
10
10
|
collectedFonts: Array<CollectedFontForMetrics>;
|
|
11
|
-
enabled: boolean;
|
|
12
11
|
systemFallbacksProvider: SystemFallbacksProvider;
|
|
13
12
|
fontMetricsResolver: FontMetricsResolver;
|
|
14
13
|
}): Promise<null | {
|
|
@@ -3,12 +3,11 @@ async function optimizeFallbacks({
|
|
|
3
3
|
family,
|
|
4
4
|
fallbacks: _fallbacks,
|
|
5
5
|
collectedFonts,
|
|
6
|
-
enabled,
|
|
7
6
|
systemFallbacksProvider,
|
|
8
7
|
fontMetricsResolver
|
|
9
8
|
}) {
|
|
10
9
|
let fallbacks = [..._fallbacks];
|
|
11
|
-
if (fallbacks.length === 0 ||
|
|
10
|
+
if (fallbacks.length === 0 || collectedFonts.length === 0) {
|
|
12
11
|
return null;
|
|
13
12
|
}
|
|
14
13
|
const lastFallback = fallbacks[fallbacks.length - 1];
|
|
@@ -25,7 +24,7 @@ async function optimizeFallbacks({
|
|
|
25
24
|
const localFontsMappings = localFonts.map((font) => ({
|
|
26
25
|
font,
|
|
27
26
|
// We mustn't wrap in quote because that's handled by the CSS renderer
|
|
28
|
-
name: `${family.
|
|
27
|
+
name: `${family.uniqueName} fallback: ${font}`
|
|
29
28
|
}));
|
|
30
29
|
fallbacks = [...localFontsMappings.map((m) => m.name), ...fallbacks];
|
|
31
30
|
let css = "";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { dedupe, withoutQuotes } from "../utils.js";
|
|
2
|
+
function resolveFamily({
|
|
3
|
+
family,
|
|
4
|
+
hasher
|
|
5
|
+
}) {
|
|
6
|
+
const name = withoutQuotes(family.name);
|
|
7
|
+
return {
|
|
8
|
+
...family,
|
|
9
|
+
name,
|
|
10
|
+
// This will be used in CSS font faces. Quotes are added by the CSS renderer if
|
|
11
|
+
// this value contains a space.
|
|
12
|
+
uniqueName: `${name}-${hasher.hashObject(family)}`,
|
|
13
|
+
weights: family.weights ? dedupe(family.weights.map((weight) => weight.toString())) : void 0,
|
|
14
|
+
styles: family.styles ? dedupe(family.styles) : void 0,
|
|
15
|
+
subsets: family.subsets ? dedupe(family.subsets) : void 0,
|
|
16
|
+
formats: family.formats ? dedupe(family.formats) : void 0,
|
|
17
|
+
fallbacks: family.fallbacks ? dedupe(family.fallbacks) : void 0,
|
|
18
|
+
unicodeRange: family.unicodeRange ? dedupe(family.unicodeRange) : void 0
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
resolveFamily
|
|
23
|
+
};
|
|
@@ -1,39 +1,17 @@
|
|
|
1
1
|
import type * as unifont from 'unifont';
|
|
2
2
|
import type { CollectedFontForMetrics } from './core/optimize-fallbacks.js';
|
|
3
|
-
import type { FontFaceMetrics, FontFileData, FontProvider, FontType, GenericFallbackName,
|
|
3
|
+
import type { CssProperties, FontFaceMetrics, FontFileData, FontProvider, FontType, GenericFallbackName, ResolveFontOptions, Style } from './types.js';
|
|
4
4
|
export interface Hasher {
|
|
5
5
|
hashString: (input: string) => string;
|
|
6
6
|
hashObject: (input: Record<string, any>) => string;
|
|
7
7
|
}
|
|
8
|
-
export interface LocalProviderUrlResolver {
|
|
9
|
-
resolve: (input: string) => string;
|
|
10
|
-
}
|
|
11
|
-
export interface ProxyData {
|
|
12
|
-
weight: unifont.FontFaceData['weight'];
|
|
13
|
-
style: unifont.FontFaceData['style'];
|
|
14
|
-
subset: NonNullable<unifont.FontFaceData['meta']>['subset'];
|
|
15
|
-
}
|
|
16
|
-
export interface UrlProxy {
|
|
17
|
-
proxy: (input: Pick<FontFileData, 'url' | 'init'> & {
|
|
18
|
-
type: FontType;
|
|
19
|
-
collectPreload: boolean;
|
|
20
|
-
data: ProxyData;
|
|
21
|
-
}) => string;
|
|
22
|
-
}
|
|
23
8
|
export interface UrlResolver {
|
|
24
|
-
resolve: (
|
|
9
|
+
resolve: (id: string) => string;
|
|
25
10
|
readonly cspResources: Array<string>;
|
|
26
11
|
}
|
|
27
|
-
export interface
|
|
12
|
+
export interface FontFileContentResolver {
|
|
28
13
|
resolve: (url: string) => string;
|
|
29
14
|
}
|
|
30
|
-
export interface DataCollector {
|
|
31
|
-
collect: (input: FontFileData & {
|
|
32
|
-
data: ProxyData;
|
|
33
|
-
preload: PreloadData | null;
|
|
34
|
-
}) => void;
|
|
35
|
-
}
|
|
36
|
-
export type CssProperties = Record<string, string | undefined>;
|
|
37
15
|
export interface CssRenderer {
|
|
38
16
|
generateFontFace: (family: string, properties: CssProperties) => string;
|
|
39
17
|
generateCssVariable: (key: string, values: Array<string>) => string;
|
|
@@ -67,12 +45,12 @@ export interface FontFileReader {
|
|
|
67
45
|
style: Style;
|
|
68
46
|
};
|
|
69
47
|
}
|
|
70
|
-
export interface
|
|
71
|
-
|
|
48
|
+
export interface FontFileIdGenerator {
|
|
49
|
+
generate: (input: {
|
|
72
50
|
originalUrl: string;
|
|
73
51
|
type: FontType;
|
|
74
52
|
cssVariable: string;
|
|
75
|
-
|
|
53
|
+
font: unifont.FontFaceData;
|
|
76
54
|
}) => string;
|
|
77
55
|
}
|
|
78
56
|
export interface StringMatcher {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FontFileContentResolver, FontFileIdGenerator, Hasher } from '../definitions.js';
|
|
2
|
+
import type { FontType } from '../types.js';
|
|
3
|
+
export declare class BuildFontFileIdGenerator implements FontFileIdGenerator {
|
|
4
|
+
#private;
|
|
5
|
+
constructor({ hasher, contentResolver, }: {
|
|
6
|
+
hasher: Hasher;
|
|
7
|
+
contentResolver: FontFileContentResolver;
|
|
8
|
+
});
|
|
9
|
+
generate({ originalUrl, type }: {
|
|
10
|
+
originalUrl: string;
|
|
11
|
+
type: FontType;
|
|
12
|
+
}): string;
|
|
13
|
+
}
|
package/dist/assets/fonts/infra/{build-url-proxy-hash-resolver.js → build-font-file-id-generator.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class BuildFontFileIdGenerator {
|
|
2
2
|
#hasher;
|
|
3
3
|
#contentResolver;
|
|
4
4
|
constructor({
|
|
@@ -8,13 +8,10 @@ class BuildUrlProxyHashResolver {
|
|
|
8
8
|
this.#hasher = hasher;
|
|
9
9
|
this.#contentResolver = contentResolver;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
originalUrl,
|
|
13
|
-
type
|
|
14
|
-
}) {
|
|
11
|
+
generate({ originalUrl, type }) {
|
|
15
12
|
return `${this.#hasher.hashString(this.#contentResolver.resolve(originalUrl))}.${type}`;
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
15
|
export {
|
|
19
|
-
|
|
16
|
+
BuildFontFileIdGenerator
|
|
20
17
|
};
|
|
@@ -15,15 +15,15 @@ class BuildUrlResolver {
|
|
|
15
15
|
this.#assetsPrefix = assetsPrefix;
|
|
16
16
|
this.#searchParams = searchParams;
|
|
17
17
|
}
|
|
18
|
-
resolve(
|
|
19
|
-
const prefix = this.#assetsPrefix ? getAssetsPrefix(fileExtension(
|
|
18
|
+
resolve(id) {
|
|
19
|
+
const prefix = this.#assetsPrefix ? getAssetsPrefix(fileExtension(id), this.#assetsPrefix) : void 0;
|
|
20
20
|
let urlPath;
|
|
21
21
|
if (prefix) {
|
|
22
22
|
this.#resources.add(prefix);
|
|
23
|
-
urlPath = joinPaths(prefix, this.#base,
|
|
23
|
+
urlPath = joinPaths(prefix, this.#base, id);
|
|
24
24
|
} else {
|
|
25
25
|
this.#resources.add("'self'");
|
|
26
|
-
urlPath = prependForwardSlash(joinPaths(this.#base,
|
|
26
|
+
urlPath = prependForwardSlash(joinPaths(this.#base, id));
|
|
27
27
|
}
|
|
28
28
|
const url = createPlaceholderURL(urlPath);
|
|
29
29
|
this.#searchParams.forEach((value, key) => {
|
|
@@ -7,5 +7,5 @@ export declare class CachedFontFetcher implements FontFetcher {
|
|
|
7
7
|
fetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
8
8
|
readFile: (url: string) => Promise<Buffer>;
|
|
9
9
|
});
|
|
10
|
-
fetch({
|
|
10
|
+
fetch({ id, url, init }: FontFileData): Promise<Buffer>;
|
|
11
11
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isAbsolute } from "node:path";
|
|
2
2
|
import { AstroError, AstroErrorData } from "../../../core/errors/index.js";
|
|
3
|
-
import { cache } from "../utils.js";
|
|
4
3
|
class CachedFontFetcher {
|
|
5
4
|
#storage;
|
|
6
5
|
#fetch;
|
|
@@ -14,8 +13,17 @@ class CachedFontFetcher {
|
|
|
14
13
|
this.#fetch = fetch;
|
|
15
14
|
this.#readFile = readFile;
|
|
16
15
|
}
|
|
17
|
-
async
|
|
18
|
-
|
|
16
|
+
async #cache(storage, key, cb) {
|
|
17
|
+
const existing = await storage.getItemRaw(key);
|
|
18
|
+
if (existing) {
|
|
19
|
+
return existing;
|
|
20
|
+
}
|
|
21
|
+
const data = await cb();
|
|
22
|
+
await storage.setItemRaw(key, data);
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
async fetch({ id, url, init }) {
|
|
26
|
+
return await this.#cache(this.#storage, id, async () => {
|
|
19
27
|
try {
|
|
20
28
|
if (isAbsolute(url)) {
|
|
21
29
|
return await this.#readFile(url);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CollectedFontForMetrics } from '../core/optimize-fallbacks.js';
|
|
2
|
-
import type {
|
|
3
|
-
import type { FontFaceMetrics } from '../types.js';
|
|
2
|
+
import type { CssRenderer, FontFetcher, FontMetricsResolver } from '../definitions.js';
|
|
3
|
+
import type { CssProperties, FontFaceMetrics } from '../types.js';
|
|
4
4
|
export declare class CapsizeFontMetricsResolver implements FontMetricsResolver {
|
|
5
5
|
#private;
|
|
6
6
|
constructor({ fontFetcher, cssRenderer, }: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as unifont from 'unifont';
|
|
2
|
+
import type { FontFileContentResolver, FontFileIdGenerator, Hasher } from '../definitions.js';
|
|
3
|
+
import type { FontType } from '../types.js';
|
|
4
|
+
export declare class DevFontFileIdGenerator implements FontFileIdGenerator {
|
|
5
|
+
#private;
|
|
6
|
+
constructor({ hasher, contentResolver, }: {
|
|
7
|
+
hasher: Hasher;
|
|
8
|
+
contentResolver: FontFileContentResolver;
|
|
9
|
+
});
|
|
10
|
+
generate({ cssVariable, originalUrl, type, font, }: {
|
|
11
|
+
originalUrl: string;
|
|
12
|
+
type: FontType;
|
|
13
|
+
cssVariable: string;
|
|
14
|
+
font: unifont.FontFaceData;
|
|
15
|
+
}): string;
|
|
16
|
+
}
|
package/dist/assets/fonts/infra/{dev-url-proxy-hash-resolver.js → dev-font-file-id-generator.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class DevFontFileIdGenerator {
|
|
2
2
|
#hasher;
|
|
3
3
|
#contentResolver;
|
|
4
4
|
constructor({
|
|
@@ -17,21 +17,21 @@ class DevUrlProxyHashResolver {
|
|
|
17
17
|
}
|
|
18
18
|
return weight?.replace(/\s+/g, "-");
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
generate({
|
|
21
21
|
cssVariable,
|
|
22
|
-
data,
|
|
23
22
|
originalUrl,
|
|
24
|
-
type
|
|
23
|
+
type,
|
|
24
|
+
font
|
|
25
25
|
}) {
|
|
26
26
|
return [
|
|
27
27
|
cssVariable.slice(2),
|
|
28
|
-
this.#formatWeight(
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
this.#formatWeight(font.weight),
|
|
29
|
+
font.style,
|
|
30
|
+
font.meta?.subset,
|
|
31
31
|
`${this.#hasher.hashString(this.#contentResolver.resolve(originalUrl))}.${type}`
|
|
32
32
|
].filter(Boolean).join("-");
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export {
|
|
36
|
-
|
|
36
|
+
DevFontFileIdGenerator
|
|
37
37
|
};
|
|
@@ -11,9 +11,9 @@ class DevUrlResolver {
|
|
|
11
11
|
this.#base = base;
|
|
12
12
|
this.#searchParams = searchParams;
|
|
13
13
|
}
|
|
14
|
-
resolve(
|
|
14
|
+
resolve(id) {
|
|
15
15
|
this.#resolved ||= true;
|
|
16
|
-
const urlPath = prependForwardSlash(joinPaths(this.#base,
|
|
16
|
+
const urlPath = prependForwardSlash(joinPaths(this.#base, id));
|
|
17
17
|
const url = createPlaceholderURL(urlPath);
|
|
18
18
|
this.#searchParams.forEach((value, key) => {
|
|
19
19
|
url.searchParams.set(key, value);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FontFileContentResolver } from '../definitions.js';
|
|
2
|
+
type ReadFileSync = (path: string) => string;
|
|
3
|
+
export declare class FsFontFileContentResolver implements FontFileContentResolver {
|
|
4
|
+
#private;
|
|
5
|
+
constructor({ readFileSync }: {
|
|
6
|
+
readFileSync: ReadFileSync;
|
|
7
|
+
});
|
|
8
|
+
resolve(url: string): string;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { AstroError, AstroErrorData } from "../../../core/errors/index.js";
|
|
3
|
+
class FsFontFileContentResolver {
|
|
4
|
+
#readFileSync;
|
|
5
|
+
constructor({ readFileSync }) {
|
|
6
|
+
this.#readFileSync = readFileSync;
|
|
7
|
+
}
|
|
8
|
+
resolve(url) {
|
|
9
|
+
if (!isAbsolute(url)) {
|
|
10
|
+
return url;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return url + this.#readFileSync(url);
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
FsFontFileContentResolver
|
|
21
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CssRenderer } from '../definitions.js';
|
|
2
|
+
import type { CssProperties } from '../types.js';
|
|
2
3
|
export declare function renderFontFace(properties: CssProperties, minify: boolean): string;
|
|
3
4
|
export declare function renderCssVariable(key: string, values: Array<string>, minify: boolean): string;
|
|
4
5
|
export declare function withFamily(family: string, properties: CssProperties): CssProperties;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FontTypeExtractor } from '../definitions.js';
|
|
2
2
|
import type { FontType } from '../types.js';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class NodeFontTypeExtractor implements FontTypeExtractor {
|
|
4
4
|
extract(url: string): FontType;
|
|
5
5
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
2
|
import { AstroError, AstroErrorData } from "../../../core/errors/index.js";
|
|
3
3
|
import { isFontType } from "../utils.js";
|
|
4
|
-
class
|
|
4
|
+
class NodeFontTypeExtractor {
|
|
5
5
|
extract(url) {
|
|
6
6
|
const extension = extname(url).slice(1);
|
|
7
7
|
if (!isFontType(extension)) {
|
|
@@ -17,5 +17,5 @@ class RealFontTypeExtractor {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
export {
|
|
20
|
-
|
|
20
|
+
NodeFontTypeExtractor
|
|
21
21
|
};
|
|
@@ -12,15 +12,17 @@ export declare class UnifontFontResolver implements FontResolver {
|
|
|
12
12
|
hasher: Hasher;
|
|
13
13
|
provider: FontProvider;
|
|
14
14
|
}): string;
|
|
15
|
-
static astroToUnifontProvider(astroProvider: FontProvider): Provider;
|
|
16
|
-
static extractUnifontProviders({ families, hasher, }: {
|
|
15
|
+
static astroToUnifontProvider(astroProvider: FontProvider, root: URL): Provider;
|
|
16
|
+
static extractUnifontProviders({ families, hasher, root, }: {
|
|
17
17
|
families: Array<ResolvedFontFamily>;
|
|
18
18
|
hasher: Hasher;
|
|
19
|
+
root: URL;
|
|
19
20
|
}): NonEmptyProviders;
|
|
20
|
-
static create({ families, hasher, storage, }: {
|
|
21
|
+
static create({ families, hasher, storage, root, }: {
|
|
21
22
|
families: Array<ResolvedFontFamily>;
|
|
22
23
|
hasher: Hasher;
|
|
23
24
|
storage: Storage;
|
|
25
|
+
root: URL;
|
|
24
26
|
}): Promise<UnifontFontResolver>;
|
|
25
27
|
resolveFont({ familyName, provider, options, ...rest }: ResolveFontOptions<Record<string, any>> & {
|
|
26
28
|
provider: FontProvider;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createUnifont, defineFontProvider } from "unifont";
|
|
2
|
-
import { LOCAL_PROVIDER_NAME } from "../constants.js";
|
|
3
2
|
class UnifontFontResolver {
|
|
4
3
|
#unifont;
|
|
5
4
|
#hasher;
|
|
@@ -17,9 +16,9 @@ class UnifontFontResolver {
|
|
|
17
16
|
});
|
|
18
17
|
return `${provider.name}-${hash}`;
|
|
19
18
|
}
|
|
20
|
-
static astroToUnifontProvider(astroProvider) {
|
|
19
|
+
static astroToUnifontProvider(astroProvider, root) {
|
|
21
20
|
return defineFontProvider(astroProvider.name, async (_options, ctx) => {
|
|
22
|
-
await astroProvider?.init?.(ctx);
|
|
21
|
+
await astroProvider?.init?.({ ...ctx, root });
|
|
23
22
|
return {
|
|
24
23
|
async resolveFont(familyName, { options, ...rest }) {
|
|
25
24
|
return await astroProvider.resolveFont({ familyName, options, ...rest });
|
|
@@ -32,16 +31,14 @@ class UnifontFontResolver {
|
|
|
32
31
|
}
|
|
33
32
|
static extractUnifontProviders({
|
|
34
33
|
families,
|
|
35
|
-
hasher
|
|
34
|
+
hasher,
|
|
35
|
+
root
|
|
36
36
|
}) {
|
|
37
37
|
const providers = /* @__PURE__ */ new Map();
|
|
38
38
|
for (const { provider } of families) {
|
|
39
|
-
if (provider === LOCAL_PROVIDER_NAME) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
39
|
const id = this.idFromProvider({ hasher, provider });
|
|
43
40
|
if (!providers.has(id)) {
|
|
44
|
-
const unifontProvider = this.astroToUnifontProvider(provider);
|
|
41
|
+
const unifontProvider = this.astroToUnifontProvider(provider, root);
|
|
45
42
|
unifontProvider._name = this.idFromProvider({ hasher, provider });
|
|
46
43
|
providers.set(id, unifontProvider);
|
|
47
44
|
}
|
|
@@ -51,10 +48,11 @@ class UnifontFontResolver {
|
|
|
51
48
|
static async create({
|
|
52
49
|
families,
|
|
53
50
|
hasher,
|
|
54
|
-
storage
|
|
51
|
+
storage,
|
|
52
|
+
root
|
|
55
53
|
}) {
|
|
56
54
|
return new UnifontFontResolver({
|
|
57
|
-
unifont: await createUnifont(this.extractUnifontProviders({ families, hasher }), {
|
|
55
|
+
unifont: await createUnifont(this.extractUnifontProviders({ families, hasher, root }), {
|
|
58
56
|
storage,
|
|
59
57
|
// TODO: consider enabling, would require new astro errors
|
|
60
58
|
throwOnError: false
|
|
@@ -68,22 +66,21 @@ class UnifontFontResolver {
|
|
|
68
66
|
options,
|
|
69
67
|
...rest
|
|
70
68
|
}) {
|
|
69
|
+
const id = UnifontFontResolver.idFromProvider({
|
|
70
|
+
hasher: this.#hasher,
|
|
71
|
+
provider
|
|
72
|
+
});
|
|
71
73
|
const { fonts } = await this.#unifont.resolveFont(
|
|
72
74
|
familyName,
|
|
73
75
|
{
|
|
74
76
|
// Options are currently namespaced by provider name, it may change in
|
|
75
77
|
// https://github.com/unjs/unifont/pull/287
|
|
76
78
|
options: {
|
|
77
|
-
[
|
|
79
|
+
[id]: options
|
|
78
80
|
},
|
|
79
81
|
...rest
|
|
80
82
|
},
|
|
81
|
-
[
|
|
82
|
-
UnifontFontResolver.idFromProvider({
|
|
83
|
-
hasher: this.#hasher,
|
|
84
|
-
provider
|
|
85
|
-
})
|
|
86
|
-
]
|
|
83
|
+
[id]
|
|
87
84
|
);
|
|
88
85
|
return fonts;
|
|
89
86
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AdobeProviderOptions, type GoogleFamilyOptions, type GoogleiconsFamilyOptions } from 'unifont';
|
|
2
2
|
import type { FontProvider } from '../types.js';
|
|
3
|
+
import { type LocalFamilyOptions } from './local.js';
|
|
3
4
|
/** [Adobe](https://fonts.adobe.com/) */
|
|
4
5
|
declare function adobe(config: AdobeProviderOptions): FontProvider;
|
|
5
6
|
/** [Bunny](https://fonts.bunny.net/) */
|
|
@@ -12,14 +13,17 @@ declare function fontsource(): FontProvider;
|
|
|
12
13
|
declare function google(): FontProvider<GoogleFamilyOptions | undefined>;
|
|
13
14
|
/** [Google Icons](https://fonts.google.com/icons) */
|
|
14
15
|
declare function googleicons(): FontProvider<GoogleiconsFamilyOptions | undefined>;
|
|
16
|
+
/** A provider that handles local files. */
|
|
17
|
+
declare function local(): FontProvider<LocalFamilyOptions>;
|
|
15
18
|
/**
|
|
16
|
-
* Astro
|
|
19
|
+
* Astro exports a few built-in providers:
|
|
17
20
|
* - [Adobe](https://fonts.adobe.com/)
|
|
18
21
|
* - [Bunny](https://fonts.bunny.net/)
|
|
19
22
|
* - [Fontshare](https://www.fontshare.com/)
|
|
20
23
|
* - [Fontsource](https://fontsource.org/)
|
|
21
24
|
* - [Google](https://fonts.google.com/)
|
|
22
25
|
* - [Google Icons](https://fonts.google.com/icons)
|
|
26
|
+
* - Local
|
|
23
27
|
*/
|
|
24
28
|
export declare const fontProviders: {
|
|
25
29
|
adobe: typeof adobe;
|
|
@@ -28,5 +32,6 @@ export declare const fontProviders: {
|
|
|
28
32
|
fontsource: typeof fontsource;
|
|
29
33
|
google: typeof google;
|
|
30
34
|
googleicons: typeof googleicons;
|
|
35
|
+
local: typeof local;
|
|
31
36
|
};
|
|
32
37
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
providers
|
|
3
3
|
} from "unifont";
|
|
4
|
+
import { FontaceFontFileReader } from "../infra/fontace-font-file-reader.js";
|
|
5
|
+
import { LocalFontProvider } from "./local.js";
|
|
4
6
|
function adobe(config) {
|
|
5
7
|
const provider = providers.adobe(config);
|
|
6
8
|
let initializedProvider;
|
|
@@ -98,13 +100,19 @@ function googleicons() {
|
|
|
98
100
|
}
|
|
99
101
|
};
|
|
100
102
|
}
|
|
103
|
+
function local() {
|
|
104
|
+
return new LocalFontProvider({
|
|
105
|
+
fontFileReader: new FontaceFontFileReader()
|
|
106
|
+
});
|
|
107
|
+
}
|
|
101
108
|
const fontProviders = {
|
|
102
109
|
adobe,
|
|
103
110
|
bunny,
|
|
104
111
|
fontshare,
|
|
105
112
|
fontsource,
|
|
106
113
|
google,
|
|
107
|
-
googleicons
|
|
114
|
+
googleicons,
|
|
115
|
+
local
|
|
108
116
|
};
|
|
109
117
|
export {
|
|
110
118
|
fontProviders
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import type * as unifont from 'unifont';
|
|
2
|
-
import type { FontFileReader
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import type { FontFileReader } from '../definitions.js';
|
|
3
|
+
import type { FamilyProperties, FontProvider, FontProviderInitContext, ResolveFontOptions, Style, Weight } from '../types.js';
|
|
4
|
+
type RawSource = string | URL | {
|
|
5
|
+
url: string | URL;
|
|
6
|
+
tech?: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
interface Variant extends FamilyProperties {
|
|
9
|
+
/**
|
|
10
|
+
* Font [sources](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src). It can be a path relative to the root, a package import or a URL. URLs are particularly useful if you inject local fonts through an integration.
|
|
11
|
+
*/
|
|
12
|
+
src: [RawSource, ...Array<RawSource>];
|
|
13
|
+
/**
|
|
14
|
+
* A [font weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight). If the associated font is a [variable font](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide), you can specify a range of weights:
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* weight: "100 900"
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
weight?: Weight | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
|
|
23
|
+
*/
|
|
24
|
+
style?: Style | undefined;
|
|
25
|
+
}
|
|
26
|
+
export interface LocalFamilyOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Each variant represents a [`@font-face` declaration](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/).
|
|
29
|
+
*/
|
|
30
|
+
variants: [Variant, ...Array<Variant>];
|
|
31
|
+
}
|
|
32
|
+
export declare class LocalFontProvider implements FontProvider<LocalFamilyOptions> {
|
|
33
|
+
#private;
|
|
34
|
+
name: string;
|
|
35
|
+
config?: Record<string, any> | undefined;
|
|
36
|
+
constructor({ fontFileReader, }: {
|
|
37
|
+
fontFileReader: FontFileReader;
|
|
38
|
+
});
|
|
39
|
+
init(context: Pick<FontProviderInitContext, 'root'>): void;
|
|
40
|
+
resolveFont(options: ResolveFontOptions<LocalFamilyOptions>): {
|
|
41
|
+
fonts: Array<unifont.FontFaceData>;
|
|
42
|
+
};
|
|
9
43
|
}
|
|
10
|
-
export declare function resolveLocalFont({ family, urlProxy, fontTypeExtractor, fontFileReader, }: Options): Array<unifont.FontFaceData>;
|
|
11
44
|
export {};
|