7.4.2 • Published 2 months ago

@pixi/text-html v7.4.2

Weekly downloads
25
License
MIT
Repository
github
Last release
2 months ago

PixiJS HTMLText

Node.js CI

An alternative to PIXI.Text that works with PixiJS v5 (both WebGL and Canvas), however, it has some advantages:

  • Supports HTML tags for styling such as <strong>, or <em>, as well as <span style="">
  • Better support for emojis and other HTML layout features, better compatibility with CSS line-height and letter-spacing.

Disadvantages:

  • Unlike PIXI.Text, HTMLText rendering will vary slightly between platforms and browsers. HTMLText uses SVG/DOM to render text and not Context2D's fillText like PIXI.Text.
  • Performance and memory usage is on-par with PIXI.Text (that is to say, slow and heavy)
  • Only works with browsers that support <foreignObject>, i.e., no Internet Explorer support.
  • Only supports web-safe fonts for the fontFamily attribute.

Install

npm install @pixi/text-html
yarn add @pixi/text-html

Usage

import { HTMLText } from '@pixi/text-html';
import { TextStyle } from '@pixi/text';

// Can use the TextStyle class found in @pixi/text
const style = new TextStyle({ fontSize: 20 });

// Make a new HTMLText object
const text = new HTMLText("Hello World", style);

Important: Because the HTMLText object takes a raw HTML string, it's represents a potential vector for XSS, it's strongly encourage you santize input especially if you're accepting user-strings.

Styles

Not all styles and values are compatible between PIXI.Text, mainly because Text is rendered using a DOM element instead of Context2D's fillText API.

Supported

  • fill
  • fontFamily (web-safe fonts only)
  • fontSize
  • fontWeight
  • fontStyle
  • fontVariant
  • letterSpacing
  • align (also supports "justify")
  • padding
  • breakWords
  • lineHeight
  • wordWrap
  • wordWrapWidth
  • strokeThickness
  • dropShadow
  • dropShadowAngle
  • dropShadowDistance
  • dropShadowBlur
  • dropShadowColor
  • trim
  • stroke
  • strokeThickness

Values may differ slightly from PIXI.Text rendering.Appearance may differ slightly between different browsers.

Unsupported

  • fillGradientStops
  • fillGradientType
  • miterLimit
  • textBaseline
  • whiteSpace

Example

https://pixijs.io/html-text/demo/

Documentation

https://pixijs.io/html-text/docs/

7.4.2

2 months ago

7.4.0

4 months ago

7.3.3

4 months ago

7.3.1

8 months ago

7.3.0

8 months ago

7.3.2

7 months ago

7.3.0-rc

10 months ago

7.3.0-rc.2

9 months ago

7.2.2

1 year ago

7.2.1

1 year ago

7.2.0

1 year ago

7.2.4

1 year ago

7.2.3

1 year ago

7.2.0-rc.3

1 year ago

7.2.0-rc.2

1 year ago

7.2.0-rc

1 year ago

7.2.0-beta.4

1 year ago

7.2.0-beta

1 year ago

3.3.1

1 year ago

7.2.0-beta.2

1 year ago

7.2.0-beta.3

1 year ago

3.3.0

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

2.1.2

2 years ago

2.1.3

2 years ago

3.0.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

3 years ago

1.0.1

3 years ago

1.0.0

4 years ago