astro 5.7.6 → 5.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/fonts/config.d.ts +3 -3
- package/dist/assets/fonts/config.js +2 -3
- package/dist/assets/fonts/constants.d.ts +3 -73
- package/dist/assets/fonts/constants.js +16 -68
- package/dist/assets/fonts/definitions.d.ts +73 -0
- package/dist/assets/fonts/definitions.js +0 -0
- package/dist/assets/fonts/implementations/css-renderer.d.ts +9 -0
- package/dist/assets/fonts/implementations/css-renderer.js +42 -0
- package/dist/assets/fonts/implementations/data-collector.d.ts +3 -0
- package/dist/assets/fonts/implementations/data-collector.js +21 -0
- package/dist/assets/fonts/implementations/error-handler.d.ts +2 -0
- package/dist/assets/fonts/implementations/error-handler.js +33 -0
- package/dist/assets/fonts/implementations/font-fetcher.d.ts +8 -0
- package/dist/assets/fonts/implementations/font-fetcher.js +34 -0
- package/dist/assets/fonts/implementations/font-metrics-resolver.d.ts +5 -0
- package/dist/assets/fonts/implementations/font-metrics-resolver.js +60 -0
- package/dist/assets/fonts/implementations/font-type-extractor.d.ts +4 -0
- package/dist/assets/fonts/implementations/font-type-extractor.js +22 -0
- package/dist/assets/fonts/implementations/hasher.d.ts +2 -0
- package/dist/assets/fonts/implementations/hasher.js +14 -0
- package/dist/assets/fonts/implementations/local-provider-url-resolver.d.ts +5 -0
- package/dist/assets/fonts/implementations/local-provider-url-resolver.js +17 -0
- package/dist/assets/fonts/implementations/remote-font-provider-mod-resolver.d.ts +6 -0
- package/dist/assets/fonts/implementations/remote-font-provider-mod-resolver.js +20 -0
- package/dist/assets/fonts/implementations/remote-font-provider-resolver.d.ts +6 -0
- package/dist/assets/fonts/implementations/remote-font-provider-resolver.js +47 -0
- package/dist/assets/fonts/implementations/storage.d.ts +4 -0
- package/dist/assets/fonts/implementations/storage.js +14 -0
- package/dist/assets/fonts/implementations/system-fallbacks-provider.d.ts +11 -0
- package/dist/assets/fonts/implementations/system-fallbacks-provider.js +74 -0
- package/dist/assets/fonts/implementations/url-proxy-content-resolver.d.ts +5 -0
- package/dist/assets/fonts/implementations/url-proxy-content-resolver.js +28 -0
- package/dist/assets/fonts/implementations/url-proxy.d.ts +8 -0
- package/dist/assets/fonts/implementations/url-proxy.js +26 -0
- package/dist/assets/fonts/logic/extract-unifont-providers.d.ts +10 -0
- package/dist/assets/fonts/logic/extract-unifont-providers.js +28 -0
- package/dist/assets/fonts/logic/normalize-remote-font-faces.d.ts +6 -0
- package/dist/assets/fonts/logic/normalize-remote-font-faces.js +36 -0
- package/dist/assets/fonts/logic/optimize-fallbacks.d.ts +17 -0
- package/dist/assets/fonts/logic/optimize-fallbacks.js +47 -0
- package/dist/assets/fonts/logic/resolve-families.d.ts +17 -0
- package/dist/assets/fonts/logic/resolve-families.js +67 -0
- package/dist/assets/fonts/orchestrate.d.ts +37 -0
- package/dist/assets/fonts/orchestrate.js +125 -0
- package/dist/assets/fonts/providers/local.d.ts +6 -7
- package/dist/assets/fonts/providers/local.js +26 -29
- package/dist/assets/fonts/types.d.ts +32 -2
- package/dist/assets/fonts/utils.d.ts +17 -88
- package/dist/assets/fonts/utils.js +20 -186
- package/dist/assets/fonts/vite-plugin-fonts.js +96 -94
- package/dist/content/content-layer.js +3 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/types/public/config.d.ts +2 -2
- package/dist/vite-plugin-markdown/images.js +4 -4
- package/package.json +4 -4
- package/types/content.d.ts +11 -4
- package/dist/assets/fonts/load.d.ts +0 -20
- package/dist/assets/fonts/load.js +0 -162
- package/dist/assets/fonts/metrics.d.ts +0 -10
- package/dist/assets/fonts/metrics.js +0 -55
- package/dist/assets/fonts/providers/utils.d.ts +0 -9
- package/dist/assets/fonts/providers/utils.js +0 -37
|
@@ -41,7 +41,7 @@ export declare const localFontFamilySchema: z.ZodObject<z.objectUtil.extendShape
|
|
|
41
41
|
* ```
|
|
42
42
|
*
|
|
43
43
|
|
|
44
|
-
* 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),
|
|
44
|
+
* 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.
|
|
45
45
|
*/
|
|
46
46
|
fallbacks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
47
47
|
/**
|
|
@@ -274,7 +274,7 @@ export declare const remoteFontFamilySchema: z.ZodObject<z.objectUtil.extendShap
|
|
|
274
274
|
* ```
|
|
275
275
|
*
|
|
276
276
|
|
|
277
|
-
* 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),
|
|
277
|
+
* 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.
|
|
278
278
|
*/
|
|
279
279
|
fallbacks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
280
280
|
/**
|
|
@@ -322,7 +322,7 @@ export declare const remoteFontFamilySchema: z.ZodObject<z.objectUtil.extendShap
|
|
|
322
322
|
/**
|
|
323
323
|
* @default `["cyrillic-ext", "cyrillic", "greek-ext", "greek", "vietnamese", "latin-ext", "latin"]`
|
|
324
324
|
*
|
|
325
|
-
* An array of [font subsets](https://
|
|
325
|
+
* An array of [font subsets](https://knaap.dev/posts/font-subsetting/):
|
|
326
326
|
*/
|
|
327
327
|
subsets: z.ZodOptional<z.ZodArray<z.ZodString, "atleastone">>;
|
|
328
328
|
}>, "strict", z.ZodTypeAny, {
|
|
@@ -55,7 +55,7 @@ const fallbacksSchema = z.object({
|
|
|
55
55
|
* ```
|
|
56
56
|
*
|
|
57
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),
|
|
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), 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.
|
|
59
59
|
*/
|
|
60
60
|
fallbacks: z.array(z.string()).optional(),
|
|
61
61
|
/**
|
|
@@ -140,11 +140,10 @@ const remoteFontFamilySchema = requiredFamilyAttributesSchema.merge(
|
|
|
140
140
|
* An array of [font styles](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
|
|
141
141
|
*/
|
|
142
142
|
styles: z.array(styleSchema).nonempty().optional(),
|
|
143
|
-
// TODO: better link
|
|
144
143
|
/**
|
|
145
144
|
* @default `["cyrillic-ext", "cyrillic", "greek-ext", "greek", "vietnamese", "latin-ext", "latin"]`
|
|
146
145
|
*
|
|
147
|
-
* An array of [font subsets](https://
|
|
146
|
+
* An array of [font subsets](https://knaap.dev/posts/font-subsetting/):
|
|
148
147
|
*/
|
|
149
148
|
subsets: z.array(z.string()).nonempty().optional()
|
|
150
149
|
})
|
|
@@ -1,81 +1,11 @@
|
|
|
1
|
+
import type { Defaults } from './types.js';
|
|
1
2
|
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
|
-
};
|
|
3
|
+
export declare const DEFAULTS: Defaults;
|
|
9
4
|
export declare const VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/internal";
|
|
10
5
|
export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
11
6
|
export declare const URL_PREFIX = "/_astro/fonts/";
|
|
12
7
|
export declare const CACHE_DIR = "./fonts/";
|
|
13
8
|
export declare const FONT_TYPES: readonly ["woff2", "woff", "otf", "ttf", "eot"];
|
|
14
9
|
export declare const FONT_FORMAT_MAP: Record<(typeof FONT_TYPES)[number], string>;
|
|
15
|
-
export declare const
|
|
16
|
-
'Times New Roman': {
|
|
17
|
-
ascent: number;
|
|
18
|
-
descent: number;
|
|
19
|
-
lineGap: number;
|
|
20
|
-
unitsPerEm: number;
|
|
21
|
-
xWidthAvg: number;
|
|
22
|
-
};
|
|
23
|
-
Arial: {
|
|
24
|
-
ascent: number;
|
|
25
|
-
descent: number;
|
|
26
|
-
lineGap: number;
|
|
27
|
-
unitsPerEm: number;
|
|
28
|
-
xWidthAvg: number;
|
|
29
|
-
};
|
|
30
|
-
'Courier New': {
|
|
31
|
-
ascent: number;
|
|
32
|
-
descent: number;
|
|
33
|
-
lineGap: number;
|
|
34
|
-
unitsPerEm: number;
|
|
35
|
-
xWidthAvg: number;
|
|
36
|
-
};
|
|
37
|
-
BlinkMacSystemFont: {
|
|
38
|
-
ascent: number;
|
|
39
|
-
descent: number;
|
|
40
|
-
lineGap: number;
|
|
41
|
-
unitsPerEm: number;
|
|
42
|
-
xWidthAvg: number;
|
|
43
|
-
};
|
|
44
|
-
'Segoe UI': {
|
|
45
|
-
ascent: number;
|
|
46
|
-
descent: number;
|
|
47
|
-
lineGap: number;
|
|
48
|
-
unitsPerEm: number;
|
|
49
|
-
xWidthAvg: number;
|
|
50
|
-
};
|
|
51
|
-
Roboto: {
|
|
52
|
-
ascent: number;
|
|
53
|
-
descent: number;
|
|
54
|
-
lineGap: number;
|
|
55
|
-
unitsPerEm: number;
|
|
56
|
-
xWidthAvg: number;
|
|
57
|
-
};
|
|
58
|
-
'Helvetica Neue': {
|
|
59
|
-
ascent: number;
|
|
60
|
-
descent: number;
|
|
61
|
-
lineGap: number;
|
|
62
|
-
unitsPerEm: number;
|
|
63
|
-
xWidthAvg: number;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
export declare const DEFAULT_FALLBACKS: {
|
|
67
|
-
readonly serif: ["Times New Roman"];
|
|
68
|
-
readonly 'sans-serif': ["Arial"];
|
|
69
|
-
readonly monospace: ["Courier New"];
|
|
70
|
-
readonly cursive: [];
|
|
71
|
-
readonly fantasy: [];
|
|
72
|
-
readonly 'system-ui': ["BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica Neue", "Arial"];
|
|
73
|
-
readonly 'ui-serif': ["Times New Roman"];
|
|
74
|
-
readonly 'ui-sans-serif': ["Arial"];
|
|
75
|
-
readonly 'ui-monospace': ["Courier New"];
|
|
76
|
-
readonly 'ui-rounded': [];
|
|
77
|
-
readonly emoji: [];
|
|
78
|
-
readonly math: [];
|
|
79
|
-
readonly fangsong: [];
|
|
80
|
-
};
|
|
10
|
+
export declare const GENERIC_FALLBACK_NAMES: readonly ["serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded", "emoji", "math", "fangsong"];
|
|
81
11
|
export declare const FONTS_TYPES_FILE = "fonts.d.ts";
|
|
@@ -19,83 +19,31 @@ const FONT_FORMAT_MAP = {
|
|
|
19
19
|
ttf: "truetype",
|
|
20
20
|
eot: "embedded-opentype"
|
|
21
21
|
};
|
|
22
|
-
const
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"Courier New": {
|
|
38
|
-
ascent: 1705,
|
|
39
|
-
descent: -615,
|
|
40
|
-
lineGap: 0,
|
|
41
|
-
unitsPerEm: 2048,
|
|
42
|
-
xWidthAvg: 1229
|
|
43
|
-
},
|
|
44
|
-
BlinkMacSystemFont: {
|
|
45
|
-
ascent: 1980,
|
|
46
|
-
descent: -432,
|
|
47
|
-
lineGap: 0,
|
|
48
|
-
unitsPerEm: 2048,
|
|
49
|
-
xWidthAvg: 853
|
|
50
|
-
},
|
|
51
|
-
"Segoe UI": {
|
|
52
|
-
ascent: 2210,
|
|
53
|
-
descent: -514,
|
|
54
|
-
lineGap: 0,
|
|
55
|
-
unitsPerEm: 2048,
|
|
56
|
-
xWidthAvg: 908
|
|
57
|
-
},
|
|
58
|
-
Roboto: {
|
|
59
|
-
ascent: 1900,
|
|
60
|
-
descent: -500,
|
|
61
|
-
lineGap: 0,
|
|
62
|
-
unitsPerEm: 2048,
|
|
63
|
-
xWidthAvg: 911
|
|
64
|
-
},
|
|
65
|
-
"Helvetica Neue": {
|
|
66
|
-
ascent: 952,
|
|
67
|
-
descent: -213,
|
|
68
|
-
lineGap: 28,
|
|
69
|
-
unitsPerEm: 1e3,
|
|
70
|
-
xWidthAvg: 450
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const DEFAULT_FALLBACKS = {
|
|
74
|
-
serif: ["Times New Roman"],
|
|
75
|
-
"sans-serif": ["Arial"],
|
|
76
|
-
monospace: ["Courier New"],
|
|
77
|
-
cursive: [],
|
|
78
|
-
fantasy: [],
|
|
79
|
-
"system-ui": ["BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica Neue", "Arial"],
|
|
80
|
-
"ui-serif": ["Times New Roman"],
|
|
81
|
-
"ui-sans-serif": ["Arial"],
|
|
82
|
-
"ui-monospace": ["Courier New"],
|
|
83
|
-
"ui-rounded": [],
|
|
84
|
-
emoji: [],
|
|
85
|
-
math: [],
|
|
86
|
-
fangsong: []
|
|
87
|
-
};
|
|
22
|
+
const GENERIC_FALLBACK_NAMES = [
|
|
23
|
+
"serif",
|
|
24
|
+
"sans-serif",
|
|
25
|
+
"monospace",
|
|
26
|
+
"cursive",
|
|
27
|
+
"fantasy",
|
|
28
|
+
"system-ui",
|
|
29
|
+
"ui-serif",
|
|
30
|
+
"ui-sans-serif",
|
|
31
|
+
"ui-monospace",
|
|
32
|
+
"ui-rounded",
|
|
33
|
+
"emoji",
|
|
34
|
+
"math",
|
|
35
|
+
"fangsong"
|
|
36
|
+
];
|
|
88
37
|
const FONTS_TYPES_FILE = "fonts.d.ts";
|
|
89
38
|
export {
|
|
90
39
|
CACHE_DIR,
|
|
91
40
|
DEFAULTS,
|
|
92
|
-
DEFAULT_FALLBACKS,
|
|
93
41
|
FONTS_TYPES_FILE,
|
|
94
42
|
FONT_FORMAT_MAP,
|
|
95
43
|
FONT_TYPES,
|
|
44
|
+
GENERIC_FALLBACK_NAMES,
|
|
96
45
|
LOCAL_PROVIDER_NAME,
|
|
97
46
|
RESOLVED_VIRTUAL_MODULE_ID,
|
|
98
|
-
SYSTEM_METRICS,
|
|
99
47
|
URL_PREFIX,
|
|
100
48
|
VIRTUAL_MODULE_ID
|
|
101
49
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type * as unifont from 'unifont';
|
|
2
|
+
import type { CollectedFontForMetrics } from './logic/optimize-fallbacks.js';
|
|
3
|
+
import type { AstroFontProvider, FontFileData, FontType, PreloadData, ResolvedFontProvider } from './types.js';
|
|
4
|
+
import type { FontFaceMetrics, GenericFallbackName } from './types.js';
|
|
5
|
+
export interface Hasher {
|
|
6
|
+
hashString: (input: string) => string;
|
|
7
|
+
hashObject: (input: Record<string, any>) => string;
|
|
8
|
+
}
|
|
9
|
+
export interface RemoteFontProviderModResolver {
|
|
10
|
+
resolve: (id: string) => Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
export interface RemoteFontProviderResolver {
|
|
13
|
+
resolve: (provider: AstroFontProvider) => Promise<ResolvedFontProvider>;
|
|
14
|
+
}
|
|
15
|
+
export interface LocalProviderUrlResolver {
|
|
16
|
+
resolve: (input: string) => string;
|
|
17
|
+
}
|
|
18
|
+
type SingleErrorInput<TType extends string, TData extends Record<string, any>> = {
|
|
19
|
+
type: TType;
|
|
20
|
+
data: TData;
|
|
21
|
+
cause: unknown;
|
|
22
|
+
};
|
|
23
|
+
export type ErrorHandlerInput = SingleErrorInput<'cannot-load-font-provider', {
|
|
24
|
+
entrypoint: string;
|
|
25
|
+
}> | SingleErrorInput<'unknown-fs-error', {}> | SingleErrorInput<'cannot-fetch-font-file', {
|
|
26
|
+
url: string;
|
|
27
|
+
}> | SingleErrorInput<'cannot-extract-font-type', {
|
|
28
|
+
url: string;
|
|
29
|
+
}>;
|
|
30
|
+
export interface ErrorHandler {
|
|
31
|
+
handle: (input: ErrorHandlerInput) => Error;
|
|
32
|
+
}
|
|
33
|
+
export interface UrlProxy {
|
|
34
|
+
proxy: (input: Pick<FontFileData, 'url' | 'init'> & {
|
|
35
|
+
collectPreload: boolean;
|
|
36
|
+
data: Partial<unifont.FontFaceData>;
|
|
37
|
+
}) => string;
|
|
38
|
+
}
|
|
39
|
+
export interface UrlProxyContentResolver {
|
|
40
|
+
resolve: (url: string) => string;
|
|
41
|
+
}
|
|
42
|
+
export interface DataCollector {
|
|
43
|
+
collect: (input: FontFileData & {
|
|
44
|
+
data: Partial<unifont.FontFaceData>;
|
|
45
|
+
preload: PreloadData | null;
|
|
46
|
+
}) => void;
|
|
47
|
+
}
|
|
48
|
+
export type CssProperties = Record<string, string | undefined>;
|
|
49
|
+
export interface CssRenderer {
|
|
50
|
+
generateFontFace: (family: string, properties: CssProperties) => string;
|
|
51
|
+
generateCssVariable: (key: string, values: Array<string>) => string;
|
|
52
|
+
}
|
|
53
|
+
export interface FontMetricsResolver {
|
|
54
|
+
getMetrics: (name: string, font: CollectedFontForMetrics) => Promise<FontFaceMetrics>;
|
|
55
|
+
generateFontFace: (input: {
|
|
56
|
+
metrics: FontFaceMetrics;
|
|
57
|
+
fallbackMetrics: FontFaceMetrics;
|
|
58
|
+
name: string;
|
|
59
|
+
font: string;
|
|
60
|
+
properties: CssProperties;
|
|
61
|
+
}) => string;
|
|
62
|
+
}
|
|
63
|
+
export interface SystemFallbacksProvider {
|
|
64
|
+
getLocalFonts: (fallback: GenericFallbackName) => Array<string> | null;
|
|
65
|
+
getMetricsForLocalFont: (family: string) => FontFaceMetrics;
|
|
66
|
+
}
|
|
67
|
+
export interface FontFetcher {
|
|
68
|
+
fetch: (input: FontFileData) => Promise<Buffer>;
|
|
69
|
+
}
|
|
70
|
+
export interface FontTypeExtractor {
|
|
71
|
+
extract: (url: string) => FontType;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CssProperties, CssRenderer } from '../definitions.js';
|
|
2
|
+
export declare function renderFontFace(properties: CssProperties, minify: boolean): string;
|
|
3
|
+
export declare function renderCssVariable(key: string, values: Array<string>, minify: boolean): string;
|
|
4
|
+
export declare function withFamily(family: string, properties: CssProperties): CssProperties;
|
|
5
|
+
/** If the value contains spaces (which would be incorrectly interpreted), we wrap it in quotes. */
|
|
6
|
+
export declare function handleValueWithSpaces(value: string): string;
|
|
7
|
+
export declare function createMinifiableCssRenderer({ minify }: {
|
|
8
|
+
minify: boolean;
|
|
9
|
+
}): CssRenderer;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function renderFontFace(properties, minify) {
|
|
2
|
+
const lf = minify ? "" : `
|
|
3
|
+
`;
|
|
4
|
+
const sp = minify ? "" : " ";
|
|
5
|
+
return `@font-face${sp}{${lf}${Object.entries(properties).filter(([, value]) => Boolean(value)).map(([key, value]) => `${sp}${sp}${key}:${sp}${value};`).join(lf)}${lf}}${lf}`;
|
|
6
|
+
}
|
|
7
|
+
function renderCssVariable(key, values, minify) {
|
|
8
|
+
const lf = minify ? "" : `
|
|
9
|
+
`;
|
|
10
|
+
const sp = minify ? "" : " ";
|
|
11
|
+
return `:root${sp}{${lf}${sp}${sp}${key}:${sp}${values.map((v) => handleValueWithSpaces(v)).join(`,${sp}`)};${lf}}${lf}`;
|
|
12
|
+
}
|
|
13
|
+
function withFamily(family, properties) {
|
|
14
|
+
return {
|
|
15
|
+
"font-family": handleValueWithSpaces(family),
|
|
16
|
+
...properties
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const SPACE_RE = /\s/;
|
|
20
|
+
function handleValueWithSpaces(value) {
|
|
21
|
+
if (SPACE_RE.test(value)) {
|
|
22
|
+
return JSON.stringify(value);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function createMinifiableCssRenderer({ minify }) {
|
|
27
|
+
return {
|
|
28
|
+
generateFontFace(family, properties) {
|
|
29
|
+
return renderFontFace(withFamily(family, properties), minify);
|
|
30
|
+
},
|
|
31
|
+
generateCssVariable(key, values) {
|
|
32
|
+
return renderCssVariable(key, values, minify);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
createMinifiableCssRenderer,
|
|
38
|
+
handleValueWithSpaces,
|
|
39
|
+
renderCssVariable,
|
|
40
|
+
renderFontFace,
|
|
41
|
+
withFamily
|
|
42
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function createDataCollector({
|
|
2
|
+
hasUrl,
|
|
3
|
+
saveUrl,
|
|
4
|
+
savePreload,
|
|
5
|
+
saveFontData
|
|
6
|
+
}) {
|
|
7
|
+
return {
|
|
8
|
+
collect({ hash, url, init, preload, data }) {
|
|
9
|
+
if (!hasUrl(hash)) {
|
|
10
|
+
saveUrl({ hash, url, init });
|
|
11
|
+
if (preload) {
|
|
12
|
+
savePreload(preload);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
saveFontData({ hash, url, data, init });
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
createDataCollector
|
|
21
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AstroError, AstroErrorData } from "../../../core/errors/index.js";
|
|
2
|
+
function getProps(input) {
|
|
3
|
+
if (input.type === "cannot-load-font-provider") {
|
|
4
|
+
return {
|
|
5
|
+
...AstroErrorData.CannotLoadFontProvider,
|
|
6
|
+
message: AstroErrorData.CannotLoadFontProvider.message(input.data.entrypoint)
|
|
7
|
+
};
|
|
8
|
+
} else if (input.type === "unknown-fs-error") {
|
|
9
|
+
return AstroErrorData.UnknownFilesystemError;
|
|
10
|
+
} else if (input.type === "cannot-fetch-font-file") {
|
|
11
|
+
return {
|
|
12
|
+
...AstroErrorData.CannotFetchFontFile,
|
|
13
|
+
message: AstroErrorData.CannotFetchFontFile.message(input.data.url)
|
|
14
|
+
};
|
|
15
|
+
} else if (input.type === "cannot-extract-font-type") {
|
|
16
|
+
return {
|
|
17
|
+
...AstroErrorData.CannotExtractFontType,
|
|
18
|
+
message: AstroErrorData.CannotExtractFontType.message(input.data.url)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
input;
|
|
22
|
+
return AstroErrorData.UnknownError;
|
|
23
|
+
}
|
|
24
|
+
function createAstroErrorHandler() {
|
|
25
|
+
return {
|
|
26
|
+
handle(input) {
|
|
27
|
+
return new AstroError(getProps(input), { cause: input.cause });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
createAstroErrorHandler
|
|
33
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Storage } from 'unstorage';
|
|
2
|
+
import type { ErrorHandler, FontFetcher } from '../definitions.js';
|
|
3
|
+
export declare function createCachedFontFetcher({ storage, errorHandler, fetch, readFile, }: {
|
|
4
|
+
storage: Storage;
|
|
5
|
+
errorHandler: ErrorHandler;
|
|
6
|
+
fetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
7
|
+
readFile: (url: string) => Promise<Buffer>;
|
|
8
|
+
}): FontFetcher;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { cache } from "../utils.js";
|
|
3
|
+
function createCachedFontFetcher({
|
|
4
|
+
storage,
|
|
5
|
+
errorHandler,
|
|
6
|
+
fetch,
|
|
7
|
+
readFile
|
|
8
|
+
}) {
|
|
9
|
+
return {
|
|
10
|
+
async fetch({ hash, url, init }) {
|
|
11
|
+
return await cache(storage, hash, async () => {
|
|
12
|
+
try {
|
|
13
|
+
if (isAbsolute(url)) {
|
|
14
|
+
return await readFile(url);
|
|
15
|
+
}
|
|
16
|
+
const response = await fetch(url, init ?? void 0);
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw new Error(`Response was not successful, received status code ${response.status}`);
|
|
19
|
+
}
|
|
20
|
+
return Buffer.from(await response.arrayBuffer());
|
|
21
|
+
} catch (cause) {
|
|
22
|
+
throw errorHandler.handle({
|
|
23
|
+
type: "cannot-fetch-font-file",
|
|
24
|
+
data: { url },
|
|
25
|
+
cause
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
createCachedFontFetcher
|
|
34
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { fromBuffer } from "@capsizecss/unpack";
|
|
2
|
+
import { renderFontSrc } from "../utils.js";
|
|
3
|
+
function filterRequiredMetrics({
|
|
4
|
+
ascent,
|
|
5
|
+
descent,
|
|
6
|
+
lineGap,
|
|
7
|
+
unitsPerEm,
|
|
8
|
+
xWidthAvg
|
|
9
|
+
}) {
|
|
10
|
+
return {
|
|
11
|
+
ascent,
|
|
12
|
+
descent,
|
|
13
|
+
lineGap,
|
|
14
|
+
unitsPerEm,
|
|
15
|
+
xWidthAvg
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function toPercentage(value, fractionDigits = 4) {
|
|
19
|
+
const percentage = value * 100;
|
|
20
|
+
return `${+percentage.toFixed(fractionDigits)}%`;
|
|
21
|
+
}
|
|
22
|
+
function createCapsizeFontMetricsResolver({
|
|
23
|
+
fontFetcher,
|
|
24
|
+
cssRenderer
|
|
25
|
+
}) {
|
|
26
|
+
const cache = {};
|
|
27
|
+
return {
|
|
28
|
+
async getMetrics(name, input) {
|
|
29
|
+
cache[name] ??= filterRequiredMetrics(await fromBuffer(await fontFetcher.fetch(input)));
|
|
30
|
+
return cache[name];
|
|
31
|
+
},
|
|
32
|
+
// Source: https://github.com/unjs/fontaine/blob/f00f84032c5d5da72c8798eae4cd68d3ddfbf340/src/css.ts#L170
|
|
33
|
+
generateFontFace({
|
|
34
|
+
metrics,
|
|
35
|
+
fallbackMetrics,
|
|
36
|
+
name: fallbackName,
|
|
37
|
+
font: fallbackFontName,
|
|
38
|
+
properties
|
|
39
|
+
}) {
|
|
40
|
+
const preferredFontXAvgRatio = metrics.xWidthAvg / metrics.unitsPerEm;
|
|
41
|
+
const fallbackFontXAvgRatio = fallbackMetrics.xWidthAvg / fallbackMetrics.unitsPerEm;
|
|
42
|
+
const sizeAdjust = preferredFontXAvgRatio / fallbackFontXAvgRatio;
|
|
43
|
+
const adjustedEmSquare = metrics.unitsPerEm * sizeAdjust;
|
|
44
|
+
const ascentOverride = metrics.ascent / adjustedEmSquare;
|
|
45
|
+
const descentOverride = Math.abs(metrics.descent) / adjustedEmSquare;
|
|
46
|
+
const lineGapOverride = metrics.lineGap / adjustedEmSquare;
|
|
47
|
+
return cssRenderer.generateFontFace(fallbackName, {
|
|
48
|
+
src: renderFontSrc([{ name: fallbackFontName }]),
|
|
49
|
+
"size-adjust": toPercentage(sizeAdjust),
|
|
50
|
+
"ascent-override": toPercentage(ascentOverride),
|
|
51
|
+
"descent-override": toPercentage(descentOverride),
|
|
52
|
+
"line-gap-override": toPercentage(lineGapOverride),
|
|
53
|
+
...properties
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
createCapsizeFontMetricsResolver
|
|
60
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { extname } from "node:path";
|
|
2
|
+
import { isFontType } from "../utils.js";
|
|
3
|
+
function createFontTypeExtractor({
|
|
4
|
+
errorHandler
|
|
5
|
+
}) {
|
|
6
|
+
return {
|
|
7
|
+
extract(url) {
|
|
8
|
+
const extension = extname(url).slice(1);
|
|
9
|
+
if (!isFontType(extension)) {
|
|
10
|
+
throw errorHandler.handle({
|
|
11
|
+
type: "cannot-extract-font-type",
|
|
12
|
+
data: { url },
|
|
13
|
+
cause: `Unexpected extension, got "${extension}"`
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return extension;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createFontTypeExtractor
|
|
22
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import xxhash from "xxhash-wasm";
|
|
2
|
+
import { sortObjectByKey } from "../utils.js";
|
|
3
|
+
async function createXxHasher() {
|
|
4
|
+
const { h64ToString: hashString } = await xxhash();
|
|
5
|
+
return {
|
|
6
|
+
hashString,
|
|
7
|
+
hashObject(input) {
|
|
8
|
+
return hashString(JSON.stringify(sortObjectByKey(input)));
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
createXxHasher
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { resolveEntrypoint } from "../utils.js";
|
|
3
|
+
function createRequireLocalProviderUrlResolver({
|
|
4
|
+
root,
|
|
5
|
+
intercept
|
|
6
|
+
}) {
|
|
7
|
+
return {
|
|
8
|
+
resolve(input) {
|
|
9
|
+
const path = fileURLToPath(resolveEntrypoint(root, input));
|
|
10
|
+
intercept?.(path);
|
|
11
|
+
return path;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
createRequireLocalProviderUrlResolver
|
|
17
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ViteDevServer } from 'vite';
|
|
2
|
+
import type { RemoteFontProviderModResolver } from '../definitions.js';
|
|
3
|
+
export declare function createBuildRemoteFontProviderModResolver(): RemoteFontProviderModResolver;
|
|
4
|
+
export declare function createDevServerRemoteFontProviderModResolver({ server, }: {
|
|
5
|
+
server: ViteDevServer;
|
|
6
|
+
}): RemoteFontProviderModResolver;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function createBuildRemoteFontProviderModResolver() {
|
|
2
|
+
return {
|
|
3
|
+
resolve(id) {
|
|
4
|
+
return import(id);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function createDevServerRemoteFontProviderModResolver({
|
|
9
|
+
server
|
|
10
|
+
}) {
|
|
11
|
+
return {
|
|
12
|
+
resolve(id) {
|
|
13
|
+
return server.ssrLoadModule(id);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
createBuildRemoteFontProviderModResolver,
|
|
19
|
+
createDevServerRemoteFontProviderModResolver
|
|
20
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ErrorHandler, RemoteFontProviderModResolver, RemoteFontProviderResolver } from '../definitions.js';
|
|
2
|
+
export declare function createRemoteFontProviderResolver({ root, modResolver, errorHandler, }: {
|
|
3
|
+
root: URL;
|
|
4
|
+
modResolver: RemoteFontProviderModResolver;
|
|
5
|
+
errorHandler: ErrorHandler;
|
|
6
|
+
}): RemoteFontProviderResolver;
|