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tC;AAEA;;;;CAIC,GACD,SAAS;IACP,KAAK,MAAM,CAAC,YAAY,IAAI,2CAC1B,sFAAsF;IACtF,kFAAkF;IAClF,IAAI,iBAAiB,eAAe,CAAC,YAAY,WAAW,EAC1D,2CAAqB,MAAM,CAAC;AAGlC;AAEA,IAAI,OAAO,aAAa;IACtB,IAAI,SAAS,UAAU,KAAK,WAC1B;SAEA,CAAA,GAAA,kCAAO,EAAE,UAAU,oBAAoB;;AAOpC,SAAS,0CAAmB,EAAkB;IACnD,4EAA4E;IAC5E,IAAI,QAAQ,OAAO,qBAAqB,CAAC;QACvC;QAEA,gEAAgE;QAChE,+EAA+E;QAC/E,IAAI,2CAAqB,IAAI,KAAK,GAChC,OAAO,GAAG;QAGZ,0CAAoB,GAAG,CAAC;IAC1B;IAEA,OAAO;QACL,OAAO,oBAAoB,CAAC;QAC5B,0CAAoB,MAAM,CAAC;IAC7B;AACF","sources":["packages/react-aria/src/utils/runAfterTransition.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 {addEvent} from './domHelpers';\nimport {getEventTarget} from './shadowdom/DOMFunctions';\n\n// We store a global list of elements that are currently transitioning,\n// mapped to a set of CSS properties that are transitioning for that element.\n// This is necessary rather than a simple count of transitions because of browser\n// bugs, e.g. Chrome sometimes fires both transitionend and transitioncancel rather\n// than one or the other. So we need to track what's actually transitioning so that\n// we can ignore these duplicate events.\nconst transitionsByElement = new Map<EventTarget, Set<string>>();\nconst transitionCallbacks = new Set<QueuedCallback>();\n\ninterface QueuedCallback {\n  (isTransition: boolean): void;\n}\n\nfunction isTransitionEvent(event: Event): event is TransitionEvent {\n  return 'propertyName' in event;\n}\n\nfunction onTransitionStart(e: Event) {\n  let eventTarget = getEventTarget(e);\n\n  if (!isTransitionEvent(e) || !eventTarget) {\n    return;\n  }\n\n  // Add the transitioning property to the list for this element.\n  let transitions = transitionsByElement.get(eventTarget);\n\n  if (!transitions) {\n    transitions = new Set();\n    transitionsByElement.set(eventTarget, transitions);\n\n    // The transitioncancel event must be registered on the element itself, rather than as a global\n    // event. This enables us to handle when the node is deleted from the document while it is transitioning.\n    // In that case, the cancel event would have nowhere to bubble to so we need to handle it directly.\n    eventTarget.addEventListener('transitioncancel', onTransitionEnd, {once: true});\n  }\n\n  transitions.add(e.propertyName);\n}\n\nfunction onTransitionEnd(e: Event) {\n  let eventTarget = getEventTarget(e);\n\n  if (!isTransitionEvent(e) || !eventTarget) {\n    return;\n  }\n\n  // Remove property from list of transitioning properties.\n  let properties = transitionsByElement.get(eventTarget);\n\n  if (!properties) {\n    return;\n  }\n\n  properties.delete(e.propertyName);\n\n  // If empty, remove transitioncancel event, and remove the element from the list of transitioning elements.\n  if (properties.size === 0) {\n    eventTarget.removeEventListener('transitioncancel', onTransitionEnd);\n    transitionsByElement.delete(eventTarget);\n  }\n\n  // If no transitioning elements, call all of the queued callbacks.\n  if (transitionsByElement.size === 0) {\n    for (let callback of transitionCallbacks) {\n      callback(true);\n      transitionCallbacks.delete(callback);\n    }\n  }\n}\n\nfunction setupGlobalEvents() {\n  addEvent(document, 'transitionrun', onTransitionStart);\n  addEvent(document, 'transitionend', onTransitionEnd);\n}\n\n/**\n * Cleans up any elements that are no longer in the document.\n * This is necessary because we can't rely on transitionend events to fire\n * for elements that are removed from the document while transitioning.\n */\nfunction cleanupDetachedElements() {\n  for (const [eventTarget] of transitionsByElement) {\n    // Similar to `eventTarget instanceof Element && !eventTarget.isConnected`, but avoids\n    // the explicit instanceof check, since it may be different in different contexts.\n    if ('isConnected' in eventTarget && !eventTarget.isConnected) {\n      transitionsByElement.delete(eventTarget);\n    }\n  }\n}\n\nif (typeof document !== 'undefined') {\n  if (document.readyState !== 'loading') {\n    setupGlobalEvents();\n  } else {\n    addEvent(document, 'DOMContentLoaded', setupGlobalEvents);\n  }\n}\n\n/**\n * Delays a callback execution until all elements finished their transition.\n */\nexport function runAfterTransition(fn: QueuedCallback): () => void {\n  // Wait one frame to see if an animation starts, e.g. a transition on mount.\n  let frame = window.requestAnimationFrame(() => {\n    cleanupDetachedElements();\n\n    // If no transitions are running, call the function immediately.\n    // Otherwise, add it to a list of callbacks to run at the end of the animation.\n    if (transitionsByElement.size === 0) {\n      return fn(false);\n    }\n\n    transitionCallbacks.add(fn);\n  });\n\n  return () => {\n    window.cancelAnimationFrame(frame);\n    transitionCallbacks.delete(fn);\n  };\n}\n"],"names":[],"version":3,"file":"runAfterTransition.cjs.map"}