# @mapbox/tiny-sdf

> Browser-side SDF font generator

Latest version **2.2.0** (published 2026-05-05) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install @mapbox/tiny-sdf
pnpm add @mapbox/tiny-sdf
yarn add @mapbox/tiny-sdf
bun add @mapbox/tiny-sdf
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2026-05-05 |
| First published | 2016-12-23 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 673 |
| Author | Vladimir Agafonkin |
| Maintainers | mapbox-npm-01, mapbox-npm-02, mapbox-npm-07, mapbox-npm-03, mapbox-npm-04, mapbox-npm-09, mapbox-npm-05, mapbox-npm-06, mapbox-npm-08, mapbox-npm-advanced-actions, mapbox-npm-ci, mapbox-npm, mapbox-admin, mapbox-machine-user, mbx-npm-ci-staging, mbx-npm-ci-production, mbx-npm-01-production, mbx-npm-02-production, mbx-npm-03-production, mbx-npm-04-production, mbx-npm-05-production, mbx-npm-06-production, mbx-npm-07-production, mbx-npm-08-production, mbx-npm-09-production, mbx-npm-02-staging, mbx-npm-advanced-actions-staging, mbx-npm-advanced-actions-production |
| Keywords | sdf, signed distance fields, font, canvas, text, distance transform |

## Links

- npm: https://www.npmjs.com/package/@mapbox/tiny-sdf
- Repository: https://github.com/mapbox/tiny-sdf
- Homepage: https://github.com/mapbox/tiny-sdf#readme
- Issues: https://github.com/mapbox/tiny-sdf/issues
- npm.io page: https://npm.io/package/@mapbox/tiny-sdf

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2026-05-05
- 2.1.0 — 2026-04-08
- 2.0.7 — 2025-08-05
- 2.0.6 — 2023-02-03
- 2.0.5 — 2022-02-01
- 2.0.4 — 2021-10-18
- 2.0.3 — 2021-10-18
- 2.0.2 — 2021-09-24
- 2.0.1 — 2021-09-22
- 2.0.0 — 2021-09-22
- 1.2.5 — 2021-02-18
- 1.2.4 — 2021-02-18
- 1.2.3 — 2021-02-08
- 1.2.2 — 2021-01-26
- 1.2.1 — 2021-01-25
- … 4 more at https://npm.io/package/@mapbox/tiny-sdf/versions

## README

# TinySDF [![Volodymyr Agafonkin's projects](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects) [![Node](https://github.com/mapbox/tiny-sdf/actions/workflows/node.yml/badge.svg)](https://github.com/mapbox/tiny-sdf/actions/workflows/node.yml)

TinySDF is a tiny and fast JavaScript library for generating SDF (signed distance field)
from system fonts on the browser using Canvas 2D and
[Felzenszwalb/Huttenlocher distance transform](https://cs.brown.edu/~pff/papers/dt-final.pdf).
This is very useful for [rendering text with WebGL](https://www.mapbox.com/blog/text-signed-distance-fields/).

## [Demo](http://mapbox.github.io/tiny-sdf)

## Usage

Create a TinySDF for drawing glyph SDFs based on font parameters:

```js
const tinySdf = new TinySDF({
    fontSize: 24,             // Font size in pixels
    fontFamily: 'sans-serif', // CSS font-family
    fontWeight: 'normal',     // CSS font-weight
    fontStyle: 'normal',      // CSS font-style
    buffer: 3,                // Whitespace buffer around a glyph in pixels
    radius: 8,                // How many pixels around the glyph shape to use for encoding distance
    cutoff: 0.25              // How much of the radius (relative) is used for the inside part of the glyph
});

const glyph = tinySdf.draw('泽'); // draw a single character
```

Returns an object with the following properties:

- `data` is a `Uint8ClampedArray` array of alpha values (0–255) for a `width` x `height` grid.
- `width`: Width of the returned bitmap.
- `height`: Height of the returned bitmap.
- `glyphTop`: Maximum ascent of the glyph from alphabetic baseline.
- `glyphLeft`: Currently hardwired to 0 (actual glyph differences are encoded in the rasterization).
- `glyphWidth`: Width of the rasterized portion of the glyph.
- `glyphHeight` Height of the rasterized portion of the glyph.
- `glyphAdvance`: Layout advance.

TinySDF is provided as a ES module, so it's only supported on modern browsers, excluding IE.

```html
<script type="module">
import TinySDF from 'https://cdn.skypack.dev/@mapbox/tiny-sdf';
...
</script>
```

In Node, you can't use `require` — only `import` in ESM-capable versions (v12.15+):

```js
import TinySDF from '@mapbox/tiny-sdf';
```

## Development

```bash
npm test  # run tests
npm start # start server for the demo page
```

## License

This implementation is licensed under the [BSD 2-Clause license](https://opensource.org/licenses/BSD-2-Clause). It's based directly on the algorithm published in the Felzenszwalb/Huttenlocher paper, and is not a port of the existing C++ implementation provided by the paper's authors.

---
_Source: https://npm.io/package/@mapbox/tiny-sdf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
