Fix style according to airbnb guidelines (only auto-fixes)

This commit is contained in:
Juanjo Diaz 2018-07-14 01:22:14 +02:00
parent 98e1f3cb8b
commit 14e900c4ae
48 changed files with 13782 additions and 13039 deletions

514
.eslintrc
View File

@ -18,5 +18,519 @@
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": true }],
"arrow-spacing": ["error"],
"no-confusing-arrow": ["error", { "allowParens": true }],
// enforce line breaks after opening and before closing array brackets
// https://eslint.org/docs/rules/array-bracket-newline
// TODO: enable? semver-major
"array-bracket-newline": ["off", "consistent"], // object option alternative: { multiline: true, minItems: 3 }
// enforce line breaks between array elements
// https://eslint.org/docs/rules/array-element-newline
// TODO: enable? semver-major
"array-element-newline": ["off", { multiline: true, minItems: 3 }],
// enforce spacing inside array brackets
"array-bracket-spacing": ["error", "never"],
// enforce spacing inside single-line blocks
// https://eslint.org/docs/rules/block-spacing
"block-spacing": ["error", "always"],
// enforce one true brace style
"brace-style": ["error", "1tbs", { allowSingleLine: true }],
// require camel case names
// TODO: semver-major (eslint 5): add ignoreDestructuring: false option
// camelcase: ["error", { properties: "never" }],
// enforce or disallow capitalization of the first letter of a comment
// https://eslint.org/docs/rules/capitalized-comments
"capitalized-comments": ["off", "never", {
line: {
ignorePattern: ".*",
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
block: {
ignorePattern: ".*",
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
}],
// require trailing commas in multiline object literals
// "comma-dangle": ["error", {
// arrays: "always-multiline",
// objects: "always-multiline",
// imports: "always-multiline",
// exports: "always-multiline",
// functions: "always-multiline",
// }],
// enforce spacing before and after comma
"comma-spacing": ["error", { before: false, after: true }],
// enforce one true comma style
"comma-style": ["error", "last", {
exceptions: {
ArrayExpression: false,
ArrayPattern: false,
ArrowFunctionExpression: false,
CallExpression: false,
FunctionDeclaration: false,
FunctionExpression: false,
ImportDeclaration: false,
ObjectExpression: false,
ObjectPattern: false,
VariableDeclaration: false,
NewExpression: false,
}
}],
// disallow padding inside computed properties
"computed-property-spacing": ["error", "never"],
// enforces consistent naming when capturing the current execution context
"consistent-this": "off",
// enforce newline at the end of file, with no multiple empty lines
"eol-last": ["error", "always"],
// enforce spacing between functions and their invocations
// https://eslint.org/docs/rules/func-call-spacing
"func-call-spacing": ["error", "never"],
// requires function names to match the name of the variable or property to which they are
// assigned
// https://eslint.org/docs/rules/func-name-matching
// TODO: semver-major (eslint 5): add considerPropertyDescriptor: true
"func-name-matching": ["off", "always", {
includeCommonJSModuleExports: false
}],
// require function expressions to have a name
// https://eslint.org/docs/rules/func-names
// "func-names": "warn",
// enforces use of function declarations or expressions
// https://eslint.org/docs/rules/func-style
// TODO: enable
"func-style": ["off", "expression"],
// enforce consistent line breaks inside function parentheses
// https://eslint.org/docs/rules/function-paren-newline
"function-paren-newline": ["error", "consistent"],
// Blacklist certain identifiers to prevent them being used
// https://eslint.org/docs/rules/id-blacklist
"id-blacklist": "off",
// this option enforces minimum and maximum identifier lengths
// (variable names, property names etc.)
"id-length": "off",
// require identifiers to match the provided regular expression
"id-match": "off",
// Enforce the location of arrow function bodies with implicit returns
// https://eslint.org/docs/rules/implicit-arrow-linebreak
"implicit-arrow-linebreak": ["error", "beside"],
// this option sets a specific tab width for your code
// https://eslint.org/docs/rules/indent
indent: ["error", 2, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
// MemberExpression: null,
FunctionDeclaration: {
parameters: 1,
body: 1
},
FunctionExpression: {
parameters: 1,
body: 1
},
CallExpression: {
arguments: 1
},
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
ignoredNodes: ["JSXElement", "JSXElement > *", "JSXAttribute", "JSXIdentifier", "JSXNamespacedName", "JSXMemberExpression", "JSXSpreadAttribute", "JSXExpressionContainer", "JSXOpeningElement", "JSXClosingElement", "JSXText", "JSXEmptyExpression", "JSXSpreadChild"],
ignoreComments: false
}],
// specify whether double or single quotes should be used in JSX attributes
// https://eslint.org/docs/rules/jsx-quotes
"jsx-quotes": ["off", "prefer-double"],
// enforces spacing between keys and values in object literal properties
"key-spacing": ["error", { beforeColon: false, afterColon: true }],
// require a space before & after certain keywords
"keyword-spacing": ["error", {
before: true,
after: true,
overrides: {
return: { after: true },
throw: { after: true },
case: { after: true }
}
}],
// enforce position of line comments
// https://eslint.org/docs/rules/line-comment-position
// TODO: enable?
"line-comment-position": ["off", {
position: "above",
ignorePattern: "",
applyDefaultPatterns: true,
}],
// disallow mixed "LF" and "CRLF" as linebreaks
// https://eslint.org/docs/rules/linebreak-style
"linebreak-style": ["error", "unix"],
// require or disallow an empty line between class members
// https://eslint.org/docs/rules/lines-between-class-members
"lines-between-class-members": ["error", "always", { exceptAfterSingleLine: false }],
// enforces empty lines around comments
"lines-around-comment": "off",
// require or disallow newlines around directives
// https://eslint.org/docs/rules/lines-around-directive
// "lines-around-directive": ["error", {
// before: "always",
// after: "always",
// }],
// specify the maximum depth that blocks can be nested
"max-depth": ["off", 4],
// specify the maximum length of a line in your program
// https://eslint.org/docs/rules/max-len
// "max-len": ["error", 100, 2, {
// ignoreUrls: true,
// ignoreComments: false,
// ignoreRegExpLiterals: true,
// ignoreStrings: true,
// ignoreTemplateLiterals: true,
// }],
// specify the max number of lines in a file
// https://eslint.org/docs/rules/max-lines
"max-lines": ["off", {
max: 300,
skipBlankLines: true,
skipComments: true
}],
// enforce a maximum function length
// https://eslint.org/docs/rules/max-lines-per-function
"max-lines-per-function": ["off", {
max: 50,
skipBlankLines: true,
skipComments: true,
IIFEs: true,
}],
// specify the maximum depth callbacks can be nested
"max-nested-callbacks": "off",
// limits the number of parameters that can be used in the function declaration.
"max-params": ["off", 3],
// specify the maximum number of statement allowed in a function
"max-statements": ["off", 10],
// restrict the number of statements per line
// https://eslint.org/docs/rules/max-statements-per-line
"max-statements-per-line": ["off", { max: 1 }],
// enforce a particular style for multiline comments
// https://eslint.org/docs/rules/multiline-comment-style
"multiline-comment-style": ["off", "starred-block"],
// require multiline ternary
// https://eslint.org/docs/rules/multiline-ternary
// TODO: enable?
"multiline-ternary": ["off", "never"],
// require a capital letter for constructors
"new-cap": ["error", {
newIsCap: true,
newIsCapExceptions: [],
capIsNew: false,
capIsNewExceptions: ["Immutable.Map", "Immutable.Set", "Immutable.List"],
}],
// disallow the omission of parentheses when invoking a constructor with no arguments
// https://eslint.org/docs/rules/new-parens
"new-parens": "error",
// allow/disallow an empty newline after var statement
"newline-after-var": "off",
// https://eslint.org/docs/rules/newline-before-return
"newline-before-return": "off",
// enforces new line after each method call in the chain to make it
// more readable and easy to maintain
// https://eslint.org/docs/rules/newline-per-chained-call
"newline-per-chained-call": ["error", { ignoreChainWithDepth: 4 }],
// disallow use of the Array constructor
"no-array-constructor": "error",
// disallow use of bitwise operators
// https://eslint.org/docs/rules/no-bitwise
// "no-bitwise": "error",
// disallow use of the continue statement
// https://eslint.org/docs/rules/no-continue
// "no-continue": "error",
// disallow comments inline after code
"no-inline-comments": "off",
// disallow if as the only statement in an else block
// https://eslint.org/docs/rules/no-lonely-if
"no-lonely-if": "error",
// disallow un-paren"d mixes of different operators
// https://eslint.org/docs/rules/no-mixed-operators
// "no-mixed-operators": ["error", {
// // the list of arthmetic groups disallows mixing `%` and `**`
// // with other arithmetic operators.
// groups: [
// ["%", "**"],
// ["%", "+"],
// ["%", "-"],
// ["%", "*"],
// ["%", "/"],
// ["**", "+"],
// ["**", "-"],
// ["**", "*"],
// ["**", "/"],
// ["&", "|", "^", "~", "<<", ">>", ">>>"],
// ["==", "!=", "===", "!==", ">", ">=", "<", "<="],
// ["&&", "||"],
// ["in", "instanceof"]
// ],
// allowSamePrecedence: false
// }],
// disallow mixed spaces and tabs for indentation
"no-mixed-spaces-and-tabs": "error",
// disallow use of chained assignment expressions
// https://eslint.org/docs/rules/no-multi-assign
// "no-multi-assign": ["error"],
// disallow multiple empty lines and only one newline at the end
"no-multiple-empty-lines": ["error", { max: 2, maxEOF: 0 }],
// disallow negated conditions
// https://eslint.org/docs/rules/no-negated-condition
"no-negated-condition": "off",
// disallow nested ternary expressions
// "no-nested-ternary": "error",
// disallow use of the Object constructor
"no-new-object": "error",
// disallow use of unary operators, ++ and --
// https://eslint.org/docs/rules/no-plusplus
// "no-plusplus": "error",
// disallow certain syntax forms
// https://eslint.org/docs/rules/no-restricted-syntax
"no-restricted-syntax": [
"error",
// {
// selector: "ForInStatement",
// message: "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.",
// },
{
selector: "ForOfStatement",
message: "iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.",
},
{
selector: "LabeledStatement",
message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
},
{
selector: "WithStatement",
message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
},
],
// disallow space between function identifier and application
"no-spaced-func": "error",
// disallow tab characters entirely
"no-tabs": "error",
// disallow the use of ternary operators
"no-ternary": "off",
// disallow trailing whitespace at the end of lines
"no-trailing-spaces": ["error", {
skipBlankLines: false,
ignoreComments: false,
}],
// disallow dangling underscores in identifiers
// "no-underscore-dangle": ["error", {
// allow: [],
// allowAfterThis: true,
// allowAfterSuper: false,
// enforceInMethodNames: false,
// }],
// disallow the use of Boolean literals in conditional expressions
// also, prefer `a || b` over `a ? a : b`
// https://eslint.org/docs/rules/no-unneeded-ternary
"no-unneeded-ternary": ["error", { defaultAssignment: false }],
// disallow whitespace before properties
// https://eslint.org/docs/rules/no-whitespace-before-property
"no-whitespace-before-property": "error",
// enforce the location of single-line statements
// https://eslint.org/docs/rules/nonblock-statement-body-position
"nonblock-statement-body-position": ["error", "beside", { overrides: {} }],
// require padding inside curly braces
"object-curly-spacing": ["error", "always"],
// enforce line breaks between braces
// https://eslint.org/docs/rules/object-curly-newline
"object-curly-newline": ["error", {
ObjectExpression: { minProperties: 4, multiline: true, consistent: true },
ObjectPattern: { minProperties: 4, multiline: true, consistent: true },
ImportDeclaration: { minProperties: 4, multiline: true, consistent: true },
ExportDeclaration: { minProperties: 4, multiline: true, consistent: true },
}],
// enforce "same line" or "multiple line" on object properties.
// https://eslint.org/docs/rules/object-property-newline
"object-property-newline": ["error", {
allowAllPropertiesOnSameLine: true,
}],
// allow just one var statement per function
"one-var": ["error", "never"],
// require a newline around variable declaration
// https://eslint.org/docs/rules/one-var-declaration-per-line
"one-var-declaration-per-line": ["error", "always"],
// require assignment operator shorthand where possible or prohibit it entirely
// https://eslint.org/docs/rules/operator-assignment
"operator-assignment": ["error", "always"],
// Requires operator at the beginning of the line in multiline statements
// https://eslint.org/docs/rules/operator-linebreak
"operator-linebreak": ["error", "before", { overrides: { "=": "none" } }],
// disallow padding within blocks
"padded-blocks": ["error", { blocks: "never", classes: "never", switches: "never" }],
// Require or disallow padding lines between statements
// https://eslint.org/docs/rules/padding-line-between-statements
"padding-line-between-statements": "off",
// Prefer use of an object spread over Object.assign
// https://eslint.org/docs/rules/prefer-object-spread
// TODO: semver-major (eslint 5): enable
"prefer-object-spread": "off",
// require quotes around object literal property names
// https://eslint.org/docs/rules/quote-props.html
"quote-props": ["error", "as-needed", { keywords: false, unnecessary: true, numbers: false }],
// specify whether double or single quotes should be used
quotes: ["error", "single", { avoidEscape: true }],
// do not require jsdoc
// https://eslint.org/docs/rules/require-jsdoc
"require-jsdoc": "off",
// require or disallow use of semicolons instead of ASI
semi: ["error", "always"],
// enforce spacing before and after semicolons
"semi-spacing": ["error", { before: false, after: true }],
// Enforce location of semicolons
// https://eslint.org/docs/rules/semi-style
"semi-style": ["error", "last"],
// requires object keys to be sorted
"sort-keys": ["off", "asc", { caseSensitive: false, natural: true }],
// sort variables within the same declaration block
"sort-vars": "off",
// require or disallow space before blocks
"space-before-blocks": "error",
// require or disallow space before function opening parenthesis
// https://eslint.org/docs/rules/space-before-function-paren
"space-before-function-paren": ["error", {
anonymous: "always",
named: "never",
asyncArrow: "always"
}],
// require or disallow spaces inside parentheses
"space-in-parens": ["error", "never"],
// require spaces around operators
"space-infix-ops": "error",
// Require or disallow spaces before/after unary operators
// https://eslint.org/docs/rules/space-unary-ops
"space-unary-ops": ["error", {
words: true,
nonwords: false,
overrides: {
},
}],
// require or disallow a space immediately following the // or /* in a comment
// https://eslint.org/docs/rules/spaced-comment
"spaced-comment": ["error", "always", {
line: {
exceptions: ["-", "+"],
markers: ["=", "!"], // space here to support sprockets directives
},
block: {
exceptions: ["-", "+"],
markers: ["=", "!"], // space here to support sprockets directives
balanced: true,
}
}],
// Enforce spacing around colons of switch statements
// https://eslint.org/docs/rules/switch-colon-spacing
"switch-colon-spacing": ["error", { after: true, before: false }],
// Require or disallow spacing between template tags and their literals
// https://eslint.org/docs/rules/template-tag-spacing
"template-tag-spacing": ["error", "never"],
// require or disallow the Unicode Byte Order Mark
// https://eslint.org/docs/rules/unicode-bom
"unicode-bom": ["error", "never"],
// require regex literals to be wrapped in parentheses
"wrap-regex": "off"
}
}

View File

@ -5,11 +5,11 @@
// No ES6 can be used in this file since it's used for the translation
/* eslint-disable prefer-arrow-callback */
(function() {
"use strict";
(function () {
'use strict';
// Fallback for all uncought errors
function handleError (event, err) {
function handleError(event, err) {
try {
const msg = document.getElementById('noVNC_fallback_errormsg');
@ -18,19 +18,19 @@
return false;
}
let div = document.createElement("div");
let div = document.createElement('div');
div.classList.add('noVNC_message');
div.appendChild(document.createTextNode(event.message));
msg.appendChild(div);
if (event.filename) {
div = document.createElement("div");
div = document.createElement('div');
div.className = 'noVNC_location';
let text = event.filename;
if (event.lineno !== undefined) {
text += ":" + event.lineno;
text += ':' + event.lineno;
if (event.colno !== undefined) {
text += ":" + event.colno;
text += ':' + event.colno;
}
}
div.appendChild(document.createTextNode(text));
@ -38,16 +38,16 @@
}
if (err && err.stack) {
div = document.createElement("div");
div = document.createElement('div');
div.className = 'noVNC_stack';
div.appendChild(document.createTextNode(err.stack));
msg.appendChild(div);
}
document.getElementById('noVNC_fallback_error')
.classList.add("noVNC_open");
.classList.add('noVNC_open');
} catch (exc) {
document.write("noVNC encountered an error.");
document.write('noVNC encountered an error.');
}
// Don't return true since this would prevent the error
// from being printed to the browser console.

View File

@ -34,15 +34,15 @@ export class Localizer {
userLanguages = [navigator.language || navigator.userLanguage];
}
for (let i = 0;i < userLanguages.length;i++) {
for (let i = 0; i < userLanguages.length; i++) {
const userLang = userLanguages[i]
.toLowerCase()
.replace("_", "-")
.split("-");
.replace('_', '-')
.split('-');
// Built-in default?
if ((userLang[0] === 'en') &&
((userLang[1] === undefined) || (userLang[1] === 'us'))) {
if ((userLang[0] === 'en')
&& ((userLang[1] === undefined) || (userLang[1] === 'us'))) {
return;
}
@ -50,29 +50,25 @@ export class Localizer {
for (let j = 0; j < supportedLanguages.length; j++) {
const supLang = supportedLanguages[j]
.toLowerCase()
.replace("_", "-")
.split("-");
.replace('_', '-')
.split('-');
if (userLang[0] !== supLang[0])
continue;
if (userLang[1] !== supLang[1])
continue;
if (userLang[0] !== supLang[0]) continue;
if (userLang[1] !== supLang[1]) continue;
this.language = supportedLanguages[j];
return;
}
// Second pass: fallback
for (let j = 0;j < supportedLanguages.length;j++) {
for (let j = 0; j < supportedLanguages.length; j++) {
const supLang = supportedLanguages[j]
.toLowerCase()
.replace("_", "-")
.split("-");
.replace('_', '-')
.split('-');
if (userLang[0] !== supLang[0])
continue;
if (supLang[1] !== undefined)
continue;
if (userLang[0] !== supLang[0]) continue;
if (supLang[1] !== undefined) continue;
this.language = supportedLanguages[j];
return;
@ -109,44 +105,44 @@ export class Localizer {
node.data = str;
}
if (elem.hasAttribute("translate")) {
if (isAnyOf(elem.getAttribute("translate"), ["", "yes"])) {
if (elem.hasAttribute('translate')) {
if (isAnyOf(elem.getAttribute('translate'), ['', 'yes'])) {
enabled = true;
} else if (isAnyOf(elem.getAttribute("translate"), ["no"])) {
} else if (isAnyOf(elem.getAttribute('translate'), ['no'])) {
enabled = false;
}
}
if (enabled) {
if (elem.hasAttribute("abbr") &&
elem.tagName === "TH") {
translateAttribute(elem, "abbr");
if (elem.hasAttribute('abbr')
&& elem.tagName === 'TH') {
translateAttribute(elem, 'abbr');
}
if (elem.hasAttribute("alt") &&
isAnyOf(elem.tagName, ["AREA", "IMG", "INPUT"])) {
translateAttribute(elem, "alt");
if (elem.hasAttribute('alt')
&& isAnyOf(elem.tagName, ['AREA', 'IMG', 'INPUT'])) {
translateAttribute(elem, 'alt');
}
if (elem.hasAttribute("download") &&
isAnyOf(elem.tagName, ["A", "AREA"])) {
translateAttribute(elem, "download");
if (elem.hasAttribute('download')
&& isAnyOf(elem.tagName, ['A', 'AREA'])) {
translateAttribute(elem, 'download');
}
if (elem.hasAttribute("label") &&
isAnyOf(elem.tagName, ["MENUITEM", "MENU", "OPTGROUP",
"OPTION", "TRACK"])) {
translateAttribute(elem, "label");
if (elem.hasAttribute('label')
&& isAnyOf(elem.tagName, ['MENUITEM', 'MENU', 'OPTGROUP',
'OPTION', 'TRACK'])) {
translateAttribute(elem, 'label');
}
// FIXME: Should update "lang"
if (elem.hasAttribute("placeholder") &&
isAnyOf(elem.tagName, ["INPUT", "TEXTAREA"])) {
translateAttribute(elem, "placeholder");
if (elem.hasAttribute('placeholder')
&& isAnyOf(elem.tagName, ['INPUT', 'TEXTAREA'])) {
translateAttribute(elem, 'placeholder');
}
if (elem.hasAttribute("title")) {
translateAttribute(elem, "title");
if (elem.hasAttribute('title')) {
translateAttribute(elem, 'title');
}
if (elem.hasAttribute("value") &&
elem.tagName === "INPUT" &&
isAnyOf(elem.getAttribute("type"), ["reset", "button", "submit"])) {
translateAttribute(elem, "value");
if (elem.hasAttribute('value')
&& elem.tagName === 'INPUT'
&& isAnyOf(elem.getAttribute('type'), ['reset', 'button', 'submit'])) {
translateAttribute(elem, 'value');
}
}

524
app/ui.js

File diff suppressed because it is too large Load Diff

View File

@ -10,9 +10,10 @@
import { init_logging as main_init_logging } from '../core/util/logging.js';
// init log level reading the logging HTTP param
export function init_logging (level) {
"use strict";
if (typeof level !== "undefined") {
export function init_logging(level) {
'use strict';
if (typeof level !== 'undefined') {
main_init_logging(level);
} else {
const param = document.location.href.match(/logging=([A-Za-z0-9._-]*)/);
@ -21,10 +22,13 @@ export function init_logging (level) {
}
// Read a query string variable
export function getQueryVar (name, defVal) {
"use strict";
const re = new RegExp('.*[?&]' + name + '=([^&#]*)'),
match = document.location.href.match(re);
export function getQueryVar(name, defVal) {
'use strict';
const re = new RegExp('.*[?&]' + name + '=([^&#]*)');
const match = document.location.href.match(re);
if (typeof defVal === 'undefined') { defVal = null; }
if (match) {
@ -35,10 +39,13 @@ export function getQueryVar (name, defVal) {
}
// Read a hash fragment variable
export function getHashVar (name, defVal) {
"use strict";
const re = new RegExp('.*[&#]' + name + '=([^&]*)'),
match = document.location.hash.match(re);
export function getHashVar(name, defVal) {
'use strict';
const re = new RegExp('.*[&#]' + name + '=([^&]*)');
const match = document.location.hash.match(re);
if (typeof defVal === 'undefined') { defVal = null; }
if (match) {
@ -50,8 +57,9 @@ export function getHashVar (name, defVal) {
// Read a variable from the fragment or the query string
// Fragment takes precedence
export function getConfigVar (name, defVal) {
"use strict";
export function getConfigVar(name, defVal) {
'use strict';
const val = getHashVar(name);
if (val === null) {
@ -66,29 +74,32 @@ export function getConfigVar (name, defVal) {
*/
// No days means only for this browser session
export function createCookie (name, value, days) {
"use strict";
let date, expires;
export function createCookie(name, value, days) {
'use strict';
let date; let
expires;
if (days) {
date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
expires = '; expires=' + date.toGMTString();
} else {
expires = "";
expires = '';
}
let secure;
if (document.location.protocol === "https:") {
secure = "; secure";
if (document.location.protocol === 'https:') {
secure = '; secure';
} else {
secure = "";
secure = '';
}
document.cookie = name + "=" + value + expires + "; path=/" + secure;
document.cookie = name + '=' + value + expires + '; path=/' + secure;
}
export function readCookie (name, defaultValue) {
"use strict";
const nameEQ = name + "=";
export function readCookie(name, defaultValue) {
'use strict';
const nameEQ = name + '=';
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i += 1) {
@ -104,9 +115,10 @@ export function readCookie (name, defaultValue) {
return (typeof defaultValue !== 'undefined') ? defaultValue : null;
}
export function eraseCookie (name) {
"use strict";
createCookie(name, "", -1);
export function eraseCookie(name) {
'use strict';
createCookie(name, '', -1);
}
/*
@ -115,8 +127,9 @@ export function eraseCookie (name) {
let settings = {};
export function initSettings (callback /*, ...callbackArgs */) {
"use strict";
export function initSettings(callback /* , ...callbackArgs */) {
'use strict';
const callbackArgs = Array.prototype.slice.call(arguments, 1);
if (window.chrome && window.chrome.storage) {
window.chrome.storage.sync.get((cfg) => {
@ -134,13 +147,14 @@ export function initSettings (callback /*, ...callbackArgs */) {
}
// Update the settings cache, but do not write to permanent storage
export function setSetting (name, value) {
export function setSetting(name, value) {
settings[name] = value;
}
// No days means only for this browser session
export function writeSetting (name, value) {
"use strict";
export function writeSetting(name, value) {
'use strict';
if (settings[name] === value) return;
settings[name] = value;
if (window.chrome && window.chrome.storage) {
@ -150,8 +164,9 @@ export function writeSetting (name, value) {
}
}
export function readSetting (name, defaultValue) {
"use strict";
export function readSetting(name, defaultValue) {
'use strict';
let value;
if ((name in settings) || (window.chrome && window.chrome.storage)) {
value = settings[name];
@ -159,19 +174,20 @@ export function readSetting (name, defaultValue) {
value = localStorage.getItem(name);
settings[name] = value;
}
if (typeof value === "undefined") {
if (typeof value === 'undefined') {
value = null;
}
if (value === null && typeof defaultValue !== "undefined") {
if (value === null && typeof defaultValue !== 'undefined') {
return defaultValue;
}
return value;
}
export function eraseSetting (name) {
"use strict";
export function eraseSetting(name) {
'use strict';
// Deleting here means that next time the setting is read when using local
// storage, it will be pulled from local storage again.
// If the setting in local storage is changed (e.g. in another tab)
@ -185,15 +201,15 @@ export function eraseSetting (name) {
}
}
export function injectParamIfMissing (path, param, value) {
export function injectParamIfMissing(path, param, value) {
// force pretend that we're dealing with a relative path
// (assume that we wanted an extra if we pass one in)
path = "/" + path;
path = '/' + path;
const elem = document.createElement('a');
elem.href = path;
const param_eq = encodeURIComponent(param) + "=";
const param_eq = encodeURIComponent(param) + '=';
let query;
if (elem.search) {
query = elem.search.slice(1).split('&');
@ -203,12 +219,12 @@ export function injectParamIfMissing (path, param, value) {
if (!query.some(v => v.startsWith(param_eq))) {
query.push(param_eq + encodeURIComponent(value));
elem.search = "?" + query.join("&");
elem.search = '?' + query.join('&');
}
// some browsers (e.g. IE11) may occasionally omit the leading slash
// in the elem.pathname string. Handle that case gracefully.
if (elem.pathname.charAt(0) == "/") {
if (elem.pathname.charAt(0) == '/') {
return elem.pathname.slice(1) + elem.search + elem.hash;
}

View File

@ -8,11 +8,12 @@ import * as Log from './util/logging.js';
export default {
/* Convert data (an array of integers) to a Base64 string. */
toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
base64Pad : '=',
toBase64Table: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
base64Pad: '=',
encode(data) {
"use strict";
'use strict';
let result = '';
const length = data.length;
const lengthpad = (length % 3);
@ -43,19 +44,19 @@ export default {
},
/* Convert Base64 data to a string */
toBinaryTable : [
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1,
-1, 0, 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,-1, -1,-1,-1,-1,
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
toBinaryTable: [
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1,
-1, 0, 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, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
],
decode(data, offset) {
offset = typeof(offset) !== 'undefined' ? offset : 0;
offset = typeof (offset) !== 'undefined' ? offset : 0;
let data_length = data.indexOf('=') - offset;
if (data_length < 0) { data_length = data.length - offset; }
@ -73,7 +74,7 @@ export default {
const padding = (data.charAt(i) === this.base64Pad);
// Skip illegal characters and whitespace
if (c === -1) {
Log.Error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
Log.Error('Illegal character code ' + data.charCodeAt(i) + ' at position ' + i);
continue;
}

View File

@ -76,16 +76,24 @@
*/
export default function DES(passwd) {
"use strict";
'use strict';
/* eslint-disable indent, comma-spacing, space-infix-ops */
// Tables, permutations, S-boxes, etc.
const PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28],
z = 0x0,
keys = [];
let a,b,c,d,e,f;
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31];
const totrot = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
const z = 0x0;
const keys = [];
let a;
let b;
let c;
let d;
let e;
let f;
a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
const SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
@ -128,14 +136,17 @@ export default function DES(passwd) {
a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
/* eslint-enable indent, comma-spacing, space-infix-ops */
// Set the key.
function setKeys(keyBlock) {
const pc1m = [], pcr = [], kn = [];
const pc1m = []; const pcr = []; const
kn = [];
for (let j = 0, l = 56; j < 56; ++j, l -= 8) {
l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
const m = l & 0x7;
pc1m[j] = ((keyBlock[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
pc1m[j] = ((keyBlock[l >>> 3] & (1 << m)) !== 0) ? 1 : 0;
}
for (let i = 0; i < 16; ++i) {
@ -178,11 +189,12 @@ export default function DES(passwd) {
// Encrypt 8 bytes of text
function enc8(text) {
const b = text.slice();
let i = 0, l, r, x; // left, right, accumulator
let i = 0; let l; let r; let
x; // left, right, accumulator
// Squash 8 bytes to 2 ints
l = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
r = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
l = b[i++] << 24 | b[i++] << 16 | b[i++] << 8 | b[i++];
r = b[i++] << 24 | b[i++] << 16 | b[i++] << 8 | b[i++];
x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
r ^= x;
@ -250,7 +262,7 @@ export default function DES(passwd) {
// Spread ints to bytes
x = [r, l];
for (i = 0; i < 8; i++) {
b[i] = (x[i>>>2] >>> (8 * (3 - (i % 4)))) % 256;
b[i] = (x[i >>> 2] >>> (8 * (3 - (i % 4)))) % 256;
if (b[i] < 0) { b[i] += 256; } // unsigned
}
return b;
@ -262,6 +274,5 @@ export default function DES(passwd) {
}
setKeys(passwd); // Setup keys
return {'encrypt': encrypt}; // Public interface
return { encrypt: encrypt }; // Public interface
}

View File

@ -8,7 +8,7 @@
*/
import * as Log from './util/logging.js';
import Base64 from "./base64.js";
import Base64 from './base64.js';
let SUPPORTS_IMAGEDATA_CONSTRUCTOR = false;
try {
@ -30,19 +30,19 @@ export default class Display {
this._fb_width = 0;
this._fb_height = 0;
this._prevDrawStyle = "";
this._prevDrawStyle = '';
this._tile = null;
this._tile16x16 = null;
this._tile_x = 0;
this._tile_y = 0;
Log.Debug(">> Display.constructor");
Log.Debug('>> Display.constructor');
// The visible canvas
this._target = target;
if (!this._target) {
throw new Error("Target must be set");
throw new Error('Target must be set');
}
if (typeof this._target === 'string') {
@ -50,33 +50,38 @@ export default class Display {
}
if (!this._target.getContext) {
throw new Error("no getContext method");
throw new Error('no getContext method');
}
this._targetCtx = this._target.getContext('2d');
// the visible canvas viewport (i.e. what actually gets seen)
this._viewportLoc = { 'x': 0, 'y': 0, 'w': this._target.width, 'h': this._target.height };
this._viewportLoc = {
x: 0, y: 0, w: this._target.width, h: this._target.height
};
// The hidden canvas, where we do the actual rendering
this._backbuffer = document.createElement('canvas');
this._drawCtx = this._backbuffer.getContext('2d');
this._damageBounds = { left:0, top:0,
this._damageBounds = {
left: 0,
top: 0,
right: this._backbuffer.width,
bottom: this._backbuffer.height };
bottom: this._backbuffer.height
};
Log.Debug("User Agent: " + navigator.userAgent);
Log.Debug('User Agent: ' + navigator.userAgent);
this.clear();
// Check canvas features
if (!('createImageData' in this._drawCtx)) {
throw new Error("Canvas does not support createImageData");
throw new Error('Canvas does not support createImageData');
}
this._tile16x16 = this._drawCtx.createImageData(16, 16);
Log.Debug("<< Display.constructor");
Log.Debug('<< Display.constructor');
// ===== PROPERTIES =====
@ -92,11 +97,13 @@ export default class Display {
// ===== PROPERTIES =====
get scale() { return this._scale; }
set scale(scale) {
this._rescale(scale);
}
get clipViewport() { return this._clipViewport; }
set clipViewport(viewport) {
this._clipViewport = viewport;
// May need to readjust the viewport dimensions
@ -147,7 +154,7 @@ export default class Display {
if (deltaX === 0 && deltaY === 0) {
return;
}
Log.Debug("viewportChange deltaX: " + deltaX + ", deltaY: " + deltaY);
Log.Debug('viewportChange deltaX: ' + deltaX + ', deltaY: ' + deltaY);
vp.x += deltaX;
vp.y += deltaY;
@ -158,12 +165,10 @@ export default class Display {
}
viewportChangeSize(width, height) {
if (!this._clipViewport ||
typeof(width) === "undefined" ||
typeof(height) === "undefined") {
Log.Debug("Setting viewport to full display region");
if (!this._clipViewport
|| typeof (width) === 'undefined'
|| typeof (height) === 'undefined') {
Log.Debug('Setting viewport to full display region');
width = this._fb_width;
height = this._fb_height;
}
@ -204,14 +209,13 @@ export default class Display {
}
resize(width, height) {
this._prevDrawStyle = "";
this._prevDrawStyle = '';
this._fb_width = width;
this._fb_height = height;
const canvas = this._backbuffer;
if (canvas.width !== width || canvas.height !== height) {
// We have to save the canvas data since changing the size will clear it
let saveImg = null;
if (canvas.width > 0 && canvas.height > 0) {
@ -258,7 +262,7 @@ export default class Display {
flip(from_queue) {
if (this._renderQ.length !== 0 && !from_queue) {
this._renderQ_push({
'type': 'flip'
type: 'flip'
});
} else {
let x = this._damageBounds.left;
@ -327,12 +331,12 @@ export default class Display {
fillRect(x, y, width, height, color, from_queue) {
if (this._renderQ.length !== 0 && !from_queue) {
this._renderQ_push({
'type': 'fill',
'x': x,
'y': y,
'width': width,
'height': height,
'color': color
type: 'fill',
x: x,
y: y,
width: width,
height: height,
color: color
});
} else {
this._setFillColor(color);
@ -344,13 +348,13 @@ export default class Display {
copyImage(old_x, old_y, new_x, new_y, w, h, from_queue) {
if (this._renderQ.length !== 0 && !from_queue) {
this._renderQ_push({
'type': 'copy',
'old_x': old_x,
'old_y': old_y,
'x': new_x,
'y': new_y,
'width': w,
'height': h,
type: 'copy',
old_x: old_x,
old_y: old_y,
x: new_x,
y: new_y,
width: w,
height: h,
});
} else {
// Due to this bug among others [1] we need to disable the image-smoothing to
@ -374,12 +378,12 @@ export default class Display {
imageRect(x, y, mime, arr) {
const img = new Image();
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
img.src = 'data: ' + mime + ';base64,' + Base64.encode(arr);
this._renderQ_push({
'type': 'img',
'img': img,
'x': x,
'y': y
type: 'img',
img: img,
x: x,
y: y
});
}
@ -442,19 +446,19 @@ export default class Display {
const new_arr = new Uint8Array(width * height * 4);
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
this._renderQ_push({
'type': 'blit',
'data': new_arr,
'x': x,
'y': y,
'width': width,
'height': height,
type: 'blit',
data: new_arr,
x: x,
y: y,
width: width,
height: height,
});
} else {
this._bgrxImageData(x, y, width, height, arr, offset);
}
}
blitRgbImage(x, y , width, height, arr, offset, from_queue) {
blitRgbImage(x, y, width, height, arr, offset, from_queue) {
if (this._renderQ.length !== 0 && !from_queue) {
// NB(directxman12): it's technically more performant here to use preallocated arrays,
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
@ -462,12 +466,12 @@ export default class Display {
const new_arr = new Uint8Array(width * height * 3);
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
this._renderQ_push({
'type': 'blitRgb',
'data': new_arr,
'x': x,
'y': y,
'width': width,
'height': height,
type: 'blitRgb',
data: new_arr,
x: x,
y: y,
width: width,
height: height,
});
} else {
this._rgbImageData(x, y, width, height, arr, offset);
@ -482,12 +486,12 @@ export default class Display {
const new_arr = new Uint8Array(width * height * 4);
new_arr.set(new Uint8Array(arr.buffer, 0, new_arr.length));
this._renderQ_push({
'type': 'blitRgbx',
'data': new_arr,
'x': x,
'y': y,
'width': width,
'height': height,
type: 'blitRgbx',
data: new_arr,
x: x,
y: y,
width: width,
height: height,
});
} else {
this._rgbxImageData(x, y, width, height, arr, offset);
@ -527,8 +531,8 @@ export default class Display {
const width = Math.round(factor * vp.w) + 'px';
const height = Math.round(factor * vp.h) + 'px';
if ((this._target.style.width !== width) ||
(this._target.style.height !== height)) {
if ((this._target.style.width !== width)
|| (this._target.style.height !== height)) {
this._target.style.width = width;
this._target.style.height = height;
}

View File

@ -30,12 +30,12 @@ export const encodings = {
export function encodingName(num) {
switch (num) {
case encodings.encodingRaw: return "Raw";
case encodings.encodingCopyRect: return "CopyRect";
case encodings.encodingRRE: return "RRE";
case encodings.encodingHextile: return "Hextile";
case encodings.encodingTight: return "Tight";
case encodings.encodingTightPNG: return "TightPNG";
default: return "[unknown encoding " + num + "]";
case encodings.encodingRaw: return 'Raw';
case encodings.encodingCopyRect: return 'CopyRect';
case encodings.encodingRRE: return 'RRE';
case encodings.encodingHextile: return 'Hextile';
case encodings.encodingTight: return 'Tight';
case encodings.encodingTightPNG: return 'TightPNG';
default: return '[unknown encoding ' + num + ']';
}
}

View File

@ -1,5 +1,5 @@
import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
import { inflateInit, inflate, inflateReset } from '../vendor/pako/lib/zlib/inflate.js';
import ZStream from '../vendor/pako/lib/zlib/zstream.js';
export default class Inflate {
constructor() {

View File

@ -4,7 +4,7 @@
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
import KeyTable from "./keysym.js";
import KeyTable from './keysym.js';
/*
* Mapping between HTML key values and VNC/X11 keysyms for "special"
@ -15,202 +15,199 @@ import KeyTable from "./keysym.js";
const DOMKeyTable = {};
function addStandard(key, standard)
{
if (standard === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
function addStandard(key, standard) {
if (standard === undefined) throw 'Undefined keysym for key "' + key + '"';
if (key in DOMKeyTable) throw 'Duplicate entry for key "' + key + '"';
DOMKeyTable[key] = [standard, standard, standard, standard];
}
function addLeftRight(key, left, right)
{
if (left === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (right === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
function addLeftRight(key, left, right) {
if (left === undefined) throw 'Undefined keysym for key "' + key + '"';
if (right === undefined) throw 'Undefined keysym for key "' + key + '"';
if (key in DOMKeyTable) throw 'Duplicate entry for key "' + key + '"';
DOMKeyTable[key] = [left, left, right, left];
}
function addNumpad(key, standard, numpad)
{
if (standard === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (numpad === undefined) throw "Undefined keysym for key \"" + key + "\"";
if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
function addNumpad(key, standard, numpad) {
if (standard === undefined) throw 'Undefined keysym for key "' + key + '"';
if (numpad === undefined) throw 'Undefined keysym for key "' + key + '"';
if (key in DOMKeyTable) throw 'Duplicate entry for key "' + key + '"';
DOMKeyTable[key] = [standard, standard, standard, numpad];
}
// 2.2. Modifier Keys
addLeftRight("Alt", KeyTable.XK_Alt_L, KeyTable.XK_Alt_R);
addStandard("AltGraph", KeyTable.XK_ISO_Level3_Shift);
addStandard("CapsLock", KeyTable.XK_Caps_Lock);
addLeftRight("Control", KeyTable.XK_Control_L, KeyTable.XK_Control_R);
addLeftRight('Alt', KeyTable.XK_Alt_L, KeyTable.XK_Alt_R);
addStandard('AltGraph', KeyTable.XK_ISO_Level3_Shift);
addStandard('CapsLock', KeyTable.XK_Caps_Lock);
addLeftRight('Control', KeyTable.XK_Control_L, KeyTable.XK_Control_R);
// - Fn
// - FnLock
addLeftRight("Hyper", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
addLeftRight("Meta", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
addStandard("NumLock", KeyTable.XK_Num_Lock);
addStandard("ScrollLock", KeyTable.XK_Scroll_Lock);
addLeftRight("Shift", KeyTable.XK_Shift_L, KeyTable.XK_Shift_R);
addLeftRight("Super", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
addLeftRight('Hyper', KeyTable.XK_Super_L, KeyTable.XK_Super_R);
addLeftRight('Meta', KeyTable.XK_Super_L, KeyTable.XK_Super_R);
addStandard('NumLock', KeyTable.XK_Num_Lock);
addStandard('ScrollLock', KeyTable.XK_Scroll_Lock);
addLeftRight('Shift', KeyTable.XK_Shift_L, KeyTable.XK_Shift_R);
addLeftRight('Super', KeyTable.XK_Super_L, KeyTable.XK_Super_R);
// - Symbol
// - SymbolLock
// 2.3. Whitespace Keys
addNumpad("Enter", KeyTable.XK_Return, KeyTable.XK_KP_Enter);
addStandard("Tab", KeyTable.XK_Tab);
addNumpad(" ", KeyTable.XK_space, KeyTable.XK_KP_Space);
addNumpad('Enter', KeyTable.XK_Return, KeyTable.XK_KP_Enter);
addStandard('Tab', KeyTable.XK_Tab);
addNumpad(' ', KeyTable.XK_space, KeyTable.XK_KP_Space);
// 2.4. Navigation Keys
addNumpad("ArrowDown", KeyTable.XK_Down, KeyTable.XK_KP_Down);
addNumpad("ArrowUp", KeyTable.XK_Up, KeyTable.XK_KP_Up);
addNumpad("ArrowLeft", KeyTable.XK_Left, KeyTable.XK_KP_Left);
addNumpad("ArrowRight", KeyTable.XK_Right, KeyTable.XK_KP_Right);
addNumpad("End", KeyTable.XK_End, KeyTable.XK_KP_End);
addNumpad("Home", KeyTable.XK_Home, KeyTable.XK_KP_Home);
addNumpad("PageDown", KeyTable.XK_Next, KeyTable.XK_KP_Next);
addNumpad("PageUp", KeyTable.XK_Prior, KeyTable.XK_KP_Prior);
addNumpad('ArrowDown', KeyTable.XK_Down, KeyTable.XK_KP_Down);
addNumpad('ArrowUp', KeyTable.XK_Up, KeyTable.XK_KP_Up);
addNumpad('ArrowLeft', KeyTable.XK_Left, KeyTable.XK_KP_Left);
addNumpad('ArrowRight', KeyTable.XK_Right, KeyTable.XK_KP_Right);
addNumpad('End', KeyTable.XK_End, KeyTable.XK_KP_End);
addNumpad('Home', KeyTable.XK_Home, KeyTable.XK_KP_Home);
addNumpad('PageDown', KeyTable.XK_Next, KeyTable.XK_KP_Next);
addNumpad('PageUp', KeyTable.XK_Prior, KeyTable.XK_KP_Prior);
// 2.5. Editing Keys
addStandard("Backspace", KeyTable.XK_BackSpace);
addNumpad("Clear", KeyTable.XK_Clear, KeyTable.XK_KP_Begin);
addStandard("Copy", KeyTable.XF86XK_Copy);
addStandard('Backspace', KeyTable.XK_BackSpace);
addNumpad('Clear', KeyTable.XK_Clear, KeyTable.XK_KP_Begin);
addStandard('Copy', KeyTable.XF86XK_Copy);
// - CrSel
addStandard("Cut", KeyTable.XF86XK_Cut);
addNumpad("Delete", KeyTable.XK_Delete, KeyTable.XK_KP_Delete);
addStandard('Cut', KeyTable.XF86XK_Cut);
addNumpad('Delete', KeyTable.XK_Delete, KeyTable.XK_KP_Delete);
// - EraseEof
// - ExSel
addNumpad("Insert", KeyTable.XK_Insert, KeyTable.XK_KP_Insert);
addStandard("Paste", KeyTable.XF86XK_Paste);
addStandard("Redo", KeyTable.XK_Redo);
addStandard("Undo", KeyTable.XK_Undo);
addNumpad('Insert', KeyTable.XK_Insert, KeyTable.XK_KP_Insert);
addStandard('Paste', KeyTable.XF86XK_Paste);
addStandard('Redo', KeyTable.XK_Redo);
addStandard('Undo', KeyTable.XK_Undo);
// 2.6. UI Keys
// - Accept
// - Again (could just be XK_Redo)
// - Attn
addStandard("Cancel", KeyTable.XK_Cancel);
addStandard("ContextMenu", KeyTable.XK_Menu);
addStandard("Escape", KeyTable.XK_Escape);
addStandard("Execute", KeyTable.XK_Execute);
addStandard("Find", KeyTable.XK_Find);
addStandard("Help", KeyTable.XK_Help);
addStandard("Pause", KeyTable.XK_Pause);
addStandard('Cancel', KeyTable.XK_Cancel);
addStandard('ContextMenu', KeyTable.XK_Menu);
addStandard('Escape', KeyTable.XK_Escape);
addStandard('Execute', KeyTable.XK_Execute);
addStandard('Find', KeyTable.XK_Find);
addStandard('Help', KeyTable.XK_Help);
addStandard('Pause', KeyTable.XK_Pause);
// - Play
// - Props
addStandard("Select", KeyTable.XK_Select);
addStandard("ZoomIn", KeyTable.XF86XK_ZoomIn);
addStandard("ZoomOut", KeyTable.XF86XK_ZoomOut);
addStandard('Select', KeyTable.XK_Select);
addStandard('ZoomIn', KeyTable.XF86XK_ZoomIn);
addStandard('ZoomOut', KeyTable.XF86XK_ZoomOut);
// 2.7. Device Keys
addStandard("BrightnessDown", KeyTable.XF86XK_MonBrightnessDown);
addStandard("BrightnessUp", KeyTable.XF86XK_MonBrightnessUp);
addStandard("Eject", KeyTable.XF86XK_Eject);
addStandard("LogOff", KeyTable.XF86XK_LogOff);
addStandard("Power", KeyTable.XF86XK_PowerOff);
addStandard("PowerOff", KeyTable.XF86XK_PowerDown);
addStandard("PrintScreen", KeyTable.XK_Print);
addStandard("Hibernate", KeyTable.XF86XK_Hibernate);
addStandard("Standby", KeyTable.XF86XK_Standby);
addStandard("WakeUp", KeyTable.XF86XK_WakeUp);
addStandard('BrightnessDown', KeyTable.XF86XK_MonBrightnessDown);
addStandard('BrightnessUp', KeyTable.XF86XK_MonBrightnessUp);
addStandard('Eject', KeyTable.XF86XK_Eject);
addStandard('LogOff', KeyTable.XF86XK_LogOff);
addStandard('Power', KeyTable.XF86XK_PowerOff);
addStandard('PowerOff', KeyTable.XF86XK_PowerDown);
addStandard('PrintScreen', KeyTable.XK_Print);
addStandard('Hibernate', KeyTable.XF86XK_Hibernate);
addStandard('Standby', KeyTable.XF86XK_Standby);
addStandard('WakeUp', KeyTable.XF86XK_WakeUp);
// 2.8. IME and Composition Keys
addStandard("AllCandidates", KeyTable.XK_MultipleCandidate);
addStandard("Alphanumeric", KeyTable.XK_Eisu_Shift); // could also be _Eisu_Toggle
addStandard("CodeInput", KeyTable.XK_Codeinput);
addStandard("Compose", KeyTable.XK_Multi_key);
addStandard("Convert", KeyTable.XK_Henkan);
addStandard('AllCandidates', KeyTable.XK_MultipleCandidate);
addStandard('Alphanumeric', KeyTable.XK_Eisu_Shift); // could also be _Eisu_Toggle
addStandard('CodeInput', KeyTable.XK_Codeinput);
addStandard('Compose', KeyTable.XK_Multi_key);
addStandard('Convert', KeyTable.XK_Henkan);
// - Dead
// - FinalMode
addStandard("GroupFirst", KeyTable.XK_ISO_First_Group);
addStandard("GroupLast", KeyTable.XK_ISO_Last_Group);
addStandard("GroupNext", KeyTable.XK_ISO_Next_Group);
addStandard("GroupPrevious", KeyTable.XK_ISO_Prev_Group);
addStandard('GroupFirst', KeyTable.XK_ISO_First_Group);
addStandard('GroupLast', KeyTable.XK_ISO_Last_Group);
addStandard('GroupNext', KeyTable.XK_ISO_Next_Group);
addStandard('GroupPrevious', KeyTable.XK_ISO_Prev_Group);
// - ModeChange (XK_Mode_switch is often used for AltGr)
// - NextCandidate
addStandard("NonConvert", KeyTable.XK_Muhenkan);
addStandard("PreviousCandidate", KeyTable.XK_PreviousCandidate);
addStandard('NonConvert', KeyTable.XK_Muhenkan);
addStandard('PreviousCandidate', KeyTable.XK_PreviousCandidate);
// - Process
addStandard("SingleCandidate", KeyTable.XK_SingleCandidate);
addStandard("HangulMode", KeyTable.XK_Hangul);
addStandard("HanjaMode", KeyTable.XK_Hangul_Hanja);
addStandard("JunjuaMode", KeyTable.XK_Hangul_Jeonja);
addStandard("Eisu", KeyTable.XK_Eisu_toggle);
addStandard("Hankaku", KeyTable.XK_Hankaku);
addStandard("Hiragana", KeyTable.XK_Hiragana);
addStandard("HiraganaKatakana", KeyTable.XK_Hiragana_Katakana);
addStandard("KanaMode", KeyTable.XK_Kana_Shift); // could also be _Kana_Lock
addStandard("KanjiMode", KeyTable.XK_Kanji);
addStandard("Katakana", KeyTable.XK_Katakana);
addStandard("Romaji", KeyTable.XK_Romaji);
addStandard("Zenkaku", KeyTable.XK_Zenkaku);
addStandard("ZenkakuHanaku", KeyTable.XK_Zenkaku_Hankaku);
addStandard('SingleCandidate', KeyTable.XK_SingleCandidate);
addStandard('HangulMode', KeyTable.XK_Hangul);
addStandard('HanjaMode', KeyTable.XK_Hangul_Hanja);
addStandard('JunjuaMode', KeyTable.XK_Hangul_Jeonja);
addStandard('Eisu', KeyTable.XK_Eisu_toggle);
addStandard('Hankaku', KeyTable.XK_Hankaku);
addStandard('Hiragana', KeyTable.XK_Hiragana);
addStandard('HiraganaKatakana', KeyTable.XK_Hiragana_Katakana);
addStandard('KanaMode', KeyTable.XK_Kana_Shift); // could also be _Kana_Lock
addStandard('KanjiMode', KeyTable.XK_Kanji);
addStandard('Katakana', KeyTable.XK_Katakana);
addStandard('Romaji', KeyTable.XK_Romaji);
addStandard('Zenkaku', KeyTable.XK_Zenkaku);
addStandard('ZenkakuHanaku', KeyTable.XK_Zenkaku_Hankaku);
// 2.9. General-Purpose Function Keys
addStandard("F1", KeyTable.XK_F1);
addStandard("F2", KeyTable.XK_F2);
addStandard("F3", KeyTable.XK_F3);
addStandard("F4", KeyTable.XK_F4);
addStandard("F5", KeyTable.XK_F5);
addStandard("F6", KeyTable.XK_F6);
addStandard("F7", KeyTable.XK_F7);
addStandard("F8", KeyTable.XK_F8);
addStandard("F9", KeyTable.XK_F9);
addStandard("F10", KeyTable.XK_F10);
addStandard("F11", KeyTable.XK_F11);
addStandard("F12", KeyTable.XK_F12);
addStandard("F13", KeyTable.XK_F13);
addStandard("F14", KeyTable.XK_F14);
addStandard("F15", KeyTable.XK_F15);
addStandard("F16", KeyTable.XK_F16);
addStandard("F17", KeyTable.XK_F17);
addStandard("F18", KeyTable.XK_F18);
addStandard("F19", KeyTable.XK_F19);
addStandard("F20", KeyTable.XK_F20);
addStandard("F21", KeyTable.XK_F21);
addStandard("F22", KeyTable.XK_F22);
addStandard("F23", KeyTable.XK_F23);
addStandard("F24", KeyTable.XK_F24);
addStandard("F25", KeyTable.XK_F25);
addStandard("F26", KeyTable.XK_F26);
addStandard("F27", KeyTable.XK_F27);
addStandard("F28", KeyTable.XK_F28);
addStandard("F29", KeyTable.XK_F29);
addStandard("F30", KeyTable.XK_F30);
addStandard("F31", KeyTable.XK_F31);
addStandard("F32", KeyTable.XK_F32);
addStandard("F33", KeyTable.XK_F33);
addStandard("F34", KeyTable.XK_F34);
addStandard("F35", KeyTable.XK_F35);
addStandard('F1', KeyTable.XK_F1);
addStandard('F2', KeyTable.XK_F2);
addStandard('F3', KeyTable.XK_F3);
addStandard('F4', KeyTable.XK_F4);
addStandard('F5', KeyTable.XK_F5);
addStandard('F6', KeyTable.XK_F6);
addStandard('F7', KeyTable.XK_F7);
addStandard('F8', KeyTable.XK_F8);
addStandard('F9', KeyTable.XK_F9);
addStandard('F10', KeyTable.XK_F10);
addStandard('F11', KeyTable.XK_F11);
addStandard('F12', KeyTable.XK_F12);
addStandard('F13', KeyTable.XK_F13);
addStandard('F14', KeyTable.XK_F14);
addStandard('F15', KeyTable.XK_F15);
addStandard('F16', KeyTable.XK_F16);
addStandard('F17', KeyTable.XK_F17);
addStandard('F18', KeyTable.XK_F18);
addStandard('F19', KeyTable.XK_F19);
addStandard('F20', KeyTable.XK_F20);
addStandard('F21', KeyTable.XK_F21);
addStandard('F22', KeyTable.XK_F22);
addStandard('F23', KeyTable.XK_F23);
addStandard('F24', KeyTable.XK_F24);
addStandard('F25', KeyTable.XK_F25);
addStandard('F26', KeyTable.XK_F26);
addStandard('F27', KeyTable.XK_F27);
addStandard('F28', KeyTable.XK_F28);
addStandard('F29', KeyTable.XK_F29);
addStandard('F30', KeyTable.XK_F30);
addStandard('F31', KeyTable.XK_F31);
addStandard('F32', KeyTable.XK_F32);
addStandard('F33', KeyTable.XK_F33);
addStandard('F34', KeyTable.XK_F34);
addStandard('F35', KeyTable.XK_F35);
// - Soft1...
// 2.10. Multimedia Keys
// - ChannelDown
// - ChannelUp
addStandard("Close", KeyTable.XF86XK_Close);
addStandard("MailForward", KeyTable.XF86XK_MailForward);
addStandard("MailReply", KeyTable.XF86XK_Reply);
addStandard("MainSend", KeyTable.XF86XK_Send);
addStandard("MediaFastForward", KeyTable.XF86XK_AudioForward);
addStandard("MediaPause", KeyTable.XF86XK_AudioPause);
addStandard("MediaPlay", KeyTable.XF86XK_AudioPlay);
addStandard("MediaRecord", KeyTable.XF86XK_AudioRecord);
addStandard("MediaRewind", KeyTable.XF86XK_AudioRewind);
addStandard("MediaStop", KeyTable.XF86XK_AudioStop);
addStandard("MediaTrackNext", KeyTable.XF86XK_AudioNext);
addStandard("MediaTrackPrevious", KeyTable.XF86XK_AudioPrev);
addStandard("New", KeyTable.XF86XK_New);
addStandard("Open", KeyTable.XF86XK_Open);
addStandard("Print", KeyTable.XK_Print);
addStandard("Save", KeyTable.XF86XK_Save);
addStandard("SpellCheck", KeyTable.XF86XK_Spell);
addStandard('Close', KeyTable.XF86XK_Close);
addStandard('MailForward', KeyTable.XF86XK_MailForward);
addStandard('MailReply', KeyTable.XF86XK_Reply);
addStandard('MainSend', KeyTable.XF86XK_Send);
addStandard('MediaFastForward', KeyTable.XF86XK_AudioForward);
addStandard('MediaPause', KeyTable.XF86XK_AudioPause);
addStandard('MediaPlay', KeyTable.XF86XK_AudioPlay);
addStandard('MediaRecord', KeyTable.XF86XK_AudioRecord);
addStandard('MediaRewind', KeyTable.XF86XK_AudioRewind);
addStandard('MediaStop', KeyTable.XF86XK_AudioStop);
addStandard('MediaTrackNext', KeyTable.XF86XK_AudioNext);
addStandard('MediaTrackPrevious', KeyTable.XF86XK_AudioPrev);
addStandard('New', KeyTable.XF86XK_New);
addStandard('Open', KeyTable.XF86XK_Open);
addStandard('Print', KeyTable.XK_Print);
addStandard('Save', KeyTable.XF86XK_Save);
addStandard('SpellCheck', KeyTable.XF86XK_Spell);
// 2.11. Multimedia Numpad Keys
@ -231,13 +228,13 @@ addStandard("SpellCheck", KeyTable.XF86XK_Spell);
// - AudioSurroundModeNext
// - AudioTrebleDown
// - AudioTrebleUp
addStandard("AudioVolumeDown", KeyTable.XF86XK_AudioLowerVolume);
addStandard("AudioVolumeUp", KeyTable.XF86XK_AudioRaiseVolume);
addStandard("AudioVolumeMute", KeyTable.XF86XK_AudioMute);
addStandard('AudioVolumeDown', KeyTable.XF86XK_AudioLowerVolume);
addStandard('AudioVolumeUp', KeyTable.XF86XK_AudioRaiseVolume);
addStandard('AudioVolumeMute', KeyTable.XF86XK_AudioMute);
// - MicrophoneToggle
// - MicrophoneVolumeDown
// - MicrophoneVolumeUp
addStandard("MicrophoneVolumeMute", KeyTable.XF86XK_AudioMicMute);
addStandard('MicrophoneVolumeMute', KeyTable.XF86XK_AudioMicMute);
// 2.13. Speech Keys
@ -246,28 +243,28 @@ addStandard("MicrophoneVolumeMute", KeyTable.XF86XK_AudioMicMute);
// 2.14. Application Keys
addStandard("LaunchCalculator", KeyTable.XF86XK_Calculator);
addStandard("LaunchCalendar", KeyTable.XF86XK_Calendar);
addStandard("LaunchMail", KeyTable.XF86XK_Mail);
addStandard("LaunchMediaPlayer", KeyTable.XF86XK_AudioMedia);
addStandard("LaunchMusicPlayer", KeyTable.XF86XK_Music);
addStandard("LaunchMyComputer", KeyTable.XF86XK_MyComputer);
addStandard("LaunchPhone", KeyTable.XF86XK_Phone);
addStandard("LaunchScreenSaver", KeyTable.XF86XK_ScreenSaver);
addStandard("LaunchSpreadsheet", KeyTable.XF86XK_Excel);
addStandard("LaunchWebBrowser", KeyTable.XF86XK_WWW);
addStandard("LaunchWebCam", KeyTable.XF86XK_WebCam);
addStandard("LaunchWordProcessor", KeyTable.XF86XK_Word);
addStandard('LaunchCalculator', KeyTable.XF86XK_Calculator);
addStandard('LaunchCalendar', KeyTable.XF86XK_Calendar);
addStandard('LaunchMail', KeyTable.XF86XK_Mail);
addStandard('LaunchMediaPlayer', KeyTable.XF86XK_AudioMedia);
addStandard('LaunchMusicPlayer', KeyTable.XF86XK_Music);
addStandard('LaunchMyComputer', KeyTable.XF86XK_MyComputer);
addStandard('LaunchPhone', KeyTable.XF86XK_Phone);
addStandard('LaunchScreenSaver', KeyTable.XF86XK_ScreenSaver);
addStandard('LaunchSpreadsheet', KeyTable.XF86XK_Excel);
addStandard('LaunchWebBrowser', KeyTable.XF86XK_WWW);
addStandard('LaunchWebCam', KeyTable.XF86XK_WebCam);
addStandard('LaunchWordProcessor', KeyTable.XF86XK_Word);
// 2.15. Browser Keys
addStandard("BrowserBack", KeyTable.XF86XK_Back);
addStandard("BrowserFavorites", KeyTable.XF86XK_Favorites);
addStandard("BrowserForward", KeyTable.XF86XK_Forward);
addStandard("BrowserHome", KeyTable.XF86XK_HomePage);
addStandard("BrowserRefresh", KeyTable.XF86XK_Refresh);
addStandard("BrowserSearch", KeyTable.XF86XK_Search);
addStandard("BrowserStop", KeyTable.XF86XK_Stop);
addStandard('BrowserBack', KeyTable.XF86XK_Back);
addStandard('BrowserFavorites', KeyTable.XF86XK_Favorites);
addStandard('BrowserForward', KeyTable.XF86XK_Forward);
addStandard('BrowserHome', KeyTable.XF86XK_HomePage);
addStandard('BrowserRefresh', KeyTable.XF86XK_Refresh);
addStandard('BrowserSearch', KeyTable.XF86XK_Search);
addStandard('BrowserStop', KeyTable.XF86XK_Stop);
// 2.16. Mobile Phone Keys
@ -280,31 +277,31 @@ addStandard("BrowserStop", KeyTable.XF86XK_Stop);
// 2.18. Media Controller Keys
// - A whole bunch...
addStandard("Dimmer", KeyTable.XF86XK_BrightnessAdjust);
addStandard("MediaAudioTrack", KeyTable.XF86XK_AudioCycleTrack);
addStandard("RandomToggle", KeyTable.XF86XK_AudioRandomPlay);
addStandard("SplitScreenToggle", KeyTable.XF86XK_SplitScreen);
addStandard("Subtitle", KeyTable.XF86XK_Subtitle);
addStandard("VideoModeNext", KeyTable.XF86XK_Next_VMode);
addStandard('Dimmer', KeyTable.XF86XK_BrightnessAdjust);
addStandard('MediaAudioTrack', KeyTable.XF86XK_AudioCycleTrack);
addStandard('RandomToggle', KeyTable.XF86XK_AudioRandomPlay);
addStandard('SplitScreenToggle', KeyTable.XF86XK_SplitScreen);
addStandard('Subtitle', KeyTable.XF86XK_Subtitle);
addStandard('VideoModeNext', KeyTable.XF86XK_Next_VMode);
// Extra: Numpad
addNumpad("=", KeyTable.XK_equal, KeyTable.XK_KP_Equal);
addNumpad("+", KeyTable.XK_plus, KeyTable.XK_KP_Add);
addNumpad("-", KeyTable.XK_minus, KeyTable.XK_KP_Subtract);
addNumpad("*", KeyTable.XK_asterisk, KeyTable.XK_KP_Multiply);
addNumpad("/", KeyTable.XK_slash, KeyTable.XK_KP_Divide);
addNumpad(".", KeyTable.XK_period, KeyTable.XK_KP_Decimal);
addNumpad(",", KeyTable.XK_comma, KeyTable.XK_KP_Separator);
addNumpad("0", KeyTable.XK_0, KeyTable.XK_KP_0);
addNumpad("1", KeyTable.XK_1, KeyTable.XK_KP_1);
addNumpad("2", KeyTable.XK_2, KeyTable.XK_KP_2);
addNumpad("3", KeyTable.XK_3, KeyTable.XK_KP_3);
addNumpad("4", KeyTable.XK_4, KeyTable.XK_KP_4);
addNumpad("5", KeyTable.XK_5, KeyTable.XK_KP_5);
addNumpad("6", KeyTable.XK_6, KeyTable.XK_KP_6);
addNumpad("7", KeyTable.XK_7, KeyTable.XK_KP_7);
addNumpad("8", KeyTable.XK_8, KeyTable.XK_KP_8);
addNumpad("9", KeyTable.XK_9, KeyTable.XK_KP_9);
addNumpad('=', KeyTable.XK_equal, KeyTable.XK_KP_Equal);
addNumpad('+', KeyTable.XK_plus, KeyTable.XK_KP_Add);
addNumpad('-', KeyTable.XK_minus, KeyTable.XK_KP_Subtract);
addNumpad('*', KeyTable.XK_asterisk, KeyTable.XK_KP_Multiply);
addNumpad('/', KeyTable.XK_slash, KeyTable.XK_KP_Divide);
addNumpad('.', KeyTable.XK_period, KeyTable.XK_KP_Decimal);
addNumpad(',', KeyTable.XK_comma, KeyTable.XK_KP_Separator);
addNumpad('0', KeyTable.XK_0, KeyTable.XK_KP_0);
addNumpad('1', KeyTable.XK_1, KeyTable.XK_KP_1);
addNumpad('2', KeyTable.XK_2, KeyTable.XK_KP_2);
addNumpad('3', KeyTable.XK_3, KeyTable.XK_KP_3);
addNumpad('4', KeyTable.XK_4, KeyTable.XK_KP_4);
addNumpad('5', KeyTable.XK_5, KeyTable.XK_KP_5);
addNumpad('6', KeyTable.XK_6, KeyTable.XK_KP_6);
addNumpad('7', KeyTable.XK_7, KeyTable.XK_KP_7);
addNumpad('8', KeyTable.XK_8, KeyTable.XK_KP_8);
addNumpad('9', KeyTable.XK_9, KeyTable.XK_KP_9);
export default DOMKeyTable;

View File

@ -18,110 +18,110 @@ export default {
// 3.1.1.1. Writing System Keys
'Backspace': 'Backspace',
Backspace: 'Backspace',
// 3.1.1.2. Functional Keys
// 3.1.1.2. Functional Keys
'AltLeft': 'Alt',
'AltRight': 'Alt', // This could also be 'AltGraph'
'CapsLock': 'CapsLock',
'ContextMenu': 'ContextMenu',
'ControlLeft': 'Control',
'ControlRight': 'Control',
'Enter': 'Enter',
'MetaLeft': 'Meta',
'MetaRight': 'Meta',
'ShiftLeft': 'Shift',
'ShiftRight': 'Shift',
'Tab': 'Tab',
AltLeft: 'Alt',
AltRight: 'Alt', // This could also be 'AltGraph'
CapsLock: 'CapsLock',
ContextMenu: 'ContextMenu',
ControlLeft: 'Control',
ControlRight: 'Control',
Enter: 'Enter',
MetaLeft: 'Meta',
MetaRight: 'Meta',
ShiftLeft: 'Shift',
ShiftRight: 'Shift',
Tab: 'Tab',
// FIXME: Japanese/Korean keys
// 3.1.2. Control Pad Section
// 3.1.2. Control Pad Section
'Delete': 'Delete',
'End': 'End',
'Help': 'Help',
'Home': 'Home',
'Insert': 'Insert',
'PageDown': 'PageDown',
'PageUp': 'PageUp',
Delete: 'Delete',
End: 'End',
Help: 'Help',
Home: 'Home',
Insert: 'Insert',
PageDown: 'PageDown',
PageUp: 'PageUp',
// 3.1.3. Arrow Pad Section
// 3.1.3. Arrow Pad Section
'ArrowDown': 'ArrowDown',
'ArrowLeft': 'ArrowLeft',
'ArrowRight': 'ArrowRight',
'ArrowUp': 'ArrowUp',
ArrowDown: 'ArrowDown',
ArrowLeft: 'ArrowLeft',
ArrowRight: 'ArrowRight',
ArrowUp: 'ArrowUp',
// 3.1.4. Numpad Section
// 3.1.4. Numpad Section
'NumLock': 'NumLock',
'NumpadBackspace': 'Backspace',
'NumpadClear': 'Clear',
NumLock: 'NumLock',
NumpadBackspace: 'Backspace',
NumpadClear: 'Clear',
// 3.1.5. Function Section
// 3.1.5. Function Section
'Escape': 'Escape',
'F1': 'F1',
'F2': 'F2',
'F3': 'F3',
'F4': 'F4',
'F5': 'F5',
'F6': 'F6',
'F7': 'F7',
'F8': 'F8',
'F9': 'F9',
'F10': 'F10',
'F11': 'F11',
'F12': 'F12',
'F13': 'F13',
'F14': 'F14',
'F15': 'F15',
'F16': 'F16',
'F17': 'F17',
'F18': 'F18',
'F19': 'F19',
'F20': 'F20',
'F21': 'F21',
'F22': 'F22',
'F23': 'F23',
'F24': 'F24',
'F25': 'F25',
'F26': 'F26',
'F27': 'F27',
'F28': 'F28',
'F29': 'F29',
'F30': 'F30',
'F31': 'F31',
'F32': 'F32',
'F33': 'F33',
'F34': 'F34',
'F35': 'F35',
'PrintScreen': 'PrintScreen',
'ScrollLock': 'ScrollLock',
'Pause': 'Pause',
Escape: 'Escape',
F1: 'F1',
F2: 'F2',
F3: 'F3',
F4: 'F4',
F5: 'F5',
F6: 'F6',
F7: 'F7',
F8: 'F8',
F9: 'F9',
F10: 'F10',
F11: 'F11',
F12: 'F12',
F13: 'F13',
F14: 'F14',
F15: 'F15',
F16: 'F16',
F17: 'F17',
F18: 'F18',
F19: 'F19',
F20: 'F20',
F21: 'F21',
F22: 'F22',
F23: 'F23',
F24: 'F24',
F25: 'F25',
F26: 'F26',
F27: 'F27',
F28: 'F28',
F29: 'F29',
F30: 'F30',
F31: 'F31',
F32: 'F32',
F33: 'F33',
F34: 'F34',
F35: 'F35',
PrintScreen: 'PrintScreen',
ScrollLock: 'ScrollLock',
Pause: 'Pause',
// 3.1.6. Media Keys
// 3.1.6. Media Keys
'BrowserBack': 'BrowserBack',
'BrowserFavorites': 'BrowserFavorites',
'BrowserForward': 'BrowserForward',
'BrowserHome': 'BrowserHome',
'BrowserRefresh': 'BrowserRefresh',
'BrowserSearch': 'BrowserSearch',
'BrowserStop': 'BrowserStop',
'Eject': 'Eject',
'LaunchApp1': 'LaunchMyComputer',
'LaunchApp2': 'LaunchCalendar',
'LaunchMail': 'LaunchMail',
'MediaPlayPause': 'MediaPlay',
'MediaStop': 'MediaStop',
'MediaTrackNext': 'MediaTrackNext',
'MediaTrackPrevious': 'MediaTrackPrevious',
'Power': 'Power',
'Sleep': 'Sleep',
'AudioVolumeDown': 'AudioVolumeDown',
'AudioVolumeMute': 'AudioVolumeMute',
'AudioVolumeUp': 'AudioVolumeUp',
'WakeUp': 'WakeUp',
BrowserBack: 'BrowserBack',
BrowserFavorites: 'BrowserFavorites',
BrowserForward: 'BrowserForward',
BrowserHome: 'BrowserHome',
BrowserRefresh: 'BrowserRefresh',
BrowserSearch: 'BrowserSearch',
BrowserStop: 'BrowserStop',
Eject: 'Eject',
LaunchApp1: 'LaunchMyComputer',
LaunchApp2: 'LaunchCalendar',
LaunchMail: 'LaunchMail',
MediaPlayPause: 'MediaPlay',
MediaStop: 'MediaStop',
MediaTrackNext: 'MediaTrackNext',
MediaTrackPrevious: 'MediaTrackPrevious',
Power: 'Power',
Sleep: 'Sleep',
AudioVolumeDown: 'AudioVolumeDown',
AudioVolumeMute: 'AudioVolumeMute',
AudioVolumeUp: 'AudioVolumeUp',
WakeUp: 'WakeUp',
};

View File

@ -7,9 +7,9 @@
import * as Log from '../util/logging.js';
import { stopEvent } from '../util/events.js';
import * as KeyboardUtil from "./util.js";
import KeyTable from "./keysym.js";
import * as browser from "../util/browser.js";
import * as KeyboardUtil from './util.js';
import KeyTable from './keysym.js';
import * as browser from '../util/browser.js';
//
// Keyboard event handler
@ -26,11 +26,11 @@ export default class Keyboard {
// keep these here so we can refer to them later
this._eventHandlers = {
'keyup': this._handleKeyUp.bind(this),
'keydown': this._handleKeyDown.bind(this),
'keypress': this._handleKeyPress.bind(this),
'blur': this._allKeysUp.bind(this),
'checkalt': this._checkAlt.bind(this),
keyup: this._handleKeyUp.bind(this),
keydown: this._handleKeyDown.bind(this),
keypress: this._handleKeyPress.bind(this),
blur: this._allKeysUp.bind(this),
checkalt: this._checkAlt.bind(this),
};
// ===== EVENT HANDLERS =====
@ -51,8 +51,8 @@ export default class Keyboard {
delete this._keyDownList[code];
}
Log.Debug("onkeyevent " + (down ? "down" : "up") +
", keysym: " + keysym, ", code: " + code);
Log.Debug('onkeyevent ' + (down ? 'down' : 'up')
+ ', keysym: ' + keysym, ', code: ' + code);
this.onkeyevent(keysym, code, down);
}
@ -102,8 +102,8 @@ export default class Keyboard {
this._altGrArmed = false;
clearTimeout(this._altGrTimeout);
if ((code === "AltRight") &&
((e.timeStamp - this._altGrCtrlTime) < 50)) {
if ((code === 'AltRight')
&& ((e.timeStamp - this._altGrCtrlTime) < 50)) {
// FIXME: We fail to detect this if either Ctrl key is
// first manually pressed as Windows then no
// longer sends the fake Ctrl down event. It
@ -113,7 +113,7 @@ export default class Keyboard {
// key to "AltGraph".
keysym = KeyTable.XK_ISO_Level3_Shift;
} else {
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
this._sendKeyEvent(KeyTable.XK_Control_L, 'ControlLeft', true);
}
}
@ -189,8 +189,8 @@ export default class Keyboard {
stopEvent(e);
// Possible start of AltGr sequence? (see above)
if ((code === "ControlLeft") && browser.isWindows() &&
!("ControlLeft" in this._keyDownList)) {
if ((code === 'ControlLeft') && browser.isWindows()
&& !('ControlLeft' in this._keyDownList)) {
this._altGrArmed = true;
this._altGrTimeout = setTimeout(this._handleAltGrTimeout.bind(this), 100);
this._altGrCtrlTime = e.timeStamp;
@ -249,10 +249,8 @@ export default class Keyboard {
// Character (A-Z)
let char = String.fromCharCode(e.keyCode);
// A feeble attempt at the correct case
if (e.shiftKey)
char = char.toUpperCase();
else
char = char.toLowerCase();
if (e.shiftKey) char = char.toUpperCase();
else char = char.toLowerCase();
keysym = char.charCodeAt();
} else {
// Unknown, give up
@ -272,7 +270,7 @@ export default class Keyboard {
if (this._altGrArmed) {
this._altGrArmed = false;
clearTimeout(this._altGrTimeout);
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
this._sendKeyEvent(KeyTable.XK_Control_L, 'ControlLeft', true);
}
// See comment in _handleKeyDown()
@ -288,15 +286,15 @@ export default class Keyboard {
_handleAltGrTimeout() {
this._altGrArmed = false;
clearTimeout(this._altGrTimeout);
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
this._sendKeyEvent(KeyTable.XK_Control_L, 'ControlLeft', true);
}
_allKeysUp() {
Log.Debug(">> Keyboard.allKeysUp");
Log.Debug('>> Keyboard.allKeysUp');
for (let code in this._keyDownList) {
this._sendKeyEvent(this._keyDownList[code], code, false);
}
Log.Debug("<< Keyboard.allKeysUp");
Log.Debug('<< Keyboard.allKeysUp');
}
// Firefox Alt workaround, see below
@ -313,8 +311,10 @@ export default class Keyboard {
}
const event = new KeyboardEvent('keyup',
{ key: downList[code],
code: code });
{
key: downList[code],
code: code
});
target.dispatchEvent(event);
});
}
@ -322,7 +322,7 @@ export default class Keyboard {
// ===== PUBLIC METHODS =====
grab() {
//Log.Debug(">> Keyboard.grab");
// Log.Debug(">> Keyboard.grab");
this._target.addEventListener('keydown', this._eventHandlers.keydown);
this._target.addEventListener('keyup', this._eventHandlers.keyup);
@ -338,17 +338,18 @@ export default class Keyboard {
const handler = this._eventHandlers.checkalt;
['mousedown', 'mouseup', 'mousemove', 'wheel',
'touchstart', 'touchend', 'touchmove',
'keydown', 'keyup'].forEach(type =>
document.addEventListener(type, handler,
{ capture: true,
passive: true }));
'keydown', 'keyup'].forEach(type => document.addEventListener(type, handler,
{
capture: true,
passive: true
}));
}
//Log.Debug("<< Keyboard.grab");
// Log.Debug("<< Keyboard.grab");
}
ungrab() {
//Log.Debug(">> Keyboard.ungrab");
// Log.Debug(">> Keyboard.ungrab");
if (browser.isWindows() && browser.isFirefox()) {
const handler = this._eventHandlers.checkalt;
@ -365,6 +366,6 @@ export default class Keyboard {
// Release (key up) all keys that are in a down state
this._allKeysUp();
//Log.Debug(">> Keyboard.ungrab");
// Log.Debug(">> Keyboard.ungrab");
}
}

View File

@ -27,11 +27,11 @@ export default class Mouse {
this._accumulatedWheelDeltaY = 0;
this._eventHandlers = {
'mousedown': this._handleMouseDown.bind(this),
'mouseup': this._handleMouseUp.bind(this),
'mousemove': this._handleMouseMove.bind(this),
'mousewheel': this._handleMouseWheel.bind(this),
'mousedisable': this._handleMouseDisable.bind(this)
mousedown: this._handleMouseDown.bind(this),
mouseup: this._handleMouseUp.bind(this),
mousemove: this._handleMouseMove.bind(this),
mousewheel: this._handleMouseWheel.bind(this),
mousedisable: this._handleMouseDisable.bind(this)
};
// ===== PROPERTIES =====
@ -90,13 +90,13 @@ export default class Mouse {
bmask = 1 << e.button;
} else {
/* IE including 9 */
bmask = (e.button & 0x1) + // Left
(e.button & 0x2) * 2 + // Right
(e.button & 0x4) / 2; // Middle
bmask = (e.button & 0x1) // Left
+ (e.button & 0x2) * 2 // Right
+ (e.button & 0x4) / 2; // Middle
}
Log.Debug("onmousebutton " + (down ? "down" : "up") +
", x: " + pos.x + ", y: " + pos.y + ", bmask: " + bmask);
Log.Debug('onmousebutton ' + (down ? 'down' : 'up')
+ ', x: ' + pos.x + ', y: ' + pos.y + ', bmask: ' + bmask);
this.onmousebutton(pos.x, pos.y, down, bmask);
stopEvent(e);
@ -104,7 +104,7 @@ export default class Mouse {
_handleMouseDown(e) {
// Touch events have implicit capture
if (e.type === "mousedown") {
if (e.type === 'mousedown') {
setCapture(this._target);
}
@ -119,7 +119,6 @@ export default class Mouse {
// protocol can't handle a wheel event with specific distance or speed.
// Therefor, if we get a lot of small mouse wheel events we combine them.
_generateWheelStepX() {
if (this._accumulatedWheelDeltaX < 0) {
this.onmousebutton(this._pos.x, this._pos.y, 1, 1 << 5);
this.onmousebutton(this._pos.x, this._pos.y, 0, 1 << 5);
@ -132,7 +131,6 @@ export default class Mouse {
}
_generateWheelStepY() {
if (this._accumulatedWheelDeltaY < 0) {
this.onmousebutton(this._pos.x, this._pos.y, 1, 1 << 3);
this.onmousebutton(this._pos.x, this._pos.y, 0, 1 << 3);
@ -179,15 +177,13 @@ export default class Mouse {
if (Math.abs(this._accumulatedWheelDeltaX) > WHEEL_STEP) {
this._generateWheelStepX();
} else {
this._wheelStepXTimer =
window.setTimeout(this._generateWheelStepX.bind(this),
this._wheelStepXTimer = window.setTimeout(this._generateWheelStepX.bind(this),
WHEEL_STEP_TIMEOUT);
}
if (Math.abs(this._accumulatedWheelDeltaY) > WHEEL_STEP) {
this._generateWheelStepY();
} else {
this._wheelStepYTimer =
window.setTimeout(this._generateWheelStepY.bind(this),
this._wheelStepYTimer = window.setTimeout(this._generateWheelStepY.bind(this),
WHEEL_STEP_TIMEOUT);
}
@ -233,7 +229,7 @@ export default class Mouse {
} else {
y = e.clientY - bounds.top;
}
this._pos = {x:x, y:y};
this._pos = { x: x, y: y };
}
// ===== PUBLIC METHODS =====

View File

@ -1,11 +1,11 @@
import keysyms from "./keysymdef.js";
import vkeys from "./vkeys.js";
import fixedkeys from "./fixedkeys.js";
import DOMKeyTable from "./domkeytable.js";
import * as browser from "../util/browser.js";
import keysyms from './keysymdef.js';
import vkeys from './vkeys.js';
import fixedkeys from './fixedkeys.js';
import DOMKeyTable from './domkeytable.js';
import * as browser from '../util/browser.js';
// Get 'KeyboardEvent.code', handling legacy browsers
export function getKeycode(evt){
export function getKeycode(evt) {
// Are we getting proper key identifiers?
// (unfortunately Firefox and Chrome are crappy here and gives
// us an empty string on some platforms, rather than leaving it
@ -125,7 +125,7 @@ export function getKey(evt) {
}
// Get the most reliable keysym value we can get from a key event
export function getKeysym(evt){
export function getKeysym(evt) {
const key = getKey(evt);
if (key === 'Unidentified') {

View File

@ -5,167 +5,167 @@
* keymap-gen --lang=js code-map keymaps.csv html atset1
*/
export default {
"Again": 0xe005, /* html:Again (Again) -> linux:129 (KEY_AGAIN) -> atset1:57349 */
"AltLeft": 0x38, /* html:AltLeft (AltLeft) -> linux:56 (KEY_LEFTALT) -> atset1:56 */
"AltRight": 0xe038, /* html:AltRight (AltRight) -> linux:100 (KEY_RIGHTALT) -> atset1:57400 */
"ArrowDown": 0xe050, /* html:ArrowDown (ArrowDown) -> linux:108 (KEY_DOWN) -> atset1:57424 */
"ArrowLeft": 0xe04b, /* html:ArrowLeft (ArrowLeft) -> linux:105 (KEY_LEFT) -> atset1:57419 */
"ArrowRight": 0xe04d, /* html:ArrowRight (ArrowRight) -> linux:106 (KEY_RIGHT) -> atset1:57421 */
"ArrowUp": 0xe048, /* html:ArrowUp (ArrowUp) -> linux:103 (KEY_UP) -> atset1:57416 */
"AudioVolumeDown": 0xe02e, /* html:AudioVolumeDown (AudioVolumeDown) -> linux:114 (KEY_VOLUMEDOWN) -> atset1:57390 */
"AudioVolumeMute": 0xe020, /* html:AudioVolumeMute (AudioVolumeMute) -> linux:113 (KEY_MUTE) -> atset1:57376 */
"AudioVolumeUp": 0xe030, /* html:AudioVolumeUp (AudioVolumeUp) -> linux:115 (KEY_VOLUMEUP) -> atset1:57392 */
"Backquote": 0x29, /* html:Backquote (Backquote) -> linux:41 (KEY_GRAVE) -> atset1:41 */
"Backslash": 0x2b, /* html:Backslash (Backslash) -> linux:43 (KEY_BACKSLASH) -> atset1:43 */
"Backspace": 0xe, /* html:Backspace (Backspace) -> linux:14 (KEY_BACKSPACE) -> atset1:14 */
"BracketLeft": 0x1a, /* html:BracketLeft (BracketLeft) -> linux:26 (KEY_LEFTBRACE) -> atset1:26 */
"BracketRight": 0x1b, /* html:BracketRight (BracketRight) -> linux:27 (KEY_RIGHTBRACE) -> atset1:27 */
"BrowserBack": 0xe06a, /* html:BrowserBack (BrowserBack) -> linux:158 (KEY_BACK) -> atset1:57450 */
"BrowserFavorites": 0xe066, /* html:BrowserFavorites (BrowserFavorites) -> linux:156 (KEY_BOOKMARKS) -> atset1:57446 */
"BrowserForward": 0xe069, /* html:BrowserForward (BrowserForward) -> linux:159 (KEY_FORWARD) -> atset1:57449 */
"BrowserHome": 0xe032, /* html:BrowserHome (BrowserHome) -> linux:172 (KEY_HOMEPAGE) -> atset1:57394 */
"BrowserRefresh": 0xe067, /* html:BrowserRefresh (BrowserRefresh) -> linux:173 (KEY_REFRESH) -> atset1:57447 */
"BrowserSearch": 0xe065, /* html:BrowserSearch (BrowserSearch) -> linux:217 (KEY_SEARCH) -> atset1:57445 */
"BrowserStop": 0xe068, /* html:BrowserStop (BrowserStop) -> linux:128 (KEY_STOP) -> atset1:57448 */
"CapsLock": 0x3a, /* html:CapsLock (CapsLock) -> linux:58 (KEY_CAPSLOCK) -> atset1:58 */
"Comma": 0x33, /* html:Comma (Comma) -> linux:51 (KEY_COMMA) -> atset1:51 */
"ContextMenu": 0xe05d, /* html:ContextMenu (ContextMenu) -> linux:127 (KEY_COMPOSE) -> atset1:57437 */
"ControlLeft": 0x1d, /* html:ControlLeft (ControlLeft) -> linux:29 (KEY_LEFTCTRL) -> atset1:29 */
"ControlRight": 0xe01d, /* html:ControlRight (ControlRight) -> linux:97 (KEY_RIGHTCTRL) -> atset1:57373 */
"Convert": 0x79, /* html:Convert (Convert) -> linux:92 (KEY_HENKAN) -> atset1:121 */
"Copy": 0xe078, /* html:Copy (Copy) -> linux:133 (KEY_COPY) -> atset1:57464 */
"Cut": 0xe03c, /* html:Cut (Cut) -> linux:137 (KEY_CUT) -> atset1:57404 */
"Delete": 0xe053, /* html:Delete (Delete) -> linux:111 (KEY_DELETE) -> atset1:57427 */
"Digit0": 0xb, /* html:Digit0 (Digit0) -> linux:11 (KEY_0) -> atset1:11 */
"Digit1": 0x2, /* html:Digit1 (Digit1) -> linux:2 (KEY_1) -> atset1:2 */
"Digit2": 0x3, /* html:Digit2 (Digit2) -> linux:3 (KEY_2) -> atset1:3 */
"Digit3": 0x4, /* html:Digit3 (Digit3) -> linux:4 (KEY_3) -> atset1:4 */
"Digit4": 0x5, /* html:Digit4 (Digit4) -> linux:5 (KEY_4) -> atset1:5 */
"Digit5": 0x6, /* html:Digit5 (Digit5) -> linux:6 (KEY_5) -> atset1:6 */
"Digit6": 0x7, /* html:Digit6 (Digit6) -> linux:7 (KEY_6) -> atset1:7 */
"Digit7": 0x8, /* html:Digit7 (Digit7) -> linux:8 (KEY_7) -> atset1:8 */
"Digit8": 0x9, /* html:Digit8 (Digit8) -> linux:9 (KEY_8) -> atset1:9 */
"Digit9": 0xa, /* html:Digit9 (Digit9) -> linux:10 (KEY_9) -> atset1:10 */
"Eject": 0xe07d, /* html:Eject (Eject) -> linux:162 (KEY_EJECTCLOSECD) -> atset1:57469 */
"End": 0xe04f, /* html:End (End) -> linux:107 (KEY_END) -> atset1:57423 */
"Enter": 0x1c, /* html:Enter (Enter) -> linux:28 (KEY_ENTER) -> atset1:28 */
"Equal": 0xd, /* html:Equal (Equal) -> linux:13 (KEY_EQUAL) -> atset1:13 */
"Escape": 0x1, /* html:Escape (Escape) -> linux:1 (KEY_ESC) -> atset1:1 */
"F1": 0x3b, /* html:F1 (F1) -> linux:59 (KEY_F1) -> atset1:59 */
"F10": 0x44, /* html:F10 (F10) -> linux:68 (KEY_F10) -> atset1:68 */
"F11": 0x57, /* html:F11 (F11) -> linux:87 (KEY_F11) -> atset1:87 */
"F12": 0x58, /* html:F12 (F12) -> linux:88 (KEY_F12) -> atset1:88 */
"F13": 0x5d, /* html:F13 (F13) -> linux:183 (KEY_F13) -> atset1:93 */
"F14": 0x5e, /* html:F14 (F14) -> linux:184 (KEY_F14) -> atset1:94 */
"F15": 0x5f, /* html:F15 (F15) -> linux:185 (KEY_F15) -> atset1:95 */
"F16": 0x55, /* html:F16 (F16) -> linux:186 (KEY_F16) -> atset1:85 */
"F17": 0xe003, /* html:F17 (F17) -> linux:187 (KEY_F17) -> atset1:57347 */
"F18": 0xe077, /* html:F18 (F18) -> linux:188 (KEY_F18) -> atset1:57463 */
"F19": 0xe004, /* html:F19 (F19) -> linux:189 (KEY_F19) -> atset1:57348 */
"F2": 0x3c, /* html:F2 (F2) -> linux:60 (KEY_F2) -> atset1:60 */
"F20": 0x5a, /* html:F20 (F20) -> linux:190 (KEY_F20) -> atset1:90 */
"F21": 0x74, /* html:F21 (F21) -> linux:191 (KEY_F21) -> atset1:116 */
"F22": 0xe079, /* html:F22 (F22) -> linux:192 (KEY_F22) -> atset1:57465 */
"F23": 0x6d, /* html:F23 (F23) -> linux:193 (KEY_F23) -> atset1:109 */
"F24": 0x6f, /* html:F24 (F24) -> linux:194 (KEY_F24) -> atset1:111 */
"F3": 0x3d, /* html:F3 (F3) -> linux:61 (KEY_F3) -> atset1:61 */
"F4": 0x3e, /* html:F4 (F4) -> linux:62 (KEY_F4) -> atset1:62 */
"F5": 0x3f, /* html:F5 (F5) -> linux:63 (KEY_F5) -> atset1:63 */
"F6": 0x40, /* html:F6 (F6) -> linux:64 (KEY_F6) -> atset1:64 */
"F7": 0x41, /* html:F7 (F7) -> linux:65 (KEY_F7) -> atset1:65 */
"F8": 0x42, /* html:F8 (F8) -> linux:66 (KEY_F8) -> atset1:66 */
"F9": 0x43, /* html:F9 (F9) -> linux:67 (KEY_F9) -> atset1:67 */
"Find": 0xe041, /* html:Find (Find) -> linux:136 (KEY_FIND) -> atset1:57409 */
"Help": 0xe075, /* html:Help (Help) -> linux:138 (KEY_HELP) -> atset1:57461 */
"Hiragana": 0x77, /* html:Hiragana (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
"Home": 0xe047, /* html:Home (Home) -> linux:102 (KEY_HOME) -> atset1:57415 */
"Insert": 0xe052, /* html:Insert (Insert) -> linux:110 (KEY_INSERT) -> atset1:57426 */
"IntlBackslash": 0x56, /* html:IntlBackslash (IntlBackslash) -> linux:86 (KEY_102ND) -> atset1:86 */
"IntlRo": 0x73, /* html:IntlRo (IntlRo) -> linux:89 (KEY_RO) -> atset1:115 */
"IntlYen": 0x7d, /* html:IntlYen (IntlYen) -> linux:124 (KEY_YEN) -> atset1:125 */
"KanaMode": 0x70, /* html:KanaMode (KanaMode) -> linux:93 (KEY_KATAKANAHIRAGANA) -> atset1:112 */
"Katakana": 0x78, /* html:Katakana (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
"KeyA": 0x1e, /* html:KeyA (KeyA) -> linux:30 (KEY_A) -> atset1:30 */
"KeyB": 0x30, /* html:KeyB (KeyB) -> linux:48 (KEY_B) -> atset1:48 */
"KeyC": 0x2e, /* html:KeyC (KeyC) -> linux:46 (KEY_C) -> atset1:46 */
"KeyD": 0x20, /* html:KeyD (KeyD) -> linux:32 (KEY_D) -> atset1:32 */
"KeyE": 0x12, /* html:KeyE (KeyE) -> linux:18 (KEY_E) -> atset1:18 */
"KeyF": 0x21, /* html:KeyF (KeyF) -> linux:33 (KEY_F) -> atset1:33 */
"KeyG": 0x22, /* html:KeyG (KeyG) -> linux:34 (KEY_G) -> atset1:34 */
"KeyH": 0x23, /* html:KeyH (KeyH) -> linux:35 (KEY_H) -> atset1:35 */
"KeyI": 0x17, /* html:KeyI (KeyI) -> linux:23 (KEY_I) -> atset1:23 */
"KeyJ": 0x24, /* html:KeyJ (KeyJ) -> linux:36 (KEY_J) -> atset1:36 */
"KeyK": 0x25, /* html:KeyK (KeyK) -> linux:37 (KEY_K) -> atset1:37 */
"KeyL": 0x26, /* html:KeyL (KeyL) -> linux:38 (KEY_L) -> atset1:38 */
"KeyM": 0x32, /* html:KeyM (KeyM) -> linux:50 (KEY_M) -> atset1:50 */
"KeyN": 0x31, /* html:KeyN (KeyN) -> linux:49 (KEY_N) -> atset1:49 */
"KeyO": 0x18, /* html:KeyO (KeyO) -> linux:24 (KEY_O) -> atset1:24 */
"KeyP": 0x19, /* html:KeyP (KeyP) -> linux:25 (KEY_P) -> atset1:25 */
"KeyQ": 0x10, /* html:KeyQ (KeyQ) -> linux:16 (KEY_Q) -> atset1:16 */
"KeyR": 0x13, /* html:KeyR (KeyR) -> linux:19 (KEY_R) -> atset1:19 */
"KeyS": 0x1f, /* html:KeyS (KeyS) -> linux:31 (KEY_S) -> atset1:31 */
"KeyT": 0x14, /* html:KeyT (KeyT) -> linux:20 (KEY_T) -> atset1:20 */
"KeyU": 0x16, /* html:KeyU (KeyU) -> linux:22 (KEY_U) -> atset1:22 */
"KeyV": 0x2f, /* html:KeyV (KeyV) -> linux:47 (KEY_V) -> atset1:47 */
"KeyW": 0x11, /* html:KeyW (KeyW) -> linux:17 (KEY_W) -> atset1:17 */
"KeyX": 0x2d, /* html:KeyX (KeyX) -> linux:45 (KEY_X) -> atset1:45 */
"KeyY": 0x15, /* html:KeyY (KeyY) -> linux:21 (KEY_Y) -> atset1:21 */
"KeyZ": 0x2c, /* html:KeyZ (KeyZ) -> linux:44 (KEY_Z) -> atset1:44 */
"Lang3": 0x78, /* html:Lang3 (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
"Lang4": 0x77, /* html:Lang4 (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
"Lang5": 0x76, /* html:Lang5 (Lang5) -> linux:85 (KEY_ZENKAKUHANKAKU) -> atset1:118 */
"LaunchApp1": 0xe06b, /* html:LaunchApp1 (LaunchApp1) -> linux:157 (KEY_COMPUTER) -> atset1:57451 */
"LaunchApp2": 0xe021, /* html:LaunchApp2 (LaunchApp2) -> linux:140 (KEY_CALC) -> atset1:57377 */
"LaunchMail": 0xe06c, /* html:LaunchMail (LaunchMail) -> linux:155 (KEY_MAIL) -> atset1:57452 */
"MediaPlayPause": 0xe022, /* html:MediaPlayPause (MediaPlayPause) -> linux:164 (KEY_PLAYPAUSE) -> atset1:57378 */
"MediaSelect": 0xe06d, /* html:MediaSelect (MediaSelect) -> linux:226 (KEY_MEDIA) -> atset1:57453 */
"MediaStop": 0xe024, /* html:MediaStop (MediaStop) -> linux:166 (KEY_STOPCD) -> atset1:57380 */
"MediaTrackNext": 0xe019, /* html:MediaTrackNext (MediaTrackNext) -> linux:163 (KEY_NEXTSONG) -> atset1:57369 */
"MediaTrackPrevious": 0xe010, /* html:MediaTrackPrevious (MediaTrackPrevious) -> linux:165 (KEY_PREVIOUSSONG) -> atset1:57360 */
"MetaLeft": 0xe05b, /* html:MetaLeft (MetaLeft) -> linux:125 (KEY_LEFTMETA) -> atset1:57435 */
"MetaRight": 0xe05c, /* html:MetaRight (MetaRight) -> linux:126 (KEY_RIGHTMETA) -> atset1:57436 */
"Minus": 0xc, /* html:Minus (Minus) -> linux:12 (KEY_MINUS) -> atset1:12 */
"NonConvert": 0x7b, /* html:NonConvert (NonConvert) -> linux:94 (KEY_MUHENKAN) -> atset1:123 */
"NumLock": 0x45, /* html:NumLock (NumLock) -> linux:69 (KEY_NUMLOCK) -> atset1:69 */
"Numpad0": 0x52, /* html:Numpad0 (Numpad0) -> linux:82 (KEY_KP0) -> atset1:82 */
"Numpad1": 0x4f, /* html:Numpad1 (Numpad1) -> linux:79 (KEY_KP1) -> atset1:79 */
"Numpad2": 0x50, /* html:Numpad2 (Numpad2) -> linux:80 (KEY_KP2) -> atset1:80 */
"Numpad3": 0x51, /* html:Numpad3 (Numpad3) -> linux:81 (KEY_KP3) -> atset1:81 */
"Numpad4": 0x4b, /* html:Numpad4 (Numpad4) -> linux:75 (KEY_KP4) -> atset1:75 */
"Numpad5": 0x4c, /* html:Numpad5 (Numpad5) -> linux:76 (KEY_KP5) -> atset1:76 */
"Numpad6": 0x4d, /* html:Numpad6 (Numpad6) -> linux:77 (KEY_KP6) -> atset1:77 */
"Numpad7": 0x47, /* html:Numpad7 (Numpad7) -> linux:71 (KEY_KP7) -> atset1:71 */
"Numpad8": 0x48, /* html:Numpad8 (Numpad8) -> linux:72 (KEY_KP8) -> atset1:72 */
"Numpad9": 0x49, /* html:Numpad9 (Numpad9) -> linux:73 (KEY_KP9) -> atset1:73 */
"NumpadAdd": 0x4e, /* html:NumpadAdd (NumpadAdd) -> linux:78 (KEY_KPPLUS) -> atset1:78 */
"NumpadComma": 0x7e, /* html:NumpadComma (NumpadComma) -> linux:121 (KEY_KPCOMMA) -> atset1:126 */
"NumpadDecimal": 0x53, /* html:NumpadDecimal (NumpadDecimal) -> linux:83 (KEY_KPDOT) -> atset1:83 */
"NumpadDivide": 0xe035, /* html:NumpadDivide (NumpadDivide) -> linux:98 (KEY_KPSLASH) -> atset1:57397 */
"NumpadEnter": 0xe01c, /* html:NumpadEnter (NumpadEnter) -> linux:96 (KEY_KPENTER) -> atset1:57372 */
"NumpadEqual": 0x59, /* html:NumpadEqual (NumpadEqual) -> linux:117 (KEY_KPEQUAL) -> atset1:89 */
"NumpadMultiply": 0x37, /* html:NumpadMultiply (NumpadMultiply) -> linux:55 (KEY_KPASTERISK) -> atset1:55 */
"NumpadParenLeft": 0xe076, /* html:NumpadParenLeft (NumpadParenLeft) -> linux:179 (KEY_KPLEFTPAREN) -> atset1:57462 */
"NumpadParenRight": 0xe07b, /* html:NumpadParenRight (NumpadParenRight) -> linux:180 (KEY_KPRIGHTPAREN) -> atset1:57467 */
"NumpadSubtract": 0x4a, /* html:NumpadSubtract (NumpadSubtract) -> linux:74 (KEY_KPMINUS) -> atset1:74 */
"Open": 0x64, /* html:Open (Open) -> linux:134 (KEY_OPEN) -> atset1:100 */
"PageDown": 0xe051, /* html:PageDown (PageDown) -> linux:109 (KEY_PAGEDOWN) -> atset1:57425 */
"PageUp": 0xe049, /* html:PageUp (PageUp) -> linux:104 (KEY_PAGEUP) -> atset1:57417 */
"Paste": 0x65, /* html:Paste (Paste) -> linux:135 (KEY_PASTE) -> atset1:101 */
"Pause": 0xe046, /* html:Pause (Pause) -> linux:119 (KEY_PAUSE) -> atset1:57414 */
"Period": 0x34, /* html:Period (Period) -> linux:52 (KEY_DOT) -> atset1:52 */
"Power": 0xe05e, /* html:Power (Power) -> linux:116 (KEY_POWER) -> atset1:57438 */
"PrintScreen": 0x54, /* html:PrintScreen (PrintScreen) -> linux:99 (KEY_SYSRQ) -> atset1:84 */
"Props": 0xe006, /* html:Props (Props) -> linux:130 (KEY_PROPS) -> atset1:57350 */
"Quote": 0x28, /* html:Quote (Quote) -> linux:40 (KEY_APOSTROPHE) -> atset1:40 */
"ScrollLock": 0x46, /* html:ScrollLock (ScrollLock) -> linux:70 (KEY_SCROLLLOCK) -> atset1:70 */
"Semicolon": 0x27, /* html:Semicolon (Semicolon) -> linux:39 (KEY_SEMICOLON) -> atset1:39 */
"ShiftLeft": 0x2a, /* html:ShiftLeft (ShiftLeft) -> linux:42 (KEY_LEFTSHIFT) -> atset1:42 */
"ShiftRight": 0x36, /* html:ShiftRight (ShiftRight) -> linux:54 (KEY_RIGHTSHIFT) -> atset1:54 */
"Slash": 0x35, /* html:Slash (Slash) -> linux:53 (KEY_SLASH) -> atset1:53 */
"Sleep": 0xe05f, /* html:Sleep (Sleep) -> linux:142 (KEY_SLEEP) -> atset1:57439 */
"Space": 0x39, /* html:Space (Space) -> linux:57 (KEY_SPACE) -> atset1:57 */
"Suspend": 0xe025, /* html:Suspend (Suspend) -> linux:205 (KEY_SUSPEND) -> atset1:57381 */
"Tab": 0xf, /* html:Tab (Tab) -> linux:15 (KEY_TAB) -> atset1:15 */
"Undo": 0xe007, /* html:Undo (Undo) -> linux:131 (KEY_UNDO) -> atset1:57351 */
"WakeUp": 0xe063, /* html:WakeUp (WakeUp) -> linux:143 (KEY_WAKEUP) -> atset1:57443 */
Again: 0xe005, /* html:Again (Again) -> linux:129 (KEY_AGAIN) -> atset1:57349 */
AltLeft: 0x38, /* html:AltLeft (AltLeft) -> linux:56 (KEY_LEFTALT) -> atset1:56 */
AltRight: 0xe038, /* html:AltRight (AltRight) -> linux:100 (KEY_RIGHTALT) -> atset1:57400 */
ArrowDown: 0xe050, /* html:ArrowDown (ArrowDown) -> linux:108 (KEY_DOWN) -> atset1:57424 */
ArrowLeft: 0xe04b, /* html:ArrowLeft (ArrowLeft) -> linux:105 (KEY_LEFT) -> atset1:57419 */
ArrowRight: 0xe04d, /* html:ArrowRight (ArrowRight) -> linux:106 (KEY_RIGHT) -> atset1:57421 */
ArrowUp: 0xe048, /* html:ArrowUp (ArrowUp) -> linux:103 (KEY_UP) -> atset1:57416 */
AudioVolumeDown: 0xe02e, /* html:AudioVolumeDown (AudioVolumeDown) -> linux:114 (KEY_VOLUMEDOWN) -> atset1:57390 */
AudioVolumeMute: 0xe020, /* html:AudioVolumeMute (AudioVolumeMute) -> linux:113 (KEY_MUTE) -> atset1:57376 */
AudioVolumeUp: 0xe030, /* html:AudioVolumeUp (AudioVolumeUp) -> linux:115 (KEY_VOLUMEUP) -> atset1:57392 */
Backquote: 0x29, /* html:Backquote (Backquote) -> linux:41 (KEY_GRAVE) -> atset1:41 */
Backslash: 0x2b, /* html:Backslash (Backslash) -> linux:43 (KEY_BACKSLASH) -> atset1:43 */
Backspace: 0xe, /* html:Backspace (Backspace) -> linux:14 (KEY_BACKSPACE) -> atset1:14 */
BracketLeft: 0x1a, /* html:BracketLeft (BracketLeft) -> linux:26 (KEY_LEFTBRACE) -> atset1:26 */
BracketRight: 0x1b, /* html:BracketRight (BracketRight) -> linux:27 (KEY_RIGHTBRACE) -> atset1:27 */
BrowserBack: 0xe06a, /* html:BrowserBack (BrowserBack) -> linux:158 (KEY_BACK) -> atset1:57450 */
BrowserFavorites: 0xe066, /* html:BrowserFavorites (BrowserFavorites) -> linux:156 (KEY_BOOKMARKS) -> atset1:57446 */
BrowserForward: 0xe069, /* html:BrowserForward (BrowserForward) -> linux:159 (KEY_FORWARD) -> atset1:57449 */
BrowserHome: 0xe032, /* html:BrowserHome (BrowserHome) -> linux:172 (KEY_HOMEPAGE) -> atset1:57394 */
BrowserRefresh: 0xe067, /* html:BrowserRefresh (BrowserRefresh) -> linux:173 (KEY_REFRESH) -> atset1:57447 */
BrowserSearch: 0xe065, /* html:BrowserSearch (BrowserSearch) -> linux:217 (KEY_SEARCH) -> atset1:57445 */
BrowserStop: 0xe068, /* html:BrowserStop (BrowserStop) -> linux:128 (KEY_STOP) -> atset1:57448 */
CapsLock: 0x3a, /* html:CapsLock (CapsLock) -> linux:58 (KEY_CAPSLOCK) -> atset1:58 */
Comma: 0x33, /* html:Comma (Comma) -> linux:51 (KEY_COMMA) -> atset1:51 */
ContextMenu: 0xe05d, /* html:ContextMenu (ContextMenu) -> linux:127 (KEY_COMPOSE) -> atset1:57437 */
ControlLeft: 0x1d, /* html:ControlLeft (ControlLeft) -> linux:29 (KEY_LEFTCTRL) -> atset1:29 */
ControlRight: 0xe01d, /* html:ControlRight (ControlRight) -> linux:97 (KEY_RIGHTCTRL) -> atset1:57373 */
Convert: 0x79, /* html:Convert (Convert) -> linux:92 (KEY_HENKAN) -> atset1:121 */
Copy: 0xe078, /* html:Copy (Copy) -> linux:133 (KEY_COPY) -> atset1:57464 */
Cut: 0xe03c, /* html:Cut (Cut) -> linux:137 (KEY_CUT) -> atset1:57404 */
Delete: 0xe053, /* html:Delete (Delete) -> linux:111 (KEY_DELETE) -> atset1:57427 */
Digit0: 0xb, /* html:Digit0 (Digit0) -> linux:11 (KEY_0) -> atset1:11 */
Digit1: 0x2, /* html:Digit1 (Digit1) -> linux:2 (KEY_1) -> atset1:2 */
Digit2: 0x3, /* html:Digit2 (Digit2) -> linux:3 (KEY_2) -> atset1:3 */
Digit3: 0x4, /* html:Digit3 (Digit3) -> linux:4 (KEY_3) -> atset1:4 */
Digit4: 0x5, /* html:Digit4 (Digit4) -> linux:5 (KEY_4) -> atset1:5 */
Digit5: 0x6, /* html:Digit5 (Digit5) -> linux:6 (KEY_5) -> atset1:6 */
Digit6: 0x7, /* html:Digit6 (Digit6) -> linux:7 (KEY_6) -> atset1:7 */
Digit7: 0x8, /* html:Digit7 (Digit7) -> linux:8 (KEY_7) -> atset1:8 */
Digit8: 0x9, /* html:Digit8 (Digit8) -> linux:9 (KEY_8) -> atset1:9 */
Digit9: 0xa, /* html:Digit9 (Digit9) -> linux:10 (KEY_9) -> atset1:10 */
Eject: 0xe07d, /* html:Eject (Eject) -> linux:162 (KEY_EJECTCLOSECD) -> atset1:57469 */
End: 0xe04f, /* html:End (End) -> linux:107 (KEY_END) -> atset1:57423 */
Enter: 0x1c, /* html:Enter (Enter) -> linux:28 (KEY_ENTER) -> atset1:28 */
Equal: 0xd, /* html:Equal (Equal) -> linux:13 (KEY_EQUAL) -> atset1:13 */
Escape: 0x1, /* html:Escape (Escape) -> linux:1 (KEY_ESC) -> atset1:1 */
F1: 0x3b, /* html:F1 (F1) -> linux:59 (KEY_F1) -> atset1:59 */
F10: 0x44, /* html:F10 (F10) -> linux:68 (KEY_F10) -> atset1:68 */
F11: 0x57, /* html:F11 (F11) -> linux:87 (KEY_F11) -> atset1:87 */
F12: 0x58, /* html:F12 (F12) -> linux:88 (KEY_F12) -> atset1:88 */
F13: 0x5d, /* html:F13 (F13) -> linux:183 (KEY_F13) -> atset1:93 */
F14: 0x5e, /* html:F14 (F14) -> linux:184 (KEY_F14) -> atset1:94 */
F15: 0x5f, /* html:F15 (F15) -> linux:185 (KEY_F15) -> atset1:95 */
F16: 0x55, /* html:F16 (F16) -> linux:186 (KEY_F16) -> atset1:85 */
F17: 0xe003, /* html:F17 (F17) -> linux:187 (KEY_F17) -> atset1:57347 */
F18: 0xe077, /* html:F18 (F18) -> linux:188 (KEY_F18) -> atset1:57463 */
F19: 0xe004, /* html:F19 (F19) -> linux:189 (KEY_F19) -> atset1:57348 */
F2: 0x3c, /* html:F2 (F2) -> linux:60 (KEY_F2) -> atset1:60 */
F20: 0x5a, /* html:F20 (F20) -> linux:190 (KEY_F20) -> atset1:90 */
F21: 0x74, /* html:F21 (F21) -> linux:191 (KEY_F21) -> atset1:116 */
F22: 0xe079, /* html:F22 (F22) -> linux:192 (KEY_F22) -> atset1:57465 */
F23: 0x6d, /* html:F23 (F23) -> linux:193 (KEY_F23) -> atset1:109 */
F24: 0x6f, /* html:F24 (F24) -> linux:194 (KEY_F24) -> atset1:111 */
F3: 0x3d, /* html:F3 (F3) -> linux:61 (KEY_F3) -> atset1:61 */
F4: 0x3e, /* html:F4 (F4) -> linux:62 (KEY_F4) -> atset1:62 */
F5: 0x3f, /* html:F5 (F5) -> linux:63 (KEY_F5) -> atset1:63 */
F6: 0x40, /* html:F6 (F6) -> linux:64 (KEY_F6) -> atset1:64 */
F7: 0x41, /* html:F7 (F7) -> linux:65 (KEY_F7) -> atset1:65 */
F8: 0x42, /* html:F8 (F8) -> linux:66 (KEY_F8) -> atset1:66 */
F9: 0x43, /* html:F9 (F9) -> linux:67 (KEY_F9) -> atset1:67 */
Find: 0xe041, /* html:Find (Find) -> linux:136 (KEY_FIND) -> atset1:57409 */
Help: 0xe075, /* html:Help (Help) -> linux:138 (KEY_HELP) -> atset1:57461 */
Hiragana: 0x77, /* html:Hiragana (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
Home: 0xe047, /* html:Home (Home) -> linux:102 (KEY_HOME) -> atset1:57415 */
Insert: 0xe052, /* html:Insert (Insert) -> linux:110 (KEY_INSERT) -> atset1:57426 */
IntlBackslash: 0x56, /* html:IntlBackslash (IntlBackslash) -> linux:86 (KEY_102ND) -> atset1:86 */
IntlRo: 0x73, /* html:IntlRo (IntlRo) -> linux:89 (KEY_RO) -> atset1:115 */
IntlYen: 0x7d, /* html:IntlYen (IntlYen) -> linux:124 (KEY_YEN) -> atset1:125 */
KanaMode: 0x70, /* html:KanaMode (KanaMode) -> linux:93 (KEY_KATAKANAHIRAGANA) -> atset1:112 */
Katakana: 0x78, /* html:Katakana (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
KeyA: 0x1e, /* html:KeyA (KeyA) -> linux:30 (KEY_A) -> atset1:30 */
KeyB: 0x30, /* html:KeyB (KeyB) -> linux:48 (KEY_B) -> atset1:48 */
KeyC: 0x2e, /* html:KeyC (KeyC) -> linux:46 (KEY_C) -> atset1:46 */
KeyD: 0x20, /* html:KeyD (KeyD) -> linux:32 (KEY_D) -> atset1:32 */
KeyE: 0x12, /* html:KeyE (KeyE) -> linux:18 (KEY_E) -> atset1:18 */
KeyF: 0x21, /* html:KeyF (KeyF) -> linux:33 (KEY_F) -> atset1:33 */
KeyG: 0x22, /* html:KeyG (KeyG) -> linux:34 (KEY_G) -> atset1:34 */
KeyH: 0x23, /* html:KeyH (KeyH) -> linux:35 (KEY_H) -> atset1:35 */
KeyI: 0x17, /* html:KeyI (KeyI) -> linux:23 (KEY_I) -> atset1:23 */
KeyJ: 0x24, /* html:KeyJ (KeyJ) -> linux:36 (KEY_J) -> atset1:36 */
KeyK: 0x25, /* html:KeyK (KeyK) -> linux:37 (KEY_K) -> atset1:37 */
KeyL: 0x26, /* html:KeyL (KeyL) -> linux:38 (KEY_L) -> atset1:38 */
KeyM: 0x32, /* html:KeyM (KeyM) -> linux:50 (KEY_M) -> atset1:50 */
KeyN: 0x31, /* html:KeyN (KeyN) -> linux:49 (KEY_N) -> atset1:49 */
KeyO: 0x18, /* html:KeyO (KeyO) -> linux:24 (KEY_O) -> atset1:24 */
KeyP: 0x19, /* html:KeyP (KeyP) -> linux:25 (KEY_P) -> atset1:25 */
KeyQ: 0x10, /* html:KeyQ (KeyQ) -> linux:16 (KEY_Q) -> atset1:16 */
KeyR: 0x13, /* html:KeyR (KeyR) -> linux:19 (KEY_R) -> atset1:19 */
KeyS: 0x1f, /* html:KeyS (KeyS) -> linux:31 (KEY_S) -> atset1:31 */
KeyT: 0x14, /* html:KeyT (KeyT) -> linux:20 (KEY_T) -> atset1:20 */
KeyU: 0x16, /* html:KeyU (KeyU) -> linux:22 (KEY_U) -> atset1:22 */
KeyV: 0x2f, /* html:KeyV (KeyV) -> linux:47 (KEY_V) -> atset1:47 */
KeyW: 0x11, /* html:KeyW (KeyW) -> linux:17 (KEY_W) -> atset1:17 */
KeyX: 0x2d, /* html:KeyX (KeyX) -> linux:45 (KEY_X) -> atset1:45 */
KeyY: 0x15, /* html:KeyY (KeyY) -> linux:21 (KEY_Y) -> atset1:21 */
KeyZ: 0x2c, /* html:KeyZ (KeyZ) -> linux:44 (KEY_Z) -> atset1:44 */
Lang3: 0x78, /* html:Lang3 (Lang3) -> linux:90 (KEY_KATAKANA) -> atset1:120 */
Lang4: 0x77, /* html:Lang4 (Lang4) -> linux:91 (KEY_HIRAGANA) -> atset1:119 */
Lang5: 0x76, /* html:Lang5 (Lang5) -> linux:85 (KEY_ZENKAKUHANKAKU) -> atset1:118 */
LaunchApp1: 0xe06b, /* html:LaunchApp1 (LaunchApp1) -> linux:157 (KEY_COMPUTER) -> atset1:57451 */
LaunchApp2: 0xe021, /* html:LaunchApp2 (LaunchApp2) -> linux:140 (KEY_CALC) -> atset1:57377 */
LaunchMail: 0xe06c, /* html:LaunchMail (LaunchMail) -> linux:155 (KEY_MAIL) -> atset1:57452 */
MediaPlayPause: 0xe022, /* html:MediaPlayPause (MediaPlayPause) -> linux:164 (KEY_PLAYPAUSE) -> atset1:57378 */
MediaSelect: 0xe06d, /* html:MediaSelect (MediaSelect) -> linux:226 (KEY_MEDIA) -> atset1:57453 */
MediaStop: 0xe024, /* html:MediaStop (MediaStop) -> linux:166 (KEY_STOPCD) -> atset1:57380 */
MediaTrackNext: 0xe019, /* html:MediaTrackNext (MediaTrackNext) -> linux:163 (KEY_NEXTSONG) -> atset1:57369 */
MediaTrackPrevious: 0xe010, /* html:MediaTrackPrevious (MediaTrackPrevious) -> linux:165 (KEY_PREVIOUSSONG) -> atset1:57360 */
MetaLeft: 0xe05b, /* html:MetaLeft (MetaLeft) -> linux:125 (KEY_LEFTMETA) -> atset1:57435 */
MetaRight: 0xe05c, /* html:MetaRight (MetaRight) -> linux:126 (KEY_RIGHTMETA) -> atset1:57436 */
Minus: 0xc, /* html:Minus (Minus) -> linux:12 (KEY_MINUS) -> atset1:12 */
NonConvert: 0x7b, /* html:NonConvert (NonConvert) -> linux:94 (KEY_MUHENKAN) -> atset1:123 */
NumLock: 0x45, /* html:NumLock (NumLock) -> linux:69 (KEY_NUMLOCK) -> atset1:69 */
Numpad0: 0x52, /* html:Numpad0 (Numpad0) -> linux:82 (KEY_KP0) -> atset1:82 */
Numpad1: 0x4f, /* html:Numpad1 (Numpad1) -> linux:79 (KEY_KP1) -> atset1:79 */
Numpad2: 0x50, /* html:Numpad2 (Numpad2) -> linux:80 (KEY_KP2) -> atset1:80 */
Numpad3: 0x51, /* html:Numpad3 (Numpad3) -> linux:81 (KEY_KP3) -> atset1:81 */
Numpad4: 0x4b, /* html:Numpad4 (Numpad4) -> linux:75 (KEY_KP4) -> atset1:75 */
Numpad5: 0x4c, /* html:Numpad5 (Numpad5) -> linux:76 (KEY_KP5) -> atset1:76 */
Numpad6: 0x4d, /* html:Numpad6 (Numpad6) -> linux:77 (KEY_KP6) -> atset1:77 */
Numpad7: 0x47, /* html:Numpad7 (Numpad7) -> linux:71 (KEY_KP7) -> atset1:71 */
Numpad8: 0x48, /* html:Numpad8 (Numpad8) -> linux:72 (KEY_KP8) -> atset1:72 */
Numpad9: 0x49, /* html:Numpad9 (Numpad9) -> linux:73 (KEY_KP9) -> atset1:73 */
NumpadAdd: 0x4e, /* html:NumpadAdd (NumpadAdd) -> linux:78 (KEY_KPPLUS) -> atset1:78 */
NumpadComma: 0x7e, /* html:NumpadComma (NumpadComma) -> linux:121 (KEY_KPCOMMA) -> atset1:126 */
NumpadDecimal: 0x53, /* html:NumpadDecimal (NumpadDecimal) -> linux:83 (KEY_KPDOT) -> atset1:83 */
NumpadDivide: 0xe035, /* html:NumpadDivide (NumpadDivide) -> linux:98 (KEY_KPSLASH) -> atset1:57397 */
NumpadEnter: 0xe01c, /* html:NumpadEnter (NumpadEnter) -> linux:96 (KEY_KPENTER) -> atset1:57372 */
NumpadEqual: 0x59, /* html:NumpadEqual (NumpadEqual) -> linux:117 (KEY_KPEQUAL) -> atset1:89 */
NumpadMultiply: 0x37, /* html:NumpadMultiply (NumpadMultiply) -> linux:55 (KEY_KPASTERISK) -> atset1:55 */
NumpadParenLeft: 0xe076, /* html:NumpadParenLeft (NumpadParenLeft) -> linux:179 (KEY_KPLEFTPAREN) -> atset1:57462 */
NumpadParenRight: 0xe07b, /* html:NumpadParenRight (NumpadParenRight) -> linux:180 (KEY_KPRIGHTPAREN) -> atset1:57467 */
NumpadSubtract: 0x4a, /* html:NumpadSubtract (NumpadSubtract) -> linux:74 (KEY_KPMINUS) -> atset1:74 */
Open: 0x64, /* html:Open (Open) -> linux:134 (KEY_OPEN) -> atset1:100 */
PageDown: 0xe051, /* html:PageDown (PageDown) -> linux:109 (KEY_PAGEDOWN) -> atset1:57425 */
PageUp: 0xe049, /* html:PageUp (PageUp) -> linux:104 (KEY_PAGEUP) -> atset1:57417 */
Paste: 0x65, /* html:Paste (Paste) -> linux:135 (KEY_PASTE) -> atset1:101 */
Pause: 0xe046, /* html:Pause (Pause) -> linux:119 (KEY_PAUSE) -> atset1:57414 */
Period: 0x34, /* html:Period (Period) -> linux:52 (KEY_DOT) -> atset1:52 */
Power: 0xe05e, /* html:Power (Power) -> linux:116 (KEY_POWER) -> atset1:57438 */
PrintScreen: 0x54, /* html:PrintScreen (PrintScreen) -> linux:99 (KEY_SYSRQ) -> atset1:84 */
Props: 0xe006, /* html:Props (Props) -> linux:130 (KEY_PROPS) -> atset1:57350 */
Quote: 0x28, /* html:Quote (Quote) -> linux:40 (KEY_APOSTROPHE) -> atset1:40 */
ScrollLock: 0x46, /* html:ScrollLock (ScrollLock) -> linux:70 (KEY_SCROLLLOCK) -> atset1:70 */
Semicolon: 0x27, /* html:Semicolon (Semicolon) -> linux:39 (KEY_SEMICOLON) -> atset1:39 */
ShiftLeft: 0x2a, /* html:ShiftLeft (ShiftLeft) -> linux:42 (KEY_LEFTSHIFT) -> atset1:42 */
ShiftRight: 0x36, /* html:ShiftRight (ShiftRight) -> linux:54 (KEY_RIGHTSHIFT) -> atset1:54 */
Slash: 0x35, /* html:Slash (Slash) -> linux:53 (KEY_SLASH) -> atset1:53 */
Sleep: 0xe05f, /* html:Sleep (Sleep) -> linux:142 (KEY_SLEEP) -> atset1:57439 */
Space: 0x39, /* html:Space (Space) -> linux:57 (KEY_SPACE) -> atset1:57 */
Suspend: 0xe025, /* html:Suspend (Suspend) -> linux:205 (KEY_SUSPEND) -> atset1:57381 */
Tab: 0xf, /* html:Tab (Tab) -> linux:15 (KEY_TAB) -> atset1:15 */
Undo: 0xe007, /* html:Undo (Undo) -> linux:131 (KEY_UNDO) -> atset1:57351 */
WakeUp: 0xe063, /* html:WakeUp (WakeUp) -> linux:143 (KEY_WAKEUP) -> atset1:57443 */
};

File diff suppressed because it is too large Load Diff

View File

@ -9,12 +9,12 @@
import * as Log from './logging.js';
// Touch detection
export let isTouchDevice = ('ontouchstart' in document.documentElement) ||
export let isTouchDevice = ('ontouchstart' in document.documentElement)
// requried for Chrome debugger
(document.ontouchstart !== undefined) ||
|| (document.ontouchstart !== undefined)
// required for MS Surface
(navigator.maxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0);
|| (navigator.maxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0);
window.addEventListener('touchstart', function onFirstTouch() {
isTouchDevice = true;
window.removeEventListener('touchstart', onFirstTouch, false);
@ -22,21 +22,21 @@ window.addEventListener('touchstart', function onFirstTouch() {
let _cursor_uris_supported = null;
export function supportsCursorURIs () {
export function supportsCursorURIs() {
if (_cursor_uris_supported === null) {
try {
const target = document.createElement('canvas');
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
if (target.style.cursor) {
Log.Info("Data URI scheme cursor supported");
Log.Info('Data URI scheme cursor supported');
_cursor_uris_supported = true;
} else {
Log.Warn("Data URI scheme cursor not supported");
Log.Warn('Data URI scheme cursor not supported');
_cursor_uris_supported = false;
}
} catch (exc) {
Log.Error("Data URI scheme cursor test exception: " + exc);
Log.Error('Data URI scheme cursor test exception: ' + exc);
_cursor_uris_supported = false;
}
}
@ -65,9 +65,8 @@ export function isWindows() {
}
export function isIOS() {
return navigator &&
(!!(/ipad/i).exec(navigator.platform) ||
!!(/iphone/i).exec(navigator.platform) ||
!!(/ipod/i).exec(navigator.platform));
return navigator
&& (!!(/ipad/i).exec(navigator.platform)
|| !!(/iphone/i).exec(navigator.platform)
|| !!(/ipod/i).exec(navigator.platform));
}

View File

@ -27,13 +27,13 @@ export default class Cursor {
this._hotSpot = { x: 0, y: 0 };
this._eventHandlers = {
'mouseover': this._handleMouseOver.bind(this),
'mouseleave': this._handleMouseLeave.bind(this),
'mousemove': this._handleMouseMove.bind(this),
'mouseup': this._handleMouseUp.bind(this),
'touchstart': this._handleTouchStart.bind(this),
'touchmove': this._handleTouchMove.bind(this),
'touchend': this._handleTouchEnd.bind(this),
mouseover: this._handleMouseOver.bind(this),
mouseleave: this._handleMouseLeave.bind(this),
mousemove: this._handleMouseMove.bind(this),
mouseup: this._handleMouseUp.bind(this),
touchstart: this._handleTouchStart.bind(this),
touchmove: this._handleTouchMove.bind(this),
touchend: this._handleTouchEnd.bind(this),
};
}
@ -46,7 +46,7 @@ export default class Cursor {
if (useFallback) {
// FIXME: These don't fire properly except for mouse
/// movement in IE. We want to also capture element
// / movement in IE. We want to also capture element
// movement, size changes, visibility, etc.
const options = { capture: true, passive: true };
this._target.addEventListener('mouseover', this._eventHandlers.mouseover, options);
@ -85,7 +85,7 @@ export default class Cursor {
return;
}
let cur = []
let cur = [];
for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
let idx = y * Math.ceil(w / 8) + Math.floor(x / 8);
@ -187,13 +187,11 @@ export default class Cursor {
}
_showCursor() {
if (this._canvas.style.visibility === 'hidden')
this._canvas.style.visibility = '';
if (this._canvas.style.visibility === 'hidden') this._canvas.style.visibility = '';
}
_hideCursor() {
if (this._canvas.style.visibility !== 'hidden')
this._canvas.style.visibility = 'hidden';
if (this._canvas.style.visibility !== 'hidden') this._canvas.style.visibility = 'hidden';
}
// Should we currently display the cursor?
@ -201,28 +199,23 @@ export default class Cursor {
// different cursor set)
_shouldShowCursor(target) {
// Easy case
if (target === this._target)
return true;
if (target === this._target) return true;
// Other part of the DOM?
if (!this._target.contains(target))
return false;
if (!this._target.contains(target)) return false;
// Has the child its own cursor?
// FIXME: How can we tell that a sub element has an
// explicit "cursor: none;"?
if (window.getComputedStyle(target).cursor !== 'none')
return false;
if (window.getComputedStyle(target).cursor !== 'none') return false;
return true;
}
_updateVisibility(target) {
if (this._shouldShowCursor(target))
this._showCursor();
else
this._hideCursor();
if (this._shouldShowCursor(target)) this._showCursor();
else this._hideCursor();
}
_updatePosition() {
this._canvas.style.left = this._position.x + "px";
this._canvas.style.top = this._position.y + "px";
this._canvas.style.left = this._position.x + 'px';
this._canvas.style.top = this._position.y + 'px';
}
}

View File

@ -10,11 +10,11 @@
* Cross-browser event and position routines
*/
export function getPointerEvent (e) {
export function getPointerEvent(e) {
return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e;
}
export function stopEvent (e) {
export function stopEvent(e) {
e.stopPropagation();
e.preventDefault();
}
@ -42,14 +42,14 @@ function _captureProxy(e) {
}
// Implicitly release the capture on button release
if (e.type === "mouseup") {
if (e.type === 'mouseup') {
releaseCapture();
}
}
// Follow cursor style of target element
function _captureElemChanged() {
const captureElem = document.getElementById("noVNC_mouse_capture_elem");
const captureElem = document.getElementById('noVNC_mouse_capture_elem');
captureElem.style.cursor = window.getComputedStyle(_captureElem).cursor;
}
@ -57,31 +57,29 @@ const _captureObserver = new MutationObserver(_captureElemChanged);
let _captureIndex = 0;
export function setCapture (elem) {
export function setCapture(elem) {
if (elem.setCapture) {
elem.setCapture();
// IE releases capture on 'click' events which might not trigger
elem.addEventListener('mouseup', releaseCapture);
} else {
// Release any existing capture in case this method is
// called multiple times without coordination
releaseCapture();
let captureElem = document.getElementById("noVNC_mouse_capture_elem");
let captureElem = document.getElementById('noVNC_mouse_capture_elem');
if (captureElem === null) {
captureElem = document.createElement("div");
captureElem.id = "noVNC_mouse_capture_elem";
captureElem.style.position = "fixed";
captureElem.style.top = "0px";
captureElem.style.left = "0px";
captureElem.style.width = "100%";
captureElem.style.height = "100%";
captureElem = document.createElement('div');
captureElem.id = 'noVNC_mouse_capture_elem';
captureElem.style.position = 'fixed';
captureElem.style.top = '0px';
captureElem.style.left = '0px';
captureElem.style.width = '100%';
captureElem.style.height = '100%';
captureElem.style.zIndex = 10000;
captureElem.style.display = "none";
captureElem.style.display = 'none';
document.body.appendChild(captureElem);
// This is to make sure callers don't get confused by having
@ -96,10 +94,10 @@ export function setCapture (elem) {
_captureIndex++;
// Track cursor and get initial cursor
_captureObserver.observe(elem, {attributes:true});
_captureObserver.observe(elem, { attributes: true });
_captureElemChanged();
captureElem.style.display = "";
captureElem.style.display = '';
// We listen to events on window in order to keep tracking if it
// happens to leave the viewport
@ -108,11 +106,9 @@ export function setCapture (elem) {
}
}
export function releaseCapture () {
export function releaseCapture() {
if (document.releaseCapture) {
document.releaseCapture();
} else {
if (!_captureElem) {
return;
@ -130,8 +126,8 @@ export function releaseCapture () {
_captureObserver.disconnect();
const captureElem = document.getElementById("noVNC_mouse_capture_elem");
captureElem.style.display = "none";
const captureElem = document.getElementById('noVNC_mouse_capture_elem');
captureElem.style.display = 'none';
window.removeEventListener('mousemove', _captureProxy);
window.removeEventListener('mouseup', _captureProxy);

View File

@ -17,7 +17,7 @@ let Info = () => {};
let Warn = () => {};
let Error = () => {};
export function init_logging (level) {
export function init_logging(level) {
if (typeof level === 'undefined') {
level = _log_level;
} else {
@ -26,7 +26,7 @@ export function init_logging (level) {
Debug = Info = Warn = Error = () => {};
if (typeof window.console !== "undefined") {
if (typeof window.console !== 'undefined') {
/* eslint-disable no-console, no-fallthrough */
switch (level) {
case 'debug':
@ -46,11 +46,13 @@ export function init_logging (level) {
}
}
export function get_logging () {
export function get_logging() {
return _log_level;
}
export { Debug, Info, Warn, Error };
export {
Debug, Info, Warn, Error
};
// Initialize logging level
init_logging();

View File

@ -9,9 +9,10 @@
/* Object.assign() (taken from MDN) */
if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
Object.defineProperty(Object, 'assign', {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
@ -39,16 +40,16 @@ if (typeof Object.assign != 'function') {
/* CustomEvent constructor (taken from MDN) */
(() => {
function CustomEvent (event, params) {
function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
const evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
const evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = window.Event.prototype;
if (typeof window.CustomEvent !== "function") {
if (typeof window.CustomEvent !== 'function') {
window.CustomEvent = CustomEvent;
}
})();

View File

@ -9,6 +9,6 @@
/*
* Decode from UTF-8
*/
export function decodeUTF8 (utf8string) {
export function decodeUTF8(utf8string) {
return decodeURIComponent(escape(utf8string));
}

View File

@ -84,20 +84,20 @@ export default class Websock {
// TODO(directxman12): test performance with these vs a DataView
rQshift16() {
return (this._rQ[this._rQi++] << 8) +
this._rQ[this._rQi++];
return (this._rQ[this._rQi++] << 8)
+ this._rQ[this._rQi++];
}
rQshift32() {
return (this._rQ[this._rQi++] << 24) +
(this._rQ[this._rQi++] << 16) +
(this._rQ[this._rQi++] << 8) +
this._rQ[this._rQi++];
return (this._rQ[this._rQi++] << 24)
+ (this._rQ[this._rQi++] << 16)
+ (this._rQ[this._rQi++] << 8)
+ this._rQ[this._rQi++];
}
rQshiftStr(len) {
if (typeof(len) === 'undefined') { len = this.rQlen(); }
let str = "";
if (typeof (len) === 'undefined') { len = this.rQlen(); }
let str = '';
// Handle large arrays in steps to avoid long strings on the stack
for (let i = 0; i < len; i += 4096) {
let part = this.rQshiftBytes(Math.min(4096, len - i));
@ -107,7 +107,7 @@ export default class Websock {
}
rQshiftBytes(len) {
if (typeof(len) === 'undefined') { len = this.rQlen(); }
if (typeof (len) === 'undefined') { len = this.rQlen(); }
this._rQi += len;
return new Uint8Array(this._rQ.buffer, this._rQi - len, len);
}
@ -139,7 +139,7 @@ export default class Websock {
if (rQlen < num) {
if (goback) {
if (this._rQi < goback) {
throw new Error("rQwait cannot backup " + goback + " bytes");
throw new Error('rQwait cannot backup ' + goback + ' bytes');
}
this._rQi -= goback;
}
@ -197,29 +197,29 @@ export default class Websock {
this._websocket.onopen = () => {
Log.Debug('>> WebSock.onopen');
if (this._websocket.protocol) {
Log.Info("Server choose sub-protocol: " + this._websocket.protocol);
Log.Info('Server choose sub-protocol: ' + this._websocket.protocol);
}
this._eventHandlers.open();
Log.Debug("<< WebSock.onopen");
Log.Debug('<< WebSock.onopen');
};
this._websocket.onclose = (e) => {
Log.Debug(">> WebSock.onclose");
Log.Debug('>> WebSock.onclose');
this._eventHandlers.close(e);
Log.Debug("<< WebSock.onclose");
Log.Debug('<< WebSock.onclose');
};
this._websocket.onerror = (e) => {
Log.Debug(">> WebSock.onerror: " + e);
Log.Debug('>> WebSock.onerror: ' + e);
this._eventHandlers.error(e);
Log.Debug("<< WebSock.onerror: " + e);
Log.Debug('<< WebSock.onerror: ' + e);
};
}
close() {
if (this._websocket) {
if ((this._websocket.readyState === WebSocket.OPEN) ||
(this._websocket.readyState === WebSocket.CONNECTING)) {
Log.Info("Closing WebSocket connection");
if ((this._websocket.readyState === WebSocket.OPEN)
|| (this._websocket.readyState === WebSocket.CONNECTING)) {
Log.Info('Closing WebSocket connection');
this._websocket.close();
}
@ -250,7 +250,7 @@ export default class Websock {
if (this._rQbufferSize > MAX_RQ_GROW_SIZE) {
this._rQbufferSize = MAX_RQ_GROW_SIZE;
if (this._rQbufferSize - this._rQlen - this._rQi < min_fit) {
throw new Error("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit");
throw new Error('Receive Queue buffer exceeded ' + MAX_RQ_GROW_SIZE + ' bytes, and the new message could not fit');
}
}
@ -259,13 +259,11 @@ export default class Websock {
this._rQmax = this._rQbufferSize / 8;
this._rQ = new Uint8Array(this._rQbufferSize);
this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi));
} else {
if (ENABLE_COPYWITHIN) {
} else if (ENABLE_COPYWITHIN) {
this._rQ.copyWithin(0, this._rQi);
} else {
this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi));
}
}
this._rQlen = this._rQlen - this._rQi;
this._rQi = 0;
@ -293,7 +291,7 @@ export default class Websock {
this._expand_compact_rQ();
}
} else {
Log.Debug("Ignoring empty message");
Log.Debug('Ignoring empty message');
}
}
}

8
po/.eslintrc Normal file
View File

@ -0,0 +1,8 @@
{
"env": {
"node": true
},
"rules": {
"no-console": 0
}
}

View File

@ -19,25 +19,25 @@
const getopt = require('node-getopt');
const fs = require('fs');
const po2json = require("po2json");
const po2json = require('po2json');
const opt = getopt.create([
['h' , 'help' , 'display this help'],
['h', 'help', 'display this help'],
]).bindHelp().parseSystem();
if (opt.argv.length != 2) {
console.error("Incorrect number of arguments given");
console.error('Incorrect number of arguments given');
process.exit(1);
}
const data = po2json.parseFileSync(opt.argv[0]);
const bodyPart = Object.keys(data).filter((msgid) => msgid !== "").map((msgid) => {
if (msgid === "") return;
const bodyPart = Object.keys(data).filter(msgid => msgid !== '').map((msgid) => {
if (msgid === '') return;
const msgstr = data[msgid][1];
return " " + JSON.stringify(msgid) + ": " + JSON.stringify(msgstr);
}).join(",\n");
return ' ' + JSON.stringify(msgid) + ': ' + JSON.stringify(msgstr);
}).join(',\n');
const output = "{\n" + bodyPart + "\n}";
const output = '{\n' + bodyPart + '\n}';
fs.writeFileSync(opt.argv[1], output);

View File

@ -11,7 +11,7 @@ chai.use(function (_chai, utils) {
// NB(directxman12): PhantomJS 1.x doesn't implement Uint8ClampedArray, so work around that
const data = new Uint8Array(data_cl);
const len = data_cl.length;
new chai.Assertion(len).to.be.equal(target_data.length, "unexpected display size");
new chai.Assertion(len).to.be.equal(target_data.length, 'unexpected display size');
let same = true;
for (let i = 0; i < len; i++) {
if (data[i] != target_data[i]) {
@ -21,11 +21,11 @@ chai.use(function (_chai, utils) {
}
if (!same) {
// eslint-disable-next-line no-console
console.log("expected data: %o, actual data: %o", target_data, data);
console.log('expected data: %o, actual data: %o', target_data, data);
}
this.assert(same,
"expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}",
"expected #{this} not to have displayed the image #{act}",
'expected #{this} to have displayed the image #{exp}, but instead it displayed #{act}',
'expected #{this} not to have displayed the image #{act}',
target_data,
data);
});
@ -33,8 +33,12 @@ chai.use(function (_chai, utils) {
_chai.Assertion.addMethod('sent', function (target_data) {
const obj = this._obj;
obj.inspect = () => {
const res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
_sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) };
const res = {
_websocket: obj._websocket,
rQi: obj._rQi,
_rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
_sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen)
};
res.prototype = obj;
return res;
};
@ -52,11 +56,11 @@ chai.use(function (_chai, utils) {
}
if (!same) {
// eslint-disable-next-line no-console
console.log("expected data: %o, actual data: %o", target_data, data);
console.log('expected data: %o, actual data: %o', target_data, data);
}
this.assert(same,
"expected #{this} to have sent the data #{exp}, but it actually sent #{act}",
"expected #{this} not to have sent the data #{act}",
'expected #{this} to have sent the data #{exp}, but it actually sent #{act}',
'expected #{this} not to have sent the data #{act}',
Array.prototype.slice.call(target_data),
Array.prototype.slice.call(data));
});
@ -81,8 +85,8 @@ chai.use(function (_chai, utils) {
}
this.assert(same,
"expected #{this} to have elements deeply equal to #{exp}",
"expected #{this} not to have elements deeply equal to #{exp}",
'expected #{this} to have elements deeply equal to #{exp}',
'expected #{this} not to have elements deeply equal to #{exp}',
Array.prototype.slice.call(target));
} else {
for (let i = 0; i < obj.length; i++) {
@ -93,8 +97,8 @@ chai.use(function (_chai, utils) {
}
this.assert(same,
"expected #{this} to have elements equal to #{exp}",
"expected #{this} not to have elements equal to #{exp}",
'expected #{this} to have elements equal to #{exp}',
'expected #{this} not to have elements equal to #{exp}',
Array.prototype.slice.call(target));
}
} else {

View File

@ -15,8 +15,8 @@ function make_event(name, props) {
export default class FakeWebSocket {
constructor(uri, protocols) {
this.url = uri;
this.binaryType = "arraybuffer";
this.extensions = "";
this.binaryType = 'arraybuffer';
this.extensions = '';
if (!protocols || typeof protocols === 'string') {
this.protocol = protocols;
@ -35,7 +35,7 @@ export default class FakeWebSocket {
close(code, reason) {
this.readyState = FakeWebSocket.CLOSED;
if (this.onclose) {
this.onclose(make_event("close", { 'code': code, 'reason': reason, 'wasClean': true }));
this.onclose(make_event('close', { code: code, reason: reason, wasClean: true }));
}
}
@ -63,7 +63,7 @@ export default class FakeWebSocket {
}
_receive_data(data) {
this.onmessage(make_event("message", { 'data': data }));
this.onmessage(make_event('message', { data: data }));
}
}

View File

@ -8,7 +8,7 @@ let encoding = null;
function message(str) {
const cell = document.getElementById('messages');
cell.textContent += str + "\n";
cell.textContent += str + '\n';
cell.scrollTop = cell.scrollHeight;
}
@ -16,17 +16,17 @@ function loadFile() {
const fname = WebUtil.getQueryVar('data', null);
if (!fname) {
return Promise.reject("Must specify data=FOO in query string.");
return Promise.reject('Must specify data=FOO in query string.');
}
message("Loading " + fname);
message('Loading ' + fname);
return new Promise((resolve, reject) => {
const script = document.createElement("script");
const script = document.createElement('script');
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
script.src = "../recordings/" + fname;
script.src = '../recordings/' + fname;
});
}
@ -41,7 +41,7 @@ function enableUI() {
document.getElementById('mode1').checked = true;
}
message("VNC_frame_data.length: " + VNC_frame_data.length);
message('VNC_frame_data.length: ' + VNC_frame_data.length);
const startButton = document.getElementById('startButton');
startButton.disabled = false;
@ -49,8 +49,7 @@ function enableUI() {
frames = VNC_frame_data;
// Only present in older recordings
if (window.VNC_frame_encoding)
encoding = VNC_frame_encoding;
if (window.VNC_frame_encoding) encoding = VNC_frame_encoding;
}
class IterationPlayer {
@ -131,7 +130,7 @@ class IterationPlayer {
}
function start() {
document.getElementById('startButton').value = "Running";
document.getElementById('startButton').value = 'Running';
document.getElementById('startButton').disabled = true;
const iterations = document.getElementById('iterations').value;
@ -160,9 +159,9 @@ function start() {
message(`${evt.iterations} iterations took ${evt.duration}ms (average ${iterTime}ms / iteration)`);
document.getElementById('startButton').disabled = false;
document.getElementById('startButton').value = "Start";
document.getElementById('startButton').value = 'Start';
};
player.start(mode);
}
loadFile().then(enableUI).catch(e => message("Error loading recording: " + e));
loadFile().then(enableUI).catch(e => message('Error loading recording: ' + e));

View File

@ -16,7 +16,7 @@ if (window.setImmediate === undefined) {
window.setImmediate = (func) => {
const index = _immediateIdCounter++;
_immediateFuncs[index] = func;
window.postMessage("noVNC immediate trigger:" + index, "*");
window.postMessage('noVNC immediate trigger:' + index, '*');
return index;
};
@ -24,13 +24,13 @@ if (window.setImmediate === undefined) {
_immediateFuncs[id];
};
window.addEventListener("message", (event) => {
if ((typeof event.data !== "string") ||
(event.data.indexOf("noVNC immediate trigger:") !== 0)) {
window.addEventListener('message', (event) => {
if ((typeof event.data !== 'string')
|| (event.data.indexOf('noVNC immediate trigger:') !== 0)) {
return;
}
const index = event.data.slice("noVNC immediate trigger:".length);
const index = event.data.slice('noVNC immediate trigger:'.length);
const callback = _immediateFuncs[index];
if (callback === undefined) {
@ -77,7 +77,7 @@ export default class RecordingPlayer {
// initialize a new RFB
this._rfb = new RFB(document.getElementById('VNC_screen'), 'wss://test');
this._rfb.viewOnly = true;
this._rfb.addEventListener("disconnect",
this._rfb.addEventListener('disconnect',
this._handleDisconnect.bind(this));
this._enablePlaybackMode();
@ -110,7 +110,7 @@ export default class RecordingPlayer {
let frame = this._frames[this._frame_index];
// skip send frames
while (this._frame_index < this._frame_length && frame.charAt(0) === "}") {
while (this._frame_index < this._frame_length && frame.charAt(0) === '}') {
this._frame_index++;
frame = this._frames[this._frame_index];
}
@ -164,7 +164,7 @@ export default class RecordingPlayer {
}
}
this._rfb._sock._recv_message({'data': u8});
this._rfb._sock._recv_message({ data: u8 });
this._frame_index++;
this._queueNextPacket();
@ -181,7 +181,7 @@ export default class RecordingPlayer {
this._rfb._display.flush();
} else {
this._running = false;
this._rfb._sock._eventHandlers.close({code: 1000, reason: ""});
this._rfb._sock._eventHandlers.close({ code: 1000, reason: '' });
delete this._rfb;
this.onfinish((new Date()).getTime() - this._start_time);
}

View File

@ -2,32 +2,32 @@ const expect = chai.expect;
import Base64 from '../core/base64.js';
describe('Base64 Tools', function() {
"use strict";
describe('Base64 Tools', function () {
'use strict';
const BIN_ARR = new Array(256);
for (let i = 0; i < 256; i++) {
BIN_ARR[i] = i;
}
const B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
const B64_STR = 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==';
describe('encode', function() {
it('should encode a binary string into Base64', function() {
describe('encode', function () {
it('should encode a binary string into Base64', function () {
const encoded = Base64.encode(BIN_ARR);
expect(encoded).to.equal(B64_STR);
});
});
describe('decode', function() {
it('should decode a Base64 string into a normal string', function() {
describe('decode', function () {
it('should decode a Base64 string into a normal string', function () {
const decoded = Base64.decode(B64_STR);
expect(decoded).to.deep.equal(BIN_ARR);
});
it('should throw an error if we have extra characters at the end of the string', function() {
expect(() => Base64.decode(B64_STR+'abcdef')).to.throw(Error);
it('should throw an error if we have extra characters at the end of the string', function () {
expect(() => Base64.decode(B64_STR + 'abcdef')).to.throw(Error);
});
});
});

View File

@ -15,7 +15,7 @@ describe('Display/Canvas Helper', function () {
const basic_data = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]);
function make_image_canvas (input_data) {
function make_image_canvas(input_data) {
const canvas = document.createElement('canvas');
canvas.width = 4;
canvas.height = 4;
@ -26,10 +26,10 @@ describe('Display/Canvas Helper', function () {
return canvas;
}
function make_image_png (input_data) {
function make_image_png(input_data) {
const canvas = make_image_canvas(input_data);
const url = canvas.toDataURL();
const data = url.split(",")[1];
const data = url.split(',')[1];
return Base64.decode(data);
}
@ -55,13 +55,13 @@ describe('Display/Canvas Helper', function () {
expect(display).to.have.displayed(expected);
});
it('should resize the target canvas when resizing the viewport', function() {
it('should resize the target canvas when resizing the viewport', function () {
display.viewportChangeSize(2, 2);
expect(display._target.width).to.equal(2);
expect(display._target.height).to.equal(2);
});
it('should move the viewport if necessary', function() {
it('should move the viewport if necessary', function () {
display.viewportChangeSize(5, 5);
expect(display.absX(0)).to.equal(0);
expect(display.absY(0)).to.equal(0);
@ -69,7 +69,7 @@ describe('Display/Canvas Helper', function () {
expect(display._target.height).to.equal(5);
});
it('should limit the viewport to the framebuffer size', function() {
it('should limit the viewport to the framebuffer size', function () {
display.viewportChangeSize(6, 6);
expect(display._target.width).to.equal(5);
expect(display._target.height).to.equal(5);
@ -87,7 +87,7 @@ describe('Display/Canvas Helper', function () {
expect(display.flip).to.have.been.calledOnce;
});
it('should show the entire framebuffer when disabling the viewport', function() {
it('should show the entire framebuffer when disabling the viewport', function () {
display.clipViewport = false;
expect(display.absX(0)).to.equal(0);
expect(display.absY(0)).to.equal(0);
@ -95,7 +95,7 @@ describe('Display/Canvas Helper', function () {
expect(display._target.height).to.equal(5);
});
it('should ignore viewport changes when the viewport is disabled', function() {
it('should ignore viewport changes when the viewport is disabled', function () {
display.clipViewport = false;
display.viewportChangeSize(2, 2);
display.viewportChangePos(1, 1);
@ -105,7 +105,7 @@ describe('Display/Canvas Helper', function () {
expect(display._target.height).to.equal(5);
});
it('should show the entire framebuffer just after enabling the viewport', function() {
it('should show the entire framebuffer just after enabling the viewport', function () {
display.clipViewport = false;
display.clipViewport = true;
expect(display.absX(0)).to.equal(0);
@ -134,10 +134,10 @@ describe('Display/Canvas Helper', function () {
display.resize(2, 2);
display.flip();
const expected = [];
for (let i = 0; i < 4 * 2*2; i += 4) {
for (let i = 0; i < 4 * 2 * 2; i += 4) {
expected[i] = 0xff;
expected[i+1] = expected[i+2] = 0;
expected[i+3] = 0xff;
expected[i + 1] = expected[i + 2] = 0;
expected[i + 3] = 0xff;
}
expect(display).to.have.displayed(new Uint8Array(expected));
});
@ -251,7 +251,6 @@ describe('Display/Canvas Helper', function () {
expect(display.absY(18)).to.equal(6);
expect(canvas.clientWidth).to.equal(12); // 16 * (4 / 3)
expect(canvas.clientHeight).to.equal(9);
});
it('should not change the bitmap size of the canvas', function () {
@ -262,7 +261,6 @@ describe('Display/Canvas Helper', function () {
});
describe('drawing', function () {
// TODO(directxman12): improve the tests for each of the drawing functions to cover more than just the
// basic cases
let display;
@ -282,7 +280,9 @@ describe('Display/Canvas Helper', function () {
});
it('should draw the logo on #clear with a logo set', function (done) {
display._logo = { width: 4, height: 4, type: "image/png", data: make_image_png(checked_data) };
display._logo = {
width: 4, height: 4, type: 'image/png', data: make_image_png(checked_data)
};
display.clear();
display.onflush = () => {
expect(display).to.have.displayed(checked_data);
@ -300,8 +300,8 @@ describe('Display/Canvas Helper', function () {
const expected = [];
for (let i = 0; i < 4 * display._fb_width * display._fb_height; i += 4) {
expected[i] = 0xff;
expected[i+1] = expected[i+2] = 0;
expected[i+3] = 0xff;
expected[i + 1] = expected[i + 2] = 0;
expected[i + 3] = 0xff;
}
expect(display).to.have.displayed(new Uint8Array(expected));
});
@ -323,7 +323,7 @@ describe('Display/Canvas Helper', function () {
});
it('should support drawing images via #imageRect', function (done) {
display.imageRect(0, 0, "image/png", make_image_png(checked_data));
display.imageRect(0, 0, 'image/png', make_image_png(checked_data));
display.flip();
display.onflush = () => {
expect(display).to.have.displayed(checked_data);
@ -343,19 +343,19 @@ describe('Display/Canvas Helper', function () {
// We have a special cache for 16x16 tiles that we need to test
it('should support drawing a 16x16 tile', function () {
const large_checked_data = new Uint8Array(16*16*4);
const large_checked_data = new Uint8Array(16 * 16 * 4);
display.resize(16, 16);
for (let y = 0;y < 16;y++) {
for (let x = 0;x < 16;x++) {
for (let y = 0; y < 16; y++) {
for (let x = 0; x < 16; x++) {
let pixel;
if ((x < 4) && (y < 4)) {
// NB: of course IE11 doesn't support #slice on ArrayBufferViews...
pixel = Array.prototype.slice.call(checked_data, (y*4+x)*4, (y*4+x+1)*4);
pixel = Array.prototype.slice.call(checked_data, (y * 4 + x) * 4, (y * 4 + x + 1) * 4);
} else {
pixel = [0, 0xff, 0, 255];
}
large_checked_data.set(pixel, (y*16+x)*4);
large_checked_data.set(pixel, (y * 16 + x) * 4);
}
}
@ -424,9 +424,13 @@ describe('Display/Canvas Helper', function () {
});
it('should wait until an image is loaded to attempt to draw it and the rest of the queue', function () {
const img = { complete: false, addEventListener: sinon.spy() }
display._renderQ = [{ type: 'img', x: 3, y: 4, img: img },
{ type: 'fill', x: 1, y: 2, width: 3, height: 4, color: 5 }];
const img = { complete: false, addEventListener: sinon.spy() };
display._renderQ = [{
type: 'img', x: 3, y: 4, img: img
},
{
type: 'fill', x: 1, y: 2, width: 3, height: 4, color: 5
}];
display.drawImage = sinon.spy();
display.fillRect = sinon.spy();
@ -452,35 +456,45 @@ describe('Display/Canvas Helper', function () {
it('should draw a blit image on type "blit"', function () {
display.blitImage = sinon.spy();
display._renderQ_push({ type: 'blit', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] });
display._renderQ_push({
type: 'blit', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9]
});
expect(display.blitImage).to.have.been.calledOnce;
expect(display.blitImage).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9], 0);
});
it('should draw a blit RGB image on type "blitRgb"', function () {
display.blitRgbImage = sinon.spy();
display._renderQ_push({ type: 'blitRgb', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9] });
display._renderQ_push({
type: 'blitRgb', x: 3, y: 4, width: 5, height: 6, data: [7, 8, 9]
});
expect(display.blitRgbImage).to.have.been.calledOnce;
expect(display.blitRgbImage).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9], 0);
});
it('should copy a region on type "copy"', function () {
display.copyImage = sinon.spy();
display._renderQ_push({ type: 'copy', x: 3, y: 4, width: 5, height: 6, old_x: 7, old_y: 8 });
display._renderQ_push({
type: 'copy', x: 3, y: 4, width: 5, height: 6, old_x: 7, old_y: 8
});
expect(display.copyImage).to.have.been.calledOnce;
expect(display.copyImage).to.have.been.calledWith(7, 8, 3, 4, 5, 6);
});
it('should fill a rect with a given color on type "fill"', function () {
display.fillRect = sinon.spy();
display._renderQ_push({ type: 'fill', x: 3, y: 4, width: 5, height: 6, color: [7, 8, 9]});
display._renderQ_push({
type: 'fill', x: 3, y: 4, width: 5, height: 6, color: [7, 8, 9]
});
expect(display.fillRect).to.have.been.calledOnce;
expect(display.fillRect).to.have.been.calledWith(3, 4, 5, 6, [7, 8, 9]);
});
it('should draw an image from an image object on type "img" (if complete)', function () {
display.drawImage = sinon.spy();
display._renderQ_push({ type: 'img', x: 3, y: 4, img: { complete: true } });
display._renderQ_push({
type: 'img', x: 3, y: 4, img: { complete: true }
});
expect(display.drawImage).to.have.been.calledOnce;
expect(display.drawImage).to.have.been.calledWith({ complete: true }, 3, 4);
});

View File

@ -1,145 +1,147 @@
const expect = chai.expect;
const expect = chai.expect;
import keysyms from '../core/input/keysymdef.js';
import * as KeyboardUtil from "../core/input/util.js";
import * as KeyboardUtil from '../core/input/util.js';
import * as browser from '../core/util/browser.js';
describe('Helpers', function() {
"use strict";
describe('Helpers', function () {
'use strict';
describe('keysyms.lookup', function() {
it('should map ASCII characters to keysyms', function() {
describe('keysyms.lookup', function () {
it('should map ASCII characters to keysyms', function () {
expect(keysyms.lookup('a'.charCodeAt())).to.be.equal(0x61);
expect(keysyms.lookup('A'.charCodeAt())).to.be.equal(0x41);
});
it('should map Latin-1 characters to keysyms', function() {
it('should map Latin-1 characters to keysyms', function () {
expect(keysyms.lookup('ø'.charCodeAt())).to.be.equal(0xf8);
expect(keysyms.lookup('é'.charCodeAt())).to.be.equal(0xe9);
});
it('should map characters that are in Windows-1252 but not in Latin-1 to keysyms', function() {
it('should map characters that are in Windows-1252 but not in Latin-1 to keysyms', function () {
expect(keysyms.lookup('Š'.charCodeAt())).to.be.equal(0x01a9);
});
it('should map characters which aren\'t in Latin1 *or* Windows-1252 to keysyms', function() {
it('should map characters which aren\'t in Latin1 *or* Windows-1252 to keysyms', function () {
expect(keysyms.lookup('ũ'.charCodeAt())).to.be.equal(0x03fd);
});
it('should map unknown codepoints to the Unicode range', function() {
it('should map unknown codepoints to the Unicode range', function () {
expect(keysyms.lookup('\n'.charCodeAt())).to.be.equal(0x100000a);
expect(keysyms.lookup('\u262D'.charCodeAt())).to.be.equal(0x100262d);
});
// This requires very recent versions of most browsers... skipping for now
it.skip('should map UCS-4 codepoints to the Unicode range', function() {
//expect(keysyms.lookup('\u{1F686}'.codePointAt())).to.be.equal(0x101f686);
it.skip('should map UCS-4 codepoints to the Unicode range', function () {
// expect(keysyms.lookup('\u{1F686}'.codePointAt())).to.be.equal(0x101f686);
});
});
describe('getKeycode', function() {
it('should pass through proper code', function() {
expect(KeyboardUtil.getKeycode({code: 'Semicolon'})).to.be.equal('Semicolon');
describe('getKeycode', function () {
it('should pass through proper code', function () {
expect(KeyboardUtil.getKeycode({ code: 'Semicolon' })).to.be.equal('Semicolon');
});
it('should map legacy values', function() {
expect(KeyboardUtil.getKeycode({code: ''})).to.be.equal('Unidentified');
expect(KeyboardUtil.getKeycode({code: 'OSLeft'})).to.be.equal('MetaLeft');
it('should map legacy values', function () {
expect(KeyboardUtil.getKeycode({ code: '' })).to.be.equal('Unidentified');
expect(KeyboardUtil.getKeycode({ code: 'OSLeft' })).to.be.equal('MetaLeft');
});
it('should map keyCode to code when possible', function() {
expect(KeyboardUtil.getKeycode({keyCode: 0x14})).to.be.equal('CapsLock');
expect(KeyboardUtil.getKeycode({keyCode: 0x5b})).to.be.equal('MetaLeft');
expect(KeyboardUtil.getKeycode({keyCode: 0x35})).to.be.equal('Digit5');
expect(KeyboardUtil.getKeycode({keyCode: 0x65})).to.be.equal('Numpad5');
it('should map keyCode to code when possible', function () {
expect(KeyboardUtil.getKeycode({ keyCode: 0x14 })).to.be.equal('CapsLock');
expect(KeyboardUtil.getKeycode({ keyCode: 0x5b })).to.be.equal('MetaLeft');
expect(KeyboardUtil.getKeycode({ keyCode: 0x35 })).to.be.equal('Digit5');
expect(KeyboardUtil.getKeycode({ keyCode: 0x65 })).to.be.equal('Numpad5');
});
it('should map keyCode left/right side', function() {
expect(KeyboardUtil.getKeycode({keyCode: 0x10, location: 1})).to.be.equal('ShiftLeft');
expect(KeyboardUtil.getKeycode({keyCode: 0x10, location: 2})).to.be.equal('ShiftRight');
expect(KeyboardUtil.getKeycode({keyCode: 0x11, location: 1})).to.be.equal('ControlLeft');
expect(KeyboardUtil.getKeycode({keyCode: 0x11, location: 2})).to.be.equal('ControlRight');
it('should map keyCode left/right side', function () {
expect(KeyboardUtil.getKeycode({ keyCode: 0x10, location: 1 })).to.be.equal('ShiftLeft');
expect(KeyboardUtil.getKeycode({ keyCode: 0x10, location: 2 })).to.be.equal('ShiftRight');
expect(KeyboardUtil.getKeycode({ keyCode: 0x11, location: 1 })).to.be.equal('ControlLeft');
expect(KeyboardUtil.getKeycode({ keyCode: 0x11, location: 2 })).to.be.equal('ControlRight');
});
it('should map keyCode on numpad', function() {
expect(KeyboardUtil.getKeycode({keyCode: 0x0d, location: 0})).to.be.equal('Enter');
expect(KeyboardUtil.getKeycode({keyCode: 0x0d, location: 3})).to.be.equal('NumpadEnter');
expect(KeyboardUtil.getKeycode({keyCode: 0x23, location: 0})).to.be.equal('End');
expect(KeyboardUtil.getKeycode({keyCode: 0x23, location: 3})).to.be.equal('Numpad1');
it('should map keyCode on numpad', function () {
expect(KeyboardUtil.getKeycode({ keyCode: 0x0d, location: 0 })).to.be.equal('Enter');
expect(KeyboardUtil.getKeycode({ keyCode: 0x0d, location: 3 })).to.be.equal('NumpadEnter');
expect(KeyboardUtil.getKeycode({ keyCode: 0x23, location: 0 })).to.be.equal('End');
expect(KeyboardUtil.getKeycode({ keyCode: 0x23, location: 3 })).to.be.equal('Numpad1');
});
it('should return Unidentified when it cannot map the keyCode', function() {
expect(KeyboardUtil.getKeycode({keycode: 0x42})).to.be.equal('Unidentified');
it('should return Unidentified when it cannot map the keyCode', function () {
expect(KeyboardUtil.getKeycode({ keycode: 0x42 })).to.be.equal('Unidentified');
});
describe('Fix Meta on macOS', function() {
describe('Fix Meta on macOS', function () {
let origNavigator;
beforeEach(function () {
// window.navigator is a protected read-only property in many
// environments, so we need to redefine it whilst running these
// tests.
origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
origNavigator = Object.getOwnPropertyDescriptor(window, 'navigator');
if (origNavigator === undefined) {
// Object.getOwnPropertyDescriptor() doesn't work
// properly in any version of IE
this.skip();
}
Object.defineProperty(window, "navigator", {value: {}});
Object.defineProperty(window, 'navigator', { value: {} });
if (window.navigator.platform !== undefined) {
// Object.defineProperty() doesn't work properly in old
// versions of Chrome
this.skip();
}
window.navigator.platform = "Mac x86_64";
window.navigator.platform = 'Mac x86_64';
});
afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator);
Object.defineProperty(window, 'navigator', origNavigator);
});
it('should respect ContextMenu on modern browser', function() {
expect(KeyboardUtil.getKeycode({code: 'ContextMenu', keyCode: 0x5d})).to.be.equal('ContextMenu');
it('should respect ContextMenu on modern browser', function () {
expect(KeyboardUtil.getKeycode({ code: 'ContextMenu', keyCode: 0x5d })).to.be.equal('ContextMenu');
});
it('should translate legacy ContextMenu to MetaRight', function() {
expect(KeyboardUtil.getKeycode({keyCode: 0x5d})).to.be.equal('MetaRight');
it('should translate legacy ContextMenu to MetaRight', function () {
expect(KeyboardUtil.getKeycode({ keyCode: 0x5d })).to.be.equal('MetaRight');
});
});
});
describe('getKey', function() {
it('should prefer key', function() {
describe('getKey', function () {
it('should prefer key', function () {
if (browser.isIE() || browser.isEdge()) this.skip();
expect(KeyboardUtil.getKey({key: 'a', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal('a');
expect(KeyboardUtil.getKey({
key: 'a', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43
})).to.be.equal('a');
});
it('should map legacy values', function() {
expect(KeyboardUtil.getKey({key: 'Spacebar'})).to.be.equal(' ');
expect(KeyboardUtil.getKey({key: 'Left'})).to.be.equal('ArrowLeft');
expect(KeyboardUtil.getKey({key: 'OS'})).to.be.equal('Meta');
expect(KeyboardUtil.getKey({key: 'Win'})).to.be.equal('Meta');
expect(KeyboardUtil.getKey({key: 'UIKeyInputLeftArrow'})).to.be.equal('ArrowLeft');
it('should map legacy values', function () {
expect(KeyboardUtil.getKey({ key: 'Spacebar' })).to.be.equal(' ');
expect(KeyboardUtil.getKey({ key: 'Left' })).to.be.equal('ArrowLeft');
expect(KeyboardUtil.getKey({ key: 'OS' })).to.be.equal('Meta');
expect(KeyboardUtil.getKey({ key: 'Win' })).to.be.equal('Meta');
expect(KeyboardUtil.getKey({ key: 'UIKeyInputLeftArrow' })).to.be.equal('ArrowLeft');
});
it('should use code if no key', function() {
expect(KeyboardUtil.getKey({code: 'NumpadBackspace'})).to.be.equal('Backspace');
it('should use code if no key', function () {
expect(KeyboardUtil.getKey({ code: 'NumpadBackspace' })).to.be.equal('Backspace');
});
it('should not use code fallback for character keys', function() {
expect(KeyboardUtil.getKey({code: 'KeyA'})).to.be.equal('Unidentified');
expect(KeyboardUtil.getKey({code: 'Digit1'})).to.be.equal('Unidentified');
expect(KeyboardUtil.getKey({code: 'Period'})).to.be.equal('Unidentified');
expect(KeyboardUtil.getKey({code: 'Numpad1'})).to.be.equal('Unidentified');
it('should not use code fallback for character keys', function () {
expect(KeyboardUtil.getKey({ code: 'KeyA' })).to.be.equal('Unidentified');
expect(KeyboardUtil.getKey({ code: 'Digit1' })).to.be.equal('Unidentified');
expect(KeyboardUtil.getKey({ code: 'Period' })).to.be.equal('Unidentified');
expect(KeyboardUtil.getKey({ code: 'Numpad1' })).to.be.equal('Unidentified');
});
it('should use charCode if no key', function() {
expect(KeyboardUtil.getKey({charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal('Š');
it('should use charCode if no key', function () {
expect(KeyboardUtil.getKey({ charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43 })).to.be.equal('Š');
});
it('should return Unidentified when it cannot map the key', function() {
expect(KeyboardUtil.getKey({keycode: 0x42})).to.be.equal('Unidentified');
it('should return Unidentified when it cannot map the key', function () {
expect(KeyboardUtil.getKey({ keycode: 0x42 })).to.be.equal('Unidentified');
});
describe('Broken key AltGraph on IE/Edge', function() {
describe('Broken key AltGraph on IE/Edge', function () {
let origNavigator;
beforeEach(function () {
// window.navigator is a protected read-only property in many
// environments, so we need to redefine it whilst running these
// tests.
origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
origNavigator = Object.getOwnPropertyDescriptor(window, 'navigator');
if (origNavigator === undefined) {
// Object.getOwnPropertyDescriptor() doesn't work
// properly in any version of IE
this.skip();
}
Object.defineProperty(window, "navigator", {value: {}});
Object.defineProperty(window, 'navigator', { value: {} });
if (window.navigator.platform !== undefined) {
// Object.defineProperty() doesn't work properly in old
// versions of Chrome
@ -147,76 +149,76 @@ describe('Helpers', function() {
}
});
afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator);
Object.defineProperty(window, 'navigator', origNavigator);
});
it('should ignore printable character key on IE', function() {
window.navigator.userAgent = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko";
expect(KeyboardUtil.getKey({key: 'a'})).to.be.equal('Unidentified');
it('should ignore printable character key on IE', function () {
window.navigator.userAgent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
expect(KeyboardUtil.getKey({ key: 'a' })).to.be.equal('Unidentified');
});
it('should ignore printable character key on Edge', function() {
window.navigator.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393";
expect(KeyboardUtil.getKey({key: 'a'})).to.be.equal('Unidentified');
it('should ignore printable character key on Edge', function () {
window.navigator.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393';
expect(KeyboardUtil.getKey({ key: 'a' })).to.be.equal('Unidentified');
});
it('should allow non-printable character key on IE', function() {
window.navigator.userAgent = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko";
expect(KeyboardUtil.getKey({key: 'Shift'})).to.be.equal('Shift');
it('should allow non-printable character key on IE', function () {
window.navigator.userAgent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
expect(KeyboardUtil.getKey({ key: 'Shift' })).to.be.equal('Shift');
});
it('should allow non-printable character key on Edge', function() {
window.navigator.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393";
expect(KeyboardUtil.getKey({key: 'Shift'})).to.be.equal('Shift');
it('should allow non-printable character key on Edge', function () {
window.navigator.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393';
expect(KeyboardUtil.getKey({ key: 'Shift' })).to.be.equal('Shift');
});
});
});
describe('getKeysym', function() {
describe('Non-character keys', function() {
it('should recognize the right keys', function() {
expect(KeyboardUtil.getKeysym({key: 'Enter'})).to.be.equal(0xFF0D);
expect(KeyboardUtil.getKeysym({key: 'Backspace'})).to.be.equal(0xFF08);
expect(KeyboardUtil.getKeysym({key: 'Tab'})).to.be.equal(0xFF09);
expect(KeyboardUtil.getKeysym({key: 'Shift'})).to.be.equal(0xFFE1);
expect(KeyboardUtil.getKeysym({key: 'Control'})).to.be.equal(0xFFE3);
expect(KeyboardUtil.getKeysym({key: 'Alt'})).to.be.equal(0xFFE9);
expect(KeyboardUtil.getKeysym({key: 'Meta'})).to.be.equal(0xFFEB);
expect(KeyboardUtil.getKeysym({key: 'Escape'})).to.be.equal(0xFF1B);
expect(KeyboardUtil.getKeysym({key: 'ArrowUp'})).to.be.equal(0xFF52);
describe('getKeysym', function () {
describe('Non-character keys', function () {
it('should recognize the right keys', function () {
expect(KeyboardUtil.getKeysym({ key: 'Enter' })).to.be.equal(0xFF0D);
expect(KeyboardUtil.getKeysym({ key: 'Backspace' })).to.be.equal(0xFF08);
expect(KeyboardUtil.getKeysym({ key: 'Tab' })).to.be.equal(0xFF09);
expect(KeyboardUtil.getKeysym({ key: 'Shift' })).to.be.equal(0xFFE1);
expect(KeyboardUtil.getKeysym({ key: 'Control' })).to.be.equal(0xFFE3);
expect(KeyboardUtil.getKeysym({ key: 'Alt' })).to.be.equal(0xFFE9);
expect(KeyboardUtil.getKeysym({ key: 'Meta' })).to.be.equal(0xFFEB);
expect(KeyboardUtil.getKeysym({ key: 'Escape' })).to.be.equal(0xFF1B);
expect(KeyboardUtil.getKeysym({ key: 'ArrowUp' })).to.be.equal(0xFF52);
});
it('should map left/right side', function() {
expect(KeyboardUtil.getKeysym({key: 'Shift', location: 1})).to.be.equal(0xFFE1);
expect(KeyboardUtil.getKeysym({key: 'Shift', location: 2})).to.be.equal(0xFFE2);
expect(KeyboardUtil.getKeysym({key: 'Control', location: 1})).to.be.equal(0xFFE3);
expect(KeyboardUtil.getKeysym({key: 'Control', location: 2})).to.be.equal(0xFFE4);
it('should map left/right side', function () {
expect(KeyboardUtil.getKeysym({ key: 'Shift', location: 1 })).to.be.equal(0xFFE1);
expect(KeyboardUtil.getKeysym({ key: 'Shift', location: 2 })).to.be.equal(0xFFE2);
expect(KeyboardUtil.getKeysym({ key: 'Control', location: 1 })).to.be.equal(0xFFE3);
expect(KeyboardUtil.getKeysym({ key: 'Control', location: 2 })).to.be.equal(0xFFE4);
});
it('should handle AltGraph', function() {
expect(KeyboardUtil.getKeysym({code: 'AltRight', key: 'Alt', location: 2})).to.be.equal(0xFFEA);
expect(KeyboardUtil.getKeysym({code: 'AltRight', key: 'AltGraph', location: 2})).to.be.equal(0xFE03);
it('should handle AltGraph', function () {
expect(KeyboardUtil.getKeysym({ code: 'AltRight', key: 'Alt', location: 2 })).to.be.equal(0xFFEA);
expect(KeyboardUtil.getKeysym({ code: 'AltRight', key: 'AltGraph', location: 2 })).to.be.equal(0xFE03);
});
it('should return null for unknown keys', function() {
expect(KeyboardUtil.getKeysym({key: 'Semicolon'})).to.be.null;
expect(KeyboardUtil.getKeysym({key: 'BracketRight'})).to.be.null;
it('should return null for unknown keys', function () {
expect(KeyboardUtil.getKeysym({ key: 'Semicolon' })).to.be.null;
expect(KeyboardUtil.getKeysym({ key: 'BracketRight' })).to.be.null;
});
it('should handle remappings', function() {
expect(KeyboardUtil.getKeysym({code: 'ControlLeft', key: 'Tab'})).to.be.equal(0xFF09);
it('should handle remappings', function () {
expect(KeyboardUtil.getKeysym({ code: 'ControlLeft', key: 'Tab' })).to.be.equal(0xFF09);
});
});
describe('Numpad', function() {
it('should handle Numpad numbers', function() {
describe('Numpad', function () {
it('should handle Numpad numbers', function () {
if (browser.isIE() || browser.isEdge()) this.skip();
expect(KeyboardUtil.getKeysym({code: 'Digit5', key: '5', location: 0})).to.be.equal(0x0035);
expect(KeyboardUtil.getKeysym({code: 'Numpad5', key: '5', location: 3})).to.be.equal(0xFFB5);
expect(KeyboardUtil.getKeysym({ code: 'Digit5', key: '5', location: 0 })).to.be.equal(0x0035);
expect(KeyboardUtil.getKeysym({ code: 'Numpad5', key: '5', location: 3 })).to.be.equal(0xFFB5);
});
it('should handle Numpad non-character keys', function() {
expect(KeyboardUtil.getKeysym({code: 'Home', key: 'Home', location: 0})).to.be.equal(0xFF50);
expect(KeyboardUtil.getKeysym({code: 'Numpad5', key: 'Home', location: 3})).to.be.equal(0xFF95);
expect(KeyboardUtil.getKeysym({code: 'Delete', key: 'Delete', location: 0})).to.be.equal(0xFFFF);
expect(KeyboardUtil.getKeysym({code: 'NumpadDecimal', key: 'Delete', location: 3})).to.be.equal(0xFF9F);
it('should handle Numpad non-character keys', function () {
expect(KeyboardUtil.getKeysym({ code: 'Home', key: 'Home', location: 0 })).to.be.equal(0xFF50);
expect(KeyboardUtil.getKeysym({ code: 'Numpad5', key: 'Home', location: 3 })).to.be.equal(0xFF95);
expect(KeyboardUtil.getKeysym({ code: 'Delete', key: 'Delete', location: 0 })).to.be.equal(0xFFFF);
expect(KeyboardUtil.getKeysym({ code: 'NumpadDecimal', key: 'Delete', location: 3 })).to.be.equal(0xFF9F);
});
it('should handle Numpad Decimal key', function() {
it('should handle Numpad Decimal key', function () {
if (browser.isIE() || browser.isEdge()) this.skip();
expect(KeyboardUtil.getKeysym({code: 'NumpadDecimal', key: '.', location: 3})).to.be.equal(0xFFAE);
expect(KeyboardUtil.getKeysym({code: 'NumpadDecimal', key: ',', location: 3})).to.be.equal(0xFFAC);
expect(KeyboardUtil.getKeysym({ code: 'NumpadDecimal', key: '.', location: 3 })).to.be.equal(0xFFAE);
expect(KeyboardUtil.getKeysym({ code: 'NumpadDecimal', key: ',', location: 3 })).to.be.equal(0xFFAC);
});
});
});

View File

@ -5,8 +5,8 @@ import sinon from '../vendor/sinon.js';
import Keyboard from '../core/input/keyboard.js';
import * as browser from '../core/util/browser.js';
describe('Key Event Handling', function() {
"use strict";
describe('Key Event Handling', function () {
'use strict';
// The real KeyboardEvent constructor might not work everywhere we
// want to run these tests
@ -20,8 +20,8 @@ describe('Key Event Handling', function() {
return e;
}
describe('Decode Keyboard Events', function() {
it('should decode keydown events', function(done) {
describe('Decode Keyboard Events', function () {
it('should decode keydown events', function (done) {
if (browser.isIE() || browser.isEdge()) this.skip();
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
@ -30,9 +30,9 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'a' }));
});
it('should decode keyup events', function(done) {
it('should decode keyup events', function (done) {
if (browser.isIE() || browser.isEdge()) this.skip();
let calls = 0;
const kbd = new Keyboard(document);
@ -44,18 +44,18 @@ describe('Key Event Handling', function() {
done();
}
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'a' }));
kbd._handleKeyUp(keyevent('keyup', { code: 'KeyA', key: 'a' }));
});
describe('Legacy keypress Events', function() {
it('should wait for keypress when needed', function() {
describe('Legacy keypress Events', function () {
it('should wait for keypress when needed', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', keyCode: 0x41 }));
expect(kbd.onkeyevent).to.not.have.been.called;
});
it('should decode keypress events', function(done) {
it('should decode keypress events', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x61);
@ -63,17 +63,17 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyA', charCode: 0x61}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', keyCode: 0x41 }));
kbd._handleKeyPress(keyevent('keypress', { code: 'KeyA', charCode: 0x61 }));
});
it('should ignore keypress with different code', function() {
it('should ignore keypress with different code', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyB', charCode: 0x61}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', keyCode: 0x41 }));
kbd._handleKeyPress(keyevent('keypress', { code: 'KeyB', charCode: 0x61 }));
expect(kbd.onkeyevent).to.not.have.been.called;
});
it('should handle keypress with missing code', function(done) {
it('should handle keypress with missing code', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x61);
@ -81,10 +81,10 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
kbd._handleKeyPress(keyevent('keypress', {charCode: 0x61}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', keyCode: 0x41 }));
kbd._handleKeyPress(keyevent('keypress', { charCode: 0x61 }));
});
it('should guess key if no keypress and numeric key', function(done) {
it('should guess key if no keypress and numeric key', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x32);
@ -92,9 +92,9 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'Digit2', keyCode: 0x32}));
kbd._handleKeyDown(keyevent('keydown', { code: 'Digit2', keyCode: 0x32 }));
});
it('should guess key if no keypress and alpha key', function(done) {
it('should guess key if no keypress and alpha key', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x61);
@ -102,9 +102,9 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: false}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', keyCode: 0x41, shiftKey: false }));
});
it('should guess key if no keypress and alpha key (with shift)', function(done) {
it('should guess key if no keypress and alpha key (with shift)', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x41);
@ -112,9 +112,9 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: true}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', keyCode: 0x41, shiftKey: true }));
});
it('should not guess key if no keypress and unknown key', function(done) {
it('should not guess key if no keypress and unknown key', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0);
@ -122,42 +122,42 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x09}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', keyCode: 0x09 }));
});
});
describe('suppress the right events at the right time', function() {
describe('suppress the right events at the right time', function () {
beforeEach(function () {
if (browser.isIE() || browser.isEdge()) this.skip();
});
it('should suppress anything with a valid key', function() {
it('should suppress anything with a valid key', function () {
const kbd = new Keyboard(document, {});
const evt1 = keyevent('keydown', {code: 'KeyA', key: 'a'});
const evt1 = keyevent('keydown', { code: 'KeyA', key: 'a' });
kbd._handleKeyDown(evt1);
expect(evt1.preventDefault).to.have.been.called;
const evt2 = keyevent('keyup', {code: 'KeyA', key: 'a'});
const evt2 = keyevent('keyup', { code: 'KeyA', key: 'a' });
kbd._handleKeyUp(evt2);
expect(evt2.preventDefault).to.have.been.called;
});
it('should not suppress keys without key', function() {
it('should not suppress keys without key', function () {
const kbd = new Keyboard(document, {});
const evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
const evt = keyevent('keydown', { code: 'KeyA', keyCode: 0x41 });
kbd._handleKeyDown(evt);
expect(evt.preventDefault).to.not.have.been.called;
});
it('should suppress the following keypress event', function() {
it('should suppress the following keypress event', function () {
const kbd = new Keyboard(document, {});
const evt1 = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
const evt1 = keyevent('keydown', { code: 'KeyA', keyCode: 0x41 });
kbd._handleKeyDown(evt1);
const evt2 = keyevent('keypress', {code: 'KeyA', charCode: 0x41});
const evt2 = keyevent('keypress', { code: 'KeyA', charCode: 0x41 });
kbd._handleKeyPress(evt2);
expect(evt2.preventDefault).to.have.been.called;
});
});
});
describe('Fake keyup', function() {
it('should fake keyup events for virtual keyboards', function(done) {
describe('Fake keyup', function () {
it('should fake keyup events for virtual keyboards', function (done) {
if (browser.isIE() || browser.isEdge()) this.skip();
let count = 0;
const kbd = new Keyboard(document);
@ -175,36 +175,36 @@ describe('Key Event Handling', function() {
done();
}
};
kbd._handleKeyDown(keyevent('keydown', {code: 'Unidentified', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', { code: 'Unidentified', key: 'a' }));
});
describe('iOS', function() {
describe('iOS', function () {
let origNavigator;
beforeEach(function () {
// window.navigator is a protected read-only property in many
// environments, so we need to redefine it whilst running these
// tests.
origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
origNavigator = Object.getOwnPropertyDescriptor(window, 'navigator');
if (origNavigator === undefined) {
// Object.getOwnPropertyDescriptor() doesn't work
// properly in any version of IE
this.skip();
}
Object.defineProperty(window, "navigator", {value: {}});
Object.defineProperty(window, 'navigator', { value: {} });
if (window.navigator.platform !== undefined) {
// Object.defineProperty() doesn't work properly in old
// versions of Chrome
this.skip();
}
window.navigator.platform = "iPhone 9.0";
window.navigator.platform = 'iPhone 9.0';
});
afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator);
Object.defineProperty(window, 'navigator', origNavigator);
});
it('should fake keyup events on iOS', function(done) {
it('should fake keyup events on iOS', function (done) {
if (browser.isIE() || browser.isEdge()) this.skip();
let count = 0;
const kbd = new Keyboard(document);
@ -222,16 +222,16 @@ describe('Key Event Handling', function() {
done();
}
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'a' }));
});
});
});
describe('Track Key State', function() {
describe('Track Key State', function () {
beforeEach(function () {
if (browser.isIE() || browser.isEdge()) this.skip();
});
it('should send release using the same keysym as the press', function(done) {
it('should send release using the same keysym as the press', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x61);
@ -240,10 +240,10 @@ describe('Key Event Handling', function() {
done();
}
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'b'}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'a' }));
kbd._handleKeyUp(keyevent('keyup', { code: 'KeyA', key: 'b' }));
});
it('should send the same keysym for multiple presses', function() {
it('should send the same keysym for multiple presses', function () {
let count = 0;
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
@ -252,19 +252,19 @@ describe('Key Event Handling', function() {
expect(down).to.be.equal(true);
count++;
};
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'b'}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'a' }));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'b' }));
expect(count).to.be.equal(2);
});
it('should do nothing on keyup events if no keys are down', function() {
it('should do nothing on keyup events if no keys are down', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
kbd._handleKeyUp(keyevent('keyup', { code: 'KeyA', key: 'a' }));
expect(kbd.onkeyevent).to.not.have.been.called;
});
describe('Legacy Events', function() {
it('should track keys using keyCode if no code', function(done) {
describe('Legacy Events', function () {
it('should track keys using keyCode if no code', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x61);
@ -273,18 +273,18 @@ describe('Key Event Handling', function() {
done();
}
};
kbd._handleKeyDown(keyevent('keydown', {keyCode: 65, key: 'a'}));
kbd._handleKeyUp(keyevent('keyup', {keyCode: 65, key: 'b'}));
kbd._handleKeyDown(keyevent('keydown', { keyCode: 65, key: 'a' }));
kbd._handleKeyUp(keyevent('keyup', { keyCode: 65, key: 'b' }));
});
it('should ignore compositing code', function() {
it('should ignore compositing code', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('Unidentified');
};
kbd._handleKeyDown(keyevent('keydown', {keyCode: 229, key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', { keyCode: 229, key: 'a' }));
});
it('should track keys using keyIdentifier if no code', function(done) {
it('should track keys using keyIdentifier if no code', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0x61);
@ -293,39 +293,39 @@ describe('Key Event Handling', function() {
done();
}
};
kbd._handleKeyDown(keyevent('keydown', {keyIdentifier: 'U+0041', key: 'a'}));
kbd._handleKeyUp(keyevent('keyup', {keyIdentifier: 'U+0041', key: 'b'}));
kbd._handleKeyDown(keyevent('keydown', { keyIdentifier: 'U+0041', key: 'a' }));
kbd._handleKeyUp(keyevent('keyup', { keyIdentifier: 'U+0041', key: 'b' }));
});
});
});
describe('Shuffle modifiers on macOS', function() {
describe('Shuffle modifiers on macOS', function () {
let origNavigator;
beforeEach(function () {
// window.navigator is a protected read-only property in many
// environments, so we need to redefine it whilst running these
// tests.
origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
origNavigator = Object.getOwnPropertyDescriptor(window, 'navigator');
if (origNavigator === undefined) {
// Object.getOwnPropertyDescriptor() doesn't work
// properly in any version of IE
this.skip();
}
Object.defineProperty(window, "navigator", {value: {}});
Object.defineProperty(window, 'navigator', { value: {} });
if (window.navigator.platform !== undefined) {
// Object.defineProperty() doesn't work properly in old
// versions of Chrome
this.skip();
}
window.navigator.platform = "Mac x86_64";
window.navigator.platform = 'Mac x86_64';
});
afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator);
Object.defineProperty(window, 'navigator', origNavigator);
});
it('should change Alt to AltGraph', function() {
it('should change Alt to AltGraph', function () {
let count = 0;
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
@ -340,103 +340,103 @@ describe('Key Event Handling', function() {
break;
}
};
kbd._handleKeyDown(keyevent('keydown', {code: 'AltLeft', key: 'Alt', location: 1}));
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2}));
kbd._handleKeyDown(keyevent('keydown', { code: 'AltLeft', key: 'Alt', location: 1 }));
kbd._handleKeyDown(keyevent('keydown', { code: 'AltRight', key: 'Alt', location: 2 }));
expect(count).to.be.equal(2);
});
it('should change left Super to Alt', function(done) {
it('should change left Super to Alt', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0xFFE9);
expect(code).to.be.equal('MetaLeft');
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaLeft', key: 'Meta', location: 1}));
kbd._handleKeyDown(keyevent('keydown', { code: 'MetaLeft', key: 'Meta', location: 1 }));
});
it('should change right Super to left Super', function(done) {
it('should change right Super to left Super', function (done) {
const kbd = new Keyboard(document);
kbd.onkeyevent = (keysym, code, down) => {
expect(keysym).to.be.equal(0xFFEB);
expect(code).to.be.equal('MetaRight');
done();
};
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaRight', key: 'Meta', location: 2}));
kbd._handleKeyDown(keyevent('keydown', { code: 'MetaRight', key: 'Meta', location: 2 }));
});
});
describe('Escape AltGraph on Windows', function() {
describe('Escape AltGraph on Windows', function () {
let origNavigator;
beforeEach(function () {
// window.navigator is a protected read-only property in many
// environments, so we need to redefine it whilst running these
// tests.
origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
origNavigator = Object.getOwnPropertyDescriptor(window, 'navigator');
if (origNavigator === undefined) {
// Object.getOwnPropertyDescriptor() doesn't work
// properly in any version of IE
this.skip();
}
Object.defineProperty(window, "navigator", {value: {}});
Object.defineProperty(window, 'navigator', { value: {} });
if (window.navigator.platform !== undefined) {
// Object.defineProperty() doesn't work properly in old
// versions of Chrome
this.skip();
}
window.navigator.platform = "Windows x86_64";
window.navigator.platform = 'Windows x86_64';
this.clock = sinon.useFakeTimers();
});
afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator);
Object.defineProperty(window, 'navigator', origNavigator);
this.clock.restore();
});
it('should supress ControlLeft until it knows if it is AltGr', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
kbd._handleKeyDown(keyevent('keydown', { code: 'ControlLeft', key: 'Control', location: 1 }));
expect(kbd.onkeyevent).to.not.have.been.called;
});
it('should not trigger on repeating ControlLeft', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
kbd._handleKeyDown(keyevent('keydown', { code: 'ControlLeft', key: 'Control', location: 1 }));
kbd._handleKeyDown(keyevent('keydown', { code: 'ControlLeft', key: 'Control', location: 1 }));
expect(kbd.onkeyevent).to.have.been.calledTwice;
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0xffe3, "ControlLeft", true);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0xffe3, "ControlLeft", true);
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0xffe3, 'ControlLeft', true);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0xffe3, 'ControlLeft', true);
});
it('should not supress ControlRight', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlRight', key: 'Control', location: 2}));
kbd._handleKeyDown(keyevent('keydown', { code: 'ControlRight', key: 'Control', location: 2 }));
expect(kbd.onkeyevent).to.have.been.calledOnce;
expect(kbd.onkeyevent).to.have.been.calledWith(0xffe4, "ControlRight", true);
expect(kbd.onkeyevent).to.have.been.calledWith(0xffe4, 'ControlRight', true);
});
it('should release ControlLeft after 100 ms', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
kbd._handleKeyDown(keyevent('keydown', { code: 'ControlLeft', key: 'Control', location: 1 }));
expect(kbd.onkeyevent).to.not.have.been.called;
this.clock.tick(100);
expect(kbd.onkeyevent).to.have.been.calledOnce;
expect(kbd.onkeyevent).to.have.been.calledWith(0xffe3, "ControlLeft", true);
expect(kbd.onkeyevent).to.have.been.calledWith(0xffe3, 'ControlLeft', true);
});
it('should release ControlLeft on other key press', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
kbd._handleKeyDown(keyevent('keydown', { code: 'ControlLeft', key: 'Control', location: 1 }));
expect(kbd.onkeyevent).to.not.have.been.called;
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'a' }));
expect(kbd.onkeyevent).to.have.been.calledTwice;
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0xffe3, "ControlLeft", true);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0x61, "KeyA", true);
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0xffe3, 'ControlLeft', true);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0x61, 'KeyA', true);
// Check that the timer is properly dead
kbd.onkeyevent.reset();
@ -447,14 +447,14 @@ describe('Key Event Handling', function() {
it('should release ControlLeft on other key release', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
kbd._handleKeyDown(keyevent('keydown', { code: 'KeyA', key: 'a' }));
kbd._handleKeyDown(keyevent('keydown', { code: 'ControlLeft', key: 'Control', location: 1 }));
expect(kbd.onkeyevent).to.have.been.calledOnce;
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0x61, "KeyA", true);
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0x61, 'KeyA', true);
kbd._handleKeyUp(keyevent('keyup', { code: 'KeyA', key: 'a' }));
expect(kbd.onkeyevent).to.have.been.calledThrice;
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0xffe3, "ControlLeft", true);
expect(kbd.onkeyevent.thirdCall).to.have.been.calledWith(0x61, "KeyA", false);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0xffe3, 'ControlLeft', true);
expect(kbd.onkeyevent.thirdCall).to.have.been.calledWith(0x61, 'KeyA', false);
// Check that the timer is properly dead
kbd.onkeyevent.reset();
@ -465,9 +465,13 @@ describe('Key Event Handling', function() {
it('should generate AltGraph for quick Ctrl+Alt sequence', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()}));
kbd._handleKeyDown(keyevent('keydown', {
code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()
}));
this.clock.tick(20);
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2, timeStamp: Date.now()}));
kbd._handleKeyDown(keyevent('keydown', {
code: 'AltRight', key: 'Alt', location: 2, timeStamp: Date.now()
}));
expect(kbd.onkeyevent).to.have.been.calledOnce;
expect(kbd.onkeyevent).to.have.been.calledWith(0xfe03, 'AltRight', true);
@ -480,12 +484,16 @@ describe('Key Event Handling', function() {
it('should generate Ctrl, Alt for slow Ctrl+Alt sequence', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()}));
kbd._handleKeyDown(keyevent('keydown', {
code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()
}));
this.clock.tick(60);
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2, timeStamp: Date.now()}));
kbd._handleKeyDown(keyevent('keydown', {
code: 'AltRight', key: 'Alt', location: 2, timeStamp: Date.now()
}));
expect(kbd.onkeyevent).to.have.been.calledTwice;
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0xffe3, "ControlLeft", true);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0xffea, "AltRight", true);
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0xffe3, 'ControlLeft', true);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0xffea, 'AltRight', true);
// Check that the timer is properly dead
kbd.onkeyevent.reset();
@ -496,7 +504,7 @@ describe('Key Event Handling', function() {
it('should pass through single Alt', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'Alt', location: 2}));
kbd._handleKeyDown(keyevent('keydown', { code: 'AltRight', key: 'Alt', location: 2 }));
expect(kbd.onkeyevent).to.have.been.calledOnce;
expect(kbd.onkeyevent).to.have.been.calledWith(0xffea, 'AltRight', true);
});
@ -504,7 +512,7 @@ describe('Key Event Handling', function() {
it('should pass through single AltGr', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'AltGraph', location: 2}));
kbd._handleKeyDown(keyevent('keydown', { code: 'AltRight', key: 'AltGraph', location: 2 }));
expect(kbd.onkeyevent).to.have.been.calledOnce;
expect(kbd.onkeyevent).to.have.been.calledWith(0xfe03, 'AltRight', true);
});

View File

@ -1,8 +1,8 @@
const expect = chai.expect;
import { l10n } from '../app/localization.js';
describe('Localization', function() {
"use strict";
describe('Localization', function () {
'use strict';
describe('language selection', function () {
let origNavigator;
@ -10,14 +10,14 @@ describe('Localization', function() {
// window.navigator is a protected read-only property in many
// environments, so we need to redefine it whilst running these
// tests.
origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
origNavigator = Object.getOwnPropertyDescriptor(window, 'navigator');
if (origNavigator === undefined) {
// Object.getOwnPropertyDescriptor() doesn't work
// properly in any version of IE
this.skip();
}
Object.defineProperty(window, "navigator", {value: {}});
Object.defineProperty(window, 'navigator', { value: {} });
if (window.navigator.languages !== undefined) {
// Object.defineProperty() doesn't work properly in old
// versions of Chrome
@ -27,45 +27,45 @@ describe('Localization', function() {
window.navigator.languages = [];
});
afterEach(function () {
Object.defineProperty(window, "navigator", origNavigator);
Object.defineProperty(window, 'navigator', origNavigator);
});
it('should use English by default', function() {
it('should use English by default', function () {
expect(l10n.language).to.equal('en');
});
it('should use English if no user language matches', function() {
window.navigator.languages = ["nl", "de"];
l10n.setup(["es", "fr"]);
it('should use English if no user language matches', function () {
window.navigator.languages = ['nl', 'de'];
l10n.setup(['es', 'fr']);
expect(l10n.language).to.equal('en');
});
it('should use the most preferred user language', function() {
window.navigator.languages = ["nl", "de", "fr"];
l10n.setup(["es", "fr", "de"]);
it('should use the most preferred user language', function () {
window.navigator.languages = ['nl', 'de', 'fr'];
l10n.setup(['es', 'fr', 'de']);
expect(l10n.language).to.equal('de');
});
it('should prefer sub-languages languages', function() {
window.navigator.languages = ["pt-BR"];
l10n.setup(["pt", "pt-BR"]);
it('should prefer sub-languages languages', function () {
window.navigator.languages = ['pt-BR'];
l10n.setup(['pt', 'pt-BR']);
expect(l10n.language).to.equal('pt-BR');
});
it('should fall back to language "parents"', function() {
window.navigator.languages = ["pt-BR"];
l10n.setup(["fr", "pt", "de"]);
it('should fall back to language "parents"', function () {
window.navigator.languages = ['pt-BR'];
l10n.setup(['fr', 'pt', 'de']);
expect(l10n.language).to.equal('pt');
});
it('should not use specific language when user asks for a generic language', function() {
window.navigator.languages = ["pt", "de"];
l10n.setup(["fr", "pt-BR", "de"]);
it('should not use specific language when user asks for a generic language', function () {
window.navigator.languages = ['pt', 'de'];
l10n.setup(['fr', 'pt-BR', 'de']);
expect(l10n.language).to.equal('de');
});
it('should handle underscore as a separator', function() {
window.navigator.languages = ["pt-BR"];
l10n.setup(["pt_BR"]);
it('should handle underscore as a separator', function () {
window.navigator.languages = ['pt-BR'];
l10n.setup(['pt_BR']);
expect(l10n.language).to.equal('pt_BR');
});
it('should handle difference in case', function() {
window.navigator.languages = ["pt-br"];
l10n.setup(["pt-BR"]);
it('should handle difference in case', function () {
window.navigator.languages = ['pt-br'];
l10n.setup(['pt-BR']);
expect(l10n.language).to.equal('pt-BR');
});
});

View File

@ -5,15 +5,18 @@ import sinon from '../vendor/sinon.js';
import Mouse from '../core/input/mouse.js';
import * as eventUtils from '../core/util/events.js';
describe('Mouse Event Handling', function() {
"use strict";
describe('Mouse Event Handling', function () {
'use strict';
sinon.stub(eventUtils, 'setCapture');
// This function is only used on target (the canvas)
// and for these tests we can assume that the canvas is 100x100
// located at coordinates 10x10
sinon.stub(Element.prototype, 'getBoundingClientRect').returns(
{left: 10, right: 110, top: 10, bottom: 110, width: 100, height: 100});
{
left: 10, right: 110, top: 10, bottom: 110, width: 100, height: 100
}
);
const target = document.createElement('canvas');
// The real constructors might not work everywhere we
@ -29,8 +32,8 @@ describe('Mouse Event Handling', function() {
};
const touchevent = mouseevent;
describe('Decode Mouse Events', function() {
it('should decode mousedown events', function(done) {
describe('Decode Mouse Events', function () {
it('should decode mousedown events', function (done) {
const mouse = new Mouse(target);
mouse.onmousebutton = (x, y, down, bmask) => {
expect(bmask).to.be.equal(0x01);
@ -39,7 +42,7 @@ describe('Mouse Event Handling', function() {
};
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
});
it('should decode mouseup events', function(done) {
it('should decode mouseup events', function (done) {
let calls = 0;
const mouse = new Mouse(target);
mouse.onmousebutton = (x, y, down, bmask) => {
@ -52,7 +55,7 @@ describe('Mouse Event Handling', function() {
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
mouse._handleMouseUp(mouseevent('mouseup', { button: '0x01' }));
});
it('should decode mousemove events', function(done) {
it('should decode mousemove events', function (done) {
const mouse = new Mouse(target);
mouse.onmousemove = (x, y) => {
// Note that target relative coordinates are sent
@ -63,12 +66,12 @@ describe('Mouse Event Handling', function() {
mouse._handleMouseMove(mouseevent('mousemove',
{ clientX: 50, clientY: 20 }));
});
it('should decode mousewheel events', function(done) {
it('should decode mousewheel events', function (done) {
let calls = 0;
const mouse = new Mouse(target);
mouse.onmousebutton = (x, y, down, bmask) => {
calls++;
expect(bmask).to.be.equal(1<<6);
expect(bmask).to.be.equal(1 << 6);
if (calls === 1) {
expect(down).to.be.equal(1);
} else if (calls === 2) {
@ -77,17 +80,19 @@ describe('Mouse Event Handling', function() {
}
};
mouse._handleMouseWheel(mouseevent('mousewheel',
{ deltaX: 50, deltaY: 0,
deltaMode: 0}));
{
deltaX: 50,
deltaY: 0,
deltaMode: 0
}));
});
});
describe('Double-click for Touch', function() {
describe('Double-click for Touch', function () {
beforeEach(function () { this.clock = sinon.useFakeTimers(); });
afterEach(function () { this.clock.restore(); });
it('should use same pos for 2nd tap if close enough', function(done) {
it('should use same pos for 2nd tap if close enough', function (done) {
let calls = 0;
const mouse = new Mouse(target);
mouse.onmousebutton = (x, y, down, bmask) => {
@ -106,19 +111,23 @@ describe('Mouse Event Handling', function() {
// touch events are sent in an array of events
// with one item for each touch point
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 78, clientY: 46 }]}));
'touchstart', { touches: [{ clientX: 78, clientY: 46 }] }
));
this.clock.tick(10);
mouse._handleMouseUp(touchevent(
'touchend', { touches: [{ clientX: 79, clientY: 45 }]}));
'touchend', { touches: [{ clientX: 79, clientY: 45 }] }
));
this.clock.tick(200);
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 67, clientY: 35 }]}));
'touchstart', { touches: [{ clientX: 67, clientY: 35 }] }
));
this.clock.tick(10);
mouse._handleMouseUp(touchevent(
'touchend', { touches: [{ clientX: 66, clientY: 36 }]}));
'touchend', { touches: [{ clientX: 66, clientY: 36 }] }
));
});
it('should not modify 2nd tap pos if far apart', function(done) {
it('should not modify 2nd tap pos if far apart', function (done) {
let calls = 0;
const mouse = new Mouse(target);
mouse.onmousebutton = (x, y, down, bmask) => {
@ -135,19 +144,23 @@ describe('Mouse Event Handling', function() {
}
};
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 78, clientY: 46 }]}));
'touchstart', { touches: [{ clientX: 78, clientY: 46 }] }
));
this.clock.tick(10);
mouse._handleMouseUp(touchevent(
'touchend', { touches: [{ clientX: 79, clientY: 45 }]}));
'touchend', { touches: [{ clientX: 79, clientY: 45 }] }
));
this.clock.tick(200);
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 57, clientY: 35 }]}));
'touchstart', { touches: [{ clientX: 57, clientY: 35 }] }
));
this.clock.tick(10);
mouse._handleMouseUp(touchevent(
'touchend', { touches: [{ clientX: 56, clientY: 36 }]}));
'touchend', { touches: [{ clientX: 56, clientY: 36 }] }
));
});
it('should not modify 2nd tap pos if not soon enough', function(done) {
it('should not modify 2nd tap pos if not soon enough', function (done) {
let calls = 0;
const mouse = new Mouse(target);
mouse.onmousebutton = (x, y, down, bmask) => {
@ -164,19 +177,23 @@ describe('Mouse Event Handling', function() {
}
};
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 78, clientY: 46 }]}));
'touchstart', { touches: [{ clientX: 78, clientY: 46 }] }
));
this.clock.tick(10);
mouse._handleMouseUp(touchevent(
'touchend', { touches: [{ clientX: 79, clientY: 45 }]}));
'touchend', { touches: [{ clientX: 79, clientY: 45 }] }
));
this.clock.tick(500);
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 67, clientY: 35 }]}));
'touchstart', { touches: [{ clientX: 67, clientY: 35 }] }
));
this.clock.tick(10);
mouse._handleMouseUp(touchevent(
'touchend', { touches: [{ clientX: 66, clientY: 36 }]}));
'touchend', { touches: [{ clientX: 66, clientY: 36 }] }
));
});
it('should not modify 2nd tap pos if not touch', function(done) {
it('should not modify 2nd tap pos if not touch', function (done) {
let calls = 0;
const mouse = new Mouse(target);
mouse.onmousebutton = (x, y, down, bmask) => {
@ -193,22 +210,24 @@ describe('Mouse Event Handling', function() {
}
};
mouse._handleMouseDown(mouseevent(
'mousedown', { button: '0x01', clientX: 78, clientY: 46 }));
'mousedown', { button: '0x01', clientX: 78, clientY: 46 }
));
this.clock.tick(10);
mouse._handleMouseUp(mouseevent(
'mouseup', { button: '0x01', clientX: 79, clientY: 45 }));
'mouseup', { button: '0x01', clientX: 79, clientY: 45 }
));
this.clock.tick(200);
mouse._handleMouseDown(mouseevent(
'mousedown', { button: '0x01', clientX: 67, clientY: 35 }));
'mousedown', { button: '0x01', clientX: 67, clientY: 35 }
));
this.clock.tick(10);
mouse._handleMouseUp(mouseevent(
'mouseup', { button: '0x01', clientX: 66, clientY: 36 }));
'mouseup', { button: '0x01', clientX: 66, clientY: 36 }
));
});
});
});
describe('Accumulate mouse wheel events with small delta', function() {
describe('Accumulate mouse wheel events with small delta', function () {
beforeEach(function () { this.clock = sinon.useFakeTimers(); });
afterEach(function () { this.clock.restore(); });
@ -217,27 +236,51 @@ describe('Mouse Event Handling', function() {
mouse.onmousebutton = sinon.spy();
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 4, deltaY: 0, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 4,
deltaY: 0,
deltaMode: 0
}
));
this.clock.tick(10);
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 4, deltaY: 0, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 4,
deltaY: 0,
deltaMode: 0
}
));
// threshold is 10
expect(mouse._accumulatedWheelDeltaX).to.be.equal(8);
this.clock.tick(10);
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 4, deltaY: 0, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 4,
deltaY: 0,
deltaMode: 0
}
));
expect(mouse.onmousebutton).to.have.callCount(2); // mouse down and up
this.clock.tick(10);
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 4, deltaY: 9, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 4,
deltaY: 9,
deltaMode: 0
}
));
expect(mouse._accumulatedWheelDeltaX).to.be.equal(4);
expect(mouse._accumulatedWheelDeltaY).to.be.equal(9);
@ -250,16 +293,34 @@ describe('Mouse Event Handling', function() {
mouse.onmousebutton = sinon.spy();
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 11, deltaY: 0, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 11,
deltaY: 0,
deltaMode: 0
}
));
this.clock.tick(10);
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 0, deltaY: 70, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 0,
deltaY: 70,
deltaMode: 0
}
));
this.clock.tick(10);
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 400, deltaY: 400, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 400,
deltaY: 400,
deltaMode: 0
}
));
expect(mouse.onmousebutton).to.have.callCount(8); // mouse down and up
});
@ -269,8 +330,14 @@ describe('Mouse Event Handling', function() {
mouse.onmousebutton = sinon.spy();
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 1, deltaY: 0, deltaMode: 0 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 1,
deltaY: 0,
deltaMode: 0
}
));
this.clock.tick(51); // timeout on 50 ms
expect(mouse.onmousebutton).to.have.callCount(2); // mouse down and up
@ -281,17 +348,28 @@ describe('Mouse Event Handling', function() {
mouse.onmousebutton = sinon.spy();
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 0, deltaY: 2, deltaMode: 1 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 0,
deltaY: 2,
deltaMode: 1
}
));
this.clock.tick(10);
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
deltaX: 1, deltaY: 0, deltaMode: 2 }));
'mousewheel', {
clientX: 18,
clientY: 40,
deltaX: 1,
deltaY: 0,
deltaMode: 2
}
));
expect(mouse.onmousebutton).to.have.callCount(4); // mouse down and up
});
});
});

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,8 @@ import * as Log from '../core/util/logging.js';
import sinon from '../vendor/sinon.js';
describe('Utils', function() {
"use strict";
describe('Utils', function () {
'use strict';
describe('logging functions', function () {
beforeEach(function () {

View File

@ -5,8 +5,8 @@ import FakeWebSocket from './fake.websocket.js';
import sinon from '../vendor/sinon.js';
describe('Websock', function() {
"use strict";
describe('Websock', function () {
'use strict';
describe('Queue methods', function () {
let sock;
@ -26,7 +26,7 @@ describe('Websock', function() {
expect(sock.rQlen()).to.equal(RQ_TEMPLATE.length);
});
it("should return the proper length if we read some from the receive queue", function () {
it('should return the proper length if we read some from the receive queue', function () {
sock.set_rQi(1);
expect(sock.rQlen()).to.equal(RQ_TEMPLATE.length - 1);
@ -63,10 +63,10 @@ describe('Websock', function() {
describe('rQshift32', function () {
it('should pop four bytes from the receive queue and return a single number', function () {
const bef_len = sock.rQlen();
const expected = (RQ_TEMPLATE[0] << 24) +
(RQ_TEMPLATE[1] << 16) +
(RQ_TEMPLATE[2] << 8) +
RQ_TEMPLATE[3];
const expected = (RQ_TEMPLATE[0] << 24)
+ (RQ_TEMPLATE[1] << 16)
+ (RQ_TEMPLATE[2] << 8)
+ RQ_TEMPLATE[3];
expect(sock.rQshift32()).to.equal(expected);
expect(sock.rQlen()).to.equal(bef_len - 4);
});
@ -90,7 +90,7 @@ describe('Websock', function() {
it('should be able to handle very large strings', function () {
const BIG_LEN = 500000;
const RQ_BIG = new Uint8Array(BIG_LEN);
let expected = "";
let expected = '';
let letterCode = 'a'.charCodeAt(0);
for (let i = 0; i < BIG_LEN; i++) {
RQ_BIG[i] = letterCode;
@ -197,7 +197,7 @@ describe('Websock', function() {
it('should actually send on the websocket', function () {
sock._websocket.bufferedAmount = 8;
sock._websocket.readyState = WebSocket.OPEN
sock._websocket.readyState = WebSocket.OPEN;
sock._sQ = new Uint8Array([1, 2, 3]);
sock._sQlen = 3;
const encoded = sock._encode_message();
@ -240,7 +240,7 @@ describe('Websock', function() {
});
it('should call send after converting the string to an array', function () {
sock.send_string("\x01\x02\x03");
sock.send_string('\x01\x02\x03');
expect(sock.send).to.have.been.calledWith([1, 2, 3]);
});
});
@ -266,7 +266,7 @@ describe('Websock', function() {
});
describe('opening', function () {
it('should pick the correct protocols if none are given' , function () {
it('should pick the correct protocols if none are given', function () {
});

View File

@ -6,31 +6,30 @@ import * as WebUtil from '../app/webutil.js';
import sinon from '../vendor/sinon.js';
describe('WebUtil', function() {
"use strict";
describe('WebUtil', function () {
'use strict';
describe('settings', function () {
describe('localStorage', function() {
describe('localStorage', function () {
let chrome = window.chrome;
before(function() {
before(function () {
chrome = window.chrome;
window.chrome = null;
});
after(function() {
after(function () {
window.chrome = chrome;
});
let origLocalStorage;
beforeEach(function() {
origLocalStorage = Object.getOwnPropertyDescriptor(window, "localStorage");
beforeEach(function () {
origLocalStorage = Object.getOwnPropertyDescriptor(window, 'localStorage');
if (origLocalStorage === undefined) {
// Object.getOwnPropertyDescriptor() doesn't work
// properly in any version of IE
this.skip();
}
Object.defineProperty(window, "localStorage", {value: {}});
Object.defineProperty(window, 'localStorage', { value: {} });
if (window.localStorage.setItem !== undefined) {
// Object.defineProperty() doesn't work properly in old
// versions of Chrome
@ -43,56 +42,56 @@ describe('WebUtil', function() {
WebUtil.initSettings();
});
afterEach(function() {
Object.defineProperty(window, "localStorage", origLocalStorage);
afterEach(function () {
Object.defineProperty(window, 'localStorage', origLocalStorage);
});
describe('writeSetting', function() {
it('should save the setting value to local storage', function() {
describe('writeSetting', function () {
it('should save the setting value to local storage', function () {
WebUtil.writeSetting('test', 'value');
expect(window.localStorage.setItem).to.have.been.calledWithExactly('test', 'value');
expect(WebUtil.readSetting('test')).to.equal('value');
});
});
describe('setSetting', function() {
it('should update the setting but not save to local storage', function() {
describe('setSetting', function () {
it('should update the setting but not save to local storage', function () {
WebUtil.setSetting('test', 'value');
expect(window.localStorage.setItem).to.not.have.been.called;
expect(WebUtil.readSetting('test')).to.equal('value');
});
});
describe('readSetting', function() {
it('should read the setting value from local storage', function() {
describe('readSetting', function () {
it('should read the setting value from local storage', function () {
localStorage.getItem.returns('value');
expect(WebUtil.readSetting('test')).to.equal('value');
});
it('should return the default value when not in local storage', function() {
it('should return the default value when not in local storage', function () {
expect(WebUtil.readSetting('test', 'default')).to.equal('default');
});
it('should return the cached value even if local storage changed', function() {
it('should return the cached value even if local storage changed', function () {
localStorage.getItem.returns('value');
expect(WebUtil.readSetting('test')).to.equal('value');
localStorage.getItem.returns('something else');
expect(WebUtil.readSetting('test')).to.equal('value');
});
it('should cache the value even if it is not initially in local storage', function() {
it('should cache the value even if it is not initially in local storage', function () {
expect(WebUtil.readSetting('test')).to.be.null;
localStorage.getItem.returns('value');
expect(WebUtil.readSetting('test')).to.be.null;
});
it('should return the default value always if the first read was not in local storage', function() {
it('should return the default value always if the first read was not in local storage', function () {
expect(WebUtil.readSetting('test', 'default')).to.equal('default');
localStorage.getItem.returns('value');
expect(WebUtil.readSetting('test', 'another default')).to.equal('another default');
});
it('should return the last local written value', function() {
it('should return the last local written value', function () {
localStorage.getItem.returns('value');
expect(WebUtil.readSetting('test')).to.equal('value');
WebUtil.writeSetting('test', 'something else');
@ -101,72 +100,72 @@ describe('WebUtil', function() {
});
// this doesn't appear to be used anywhere
describe('eraseSetting', function() {
it('should remove the setting from local storage', function() {
describe('eraseSetting', function () {
it('should remove the setting from local storage', function () {
WebUtil.eraseSetting('test');
expect(window.localStorage.removeItem).to.have.been.calledWithExactly('test');
});
});
});
describe('chrome.storage', function() {
describe('chrome.storage', function () {
let chrome = window.chrome;
let settings = {};
before(function() {
before(function () {
chrome = window.chrome;
window.chrome = {
storage: {
sync: {
get(cb){ cb(settings); },
set(){},
get(cb) { cb(settings); },
set() {},
remove() {}
}
}
};
});
after(function() {
after(function () {
window.chrome = chrome;
});
const csSandbox = sinon.createSandbox();
beforeEach(function() {
beforeEach(function () {
settings = {};
csSandbox.spy(window.chrome.storage.sync, 'set');
csSandbox.spy(window.chrome.storage.sync, 'remove');
WebUtil.initSettings();
});
afterEach(function() {
afterEach(function () {
csSandbox.restore();
});
describe('writeSetting', function() {
it('should save the setting value to chrome storage', function() {
describe('writeSetting', function () {
it('should save the setting value to chrome storage', function () {
WebUtil.writeSetting('test', 'value');
expect(window.chrome.storage.sync.set).to.have.been.calledWithExactly(sinon.match({ test: 'value' }));
expect(WebUtil.readSetting('test')).to.equal('value');
});
});
describe('setSetting', function() {
it('should update the setting but not save to chrome storage', function() {
describe('setSetting', function () {
it('should update the setting but not save to chrome storage', function () {
WebUtil.setSetting('test', 'value');
expect(window.chrome.storage.sync.set).to.not.have.been.called;
expect(WebUtil.readSetting('test')).to.equal('value');
});
});
describe('readSetting', function() {
it('should read the setting value from chrome storage', function() {
describe('readSetting', function () {
it('should read the setting value from chrome storage', function () {
settings.test = 'value';
expect(WebUtil.readSetting('test')).to.equal('value');
});
it('should return the default value when not in chrome storage', function() {
it('should return the default value when not in chrome storage', function () {
expect(WebUtil.readSetting('test', 'default')).to.equal('default');
});
it('should return the last local written value', function() {
it('should return the last local written value', function () {
settings.test = 'value';
expect(WebUtil.readSetting('test')).to.equal('value');
WebUtil.writeSetting('test', 'something else');
@ -175,8 +174,8 @@ describe('WebUtil', function() {
});
// this doesn't appear to be used anywhere
describe('eraseSetting', function() {
it('should remove the setting from chrome storage', function() {
describe('eraseSetting', function () {
it('should remove the setting from chrome storage', function () {
WebUtil.eraseSetting('test');
expect(window.chrome.storage.sync.remove).to.have.been.calledWithExactly('test');
});

View File

@ -6,7 +6,7 @@
* Licensed under MPL 2.0 (see LICENSE.txt)
*/
"use strict";
'use strict';
const fs = require('fs');
@ -15,12 +15,12 @@ let filename;
for (let i = 2; i < process.argv.length; ++i) {
switch (process.argv[i]) {
case "--help":
case "-h":
case '--help':
case '-h':
show_help = true;
break;
case "--file":
case "-f":
case '--file':
case '-f':
default:
filename = process.argv[i];
}
@ -28,14 +28,14 @@ for (let i = 2; i < process.argv.length; ++i) {
if (!filename) {
show_help = true;
console.log("Error: No filename specified\n");
console.log('Error: No filename specified\n');
}
if (show_help) {
console.log("Parses a *nix keysymdef.h to generate Unicode code point mappings");
console.log("Usage: node parse.js [options] filename:");
console.log(" -h [ --help ] Produce this help message");
console.log(" filename The keysymdef.h file to parse");
console.log('Parses a *nix keysymdef.h to generate Unicode code point mappings');
console.log('Usage: node parse.js [options] filename:');
console.log(' -h [ --help ] Produce this help message');
console.log(' filename The keysymdef.h file to parse');
process.exit(0);
}
@ -50,7 +50,7 @@ const codepoints = {};
for (let i = 0; i < arr.length; ++i) {
const result = re.exec(arr[i]);
if (result){
if (result) {
const keyname = result[1];
const keysym = parseInt(result[2], 16);
const remainder = result[3];
@ -59,31 +59,30 @@ for (let i = 0; i < arr.length; ++i) {
if (unicodeRes) {
const unicode = parseInt(unicodeRes[1], 16);
// The first entry is the preferred one
if (!codepoints[unicode]){
if (!codepoints[unicode]) {
codepoints[unicode] = { keysym: keysym, name: keyname };
}
}
}
}
let out =
"/*\n" +
" * Mapping from Unicode codepoints to X11/RFB keysyms\n" +
" *\n" +
" * This file was automatically generated from keysymdef.h\n" +
" * DO NOT EDIT!\n" +
" */\n" +
"\n" +
"/* Functions at the bottom */\n" +
"\n" +
"const codepoints = {\n";
let out = '/*\n'
+ ' * Mapping from Unicode codepoints to X11/RFB keysyms\n'
+ ' *\n'
+ ' * This file was automatically generated from keysymdef.h\n'
+ ' * DO NOT EDIT!\n'
+ ' */\n'
+ '\n'
+ '/* Functions at the bottom */\n'
+ '\n'
+ 'const codepoints = {\n';
function toHex(num) {
let s = num.toString(16);
if (s.length < 4) {
s = ("0000" + s).slice(-4);
s = ('0000' + s).slice(-4);
}
return "0x" + s;
return '0x' + s;
}
for (let codepoint in codepoints) {
@ -99,30 +98,30 @@ for (let codepoint in codepoints) {
continue;
}
out += " " + toHex(codepoint) + ": " +
toHex(codepoints[codepoint].keysym) +
", // XK_" + codepoints[codepoint].name + "\n";
out += ' ' + toHex(codepoint) + ': '
+ toHex(codepoints[codepoint].keysym)
+ ', // XK_' + codepoints[codepoint].name + '\n';
}
out +=
"};\n" +
"\n" +
"export default {\n" +
" lookup(u) {\n" +
" // Latin-1 is one-to-one mapping\n" +
" if ((u >= 0x20) && (u <= 0xff)) {\n" +
" return u;\n" +
" }\n" +
"\n" +
" // Lookup table (fairly random)\n" +
" const keysym = codepoints[u];\n" +
" if (keysym !== undefined) {\n" +
" return keysym;\n" +
" }\n" +
"\n" +
" // General mapping as final fallback\n" +
" return 0x01000000 | u;\n" +
" },\n" +
"};";
out
+= '};\n'
+ '\n'
+ 'export default {\n'
+ ' lookup(u) {\n'
+ ' // Latin-1 is one-to-one mapping\n'
+ ' if ((u >= 0x20) && (u <= 0xff)) {\n'
+ ' return u;\n'
+ ' }\n'
+ '\n'
+ ' // Lookup table (fairly random)\n'
+ ' const keysym = codepoints[u];\n'
+ ' if (keysym !== undefined) {\n'
+ ' return keysym;\n'
+ ' }\n'
+ '\n'
+ ' // General mapping as final fallback\n'
+ ' return 0x01000000 | u;\n'
+ ' },\n'
+ '};';
console.log(out);

View File

@ -51,7 +51,7 @@ function promisify(original) {
resolve(value);
}));
});
}
};
}
const readFile = promisify(fs.readFile);
@ -84,7 +84,7 @@ function walkDir(base_path, cb, filter) {
});
}
function transform_html (legacy_scripts, only_legacy) {
function transform_html(legacy_scripts, only_legacy) {
// write out the modified vnc.html file that works with the bundle
const src_html_path = path.resolve(__dirname, '..', 'vnc.html');
const out_html_path = path.resolve(paths.out_dir_base, 'vnc.html');
@ -101,7 +101,7 @@ function transform_html (legacy_scripts, only_legacy) {
if (only_legacy) {
// Only legacy version, so include things directly
for (let i = 0;i < legacy_scripts.length;i++) {
for (let i = 0; i < legacy_scripts.length; i++) {
new_script += ` <script src="${legacy_scripts[i]}"></script>\n`;
}
} else {
@ -140,7 +140,7 @@ function transform_html (legacy_scripts, only_legacy) {
function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
if (!import_format) {
throw new Error("you must specify an import format to generate compiled noVNC libraries");
throw new Error('you must specify an import format to generate compiled noVNC libraries');
} else if (!SUPPORTED_FORMATS.has(import_format)) {
throw new Error(`unsupported output format "${import_format}" for import/export -- only ${Array.from(SUPPORTED_FORMATS)} are supported`);
}
@ -182,7 +182,7 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
const out_path = path.join(out_path_base, path.relative(in_path_base, filename));
const legacy_path = path.join(legacy_path_base, path.relative(in_path_base, filename));
if(path.extname(filename) !== '.js') {
if (path.extname(filename) !== '.js') {
if (!js_only) {
console.log(`Writing ${out_path}`);
return copy(filename, out_path);
@ -199,7 +199,7 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
.then(() => {
console.log(`Writing ${out_path}`);
return copy(filename, out_path);
})
});
})
.then(() => ensureDir(path.dirname(legacy_path)))
.then(() => {
@ -214,16 +214,18 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
// Adjust for the fact that we move the core files relative
// to the vendor directory
if (vendor_rewrite) {
opts.plugins.push(["import-redirect",
{"root": legacy_path_base,
"redirect": { "vendor/(.+)": "./vendor/$1"}}]);
opts.plugins.push(['import-redirect',
{
root: legacy_path_base,
redirect: { 'vendor/(.+)': './vendor/$1' }
}]);
}
return babelTransformFile(filename, opts)
.then((res) => {
console.log(`Writing ${legacy_path}`);
const {map} = res;
let {code} = res;
const { map } = res;
let { code } = res;
if (source_maps === true) {
// append URL for external source map
code += `\n//# sourceMappingURL=${path.basename(legacy_path)}.map\n`;
@ -279,14 +281,13 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
})
.then(() => {
if (!helper.removeModules) return;
console.log(`Cleaning up temporary files...`);
console.log('Cleaning up temporary files...');
return Promise.all(outFiles.map((filepath) => {
unlink(filepath)
.then(() => {
// Try to clean up any empty directories if this
// was the last file in there
const rmdir_r = dir =>
rmdir(dir)
const rmdir_r = dir => rmdir(dir)
.then(() => rmdir_r(path.dirname(dir)))
.catch(() => {
// Assume the error was ENOTEMPTY and ignore it

View File

@ -12,13 +12,13 @@ function promisify(original) {
resolve(value);
}));
});
}
};
}
const writeFile = promisify(fs.writeFile);
module.exports = {
'amd': {
amd: {
appWriter: (base_out_path, script_base_path, out_path) => {
// setup for requirejs
const ui_path = path.relative(base_out_path,
@ -27,16 +27,16 @@ module.exports = {
.then(() => {
console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
const require_path = path.relative(base_out_path,
path.join(script_base_path, 'require.js'))
return [ require_path ];
path.join(script_base_path, 'require.js'));
return [require_path];
});
},
noCopyOverride: () => {},
},
'commonjs': {
commonjs: {
optionsOverride: (opts) => {
// CommonJS supports properly shifting the default export to work as normal
opts.plugins.unshift("add-module-exports");
opts.plugins.unshift('add-module-exports');
},
appWriter: (base_out_path, script_base_path, out_path) => {
const browserify = require('browserify');
@ -48,7 +48,7 @@ module.exports = {
noCopyOverride: () => {},
removeModules: true,
},
'systemjs': {
systemjs: {
appWriter: (base_out_path, script_base_path, out_path) => {
const ui_path = path.relative(base_out_path,
path.join(script_base_path, 'app', 'ui.js'));
@ -57,20 +57,20 @@ module.exports = {
console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
// FIXME: Should probably be in the legacy directory
const promise_path = path.relative(base_out_path,
path.join(base_out_path, 'vendor', 'promise.js'))
path.join(base_out_path, 'vendor', 'promise.js'));
const systemjs_path = path.relative(base_out_path,
path.join(script_base_path, 'system-production.js'))
return [ promise_path, systemjs_path ];
path.join(script_base_path, 'system-production.js'));
return [promise_path, systemjs_path];
});
},
noCopyOverride: (paths, no_copy_files) => {
no_copy_files.delete(path.join(paths.vendor, 'promise.js'));
},
},
'umd': {
umd: {
optionsOverride: (opts) => {
// umd supports properly shifting the default export to work as normal
opts.plugins.unshift("add-module-exports");
opts.plugins.unshift('add-module-exports');
},
},
}
};