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

twojs-multiline-text-fixed

v1.1.3

Published

[![test](https://github.com/juliendargelos/twojs-multiline-text/workflows/test/badge.svg?branch=master)](https://github.com/juliendargelos/twojs-multiline-text/actions?workflow=test) [![build](https://github.com/juliendargelos/twojs-multiline-text/workflo

Downloads

2

Readme

twojs-multiline-text

test build version

Provides a MultilineText class fitted for Two.js. It has the same interface as the built-in Two.Text class but allows for multiline text by handling line breaks and word wrapping using word-wrapper.

Go to the demo to see it in action.

Install

npm i twojs-multiline-text --save

You can also use it from CDN:

<script src="https://unpkg.com/two.js"></script>
<script src="https://unpkg.com/twojs-multiline-text"></script>
<script>
  // MutilineText class available in global scope as TwojsMultilineText.MultilineText
</script>

Use skypack CDN to import the native es module:

<script type="module">
  import { MultilineText } from 'https://cdn.skypack.dev/twojs-multiline-text'
</script>

Usage

import Two from 'two.js'
import { MultilineText } from 'twojs-multiline-text'

const two = new Two().appendTo(document.body)

const textContent = `
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation.

Ullamco laboris nisi ut aliquip ex ea commodo
consequat.
`.trim()

const multilineText = new MultilineText(textContent, 0, 0, {
  // These are the default values
  width: Infinity,
  measure: 'font',
  mode: 'normal',
  family: 'sans-serif',
  size: 13,
  weight: 500,
  style: 'normal',
  leading: 1.2,
  absoluteLeading: false,
  alignment: 'middle',
  fill: '#000',
  stroke: 'transparent',
  linewidth: 1,
  decoration: 'none',
  baseline: 'middle',
  opacity: 1,
  visible: true
})

// Like in Two.Text, text content can be changed from the value attribute:
multilineText.value = `another text`

two.add(multilineText)

The MultilineText class has the same options as Two.Text, they can be set at instantiation or later from the instance (changes are dynamically reflected).

There are extra options for measuring and wrapping behaviour:

  • width The maximum width of the text. Interpreted depending on the value of measure option.
  • measure Name of the method to use to measure text, can be one of the following:
    • 'font' Actually measures the text by taking in account the font shape. Interprets the width option as a value in pixels.
    • 'monospace' Behaves the same as 'font' except that only one character is measured when updating text content or style. This can be used to improve performances when the font is monospaced and the text is frequently updated.
    • 'length' Only counts the number of characters. Interprets the width option as a number of characters. This is the most performant method of measuring.
  • mode Name of the method to use to wrap text. It is directly passed to the wrap function from word-wrapper. Can be one of the following:
    • 'normal' Normal wrapping.
    • 'pre' Maintains spacing.
    • 'nowrap' Collapse whitespace but only break on newline characters.
  • absoluteLeading Determines how the leading option is intepreted. When set to true, it is intepreted as an absolute value in pixels instead of a value relative to the size option (size * leading).