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

use-pretext

v0.1.0

Published

Vue 3 composables for @chenglou/pretext text measurement and line layout.

Readme

use-pretext

Vue 3 composables for @chenglou/pretext.

This package wraps Pretext with Vue 3 composables for:

  • measuring multiline text height from a reactive width or DOM target
  • reading wrapped line output for custom renderers
  • using the same text layout logic in DOM and canvas flows

Install

npm install vue @chenglou/pretext use-pretext

usePretext

Use this when you want the measured block height and line count for reactive text.

import { ref } from 'vue'
import { usePretext } from 'use-pretext'

const target = ref<HTMLElement | null>(null)
const text = ref('AGI 春天到了. بدأت الرحلة')

const layout = usePretext({
  target,
  text,
  lineHeight: 24,
  font: {
    size: '16px',
    family: 'Inter',
    weight: 500,
  },
})
<template>
  <div ref="target">
    Height: {{ layout.height }}
    Lines: {{ layout.lineCount }}
  </div>
</template>

You can also pass a reactive width directly instead of a target.

usePretextLines

Use this when you also need the actual wrapped lines.

import { computed, ref } from 'vue'
import { usePretextLines } from 'use-pretext'

const width = ref(320)
const text = ref('Manual rendering is easier when you already know the line breaks.')

const layout = usePretextLines({
  width,
  text,
  lineHeight: 22,
  font: '16px "Helvetica Neue"',
})

const labels = computed(() => layout.lines.value.map((line) => line.text))

Demo

This repo includes a small Vite demo app under demo/.

npm install
npm run demo

It shows:

  • usePretext(...) with a real observed DOM container
  • usePretextLines(...) with explicit width control and per-line output

Each use case is split into its own page in the demo so you can inspect them independently.

Options

  • text: string | Ref<string> | () => string
  • font: Pretext font string or an object with size, family, and optional style, variant, weight, stretch
  • lineHeight: number used for pretext.layout(...)
  • width: optional explicit width
  • target: optional element ref to observe with ResizeObserver
  • whiteSpace: 'normal' | 'pre-wrap'
  • locale: forwarded to pretext.setLocale(...)
  • observeResize: defaults to true

Notes

  • If both width and target are provided, width wins.
  • locale is global inside Pretext. Changing it clears Pretext's shared cache.

Publishing

This repo is set up to be published as an npm package.

Before publishing:

  1. Confirm that the package name use-pretext is available on npm, or change "name" in package.json to a scoped name such as @your-scope/use-pretext.
  2. Install dependencies and run:
npm install
npm run test
npm run check
npm run build
  1. Log in to npm:
npm login
  1. Publish:
npm publish

If you switch to a scoped package name and want it public, publish with:

npm publish --access public