Note: This is a modernized fork under active development. The core parsing and rendering features are stable, with ongoing work to expand 2D entity coverage. See ROADMAP.md for current progress.
DXF parser for node/browser.
Written in TypeScript with full type definitions included. Uses modern ES2015+ features and is built with esbuild for optimal performance.
Note: This is a renewed and modernized fork of the original dxf library, with complete TypeScript migration, enhanced performance, and additional features.
- Parse:
parseString(dxfText)→ typedParsedDXF - Expand blocks:
denormalise(parsed)→ flatEntity[]with transforms - Render/export:
toSVG(parsed)→ SVG stringtoPolylines(parsed)→ numeric polyline arraystoJson(parsed)→ JSON string
- TypeScript-first public API (strict typing)
- Deterministic parsing + regression coverage via real DXF fixtures
- INSERT/BLOCK expansion (denormalisation) with transform stacking
- SVG rendering for common 2D geometry + annotation entities
- Polyline output for custom renderers (Canvas/WebGL/etc.)
- Framework-agnostic (no React/Webpack required)
This project follows a phased migration plan to align with AutoCAD 2024 DXF specifications and achieve complete 2D coverage.
Current Status (as of 2026-01-01):
- ✅ M0 — Baseline & Regression Harness: Complete
- 🔄 M1 — DXF Format & Section-Level Compliance: Ongoing
- 🔄 M2 — TABLES Coverage (2D-Relevant): In Progress
- 🔄 M3 — OBJECTS Coverage (2D-Relevant): In Progress
- 🔄 M4 — ENTITIES: Complete 2D Set: Ongoing
- 🔄 M5 — Rendering Parity (toPolylines / toSVG): Ongoing
For detailed progress, implementation roadmap, and architecture documentation, see:
- ROADMAP.md - Full migration plan and progress tracking
- ARCHITECTURE.md - Architecture overview
- Project roadmap and progress: ROADMAP.md
- Architecture overview: ARCHITECTURE.md
Version 2.0 - Complete rewrite from SAX-style parsing to handle nested references properly (inserts, blocks, etc.)
Version 3.0 - Adopted standard JS, ES6 imports, removed Gulp, updated dependencies
Version 4.x - Native SVG elements where possible (<circle />, <ellipse />, etc.)
Version 5.x - Complete TypeScript migration:
- 🎯 Full TypeScript codebase with strict type checking
- ⚡ Built with esbuild (96% faster than Babel - 18ms vs 447ms)
- 📦 Modular type system with 22+ separate type files
- ✅ Extensive unit tests and browser integration tests
- 🎨 Enhanced SVG rendering with TEXT, MTEXT, and DIMENSION support
- 📚 Comprehensive type definitions for all DXF entities
Version 7.0.0 - Semantic versioning and project modernization:
- 🔄 Implemented semantic-release for automated versioning
- 🌍 Complete migration to English (en_US) codebase
- 🎨 Advanced DIMENSION rendering with arrows and extension lines
- 📝 Consolidated type system and eliminated duplicate interfaces
- 🔧 TypeScript ESLint support
Version 7.1.0 - Entity coverage expansion:
- 🐛 Hardened POLYLINE/VERTEX/SEQEND sequencing
- 🎯 Fixed block basepoint handling for TEXT/MTEXT/DIMENSION entities
- 🖼️ Added IMAGE, UNDERLAY, LEADER, and TOLERANCE entity support
- 🧪 Browser-based SVG rendering integration tests with Playwright
- 📊 Enhanced DIMENSION support for angular 3-point rendering
Version 7.2.x (Current) - Complete 2D coverage initiative:
- 🎨 Added rendering support for RAY, XLINE, TRACE, SHAPE, WIPEOUT, and LEADER entities
- 📦 Implemented toJson export functionality
- 🗂️ Added FIELD, DIMASSOC objects and additional table types
- 🔧 Migrated functional tests to Vite (removed Babel/React/Webpack)
- 📚 Consolidated documentation into ROADMAP.md and ARCHITECTURE.md
- 🏗️ Aligned with AutoCAD 2024 DXF specifications
Many common DXF entities are parsed and rendered to SVG. Some entities are parsed but currently skipped during SVG rendering.
- ✅ LINE - Straight line segments
- ✅ CIRCLE - Native SVG
<circle />element - ✅ ARC - Circular arcs with native SVG paths
- ✅ ELLIPSE - Native SVG
<ellipse />element - ✅ LWPOLYLINE - Lightweight polylines with bulges
- ✅ POLYLINE - 2D/3D polylines with vertices
- ✅ SPLINE - B-spline curves (degree 2-3 as Bézier, others interpolated)
- ✅ TEXT - Single-line text with rotation
- ✅ MTEXT - Multi-line text with formatting
- ✅ DIMENSION - Linear, aligned, radial, diameter, and ordinate dimensions
- ✅ SOLID - Solid-filled triangles and quadrilaterals
- ✅ TRACE - Rendered as a filled path outline
- ✅ RAY - Rendered as polylines (finite fallback)
- ✅ XLINE - Rendered as polylines (finite fallback)
- ✅ WIPEOUT - Rendered as outline fallback (masking not yet implemented)
- ✅ LEADER - Rendered as an SVG path
- ✅ TOLERANCE - Rendered with SVG text fallback
- ✅ SHAPE - Rendered with SVG text fallback
INSERT note: INSERT is supported via denormalisation. The library expands INSERT entities into their referenced BLOCK contents and then renders the resulting entities with transforms applied.
⚠️ POINT - Parsed but currently not rendered to SVG⚠️ 3DFACE - Parsed but currently not rendered to SVG⚠️ HATCH - Parsed but currently not rendered to SVG⚠️ ATTDEF/ATTRIB - Block attributes parsed but not rendered⚠️ MLEADER - Parsed but not rendered to SVG⚠️ OLEFRAME - Parsed but not rendered to SVG⚠️ REGION - Parsed but not rendered to SVG⚠️ TABLE - Parsed but not rendered to SVG⚠️ MLINE - Parsed but not rendered to SVG
Note: Text styles (STYLE table) are parsed. Colors are supported; fonts are not applied to SVG.
TypeScript example with full type safety:
import { Helper } from '@linkiez/dxf-renew'
const helper = new Helper(dxfString)
// The 1-to-1 object representation of the DXF
console.log('parsed:', helper.parsed)
// Denormalised blocks inserted with transforms applied
console.log('denormalised:', helper.denormalised)
// Create an SVG
console.log('svg:', helper.toSVG())
// Create polylines (e.g. to render in WebGL)
console.log('polylines:', helper.toPolylines())
// Create a JSON representation (1-to-1 with the parsed model)
console.log('json:', helper.toJson({ pretty: true }))JavaScript example:
const { Helper } = require('@linkiez/dxf-renew')
const helper = new Helper(dxfString)
// The 1-to-1 object representation of the DXF
console.log('parsed:', helper.parsed)
// Denormalised blocks inserted with transforms applied
console.log('denormalised:', helper.denormalised)
// Create an SVG
console.log('svg:', helper.toSVG())
// Create polylines (e.g. to render in WebGL)
console.log('polylines:', helper.toPolylines())
// Create a JSON representation (1-to-1 with the parsed model)
console.log('json:', helper.toJson({ pretty: true }))The public API is exported from src/index.ts.
parseString(dxfText: string): ParsedDXF- Parse DXF text into a typed model.
denormalise(parsed: ParsedDXF): Entity[]- Expand
INSERTentities into their referencedBLOCKcontents.
- Expand
toSVG(parsed: ParsedDXF, options?): string- Render the drawing to an SVG string.
toPolylines(parsed: ParsedDXF, options?): any[]- Convert supported entities to polyline arrays.
toJson(parsed: ParsedDXF, options?): string- Serialize the parsed model as JSON.
Helper- Convenience wrapper that exposes
parsed,denormalised, plustoSVG(),toPolylines(), andtoJson().
- Convenience wrapper that exposes
There are examples in the examples/ directory.
Node ES6 (TypeScript). Will write an SVG to examples/example.es6.svg:
npx tsx examples/example.es6.jsNode ES5. Will write an SVG to examples/example.es5.svg:
node examples/example.es5.jsBrowser. Compile to a browser bundle and open the example webpage:
yarn compile
open examples/dxf.htmlThis project uses Yarn 4 (Berry) as the package manager. Make sure you have Yarn installed:
# Install via npm
npm install -g yarn
# Or via corepack (recommended)
corepack enableAll npm commands in the documentation can be replaced with yarn equivalents:
npm install→yarn installor justyarnnpm test→yarn testnpm run compile→yarn compile
Geometric elements are fully supported with native SVG elements where possible (<circle />, <ellipse/>, etc.). TEXT, MTEXT, and DIMENSION entities are now fully rendered with proper transformations and formatting.
SPLINE entities with degree 2-3 and no weights are converted to native Bézier curves. Other splines are interpolated as polylines.
Here's an example you will find in the functional test output:
DIMENSION rendering supports viewport-based auto-scaling so that arrows and text remain readable across different coordinate scales.
import { Helper } from '@linkiez/dxf-renew'
const helper = new Helper(dxfString)
const svg = helper.toSVG({
dimension: {
autoScale: true,
// Reference used when percentages are not provided.
autoScaleViewportReference: 40,
// Optional per-element overrides as a percentage (0..100)
// of min(viewBoxWidth, viewBoxHeight).
autoScaleViewportPercentages: {
arrowSize: 1.5,
textHeight: 1
}
}
})When autoScaleViewportPercentages is provided (and autoScale is enabled), the final size for each configured element is computed as:
size = min(viewBoxWidth, viewBoxHeight) * (percent / 100)
The library supports outputting DXFs as interpolated polylines for custom rendering (e.g. WebGL) or other applications:
const polylines = helper.toPolylines()There is a command-line utility (courtesy of @Joge97) for converting DXF files to SVG:
yarn global add @linkiez/dxf-renew
# or
npm i -g @linkiez/dxf-renew
dxf-to-svg --helpUsage:
Usage: dxf-to-svg [options] <dxfFile> [svgFile]
Converts a dxf file to a svg file.
Options:
-V, --version output the version number
-v --verbose Verbose output
-h, --help output usage information
Running the unit tests:
yarn testRunning the browser integration tests (Playwright):
yarn test:integration:browserThese tests render fixtures in a real browser and write deterministic PNG screenshots under test/rendered/ (overwritten on each run).
Running the functional tests in a browser:
yarn test:functionalThis starts a Vite dev server and opens http://localhost:8030/toSVG.html.
Project documentation index: ROADMAP.md (see “Documentation (Consolidated)”).
This library is written in TypeScript and includes full type definitions. All DXF entities, configuration options, and helper methods are fully typed.
Example with type imports:
import { Helper, ParsedDXF, Entity, LineEntity, CircleEntity } from '@linkiez/dxf-renew'
const helper = new Helper(dxfString)
const parsed: ParsedDXF = helper.parsed
const entities: Entity[] = helper.denormalised
// Type narrowing
entities.forEach((entity) => {
if (entity.type === 'LINE') {
const line = entity as LineEntity
console.log(`Line from (${line.start.x}, ${line.start.y}) to (${line.end.x}, ${line.end.y})`)
}
})The project uses esbuild for compilation, which is significantly faster than Babel:
- Build time: ~18-22ms (vs 447ms with Babel)
- 96% performance improvement
- Full TypeScript support with type checking via
tsc - Yarn 4 (Berry) as package manager
Build commands:
yarn compile # Compile TypeScript to JavaScript
yarn type-check # Run TypeScript type checking
yarn test # Run all testsThis project is a modernized fork of the original dxf library by skymakerolof, which itself was based on the work by bjnortier and many contributors. DXF-Renewed aims to maintain and improve upon this excellent foundation with modern TypeScript, enhanced performance, and new features.
This project uses semantic-release for automated version management and package publishing.
Releases are automatically created when commits following Conventional Commits are pushed to:
main- Stable production releases (1.0.0,1.1.0,2.0.0)
# New feature → MINOR version (1.0.0 → 1.1.0)
feat(dimension): add DIMSTYLE color support
# Bug fix → PATCH version (1.0.0 → 1.0.1)
fix(parser): correct POLYLINE parsing
# Breaking change → MAJOR version (1.0.0 → 2.0.0)
feat!: migrate to pure ESM
BREAKING CHANGE: CommonJS is no longer supportedTo contribute:
- Fork the repository
- Make commits using
yarn commit(interactive) or following Conventional Commits - Push to your fork
- Open a Pull Request to
main
See CONTRIBUTING.md for detailed guidelines.
- Liam Mitchell https://github.com/LiamKarlMitchell
- Artur Zochniak https://github.com/arjamizo
- Andy Werner https://github.com/Gallore
- Ivan Baktsheev https://github.com/apla
- Jeff Chen https://github.com/jeffontheground
- Markko Paas https://github.com/markkopaas
- Kim Lokøy https://github.com/klokoy
- Erik Söhnel https://github.com/hoeck
- Teja https://github.com/hungerpirat
- Jakob Pallhuber https://github.com/Joge97
- Eric Mansfield https://github.com/ericman314
- Kristofer https://github.com/kriffe
- LiNkIeZ https://github.com/linkiez
See LICENSE file for details.
