@koine/next 2.0.0-beta.17 → 2.0.0-beta.19

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 (95) hide show
  1. package/12/AnalyticsGoogle.d.ts +0 -0
  2. package/12/AnalyticsGoogle.js +0 -0
  3. package/12/DisableErrorOverlay.d.ts +0 -0
  4. package/12/DisableErrorOverlay.js +0 -0
  5. package/12/DynamicNamespaces.d.ts +0 -0
  6. package/12/DynamicNamespaces.js +0 -0
  7. package/12/Favicon.d.ts +0 -0
  8. package/12/Favicon.js +0 -0
  9. package/12/Link.d.ts +0 -0
  10. package/12/Link.js +0 -0
  11. package/12/NextProgress.d.ts +0 -0
  12. package/12/NextProgress.js +0 -0
  13. package/12/Seo.d.ts +0 -0
  14. package/12/Seo.js +0 -0
  15. package/12/SeoDefaults.d.ts +0 -0
  16. package/12/SeoDefaults.js +0 -0
  17. package/12/T.d.ts +0 -0
  18. package/12/T.js +0 -0
  19. package/12/TransText.d.ts +0 -0
  20. package/12/TransText.js +0 -0
  21. package/12/app/AppHead.d.ts +0 -0
  22. package/12/app/AppHead.js +0 -0
  23. package/12/app/AppMain.d.ts +0 -0
  24. package/12/app/AppMain.js +0 -0
  25. package/12/app/css/AppMain.d.ts +0 -0
  26. package/12/app/css/AppMain.js +0 -0
  27. package/12/app/css/AppTheme.d.ts +0 -0
  28. package/12/app/css/AppTheme.js +0 -0
  29. package/12/app/css/auth/index.d.ts +0 -0
  30. package/12/app/css/auth/index.js +0 -0
  31. package/12/app/css/index.d.ts +0 -0
  32. package/12/app/css/index.js +0 -0
  33. package/12/app/index.d.ts +0 -0
  34. package/12/app/index.js +0 -0
  35. package/12/app/sc/AppMain.d.ts +0 -0
  36. package/12/app/sc/AppMain.js +0 -0
  37. package/12/app/sc/AppTheme.d.ts +0 -0
  38. package/12/app/sc/AppTheme.js +0 -0
  39. package/12/app/sc/auth/index.d.ts +0 -0
  40. package/12/app/sc/auth/index.js +0 -0
  41. package/12/app/sc/index.d.ts +0 -0
  42. package/12/app/sc/index.js +0 -0
  43. package/12/document/Document.d.ts +0 -0
  44. package/12/document/Document.js +0 -0
  45. package/12/document/css/index.d.ts +0 -0
  46. package/12/document/css/index.js +0 -0
  47. package/12/document/index.d.ts +0 -0
  48. package/12/document/index.js +0 -0
  49. package/12/document/sc/index.d.ts +0 -0
  50. package/12/document/sc/index.js +0 -0
  51. package/12/getT.d.ts +0 -0
  52. package/12/getT.js +0 -0
  53. package/12/index.d.ts +0 -0
  54. package/12/index.js +0 -0
  55. package/12/seoBuildTags.d.ts +0 -0
  56. package/12/seoBuildTags.js +0 -0
  57. package/12/to.d.ts +0 -0
  58. package/12/to.js +0 -0
  59. package/12/translationAsOptions.d.ts +0 -0
  60. package/12/translationAsOptions.js +0 -0
  61. package/12/types-i18n.d.ts +0 -0
  62. package/12/types-i18n.js +0 -0
  63. package/12/types-seo.d.ts +0 -0
  64. package/12/types-seo.js +0 -0
  65. package/12/types.d.ts +0 -0
  66. package/12/types.js +0 -0
  67. package/12/useBackUrl.d.ts +0 -0
  68. package/12/useBackUrl.js +0 -0
  69. package/12/useDateFormat.d.ts +0 -0
  70. package/12/useDateFormat.js +0 -0
  71. package/12/useForm.d.ts +0 -0
  72. package/12/useForm.js +0 -0
  73. package/12/useLocale.d.ts +0 -0
  74. package/12/useLocale.js +0 -0
  75. package/12/useT.d.ts +0 -0
  76. package/12/useT.js +0 -0
  77. package/12/useTo.d.ts +0 -0
  78. package/12/useTo.js +0 -0
  79. package/ThemeContext.d.ts +0 -0
  80. package/ThemeContext.js +0 -0
  81. package/ThemeProvider.d.ts +0 -0
  82. package/ThemeProvider.js +0 -0
  83. package/config-i18n.d.ts +52 -0
  84. package/config-i18n.js +251 -0
  85. package/config.d.ts +99 -27
  86. package/config.js +18 -146
  87. package/getSiteUrl.d.ts +0 -0
  88. package/getSiteUrl.js +0 -0
  89. package/index.d.ts +0 -0
  90. package/index.js +0 -0
  91. package/load.d.ts +0 -0
  92. package/load.js +0 -0
  93. package/package.json +7 -4
  94. package/useTheme.d.ts +0 -0
  95. package/useTheme.js +0 -0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/12/Favicon.d.ts CHANGED
File without changes
package/12/Favicon.js CHANGED
File without changes
package/12/Link.d.ts CHANGED
File without changes
package/12/Link.js CHANGED
File without changes
File without changes
File without changes
package/12/Seo.d.ts CHANGED
File without changes
package/12/Seo.js CHANGED
File without changes
File without changes
package/12/SeoDefaults.js CHANGED
File without changes
package/12/T.d.ts CHANGED
File without changes
package/12/T.js CHANGED
File without changes
package/12/TransText.d.ts CHANGED
File without changes
package/12/TransText.js CHANGED
File without changes
File without changes
package/12/app/AppHead.js CHANGED
File without changes
File without changes
package/12/app/AppMain.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/12/app/index.d.ts CHANGED
File without changes
package/12/app/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/12/getT.d.ts CHANGED
File without changes
package/12/getT.js CHANGED
File without changes
package/12/index.d.ts CHANGED
File without changes
package/12/index.js CHANGED
File without changes
File without changes
File without changes
package/12/to.d.ts CHANGED
File without changes
package/12/to.js CHANGED
File without changes
File without changes
File without changes
File without changes
package/12/types-i18n.js CHANGED
File without changes
package/12/types-seo.d.ts CHANGED
File without changes
package/12/types-seo.js CHANGED
File without changes
package/12/types.d.ts CHANGED
File without changes
package/12/types.js CHANGED
File without changes
File without changes
package/12/useBackUrl.js CHANGED
File without changes
File without changes
File without changes
package/12/useForm.d.ts CHANGED
File without changes
package/12/useForm.js CHANGED
File without changes
package/12/useLocale.d.ts CHANGED
File without changes
package/12/useLocale.js CHANGED
File without changes
package/12/useT.d.ts CHANGED
File without changes
package/12/useT.js CHANGED
File without changes
package/12/useTo.d.ts CHANGED
File without changes
package/12/useTo.js CHANGED
File without changes
package/ThemeContext.d.ts CHANGED
File without changes
package/ThemeContext.js CHANGED
File without changes
File without changes
package/ThemeProvider.js CHANGED
File without changes
@@ -0,0 +1,52 @@
1
+ import type { Redirect as _Redirect, Rewrite as _Rewrite } from "next/dist/lib/load-custom-routes";
2
+ export type Redirect = Omit<_Redirect, "locale"> & {
3
+ locale?: boolean;
4
+ };
5
+ export type Rewrite = Omit<_Rewrite, "locale"> & {
6
+ locale?: boolean;
7
+ };
8
+ type Route = string | {
9
+ [key: string]: Route | string;
10
+ };
11
+ type RoutesByLocale = Record<string, Route>;
12
+ export type Locale = string;
13
+ export type Routes = Record<Locale, RoutesByLocale>;
14
+ type RoutesMapRoute = {
15
+ template: string;
16
+ pathname: string;
17
+ wildcard?: boolean;
18
+ };
19
+ export declare function normaliseUrlPathname(pathname?: string): string;
20
+ export declare function toPath(urlOrPathname?: string): string;
21
+ export declare function encodePathname(pathname?: string): string;
22
+ export declare function getRoutesOfDefaultLocale(routes: Routes | RoutesByLocale, defaultLocale?: Locale): RoutesByLocale;
23
+ export type ConfigI18nOptions = {
24
+ locales: Locale[];
25
+ defaultLocale: Locale;
26
+ hideDefaultLocaleInUrl?: boolean;
27
+ localeParam?: string;
28
+ };
29
+ type Options = ConfigI18nOptions & {
30
+ routes: Routes;
31
+ debug?: boolean;
32
+ permanent?: boolean;
33
+ };
34
+ export declare function getPathRedirect(arg: Pick<GetRedirectsOptions, "localeParam" | "permanent"> & {
35
+ localeSource?: Locale;
36
+ localeDestination?: Locale;
37
+ route: RoutesMapRoute;
38
+ usePathnameAsSource?: boolean;
39
+ }): Redirect | undefined;
40
+ type GetRedirectsOptions = Options;
41
+ export declare function getRedirects(arg: GetRedirectsOptions): Promise<Redirect[]>;
42
+ export declare function getPathRewrite(arg: Pick<GetRewritesOptions, "localeParam"> & {
43
+ localeSource?: Locale;
44
+ localeDestination?: Locale;
45
+ route: RoutesMapRoute;
46
+ }): {
47
+ source: string;
48
+ destination: string;
49
+ } | undefined;
50
+ type GetRewritesOptions = Options;
51
+ export declare function getRewrites(arg: GetRewritesOptions): Promise<Rewrite[]>;
52
+ export {};
package/config-i18n.js ADDED
@@ -0,0 +1,251 @@
1
+ import { __assign, __awaiter, __generator } from "tslib";
2
+ var arrayUniqueByProperties = function (array, keys) {
3
+ return array.filter(function (item, idx, arr) {
4
+ return arr.findIndex(function (itemWith) {
5
+ return keys.every(function (k) { return itemWith[k] === item[k]; });
6
+ }) === idx;
7
+ });
8
+ };
9
+ export function normaliseUrlPathname(pathname) {
10
+ if (pathname === void 0) { pathname = ""; }
11
+ return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
12
+ }
13
+ export function toPath(urlOrPathname) {
14
+ if (urlOrPathname === void 0) { urlOrPathname = ""; }
15
+ var pathname = "";
16
+ try {
17
+ var parsed = new URL(urlOrPathname);
18
+ pathname = parsed.pathname;
19
+ }
20
+ catch (e) {
21
+ pathname = urlOrPathname;
22
+ }
23
+ return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
24
+ }
25
+ export function encodePathname(pathname) {
26
+ if (pathname === void 0) { pathname = ""; }
27
+ var parts = normaliseUrlPathname(pathname).split("/");
28
+ return parts
29
+ .filter(function (part) { return !!part; })
30
+ .map(function (part) { return encodeURIComponent(part); })
31
+ .join("/");
32
+ }
33
+ function transformRoute(route) {
34
+ var rawPathname = route.pathname, rawTemplate = route.template;
35
+ var pathnameParts = rawPathname.split("/").filter(function (part) { return !!part; });
36
+ var templateParts = rawTemplate.split("/").filter(function (part) { return !!part; });
37
+ var mapPartsByIdx = {};
38
+ var pathname = pathnameParts
39
+ .map(function (part) {
40
+ var _a, _b;
41
+ var hasWildcard = part.endsWith("*");
42
+ part = part.replace("*", "");
43
+ var isDynamic = part.startsWith("{{") && part.endsWith("}}");
44
+ var asValue = isDynamic
45
+ ? (_b = (_a = part.match(/{{(.+)}}/)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : ""
46
+ : part.trim();
47
+ var asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
48
+ mapPartsByIdx[asValue] = {
49
+ isDynamic: isDynamic,
50
+ hasWildcard: hasWildcard,
51
+ };
52
+ return isDynamic ? ":".concat(asPath) : asPath;
53
+ })
54
+ .join("/");
55
+ var template = templateParts
56
+ .map(function (part) {
57
+ var _a, _b, _c;
58
+ var isDynamic = part.startsWith("[") && part.endsWith("]");
59
+ var asValue = isDynamic
60
+ ? (_b = (_a = part.match(/\[(.+)\]/)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : ""
61
+ : part.trim();
62
+ var hasWildcard = (_c = mapPartsByIdx[asValue]) === null || _c === void 0 ? void 0 : _c.hasWildcard;
63
+ var asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
64
+ return isDynamic ? ":".concat(asPath) : asPath;
65
+ })
66
+ .join("/");
67
+ return { pathname: pathname, template: template };
68
+ }
69
+ function getRoutesMap(map, routesByLocale, pathnameBuffer, templateBuffer) {
70
+ if (map === void 0) { map = {}; }
71
+ if (pathnameBuffer === void 0) { pathnameBuffer = ""; }
72
+ if (templateBuffer === void 0) { templateBuffer = ""; }
73
+ var isSpaRoute = Object.keys(routesByLocale).includes("[spa]");
74
+ for (var key in routesByLocale) {
75
+ var pathOrNestedRoutes = routesByLocale[key];
76
+ var template = "".concat(templateBuffer, "/").concat(key);
77
+ if (typeof pathOrNestedRoutes === "string") {
78
+ if (!isSpaRoute || (isSpaRoute && ["[spa]", "index"].includes(key))) {
79
+ map[template] = {
80
+ template: template,
81
+ pathname: pathOrNestedRoutes,
82
+ wildcard: pathOrNestedRoutes.includes("*"),
83
+ };
84
+ }
85
+ }
86
+ else {
87
+ if (!isSpaRoute) {
88
+ getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
89
+ }
90
+ }
91
+ }
92
+ return map;
93
+ }
94
+ function getWithoutIndex(template) {
95
+ return template.replace(/\/index$/, "");
96
+ }
97
+ export function getRoutesOfDefaultLocale(routes, defaultLocale) {
98
+ var routesByLocale = routes;
99
+ if (defaultLocale &&
100
+ routesByLocale[defaultLocale]) {
101
+ return routesByLocale[defaultLocale];
102
+ }
103
+ if (Object.keys(routes).length === 1) {
104
+ var routesWithOneLocale = routes;
105
+ var output = {};
106
+ for (var onlyLocale in routesWithOneLocale) {
107
+ output =
108
+ routesWithOneLocale[onlyLocale];
109
+ }
110
+ return output;
111
+ }
112
+ return routes;
113
+ }
114
+ export function getPathRedirect(arg) {
115
+ var localeSource = arg.localeSource, localeDestination = arg.localeDestination, route = arg.route, usePathnameAsSource = arg.usePathnameAsSource, permanent = arg.permanent;
116
+ var _a = transformRoute(route), routeTemplate = _a.template, pathname = _a.pathname;
117
+ var template = usePathnameAsSource ? pathname : routeTemplate;
118
+ var sourcePrefix = localeSource ? "".concat(localeSource, "/") : "";
119
+ var source = getWithoutIndex("/".concat(normaliseUrlPathname(sourcePrefix + template)));
120
+ var destinationPrefix = localeDestination ? "".concat(localeDestination, "/") : "";
121
+ var destination = "/".concat(normaliseUrlPathname(destinationPrefix + pathname));
122
+ if (source === destination)
123
+ return;
124
+ var redirect = {
125
+ source: source,
126
+ destination: destination,
127
+ permanent: Boolean(permanent),
128
+ };
129
+ return redirect;
130
+ }
131
+ export function getRedirects(arg) {
132
+ return __awaiter(this, void 0, void 0, function () {
133
+ var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, permanent, debug, redirects, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
134
+ return __generator(this, function (_a) {
135
+ routes = arg.routes, defaultLocale = arg.defaultLocale, hideDefaultLocaleInUrl = arg.hideDefaultLocaleInUrl, localeParam = arg.localeParam, permanent = arg.permanent, debug = arg.debug;
136
+ redirects = [];
137
+ for (locale in routes) {
138
+ routesByLocale = routes[locale];
139
+ routesMap = getRoutesMap({}, routesByLocale);
140
+ for (template in routesMap) {
141
+ route = routesMap[template];
142
+ if (route.pathname !== getWithoutIndex(template)) {
143
+ isVisibleDefaultLocale = locale === defaultLocale && !hideDefaultLocaleInUrl;
144
+ isHiddenDefaultLocale = locale === defaultLocale && hideDefaultLocaleInUrl;
145
+ if (localeParam) {
146
+ if (isVisibleDefaultLocale) {
147
+ redirects.push(getPathRedirect({ localeDestination: locale, route: route, permanent: permanent }));
148
+ }
149
+ else if (isHiddenDefaultLocale) {
150
+ redirects.push(getPathRedirect({ localeSource: locale, route: route, permanent: permanent }));
151
+ }
152
+ else if (locale !== defaultLocale) {
153
+ redirects.push(getPathRedirect({
154
+ localeSource: locale,
155
+ localeDestination: locale,
156
+ route: route,
157
+ permanent: permanent,
158
+ }));
159
+ }
160
+ else {
161
+ redirects.push(getPathRedirect({ route: route, permanent: permanent }));
162
+ }
163
+ }
164
+ else {
165
+ if (isVisibleDefaultLocale) {
166
+ redirects.push(getPathRedirect({ localeDestination: locale, route: route, permanent: permanent }));
167
+ }
168
+ else if (locale !== defaultLocale) {
169
+ redirects.push(getPathRedirect({
170
+ localeSource: locale,
171
+ localeDestination: locale,
172
+ route: route,
173
+ permanent: permanent,
174
+ }));
175
+ }
176
+ else {
177
+ redirects.push(getPathRedirect({ route: route, permanent: permanent }));
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ cleaned = arrayUniqueByProperties(redirects.filter(Boolean), ["source", "destination"]).map(function (rewrite) { return (localeParam ? rewrite : __assign(__assign({}, rewrite), { locale: false })); });
184
+ if (debug)
185
+ console.info("[@koine/next/config:getRedirects]", cleaned);
186
+ return [2, cleaned];
187
+ });
188
+ });
189
+ }
190
+ export function getPathRewrite(arg) {
191
+ var localeSource = arg.localeSource, localeDestination = arg.localeDestination, localeParam = arg.localeParam, route = arg.route;
192
+ var _a = transformRoute(route), pathname = _a.pathname, template = _a.template;
193
+ var sourcePrefix = "";
194
+ if (localeSource)
195
+ sourcePrefix = "".concat(localeSource, "/");
196
+ else if (localeParam)
197
+ sourcePrefix = ":".concat(localeParam, "/");
198
+ var source = "/".concat(normaliseUrlPathname(sourcePrefix + pathname));
199
+ var destinationPrefix = "";
200
+ if (localeDestination)
201
+ destinationPrefix = "".concat(localeDestination, "/");
202
+ else if (localeParam)
203
+ destinationPrefix = ":".concat(localeParam, "/");
204
+ var destination = getWithoutIndex("/".concat(normaliseUrlPathname(destinationPrefix + template)));
205
+ if (source === destination)
206
+ return;
207
+ return {
208
+ source: source,
209
+ destination: destination,
210
+ };
211
+ }
212
+ export function getRewrites(arg) {
213
+ return __awaiter(this, void 0, void 0, function () {
214
+ var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, debug, rewrites, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
215
+ return __generator(this, function (_a) {
216
+ routes = arg.routes, defaultLocale = arg.defaultLocale, hideDefaultLocaleInUrl = arg.hideDefaultLocaleInUrl, localeParam = arg.localeParam, debug = arg.debug;
217
+ rewrites = [];
218
+ for (locale in routes) {
219
+ routesByLocale = routes[locale];
220
+ routesMap = getRoutesMap({}, routesByLocale);
221
+ for (template in routesMap) {
222
+ route = routesMap[template];
223
+ isVisibleDefaultLocale = locale === defaultLocale && !hideDefaultLocaleInUrl;
224
+ isHiddenDefaultLocale = locale === defaultLocale && hideDefaultLocaleInUrl;
225
+ if (localeParam) {
226
+ if (isHiddenDefaultLocale) {
227
+ rewrites.push(getPathRewrite({ localeDestination: locale, route: route }));
228
+ }
229
+ else {
230
+ rewrites.push(getPathRewrite({ localeParam: localeParam, route: route }));
231
+ }
232
+ }
233
+ else {
234
+ if (route.pathname !== getWithoutIndex(template)) {
235
+ if (locale !== defaultLocale || isVisibleDefaultLocale) {
236
+ rewrites.push(getPathRewrite({ localeSource: locale, route: route }));
237
+ }
238
+ else {
239
+ rewrites.push(getPathRewrite({ route: route }));
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ cleaned = arrayUniqueByProperties(rewrites.filter(Boolean), ["source", "destination"]);
246
+ if (debug)
247
+ console.info("[@koine/next/config:getRewrites]", cleaned);
248
+ return [2, cleaned];
249
+ });
250
+ });
251
+ }
package/config.d.ts CHANGED
@@ -1,30 +1,6 @@
1
1
  import type { NextConfig } from "next";
2
- import type { Redirect, Rewrite } from "next/dist/lib/load-custom-routes";
3
- type Route = string | {
4
- [key: string]: Route | string;
5
- };
6
- type Routes = Record<string, Route>;
7
- type RoutesMapRoute = {
8
- template: string;
9
- pathname: string;
10
- wildcard?: boolean;
11
- };
12
- export declare function normaliseUrlPathname(pathname?: string): string;
13
- export declare function toPath(urlOrPathname?: string): string;
14
- export declare function encodePathname(pathname?: string): string;
15
- export declare function getPathRewrite(route: RoutesMapRoute): {
16
- source: string;
17
- destination: string;
18
- };
19
- export declare function getPathRedirect(locale: string | undefined, route: RoutesMapRoute, permanent?: boolean): {
20
- source: string;
21
- destination: string;
22
- permanent: boolean;
23
- locale: false;
24
- };
25
- export declare function getRedirects(defaultLocale: string, routes: Routes, permanent?: boolean, debug?: boolean): Promise<Redirect[]>;
26
- export declare function getRewrites(routes: Routes, debug?: boolean): Promise<Rewrite[]>;
27
- type KoineNextConfig = {
2
+ import { type ConfigI18nOptions, type Routes } from "./config-i18n.js";
3
+ interface KoineNextConfig {
28
4
  nx?: boolean;
29
5
  svg?: boolean;
30
6
  sc?: boolean;
@@ -32,6 +8,102 @@ type KoineNextConfig = {
32
8
  routes?: Routes;
33
9
  permanent?: boolean;
34
10
  debug?: boolean;
11
+ i18n: ConfigI18nOptions & {
12
+ loader?: any;
13
+ };
14
+ }
15
+ interface MergedConfig extends KoineNextConfig, Omit<NextConfig, "i18n"> {
16
+ }
17
+ export declare function withKoine({ nx, svg, sc, page, routes, permanent, debug, ...custom }?: MergedConfig): NextConfig | {
18
+ redirects(): Promise<import("./config-i18n.js").Redirect[]>;
19
+ rewrites(): Promise<{
20
+ beforeFiles: import("./config-i18n.js").Rewrite[];
21
+ afterFiles: import("next/dist/lib/load-custom-routes.js").Rewrite[];
22
+ fallback: import("next/dist/lib/load-custom-routes.js").Rewrite[];
23
+ }>;
24
+ exportPathMap?: ((defaultMap: import("next/dist/server/config-shared.js").ExportPathMap, ctx: {
25
+ dev: boolean;
26
+ dir: string;
27
+ outDir: string | null;
28
+ distDir: string;
29
+ buildId: string;
30
+ }) => import("next/dist/server/config-shared.js").ExportPathMap | Promise<import("next/dist/server/config-shared.js").ExportPathMap>) | undefined;
31
+ i18n?: import("next/dist/server/config-shared.js").I18NConfig | null | undefined;
32
+ eslint?: import("next/dist/server/config-shared.js").ESLintConfig | undefined;
33
+ typescript?: import("next/dist/server/config-shared.js").TypeScriptConfig | undefined;
34
+ headers?: (() => Promise<import("next/dist/lib/load-custom-routes.js").Header[]>) | undefined;
35
+ excludeDefaultMomentLocales?: boolean | undefined;
36
+ webpack?: import("next/dist/server/config-shared.js").NextJsWebpackConfig | null | undefined;
37
+ trailingSlash?: boolean | undefined;
38
+ env?: Record<string, string> | undefined;
39
+ distDir?: string | undefined;
40
+ cleanDistDir?: boolean | undefined;
41
+ assetPrefix?: string | undefined;
42
+ useFileSystemPublicRoutes?: boolean | undefined;
43
+ generateBuildId?: (() => string | Promise<string | null> | null) | undefined;
44
+ generateEtags?: boolean | undefined;
45
+ pageExtensions?: string[] | undefined;
46
+ compress?: boolean | undefined;
47
+ analyticsId?: string | undefined;
48
+ poweredByHeader?: boolean | undefined;
49
+ images?: Partial<import("next/dist/shared/lib/image-config.js").ImageConfigComplete> | undefined;
50
+ devIndicators?: {
51
+ buildActivity?: boolean | undefined;
52
+ buildActivityPosition?: "bottom-right" | "bottom-left" | "top-right" | "top-left" | undefined;
53
+ } | undefined;
54
+ onDemandEntries?: {
55
+ maxInactiveAge?: number | undefined;
56
+ pagesBufferLength?: number | undefined;
57
+ } | undefined;
58
+ amp?: {
59
+ canonicalBase?: string | undefined;
60
+ } | undefined;
61
+ basePath?: string | undefined;
62
+ sassOptions?: {
63
+ [key: string]: any;
64
+ } | undefined;
65
+ productionBrowserSourceMaps?: boolean | undefined;
66
+ optimizeFonts?: boolean | undefined;
67
+ reactProductionProfiling?: boolean | undefined;
68
+ reactStrictMode?: boolean | null | undefined;
69
+ publicRuntimeConfig?: {
70
+ [key: string]: any;
71
+ } | undefined;
72
+ serverRuntimeConfig?: {
73
+ [key: string]: any;
74
+ } | undefined;
75
+ httpAgentOptions?: {
76
+ keepAlive?: boolean | undefined;
77
+ } | undefined;
78
+ outputFileTracing?: boolean | undefined;
79
+ staticPageGenerationTimeout?: number | undefined;
80
+ crossOrigin?: false | "anonymous" | "use-credentials" | undefined;
81
+ swcMinify?: boolean | undefined;
82
+ compiler?: {
83
+ reactRemoveProperties?: boolean | {
84
+ properties?: string[] | undefined;
85
+ } | undefined;
86
+ relay?: {
87
+ src: string;
88
+ artifactDirectory?: string | undefined;
89
+ language?: "typescript" | "flow" | "javascript" | undefined;
90
+ eagerEsModules?: boolean | undefined;
91
+ } | undefined;
92
+ removeConsole?: boolean | {
93
+ exclude?: string[] | undefined;
94
+ } | undefined;
95
+ styledComponents?: boolean | import("next/dist/server/config-shared.js").StyledComponentsConfig | undefined;
96
+ emotion?: boolean | import("next/dist/server/config-shared.js").EmotionConfig | undefined;
97
+ } | undefined;
98
+ output?: "standalone" | "export" | undefined;
99
+ transpilePackages?: string[] | undefined;
100
+ skipMiddlewareUrlNormalize?: boolean | undefined;
101
+ skipTrailingSlashRedirect?: boolean | undefined;
102
+ modularizeImports?: Record<string, {
103
+ transform: string | Record<string, string>;
104
+ preventFullImport?: boolean | undefined;
105
+ skipDefaultConversion?: boolean | undefined;
106
+ }> | undefined;
107
+ experimental?: import("next/dist/server/config-shared.js").ExperimentalConfig | undefined;
35
108
  };
36
- export declare function withKoine({ nx, svg, sc, page, routes, permanent, debug, ...custom }?: NextConfig & KoineNextConfig): NextConfig;
37
109
  export default withKoine;
package/config.js CHANGED
@@ -1,150 +1,14 @@
1
1
  import { __assign, __awaiter, __generator, __read, __rest, __spreadArray } from "tslib";
2
- export function normaliseUrlPathname(pathname) {
3
- if (pathname === void 0) { pathname = ""; }
4
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
5
- }
6
- export function toPath(urlOrPathname) {
7
- if (urlOrPathname === void 0) { urlOrPathname = ""; }
8
- var pathname = "";
9
- try {
10
- var parsed = new URL(urlOrPathname);
11
- pathname = parsed.pathname;
12
- }
13
- catch (e) {
14
- pathname = urlOrPathname;
15
- }
16
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
17
- }
18
- export function encodePathname(pathname) {
19
- if (pathname === void 0) { pathname = ""; }
20
- var parts = normaliseUrlPathname(pathname).split("/");
21
- return parts
22
- .filter(function (part) { return !!part; })
23
- .map(function (part) { return encodeURIComponent(part); })
24
- .join("/");
25
- }
26
- function transformRoute(route) {
27
- var rawPathname = route.pathname, rawTemplate = route.template;
28
- var pathnameParts = rawPathname.split("/").filter(function (part) { return !!part; });
29
- var templateParts = rawTemplate.split("/").filter(function (part) { return !!part; });
30
- var mapPartsByIdx = {};
31
- var pathname = pathnameParts
32
- .map(function (part) {
33
- var _a, _b;
34
- var hasWildcard = part.endsWith("*");
35
- part = part.replace("*", "");
36
- var isDynamic = part.startsWith("{{") && part.endsWith("}}");
37
- var asValue = isDynamic
38
- ? (_b = (_a = part.match(/{{(.+)}}/)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : ""
39
- : part.trim();
40
- var asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
41
- mapPartsByIdx[asValue] = {
42
- isDynamic: isDynamic,
43
- hasWildcard: hasWildcard,
44
- };
45
- return isDynamic ? ":".concat(asPath) : asPath;
46
- })
47
- .join("/");
48
- var template = templateParts
49
- .map(function (part) {
50
- var _a, _b, _c;
51
- var isDynamic = part.startsWith("[") && part.endsWith("]");
52
- var asValue = isDynamic
53
- ? (_b = (_a = part.match(/\[(.+)\]/)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : ""
54
- : part.trim();
55
- var hasWildcard = (_c = mapPartsByIdx[asValue]) === null || _c === void 0 ? void 0 : _c.hasWildcard;
56
- var asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
57
- return isDynamic ? ":".concat(asPath) : asPath;
58
- })
59
- .join("/");
60
- return { pathname: pathname, template: template };
61
- }
62
- function getRoutesMap(map, routes, pathnameBuffer, templateBuffer) {
63
- if (map === void 0) { map = {}; }
64
- if (pathnameBuffer === void 0) { pathnameBuffer = ""; }
65
- if (templateBuffer === void 0) { templateBuffer = ""; }
66
- for (var key in routes) {
67
- var pathOrNestedRoutes = routes[key];
68
- var template = "".concat(templateBuffer, "/").concat(key);
69
- if (typeof pathOrNestedRoutes === "string") {
70
- map[template] = {
71
- template: template,
72
- pathname: pathOrNestedRoutes,
73
- wildcard: pathOrNestedRoutes.includes("*"),
74
- };
75
- }
76
- else {
77
- getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
78
- }
79
- }
80
- return map;
81
- }
82
- function getWithoutIndex(template) {
83
- return template.replace(/\/index$/, "");
84
- }
85
- export function getPathRewrite(route) {
86
- var _a = transformRoute(route), pathname = _a.pathname, template = _a.template;
87
- var source = "/".concat(normaliseUrlPathname(pathname));
88
- var destination = "/".concat(normaliseUrlPathname(template));
89
- return {
90
- source: source,
91
- destination: getWithoutIndex(destination),
92
- };
93
- }
94
- export function getPathRedirect(locale, route, permanent) {
95
- if (locale === void 0) { locale = ""; }
96
- var _a = transformRoute(route), template = _a.template, pathname = _a.pathname;
97
- var source = "/".concat(normaliseUrlPathname((locale ? "/".concat(locale, "/") : "/") + template));
98
- var destination = "/".concat(normaliseUrlPathname(pathname));
99
- return {
100
- source: getWithoutIndex(source),
101
- destination: destination,
102
- permanent: Boolean(permanent),
103
- locale: false,
104
- };
105
- }
106
- export function getRedirects(defaultLocale, routes, permanent, debug) {
107
- return __awaiter(this, void 0, void 0, function () {
108
- var redirects, routesMap;
109
- return __generator(this, function (_a) {
110
- redirects = [];
111
- routesMap = getRoutesMap({}, routes);
112
- Object.keys(routesMap).forEach(function (template) {
113
- var route = routesMap[template];
114
- if (route.pathname !== getWithoutIndex(template)) {
115
- redirects.push(getPathRedirect("", route, permanent));
116
- }
117
- });
118
- if (debug)
119
- console.info("[@koine/next/config:getRedirects]", redirects);
120
- return [2, redirects];
121
- });
122
- });
123
- }
124
- export function getRewrites(routes, debug) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- var rewrites, routesMap;
127
- return __generator(this, function (_a) {
128
- rewrites = [];
129
- routesMap = getRoutesMap({}, routes);
130
- Object.keys(routesMap).forEach(function (template) {
131
- var route = routesMap[template];
132
- if (route.pathname !== getWithoutIndex(template)) {
133
- rewrites.push(getPathRewrite(route));
134
- }
135
- });
136
- if (debug)
137
- console.info("[@koine/next/config:getRewrites]", rewrites);
138
- return [2, rewrites];
139
- });
140
- });
141
- }
2
+ import { getRedirects, getRewrites, } from "./config-i18n.js";
142
3
  export function withKoine(_a) {
143
- var _b;
144
4
  if (_a === void 0) { _a = {
145
- i18n: { locales: ["en"], defaultLocale: "en" },
5
+ i18n: {
6
+ locales: ["en"],
7
+ defaultLocale: "en",
8
+ hideDefaultLocaleInUrl: false,
9
+ },
146
10
  }; }
147
- var _c = _a.nx, nx = _c === void 0 ? true : _c, _d = _a.svg, svg = _d === void 0 ? true : _d, _e = _a.sc, sc = _e === void 0 ? true : _e, page = _a.page, routes = _a.routes, permanent = _a.permanent, debug = _a.debug, custom = __rest(_a, ["nx", "svg", "sc", "page", "routes", "permanent", "debug"]);
11
+ var _b = _a.nx, nx = _b === void 0 ? true : _b, _c = _a.svg, svg = _c === void 0 ? true : _c, _d = _a.sc, sc = _d === void 0 ? true : _d, page = _a.page, routes = _a.routes, permanent = _a.permanent, debug = _a.debug, custom = __rest(_a, ["nx", "svg", "sc", "page", "routes", "permanent", "debug"]);
148
12
  var nextConfig = __assign({ pageExtensions: page ? ["page.tsx", "page.ts"] : undefined, eslint: {
149
13
  ignoreDuringBuilds: true,
150
14
  }, typescript: {
@@ -192,14 +56,22 @@ export function withKoine(_a) {
192
56
  styledComponents: true,
193
57
  };
194
58
  }
59
+ if (custom.i18n) {
60
+ var _e = custom.i18n || {}, hideDefaultLocaleInUrl = _e.hideDefaultLocaleInUrl, localeParam = _e.localeParam, loader = _e.loader, nextI18nConfig = __rest(_e, ["hideDefaultLocaleInUrl", "localeParam", "loader"]);
61
+ if (localeParam) {
62
+ delete nextConfig.i18n;
63
+ }
64
+ else {
65
+ nextConfig.i18n = nextI18nConfig;
66
+ }
67
+ }
195
68
  if (routes) {
196
- var defaultLocale_1 = (_b = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.i18n) === null || _b === void 0 ? void 0 : _b.defaultLocale;
197
69
  return __assign(__assign({}, nextConfig), { redirects: function () {
198
70
  return __awaiter(this, void 0, void 0, function () {
199
71
  var defaults, customs;
200
72
  return __generator(this, function (_a) {
201
73
  switch (_a.label) {
202
- case 0: return [4, getRedirects(defaultLocale_1, routes, permanent, debug)];
74
+ case 0: return [4, getRedirects(__assign({ routes: routes, permanent: permanent, debug: debug }, custom.i18n))];
203
75
  case 1:
204
76
  defaults = _a.sent();
205
77
  if (!nextConfig.redirects) return [3, 3];
@@ -216,7 +88,7 @@ export function withKoine(_a) {
216
88
  var defaults, customs;
217
89
  return __generator(this, function (_a) {
218
90
  switch (_a.label) {
219
- case 0: return [4, getRewrites(routes, debug)];
91
+ case 0: return [4, getRewrites(__assign({ routes: routes, debug: debug }, custom.i18n))];
220
92
  case 1:
221
93
  defaults = _a.sent();
222
94
  if (!nextConfig.rewrites) return [3, 3];
package/getSiteUrl.d.ts CHANGED
File without changes
package/getSiteUrl.js CHANGED
File without changes
package/index.d.ts CHANGED
File without changes
package/index.js CHANGED
File without changes
package/load.d.ts CHANGED
File without changes
package/load.js CHANGED
File without changes
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@koine/next",
3
3
  "sideEffects": false,
4
4
  "dependencies": {
5
- "@koine/browser": "2.0.0-beta.17",
6
- "@koine/react": "2.0.0-beta.17",
7
- "@koine/utils": "2.0.0-beta.17"
5
+ "@koine/browser": "2.0.0-beta.19",
6
+ "@koine/react": "2.0.0-beta.19",
7
+ "@koine/utils": "2.0.0-beta.19"
8
8
  },
9
9
  "peerDependenciesMeta": {
10
10
  "@hookform/resolvers": {
@@ -201,6 +201,9 @@
201
201
  "./ThemeProvider": {
202
202
  "import": "./ThemeProvider.js"
203
203
  },
204
+ "./config-i18n": {
205
+ "import": "./config-i18n.js"
206
+ },
204
207
  "./config": {
205
208
  "import": "./config.js"
206
209
  },
@@ -215,5 +218,5 @@
215
218
  }
216
219
  },
217
220
  "peerDependencies": {},
218
- "version": "2.0.0-beta.17"
221
+ "version": "2.0.0-beta.19"
219
222
  }
package/useTheme.d.ts CHANGED
File without changes
package/useTheme.js CHANGED
File without changes