@tenphi/tasty 0.10.1 → 0.12.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.
@@ -0,0 +1,201 @@
1
+ # Getting Started
2
+
3
+ This guide walks you from zero to a working Tasty setup with tooling. For a feature overview, see the [README](../README.md). For the full style language reference, see the [Style DSL](dsl.md). For the React API, see the [Runtime API](runtime.md).
4
+
5
+ ---
6
+
7
+ ## Prerequisites
8
+
9
+ - **Node.js** >= 20
10
+ - **React** >= 18 (peer dependency)
11
+ - **Package manager**: pnpm, npm, or yarn
12
+
13
+ ---
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pnpm add @tenphi/tasty
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Your first component
24
+
25
+ ```tsx
26
+ import { tasty } from '@tenphi/tasty';
27
+
28
+ const Card = tasty({
29
+ as: 'div',
30
+ styles: {
31
+ display: 'flex',
32
+ flow: 'column',
33
+ padding: '4x',
34
+ gap: '2x',
35
+ fill: '#white',
36
+ border: true,
37
+ radius: true,
38
+ },
39
+ });
40
+
41
+ export default function App() {
42
+ return <Card>Hello, Tasty!</Card>;
43
+ }
44
+ ```
45
+
46
+ `tasty()` returns a normal React component. Values like `4x`, `#white`, `true`, and `1r` are Tasty DSL — they map to CSS custom properties, shorthand expansions, and design tokens. See [Style Properties](styles.md) for the full reference.
47
+
48
+ ---
49
+
50
+ ## Add configuration
51
+
52
+ Call `configure()` once, before your app renders, to define state aliases and other conventions your components share:
53
+
54
+ ```tsx
55
+ // src/tasty-config.ts
56
+ import { configure } from '@tenphi/tasty';
57
+
58
+ configure({
59
+ states: {
60
+ '@mobile': '@media(w < 768px)',
61
+ '@dark': '@root(schema=dark)',
62
+ },
63
+ });
64
+ ```
65
+
66
+ Import this file at the top of your app entry point so it runs before any component renders:
67
+
68
+ ```tsx
69
+ // src/main.tsx
70
+ import './tasty-config';
71
+ import { createRoot } from 'react-dom/client';
72
+ import App from './App';
73
+
74
+ createRoot(document.getElementById('root')!).render(<App />);
75
+ ```
76
+
77
+ ### Define design tokens and unit values
78
+
79
+ Color tokens like `#primary` resolve to CSS custom properties at runtime (e.g. `var(--primary-color)`). Built-in units like `x`, `r`, and `bw` also multiply CSS custom properties. Define them via `configure({ tokens })`:
80
+
81
+ ```tsx
82
+ // src/tasty-config.ts
83
+ import { configure } from '@tenphi/tasty';
84
+
85
+ configure({
86
+ tokens: {
87
+ '#primary': 'oklch(55% 0.25 265)',
88
+ '#surface': '#fff',
89
+ '#text': '#111',
90
+ '$gap': '8px',
91
+ '$radius': '4px',
92
+ '$border-width': '1px',
93
+ '$outline-width': '2px',
94
+ },
95
+ });
96
+ ```
97
+
98
+ Tokens support state maps for responsive or theme-aware values:
99
+
100
+ ```tsx
101
+ configure({
102
+ tokens: {
103
+ '#primary': {
104
+ '': 'oklch(55% 0.25 265)',
105
+ '@dark': 'oklch(75% 0.2 265)',
106
+ },
107
+ },
108
+ });
109
+ ```
110
+
111
+ Every component using `#primary`, `2x`, or `1r` adjusts automatically. Tokens are injected as `:root` CSS custom properties when the first style is rendered.
112
+
113
+ > **Note:** `configure({ replaceTokens })` is a separate mechanism — it replaces tokens with literal values at parse time (baked into CSS). Use it for value aliases like `$card-padding: '4x'` that should be resolved during style generation, not for defining color or unit values. See [Configuration — Replace Tokens](configuration.md#replace-tokens-parse-time-substitution) for details.
114
+
115
+ See [Configuration](configuration.md) for the full `configure()` API — tokens, replace tokens, recipes, custom units, style handlers, and TypeScript extensions.
116
+
117
+ ---
118
+
119
+ ## ESLint plugin
120
+
121
+ The ESLint plugin catches invalid style properties, bad token references, malformed state keys, and other mistakes at lint time — before they reach the browser.
122
+
123
+ ### Install
124
+
125
+ ```bash
126
+ pnpm add -D @tenphi/eslint-plugin-tasty
127
+ ```
128
+
129
+ ### Configure
130
+
131
+ Add the plugin to your flat config:
132
+
133
+ ```js
134
+ // eslint.config.js
135
+ import tasty from '@tenphi/eslint-plugin-tasty';
136
+
137
+ export default [
138
+ // ...your other configs
139
+ tasty.configs.recommended,
140
+ ];
141
+ ```
142
+
143
+ ### What `recommended` catches
144
+
145
+ The recommended config enables 18 rules covering the most common issues:
146
+
147
+ | Category | Rules | Examples |
148
+ |----------|-------|---------|
149
+ | Property validation | `known-property`, `valid-boolean-property`, `valid-sub-element` | Flags typos like `pading` or invalid boolean usage |
150
+ | Value validation | `valid-value`, `valid-color-token`, `valid-custom-unit` | Catches `#nonexistent` tokens, bad unit syntax |
151
+ | State validation | `valid-state-key`, `no-nested-state-map`, `require-default-state` | Validates state key syntax, ensures `''` default exists |
152
+ | Structure | `valid-styles-structure`, `no-important`, `no-nested-selector` | Prevents `!important`, invalid nesting |
153
+ | Static mode | `static-no-dynamic-values`, `static-valid-selector` | Enforces build-time constraints in `tastyStatic()` |
154
+ | Style properties | `valid-preset`, `valid-recipe`, `valid-transition`, `valid-directional-modifier`, `valid-radius-shape` | Validates preset names, recipe references, transition syntax |
155
+
156
+ ### Strict config
157
+
158
+ For stricter governance, use `tasty.configs.strict`. It adds rules that enforce best practices like preferring shorthand properties, consistent token usage, and flagging direct `styles` prop usage:
159
+
160
+ ```js
161
+ export default [
162
+ tasty.configs.strict,
163
+ ];
164
+ ```
165
+
166
+ ---
167
+
168
+ ## Editor support
169
+
170
+ **[VS Code Extension](https://github.com/tenphi/tasty-vscode-extension)** — Syntax highlighting for Tasty styles in TypeScript/TSX/JavaScript/JSX. Highlights color tokens, custom units, state keys, presets, and style properties inside `tasty()` and `tastyStatic()` calls. Install from the VS Code marketplace or from a `.vsix` file.
171
+
172
+ **[Glaze](https://github.com/tenphi/glaze)** — OKHSL-based color theme generator with automatic WCAG contrast solving. Generate light, dark, and high-contrast color palettes from a single hue and export them directly as Tasty color tokens. See the [Ecosystem section](../README.md#ecosystem) in the README.
173
+
174
+ ---
175
+
176
+ ## Choosing a rendering mode
177
+
178
+ Tasty supports three rendering modes. Pick the one that fits your use case:
179
+
180
+ | Mode | Entry point | Best for | Trade-off |
181
+ |------|-------------|----------|-----------|
182
+ | **Runtime** | `tasty()` from `@tenphi/tasty` | Interactive apps, design systems | CSS generated at runtime; full feature set (styleProps, sub-elements, variants) |
183
+ | **Zero-runtime** | `tastyStatic()` from `@tenphi/tasty/static` | Static sites, landing pages, SSG | Zero JS overhead; requires Babel plugin; no dynamic props |
184
+ | **SSR** | `@tenphi/tasty/ssr/next` or `@tenphi/tasty/ssr/astro` | Next.js, Astro, streaming SSR | Runtime `tasty()` with server-rendered CSS and zero-cost hydration |
185
+
186
+ All three share the same DSL, tokens, units, and state mappings.
187
+
188
+ - Runtime is the default and requires no extra setup beyond `@tenphi/tasty`.
189
+ - Zero-runtime requires the Babel plugin and additional peer dependencies. See [Zero Runtime (tastyStatic)](tasty-static.md).
190
+ - SSR works with existing `tasty()` components — wrap your app with a registry or middleware. See [Server-Side Rendering](ssr.md).
191
+
192
+ ---
193
+
194
+ ## Next steps
195
+
196
+ - **[Methodology](methodology.md)** — The recommended patterns for structuring Tasty components: sub-elements, styleProps, tokens, extension
197
+ - **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
198
+ - **[Runtime API](runtime.md)** — `tasty()` factory, component props, variants, sub-elements, hooks
199
+ - **[Building a Design System](design-system.md)** — Practical guide to building a DS layer with Tasty: tokens, recipes, primitives, compound components
200
+ - **[Configuration](configuration.md)** — Full `configure()` API: tokens, recipes, custom units, style handlers, TypeScript extensions
201
+ - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
package/docs/injector.md CHANGED
@@ -511,7 +511,7 @@ const StyledButton = tasty({
511
511
  // 4. dispose() is called when component unmounts
512
512
  ```
513
513
 
514
- For most development, you'll use the [Tasty style system](./usage.md) rather than the injector directly. The injector provides the high-performance foundation that makes Tasty's declarative styling possible.
514
+ For most development, you'll use the [Runtime API](./runtime.md) rather than the injector directly. The injector provides the high-performance foundation that makes Tasty's declarative styling possible.
515
515
 
516
516
  ---
517
517
 
@@ -525,4 +525,4 @@ Direct injector usage is recommended for:
525
525
  - **Performance-critical scenarios** where you need direct control
526
526
  - **Testing utilities** that need to inject or extract CSS
527
527
 
528
- For regular component styling, prefer the [`tasty()` API](./usage.md) which provides a more developer-friendly interface.
528
+ For regular component styling, prefer the [`tasty()` API](./runtime.md) which provides a more developer-friendly interface.