React CAD SDK (@barocss/cad-react/sdk)
While the root @barocss/cad-react entry provides declarative JSX geometry authoring (<Part>, <Extrude>, <Hole>), @barocss/cad-react/sdk ships ready-to-mount React components and hooks for building CAD viewers, configurators, and 2D drawing inspectors — the exact SDK powering BaroCSS Review.
Public exports
| Export | Kind | Purpose |
|---|---|---|
CadViewport | Component | Embeddable WebGPU/WebGL2 3D CAD viewport bound to evaluated display meshes or snapshots |
CadDrawing | Component | Interactive 2D HLR engineering drawing SVG view with semantic edge/face/item hit callbacks |
useCadDocument | Hook | Manages reactive .bcad / part document state, parameter overrides, and worker evaluation |
useCadSelection | Hook | Tracks typed 3D/2D entity selection (surface, curve, edge, item) across views |
renderCadDrawingSvg | Function | Headless SVG rendering helper over @barocss/cad-projection with semantic data-* attributes |
extractDrawingHit | Function | Maps pointer events on a CadDrawing SVG element to typed CadDrawingHit payloads |
snapshotToDisplayMeshes | Function | Converts an evaluated kernel/model snapshot into CadViewport display mesh packets |
Interactive 3D + 2D cross-highlighting
Combine CadViewport and CadDrawing with useCadSelection to build split 3D/2D review surfaces:
import { useState } from 'react';
import {
CadViewport,
CadDrawing,
useCadSelection,
type CadDrawingHit,
type ProjectionItem,
} from '@barocss/cad-react/sdk';
export function PartReviewCard({ items }: { items: readonly ProjectionItem[] }) {
const selection = useCadSelection();
const [lastHit, setLastHit] = useState<CadDrawingHit | null>(null);
return (
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
<CadViewport />
<CadDrawing
items={items}
view="iso"
hiddenLines
onHit={hit => {
setLastHit(hit);
if (hit?.itemId) selection.select({ kind: 'item', id: hit.itemId });
}}
/>
{lastHit && <pre>{JSON.stringify(lastHit)}</pre>}
</div>
);
}Semantic 2D SVG hit callbacks
CadDrawing wraps @barocss/cad-projection and annotates projected paths with semantic metadata (CadDrawingEdgeHit, CadDrawingFaceHit, CadDrawingItemHit). Clicking a hidden line, silhouette edge, or filled face invokes onHit with the originating B-rep item and edge classification so inspectors and 3D viewports stay synchronized without DOM coordinate heuristics.
Headless JSX DSL (@barocss/cad-react/dsl)
For server-side or worker-side declarative part generation without a DOM, import the headless compiler from @barocss/cad-react/dsl. For standard component props and compiler rules, see Components and props.