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

@sch39/canvas-text-paragraphs

v1.0.3

Published

a lightweight JavaScript library designed to simplify the process of managing text paragraphs within a canvas environment. It provides a comprehensive set of tools for aligning, indenting, and spacing text paragraphs, enabling developers to create visuall

Downloads

7

Readme

Canvas Text Paragraphs

Canvas Text Paragraphs is a JavaScript library designed to facilitate the rendering of formatted paragraphs on an HTML5 canvas element. It provides functionality to manage text alignment, indentation, line spacing, and vertical positioning within the canvas.

Installation

You can install Canvas Text Paragraphs via npm:

npm install @sch39/canvas-text-paragraphs

or from unpkg

<script src="https://unpkg.com/@sch39/canvas-text-paragraphs@latest/dist/index.umd.js"></script>

Usage

Importing the Library

import canvasTextParagraphs from '@sch39/canvas-text-paragraphs'

Example

import canvasTextParagraphs from '@sch39/canvas-text-paragraphs';

const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

const text = `
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla facilisi. Integer id elit varius, commodo tortor eget,
lacinia ligula. Ut interdum nisi non dui pretium faucibus.
`;

canvasTextParagraphs(text, ctx, {
  align: 'center',
  verticalAlign: 'middle',
  spaceBeforeParagraph: 20,
  spaceAfterParagraph: 20,
  indent: {
    type: 'firstLine',
    by: 40,
  },
});

Demo

Link: Click here

Live Demo: Click here

Function Parameter

  • text (string): The text content to be rendered.
  • ctx (CanvasRenderingContext2D): The canvas rendering context.
  • options (object): Optional configuration object with the following properties:
    • width (number, default: 'auto'): Width of the paragraph area.
    • height (number, default: 'auto'): Height of the paragraph area.
    • xStart (number, default: 0): starting position of the paragraph on the x axis
    • yStart (number, default: 0): starting position of the paragraph on the y axis
    • align (string, default: 'left'): Horizontal text alignment ('left', 'center', 'right', 'justify').
    • verticalAlign (string, default: 'top'): Vertical text alignment ('top', 'middle', 'bottom').
    • baseLine (string, default: 'top'): Text baseline alignment ('top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom').
    • spaceBeforeParagraph (number, default: 0): Space before each paragraph.
    • spaceAfterParagraph (number, default: 0): Space after each paragraph.
    • lineSpacing (number or string, default: 'auto'): Line spacing factor or 'auto' for automatic spacing.
    • indent (object):
      • type (string, default: 'none'): Type of indentation ('none', 'firstLine', 'hanging').
      • by (number, default: 0): Indentation amount in pixels.

License

This project is licensed under the MIT License. See the LICENSE file for details.