@koine/next 1.2.2 → 2.0.0-alpha.1

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 (169) hide show
  1. package/AnalyticsGoogle.js +1 -0
  2. package/AnalyticsGoogle.mjs +1 -0
  3. package/DynamicNamespaces.js +1 -0
  4. package/DynamicNamespaces.mjs +1 -0
  5. package/NextProgress.js +1 -0
  6. package/NextProgress.mjs +1 -0
  7. package/T.js +1 -0
  8. package/T.mjs +1 -0
  9. package/ThemeProvider.js +1 -0
  10. package/ThemeProvider.mjs +1 -0
  11. package/TransText.js +1 -0
  12. package/TransText.mjs +1 -0
  13. package/auth/useLoginUrl.js +1 -0
  14. package/auth/useLoginUrl.mjs +1 -0
  15. package/auth/useLogout.js +1 -0
  16. package/auth/useLogout.mjs +1 -0
  17. package/getT.js +2 -1
  18. package/getT.mjs +1 -0
  19. package/index.d.ts +2 -28
  20. package/index.js +5 -31
  21. package/index.mjs +2 -30
  22. package/legacy/AnalyticsGoogle.d.ts +6 -0
  23. package/legacy/AnalyticsGoogle.js +39 -0
  24. package/legacy/AnalyticsGoogle.mjs +35 -0
  25. package/legacy/DisableErrorOverlay.d.ts +7 -0
  26. package/legacy/DisableErrorOverlay.js +18 -0
  27. package/legacy/DisableErrorOverlay.mjs +13 -0
  28. package/legacy/DynamicNamespaces.d.ts +13 -0
  29. package/legacy/DynamicNamespaces.js +13 -0
  30. package/legacy/DynamicNamespaces.mjs +9 -0
  31. package/legacy/Favicon.d.ts +4 -0
  32. package/legacy/Favicon.js +10 -0
  33. package/legacy/Favicon.mjs +6 -0
  34. package/legacy/Link.d.ts +10 -0
  35. package/legacy/Link.js +15 -0
  36. package/legacy/Link.mjs +12 -0
  37. package/legacy/NextProgress.d.ts +25 -0
  38. package/legacy/NextProgress.js +46 -0
  39. package/legacy/NextProgress.mjs +42 -0
  40. package/legacy/Seo.d.ts +41 -0
  41. package/legacy/Seo.js +34 -0
  42. package/legacy/Seo.mjs +29 -0
  43. package/legacy/SeoDefaults.d.ts +11 -0
  44. package/legacy/SeoDefaults.js +17 -0
  45. package/legacy/SeoDefaults.mjs +12 -0
  46. package/legacy/T.d.ts +15 -0
  47. package/legacy/T.js +17 -0
  48. package/legacy/T.mjs +13 -0
  49. package/legacy/ThemeContext.d.ts +17 -0
  50. package/legacy/ThemeContext.js +10 -0
  51. package/legacy/ThemeContext.mjs +7 -0
  52. package/legacy/ThemeProvider.d.ts +35 -0
  53. package/legacy/ThemeProvider.js +251 -0
  54. package/legacy/ThemeProvider.mjs +247 -0
  55. package/legacy/TransText.d.ts +3 -0
  56. package/legacy/TransText.js +8 -0
  57. package/legacy/TransText.mjs +4 -0
  58. package/legacy/app/AppHead.d.ts +3 -0
  59. package/legacy/app/AppHead.js +11 -0
  60. package/legacy/app/AppHead.mjs +6 -0
  61. package/legacy/app/AppMain.d.ts +35 -0
  62. package/legacy/app/AppMain.js +2 -0
  63. package/legacy/app/AppMain.mjs +1 -0
  64. package/legacy/app/css/AppMain.d.ts +9 -0
  65. package/legacy/app/css/AppMain.js +18 -0
  66. package/legacy/app/css/AppMain.mjs +14 -0
  67. package/legacy/app/css/AppTheme.d.ts +11 -0
  68. package/legacy/app/css/AppTheme.js +19 -0
  69. package/legacy/app/css/AppTheme.mjs +15 -0
  70. package/legacy/app/css/auth/index.d.ts +11 -0
  71. package/legacy/app/css/auth/index.js +17 -0
  72. package/legacy/app/css/auth/index.mjs +13 -0
  73. package/legacy/app/css/auth/package.json +6 -0
  74. package/legacy/app/css/index.d.ts +54 -0
  75. package/legacy/app/css/index.js +61 -0
  76. package/legacy/app/css/index.mjs +57 -0
  77. package/legacy/app/css/package.json +6 -0
  78. package/legacy/app/index.d.ts +2 -0
  79. package/legacy/app/index.js +5 -0
  80. package/legacy/app/index.mjs +2 -0
  81. package/legacy/app/package.json +6 -0
  82. package/legacy/app/sc/AppMain.d.ts +11 -0
  83. package/legacy/app/sc/AppMain.js +29 -0
  84. package/legacy/app/sc/AppMain.mjs +25 -0
  85. package/legacy/app/sc/AppTheme.d.ts +14 -0
  86. package/legacy/app/sc/AppTheme.js +16 -0
  87. package/legacy/app/sc/AppTheme.mjs +12 -0
  88. package/legacy/app/sc/auth/index.d.ts +11 -0
  89. package/legacy/app/sc/auth/index.js +17 -0
  90. package/legacy/app/sc/auth/index.mjs +13 -0
  91. package/legacy/app/sc/auth/package.json +6 -0
  92. package/legacy/app/sc/index.d.ts +56 -0
  93. package/legacy/app/sc/index.js +63 -0
  94. package/legacy/app/sc/index.mjs +59 -0
  95. package/legacy/app/sc/package.json +6 -0
  96. package/legacy/document/Document.d.ts +16 -0
  97. package/legacy/document/Document.js +31 -0
  98. package/legacy/document/Document.mjs +28 -0
  99. package/legacy/document/css/index.d.ts +18 -0
  100. package/legacy/document/css/index.js +45 -0
  101. package/legacy/document/css/index.mjs +45 -0
  102. package/legacy/document/css/package.json +6 -0
  103. package/legacy/document/index.d.ts +2 -0
  104. package/legacy/document/index.js +7 -0
  105. package/legacy/document/index.mjs +2 -0
  106. package/legacy/document/package.json +6 -0
  107. package/legacy/document/sc/index.d.ts +20 -0
  108. package/legacy/document/sc/index.js +67 -0
  109. package/legacy/document/sc/index.mjs +64 -0
  110. package/legacy/document/sc/package.json +6 -0
  111. package/legacy/getT.d.ts +9 -0
  112. package/legacy/getT.js +14 -0
  113. package/legacy/getT.mjs +10 -0
  114. package/legacy/index.d.ts +24 -0
  115. package/legacy/index.js +52 -0
  116. package/legacy/index.mjs +27 -0
  117. package/legacy/package.json +6 -0
  118. package/legacy/seoBuildTags.d.ts +23 -0
  119. package/legacy/seoBuildTags.js +121 -0
  120. package/legacy/seoBuildTags.mjs +117 -0
  121. package/legacy/to.d.ts +24 -0
  122. package/legacy/to.js +29 -0
  123. package/legacy/to.mjs +25 -0
  124. package/legacy/translationAsOptions.d.ts +3 -0
  125. package/legacy/translationAsOptions.js +13 -0
  126. package/legacy/translationAsOptions.mjs +9 -0
  127. package/legacy/types-i18n.d.ts +118 -0
  128. package/legacy/types-i18n.js +14 -0
  129. package/legacy/types-i18n.mjs +13 -0
  130. package/legacy/types-seo.d.ts +7 -0
  131. package/legacy/types-seo.js +2 -0
  132. package/legacy/types-seo.mjs +1 -0
  133. package/legacy/useBackUrl.d.ts +2 -0
  134. package/legacy/useBackUrl.js +33 -0
  135. package/legacy/useBackUrl.mjs +28 -0
  136. package/legacy/useDateFormat.d.ts +7 -0
  137. package/legacy/useDateFormat.js +43 -0
  138. package/legacy/useDateFormat.mjs +39 -0
  139. package/legacy/useForm.d.ts +27 -0
  140. package/legacy/useForm.js +39 -0
  141. package/legacy/useForm.mjs +35 -0
  142. package/legacy/useLocale.d.ts +2 -0
  143. package/legacy/useLocale.js +11 -0
  144. package/legacy/useLocale.mjs +6 -0
  145. package/legacy/useT.d.ts +17 -0
  146. package/legacy/useT.js +40 -0
  147. package/legacy/useT.mjs +19 -0
  148. package/legacy/useTheme.d.ts +7 -0
  149. package/legacy/useTheme.js +12 -0
  150. package/legacy/useTheme.mjs +8 -0
  151. package/legacy/useTo.d.ts +3 -0
  152. package/legacy/useTo.js +19 -0
  153. package/legacy/useTo.mjs +15 -0
  154. package/package.json +4 -10
  155. package/typings.d.ts +0 -87
  156. package/useBackUrl.js +1 -0
  157. package/useBackUrl.mjs +1 -0
  158. package/useDateFormat.js +1 -0
  159. package/useDateFormat.mjs +1 -0
  160. package/useForm.js +1 -0
  161. package/useForm.mjs +1 -0
  162. package/useLocale.js +1 -0
  163. package/useLocale.mjs +1 -0
  164. package/useT.js +1 -0
  165. package/useT.mjs +1 -16
  166. package/useTheme.js +1 -0
  167. package/useTheme.mjs +1 -0
  168. package/useTo.js +1 -0
  169. package/useTo.mjs +1 -0
package/legacy/Seo.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Seo = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ // import { memo } from "react";
7
+ var head_1 = tslib_1.__importDefault(require("next/head"));
8
+ var seoBuildTags_1 = require("./seoBuildTags");
9
+ /**
10
+ * Adapted from [garmeeh/next-seo](https://github.com/garmeeh/next-seo)
11
+ *
12
+ * See also:
13
+ * - https://github.com/catnose99/next-head-seo
14
+ * - https://nextjs.org/docs/api-reference/next/head
15
+ *
16
+ * NB: on the homepage you usually want to customize the `titleTemplate` to avoid
17
+ * doubled app name. Assuming your default seo configuration is something like:
18
+ *
19
+ * ```js
20
+ * {
21
+ * titleTemplate: "%s | MyApp"
22
+ * }
23
+ * ```
24
+ *
25
+ * On the homepage you migh want to override it, e.g.:
26
+ * ```js
27
+ * <Seo title="MyApp | Some description" titleTemplate="%s" />
28
+ * ```
29
+ */
30
+ var Seo = function (props) {
31
+ return (0, jsx_runtime_1.jsx)(head_1.default, { children: (0, seoBuildTags_1.seoBuildTags)(props) });
32
+ };
33
+ exports.Seo = Seo;
34
+ exports.default = exports.Seo;
package/legacy/Seo.mjs ADDED
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // import { memo } from "react";
3
+ import Head from "next/head";
4
+ import { seoBuildTags } from "./seoBuildTags";
5
+ /**
6
+ * Adapted from [garmeeh/next-seo](https://github.com/garmeeh/next-seo)
7
+ *
8
+ * See also:
9
+ * - https://github.com/catnose99/next-head-seo
10
+ * - https://nextjs.org/docs/api-reference/next/head
11
+ *
12
+ * NB: on the homepage you usually want to customize the `titleTemplate` to avoid
13
+ * doubled app name. Assuming your default seo configuration is something like:
14
+ *
15
+ * ```js
16
+ * {
17
+ * titleTemplate: "%s | MyApp"
18
+ * }
19
+ * ```
20
+ *
21
+ * On the homepage you migh want to override it, e.g.:
22
+ * ```js
23
+ * <Seo title="MyApp | Some description" titleTemplate="%s" />
24
+ * ```
25
+ */
26
+ export var Seo = function (props) {
27
+ return _jsx(Head, { children: seoBuildTags(props) });
28
+ };
29
+ export default Seo;
@@ -0,0 +1,11 @@
1
+ import type { DefaultSeoProps } from "next-seo/lib/types";
2
+ import { type MetaTag, type LinkTag } from "./seoBuildTags";
3
+ /**
4
+ * @see https://github.com/garmeeh/next-seo/blob/master/src/types.ts#L413
5
+ */
6
+ export type SeoDefaultsProps = Omit<DefaultSeoProps, "additionalMetaTags" | "additionalLinkTags" | "dangerouslySetAllPagesToNoIndex" | "dangerouslySetAllPagesToNoFollow" | "defaultOpenGraphImageWidth" | "defaultOpenGraphImageHeight" | "defaultOpenGraphVideoWidth" | "defaultOpenGraphVideoHeight" | "mobileAlternate" | "robotsProps"> & {
7
+ metaTags?: ReadonlyArray<MetaTag>;
8
+ linkTags?: ReadonlyArray<LinkTag>;
9
+ };
10
+ export declare const SeoDefaults: (props: SeoDefaultsProps) => JSX.Element;
11
+ export default SeoDefaults;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SeoDefaults = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var jsx_runtime_1 = require("react/jsx-runtime");
6
+ // import { memo } from "react";
7
+ var head_1 = tslib_1.__importDefault(require("next/head"));
8
+ // import { useRouter } from "next/router";
9
+ // import { getSiteUrl } from "../utils";
10
+ var seoBuildTags_1 = require("./seoBuildTags");
11
+ var SeoDefaults = function (props) {
12
+ // const router = useRouter();
13
+ // props.openGraph.url = getSiteUrl(router.asPath);
14
+ return (0, jsx_runtime_1.jsx)(head_1.default, { children: (0, seoBuildTags_1.seoBuildTags)(props) });
15
+ };
16
+ exports.SeoDefaults = SeoDefaults;
17
+ exports.default = exports.SeoDefaults;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // import { memo } from "react";
3
+ import Head from "next/head";
4
+ // import { useRouter } from "next/router";
5
+ // import { getSiteUrl } from "../utils";
6
+ import { seoBuildTags } from "./seoBuildTags";
7
+ export var SeoDefaults = function (props) {
8
+ // const router = useRouter();
9
+ // props.openGraph.url = getSiteUrl(router.asPath);
10
+ return _jsx(Head, { children: seoBuildTags(props) });
11
+ };
12
+ export default SeoDefaults;
package/legacy/T.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { TransProps } from "next-translate";
2
+ import type { TranslateNamespace, TranslationsPaths, TranslationsAllPaths } from "./types-i18n";
3
+ export type TProps<TNamespace extends TranslateNamespace | undefined = undefined> = (Omit<TransProps, "i18nKey" | "ns"> & {
4
+ i18nKey: TranslationsAllPaths;
5
+ }) | (Omit<TransProps, "i18nKey" | "ns"> & {
6
+ ns: TNamespace;
7
+ i18nKey: TranslationsPaths<TNamespace>;
8
+ });
9
+ /**
10
+ * **NOTE**: To make typescript work nicely here make sure to enable
11
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
12
+ * in your `tsconfig.json` file.
13
+ */
14
+ export declare const T: <TNamespace extends "~" | undefined = undefined>(props: TProps<TNamespace>) => import("react").ReactElement<TProps<TNamespace>, string | import("react").JSXElementConstructor<any>>;
15
+ export default T;
package/legacy/T.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.T = void 0;
5
+ var tslib_1 = require("tslib");
6
+ var jsx_runtime_1 = require("react/jsx-runtime");
7
+ var Trans_1 = tslib_1.__importDefault(require("next-translate/Trans"));
8
+ /**
9
+ * **NOTE**: To make typescript work nicely here make sure to enable
10
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
11
+ * in your `tsconfig.json` file.
12
+ */
13
+ var T = function (props) {
14
+ return ((0, jsx_runtime_1.jsx)(Trans_1.default, tslib_1.__assign({}, props)));
15
+ };
16
+ exports.T = T;
17
+ exports.default = exports.T;
package/legacy/T.mjs ADDED
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import { __assign } from "tslib";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import Trans from "next-translate/Trans";
5
+ /**
6
+ * **NOTE**: To make typescript work nicely here make sure to enable
7
+ * [`resolveJsonModule`](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
8
+ * in your `tsconfig.json` file.
9
+ */
10
+ export var T = function (props) {
11
+ return (_jsx(Trans, __assign({}, props)));
12
+ };
13
+ export default T;
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ export type ThemeContextProps = {
3
+ /** List of all available theme names */
4
+ themes: string[];
5
+ /** Forced theme name for the current page */
6
+ forcedTheme?: string;
7
+ /** Update the theme */
8
+ setTheme: (theme: string) => void;
9
+ /** Active theme name */
10
+ theme?: string;
11
+ /** If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme` */
12
+ resolvedTheme?: string;
13
+ /** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */
14
+ systemTheme?: "dark" | "light";
15
+ };
16
+ export declare const ThemeContext: import("react").Context<ThemeContextProps>;
17
+ export default ThemeContext;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThemeContext = void 0;
4
+ var react_1 = require("react");
5
+ exports.ThemeContext = (0, react_1.createContext)({
6
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
7
+ setTheme: function (_) { },
8
+ themes: [],
9
+ });
10
+ exports.default = exports.ThemeContext;
@@ -0,0 +1,7 @@
1
+ import { createContext } from "react";
2
+ export var ThemeContext = createContext({
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
4
+ setTheme: function (_) { },
5
+ themes: [],
6
+ });
7
+ export default ThemeContext;
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ type ValueObject = {
3
+ [themeName: string]: string;
4
+ };
5
+ export type ThemeProviderProps = React.PropsWithChildren<{
6
+ /** List of all available theme names */
7
+ themes?: string[];
8
+ /** Forced theme name for the current page */
9
+ forcedTheme?: string;
10
+ /** Whether to switch between dark and light themes based on prefers-color-scheme */
11
+ enableSystem?: boolean;
12
+ /** Disable all CSS transitions when switching themes */
13
+ disableTransitionOnChange?: boolean;
14
+ /** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */
15
+ enableColorScheme?: boolean;
16
+ /** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */
17
+ defaultTheme?: string;
18
+ /** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */
19
+ attribute?: string | "class";
20
+ /** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */
21
+ value?: ValueObject;
22
+ /** Nonce string to pass to the inline script for CSP headers */
23
+ nonce?: string;
24
+ }>;
25
+ /**
26
+ * @borrows [next-themes](https://github.com/pacocoursey/next-themes)
27
+ *
28
+ * Differences:
29
+ *
30
+ * - enableColorScheme: `false` by default (instead of `true`), this plays more
31
+ * nicely with tailwind `dark` class mode as dark theme is supposed to be only
32
+ * controlled by tailwind modifiers
33
+ */
34
+ export declare const ThemeProvider: ({ forcedTheme, disableTransitionOnChange, enableSystem, enableColorScheme, themes, defaultTheme, attribute, value, children, nonce, }: ThemeProviderProps) => JSX.Element;
35
+ export default ThemeProvider;
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ThemeProvider = void 0;
5
+ var tslib_1 = require("tslib");
6
+ var jsx_runtime_1 = require("react/jsx-runtime");
7
+ var react_1 = require("react");
8
+ var script_1 = tslib_1.__importDefault(require("next/script"));
9
+ var isServer_1 = tslib_1.__importDefault(require("@koine/utils/isServer"));
10
+ var ThemeContext_1 = require("./ThemeContext");
11
+ var colorSchemes = ["light", "dark"];
12
+ var MEDIA = "(prefers-color-scheme: dark)";
13
+ var THEME_STORAGE_KEY = "theme";
14
+ /**
15
+ * @borrows [next-themes](https://github.com/pacocoursey/next-themes)
16
+ *
17
+ * Differences:
18
+ *
19
+ * - enableColorScheme: `false` by default (instead of `true`), this plays more
20
+ * nicely with tailwind `dark` class mode as dark theme is supposed to be only
21
+ * controlled by tailwind modifiers
22
+ */
23
+ var ThemeProvider = function (_a) {
24
+ 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;
25
+ var _g = (0, react_1.useState)(function () {
26
+ return getTheme(THEME_STORAGE_KEY, defaultTheme);
27
+ }), theme = _g[0], setThemeState = _g[1];
28
+ var _h = (0, react_1.useState)(function () {
29
+ return getTheme(THEME_STORAGE_KEY);
30
+ }), resolvedTheme = _h[0], setResolvedTheme = _h[1];
31
+ var attrs = !value ? themes : Object.values(value);
32
+ var applyTheme = (0, react_1.useCallback)(function (theme) {
33
+ var _a;
34
+ var resolved = theme;
35
+ if (isServer_1.default || !resolved)
36
+ return;
37
+ // If theme is system, resolve it before setting theme
38
+ if (theme === "system" && enableSystem) {
39
+ resolved = getSystemTheme();
40
+ }
41
+ var name = value ? value[resolved] : resolved;
42
+ var enable = disableTransitionOnChange ? disableAnimation() : null;
43
+ var d = document.documentElement;
44
+ if (attribute === "class") {
45
+ (_a = d.classList).remove.apply(_a, attrs);
46
+ if (name)
47
+ d.classList.add(name);
48
+ }
49
+ else {
50
+ if (name) {
51
+ d.setAttribute(attribute, name);
52
+ }
53
+ else {
54
+ d.removeAttribute(attribute);
55
+ }
56
+ }
57
+ if (enableColorScheme) {
58
+ var fallback = colorSchemes.includes(defaultTheme)
59
+ ? defaultTheme
60
+ : "";
61
+ var colorScheme = colorSchemes.includes(resolved)
62
+ ? resolved
63
+ : fallback;
64
+ d.style.colorScheme = colorScheme;
65
+ }
66
+ enable === null || enable === void 0 ? void 0 : enable();
67
+ }, [
68
+ attribute,
69
+ attrs,
70
+ defaultTheme,
71
+ disableTransitionOnChange,
72
+ enableColorScheme,
73
+ enableSystem,
74
+ value,
75
+ ]);
76
+ var setTheme = (0, react_1.useCallback)(function (theme) {
77
+ setThemeState(theme);
78
+ // Save to storage
79
+ try {
80
+ localStorage.setItem(THEME_STORAGE_KEY, theme);
81
+ }
82
+ catch (e) {
83
+ // Unsupported
84
+ }
85
+ }, []);
86
+ var handleMediaQuery = (0, react_1.useCallback)(function (e) {
87
+ var resolved = getSystemTheme(e);
88
+ setResolvedTheme(resolved);
89
+ if (theme === "system" && enableSystem && !forcedTheme) {
90
+ applyTheme("system");
91
+ }
92
+ }, [theme, enableSystem, forcedTheme, applyTheme]);
93
+ // Always listen to System preference
94
+ (0, react_1.useEffect)(function () {
95
+ var media = window.matchMedia(MEDIA);
96
+ // Intentionally use deprecated listener methods to support iOS & old browsers
97
+ media.addListener(handleMediaQuery);
98
+ handleMediaQuery(media);
99
+ return function () { return media.removeListener(handleMediaQuery); };
100
+ }, [handleMediaQuery]);
101
+ // localStorage event handling
102
+ (0, react_1.useEffect)(function () {
103
+ var handleStorage = function (e) {
104
+ if (e.key !== THEME_STORAGE_KEY) {
105
+ return;
106
+ }
107
+ // If default theme set, use it if localstorage === null (happens on local storage manual deletion)
108
+ var theme = e.newValue || defaultTheme;
109
+ setTheme(theme);
110
+ };
111
+ window.addEventListener("storage", handleStorage);
112
+ return function () { return window.removeEventListener("storage", handleStorage); };
113
+ }, [defaultTheme, setTheme]);
114
+ // Whenever theme or forcedTheme changes, apply it
115
+ (0, react_1.useEffect)(function () {
116
+ applyTheme(forcedTheme !== null && forcedTheme !== void 0 ? forcedTheme : theme);
117
+ }, [applyTheme, forcedTheme, theme]);
118
+ return ((0, jsx_runtime_1.jsxs)(ThemeContext_1.ThemeContext.Provider, tslib_1.__assign({ value: {
119
+ theme: theme,
120
+ setTheme: setTheme,
121
+ forcedTheme: forcedTheme,
122
+ resolvedTheme: theme === "system" ? resolvedTheme : theme,
123
+ themes: enableSystem ? tslib_1.__spreadArray(tslib_1.__spreadArray([], themes, true), ["system"], false) : themes,
124
+ systemTheme: (enableSystem ? resolvedTheme : undefined),
125
+ } }, { children: [(0, jsx_runtime_1.jsx)(ThemeScript, tslib_1.__assign({}, {
126
+ forcedTheme: forcedTheme,
127
+ disableTransitionOnChange: disableTransitionOnChange,
128
+ enableSystem: enableSystem,
129
+ enableColorScheme: enableColorScheme,
130
+ themes: themes,
131
+ defaultTheme: defaultTheme,
132
+ attribute: attribute,
133
+ value: value,
134
+ children: children,
135
+ attrs: attrs,
136
+ nonce: nonce,
137
+ })), children] })));
138
+ };
139
+ exports.ThemeProvider = ThemeProvider;
140
+ var ThemeScript = (0, react_1.memo)(function (_a) {
141
+ 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;
142
+ var defaultSystem = defaultTheme === "system";
143
+ // Code-golfing the amount of characters in the script
144
+ var optimization = (function () {
145
+ var removeClasses = "d.remove(".concat(attrs
146
+ .map(function (t) { return "'".concat(t, "'"); })
147
+ .join(","), ")");
148
+ return "var d=document.documentElement.classList;".concat(removeClasses, ";");
149
+ })();
150
+ var fallbackColorScheme = (function () {
151
+ if (!enableColorScheme) {
152
+ return "";
153
+ }
154
+ var fallback = colorSchemes.includes(defaultTheme)
155
+ ? defaultTheme
156
+ : null;
157
+ if (fallback) {
158
+ return "if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'".concat(defaultTheme, "'");
159
+ }
160
+ else {
161
+ return "if(e==='light'||e==='dark')d.style.colorScheme=e";
162
+ }
163
+ })();
164
+ var updateDOM = function (name, literal, setColorScheme) {
165
+ if (literal === void 0) { literal = false; }
166
+ if (setColorScheme === void 0) { setColorScheme = true; }
167
+ var resolvedName = value ? value[name] : name;
168
+ var val = literal ? name + "|| ''" : "'".concat(resolvedName, "'");
169
+ var text = "";
170
+ // MUCH faster to set colorScheme alongside HTML attribute/class
171
+ // as it only incurs 1 style recalculation rather than 2
172
+ // This can save over 250ms of work for pages with big DOM
173
+ if (enableColorScheme &&
174
+ setColorScheme &&
175
+ !literal &&
176
+ colorSchemes.includes(name)) {
177
+ text += "d.style.colorScheme = '".concat(name, "';");
178
+ }
179
+ if (attribute === "class") {
180
+ if (literal || resolvedName) {
181
+ text += "d.add(".concat(val, ")");
182
+ }
183
+ else {
184
+ text += "null";
185
+ }
186
+ }
187
+ else {
188
+ if (resolvedName) {
189
+ text += "d[s](n, ".concat(val, ")");
190
+ }
191
+ }
192
+ return text;
193
+ };
194
+ var scriptSrc = (function () {
195
+ if (forcedTheme) {
196
+ return "!function(){".concat(optimization).concat(updateDOM(forcedTheme), "}()");
197
+ }
198
+ if (enableSystem) {
199
+ 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
200
+ ? "else{" + updateDOM(defaultTheme, false, false) + "}"
201
+ : "").concat(fallbackColorScheme, "}catch(e){}}()");
202
+ }
203
+ 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){}}();");
204
+ })();
205
+ // We MUST use next/script's `beforeInteractive` strategy to avoid flashing on load.
206
+ // However, it only accepts the `src` prop, not `dangerouslySetInnerHTML` or `children`
207
+ // But our script cannot be external because it changes at runtime based on React props
208
+ // so we trick next/script by passing `src` as a base64 JS script
209
+ var encodedScript = "data:text/javascript;base64,".concat(encodeBase64(scriptSrc));
210
+ return ((0, jsx_runtime_1.jsx)(script_1.default, { id: "next-theme-script", strategy: "beforeInteractive", src: encodedScript, nonce: nonce }));
211
+ },
212
+ // Never re-render this component
213
+ function () { return true; });
214
+ // Helpers
215
+ var getTheme = function (key, fallback) {
216
+ if (isServer_1.default)
217
+ return undefined;
218
+ var theme;
219
+ try {
220
+ theme = localStorage.getItem(key) || undefined;
221
+ }
222
+ catch (e) {
223
+ // Unsupported
224
+ }
225
+ return theme || fallback;
226
+ };
227
+ var disableAnimation = function () {
228
+ var d = document;
229
+ var css = d.createElement("style");
230
+ css.appendChild(d.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}"));
231
+ d.head.appendChild(css);
232
+ return function () {
233
+ // Force restyle
234
+ (function () { return window.getComputedStyle(d.body); })();
235
+ // Wait for next tick before removing
236
+ setTimeout(function () {
237
+ d.head.removeChild(css);
238
+ }, 1);
239
+ };
240
+ };
241
+ var getSystemTheme = function (e) {
242
+ if (!e)
243
+ e = window.matchMedia(MEDIA);
244
+ var isDark = e.matches;
245
+ var systemTheme = isDark ? "dark" : "light";
246
+ return systemTheme;
247
+ };
248
+ var encodeBase64 = function (str) {
249
+ return isServer_1.default ? Buffer.from(str).toString("base64") : btoa(str);
250
+ };
251
+ exports.default = exports.ThemeProvider;