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AAS,CAAC,CAAC;IAEpD,OAAO,iBAAiB,GAAG,MAAM,CAAC;AACpC,CAAC;AAED,SAAS,kCAAkC,CAAC,MAAW,EAAE,IAAY;IACnE,kBAAkB;IAClB,KAAK,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACpF,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;QACzC,IAAI,MAAM,EAAE;YACV,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;SAClD;KACF;IAED,aAAa;IACb,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7E,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAE7E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,8BAA8B;AAC9B,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport '@expo/metro-runtime';\n\nimport { ServerContainer, ServerContainerRef } from '@react-navigation/native';\nimport { ctx } from 'expo-router/_ctx';\nimport React from 'react';\nimport ReactDOMServer from 'react-dom/server';\nimport { AppRegistry } from 'react-native-web';\n\nimport { ExpoRoot, ExpoRootProps } from '../ExpoRoot';\nimport { getNavigationConfig } from '../getLinkingConfig';\nimport { getRoutes } from '../getRoutes';\nimport { Head } from '../head';\nimport { loadStaticParamsAsync } from '../loadStaticParamsAsync';\nimport { getRootComponent } from './getRootComponent';\n\n/// <reference types=\"expo-router/index\" />\n\nAppRegistry.registerComponent('App', () => App);\n\n// Must be exported or Fast Refresh won't update the context >:[\nfunction App(props: Omit<ExpoRootProps, 'context'>) {\n  return <ExpoRoot context={ctx} {...props} />;\n}\n\n/** Get the linking manifest from a Node.js process. */\nasync function getManifest(options: any) {\n  const routeTree = getRoutes(ctx, options);\n\n  if (!routeTree) {\n    throw new Error('No routes found');\n  }\n\n  // Evaluate all static params\n  await loadStaticParamsAsync(routeTree);\n\n  return getNavigationConfig(routeTree);\n}\n\nfunction resetReactNavigationContexts() {\n  // https://github.com/expo/router/discussions/588\n  // https://github.com/react-navigation/react-navigation/blob/9fe34b445fcb86e5666f61e144007d7540f014fa/packages/elements/src/getNamedContext.tsx#LL3C1-L4C1\n\n  // React Navigation is storing providers in a global, this is fine for the first static render\n  // but subsequent static renders of Stack or Tabs will cause React to throw a warning. To prevent this warning, we'll reset the globals before rendering.\n  const contexts = '__react_navigation__elements_contexts';\n  global[contexts] = new Map<string, React.Context<any>>();\n}\n\nexport function getStaticContent(location: URL): string {\n  const headContext: { helmet?: any } = {};\n\n  const ref = React.createRef<ServerContainerRef>();\n\n  const {\n    // Skipping the `element` that's returned to ensure the HTML\n    // matches what's used in the client -- this results in two extra Views and\n    // the seemingly unused `RootTagContext.Provider` from being added.\n    getStyleElement,\n  } = AppRegistry.getApplication('App');\n\n  const Root = getRootComponent();\n\n  // This MUST be run before `ReactDOMServer.renderToString` to prevent\n  // \"Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported.\"\n  resetReactNavigationContexts();\n\n  const html = ReactDOMServer.renderToString(\n    <Head.Provider context={headContext}>\n      <ServerContainer ref={ref}>\n        <App\n          location={location}\n          wrapper={({ children }) => {\n            return React.createElement(Root, {\n              children: React.createElement(\n                'div',\n                {\n                  id: 'root',\n                },\n                children\n              ),\n            });\n          }}\n        />\n      </ServerContainer>\n    </Head.Provider>\n  );\n\n  // Eval the CSS after the HTML is rendered so that the CSS is in the same order\n  const css = ReactDOMServer.renderToStaticMarkup(getStyleElement());\n\n  let output = mixHeadComponentsWithStaticResults(headContext.helmet, html);\n\n  output = output.replace('</head>', `${css}</head>`);\n\n  return '<!DOCTYPE html>' + output;\n}\n\nfunction mixHeadComponentsWithStaticResults(helmet: any, html: string) {\n  // Head components\n  for (const key of ['title', 'priority', 'meta', 'link', 'script', 'style'].reverse()) {\n    const result = helmet?.[key]?.toString();\n    if (result) {\n      html = html.replace('<head>', `<head>${result}`);\n    }\n  }\n\n  // attributes\n  html = html.replace('<html ', `<html ${helmet?.htmlAttributes.toString()} `);\n  html = html.replace('<body ', `<body ${helmet?.bodyAttributes.toString()} `);\n\n  return html;\n}\n\n// Re-export for use in server\nexport { getManifest };\n"]}