- input-prefs 에 panButton(왼 · 가운데 · 오른 · 기본 가운데) · keys(바꾼 키만) 칸 - isPanButton = 고른 단추 또는 가운데 · 585-1 카카오 부품이 부름 - test_input_prefs 기본값 · 단추 판정 · 깨진 값 거름 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
3.0 KiB
JavaScript
69 lines
3.0 KiB
JavaScript
/* PLAN 332-1 단위검증 헬퍼 — 휠 방향 읽기 층(`A00_Common/input_prefs.ts`) · 손가락 다리(`touch_bridge.ts`)
|
|
* · 등록표 키(`b_page_state.ts`)를 그 자리에서 트랜스파일해 Node 로 돌림. 가짜 localStorage 로 설정을 바꿔 봄.
|
|
* 결과 = 표준출력 JSON 한 벌. 짝 = `test_input_prefs.py`. */
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
const A00 = path.join(ROOT, "A00_Common");
|
|
function load(file) {
|
|
const js = ts.transpileModule(fs.readFileSync(file, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
}).outputText;
|
|
const box = { exports: {} };
|
|
const req = (p) => (p === "./input_prefs" ? prefs : {});
|
|
new Function("exports", "module", "require", js)(box.exports, box, req);
|
|
return box.exports;
|
|
}
|
|
|
|
const out = {};
|
|
// ① Node(저장소 없음) — 불러올 때 window 를 안 만지고 기본값
|
|
const prefs = load(path.join(A00, "input_prefs.ts"));
|
|
const bridge = load(path.join(A00, "touch_bridge.ts"));
|
|
const page = load(path.join(A00, "b_page_state.ts"));
|
|
const sample = () => ({
|
|
prefs: prefs.inputPrefs(),
|
|
pull: prefs.wheelIn(100),
|
|
push: prefs.wheelIn(-100),
|
|
mouseCtrl: prefs.wheelEventIn({ ctrlKey: true, deltaY: 100 }),
|
|
padSpread: prefs.wheelEventIn({ ctrlKey: true, deltaY: -3.5 }),
|
|
padPinch: prefs.wheelEventIn({ ctrlKey: true, deltaY: 3.5 }),
|
|
fingerSpread: prefs.wheelEventIn({ ctrlKey: true, deltaY: -9.5 }, true),
|
|
bridgePull: bridge.wheelZoomsIn({ ctrlKey: false, deltaY: 100 }),
|
|
pan: [0, 1, 2].map((button) => prefs.isPanButton(button)),
|
|
});
|
|
out.node = { key: prefs.INPUT_PREFS_KEY, default: prefs.DEFAULT_INPUT_PREFS, ...sample() };
|
|
out.registryKey = page.stateKey("input-prefs");
|
|
out.registryEntry = page.STATE_REGISTRY["input-prefs"];
|
|
|
|
// ② 브라우저 저장소 흉내 — 값을 바꾸면 다음 부름부터 바로 따름
|
|
const store = new Map();
|
|
globalThis.localStorage = {
|
|
getItem: (k) => (store.has(k) ? store.get(k) : null),
|
|
setItem: (k, v) => store.set(k, String(v)),
|
|
removeItem: (k) => store.delete(k),
|
|
};
|
|
const set = (v) => store.set(prefs.INPUT_PREFS_KEY, v);
|
|
set(JSON.stringify({ wheelZoom: "pull", cadAliases: { line: ["ll", 3], ARC: [] } }));
|
|
out.saved = sample(); // 기본 밂(337) 의 반대를 저장
|
|
for (const button of ["left", "right", "sideways"]) {
|
|
set(JSON.stringify({ panButton: button, keys: { "plan.delete": ["X", 3], bad: "Y" } }));
|
|
out[`pan_${button}`] = sample();
|
|
}
|
|
set("{깨짐");
|
|
out.broken = sample();
|
|
set(JSON.stringify({ wheelZoom: "sideways" }));
|
|
out.unknown = sample();
|
|
store.delete(prefs.INPUT_PREFS_KEY);
|
|
out.empty = sample();
|
|
// ③ 불러오는 동안 저장소가 던지는 브라우저(사생활 보호) — 기본값
|
|
globalThis.localStorage = {
|
|
getItem: () => {
|
|
throw new Error("blocked");
|
|
},
|
|
};
|
|
out.blocked = sample();
|
|
|
|
process.stdout.write(JSON.stringify(out));
|