Skip to content

AI-native design editor. Open-source Figma alternative.

feat(core): load web fonts as their variable files (#1454)

Danila Poyarkov0c1ecd9b8955
diff --git a/bun.lock b/bun.lock
index b8e8b6599..637246865 100644
--- a/bun.lock
+++ b/bun.lock
@@ -293,7 +293,7 @@
"svg2pdf.js": "^2.8.1",
"svgpath": "^2.6.0",
"twirlwind": "^0.4.1",
- "unifont": "0.7.4",
+ "unifont": "1.0.3",
"valibot": "^1.5.0",
"woff2-encoder": "2.0.0",
"yoga-layout": "npm:@open-pencil/[email protected]",
@@ -3343,6 +3343,8 @@
"floating-vue": ["[email protected]", "", { "dependencies": { "@floating-ui/dom": "~1.1.1", "vue-resize": "^2.0.0-alpha.1" }, "peerDependencies": { "@nuxt/kit": "^3.2.0", "vue": "^3.2.0" }, "optionalPeers": ["@nuxt/kit"] }, "sha512-afW+h2CFafo+7Y9Lvw/xsqjaQlKLdJV7h1fCHfcYQ1C4SVMlu7OAekqWgu5d4SgvkBVU0pVpLlVsrSTBURFRkg=="],
+ "fnv1a-64": ["[email protected]", "", {}, "sha512-mJbcILTPybAR1jdOwt/lVv8N2cffeJFFP+gVbSAwLEx1ujXH27RpPd8Rokec/KX9c76UYIB6Co+H4lQzxPnJfA=="],
+
"focus-trap": ["[email protected]", "", { "dependencies": { "tabbable": "^6.5.0" } }, "sha512-qV0g8hRYBqgACcFOH3f9wXc4zPKhr/0z9RI2a6ZijZ72EeBi4g8oBy8zAWuUR1TsMpOzwpUMFvjdasrC41Joug=="],
"font-family-papandreou": ["[email protected]", "", {}, "sha512-l/YiRdBSH/eWv6OF3sLGkwErL+n0MqCICi9mppTZBOCL5vixWGDqCYvRcuxB2h7RGCTzaTKOHT2caHvCXQPRlw=="],
@@ -4587,6 +4589,8 @@
"statuses": ["[email protected]", "", {}, "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw=="],
+ "std-env": ["[email protected]", "", {}, "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag=="],
+
"steiger": ["[email protected]", "", { "dependencies": { "@clack/prompts": "^0.9.1", "@feature-sliced/steiger-plugin": "0.6.0", "chokidar": "^4.0.3", "cosmiconfig": "^9.0.0", "effector": "^23.4.2", "empathic": "^1.1.0", "fastest-levenshtein": "^1.0.16", "globby": "^14.1.0", "immer": "^10.1.1", "lodash-es": "^4.17.21", "micromatch": "^4.0.8", "patronum": "^2.3.0", "picocolors": "^1.1.1", "prexit": "^2.3.0", "yargs": "^17.7.2", "zod": "^3.25.76", "zod-validation-error": "^3.5.3" }, "bin": { "steiger": "dist/cli.mjs" } }, "sha512-Vbgb9tMmxo3wf1jXvn+px3hDEOELdYJdWji6DT++zFcWwVHgjY22DjxYbCjq+dtEE6BWYSyv6OhwbPZPy8ovQQ=="],
"stop-iteration-iterator": ["[email protected]", "", { "dependencies": { "es-errors": "^1.3.0", "internal-slot": "^1.1.0" } }, "sha512-eLoXW/DHyl62zxY4SCaIgnRhuMr6ri4juEYARS8E6sCEqzKpOiE521Ucofdx+KnDZl5xmvGYaaKCk5FEOxJCoQ=="],
@@ -4797,7 +4801,7 @@
"unconfig-core": ["[email protected]", "", { "dependencies": { "@quansync/fs": "^1.0.0", "quansync": "^1.0.0" } }, "sha512-Su3FauozOGP44ZmKdHy2oE6LPjk51M/TRRjHv2HNCWiDvfvCoxC2lno6jevMA91MYAdCdwP05QnWdWpSbncX/w=="],
- "undici": ["[email protected]", "", {}, "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q=="],
+ "undici": ["[email protected]", "", {}, "sha512-aWZpUj7XoGonMClx4gdDRfgBjqeA+F473aDmROQQbM9n6PRfK/u1q/a0X4wMTgcHfT8H6fpbt98PFuDUwFg2YA=="],
"undici-types": ["[email protected]", "", {}, "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg=="],
@@ -4823,7 +4827,7 @@
"unified": ["[email protected]", "", { "dependencies": { "@types/unist": "^3.0.0", "bail": "^2.0.0", "devlop": "^1.0.0", "extend": "^3.0.0", "is-plain-obj": "^4.0.0", "trough": "^2.0.0", "vfile": "^6.0.0" } }, "sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA=="],
- "unifont": ["[email protected]", "", { "dependencies": { "css-tree": "^3.1.0", "ofetch": "^1.5.1", "ohash": "^2.0.11" } }, "sha512-oHeis4/xl42HUIeHuNZRGEvxj5AaIKR+bHPNegRq5LV1gdc3jundpONbjglKpihmJf+dswygdMJn3eftGIMemg=="],
+ "unifont": ["[email protected]", "", { "dependencies": { "css-tree": "^3.1.0", "fnv1a-64": "^0.1.2", "std-env": "^4.2.0", "undici": "^8.0.0" } }, "sha512-XGnEwj5sWdCbiBX01mWLSBncS0yMRjnLygau3IfdOlfjMacNIQvTGW4VH7pWBq+gGWArfSef/CensMLjMmIr/A=="],
"unique-string": ["[email protected]", "", { "dependencies": { "crypto-random-string": "^2.0.0" } }, "sha512-uNaeirEPvpZWSgzwsPGtU2zVSTrn/8L5q/IexZmH0eH6SA73CmAA5U4GwORTxQAZs95TAXLNqeLoPPNO5gZfWg=="],
@@ -5079,6 +5083,8 @@
"zwitch": ["[email protected]", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="],
+ "@ai-sdk/provider-utils/undici": ["[email protected]", "", {}, "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q=="],
+
"@apideck/better-ajv-errors/ajv": ["[email protected]", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA=="],
"@arethetypeswrong/core/typescript": ["[email protected]", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-E3b2+1zEFu84jB0YQi9BORDjz9+jGbwwy1Zi3G0LUNw7a7cePUrHMRNy8aPh53nXpkFGVHSxIZo5vKTfYaFiBQ=="],
@@ -5167,8 +5173,6 @@
"@earendil-works/pi-coding-agent/typebox": ["[email protected]", "", {}, "sha512-meKuifc33Pccx0O6PdIzYMq3Og8zvP4TIi/a+Bw3AEMZMxOD0+RHGQvpglEe6Zdy3wZ8nqn/j95h8LUZLk/6Hg=="],
- "@earendil-works/pi-coding-agent/undici": ["[email protected]", "", {}, "sha512-aWZpUj7XoGonMClx4gdDRfgBjqeA+F473aDmROQQbM9n6PRfK/u1q/a0X4wMTgcHfT8H6fpbt98PFuDUwFg2YA=="],
-
"@earendil-works/pi-tui/marked": ["[email protected]", "", { "bin": { "marked": "bin/marked.js" } }, "sha512-S6GcvALHg6K4ohtu4E7x0a1AqhAjp6cV8KhLSyN9qVapnzJkusVBxZRcIU9AeYsbe6P1hKDusSbEOzGyyuce6w=="],
"@feature-sliced/filesystem/typescript": ["[email protected]", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
@@ -5349,6 +5353,8 @@
"cheerio/parse5-htmlparser2-tree-adapter": ["[email protected]", "", { "dependencies": { "domhandler": "^5.0.3", "parse5": "^7.0.0" } }, "sha512-ruw5xyKs6lrpo9x9rCZqZZnIUntICjQAd0Wsmp396Ul9lN/h+ifgVV1x1gZHi8euej6wTfpqX8j+BFQxF0NS/g=="],
+ "cheerio/undici": ["[email protected]", "", {}, "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q=="],
+
"cli-highlight/parse5": ["[email protected]", "", {}, "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug=="],
"cli-highlight/yargs": ["[email protected]", "", { "dependencies": { "cliui": "^7.0.2", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.0", "y18n": "^5.0.5", "yargs-parser": "^20.2.2" } }, "sha512-Nt9ZJjXTv5R8MHbqby/wXQ6Gi0Bb3TcYZkR1bzuL4yB2OxWPkXknz513gEF0GoA6tn00UpbPvERW8rzCuWCA6w=="],
@@ -5471,6 +5477,8 @@
"miniflare/sharp": ["[email protected]", "", { "dependencies": { "@img/colour": "^1.1.0", "detect-libc": "^2.1.2", "semver": "^7.8.5" }, "optionalDependencies": { "@img/sharp-darwin-arm64": "0.35.5", "@img/sharp-darwin-x64": "0.35.5", "@img/sharp-freebsd-wasm32": "0.35.5", "@img/sharp-libvips-darwin-arm64": "1.3.4", "@img/sharp-libvips-darwin-x64": "1.3.4", "@img/sharp-libvips-linux-arm": "1.3.4", "@img/sharp-libvips-linux-arm64": "1.3.4", "@img/sharp-libvips-linux-ppc64": "1.3.4", "@img/sharp-libvips-linux-riscv64": "1.3.4", "@img/sharp-libvips-linux-s390x": "1.3.4", "@img/sharp-libvips-linux-x64": "1.3.4", "@img/sharp-libvips-linuxmusl-arm64": "1.3.4", "@img/sharp-libvips-linuxmusl-x64": "1.3.4", "@img/sharp-linux-arm": "0.35.5", "@img/sharp-linux-arm64": "0.35.5", "@img/sharp-linux-ppc64": "0.35.5", "@img/sharp-linux-riscv64": "0.35.5", "@img/sharp-linux-s390x": "0.35.5", "@img/sharp-linux-x64": "0.35.5", "@img/sharp-linuxmusl-arm64": "0.35.5", "@img/sharp-linuxmusl-x64": "0.35.5", "@img/sharp-webcontainers-wasm32": "0.35.5", "@img/sharp-win32-arm64": "0.35.5", "@img/sharp-win32-ia32": "0.35.5", "@img/sharp-win32-x64": "0.35.5" }, "peerDependencies": { "@types/node": "*" }, "optionalPeers": ["@types/node"] }, "sha512-Ywn4OnzGukp7CDMrp08RQ50YKmuwG47brZgIVPTvBaaAfQlRlygrRqSrxdCiL9M+LlzLBiJ68IR1QqvzHyjC7g=="],
+ "miniflare/undici": ["[email protected]", "", {}, "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q=="],
+
"miniflare/ws": ["[email protected]", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g=="],
"mlly/pkg-types": ["[email protected]", "", { "dependencies": { "confbox": "^0.1.8", "mlly": "^1.7.4", "pathe": "^2.0.1" } }, "sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ=="],
diff --git a/changes/1454/changed.md b/changes/1454/changed.md
new file mode 100644
index 000000000..815422aa7
--- /dev/null
+++ b/changes/1454/changed.md
@@ -0,0 +1 @@
+- Web fonts from Google Fonts and Fontsource load as their variable files, one download per family with every axis, and Material Symbols load from Google's icon catalogue with all four axes.
diff --git a/packages/core/package.json b/packages/core/package.json
index bd64311a5..28e3c3c56 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -211,7 +211,7 @@
"svg2pdf.js": "^2.8.1",
"svgpath": "^2.6.0",
"twirlwind": "^0.4.1",
- "unifont": "0.7.4",
+ "unifont": "1.0.3",
"valibot": "^1.5.0",
"woff2-encoder": "2.0.0",
"yoga-layout": "npm:@open-pencil/[email protected]"
diff --git a/packages/core/src/text/web-font/providers.ts b/packages/core/src/text/web-font/providers.ts
index bcef15c56..c7fb3088d 100644
--- a/packages/core/src/text/web-font/providers.ts
+++ b/packages/core/src/text/web-font/providers.ts
@@ -11,24 +11,33 @@ import type { WebFontProviderId } from '#core/text/web-fonts'
export type WebFontProvider =
| ReturnType<typeof providers.google>
+ | ReturnType<typeof providers.googleicons>
| ReturnType<typeof providers.fontsource>
| ReturnType<typeof providers.bunny>
| ReturnType<typeof providers.fontshare>
-export type WebUnifont = Unifont<[WebFontProvider]>
+/** One or more providers behind a provider setting. */
+export type WebFontProviders = [WebFontProvider, ...WebFontProvider[]]
+export type WebUnifont = Unifont<WebFontProviders>
export type WebFontResolveOptions = Pick<
ResolveFontOptions<{ google?: GoogleFamilyOptions }>,
- 'weights' | 'styles' | 'formats' | 'subsets' | 'options'
+ 'weights' | 'styles' | 'formats' | 'subsets' | 'variableAxis' | 'options'
>
+/**
+ * The unifont providers behind each provider setting. Google serves its Material Symbols from
+ * its icon catalogue, as variable fonts with every axis, so its setting covers both.
+ */
export const providerFactories = {
- google: providers.google,
- fontsource: providers.fontsource,
- bunny: providers.bunny,
- fontshare: providers.fontshare
-} satisfies Record<WebFontProviderId, () => WebFontProvider>
+ google: (): WebFontProviders => [providers.google(), providers.googleicons()],
+ fontsource: (): WebFontProviders => [providers.fontsource()],
+ bunny: (): WebFontProviders => [providers.bunny()],
+ fontshare: (): WebFontProviders => [providers.fontshare()]
+} satisfies Record<WebFontProviderId, () => WebFontProviders>
export async function createProviderUnifont(provider: WebFontProviderId): Promise<WebUnifont> {
- return createUnifont([providerFactories[provider]()], { throwOnError: false })
+ // In a page unifont sends provider requests to its hosted proxy; ours go through the host's
+ // fetch, which reaches the providers itself.
+ return createUnifont(providerFactories[provider](), { throwOnError: false, apiBase: false })
}
export function isRemoteFontSource(
diff --git a/packages/core/src/text/web-fonts.ts b/packages/core/src/text/web-fonts.ts
index 7956af713..20be4682f 100644
--- a/packages/core/src/text/web-fonts.ts
+++ b/packages/core/src/text/web-fonts.ts
@@ -80,10 +80,11 @@ export function webFontSubsetsForText(text: string): string[] {
function preferredRemoteSource(face: FontFaceData): RemoteFontSource | undefined {
const sources = face.src.filter(isRemoteFontSource)
+ // WOFF2 is decoded on arrival, and it is the only format Google serves variable fonts in.
return (
+ sources.find((source) => source.format === 'woff2') ??
sources.find((source) => source.format === 'truetype' || source.format === 'ttf') ??
sources.find((source) => source.format === 'opentype' || source.format === 'otf') ??
- sources.find((source) => source.format === 'woff2') ??
sources.find((source) => source.format === 'woff') ??
sources[0]
)
@@ -321,6 +322,36 @@ export class WebFontResolver {
}
}
+ /**
+ * The weights to ask for a style in, and the other axes: a variable family's whole range, so one
+ * file draws every weight and axis it has, or the style's own weight. unifont narrows each range
+ * to what the provider serves.
+ */
+ private async requestedAxes(
+ unifont: WebUnifont,
+ family: string,
+ weight: number,
+ signal?: AbortSignal
+ ): Promise<Pick<WebFontResolveOptions, 'weights' | 'variableAxis'>> {
+ const properties = await this.withFetchProxy(() => unifont.getFontProperties(family), signal)
+ const axes = properties?.axes ?? []
+ const wght = axes.find((axis) => axis.tag === 'wght')
+ const range = wght
+ ? [wght.min, wght.max]
+ : properties?.weights
+ ?.map((value) => value.split(' ').map(Number))
+ .find((bounds) => bounds.length === 2)
+ const [min = weight, max = weight] = range ?? []
+ if (!range || weight < min || weight > max) return { weights: [String(weight)] }
+ const others = axes.filter((axis) => axis.tag !== 'wght' && axis.tag !== 'ital')
+ return {
+ weights: [`${min} ${max}`],
+ variableAxis: Object.fromEntries(
+ others.map((axis) => [axis.tag, [{ min: axis.min, max: axis.max }]])
+ )
+ }
+ }
+
private async fetchRemote(url: string, init?: RequestInit): Promise<Response> {
if (this.remoteFetch) return this.remoteFetch(url, init)
return fetch(url, init)
@@ -393,15 +424,22 @@ export class WebFontResolver {
signal?.throwIfAborted()
const parsed = parseFontStyle(style)
const unifont = await this.unifont(provider, signal)
- const options = {
- weights: [String(parsed.weight)],
+ const { weights, variableAxis } = await this.requestedAxes(
+ unifont,
+ family,
+ parsed.weight,
+ signal
+ )
+ const options: WebFontResolveOptions = {
+ weights,
styles: [parsed.italic ? 'italic' : 'normal'],
- formats: ['ttf', 'otf', 'woff2', 'woff'],
+ formats: ['woff2', 'ttf', 'otf', 'woff'],
subsets: webFontSubsetsForText(characters),
- ...(provider === 'google' && characters
- ? { options: { google: { experimental: { glyphs: [characters] } } } }
- : {})
- } satisfies WebFontResolveOptions
+ variableAxis
+ }
+ if (provider === 'google' && characters) {
+ options.options = { google: { experimental: { glyphs: [characters] } } }
+ }
const result = await this.withFetchProxy<ResolveFontResult>(
() => unifont.resolveFont(family, options),
signal
diff --git a/packages/core/tests/text/web-fonts.test.ts b/packages/core/tests/text/web-fonts.test.ts
index 0e27fae07..d8574a9e1 100644
--- a/packages/core/tests/text/web-fonts.test.ts
+++ b/packages/core/tests/text/web-fonts.test.ts
@@ -1,32 +1,95 @@
-import { expect, test } from 'bun:test'
+import { describe, expect, test } from 'bun:test'
import { join } from 'node:path'
import { FIXTURES } from '#core-tests/helpers/paths'
import { isVariableFont, isWOFF2, WebFontResolver } from '@open-pencil/core/text'
-test('loads a web font served as WOFF2 as the TrueType font it holds', async () => {
+const FONT_URL = 'https://fonts.gstatic.com/s/test/faces.woff2'
+
+interface Family {
+ family: string
+ axes: { tag: string; min: number; max: number }[]
+}
+
+/**
+ * A resolver whose Google Fonts serves `families`, and Material Symbols from its icon catalogue,
+ * every face as the variable WOFF2 fixture. It records each CSS request.
+ */
+async function googleResolver(families: Family[], icons: string[] = []) {
const woff2 = await Bun.file(join(FIXTURES, 'fonts', 'InterVariable-Faces.woff2')).arrayBuffer()
- const family = 'Web Font Test WOFF2'
- const fontURL = 'https://fonts.gstatic.com/s/test/faces.woff2'
+ const requests: URL[] = []
const resolver = new WebFontResolver()
resolver.setEnabled({ google: true })
resolver.setRemoteFetch(async (input) => {
- const url = String(input)
- if (url.startsWith('https://fonts.google.com/metadata/fonts'))
- return Response.json({ familyMetadataList: [{ family, fonts: { '400': {} }, axes: [] }] })
- if (url.startsWith('https://fonts.googleapis.com/css2'))
+ const url = new URL(String(input))
+ if (url.href.startsWith('https://fonts.google.com/metadata/fonts'))
+ return Response.json({
+ familyMetadataList: families.map((family) => ({
+ ...family,
+ fonts: { '400': {}, '700': {} }
+ }))
+ })
+ if (url.href.startsWith('https://fonts.google.com/metadata/icons'))
+ return new Response(`)]}'\n${JSON.stringify({ families: icons })}`)
+ if (url.href.startsWith('https://fonts.googleapis.com/css2')) {
+ requests.push(url)
+ const family = url.searchParams.get('family')?.split(':')[0] ?? ''
return new Response(
- `@font-face { font-family: '${family}'; font-style: normal; font-weight: 400; src: url(${fontURL}) format('woff2'); }`
+ `@font-face { font-family: '${family}'; font-style: normal; font-weight: 400; src: url(${FONT_URL}) format('woff2'); }`
)
- if (url === fontURL) return new Response(woff2)
+ }
+ if (url.href === FONT_URL) return new Response(woff2)
return new Response(null, { status: 404 })
})
+ return { resolver, requests }
+}
- const resolved = await resolver.fetchFont([family], 'Regular', '')
- const font = resolved?.buffers[0]
- expect(font).toBeDefined()
- if (!font) return
- expect(isWOFF2(font)).toBe(false)
- expect(isVariableFont(font)).toBe(true)
+describe('web fonts', () => {
+ test('loads a font served as WOFF2 as the TrueType font it holds', async () => {
+ const family = 'Web Font Test WOFF2'
+ const { resolver } = await googleResolver([{ family, axes: [] }])
+ const font = (await resolver.fetchFont([family], 'Regular', ''))?.buffers[0]
+ expect(font).toBeDefined()
+ if (!font) return
+ expect(isWOFF2(font)).toBe(false)
+ expect(isVariableFont(font)).toBe(true)
+ })
+
+ test('asks Google for a variable family whole, every axis in the range Google lists', async () => {
+ const family = 'Web Font Test Variable'
+ const { resolver, requests } = await googleResolver([
+ {
+ family,
+ axes: [
+ { tag: 'opsz', min: 14, max: 32 },
+ { tag: 'wght', min: 100, max: 900 }
+ ]
+ }
+ ])
+ await resolver.fetchFont([family], 'Bold', '')
+ expect(requests.map((url) => url.searchParams.get('family'))).toContain(
+ // unifont asks for the upright slant on the `ital` axis.
+ `${family}:ital,opsz,wght@0,14..32,100..900`
+ )
+ })
+
+ test('asks Google for the one weight of a static family', async () => {
+ const family = 'Web Font Test Static'
+ const { resolver, requests } = await googleResolver([{ family, axes: [] }])
+ await resolver.fetchFont([family], 'Bold', '')
+ expect(requests.map((url) => url.searchParams.get('family'))).toContain(
+ `${family}:ital,wght@0,700`
+ )
+ })
+
+ test('loads Material Symbols from Google’s icon catalogue with every axis', async () => {
+ const family = 'Material Symbols Rounded'
+ const { resolver, requests } = await googleResolver([], [family])
+ const font = (await resolver.fetchFont([family], 'ExtraLight', ''))?.buffers[0]
+ expect(font && isVariableFont(font)).toBe(true)
+ expect(requests.map((url) => url.searchParams.get('family'))).toContain(
+ `${family}:opsz,wght,FILL,[email protected],100..700,0..1,-50..200`
+ )
+ })
})
diff --git a/vite/aliases.ts b/vite/aliases.ts
index df581cadd..dc9317fdb 100644
--- a/vite/aliases.ts
+++ b/vite/aliases.ts
@@ -28,6 +28,7 @@ export function createOpenPencilAliases(rootDir: string, options: { cloud?: bool
return [
{ find: /^fs$/, replacement: emptyNodeModule },
{ find: /^path$/, replacement: emptyNodeModule },
+ { find: /^node:process$/, replacement: resolve(rootDir, 'vite/node-process.ts') },
...(options.cloud === false ? cloudOffAliases(rootDir) : []),
{ find: '@', replacement: resolve(rootDir, 'src') },
{ find: '#vue', replacement: resolve(rootDir, 'packages/vue/src') },
diff --git a/vite/node-process.ts b/vite/node-process.ts
new file mode 100644
index 000000000..97803db5b
--- /dev/null
+++ b/vite/node-process.ts
@@ -0,0 +1,7 @@
+/**
+ * `node:process` for the browser: unifont reads proxy settings from `env` when it starts, which a
+ * page has none of.
+ */
+export const env: Record<string, string | undefined> = {}
+
+export default { env }