1.1.6 • Published 1 year ago

@fcanvas/worker v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@fcanvas/worker

The plugin provides support for using fCanvas in WebWorker

This plugin needs to be integrated into both mainstream and Worker

If you just need simple operation and don't need to redraw many times directly or manipulate events you don't need this plugin

View source code at: https://github.com/fcanvas/fcanvas

NPM Size Download

Install

pnpm add fcanvas @fcanvas/worker

Usage

To use the power of WebWorker with fCanvas you first need to create a Stage on the main thread to receive signals from Worker:

main.ts

import Worker from "./worker?worker"

import { portToWorker } from "@fcanvas/worker"

const worker = new Worker()

const stage = new Stage().mount("#app")
portToWorker(worker, stage)

then you just create another Stage in Worker and send it to thread and use fCanvas as usual:

worker.ts

import {
  Circle,
  computed,
  Layer,
  Stage,
  useMouseIsPressed,
  useMousePos
} from "fcanvas"

import { portToThread } from "@fcanvas/worker"

const stage = new Stage()

const layer = new Layer()
stage.add(layer)

const pos = useMousePos(layer)
const mouseIsPressed = useMouseIsPressed(layer)

const circle = new Circle({
  x: computed(() => pos.mouseX),
  y: computed(() => pos.mouseY),
  radius: 50,
  stroke: "#fff",
  fill: computed(() => (mouseIsPressed.value ? "red" : "green"))
})
layer.add(circle)

portToThread(stage)
1.1.6

1 year ago

1.1.5

2 years ago

1.1.1

2 years ago

1.1.0-rc.40

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.0-rc.39

2 years ago

1.1.0-rc.37

2 years ago

1.1.0-rc.38

2 years ago

1.1.0-rc.35

2 years ago

1.1.0-rc.36

2 years ago

1.1.0-rc.33

2 years ago

1.1.0-rc.34

2 years ago

1.1.0-rc.31

2 years ago

1.1.0-rc.32

2 years ago

1.1.0-rc.30

2 years ago

1.1.0-rc.29

2 years ago

1.1.0-rc.28

2 years ago

1.1.0-rc.27

2 years ago

1.1.0-rc.26

2 years ago

1.1.0-rc.24

2 years ago

1.1.0-rc.25

2 years ago

1.1.0-rc.23

2 years ago

1.1.0-rc.22

2 years ago

1.1.0-rc.21

2 years ago