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AA,QACrB,IAAZ,I,EAES,EAAM,QAAQ,EAAS,G,EACtB,EAAQ,EAAe,EAAa,EAAM,O,EAEhD,KAAK,C,MACJ,E,IACF,EAAc,EAAQ,O,MACpB,EAAQ,S,GAGD,EAAQ,O,GACV,EAAQ,O,OAItB,EAAO,C,IACH,EAAQ,EAAM,GAChB,EAAc,EACd,EAAa,E,EAEX,MAAM,EAAG,EAAM,QAAQ,SAAQ,SAAA,QACnB,IAAZ,I,EAES,EAAM,QAAQ,EAAS,G,EACtB,EAAQ,EAAe,E,EAE7B,KAAK,C,MACJ,E,IACF,EAAc,EAAQ,O,MACpB,I,GAGO,EAAQ,O,GACV,EAAQ,O,WAInB,C,EA9GS,CAAW,EAAS,GAE5B,SAAQ,SAAA,G,EAEX,aAAa,EAAO,OACpB,YAAY,EAAO,KACnB,S,GACa,EAAO,K,OAGV,E,EACR,OAAO,G,EACP,KAAK,EAAK,OAAQ,EAAO,E,GAqHpC,SAAS,iBAAiB,G,OAChB,OAAO,I,IACR,W,OACI,E,IACJ,S,OACI,SAAA,G,SAAY,EAAM,MAAO,EAAM,IAAI,MAAM,G,MAC7C,S,OACI,SAAS,G","file":"/npm/slate-auto-replace@0.12.1/lib/slate-auto-replace.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/slate-auto-replace@0.12.1/lib/slate-auto-replace.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import isHotkey from 'is-hotkey'\nimport typeOf from 'type-of'\n\n/**\n * A Slate plugin to automatically replace a block when a string of matching\n * text is typed.\n *\n * @param {Object} opts\n * @return {Object}\n */\n\nfunction AutoReplace(opts = {}) {\n  if (!opts.change) throw new Error('You must provide a `change` option.')\n  if (!opts.trigger) throw new Error('You must provide a `trigger` option.')\n\n  const trigger = normalizeTrigger(opts.trigger)\n\n  /**\n   * On key down.\n   *\n   * @param {Event} event\n   * @param {Change} change\n   * @param {Function} next\n   * @return {Value}\n   */\n\n  function onKeyDown(event, change, next) {\n    if (!trigger(event, change, next)) return next()\n\n    const { value } = change\n    const { selection } = value\n    if (selection.isExpanded) return next()\n\n    const { startBlock } = value\n    if (!startBlock) return next()\n\n    const matches = getMatches(value)\n    if (!matches) return next()\n\n    event.preventDefault()\n\n    const { start } = selection\n    let startOffset = start.offset\n    let totalRemoved = 0\n    const offsets = getOffsets(matches, startOffset)\n\n    offsets.forEach(offset => {\n      change\n        .moveAnchorTo(offset.start)\n        .moveFocusTo(offset.end)\n        .delete()\n      totalRemoved += offset.total\n    })\n\n    startOffset -= totalRemoved\n    change.moveTo(startOffset)\n    change.call(opts.change, event, matches)\n  }\n\n  /**\n   * Try to match the current text of a `value` with the `before` and\n   * `after` regexes.\n   *\n   * @param {Value} value\n   * @return {Object}\n   */\n\n  function getMatches(value) {\n    const { selection, startText } = value\n    const { start } = selection\n    const { text } = startText\n    let after = null\n    let before = null\n\n    if (opts.after) {\n      const string = text.slice(start.offset)\n      after = string.match(opts.after)\n    }\n\n    if (opts.before) {\n      const string = text.slice(0, start.offset)\n      before = string.match(opts.before)\n    }\n\n    // If both sides, require that both are matched, otherwise null.\n    if (opts.before && opts.after && !before) after = null\n    if (opts.before && opts.after && !after) before = null\n\n    // Return null unless we have a match.\n    if (!before && !after) return null\n\n    if (after) after[0] = after[0].replace(/\\s+$/, '')\n    if (before) before[0] = before[0].replace(/^\\s+/, '')\n\n    return { before, after }\n  }\n\n  /**\n   * Return the offsets for `matches` with `start` offset.\n   *\n   * @param {Object} matches\n   * @param {Number} start\n   * @return {Object}\n   */\n\n  function getOffsets(matches, start) {\n    const { before, after } = matches\n    const offsets = []\n    let totalRemoved = 0\n\n    if (before) {\n      const match = before[0]\n      let startOffset = 0\n      let matchIndex = 0\n\n      before.slice(1, before.length).forEach(current => {\n        if (current === undefined) return\n\n        matchIndex = match.indexOf(current, matchIndex)\n        startOffset = start - totalRemoved + matchIndex - match.length\n\n        offsets.push({\n          start: startOffset,\n          end: startOffset + current.length,\n          total: current.length,\n        })\n\n        totalRemoved += current.length\n        matchIndex += current.length\n      })\n    }\n\n    if (after) {\n      const match = after[0]\n      let startOffset = 0\n      let matchIndex = 0\n\n      after.slice(1, after.length).forEach(current => {\n        if (current === undefined) return\n\n        matchIndex = match.indexOf(current, matchIndex)\n        startOffset = start - totalRemoved + matchIndex\n\n        offsets.push({\n          start: startOffset,\n          end: startOffset + current.length,\n          total: 0,\n        })\n\n        totalRemoved += current.length\n        matchIndex += current.length\n      })\n    }\n\n    return offsets\n  }\n\n  /**\n   * Return the plugin.\n   *\n   * @type {Object}\n   */\n\n  return { onKeyDown }\n}\n\n/**\n * Normalize a `trigger` option to a matching function.\n *\n * @param {Mixed} trigger\n * @return {Function}\n */\n\nfunction normalizeTrigger(trigger) {\n  switch (typeOf(trigger)) {\n    case 'function':\n      return trigger\n    case 'regexp':\n      return event => !!(event.key && event.key.match(trigger))\n    case 'string':\n      return isHotkey(trigger)\n  }\n}\n\n/**\n * Export.\n *\n * @type {Function}\n */\n\nexport default AutoReplace\n"]}