Skip to content
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

Add createFontStack for metrics-based font fallbacks #117

Merged
merged 12 commits into from Jan 30, 2023

Conversation

michaeltaranto
Copy link
Contributor

Creates metrics-based @font-face declarations to improve the alignment of font family fallbacks, which can dramatically improve the Cumulative Layout Shift metric for sites that depend on a web font.

Example usage

import { createFontStack } from '@capsizecss/core';
import lobster from '@capsizecss/metrics/lobster';
import helveticaNeue from '@capsizecss/metrics/helveticaNeue';
import arial from '@capsizecss/metrics/arial';

const { fontFamily, fontFaces } = createFontStack([
  lobster,
  helveticaNeue,
  arial,
]);

The returned values are the computed font family and the generated font face declarations:

// `fontFamily`
"Lobster, 'Lobster Fallback: Helvetica Neue', 'Lobster Fallback: Arial'"
/* `fontFaces` */
@font-face {
  font-family: 'Lobster Fallback: Helvetica Neue';
  src: local('Helvetica Neue');
  ascent-override: 115.1741%;
  descent-override: 28.7935%;
  size-adjust: 86.8251%;
}
@font-face {
  font-family: 'Lobster Fallback: Arial';
  src: local('Arial');
  ascent-override: 113.5679%;
  descent-override: 28.392%;
  size-adjust: 88.053%;
}

@michaeltaranto michaeltaranto requested a review from a team as a code owner November 22, 2022 10:47
@changeset-bot
Copy link

changeset-bot bot commented Nov 22, 2022

🦋 Changeset detected

Latest commit: 14d3086

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@capsizecss/core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@mrm007 mrm007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really excited for this work to finally get published! 👏👏👏

Just a few nitpicky comments from me 🏃‍♂️

README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
packages/core/package.json Outdated Show resolved Hide resolved
packages/core/src/createFontStack.ts Outdated Show resolved Hide resolved
packages/core/src/createFontStack.ts Outdated Show resolved Hide resolved
packages/core/src/createFontStack.ts Outdated Show resolved Hide resolved
packages/core/src/createFontStack.ts Outdated Show resolved Hide resolved
packages/core/src/createFontStack.test.ts Outdated Show resolved Hide resolved
packages/core/src/createFontStack.test.ts Outdated Show resolved Hide resolved
@phil-lgr
Copy link

phil-lgr commented Dec 15, 2022

Really hyped about this one, can we help in any way? I'd like to try and test this

@michaeltaranto
Copy link
Contributor Author

Really hyped about this one, can we help in any way? I'd like to try and test this

Apologies for the festive season delays on this one 😄. Hoping to get it through soon. The full benefit will be had in tandem with the update to the metrics package which will be PR'd shortly.

FWIW, there is a snapshot deployment of this PR you can take for a spin:

npm install @capsizecss/core@0.0.0-create-font-stack-20221130045640

To test out the fallbacks with the size-adjust property you can install the updated metrics package too:

npm install @capsizecss/metrics@0.0.0-x-width-avg-20230123213508

@michaeltaranto michaeltaranto merged commit 0e969d8 into master Jan 30, 2023
@michaeltaranto michaeltaranto deleted the create-font-stack branch January 30, 2023 04:41
@seek-oss-ci seek-oss-ci mentioned this pull request Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants