Files
Aislo/resources/tester/helper_514_2_stale_flow.cjs
T

63 lines
2.3 KiB
JavaScript

/* 514-2 낡은 유량 가림 헬퍼 — 진짜 `design_structure_ford_calc.ts` 를 Node 로 돌려 JSON 한 벌로(요구 328-3). */
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(".")) 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;
};
const calc = load(path.join(ROOT, "A00_Common", "design", "design_structure_ford_calc.ts"));
globalThis.document = { createElement: () => ({ textContent: "", className: "" }) };
const state = { ford: [{ width: "10", height: "" }] };
let refreshed = 0;
const form = {
state: () => state,
setValue: (c, i, v) => (state[c][0][i] = v),
refresh: () => (refreshed += 1),
};
const sync = calc.overflowSync(
() => form,
"ford",
() => 2.54,
() => undefined,
);
const hint = () => sync.fields({ id: "ford" })[0].textContent;
const edit = (item, value) => {
state.ford[0][item] = value;
sync.onChange({ id: "ford" }, { id: item });
return state.ford[0].height;
};
const fresh = { hint: hint(), height: edit("width", "10") };
calc.setDrainageStale(true);
state.ford[0].height = "";
const stale = { refreshed, hint: hint(), height: edit("width", "8") };
sync.arm(true);
sync.fill();
stale.afterFill = state.ford[0].height;
let before = refreshed;
calc.setDrainageStale(true); // 같은 값 = 다시 안 그림
stale.repaintSame = refreshed - before;
before = refreshed;
calc.setDrainageStale(false);
const back = { repaint: refreshed - before, hint: hint() };
sync.fill();
back.afterFill = state.ford[0].height;
process.stdout.write(JSON.stringify({ fresh, stale, back }));