diff --git a/modules/rgov/mod.ts b/modules/rgov/mod.ts index 8320c08..47bdd51 100644 --- a/modules/rgov/mod.ts +++ b/modules/rgov/mod.ts @@ -8,6 +8,7 @@ */ import { Hono } from "hono"; +import { resolve } from "path"; import { renderShell } from "../../server/shell"; import { getModuleInfoList } from "../../shared/module"; import type { RSpaceModule } from "../../shared/module"; @@ -16,10 +17,53 @@ import { addShapes, getDocumentData } from "../../server/community-store"; const routes = new Hono(); -// ── Module page (within a space) ── +// ── Canvas content loader (same approach as rspace module) ── -routes.get("/", (c) => { +const DIST_DIR = resolve(import.meta.dir, "../../dist"); +let canvasCache: { body: string; styles: string; scripts: string } | null = null; + +function extractCanvasContent(html: string) { + const bodyMatch = html.match(/]*>([\s\S]*?)<\/body>/i); + const styleMatches = [...html.matchAll(/]*>([\s\S]*?)<\/style>/gi)]; + const scriptMatches = [...html.matchAll(/]*>[\s\S]*?<\/script>/gi)]; + return { + body: bodyMatch?.[1] || "", + styles: styleMatches.map(m => m[0]).join("\n"), + scripts: scriptMatches.map(m => m[0]).join("\n"), + }; +} + +async function getCanvasContent() { + if (canvasCache) return canvasCache; + + const moduleFile = Bun.file(resolve(DIST_DIR, "canvas-module.html")); + if (await moduleFile.exists()) { + canvasCache = { + body: await moduleFile.text(), + styles: "", + scripts: ``, + }; + return canvasCache; + } + + const fullFile = Bun.file(resolve(DIST_DIR, "canvas.html")); + if (await fullFile.exists()) { + canvasCache = extractCanvasContent(await fullFile.text()); + return canvasCache; + } + + return { + body: `
Canvas loading...
`, + styles: "", + scripts: "", + }; +} + +// ── Module page (within a space) — renders canvas directly ── + +routes.get("/", async (c) => { const space = c.req.param("space") || "demo"; + const canvas = await getCanvasContent(); return c.html(renderShell({ title: `${space} — rGov | rSpace`, @@ -27,29 +71,9 @@ routes.get("/", (c) => { spaceSlug: space, modules: getModuleInfoList(), theme: "dark", - body: ` -
-

⚖️ rGov — GovMods

-

Do-ocratic circuit components for multiplayer collaboration

-

- Build governance decision circuits by wiring GovMods together on the canvas: -

-
    -
  • Signoff Gates — Yes/No approval checkpoints
  • -
  • Thresholds — Numeric targets (hours, dollars, signatures)
  • -
  • Knobs — Tunable parameters with temporal viscosity
  • -
  • Projects — Circuit aggregators showing "X of Y gates satisfied"
  • -
  • Amendments — Propose in-place circuit modifications
  • -
  • Quadratic Transform — Weight dampening (sqrt/log) for fair voting
  • -
  • Conviction Accumulator — Time-weighted conviction scoring
  • -
  • Multisig Gate — M-of-N approval multiplexor
  • -
  • Sankey Visualizer — Auto-discovered governance flow diagram
  • -
- - Open Canvas → - -
- `, + body: canvas.body, + styles: canvas.styles, + scripts: canvas.scripts, })); });