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 🙏

© 2024 – Pkg Stats / Ryan Hefner

manga-renderer

v1.0.4

Published

A renderer for package files output from FramePlanner

Downloads

342

Readme

manga-renderer

A JavaScript library for rendering manga/comic pages in browser canvas.

Features

  • Load and render manga pages from envelope file format
  • Automatic font loading (supports both Google Fonts and local fonts)
  • Canvas-based rendering for optimal performance
  • Handles text bubbles and typography
  • TypeScript support

Installation

npm install manga-renderer

Basic Usage

import { readEnvelope, buildRenderer, listFonts, isLocalFont, loadGoogleFontForCanvas } from "manga-renderer";

// Load your envelope file
const response = await fetch('your-manga.envelope');
const fileContent = await response.blob();
const book = await readEnvelope(fileContent);

// Get canvas element
const canvas = document.querySelector('canvas');

// Load required fonts
const fonts = listFonts(book);
for (const font of fonts) {
  const { family, weight } = font;
  
  if (isLocalFont(family)) {
    // Load local font
    const localFile = localFonts[family];
    const url = `/fonts/${localFile}.woff2`;
    const font = new FontFace(family, `url(${url}) format('woff2')`, { 
      style: 'normal', 
      weight 
    });
    document.fonts.add(font);
    await font.load();
  } else {
    // Load Google font
    await loadGoogleFontForCanvas(family, [weight]);
  }
}

// Initialize renderer
const renderer = buildRenderer(canvas, book);

API Reference

readEnvelope(blob: Blob): Promise<Book>

Reads and parses a manga envelope file.

buildRenderer(canvas: HTMLCanvasElement, book: Book): Renderer

Creates a new renderer instance for the given canvas and book.

listFonts(book: Book): Font[]

Returns an array of required fonts for the book.

isLocalFont(family: string): boolean

Checks if the given font family is a local font.

loadGoogleFontForCanvas(family: string, weights: string[]): Promise<void>

Loads a Google Font for use with canvas.

License

MIT

Development Setup

Before building the package, you need to:

  1. Clone the FramePlanner2 repository alongside the manga-renderer directory:
# Your workspace directory
├── manga-renderer/
└── FramePlanner2/  # clone this repository
  1. Clone FramePlanner2:
git clone https://github.com/jonigata/FramePlanner2.git
  1. Run the setup script:
cd manga-renderer
sh setup.sh

This setup process is required because manga-renderer depends on some modules from the FramePlanner2 project.

Project Structure

manga-renderer-npm/
├── src/
│   ├── /lib/layeredCanvas/ -> ../../../FramePlanner/src/lib/layeredCanvas/  (symlink)
│   └── /lib/book/ -> ../../../FramePlanner/src/lib/book/  (symlink)
├── setup.sh
└── package.json

Note: The src/manga-renderer directory is a symbolic link to the source code in the FramePlanner repository. Changes made to the files in either location will be reflected in both places.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.