astro 5.6.2 → 5.7.1

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.
Files changed (80) hide show
  1. package/client.d.ts +3 -0
  2. package/components/Font.astro +32 -0
  3. package/dist/actions/plugins.js +2 -2
  4. package/dist/assets/fonts/config.d.ts +378 -0
  5. package/dist/assets/fonts/config.js +157 -0
  6. package/dist/assets/fonts/constants.d.ts +15 -0
  7. package/dist/assets/fonts/constants.js +41 -0
  8. package/dist/assets/fonts/load.d.ts +20 -0
  9. package/dist/assets/fonts/load.js +135 -0
  10. package/dist/assets/fonts/metrics.d.ts +9 -0
  11. package/dist/assets/fonts/metrics.js +61 -0
  12. package/dist/assets/fonts/providers/entrypoints/adobe.d.ts +2 -0
  13. package/dist/assets/fonts/providers/entrypoints/adobe.js +5 -0
  14. package/dist/assets/fonts/providers/entrypoints/bunny.d.ts +1 -0
  15. package/dist/assets/fonts/providers/entrypoints/bunny.js +5 -0
  16. package/dist/assets/fonts/providers/entrypoints/fontshare.d.ts +1 -0
  17. package/dist/assets/fonts/providers/entrypoints/fontshare.js +5 -0
  18. package/dist/assets/fonts/providers/entrypoints/fontsource.d.ts +1 -0
  19. package/dist/assets/fonts/providers/entrypoints/fontsource.js +5 -0
  20. package/dist/assets/fonts/providers/entrypoints/google.d.ts +2 -0
  21. package/dist/assets/fonts/providers/entrypoints/google.js +5 -0
  22. package/dist/assets/fonts/providers/index.d.ts +48 -0
  23. package/dist/assets/fonts/providers/index.js +40 -0
  24. package/dist/assets/fonts/providers/local.d.ts +10 -0
  25. package/dist/assets/fonts/providers/local.js +30 -0
  26. package/dist/assets/fonts/providers/utils.d.ts +9 -0
  27. package/dist/assets/fonts/providers/utils.js +37 -0
  28. package/dist/assets/fonts/sync.d.ts +2 -0
  29. package/dist/assets/fonts/sync.js +17 -0
  30. package/dist/assets/fonts/types.d.ts +45 -0
  31. package/dist/assets/fonts/types.js +0 -0
  32. package/dist/assets/fonts/utils.d.ts +92 -0
  33. package/dist/assets/fonts/utils.js +215 -0
  34. package/dist/assets/fonts/vite-plugin-fonts.d.ts +10 -0
  35. package/dist/assets/fonts/vite-plugin-fonts.js +212 -0
  36. package/dist/assets/utils/node/emitAsset.d.ts +4 -2
  37. package/dist/assets/utils/node/emitAsset.js +1 -1
  38. package/dist/assets/utils/vendor/image-size/types/index.d.ts +2 -2
  39. package/dist/assets/vite-plugin-assets.d.ts +8 -3
  40. package/dist/assets/vite-plugin-assets.js +7 -7
  41. package/dist/config/entrypoint.d.ts +2 -0
  42. package/dist/config/entrypoint.js +3 -0
  43. package/dist/config/index.d.ts +2 -1
  44. package/dist/content/content-layer.js +5 -4
  45. package/dist/content/runtime-assets.js +1 -0
  46. package/dist/content/vite-plugin-content-imports.js +4 -2
  47. package/dist/core/build/generate.js +2 -2
  48. package/dist/core/build/pipeline.js +2 -2
  49. package/dist/core/build/static-build.js +2 -2
  50. package/dist/core/config/schemas/base.d.ts +436 -39
  51. package/dist/core/config/schemas/base.js +3 -7
  52. package/dist/core/config/schemas/refined.js +12 -0
  53. package/dist/core/config/schemas/relative.d.ts +567 -63
  54. package/dist/core/config/schemas/relative.js +1 -2
  55. package/dist/core/constants.js +1 -1
  56. package/dist/core/create-vite.js +2 -2
  57. package/dist/core/dev/dev.js +1 -1
  58. package/dist/core/errors/errors-data.d.ts +82 -26
  59. package/dist/core/errors/errors-data.js +45 -16
  60. package/dist/core/logger/core.d.ts +1 -1
  61. package/dist/core/messages.js +2 -2
  62. package/dist/core/middleware/vite-plugin.js +2 -2
  63. package/dist/core/render-context.js +38 -5
  64. package/dist/core/routing/rewrite.js +14 -5
  65. package/dist/core/session.d.ts +4 -6
  66. package/dist/core/session.js +4 -29
  67. package/dist/core/sync/index.js +2 -0
  68. package/dist/integrations/hooks.js +2 -3
  69. package/dist/manifest/virtual-module.d.ts +1 -5
  70. package/dist/manifest/virtual-module.js +1 -18
  71. package/dist/prerender/utils.d.ts +5 -1
  72. package/dist/prerender/utils.js +8 -8
  73. package/dist/runtime/client/dev-toolbar/apps/audit/annotations.d.ts +6 -0
  74. package/dist/runtime/client/dev-toolbar/apps/audit/annotations.js +27 -0
  75. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +10 -4
  76. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +2 -2
  77. package/dist/types/public/config.d.ts +155 -98
  78. package/dist/vite-plugin-astro-server/plugin.js +1 -1
  79. package/package.json +7 -4
  80. package/types/fonts.d.ts +4 -0
package/client.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  /// <reference path="./types/content.d.ts" />
3
3
  /// <reference path="./types/actions.d.ts" />
4
4
  /// <reference path="./types/env.d.ts" />
5
+ /// <reference path="./types/fonts.d.ts" />
5
6
 
6
7
  interface ImportMetaEnv {
7
8
  /**
@@ -54,6 +55,7 @@ declare module 'astro:assets' {
54
55
  inferRemoteSize: typeof import('./dist/assets/utils/index.js').inferRemoteSize;
55
56
  Image: typeof import('./components/Image.astro').default;
56
57
  Picture: typeof import('./components/Picture.astro').default;
58
+ Font: typeof import('./components/Font.astro').default;
57
59
  };
58
60
 
59
61
  type ImgAttributes = import('./dist/type-utils.js').WithRequired<
@@ -73,6 +75,7 @@ declare module 'astro:assets' {
73
75
  imageConfig,
74
76
  Image,
75
77
  Picture,
78
+ Font,
76
79
  inferRemoteSize,
77
80
  }: AstroAssets;
78
81
  }
@@ -0,0 +1,32 @@
1
+ ---
2
+ import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
3
+
4
+ // TODO: remove dynamic import when fonts are stabilized
5
+ const { fontsData } = await import('virtual:astro:assets/fonts/internal').catch(() => {
6
+ throw new AstroError(AstroErrorData.ExperimentalFontsNotEnabled);
7
+ });
8
+
9
+ interface Props {
10
+ /** The `cssVariable` registered in your Astro configuration. */
11
+ cssVariable: import('astro:assets').FontFamily;
12
+ /** Whether it should output [preload links](https://web.dev/learn/performance/optimize-web-fonts#preload) or not. */
13
+ preload?: boolean;
14
+ }
15
+
16
+ const { cssVariable, preload = false } = Astro.props;
17
+ const data = fontsData.get(cssVariable);
18
+ if (!data) {
19
+ throw new AstroError({
20
+ ...AstroErrorData.FontFamilyNotFound,
21
+ message: AstroErrorData.FontFamilyNotFound.message(cssVariable),
22
+ });
23
+ }
24
+ ---
25
+
26
+ {
27
+ preload &&
28
+ data.preloadData.map(({ url, type }) => (
29
+ <link rel="preload" href={url} as="font" type={`font/${type}`} crossorigin />
30
+ ))
31
+ }
32
+ <style set:html={data.css}></style>
@@ -1,6 +1,6 @@
1
1
  import { addRollupInput } from "../core/build/add-rollup-input.js";
2
2
  import { shouldAppendForwardSlash } from "../core/build/util.js";
3
- import { getOutputDirectory } from "../prerender/utils.js";
3
+ import { getServerOutputDirectory } from "../prerender/utils.js";
4
4
  import {
5
5
  ASTRO_ACTIONS_INTERNAL_MODULE_ID,
6
6
  NOOP_ACTIONS,
@@ -46,7 +46,7 @@ function vitePluginActionsBuild(opts, internals) {
46
46
  writeBundle(_, bundle) {
47
47
  for (const [chunkName, chunk] of Object.entries(bundle)) {
48
48
  if (chunk.type !== "asset" && chunk.facadeModuleId === RESOLVED_ASTRO_ACTIONS_INTERNAL_MODULE_ID) {
49
- const outputDirectory = getOutputDirectory(opts.settings);
49
+ const outputDirectory = getServerOutputDirectory(opts.settings);
50
50
  internals.astroActionsEntryPoint = new URL(chunkName, outputDirectory);
51
51
  }
52
52
  }
@@ -0,0 +1,378 @@
1
+ import { z } from 'zod';
2
+ export declare const requiredFamilyAttributesSchema: z.ZodObject<{
3
+ /**
4
+ * The font family name, as identified by your font provider.
5
+ */
6
+ name: z.ZodString;
7
+ /**
8
+ * A valid [ident](https://developer.mozilla.org/en-US/docs/Web/CSS/ident) in the form of a CSS variable (i.e. starting with `--`).
9
+ */
10
+ cssVariable: z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ name: string;
13
+ cssVariable: string;
14
+ }, {
15
+ name: string;
16
+ cssVariable: string;
17
+ }>;
18
+ export declare const fontProviderSchema: z.ZodObject<{
19
+ /**
20
+ * URL, path relative to the root or package import.
21
+ */
22
+ entrypoint: z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>;
23
+ /**
24
+ * Optional serializable object passed to the unifont provider.
25
+ */
26
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
27
+ }, "strict", z.ZodTypeAny, {
28
+ entrypoint: string | URL;
29
+ config?: Record<string, any> | undefined;
30
+ }, {
31
+ entrypoint: string | URL;
32
+ config?: Record<string, any> | undefined;
33
+ }>;
34
+ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
35
+ /**
36
+ * The font family name, as identified by your font provider.
37
+ */
38
+ name: z.ZodString;
39
+ /**
40
+ * A valid [ident](https://developer.mozilla.org/en-US/docs/Web/CSS/ident) in the form of a CSS variable (i.e. starting with `--`).
41
+ */
42
+ cssVariable: z.ZodString;
43
+ }, {
44
+ /**
45
+ * @default `["sans-serif"]`
46
+ *
47
+ * An array of fonts to use when your chosen font is unavailable, or loading. Fallback fonts will be chosen in the order listed. The first available font will be used:
48
+ *
49
+ * ```js
50
+ * fallbacks: ["CustomFont", "serif"]
51
+ * ```
52
+ *
53
+ * To disable fallback fonts completely, configure an empty array:
54
+ *
55
+ * ```js
56
+ * fallbacks: []
57
+ * ```
58
+ *
59
+
60
+ * If the last font in the `fallbacks` array is a [generic family name](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#generic-name), an [optimized fallback](https://developer.chrome.com/blog/font-fallbacks) using font metrics will be generated. To disable this optimization, set `optimizedFallbacks` to false.
61
+ */
62
+ fallbacks: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
63
+ /**
64
+ * @default `true`
65
+ *
66
+ * Whether or not to enable optimized fallback generation. You may disable this default optimization to have full control over `fallbacks`.
67
+ */
68
+ optimizedFallbacks: z.ZodOptional<z.ZodBoolean>;
69
+ }>, {
70
+ /**
71
+ * The source of your font files. Set to `"local"` to use local font files.
72
+ */
73
+ provider: z.ZodLiteral<"local">;
74
+ /**
75
+ * Each variant represents a [`@font-face` declaration](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/).
76
+ */
77
+ variants: z.ZodArray<z.ZodObject<z.objectUtil.extendShape<{
78
+ /**
79
+ * 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:
80
+ *
81
+ * ```js
82
+ * weight: "100 900"
83
+ * ```
84
+ */
85
+ weight: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
86
+ /**
87
+ * A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
88
+ */
89
+ style: z.ZodEnum<["normal", "italic", "oblique"]>;
90
+ /**
91
+ * @default `"swap"`
92
+ *
93
+ * A [font display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display).
94
+ */
95
+ display: z.ZodOptional<z.ZodEnum<["auto", "block", "swap", "fallback", "optional"]>>;
96
+ /**
97
+ * A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
98
+ */
99
+ unicodeRange: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
100
+ /**
101
+ * A [font stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch).
102
+ */
103
+ stretch: z.ZodOptional<z.ZodString>;
104
+ /**
105
+ * Font [feature settings](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-feature-settings).
106
+ */
107
+ featureSettings: z.ZodOptional<z.ZodString>;
108
+ /**
109
+ * Font [variation settings](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-variation-settings).
110
+ */
111
+ variationSettings: z.ZodOptional<z.ZodString>;
112
+ }, {
113
+ /**
114
+ * 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.
115
+ */
116
+ src: z.ZodArray<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>, z.ZodObject<{
117
+ url: z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>;
118
+ tech: z.ZodOptional<z.ZodString>;
119
+ }, "strict", z.ZodTypeAny, {
120
+ url: string | URL;
121
+ tech?: string | undefined;
122
+ }, {
123
+ url: string | URL;
124
+ tech?: string | undefined;
125
+ }>]>, "atleastone">;
126
+ }>, "strict", z.ZodTypeAny, {
127
+ style: "normal" | "italic" | "oblique";
128
+ src: [string | URL | {
129
+ url: string | URL;
130
+ tech?: string | undefined;
131
+ }, ...(string | URL | {
132
+ url: string | URL;
133
+ tech?: string | undefined;
134
+ })[]];
135
+ weight: string | number;
136
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
137
+ unicodeRange?: [string, ...string[]] | undefined;
138
+ stretch?: string | undefined;
139
+ featureSettings?: string | undefined;
140
+ variationSettings?: string | undefined;
141
+ }, {
142
+ style: "normal" | "italic" | "oblique";
143
+ src: [string | URL | {
144
+ url: string | URL;
145
+ tech?: string | undefined;
146
+ }, ...(string | URL | {
147
+ url: string | URL;
148
+ tech?: string | undefined;
149
+ })[]];
150
+ weight: string | number;
151
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
152
+ unicodeRange?: [string, ...string[]] | undefined;
153
+ stretch?: string | undefined;
154
+ featureSettings?: string | undefined;
155
+ variationSettings?: string | undefined;
156
+ }>, "atleastone">;
157
+ }>, "strict", z.ZodTypeAny, {
158
+ name: string;
159
+ cssVariable: string;
160
+ provider: "local";
161
+ variants: [{
162
+ style: "normal" | "italic" | "oblique";
163
+ src: [string | URL | {
164
+ url: string | URL;
165
+ tech?: string | undefined;
166
+ }, ...(string | URL | {
167
+ url: string | URL;
168
+ tech?: string | undefined;
169
+ })[]];
170
+ weight: string | number;
171
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
172
+ unicodeRange?: [string, ...string[]] | undefined;
173
+ stretch?: string | undefined;
174
+ featureSettings?: string | undefined;
175
+ variationSettings?: string | undefined;
176
+ }, ...{
177
+ style: "normal" | "italic" | "oblique";
178
+ src: [string | URL | {
179
+ url: string | URL;
180
+ tech?: string | undefined;
181
+ }, ...(string | URL | {
182
+ url: string | URL;
183
+ tech?: string | undefined;
184
+ })[]];
185
+ weight: string | number;
186
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
187
+ unicodeRange?: [string, ...string[]] | undefined;
188
+ stretch?: string | undefined;
189
+ featureSettings?: string | undefined;
190
+ variationSettings?: string | undefined;
191
+ }[]];
192
+ fallbacks?: [string, ...string[]] | undefined;
193
+ optimizedFallbacks?: boolean | undefined;
194
+ }, {
195
+ name: string;
196
+ cssVariable: string;
197
+ provider: "local";
198
+ variants: [{
199
+ style: "normal" | "italic" | "oblique";
200
+ src: [string | URL | {
201
+ url: string | URL;
202
+ tech?: string | undefined;
203
+ }, ...(string | URL | {
204
+ url: string | URL;
205
+ tech?: string | undefined;
206
+ })[]];
207
+ weight: string | number;
208
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
209
+ unicodeRange?: [string, ...string[]] | undefined;
210
+ stretch?: string | undefined;
211
+ featureSettings?: string | undefined;
212
+ variationSettings?: string | undefined;
213
+ }, ...{
214
+ style: "normal" | "italic" | "oblique";
215
+ src: [string | URL | {
216
+ url: string | URL;
217
+ tech?: string | undefined;
218
+ }, ...(string | URL | {
219
+ url: string | URL;
220
+ tech?: string | undefined;
221
+ })[]];
222
+ weight: string | number;
223
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
224
+ unicodeRange?: [string, ...string[]] | undefined;
225
+ stretch?: string | undefined;
226
+ featureSettings?: string | undefined;
227
+ variationSettings?: string | undefined;
228
+ }[]];
229
+ fallbacks?: [string, ...string[]] | undefined;
230
+ optimizedFallbacks?: boolean | undefined;
231
+ }>;
232
+ export declare const remoteFontFamilySchema: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<z.objectUtil.extendShape<{
233
+ /**
234
+ * The font family name, as identified by your font provider.
235
+ */
236
+ name: z.ZodString;
237
+ /**
238
+ * A valid [ident](https://developer.mozilla.org/en-US/docs/Web/CSS/ident) in the form of a CSS variable (i.e. starting with `--`).
239
+ */
240
+ cssVariable: z.ZodString;
241
+ }, Omit<{
242
+ /**
243
+ * 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:
244
+ *
245
+ * ```js
246
+ * weight: "100 900"
247
+ * ```
248
+ */
249
+ weight: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
250
+ /**
251
+ * A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
252
+ */
253
+ style: z.ZodEnum<["normal", "italic", "oblique"]>;
254
+ /**
255
+ * @default `"swap"`
256
+ *
257
+ * A [font display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display).
258
+ */
259
+ display: z.ZodOptional<z.ZodEnum<["auto", "block", "swap", "fallback", "optional"]>>;
260
+ /**
261
+ * A [unicode range](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range).
262
+ */
263
+ unicodeRange: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
264
+ /**
265
+ * A [font stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch).
266
+ */
267
+ stretch: z.ZodOptional<z.ZodString>;
268
+ /**
269
+ * Font [feature settings](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-feature-settings).
270
+ */
271
+ featureSettings: z.ZodOptional<z.ZodString>;
272
+ /**
273
+ * Font [variation settings](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-variation-settings).
274
+ */
275
+ variationSettings: z.ZodOptional<z.ZodString>;
276
+ }, "style" | "weight">>, {
277
+ /**
278
+ * @default `["sans-serif"]`
279
+ *
280
+ * An array of fonts to use when your chosen font is unavailable, or loading. Fallback fonts will be chosen in the order listed. The first available font will be used:
281
+ *
282
+ * ```js
283
+ * fallbacks: ["CustomFont", "serif"]
284
+ * ```
285
+ *
286
+ * To disable fallback fonts completely, configure an empty array:
287
+ *
288
+ * ```js
289
+ * fallbacks: []
290
+ * ```
291
+ *
292
+
293
+ * If the last font in the `fallbacks` array is a [generic family name](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#generic-name), an [optimized fallback](https://developer.chrome.com/blog/font-fallbacks) using font metrics will be generated. To disable this optimization, set `optimizedFallbacks` to false.
294
+ */
295
+ fallbacks: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
296
+ /**
297
+ * @default `true`
298
+ *
299
+ * Whether or not to enable optimized fallback generation. You may disable this default optimization to have full control over `fallbacks`.
300
+ */
301
+ optimizedFallbacks: z.ZodOptional<z.ZodBoolean>;
302
+ }>, {
303
+ /**
304
+ * The source of your font files. You can use a built-in provider or write your own custom provider.
305
+ */
306
+ provider: z.ZodObject<{
307
+ /**
308
+ * URL, path relative to the root or package import.
309
+ */
310
+ entrypoint: z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>;
311
+ /**
312
+ * Optional serializable object passed to the unifont provider.
313
+ */
314
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
315
+ }, "strict", z.ZodTypeAny, {
316
+ entrypoint: string | URL;
317
+ config?: Record<string, any> | undefined;
318
+ }, {
319
+ entrypoint: string | URL;
320
+ config?: Record<string, any> | undefined;
321
+ }>;
322
+ /**
323
+ * @default `[400]`
324
+ *
325
+ * An array of [font weights](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:
326
+ *
327
+ * ```js
328
+ * weight: "100 900"
329
+ * ```
330
+ */
331
+ weights: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "atleastone">>;
332
+ /**
333
+ * @default `["normal", "italic"]`
334
+ *
335
+ * An array of [font styles](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
336
+ */
337
+ styles: z.ZodOptional<z.ZodArray<z.ZodEnum<["normal", "italic", "oblique"]>, "atleastone">>;
338
+ /**
339
+ * @default `["cyrillic-ext", "cyrillic", "greek-ext", "greek", "vietnamese", "latin-ext", "latin"]`
340
+ *
341
+ * An array of [font subsets](https://fonts.google.com/knowledge/glossary/subsetting):
342
+ */
343
+ subsets: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
344
+ }>, "strict", z.ZodTypeAny, {
345
+ name: string;
346
+ cssVariable: string;
347
+ provider: {
348
+ entrypoint: string | URL;
349
+ config?: Record<string, any> | undefined;
350
+ };
351
+ fallbacks?: [string, ...string[]] | undefined;
352
+ optimizedFallbacks?: boolean | undefined;
353
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
354
+ unicodeRange?: [string, ...string[]] | undefined;
355
+ stretch?: string | undefined;
356
+ featureSettings?: string | undefined;
357
+ variationSettings?: string | undefined;
358
+ weights?: [string | number, ...(string | number)[]] | undefined;
359
+ styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
360
+ subsets?: [string, ...string[]] | undefined;
361
+ }, {
362
+ name: string;
363
+ cssVariable: string;
364
+ provider: {
365
+ entrypoint: string | URL;
366
+ config?: Record<string, any> | undefined;
367
+ };
368
+ fallbacks?: [string, ...string[]] | undefined;
369
+ optimizedFallbacks?: boolean | undefined;
370
+ display?: "fallback" | "auto" | "optional" | "block" | "swap" | undefined;
371
+ unicodeRange?: [string, ...string[]] | undefined;
372
+ stretch?: string | undefined;
373
+ featureSettings?: string | undefined;
374
+ variationSettings?: string | undefined;
375
+ weights?: [string | number, ...(string | number)[]] | undefined;
376
+ styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
377
+ subsets?: [string, ...string[]] | undefined;
378
+ }>;
@@ -0,0 +1,157 @@
1
+ import { z } from "zod";
2
+ import { LOCAL_PROVIDER_NAME } from "./constants.js";
3
+ const weightSchema = z.union([z.string(), z.number()]);
4
+ const styleSchema = z.enum(["normal", "italic", "oblique"]);
5
+ const familyPropertiesSchema = z.object({
6
+ /**
7
+ * 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:
8
+ *
9
+ * ```js
10
+ * weight: "100 900"
11
+ * ```
12
+ */
13
+ weight: weightSchema,
14
+ /**
15
+ * A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
16
+ */
17
+ style: styleSchema,
18
+ /**
19
+ * @default `"swap"`
20
+ *
21
+ * A [font display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display).
22
+ */
23
+ 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
+ /**
29
+ * A [font stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-stretch).
30
+ */
31
+ stretch: z.string().optional(),
32
+ /**
33
+ * Font [feature settings](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-feature-settings).
34
+ */
35
+ featureSettings: z.string().optional(),
36
+ /**
37
+ * Font [variation settings](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-variation-settings).
38
+ */
39
+ variationSettings: z.string().optional()
40
+ });
41
+ const fallbacksSchema = z.object({
42
+ /**
43
+ * @default `["sans-serif"]`
44
+ *
45
+ * An array of fonts to use when your chosen font is unavailable, or loading. Fallback fonts will be chosen in the order listed. The first available font will be used:
46
+ *
47
+ * ```js
48
+ * fallbacks: ["CustomFont", "serif"]
49
+ * ```
50
+ *
51
+ * To disable fallback fonts completely, configure an empty array:
52
+ *
53
+ * ```js
54
+ * fallbacks: []
55
+ * ```
56
+ *
57
+
58
+ * If the last font in the `fallbacks` array is a [generic family name](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family#generic-name), an [optimized fallback](https://developer.chrome.com/blog/font-fallbacks) using font metrics will be generated. To disable this optimization, set `optimizedFallbacks` to false.
59
+ */
60
+ fallbacks: z.array(z.string()).nonempty().optional(),
61
+ /**
62
+ * @default `true`
63
+ *
64
+ * Whether or not to enable optimized fallback generation. You may disable this default optimization to have full control over `fallbacks`.
65
+ */
66
+ optimizedFallbacks: z.boolean().optional()
67
+ });
68
+ const requiredFamilyAttributesSchema = z.object({
69
+ /**
70
+ * The font family name, as identified by your font provider.
71
+ */
72
+ name: z.string(),
73
+ /**
74
+ * A valid [ident](https://developer.mozilla.org/en-US/docs/Web/CSS/ident) in the form of a CSS variable (i.e. starting with `--`).
75
+ */
76
+ cssVariable: z.string()
77
+ });
78
+ const entrypointSchema = z.union([z.string(), z.instanceof(URL)]);
79
+ const fontProviderSchema = z.object({
80
+ /**
81
+ * URL, path relative to the root or package import.
82
+ */
83
+ entrypoint: entrypointSchema,
84
+ /**
85
+ * Optional serializable object passed to the unifont provider.
86
+ */
87
+ config: z.record(z.string(), z.any()).optional()
88
+ }).strict();
89
+ const localFontFamilySchema = requiredFamilyAttributesSchema.merge(fallbacksSchema).merge(
90
+ z.object({
91
+ /**
92
+ * The source of your font files. Set to `"local"` to use local font files.
93
+ */
94
+ provider: z.literal(LOCAL_PROVIDER_NAME),
95
+ /**
96
+ * Each variant represents a [`@font-face` declaration](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/).
97
+ */
98
+ variants: z.array(
99
+ familyPropertiesSchema.merge(
100
+ z.object({
101
+ /**
102
+ * 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.
103
+ */
104
+ src: z.array(
105
+ z.union([
106
+ entrypointSchema,
107
+ z.object({ url: entrypointSchema, tech: z.string().optional() }).strict()
108
+ ])
109
+ ).nonempty()
110
+ // TODO: find a way to support subsets (through fontkit?)
111
+ }).strict()
112
+ )
113
+ ).nonempty()
114
+ })
115
+ ).strict();
116
+ const remoteFontFamilySchema = requiredFamilyAttributesSchema.merge(
117
+ familyPropertiesSchema.omit({
118
+ weight: true,
119
+ style: true
120
+ })
121
+ ).merge(fallbacksSchema).merge(
122
+ z.object({
123
+ /**
124
+ * The source of your font files. You can use a built-in provider or write your own custom provider.
125
+ */
126
+ provider: fontProviderSchema,
127
+ /**
128
+ * @default `[400]`
129
+ *
130
+ * An array of [font weights](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:
131
+ *
132
+ * ```js
133
+ * weight: "100 900"
134
+ * ```
135
+ */
136
+ weights: z.array(weightSchema).nonempty().optional(),
137
+ /**
138
+ * @default `["normal", "italic"]`
139
+ *
140
+ * An array of [font styles](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
141
+ */
142
+ styles: z.array(styleSchema).nonempty().optional(),
143
+ // TODO: better link
144
+ /**
145
+ * @default `["cyrillic-ext", "cyrillic", "greek-ext", "greek", "vietnamese", "latin-ext", "latin"]`
146
+ *
147
+ * An array of [font subsets](https://fonts.google.com/knowledge/glossary/subsetting):
148
+ */
149
+ subsets: z.array(z.string()).nonempty().optional()
150
+ })
151
+ ).strict();
152
+ export {
153
+ fontProviderSchema,
154
+ localFontFamilySchema,
155
+ remoteFontFamilySchema,
156
+ requiredFamilyAttributesSchema
157
+ };
@@ -0,0 +1,15 @@
1
+ export declare const LOCAL_PROVIDER_NAME = "local";
2
+ export declare const DEFAULTS: {
3
+ weights: string[];
4
+ styles: ["normal", "italic"];
5
+ subsets: [string, string, string, string, string, string, string];
6
+ fallbacks: [string];
7
+ optimizedFallbacks: true;
8
+ };
9
+ export declare const VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/internal";
10
+ export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
11
+ export declare const URL_PREFIX = "/_astro/fonts/";
12
+ export declare const CACHE_DIR = "./fonts/";
13
+ export declare const FONT_TYPES: readonly ["woff2", "woff", "otf", "ttf", "eot"];
14
+ export declare const DEFAULT_FALLBACKS: Record<string, Array<string>>;
15
+ export declare const FONTS_TYPES_FILE = "fonts.d.ts";
@@ -0,0 +1,41 @@
1
+ const LOCAL_PROVIDER_NAME = "local";
2
+ const DEFAULTS = {
3
+ weights: ["400"],
4
+ styles: ["normal", "italic"],
5
+ subsets: ["cyrillic-ext", "cyrillic", "greek-ext", "greek", "vietnamese", "latin-ext", "latin"],
6
+ // Technically serif is the browser default but most websites these days use sans-serif
7
+ fallbacks: ["sans-serif"],
8
+ optimizedFallbacks: true
9
+ };
10
+ const VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/internal";
11
+ const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
12
+ const URL_PREFIX = "/_astro/fonts/";
13
+ const CACHE_DIR = "./fonts/";
14
+ const FONT_TYPES = ["woff2", "woff", "otf", "ttf", "eot"];
15
+ const DEFAULT_FALLBACKS = {
16
+ serif: ["Times New Roman"],
17
+ "sans-serif": ["Arial"],
18
+ monospace: ["Courier New"],
19
+ cursive: [],
20
+ fantasy: [],
21
+ "system-ui": ["BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica Neue", "Arial"],
22
+ "ui-serif": ["Times New Roman"],
23
+ "ui-sans-serif": ["Arial"],
24
+ "ui-monospace": ["Courier New"],
25
+ "ui-rounded": [],
26
+ emoji: [],
27
+ math: [],
28
+ fangsong: []
29
+ };
30
+ const FONTS_TYPES_FILE = "fonts.d.ts";
31
+ export {
32
+ CACHE_DIR,
33
+ DEFAULTS,
34
+ DEFAULT_FALLBACKS,
35
+ FONTS_TYPES_FILE,
36
+ FONT_TYPES,
37
+ LOCAL_PROVIDER_NAME,
38
+ RESOLVED_VIRTUAL_MODULE_ID,
39
+ URL_PREFIX,
40
+ VIRTUAL_MODULE_ID
41
+ };