0.4.19 • Published 10 months ago

modern-canvas v0.4.19

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Features

  • WebGL and WebGL2

  • Animation

  • Special effects

  • Transition effects

  • Describe element as you would a CSSStyle

📦 Install

npm i modern-canvas

🦄 Usage

import { Animation, Engine, Image2D, Text2D, Video2D } from 'modern-canvas'
import { fonts } from 'modern-font'

async function loadFallbackFont() {
  fonts.fallbackFont = await fonts.load({ family: 'fallbackFont', src: '/fallback.woff' })
}

loadFallbackFont().then(() => {
  const engine = new Engine({ width: 500, height: 500 }).start()

  engine.root.appendChild(
    new Image2D({
      style: {
        left: 100,
        top: 100,
        width: 100,
        height: 100,
        rotate: 30,
        opacity: 0.5,
        backgroundColor: '#00FF00',
        filter: 'brightness(102%) contrast(90%) saturate(128%) sepia(18%)',
      },
      src: '/example.png',
    }, [
      new Animation({
        duration: 3000,
        loop: true,
        keyframes: [
          { offset: 1, rotate: 180 },
        ],
      }),
      new Text2D({
        fonts,
        style: {
          fontSize: 30,
        },
        content: '/example.png',
      }),
      new Video2D({
        style: {
          left: 200,
          top: 200,
          width: 100,
          height: 100,
          maskImage: '/example.png',
        },
        src: '/example.mp4',
      }),
    ])
  )

  console.log(engine)

  document.body.append(engine.view)
})

Special effect

See all preset special effects

import { EmbossEffect, Image2D } from 'modern-canvas'

engine.root.appendChild(
  new Image2D({
    src: '/example.png',
  }, [
    new EmbossEffect(),
  ])
)

Transition effect

See all preset transitions

import { Image2D, TiltShiftTransition } from 'modern-canvas'

engine.root.appendChild(
  new Image2D({
    src: '/example.png',
  }),
  new TiltShiftTransition(),
  new Image2D({
    src: '/example.gif',
  }),
)

Use https://github.com/gl-transitions/gl-transitions with vite

import bounceGLSL from 'gl-transitions/transitions/Bounce.glsl?raw'
import { Image2D, Transition } from 'modern-canvas'

engine.root.appendChild(
  new Image2D({
    src: '/example.png',
  }),
  new Transition({ glsl: bounceGLSL }),
  new Image2D({
    src: '/example.gif',
  }),
)
0.1.10

12 months ago

0.4.9

10 months ago

0.4.8

10 months ago

0.4.19

10 months ago

0.4.10

10 months ago

0.4.17

10 months ago

0.4.18

10 months ago

0.4.15

10 months ago

0.4.16

10 months ago

0.4.13

10 months ago

0.4.14

10 months ago

0.4.11

10 months ago

0.4.12

10 months ago

0.1.0

12 months ago

0.3.0

12 months ago

0.2.1

12 months ago

0.1.2

12 months ago

0.2.0

12 months ago

0.1.1

12 months ago

0.4.5

10 months ago

0.1.8

12 months ago

0.4.4

10 months ago

0.1.7

12 months ago

0.4.7

10 months ago

0.4.6

10 months ago

0.1.9

12 months ago

0.4.1

10 months ago

0.3.2

12 months ago

0.2.3

12 months ago

0.1.4

12 months ago

0.4.0

10 months ago

0.3.1

12 months ago

0.2.2

12 months ago

0.1.3

12 months ago

0.4.3

10 months ago

0.2.5

12 months ago

0.1.6

12 months ago

0.4.2

10 months ago

0.3.3

12 months ago

0.2.4

12 months ago

0.1.5

12 months ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.0

5 years ago