{"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\n  state = 'disabled';\n}\nexport function restoreTextSelection() {\n  if (state !== 'disabled') {\n    return;\n  }\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\n        savedUserSelect = '';\n        state = 'default';\n      }\n    });\n  }, 300);\n}","map":{"version":3,"sources":["textSelection.ts"],"names":["state","savedUserSelect","document","setTimeout","runAfterTransition"],"mappings":"AAYA,SAAA,kBAAA,QAAA,mBAAA;AAaA,IAAIA,KAAY,GAAhB,SAAA;AACA,IAAIC,eAAe,GAAnB,EAAA;AAEA,OAAO,SAAA,oBAAA,GAAgC;AACrC,MAAID,KAAK,KAAT,SAAA,EAAyB;AACvBC,IAAAA,eAAe,GAAGC,QAAQ,CAARA,eAAAA,CAAAA,KAAAA,CAAlBD,gBAAAA;AACAC,IAAAA,QAAQ,CAARA,eAAAA,CAAAA,KAAAA,CAAAA,gBAAAA,GAAAA,MAAAA;AACD;;AAEDF,EAAAA,KAAK,GAALA,UAAAA;AACD;AAED,OAAO,SAAA,oBAAA,GAAgC;AAGrC,MAAIA,KAAK,KAAT,UAAA,EAA0B;AACxB;AACD;;AAEDA,EAAAA,KAAK,GAPgC,WAOrCA;AAIAG,EAAAA,UAAU,CAAC,YAAM;AAGfC,IAAAA,kBAAkB,CAAC,YAAM;AAEvB,UAAIJ,KAAK,KAAT,WAAA,EAA2B;AACzB,YAAIE,QAAQ,CAARA,eAAAA,CAAAA,KAAAA,CAAAA,gBAAAA,KAAJ,MAAA,EAAgE;AAC9DA,UAAAA,QAAQ,CAARA,eAAAA,CAAAA,KAAAA,CAAAA,gBAAAA,GACED,eAAe,IADjBC,EAAAA;AAED;;AAEDD,QAAAA,eAAe,GAAfA,EAAAA;AACAD,QAAAA,KAAK,GAALA,SAAAA;AACD;AAVHI,KAAkB,CAAlBA;AAHQ,GAAA,EAAVD,GAAU,CAAVA;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"}