singularity-core 0.15.3 → 0.17.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.
- package/README.md +1 -70
- package/dist/images/index.d.ts +8 -0
- package/dist/images/index.js +19 -0
- package/dist/router/react.d.ts +1 -0
- package/dist/router/react.js +1 -0
- package/dist/router/view-transition.d.ts +13 -0
- package/dist/router/view-transition.js +11 -0
- package/dist/theme/index.d.ts +11 -0
- package/dist/theme/index.js +15 -0
- package/dist/theme/react.d.ts +27 -2
- package/dist/theme/react.js +27 -4
- package/dist/theme/server.d.ts +12 -0
- package/dist/theme/server.js +24 -6
- package/package.json +156 -153
package/README.md
CHANGED
|
@@ -15,73 +15,4 @@ export const { login, logout, getValidSession, hasUserPermission } =
|
|
|
15
15
|
createCookieSession({ client: fetchAuthServerClient, cookiePrefix: "filion" });
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
See [AGENTS.md](./AGENTS.md) for the subpaths and the rules for adding code.
|
|
19
|
-
|
|
20
|
-
## TODO
|
|
21
|
-
|
|
22
|
-
Fix on `main` and release as 0.9.0 (the `feature/fragments` tarballs already use
|
|
23
|
-
up to 0.8.7), then rebase `feature/fragments`.
|
|
24
|
-
|
|
25
|
-
### High value
|
|
26
|
-
|
|
27
|
-
- [x] Logout can end the user's sessions on every device. `endApiSession`
|
|
28
|
-
(`src/auth/server.ts:156`) sends `refreshToken: null` when the refresh cookie
|
|
29
|
-
is missing, and `?? refreshToken` (`:241`) keeps an `EMPTY_GUID` from a
|
|
30
|
-
refresh. Treat `EMPTY_GUID` as no token everywhere and skip the API logout
|
|
31
|
-
when there is no real refresh token.
|
|
32
|
-
- [x] Temporary API errors sign users out. A refresh that returns 429 or 5xx
|
|
33
|
-
clears the cookies (`src/auth/server.ts:232-235`), and the `catch` (`:243`)
|
|
34
|
-
returns null even while the access token is still valid. Clear only on
|
|
35
|
-
400/401/403 and keep the current token while `secondsUntilExpiry > 0`. Add
|
|
36
|
-
tests for both.
|
|
37
|
-
- [x] Cookie roles are decoded, not verified (`src/auth/server.ts:70-93`). Keep it
|
|
38
|
-
decode-only, but document here and in `docs/projects/core.md` that roles are
|
|
39
|
-
a UI hint and the API is the real gate. Audit that every admin and blog
|
|
40
|
-
server function behind `requirePermission` calls the API with the bearer
|
|
41
|
-
token.
|
|
42
|
-
- [x] CSP (`src/security/index.ts:59-76`) lacks `base-uri 'self'`,
|
|
43
|
-
`object-src 'none'` and `form-action 'self'`. Widen `CspDirective` to allow
|
|
44
|
-
`frame-src` and `worker-src`. In the dev policy, browsers ignore
|
|
45
|
-
`'unsafe-inline'` next to a nonce or `'strict-dynamic'`.
|
|
46
|
-
- [x] `useListSearch` (`src/paging/react.ts:14-26`) reapplies the old text after
|
|
47
|
-
Back or a link clears the search. Re-sync `text` when `current` changes from
|
|
48
|
-
outside (track the last applied value in a ref).
|
|
49
|
-
- [x] `build` doesn't clean `dist/`, so `dist/fragments` from the other branch
|
|
50
|
-
would ship in the next pack. Delete `dist` before `tsc`.
|
|
51
|
-
- [x] `formatDate` (`src/format/index.ts:1-14`) uses local getters, so server
|
|
52
|
-
(UTC) and browser (Stockholm) disagree near midnight, and invalid input gives
|
|
53
|
-
`NaN-NaN-NaN`. Use `Intl.DateTimeFormat` with a `timeZone` and return `""`
|
|
54
|
-
for invalid dates.
|
|
55
|
-
|
|
56
|
-
### Nice to have
|
|
57
|
-
|
|
58
|
-
- [x] `formatTimeSpan` drops days (`src/format/index.ts:32-34`), and the "days
|
|
59
|
-
included" test expects the wrong value.
|
|
60
|
-
- [x] The theme client hint `Sec-CH-Prefers-Color-Scheme` (`src/theme/server.ts:22`)
|
|
61
|
-
is never requested with `Accept-CH`. The server renders "system" as light
|
|
62
|
-
while `ThemeProvider` treats it as dark before mount
|
|
63
|
-
(`src/theme/react.tsx:89`). Make the two defaults agree.
|
|
64
|
-
- [x] `ThemeProvider` reads and writes `localStorage` without a guard
|
|
65
|
-
(`src/theme/react.tsx:98,128`). `buildThemeBootstrapScript`
|
|
66
|
-
(`src/theme/index.ts:63`) puts keys into a JS string and a RegExp unescaped;
|
|
67
|
-
use `JSON.stringify` and escape the regex.
|
|
68
|
-
- [x] `proxyEventStream` (`src/api/server.ts:89-94`) doesn't catch a failed fetch.
|
|
69
|
-
Return 502 with `failureMessage`.
|
|
70
|
-
- [x] Small fixes: `pageSearchSchema` throws on `?page=abc` (add
|
|
71
|
-
`.catch(undefined)`); `parsePage` accepts `take: 0` (use
|
|
72
|
-
`.int().positive()`); `na` returns one shared fallback array; `IMAGE_WIDTHS`
|
|
73
|
-
is mutable; `new URL(src)` throws on relative `/i/` URLs
|
|
74
|
-
(`src/images/index.ts:57,82`); `slugify` drops ø/æ/ß/ł.
|
|
75
|
-
- [x] `getValidSession` isn't cached per request, so beforeLoad, middleware and a
|
|
76
|
-
loader can each refresh. Make cookie `secure` an option instead of reading
|
|
77
|
-
`NODE_ENV`.
|
|
78
|
-
- [x] `engines` pins Node 25, which reached end of life in June 2026. Allow 24 LTS
|
|
79
|
-
and 26.
|
|
80
|
-
- [x] Add `.gitattributes` (`* text=auto eol=lf`). CRLF in `package.json` is why
|
|
81
|
-
`biome check` fails.
|
|
82
|
-
- [x] Add a `check` script that only reports and a `verify` script (typecheck,
|
|
83
|
-
check, test). Add `"./package.json"` to `exports`.
|
|
84
|
-
- [x] No tests for `http` or `router/react`.
|
|
85
|
-
- [x] Docs drift: `AGENTS.md` mentions `pnpm openapi-types`, which isn't in
|
|
86
|
-
`package.json`; it describes both tarballs and publishing without saying
|
|
87
|
-
which is current. This README names 5 of the 13 areas.
|
|
18
|
+
See [AGENTS.md](./AGENTS.md) for the subpaths and the rules for adding code. Open fixes are in [IMPROVEMENTS.md](./IMPROVEMENTS.md). What each version contains is in [RELEASE_NOTES.md](./RELEASE_NOTES.md).
|
package/dist/images/index.d.ts
CHANGED
|
@@ -30,6 +30,14 @@ export declare function filionTransformer(src: string | URL, operations: {
|
|
|
30
30
|
* constrained one only those up to twice its display width.
|
|
31
31
|
*/
|
|
32
32
|
export declare function getImageBreakpoints(width: number | undefined, layout: string): number[];
|
|
33
|
+
/**
|
|
34
|
+
* Starts loading a full-width Filion image, so the page about to show it finds
|
|
35
|
+
* it ready. The srcset and sizes are those of a `fullWidth` image, which makes
|
|
36
|
+
* the browser pick the same file. Resolves once the image is decoded, when it
|
|
37
|
+
* fails, or after `timeoutMs`, whichever comes first. Does nothing on the
|
|
38
|
+
* server or for any other URL.
|
|
39
|
+
*/
|
|
40
|
+
export declare function preloadFullWidthImage(src: string, timeoutMs?: number): Promise<void>;
|
|
33
41
|
/** A focal point as fractions of the image, 0..1 from the top left. */
|
|
34
42
|
export type ImageFocus = {
|
|
35
43
|
x: number;
|
package/dist/images/index.js
CHANGED
|
@@ -94,6 +94,25 @@ export function getImageBreakpoints(width, layout) {
|
|
|
94
94
|
const max = snapWidth(width * 2);
|
|
95
95
|
return IMAGE_WIDTHS.filter((candidate) => candidate <= max);
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Starts loading a full-width Filion image, so the page about to show it finds
|
|
99
|
+
* it ready. The srcset and sizes are those of a `fullWidth` image, which makes
|
|
100
|
+
* the browser pick the same file. Resolves once the image is decoded, when it
|
|
101
|
+
* fails, or after `timeoutMs`, whichever comes first. Does nothing on the
|
|
102
|
+
* server or for any other URL.
|
|
103
|
+
*/
|
|
104
|
+
export async function preloadFullWidthImage(src, timeoutMs = 300) {
|
|
105
|
+
if (typeof document === "undefined" || !isFilionImage(src))
|
|
106
|
+
return;
|
|
107
|
+
const image = new Image();
|
|
108
|
+
image.sizes = "100vw";
|
|
109
|
+
image.srcset = IMAGE_WIDTHS.map((width) => `${withImageSize(src, width)} ${width}w`).join(", ");
|
|
110
|
+
image.src = src;
|
|
111
|
+
await Promise.race([
|
|
112
|
+
image.decode().catch(() => undefined),
|
|
113
|
+
new Promise((resolve) => setTimeout(resolve, timeoutMs)),
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
97
116
|
/** Converts a normalized focal point to a CSS object-position value. */
|
|
98
117
|
export function getObjectPosition(focus) {
|
|
99
118
|
return `${focus.x * 100}% ${focus.y * 100}%`;
|
package/dist/router/react.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type StaticDataRouteOption } from "@tanstack/react-router";
|
|
2
|
+
export { pageViewTransition } from "./view-transition.js";
|
|
2
3
|
/**
|
|
3
4
|
* `staticData[key]` of the deepest matched route that sets it, so a layout
|
|
4
5
|
* route can act on what the page under it declares. The apps use it for the
|
package/dist/router/react.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMatches } from "@tanstack/react-router";
|
|
2
2
|
import { deepestStaticData } from "./static-data.js";
|
|
3
|
+
export { pageViewTransition } from "./view-transition.js";
|
|
3
4
|
/**
|
|
4
5
|
* `staticData[key]` of the deepest matched route that sets it, so a layout
|
|
5
6
|
* route can act on what the page under it declares. The apps use it for the
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The apps' `defaultViewTransition`: a change of path animates, a change of
|
|
3
|
+
* only the search or hash does not, so filters, search and paging stay still.
|
|
4
|
+
* The router default also covers back and forward, which a `Link` prop cannot.
|
|
5
|
+
*
|
|
6
|
+
* A browser that has `startViewTransition` but no transition types never
|
|
7
|
+
* calls `types`, so there a filter change fades too.
|
|
8
|
+
*/
|
|
9
|
+
export declare const pageViewTransition: {
|
|
10
|
+
types: ({ pathChanged }: {
|
|
11
|
+
pathChanged: boolean;
|
|
12
|
+
}) => string[] | false;
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The apps' `defaultViewTransition`: a change of path animates, a change of
|
|
3
|
+
* only the search or hash does not, so filters, search and paging stay still.
|
|
4
|
+
* The router default also covers back and forward, which a `Link` prop cannot.
|
|
5
|
+
*
|
|
6
|
+
* A browser that has `startViewTransition` but no transition types never
|
|
7
|
+
* calls `types`, so there a filter change fades too.
|
|
8
|
+
*/
|
|
9
|
+
export const pageViewTransition = {
|
|
10
|
+
types: ({ pathChanged }) => pathChanged ? [] : false,
|
|
11
|
+
};
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -41,6 +41,17 @@ export declare function themeNeedsClientBootstrap(theme: Theme): boolean;
|
|
|
41
41
|
* Applies or removes the `dark` class on `document.documentElement`.
|
|
42
42
|
*/
|
|
43
43
|
export declare function applyDarkClass(isDark: boolean): void;
|
|
44
|
+
/**
|
|
45
|
+
* The named theme to show: `raw` when it is one of `names`, else `fallback`.
|
|
46
|
+
* A named theme is a whole look, picked with `data-theme` on `<html>`, and
|
|
47
|
+
* each has a light and a dark mode; it is not the `Theme` preference above.
|
|
48
|
+
* The names belong to the app's UI library, so the app passes them in.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveThemeName<TName extends string>(raw: string | null | undefined, names: readonly TName[], fallback: TName): TName;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the named theme on `document.documentElement` as `data-theme`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function applyThemeName(themeName: string): void;
|
|
44
55
|
/**
|
|
45
56
|
* Inline script for first paint when preference is `system` (or legacy localStorage-only).
|
|
46
57
|
* `storageKey` is both the localStorage key and the cookie name unless
|
package/dist/theme/index.js
CHANGED
|
@@ -54,6 +54,21 @@ export function applyDarkClass(isDark) {
|
|
|
54
54
|
root.classList.remove("dark");
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The named theme to show: `raw` when it is one of `names`, else `fallback`.
|
|
59
|
+
* A named theme is a whole look, picked with `data-theme` on `<html>`, and
|
|
60
|
+
* each has a light and a dark mode; it is not the `Theme` preference above.
|
|
61
|
+
* The names belong to the app's UI library, so the app passes them in.
|
|
62
|
+
*/
|
|
63
|
+
export function resolveThemeName(raw, names, fallback) {
|
|
64
|
+
return names.find((name) => name === raw) ?? fallback;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Sets the named theme on `document.documentElement` as `data-theme`.
|
|
68
|
+
*/
|
|
69
|
+
export function applyThemeName(themeName) {
|
|
70
|
+
document.documentElement.dataset.theme = themeName;
|
|
71
|
+
}
|
|
57
72
|
/**
|
|
58
73
|
* A JS string literal for an inline `<script>`: JSON-quoted, with `<`
|
|
59
74
|
* escaped so the text can never close the script tag.
|
package/dist/theme/react.d.ts
CHANGED
|
@@ -14,6 +14,19 @@ type ThemeProviderProps = {
|
|
|
14
14
|
/** Saves the preference for SSR, normally a server function setting the cookie. */
|
|
15
15
|
persistTheme: (theme: Theme) => unknown;
|
|
16
16
|
onResolvedIsDarkChange?: (isDark: boolean) => void;
|
|
17
|
+
/**
|
|
18
|
+
* The named themes a visitor may pick from, for an app with a theme
|
|
19
|
+
* picker. A named theme is a whole look (`data-theme` on `<html>`), each
|
|
20
|
+
* with a light and a dark mode. Leave out for an app with one fixed theme.
|
|
21
|
+
*/
|
|
22
|
+
themeNames?: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* The named theme the server rendered on `<html>`, from `getThemeName`.
|
|
25
|
+
* Pass it with `themeNames`.
|
|
26
|
+
*/
|
|
27
|
+
initialThemeName?: string;
|
|
28
|
+
/** Saves the named theme for SSR, normally a server function setting the cookie. */
|
|
29
|
+
persistThemeName?: (themeName: string) => unknown;
|
|
17
30
|
};
|
|
18
31
|
type ThemeProviderState = {
|
|
19
32
|
/** The preference: light, dark or system. */
|
|
@@ -30,13 +43,25 @@ type ThemeProviderState = {
|
|
|
30
43
|
resolvedTheme: "light" | "dark";
|
|
31
44
|
/** False on the server and the first client render, so their markup matches. */
|
|
32
45
|
mounted: boolean;
|
|
46
|
+
/** The named themes a visitor may pick from. Empty when the app has one fixed theme. */
|
|
47
|
+
themeNames: readonly string[];
|
|
48
|
+
/** The named theme shown. Undefined when the app offers none. */
|
|
49
|
+
themeName: string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Shows a named theme (`data-theme` on `<html>`) and saves it with
|
|
52
|
+
* `persistThemeName`. A name that is not in `themeNames` is ignored.
|
|
53
|
+
*/
|
|
54
|
+
setThemeName: (themeName: string) => void;
|
|
33
55
|
};
|
|
34
56
|
/**
|
|
35
57
|
* Manages theme preference (localStorage + cookie) and syncs the `dark` class on `<html>`.
|
|
58
|
+
* With `themeNames` it also holds the named theme a visitor picked and sets
|
|
59
|
+
* it as `data-theme` on `<html>`.
|
|
36
60
|
*/
|
|
37
|
-
export declare function ThemeProvider({ children, initialTheme, initialIsDark, storageKey, persistTheme, onResolvedIsDarkChange, }: ThemeProviderProps): React.JSX.Element;
|
|
61
|
+
export declare function ThemeProvider({ children, initialTheme, initialIsDark, storageKey, persistTheme, onResolvedIsDarkChange, themeNames, initialThemeName, persistThemeName, }: ThemeProviderProps): React.JSX.Element;
|
|
38
62
|
/**
|
|
39
|
-
* Hook to access the theme preference, the theme shown, and the setters
|
|
63
|
+
* Hook to access the theme preference, the theme shown, and the setters,
|
|
64
|
+
* plus the named theme and its setter when the app offers a picker.
|
|
40
65
|
*/
|
|
41
66
|
export declare const useTheme: () => ThemeProviderState;
|
|
42
67
|
export {};
|
package/dist/theme/react.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { applyDarkClass, resolveIsDark, SYSTEM_DARK_WHEN_UNKNOWN, ThemeSchema, } from "./index.js";
|
|
3
|
+
import { applyDarkClass, applyThemeName, resolveIsDark, SYSTEM_DARK_WHEN_UNKNOWN, ThemeSchema, } from "./index.js";
|
|
4
|
+
/** One array for "no named themes", so the context value keeps its identity. */
|
|
5
|
+
const NO_THEME_NAMES = [];
|
|
4
6
|
const initialState = {
|
|
5
7
|
theme: "system",
|
|
6
8
|
setTheme: () => null,
|
|
7
9
|
toggleTheme: () => null,
|
|
8
10
|
resolvedTheme: SYSTEM_DARK_WHEN_UNKNOWN ? "dark" : "light",
|
|
9
11
|
mounted: false,
|
|
12
|
+
themeNames: NO_THEME_NAMES,
|
|
13
|
+
themeName: undefined,
|
|
14
|
+
setThemeName: () => null,
|
|
10
15
|
};
|
|
11
16
|
/**
|
|
12
17
|
* One context for every copy of this module. TanStack Start bundles this
|
|
@@ -51,9 +56,14 @@ function storeTheme(storageKey, theme) {
|
|
|
51
56
|
}
|
|
52
57
|
/**
|
|
53
58
|
* Manages theme preference (localStorage + cookie) and syncs the `dark` class on `<html>`.
|
|
59
|
+
* With `themeNames` it also holds the named theme a visitor picked and sets
|
|
60
|
+
* it as `data-theme` on `<html>`.
|
|
54
61
|
*/
|
|
55
|
-
export function ThemeProvider({ children, initialTheme, initialIsDark = SYSTEM_DARK_WHEN_UNKNOWN, storageKey, persistTheme, onResolvedIsDarkChange, }) {
|
|
62
|
+
export function ThemeProvider({ children, initialTheme, initialIsDark = SYSTEM_DARK_WHEN_UNKNOWN, storageKey, persistTheme, onResolvedIsDarkChange, themeNames = NO_THEME_NAMES, initialThemeName, persistThemeName, }) {
|
|
56
63
|
const [theme, setThemeState] = React.useState(initialTheme);
|
|
64
|
+
// The server rendered the first one on <html>; after that `setThemeName`
|
|
65
|
+
// sets the attribute itself.
|
|
66
|
+
const [themeName, setThemeNameState] = React.useState(initialThemeName);
|
|
57
67
|
// The OS preference; undefined until mounted.
|
|
58
68
|
const [systemPrefersDark, setSystemPrefersDark] = React.useState(undefined);
|
|
59
69
|
const mounted = systemPrefersDark !== undefined;
|
|
@@ -63,6 +73,8 @@ export function ThemeProvider({ children, initialTheme, initialIsDark = SYSTEM_D
|
|
|
63
73
|
persistRef.current = persistTheme;
|
|
64
74
|
const onResolvedIsDarkChangeRef = React.useRef(onResolvedIsDarkChange);
|
|
65
75
|
onResolvedIsDarkChangeRef.current = onResolvedIsDarkChange;
|
|
76
|
+
const persistThemeNameRef = React.useRef(persistThemeName);
|
|
77
|
+
persistThemeNameRef.current = persistThemeName;
|
|
66
78
|
React.useEffect(() => {
|
|
67
79
|
const storedTheme = readStoredTheme(storageKey);
|
|
68
80
|
if (!storedTheme) {
|
|
@@ -102,11 +114,22 @@ export function ThemeProvider({ children, initialTheme, initialIsDark = SYSTEM_D
|
|
|
102
114
|
toggleTheme: () => setTheme(resolveIsDark(theme, getSystemPrefersDark()) ? "light" : "dark"),
|
|
103
115
|
resolvedTheme: isDark ? "dark" : "light",
|
|
104
116
|
mounted,
|
|
117
|
+
themeNames,
|
|
118
|
+
themeName,
|
|
119
|
+
setThemeName: (newThemeName) => {
|
|
120
|
+
if (!themeNames.includes(newThemeName)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
applyThemeName(newThemeName);
|
|
124
|
+
void persistThemeNameRef.current?.(newThemeName);
|
|
125
|
+
setThemeNameState(newThemeName);
|
|
126
|
+
},
|
|
105
127
|
};
|
|
106
|
-
}, [theme, storageKey, isDark, mounted]);
|
|
128
|
+
}, [theme, storageKey, isDark, mounted, themeNames, themeName]);
|
|
107
129
|
return (_jsx(ThemeProviderContext.Provider, { value: value, children: children }));
|
|
108
130
|
}
|
|
109
131
|
/**
|
|
110
|
-
* Hook to access the theme preference, the theme shown, and the setters
|
|
132
|
+
* Hook to access the theme preference, the theme shown, and the setters,
|
|
133
|
+
* plus the named theme and its setter when the app offers a picker.
|
|
111
134
|
*/
|
|
112
135
|
export const useTheme = () => React.useContext(ThemeProviderContext);
|
package/dist/theme/server.d.ts
CHANGED
|
@@ -10,3 +10,15 @@ export declare function getThemeContext(cookieName: string): ThemeContext;
|
|
|
10
10
|
* Persists theme preference in an HTTP cookie for SSR on the next request.
|
|
11
11
|
*/
|
|
12
12
|
export declare function setThemeCookie(cookieName: string, theme: Theme): void;
|
|
13
|
+
/**
|
|
14
|
+
* Reads the named theme a visitor picked from the `cookieName` cookie: its
|
|
15
|
+
* value when it is one of `names`, else `fallback`. The root route renders it
|
|
16
|
+
* as `data-theme` on `<html>`. The cookie is the only place it is kept, so
|
|
17
|
+
* the server always knows it and the page needs no first-paint script for it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getThemeName<TName extends string>(cookieName: string, names: readonly TName[], fallback: TName): TName;
|
|
20
|
+
/**
|
|
21
|
+
* Persists the named theme in an HTTP cookie for SSR on the next request.
|
|
22
|
+
* The app's server function checks the name against its own list first.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setThemeNameCookie(cookieName: string, themeName: string): void;
|
package/dist/theme/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCookie, getRequestHeader, setCookie, } from "@tanstack/react-start/server";
|
|
2
|
-
import { resolveIsDark, SYSTEM_DARK_WHEN_UNKNOWN, ThemeSchema, } from "./index.js";
|
|
2
|
+
import { resolveIsDark, resolveThemeName, SYSTEM_DARK_WHEN_UNKNOWN, ThemeSchema, } from "./index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Reads theme preference from the `cookieName` cookie and resolves dark mode
|
|
5
5
|
* for SSR. For a `system` preference it uses `Sec-CH-Prefers-Color-Scheme`,
|
|
@@ -19,13 +19,31 @@ export function getThemeContext(cookieName) {
|
|
|
19
19
|
const isDark = resolveIsDark(theme, prefersDark);
|
|
20
20
|
return { theme, isDark };
|
|
21
21
|
}
|
|
22
|
+
/** A year, for the whole site. Readable by script: the bootstrap script reads the preference. */
|
|
23
|
+
const THEME_COOKIE_OPTIONS = {
|
|
24
|
+
path: "/",
|
|
25
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
26
|
+
sameSite: "lax",
|
|
27
|
+
};
|
|
22
28
|
/**
|
|
23
29
|
* Persists theme preference in an HTTP cookie for SSR on the next request.
|
|
24
30
|
*/
|
|
25
31
|
export function setThemeCookie(cookieName, theme) {
|
|
26
|
-
setCookie(cookieName, theme,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
setCookie(cookieName, theme, THEME_COOKIE_OPTIONS);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reads the named theme a visitor picked from the `cookieName` cookie: its
|
|
36
|
+
* value when it is one of `names`, else `fallback`. The root route renders it
|
|
37
|
+
* as `data-theme` on `<html>`. The cookie is the only place it is kept, so
|
|
38
|
+
* the server always knows it and the page needs no first-paint script for it.
|
|
39
|
+
*/
|
|
40
|
+
export function getThemeName(cookieName, names, fallback) {
|
|
41
|
+
return resolveThemeName(getCookie(cookieName), names, fallback);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Persists the named theme in an HTTP cookie for SSR on the next request.
|
|
45
|
+
* The app's server function checks the name against its own list first.
|
|
46
|
+
*/
|
|
47
|
+
export function setThemeNameCookie(cookieName, themeName) {
|
|
48
|
+
setCookie(cookieName, themeName, THEME_COOKIE_OPTIONS);
|
|
31
49
|
}
|
package/package.json
CHANGED
|
@@ -1,154 +1,157 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
2
|
+
"name": "singularity-core",
|
|
3
|
+
"version": "0.17.1",
|
|
4
|
+
"description": "Shared non-UI code for Singularity TanStack Start apps: auth sessions, API client middleware, API schemas, paging, route data, images, formatting, HTTP helpers, theme, cookie notice, SEO, security headers and telemetry.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "Filip",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"config"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"./dist/security/zod-jitless.js"
|
|
14
|
+
],
|
|
15
|
+
"packageManager": "pnpm@12.3.4",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=26.0.0 <27.0.0",
|
|
18
|
+
"pnpm": ">=12.0.0 <13.0.0"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
"./auth": {
|
|
22
|
+
"types": "./dist/auth/index.d.ts",
|
|
23
|
+
"import": "./dist/auth/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./auth/server": {
|
|
26
|
+
"types": "./dist/auth/server.d.ts",
|
|
27
|
+
"import": "./dist/auth/server.js"
|
|
28
|
+
},
|
|
29
|
+
"./api": {
|
|
30
|
+
"types": "./dist/api/index.d.ts",
|
|
31
|
+
"import": "./dist/api/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./api/server": {
|
|
34
|
+
"types": "./dist/api/server.d.ts",
|
|
35
|
+
"import": "./dist/api/server.js"
|
|
36
|
+
},
|
|
37
|
+
"./paging": {
|
|
38
|
+
"types": "./dist/paging/index.d.ts",
|
|
39
|
+
"import": "./dist/paging/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./paging/react": {
|
|
42
|
+
"types": "./dist/paging/react.d.ts",
|
|
43
|
+
"import": "./dist/paging/react.js"
|
|
44
|
+
},
|
|
45
|
+
"./router/react": {
|
|
46
|
+
"types": "./dist/router/react.d.ts",
|
|
47
|
+
"import": "./dist/router/react.js"
|
|
48
|
+
},
|
|
49
|
+
"./cookie-notice/server": {
|
|
50
|
+
"types": "./dist/cookie-notice/server.d.ts",
|
|
51
|
+
"import": "./dist/cookie-notice/server.js"
|
|
52
|
+
},
|
|
53
|
+
"./theme": {
|
|
54
|
+
"types": "./dist/theme/index.d.ts",
|
|
55
|
+
"import": "./dist/theme/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./theme/server": {
|
|
58
|
+
"types": "./dist/theme/server.d.ts",
|
|
59
|
+
"import": "./dist/theme/server.js"
|
|
60
|
+
},
|
|
61
|
+
"./theme/react": {
|
|
62
|
+
"types": "./dist/theme/react.d.ts",
|
|
63
|
+
"import": "./dist/theme/react.js"
|
|
64
|
+
},
|
|
65
|
+
"./schema": {
|
|
66
|
+
"types": "./dist/schema/index.d.ts",
|
|
67
|
+
"import": "./dist/schema/index.js"
|
|
68
|
+
},
|
|
69
|
+
"./seo": {
|
|
70
|
+
"types": "./dist/seo/index.d.ts",
|
|
71
|
+
"import": "./dist/seo/index.js"
|
|
72
|
+
},
|
|
73
|
+
"./security": {
|
|
74
|
+
"types": "./dist/security/index.d.ts",
|
|
75
|
+
"import": "./dist/security/index.js"
|
|
76
|
+
},
|
|
77
|
+
"./security/zod-jitless": {
|
|
78
|
+
"types": "./dist/security/zod-jitless.d.ts",
|
|
79
|
+
"import": "./dist/security/zod-jitless.js"
|
|
80
|
+
},
|
|
81
|
+
"./telemetry": {
|
|
82
|
+
"types": "./dist/telemetry/index.d.ts",
|
|
83
|
+
"import": "./dist/telemetry/index.js"
|
|
84
|
+
},
|
|
85
|
+
"./images": {
|
|
86
|
+
"types": "./dist/images/index.d.ts",
|
|
87
|
+
"import": "./dist/images/index.js"
|
|
88
|
+
},
|
|
89
|
+
"./format": {
|
|
90
|
+
"types": "./dist/format/index.d.ts",
|
|
91
|
+
"import": "./dist/format/index.js"
|
|
92
|
+
},
|
|
93
|
+
"./http": {
|
|
94
|
+
"types": "./dist/http/index.d.ts",
|
|
95
|
+
"import": "./dist/http/index.js"
|
|
96
|
+
},
|
|
97
|
+
"./biome": "./config/biome-app.json",
|
|
98
|
+
"./package.json": "./package.json"
|
|
99
|
+
},
|
|
100
|
+
"scripts": {
|
|
101
|
+
"build": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
|
|
102
|
+
"typecheck": "tsc --noEmit",
|
|
103
|
+
"test": "vitest run",
|
|
104
|
+
"test:watch": "vitest",
|
|
105
|
+
"openapi-dev-types": "openapi-typescript http://localhost:5268/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
|
|
106
|
+
"openapi-types": "openapi-typescript https://api.filion.se/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
|
|
107
|
+
"prepack": "pnpm build",
|
|
108
|
+
"prepublishOnly": "pnpm verify",
|
|
109
|
+
"check": "biome check",
|
|
110
|
+
"verify": "pnpm run typecheck && pnpm run check && pnpm run test",
|
|
111
|
+
"biome:check": "biome check --write",
|
|
112
|
+
"biome:lint": "biome lint --fix",
|
|
113
|
+
"biome:format": "biome format --write"
|
|
114
|
+
},
|
|
115
|
+
"peerDependencies": {
|
|
116
|
+
"@tanstack/react-router": "^1.170.0",
|
|
117
|
+
"@tanstack/react-start": "^1.168.0",
|
|
118
|
+
"jose": "^6.0.0",
|
|
119
|
+
"openapi-fetch": "^0.17.0",
|
|
120
|
+
"react": "^19.0.0",
|
|
121
|
+
"zod": "^4.0.0"
|
|
122
|
+
},
|
|
123
|
+
"peerDependenciesMeta": {
|
|
124
|
+
"@tanstack/react-router": {
|
|
125
|
+
"optional": true
|
|
126
|
+
},
|
|
127
|
+
"@tanstack/react-start": {
|
|
128
|
+
"optional": true
|
|
129
|
+
},
|
|
130
|
+
"jose": {
|
|
131
|
+
"optional": true
|
|
132
|
+
},
|
|
133
|
+
"openapi-fetch": {
|
|
134
|
+
"optional": true
|
|
135
|
+
},
|
|
136
|
+
"react": {
|
|
137
|
+
"optional": true
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"devDependencies": {
|
|
141
|
+
"@biomejs/biome": "2.5.15",
|
|
142
|
+
"@tanstack/react-router": "1.170.46",
|
|
143
|
+
"@tanstack/react-start": "1.169.4",
|
|
144
|
+
"@types/node": "26.6.6",
|
|
145
|
+
"@types/react": "19.3.0",
|
|
146
|
+
"@types/react-dom": "19.3.0",
|
|
147
|
+
"happy-dom": "20.14.6",
|
|
148
|
+
"jose": "6.2.13",
|
|
149
|
+
"openapi-fetch": "0.17.0",
|
|
150
|
+
"openapi-typescript": "7.13.0",
|
|
151
|
+
"react": "19.3.1",
|
|
152
|
+
"react-dom": "19.3.1",
|
|
153
|
+
"typescript": "6.0.3",
|
|
154
|
+
"vitest": "5.0.5",
|
|
155
|
+
"zod": "4.6.7"
|
|
156
|
+
}
|
|
157
|
+
}
|