@unpunnyfuns/swatchbook-blocks 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 +105 -0
- package/dist/index.d.mts +544 -0
- package/dist/index.mjs +3908 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Unpunny Funs
|
|
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,105 @@
|
|
|
1
|
+
# Blocks
|
|
2
|
+
|
|
3
|
+
Published as `@unpunnyfuns/swatchbook-blocks`. Storybook MDX doc blocks for DTCG design tokens. React components for rendering token documentation inside `.mdx` pages or regular stories. Self-mount the addon's CSS and react to axis changes from the toolbar; work inside the docs container even though story decorators don't.
|
|
4
|
+
|
|
5
|
+
> **Documentation:** [unpunnyfuns.github.io/swatchbook](https://unpunnyfuns.github.io/swatchbook/). Token parsing powered by [Terrazzo](https://terrazzo.app/) by [Drew Powers](https://github.com/drwpow) via `@unpunnyfuns/swatchbook-core`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @unpunnyfuns/swatchbook-blocks
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Blocks read the token graph from a `SwatchbookProvider`. Inside Storybook, register `@unpunnyfuns/swatchbook-addon` alongside these blocks — its preview decorator mounts the provider automatically. Outside Storybook, wrap your tree in `SwatchbookProvider` and pass a `ProjectSnapshot` directly (see [Outside Storybook](#outside-storybook) below).
|
|
14
|
+
|
|
15
|
+
## Blocks
|
|
16
|
+
|
|
17
|
+
| Block | What |
|
|
18
|
+
| ------------------- | ----------------------------------------------------------------------------------- |
|
|
19
|
+
| `TokenTable` | Searchable table of tokens, filterable by path glob and `$type`. |
|
|
20
|
+
| `TokenNavigator` | Expandable tree view of the token graph keyed on dot-path segments, with inline per-type previews. |
|
|
21
|
+
| `ColorPalette` | Swatch grid grouped by sub-path. Auto-groups from the filter; `groupBy` overrides. |
|
|
22
|
+
| `TypographyScale` | Each typography composite token rendered as a sample line using its own value. |
|
|
23
|
+
| `FontFamilySample` | Pangram rendered per `fontFamily` primitive. |
|
|
24
|
+
| `FontWeightScale` | Same sample text rendered at each `fontWeight` primitive, sorted ascending. |
|
|
25
|
+
| `StrokeStyleSample` | Border rendered per `strokeStyle` primitive. |
|
|
26
|
+
| `GradientPalette` | Wide swatch per `gradient` token with stop breakdown (linear-gradient default). |
|
|
27
|
+
| `MotionSample` | Animated ball + track for one `transition` / `duration` / `cubicBezier` token. Accepts `speed` / `runKey`. |
|
|
28
|
+
| `ShadowSample` | Surface rectangle with one `shadow` token applied as `box-shadow`. |
|
|
29
|
+
| `BorderSample` | Surface rectangle with one `border` token applied as `border`. |
|
|
30
|
+
| `DimensionBar` | Width-driven bar (or square / radius sample, via `kind`) for one `dimension` token. |
|
|
31
|
+
| `TokenDetail` | Single-token inspector — composition of the subcomponents below. |
|
|
32
|
+
| `TokenHeader` | Heading + `$type` pill + cssVar + `$description`, or a missing-token empty state. |
|
|
33
|
+
| `CompositePreview` | Type-dispatched live preview (typography, shadow, border, transition, dimension, duration, cubicBezier, fontFamily, fontWeight, strokeStyle, gradient, color). |
|
|
34
|
+
| `CompositeBreakdown`| Labelled sub-value grid for composite types (typography / border / transition / shadow / gradient). |
|
|
35
|
+
| `AliasChain` | Forward alias chain (`path → alias → …`). Renders nothing for non-aliases. |
|
|
36
|
+
| `AliasedBy` | Aliased-by tree (backward). Truncates at depth 6. |
|
|
37
|
+
| `AxisVariance` | Per-axis value table — constant, one-axis, or two-axis matrix view. |
|
|
38
|
+
| `TokenUsageSnippet` | Copy-ready `color: var(--…);` snippet. |
|
|
39
|
+
|
|
40
|
+
Shared: every block accepts a `caption` override and renders against the addon's `var(--<prefix>-…)` output.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Inside Storybook
|
|
45
|
+
|
|
46
|
+
The addon's preview decorator wraps every story in a `SwatchbookProvider` for you, so MDX and story authors drop blocks in directly:
|
|
47
|
+
|
|
48
|
+
```mdx
|
|
49
|
+
import { TokenTable, ColorPalette, TokenDetail } from '@unpunnyfuns/swatchbook-blocks';
|
|
50
|
+
|
|
51
|
+
# Color tokens
|
|
52
|
+
|
|
53
|
+
<ColorPalette filter="color.sys.*" />
|
|
54
|
+
|
|
55
|
+
## Every color token
|
|
56
|
+
|
|
57
|
+
<TokenTable filter="color.sys.*" type="color" />
|
|
58
|
+
|
|
59
|
+
## Inspect one
|
|
60
|
+
|
|
61
|
+
<TokenDetail path="color.sys.accent.bg" />
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Outside Storybook
|
|
65
|
+
|
|
66
|
+
Blocks are pure presentation — given a `ProjectSnapshot` they render without any Storybook or Vite plugin. Mount a `SwatchbookProvider` at the top of your tree:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { SwatchbookProvider, TokenTable } from '@unpunnyfuns/swatchbook-blocks';
|
|
70
|
+
import snapshot from './tokens-snapshot.json';
|
|
71
|
+
|
|
72
|
+
export function TokenDocs() {
|
|
73
|
+
return (
|
|
74
|
+
<SwatchbookProvider value={snapshot}>
|
|
75
|
+
<TokenTable filter='color.sys.*' />
|
|
76
|
+
</SwatchbookProvider>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`SwatchbookProvider` is the canonical integration point. The `virtual:swatchbook/tokens` module is the Storybook addon's internal wiring, not a public API.
|
|
82
|
+
|
|
83
|
+
## Props
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
<TokenTable filter="color.sys.*" type="color" />
|
|
87
|
+
<ColorPalette filter="color.sys.*" />
|
|
88
|
+
<TypographyScale filter="typography" sample="The quick brown fox" />
|
|
89
|
+
<TokenDetail path="color.sys.accent.bg" />
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Do / don't
|
|
93
|
+
|
|
94
|
+
- ✅ React to the active swatchbook theme — switching in the toolbar updates resolved values live, even on MDX docs pages.
|
|
95
|
+
- ✅ Compose multiple blocks per MDX page — each mounts independently.
|
|
96
|
+
- ✅ Render blocks outside Storybook by wrapping them in `SwatchbookProvider` with a hand-built or loaded `ProjectSnapshot`.
|
|
97
|
+
- ❌ Don't import from `virtual:swatchbook/tokens` directly — it's the addon's internal wiring, not a public API. Use `SwatchbookProvider` instead.
|
|
98
|
+
- ❌ Don't use `useGlobals` / `useArgs` from `storybook/preview-api` inside custom blocks you write — those are story-only hooks and throw in docs context. Subscribe to `addons.getChannel()` directly for globals reactivity.
|
|
99
|
+
|
|
100
|
+
## See also
|
|
101
|
+
|
|
102
|
+
- [`@unpunnyfuns/swatchbook-addon`](../addon) — required peer. Registers the virtual module and the toolbar.
|
|
103
|
+
- [`@unpunnyfuns/swatchbook-core`](../core) — underlying loader.
|
|
104
|
+
- [Project README](../../README.md) — install and wiring flow for the whole toolchain.
|
|
105
|
+
- [Documentation](https://unpunnyfuns.github.io/swatchbook/) — concepts, guides, and full API reference.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import * as _$react from "react";
|
|
2
|
+
import { ReactElement, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/format-color.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Color display formats understood by {@link formatColor}.
|
|
7
|
+
*
|
|
8
|
+
* - `hex` — sRGB hex (`#rrggbb` or `#rrggbbaa`). Out-of-gamut or wide-gamut
|
|
9
|
+
* colors fall back to `rgb()` and surface `outOfGamut: true` so callers
|
|
10
|
+
* can render a ⚠ glyph.
|
|
11
|
+
* - `rgb` / `hsl` — modern CSS Color 4 space-separated syntax, converted
|
|
12
|
+
* from the source colorspace. Out-of-gamut values are still stringified
|
|
13
|
+
* (the browser will clip when actually rendering) and flagged.
|
|
14
|
+
* - `oklch` — perceptual wide-gamut form. Never marks out-of-gamut because
|
|
15
|
+
* every color expressible in sRGB/P3 fits in oklch.
|
|
16
|
+
* - `raw` — compact JSON of the normalized Terrazzo shape. For DTCG
|
|
17
|
+
* authors who want to see what the parser actually stored.
|
|
18
|
+
*/
|
|
19
|
+
type ColorFormat = 'hex' | 'rgb' | 'hsl' | 'oklch' | 'raw';
|
|
20
|
+
declare const COLOR_FORMATS: readonly ColorFormat[];
|
|
21
|
+
/**
|
|
22
|
+
* Terrazzo's `ColorValueNormalized`, copied inline to avoid a hard dep on
|
|
23
|
+
* `@terrazzo/token-tools` from blocks. Matches the shape documented at
|
|
24
|
+
* https://terrazzo.app/docs/cli/reference/token-tools/ColorValueNormalized.
|
|
25
|
+
*
|
|
26
|
+
* Some token payloads we see in the wild use the legacy DTCG-ish `channels`
|
|
27
|
+
* field in place of `components`; we accept either.
|
|
28
|
+
*/
|
|
29
|
+
interface NormalizedColor {
|
|
30
|
+
colorSpace: string;
|
|
31
|
+
components?: readonly (number | null)[];
|
|
32
|
+
channels?: readonly (number | null)[];
|
|
33
|
+
alpha?: number;
|
|
34
|
+
hex?: string;
|
|
35
|
+
}
|
|
36
|
+
interface FormatColorResult {
|
|
37
|
+
/** Display string — e.g. `rgb(59 132 246)`, `#3b82f6`. */
|
|
38
|
+
value: string;
|
|
39
|
+
/** True when the requested format can't losslessly represent the color. */
|
|
40
|
+
outOfGamut: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convert Terrazzo's normalized color payload into a display string in the
|
|
44
|
+
* requested format. Pure function — never throws; returns `{ value: '—' }`
|
|
45
|
+
* for unrecognized input so calling blocks don't need try/catch.
|
|
46
|
+
*/
|
|
47
|
+
declare function formatColor(value: unknown, format: ColorFormat, fallback?: string): FormatColorResult;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/BorderPreview.d.ts
|
|
50
|
+
interface BorderPreviewProps {
|
|
51
|
+
/**
|
|
52
|
+
* Token-path filter. Defaults to every `border` token. Use e.g.
|
|
53
|
+
* `"border.sys.*"` to scope to the semantic layer.
|
|
54
|
+
*/
|
|
55
|
+
filter?: string;
|
|
56
|
+
/** Override the caption. */
|
|
57
|
+
caption?: string;
|
|
58
|
+
}
|
|
59
|
+
declare function BorderPreview({
|
|
60
|
+
filter,
|
|
61
|
+
caption
|
|
62
|
+
}: BorderPreviewProps): ReactElement;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/border-preview/BorderSample.d.ts
|
|
65
|
+
interface BorderSampleProps {
|
|
66
|
+
/** Full dot-path of the border token to preview. */
|
|
67
|
+
path: string;
|
|
68
|
+
}
|
|
69
|
+
declare function BorderSample({
|
|
70
|
+
path
|
|
71
|
+
}: BorderSampleProps): ReactElement;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/ColorPalette.d.ts
|
|
74
|
+
interface ColorPaletteProps {
|
|
75
|
+
/**
|
|
76
|
+
* Token-path filter. Defaults to every `color` token. Use e.g.
|
|
77
|
+
* `"color.sys.*"` to scope to the semantic layer, or `"color.ref.blue.*"`
|
|
78
|
+
* for a single ref ramp.
|
|
79
|
+
*/
|
|
80
|
+
filter?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Grouping depth. Tokens are grouped by the first `groupBy` dot-segments
|
|
83
|
+
* of their path. `2` yields groups like `color.sys`, `color.ref`; `3`
|
|
84
|
+
* yields `color.sys.surface`, `color.sys.text`, etc.
|
|
85
|
+
*
|
|
86
|
+
* If omitted, groupBy is derived from the filter: one level below the
|
|
87
|
+
* filter's fixed prefix (segments before the first `*`), clamped so each
|
|
88
|
+
* swatch still carries a leaf label. `"color.sys.*"` → groups at
|
|
89
|
+
* `color.sys.<family>`; `"color.ref.blue.*"` collapses all shades into
|
|
90
|
+
* one `color.ref.blue` group because the tokens have no deeper level.
|
|
91
|
+
*/
|
|
92
|
+
groupBy?: number;
|
|
93
|
+
/** Override the section caption. */
|
|
94
|
+
caption?: string;
|
|
95
|
+
}
|
|
96
|
+
declare function ColorPalette({
|
|
97
|
+
filter,
|
|
98
|
+
groupBy,
|
|
99
|
+
caption
|
|
100
|
+
}: ColorPaletteProps): ReactElement;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/dimension-scale/DimensionBar.d.ts
|
|
103
|
+
type DimensionKind = 'length' | 'radius' | 'size';
|
|
104
|
+
interface DimensionBarProps {
|
|
105
|
+
/** Full dot-path of the dimension token to preview. */
|
|
106
|
+
path: string;
|
|
107
|
+
/**
|
|
108
|
+
* Visualization kind:
|
|
109
|
+
* - `'length'` (default): horizontal bar whose width equals the token's dimension.
|
|
110
|
+
* - `'radius'`: 56×56 square with the token applied as `border-radius`.
|
|
111
|
+
* - `'size'`: a square sized to the token's dimension.
|
|
112
|
+
*/
|
|
113
|
+
kind?: DimensionKind;
|
|
114
|
+
}
|
|
115
|
+
declare function DimensionBar({
|
|
116
|
+
path,
|
|
117
|
+
kind
|
|
118
|
+
}: DimensionBarProps): ReactElement;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/DimensionScale.d.ts
|
|
121
|
+
interface DimensionScaleProps {
|
|
122
|
+
/**
|
|
123
|
+
* Token-path filter. Defaults to every `dimension` token. Use e.g.
|
|
124
|
+
* `"space.sys.*"` to scope to the spacing scale.
|
|
125
|
+
*/
|
|
126
|
+
filter?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Visualization kind:
|
|
129
|
+
* - `'length'` (default): horizontal bar whose width equals the token's dimension.
|
|
130
|
+
* - `'radius'`: 56×56 square with the token applied as `border-radius`.
|
|
131
|
+
* - `'size'`: a square sized to the token's dimension.
|
|
132
|
+
*/
|
|
133
|
+
kind?: DimensionKind;
|
|
134
|
+
/** Override the caption. */
|
|
135
|
+
caption?: string;
|
|
136
|
+
}
|
|
137
|
+
declare function DimensionScale({
|
|
138
|
+
filter,
|
|
139
|
+
kind,
|
|
140
|
+
caption
|
|
141
|
+
}: DimensionScaleProps): ReactElement;
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/FontFamilySample.d.ts
|
|
144
|
+
interface FontFamilySampleProps {
|
|
145
|
+
/**
|
|
146
|
+
* Token-path filter. Defaults to every `fontFamily` token. Use e.g.
|
|
147
|
+
* `"font.ref.family.*"` to scope to the ref layer.
|
|
148
|
+
*/
|
|
149
|
+
filter?: string;
|
|
150
|
+
/** Override the sample text rendered for each token. */
|
|
151
|
+
sample?: string;
|
|
152
|
+
/** Override the caption. */
|
|
153
|
+
caption?: string;
|
|
154
|
+
}
|
|
155
|
+
declare function FontFamilySample({
|
|
156
|
+
filter,
|
|
157
|
+
sample,
|
|
158
|
+
caption
|
|
159
|
+
}: FontFamilySampleProps): ReactElement;
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/FontWeightScale.d.ts
|
|
162
|
+
interface FontWeightScaleProps {
|
|
163
|
+
/**
|
|
164
|
+
* Token-path filter. Defaults to every `fontWeight` token. Use e.g.
|
|
165
|
+
* `"font.ref.weight.*"` to scope to the ref layer.
|
|
166
|
+
*/
|
|
167
|
+
filter?: string;
|
|
168
|
+
/** Override the sample text rendered for each token. */
|
|
169
|
+
sample?: string;
|
|
170
|
+
/** Override the caption. */
|
|
171
|
+
caption?: string;
|
|
172
|
+
}
|
|
173
|
+
declare function FontWeightScale({
|
|
174
|
+
filter,
|
|
175
|
+
sample,
|
|
176
|
+
caption
|
|
177
|
+
}: FontWeightScaleProps): ReactElement;
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/GradientPalette.d.ts
|
|
180
|
+
interface GradientPaletteProps {
|
|
181
|
+
/**
|
|
182
|
+
* Token-path filter. Defaults to every `gradient` token. Use e.g.
|
|
183
|
+
* `"gradient.ref.*"` or `"gradient.sys.accent"` to scope.
|
|
184
|
+
*/
|
|
185
|
+
filter?: string;
|
|
186
|
+
/** Override the caption. */
|
|
187
|
+
caption?: string;
|
|
188
|
+
}
|
|
189
|
+
declare function GradientPalette({
|
|
190
|
+
filter,
|
|
191
|
+
caption
|
|
192
|
+
}: GradientPaletteProps): ReactElement;
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/motion-preview/MotionSample.d.ts
|
|
195
|
+
type MotionSpeed = 0.25 | 0.5 | 1 | 2;
|
|
196
|
+
interface MotionSampleProps {
|
|
197
|
+
/** Full dot-path of the motion token (`transition`, `duration`, or `cubicBezier`). */
|
|
198
|
+
path: string;
|
|
199
|
+
/** Playback speed multiplier. Defaults to `1`. */
|
|
200
|
+
speed?: MotionSpeed;
|
|
201
|
+
/**
|
|
202
|
+
* Change this value to force the animation to restart. Useful when an
|
|
203
|
+
* outer block exposes a "replay" button that should re-trigger every
|
|
204
|
+
* sample at once.
|
|
205
|
+
*/
|
|
206
|
+
runKey?: number;
|
|
207
|
+
}
|
|
208
|
+
declare function MotionSample({
|
|
209
|
+
path,
|
|
210
|
+
speed,
|
|
211
|
+
runKey
|
|
212
|
+
}: MotionSampleProps): ReactElement;
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/MotionPreview.d.ts
|
|
215
|
+
interface MotionPreviewProps {
|
|
216
|
+
/**
|
|
217
|
+
* Token-path filter. Defaults to transition + duration + cubicBezier
|
|
218
|
+
* tokens. Use e.g. `"motion.sys.*"` to scope to the semantic layer.
|
|
219
|
+
*/
|
|
220
|
+
filter?: string;
|
|
221
|
+
/** Override the caption. */
|
|
222
|
+
caption?: string;
|
|
223
|
+
}
|
|
224
|
+
declare function MotionPreview({
|
|
225
|
+
filter,
|
|
226
|
+
caption
|
|
227
|
+
}: MotionPreviewProps): ReactElement;
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/contexts.d.ts
|
|
230
|
+
/**
|
|
231
|
+
* Typed shape of the addon's `virtual:swatchbook/tokens` module, duplicated
|
|
232
|
+
* as value-importable interfaces so consumers outside the addon's Vite
|
|
233
|
+
* plugin (unit tests, custom React apps) can construct a snapshot by hand.
|
|
234
|
+
*
|
|
235
|
+
* The ambient `declare module 'virtual:swatchbook/tokens'` declarations in
|
|
236
|
+
* `packages/addon/src/virtual.d.ts` describe the same payload; the two
|
|
237
|
+
* stay in sync by eye.
|
|
238
|
+
*/
|
|
239
|
+
interface VirtualAxisShape {
|
|
240
|
+
name: string;
|
|
241
|
+
contexts: readonly string[];
|
|
242
|
+
default: string;
|
|
243
|
+
description?: string;
|
|
244
|
+
source: 'resolver' | 'synthetic';
|
|
245
|
+
}
|
|
246
|
+
interface VirtualThemeShape {
|
|
247
|
+
name: string;
|
|
248
|
+
input: Record<string, string>;
|
|
249
|
+
sources: string[];
|
|
250
|
+
}
|
|
251
|
+
interface VirtualDiagnosticShape {
|
|
252
|
+
severity: 'error' | 'warn' | 'info';
|
|
253
|
+
group: string;
|
|
254
|
+
message: string;
|
|
255
|
+
filename?: string;
|
|
256
|
+
line?: number;
|
|
257
|
+
column?: number;
|
|
258
|
+
}
|
|
259
|
+
interface VirtualTokenShape {
|
|
260
|
+
$type?: string;
|
|
261
|
+
$value?: unknown;
|
|
262
|
+
$description?: string;
|
|
263
|
+
aliasOf?: string;
|
|
264
|
+
aliasChain?: readonly string[];
|
|
265
|
+
aliasedBy?: readonly string[];
|
|
266
|
+
}
|
|
267
|
+
interface VirtualPresetShape {
|
|
268
|
+
name: string;
|
|
269
|
+
axes: Partial<Record<string, string>>;
|
|
270
|
+
description?: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Full project data read by blocks. Populated by the addon's preview
|
|
274
|
+
* decorator (from the virtual module) or constructed by hand in
|
|
275
|
+
* non-Storybook consumers.
|
|
276
|
+
*/
|
|
277
|
+
interface ProjectSnapshot {
|
|
278
|
+
axes: readonly VirtualAxisShape[];
|
|
279
|
+
/** Axis names suppressed via `config.disabledAxes` — pinned to their defaults, hidden from the toolbar. */
|
|
280
|
+
disabledAxes: readonly string[];
|
|
281
|
+
presets: readonly VirtualPresetShape[];
|
|
282
|
+
themes: readonly VirtualThemeShape[];
|
|
283
|
+
themesResolved: Record<string, Record<string, VirtualTokenShape>>;
|
|
284
|
+
activeTheme: string;
|
|
285
|
+
activeAxes: Readonly<Record<string, string>>;
|
|
286
|
+
cssVarPrefix: string;
|
|
287
|
+
diagnostics: readonly VirtualDiagnosticShape[];
|
|
288
|
+
css: string;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Context carrying the full {@link ProjectSnapshot}. `null` sentinel lets
|
|
292
|
+
* `useSwatchbookData()` tell "provider present" from "fall back to the
|
|
293
|
+
* virtual module".
|
|
294
|
+
*/
|
|
295
|
+
declare const SwatchbookContext: _$react.Context<ProjectSnapshot | null>;
|
|
296
|
+
declare function useOptionalSwatchbookData(): ProjectSnapshot | null;
|
|
297
|
+
/**
|
|
298
|
+
* Active swatchbook theme for the current story/docs render. Populated by
|
|
299
|
+
* the addon's preview decorator and consumed by `useToken` + any future
|
|
300
|
+
* consumer hooks.
|
|
301
|
+
*
|
|
302
|
+
* This runs through plain React context rather than Storybook's
|
|
303
|
+
* `useGlobals` so the same hook works in autodocs / MDX renders where the
|
|
304
|
+
* preview-hooks context isn't available.
|
|
305
|
+
*/
|
|
306
|
+
declare const ThemeContext: _$react.Context<string>;
|
|
307
|
+
declare function useActiveTheme(): string;
|
|
308
|
+
/**
|
|
309
|
+
* Active axis tuple for the current story/docs render — `Record<axisName,
|
|
310
|
+
* contextName>`. Derived from the same input as {@link ThemeContext}; split
|
|
311
|
+
* out so consumers needing per-axis info (toolbar, panel, tuple-aware
|
|
312
|
+
* blocks) don't have to reparse the composed permutation ID.
|
|
313
|
+
*/
|
|
314
|
+
declare const AxesContext: _$react.Context<Readonly<Record<string, string>>>;
|
|
315
|
+
declare function useActiveAxes(): Readonly<Record<string, string>>;
|
|
316
|
+
/**
|
|
317
|
+
* Active color-display format for the current story/docs render. Populated
|
|
318
|
+
* by the addon's preview decorator from the `swatchbookColorFormat` global
|
|
319
|
+
* (per-story `globals` or toolbar dropdown) and consumed by blocks that
|
|
320
|
+
* render color-token values. Emitted CSS is unaffected.
|
|
321
|
+
*
|
|
322
|
+
* Runs through plain React context rather than Storybook's `useGlobals` so
|
|
323
|
+
* per-story seeded globals flow through on first render and the same hook
|
|
324
|
+
* is safe to call from MDX doc blocks (where the preview-hooks context
|
|
325
|
+
* isn't available).
|
|
326
|
+
*/
|
|
327
|
+
declare const ColorFormatContext: _$react.Context<ColorFormat>;
|
|
328
|
+
declare function useColorFormat(): ColorFormat;
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/provider.d.ts
|
|
331
|
+
interface SwatchbookProviderProps {
|
|
332
|
+
value: ProjectSnapshot;
|
|
333
|
+
children: ReactNode;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Wraps a tree of blocks with the token data they need to render.
|
|
337
|
+
*
|
|
338
|
+
* The Storybook addon's preview decorator mounts this automatically, so
|
|
339
|
+
* story/MDX authors typically never see it. Outside Storybook — unit
|
|
340
|
+
* tests, custom React apps, non-Storybook doc sites — consumers construct
|
|
341
|
+
* a {@link ProjectSnapshot} (often imported from a JSON file) and wrap
|
|
342
|
+
* their blocks in this provider.
|
|
343
|
+
*/
|
|
344
|
+
declare function SwatchbookProvider({
|
|
345
|
+
value,
|
|
346
|
+
children
|
|
347
|
+
}: SwatchbookProviderProps): ReactElement;
|
|
348
|
+
/**
|
|
349
|
+
* Read the current {@link ProjectSnapshot}. Throws if called outside a
|
|
350
|
+
* {@link SwatchbookProvider}; blocks that need to fall back to the
|
|
351
|
+
* virtual module go through the internal `useProject()` hook instead.
|
|
352
|
+
*/
|
|
353
|
+
declare function useSwatchbookData(): ProjectSnapshot;
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/ShadowPreview.d.ts
|
|
356
|
+
interface ShadowPreviewProps {
|
|
357
|
+
/**
|
|
358
|
+
* Token-path filter. Defaults to every `shadow` token. Use e.g.
|
|
359
|
+
* `"shadow.sys.*"` to scope to the semantic layer.
|
|
360
|
+
*/
|
|
361
|
+
filter?: string;
|
|
362
|
+
/** Override the caption. */
|
|
363
|
+
caption?: string;
|
|
364
|
+
}
|
|
365
|
+
declare function ShadowPreview({
|
|
366
|
+
filter,
|
|
367
|
+
caption
|
|
368
|
+
}: ShadowPreviewProps): ReactElement;
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/shadow-preview/ShadowSample.d.ts
|
|
371
|
+
interface ShadowSampleProps {
|
|
372
|
+
/** Full dot-path of the shadow token to preview. */
|
|
373
|
+
path: string;
|
|
374
|
+
}
|
|
375
|
+
declare function ShadowSample({
|
|
376
|
+
path
|
|
377
|
+
}: ShadowSampleProps): ReactElement;
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/StrokeStyleSample.d.ts
|
|
380
|
+
interface StrokeStyleSampleProps {
|
|
381
|
+
/**
|
|
382
|
+
* Token-path filter. Defaults to every `strokeStyle` token. Use e.g.
|
|
383
|
+
* `"stroke.ref.style.*"` to scope to the ref layer.
|
|
384
|
+
*/
|
|
385
|
+
filter?: string;
|
|
386
|
+
/** Override the caption. */
|
|
387
|
+
caption?: string;
|
|
388
|
+
}
|
|
389
|
+
declare function StrokeStyleSample({
|
|
390
|
+
filter,
|
|
391
|
+
caption
|
|
392
|
+
}: StrokeStyleSampleProps): ReactElement;
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/TokenDetail.d.ts
|
|
395
|
+
interface TokenDetailProps {
|
|
396
|
+
/** Full dot-path of the token to inspect. */
|
|
397
|
+
path: string;
|
|
398
|
+
/** Override the heading. Defaults to the path. */
|
|
399
|
+
heading?: string;
|
|
400
|
+
}
|
|
401
|
+
declare function TokenDetail({
|
|
402
|
+
path,
|
|
403
|
+
heading
|
|
404
|
+
}: TokenDetailProps): ReactElement;
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/token-detail/AliasChain.d.ts
|
|
407
|
+
interface AliasChainProps {
|
|
408
|
+
/** Full dot-path of the token. */
|
|
409
|
+
path: string;
|
|
410
|
+
}
|
|
411
|
+
declare function AliasChain({
|
|
412
|
+
path
|
|
413
|
+
}: AliasChainProps): ReactElement | null;
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/token-detail/AliasedBy.d.ts
|
|
416
|
+
interface AliasedByProps {
|
|
417
|
+
/** Full dot-path of the token. */
|
|
418
|
+
path: string;
|
|
419
|
+
}
|
|
420
|
+
declare function AliasedBy({
|
|
421
|
+
path
|
|
422
|
+
}: AliasedByProps): ReactElement | null;
|
|
423
|
+
//#endregion
|
|
424
|
+
//#region src/token-detail/AxisVariance.d.ts
|
|
425
|
+
interface AxisVarianceProps {
|
|
426
|
+
/** Full dot-path of the token. */
|
|
427
|
+
path: string;
|
|
428
|
+
}
|
|
429
|
+
declare function AxisVariance({
|
|
430
|
+
path
|
|
431
|
+
}: AxisVarianceProps): ReactElement;
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/token-detail/CompositeBreakdown.d.ts
|
|
434
|
+
interface CompositeBreakdownProps {
|
|
435
|
+
/** Full dot-path of the token. */
|
|
436
|
+
path: string;
|
|
437
|
+
}
|
|
438
|
+
declare function CompositeBreakdown({
|
|
439
|
+
path
|
|
440
|
+
}: CompositeBreakdownProps): ReactElement | null;
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/token-detail/CompositePreview.d.ts
|
|
443
|
+
interface CompositePreviewProps {
|
|
444
|
+
/** Full dot-path of the token to preview. */
|
|
445
|
+
path: string;
|
|
446
|
+
}
|
|
447
|
+
declare function CompositePreview({
|
|
448
|
+
path
|
|
449
|
+
}: CompositePreviewProps): ReactElement | null;
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/token-detail/ConsumerOutput.d.ts
|
|
452
|
+
interface ConsumerOutputProps {
|
|
453
|
+
/** Full dot-path of the token. */
|
|
454
|
+
path: string;
|
|
455
|
+
}
|
|
456
|
+
declare function ConsumerOutput({
|
|
457
|
+
path
|
|
458
|
+
}: ConsumerOutputProps): ReactElement | null;
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/token-detail/TokenHeader.d.ts
|
|
461
|
+
interface TokenHeaderProps {
|
|
462
|
+
/** Full dot-path of the token. */
|
|
463
|
+
path: string;
|
|
464
|
+
/** Override the heading. Defaults to the path. */
|
|
465
|
+
heading?: string;
|
|
466
|
+
}
|
|
467
|
+
declare function TokenHeader({
|
|
468
|
+
path,
|
|
469
|
+
heading
|
|
470
|
+
}: TokenHeaderProps): ReactElement;
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/token-detail/TokenUsageSnippet.d.ts
|
|
473
|
+
interface TokenUsageSnippetProps {
|
|
474
|
+
/** Full dot-path of the token. */
|
|
475
|
+
path: string;
|
|
476
|
+
}
|
|
477
|
+
declare function TokenUsageSnippet({
|
|
478
|
+
path
|
|
479
|
+
}: TokenUsageSnippetProps): ReactElement | null;
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/TokenNavigator.d.ts
|
|
482
|
+
interface TokenNavigatorProps {
|
|
483
|
+
/** If provided, mount at this dot-path subtree and hide everything outside it. */
|
|
484
|
+
root?: string;
|
|
485
|
+
/**
|
|
486
|
+
* Depth (from the mounted root) that is expanded on first render.
|
|
487
|
+
* `0` = everything collapsed, `1` = top-level groups open (default),
|
|
488
|
+
* `2` = one level deeper, etc.
|
|
489
|
+
*/
|
|
490
|
+
initiallyExpanded?: number;
|
|
491
|
+
/**
|
|
492
|
+
* Called with a leaf's full dot-path when it is clicked. When set, the
|
|
493
|
+
* inline `<TokenDetail>` slide-over is suppressed — the consumer owns
|
|
494
|
+
* the follow-up UI.
|
|
495
|
+
*/
|
|
496
|
+
onSelect?(path: string): void;
|
|
497
|
+
}
|
|
498
|
+
declare function TokenNavigator({
|
|
499
|
+
root,
|
|
500
|
+
initiallyExpanded,
|
|
501
|
+
onSelect
|
|
502
|
+
}: TokenNavigatorProps): ReactElement;
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/TokenTable.d.ts
|
|
505
|
+
interface TokenTableProps {
|
|
506
|
+
/**
|
|
507
|
+
* Token-path filter. `"color.sys.*"` matches every `color.sys.…` token;
|
|
508
|
+
* omit to include everything. Combines with `type` (both must match).
|
|
509
|
+
*/
|
|
510
|
+
filter?: string;
|
|
511
|
+
/** Restrict to one DTCG `$type`. */
|
|
512
|
+
type?: string;
|
|
513
|
+
/** Show the CSS variable reference column. Defaults to `true`. */
|
|
514
|
+
showVar?: boolean;
|
|
515
|
+
/** Override the table caption. */
|
|
516
|
+
caption?: string;
|
|
517
|
+
}
|
|
518
|
+
declare function TokenTable({
|
|
519
|
+
filter,
|
|
520
|
+
type,
|
|
521
|
+
showVar,
|
|
522
|
+
caption
|
|
523
|
+
}: TokenTableProps): ReactElement;
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region src/TypographyScale.d.ts
|
|
526
|
+
interface TypographyScaleProps {
|
|
527
|
+
/**
|
|
528
|
+
* Token-path filter. Defaults to every `typography` token. Use e.g.
|
|
529
|
+
* `"typography.sys.*"` to scope to the semantic layer.
|
|
530
|
+
*/
|
|
531
|
+
filter?: string;
|
|
532
|
+
/** Override the sample text rendered for each token. */
|
|
533
|
+
sample?: string;
|
|
534
|
+
/** Override the caption. */
|
|
535
|
+
caption?: string;
|
|
536
|
+
}
|
|
537
|
+
declare function TypographyScale({
|
|
538
|
+
filter,
|
|
539
|
+
sample,
|
|
540
|
+
caption
|
|
541
|
+
}: TypographyScaleProps): ReactElement;
|
|
542
|
+
//#endregion
|
|
543
|
+
export { AliasChain, type AliasChainProps, AliasedBy, type AliasedByProps, AxesContext, AxisVariance, type AxisVarianceProps, BorderPreview, type BorderPreviewProps, BorderSample, type BorderSampleProps, COLOR_FORMATS, type ColorFormat, ColorFormatContext, ColorPalette, type ColorPaletteProps, CompositeBreakdown, type CompositeBreakdownProps, CompositePreview, type CompositePreviewProps, ConsumerOutput, type ConsumerOutputProps, DimensionBar, type DimensionBarProps, type DimensionKind, DimensionScale, type DimensionScaleProps, FontFamilySample, type FontFamilySampleProps, FontWeightScale, type FontWeightScaleProps, type FormatColorResult, GradientPalette, type GradientPaletteProps, MotionPreview, type MotionPreviewProps, MotionSample, type MotionSampleProps, type MotionSpeed, type NormalizedColor, type ProjectSnapshot, ShadowPreview, type ShadowPreviewProps, ShadowSample, type ShadowSampleProps, StrokeStyleSample, type StrokeStyleSampleProps, SwatchbookContext, SwatchbookProvider, type SwatchbookProviderProps, ThemeContext, TokenDetail, type TokenDetailProps, TokenHeader, type TokenHeaderProps, TokenNavigator, type TokenNavigatorProps, TokenTable, type TokenTableProps, TokenUsageSnippet, type TokenUsageSnippetProps, TypographyScale, type TypographyScaleProps, type VirtualAxisShape as VirtualAxis, type VirtualAxisShape, type VirtualDiagnosticShape as VirtualDiagnostic, type VirtualDiagnosticShape, type VirtualPresetShape as VirtualPreset, type VirtualPresetShape, type VirtualThemeShape as VirtualTheme, type VirtualThemeShape, type VirtualTokenShape as VirtualToken, type VirtualTokenShape, formatColor, useActiveAxes, useActiveTheme, useColorFormat, useOptionalSwatchbookData, useSwatchbookData };
|
|
544
|
+
//# sourceMappingURL=index.d.mts.map
|