Building a 10,700-Line Browser CAD Engine in TypeScript: Planar-Graph Room Solving, True-Scale Vector PDFs, and Layered DXF Export
Most browser floor-plan tools are either lightweight room decorators or $49/month SaaS subscriptions that lock your own drawings behind recurring billing. I built PlanCaliber to run a real imperial 2D/3D CAD drafting eng
Most browser floor-plan tools are either lightweight room decorators or $49/month SaaS subscriptions that lock your own drawings behind recurring billing. I built PlanCaliber to run a real imperial 2D/3D CAD drafting engine, AI sketch/PDF-to-CAD pipeline, and true-scale blueprint exporter directly in the browser on SvelteKit and Cloudflare Workersβwith no account required to draft and straightforward one-time export pricing.
Here is a quick 38-second walkthrough of the live Studio and exports:
Watch the 38s walkthrough on YouTube
And here is a look at the four trickiest engineering problems inside the src/lib/cad/ engine (10,710 lines of pure TypeScript, zero headless Chromium).
1. Healing Messy Walls into Watertight Rooms (healer.ts)
Whether walls come from mouse clicks on a 2D canvas, a phone photo of a hand-drawn napkin sketch, or an old PDF floor plan, raw wall segments are never topologically clean:
- Endpoints miss by 1β4 inches.
- Interior partition walls terminate in the middle of exterior walls (T-junctions) without sharing a vertex.
- Split segments sit collinearly along the same wall line.
Before computing room areas, clearances, or 3D extrusions, healPlanDocument() and solvePlan() run a deterministic topology pipeline:
-
Endpoint snapping & orthogonal alignment on a US imperial inch grid (
1/16"precision). - T-junction splitting so any wall terminating on another wall's interior splits the host segment into clean graph edges without breaking hosted doors or windows.
- Planar-graph half-edge cycle extraction to detect minimal enclosed interior room polygons, separate exterior envelope walls from interior partitions, and compute live ANSI Z765 Gross Living Area (GLA) square footage.
-
Wall-pier trimming around doors and windows so double-line 2D walls, 3D Three.js extrusions, and
.DXFwall faces stop cleanly at every rough opening jamb.
2. True-Scale 1/4" = 1'-0" Vector Blueprints Without a Headless Browser (export-pdf.ts)
Running Puppeteer or headless Chrome to print HTML to PDF breaks true architectural scale, bloats memory, and won't run inside a lightweight edge worker.
Instead, PlanCaliber builds vector sheets directly on pdf-lib using exact PDF point coordinates (72 pt = 1 inch, so 1/4" = 1'-0" maps 12" of building geometry to 18.0 pt on paper, with automatic fallback scales like 3/16" or 1/8" when a floor plan exceeds the printable ARCH D / Tabloid viewport). Every export emits crisp vector lineworkβnever rasterized screenshots:
-
A-101: Dimensioned architectural floor plan with exterior/interior dimension chains, door swing arcs, room labels, and title block. -
M-101: Clean white MLS-style presentation sheet for real estate listings. -
A-102: Automated IRC & NKBA clearance overlay (hallway widths, door clear openings, toilet/vanity/shower clearances, kitchen work aisle & triangle checks). -
E-101: NEC electrical layout overlay (GFCI, duplex outlets, switches, recessed fixtures). -
A-201: Automated framing & material takeoff sheet (linear feet of exterior/interior walls, 16" OC stud counts, top/bottom plates, drywall 4Γ8 sheet counts).
3. Native ASCII .DXF Serialization (export-dxf.ts)
If a contractor, drafter, or homeowner wants to open a sketch-converted plan in AutoCAD, QCAD, LibreCAD, or SketchUp, they need real CAD geometry organized by standard AIA layersβnot a flat SVG dump.
generateAutoCadDxf() emits clean AutoCAD R12 (AC1009) ASCII .DXF with flipped CAD Y-coordinates (dxfY = maxY - y), exact door swing arcs (ARC entities computed from hinge/leaf vectors), double-line wall faces trimmed at every door and window jamb, and 8 standard layers:
-
A-WALLβ double-line trimmed wall piers -
A-DOORβ door leaves, jambs, and swing arcs -
A-GLAZβ window glazing and sills -
A-CABNβ kitchen/bath cabinetry and appliances -
A-FURNβ furniture and fixtures -
E-POWRβ electrical symbols -
A-ROOMβ room labels and square-footage tags -
A-DIMSβ exterior and interior dimension chains
4. Turning Hand Sketches & PDFs Into Editable Vector Geometry
A common trap with AI + floor plans is using image-to-image diffusion models, which hallucinate dimensions, warp text, and output flat pixels you cannot edit. PlanCaliber instead parses sketches, phone photos (including a QR phone-camera upload bridge), PDF floor plans, or plain-English room briefs into structured JSON walls, openings, fixtures, and roomsβthen feeds that output straight through the exact same deterministic healAndSolvePlan() solver so every extracted wall is immediately editable, snappable, measurable in 2D/3D, and exportable to true-scale PDF and .DXF.
Try It Live
You can test the full 2D/3D studio, 20 starter US floor-plan templates, and 8 standalone US building-code calculators (IRC stair rise/run, egress windows, ANSI Z765 GLA, bathroom/garage clearances, floor-plan scale converter) right now in your browser at plancaliber.com with no account required.
Export pricing is strictly one-time (no subscription required):
- Free in browser: Full 2D/3D Studio, 2 AI sketch/PDF scans per day, watermarked sheet proofs, all 8 calculators.
-
$9 one-time (Clean Print & Share Pass): Removes all watermarks and unlocks true-scale
A-101+M-101vector PDF,2400pxPNG, vector SVG, shareable 2D/3D client link, custom unbranded title block, 40 AI scans/day, and 30 days of free edits & re-downloads. -
$19 one-time (Full 5-Sheet CAD +
.DXFPack): AddsA-102,E-101,A-201PDF sheets, layered AutoCAD.DXF, 3D.OBJ/.MTL, and takeoff.CSV. - Every purchase includes a 14-day instant no-questions-asked refund.
Note: PlanCaliber is preliminary space-planning and drafting software (not licensed architectural or engineering services); always verify dimensions and local building codes on site.
Would love feedback from anyone who tests the planar room solver or imports the .DXF output into AutoCAD, QCAD, LibreCAD, or SketchUp!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.