-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(fonts)!: update font provider API #15130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d14bb27
feat(fonts)!: update font provider API
florian-lefebvre 76b7d5b
type test
florian-lefebvre a1bc0e3
fix: unit tests
florian-lefebvre 8fbc5c0
feat: update test util
florian-lefebvre 7a0a7b6
fix: tests
florian-lefebvre 2e4ab02
fix: build
florian-lefebvre ae8c3de
chore: clean unifont mentions
florian-lefebvre ddd6b6e
Merge branch 'main' into feat/fonts-updated-provider-api-2
florian-lefebvre 689cc48
test astroToUnifontProvider
florian-lefebvre 2fa7844
chore: jsdoc
florian-lefebvre ac60869
fix: test
florian-lefebvre 19dcf96
chore: changeset
florian-lefebvre aa8be0a
make resolveFamily sync
florian-lefebvre a4a9cff
update changeset example
florian-lefebvre f44e40d
Merge branch 'main' into feat/fonts-updated-provider-api-2
florian-lefebvre 49698a4
Update .changeset/forty-zebras-enter.md
florian-lefebvre 5274d4e
Update .changeset/forty-zebras-enter.md
florian-lefebvre f167b31
Update .changeset/forty-zebras-enter.md
florian-lefebvre fa9d436
Update .changeset/forty-zebras-enter.md
florian-lefebvre 3df6dd4
Merge branch 'main' into feat/fonts-updated-provider-api-2
florian-lefebvre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --- | ||
| 'astro': patch | ||
| --- | ||
|
|
||
| **BREAKING CHANGE to the experimental Fonts API only** | ||
|
|
||
| Changes how font providers are implemented with updates to the `FontProvider` type | ||
|
|
||
| This is an implementation detail that changes how font providers are created. This process allows Astro to take more control rather than relying directly on `unifont` types. **All of Astro's built-in font providers have been updated to reflect this new type, and can be configured as before**. However, using third-party unifont providers that rely on `unifont` types will require an update to your project code. | ||
|
|
||
| Previously, an Astro `FontProvider` was made of a config and a runtime part. It relied directly on `unifont` types, which allowed a simple configuration for third-party unifont providers, but also coupled Astro's implementation to unifont, which was limiting. | ||
|
|
||
| Astro's font provider implementation is now only made of a config part with dedicated hooks. This allows for the separation of config and runtime, but requires you to create a font provider object in order to use custom font providers (e.g. third-party unifont providers, or private font registeries). | ||
|
|
||
| #### What should I do? | ||
|
|
||
| If you were using a 3rd-party `unifont` font provider, you will now need to write an Astro `FontProvider` using it under the hood. For example: | ||
|
|
||
| ```diff | ||
| // astro.config.ts | ||
| import { defineConfig } from "astro/config"; | ||
| import { acmeProvider, type AcmeOptions } from '@acme/unifont-provider' | ||
| +import type { FontProvider } from "astro"; | ||
| +import type { InitializedProvider } from 'unifont'; | ||
|
|
||
| +function acme(config?: AcmeOptions): FontProvider { | ||
| + const provider = acmeProvider(config); | ||
| + let initializedProvider: InitializedProvider | undefined; | ||
| + return { | ||
| + name: provider._name, | ||
| + config, | ||
| + async init(context) { | ||
| + initializedProvider = await provider(context); | ||
| + }, | ||
| + async resolveFont({ familyName, ...rest }) { | ||
| + return await initializedProvider?.resolveFont(familyName, rest); | ||
| + }, | ||
| + async listFonts() { | ||
| + return await initializedProvider?.listFonts?.(); | ||
| + }, | ||
| + }; | ||
| +} | ||
|
|
||
| export default defineConfig({ | ||
| experimental: { | ||
| fonts: [{ | ||
| - provider: acmeProvider({ /* ... */ }), | ||
| + provider: acme({ /* ... */ }), | ||
| name: "Material Symbols Outlined", | ||
| cssVariable: "--font-material" | ||
| }] | ||
| } | ||
| }); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
packages/astro/src/assets/fonts/infra/build-remote-font-provider-mod-resolver.ts
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
packages/astro/src/assets/fonts/infra/dev-remote-font-provider-mod-resolver.ts
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
packages/astro/src/assets/fonts/infra/remote-font-provider-resolver.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.