@k8ordo/color-scheme 1.4.0 → 1.4.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/README.md +1 -1
- package/dist/provider.d.mts +1 -3
- package/dist/provider.mjs +1 -2
- package/dist/scheme.d.mts +1 -3
- package/dist/scheme.mjs +1 -2
- package/docs/GUIDE.md +4 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ pnpm add @k8ordo/color-scheme @k8ordo/state zod
|
|
|
31
31
|
|
|
32
32
|
| Package | Version | Required | Needed for |
|
|
33
33
|
| --------------- | ------- | -------- | ------------------------------------------ |
|
|
34
|
-
| `@k8ordo/state` | ^1.4.
|
|
34
|
+
| `@k8ordo/state` | ^1.4.2 | yes | where the preference lives (localStorage) |
|
|
35
35
|
| `react` | ≥19.3.0 | yes | the provider and the hook |
|
|
36
36
|
| `zod` | ^4.6.6 | yes | the one-field schema `@k8ordo/state` reads |
|
|
37
37
|
| `typescript` | ≥7.0.0 | optional | the shipped type declarations |
|
package/dist/provider.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ColorScheme, ColorSchemePreference } from "./scheme.mjs";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
|
-
//#region src/provider.d.ts
|
|
4
3
|
export type UseColorScheme = {
|
|
5
4
|
/**
|
|
6
5
|
* What is on screen: the preference, the provider's default, or the
|
|
@@ -39,5 +38,4 @@ export type ColorSchemeProviderProps = {
|
|
|
39
38
|
*/
|
|
40
39
|
export declare function ColorSchemeProvider({ defaultPreference, nonce, children }: ColorSchemeProviderProps): ReactNode;
|
|
41
40
|
/** The visitor's colour scheme and a way to change it, from the provider above. */
|
|
42
|
-
export declare function useColorScheme(): UseColorScheme;
|
|
43
|
-
//#endregion
|
|
41
|
+
export declare function useColorScheme(): UseColorScheme;
|
package/dist/provider.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { DARK_CLASS, DARK_QUERY, colorSchemeState, resolve, scriptFor } from "./
|
|
|
3
3
|
import { useAppState } from "@k8ordo/state";
|
|
4
4
|
import { createContext, use, useCallback, useEffect, useMemo, useSyncExternalStore } from "react";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
|
|
6
|
+
// src/provider.tsx
|
|
7
7
|
const ColorSchemeContext = createContext(null);
|
|
8
8
|
const subscribeSystem = (onChange) => {
|
|
9
9
|
const query = matchMedia(DARK_QUERY);
|
|
@@ -57,5 +57,4 @@ function useColorScheme() {
|
|
|
57
57
|
if (value === null) throw new Error("useColorScheme needs <ColorSchemeProvider> above it — put one in the root layout, inside <body>");
|
|
58
58
|
return value;
|
|
59
59
|
}
|
|
60
|
-
//#endregion
|
|
61
60
|
export { ColorSchemeProvider, useColorScheme };
|
package/dist/scheme.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as z from "zod/mini";
|
|
2
|
-
//#region src/scheme.d.ts
|
|
3
2
|
export type ColorScheme = 'light' | 'dark';
|
|
4
3
|
/**
|
|
5
4
|
* A scheme, or `'system'`. As a visitor's preference, `'system'` is nothing
|
|
@@ -45,5 +44,4 @@ export declare const scriptFor: (defaultPreference: ColorSchemePreference) => st
|
|
|
45
44
|
* option, or a header that names no nonce. Give it the default the provider
|
|
46
45
|
* is given: the script carries it.
|
|
47
46
|
*/
|
|
48
|
-
export declare const colorSchemeScriptHash: (defaultPreference?: ColorSchemePreference) => Promise<string>;
|
|
49
|
-
//#endregion
|
|
47
|
+
export declare const colorSchemeScriptHash: (defaultPreference?: ColorSchemePreference) => Promise<string>;
|
package/dist/scheme.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineLocalState } from "@k8ordo/state";
|
|
2
2
|
import * as z from "zod/mini";
|
|
3
|
-
|
|
3
|
+
// src/scheme.ts
|
|
4
4
|
/**
|
|
5
5
|
* Where the preference lives: localStorage, under
|
|
6
6
|
* `k8ordo-state:color-scheme`. An absent `preference` is "nothing chosen",
|
|
@@ -40,5 +40,4 @@ const colorSchemeScriptHash = async (defaultPreference = "system") => {
|
|
|
40
40
|
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(scriptFor(defaultPreference)));
|
|
41
41
|
return `'sha256-${btoa(String.fromCodePoint(...new Uint8Array(digest)))}'`;
|
|
42
42
|
};
|
|
43
|
-
//#endregion
|
|
44
43
|
export { DARK_CLASS, DARK_QUERY, colorSchemeScriptHash, colorSchemeState, resolve, scriptFor };
|
package/docs/GUIDE.md
CHANGED
|
@@ -210,6 +210,10 @@ every visitor who never chose.
|
|
|
210
210
|
never reaches the tab that wrote, so a `localStorage.setItem` on the row
|
|
211
211
|
in the same tab goes unnoticed until a reload: change it through
|
|
212
212
|
`setPreference`.
|
|
213
|
+
- **Blocked storage still renders.** A browser that blocks site data cannot
|
|
214
|
+
store a choice. The script and the provider both apply
|
|
215
|
+
`defaultPreference`, and a scheme set with `setPreference` stays in memory
|
|
216
|
+
until the next load.
|
|
213
217
|
|
|
214
218
|
## Testing
|
|
215
219
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8ordo/color-scheme",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "The colour-scheme axis of an application, owned: the visitor's light / dark / system preference, kept in localStorage, resolved against the system, put on <html> before the first paint and kept there.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"color-scheme",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@arethetypeswrong/cli": "0.18.5",
|
|
42
|
-
"@k8ordo/state": "^1.4.
|
|
42
|
+
"@k8ordo/state": "^1.4.2",
|
|
43
43
|
"@types/react": "19.3.0",
|
|
44
44
|
"@types/react-dom": "19.3.0",
|
|
45
45
|
"@vitejs/plugin-react": "6.1.2",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"react": "19.3.1",
|
|
49
49
|
"react-dom": "19.3.1",
|
|
50
50
|
"typescript": "7.0.2",
|
|
51
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@1.
|
|
52
|
-
"vite-plus": "1.
|
|
51
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
52
|
+
"vite-plus": "1.4.0",
|
|
53
53
|
"vitest": "5.0.5",
|
|
54
54
|
"vitest-browser-react": "2.3.0",
|
|
55
55
|
"zod": "4.6.7"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@k8ordo/state": "^1.4.
|
|
58
|
+
"@k8ordo/state": "^1.4.2",
|
|
59
59
|
"@types/react": ">=19.3.0",
|
|
60
60
|
"react": ">=19.3.0",
|
|
61
61
|
"typescript": ">=7.0.0",
|