vue-clamp is a collection of Vue 3 components engineered for precise text and content clamping, leveraging actual browser layout measurements rather than estimations. It offers several specialized primitives: `<LineClamp>` for multiline plain text with flexible ellipsis placement, `<RichLineClamp>` for clamping trusted inline HTML while preserving formatting, `<InlineClamp>` for single-line strings with fixed affixes, and `<WrapClamp>` for truncating collections of atomic items. The current stable version is 1.2.0. The library follows a minor release cadence, regularly introducing new features such as advanced ellipsis positioning and enhanced rich text support. A significant differentiator is its reliance on real-time DOM measurements, which ensures accurate truncation where simpler CSS-based methods might fail. It mandates Vue ^3.3.0 as a peer dependency.
npm install vue-clampVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic multiline text clamping using `<LineClamp>` with a toggle button to expand/collapse the text.
Upgrade your project to Vue 3 or use a `vue-clamp` version from the `0.x` series for Vue 2 compatibility.
Change `import VueClamp from 'vue-clamp'` to `import { LineClamp, InlineClamp } from 'vue-clamp'` and use named components directly.Migrate from `<LineClamp>Some text</LineClamp>` to `<LineClamp :text="someText" />`.
Update usage from `:tag="'div'"` to `:as="'div'"` for component root element customization.
Remove the `autoresize` prop from your component usage. Resizing is now handled internally.
Ensure all HTML passed to `<RichLineClamp :html="..." />` originates from a trusted source or has been thoroughly sanitized using a library like DOMPurify.
Update your import statement from `import VueClamp from 'vue-clamp'` to `import { LineClamp, InlineClamp } from 'vue-clamp'`.Downgrade `vue-clamp` to a `0.x` version compatible with Vue 2, or upgrade your project to Vue 3.
Change from `<LineClamp>Your content here</LineClamp>` to `<LineClamp :text="'Your content here'" />`.