{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport _react, { useContext, useLayoutEffect, useMemo, useState } from \"react\";\nvar $f01a183cc7bdff77849e49ad26eb904$var$defaultContext = {\n  prefix: Math.round(Math.random() * 10000000000),\n  current: 0\n};\n\nvar $f01a183cc7bdff77849e49ad26eb904$var$SSRContext = _react.createContext($f01a183cc7bdff77849e49ad26eb904$var$defaultContext);\n\nexport function SSRProvider(props) {\n  var cur = useContext($f01a183cc7bdff77849e49ad26eb904$var$SSRContext);\n  var value = useMemo(function () {\n    return {\n      prefix: cur === $f01a183cc7bdff77849e49ad26eb904$var$defaultContext ? 0 : ++cur.prefix,\n      current: 0\n    };\n  }, [cur]);\n  return _react.createElement($f01a183cc7bdff77849e49ad26eb904$var$SSRContext.Provider, {\n    value: value\n  }, props.children);\n}\nvar $f01a183cc7bdff77849e49ad26eb904$var$canUseDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);\nexport function useSSRSafeId(defaultId) {\n  var ctx = useContext($f01a183cc7bdff77849e49ad26eb904$var$SSRContext);\n\n  if (ctx === $f01a183cc7bdff77849e49ad26eb904$var$defaultContext && !$f01a183cc7bdff77849e49ad26eb904$var$canUseDOM) {\n    console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');\n  }\n\n  return useMemo(function () {\n    return defaultId || \"react-aria-\" + ctx.prefix + \"-\" + ++ctx.current;\n  }, [defaultId]);\n}\nexport function useIsSSR() {\n  var cur = useContext($f01a183cc7bdff77849e49ad26eb904$var$SSRContext);\n  var isInSSRContext = cur !== $f01a183cc7bdff77849e49ad26eb904$var$defaultContext;\n\n  var _useState = useState(isInSSRContext),\n      _useState2 = _slicedToArray(_useState, 2),\n      isSSR = _useState2[0],\n      setIsSSR = _useState2[1];\n\n  if (typeof window !== 'undefined' && isInSSRContext) {\n    useLayoutEffect(function () {\n      setIsSSR(false);\n    }, []);\n  }\n\n  return isSSR;\n}","map":{"version":3,"sources":["packages/@react-aria/ssr/src/SSRProvider.tsx"],"names":["defaultContext","prefix","Math","current","SSRContext","React","cur","useContext","value","useMemo","props","canUseDOM","Boolean","window","ctx","console","defaultId","isInSSRContext","useState","useLayoutEffect","setIsSSR"],"mappings":";;AA8BA,IAAMA,mDAA+B,GAAG;AACtCC,EAAAA,MAAM,EAAEC,IAAI,CAAJA,KAAAA,CAAWA,IAAI,CAAJA,MAAAA,KADmB,WAC9BA,CAD8B;AAEtCC,EAAAA,OAAO,EAAE;AAF6B,CAAxC;;AAKA,IAAMC,+CAAU,GAAGC,MAAK,CAALA,aAAAA,CAAnB,mDAAmBA,CAAnB;;OAWO,SAAA,WAAA,CAAA,KAAA,EAA2D;AAChE,MAAIC,GAAG,GAAGC,UAAU,CAApB,+CAAoB,CAApB;AACA,MAAIC,KAAsB,GAAGC,OAAO,CAAC;AAAA,WAAO;AAE1CR,MAAAA,MAAM,EAAEK,GAAG,KAAHA,mDAAAA,GAAAA,CAAAA,GAA6B,EAAEA,GAAG,CAFA,MAAA;AAG1CH,MAAAA,OAAO,EAAE;AAHiC,KAAP;AAAA,GAAD,EAIhC,CAJJ,GAII,CAJgC,CAApC;AAMA,SACE,MAAA,CAAA,aAAA,CAAC,+CAAD,CAAA,QAAA,EAAA;AAAqB,IAAA,KAAK,EAAEK;AAA5B,GAAA,EACGE,KAAK,CAFV,QACE,CADF;AAKD;AAED,IAAIC,8CAAS,GAAGC,OAAO,CACrB,OAAA,MAAA,KAAA,WAAA,IACAC,MAAM,CADN,QAAA,IAEAA,MAAM,CAANA,QAAAA,CAHF,aAAuB,CAAvB;OAOO,SAAA,YAAA,CAAA,SAAA,EAAkD;AACvD,MAAIC,GAAG,GAAGP,UAAU,CADmC,+CACnC,CAApB;;AAIA,MAAIO,GAAG,KAAHA,mDAAAA,IAA0B,CAA9B,8CAAA,EAA0C;AACxCC,IAAAA,OAAO,CAAPA,IAAAA,CAAAA,iJAAAA;AACD;;AAED,SAAON,OAAO,CAAC;AAAA,WAAMO,SAAS,IAAA,gBAAkBF,GAAG,CAArB,MAAA,GAAA,GAAA,GAAgC,EAAEA,GAAG,CAArD,OAAC;AAAA,GAAD,EAAiE,CAA/E,SAA+E,CAAjE,CAAd;AACD;OAOM,SAAA,QAAA,GAA6B;AAClC,MAAIR,GAAG,GAAGC,UAAU,CAApB,+CAAoB,CAApB;AACA,MAAIU,cAAc,GAAGX,GAAG,KAAxB,mDAAA;;AAFkC,kBAGVY,QAAQ,CAHE,cAGF,CAHE;AAAA;AAAA,MAG9B,KAH8B;AAAA,MAG9B,QAH8B;;AAOlC,MAAI,OAAA,MAAA,KAAA,WAAA,IAAJ,cAAA,EAAqD;AAInDC,IAAAA,eAAe,CAAC,YAAM;AACpBC,MAAAA,QAAQ,CAARA,KAAQ,CAARA;AADa,KAAA,EAAfD,EAAe,CAAfA;AAGD;;AAED,SAAA,KAAA;AACD","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 React, {ReactNode, useContext, useLayoutEffect, useMemo, useState} from 'react';\n\n// To support SSR, the auto incrementing id counter is stored in a context. This allows\n// it to be reset on every request to ensure the client and server are consistent.\n// There is also a prefix counter that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which increments the prefix\n// and resets the current id counter. This ensures that async loaded components have\n// consistent ids regardless  of the loading order.\ninterface SSRContextValue {\n  prefix: number,\n  current: number\n}\n\n// Default context value to use in case there is no SSRProvider. This is fine for\n// client-only apps. In order to support multiple copies of React Aria potentially\n// being on the page at once, the prefix is set to a random number. SSRProvider\n// will reset this to zero for consistency between server and client, so in the\n// SSR case multiple copies of React Aria is not supported.\nconst defaultContext: SSRContextValue = {\n  prefix: Math.round(Math.random() * 10000000000),\n  current: 0\n};\n\nconst SSRContext = React.createContext<SSRContextValue>(defaultContext);\n\ninterface SSRProviderProps {\n  /** Your application here. */\n  children: ReactNode\n}\n\n/**\n * When using SSR with React Aria, applications must be wrapped in an SSRProvider.\n * This ensures that auto generated ids are consistent between the client and server.\n */\nexport function SSRProvider(props: SSRProviderProps): JSX.Element {\n  let cur = useContext(SSRContext);\n  let value: SSRContextValue = useMemo(() => ({\n    // If this is the first SSRProvider, set to zero, otherwise increment.\n    prefix: cur === defaultContext ? 0 : ++cur.prefix,\n    current: 0\n  }), [cur]);\n\n  return (\n    <SSRContext.Provider value={value}>\n      {props.children}\n    </SSRContext.Provider>\n  );\n}\n\nlet canUseDOM = Boolean(\n  typeof window !== 'undefined' &&\n  window.document &&\n  window.document.createElement\n);\n\n/** @private */\nexport function useSSRSafeId(defaultId?: string): string {\n  let ctx = useContext(SSRContext);\n\n  // If we are rendering in a non-DOM environment, and there's no SSRProvider,\n  // provide a warning to hint to the developer to add one.\n  if (ctx === defaultContext && !canUseDOM) {\n    console.warn('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.');\n  }\n\n  return useMemo(() => defaultId || `react-aria-${ctx.prefix}-${++ctx.current}`, [defaultId]);\n}\n\n/**\n * Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nexport function useIsSSR(): boolean {\n  let cur = useContext(SSRContext);\n  let isInSSRContext = cur !== defaultContext;\n  let [isSSR, setIsSSR] = useState(isInSSRContext);\n\n  // If on the client, and the component was initially server rendered,\n  // then schedule a layout effect to update the component after hydration.\n  if (typeof window !== 'undefined' && isInSSRContext) {\n    // This if statement technically breaks the rules of hooks, but is safe\n    // because the condition never changes after mounting.\n    // eslint-disable-next-line react-hooks/rules-of-hooks\n    useLayoutEffect(() => {\n      setIsSSR(false);\n    }, []);\n  }\n\n  return isSSR;\n}\n"]},"metadata":{},"sourceType":"module"}