fontaine 0.8.0 → 0.8.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/README.md +32 -4
- package/dist/capsize-font-metrics.mjs +1 -1
- package/dist/fallbacks-Cj4LUWhi.d.cts +34 -0
- package/dist/fallbacks-Cj4LUWhi.d.mts +34 -0
- package/dist/index.cjs +138 -299
- package/dist/index.d.cts +65 -98
- package/dist/index.d.mts +64 -98
- package/dist/index.mjs +120 -277
- package/dist/metrics-ChAPPk2j.cjs +425 -0
- package/dist/metrics-DgPzfV2U.mjs +354 -0
- package/dist/postcss.cjs +91 -0
- package/dist/postcss.d.cts +52 -0
- package/dist/postcss.d.mts +52 -0
- package/dist/postcss.mjs +91 -0
- package/package.json +34 -15
package/README.md
CHANGED
|
@@ -135,6 +135,34 @@ If your custom font is used through the mechanism of CSS variables, you'll need
|
|
|
135
135
|
|
|
136
136
|
Behind the scenes, there is a 'Poppins fallback' `@font-face` rule that has been created by fontaine. By manually adding this fallback font family to our CSS variable, we make our site use the fallback `@font-face` rule with the correct font metrics that fontaine generates.
|
|
137
137
|
|
|
138
|
+
## Using Sass, Less or Stylus
|
|
139
|
+
|
|
140
|
+
The bundler plugin runs before your preprocessor, so it only sees the raw source of files your bundler treats as modules. If your `@font-face` rules live in a Sass partial, are generated by a mixin, or are pulled in with a Sass `@import`, fontaine never sees them: Sass inlines all of that before the bundler does.
|
|
141
|
+
|
|
142
|
+
For these setups, use the PostCSS plugin instead. It runs over fully-compiled CSS, so `@font-face` rules and `font-family` values are already plain CSS by the time fontaine reads them.
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
// postcss.config.js
|
|
146
|
+
module.exports = {
|
|
147
|
+
plugins: [
|
|
148
|
+
require('fontaine/postcss')({
|
|
149
|
+
fallbacks: ['BlinkMacSystemFont', 'Segoe UI', 'Helvetica Neue', 'Arial', 'Noto Sans'],
|
|
150
|
+
}),
|
|
151
|
+
// ...any other plugins, such as autoprefixer or cssnano
|
|
152
|
+
],
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
It accepts the same `fallbacks`, `categoryFallbacks`, `resolvePath`, `skipFontFaceGeneration` and `fallbackName` options as the bundler plugin. Do not use both plugins at once.
|
|
157
|
+
|
|
158
|
+
A couple of things worth checking in a webpack setup:
|
|
159
|
+
|
|
160
|
+
- Enable source maps on `sass-loader`. Sass does not rebase the URLs it inlines, so fontaine uses the source map to work out which stylesheet a `src` URL was written relative to. Without it, relative font paths are resolved against the entrypoint and metrics cannot be read.
|
|
161
|
+
- Set `importLoaders` on `css-loader` (`2` for `postcss-loader` + `sass-loader`) if you import CSS that contains `@font-face` rules, such as Fontsource packages. Otherwise `css-loader` resolves those imports without running them through `postcss-loader`, and fontaine never sees them.
|
|
162
|
+
|
|
163
|
+
> [!NOTE]
|
|
164
|
+
> Because a `font-family` declaration and the `@font-face` rule it refers to may end up in different stylesheets, the PostCSS plugin appends a fallback to every non-generic `font-family` it finds, whether or not it generated the matching `@font-face` rule itself. A fallback family with no `@font-face` rule is ignored by the browser.
|
|
165
|
+
|
|
138
166
|
## Category-Aware Fallbacks
|
|
139
167
|
|
|
140
168
|
Fontaine automatically selects appropriate fallback fonts based on font categories (serif, sans-serif, monospace, etc.) when using object-based fallback configuration.
|
|
@@ -242,10 +270,10 @@ Published under [MIT License](./LICENCE).
|
|
|
242
270
|
|
|
243
271
|
<!-- Badges -->
|
|
244
272
|
|
|
245
|
-
[npm-version-src]: https://
|
|
246
|
-
[npm-version-href]: https://
|
|
247
|
-
[npm-downloads-src]: https://
|
|
248
|
-
[npm-downloads-href]: https://
|
|
273
|
+
[npm-version-src]: https://npmx.dev/api/registry/badge/version/fontaine
|
|
274
|
+
[npm-version-href]: https://npmx.dev/package/fontaine
|
|
275
|
+
[npm-downloads-src]: https://npmx.dev/api/registry/badge/downloads/fontaine
|
|
276
|
+
[npm-downloads-href]: https://npmx.dev/package/fontaine
|
|
249
277
|
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/fontaine/ci.yml?branch=main&style=flat-square
|
|
250
278
|
[github-actions-href]: https://github.com/unjs/fontaine/actions/workflows/ci.yml
|
|
251
279
|
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/fontaine/main?style=flat-square
|