/* 854-3 헬퍼 — 줄 쌓기 화면 열고 닫기를 되풀이해도 창 크기 듣기가 안 늘고 · M01 화면 들어올 때 상세 길이 M01 로 돌아옴 * 가짜 DOM · 진짜 코드(line_stack_screen · Sangeun_Tabs · M01 Logic_Api · M01 Page) · 나머지 이웃 파일은 빈 부품 */ const fs = require("fs"); const path = require("path"); const ROOT = path.resolve(__dirname, "..", ".."); const ts = require(path.join(ROOT, "config", "node_modules", "typescript")); class Fake { constructor(tag) { this.tagName = String(tag).toUpperCase(); this.children = []; this.parentElement = null; this.dataset = {}; this.style = { setProperty() {} }; this.offsetHeight = 0; this.clientHeight = 0; this.hidden = false; } append(...xs) { for (const x of xs) if (x instanceof Fake) (x.parentElement = this), this.children.push(x); } replaceChildren(...xs) { this.children = []; this.append(...xs); } addEventListener() {} setAttribute() {} } let listeners = 0; // window 의 resize 듣기 수 globalThis.window = globalThis; globalThis.addEventListener = (type) => type === "resize" && listeners++; globalThis.removeEventListener = (type) => type === "resize" && listeners--; globalThis.getComputedStyle = () => ({ overflowY: "visible" }); globalThis.innerHeight = 800; globalThis.HTMLElement = Fake; globalThis.document = { createElement: (t) => new Fake(t), body: new Fake("body") }; globalThis.sessionStorage = { getItem: () => null, setItem() {}, removeItem() {} }; const empty = () => new Proxy(function () {}, { get: (_, k) => (k === "then" ? undefined : empty()), apply: () => undefined }); const own = { ui_template_elements: { showToast() {}, el: (tag, o = {}) => { const n = new Fake(tag); n.append(...(o.children ?? [])); return n; } }, }; function makeLoader(stubs) { const cache = new Map(); const resolve = (from, p) => { if (p.startsWith("@ui/")) return path.join(ROOT, "ui_template", `${p.slice(4)}.ts`); if (p.startsWith("@config/")) return path.join(ROOT, "config", `${p.slice(8)}.ts`); if (p.startsWith(".")) return `${path.resolve(path.dirname(from), p)}.ts`; return null; }; function load(at) { if (cache.has(at)) return cache.get(at); const js = ts.transpileModule(fs.readFileSync(at, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; cache.set(at, box.exports); const need = (p) => { const name = path.basename(p); if (p.endsWith(".css")) return {}; if (stubs[name]) return stubs[name]; const r = resolve(at, p); // 읽어 올 몸 = 진짜 · 그 밖 = 빈 부품 return r && real.has(path.basename(r, ".ts")) ? load(r) : empty(); }; new Function("exports", "module", "require", js)(box.exports, box, need); return box.exports; } return (rel) => load(path.join(ROOT, rel)); } const real = new Set([ "line_stack_screen", "M02_MasterTemplete_Sangeun_Tabs", "M01_MasterData_UI_Logic_Api", "M01_MasterData_UI_Page", ]); const state = { user: null }; const load = makeLoader({ ...own, A06_Login_Api_Fetch: { fetchSessionUser: async () => state.user }, }); const out = { screen: [], tabs: [], page: {} }; // ① 줄 쌓기 화면 — 열고 닫기 다섯 번 const { createStackScreen } = load("A00_Common/line_stack_screen.ts"); const base = listeners; for (let i = 0; i < 5; i++) { const s = createStackScreen({ base: "/m01/logic/doc", admin: false, cache: "x" }); out.screen.push(listeners - base); // 열린 동안 +1 s.destroy(); out.screen.push(listeners - base); } // ② M02 단가산출 줄 쌓기 그릇 — 열고 닫기 다섯 번 const { createSangeunTabs } = load("M02_MasterTemplete/M02_MasterTemplete_Sangeun_Tabs.ts"); const b2 = listeners; for (let i = 0; i < 5; i++) { const t = createSangeunTabs({ edit: false, scope: { layer: "system", owner: null } }); out.tabs.push(listeners - b2); t.destroy(); out.tabs.push(listeners - b2); } // ③ M01 화면에 들어오면 상세 길이 M01 기본으로 const api = load("M01_MasterData/M01_MasterData_UI_Logic_Api.ts"); api.setLogicApiPaths({ read: "/m02/logic-lib", calc: "/m02/logic-lib" }); out.page.before = api.logicApiPaths().read; const { renderM01MasterData } = load("M01_MasterData/M01_MasterData_UI_Page.ts"); renderM01MasterData(new Fake("div")).then(() => { out.page.after = api.logicApiPaths().read; console.log(JSON.stringify(out)); });