kollapsminoriteten/wp-includes/js/dist/keycodes.js

242 lines
7.9 KiB
JavaScript
Raw Permalink Normal View History

2024-04-17 11:32:24 +02:00
/******/ (() => { // webpackBootstrap
2022-06-16 14:03:35 +02:00
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define getter functions for harmony exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.d = (exports, definition) => {
2022-06-16 14:03:35 +02:00
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
2024-04-17 11:32:24 +02:00
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/make namespace object */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define __esModule on exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.r = (exports) => {
2022-06-16 14:03:35 +02:00
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
2019-11-02 10:38:58 +01:00
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
2019-11-02 10:38:58 +01:00
/************************************************************************/
2022-06-16 14:03:35 +02:00
var __webpack_exports__ = {};
2020-09-15 14:29:22 +02:00
// ESM COMPAT FLAG
2019-11-02 10:38:58 +01:00
__webpack_require__.r(__webpack_exports__);
2020-09-15 14:29:22 +02:00
// EXPORTS
2022-06-16 14:03:35 +02:00
__webpack_require__.d(__webpack_exports__, {
2024-04-17 11:32:24 +02:00
ALT: () => (/* binding */ ALT),
BACKSPACE: () => (/* binding */ BACKSPACE),
COMMAND: () => (/* binding */ COMMAND),
CTRL: () => (/* binding */ CTRL),
DELETE: () => (/* binding */ DELETE),
DOWN: () => (/* binding */ DOWN),
END: () => (/* binding */ END),
ENTER: () => (/* binding */ ENTER),
ESCAPE: () => (/* binding */ ESCAPE),
F10: () => (/* binding */ F10),
HOME: () => (/* binding */ HOME),
LEFT: () => (/* binding */ LEFT),
PAGEDOWN: () => (/* binding */ PAGEDOWN),
PAGEUP: () => (/* binding */ PAGEUP),
RIGHT: () => (/* binding */ RIGHT),
SHIFT: () => (/* binding */ SHIFT),
SPACE: () => (/* binding */ SPACE),
TAB: () => (/* binding */ TAB),
UP: () => (/* binding */ UP),
ZERO: () => (/* binding */ ZERO),
displayShortcut: () => (/* binding */ displayShortcut),
displayShortcutList: () => (/* binding */ displayShortcutList),
isAppleOS: () => (/* reexport */ isAppleOS),
isKeyboardEvent: () => (/* binding */ isKeyboardEvent),
modifiers: () => (/* binding */ modifiers),
rawShortcut: () => (/* binding */ rawShortcut),
shortcutAriaLabel: () => (/* binding */ shortcutAriaLabel)
2022-06-16 14:03:35 +02:00
});
2025-04-25 12:30:07 +02:00
;// external ["wp","i18n"]
2024-04-17 11:32:24 +02:00
const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keycodes/build-module/platform.js
2025-12-12 13:15:55 +01:00
function isAppleOS(_window) {
2021-07-23 11:58:50 +02:00
if (!_window) {
2025-12-12 13:15:55 +01:00
if (typeof window === "undefined") {
2021-07-23 11:58:50 +02:00
return false;
}
_window = window;
}
2025-12-12 13:15:55 +01:00
const { platform } = _window.navigator;
return platform.indexOf("Mac") !== -1 || ["iPad", "iPhone"].includes(platform);
2019-11-02 10:38:58 +01:00
}
2021-04-27 08:32:47 +02:00
2025-12-12 13:15:55 +01:00
;// ./node_modules/@wordpress/keycodes/build-module/index.js
2021-04-27 08:32:47 +02:00
2023-04-26 17:39:43 +02:00
2021-07-23 11:58:50 +02:00
const BACKSPACE = 8;
const TAB = 9;
const ENTER = 13;
const ESCAPE = 27;
const SPACE = 32;
2022-04-02 10:26:41 +02:00
const PAGEUP = 33;
const PAGEDOWN = 34;
const END = 35;
const HOME = 36;
2021-07-23 11:58:50 +02:00
const LEFT = 37;
const UP = 38;
const RIGHT = 39;
const DOWN = 40;
const DELETE = 46;
const F10 = 121;
2025-12-12 13:15:55 +01:00
const ALT = "alt";
const CTRL = "ctrl";
const COMMAND = "meta";
const SHIFT = "shift";
2021-07-23 11:58:50 +02:00
const ZERO = 48;
2024-04-17 11:32:24 +02:00
function capitaliseFirstCharacter(string) {
return string.length < 2 ? string.toUpperCase() : string.charAt(0).toUpperCase() + string.slice(1);
}
2023-04-26 17:39:43 +02:00
function mapValues(object, mapFn) {
2025-12-12 13:15:55 +01:00
return Object.fromEntries(
Object.entries(object).map(([key, value]) => [
key,
mapFn(value)
])
);
2023-04-26 17:39:43 +02:00
}
2021-07-23 11:58:50 +02:00
const modifiers = {
2025-12-12 13:15:55 +01:00
primary: (_isApple) => _isApple() ? [COMMAND] : [CTRL],
primaryShift: (_isApple) => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT],
primaryAlt: (_isApple) => _isApple() ? [ALT, COMMAND] : [CTRL, ALT],
secondary: (_isApple) => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT],
access: (_isApple) => _isApple() ? [CTRL, ALT] : [SHIFT, ALT],
2021-07-23 11:58:50 +02:00
ctrl: () => [CTRL],
alt: () => [ALT],
ctrlShift: () => [CTRL, SHIFT],
shift: () => [SHIFT],
2022-04-02 10:26:41 +02:00
shiftAlt: () => [SHIFT, ALT],
undefined: () => []
2019-11-02 10:38:58 +01:00
};
2025-12-12 13:15:55 +01:00
const rawShortcut = /* @__PURE__ */ mapValues(modifiers, (modifier) => {
return (character, _isApple = isAppleOS) => {
return [...modifier(_isApple), character.toLowerCase()].join(
"+"
);
2024-04-17 11:32:24 +02:00
};
2019-11-02 10:38:58 +01:00
});
2025-12-12 13:15:55 +01:00
const displayShortcutList = /* @__PURE__ */ mapValues(
modifiers,
(modifier) => {
return (character, _isApple = isAppleOS) => {
const isApple = _isApple();
const replacementKeyMap = {
[ALT]: isApple ? "\u2325" : "Alt",
[CTRL]: isApple ? "\u2303" : "Ctrl",
// Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.
[COMMAND]: "\u2318",
[SHIFT]: isApple ? "\u21E7" : "Shift"
};
const modifierKeys = modifier(_isApple).reduce(
(accumulator, key) => {
const replacementKey = replacementKeyMap[key] ?? key;
if (isApple) {
return [...accumulator, replacementKey];
}
return [...accumulator, replacementKey, "+"];
},
[]
);
return [
...modifierKeys,
capitaliseFirstCharacter(character)
];
2024-04-17 11:32:24 +02:00
};
2025-12-12 13:15:55 +01:00
}
);
const displayShortcut = /* @__PURE__ */ mapValues(
displayShortcutList,
(shortcutList) => {
return (character, _isApple = isAppleOS) => shortcutList(character, _isApple).join("");
}
);
const shortcutAriaLabel = /* @__PURE__ */ mapValues(modifiers, (modifier) => {
return (character, _isApple = isAppleOS) => {
2024-04-17 11:32:24 +02:00
const isApple = _isApple();
const replacementKeyMap = {
2025-12-12 13:15:55 +01:00
[SHIFT]: "Shift",
[COMMAND]: isApple ? "Command" : "Control",
[CTRL]: "Control",
[ALT]: isApple ? "Option" : "Alt",
2024-04-17 11:32:24 +02:00
/* translators: comma as in the character ',' */
2025-12-12 13:15:55 +01:00
",": (0,external_wp_i18n_namespaceObject.__)("Comma"),
2024-04-17 11:32:24 +02:00
/* translators: period as in the character '.' */
2025-12-12 13:15:55 +01:00
".": (0,external_wp_i18n_namespaceObject.__)("Period"),
2024-04-17 11:32:24 +02:00
/* translators: backtick as in the character '`' */
2025-12-12 13:15:55 +01:00
"`": (0,external_wp_i18n_namespaceObject.__)("Backtick"),
2024-04-17 11:32:24 +02:00
/* translators: tilde as in the character '~' */
2025-12-12 13:15:55 +01:00
"~": (0,external_wp_i18n_namespaceObject.__)("Tilde")
2024-04-17 11:32:24 +02:00
};
2025-12-12 13:15:55 +01:00
return [...modifier(_isApple), character].map(
(key) => capitaliseFirstCharacter(replacementKeyMap[key] ?? key)
).join(isApple ? " " : " + ");
2024-04-17 11:32:24 +02:00
};
2019-11-02 10:38:58 +01:00
});
2020-09-15 14:29:22 +02:00
function getEventModifiers(event) {
2025-12-12 13:15:55 +01:00
return [ALT, CTRL, COMMAND, SHIFT].filter(
(key) => event[`${key}Key`]
);
2020-09-15 14:29:22 +02:00
}
2025-12-12 13:15:55 +01:00
const isKeyboardEvent = /* @__PURE__ */ mapValues(modifiers, (getModifiers) => {
return (event, character, _isApple = isAppleOS) => {
2024-04-17 11:32:24 +02:00
const mods = getModifiers(_isApple);
const eventMods = getEventModifiers(event);
const replacementWithShiftKeyMap = {
2025-12-12 13:15:55 +01:00
Comma: ",",
Backslash: "\\",
2024-04-17 11:32:24 +02:00
// Windows returns `\` for both IntlRo and IntlYen.
2025-12-12 13:15:55 +01:00
IntlRo: "\\",
IntlYen: "\\"
2024-04-17 11:32:24 +02:00
};
2025-12-12 13:15:55 +01:00
const modsDiff = mods.filter(
(mod) => !eventMods.includes(mod)
);
const eventModsDiff = eventMods.filter(
(mod) => !mods.includes(mod)
);
2024-04-17 11:32:24 +02:00
if (modsDiff.length > 0 || eventModsDiff.length > 0) {
return false;
}
let key = event.key.toLowerCase();
if (!character) {
2025-12-12 13:15:55 +01:00
return mods.includes(key);
2024-04-17 11:32:24 +02:00
}
if (event.altKey && character.length === 1) {
key = String.fromCharCode(event.keyCode).toLowerCase();
}
if (event.shiftKey && character.length === 1 && replacementWithShiftKeyMap[event.code]) {
key = replacementWithShiftKeyMap[event.code];
}
2025-12-12 13:15:55 +01:00
if (character === "del") {
character = "delete";
2021-04-27 08:32:47 +02:00
}
2024-04-17 11:32:24 +02:00
return key === character.toLowerCase();
};
2019-11-02 10:38:58 +01:00
});
2025-12-12 13:15:55 +01:00
2022-06-16 14:03:35 +02:00
(window.wp = window.wp || {}).keycodes = __webpack_exports__;
/******/ })()
;