index.cjs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. };
  57. var shift = {
  58. 48: ")",
  59. 49: "!",
  60. 50: "@",
  61. 51: "#",
  62. 52: "$",
  63. 53: "%",
  64. 54: "^",
  65. 55: "&",
  66. 56: "*",
  67. 57: "(",
  68. 59: ":",
  69. 61: "+",
  70. 173: "_",
  71. 186: ":",
  72. 187: "+",
  73. 188: "<",
  74. 189: "_",
  75. 190: ">",
  76. 191: "?",
  77. 192: "~",
  78. 219: "{",
  79. 220: "|",
  80. 221: "}",
  81. 222: "\""
  82. };
  83. var mac = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
  84. var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
  85. // Fill in the digit keys
  86. for (var i = 0; i < 10; i++) base[48 + i] = base[96 + i] = String(i);
  87. // The function keys
  88. for (var i = 1; i <= 24; i++) base[i + 111] = "F" + i;
  89. // And the alphabetic keys
  90. for (var i = 65; i <= 90; i++) {
  91. base[i] = String.fromCharCode(i + 32);
  92. shift[i] = String.fromCharCode(i);
  93. }
  94. // For each code that doesn't have a shift-equivalent, copy the base name
  95. for (var code in base) if (!shift.hasOwnProperty(code)) shift[code] = base[code];
  96. function keyName(event) {
  97. // On macOS, keys held with Shift and Cmd don't reflect the effect of Shift in `.key`.
  98. // On IE, shift effect is never included in `.key`.
  99. var ignoreKey = mac && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey ||
  100. ie && event.shiftKey && event.key && event.key.length == 1 ||
  101. event.key == "Unidentified";
  102. var name = (!ignoreKey && event.key) ||
  103. (event.shiftKey ? shift : base)[event.keyCode] ||
  104. event.key || "Unidentified";
  105. // Edge sometimes produces wrong names (Issue #3)
  106. if (name == "Esc") name = "Escape";
  107. if (name == "Del") name = "Delete";
  108. // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8860571/
  109. if (name == "Left") name = "ArrowLeft";
  110. if (name == "Up") name = "ArrowUp";
  111. if (name == "Right") name = "ArrowRight";
  112. if (name == "Down") name = "ArrowDown";
  113. return name
  114. }
  115. exports.base = base;
  116. exports.keyName = keyName;
  117. exports.shift = shift;