astro 5.7.10 → 5.7.12
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/ClientRouter.astro +18 -7
- package/dist/assets/fonts/config.d.ts +33 -32
- package/dist/assets/fonts/config.js +15 -9
- package/dist/assets/fonts/constants.d.ts +5 -2
- package/dist/assets/fonts/constants.js +8 -8
- package/dist/assets/fonts/definitions.d.ts +14 -1
- package/dist/assets/fonts/implementations/error-handler.js +8 -0
- package/dist/assets/fonts/implementations/font-file-reader.d.ts +4 -0
- package/dist/assets/fonts/implementations/font-file-reader.js +26 -0
- package/dist/assets/fonts/implementations/font-metrics-resolver.js +2 -2
- package/dist/assets/fonts/implementations/url-proxy.d.ts +2 -3
- package/dist/assets/fonts/implementations/url-proxy.js +2 -4
- package/dist/assets/fonts/logic/normalize-remote-font-faces.d.ts +3 -2
- package/dist/assets/fonts/logic/normalize-remote-font-faces.js +7 -3
- package/dist/assets/fonts/logic/resolve-families.js +1 -1
- package/dist/assets/fonts/orchestrate.d.ts +5 -2
- package/dist/assets/fonts/orchestrate.js +12 -2
- package/dist/assets/fonts/providers/local.d.ts +3 -2
- package/dist/assets/fonts/providers/local.js +47 -28
- package/dist/assets/fonts/types.d.ts +3 -2
- package/dist/assets/fonts/utils.js +1 -1
- package/dist/assets/fonts/vite-plugin-fonts.js +5 -2
- package/dist/content/content-layer.js +3 -3
- package/dist/content/loaders/file.js +9 -4
- package/dist/core/config/schemas/base.d.ts +54 -54
- package/dist/core/config/schemas/relative.d.ts +68 -68
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +13 -0
- package/dist/core/errors/errors-data.js +7 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.js +0 -1
- package/package.json +5 -4
- package/types/content.d.ts +1 -16
|
@@ -37,6 +37,7 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
37
37
|
import { init } from 'astro/virtual-modules/prefetch.js';
|
|
38
38
|
|
|
39
39
|
type Fallback = 'none' | 'animate' | 'swap';
|
|
40
|
+
let lastClickedElementLeavingWindow: EventTarget | null = null;
|
|
40
41
|
|
|
41
42
|
function getFallback(): Fallback {
|
|
42
43
|
const el = document.querySelector('[name="astro-view-transitions-fallback"]');
|
|
@@ -50,6 +51,13 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
50
51
|
return el.dataset.astroReload !== undefined;
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
const leavesWindow = (ev: MouseEvent) =>
|
|
55
|
+
(ev.button && ev.button !== 0) || // left clicks only
|
|
56
|
+
ev.metaKey || // new tab (mac)
|
|
57
|
+
ev.ctrlKey || // new tab (windows)
|
|
58
|
+
ev.altKey || // download
|
|
59
|
+
ev.shiftKey; // new window
|
|
60
|
+
|
|
53
61
|
if (supportsViewTransitions || getFallback() !== 'none') {
|
|
54
62
|
if (import.meta.env.DEV && window.matchMedia('(prefers-reduced-motion)').matches) {
|
|
55
63
|
console.warn(
|
|
@@ -58,6 +66,9 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
58
66
|
}
|
|
59
67
|
document.addEventListener('click', (ev) => {
|
|
60
68
|
let link = ev.target;
|
|
69
|
+
|
|
70
|
+
lastClickedElementLeavingWindow = leavesWindow(ev) ? link : null;
|
|
71
|
+
|
|
61
72
|
if (ev.composed) {
|
|
62
73
|
link = ev.composedPath()[0];
|
|
63
74
|
}
|
|
@@ -82,11 +93,7 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
82
93
|
!link.href ||
|
|
83
94
|
(linkTarget && linkTarget !== '_self') ||
|
|
84
95
|
origin !== location.origin ||
|
|
85
|
-
|
|
86
|
-
ev.metaKey || // new tab (mac)
|
|
87
|
-
ev.ctrlKey || // new tab (windows)
|
|
88
|
-
ev.altKey || // download
|
|
89
|
-
ev.shiftKey || // new window
|
|
96
|
+
lastClickedElementLeavingWindow ||
|
|
90
97
|
ev.defaultPrevented
|
|
91
98
|
) {
|
|
92
99
|
// No page transitions in these cases,
|
|
@@ -102,11 +109,15 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
102
109
|
|
|
103
110
|
document.addEventListener('submit', (ev) => {
|
|
104
111
|
let el = ev.target as HTMLElement;
|
|
105
|
-
|
|
112
|
+
const submitter = ev.submitter;
|
|
113
|
+
|
|
114
|
+
const clickedWithKeys = submitter && submitter === lastClickedElementLeavingWindow;
|
|
115
|
+
lastClickedElementLeavingWindow = null;
|
|
116
|
+
|
|
117
|
+
if (el.tagName !== 'FORM' || ev.defaultPrevented || isReloadEl(el) || clickedWithKeys) {
|
|
106
118
|
return;
|
|
107
119
|
}
|
|
108
120
|
const form = el as HTMLFormElement;
|
|
109
|
-
const submitter = ev.submitter;
|
|
110
121
|
const formData = new FormData(form, submitter);
|
|
111
122
|
// form.action and form.method can point to an <input name="action"> or <input name="method">
|
|
112
123
|
// in which case should fallback to the form attribute
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export declare const styleSchema: z.ZodEnum<["normal", "italic", "oblique"]>;
|
|
2
3
|
export declare const fontProviderSchema: z.ZodObject<{
|
|
3
4
|
/**
|
|
4
5
|
* URL, path relative to the root or package import.
|
|
@@ -66,21 +67,17 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
66
67
|
* weight: "100 900"
|
|
67
68
|
* ```
|
|
68
69
|
*/
|
|
69
|
-
weight: z.ZodUnion<[z.ZodString, z.ZodNumber]
|
|
70
|
+
weight: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
70
71
|
/**
|
|
71
72
|
* A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
|
|
72
73
|
*/
|
|
73
|
-
style: z.ZodEnum<["normal", "italic", "oblique"]
|
|
74
|
+
style: z.ZodOptional<z.ZodEnum<["normal", "italic", "oblique"]>>;
|
|
74
75
|
/**
|
|
75
76
|
* @default `"swap"`
|
|
76
77
|
*
|
|
77
78
|
* A [font display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display).
|
|
78
79
|
*/
|
|
79
80
|
display: z.ZodOptional<z.ZodEnum<["auto", "block", "swap", "fallback", "optional"]>>;
|
|
80
|
-
/**
|
|
81
|
-
* A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
|
|
82
|
-
*/
|
|
83
|
-
unicodeRange: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
|
|
84
81
|
/**
|
|
85
82
|
* A [font stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch).
|
|
86
83
|
*/
|
|
@@ -107,8 +104,11 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
107
104
|
url: string | URL;
|
|
108
105
|
tech?: string | undefined;
|
|
109
106
|
}>]>, "atleastone">;
|
|
107
|
+
/**
|
|
108
|
+
* A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
|
|
109
|
+
*/
|
|
110
|
+
unicodeRange: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
|
|
110
111
|
}>, "strict", z.ZodTypeAny, {
|
|
111
|
-
style: "normal" | "italic" | "oblique";
|
|
112
112
|
src: [string | URL | {
|
|
113
113
|
url: string | URL;
|
|
114
114
|
tech?: string | undefined;
|
|
@@ -116,14 +116,14 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
116
116
|
url: string | URL;
|
|
117
117
|
tech?: string | undefined;
|
|
118
118
|
})[]];
|
|
119
|
-
|
|
119
|
+
style?: "normal" | "italic" | "oblique" | undefined;
|
|
120
|
+
weight?: string | number | undefined;
|
|
120
121
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
121
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
122
122
|
stretch?: string | undefined;
|
|
123
123
|
featureSettings?: string | undefined;
|
|
124
124
|
variationSettings?: string | undefined;
|
|
125
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
125
126
|
}, {
|
|
126
|
-
style: "normal" | "italic" | "oblique";
|
|
127
127
|
src: [string | URL | {
|
|
128
128
|
url: string | URL;
|
|
129
129
|
tech?: string | undefined;
|
|
@@ -131,19 +131,19 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
131
131
|
url: string | URL;
|
|
132
132
|
tech?: string | undefined;
|
|
133
133
|
})[]];
|
|
134
|
-
|
|
134
|
+
style?: "normal" | "italic" | "oblique" | undefined;
|
|
135
|
+
weight?: string | number | undefined;
|
|
135
136
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
136
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
137
137
|
stretch?: string | undefined;
|
|
138
138
|
featureSettings?: string | undefined;
|
|
139
139
|
variationSettings?: string | undefined;
|
|
140
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
140
141
|
}>, "atleastone">;
|
|
141
142
|
}>, "strict", z.ZodTypeAny, {
|
|
142
143
|
name: string;
|
|
143
144
|
cssVariable: string;
|
|
144
145
|
provider: "local";
|
|
145
146
|
variants: [{
|
|
146
|
-
style: "normal" | "italic" | "oblique";
|
|
147
147
|
src: [string | URL | {
|
|
148
148
|
url: string | URL;
|
|
149
149
|
tech?: string | undefined;
|
|
@@ -151,14 +151,14 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
151
151
|
url: string | URL;
|
|
152
152
|
tech?: string | undefined;
|
|
153
153
|
})[]];
|
|
154
|
-
|
|
154
|
+
style?: "normal" | "italic" | "oblique" | undefined;
|
|
155
|
+
weight?: string | number | undefined;
|
|
155
156
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
156
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
157
157
|
stretch?: string | undefined;
|
|
158
158
|
featureSettings?: string | undefined;
|
|
159
159
|
variationSettings?: string | undefined;
|
|
160
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
160
161
|
}, ...{
|
|
161
|
-
style: "normal" | "italic" | "oblique";
|
|
162
162
|
src: [string | URL | {
|
|
163
163
|
url: string | URL;
|
|
164
164
|
tech?: string | undefined;
|
|
@@ -166,12 +166,13 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
166
166
|
url: string | URL;
|
|
167
167
|
tech?: string | undefined;
|
|
168
168
|
})[]];
|
|
169
|
-
|
|
169
|
+
style?: "normal" | "italic" | "oblique" | undefined;
|
|
170
|
+
weight?: string | number | undefined;
|
|
170
171
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
171
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
172
172
|
stretch?: string | undefined;
|
|
173
173
|
featureSettings?: string | undefined;
|
|
174
174
|
variationSettings?: string | undefined;
|
|
175
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
175
176
|
}[]];
|
|
176
177
|
fallbacks?: string[] | undefined;
|
|
177
178
|
optimizedFallbacks?: boolean | undefined;
|
|
@@ -180,7 +181,6 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
180
181
|
cssVariable: string;
|
|
181
182
|
provider: "local";
|
|
182
183
|
variants: [{
|
|
183
|
-
style: "normal" | "italic" | "oblique";
|
|
184
184
|
src: [string | URL | {
|
|
185
185
|
url: string | URL;
|
|
186
186
|
tech?: string | undefined;
|
|
@@ -188,14 +188,14 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
188
188
|
url: string | URL;
|
|
189
189
|
tech?: string | undefined;
|
|
190
190
|
})[]];
|
|
191
|
-
|
|
191
|
+
style?: "normal" | "italic" | "oblique" | undefined;
|
|
192
|
+
weight?: string | number | undefined;
|
|
192
193
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
193
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
194
194
|
stretch?: string | undefined;
|
|
195
195
|
featureSettings?: string | undefined;
|
|
196
196
|
variationSettings?: string | undefined;
|
|
197
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
197
198
|
}, ...{
|
|
198
|
-
style: "normal" | "italic" | "oblique";
|
|
199
199
|
src: [string | URL | {
|
|
200
200
|
url: string | URL;
|
|
201
201
|
tech?: string | undefined;
|
|
@@ -203,12 +203,13 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
203
203
|
url: string | URL;
|
|
204
204
|
tech?: string | undefined;
|
|
205
205
|
})[]];
|
|
206
|
-
|
|
206
|
+
style?: "normal" | "italic" | "oblique" | undefined;
|
|
207
|
+
weight?: string | number | undefined;
|
|
207
208
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
208
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
209
209
|
stretch?: string | undefined;
|
|
210
210
|
featureSettings?: string | undefined;
|
|
211
211
|
variationSettings?: string | undefined;
|
|
212
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
212
213
|
}[]];
|
|
213
214
|
fallbacks?: string[] | undefined;
|
|
214
215
|
optimizedFallbacks?: boolean | undefined;
|
|
@@ -230,21 +231,17 @@ export declare const remoteFontFamilySchema: z.ZodObject<z.objectUtil.extendShap
|
|
|
230
231
|
* weight: "100 900"
|
|
231
232
|
* ```
|
|
232
233
|
*/
|
|
233
|
-
weight: z.ZodUnion<[z.ZodString, z.ZodNumber]
|
|
234
|
+
weight: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
234
235
|
/**
|
|
235
236
|
* A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
|
|
236
237
|
*/
|
|
237
|
-
style: z.ZodEnum<["normal", "italic", "oblique"]
|
|
238
|
+
style: z.ZodOptional<z.ZodEnum<["normal", "italic", "oblique"]>>;
|
|
238
239
|
/**
|
|
239
240
|
* @default `"swap"`
|
|
240
241
|
*
|
|
241
242
|
* A [font display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display).
|
|
242
243
|
*/
|
|
243
244
|
display: z.ZodOptional<z.ZodEnum<["auto", "block", "swap", "fallback", "optional"]>>;
|
|
244
|
-
/**
|
|
245
|
-
* A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
|
|
246
|
-
*/
|
|
247
|
-
unicodeRange: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
|
|
248
245
|
/**
|
|
249
246
|
* A [font stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch).
|
|
250
247
|
*/
|
|
@@ -325,6 +322,10 @@ export declare const remoteFontFamilySchema: z.ZodObject<z.objectUtil.extendShap
|
|
|
325
322
|
* An array of [font subsets](https://knaap.dev/posts/font-subsetting/):
|
|
326
323
|
*/
|
|
327
324
|
subsets: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
|
|
325
|
+
/**
|
|
326
|
+
* A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
|
|
327
|
+
*/
|
|
328
|
+
unicodeRange: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
|
|
328
329
|
}>, "strict", z.ZodTypeAny, {
|
|
329
330
|
name: string;
|
|
330
331
|
cssVariable: string;
|
|
@@ -335,10 +336,10 @@ export declare const remoteFontFamilySchema: z.ZodObject<z.objectUtil.extendShap
|
|
|
335
336
|
fallbacks?: string[] | undefined;
|
|
336
337
|
optimizedFallbacks?: boolean | undefined;
|
|
337
338
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
338
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
339
339
|
stretch?: string | undefined;
|
|
340
340
|
featureSettings?: string | undefined;
|
|
341
341
|
variationSettings?: string | undefined;
|
|
342
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
342
343
|
weights?: [string | number, ...(string | number)[]] | undefined;
|
|
343
344
|
styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
|
|
344
345
|
subsets?: [string, ...string[]] | undefined;
|
|
@@ -352,10 +353,10 @@ export declare const remoteFontFamilySchema: z.ZodObject<z.objectUtil.extendShap
|
|
|
352
353
|
fallbacks?: string[] | undefined;
|
|
353
354
|
optimizedFallbacks?: boolean | undefined;
|
|
354
355
|
display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
|
|
355
|
-
unicodeRange?: [string, ...string[]] | undefined;
|
|
356
356
|
stretch?: string | undefined;
|
|
357
357
|
featureSettings?: string | undefined;
|
|
358
358
|
variationSettings?: string | undefined;
|
|
359
|
+
unicodeRange?: [string, ...string[]] | undefined;
|
|
359
360
|
weights?: [string | number, ...(string | number)[]] | undefined;
|
|
360
361
|
styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
|
|
361
362
|
subsets?: [string, ...string[]] | undefined;
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { LOCAL_PROVIDER_NAME } from "./constants.js";
|
|
3
3
|
const weightSchema = z.union([z.string(), z.number()]);
|
|
4
4
|
const styleSchema = z.enum(["normal", "italic", "oblique"]);
|
|
5
|
+
const unicodeRangeSchema = z.array(z.string()).nonempty();
|
|
5
6
|
const familyPropertiesSchema = z.object({
|
|
6
7
|
/**
|
|
7
8
|
* 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:
|
|
@@ -10,21 +11,17 @@ const familyPropertiesSchema = z.object({
|
|
|
10
11
|
* weight: "100 900"
|
|
11
12
|
* ```
|
|
12
13
|
*/
|
|
13
|
-
weight: weightSchema,
|
|
14
|
+
weight: weightSchema.optional(),
|
|
14
15
|
/**
|
|
15
16
|
* A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
|
|
16
17
|
*/
|
|
17
|
-
style: styleSchema,
|
|
18
|
+
style: styleSchema.optional(),
|
|
18
19
|
/**
|
|
19
20
|
* @default `"swap"`
|
|
20
21
|
*
|
|
21
22
|
* A [font display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display).
|
|
22
23
|
*/
|
|
23
24
|
display: z.enum(["auto", "block", "swap", "fallback", "optional"]).optional(),
|
|
24
|
-
/**
|
|
25
|
-
* A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
|
|
26
|
-
*/
|
|
27
|
-
unicodeRange: z.array(z.string()).nonempty().optional(),
|
|
28
25
|
/**
|
|
29
26
|
* A [font stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch).
|
|
30
27
|
*/
|
|
@@ -106,7 +103,11 @@ const localFontFamilySchema = requiredFamilyAttributesSchema.merge(fallbacksSche
|
|
|
106
103
|
entrypointSchema,
|
|
107
104
|
z.object({ url: entrypointSchema, tech: z.string().optional() }).strict()
|
|
108
105
|
])
|
|
109
|
-
).nonempty()
|
|
106
|
+
).nonempty(),
|
|
107
|
+
/**
|
|
108
|
+
* A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
|
|
109
|
+
*/
|
|
110
|
+
unicodeRange: unicodeRangeSchema.optional()
|
|
110
111
|
// TODO: find a way to support subsets (through fontkit?)
|
|
111
112
|
}).strict()
|
|
112
113
|
)
|
|
@@ -145,11 +146,16 @@ const remoteFontFamilySchema = requiredFamilyAttributesSchema.merge(
|
|
|
145
146
|
*
|
|
146
147
|
* An array of [font subsets](https://knaap.dev/posts/font-subsetting/):
|
|
147
148
|
*/
|
|
148
|
-
subsets: z.array(z.string()).nonempty().optional()
|
|
149
|
+
subsets: z.array(z.string()).nonempty().optional(),
|
|
150
|
+
/**
|
|
151
|
+
* A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
|
|
152
|
+
*/
|
|
153
|
+
unicodeRange: unicodeRangeSchema.optional()
|
|
149
154
|
})
|
|
150
155
|
).strict();
|
|
151
156
|
export {
|
|
152
157
|
fontProviderSchema,
|
|
153
158
|
localFontFamilySchema,
|
|
154
|
-
remoteFontFamilySchema
|
|
159
|
+
remoteFontFamilySchema,
|
|
160
|
+
styleSchema
|
|
155
161
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Defaults } from './types.js';
|
|
1
|
+
import type { Defaults, FontType } from './types.js';
|
|
2
2
|
export declare const LOCAL_PROVIDER_NAME = "local";
|
|
3
3
|
export declare const DEFAULTS: Defaults;
|
|
4
4
|
export declare const VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/internal";
|
|
@@ -6,6 +6,9 @@ export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
|
6
6
|
export declare const URL_PREFIX = "/_astro/fonts/";
|
|
7
7
|
export declare const CACHE_DIR = "./fonts/";
|
|
8
8
|
export declare const FONT_TYPES: readonly ["woff2", "woff", "otf", "ttf", "eot"];
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const FONT_FORMATS: Array<{
|
|
10
|
+
type: FontType;
|
|
11
|
+
format: string;
|
|
12
|
+
}>;
|
|
10
13
|
export declare const GENERIC_FALLBACK_NAMES: readonly ["serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded", "emoji", "math", "fangsong"];
|
|
11
14
|
export declare const FONTS_TYPES_FILE = "fonts.d.ts";
|
|
@@ -12,13 +12,13 @@ const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
|
12
12
|
const URL_PREFIX = "/_astro/fonts/";
|
|
13
13
|
const CACHE_DIR = "./fonts/";
|
|
14
14
|
const FONT_TYPES = ["woff2", "woff", "otf", "ttf", "eot"];
|
|
15
|
-
const
|
|
16
|
-
woff2: "woff2",
|
|
17
|
-
woff: "woff",
|
|
18
|
-
otf: "opentype",
|
|
19
|
-
ttf: "truetype",
|
|
20
|
-
eot: "embedded-opentype"
|
|
21
|
-
|
|
15
|
+
const FONT_FORMATS = [
|
|
16
|
+
{ type: "woff2", format: "woff2" },
|
|
17
|
+
{ type: "woff", format: "woff" },
|
|
18
|
+
{ type: "otf", format: "opentype" },
|
|
19
|
+
{ type: "ttf", format: "truetype" },
|
|
20
|
+
{ type: "eot", format: "embedded-opentype" }
|
|
21
|
+
];
|
|
22
22
|
const GENERIC_FALLBACK_NAMES = [
|
|
23
23
|
"serif",
|
|
24
24
|
"sans-serif",
|
|
@@ -39,7 +39,7 @@ export {
|
|
|
39
39
|
CACHE_DIR,
|
|
40
40
|
DEFAULTS,
|
|
41
41
|
FONTS_TYPES_FILE,
|
|
42
|
-
|
|
42
|
+
FONT_FORMATS,
|
|
43
43
|
FONT_TYPES,
|
|
44
44
|
GENERIC_FALLBACK_NAMES,
|
|
45
45
|
LOCAL_PROVIDER_NAME,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as unifont from 'unifont';
|
|
2
2
|
import type { CollectedFontForMetrics } from './logic/optimize-fallbacks.js';
|
|
3
|
-
import type { AstroFontProvider, FontFileData, FontType, PreloadData, ResolvedFontProvider } from './types.js';
|
|
3
|
+
import type { AstroFontProvider, FontFileData, FontType, PreloadData, ResolvedFontProvider, Style } from './types.js';
|
|
4
4
|
import type { FontFaceMetrics, GenericFallbackName } from './types.js';
|
|
5
5
|
export interface Hasher {
|
|
6
6
|
hashString: (input: string) => string;
|
|
@@ -26,12 +26,16 @@ export type ErrorHandlerInput = SingleErrorInput<'cannot-load-font-provider', {
|
|
|
26
26
|
url: string;
|
|
27
27
|
}> | SingleErrorInput<'cannot-extract-font-type', {
|
|
28
28
|
url: string;
|
|
29
|
+
}> | SingleErrorInput<'cannot-extract-data', {
|
|
30
|
+
family: string;
|
|
31
|
+
url: string;
|
|
29
32
|
}>;
|
|
30
33
|
export interface ErrorHandler {
|
|
31
34
|
handle: (input: ErrorHandlerInput) => Error;
|
|
32
35
|
}
|
|
33
36
|
export interface UrlProxy {
|
|
34
37
|
proxy: (input: Pick<FontFileData, 'url' | 'init'> & {
|
|
38
|
+
type: FontType;
|
|
35
39
|
collectPreload: boolean;
|
|
36
40
|
data: Partial<unifont.FontFaceData>;
|
|
37
41
|
}) => string;
|
|
@@ -70,4 +74,13 @@ export interface FontFetcher {
|
|
|
70
74
|
export interface FontTypeExtractor {
|
|
71
75
|
extract: (url: string) => FontType;
|
|
72
76
|
}
|
|
77
|
+
export interface FontFileReader {
|
|
78
|
+
extract: (input: {
|
|
79
|
+
family: string;
|
|
80
|
+
url: string;
|
|
81
|
+
}) => {
|
|
82
|
+
weight: string;
|
|
83
|
+
style: Style;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
73
86
|
export {};
|
|
@@ -17,6 +17,14 @@ function getProps(input) {
|
|
|
17
17
|
...AstroErrorData.CannotExtractFontType,
|
|
18
18
|
message: AstroErrorData.CannotExtractFontType.message(input.data.url)
|
|
19
19
|
};
|
|
20
|
+
} else if (input.type === "cannot-extract-data") {
|
|
21
|
+
return {
|
|
22
|
+
...AstroErrorData.CannotDetermineWeightAndStyleFromFontFile,
|
|
23
|
+
message: AstroErrorData.CannotDetermineWeightAndStyleFromFontFile.message(
|
|
24
|
+
input.data.family,
|
|
25
|
+
input.data.url
|
|
26
|
+
)
|
|
27
|
+
};
|
|
20
28
|
}
|
|
21
29
|
input;
|
|
22
30
|
return AstroErrorData.UnknownError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fontace } from "fontace";
|
|
3
|
+
function createFontaceFontFileReader({
|
|
4
|
+
errorHandler
|
|
5
|
+
}) {
|
|
6
|
+
return {
|
|
7
|
+
extract({ family, url }) {
|
|
8
|
+
try {
|
|
9
|
+
const data = fontace(readFileSync(url));
|
|
10
|
+
return {
|
|
11
|
+
weight: data.weight,
|
|
12
|
+
style: data.style
|
|
13
|
+
};
|
|
14
|
+
} catch (cause) {
|
|
15
|
+
throw errorHandler.handle({
|
|
16
|
+
type: "cannot-extract-data",
|
|
17
|
+
data: { family, url },
|
|
18
|
+
cause
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
createFontaceFontFileReader
|
|
26
|
+
};
|
|
@@ -45,12 +45,12 @@ function createCapsizeFontMetricsResolver({
|
|
|
45
45
|
const descentOverride = Math.abs(metrics.descent) / adjustedEmSquare;
|
|
46
46
|
const lineGapOverride = metrics.lineGap / adjustedEmSquare;
|
|
47
47
|
return cssRenderer.generateFontFace(fallbackName, {
|
|
48
|
+
...properties,
|
|
48
49
|
src: renderFontSrc([{ name: fallbackFontName }]),
|
|
49
50
|
"size-adjust": toPercentage(sizeAdjust),
|
|
50
51
|
"ascent-override": toPercentage(ascentOverride),
|
|
51
52
|
"descent-override": toPercentage(descentOverride),
|
|
52
|
-
"line-gap-override": toPercentage(lineGapOverride)
|
|
53
|
-
...properties
|
|
53
|
+
"line-gap-override": toPercentage(lineGapOverride)
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { DataCollector,
|
|
2
|
-
export declare function createUrlProxy({ base, contentResolver, hasher, dataCollector,
|
|
1
|
+
import type { DataCollector, Hasher, UrlProxy, UrlProxyContentResolver } from '../definitions.js';
|
|
2
|
+
export declare function createUrlProxy({ base, contentResolver, hasher, dataCollector, }: {
|
|
3
3
|
base: string;
|
|
4
4
|
contentResolver: UrlProxyContentResolver;
|
|
5
5
|
hasher: Hasher;
|
|
6
6
|
dataCollector: DataCollector;
|
|
7
|
-
fontTypeExtractor: FontTypeExtractor;
|
|
8
7
|
}): UrlProxy;
|
|
@@ -2,12 +2,10 @@ function createUrlProxy({
|
|
|
2
2
|
base,
|
|
3
3
|
contentResolver,
|
|
4
4
|
hasher,
|
|
5
|
-
dataCollector
|
|
6
|
-
fontTypeExtractor
|
|
5
|
+
dataCollector
|
|
7
6
|
}) {
|
|
8
7
|
return {
|
|
9
|
-
proxy({ url: originalUrl, data, collectPreload, init }) {
|
|
10
|
-
const type = fontTypeExtractor.extract(originalUrl);
|
|
8
|
+
proxy({ url: originalUrl, type, data, collectPreload, init }) {
|
|
11
9
|
const hash = `${hasher.hashString(contentResolver.resolve(originalUrl))}.${type}`;
|
|
12
10
|
const url = base + hash;
|
|
13
11
|
dataCollector.collect({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as unifont from 'unifont';
|
|
2
|
-
import type { UrlProxy } from '../definitions.js';
|
|
3
|
-
export declare function normalizeRemoteFontFaces({ fonts, urlProxy, }: {
|
|
2
|
+
import type { FontTypeExtractor, UrlProxy } from '../definitions.js';
|
|
3
|
+
export declare function normalizeRemoteFontFaces({ fonts, urlProxy, fontTypeExtractor, }: {
|
|
4
4
|
fonts: Array<unifont.FontFaceData>;
|
|
5
5
|
urlProxy: UrlProxy;
|
|
6
|
+
fontTypeExtractor: FontTypeExtractor;
|
|
6
7
|
}): Array<unifont.FontFaceData>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { FONT_FORMATS } from "../constants.js";
|
|
1
2
|
function normalizeRemoteFontFaces({
|
|
2
3
|
fonts,
|
|
3
|
-
urlProxy
|
|
4
|
+
urlProxy,
|
|
5
|
+
fontTypeExtractor
|
|
4
6
|
}) {
|
|
5
7
|
return fonts.filter((font) => typeof font.meta?.priority === "number" ? font.meta.priority === 0 : true).map((font) => {
|
|
6
8
|
let index = 0;
|
|
@@ -10,11 +12,13 @@ function normalizeRemoteFontFaces({
|
|
|
10
12
|
if ("name" in source) {
|
|
11
13
|
return source;
|
|
12
14
|
}
|
|
15
|
+
const url = source.url.startsWith("//") ? `https:${source.url}` : source.url;
|
|
13
16
|
const proxied = {
|
|
14
17
|
...source,
|
|
15
|
-
originalURL:
|
|
18
|
+
originalURL: url,
|
|
16
19
|
url: urlProxy.proxy({
|
|
17
|
-
url
|
|
20
|
+
url,
|
|
21
|
+
type: FONT_FORMATS.find((e) => e.format === source.format)?.type ?? fontTypeExtractor.extract(source.url),
|
|
18
22
|
// We only collect the first URL to avoid preloading fallback sources (eg. we only
|
|
19
23
|
// preload woff2 if woff is available)
|
|
20
24
|
collectPreload: index === 0,
|
|
@@ -6,7 +6,7 @@ function resolveVariants({
|
|
|
6
6
|
}) {
|
|
7
7
|
return variants.map((variant) => ({
|
|
8
8
|
...variant,
|
|
9
|
-
weight: variant.weight
|
|
9
|
+
weight: variant.weight?.toString(),
|
|
10
10
|
src: variant.src.map((value) => {
|
|
11
11
|
const isValue = typeof value === "string" || value instanceof URL;
|
|
12
12
|
const url = (isValue ? value : value.url).toString();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Storage } from 'unstorage';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Logger } from '../../core/logger/core.js';
|
|
3
|
+
import type { CssRenderer, FontFileReader, FontMetricsResolver, FontTypeExtractor, Hasher, LocalProviderUrlResolver, RemoteFontProviderResolver, SystemFallbacksProvider, UrlProxy } from './definitions.js';
|
|
3
4
|
import type { ConsumableMap, CreateUrlProxyParams, Defaults, FontFamily, FontFileDataMap } from './types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Manages how fonts are resolved:
|
|
@@ -19,7 +20,7 @@ import type { ConsumableMap, CreateUrlProxyParams, Defaults, FontFamily, FontFil
|
|
|
19
20
|
*
|
|
20
21
|
* Once that's done, the collected data is returned
|
|
21
22
|
*/
|
|
22
|
-
export declare function orchestrate({ families, hasher, remoteFontProviderResolver, localProviderUrlResolver, storage, cssRenderer, systemFallbacksProvider, fontMetricsResolver, fontTypeExtractor, createUrlProxy, defaults, }: {
|
|
23
|
+
export declare function orchestrate({ families, hasher, remoteFontProviderResolver, localProviderUrlResolver, storage, cssRenderer, systemFallbacksProvider, fontMetricsResolver, fontTypeExtractor, fontFileReader, logger, createUrlProxy, defaults, }: {
|
|
23
24
|
families: Array<FontFamily>;
|
|
24
25
|
hasher: Hasher;
|
|
25
26
|
remoteFontProviderResolver: RemoteFontProviderResolver;
|
|
@@ -29,6 +30,8 @@ export declare function orchestrate({ families, hasher, remoteFontProviderResolv
|
|
|
29
30
|
systemFallbacksProvider: SystemFallbacksProvider;
|
|
30
31
|
fontMetricsResolver: FontMetricsResolver;
|
|
31
32
|
fontTypeExtractor: FontTypeExtractor;
|
|
33
|
+
fontFileReader: FontFileReader;
|
|
34
|
+
logger: Logger;
|
|
32
35
|
createUrlProxy: (params: CreateUrlProxyParams) => UrlProxy;
|
|
33
36
|
defaults: Defaults;
|
|
34
37
|
}): Promise<{
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bold } from "kleur/colors";
|
|
1
2
|
import * as unifont from "unifont";
|
|
2
3
|
import { LOCAL_PROVIDER_NAME } from "./constants.js";
|
|
3
4
|
import { extractUnifontProviders } from "./logic/extract-unifont-providers.js";
|
|
@@ -16,6 +17,8 @@ async function orchestrate({
|
|
|
16
17
|
systemFallbacksProvider,
|
|
17
18
|
fontMetricsResolver,
|
|
18
19
|
fontTypeExtractor,
|
|
20
|
+
fontFileReader,
|
|
21
|
+
logger,
|
|
19
22
|
createUrlProxy,
|
|
20
23
|
defaults
|
|
21
24
|
}) {
|
|
@@ -63,7 +66,8 @@ async function orchestrate({
|
|
|
63
66
|
const result = resolveLocalFont({
|
|
64
67
|
family,
|
|
65
68
|
urlProxy,
|
|
66
|
-
fontTypeExtractor
|
|
69
|
+
fontTypeExtractor,
|
|
70
|
+
fontFileReader
|
|
67
71
|
});
|
|
68
72
|
fonts = result.fonts;
|
|
69
73
|
} else {
|
|
@@ -81,7 +85,13 @@ async function orchestrate({
|
|
|
81
85
|
// from families (inside extractUnifontProviders).
|
|
82
86
|
[family.provider.name]
|
|
83
87
|
);
|
|
84
|
-
|
|
88
|
+
if (result.fonts.length === 0) {
|
|
89
|
+
logger.warn(
|
|
90
|
+
"assets",
|
|
91
|
+
`No data found for font family ${bold(family.name)}. Review your configuration`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
fonts = normalizeRemoteFontFaces({ fonts: result.fonts, urlProxy, fontTypeExtractor });
|
|
85
95
|
}
|
|
86
96
|
for (const data of fonts) {
|
|
87
97
|
css += cssRenderer.generateFontFace(
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type * as unifont from 'unifont';
|
|
2
|
-
import type { FontTypeExtractor, UrlProxy } from '../definitions.js';
|
|
2
|
+
import type { FontFileReader, FontTypeExtractor, UrlProxy } from '../definitions.js';
|
|
3
3
|
import type { ResolvedLocalFontFamily } from '../types.js';
|
|
4
4
|
interface Options {
|
|
5
5
|
family: ResolvedLocalFontFamily;
|
|
6
6
|
urlProxy: UrlProxy;
|
|
7
7
|
fontTypeExtractor: FontTypeExtractor;
|
|
8
|
+
fontFileReader: FontFileReader;
|
|
8
9
|
}
|
|
9
|
-
export declare function resolveLocalFont({ family, urlProxy, fontTypeExtractor }: Options): {
|
|
10
|
+
export declare function resolveLocalFont({ family, urlProxy, fontTypeExtractor, fontFileReader, }: Options): {
|
|
10
11
|
fonts: Array<unifont.FontFaceData>;
|
|
11
12
|
};
|
|
12
13
|
export {};
|