@uyghurcommunity/keyboard 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/layouts.js ADDED
@@ -0,0 +1,121 @@
1
+ /** The complete 32-letter alphabet is represented across these virtual rows. */
2
+ export const KEY_LAYOUT = Object.freeze([
3
+ Object.freeze(['چ', 'ۋ', 'ې', 'ر', 'ت', 'ي', 'ۇ', 'ڭ', 'و', 'پ']),
4
+ Object.freeze(['ھ', 'س', 'د', 'ا', 'ە', 'ى', 'ق', 'ك', 'ل', 'ژ']),
5
+ Object.freeze(['ز', 'ش', 'غ', 'ۈ', 'ب', 'ن', 'م', 'ۆ', 'گ', 'خ', 'ف', 'ج']),
6
+ Object.freeze(['ئ', 'ئا', 'ئە', 'ئې', 'ئى', 'ئو', 'ئۇ', 'ئۆ', 'ئۈ']),
7
+ ]);
8
+
9
+ /** An explicit, optional phonetic map. This is not an operating-system layout. */
10
+ export const PHONETIC_MAP = Object.freeze({
11
+ a: 'ا', b: 'ب', c: 'چ', d: 'د', e: 'ە', f: 'ف', g: 'گ', h: 'ھ', i: 'ى', j: 'ج',
12
+ k: 'ك', l: 'ل', m: 'م', n: 'ن', o: 'و', p: 'پ', q: 'ق', r: 'ر', s: 'س', t: 'ت',
13
+ u: 'ۇ', v: 'ۆ', w: 'ۋ', x: 'خ', y: 'ي', z: 'ز',
14
+ Z: 'ژ', A: 'ئا', E: 'ئە', I: 'ئى', O: 'ئو', U: 'ئۇ', G: 'غ', N: 'ڭ', S: 'ش', V: 'ئۆ', W: 'ئۈ', C: 'ج', Y: 'ې',
15
+ });
16
+
17
+ const arabicExtras = ['ژ', 'ف', 'گ', 'خ', 'ج', 'ۆ', '،', '؛', '؟', '«', '»'];
18
+
19
+ // Functional key positions verified against Microsoft Learn's Uyghur layout
20
+ // (KLID 00010480) and cross-checked against XKB cn(ug). The web keyboard
21
+ // displays key positions from left to right and edits text right to left.
22
+ // The Uyghur character inventory and behavior still need native-speaker review.
23
+ const desktopRows = [
24
+ ['`', ...'1234567890', '-', '='],
25
+ [...'چۋېرتيۇڭوپ', ']', '[', '\\'],
26
+ [...'ھسداەىقكل', '؛', "'"],
27
+ [...'زشغۈبنم', '،', '.', 'ئ'],
28
+ ];
29
+ const desktopShiftedRows = [
30
+ ['~', ...'!@#$%^&*)(', '_', '+'],
31
+ [...'چۋېرتيۇڭوپ', '»', '«', '|'],
32
+ ['ھ', 'س', 'ژ', 'ف', 'گ', 'خ', 'ج', 'ۆ', 'لا', ':', '"'],
33
+ [...'زشغۈبنم', '>', '<', '؟'],
34
+ ];
35
+ const desktopKeys = [..."`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./"];
36
+ const desktopShiftKeys = [...'~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?'];
37
+ // Physical key positions, row by row, as KeyboardEvent.code values, so a real key
38
+ // press can light up the matching virtual key whatever the operating-system layout.
39
+ const desktopCodes = [
40
+ ['Backquote', 'Digit1', 'Digit2', 'Digit3', 'Digit4', 'Digit5', 'Digit6', 'Digit7', 'Digit8', 'Digit9', 'Digit0', 'Minus', 'Equal'],
41
+ [...'QWERTYUIOP'].map((k) => 'Key' + k).concat(['BracketLeft', 'BracketRight', 'Backslash']),
42
+ [...'ASDFGHJKL'].map((k) => 'Key' + k).concat(['Semicolon', 'Quote']),
43
+ [...'ZXCVBNM'].map((k) => 'Key' + k).concat(['Comma', 'Period', 'Slash']),
44
+ ];
45
+ // The Latin key cap printed on each key, as on a Uyghur keyboard sticker.
46
+ const desktopCaps = desktopCodes.map((row) => row.map((code) => (code.startsWith('Key') ? code.slice(3) : '')));
47
+ const desktopMap = {};
48
+ for (const [keys, values] of [[desktopKeys, desktopRows.flat()], [desktopShiftKeys, desktopShiftedRows.flat()]]) {
49
+ keys.forEach((key, index) => { desktopMap[key] = values[index]; });
50
+ }
51
+
52
+ const latinRows = [
53
+ [...'qwertyuiop'],
54
+ [...'asdfghjkl'],
55
+ [...'zxcvbnm', 'ë', 'ö', 'ü', "'"],
56
+ ];
57
+ const cyrillicRows = [
58
+ [...'йцукенгшщзхъ'],
59
+ [...'фывапролджэ'],
60
+ [...'ячсмитьбюё'],
61
+ [...'әғҗқңөүһ'],
62
+ ];
63
+
64
+ function shiftRows(rows) {
65
+ return rows.map((row) => row.map((key) => key.toUpperCase()));
66
+ }
67
+
68
+ function freezeLayout(layout) {
69
+ for (const rows of [layout.rows, layout.shiftedRows, layout.keyCodes, layout.keyCaps]) {
70
+ if (!rows) continue;
71
+ rows.forEach(Object.freeze);
72
+ Object.freeze(rows);
73
+ }
74
+ Object.freeze(layout.labels);
75
+ Object.freeze(layout.physicalMap);
76
+ Object.freeze(layout.secondary);
77
+ return Object.freeze(layout);
78
+ }
79
+
80
+ /**
81
+ * The standard Uyghur computer layout is the default: the one built into Windows
82
+ * (KLID 00010480), Linux (XKB cn(ug)) and macOS, and taught by typing trainers
83
+ * such as Konupka. Its letters are checked key by key in the tests.
84
+ */
85
+ export const DEFAULT_LAYOUT = 'uey-desktop';
86
+
87
+ export const KEYBOARD_LAYOUTS = Object.freeze({
88
+ 'uey-desktop': freezeLayout({
89
+ id: 'uey-desktop', labels: { en: 'Standard Uyghur (UEY)', ug: 'ئۆلچەملىك ئۇيغۇرچە (UEY)' }, lang: 'ug-Arab',
90
+ direction: 'rtl', keyDirection: 'ltr', rows: desktopRows, shiftedRows: desktopShiftedRows,
91
+ physicalMap: desktopMap, secondary: arabicExtras, reviewStatus: 'draft',
92
+ keyCodes: desktopCodes, keyCaps: desktopCaps,
93
+ }),
94
+ phonetic: freezeLayout({
95
+ id: 'phonetic', labels: { en: 'Phonetic', ug: 'ئاھاڭداش' }, lang: 'ug-Arab',
96
+ direction: 'rtl', rows: KEY_LAYOUT, physicalMap: PHONETIC_MAP, secondary: arabicExtras,
97
+ }),
98
+ uly: freezeLayout({
99
+ id: 'uly', labels: { en: 'Latin (ULY)', ug: 'لاتىن يېزىقى (ULY)' }, lang: 'ug-Latn',
100
+ direction: 'ltr', rows: latinRows, shiftedRows: shiftRows(latinRows),
101
+ secondary: ['ch', 'gh', 'ng', 'sh', 'zh', '،', '؛', '؟', '«', '»'], reviewStatus: 'draft',
102
+ }),
103
+ usy: freezeLayout({
104
+ id: 'usy', labels: { en: 'Cyrillic (USY)', ug: 'كىرىل يېزىقى (USY)' }, lang: 'ug-Cyrl',
105
+ direction: 'ltr', rows: cyrillicRows, shiftedRows: shiftRows(cyrillicRows),
106
+ secondary: ['،', '؛', '؟', '«', '»'], reviewStatus: 'draft',
107
+ }),
108
+ });
109
+
110
+ // New Uyghur translations and control labels need native-speaker review.
111
+ export const keyboardLabels = {
112
+ en: {
113
+ keyboard: 'Uyghur keyboard', layout: 'Keyboard layout', space: 'Space', backspace: 'Backspace', shift: 'Shift',
114
+ punctuation: { '،': 'Comma', '؛': 'Semicolon', '؟': 'Question mark', '«': 'Left guillemet', '»': 'Right guillemet' },
115
+ },
116
+ ug: {
117
+ keyboard: 'ئۇيغۇرچە كۇنۇپكا تاختىسى', layout: 'كۇنۇپكا تاختىسىنىڭ ئورۇنلاشتۇرۇلۇشى',
118
+ space: 'بوشلۇق', backspace: 'ئالدىنقى ھەرپنى ئۆچۈرۈش', shift: 'چوڭ ھەرپ كۇنۇپكىسى',
119
+ punctuation: { '،': 'پەش', '؛': 'چېكىتلىك پەش', '؟': 'سوئال بەلگىسى', '«': 'سول تىرناق', '»': 'ئوڭ تىرناق' },
120
+ },
121
+ };
@@ -0,0 +1,45 @@
1
+ const directions = new Set(['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End']);
2
+
3
+ /** Locate the next key using the visual rows, including rows wrapped on phones. */
4
+ export function nextKey(buttonRows, current, key, rtl) {
5
+ if (!directions.has(key)) return undefined;
6
+ const buttons = buttonRows.flat();
7
+ const currentRect = current.getBoundingClientRect?.();
8
+ const rows = [];
9
+ if (currentRect?.width) {
10
+ let top;
11
+ for (const button of buttons) {
12
+ const rect = button.getBoundingClientRect();
13
+ if (top !== rect.top) {
14
+ rows.push([]);
15
+ top = rect.top;
16
+ }
17
+ rows.at(-1).push(button);
18
+ }
19
+ } else {
20
+ rows.push(...buttonRows);
21
+ }
22
+ const rowIndex = rows.findIndex((row) => row.includes(current));
23
+ if (rowIndex < 0) return undefined;
24
+ const row = rows[rowIndex];
25
+ const index = row.indexOf(current);
26
+ if (key === 'Home') return row[0];
27
+ if (key === 'End') return row.at(-1);
28
+ if (key === 'ArrowLeft') return row[index + (rtl ? 1 : -1)] || current;
29
+ if (key === 'ArrowRight') return row[index + (rtl ? -1 : 1)] || current;
30
+ const nextRow = rows[rowIndex + (key === 'ArrowUp' ? -1 : 1)];
31
+ if (!nextRow) return current;
32
+ if (!currentRect?.width) return nextRow[Math.min(index, nextRow.length - 1)];
33
+ const center = currentRect.left + currentRect.width / 2;
34
+ let nearest = current;
35
+ let distance = Infinity;
36
+ for (const button of nextRow) {
37
+ const rect = button.getBoundingClientRect();
38
+ const difference = Math.abs(center - rect.left - rect.width / 2);
39
+ if (difference < distance) {
40
+ nearest = button;
41
+ distance = difference;
42
+ }
43
+ }
44
+ return nearest;
45
+ }
package/src/style.js ADDED
@@ -0,0 +1,97 @@
1
+ export const alkatipFontFace = `@font-face {
2
+ font-family: "ALKATIP Basma";
3
+ src: url("https://db.onlinewebfonts.com/t/3c16518f40da2fc2901f37666c0556a7.woff2") format("woff2"),
4
+ url("https://db.onlinewebfonts.com/t/3c16518f40da2fc2901f37666c0556a7.woff") format("woff"),
5
+ url("https://db.onlinewebfonts.com/t/3c16518f40da2fc2901f37666c0556a7.ttf") format("truetype");
6
+ font-weight: normal;
7
+ font-style: normal;
8
+ font-display: swap;
9
+ }`;
10
+ export const alkatipHelperStyles = `.alkatip-basma {
11
+ font-family: "ALKATIP Basma", serif;
12
+ direction: rtl;
13
+ unicode-bidi: embed;
14
+ line-height: 2.2;
15
+ }`;
16
+ export const keyboardStyles = `
17
+ ${alkatipHelperStyles}
18
+ .ug-keyboard {
19
+ --_bg:#f1f3ef; --_key:#fff; --_ink:#17362f; --_line:#ccd7cf; --_hover:#e3ede5; --_focus:#087866;
20
+ box-sizing:border-box;
21
+ width:100%;
22
+ padding:12px;
23
+ border:1px solid var(--ug-line,var(--_line));
24
+ border-radius:16px;
25
+ background:var(--ug-bg,var(--_bg));
26
+ color:var(--ug-ink,var(--_ink));
27
+ color-scheme:light;
28
+ font-family:"ALKATIP Basma",Tahoma,Arial,sans-serif;
29
+ line-height:1.5;
30
+ }
31
+ .ug-keyboard[dir="ltr"] { direction:ltr; }
32
+ .ug-keyboard[data-theme="dark"] {
33
+ --_bg:#182722; --_key:#263c33; --_ink:#eef7f2; --_line:#527367; --_hover:#37564a; --_focus:#89e6ca;
34
+ color-scheme:dark;
35
+ }
36
+ .ug-keyboard * { box-sizing:border-box; }
37
+ .ug-keyboard__row {
38
+ display:flex;
39
+ flex-wrap:wrap;
40
+ justify-content:center;
41
+ gap:6px;
42
+ margin-block:6px;
43
+ }
44
+ .ug-keyboard__layout, .ug-keyboard__key {
45
+ min-width:44px;
46
+ min-height:44px;
47
+ border:1px solid var(--ug-line,var(--_line));
48
+ border-radius:8px;
49
+ background:var(--ug-key,var(--_key));
50
+ color:inherit;
51
+ cursor:pointer;
52
+ touch-action:manipulation;
53
+ }
54
+ .ug-keyboard__layout {
55
+ max-width:100%;
56
+ padding:4px 8px;
57
+ font:16px/1.5 "ALKATIP Basma",Tahoma,Arial,sans-serif;
58
+ }
59
+ .ug-keyboard__key {
60
+ display:inline-flex;
61
+ align-items:center;
62
+ justify-content:center;
63
+ flex:1 0 44px;
64
+ padding:4px 2px;
65
+ font:22px/1.5 "ALKATIP Basma",Tahoma,Arial,sans-serif;
66
+ }
67
+ .ug-keyboard__key:hover, .ug-keyboard__key[aria-pressed="true"] { background:var(--ug-hover,var(--_hover)); }
68
+ .ug-keyboard__key:focus-visible, .ug-keyboard__layout:focus-visible {
69
+ outline:2px solid var(--ug-focus,var(--_focus));
70
+ outline-offset:1px;
71
+ z-index:1;
72
+ }
73
+ .ug-keyboard__key[data-action] { font-size:16px; gap:8px; }
74
+ .ug-keyboard__key { position:relative; }
75
+ /* Shift letter (top) and Latin key cap (bottom), as printed on a Uyghur keyboard. */
76
+ .ug-keyboard__shift-legend { position:absolute; top:1px; left:6px; font-size:13px; line-height:1.3; opacity:.72; pointer-events:none; }
77
+ .ug-keyboard__cap { position:absolute; bottom:2px; right:6px; font:10px/1 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; opacity:.45; pointer-events:none; }
78
+ /* A real key press lights up its virtual key. */
79
+ .ug-keyboard__key[data-pressed="true"] { background:var(--ug-focus,var(--_focus)); color:var(--ug-key,var(--_key)); border-color:var(--ug-focus,var(--_focus)); transform:translateY(1px); }
80
+ /* Shift and Delete icons are Uyghur UI drawings (arrow-up, arrow-left), drawn as masks so they follow the text colour. */
81
+ .ug-keyboard__icon { display:inline-block; width:18px; height:18px; flex:none; background-color:currentColor; -webkit-mask:center/contain no-repeat; mask:center/contain no-repeat; }
82
+ .ug-keyboard__icon--shift { -webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5m-6 6 6-6 6 6'/%3E%3C/svg%3E"); mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5m-6 6 6-6 6 6'/%3E%3C/svg%3E"); }
83
+ .ug-keyboard__icon--backspace { -webkit-mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5m6-6-6 6 6 6'/%3E%3C/svg%3E"); mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5m6-6-6 6 6 6'/%3E%3C/svg%3E"); }
84
+ .ug-keyboard[data-compact="true"] .ug-keyboard__cap { display:none; }
85
+ .ug-keyboard__key[data-action="space"] { flex-grow:4; }
86
+ .ug-keyboard[data-compact="true"] { padding:6px; }
87
+ .ug-keyboard[data-compact="true"] .ug-keyboard__row { gap:3px; margin-block:3px; }
88
+ .ug-keyboard[data-compact="true"] .ug-keyboard__key { padding:2px; font-size:18px; }
89
+ .ug-keyboard[hidden] { display:none; }
90
+ @media (max-width:420px) {
91
+ .ug-keyboard { padding:6px; }
92
+ .ug-keyboard__row { gap:4px; }
93
+ .ug-keyboard__cap { display:none; }
94
+ .ug-keyboard__shift-legend { left:3px; font-size:11px; }
95
+ .ug-keyboard__key[data-action="backspace"] { font-size:13px; gap:4px; }
96
+ }
97
+ `;