astro 5.16.13 → 5.16.15
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 +19 -236
- package/dist/assets/fonts/config.js +7 -23
- 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 +58 -429
- package/dist/core/config/schemas/base.js +2 -2
- package/dist/core/config/schemas/relative.d.ts +76 -541
- 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
package/components/Font.astro
CHANGED
|
@@ -4,8 +4,8 @@ import { filterPreloads } from '../dist/assets/fonts/core/filter-preloads.js';
|
|
|
4
4
|
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
|
|
5
5
|
|
|
6
6
|
// TODO: remove check when fonts are stabilized
|
|
7
|
-
const {
|
|
8
|
-
if (!
|
|
7
|
+
const { componentDataByCssVariable } = mod;
|
|
8
|
+
if (!componentDataByCssVariable) {
|
|
9
9
|
throw new AstroError(AstroErrorData.ExperimentalFontsNotEnabled);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ interface Props {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const { cssVariable, preload = false } = Astro.props as Props;
|
|
20
|
-
const data =
|
|
20
|
+
const data = componentDataByCssVariable.get(cssVariable);
|
|
21
21
|
if (!data) {
|
|
22
22
|
throw new AstroError({
|
|
23
23
|
...AstroErrorData.FontFamilyNotFound,
|
|
@@ -25,7 +25,7 @@ if (!data) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const filteredPreloadData = filterPreloads(data.
|
|
28
|
+
const filteredPreloadData = filterPreloads(data.preloads, preload);
|
|
29
29
|
---
|
|
30
30
|
|
|
31
31
|
<style set:html={data.css}></style>
|
|
@@ -1,208 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import type { FontProvider } from './types.js';
|
|
2
3
|
export declare const weightSchema: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
3
4
|
export declare const styleSchema: z.ZodEnum<["normal", "italic", "oblique"]>;
|
|
4
5
|
export declare const displaySchema: z.ZodEnum<["auto", "block", "swap", "fallback", "optional"]>;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
src: z.ZodArray<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>, z.ZodObject<{
|
|
9
|
-
url: z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>;
|
|
10
|
-
tech: z.ZodOptional<z.ZodString>;
|
|
11
|
-
}, "strict", z.ZodTypeAny, {
|
|
12
|
-
url: string | URL;
|
|
13
|
-
tech?: string | undefined;
|
|
14
|
-
}, {
|
|
15
|
-
url: string | URL;
|
|
16
|
-
tech?: string | undefined;
|
|
17
|
-
}>]>, "atleastone">;
|
|
18
|
-
weight: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
19
|
-
style: z.ZodOptional<z.ZodEnum<["normal", "italic", "oblique"]>>;
|
|
20
|
-
display: z.ZodOptional<z.ZodEnum<["auto", "block", "swap", "fallback", "optional"]>>;
|
|
21
|
-
stretch: z.ZodOptional<z.ZodString>;
|
|
22
|
-
featureSettings: z.ZodOptional<z.ZodString>;
|
|
23
|
-
variationSettings: z.ZodOptional<z.ZodString>;
|
|
24
|
-
unicodeRange: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
|
|
25
|
-
}, "strict", z.ZodTypeAny, {
|
|
26
|
-
src: [string | URL | {
|
|
27
|
-
url: string | URL;
|
|
28
|
-
tech?: string | undefined;
|
|
29
|
-
}, ...(string | URL | {
|
|
30
|
-
url: string | URL;
|
|
31
|
-
tech?: string | undefined;
|
|
32
|
-
})[]];
|
|
33
|
-
weight?: string | number | undefined;
|
|
34
|
-
style?: "normal" | "italic" | "oblique" | undefined;
|
|
35
|
-
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
36
|
-
stretch?: string | undefined;
|
|
37
|
-
featureSettings?: string | undefined;
|
|
38
|
-
variationSettings?: string | undefined;
|
|
39
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
40
|
-
}, {
|
|
41
|
-
src: [string | URL | {
|
|
42
|
-
url: string | URL;
|
|
43
|
-
tech?: string | undefined;
|
|
44
|
-
}, ...(string | URL | {
|
|
45
|
-
url: string | URL;
|
|
46
|
-
tech?: string | undefined;
|
|
47
|
-
})[]];
|
|
48
|
-
weight?: string | number | undefined;
|
|
49
|
-
style?: "normal" | "italic" | "oblique" | undefined;
|
|
50
|
-
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
51
|
-
stretch?: string | undefined;
|
|
52
|
-
featureSettings?: string | undefined;
|
|
53
|
-
variationSettings?: string | undefined;
|
|
54
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
55
|
-
}>, "atleastone">;
|
|
56
|
-
fallbacks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
57
|
-
optimizedFallbacks: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
-
name: z.ZodString;
|
|
59
|
-
cssVariable: z.ZodString;
|
|
60
|
-
}, "strict", z.ZodTypeAny, {
|
|
61
|
-
name: string;
|
|
62
|
-
cssVariable: string;
|
|
63
|
-
provider: "local";
|
|
64
|
-
variants: [{
|
|
65
|
-
src: [string | URL | {
|
|
66
|
-
url: string | URL;
|
|
67
|
-
tech?: string | undefined;
|
|
68
|
-
}, ...(string | URL | {
|
|
69
|
-
url: string | URL;
|
|
70
|
-
tech?: string | undefined;
|
|
71
|
-
})[]];
|
|
72
|
-
weight?: string | number | undefined;
|
|
73
|
-
style?: "normal" | "italic" | "oblique" | undefined;
|
|
74
|
-
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
75
|
-
stretch?: string | undefined;
|
|
76
|
-
featureSettings?: string | undefined;
|
|
77
|
-
variationSettings?: string | undefined;
|
|
78
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
79
|
-
}, ...{
|
|
80
|
-
src: [string | URL | {
|
|
81
|
-
url: string | URL;
|
|
82
|
-
tech?: string | undefined;
|
|
83
|
-
}, ...(string | URL | {
|
|
84
|
-
url: string | URL;
|
|
85
|
-
tech?: string | undefined;
|
|
86
|
-
})[]];
|
|
87
|
-
weight?: string | number | undefined;
|
|
88
|
-
style?: "normal" | "italic" | "oblique" | undefined;
|
|
89
|
-
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
90
|
-
stretch?: string | undefined;
|
|
91
|
-
featureSettings?: string | undefined;
|
|
92
|
-
variationSettings?: string | undefined;
|
|
93
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
94
|
-
}[]];
|
|
95
|
-
fallbacks?: string[] | undefined;
|
|
96
|
-
optimizedFallbacks?: boolean | undefined;
|
|
97
|
-
}, {
|
|
98
|
-
name: string;
|
|
99
|
-
cssVariable: string;
|
|
100
|
-
provider: "local";
|
|
101
|
-
variants: [{
|
|
102
|
-
src: [string | URL | {
|
|
103
|
-
url: string | URL;
|
|
104
|
-
tech?: string | undefined;
|
|
105
|
-
}, ...(string | URL | {
|
|
106
|
-
url: string | URL;
|
|
107
|
-
tech?: string | undefined;
|
|
108
|
-
})[]];
|
|
109
|
-
weight?: string | number | undefined;
|
|
110
|
-
style?: "normal" | "italic" | "oblique" | undefined;
|
|
111
|
-
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
112
|
-
stretch?: string | undefined;
|
|
113
|
-
featureSettings?: string | undefined;
|
|
114
|
-
variationSettings?: string | undefined;
|
|
115
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
116
|
-
}, ...{
|
|
117
|
-
src: [string | URL | {
|
|
118
|
-
url: string | URL;
|
|
119
|
-
tech?: string | undefined;
|
|
120
|
-
}, ...(string | URL | {
|
|
121
|
-
url: string | URL;
|
|
122
|
-
tech?: string | undefined;
|
|
123
|
-
})[]];
|
|
124
|
-
weight?: string | number | undefined;
|
|
125
|
-
style?: "normal" | "italic" | "oblique" | undefined;
|
|
126
|
-
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
127
|
-
stretch?: string | undefined;
|
|
128
|
-
featureSettings?: string | undefined;
|
|
129
|
-
variationSettings?: string | undefined;
|
|
130
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
131
|
-
}[]];
|
|
132
|
-
fallbacks?: string[] | undefined;
|
|
133
|
-
optimizedFallbacks?: boolean | undefined;
|
|
134
|
-
}>;
|
|
135
|
-
export declare const fontProviderSchema: z.ZodObject<{
|
|
136
|
-
name: z.ZodString;
|
|
137
|
-
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
138
|
-
init: z.ZodOptional<z.ZodType<((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined, z.ZodTypeDef, ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined>>;
|
|
139
|
-
resolveFont: z.ZodType<(options: import("./types.js").ResolveFontOptions<never>) => {
|
|
140
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
141
|
-
} | Promise<{
|
|
142
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
143
|
-
} | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions<never>) => {
|
|
144
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
145
|
-
} | Promise<{
|
|
146
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
147
|
-
} | undefined> | undefined>;
|
|
148
|
-
listFonts: z.ZodOptional<z.ZodType<(() => string[] | Promise<string[] | undefined> | undefined) | undefined, z.ZodTypeDef, (() => string[] | Promise<string[] | undefined> | undefined) | undefined>>;
|
|
149
|
-
}, "strict", z.ZodTypeAny, {
|
|
150
|
-
name: string;
|
|
151
|
-
resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
|
|
152
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
153
|
-
} | Promise<{
|
|
154
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
155
|
-
} | undefined> | undefined;
|
|
156
|
-
config?: Record<string, any> | undefined;
|
|
157
|
-
init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
|
|
158
|
-
listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
|
|
159
|
-
}, {
|
|
160
|
-
name: string;
|
|
161
|
-
resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
|
|
162
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
163
|
-
} | Promise<{
|
|
164
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
165
|
-
} | undefined> | undefined;
|
|
166
|
-
config?: Record<string, any> | undefined;
|
|
167
|
-
init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
|
|
168
|
-
listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
|
|
169
|
-
}>;
|
|
170
|
-
export declare const remoteFontFamilySchema: z.ZodObject<{
|
|
171
|
-
provider: z.ZodObject<{
|
|
172
|
-
name: z.ZodString;
|
|
173
|
-
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
174
|
-
init: z.ZodOptional<z.ZodType<((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined, z.ZodTypeDef, ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined>>;
|
|
175
|
-
resolveFont: z.ZodType<(options: import("./types.js").ResolveFontOptions<never>) => {
|
|
176
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
177
|
-
} | Promise<{
|
|
178
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
179
|
-
} | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions<never>) => {
|
|
180
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
181
|
-
} | Promise<{
|
|
182
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
183
|
-
} | undefined> | undefined>;
|
|
184
|
-
listFonts: z.ZodOptional<z.ZodType<(() => string[] | Promise<string[] | undefined> | undefined) | undefined, z.ZodTypeDef, (() => string[] | Promise<string[] | undefined> | undefined) | undefined>>;
|
|
185
|
-
}, "strict", z.ZodTypeAny, {
|
|
186
|
-
name: string;
|
|
187
|
-
resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
|
|
188
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
189
|
-
} | Promise<{
|
|
190
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
191
|
-
} | undefined> | undefined;
|
|
192
|
-
config?: Record<string, any> | undefined;
|
|
193
|
-
init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
|
|
194
|
-
listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
|
|
195
|
-
}, {
|
|
196
|
-
name: string;
|
|
197
|
-
resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
|
|
198
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
199
|
-
} | Promise<{
|
|
200
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
201
|
-
} | undefined> | undefined;
|
|
202
|
-
config?: Record<string, any> | undefined;
|
|
203
|
-
init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
|
|
204
|
-
listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
|
|
205
|
-
}>;
|
|
6
|
+
export declare const fontProviderSchema: z.ZodType<FontProvider<never>, z.ZodTypeDef, FontProvider<never>>;
|
|
7
|
+
export declare const fontFamilySchema: z.ZodObject<{
|
|
8
|
+
provider: z.ZodType<FontProvider<never>, z.ZodTypeDef, FontProvider<never>>;
|
|
206
9
|
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
207
10
|
weights: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "atleastone">>;
|
|
208
11
|
styles: z.ZodOptional<z.ZodArray<z.ZodEnum<["normal", "italic", "oblique"]>, "atleastone">>;
|
|
@@ -220,53 +23,33 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
|
|
|
220
23
|
}, "strict", z.ZodTypeAny, {
|
|
221
24
|
name: string;
|
|
222
25
|
cssVariable: string;
|
|
223
|
-
provider:
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
config?: Record<string, any> | undefined;
|
|
231
|
-
init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
|
|
232
|
-
listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
|
|
233
|
-
};
|
|
234
|
-
options?: Record<string, any> | undefined;
|
|
26
|
+
provider: FontProvider<never>;
|
|
27
|
+
weights?: [string | number, ...(string | number)[]] | undefined;
|
|
28
|
+
styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
|
|
29
|
+
subsets?: [string, ...string[]] | undefined;
|
|
30
|
+
fallbacks?: string[] | undefined;
|
|
31
|
+
optimizedFallbacks?: boolean | undefined;
|
|
32
|
+
formats?: ["woff2" | "woff" | "otf" | "ttf" | "eot", ...("woff2" | "woff" | "otf" | "ttf" | "eot")[]] | undefined;
|
|
235
33
|
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
236
34
|
stretch?: string | undefined;
|
|
237
35
|
featureSettings?: string | undefined;
|
|
238
36
|
variationSettings?: string | undefined;
|
|
239
37
|
unicodeRange?: [string, ...string[]] | undefined;
|
|
240
|
-
|
|
241
|
-
|
|
38
|
+
options?: Record<string, any> | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
name: string;
|
|
41
|
+
cssVariable: string;
|
|
42
|
+
provider: FontProvider<never>;
|
|
242
43
|
weights?: [string | number, ...(string | number)[]] | undefined;
|
|
243
44
|
styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
|
|
244
45
|
subsets?: [string, ...string[]] | undefined;
|
|
46
|
+
fallbacks?: string[] | undefined;
|
|
47
|
+
optimizedFallbacks?: boolean | undefined;
|
|
245
48
|
formats?: ["woff2" | "woff" | "otf" | "ttf" | "eot", ...("woff2" | "woff" | "otf" | "ttf" | "eot")[]] | undefined;
|
|
246
|
-
}, {
|
|
247
|
-
name: string;
|
|
248
|
-
cssVariable: string;
|
|
249
|
-
provider: {
|
|
250
|
-
name: string;
|
|
251
|
-
resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
|
|
252
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
253
|
-
} | Promise<{
|
|
254
|
-
fonts: Array<import("unifont").FontFaceData>;
|
|
255
|
-
} | undefined> | undefined;
|
|
256
|
-
config?: Record<string, any> | undefined;
|
|
257
|
-
init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
|
|
258
|
-
listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
|
|
259
|
-
};
|
|
260
|
-
options?: Record<string, any> | undefined;
|
|
261
49
|
display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
|
|
262
50
|
stretch?: string | undefined;
|
|
263
51
|
featureSettings?: string | undefined;
|
|
264
52
|
variationSettings?: string | undefined;
|
|
265
53
|
unicodeRange?: [string, ...string[]] | undefined;
|
|
266
|
-
|
|
267
|
-
optimizedFallbacks?: boolean | undefined;
|
|
268
|
-
weights?: [string | number, ...(string | number)[]] | undefined;
|
|
269
|
-
styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
|
|
270
|
-
subsets?: [string, ...string[]] | undefined;
|
|
271
|
-
formats?: ["woff2" | "woff" | "otf" | "ttf" | "eot", ...("woff2" | "woff" | "otf" | "ttf" | "eot")[]] | undefined;
|
|
54
|
+
options?: Record<string, any> | undefined;
|
|
272
55
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { FONT_TYPES
|
|
2
|
+
import { FONT_TYPES } from "./constants.js";
|
|
3
3
|
const weightSchema = z.union([z.string(), z.number()]);
|
|
4
4
|
const styleSchema = z.enum(["normal", "italic", "oblique"]);
|
|
5
5
|
const displaySchema = z.enum(["auto", "block", "swap", "fallback", "optional"]);
|
|
@@ -20,32 +20,17 @@ const requiredFamilyAttributesSchema = z.object({
|
|
|
20
20
|
name: z.string(),
|
|
21
21
|
cssVariable: z.string()
|
|
22
22
|
});
|
|
23
|
-
const
|
|
24
|
-
const localFontFamilySchema = z.object({
|
|
25
|
-
...requiredFamilyAttributesSchema.shape,
|
|
26
|
-
...fallbacksSchema.shape,
|
|
27
|
-
provider: z.literal(LOCAL_PROVIDER_NAME),
|
|
28
|
-
variants: z.array(
|
|
29
|
-
z.object({
|
|
30
|
-
...familyPropertiesSchema.shape,
|
|
31
|
-
src: z.array(
|
|
32
|
-
z.union([
|
|
33
|
-
entrypointSchema,
|
|
34
|
-
z.object({ url: entrypointSchema, tech: z.string().optional() }).strict()
|
|
35
|
-
])
|
|
36
|
-
).nonempty()
|
|
37
|
-
// TODO: find a way to support subsets (through fontkit?)
|
|
38
|
-
}).strict()
|
|
39
|
-
).nonempty()
|
|
40
|
-
}).strict();
|
|
41
|
-
const fontProviderSchema = z.object({
|
|
23
|
+
const _fontProviderSchema = z.object({
|
|
42
24
|
name: z.string(),
|
|
43
25
|
config: z.record(z.string(), z.any()).optional(),
|
|
44
26
|
init: z.custom((v) => typeof v === "function").optional(),
|
|
45
27
|
resolveFont: z.custom((v) => typeof v === "function"),
|
|
46
28
|
listFonts: z.custom((v) => typeof v === "function").optional()
|
|
47
29
|
}).strict();
|
|
48
|
-
const
|
|
30
|
+
const fontProviderSchema = z.custom((v) => {
|
|
31
|
+
return _fontProviderSchema.safeParse(v).success;
|
|
32
|
+
}, "Invalid FontProvider object");
|
|
33
|
+
const fontFamilySchema = z.object({
|
|
49
34
|
...requiredFamilyAttributesSchema.shape,
|
|
50
35
|
...fallbacksSchema.shape,
|
|
51
36
|
...familyPropertiesSchema.omit({
|
|
@@ -61,9 +46,8 @@ const remoteFontFamilySchema = z.object({
|
|
|
61
46
|
}).strict();
|
|
62
47
|
export {
|
|
63
48
|
displaySchema,
|
|
49
|
+
fontFamilySchema,
|
|
64
50
|
fontProviderSchema,
|
|
65
|
-
localFontFamilySchema,
|
|
66
|
-
remoteFontFamilySchema,
|
|
67
51
|
styleSchema,
|
|
68
52
|
weightSchema
|
|
69
53
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Defaults, FontType } from './types.js';
|
|
2
|
-
export declare const LOCAL_PROVIDER_NAME = "local";
|
|
3
2
|
export declare const DEFAULTS: Defaults;
|
|
4
3
|
export declare const VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/internal";
|
|
5
4
|
export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const LOCAL_PROVIDER_NAME = "local";
|
|
2
1
|
const DEFAULTS = {
|
|
3
2
|
weights: ["400"],
|
|
4
3
|
styles: ["normal", "italic"],
|
|
@@ -49,7 +48,6 @@ export {
|
|
|
49
48
|
FONT_FORMATS,
|
|
50
49
|
FONT_TYPES,
|
|
51
50
|
GENERIC_FALLBACK_NAMES,
|
|
52
|
-
LOCAL_PROVIDER_NAME,
|
|
53
51
|
RESOLVED_BUFFER_VIRTUAL_MODULE_ID_PREFIX,
|
|
54
52
|
RESOLVED_RUNTIME_VIRTUAL_MODULE_ID,
|
|
55
53
|
RESOLVED_VIRTUAL_MODULE_ID,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CssRenderer } from '../definitions.js';
|
|
2
|
+
import type { Collaborator, ComponentDataByCssVariable, Defaults, FontFamilyAssets } from '../types.js';
|
|
3
|
+
import type { optimizeFallbacks as _optimizeFallbacks } from './optimize-fallbacks.js';
|
|
4
|
+
export declare function collectComponentData({ fontFamilyAssets, cssRenderer, defaults, optimizeFallbacks, }: {
|
|
5
|
+
fontFamilyAssets: Array<FontFamilyAssets>;
|
|
6
|
+
cssRenderer: CssRenderer;
|
|
7
|
+
defaults: Pick<Defaults, 'fallbacks' | 'optimizedFallbacks'>;
|
|
8
|
+
optimizeFallbacks: Collaborator<typeof _optimizeFallbacks, 'family' | 'fallbacks' | 'collectedFonts'>;
|
|
9
|
+
}): Promise<ComponentDataByCssVariable>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { unifontFontFaceDataToProperties } from "../utils.js";
|
|
2
|
+
async function collectComponentData({
|
|
3
|
+
fontFamilyAssets,
|
|
4
|
+
cssRenderer,
|
|
5
|
+
defaults,
|
|
6
|
+
optimizeFallbacks
|
|
7
|
+
}) {
|
|
8
|
+
const componentDataByCssVariable = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const { family, fonts, collectedFontsForMetricsByUniqueKey, preloads } of fontFamilyAssets) {
|
|
10
|
+
let css = "";
|
|
11
|
+
for (const data of fonts) {
|
|
12
|
+
css += cssRenderer.generateFontFace(
|
|
13
|
+
family.uniqueName,
|
|
14
|
+
unifontFontFaceDataToProperties({
|
|
15
|
+
src: data.src,
|
|
16
|
+
weight: data.weight,
|
|
17
|
+
style: data.style,
|
|
18
|
+
// User settings override the generated font settings
|
|
19
|
+
display: data.display ?? family.display,
|
|
20
|
+
unicodeRange: data.unicodeRange ?? family.unicodeRange,
|
|
21
|
+
stretch: data.stretch ?? family.stretch,
|
|
22
|
+
featureSettings: data.featureSettings ?? family.featureSettings,
|
|
23
|
+
variationSettings: data.variationSettings ?? family.variationSettings
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const fallbacks = family.fallbacks ?? defaults.fallbacks;
|
|
28
|
+
const cssVarValues = [family.uniqueName];
|
|
29
|
+
const optimizeFallbacksResult = family.optimizedFallbacks ?? defaults.optimizedFallbacks ? await optimizeFallbacks({
|
|
30
|
+
family,
|
|
31
|
+
fallbacks,
|
|
32
|
+
collectedFonts: Array.from(collectedFontsForMetricsByUniqueKey.values())
|
|
33
|
+
}) : null;
|
|
34
|
+
if (optimizeFallbacksResult) {
|
|
35
|
+
css += optimizeFallbacksResult.css;
|
|
36
|
+
cssVarValues.push(...optimizeFallbacksResult.fallbacks);
|
|
37
|
+
} else {
|
|
38
|
+
cssVarValues.push(...fallbacks);
|
|
39
|
+
}
|
|
40
|
+
css += cssRenderer.generateCssVariable(family.cssVariable, cssVarValues);
|
|
41
|
+
componentDataByCssVariable.set(family.cssVariable, { preloads, css });
|
|
42
|
+
}
|
|
43
|
+
return componentDataByCssVariable;
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
collectComponentData
|
|
47
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as unifont from 'unifont';
|
|
2
|
+
import type { FontFileIdGenerator, Hasher } from '../definitions.js';
|
|
3
|
+
import type { Defaults, FontFileById, PreloadData, ResolvedFontFamily } from '../types.js';
|
|
4
|
+
import type { CollectedFontForMetrics } from './optimize-fallbacks.js';
|
|
5
|
+
export declare function collectFontAssetsFromFaces({ fonts, fontFileIdGenerator, family, fontFilesIds, collectedFontsIds, hasher, defaults, }: {
|
|
6
|
+
fonts: Array<unifont.FontFaceData>;
|
|
7
|
+
fontFileIdGenerator: FontFileIdGenerator;
|
|
8
|
+
family: Pick<ResolvedFontFamily, 'cssVariable' | 'fallbacks'>;
|
|
9
|
+
fontFilesIds: Set<string>;
|
|
10
|
+
collectedFontsIds: Set<string>;
|
|
11
|
+
hasher: Hasher;
|
|
12
|
+
defaults: Pick<Defaults, 'fallbacks'>;
|
|
13
|
+
}): {
|
|
14
|
+
fontFileById: FontFileById;
|
|
15
|
+
preloads: PreloadData[];
|
|
16
|
+
collectedFontsForMetricsByUniqueKey: Map<string, CollectedFontForMetrics>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FONT_FORMATS } from "../constants.js";
|
|
2
|
+
import { renderFontWeight } from "../utils.js";
|
|
3
|
+
function collectFontAssetsFromFaces({
|
|
4
|
+
fonts,
|
|
5
|
+
fontFileIdGenerator,
|
|
6
|
+
family,
|
|
7
|
+
fontFilesIds,
|
|
8
|
+
collectedFontsIds,
|
|
9
|
+
hasher,
|
|
10
|
+
defaults
|
|
11
|
+
}) {
|
|
12
|
+
const fontFileById = /* @__PURE__ */ new Map();
|
|
13
|
+
const collectedFontsForMetricsByUniqueKey = /* @__PURE__ */ new Map();
|
|
14
|
+
const preloads = [];
|
|
15
|
+
for (const font of fonts) {
|
|
16
|
+
let index = 0;
|
|
17
|
+
for (const source of font.src) {
|
|
18
|
+
if ("name" in source) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const format = FONT_FORMATS.find((e) => e.format === source.format);
|
|
22
|
+
const originalUrl = source.originalURL;
|
|
23
|
+
const id = fontFileIdGenerator.generate({
|
|
24
|
+
cssVariable: family.cssVariable,
|
|
25
|
+
font,
|
|
26
|
+
originalUrl,
|
|
27
|
+
type: format.type
|
|
28
|
+
});
|
|
29
|
+
if (!fontFilesIds.has(id) && !fontFileById.has(id)) {
|
|
30
|
+
fontFileById.set(id, { url: originalUrl, init: font.meta?.init });
|
|
31
|
+
if (index === 0) {
|
|
32
|
+
preloads.push({
|
|
33
|
+
style: font.style,
|
|
34
|
+
subset: font.meta?.subset,
|
|
35
|
+
type: format.type,
|
|
36
|
+
url: source.url,
|
|
37
|
+
weight: renderFontWeight(font.weight)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const collected = {
|
|
42
|
+
id,
|
|
43
|
+
url: originalUrl,
|
|
44
|
+
init: font.meta?.init,
|
|
45
|
+
data: {
|
|
46
|
+
weight: font.weight,
|
|
47
|
+
style: font.style,
|
|
48
|
+
meta: {
|
|
49
|
+
subset: font.meta?.subset
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const collectedKey = hasher.hashObject(collected.data);
|
|
54
|
+
const fallbacks = family.fallbacks ?? defaults.fallbacks;
|
|
55
|
+
if (fallbacks.length > 0 && // If the same data has already been sent for this family, we don't want to have
|
|
56
|
+
// duplicated fallbacks. Such scenario can occur with unicode ranges.
|
|
57
|
+
!collectedFontsIds.has(collectedKey) && !collectedFontsForMetricsByUniqueKey.has(collectedKey)) {
|
|
58
|
+
collectedFontsForMetricsByUniqueKey.set(collectedKey, collected);
|
|
59
|
+
}
|
|
60
|
+
index++;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
fontFileById,
|
|
65
|
+
preloads,
|
|
66
|
+
collectedFontsForMetricsByUniqueKey
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
collectFontAssetsFromFaces
|
|
71
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { renderFontWeight } from "../utils.js";
|
|
2
|
+
function collectFontData(fontFamilyAssets) {
|
|
3
|
+
const fontDataByCssVariable = {};
|
|
4
|
+
for (const { family, fonts } of fontFamilyAssets) {
|
|
5
|
+
const fontData = [];
|
|
6
|
+
for (const data of fonts) {
|
|
7
|
+
fontData.push({
|
|
8
|
+
weight: renderFontWeight(data.weight),
|
|
9
|
+
style: data.style,
|
|
10
|
+
src: data.src.filter((src) => "url" in src).map((src) => ({
|
|
11
|
+
url: src.url,
|
|
12
|
+
format: src.format,
|
|
13
|
+
tech: src.tech
|
|
14
|
+
}))
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
fontDataByCssVariable[family.cssVariable] = fontData;
|
|
18
|
+
}
|
|
19
|
+
return fontDataByCssVariable;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
collectFontData
|
|
23
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Logger } from '../../../core/logger/core.js';
|
|
2
|
+
import type { FontResolver, StringMatcher } from '../definitions.js';
|
|
3
|
+
import type { Collaborator, Defaults, FontFileById, ResolvedFontFamily } from '../types.js';
|
|
4
|
+
import type { collectFontAssetsFromFaces as _collectFontAssetsFromFaces } from './collect-font-assets-from-faces.js';
|
|
5
|
+
import type { filterAndTransformFontFaces as _filterAndTransformFontFaces } from './filter-and-transform-font-faces.js';
|
|
6
|
+
import type { getOrCreateFontFamilyAssets as _getOrCreateFontFamilyAssets } from './get-or-create-font-family-assets.js';
|
|
7
|
+
export declare function computeFontFamiliesAssets({ resolvedFamilies, fontResolver, logger, bold, defaults, stringMatcher, getOrCreateFontFamilyAssets, collectFontAssetsFromFaces, filterAndTransformFontFaces, }: {
|
|
8
|
+
resolvedFamilies: Array<ResolvedFontFamily>;
|
|
9
|
+
fontResolver: FontResolver;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
bold: (input: string) => string;
|
|
12
|
+
defaults: Defaults;
|
|
13
|
+
stringMatcher: StringMatcher;
|
|
14
|
+
getOrCreateFontFamilyAssets: Collaborator<typeof _getOrCreateFontFamilyAssets, 'family' | 'fontFamilyAssetsByUniqueKey'>;
|
|
15
|
+
filterAndTransformFontFaces: Collaborator<typeof _filterAndTransformFontFaces, 'family' | 'fonts'>;
|
|
16
|
+
collectFontAssetsFromFaces: Collaborator<typeof _collectFontAssetsFromFaces, 'family' | 'fonts' | 'collectedFontsIds' | 'fontFilesIds'>;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
fontFamilyAssets: import("../types.js").FontFamilyAssets[];
|
|
19
|
+
fontFileById: FontFileById;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
async function computeFontFamiliesAssets({
|
|
2
|
+
resolvedFamilies,
|
|
3
|
+
fontResolver,
|
|
4
|
+
logger,
|
|
5
|
+
bold,
|
|
6
|
+
defaults,
|
|
7
|
+
stringMatcher,
|
|
8
|
+
getOrCreateFontFamilyAssets,
|
|
9
|
+
collectFontAssetsFromFaces,
|
|
10
|
+
filterAndTransformFontFaces
|
|
11
|
+
}) {
|
|
12
|
+
const fontFamilyAssetsByUniqueKey = /* @__PURE__ */ new Map();
|
|
13
|
+
const fontFileById = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const family of resolvedFamilies) {
|
|
15
|
+
const fontAssets = getOrCreateFontFamilyAssets({
|
|
16
|
+
fontFamilyAssetsByUniqueKey,
|
|
17
|
+
family
|
|
18
|
+
});
|
|
19
|
+
const _fonts = await fontResolver.resolveFont({
|
|
20
|
+
familyName: family.name,
|
|
21
|
+
provider: family.provider,
|
|
22
|
+
// We do not merge the defaults, we only provide defaults as a fallback
|
|
23
|
+
weights: family.weights ?? defaults.weights,
|
|
24
|
+
styles: family.styles ?? defaults.styles,
|
|
25
|
+
subsets: family.subsets ?? defaults.subsets,
|
|
26
|
+
formats: family.formats ?? defaults.formats,
|
|
27
|
+
options: family.options
|
|
28
|
+
});
|
|
29
|
+
if (_fonts.length === 0) {
|
|
30
|
+
logger.warn(
|
|
31
|
+
"assets",
|
|
32
|
+
`No data found for font family ${bold(family.name)}. Review your configuration`
|
|
33
|
+
);
|
|
34
|
+
const availableFamilies = await fontResolver.listFonts({ provider: family.provider });
|
|
35
|
+
if (availableFamilies && availableFamilies.length > 0 && !availableFamilies.includes(family.name)) {
|
|
36
|
+
logger.warn(
|
|
37
|
+
"assets",
|
|
38
|
+
`${bold(family.name)} font family cannot be retrieved by the provider. Did you mean ${bold(stringMatcher.getClosestMatch(family.name, availableFamilies))}?`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
fontAssets.fonts.push(
|
|
44
|
+
...filterAndTransformFontFaces({
|
|
45
|
+
fonts: _fonts,
|
|
46
|
+
family
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
const result = collectFontAssetsFromFaces({
|
|
50
|
+
fonts: fontAssets.fonts,
|
|
51
|
+
family,
|
|
52
|
+
fontFilesIds: new Set(fontFileById.keys()),
|
|
53
|
+
collectedFontsIds: new Set(fontAssets.collectedFontsForMetricsByUniqueKey.keys())
|
|
54
|
+
});
|
|
55
|
+
for (const [key, value] of result.fontFileById.entries()) {
|
|
56
|
+
fontFileById.set(key, value);
|
|
57
|
+
}
|
|
58
|
+
for (const [key, value] of result.collectedFontsForMetricsByUniqueKey.entries()) {
|
|
59
|
+
fontAssets.collectedFontsForMetricsByUniqueKey.set(key, value);
|
|
60
|
+
}
|
|
61
|
+
fontAssets.preloads.push(...result.preloads);
|
|
62
|
+
}
|
|
63
|
+
return { fontFamilyAssets: Array.from(fontFamilyAssetsByUniqueKey.values()), fontFileById };
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
computeFontFamiliesAssets
|
|
67
|
+
};
|