Skip to content

Commit

Permalink
chore: update Bidi key values (#10466)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Jun 29, 2023
1 parent 1175fe9 commit 1c80ebe
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 75 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/puppeteer-core/package.json
Expand Up @@ -141,7 +141,7 @@
"author": "The Chromium Authors",
"license": "Apache-2.0",
"dependencies": {
"chromium-bidi": "0.4.15",
"chromium-bidi": "0.4.16",
"cross-fetch": "3.1.6",
"debug": "4.3.4",
"devtools-protocol": "0.0.1135028",
Expand Down
160 changes: 126 additions & 34 deletions packages/puppeteer-core/src/common/bidi/Input.ts
Expand Up @@ -41,8 +41,9 @@ const enum InputId {
Finger = '__puppeteer_finger',
}

const getBidiKeyValue = (key: string) => {
const getBidiKeyValue = (key: KeyInput) => {
switch (key) {
case '\r':
case '\n':
key = 'Enter';
break;
Expand All @@ -52,8 +53,6 @@ const getBidiKeyValue = (key: string) => {
return key;
}
switch (key) {
case 'Unidentified':
return '\uE000';
case 'Cancel':
return '\uE001';
case 'Help':
Expand All @@ -64,22 +63,21 @@ const getBidiKeyValue = (key: string) => {
return '\uE004';
case 'Clear':
return '\uE005';
case 'Return':
return '\uE006';
case 'Enter':
return '\uE007';
case 'Shift':
case 'ShiftLeft':
return '\uE008';
case 'Control':
case 'ControlLeft':
return '\uE009';
case 'Alt':
case 'AltLeft':
return '\uE00A';
case 'Pause':
return '\uE00B';
case 'Escape':
return '\uE00C';
case ' ':
return '\uE00D';
case 'PageUp':
return '\uE00E';
case 'PageDown':
Expand All @@ -100,41 +98,37 @@ const getBidiKeyValue = (key: string) => {
return '\uE016';
case 'Delete':
return '\uE017';
case ';':
return '\uE018';
case '=':
case 'NumpadEqual':
return '\uE019';
case '0':
case 'Numpad0':
return '\uE01A';
case '1':
case 'Numpad1':
return '\uE01B';
case '2':
case 'Numpad2':
return '\uE01C';
case '3':
case 'Numpad3':
return '\uE01D';
case '4':
case 'Numpad4':
return '\uE01E';
case '5':
case 'Numpad5':
return '\uE01F';
case '6':
case 'Numpad6':
return '\uE020';
case '7':
case 'Numpad7':
return '\uE021';
case '8':
case 'Numpad8':
return '\uE022';
case '9':
case 'Numpad9':
return '\uE023';
case '*':
case 'NumpadMultiply':
return '\uE024';
case '+':
case 'NumpadAdd':
return '\uE025';
case ',':
return '\uE026';
case '-':
case 'NumpadSubtract':
return '\uE027';
case '.':
case 'NumpadDecimal':
return '\uE028';
case '/':
case 'NumpadDivide':
return '\uE029';
case 'F1':
return '\uE031';
Expand All @@ -161,9 +155,110 @@ const getBidiKeyValue = (key: string) => {
case 'F12':
return '\uE03C';
case 'Meta':
case 'MetaLeft':
return '\uE03D';
case 'ZenkakuHankaku':
return '\uE040';
case 'ShiftRight':
return '\uE050';
case 'ControlRight':
return '\uE051';
case 'AltRight':
return '\uE052';
case 'MetaRight':
return '\uE053';
case 'Digit0':
return '0';
case 'Digit1':
return '1';
case 'Digit2':
return '2';
case 'Digit3':
return '3';
case 'Digit4':
return '4';
case 'Digit5':
return '5';
case 'Digit6':
return '6';
case 'Digit7':
return '7';
case 'Digit8':
return '8';
case 'Digit9':
return '9';
case 'KeyA':
return 'a';
case 'KeyB':
return 'b';
case 'KeyC':
return 'c';
case 'KeyD':
return 'd';
case 'KeyE':
return 'e';
case 'KeyF':
return 'f';
case 'KeyG':
return 'g';
case 'KeyH':
return 'h';
case 'KeyI':
return 'i';
case 'KeyJ':
return 'j';
case 'KeyK':
return 'k';
case 'KeyL':
return 'l';
case 'KeyM':
return 'm';
case 'KeyN':
return 'n';
case 'KeyO':
return 'o';
case 'KeyP':
return 'p';
case 'KeyQ':
return 'q';
case 'KeyR':
return 'r';
case 'KeyS':
return 's';
case 'KeyT':
return 't';
case 'KeyU':
return 'u';
case 'KeyV':
return 'v';
case 'KeyW':
return 'w';
case 'KeyX':
return 'x';
case 'KeyY':
return 'y';
case 'KeyZ':
return 'z';
case 'Semicolon':
return ';';
case 'Equal':
return '=';
case 'Comma':
return ',';
case 'Minus':
return '-';
case 'Period':
return '.';
case 'Slash':
return '/';
case 'Backquote':
return '`';
case 'BracketLeft':
return '[';
case 'Backslash':
return '\\';
case 'BracketRight':
return ']';
case 'Quote':
return '"';
default:
throw new Error(`Unknown key: "${key}"`);
}
Expand All @@ -185,11 +280,8 @@ export class Keyboard extends BaseKeyboard {

override async down(
key: KeyInput,
options?: Readonly<KeyDownOptions>
_options?: Readonly<KeyDownOptions>
): Promise<void> {
if (options) {
throw new Error('KeyDownOptions are not supported');
}
await this.#context.connection.send('input.performActions', {
context: this.#context.id,
actions: [
Expand Down Expand Up @@ -265,7 +357,7 @@ export class Keyboard extends BaseKeyboard {
const {delay = 0} = options;
// This spread separates the characters into code points rather than UTF-16
// code units.
const values = [...text].map(getBidiKeyValue);
const values = ([...text] as KeyInput[]).map(getBidiKeyValue);
const actions: Bidi.Input.KeySourceAction[] = [];
if (delay <= 0) {
for (const value of values) {
Expand Down

0 comments on commit 1c80ebe

Please sign in to comment.