diff --git a/cfb-svg/README.md b/cfb-svg/README.md index 7b1ac40..ce065dc 100644 --- a/cfb-svg/README.md +++ b/cfb-svg/README.md @@ -1,3 +1,40 @@ # `cfb-svg` This module aims to export SVGs for the (single) nodes defined in the `cfb-core` module. + +## Usage + +`cfb-svg` supports `browser` runtime natively. To use it in `node` / `deno` runtime, you +need to patch the `window` / `document` with `svgdom`: + +```ts +// import { assertEquals } from "assert_equals"; +import { createSVGWindow } from "npm:svgdom"; +import { registerWindow } from "@svgdotjs/svg.js"; +import { makeSingleNode, Matrix2D } from "@carefree0910/cfb-core"; +import { ShapeNodeSVGExporter } from "@carefree0910/cfb-svg"; + +const window = createSVGWindow(); +const document = window.document; +registerWindow(window, document); + +const rectangle = makeSingleNode({ + type: "rectangle", + alias: "rect", + transform: Matrix2D.from(100, 100, 50, 50), + params: { + fillParamsList: [{ type: "color", color: "#ff0000", opacity: 0.25 }], + }, + z: 0, +}); +const exporter = new ShapeNodeSVGExporter(); +const exported = await exporter.export([rectangle]); +/** + * + * + * + * + * + */ +console.log(exported.svg()); +```