@koine/next 1.0.3 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/Analytics/AnalyticsGoogle.d.ts +5 -6
  2. package/Analytics/AnalyticsGoogle.js +37 -0
  3. package/Analytics/index.d.ts +1 -1
  4. package/Analytics/index.js +1 -0
  5. package/Auth/helpers.d.ts +17 -17
  6. package/Auth/helpers.js +21 -0
  7. package/Auth/index.d.ts +4 -4
  8. package/Auth/index.js +4 -0
  9. package/Auth/useLogin.d.ts +7 -7
  10. package/Auth/useLogin.js +47 -0
  11. package/Auth/useLoginUrl.d.ts +1 -1
  12. package/Auth/useLoginUrl.js +11 -0
  13. package/Auth/useLogout.d.ts +6 -6
  14. package/Auth/useLogout.js +52 -0
  15. package/Favicon/Favicon.d.ts +3 -4
  16. package/Favicon/Favicon.js +4 -0
  17. package/Favicon/index.d.ts +1 -1
  18. package/Favicon/index.js +1 -0
  19. package/Forms/index.d.ts +2 -2
  20. package/Forms/index.js +2 -0
  21. package/Forms/useForm.d.ts +32 -32
  22. package/Forms/useForm.js +33 -0
  23. package/Forms/useSubmit.d.ts +24 -24
  24. package/Forms/useSubmit.js +20 -0
  25. package/Head/Head.d.ts +1 -1
  26. package/Head/Head.js +1 -0
  27. package/Head/index.d.ts +1 -1
  28. package/Head/index.js +1 -0
  29. package/I18n/I18n.d.ts +48 -48
  30. package/I18n/I18n.js +86 -0
  31. package/I18n/index.d.ts +1 -1
  32. package/I18n/index.js +1 -0
  33. package/Img/Img.d.ts +21 -21
  34. package/Img/Img.js +30 -0
  35. package/Img/index.d.ts +1 -1
  36. package/Img/index.js +1 -0
  37. package/Link/Link.d.ts +8 -8
  38. package/Link/Link.js +12 -0
  39. package/Link/index.d.ts +1 -1
  40. package/Link/index.js +1 -0
  41. package/NextProgress/NextProgress.d.ts +13 -14
  42. package/NextProgress/NextProgress.js +38 -0
  43. package/NextProgress/index.d.ts +1 -1
  44. package/NextProgress/index.js +1 -0
  45. package/Seo/Seo.d.ts +3 -3
  46. package/Seo/Seo.js +8 -0
  47. package/Seo/SeoDefaults.d.ts +3 -3
  48. package/Seo/SeoDefaults.js +12 -0
  49. package/Seo/helpers.d.ts +48 -48
  50. package/Seo/helpers.js +113 -0
  51. package/Seo/index.d.ts +12 -12
  52. package/Seo/index.js +12 -0
  53. package/Theme/Theme.d.ts +46 -46
  54. package/Theme/Theme.js +235 -0
  55. package/Theme/index.d.ts +1 -1
  56. package/Theme/index.js +1 -0
  57. package/app/App--emotion.d.ts +10 -10
  58. package/app/App--emotion.js +11 -0
  59. package/app/App--sc.d.ts +10 -10
  60. package/app/App--sc.js +11 -0
  61. package/app/App--vanilla.d.ts +10 -10
  62. package/app/App--vanilla.js +11 -0
  63. package/app/AppAuth--emotion.d.ts +10 -10
  64. package/app/AppAuth--emotion.js +12 -0
  65. package/app/AppAuth--sc.d.ts +10 -10
  66. package/app/AppAuth--sc.js +12 -0
  67. package/app/AppHead.d.ts +3 -3
  68. package/app/AppHead.js +5 -0
  69. package/app/{AppMain.d.ts → AppMain--emotion.d.ts} +34 -34
  70. package/app/AppMain--emotion.js +27 -0
  71. package/app/AppMain--sc.d.ts +34 -0
  72. package/app/AppMain--sc.js +27 -0
  73. package/app/AppMain--vanilla.d.ts +27 -27
  74. package/app/AppMain--vanilla.js +11 -0
  75. package/app/AppTheme--emotion.d.ts +15 -15
  76. package/app/AppTheme--emotion.js +17 -0
  77. package/app/AppTheme--sc.d.ts +13 -13
  78. package/app/AppTheme--sc.js +9 -0
  79. package/app/AppTheme--vanilla.d.ts +10 -10
  80. package/app/AppTheme--vanilla.js +12 -0
  81. package/app/index.d.ts +11 -11
  82. package/app/index.js +11 -0
  83. package/app/motion-features.d.ts +2 -2
  84. package/app/motion-features.js +2 -0
  85. package/config/index.d.ts +58 -58
  86. package/config/index.js +144 -0
  87. package/document/Document--emotion.d.ts +5 -5
  88. package/document/Document--emotion.js +55 -0
  89. package/document/Document--sc.d.ts +11 -11
  90. package/document/Document--sc.js +33 -0
  91. package/document/Document--vanilla.d.ts +11 -11
  92. package/document/Document--vanilla.js +20 -0
  93. package/document/Document.d.ts +10 -10
  94. package/document/Document.js +14 -0
  95. package/document/index.d.ts +4 -4
  96. package/document/index.js +4 -0
  97. package/index.d.ts +15 -12
  98. package/index.js +15 -743
  99. package/index.umd.js +2061 -78
  100. package/package.json +27 -21
  101. package/{types.d.ts → typings.d.ts} +0 -0
  102. package/utils/api.d.ts +55 -55
  103. package/utils/api.js +33 -0
  104. package/{document/emotion.d.ts → utils/emotion-cache.d.ts} +5 -5
  105. package/utils/emotion-cache.js +8 -0
  106. package/utils/index.d.ts +20 -19
  107. package/utils/index.js +27 -0
  108. package/Theme.js +0 -1905
  109. package/_tslib.js +0 -41
  110. package/app.js +0 -250
  111. package/config.js +0 -183
  112. package/document.js +0 -207
  113. package/emotion.js +0 -1329
  114. package/es.object.assign.js +0 -1074
  115. package/es.string.replace.js +0 -785
  116. package/es.string.split.js +0 -201
  117. package/index.esm.js +0 -4600
  118. package/motion-features.js +0 -10
package/_tslib.js DELETED
@@ -1,41 +0,0 @@
1
- 'use strict';
2
-
3
- /*! *****************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
-
18
- function __rest(s, e) {
19
- var t = {};
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
21
- t[p] = s[p];
22
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
23
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
24
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
25
- t[p[i]] = s[p[i]];
26
- }
27
- return t;
28
- }
29
-
30
- function __awaiter(thisArg, _arguments, P, generator) {
31
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
- return new (P || (P = Promise))(function (resolve, reject) {
33
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37
- });
38
- }
39
-
40
- exports.__awaiter = __awaiter;
41
- exports.__rest = __rest;
package/app.js DELETED
@@ -1,250 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('./es.object.assign.js');
6
- var jsxRuntime = require('react/jsx-runtime');
7
- var React = require('react');
8
- var Head = require('next/head');
9
- var styles = require('@mui/material/styles');
10
- var react = require('@emotion/react');
11
- var CssBaseline = require('@mui/material/CssBaseline');
12
- var react$1 = require('@koine/react');
13
- var emotion = require('./emotion.js');
14
- var Theme = require('./Theme.js');
15
- var router = require('next/router');
16
- var framerMotion = require('framer-motion');
17
- require('./es.string.replace.js');
18
- require('@koine/utils');
19
- var styledComponents = require('styled-components');
20
- var react$2 = require('next-auth/react');
21
- require('next/script');
22
-
23
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
24
-
25
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
26
- var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
27
- var CssBaseline__default = /*#__PURE__*/_interopDefaultLegacy(CssBaseline);
28
-
29
- const AppHead = props => {
30
- return jsxRuntime.jsx(Head__default["default"], Object.assign({}, props, {
31
- children: jsxRuntime.jsx("meta", {
32
- name: "viewport",
33
- content: "width=device-width"
34
- })
35
- }));
36
- };
37
-
38
- let _ = t => t,
39
- _t;
40
-
41
- const clientSideEmotionCache = emotion.createEmotionCache();
42
- /**
43
- * App theme with `emotion` (good for `@mui`)s
44
- */
45
-
46
- const AppThemeEmotion = ({
47
- emotionCache: _emotionCache = clientSideEmotionCache,
48
- theme,
49
- children
50
- }) => {
51
- return jsxRuntime.jsx(react.CacheProvider, Object.assign({
52
- value: _emotionCache
53
- }, {
54
- children: jsxRuntime.jsxs(styles.ThemeProvider, Object.assign({
55
- theme: theme
56
- }, {
57
- children: [jsxRuntime.jsx(CssBaseline__default["default"], {}), jsxRuntime.jsx(react.Global, {
58
- styles: react.css(_t || (_t = _`
59
- ${0}
60
- `), react$1.stylesGlobal)
61
- }), children]
62
- }))
63
- }));
64
- };
65
-
66
- /**
67
- * @see https://www.framer.com/docs/guide-reduce-bundle-size/
68
- */
69
-
70
- const loadMotionFeatures = () => Promise.resolve().then(function () { return require('./motion-features.js'); }).then(m => m.default);
71
- /**
72
- * App main
73
- *
74
- * It implies a setup for `styled-components` and `framer-motion` libraries.
75
- *
76
- * About the page transition [wallis' blog post](https://wallis.dev/blog/nextjs-page-transitions-with-framer-motion)
77
- */
78
-
79
-
80
- const AppMain = ({
81
- Component,
82
- pageProps,
83
- Layout,
84
- // theme,
85
- seo,
86
- transition: _transition = {
87
- initial: {
88
- opacity: 0
89
- },
90
- animate: {
91
- opacity: 1
92
- },
93
- exit: {
94
- opacity: 0
95
- }
96
- },
97
- pre,
98
- post
99
- }) => {
100
- const {
101
- pathname
102
- } = router.useRouter();
103
- return jsxRuntime.jsxs(framerMotion.LazyMotion, Object.assign({
104
- features: loadMotionFeatures
105
- }, {
106
- children: [jsxRuntime.jsx(Theme.SeoDefaults, Object.assign({}, seo)), pre, jsxRuntime.jsx(Theme.NextProgress, {}), jsxRuntime.jsx(Layout, {
107
- children: jsxRuntime.jsx(framerMotion.AnimatePresence, Object.assign({
108
- exitBeforeEnter: true,
109
- initial: false
110
- }, {
111
- children: jsxRuntime.jsx(framerMotion.m.div, Object.assign({}, _transition, {
112
- children: /*#__PURE__*/React.createElement(Component, Object.assign({}, pageProps, {
113
- key: pathname
114
- }))
115
- }), pathname)
116
- }))
117
- }), post]
118
- }));
119
- };
120
-
121
- /**
122
- * App
123
- */
124
-
125
- const AppEmotion = props => {
126
- return jsxRuntime.jsxs(React__default["default"].Fragment, {
127
- children: [jsxRuntime.jsx(AppHead, {}), jsxRuntime.jsx(AppThemeEmotion, Object.assign({}, props, {
128
- children: jsxRuntime.jsx(AppMain, Object.assign({}, props))
129
- }))]
130
- });
131
- };
132
-
133
- /**
134
- * App theme with `styled-components`
135
- */
136
-
137
- const AppThemeSc = ({
138
- theme,
139
- children
140
- }) => {
141
- return jsxRuntime.jsxs(styledComponents.ThemeProvider, Object.assign({
142
- theme: theme
143
- }, {
144
- children: [jsxRuntime.jsx(react$1.StylesGlobal, {}), children]
145
- }));
146
- };
147
-
148
- /**
149
- * App
150
- */
151
-
152
- const AppBase = props => {
153
- return jsxRuntime.jsxs(React__default["default"].Fragment, {
154
- children: [jsxRuntime.jsx(AppHead, {}), jsxRuntime.jsx(AppThemeSc, Object.assign({}, props, {
155
- children: jsxRuntime.jsx(AppMain, Object.assign({}, props))
156
- }))]
157
- });
158
- };
159
-
160
- /**
161
- * App theme with vanilla class based theme (good for `tailwindcss`)
162
- */
163
-
164
- const AppThemeVanilla = ({
165
- theme,
166
- children
167
- }) => {
168
- // return (
169
- // <ThemeVanillaProvider initialTheme={theme}>{children}</ThemeVanillaProvider>
170
- // );
171
- return jsxRuntime.jsx(Theme.ThemeProvider, Object.assign({
172
- defaultTheme: theme,
173
- attribute: "class"
174
- }, {
175
- children: children
176
- }));
177
- };
178
-
179
- /**
180
- * App main
181
- *
182
- * It does not imply any specific styling or animation solution
183
- */
184
-
185
- const AppMainVanilla = ({
186
- Component,
187
- pageProps,
188
- Layout,
189
- seo,
190
- pre,
191
- post
192
- }) => {
193
- return jsxRuntime.jsxs(React__default["default"].Fragment, {
194
- children: [jsxRuntime.jsx(Theme.SeoDefaults, Object.assign({}, seo)), pre, jsxRuntime.jsx(Layout, {
195
- children: jsxRuntime.jsx(Component, Object.assign({}, pageProps))
196
- }), post]
197
- });
198
- };
199
-
200
- /**
201
- * App
202
- */
203
-
204
- const AppVanilla = props => {
205
- return jsxRuntime.jsxs(React__default["default"].Fragment, {
206
- children: [jsxRuntime.jsx(AppHead, {}), jsxRuntime.jsx(AppThemeVanilla, Object.assign({}, props, {
207
- children: jsxRuntime.jsx(AppMainVanilla, Object.assign({}, props))
208
- }))]
209
- });
210
- };
211
-
212
- /**
213
- * App with authentication provided by `next-auth`
214
- */
215
-
216
- const AppAuthEmotion = props => {
217
- return jsxRuntime.jsxs(react$2.SessionProvider, Object.assign({
218
- session: props.pageProps.session
219
- }, {
220
- children: [jsxRuntime.jsx(AppHead, {}), jsxRuntime.jsx(AppThemeEmotion, Object.assign({}, props, {
221
- children: jsxRuntime.jsx(AppMain, Object.assign({}, props))
222
- }))]
223
- }));
224
- };
225
-
226
- /**
227
- * App with authentication provided by `next-auth`
228
- */
229
-
230
- const AppAuthSc = props => {
231
- return jsxRuntime.jsxs(react$2.SessionProvider, Object.assign({
232
- session: props.pageProps.session
233
- }, {
234
- children: [jsxRuntime.jsx(AppHead, {}), jsxRuntime.jsx(AppThemeSc, Object.assign({}, props, {
235
- children: jsxRuntime.jsx(AppMain, Object.assign({}, props))
236
- }))]
237
- }));
238
- };
239
-
240
- exports.AppAuthEmotion = AppAuthEmotion;
241
- exports.AppAuthSc = AppAuthSc;
242
- exports.AppBase = AppBase;
243
- exports.AppEmotion = AppEmotion;
244
- exports.AppHead = AppHead;
245
- exports.AppMain = AppMain;
246
- exports.AppMainVanilla = AppMainVanilla;
247
- exports.AppThemeEmotion = AppThemeEmotion;
248
- exports.AppThemeSc = AppThemeSc;
249
- exports.AppThemeVanilla = AppThemeVanilla;
250
- exports.AppVanilla = AppVanilla;
package/config.js DELETED
@@ -1,183 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('./es.string.replace.js');
6
- require('./es.string.split.js');
7
- require('./es.object.assign.js');
8
- var _tslib = require('./_tslib.js');
9
-
10
- /**
11
- * Normalise pathname
12
- *
13
- * From a path like `/some//malformed/path///` it returns `some/malformed/path`
14
- *
15
- * - Removes subsequent slashes
16
- * - Removing initial and ending slashes
17
- */
18
-
19
- function normaliseUrlPathname(pathname) {
20
- return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
21
- }
22
- /**
23
- * Clean a pathname and encode each part
24
- *
25
- * @see {@link normaliseUrlPathname}
26
- */
27
-
28
- function encodePathname(pathname) {
29
- const parts = normaliseUrlPathname(pathname).split("/");
30
- return parts.filter(part => !!part).map(part => encodeURIComponent(part)).join("/");
31
- }
32
- /**
33
- */
34
-
35
- function getPathRedirect(locale, localisedPathname, templateName, dynamic, permanent) {
36
- const suffix = dynamic ? `/:slug*` : "";
37
- return {
38
- source: `/${locale}/${encodePathname(localisedPathname)}${suffix}`,
39
- destination: `/${encodePathname(templateName)}${suffix}`,
40
- permanent: Boolean(permanent),
41
- locale: false
42
- };
43
- }
44
- /**
45
- */
46
-
47
- function getPathRewrite(source, destination, dynamic) {
48
- const suffix = dynamic ? `/:path*` : "";
49
- return {
50
- source: `/${encodePathname(source)}${suffix}`,
51
- destination: `/${encodePathname(destination)}${suffix}`
52
- };
53
- }
54
- /**
55
- */
56
-
57
- function getRedirects({
58
- defaultLocale,
59
- routes,
60
- dynamicRoutes,
61
- permanent
62
- }) {
63
- return _tslib.__awaiter(this, void 0, void 0, function* () {
64
- const redirects = [];
65
- Object.keys(routes).forEach(page => {
66
- const dynamic = dynamicRoutes[page];
67
-
68
- if (routes[page] !== page) {
69
- if (dynamic) {
70
- redirects.push(getPathRedirect(defaultLocale, page, routes[page], true, permanent));
71
- } else {
72
- redirects.push(getPathRedirect(defaultLocale, page, routes[page], false, permanent));
73
- }
74
- }
75
- }); // console.log("redirects", redirects);
76
-
77
- return redirects;
78
- });
79
- }
80
- /**
81
- */
82
-
83
- function getRewrites({
84
- routes,
85
- dynamicRoutes
86
- }) {
87
- return _tslib.__awaiter(this, void 0, void 0, function* () {
88
- const rewrites = [];
89
- Object.keys(routes).forEach(page => {
90
- const dynamic = dynamicRoutes[page];
91
-
92
- if (routes[page] !== page) {
93
- if (dynamic) {
94
- rewrites.push(getPathRewrite(routes[page], page, true));
95
- } else {
96
- rewrites.push(getPathRewrite(routes[page], page));
97
- }
98
- }
99
- }); // console.log("rewrites", rewrites);
100
-
101
- return rewrites;
102
- });
103
- }
104
- /**
105
- * Get Next.js config with some basic opinionated defaults
106
- */
107
-
108
- function withKoine(_a = {}) {
109
- var {
110
- nx = true,
111
- svg = true,
112
- sc = true
113
- } = _a,
114
- nextConfig = _tslib.__rest(_a, ["nx", "svg", "sc"]);
115
-
116
- nextConfig = Object.assign({
117
- // @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
118
- pageExtensions: ["page.tsx", "page.ts"],
119
- eslint: {
120
- ignoreDuringBuilds: true // we have this strict check on each commit
121
-
122
- },
123
- typescript: {
124
- ignoreBuildErrors: true // we have this strict check on each commit
125
-
126
- },
127
- poweredByHeader: false,
128
- swcMinify: true,
129
- experimental: Object.assign({
130
- // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
131
- // @see critters error https://github.com/vercel/next.js/issues/20742
132
- // optimizeCss: true,
133
- // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
134
- scrollRestoration: true
135
- }, nextConfig.experimental || {})
136
- }, nextConfig);
137
-
138
- if (svg) {
139
- if (nx) {
140
- // @see https://github.com/gregberge/svgr
141
- nextConfig["nx"] = {
142
- svgr: true
143
- };
144
- } else {
145
- nextConfig.webpack = (_config, options) => {
146
- const webpackConfig = typeof nextConfig.webpack === "function" ? nextConfig.webpack(_config, options) : _config; // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
147
-
148
- webpackConfig.module.rules.push({
149
- test: /\.svg$/,
150
- use: [{
151
- loader: "@svgr/webpack",
152
- options: {
153
- svgoConfig: {
154
- plugins: [{
155
- name: "removeViewBox",
156
- active: false
157
- }]
158
- }
159
- }
160
- }]
161
- });
162
- return webpackConfig;
163
- };
164
- }
165
- }
166
-
167
- if (sc) {
168
- nextConfig.compiler = {
169
- styledComponents: true
170
- };
171
- }
172
-
173
- return nextConfig;
174
- }
175
-
176
- exports["default"] = withKoine;
177
- exports.encodePathname = encodePathname;
178
- exports.getPathRedirect = getPathRedirect;
179
- exports.getPathRewrite = getPathRewrite;
180
- exports.getRedirects = getRedirects;
181
- exports.getRewrites = getRewrites;
182
- exports.normaliseUrlPathname = normaliseUrlPathname;
183
- exports.withKoine = withKoine;
package/document.js DELETED
@@ -1,207 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('./es.object.assign.js');
6
- var jsxRuntime = require('react/jsx-runtime');
7
- var NextDocument = require('next/document');
8
- var react = require('@koine/react');
9
- var _tslib = require('./_tslib.js');
10
- var createEmotionServer = require('@emotion/server/create-instance');
11
- var emotion = require('./emotion.js');
12
- var styledComponents = require('styled-components');
13
-
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
-
16
- var NextDocument__default = /*#__PURE__*/_interopDefaultLegacy(NextDocument);
17
- var createEmotionServer__default = /*#__PURE__*/_interopDefaultLegacy(createEmotionServer);
18
-
19
- /**
20
- * For typescript safety of this component
21
- *
22
- * @see https://bit.ly/3ceuF8m
23
- */
24
-
25
- class Document extends NextDocument__default["default"] {
26
- render() {
27
- const {
28
- locale,
29
- defaultLocale
30
- } = this.props.__NEXT_DATA__;
31
- return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
32
- lang: locale || defaultLocale,
33
- className: "no-js"
34
- }, {
35
- children: [jsxRuntime.jsxs(NextDocument.Head, {
36
- children: [jsxRuntime.jsx(react.Meta, {}), jsxRuntime.jsx(react.NoJs, {})]
37
- }), jsxRuntime.jsxs("body", {
38
- children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
39
- })]
40
- }));
41
- }
42
-
43
- }
44
-
45
- class DocumentEmotion extends NextDocument__default["default"] {
46
- render() {
47
- const {
48
- locale,
49
- defaultLocale
50
- } = this.props.__NEXT_DATA__;
51
- return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
52
- lang: locale || defaultLocale,
53
- className: "no-js"
54
- }, {
55
- children: [jsxRuntime.jsxs(NextDocument.Head, {
56
- children: [jsxRuntime.jsx(react.NoJs, {}), this.props.emotionStyleTags]
57
- }), jsxRuntime.jsxs("body", {
58
- children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
59
- })]
60
- }));
61
- }
62
-
63
- } // `getInitialProps` belongs to `_document` (instead of `_app`),
64
- // it's compatible with static-site generation (SSG).
65
-
66
- DocumentEmotion.getInitialProps = ctx => _tslib.__awaiter(void 0, void 0, void 0, function* () {
67
- // Resolution order
68
- //
69
- // On the server:
70
- // 1. app.getInitialProps
71
- // 2. page.getInitialProps
72
- // 3. document.getInitialProps
73
- // 4. app.render
74
- // 5. page.render
75
- // 6. document.render
76
- //
77
- // On the server with error:
78
- // 1. document.getInitialProps
79
- // 2. app.render
80
- // 3. page.render
81
- // 4. document.render
82
- //
83
- // On the client
84
- // 1. app.getInitialProps
85
- // 2. page.getInitialProps
86
- // 3. app.render
87
- // 4. page.render
88
- const originalRenderPage = ctx.renderPage; // You can consider sharing the same emotion cache between all the SSR requests to speed up performance.
89
- // However, be aware that it can have global side effects.
90
-
91
- const cache = emotion.createEmotionCache();
92
- const {
93
- extractCriticalToChunks
94
- } = createEmotionServer__default["default"](cache);
95
-
96
- ctx.renderPage = () => originalRenderPage({
97
- enhanceApp: App => function EnhanceApp(props) {
98
- return jsxRuntime.jsx(App, Object.assign({
99
- emotionCache: cache
100
- }, props));
101
- }
102
- });
103
-
104
- const initialProps = yield NextDocument__default["default"].getInitialProps(ctx); // This is important. It prevents emotion to render invalid HTML.
105
- // See https://github.com/mui-org/material-ui/issues/26561#issuecomment-855286153
106
-
107
- const emotionStyles = extractCriticalToChunks(initialProps.html);
108
- const emotionStyleTags = emotionStyles.styles.map(style => jsxRuntime.jsx("style", {
109
- "data-emotion": `${style.key} ${style.ids.join(" ")}`,
110
- // eslint-disable-next-line react/no-danger
111
- dangerouslySetInnerHTML: {
112
- __html: style.css
113
- }
114
- }, style.key));
115
- return Object.assign(Object.assign({}, initialProps), {
116
- emotionStyleTags
117
- });
118
- });
119
-
120
- /**
121
- * For typescript safety of this component
122
- *
123
- * @see https://bit.ly/3ceuF8m
124
- */
125
-
126
- class DocumentSc extends NextDocument__default["default"] {
127
- static getInitialProps(ctx) {
128
- return _tslib.__awaiter(this, void 0, void 0, function* () {
129
- const sheet = new styledComponents.ServerStyleSheet();
130
- const originalRenderPage = ctx.renderPage;
131
-
132
- try {
133
- ctx.renderPage = () => originalRenderPage({
134
- enhanceApp: App => props => sheet.collectStyles(jsxRuntime.jsx(App, Object.assign({}, props)))
135
- });
136
-
137
- const initialProps = yield NextDocument__default["default"].getInitialProps(ctx);
138
- return Object.assign(Object.assign({}, initialProps), {
139
- styles: jsxRuntime.jsxs(jsxRuntime.Fragment, {
140
- children: [initialProps.styles, sheet.getStyleElement()]
141
- })
142
- });
143
- } finally {
144
- sheet.seal();
145
- }
146
- });
147
- }
148
-
149
- render() {
150
- const {
151
- locale,
152
- defaultLocale
153
- } = this.props.__NEXT_DATA__;
154
- return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
155
- lang: locale || defaultLocale,
156
- className: "no-js"
157
- }, {
158
- children: [jsxRuntime.jsxs(NextDocument.Head, {
159
- children: [jsxRuntime.jsx(react.Meta, {}), jsxRuntime.jsx(react.NoJs, {})]
160
- }), jsxRuntime.jsxs("body", {
161
- children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
162
- })]
163
- }));
164
- }
165
-
166
- }
167
-
168
- /**
169
- */
170
-
171
- class DocumentVanilla extends NextDocument__default["default"] {
172
- static getInitialProps(ctx) {
173
- var _a;
174
-
175
- return _tslib.__awaiter(this, void 0, void 0, function* () {
176
- const initialProps = yield NextDocument__default["default"].getInitialProps(ctx);
177
- return Object.assign(Object.assign({}, initialProps), {
178
- theme: react.getInitialThemeFromRequest(((_a = ctx.req) === null || _a === void 0 ? void 0 : _a.headers.cookie
179
- /* || document?.cookie */
180
- ) || "")
181
- });
182
- });
183
- }
184
-
185
- render() {
186
- const {
187
- locale,
188
- defaultLocale
189
- } = this.props.__NEXT_DATA__;
190
- return jsxRuntime.jsxs(NextDocument.Html, Object.assign({
191
- lang: locale || defaultLocale,
192
- className: "no-js"
193
- }, {
194
- children: [jsxRuntime.jsxs(NextDocument.Head, {
195
- children: [jsxRuntime.jsx(react.Meta, {}), jsxRuntime.jsx(react.NoJs, {})]
196
- }), jsxRuntime.jsxs("body", {
197
- children: [jsxRuntime.jsx(NextDocument.Main, {}), jsxRuntime.jsx(NextDocument.NextScript, {})]
198
- })]
199
- }));
200
- }
201
-
202
- }
203
-
204
- exports.Document = Document;
205
- exports.DocumentEmotion = DocumentEmotion;
206
- exports.DocumentSc = DocumentSc;
207
- exports.DocumentVanilla = DocumentVanilla;