@koine/next 2.0.0-beta.20 → 2.0.0-beta.201

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 (131) hide show
  1. package/12/AnalyticsGoogle.cjs.js +20 -0
  2. package/12/AnalyticsGoogle.d.ts +2 -1
  3. package/12/AnalyticsGoogle.esm.js +15 -0
  4. package/12/DisableErrorOverlay.cjs.js +11 -0
  5. package/12/DisableErrorOverlay.d.ts +6 -1
  6. package/12/DisableErrorOverlay.esm.js +6 -0
  7. package/12/Seo.d.ts +35 -3
  8. package/12/SeoDefaults.d.ts +10 -2
  9. package/12/seoBuildTags.d.ts +18 -4
  10. package/12/types.d.ts +5 -7
  11. package/12.cjs.default.js +1 -0
  12. package/12.cjs.js +9 -0
  13. package/12.cjs.mjs +2 -0
  14. package/12.d.ts +3 -0
  15. package/12.esm.js +2 -0
  16. package/README.md +1 -0
  17. package/ThemeContext.cjs.default.js +1 -0
  18. package/ThemeContext.cjs.js +10 -0
  19. package/ThemeContext.cjs.mjs +2 -0
  20. package/ThemeContext.d.ts +6 -1
  21. package/ThemeContext.esm.js +5 -0
  22. package/ThemeProvider.cjs.default.js +1 -0
  23. package/ThemeProvider.cjs.js +14 -0
  24. package/ThemeProvider.cjs.mjs +2 -0
  25. package/ThemeProvider.d.ts +18 -1
  26. package/ThemeProvider.esm.js +9 -0
  27. package/config.cjs.default.js +1 -0
  28. package/config.cjs.js +8 -0
  29. package/config.cjs.mjs +2 -0
  30. package/config.d.ts +30 -106
  31. package/config.esm.js +6 -0
  32. package/index.cjs.default.js +1 -0
  33. package/index.cjs.js +13 -0
  34. package/index.cjs.mjs +2 -0
  35. package/index.d.ts +4 -5
  36. package/index.esm.js +4 -0
  37. package/load.cjs.default.js +1 -0
  38. package/load.cjs.js +8 -0
  39. package/load.cjs.mjs +2 -0
  40. package/load.d.ts +8 -0
  41. package/load.esm.js +3 -0
  42. package/package.json +54 -204
  43. package/typings.d.ts +39 -50
  44. package/useTheme.cjs.default.js +1 -0
  45. package/useTheme.cjs.js +11 -0
  46. package/useTheme.cjs.mjs +2 -0
  47. package/useTheme.d.ts +4 -1
  48. package/useTheme.esm.js +6 -0
  49. package/vite.config.d.ts +2 -0
  50. package/12/AnalyticsGoogle.js +0 -33
  51. package/12/DisableErrorOverlay.js +0 -8
  52. package/12/DynamicNamespaces.d.ts +0 -8
  53. package/12/DynamicNamespaces.js +0 -4
  54. package/12/Favicon.d.ts +0 -4
  55. package/12/Favicon.js +0 -6
  56. package/12/Link.d.ts +0 -7
  57. package/12/Link.js +0 -9
  58. package/12/NextProgress.d.ts +0 -22
  59. package/12/NextProgress.js +0 -40
  60. package/12/Seo.js +0 -7
  61. package/12/SeoDefaults.js +0 -7
  62. package/12/T.d.ts +0 -10
  63. package/12/T.js +0 -8
  64. package/12/TransText.d.ts +0 -3
  65. package/12/TransText.js +0 -4
  66. package/12/app/AppHead.d.ts +0 -3
  67. package/12/app/AppHead.js +0 -6
  68. package/12/app/AppMain.d.ts +0 -17
  69. package/12/app/AppMain.js +0 -1
  70. package/12/app/css/AppMain.d.ts +0 -4
  71. package/12/app/css/AppMain.js +0 -9
  72. package/12/app/css/AppTheme.d.ts +0 -8
  73. package/12/app/css/AppTheme.js +0 -7
  74. package/12/app/css/auth/index.d.ts +0 -8
  75. package/12/app/css/auth/index.js +0 -10
  76. package/12/app/css/index.d.ts +0 -6
  77. package/12/app/css/index.js +0 -9
  78. package/12/app/index.d.ts +0 -2
  79. package/12/app/index.js +0 -2
  80. package/12/app/sc/AppMain.d.ts +0 -4
  81. package/12/app/sc/AppMain.js +0 -18
  82. package/12/app/sc/AppTheme.d.ts +0 -8
  83. package/12/app/sc/AppTheme.js +0 -8
  84. package/12/app/sc/auth/index.d.ts +0 -8
  85. package/12/app/sc/auth/index.js +0 -10
  86. package/12/app/sc/index.d.ts +0 -6
  87. package/12/app/sc/index.js +0 -9
  88. package/12/document/Document.d.ts +0 -5
  89. package/12/document/Document.js +0 -18
  90. package/12/document/css/index.d.ts +0 -5
  91. package/12/document/css/index.js +0 -18
  92. package/12/document/index.d.ts +0 -2
  93. package/12/document/index.js +0 -2
  94. package/12/document/sc/index.d.ts +0 -6
  95. package/12/document/sc/index.js +0 -50
  96. package/12/getT.d.ts +0 -4
  97. package/12/getT.js +0 -4
  98. package/12/index.d.ts +0 -3
  99. package/12/index.js +0 -3
  100. package/12/seoBuildTags.js +0 -93
  101. package/12/to.d.ts +0 -14
  102. package/12/to.js +0 -19
  103. package/12/translationAsOptions.d.ts +0 -4
  104. package/12/translationAsOptions.js +0 -10
  105. package/12/types-i18n.d.ts +0 -31
  106. package/12/types-i18n.js +0 -1
  107. package/12/types-seo.d.ts +0 -7
  108. package/12/types-seo.js +0 -1
  109. package/12/types.js +0 -2
  110. package/12/useBackUrl.d.ts +0 -2
  111. package/12/useBackUrl.js +0 -24
  112. package/12/useDateFormat.d.ts +0 -3
  113. package/12/useDateFormat.js +0 -35
  114. package/12/useForm.d.ts +0 -27
  115. package/12/useForm.js +0 -15
  116. package/12/useLocale.d.ts +0 -2
  117. package/12/useLocale.js +0 -6
  118. package/12/useT.d.ts +0 -4
  119. package/12/useT.js +0 -17
  120. package/12/useTo.d.ts +0 -3
  121. package/12/useTo.js +0 -15
  122. package/ThemeContext.js +0 -6
  123. package/ThemeProvider.js +0 -204
  124. package/config-i18n.d.ts +0 -52
  125. package/config-i18n.js +0 -251
  126. package/config.js +0 -118
  127. package/getSiteUrl.d.ts +0 -2
  128. package/getSiteUrl.js +0 -6
  129. package/index.js +0 -5
  130. package/load.js +0 -6
  131. package/useTheme.js +0 -5
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var router = require('next/router');
7
+ var o = require('next/script');
8
+ var react = require('react');
9
+ var browser = require('@koine/browser');
10
+
11
+ let AnalyticsGoogle=({id:s})=>{let l=s||process.env.NEXT_PUBLIC_GTM_ID,{events:m,asPath:c,query:d}=router.useRouter(),[p,f]=react.useState(false),[w,u]=react.useState(false);return (react.useEffect(()=>{let e=()=>{u(true);};return m.on("routeChangeComplete",e),()=>{m.off("routeChangeComplete",e);}},[m]),react.useEffect(()=>{w&&p&&c&&browser.gtagPageview(c);},[c,d,w,p]),l)?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(o,{id:"google-tagmanager",src:`https://www.googletagmanager.com/gtag/js?id=${s}`,strategy:"afterInteractive",onLoad:()=>f(true)}),jsxRuntime.jsx(o,{id:"google-analytics",strategy:"afterInteractive",children:`
12
+ window.dataLayer = window.dataLayer || [];
13
+ function gtag(){window.dataLayer.push(arguments);}
14
+ gtag('js', new Date());
15
+
16
+ gtag('config', '${s}', { 'send_page_view': false });
17
+ `})]}):null};
18
+
19
+ exports.AnalyticsGoogle = AnalyticsGoogle;
20
+ exports.default = AnalyticsGoogle;
@@ -1,5 +1,6 @@
1
1
  export type AnalyticsGoogleProps = {
2
+ /** Falls back to `.env` variable `NEXT_PUBLIC_GTM_ID` */
2
3
  id?: string;
3
4
  };
4
- export declare const AnalyticsGoogle: ({ id }: AnalyticsGoogleProps) => import("react/jsx-runtime").JSX.Element | null;
5
+ export declare let AnalyticsGoogle: ({ id }: AnalyticsGoogleProps) => import("react/jsx-runtime").JSX.Element | null;
5
6
  export default AnalyticsGoogle;
@@ -0,0 +1,15 @@
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
+ import { useRouter } from 'next/router';
3
+ import o from 'next/script';
4
+ import { useState, useEffect } from 'react';
5
+ import { gtagPageview } from '@koine/browser';
6
+
7
+ let AnalyticsGoogle=({id:s})=>{let l=s||process.env.NEXT_PUBLIC_GTM_ID,{events:m,asPath:c,query:d}=useRouter(),[p,f]=useState(false),[w,u]=useState(false);return (useEffect(()=>{let e=()=>{u(true);};return m.on("routeChangeComplete",e),()=>{m.off("routeChangeComplete",e);}},[m]),useEffect(()=>{w&&p&&c&&gtagPageview(c);},[c,d,w,p]),l)?jsxs(Fragment,{children:[jsx(o,{id:"google-tagmanager",src:`https://www.googletagmanager.com/gtag/js?id=${s}`,strategy:"afterInteractive",onLoad:()=>f(true)}),jsx(o,{id:"google-analytics",strategy:"afterInteractive",children:`
8
+ window.dataLayer = window.dataLayer || [];
9
+ function gtag(){window.dataLayer.push(arguments);}
10
+ gtag('js', new Date());
11
+
12
+ gtag('config', '${s}', { 'send_page_view': false });
13
+ `})]}):null};
14
+
15
+ export { AnalyticsGoogle, AnalyticsGoogle as default };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var r = require('next/head');
7
+
8
+ let DisableErrorOverlay=()=>jsxRuntime.jsx(r,{children:"development"===process.env.NODE_ENV&&jsxRuntime.jsx("script",{dangerouslySetInnerHTML:{__html:"window.addEventListener('error',event =>{event.stopImmediatePropagation()});window.addEventListener('unhandledrejection',event =>{event.stopImmediatePropagation()});"}})});
9
+
10
+ exports.DisableErrorOverlay = DisableErrorOverlay;
11
+ exports.default = DisableErrorOverlay;
@@ -1,2 +1,7 @@
1
- export declare const DisableErrorOverlay: () => import("react/jsx-runtime").JSX.Element;
1
+ /**
2
+ * Disable error overlay during `dev`
3
+ *
4
+ * @see https://github.com/vercel/next.js/discussions/13387#discussioncomment-101564
5
+ */
6
+ export declare let DisableErrorOverlay: () => import("react/jsx-runtime").JSX.Element;
2
7
  export default DisableErrorOverlay;
@@ -0,0 +1,6 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import r from 'next/head';
3
+
4
+ let DisableErrorOverlay=()=>jsx(r,{children:"development"===process.env.NODE_ENV&&jsx("script",{dangerouslySetInnerHTML:{__html:"window.addEventListener('error',event =>{event.stopImmediatePropagation()});window.addEventListener('unhandledrejection',event =>{event.stopImmediatePropagation()});"}})});
5
+
6
+ export { DisableErrorOverlay, DisableErrorOverlay as default };
package/12/Seo.d.ts CHANGED
@@ -1,9 +1,18 @@
1
1
  import type { NextSeoProps } from "next-seo/lib/types";
2
- import { type LinkTag, type MetaTag } from "./seoBuildTags.js";
3
- import type { SeoData } from "./types-seo.js";
2
+ import { type LinkTag, type MetaTag } from "./seoBuildTags";
3
+ export type SeoData = {
4
+ hidden?: boolean;
5
+ title?: string;
6
+ description?: string;
7
+ keywords?: string | string[];
8
+ ogimage?: string;
9
+ };
4
10
  type SeoPropsOpenGraph = NextSeoProps["openGraph"] & {
5
11
  image?: string;
6
12
  };
13
+ /**
14
+ * @see https://github.com/garmeeh/next-seo/blob/master/src/types.ts#L395
15
+ */
7
16
  export type SeoProps = Omit<NextSeoProps, "additionalMetaTags" | "additionalLinkTags" | "mobileAlternate" | "robotsProps"> & {
8
17
  metaTags?: ReadonlyArray<MetaTag>;
9
18
  linkTags?: ReadonlyArray<LinkTag>;
@@ -13,5 +22,28 @@ export type SeoProps = Omit<NextSeoProps, "additionalMetaTags" | "additionalLink
13
22
  openGraph?: SeoPropsOpenGraph;
14
23
  og?: SeoPropsOpenGraph;
15
24
  };
16
- export declare const Seo: (props: SeoProps) => import("react/jsx-runtime").JSX.Element;
25
+ /**
26
+ * Adapted from [garmeeh/next-seo](https://github.com/garmeeh/next-seo)
27
+ *
28
+ * See also:
29
+ * - https://github.com/catnose99/next-head-seo
30
+ * - https://nextjs.org/docs/api-reference/next/head
31
+ *
32
+ * NB: on the homepage you usually want to customize the `titleTemplate` to avoid
33
+ * doubled app name. Assuming your default seo configuration is something like:
34
+ *
35
+ * ```js
36
+ * {
37
+ * titleTemplate: "%s | MyApp"
38
+ * }
39
+ * ```
40
+ *
41
+ * On the homepage you migh want to override it, e.g.:
42
+ * ```js
43
+ * <Seo title="MyApp | Some description" titleTemplate="%s" />
44
+ * ```
45
+ *
46
+ * @deprecated
47
+ */
48
+ export declare let Seo: (props: SeoProps) => import("react/jsx-runtime").JSX.Element;
17
49
  export default Seo;
@@ -1,8 +1,16 @@
1
1
  import type { DefaultSeoProps } from "next-seo/lib/types";
2
- import { type LinkTag, type MetaTag } from "./seoBuildTags.js";
2
+ import type { JsonObject } from "@koine/utils";
3
+ import { type LinkTag, type MetaTag } from "./seoBuildTags";
4
+ /**
5
+ * @see https://github.com/garmeeh/next-seo/blob/master/src/types.ts#L413
6
+ */
3
7
  export type SeoDefaultsProps = Omit<DefaultSeoProps, "additionalMetaTags" | "additionalLinkTags" | "dangerouslySetAllPagesToNoIndex" | "dangerouslySetAllPagesToNoFollow" | "defaultOpenGraphImageWidth" | "defaultOpenGraphImageHeight" | "defaultOpenGraphVideoWidth" | "defaultOpenGraphVideoHeight" | "mobileAlternate" | "robotsProps"> & {
4
8
  metaTags?: ReadonlyArray<MetaTag>;
5
9
  linkTags?: ReadonlyArray<LinkTag>;
10
+ schema?: JsonObject;
6
11
  };
7
- export declare const SeoDefaults: (props: SeoDefaultsProps) => import("react/jsx-runtime").JSX.Element;
12
+ /**
13
+ * @deprecated
14
+ */
15
+ export declare let SeoDefaults: (props: SeoDefaultsProps) => import("react/jsx-runtime").JSX.Element;
8
16
  export default SeoDefaults;
@@ -1,8 +1,22 @@
1
- import React from "react";
2
- import type { SeoProps } from "./Seo.js";
3
- import type { SeoDefaultsProps } from "./SeoDefaults.js";
1
+ import type { SeoProps } from "./Seo";
2
+ import type { SeoDefaultsProps } from "./SeoDefaults";
4
3
  export type MetaTag = React.DetailedHTMLProps<React.MetaHTMLAttributes<HTMLMetaElement>, HTMLMetaElement>;
5
4
  export type LinkTag = React.DetailedHTMLProps<React.LinkHTMLAttributes<HTMLLinkElement>, HTMLLinkElement>;
6
5
  type BuildTagsParams = SeoProps & SeoDefaultsProps;
7
- export declare const seoBuildTags: ({ seo, hidden, keywords, title, titleTemplate, defaultTitle, noindex, nofollow, description, languageAlternates, twitter, facebook, openGraph, og: ogAlias, canonical, metaTags, linkTags, }?: BuildTagsParams) => React.ReactNode[];
6
+ /**
7
+ * Comparing to `next-seo` we do a couple of things in addition while many
8
+ * others are removed.
9
+ *
10
+ * - Add `seo` meta object coming from a CMS probably
11
+ * - Add `ogimage` and `openGraph.image` as single image source
12
+ * - Add `og` alias to define `openGraph`
13
+ * - Add check for `title` equal to `templateTitle` to avoid meta titles like
14
+ * "My site | My site" often happening in homepages
15
+ * - Remove the open graph videos and images
16
+ *
17
+ * - Shorter code
18
+ *
19
+ * @returns
20
+ */
21
+ export declare const seoBuildTags: ({ seo, hidden, keywords, title, titleTemplate, defaultTitle, noindex, nofollow, description, languageAlternates, twitter, facebook, openGraph, og: ogAlias, canonical, metaTags, linkTags, schema, }?: BuildTagsParams) => import("react").ReactNode[];
8
22
  export default seoBuildTags;
package/12/types.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- export * from "./types-i18n.js";
2
- export * from "./types-seo.js";
3
- export type { TProps } from "./T.js";
4
- export type { GetT } from "./getT.js";
5
- export type { DynamicNamespacesProps } from "./DynamicNamespaces.js";
6
- export type { SeoDefaultsProps } from "./SeoDefaults.js";
7
- export type { ToTranslate, ToStaticRoute, ToDynamicRoute, ToArgs } from "./to.js";
1
+ /**
2
+ * @file Export all types separately to ease imports
3
+ */
4
+ export type { SeoData } from "./Seo";
5
+ export type { SeoDefaultsProps } from "./SeoDefaults";
@@ -0,0 +1 @@
1
+ exports._default = require('./12.cjs.js').default;
package/12.cjs.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var AnalyticsGoogle = require('./12/AnalyticsGoogle.cjs.js');
4
+ var DisableErrorOverlay = require('./12/DisableErrorOverlay.cjs.js');
5
+
6
+
7
+
8
+ exports.AnalyticsGoogle = AnalyticsGoogle.AnalyticsGoogle;
9
+ exports.DisableErrorOverlay = DisableErrorOverlay.DisableErrorOverlay;
package/12.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './12.cjs.js';
2
+ export { _default as default } from './12.cjs.default.js';
package/12.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { AnalyticsGoogle, type AnalyticsGoogleProps, } from "./12/AnalyticsGoogle";
2
+ export { DisableErrorOverlay } from "./12/DisableErrorOverlay";
3
+ export * from "./12/types";
package/12.esm.js ADDED
@@ -0,0 +1,2 @@
1
+ export { AnalyticsGoogle } from './12/AnalyticsGoogle.esm.js';
2
+ export { DisableErrorOverlay } from './12/DisableErrorOverlay.esm.js';
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @koine/next
@@ -0,0 +1 @@
1
+ exports._default = require('./ThemeContext.cjs.js').default;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ const ThemeContext=react.createContext({setTheme:e=>{},themes:[]});
8
+
9
+ exports.ThemeContext = ThemeContext;
10
+ exports.default = ThemeContext;
@@ -0,0 +1,2 @@
1
+ export * from './ThemeContext.cjs.js';
2
+ export { _default as default } from './ThemeContext.cjs.default.js';
package/ThemeContext.d.ts CHANGED
@@ -1,10 +1,15 @@
1
- /// <reference types="react" />
2
1
  export type ThemeContextProps = {
2
+ /** List of all available theme names */
3
3
  themes: string[];
4
+ /** Forced theme name for the current page */
4
5
  forcedTheme?: string;
6
+ /** Update the theme */
5
7
  setTheme: (theme: string) => void;
8
+ /** Active theme name */
6
9
  theme?: string;
10
+ /** 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` */
7
11
  resolvedTheme?: string;
12
+ /** If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is */
8
13
  systemTheme?: "dark" | "light";
9
14
  };
10
15
  export declare const ThemeContext: import("react").Context<ThemeContextProps>;
@@ -0,0 +1,5 @@
1
+ import { createContext } from 'react';
2
+
3
+ const ThemeContext=createContext({setTheme:e=>{},themes:[]});
4
+
5
+ export { ThemeContext, ThemeContext as default };
@@ -0,0 +1 @@
1
+ exports._default = require('./ThemeProvider.cjs.js').default;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var o = require('next/script');
7
+ var react = require('react');
8
+ var utils = require('@koine/utils');
9
+ var ThemeContext = require('./ThemeContext.cjs.js');
10
+
11
+ let l=["light","dark"],d="(prefers-color-scheme: dark)",c="theme";const ThemeProvider=({forcedTheme:r,disableTransitionOnChange:o=false,enableSystem:v=true,enableColorScheme:y,themes:p=["light","dark"],defaultTheme:g=v?"system":"light",attribute:w="data-theme",value:x,children:S,nonce:k})=>{let[b,L]=react.useState(()=>u(c,g)),[T,j]=react.useState(()=>u(c)),C=x?Object.values(x):p,E=react.useCallback(e=>{let t=e;if(utils.isServer||!t)return;"system"===e&&v&&(t=f());let r=x?x[t]:t,i=o?$():null,n=document.documentElement;if("class"===w?(n.classList.remove(...C),r&&n.classList.add(r)):r?n.setAttribute(w,r):n.removeAttribute(w),y){let e=l.includes(g)?g:"",r=l.includes(t)?t:e;n.style.colorScheme=r;}i?.();},[w,C,g,o,y,v,x]),I=react.useCallback(e=>{L(e);try{localStorage.setItem(c,e);}catch(e){}},[]),M=react.useCallback(e=>{j(f(e)),"system"===b&&v&&!r&&E("system");},[b,v,r,E]);return react.useEffect(()=>{let e=window.matchMedia(d);return e.addListener(M),M(e),()=>e.removeListener(M)},[M]),react.useEffect(()=>{let e=e=>{e.key===c&&I(e.newValue||g);};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[g,I]),react.useEffect(()=>{E(r??b);},[E,r,b]),jsxRuntime.jsxs(ThemeContext.ThemeContext.Provider,{value:{theme:b,setTheme:I,forcedTheme:r,resolvedTheme:"system"===b?T:b,themes:v?[...p,"system"]:p,systemTheme:v?T:void 0},children:[jsxRuntime.jsx(h,{forcedTheme:r,disableTransitionOnChange:o,enableSystem:v,enableColorScheme:y,themes:p,defaultTheme:g,attribute:w,value:x,children:S,attrs:C,nonce:k}),S]})};let h=react.memo(({forcedTheme:t,attribute:o$1,enableSystem:i,enableColorScheme:n,defaultTheme:s,value:a,attrs:m,nonce:h})=>{let u="system"===s,$=(()=>{let e=`d.remove(${m.map(e=>`'${e}'`).join(",")})`;return `var d=document.documentElement.classList;${e};`})(),f=n?(l.includes(s)?s:null)?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${s}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",y=(e,t=false,r=true)=>{let i=a?a[e]:e,s=t?e+"|| ''":`'${i}'`,m="";return n&&r&&!t&&l.includes(e)&&(m+=`d.style.colorScheme = '${e}';`),"class"===o$1?t||i?m+=`d.add(${s})`:m+="null":i&&(m+=`d[s](n, ${s})`),m},p=t?`!function(){${$}${y(t)}}()`:i?`!function(){try {${$}var e=localStorage.getItem('${c}');if("system"===e||(!e&&${u})){var t="${d}",m=window.matchMedia(t);if(m.media!==t||m.matches){${y("dark")}}else{${y("light")}}}else if(e){${a?`var x=${JSON.stringify(a)};`:""}${y(a?"x[e]":"e",true)}}${!u?"else{"+y(s,false,false)+"}":""}${f}}catch(e){}}()`:`!function(){try{${$}var e=localStorage.getItem("${c}");if(e){${a?`var x=${JSON.stringify(a)};`:""}${y(a?"x[e]":"e",true)}}else{${y(s,false,false)};}${f}}catch(t){}}();`;return jsxRuntime.jsx(o,{id:"next-theme-script",strategy:"beforeInteractive",src:`data:text/javascript;base64,${v(p)}`,nonce:h})},()=>true),u=(e,t)=>{let r;if(!utils.isServer){try{r=localStorage.getItem(e)||void 0;}catch(e){}return r||t}},$=()=>{let e=document,t=e.createElement("style");return t.appendChild(e.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),e.head.appendChild(t),()=>{window.getComputedStyle(e.body),setTimeout(()=>{e.head.removeChild(t);},1);}},f=e=>(e||(e=window.matchMedia(d)),e.matches?"dark":"light"),v=e=>utils.isServer?Buffer.from(e).toString("base64"):btoa(e);
12
+
13
+ exports.ThemeProvider = ThemeProvider;
14
+ exports.default = ThemeProvider;
@@ -0,0 +1,2 @@
1
+ export * from './ThemeProvider.cjs.js';
2
+ export { _default as default } from './ThemeProvider.cjs.default.js';
@@ -1,17 +1,34 @@
1
- /// <reference types="react" />
2
1
  type ValueObject = {
3
2
  [themeName: string]: string;
4
3
  };
5
4
  export type ThemeProviderProps = React.PropsWithChildren<{
5
+ /** List of all available theme names */
6
6
  themes?: string[];
7
+ /** Forced theme name for the current page */
7
8
  forcedTheme?: string;
9
+ /** Whether to switch between dark and light themes based on prefers-color-scheme */
8
10
  enableSystem?: boolean;
11
+ /** Disable all CSS transitions when switching themes */
9
12
  disableTransitionOnChange?: boolean;
13
+ /** Whether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons */
10
14
  enableColorScheme?: boolean;
15
+ /** Default theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light */
11
16
  defaultTheme?: string;
17
+ /** HTML attribute modified based on the active theme. Accepts `class` and `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.) */
12
18
  attribute?: string | "class";
19
+ /** Mapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value */
13
20
  value?: ValueObject;
21
+ /** Nonce string to pass to the inline script for CSP headers */
14
22
  nonce?: string;
15
23
  }>;
24
+ /**
25
+ * @borrows [next-themes](https://github.com/pacocoursey/next-themes)
26
+ *
27
+ * Differences:
28
+ *
29
+ * - enableColorScheme: `false` by default (instead of `true`), this plays more
30
+ * nicely with tailwind `dark` class mode as dark theme is supposed to be only
31
+ * controlled by tailwind modifiers
32
+ */
16
33
  export declare const ThemeProvider: ({ forcedTheme, disableTransitionOnChange, enableSystem, enableColorScheme, themes, defaultTheme, attribute, value, children, nonce, }: ThemeProviderProps) => import("react/jsx-runtime").JSX.Element;
17
34
  export default ThemeProvider;
@@ -0,0 +1,9 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import o from 'next/script';
3
+ import { memo, useState, useCallback, useEffect } from 'react';
4
+ import { isServer } from '@koine/utils';
5
+ import { ThemeContext } from './ThemeContext.esm.js';
6
+
7
+ let l=["light","dark"],d="(prefers-color-scheme: dark)",c="theme";const ThemeProvider=({forcedTheme:r,disableTransitionOnChange:o=false,enableSystem:v=true,enableColorScheme:y,themes:p=["light","dark"],defaultTheme:g=v?"system":"light",attribute:w="data-theme",value:x,children:S,nonce:k})=>{let[b,L]=useState(()=>u(c,g)),[T,j]=useState(()=>u(c)),C=x?Object.values(x):p,E=useCallback(e=>{let t=e;if(isServer||!t)return;"system"===e&&v&&(t=f());let r=x?x[t]:t,i=o?$():null,n=document.documentElement;if("class"===w?(n.classList.remove(...C),r&&n.classList.add(r)):r?n.setAttribute(w,r):n.removeAttribute(w),y){let e=l.includes(g)?g:"",r=l.includes(t)?t:e;n.style.colorScheme=r;}i?.();},[w,C,g,o,y,v,x]),I=useCallback(e=>{L(e);try{localStorage.setItem(c,e);}catch(e){}},[]),M=useCallback(e=>{j(f(e)),"system"===b&&v&&!r&&E("system");},[b,v,r,E]);return useEffect(()=>{let e=window.matchMedia(d);return e.addListener(M),M(e),()=>e.removeListener(M)},[M]),useEffect(()=>{let e=e=>{e.key===c&&I(e.newValue||g);};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[g,I]),useEffect(()=>{E(r??b);},[E,r,b]),jsxs(ThemeContext.Provider,{value:{theme:b,setTheme:I,forcedTheme:r,resolvedTheme:"system"===b?T:b,themes:v?[...p,"system"]:p,systemTheme:v?T:void 0},children:[jsx(h,{forcedTheme:r,disableTransitionOnChange:o,enableSystem:v,enableColorScheme:y,themes:p,defaultTheme:g,attribute:w,value:x,children:S,attrs:C,nonce:k}),S]})};let h=memo(({forcedTheme:t,attribute:o$1,enableSystem:i,enableColorScheme:n,defaultTheme:s,value:a,attrs:m,nonce:h})=>{let u="system"===s,$=(()=>{let e=`d.remove(${m.map(e=>`'${e}'`).join(",")})`;return `var d=document.documentElement.classList;${e};`})(),f=n?(l.includes(s)?s:null)?`if(e==='light'||e==='dark'||!e)d.style.colorScheme=e||'${s}'`:"if(e==='light'||e==='dark')d.style.colorScheme=e":"",y=(e,t=false,r=true)=>{let i=a?a[e]:e,s=t?e+"|| ''":`'${i}'`,m="";return n&&r&&!t&&l.includes(e)&&(m+=`d.style.colorScheme = '${e}';`),"class"===o$1?t||i?m+=`d.add(${s})`:m+="null":i&&(m+=`d[s](n, ${s})`),m},p=t?`!function(){${$}${y(t)}}()`:i?`!function(){try {${$}var e=localStorage.getItem('${c}');if("system"===e||(!e&&${u})){var t="${d}",m=window.matchMedia(t);if(m.media!==t||m.matches){${y("dark")}}else{${y("light")}}}else if(e){${a?`var x=${JSON.stringify(a)};`:""}${y(a?"x[e]":"e",true)}}${!u?"else{"+y(s,false,false)+"}":""}${f}}catch(e){}}()`:`!function(){try{${$}var e=localStorage.getItem("${c}");if(e){${a?`var x=${JSON.stringify(a)};`:""}${y(a?"x[e]":"e",true)}}else{${y(s,false,false)};}${f}}catch(t){}}();`;return jsx(o,{id:"next-theme-script",strategy:"beforeInteractive",src:`data:text/javascript;base64,${v(p)}`,nonce:h})},()=>true),u=(e,t)=>{let r;if(!isServer){try{r=localStorage.getItem(e)||void 0;}catch(e){}return r||t}},$=()=>{let e=document,t=e.createElement("style");return t.appendChild(e.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}")),e.head.appendChild(t),()=>{window.getComputedStyle(e.body),setTimeout(()=>{e.head.removeChild(t);},1);}},f=e=>(e||(e=window.matchMedia(d)),e.matches?"dark":"light"),v=e=>isServer?Buffer.from(e).toString("base64"):btoa(e);
8
+
9
+ export { ThemeProvider, ThemeProvider as default };
@@ -0,0 +1 @@
1
+ exports._default = require('./config.cjs.js').default;
package/config.cjs.js ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var swc = require('@koine/node/swc');
4
+ var next = require('@koine/i18n/next');
5
+
6
+ let withKoine=(s={})=>{let{nx:p,svg:a,i18nRoutes:m,i18nCompiler:l,modularize:u,...c}=s,w={modularizeImports:{...u?Array.isArray(u)?swc.swcCreateTransforms(u):swc.swcCreateTransform(u):{},...c.modularizeImports||{},...swc.swcTransformsKoine},...c};return (a&&(p?w.nx={svgr:true}:(delete w.nx,w.webpack=(e,o)=>{let r="function"==typeof c.webpack?c.webpack(e,o):e;return r.module.rules.push({test:/\.svg$/,use:[{loader:"@svgr/webpack",options:{svgoConfig:{plugins:[{name:"removeViewBox",active:false}]}}}]}),r})),m)?next.withI18nLegacy({...w,i18nRoutes:m}):l?p?next.withI18nAsync({...w,i18nCompiler:l}):next.withI18n({...w,i18nCompiler:l}):w};
7
+
8
+ exports.withKoine = withKoine;
package/config.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './config.cjs.js';
2
+ export { _default as default } from './config.cjs.default.js';
package/config.d.ts CHANGED
@@ -1,109 +1,33 @@
1
1
  import type { NextConfig } from "next";
2
- import { type ConfigI18nOptions, type Routes } from "./config-i18n.js";
3
- interface KoineNextConfig {
2
+ import { type SwcTransformingLib } from "@koine/node/swc";
3
+ import { type WithI18nAsyncOptions, type WithI18nLegacyOptions } from "@koine/i18n/next";
4
+ /**
5
+ * @legacy
6
+ */
7
+ export type Routes = NonNullable<WithI18nLegacyOptions["i18nRoutes"]>["routes"];
8
+ export type WithKoineOptions = NextConfig & {
9
+ /**
10
+ * Set it to `true` when your _Next.js_ app is built inside a Nx monorepo
11
+ */
4
12
  nx?: boolean;
13
+ /**
14
+ * Set it to `true` in order to be able importing React components directly
15
+ * from `.svg` files.
16
+ *
17
+ * It automatically configure webpack taking into account the `nx` option.
18
+ */
5
19
  svg?: boolean;
6
- sc?: boolean;
7
- page?: boolean;
8
- routes?: Routes;
9
- permanent?: boolean;
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;
108
- };
109
- export default withKoine;
20
+ /**
21
+ * Shortcut option to automatically create swc transforms to feed into
22
+ * _Next.js_' `modularizeImports`.
23
+ *
24
+ * Pass _one_ or an _array_ of {@link SwcTransformingLib lib transform object}.
25
+ */
26
+ modularize?: SwcTransformingLib[] | SwcTransformingLib;
27
+ } & WithI18nLegacyOptions & WithI18nAsyncOptions;
28
+ /**
29
+ * Get _Next.js_ config with some extra {@link WithKoineOptions options}
30
+ *
31
+ * @param options
32
+ */
33
+ export declare let withKoine: (options?: WithKoineOptions) => NextConfig;
package/config.esm.js ADDED
@@ -0,0 +1,6 @@
1
+ import { swcTransformsKoine, swcCreateTransforms, swcCreateTransform } from '@koine/node/swc';
2
+ import { withI18nLegacy, withI18nAsync, withI18n } from '@koine/i18n/next';
3
+
4
+ let withKoine=(s={})=>{let{nx:p,svg:a,i18nRoutes:m,i18nCompiler:l,modularize:u,...c}=s,w={modularizeImports:{...u?Array.isArray(u)?swcCreateTransforms(u):swcCreateTransform(u):{},...c.modularizeImports||{},...swcTransformsKoine},...c};return (a&&(p?w.nx={svgr:true}:(delete w.nx,w.webpack=(e,o)=>{let r="function"==typeof c.webpack?c.webpack(e,o):e;return r.module.rules.push({test:/\.svg$/,use:[{loader:"@svgr/webpack",options:{svgoConfig:{plugins:[{name:"removeViewBox",active:false}]}}}]}),r})),m)?withI18nLegacy({...w,i18nRoutes:m}):l?p?withI18nAsync({...w,i18nCompiler:l}):withI18n({...w,i18nCompiler:l}):w};
5
+
6
+ export { withKoine };
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/index.cjs.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var load = require('./load.cjs.js');
4
+ var ThemeContext = require('./ThemeContext.cjs.js');
5
+ var ThemeProvider = require('./ThemeProvider.cjs.js');
6
+ var useTheme = require('./useTheme.cjs.js');
7
+
8
+
9
+
10
+ exports.load = load.load;
11
+ exports.ThemeContext = ThemeContext.ThemeContext;
12
+ exports.ThemeProvider = ThemeProvider.ThemeProvider;
13
+ exports.useTheme = useTheme.useTheme;
package/index.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { getSiteUrl } from "./getSiteUrl.js";
2
- export { load } from "./load.js";
3
- export { ThemeContext, type ThemeContextProps } from "./ThemeContext.js";
4
- export { ThemeProvider, type ThemeProviderProps } from "./ThemeProvider.js";
5
- export { useTheme, type UseThemeProps } from "./useTheme.js";
1
+ export { load } from "./load";
2
+ export { ThemeContext, type ThemeContextProps } from "./ThemeContext";
3
+ export { ThemeProvider, type ThemeProviderProps } from "./ThemeProvider";
4
+ export { useTheme, type UseThemeProps } from "./useTheme";
package/index.esm.js ADDED
@@ -0,0 +1,4 @@
1
+ export { load } from './load.esm.js';
2
+ export { ThemeContext } from './ThemeContext.esm.js';
3
+ export { ThemeProvider } from './ThemeProvider.esm.js';
4
+ export { useTheme } from './useTheme.esm.js';
@@ -0,0 +1 @@
1
+ exports._default = require('./load.cjs.js').default;
package/load.cjs.js ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function load(e,o){return new Promise(t=>{setTimeout(()=>t(e),o);})}
6
+
7
+ exports.default = load;
8
+ exports.load = load;
package/load.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './load.cjs.js';
2
+ export { _default as default } from './load.cjs.default.js';
package/load.d.ts CHANGED
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Utility to load a component with an optional pre-determined delay.
3
+ *
4
+ * This was designed to improve anti spam with async form loading.
5
+ *
6
+ * @see https://github.com/vercel/next.js/blob/main/packages/next/next-server/lib/dynamic.tsx
7
+ * @see https://github.com/vercel/next.js/blob/canary/examples/with-dynamic-import/pages/index.js
8
+ */
1
9
  export declare function load<T>(component: T, milliseconds: number): Promise<T>;
2
10
  export default load;
package/load.esm.js ADDED
@@ -0,0 +1,3 @@
1
+ function load(e,o){return new Promise(t=>{setTimeout(()=>t(e),o);})}
2
+
3
+ export { load as default, load };