BREP_app 0.36.1

The next.BREP.io CAD application on the Rust B-rep kernel: an eframe (egui + wgpu) host that draws the brep-render 3D engine into an egui frame, native + wasm from one codebase.
Documentation
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BREP CAD — remote session</title>
<style>
  html, body { margin: 0; height: 100%; background: #131b24; color: #d8e0e8; font: 14px system-ui, sans-serif; overflow: hidden; }
  #stage { position: fixed; inset: 0; }
  #screen { width: 100%; height: 100%; display: block; object-fit: contain; outline: none; }
  #gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
  #gate[hidden] { display: none; }
  #gate form { display: flex; gap: 8px; }
  #gate input { width: 28em; padding: 6px 8px; background: #0d131a; color: inherit; border: 1px solid #34465a; border-radius: 4px; }
  #gate button, #bar button { padding: 6px 12px; background: #2a3c50; color: inherit; border: 1px solid #34465a; border-radius: 4px; cursor: pointer; }
  #bar { position: fixed; right: 8px; bottom: 8px; display: none; gap: 8px; align-items: center; background: #0d131acc; padding: 4px 8px; border-radius: 4px; font-size: 12px; }
  #bar.view { display: flex; }
  #agent { position: fixed; left: 50%; top: 8px; transform: translateX(-50%); background: #7a4a12e6; color: #fff3e0; padding: 3px 10px; border-radius: 10px; font-size: 12px; pointer-events: none; }
  #agent[hidden] { display: none; }
</style>
</head>
<body>
<div id="stage"><canvas id="screen"></canvas></div>
<div id="gate" hidden>
  <form id="tokenform"><input id="token" type="password" placeholder="Session token" autocomplete="off"><button>Connect</button></form>
</div>
<div id="agent" hidden>Agent is driving</div>
<div id="bar"><span id="rolelabel">Watching</span><button id="take">Take control</button></div>
<script type="module">
import { connect } from "./stream.js";

// Embedding: the harness posts {type:"brep-stream:connect", token, role?, url?}.
// A standalone visit can carry the token in the fragment (#token=...), which never
// reaches a server log, or type it in.
const params = new URLSearchParams(location.search);
const pinnedParent = params.get("parent");
const embedded = window.parent !== window;
let parentOrigin = pinnedParent;
let session = null;
const canvas = document.getElementById("screen");
const defaultUrl = `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/stream/ws`;

const tell = (type, detail = {}) => {
  if (embedded && parentOrigin) window.parent.postMessage({ type: `brep-stream:${type}`, ...detail }, parentOrigin);
};

function start({ token, role, url }) {
  if (session) session.close();
  document.getElementById("gate").hidden = true;
  session = connect({ url: url || defaultUrl, token, canvas, role: role || "control" });
  window.brepStream = session;
  session
    .on("ready", (m) => tell("ready", { session: m.session, role: m.role }))
    .on("role", ({ role }) => {
      document.getElementById("bar").className = role === "control" ? "" : "view";
      tell("role", { role });
      if (role === "control") session.focus();
    })
    .on("frame", (f) => tell("frame", { seq: f.seq }))
    .on("clipboard", (c) => tell("clipboard", c))
    .on("doc", ({ title, dirty, documents }) => tell("doc", { title, dirty, documents }))
    .on("selection", ({ selection }) => tell("selection", { selection }))
    .on("agent", ({ on }) => { document.getElementById("agent").hidden = !on; tell("agent", { on }); })
    .on("uploaded", ({ name, path }) => tell("uploaded", { name, path }))
    .on("download", ({ id, name, size }) => {
      // On its own the page saves the export; embedded, the harness decides
      // (it posts brep-stream:download back; the iframe needs allow-downloads).
      if (!embedded) session.download(id, name).catch((e) => console.warn("brep-stream: download", e));
      tell("download", { id, name, size });
    })
    .on("error", (e) => { tell("error", e); if (e.code === "auth") document.getElementById("gate").hidden = false; })
    .on("close", () => tell("closed"));
}

window.addEventListener("message", (ev) => {
  if (!embedded || ev.source !== window.parent) return;
  if (parentOrigin && ev.origin !== parentOrigin) return;
  const msg = ev.data || {};
  if (msg.type === "brep-stream:connect") {
    parentOrigin = parentOrigin || ev.origin; // pinned to the first sender
    start(msg);
  } else if (msg.type === "brep-stream:focus") {
    session && session.focus();
  } else if (msg.type === "brep-stream:take-control") {
    session && session.takeControl();
  } else if (msg.type === "brep-stream:download") {
    session && session.download(msg.id, msg.name).catch((e) => tell("error", { code: "download", msg: String(e.message || e) }));
  }
});
document.getElementById("take").addEventListener("click", () => session && session.takeControl());
document.getElementById("tokenform").addEventListener("submit", (e) => {
  e.preventDefault();
  start({ token: document.getElementById("token").value, role: params.get("role") || "control" });
});

const fragment = new URLSearchParams(location.hash.slice(1));
if (fragment.get("token")) {
  start({ token: fragment.get("token"), role: fragment.get("role") || params.get("role") || "control" });
  history.replaceState(null, "", location.pathname + location.search);
} else if (embedded) {
  window.parent.postMessage({ type: "brep-stream:loaded" }, pinnedParent || "*");
} else {
  document.getElementById("gate").hidden = false;
}
</script>
</body>
</html>