shapingkit
v0.0.1
Published
Deterministic, font-agnostic line shaping helpers for text previews.
Maintainers
Readme
Shaping Kit
Deterministic line shaping for previews and text layout.
Line breaks are part of the reading experience. shapingkit provides a
predictable, font-agnostic pass for server-rendered specimens, fallbacks, and
layout previews where a browser's exact font metrics are not available yet.
It works on words and a caller-supplied measure. It does not pretend to replace the browser's OpenType shaping engine.
Usage
import { balanceLines, shapeLines, truncateLines } from "shapingkit";
shapeLines("A type system should make the next decision obvious.", {
maxCharacters: 22,
});
balanceLines("A type system should make the next decision obvious.", 3);
truncateLines("A long specimen can still have a quiet ending.", {
maxCharacters: 18,
maxLines: 2,
});API
| Export | Purpose |
| --- | --- |
| shapeLines(text, options) | Wraps words at a maximum character measure. |
| balanceLines(text, lineCount) | Splits text into nearly equal word-balanced lines. |
| truncateLines(text, options) | Shapes text and adds an ellipsis when it exceeds the requested line count. |
| ShapeOptions | { maxCharacters, breakWords? }; long words stay intact by default. |
Development
npm run build --workspace=shapingkitMIT.
