@tenphi/tasty 0.0.0-snapshot.002b1b3

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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +637 -0
  3. package/dist/async-storage-B7_o6FKt.js +44 -0
  4. package/dist/async-storage-B7_o6FKt.js.map +1 -0
  5. package/dist/collector-LuU1vZ68.d.ts +98 -0
  6. package/dist/collector-MOYY2SOr.js +230 -0
  7. package/dist/collector-MOYY2SOr.js.map +1 -0
  8. package/dist/config-A237aY9H.js +10235 -0
  9. package/dist/config-A237aY9H.js.map +1 -0
  10. package/dist/config-vuCRkBWX.d.ts +884 -0
  11. package/dist/context-CkSg-kDT.js +24 -0
  12. package/dist/context-CkSg-kDT.js.map +1 -0
  13. package/dist/core/index.d.ts +5 -0
  14. package/dist/core/index.js +6 -0
  15. package/dist/core-BkKav78f.js +1592 -0
  16. package/dist/core-BkKav78f.js.map +1 -0
  17. package/dist/css-writer-Cos9tQRM.js +329 -0
  18. package/dist/css-writer-Cos9tQRM.js.map +1 -0
  19. package/dist/format-global-rules-Dbc_1tc3.js +22 -0
  20. package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
  21. package/dist/format-rules-C2oiTsEO.js +143 -0
  22. package/dist/format-rules-C2oiTsEO.js.map +1 -0
  23. package/dist/hydrate-miFzWIKR.js +45 -0
  24. package/dist/hydrate-miFzWIKR.js.map +1 -0
  25. package/dist/index-CJMXAAO5.d.ts +1602 -0
  26. package/dist/index-dUtwpOux.d.ts +1266 -0
  27. package/dist/index.d.ts +5 -0
  28. package/dist/index.js +732 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/keyframes-DDtNo_hl.js +587 -0
  31. package/dist/keyframes-DDtNo_hl.js.map +1 -0
  32. package/dist/merge-styles-CtDJMhpJ.d.ts +7 -0
  33. package/dist/merge-styles-D_HbBOlq.js +144 -0
  34. package/dist/merge-styles-D_HbBOlq.js.map +1 -0
  35. package/dist/resolve-recipes-B7-823LL.js +144 -0
  36. package/dist/resolve-recipes-B7-823LL.js.map +1 -0
  37. package/dist/ssr/astro-client.d.ts +1 -0
  38. package/dist/ssr/astro-client.js +19 -0
  39. package/dist/ssr/astro-client.js.map +1 -0
  40. package/dist/ssr/astro-middleware.d.ts +15 -0
  41. package/dist/ssr/astro-middleware.js +19 -0
  42. package/dist/ssr/astro-middleware.js.map +1 -0
  43. package/dist/ssr/astro.d.ts +97 -0
  44. package/dist/ssr/astro.js +149 -0
  45. package/dist/ssr/astro.js.map +1 -0
  46. package/dist/ssr/index.d.ts +44 -0
  47. package/dist/ssr/index.js +10 -0
  48. package/dist/ssr/index.js.map +1 -0
  49. package/dist/ssr/next.d.ts +46 -0
  50. package/dist/ssr/next.js +75 -0
  51. package/dist/ssr/next.js.map +1 -0
  52. package/dist/static/index.d.ts +91 -0
  53. package/dist/static/index.js +50 -0
  54. package/dist/static/index.js.map +1 -0
  55. package/dist/static/inject.d.ts +5 -0
  56. package/dist/static/inject.js +17 -0
  57. package/dist/static/inject.js.map +1 -0
  58. package/dist/zero/babel.d.ts +81 -0
  59. package/dist/zero/babel.js +466 -0
  60. package/dist/zero/babel.js.map +1 -0
  61. package/dist/zero/index.d.ts +67 -0
  62. package/dist/zero/index.js +2 -0
  63. package/dist/zero/next.d.ts +86 -0
  64. package/dist/zero/next.js +143 -0
  65. package/dist/zero/next.js.map +1 -0
  66. package/docs/README.md +31 -0
  67. package/docs/adoption.md +298 -0
  68. package/docs/comparison.md +419 -0
  69. package/docs/configuration.md +394 -0
  70. package/docs/debug.md +320 -0
  71. package/docs/design-system.md +436 -0
  72. package/docs/dsl.md +688 -0
  73. package/docs/getting-started.md +217 -0
  74. package/docs/injector.md +544 -0
  75. package/docs/methodology.md +616 -0
  76. package/docs/pipeline.md +673 -0
  77. package/docs/react-api.md +557 -0
  78. package/docs/ssr.md +442 -0
  79. package/docs/styles.md +596 -0
  80. package/docs/tasty-static.md +532 -0
  81. package/package.json +222 -0
  82. package/tasty.config.ts +15 -0
@@ -0,0 +1,436 @@
1
+ # Building a Design System
2
+
3
+ This guide walks through building a design-system styling layer on top of Tasty — defining tokens, state aliases, recipes, primitive components, and compound components with sub-elements.
4
+
5
+ It assumes you have already decided to adopt Tasty. The goal is not just to centralize tokens, but to define a styling language whose component states resolve deterministically across variants, responsive rules, and sub-elements. For evaluation criteria, audience fit, and incremental adoption phases, see the [Adoption Guide](adoption.md). For the recommended component patterns and mental model, see [Methodology](methodology.md).
6
+
7
+ ---
8
+
9
+ ## Designing your token vocabulary
10
+
11
+ Tokens are the foundation of a design system. In Tasty, tokens are defined via `configure({ tokens })` and referenced in styles with `#name` (colors) or `$name` (values). See [Configuration — Design Tokens](configuration.md#design-tokens) for the API.
12
+
13
+ ### Color tokens
14
+
15
+ Adopt a semantic naming convention that maps intent, not visual appearance. Define tokens via `configure({ tokens })`:
16
+
17
+ ```tsx
18
+ import { configure } from '@tenphi/tasty';
19
+
20
+ configure({
21
+ tokens: {
22
+ // Surfaces
23
+ '#surface': '#fff',
24
+ '#surface-hover': '#f5f5f5',
25
+ '#surface-pressed': '#ebebeb',
26
+
27
+ // Primary action
28
+ '#primary': 'oklch(55% 0.25 265)',
29
+ '#primary-hover': 'oklch(50% 0.25 265)',
30
+ '#primary-pressed': 'oklch(45% 0.25 265)',
31
+ '#on-primary': '#fff',
32
+
33
+ // Semantic
34
+ '#danger': 'oklch(55% 0.22 25)',
35
+ '#danger-hover': 'oklch(50% 0.22 25)',
36
+ '#on-danger': '#fff',
37
+
38
+ // Text
39
+ '#text': '#111',
40
+ '#text-secondary': '#666',
41
+
42
+ // Borders
43
+ '#border': '#e0e0e0',
44
+
45
+ // Unit values
46
+ '$gap': '8px',
47
+ '$radius': '4px',
48
+ '$border-width': '1px',
49
+ '$outline-width': '2px',
50
+ },
51
+ });
52
+ ```
53
+
54
+ Tokens are injected as CSS custom properties on `:root` when the first style is rendered. They support state maps for theme-aware values:
55
+
56
+ ```tsx
57
+ configure({
58
+ tokens: {
59
+ '#primary': {
60
+ '': 'oklch(55% 0.25 265)',
61
+ '@dark': 'oklch(75% 0.2 265)',
62
+ },
63
+ },
64
+ });
65
+ ```
66
+
67
+ The `#on-*` convention names the text color that sits on top of a fill — `#on-primary` is the text color on a `#primary` background. This makes state maps self-documenting: `fill: '#primary'` and `color: '#on-primary'` clearly belong together.
68
+
69
+ For OKHSL-based palette generation with automatic WCAG contrast solving, see [Glaze](https://github.com/tenphi/glaze).
70
+
71
+ ### Replace tokens for value aliases
72
+
73
+ `configure({ replaceTokens })` replaces tokens with literal values at parse time, baking them into the generated CSS. Use it for value aliases that should be inlined during style generation:
74
+
75
+ ```tsx
76
+ configure({
77
+ replaceTokens: {
78
+ '$card-padding': '4x',
79
+ '$input-height': '5x',
80
+ '$sidebar-width': '280px',
81
+ },
82
+ });
83
+ ```
84
+
85
+ ### Typography presets
86
+
87
+ Pass typography presets directly to `configure()` — they are converted to tokens automatically:
88
+
89
+ ```tsx
90
+ import { configure } from '@tenphi/tasty';
91
+
92
+ configure({
93
+ presets: {
94
+ h1: { fontSize: '2rem', lineHeight: '1.2', letterSpacing: '-0.02em', fontWeight: 700 },
95
+ t2: { fontSize: '0.875rem', lineHeight: '1.5', letterSpacing: 'normal', fontWeight: 400 },
96
+ },
97
+ });
98
+ ```
99
+
100
+ Preset values support state maps for responsive or theme-aware typography:
101
+
102
+ ```tsx
103
+ configure({
104
+ presets: {
105
+ t2: {
106
+ fontSize: '0.875rem',
107
+ lineHeight: '1.5',
108
+ fontWeight: { '': 400, '@dark': 300 },
109
+ },
110
+ },
111
+ });
112
+ ```
113
+
114
+ Then use `preset: 'h1'` or `preset: 't2'` in any component's styles.
115
+
116
+ > You can also call `generateTypographyTokens()` manually and spread the result into `tokens` for more control — `presets` is just a shorthand.
117
+
118
+ ### Registering brand fonts
119
+
120
+ Register your design system's custom fonts via `configure({ fontFace })` so every component can reference them:
121
+
122
+ ```ts
123
+ configure({
124
+ fontFace: {
125
+ 'Brand Sans': [
126
+ { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
127
+ { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
128
+ ],
129
+ },
130
+ });
131
+ ```
132
+
133
+ See [Font Face](configuration.md#font-face) for the full configuration reference.
134
+
135
+ ---
136
+
137
+ ## Defining state aliases
138
+
139
+ State aliases let you write `@mobile` instead of `@media(w < 768px)` in every component. Define them once in `configure()`:
140
+
141
+ ```tsx
142
+ configure({
143
+ states: {
144
+ '@mobile': '@media(w < 768px)',
145
+ '@tablet': '@media(768px <= w < 1024px)',
146
+ '@desktop': '@media(w >= 1024px)',
147
+ '@dark': '@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))',
148
+ '@reduced-motion': '@media(prefers-reduced-motion: reduce)',
149
+ },
150
+ });
151
+ ```
152
+
153
+ Every component can now use these without repeating the query logic:
154
+
155
+ ```tsx
156
+ const Card = tasty({
157
+ styles: {
158
+ padding: { '': '4x', '@mobile': '2x' },
159
+ flow: { '': 'row', '@mobile': 'column' },
160
+ fill: { '': '#surface', '@dark': '#surface-dark' },
161
+ },
162
+ });
163
+ ```
164
+
165
+ Without aliases, the same component would need the full media query expression inlined in every state map — across every property, in every component. Aliases eliminate that duplication.
166
+
167
+ ---
168
+
169
+ ## Creating recipes
170
+
171
+ Recipes are named style bundles for patterns that repeat across components. Define them in `configure()`:
172
+
173
+ ```tsx
174
+ configure({
175
+ recipes: {
176
+ card: {
177
+ padding: '4x',
178
+ fill: '#surface',
179
+ radius: '1r',
180
+ border: true,
181
+ },
182
+ elevated: {
183
+ shadow: '0 2x 4x #shadow',
184
+ },
185
+ 'input-reset': {
186
+ border: 'none',
187
+ outline: 'none',
188
+ fill: 'transparent',
189
+ font: true,
190
+ preset: 't3',
191
+ },
192
+ interactive: {
193
+ cursor: { '': 'pointer', disabled: 'not-allowed' },
194
+ opacity: { '': '1', disabled: '.5' },
195
+ transition: 'theme',
196
+ },
197
+ },
198
+ });
199
+ ```
200
+
201
+ Components reference recipes by name. This keeps component definitions lean while ensuring consistency:
202
+
203
+ ```tsx
204
+ const ProfileCard = tasty({
205
+ styles: {
206
+ recipe: 'card elevated',
207
+ color: '#text',
208
+ Title: { preset: 'h3', color: '#primary' },
209
+ },
210
+ elements: { Title: 'h2' },
211
+ });
212
+ ```
213
+
214
+ Use the `/` separator when a recipe should be applied *after* local styles (post-merge), so recipe states take priority:
215
+
216
+ ```tsx
217
+ const Input = tasty({
218
+ styles: {
219
+ recipe: 'input-reset / interactive',
220
+ padding: '1.5x 2x',
221
+ border: '1bw solid #border',
222
+ },
223
+ });
224
+ ```
225
+
226
+ See [Configuration — Recipes](configuration.md#recipes) for the API and [Style DSL — Recipes](dsl.md#recipes) for composition patterns.
227
+
228
+ ---
229
+
230
+ ## Building primitive components
231
+
232
+ Primitives are the layout and utility components that product engineers compose. They expose a controlled set of style props and have minimal opinions about appearance.
233
+
234
+ ### Layout primitives
235
+
236
+ ```tsx
237
+ import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
238
+
239
+ const Space = tasty({
240
+ as: 'div',
241
+ styles: {
242
+ display: 'flex',
243
+ flow: 'column',
244
+ gap: '1x',
245
+ },
246
+ styleProps: FLOW_STYLES,
247
+ });
248
+
249
+ const Box = tasty({
250
+ as: 'div',
251
+ styles: {
252
+ display: 'block',
253
+ },
254
+ styleProps: [...FLOW_STYLES, ...POSITION_STYLES, 'padding', 'fill', 'radius'],
255
+ });
256
+
257
+ const Grid = tasty({
258
+ as: 'div',
259
+ styles: {
260
+ display: 'grid',
261
+ gap: '1x',
262
+ },
263
+ styleProps: [...FLOW_STYLES, 'gridColumns', 'gridRows', 'gridAreas'],
264
+ });
265
+ ```
266
+
267
+ Product engineers use these to compose layouts without writing CSS:
268
+
269
+ ```tsx
270
+ <Space flow="row" gap="2x" placeItems="center">
271
+ <Title>Dashboard</Title>
272
+ <Button placeSelf="end">Add Item</Button>
273
+ </Space>
274
+
275
+ <Grid gridColumns={{ '': '1fr', '@tablet': '1fr 1fr', '@desktop': '1fr 1fr 1fr' }} gap="3x">
276
+ <Card>...</Card>
277
+ <Card>...</Card>
278
+ <Card>...</Card>
279
+ </Grid>
280
+ ```
281
+
282
+ ### Which styleProps to expose
283
+
284
+ Match the prop set to the component's role:
285
+
286
+ | Component category | Recommended styleProps |
287
+ |--------------------|----------------------|
288
+ | Layout containers (`Space`, `Box`, `Grid`) | `FLOW_STYLES` — flow, gap, align, justify, padding, fill |
289
+ | Positioned elements (`Button`, `Badge`) | `POSITION_STYLES` — placeSelf, gridArea, order |
290
+ | Text elements | `['preset', 'color']` or a custom subset |
291
+ | Compound components | Typically none — styling happens via sub-elements and wrapping |
292
+
293
+ Exposing too many props weakens the design system's constraints. See [Methodology — styleProps as the public API](methodology.md#styleprops-as-the-public-api) for the rationale.
294
+
295
+ ---
296
+
297
+ ## Building compound components
298
+
299
+ Compound components have inner parts — a card has a title, content, and footer; a dialog has a header, body, and actions. Tasty models these as sub-elements.
300
+
301
+ ```tsx
302
+ const Card = tasty({
303
+ styles: {
304
+ recipe: 'card',
305
+ flow: 'column',
306
+ gap: '2x',
307
+
308
+ Title: {
309
+ preset: 'h3',
310
+ color: '#primary',
311
+ },
312
+ Content: {
313
+ preset: 't2',
314
+ color: '#text',
315
+ },
316
+ Footer: {
317
+ display: 'flex',
318
+ flow: 'row',
319
+ gap: '1x',
320
+ justify: 'flex-end',
321
+ padding: '2x top',
322
+ border: '1bw solid #border top',
323
+ },
324
+ },
325
+ elements: {
326
+ Title: 'h2',
327
+ Content: 'div',
328
+ Footer: 'div',
329
+ },
330
+ });
331
+ ```
332
+
333
+ Usage:
334
+
335
+ ```tsx
336
+ <Card>
337
+ <Card.Title>Monthly Revenue</Card.Title>
338
+ <Card.Content>
339
+ $1.2M — up 12% from last month.
340
+ </Card.Content>
341
+ <Card.Footer>
342
+ <Button>Details</Button>
343
+ </Card.Footer>
344
+ </Card>
345
+ ```
346
+
347
+ Sub-elements share the root component's state context by default. A `disabled` modifier on `<Card>` affects `Title`, `Content`, and `Footer` styles automatically — no prop drilling. For the full mental model, see [Methodology — Component architecture](methodology.md#component-architecture-root--sub-elements).
348
+
349
+ For sub-element syntax details (selector affix `$`, `@own()`, `elements` config), see [React API — Sub-element Styling](react-api.md#sub-element-styling).
350
+
351
+ ---
352
+
353
+ ## Defining the override contract
354
+
355
+ A design system works best when the rules for customization are explicit. Tasty provides three levels of control:
356
+
357
+ ### What product engineers can do
358
+
359
+ 1. **Use styleProps** — adjust layout, spacing, positioning through the props the component exposes:
360
+
361
+ ```tsx
362
+ <Space flow="row" gap="3x" padding="2x">
363
+ ```
364
+
365
+ 2. **Use modProps** — control component states through typed props instead of `mods`:
366
+
367
+ ```tsx
368
+ <Button isLoading size="large">Submit</Button>
369
+ ```
370
+
371
+ 3. **Pass tokens** — inject runtime values through the `tokens` prop for per-instance customization:
372
+
373
+ ```tsx
374
+ <ProgressBar tokens={{ '$progress': `${percent}%` }} />
375
+ ```
376
+
377
+ 4. **Create styled wrappers** — extend a component's styles with `tasty(Base, { styles })`:
378
+
379
+ ```tsx
380
+ const DangerButton = tasty(Button, {
381
+ styles: {
382
+ fill: { '': '#danger', ':hover': '#danger-hover' },
383
+ color: '#on-danger',
384
+ },
385
+ });
386
+ ```
387
+
388
+ ### What to discourage
389
+
390
+ - **Direct `styles` prop** — bypasses the component's intended API; prefer styled wrappers
391
+ - **`style` prop** — React inline styles that bypass Tasty entirely; reserve for third-party integration only
392
+ - **Overriding internal sub-elements** — if product engineers need to restyle sub-elements, the DS component should expose that through its own API (additional props or variants), not through raw `styles` overrides
393
+
394
+ See [Methodology — styles prop vs style prop](methodology.md#styles-prop-vs-style-prop) and [Methodology — Wrapping and extension](methodology.md#wrapping-and-extension) for the full rationale.
395
+
396
+ ---
397
+
398
+ ## Project structure
399
+
400
+ A recommended structure for a design system built on Tasty:
401
+
402
+ ```
403
+ ds/
404
+ config.ts # configure() — tokens, units, states, recipes
405
+ primitives/
406
+ Space.tsx # Layout: flex container with FLOW_STYLES
407
+ Box.tsx # Generic container
408
+ Grid.tsx # Grid container
409
+ Text.tsx # Text element with preset + color
410
+ components/
411
+ Button.tsx # Interactive component with variants
412
+ Card.tsx # Compound component with sub-elements
413
+ Input.tsx # Form input with recipes
414
+ Dialog.tsx # Overlay compound component
415
+ recipes/
416
+ index.ts # Recipe definitions (imported by config.ts)
417
+ tokens/
418
+ colors.ts # Color token definitions
419
+ typography.ts # Typography presets for configure({ presets })
420
+ spacing.ts # Spacing token definitions
421
+ index.ts # Public API: re-exports components + configure
422
+ ```
423
+
424
+ The key principle: `config.ts` imports tokens and recipes, calls `configure()`, and is imported at the app entry point before any component renders. Components import only from `@tenphi/tasty` — they reference tokens and recipes by name, not by import.
425
+
426
+ ---
427
+
428
+ ## Learn more
429
+
430
+ - **[Methodology](methodology.md)** — The recommended patterns for structuring Tasty components
431
+ - **[Getting Started](getting-started.md)** — Installation, first component, tooling setup
432
+ - **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
433
+ - **[React API](react-api.md)** — `tasty()` factory, component props, variants, sub-elements, style functions
434
+ - **[Configuration](configuration.md)** — Full `configure()` API: tokens, recipes, custom units, style handlers
435
+ - **[Adoption Guide](adoption.md)** — Who should adopt Tasty, incremental phases, what changes for product engineers
436
+ - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties