UNPKG

@thi.ng/hiccup-canvas

Version:

Hiccup shape tree renderer for vanilla Canvas 2D contexts

27 lines (26 loc) 633 B
import { implementsFunction } from "@thi.ng/checks/implements-function"; const image = (ctx, _, { width, height }, img, dpos, spos, ssize) => { if (implementsFunction(img, "toImageData")) { img = img.toImageData(); } if (img instanceof ImageData) { ctx.putImageData(img, dpos[0], dpos[1]); return; } width = width || img.width; height = height || img.height; spos ? ctx.drawImage( img, spos[0], spos[1], ssize ? ssize[0] : width, ssize ? ssize[1] : height, dpos[0], dpos[1], width, height ) : ctx.drawImage(img, dpos[0], dpos[1], width, height); }; export { image };