@tenphi/tasty 0.0.0-snapshot.2dc73be → 0.0.0-snapshot.2f5d166
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/README.md +288 -250
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +17 -10
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +2 -3
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +32 -34
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +335 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +109 -30
- package/dist/config.js +142 -57
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +10 -9
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +357 -637
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +52 -0
- package/dist/hooks/useCounterStyle.js +43 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +45 -0
- package/dist/hooks/useFontFace.js +68 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +18 -2
- package/dist/hooks/useGlobalStyles.js +50 -46
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +32 -57
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +29 -45
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +8 -44
- package/dist/hooks/useRawCSS.js +82 -27
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +4 -9
- package/dist/hooks/useStyles.js +7 -226
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.js +13 -10
- package/dist/injector/index.d.ts +36 -19
- package/dist/injector/index.js +42 -19
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +48 -3
- package/dist/injector/injector.js +144 -16
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +9 -13
- package/dist/injector/sheet-manager.js +39 -70
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +103 -19
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +6 -6
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +2 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +1 -2
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +80 -32
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +329 -82
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +3 -8
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +1 -2
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +3 -277
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/properties/index.js +3 -17
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +5 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- package/dist/rsc-cache.js +70 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +24 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +85 -8
- package/dist/ssr/astro.js +111 -22
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/async-storage.js +1 -2
- package/dist/ssr/async-storage.js.map +1 -1
- package/dist/ssr/collect-auto-properties.js +29 -11
- package/dist/ssr/collect-auto-properties.js.map +1 -1
- package/dist/ssr/collector.d.ts +17 -0
- package/dist/ssr/collector.js +60 -14
- package/dist/ssr/collector.js.map +1 -1
- package/dist/ssr/format-global-rules.js +1 -1
- package/dist/ssr/format-keyframes.js +1 -2
- package/dist/ssr/format-keyframes.js.map +1 -1
- package/dist/ssr/format-property.js +10 -9
- package/dist/ssr/format-property.js.map +1 -1
- package/dist/ssr/format-rules.js +8 -5
- package/dist/ssr/format-rules.js.map +1 -1
- package/dist/ssr/hydrate.js +1 -2
- package/dist/ssr/hydrate.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -3
- package/dist/ssr/index.js +2 -4
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +1 -3
- package/dist/ssr/next.js +10 -7
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr/ssr-collector-ref.js +1 -1
- package/dist/states/index.js +13 -259
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- package/dist/styles/color.js +11 -8
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +28 -26
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +3 -4
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -4
- package/dist/styles/predefined.js +9 -10
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -3
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +1 -1
- package/dist/styles/scrollbar.js +8 -5
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +5 -4
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +84 -15
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -893
- package/dist/tasty.js +96 -59
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/cache-wrapper.js +4 -9
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.js +3 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +3 -4
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -17
- package/dist/utils/process-tokens.js +19 -107
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +3 -81
- package/dist/utils/styles.js +29 -539
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +15 -17
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +63 -8
- package/dist/zero/babel.js +163 -44
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +54 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +28 -1
- package/dist/zero/next.js +70 -15
- package/dist/zero/next.js.map +1 -1
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +296 -0
- package/docs/comparison.md +420 -0
- package/docs/configuration.md +127 -12
- package/docs/debug.md +152 -339
- package/docs/design-system.md +424 -0
- package/docs/{usage.md → dsl.md} +379 -386
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +43 -27
- package/docs/methodology.md +616 -0
- package/docs/runtime.md +575 -0
- package/docs/ssr.md +144 -81
- package/docs/styles.md +48 -26
- package/docs/tasty-static.md +166 -22
- package/package.json +27 -12
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -14
- package/dist/ssr/context.js.map +0 -1
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
This guide walks you from zero to a working Tasty component, then through the optional shared configuration and tooling layers. It is the right starting point when you already want to try Tasty in code. If you are still deciding whether Tasty fits your team, start with [Comparison](comparison.md) and [Adoption Guide](adoption.md) first. 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). For the rest of the docs by role or task, see the [Docs Hub](README.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
|
+
Tasty can be used immediately in a React app, but it is most compelling for teams building reusable components with intersecting states, variants, tokens, and design-system conventions.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @tenphi/tasty
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Your first component
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { tasty } from '@tenphi/tasty';
|
|
29
|
+
|
|
30
|
+
const Card = tasty({
|
|
31
|
+
as: 'div',
|
|
32
|
+
styles: {
|
|
33
|
+
display: 'flex',
|
|
34
|
+
flow: 'column',
|
|
35
|
+
padding: '4x',
|
|
36
|
+
gap: '2x',
|
|
37
|
+
fill: '#white',
|
|
38
|
+
border: true,
|
|
39
|
+
radius: true,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export default function App() {
|
|
44
|
+
return <Card>Hello, Tasty!</Card>;
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`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.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Optional: add shared configuration
|
|
53
|
+
|
|
54
|
+
Use `configure()` once, before your app renders, when your app or design system needs shared state aliases, tokens, recipes, or parser extensions:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// src/tasty-config.ts
|
|
58
|
+
import { configure } from '@tenphi/tasty';
|
|
59
|
+
|
|
60
|
+
configure({
|
|
61
|
+
states: {
|
|
62
|
+
'@mobile': '@media(w < 768px)',
|
|
63
|
+
'@dark': '@root(schema=dark)',
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
These examples use `data-schema="dark"` as the root-state convention. If your app already uses a different attribute such as `data-theme="dark"`, keep the pattern and swap the attribute name consistently across your config and components.
|
|
69
|
+
|
|
70
|
+
Import this file at the top of your app entry point so it runs before any component renders:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
// src/main.tsx
|
|
74
|
+
import './tasty-config';
|
|
75
|
+
import { createRoot } from 'react-dom/client';
|
|
76
|
+
import App from './App';
|
|
77
|
+
|
|
78
|
+
createRoot(document.getElementById('root')!).render(<App />);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Define shared tokens and override default unit values
|
|
82
|
+
|
|
83
|
+
Color tokens like `#primary` resolve to CSS custom properties at runtime (e.g. `var(--primary-color)`). Built-in units like `x`, `r`, and `bw` already work without setup and multiply CSS custom properties by default. Use `configure({ tokens })` when you want to define shared token values or override the defaults your app uses:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
// src/tasty-config.ts
|
|
87
|
+
import { configure } from '@tenphi/tasty';
|
|
88
|
+
|
|
89
|
+
configure({
|
|
90
|
+
tokens: {
|
|
91
|
+
'#primary': 'oklch(55% 0.25 265)',
|
|
92
|
+
'#surface': '#fff',
|
|
93
|
+
'#text': '#111',
|
|
94
|
+
'$gap': '8px',
|
|
95
|
+
'$radius': '4px',
|
|
96
|
+
'$border-width': '1px',
|
|
97
|
+
'$outline-width': '2px',
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Tokens support state maps for responsive or theme-aware values:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
configure({
|
|
106
|
+
tokens: {
|
|
107
|
+
'#primary': {
|
|
108
|
+
'': 'oklch(55% 0.25 265)',
|
|
109
|
+
'@dark': 'oklch(75% 0.2 265)',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Every component using `#primary`, `2x`, or `1r` adjusts automatically. Tokens are injected as `:root` CSS custom properties when the first style is rendered. You can also use standard CSS color values such as `rgb(...)`, `hsl(...)`, and named colors directly; `okhsl(...)` is the recommended choice when you want authored colors that stay aligned with Tasty's design-system-oriented workflow.
|
|
116
|
+
|
|
117
|
+
> **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.
|
|
118
|
+
|
|
119
|
+
See [Configuration](configuration.md) for the full `configure()` API — tokens, replace tokens, recipes, custom units, style handlers, and TypeScript extensions.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## ESLint plugin
|
|
124
|
+
|
|
125
|
+
The ESLint plugin catches invalid style properties, bad token references, malformed state keys, and other mistakes at lint time — before they reach the browser.
|
|
126
|
+
|
|
127
|
+
### Install
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pnpm add -D @tenphi/eslint-plugin-tasty
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Configure
|
|
134
|
+
|
|
135
|
+
Add the plugin to your flat config:
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
// eslint.config.js
|
|
139
|
+
import tasty from '@tenphi/eslint-plugin-tasty';
|
|
140
|
+
|
|
141
|
+
export default [
|
|
142
|
+
// ...your other configs
|
|
143
|
+
tasty.configs.recommended,
|
|
144
|
+
];
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### What `recommended` catches
|
|
148
|
+
|
|
149
|
+
The `recommended` config enables 18 of the plugin's 27 total rules. It covers the most common issues without turning on the stricter governance rules:
|
|
150
|
+
|
|
151
|
+
| Category | Rules | Examples |
|
|
152
|
+
|----------|-------|---------|
|
|
153
|
+
| Property validation | `known-property`, `valid-boolean-property`, `valid-sub-element` | Flags typos like `pading` or invalid boolean usage |
|
|
154
|
+
| Value validation | `valid-value`, `valid-color-token`, `valid-custom-unit` | Catches `#nonexistent` tokens, bad unit syntax |
|
|
155
|
+
| State validation | `valid-state-key`, `no-nested-state-map`, `require-default-state` | Validates state key syntax, ensures `''` default exists |
|
|
156
|
+
| Structure | `valid-styles-structure`, `no-important`, `no-nested-selector` | Prevents `!important`, invalid nesting |
|
|
157
|
+
| Static mode | `static-no-dynamic-values`, `static-valid-selector` | Enforces build-time constraints in `tastyStatic()` |
|
|
158
|
+
| Style properties | `valid-preset`, `valid-recipe`, `valid-transition`, `valid-directional-modifier`, `valid-radius-shape` | Validates preset names, recipe references, transition syntax |
|
|
159
|
+
|
|
160
|
+
### Strict config
|
|
161
|
+
|
|
162
|
+
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:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
export default [
|
|
166
|
+
tasty.configs.strict,
|
|
167
|
+
];
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Editor support
|
|
173
|
+
|
|
174
|
+
**[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.
|
|
175
|
+
|
|
176
|
+
**[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.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Choosing a rendering mode
|
|
181
|
+
|
|
182
|
+
Tasty has two styling approaches. Pick the one that fits your use case, then decide whether your runtime setup also needs server rendering support:
|
|
183
|
+
|
|
184
|
+
| Approach | Entry point | Best for | Trade-off |
|
|
185
|
+
|------|-------------|----------|-----------|
|
|
186
|
+
| **Runtime** | `tasty()` from `@tenphi/tasty` | Interactive apps with reusable stateful components, design systems | CSS generated at runtime; full feature set (styleProps, sub-elements, variants) |
|
|
187
|
+
| **Zero-runtime** | `tastyStatic()` from `@tenphi/tasty/static` | Static sites, landing pages, SSG | Zero JS overhead; requires Babel plugin; no dynamic props |
|
|
188
|
+
|
|
189
|
+
Both share the same DSL, tokens, units, and state mappings.
|
|
190
|
+
|
|
191
|
+
- Runtime is the default and requires no extra setup beyond `@tenphi/tasty`.
|
|
192
|
+
- If your framework can execute runtime code during server rendering, add SSR support on top of runtime with `@tenphi/tasty/ssr/next`, `@tenphi/tasty/ssr/astro`, or the core SSR API. This still uses `tasty()`; it just collects CSS on the server and hydrates the cache on the client.
|
|
193
|
+
- Zero-runtime requires the Babel plugin and additional peer dependencies. See [Zero Runtime (tastyStatic)](tasty-static.md).
|
|
194
|
+
- SSR works with existing `tasty()` components — wrap your app with a registry, middleware, or collector. See [Server-Side Rendering](ssr.md).
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Next steps
|
|
199
|
+
|
|
200
|
+
- **[Docs Hub](README.md)** — Pick the next guide by role, styling approach, or task
|
|
201
|
+
- **[Methodology](methodology.md)** — The recommended patterns for structuring Tasty components: sub-elements, styleProps, tokens, extension
|
|
202
|
+
- **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
|
|
203
|
+
- **[Runtime API](runtime.md)** — `tasty()` factory, component props, variants, sub-elements, style functions
|
|
204
|
+
- **[Building a Design System](design-system.md)** — Practical guide to building a DS layer with Tasty: tokens, recipes, primitives, compound components
|
|
205
|
+
- **[Adoption Guide](adoption.md)** — Roll out Tasty inside an existing design system or platform team
|
|
206
|
+
- **[Comparison](comparison.md)** — Evaluate Tasty against other styling systems
|
|
207
|
+
- **[Configuration](configuration.md)** — Full `configure()` API: tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
208
|
+
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
209
|
+
- **[Debug Utilities](debug.md)** — Inspect generated CSS and debug runtime behavior when styles do not look right
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Common issues
|
|
214
|
+
|
|
215
|
+
- Styles are missing on first render: make sure the file that calls `configure()` is imported before any `tasty()` component renders.
|
|
216
|
+
- Token or unit values are not what you expect: check your `configure({ tokens, units })` setup, then inspect the generated CSS variables with [Debug Utilities](debug.md).
|
|
217
|
+
- You need build-time extraction or server-rendered CSS delivery: use [Zero Runtime (tastyStatic)](tasty-static.md) for extraction, or add [Server-Side Rendering](ssr.md) on top of runtime `tasty()` when your framework renders on the server.
|
package/docs/injector.md
CHANGED
|
@@ -115,11 +115,13 @@ dispose();
|
|
|
115
115
|
|
|
116
116
|
### `useRawCSS(css, options?)` or `useRawCSS(factory, deps, options?)`
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
Inject raw CSS without parsing. Hook-free — works in client components, SSR, and React Server Components.
|
|
119
119
|
|
|
120
120
|
Supports two overloads:
|
|
121
|
-
- **Static CSS**: `useRawCSS(cssString, options?)`
|
|
122
|
-
- **Factory function**: `useRawCSS(() => cssString, deps, options?)`
|
|
121
|
+
- **Static CSS**: `useRawCSS(cssString, options?)` — content-based deduplication
|
|
122
|
+
- **Factory function**: `useRawCSS(() => cssString, deps, options?)` — factory called on every invocation, dedup handled internally
|
|
123
|
+
|
|
124
|
+
Use the `id` option for update tracking — when the CSS changes for the same id, the previous injection is replaced:
|
|
123
125
|
|
|
124
126
|
```tsx
|
|
125
127
|
import { useRawCSS } from '@tenphi/tasty';
|
|
@@ -132,7 +134,7 @@ function GlobalReset() {
|
|
|
132
134
|
return null;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
// Dynamic CSS with factory function
|
|
137
|
+
// Dynamic CSS with factory function and update tracking
|
|
136
138
|
function ThemeStyles({ theme }: { theme: 'dark' | 'light' }) {
|
|
137
139
|
useRawCSS(() => `
|
|
138
140
|
body {
|
|
@@ -140,7 +142,7 @@ function ThemeStyles({ theme }: { theme: 'dark' | 'light' }) {
|
|
|
140
142
|
background: ${theme === 'dark' ? '#000' : '#fff'};
|
|
141
143
|
color: ${theme === 'dark' ? '#fff' : '#000'};
|
|
142
144
|
}
|
|
143
|
-
`, [theme]);
|
|
145
|
+
`, [theme], { id: 'theme-body' });
|
|
144
146
|
|
|
145
147
|
return null;
|
|
146
148
|
}
|
|
@@ -199,7 +201,7 @@ slideIn.dispose(); // Immediate keyframes deletion from DOM
|
|
|
199
201
|
|
|
200
202
|
### `configure(config): void`
|
|
201
203
|
|
|
202
|
-
Configures the Tasty style system.
|
|
204
|
+
Configures the Tasty style system. `configure()` is optional, but if you use it, it must be called **before** any styles are generated (before first render).
|
|
203
205
|
|
|
204
206
|
```typescript
|
|
205
207
|
import { configure } from '@tenphi/tasty';
|
|
@@ -207,16 +209,15 @@ import { configure } from '@tenphi/tasty';
|
|
|
207
209
|
configure({
|
|
208
210
|
devMode: true, // Enable development features (auto-detected)
|
|
209
211
|
maxRulesPerSheet: 8192, // Cap rules per stylesheet (default: 8192)
|
|
210
|
-
unusedStylesThreshold: 500, // Trigger cleanup threshold (CSS rules only)
|
|
211
|
-
bulkCleanupDelay: 5000, // Cleanup delay (ms) - ignored if idleCleanup is true
|
|
212
|
-
idleCleanup: true, // Use requestIdleCallback for cleanup
|
|
213
|
-
bulkCleanupBatchRatio: 0.5, // Clean up oldest 50% per batch
|
|
214
|
-
unusedStylesMinAgeMs: 10000, // Minimum age before cleanup (ms)
|
|
215
212
|
forceTextInjection: false, // Force textContent insertion (auto-detected for tests)
|
|
216
213
|
nonce: 'csp-nonce', // CSP nonce for security
|
|
214
|
+
gc: { // Garbage collection for unused styles
|
|
215
|
+
touchInterval: 1000, // Touch events between GC cycles (default: 1000)
|
|
216
|
+
capacity: 1000, // Max unused styles to retain (default: 1000)
|
|
217
|
+
},
|
|
217
218
|
states: { // Global predefined states for advanced state mapping
|
|
218
219
|
'@mobile': '@media(w < 768px)',
|
|
219
|
-
'@dark': '@root(
|
|
220
|
+
'@dark': '@root(schema=dark)',
|
|
220
221
|
},
|
|
221
222
|
});
|
|
222
223
|
```
|
|
@@ -229,7 +230,8 @@ configure({
|
|
|
229
230
|
- Most options have sensible defaults and auto-detection
|
|
230
231
|
- `configure()` is optional - the injector works with defaults
|
|
231
232
|
- **Configuration is locked after styles are generated** - calling `configure()` after first render will emit a warning and be ignored
|
|
232
|
-
- `
|
|
233
|
+
- `gc.touchInterval`: Number of touch events between GC cycles. Each style render counts as a touch. When the counter reaches this value, GC is scheduled via `requestIdleCallback`.
|
|
234
|
+
- `gc.capacity`: Maximum number of unused styles (refCount = 0, not in DOM) to retain. When exceeded, the oldest are evicted first. Actively referenced styles don't count against this limit.
|
|
233
235
|
|
|
234
236
|
---
|
|
235
237
|
|
|
@@ -291,21 +293,34 @@ comp3.dispose(); // refCount: 1 → 0, eligible for bulk cleanup
|
|
|
291
293
|
// Next inject() with same styles will increment refCount and reuse immediately
|
|
292
294
|
```
|
|
293
295
|
|
|
294
|
-
###
|
|
296
|
+
### Garbage Collection
|
|
295
297
|
|
|
296
298
|
```typescript
|
|
297
|
-
import { configure } from '@tenphi/tasty';
|
|
299
|
+
import { configure, gc } from '@tenphi/tasty';
|
|
298
300
|
|
|
299
|
-
// CSS rules: Not immediately deleted, marked for bulk cleanup (refCount = 0)
|
|
300
301
|
// Keyframes: Disposed immediately when refCount = 0 (safer for global scope)
|
|
302
|
+
// CSS rules: Tracked by touch count and cleaned up via gc()
|
|
301
303
|
|
|
302
304
|
configure({
|
|
303
|
-
|
|
304
|
-
|
|
305
|
+
gc: {
|
|
306
|
+
touchInterval: 1000, // Schedule GC every 1000 touches
|
|
307
|
+
capacity: 1000, // Max unused styles to retain
|
|
308
|
+
},
|
|
305
309
|
});
|
|
306
310
|
|
|
311
|
+
// Manual GC (synchronous, returns number of swept styles):
|
|
312
|
+
gc();
|
|
313
|
+
|
|
314
|
+
// Force-remove ALL unused styles (e.g. on route change or test teardown):
|
|
315
|
+
gc({ force: true });
|
|
316
|
+
|
|
317
|
+
// GC is also triggered automatically by touch count during rendering.
|
|
318
|
+
// Every `touchInterval` touches, GC is scheduled via requestIdleCallback.
|
|
319
|
+
|
|
307
320
|
// Benefits:
|
|
308
|
-
// -
|
|
321
|
+
// - Activity-proportional: busy apps trigger GC more often
|
|
322
|
+
// - DOM-safe: styles currently in the DOM are never evicted
|
|
323
|
+
// - Oldest-first: least recently used styles are evicted first
|
|
309
324
|
// - Keyframes: Immediate cleanup prevents global namespace pollution
|
|
310
325
|
// - Unused styles can be instantly reactivated (just increment refCount)
|
|
311
326
|
```
|
|
@@ -462,13 +477,14 @@ injectGlobal([
|
|
|
462
477
|
{ selector: '.container', declarations: 'max-width: 1200px;' }
|
|
463
478
|
]);
|
|
464
479
|
|
|
465
|
-
// ✅ Configure
|
|
480
|
+
// ✅ Configure GC for your app (BEFORE first render!)
|
|
466
481
|
import { configure } from '@tenphi/tasty';
|
|
467
482
|
|
|
468
483
|
configure({
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
484
|
+
gc: {
|
|
485
|
+
touchInterval: 1000, // Schedule GC every 1000 style touches
|
|
486
|
+
capacity: 1000, // Max unused styles to retain
|
|
487
|
+
},
|
|
472
488
|
});
|
|
473
489
|
```
|
|
474
490
|
|
|
@@ -480,8 +496,8 @@ configure({
|
|
|
480
496
|
// 1. Hash-based deduplication - same CSS = same className
|
|
481
497
|
// 2. Reference counting - styles stay alive while in use (refCount > 0)
|
|
482
498
|
// 3. Immediate keyframes cleanup - disposed instantly when refCount = 0
|
|
483
|
-
// 4.
|
|
484
|
-
// 5.
|
|
499
|
+
// 4. Touch-count GC - unused CSS rules are evicted oldest-first when over capacity
|
|
500
|
+
// 5. DOM safety guard - styles visible in the DOM are never evicted
|
|
485
501
|
|
|
486
502
|
// Manual cleanup is rarely needed but available:
|
|
487
503
|
cleanup(); // Force immediate cleanup of all unused CSS rules (refCount = 0)
|
|
@@ -511,7 +527,7 @@ const StyledButton = tasty({
|
|
|
511
527
|
// 4. dispose() is called when component unmounts
|
|
512
528
|
```
|
|
513
529
|
|
|
514
|
-
For most development, you'll use the [
|
|
530
|
+
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
531
|
|
|
516
532
|
---
|
|
517
533
|
|
|
@@ -525,4 +541,4 @@ Direct injector usage is recommended for:
|
|
|
525
541
|
- **Performance-critical scenarios** where you need direct control
|
|
526
542
|
- **Testing utilities** that need to inject or extract CSS
|
|
527
543
|
|
|
528
|
-
For regular component styling, prefer the [`tasty()` API](./
|
|
544
|
+
For regular component styling, prefer the [`tasty()` API](./runtime.md) which provides a more developer-friendly interface.
|