{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport $fZ9Rb$react, { useContext as $fZ9Rb$useContext, useMemo as $fZ9Rb$useMemo, useState as $fZ9Rb$useState, useLayoutEffect as $fZ9Rb$useLayoutEffect } from \"react\";\n\nfunction $parcel$export(e, n, v, s) {\n  Object.defineProperty(e, n, {\n    get: v,\n    set: s,\n    enumerable: true,\n    configurable: true\n  });\n}\n\nvar $6f523efd7517f7a2$exports = {};\n$parcel$export($6f523efd7517f7a2$exports, \"SSRProvider\", function () {\n  return $6f523efd7517f7a2$export$9f8ac96af4b1b2ae;\n});\n$parcel$export($6f523efd7517f7a2$exports, \"useSSRSafeId\", function () {\n  return $6f523efd7517f7a2$export$619500959fc48b26;\n});\n$parcel$export($6f523efd7517f7a2$exports, \"useIsSSR\", function () {\n  return $6f523efd7517f7a2$export$535bd6ca7f90a273;\n});\nvar $6f523efd7517f7a2$var$defaultContext = {\n  prefix: String(Math.round(Math.random() * 10000000000)),\n  current: 0\n};\nvar $6f523efd7517f7a2$var$SSRContext = $fZ9Rb$react.createContext($6f523efd7517f7a2$var$defaultContext);\n\nfunction $6f523efd7517f7a2$export$9f8ac96af4b1b2ae(props) {\n  var cur = $fZ9Rb$useContext($6f523efd7517f7a2$var$SSRContext);\n  var value = $fZ9Rb$useMemo(function () {\n    return {\n      prefix: cur === $6f523efd7517f7a2$var$defaultContext ? '' : cur.prefix + \"-\" + ++cur.current,\n      current: 0\n    };\n  }, [cur]);\n  return $fZ9Rb$react.createElement($6f523efd7517f7a2$var$SSRContext.Provider, {\n    value: value\n  }, props.children);\n}\n\nvar $6f523efd7517f7a2$var$canUseDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);\n\nfunction $6f523efd7517f7a2$export$619500959fc48b26(defaultId) {\n  var ctx = $fZ9Rb$useContext($6f523efd7517f7a2$var$SSRContext);\n  if (ctx === $6f523efd7517f7a2$var$defaultContext && !$6f523efd7517f7a2$var$canUseDOM) 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  return $fZ9Rb$useMemo(function () {\n    return defaultId || \"react-aria\" + ctx.prefix + \"-\" + ++ctx.current;\n  }, [defaultId]);\n}\n\nfunction $6f523efd7517f7a2$export$535bd6ca7f90a273() {\n  var cur = $fZ9Rb$useContext($6f523efd7517f7a2$var$SSRContext);\n  var isInSSRContext = cur !== $6f523efd7517f7a2$var$defaultContext;\n\n  var _$fZ9Rb$useState = $fZ9Rb$useState(isInSSRContext),\n      _$fZ9Rb$useState2 = _slicedToArray(_$fZ9Rb$useState, 2),\n      isSSR = _$fZ9Rb$useState2[0],\n      setIsSSR = _$fZ9Rb$useState2[1];\n\n  if (typeof window !== 'undefined' && isInSSRContext) $fZ9Rb$useLayoutEffect(function () {\n      setIsSSR(false);\n    }, []);\n  return isSSR;\n}\n\nexport { $6f523efd7517f7a2$export$9f8ac96af4b1b2ae as SSRProvider, $6f523efd7517f7a2$export$619500959fc48b26 as useSSRSafeId, $6f523efd7517f7a2$export$535bd6ca7f90a273 as useIsSSR };","map":{"version":3,"sources":["packages/@react-aria/ssr/src/SSRProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAM,oCAAc,GAAoB;AACtC,EAAA,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAL,CAAW,IAAI,CAAC,MAAL,KAAgB,WAA3B,CAAD,CADwB;AAEtC,EAAA,OAAO,EAAE;AAF6B,CAAxC;AAKA,IAAM,gCAAU,GAAG,YAAK,CAAC,aAAN,CAAqC,oCAArC,CAAnB;;SAWgB,yC,CAAY,K,EAAsC;AAChE,MAAI,GAAG,GAAG,iBAAU,CAAC,gCAAD,CAApB;AACA,MAAI,KAAK,GAAoB,cAAO,CAAA;AAAA,WAAQ;AAG1C,MAAA,MAAM,EAAE,GAAG,KAAK,oCAAR,GAAyB,EAAzB,GAAiC,GAAG,CAAC,MAArC,SAA6C,EAAI,GAAG,CAAC,OAHnB;AAI1C,MAAA,OAAO,EAAE;AAJiC,KAAR;AAAA,GAAA,EAKhC,CAAC,GAAD,CALgC,CAApC;AAOA,SAAM,YAAA,CAAA,aAAA,CACH,gCAAU,CAAC,QADR,EACgB;AAAC,IAAA,KAAK,EAAE;AAAR,GADhB,EAED,KAAK,CAAC,QAFL,CAAN;AAKD;;AAED,IAAI,+BAAS,GAAG,OAAO,CACrB,OAAO,MAAP,KAAkB,WAAlB,IACA,MAAM,CAAC,QADP,IAEA,MAAM,CAAC,QAAP,CAAgB,aAHK,CAAvB;;SAOgB,yC,CAAa,S,EAA4B;AACvD,MAAI,GAAG,GAAG,iBAAU,CAAC,gCAAD,CAApB;AAIA,MAAI,GAAG,KAAK,oCAAR,IAAsB,CAAK,+BAA/B,EACE,OAAO,CAAC,IAAR,CAAa,iJAAb;AAGF,SAAO,cAAO,CAAA;AAAA,WAAO,SAAS,mBAAiB,GAAG,CAAC,MAArB,SAA6B,EAAI,GAAG,CAAC,OAArD;AAAA,GAAA,EAAgE,CAAC,SAAD,CAAhE,CAAd;AACD;;SAOe,yC,GAAoB;AAClC,MAAI,GAAG,GAAG,iBAAU,CAAC,gCAAD,CAApB;AACA,MAAI,cAAc,GAAG,GAAG,KAAK,oCAA7B;;AACA,yBAAwB,eAAQ,CAAC,cAAD,CAAhC;AAAA;AAAA,MAAK,KAAL;AAAA,MAAY,QAAZ;;AAIA,MAAI,OAAO,MAAP,KAAkB,WAAlB,IAAiC,cAArC,EAIE,sBAAe,CAAA,YAAO;AACpB,MAAA,QAAQ,CAAC,KAAD,CAAR;AACD,KAFc,EAEZ,EAFY,CAAf;AAKF,SAAO,KAAP;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\n// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is\n// guarded by a check that it only runs on the client side.\n// eslint-disable-next-line rulesdir/useLayoutEffectRule\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 string that is used to support async loading components\n// Each async boundary must be wrapped in an SSR provider, which appends to 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: string,\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: String(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, start with an empty string prefix, otherwise\n    // append and increment the counter.\n    prefix: cur === defaultContext ? '' : `${cur.prefix}-${++cur.current}`,\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"}