npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lbrn2-to-svg

v0.5.3

Published

A library and CLI to parse LightBurn LBRN2 files and convert them to SVG.

Downloads

33

Readme

LBRN2 to SVG Converter (lbrn2-to-svg)

NPM Version License: MIT

A TypeScript library and command-line interface (CLI) to parse LightBurn LBRN2 project files and convert their 2D vector shapes, images, and text outlines to Scalable Vector Graphics (SVG) format.

This project aims to provide a robust tool for developers needing to work with LBRN2 files programmatically or convert them for use in other applications. It is designed to be compatible with various JavaScript/TypeScript environments, including Node.js, Deno, Bun, and modern web browsers (for the library functionality).

Features

  • LBRN2 Parsing: Parses LBRN2 XML structure into a typed JavaScript object.
  • SVG Conversion: Converts supported LBRN2 elements to their SVG equivalents.
    • Supported Elements: Rect, Ellipse, Path (including Lines and Bezier curves), Group, Bitmap, Text (via BackupPath).
    • Handles element transformations (<XForm>).
  • Styling: Applies basic styling (stroke color) from LBRN2 <CutSetting> elements for vector shapes.
  • CLI Tool: Provides a command-line interface for easy file conversion.
  • TypeScript Library: Offers an ESM library for programmatic integration into your projects.
  • Cross-Environment: The core library is designed to be environment-agnostic. The CLI is for server-side environments (Node, Deno, Bun).

Supported LBRN2 Features

  • Shapes/Elements:

    • <Shape Type="Rect"> (including corner radius Cr)
    • <Shape Type="Ellipse"> (converts to <circle> if Rx equals Ry)
    • <Shape Type="Path">
      • <VertList> (vertex coordinates and control points c0x, c0y, c1x, c1y)
      • <PrimList> (primitives: L for Line, B for Bezier)
    • <Shape Type="Group"> (with nested shapes and transform composition)
    • <Shape Type="Bitmap">
      • Reads W (width), H (height), and Data (Base64 encoded image data).
      • Converted to an SVG <image> element with xlink:href set to the data URL.
      • Other bitmap properties (Gamma, Contrast, etc.) are parsed but not used in the SVG output.
    • <Shape Type="Text">
      • If the Text shape has HasBackupPath="1" and contains a <BackupPath> child of Type="Path", the parser automatically replaces the Text shape with this Path shape.
      • This allows conversion of the text outline as vector paths, avoiding complex font and rendering issues in SVG.
      • Text shapes without a usable BackupPath are currently skipped/ignored for rendering.
  • Transformations: <XForm> matrix for each shape and group.

  • Cut Settings: Uses CutIndex to link vector shapes (Rect, Ellipse, Path, Group) to <CutSetting> for stroke color. Default colors are used if a color is not explicitly defined in the CutSetting. Note: Style settings are not applied to <image> elements converted from Bitmap shapes.

  • Coordinate System: Correctly handles LightBurn's Y-up coordinate system and transforms it to SVG's Y-down system within the calculated viewBox.

Limitations & TODO

  • Direct conversion of Text elements to SVG <text> elements (which would involve font handling, layout, etc.) is not supported. Text is only rendered if a vector BackupPath is available.
  • Only basic styling (stroke color, default stroke width) is applied from CutSetting. Other laser parameters are ignored.
  • More complex PrimList primitives (if any beyond Line and Bezier) are not fully tested or supported.
  • Error handling for malformed LBRN2 files can be improved.

Installation

# Using npm
npm install lbrn2-to-svg

# Using yarn
yarn add lbrn2-to-svg

# Using bun
bun add lbrn2-to-svg

Usage

Command-Line Interface (CLI)

After installation, you can use the CLI tool:

npx lbrn2-to-svg <input.lbrn2> <output.svg>

Or, if installed globally or as a project dependency with scripts:

lbrn2-to-svg path/to/your/file.lbrn2 path/to/output/file.svg

Example:

lbrn2-to-svg project.lbrn2 project.svg
# SVG written to project.svg

Programmatic (Library)

You can use the library in your TypeScript or JavaScript (ESM) projects:

import { parseLbrn2, lbrn2ToSvg, type LightBurnProjectFile } from 'lbrn2-to-svg';
import fs from 'fs/promises';

async function convertFile(inputPath: string, outputPath: string) {
  try {
    const lbrn2Xml: string = await fs.readFile(inputPath, 'utf-8');
    const project: LightBurnProjectFile = parseLbrn2(lbrn2Xml);
    const svgString: string = lbrn2ToSvg(project);
    await fs.writeFile(outputPath, svgString, 'utf-8');
    console.log(`SVG successfully written to ${outputPath}`);
  } catch (error) {
    console.error('Conversion failed:', error);
  }
}

The core parsing and conversion functions (parseLbrn2, lbrn2ToSvg) are pure and do not rely on Node.js-specific APIs, making them suitable for browser environments if you provide the LBRN2 XML string.

Development

Setup

  1. Clone the repository:
    git clone https://github.com/jlucaso1/lbrn2-to-svg.git
    cd lbrn2-to-svg
  2. Install dependencies:
    bun install

Building

To compile TypeScript to JavaScript (outputs to dist directory):

bun run build

A tsconfig.json is included for build configuration.

Testing

Run tests using Bun:

bun test

Tests use .lbrn2 and .svg artifact files located in tests/artifacts/.

LBRN2 Artifact Minimization

A utility script is provided to minimize the size of .lbrn2 test artifacts by removing non-essential XML elements and attributes. This helps keep test files focused on the geometric data being tested.

To run the minimizer on files in tests/artifacts/:

bun run scripts/minimize_lbrn2_artifacts.ts

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests. For major changes, please open an issue first to discuss what you would like to change.

Ensure to update tests as appropriate.

License

This project is licensed under the MIT License - see the LICENSE file for details.