@symblight/md-colors 0.1.0
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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/client.esm.js +7044 -0
- package/dist/client.esm.js.map +7 -0
- package/dist/client.js +97 -0
- package/dist/client.js.map +7 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +7 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aleksei Tkachenko <leshtkachenko@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @symblight/md-colors
|
|
2
|
+
|
|
3
|
+
Material Design 3 color token generator. Takes a source color and derives a full MD3 tonal palette, outputting `--md-sys-color-*` tokens in oklch format.
|
|
4
|
+
|
|
5
|
+
Built on [`@material/material-color-utilities`](https://github.com/material-foundation/material-color-utilities).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @symblight/md-colors
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Two builds
|
|
14
|
+
|
|
15
|
+
| Build | Entry | Format | Use case |
|
|
16
|
+
|---|---|---|---|
|
|
17
|
+
| Node / bundler | `dist/index.js` | ESM | Programmatic token generation, CSS file output |
|
|
18
|
+
| Browser (bundler) | `dist/client.esm.js` | ESM | Vite, Storybook, bundler imports |
|
|
19
|
+
| Browser (script) | `dist/client.js` | IIFE | Plain `<script>` tag, no bundler |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Node — programmatic API
|
|
24
|
+
|
|
25
|
+
Import `generateTokens` to build token maps in Node.js scripts or server-side tooling.
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { generateTokens } from "@symblight/md-colors";
|
|
29
|
+
|
|
30
|
+
const tokens = generateTokens({ sourceColor: "#6750A4", scheme: "dark" });
|
|
31
|
+
// { "--md-sys-color-primary": "oklch(…)", … }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### `generateTokens(config)`
|
|
35
|
+
|
|
36
|
+
| Param | Type | Default | Description |
|
|
37
|
+
|---|---|---|---|
|
|
38
|
+
| `config.sourceColor` | `string` | `"#1D5D78"` | Seed color as a hex string |
|
|
39
|
+
| `config.scheme` | `"light" \| "dark"` | `"light"` | Color scheme variant |
|
|
40
|
+
|
|
41
|
+
Returns `Record<string, string>` — CSS variable names mapped to oklch color strings.
|
|
42
|
+
|
|
43
|
+
### Generate a CSS file
|
|
44
|
+
|
|
45
|
+
Run the following to write a `colors.css` file to the package directory:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm generate-theme
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Output:
|
|
52
|
+
|
|
53
|
+
```css
|
|
54
|
+
:root {
|
|
55
|
+
--md-sys-color-primary: oklch(...);
|
|
56
|
+
--md-sys-color-on-primary: oklch(...);
|
|
57
|
+
--md-sys-color-surface-container-highest: oklch(...);
|
|
58
|
+
/* …all MD3 system color tokens */
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Source color and scheme are configured directly in `create-theme-file.mjs`.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Browser client — runtime theming
|
|
67
|
+
|
|
68
|
+
The browser build registers `window.generateTheme`, which injects tokens as CSS custom properties on `:root` at runtime.
|
|
69
|
+
|
|
70
|
+
### Via ES module import (Vite, Storybook)
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import "@symblight/md-colors/client";
|
|
74
|
+
|
|
75
|
+
window.generateTheme({ sourceColor: "#6750A4", scheme: "dark" });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Via `<script>` tag (no bundler)
|
|
79
|
+
|
|
80
|
+
```html
|
|
81
|
+
<script src="node_modules/@symblight/md-colors/dist/client.js"></script>
|
|
82
|
+
<script>
|
|
83
|
+
window.generateTheme({ sourceColor: "#6750A4", scheme: "dark" });
|
|
84
|
+
</script>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### `window.generateTheme(options)`
|
|
88
|
+
|
|
89
|
+
| Param | Type | Default | Description |
|
|
90
|
+
|---|---|---|---|
|
|
91
|
+
| `options.sourceColor` | `string` | — | Seed color as a hex string |
|
|
92
|
+
| `options.scheme` | `"light" \| "dark"` | `"light"` | Color scheme variant |
|
|
93
|
+
|
|
94
|
+
Sets every `--md-sys-color-*` variable on `document.documentElement` via `style.setProperty`.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pnpm build # Build all dist outputs
|
|
102
|
+
pnpm generate-theme # Write colors.css
|
|
103
|
+
pnpm test # Run Jest tests
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
[MIT](./LICENSE) © Aleksei Tkachenko
|