astro 5.16.13 → 5.16.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/components/Font.astro +4 -4
  2. package/dist/assets/fonts/config.d.ts +19 -236
  3. package/dist/assets/fonts/config.js +7 -23
  4. package/dist/assets/fonts/constants.d.ts +0 -1
  5. package/dist/assets/fonts/constants.js +0 -2
  6. package/dist/assets/fonts/core/collect-component-data.d.ts +9 -0
  7. package/dist/assets/fonts/core/collect-component-data.js +47 -0
  8. package/dist/assets/fonts/core/collect-font-assets-from-faces.d.ts +17 -0
  9. package/dist/assets/fonts/core/collect-font-assets-from-faces.js +71 -0
  10. package/dist/assets/fonts/core/collect-font-data.d.ts +4 -0
  11. package/dist/assets/fonts/core/collect-font-data.js +23 -0
  12. package/dist/assets/fonts/core/compute-font-families-assets.d.ts +20 -0
  13. package/dist/assets/fonts/core/compute-font-families-assets.js +67 -0
  14. package/dist/assets/fonts/core/filter-and-transform-font-faces.d.ts +20 -0
  15. package/dist/assets/fonts/core/filter-and-transform-font-faces.js +39 -0
  16. package/dist/assets/fonts/core/get-or-create-font-family-assets.d.ts +8 -0
  17. package/dist/assets/fonts/core/get-or-create-font-family-assets.js +34 -0
  18. package/dist/assets/fonts/core/optimize-fallbacks.d.ts +2 -3
  19. package/dist/assets/fonts/core/optimize-fallbacks.js +2 -3
  20. package/dist/assets/fonts/core/resolve-family.d.ts +6 -0
  21. package/dist/assets/fonts/core/resolve-family.js +23 -0
  22. package/dist/assets/fonts/definitions.d.ts +6 -28
  23. package/dist/assets/fonts/infra/build-font-file-id-generator.d.ts +13 -0
  24. package/dist/assets/fonts/infra/{build-url-proxy-hash-resolver.js → build-font-file-id-generator.js} +3 -6
  25. package/dist/assets/fonts/infra/build-url-resolver.d.ts +1 -1
  26. package/dist/assets/fonts/infra/build-url-resolver.js +4 -4
  27. package/dist/assets/fonts/infra/cached-font-fetcher.d.ts +1 -1
  28. package/dist/assets/fonts/infra/cached-font-fetcher.js +11 -3
  29. package/dist/assets/fonts/infra/capsize-font-metrics-resolver.d.ts +2 -2
  30. package/dist/assets/fonts/infra/dev-font-file-id-generator.d.ts +16 -0
  31. package/dist/assets/fonts/infra/{dev-url-proxy-hash-resolver.js → dev-font-file-id-generator.js} +8 -8
  32. package/dist/assets/fonts/infra/dev-url-resolver.d.ts +1 -1
  33. package/dist/assets/fonts/infra/dev-url-resolver.js +2 -2
  34. package/dist/assets/fonts/infra/fs-font-file-content-resolver.d.ts +10 -0
  35. package/dist/assets/fonts/infra/fs-font-file-content-resolver.js +21 -0
  36. package/dist/assets/fonts/infra/minifiable-css-renderer.d.ts +2 -1
  37. package/dist/assets/fonts/infra/{font-type-extractor.d.ts → node-font-type-extractor.d.ts} +1 -1
  38. package/dist/assets/fonts/infra/{font-type-extractor.js → node-font-type-extractor.js} +2 -2
  39. package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +5 -3
  40. package/dist/assets/fonts/infra/unifont-font-resolver.js +14 -17
  41. package/dist/assets/fonts/providers/index.d.ts +6 -1
  42. package/dist/assets/fonts/providers/index.js +9 -1
  43. package/dist/assets/fonts/providers/local.d.ts +41 -8
  44. package/dist/assets/fonts/providers/local.js +65 -48
  45. package/dist/assets/fonts/runtime/client.d.ts +1 -1
  46. package/dist/assets/fonts/runtime/client.js +1 -1
  47. package/dist/assets/fonts/runtime/server.d.ts +1 -1
  48. package/dist/assets/fonts/runtime/server.js +1 -1
  49. package/dist/assets/fonts/types.d.ts +61 -110
  50. package/dist/assets/fonts/utils.d.ts +1 -7
  51. package/dist/assets/fonts/utils.js +1 -15
  52. package/dist/assets/fonts/vite-plugin-fonts.js +149 -141
  53. package/dist/cli/add/index.js +39 -0
  54. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  55. package/dist/config/index.d.ts +1 -2
  56. package/dist/content/content-layer.js +3 -3
  57. package/dist/core/config/schemas/base.d.ts +58 -429
  58. package/dist/core/config/schemas/base.js +2 -2
  59. package/dist/core/config/schemas/relative.d.ts +76 -541
  60. package/dist/core/constants.js +1 -1
  61. package/dist/core/dev/dev.js +1 -1
  62. package/dist/core/errors/errors-data.d.ts +1 -1
  63. package/dist/core/errors/errors-data.js +1 -1
  64. package/dist/core/messages.js +2 -2
  65. package/dist/types/public/config.d.ts +3 -4
  66. package/package.json +5 -5
  67. package/dist/assets/fonts/core/normalize-remote-font-faces.d.ts +0 -7
  68. package/dist/assets/fonts/core/normalize-remote-font-faces.js +0 -41
  69. package/dist/assets/fonts/core/resolve-families.d.ts +0 -16
  70. package/dist/assets/fonts/core/resolve-families.js +0 -63
  71. package/dist/assets/fonts/infra/build-url-proxy-hash-resolver.d.ts +0 -15
  72. package/dist/assets/fonts/infra/data-collector.d.ts +0 -10
  73. package/dist/assets/fonts/infra/data-collector.js +0 -35
  74. package/dist/assets/fonts/infra/dev-url-proxy-hash-resolver.d.ts +0 -15
  75. package/dist/assets/fonts/infra/local-url-proxy-content-resolver.d.ts +0 -4
  76. package/dist/assets/fonts/infra/local-url-proxy-content-resolver.js +0 -14
  77. package/dist/assets/fonts/infra/remote-url-proxy-content-resolver.d.ts +0 -4
  78. package/dist/assets/fonts/infra/remote-url-proxy-content-resolver.js +0 -9
  79. package/dist/assets/fonts/infra/require-local-provider-url-resolver.d.ts +0 -9
  80. package/dist/assets/fonts/infra/require-local-provider-url-resolver.js +0 -30
  81. package/dist/assets/fonts/infra/url-proxy.d.ts +0 -16
  82. package/dist/assets/fonts/infra/url-proxy.js +0 -50
  83. package/dist/assets/fonts/orchestrate.d.ts +0 -42
  84. package/dist/assets/fonts/orchestrate.js +0 -173
@@ -1,11 +1,44 @@
1
1
  import type * as unifont from 'unifont';
2
- import type { FontFileReader, FontTypeExtractor, UrlProxy } from '../definitions.js';
3
- import type { ResolvedLocalFontFamily } from '../types.js';
4
- interface Options {
5
- family: ResolvedLocalFontFamily;
6
- urlProxy: UrlProxy;
7
- fontTypeExtractor: FontTypeExtractor;
8
- fontFileReader: FontFileReader;
2
+ import type { FontFileReader } from '../definitions.js';
3
+ import type { FamilyProperties, FontProvider, FontProviderInitContext, ResolveFontOptions, Style, Weight } from '../types.js';
4
+ type RawSource = string | URL | {
5
+ url: string | URL;
6
+ tech?: string | undefined;
7
+ };
8
+ interface Variant extends FamilyProperties {
9
+ /**
10
+ * 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.
11
+ */
12
+ src: [RawSource, ...Array<RawSource>];
13
+ /**
14
+ * 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:
15
+ *
16
+ * ```js
17
+ * weight: "100 900"
18
+ * ```
19
+ */
20
+ weight?: Weight | undefined;
21
+ /**
22
+ * A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
23
+ */
24
+ style?: Style | undefined;
25
+ }
26
+ export interface LocalFamilyOptions {
27
+ /**
28
+ * Each variant represents a [`@font-face` declaration](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/).
29
+ */
30
+ variants: [Variant, ...Array<Variant>];
31
+ }
32
+ export declare class LocalFontProvider implements FontProvider<LocalFamilyOptions> {
33
+ #private;
34
+ name: string;
35
+ config?: Record<string, any> | undefined;
36
+ constructor({ fontFileReader, }: {
37
+ fontFileReader: FontFileReader;
38
+ });
39
+ init(context: Pick<FontProviderInitContext, 'root'>): void;
40
+ resolveFont(options: ResolveFontOptions<LocalFamilyOptions>): {
41
+ fonts: Array<unifont.FontFaceData>;
42
+ };
9
43
  }
10
- export declare function resolveLocalFont({ family, urlProxy, fontTypeExtractor, fontFileReader, }: Options): Array<unifont.FontFaceData>;
11
44
  export {};
@@ -1,52 +1,69 @@
1
- import { FONT_FORMATS } from "../constants.js";
2
- function resolveLocalFont({
3
- family,
4
- urlProxy,
5
- fontTypeExtractor,
6
- fontFileReader
7
- }) {
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
1
+ import { createRequire } from "node:module";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ class LocalFontProvider {
4
+ name = "local";
5
+ config;
6
+ #fontFileReader;
7
+ #root;
8
+ constructor({
9
+ fontFileReader
10
+ }) {
11
+ this.config = void 0;
12
+ this.#fontFileReader = fontFileReader;
13
+ this.#root = void 0;
14
+ }
15
+ init(context) {
16
+ this.#root = context.root;
17
+ }
18
+ #resolveEntrypoint(root, entrypoint) {
19
+ const require2 = createRequire(root);
20
+ try {
21
+ return pathToFileURL(require2.resolve(entrypoint));
22
+ } catch {
23
+ return new URL(entrypoint, root);
24
+ }
25
+ }
26
+ #normalizeSource(value) {
27
+ const isValue = typeof value === "string" || value instanceof URL;
28
+ const url = (isValue ? value : value.url).toString();
29
+ const tech = isValue ? void 0 : value.tech;
30
+ return {
31
+ url: fileURLToPath(this.#resolveEntrypoint(this.#root ?? new URL(import.meta.url), url)),
32
+ tech
20
33
  };
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
45
- };
46
- });
47
- return data;
48
- });
34
+ }
35
+ resolveFont(options) {
36
+ return {
37
+ fonts: options.options?.variants.map((variant) => {
38
+ const shouldInfer = variant.weight === void 0 || variant.style === void 0;
39
+ const data = {
40
+ // If it should be inferred, we don't want to set the value
41
+ weight: variant.weight,
42
+ style: variant.style,
43
+ src: [],
44
+ unicodeRange: variant.unicodeRange,
45
+ display: variant.display,
46
+ stretch: variant.stretch,
47
+ featureSettings: variant.featureSettings,
48
+ variationSettings: variant.variationSettings
49
+ };
50
+ data.src = variant.src.map((rawSource, index) => {
51
+ const source = this.#normalizeSource(rawSource);
52
+ if (shouldInfer && index === 0) {
53
+ const result = this.#fontFileReader.extract({
54
+ family: options.familyName,
55
+ url: source.url
56
+ });
57
+ if (variant.weight === void 0) data.weight = result.weight;
58
+ if (variant.style === void 0) data.style = result.style;
59
+ }
60
+ return source;
61
+ });
62
+ return data;
63
+ }) ?? []
64
+ };
65
+ }
49
66
  }
50
67
  export {
51
- resolveLocalFont
68
+ LocalFontProvider
52
69
  };
@@ -1,2 +1,2 @@
1
- export declare const fontData: import("../types.js").FontDataRecord;
1
+ export declare const fontData: import("../types.js").FontDataByCssVariable;
2
2
  export declare function getFontBuffer(): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import * as fontsMod from "virtual:astro:assets/fonts/internal";
2
- const fontData = fontsMod.fontData ?? {};
2
+ const fontData = fontsMod.fontDataByCssVariable ?? {};
3
3
  async function getFontBuffer() {
4
4
  throw new Error("[astro:assets] `getFontBuffer()` is not available on the client.");
5
5
  }
@@ -1,2 +1,2 @@
1
- export declare const fontData: import("../types.js").FontDataRecord;
1
+ export declare const fontData: import("../types.js").FontDataByCssVariable;
2
2
  export declare const getFontBuffer: (url: string) => Promise<Buffer<ArrayBufferLike>>;
@@ -1,6 +1,6 @@
1
1
  import * as fontsMod from "virtual:astro:assets/fonts/internal";
2
2
  import { createGetFontBuffer } from "../core/create-get-font-buffer.js";
3
- const fontData = fontsMod.fontData ?? {};
3
+ const fontData = fontsMod.fontDataByCssVariable ?? {};
4
4
  const getFontBuffer = createGetFontBuffer(fontsMod);
5
5
  export {
6
6
  fontData,
@@ -2,11 +2,10 @@ import type { Font } from '@capsizecss/unpack';
2
2
  import type * as unifont from 'unifont';
3
3
  import type { z } from 'zod';
4
4
  import type { displaySchema, styleSchema, weightSchema } from './config.js';
5
- import type { FONT_TYPES, GENERIC_FALLBACK_NAMES, LOCAL_PROVIDER_NAME } from './constants.js';
5
+ import type { FONT_TYPES, GENERIC_FALLBACK_NAMES } from './constants.js';
6
6
  import type { CollectedFontForMetrics } from './core/optimize-fallbacks.js';
7
- type Weight = z.infer<typeof weightSchema>;
7
+ export type Weight = z.infer<typeof weightSchema>;
8
8
  type Display = z.infer<typeof displaySchema>;
9
- /** @lintignore */
10
9
  export interface FontProviderInitContext {
11
10
  storage: {
12
11
  getItem: {
@@ -15,6 +14,7 @@ export interface FontProviderInitContext {
15
14
  };
16
15
  setItem: (key: string, value: unknown) => Awaitable<void>;
17
16
  };
17
+ root: URL;
18
18
  }
19
19
  type Awaitable<T> = T | Promise<T>;
20
20
  export interface FontProvider<TFamilyOptions extends Record<string, any> | undefined | never = never> {
@@ -41,56 +41,7 @@ export interface FontProvider<TFamilyOptions extends Record<string, any> | undef
41
41
  */
42
42
  listFonts?: (() => Awaitable<Array<string> | undefined>) | undefined;
43
43
  }
44
- interface RequiredFamilyAttributes {
45
- /**
46
- * The font family name, as identified by your font provider.
47
- */
48
- name: string;
49
- /**
50
- * A valid [ident](https://developer.mozilla.org/en-US/docs/Web/CSS/ident) in the form of a CSS variable (i.e. starting with `--`).
51
- */
52
- cssVariable: string;
53
- }
54
- interface Fallbacks {
55
- /**
56
- * @default `["sans-serif"]`
57
- *
58
- * 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:
59
- *
60
- * ```js
61
- * fallbacks: ["CustomFont", "serif"]
62
- * ```
63
- *
64
- * To disable fallback fonts completely, configure an empty array:
65
- *
66
- * ```js
67
- * fallbacks: []
68
- * ```
69
- *
70
-
71
- * 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), Astro will attempt to generate [optimized fallbacks](https://developer.chrome.com/blog/font-fallbacks) using font metrics will be generated. To disable this optimization, set `optimizedFallbacks` to false.
72
- */
73
- fallbacks?: Array<string> | undefined;
74
- /**
75
- * @default `true`
76
- *
77
- * Whether or not to enable optimized fallback generation. You may disable this default optimization to have full control over `fallbacks`.
78
- */
79
- optimizedFallbacks?: boolean | undefined;
80
- }
81
- interface FamilyProperties {
82
- /**
83
- * 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:
84
- *
85
- * ```js
86
- * weight: "100 900"
87
- * ```
88
- */
89
- weight?: Weight | undefined;
90
- /**
91
- * A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
92
- */
93
- style?: Style | undefined;
44
+ export interface FamilyProperties {
94
45
  /**
95
46
  * @default `"swap"`
96
47
  *
@@ -114,38 +65,6 @@ interface FamilyProperties {
114
65
  */
115
66
  unicodeRange?: [string, ...Array<string>] | undefined;
116
67
  }
117
- type Src = string | URL | {
118
- url: string | URL;
119
- tech?: string | undefined;
120
- };
121
- interface Variant extends FamilyProperties {
122
- /**
123
- * 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.
124
- */
125
- src: [Src, ...Array<Src>];
126
- }
127
- export interface LocalFontFamily extends RequiredFamilyAttributes, Fallbacks {
128
- /**
129
- * The source of your font files. Set to `"local"` to use local font files.
130
- */
131
- provider: typeof LOCAL_PROVIDER_NAME;
132
- /**
133
- * Each variant represents a [`@font-face` declaration](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/).
134
- */
135
- variants: [Variant, ...Array<Variant>];
136
- }
137
- interface ResolvedFontFamilyAttributes {
138
- nameWithHash: string;
139
- }
140
- export interface ResolvedLocalFontFamily extends ResolvedFontFamilyAttributes, Omit<LocalFontFamily, 'variants'> {
141
- variants: Array<Omit<LocalFontFamily['variants'][number], 'weight' | 'src'> & {
142
- weight?: string;
143
- src: Array<{
144
- url: string;
145
- tech?: string;
146
- }>;
147
- }>;
148
- }
149
68
  type WithOptions<TFontProvider extends FontProvider> = TFontProvider extends FontProvider<infer TFamilyOptions> ? [TFamilyOptions] extends [never] ? {
150
69
  /**
151
70
  * Options forwarded to the font provider while resolving this font family.
@@ -167,7 +86,15 @@ type WithOptions<TFontProvider extends FontProvider> = TFontProvider extends Fon
167
86
  */
168
87
  options?: undefined;
169
88
  };
170
- export type RemoteFontFamily<TFontProvider extends FontProvider = FontProvider> = RequiredFamilyAttributes & Omit<FamilyProperties, 'weight' | 'style' | 'subsets' | 'formats'> & Fallbacks & WithOptions<NoInfer<TFontProvider>> & {
89
+ export type FontFamily<TFontProvider extends FontProvider = FontProvider> = FamilyProperties & WithOptions<NoInfer<TFontProvider>> & {
90
+ /**
91
+ * The font family name, as identified by your font provider.
92
+ */
93
+ name: string;
94
+ /**
95
+ * A valid [ident](https://developer.mozilla.org/en-US/docs/Web/CSS/ident) in the form of a CSS variable (i.e. starting with `--`).
96
+ */
97
+ cssVariable: string;
171
98
  /**
172
99
  * The source of your font files. You can use a built-in provider or write your own custom provider.
173
100
  */
@@ -200,13 +127,36 @@ export type RemoteFontFamily<TFontProvider extends FontProvider = FontProvider>
200
127
  * An array of [font formats](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@font-face/src#font_formats).
201
128
  */
202
129
  formats?: [FontType, ...Array<FontType>] | undefined;
130
+ /**
131
+ * @default `["sans-serif"]`
132
+ *
133
+ * 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:
134
+ *
135
+ * ```js
136
+ * fallbacks: ["CustomFont", "serif"]
137
+ * ```
138
+ *
139
+ * To disable fallback fonts completely, configure an empty array:
140
+ *
141
+ * ```js
142
+ * fallbacks: []
143
+ * ```
144
+ *
145
+
146
+ * 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), Astro will attempt to generate [optimized fallbacks](https://developer.chrome.com/blog/font-fallbacks) using font metrics will be generated. To disable this optimization, set `optimizedFallbacks` to false.
147
+ */
148
+ fallbacks?: Array<string> | undefined;
149
+ /**
150
+ * @default `true`
151
+ *
152
+ * Whether or not to enable optimized fallback generation. You may disable this default optimization to have full control over `fallbacks`.
153
+ */
154
+ optimizedFallbacks?: boolean | undefined;
203
155
  };
204
- /** @lintignore somehow required by pickFontFaceProperty in utils */
205
- export interface ResolvedRemoteFontFamily extends ResolvedFontFamilyAttributes, Omit<RemoteFontFamily, 'weights'> {
156
+ export interface ResolvedFontFamily extends Omit<FontFamily, 'weights'> {
157
+ uniqueName: string;
206
158
  weights?: Array<string>;
207
159
  }
208
- export type FontFamily<TFontProvider extends FontProvider = FontProvider> = LocalFontFamily | RemoteFontFamily<TFontProvider>;
209
- export type ResolvedFontFamily = ResolvedLocalFontFamily | ResolvedRemoteFontFamily;
210
160
  export type FontType = (typeof FONT_TYPES)[number];
211
161
  /**
212
162
  * Preload data is used for links generation inside the <Font /> component
@@ -226,30 +176,19 @@ export interface PreloadData {
226
176
  }
227
177
  export type FontFaceMetrics = Pick<Font, 'ascent' | 'descent' | 'lineGap' | 'unitsPerEm' | 'xWidthAvg'>;
228
178
  export type GenericFallbackName = (typeof GENERIC_FALLBACK_NAMES)[number];
229
- export type Defaults = Required<Pick<ResolvedRemoteFontFamily, 'weights' | 'styles' | 'subsets' | 'fallbacks' | 'optimizedFallbacks' | 'formats'>>;
179
+ export type Defaults = Required<Pick<ResolvedFontFamily, 'weights' | 'styles' | 'subsets' | 'fallbacks' | 'optimizedFallbacks' | 'formats'>>;
230
180
  export interface FontFileData {
231
- hash: string;
181
+ id: string;
232
182
  url: string;
233
- init: RequestInit | null;
234
- }
235
- export interface CreateUrlProxyParams {
236
- local: boolean;
237
- hasUrl: (hash: string) => boolean;
238
- saveUrl: (input: FontFileData) => void;
239
- savePreload: (preload: PreloadData) => void;
240
- saveFontData: (collected: CollectedFontForMetrics) => void;
241
- cssVariable: string;
183
+ init: RequestInit | undefined;
242
184
  }
243
185
  /**
244
- * Holds associations of hash and original font file URLs, so they can be
245
- * downloaded whenever the hash is requested.
186
+ * Holds associations of id and original font file URLs, so they can be
187
+ * downloaded whenever the id is requested.
246
188
  */
247
- export type FontFileDataMap = Map<FontFileData['hash'], Pick<FontFileData, 'url' | 'init'>>;
248
- /**
249
- * Holds associations of CSS variables and preloadData/css to be passed to the internal virtual module.
250
- */
251
- export type InternalConsumableMap = Map<string, {
252
- preloadData: Array<PreloadData>;
189
+ export type FontFileById = Map<FontFileData['id'], Pick<FontFileData, 'url' | 'init'>>;
190
+ export type ComponentDataByCssVariable = Map<string, {
191
+ preloads: Array<PreloadData>;
253
192
  css: string;
254
193
  }>;
255
194
  export interface FontData {
@@ -264,7 +203,7 @@ export interface FontData {
264
203
  /**
265
204
  * Holds associations of CSS variables and font data to be exposed via virtual module.
266
205
  */
267
- export type FontDataRecord = Record<string, Array<FontData>>;
206
+ export type FontDataByCssVariable = Record<string, Array<FontData>>;
268
207
  export type Style = z.output<typeof styleSchema>;
269
208
  export type PreloadFilter = boolean | Array<{
270
209
  weight?: string | number;
@@ -279,6 +218,18 @@ export interface ResolveFontOptions<FamilyOptions extends Record<string, any> |
279
218
  formats: FontType[];
280
219
  options: [FamilyOptions] extends [never] ? undefined : FamilyOptions | undefined;
281
220
  }
221
+ export type CssProperties = Record<string, string | undefined>;
222
+ export interface FontFamilyAssets {
223
+ family: ResolvedFontFamily;
224
+ fonts: Array<unifont.FontFaceData>;
225
+ /**
226
+ * Holds a list of font files to be used for optimized fallbacks generation
227
+ */
228
+ collectedFontsForMetricsByUniqueKey: Map<string, CollectedFontForMetrics>;
229
+ preloads: Array<PreloadData>;
230
+ }
231
+ export type FontFamilyAssetsByUniqueKey = Map<string, FontFamilyAssets>;
232
+ export type Collaborator<T extends (input: any) => any, U extends keyof Parameters<T>[0]> = (params: Pick<Parameters<T>[0], U>) => ReturnType<T>;
282
233
  export type BufferImports = Record<string, () => Promise<{
283
234
  default: Buffer | null;
284
235
  }>>;
@@ -1,6 +1,5 @@
1
1
  import type * as unifont from 'unifont';
2
- import type { CssProperties, Storage } from './definitions.js';
3
- import type { FontType, GenericFallbackName, ResolvedFontFamily } from './types.js';
2
+ import type { CssProperties, FontType, GenericFallbackName } from './types.js';
4
3
  /**
5
4
  * Turns unifont font face data into generic CSS properties, to be consumed by the CSS renderer.
6
5
  */
@@ -16,11 +15,6 @@ export declare function renderFontSrc(sources: Exclude<unifont.FontFaceData['src
16
15
  */
17
16
  export declare function withoutQuotes(str: string): string;
18
17
  export declare function isFontType(str: string): str is FontType;
19
- export declare function cache(storage: Storage, key: string, cb: () => Promise<Buffer>): Promise<Buffer>;
20
18
  export declare function isGenericFontFamily(str: string): str is GenericFallbackName;
21
19
  export declare function dedupe<const T extends Array<any>>(arr: T): T;
22
20
  export declare function sortObjectByKey<T extends Record<string, any>>(unordered: T): T;
23
- export declare function pickFontFaceProperty<T extends keyof Pick<unifont.FontFaceData, 'display' | 'unicodeRange' | 'stretch' | 'featureSettings' | 'variationSettings'>>(property: T, { data, family }: {
24
- data: unifont.FontFaceData;
25
- family: ResolvedFontFamily;
26
- }): import("./types.js").ResolvedRemoteFontFamily[T] | NonNullable<unifont.FontFaceData[T]> | undefined;
@@ -1,4 +1,4 @@
1
- import { FONT_TYPES, GENERIC_FALLBACK_NAMES, LOCAL_PROVIDER_NAME } from "./constants.js";
1
+ import { FONT_TYPES, GENERIC_FALLBACK_NAMES } from "./constants.js";
2
2
  function unifontFontFaceDataToProperties(font) {
3
3
  return {
4
4
  src: font.src ? renderFontSrc(font.src) : void 0,
@@ -36,15 +36,6 @@ function withoutQuotes(str) {
36
36
  function isFontType(str) {
37
37
  return FONT_TYPES.includes(str);
38
38
  }
39
- async function cache(storage, key, cb) {
40
- const existing = await storage.getItemRaw(key);
41
- if (existing) {
42
- return existing;
43
- }
44
- const data = await cb();
45
- await storage.setItemRaw(key, data);
46
- return data;
47
- }
48
39
  function isGenericFontFamily(str) {
49
40
  return GENERIC_FALLBACK_NAMES.includes(str);
50
41
  }
@@ -59,15 +50,10 @@ function sortObjectByKey(unordered) {
59
50
  }, {});
60
51
  return ordered;
61
52
  }
62
- function pickFontFaceProperty(property, { data, family }) {
63
- return data[property] ?? (family.provider === LOCAL_PROVIDER_NAME ? void 0 : family[property]);
64
- }
65
53
  export {
66
- cache,
67
54
  dedupe,
68
55
  isFontType,
69
56
  isGenericFontFamily,
70
- pickFontFaceProperty,
71
57
  renderFontSrc,
72
58
  renderFontWeight,
73
59
  sortObjectByKey,