
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
tailwindcss-capsize
Advanced tools
A TailwindCSS plugin that generates text-box-trim utility classes using Capsize.
npm install --save-dev tailwindcss-capsize
Formerly known as leading-trim
, a proposed CSS property 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.
A JavaScript config file is required due to the values needed by the plugin.
@config "../tailwind.config.js";
Other Tailwind settings can be configured through CSS directives or included in the config file.
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:
{
ascent: number
descent: number
lineGap: number
unitsPerEm: number
capHeight: number
}
These values can be determined by using the Capsize website, fontkit, FontDrop!, or some other means.
// tailwind.config.js
import pluginCapsize from 'tailwindcss-capsize'
export default {
theme: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
},
fontMetrics: {
// Keys here must match those in fontFamily.
sans: {
capHeight: 2048,
ascent: 2728,
descent: -680,
lineGap: 0,
unitsPerEm: 2816,
},
},
// ...
},
plugins: [pluginCapsize],
}
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.
<!-- Example using default TailwindCSS config -->
<p class="font-sans text-base leading-none capsize">Lorem ipsum dolor</p>
number
(optional, default: 16
)The plugin assumes a root font-size of 16px
when converting from rem values. To use a different value, pass it in (without units) to the plugin options.
pluginCapsize({ rootSize: 12 })
string
(optional, default: 'capsize'
)The default .capsize
utility class can be replaced with a custom class name if preferred.
pluginCapsize({ className: 'leading-trim' })
Sometimes an interface calls for truncating text to a single line or clamping text to a specified number of lines. Applying these methods to the same element that the default .capsize
class is applied to will cause issues since the class assigns pseudo ::before
and ::after
elements to that element.
<!-- ❌ Does NOT work -->
<p class="font-sans text-base leading-none capsize truncate">
Text to be truncated to a single line
</p>
To solve this, a child element to the element with the .capsize
class should wrap the text. This element should receive the styling to truncate or line clamp.
<!-- ✅ Does work! -->
<p class="font-sans text-base leading-none capsize">
<span class="truncate">Text to be truncated to a single line</span>
</p>
🔡 tailwindcss-opentype — Utility classes for advanced typographic features.
FAQs
TailwindCSS leading-trim utility classes.
The npm package tailwindcss-capsize receives a total of 13,034 weekly downloads. As such, tailwindcss-capsize popularity was classified as popular.
We found that tailwindcss-capsize demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.