@reforma/site 1.0.1 → 1.0.2

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  export { initAnalytics, track } from './analytics.js';
2
2
  export { ErrorState } from './error-state.js';
3
3
  export { projectMetadata, projectRobots } from './metadata.js';
4
+ export { SiteRoot } from './root.js';
5
+ export { useTheme as useMode, useTheme } from 'next-themes';
4
6
  export type { FixErrorDetail } from './error-state.js';
7
+ export type { ModeDocument } from './root.js';
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5D,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export { initAnalytics, track } from './analytics.js';
2
2
  export { ErrorState } from './error-state.js';
3
3
  export { projectMetadata, projectRobots } from './metadata.js';
4
+ export { SiteRoot } from './root.js';
5
+ // `useMode` is the pre-1.0 name, kept for older starters' sonner.tsx.
6
+ export { useTheme as useMode, useTheme } from 'next-themes';
package/dist/root.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type ReactNode } from 'react';
2
+ /** The project's generated `.reforma/tokens/.generated/modes.json`. */
3
+ export type ModeDocument = {
4
+ default: string;
5
+ modifiers: {
6
+ name: string;
7
+ contexts: string[];
8
+ }[];
9
+ };
10
+ /** Mounts next-themes on `data-theme` with the token modes, which the generated token CSS selects. */
11
+ export declare function SiteRoot({ children, modes }: {
12
+ children: ReactNode;
13
+ modes: ModeDocument;
14
+ }): import("react").JSX.Element;
15
+ //# sourceMappingURL=root.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3D,uEAAuE;AACvE,MAAM,MAAM,YAAY,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;CACrD,CAAC;AAeF,sGAAsG;AACtG,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,+BAYzF"}
package/dist/root.js ADDED
@@ -0,0 +1,19 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { ThemeProvider, useTheme } from 'next-themes';
4
+ import { useEffect, useMemo } from 'react';
5
+ /** next-themes keeps a stored theme the tokens no longer have (renamed or deleted); fall back to the default mode. */
6
+ function DropRemovedTheme({ themes, defaultTheme }) {
7
+ const { theme, setTheme } = useTheme();
8
+ useEffect(() => {
9
+ if (theme && theme !== 'system' && !themes.includes(theme)) {
10
+ setTheme(defaultTheme);
11
+ }
12
+ }, [theme, setTheme, themes, defaultTheme]);
13
+ return null;
14
+ }
15
+ /** Mounts next-themes on `data-theme` with the token modes, which the generated token CSS selects. */
16
+ export function SiteRoot({ children, modes }) {
17
+ const themes = useMemo(() => modes.modifiers.find(modifier => modifier.name === 'mode')?.contexts ?? [], [modes]);
18
+ return (_jsxs(ThemeProvider, { attribute: "data-theme", themes: themes, defaultTheme: modes.default, disableTransitionOnChange: true, children: [_jsx(DropRemovedTheme, { themes: themes, defaultTheme: modes.default }), children] }));
19
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reforma/site",
3
- "version": "1.0.1",
4
- "description": "Visitor runtime for a Reforma site: publish metadata, analytics, and the PostCSS url guard.",
3
+ "version": "1.0.2",
4
+ "description": "Visitor runtime for a Reforma site: theme modes, publish metadata, analytics, and the PostCSS url guard.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "author": "Reforma, Inc. <dev@reforma.ai>",
@@ -41,6 +41,9 @@
41
41
  "lint": "eslint src",
42
42
  "lint:fix": "eslint src --fix"
43
43
  },
44
+ "dependencies": {
45
+ "next-themes": "^0.4.6"
46
+ },
44
47
  "peerDependencies": {
45
48
  "react": "^19.2.8",
46
49
  "react-dom": "^19.2.8"