npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vyaz/core

v0.0.16

Published

Rich text layout engine — TypeScript, isomorphic (browser + Bun/Node.js), pixel-perfect typography.

Readme

@vyaz/core

Rich text layout engine — TypeScript, isomorphic (browser + Bun/Node.js), pixel-perfect typography.

Part of the Vyaz project. Parses styled text into positioned lines with precise font metrics, supporting both CSS Text and Office (PowerPoint/DrawingML) rendering modes.

The engine operates on a TextFrame → Paragraph → TextRun hierarchy, following W3C CSS Text, CSS Writing Modes, and CSS Inline Layout specifications.

Installation

bun add @vyaz/core
# or
npm install @vyaz/core

Quick Start

import { layoutTextFrame } from '@vyaz/core';
import type { TextFrame } from '@vyaz/core';

const frame: TextFrame = {
  width: 400,
  wrap: true,
  paragraphs: [
    {
      style: { alignment: 'left', lineHeight: 1.4, spaceBefore: 0, spaceAfter: 0 },
      children: [
        { text: 'Hello, Vyaz!', fontFamily: 'Arial', fontSize: 16, fontWeight: 'bold', fontStyle: 'normal', color: '#000' },
      ],
    },
  ],
};

const result = layoutTextFrame(frame);
console.log(result.lines);

Features

  • Text frame layout — multi-paragraph frames with padding, wrapping, and vertical alignment
  • Multi-font, multi-style text — bold, italic, size, color, subscript/superscript, letter-spacing
  • Text alignment — left, center, right, justify
  • Line wrapping — soft/hard breaks, white-space control (normal, nowrap, pre)
  • Writing modeshorizontal-tb, vertical-rl, vertical-lr with text orientation
  • Auto-fit — scale text proportionally to fit the container (AutofitConfig)
  • Inline widgets — embedded objects (icons, images) inside the text flow
  • Office-compatible modemode: 'office' for PowerPoint/DrawingML rendering
  • Font metrics — system font registry with fontkit-based metric extraction
  • Compiler — paragraph compilation with token preparation for external renderers

API Overview

Text Frame Layout

import { layoutTextFrame } from '@vyaz/core';
import type { TextFrame, TextFrameLayoutResult } from '@vyaz/core';

const frame: TextFrame = {
  width: 600,
  height: 400,
  wrap: true,
  padding: { top: 20, right: 20, bottom: 20, left: 20 },
  verticalAlignment: 'top',
  paragraphs: [
    {
      style: { alignment: 'left', lineHeight: 1.4, spaceBefore: 0, spaceAfter: 12 },
      children: [
        { text: 'First paragraph', fontFamily: 'Arial', fontSize: 16, fontWeight: 'normal', fontStyle: 'normal', color: '#000' },
      ],
    },
  ],
};

const result: TextFrameLayoutResult = layoutTextFrame(frame);
// → { lines: Line[], frameWidth?, frameHeight?, contentWidth, contentHeight, fitHorizontal, fitVertical }

Autofit

import { applyScale, findScale } from '@vyaz/core';
import type { AutoFitOptions, AutoFitResult } from '@vyaz/core';

const scale: AutoFitResult = findScale(contentWidth, contentHeight, frameWidth, frameHeight);
const scaledLines = applyScale(result.lines, scale);

Font Registration & Metrics

import {
  FontMetricsProvider,
  SystemFontRegistry,
  createFontFace,
  getFontBuffer,
} from '@vyaz/core';
import type { FontMetrics, IFontMetricsProvider, FontFace } from '@vyaz/core';

const provider = new FontMetricsProvider();

// Node.js — register from a local file
import { readFileSync } from 'node:fs';
const buffer = readFileSync('/path/to/font.ttf');
await provider.registerFont('MyFont', { weight: 'bold', style: 'normal' }, buffer);

// Browser — register from a URL
await provider.registerFont('MyFont', {}, 'https://example.com/font.woff2');

// Get pixel metrics
const metrics: FontMetrics = provider.getMetrics('MyFont', 16);
// → { ascent, descent, capHeight, unitsPerEm, sourceTable }

Compiler

import { compileParagraph, getParagraphText, makeFontToken } from '@vyaz/core';
import type { PreparedRichInlineItem } from '@vyaz/core';

const items: PreparedRichInlineItem[] = compileParagraph(paragraph, defaultStyle);
const text: string = getParagraphText(paragraph);
const token: string = makeFontToken(fontFamily, fontSize, fontWeight, fontStyle);

Paragraph Layout Engine (low-level)

import { ParagraphLayoutEngine, paragraphLayoutEngine } from '@vyaz/core';

const engine = new ParagraphLayoutEngine();
const result = engine.layout(paragraph, maxWidth, yOffset);
// → ParagraphLayoutResult { lines: Line[], width, height, contentWidth, contentHeight }

Package Structure

src/
├── compile/        — DocumentCompiler, paragraph→token compilation
├── layout/         — Layout engines (Paragraph, TextFrame, Positioning, AutoFit)
├── measure/        — Font metrics, fontkit integration, system font registry
├── types/          — TypeScript type definitions (Document, Font, Layout)
└── utils/          — Helpers (font, list, text transform, env detection)

Requirements

  • Runtime: Bun 1.x, Node.js 18+, or modern browser
  • Optional: @napi-rs/canvas, fontkit, get-system-fonts for Node.js font metrics

License

MIT