@koine/next 2.0.0-beta.8 → 2.0.0-beta.82

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 (179) hide show
  1. package/12/AnalyticsGoogle.d.ts +1 -2
  2. package/12/DisableErrorOverlay.d.ts +1 -6
  3. package/12/Seo.d.ts +8 -26
  4. package/12/SeoDefaults.d.ts +3 -4
  5. package/12/seoBuildTags.d.ts +2 -17
  6. package/12/types.d.ts +2 -0
  7. package/12.cjs.d.ts +1 -0
  8. package/12.cjs.default.js +1 -0
  9. package/12.cjs.js +28 -0
  10. package/12.cjs.mjs +2 -0
  11. package/12.d.ts +3 -0
  12. package/12.esm.js +18 -0
  13. package/README.md +0 -12
  14. package/ThemeContext.cjs.d.ts +2 -0
  15. package/ThemeContext.cjs.default.js +1 -0
  16. package/ThemeContext.cjs.js +10 -0
  17. package/ThemeContext.cjs.mjs +2 -0
  18. package/ThemeContext.d.ts +11 -0
  19. package/ThemeContext.esm.js +5 -0
  20. package/ThemeProvider.cjs.d.ts +2 -0
  21. package/ThemeProvider.cjs.default.js +1 -0
  22. package/ThemeProvider.cjs.js +18 -0
  23. package/ThemeProvider.cjs.mjs +2 -0
  24. package/ThemeProvider.d.ts +17 -0
  25. package/ThemeProvider.esm.js +9 -0
  26. package/config.cjs.d.ts +1 -0
  27. package/config.cjs.default.js +1 -0
  28. package/config.cjs.js +9 -0
  29. package/config.cjs.mjs +2 -0
  30. package/config.d.ts +7 -0
  31. package/config.esm.js +5 -0
  32. package/index.cjs.d.ts +1 -0
  33. package/index.cjs.default.js +1 -0
  34. package/index.cjs.js +19 -0
  35. package/index.cjs.mjs +2 -0
  36. package/index.d.ts +3 -1
  37. package/index.esm.js +8 -0
  38. package/load.cjs.d.ts +2 -0
  39. package/load.cjs.default.js +1 -0
  40. package/load.cjs.js +8 -0
  41. package/load.cjs.mjs +2 -0
  42. package/load.d.ts +0 -8
  43. package/load.esm.js +3 -0
  44. package/package.json +49 -89
  45. package/typings.d.ts +39 -50
  46. package/useTheme.cjs.d.ts +2 -0
  47. package/useTheme.cjs.default.js +1 -0
  48. package/useTheme.cjs.js +11 -0
  49. package/useTheme.cjs.mjs +2 -0
  50. package/useTheme.d.ts +4 -0
  51. package/useTheme.esm.js +6 -0
  52. package/12/AnalyticsGoogle.js +0 -79
  53. package/12/AnalyticsGoogle.mjs +0 -60
  54. package/12/DisableErrorOverlay.js +0 -31
  55. package/12/DisableErrorOverlay.mjs +0 -16
  56. package/12/DynamicNamespaces.d.ts +0 -13
  57. package/12/DynamicNamespaces.js +0 -23
  58. package/12/DynamicNamespaces.mjs +0 -8
  59. package/12/Favicon.d.ts +0 -4
  60. package/12/Favicon.js +0 -29
  61. package/12/Favicon.mjs +0 -10
  62. package/12/Link.d.ts +0 -10
  63. package/12/Link.js +0 -38
  64. package/12/Link.mjs +0 -20
  65. package/12/NextProgress.d.ts +0 -25
  66. package/12/NextProgress.js +0 -69
  67. package/12/NextProgress.mjs +0 -51
  68. package/12/Seo.js +0 -29
  69. package/12/Seo.mjs +0 -30
  70. package/12/SeoDefaults.js +0 -31
  71. package/12/SeoDefaults.mjs +0 -14
  72. package/12/T.d.ts +0 -16
  73. package/12/T.js +0 -43
  74. package/12/T.mjs +0 -27
  75. package/12/ThemeContext.d.ts +0 -17
  76. package/12/ThemeContext.js +0 -25
  77. package/12/ThemeContext.mjs +0 -7
  78. package/12/ThemeProvider.d.ts +0 -35
  79. package/12/ThemeProvider.js +0 -256
  80. package/12/ThemeProvider.mjs +0 -245
  81. package/12/TransText.d.ts +0 -3
  82. package/12/TransText.js +0 -23
  83. package/12/TransText.mjs +0 -4
  84. package/12/app/AppHead.d.ts +0 -3
  85. package/12/app/AppHead.js +0 -31
  86. package/12/app/AppHead.mjs +0 -12
  87. package/12/app/AppMain.d.ts +0 -35
  88. package/12/app/AppMain.js +0 -6
  89. package/12/app/AppMain.mjs +0 -1
  90. package/12/app/css/AppMain.d.ts +0 -9
  91. package/12/app/css/AppMain.js +0 -39
  92. package/12/app/css/AppMain.mjs +0 -24
  93. package/12/app/css/AppTheme.d.ts +0 -11
  94. package/12/app/css/AppTheme.js +0 -33
  95. package/12/app/css/AppTheme.mjs +0 -17
  96. package/12/app/css/auth/index.d.ts +0 -11
  97. package/12/app/css/auth/index.js +0 -40
  98. package/12/app/css/auth/index.mjs +0 -24
  99. package/12/app/css/index.d.ts +0 -54
  100. package/12/app/css/index.js +0 -36
  101. package/12/app/css/index.mjs +0 -65
  102. package/12/app/index.d.ts +0 -2
  103. package/12/app/index.js +0 -7
  104. package/12/app/index.mjs +0 -2
  105. package/12/app/sc/AppMain.d.ts +0 -11
  106. package/12/app/sc/AppMain.js +0 -70
  107. package/12/app/sc/AppMain.mjs +0 -58
  108. package/12/app/sc/AppTheme.d.ts +0 -14
  109. package/12/app/sc/AppTheme.js +0 -33
  110. package/12/app/sc/AppTheme.mjs +0 -16
  111. package/12/app/sc/auth/index.d.ts +0 -11
  112. package/12/app/sc/auth/index.js +0 -40
  113. package/12/app/sc/auth/index.mjs +0 -24
  114. package/12/app/sc/index.d.ts +0 -56
  115. package/12/app/sc/index.js +0 -36
  116. package/12/app/sc/index.mjs +0 -67
  117. package/12/document/Document.d.ts +0 -15
  118. package/12/document/Document.js +0 -49
  119. package/12/document/Document.mjs +0 -38
  120. package/12/document/css/index.d.ts +0 -17
  121. package/12/document/css/index.js +0 -60
  122. package/12/document/css/index.mjs +0 -53
  123. package/12/document/index.d.ts +0 -2
  124. package/12/document/index.js +0 -19
  125. package/12/document/index.mjs +0 -2
  126. package/12/document/sc/index.d.ts +0 -19
  127. package/12/document/sc/index.js +0 -73
  128. package/12/document/sc/index.mjs +0 -65
  129. package/12/getT.d.ts +0 -9
  130. package/12/getT.js +0 -23
  131. package/12/getT.mjs +0 -8
  132. package/12/index.d.ts +0 -24
  133. package/12/index.js +0 -100
  134. package/12/index.mjs +0 -27
  135. package/12/seoBuildTags.js +0 -126
  136. package/12/seoBuildTags.mjs +0 -121
  137. package/12/to.d.ts +0 -24
  138. package/12/to.js +0 -31
  139. package/12/to.mjs +0 -19
  140. package/12/translationAsOptions.d.ts +0 -3
  141. package/12/translationAsOptions.js +0 -19
  142. package/12/translationAsOptions.mjs +0 -9
  143. package/12/types-i18n.d.ts +0 -118
  144. package/12/types-i18n.js +0 -15
  145. package/12/types-i18n.mjs +0 -12
  146. package/12/types-seo.d.ts +0 -7
  147. package/12/types-seo.js +0 -4
  148. package/12/types-seo.mjs +0 -1
  149. package/12/useBackUrl.d.ts +0 -2
  150. package/12/useBackUrl.js +0 -47
  151. package/12/useBackUrl.mjs +0 -28
  152. package/12/useDateFormat.d.ts +0 -7
  153. package/12/useDateFormat.js +0 -42
  154. package/12/useDateFormat.mjs +0 -26
  155. package/12/useForm.d.ts +0 -27
  156. package/12/useForm.js +0 -65
  157. package/12/useForm.mjs +0 -47
  158. package/12/useLocale.d.ts +0 -2
  159. package/12/useLocale.js +0 -25
  160. package/12/useLocale.mjs +0 -6
  161. package/12/useT.d.ts +0 -4
  162. package/12/useT.js +0 -58
  163. package/12/useT.mjs +0 -39
  164. package/12/useTheme.d.ts +0 -7
  165. package/12/useTheme.js +0 -23
  166. package/12/useTheme.mjs +0 -7
  167. package/12/useTo.d.ts +0 -3
  168. package/12/useTo.js +0 -26
  169. package/12/useTo.mjs +0 -8
  170. package/config/index.d.ts +0 -160
  171. package/config/index.js +0 -317
  172. package/config/index.mjs +0 -315
  173. package/getSiteUrl.d.ts +0 -8
  174. package/getSiteUrl.js +0 -24
  175. package/getSiteUrl.mjs +0 -10
  176. package/index.js +0 -20
  177. package/index.mjs +0 -2
  178. package/load.js +0 -31
  179. package/load.mjs +0 -13
package/config/index.js DELETED
@@ -1,317 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- normaliseUrlPathname: function() {
13
- return normaliseUrlPathname;
14
- },
15
- toPath: function() {
16
- return toPath;
17
- },
18
- encodePathname: function() {
19
- return encodePathname;
20
- },
21
- getPathRewrite: function() {
22
- return getPathRewrite;
23
- },
24
- getPathRedirect: function() {
25
- return getPathRedirect;
26
- },
27
- getRedirects: function() {
28
- return getRedirects;
29
- },
30
- getRewrites: function() {
31
- return getRewrites;
32
- },
33
- withKoine: function() {
34
- return withKoine;
35
- },
36
- default: function() {
37
- return _default;
38
- }
39
- });
40
- function normaliseUrlPathname(pathname = "") {
41
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
42
- // we would instead return a single slash if only slashes are given
43
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
44
- }
45
- function toPath(urlOrPathname = "") {
46
- let pathname = "";
47
- try {
48
- const parsed = new URL(urlOrPathname);
49
- pathname = parsed.pathname;
50
- } catch (e) {
51
- pathname = urlOrPathname;
52
- }
53
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
54
- // we would instead return a single slash if only slashes are given
55
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
56
- }
57
- function encodePathname(pathname = "") {
58
- const parts = normaliseUrlPathname(pathname).split("/");
59
- return parts.filter((part)=>!!part).map((part)=>encodeURIComponent(part)).join("/");
60
- }
61
- /**
62
- * Transform the route translated defintion into a `pathname` and a `template`.
63
- *
64
- * Here we add the wildcard flag maybe found in the pathname to the template
65
- * name too, this is because we do not want to have the wildcard in the JSON
66
- * keys as those are also used to produce links throught the `useTo` hook and
67
- * having asterisks there is a bit cumbersome.
68
- *
69
- * @see https://nextjs.org/docs/messages/invalid-multi-match
70
- */ function transformRoute(route) {
71
- const { pathname: rawPathname, template: rawTemplate } = route;
72
- const pathnameParts = rawPathname.split("/").filter((part)=>!!part);
73
- const templateParts = rawTemplate.split("/").filter((part)=>!!part);
74
- const mapPartsByIdx = {};
75
- const pathname = pathnameParts.map((part)=>{
76
- const hasWildcard = part.endsWith("*");
77
- part = part.replace("*", "");
78
- const isDynamic = part.startsWith("{{") && part.endsWith("}}");
79
- const asValue = isDynamic ? part.match(/{{(.+)}}/)?.[1].trim() ?? "" : part.trim();
80
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
81
- mapPartsByIdx[asValue] = {
82
- isDynamic,
83
- hasWildcard
84
- };
85
- return isDynamic ? `:${asPath}` : asPath;
86
- }).join("/");
87
- const template = templateParts.map((part)=>{
88
- const isDynamic = part.startsWith("[") && part.endsWith("]");
89
- const asValue = isDynamic ? part.match(/\[(.+)\]/)?.[1].trim() ?? "" : part.trim();
90
- const hasWildcard = mapPartsByIdx[asValue]?.hasWildcard;
91
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
92
- return isDynamic ? `:${asPath}` : asPath;
93
- }).join("/");
94
- return {
95
- pathname,
96
- template
97
- };
98
- }
99
- /**
100
- * Get routes map dictionary
101
- */ function getRoutesMap(map = {}, routes, pathnameBuffer = "", templateBuffer = "") {
102
- for(const key in routes){
103
- const pathOrNestedRoutes = routes[key];
104
- const template = `${templateBuffer}/${key}`;
105
- if (typeof pathOrNestedRoutes === "string") {
106
- map[template] = {
107
- template,
108
- pathname: pathOrNestedRoutes,
109
- wildcard: pathOrNestedRoutes.includes("*")
110
- };
111
- } else {
112
- getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
113
- }
114
- }
115
- return map;
116
- }
117
- /**
118
- * Removes `/index` from a template/url path
119
- */ function getWithoutIndex(template) {
120
- return template.replace(/\/index$/, "");
121
- }
122
- function getPathRewrite(route) {
123
- const { pathname, template } = transformRoute(route);
124
- const source = `/${normaliseUrlPathname(pathname)}`;
125
- const destination = `/${normaliseUrlPathname(template)}`;
126
- // console.log(`rewrite pathname "${source}" to template "${destination}"`);
127
- return {
128
- source,
129
- destination: getWithoutIndex(destination)
130
- };
131
- }
132
- function getPathRedirect(locale = "", route, permanent) {
133
- const { template, pathname } = transformRoute(route);
134
- const source = `/${normaliseUrlPathname((locale ? `/${locale}/` : "/") + template)}`;
135
- const destination = `/${normaliseUrlPathname(pathname)}`;
136
- // console.log(`redirect template "${source}" to pathname "${destination}"`);
137
- return {
138
- source: getWithoutIndex(source),
139
- destination,
140
- permanent: Boolean(permanent),
141
- locale: false
142
- };
143
- }
144
- async function getRedirects(defaultLocale, routes, permanent, debug) {
145
- const redirects = [];
146
- const routesMap = getRoutesMap({}, routes);
147
- Object.keys(routesMap).forEach((template)=>{
148
- const route = routesMap[template];
149
- // TODO: add option hideDefaultLocaleInUrl?
150
- // this is meant to redirect the URL with the default locale to the same
151
- // url without locale prefix, e.g.: /en/about -> /about (assuming en is the
152
- // defualt locale).
153
- // Actually this redirect seem not to be necessary, probably the i18n routing
154
- // mechanism of next 12 already does this, enabling causes infinite redirects
155
- // if (hideDefaultLocaleInUrl) {
156
- // redirects.push(getPathRedirect(defaultLocale, route, permanent));
157
- // }
158
- if (route.pathname !== getWithoutIndex(template)) {
159
- redirects.push(getPathRedirect("", route, permanent));
160
- }
161
- });
162
- if (debug) console.info("[@koine/next/config:getRedirects]", redirects);
163
- return redirects;
164
- }
165
- async function getRewrites(routes, debug) {
166
- const rewrites = [];
167
- const routesMap = getRoutesMap({}, routes);
168
- Object.keys(routesMap).forEach((template)=>{
169
- const route = routesMap[template];
170
- if (route.pathname !== getWithoutIndex(template)) {
171
- rewrites.push(getPathRewrite(route));
172
- }
173
- });
174
- if (debug) console.info("[@koine/next/config:getRewrites]", rewrites);
175
- return rewrites;
176
- }
177
- function withKoine({ nx = true, svg = true, sc = true, page, routes, permanent, debug, ...custom } = {
178
- i18n: {
179
- locales: [
180
- "en"
181
- ],
182
- defaultLocale: "en"
183
- }
184
- }) {
185
- const nextConfig = {
186
- // @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
187
- pageExtensions: page ? [
188
- "page.tsx",
189
- "page.ts"
190
- ] : undefined,
191
- eslint: {
192
- ignoreDuringBuilds: true
193
- },
194
- typescript: {
195
- ignoreBuildErrors: true
196
- },
197
- poweredByHeader: false,
198
- swcMinify: true,
199
- modularizeImports: {
200
- "@koine/api": {
201
- transform: "@koine/api/{{member}}"
202
- },
203
- "@koine/browser": {
204
- transform: "@koine/browser/{{member}}"
205
- },
206
- "@koine/dom": {
207
- transform: "@koine/dom/{{member}}"
208
- },
209
- "@koine/next/?(((\\w*)?/?)*)": {
210
- transform: "@koine/next/{{ matches.[1] }}/{{member}}"
211
- },
212
- "@koine/react/?(((\\w*)?/?)*)": {
213
- transform: "@koine/react/{{ matches.[1] }}/{{member}}"
214
- },
215
- "@koine/utils": {
216
- transform: "@koine/utils/{{member}}"
217
- },
218
- ...custom["modularizeImports"] || {}
219
- },
220
- experimental: {
221
- // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
222
- // @see critters error https://github.com/vercel/next.js/issues/20742
223
- // optimizeCss: true,
224
- // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
225
- scrollRestoration: true,
226
- // concurrentFeatures: true,
227
- // serverComponents: true,
228
- // reactRoot: true,
229
- ...custom["experimental"] || {}
230
- },
231
- // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
232
- // reactStrictMode: true,
233
- ...custom
234
- };
235
- if (svg) {
236
- if (nx) {
237
- // @see https://github.com/gregberge/svgr
238
- nextConfig["nx"] = {
239
- svgr: true
240
- };
241
- } else {
242
- nextConfig.webpack = (_config, options)=>{
243
- const webpackConfig = typeof nextConfig.webpack === "function" ? nextConfig.webpack(_config, options) : _config;
244
- // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
245
- webpackConfig.module.rules.push({
246
- test: /\.svg$/,
247
- use: [
248
- {
249
- loader: "@svgr/webpack",
250
- options: {
251
- svgoConfig: {
252
- plugins: [
253
- {
254
- name: "removeViewBox",
255
- active: false
256
- }
257
- ]
258
- }
259
- }
260
- }
261
- ]
262
- });
263
- return webpackConfig;
264
- };
265
- }
266
- }
267
- if (sc) {
268
- nextConfig.compiler = {
269
- styledComponents: true
270
- };
271
- }
272
- if (routes) {
273
- // we pass the default values, so we can assert I guess
274
- const defaultLocale = nextConfig?.i18n?.defaultLocale;
275
- return {
276
- ...nextConfig,
277
- async redirects () {
278
- const defaults = await getRedirects(defaultLocale, routes, permanent, debug);
279
- if (nextConfig.redirects) {
280
- const customs = await nextConfig.redirects();
281
- return [
282
- ...defaults,
283
- ...customs
284
- ];
285
- }
286
- return defaults;
287
- },
288
- async rewrites () {
289
- const defaults = await getRewrites(routes, debug);
290
- if (nextConfig.rewrites) {
291
- const customs = await nextConfig.rewrites();
292
- if (Array.isArray(customs)) {
293
- return {
294
- beforeFiles: defaults,
295
- afterFiles: customs,
296
- fallback: []
297
- };
298
- }
299
- return {
300
- ...customs,
301
- beforeFiles: [
302
- ...defaults,
303
- ...customs.beforeFiles || []
304
- ]
305
- };
306
- }
307
- return {
308
- afterFiles: [],
309
- beforeFiles: defaults,
310
- fallback: []
311
- };
312
- }
313
- };
314
- }
315
- return nextConfig;
316
- }
317
- const _default = withKoine;
package/config/index.mjs DELETED
@@ -1,315 +0,0 @@
1
- /**
2
- * Normalise pathname
3
- *
4
- * From a path like `/some//malformed/path///` it returns `some/malformed/path`
5
- *
6
- * - Removes subsequent slashes
7
- * - Removing initial and ending slashes
8
- * - Returns an empty string `"""` if only slashes are given
9
- */ export function normaliseUrlPathname(pathname = "") {
10
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
11
- // we would instead return a single slash if only slashes are given
12
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
13
- }
14
- /**
15
- * Transform to path any absolute or relative URL
16
- *
17
- * Useful when setting up `rewrites` and `redirects` especally in a [multi-zones
18
- * setup](https://nextjs.org/docs/advanced-features/multi-zones).
19
- *
20
- * From a path like `http://localhost/some//malformed/path///` it returns `/some/malformed/path`
21
- *
22
- * @see {@link normaliseUrlPathname}
23
- */ export function toPath(urlOrPathname = "") {
24
- let pathname = "";
25
- try {
26
- const parsed = new URL(urlOrPathname);
27
- pathname = parsed.pathname;
28
- } catch (e) {
29
- pathname = urlOrPathname;
30
- }
31
- // with return pathname.replace(/\/+\//g, "/").replace(/^\/+(.*?)\/+$/, "$1");
32
- // we would instead return a single slash if only slashes are given
33
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
34
- }
35
- /**
36
- * Clean a pathname and encode each part
37
- *
38
- * @see {@link normaliseUrlPathname}
39
- */ export function encodePathname(pathname = "") {
40
- const parts = normaliseUrlPathname(pathname).split("/");
41
- return parts.filter((part)=>!!part).map((part)=>encodeURIComponent(part)).join("/");
42
- }
43
- /**
44
- * Transform the route translated defintion into a `pathname` and a `template`.
45
- *
46
- * Here we add the wildcard flag maybe found in the pathname to the template
47
- * name too, this is because we do not want to have the wildcard in the JSON
48
- * keys as those are also used to produce links throught the `useTo` hook and
49
- * having asterisks there is a bit cumbersome.
50
- *
51
- * @see https://nextjs.org/docs/messages/invalid-multi-match
52
- */ function transformRoute(route) {
53
- const { pathname: rawPathname, template: rawTemplate } = route;
54
- const pathnameParts = rawPathname.split("/").filter((part)=>!!part);
55
- const templateParts = rawTemplate.split("/").filter((part)=>!!part);
56
- const mapPartsByIdx = {};
57
- const pathname = pathnameParts.map((part)=>{
58
- const hasWildcard = part.endsWith("*");
59
- part = part.replace("*", "");
60
- const isDynamic = part.startsWith("{{") && part.endsWith("}}");
61
- const asValue = isDynamic ? part.match(/{{(.+)}}/)?.[1].trim() ?? "" : part.trim();
62
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
63
- mapPartsByIdx[asValue] = {
64
- isDynamic,
65
- hasWildcard
66
- };
67
- return isDynamic ? `:${asPath}` : asPath;
68
- }).join("/");
69
- const template = templateParts.map((part)=>{
70
- const isDynamic = part.startsWith("[") && part.endsWith("]");
71
- const asValue = isDynamic ? part.match(/\[(.+)\]/)?.[1].trim() ?? "" : part.trim();
72
- const hasWildcard = mapPartsByIdx[asValue]?.hasWildcard;
73
- const asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
74
- return isDynamic ? `:${asPath}` : asPath;
75
- }).join("/");
76
- return {
77
- pathname,
78
- template
79
- };
80
- }
81
- /**
82
- * Get routes map dictionary
83
- */ function getRoutesMap(map = {}, routes, pathnameBuffer = "", templateBuffer = "") {
84
- for(const key in routes){
85
- const pathOrNestedRoutes = routes[key];
86
- const template = `${templateBuffer}/${key}`;
87
- if (typeof pathOrNestedRoutes === "string") {
88
- map[template] = {
89
- template,
90
- pathname: pathOrNestedRoutes,
91
- wildcard: pathOrNestedRoutes.includes("*")
92
- };
93
- } else {
94
- getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
95
- }
96
- }
97
- return map;
98
- }
99
- /**
100
- * Removes `/index` from a template/url path
101
- */ function getWithoutIndex(template) {
102
- return template.replace(/\/index$/, "");
103
- }
104
- /**
105
- * Get path rewrite
106
- */ export function getPathRewrite(route) {
107
- const { pathname, template } = transformRoute(route);
108
- const source = `/${normaliseUrlPathname(pathname)}`;
109
- const destination = `/${normaliseUrlPathname(template)}`;
110
- // console.log(`rewrite pathname "${source}" to template "${destination}"`);
111
- return {
112
- source,
113
- destination: getWithoutIndex(destination)
114
- };
115
- }
116
- /**
117
- * Get path redirect
118
- */ export function getPathRedirect(locale = "", route, permanent) {
119
- const { template, pathname } = transformRoute(route);
120
- const source = `/${normaliseUrlPathname((locale ? `/${locale}/` : "/") + template)}`;
121
- const destination = `/${normaliseUrlPathname(pathname)}`;
122
- // console.log(`redirect template "${source}" to pathname "${destination}"`);
123
- return {
124
- source: getWithoutIndex(source),
125
- destination,
126
- permanent: Boolean(permanent),
127
- locale: false
128
- };
129
- }
130
- /**
131
- */ export async function getRedirects(defaultLocale, routes, permanent, debug) {
132
- const redirects = [];
133
- const routesMap = getRoutesMap({}, routes);
134
- Object.keys(routesMap).forEach((template)=>{
135
- const route = routesMap[template];
136
- // TODO: add option hideDefaultLocaleInUrl?
137
- // this is meant to redirect the URL with the default locale to the same
138
- // url without locale prefix, e.g.: /en/about -> /about (assuming en is the
139
- // defualt locale).
140
- // Actually this redirect seem not to be necessary, probably the i18n routing
141
- // mechanism of next 12 already does this, enabling causes infinite redirects
142
- // if (hideDefaultLocaleInUrl) {
143
- // redirects.push(getPathRedirect(defaultLocale, route, permanent));
144
- // }
145
- if (route.pathname !== getWithoutIndex(template)) {
146
- redirects.push(getPathRedirect("", route, permanent));
147
- }
148
- });
149
- if (debug) console.info("[@koine/next/config:getRedirects]", redirects);
150
- return redirects;
151
- }
152
- /**
153
- */ export async function getRewrites(routes, debug) {
154
- const rewrites = [];
155
- const routesMap = getRoutesMap({}, routes);
156
- Object.keys(routesMap).forEach((template)=>{
157
- const route = routesMap[template];
158
- if (route.pathname !== getWithoutIndex(template)) {
159
- rewrites.push(getPathRewrite(route));
160
- }
161
- });
162
- if (debug) console.info("[@koine/next/config:getRewrites]", rewrites);
163
- return rewrites;
164
- }
165
- /**
166
- * Get Next.js config with some basic opinionated defaults
167
- *
168
- * @param {object} options
169
- * @property {boolean} [options.nx=false] Nx monorepo setup
170
- * @property {boolean} [options.svg=false] Svg to react components
171
- * @property {boolean} [options.sc=false] Styled components enabled
172
- * @property {boolean} [options.page=false] When `true` uses `*.page.ts` or `*.page.tsx`
173
- * extension for next.js config option [`pageExtensions`](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory)
174
- * and it enables the same for `next-translate`.
175
- */ export function withKoine({ nx = true, svg = true, sc = true, page, routes, permanent, debug, ...custom } = {
176
- i18n: {
177
- locales: [
178
- "en"
179
- ],
180
- defaultLocale: "en"
181
- }
182
- }) {
183
- const nextConfig = {
184
- // @see https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions#including-non-page-files-in-the-pages-directory
185
- pageExtensions: page ? [
186
- "page.tsx",
187
- "page.ts"
188
- ] : undefined,
189
- eslint: {
190
- ignoreDuringBuilds: true
191
- },
192
- typescript: {
193
- ignoreBuildErrors: true
194
- },
195
- poweredByHeader: false,
196
- swcMinify: true,
197
- modularizeImports: {
198
- "@koine/api": {
199
- transform: "@koine/api/{{member}}"
200
- },
201
- "@koine/browser": {
202
- transform: "@koine/browser/{{member}}"
203
- },
204
- "@koine/dom": {
205
- transform: "@koine/dom/{{member}}"
206
- },
207
- "@koine/next/?(((\\w*)?/?)*)": {
208
- transform: "@koine/next/{{ matches.[1] }}/{{member}}"
209
- },
210
- "@koine/react/?(((\\w*)?/?)*)": {
211
- transform: "@koine/react/{{ matches.[1] }}/{{member}}"
212
- },
213
- "@koine/utils": {
214
- transform: "@koine/utils/{{member}}"
215
- },
216
- ...custom["modularizeImports"] || {}
217
- },
218
- experimental: {
219
- // @see https://github.com/vercel/vercel/discussions/5973#discussioncomment-472618
220
- // @see critters error https://github.com/vercel/next.js/issues/20742
221
- // optimizeCss: true,
222
- // @see https://github.com/vercel/next.js/discussions/30174#discussion-3643870
223
- scrollRestoration: true,
224
- // concurrentFeatures: true,
225
- // serverComponents: true,
226
- // reactRoot: true,
227
- ...custom["experimental"] || {}
228
- },
229
- // @see https://github.com/vercel/next.js/issues/7322#issuecomment-887330111
230
- // reactStrictMode: true,
231
- ...custom
232
- };
233
- if (svg) {
234
- if (nx) {
235
- // @see https://github.com/gregberge/svgr
236
- nextConfig["nx"] = {
237
- svgr: true
238
- };
239
- } else {
240
- nextConfig.webpack = (_config, options)=>{
241
- const webpackConfig = typeof nextConfig.webpack === "function" ? nextConfig.webpack(_config, options) : _config;
242
- // @see https://dev.to/dolearning/importing-svgs-to-next-js-nna#svgr
243
- webpackConfig.module.rules.push({
244
- test: /\.svg$/,
245
- use: [
246
- {
247
- loader: "@svgr/webpack",
248
- options: {
249
- svgoConfig: {
250
- plugins: [
251
- {
252
- name: "removeViewBox",
253
- active: false
254
- }
255
- ]
256
- }
257
- }
258
- }
259
- ]
260
- });
261
- return webpackConfig;
262
- };
263
- }
264
- }
265
- if (sc) {
266
- nextConfig.compiler = {
267
- styledComponents: true
268
- };
269
- }
270
- if (routes) {
271
- // we pass the default values, so we can assert I guess
272
- const defaultLocale = nextConfig?.i18n?.defaultLocale;
273
- return {
274
- ...nextConfig,
275
- async redirects () {
276
- const defaults = await getRedirects(defaultLocale, routes, permanent, debug);
277
- if (nextConfig.redirects) {
278
- const customs = await nextConfig.redirects();
279
- return [
280
- ...defaults,
281
- ...customs
282
- ];
283
- }
284
- return defaults;
285
- },
286
- async rewrites () {
287
- const defaults = await getRewrites(routes, debug);
288
- if (nextConfig.rewrites) {
289
- const customs = await nextConfig.rewrites();
290
- if (Array.isArray(customs)) {
291
- return {
292
- beforeFiles: defaults,
293
- afterFiles: customs,
294
- fallback: []
295
- };
296
- }
297
- return {
298
- ...customs,
299
- beforeFiles: [
300
- ...defaults,
301
- ...customs.beforeFiles || []
302
- ]
303
- };
304
- }
305
- return {
306
- afterFiles: [],
307
- beforeFiles: defaults,
308
- fallback: []
309
- };
310
- }
311
- };
312
- }
313
- return nextConfig;
314
- }
315
- export default withKoine;
package/getSiteUrl.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * Get site absolute url with the given path
3
- *
4
- * - It uses the `NEXT_PUBLIC_APP_URL` env variable
5
- * - It removes the trailing slashes
6
- */
7
- export declare function getSiteUrl(path?: string): string;
8
- export default getSiteUrl;
package/getSiteUrl.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- getSiteUrl: function() {
13
- return getSiteUrl;
14
- },
15
- default: function() {
16
- return _default;
17
- }
18
- });
19
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
20
- const _normaliseUrl = /*#__PURE__*/ _interop_require_default._(require("@koine/utils/normaliseUrl"));
21
- function getSiteUrl(path = "") {
22
- return (0, _normaliseUrl.default)(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
23
- }
24
- const _default = getSiteUrl;
package/getSiteUrl.mjs DELETED
@@ -1,10 +0,0 @@
1
- import normaliseUrl from "@koine/utils/normaliseUrl";
2
- /**
3
- * Get site absolute url with the given path
4
- *
5
- * - It uses the `NEXT_PUBLIC_APP_URL` env variable
6
- * - It removes the trailing slashes
7
- */ export function getSiteUrl(path = "") {
8
- return normaliseUrl(`${process.env["NEXT_PUBLIC_APP_URL"]}/${path}`);
9
- }
10
- export default getSiteUrl;