JSPM

@lokasketch/utils

0.1.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q7419F
  • License SEE LICENSE IN LICENSE

Utility functions for Custom Editor SDK - export helpers (PNG/JPG/PDF/SVG), JSON serialization, and design validation

Package Exports

  • @lokasketch/utils

Readme

@lokasketch/utils

Utility functions for LokaSketch Editor SDK - export helpers, JSON serialization, and design validation.

Installation

npm install @lokasketch/utils

Usage

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 blob
  • exportToJPG(stage, options) - Export Konva stage to JPG blob
  • exportToPDF(stage, options) - Export Konva stage to PDF blob
  • exportToSVG(stage, options) - Export Konva stage to SVG string
  • downloadAsPNG(stage, options, filename) - Download as PNG
  • downloadAsJPG(stage, options, filename) - Download as JPG
  • downloadAsPDF(stage, options, filename) - Download as PDF
  • downloadAsSVG(stage, options, filename) - Download as SVG

JSON Utilities

  • serializeDesign(elements, canvas) - Serialize design to JSON
  • parseDesign(json) - Parse JSON to design object
  • validateDesign(json) - Validate design JSON structure
  • createEmptyDesign(width, height) - Create empty design template

Dependencies

  • jspdf - For PDF export functionality
  • @lokasketch/types - Type definitions (peer dependency)

License

MIT