@codefast/theme 0.5.0-canary.1 → 0.5.0-canary.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/CHANGELOG.md +31 -0
- package/README.md +107 -178
- package/dist/appearance-context.d.mts +18 -0
- package/dist/appearance-context.mjs +16 -0
- package/dist/appearance-provider.d.mts +74 -0
- package/dist/appearance-provider.mjs +180 -0
- package/dist/appearance-script.d.mts +59 -0
- package/dist/appearance-script.mjs +46 -0
- package/dist/appearance.d.mts +60 -0
- package/dist/appearance.mjs +25 -0
- package/dist/color-scheme.d.mts +27 -0
- package/dist/color-scheme.mjs +32 -0
- package/dist/constants.d.mts +15 -14
- package/dist/constants.mjs +14 -13
- package/dist/{utils/dom.d.mts → dom.d.mts} +6 -8
- package/dist/{utils/dom.mjs → dom.mjs} +7 -9
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -7
- package/dist/use-appearance.d.mts +34 -0
- package/dist/use-appearance.mjs +38 -0
- package/package.json +39 -63
- package/src/appearance-context.ts +22 -0
- package/src/appearance-provider.tsx +363 -0
- package/src/appearance-script.tsx +86 -0
- package/src/appearance.ts +66 -0
- package/src/color-scheme.ts +42 -0
- package/src/constants.ts +14 -13
- package/src/{utils/dom.ts → dom.ts} +8 -10
- package/src/index.ts +19 -16
- package/src/use-appearance.ts +46 -0
- package/dist/adapters/tanstack-start/server.d.mts +0 -88
- package/dist/adapters/tanstack-start/server.mjs +0 -93
- package/dist/adapters/tanstack-start/vite.d.mts +0 -12
- package/dist/adapters/tanstack-start/vite.mjs +0 -21
- package/dist/core/context.d.mts +0 -18
- package/dist/core/context.mjs +0 -16
- package/dist/core/provider.d.mts +0 -118
- package/dist/core/provider.mjs +0 -231
- package/dist/core/use-theme.d.mts +0 -34
- package/dist/core/use-theme.mjs +0 -38
- package/dist/script/theme-script.d.mts +0 -68
- package/dist/script/theme-script.mjs +0 -45
- package/dist/start.d.mts +0 -2
- package/dist/start.mjs +0 -2
- package/dist/types.d.mts +0 -60
- package/dist/types.mjs +0 -25
- package/dist/utils/system.d.mts +0 -34
- package/dist/utils/system.mjs +0 -40
- package/src/adapters/tanstack-start/server.ts +0 -146
- package/src/adapters/tanstack-start/vite.ts +0 -50
- package/src/core/context.tsx +0 -22
- package/src/core/provider.tsx +0 -470
- package/src/core/use-theme.ts +0 -46
- package/src/script/theme-script.tsx +0 -92
- package/src/start.ts +0 -54
- package/src/types.ts +0 -61
- package/src/utils/system.ts +0 -56
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/dom.ts
|
|
2
2
|
/**
|
|
3
|
-
* Apply color scheme to the DOM by updating `<html>` element.
|
|
3
|
+
* Apply a color scheme to the DOM by updating the `<html>` element.
|
|
4
4
|
*
|
|
5
5
|
* Updates both:
|
|
6
6
|
* - CSS class (for Tailwind's `dark:` variants)
|
|
7
7
|
* - `color-scheme` style (for native form controls and scrollbars)
|
|
8
8
|
*
|
|
9
|
-
* @param resolved - The resolved color scheme to apply ('light' or 'dark')
|
|
10
|
-
*
|
|
11
9
|
* @since 0.3.16-canary.0
|
|
12
10
|
*/
|
|
13
|
-
function applyColorScheme(
|
|
11
|
+
function applyColorScheme(colorScheme) {
|
|
14
12
|
const root = window.document.documentElement;
|
|
15
13
|
root.classList.remove("light", "dark", "automatic");
|
|
16
|
-
root.classList.add(
|
|
17
|
-
root.style.colorScheme =
|
|
14
|
+
root.classList.add(colorScheme);
|
|
15
|
+
root.style.colorScheme = colorScheme;
|
|
18
16
|
}
|
|
19
17
|
/**
|
|
20
|
-
* Temporarily suppress all CSS transitions during
|
|
18
|
+
* Temporarily suppress all CSS transitions during appearance changes.
|
|
21
19
|
*
|
|
22
20
|
* Prevents jarring color animations when switching between light/dark appearances.
|
|
23
21
|
* Respects user's `prefers-reduced-motion` preference (does nothing if enabled).
|
|
24
22
|
*
|
|
25
23
|
* @param nonce - Optional CSP nonce for the injected style element
|
|
26
|
-
* @returns Cleanup function to re-enable transitions. Call after color scheme is applied.
|
|
24
|
+
* @returns Cleanup function to re-enable transitions. Call after the color scheme is applied.
|
|
27
25
|
*
|
|
28
26
|
* @example
|
|
29
27
|
* ```tsx
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export { AppearanceProvider, type AppearanceProviderProps, AppearanceScript, type AppearanceScriptProps, type ColorScheme,
|
|
1
|
+
import { Appearance, AppearanceContextType, ColorScheme, appearanceSchema, appearances } from "./appearance.mjs";
|
|
2
|
+
import { AppearanceProvider, AppearanceProviderProps } from "./appearance-provider.mjs";
|
|
3
|
+
import { AppearanceScript, AppearanceScriptProps } from "./appearance-script.mjs";
|
|
4
|
+
import { resolveColorScheme } from "./color-scheme.mjs";
|
|
5
|
+
import { DEFAULT_APPEARANCE, DEFAULT_COLOR_SCHEME } from "./constants.mjs";
|
|
6
|
+
import { useAppearance } from "./use-appearance.mjs";
|
|
7
|
+
export { type Appearance, type AppearanceContextType, AppearanceProvider, type AppearanceProviderProps, AppearanceScript, type AppearanceScriptProps, type ColorScheme, DEFAULT_APPEARANCE, DEFAULT_COLOR_SCHEME, appearanceSchema, appearances, resolveColorScheme, useAppearance };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { resolveColorScheme } from "./
|
|
4
|
-
import { AppearanceProvider } from "./
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export { AppearanceProvider, AppearanceScript,
|
|
1
|
+
import { appearanceSchema, appearances } from "./appearance.mjs";
|
|
2
|
+
import { DEFAULT_APPEARANCE, DEFAULT_COLOR_SCHEME } from "./constants.mjs";
|
|
3
|
+
import { resolveColorScheme } from "./color-scheme.mjs";
|
|
4
|
+
import { AppearanceProvider } from "./appearance-provider.mjs";
|
|
5
|
+
import { AppearanceScript } from "./appearance-script.mjs";
|
|
6
|
+
import { useAppearance } from "./use-appearance.mjs";
|
|
7
|
+
export { AppearanceProvider, AppearanceScript, DEFAULT_APPEARANCE, DEFAULT_COLOR_SCHEME, appearanceSchema, appearances, resolveColorScheme, useAppearance };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AppearanceContextType } from "./appearance.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/use-appearance.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Hook to access appearance context.
|
|
6
|
+
*
|
|
7
|
+
* Uses React 19's `use()` API for context consumption, enabling:
|
|
8
|
+
* - Conditional context reading
|
|
9
|
+
* - Better Suspense boundary integration
|
|
10
|
+
*
|
|
11
|
+
* @returns Appearance context with `appearance`, `colorScheme`, `setAppearance`, and `isPending`
|
|
12
|
+
* @throws Error if called outside of AppearanceProvider
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function AppearanceToggle() {
|
|
17
|
+
* const { appearance, setAppearance, isPending } = useAppearance();
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <button
|
|
21
|
+
* onClick={() => setAppearance(appearance === 'dark' ? 'light' : 'dark')}
|
|
22
|
+
* disabled={isPending}
|
|
23
|
+
* >
|
|
24
|
+
* {appearance}
|
|
25
|
+
* </button>
|
|
26
|
+
* );
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @since 0.5.0-canary.2
|
|
31
|
+
*/
|
|
32
|
+
declare function useAppearance(): AppearanceContextType;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { useAppearance };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AppearanceContext } from "./appearance-context.mjs";
|
|
2
|
+
import { use } from "react";
|
|
3
|
+
//#region src/use-appearance.ts
|
|
4
|
+
/**
|
|
5
|
+
* Hook to access appearance context.
|
|
6
|
+
*
|
|
7
|
+
* Uses React 19's `use()` API for context consumption, enabling:
|
|
8
|
+
* - Conditional context reading
|
|
9
|
+
* - Better Suspense boundary integration
|
|
10
|
+
*
|
|
11
|
+
* @returns Appearance context with `appearance`, `colorScheme`, `setAppearance`, and `isPending`
|
|
12
|
+
* @throws Error if called outside of AppearanceProvider
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function AppearanceToggle() {
|
|
17
|
+
* const { appearance, setAppearance, isPending } = useAppearance();
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <button
|
|
21
|
+
* onClick={() => setAppearance(appearance === 'dark' ? 'light' : 'dark')}
|
|
22
|
+
* disabled={isPending}
|
|
23
|
+
* >
|
|
24
|
+
* {appearance}
|
|
25
|
+
* </button>
|
|
26
|
+
* );
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @since 0.5.0-canary.2
|
|
31
|
+
*/
|
|
32
|
+
function useAppearance() {
|
|
33
|
+
const value = use(AppearanceContext);
|
|
34
|
+
if (!value) throw new Error("useAppearance must be used within an AppearanceProvider");
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useAppearance };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codefast/theme",
|
|
3
|
-
"version": "0.5.0-canary.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.5.0-canary.2",
|
|
4
|
+
"description": "Appearance management for React 19 with HIG-inspired vocabulary - optimistic updates, cross-tab sync, and FOUC-free SSR",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dark-mode",
|
|
7
7
|
"light-mode",
|
|
@@ -56,60 +56,45 @@
|
|
|
56
56
|
"types": "./dist/index.d.mts",
|
|
57
57
|
"import": "./dist/index.mjs"
|
|
58
58
|
},
|
|
59
|
-
"./
|
|
60
|
-
"source": "./src/
|
|
61
|
-
"types": "./dist/
|
|
62
|
-
"import": "./dist/
|
|
59
|
+
"./appearance": {
|
|
60
|
+
"source": "./src/appearance.ts",
|
|
61
|
+
"types": "./dist/appearance.d.mts",
|
|
62
|
+
"import": "./dist/appearance.mjs"
|
|
63
63
|
},
|
|
64
|
-
"./
|
|
65
|
-
"source": "./src/
|
|
66
|
-
"types": "./dist/
|
|
67
|
-
"import": "./dist/
|
|
64
|
+
"./appearance-context": {
|
|
65
|
+
"source": "./src/appearance-context.ts",
|
|
66
|
+
"types": "./dist/appearance-context.d.mts",
|
|
67
|
+
"import": "./dist/appearance-context.mjs"
|
|
68
68
|
},
|
|
69
|
-
"./
|
|
70
|
-
"source": "./src/
|
|
71
|
-
"types": "./dist/
|
|
72
|
-
"import": "./dist/
|
|
69
|
+
"./appearance-provider": {
|
|
70
|
+
"source": "./src/appearance-provider.tsx",
|
|
71
|
+
"types": "./dist/appearance-provider.d.mts",
|
|
72
|
+
"import": "./dist/appearance-provider.mjs"
|
|
73
73
|
},
|
|
74
|
-
"./
|
|
75
|
-
"source": "./src/
|
|
76
|
-
"types": "./dist/
|
|
77
|
-
"import": "./dist/
|
|
74
|
+
"./appearance-script": {
|
|
75
|
+
"source": "./src/appearance-script.tsx",
|
|
76
|
+
"types": "./dist/appearance-script.d.mts",
|
|
77
|
+
"import": "./dist/appearance-script.mjs"
|
|
78
78
|
},
|
|
79
|
-
"./
|
|
80
|
-
"source": "./src/
|
|
81
|
-
"types": "./dist/
|
|
82
|
-
"import": "./dist/
|
|
79
|
+
"./color-scheme": {
|
|
80
|
+
"source": "./src/color-scheme.ts",
|
|
81
|
+
"types": "./dist/color-scheme.d.mts",
|
|
82
|
+
"import": "./dist/color-scheme.mjs"
|
|
83
83
|
},
|
|
84
|
-
"./
|
|
85
|
-
"source": "./src/
|
|
86
|
-
"types": "./dist/
|
|
87
|
-
"import": "./dist/
|
|
88
|
-
},
|
|
89
|
-
"./start": {
|
|
90
|
-
"source": "./src/start.ts",
|
|
91
|
-
"types": "./dist/start.d.mts",
|
|
92
|
-
"import": "./dist/start.mjs"
|
|
93
|
-
},
|
|
94
|
-
"./types": {
|
|
95
|
-
"source": "./src/types.ts",
|
|
96
|
-
"types": "./dist/types.d.mts",
|
|
97
|
-
"import": "./dist/types.mjs"
|
|
98
|
-
},
|
|
99
|
-
"./utils/dom": {
|
|
100
|
-
"source": "./src/utils/dom.ts",
|
|
101
|
-
"types": "./dist/utils/dom.d.mts",
|
|
102
|
-
"import": "./dist/utils/dom.mjs"
|
|
84
|
+
"./constants": {
|
|
85
|
+
"source": "./src/constants.ts",
|
|
86
|
+
"types": "./dist/constants.d.mts",
|
|
87
|
+
"import": "./dist/constants.mjs"
|
|
103
88
|
},
|
|
104
|
-
"./
|
|
105
|
-
"source": "./src/
|
|
106
|
-
"types": "./dist/
|
|
107
|
-
"import": "./dist/
|
|
89
|
+
"./dom": {
|
|
90
|
+
"source": "./src/dom.ts",
|
|
91
|
+
"types": "./dist/dom.d.mts",
|
|
92
|
+
"import": "./dist/dom.mjs"
|
|
108
93
|
},
|
|
109
|
-
"./
|
|
110
|
-
"source": "./src/
|
|
111
|
-
"types": "./dist/
|
|
112
|
-
"import": "./dist/
|
|
94
|
+
"./use-appearance": {
|
|
95
|
+
"source": "./src/use-appearance.ts",
|
|
96
|
+
"types": "./dist/use-appearance.d.mts",
|
|
97
|
+
"import": "./dist/use-appearance.mjs"
|
|
113
98
|
},
|
|
114
99
|
"./package.json": "./package.json"
|
|
115
100
|
},
|
|
@@ -120,42 +105,33 @@
|
|
|
120
105
|
"zod": "^4.4.3"
|
|
121
106
|
},
|
|
122
107
|
"devDependencies": {
|
|
123
|
-
"@tanstack/react-start": "^1.168.26",
|
|
124
108
|
"@testing-library/dom": "^10.4.1",
|
|
125
109
|
"@testing-library/jest-dom": "^6.9.1",
|
|
126
110
|
"@testing-library/react": "^16.3.2",
|
|
127
111
|
"@testing-library/user-event": "^14.6.1",
|
|
128
|
-
"@types/node": "^26.0
|
|
129
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
112
|
+
"@types/node": "^26.1.0",
|
|
113
|
+
"@typescript/native-preview": "7.0.0-dev.20260702.3",
|
|
130
114
|
"@vitejs/plugin-react": "^6.0.3",
|
|
131
115
|
"@vitest/coverage-v8": "^4.1.9",
|
|
132
116
|
"jsdom": "^29.1.1",
|
|
133
117
|
"tsdown": "^0.22.3",
|
|
134
118
|
"typescript": "^6.0.3",
|
|
135
|
-
"vite": "^8.1.
|
|
119
|
+
"vite": "^8.1.3",
|
|
136
120
|
"vitest": "^4.1.9",
|
|
137
|
-
"@codefast/typescript-config": "0.5.0-canary.
|
|
121
|
+
"@codefast/typescript-config": "0.5.0-canary.2"
|
|
138
122
|
},
|
|
139
123
|
"peerDependencies": {
|
|
140
|
-
"@tanstack/react-start": ">=1.168.0",
|
|
141
124
|
"@types/react": ">=19.0.0",
|
|
142
125
|
"@types/react-dom": ">=19.0.0",
|
|
143
126
|
"react": ">=19.0.0",
|
|
144
|
-
"react-dom": ">=19.0.0"
|
|
145
|
-
"vite": ">=6.0.0"
|
|
127
|
+
"react-dom": ">=19.0.0"
|
|
146
128
|
},
|
|
147
129
|
"peerDependenciesMeta": {
|
|
148
|
-
"@tanstack/react-start": {
|
|
149
|
-
"optional": true
|
|
150
|
-
},
|
|
151
130
|
"@types/react": {
|
|
152
131
|
"optional": true
|
|
153
132
|
},
|
|
154
133
|
"@types/react-dom": {
|
|
155
134
|
"optional": true
|
|
156
|
-
},
|
|
157
|
-
"vite": {
|
|
158
|
-
"optional": true
|
|
159
135
|
}
|
|
160
136
|
},
|
|
161
137
|
"engines": {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
|
|
3
|
+
import type { AppearanceContextType } from "#/appearance";
|
|
4
|
+
|
|
5
|
+
/* -----------------------------------------------------------------------------
|
|
6
|
+
* Context
|
|
7
|
+
* -------------------------------------------------------------------------- */
|
|
8
|
+
|
|
9
|
+
type AppearanceContextValue = null | AppearanceContextType;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React context for appearance state management.
|
|
13
|
+
*
|
|
14
|
+
* Provides access to the current appearance, resolved color scheme, setter function, and pending state.
|
|
15
|
+
* Use {@link useAppearance} hook instead of consuming this context directly.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link AppearanceProvider} - Provider component
|
|
18
|
+
* @see {@link useAppearance} - Consumer hook
|
|
19
|
+
*
|
|
20
|
+
* @since 0.5.0-canary.2
|
|
21
|
+
*/
|
|
22
|
+
export const AppearanceContext = createContext<AppearanceContextValue>(null);
|