provisional/decisions.md の仮決定(T-1〜T-28)に従い、mock/ に Vue 3 + Vite + TypeScript のモックを置いた。 T-3 の1〜3(回転したクラスター内のドラッグと保存の往復、IDX・MAPとの連携、ELCと出力の対応表)まで。疑似デバイスとの往復(T-24)は未着手。 - KLE JSONの入出力は、KLE本家の serial.js の deserialize の結果を期待値とする fixture(tests/fixtures/kle-oracle.json)で照合した。本家のコードは取り込んでいない(T-7) - 基本キーコードの表は QMK の data/constants/keycodes/keycodes_0.0.1_basic.hjson(1e340cd)から抽出した - 実装は Codex(Luna)、レビューは Codex(Sol)。検証: Vitest 53件、Playwright 20件、vue-tsc、vite build - TypeScript は vue-tsc が 7 系に未対応のため 6 系に固定した - 操作性の改善(ELCの提供者の表示、一括配線とGeneratorのピン設定の引き継ぎ、キー内の文字のはみ出し)は別途行う Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AATqjRyp6rrnwTNdYw8XBT
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import type { PhyFile, Node } from "./phy";
|
|
import { createId } from "./ids";
|
|
import { importKle } from "../io/kleImport";
|
|
import { sha256Jcs } from "../io/json";
|
|
import { createIdx, type IdxFile } from "./idx";
|
|
import { createElc, type ElcFile } from "./elc";
|
|
import { createMap, type MapFile } from "./map";
|
|
export type MatrixOutputSettings = {
|
|
rowPins: string[];
|
|
colPins: string[];
|
|
kind?: "matrix" | "charlieplexing" | "direct";
|
|
[key: string]: unknown;
|
|
};
|
|
export type ProjectFile = {
|
|
format: "beyond-kle-mock-project";
|
|
version: string;
|
|
projectId: string;
|
|
phy: PhyFile;
|
|
elc: ElcFile;
|
|
idx: IdxFile;
|
|
map: MapFile;
|
|
output: { variantSelection: Record<string, string>; matrix?: MatrixOutputSettings; [key: string]: unknown };
|
|
ui?: unknown;
|
|
[key: string]: unknown;
|
|
};
|
|
/** Creates default variant selections from PHY. T-10/T-20. */
|
|
export function defaultVariantSelection(phy: PhyFile): Record<string, string> {
|
|
const out: Record<string, string> = {};
|
|
const walk = (nodes: Node[]) =>
|
|
nodes.forEach((n) => {
|
|
if (n.type === "cluster") walk(n.children);
|
|
if (n.type === "variantGroup") {
|
|
out[n.id] = n.default;
|
|
const v = n.children.find((x) => x.id === n.default);
|
|
if (v) walk(v.children);
|
|
}
|
|
});
|
|
walk(phy.root);
|
|
return out;
|
|
}
|
|
/** Creates an empty project with default reference values. T-10/T-13. */
|
|
export async function createProject(phy: PhyFile, gen?: () => string): Promise<ProjectFile> {
|
|
const ref = { source: "project:phy", checksum: await sha256Jcs(phy) };
|
|
return {
|
|
format: "beyond-kle-mock-project",
|
|
version: "0.1.0",
|
|
projectId: createId("project-", gen),
|
|
phy: structuredClone(phy),
|
|
elc: createElc(ref),
|
|
idx: createIdx(phy, [], ref),
|
|
map: createMap(ref),
|
|
output: { variantSelection: defaultVariantSelection(phy) },
|
|
};
|
|
}
|
|
/** Imports KLE as a new project and initializes IDX from occurrence order. T-18. */
|
|
export async function createProjectFromKle(
|
|
input: unknown,
|
|
options: { idGenerator?: () => string; name?: string; projectIdGenerator?: () => string } = {},
|
|
): Promise<ProjectFile> {
|
|
const { phy, keyOrder } = importKle(input, options);
|
|
const p = await createProject(phy, options.projectIdGenerator);
|
|
p.idx = createIdx(phy, keyOrder, p.idx.phyReference);
|
|
return p;
|
|
}
|