khalidadil
  • Joined on 2025-08-25

@khalidadil/laser-geometry (0.6.2)

Published 2026-09-07 08:37:32 +00:00 by khalidadil

Installation

@khalidadil:registry=
npm install @khalidadil/laser-geometry@0.6.2
"@khalidadil/laser-geometry": "0.6.2"

About this package

@khalidadil/laser-geometry

Shared laser name-art geometry engine + client render, imported by pattern-svg-builder (the editor) and artisan-cuts (the storefront) so both produce the same cut geometry and the same on-screen look.

Two entry points:

  • @khalidadil/laser-geometry/core — Node + native. The Clipper2 geometry pipeline (text→outlines→pattern→stencil→bridges→ring), warnings, and both SVG emit surfaces. Behavioural forks between the two apps are options whose defaults reproduce the editor; the storefront passes flags:

    import { buildTextFillGeometry, emitCompoundSvg, buildFinalSVG } from '@khalidadil/laser-geometry/core';
    
    // editor: default (no perimeter band, whole bridge bars, round tabs)
    const g = await buildTextFillGeometry(project);
    
    // storefront: perimeter band, clipped void-only tabs, hourglass web
    const g2 = await buildTextFillGeometry(project, {
      patternPerimeterMm: 2.5, clipBridges: true, bridgeProfile: 'hourglass',
    });
    
  • @khalidadil/laser-geometry/render — browser, pure JS. buildArtSvg (wood-photo clip vs flat plastic), the materials palette, the wall-plane homography, and the instant approx preview.

The caller owns font/pattern loading and all file/DB/HTTP I/O; the package is pure geometry + emit. setDiagSink() optionally routes the core's diagnostic events to the host's logger (default: no-op).

Native binary

native/ is a napi-rs Clipper2 crate. A darwin-arm64 prebuild is committed for local dev. Other platforms compile from the Rust source:

npm run build:native   # cd native && napi build --release

Each consuming app's Dockerfile runs this against node_modules/@khalidadil/laser-geometry/native to produce the Linux .node (the same way the apps already build their vendored crate).

Backer (0.2.0)

core/backerService.js derives the backer — the contour-cut backing layer behind a piece (the Two-Tone product's second, thicker plastic sheet):

  • fillSilhouette(paths) — the filled outer silhouette: hole-wound contours dropped, outers re-unioned (NonZero) so nested islands absorb. Hole-free by construction.
  • buildBackerGeometry(artworkPaths, { inflationPct = 6, inflateMm, connectorWidthMm, simplifyToleranceMm }) → { paths, bounds, deltaMm, componentCountBefore, connectorCount, connected }. Operates on the FINAL compound (outlines + bridges included). Inflation deltaMm = pct/100 × min(bounds.w, bounds.h); disconnected components are auto-joined with round capsule connectors (width max(2δ, 3) mm) until ONE physical piece remains.

emitCompoundSvg(paths, bounds, { backerPaths }) grows the doc box to the backer, shifts both path sets by ONE offset (reported as docBounds — shift sibling overlays like the store's data-bridges by the same origin), and rides the backer along as <path data-backer="true" … fill="none"/>. data-backer is distinct from the legacy data-hull (whose mere presence means "paint the same-material backing" for construction:'two-layer' presets).

Render side: parseRenderSvg returns backer; buildArtSvg paints the Two-Tone stack only when BOTH a backer path and opts.backerColor are present (backer tone family prefixed --art-bk-* via artToneVars(material, color, { prefix }); artwork edge ≈1mm, backer edge ≈3mm look); buildShadowSvg casts backer ?? hull ?? d.

Parity gate

node test/golden-parity.mjs drives the real builder + shop engines and the package over a text/pattern/outline/bridge matrix and asserts byte-identical output (defaults === editor, shop-opts === storefront). Run it after any change to the geometry.

Publish (Gitea npm registry)

Reads are public; publishing needs a Gitea token (Khalid, like an image push):

npm publish

(publishConfig.registry points at https://git.kadil.dev/api/packages/khalidadil/npm/. Authenticate once with a Gitea package-write token in ~/.npmrc.)

Dependencies

Dependencies

ID Version
@xmldom/xmldom ^0.8.10
earcut ^3.2.3
opentype.js ^1.3.4
paper ^0.12.17
paperjs-offset ^1.0.8

Development Dependencies

ID Version
@napi-rs/cli ^2.18.0
three ^0.185.1

Peer Dependencies

ID Version
three >=0.150.0
Details
npm
2026-09-07 08:37:32 +00:00
7
349 KiB
Assets (1)
Versions (17) View all
0.11.0 2026-10-14
0.10.0 2026-09-18
0.9.0 2026-09-18
0.8.0 2026-09-10
0.7.0 2026-09-10