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AC;QACvC,QAAQ,OAAO,qBAAqB,CAAC;YACnC,IAAI,gBAAgB,SAAS,QAAQ,KAAK,CAAA,GAAA,0CAAe,MAAM;YAC/D,IAAI,mBAAmB,CAAA,GAAA,0CAAe,EAAE;YAExC,2DAA2D;YAC3D,IAAI,CAAA,GAAA,wCAAa,QAAQ,kBACvB,OAAO,GAAG;YAGZ,iEAAiE;YACjE,IAAI,CAAA,GAAA,wCAAa,OAAO,CAAC,kBACvB,OAAO,GAAG;YAGZ,sCAAgB,GAAG,CAAC;YAEpB,IAAI,CAAC,wCAAkB,GAAG,CAAC,SACzB,wCAAkB,GAAG,CAAC,QAAQ;QAElC;IACF;IAEA,OAAO;QACL,OAAO,oBAAoB,CAAC;QAC5B,sCAAgB,MAAM,CAAC;IACzB;AACF;AAMO,SAAS,0CAA2B,EAAkB;IAC3D,0FAA0F;IAC1F,sEAAsE;IACtE,IAAI,CAAC,CAAA,GAAA,0CAAe,KAClB,OAAQ,GAAG,QAAQ,KAAO;IAG5B,qDAAqD;IACrD,IAAI,QAAQ,OAAO,qBAAqB,CAAC;QACvC,QAAQ,OAAO,qBAAqB,CAAC;YACnC,IAAI,gBAAgB,SAAS,QAAQ,KAAK,CAAA,GAAA,0CAAe,MAAM;YAC/D,IAAI,mBAAmB,CAAA,GAAA,0CAAe,EAAE;YAExC,kDAAkD;YAClD,IAAI,CAAA,GAAA,wCAAa,QAAQ,kBACvB,OAAO,GAAG;YAGZ,0CAAoB,GAAG,CAAC;YAExB,IAAI,CAAC,wCAAkB,GAAG,CAAC,SACzB,wCAAkB,GAAG,CAAC,QAAQ;QAElC;IACF;IAEA,OAAO;QACL,OAAO,oBAAoB,CAAC;QAC5B,0CAAoB,MAAM,CAAC;IAC7B;AACF","sources":["packages/react-aria/src/utils/runAfterKeyboard.ts"],"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 {getActiveElement} from './shadowdom/DOMFunctions';\nimport {isKeyboardOpen, supportsKeyboard, willOpenKeyboard} from './keyboard';\nimport {isWebKit} from './platform';\n\nconst WEBKIT_OPEN_DELAY = 200;\nconst TRANSITION_FRAMETIME = 50;\nconst TRANSITION_TIMEOUT = 600;\n\nconst listenersByWindow = new WeakMap<EventTarget, number | undefined>();\nconst transitionCallbacks = new Set<QueuedCallback>();\nconst resizeCallbacks = new Set<QueuedCallback>();\n\ninterface QueuedCallback {\n  (isKeyboardOpen: boolean): void;\n}\n\nfunction onTransitionFrame(wasOpenKeyboard: boolean, signal: AbortSignal): void {\n  let isOpenKeyboard = isKeyboardOpen();\n\n  // Flush resize callbacks when the keyboard has affected layout or we ran out of time.\n  if (wasOpenKeyboard !== isOpenKeyboard || signal.aborted) {\n    for (let callback of resizeCallbacks) {\n      callback(isOpenKeyboard);\n      resizeCallbacks.delete(callback);\n    }\n  }\n\n  // WebKit only fires a single resize event at the start of an opening transition.\n  // The animation takes ~200ms, so restart the listener and flush when it runs out of time.\n  if (!wasOpenKeyboard && isOpenKeyboard && isWebKit() && !signal.aborted) {\n    window.clearInterval(listenersByWindow.get(window));\n    listenersByWindow.set(window, setupGlobalListeners(WEBKIT_OPEN_DELAY));\n    return;\n  }\n\n  // Flush transition callbacks when the animation has completed or we ran out of time.\n  if (wasOpenKeyboard !== isOpenKeyboard || signal.aborted) {\n    for (let callback of transitionCallbacks) {\n      callback(isOpenKeyboard);\n      transitionCallbacks.delete(callback);\n    }\n  }\n\n  // Cancel the observer when no pending updates remain or we ran out of time.\n  if (resizeCallbacks.size + transitionCallbacks.size <= 0 || signal.aborted) {\n    window.clearInterval(listenersByWindow.get(window));\n    listenersByWindow.delete(window);\n  }\n}\n\nfunction setupGlobalListeners(timeout = TRANSITION_TIMEOUT): number {\n  return window.setInterval(\n    onTransitionFrame,\n    TRANSITION_FRAMETIME,\n    isKeyboardOpen(),\n    AbortSignal.timeout(timeout)\n  );\n}\n\n/**\n * Delays a callback execution until a keyboard transition may no longer impact layout.\n * Guarantees an invocation if an expected transition did not finish within 300ms.\n */\nexport function runAfterKeyboard(fn: QueuedCallback): () => void {\n  // Flush synchronously when keyboard is unsupported. This is default for non-touch devices\n  // or devices which did not open their OSK within our opening timeout.\n  if (!supportsKeyboard()) {\n    return (fn(false), () => {});\n  }\n\n  // Wait two frames to see if focus lands on an input.\n  let frame = window.requestAnimationFrame(() => {\n    frame = window.requestAnimationFrame(() => {\n      let activeElement = document.hasFocus() ? getActiveElement() : null;\n      let willKeyboardOpen = willOpenKeyboard(activeElement);\n\n      // If keyboard won't change, call the function immediately.\n      if (isKeyboardOpen() === willKeyboardOpen) {\n        return fn(willKeyboardOpen);\n      }\n\n      // On close, fire immediately since consumers may assert the ICB.\n      if (isKeyboardOpen() && !willKeyboardOpen) {\n        return fn(willKeyboardOpen);\n      }\n\n      resizeCallbacks.add(fn);\n\n      if (!listenersByWindow.has(window)) {\n        listenersByWindow.set(window, setupGlobalListeners());\n      }\n    });\n  });\n\n  return () => {\n    window.cancelAnimationFrame(frame);\n    resizeCallbacks.delete(fn);\n  };\n}\n\n/**\n * Delays a callback execution until the on-screen keyboard has finished its transition.\n * Guarantees an invocation if an expected transition did not finish within 600ms.\n */\nexport function runAfterKeyboardTransition(fn: QueuedCallback): () => void {\n  // Flush synchronously when keyboard is unsupported. This is default for non-touch devices\n  // or devices which did not open their OSK within our opening timeout.\n  if (!supportsKeyboard()) {\n    return (fn(false), () => {});\n  }\n\n  // Wait two frames to see if focus lands on an input.\n  let frame = window.requestAnimationFrame(() => {\n    frame = window.requestAnimationFrame(() => {\n      let activeElement = document.hasFocus() ? getActiveElement() : null;\n      let willKeyboardOpen = willOpenKeyboard(activeElement);\n\n      // If keyboard won't transition, fire immediately.\n      if (isKeyboardOpen() === willKeyboardOpen) {\n        return fn(willKeyboardOpen);\n      }\n\n      transitionCallbacks.add(fn);\n\n      if (!listenersByWindow.has(window)) {\n        listenersByWindow.set(window, setupGlobalListeners());\n      }\n    });\n  });\n\n  return () => {\n    window.cancelAnimationFrame(frame);\n    transitionCallbacks.delete(fn);\n  };\n}\n"],"names":[],"version":3,"file":"runAfterKeyboard.cjs.map"}