Gathering detailed insights and metrics for @capsizecss/metrics
Gathering detailed insights and metrics for @capsizecss/metrics
Gathering detailed insights and metrics for @capsizecss/metrics
Gathering detailed insights and metrics for @capsizecss/metrics
npm install @capsizecss/metrics
Typescript
Module System
Node Version
NPM Version
@capsizecss/unpack@3.0.0
Updated on Jul 01, 2025
@capsizecss/vanilla-extract@2.0.1
Updated on May 29, 2025
@capsizecss/unpack@2.4.0
Updated on Mar 31, 2025
@capsizecss/metrics@3.5.0
Updated on Mar 31, 2025
@capsizecss/metrics@3.4.0
Updated on Nov 13, 2024
@capsizecss/metrics@3.3.0
Updated on Sep 15, 2024
TypeScript (92.21%)
CSS (5.96%)
JavaScript (1.76%)
HTML (0.05%)
Shell (0.03%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,618 Stars
232 Commits
43 Forks
10 Watchers
11 Branches
24 Contributors
Updated on Jul 15, 2025
Latest Version
3.5.0
Package Id
@capsizecss/metrics@3.5.0
Unpacked Size
21.42 MB
Size
1.38 MB
File Count
26,169
NPM Version
10.2.4
Node Version
20.11.0
Published on
Mar 31, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Font metrics library for system and Google fonts.
1npm install @capsizecss/metrics
Import the metrics for your chosen font to pass them directly into capsize.
1import { createStyleObject } from '@capsizecss/core'; 2import arialMetrics from '@capsizecss/metrics/arial'; 3 4const capsizeStyles = createStyleObject({ 5 fontSize: 16, 6 leading: 24, 7 fontMetrics: arialMetrics, 8});
In addition to common system fonts, Google fonts are also supported.
1import { createStyleObject } from '@capsizecss/core'; 2import lobsterMetrics from '@capsizecss/metrics/lobster'; 3 4const capsizeStyles = createStyleObject({ 5 fontSize: 16, 6 leading: 24, 7 fontMetrics: lobsterMetrics, 8});
Metrics for the available variants of a font can be imported by weight and font style.
1import metrics from '@capsizecss/metrics/ {font-family} / {weight}{style}';
The format follows the convention used by Google Fonts for variant names: either a standalone weight or style (e.g. regular
, italic
), a specific weight (e.g. numeric 100
to 900
), or a combination of both (e.g. 100italic
-900italic
).
[!NOTE] Each font only includes the variants that are available for that specific font.
1import arialRegular from '@capsizecss/metrics/arial/regular'; 2import arialItalic from '@capsizecss/metrics/arial/italic'; 3import arialBold from '@capsizecss/metrics/arial/700'; 4import arialBoldItalic from '@capsizecss/metrics/arial/700italic';
The top-most import path for a font family (e.g. without a variant: @capsizecss/metrics/arial
) will return the regular
variant.
In the case of a Google Font that has no regular
variant, the first variant in the variants array is returned.
The font metrics object returned contains the following properties if available:
Property | Type | Description |
---|---|---|
familyName | string | The font’s family name as authored by font creator |
fullName | string | The font’s full name as authored by font creator |
postscriptName | string | The font’s unique PostScript name as authored by font creator |
category | string | The style of the font: serif, sans-serif, monospace, display, or handwriting. |
capHeight | number | The height of capital letters above the baseline |
ascent | number | The height of the ascenders above baseline |
descent | number | The descent of the descenders below baseline |
lineGap | number | The amount of space included between lines |
unitsPerEm | number | The size of the font’s internal coordinate grid |
xHeight | number | The height of the main body of lower case letters above baseline |
xWidthAvg | number | The average width of character glyphs in the font for the selected unicode subset. Calculated based on character frequencies in written text (see below), falling back to the built in xAvgCharWidth from the OS/2 table. |
subsets | { [subset]: { xWidthAvg: number } } | A lookup of the xWidthAvg metric by subset (see supported subsets below) |
xWidthAvg
is calculatedThe xWidthAvg
metric is derived from character frequencies in written language.
The value takes a weighted average of character glyph widths in the font, falling back to the built in xAvgCharWidth from the OS/2 table if the glyph width is not available.
The purpose of this metric is to support generating CSS metric overrides (e.g. ascent-override
, size-adjust
, etc) for fallback fonts, enabling inference of average line lengths so that a fallback font can be scaled to better align with a web font. This can be done either manually or using createFontStack
.
For this technique to be effective, the metric factors in a character frequency weightings as observed in written language, using “abstracts” from Wikinews articles as a data source. Below is the source analysed for each supported subset:
Subset | Language |
---|---|
latin | English (source) |
thai | Thai (source) |
[!TIP] Need support for a different unicode subset? Either create an issue or follow the steps outlined in the
generate-weightings
script in theunpack
package and open a PR.
For more information on how to access the metrics for different subsets, see the subsets section below.
The top level xWidthAvg
metric represents the average character width for the latin
subset. However, the xWidthAvg
for each supported subset is available explicitly within the subsets
field.
For example:
1import arial from '@capsizecss/metrics/arial'; 2 3const xWidthAvgDefault = arial.xWidthAvg; 4const xWidthAvgLatin = arial.subsets.latin.xWidthAvg; // Same as above 5const xWidthAvgThai = arial.subsets.thai.xWidthAvg;
fontFamilyToCamelCase
A helper function to support tooling that needs to convert the font family name to the correct casing for the relevant metrics import.
1import { fontFamilyToCamelCase } from '@capsizecss/metrics'; 2 3const familyName = fontFamilyToCamelCase('--apple-system'); // => `appleSystem` 4const metrics = await import(`@capsizecss/metrics/${familyName}`);
entireMetricsCollection
Provides the entire metrics collection as a JSON object, keyed by font family name.
⚠️ CAUTION: Importing this will result in a large JSON structure being pulled into your project!
It is not recommended to use this client side.
1import { entireMetricsCollection } from '@capsizecss/metrics/entireMetricsCollection'; 2 3const metrics = entireMetricsCollection['arial'];
or for a specific variant:
1import { entireMetricsCollection } from '@capsizecss/metrics/entireMetricsCollection'; 2 3const arialBoldItalic = entireMetricsCollection['arial'].variants['700italic'];
MIT.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
5 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 4
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
54 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More