@unpunnyfuns/swatchbook-blocks 1.2.0 → 2.0.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/README.md +5 -3
- package/dist/host-e2nSv-sA.mjs +791 -0
- package/dist/host-e2nSv-sA.mjs.map +1 -0
- package/dist/host.d.mts +57 -0
- package/dist/host.mjs +2 -0
- package/dist/index.d.mts +190 -348
- package/dist/index.mjs +485 -1100
- package/dist/index.mjs.map +1 -1
- package/dist/registry-Dm25Go94.d.mts +244 -0
- package/dist/style.css +237 -240
- package/package.json +6 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,184 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FormatColorResult, NormalizedColor, formatColor } from "@unpunnyfuns/swatchbook-core/format-color";
|
|
3
|
-
import * as _$react from "react";
|
|
1
|
+
import { C as useOptionalSwatchbookData, D as NormalizedColor, E as FormatColorResult, O as formatColor, S as useColorFormat, T as ColorFormat, _ as VirtualTokenGraph, a as usePresenter, b as useActiveAxes, c as PresenterRegistry, d as ProjectSnapshot, f as SwatchbookContext, g as VirtualPresetShape, h as VirtualDiagnosticShape, l as AxesContext, m as VirtualAxisShape, n as PresenterContext, o as PresenterComponent, p as ThemeContext, r as mergePresenters, s as PresenterProps, t as DEFAULT_PRESENTERS, u as ColorFormatContext, v as VirtualTokenListing, w as COLOR_FORMATS, x as useActiveTheme, y as VirtualTokenShape } from "./registry-Dm25Go94.mjs";
|
|
4
2
|
import { ReactElement, ReactNode } from "react";
|
|
5
|
-
import {
|
|
6
|
-
import { Axis
|
|
7
|
-
import {
|
|
3
|
+
import { formatTokenValue } from "@unpunnyfuns/swatchbook-core/token-value-css";
|
|
4
|
+
import { Axis } from "@unpunnyfuns/swatchbook-core";
|
|
5
|
+
import { SnapshotForWire } from "@unpunnyfuns/swatchbook-core/snapshot-for-wire";
|
|
6
|
+
import { RealisedToken, RealisedToken as RealisedToken$1, TokenType } from "@unpunnyfuns/swatchbook-core/token-value-types";
|
|
8
7
|
|
|
9
|
-
//#region src/contexts.d.ts
|
|
10
|
-
/**
|
|
11
|
-
* Typed shape of the addon's `virtual:swatchbook/tokens` module.
|
|
12
|
-
*
|
|
13
|
-
* The axis / permutation / diagnostic / preset entries are deliberate
|
|
14
|
-
* type-aliases of core's authoritative shapes — the virtual module
|
|
15
|
-
* publishes those shapes verbatim, so single-sourcing the types prevents
|
|
16
|
-
* silent drift the moment core grows a field the plugin doesn't
|
|
17
|
-
* serialise.
|
|
18
|
-
*
|
|
19
|
-
* Token / listing shapes stay as narrowed interfaces because blocks
|
|
20
|
-
* only read a subset of Terrazzo's full token / listing structure; the
|
|
21
|
-
* narrower shape documents what's actually relied on.
|
|
22
|
-
*
|
|
23
|
-
* The ambient `declare module 'virtual:swatchbook/tokens'` declarations
|
|
24
|
-
* in `packages/addon/src/virtual.d.ts` describe the same payload.
|
|
25
|
-
*/
|
|
26
|
-
type VirtualAxisShape = Axis;
|
|
27
|
-
type VirtualDiagnosticShape = Diagnostic;
|
|
28
|
-
interface VirtualTokenShape {
|
|
29
|
-
$type?: string | undefined;
|
|
30
|
-
$value?: unknown;
|
|
31
|
-
$description?: string | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* DTCG `$deprecated` — `true` or a message string. Mirrors core's
|
|
34
|
-
* `SwatchbookToken.$deprecated`; reaches blocks via the resolved token
|
|
35
|
-
* map reconstructed from the wire `tokenGraph`.
|
|
36
|
-
*/
|
|
37
|
-
$deprecated?: string | boolean | undefined;
|
|
38
|
-
aliasOf?: string | undefined;
|
|
39
|
-
aliasChain?: readonly string[] | undefined;
|
|
40
|
-
aliasedBy?: readonly string[] | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Per-sub-field alias map for composite tokens whose value blends
|
|
43
|
-
* primitives with aliased fragments — Terrazzo populates this when
|
|
44
|
-
* one or more component fields of a composite ($type: 'border',
|
|
45
|
-
* 'shadow', 'typography', 'gradient', 'transition') resolve through
|
|
46
|
-
* an alias. The `CompositeBreakdown` block reads it to render the
|
|
47
|
-
* source path beside each component value. Typed as `unknown` because
|
|
48
|
-
* the shape varies per composite type (color carries a
|
|
49
|
-
* `{components: (string | undefined)[]}` sub-shape; typography/border
|
|
50
|
-
* carry a flat `Record<string, string | undefined>`); the block
|
|
51
|
-
* narrows it at the consumer.
|
|
52
|
-
*/
|
|
53
|
-
partialAliasOf?: unknown;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Subset of `@terrazzo/plugin-token-listing`'s `ListedToken` that the
|
|
57
|
-
* snapshot carries. Blocks read `names.css` for the authoritative CSS
|
|
58
|
-
* variable name and `previewValue` for the display-ready CSS string.
|
|
59
|
-
* `source.loc` enables "jump to authoring source" affordances.
|
|
60
|
-
*
|
|
61
|
-
* Aliases `SlimListedToken` from core's `/snapshot-for-wire` subpath —
|
|
62
|
-
* the single canonical wire shape; both the addon's plugin (server-side
|
|
63
|
-
* emit) and blocks (consumer-side read) reference the same definition.
|
|
64
|
-
*/
|
|
65
|
-
type VirtualTokenListing = SlimListedToken;
|
|
66
|
-
type VirtualPresetShape = Preset;
|
|
67
|
-
/**
|
|
68
|
-
* Wire shape of the token graph — aliased from core's authoritative
|
|
69
|
-
* `TokenGraph` so both the virtual module declaration and the React
|
|
70
|
-
* context stay aligned with the same definition.
|
|
71
|
-
*/
|
|
72
|
-
type VirtualTokenGraph = TokenGraph;
|
|
73
|
-
/**
|
|
74
|
-
* Full project data read by blocks. Populated by the addon's preview
|
|
75
|
-
* decorator (from the virtual module) or constructed by hand in
|
|
76
|
-
* non-Storybook consumers.
|
|
77
|
-
*/
|
|
78
|
-
interface ProjectSnapshot {
|
|
79
|
-
axes: readonly VirtualAxisShape[];
|
|
80
|
-
activeTheme: string;
|
|
81
|
-
activeAxes: Readonly<Record<string, string>>;
|
|
82
|
-
cssVarPrefix: string;
|
|
83
|
-
/**
|
|
84
|
-
* Project-wide baseline for the row-indicator strip from
|
|
85
|
-
* `config.indicators`. Sits between the hard-coded indicator defaults
|
|
86
|
-
* and a block's `indicators` prop. Optional — hand-built snapshots
|
|
87
|
-
* (tests, MDX) omit it and blocks fall back to the bare defaults.
|
|
88
|
-
*/
|
|
89
|
-
indicators?: Readonly<Record<string, boolean>>;
|
|
90
|
-
diagnostics: readonly VirtualDiagnosticShape[];
|
|
91
|
-
/**
|
|
92
|
-
* Raw stylesheet text for the active theme. Optional — nothing on the
|
|
93
|
-
* `SwatchbookProvider` read path consumes it (`useProject()` never reads
|
|
94
|
-
* `snapshot.css`); the addon populates it incidentally when constructing
|
|
95
|
-
* its snapshot but injects CSS through its own independent mechanism.
|
|
96
|
-
*/
|
|
97
|
-
css?: string;
|
|
98
|
-
/**
|
|
99
|
-
* Path-indexed Token Listing data produced by
|
|
100
|
-
* `@terrazzo/plugin-token-listing`. Blocks prefer reading authoritative
|
|
101
|
-
* CSS var names and preview values from here; empty for non-resolver
|
|
102
|
-
* projects. Treat as enrichment — fall back gracefully when a path is
|
|
103
|
-
* absent.
|
|
104
|
-
*/
|
|
105
|
-
listing?: Readonly<Record<string, VirtualTokenListing>>;
|
|
106
|
-
/**
|
|
107
|
-
* Pre-built token graph for the project. JSON-serializable; nodes
|
|
108
|
-
* carry per-axis writes plus alias edges. The blocks hook backs
|
|
109
|
-
* `resolveAt` and variance from this graph.
|
|
110
|
-
*/
|
|
111
|
-
tokenGraph?: VirtualTokenGraph;
|
|
112
|
-
/** The default tuple — `{ axis: axis.default }` for every axis. */
|
|
113
|
-
defaultTuple: Record<string, string>;
|
|
114
|
-
/**
|
|
115
|
-
* Starting color format for blocks that display color values:
|
|
116
|
-
* `config.defaultColorFormat` from core, passed through the wire
|
|
117
|
-
* snapshot. `useColorFormat()` falls back to this when neither a
|
|
118
|
-
* block's own `colorFormat` prop nor a `ColorFormatContext` override is
|
|
119
|
-
* active. Optional: hand-built snapshots (tests, MDX) that omit it fall
|
|
120
|
-
* through to the bare `'hex'` default.
|
|
121
|
-
*/
|
|
122
|
-
defaultColorFormat?: ColorFormat;
|
|
123
|
-
/**
|
|
124
|
-
* Pre-built `resolveAt(tuple)` accessor. The addon's preview decorator
|
|
125
|
-
* instantiates this once per iframe lifetime. When present, use-project
|
|
126
|
-
* prefers it over building its own from `tokenGraph`, so it MUST preserve
|
|
127
|
-
* alias provenance — back it with `resolveAllWithProvenanceAt`, not the raw
|
|
128
|
-
* leaf `resolveAllAt`, or axis-varying aliases silently lose their chain /
|
|
129
|
-
* reverse refs / description at non-default tuples. Hand-built snapshots
|
|
130
|
-
* (tests, MDX) can omit this; blocks then fall back to a provenance-aware
|
|
131
|
-
* graph-backed resolver built from `tokenGraph`.
|
|
132
|
-
*/
|
|
133
|
-
resolveAt?: (tuple: Record<string, string>) => Record<string, VirtualTokenShape>;
|
|
134
|
-
}
|
|
135
|
-
declare function useOptionalSwatchbookData(): ProjectSnapshot | null;
|
|
136
|
-
/**
|
|
137
|
-
* Active swatchbook theme for the current story/docs render. Populated by
|
|
138
|
-
* the addon's preview decorator and consumed by `useToken` + any future
|
|
139
|
-
* consumer hooks.
|
|
140
|
-
*
|
|
141
|
-
* This runs through plain React context rather than Storybook's
|
|
142
|
-
* `useGlobals` so the same hook works in autodocs / MDX renders where the
|
|
143
|
-
* preview-hooks context isn't available.
|
|
144
|
-
*/
|
|
145
|
-
declare const ThemeContext: _$react.Context<string>;
|
|
146
|
-
declare function useActiveTheme(): string;
|
|
147
|
-
/**
|
|
148
|
-
* Active axis tuple for the current story/docs render — `Record<axisName,
|
|
149
|
-
* contextName>`. Derived from the same input as {@link ThemeContext}; split
|
|
150
|
-
* out so consumers needing per-axis info (toolbar, panel, tuple-aware
|
|
151
|
-
* blocks) don't have to reparse the composed theme name.
|
|
152
|
-
*/
|
|
153
|
-
declare const AxesContext: _$react.Context<Readonly<Record<string, string>>>;
|
|
154
|
-
declare function useActiveAxes(): Readonly<Record<string, string>>;
|
|
155
|
-
/**
|
|
156
|
-
* Active color-display format for the current story/docs render, consumed
|
|
157
|
-
* by blocks that render color-token values. Emitted CSS is unaffected.
|
|
158
|
-
*
|
|
159
|
-
* Sits in the middle of the precedence chain a block resolves via
|
|
160
|
-
* `colorFormat ?? useColorFormat()`: a block's own `colorFormat` prop wins
|
|
161
|
-
* over this context, which wins over the active snapshot's
|
|
162
|
-
* `defaultColorFormat` (from `Config.defaultColorFormat`). "Active
|
|
163
|
-
* snapshot" is whichever source is actually feeding the render:
|
|
164
|
-
* `SwatchbookProvider` when a story decorator mounted one, otherwise the
|
|
165
|
-
* channel-fed `TokenSnapshot` that MDX-embedded blocks (no `<Story/>`, no
|
|
166
|
-
* provider) read through `useProject()`'s fallback path.
|
|
167
|
-
*
|
|
168
|
-
* Runs through plain React context rather than Storybook's `useGlobals` so
|
|
169
|
-
* per-story seeded globals flow through on first render and the same hook
|
|
170
|
-
* is safe to call from MDX doc blocks (where the preview-hooks context
|
|
171
|
-
* isn't available).
|
|
172
|
-
*/
|
|
173
|
-
declare const ColorFormatContext: _$react.Context<ColorFormat | null>;
|
|
174
|
-
/**
|
|
175
|
-
* Resolves the color-display format from the context/snapshot/default
|
|
176
|
-
* chain: `ColorFormatContext` → active snapshot's `defaultColorFormat` →
|
|
177
|
-
* `'hex'`. Composing blocks read `colorFormat ?? useColorFormat()` to give
|
|
178
|
-
* their own `colorFormat` prop top precedence over this chain.
|
|
179
|
-
*/
|
|
180
|
-
declare function useColorFormat(): ColorFormat;
|
|
181
|
-
//#endregion
|
|
182
8
|
//#region src/internal/sort-tokens.d.ts
|
|
183
9
|
type SortBy = 'path' | 'value' | 'none';
|
|
184
10
|
type SortDir = 'asc' | 'desc';
|
|
@@ -216,12 +42,12 @@ declare function BorderPreview({
|
|
|
216
42
|
}: BorderPreviewProps): ReactElement;
|
|
217
43
|
//#endregion
|
|
218
44
|
//#region src/border-preview/BorderSample.d.ts
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
path: string;
|
|
222
|
-
}
|
|
45
|
+
/** Props for the connected {@link BorderSample} block. */
|
|
46
|
+
type BorderSampleProps = PresenterProps<'border'>;
|
|
223
47
|
declare function BorderSample({
|
|
224
|
-
|
|
48
|
+
token,
|
|
49
|
+
cssVar,
|
|
50
|
+
colorFormat
|
|
225
51
|
}: BorderSampleProps): ReactElement;
|
|
226
52
|
//#endregion
|
|
227
53
|
//#region src/ColorPalette.d.ts
|
|
@@ -272,6 +98,29 @@ declare function ColorPalette({
|
|
|
272
98
|
colorFormat
|
|
273
99
|
}: ColorPaletteProps): ReactElement;
|
|
274
100
|
//#endregion
|
|
101
|
+
//#region src/presenters/ColorSwatch.d.ts
|
|
102
|
+
/** Props for the {@link ColorSwatch} presenter. */
|
|
103
|
+
type ColorSwatchProps = PresenterProps<'color'>;
|
|
104
|
+
/**
|
|
105
|
+
* Presenter for `$type: color` tokens: a color chip, leaf label, and
|
|
106
|
+
* formatted value with an out-of-gamut marker. The chip's background is
|
|
107
|
+
* `cssVar` when supplied (R3); otherwise it is computed straight from
|
|
108
|
+
* `token.$value`, with `raw` guarded to `hex` (`cssColorFormat`) so the chip
|
|
109
|
+
* always paints a real color even when the display format is a JSON debug
|
|
110
|
+
* string. The value text below the chip uses the actual `colorFormat`,
|
|
111
|
+
* `raw` included. `options.label` lets a grouped consumer (e.g.
|
|
112
|
+
* `ColorPalette`) supply a group-relative label instead of the bare leaf
|
|
113
|
+
* segment, so context lost to grouping (`blue` in `color.palette.blue.50`)
|
|
114
|
+
* still reads on the swatch; standalone usage falls back to `leafOf(path)`.
|
|
115
|
+
*/
|
|
116
|
+
declare function ColorSwatch({
|
|
117
|
+
path,
|
|
118
|
+
token,
|
|
119
|
+
cssVar,
|
|
120
|
+
colorFormat,
|
|
121
|
+
options
|
|
122
|
+
}: ColorSwatchProps): ReactElement;
|
|
123
|
+
//#endregion
|
|
275
124
|
//#region src/indicators/resolve.d.ts
|
|
276
125
|
/** The individually-toggleable indicators in the row strip. `alias` covers the whole alias unit (forward chain + reverse count). */
|
|
277
126
|
type IndicatorName = 'alias' | 'variance' | 'gamut' | 'deprecation' | 'description' | 'composes';
|
|
@@ -387,22 +236,14 @@ declare function Diagnostics({
|
|
|
387
236
|
//#region src/dimension-scale/DimensionSample.d.ts
|
|
388
237
|
/** The visual treatment for a dimension sample: a length bar, a radius square, or a sized square. */
|
|
389
238
|
type DimensionVisual = 'length' | 'radius' | 'size';
|
|
390
|
-
/** Props for the connected {@link DimensionSample} block. */
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
path: string;
|
|
394
|
-
/**
|
|
395
|
-
* Visualization kind:
|
|
396
|
-
* - `'length'` (default): horizontal bar whose width equals the token's dimension.
|
|
397
|
-
* - `'radius'`: 56×56 square with the token applied as `border-radius`.
|
|
398
|
-
* - `'size'`: a square sized to the token's dimension.
|
|
399
|
-
*/
|
|
400
|
-
visual?: DimensionVisual;
|
|
401
|
-
}
|
|
402
|
-
/** Connected block: resolves `path` against the active project and renders its dimension sample. */
|
|
239
|
+
/** Props for the connected {@link DimensionSample} block. `options.visual` selects the visualization kind (see {@link DimensionVisual}); defaults to `'length'`. */
|
|
240
|
+
type DimensionSampleProps = PresenterProps<'dimension'>;
|
|
241
|
+
/** Connected block: renders a realised dimension token's sample, capped for oversized values. */
|
|
403
242
|
declare function DimensionSample({
|
|
404
|
-
|
|
405
|
-
|
|
243
|
+
token,
|
|
244
|
+
cssVar,
|
|
245
|
+
colorFormat,
|
|
246
|
+
options
|
|
406
247
|
}: DimensionSampleProps): ReactElement;
|
|
407
248
|
//#endregion
|
|
408
249
|
//#region src/DimensionScale.d.ts
|
|
@@ -468,6 +309,20 @@ declare function FontFamilyPreview({
|
|
|
468
309
|
sortDir
|
|
469
310
|
}: FontFamilyPreviewProps): ReactElement;
|
|
470
311
|
//#endregion
|
|
312
|
+
//#region src/presenters/FontFamilySpecimen.d.ts
|
|
313
|
+
/** Props for the {@link FontFamilySpecimen} presenter. `options.sample` overrides the rendered sample text; defaults to a pangram. */
|
|
314
|
+
type FontFamilySpecimenProps = PresenterProps<'fontFamily'>;
|
|
315
|
+
/**
|
|
316
|
+
* Presenter for `$type: fontFamily` tokens: path, resolved stack, a sample
|
|
317
|
+
* line styled per R3, and the css var in use.
|
|
318
|
+
*/
|
|
319
|
+
declare function FontFamilySpecimen({
|
|
320
|
+
path,
|
|
321
|
+
token,
|
|
322
|
+
cssVar,
|
|
323
|
+
options
|
|
324
|
+
}: FontFamilySpecimenProps): ReactElement;
|
|
325
|
+
//#endregion
|
|
471
326
|
//#region src/FontWeightScale.d.ts
|
|
472
327
|
interface FontWeightScaleProps {
|
|
473
328
|
/**
|
|
@@ -497,6 +352,20 @@ declare function FontWeightScale({
|
|
|
497
352
|
sortDir
|
|
498
353
|
}: FontWeightScaleProps): ReactElement;
|
|
499
354
|
//#endregion
|
|
355
|
+
//#region src/presenters/FontWeightSpecimen.d.ts
|
|
356
|
+
/** Props for the {@link FontWeightSpecimen} presenter. `options.sample` overrides the rendered sample text; defaults to `'Aa'`. */
|
|
357
|
+
type FontWeightSpecimenProps = PresenterProps<'fontWeight'>;
|
|
358
|
+
/**
|
|
359
|
+
* Presenter for `$type: fontWeight` tokens: path, the raw weight value, a
|
|
360
|
+
* sample glyph styled per R3, and the css var in use.
|
|
361
|
+
*/
|
|
362
|
+
declare function FontWeightSpecimen({
|
|
363
|
+
path,
|
|
364
|
+
token,
|
|
365
|
+
cssVar,
|
|
366
|
+
options
|
|
367
|
+
}: FontWeightSpecimenProps): ReactElement;
|
|
368
|
+
//#endregion
|
|
500
369
|
//#region src/GradientPalette.d.ts
|
|
501
370
|
interface GradientPaletteProps {
|
|
502
371
|
/**
|
|
@@ -529,24 +398,48 @@ declare function GradientPalette({
|
|
|
529
398
|
colorFormat
|
|
530
399
|
}: GradientPaletteProps): ReactElement;
|
|
531
400
|
//#endregion
|
|
401
|
+
//#region src/presenters/GradientSwatch.d.ts
|
|
402
|
+
/** Props for the {@link GradientSwatch} presenter. */
|
|
403
|
+
type GradientSwatchProps = PresenterProps<'gradient'>;
|
|
404
|
+
/**
|
|
405
|
+
* Presenter for `$type: gradient` tokens: a gradient chip. Unlike the
|
|
406
|
+
* other composite presenters, a gradient's css var (per Terrazzo's
|
|
407
|
+
* `transformGradient`) resolves to a bare `<color> <pct>, ...` stop list,
|
|
408
|
+
* not a complete property value: DTCG gradients carry no direction, so
|
|
409
|
+
* both branches need one supplied at render time. `90deg` (`to right`)
|
|
410
|
+
* matches the direction the standalone block previously hard-coded.
|
|
411
|
+
*/
|
|
412
|
+
declare function GradientSwatch({
|
|
413
|
+
token,
|
|
414
|
+
cssVar,
|
|
415
|
+
colorFormat
|
|
416
|
+
}: GradientSwatchProps): ReactElement;
|
|
417
|
+
//#endregion
|
|
532
418
|
//#region src/motion-preview/MotionSample.d.ts
|
|
533
419
|
type MotionSpeed = 0.25 | 0.5 | 1 | 2;
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
420
|
+
/**
|
|
421
|
+
* Props for the connected {@link MotionSample} block. `token` accepts any
|
|
422
|
+
* of the three motion `$type`s (`transition`, `duration`, `cubicBezier`) —
|
|
423
|
+
* looser than a single-type `PresenterProps<'transition'>` because
|
|
424
|
+
* `resolveMotionSpec` dispatches on the realised `$type` at runtime and
|
|
425
|
+
* TokenNavigator/MotionPreview feed it all three from one call site.
|
|
426
|
+
* `options.speed` is the playback speed multiplier (defaults to `1`);
|
|
427
|
+
* `options.runKey` forces the animation to restart when changed, e.g. from
|
|
428
|
+
* an outer block's "replay" button re-triggering every sample at once.
|
|
429
|
+
*/
|
|
430
|
+
type MotionSampleProps = PresenterProps;
|
|
431
|
+
/**
|
|
432
|
+
* Connected block: renders a realised motion token's animated sample. Both
|
|
433
|
+
* `durationMs` and `easing` come from the realised `$value`; the ball's
|
|
434
|
+
* setInterval loop needs a JS-readable duration, and (see the comment below)
|
|
435
|
+
* `cssVar` cannot stand in for `easing` here. `cssVar` is still accepted, per
|
|
436
|
+
* the uniform `PresenterProps` contract every presenter shares, but this
|
|
437
|
+
* View has nowhere safe to apply it.
|
|
438
|
+
*/
|
|
546
439
|
declare function MotionSample({
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
440
|
+
token,
|
|
441
|
+
cssVar: _cssVar,
|
|
442
|
+
options
|
|
550
443
|
}: MotionSampleProps): ReactElement;
|
|
551
444
|
//#endregion
|
|
552
445
|
//#region src/MotionPreview.d.ts
|
|
@@ -619,81 +512,71 @@ declare function OpacityScale({
|
|
|
619
512
|
sortDir
|
|
620
513
|
}: OpacityScaleProps): ReactElement;
|
|
621
514
|
//#endregion
|
|
622
|
-
//#region src/
|
|
515
|
+
//#region src/presenters/OpacitySwatch.d.ts
|
|
623
516
|
/**
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* On MDX docs pages, Storybook force-rerenders the docs container on every
|
|
628
|
-
* `updateGlobals` (see `preview/runtime.js` → `onUpdateGlobals`), which
|
|
629
|
-
* unmounts and remounts any embedded blocks. A `useState(null)` initializer
|
|
630
|
-
* inside the block would reset to null on each remount — the symptom is a
|
|
631
|
-
* one-frame flicker to the correct value, then revert to the defaults.
|
|
632
|
-
* Module-level state persists; React reads it through `useSyncExternalStore`
|
|
633
|
-
* and stays concurrent-safe.
|
|
517
|
+
* Props for the {@link OpacitySwatch} presenter. `options.sampleColorVar`
|
|
518
|
+
* sets the chip's fill color (a resolved css var or literal); defaults to
|
|
519
|
+
* the swatchbook accent surface.
|
|
634
520
|
*/
|
|
635
|
-
|
|
636
|
-
axes: Record<string, string> | null;
|
|
637
|
-
format: ColorFormat | null;
|
|
638
|
-
}
|
|
639
|
-
declare function useChannelGlobals(): ChannelGlobals;
|
|
640
|
-
//#endregion
|
|
641
|
-
//#region src/internal/channel.d.ts
|
|
521
|
+
type OpacitySwatchProps = PresenterProps<'number'>;
|
|
642
522
|
/**
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
* touch this; it exists for whoever builds the next integration.
|
|
648
|
-
*
|
|
649
|
-
* Minimal event-source contract blocks need from their host. Storybook's
|
|
650
|
-
* preview Channel satisfies it structurally; a plain emitter or a test double
|
|
651
|
-
* does too. Blocks never import `storybook/preview-api` — the addon, which
|
|
652
|
-
* owns the Storybook relationship, injects the channel at preview init via
|
|
653
|
-
* {@link registerChannel}, mirroring how `registerTokenSource` injects the
|
|
654
|
-
* initial token snapshot.
|
|
655
|
-
*/
|
|
656
|
-
interface BlockChannel {
|
|
657
|
-
on<T>(event: string, listener: (payload: T) => void): void;
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* Host adapter API. The single most load-bearing function in the host
|
|
661
|
-
* contract — the addon calls it once at preview init.
|
|
662
|
-
*
|
|
663
|
-
* Inject the host channel. Runs any subscribers that queued before the
|
|
664
|
-
* channel existed, then clears the queue. The host contract does NOT dedupe:
|
|
665
|
-
* on HMR a subscriber's module re-runs {@link onChannel}, which re-attaches
|
|
666
|
-
* immediately once the channel is set, so each subscriber MUST guard its own
|
|
667
|
-
* attach to stay single-wired.
|
|
523
|
+
* Presenter for `$type: number` opacity tokens: a colored chip over a
|
|
524
|
+
* checkerboard backdrop, with the chip's `opacity` set from the token per
|
|
525
|
+
* R3. The number alone (`0.4`) doesn't convey what the token looks like
|
|
526
|
+
* applied to a surface; the chip does.
|
|
668
527
|
*/
|
|
669
|
-
declare function
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
* it to run the moment {@link registerChannel} fires. Blocks call this at
|
|
675
|
-
* module load; the queue absorbs the gap until the addon injects the channel.
|
|
676
|
-
*/
|
|
677
|
-
declare function onChannel(attach: (channel: BlockChannel) => void): void;
|
|
528
|
+
declare function OpacitySwatch({
|
|
529
|
+
token,
|
|
530
|
+
cssVar,
|
|
531
|
+
options
|
|
532
|
+
}: OpacitySwatchProps): ReactElement;
|
|
678
533
|
//#endregion
|
|
679
534
|
//#region src/provider.d.ts
|
|
680
535
|
interface SwatchbookProviderProps {
|
|
681
|
-
|
|
536
|
+
snapshot: SnapshotForWire;
|
|
537
|
+
/** Controlled active tuple. Mutually exclusive with `defaultAxes`. */
|
|
538
|
+
axes?: Record<string, string> | undefined;
|
|
539
|
+
/** Uncontrolled initial tuple; the provider owns state and `useSetAxes` flips it. */
|
|
540
|
+
defaultAxes?: Record<string, string> | undefined;
|
|
541
|
+
/** Overrides merged over {@link DEFAULT_PRESENTERS} for this subtree. */
|
|
542
|
+
presenters?: PresenterRegistry | undefined;
|
|
543
|
+
/**
|
|
544
|
+
* Mount the snapshot's emitted CSS into `document.head` through the shared
|
|
545
|
+
* managed style element (default `true`). Pass `false` when the host places
|
|
546
|
+
* the stylesheet itself: SSR frameworks, shadow roots, the Storybook addon
|
|
547
|
+
* (which injects its own combined stylesheet). The element is shared by ID,
|
|
548
|
+
* so a page hosting providers with different snapshots should opt out and
|
|
549
|
+
* manage stylesheets itself; same-snapshot providers are idempotent.
|
|
550
|
+
*/
|
|
551
|
+
mountCss?: boolean | undefined;
|
|
682
552
|
children: ReactNode;
|
|
683
553
|
}
|
|
684
554
|
/**
|
|
685
|
-
* Wraps a tree of blocks with the token data they need to render
|
|
555
|
+
* Wraps a tree of blocks with the token data they need to render, assembled
|
|
556
|
+
* from core's wire snapshot plus an active axis tuple.
|
|
686
557
|
*
|
|
687
|
-
* The Storybook addon's preview decorator mounts this automatically
|
|
688
|
-
* story/MDX authors typically never
|
|
689
|
-
* tests, custom React apps, non-Storybook
|
|
690
|
-
* a {@link
|
|
691
|
-
*
|
|
558
|
+
* The Storybook addon's preview decorator mounts this automatically
|
|
559
|
+
* (`axes` controlled by the toolbar), so story/MDX authors typically never
|
|
560
|
+
* see it. Outside Storybook: unit tests, custom React apps, non-Storybook
|
|
561
|
+
* doc sites. Consumers pass a {@link SnapshotForWire} (often imported from
|
|
562
|
+
* a JSON file) and either drive `axes` themselves or let the provider own
|
|
563
|
+
* the tuple via `defaultAxes` + {@link useSetAxes}.
|
|
692
564
|
*/
|
|
693
565
|
declare function SwatchbookProvider({
|
|
694
|
-
|
|
566
|
+
snapshot,
|
|
567
|
+
axes,
|
|
568
|
+
defaultAxes,
|
|
569
|
+
presenters,
|
|
570
|
+
mountCss,
|
|
695
571
|
children
|
|
696
572
|
}: SwatchbookProviderProps): ReactElement;
|
|
573
|
+
/**
|
|
574
|
+
* Flip the active tuple on an uncontrolled {@link SwatchbookProvider}
|
|
575
|
+
* (mounted with `defaultAxes`, not `axes`). Throws when the nearest
|
|
576
|
+
* provider is controlled (the host owns `axes`) or absent, since there's
|
|
577
|
+
* no internal state to flip in either case.
|
|
578
|
+
*/
|
|
579
|
+
declare function useSetAxes(): (tuple: Record<string, string>) => void;
|
|
697
580
|
/**
|
|
698
581
|
* Read the current {@link ProjectSnapshot}. Throws if called outside a
|
|
699
582
|
* {@link SwatchbookProvider}; blocks that need to fall back to the
|
|
@@ -701,74 +584,6 @@ declare function SwatchbookProvider({
|
|
|
701
584
|
*/
|
|
702
585
|
declare function useSwatchbookData(): ProjectSnapshot;
|
|
703
586
|
//#endregion
|
|
704
|
-
//#region src/internal/channel-tokens.d.ts
|
|
705
|
-
/**
|
|
706
|
-
* Host adapter API — same integration tier as {@link BlockChannel} /
|
|
707
|
-
* {@link registerChannel} / {@link onChannel}, distinct from the
|
|
708
|
-
* components/hooks/`SwatchbookProvider` surface MDX/story authors use.
|
|
709
|
-
* Most consumers never touch this; it exists for whoever builds the next
|
|
710
|
-
* host integration.
|
|
711
|
-
*
|
|
712
|
-
* Live token snapshot backed by the addon's preview dev-time HMR event.
|
|
713
|
-
*
|
|
714
|
-
* The initial snapshot is *injected* by the addon preview via
|
|
715
|
-
* {@link registerTokenSource} rather than imported from the addon's
|
|
716
|
-
* `virtual:swatchbook/tokens` build artifact — so blocks carries no
|
|
717
|
-
* dependency on that module and imports cleanly standalone (outside
|
|
718
|
-
* Storybook, in unit tests, in the docs site). Until something registers
|
|
719
|
-
* a source, blocks render from empty defaults.
|
|
720
|
-
*
|
|
721
|
-
* For dev-time updates this module subscribes to `TOKENS_UPDATED_EVENT`
|
|
722
|
-
* on Storybook's channel (which the addon preview re-broadcasts from its
|
|
723
|
-
* own HMR listener) and exposes the latest snapshot via
|
|
724
|
-
* `useSyncExternalStore`, so hooks re-render in place on each token save.
|
|
725
|
-
*/
|
|
726
|
-
declare const TOKENS_UPDATED_EVENT = "swatchbook/tokens-updated";
|
|
727
|
-
/** Host adapter API — see {@link registerTokenSource}. */
|
|
728
|
-
interface TokenSnapshot {
|
|
729
|
-
readonly axes: readonly VirtualAxisShape[];
|
|
730
|
-
readonly presets: readonly {
|
|
731
|
-
name: string;
|
|
732
|
-
axes: Partial<Record<string, string>>;
|
|
733
|
-
description?: string;
|
|
734
|
-
}[];
|
|
735
|
-
readonly diagnostics: readonly VirtualDiagnosticShape[];
|
|
736
|
-
readonly css: string;
|
|
737
|
-
readonly cssVarPrefix: string;
|
|
738
|
-
/** Project-wide baseline for the row-indicator strip from `config.indicators`. */
|
|
739
|
-
readonly indicators: Readonly<Record<string, boolean>>;
|
|
740
|
-
readonly listing: Readonly<Record<string, VirtualTokenListing>>;
|
|
741
|
-
readonly tokenGraph: VirtualTokenGraph;
|
|
742
|
-
readonly defaultTuple: Record<string, string>;
|
|
743
|
-
/**
|
|
744
|
-
* Starting color format for blocks that display color values:
|
|
745
|
-
* `config.defaultColorFormat` from core, forwarded from the addon's
|
|
746
|
-
* `registerTokenSource` call. `useColorFormat()` falls back to this on
|
|
747
|
-
* the provider-less (MDX/autodocs) path when no `ColorFormatContext`/
|
|
748
|
-
* channel-globals override is active.
|
|
749
|
-
*/
|
|
750
|
-
readonly defaultColorFormat: ColorFormat;
|
|
751
|
-
/** Monotonic counter, bumped on each update. Useful as a React key. */
|
|
752
|
-
readonly version: number;
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* Host adapter API — same integration tier as {@link registerChannel}.
|
|
756
|
-
*
|
|
757
|
-
* Seed the initial token snapshot. The addon preview calls this once at
|
|
758
|
-
* init with the build-time `virtual:swatchbook/tokens` data. Keeping the
|
|
759
|
-
* virtual-module read on the addon side (the package that owns it) lets
|
|
760
|
-
* blocks import cleanly without it. No-op fields fall back to the current
|
|
761
|
-
* snapshot, so a partial source is safe.
|
|
762
|
-
*/
|
|
763
|
-
declare function registerTokenSource(source: Partial<TokenSnapshot>): void;
|
|
764
|
-
/**
|
|
765
|
-
* Host adapter API — same integration tier as {@link registerChannel}. Most
|
|
766
|
-
* consumers read project data through `useSwatchbookData()` /
|
|
767
|
-
* `SwatchbookProvider` instead; this is the internal subscription
|
|
768
|
-
* `useProject()`'s fallback path uses to read the live channel-fed snapshot.
|
|
769
|
-
*/
|
|
770
|
-
declare function useTokenSnapshot(): TokenSnapshot;
|
|
771
|
-
//#endregion
|
|
772
587
|
//#region src/ShadowPreview.d.ts
|
|
773
588
|
interface ShadowPreviewProps {
|
|
774
589
|
/**
|
|
@@ -802,14 +617,27 @@ declare function ShadowPreview({
|
|
|
802
617
|
}: ShadowPreviewProps): ReactElement;
|
|
803
618
|
//#endregion
|
|
804
619
|
//#region src/shadow-preview/ShadowSample.d.ts
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
path: string;
|
|
808
|
-
}
|
|
620
|
+
/** Props for the connected {@link ShadowSample} block. */
|
|
621
|
+
type ShadowSampleProps = PresenterProps<'shadow'>;
|
|
809
622
|
declare function ShadowSample({
|
|
810
|
-
|
|
623
|
+
token,
|
|
624
|
+
cssVar,
|
|
625
|
+
colorFormat
|
|
811
626
|
}: ShadowSampleProps): ReactElement;
|
|
812
627
|
//#endregion
|
|
628
|
+
//#region src/presenters/StrokeSample.d.ts
|
|
629
|
+
/** Props for the {@link StrokeSample} presenter. */
|
|
630
|
+
type StrokeSampleProps = PresenterProps<'strokeStyle'>;
|
|
631
|
+
/**
|
|
632
|
+
* Presenter for `$type: strokeStyle` tokens: a line styled with the
|
|
633
|
+
* token's `border-top-style` per R3, or the object-form fallback message
|
|
634
|
+
* when `$value` is a dash pattern with no pure CSS equivalent.
|
|
635
|
+
*/
|
|
636
|
+
declare function StrokeSample({
|
|
637
|
+
token,
|
|
638
|
+
cssVar
|
|
639
|
+
}: StrokeSampleProps): ReactElement;
|
|
640
|
+
//#endregion
|
|
813
641
|
//#region src/StrokeStylePreview.d.ts
|
|
814
642
|
interface StrokeStylePreviewProps {
|
|
815
643
|
/**
|
|
@@ -1088,6 +916,20 @@ declare function TokenTable({
|
|
|
1088
916
|
colorFormat
|
|
1089
917
|
}: TokenTableProps): ReactElement;
|
|
1090
918
|
//#endregion
|
|
919
|
+
//#region src/presenters/TypeSpecimen.d.ts
|
|
920
|
+
/** Props for the connected {@link TypeSpecimen} block. `options.sample` overrides the rendered sample text; defaults to a pangram. */
|
|
921
|
+
type TypeSpecimenProps = PresenterProps<'typography'>;
|
|
922
|
+
/**
|
|
923
|
+
* Presenter for `$type: typography` tokens: a spec summary and a sample line
|
|
924
|
+
* styled per R3. Token identity (the path) is the consuming block's
|
|
925
|
+
* responsibility, not this presenter's; see `TypographyScale`.
|
|
926
|
+
*/
|
|
927
|
+
declare function TypeSpecimen({
|
|
928
|
+
token,
|
|
929
|
+
cssVar: _cssVar,
|
|
930
|
+
options
|
|
931
|
+
}: TypeSpecimenProps): ReactElement;
|
|
932
|
+
//#endregion
|
|
1091
933
|
//#region src/TypographyScale.d.ts
|
|
1092
934
|
interface TypographyScaleProps {
|
|
1093
935
|
/**
|
|
@@ -1116,5 +958,5 @@ declare function TypographyScale({
|
|
|
1116
958
|
sortDir
|
|
1117
959
|
}: TypographyScaleProps): ReactElement;
|
|
1118
960
|
//#endregion
|
|
1119
|
-
export { AliasChain, type AliasChainProps, AliasedBy, type AliasedByProps, AxesContext, AxisVariance, type AxisVarianceProps,
|
|
961
|
+
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, ColorSwatch, type ColorSwatchProps, ColorTable, type ColorTableProps, CompositeBreakdown, type CompositeBreakdownProps, CompositePreview, type CompositePreviewProps, ConsumerOutput, type ConsumerOutputProps, DEFAULT_PRESENTERS, Diagnostics, type DiagnosticsProps, DimensionSample, type DimensionSampleProps, DimensionScale, type DimensionScaleProps, type DimensionVisual, FontFamilyPreview, type FontFamilyPreviewProps, FontFamilySpecimen, type FontFamilySpecimenProps, FontWeightScale, type FontWeightScaleProps, FontWeightSpecimen, type FontWeightSpecimenProps, type FormatColorResult, GradientPalette, type GradientPaletteProps, GradientSwatch, type GradientSwatchProps, type IndicatorName, type IndicatorsProp, MotionPreview, type MotionPreviewProps, MotionSample, type MotionSampleProps, type MotionSpeed, type NormalizedColor, OpacityScale, type OpacityScaleProps, OpacitySwatch, type OpacitySwatchProps, type PresenterComponent, PresenterContext, type PresenterProps, type PresenterRegistry, type ProjectSnapshot, type RealisedToken, ShadowPreview, type ShadowPreviewProps, ShadowSample, type ShadowSampleProps, type SortBy, type SortDir, StrokeSample, type StrokeSampleProps, StrokeStylePreview, type StrokeStylePreviewProps, SwatchbookContext, SwatchbookProvider, type SwatchbookProviderProps, ThemeContext, TokenDetail, type TokenDetailProps, TokenHeader, type TokenHeaderProps, TokenNavigator, type TokenNavigatorProps, TokenTable, type TokenTableProps, type TokenType, TokenUsageSnippet, type TokenUsageSnippetProps, TypeSpecimen, type TypeSpecimenProps, TypographyScale, type TypographyScaleProps, type VirtualAxisShape as VirtualAxis, type VirtualDiagnosticShape as VirtualDiagnostic, type VirtualPresetShape as VirtualPreset, type VirtualTokenShape as VirtualToken, type VirtualTokenGraph, type VirtualTokenListing, formatColor, formatTokenValue, mergePresenters, useActiveAxes, useActiveTheme, useColorFormat, useOptionalSwatchbookData, usePresenter, useSetAxes, useSwatchbookData };
|
|
1120
962
|
//# sourceMappingURL=index.d.mts.map
|