You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A bunch of Javascript functions that make canvas drawing easier
๐ powered by Rust & WebAssembly, so the browser execute binary under the hood
๐ฟ access with a fluent API, clean code first !
๐จ Css-like properties names
๐ and TS types included
Installation
npm i -S @forgen/canvas-drawing
or
yarn add @forgen/canvas-drawing
Example with React
import{arrow,line,arrowHead,LineStyle,ellipse,diamond,text,LineCap}from'canvas-drawing'importReact,{useEffect,useRef}from'react'functionApp(){constcanvasRef=useRef<HTMLCanvasElement>(null)useEffect(()=>{constcontext=canvasRef.current.getContext('2d')diamond().x(140).y(0).width(60).height(40).borderColor('yellow').backgroundColor('grey').draw(context)ellipse().x(160).y(60).width(60).height(40).borderColor('white').borderStyle(LineStyle.Dashed).draw(context)text("Hello").start(10,90).color('#FFF').fontSize(34).draw(context)arrow().body(line().from(10,10).to(120,100).width(6).color('white').cap(LineCap.Round).quadraticCurve(160,10)).head(arrowHead().color('red').width(6).size(16)).draw(context)postit(260,10).draw(context)text("@TODO star repo").start(270,50).fontFamily("Kalam").bold().color("#333").maxWidth(80).draw(context)},[])return(<canvasref={canvasRef}/>)}
If given, text will be cropped and multi-lined automatically.
fontWeight
FontWeight
Normal, Light, Bold
bold
Shortup for setting lineWeight to Bold
fontStyle
FontStyle
Normal, Italic, Oblique. Italic vs Oblic : Italic is described in the font declaration. Oblique is a browser text slant.
italic
Shortup for setting lineStyle to Italic
underline
bool
undefined
strikethrough
bool
undefined
text("This is an auto cropped text based on the maxWidth property").start(0,40).color('#FFF').fontSize(18).maxWidth(200).fontFamily("Arial").draw(context)line().from(200,0).to(200,100).width(2).color('red').draw(context)