UNPKG

@thi.ng/scenegraph

Version:

Extensible 2D/3D scene graph with @thi.ng/hiccup-canvas support

15 lines (14 loc) 497 B
import { deref } from "@thi.ng/api/deref"; import { isFunction } from "@thi.ng/checks/is-function"; const toHiccup = (node, ctx) => { const body = isFunction(node.body) ? node.body(ctx) : deref(node.body); return node.enabled && node.display ? node.children.length ? [ "g", {}, node.body ? ["g", { transform: node.mat }, body] : void 0, ...node.children.map((c) => c.toHiccup(ctx)) ] : body ? ["g", { transform: node.mat }, body] : void 0 : void 0; }; export { toHiccup };