[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> keycodes.js (source)

   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.js
  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      displayShortcut: () => displayShortcut,
  66      displayShortcutList: () => displayShortcutList,
  67      isAppleOS: () => isAppleOS,
  68      isKeyboardEvent: () => isKeyboardEvent,
  69      modifiers: () => modifiers,
  70      rawShortcut: () => rawShortcut,
  71      shortcutAriaLabel: () => shortcutAriaLabel
  72    });
  73    var import_i18n = __toESM(require_i18n());
  74  
  75    // packages/keycodes/build-module/platform.js
  76    function isAppleOS(_window) {
  77      if (!_window) {
  78        if (typeof window === "undefined") {
  79          return false;
  80        }
  81        _window = window;
  82      }
  83      const { platform } = _window.navigator;
  84      return platform.indexOf("Mac") !== -1 || ["iPad", "iPhone"].includes(platform);
  85    }
  86  
  87    // packages/keycodes/build-module/index.js
  88    var BACKSPACE = 8;
  89    var TAB = 9;
  90    var ENTER = 13;
  91    var ESCAPE = 27;
  92    var SPACE = 32;
  93    var PAGEUP = 33;
  94    var PAGEDOWN = 34;
  95    var END = 35;
  96    var HOME = 36;
  97    var LEFT = 37;
  98    var UP = 38;
  99    var RIGHT = 39;
 100    var DOWN = 40;
 101    var DELETE = 46;
 102    var F10 = 121;
 103    var ALT = "alt";
 104    var CTRL = "ctrl";
 105    var COMMAND = "meta";
 106    var SHIFT = "shift";
 107    var ZERO = 48;
 108    function capitaliseFirstCharacter(string) {
 109      return string.length < 2 ? string.toUpperCase() : string.charAt(0).toUpperCase() + string.slice(1);
 110    }
 111    function mapValues(object, mapFn) {
 112      return Object.fromEntries(
 113        Object.entries(object).map(([key, value]) => [
 114          key,
 115          mapFn(value)
 116        ])
 117      );
 118    }
 119    var modifiers = {
 120      primary: (_isApple) => _isApple() ? [COMMAND] : [CTRL],
 121      primaryShift: (_isApple) => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT],
 122      primaryAlt: (_isApple) => _isApple() ? [ALT, COMMAND] : [CTRL, ALT],
 123      secondary: (_isApple) => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT],
 124      access: (_isApple) => _isApple() ? [CTRL, ALT] : [SHIFT, ALT],
 125      ctrl: () => [CTRL],
 126      alt: () => [ALT],
 127      ctrlShift: () => [CTRL, SHIFT],
 128      shift: () => [SHIFT],
 129      shiftAlt: () => [SHIFT, ALT],
 130      undefined: () => []
 131    };
 132    var rawShortcut = /* @__PURE__ */ mapValues(modifiers, (modifier) => {
 133      return (character, _isApple = isAppleOS) => {
 134        return [...modifier(_isApple), character.toLowerCase()].join(
 135          "+"
 136        );
 137      };
 138    });
 139    var displayShortcutList = /* @__PURE__ */ mapValues(
 140      modifiers,
 141      (modifier) => {
 142        return (character, _isApple = isAppleOS) => {
 143          const isApple = _isApple();
 144          const replacementKeyMap = {
 145            [ALT]: isApple ? "\u2325" : "Alt",
 146            [CTRL]: isApple ? "\u2303" : "Ctrl",
 147            // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.
 148            [COMMAND]: "\u2318",
 149            [SHIFT]: isApple ? "\u21E7" : "Shift"
 150          };
 151          const modifierKeys = modifier(_isApple).reduce(
 152            (accumulator, key) => {
 153              const replacementKey = replacementKeyMap[key] ?? key;
 154              if (isApple) {
 155                return [...accumulator, replacementKey];
 156              }
 157              return [...accumulator, replacementKey, "+"];
 158            },
 159            []
 160          );
 161          return [
 162            ...modifierKeys,
 163            capitaliseFirstCharacter(character)
 164          ];
 165        };
 166      }
 167    );
 168    var displayShortcut = /* @__PURE__ */ mapValues(
 169      displayShortcutList,
 170      (shortcutList) => {
 171        return (character, _isApple = isAppleOS) => shortcutList(character, _isApple).join("");
 172      }
 173    );
 174    var shortcutAriaLabel = /* @__PURE__ */ mapValues(modifiers, (modifier) => {
 175      return (character, _isApple = isAppleOS) => {
 176        const isApple = _isApple();
 177        const replacementKeyMap = {
 178          [SHIFT]: "Shift",
 179          [COMMAND]: isApple ? "Command" : "Control",
 180          [CTRL]: "Control",
 181          [ALT]: isApple ? "Option" : "Alt",
 182          /* translators: comma as in the character ',' */
 183          ",": (0, import_i18n.__)("Comma"),
 184          /* translators: period as in the character '.' */
 185          ".": (0, import_i18n.__)("Period"),
 186          /* translators: backtick as in the character '`' */
 187          "`": (0, import_i18n.__)("Backtick"),
 188          /* translators: tilde as in the character '~' */
 189          "~": (0, import_i18n.__)("Tilde")
 190        };
 191        return [...modifier(_isApple), character].map(
 192          (key) => capitaliseFirstCharacter(replacementKeyMap[key] ?? key)
 193        ).join(isApple ? " " : " + ");
 194      };
 195    });
 196    function getEventModifiers(event) {
 197      return [ALT, CTRL, COMMAND, SHIFT].filter(
 198        (key) => event[`$key}Key`]
 199      );
 200    }
 201    var isKeyboardEvent = /* @__PURE__ */ mapValues(modifiers, (getModifiers) => {
 202      return (event, character, _isApple = isAppleOS) => {
 203        const mods = getModifiers(_isApple);
 204        const eventMods = getEventModifiers(event);
 205        const replacementWithShiftKeyMap = {
 206          Comma: ",",
 207          Backslash: "\\",
 208          // Windows returns `\` for both IntlRo and IntlYen.
 209          IntlRo: "\\",
 210          IntlYen: "\\"
 211        };
 212        const modsDiff = mods.filter(
 213          (mod) => !eventMods.includes(mod)
 214        );
 215        const eventModsDiff = eventMods.filter(
 216          (mod) => !mods.includes(mod)
 217        );
 218        if (modsDiff.length > 0 || eventModsDiff.length > 0) {
 219          return false;
 220        }
 221        let key = event.key.toLowerCase();
 222        if (!character) {
 223          return mods.includes(key);
 224        }
 225        if (event.altKey && character.length === 1) {
 226          key = String.fromCharCode(event.keyCode).toLowerCase();
 227        }
 228        if (event.shiftKey && character.length === 1 && replacementWithShiftKeyMap[event.code]) {
 229          key = replacementWithShiftKeyMap[event.code];
 230        }
 231        if (character === "del") {
 232          character = "delete";
 233        }
 234        return key === character.toLowerCase();
 235      };
 236    });
 237    return __toCommonJS(index_exports);
 238  })();


Generated : Wed May 13 08:20:03 2026 Cross-referenced by PHPXref