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.
package/dist/lib.d.ts ADDED
@@ -0,0 +1,109 @@
1
+ export { default as Coordinate } from 'jsts/org/locationtech/jts/geom/Coordinate.js';
2
+ export { default as GeometryFactory } from 'jsts/org/locationtech/jts/geom/GeometryFactory.js';
3
+
4
+ interface SvgElement {
5
+ tag: string;
6
+ id: string;
7
+ attrs: Record<string, string>;
8
+ }
9
+ interface SvgFile {
10
+ elements: SvgElement[];
11
+ allTags: string[];
12
+ hasYFlip: boolean;
13
+ raw: unknown;
14
+ }
15
+ declare function parseSvgFile(filePath: string): SvgFile;
16
+ interface LineGeometry {
17
+ start_x: number;
18
+ start_y: number;
19
+ end_x: number;
20
+ end_y: number;
21
+ length: number;
22
+ thickness: number;
23
+ }
24
+ interface RectGeometry {
25
+ x: number;
26
+ y: number;
27
+ rotation: number;
28
+ size_x: number;
29
+ size_y: number;
30
+ }
31
+ interface PolygonGeometry {
32
+ points: string;
33
+ area: number;
34
+ }
35
+ interface CircleGeometry {
36
+ x: number;
37
+ y: number;
38
+ size_x: number;
39
+ size_y: number;
40
+ }
41
+ declare function extractLineGeometry(el: SvgElement): LineGeometry;
42
+ declare function extractRectGeometry(el: SvgElement): RectGeometry;
43
+ declare function extractPolygonGeometry(el: SvgElement): PolygonGeometry;
44
+ declare function extractCircleGeometry(el: SvgElement): CircleGeometry;
45
+
46
+ /**
47
+ * Structural interface describing the subset of JSTS Geometry methods used by
48
+ * this toolkit. We don't pull in real JSTS types (jsts has no .d.ts), but
49
+ * consumers still get autocomplete for the common operations.
50
+ */
51
+ interface JstsGeometry {
52
+ getGeometryType(): 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | (string & {});
53
+ getCoordinates(): {
54
+ x: number;
55
+ y: number;
56
+ }[];
57
+ getCoordinate(): {
58
+ x: number;
59
+ y: number;
60
+ };
61
+ getEnvelopeInternal(): {
62
+ getMinX(): number;
63
+ getMinY(): number;
64
+ getMaxX(): number;
65
+ getMaxY(): number;
66
+ };
67
+ getNumGeometries(): number;
68
+ getGeometryN(i: number): JstsGeometry;
69
+ getExteriorRing(): JstsGeometry;
70
+ intersection(other: JstsGeometry): JstsGeometry;
71
+ union(other: JstsGeometry): JstsGeometry;
72
+ difference(other: JstsGeometry): JstsGeometry;
73
+ symDifference(other: JstsGeometry): JstsGeometry;
74
+ buffer(distance: number): JstsGeometry;
75
+ contains(other: JstsGeometry): boolean;
76
+ intersects(other: JstsGeometry): boolean;
77
+ isEmpty(): boolean;
78
+ }
79
+ type BimDownGeometry = JstsGeometry;
80
+ type GeometryMap = Map<string, BimDownGeometry>;
81
+ /**
82
+ * Convert a single SVG element to a JSTS geometry.
83
+ * Returns null if the element type is not supported.
84
+ */
85
+ declare function svgToJsts(el: SvgElement): BimDownGeometry | null;
86
+ /**
87
+ * Convert a JSTS geometry back to an SVG element string (inner content only — no <svg> wrapper).
88
+ * Determines the SVG tag from the geometry type:
89
+ * - LineString → <path d="M x,y L x,y" />
90
+ * - Polygon → <polygon points="x,y x,y ..." />
91
+ * - Point → <circle cx cy r="0.15" /> (default radius, caller may override attributes)
92
+ * - Multi* / GeometryCollection → emits multiple elements with id suffixes a, b, c, ...
93
+ */
94
+ declare function jstsToSvg(id: string, geom: BimDownGeometry, extraAttrs?: Record<string, string>): string;
95
+ /**
96
+ * Read an entire BimDown SVG file and return a Map of element id → JSTS geometry.
97
+ *
98
+ * All geometries are in the same Cartesian coordinate system as the SVG
99
+ * (after the `<g transform="scale(1,-1)">` flip — i.e. Y-up meters).
100
+ */
101
+ declare function readBimDownGeometry(filePath: string): GeometryMap;
102
+ /**
103
+ * Write a GeometryMap back to an SVG file. Computes a tight viewBox from the
104
+ * geometries. Preserves the standard BimDown `<g transform="scale(1,-1)">`
105
+ * wrapper and Y-up coordinate convention.
106
+ */
107
+ declare function writeBimDownGeometry(filePath: string, geometries: GeometryMap): void;
108
+
109
+ export { type BimDownGeometry, type GeometryMap, type SvgElement, type SvgFile, extractCircleGeometry, extractLineGeometry, extractPolygonGeometry, extractRectGeometry, jstsToSvg, parseSvgFile, readBimDownGeometry, svgToJsts, writeBimDownGeometry };
package/dist/lib.js ADDED
@@ -0,0 +1,271 @@
1
+ // src/geo/index.ts
2
+ import { writeFileSync } from "fs";
3
+
4
+ // src/utils/svg.ts
5
+ import { readFileSync } from "fs";
6
+ import { XMLParser } from "fast-xml-parser";
7
+ var parser = new XMLParser({
8
+ ignoreAttributes: false,
9
+ attributeNamePrefix: "@_",
10
+ allowBooleanAttributes: true,
11
+ parseAttributeValue: false,
12
+ trimValues: true
13
+ });
14
+ function parseSvgFile(filePath) {
15
+ let text = readFileSync(filePath, "utf-8");
16
+ if (text.charCodeAt(0) === 65279) text = text.slice(1);
17
+ const parsed = parser.parse(text);
18
+ const elements = [];
19
+ const allTags = [];
20
+ let hasYFlip = false;
21
+ function walk(node, tag) {
22
+ if (!node || typeof node !== "object") return;
23
+ if (tag) allTags.push(tag);
24
+ if (tag === "g") {
25
+ const transform = node["@_transform"] ?? "";
26
+ if (typeof transform === "string" && transform.includes("scale(1,-1)")) {
27
+ hasYFlip = true;
28
+ }
29
+ }
30
+ const geoTags = ["path", "line", "rect", "polygon", "circle", "text"];
31
+ if (tag && geoTags.includes(tag)) {
32
+ const attrs = {};
33
+ for (const [k, v] of Object.entries(node)) {
34
+ if (k.startsWith("@_")) {
35
+ attrs[k.slice(2)] = String(v);
36
+ }
37
+ }
38
+ if (attrs.id) {
39
+ elements.push({ tag, id: attrs.id, attrs });
40
+ }
41
+ }
42
+ for (const [key, value] of Object.entries(node)) {
43
+ if (key.startsWith("@_") || key.startsWith("?")) continue;
44
+ if (Array.isArray(value)) {
45
+ for (const item of value) walk(item, key);
46
+ } else if (typeof value === "object" && value !== null) {
47
+ walk(value, key);
48
+ }
49
+ }
50
+ }
51
+ walk(parsed);
52
+ return { elements, allTags, hasYFlip, raw: parsed };
53
+ }
54
+ function extractLineGeometry(el) {
55
+ let x1, y1, x2, y2;
56
+ if (el.tag === "path") {
57
+ const d = el.attrs.d ?? "";
58
+ const m = d.match(/M\s*(-?[\d.]+)[,\s]+(-?[\d.]+)\s*L\s*(-?[\d.]+)[,\s]+(-?[\d.]+)/);
59
+ if (m) {
60
+ x1 = parseFloat(m[1]);
61
+ y1 = parseFloat(m[2]);
62
+ x2 = parseFloat(m[3]);
63
+ y2 = parseFloat(m[4]);
64
+ } else {
65
+ x1 = y1 = x2 = y2 = 0;
66
+ }
67
+ } else {
68
+ x1 = parseFloat(el.attrs.x1 ?? "0");
69
+ y1 = parseFloat(el.attrs.y1 ?? "0");
70
+ x2 = parseFloat(el.attrs.x2 ?? "0");
71
+ y2 = parseFloat(el.attrs.y2 ?? "0");
72
+ }
73
+ const dx = x2 - x1;
74
+ const dy = y2 - y1;
75
+ return {
76
+ start_x: x1,
77
+ start_y: y1,
78
+ end_x: x2,
79
+ end_y: y2,
80
+ length: Math.sqrt(dx * dx + dy * dy),
81
+ thickness: 0
82
+ };
83
+ }
84
+ function extractRectGeometry(el) {
85
+ const x = parseFloat(el.attrs.x ?? "0");
86
+ const y = parseFloat(el.attrs.y ?? "0");
87
+ const w = parseFloat(el.attrs.width ?? "0");
88
+ const h = parseFloat(el.attrs.height ?? "0");
89
+ let rotation = 0;
90
+ const transform = el.attrs.transform;
91
+ if (transform) {
92
+ const m = transform.match(/rotate\(([^,)]+)/);
93
+ if (m) rotation = parseFloat(m[1]);
94
+ }
95
+ return {
96
+ x: x + w / 2,
97
+ y: y + h / 2,
98
+ rotation,
99
+ size_x: w,
100
+ size_y: h
101
+ };
102
+ }
103
+ function extractPolygonGeometry(el) {
104
+ const pointsStr = el.attrs.points ?? "";
105
+ const coords = pointsStr.trim().split(/\s+/).map((p) => {
106
+ const [x, y] = p.split(",").map(Number);
107
+ return { x: x ?? 0, y: y ?? 0 };
108
+ });
109
+ let area = 0;
110
+ for (let i = 0; i < coords.length; i++) {
111
+ const j = (i + 1) % coords.length;
112
+ area += coords[i].x * coords[j].y;
113
+ area -= coords[j].x * coords[i].y;
114
+ }
115
+ return { points: pointsStr, area: Math.abs(area) / 2 };
116
+ }
117
+ function extractCircleGeometry(el) {
118
+ const cx = parseFloat(el.attrs.cx ?? "0");
119
+ const cy = parseFloat(el.attrs.cy ?? "0");
120
+ const r = parseFloat(el.attrs.r ?? "0");
121
+ return { x: cx, y: cy, size_x: r * 2, size_y: r * 2 };
122
+ }
123
+
124
+ // src/geo/jsts-exports.ts
125
+ import "jsts/org/locationtech/jts/monkey.js";
126
+ import Coordinate from "jsts/org/locationtech/jts/geom/Coordinate.js";
127
+ import GeometryFactory from "jsts/org/locationtech/jts/geom/GeometryFactory.js";
128
+
129
+ // src/geo/index.ts
130
+ var factory = new GeometryFactory();
131
+ function svgToJsts(el) {
132
+ switch (el.tag) {
133
+ case "path": {
134
+ const geo = extractLineGeometry(el);
135
+ return factory.createLineString([
136
+ new Coordinate(geo.start_x, geo.start_y),
137
+ new Coordinate(geo.end_x, geo.end_y)
138
+ ]);
139
+ }
140
+ case "polygon": {
141
+ const geo = extractPolygonGeometry(el);
142
+ const pts = geo.points.trim().split(/\s+/).map((p) => {
143
+ const [x, y] = p.split(",").map(Number);
144
+ return new Coordinate(x ?? 0, y ?? 0);
145
+ });
146
+ if (pts.length > 0) {
147
+ const first = pts[0];
148
+ const last = pts[pts.length - 1];
149
+ if (first.x !== last.x || first.y !== last.y) {
150
+ pts.push(new Coordinate(first.x, first.y));
151
+ }
152
+ }
153
+ if (pts.length < 4) return null;
154
+ return factory.createPolygon(factory.createLinearRing(pts));
155
+ }
156
+ case "rect": {
157
+ const x = parseFloat(el.attrs.x ?? "0");
158
+ const y = parseFloat(el.attrs.y ?? "0");
159
+ const w = parseFloat(el.attrs.width ?? "0");
160
+ const h = parseFloat(el.attrs.height ?? "0");
161
+ const pts = [
162
+ new Coordinate(x, y),
163
+ new Coordinate(x + w, y),
164
+ new Coordinate(x + w, y + h),
165
+ new Coordinate(x, y + h),
166
+ new Coordinate(x, y)
167
+ ];
168
+ return factory.createPolygon(factory.createLinearRing(pts));
169
+ }
170
+ case "circle": {
171
+ const cx = parseFloat(el.attrs.cx ?? "0");
172
+ const cy = parseFloat(el.attrs.cy ?? "0");
173
+ return factory.createPoint(new Coordinate(cx, cy));
174
+ }
175
+ default:
176
+ return null;
177
+ }
178
+ }
179
+ function jstsToSvg(id, geom, extraAttrs = {}) {
180
+ const attrs = { id, ...extraAttrs };
181
+ const attrStr = (a) => Object.entries(a).map(([k, v]) => `${k}="${v}"`).join(" ");
182
+ const type = geom.getGeometryType();
183
+ switch (type) {
184
+ case "LineString": {
185
+ const coords = geom.getCoordinates();
186
+ if (coords.length < 2) return "";
187
+ const d = `M ${fmt(coords[0].x)},${fmt(coords[0].y)} L ${fmt(coords[coords.length - 1].x)},${fmt(coords[coords.length - 1].y)}`;
188
+ return `<path ${attrStr({ ...attrs, d })} />`;
189
+ }
190
+ case "Polygon": {
191
+ const ring = geom.getExteriorRing();
192
+ const coords = ring.getCoordinates();
193
+ const pts = coords.slice(0, coords.length - 1);
194
+ const pointsStr = pts.map((c) => `${fmt(c.x)},${fmt(c.y)}`).join(" ");
195
+ return `<polygon ${attrStr({ ...attrs, points: pointsStr })} />`;
196
+ }
197
+ case "Point": {
198
+ const c = geom.getCoordinate();
199
+ const r = extraAttrs.r ?? "0.15";
200
+ return `<circle ${attrStr({ ...attrs, cx: fmt(c.x), cy: fmt(c.y), r })} />`;
201
+ }
202
+ }
203
+ const n = typeof geom.getNumGeometries === "function" ? geom.getNumGeometries() : 0;
204
+ if (n === 1) {
205
+ return jstsToSvg(id, geom.getGeometryN(0), extraAttrs);
206
+ }
207
+ if (n > 1) {
208
+ const parts = [];
209
+ for (let i = 0; i < n; i++) {
210
+ const suffix = String.fromCharCode(97 + i);
211
+ parts.push(jstsToSvg(`${id}${suffix}`, geom.getGeometryN(i), extraAttrs));
212
+ }
213
+ return parts.filter(Boolean).join("\n ");
214
+ }
215
+ return "";
216
+ }
217
+ function readBimDownGeometry(filePath) {
218
+ const svg = parseSvgFile(filePath);
219
+ const map = /* @__PURE__ */ new Map();
220
+ for (const el of svg.elements) {
221
+ if (!el.id) continue;
222
+ const geom = svgToJsts(el);
223
+ if (geom) map.set(el.id, geom);
224
+ }
225
+ return map;
226
+ }
227
+ function writeBimDownGeometry(filePath, geometries) {
228
+ const innerElements = [];
229
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
230
+ for (const [id, geom] of geometries) {
231
+ const svgEl = jstsToSvg(id, geom);
232
+ if (svgEl) innerElements.push(svgEl);
233
+ const env = geom.getEnvelopeInternal();
234
+ minX = Math.min(minX, env.getMinX());
235
+ minY = Math.min(minY, env.getMinY());
236
+ maxX = Math.max(maxX, env.getMaxX());
237
+ maxY = Math.max(maxY, env.getMaxY());
238
+ }
239
+ const pad = Math.max(maxX - minX, maxY - minY) * 0.02;
240
+ const vbX = isFinite(minX) ? minX - pad : 0;
241
+ const vbY = isFinite(minY) ? -(maxY + pad) : 0;
242
+ const vbW = isFinite(maxX) ? maxX - minX + pad * 2 : 100;
243
+ const vbH = isFinite(maxY) ? maxY - minY + pad * 2 : 100;
244
+ const svg = [
245
+ '<?xml version="1.0" encoding="utf-8"?>',
246
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${fmt(vbX)} ${fmt(vbY)} ${fmt(vbW)} ${fmt(vbH)}">`,
247
+ ' <g transform="scale(1,-1)">',
248
+ ...innerElements.map((e) => " " + e),
249
+ " </g>",
250
+ "</svg>"
251
+ ].join("\n");
252
+ writeFileSync(filePath, svg, "utf-8");
253
+ }
254
+ function fmt(n) {
255
+ if (!isFinite(n)) return "0";
256
+ return Number(n.toFixed(3)).toString();
257
+ }
258
+ export {
259
+ Coordinate,
260
+ GeometryFactory,
261
+ extractCircleGeometry,
262
+ extractLineGeometry,
263
+ extractPolygonGeometry,
264
+ extractRectGeometry,
265
+ jstsToSvg,
266
+ parseSvgFile,
267
+ readBimDownGeometry,
268
+ svgToJsts,
269
+ writeBimDownGeometry
270
+ };
271
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/geo/index.ts","../src/utils/svg.ts","../src/geo/jsts-exports.ts"],"sourcesContent":["/**\n * BimDown geometry toolkit — bridges SVG files and JSTS computational geometry.\n *\n * AI agents and scripts can use this to:\n * - Load all geometry from a BimDown SVG file as JSTS geometries\n * - Perform computational geometry operations (buffer, split, boolean ops)\n * - Write results back to SVG files\n *\n * Example:\n * import { readBimDownGeometry, writeBimDownGeometry, GeometryFactory, Coordinate } from 'bimdown-cli';\n *\n * const slabs = readBimDownGeometry('project/lv-1/slab.svg');\n * const slab = slabs.get('sl-1'); // JSTS Polygon\n *\n * const factory = new GeometryFactory();\n * const splitLine = factory.createPolygon(factory.createLinearRing([\n * new Coordinate(-1000, -1000), new Coordinate(5, -1000),\n * new Coordinate(5, 1000), new Coordinate(-1000, 1000),\n * new Coordinate(-1000, -1000),\n * ]));\n * const left = slab.intersection(splitLine);\n * const right = slab.difference(splitLine);\n *\n * slabs.delete('sl-1');\n * slabs.set('sl-1a', left);\n * slabs.set('sl-1b', right);\n * writeBimDownGeometry('project/lv-1/slab.svg', slabs);\n */\nimport { writeFileSync } from 'node:fs';\nimport { parseSvgFile, extractLineGeometry, extractRectGeometry, extractPolygonGeometry, extractCircleGeometry } from '../utils/svg.js';\nimport type { SvgElement } from '../utils/svg.js';\nimport { Coordinate, GeometryFactory } from './jsts-exports.js';\n\n/**\n * Structural interface describing the subset of JSTS Geometry methods used by\n * this toolkit. We don't pull in real JSTS types (jsts has no .d.ts), but\n * consumers still get autocomplete for the common operations.\n */\nexport interface JstsGeometry {\n getGeometryType(): 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | (string & {});\n getCoordinates(): { x: number; y: number }[];\n getCoordinate(): { x: number; y: number };\n getEnvelopeInternal(): {\n getMinX(): number;\n getMinY(): number;\n getMaxX(): number;\n getMaxY(): number;\n };\n getNumGeometries(): number;\n getGeometryN(i: number): JstsGeometry;\n getExteriorRing(): JstsGeometry;\n intersection(other: JstsGeometry): JstsGeometry;\n union(other: JstsGeometry): JstsGeometry;\n difference(other: JstsGeometry): JstsGeometry;\n symDifference(other: JstsGeometry): JstsGeometry;\n buffer(distance: number): JstsGeometry;\n contains(other: JstsGeometry): boolean;\n intersects(other: JstsGeometry): boolean;\n isEmpty(): boolean;\n}\n\nexport type BimDownGeometry = JstsGeometry;\n\nexport type GeometryMap = Map<string, BimDownGeometry>;\n\nconst factory = new GeometryFactory();\n\n/**\n * Convert a single SVG element to a JSTS geometry.\n * Returns null if the element type is not supported.\n */\nexport function svgToJsts(el: SvgElement): BimDownGeometry | null {\n switch (el.tag) {\n case 'path': {\n // Line element — parse \"M x,y L x,y\" or \"M x y L x y\"\n const geo = extractLineGeometry(el);\n return factory.createLineString([\n new Coordinate(geo.start_x, geo.start_y),\n new Coordinate(geo.end_x, geo.end_y),\n ]);\n }\n case 'polygon': {\n const geo = extractPolygonGeometry(el);\n const pts = geo.points.trim().split(/\\s+/).map((p) => {\n const [x, y] = p.split(',').map(Number);\n return new Coordinate(x ?? 0, y ?? 0);\n });\n // Close the ring if not already closed\n if (pts.length > 0) {\n const first = pts[0];\n const last = pts[pts.length - 1];\n if (first.x !== last.x || first.y !== last.y) {\n pts.push(new Coordinate(first.x, first.y));\n }\n }\n if (pts.length < 4) return null;\n return factory.createPolygon(factory.createLinearRing(pts));\n }\n case 'rect': {\n const x = parseFloat(el.attrs.x ?? '0');\n const y = parseFloat(el.attrs.y ?? '0');\n const w = parseFloat(el.attrs.width ?? '0');\n const h = parseFloat(el.attrs.height ?? '0');\n const pts = [\n new Coordinate(x, y),\n new Coordinate(x + w, y),\n new Coordinate(x + w, y + h),\n new Coordinate(x, y + h),\n new Coordinate(x, y),\n ];\n return factory.createPolygon(factory.createLinearRing(pts));\n }\n case 'circle': {\n const cx = parseFloat(el.attrs.cx ?? '0');\n const cy = parseFloat(el.attrs.cy ?? '0');\n return factory.createPoint(new Coordinate(cx, cy));\n }\n default:\n return null;\n }\n}\n\n/**\n * Convert a JSTS geometry back to an SVG element string (inner content only — no <svg> wrapper).\n * Determines the SVG tag from the geometry type:\n * - LineString → <path d=\"M x,y L x,y\" />\n * - Polygon → <polygon points=\"x,y x,y ...\" />\n * - Point → <circle cx cy r=\"0.15\" /> (default radius, caller may override attributes)\n * - Multi* / GeometryCollection → emits multiple elements with id suffixes a, b, c, ...\n */\nexport function jstsToSvg(id: string, geom: BimDownGeometry, extraAttrs: Record<string, string> = {}): string {\n const attrs = { id, ...extraAttrs };\n const attrStr = (a: Record<string, string>) =>\n Object.entries(a).map(([k, v]) => `${k}=\"${v}\"`).join(' ');\n\n const type = geom.getGeometryType();\n\n switch (type) {\n case 'LineString': {\n const coords = geom.getCoordinates();\n if (coords.length < 2) return '';\n const d = `M ${fmt(coords[0].x)},${fmt(coords[0].y)} L ${fmt(coords[coords.length - 1].x)},${fmt(coords[coords.length - 1].y)}`;\n return `<path ${attrStr({ ...attrs, d })} />`;\n }\n case 'Polygon': {\n const ring = geom.getExteriorRing();\n const coords = ring.getCoordinates();\n // Drop closing duplicate vertex\n const pts = coords.slice(0, coords.length - 1);\n const pointsStr = pts.map((c) => `${fmt(c.x)},${fmt(c.y)}`).join(' ');\n return `<polygon ${attrStr({ ...attrs, points: pointsStr })} />`;\n }\n case 'Point': {\n const c = geom.getCoordinate();\n const r = extraAttrs.r ?? '0.15';\n return `<circle ${attrStr({ ...attrs, cx: fmt(c.x), cy: fmt(c.y), r })} />`;\n }\n }\n\n // Multi* / GeometryCollection — unwrap into individual geometries.\n // 1 sub-geometry → recurse with the same id.\n // N > 1 → suffix ids with a, b, c, ...\n const n = typeof geom.getNumGeometries === 'function' ? geom.getNumGeometries() : 0;\n if (n === 1) {\n return jstsToSvg(id, geom.getGeometryN(0), extraAttrs);\n }\n if (n > 1) {\n const parts: string[] = [];\n for (let i = 0; i < n; i++) {\n const suffix = String.fromCharCode(97 + i); // a, b, c, ...\n parts.push(jstsToSvg(`${id}${suffix}`, geom.getGeometryN(i), extraAttrs));\n }\n return parts.filter(Boolean).join('\\n ');\n }\n\n return '';\n}\n\n/**\n * Read an entire BimDown SVG file and return a Map of element id → JSTS geometry.\n *\n * All geometries are in the same Cartesian coordinate system as the SVG\n * (after the `<g transform=\"scale(1,-1)\">` flip — i.e. Y-up meters).\n */\nexport function readBimDownGeometry(filePath: string): GeometryMap {\n const svg = parseSvgFile(filePath);\n const map: GeometryMap = new Map();\n for (const el of svg.elements) {\n if (!el.id) continue;\n const geom = svgToJsts(el);\n if (geom) map.set(el.id, geom);\n }\n return map;\n}\n\n/**\n * Write a GeometryMap back to an SVG file. Computes a tight viewBox from the\n * geometries. Preserves the standard BimDown `<g transform=\"scale(1,-1)\">`\n * wrapper and Y-up coordinate convention.\n */\nexport function writeBimDownGeometry(filePath: string, geometries: GeometryMap): void {\n const innerElements: string[] = [];\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n\n for (const [id, geom] of geometries) {\n const svgEl = jstsToSvg(id, geom);\n if (svgEl) innerElements.push(svgEl);\n\n const env = geom.getEnvelopeInternal();\n minX = Math.min(minX, env.getMinX());\n minY = Math.min(minY, env.getMinY());\n maxX = Math.max(maxX, env.getMaxX());\n maxY = Math.max(maxY, env.getMaxY());\n }\n\n const pad = Math.max(maxX - minX, maxY - minY) * 0.02;\n const vbX = isFinite(minX) ? minX - pad : 0;\n const vbY = isFinite(minY) ? -(maxY + pad) : 0;\n const vbW = isFinite(maxX) ? (maxX - minX) + pad * 2 : 100;\n const vbH = isFinite(maxY) ? (maxY - minY) + pad * 2 : 100;\n\n const svg = [\n '<?xml version=\"1.0\" encoding=\"utf-8\"?>',\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${fmt(vbX)} ${fmt(vbY)} ${fmt(vbW)} ${fmt(vbH)}\">`,\n ' <g transform=\"scale(1,-1)\">',\n ...innerElements.map((e) => ' ' + e),\n ' </g>',\n '</svg>',\n ].join('\\n');\n\n writeFileSync(filePath, svg, 'utf-8');\n}\n\nfunction fmt(n: number): string {\n if (!isFinite(n)) return '0';\n return Number(n.toFixed(3)).toString();\n}\n","import { readFileSync } from 'node:fs';\nimport { XMLParser } from 'fast-xml-parser';\n\nexport interface SvgElement {\n tag: string;\n id: string;\n attrs: Record<string, string>;\n}\n\nexport interface SvgFile {\n elements: SvgElement[];\n allTags: string[];\n hasYFlip: boolean;\n raw: unknown;\n}\n\nconst parser = new XMLParser({\n ignoreAttributes: false,\n attributeNamePrefix: '@_',\n allowBooleanAttributes: true,\n parseAttributeValue: false,\n trimValues: true,\n});\n\nexport function parseSvgFile(filePath: string): SvgFile {\n let text = readFileSync(filePath, 'utf-8');\n if (text.charCodeAt(0) === 0xfeff) text = text.slice(1);\n\n const parsed = parser.parse(text);\n const elements: SvgElement[] = [];\n const allTags: string[] = [];\n let hasYFlip = false;\n\n function walk(node: any, tag?: string) {\n if (!node || typeof node !== 'object') return;\n\n if (tag) allTags.push(tag);\n\n // Check for Y-axis flip\n if (tag === 'g') {\n const transform = node['@_transform'] ?? '';\n if (typeof transform === 'string' && transform.includes('scale(1,-1)')) {\n hasYFlip = true;\n }\n }\n\n // Extract geometry elements\n const geoTags = ['path', 'line', 'rect', 'polygon', 'circle', 'text'];\n if (tag && geoTags.includes(tag)) {\n const attrs: Record<string, string> = {};\n for (const [k, v] of Object.entries(node)) {\n if (k.startsWith('@_')) {\n attrs[k.slice(2)] = String(v);\n }\n }\n if (attrs.id) {\n elements.push({ tag, id: attrs.id, attrs });\n }\n }\n\n // Recurse into children\n for (const [key, value] of Object.entries(node)) {\n if (key.startsWith('@_') || key.startsWith('?')) continue;\n if (Array.isArray(value)) {\n for (const item of value) walk(item, key);\n } else if (typeof value === 'object' && value !== null) {\n walk(value, key);\n }\n }\n }\n\n walk(parsed);\n return { elements, allTags, hasYFlip, raw: parsed };\n}\n\nexport interface LineGeometry {\n start_x: number;\n start_y: number;\n end_x: number;\n end_y: number;\n length: number;\n thickness: number;\n}\n\nexport interface RectGeometry {\n x: number;\n y: number;\n rotation: number;\n size_x: number;\n size_y: number;\n}\n\nexport interface PolygonGeometry {\n points: string;\n area: number;\n}\n\nexport interface CircleGeometry {\n x: number;\n y: number;\n size_x: number;\n size_y: number;\n}\n\nexport function extractLineGeometry(el: SvgElement): LineGeometry {\n let x1: number, y1: number, x2: number, y2: number;\n\n if (el.tag === 'path') {\n // Parse \"M x1,y1 L x2,y2\"\n const d = el.attrs.d ?? '';\n const m = d.match(/M\\s*(-?[\\d.]+)[,\\s]+(-?[\\d.]+)\\s*L\\s*(-?[\\d.]+)[,\\s]+(-?[\\d.]+)/);\n if (m) {\n x1 = parseFloat(m[1]); y1 = parseFloat(m[2]);\n x2 = parseFloat(m[3]); y2 = parseFloat(m[4]);\n } else {\n x1 = y1 = x2 = y2 = 0;\n }\n } else {\n x1 = parseFloat(el.attrs.x1 ?? '0');\n y1 = parseFloat(el.attrs.y1 ?? '0');\n x2 = parseFloat(el.attrs.x2 ?? '0');\n y2 = parseFloat(el.attrs.y2 ?? '0');\n }\n\n const dx = x2 - x1;\n const dy = y2 - y1;\n return {\n start_x: x1, start_y: y1,\n end_x: x2, end_y: y2,\n length: Math.sqrt(dx * dx + dy * dy),\n thickness: 0,\n };\n}\n\nexport function extractRectGeometry(el: SvgElement): RectGeometry {\n const x = parseFloat(el.attrs.x ?? '0');\n const y = parseFloat(el.attrs.y ?? '0');\n const w = parseFloat(el.attrs.width ?? '0');\n const h = parseFloat(el.attrs.height ?? '0');\n let rotation = 0;\n const transform = el.attrs.transform;\n if (transform) {\n const m = transform.match(/rotate\\(([^,)]+)/);\n if (m) rotation = parseFloat(m[1]);\n }\n return {\n x: x + w / 2,\n y: y + h / 2,\n rotation,\n size_x: w,\n size_y: h,\n };\n}\n\nexport function extractPolygonGeometry(el: SvgElement): PolygonGeometry {\n const pointsStr = el.attrs.points ?? '';\n const coords = pointsStr.trim().split(/\\s+/).map((p) => {\n const [x, y] = p.split(',').map(Number);\n return { x: x ?? 0, y: y ?? 0 };\n });\n // Shoelace formula for area\n let area = 0;\n for (let i = 0; i < coords.length; i++) {\n const j = (i + 1) % coords.length;\n area += coords[i].x * coords[j].y;\n area -= coords[j].x * coords[i].y;\n }\n return { points: pointsStr, area: Math.abs(area) / 2 };\n}\n\nexport function extractCircleGeometry(el: SvgElement): CircleGeometry {\n const cx = parseFloat(el.attrs.cx ?? '0');\n const cy = parseFloat(el.attrs.cy ?? '0');\n const r = parseFloat(el.attrs.r ?? '0');\n return { x: cx, y: cy, size_x: r * 2, size_y: r * 2 };\n}\n\n// ─── SVG writing / merging ───────────────────────────────\n\nfunction formatSvgAttrs(attrs: Record<string, string>, idOverride?: string): string {\n const parts: string[] = [];\n for (const [k, v] of Object.entries(attrs)) {\n const val = k === 'id' && idOverride ? idOverride : v;\n parts.push(`${k}=\"${val}\"`);\n }\n return parts.join(' ');\n}\n\nfunction elementBounds(el: SvgElement): { minX: number; minY: number; maxX: number; maxY: number } {\n switch (el.tag) {\n case 'path': {\n const geo = extractLineGeometry(el);\n return {\n minX: Math.min(geo.start_x, geo.end_x), minY: Math.min(geo.start_y, geo.end_y),\n maxX: Math.max(geo.start_x, geo.end_x), maxY: Math.max(geo.start_y, geo.end_y),\n };\n }\n case 'line': {\n const x1 = parseFloat(el.attrs.x1 ?? '0'), y1 = parseFloat(el.attrs.y1 ?? '0');\n const x2 = parseFloat(el.attrs.x2 ?? '0'), y2 = parseFloat(el.attrs.y2 ?? '0');\n return { minX: Math.min(x1, x2), minY: Math.min(y1, y2), maxX: Math.max(x1, x2), maxY: Math.max(y1, y2) };\n }\n case 'rect': {\n const x = parseFloat(el.attrs.x ?? '0'), y = parseFloat(el.attrs.y ?? '0');\n const w = parseFloat(el.attrs.width ?? '0'), h = parseFloat(el.attrs.height ?? '0');\n return { minX: x, minY: y, maxX: x + w, maxY: y + h };\n }\n case 'circle': {\n const cx = parseFloat(el.attrs.cx ?? '0'), cy = parseFloat(el.attrs.cy ?? '0');\n const r = parseFloat(el.attrs.r ?? '0');\n return { minX: cx - r, minY: cy - r, maxX: cx + r, maxY: cy + r };\n }\n case 'polygon': {\n const pts = (el.attrs.points ?? '').trim().split(/\\s+/).map((p) => {\n const [x, y] = p.split(',').map(Number);\n return { x: x ?? 0, y: y ?? 0 };\n });\n if (pts.length === 0) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const p of pts) {\n minX = Math.min(minX, p.x); minY = Math.min(minY, p.y);\n maxX = Math.max(maxX, p.x); maxY = Math.max(maxY, p.y);\n }\n return { minX, minY, maxX, maxY };\n }\n default:\n return { minX: 0, minY: 0, maxX: 0, maxY: 0 };\n }\n}\n\nexport interface MergeSvgInput {\n elements: SvgElement[];\n idRemap: Map<string, string>;\n}\n\nexport function writeMergedSvg(inputs: MergeSvgInput[]): string {\n const allElements: { el: SvgElement; newId: string }[] = [];\n\n for (const input of inputs) {\n for (const el of input.elements) {\n const newId = input.idRemap.get(el.id) ?? el.id;\n allElements.push({ el, newId });\n }\n }\n\n if (allElements.length === 0) {\n return '<?xml version=\"1.0\" encoding=\"utf-8\"?>\\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 0 0\">\\n <g transform=\"scale(1,-1)\">\\n </g>\\n</svg>';\n }\n\n // Compute union viewBox from element bounds (coordinates are in flipped space)\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const { el } of allElements) {\n const b = elementBounds(el);\n minX = Math.min(minX, b.minX); minY = Math.min(minY, b.minY);\n maxX = Math.max(maxX, b.maxX); maxY = Math.max(maxY, b.maxY);\n }\n\n // viewBox uses positive-Y-up after scale(1,-1), so negate Y bounds\n const vbX = minX;\n const vbY = -maxY;\n const vbW = maxX - minX;\n const vbH = maxY - minY;\n\n const pad = Math.max(vbW, vbH) * 0.02;\n const viewBox = `${(vbX - pad).toFixed(3)} ${(vbY - pad).toFixed(3)} ${(vbW + pad * 2).toFixed(3)} ${(vbH + pad * 2).toFixed(3)}`;\n\n const lines: string[] = [\n '<?xml version=\"1.0\" encoding=\"utf-8\"?>',\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${viewBox}\">`,\n ' <g transform=\"scale(1,-1)\">',\n ];\n\n for (const { el, newId } of allElements) {\n lines.push(` <${el.tag} ${formatSvgAttrs(el.attrs, newId)} />`);\n }\n\n lines.push(' </g>');\n lines.push('</svg>');\n return lines.join('\\n');\n}\n","/**\n * Re-export commonly used JSTS classes so consumers don't need a separate\n * `jsts` dependency or figure out deep import paths.\n */\n// IMPORTANT: Importing monkey.js triggers Geometry.prototype patching with\n// intersection/union/difference/buffer/etc. Without this, these methods are missing.\n// @ts-ignore - jsts has no type definitions\nimport 'jsts/org/locationtech/jts/monkey.js';\n\n// @ts-ignore\nimport Coordinate from 'jsts/org/locationtech/jts/geom/Coordinate.js';\n// @ts-ignore\nimport GeometryFactory from 'jsts/org/locationtech/jts/geom/GeometryFactory.js';\n\nexport { Coordinate, GeometryFactory };\n"],"mappings":";AA4BA,SAAS,qBAAqB;;;AC5B9B,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAe1B,IAAM,SAAS,IAAI,UAAU;AAAA,EAC3B,kBAAkB;AAAA,EAClB,qBAAqB;AAAA,EACrB,wBAAwB;AAAA,EACxB,qBAAqB;AAAA,EACrB,YAAY;AACd,CAAC;AAEM,SAAS,aAAa,UAA2B;AACtD,MAAI,OAAO,aAAa,UAAU,OAAO;AACzC,MAAI,KAAK,WAAW,CAAC,MAAM,MAAQ,QAAO,KAAK,MAAM,CAAC;AAEtD,QAAM,SAAS,OAAO,MAAM,IAAI;AAChC,QAAM,WAAyB,CAAC;AAChC,QAAM,UAAoB,CAAC;AAC3B,MAAI,WAAW;AAEf,WAAS,KAAK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AK,IAAI,OAAO,MAAM,OAAO,IAAI,IAAI;AACjD,QAAM,MAAM,SAAS,IAAI,IAAI,OAAO,MAAM;AAC1C,QAAM,MAAM,SAAS,IAAI,IAAI,EAAE,OAAO,OAAO;AAC7C,QAAM,MAAM,SAAS,IAAI,IAAK,OAAO,OAAQ,MAAM,IAAI;AACvD,QAAM,MAAM,SAAS,IAAI,IAAK,OAAO,OAAQ,MAAM,IAAI;AAEvD,QAAM,MAAM;AAAA,IACV;AAAA,IACA,oDAAoD,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC;AAAA,IAChG;AAAA,IACA,GAAG,cAAc,IAAI,CAAC,MAAM,SAAS,CAAC;AAAA,IACtC;AAAA,IACA;AAAA,EACF,EAAE,KAAK,IAAI;AAEX,gBAAc,UAAU,KAAK,OAAO;AACtC;AAEA,SAAS,IAAI,GAAmB;AAC9B,MAAI,CAAC,SAAS,CAAC,EAAG,QAAO;AACzB,SAAO,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,SAAS;AACvC;","names":[]}
@@ -2,6 +2,11 @@ name: vertical_span
2
2
  abstract: true
3
3
 
4
4
  fields:
5
+ - name: base_level_id
6
+ type: reference
7
+ reference: level
8
+ description: Base level. Optional — usually derived from the containing directory, but required for multi-story elements stored in global/.
9
+
5
10
  - name: top_level_id
6
11
  type: reference
7
12
  reference: level
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimdown-cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "An open-source, AI-native building data format using CSV and SVG.",
5
5
  "author": "NovaShang",
6
6
  "license": "MIT",
@@ -31,10 +31,18 @@
31
31
  ],
32
32
  "type": "module",
33
33
  "bin": {
34
- "bimdown": "dist/index.js"
34
+ "bimdown": "dist/cli.js"
35
+ },
36
+ "main": "./dist/lib.js",
37
+ "types": "./dist/lib.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/lib.d.ts",
41
+ "import": "./dist/lib.js"
42
+ }
35
43
  },
36
44
  "scripts": {
37
- "build": "tsup",
45
+ "build": "rm -rf dist && tsup",
38
46
  "dev": "tsup --watch",
39
47
  "test": "vitest run",
40
48
  "test:watch": "vitest"
@@ -44,6 +52,7 @@
44
52
  "commander": "^13.1.0",
45
53
  "fast-xml-parser": "^5.2.0",
46
54
  "fflate": "^0.8.2",
55
+ "jsts": "^2.12.1",
47
56
  "sharp": "^0.34.5",
48
57
  "yaml": "^2.7.0"
49
58
  },