astro 5.16.8 → 5.16.9

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 (50) hide show
  1. package/dist/assets/fonts/config.d.ts +79 -5
  2. package/dist/assets/fonts/config.js +9 -4
  3. package/dist/assets/fonts/core/resolve-families.d.ts +4 -5
  4. package/dist/assets/fonts/core/resolve-families.js +8 -13
  5. package/dist/assets/fonts/definitions.d.ts +1 -7
  6. package/dist/assets/fonts/infra/require-local-provider-url-resolver.js +11 -3
  7. package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +2 -1
  8. package/dist/assets/fonts/infra/unifont-font-resolver.js +15 -2
  9. package/dist/assets/fonts/orchestrate.d.ts +3 -5
  10. package/dist/assets/fonts/orchestrate.js +3 -8
  11. package/dist/assets/fonts/providers/index.d.ts +7 -3
  12. package/dist/assets/fonts/providers/index.js +84 -8
  13. package/dist/assets/fonts/providers/local.d.ts +1 -3
  14. package/dist/assets/fonts/providers/local.js +40 -42
  15. package/dist/assets/fonts/types.d.ts +34 -15
  16. package/dist/assets/fonts/utils.d.ts +0 -1
  17. package/dist/assets/fonts/utils.js +0 -11
  18. package/dist/assets/fonts/vite-plugin-fonts.js +19 -22
  19. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  20. package/dist/content/content-layer.js +3 -3
  21. package/dist/core/config/schemas/base.d.ts +82 -15
  22. package/dist/core/config/schemas/relative.d.ts +100 -19
  23. package/dist/core/constants.js +1 -1
  24. package/dist/core/dev/dev.js +1 -1
  25. package/dist/core/messages.js +2 -2
  26. package/dist/runtime/server/jsx.js +18 -4
  27. package/dist/runtime/server/render/common.js +8 -0
  28. package/dist/runtime/server/render/component.js +28 -4
  29. package/dist/runtime/server/render/instruction.d.ts +6 -1
  30. package/dist/runtime/server/render/script.d.ts +5 -1
  31. package/dist/runtime/server/render/script.js +7 -10
  32. package/dist/runtime/server/render/slot.d.ts +5 -0
  33. package/dist/runtime/server/render/slot.js +9 -4
  34. package/package.json +1 -2
  35. package/dist/assets/fonts/infra/build-remote-font-provider-mod-resolver.d.ts +0 -4
  36. package/dist/assets/fonts/infra/build-remote-font-provider-mod-resolver.js +0 -8
  37. package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.d.ts +0 -9
  38. package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.js +0 -14
  39. package/dist/assets/fonts/infra/remote-font-provider-resolver.d.ts +0 -10
  40. package/dist/assets/fonts/infra/remote-font-provider-resolver.js +0 -49
  41. package/dist/assets/fonts/providers/entrypoints/adobe.d.ts +0 -2
  42. package/dist/assets/fonts/providers/entrypoints/adobe.js +0 -5
  43. package/dist/assets/fonts/providers/entrypoints/bunny.d.ts +0 -1
  44. package/dist/assets/fonts/providers/entrypoints/bunny.js +0 -5
  45. package/dist/assets/fonts/providers/entrypoints/fontshare.d.ts +0 -1
  46. package/dist/assets/fonts/providers/entrypoints/fontshare.js +0 -5
  47. package/dist/assets/fonts/providers/entrypoints/fontsource.d.ts +0 -1
  48. package/dist/assets/fonts/providers/entrypoints/fontsource.js +0 -5
  49. package/dist/assets/fonts/providers/entrypoints/google.d.ts +0 -2
  50. package/dist/assets/fonts/providers/entrypoints/google.js +0 -5
@@ -132,16 +132,76 @@ export declare const localFontFamilySchema: z.ZodObject<{
132
132
  fallbacks?: string[] | undefined;
133
133
  optimizedFallbacks?: boolean | undefined;
134
134
  }>;
135
+ export declare const fontProviderSchema: z.ZodObject<{
136
+ name: z.ZodString;
137
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
138
+ init: z.ZodOptional<z.ZodType<((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined, z.ZodTypeDef, ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined>>;
139
+ resolveFont: z.ZodType<(options: import("./types.js").ResolveFontOptions) => {
140
+ fonts: Array<import("unifont").FontFaceData>;
141
+ } | Promise<{
142
+ fonts: Array<import("unifont").FontFaceData>;
143
+ } | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions) => {
144
+ fonts: Array<import("unifont").FontFaceData>;
145
+ } | Promise<{
146
+ fonts: Array<import("unifont").FontFaceData>;
147
+ } | undefined> | undefined>;
148
+ listFonts: z.ZodOptional<z.ZodType<(() => string[] | Promise<string[] | undefined> | undefined) | undefined, z.ZodTypeDef, (() => string[] | Promise<string[] | undefined> | undefined) | undefined>>;
149
+ }, "strict", z.ZodTypeAny, {
150
+ name: string;
151
+ resolveFont: (options: import("./types.js").ResolveFontOptions) => {
152
+ fonts: Array<import("unifont").FontFaceData>;
153
+ } | Promise<{
154
+ fonts: Array<import("unifont").FontFaceData>;
155
+ } | undefined> | undefined;
156
+ config?: Record<string, any> | undefined;
157
+ init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
158
+ listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
159
+ }, {
160
+ name: string;
161
+ resolveFont: (options: import("./types.js").ResolveFontOptions) => {
162
+ fonts: Array<import("unifont").FontFaceData>;
163
+ } | Promise<{
164
+ fonts: Array<import("unifont").FontFaceData>;
165
+ } | undefined> | undefined;
166
+ config?: Record<string, any> | undefined;
167
+ init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
168
+ listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
169
+ }>;
135
170
  export declare const remoteFontFamilySchema: z.ZodObject<{
136
171
  provider: z.ZodObject<{
137
- entrypoint: z.ZodUnion<[z.ZodString, z.ZodType<URL, z.ZodTypeDef, URL>]>;
172
+ name: z.ZodString;
138
173
  config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
174
+ init: z.ZodOptional<z.ZodType<((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined, z.ZodTypeDef, ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined>>;
175
+ resolveFont: z.ZodType<(options: import("./types.js").ResolveFontOptions) => {
176
+ fonts: Array<import("unifont").FontFaceData>;
177
+ } | Promise<{
178
+ fonts: Array<import("unifont").FontFaceData>;
179
+ } | undefined> | undefined, z.ZodTypeDef, (options: import("./types.js").ResolveFontOptions) => {
180
+ fonts: Array<import("unifont").FontFaceData>;
181
+ } | Promise<{
182
+ fonts: Array<import("unifont").FontFaceData>;
183
+ } | undefined> | undefined>;
184
+ listFonts: z.ZodOptional<z.ZodType<(() => string[] | Promise<string[] | undefined> | undefined) | undefined, z.ZodTypeDef, (() => string[] | Promise<string[] | undefined> | undefined) | undefined>>;
139
185
  }, "strict", z.ZodTypeAny, {
140
- entrypoint: string | URL;
186
+ name: string;
187
+ resolveFont: (options: import("./types.js").ResolveFontOptions) => {
188
+ fonts: Array<import("unifont").FontFaceData>;
189
+ } | Promise<{
190
+ fonts: Array<import("unifont").FontFaceData>;
191
+ } | undefined> | undefined;
141
192
  config?: Record<string, any> | undefined;
193
+ init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
194
+ listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
142
195
  }, {
143
- entrypoint: string | URL;
196
+ name: string;
197
+ resolveFont: (options: import("./types.js").ResolveFontOptions) => {
198
+ fonts: Array<import("unifont").FontFaceData>;
199
+ } | Promise<{
200
+ fonts: Array<import("unifont").FontFaceData>;
201
+ } | undefined> | undefined;
144
202
  config?: Record<string, any> | undefined;
203
+ init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
204
+ listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
145
205
  }>;
146
206
  weights: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "atleastone">>;
147
207
  styles: z.ZodOptional<z.ZodArray<z.ZodEnum<["normal", "italic", "oblique"]>, "atleastone">>;
@@ -158,8 +218,15 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
158
218
  cssVariable: z.ZodString;
159
219
  }, "strict", z.ZodTypeAny, {
160
220
  provider: {
161
- entrypoint: string | URL;
221
+ name: string;
222
+ resolveFont: (options: import("./types.js").ResolveFontOptions) => {
223
+ fonts: Array<import("unifont").FontFaceData>;
224
+ } | Promise<{
225
+ fonts: Array<import("unifont").FontFaceData>;
226
+ } | undefined> | undefined;
162
227
  config?: Record<string, any> | undefined;
228
+ init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
229
+ listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
163
230
  };
164
231
  name: string;
165
232
  cssVariable: string;
@@ -176,8 +243,15 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
176
243
  unicodeRange?: [string, ...string[]] | undefined;
177
244
  }, {
178
245
  provider: {
179
- entrypoint: string | URL;
246
+ name: string;
247
+ resolveFont: (options: import("./types.js").ResolveFontOptions) => {
248
+ fonts: Array<import("unifont").FontFaceData>;
249
+ } | Promise<{
250
+ fonts: Array<import("unifont").FontFaceData>;
251
+ } | undefined> | undefined;
180
252
  config?: Record<string, any> | undefined;
253
+ init?: ((context: import("./types.js").FontProviderInitContext) => void | Promise<void>) | undefined;
254
+ listFonts?: (() => string[] | Promise<string[] | undefined> | undefined) | undefined;
181
255
  };
182
256
  name: string;
183
257
  cssVariable: string;
@@ -38,6 +38,13 @@ const localFontFamilySchema = z.object({
38
38
  }).strict()
39
39
  ).nonempty()
40
40
  }).strict();
41
+ const fontProviderSchema = z.object({
42
+ name: z.string(),
43
+ config: z.record(z.string(), z.any()).optional(),
44
+ init: z.custom((v) => typeof v === "function").optional(),
45
+ resolveFont: z.custom((v) => typeof v === "function"),
46
+ listFonts: z.custom((v) => typeof v === "function").optional()
47
+ }).strict();
41
48
  const remoteFontFamilySchema = z.object({
42
49
  ...requiredFamilyAttributesSchema.shape,
43
50
  ...fallbacksSchema.shape,
@@ -45,10 +52,7 @@ const remoteFontFamilySchema = z.object({
45
52
  weight: true,
46
53
  style: true
47
54
  }).shape,
48
- provider: z.object({
49
- entrypoint: entrypointSchema,
50
- config: z.record(z.string(), z.any()).optional()
51
- }).strict(),
55
+ provider: fontProviderSchema,
52
56
  weights: z.array(weightSchema).nonempty().optional(),
53
57
  styles: z.array(styleSchema).nonempty().optional(),
54
58
  subsets: z.array(z.string()).nonempty().optional(),
@@ -56,6 +60,7 @@ const remoteFontFamilySchema = z.object({
56
60
  }).strict();
57
61
  export {
58
62
  displaySchema,
63
+ fontProviderSchema,
59
64
  localFontFamilySchema,
60
65
  remoteFontFamilySchema,
61
66
  styleSchema,
@@ -1,17 +1,16 @@
1
- import type { Hasher, LocalProviderUrlResolver, RemoteFontProviderResolver } from '../definitions.js';
1
+ import type { Hasher, LocalProviderUrlResolver } from '../definitions.js';
2
2
  import type { FontFamily, ResolvedFontFamily } from '../types.js';
3
3
  /**
4
4
  * Dedupes properties if applicable and resolves entrypoints.
5
5
  */
6
- export declare function resolveFamily({ family, hasher, remoteFontProviderResolver, localProviderUrlResolver, }: {
6
+ export declare function resolveFamily({ family, hasher, localProviderUrlResolver, }: {
7
7
  family: FontFamily;
8
8
  hasher: Hasher;
9
- remoteFontProviderResolver: RemoteFontProviderResolver;
10
9
  localProviderUrlResolver: LocalProviderUrlResolver;
11
- }): Promise<ResolvedFontFamily>;
10
+ }): ResolvedFontFamily;
12
11
  /**
13
12
  * A function for convenience. The actual logic lives in resolveFamily
14
13
  */
15
14
  export declare function resolveFamilies({ families, ...dependencies }: {
16
15
  families: Array<FontFamily>;
17
- } & Omit<Parameters<typeof resolveFamily>[0], 'family'>): Promise<Array<ResolvedFontFamily>>;
16
+ } & Omit<Parameters<typeof resolveFamily>[0], 'family'>): Array<ResolvedFontFamily>;
@@ -18,10 +18,9 @@ function resolveVariants({
18
18
  })
19
19
  }));
20
20
  }
21
- async function resolveFamily({
21
+ function resolveFamily({
22
22
  family,
23
23
  hasher,
24
- remoteFontProviderResolver,
25
24
  localProviderUrlResolver
26
25
  }) {
27
26
  const name = withoutQuotes(family.name);
@@ -44,22 +43,18 @@ async function resolveFamily({
44
43
  subsets: family.subsets ? dedupe(family.subsets) : void 0,
45
44
  formats: family.formats ? dedupe(family.formats) : void 0,
46
45
  fallbacks: family.fallbacks ? dedupe(family.fallbacks) : void 0,
47
- unicodeRange: family.unicodeRange ? dedupe(family.unicodeRange) : void 0,
48
- // This will be Astro specific eventually
49
- provider: await remoteFontProviderResolver.resolve(family.provider)
46
+ unicodeRange: family.unicodeRange ? dedupe(family.unicodeRange) : void 0
50
47
  };
51
48
  }
52
- async function resolveFamilies({
49
+ function resolveFamilies({
53
50
  families,
54
51
  ...dependencies
55
52
  }) {
56
- return await Promise.all(
57
- families.map(
58
- (family) => resolveFamily({
59
- family,
60
- ...dependencies
61
- })
62
- )
53
+ return families.map(
54
+ (family) => resolveFamily({
55
+ family,
56
+ ...dependencies
57
+ })
63
58
  );
64
59
  }
65
60
  export {
@@ -1,16 +1,10 @@
1
1
  import type * as unifont from 'unifont';
2
2
  import type { CollectedFontForMetrics } from './core/optimize-fallbacks.js';
3
- import type { FontFaceMetrics, FontFileData, FontProvider, FontType, GenericFallbackName, PreloadData, ResolvedFontProvider, ResolveFontOptions, Style } from './types.js';
3
+ import type { FontFaceMetrics, FontFileData, 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;
7
7
  }
8
- export interface RemoteFontProviderModResolver {
9
- resolve: (id: string) => Promise<any>;
10
- }
11
- export interface RemoteFontProviderResolver {
12
- resolve: (provider: FontProvider) => Promise<ResolvedFontProvider>;
13
- }
14
8
  export interface LocalProviderUrlResolver {
15
9
  resolve: (input: string) => string;
16
10
  }
@@ -1,5 +1,5 @@
1
- import { fileURLToPath } from "node:url";
2
- import { resolveEntrypoint } from "../utils.js";
1
+ import { createRequire } from "node:module";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  class RequireLocalProviderUrlResolver {
4
4
  #root;
5
5
  // TODO: remove when stabilizing
@@ -11,8 +11,16 @@ class RequireLocalProviderUrlResolver {
11
11
  this.#root = root;
12
12
  this.#intercept = intercept;
13
13
  }
14
+ #resolveEntrypoint(root, entrypoint) {
15
+ const require2 = createRequire(root);
16
+ try {
17
+ return pathToFileURL(require2.resolve(entrypoint));
18
+ } catch {
19
+ return new URL(entrypoint, root);
20
+ }
21
+ }
14
22
  resolve(input) {
15
- const path = fileURLToPath(resolveEntrypoint(this.#root, input));
23
+ const path = fileURLToPath(this.#resolveEntrypoint(this.#root, input));
16
24
  this.#intercept?.(path);
17
25
  return path;
18
26
  }
@@ -1,10 +1,11 @@
1
1
  import type { FontFaceData, Provider } from 'unifont';
2
2
  import type { FontResolver, Hasher, Storage } from '../definitions.js';
3
- import type { ResolvedFontFamily, ResolveFontOptions } from '../types.js';
3
+ import type { FontProvider, ResolvedFontFamily, ResolveFontOptions } from '../types.js';
4
4
  type NonEmptyProviders = [Provider, ...Array<Provider>];
5
5
  export declare class UnifontFontResolver implements FontResolver {
6
6
  #private;
7
7
  private constructor();
8
+ static astroToUnifontProvider(astroProvider: FontProvider): Provider;
8
9
  static extractUnifontProviders({ families, hasher, }: {
9
10
  families: Array<ResolvedFontFamily>;
10
11
  hasher: Hasher;
@@ -1,10 +1,23 @@
1
- import { createUnifont } from "unifont";
1
+ import { createUnifont, defineFontProvider } from "unifont";
2
2
  import { LOCAL_PROVIDER_NAME } from "../constants.js";
3
3
  class UnifontFontResolver {
4
4
  #unifont;
5
5
  constructor({ unifont }) {
6
6
  this.#unifont = unifont;
7
7
  }
8
+ static astroToUnifontProvider(astroProvider) {
9
+ return defineFontProvider(astroProvider.name, async (_options, ctx) => {
10
+ await astroProvider?.init?.(ctx);
11
+ return {
12
+ async resolveFont(familyName, options) {
13
+ return await astroProvider.resolveFont({ familyName, ...options });
14
+ },
15
+ async listFonts() {
16
+ return astroProvider.listFonts?.();
17
+ }
18
+ };
19
+ })(astroProvider.config);
20
+ }
8
21
  static extractUnifontProviders({
9
22
  families,
10
23
  hasher
@@ -15,7 +28,7 @@ class UnifontFontResolver {
15
28
  if (provider === LOCAL_PROVIDER_NAME) {
16
29
  continue;
17
30
  }
18
- const unifontProvider = provider.provider(provider.config);
31
+ const unifontProvider = this.astroToUnifontProvider(provider);
19
32
  const hash = hasher.hashObject({
20
33
  name: unifontProvider._name,
21
34
  ...provider.config
@@ -1,12 +1,11 @@
1
1
  import type { Logger } from '../../core/logger/core.js';
2
- import type { CssRenderer, FontFileReader, FontMetricsResolver, FontResolver, FontTypeExtractor, Hasher, LocalProviderUrlResolver, RemoteFontProviderResolver, StringMatcher, SystemFallbacksProvider, UrlProxy } from './definitions.js';
2
+ import type { CssRenderer, FontFileReader, FontMetricsResolver, FontResolver, FontTypeExtractor, Hasher, LocalProviderUrlResolver, StringMatcher, SystemFallbacksProvider, UrlProxy } from './definitions.js';
3
3
  import type { ConsumableMap, CreateUrlProxyParams, Defaults, FontFamily, FontFileDataMap, InternalConsumableMap, ResolvedFontFamily } from './types.js';
4
4
  /**
5
5
  * Manages how fonts are resolved:
6
6
  *
7
7
  * - families are resolved
8
- * - unifont providers are extracted from families
9
- * - unifont is initialized
8
+ * - font resolver is initialized
10
9
  *
11
10
  * For each family:
12
11
  * - We create a URL proxy
@@ -19,10 +18,9 @@ import type { ConsumableMap, CreateUrlProxyParams, Defaults, FontFamily, FontFil
19
18
  *
20
19
  * Once that's done, the collected data is returned
21
20
  */
22
- export declare function orchestrate({ families, hasher, remoteFontProviderResolver, localProviderUrlResolver, cssRenderer, systemFallbacksProvider, fontMetricsResolver, fontTypeExtractor, fontFileReader, logger, createUrlProxy, defaults, bold, stringMatcher, createFontResolver, }: {
21
+ export declare function orchestrate({ families, hasher, localProviderUrlResolver, cssRenderer, systemFallbacksProvider, fontMetricsResolver, fontTypeExtractor, fontFileReader, logger, createUrlProxy, defaults, bold, stringMatcher, createFontResolver, }: {
23
22
  families: Array<FontFamily>;
24
23
  hasher: Hasher;
25
- remoteFontProviderResolver: RemoteFontProviderResolver;
26
24
  localProviderUrlResolver: LocalProviderUrlResolver;
27
25
  cssRenderer: CssRenderer;
28
26
  systemFallbacksProvider: SystemFallbacksProvider;
@@ -11,7 +11,6 @@ import {
11
11
  async function orchestrate({
12
12
  families,
13
13
  hasher,
14
- remoteFontProviderResolver,
15
14
  localProviderUrlResolver,
16
15
  cssRenderer,
17
16
  systemFallbacksProvider,
@@ -25,10 +24,9 @@ async function orchestrate({
25
24
  stringMatcher,
26
25
  createFontResolver
27
26
  }) {
28
- const resolvedFamilies = await resolveFamilies({
27
+ const resolvedFamilies = resolveFamilies({
29
28
  families,
30
29
  hasher,
31
- remoteFontProviderResolver,
32
30
  localProviderUrlResolver
33
31
  });
34
32
  const fontResolver = await createFontResolver({ families: resolvedFamilies });
@@ -80,19 +78,16 @@ async function orchestrate({
80
78
  cssVariable: family.cssVariable
81
79
  });
82
80
  if (family.provider === LOCAL_PROVIDER_NAME) {
83
- const result = resolveLocalFont({
81
+ const fonts = resolveLocalFont({
84
82
  family,
85
83
  urlProxy,
86
84
  fontTypeExtractor,
87
85
  fontFileReader
88
86
  });
89
- resolvedFamily.fonts.push(...result.fonts);
87
+ resolvedFamily.fonts.push(...fonts);
90
88
  } else {
91
89
  const fonts = await fontResolver.resolveFont({
92
90
  familyName: family.name,
93
- // By default, unifont goes through all providers. We use a different approach where
94
- // we specify a provider per font. Name has been set while extracting unifont providers
95
- // from families (inside extractUnifontProviders).
96
91
  provider: family.provider.name,
97
92
  // We do not merge the defaults, we only provide defaults as a fallback
98
93
  weights: family.weights ?? defaults.weights,
@@ -1,7 +1,7 @@
1
- import type { providers } from 'unifont';
1
+ import { type AdobeProviderOptions, type GoogleiconsOptions, type GoogleOptions } from 'unifont';
2
2
  import type { FontProvider } from '../types.js';
3
3
  /** [Adobe](https://fonts.adobe.com/) */
4
- declare function adobe(config: Parameters<typeof providers.adobe>[0]): FontProvider;
4
+ declare function adobe(config: AdobeProviderOptions): FontProvider;
5
5
  /** [Bunny](https://fonts.bunny.net/) */
6
6
  declare function bunny(): FontProvider;
7
7
  /** [Fontshare](https://www.fontshare.com/) */
@@ -9,7 +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?: Parameters<typeof providers.google>[0]): FontProvider;
12
+ declare function google(config?: GoogleOptions): FontProvider;
13
+ /** [Google Icons](https://fonts.google.com/icons) */
14
+ declare function googleicons(config?: GoogleiconsOptions): FontProvider;
13
15
  /**
14
16
  * Astro re-exports most [unifont](https://github.com/unjs/unifont/) providers:
15
17
  * - [Adobe](https://fonts.adobe.com/)
@@ -17,6 +19,7 @@ declare function google(config?: Parameters<typeof providers.google>[0]): FontPr
17
19
  * - [Fontshare](https://www.fontshare.com/)
18
20
  * - [Fontsource](https://fontsource.org/)
19
21
  * - [Google](https://fonts.google.com/)
22
+ * - [Google Icons](https://fonts.google.com/icons)
20
23
  */
21
24
  export declare const fontProviders: {
22
25
  adobe: typeof adobe;
@@ -24,5 +27,6 @@ export declare const fontProviders: {
24
27
  fontshare: typeof fontshare;
25
28
  fontsource: typeof fontsource;
26
29
  google: typeof google;
30
+ googleicons: typeof googleicons;
27
31
  };
28
32
  export {};
@@ -1,28 +1,103 @@
1
+ import {
2
+ providers
3
+ } from "unifont";
1
4
  function adobe(config) {
5
+ const provider = providers.adobe(config);
6
+ let initializedProvider;
2
7
  return {
3
- entrypoint: "astro/assets/fonts/providers/adobe",
4
- config
8
+ name: provider._name,
9
+ config,
10
+ async init(context) {
11
+ initializedProvider = await provider(context);
12
+ },
13
+ async resolveFont({ familyName, ...rest }) {
14
+ return await initializedProvider?.resolveFont(familyName, rest);
15
+ },
16
+ async listFonts() {
17
+ return await initializedProvider?.listFonts?.();
18
+ }
5
19
  };
6
20
  }
7
21
  function bunny() {
22
+ const provider = providers.bunny();
23
+ let initializedProvider;
8
24
  return {
9
- entrypoint: "astro/assets/fonts/providers/bunny"
25
+ name: provider._name,
26
+ async init(context) {
27
+ initializedProvider = await provider(context);
28
+ },
29
+ async resolveFont({ familyName, ...rest }) {
30
+ return await initializedProvider?.resolveFont(familyName, rest);
31
+ },
32
+ async listFonts() {
33
+ return await initializedProvider?.listFonts?.();
34
+ }
10
35
  };
11
36
  }
12
37
  function fontshare() {
38
+ const provider = providers.fontshare();
39
+ let initializedProvider;
13
40
  return {
14
- entrypoint: "astro/assets/fonts/providers/fontshare"
41
+ name: provider._name,
42
+ async init(context) {
43
+ initializedProvider = await provider(context);
44
+ },
45
+ async resolveFont({ familyName, ...rest }) {
46
+ return await initializedProvider?.resolveFont(familyName, rest);
47
+ },
48
+ async listFonts() {
49
+ return await initializedProvider?.listFonts?.();
50
+ }
15
51
  };
16
52
  }
17
53
  function fontsource() {
54
+ const provider = providers.fontsource();
55
+ let initializedProvider;
18
56
  return {
19
- entrypoint: "astro/assets/fonts/providers/fontsource"
57
+ name: provider._name,
58
+ async init(context) {
59
+ initializedProvider = await provider(context);
60
+ },
61
+ async resolveFont({ familyName, ...rest }) {
62
+ return await initializedProvider?.resolveFont(familyName, rest);
63
+ },
64
+ async listFonts() {
65
+ return await initializedProvider?.listFonts?.();
66
+ }
20
67
  };
21
68
  }
22
69
  function google(config) {
70
+ const provider = providers.google(config);
71
+ let initializedProvider;
23
72
  return {
24
- entrypoint: "astro/assets/fonts/providers/google",
25
- config
73
+ name: provider._name,
74
+ config,
75
+ async init(context) {
76
+ initializedProvider = await provider(context);
77
+ },
78
+ async resolveFont({ familyName, ...rest }) {
79
+ return await initializedProvider?.resolveFont(familyName, rest);
80
+ },
81
+ async listFonts() {
82
+ return await initializedProvider?.listFonts?.();
83
+ }
84
+ };
85
+ }
86
+ function googleicons(config) {
87
+ const provider = providers.googleicons(config);
88
+ let initializedProvider;
89
+ return {
90
+ name: provider._name,
91
+ config,
92
+ async init(context) {
93
+ initializedProvider = await provider(context);
94
+ },
95
+ async resolveFont({ familyName, ...rest }) {
96
+ return await initializedProvider?.resolveFont(familyName, rest);
97
+ },
98
+ async listFonts() {
99
+ return await initializedProvider?.listFonts?.();
100
+ }
26
101
  };
27
102
  }
28
103
  const fontProviders = {
@@ -30,7 +105,8 @@ const fontProviders = {
30
105
  bunny,
31
106
  fontshare,
32
107
  fontsource,
33
- google
108
+ google,
109
+ googleicons
34
110
  };
35
111
  export {
36
112
  fontProviders
@@ -7,7 +7,5 @@ interface Options {
7
7
  fontTypeExtractor: FontTypeExtractor;
8
8
  fontFileReader: FontFileReader;
9
9
  }
10
- export declare function resolveLocalFont({ family, urlProxy, fontTypeExtractor, fontFileReader, }: Options): {
11
- fonts: Array<unifont.FontFaceData>;
12
- };
10
+ export declare function resolveLocalFont({ family, urlProxy, fontTypeExtractor, fontFileReader, }: Options): Array<unifont.FontFaceData>;
13
11
  export {};
@@ -5,49 +5,47 @@ function resolveLocalFont({
5
5
  fontTypeExtractor,
6
6
  fontFileReader
7
7
  }) {
8
- return {
9
- fonts: family.variants.map((variant) => {
10
- const shouldInfer = variant.weight === void 0 || variant.style === void 0;
11
- const data = {
12
- // If it should be inferred, we don't want to set the value
13
- weight: variant.weight,
14
- style: variant.style,
15
- src: [],
16
- unicodeRange: variant.unicodeRange,
17
- display: variant.display,
18
- stretch: variant.stretch,
19
- featureSettings: variant.featureSettings,
20
- variationSettings: variant.variationSettings
8
+ return family.variants.map((variant) => {
9
+ const shouldInfer = variant.weight === void 0 || variant.style === void 0;
10
+ const data = {
11
+ // If it should be inferred, we don't want to set the value
12
+ weight: variant.weight,
13
+ style: variant.style,
14
+ src: [],
15
+ unicodeRange: variant.unicodeRange,
16
+ display: variant.display,
17
+ stretch: variant.stretch,
18
+ featureSettings: variant.featureSettings,
19
+ variationSettings: variant.variationSettings
20
+ };
21
+ data.src = variant.src.map((source, index) => {
22
+ if (shouldInfer && index === 0) {
23
+ const result = fontFileReader.extract({ family: family.name, url: source.url });
24
+ if (variant.weight === void 0) data.weight = result.weight;
25
+ if (variant.style === void 0) data.style = result.style;
26
+ }
27
+ const type = fontTypeExtractor.extract(source.url);
28
+ return {
29
+ originalURL: source.url,
30
+ url: urlProxy.proxy({
31
+ url: source.url,
32
+ type,
33
+ // We only use the first source for preloading. For example if woff2 and woff
34
+ // are available, we only keep woff2.
35
+ collectPreload: index === 0,
36
+ data: {
37
+ weight: data.weight,
38
+ style: data.style,
39
+ subset: void 0
40
+ },
41
+ init: null
42
+ }),
43
+ format: FONT_FORMATS.find((e) => e.type === type)?.format,
44
+ tech: source.tech
21
45
  };
22
- data.src = variant.src.map((source, index) => {
23
- if (shouldInfer && index === 0) {
24
- const result = fontFileReader.extract({ family: family.name, url: source.url });
25
- if (variant.weight === void 0) data.weight = result.weight;
26
- if (variant.style === void 0) data.style = result.style;
27
- }
28
- const type = fontTypeExtractor.extract(source.url);
29
- return {
30
- originalURL: source.url,
31
- url: urlProxy.proxy({
32
- url: source.url,
33
- type,
34
- // We only use the first source for preloading. For example if woff2 and woff
35
- // are available, we only keep woff2.
36
- collectPreload: index === 0,
37
- data: {
38
- weight: data.weight,
39
- style: data.style,
40
- subset: void 0
41
- },
42
- init: null
43
- }),
44
- format: FONT_FORMATS.find((e) => e.type === type)?.format,
45
- tech: source.tech
46
- };
47
- });
48
- return data;
49
- })
50
- };
46
+ });
47
+ return data;
48
+ });
51
49
  }
52
50
  export {
53
51
  resolveLocalFont