astro 6.0.0-beta.1 → 6.0.0-beta.2
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/client.d.ts +4 -4
- package/components/Font.astro +1 -1
- package/dist/assets/endpoint/node.js +21 -4
- package/dist/assets/fonts/config.d.ts +28 -1
- package/dist/assets/fonts/config.js +10 -4
- package/dist/assets/fonts/constants.d.ts +4 -1
- package/dist/assets/fonts/constants.js +8 -0
- package/dist/assets/fonts/core/create-get-font-buffer.d.ts +4 -0
- package/dist/assets/fonts/core/create-get-font-buffer.js +35 -0
- package/dist/assets/fonts/core/filter-preloads.d.ts +2 -0
- package/dist/assets/fonts/{runtime.js → core/filter-preloads.js} +0 -17
- package/dist/assets/fonts/core/resolve-families.d.ts +4 -5
- package/dist/assets/fonts/core/resolve-families.js +8 -13
- package/dist/assets/fonts/definitions.d.ts +4 -10
- package/dist/assets/fonts/infra/require-local-provider-url-resolver.js +11 -3
- package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +13 -5
- package/dist/assets/fonts/infra/unifont-font-resolver.js +60 -18
- package/dist/assets/fonts/orchestrate.d.ts +5 -7
- package/dist/assets/fonts/orchestrate.js +12 -16
- package/dist/assets/fonts/providers/index.d.ts +7 -3
- package/dist/assets/fonts/providers/index.js +83 -9
- package/dist/assets/fonts/providers/local.d.ts +1 -3
- package/dist/assets/fonts/providers/local.js +40 -42
- package/dist/assets/fonts/runtime/client.d.ts +2 -0
- package/dist/assets/fonts/runtime/client.js +9 -0
- package/dist/assets/fonts/runtime/server.d.ts +2 -0
- package/dist/assets/fonts/runtime/server.js +8 -0
- package/dist/assets/fonts/types.d.ts +66 -22
- package/dist/assets/fonts/utils.d.ts +0 -1
- package/dist/assets/fonts/utils.js +0 -11
- package/dist/assets/fonts/vite-plugin-fonts.js +96 -42
- package/dist/assets/services/sharp.js +2 -7
- package/dist/assets/vite-plugin-assets.js +8 -10
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/config/index.d.ts +4 -2
- package/dist/content/content-layer.js +3 -3
- package/dist/content/runtime.js +2 -2
- package/dist/content/vite-plugin-content-assets.d.ts +2 -1
- package/dist/content/vite-plugin-content-assets.js +13 -3
- package/dist/core/build/generate.js +2 -2
- package/dist/core/build/internal.d.ts +8 -0
- package/dist/core/build/internal.js +14 -0
- package/dist/core/build/plugins/plugin-analyzer.js +17 -7
- package/dist/core/build/plugins/plugin-css.js +84 -2
- package/dist/core/build/static-build.js +43 -13
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/compile/style.d.ts +3 -1
- package/dist/core/compile/style.js +32 -1
- package/dist/core/config/config.d.ts +1 -1
- package/dist/core/config/config.js +1 -3
- package/dist/core/config/schemas/base.d.ts +16 -4
- package/dist/core/config/schemas/relative.d.ts +40 -12
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/dev/utils.js +1 -1
- package/dist/core/errors/errors-data.d.ts +6 -5
- package/dist/core/errors/errors-data.js +7 -6
- package/dist/core/logger/core.d.ts +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/index.js +2 -14
- package/dist/core/render-context.js +16 -32
- package/dist/core/session/config.d.ts +2 -2
- package/dist/core/session/config.js +1 -1
- package/dist/core/session/types.d.ts +5 -5
- package/dist/core/session/utils.js +3 -2
- package/dist/core/session/vite-plugin.js +1 -1
- package/dist/manifest/serialized.js +14 -0
- package/dist/runtime/server/render/component.js +4 -28
- package/dist/transitions/events.d.ts +4 -0
- package/dist/transitions/events.js +8 -2
- package/dist/transitions/router.d.ts +0 -4
- package/dist/transitions/router.js +3 -9
- package/dist/types/public/common.d.ts +4 -4
- package/dist/types/public/config.d.ts +7 -4
- package/dist/types/public/context.d.ts +5 -5
- package/dist/vite-plugin-css/index.d.ts +1 -1
- package/dist/vite-plugin-css/index.js +12 -6
- package/dist/vite-plugin-renderers/index.d.ts +0 -1
- package/dist/vite-plugin-renderers/index.js +0 -1
- package/env.d.ts +1 -1
- package/package.json +12 -13
- package/types/fonts.d.ts +1 -1
- package/dist/assets/fonts/infra/build-remote-font-provider-mod-resolver.d.ts +0 -4
- package/dist/assets/fonts/infra/build-remote-font-provider-mod-resolver.js +0 -8
- package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.d.ts +0 -9
- package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.js +0 -14
- package/dist/assets/fonts/infra/remote-font-provider-resolver.d.ts +0 -10
- package/dist/assets/fonts/infra/remote-font-provider-resolver.js +0 -49
- package/dist/assets/fonts/providers/entrypoints/adobe.d.ts +0 -2
- package/dist/assets/fonts/providers/entrypoints/adobe.js +0 -5
- package/dist/assets/fonts/providers/entrypoints/bunny.d.ts +0 -1
- package/dist/assets/fonts/providers/entrypoints/bunny.js +0 -5
- package/dist/assets/fonts/providers/entrypoints/fontshare.d.ts +0 -1
- package/dist/assets/fonts/providers/entrypoints/fontshare.js +0 -5
- package/dist/assets/fonts/providers/entrypoints/fontsource.d.ts +0 -1
- package/dist/assets/fonts/providers/entrypoints/fontsource.js +0 -5
- package/dist/assets/fonts/providers/entrypoints/google.d.ts +0 -2
- package/dist/assets/fonts/providers/entrypoints/google.js +0 -5
- package/dist/assets/fonts/runtime.d.ts +0 -5
|
@@ -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,16 +24,15 @@ async function orchestrate({
|
|
|
25
24
|
stringMatcher,
|
|
26
25
|
createFontResolver
|
|
27
26
|
}) {
|
|
28
|
-
const resolvedFamilies =
|
|
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 });
|
|
35
33
|
const fontFileDataMap = /* @__PURE__ */ new Map();
|
|
36
34
|
const internalConsumableMap = /* @__PURE__ */ new Map();
|
|
37
|
-
const
|
|
35
|
+
const fontData = {};
|
|
38
36
|
const resolvedFamiliesMap = /* @__PURE__ */ new Map();
|
|
39
37
|
for (const family of resolvedFamilies) {
|
|
40
38
|
const key = `${family.cssVariable}:${family.name}:${typeof family.provider === "string" ? family.provider : family.provider.name}`;
|
|
@@ -80,32 +78,30 @@ async function orchestrate({
|
|
|
80
78
|
cssVariable: family.cssVariable
|
|
81
79
|
});
|
|
82
80
|
if (family.provider === LOCAL_PROVIDER_NAME) {
|
|
83
|
-
const
|
|
81
|
+
const fonts = resolveLocalFont({
|
|
84
82
|
family,
|
|
85
83
|
urlProxy,
|
|
86
84
|
fontTypeExtractor,
|
|
87
85
|
fontFileReader
|
|
88
86
|
});
|
|
89
|
-
resolvedFamily.fonts.push(...
|
|
87
|
+
resolvedFamily.fonts.push(...fonts);
|
|
90
88
|
} else {
|
|
91
89
|
const fonts = await fontResolver.resolveFont({
|
|
92
90
|
familyName: family.name,
|
|
93
|
-
|
|
94
|
-
// we specify a provider per font. Name has been set while extracting unifont providers
|
|
95
|
-
// from families (inside extractUnifontProviders).
|
|
96
|
-
provider: family.provider.name,
|
|
91
|
+
provider: family.provider,
|
|
97
92
|
// We do not merge the defaults, we only provide defaults as a fallback
|
|
98
93
|
weights: family.weights ?? defaults.weights,
|
|
99
94
|
styles: family.styles ?? defaults.styles,
|
|
100
95
|
subsets: family.subsets ?? defaults.subsets,
|
|
101
|
-
formats: family.formats ?? defaults.formats
|
|
96
|
+
formats: family.formats ?? defaults.formats,
|
|
97
|
+
options: family.options
|
|
102
98
|
});
|
|
103
99
|
if (fonts.length === 0) {
|
|
104
100
|
logger.warn(
|
|
105
101
|
"assets",
|
|
106
102
|
`No data found for font family ${bold(family.name)}. Review your configuration`
|
|
107
103
|
);
|
|
108
|
-
const availableFamilies = await fontResolver.listFonts({ provider: family.provider
|
|
104
|
+
const availableFamilies = await fontResolver.listFonts({ provider: family.provider });
|
|
109
105
|
if (availableFamilies && availableFamilies.length > 0 && !availableFamilies.includes(family.name)) {
|
|
110
106
|
logger.warn(
|
|
111
107
|
"assets",
|
|
@@ -123,7 +119,7 @@ async function orchestrate({
|
|
|
123
119
|
collectedFonts,
|
|
124
120
|
preloadData
|
|
125
121
|
} of resolvedFamiliesMap.values()) {
|
|
126
|
-
const
|
|
122
|
+
const fontDataValue = [];
|
|
127
123
|
let css = "";
|
|
128
124
|
for (const data of fonts) {
|
|
129
125
|
css += cssRenderer.generateFontFace(
|
|
@@ -141,7 +137,7 @@ async function orchestrate({
|
|
|
141
137
|
variationSettings: pickFontFaceProperty("variationSettings", { data, family })
|
|
142
138
|
})
|
|
143
139
|
);
|
|
144
|
-
|
|
140
|
+
fontDataValue.push({
|
|
145
141
|
weight: renderFontWeight(data.weight),
|
|
146
142
|
style: data.style,
|
|
147
143
|
src: data.src.filter((src) => "url" in src).map((src) => ({
|
|
@@ -168,9 +164,9 @@ async function orchestrate({
|
|
|
168
164
|
}
|
|
169
165
|
css += cssRenderer.generateCssVariable(family.cssVariable, cssVarValues);
|
|
170
166
|
internalConsumableMap.set(family.cssVariable, { preloadData, css });
|
|
171
|
-
|
|
167
|
+
fontData[family.cssVariable] = fontDataValue;
|
|
172
168
|
}
|
|
173
|
-
return { fontFileDataMap, internalConsumableMap,
|
|
169
|
+
return { fontFileDataMap, internalConsumableMap, fontData };
|
|
174
170
|
}
|
|
175
171
|
export {
|
|
176
172
|
orchestrate
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
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
|
-
declare function adobe(config:
|
|
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(
|
|
12
|
+
declare function google(): FontProvider<GoogleFamilyOptions | undefined>;
|
|
13
|
+
/** [Google Icons](https://fonts.google.com/icons) */
|
|
14
|
+
declare function googleicons(): FontProvider<GoogleiconsFamilyOptions | undefined>;
|
|
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,101 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
function google(
|
|
69
|
+
function google() {
|
|
70
|
+
const provider = providers.google();
|
|
71
|
+
let initializedProvider;
|
|
23
72
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
73
|
+
name: provider._name,
|
|
74
|
+
async init(context) {
|
|
75
|
+
initializedProvider = await provider(context);
|
|
76
|
+
},
|
|
77
|
+
async resolveFont({ familyName, ...rest }) {
|
|
78
|
+
return await initializedProvider?.resolveFont(familyName, rest);
|
|
79
|
+
},
|
|
80
|
+
async listFonts() {
|
|
81
|
+
return await initializedProvider?.listFonts?.();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function googleicons() {
|
|
86
|
+
const provider = providers.googleicons();
|
|
87
|
+
let initializedProvider;
|
|
88
|
+
return {
|
|
89
|
+
name: provider._name,
|
|
90
|
+
async init(context) {
|
|
91
|
+
initializedProvider = await provider(context);
|
|
92
|
+
},
|
|
93
|
+
async resolveFont({ familyName, ...rest }) {
|
|
94
|
+
return await initializedProvider?.resolveFont(familyName, rest);
|
|
95
|
+
},
|
|
96
|
+
async listFonts() {
|
|
97
|
+
return await initializedProvider?.listFonts?.();
|
|
98
|
+
}
|
|
26
99
|
};
|
|
27
100
|
}
|
|
28
101
|
const fontProviders = {
|
|
@@ -30,7 +103,8 @@ const fontProviders = {
|
|
|
30
103
|
bunny,
|
|
31
104
|
fontshare,
|
|
32
105
|
fontsource,
|
|
33
|
-
google
|
|
106
|
+
google,
|
|
107
|
+
googleicons
|
|
34
108
|
};
|
|
35
109
|
export {
|
|
36
110
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as fontsMod from "virtual:astro:assets/fonts/internal";
|
|
2
|
+
const fontData = fontsMod.fontData ?? {};
|
|
3
|
+
async function getFontBuffer() {
|
|
4
|
+
throw new Error("[astro:assets] `getFontBuffer()` is not available on the client.");
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
fontData,
|
|
8
|
+
getFontBuffer
|
|
9
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as fontsMod from "virtual:astro:assets/fonts/internal";
|
|
2
|
+
import { createGetFontBuffer } from "../core/create-get-font-buffer.js";
|
|
3
|
+
const fontData = fontsMod.fontData ?? {};
|
|
4
|
+
const getFontBuffer = createGetFontBuffer(fontsMod);
|
|
5
|
+
export {
|
|
6
|
+
fontData,
|
|
7
|
+
getFontBuffer
|
|
8
|
+
};
|
|
@@ -6,15 +6,40 @@ import type { FONT_TYPES, GENERIC_FALLBACK_NAMES, LOCAL_PROVIDER_NAME } from './
|
|
|
6
6
|
import type { CollectedFontForMetrics } from './core/optimize-fallbacks.js';
|
|
7
7
|
type Weight = z.infer<typeof weightSchema>;
|
|
8
8
|
type Display = z.infer<typeof displaySchema>;
|
|
9
|
-
|
|
9
|
+
/** @lintignore */
|
|
10
|
+
export interface FontProviderInitContext {
|
|
11
|
+
storage: {
|
|
12
|
+
getItem: {
|
|
13
|
+
<T = unknown>(key: string): Promise<T | null>;
|
|
14
|
+
<T = unknown>(key: string, init: () => Awaitable<T>): Promise<T>;
|
|
15
|
+
};
|
|
16
|
+
setItem: (key: string, value: unknown) => Awaitable<void>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
type Awaitable<T> = T | Promise<T>;
|
|
20
|
+
export interface FontProvider<TFamilyOptions extends Record<string, any> | undefined | never = never> {
|
|
10
21
|
/**
|
|
11
|
-
*
|
|
22
|
+
* The font provider name, used for display and deduplication.
|
|
12
23
|
*/
|
|
13
|
-
|
|
24
|
+
name: string;
|
|
14
25
|
/**
|
|
15
|
-
* Optional serializable object
|
|
26
|
+
* Optional serializable object, used for deduplication.
|
|
16
27
|
*/
|
|
17
28
|
config?: Record<string, any> | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Optional callback, used to perform any initialization logic.
|
|
31
|
+
*/
|
|
32
|
+
init?: ((context: FontProviderInitContext) => Awaitable<void>) | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Required callback, used to retrieve and return font face data based on the given options.
|
|
35
|
+
*/
|
|
36
|
+
resolveFont: (options: ResolveFontOptions<TFamilyOptions>) => Awaitable<{
|
|
37
|
+
fonts: Array<unifont.FontFaceData>;
|
|
38
|
+
} | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* Optional callback, used to return the list of available font names.
|
|
41
|
+
*/
|
|
42
|
+
listFonts?: (() => Awaitable<Array<string> | undefined>) | undefined;
|
|
18
43
|
}
|
|
19
44
|
interface RequiredFamilyAttributes {
|
|
20
45
|
/**
|
|
@@ -89,11 +114,6 @@ interface FamilyProperties {
|
|
|
89
114
|
*/
|
|
90
115
|
unicodeRange?: [string, ...Array<string>] | undefined;
|
|
91
116
|
}
|
|
92
|
-
export interface ResolvedFontProvider {
|
|
93
|
-
name?: string;
|
|
94
|
-
provider: (config?: Record<string, any>) => unifont.Provider;
|
|
95
|
-
config?: Record<string, any>;
|
|
96
|
-
}
|
|
97
117
|
type Src = string | URL | {
|
|
98
118
|
url: string | URL;
|
|
99
119
|
tech?: string | undefined;
|
|
@@ -126,11 +146,32 @@ export interface ResolvedLocalFontFamily extends ResolvedFontFamilyAttributes, O
|
|
|
126
146
|
}>;
|
|
127
147
|
}>;
|
|
128
148
|
}
|
|
129
|
-
|
|
149
|
+
type WithOptions<TFontProvider extends FontProvider> = TFontProvider extends FontProvider<infer TFamilyOptions> ? [TFamilyOptions] extends [never] ? {
|
|
150
|
+
/**
|
|
151
|
+
* Options forwarded to the font provider while resolving this font family.
|
|
152
|
+
*/
|
|
153
|
+
options?: undefined;
|
|
154
|
+
} : undefined extends TFamilyOptions ? {
|
|
155
|
+
/**
|
|
156
|
+
* Options forwarded to the font provider while resolving this font family.
|
|
157
|
+
*/
|
|
158
|
+
options?: TFamilyOptions;
|
|
159
|
+
} : {
|
|
160
|
+
/**
|
|
161
|
+
* Options forwarded to the font provider while resolving this font family.
|
|
162
|
+
*/
|
|
163
|
+
options: TFamilyOptions;
|
|
164
|
+
} : {
|
|
165
|
+
/**
|
|
166
|
+
* Options forwarded to the font provider while resolving this font family.
|
|
167
|
+
*/
|
|
168
|
+
options?: undefined;
|
|
169
|
+
};
|
|
170
|
+
export type RemoteFontFamily<TFontProvider extends FontProvider = FontProvider> = RequiredFamilyAttributes & Omit<FamilyProperties, 'weight' | 'style' | 'subsets' | 'formats'> & Fallbacks & WithOptions<NoInfer<TFontProvider>> & {
|
|
130
171
|
/**
|
|
131
172
|
* The source of your font files. You can use a built-in provider or write your own custom provider.
|
|
132
173
|
*/
|
|
133
|
-
provider:
|
|
174
|
+
provider: TFontProvider;
|
|
134
175
|
/**
|
|
135
176
|
* @default `[400]`
|
|
136
177
|
*
|
|
@@ -159,13 +200,12 @@ export interface RemoteFontFamily extends RequiredFamilyAttributes, Omit<FamilyP
|
|
|
159
200
|
* An array of [font formats](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@font-face/src#font_formats).
|
|
160
201
|
*/
|
|
161
202
|
formats?: [FontType, ...Array<FontType>] | undefined;
|
|
162
|
-
}
|
|
203
|
+
};
|
|
163
204
|
/** @lintignore somehow required by pickFontFaceProperty in utils */
|
|
164
|
-
export interface ResolvedRemoteFontFamily extends ResolvedFontFamilyAttributes, Omit<RemoteFontFamily, '
|
|
165
|
-
provider: ResolvedFontProvider;
|
|
205
|
+
export interface ResolvedRemoteFontFamily extends ResolvedFontFamilyAttributes, Omit<RemoteFontFamily, 'weights'> {
|
|
166
206
|
weights?: Array<string>;
|
|
167
207
|
}
|
|
168
|
-
export type FontFamily = LocalFontFamily | RemoteFontFamily
|
|
208
|
+
export type FontFamily<TFontProvider extends FontProvider = FontProvider> = LocalFontFamily | RemoteFontFamily<TFontProvider>;
|
|
169
209
|
export type ResolvedFontFamily = ResolvedLocalFontFamily | ResolvedRemoteFontFamily;
|
|
170
210
|
export type FontType = (typeof FONT_TYPES)[number];
|
|
171
211
|
/**
|
|
@@ -186,7 +226,7 @@ export interface PreloadData {
|
|
|
186
226
|
}
|
|
187
227
|
export type FontFaceMetrics = Pick<Font, 'ascent' | 'descent' | 'lineGap' | 'unitsPerEm' | 'xWidthAvg'>;
|
|
188
228
|
export type GenericFallbackName = (typeof GENERIC_FALLBACK_NAMES)[number];
|
|
189
|
-
export type Defaults =
|
|
229
|
+
export type Defaults = Required<Pick<ResolvedRemoteFontFamily, 'weights' | 'styles' | 'subsets' | 'fallbacks' | 'optimizedFallbacks' | 'formats'>>;
|
|
190
230
|
export interface FontFileData {
|
|
191
231
|
hash: string;
|
|
192
232
|
url: string;
|
|
@@ -224,18 +264,22 @@ export interface FontData {
|
|
|
224
264
|
/**
|
|
225
265
|
* Holds associations of CSS variables and font data to be exposed via virtual module.
|
|
226
266
|
*/
|
|
227
|
-
export type
|
|
267
|
+
export type FontDataRecord = Record<string, Array<FontData>>;
|
|
228
268
|
export type Style = z.output<typeof styleSchema>;
|
|
229
269
|
export type PreloadFilter = boolean | Array<{
|
|
230
270
|
weight?: string | number;
|
|
231
271
|
style?: string;
|
|
232
272
|
subset?: string;
|
|
233
273
|
}>;
|
|
234
|
-
export interface
|
|
274
|
+
export interface ResolveFontOptions<FamilyOptions extends Record<string, any> | undefined | never = never> {
|
|
235
275
|
familyName: string;
|
|
236
|
-
weights: string[]
|
|
237
|
-
styles: Style[]
|
|
238
|
-
subsets: string[]
|
|
239
|
-
formats: FontType[]
|
|
276
|
+
weights: string[];
|
|
277
|
+
styles: Style[];
|
|
278
|
+
subsets: string[];
|
|
279
|
+
formats: FontType[];
|
|
280
|
+
options: [FamilyOptions] extends [never] ? undefined : FamilyOptions | undefined;
|
|
240
281
|
}
|
|
282
|
+
export type BufferImports = Record<string, () => Promise<{
|
|
283
|
+
default: Buffer | null;
|
|
284
|
+
}>>;
|
|
241
285
|
export {};
|
|
@@ -20,7 +20,6 @@ export declare function cache(storage: Storage, key: string, cb: () => Promise<B
|
|
|
20
20
|
export declare function isGenericFontFamily(str: string): str is GenericFallbackName;
|
|
21
21
|
export declare function dedupe<const T extends Array<any>>(arr: T): T;
|
|
22
22
|
export declare function sortObjectByKey<T extends Record<string, any>>(unordered: T): T;
|
|
23
|
-
export declare function resolveEntrypoint(root: URL, entrypoint: string): URL;
|
|
24
23
|
export declare function pickFontFaceProperty<T extends keyof Pick<unifont.FontFaceData, 'display' | 'unicodeRange' | 'stretch' | 'featureSettings' | 'variationSettings'>>(property: T, { data, family }: {
|
|
25
24
|
data: unifont.FontFaceData;
|
|
26
25
|
family: ResolvedFontFamily;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
1
|
import { FONT_TYPES, GENERIC_FALLBACK_NAMES, LOCAL_PROVIDER_NAME } from "./constants.js";
|
|
4
2
|
function unifontFontFaceDataToProperties(font) {
|
|
5
3
|
return {
|
|
@@ -61,14 +59,6 @@ function sortObjectByKey(unordered) {
|
|
|
61
59
|
}, {});
|
|
62
60
|
return ordered;
|
|
63
61
|
}
|
|
64
|
-
function resolveEntrypoint(root, entrypoint) {
|
|
65
|
-
const require2 = createRequire(root);
|
|
66
|
-
try {
|
|
67
|
-
return pathToFileURL(require2.resolve(entrypoint));
|
|
68
|
-
} catch {
|
|
69
|
-
return new URL(entrypoint, root);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
62
|
function pickFontFaceProperty(property, { data, family }) {
|
|
73
63
|
return data[property] ?? (family.provider === LOCAL_PROVIDER_NAME ? void 0 : family[property]);
|
|
74
64
|
}
|
|
@@ -80,7 +70,6 @@ export {
|
|
|
80
70
|
pickFontFaceProperty,
|
|
81
71
|
renderFontSrc,
|
|
82
72
|
renderFontWeight,
|
|
83
|
-
resolveEntrypoint,
|
|
84
73
|
sortObjectByKey,
|
|
85
74
|
unifontFontFaceDataToProperties,
|
|
86
75
|
withoutQuotes
|