| 1 |
"use strict"; |
| 2 |
var wp; |
| 3 |
(wp ||= {}).keycodes = (() => { |
| 4 |
var __create = Object.create; |
| 5 |
var __defProp = Object.defineProperty; |
| 6 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 7 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
| 8 |
var __getProtoOf = Object.getPrototypeOf; |
| 9 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 10 |
var __commonJS = (cb, mod) => function __require() { |
| 11 |
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 12 |
}; |
| 13 |
var __export = (target, all) => { |
| 14 |
for (var name in all) |
| 15 |
__defProp(target, name, { get: all[name], enumerable: true }); |
| 16 |
}; |
| 17 |
var __copyProps = (to, from, except, desc) => { |
| 18 |
if (from && typeof from === "object" || typeof from === "function") { |
| 19 |
for (let key of __getOwnPropNames(from)) |
| 20 |
if (!__hasOwnProp.call(to, key) && key !== except) |
| 21 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 22 |
} |
| 23 |
return to; |
| 24 |
}; |
| 25 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 26 |
// If the importer is in node compatibility mode or this is not an ESM |
| 27 |
// file that has been converted to a CommonJS file using a Babel- |
| 28 |
// compatible transform (i.e. "__esModule" has not been set), then set |
| 29 |
// "default" to the CommonJS "module.exports" for node compatibility. |
| 30 |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 31 |
mod |
| 32 |
)); |
| 33 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
| 34 |
|
| 35 |
// package-external:@wordpress/i18n |
| 36 |
var require_i18n = __commonJS({ |
| 37 |
"package-external:@wordpress/i18n"(exports, module) { |
| 38 |
module.exports = window.wp.i18n; |
| 39 |
} |
| 40 |
}); |
| 41 |
|
| 42 |
// packages/keycodes/build-module/index.mjs |
| 43 |
var index_exports = {}; |
| 44 |
__export(index_exports, { |
| 45 |
ALT: () => ALT, |
| 46 |
BACKSPACE: () => BACKSPACE, |
| 47 |
COMMAND: () => COMMAND, |
| 48 |
CTRL: () => CTRL, |
| 49 |
DELETE: () => DELETE, |
| 50 |
DOWN: () => DOWN, |
| 51 |
END: () => END, |
| 52 |
ENTER: () => ENTER, |
| 53 |
ESCAPE: () => ESCAPE, |
| 54 |
F10: () => F10, |
| 55 |
HOME: () => HOME, |
| 56 |
LEFT: () => LEFT, |
| 57 |
PAGEDOWN: () => PAGEDOWN, |
| 58 |
PAGEUP: () => PAGEUP, |
| 59 |
RIGHT: () => RIGHT, |
| 60 |
SHIFT: () => SHIFT, |
| 61 |
SPACE: () => SPACE, |
| 62 |
TAB: () => TAB, |
| 63 |
UP: () => UP, |
| 64 |
ZERO: () => ZERO, |
| 65 |
ariaKeyShortcut: () => ariaKeyShortcut, |
| 66 |
displayShortcut: () => displayShortcut, |
| 67 |
displayShortcutList: () => displayShortcutList, |
| 68 |
isAppleOS: () => isAppleOS, |
| 69 |
isKeyboardEvent: () => isKeyboardEvent, |
| 70 |
modifiers: () => modifiers, |
| 71 |
rawShortcut: () => rawShortcut, |
| 72 |
shortcutAriaLabel: () => shortcutAriaLabel |
| 73 |
}); |
| 74 |
var import_i18n = __toESM(require_i18n(), 1); |
| 75 |
|
| 76 |
// packages/keycodes/build-module/platform.mjs |
| 77 |
function isAppleOS(_window) { |
| 78 |
if (!_window) { |
| 79 |
if (typeof window === "undefined") { |
| 80 |
return false; |
| 81 |
} |
| 82 |
_window = window; |
| 83 |
} |
| 84 |
const { platform } = _window.navigator; |
| 85 |
return platform.indexOf("Mac") !== -1 || ["iPad", "iPhone"].includes(platform); |
| 86 |
} |
| 87 |
|
| 88 |
// packages/keycodes/build-module/index.mjs |
| 89 |
var BACKSPACE = 8; |
| 90 |
var TAB = 9; |
| 91 |
var ENTER = 13; |
| 92 |
var ESCAPE = 27; |
| 93 |
var SPACE = 32; |
| 94 |
var PAGEUP = 33; |
| 95 |
var PAGEDOWN = 34; |
| 96 |
var END = 35; |
| 97 |
var HOME = 36; |
| 98 |
var LEFT = 37; |
| 99 |
var UP = 38; |
| 100 |
var RIGHT = 39; |
| 101 |
var DOWN = 40; |
| 102 |
var DELETE = 46; |
| 103 |
var F10 = 121; |
| 104 |
var ALT = "alt"; |
| 105 |
var CTRL = "ctrl"; |
| 106 |
var COMMAND = "meta"; |
| 107 |
var SHIFT = "shift"; |
| 108 |
var ZERO = 48; |
| 109 |
function capitaliseFirstCharacter(string) { |
| 110 |
return string.length < 2 ? string.toUpperCase() : string.charAt(0).toUpperCase() + string.slice(1); |
| 111 |
} |
| 112 |
function mapValues(object, mapFn) { |
| 113 |
return Object.fromEntries( |
| 114 |
Object.entries(object).map(([key, value]) => [ |
| 115 |
key, |
| 116 |
mapFn(value) |
| 117 |
]) |
| 118 |
); |
| 119 |
} |
| 120 |
var modifiers = { |
| 121 |
primary: (_isApple) => _isApple() ? [COMMAND] : [CTRL], |
| 122 |
primaryShift: (_isApple) => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT], |
| 123 |
primaryAlt: (_isApple) => _isApple() ? [ALT, COMMAND] : [CTRL, ALT], |
| 124 |
secondary: (_isApple) => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT], |
| 125 |
access: (_isApple) => _isApple() ? [CTRL, ALT] : [SHIFT, ALT], |
| 126 |
ctrl: () => [CTRL], |
| 127 |
alt: () => [ALT], |
| 128 |
ctrlShift: () => [CTRL, SHIFT], |
| 129 |
shift: () => [SHIFT], |
| 130 |
shiftAlt: () => [SHIFT, ALT], |
| 131 |
undefined: () => [] |
| 132 |
}; |
| 133 |
var rawShortcut = /* @__PURE__ */ mapValues(modifiers, (modifier) => { |
| 134 |
return (character, _isApple = isAppleOS) => { |
| 135 |
return [...modifier(_isApple), character.toLowerCase()].join( |
| 136 |
"+" |
| 137 |
); |
| 138 |
}; |
| 139 |
}); |
| 140 |
var ariaKeyShortcut = /* @__PURE__ */ mapValues(modifiers, (modifier) => { |
| 141 |
return (character, _isApple = isAppleOS) => { |
| 142 |
return [ |
| 143 |
...modifier(_isApple).map((key) => key === CTRL ? "Control" : key).map((key) => capitaliseFirstCharacter(key)), |
| 144 |
capitaliseFirstCharacter(character) |
| 145 |
].join("+"); |
| 146 |
}; |
| 147 |
}); |
| 148 |
var displayShortcutList = /* @__PURE__ */ mapValues( |
| 149 |
modifiers, |
| 150 |
(modifier) => { |
| 151 |
return (character, _isApple = isAppleOS) => { |
| 152 |
const isApple = _isApple(); |
| 153 |
const replacementKeyMap = { |
| 154 |
[ALT]: isApple ? "\u2325" : "Alt", |
| 155 |
[CTRL]: isApple ? "\u2303" : "Ctrl", |
| 156 |
// Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character. |
| 157 |
[COMMAND]: "\u2318", |
| 158 |
[SHIFT]: isApple ? "\u21E7" : "Shift" |
| 159 |
}; |
| 160 |
const modifierKeys = modifier(_isApple).reduce( |
| 161 |
(accumulator, key) => { |
| 162 |
const replacementKey = replacementKeyMap[key] ?? key; |
| 163 |
if (isApple) { |
| 164 |
return [...accumulator, replacementKey]; |
| 165 |
} |
| 166 |
return [...accumulator, replacementKey, "+"]; |
| 167 |
}, |
| 168 |
[] |
| 169 |
); |
| 170 |
return [ |
| 171 |
...modifierKeys, |
| 172 |
capitaliseFirstCharacter(character) |
| 173 |
]; |
| 174 |
}; |
| 175 |
} |
| 176 |
); |
| 177 |
var displayShortcut = /* @__PURE__ */ mapValues( |
| 178 |
displayShortcutList, |
| 179 |
(shortcutList) => { |
| 180 |
return (character, _isApple = isAppleOS) => shortcutList(character, _isApple).join(""); |
| 181 |
} |
| 182 |
); |
| 183 |
var shortcutAriaLabel = /* @__PURE__ */ mapValues(modifiers, (modifier) => { |
| 184 |
return (character, _isApple = isAppleOS) => { |
| 185 |
const isApple = _isApple(); |
| 186 |
const replacementKeyMap = { |
| 187 |
[SHIFT]: "Shift", |
| 188 |
[COMMAND]: isApple ? "Command" : "Control", |
| 189 |
[CTRL]: "Control", |
| 190 |
[ALT]: isApple ? "Option" : "Alt", |
| 191 |
/* translators: comma as in the character ',' */ |
| 192 |
",": (0, import_i18n.__)("Comma"), |
| 193 |
/* translators: period as in the character '.' */ |
| 194 |
".": (0, import_i18n.__)("Period"), |
| 195 |
/* translators: backtick as in the character '`' */ |
| 196 |
"`": (0, import_i18n.__)("Backtick"), |
| 197 |
/* translators: tilde as in the character '~' */ |
| 198 |
"~": (0, import_i18n.__)("Tilde") |
| 199 |
}; |
| 200 |
return [...modifier(_isApple), character].map( |
| 201 |
(key) => capitaliseFirstCharacter(replacementKeyMap[key] ?? key) |
| 202 |
).join(isApple ? " " : " + "); |
| 203 |
}; |
| 204 |
}); |
| 205 |
function getEventModifiers(event) { |
| 206 |
return [ALT, CTRL, COMMAND, SHIFT].filter( |
| 207 |
(key) => event[`${key}Key`] |
| 208 |
); |
| 209 |
} |
| 210 |
var isKeyboardEvent = /* @__PURE__ */ mapValues(modifiers, (getModifiers) => { |
| 211 |
return (event, character, _isApple = isAppleOS) => { |
| 212 |
const mods = getModifiers(_isApple); |
| 213 |
const eventMods = getEventModifiers(event); |
| 214 |
const replacementWithShiftKeyMap = { |
| 215 |
Comma: ",", |
| 216 |
Backslash: "\\", |
| 217 |
// Windows returns `\` for both IntlRo and IntlYen. |
| 218 |
IntlRo: "\\", |
| 219 |
IntlYen: "\\" |
| 220 |
}; |
| 221 |
const modsDiff = mods.filter( |
| 222 |
(mod) => !eventMods.includes(mod) |
| 223 |
); |
| 224 |
const eventModsDiff = eventMods.filter( |
| 225 |
(mod) => !mods.includes(mod) |
| 226 |
); |
| 227 |
if (modsDiff.length > 0 || eventModsDiff.length > 0) { |
| 228 |
return false; |
| 229 |
} |
| 230 |
let key = event.key.toLowerCase(); |
| 231 |
if (!character) { |
| 232 |
return mods.includes(key); |
| 233 |
} |
| 234 |
if (event.altKey && character.length === 1) { |
| 235 |
key = String.fromCharCode(event.keyCode).toLowerCase(); |
| 236 |
} |
| 237 |
if (event.shiftKey && character.length === 1 && replacementWithShiftKeyMap[event.code]) { |
| 238 |
key = replacementWithShiftKeyMap[event.code]; |
| 239 |
} |
| 240 |
if (character === "del") { |
| 241 |
character = "delete"; |
| 242 |
} |
| 243 |
return key === character.toLowerCase(); |
| 244 |
}; |
| 245 |
}); |
| 246 |
return __toCommonJS(index_exports); |
| 247 |
})(); |
| 248 |
//# sourceMappingURL=index.js.map |
| 249 |
|