@sigx/lynx-daisyui 0.4.1 → 0.4.3

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.
@@ -0,0 +1,185 @@
1
+ // Shared status palette — identical across the original built-ins, hoisted to
2
+ // avoid repetition. (Themes are free to override any of these.)
3
+ const STATUS_LIGHT = {
4
+ 'info': '#00b4fa', 'info-content': '#000000',
5
+ 'success': '#00a96e', 'success-content': '#000000',
6
+ 'warning': '#ffc100', 'warning-content': '#000000',
7
+ 'error': '#ff676a', 'error-content': '#000000',
8
+ };
9
+ const registry = [
10
+ {
11
+ name: 'daisy-light', variant: 'light', pair: 'daisy-dark',
12
+ colors: {
13
+ 'primary': '#491dff', 'primary-content': '#d3dbff',
14
+ 'secondary': '#ff20cc', 'secondary-content': '#fff8fc',
15
+ 'accent': '#00cfbd', 'accent-content': '#00100d',
16
+ 'neutral': '#2b3440', 'neutral-content': '#d7dde4',
17
+ 'base-100': '#ffffff', 'base-200': '#f2f2f2', 'base-300': '#e5e6e6',
18
+ 'base-content': '#1f2937',
19
+ ...STATUS_LIGHT,
20
+ },
21
+ },
22
+ {
23
+ name: 'daisy-cupcake', variant: 'light', pair: 'daisy-synthwave',
24
+ colors: {
25
+ 'primary': '#65c3c8', 'primary-content': '#052124',
26
+ 'secondary': '#ef9fbc', 'secondary-content': '#2d0a16',
27
+ 'accent': '#eeaf3a', 'accent-content': '#2d1c00',
28
+ 'neutral': '#291334', 'neutral-content': '#f5f1f8',
29
+ 'base-100': '#faf7f5', 'base-200': '#efeae6', 'base-300': '#e7e2df',
30
+ 'base-content': '#291334',
31
+ ...STATUS_LIGHT,
32
+ },
33
+ },
34
+ {
35
+ name: 'daisy-emerald', variant: 'light', pair: 'daisy-dracula',
36
+ colors: {
37
+ 'primary': '#66cc8a', 'primary-content': '#06200f',
38
+ 'secondary': '#377cfb', 'secondary-content': '#02112d',
39
+ 'accent': '#f68067', 'accent-content': '#2d0a02',
40
+ 'neutral': '#333c4d', 'neutral-content': '#e9eaed',
41
+ 'base-100': '#ffffff', 'base-200': '#f3f4f6', 'base-300': '#e5e7eb',
42
+ 'base-content': '#333c4d',
43
+ 'info': '#1c92f2', 'info-content': '#000a14',
44
+ 'success': '#00a96e', 'success-content': '#000a05',
45
+ 'warning': '#ff9900', 'warning-content': '#261600',
46
+ 'error': '#ff5724', 'error-content': '#000000',
47
+ },
48
+ },
49
+ {
50
+ name: 'daisy-dark', variant: 'dark', pair: 'daisy-light',
51
+ colors: {
52
+ 'primary': '#7582ff', 'primary-content': '#050617',
53
+ 'secondary': '#ff71cf', 'secondary-content': '#190211',
54
+ 'accent': '#00e7d0', 'accent-content': '#001210',
55
+ 'neutral': '#2a323c', 'neutral-content': '#a6adbb',
56
+ 'base-100': '#1d232a', 'base-200': '#191e24', 'base-300': '#343b46',
57
+ 'base-content': '#a6adbb',
58
+ ...STATUS_LIGHT,
59
+ },
60
+ },
61
+ {
62
+ name: 'daisy-synthwave', variant: 'dark', pair: 'daisy-cupcake',
63
+ colors: {
64
+ 'primary': '#e779c1', 'primary-content': '#2a0a1f',
65
+ 'secondary': '#58c7f3', 'secondary-content': '#02141d',
66
+ 'accent': '#f3cc30', 'accent-content': '#2a1f00',
67
+ 'neutral': '#20134e', 'neutral-content': '#e3e0f5',
68
+ 'base-100': '#2d1b69', 'base-200': '#261159', 'base-300': '#1f0f4a',
69
+ 'base-content': '#f9f7fd',
70
+ 'info': '#53c0f3', 'info-content': '#02151e',
71
+ 'success': '#71ead2', 'success-content': '#002721',
72
+ 'warning': '#f3cc30', 'warning-content': '#2a1f00',
73
+ 'error': '#e24056', 'error-content': '#ffffff',
74
+ },
75
+ },
76
+ {
77
+ name: 'daisy-dracula', variant: 'dark', pair: 'daisy-emerald',
78
+ colors: {
79
+ 'primary': '#ff79c6', 'primary-content': '#2d0414',
80
+ 'secondary': '#bd93f9', 'secondary-content': '#160226',
81
+ 'accent': '#50fa7b', 'accent-content': '#002a0e',
82
+ 'neutral': '#414558', 'neutral-content': '#f8f8f2',
83
+ 'base-100': '#282a36', 'base-200': '#21222c', 'base-300': '#181920',
84
+ 'base-content': '#f8f8f2',
85
+ 'info': '#8be9fd', 'info-content': '#002a31',
86
+ 'success': '#50fa7b', 'success-content': '#002a0e',
87
+ 'warning': '#f1fa8c', 'warning-content': '#2a2900',
88
+ 'error': '#ff5555', 'error-content': '#2a0000',
89
+ },
90
+ },
91
+ ];
92
+ /**
93
+ * Resolve a `theme.name` to its registered `Theme`. Supports multi-class names
94
+ * like `'daisy-light daisy-rounded'` by matching the first registered id found.
95
+ */
96
+ function findTheme(name) {
97
+ if (!name)
98
+ return undefined;
99
+ for (const part of name.split(/\s+/)) {
100
+ const hit = registry.find((t) => t.name === part);
101
+ if (hit)
102
+ return hit;
103
+ }
104
+ return undefined;
105
+ }
106
+ /**
107
+ * All registered themes in insertion order. Returns a shallow copy so callers
108
+ * can't mutate the internal registry — re-registration goes through
109
+ * `registerTheme()`. Each entry is a full `Theme` (name, variant, palette),
110
+ * so consumers can render swatches in a picker.
111
+ */
112
+ export function listThemes() {
113
+ return registry.slice();
114
+ }
115
+ /**
116
+ * Register (or replace, by `name`) a theme. Call at module-load time before
117
+ * mounting `<ThemeProvider>` so it shows up in `listThemes()` / `pickThemeFor()`.
118
+ */
119
+ export function registerTheme(theme) {
120
+ const i = registry.findIndex((t) => t.name === theme.name);
121
+ if (i >= 0)
122
+ registry[i] = theme;
123
+ else
124
+ registry.push(theme);
125
+ }
126
+ /**
127
+ * Derive a new theme from a registered base, overriding any colors / roundness.
128
+ * Ergonomic for "tenant tweaks a few tokens": the result is a full `Theme` you
129
+ * pass to `registerTheme()`. Throws if `base` isn't registered.
130
+ *
131
+ * ```ts
132
+ * registerTheme(extendTheme('daisy-dark', {
133
+ * name: 'acme-dark',
134
+ * colors: { primary: '#fb7185' },
135
+ * }));
136
+ * ```
137
+ */
138
+ export function extendTheme(base, patch) {
139
+ const src = findTheme(base);
140
+ if (!src) {
141
+ throw new Error(`[lynx-daisyui] extendTheme: unknown base theme "${base}". `
142
+ + `Register it first, or extend a built-in (e.g. 'daisy-light').`);
143
+ }
144
+ return {
145
+ name: patch.name,
146
+ variant: patch.variant ?? src.variant,
147
+ pair: patch.pair ?? src.pair,
148
+ colors: { ...src.colors, ...patch.colors },
149
+ radius: patch.radius ?? src.radius,
150
+ };
151
+ }
152
+ /** The variant of a registered theme, or `undefined` if not registered. */
153
+ export function variantOf(name) {
154
+ return findTheme(name)?.variant;
155
+ }
156
+ /** The color palette of a registered theme, or `undefined` if not registered. */
157
+ export function colorsOf(name) {
158
+ return findTheme(name)?.colors;
159
+ }
160
+ /** The roundness overrides of a registered theme, if any. */
161
+ export function radiusOf(name) {
162
+ return findTheme(name)?.radius;
163
+ }
164
+ /**
165
+ * Pick a default theme for a given system color scheme — the first registered
166
+ * theme of that variant (`daisy-light` / `daisy-dark` under the seeded
167
+ * registry). Falls back to `'daisy-light'` if none of that variant exists.
168
+ */
169
+ export function pickThemeFor(scheme) {
170
+ const hit = registry.find((t) => t.variant === scheme);
171
+ return hit?.name ?? 'daisy-light';
172
+ }
173
+ /**
174
+ * Resolve the paired theme of a given name — used by `theme.toggle()`. Follows
175
+ * `pair` if set, otherwise the first theme of the opposite variant. Returns the
176
+ * input unchanged when the theme isn't registered.
177
+ */
178
+ export function pairOf(name) {
179
+ const hit = findTheme(name);
180
+ if (!hit)
181
+ return name;
182
+ if (hit.pair)
183
+ return hit.pair;
184
+ return pickThemeFor(hit.variant === 'light' ? 'dark' : 'light');
185
+ }
@@ -0,0 +1,28 @@
1
+ import type { DaisyTheme, ThemeController } from './ThemeProvider.js';
2
+ /** The mutable selection a `ThemeController` reads from and writes to. */
3
+ export interface ThemeState {
4
+ name: DaisyTheme;
5
+ following: boolean;
6
+ }
7
+ /**
8
+ * Build a `ThemeController` over a given state object. Used for both the global
9
+ * singleton (below) and each nested `<ThemeProvider>`'s local state — same
10
+ * behaviour, different backing store. `followSystem()` only flips the flag; the
11
+ * owning provider's follow effect performs the re-apply.
12
+ */
13
+ export declare function makeThemeController(state: ThemeState): ThemeController;
14
+ /**
15
+ * The backing signal for the global theme. Read/written by the root
16
+ * `<ThemeProvider>` and shared with `themeController`; not part of the public
17
+ * API.
18
+ * @internal
19
+ */
20
+ export declare const globalThemeState: import("@sigx/reactivity").Signal<ThemeState>;
21
+ /**
22
+ * The global theme controller — the headless handle for issue #113. Import and
23
+ * call from anywhere (no `<ThemeProvider>` ancestor required); `useTheme()`'s
24
+ * default factory returns this same instance, and the root `<ThemeProvider>`
25
+ * provides it to its subtree. `StatusBarSync` binds to it so the OS bars always
26
+ * follow the global/screen theme, never a content sub-scope.
27
+ */
28
+ export declare const themeController: ThemeController;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Global theme state — the headless DI singleton behind `useTheme()`.
3
+ *
4
+ * The active selection (current theme name + follow-system flag) lives here as
5
+ * a module-level signal, mirroring how `./registry.ts` is already a global
6
+ * module singleton. This is what makes theme control reachable from *headless*
7
+ * code — a store, a service, app-boot logic, an effect — not just from a
8
+ * component mounted under `<ThemeProvider>`.
9
+ *
10
+ * The root `<ThemeProvider>` (depth 0) binds to this state: it renders its host
11
+ * view from it, owns the system-color-scheme follow effect that writes to it
12
+ * while `following`, and seeds an `initial` prop into it. Nested providers
13
+ * (depth >= 1) build their own local state via `makeThemeController` so a
14
+ * subtree can be overridden without touching the global — see
15
+ * `./ThemeProvider.tsx`.
16
+ *
17
+ * `followSystem()` here only flips the flag; the actual re-apply on an OS color
18
+ * scheme change is driven by the root provider's follow effect (which has the
19
+ * appearance signal in scope).
20
+ */
21
+ import { signal } from '@sigx/lynx';
22
+ import { pairOf, pickThemeFor } from './registry.js';
23
+ /**
24
+ * Build a `ThemeController` over a given state object. Used for both the global
25
+ * singleton (below) and each nested `<ThemeProvider>`'s local state — same
26
+ * behaviour, different backing store. `followSystem()` only flips the flag; the
27
+ * owning provider's follow effect performs the re-apply.
28
+ */
29
+ export function makeThemeController(state) {
30
+ return {
31
+ get name() {
32
+ return state.name;
33
+ },
34
+ get followingSystem() {
35
+ return state.following;
36
+ },
37
+ set(next) {
38
+ state.name = next;
39
+ state.following = false;
40
+ },
41
+ toggle() {
42
+ state.name = pairOf(state.name);
43
+ state.following = false;
44
+ },
45
+ followSystem() {
46
+ state.following = true;
47
+ },
48
+ };
49
+ }
50
+ // Object signal (not primitive) so the `DaisyTheme` literal union survives —
51
+ // `signal<T>` widens primitive literals to plain `string` via `Widen<T>`.
52
+ // Seeded to a sane default; the root <ThemeProvider> re-seeds from the system
53
+ // color scheme + its props on mount.
54
+ const state = signal({
55
+ name: pickThemeFor('light'),
56
+ following: true,
57
+ });
58
+ /**
59
+ * The backing signal for the global theme. Read/written by the root
60
+ * `<ThemeProvider>` and shared with `themeController`; not part of the public
61
+ * API.
62
+ * @internal
63
+ */
64
+ export const globalThemeState = state;
65
+ /**
66
+ * The global theme controller — the headless handle for issue #113. Import and
67
+ * call from anywhere (no `<ThemeProvider>` ancestor required); `useTheme()`'s
68
+ * default factory returns this same instance, and the root `<ThemeProvider>`
69
+ * provides it to its subtree. `StatusBarSync` binds to it so the OS bars always
70
+ * follow the global/screen theme, never a content sub-scope.
71
+ */
72
+ export const themeController = makeThemeController(state);
@@ -0,0 +1,3 @@
1
+ import type { DaisyTheme } from './ThemeProvider.js';
2
+ /** Pin the global theme to `name` while this screen is focused; restore on blur. */
3
+ export declare function useScreenTheme(name: DaisyTheme): void;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * `useScreenTheme(name)` — pin the **global** daisy theme while a navigation
3
+ * screen is focused, restoring the previous selection when it blurs.
4
+ *
5
+ * This is the right tool for *per-screen* theming — "this screen is dark, that
6
+ * one is light." Because it drives the global theme (not a content sub-scope),
7
+ * the OS status/navigation bars follow automatically via `<StatusBarSync>`, so
8
+ * the bar icons stay legible against each screen's background. For recoloring a
9
+ * *region within* a screen without touching the bars, nest a `<ThemeProvider>`
10
+ * instead.
11
+ *
12
+ * Built on `useFocusEffect` from `@sigx/lynx-navigation` (an optional peer
13
+ * dependency): it must be called from inside a component rendered as a route by
14
+ * `<Stack>` / `<Tabs>` — the same constraint as `useFocusEffect`/`useIsFocused`.
15
+ *
16
+ * Save/restore composes with the stack (LIFO focus/blur): pushing a themed
17
+ * screen saves whatever was live, applies its own theme, and restores on pop —
18
+ * including resuming follow-system if that's what was active.
19
+ *
20
+ * ```tsx
21
+ * const Gallery = component(() => {
22
+ * useScreenTheme('daisy-dark'); // dark while this screen is on top
23
+ * return () => <view>…</view>;
24
+ * });
25
+ * ```
26
+ */
27
+ import { useFocusEffect } from '@sigx/lynx-navigation';
28
+ import { themeController } from './theme-state.js';
29
+ /** Pin the global theme to `name` while this screen is focused; restore on blur. */
30
+ export function useScreenTheme(name) {
31
+ useFocusEffect(() => {
32
+ const prevName = themeController.name;
33
+ const prevFollowing = themeController.followingSystem;
34
+ themeController.set(name);
35
+ return () => {
36
+ if (prevFollowing)
37
+ themeController.followSystem();
38
+ else
39
+ themeController.set(prevName);
40
+ };
41
+ });
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigx/lynx-daisyui",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "DaisyUI integration for sigx-lynx",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -37,12 +37,15 @@
37
37
  "LICENSE"
38
38
  ],
39
39
  "dependencies": {
40
- "@sigx/lynx": "^0.4.1",
41
- "@sigx/lynx-gestures": "^0.4.1"
40
+ "@sigx/lynx": "^0.4.3",
41
+ "@sigx/lynx-gestures": "^0.4.3",
42
+ "@sigx/lynx-icons": "^0.4.3",
43
+ "@sigx/lynx-appearance": "^0.4.3",
44
+ "@sigx/lynx-motion": "^0.4.3"
42
45
  },
43
46
  "peerDependencies": {
44
47
  "tailwindcss": "^3.0.0 || ^4.0.0",
45
- "@sigx/lynx-navigation": "^0.4.1"
48
+ "@sigx/lynx-navigation": "^0.4.3"
46
49
  },
47
50
  "peerDependenciesMeta": {
48
51
  "@sigx/lynx-navigation": {
@@ -50,10 +53,10 @@
50
53
  }
51
54
  },
52
55
  "devDependencies": {
53
- "@typescript/native-preview": "7.0.0-dev.20260511.1",
56
+ "@typescript/native-preview": "7.0.0-dev.20260521.1",
54
57
  "tailwindcss": "^4.0.0",
55
58
  "typescript": "^6.0.3",
56
- "@sigx/lynx-navigation": "^0.4.1"
59
+ "@sigx/lynx-navigation": "^0.4.3"
57
60
  },
58
61
  "publishConfig": {
59
62
  "access": "public"
@@ -1,95 +0,0 @@
1
- /* DaisyUI Light Theme — design tokens as CSS custom properties */
2
- /* Scoped under .daisy-light; CSS inheritance propagates to descendants */
3
-
4
- .daisy-light {
5
- /* Apply base colors to the theme root */
6
- background-color: #ffffff;
7
- color: #1f2937;
8
-
9
- /* Semantic colors */
10
- --color-primary: #491dff;
11
- --color-primary-content: #d3dbff;
12
- --color-secondary: #ff20cc;
13
- --color-secondary-content: #fff8fc;
14
- --color-accent: #00cfbd;
15
- --color-accent-content: #00100d;
16
- --color-neutral: #2b3440;
17
- --color-neutral-content: #d7dde4;
18
-
19
- /* Base colors */
20
- --color-base-100: #ffffff;
21
- --color-base-200: #f2f2f2;
22
- --color-base-300: #e5e6e6;
23
- --color-base-content: #1f2937;
24
-
25
- /* Status colors */
26
- --color-info: #00b4fa;
27
- --color-info-content: #000000;
28
- --color-success: #00a96e;
29
- --color-success-content: #000000;
30
- --color-warning: #ffc100;
31
- --color-warning-content: #000000;
32
- --color-error: #ff676a;
33
- --color-error-content: #000000;
34
-
35
- /* ── Roundness ── */
36
- --rounded-box: 16px;
37
- --rounded-btn: 8px;
38
- --rounded-badge: 9999px;
39
- --rounded-tab: 8px;
40
- --rounded-selector: 8px;
41
- --rounded-toggle: 9999px;
42
-
43
- /* ── Sizing scale ── */
44
- --size-xs: 24px;
45
- --size-sm: 32px;
46
- --size-md: 48px;
47
- --size-lg: 64px;
48
-
49
- /* ── Font sizes ── */
50
- --font-xs: 12px;
51
- --font-sm: 14px;
52
- --font-md: 14px;
53
- --font-lg: 18px;
54
-
55
- /* ── Spacing ── */
56
- --padding-btn-xs: 8px;
57
- --padding-btn-sm: 12px;
58
- --padding-btn-md: 16px;
59
- --padding-btn-lg: 24px;
60
- --padding-box: 16px;
61
- --padding-box-compact: 8px;
62
- --gap-box: 8px;
63
-
64
- /* ── Borders ── */
65
- --border-btn: 1px;
66
- --border-card: 1px;
67
-
68
- /* ── Component-specific sizes ── */
69
- --checkbox-xs: 16px;
70
- --checkbox-sm: 20px;
71
- --checkbox-md: 24px;
72
- --checkbox-lg: 32px;
73
- --toggle-width-xs: 32px;
74
- --toggle-width-sm: 40px;
75
- --toggle-width-md: 48px;
76
- --toggle-width-lg: 56px;
77
- --toggle-height-xs: 22px;
78
- --toggle-height-sm: 24px;
79
- --toggle-height-md: 28px;
80
- --toggle-height-lg: 32px;
81
- --toggle-thumb-xs: 14px;
82
- --toggle-thumb-sm: 16px;
83
- --toggle-thumb-md: 20px;
84
- --toggle-thumb-lg: 24px;
85
- --badge-xs: 16px;
86
- --badge-sm: 20px;
87
- --badge-md: 24px;
88
- --badge-lg: 32px;
89
- --step-indicator: 32px;
90
- --progress-height: 8px;
91
- --modal-max-width: 400px;
92
-
93
- /* ── Opacity ── */
94
- --disabled-opacity: 0.5;
95
- }