{"ast":null,"code":"import { runAfterTransition } from '@react-aria/utils';\nvar state = 'default';\nvar savedUserSelect = '';\nexport function disableTextSelection() {\n  if (state === 'default') {\n    savedUserSelect = document.documentElement.style.webkitUserSelect;\n    document.documentElement.style.webkitUserSelect = 'none';\n  }\n  state = 'disabled';\n}\nexport function restoreTextSelection() {\n  if (state !== 'disabled') {\n    return;\n  }\n  state = 'restoring';\n  setTimeout(function () {\n    runAfterTransition(function () {\n      if (state === 'restoring') {\n        if (document.documentElement.style.webkitUserSelect === 'none') {\n          document.documentElement.style.webkitUserSelect = savedUserSelect || '';\n        }\n        savedUserSelect = '';\n        state = 'default';\n      }\n    });\n  }, 300);\n}","map":{"version":3,"sources":["textSelection.ts"],"names":["runAfterTransition","state","savedUserSelect","disableTextSelection","document","documentElement","style","webkitUserSelect","restoreTextSelection","setTimeout"],"mappings":"AAYA,SAASA,kBAAT,QAAmC,mBAAnC;AAaA,IAAIC,KAAY,GAAG,SAAnB;AACA,IAAIC,eAAe,GAAG,EAAtB;AAEA,OAAO,SAASC,oBAAT,CAAA,EAAgC;EACrC,IAAIF,KAAK,KAAK,SAAd,EAAyB;IACvBC,eAAe,GAAGE,QAAQ,CAACC,eAATD,CAAyBE,KAAzBF,CAA+BG,gBAAjDL;IACAE,QAAQ,CAACC,eAATD,CAAyBE,KAAzBF,CAA+BG,gBAA/BH,GAAkD,MAAlDA;EACD;EAEDH,KAAK,GAAG,UAARA;AACD;AAED,OAAO,SAASO,oBAAT,CAAA,EAAgC;EAGrC,IAAIP,KAAK,KAAK,UAAd,EAA0B;IACxB;EACD;EAEDA,KAAK,GAAG,WAP6B;EAWrCQ,UAAU,CAAC,YAAM;IAGfT,kBAAkB,CAAC,YAAM;MAEvB,IAAIC,KAAK,KAAK,WAAd,EAA2B;QACzB,IAAIG,QAAQ,CAACC,eAATD,CAAyBE,KAAzBF,CAA+BG,gBAA/BH,KAAoD,MAAxD,EAAgE;UAC9DA,QAAQ,CAACC,eAATD,CAAyBE,KAAzBF,CAA+BG,gBAA/BH,GACEF,eAAe,IAAI,EADrBE;QAED;QAEDF,eAAe,GAAG,EAAlBA;QACAD,KAAK,GAAG,SAARA;MACD;IACF,CAXiB,CAAlBD;EAYD,CAfS,EAeP,GAfO,CAAVS;AAgBD","sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { runAfterTransition } from '@react-aria/utils';\n\n// Safari on iOS starts selecting text on long press. The only way to avoid this, it seems,\n// is to add user-select: none to the entire page. Adding it to the pressable element prevents\n// that element from being selected, but nearby elements may still receive selection. We add\n// user-select: none on touch start, and remove it again on touch end to prevent this.\n// This must be implemented using global state to avoid race conditions between multiple elements.\n\n// There are three possible states due to the delay before removing user-select: none after\n// pointer up. The 'default' state always transitions to the 'disabled' state, which transitions\n// to 'restoring'. The 'restoring' state can either transition back to 'disabled' or 'default'.\ntype State = 'default' | 'disabled' | 'restoring';\n\nlet state: State = 'default';\nlet savedUserSelect = '';\n\nexport function disableTextSelection() {\n  if (state === 'default') {\n    savedUserSelect = document.documentElement.style.webkitUserSelect;\n    document.documentElement.style.webkitUserSelect = 'none';\n  }\n\n  state = 'disabled';\n}\n\nexport function restoreTextSelection() {\n  // If the state is already default, there's nothing to do.\n  // If it is restoring, then there's no need to queue a second restore.\n  if (state !== 'disabled') {\n    return;\n  }\n\n  state = 'restoring';\n\n  // There appears to be a delay on iOS where selection still might occur\n  // after pointer up, so wait a bit before removing user-select.\n  setTimeout(() => {\n    // Wait for any CSS transitions to complete so we don't recompute style\n    // for the whole page in the middle of the animation and cause jank.\n    runAfterTransition(() => {\n      // Avoid race conditions\n      if (state === 'restoring') {\n        if (document.documentElement.style.webkitUserSelect === 'none') {\n          document.documentElement.style.webkitUserSelect =\n            savedUserSelect || '';\n        }\n\n        savedUserSelect = '';\n        state = 'default';\n      }\n    });\n  }, 300);\n}\n"]},"metadata":{},"sourceType":"module"}