/* 387-8 헬퍼 — 종단 판이 접힘(그리기 · 그리기 낡음 판정 없음) + 관 초안 둔 채 다시 열기: 진짜 상세 가게 * (`B06_Section_Section_Store`) · 진짜 낡음 판정(`B06_Section_Cross_Refresh` staleKeyAgainstScreen)이 묶음 cross * 뒤에 얹힌 미리 뜬 측점(서버가 옛 계획고로 셈)을 보고 묶음에 cross 한 번 더 부탁하는지. 묶음 · 초안 얹기 · 서버는 가짜 — * 가짜 cross = 상세 측점마다 계획고를 지금 계획선으로(면적 = 계획고 함수). 짝 = `test_387_8_folded_profile.py`. */ const fs = require("fs"); const path = require("path"); const { makeLoader } = require("./helper_ts_stub_loader.cjs"); const CATALOG = require("./helper_322_catalog_module.cjs"); const ROOT = path.join(__dirname, "..", ".."); const P = "P387"; const ROUTE = 7; const PLAN = 100; // 지금 계획선(평평) function memoryStorage() { const map = new Map(); return { getItem: (k) => (map.has(k) ? map.get(k) : null), setItem: (k, v) => map.set(k, String(v)), removeItem: (k) => map.delete(k), key: (i) => [...map.keys()][i] ?? null, get length() { return map.size; }, }; } globalThis.window = { sessionStorage: memoryStorage(), localStorage: memoryStorage() }; const anyModule = (extra = {}) => new Proxy(extra, { get: (t, key) => (key in t ? t[key] : () => undefined) }); /** 가짜 계산 묶음 — 부탁 수 · 강제 수 · cross = 상세 계획고 맞춤. */ const pipe = { generation: 1, route: null, crosses: 0, forced: 0, fix: true }; const areaOf = (elevation) => Math.round((elevation - 90) * 1000) / 1000; function cross() { pipe.crosses += 1; if (!pipe.fix) return; for (const section of storeDetail().cross_sections) { section.design = { ...section.design, design_elevation_m: PLAN, cut_area_m2: areaOf(PLAN), }; } } let previewAt = null; // 관 초안 자리(미리 뜬 측점) const STUBS = { "design_pipeline_page.ts": { reconcilePagePipeline: async () => 0, pipelineOwnsCross: () => true, pagePipeline: () => ({ generation: pipe.generation, input: () => pipe.route, settled: async () => undefined, }), pipelineCross: () => cross(), }, "design_pipeline_cross.ts": { forceCross: () => void (pipe.forced += 1) }, // 초안 측점 — 관 초안 자리에 서버가 미리 뜬 횡단(저장 계획선 = 옛 계획고 102)을 얹음 "B06_Section_Section_Drafts.ts": { forgetDraftStations: () => undefined, withDraftShapes: async () => undefined, withDraftStations: async (detail) => { if (previewAt === null || detail.cross_sections.some((s) => s.preview)) return; detail.cross_sections.push({ chainage_m: previewAt, kind: "irregular", preview: true, samples: [], design: { design_elevation_m: 102, cut_area_m2: areaOf(102) }, }); detail.cross_sections.sort((a, b) => a.chainage_m - b.chainage_m); }, }, "B05_Profile_Api_PlusStations.ts": { loadSavedPlusStations: async () => undefined, plusStationsOf: () => [], }, "B05_Profile_Api_Pipes_Draft.ts": { readPendingPipes: () => null }, "design_page_data.ts": { pagePipes: async () => ({ pipe_points: [] }) }, "B06_Section_Api_Fetch.ts": anyModule(), "B06_Section_Api_Culvert_Options.ts": anyModule({ STRUCTURE_ADJUST_KEYS: [] }), "B06_Section_Swap_Bus.ts": anyModule(), "B06_Section_Station_Keys.ts": anyModule({ KEYED_STATES: [] }), "B06_Section_UI_Page_Persist.ts": anyModule(), "B06_Section_UI_Standard_Panel.ts": anyModule(), "B06_Section_Cross_Design_Session.ts": anyModule(), "common_util_cross_design.ts": anyModule(), "B06_Section_Cross_Culvert_Wire.ts": anyModule(), "B06_Section_Cross_Ford_Geom.ts": anyModule(), "B06_Section_Cross_Box_Geom.ts": anyModule(), "B06_Section_UI_IrregularStations.ts": anyModule({ PIPE_DISPLAY_NAME: {} }), "B05_Profile_UI_IrregularStations.ts": anyModule({ PIPE_DISPLAY_NAME: {} }), "config_frontend.ts": anyModule({ PIPE_TYPES: [] }), }; const resolve = (base) => [base, `${base}.ts`, path.join(base, "index.ts")].find( (p) => fs.existsSync(p) && fs.statSync(p).isFile(), ) ?? `${base}.ts`; const { loadTs } = makeLoader({ root: ROOT, interop: true, fileStub: (full) => STUBS[path.basename(full)], requireFor: (full) => (request) => { if (CATALOG.isCatalogRequest(request)) return CATALOG; const alias = { "@util/": "common_util", "@ui/": "ui_template", "@config/": "config" }; for (const [prefix, dir] of Object.entries(alias)) if (request.startsWith(prefix)) return loadTs(resolve(path.join(ROOT, dir, request.slice(prefix.length)))); return loadTs(resolve(path.join(path.dirname(full), request))); }, }); const B06 = (f) => path.join(ROOT, "B06_Section", `${f}.ts`); const store = loadTs(B06("B06_Section_Section_Store")); const { writeState } = loadTs(path.join(ROOT, "A00_Common", "b_page_state.ts")); const storeDetail = () => store.peekSectionDetail(P, ROUTE); /** 저장 정본 — 격자 0 · 20 · 40 · 60(지금 계획선으로 셈한 설계) · 계획선 평평 100. */ const canon = () => ({ longitudinal: { design_profiles: [ { samples: [ { chainage_m: 0, elevation_m: PLAN }, { chainage_m: 60, elevation_m: PLAN }, ], }, ], }, cross_sections: [0, 20, 40, 60].map((c) => ({ chainage_m: c, kind: c === 0 ? "bp" : "regular", samples: [], design: { design_elevation_m: PLAN, cut_area_m2: areaOf(PLAN) }, })), }); const tick = () => new Promise((r) => setTimeout(r, 20)); const sum = () => Math.round(storeDetail().cross_sections.reduce((a, s) => a + s.design.cut_area_m2, 0) * 1000) / 1000; const mixed = () => storeDetail() .cross_sections.filter((s) => s.design.design_elevation_m !== PLAN) .map((s) => s.chainage_m); const counts = () => ({ crosses: pipe.crosses, forced: pipe.forced }); async function open(fresh = true) { if (fresh) { store.invalidateSectionDetail(P); writeState("section-detail", canon(), P, ROUTE); } await store.loadSectionDetail(P, ROUTE); await tick(); } (async () => { const out = {}; // 펼친 때 기준 — 미리 뜬 측점이 첫 cross 전에 얹혀 같이 셈 previewAt = 30; await open(); cross(); out.expanded = { sum: sum(), mixed: mixed() }; // 접힌 종단 판 + 관 초안 다시 열기 — 미리 뜬 측점이 cross 뒤에 얹힘(그리기 판정 없음) → 가게가 한 번 더 부탁 Object.assign(pipe, { crosses: 0, forced: 0 }); await open(); out.folded = { sum: sum(), mixed: mixed(), ...counts() }; // 같은 상세 다시 읽음(보기 전환) — 낡음 없음 = 부탁 없음 await open(false); out.again = counts(); // 다시 셈이 못 고치는 낡음 — 한 번만 부탁(되풀이 없음) Object.assign(pipe, { crosses: 0, forced: 0, fix: false }); await open(); await open(false); await open(false); out.unfixed = counts(); pipe.fix = true; // 묶음이 아직 안 섬(첫 차례 몫) · 노선 초안(묶음 새 노선 상세 몫) = 안 부탁 Object.assign(pipe, { crosses: 0, forced: 0, generation: 0 }); await open(); out.notStarted = counts(); Object.assign(pipe, { crosses: 0, forced: 0, generation: 1, route: { rev: 1 } }); await open(); out.routeDraft = counts(); pipe.route = null; // 관 초안 없음 — 낡음 없음 = 부탁 없음 Object.assign(pipe, { crosses: 0, forced: 0 }); previewAt = null; await open(); out.noDraft = { sum: sum(), ...counts() }; process.stdout.write(JSON.stringify(out)); })().catch((error) => { process.stderr.write(String(error && error.stack ? error.stack : error)); process.exit(1); });