Support local custom fonts#3
Open
i-am-the-slime wants to merge 2 commits into
Open
Conversation
Add an "Upload local font" affordance to the font picker so users can bring their own .woff2 / .woff / .ttf / .otf monospace fonts. Uploaded fonts are persisted in localStorage as base64, registered with document.fonts for the DOM preview, and surfaced through loadCodeFont so Satori uses them on the PNG/SVG export path too.
|
@i-am-the-slime is attempting to deploy a commit to the betalyra Team on Vercel. A member of the Team first needs to authorize it. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
.woff2/.woff/.ttf/.otffiles (e.g. the TX-02 from Berkeley Graphics) when none of the bundled fonts fit.localStorage(base64-encoded bytes) and appear in a new Custom group at the top of the picker with a per-row delete button.document.fontsfor the live DOM preview, and surfaced vialoadCodeFontso Satori uses the same bytes when exporting PNG/SVG.Implementation notes
src/lib/customFonts.tsholds the small store (one localStorage key, simple subscribe/notify), file-reader helpers, and a CSS-family helper.src/lib/fonts.tsnow treats the font name as a string and falls back to the custom store when the name isn't in the built-inREGISTRY. Its load-promise cache is invalidated whenever the custom-font store changes so re-uploads pick up the new bytes.Settings.codeFontis widened from theCodeFontliteral union tostring. The union is still used as the key type of the built-in registry, so built-in fonts remain exhaustive.FontComboboxgrows a file<input>, a custom-fonts group, and a remove button.Test plan
bunx tsc --noEmitcleanbun run buildsucceedsSettings.codeFont..woff2(e.g. TX-02) and confirm both the live preview and the exported PNG render it.