/* 294 물넘이 낮은 쪽 연장 · 도수로 끝단 · 띠 ↔ 사면 고름 헬퍼 — 진짜 TS 를 Node 로 돌려 JSON 한 벌로. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const ROOT = path.join(__dirname, "..", ".."); const cache = new Map(); const load = (file) => { if (cache.has(file)) return cache.get(file); const js = ts.transpileModule(fs.readFileSync(file, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; cache.set(file, box.exports); const near = (m) => { if (m.startsWith("@config/")) return load(path.join(ROOT, "config", `${m.slice(8)}.ts`)); if (m.startsWith("@util/")) return load(path.join(ROOT, "common_util", `${m.slice(6)}.ts`)); if (m.startsWith(".")) return load(path.join(path.dirname(file), `${m}.ts`)); return new Proxy({}, { get: () => () => {} }); }; new Function("exports", "module", "require", js)(box.exports, box, near); return box.exports; }; class Node { constructor(tag) { this.tag = tag; this.attrs = {}; this.children = []; this.dataset = {}; this.style = {}; } setAttribute(k, v) { this.attrs[k] = String(v); } getAttribute(k) { return this.attrs[k] ?? null; } append(...kids) { this.children.push(...kids); } } globalThis.document = { createElementNS: (_ns, tag) => new Node(tag) }; const input = JSON.parse(fs.readFileSync(process.argv[2], "utf8")); const pave = load(path.join(ROOT, "B06_Section", "B06_Section_UI_Cross_Ford_Pavement.ts")); const design = input.design; // 서버가 낸 양측 절토 · 낮은 쪽 연장 설계 const svg = new Node("g"); pave.appendFordPavementOverlay( svg, { span_m: 8, depth_m: 0.3, slope_pct: 5 }, design, (o) => o, (e) => e, ); const paveLayer = svg.children.find((k) => (k.attrs.class ?? "").includes("ford-pavement")); // 294-4 도수로 · 돌붙임 끝단 · 길이 const hatch = load(path.join(ROOT, "B06_Section", "B06_Section_UI_Cross_Wall_Hatch.ts")); const P = (offset, elevation) => ({ offset, elevation }); const slope = [{ points: [P(0, 0), P(3, -4)], kind: "fill" }]; // 사면 5 m const flat = [P(3, -4), P(5, -4), P(8, -4)]; // 사면 끝 바깥 원지반 const pts = (lines) => lines.map((l) => l.points.map((p) => [+p.offset.toFixed(4), +p.elevation.toFixed(4)])); const dipGround = hatch.groundLine(input.dipSamples); const fillGround = hatch.groundLine(input.fillSamples); const guard = load(path.join(ROOT, "A00_Common", "design", "design_structure_guard.ts")); const fordPave = load(path.join(ROOT, "A00_Common", "design", "design_structure_ford_pavement.ts")); const out = { edges: pave.fordEdges(design), pavePoints: paveLayer?.attrs.points ?? null, runNone: pts(hatch.chuteRun(slope)), runShort: pts(hatch.chuteRun(slope, 2)), runLong: pts(hatch.chuteRun(slope, 7, flat)), runPointOnly: pts(hatch.chuteRun([{ points: [P(3, -4)] }])), runPointLength: pts(hatch.chuteRun([{ points: [P(3, -4)] }], 2, flat)), dipLine: pave.outletFillLine(design, dipGround), dipChute: pave.fordChuteLine(design, {}, dipGround), dipChuteLength: pave.fordChuteLine(design, { length_m: 1.5 }, dipGround), fillLine: pave.outletFillLine(input.fillDesign, fillGround), fillLineOld: pave.outletFillLine(input.fillDesign), fillChuteLength: pave.fordChuteLine(input.fillDesign, { length_m: 1 }, fillGround), chuteItems: guard.CHUTE_ITEMS.map((i) => i.id), fordPaveChuteSame: fordPave.FORD_PAVEMENT_SPEC.containers.find((c) => c.id === "chute").items === guard.CHUTE_ITEMS, }; process.stdout.write(JSON.stringify(out));