@ds-mo/tokens 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 TokoMo contributors
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,145 @@
1
+ # @ds-mo/tokens
2
+
3
+ Design tokens as CSS custom properties, JSON, and TypeScript constants — the token foundation for the **CompoMo** design system.
4
+
5
+ Part of the design system trilogy:
6
+ **TokoMo** (`@ds-mo/tokens`) → **IcoMo** (`@ds-mo/icons`) → **CompoMo** (`@ds-mo/ui`)
7
+
8
+ Figma-first: tokens are exported from Figma variables and built into CSS via generator scripts. Drop in new JSON, run the build, everything updates.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @ds-mo/tokens
14
+ # or
15
+ pnpm add @ds-mo/tokens
16
+
17
+ # Local development (no npm publish needed):
18
+ pnpm add file:../path/to/tokomo
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### CSS
24
+
25
+ ```css
26
+ /* All tokens at once */
27
+ @import '@ds-mo/tokens';
28
+
29
+ /* Or selectively */
30
+ @import '@ds-mo/tokens/colors';
31
+ @import '@ds-mo/tokens/dimensions';
32
+ @import '@ds-mo/tokens/typography';
33
+ @import '@ds-mo/tokens/effects';
34
+
35
+ /* Optional: base styles (font loading, reduced-motion, focus rings) */
36
+ @import '@ds-mo/tokens/globals';
37
+
38
+ /* Optional: CSS reset */
39
+ @import '@ds-mo/tokens/reset';
40
+ ```
41
+
42
+ ### JS / TypeScript (via bundler)
43
+
44
+ ```ts
45
+ import '@ds-mo/tokens';
46
+ import '@ds-mo/tokens/globals';
47
+
48
+ // Type-safe token name constants
49
+ import { colorBackgroundPrimary, dimensionSpace200 } from '@ds-mo/tokens/ts';
50
+ // value is just the CSS variable name string: '--color-background-primary'
51
+ element.style.setProperty(colorBackgroundPrimary, 'red');
52
+ ```
53
+
54
+ ### JSON (for tooling, plugins, etc.)
55
+
56
+ ```ts
57
+ import tokens from '@ds-mo/tokens/json';
58
+ import colors from '@ds-mo/tokens/json/colors';
59
+ ```
60
+
61
+ ## Theming
62
+
63
+ Light/dark theme is controlled via a `data-theme` attribute on `<html>`:
64
+
65
+ ```ts
66
+ document.documentElement.setAttribute('data-theme', 'dark');
67
+ document.documentElement.setAttribute('data-theme', 'light');
68
+ ```
69
+
70
+ Light is the default. No JS required — pure CSS variable overrides.
71
+
72
+ ## Token categories
73
+
74
+ | File | Prefix | Contains |
75
+ |---|---|---|
76
+ | `colors.css` | `--color-*` | Semantic colors (light + dark), reference palette, data viz |
77
+ | `dimensions.css` | `--dimension-*` | Space, radius, size, stroke-width — all `calc()` from `--dimension-base` |
78
+ | `typography.css` | `--typography-*` | Weight, font-size, line-height, letter-spacing + `.text-*` classes |
79
+ | `effects.css` | `--effect-*` | Blur, animation timing, easing, elevation shadows |
80
+
81
+ ## Scaling
82
+
83
+ All dimension tokens are `calc()` from `--dimension-base: 8px`. Override it to scale everything:
84
+
85
+ ```css
86
+ :root {
87
+ --dimension-base: 10px; /* scales all spacing, radius, size, stroke-width */
88
+ }
89
+ ```
90
+
91
+ Or override a single category:
92
+
93
+ ```css
94
+ :root {
95
+ --dimension-space-base: 10px;
96
+ --dimension-radius-base: 6px;
97
+ }
98
+ ```
99
+
100
+ ## Elevation
101
+
102
+ Each level gives you three tokens to handle `overflow: hidden` clipping:
103
+
104
+ ```css
105
+ /* Simple case — no overflow clipping */
106
+ .card { box-shadow: var(--effect-elevation-elevated-sm); }
107
+
108
+ /* With overflow: hidden — split shadow and highlight */
109
+ .card {
110
+ overflow: hidden;
111
+ box-shadow: var(--effect-shadow-elevated-sm); /* outset on root */
112
+ position: relative;
113
+ }
114
+ .card::after {
115
+ content: '';
116
+ position: absolute;
117
+ inset: 0;
118
+ border-radius: inherit;
119
+ box-shadow: var(--effect-highlight-elevated-sm); /* inset on overlay */
120
+ pointer-events: none;
121
+ }
122
+ ```
123
+
124
+ Available: `elevated-none`, `elevated-sm`, `elevated-md`, `elevated-floating`, `depressed-sm`, `depressed-md`, `elevated-panel-top/right/bottom/left`
125
+
126
+ ## Updating from Figma
127
+
128
+ 1. Export updated variable JSON from Figma
129
+ 2. Drop into `src/json/{colors,dimensions,typography,effects}/`
130
+ 3. Run the build:
131
+
132
+ ```bash
133
+ node scripts/build.mjs
134
+ ```
135
+
136
+ ## Dev
137
+
138
+ ```bash
139
+ node scripts/build.mjs # full build
140
+ node scripts/build.mjs --watch # watch mode
141
+ ```
142
+
143
+ ## License
144
+
145
+ MIT