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,WAMnF,GAAI,EAAM,kBAAoB,EAAU,QAAQ,qBAC1C,EAAU,QAAQ,OACpB,QAAQ,IAAI,6CAA8C,EAAM,UAFpE,CAQA,GAAI,EAAU,QAAQ,cACH,kBAAkB,EAAY,SAChC,IAAI,EAAM,OACvB,EAAM,iBAKN,EAAM,QAAU,EAAU,QAAQ,EAAM,MACtC,EAAU,QAAQ,mBAChB,EAAU,QAAQ,OACpB,QAAQ,IAAI,qDAAsD,EAAM,MAI1E,EAAS,IAMT,EAAU,QAAQ,EAAM,eACnB,EAAU,QAAQ,EAAM,MAC/B,KAEF,EAAU,QAAQ,EAAM,OAAQ,EAChC,IA7BA,CA8BF,GAAG,CAAC,EAAU,IAGV,EAAU,QAAQ,QACpB,OAAO,qBAAuB,cAEhC,IAAI,EAAa,eAAwB,QAAE,aAAY,WACjD,EAAU,QAAQ,OACpB,QAAQ,IAAI,iDAEd,EAAU,QAAU,CAAC,EACrB,GACF,GAAG,CAAC,IAWJ,OAVA,eAAwB,QAAE,WAAU,WAIlC,OAHA,sBAAsB,iBAAiB,UAAW,EAAY,GAC9D,sBAAsB,iBAAiB,QAAS,EAAU,GAC1D,OAAO,iBAAiB,OAAQ,GACzB,WACL,sBAAsB,oBAAoB,UAAW,GACrD,sBAAsB,oBAAoB,QAAS,GACnD,OAAO,oBAAoB,OAAQ,EACrC,CACF,GAAG,CAAC,EAAY,EAAU,EAAY,IAC/B,SAAS,CAAC,EAAG,EAAO,CACzB,cAAe,GAEnB,EAEA,QAAQ,aAAe,aACvB,QAAQ,cAAgB,cACxB,QAAQ,YAAc","file":"/npm/use-key-state@0.2.2/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/use-key-state@0.2.2/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var React = require('react');\n\nfunction _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }\n\nvar React__default = /*#__PURE__*/_interopDefaultLegacy(React);\n\nfunction _extends() {\n  _extends = Object.assign || function (target) {\n    for (var i = 1; i < arguments.length; i++) {\n      var source = arguments[i];\n      for (var key in source) {\n        if (Object.prototype.hasOwnProperty.call(source, key)) {\n          target[key] = source[key];\n        }\n      }\n    }\n    return target;\n  };\n  return _extends.apply(this, arguments);\n}\n\n//  Event Emitter\nvar EventEmitter = /*#__PURE__*/function () {\n  function EventEmitter() {\n    this.events = {};\n  }\n  var _proto = EventEmitter.prototype;\n  _proto._getWeightedEventListByName = function _getWeightedEventListByName(eventName) {\n    if (typeof this.events[eventName] === \"undefined\") {\n      this.events[eventName] = [];\n    }\n    return this.events[eventName];\n  };\n  _proto.on = function on(eventName, fn, priority) {\n    if (priority === void 0) {\n      priority = 0;\n    }\n    var weightedLists = this._getWeightedEventListByName(eventName);\n    if (!weightedLists[priority]) {\n      weightedLists[priority] = new Set();\n    }\n    weightedLists[priority].add(fn);\n  };\n  _proto.once = function once(eventName, fn) {\n    var self = this;\n    var onceFn = function onceFn() {\n      self.removeListener(eventName, onceFn);\n      fn.apply(self, [].slice.call(arguments));\n    };\n    this.on(eventName, onceFn);\n  };\n  _proto.emit = function emit(eventName) {\n    var args = [].slice.call(arguments, 1);\n    var prioritizedCallbacks = [].concat(this._getWeightedEventListByName(eventName)).reverse() // highest weight first\n    .map(function (list) {\n      return Array.from(list);\n    }) // preserving insertion order\n    .flat();\n    prioritizedCallbacks.forEach(function (fn) {\n      fn.apply(this, args);\n    }.bind(this));\n  };\n  _proto.removeListener = function removeListener(eventName, fn) {\n    this._getWeightedEventListByName(eventName).forEach(function (list) {\n      return list[\"delete\"](fn);\n    });\n  };\n  return EventEmitter;\n}(); // Document Event Listener\nvar eventEmitter = new EventEmitter();\nvar boundEvents = {};\nfunction emitDomEvent(event) {\n  eventEmitter.emit(event.type, event);\n}\nvar DocumentEventListener = {\n  addEventListener: function addEventListener(eventName, listener, priority) {\n    if (!boundEvents[eventName]) {\n      document.addEventListener(eventName, emitDomEvent, true);\n    }\n    eventEmitter.on(eventName, listener, priority);\n  },\n  removeEventListener: function removeEventListener(eventName, listener) {\n    eventEmitter.removeListener(eventName, listener);\n  }\n};\n\n// Key State\n\nfunction KeyState(isDown, justReset) {\n  if (isDown === void 0) {\n    isDown = false;\n  }\n  if (justReset === void 0) {\n    justReset = false;\n  }\n  this.pressed = isDown; //current (live) combo pressed state\n  this.down = isDown; //only true for one read after combo becomes valid\n  this.up = justReset; //only true for one read after combo is no longer valid\n}\nfunction _get(context, key) {\n  var expiredKey = \"_\" + key + \"Expired\";\n  var valueKey = \"_\" + key;\n  if (context[expiredKey]) {\n    return false;\n  }\n  context[expiredKey] = true;\n  return context[valueKey];\n}\nfunction _set(context, key, value) {\n  var expiredKey = \"_\" + key + \"Expired\";\n  var valueKey = \"_\" + key;\n  context[expiredKey] = false;\n  context[valueKey] = value;\n}\nObject.defineProperty(KeyState.prototype, \"down\", {\n  get: function get() {\n    return _get(this, \"down\");\n  },\n  set: function set(value) {\n    _set(this, \"down\", value);\n  }\n});\nObject.defineProperty(KeyState.prototype, \"up\", {\n  get: function get() {\n    return _get(this, \"up\");\n  },\n  set: function set(value) {\n    _set(this, \"up\", value);\n  }\n});\n\n// Utils\n\n// toCodes: maps our string notation to possible key event codes\n// See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code\n// Returns an array because browser / platform inconsistencies and we don't care to\n// distinguish between left and right keys usually. If we can't map it we pass\n// it through which means everyone is free to use the actual codes in the rules\n// if they need more.\nfunction toCodes(input) {\n  if (!input.length) {\n    return [];\n  }\n  var str = input.toLowerCase();\n  var len = str.length;\n  if (len === 1 && str.match(/[a-z]/i)) {\n    // a-z\n    return [\"Key\" + str.toUpperCase()];\n  } else if (len === 1 && str.match(/[0-9]/i)) {\n    // 0-9\n    return [\"Digit\" + str];\n  }\n  switch (str) {\n    case \"[\":\n      return [\"BracketLeft\"];\n    case \"]\":\n      return [\"BracketRight\"];\n    case \"\\\\\":\n    case \"backslash\":\n      return [\"Backslash\"];\n    case \"period\":\n    case \".\":\n      return [\"Period\"];\n    case \"comma\":\n    case \",\":\n      return [\"Comma\", \"NumpadComma\"];\n    case \"slash\":\n    case \"/\":\n      return [\"Slash\"];\n    case \"backquote\":\n    case \"`\":\n      return [\"Backquote\"];\n    case \"delete\":\n    case \"backspace\":\n      return [\"Backspace\", \"Delete\"];\n    case \"tab\":\n      return [\"Tab\"];\n    case \"enter\":\n    case \"return\":\n      return [\"Enter\", \"NumpadEnter\"];\n    case \"shift\":\n      return [\"ShiftLeft\", \"ShiftRight\"];\n    case \"ctrl\":\n    case \"cntrl\":\n    case \"control\":\n      return [\"ControlRight\", \"ControlLeft\"];\n    case \"option\":\n    case \"opt\":\n    case \"alt\":\n      return [\"AltLeft\", \"AltRight\"];\n    case \"esc\":\n    case \"escape\":\n      return [\"Escape\"];\n    case \"space\":\n      return [\"Space\"];\n    case \"left\":\n      return [\"ArrowLeft\"];\n    case \"up\":\n      return [\"ArrowUp\"];\n    case \"right\":\n      return [\"ArrowRight\"];\n    case \"down\":\n      return [\"ArrowDown\"];\n    case \"cmd\":\n    case \"command\":\n    case \"win\":\n    case \"meta\":\n      return [\"OSLeft\", \"OSRight\", \"MetaLeft\", \"MetaRight\"];\n    case \"plus\":\n    case \"equal\":\n    case \"equals\":\n    case \"=\":\n      return [\"Equal\"];\n    case \"minus\":\n      return [\"Minus\"];\n    case \"f1\":\n    case \"f2\":\n    case \"f3\":\n    case \"f4\":\n    case \"f5\":\n    case \"f6\":\n    case \"f8\":\n    case \"f9\":\n    case \"f10\":\n    case \"f11\":\n    case \"f12\":\n      return [str.toUpperCase()];\n    default:\n      // Pass input through to allow using specific event codes directly:\n      return [input];\n  }\n}\nfunction matchRule(rule, isDown) {\n  function matchRuleStr(ruleStr) {\n    var parts = parseRuleStr(ruleStr);\n    var results = parts.map(function (str) {\n      return isDown(toCodes(str));\n    });\n    return results.every(function (r) {\n      return r === true;\n    });\n  }\n  if (Array.isArray(rule)) {\n    return rule.some(function (ruleStr) {\n      return matchRuleStr(ruleStr) === true;\n    });\n  }\n  return matchRuleStr(rule);\n}\nfunction extractCaptureSet(rulesMap) {\n  var captureSet = new Set();\n  Object.entries(rulesMap).forEach(function (_ref) {\n    var value = _ref[1];\n    var rules = Array.isArray(value) ? value : [value];\n    rules.forEach(function (rule) {\n      var parts = parseRuleStr(rule);\n      parts.forEach(function (part) {\n        toCodes(part).forEach(function (code) {\n          return captureSet.add(code);\n        });\n      });\n    });\n  });\n  return captureSet;\n}\nfunction parseRuleStr(rule) {\n  return rule.split(\"+\").map(function (str) {\n    return str.trim();\n  });\n}\nfunction mapRulesToState(rulesMap, prevState, isDown) {\n  if (prevState === void 0) {\n    prevState = {};\n  }\n  if (isDown === void 0) {\n    isDown = function isDown() {\n      return false;\n    };\n  }\n  var keysToState = _extends({}, prevState);\n  Object.entries(rulesMap).forEach(function (_ref2) {\n    var key = _ref2[0],\n      rule = _ref2[1];\n    var matched = matchRule(rule, isDown);\n    var prevKeyState = keysToState[key];\n    if (prevKeyState) {\n      if (prevKeyState.pressed !== matched) {\n        var up = prevKeyState.pressed && !matched;\n        keysToState[key] = new KeyState(matched, up);\n      }\n    } else {\n      keysToState[key] = new KeyState();\n    }\n  });\n  return keysToState;\n}\nfunction validateRulesMap(map) {\n  // Expecting an object\n  if (!map || typeof map !== \"object\") {\n    throw new Error(\"useKeyState: expecting an object {key:value<String|Array>} as first parameter.\");\n  }\n  // Expecting string or array values for each key\n  Object.entries(map).forEach(function (_ref3) {\n    var key = _ref3[0],\n      value = _ref3[1];\n    var isArray = Array.isArray(value);\n    var isString = typeof value === \"string\";\n    if (!isString && !isArray) {\n      throw new Error(\"useKeyState: expecting string or array value for key \" + key + \".\");\n    }\n    if (isArray) {\n      value.forEach(function (rule) {\n        if (typeof rule !== \"string\") {\n          throw new Error(\"useKeyState: expecting array of strings for key \" + key);\n        }\n      });\n    }\n  });\n}\n\n// Utils\n\nfunction deepEqual(o1, o2) {\n  return JSON.stringify(o1) === JSON.stringify(o2);\n}\nfunction isInputAcceptingTarget(event) {\n  // content editable\n  if (event.target.isContentEditable) {\n    return true;\n  }\n  // form elements\n  var tagName = (event.target || event.srcElement).tagName;\n  return tagName === \"INPUT\" || tagName === \"SELECT\" || tagName === \"TEXTAREA\";\n}\n\n// Config\n\nvar defaultConfig = {\n  captureEvents: false,\n  // call event.preventDefault()\n  ignoreRepeatEvents: true,\n  // filter out repeat key events (whos event.repeat property is true)\n  ignoreCapturedEvents: true,\n  // respect the defaultPrevented event flag\n  ignoreInputAcceptingElements: true,\n  // filter out events from all forms of inputs\n  priority: undefined,\n  // see DepthContext below\n  debug: false\n};\n\n// DepthContext\n// We want to mimic the DOM bubbling behavior of giving deeper children a chance to capture events.\n// We subscribe to a global key handler on component mount in a filo fashion (useEffect (our subscription) is called in a bottom-up fashion).\n// Late mounted children however would get added to the end of the priority list despite being deeper in the tree.\n// To enforce a depth priority, you can wrap your app layers in <KeyStateLayer> components that keep track of depth relative to parent <KeyStateLayer>.\n// Key callbacks will be sorted first by depth and then by insertion order.\n// Alternatively set priority config option. This will override other default or inferred priorities.\n\nvar DepthContext = React__default['default'].createContext(0);\nfunction KeyStateLayer(_ref4) {\n  var children = _ref4.children;\n  var parentDepth = React__default['default'].useContext(DepthContext);\n  return React__default['default'].createElement(DepthContext.Provider, {\n    value: parentDepth + 1\n  }, children);\n}\n\n// useKeyState ¿\n\nvar useKeyState = function useKeyState(rulesMap, configOverrides) {\n  if (rulesMap === void 0) {\n    rulesMap = {};\n  }\n  if (configOverrides === void 0) {\n    configOverrides = {};\n  }\n  var configRef = React__default['default'].useRef(_extends({}, defaultConfig, configOverrides));\n  React__default['default'].useEffect(function () {\n    // configOverrides is likely to always be different:\n    if (!deepEqual(configOverrides, configRef.current)) {\n      configRef.current = _extends({}, defaultConfig, configOverrides);\n    }\n  }, [configOverrides]);\n  var inferredPriority = React__default['default'].useContext(DepthContext);\n  var depth = configRef.current.priority || inferredPriority || 0;\n\n  // Maintain a copy of the rules map passed in\n  var rulesMapRef = React__default['default'].useRef({});\n  // Validate and update rulesMap when it changes to enable dynamic rules\n  React__default['default'].useEffect(function () {\n    // rulesMap is likely to always be different:\n    if (!deepEqual(rulesMap, rulesMapRef.current)) {\n      validateRulesMap(rulesMap);\n      rulesMapRef.current = rulesMap;\n    }\n  }, [rulesMap]);\n  // Keep track of what keys are down\n  var keyMapRef = React__default['default'].useRef({});\n  // This gets passed back to the caller and is updated\n  // once any hotkey rule matches or stops matching\n  var _React$useState = React__default['default'].useState(function () {\n      return mapRulesToState(rulesMap);\n    }),\n    state = _React$useState[0],\n    setState = _React$useState[1];\n  // Query live key state and some common key utility fns:\n  // This object gets merged into return object\n  var keyStateQuery = {\n    pressed: function pressed(input) {\n      return matchRule(input, isDown);\n    },\n    space: function space() {\n      return isDown(toCodes(\"space\"));\n    },\n    shift: function shift() {\n      return isDown(toCodes(\"shift\"));\n    },\n    ctrl: function ctrl() {\n      return isDown(toCodes(\"ctrl\"));\n    },\n    alt: function alt() {\n      return isDown(toCodes(\"alt\"));\n    },\n    option: function option() {\n      return isDown(toCodes(\"option\"));\n    },\n    meta: function meta() {\n      return isDown(toCodes(\"meta\"));\n    },\n    esc: function esc() {\n      return isDown(toCodes(\"esc\"));\n    }\n  };\n\n  // Re-render the component if the key states have changed.\n  // Must capture state value in a ref because the actual\n  // updateKeyState function captures the initial value:\n  var stateRef = React__default['default'].useRef(state);\n  var updateKeyState = React__default['default'].useCallback(function () {\n    var nextState = mapRulesToState(rulesMapRef.current, stateRef.current, isDown);\n    var isEquivalentState = deepEqual(stateRef.current, nextState);\n    if (configRef.current.debug) {\n      console.log(\"useKeyState: rulesMap\", _extends({}, rulesMapRef.current), \"keyMap\", _extends({}, keyMapRef.current));\n    }\n    if (!isEquivalentState) {\n      stateRef.current = nextState;\n      setState(nextState);\n    }\n  }, []);\n  function isDown(codes) {\n    var results = codes.map(function (code) {\n      return keyMapRef.current[code] || false;\n    });\n    return results.some(function (r) {\n      return r === true;\n    });\n  }\n\n  // Event handlers\n\n  var handleUp = React__default['default'].useCallback(function (event) {\n    if (configRef.current.debug) {\n      console.log(\"useKeyState: up\", event.code);\n    }\n    // If we have an up event for an already captured down, process it regardless of source.\n    // This is because the down could have come in before the input got focus.\n    var isDown = !!keyMapRef.current[event.code];\n    // Ignore events from input accepting elements (inputs etc)\n    if (configRef.current.ignoreInputAcceptingElements && isInputAcceptingTarget(event) && !isDown) {\n      if (configRef.current.debug) {\n        console.log(\"useKeyState: Ignoring captured up event:\", event.code);\n      }\n      return;\n    }\n    // If Meta goes up, throw everything away because we might have stuck\n    // keys (OSX gets no keyup events while the cmd key is held down)\n    // http://web.archive.org/web/20160304022453/http://bitspushedaround.com/on-a-few-things-you-may-not-know-about-the-hellish-command-key-and-javascript-events/\n    if (toCodes(\"meta\").includes(event.code)) {\n      keyMapRef.current = {};\n    }\n    delete keyMapRef.current[event.code];\n    updateKeyState();\n  }, [updateKeyState]);\n  var handleDown = React__default['default'].useCallback(function (event) {\n    if (configRef.current.debug) {\n      console.log(\"useKeyState: down\", event.code);\n    }\n\n    // Ignore events from input accepting elements (inputs etc)\n    if (configRef.current.ignoreInputAcceptingElements && isInputAcceptingTarget(event)) {\n      if (configRef.current.debug) {\n        console.log(\"useKeyState: Ignoring event from input accepting element:\", event.code);\n      }\n      return;\n    }\n\n    // Ignore handled event\n    if (event.defaultPrevented && configRef.current.ignoreCapturedEvents) {\n      if (configRef.current.debug) {\n        console.log(\"useKeyState: Ignoring captured down event:\", event.code);\n      }\n      return;\n    }\n\n    // Capture event if it is part of our rules and hook is configured to do so:\n    if (configRef.current.captureEvents) {\n      var captureSet = extractCaptureSet(rulesMapRef.current);\n      if (captureSet.has(event.code)) {\n        event.preventDefault();\n      }\n    }\n\n    // Handle key repeat\n    if (event.repeat && keyMapRef.current[event.code]) {\n      if (configRef.current.ignoreRepeatEvents) {\n        if (configRef.current.debug) {\n          console.log(\"useKeyState: Ignoring event from repeat key event:\", event.code);\n        }\n      } else {\n        // handle it as a key up (drop every other frame, hack)\n        handleUp(event);\n      }\n      return;\n    }\n\n    // Handle key that didn't receive a key up event - happens when meta key is down\n    if (keyMapRef.current[event.code]) {\n      delete keyMapRef.current[event.code];\n      updateKeyState();\n    }\n    keyMapRef.current[event.code] = true;\n    updateKeyState();\n  }, [handleUp, updateKeyState]);\n\n  // Mark handlers to help debug callback order\n  if (configRef.current.debug) {\n    window.keyStateEventEmitter = eventEmitter;\n  }\n  var handleBlur = React__default['default'].useCallback(function () {\n    if (configRef.current.debug) {\n      console.log(\"useKeyState: clearing keyMap on document blur\");\n    }\n    keyMapRef.current = {};\n    updateKeyState();\n  }, [updateKeyState]);\n  React__default['default'].useEffect(function () {\n    DocumentEventListener.addEventListener(\"keydown\", handleDown, depth);\n    DocumentEventListener.addEventListener(\"keyup\", handleUp, depth);\n    window.addEventListener(\"blur\", handleBlur);\n    return function () {\n      DocumentEventListener.removeEventListener(\"keydown\", handleDown);\n      DocumentEventListener.removeEventListener(\"keyup\", handleUp);\n      window.removeEventListener(\"blur\", handleBlur);\n    };\n  }, [handleDown, handleUp, handleBlur, depth]);\n  return _extends({}, state, {\n    keyStateQuery: keyStateQuery\n  });\n};\n\nexports.DepthContext = DepthContext;\nexports.KeyStateLayer = KeyStateLayer;\nexports.useKeyState = useKeyState;\n"]}