@hellixit/utils
v0.1.1
Published
Hellixitboard utility functions
Downloads
208
Maintainers
Readme
@hellixit/utils
Install
npm install @hellixit/utilsIf you prefer Yarn over npm, use this command to install the Hellixitboard utils package:
yarn add @hellixit/utilsAPI
serializeAsJSON
See serializeAsJSON for API and description.
exportToBlob (async)
Export a Hellixitboard diagram to a Blob.
exportToSvg
Export a Hellixitboard diagram to a SVGElement.
Usage
Hellixitboard utils is published as a UMD (Universal Module Definition). If you are using a module bundler (for instance, Webpack), you can import it as an ES6 module:
import { exportToSvg, exportToBlob } from "@hellixit/utils";To use it in a browser directly:
<script src="https://unpkg.com/@hellixit/[email protected]/dist/hellixitboard-utils.min.js"></script>
<script>
// HellixitboardUtils is a global variable defined by hellixitboard.min.js
const { exportToSvg, exportToBlob } = HellixitboardUtils;
</script>Here's the exportToBlob and exportToSvg functions in action:
const hellixitboardDiagram = {
type: "hellixitboard",
version: 2,
source: "https://board.hellixit.cloud",
elements: [
{
id: "vWrqOAfkind2qcm7LDAGZ",
type: "ellipse",
x: 414,
y: 237,
width: 214,
height: 214,
angle: 0,
strokeColor: "#000000",
backgroundColor: "#15aabf",
fillStyle: "hachure",
strokeWidth: 1,
strokeStyle: "solid",
roughness: 1,
opacity: 100,
groupIds: [],
roundness: null,
seed: 1041657908,
version: 120,
versionNonce: 1188004276,
isDeleted: false,
boundElementIds: null,
},
],
appState: {
viewBackgroundColor: "#ffffff",
gridSize: null,
},
};
// Export the Hellixitboard diagram as SVG string
const svg = exportToSvg(hellixitboardDiagram);
console.log(svg.outerHTML);
// Export the Hellixitboard diagram as PNG Blob URL
(async () => {
const blob = await exportToBlob({
...hellixitboardDiagram,
mimeType: "image/png",
});
const urlCreator = window.URL || window.webkitURL;
console.log(urlCreator.createObjectURL(blob));
})();