bimdown-cli 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -528,6 +528,7 @@ async function hydrate(conn, dir) {
528
528
  { name: "global", path: layout.globalDir },
529
529
  ...layout.levelDirs
530
530
  ];
531
+ const hydrated = [];
531
532
  for (const [tableName, table] of registry) {
532
533
  const csvFiles = [];
533
534
  for (const d of allDirs) {
@@ -550,38 +551,96 @@ async function hydrate(conn, dir) {
550
551
  const cols = [...headers, "_partition"];
551
552
  const colDefs = cols.map((c) => `"${c}" VARCHAR`).join(", ");
552
553
  await runQuery(conn, `CREATE TABLE "${tableName}" (${colDefs})`);
553
- for (const row of allRows) {
554
- const values = cols.map((c) => escapeSql(row[c] ?? ""));
555
- await runQuery(conn, `INSERT INTO "${tableName}" VALUES (${values.join(", ")})`);
554
+ for (let i = 0; i < allRows.length; i += INSERT_BATCH_SIZE) {
555
+ const batch = allRows.slice(i, i + INSERT_BATCH_SIZE);
556
+ const valuesSql = batch.map((row) => `(${cols.map((c) => escapeSql(row[c] ?? "")).join(", ")})`).join(", ");
557
+ await runQuery(conn, `INSERT INTO "${tableName}" VALUES ${valuesSql}`);
556
558
  }
557
559
  tables.push(tableName);
558
- await injectGeometry(conn, tableName, allDirs);
560
+ hydrated.push({ name: tableName, table });
561
+ }
562
+ const levelsReady = await tryCreateLevelsTemp(conn);
563
+ for (const { name, table } of hydrated) {
564
+ await injectGeometry(conn, name, allDirs);
565
+ if (levelsReady && table.computedFields.some((f) => f.name === "height")) {
566
+ await injectHeight(conn, name);
567
+ }
559
568
  }
560
569
  return tables;
561
570
  }
571
+ async function tryCreateLevelsTemp(conn) {
572
+ const check = await runQuery(
573
+ conn,
574
+ `SELECT table_name FROM information_schema.tables WHERE table_name = 'level'`
575
+ );
576
+ if (check.rows.length === 0) return false;
577
+ await runQuery(
578
+ conn,
579
+ `CREATE TEMP TABLE _levels AS
580
+ SELECT
581
+ id,
582
+ CAST(elevation AS DOUBLE) AS elevation,
583
+ ROW_NUMBER() OVER (ORDER BY CAST(elevation AS DOUBLE)) AS rank
584
+ FROM level
585
+ WHERE elevation IS NOT NULL AND elevation <> ''`
586
+ );
587
+ return true;
588
+ }
589
+ async function injectHeight(conn, tableName) {
590
+ const colsResult = await runQuery(
591
+ conn,
592
+ `SELECT column_name FROM information_schema.columns WHERE table_name = '${tableName}'`
593
+ );
594
+ const existing = new Set(colsResult.rows.map((r) => String(r.column_name)));
595
+ const ensureVarchar = async (col) => {
596
+ if (!existing.has(col)) {
597
+ await runQuery(conn, `ALTER TABLE "${tableName}" ADD COLUMN "${col}" VARCHAR`);
598
+ }
599
+ };
600
+ await ensureVarchar("base_level_id");
601
+ await ensureVarchar("top_level_id");
602
+ await ensureVarchar("base_offset");
603
+ await ensureVarchar("top_offset");
604
+ if (!existing.has("height")) {
605
+ await runQuery(conn, `ALTER TABLE "${tableName}" ADD COLUMN "height" DOUBLE`);
606
+ }
607
+ await runQuery(
608
+ conn,
609
+ `UPDATE "${tableName}" AS t
610
+ SET height = (lv_top.elevation + COALESCE(CAST(NULLIF(t.top_offset, '') AS DOUBLE), 0))
611
+ - (lv_base.elevation + COALESCE(CAST(NULLIF(t.base_offset, '') AS DOUBLE), 0))
612
+ FROM _levels AS lv_base, _levels AS lv_top
613
+ WHERE lv_base.id = COALESCE(
614
+ NULLIF(t.base_level_id, ''),
615
+ CASE WHEN t._partition <> 'global'
616
+ THEN t._partition
617
+ ELSE (SELECT id FROM _levels ORDER BY rank LIMIT 1)
618
+ END
619
+ )
620
+ AND lv_top.id = COALESCE(
621
+ NULLIF(t.top_level_id, ''),
622
+ (SELECT id FROM _levels WHERE rank = lv_base.rank + 1)
623
+ )`
624
+ );
625
+ }
562
626
  async function injectGeometry(conn, tableName, dirs) {
563
627
  const svgName = SVG_FILE_NAMES[tableName];
564
628
  if (!svgName) return;
565
629
  const geometries = /* @__PURE__ */ new Map();
566
630
  for (const d of dirs) {
567
- if (d.name === "global") continue;
568
631
  const svgPath = join11(d.path, `${svgName}.svg`);
569
632
  if (!existsSync10(svgPath)) continue;
570
633
  try {
571
634
  const svg = parseSvgFile(svgPath);
572
635
  for (const el of svg.elements) {
573
636
  if (el.tag === "path") {
574
- const geo = extractLineGeometry(el);
575
- geometries.set(el.id, geo);
637
+ geometries.set(el.id, extractLineGeometry(el));
576
638
  } else if (el.tag === "rect") {
577
- const geo = extractRectGeometry(el);
578
- geometries.set(el.id, geo);
639
+ geometries.set(el.id, extractRectGeometry(el));
579
640
  } else if (el.tag === "polygon") {
580
- const geo = extractPolygonGeometry(el);
581
- geometries.set(el.id, geo);
641
+ geometries.set(el.id, extractPolygonGeometry(el));
582
642
  } else if (el.tag === "circle") {
583
- const geo = extractCircleGeometry(el);
584
- geometries.set(el.id, geo);
643
+ geometries.set(el.id, extractCircleGeometry(el));
585
644
  }
586
645
  }
587
646
  } catch {
@@ -592,24 +651,50 @@ async function injectGeometry(conn, tableName, dirs) {
592
651
  for (const geo of geometries.values()) {
593
652
  for (const k of Object.keys(geo)) allKeys.add(k);
594
653
  }
654
+ const geoCols = Array.from(allKeys);
655
+ const typeOf = (col) => col === "points" ? "VARCHAR" : "DOUBLE";
595
656
  const existingCols = await runQuery(
596
657
  conn,
597
658
  `SELECT column_name FROM information_schema.columns WHERE table_name = '${tableName}'`
598
659
  );
599
660
  const existingSet = new Set(existingCols.rows.map((r) => String(r.column_name)));
600
- for (const col of allKeys) {
661
+ for (const col of geoCols) {
601
662
  if (existingSet.has(col)) continue;
602
- const sqlType = col === "points" ? "VARCHAR" : "DOUBLE";
603
- await runQuery(conn, `ALTER TABLE "${tableName}" ADD COLUMN "${col}" ${sqlType}`);
604
- }
605
- for (const [id, geo] of geometries) {
606
- const sets = Object.entries(geo).map(([k, v]) => `"${k}" = ${typeof v === "string" ? escapeSql(v) : v}`).join(", ");
607
- await runQuery(conn, `UPDATE "${tableName}" SET ${sets} WHERE id = ${escapeSql(id)}`);
663
+ await runQuery(conn, `ALTER TABLE "${tableName}" ADD COLUMN "${col}" ${typeOf(col)}`);
664
+ }
665
+ const stagingName = `_geo_${tableName}`;
666
+ const stagingColDefs = ['"id" VARCHAR', ...geoCols.map((c) => `"${c}" ${typeOf(c)}`)].join(", ");
667
+ await runQuery(conn, `CREATE TEMP TABLE "${stagingName}" (${stagingColDefs})`);
668
+ const entries = Array.from(geometries.entries());
669
+ for (let i = 0; i < entries.length; i += INSERT_BATCH_SIZE) {
670
+ const batch = entries.slice(i, i + INSERT_BATCH_SIZE);
671
+ const valuesSql = batch.map(([id, geo]) => {
672
+ const vals = [escapeSql(id)];
673
+ for (const col of geoCols) {
674
+ const v = geo[col];
675
+ if (v === void 0 || v === null) {
676
+ vals.push("NULL");
677
+ } else if (typeof v === "string") {
678
+ vals.push(escapeSql(v));
679
+ } else {
680
+ vals.push(String(v));
681
+ }
682
+ }
683
+ return `(${vals.join(", ")})`;
684
+ }).join(", ");
685
+ await runQuery(conn, `INSERT INTO "${stagingName}" VALUES ${valuesSql}`);
608
686
  }
687
+ const setClause = geoCols.map((c) => `"${c}" = g."${c}"`).join(", ");
688
+ await runQuery(
689
+ conn,
690
+ `UPDATE "${tableName}" SET ${setClause} FROM "${stagingName}" g WHERE "${tableName}".id = g.id`
691
+ );
692
+ await runQuery(conn, `DROP TABLE "${stagingName}"`);
609
693
  }
610
694
  function escapeSql(val) {
611
695
  return "'" + val.replace(/'/g, "''") + "'";
612
696
  }
697
+ var INSERT_BATCH_SIZE;
613
698
  var init_hydrate = __esm({
614
699
  "src/duckdb/hydrate.ts"() {
615
700
  "use strict";
@@ -618,6 +703,7 @@ var init_hydrate = __esm({
618
703
  init_csv();
619
704
  init_svg();
620
705
  init_engine();
706
+ INSERT_BATCH_SIZE = 500;
621
707
  }
622
708
  });
623
709
 
@@ -806,7 +892,7 @@ function renderHostedElements(levelDir, tableName, wallElements) {
806
892
  const y1 = cy - uy * halfW;
807
893
  const x2 = cx + ux * halfW;
808
894
  const y2 = cy + uy * halfW;
809
- const sw = tableName === "door" ? "0.08" : "0.06";
895
+ const sw = tableName === "door" ? "0.22" : "0.18";
810
896
  const markup = ` <line id="${row.id}" x1="${x1.toFixed(3)}" y1="${y1.toFixed(3)}" x2="${x2.toFixed(3)}" y2="${y2.toFixed(3)}" stroke="${color.stroke}" stroke-width="${sw}" />`;
811
897
  results.push({
812
898
  tableName,
@@ -895,22 +981,28 @@ function renderLevel(projectDir, levelId) {
895
981
  const csvOnlyElements = [];
896
982
  let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
897
983
  const wallElements = /* @__PURE__ */ new Map();
984
+ const renderSources = [
985
+ { path: layout.globalDir },
986
+ { path: levelDir.path }
987
+ ];
898
988
  for (const tableName of RENDER_ORDER) {
899
989
  if (CSV_ONLY_TABLES.has(tableName)) continue;
900
990
  const svgName = SVG_FILE_NAMES[tableName];
901
991
  if (!svgName) continue;
902
- const svgPath = join13(levelDir.path, svgName + ".svg");
903
- if (!existsSync12(svgPath)) continue;
904
- const svg = parseSvgFile(svgPath);
905
- for (const el of svg.elements) {
906
- allElements.push({ tableName, el });
907
- if (tableName === "wall") wallElements.set(el.id, el);
908
- const b = elementBounds2(el);
909
- if (b) {
910
- minX = Math.min(minX, b.minX);
911
- minY = Math.min(minY, b.minY);
912
- maxX = Math.max(maxX, b.maxX);
913
- maxY = Math.max(maxY, b.maxY);
992
+ for (const src of renderSources) {
993
+ const svgPath = join13(src.path, svgName + ".svg");
994
+ if (!existsSync12(svgPath)) continue;
995
+ const svg = parseSvgFile(svgPath);
996
+ for (const el of svg.elements) {
997
+ allElements.push({ tableName, el });
998
+ if (tableName === "wall") wallElements.set(el.id, el);
999
+ const b = elementBounds2(el);
1000
+ if (b) {
1001
+ minX = Math.min(minX, b.minX);
1002
+ minY = Math.min(minY, b.minY);
1003
+ maxX = Math.max(maxX, b.maxX);
1004
+ maxY = Math.max(maxY, b.maxY);
1005
+ }
914
1006
  }
915
1007
  }
916
1008
  }
@@ -2419,18 +2511,21 @@ import { join as join6 } from "path";
2419
2511
  var TOLERANCE = 0.01;
2420
2512
  var MAX_FACE_EDGES = 1e4;
2421
2513
  var BOUNDARY_TABLES = ["wall", "structure_wall", "curtain_wall", "room_separator"];
2422
- function computeSpaceBoundaries(levelDir) {
2514
+ function computeSpaceBoundaries(levelDir, globalDir) {
2423
2515
  const warnings = [];
2424
2516
  const spaceCsvPath = join6(levelDir.path, "space.csv");
2425
2517
  if (!existsSync5(spaceCsvPath)) return { warnings, svgWritten: false };
2426
2518
  const spaceCsv = readCsv(spaceCsvPath);
2427
2519
  if (spaceCsv.rows.length === 0) return { warnings, svgWritten: false };
2428
2520
  const segments = collectBoundarySegments(levelDir.path);
2521
+ if (globalDir) {
2522
+ segments.push(...collectBoundarySegments(globalDir));
2523
+ }
2429
2524
  if (segments.length === 0) {
2430
2525
  warnings.push(`${levelDir.name}/ no boundary elements found for space boundary computation`);
2431
2526
  return { warnings, svgWritten: false };
2432
2527
  }
2433
- const splitSegments = splitAtTJunctions(segments);
2528
+ const splitSegments = splitAtIntersections(segments);
2434
2529
  const { vertices, halfEdges } = buildHalfEdgeStructure(splitSegments);
2435
2530
  for (const v of vertices) {
2436
2531
  if (v.outgoing.length === 1) {
@@ -2491,24 +2586,19 @@ function collectBoundarySegments(levelPath) {
2491
2586
  }
2492
2587
  return segments;
2493
2588
  }
2494
- function splitAtTJunctions(segments) {
2495
- const endpoints = [];
2496
- for (const seg of segments) {
2497
- endpoints.push({ x: seg.startX, y: seg.startY });
2498
- endpoints.push({ x: seg.endX, y: seg.endY });
2499
- }
2589
+ function splitAtIntersections(segments) {
2500
2590
  let result = [...segments];
2501
2591
  let changed = true;
2502
2592
  while (changed) {
2503
2593
  changed = false;
2504
- const nextResult = [];
2505
2594
  const allEndpoints = [];
2506
2595
  for (const seg of result) {
2507
2596
  allEndpoints.push({ x: seg.startX, y: seg.startY });
2508
2597
  allEndpoints.push({ x: seg.endX, y: seg.endY });
2509
2598
  }
2510
- for (const seg of result) {
2511
- const splitPoints = [];
2599
+ const nextResult = [];
2600
+ for (let i = 0; i < result.length; i++) {
2601
+ const seg = result[i];
2512
2602
  const dx = seg.endX - seg.startX;
2513
2603
  const dy = seg.endY - seg.startY;
2514
2604
  const lenSq = dx * dx + dy * dy;
@@ -2516,6 +2606,7 @@ function splitAtTJunctions(segments) {
2516
2606
  nextResult.push(seg);
2517
2607
  continue;
2518
2608
  }
2609
+ const splitPoints = [];
2519
2610
  for (const ep of allEndpoints) {
2520
2611
  if (Math.abs(ep.x - seg.startX) < TOLERANCE && Math.abs(ep.y - seg.startY) < TOLERANCE) continue;
2521
2612
  if (Math.abs(ep.x - seg.endX) < TOLERANCE && Math.abs(ep.y - seg.endY) < TOLERANCE) continue;
@@ -2528,15 +2619,34 @@ function splitAtTJunctions(segments) {
2528
2619
  splitPoints.push({ x: ep.x, y: ep.y, t });
2529
2620
  }
2530
2621
  }
2622
+ for (let j = 0; j < result.length; j++) {
2623
+ if (j === i) continue;
2624
+ const other = result[j];
2625
+ const ox = other.endX - other.startX;
2626
+ const oy = other.endY - other.startY;
2627
+ const det = dx * oy - dy * ox;
2628
+ if (Math.abs(det) < 1e-12) continue;
2629
+ const rx = other.startX - seg.startX;
2630
+ const ry = other.startY - seg.startY;
2631
+ const t = (rx * oy - ry * ox) / det;
2632
+ const s = (rx * dy - ry * dx) / det;
2633
+ if (t <= TOLERANCE || t >= 1 - TOLERANCE) continue;
2634
+ if (s <= TOLERANCE || s >= 1 - TOLERANCE) continue;
2635
+ splitPoints.push({
2636
+ x: seg.startX + t * dx,
2637
+ y: seg.startY + t * dy,
2638
+ t
2639
+ });
2640
+ }
2531
2641
  if (splitPoints.length === 0) {
2532
2642
  nextResult.push(seg);
2533
2643
  } else {
2534
2644
  changed = true;
2535
2645
  splitPoints.sort((a, b) => a.t - b.t);
2536
2646
  const unique = [splitPoints[0]];
2537
- for (let i = 1; i < splitPoints.length; i++) {
2538
- if (Math.abs(splitPoints[i].t - unique[unique.length - 1].t) > TOLERANCE) {
2539
- unique.push(splitPoints[i]);
2647
+ for (let k = 1; k < splitPoints.length; k++) {
2648
+ if (Math.abs(splitPoints[k].t - unique[unique.length - 1].t) > TOLERANCE) {
2649
+ unique.push(splitPoints[k]);
2540
2650
  }
2541
2651
  }
2542
2652
  let prevX = seg.startX, prevY = seg.startY;
@@ -2970,11 +3080,13 @@ function findNearestWall(px, py, walls, preferredHostId) {
2970
3080
 
2971
3081
  // src/build/snap-endpoints.ts
2972
3082
  init_svg();
3083
+ init_csv();
2973
3084
  init_fs();
2974
3085
  import { existsSync as existsSync8, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
2975
3086
  import { join as join9 } from "path";
2976
- var SNAP_TOLERANCE = 0.05;
3087
+ var MIN_SNAP_TOLERANCE = 0.1;
2977
3088
  var BOUNDARY_TABLES3 = ["wall", "structure_wall", "curtain_wall", "room_separator"];
3089
+ var WALL_TABLES_WITH_THICKNESS = ["wall", "structure_wall", "curtain_wall"];
2978
3090
  function snapEndpoints(dir) {
2979
3091
  const layout = discoverLayout(dir);
2980
3092
  const allDirs = [
@@ -2982,9 +3094,10 @@ function snapEndpoints(dir) {
2982
3094
  ...layout.levelDirs
2983
3095
  ];
2984
3096
  let totalSnapped = 0;
3097
+ const snapTolerance = computeSnapTolerance(allDirs);
3098
+ const allEndpoints = [];
2985
3099
  for (const d of allDirs) {
2986
3100
  if (!existsSync8(d.path)) continue;
2987
- const endpoints = [];
2988
3101
  for (const table of BOUNDARY_TABLES3) {
2989
3102
  const svgPath = join9(d.path, `${table}.svg`);
2990
3103
  if (!existsSync8(svgPath)) continue;
@@ -2993,29 +3106,32 @@ function snapEndpoints(dir) {
2993
3106
  for (const el of svg.elements) {
2994
3107
  if (el.tag !== "path") continue;
2995
3108
  const geo = extractLineGeometry(el);
2996
- endpoints.push({ point: { x: geo.start_x, y: geo.start_y }, table, elementId: el.id, side: "start", levelDir: d.name, levelPath: d.path });
2997
- endpoints.push({ point: { x: geo.end_x, y: geo.end_y }, table, elementId: el.id, side: "end", levelDir: d.name, levelPath: d.path });
3109
+ allEndpoints.push({ point: { x: geo.start_x, y: geo.start_y }, table, elementId: el.id, side: "start", levelDir: d.name, levelPath: d.path });
3110
+ allEndpoints.push({ point: { x: geo.end_x, y: geo.end_y }, table, elementId: el.id, side: "end", levelDir: d.name, levelPath: d.path });
2998
3111
  }
2999
3112
  } catch {
3000
3113
  }
3001
3114
  }
3002
- if (endpoints.length === 0) continue;
3003
- const clusters = clusterEndpoints(endpoints);
3004
- const snapMap = /* @__PURE__ */ new Map();
3005
- for (const cluster of clusters) {
3006
- if (cluster.length <= 1) continue;
3007
- const canonical = pickCanonical(cluster);
3008
- for (const ep of cluster) {
3009
- const dx = Math.abs(ep.point.x - canonical.x);
3010
- const dy = Math.abs(ep.point.y - canonical.y);
3011
- if (dx > 1e-6 || dy > 1e-6) {
3012
- const key = `${ep.table}:${ep.elementId}:${ep.side}`;
3013
- snapMap.set(key, canonical);
3014
- totalSnapped++;
3015
- }
3115
+ }
3116
+ if (allEndpoints.length === 0) return 0;
3117
+ const clusters = clusterEndpoints(allEndpoints, snapTolerance);
3118
+ const snapMap = /* @__PURE__ */ new Map();
3119
+ for (const cluster of clusters) {
3120
+ if (cluster.length <= 1) continue;
3121
+ const canonical = pickCanonical(cluster);
3122
+ for (const ep of cluster) {
3123
+ const dx = Math.abs(ep.point.x - canonical.x);
3124
+ const dy = Math.abs(ep.point.y - canonical.y);
3125
+ if (dx > 1e-6 || dy > 1e-6) {
3126
+ const key = `${ep.levelPath}:${ep.table}:${ep.elementId}:${ep.side}`;
3127
+ snapMap.set(key, canonical);
3128
+ totalSnapped++;
3016
3129
  }
3017
3130
  }
3018
- if (snapMap.size === 0) continue;
3131
+ }
3132
+ if (snapMap.size === 0) return 0;
3133
+ for (const d of allDirs) {
3134
+ if (!existsSync8(d.path)) continue;
3019
3135
  for (const table of BOUNDARY_TABLES3) {
3020
3136
  const svgPath = join9(d.path, `${table}.svg`);
3021
3137
  if (!existsSync8(svgPath)) continue;
@@ -3026,8 +3142,8 @@ function snapEndpoints(dir) {
3026
3142
  for (const el of svg.elements) {
3027
3143
  if (el.tag !== "path") continue;
3028
3144
  const geo = extractLineGeometry(el);
3029
- const startKey = `${table}:${el.id}:start`;
3030
- const endKey = `${table}:${el.id}:end`;
3145
+ const startKey = `${d.path}:${table}:${el.id}:start`;
3146
+ const endKey = `${d.path}:${table}:${el.id}:end`;
3031
3147
  const newStart = snapMap.get(startKey);
3032
3148
  const newEnd = snapMap.get(endKey);
3033
3149
  if (!newStart && !newEnd) continue;
@@ -3052,7 +3168,27 @@ function snapEndpoints(dir) {
3052
3168
  }
3053
3169
  return totalSnapped;
3054
3170
  }
3055
- function clusterEndpoints(endpoints) {
3171
+ function computeSnapTolerance(dirs) {
3172
+ let maxThickness = 0;
3173
+ for (const d of dirs) {
3174
+ if (!existsSync8(d.path)) continue;
3175
+ for (const table of WALL_TABLES_WITH_THICKNESS) {
3176
+ const csvPath = join9(d.path, `${table}.csv`);
3177
+ if (!existsSync8(csvPath)) continue;
3178
+ try {
3179
+ const csv = readCsv(csvPath);
3180
+ for (const row of csv.rows) {
3181
+ const t = parseFloat(row.thickness ?? "0");
3182
+ if (t > maxThickness) maxThickness = t;
3183
+ }
3184
+ } catch {
3185
+ }
3186
+ }
3187
+ }
3188
+ const tolerance = Math.max(MIN_SNAP_TOLERANCE, maxThickness);
3189
+ return tolerance;
3190
+ }
3191
+ function clusterEndpoints(endpoints, tolerance) {
3056
3192
  const visited = /* @__PURE__ */ new Set();
3057
3193
  const clusters = [];
3058
3194
  for (let i = 0; i < endpoints.length; i++) {
@@ -3065,7 +3201,7 @@ function clusterEndpoints(endpoints) {
3065
3201
  for (let j = 0; j < endpoints.length; j++) {
3066
3202
  if (visited.has(j)) continue;
3067
3203
  for (const member of cluster) {
3068
- if (dist(member.point, endpoints[j].point) < SNAP_TOLERANCE) {
3204
+ if (dist(member.point, endpoints[j].point) < tolerance) {
3069
3205
  cluster.push(endpoints[j]);
3070
3206
  visited.add(j);
3071
3207
  expanded = true;
@@ -3127,7 +3263,7 @@ function build(dir) {
3127
3263
  for (const levelDir of layout.levelDirs) {
3128
3264
  const spaceCsvPath = join10(levelDir.path, "space.csv");
3129
3265
  if (!existsSync9(spaceCsvPath)) continue;
3130
- const result = computeSpaceBoundaries(levelDir);
3266
+ const result = computeSpaceBoundaries(levelDir, layout.globalDir);
3131
3267
  warnings.push(...result.warnings);
3132
3268
  if (result.svgWritten) {
3133
3269
  artifacts.push(`${levelDir.name}/space.svg`);
@@ -3143,7 +3279,7 @@ init_csv();
3143
3279
  import { existsSync as existsSync18, writeFileSync as writeFileSync7 } from "fs";
3144
3280
  import { join as join18 } from "path";
3145
3281
  var program = new Command();
3146
- program.name("bimdown").description("BimDown CLI \u2014 build, query, and manage BimDown projects").version(true ? "0.3.0" : "0.0.0");
3282
+ program.name("bimdown").description("BimDown CLI \u2014 build, query, and manage BimDown projects").version(true ? "0.4.0" : "0.0.0");
3147
3283
  function runBuild(dir) {
3148
3284
  const absDir = resolve2(dir);
3149
3285
  const result = build(absDir);
@@ -3163,7 +3299,7 @@ ${result.issues.length} issue(s) found.`);
3163
3299
  ${result.warnings.length} warning(s).`);
3164
3300
  }
3165
3301
  if (result.snappedEndpoints > 0) {
3166
- console.log(`Snapped ${result.snappedEndpoints} endpoint(s) (within 5cm tolerance).`);
3302
+ console.log(`Snapped ${result.snappedEndpoints} endpoint(s).`);
3167
3303
  }
3168
3304
  if (result.artifacts.length > 0) {
3169
3305
  console.log(`
@@ -3207,7 +3343,7 @@ program.command("sync").argument("<dir>", "BimDown project directory").descripti
3207
3343
  await closeConnection2();
3208
3344
  }
3209
3345
  });
3210
- program.command("render").argument("<dir>", "BimDown project directory").option("-l, --level <id>", "Level to render (defaults to lv-1)", "lv-1").option("-o, --output <file>", "Output file path (defaults to render.png)", "render.png").option("-w, --width <px>", "Image width in pixels", "2048").description("Renders the BimDown project into a visual blueprint (PNG)").action(async (dir, opts) => {
3346
+ program.command("render").argument("<dir>", "BimDown project directory").option("-l, --level <id>", "Level to render (defaults to lv-1)", "lv-1").option("-o, --output <file>", "Output file path (defaults to render.png)", "render.png").option("-w, --width <px>", "Image width in pixels", "2048").description("Renders the BimDown project into a visual blueprint (PNG). Color legend: walls=dark navy, structural walls=slate, columns=dark filled, slabs=light grey translucent, spaces=blue translucent, stairs=orange, beams=purple. DOORS render as BOLD RED (#e63946) lines and WINDOWS as BOLD TEAL (#2a9d8f) lines cutting across their host walls. MEP: ducts=cyan, pipes=light blue, cable tray=green, conduit=teal, equipment=red fill, terminals=orange fill.").action(async (dir, opts) => {
3211
3347
  const absDir = resolve2(dir);
3212
3348
  const { renderLevel: renderLevel2 } = await Promise.resolve().then(() => (init_render(), render_exports));
3213
3349
  try {
@@ -3363,4 +3499,4 @@ function jsonReplacer(_key, value) {
3363
3499
  if (typeof value === "bigint") return Number(value);
3364
3500
  return value;
3365
3501
  }
3366
- //# sourceMappingURL=index.js.map
3502
+ //# sourceMappingURL=cli.js.map