astro 6.0.0-beta.0 → 6.0.0-beta.10
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/README.md +1 -1
- package/bin/astro.mjs +1 -1
- package/client.d.ts +6 -4
- package/components/Code.astro +2 -3
- package/components/Font.astro +4 -10
- package/components/Picture.astro +10 -3
- package/dist/assets/consts.js +2 -1
- package/dist/assets/endpoint/node.js +21 -4
- package/dist/assets/fonts/config.d.ts +10 -68
- package/dist/assets/fonts/config.js +33 -55
- package/dist/assets/fonts/constants.d.ts +2 -2
- package/dist/assets/fonts/constants.js +4 -2
- package/dist/assets/fonts/core/collect-component-data.d.ts +9 -0
- package/dist/assets/fonts/core/collect-component-data.js +47 -0
- package/dist/assets/fonts/core/collect-font-assets-from-faces.d.ts +17 -0
- package/dist/assets/fonts/core/collect-font-assets-from-faces.js +71 -0
- package/dist/assets/fonts/core/collect-font-data.d.ts +4 -0
- package/dist/assets/fonts/core/collect-font-data.js +23 -0
- package/dist/assets/fonts/core/compute-font-families-assets.d.ts +20 -0
- package/dist/assets/fonts/core/compute-font-families-assets.js +67 -0
- package/dist/assets/fonts/core/filter-and-transform-font-faces.d.ts +20 -0
- package/dist/assets/fonts/core/filter-and-transform-font-faces.js +39 -0
- package/dist/assets/fonts/core/filter-preloads.d.ts +2 -0
- package/dist/assets/fonts/core/filter-preloads.js +37 -0
- package/dist/assets/fonts/core/get-or-create-font-family-assets.d.ts +8 -0
- package/dist/assets/fonts/core/get-or-create-font-family-assets.js +34 -0
- package/dist/assets/fonts/core/optimize-fallbacks.d.ts +2 -3
- package/dist/assets/fonts/core/optimize-fallbacks.js +2 -3
- package/dist/assets/fonts/core/resolve-family.d.ts +6 -0
- package/dist/assets/fonts/core/resolve-family.js +23 -0
- package/dist/assets/fonts/definitions.d.ts +9 -37
- package/dist/assets/fonts/infra/build-font-file-id-generator.d.ts +13 -0
- package/dist/assets/fonts/infra/{build-url-proxy-hash-resolver.js → build-font-file-id-generator.js} +3 -6
- package/dist/assets/fonts/infra/build-url-resolver.d.ts +1 -1
- package/dist/assets/fonts/infra/build-url-resolver.js +4 -4
- package/dist/assets/fonts/infra/cached-font-fetcher.d.ts +1 -1
- package/dist/assets/fonts/infra/cached-font-fetcher.js +11 -3
- package/dist/assets/fonts/infra/capsize-font-metrics-resolver.d.ts +2 -2
- package/dist/assets/fonts/infra/dev-font-file-id-generator.d.ts +16 -0
- package/dist/assets/fonts/infra/{dev-url-proxy-hash-resolver.js → dev-font-file-id-generator.js} +8 -8
- package/dist/assets/fonts/infra/dev-url-resolver.d.ts +1 -1
- package/dist/assets/fonts/infra/dev-url-resolver.js +2 -2
- package/dist/assets/fonts/infra/fs-font-file-content-resolver.d.ts +10 -0
- package/dist/assets/fonts/infra/fs-font-file-content-resolver.js +21 -0
- package/dist/assets/fonts/infra/minifiable-css-renderer.d.ts +2 -1
- package/dist/assets/fonts/infra/{font-type-extractor.d.ts → node-font-type-extractor.d.ts} +1 -1
- package/dist/assets/fonts/infra/{font-type-extractor.js → node-font-type-extractor.js} +2 -2
- package/dist/assets/fonts/infra/unifont-font-resolver.d.ts +17 -7
- package/dist/assets/fonts/infra/unifont-font-resolver.js +64 -25
- package/dist/assets/fonts/providers/index.d.ts +13 -4
- package/dist/assets/fonts/providers/index.js +91 -9
- package/dist/assets/fonts/providers/local.d.ts +54 -10
- package/dist/assets/fonts/providers/local.js +65 -50
- package/dist/assets/fonts/runtime.d.ts +1 -5
- package/dist/assets/fonts/runtime.js +3 -52
- package/dist/assets/fonts/sync.js +2 -2
- package/dist/assets/fonts/types.d.ts +125 -118
- package/dist/assets/fonts/utils.d.ts +1 -8
- package/dist/assets/fonts/utils.js +1 -26
- package/dist/assets/fonts/vite-plugin-fonts.js +163 -166
- package/dist/assets/internal.js +25 -17
- package/dist/assets/services/service.d.ts +10 -2
- package/dist/assets/services/service.js +9 -2
- package/dist/assets/services/sharp.d.ts +5 -1
- package/dist/assets/services/sharp.js +12 -9
- package/dist/assets/types.d.ts +1 -0
- package/dist/assets/utils/assets.d.ts +23 -0
- package/dist/assets/utils/assets.js +24 -0
- package/dist/assets/utils/index.d.ts +1 -0
- package/dist/assets/utils/index.js +2 -0
- package/dist/assets/vite-plugin-assets.js +20 -13
- package/dist/cli/add/index.js +151 -46
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/config/index.d.ts +3 -2
- package/dist/container/index.js +3 -1
- package/dist/content/consts.d.ts +1 -0
- package/dist/content/consts.js +2 -0
- package/dist/content/content-layer.js +13 -6
- package/dist/content/loaders/file.d.ts +2 -1
- package/dist/content/loaders/file.js +1 -1
- package/dist/content/loaders/glob.d.ts +6 -0
- package/dist/content/loaders/glob.js +9 -3
- package/dist/content/loaders/types.d.ts +7 -1
- package/dist/content/runtime-assets.js +2 -1
- package/dist/content/runtime.js +6 -4
- package/dist/content/vite-plugin-content-assets.d.ts +2 -1
- package/dist/content/vite-plugin-content-assets.js +13 -3
- package/dist/core/app/dev/app.d.ts +6 -4
- package/dist/core/app/dev/app.js +9 -1
- package/dist/core/app/dev/pipeline.js +2 -1
- package/dist/core/app/entrypoint/dev.d.ts +2 -0
- package/dist/core/app/entrypoint/dev.js +27 -0
- package/dist/core/app/entrypoint/prod.d.ts +2 -0
- package/dist/core/app/entrypoint/prod.js +8 -0
- package/dist/core/app/entrypoint.d.ts +1 -2
- package/dist/core/app/entrypoint.js +1 -12
- package/dist/core/app/manifest.d.ts +1 -0
- package/dist/core/app/pipeline.js +3 -1
- package/dist/core/app/types.d.ts +3 -0
- package/dist/core/build/app.d.ts +2 -0
- package/dist/core/build/app.js +5 -0
- package/dist/core/build/default-prerenderer.d.ts +22 -0
- package/dist/core/build/default-prerenderer.js +37 -0
- package/dist/core/build/generate.js +181 -255
- package/dist/core/build/index.js +3 -4
- package/dist/core/build/internal.d.ts +34 -0
- package/dist/core/build/internal.js +30 -1
- package/dist/core/build/plugins/index.js +3 -1
- package/dist/core/build/plugins/plugin-analyzer.js +17 -7
- package/dist/core/build/plugins/plugin-css.js +108 -23
- package/dist/core/build/plugins/plugin-internals.js +11 -7
- package/dist/core/build/plugins/plugin-manifest.js +6 -4
- package/dist/core/build/plugins/plugin-ssr.d.ts +2 -1
- package/dist/core/build/plugins/plugin-ssr.js +17 -13
- package/dist/core/build/static-build.d.ts +0 -2
- package/dist/core/build/static-build.js +117 -76
- package/dist/core/build/vite-plugin-ssr-assets.d.ts +9 -0
- package/dist/core/build/vite-plugin-ssr-assets.js +94 -0
- 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 +59 -105
- package/dist/core/config/schemas/base.js +4 -3
- package/dist/core/config/schemas/refined.js +4 -4
- package/dist/core/config/schemas/relative.d.ts +105 -227
- package/dist/core/config/settings.js +1 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.d.ts +1 -1
- package/dist/core/create-vite.js +3 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/dev/utils.js +23 -3
- package/dist/core/errors/errors-data.d.ts +16 -37
- package/dist/core/errors/errors-data.js +8 -21
- 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 +18 -34
- package/dist/core/routing/manifest/create.js +9 -1
- package/dist/core/routing/rewrite.js +1 -1
- package/dist/core/server-islands/endpoint.js +13 -2
- package/dist/core/session/config.d.ts +3 -3
- package/dist/core/session/config.js +2 -2
- 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/core/sync/index.js +35 -29
- package/dist/integrations/hooks.d.ts +4 -4
- package/dist/integrations/hooks.js +9 -5
- package/dist/manifest/serialized.js +19 -3
- package/dist/runtime/client/dev-toolbar/settings.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/settings.js +5 -0
- package/dist/runtime/prerender/static-paths.d.ts +25 -0
- package/dist/runtime/prerender/static-paths.js +75 -0
- package/dist/runtime/server/render/component.js +4 -28
- package/dist/runtime/server/render/server-islands.js +5 -4
- 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/astro.d.ts +2 -1
- package/dist/types/public/common.d.ts +4 -4
- package/dist/types/public/config.d.ts +265 -61
- package/dist/types/public/context.d.ts +6 -6
- package/dist/types/public/integrations.d.ts +55 -9
- package/dist/types/public/toolbar.d.ts +2 -0
- package/dist/vite-plugin-app/app.d.ts +5 -0
- package/dist/vite-plugin-app/app.js +13 -2
- package/dist/vite-plugin-app/createAstroServerApp.js +15 -0
- package/dist/vite-plugin-app/index.d.ts +2 -2
- package/dist/vite-plugin-app/index.js +42 -11
- package/dist/vite-plugin-app/pipeline.js +23 -11
- package/dist/vite-plugin-astro-server/plugin.js +12 -5
- package/dist/vite-plugin-astro-server/route-guard.d.ts +10 -0
- package/dist/vite-plugin-astro-server/route-guard.js +54 -0
- package/dist/vite-plugin-astro-server/vite.js +2 -1
- package/dist/vite-plugin-css/const.d.ts +7 -0
- package/dist/vite-plugin-css/const.js +16 -0
- package/dist/vite-plugin-css/index.js +25 -13
- package/dist/vite-plugin-css/util.d.ts +2 -0
- package/dist/vite-plugin-css/util.js +10 -2
- package/dist/vite-plugin-hmr-reload/index.js +11 -0
- package/dist/vite-plugin-markdown/content-entry-type.js +0 -1
- package/dist/vite-plugin-markdown/index.js +0 -1
- package/dist/vite-plugin-renderers/index.d.ts +0 -1
- package/dist/vite-plugin-renderers/index.js +0 -1
- package/dist/vite-plugin-routes/index.js +8 -6
- package/dist/vite-plugin-static-paths/index.d.ts +9 -0
- package/dist/vite-plugin-static-paths/index.js +35 -0
- package/dist/vite-plugin-utils/index.js +2 -2
- package/env.d.ts +1 -1
- package/package.json +33 -33
- package/types/fonts.d.ts +1 -1
- package/dist/assets/fonts/core/normalize-remote-font-faces.d.ts +0 -7
- package/dist/assets/fonts/core/normalize-remote-font-faces.js +0 -41
- package/dist/assets/fonts/core/resolve-families.d.ts +0 -17
- package/dist/assets/fonts/core/resolve-families.js +0 -68
- 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/build-url-proxy-hash-resolver.d.ts +0 -15
- package/dist/assets/fonts/infra/data-collector.d.ts +0 -10
- package/dist/assets/fonts/infra/data-collector.js +0 -35
- 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/dev-url-proxy-hash-resolver.d.ts +0 -15
- package/dist/assets/fonts/infra/local-url-proxy-content-resolver.d.ts +0 -4
- package/dist/assets/fonts/infra/local-url-proxy-content-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/infra/remote-url-proxy-content-resolver.d.ts +0 -4
- package/dist/assets/fonts/infra/remote-url-proxy-content-resolver.js +0 -9
- package/dist/assets/fonts/infra/require-local-provider-url-resolver.d.ts +0 -9
- package/dist/assets/fonts/infra/require-local-provider-url-resolver.js +0 -22
- package/dist/assets/fonts/infra/url-proxy.d.ts +0 -16
- package/dist/assets/fonts/infra/url-proxy.js +0 -50
- package/dist/assets/fonts/orchestrate.d.ts +0 -44
- package/dist/assets/fonts/orchestrate.js +0 -177
- 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/core/shiki.d.ts +0 -2
- package/dist/core/shiki.js +0 -16
package/README.md
CHANGED
|
@@ -38,6 +38,6 @@ Join us on [Discord](https://astro.build/chat) to meet other contributors. We'll
|
|
|
38
38
|
|
|
39
39
|
## Sponsors
|
|
40
40
|
|
|
41
|
-
Astro is generously supported by [
|
|
41
|
+
Astro is generously supported by [Cloudflare](https://www.cloudflare.com/pt-br/?utm_source=astro&utm_medium=astro&utm_campaign=astro), [Mux](https://www.mux.com/?utm_campaign=21819274-Astro&utm_source=astro), [Netlify](https://www.netlify.com/?utm_campaign=Astro-2024&utm_source=astro-referral), [Webflow](https://webflow.com/feature/cloud?utm_source=Astro&utm_medium=tech-partner&utm_campaign=fy26-astro&utm_content=fy26-docs), and several [other amazing organizations](https://opencollective.com/astrodotbuild).
|
|
42
42
|
|
|
43
43
|
[❤️ Sponsor Astro! ❤️](https://github.com/withastro/.github/blob/main/FUNDING.md)
|
package/bin/astro.mjs
CHANGED
|
@@ -12,7 +12,7 @@ const CI_INSTRUCTIONS = {
|
|
|
12
12
|
const IS_STACKBLITZ = !!process.versions.webcontainer;
|
|
13
13
|
|
|
14
14
|
// Hardcode supported Node.js version so we don't have to read differently in CJS & ESM.
|
|
15
|
-
const engines = IS_STACKBLITZ ? '>=20.19.
|
|
15
|
+
const engines = IS_STACKBLITZ ? '>=20.19.1' : '>=22.12.0';
|
|
16
16
|
const skipSemverCheckIfAbove = IS_STACKBLITZ ? 21 : 23;
|
|
17
17
|
|
|
18
18
|
/** `astro *` */
|
package/client.d.ts
CHANGED
|
@@ -58,9 +58,7 @@ declare module 'astro:assets' {
|
|
|
58
58
|
Image: typeof import('./components/Image.astro').default;
|
|
59
59
|
Picture: typeof import('./components/Picture.astro').default;
|
|
60
60
|
Font: typeof import('./components/Font.astro').default;
|
|
61
|
-
|
|
62
|
-
cssVariable: import('astro:assets').CssVariable,
|
|
63
|
-
) => Array<import('astro:assets').FontData>;
|
|
61
|
+
fontData: Record<import('astro:assets').CssVariable, Array<import('astro:assets').FontData>>;
|
|
64
62
|
};
|
|
65
63
|
|
|
66
64
|
type ImgAttributes = import('./dist/type-utils.js').WithRequired<
|
|
@@ -82,7 +80,7 @@ declare module 'astro:assets' {
|
|
|
82
80
|
Picture,
|
|
83
81
|
Font,
|
|
84
82
|
inferRemoteSize,
|
|
85
|
-
|
|
83
|
+
fontData,
|
|
86
84
|
}: AstroAssets;
|
|
87
85
|
}
|
|
88
86
|
|
|
@@ -288,6 +286,10 @@ declare module 'astro:ssr-manifest' {
|
|
|
288
286
|
export const manifest: import('./dist/types/public/internal.js').SSRManifest;
|
|
289
287
|
}
|
|
290
288
|
|
|
289
|
+
declare module 'astro:static-paths' {
|
|
290
|
+
export const StaticPaths: typeof import('./dist/runtime/prerender/static-paths.js').StaticPaths;
|
|
291
|
+
}
|
|
292
|
+
|
|
291
293
|
// Everything below are Vite's types (apart from image types, which are in `client.d.ts`)
|
|
292
294
|
|
|
293
295
|
// CSS modules
|
package/components/Code.astro
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
import type
|
|
2
|
+
import { type ThemePresets, createShikiHighlighter } from '@astrojs/markdown-remark';
|
|
3
3
|
import type { ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
|
|
4
4
|
import { bundledLanguages } from 'shiki/langs';
|
|
5
|
-
import { getCachedHighlighter } from '../dist/core/shiki.js';
|
|
6
5
|
import type { CodeLanguage } from '../dist/types/public/common.js';
|
|
7
6
|
import type { HTMLAttributes } from '../types.js';
|
|
8
7
|
|
|
@@ -95,7 +94,7 @@ if (typeof lang === 'object') {
|
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
const highlighter = await
|
|
97
|
+
const highlighter = await createShikiHighlighter({
|
|
99
98
|
langs: [
|
|
100
99
|
typeof lang === 'string'
|
|
101
100
|
? Object.keys(bundledLanguages).includes(lang)
|
package/components/Font.astro
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
---
|
|
2
|
-
import
|
|
3
|
-
import { filterPreloads } from '
|
|
2
|
+
import { componentDataByCssVariable } from 'virtual:astro:assets/fonts/internal';
|
|
3
|
+
import { filterPreloads } from '../dist/assets/fonts/core/filter-preloads.js';
|
|
4
4
|
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
|
|
5
5
|
|
|
6
|
-
// TODO: remove check when fonts are stabilized
|
|
7
|
-
const { internalConsumableMap } = mod;
|
|
8
|
-
if (!internalConsumableMap) {
|
|
9
|
-
throw new AstroError(AstroErrorData.ExperimentalFontsNotEnabled);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
6
|
interface Props {
|
|
13
7
|
/** The `cssVariable` registered in your Astro configuration. */
|
|
14
8
|
cssVariable: import('astro:assets').CssVariable;
|
|
@@ -17,7 +11,7 @@ interface Props {
|
|
|
17
11
|
}
|
|
18
12
|
|
|
19
13
|
const { cssVariable, preload = false } = Astro.props as Props;
|
|
20
|
-
const data =
|
|
14
|
+
const data = componentDataByCssVariable.get(cssVariable);
|
|
21
15
|
if (!data) {
|
|
22
16
|
throw new AstroError({
|
|
23
17
|
...AstroErrorData.FontFamilyNotFound,
|
|
@@ -25,7 +19,7 @@ if (!data) {
|
|
|
25
19
|
});
|
|
26
20
|
}
|
|
27
21
|
|
|
28
|
-
const filteredPreloadData = filterPreloads(data.
|
|
22
|
+
const filteredPreloadData = filterPreloads(data.preloads, preload);
|
|
29
23
|
---
|
|
30
24
|
|
|
31
25
|
<style set:html={data.css}></style>
|
package/components/Picture.astro
CHANGED
|
@@ -73,13 +73,20 @@ const optimizedImages: GetImageResult[] = await Promise.all(
|
|
|
73
73
|
),
|
|
74
74
|
);
|
|
75
75
|
|
|
76
|
+
// Clone the `src` object if it's an ESM import so that we don't refer to any properties of the original object
|
|
77
|
+
// Causing our generate step to think the image is used outside of the image optimization pipeline
|
|
78
|
+
const clonedSrc = isESMImportedImage(originalSrc)
|
|
79
|
+
? // @ts-expect-error - clone is a private, hidden prop
|
|
80
|
+
(originalSrc.clone ?? originalSrc)
|
|
81
|
+
: originalSrc;
|
|
82
|
+
|
|
76
83
|
let resultFallbackFormat = fallbackFormat ?? defaultFallbackFormat;
|
|
77
84
|
if (
|
|
78
85
|
!fallbackFormat &&
|
|
79
|
-
isESMImportedImage(
|
|
80
|
-
(specialFormatsFallback as ReadonlyArray<string>).includes(
|
|
86
|
+
isESMImportedImage(clonedSrc) &&
|
|
87
|
+
(specialFormatsFallback as ReadonlyArray<string>).includes(clonedSrc.format)
|
|
81
88
|
) {
|
|
82
|
-
resultFallbackFormat =
|
|
89
|
+
resultFallbackFormat = clonedSrc.format;
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
const fallbackImage = await getImage({
|
package/dist/assets/consts.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { outDir } from "astro:assets";
|
|
1
|
+
import { outDir, serverDir } from "astro:assets";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { isParentDirectory } from "@astrojs/internal-helpers/path";
|
|
5
6
|
import { handleImageRequest } from "./shared.js";
|
|
6
7
|
async function loadLocalImage(src, url) {
|
|
8
|
+
const outDirURL = resolveOutDir();
|
|
7
9
|
const idx = url.pathname.indexOf("/_image");
|
|
8
10
|
if (idx > 0) {
|
|
9
11
|
src = src.slice(idx);
|
|
10
12
|
}
|
|
11
|
-
if (!URL.canParse("." + src,
|
|
13
|
+
if (!URL.canParse("." + src, outDirURL)) {
|
|
12
14
|
return void 0;
|
|
13
15
|
}
|
|
14
|
-
const fileUrl = new URL("." + src,
|
|
16
|
+
const fileUrl = new URL("." + src, outDirURL);
|
|
15
17
|
if (fileUrl.protocol !== "file:") {
|
|
16
18
|
return void 0;
|
|
17
19
|
}
|
|
18
|
-
if (!isParentDirectory(fileURLToPath(
|
|
20
|
+
if (!isParentDirectory(fileURLToPath(outDirURL), fileURLToPath(fileUrl))) {
|
|
19
21
|
return void 0;
|
|
20
22
|
}
|
|
21
23
|
try {
|
|
@@ -34,6 +36,21 @@ const GET = async ({ request }) => {
|
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
};
|
|
39
|
+
function resolveOutDir() {
|
|
40
|
+
const serverDirPath = fileURLToPath(serverDir);
|
|
41
|
+
const rel = path.relative(serverDirPath, fileURLToPath(outDir));
|
|
42
|
+
const serverFolder = path.basename(serverDirPath);
|
|
43
|
+
let serverEntryFolderURL = path.dirname(import.meta.url);
|
|
44
|
+
while (!serverEntryFolderURL.endsWith(serverFolder)) {
|
|
45
|
+
serverEntryFolderURL = path.dirname(serverEntryFolderURL);
|
|
46
|
+
}
|
|
47
|
+
const serverEntryURL = serverEntryFolderURL + "/entry.mjs";
|
|
48
|
+
const outDirURL = new URL(appendForwardSlash(rel), serverEntryURL);
|
|
49
|
+
return outDirURL;
|
|
50
|
+
}
|
|
51
|
+
function appendForwardSlash(pth) {
|
|
52
|
+
return pth.endsWith("/") ? pth : pth + "/";
|
|
53
|
+
}
|
|
37
54
|
export {
|
|
38
55
|
GET
|
|
39
56
|
};
|
|
@@ -1,80 +1,23 @@
|
|
|
1
1
|
import * as z from 'zod/v4';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
2
|
+
import type { FontProvider } from './types.js';
|
|
3
|
+
export declare const WeightSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
4
|
+
export declare const StyleSchema: z.ZodEnum<{
|
|
4
5
|
normal: "normal";
|
|
5
6
|
italic: "italic";
|
|
6
7
|
oblique: "oblique";
|
|
7
8
|
}>;
|
|
8
|
-
export declare const
|
|
9
|
+
export declare const DisplaySchema: z.ZodEnum<{
|
|
9
10
|
optional: "optional";
|
|
10
11
|
auto: "auto";
|
|
11
12
|
block: "block";
|
|
12
13
|
swap: "swap";
|
|
13
14
|
fallback: "fallback";
|
|
14
15
|
}>;
|
|
15
|
-
export declare const
|
|
16
|
-
|
|
17
|
-
variants: z.ZodTuple<[z.ZodObject<{
|
|
18
|
-
src: z.ZodTuple<[z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>, z.ZodObject<{
|
|
19
|
-
url: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
20
|
-
tech: z.ZodOptional<z.ZodString>;
|
|
21
|
-
}, z.core.$strict>]>], z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>, z.ZodObject<{
|
|
22
|
-
url: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
23
|
-
tech: z.ZodOptional<z.ZodString>;
|
|
24
|
-
}, z.core.$strict>]>>;
|
|
25
|
-
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
26
|
-
style: z.ZodOptional<z.ZodEnum<{
|
|
27
|
-
normal: "normal";
|
|
28
|
-
italic: "italic";
|
|
29
|
-
oblique: "oblique";
|
|
30
|
-
}>>;
|
|
31
|
-
display: z.ZodOptional<z.ZodEnum<{
|
|
32
|
-
optional: "optional";
|
|
33
|
-
auto: "auto";
|
|
34
|
-
block: "block";
|
|
35
|
-
swap: "swap";
|
|
36
|
-
fallback: "fallback";
|
|
37
|
-
}>>;
|
|
38
|
-
stretch: z.ZodOptional<z.ZodString>;
|
|
39
|
-
featureSettings: z.ZodOptional<z.ZodString>;
|
|
40
|
-
variationSettings: z.ZodOptional<z.ZodString>;
|
|
41
|
-
unicodeRange: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodString>>;
|
|
42
|
-
}, z.core.$strict>], z.ZodObject<{
|
|
43
|
-
src: z.ZodTuple<[z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>, z.ZodObject<{
|
|
44
|
-
url: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
45
|
-
tech: z.ZodOptional<z.ZodString>;
|
|
46
|
-
}, z.core.$strict>]>], z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>, z.ZodObject<{
|
|
47
|
-
url: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
48
|
-
tech: z.ZodOptional<z.ZodString>;
|
|
49
|
-
}, z.core.$strict>]>>;
|
|
50
|
-
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
51
|
-
style: z.ZodOptional<z.ZodEnum<{
|
|
52
|
-
normal: "normal";
|
|
53
|
-
italic: "italic";
|
|
54
|
-
oblique: "oblique";
|
|
55
|
-
}>>;
|
|
56
|
-
display: z.ZodOptional<z.ZodEnum<{
|
|
57
|
-
optional: "optional";
|
|
58
|
-
auto: "auto";
|
|
59
|
-
block: "block";
|
|
60
|
-
swap: "swap";
|
|
61
|
-
fallback: "fallback";
|
|
62
|
-
}>>;
|
|
63
|
-
stretch: z.ZodOptional<z.ZodString>;
|
|
64
|
-
featureSettings: z.ZodOptional<z.ZodString>;
|
|
65
|
-
variationSettings: z.ZodOptional<z.ZodString>;
|
|
66
|
-
unicodeRange: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodString>>;
|
|
67
|
-
}, z.core.$strict>>;
|
|
68
|
-
fallbacks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
69
|
-
optimizedFallbacks: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
export declare const FontProviderSchema: z.ZodCustom<FontProvider<never>, FontProvider<never>>;
|
|
17
|
+
export declare const FontFamilySchema: z.ZodObject<{
|
|
70
18
|
name: z.ZodString;
|
|
71
19
|
cssVariable: z.ZodString;
|
|
72
|
-
|
|
73
|
-
export declare const remoteFontFamilySchema: z.ZodObject<{
|
|
74
|
-
provider: z.ZodObject<{
|
|
75
|
-
entrypoint: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
76
|
-
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
77
|
-
}, z.core.$strict>;
|
|
20
|
+
provider: z.ZodCustom<FontProvider<never>, FontProvider<never>>;
|
|
78
21
|
weights: z.ZodOptional<z.ZodTuple<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>], z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
79
22
|
styles: z.ZodOptional<z.ZodTuple<[z.ZodEnum<{
|
|
80
23
|
normal: "normal";
|
|
@@ -99,6 +42,8 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
|
|
|
99
42
|
ttf: "ttf";
|
|
100
43
|
eot: "eot";
|
|
101
44
|
}>>>;
|
|
45
|
+
fallbacks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
46
|
+
optimizedFallbacks: z.ZodOptional<z.ZodBoolean>;
|
|
102
47
|
display: z.ZodOptional<z.ZodEnum<{
|
|
103
48
|
optional: "optional";
|
|
104
49
|
auto: "auto";
|
|
@@ -110,8 +55,5 @@ export declare const remoteFontFamilySchema: z.ZodObject<{
|
|
|
110
55
|
featureSettings: z.ZodOptional<z.ZodString>;
|
|
111
56
|
variationSettings: z.ZodOptional<z.ZodString>;
|
|
112
57
|
unicodeRange: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodString>>;
|
|
113
|
-
|
|
114
|
-
optimizedFallbacks: z.ZodOptional<z.ZodBoolean>;
|
|
115
|
-
name: z.ZodString;
|
|
116
|
-
cssVariable: z.ZodString;
|
|
58
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
117
59
|
}, z.core.$strict>;
|
|
@@ -1,62 +1,40 @@
|
|
|
1
1
|
import * as z from "zod/v4";
|
|
2
|
-
import { FONT_TYPES
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
weight: weightSchema.optional(),
|
|
9
|
-
style: styleSchema.optional(),
|
|
10
|
-
display: displaySchema.optional(),
|
|
11
|
-
stretch: z.string().optional(),
|
|
12
|
-
featureSettings: z.string().optional(),
|
|
13
|
-
variationSettings: z.string().optional(),
|
|
14
|
-
unicodeRange: z.tuple([z.string()], z.string()).optional()
|
|
15
|
-
});
|
|
16
|
-
const fallbacksSchema = z.object({
|
|
17
|
-
fallbacks: z.array(z.string()).optional(),
|
|
18
|
-
optimizedFallbacks: z.boolean().optional()
|
|
19
|
-
});
|
|
20
|
-
const requiredFamilyAttributesSchema = z.object({
|
|
2
|
+
import { FONT_TYPES } from "./constants.js";
|
|
3
|
+
const WeightSchema = z.union([z.string(), z.number()]);
|
|
4
|
+
const StyleSchema = z.enum(["normal", "italic", "oblique"]);
|
|
5
|
+
const DisplaySchema = z.enum(["auto", "block", "swap", "fallback", "optional"]);
|
|
6
|
+
const FormatSchema = z.enum(FONT_TYPES);
|
|
7
|
+
const _FontProviderSchema = z.strictObject({
|
|
21
8
|
name: z.string(),
|
|
22
|
-
|
|
9
|
+
config: z.record(z.string(), z.any()).optional(),
|
|
10
|
+
init: z.custom((v) => typeof v === "function").optional(),
|
|
11
|
+
resolveFont: z.custom((v) => typeof v === "function"),
|
|
12
|
+
listFonts: z.custom((v) => typeof v === "function").optional()
|
|
23
13
|
});
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}).strict();
|
|
34
|
-
const localFontFamilySchema = z.object({
|
|
35
|
-
...requiredFamilyAttributesSchema.shape,
|
|
36
|
-
...fallbacksSchema.shape,
|
|
37
|
-
provider: z.literal(LOCAL_PROVIDER_NAME),
|
|
38
|
-
variants: z.tuple([variantSchema], variantSchema)
|
|
39
|
-
}).strict();
|
|
40
|
-
const remoteFontFamilySchema = z.object({
|
|
41
|
-
...requiredFamilyAttributesSchema.shape,
|
|
42
|
-
...fallbacksSchema.shape,
|
|
43
|
-
...familyPropertiesSchema.omit({
|
|
44
|
-
weight: true,
|
|
45
|
-
style: true
|
|
46
|
-
}).shape,
|
|
47
|
-
provider: z.object({
|
|
48
|
-
entrypoint: entrypointSchema,
|
|
49
|
-
config: z.record(z.string(), z.any()).optional()
|
|
50
|
-
}).strict(),
|
|
51
|
-
weights: z.tuple([weightSchema], weightSchema).optional(),
|
|
52
|
-
styles: z.tuple([styleSchema], styleSchema).optional(),
|
|
14
|
+
const FontProviderSchema = z.custom((v) => {
|
|
15
|
+
return _FontProviderSchema.safeParse(v).success;
|
|
16
|
+
}, "Invalid FontProvider object");
|
|
17
|
+
const FontFamilySchema = z.object({
|
|
18
|
+
name: z.string(),
|
|
19
|
+
cssVariable: z.string(),
|
|
20
|
+
provider: FontProviderSchema,
|
|
21
|
+
weights: z.tuple([WeightSchema], WeightSchema).optional(),
|
|
22
|
+
styles: z.tuple([StyleSchema], StyleSchema).optional(),
|
|
53
23
|
subsets: z.tuple([z.string()], z.string()).optional(),
|
|
54
|
-
formats: z.tuple([
|
|
24
|
+
formats: z.tuple([FormatSchema], FormatSchema).optional(),
|
|
25
|
+
fallbacks: z.array(z.string()).optional(),
|
|
26
|
+
optimizedFallbacks: z.boolean().optional(),
|
|
27
|
+
display: DisplaySchema.optional(),
|
|
28
|
+
stretch: z.string().optional(),
|
|
29
|
+
featureSettings: z.string().optional(),
|
|
30
|
+
variationSettings: z.string().optional(),
|
|
31
|
+
unicodeRange: z.tuple([z.string()], z.string()).optional(),
|
|
32
|
+
options: z.record(z.string(), z.any()).optional()
|
|
55
33
|
}).strict();
|
|
56
34
|
export {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
35
|
+
DisplaySchema,
|
|
36
|
+
FontFamilySchema,
|
|
37
|
+
FontProviderSchema,
|
|
38
|
+
StyleSchema,
|
|
39
|
+
WeightSchema
|
|
62
40
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Defaults, FontType } from './types.js';
|
|
2
|
-
export declare const LOCAL_PROVIDER_NAME = "local";
|
|
3
2
|
export declare const DEFAULTS: Defaults;
|
|
4
|
-
/** Used to serialize data, to be used by public APIs */
|
|
5
3
|
export declare const VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/internal";
|
|
6
4
|
export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
5
|
+
export declare const RUNTIME_VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/runtime";
|
|
6
|
+
export declare const RESOLVED_RUNTIME_VIRTUAL_MODULE_ID: string;
|
|
7
7
|
export declare const ASSETS_DIR = "fonts";
|
|
8
8
|
export declare const CACHE_DIR = "./fonts/";
|
|
9
9
|
export declare const FONT_TYPES: readonly ["woff2", "woff", "otf", "ttf", "eot"];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const LOCAL_PROVIDER_NAME = "local";
|
|
2
1
|
const DEFAULTS = {
|
|
3
2
|
weights: ["400"],
|
|
4
3
|
styles: ["normal", "italic"],
|
|
@@ -10,6 +9,8 @@ const DEFAULTS = {
|
|
|
10
9
|
};
|
|
11
10
|
const VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/internal";
|
|
12
11
|
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
12
|
+
const RUNTIME_VIRTUAL_MODULE_ID = "virtual:astro:assets/fonts/runtime";
|
|
13
|
+
const RESOLVED_RUNTIME_VIRTUAL_MODULE_ID = "\0" + RUNTIME_VIRTUAL_MODULE_ID;
|
|
13
14
|
const ASSETS_DIR = "fonts";
|
|
14
15
|
const CACHE_DIR = "./fonts/";
|
|
15
16
|
const FONT_TYPES = ["woff2", "woff", "otf", "ttf", "eot"];
|
|
@@ -44,7 +45,8 @@ export {
|
|
|
44
45
|
FONT_FORMATS,
|
|
45
46
|
FONT_TYPES,
|
|
46
47
|
GENERIC_FALLBACK_NAMES,
|
|
47
|
-
|
|
48
|
+
RESOLVED_RUNTIME_VIRTUAL_MODULE_ID,
|
|
48
49
|
RESOLVED_VIRTUAL_MODULE_ID,
|
|
50
|
+
RUNTIME_VIRTUAL_MODULE_ID,
|
|
49
51
|
VIRTUAL_MODULE_ID
|
|
50
52
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CssRenderer } from '../definitions.js';
|
|
2
|
+
import type { Collaborator, ComponentDataByCssVariable, Defaults, FontFamilyAssets } from '../types.js';
|
|
3
|
+
import type { optimizeFallbacks as _optimizeFallbacks } from './optimize-fallbacks.js';
|
|
4
|
+
export declare function collectComponentData({ fontFamilyAssets, cssRenderer, defaults, optimizeFallbacks, }: {
|
|
5
|
+
fontFamilyAssets: Array<FontFamilyAssets>;
|
|
6
|
+
cssRenderer: CssRenderer;
|
|
7
|
+
defaults: Pick<Defaults, 'fallbacks' | 'optimizedFallbacks'>;
|
|
8
|
+
optimizeFallbacks: Collaborator<typeof _optimizeFallbacks, 'family' | 'fallbacks' | 'collectedFonts'>;
|
|
9
|
+
}): Promise<ComponentDataByCssVariable>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { unifontFontFaceDataToProperties } from "../utils.js";
|
|
2
|
+
async function collectComponentData({
|
|
3
|
+
fontFamilyAssets,
|
|
4
|
+
cssRenderer,
|
|
5
|
+
defaults,
|
|
6
|
+
optimizeFallbacks
|
|
7
|
+
}) {
|
|
8
|
+
const componentDataByCssVariable = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const { family, fonts, collectedFontsForMetricsByUniqueKey, preloads } of fontFamilyAssets) {
|
|
10
|
+
let css = "";
|
|
11
|
+
for (const data of fonts) {
|
|
12
|
+
css += cssRenderer.generateFontFace(
|
|
13
|
+
family.uniqueName,
|
|
14
|
+
unifontFontFaceDataToProperties({
|
|
15
|
+
src: data.src,
|
|
16
|
+
weight: data.weight,
|
|
17
|
+
style: data.style,
|
|
18
|
+
// User settings override the generated font settings
|
|
19
|
+
display: data.display ?? family.display,
|
|
20
|
+
unicodeRange: data.unicodeRange ?? family.unicodeRange,
|
|
21
|
+
stretch: data.stretch ?? family.stretch,
|
|
22
|
+
featureSettings: data.featureSettings ?? family.featureSettings,
|
|
23
|
+
variationSettings: data.variationSettings ?? family.variationSettings
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const fallbacks = family.fallbacks ?? defaults.fallbacks;
|
|
28
|
+
const cssVarValues = [family.uniqueName];
|
|
29
|
+
const optimizeFallbacksResult = family.optimizedFallbacks ?? defaults.optimizedFallbacks ? await optimizeFallbacks({
|
|
30
|
+
family,
|
|
31
|
+
fallbacks,
|
|
32
|
+
collectedFonts: Array.from(collectedFontsForMetricsByUniqueKey.values())
|
|
33
|
+
}) : null;
|
|
34
|
+
if (optimizeFallbacksResult) {
|
|
35
|
+
css += optimizeFallbacksResult.css;
|
|
36
|
+
cssVarValues.push(...optimizeFallbacksResult.fallbacks);
|
|
37
|
+
} else {
|
|
38
|
+
cssVarValues.push(...fallbacks);
|
|
39
|
+
}
|
|
40
|
+
css += cssRenderer.generateCssVariable(family.cssVariable, cssVarValues);
|
|
41
|
+
componentDataByCssVariable.set(family.cssVariable, { preloads, css });
|
|
42
|
+
}
|
|
43
|
+
return componentDataByCssVariable;
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
collectComponentData
|
|
47
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as unifont from 'unifont';
|
|
2
|
+
import type { FontFileIdGenerator, Hasher } from '../definitions.js';
|
|
3
|
+
import type { Defaults, FontFileById, PreloadData, ResolvedFontFamily } from '../types.js';
|
|
4
|
+
import type { CollectedFontForMetrics } from './optimize-fallbacks.js';
|
|
5
|
+
export declare function collectFontAssetsFromFaces({ fonts, fontFileIdGenerator, family, fontFilesIds, collectedFontsIds, hasher, defaults, }: {
|
|
6
|
+
fonts: Array<unifont.FontFaceData>;
|
|
7
|
+
fontFileIdGenerator: FontFileIdGenerator;
|
|
8
|
+
family: Pick<ResolvedFontFamily, 'cssVariable' | 'fallbacks'>;
|
|
9
|
+
fontFilesIds: Set<string>;
|
|
10
|
+
collectedFontsIds: Set<string>;
|
|
11
|
+
hasher: Hasher;
|
|
12
|
+
defaults: Pick<Defaults, 'fallbacks'>;
|
|
13
|
+
}): {
|
|
14
|
+
fontFileById: FontFileById;
|
|
15
|
+
preloads: PreloadData[];
|
|
16
|
+
collectedFontsForMetricsByUniqueKey: Map<string, CollectedFontForMetrics>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FONT_FORMATS } from "../constants.js";
|
|
2
|
+
import { renderFontWeight } from "../utils.js";
|
|
3
|
+
function collectFontAssetsFromFaces({
|
|
4
|
+
fonts,
|
|
5
|
+
fontFileIdGenerator,
|
|
6
|
+
family,
|
|
7
|
+
fontFilesIds,
|
|
8
|
+
collectedFontsIds,
|
|
9
|
+
hasher,
|
|
10
|
+
defaults
|
|
11
|
+
}) {
|
|
12
|
+
const fontFileById = /* @__PURE__ */ new Map();
|
|
13
|
+
const collectedFontsForMetricsByUniqueKey = /* @__PURE__ */ new Map();
|
|
14
|
+
const preloads = [];
|
|
15
|
+
for (const font of fonts) {
|
|
16
|
+
let index = 0;
|
|
17
|
+
for (const source of font.src) {
|
|
18
|
+
if ("name" in source) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const format = FONT_FORMATS.find((e) => e.format === source.format);
|
|
22
|
+
const originalUrl = source.originalURL;
|
|
23
|
+
const id = fontFileIdGenerator.generate({
|
|
24
|
+
cssVariable: family.cssVariable,
|
|
25
|
+
font,
|
|
26
|
+
originalUrl,
|
|
27
|
+
type: format.type
|
|
28
|
+
});
|
|
29
|
+
if (!fontFilesIds.has(id) && !fontFileById.has(id)) {
|
|
30
|
+
fontFileById.set(id, { url: originalUrl, init: font.meta?.init });
|
|
31
|
+
if (index === 0) {
|
|
32
|
+
preloads.push({
|
|
33
|
+
style: font.style,
|
|
34
|
+
subset: font.meta?.subset,
|
|
35
|
+
type: format.type,
|
|
36
|
+
url: source.url,
|
|
37
|
+
weight: renderFontWeight(font.weight)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const collected = {
|
|
42
|
+
id,
|
|
43
|
+
url: originalUrl,
|
|
44
|
+
init: font.meta?.init,
|
|
45
|
+
data: {
|
|
46
|
+
weight: font.weight,
|
|
47
|
+
style: font.style,
|
|
48
|
+
meta: {
|
|
49
|
+
subset: font.meta?.subset
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const collectedKey = hasher.hashObject(collected.data);
|
|
54
|
+
const fallbacks = family.fallbacks ?? defaults.fallbacks;
|
|
55
|
+
if (fallbacks.length > 0 && // If the same data has already been sent for this family, we don't want to have
|
|
56
|
+
// duplicated fallbacks. Such scenario can occur with unicode ranges.
|
|
57
|
+
!collectedFontsIds.has(collectedKey) && !collectedFontsForMetricsByUniqueKey.has(collectedKey)) {
|
|
58
|
+
collectedFontsForMetricsByUniqueKey.set(collectedKey, collected);
|
|
59
|
+
}
|
|
60
|
+
index++;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
fontFileById,
|
|
65
|
+
preloads,
|
|
66
|
+
collectedFontsForMetricsByUniqueKey
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
collectFontAssetsFromFaces
|
|
71
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { renderFontWeight } from "../utils.js";
|
|
2
|
+
function collectFontData(fontFamilyAssets) {
|
|
3
|
+
const fontDataByCssVariable = {};
|
|
4
|
+
for (const { family, fonts } of fontFamilyAssets) {
|
|
5
|
+
const fontData = [];
|
|
6
|
+
for (const data of fonts) {
|
|
7
|
+
fontData.push({
|
|
8
|
+
weight: renderFontWeight(data.weight),
|
|
9
|
+
style: data.style,
|
|
10
|
+
src: data.src.filter((src) => "url" in src).map((src) => ({
|
|
11
|
+
url: src.url,
|
|
12
|
+
format: src.format,
|
|
13
|
+
tech: src.tech
|
|
14
|
+
}))
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
fontDataByCssVariable[family.cssVariable] = fontData;
|
|
18
|
+
}
|
|
19
|
+
return fontDataByCssVariable;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
collectFontData
|
|
23
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Logger } from '../../../core/logger/core.js';
|
|
2
|
+
import type { FontResolver, StringMatcher } from '../definitions.js';
|
|
3
|
+
import type { Collaborator, Defaults, FontFileById, ResolvedFontFamily } from '../types.js';
|
|
4
|
+
import type { collectFontAssetsFromFaces as _collectFontAssetsFromFaces } from './collect-font-assets-from-faces.js';
|
|
5
|
+
import type { filterAndTransformFontFaces as _filterAndTransformFontFaces } from './filter-and-transform-font-faces.js';
|
|
6
|
+
import type { getOrCreateFontFamilyAssets as _getOrCreateFontFamilyAssets } from './get-or-create-font-family-assets.js';
|
|
7
|
+
export declare function computeFontFamiliesAssets({ resolvedFamilies, fontResolver, logger, bold, defaults, stringMatcher, getOrCreateFontFamilyAssets, collectFontAssetsFromFaces, filterAndTransformFontFaces, }: {
|
|
8
|
+
resolvedFamilies: Array<ResolvedFontFamily>;
|
|
9
|
+
fontResolver: FontResolver;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
bold: (input: string) => string;
|
|
12
|
+
defaults: Defaults;
|
|
13
|
+
stringMatcher: StringMatcher;
|
|
14
|
+
getOrCreateFontFamilyAssets: Collaborator<typeof _getOrCreateFontFamilyAssets, 'family' | 'fontFamilyAssetsByUniqueKey'>;
|
|
15
|
+
filterAndTransformFontFaces: Collaborator<typeof _filterAndTransformFontFaces, 'family' | 'fonts'>;
|
|
16
|
+
collectFontAssetsFromFaces: Collaborator<typeof _collectFontAssetsFromFaces, 'family' | 'fonts' | 'collectedFontsIds' | 'fontFilesIds'>;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
fontFamilyAssets: import("../types.js").FontFamilyAssets[];
|
|
19
|
+
fontFileById: FontFileById;
|
|
20
|
+
}>;
|