@koine/next 2.0.0-beta.37 → 2.0.0-beta.39

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 (92) hide show
  1. package/12/Seo.d.ts +2 -2
  2. package/12/SeoDefaults.d.ts +1 -1
  3. package/12/seoBuildTags.d.ts +2 -2
  4. package/12/types.d.ts +1 -4
  5. package/12.cjs.d.ts +1 -0
  6. package/12.cjs.default.js +1 -0
  7. package/12.cjs.js +28 -0
  8. package/12.cjs.mjs +2 -0
  9. package/12.d.ts +3 -0
  10. package/12.esm.js +18 -0
  11. package/README.md +13 -0
  12. package/config-i18n.d.ts +2 -28
  13. package/config.cjs.d.ts +1 -0
  14. package/config.cjs.default.js +1 -0
  15. package/config.cjs.js +9 -0
  16. package/config.cjs.mjs +2 -0
  17. package/config.d.ts +5 -3
  18. package/config.esm.js +5 -0
  19. package/index.cjs.d.ts +1 -0
  20. package/index.cjs.default.js +1 -0
  21. package/index.cjs.js +25 -0
  22. package/index.cjs.mjs +2 -0
  23. package/index.d.ts +4 -4
  24. package/index.esm.js +14 -0
  25. package/package.json +21 -128
  26. package/{useTheme.d.ts → theme/useTheme.d.ts} +1 -1
  27. package/{load.d.ts → utils/load.d.ts} +0 -1
  28. package/12/AnalyticsGoogle.js +0 -33
  29. package/12/DisableErrorOverlay.js +0 -8
  30. package/12/DynamicNamespaces.d.ts +0 -8
  31. package/12/DynamicNamespaces.js +0 -4
  32. package/12/Favicon.d.ts +0 -4
  33. package/12/Favicon.js +0 -6
  34. package/12/NextProgress.js +0 -40
  35. package/12/Seo.js +0 -7
  36. package/12/SeoDefaults.js +0 -7
  37. package/12/T.d.ts +0 -11
  38. package/12/T.js +0 -8
  39. package/12/TransText.d.ts +0 -3
  40. package/12/TransText.js +0 -4
  41. package/12/app/AppHead.d.ts +0 -3
  42. package/12/app/AppHead.js +0 -6
  43. package/12/app/AppMain.d.ts +0 -11
  44. package/12/app/AppMain.js +0 -1
  45. package/12/app/css/AppMain.d.ts +0 -4
  46. package/12/app/css/AppMain.js +0 -9
  47. package/12/app/css/AppTheme.d.ts +0 -8
  48. package/12/app/css/AppTheme.js +0 -7
  49. package/12/app/css/index.d.ts +0 -6
  50. package/12/app/css/index.js +0 -9
  51. package/12/app/index.d.ts +0 -2
  52. package/12/app/index.js +0 -2
  53. package/12/createUseLocale.d.ts +0 -2
  54. package/12/createUseLocale.js +0 -7
  55. package/12/createUseT.d.ts +0 -6
  56. package/12/createUseT.js +0 -18
  57. package/12/createUseTo.d.ts +0 -3
  58. package/12/createUseTo.js +0 -21
  59. package/12/document/Document.d.ts +0 -5
  60. package/12/document/Document.js +0 -18
  61. package/12/document/css/index.d.ts +0 -5
  62. package/12/document/css/index.js +0 -18
  63. package/12/document/index.d.ts +0 -2
  64. package/12/document/index.js +0 -2
  65. package/12/getT.d.ts +0 -4
  66. package/12/getT.js +0 -4
  67. package/12/index.d.ts +0 -6
  68. package/12/index.js +0 -6
  69. package/12/seoBuildTags.js +0 -93
  70. package/12/translationAsOptions.d.ts +0 -4
  71. package/12/translationAsOptions.js +0 -10
  72. package/12/types-seo.js +0 -1
  73. package/12/types.js +0 -1
  74. package/12/typings.d.ts +0 -48
  75. package/12/useBackUrl.d.ts +0 -2
  76. package/12/useBackUrl.js +0 -24
  77. package/12/useDateFormat.d.ts +0 -3
  78. package/12/useDateFormat.js +0 -35
  79. package/12/useLocale.d.ts +0 -2
  80. package/12/useLocale.js +0 -6
  81. package/12/useT.d.ts +0 -0
  82. package/12/useT.js +0 -1
  83. package/ThemeContext.js +0 -6
  84. package/ThemeProvider.js +0 -204
  85. package/config-i18n.js +0 -258
  86. package/config.js +0 -114
  87. package/index.js +0 -4
  88. package/load.js +0 -6
  89. package/typings.d.ts +0 -33
  90. package/useTheme.js +0 -5
  91. /package/{ThemeContext.d.ts → theme/ThemeContext.d.ts} +0 -0
  92. /package/{ThemeProvider.d.ts → theme/ThemeProvider.d.ts} +0 -0
package/ThemeProvider.js DELETED
@@ -1,204 +0,0 @@
1
- "use client";
2
- import { __read, __spreadArray } from "tslib";
3
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
- import NextScript from "next/script";
5
- import { memo, useCallback, useEffect, useState } from "react";
6
- import { isServer } from "@koine/utils";
7
- import { ThemeContext } from "./ThemeContext.js";
8
- var colorSchemes = ["light", "dark"];
9
- var MEDIA = "(prefers-color-scheme: dark)";
10
- var THEME_STORAGE_KEY = "theme";
11
- export var ThemeProvider = function (_a) {
12
- var forcedTheme = _a.forcedTheme, _b = _a.disableTransitionOnChange, disableTransitionOnChange = _b === void 0 ? false : _b, _c = _a.enableSystem, enableSystem = _c === void 0 ? true : _c, enableColorScheme = _a.enableColorScheme, _d = _a.themes, themes = _d === void 0 ? ["light", "dark"] : _d, _e = _a.defaultTheme, defaultTheme = _e === void 0 ? enableSystem ? "system" : "light" : _e, _f = _a.attribute, attribute = _f === void 0 ? "data-theme" : _f, value = _a.value, children = _a.children, nonce = _a.nonce;
13
- var _g = __read(useState(function () {
14
- return getTheme(THEME_STORAGE_KEY, defaultTheme);
15
- }), 2), theme = _g[0], setThemeState = _g[1];
16
- var _h = __read(useState(function () {
17
- return getTheme(THEME_STORAGE_KEY);
18
- }), 2), resolvedTheme = _h[0], setResolvedTheme = _h[1];
19
- var attrs = !value ? themes : Object.values(value);
20
- var applyTheme = useCallback(function (theme) {
21
- var _a;
22
- var resolved = theme;
23
- if (isServer || !resolved)
24
- return;
25
- if (theme === "system" && enableSystem) {
26
- resolved = getSystemTheme();
27
- }
28
- var name = value ? value[resolved] : resolved;
29
- var enable = disableTransitionOnChange ? disableAnimation() : null;
30
- var d = document.documentElement;
31
- if (attribute === "class") {
32
- (_a = d.classList).remove.apply(_a, __spreadArray([], __read(attrs), false));
33
- if (name)
34
- d.classList.add(name);
35
- }
36
- else {
37
- if (name) {
38
- d.setAttribute(attribute, name);
39
- }
40
- else {
41
- d.removeAttribute(attribute);
42
- }
43
- }
44
- if (enableColorScheme) {
45
- var fallback = colorSchemes.includes(defaultTheme)
46
- ? defaultTheme
47
- : "";
48
- var colorScheme = colorSchemes.includes(resolved)
49
- ? resolved
50
- : fallback;
51
- d.style.colorScheme = colorScheme;
52
- }
53
- enable === null || enable === void 0 ? void 0 : enable();
54
- }, [
55
- attribute,
56
- attrs,
57
- defaultTheme,
58
- disableTransitionOnChange,
59
- enableColorScheme,
60
- enableSystem,
61
- value,
62
- ]);
63
- var setTheme = useCallback(function (theme) {
64
- setThemeState(theme);
65
- try {
66
- localStorage.setItem(THEME_STORAGE_KEY, theme);
67
- }
68
- catch (e) {
69
- }
70
- }, []);
71
- var handleMediaQuery = useCallback(function (e) {
72
- var resolved = getSystemTheme(e);
73
- setResolvedTheme(resolved);
74
- if (theme === "system" && enableSystem && !forcedTheme) {
75
- applyTheme("system");
76
- }
77
- }, [theme, enableSystem, forcedTheme, applyTheme]);
78
- useEffect(function () {
79
- var media = window.matchMedia(MEDIA);
80
- media.addListener(handleMediaQuery);
81
- handleMediaQuery(media);
82
- return function () { return media.removeListener(handleMediaQuery); };
83
- }, [handleMediaQuery]);
84
- useEffect(function () {
85
- var handleStorage = function (e) {
86
- if (e.key !== THEME_STORAGE_KEY) {
87
- return;
88
- }
89
- var theme = e.newValue || defaultTheme;
90
- setTheme(theme);
91
- };
92
- window.addEventListener("storage", handleStorage);
93
- return function () { return window.removeEventListener("storage", handleStorage); };
94
- }, [defaultTheme, setTheme]);
95
- useEffect(function () {
96
- applyTheme(forcedTheme !== null && forcedTheme !== void 0 ? forcedTheme : theme);
97
- }, [applyTheme, forcedTheme, theme]);
98
- return (_jsxs(ThemeContext.Provider, { value: {
99
- theme: theme,
100
- setTheme: setTheme,
101
- forcedTheme: forcedTheme,
102
- resolvedTheme: theme === "system" ? resolvedTheme : theme,
103
- themes: enableSystem ? __spreadArray(__spreadArray([], __read(themes), false), ["system"], false) : themes,
104
- systemTheme: (enableSystem ? resolvedTheme : undefined),
105
- }, children: [_jsx(ThemeScript, { forcedTheme: forcedTheme, disableTransitionOnChange: disableTransitionOnChange, enableSystem: enableSystem, enableColorScheme: enableColorScheme, themes: themes, defaultTheme: defaultTheme, attribute: attribute, value: value, children: children, attrs: attrs, nonce: nonce }), children] }));
106
- };
107
- var ThemeScript = memo(function (_a) {
108
- var forcedTheme = _a.forcedTheme, attribute = _a.attribute, enableSystem = _a.enableSystem, enableColorScheme = _a.enableColorScheme, defaultTheme = _a.defaultTheme, value = _a.value, attrs = _a.attrs, nonce = _a.nonce;
109
- var defaultSystem = defaultTheme === "system";
110
- var optimization = (function () {
111
- var removeClasses = "d.remove(".concat(attrs
112
- .map(function (t) { return "'".concat(t, "'"); })
113
- .join(","), ")");
114
- return "var d=document.documentElement.classList;".concat(removeClasses, ";");
115
- })();
116
- var fallbackColorScheme = (function () {
117
- if (!enableColorScheme) {
118
- return "";
119
- }
120
- var fallback = colorSchemes.includes(defaultTheme)
121
- ? defaultTheme
122
- : null;
123
- if (fallback) {
124
- return "if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'".concat(defaultTheme, "'");
125
- }
126
- else {
127
- return "if(e==='light'||e==='dark')d.style.colorScheme=e";
128
- }
129
- })();
130
- var updateDOM = function (name, literal, setColorScheme) {
131
- if (literal === void 0) { literal = false; }
132
- if (setColorScheme === void 0) { setColorScheme = true; }
133
- var resolvedName = value ? value[name] : name;
134
- var val = literal ? name + "|| ''" : "'".concat(resolvedName, "'");
135
- var text = "";
136
- if (enableColorScheme &&
137
- setColorScheme &&
138
- !literal &&
139
- colorSchemes.includes(name)) {
140
- text += "d.style.colorScheme = '".concat(name, "';");
141
- }
142
- if (attribute === "class") {
143
- if (literal || resolvedName) {
144
- text += "d.add(".concat(val, ")");
145
- }
146
- else {
147
- text += "null";
148
- }
149
- }
150
- else {
151
- if (resolvedName) {
152
- text += "d[s](n, ".concat(val, ")");
153
- }
154
- }
155
- return text;
156
- };
157
- var scriptSrc = (function () {
158
- if (forcedTheme) {
159
- return "!function(){".concat(optimization).concat(updateDOM(forcedTheme), "}()");
160
- }
161
- if (enableSystem) {
162
- return "!function(){try {".concat(optimization, "var e=localStorage.getItem('").concat(THEME_STORAGE_KEY, "');if(\"system\"===e||(!e&&").concat(defaultSystem, ")){var t=\"").concat(MEDIA, "\",m=window.matchMedia(t);if(m.media!==t||m.matches){").concat(updateDOM("dark"), "}else{").concat(updateDOM("light"), "}}else if(e){").concat(value ? "var x=".concat(JSON.stringify(value), ";") : "").concat(updateDOM(value ? "x[e]" : "e", true), "}").concat(!defaultSystem
163
- ? "else{" + updateDOM(defaultTheme, false, false) + "}"
164
- : "").concat(fallbackColorScheme, "}catch(e){}}()");
165
- }
166
- return "!function(){try{".concat(optimization, "var e=localStorage.getItem(\"").concat(THEME_STORAGE_KEY, "\");if(e){").concat(value ? "var x=".concat(JSON.stringify(value), ";") : "").concat(updateDOM(value ? "x[e]" : "e", true), "}else{").concat(updateDOM(defaultTheme, false, false), ";}").concat(fallbackColorScheme, "}catch(t){}}();");
167
- })();
168
- var encodedScript = "data:text/javascript;base64,".concat(encodeBase64(scriptSrc));
169
- return (_jsx(NextScript, { id: "next-theme-script", strategy: "beforeInteractive", src: encodedScript, nonce: nonce }));
170
- }, function () { return true; });
171
- var getTheme = function (key, fallback) {
172
- if (isServer)
173
- return undefined;
174
- var theme;
175
- try {
176
- theme = localStorage.getItem(key) || undefined;
177
- }
178
- catch (e) {
179
- }
180
- return theme || fallback;
181
- };
182
- var disableAnimation = function () {
183
- var d = document;
184
- var css = d.createElement("style");
185
- css.appendChild(d.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}"));
186
- d.head.appendChild(css);
187
- return function () {
188
- (function () { return window.getComputedStyle(d.body); })();
189
- setTimeout(function () {
190
- d.head.removeChild(css);
191
- }, 1);
192
- };
193
- };
194
- var getSystemTheme = function (e) {
195
- if (!e)
196
- e = window.matchMedia(MEDIA);
197
- var isDark = e.matches;
198
- var systemTheme = isDark ? "dark" : "light";
199
- return systemTheme;
200
- };
201
- var encodeBase64 = function (str) {
202
- return isServer ? Buffer.from(str).toString("base64") : btoa(str);
203
- };
204
- export default ThemeProvider;
package/config-i18n.js DELETED
@@ -1,258 +0,0 @@
1
- import { __assign, __awaiter, __generator, __rest } 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 orderRoutes(routes, defaultLocale) {
10
- var _a;
11
- var _b = routes, _c = defaultLocale, routesForDefaultLocale = _b[_c], restRoutes = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
12
- return __assign((_a = {}, _a[defaultLocale] = routesForDefaultLocale, _a), restRoutes);
13
- }
14
- export function normaliseUrlPathname(pathname) {
15
- if (pathname === void 0) { pathname = ""; }
16
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
17
- }
18
- export function toPath(urlOrPathname) {
19
- if (urlOrPathname === void 0) { urlOrPathname = ""; }
20
- var pathname = "";
21
- try {
22
- var parsed = new URL(urlOrPathname);
23
- pathname = parsed.pathname;
24
- }
25
- catch (e) {
26
- pathname = urlOrPathname;
27
- }
28
- return pathname.replace(/\/+\//g, "/").replace(/^\/*(.*?)\/*$/, "$1");
29
- }
30
- export function encodePathname(pathname) {
31
- if (pathname === void 0) { pathname = ""; }
32
- var parts = normaliseUrlPathname(pathname).split("/");
33
- return parts
34
- .filter(function (part) { return !!part; })
35
- .map(function (part) { return encodeURIComponent(part); })
36
- .join("/");
37
- }
38
- function transformRoute(route) {
39
- var rawPathname = route.pathname, rawTemplate = route.template;
40
- var pathnameParts = rawPathname.split("/").filter(function (part) { return !!part; });
41
- var templateParts = rawTemplate.split("/").filter(function (part) { return !!part; });
42
- var mapPartsByIdx = {};
43
- var pathname = pathnameParts
44
- .map(function (part) {
45
- var _a, _b;
46
- var hasWildcard = part.endsWith("*");
47
- part = part.replace("*", "");
48
- var isDynamic = part.startsWith("{{") && part.endsWith("}}");
49
- var asValue = isDynamic
50
- ? (_b = (_a = part.match(/{{(.+)}}/)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : ""
51
- : part.trim();
52
- var asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
53
- mapPartsByIdx[asValue] = {
54
- isDynamic: isDynamic,
55
- hasWildcard: hasWildcard,
56
- };
57
- return isDynamic ? ":".concat(asPath) : asPath;
58
- })
59
- .join("/");
60
- var template = templateParts
61
- .map(function (part) {
62
- var _a, _b, _c;
63
- var isDynamic = part.startsWith("[") && part.endsWith("]");
64
- var asValue = isDynamic
65
- ? (_b = (_a = part.match(/\[(.+)\]/)) === null || _a === void 0 ? void 0 : _a[1].trim()) !== null && _b !== void 0 ? _b : ""
66
- : part.trim();
67
- var hasWildcard = (_c = mapPartsByIdx[asValue]) === null || _c === void 0 ? void 0 : _c.hasWildcard;
68
- var asPath = encodeURIComponent(asValue) + (hasWildcard ? "*" : "");
69
- return isDynamic ? ":".concat(asPath) : asPath;
70
- })
71
- .join("/");
72
- return { pathname: pathname, template: template };
73
- }
74
- function getRoutesMap(map, routesByLocale, pathnameBuffer, templateBuffer) {
75
- if (map === void 0) { map = {}; }
76
- if (pathnameBuffer === void 0) { pathnameBuffer = ""; }
77
- if (templateBuffer === void 0) { templateBuffer = ""; }
78
- var isSpaRoute = Object.keys(routesByLocale).includes("[spa]");
79
- for (var key in routesByLocale) {
80
- var pathOrNestedRoutes = routesByLocale[key];
81
- var template = "".concat(templateBuffer, "/").concat(key);
82
- if (typeof pathOrNestedRoutes === "string") {
83
- if (!isSpaRoute || (isSpaRoute && ["[spa]", "index"].includes(key))) {
84
- map[template] = {
85
- template: template,
86
- pathname: pathOrNestedRoutes,
87
- wildcard: pathOrNestedRoutes.includes("*"),
88
- };
89
- }
90
- }
91
- else {
92
- if (!isSpaRoute) {
93
- getRoutesMap(map, pathOrNestedRoutes, pathnameBuffer, template);
94
- }
95
- }
96
- }
97
- return map;
98
- }
99
- function getWithoutIndex(template) {
100
- return template.replace(/\/index$/, "");
101
- }
102
- export function getRoutesOfDefaultLocale(routes, defaultLocale) {
103
- var routesByLocale = routes;
104
- if (defaultLocale &&
105
- routesByLocale[defaultLocale]) {
106
- return routesByLocale[defaultLocale];
107
- }
108
- if (Object.keys(routes).length === 1) {
109
- var routesWithOneLocale = routes;
110
- var output = {};
111
- for (var onlyLocale in routesWithOneLocale) {
112
- output =
113
- routesWithOneLocale[onlyLocale];
114
- }
115
- return output;
116
- }
117
- return routes;
118
- }
119
- export function getPathRedirect(arg) {
120
- var localeSource = arg.localeSource, localeDestination = arg.localeDestination, route = arg.route, usePathnameAsSource = arg.usePathnameAsSource, permanent = arg.permanent;
121
- var _a = transformRoute(route), routeTemplate = _a.template, pathname = _a.pathname;
122
- var template = usePathnameAsSource ? pathname : routeTemplate;
123
- var sourcePrefix = localeSource ? "".concat(localeSource, "/") : "";
124
- var source = getWithoutIndex("/".concat(normaliseUrlPathname(sourcePrefix + template)));
125
- var destinationPrefix = localeDestination ? "".concat(localeDestination, "/") : "";
126
- var destination = "/".concat(normaliseUrlPathname(destinationPrefix + pathname));
127
- if (source === destination)
128
- return;
129
- var redirect = {
130
- source: source,
131
- destination: destination,
132
- permanent: Boolean(permanent),
133
- };
134
- return redirect;
135
- }
136
- export function getRedirects(arg) {
137
- return __awaiter(this, void 0, void 0, function () {
138
- var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, permanent, debug, orderedRoutes, redirects, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
139
- return __generator(this, function (_a) {
140
- routes = arg.routes, defaultLocale = arg.defaultLocale, hideDefaultLocaleInUrl = arg.hideDefaultLocaleInUrl, localeParam = arg.localeParam, permanent = arg.permanent, debug = arg.debug;
141
- orderedRoutes = orderRoutes(routes, defaultLocale);
142
- redirects = [];
143
- for (locale in orderedRoutes) {
144
- routesByLocale = routes[locale];
145
- routesMap = getRoutesMap({}, routesByLocale);
146
- for (template in routesMap) {
147
- route = routesMap[template];
148
- if (route.pathname !== getWithoutIndex(template)) {
149
- isVisibleDefaultLocale = locale === defaultLocale && !hideDefaultLocaleInUrl;
150
- isHiddenDefaultLocale = locale === defaultLocale && hideDefaultLocaleInUrl;
151
- if (localeParam) {
152
- if (isVisibleDefaultLocale) {
153
- redirects.push(getPathRedirect({ localeDestination: locale, route: route, permanent: permanent }));
154
- }
155
- else if (isHiddenDefaultLocale) {
156
- redirects.push(getPathRedirect({ localeSource: locale, route: route, permanent: permanent }));
157
- }
158
- else if (locale !== defaultLocale) {
159
- redirects.push(getPathRedirect({
160
- localeSource: locale,
161
- localeDestination: locale,
162
- route: route,
163
- permanent: permanent,
164
- }));
165
- }
166
- else {
167
- redirects.push(getPathRedirect({ route: route, permanent: permanent }));
168
- }
169
- }
170
- else {
171
- if (isVisibleDefaultLocale) {
172
- redirects.push(getPathRedirect({ localeDestination: locale, route: route, permanent: permanent }));
173
- }
174
- else if (locale !== defaultLocale) {
175
- redirects.push(getPathRedirect({
176
- localeSource: locale,
177
- localeDestination: locale,
178
- route: route,
179
- permanent: permanent,
180
- }));
181
- }
182
- else {
183
- redirects.push(getPathRedirect({ route: route, permanent: permanent }));
184
- }
185
- }
186
- }
187
- }
188
- }
189
- cleaned = arrayUniqueByProperties(redirects.filter(Boolean), ["source", "destination"]).map(function (rewrite) { return (localeParam ? rewrite : __assign(__assign({}, rewrite), { locale: false })); });
190
- if (debug)
191
- console.info("[@koine/next/config:getRedirects]", cleaned);
192
- return [2, cleaned];
193
- });
194
- });
195
- }
196
- export function getPathRewrite(arg) {
197
- var localeSource = arg.localeSource, localeDestination = arg.localeDestination, localeParam = arg.localeParam, route = arg.route;
198
- var _a = transformRoute(route), pathname = _a.pathname, template = _a.template;
199
- var sourcePrefix = "";
200
- if (localeSource)
201
- sourcePrefix = "".concat(localeSource, "/");
202
- else if (localeParam)
203
- sourcePrefix = ":".concat(localeParam, "/");
204
- var source = "/".concat(normaliseUrlPathname(sourcePrefix + pathname));
205
- var destinationPrefix = "";
206
- if (localeDestination)
207
- destinationPrefix = "".concat(localeDestination, "/");
208
- else if (localeParam)
209
- destinationPrefix = ":".concat(localeParam, "/");
210
- var destination = getWithoutIndex("/".concat(normaliseUrlPathname(destinationPrefix + template)));
211
- if (source === destination)
212
- return;
213
- return {
214
- source: source,
215
- destination: destination,
216
- };
217
- }
218
- export function getRewrites(arg) {
219
- return __awaiter(this, void 0, void 0, function () {
220
- var routes, defaultLocale, hideDefaultLocaleInUrl, localeParam, debug, orderedRoutes, rewrites, locale, routesByLocale, routesMap, template, route, isVisibleDefaultLocale, isHiddenDefaultLocale, cleaned;
221
- return __generator(this, function (_a) {
222
- routes = arg.routes, defaultLocale = arg.defaultLocale, hideDefaultLocaleInUrl = arg.hideDefaultLocaleInUrl, localeParam = arg.localeParam, debug = arg.debug;
223
- orderedRoutes = orderRoutes(routes, defaultLocale);
224
- rewrites = [];
225
- for (locale in orderedRoutes) {
226
- routesByLocale = routes[locale];
227
- routesMap = getRoutesMap({}, routesByLocale);
228
- for (template in routesMap) {
229
- route = routesMap[template];
230
- isVisibleDefaultLocale = locale === defaultLocale && !hideDefaultLocaleInUrl;
231
- isHiddenDefaultLocale = locale === defaultLocale && hideDefaultLocaleInUrl;
232
- if (localeParam) {
233
- if (isHiddenDefaultLocale) {
234
- rewrites.push(getPathRewrite({ localeDestination: locale, route: route }));
235
- }
236
- else {
237
- rewrites.push(getPathRewrite({ localeParam: localeParam, route: route }));
238
- }
239
- }
240
- else {
241
- if (route.pathname !== getWithoutIndex(template)) {
242
- if (locale !== defaultLocale || isVisibleDefaultLocale) {
243
- rewrites.push(getPathRewrite({ localeSource: locale, route: route }));
244
- }
245
- else {
246
- rewrites.push(getPathRewrite({ route: route }));
247
- }
248
- }
249
- }
250
- }
251
- }
252
- cleaned = arrayUniqueByProperties(rewrites.filter(Boolean), ["source", "destination"]);
253
- if (debug)
254
- console.info("[@koine/next/config:getRewrites]", cleaned);
255
- return [2, cleaned];
256
- });
257
- });
258
- }
package/config.js DELETED
@@ -1,114 +0,0 @@
1
- import { __assign, __awaiter, __generator, __read, __rest, __spreadArray } from "tslib";
2
- import { getRedirects, getRewrites, } from "./config-i18n.js";
3
- export function withKoine(_a) {
4
- if (_a === void 0) { _a = {
5
- i18n: {
6
- locales: ["en"],
7
- defaultLocale: "en",
8
- hideDefaultLocaleInUrl: false,
9
- },
10
- }; }
11
- var _b = _a.nx, nx = _b === void 0 ? true : _b, _c = _a.svg, svg = _c === void 0 ? true : _c, page = _a.page, routes = _a.routes, permanent = _a.permanent, debug = _a.debug, custom = __rest(_a, ["nx", "svg", "page", "routes", "permanent", "debug"]);
12
- var nextConfig = __assign({ eslint: {
13
- ignoreDuringBuilds: true,
14
- }, typescript: {
15
- ignoreBuildErrors: true,
16
- }, poweredByHeader: false, modularizeImports: __assign({ "@koine/api": { transform: "@koine/api/{{member}}" }, "@koine/browser": { transform: "@koine/browser/{{member}}" }, "@koine/dom": { transform: "@koine/dom/{{member}}" }, "@koine/i18n": { transform: "@koine/i18n/{{member}}" }, "@koine/next/?(((\\w*)?/?)*)": {
17
- transform: "@koine/next/{{ matches.[1] }}/{{member}}",
18
- }, "@koine/node": { transform: "@koine/node/{{member}}" }, "@koine/react/?(((\\w*)?/?)*)": {
19
- transform: "@koine/react/{{ matches.[1] }}/{{member}}",
20
- }, "@koine/utils": { transform: "@koine/utils/{{member}}" } }, (custom["modularizeImports"] || {})), experimental: __assign({ scrollRestoration: true }, (custom["experimental"] || {})) }, custom);
21
- if (svg) {
22
- if (nx) {
23
- nextConfig["nx"] = {
24
- svgr: true,
25
- };
26
- }
27
- else {
28
- delete nextConfig["nx"];
29
- nextConfig.webpack = function (_config, options) {
30
- var webpackConfig = typeof nextConfig.webpack === "function"
31
- ? nextConfig.webpack(_config, options)
32
- : _config;
33
- webpackConfig.module.rules.push({
34
- test: /\.svg$/,
35
- use: [
36
- {
37
- loader: "@svgr/webpack",
38
- options: {
39
- svgoConfig: {
40
- plugins: [
41
- {
42
- name: "removeViewBox",
43
- active: false,
44
- },
45
- ],
46
- },
47
- },
48
- },
49
- ],
50
- });
51
- return webpackConfig;
52
- };
53
- }
54
- }
55
- if (custom.i18n) {
56
- var _d = custom.i18n, locales = _d.locales, defaultLocale = _d.defaultLocale, localeParam = _d.localeParam;
57
- if (localeParam) {
58
- delete nextConfig.i18n;
59
- }
60
- else {
61
- nextConfig.i18n = { locales: locales, defaultLocale: defaultLocale };
62
- }
63
- }
64
- if (routes) {
65
- return __assign(__assign({}, nextConfig), { redirects: function () {
66
- return __awaiter(this, void 0, void 0, function () {
67
- var defaults, customs;
68
- return __generator(this, function (_a) {
69
- switch (_a.label) {
70
- case 0: return [4, getRedirects(__assign({ routes: routes, permanent: permanent, debug: debug }, custom.i18n))];
71
- case 1:
72
- defaults = _a.sent();
73
- if (!nextConfig.redirects) return [3, 3];
74
- return [4, nextConfig.redirects()];
75
- case 2:
76
- customs = _a.sent();
77
- return [2, __spreadArray(__spreadArray([], __read(defaults), false), __read(customs), false)];
78
- case 3: return [2, defaults];
79
- }
80
- });
81
- });
82
- }, rewrites: function () {
83
- return __awaiter(this, void 0, void 0, function () {
84
- var defaults, customs;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
87
- case 0: return [4, getRewrites(__assign({ routes: routes, debug: debug }, custom.i18n))];
88
- case 1:
89
- defaults = _a.sent();
90
- if (!nextConfig.rewrites) return [3, 3];
91
- return [4, nextConfig.rewrites()];
92
- case 2:
93
- customs = _a.sent();
94
- if (Array.isArray(customs)) {
95
- return [2, {
96
- beforeFiles: defaults,
97
- afterFiles: customs,
98
- fallback: [],
99
- }];
100
- }
101
- return [2, __assign(__assign({}, customs), { beforeFiles: __spreadArray(__spreadArray([], __read(defaults), false), __read((customs.beforeFiles || [])), false) })];
102
- case 3: return [2, {
103
- beforeFiles: defaults,
104
- afterFiles: [],
105
- fallback: [],
106
- }];
107
- }
108
- });
109
- });
110
- } });
111
- }
112
- return nextConfig;
113
- }
114
- export default withKoine;
package/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { load } from "./load.js";
2
- export { ThemeContext } from "./ThemeContext.js";
3
- export { ThemeProvider } from "./ThemeProvider.js";
4
- export { useTheme } from "./useTheme.js";
package/load.js DELETED
@@ -1,6 +0,0 @@
1
- export function load(component, milliseconds) {
2
- return new Promise(function (resolve) {
3
- setTimeout(function () { return resolve(component); }, milliseconds);
4
- });
5
- }
6
- export default load;
package/typings.d.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * Nx types
3
- *
4
- * Allow to embed SVGs as both URLs string and as React components
5
- */
6
- declare module "*.svg" {
7
- const content: unknown;
8
- export const ReactComponent: import("react").FC<
9
- import("react").ComponentProps<"svg">
10
- >;
11
- export default content;
12
- }
13
-
14
- /**
15
- * Types specifically related to `@koine/next` exposed on the global unique
16
- * namespace `Koine`. Most of the types here should be prefixed by `Next`, e.g.
17
- * `NextSomeFeature` accessible anywhere from `Koine.NextSomeFeature`
18
- */
19
- declare namespace Koine {
20
- /**
21
- * Default SEO data structure expected by the `<Seo>` component's prop `seo`
22
- */
23
- type NextSeo = import("./12/types-seo").SeoData;
24
- }
25
-
26
- /**
27
- * List here the global variables used by third party scripts supported within
28
- * the `koine` ecosystem. For instance Google Analytics globally available
29
- * variables.
30
- */
31
- declare interface Window {
32
- gtag: (...args: Record<string, unknown>[]) => Record<string, unknown>;
33
- }
package/useTheme.js DELETED
@@ -1,5 +0,0 @@
1
- "use client";
2
- import { useContext } from "react";
3
- import { ThemeContext } from "./ThemeContext.js";
4
- export var useTheme = function () { return useContext(ThemeContext); };
5
- export default useTheme;
File without changes