Package Exports
- @lokasketch/utils
Readme
@lokasketch/utils
Utility functions for LokaSketch Editor SDK - export helpers, JSON serialization, and design validation.
Installation
npm install @lokasketch/utilsUsage
Export Functions
import {
exportToPNG,
exportToJPG,
exportToPDF,
exportToSVG,
downloadAsPNG,
downloadAsJPG,
downloadAsPDF,
downloadAsSVG,
} from '@lokasketch/utils'
// Export to blob
const pngBlob = await exportToPNG(stage, { width: 800, height: 600 })
// Download directly
await downloadAsPNG(stage, { width: 800, height: 600 }, 'design.png')JSON Utilities
import { serializeDesign, parseDesign, validateDesign, createEmptyDesign } from '@lokasketch/utils'
// Serialize design to JSON
const json = serializeDesign(elements, canvas)
// Parse JSON to design
const design = parseDesign(json)
// Validate design JSON
const isValid = validateDesign(json)
// Create empty design
const empty = createEmptyDesign(800, 600)API Reference
Export Functions
exportToPNG(stage, options)- Export Konva stage to PNG blobexportToJPG(stage, options)- Export Konva stage to JPG blobexportToPDF(stage, options)- Export Konva stage to PDF blobexportToSVG(stage, options)- Export Konva stage to SVG stringdownloadAsPNG(stage, options, filename)- Download as PNGdownloadAsJPG(stage, options, filename)- Download as JPGdownloadAsPDF(stage, options, filename)- Download as PDFdownloadAsSVG(stage, options, filename)- Download as SVG
JSON Utilities
serializeDesign(elements, canvas)- Serialize design to JSONparseDesign(json)- Parse JSON to design objectvalidateDesign(json)- Validate design JSON structurecreateEmptyDesign(width, height)- Create empty design template
Dependencies
jspdf- For PDF export functionality@lokasketch/types- Type definitions (peer dependency)
License
MIT