@molecule/app-theme-css-variables 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +203 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,203 @@
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-08-04T01:52:56.051Z
7
+ -->
8
+
9
+ # @molecule/app-theme-css-variables
10
+
11
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
+ > It is written to be read by coding agents as much as by people, and is generated from this
13
+ > package's source — edit `src/index.ts` JSDoc, not this file.
14
+
15
+ CSS custom properties theme provider for molecule.dev.
16
+
17
+ Provides a framework-agnostic ThemeProvider implementation that applies
18
+ theme tokens as CSS custom properties (variables) to the document root.
19
+ Works with any framework -- React, Vue, Svelte, Angular, Solid, or vanilla JS.
20
+
21
+ ## Quick Start
22
+
23
+ ```typescript
24
+ import {
25
+ createCSSVariablesThemeProvider,
26
+ lightTheme,
27
+ darkTheme,
28
+ } from '@molecule/app-theme-css-variables'
29
+ import { setProvider } from '@molecule/app-theme'
30
+
31
+ const provider = createCSSVariablesThemeProvider({
32
+ themes: [lightTheme, darkTheme],
33
+ defaultTheme: 'light',
34
+ persistKey: 'molecule-theme',
35
+ })
36
+
37
+ setProvider(provider)
38
+ ```
39
+
40
+ Then use CSS variables in your stylesheets:
41
+
42
+ ```css
43
+ .button {
44
+ background-color: var(--mol-color-primary);
45
+ color: var(--mol-color-text-inverse);
46
+ padding: var(--mol-spacing-sm) var(--mol-spacing-md);
47
+ border-radius: var(--mol-radius-md);
48
+ transition: background-color var(--mol-transition-fast);
49
+ }
50
+ ```
51
+
52
+ ## Type
53
+
54
+ `provider`
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ npm install @molecule/app-theme-css-variables @molecule/app-theme
60
+ ```
61
+
62
+ ## API
63
+
64
+ ### Interfaces
65
+
66
+ #### `CSSVariablesThemeConfig`
67
+
68
+ Configuration for css variables theme.
69
+
70
+ ```typescript
71
+ interface CSSVariablesThemeConfig {
72
+ /** Available themes. */
73
+ themes: Theme[]
74
+ /** Name of the default theme to use. */
75
+ defaultTheme?: string
76
+ /** CSS variable prefix (default: 'mol'). */
77
+ prefix?: string
78
+ /** Whether to auto-apply CSS variables to :root (default: true). */
79
+ applyToDocument?: boolean
80
+ /**
81
+ * Key for persisting the selected theme name across reloads. When `storage`
82
+ * is omitted, persistence falls back to `window.localStorage` in browser
83
+ * environments; in SSR / non-browser environments persistence is skipped.
84
+ */
85
+ persistKey?: string
86
+ /**
87
+ * Storage adapter for persisting theme preference. Optional — when omitted
88
+ * and `persistKey` is set, `window.localStorage` is used when available.
89
+ * Provide an adapter for React Native (AsyncStorage wrapper) or custom stores.
90
+ */
91
+ storage?: ThemeStorageAdapter
92
+ }
93
+ ```
94
+
95
+ #### `ThemeStorageAdapter`
96
+
97
+ Minimal storage adapter for theme persistence. Compatible with
98
+ localStorage, sessionStorage, or any custom implementation
99
+ (e.g., React Native AsyncStorage wrapper, SSR no-op).
100
+
101
+ ```typescript
102
+ interface ThemeStorageAdapter {
103
+ getItem(key: string): string | null
104
+ setItem(key: string, value: string): void
105
+ }
106
+ ```
107
+
108
+ ### Functions
109
+
110
+ #### `createCSSVariablesThemeProvider(config)`
111
+
112
+ Creates a framework-agnostic ThemeProvider that applies theme tokens
113
+ as CSS custom properties on the document root element.
114
+
115
+ ```typescript
116
+ function createCSSVariablesThemeProvider(config: CSSVariablesThemeConfig): ThemeProvider
117
+ ```
118
+
119
+ - `config` — Theme provider configuration (available themes, default theme, CSS variable prefix, persistence).
120
+
121
+ **Returns:** A ThemeProvider that applies themes as CSS custom properties on the document root.
122
+
123
+ ### Constants
124
+
125
+ #### `darkTheme`
126
+
127
+ Default dark theme.
128
+
129
+ Dark backgrounds (#0f172a, #1e293b), light text, blue primary (#60a5fa).
130
+
131
+ ```typescript
132
+ const darkTheme: Theme
133
+ ```
134
+
135
+ #### `lightTheme`
136
+
137
+ Default light theme.
138
+
139
+ Near-white backgrounds (#f6f6f6 background, #ffffff surface), dark text,
140
+ blue primary (#4070e0).
141
+
142
+ ```typescript
143
+ const lightTheme: Theme
144
+ ```
145
+
146
+ #### `provider`
147
+
148
+ Default CSS variables theme provider with light and dark themes.
149
+
150
+ ```typescript
151
+ const provider: ThemeProvider
152
+ ```
153
+
154
+ ## Core Interface
155
+
156
+ Implements `@molecule/app-theme` interface.
157
+
158
+ ## Bond Wiring
159
+
160
+ Setup function to register this provider with the core interface:
161
+
162
+ ```typescript
163
+ import { setProvider } from '@molecule/app-theme'
164
+ import { provider } from '@molecule/app-theme-css-variables'
165
+
166
+ export function setupThemeCssVariables(): void {
167
+ setProvider(provider)
168
+ }
169
+ ```
170
+
171
+ ## Injection Notes
172
+
173
+ ### Requirements
174
+
175
+ Peer dependencies:
176
+
177
+ - `@molecule/app-theme` ^1.0.1
178
+
179
+ ### Runtime Dependencies
180
+
181
+ - `@molecule/app-theme`
182
+
183
+ Recoloring a scaffolded app — where the palette actually lives:
184
+
185
+ This bond writes `--mol-color-*` variables and toggles light/dark via a
186
+ `data-mol-mode` attribute. In `@molecule/app-ui-tailwind`'s `base.css` the
187
+ Tailwind `@theme` reads each core token as
188
+ `--color-primary: var(--mol-color-primary, <default>)`, so for a CUSTOM build
189
+ (no per-app `theme.css`) this bond's `Theme` objects ARE the palette — edit
190
+ `colors` here to recolor.
191
+
192
+ BUT template-based apps ship `app/src/theme.css` that hardcodes `--color-*` on
193
+ `:root` / `[data-mol-mode='dark']`. Those have the same `:root` specificity and
194
+ load last, so they SHADOW the `var(--mol-color-*)` reference — the visible
195
+ colors come only from `theme.css`. When `theme.css` defines colors, editing
196
+ this bond has NO visible effect; recolor by editing `app/src/theme.css`. This
197
+ bond still drives light/dark mode and is the palette for non-Tailwind targets
198
+ (e.g. React Native). Precedence: `theme.css` > this bond > base defaults.
199
+
200
+ The provider also toggles a `.dark` class on `<html>` (alongside the
201
+ `data-mol-mode` attribute) so Tailwind `dark:` variants react to theme
202
+ toggles — if `dark:` utilities aren't switching, check that this bond is
203
+ wired and applying to the document.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-theme-css-variables",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CSS custom properties theme provider for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,7 +17,8 @@
17
17
  }
18
18
  },
19
19
  "files": [
20
- "dist"
20
+ "dist",
21
+ "README.md"
21
22
  ],
22
23
  "keywords": [
23
24
  "molecule",
@@ -33,7 +34,7 @@
33
34
  "vitest": "4.1.10"
34
35
  },
35
36
  "peerDependencies": {
36
- "@molecule/app-theme": "^1.0.0"
37
+ "@molecule/app-theme": "^1.0.1"
37
38
  },
38
39
  "repository": {
39
40
  "type": "git",