index.cjs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var base = {
  4. 8: "Backspace",
  5. 9: "Tab",
  6. 10: "Enter",
  7. 12: "NumLock",
  8. 13: "Enter",
  9. 16: "Shift",
  10. 17: "Control",
  11. 18: "Alt",
  12. 20: "CapsLock",
  13. 27: "Escape",
  14. 32: " ",
  15. 33: "PageUp",
  16. 34: "PageDown",
  17. 35: "End",
  18. 36: "Home",
  19. 37: "ArrowLeft",
  20. 38: "ArrowUp",
  21. 39: "ArrowRight",
  22. 40: "ArrowDown",
  23. 44: "PrintScreen",
  24. 45: "Insert",
  25. 46: "Delete",
  26. 59: ";",
  27. 61: "=",
  28. 91: "Meta",
  29. 92: "Meta",
  30. 106: "*",
  31. 107: "+",
  32. 108: ",",
  33. 109: "-",
  34. 110: ".",
  35. 111: "/",
  36. 144: "NumLock",
  37. 145: "ScrollLock",
  38. 160: "Shift",
  39. 161: "Shift",
  40. 162: "Control",
  41. 163: "Control",
  42. 164: "Alt",
  43. 165: "Alt",
  44. 173: "-",
  45. 186: ";",
  46. 187: "=",
  47. 188: ",",
  48. 189: "-",
  49. 190: ".",
  50. 191: "/",
  51. 192: "`",
  52. 219: "[",
  53. 220: "\\",
  54. 221: "]",
  55. 222: "'",
  56. 229: "q"
  57. };
  58. var shift = {
  59. 48: ")",
  60. 49: "!",
  61. 50: "@",
  62. 51: "#",
  63. 52: "$",
  64. 53: "%",
  65. 54: "^",
  66. 55: "&",
  67. 56: "*",
  68. 57: "(",
  69. 59: ":",
  70. 61: "+",
  71. 173: "_",
  72. 186: ":",
  73. 187: "+",
  74. 188: "<",
  75. 189: "_",
  76. 190: ">",
  77. 191: "?",
  78. 192: "~",
  79. 219: "{",
  80. 220: "|",
  81. 221: "}",
  82. 222: "\"",
  83. 229: "Q"
  84. };
  85. var chrome = typeof navigator != "undefined" && /Chrome\/(\d+)/.exec(navigator.userAgent);
  86. var safari = typeof navigator != "undefined" && /Apple Computer/.test(navigator.vendor);
  87. var gecko = typeof navigator != "undefined" && /Gecko\/\d+/.test(navigator.userAgent);
  88. var mac = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
  89. var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
  90. var brokenModifierNames = chrome && (mac || +chrome[1] < 57) || gecko && mac;
  91. // Fill in the digit keys
  92. for (var i = 0; i < 10; i++) base[48 + i] = base[96 + i] = String(i);
  93. // The function keys
  94. for (var i = 1; i <= 24; i++) base[i + 111] = "F" + i;
  95. // And the alphabetic keys
  96. for (var i = 65; i <= 90; i++) {
  97. base[i] = String.fromCharCode(i + 32);
  98. shift[i] = String.fromCharCode(i);
  99. }
  100. // For each code that doesn't have a shift-equivalent, copy the base name
  101. for (var code in base) if (!shift.hasOwnProperty(code)) shift[code] = base[code];
  102. function keyName(event) {
  103. // Don't trust event.key in Chrome when there are modifiers until
  104. // they fix https://bugs.chromium.org/p/chromium/issues/detail?id=633838
  105. var ignoreKey = brokenModifierNames && (event.ctrlKey || event.altKey || event.metaKey) ||
  106. (safari || ie) && event.shiftKey && event.key && event.key.length == 1;
  107. var name = (!ignoreKey && event.key) ||
  108. (event.shiftKey ? shift : base)[event.keyCode] ||
  109. event.key || "Unidentified";
  110. // Edge sometimes produces wrong names (Issue #3)
  111. if (name == "Esc") name = "Escape";
  112. if (name == "Del") name = "Delete";
  113. // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/
  114. if (name == "Left") name = "ArrowLeft";
  115. if (name == "Up") name = "ArrowUp";
  116. if (name == "Right") name = "ArrowRight";
  117. if (name == "Down") name = "ArrowDown";
  118. return name
  119. }
  120. exports.base = base;
  121. exports.keyName = keyName;
  122. exports.shift = shift;