{"version":3,"sources":["../../src/use-clipboard/legacy.ts"],"sourcesContent":["import { noop } from '../utils/basic'\n\nexport function legacyCopy(value: string): void {\n  const restoreSelection = removeSelection()\n  const textarea = createHiddenTextarea(value)\n  document.body.appendChild(textarea)\n  textarea.select()\n  document.execCommand('copy')\n  textarea.remove()\n  restoreSelection()\n}\n\nexport function legacyRead(): string {\n  return document.getSelection()?.toString() ?? ''\n}\n\n// @see https://github.com/sudodoki/toggle-selection/blob/ac73e2b274c10d019d1f13e4da5f8fc93809806a/index.js\nexport function removeSelection(): () => void {\n  const activeEl = document.activeElement\n  const selection = document.getSelection()\n\n  if (!selection || !selection.rangeCount || !activeEl) return noop\n\n  const ranges: Range[] = []\n\n  for (let i = 0; i < selection.rangeCount; i++) {\n    ranges.push(selection.getRangeAt(i))\n  }\n\n  isInputtable(activeEl) && activeEl.blur()\n\n  selection.removeAllRanges()\n\n  return function restoreSelection() {\n    selection.type === 'Caret' && selection.removeAllRanges()\n\n    if (!selection.rangeCount) {\n      for (const range of ranges) {\n        selection.addRange(range)\n      }\n    }\n\n    isInputtable(activeEl) && activeEl.focus()\n  }\n}\n\nfunction createHiddenTextarea(value: string = ''): HTMLTextAreaElement {\n  const textarea = document.createElement('textarea')\n\n  // reset user styles for textarea element\n  textarea.style.all = 'unset'\n\n  // Prevent zooming on iOS\n  textarea.style.fontSize = '12pt'\n\n  // Reset box model\n  textarea.style.border = '0'\n  textarea.style.padding = '0'\n  textarea.style.margin = '0'\n\n  // Move element out of screen horizontally\n  textarea.style.position = 'absolute'\n  const isRTL = document.documentElement.getAttribute('dir') === 'rtl'\n  textarea.style[isRTL ? 'right' : 'left'] = '-99999px'\n  textarea.style.opacity = '0'\n  textarea.style.zIndex = '-999999999'\n\n  // Move element to the same position vertically\n  const yPosition = window.scrollY || window.pageYOffset || document.documentElement.scrollTop\n  textarea.style.top = `${yPosition}px`\n\n  // avoid screen readers from reading out loud the text\n  textarea.ariaHidden = 'true'\n\n  // used to preserve spaces and line breaks\n  textarea.style.whiteSpace = 'pre'\n\n  // do not inherit user-select (it may be `none`)\n  textarea.style.webkitUserSelect = 'text'\n  // @ts-expect-error legacy style\n  textarea.style.MozUserSelect = 'text'\n  // @ts-expect-error legacy style\n  textarea.style.msUserSelect = 'text'\n  textarea.style.userSelect = 'text'\n\n  textarea.setAttribute('readonly', '')\n\n  textarea.value = value\n\n  return textarea\n}\n\nfunction isInputtable(active: Element | null): active is HTMLInputElement | HTMLTextAreaElement {\n  switch (active?.tagName.toUpperCase()) {\n    case 'INPUT':\n    case 'TEXTAREA':\n      return true\n    default:\n      return false\n  }\n\n  // return [HTMLInputElement, HTMLTextAreaElement].some((el) => active instanceof el)\n}\n"],"names":["legacyCopy","legacyRead","removeSelection","value","restoreSelection","textarea","createHiddenTextarea","document","body","appendChild","select","execCommand","remove","getSelection","toString","activeEl","activeElement","selection","rangeCount","noop","ranges","i","push","getRangeAt","isInputtable","blur","removeAllRanges","type","range","addRange","focus","createElement","style","all","fontSize","border","padding","margin","position","isRTL","documentElement","getAttribute","opacity","zIndex","yPosition","window","scrollY","pageYOffset","scrollTop","top","ariaHidden","whiteSpace","webkitUserSelect","MozUserSelect","msUserSelect","userSelect","setAttribute","active","tagName","toUpperCase"],"mappings":";;;;;;;;;;;QAEgBA;eAAAA;;QAUAC;eAAAA;;QAKAC;eAAAA;;;qBAjBK;AAEd,SAASF,WAAWG,KAAa;IACtC,IAAMC,mBAAmBF;IACzB,IAAMG,WAAWC,qBAAqBH;IACtCI,SAASC,IAAI,CAACC,WAAW,CAACJ;IAC1BA,SAASK,MAAM;IACfH,SAASI,WAAW,CAAC;IACrBN,SAASO,MAAM;IACfR;AACF;AAEO,SAASH;QACPM;QAAAA;IAAP,OAAOA,CAAAA,mCAAAA,yBAAAA,SAASM,YAAY,gBAArBN,6CAAAA,uBAAyBO,QAAQ,gBAAjCP,6CAAAA,kCAAuC;AAChD;AAGO,SAASL;IACd,IAAMa,WAAWR,SAASS,aAAa;IACvC,IAAMC,YAAYV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