Embedding & Self-Hosting
BaroCSS CAD ships as a 100% static client-side bundle — no backend geometry servers, no database migrations, and no WebAssembly build quirks. You can embed interactive 3D CAD directly inside documentation, product configurators, or internal portals, or deploy the entire unified site on any static host.
1. Unified Static Build (pnpm build:site)
Running pnpm build:site executes scripts/build-static-site.mjs and assembles a single static directory (dist-site/):
| Route | Source App | Role |
|---|---|---|
/ | apps/library-docs | Product showcase, documentation, 77 /how/ visualizers, Live TS Playground |
/app/ | apps/cad-studio | Full 5-Workspace CAD Studio + ?embed=1 Quick-Fit mode |
/review/ | apps/cad-viewer | Shareable BaroCSS Review (.bcad 3D/2D diff + automatic 2D HLR fallback) |
/llms*.txt | generate-llms.mjs | AI-Ready context indexes (llms.txt, llms-sdk.txt, llms-mcp.txt, llms-full.txt) |
Root Domain vs Subpath Hosting (SITE_BASE)
# Custom root domain (official site: https://cad.barocss.com/)
pnpm build:library
pnpm build:site # writes dist-site/CNAME = cad.barocss.com
SITE_CNAME=cad.example.com pnpm build:site # self-hosted custom domain
SITE_CNAME= pnpm build:site # skip the CNAME file
# Subpath hosting (e.g. https://barocss.github.io/cad/)
SITE_BASE=/cad/ SITE_ORIGIN=https://barocss.github.io pnpm build:sitebuild-static-site.mjs automatically configures:
- VitePress
baseand sitemap/OpenGraph URLs cad-studioVITE_BASE(/app/or/cad/app/)- Base-prefixed
dist-site/llms.txtlinks (without mutating repo-trackeddocs/public/llms.txt) _headerswith strictframe-ancestorsCSP and immutable asset caching for Cloudflare Pages / Netlify
Static Host Recipes
- GitHub Pages: Already automated via
.github/workflows/deploy-site.yml(actions/configure-pages@v5automatically injectsSITE_BASEandSITE_ORIGIN). Enable Settings → Pages → Source: GitHub Actions. - Cloudflare Pages / Netlify: Set build command to
pnpm build:library && pnpm build:siteand output directory todist-site. - Vercel: Set build command to
pnpm build:library && pnpm build:siteand output directory todist-site.
2. Embedding Quick-Fit Studio (?embed=1)
Embed a live, interactive parametric part configurator in any webpage with a single <iframe>:
<iframe
src="https://cad.barocss.com/app/?mode=quickfit&preset=nema17&embed=1&chrome=minimal"
title="BaroCSS CAD Live Quick-Fit"
style="width: 100%; height: 480px; border: 0; border-radius: 12px;"
allow="webgpu; clipboard-write"
></iframe>Supported Query Parameters
| Parameter | Values | Behavior |
|---|---|---|
embed | 1 | true | Enables embed mode: hides top navigation chrome and uses an ephemeral session so embedded previews never overwrite a visitor's saved Studio workspace |
mode | quickfit | Opens directly in Quick-Fit parametric slider mode |
preset | nema17 | enclosure | adapter | Loads a built-in parametric B-Rep preset |
chrome | none | minimal | minimal shows the Quick-Fit parameter panel and Open in Studio ↗ handoff button; none renders a pure 3D canvas |
theme | dark | light | Matches host page appearance |
renderer | auto | webgl2 | Forces WebGL2 when WebGPU is unavailable (recommended fallback after probing navigator.gpu?.requestAdapter()) |
3. Controlling the Embed via postMessage (barocss-embed-v1)
The Studio iframe exposes a typed, origin-checked postMessage bridge on channel 'barocss-embed-v1':
Messages Sent by Studio → Host
type EmbedChildToHost =
| { channel: 'barocss-embed-v1'; type: 'ready'; renderer: 'webgpu' | 'webgl2'; preset: string }
| {
channel: 'barocss-embed-v1';
type: 'metrics';
volumeMm3: number | null;
massG: number | null;
boundsMm: [number, number, number] | null;
health: 'healthy' | 'warning' | 'error';
parameters: Record<string, number>;
}
| { channel: 'barocss-embed-v1'; type: 'error'; code: string; message: string };Messages Sent by Host → Studio
const frame = document.querySelector<HTMLIFrameElement>('#cad-embed');
// Switch parametric preset live without reloading the iframe
frame?.contentWindow?.postMessage(
{ channel: 'barocss-embed-v1', type: 'setPreset', preset: 'enclosure' },
'*',
);
// Update a single named parameter deterministically
frame?.contentWindow?.postMessage(
{ channel: 'barocss-embed-v1', type: 'setParam', name: 'thickness', value: 8 },
'*',
);
// Reframe the 3D camera
frame?.contentWindow?.postMessage(
{ channel: 'barocss-embed-v1', type: 'fitCamera' },
'*',
);Incoming host messages are validated against isAllowedEmbedOrigin (same-origin, localhost / 127.0.0.1, barocss.dev, barocss.com (incl. cad.barocss.com), *.pages.dev, *.vercel.app). When self-hosting on a custom domain, keep the embed on the same origin (/app/ alongside /) so origin validation passes automatically with zero CORS or cross-origin friction.
4. Embedding BaroCSS Review (/review/?embed=1)
To embed an interactive .bcad pull-request review with Before/After geometry diffs, approval evidence, and Quick-Fit sliders:
<iframe
src="https://cad.barocss.com/review/?embed=1"
title="BaroCSS Review Live Demo"
style="width: 100%; height: 480px; border: 0; border-radius: 12px;"
allow="webgpu"
></iframe>On browsers without WebGPU (Firefox, Safari, VMs, headless environments), BaroCSS Review automatically switches to interactive 2D HLR projection fallback (Iso | Front | Top | Right | 4-View + clickable edges/faces) so proposal diffs and spec verification remain 100% functional.