/* 표 기하(`openwebcad/src/helpers/table-geometry.ts`) 거울 헬퍼 — 서버 DXF `table_parts` 와 대조. * stdin JSON [표 shapeData] → stdout JSON [{lines, texts}] (TS 규칙 그대로). */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const file = path.join( __dirname, "..", "..", "B07_DesignDetail", "openwebcad", "src", "helpers", "table-geometry.ts", ); const js = ts.transpileModule(fs.readFileSync(file, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; new Function("exports", "module", "require", js)(box.exports, box, require); const g = box.exports; const shapes = JSON.parse(fs.readFileSync(0, "utf8")); const out = shapes.map((s) => { const lines = g .tableBorders(s.origin, s.columnWidths, s.rowHeights, s.cells) .map((b) => [b.x1, b.y1, b.x2, b.y2]); const padding = s.style?.padding ?? 1; const texts = []; for (let row = 0; row < s.rowHeights.length; row += 1) for (let column = 0; column < s.columnWidths.length; column += 1) { const cell = s.cells[row]?.[column]; if (!cell?.text) continue; const rect = g.cellRect(s.origin, s.columnWidths, s.rowHeights, row, column, cell); const at = g.cellTextAnchor(rect, cell.align, padding); texts.push({ text: cell.text, x: at.x, y: at.y, align: cell.align ?? "center" }); } return { lines, texts }; }); process.stdout.write(JSON.stringify(out));