Brickheart-web project audit 06NOV2026
How this was produced: file lists and git ls-files, tsc, knip with explicit entry points, npm ls, grep for references, and a TypeScript-compiler-API script (scripts/_audit.mjs) that generated the per-file inventory at the bottom. Statements marked (inferred) come from signatures, comments and test names, not from reading the code. - Claude Sonnet 5.5
1. Overview
Three npm workspaces plus shared code, each deployed to Cloudflare (free plan) as a static-assets Worker from its own dist:
| area | purpose | build |
|---|---|---|
dev |
English-only dev blog and changelog | dev/build.mjs |
site |
static multilingual pages about the app and the data | site/build.mjs |
app |
offline-capable web app: Browse (SQLite) and Build (3D) | app/build.mjs |
shared |
engine/ (markdown, layout, paths, sitemap), assets/ (CSS, JS, brand, fonts), data/ (gitignored pack output) |
copied into each dist |
After cleanup: 77 code files, 7,892 lines (was 85 files, 8,198). The "TS project" is TypeScript only under app/src; build tooling is plain ESM .mjs. tsc checks app/src only, so scripts/*.ts and every .mjs file are unchecked.
Pattern worth keeping: scan.mjs and render.mjs are pure (return data or strings), build.mjs does the file writing, and each has *.test.mjs beside it. Tests: 58 root tests, 8 app query tests, 26 snap tests, all passing.
2. Module guide
App pages (app/src)
main.ts: the Browse page. Subject tiles, filters and a paged results table, querying SQLite throughdb-client. SQL strings come fromquery.ts(pure, unit-tested against the real database).build.ts(910 lines): the Build page. Three.js scene (init3d,makeTile), pack download (ensurePack), history, selection, MPD export and collision checks. Everything after line 240 is inside onestart()function (about 670 lines), so most handlers are nested closures. Largest refactor candidate.attach-ui.ts: part-picker UI (createPicker).
Workers and clients
db.worker.tsplusdb-client.ts: sql.js (WebAssembly SQLite) in a worker; the page talks to it by message. The worker also handles LDraw pack install and lookup.collide.worker.tspluscollide-client.ts: collision pack storage, collider cache and the collision scene. Requests run in arrival order.collide-client.tsanddb-client.tsare near-identical (samePending,failAll,onMessage), as are the two workers'describe/Handlerhelpers. A shared worker-client factory would remove about 100 lines.
LDraw (app/src/ldraw)
ldraw-store.ts: IndexedDB store. Files keyed by name and shared between subjects, plus per-subject membership rows. Install, remove, interrupted-install cleanup, andgetClosure(stems)to fetch a part's file set.ldraw-hook.ts: makes three.js's LDraw loader read from the offline store.geometry.ts,parts.ts: loader to geometry, rotation and matrix helpers.mpd.ts: MPD parsing (flattenMpdis deliberately kept for the planned MPD import).pack.ts: streaming reader for the indexed pack format (4-byte index length, JSON index, payload).
app/src/snap (inferred: a TypeScript port of the BrickAgent and BrickNet Python logic, tested against golden JSON from those projects)
names,catalog,agentdata,agentload: part and colour resolution, connector catalogue, data loading.joints,pairs,place,relate: connector compatibility, placement maths, relations and joint candidates.model:Assembly(attach, connectors, parts).graph,decode,path: BrickNet graph build, LDR text encode and decode, letter-ID path grammar.mat: matrix and quaternion helpers.collide: CVX1 collider parser and scene (the only specification of that binary format).errors: shared error classes.
Build tooling
app/build.mjs,render.mjs,render-build.mjs: per-language pages, js bundles via esbuild, service worker generation.tools/make-agent-bundle.mjsbuilds the trackeddata/agent/bundle.json.gzfrom SQLite.site:scanthenblocks(translatable text blocks, hashed) thentranslate/localizethenrender;root.mjsmakes the language picker, 404s and hreflang sitemap;tables.mjs,links.mjssupport content.dev:scan,render,config,buildfor the blog.scripts/build-sitemap.mjsis the rootbuild.
3. Offline path
Confirmed from the build output and precache list:
sw.jsis a template.build.mjsfills in the cache version and a precache list (39 files: shell pages, CSS, JS, workers, the sql.js wasm,rebrickable.db, the agent bundle, brand assets).- The large subject packs are not precached. They are fetched on demand.
From signatures and comments (inferred):
- "Make available offline" calls
requestPersistence, theninstallSubjectstreams a pack throughfetchPackandreadPackinto IndexedDB. The LDraw and collision stores each do this for their own pack type. Startup runscleanupInterruptedto discard half-finished installs. - Build page:
getClosuregets a part's file set,setOfflineFileshands it toldraw-hook, and three.js's loader reads from there instead of the network. Collision bins are read throughcollide-store.getBuffer. Verified from source: - The two stores use separate IndexedDB databases (
brickheart-ldraw,brickheart-collide), so they cannot clash. sw.jsis network-first with a cache fallback. It precaches the shell at install, stores each successful same-origin response, and serves from cache only when the network fails (ignoring the query string for navigations). It never touches range requests, non-GET requests, cross-origin requests, or/data/ldraw/and/data/collide/.- Gap: a page that was never precached or visited (for example
/zh/build/) fails offline with the browser error. There is no offline fallback page.
4. Data and collision pipeline (Python, not yet in the repo)
load_data_fat.pybuildsrebrickable.dbfrom Rebrickable CSVs,schema.sqland classification CSVs, applying the "alternative history" rules (v1 inventories, no minifigs or stickers, excluded themes, size 15-999, modern colour mapping, LDraw stem and collision bin must exist). Also writessite/data/colour-mapping.json.ldraw_bin_pack.py(two scripts in one file): read the DB, writesubject-N_dat.gzandsubject-N_bin.gzplus manifests toshared/data. Unfiltered pool is about 5k parts used in sets with both a DAT and a collision bin; the shipped packs hold 3,675 distinct parts after subject filters.- Collision bins are int16-quaternion files converted from
.cvx.objby another Python script (not yet in the repo). - Findings: hardcoded
/home/chinapal/...paths;ldraw_map.jsonandmissing_ldraw_parts.csvare cwd-relative; missing from the paste:ldraw_weight.py, thebricknetpackage,schema.sql;REWRITE_INVENTORY_PARTS = Falseinsidemain()is a local that shadows the module setting;normalize_part_numbersis defined twice; several stages are commented out; pack docstrings say JSONL but the code writes the indexed format; the two pack scripts duplicatenorm, the stem query and the manifest logic; no script records howapp/datais copied fromshared/data. - Plan: port to a TypeScript
tools/data/pipeline (better-sqlite3,zlib,crypto; the CIE Lab colour mapping is plain maths). Keep Python only for ground-truth fixtures. Compare decompressed contents and manifest counts, not.gzbytes. - Collision status: engine works; fixture parity is a known gap (84 of 6,000 cases outside tolerance), guarded by a test that fails above 100. The test skips itself when the gitignored loose bins are missing. Not investigated further by design.
5. i18n and settings (state and plan)
State:
bh-theme(cookie scoped to.brickheart.org, plus localStorage) is the shared setting mechanism.theme.jsreads it before first paint;picker.jsskips the picker for visitors who already chose a language.- The settings page does not exist for the app, so language and theme cannot yet be changed there. Site and app should share both settings.
- The app has no 404 page.
app/wrangler.jsoncsetsnot_found_handling: "404-page", butapp/disthas no404.html, so visitors get a bare 404. - The
zhBuild page is not generated (only the source language), so offline/zh/build/does not exist.zhBrowse does. - Translation has evolved. Today:
site/ui.json(English UI),site/translations/translations.json(keyed by folder, currentlyzhonly), gitignoredtodo.json,site/languages.json. App build-page strings are EnglishDEFAULTSinsideapp/render-build.mjs, overridden bybuild.*keys. The app importscfg,languagesanduifrom../site/config.mjs, so the app build depends on the site workspace. A language builds only when every UI string is translated.
Intended structure (from the project owner): separate files for UI strings and content, separate for site and app, and todo and translated files carrying the language code, so the site can host a page to download the en file and accept new language files. Suggested layout: site/i18n/{ui,content}/<lang>.json, app/i18n/ui/<lang>.json, todo.<lang>.json per language, languages.json moved to shared/, and the app's DEFAULTS moved into the app's en file.
6. Cleanup done, and recommendations
Done on branch audit-cleanup (commits):
- 4a44f06 app: added attach for axles and tires
- d01b34b blog: collision and attach
- 4435e74 WIP before audit
- 21713a8 Remove Vite starter leftovers
- 69494e6 Drop Vite and its internals, fix test script
- c8d0a38 Single page.js and picker.js in shared/assets
- 00d9622 Remove finished bench and sets-server experiments
- 6bee1a5 Remove unused ldraw/export.ts and duplicate tsx
- 17d7164 Drop unused exports and dead code; keep flattenMpd for MPD import
- ed0048e Remove finished joint-probe script
Also fixed along the way: the root npm test now runs the five snap tests it used to skip; the site now ships the cookie-aware picker.js; the app gets the shared page.js.
Recommended, not done:
- Nothing to do for the unused exports listed in the appendix: they are BrickNet and BrickAgent logic ported from Python for features not finished yet (see the note under that heading). Re-check once those features land.
- README for regenerating
shared/data,app/test-dataanddata/agent/bundle.json.gz, and for the Python pipeline. - Add a 404 page to the app build; add the
zhBuild page; finish the settings page. - Split
build.ts; extract a shared worker-client and IndexedDB-store base from the duplicated code. - Check Cloudflare's current per-file limit against
app/data/collide/subject-1_bin.gz(about 24 MB). - CSP is
script-src 'self'with no'wasm-unsafe-eval'. The app works in the owner's browser; verify in others. - Consider keeping the 12 MB
rebrickable.dband the packs out of git history (Git LFS or release artifacts). - Extend type-checking to
scripts/and the.mjsfiles (checkJs). - Fix the stale comments that name
ldraw_pack.py(the script isldraw_bin_pack.py) and the pack docstrings.
Appendix: generated inventory
Lists top-level declarations only. Nested functions (for example the handlers inside build.ts start()) are not shown. "UNUSED" means no importer in the repo; tests count as importers.
Audit of brickheart-web
77 code files, 7892 lines. Generated from git ls-files.
Files nothing imports
Entry points, scripts and copied assets show here legitimately. Files with no mentions anywhere are the strongest candidates.
| file | lines | mentioned in |
|---|---|---|
app/tools/make-agent-bundle.mjs |
50 | none |
scripts/collide-parity.ts |
32 | none |
app/src/main.ts |
206 | app/build.mjs |
scripts/build-sitemap.mjs |
24 | package.json |
app/src/build.ts |
910 | app/build.mjs, app/render-build.mjs |
app/src/collide.worker.ts |
125 | app/build.mjs, app/src/collide-client.ts |
app/src/db.worker.ts |
142 | app/build.mjs, app/src/db-client.ts |
app/src/sw.js |
43 | app/build.mjs, app/src/build.ts, app/src/main.ts |
shared/assets/js/page.js |
27 | dev/build.mjs, shared/engine/index.html, site/build.mjs, site/render.mjs |
shared/assets/js/picker.js |
51 | dev/build.mjs, site-build.md, site/build.mjs, site/root.mjs |
app/build.mjs |
229 | app/package.json, app/render-build.mjs, app/src/sw.js, dev/package.json |
dev/build.mjs |
64 | app/build.mjs, app/package.json, app/render-build.mjs, app/src/sw.js |
site/build.mjs |
125 | app/build.mjs, app/package.json, app/render-build.mjs, app/src/sw.js |
shared/assets/js/theme.js |
26 | app/build.mjs, app/render-build.mjs, app/render.mjs, dev/build.mjs |
Exports nobody imports
_Most of these are intentional: BrickNet/BrickAgent ports kept for unfinished functionality, so they are not removal candidates.
- app/src/attach-ui.ts: PickerHost
- app/src/ldraw/geometry.ts: PartGeom
- app/src/ldraw/mpd.ts: flattenMpd
- app/src/pack.ts: PackItem
- app/src/query.ts: Paging
- app/src/snap/agentdata.ts: AgentData
- app/src/snap/agentdata.ts: Derived
- app/src/snap/collide.ts: SceneItem
- app/src/snap/collide.ts: CheckResult
- app/src/snap/graph.ts: Adj
- app/src/snap/model.ts: Addresses
- app/src/snap/model.ts: AttachOpts
- app/src/snap/model.ts: Placed
- app/src/snap/pairs.ts: POS_THR
- app/src/snap/pairs.ts: AXIS_THR
- app/src/snap/pairs.ts: AXLE_AXIS_THR
- app/src/snap/pairs.ts: AXLE_PERP_THR
- app/src/snap/pairs.ts: AXLE_DEFAULT_RAD
- app/src/snap/pairs.ts: AXLE_QUERY_PAD
- app/src/snap/pairs.ts: FIXED_AXIS_THR
- app/src/snap/pairs.ts: FIXED_FRAME_TRACE
- app/src/snap/path.ts: ParseResult
- app/src/snap/relate.ts: Box
- app/src/snap/relate.ts: TargetPart
- site/tables.mjs: inkFor
- site/tables.mjs: parseSpec
Exports only tests import
- app/src/pack.ts: readPack
- app/src/query.ts: SUBJECT_IDS
- app/src/snap/decode.ts: decodeGraph
- app/src/snap/decode.ts: pyRound6
- app/src/snap/decode.ts: fmtG12
- app/src/snap/decode.ts: graphToLdr
- app/src/snap/graph.ts: parseLdr
- app/src/snap/graph.ts: connectionsFor
- app/src/snap/graph.ts: sampleTree
- app/src/snap/graph.ts: treeToGraph
- app/src/snap/mat.ts: toEngine
- app/src/snap/model.ts: Occurrence
- app/src/snap/model.ts: parts
- app/src/snap/model.ts: attachments
- app/src/snap/path.ts: Vocab
- app/src/snap/path.ts: id2i
- app/src/snap/path.ts: i2id
- app/src/snap/path.ts: serializeTree
- app/src/snap/path.ts: parseSample
- app/src/snap/place.ts: placement
- app/src/snap/relate.ts: worldBox
- site/blocks.mjs: hashOf
- site/blocks.mjs: splitBlocks
- site/translate.mjs: checkTranslation
- site/translate.mjs: mergeInbox
- site/translate.mjs: buildTodo
Internal declarations never referenced
none
Per-file inventory
app/build.mjs (229 lines)
Builds app/dist. One folder per language, each with browse/index.html.
- Imported by: nothing (entry point, script, or orphan)
- Packages: esbuild
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | here |
`` | 15 | internal | |
| const | root |
`` | 16 | internal | |
| const | dist |
`` | 17 | internal | |
| const | APP_BASE_URL |
`` | 19 | internal | |
| const | DB_SOURCE |
`` | 20 | internal | |
| const | MAX_FILE |
`` | 22 | const ENTRY = path.join(here, 'src/main.ts'); | internal |
| const | source |
`` | 26 | The translation store is read-only here: site/build.mjs owns writing it. | internal |
| const | STORE_FILE |
`` | 31 | internal | |
| const | store |
`` | 32 | internal | |
| const | current |
`` | 33 | internal | |
| const | translations |
`` | 34 | internal | |
| const | built |
`` | 36 | internal | |
| const | uiByFolder |
`` | 37 | internal | |
| const | sharedDir |
`` | 63 | Fresh dist: shared assets first (base.css, theme.js, fonts, brand), then app css on top. | internal |
| const | SKIP |
`` | 64 | internal | |
| function | keep |
(src) |
65 | internal | |
| const | headersFile |
`` | 72 | without 'unsafe-eval'. Fails the build if the shared policy changes shape. | internal |
| const | headers |
`` | 73 | internal | |
| const | loosened |
`` | 74 | internal | |
| const | AGENT_BUNDLE |
`` | 85 | BrickAgent attachment bundle | internal |
| function | copyPacks |
(name, { required }) |
101 | Offline packs. Only files named in a manifest are copied (never loose .bin files or fixtures). | internal |
| const | dbSize |
`` | 127 | internal | |
| const | ENTRIES |
`` | 166 | Browser scripts | internal |
| const | bundles |
`` | 172 | internal | |
| const | require |
`` | 189 | sql.js WASM: copy whichever .wasm files the bundles ask for (the name differs between sql.js versions) | internal |
| const | sqlDist |
`` | 190 | internal | |
| const | wasmFiles |
`` | 191 | internal | |
| const | copied |
`` | 192 | internal |
app/render-build.mjs (214 lines)
Renders the Build page. Pure: writes nothing. English defaults until the keys are in ui.json.
- Imported by: app/build.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DEFAULTS |
`` | 5 | internal | |
| const | SCENE |
`` | 116 | internal | |
| const | MOVE |
`` | 117 | internal | |
| const | CAMERA |
`` | 118 | internal | |
| function | renderBuild |
(lang, ui, { siteName, baseUrl, siteHome }) |
120 | build.mjs |
app/render.mjs (135 lines)
Renders the Browse page for one language. Pure: writes nothing.
- Imported by: app/build.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | PAGE_SIZES |
`` | 5 | internal | |
| const | BROWSE_DEFAULTS |
`` | 6 | internal | |
| function | renderBrowse |
(lang, ui, { siteName, baseUrl, siteHome }) |
12 | build.mjs |
app/src/attach-ui.ts (117 lines)
- Imported by: app/src/build.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| type | Vars |
`` | 5 | internal | |
| type | Rank |
`` | 6 | build.ts | |
| interface | PickerHost |
`` | 7 | UNUSED | |
| interface | Picker |
`` | 16 | build.ts | |
| function | createPicker |
(host: PickerHost): Picker |
18 | build.ts |
app/src/build.ts (910 lines)
- Imported by: nothing (entry point, script, or orphan)
- Packages: three
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | DbRow |
`` | 16 | internal | |
| interface | Row |
`` | 20 | internal | |
| type | Op |
`` | 37 | internal | |
| interface | Placed |
`` | 44 | internal | |
| const | strings |
`` | 46 | internal | |
| function | t |
(key: string, v: Record<string, string | number> = {}): string |
47 | internal | |
| function | el |
(id: string): T |
50 | internal | |
| function | query |
(sql: string, params: (string | number)[]): Promise<T[]> |
56 | internal | |
| const | ROWS_SQL |
`` | 59 | internal | |
| function | pad4 |
(n: number) |
73 | ---- Label: #1234 color_family.colorID part_name ---- | internal |
| function | partName |
(s: string) |
74 | internal | |
| const | STRIDE |
`` | 75 | internal | |
| function | seedOf |
(setNum: string): number |
76 | internal | |
| function | ensurePack |
(root: string, subject: number): Promise<void> |
83 | ---- Pack ---- | internal |
| const | CELL |
`` | 117 | ---- 3D ---- | internal |
| const | PITCH |
`` | 117 | ---- 3D ---- | internal |
| const | HI_Z |
`` | 117 | ---- 3D ---- | internal |
| const | STUD |
`` | 118 | internal | |
| const | PLATE |
`` | 118 | internal | |
| const | BRICK |
`` | 118 | internal | |
| const | FLOOR |
`` | 119 | internal | |
| const | WALL_Z |
`` | 120 | internal | |
| function | init3d |
(stage: HTMLElement) |
122 | internal | |
| function | makeTile |
(row: Row): Promise<THREE.Group | null> |
199 | internal | |
| const | RY |
`` | 229 | Quarter turn about the vertical axis, applied to the LDraw matrix (same as the bench). | internal |
| const | RX |
`` | 231 | Quarter turn about a horizontal axis. | internal |
| function | mul |
(a: number[], b: number[]) |
232 | internal | |
| function | start |
(): Promise<void> |
240 | internal |
app/src/collide-client.ts (50 lines)
Page-side client for collide.worker.ts. Same protocol as db-client.ts.
- Imported by: app/src/build.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | Pending |
`` | 2 | Page-side client for collide.worker.ts. Same protocol as db-client.ts. | internal |
| const | w |
`` | 4 | internal | |
| const | n |
`` | 5 | internal | |
| const | pending |
`` | 6 | internal | |
| function | failAll |
(err: Error): void |
8 | internal | |
| function | onMessage |
({ data }: MessageEvent): void |
13 | internal | |
| function | startCollide |
(root: string): void |
23 | build.ts | |
| function | collide |
(op: string, args: unknown, o: { onProgress?: (p: any) => void; signal?: AbortSignal } = {}): Promise<T> |
32 | build.ts |
app/src/collide-store.ts (117 lines)
IndexedDB store for collision packs. Mirrors ldraw-store.ts; values are raw CVX1 buffers.
- Imported by: app/src/collide.worker.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DB_NAME |
`` | 6 | internal | |
| const | DB_VERSION |
`` | 7 | internal | |
| interface | SubjectRow |
`` | 9 | internal | |
| const | dbPromise |
`` | 11 | internal | |
| function | openDb |
(): Promise<IDBDatabase> |
12 | internal | |
| function | rq |
(r: IDBRequest<T>) |
26 | internal | |
| function | txDone |
(tx: IDBTransaction) |
28 | internal | |
| function | subjectRange |
(id: number) |
34 | internal | |
| function | isInstalled |
(id: number): Promise<boolean> |
36 | collide.worker.ts | |
| function | getBuffer |
(stem: string): Promise<ArrayBuffer | null> |
43 | The stored buffer is exactly the .bin bytes, so typed-array offsets are aligned. | collide.worker.ts |
| function | removeSubject |
(id: number): Promise<void> |
50 | collide.worker.ts | |
| function | cleanupInterrupted |
(): Promise<number[]> |
70 | collide.worker.ts | |
| function | installSubject |
(id: number, opts: InstallOptions): Promise<void> |
78 | collide.worker.ts |
app/src/collide.worker.ts (125 lines)
Owns collision pack storage, the collider cache and the scene. The page talks to it via collide-client.ts.
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| type | Rank |
`` | 8 | internal | |
| interface | PartIn |
`` | 9 | internal | |
| interface | Cur |
`` | 10 | internal | |
| const | ctx |
`` | 12 | internal | |
| const | scene |
`` | 17 | internal | |
| const | memo |
`` | 18 | internal | |
| const | cur |
`` | 19 | internal | |
| const | latestRank |
`` | 20 | internal | |
| const | latestCheck |
`` | 20 | internal | |
| const | installing |
`` | 21 | internal | |
| const | aborts |
`` | 22 | internal | |
| function | collider |
(stem: string): Promise<Collider | null> |
24 | internal | |
| function | tick |
() |
32 | internal | |
| type | Post |
`` | 34 | internal | |
| type | Handler |
`` | 35 | internal | |
| const | queue |
`` | 38 | sync / check / rank run strictly in arrival order. Installs and lookups do not wait for them. | internal |
| function | serial |
(h: Handler): Handler |
39 | internal | |
| const | handlers |
`` | 45 | internal | |
| function | describe |
(err: unknown): { name: string; message: string } |
105 | internal |
app/src/db-client.ts (77 lines)
src/db-client.ts
- Imported by: app/src/build.ts, app/src/main.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | Pending |
`` | 9 | internal | |
| const | w |
`` | 16 | internal | |
| const | n |
`` | 17 | internal | |
| const | pending |
`` | 18 | internal | |
| function | failAll |
(err: Error): void |
20 | internal | |
| function | onMessage |
({ data }: MessageEvent): void |
25 | internal | |
| function | startDb |
(root: string): Promise<void> |
40 | Starts the worker and sends it the absolute base URL. root is the page's relative prefix, e.g. "../" or "/". |
build.ts, main.ts |
| function | call |
(op: string, args: unknown, o: { onProgress?: (p: any) => void; signal?: AbortSignal } = {}): Promise<T> |
50 | build.ts | |
| function | run |
(b: Built): Promise<T[]> |
76 | Runs a Built query from query.ts. Rows are plain objects keyed by column name. | main.ts |
app/src/db.worker.ts (142 lines)
src/db.worker.ts
- Imported by: nothing (entry point, script, or orphan)
- Packages: sql.js
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| type | Param |
`` | 12 | internal | |
| type | Post |
`` | 13 | internal | |
| type | Handler |
`` | 14 | internal | |
| const | ctx |
`` | 17 | Minimal typing so this file compiles without adding the "webworker" lib to tsconfig. | internal |
| const | base |
`` | 24 | Set once by the "init" op. Absolute, ends with "/", e.g. https://app.brickheart.org/ | internal |
| function | urlFor |
(path: string): string |
26 | internal | |
| const | dbP |
`` | 32 | ---- sql.js ---- | internal |
| function | loadDb |
(): Promise<Database> |
34 | internal | |
| function | getDb |
(): Promise<Database> |
42 | internal | |
| const | aborts |
`` | 54 | Install requests are keyed by request id so "cancel" can find the right AbortController. | internal |
| const | installing |
`` | 55 | internal | |
| const | handlers |
`` | 58 | ---- Operations ---- | internal |
| function | describe |
(err: unknown): { name: string; message: string } |
117 | ---- Message loop ---- | internal |
app/src/ldraw/geometry.ts (98 lines)
- Imported by: app/src/build.ts, app/src/ldraw/parts.ts
- Packages: three
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | BASE |
`` | 6 | internal | |
| const | loaderP |
`` | 7 | internal | |
| function | getLoader |
(): Promise<LDrawLoader> |
10 | Reference E(): URL rewrite hook, library path, preloaded materials. | internal |
| function | load |
(l: LDrawLoader, url: string) |
28 | internal | |
| const | groupCache |
`` | 32 | Reference k(): no packed files yet, so parts/ then p/. | internal |
| function | loadPartGroup |
(id: string): Promise<THREE.Group> |
33 | internal | |
| function | releaseGroups |
(): void |
47 | Drops the parsed Groups. geomCache holds the merged geometry the renderer uses. | build.ts |
| const | matCache |
`` | 50 | Reference x() | internal |
| function | getColorMaterial |
(code: number) |
51 | build.ts, parts.ts | |
| interface | PartGeom |
`` | 60 | Reference A(): merge triangles and edges, flip 180° about X, cache by part id. | UNUSED |
| const | geomCache |
`` | 61 | internal | |
| function | getPartGeometry |
(id: string): Promise<PartGeom> |
62 | build.ts, parts.ts |
app/src/ldraw/ldraw-hook.ts (42 lines)
- Imported by: app/src/build.ts
- Packages: three
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | BASE |
`` | 4 | internal | |
| const | PREFIX |
`` | 5 | internal | |
| const | files |
`` | 7 | internal | |
| const | installed |
`` | 8 | internal | |
| function | setOfflineFiles |
(m: Map<string, string> | null) |
11 | Replace the served files. Safe to call per set; the loader itself is built once. | build.ts |
| function | installFileLoaderHook |
() |
13 | build.ts |
app/src/ldraw/ldraw-store.ts (214 lines)
Offline LDraw store. Files are keyed by name and shared across subjects (option B).
- Imported by: app/src/build.ts, app/src/collide-store.ts, app/src/collide.worker.ts, app/src/db.worker.ts, app/src/ldraw/ldraw-hook.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DB_NAME |
`` | 6 | internal | |
| const | DB_VERSION |
`` | 7 | internal | |
| interface | FileRow |
`` | 9 | internal | |
| interface | MemberRow |
`` | 10 | internal | |
| interface | SubjectRow |
`` | 11 | internal | |
| interface | InstallOptions |
`` | 19 | collide-store.ts, collide.worker.ts, db.worker.ts | |
| function | normalise |
(name: string): string |
28 | Lowercase, backslash to slash, strip a leading ./ then one leading parts/ or p/. Matches ldraw_pack.py. | collide-store.ts, db.worker.ts, ldraw-hook.ts |
| const | dbPromise |
`` | 39 | ---- IndexedDB plumbing ---- | internal |
| function | openDb |
(): Promise<IDBDatabase> |
41 | internal | |
| function | rq |
(r: IDBRequest<T>) |
57 | internal | |
| function | txDone |
(tx: IDBTransaction) |
60 | internal | |
| function | subjectRange |
(id: number) |
67 | internal | |
| function | requestPersistence |
(): Promise<boolean> |
72 | Call from the "Make available offline" tap handler, before installSubject. | build.ts, db.worker.ts |
| function | isInstalled |
(id: number): Promise<boolean> |
82 | db.worker.ts | |
| function | listStems |
(id: number): Promise<string[]> |
90 | Names of the part stems (r = 1) in an installed subject, sorted. | db.worker.ts |
| function | removeSubject |
(id: number): Promise<void> |
101 | Deletes the subject's membership rows, then each file that no other subject lists. | db.worker.ts |
| function | cleanupInterrupted |
(): Promise<number[]> |
123 | Run once at startup: removes any install that was interrupted. | db.worker.ts |
| function | installSubject |
(id: number, opts: InstallOptions): Promise<void> |
131 | db.worker.ts | |
| function | getClosure |
(stems: string[], alwaysInclude: string[] = ['ldconfig.ldr']): Promise<{ files: Map<string, string>; missing: Set<string> }> |
184 | db.worker.ts |
app/src/ldraw/mpd.ts (64 lines)
- Imported by: app/src/build.ts, app/src/ldraw/parts.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | PartRecord |
`` | 1 | build.ts, parts.ts | |
| function | norm |
(s: string) |
8 | internal | |
| function | mul |
(a: number[], b: number[]): number[] |
9 | internal | |
| function | flattenMpd |
(text: string): PartRecord[] |
20 | Reserved: MPD import, not wired up yet. | UNUSED |
app/src/ldraw/parts.ts (100 lines)
- Imported by: app/src/build.ts
- Packages: three
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | engineRotFromLdraw |
(m: number[]): number[] |
8 | INFERRED, not read from the reference (2fmu4y60objlb.js ~165-187). | internal |
| function | composeMatrix |
(obj: THREE.Object3D, rec: PartRecord) |
14 | Reference h() = composeMatrix, record-with-matrix branch only. | internal |
| const | token |
`` | 28 | internal | |
| function | renderParts |
(partsGroup: THREE.Group, parts: PartRecord[], selected: Set<number>, showEdges = true) |
32 | selected bricks get their own emissive mesh, clear+refill only at the end. | build.ts |
app/src/main.ts (206 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | Subject |
`` | 7 | internal | |
| interface | Format |
`` | 8 | internal | |
| interface | Range |
`` | 9 | internal | |
| interface | SetRow |
`` | 10 | internal | |
| const | strings |
`` | 13 | Strings for this language, embedded in the page by the build. | internal |
| function | t |
(key: string): string |
14 | internal | |
| function | fill |
(text: string, values: Record<string, string>): string |
15 | internal | |
| const | pageLang |
`` | 18 | internal | |
| const | numbers |
`` | 19 | internal | |
| function | markEnglish |
(node: HTMLElement): void |
21 | Database text is English only: mark it so screen readers pronounce it correctly. | internal |
| function | el |
(id: string): T |
25 | internal | |
| function | all |
(q: Built): Promise<T[]> |
31 | internal | |
| function | fail |
(error: unknown): void |
33 | internal | |
| function | cell |
(tag: 'th' | 'td', text: string, className = ''): HTMLTableCellElement |
38 | internal | |
| function | showTiles |
(subjects: Subject[]): void |
46 | internal | |
| function | showBrowser |
(subjects: Subject[], initialSubject: number): Promise<void> |
60 | internal | |
| function | start |
(): Promise<void> |
186 | internal |
app/src/pack.ts (64 lines)
Streaming reader for indexed packs:
- Imported by: app/src/collide-store.ts, app/src/ldraw/ldraw-store.ts, app/src/snap/collide.test.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | PackEntry |
`` | 5 | Entries are yielded in offset order, one at a time, so memory stays small. | internal |
| interface | PackItem |
`` | 6 | UNUSED | |
| class | Bytes |
`` | 8 | internal | |
| method | Bytes.constructor |
(r: ReadableStreamDefaultReader<Uint8Array>) |
12 | ||
| method | Bytes.take |
(n: number): Promise<Uint8Array> |
14 | Exactly n bytes in a fresh, exactly-sized buffer (byteOffset 0). | |
| function | readPack |
(stream: ReadableStream<Uint8Array>): AsyncGenerator<PackItem> |
35 | stream is the already-decompressed byte stream. |
tests only |
| function | fetchPack |
(url: string, o: { signal?: AbortSignal; onCompressed?: (bytes: number) => void } = {}): AsyncGenerator<PackItem> |
53 | collide-store.ts, ldraw-store.ts |
app/src/query.test.mjs (77 lines)
- Imported by: nothing (entry point, script, or orphan)
- Packages: better-sqlite3
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DB_FILE |
`` | 36 | Against the real database (same SQL the browser runs) | internal |
| const | hasDb |
`` | 37 | internal | |
| const | db |
`` | 38 | internal | |
| function | run |
(q) |
39 | internal | |
| const | skip |
`` | 40 | internal |
app/src/query.ts (102 lines)
SQL for the Browse page. Pure: builds strings and parameters, runs nothing.
- Imported by: app/src/db-client.ts, app/src/main.ts, app/src/query.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | SUBJECT_IDS |
`` | 3 | Only subjects 1 to 3 are shown; sets with Unknown or no subject are left out. | tests only |
| interface | BrowseFilters |
`` | 5 | main.ts | |
| interface | Paging |
`` | 14 | UNUSED | |
| interface | Built |
`` | 19 | db-client.ts, main.ts | |
| function | int |
(value: number, name: string): number |
24 | internal | |
| function | subject |
(value: number): number |
29 | internal | |
| function | where |
(f: BrowseFilters): { clause: string; params: number[] } |
36 | internal | |
| function | subjectsQuery |
(): Built |
55 | The subjects shown as tiles and in the Subject select. | main.ts |
| function | rangeQuery |
(subjectId: number): Built |
63 | Default values for the year and parts inputs. | main.ts |
| function | formatsQuery |
(subjectId: number): Built |
72 | Formats that actually occur in this subject. | main.ts |
| function | countQuery |
(f: BrowseFilters): Built |
82 | main.ts | |
| function | pageQuery |
(f: BrowseFilters, paging: Paging): Built |
87 | main.ts |
app/src/snap/agent.test.ts (137 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | rd |
(p: string): any |
14 | internal | |
| const | B |
`` | 15 | internal | |
| const | A |
`` | 15 | internal | |
| const | golden |
`` | 22 | internal | |
| function | close |
(a: number, b: number) |
24 | internal | |
| function | poseDiff |
(got: readonly number[], want: readonly number[]): string | null |
25 | internal | |
| type | Err |
`` | 29 | internal | |
| function | classify |
(e: unknown): Err |
30 | internal | |
| function | sameErr |
(got: Err, want: Err) |
36 | KeyError text is Python repr-formatted, so only its class is compared. | internal |
| function | report |
(bad: string[]) |
37 | internal | |
| interface | Ref |
`` | 84 | internal | |
| interface | Step |
`` | 85 | internal | |
| function | run |
(steps: Step[]) |
90 | internal |
app/src/snap/agentdata.ts (52 lines)
- Imported by: app/src/snap/agent.test.ts, app/src/snap/agentload.ts, app/src/snap/joints.ts, app/src/snap/model.ts, app/src/snap/names.ts, app/src/snap/relate.test.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | Seating |
`` | 3 | agentload.ts | |
| interface | AgentData |
`` | 8 | UNUSED | |
| interface | Derived |
`` | 18 | UNUSED | |
| const | current |
`` | 25 | internal | |
| const | derivedOf |
`` | 26 | internal | |
| function | setAgentData |
(d: AgentData): void |
28 | agentload.ts | |
| function | data |
(): AgentData |
29 | joints.ts, model.ts, names.ts | |
| function | cache |
(): Derived |
33 | joints.ts, names.ts | |
| function | own |
(o: Record<string, T>, k: string): T | undefined |
39 | joints.ts, names.ts | |
| function | fetchJson |
(url: string): Promise<T> |
42 | Browser loader. .json.gz goes through DecompressionStream (xz is not available in browsers). |
agentload.ts |
| function | toRecord |
(x: Record<string, T> | readonly (readonly [string, T])[]): Record<string, T> |
50 | Accepts {key: value} or an ordered list of [key, value] pairs (the test-data form). | agentload.ts |
app/src/snap/agentload.ts (20 lines)
- Imported by: app/src/build.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | Bundle |
`` | 6 | internal | |
| function | loadAgentBundle |
(url: string): Promise<void> |
13 | Fetch the filtered BrickNet + BrickAgent tables and install them. | build.ts |
app/src/snap/catalog.ts (131 lines)
- Imported by: app/src/snap/agent.test.ts, app/src/snap/agentdata.ts, app/src/snap/agentload.ts, app/src/snap/decode.test.ts, app/src/snap/decode.ts, app/src/snap/graph.test.ts, app/src/snap/graph.ts, app/src/snap/joints.ts, app/src/snap/pairs.ts, app/src/snap/path.ts, app/src/snap/relate.test.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | Kind |
`` | 3 | graph.ts, joints.ts, pairs.ts | |
| type | Kind |
`` | 12 | graph.ts, joints.ts, pairs.ts | |
| const | KIND_NAMES |
`` | 13 | graph.ts, joints.ts | |
| const | KIND_BY_NAME |
`` | 14 | internal | |
| type | Family |
`` | 15 | graph.ts | |
| const | STUD_SUBS |
`` | 17 | graph.ts, path.ts | |
| const | AXLE_SUBS |
`` | 18 | graph.ts, path.ts | |
| const | SUB_ENC |
`` | 19 | internal | |
| const | N_SUBS |
`` | 23 | pairs.ts | |
| function | subEnc |
(s: string): number |
24 | internal | |
| const | STUD_MATES |
`` | 32 | joints.ts, path.ts | |
| const | AXLE_MATES |
`` | 33 | joints.ts, path.ts | |
| function | mateMat |
(pairs: [string, string][]): boolean[][] |
34 | internal | |
| const | STUD_MATE_MAT |
`` | 39 | pairs.ts | |
| const | AXLE_MATE_MAT |
`` | 40 | pairs.ts | |
| type | Rows |
`` | 42 | internal | |
| type | Labels |
`` | 43 | agentload.ts | |
| interface | AliasRow |
`` | 44 | agentload.ts | |
| interface | Conn |
`` | 46 | graph.ts, pairs.ts | |
| interface | PartInfo |
`` | 53 | joints.ts, pairs.ts | |
| function | flatKey |
(sub: string, pol: string | null, idx: number) |
54 | graph.ts | |
| function | connFrame |
(row: number[], kind: string): M |
57 | data.py::_load_all_connectors frame maths. row = [x, y, z, pitch°, roll°, (yaw° for fixed axle length)] | internal |
| function | buildPart |
(stem: string, kinds: Labels[string]): PartInfo |
72 | Canonical order: sorted(kind), sorted(sub), sorted(pol), row order. | internal |
| class | Catalog |
`` | 102 | agentdata.ts, agentload.ts, decode.ts, graph.ts, path.ts | |
| method | Catalog.constructor |
(labels: Labels, aliases: AliasRow[] | { rows: AliasRow[] } = []) |
107 | ||
| method | Catalog.has |
(stem: string) |
114 | ||
| method | Catalog.aliasDst |
(stem: string): string |
116 | The alias target of stem, or stem itself. No vocabulary check (brickagent catalog._stem). |
|
| method | Catalog.part |
(stem: string): PartInfo |
117 | ||
| method | Catalog.resolve |
(stem: string): { stem: string; wrap: M | null } | null |
126 | parse_ldr's alias step: T_new = T_part @ wrap. null if the (aliased) stem is out of vocabulary. |
app/src/snap/collide.test.ts (110 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | cube |
(half: number): Collider |
8 | ---- synthetic data ---- | internal |
| function | at |
(x: number) |
18 | internal | |
| function | makePack |
(files: Record<string, Uint8Array>): Uint8Array |
54 | ---- pack reader ---- | internal |
| function | chunked |
(b: Uint8Array, k: number) |
66 | internal | |
| const | DIR |
`` | 87 | ---- fixture parity (needs the loose bins, which are gitignored) ---- | internal |
app/src/snap/collide.ts (290 lines)
- Imported by: app/src/collide.worker.ts, app/src/snap/collide.test.ts, scripts/collide-parity.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | TAU |
`` | 3 | collide-parity.ts | |
| const | MARGIN |
`` | 4 | internal | |
| const | CELL |
`` | 5 | internal | |
| const | stats |
`` | 7 | collide-parity.ts | |
| type | V |
`` | 9 | internal | |
| interface | Collider |
`` | 12 | ---------------------------------------------------------------- pack format (CVX1) | collide.worker.ts, collide-parity.ts |
| function | parseCollider |
(buf: ArrayBuffer): Collider |
17 | collide.worker.ts, collide-parity.ts | |
| interface | World |
`` | 36 | ---------------------------------------------------------------- world-space hulls | internal |
| function | toWorld |
(c: Collider, m: M): World |
38 | internal | |
| function | sub |
(a: V, b: V): V |
64 | ---------------------------------------------------------------- GJK + EPA on vertex sets | internal |
| function | dot |
(a: V, b: V) |
65 | internal | |
| function | neg |
(a: V): V |
66 | internal | |
| function | cross |
(a: V, b: V): V |
67 | internal | |
| function | perp |
(a: V): V |
68 | internal | |
| interface | Hull |
`` | 70 | internal | |
| function | support |
(h: Hull, d: V): V |
72 | internal | |
| function | mink |
(a: Hull, b: Hull, d: V): V |
80 | internal | |
| function | line |
(s: V[]): V |
83 | Simplex s is newest-first. Each step may shrink s and returns the next direction. | internal |
| function | triangle |
(s: V[]): V |
92 | internal | |
| function | tetra |
(s: V[]): V | null |
101 | internal | |
| function | gjk |
(A: Hull, B: Hull): V[] | null | 'fail' |
110 | Tetrahedron enclosing the origin; null if separated; 'fail' if inconclusive. | internal |
| interface | Face |
`` | 127 | internal | |
| function | face |
(pts: V[], a: number, b: number, c: number): Face | null |
128 | internal | |
| function | epa |
(simplex: V[], A: Hull, B: Hull, fallback: number): number |
137 | internal | |
| function | penetration |
(A: Hull, B: Hull, fallback: number): number |
165 | Penetration depth of two convex vertex sets; 0 when separated. fallback = AABB overlap bound. |
internal |
| interface | Clock |
`` | 173 | ---------------------------------------------------------------- part vs part | internal |
| function | inRegion |
(w: World, lo: V, hi: V): number[] |
175 | internal | |
| function | maxDepth |
(a: World, b: World, floor: number, stop: boolean, clk?: Clock): number |
187 | Deepest hull-pair penetration above floor (else floor). stop=true returns at the first pair above |
internal |
| function | pairDepth |
(ca: Collider, ma: M, cb: Collider, mb: M, floor = 0): number |
212 | Deepest penetration between two placed parts (floor 0 gives the full depth). For tests. | collide-parity.ts |
| interface | Entry |
`` | 217 | ---------------------------------------------------------------- scene | internal |
| interface | SceneItem |
`` | 218 | UNUSED | |
| interface | CheckResult |
`` | 219 | UNUSED | |
| function | boxAabb |
(b: number[], m: M): [V, V] |
221 | internal | |
| class | CollisionScene |
`` | 233 | Collision world. replace swaps in the full part list; entries whose key is unchanged keep |
collide.worker.ts |
| method | CollisionScene.constructor |
(tau = TAU) |
237 | ||
| method | CollisionScene.cells |
(lo: V, hi: V): string[] |
241 | ||
| method | CollisionScene.replace |
(items: SceneItem[]): void |
249 | Scene indices afterwards match the order of items. Key must change when stem or pose does. |
|
| method | CollisionScene.check |
(pose: M, c: Collider | null, o: { exclude?: number | readonly number[]; firstOnly?: boolean; budgetMs?: number } = {}): CheckResult |
269 | Scene indices colliding with this part at this pose. budgetMs bounds the whole call. |
app/src/snap/decode.test.ts (68 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DIR |
`` | 10 | internal | |
| function | load |
(f: string) |
11 | internal | |
| const | cat |
`` | 12 | internal | |
| const | vocab |
`` | 13 | internal | |
| const | gold |
`` | 14 | internal | |
| const | graph |
`` | 15 | internal | |
| function | close |
(x: ArrayLike<number>, y: ArrayLike<number>, eps: number, msg = '') |
16 | internal |
app/src/snap/decode.ts (85 lines)
- Imported by: app/src/snap/decode.test.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | graphEdgeRotation |
(e: GEdge): M |
6 | _graph_edge_rotation: the edge transform in the stored a->b direction, continuous parameters. | internal |
| function | edgeMatrix |
(e: GEdge, aStem: string, bStem: string, cat: Catalog): M |
22 | _edge_matrix: part b's transform in part a's frame. fa @ R @ inv(fb). | internal |
| function | decodeGraph |
(g: Graph, cat: Catalog): M[] |
28 | decode_graph: BFS from the lowest part of each component, which is placed at identity. | tests only |
| function | pyRound6 |
(v: number): number |
52 | round(v, 6): exact-decimal rounding, ties to even (toFixed rounds ties up, so fix ties). | tests only |
| function | fmtG12 |
(v: number): string |
65 | Python's format(v, ".12g"). | tests only |
| function | graphToLdr |
(g: Graph, cat: Catalog): string |
75 | graph_to_ldr. Uses stored transforms, or decodeGraph when rootless (single component only). | tests only |
app/src/snap/errors.ts (10 lines)
- Imported by: app/src/snap/agent.test.ts, app/src/snap/joints.ts, app/src/snap/mat.ts, app/src/snap/model.ts, app/src/snap/names.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| class | ValueError |
`` | 1 | joints.ts, mat.ts, model.ts, names.ts | |
| method | ValueError.constructor |
(message: string) |
2 | ||
| class | NoMate |
`` | 5 | Ambiguous, incompatible, missing or inexact connection. | joints.ts, model.ts |
| method | NoMate.constructor |
(message: string) |
6 | ||
| class | KeyError |
`` | 8 | joints.ts, names.ts | |
| method | KeyError.constructor |
(message: string) |
9 |
app/src/snap/graph.test.ts (68 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DIR |
`` | 10 | internal | |
| function | load |
(f: string) |
11 | internal | |
| const | cat |
`` | 12 | internal | |
| const | gold |
`` | 13 | internal | |
| function | close |
(x: number[], y: number[], eps = 1e-9) |
14 | internal | |
| const | graph |
`` | 30 | internal | |
| function | key |
(e: { a: number; aConn: number; b: number; bConn: number }) |
37 | internal |
app/src/snap/graph.ts (248 lines)
- Imported by: app/src/snap/decode.test.ts, app/src/snap/decode.ts, app/src/snap/graph.test.ts, app/src/snap/path.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| interface | InPart |
`` | 12 | internal | |
| interface | GEdge |
`` | 13 | decode.ts | |
| interface | Graph |
`` | 19 | decode.ts | |
| function | canonicalize |
(cat: Catalog, stem: string, pose: M): { stem: string; pose: number[] } |
25 | ---- parse_ldr ----------------------------------------------------------------------------- | internal |
| function | parseLdr |
(text: string, cat: Catalog): Graph |
32 | tests only | |
| const | A_AXLE |
`` | 43 | internal | |
| function | isA |
(c: Conn) |
44 | internal | |
| function | buildEdges |
(flat: FlatConn[], raw: [number, number][]): GEdge[] |
47 | internal | |
| function | buildGraph |
(parts: InPart[], cat: Catalog): Graph |
78 | internal | |
| function | connectionsFor |
(parts: PosedPart[], index: number, cat: Catalog): GEdge[] |
90 | Edges between one part and the rest (for placement). a/b are indices into parts. |
tests only |
| function | componentsFromEdges |
(n: number, a: number[], b: number[]): number[][] |
95 | internal | |
| const | FAM_RANK |
`` | 116 | ---- adjacency and walks --------------------------------------------------------------------- | internal |
| type | Adj |
`` | 117 | UNUSED | |
| function | adjacency |
(edges: GEdge[], nodes?: Set<number>): Adj |
119 | decode.ts | |
| interface | TBase |
`` | 132 | internal | |
| type | TreeEdge |
`` | 133 | path.ts | |
| interface | Tree |
`` | 139 | path.ts | |
| function | pyRound |
(x: number): number |
142 | Python round(): half to even. | internal |
| function | qdeg |
(rad: number) |
146 | internal | |
| function | makeTreeEdge |
(ge: GEdge, parent: number, child: number, forward: boolean, stems: string[], cat: Catalog): TreeEdge |
148 | internal | |
| type | ParentOf |
`` | 174 | internal | |
| function | buildTree |
(g: Graph, order: number[], parentOf: ParentOf, cat: Catalog): Tree |
175 | internal | |
| function | sampleTree |
(g: Graph, cat: Catalog, component = 0, opts: { method?: 'bfs' | 'random'; root?: number; rand?: () => number } = {}): Tree |
187 | sample_tree. bfs: root is the start node (the Python's seed). random: pass rand (numpy's |
tests only |
| function | treeEdgeRow |
(e: TreeEdge, parent: number, child: number, parentStem: string, childStem: string, cat: Catalog): GEdge |
217 | _tree_edge_row: dequantize a tree edge. Ball edges come out canonical a = "in" side. | internal |
| function | treeToGraph |
(t: Tree, cat: Catalog): Graph |
244 | tree_to_graph: rootless (transforms null). | tests only |
app/src/snap/joints.ts (210 lines)
- Imported by: app/src/snap/agent.test.ts, app/src/snap/model.ts, app/src/snap/relate.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | TYPES |
`` | 8 | model.ts | |
| function | info |
(stem: string): PartInfo |
10 | model.ts | |
| function | addresses |
(stem: string): [string, number][] |
13 | (type, typed index): the subtype for stud/hole/axle connectors, the kind otherwise; indexed per consecutive run. | model.ts |
| interface | PathNode |
`` | 31 | What a connector path element must provide. Occurrence implements it. | model.ts |
| class | Connector |
`` | 33 | model.ts, relate.ts | |
| method | Connector.constructor |
(path: readonly PathNode[], nativeIndex: number) |
37 | ||
| method | Connector.equals |
(o: Connector): boolean |
66 | ||
| function | pairKey |
(x: string, y: string) |
71 | internal | |
| const | STUD_SET |
`` | 72 | internal | |
| const | AXLE_SET |
`` | 73 | internal | |
| function | mates |
(type: string): string |
75 | internal | |
| function | compatible |
(a: Connector, b: Connector): boolean |
83 | model.ts, relate.ts | |
| function | socketFaces |
(stem: string, index: number): number[] |
92 | Socket ends that also carry a native stud-receiving hole (as signs along the socket axis). | internal |
| function | mm3 |
(a: readonly number[], b: readonly number[]): number[] |
110 | 3x3 row-major helpers | internal |
| function | tr3 |
(a: readonly number[]): number[] |
115 | internal | |
| function | mv3 |
(a: readonly number[], v: readonly number[]): number[] |
116 | internal | |
| const | EYE3 |
`` | 118 | internal | |
| const | RX3 |
`` | 118 | internal | |
| function | g |
(x: number) |
119 | internal | |
| interface | PlaceOpts |
`` | 121 | model.ts, relate.ts | |
| function | placement |
(target: Connector, source: Connector, o: PlaceOpts = {}): number[] |
127 | joints.placement: the pose that maps source into target's frame. Pure; mutates nothing. |
model.ts, relate.ts |
app/src/snap/mat.ts (143 lines)
- Imported by: app/src/attach-ui.ts, app/src/snap/agent.test.ts, app/src/snap/catalog.ts, app/src/snap/collide.ts, app/src/snap/decode.test.ts, app/src/snap/decode.ts, app/src/snap/graph.test.ts, app/src/snap/graph.ts, app/src/snap/joints.ts, app/src/snap/model.ts, app/src/snap/pairs.ts, app/src/snap/place.ts, app/src/snap/relate.test.ts, app/src/snap/relate.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| type | M |
`` | 4 | 12 numbers: 3x3 rotation row-major, then translation (x, y, z). | attach-ui.ts, catalog.ts, collide.ts, decode.ts, graph.ts, joints.ts, model.ts, pairs.ts, place.ts, relate.ts |
| const | I |
`` | 5 | decode.ts, model.ts | |
| function | mul |
(a: M, b: M): number[] |
7 | decode.ts, graph.ts, joints.ts, model.ts, pairs.ts, place.ts | |
| function | inv |
(a: M): number[] |
17 | decode.ts, joints.ts, place.ts | |
| function | rotYRad |
(t: number): number[] |
24 | decode.ts | |
| function | rotY |
(turns: number): number[] |
28 | place.ts | |
| function | col |
(m: M, k: number): number[] |
34 | graph.ts, pairs.ts | |
| function | col1 |
(m: M) |
35 | joints.ts | |
| function | dot3 |
(a: readonly number[], b: readonly number[]) |
36 | graph.ts, joints.ts, pairs.ts | |
| function | fromLdr |
(n: number[]): number[] |
39 | LDraw line-type-1 numbers: x y z a b c d e f g h i | graph.ts |
| function | inv3 |
(m: number[]): number[] | null |
41 | internal | |
| function | orthonormalize |
(m: M): number[] |
53 | Port of the SVD step in parse_ldr (U @ Vt = polar factor). Newton iteration; keeps translation. | graph.ts |
| function | eulerXYZ |
(R: readonly number[]): [number, number, number] |
68 | scipy as_euler("xyz") (extrinsic): R = Rz(c) Ry(b) Rx(a), returns [a, b, c]. | graph.ts |
| const | RX_PI |
`` | 76 | decode.ts | |
| function | fromEulerXYZ |
(a: number, b: number, c: number): number[] |
79 | scipy Rotation.from_euler("xyz", [a, b, c]) (extrinsic): R = Rz(c) Ry(b) Rx(a). Translation zero. | decode.ts |
| function | apply |
(m: M, p: readonly number[]): number[] |
92 | Pose.call: map a point. | collide.ts, relate.ts |
| function | dir |
(m: M, v: readonly number[]): number[] |
99 | Pose.dir: rotate a direction. | joints.ts |
| function | isProper |
(m: readonly number[]): boolean |
106 | Pose.post_init: twelve finite numbers, R^T R = I within 1e-8, det > 0. | joints.ts, model.ts |
| function | unit |
(v: readonly number[]): number[] | null |
117 | pose._unit: normalised, or null for a zero vector. | internal |
| function | spin |
(axis: readonly number[], degrees: number, about: readonly number[] = [0, 0, 0]): number[] |
124 | pose.spin: right-handed rotation by degrees about the line through about along axis. |
joints.ts, relate.ts |
| function | toEngine |
(m: M): number[] |
140 | LDraw (y down) to engine (y up): conjugate by F = diag(1,-1,-1). R' = F R F, t' = F t. | tests only |
app/src/snap/model.ts (214 lines)
- Imported by: app/src/snap/agent.test.ts, app/src/snap/relate.test.ts, app/src/snap/relate.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | poseEq |
(a: M, b: M) |
8 | internal | |
| class | Addresses |
`` | 11 | Connectors of one type on a part. get() takes Python-style negative indices. | UNUSED |
| method | Addresses.constructor |
(items: readonly Connector[], part: string, type: string | null) |
13 | ||
| method | Addresses.[Symbol.iterator] |
(): Iterator<Connector> |
15 | ||
| method | Addresses.get |
(index: number): Connector |
16 | ||
| method | Addresses.near |
(point: readonly number[]): Connector |
25 | The connector nearest point, in the frame its .at is given in. |
|
| function | connectors |
(stem: string, type: string | null = null): Addresses |
33 | Part-local references. | relate.ts |
| class | Occurrence |
`` | 38 | Placement in its parent's frame. Identity is object identity; a copied Assembly gets new Occurrences. | tests only |
| method | Occurrence.constructor |
(assemblyName: string | null, what: string | Assembly, pose: M = I, color: string | number | null = null, index = 0) |
46 | ||
| method | Occurrence.connectors |
(type: string | null = null): Addresses |
52 | ||
| method | Occurrence.connector |
(reference: Connector): Connector |
66 | Bind a definition reference to this copy. | |
| class | Assembly |
`` | 73 | relate.ts | |
| method | Assembly.constructor |
(name: string) |
80 | ||
| method | Assembly.toString |
(): string |
84 | ||
| method | Assembly.connector |
(reference: Connector): Connector |
88 | Resolve a definition reference, mapping native counterparts when mirrored. | |
| method | Assembly.add |
(what: string | Assembly | Occurrence, o: { pose?: M; color?: string | number | null } = {}): Occurrence |
105 | ||
| method | Assembly.attach |
(what: string | Assembly, o: AttachOpts): Occurrence |
122 | ||
| interface | AttachOpts |
`` | 153 | UNUSED | |
| function | definitions |
(root: Assembly): Set<Assembly> |
159 | internal | |
| function | contains |
(shape: Assembly | Occurrence, ref: Connector): boolean |
168 | internal | |
| function | childrenOf |
(shape: Assembly | Occurrence): readonly Occurrence[] |
178 | internal | |
| interface | Placed |
`` | 184 | UNUSED | |
| function | parts |
(shape: Assembly | Occurrence): Placed[] |
187 | Flatten to leaf snapshots in the enclosing frame. Explicit stack, so depth is unbounded. | tests only |
| function | attachments |
(shape: Assembly | Occurrence): [Connector, Connector][] |
203 | Authored connector pairs inside shape, including nested copies, bound into its enclosing frame. |
tests only |
app/src/snap/names.ts (84 lines)
- Imported by: app/src/snap/agent.test.ts, app/src/snap/model.ts, app/src/snap/relate.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DIM |
`` | 4 | internal | |
| function | words |
(text: string): string[] |
7 | catalog._words: lowercase, footprints ordered small-to-large, split on whitespace. | internal |
| function | keysOf |
(): Map<string, string[]> |
13 | internal | |
| function | stemOf |
(what: string): string |
22 | internal | |
| function | same |
(a: readonly string[], b: readonly string[]) |
29 | internal | |
| function | resolveName |
(text: string): string |
31 | internal | |
| function | resolve |
(what: string): string |
49 | Part ID (optional .dat), alias, or family-first title. Missing or ambiguous names raise KeyError. | model.ts, relate.ts |
| function | name |
(stem: string): string |
59 | internal | |
| function | measure |
(stem: string): [number[], number[]] |
62 | Surface bounds [lo, hi] in part-local LDU, including studs. | relate.ts |
| function | colorsMap |
(): Map<string, number> |
67 | internal | |
| function | color |
(nameOrCode: string | number): number |
73 | model.ts |
app/src/snap/pairs.ts (141 lines)
- Imported by: app/src/snap/graph.ts, app/src/snap/joints.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | POS_THR |
`` | 7 | UNUSED | |
| const | AXIS_THR |
`` | 7 | UNUSED | |
| const | AXLE_AXIS_THR |
`` | 7 | UNUSED | |
| const | AXLE_PERP_THR |
`` | 7 | UNUSED | |
| const | AXLE_DEFAULT_RAD |
`` | 7 | UNUSED | |
| const | AXLE_MIN_OVERLAP |
`` | 7 | joints.ts | |
| const | AXLE_QUERY_PAD |
`` | 7 | UNUSED | |
| const | FIXED_AXIS_THR |
`` | 7 | UNUSED | |
| const | FIXED_FRAME_TRACE |
`` | 7 | UNUSED | |
| const | FIXED_ORIENTED |
`` | 10 | internal | |
| const | AXLE_A_SIDE |
`` | 11 | internal | |
| interface | PosedPart |
`` | 13 | graph.ts | |
| interface | FlatConn |
`` | 14 | graph.ts | |
| function | flatten |
(parts: PosedPart[], infoOf: (stem: string) => PartInfo): FlatConn[] |
19 | graph.ts | |
| class | Hash |
`` | 32 | stands in for cKDTree | internal |
| method | Hash.constructor |
(cell: number) |
36 | ||
| method | Hash.add |
(i: number, p: number[]) |
40 | ||
| method | Hash.ball |
(p: number[], r: number, fn: (j: number) => void) |
44 | ||
| function | d2 |
(a: number[], b: number[]) |
52 | internal | |
| type | Verdict |
`` | 54 | internal | |
| function | judge |
(a: FlatConn, b: FlatConn): Verdict |
57 | The mask logic of _find_pairs, one pair (a = lower flat index) at a time. | internal |
| function | findPairs |
(flat: FlatConn[], involving?: number): [number, number][] |
102 | Returns raw pairs [lowerFlat, upperFlat], fast-mask pairs first, then fixed/axle, like the Python. | graph.ts |
app/src/snap/path.ts (187 lines)
- Imported by: app/src/snap/decode.test.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| class | ParseError |
`` | 4 | internal | |
| interface | ParseResult |
`` | 5 | UNUSED | |
| class | Vocab |
`` | 8 | The catalog's name tables (Catalog.id_to_name, name_to_id, color tables). Input is pairs, in file order. | tests only |
| method | Vocab.constructor |
(partNames: [string, string][], colorNames: [string, number][]) |
14 | ||
| const | EDGE_ARITY |
`` | 22 | internal | |
| function | pairSet |
(p: [string, string][]) |
23 | internal | |
| const | STUD_SET |
`` | 24 | internal | |
| const | AXLE_SET |
`` | 24 | internal | |
| function | pyRepr |
(s: string): string |
27 | Python repr() of a str, enough for error messages (no hex escapes for control characters). | internal |
| function | id2i |
(t: string): number |
42 | Letter ID ('a'=0, 'z'=25, 'aa'=26, ...). IDs over 10 letters exceed safe integers and are rejected. | tests only |
| function | i2id |
(n: number): string |
50 | tests only | |
| function | pyInt |
(tok: string, label: string): number |
60 | internal | |
| function | deg |
(tok: string): number |
65 | internal | |
| function | flip |
(tok: string): boolean |
70 | internal | |
| const | countCache |
`` | 75 | internal | |
| function | counts |
(cat: Catalog, stem: string): Map<string, number> |
76 | internal | |
| function | conn |
(cat: Catalog, v: Vocab, stem: string, sub: string, pol: 'in' | 'on' | null, lid: string): number |
88 | _conn: index within the (subtype, polarity) subgroup. Python raises KeyError (not ParseError) for a part with no connectors at all. | internal |
| function | parseNode |
(line: string, v: Vocab): { stem: string; color: number } |
97 | internal | |
| function | parseEdge |
(line: string, parts: { stem: string }[], childStem: string, v: Vocab, cat: Catalog): TreeEdge |
111 | internal | |
| function | serializeTree |
(tree: Tree, v: Vocab): string |
143 | tests only | |
| function | parseSample |
(text: string, v: Vocab, cat: Catalog): ParseResult |
167 | tests only |
app/src/snap/place.ts (6 lines)
- Imported by: app/src/snap/graph.test.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | placement |
(targetPose: M, targetFrame: M, sourceFrame: M, turns: number): number[] |
4 | BrickNet _edge_matrix: target_pose @ target_frame @ RotY(turns) @ inv(source_frame) | tests only |
app/src/snap/relate.test.ts (52 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | rd |
(p: string): any |
10 | internal | |
| const | B |
`` | 11 | internal | |
| const | A |
`` | 11 | internal | |
| function | close |
(a: number, b: number) |
18 | internal | |
| const | target |
`` | 19 | internal |
app/src/snap/relate.ts (125 lines)
- Imported by: app/src/attach-ui.ts, app/src/build.ts, app/src/snap/relate.test.ts
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | RELATIONS |
`` | 7 | attach-ui.ts | |
| type | Relation |
`` | 8 | attach-ui.ts | |
| const | SIDE |
`` | 12 | Model-frame sides in LDraw axes: [axis index, sign]. -y is up. Front is -z (the minifig's facing), | internal |
| const | TOL |
`` | 13 | internal | |
| const | YAWS |
`` | 14 | internal | |
| const | LIMIT |
`` | 15 | internal | |
| interface | Box |
`` | 17 | UNUSED | |
| interface | Addr |
`` | 18 | internal | |
| interface | Candidate |
`` | 19 | attach-ui.ts, build.ts | |
| interface | TargetPart |
`` | 24 | UNUSED | |
| function | worldBox |
(stem: string, pose: M): Box |
26 | tests only | |
| function | centre |
(b: Box, a: number) |
36 | internal | |
| function | classify |
(t: Box, s: Box): Relation |
39 | Where the source sits relative to the target, by their world boxes. | internal |
| const | ROUND |
`` | 54 | internal | |
| function | through |
(t: Connector, s: Connector) |
56 | Axle through a hole or bush: overlaps its target, so the relation filter is meaningless. | internal |
| function | seatedOverlap |
(c: Candidate): boolean |
60 | Joints whose own mate is meant to overlap: pin in hole, any hollow stud. | attach-ui.ts, build.ts |
| function | optionSets |
(t: Connector, s: Connector): PlaceOpts[] |
66 | internal | |
| function | poseKey |
(p: readonly number[]) |
77 | internal | |
| function | jointCandidates |
(target: TargetPart, sourceStem: string, want: Relation): Candidate[] |
80 | Every attachment of sourceStem to target that BrickAgent allows and that lands on side want. |
attach-ui.ts |
| function | touchCandidates |
(target: TargetPart, sourceStem: string, want: Relation): Candidate[] |
105 | Unattached placements flush against one side of the target's bounds. Lateral relations only. | attach-ui.ts |
app/src/sw.js (43 lines)
Service worker: keeps a copy of the app shell so pages work with no network.
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | CACHE |
`` | 3 | The version and precache list below are filled in by build.mjs. | internal |
| const | PRECACHE |
`` | 4 | internal |
app/tools/make-agent-bundle.mjs (50 lines)
node tools/make-agent-bundle.mjs (run from app/) -> data/agent/bundle.json.gz
- Imported by: nothing (entry point, script, or orphan)
- Packages: better-sqlite3
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | B |
`` | 6 | internal | |
| const | A |
`` | 6 | internal | |
| function | rd |
(p) |
7 | internal | |
| function | rec |
(x) |
8 | internal | |
| function | aliasRows |
(a) |
9 | internal | |
| const | aliases |
`` | 11 | internal | |
| const | aliasDst |
`` | 12 | internal | |
| const | ids |
`` | 13 | internal | |
| const | bounds |
`` | 14 | internal | |
| const | names |
`` | 15 | internal | |
| const | labels |
`` | 16 | internal | |
| const | seating |
`` | 17 | internal | |
| const | db |
`` | 19 | internal | |
| const | stems |
`` | 20 | internal | |
| const | keep |
`` | 23 | Same resolution order as names.ts stemOf(). | internal |
| const | missing |
`` | 24 | internal | |
| function | pick |
(o, ok) |
31 | internal | |
| function | stemOfKey |
(k) |
32 | internal | |
| const | bundle |
`` | 34 | internal | |
| const | gz |
`` | 47 | internal |
dev/build.mjs (64 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | here |
`` | 9 | internal | |
| const | root |
`` | 10 | internal | |
| const | dist |
`` | 11 | internal | |
| const | site |
`` | 12 | internal | |
| const | SKIP |
`` | 26 | Shared assets that dev must not publish | internal |
| const | sharedDir |
`` | 27 | internal | |
| function | notSkipped |
(src) |
28 | internal | |
| const | pages |
`` | 41 | internal | |
| const | files |
`` | 42 | internal |
dev/changelog.test.mjs (48 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | tree |
(files) |
10 | internal | |
| const | files |
`` | 19 | internal | |
| const | pages |
`` | 27 | internal | |
| function | count |
(s, re) |
28 | internal |
dev/config.mjs (62 lines)
- Imported by: dev/build.mjs, dev/changelog.test.mjs, dev/pages.test.mjs, dev/render.test.mjs, shared/engine/sitemap.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | cfg |
`` | 1 | build.mjs |
dev/pages.test.mjs (45 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | tree |
(files) |
10 | internal | |
| const | aiTags |
`` | 18 | internal |
dev/render.mjs (156 lines)
Scanned site -> [{ outPath, html }]. Pure: writes nothing.
- Imported by: dev/build.mjs, dev/changelog.test.mjs, dev/pages.test.mjs, dev/render.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | renderPages |
(site, cfg) |
6 | build.mjs |
dev/render.test.mjs (59 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | tree |
(files) |
10 | internal | |
| const | files |
`` | 19 | internal | |
| const | site |
`` | 26 | internal | |
| const | pages |
`` | 27 | internal | |
| function | count |
(s, re) |
28 | internal |
dev/scan.mjs (155 lines)
Reads dev/content, validates it, returns every collection. Collects errors; never throws on content.
- Imported by: dev/build.mjs, dev/changelog.test.mjs, dev/pages.test.mjs, dev/render.test.mjs, dev/scan.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | STATUSES |
`` | 7 | internal | |
| function | walk |
(dir, base = '') |
9 | internal | |
| const | PAGE_RESERVED |
`` | 20 | internal | |
| function | scan |
(contentDir, { aiTags = [] } = {}) |
21 | build.mjs |
dev/scan.test.mjs (62 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | tree |
(files) |
8 | internal |
scripts/build-sitemap.mjs (24 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | site |
`` | 3 | internal | |
| const | langs |
`` | 4 | internal | |
| const | alternates |
`` | 6 | internal | |
| const | urls |
`` | 12 | internal | |
| const | xml |
`` | 16 | internal |
scripts/collide-parity.ts (32 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | DIR |
`` | 4 | internal | |
| const | fx |
`` | 5 | internal | |
| const | cache |
`` | 6 | internal | |
| function | load |
(s: string) |
7 | internal | |
| function | toM |
(m: number[][]) |
16 | internal | |
| const | bad |
`` | 18 | internal | |
| const | band |
`` | 18 | internal | |
| const | bandBad |
`` | 18 | internal | |
| const | worst |
`` | 18 | internal | |
| const | slowest |
`` | 18 | internal | |
| const | slowPair |
`` | 18 | internal | |
| const | t0 |
`` | 19 | internal |
shared/assets/js/page.js (27 lines)
"Change settings" links forget the saved language. The theme is handled by theme.js in the head.
- Imported by: nothing (entry point, script, or orphan)
- no top-level declarations
shared/assets/js/picker.js (51 lines)
Skip the picker if the visitor already chose a language
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | saved |
`` | 2 | Skip the picker if the visitor already chose a language | internal |
| const | root |
`` | 12 | internal | |
| const | btn |
`` | 13 | internal | |
| const | mq |
`` | 14 | internal | |
| function | saveTheme |
(theme) |
16 | internal | |
| function | readTheme |
() |
21 | internal | |
| function | getTheme |
() |
26 | internal | |
| function | apply |
(theme) |
31 | internal |
shared/assets/js/theme.js (26 lines)
Runs in <head> before first paint. Order: saved choice (cookie, then localStorage), else system setting.
- Imported by: nothing (entry point, script, or orphan)
- no top-level declarations
shared/engine/layout.mjs (89 lines)
Escaped html`` tag and the dev page shell.
- Imported by: app/render-build.mjs, app/render.mjs, dev/render.mjs, shared/engine/layout.test.mjs, shared/engine/sitemap.mjs, shared/engine/sitemap.test.mjs, site/render.mjs, site/root.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| class | Raw |
`` | 4 | internal | |
| method | Raw.constructor |
(s) |
4 | ||
| method | Raw.toString |
() |
4 | ||
| function | raw |
(s) |
5 | render-build.mjs, render.mjs, render.mjs, render.mjs | |
| const | ESC |
`` | 7 | internal | |
| function | esc |
(v) |
8 | sitemap.mjs, root.mjs | |
| function | part |
(v) |
10 | internal | |
| function | html |
(strings, ...values) |
18 | html<p>${userText}</p> returns Raw, so nesting works. |
render-build.mjs, render.mjs, render.mjs, sitemap.mjs, render.mjs, root.mjs |
| function | canonicalUrl |
(base, outPath) |
26 | "blog/hello.html" -> "https://dev.brickheart.org/blog/hello" | render-build.mjs, render.mjs, sitemap.mjs, render.mjs, root.mjs |
| function | page |
(cfg, pg) |
33 | page: { outPath, title, description, body, tagNav, isHome, rootAbsolute } | render.mjs |
shared/engine/layout.test.mjs (44 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | cfg |
`` | 5 | internal |
shared/engine/lists.mjs (13 lines)
- Imported by: dev/render.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | paginate |
(items, size) |
1 | render.mjs | |
| function | pageName |
(name, n) |
8 | design, 1 -> design.html design, 2 -> design-2.html | render.mjs |
| function | formatDate |
(iso, locale = 'en-GB') |
10 | render.mjs |
shared/engine/markdown.mjs (108 lines)
Markdown -> { title, html, excerpt, errors, warnings }. Never throws on bad content.
- Imported by: dev/scan.mjs, shared/engine/markdown.test.mjs, site/localize.mjs, site/scan.mjs
- Packages: markdown-it
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | md |
`` | 6 | internal | |
| const | baseFence |
`` | 9 | Scrollable code blocks must be keyboard-focusable | internal |
| const | baseCode |
`` | 10 | internal | |
| function | focusable |
(s) |
11 | internal | |
| function | inlineText |
(inline) |
25 | Plain text of an inline token (links and emphasis flattened, images skipped). | internal |
| function | rawToken |
(content) |
34 | internal | |
| function | renderMarkdown |
(src, { file = '', rewriteLink } = {}) |
41 | scan.mjs, localize.mjs, scan.mjs |
shared/engine/markdown.test.mjs (45 lines)
- Imported by: nothing (entry point, script, or orphan)
- no top-level declarations
shared/engine/paths.mjs (58 lines)
Slugs, entry file names, tags and relative paths. No other dependencies.
- Imported by: app/render-build.mjs, app/render.mjs, dev/render.mjs, dev/scan.mjs, shared/engine/layout.mjs, shared/engine/markdown.mjs, shared/engine/paths.test.mjs, site/render.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | RESERVED_SLUGS |
`` | 3 | Slugs, entry file names, tags and relative paths. No other dependencies. | internal |
| function | slugify |
(text) |
5 | scan.mjs, markdown.mjs | |
| function | checkSlug |
(slug) |
16 | scan.mjs | |
| function | parseEntryName |
(fileName) |
23 | A later letter sorts as newer. A missing letter sorts before "a". | scan.mjs |
| function | isIntroFile |
(relPath) |
35 | Tag intro file: basename equals the folder it sits in (tags/accessibility/accessibility.md). | scan.mjs |
| function | checkTagName |
(name) |
41 | scan.mjs | |
| function | tagLabel |
(name) |
49 | data_analysis -> "Data analysis" | render.mjs |
| function | rootPrefix |
(outPath) |
56 | "blog/tags/design.html" -> "../../", "roadmap.html" -> "" | render-build.mjs, render.mjs, render.mjs, layout.mjs, render.mjs |
shared/engine/paths.test.mjs (37 lines)
- Imported by: nothing (entry point, script, or orphan)
- no top-level declarations
shared/engine/sitemap.mjs (55 lines)
sitemap.xml, robots.txt and the 404 page. All pure: they return strings.
- Imported by: dev/build.mjs, shared/engine/sitemap.test.mjs, site/build.mjs, site/root.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | sitemapXml |
(baseUrl, outPaths) |
4 | build.mjs | |
| function | robotsTxt |
(baseUrl) |
13 | build.mjs, build.mjs | |
| function | notFoundHtml |
(cfg) |
18 | cfg.notFound: { title, text, home, quote: { text, ref, translation, lang } } | build.mjs, root.mjs |
shared/engine/sitemap.test.mjs (28 lines)
- Imported by: nothing (entry point, script, or orphan)
- no top-level declarations
site/blocks.mjs (62 lines)
- Imported by: app/build.mjs, site/build.mjs, site/config.mjs, site/localize.mjs, site/localize.test.mjs, site/translate.test.mjs
- Packages: markdown-it
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | md |
`` | 4 | internal | |
| function | hashOf |
(s) |
6 | tests only | |
| const | MARKER |
`` | 8 | internal | |
| function | stripMarker |
(s) |
11 | "- a", "* a", "1. a" -> "a"; continuation lines lose their indent too. | internal |
| function | splitBlocks |
(src) |
14 | Source -> [{ kind, text, map, prefix }] in document order. Fenced and indented code are skipped. | tests only |
| function | collectBlocks |
(sources, ui) |
36 | Pages -> { "about/3": { hash, en } }. Key = page path without .md, plus 1-based position. | build.mjs, build.mjs, config.mjs |
| function | applyBlocks |
(src, key, t) |
48 | t maps "page/3" -> { text }. Blocks without a translation stay in English. | localize.mjs |
site/build.mjs (125 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | here |
`` | 14 | internal | |
| const | root |
`` | 15 | internal | |
| const | dist |
`` | 16 | internal | |
| const | site |
`` | 18 | internal | |
| const | source |
`` | 19 | internal | |
| const | load |
`` | 22 | internal | |
| function | validateNav |
(items) |
27 | internal | |
| const | sources |
`` | 53 | Translation step: collect, merge the inbox, write the todo (locally), or just read (CI). | internal |
| const | current |
`` | 54 | internal | |
| const | others |
`` | 55 | internal | |
| const | step |
`` | 56 | internal | |
| const | pageKeys |
`` | 63 | Which languages can be built, and which of their pages are complete. | internal |
| const | complete |
`` | 64 | internal | |
| const | built |
`` | 65 | internal | |
| const | uiByFolder |
`` | 66 | internal | |
| const | sharedDir |
`` | 78 | Fresh dist: shared assets, then site-only css and js on top. | internal |
| const | SKIP |
`` | 79 | internal | |
| function | keep |
(src) |
80 | internal | |
| const | out |
`` | 90 | Render every built language. | internal |
| const | pagesByFolder |
`` | 91 | internal | |
| const | files |
`` | 106 | internal |
site/config.mjs (63 lines)
- Imported by: app/build.mjs, site/build.mjs, site/localize.test.mjs, site/root.test.mjs, site/site.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | load |
(name) |
6 | internal | |
| const | languages |
`` | 8 | build.mjs, build.mjs | |
| const | ui |
`` | 9 | build.mjs, build.mjs | |
| const | cfg |
`` | 11 | build.mjs, build.mjs |
site/links.mjs (17 lines)
- Imported by: site/localize.mjs, site/scan.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | SCHEME |
`` | 3 | internal | |
| function | makeLinkRewriter |
(fromRel, known) |
6 | Returns a function that maps a link target in fromRel (e.g. "legal/privacy.md") to its output form. |
localize.mjs, scan.mjs |
site/localize.mjs (26 lines)
- Imported by: app/build.mjs, site/build.mjs, site/config.mjs, site/localize.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | uiFor |
(base, t) |
6 | English ui with one language's translations laid over it. | build.mjs, build.mjs, config.mjs |
| function | localizePages |
({ pages, sources, t, complete }) |
11 | complete: page keys (no .md) that are fully translated. Others come back with fallback: true. | build.mjs |
site/localize.test.mjs (47 lines)
- Imported by: nothing (entry point, script, or orphan)
- no top-level declarations
site/render.mjs (106 lines)
Pages + one language -> [{ outPath, html }]. Pure: writes nothing.
- Imported by: site/build.mjs, site/localize.test.mjs, site/site.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | rel |
(from, to) |
8 | internal | |
| function | renderSite |
(pages, lang, ui, cfg, { source, sourceUi, load } = {}) |
11 | build.mjs |
site/root.mjs (88 lines)
Root picker, 404 pages and hreflang sitemap. All pure: they return strings.
- Imported by: site/build.mjs, site/root.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | renderPicker |
(langs, cfg) |
5 | build.mjs | |
| function | renderNotFounds |
(langs, uiFor, cfg) |
50 | One 404 per language; uiFor(lang) returns that language's UI strings. | build.mjs |
| function | rootNotFound |
(ui, cfg) |
63 | build.mjs | |
| function | siteSitemap |
(baseUrl, langs, pagesByFolder, sourceFolder) |
71 | pagesByFolder: Map folder -> ["index.html", "about.html", ...] (only complete, current pages). | build.mjs |
site/root.test.mjs (38 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | zh |
`` | 6 | internal | |
| const | ar |
`` | 7 | internal |
site/scan.mjs (65 lines)
Reads site/content, validates it, returns pages. Collects errors; never throws on content.
- Imported by: site/build.mjs, site/site.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| const | NAME |
`` | 7 | internal | |
| const | RESERVED |
`` | 8 | internal | |
| function | walk |
(dir, base = '') |
10 | internal | |
| function | scan |
(contentDir) |
22 | build.mjs |
site/site.test.mjs (65 lines)
- Imported by: nothing (entry point, script, or orphan)
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | tree |
(files) |
10 | internal | |
| const | good |
`` | 19 | internal | |
| const | site |
`` | 24 | internal | |
| const | out |
`` | 25 | internal |
site/tables.mjs (149 lines)
- Imported by: site/build.mjs, site/render.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | esc |
(s) |
4 | internal | |
| const | HEX |
`` | 5 | internal | |
| function | hex |
(v) |
6 | internal | |
| function | lin |
(c) |
13 | WCAG relative luminance: pick whichever of black or white text has the higher contrast ratio. | internal |
| function | lum |
(h) |
14 | internal | |
| function | inkFor |
(h) |
15 | UNUSED | |
| const | ALLOWED |
`` | 17 | internal | |
| function | parseSpec |
(body) |
18 | UNUSED | |
| function | makeLoader |
(dataDir) |
29 | build.mjs | |
| function | rangeHtml |
(col, [y1, y2], ctx) |
42 | internal | |
| function | paletteHtml |
(col, v, ctx) |
59 | Bar is decorative; the same information is always printed as text beside it. | internal |
| function | cellHtml |
(col, v, ctx) |
70 | internal | |
| function | tableHtml |
(t, ctx, id) |
85 | internal | |
| function | stripHtml |
(t, spec) |
112 | internal | |
| function | hydrate |
(pageHtml, { lang, ui, load, file }) |
129 | Swap every data placeholder in a page's HTML. Throws with the file name on any problem. | render.mjs |
site/translate.mjs (126 lines)
- Imported by: app/build.mjs, site/build.mjs, site/config.mjs, site/translate.test.mjs
| kind | name | signature | line | comment | usage |
|---|---|---|---|---|---|
| function | readJson |
(f, fallback) |
4 | internal | |
| function | links |
(s) |
6 | internal | |
| function | markers |
(s) |
7 | internal | |
| function | checkTranslation |
(en, text) |
10 | Reject translations that change link targets or placeholders. | tests only |
| function | loadStore |
(raw) |
19 | Old position-keyed entries ({ "about/3": { hash, text } }) are migrated on read. | build.mjs, config.mjs |
| function | keyView |
(store, current) |
32 | Hash store -> { zh: { "about/3": { hash, text } } } for the blocks that exist now. | build.mjs, config.mjs |
| function | mergeInbox |
(inbox, store, current) |
45 | Merge a filled-in todo into the store. Blank fields are skipped. | tests only |
| function | buildTodo |
(current, store, langs, drafts = {}) |
72 | Blocks whose English has no translation yet. Identical English is listed once per language. | tests only |
| function | runTranslationStep |
({ dir, current, langs, isCI }) |
84 | build.mjs | |
| function | completePages |
(current, translations, lang, pageKeys) |
119 | Which pages are complete in a language: every block (and all ui) is current. | build.mjs |
site/translate.test.mjs (70 lines)
- Imported by: nothing (entry point, script, or orphan)
- no top-level declarations