Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions .github/architecture/repo-map.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<!-- AUTO-GENERATED by .github/scripts/generate-repo-map.mjs — run `pnpm map` to update. -->
# PolyCSS Repository Map

Tracked production code scanned across `packages/*/src`, `bench/`, and `website/src`: **421 files**, **101,578 lines**. Regenerate with `pnpm map`; verified in CI by `pnpm check:map`.
Tracked production code scanned across `packages/*/src`, `bench/`, and `website/src`: **435 files**, **98,545 lines**. Regenerate with `pnpm map`; verified in CI by `pnpm check:map`.

## 1. Packages & Entry Points

| Package | Visibility | Exports | Workspace deps | Src files | Src lines | Test files |
|---|---|---|---|---:|---:|---:|
| `packages/core` (`@layoutit/polycss-core`) | npm | `., ./three` | — | 75 | 27,024 | 58 |
| `packages/core` (`@layoutit/polycss-core`) | npm | `., ./three` | — | 78 | 26,885 | 58 |
| `packages/domformat` (`@layoutit/polycss-domformat`) | private | `., ./browser` | — | 36 | 13,165 | 0 |
| `packages/fonts` (`@layoutit/polycss-fonts`) | npm | `.` | `@layoutit/polycss-core` | 7 | 1,661 | 4 |
| `packages/morph` (`@layoutit/polycss-morph`) | npm | `., ./prepare` | `@layoutit/polycss`, `@layoutit/polycss-core` | 49 | 7,633 | 14 |
| `packages/polycss` (`@layoutit/polycss`) | npm | `., ./runtime, ./elements, ./three` | `@layoutit/polycss-core` | 62 | 16,582 | 40 |
| `packages/react` (`@layoutit/polycss-react`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 44 | 6,398 | 31 |
| `packages/fonts` (`@layoutit/polycss-fonts`) | npm | `.` | `@layoutit/polycss-core` | 7 | 1,656 | 4 |
| `packages/morph` (`@layoutit/polycss-morph`) | npm | `., ./prepare` | `@layoutit/polycss`, `@layoutit/polycss-core` | 49 | 7,629 | 14 |
| `packages/polycss` (`@layoutit/polycss`) | npm | `., ./runtime, ./elements, ./three` | `@layoutit/polycss-core` | 72 | 16,820 | 41 |
| `packages/react` (`@layoutit/polycss-react`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 44 | 4,653 | 31 |
| `packages/skills` (`@layoutit/polycss-skills`) | npm | `.` | — | 1 | 415 | 1 |
| `packages/vue` (`@layoutit/polycss-vue`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 42 | 5,560 | 29 |
| `packages/vue` (`@layoutit/polycss-vue`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 42 | 4,402 | 29 |

## 2. Canonical Workspace Source Aliases

Expand Down Expand Up @@ -44,35 +44,35 @@ Single source of truth: [`packages/workspace-aliases.mjs`](../../packages/worksp

| Fan-in | Lines | File |
|---:|---:|---|
| 108 | 642 | `packages/core/src/index.ts` |
| 65 | 248 | `packages/core/src/types.ts` |
| 113 | 644 | `packages/core/src/index.ts` |
| 67 | 248 | `packages/core/src/types.ts` |
| 39 | 247 | `packages/polycss/src/runtime.ts` |
| 32 | 301 | `packages/react/src/index.ts` |
| 31 | 119 | `website/src/components/types.ts` |
| 24 | 147 | `packages/polycss/src/runtime.ts` |
| 30 | 119 | `website/src/components/types.ts` |
| 18 | 218 | `packages/polycss/src/index.ts` |
| 18 | 88 | `website/src/components/GalleryWorkbench/types.ts` |
| 13 | 283 | `packages/polycss/src/elements/PolySceneElement.ts` |
| 13 | 45 | `packages/polycss/src/render/textureAtlas.ts` |
| 13 | 41 | `packages/react/src/camera/context.ts` |
| 12 | 1,396 | `packages/polycss/src/api/createPolyScene.ts` |
| 11 | 101 | `packages/core/src/atlas/constants.ts` |
| 17 | 385 | `packages/polycss/src/api/createPolyScene.ts` |
| 16 | 45 | `packages/polycss/src/render/textureAtlas.ts` |
| 13 | 121 | `packages/polycss/src/api/scene/internalTypes.ts` |
| 13 | 476 | `packages/polycss/src/api/scene/types.ts` |
| 12 | 49 | `packages/core/src/math/vec3.ts` |

### Largest production source files

| Lines | File |
|---:|---|
| 3,578 | `packages/domformat/src/schema.ts` |
| 2,746 | `packages/core/src/merge/optimizePolygons.ts` |
| 2,185 | `packages/core/src/shadow/computeReceiverShadows.ts` |
| 2,017 | `packages/core/src/parser/parseGltf.ts` |
| 2,705 | `packages/core/src/merge/optimizePolygons.ts` |
| 2,186 | `packages/core/src/shadow/computeReceiverShadows.ts` |
| 2,010 | `packages/core/src/parser/parseGltf.ts` |
| 1,935 | `packages/domformat/src/state/polycss.ts` |
| 1,592 | `packages/core/src/merge/seamRepair.ts` |
| 1,527 | `website/src/components/GalleryWorkbench/GalleryWorkbench.tsx` |
| 1,396 | `packages/polycss/src/api/createPolyScene.ts` |
| 1,283 | `website/src/components/VanillaScene/VanillaScene.tsx` |
| 1,227 | `packages/react/src/controls/TransformControls.tsx` |
| 1,548 | `packages/core/src/merge/seamRepair.ts` |
| 1,519 | `website/src/components/GalleryWorkbench/GalleryWorkbench.tsx` |
| 1,274 | `website/src/components/VanillaScene/VanillaScene.tsx` |
| 1,214 | `website/src/components/WordArtWorkbench/WordArtWorkbench.tsx` |
| 1,198 | `bench/visual-gate.mjs` |
| 1,192 | `bench/visual-gate.mjs` |
| 1,178 | `packages/domformat/src/browser.ts` |
| 1,139 | `website/src/components/GalleryWorkbench/presets/presetFiles.ts` |

## 4. Core Render & Control Pipelines

Expand Down
90 changes: 89 additions & 1 deletion .github/scripts/check-packs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Usage:
* node .github/scripts/check-packs.mjs
*/
import { execFile } from "node:child_process";
import { execFile, execFileSync } from "node:child_process";
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
Expand Down Expand Up @@ -110,6 +110,93 @@ export function validateTarballInventory(pkgName, packedManifest, tarEntries) {
return errors;
}

export function extractNamedImportsFromDist(jsSource, targetSpecifier) {
const escaped = targetSpecifier.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const re = new RegExp(`import\\s*\\{([^}]*)\\}\\s*from\\s*["']${escaped}["']`, "g");
const names = new Set();
for (const match of jsSource.matchAll(re)) {
for (const part of match[1].split(",")) {
const cleaned = part.trim();
if (!cleaned) continue;
const imported = cleaned.split(/\s+as\s+/)[0].trim();
if (imported) names.add(imported);
}
}
return [...names].sort();
}

export function collectBarrelValueExports(barrelSource) {
const names = new Set();
const stripped = barrelSource
.replace(/\/\*[\s\S]*?\*\//g, "")
.replace(/\/\/[^\n]*/g, "");
for (const match of stripped.matchAll(/export\s+(?!type\b)\{([^}]*)\}/g)) {
for (const part of match[1].split(",")) {
const cleaned = part.trim();
if (!cleaned || /^type\s+/.test(cleaned)) continue;
const pieces = cleaned.split(/\s+as\s+/);
const exported = (pieces[1] ?? pieces[0]).trim();
if (exported) names.add(exported);
}
}
for (const match of stripped.matchAll(/export\s+(?:async\s+)?(?:function|const|let|var|class)\s+([A-Za-z_$][\w$]*)/g)) {
names.add(match[1]);
}
return names;
}

function readGitFile(root, ref, relPath) {
try {
return execFileSync("git", ["show", `${ref}:${relPath}`], {
cwd: root,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
});
} catch {
return null;
}
}

export function validateMorphRegistryCompat({ root = repoRoot } = {}) {
const morphManifestPath = join(root, "packages", "morph", "package.json");
const coreManifestPath = join(root, "packages", "core", "package.json");
const morphDistDir = join(root, "packages", "morph", "dist");
if (!existsSync(morphManifestPath) || !existsSync(coreManifestPath) || !existsSync(morphDistDir)) {
return [];
}
const coreVersion = JSON.parse(readFileSync(coreManifestPath, "utf8")).version;
const candidateRefs = [`v${coreVersion}`, "origin/main", "main"];
let baseRef = null;
for (const ref of candidateRefs) {
const baseCorePkgRaw = readGitFile(root, ref, "packages/core/package.json");
if (!baseCorePkgRaw) continue;
const baseCoreVersion = JSON.parse(baseCorePkgRaw).version;
if (baseCoreVersion === coreVersion) {
baseRef = ref;
break;
}
}
if (!baseRef) return [];

const baseCoreIndex = readGitFile(root, baseRef, "packages/core/src/index.ts");
if (!baseCoreIndex) return [];
const publishedCoreExports = collectBarrelValueExports(baseCoreIndex);

const errors = [];
const distJsFiles = readdirSync(morphDistDir).filter((f) => f.endsWith(".js")).sort();
for (const file of distJsFiles) {
const src = readFileSync(join(morphDistDir, file), "utf8");
const imported = extractNamedImportsFromDist(src, "@layoutit/polycss-core");
const missing = imported.filter((name) => !publishedCoreExports.has(name));
if (missing.length > 0) {
errors.push(
`@layoutit/polycss-morph: dist/${file} imports @layoutit/polycss-core symbol(s) missing from ${baseRef} (${coreVersion}): ${missing.join(", ")} (will fail morph test:package:registry in CI)`,
);
}
}
return errors;
}

export async function checkAllPublishablePacks({ root = repoRoot } = {}) {
const packagesRoot = resolve(root, "packages");
const pkgDirs = readdirSync(packagesRoot, { withFileTypes: true })
Expand Down Expand Up @@ -158,6 +245,7 @@ export async function checkAllPublishablePacks({ root = repoRoot } = {}) {
);

for (const item of checked) allErrors.push(...item.errors);
allErrors.push(...validateMorphRegistryCompat({ root }));
return {
ok: allErrors.length === 0,
checked: checked.map(({ errors: _e, ...rest }) => rest),
Expand Down
29 changes: 28 additions & 1 deletion .github/scripts/check-packs.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import test from "node:test";
import assert from "node:assert/strict";
import { collectDeclaredEntryPaths, validateTarballInventory } from "./check-packs.mjs";
import {
collectBarrelValueExports,
collectDeclaredEntryPaths,
extractNamedImportsFromDist,
validateTarballInventory,
} from "./check-packs.mjs";

test("collectDeclaredEntryPaths collects main, module, types, bin, exports, and typesVersions", () => {
const entries = collectDeclaredEntryPaths({
Expand Down Expand Up @@ -74,3 +79,25 @@ test("validateTarballInventory catches missing entries, missing README, unresolv
assert.ok(errors.some((e) => e.includes("unresolved workspace specifier")));
assert.ok(errors.some((e) => e.includes("test file leaked")));
});

test("extractNamedImportsFromDist and collectBarrelValueExports catch new core imports missing from published barrel", () => {
const distJs = 'import{crossVec as a,transformPointMat4 as b}from"@layoutit/polycss-core";';
const imported = extractNamedImportsFromDist(distJs, "@layoutit/polycss-core");
assert.deepEqual(imported, ["crossVec", "transformPointMat4"]);

const baseBarrel = `
export type { Vec3 } from "./types";
export { crossVec, type Foo, bar as baz } from "./math";
export const BASE_TILE = 50;
`;
const exported = collectBarrelValueExports(baseBarrel);
assert.equal(exported.has("crossVec"), true);
assert.equal(exported.has("baz"), true);
assert.equal(exported.has("BASE_TILE"), true);
assert.equal(exported.has("Foo"), false);
assert.equal(exported.has("transformPointMat4"), false);
assert.deepEqual(
imported.filter((name) => !exported.has(name)),
["transformPointMat4"],
);
});
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Public API is **mirrored** across React and Vue. Explicit `*/three` subpaths (`@
- `pnpm check:mirrors --require-base` — identical react↔vue files, 12 mirror sets covering all of `packages/{react,vue}/src`, per-pair & cross-lane-group diff parity against base ref, and fail-closed tamper-evident waivers (`.github/mirror-waivers.json`). Note: touch parity ≠ semantic parity.
- `pnpm check:exports` — React↔Vue root and `./three` barrel value/type export parity (block, direct, and namespace exports; fails closed on bare `export *`).
- `pnpm check:ir` — zero-browser cross-renderer DOM/CSS IR conformance across compiled `polycss`, `react`, and `vue` `dist/index.js` in `happy-dom` (real lighting/normal/albedo vars, baked paint, transforms, shadows, and `*/three`).
- `pnpm check:packs` — read-only parallel `pnpm pack` verification for all 7 publishable packages (all declared entries + `typesVersions` + `README.md`, zero `workspace:` leaks, zero test files).
- `pnpm check:packs` — read-only parallel `pnpm pack` verification for all 7 publishable packages (all declared entries + `typesVersions` + `README.md`, zero `workspace:` leaks, zero test files, plus zero-network `morph` registry-dependency export compatibility against the published `core` version).
- `pnpm check:readmes` and `pnpm check:skill` — shared README blocks and website skill sync.

## Backward compatibility & iterating on the system
Expand Down Expand Up @@ -86,6 +86,7 @@ Public API is **mirrored** across React and Vue. Explicit `*/three` subpaths (`@
- `pnpm bench:gate:lifecycle` — fail-closed Node SSR + Chromium lifecycle gate (`bench/lifecycle-gate.mjs`): verifies pure Node SSR (zero DOM globals), React `<StrictMode>` remounts and textured `<Poly>` blob URLs, `setOptions` / 3× rebake / `undefined` clears, real `.vox` class updates, stable-topology overrides, dynamic shadow emits, Vue async `src` single-mount, and controls interaction.
- Shared browser and `ffmpeg` discovery lives in `bench/browser-discovery.mjs`. Gate fail-closed invariants are unit-tested in `bench/{visual,perf,lifecycle}-gate.test.mjs` (`pnpm test:scripts`).
- **CI (`.github/workflows/ci.yml`)** runs `test-and-build` (`check:guards`, unified `test:coverage`, `build:packages`, `typecheck`, `check:packs`, `check:ir`, website/bench/examples), path-filtered PR `visual-gate` (Chromium + Firefox), `perf-gate` (paired A/B on Chromium), `lifecycle-gate` (Node SSR + Chromium), and `certify-domformat-browser` / `certify-gallery-domformat-corpus` (path-filtered on PRs, unconditional on `push: main`). `.github/workflows/publish-packages.yml` runs `check:guards`, `test`, `build:packages`, `typecheck`, `check:ir`, `check:packs`, and `morph test:package` before publishing.
- **Pre-push & dead-code hygiene:** Check `.github/workflows/ci.yml` path filters before editing peripheral packages (`packages/domformat` triggers the 45-minute `certify-domformat-browser` job; `packages/morph` is tested against npm-published `@layoutit/polycss-core` by `test:package:registry`). Always grep the entire repo including `.agents/` (e.g., `.agents/skills/chrome-trace/scripts/`) before deleting any export.

## Style / process

Expand Down
46 changes: 17 additions & 29 deletions bench/gate/cases.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* Declarative visual-gate test matrices and frame-locked iframe driver HTML.
*/
import { dirFromAzEl } from "../math.mjs";

export { dirFromAzEl };

export const DRIVER_HTML = `<!doctype html>
<html>
Expand Down Expand Up @@ -28,13 +31,6 @@ export const DRIVER_HTML = `<!doctype html>
</body>
</html>`;

export function dirFromAzEl(azDeg, elDeg) {
const az = (azDeg * Math.PI) / 180;
const el = (elDeg * Math.PI) / 180;
const cosEl = Math.cos(el);
return [cosEl * Math.sin(az), cosEl * Math.cos(az), Math.sin(el)];
}

export function lerpHexColor(t) {
// Smooth cycle across white -> pure red -> pure green -> pure blue -> white
const stops = [
Expand Down Expand Up @@ -429,17 +425,7 @@ export const VIDEO_ORACLE_CASES = [
bakedPage: "perf-react.html",
dynQuery: "mesh=chicken&mode=dynamic&motion=none&az=40&el=35&nohud=1",
bakedBaseQuery: "mesh=chicken&mode=baked&motion=none&az=40&el=35&nohud=1",
frame(k, n) {
const t = k / n;
const rx = 25 * Math.sin(t * Math.PI * 2);
const ry = t * 360;
const rz = 20 * Math.cos(t * Math.PI * 2);
return {
tag: `r=[${rx.toFixed(0)},${ry.toFixed(0)},${rz.toFixed(0)}]`,
msgs: [{ kind: "set-object", rotation: [rx, ry, rz] }],
bakedExtra: `orx=${rx.toFixed(3)}&ory=${ry.toFixed(3)}&orz=${rz.toFixed(3)}`,
};
},
frame: chickenTumbleFrame,
},
{
id: "video-oracle-chicken-tumble-vue",
Expand All @@ -448,16 +434,18 @@ export const VIDEO_ORACLE_CASES = [
bakedPage: "perf-vue.html",
dynQuery: "mesh=chicken&mode=dynamic&motion=none&az=40&el=35&nohud=1",
bakedBaseQuery: "mesh=chicken&mode=baked&motion=none&az=40&el=35&nohud=1",
frame(k, n) {
const t = k / n;
const rx = 25 * Math.sin(t * Math.PI * 2);
const ry = t * 360;
const rz = 20 * Math.cos(t * Math.PI * 2);
return {
tag: `r=[${rx.toFixed(0)},${ry.toFixed(0)},${rz.toFixed(0)}]`,
msgs: [{ kind: "set-object", rotation: [rx, ry, rz] }],
bakedExtra: `orx=${rx.toFixed(3)}&ory=${ry.toFixed(3)}&orz=${rz.toFixed(3)}`,
};
},
frame: chickenTumbleFrame,
},
];

function chickenTumbleFrame(k, n) {
const t = k / n;
const rx = 25 * Math.sin(t * Math.PI * 2);
const ry = t * 360;
const rz = 20 * Math.cos(t * Math.PI * 2);
return {
tag: `r=[${rx.toFixed(0)},${ry.toFixed(0)},${rz.toFixed(0)}]`,
msgs: [{ kind: "set-object", rotation: [rx, ry, rz] }],
bakedExtra: `orx=${rx.toFixed(3)}&ory=${ry.toFixed(3)}&orz=${rz.toFixed(3)}`,
};
}
19 changes: 19 additions & 0 deletions bench/math.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Zero-dependency math & statistics helpers shared between Node bench/gate
* scripts and browser bench pages.
*/
export function dirFromAzEl(azDeg, elDeg) {
const az = (azDeg * Math.PI) / 180;
const el = (elDeg * Math.PI) / 180;
const cosEl = Math.cos(el);
return [cosEl * Math.sin(az), cosEl * Math.cos(az), Math.sin(el)];
}

export function quantile(sorted, q) {
if (sorted.length === 0) return 0;
const i = (sorted.length - 1) * q;
const lo = Math.floor(i);
const hi = Math.ceil(i);
if (lo === hi) return sorted[lo];
return sorted[lo] + (sorted[hi] - sorted[lo]) * (i - lo);
}
10 changes: 1 addition & 9 deletions bench/perf-bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { fileURLToPath } from "node:url";
import { chromiumArgsWithGpuDefault } from "./chromium-defaults.mjs";
import { findCachedExecutable, launchBrowser } from "./browser-discovery.mjs";
import { startStaticServer } from "./http-server.mjs";
import { quantile } from "./math.mjs";

const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(__dirname, "..");
Expand Down Expand Up @@ -101,15 +102,6 @@ function startServer() {
}

// ── stats helpers ──────────────────────────────────────────────────────
function quantile(sorted, q) {
if (sorted.length === 0) return 0;
const i = (sorted.length - 1) * q;
const lo = Math.floor(i);
const hi = Math.ceil(i);
if (lo === hi) return sorted[lo];
return sorted[lo] + (sorted[hi] - sorted[lo]) * (i - lo);
}

function summarizeFrameTimes(dts, rawCount) {
const sample_count_raw = rawCount ?? dts.length;
if (dts.length === 0) return { fps_p50: 0, fps_p95: 0, frame_time_p50_ms: 0, frame_time_p95_ms: 0, frame_time_p99_ms: 0, sample_count: 0, sample_count_raw, sample_count_filtered: sample_count_raw, is_bimodal: false };
Expand Down
10 changes: 1 addition & 9 deletions bench/perf-gate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { dirname, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { startStaticServer } from "./http-server.mjs";
import { findCachedExecutable, launchBrowser } from "./browser-discovery.mjs";
import { quantile } from "./math.mjs";

const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(__dirname, "..");
Expand Down Expand Up @@ -202,15 +203,6 @@ export function parsePerfCliArgs(argv) {
return cfg;
}

function quantile(sorted, q) {
if (sorted.length === 0) return 0;
const i = (sorted.length - 1) * q;
const lo = Math.floor(i);
const hi = Math.ceil(i);
if (lo === hi) return sorted[lo];
return sorted[lo] + (sorted[hi] - sorted[lo]) * (i - lo);
}

export function summarizeFrameTimes(dts, rawCount = dts.length) {
if (dts.length === 0) {
return {
Expand Down
Loading
Loading