Skip to content

Commit 69f29fe

Browse files
authored
New: Add modern mode (#123)
1 parent 34cd052 commit 69f29fe

File tree

7 files changed

+2263
-615
lines changed

7 files changed

+2263
-615
lines changed

.changeset/tasty-dolphins-sell.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'tailwindcss-capsize': major
3+
---
4+
5+
Add `modern` output mode
6+
In this mode the `fontFamily`, `fontSize`, and `lineHeight` core plugins are replaced, adding custom properties to the output of each which are used in the `calc()` expressions in the utility class.
7+
8+
`modern` mode is enabled by default. The previous functionality can be maintained if needed by switching to `classic` mode.

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
$ npm install --save-dev tailwindcss-capsize
99
```
1010

11+
## leading-trim?
12+
13+
A [proposed CSS property](https://www.w3.org/TR/css-inline-3/#leading-trim) to remove the extra space from text bounding boxes, which affects optical alignment. This [article from Microsoft Design][] outlines the problem and how the proposed solution works.
14+
1115
## Configuration
1216

1317
This plugin requires a `fontMetrics` key added to your Tailwind theme. It should be an object with keys matching those in your `fontFamily` definitions, and each key should have an object of the following shape:
@@ -52,7 +56,7 @@ module.exports = {
5256

5357
## Usage
5458

55-
The new `.capsize` utility class should be applied to the _direct parent_ element surrounding a text node. This class only provides the neccessary styles for trimming whitespace, utility classes for setting `font-family`, `font-size`, and `line-height` will need to be applied as well.
59+
The new `.capsize` utility class should be applied to the _direct parent_ element surrounding a text node. This class requires `font-family`, `font-size`, and `line-height` utilities to be applied at some point above it in the cascade in order for the required custom properties to be available.
5660

5761
## Options
5862

@@ -72,5 +76,32 @@ The default `.capsize` utility class can be replaced with a custom class name if
7276
require('tailwindcss-capsize')({ className: 'leading-trim' })
7377
```
7478

79+
### mode
80+
81+
By default the plugin replaces the `fontFamily`, `fontSize`, and `lineHeight` core plugins, adding custom properties to the output of each which are used in the `calc()` expressions in the utility class.
82+
83+
```diff
84+
.font-sans {
85+
+ --ascent-scale: 0.9688;
86+
+ --descent-scale: 0.2415;
87+
+ --cap-height-scale: 0.7273;
88+
+ --line-gap-scale: 0;
89+
+ --line-height-scale: 1.2102;
90+
font-family: Inter, sans-serif;
91+
}
92+
```
93+
94+
If you need to support browsers that don’t support custom properties, setting `mode` to `'classic'` will handle all the calculation at build-time before the CSS is output. This will require that the markup matches a specific selector format.
95+
96+
```js
97+
require('tailwindcss-capsize')({ mode: 'classic' })
98+
```
99+
100+
## Related
101+
102+
[🔡 tailwindcss-opentype](https://github.com/stormwarning/tailwindcss-opentype)
103+
Utility classes for advanced typographic features.
104+
75105
[npm-url]: https://www.npmjs.com/package/tailwindcss-capsize
76106
[npm-img]: https://img.shields.io/npm/v/tailwindcss-capsize.svg?style=flat-square
107+
[article from microsoft design]: https://medium.com/microsoft-design/leading-trim-the-future-of-digital-typesetting-d082d84b202

0 commit comments

Comments
 (0)