All files / virtual-keyboard/src/layouts latin.ts

100% Statements 8/8
100% Branches 8/8
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                1x                                             107x 107x 107x 107x 107x    
import type { KeyDefinition } from "../types";
 
/**
 * Accent long-press **variants** shared across the Latin layout catalog, keyed
 * by the base letter. Mirrors the set the built-in {@link qwertyLayout} exposes
 * so every Latin layout offers the same accents regardless of where a letter
 * physically sits (é on `e`, ç on `c`, …).
 */
export const LATIN_VARIANTS: Record<string, string[]> = {
  a: ["à", "á", "â", "ä", "å", "æ", "ã"],
  c: ["ç", "ć", "č"],
  e: ["é", "è", "ê", "ë", "ē", "ę"],
  i: ["í", "ì", "î", "ï", "ī"],
  n: ["ñ", "ń"],
  o: ["ó", "ò", "ô", "ö", "õ", "ø"],
  s: ["ß", "ś", "š"],
  u: ["ú", "ù", "û", "ü", "ū"],
  y: ["ý", "ÿ"],
  z: ["ž", "ź", "ż"],
};
 
/**
 * Build a `char` key for a Latin-catalog layout. Attaches the symbol-layer glyph
 * (`layerKey`) when given and auto-attaches this letter's accent {@link LATIN_VARIANTS}
 * unless an explicit `variants` list is supplied (pass `[]` to opt out).
 */
export function ck(
  key: string,
  layerKey?: string,
  variants?: string[]
): KeyDefinition {
  const def: KeyDefinition = { key, type: "char" };
  if (layerKey !== undefined) def.layerKey = layerKey;
  const v = variants ?? LATIN_VARIANTS[key];
  if (v && v.length > 0) def.variants = v;
  return def;
}