_document.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Html = Html;
  6. exports.Main = Main;
  7. exports.default = void 0;
  8. var _react = _interopRequireWildcard(require("react"));
  9. var _constants = require("../shared/lib/constants");
  10. var _getPageFiles = require("../server/get-page-files");
  11. var _htmlescape = require("../server/htmlescape");
  12. var _isError = _interopRequireDefault(require("../lib/is-error"));
  13. var _htmlContext = require("../shared/lib/html-context");
  14. class Document extends _react.default.Component {
  15. /**
  16. * `getInitialProps` hook returns the context object with the addition of `renderPage`.
  17. * `renderPage` callback executes `React` rendering logic synchronously to support server-rendering wrappers
  18. */ static getInitialProps(ctx) {
  19. return ctx.defaultGetInitialProps(ctx);
  20. }
  21. render() {
  22. return /*#__PURE__*/ _react.default.createElement(Html, null, /*#__PURE__*/ _react.default.createElement(Head, null), /*#__PURE__*/ _react.default.createElement("body", null, /*#__PURE__*/ _react.default.createElement(Main, null), /*#__PURE__*/ _react.default.createElement(NextScript, null)));
  23. }
  24. }
  25. exports.default = Document;
  26. function _interopRequireDefault(obj) {
  27. return obj && obj.__esModule ? obj : {
  28. default: obj
  29. };
  30. }
  31. function _getRequireWildcardCache() {
  32. if (typeof WeakMap !== "function") return null;
  33. var cache = new WeakMap();
  34. _getRequireWildcardCache = function() {
  35. return cache;
  36. };
  37. return cache;
  38. }
  39. function _interopRequireWildcard(obj) {
  40. if (obj && obj.__esModule) {
  41. return obj;
  42. }
  43. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  44. return {
  45. default: obj
  46. };
  47. }
  48. var cache = _getRequireWildcardCache();
  49. if (cache && cache.has(obj)) {
  50. return cache.get(obj);
  51. }
  52. var newObj = {};
  53. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  54. for(var key in obj){
  55. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  56. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  57. if (desc && (desc.get || desc.set)) {
  58. Object.defineProperty(newObj, key, desc);
  59. } else {
  60. newObj[key] = obj[key];
  61. }
  62. }
  63. }
  64. newObj.default = obj;
  65. if (cache) {
  66. cache.set(obj, newObj);
  67. }
  68. return newObj;
  69. }
  70. function getDocumentFiles(buildManifest, pathname, inAmpMode) {
  71. const sharedFiles = (0, _getPageFiles).getPageFiles(buildManifest, "/_app");
  72. const pageFiles = process.env.NEXT_RUNTIME !== "edge" && inAmpMode ? [] : (0, _getPageFiles).getPageFiles(buildManifest, pathname);
  73. return {
  74. sharedFiles,
  75. pageFiles,
  76. allFiles: [
  77. ...new Set([
  78. ...sharedFiles,
  79. ...pageFiles
  80. ])
  81. ]
  82. };
  83. }
  84. function getPolyfillScripts(context, props) {
  85. // polyfills.js has to be rendered as nomodule without async
  86. // It also has to be the first script to load
  87. const { assetPrefix , buildManifest , devOnlyCacheBusterQueryString , disableOptimizedLoading , crossOrigin , } = context;
  88. return buildManifest.polyfillFiles.filter((polyfill)=>polyfill.endsWith(".js") && !polyfill.endsWith(".module.js")).map((polyfill)=>/*#__PURE__*/ _react.default.createElement("script", {
  89. key: polyfill,
  90. defer: !disableOptimizedLoading,
  91. nonce: props.nonce,
  92. crossOrigin: props.crossOrigin || crossOrigin,
  93. noModule: true,
  94. src: `${assetPrefix}/_next/${polyfill}${devOnlyCacheBusterQueryString}`
  95. }));
  96. }
  97. function hasComponentProps(child) {
  98. return !!child && !!child.props;
  99. }
  100. function AmpStyles({ styles }) {
  101. if (!styles) return null;
  102. // try to parse styles from fragment for backwards compat
  103. const curStyles = Array.isArray(styles) ? styles : [];
  104. if (// @ts-ignore Property 'props' does not exist on type ReactElement
  105. styles.props && // @ts-ignore Property 'props' does not exist on type ReactElement
  106. Array.isArray(styles.props.children)) {
  107. const hasStyles = (el)=>{
  108. var ref, ref1;
  109. return el == null ? void 0 : (ref = el.props) == null ? void 0 : (ref1 = ref.dangerouslySetInnerHTML) == null ? void 0 : ref1.__html;
  110. };
  111. // @ts-ignore Property 'props' does not exist on type ReactElement
  112. styles.props.children.forEach((child)=>{
  113. if (Array.isArray(child)) {
  114. child.forEach((el)=>hasStyles(el) && curStyles.push(el));
  115. } else if (hasStyles(child)) {
  116. curStyles.push(child);
  117. }
  118. });
  119. }
  120. /* Add custom styles before AMP styles to prevent accidental overrides */ return /*#__PURE__*/ _react.default.createElement("style", {
  121. "amp-custom": "",
  122. dangerouslySetInnerHTML: {
  123. __html: curStyles.map((style)=>style.props.dangerouslySetInnerHTML.__html).join("").replace(/\/\*# sourceMappingURL=.*\*\//g, "").replace(/\/\*@ sourceURL=.*?\*\//g, "")
  124. }
  125. });
  126. }
  127. function getDynamicChunks(context, props, files) {
  128. const { dynamicImports , assetPrefix , isDevelopment , devOnlyCacheBusterQueryString , disableOptimizedLoading , crossOrigin , } = context;
  129. return dynamicImports.map((file)=>{
  130. if (!file.endsWith(".js") || files.allFiles.includes(file)) return null;
  131. return /*#__PURE__*/ _react.default.createElement("script", {
  132. async: !isDevelopment && disableOptimizedLoading,
  133. defer: !disableOptimizedLoading,
  134. key: file,
  135. src: `${assetPrefix}/_next/${encodeURI(file)}${devOnlyCacheBusterQueryString}`,
  136. nonce: props.nonce,
  137. crossOrigin: props.crossOrigin || crossOrigin
  138. });
  139. });
  140. }
  141. function getScripts(context, props, files) {
  142. var ref;
  143. const { assetPrefix , buildManifest , isDevelopment , devOnlyCacheBusterQueryString , disableOptimizedLoading , crossOrigin , } = context;
  144. const normalScripts = files.allFiles.filter((file)=>file.endsWith(".js"));
  145. const lowPriorityScripts = (ref = buildManifest.lowPriorityFiles) == null ? void 0 : ref.filter((file)=>file.endsWith(".js"));
  146. return [
  147. ...normalScripts,
  148. ...lowPriorityScripts
  149. ].map((file)=>{
  150. return /*#__PURE__*/ _react.default.createElement("script", {
  151. key: file,
  152. src: `${assetPrefix}/_next/${encodeURI(file)}${devOnlyCacheBusterQueryString}`,
  153. nonce: props.nonce,
  154. async: !isDevelopment && disableOptimizedLoading,
  155. defer: !disableOptimizedLoading,
  156. crossOrigin: props.crossOrigin || crossOrigin
  157. });
  158. });
  159. }
  160. function getPreNextWorkerScripts(context, props) {
  161. const { assetPrefix , scriptLoader , crossOrigin , nextScriptWorkers } = context;
  162. // disable `nextScriptWorkers` in edge runtime
  163. if (!nextScriptWorkers || process.env.NEXT_RUNTIME === "edge") return null;
  164. try {
  165. let { partytownSnippet } = __non_webpack_require__("@builder.io/partytown/integration");
  166. const children = Array.isArray(props.children) ? props.children : [
  167. props.children
  168. ];
  169. // Check to see if the user has defined their own Partytown configuration
  170. const userDefinedConfig = children.find((child)=>{
  171. var ref, ref2;
  172. return hasComponentProps(child) && (child == null ? void 0 : (ref = child.props) == null ? void 0 : (ref2 = ref.dangerouslySetInnerHTML) == null ? void 0 : ref2.__html.length) && "data-partytown-config" in child.props;
  173. });
  174. return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, !userDefinedConfig && /*#__PURE__*/ _react.default.createElement("script", {
  175. "data-partytown-config": "",
  176. dangerouslySetInnerHTML: {
  177. __html: `
  178. partytown = {
  179. lib: "${assetPrefix}/_next/static/~partytown/"
  180. };
  181. `
  182. }
  183. }), /*#__PURE__*/ _react.default.createElement("script", {
  184. "data-partytown": "",
  185. dangerouslySetInnerHTML: {
  186. __html: partytownSnippet()
  187. }
  188. }), (scriptLoader.worker || []).map((file, index)=>{
  189. const { strategy , src , children: scriptChildren , dangerouslySetInnerHTML , ...scriptProps } = file;
  190. let srcProps = {};
  191. if (src) {
  192. // Use external src if provided
  193. srcProps.src = src;
  194. } else if (dangerouslySetInnerHTML && dangerouslySetInnerHTML.__html) {
  195. // Embed inline script if provided with dangerouslySetInnerHTML
  196. srcProps.dangerouslySetInnerHTML = {
  197. __html: dangerouslySetInnerHTML.__html
  198. };
  199. } else if (scriptChildren) {
  200. // Embed inline script if provided with children
  201. srcProps.dangerouslySetInnerHTML = {
  202. __html: typeof scriptChildren === "string" ? scriptChildren : Array.isArray(scriptChildren) ? scriptChildren.join("") : ""
  203. };
  204. } else {
  205. throw new Error("Invalid usage of next/script. Did you forget to include a src attribute or an inline script? https://nextjs.org/docs/messages/invalid-script");
  206. }
  207. return /*#__PURE__*/ _react.default.createElement("script", Object.assign({}, srcProps, scriptProps, {
  208. type: "text/partytown",
  209. key: src || index,
  210. nonce: props.nonce,
  211. "data-nscript": "worker",
  212. crossOrigin: props.crossOrigin || crossOrigin
  213. }));
  214. }));
  215. } catch (err) {
  216. if ((0, _isError).default(err) && err.code !== "MODULE_NOT_FOUND") {
  217. console.warn(`Warning: ${err.message}`);
  218. }
  219. return null;
  220. }
  221. }
  222. function getPreNextScripts(context, props) {
  223. const { scriptLoader , disableOptimizedLoading , crossOrigin } = context;
  224. const webWorkerScripts = getPreNextWorkerScripts(context, props);
  225. const beforeInteractiveScripts = (scriptLoader.beforeInteractive || []).filter((script)=>script.src).map((file, index)=>{
  226. const { strategy , ...scriptProps } = file;
  227. var _defer;
  228. return /*#__PURE__*/ _react.default.createElement("script", Object.assign({}, scriptProps, {
  229. key: scriptProps.src || index,
  230. defer: (_defer = scriptProps.defer) != null ? _defer : !disableOptimizedLoading,
  231. nonce: props.nonce,
  232. "data-nscript": "beforeInteractive",
  233. crossOrigin: props.crossOrigin || crossOrigin
  234. }));
  235. });
  236. return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, webWorkerScripts, beforeInteractiveScripts);
  237. }
  238. function getHeadHTMLProps(props) {
  239. const { crossOrigin , nonce , ...restProps } = props;
  240. // This assignment is necessary for additional type checking to avoid unsupported attributes in <head>
  241. const headProps = restProps;
  242. return headProps;
  243. }
  244. function getAmpPath(ampPath, asPath) {
  245. return ampPath || `${asPath}${asPath.includes("?") ? "&" : "?"}amp=1`;
  246. }
  247. class Head extends _react.default.Component {
  248. static contextType = _htmlContext.HtmlContext;
  249. getCssLinks(files) {
  250. const { assetPrefix , devOnlyCacheBusterQueryString , dynamicImports , crossOrigin , optimizeCss , optimizeFonts , } = this.context;
  251. const cssFiles = files.allFiles.filter((f)=>f.endsWith(".css"));
  252. const sharedFiles = new Set(files.sharedFiles);
  253. // Unmanaged files are CSS files that will be handled directly by the
  254. // webpack runtime (`mini-css-extract-plugin`).
  255. let unmangedFiles = new Set([]);
  256. let dynamicCssFiles = Array.from(new Set(dynamicImports.filter((file)=>file.endsWith(".css"))));
  257. if (dynamicCssFiles.length) {
  258. const existing = new Set(cssFiles);
  259. dynamicCssFiles = dynamicCssFiles.filter((f)=>!(existing.has(f) || sharedFiles.has(f)));
  260. unmangedFiles = new Set(dynamicCssFiles);
  261. cssFiles.push(...dynamicCssFiles);
  262. }
  263. let cssLinkElements = [];
  264. cssFiles.forEach((file)=>{
  265. const isSharedFile = sharedFiles.has(file);
  266. if (!optimizeCss) {
  267. cssLinkElements.push(/*#__PURE__*/ _react.default.createElement("link", {
  268. key: `${file}-preload`,
  269. nonce: this.props.nonce,
  270. rel: "preload",
  271. href: `${assetPrefix}/_next/${encodeURI(file)}${devOnlyCacheBusterQueryString}`,
  272. as: "style",
  273. crossOrigin: this.props.crossOrigin || crossOrigin
  274. }));
  275. }
  276. const isUnmanagedFile = unmangedFiles.has(file);
  277. cssLinkElements.push(/*#__PURE__*/ _react.default.createElement("link", {
  278. key: file,
  279. nonce: this.props.nonce,
  280. rel: "stylesheet",
  281. href: `${assetPrefix}/_next/${encodeURI(file)}${devOnlyCacheBusterQueryString}`,
  282. crossOrigin: this.props.crossOrigin || crossOrigin,
  283. "data-n-g": isUnmanagedFile ? undefined : isSharedFile ? "" : undefined,
  284. "data-n-p": isUnmanagedFile ? undefined : isSharedFile ? undefined : ""
  285. }));
  286. });
  287. if (process.env.NODE_ENV !== "development" && optimizeFonts) {
  288. cssLinkElements = this.makeStylesheetInert(cssLinkElements);
  289. }
  290. return cssLinkElements.length === 0 ? null : cssLinkElements;
  291. }
  292. getPreloadDynamicChunks() {
  293. const { dynamicImports , assetPrefix , devOnlyCacheBusterQueryString , crossOrigin , } = this.context;
  294. return dynamicImports.map((file)=>{
  295. if (!file.endsWith(".js")) {
  296. return null;
  297. }
  298. return /*#__PURE__*/ _react.default.createElement("link", {
  299. rel: "preload",
  300. key: file,
  301. href: `${assetPrefix}/_next/${encodeURI(file)}${devOnlyCacheBusterQueryString}`,
  302. as: "script",
  303. nonce: this.props.nonce,
  304. crossOrigin: this.props.crossOrigin || crossOrigin
  305. });
  306. })// Filter out nulled scripts
  307. .filter(Boolean);
  308. }
  309. getPreloadMainLinks(files) {
  310. const { assetPrefix , devOnlyCacheBusterQueryString , scriptLoader , crossOrigin , } = this.context;
  311. const preloadFiles = files.allFiles.filter((file)=>{
  312. return file.endsWith(".js");
  313. });
  314. return [
  315. ...(scriptLoader.beforeInteractive || []).map((file)=>/*#__PURE__*/ _react.default.createElement("link", {
  316. key: file.src,
  317. nonce: this.props.nonce,
  318. rel: "preload",
  319. href: file.src,
  320. as: "script",
  321. crossOrigin: this.props.crossOrigin || crossOrigin
  322. })),
  323. ...preloadFiles.map((file)=>/*#__PURE__*/ _react.default.createElement("link", {
  324. key: file,
  325. nonce: this.props.nonce,
  326. rel: "preload",
  327. href: `${assetPrefix}/_next/${encodeURI(file)}${devOnlyCacheBusterQueryString}`,
  328. as: "script",
  329. crossOrigin: this.props.crossOrigin || crossOrigin
  330. })),
  331. ];
  332. }
  333. getBeforeInteractiveInlineScripts() {
  334. const { scriptLoader } = this.context;
  335. const { nonce , crossOrigin } = this.props;
  336. return (scriptLoader.beforeInteractive || []).filter((script)=>!script.src && (script.dangerouslySetInnerHTML || script.children)).map((file, index)=>{
  337. const { strategy , children , dangerouslySetInnerHTML , src , ...scriptProps } = file;
  338. let html = "";
  339. if (dangerouslySetInnerHTML && dangerouslySetInnerHTML.__html) {
  340. html = dangerouslySetInnerHTML.__html;
  341. } else if (children) {
  342. html = typeof children === "string" ? children : Array.isArray(children) ? children.join("") : "";
  343. }
  344. return /*#__PURE__*/ _react.default.createElement("script", Object.assign({}, scriptProps, {
  345. dangerouslySetInnerHTML: {
  346. __html: html
  347. },
  348. key: scriptProps.id || index,
  349. nonce: nonce,
  350. "data-nscript": "beforeInteractive",
  351. crossOrigin: crossOrigin || process.env.__NEXT_CROSS_ORIGIN
  352. }));
  353. });
  354. }
  355. getDynamicChunks(files) {
  356. return getDynamicChunks(this.context, this.props, files);
  357. }
  358. getPreNextScripts() {
  359. return getPreNextScripts(this.context, this.props);
  360. }
  361. getScripts(files) {
  362. return getScripts(this.context, this.props, files);
  363. }
  364. getPolyfillScripts() {
  365. return getPolyfillScripts(this.context, this.props);
  366. }
  367. makeStylesheetInert(node) {
  368. return _react.default.Children.map(node, (c)=>{
  369. var ref5, ref3;
  370. if ((c == null ? void 0 : c.type) === "link" && (c == null ? void 0 : (ref5 = c.props) == null ? void 0 : ref5.href) && _constants.OPTIMIZED_FONT_PROVIDERS.some(({ url })=>{
  371. var ref, ref4;
  372. return c == null ? void 0 : (ref = c.props) == null ? void 0 : (ref4 = ref.href) == null ? void 0 : ref4.startsWith(url);
  373. })) {
  374. const newProps = {
  375. ...c.props || {},
  376. "data-href": c.props.href,
  377. href: undefined
  378. };
  379. return /*#__PURE__*/ _react.default.cloneElement(c, newProps);
  380. } else if (c == null ? void 0 : (ref3 = c.props) == null ? void 0 : ref3.children) {
  381. const newProps = {
  382. ...c.props || {},
  383. children: this.makeStylesheetInert(c.props.children)
  384. };
  385. return /*#__PURE__*/ _react.default.cloneElement(c, newProps);
  386. }
  387. return c;
  388. }).filter(Boolean);
  389. }
  390. render() {
  391. const { styles , ampPath , inAmpMode , hybridAmp , canonicalBase , __NEXT_DATA__ , dangerousAsPath , headTags , unstable_runtimeJS , unstable_JsPreload , disableOptimizedLoading , optimizeCss , optimizeFonts , } = this.context;
  392. const disableRuntimeJS = unstable_runtimeJS === false;
  393. const disableJsPreload = unstable_JsPreload === false || !disableOptimizedLoading;
  394. this.context.docComponentsRendered.Head = true;
  395. let { head } = this.context;
  396. let cssPreloads = [];
  397. let otherHeadElements = [];
  398. if (head) {
  399. head.forEach((c)=>{
  400. if (c && c.type === "link" && c.props["rel"] === "preload" && c.props["as"] === "style") {
  401. cssPreloads.push(c);
  402. } else {
  403. c && otherHeadElements.push(c);
  404. }
  405. });
  406. head = cssPreloads.concat(otherHeadElements);
  407. }
  408. let children = _react.default.Children.toArray(this.props.children).filter(Boolean);
  409. // show a warning if Head contains <title> (only in development)
  410. if (process.env.NODE_ENV !== "production") {
  411. children = _react.default.Children.map(children, (child)=>{
  412. var ref;
  413. const isReactHelmet = child == null ? void 0 : (ref = child.props) == null ? void 0 : ref["data-react-helmet"];
  414. if (!isReactHelmet) {
  415. var ref6;
  416. if ((child == null ? void 0 : child.type) === "title") {
  417. console.warn("Warning: <title> should not be used in _document.js's <Head>. https://nextjs.org/docs/messages/no-document-title");
  418. } else if ((child == null ? void 0 : child.type) === "meta" && (child == null ? void 0 : (ref6 = child.props) == null ? void 0 : ref6.name) === "viewport") {
  419. console.warn("Warning: viewport meta tags should not be used in _document.js's <Head>. https://nextjs.org/docs/messages/no-document-viewport-meta");
  420. }
  421. }
  422. return child;
  423. });
  424. if (this.props.crossOrigin) console.warn("Warning: `Head` attribute `crossOrigin` is deprecated. https://nextjs.org/docs/messages/doc-crossorigin-deprecated");
  425. }
  426. if (process.env.NODE_ENV !== "development" && optimizeFonts && !(process.env.NEXT_RUNTIME !== "edge" && inAmpMode)) {
  427. children = this.makeStylesheetInert(children);
  428. }
  429. let hasAmphtmlRel = false;
  430. let hasCanonicalRel = false;
  431. // show warning and remove conflicting amp head tags
  432. head = _react.default.Children.map(head || [], (child)=>{
  433. if (!child) return child;
  434. const { type , props } = child;
  435. if (process.env.NEXT_RUNTIME !== "edge" && inAmpMode) {
  436. let badProp = "";
  437. if (type === "meta" && props.name === "viewport") {
  438. badProp = 'name="viewport"';
  439. } else if (type === "link" && props.rel === "canonical") {
  440. hasCanonicalRel = true;
  441. } else if (type === "script") {
  442. // only block if
  443. // 1. it has a src and isn't pointing to ampproject's CDN
  444. // 2. it is using dangerouslySetInnerHTML without a type or
  445. // a type of text/javascript
  446. if (props.src && props.src.indexOf("ampproject") < -1 || props.dangerouslySetInnerHTML && (!props.type || props.type === "text/javascript")) {
  447. badProp = "<script";
  448. Object.keys(props).forEach((prop)=>{
  449. badProp += ` ${prop}="${props[prop]}"`;
  450. });
  451. badProp += "/>";
  452. }
  453. }
  454. if (badProp) {
  455. console.warn(`Found conflicting amp tag "${child.type}" with conflicting prop ${badProp} in ${__NEXT_DATA__.page}. https://nextjs.org/docs/messages/conflicting-amp-tag`);
  456. return null;
  457. }
  458. } else {
  459. // non-amp mode
  460. if (type === "link" && props.rel === "amphtml") {
  461. hasAmphtmlRel = true;
  462. }
  463. }
  464. return child;
  465. });
  466. const files = getDocumentFiles(this.context.buildManifest, this.context.__NEXT_DATA__.page, process.env.NEXT_RUNTIME !== "edge" && inAmpMode);
  467. var _nonce, _nonce1;
  468. return /*#__PURE__*/ _react.default.createElement("head", Object.assign({}, getHeadHTMLProps(this.props)), this.context.isDevelopment && /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement("style", {
  469. "data-next-hide-fouc": true,
  470. "data-ampdevmode": process.env.NEXT_RUNTIME !== "edge" && inAmpMode ? "true" : undefined,
  471. dangerouslySetInnerHTML: {
  472. __html: `body{display:none}`
  473. }
  474. }), /*#__PURE__*/ _react.default.createElement("noscript", {
  475. "data-next-hide-fouc": true,
  476. "data-ampdevmode": process.env.NEXT_RUNTIME !== "edge" && inAmpMode ? "true" : undefined
  477. }, /*#__PURE__*/ _react.default.createElement("style", {
  478. dangerouslySetInnerHTML: {
  479. __html: `body{display:block}`
  480. }
  481. }))), head, /*#__PURE__*/ _react.default.createElement("meta", {
  482. name: "next-head-count",
  483. content: _react.default.Children.count(head || []).toString()
  484. }), children, optimizeFonts && /*#__PURE__*/ _react.default.createElement("meta", {
  485. name: "next-font-preconnect"
  486. }), process.env.NEXT_RUNTIME !== "edge" && inAmpMode && /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement("meta", {
  487. name: "viewport",
  488. content: "width=device-width,minimum-scale=1,initial-scale=1"
  489. }), !hasCanonicalRel && /*#__PURE__*/ _react.default.createElement("link", {
  490. rel: "canonical",
  491. href: canonicalBase + require("../server/utils").cleanAmpPath(dangerousAsPath)
  492. }), /*#__PURE__*/ _react.default.createElement("link", {
  493. rel: "preload",
  494. as: "script",
  495. href: "https://cdn.ampproject.org/v0.js"
  496. }), /*#__PURE__*/ _react.default.createElement(AmpStyles, {
  497. styles: styles
  498. }), /*#__PURE__*/ _react.default.createElement("style", {
  499. "amp-boilerplate": "",
  500. dangerouslySetInnerHTML: {
  501. __html: `body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}`
  502. }
  503. }), /*#__PURE__*/ _react.default.createElement("noscript", null, /*#__PURE__*/ _react.default.createElement("style", {
  504. "amp-boilerplate": "",
  505. dangerouslySetInnerHTML: {
  506. __html: `body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}`
  507. }
  508. })), /*#__PURE__*/ _react.default.createElement("script", {
  509. async: true,
  510. src: "https://cdn.ampproject.org/v0.js"
  511. })), !(process.env.NEXT_RUNTIME !== "edge" && inAmpMode) && /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, !hasAmphtmlRel && hybridAmp && /*#__PURE__*/ _react.default.createElement("link", {
  512. rel: "amphtml",
  513. href: canonicalBase + getAmpPath(ampPath, dangerousAsPath)
  514. }), this.getBeforeInteractiveInlineScripts(), !optimizeCss && this.getCssLinks(files), !optimizeCss && /*#__PURE__*/ _react.default.createElement("noscript", {
  515. "data-n-css": (_nonce = this.props.nonce) != null ? _nonce : ""
  516. }), !disableRuntimeJS && !disableJsPreload && this.getPreloadDynamicChunks(), !disableRuntimeJS && !disableJsPreload && this.getPreloadMainLinks(files), !disableOptimizedLoading && !disableRuntimeJS && this.getPolyfillScripts(), !disableOptimizedLoading && !disableRuntimeJS && this.getPreNextScripts(), !disableOptimizedLoading && !disableRuntimeJS && this.getDynamicChunks(files), !disableOptimizedLoading && !disableRuntimeJS && this.getScripts(files), optimizeCss && this.getCssLinks(files), optimizeCss && /*#__PURE__*/ _react.default.createElement("noscript", {
  517. "data-n-css": (_nonce1 = this.props.nonce) != null ? _nonce1 : ""
  518. }), this.context.isDevelopment && // this element is used to mount development styles so the
  519. // ordering matches production
  520. // (by default, style-loader injects at the bottom of <head />)
  521. /*#__PURE__*/ _react.default.createElement("noscript", {
  522. id: "__next_css__DO_NOT_USE__"
  523. }), styles || null), /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, {}, ...headTags || []));
  524. }
  525. }
  526. exports.Head = Head;
  527. function handleDocumentScriptLoaderItems(scriptLoader, __NEXT_DATA__, props) {
  528. var ref10, ref7, ref8, ref9;
  529. if (!props.children) return;
  530. const scriptLoaderItems = [];
  531. const children = Array.isArray(props.children) ? props.children : [
  532. props.children
  533. ];
  534. const headChildren = (ref10 = children.find((child)=>child.type === Head)) == null ? void 0 : (ref7 = ref10.props) == null ? void 0 : ref7.children;
  535. const bodyChildren = (ref8 = children.find((child)=>child.type === "body")) == null ? void 0 : (ref9 = ref8.props) == null ? void 0 : ref9.children;
  536. // Scripts with beforeInteractive can be placed inside Head or <body> so children of both needs to be traversed
  537. const combinedChildren = [
  538. ...Array.isArray(headChildren) ? headChildren : [
  539. headChildren
  540. ],
  541. ...Array.isArray(bodyChildren) ? bodyChildren : [
  542. bodyChildren
  543. ],
  544. ];
  545. _react.default.Children.forEach(combinedChildren, (child)=>{
  546. var ref;
  547. if (!child) return;
  548. // When using the `next/script` component, register it in script loader.
  549. if ((ref = child.type) == null ? void 0 : ref.__nextScript) {
  550. if (child.props.strategy === "beforeInteractive") {
  551. scriptLoader.beforeInteractive = (scriptLoader.beforeInteractive || []).concat([
  552. {
  553. ...child.props
  554. },
  555. ]);
  556. return;
  557. } else if ([
  558. "lazyOnload",
  559. "afterInteractive",
  560. "worker"
  561. ].includes(child.props.strategy)) {
  562. scriptLoaderItems.push(child.props);
  563. return;
  564. }
  565. }
  566. });
  567. __NEXT_DATA__.scriptLoader = scriptLoaderItems;
  568. }
  569. class NextScript extends _react.default.Component {
  570. static contextType = _htmlContext.HtmlContext;
  571. getDynamicChunks(files) {
  572. return getDynamicChunks(this.context, this.props, files);
  573. }
  574. getPreNextScripts() {
  575. return getPreNextScripts(this.context, this.props);
  576. }
  577. getScripts(files) {
  578. return getScripts(this.context, this.props, files);
  579. }
  580. getPolyfillScripts() {
  581. return getPolyfillScripts(this.context, this.props);
  582. }
  583. static getInlineScriptSource(context) {
  584. const { __NEXT_DATA__ , largePageDataBytes } = context;
  585. try {
  586. const data = JSON.stringify(__NEXT_DATA__);
  587. const bytes = process.env.NEXT_RUNTIME === "edge" ? new TextEncoder().encode(data).buffer.byteLength : Buffer.from(data).byteLength;
  588. const prettyBytes = require("../lib/pretty-bytes").default;
  589. if (largePageDataBytes && bytes > largePageDataBytes) {
  590. console.warn(`Warning: data for page "${__NEXT_DATA__.page}"${__NEXT_DATA__.page === context.dangerousAsPath ? "" : ` (path "${context.dangerousAsPath}")`} is ${prettyBytes(bytes)} which exceeds the threshold of ${prettyBytes(largePageDataBytes)}, this amount of data can reduce performance.\nSee more info here: https://nextjs.org/docs/messages/large-page-data`);
  591. }
  592. return (0, _htmlescape).htmlEscapeJsonString(data);
  593. } catch (err) {
  594. if ((0, _isError).default(err) && err.message.indexOf("circular structure") !== -1) {
  595. throw new Error(`Circular structure in "getInitialProps" result of page "${__NEXT_DATA__.page}". https://nextjs.org/docs/messages/circular-structure`);
  596. }
  597. throw err;
  598. }
  599. }
  600. render() {
  601. const { assetPrefix , inAmpMode , buildManifest , unstable_runtimeJS , docComponentsRendered , devOnlyCacheBusterQueryString , disableOptimizedLoading , crossOrigin , } = this.context;
  602. const disableRuntimeJS = unstable_runtimeJS === false;
  603. docComponentsRendered.NextScript = true;
  604. if (process.env.NEXT_RUNTIME !== "edge" && inAmpMode) {
  605. if (process.env.NODE_ENV === "production") {
  606. return null;
  607. }
  608. const ampDevFiles = [
  609. ...buildManifest.devFiles,
  610. ...buildManifest.polyfillFiles,
  611. ...buildManifest.ampDevFiles,
  612. ];
  613. return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, disableRuntimeJS ? null : /*#__PURE__*/ _react.default.createElement("script", {
  614. id: "__NEXT_DATA__",
  615. type: "application/json",
  616. nonce: this.props.nonce,
  617. crossOrigin: this.props.crossOrigin || crossOrigin,
  618. dangerouslySetInnerHTML: {
  619. __html: NextScript.getInlineScriptSource(this.context)
  620. },
  621. "data-ampdevmode": true
  622. }), ampDevFiles.map((file)=>/*#__PURE__*/ _react.default.createElement("script", {
  623. key: file,
  624. src: `${assetPrefix}/_next/${file}${devOnlyCacheBusterQueryString}`,
  625. nonce: this.props.nonce,
  626. crossOrigin: this.props.crossOrigin || crossOrigin,
  627. "data-ampdevmode": true
  628. })));
  629. }
  630. if (process.env.NODE_ENV !== "production") {
  631. if (this.props.crossOrigin) console.warn("Warning: `NextScript` attribute `crossOrigin` is deprecated. https://nextjs.org/docs/messages/doc-crossorigin-deprecated");
  632. }
  633. const files = getDocumentFiles(this.context.buildManifest, this.context.__NEXT_DATA__.page, process.env.NEXT_RUNTIME !== "edge" && inAmpMode);
  634. return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, !disableRuntimeJS && buildManifest.devFiles ? buildManifest.devFiles.map((file)=>/*#__PURE__*/ _react.default.createElement("script", {
  635. key: file,
  636. src: `${assetPrefix}/_next/${encodeURI(file)}${devOnlyCacheBusterQueryString}`,
  637. nonce: this.props.nonce,
  638. crossOrigin: this.props.crossOrigin || crossOrigin
  639. })) : null, disableRuntimeJS ? null : /*#__PURE__*/ _react.default.createElement("script", {
  640. id: "__NEXT_DATA__",
  641. type: "application/json",
  642. nonce: this.props.nonce,
  643. crossOrigin: this.props.crossOrigin || crossOrigin,
  644. dangerouslySetInnerHTML: {
  645. __html: NextScript.getInlineScriptSource(this.context)
  646. }
  647. }), disableOptimizedLoading && !disableRuntimeJS && this.getPolyfillScripts(), disableOptimizedLoading && !disableRuntimeJS && this.getPreNextScripts(), disableOptimizedLoading && !disableRuntimeJS && this.getDynamicChunks(files), disableOptimizedLoading && !disableRuntimeJS && this.getScripts(files));
  648. }
  649. }
  650. exports.NextScript = NextScript;
  651. function Html(props) {
  652. const { inAmpMode , docComponentsRendered , locale , scriptLoader , __NEXT_DATA__ , } = (0, _react).useContext(_htmlContext.HtmlContext);
  653. docComponentsRendered.Html = true;
  654. handleDocumentScriptLoaderItems(scriptLoader, __NEXT_DATA__, props);
  655. return /*#__PURE__*/ _react.default.createElement("html", Object.assign({}, props, {
  656. lang: props.lang || locale || undefined,
  657. amp: process.env.NEXT_RUNTIME !== "edge" && inAmpMode ? "" : undefined,
  658. "data-ampdevmode": process.env.NEXT_RUNTIME !== "edge" && inAmpMode && process.env.NODE_ENV !== "production" ? "" : undefined
  659. }));
  660. }
  661. function Main() {
  662. const { docComponentsRendered } = (0, _react).useContext(_htmlContext.HtmlContext);
  663. docComponentsRendered.Main = true;
  664. // @ts-ignore
  665. return /*#__PURE__*/ _react.default.createElement("next-js-internal-body-render-target", null);
  666. }
  667. // Add a special property to the built-in `Document` component so later we can
  668. // identify if a user customized `Document` is used or not.
  669. const InternalFunctionDocument = function InternalFunctionDocument() {
  670. return /*#__PURE__*/ _react.default.createElement(Html, null, /*#__PURE__*/ _react.default.createElement(Head, null), /*#__PURE__*/ _react.default.createElement("body", null, /*#__PURE__*/ _react.default.createElement(Main, null), /*#__PURE__*/ _react.default.createElement(NextScript, null)));
  671. };
  672. Document[_constants.NEXT_BUILTIN_DOCUMENT] = InternalFunctionDocument;
  673. //# sourceMappingURL=_document.js.map