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

adaptive-layout-composer

v1.0.0

Published

Adaptive layout composer with precise text measurement, dynamic font sizing, and intelligent positioning for international text and emojis

Readme

Adaptive Layout Composer

An adaptive layout composer with precise text measurement, dynamic font sizing, and intelligent positioning for international text and emojis.

Features

  • Generate SVG images with custom dimensions
  • Accurate text measurement using OpenType.js
  • Support for international text (CJK, Arabic, Hebrew, etc.) and emojis
  • Dynamic font sizing that fits text within constraints
  • Support for background images (fetched from URLs)
  • Returns SVG data as Uint8Array or base64
  • Optimized for Cloudflare Workers

Installation

npm install adaptive-layout-composer

Usage

import { createDynamicSVGImage } from 'adaptive-layout-composer';

// Generate SVG with auto font sizing
const svgData = await createDynamicSVGImage({
  text: "Hello 🌍 World!",
  width: 400,
  height: 200,
  autoFontSize: true,
  ensStyle: true
});

// Convert to base64 for data URL
const base64 = btoa(String.fromCharCode(...svgData));
const dataUrl = `data:image/svg+xml;base64,${base64}`;

API Reference

createDynamicSVGImage(options)

Generate an SVG image with the following options:

{
  text: "Hello World!",           // Text to render
  width: 270,                     // Image width in pixels
  height: 270,                    // Image height in pixels
  textColor: [255, 255, 255, 1],  // RGBA text color
  backgroundImageUrl: "https://example.com/image.jpg", // Optional background
  autoFontSize: true,             // Auto-calculate font size to fit
  maxFontSize: 68,                // Maximum font size when auto-sizing
  fontSize: 48,                   // Manual font size (if autoFontSize: false)
  ensStyle: true,                 // Use ENS-style layout with logo
  textX: 100,                     // Manual X position
  textY: 100,                     // Manual Y position
  maxTextWidth: 200               // Maximum text width
}

Other Functions

  • measureTextAccurate(text, fontSize, fontFamily) - Get accurate text measurements
  • calculateFontSize(text, maxWidth, maxHeight, minSize, maxSize) - Calculate optimal font size
  • initializeFont() - Initialize the embedded Satoshi font

Demo API Usage

The demo worker provides a REST API:

POST /

{
  "text": "Hello 🌍 World!",
  "width": 400,
  "height": 200,
  "autoFontSize": true,
  "ensStyle": true
}

Response:

{
  "success": true,
  "image": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0i...",
  "base64": "PHN2ZyB3aWR0aD0i...",
  "format": "svg"
}

Development

The project is structured as a library with a demo implementation:

  • Library: Core text measurement and SVG generation functions in src/
  • Demo: Cloudflare Worker implementation in demo/

Library Development

# Install dependencies
yarn install

# The library exports functions from src/index.js:
# - createDynamicSVGImage()
# - measureTextAccurate()
# - calculateFontSize()
# - initializeFont()

Demo Worker Development

# Start development server for the demo worker
yarn demo:dev

# This runs the worker from demo/worker.js which:
# - Serves the demo HTML interface at /
# - Provides the API endpoint for image generation

Deployment

Deploy Demo Worker

# Deploy the demo worker to Cloudflare
yarn demo:deploy

# This deploys demo/worker.js as a Cloudflare Worker

Deploy Demo Pages (Optional)

# If you want to serve the demo HTML as static pages:
# 1. Upload demo/index.html to any static hosting service
# 2. Update the WORKER_URL in the HTML to point to your deployed worker

Using as a Library

Import the library functions in your own Cloudflare Worker:

import { createDynamicSVGImage } from './src/index.js';

export default {
  async fetch(request) {
    const svgData = await createDynamicSVGImage({
      text: "Hello World",
      width: 400,
      height: 200
    });

    return new Response(svgData, {
      headers: { 'Content-Type': 'image/svg+xml' }
    });
  }
}