astro 5.16.10 → 5.16.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.
Files changed (37) hide show
  1. package/client.d.ts +2 -4
  2. package/components/Font.astro +1 -1
  3. package/dist/assets/fonts/config.d.ts +31 -28
  4. package/dist/assets/fonts/config.js +1 -0
  5. package/dist/assets/fonts/core/filter-preloads.d.ts +2 -0
  6. package/dist/assets/fonts/core/filter-preloads.js +37 -0
  7. package/dist/assets/fonts/definitions.d.ts +4 -4
  8. package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +11 -4
  9. package/dist/assets/fonts/infra/unifont-font-resolver.js +48 -19
  10. package/dist/assets/fonts/orchestrate.d.ts +2 -2
  11. package/dist/assets/fonts/orchestrate.js +9 -8
  12. package/dist/assets/fonts/providers/index.d.ts +3 -3
  13. package/dist/assets/fonts/providers/index.js +4 -6
  14. package/dist/assets/fonts/runtime.d.ts +1 -5
  15. package/dist/assets/fonts/runtime.js +3 -52
  16. package/dist/assets/fonts/types.d.ts +30 -8
  17. package/dist/assets/fonts/vite-plugin-fonts.js +5 -5
  18. package/dist/assets/vite-plugin-assets.js +1 -4
  19. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  20. package/dist/config/index.d.ts +3 -1
  21. package/dist/content/content-layer.js +3 -3
  22. package/dist/content/runtime.js +2 -2
  23. package/dist/core/build/internal.d.ts +8 -0
  24. package/dist/core/build/internal.js +14 -0
  25. package/dist/core/build/plugins/plugin-analyzer.js +17 -7
  26. package/dist/core/build/plugins/plugin-css.js +90 -2
  27. package/dist/core/config/schemas/base.d.ts +79 -72
  28. package/dist/core/config/schemas/relative.d.ts +103 -94
  29. package/dist/core/constants.js +1 -1
  30. package/dist/core/dev/dev.js +1 -1
  31. package/dist/core/errors/dev/utils.js +1 -1
  32. package/dist/core/errors/errors-data.d.ts +1 -1
  33. package/dist/core/errors/errors-data.js +1 -1
  34. package/dist/core/messages.js +2 -2
  35. package/dist/runtime/server/render/component.js +4 -28
  36. package/dist/types/public/config.d.ts +6 -3
  37. package/package.json +10 -10
package/client.d.ts CHANGED
@@ -54,9 +54,7 @@ declare module 'astro:assets' {
54
54
  Image: typeof import('./components/Image.astro').default;
55
55
  Picture: typeof import('./components/Picture.astro').default;
56
56
  Font: typeof import('./components/Font.astro').default;
57
- getFontData: (
58
- cssVariable: import('astro:assets').CssVariable,
59
- ) => Array<import('astro:assets').FontData>;
57
+ fontData: Record<import('astro:assets').CssVariable, Array<import('astro:assets').FontData>>;
60
58
  };
61
59
 
62
60
  type ImgAttributes = import('./dist/type-utils.js').WithRequired<
@@ -78,7 +76,7 @@ declare module 'astro:assets' {
78
76
  Picture,
79
77
  Font,
80
78
  inferRemoteSize,
81
- getFontData,
79
+ fontData,
82
80
  }: AstroAssets;
83
81
  }
84
82
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import * as mod from 'virtual:astro:assets/fonts/internal';
3
- import { filterPreloads } from 'astro/assets/fonts/runtime';
3
+ 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
@@ -58,9 +58,9 @@ export declare const localFontFamilySchema: z.ZodObject<{
58
58
  name: z.ZodString;
59
59
  cssVariable: z.ZodString;
60
60
  }, "strict", z.ZodTypeAny, {
61
- provider: "local";
62
61
  name: string;
63
62
  cssVariable: string;
63
+ provider: "local";
64
64
  variants: [{
65
65
  src: [string | URL | {
66
66
  url: string | URL;
@@ -95,9 +95,9 @@ export declare const localFontFamilySchema: z.ZodObject<{
95
95
  fallbacks?: string[] | undefined;
96
96
  optimizedFallbacks?: boolean | undefined;
97
97
  }, {
98
- provider: "local";
99
98
  name: string;
100
99
  cssVariable: string;
100
+ provider: "local";
101
101
  variants: [{
102
102
  src: [string | URL | {
103
103
  url: string | URL;
@@ -136,11 +136,11 @@ export declare const fontProviderSchema: z.ZodObject<{
136
136
  name: z.ZodString;
137
137
  config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
138
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) => {
139
+ resolveFont: z.ZodType<(options: import("./types.js").ResolveFontOptions<never>) => {
140
140
  fonts: Array<import("unifont").FontFaceData>;
141
141
  } | Promise<{
142
142
  fonts: Array<import("unifont").FontFaceData>;
143
- } | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions) => {
143
+ } | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions<never>) => {
144
144
  fonts: Array<import("unifont").FontFaceData>;
145
145
  } | Promise<{
146
146
  fonts: Array<import("unifont").FontFaceData>;
@@ -148,7 +148,7 @@ export declare const fontProviderSchema: z.ZodObject<{
148
148
  listFonts: z.ZodOptional<z.ZodType<(() => string[] | Promise<string[] | undefined> | undefined) | undefined, z.ZodTypeDef, (() => string[] | Promise<string[] | undefined> | undefined) | undefined>>;
149
149
  }, "strict", z.ZodTypeAny, {
150
150
  name: string;
151
- resolveFont: (options: import("./types.js").ResolveFontOptions) => {
151
+ resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
152
152
  fonts: Array<import("unifont").FontFaceData>;
153
153
  } | Promise<{
154
154
  fonts: Array<import("unifont").FontFaceData>;
@@ -158,7 +158,7 @@ export declare const fontProviderSchema: z.ZodObject<{
158
158
  listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
159
159
  }, {
160
160
  name: string;
161
- resolveFont: (options: import("./types.js").ResolveFontOptions) => {
161
+ resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
162
162
  fonts: Array<import("unifont").FontFaceData>;
163
163
  } | Promise<{
164
164
  fonts: Array<import("unifont").FontFaceData>;
@@ -172,11 +172,11 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
172
172
  name: z.ZodString;
173
173
  config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
174
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) => {
175
+ resolveFont: z.ZodType<(options: import("./types.js").ResolveFontOptions<never>) => {
176
176
  fonts: Array<import("unifont").FontFaceData>;
177
177
  } | Promise<{
178
178
  fonts: Array<import("unifont").FontFaceData>;
179
- } | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions) => {
179
+ } | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions<never>) => {
180
180
  fonts: Array<import("unifont").FontFaceData>;
181
181
  } | Promise<{
182
182
  fonts: Array<import("unifont").FontFaceData>;
@@ -184,7 +184,7 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
184
184
  listFonts: z.ZodOptional<z.ZodType<(() => string[] | Promise<string[] | undefined> | undefined) | undefined, z.ZodTypeDef, (() => string[] | Promise<string[] | undefined> | undefined) | undefined>>;
185
185
  }, "strict", z.ZodTypeAny, {
186
186
  name: string;
187
- resolveFont: (options: import("./types.js").ResolveFontOptions) => {
187
+ resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
188
188
  fonts: Array<import("unifont").FontFaceData>;
189
189
  } | Promise<{
190
190
  fonts: Array<import("unifont").FontFaceData>;
@@ -194,7 +194,7 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
194
194
  listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
195
195
  }, {
196
196
  name: string;
197
- resolveFont: (options: import("./types.js").ResolveFontOptions) => {
197
+ resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
198
198
  fonts: Array<import("unifont").FontFaceData>;
199
199
  } | Promise<{
200
200
  fonts: Array<import("unifont").FontFaceData>;
@@ -203,6 +203,7 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
203
203
  init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
204
204
  listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
205
205
  }>;
206
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
206
207
  weights: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "atleastone">>;
207
208
  styles: z.ZodOptional<z.ZodArray<z.ZodEnum<["normal", "italic", "oblique"]>, "atleastone">>;
208
209
  subsets: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
@@ -217,9 +218,11 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
217
218
  name: z.ZodString;
218
219
  cssVariable: z.ZodString;
219
220
  }, "strict", z.ZodTypeAny, {
221
+ name: string;
222
+ cssVariable: string;
220
223
  provider: {
221
224
  name: string;
222
- resolveFont: (options: import("./types.js").ResolveFontOptions) => {
225
+ resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
223
226
  fonts: Array<import("unifont").FontFaceData>;
224
227
  } | Promise<{
225
228
  fonts: Array<import("unifont").FontFaceData>;
@@ -228,23 +231,24 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
228
231
  init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
229
232
  listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
230
233
  };
231
- name: string;
232
- cssVariable: string;
233
- weights?: [string | number, ...(string | number)[]] | undefined;
234
- styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
235
- subsets?: [string, ...string[]] | undefined;
236
- fallbacks?: string[] | undefined;
237
- optimizedFallbacks?: boolean | undefined;
238
- formats?: ["woff2" | "woff" | "otf" | "ttf" | "eot", ...("woff2" | "woff" | "otf" | "ttf" | "eot")[]] | undefined;
234
+ options?: Record<string, any> | undefined;
239
235
  display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
240
236
  stretch?: string | undefined;
241
237
  featureSettings?: string | undefined;
242
238
  variationSettings?: string | undefined;
243
239
  unicodeRange?: [string, ...string[]] | undefined;
240
+ fallbacks?: string[] | undefined;
241
+ optimizedFallbacks?: boolean | undefined;
242
+ weights?: [string | number, ...(string | number)[]] | undefined;
243
+ styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
244
+ subsets?: [string, ...string[]] | undefined;
245
+ formats?: ["woff2" | "woff" | "otf" | "ttf" | "eot", ...("woff2" | "woff" | "otf" | "ttf" | "eot")[]] | undefined;
244
246
  }, {
247
+ name: string;
248
+ cssVariable: string;
245
249
  provider: {
246
250
  name: string;
247
- resolveFont: (options: import("./types.js").ResolveFontOptions) => {
251
+ resolveFont: (options: import("./types.js").ResolveFontOptions<never>) => {
248
252
  fonts: Array<import("unifont").FontFaceData>;
249
253
  } | Promise<{
250
254
  fonts: Array<import("unifont").FontFaceData>;
@@ -253,17 +257,16 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
253
257
  init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
254
258
  listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
255
259
  };
256
- name: string;
257
- cssVariable: string;
258
- weights?: [string | number, ...(string | number)[]] | undefined;
259
- styles?: ["normal" | "italic" | "oblique", ...("normal" | "italic" | "oblique")[]] | undefined;
260
- subsets?: [string, ...string[]] | undefined;
261
- fallbacks?: string[] | undefined;
262
- optimizedFallbacks?: boolean | undefined;
263
- formats?: ["woff2" | "woff" | "otf" | "ttf" | "eot", ...("woff2" | "woff" | "otf" | "ttf" | "eot")[]] | undefined;
260
+ options?: Record<string, any> | undefined;
264
261
  display?: "auto" | "block" | "swap" | "fallback" | "optional" | undefined;
265
262
  stretch?: string | undefined;
266
263
  featureSettings?: string | undefined;
267
264
  variationSettings?: string | undefined;
268
265
  unicodeRange?: [string, ...string[]] | undefined;
266
+ fallbacks?: string[] | undefined;
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;
269
272
  }>;
@@ -53,6 +53,7 @@ const remoteFontFamilySchema = z.object({
53
53
  style: true
54
54
  }).shape,
55
55
  provider: fontProviderSchema,
56
+ options: z.record(z.string(), z.any()).optional(),
56
57
  weights: z.array(weightSchema).nonempty().optional(),
57
58
  styles: z.array(styleSchema).nonempty().optional(),
58
59
  subsets: z.array(z.string()).nonempty().optional(),
@@ -0,0 +1,2 @@
1
+ import type { PreloadData, PreloadFilter } from '../types.js';
2
+ export declare function filterPreloads(data: Array<PreloadData>, preload: PreloadFilter): Array<PreloadData> | null;
@@ -0,0 +1,37 @@
1
+ function filterPreloads(data, preload) {
2
+ if (!preload) {
3
+ return null;
4
+ }
5
+ if (preload === true) {
6
+ return data;
7
+ }
8
+ return data.filter(
9
+ ({ weight, style, subset }) => preload.some((p) => {
10
+ if (p.weight !== void 0 && weight !== void 0 && !checkWeight(p.weight.toString(), weight)) {
11
+ return false;
12
+ }
13
+ if (p.style !== void 0 && p.style !== style) {
14
+ return false;
15
+ }
16
+ if (p.subset !== void 0 && p.subset !== subset) {
17
+ return false;
18
+ }
19
+ return true;
20
+ })
21
+ );
22
+ }
23
+ function checkWeight(input, target) {
24
+ const trimmedInput = input.trim();
25
+ if (trimmedInput.includes(" ")) {
26
+ return trimmedInput === target;
27
+ }
28
+ if (target.includes(" ")) {
29
+ const [a, b] = target.split(" ");
30
+ const parsedInput = Number.parseInt(input);
31
+ return parsedInput >= Number.parseInt(a) && parsedInput <= Number.parseInt(b);
32
+ }
33
+ return input === target;
34
+ }
35
+ export {
36
+ filterPreloads
37
+ };
@@ -1,6 +1,6 @@
1
1
  import type * as unifont from 'unifont';
2
2
  import type { CollectedFontForMetrics } from './core/optimize-fallbacks.js';
3
- import type { FontFaceMetrics, FontFileData, FontType, GenericFallbackName, PreloadData, ResolveFontOptions, Style } from './types.js';
3
+ import type { FontFaceMetrics, FontFileData, FontProvider, FontType, GenericFallbackName, PreloadData, ResolveFontOptions, Style } from './types.js';
4
4
  export interface Hasher {
5
5
  hashString: (input: string) => string;
6
6
  hashObject: (input: Record<string, any>) => string;
@@ -85,10 +85,10 @@ export interface Storage {
85
85
  setItemRaw: (key: string, value: any) => Promise<void>;
86
86
  }
87
87
  export interface FontResolver {
88
- resolveFont: (options: ResolveFontOptions & {
89
- provider: string;
88
+ resolveFont: (options: ResolveFontOptions<Record<string, any>> & {
89
+ provider: FontProvider;
90
90
  }) => Promise<Array<unifont.FontFaceData>>;
91
91
  listFonts: (options: {
92
- provider: string;
92
+ provider: FontProvider;
93
93
  }) => Promise<string[] | undefined>;
94
94
  }
@@ -1,10 +1,17 @@
1
1
  import type { FontFaceData, Provider } from 'unifont';
2
2
  import type { FontResolver, Hasher, Storage } from '../definitions.js';
3
3
  import type { FontProvider, ResolvedFontFamily, ResolveFontOptions } from '../types.js';
4
- type NonEmptyProviders = [Provider, ...Array<Provider>];
4
+ type NonEmptyProviders = [
5
+ Provider<string, Record<string, any>>,
6
+ ...Array<Provider<string, Record<string, any>>>
7
+ ];
5
8
  export declare class UnifontFontResolver implements FontResolver {
6
9
  #private;
7
10
  private constructor();
11
+ static idFromProvider({ hasher, provider }: {
12
+ hasher: Hasher;
13
+ provider: FontProvider;
14
+ }): string;
8
15
  static astroToUnifontProvider(astroProvider: FontProvider): Provider;
9
16
  static extractUnifontProviders({ families, hasher, }: {
10
17
  families: Array<ResolvedFontFamily>;
@@ -15,11 +22,11 @@ export declare class UnifontFontResolver implements FontResolver {
15
22
  hasher: Hasher;
16
23
  storage: Storage;
17
24
  }): Promise<UnifontFontResolver>;
18
- resolveFont({ familyName, provider, ...rest }: ResolveFontOptions & {
19
- provider: string;
25
+ resolveFont({ familyName, provider, options, ...rest }: ResolveFontOptions<Record<string, any>> & {
26
+ provider: FontProvider;
20
27
  }): Promise<Array<FontFaceData>>;
21
28
  listFonts({ provider }: {
22
- provider: string;
29
+ provider: FontProvider;
23
30
  }): Promise<string[] | undefined>;
24
31
  }
25
32
  export {};
@@ -2,15 +2,27 @@ import { createUnifont, defineFontProvider } from "unifont";
2
2
  import { LOCAL_PROVIDER_NAME } from "../constants.js";
3
3
  class UnifontFontResolver {
4
4
  #unifont;
5
- constructor({ unifont }) {
5
+ #hasher;
6
+ constructor({
7
+ unifont,
8
+ hasher
9
+ }) {
6
10
  this.#unifont = unifont;
11
+ this.#hasher = hasher;
12
+ }
13
+ static idFromProvider({ hasher, provider }) {
14
+ const hash = hasher.hashObject({
15
+ name: provider.name,
16
+ ...provider.config
17
+ });
18
+ return `${provider.name}-${hash}`;
7
19
  }
8
20
  static astroToUnifontProvider(astroProvider) {
9
21
  return defineFontProvider(astroProvider.name, async (_options, ctx) => {
10
22
  await astroProvider?.init?.(ctx);
11
23
  return {
12
- async resolveFont(familyName, options) {
13
- return await astroProvider.resolveFont({ familyName, ...options });
24
+ async resolveFont(familyName, { options, ...rest }) {
25
+ return await astroProvider.resolveFont({ familyName, options, ...rest });
14
26
  },
15
27
  async listFonts() {
16
28
  return astroProvider.listFonts?.();
@@ -22,25 +34,19 @@ class UnifontFontResolver {
22
34
  families,
23
35
  hasher
24
36
  }) {
25
- const hashes = /* @__PURE__ */ new Set();
26
- const providers = [];
37
+ const providers = /* @__PURE__ */ new Map();
27
38
  for (const { provider } of families) {
28
39
  if (provider === LOCAL_PROVIDER_NAME) {
29
40
  continue;
30
41
  }
31
- const unifontProvider = this.astroToUnifontProvider(provider);
32
- const hash = hasher.hashObject({
33
- name: unifontProvider._name,
34
- ...provider.config
35
- });
36
- unifontProvider._name += `-${hash}`;
37
- provider.name = unifontProvider._name;
38
- if (!hashes.has(hash)) {
39
- hashes.add(hash);
40
- providers.push(unifontProvider);
42
+ const id = this.idFromProvider({ hasher, provider });
43
+ if (!providers.has(id)) {
44
+ const unifontProvider = this.astroToUnifontProvider(provider);
45
+ unifontProvider._name = this.idFromProvider({ hasher, provider });
46
+ providers.set(id, unifontProvider);
41
47
  }
42
48
  }
43
- return providers;
49
+ return Array.from(providers.values());
44
50
  }
45
51
  static async create({
46
52
  families,
@@ -52,19 +58,42 @@ class UnifontFontResolver {
52
58
  storage,
53
59
  // TODO: consider enabling, would require new astro errors
54
60
  throwOnError: false
55
- })
61
+ }),
62
+ hasher
56
63
  });
57
64
  }
58
65
  async resolveFont({
59
66
  familyName,
60
67
  provider,
68
+ options,
61
69
  ...rest
62
70
  }) {
63
- const { fonts } = await this.#unifont.resolveFont(familyName, rest, [provider]);
71
+ const { fonts } = await this.#unifont.resolveFont(
72
+ familyName,
73
+ {
74
+ // Options are currently namespaced by provider name, it may change in
75
+ // https://github.com/unjs/unifont/pull/287
76
+ options: {
77
+ [provider.name]: options
78
+ },
79
+ ...rest
80
+ },
81
+ [
82
+ UnifontFontResolver.idFromProvider({
83
+ hasher: this.#hasher,
84
+ provider
85
+ })
86
+ ]
87
+ );
64
88
  return fonts;
65
89
  }
66
90
  async listFonts({ provider }) {
67
- return await this.#unifont.listFonts([provider]);
91
+ return await this.#unifont.listFonts([
92
+ UnifontFontResolver.idFromProvider({
93
+ hasher: this.#hasher,
94
+ provider
95
+ })
96
+ ]);
68
97
  }
69
98
  }
70
99
  export {
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from '../../core/logger/core.js';
2
2
  import type { CssRenderer, FontFileReader, FontMetricsResolver, FontResolver, FontTypeExtractor, Hasher, LocalProviderUrlResolver, StringMatcher, SystemFallbacksProvider, UrlProxy } from './definitions.js';
3
- import type { ConsumableMap, CreateUrlProxyParams, Defaults, FontFamily, FontFileDataMap, InternalConsumableMap, ResolvedFontFamily } from './types.js';
3
+ import type { CreateUrlProxyParams, Defaults, FontDataRecord, FontFamily, FontFileDataMap, InternalConsumableMap, ResolvedFontFamily } from './types.js';
4
4
  /**
5
5
  * Manages how fonts are resolved:
6
6
  *
@@ -38,5 +38,5 @@ export declare function orchestrate({ families, hasher, localProviderUrlResolver
38
38
  }): Promise<{
39
39
  fontFileDataMap: FontFileDataMap;
40
40
  internalConsumableMap: InternalConsumableMap;
41
- consumableMap: ConsumableMap;
41
+ fontData: FontDataRecord;
42
42
  }>;
@@ -32,7 +32,7 @@ async function orchestrate({
32
32
  const fontResolver = await createFontResolver({ families: resolvedFamilies });
33
33
  const fontFileDataMap = /* @__PURE__ */ new Map();
34
34
  const internalConsumableMap = /* @__PURE__ */ new Map();
35
- const consumableMap = /* @__PURE__ */ new Map();
35
+ const fontData = {};
36
36
  const resolvedFamiliesMap = /* @__PURE__ */ new Map();
37
37
  for (const family of resolvedFamilies) {
38
38
  const key = `${family.cssVariable}:${family.name}:${typeof family.provider === "string" ? family.provider : family.provider.name}`;
@@ -88,19 +88,20 @@ async function orchestrate({
88
88
  } else {
89
89
  const fonts = await fontResolver.resolveFont({
90
90
  familyName: family.name,
91
- provider: family.provider.name,
91
+ provider: family.provider,
92
92
  // We do not merge the defaults, we only provide defaults as a fallback
93
93
  weights: family.weights ?? defaults.weights,
94
94
  styles: family.styles ?? defaults.styles,
95
95
  subsets: family.subsets ?? defaults.subsets,
96
- formats: family.formats ?? defaults.formats
96
+ formats: family.formats ?? defaults.formats,
97
+ options: family.options
97
98
  });
98
99
  if (fonts.length === 0) {
99
100
  logger.warn(
100
101
  "assets",
101
102
  `No data found for font family ${bold(family.name)}. Review your configuration`
102
103
  );
103
- const availableFamilies = await fontResolver.listFonts({ provider: family.provider.name });
104
+ const availableFamilies = await fontResolver.listFonts({ provider: family.provider });
104
105
  if (availableFamilies && availableFamilies.length > 0 && !availableFamilies.includes(family.name)) {
105
106
  logger.warn(
106
107
  "assets",
@@ -118,7 +119,7 @@ async function orchestrate({
118
119
  collectedFonts,
119
120
  preloadData
120
121
  } of resolvedFamiliesMap.values()) {
121
- const consumableMapValue = [];
122
+ const fontDataValue = [];
122
123
  let css = "";
123
124
  for (const data of fonts) {
124
125
  css += cssRenderer.generateFontFace(
@@ -136,7 +137,7 @@ async function orchestrate({
136
137
  variationSettings: pickFontFaceProperty("variationSettings", { data, family })
137
138
  })
138
139
  );
139
- consumableMapValue.push({
140
+ fontDataValue.push({
140
141
  weight: renderFontWeight(data.weight),
141
142
  style: data.style,
142
143
  src: data.src.filter((src) => "url" in src).map((src) => ({
@@ -163,9 +164,9 @@ async function orchestrate({
163
164
  }
164
165
  css += cssRenderer.generateCssVariable(family.cssVariable, cssVarValues);
165
166
  internalConsumableMap.set(family.cssVariable, { preloadData, css });
166
- consumableMap.set(family.cssVariable, consumableMapValue);
167
+ fontData[family.cssVariable] = fontDataValue;
167
168
  }
168
- return { fontFileDataMap, internalConsumableMap, consumableMap };
169
+ return { fontFileDataMap, internalConsumableMap, fontData };
169
170
  }
170
171
  export {
171
172
  orchestrate
@@ -1,4 +1,4 @@
1
- import { type AdobeProviderOptions, type GoogleiconsOptions, type GoogleOptions } from 'unifont';
1
+ import { type AdobeProviderOptions, type GoogleFamilyOptions, type GoogleiconsFamilyOptions } from 'unifont';
2
2
  import type { FontProvider } from '../types.js';
3
3
  /** [Adobe](https://fonts.adobe.com/) */
4
4
  declare function adobe(config: AdobeProviderOptions): FontProvider;
@@ -9,9 +9,9 @@ declare function fontshare(): FontProvider;
9
9
  /** [Fontsource](https://fontsource.org/) */
10
10
  declare function fontsource(): FontProvider;
11
11
  /** [Google](https://fonts.google.com/) */
12
- declare function google(config?: GoogleOptions): FontProvider;
12
+ declare function google(): FontProvider<GoogleFamilyOptions | undefined>;
13
13
  /** [Google Icons](https://fonts.google.com/icons) */
14
- declare function googleicons(config?: GoogleiconsOptions): FontProvider;
14
+ declare function googleicons(): FontProvider<GoogleiconsFamilyOptions | undefined>;
15
15
  /**
16
16
  * Astro re-exports most [unifont](https://github.com/unjs/unifont/) providers:
17
17
  * - [Adobe](https://fonts.adobe.com/)
@@ -66,12 +66,11 @@ function fontsource() {
66
66
  }
67
67
  };
68
68
  }
69
- function google(config) {
70
- const provider = providers.google(config);
69
+ function google() {
70
+ const provider = providers.google();
71
71
  let initializedProvider;
72
72
  return {
73
73
  name: provider._name,
74
- config,
75
74
  async init(context) {
76
75
  initializedProvider = await provider(context);
77
76
  },
@@ -83,12 +82,11 @@ function google(config) {
83
82
  }
84
83
  };
85
84
  }
86
- function googleicons(config) {
87
- const provider = providers.googleicons(config);
85
+ function googleicons() {
86
+ const provider = providers.googleicons();
88
87
  let initializedProvider;
89
88
  return {
90
89
  name: provider._name,
91
- config,
92
90
  async init(context) {
93
91
  initializedProvider = await provider(context);
94
92
  },
@@ -1,5 +1 @@
1
- import type { ConsumableMap, PreloadData, PreloadFilter } from './types.js';
2
- export declare function createGetFontData({ consumableMap }: {
3
- consumableMap?: ConsumableMap;
4
- }): (cssVariable: string) => import("./types.js").FontData[];
5
- export declare function filterPreloads(data: Array<PreloadData>, preload: PreloadFilter): Array<PreloadData> | null;
1
+ export declare const fontData: import("./types.js").FontDataRecord;
@@ -1,54 +1,5 @@
1
- import { AstroError, AstroErrorData } from "../../core/errors/index.js";
2
- function createGetFontData({ consumableMap }) {
3
- return function getFontData(cssVariable) {
4
- if (!consumableMap) {
5
- throw new AstroError(AstroErrorData.ExperimentalFontsNotEnabled);
6
- }
7
- const data = consumableMap.get(cssVariable);
8
- if (!data) {
9
- throw new AstroError({
10
- ...AstroErrorData.FontFamilyNotFound,
11
- message: AstroErrorData.FontFamilyNotFound.message(cssVariable)
12
- });
13
- }
14
- return data;
15
- };
16
- }
17
- function filterPreloads(data, preload) {
18
- if (!preload) {
19
- return null;
20
- }
21
- if (preload === true) {
22
- return data;
23
- }
24
- return data.filter(
25
- ({ weight, style, subset }) => preload.some((p) => {
26
- if (p.weight !== void 0 && weight !== void 0 && !checkWeight(p.weight.toString(), weight)) {
27
- return false;
28
- }
29
- if (p.style !== void 0 && p.style !== style) {
30
- return false;
31
- }
32
- if (p.subset !== void 0 && p.subset !== subset) {
33
- return false;
34
- }
35
- return true;
36
- })
37
- );
38
- }
39
- function checkWeight(input, target) {
40
- const trimmedInput = input.trim();
41
- if (trimmedInput.includes(" ")) {
42
- return trimmedInput === target;
43
- }
44
- if (target.includes(" ")) {
45
- const [a, b] = target.split(" ");
46
- const parsedInput = Number.parseInt(input);
47
- return parsedInput >= Number.parseInt(a) && parsedInput <= Number.parseInt(b);
48
- }
49
- return input === target;
50
- }
1
+ import * as fontsMod from "virtual:astro:assets/fonts/internal";
2
+ const fontData = fontsMod.fontData ?? {};
51
3
  export {
52
- createGetFontData,
53
- filterPreloads
4
+ fontData
54
5
  };