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

kaplay-plugin-text

v1.0.0

Published

KAPLAY plugin for styled text

Readme

kaplay-plugin-text

NPM

NPM version build codecov

🦖 KAPLAY plugin for styled text.

Prerequisites

Install kaplay:

npm install kaplay

Install

NPM:

npm install kaplay-plugin-text

CDN:

<script src="https://unpkg.com/kaplay-plugin-text@latest/dist/plugin.umd.js"></script>

Usage

Import the plugin:

import kaplay from 'kaplay';
import { styledTextPlugin } from 'kaplay-plugin-text';

const k = kaplay({
  plugins: [styledTextPlugin],
});

Outline text:

k.styledText('Hello', {
  size: 48,
  fill: k.rgb(255, 255, 255),
  outline: {
    color: k.rgb(0, 0, 0),
    width: 4,
  },
});

Add a drop shadow:

k.styledText('Hello', {
  size: 48,
  fill: k.rgb(255, 255, 255),
  shadow: {
    color: k.rgb(0, 0, 0),
    offsetX: 4,
    offsetY: 4,
    blur: 8,
  },
});

Fill with a gradient:

k.styledText('Hello', {
  size: 48,
  gradient: {
    from: k.rgb(255, 0, 0),
    to: k.rgb(0, 0, 255),
    direction: 'horizontal',
  },
});

Combine outline, shadow, and gradient:

k.styledText('GAME OVER', {
  size: 56,
  outline: { color: k.rgb(0, 0, 0), width: 6 },
  shadow: { color: k.rgb(0, 0, 0), offsetX: 6, offsetY: 6, blur: 12 },
  gradient: {
    from: k.rgb(255, 215, 0),
    to: k.rgb(255, 50, 50),
    direction: 'horizontal',
  },
});

Update text and styles at runtime:

const score = k.styledText('Score: 0', { size: 32 });

score.text = 'Score: 10';

// Update styles at runtime
score.setStyle({ fill: k.rgb(0, 255, 0) });

To load the plugin using a script:

<script src="https://unpkg.com/kaplay@latest/dist/kaplay.js"></script>
<script src="https://unpkg.com/kaplay-plugin-text@latest/dist/plugin.umd.js"></script>

<script>
  const k = kaplay({
    plugins: [KaplayPluginText.styledTextPlugin],
  });

  k.styledText('Hello', {
    size: 48,
    outline: { color: k.rgb(0, 0, 0), width: 4 },
  });
</script>

How It Works

The plugin creates an offscreen HTML5 <canvas> element, renders text using the 2D context API (strokeText, shadowBlur, createLinearGradient, fillText), then converts the canvas to a KAPLAY sprite via SpriteData.fromImage().

KAPLAY renders via WebGL, which doesn't natively support stroke, shadow, or gradient on text. The canvas API does, so this plugin bridges the gap by rasterizing styled text to a texture and rendering it as a sprite.

Performance

Rendering only happens when text or styles change — per-frame draws are a single cached sprite call. Canvas and textures are reused across updates.

Limitations

  • No bitmap font support: canvas only supports CSS font families, not KAPLAY's bitmap fonts
  • No textStyles / [style] markup: KAPLAY's per-character style syntax doesn't work — text is rendered as a flat string
  • No textTransform: per-character CharTransform (pos, scale, angle, color per char) is not supported
  • No letterSpacing: canvas has no native letter-spacing (may work in modern browsers via ctx.letterSpacing, but not universal)
  • Not a drop-in replacement for text(): styledText() is a separate component; use text() for plain text, styledText() when you need outline/shadow/gradient

API

styledText(txt?, opt?)

Returns a StyledTextComp component for rendering styled text.

Parameters

| Option | Type | Default | Description | | ----------------- | -------------------- | --------------------------------- | ------------------------------------------------- | | txt | string | '' | The text to display | | opt.size | number | 48 | Font size in pixels | | opt.font | string | kaplay init font or 'monospace' | CSS font family | | opt.fill | Color | Color.WHITE | Fill color | | opt.outline | Outline | — | Text outline ({ width?, color?, opacity? }) | | opt.shadow | StyledTextShadow | — | Drop shadow ({ color, offsetX, offsetY, blur }) | | opt.gradient | StyledTextGradient | — | Color gradient ({ from, to, direction }) | | opt.align | TextAlign | 'left' | Text alignment ('left', 'center', 'right') | | opt.width | number | — | Wrap width in pixels | | opt.lineSpacing | number | 0 | Gap between lines in pixels |

Component Properties

| Property | Type | Description | | --------------- | -------- | -------------------------------- | | text | string | Get/set text (re-renders on set) | | width | number | Get rendered text width | | height | number | Get rendered text height | | setStyle(opt) | void | Update styles and re-render |

Release

Release is automated with Release Please.

License

MIT