feat(2d-nds): help labels
This commit is contained in:
@@ -15,6 +15,42 @@ export const mapCodeToNDS = (code: string): string | null => {
|
||||
return CODE_TO_NDS_BUTTON[code] ?? null;
|
||||
};
|
||||
|
||||
const NDS_BUTTON_TO_CODE = Object.fromEntries(
|
||||
Object.entries(CODE_TO_NDS_BUTTON).map(([code, nds]) => [nds, code]),
|
||||
);
|
||||
|
||||
const LAYOUT_OVERRIDES: Record<string, Record<string, string>> = {
|
||||
// AZERTY: fr
|
||||
fr: { KeyQ: "A", KeyA: "Q", KeyW: "Z", KeyZ: "W", KeyM: ",", Semicolon: "M" },
|
||||
// QWERTZ: de, cs, hu, sk, sl, hr, bs, sr, pl
|
||||
de: { KeyY: "Z", KeyZ: "Y" },
|
||||
cs: { KeyY: "Z", KeyZ: "Y" },
|
||||
hu: { KeyY: "Z", KeyZ: "Y" },
|
||||
sk: { KeyY: "Z", KeyZ: "Y" },
|
||||
sl: { KeyY: "Z", KeyZ: "Y" },
|
||||
hr: { KeyY: "Z", KeyZ: "Y" },
|
||||
bs: { KeyY: "Z", KeyZ: "Y" },
|
||||
sr: { KeyY: "Z", KeyZ: "Y" },
|
||||
pl: { KeyY: "Z", KeyZ: "Y" },
|
||||
};
|
||||
|
||||
const getLayoutOverrides = (): Record<string, string> => {
|
||||
if (!import.meta.client) return {};
|
||||
const lang = navigator.language.split("-")[0]!;
|
||||
return LAYOUT_OVERRIDES[lang] ?? {};
|
||||
};
|
||||
|
||||
export const mapNDSToKey = (nds: string): string => {
|
||||
const code = NDS_BUTTON_TO_CODE[nds];
|
||||
if (!code) return nds;
|
||||
|
||||
const overrides = getLayoutOverrides();
|
||||
if (overrides[code]) return overrides[code];
|
||||
|
||||
if (code.startsWith("Key")) return code.slice(3);
|
||||
return code;
|
||||
};
|
||||
|
||||
export const useMouseUp = (callback: () => void) => {
|
||||
onMounted(() => {
|
||||
document.addEventListener("mouseup", callback);
|
||||
|
||||
Reference in New Issue
Block a user