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

@topgrid/grid-sizing

v0.3.0

Published

Declarative column sizing: auto-size, star/flex ratio widths, sizeToFit (pure + injectable measurement)

Readme

@topgrid/grid-sizing

Declarative, headless column-sizing helpers for TopGrid: content-fit auto-size, star/flex ratio widths ('*' / '2*'), and container-fit sizeToFit.

The width math is pure (no DOM). Browser text measurement is injected via a MeasureText function so the sizing logic stays testable in node/SSR. A SSR-guarded createCanvasMeasureText() factory provides the browser canvas measurer. All helpers return a Record<columnId, px> map that flows into grid-core's columnSizing (TanStack ColumnSizingState) declaratively — no imperative <th>.style.width.

Installation

pnpm add @topgrid/grid-sizing
# or
npm install @topgrid/grid-sizing
# or
yarn add @topgrid/grid-sizing

Peer Dependencies

| Package | Version | |---------|---------| | @topgrid/grid-core | workspace:* | | @tanstack/react-table | >=8.0.0 <9.0.0 | | react | ^18.0.0 \|\| ^19.0.0 | | react-dom | ^18.0.0 \|\| ^19.0.0 |

This package has no runtime dependencies of its own.

Usage

Star / flex ratio widths

import { distributeStarWidths } from '@topgrid/grid-sizing';

// Container 600px, one 200px fixed column, then 1* and 2* star columns.
const widths = distributeStarWidths({
  totalWidth: 600,
  columns: [
    { id: 'a', spec: 200 },   // fixed
    { id: 'b', spec: '1*' },  // → 133.33 (of the remaining 400)
    { id: 'c', spec: '2*' },  // → 266.67
  ],
});
// { a: 200, b: 133.33…, c: 266.67… }

When a star column declares a min, it is clamped iteratively: a clamped column leaves the star pool and the remaining width is re-distributed among the rest.

Container-fit

import { sizeToFit } from '@topgrid/grid-sizing';

const widths = sizeToFit({
  containerWidth: 800,
  columns: [
    { id: 'a', width: 100 },
    { id: 'b', width: 300 },
  ],
});
// integer px that sum exactly to 800

Content-fit auto-size

import {
  autoSizeColumn,
  autoSizeColumns,
  createCanvasMeasureText,
} from '@topgrid/grid-sizing';

const measureText = createCanvasMeasureText(); // canvas in browser, estimator in SSR

const width = autoSizeColumn({
  columnId: 'name',
  header: 'Full Name',
  cellValues: ['Ada Lovelace', 'Alan Turing'],
  measureText,
  padding: 16,
  min: 80,
  max: 320,
});

For testing, inject any pure measurer — e.g. (t) => t.length * 8 — to verify the math without a browser.

API

| Export | Description | |--------|-------------| | parseColumnWidth | Parse '*' / '2*' / 120 / '120px' into a star/fixed spec | | distributeStarWidths | Split remaining width across star columns by factor (iterative min-clamp) | | sizeToFit | Scale current widths so they sum exactly to the container width | | autoSizeColumn | Content-fit width for one column (injected measurement) | | autoSizeColumns | Content-fit width map for multiple columns | | createCanvasMeasureText | Browser canvas MeasureText (SSR-guarded fallback, never throws) | | DEFAULT_AUTOSIZE_PADDING | Default auto-size padding (px) | | approxCharPx | Per-character width used by the SSR/node fallback estimator |

License

MIT © Platree. Free and open source — no license activation required.


Documentation | API Reference