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
2 changes: 1 addition & 1 deletion .github/architecture/cross-package-and-mirrors.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ When you change `packages/polycss` or `packages/core` in a way that affects the

The DOM snapshot exporter is the current exception to mirrored React/Vue public exports: `exportPolySceneSnapshot` lives in `@layoutit/polycss` because it is browser DOM serialization, not component API. React/Vue callers import it from `@layoutit/polycss` and pass the rendered `.polycss-camera` / `.polycss-scene` element.

**Single renderer runtime.** All DOM/CSS rendering — the canvas atlas pipeline, browser feature detection, direct voxel renderer, shadow orchestrator, base stylesheet (`styles.ts`), render stats, and camera/control engines — lives once in `@layoutit/polycss` and is exported through the side-effect-free `@layoutit/polycss/runtime` subpath. React and Vue are thin Adopt-DOM bindings (`createPolyScene(..., { elements: { cameraEl, sceneEl } })`, `scene.add(..., { wrapper })`, `injectPolyBaseStyles` re-export) rather than parallel renderer implementations.
**Single renderer runtime.** All DOM/CSS rendering — the canvas atlas pipeline, browser feature detection, direct voxel renderer, shadow orchestrator, base stylesheet (`styles.ts`), render stats, and camera/control engines — lives once in `@layoutit/polycss`. Public imperative runtime APIs are exported through the side-effect-free `@layoutit/polycss/runtime` subpath, while lockstep adapter plumbing (gizmo/selection/hit-test/snapshot/standalone-mesh/leaf-descriptor helpers) is fenced behind `@layoutit/polycss/internal`. React and Vue are thin Adopt-DOM bindings (`createPolyScene(..., { elements: { cameraEl, sceneEl } })`, `scene.add(..., { wrapper })`, `injectPolyBaseStyles` re-export) rather than parallel renderer implementations.

**CI enforces this and the package boundaries.** `pnpm check:boundaries` (`.github/scripts/check-boundaries.mjs`) fails on any import that violates the package dependency boundaries in [AGENTS.md](../../AGENTS.md), on deep imports into another package's `src` (`DEEP_IMPORT_ALLOWLIST` is empty), and on node builtins outside the Node-only surfaces. It scans `.ts`/`.tsx`/`.mts`/`.cts` **and** `.mjs`/`.cjs`/`.js` sources (so the `packages/skills` CLI is covered). Specifiers are read by a single-pass **lexer**, not a regex over raw source, because pattern-matching is wrong in both directions: it misses valid imports (a comment between the keyword and the specifier, `import(\`x\`)`, a statement split across lines) and matches text that is not code (a commented-out import, an import-shaped string). The lexer skips comments, tracks single/double-quoted strings, template literals including `${}` nesting, and regex literals, and yields `import`/`export … from`, bare `import "x"`, `import()` and `require()` specifiers; a template WITH a substitution is not a static specifier and is ignored rather than crashed on. Quoted strings and regex literals may never span a newline, so a mis-lex in TSX (JSX apostrophes, `</div>`) recovers on the next line instead of swallowing code. The same allow-list is applied to each package's manifest: a `dependencies`, `optionalDependencies`, or `peerDependencies` entry outside the package's allow-list fails even when nothing imports it yet. `devDependencies` are tooling and are not constrained. The allow-list is applied to the RESOLVED dependency, not the manifest key, because the key is not what gets installed. Resolved forms: `npm:<name>[@range]` aliases; `link:`/`file:`/`portal:` local paths and `workspace:<path>` targets (both read through the target directory's own `package.json` name); and `workspace:<name>[@range]` aliases, versioned or not. So `"@layoutit/polycss-core": "npm:@layoutit/polycss-vue@0.2.0"`, `"workspace:@layoutit/polycss-vue"` and `"workspace:../vue"` all fail in React under the allowed key. Only bare ranges and dist-tags (`^0.2.0`, `*`, `latest`, `workspace:^`, `workspace:*`, `workspace:1.2.3`) leave the key standing. Everything else is a **violation, not a pass**: a local or workspace target whose manifest cannot be read, an empty or non-string specifier, and every form whose install target is not determinable from the repo — `catalog:` (the target lives in `pnpm-workspace.yaml`), git specs (`github:`/`gitlab:`/`bitbucket:`/`git+…`/the bare `owner/repo` shorthand), remote tarball URLs, `jsr:` (which installs under a rewritten `@jsr/…` name), and any unrecognised `protocol:`. Falling back to the key for an unresolvable specifier is exactly the bypass, so a package that needs one of those forms must declare it in a shape the checker can see through.

Expand Down
43 changes: 22 additions & 21 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`: **435 files**, **98,545 lines**. Regenerate with `pnpm map`; verified in CI by `pnpm check:map`.
Tracked production code scanned across `packages/*/src`, `bench/`, and `website/src`: **465 files**, **98,571 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` | — | 78 | 26,885 | 58 |
| `packages/core` (`@layoutit/polycss-core`) | npm | `., ./three` | — | 99 | 27,290 | 58 |
| `packages/domformat` (`@layoutit/polycss-domformat`) | private | `., ./browser` | — | 36 | 13,165 | 0 |
| `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/polycss` (`@layoutit/polycss`) | npm | `., ./runtime, ./internal, ./elements, ./three` | `@layoutit/polycss-core` | 73 | 16,933 | 41 |
| `packages/react` (`@layoutit/polycss-react`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 44 | 4,651 | 31 |
| `packages/skills` (`@layoutit/polycss-skills`) | npm | `.` | — | 1 | 415 | 1 |
| `packages/vue` (`@layoutit/polycss-vue`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 42 | 4,402 | 29 |
| `packages/vue` (`@layoutit/polycss-vue`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 42 | 4,437 | 29 |

## 2. Canonical Workspace Source Aliases

Expand All @@ -25,6 +25,7 @@ Single source of truth: [`packages/workspace-aliases.mjs`](../../packages/worksp
| `@layoutit/polycss-core/three` | `packages/core/src/three/index.ts` |
| `@layoutit/polycss-core` | `packages/core/src/index.ts` |
| `@layoutit/polycss/runtime` | `packages/polycss/src/runtime.ts` |
| `@layoutit/polycss/internal` | `packages/polycss/src/internal.ts` |
| `@layoutit/polycss/elements` | `packages/polycss/src/elements/index.ts` |
| `@layoutit/polycss/three` | `packages/polycss/src/three.ts` |
| `@layoutit/polycss` | `packages/polycss/src/index.ts` |
Expand All @@ -44,35 +45,35 @@ Single source of truth: [`packages/workspace-aliases.mjs`](../../packages/worksp

| Fan-in | Lines | File |
|---:|---:|---|
| 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` |
| 30 | 119 | `website/src/components/types.ts` |
| 18 | 218 | `packages/polycss/src/index.ts` |
| 18 | 88 | `website/src/components/GalleryWorkbench/types.ts` |
| 113 | 528 | `packages/core/src/index.ts` |
| 87 | 248 | `packages/core/src/types.ts` |
| 38 | 301 | `packages/react/src/index.ts` |
| 33 | 119 | `website/src/components/types.ts` |
| 29 | 148 | `packages/polycss/src/runtime.ts` |
| 22 | 220 | `packages/polycss/src/index.ts` |
| 20 | 57 | `packages/polycss/src/internal.ts` |
| 19 | 88 | `website/src/components/GalleryWorkbench/types.ts` |
| 17 | 49 | `packages/core/src/math/vec3.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,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,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,192 | `bench/visual-gate.mjs` |
| 1,178 | `packages/domformat/src/browser.ts` |
| 1,139 | `website/src/components/GalleryWorkbench/presets/presetFiles.ts` |
| 968 | `packages/polycss/src/snapshot/exportPolySceneSnapshot.ts` |
| 963 | `packages/core/src/atlas/plan.ts` |
| 912 | `bench/entries/lifecycle.tsx` |
| 910 | `website/src/components/GalleryWorkbench/GalleryWorkbench.tsx` |
| 885 | `packages/morph/src/contracts/validation.ts` |
| 860 | `packages/domformat/src/state/interaction.ts` |
| 840 | `packages/polycss/src/render/atlas/renderPolygons.ts` |

## 4. Core Render & Control Pipelines

Expand Down
19 changes: 16 additions & 3 deletions .github/scripts/check-boundaries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ export const PACKAGE_RULES = {
polycss: { allow: ["@layoutit/polycss-core"] },
react: {
allow: ["@layoutit/polycss-core", "@layoutit/polycss", "react", "react-dom"],
allowedSubpaths: { "@layoutit/polycss": ["@layoutit/polycss/runtime"] },
allowedSubpaths: {
"@layoutit/polycss": ["@layoutit/polycss/runtime", "@layoutit/polycss/internal"],
},
},
vue: {
allow: ["@layoutit/polycss-core", "@layoutit/polycss", "vue"],
allowedSubpaths: { "@layoutit/polycss": ["@layoutit/polycss/runtime"] },
allowedSubpaths: {
"@layoutit/polycss": ["@layoutit/polycss/runtime", "@layoutit/polycss/internal"],
},
},
fonts: { allow: ["@layoutit/polycss-core", "earcut"] },
morph: { allow: ["@layoutit/polycss", "@layoutit/polycss-core"] },
morph: {
allow: ["@layoutit/polycss", "@layoutit/polycss-core"],
allowedSubpaths: {
"@layoutit/polycss": ["@layoutit/polycss", "@layoutit/polycss/runtime"],
},
},
domformat: { allow: [] },
// The skill installer copies markdown with node builtins only; it must never
// pull a renderer in, or `npx polycss-skills` would install a whole engine.
Expand Down Expand Up @@ -655,6 +664,10 @@ function checkDeepImportsOutsidePackages(root, violations) {
violations.push(
`${rel}: deep import into a package's src: "${spec}"`,
);
} else if (spec === "@layoutit/polycss/internal") {
violations.push(
`${rel}: disallowed internal subpath "${spec}" (reserved for @layoutit/polycss-react and @layoutit/polycss-vue)`,
);
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions .github/scripts/check-boundaries.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,17 @@ test("plain ranges, dist-tags and workspace ranges keep the declared key", () =>
}
});

test("react and vue may only import @layoutit/polycss/runtime from @layoutit/polycss", () => {
test("react and vue may only import @layoutit/polycss/runtime and /internal from @layoutit/polycss", () => {
const okRoot = makeRepo(
withManifests({
"packages/react/src/ok.ts": 'import { createPolyScene } from "@layoutit/polycss/runtime";\ncreatePolyScene;\n',
"packages/vue/src/ok.ts": 'import { createPolyScene } from "@layoutit/polycss/runtime";\ncreatePolyScene;\n',
"packages/react/src/ok.ts":
'import { createPolyScene } from "@layoutit/polycss/runtime";\n' +
'import { createSelectionController } from "@layoutit/polycss/internal";\n' +
"createPolyScene; createSelectionController;\n",
"packages/vue/src/ok.ts":
'import { createPolyScene } from "@layoutit/polycss/runtime";\n' +
'import { createSelectionController } from "@layoutit/polycss/internal";\n' +
"createPolyScene; createSelectionController;\n",
}),
);
assert.deepEqual(runChecks(okRoot), []);
Expand All @@ -639,12 +645,16 @@ test("react and vue may only import @layoutit/polycss/runtime from @layoutit/pol
"packages/react/src/badRoot.ts": 'import { createPolyScene } from "@layoutit/polycss";\ncreatePolyScene;\n',
"packages/react/src/badEl.ts": 'import "@layoutit/polycss/elements";\n',
"packages/vue/src/badThree.ts": 'import { mountPolyThreeScene } from "@layoutit/polycss/three";\nmountPolyThreeScene;\n',
"packages/morph/src/badInternal.ts": 'import { createSelectionController } from "@layoutit/polycss/internal";\ncreateSelectionController;\n',
"website/src/badInternal.ts": 'import { createSelectionController } from "@layoutit/polycss/internal";\ncreateSelectionController;\n',
}),
);
const violations = runChecks(badRoot).sort();
assert.equal(violations.length, 3);
assert.match(violations[0], /badEl\.ts: disallowed subpath "@layoutit\/polycss\/elements"/);
assert.match(violations[1], /badRoot\.ts: disallowed subpath "@layoutit\/polycss"/);
assert.match(violations[2], /badThree\.ts: disallowed subpath "@layoutit\/polycss\/three"/);
assert.equal(violations.length, 5);
assert.match(violations[0], /badInternal\.ts: disallowed subpath "@layoutit\/polycss\/internal"/);
assert.match(violations[1], /badEl\.ts: disallowed subpath "@layoutit\/polycss\/elements"/);
assert.match(violations[2], /badRoot\.ts: disallowed subpath "@layoutit\/polycss"/);
assert.match(violations[3], /badThree\.ts: disallowed subpath "@layoutit\/polycss\/three"/);
assert.match(violations[4], /website\/src\/badInternal\.ts: disallowed internal subpath "@layoutit\/polycss\/internal"/);
cleanup(badRoot);
});
30 changes: 30 additions & 0 deletions .github/scripts/check-packs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,29 @@ export function validateTarballInventory(pkgName, packedManifest, tarEntries) {
return errors;
}

export function validateInternalSubpathContract(pkgName, packedManifest, distFiles) {
const errors = [];
let importsInternalJs = false;
for (const { name, content } of distFiles) {
const code = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
if (!code.includes("@layoutit/polycss/internal")) continue;
if (/\.d\.[cm]?ts$/.test(name)) {
errors.push(`${pkgName}: public declaration dist/${name} leaks "@layoutit/polycss/internal"`);
} else if (/\.[cm]?js$/.test(name)) {
importsInternalJs = true;
}
}
if (importsInternalJs) {
const polycssSpec = packedManifest.dependencies?.["@layoutit/polycss"];
if (typeof polycssSpec !== "string" || !/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(polycssSpec)) {
errors.push(
`${pkgName}: imports @layoutit/polycss/internal but packed dependency "@layoutit/polycss" is "${polycssSpec}" instead of an exact lockstep version (use "workspace:*")`,
);
}
}
return errors;
}

export function extractNamedImportsFromDist(jsSource, targetSpecifier) {
const escaped = targetSpecifier.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const re = new RegExp(`import\\s*\\{([^}]*)\\}\\s*from\\s*["']${escaped}["']`, "g");
Expand Down Expand Up @@ -234,6 +257,13 @@ export async function checkAllPublishablePacks({ root = repoRoot } = {}) {
const tarList = tarListOut.split("\n").filter(Boolean);
const packedManifest = JSON.parse(packedPkgJson);
const errors = validateTarballInventory(pkgName, packedManifest, tarList);
const distDir = join(dir, "dist");
if (existsSync(distDir)) {
const distFiles = readdirSync(distDir)
.filter((f) => /\.(?:d\.[cm]?ts|[cm]?js)$/.test(f))
.map((name) => ({ name, content: readFileSync(join(distDir, name), "utf8") }));
errors.push(...validateInternalSubpathContract(pkgName, packedManifest, distFiles));
}
return {
name: pkgName,
files: tarList.length,
Expand Down
25 changes: 25 additions & 0 deletions .github/scripts/check-packs.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
collectBarrelValueExports,
collectDeclaredEntryPaths,
extractNamedImportsFromDist,
validateInternalSubpathContract,
validateTarballInventory,
} from "./check-packs.mjs";

Expand Down Expand Up @@ -101,3 +102,27 @@ test("extractNamedImportsFromDist and collectBarrelValueExports catch new core i
["transformPointMat4"],
);
});

test("validateInternalSubpathContract rejects .d.ts leaks and non-exact lockstep dependencies", () => {
const ok = validateInternalSubpathContract(
"@layoutit/polycss-react",
{ dependencies: { "@layoutit/polycss": "0.3.0" } },
[
{ name: "chunk-abc.js", content: 'import { foo } from "@layoutit/polycss/internal";' },
{ name: "index.d.ts", content: 'export { pointInMeshElement } from "@layoutit/polycss/runtime";' },
],
);
assert.deepEqual(ok, []);

const bad = validateInternalSubpathContract(
"@layoutit/polycss-react",
{ dependencies: { "@layoutit/polycss": "^0.3.0" } },
[
{ name: "chunk-abc.js", content: 'import { foo } from "@layoutit/polycss/internal";' },
{ name: "index.d.ts", content: 'import { GizmoMode } from "@layoutit/polycss/internal";' },
],
);
assert.equal(bad.length, 2);
assert.ok(bad.some((e) => e.includes('public declaration dist/index.d.ts leaks "@layoutit/polycss/internal"')));
assert.ok(bad.some((e) => e.includes('instead of an exact lockstep version')));
});
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Monorepo layout (pnpm workspaces):
| Package | npm name | Role |
|---|---|---|
| `packages/core` | `@layoutit/polycss-core` | Pure math: Vec3, Polygon, scene, camera, mesh ops, atlas planning. Zero browser globals (`lib: ES2020` only). |
| `packages/polycss` | `@layoutit/polycss` | Single DOM/CSS renderer (`createPolyScene`, atlas, voxels, shadows, styles, controls) + custom elements (`<poly-scene>`, etc.) + side-effect-free `@layoutit/polycss/runtime` subpath. Depends on `core` only. |
| `packages/react` | `@layoutit/polycss-react` | Thin Adopt-DOM React components + hooks over `@layoutit/polycss/runtime`. Depends on `core` and `@layoutit/polycss/runtime`. |
| `packages/vue` | `@layoutit/polycss-vue` | Vue 3 mirror of React over `@layoutit/polycss/runtime`. Depends on `core` and `@layoutit/polycss/runtime`. |
| `packages/polycss` | `@layoutit/polycss` | Single DOM/CSS renderer (`createPolyScene`, atlas, voxels, shadows, styles, controls) + custom elements (`<poly-scene>`, etc.) + side-effect-free `@layoutit/polycss/runtime` public subpath and `@layoutit/polycss/internal` adapter-plumbing subpath. Depends on `core` only. |
| `packages/react` | `@layoutit/polycss-react` | Thin Adopt-DOM React components + hooks over `@layoutit/polycss/runtime` and `@layoutit/polycss/internal`. Depends on `core` and `@layoutit/polycss`. |
| `packages/vue` | `@layoutit/polycss-vue` | Vue 3 mirror of React over `@layoutit/polycss/runtime` and `@layoutit/polycss/internal`. Depends on `core` and `@layoutit/polycss`. |
| `packages/fonts` | `@layoutit/polycss-fonts` | Fonts + text → extruded 3D `Polygon[]`. Framework-agnostic. Depends on `core` + `earcut`. |
| `packages/morph` | `@layoutit/polycss-morph` | Framework-agnostic prepared-model contracts, Node preparation (`./prepare`), browser loading, retained DOM mounting, sparse deformation, skinning, and playback. No React/Vue mirrors. |
| `packages/domformat` | `@layoutit/polycss-domformat` | Private strict-TypeScript `domformat@0` writer, reader, validator, CLI, and browser mount. Producer-neutral wire contract. Not published. |
Expand Down
Loading
Loading