@unpunnyfuns/swatchbook-blocks 0.2.2 → 0.3.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/dist/index.d.mts CHANGED
@@ -46,6 +46,111 @@ interface FormatColorResult {
46
46
  */
47
47
  declare function formatColor(value: unknown, format: ColorFormat, fallback?: string): FormatColorResult;
48
48
  //#endregion
49
+ //#region src/contexts.d.ts
50
+ /**
51
+ * Typed shape of the addon's `virtual:swatchbook/tokens` module, duplicated
52
+ * as value-importable interfaces so consumers outside the addon's Vite
53
+ * plugin (unit tests, custom React apps) can construct a snapshot by hand.
54
+ *
55
+ * The ambient `declare module 'virtual:swatchbook/tokens'` declarations in
56
+ * `packages/addon/src/virtual.d.ts` describe the same payload; the two
57
+ * stay in sync by eye.
58
+ */
59
+ interface VirtualAxisShape {
60
+ name: string;
61
+ contexts: readonly string[];
62
+ default: string;
63
+ description?: string;
64
+ source: 'resolver' | 'layered' | 'synthetic';
65
+ }
66
+ interface VirtualThemeShape {
67
+ name: string;
68
+ input: Record<string, string>;
69
+ sources: string[];
70
+ }
71
+ interface VirtualDiagnosticShape {
72
+ severity: 'error' | 'warn' | 'info';
73
+ group: string;
74
+ message: string;
75
+ filename?: string;
76
+ line?: number;
77
+ column?: number;
78
+ }
79
+ interface VirtualTokenShape {
80
+ $type?: string;
81
+ $value?: unknown;
82
+ $description?: string;
83
+ aliasOf?: string;
84
+ aliasChain?: readonly string[];
85
+ aliasedBy?: readonly string[];
86
+ }
87
+ interface VirtualPresetShape {
88
+ name: string;
89
+ axes: Partial<Record<string, string>>;
90
+ description?: string;
91
+ }
92
+ /**
93
+ * Full project data read by blocks. Populated by the addon's preview
94
+ * decorator (from the virtual module) or constructed by hand in
95
+ * non-Storybook consumers.
96
+ */
97
+ interface ProjectSnapshot {
98
+ axes: readonly VirtualAxisShape[];
99
+ /** Axis names suppressed via `config.disabledAxes` — pinned to their defaults, hidden from the toolbar. */
100
+ disabledAxes: readonly string[];
101
+ presets: readonly VirtualPresetShape[];
102
+ themes: readonly VirtualThemeShape[];
103
+ themesResolved: Record<string, Record<string, VirtualTokenShape>>;
104
+ activeTheme: string;
105
+ activeAxes: Readonly<Record<string, string>>;
106
+ cssVarPrefix: string;
107
+ diagnostics: readonly VirtualDiagnosticShape[];
108
+ css: string;
109
+ }
110
+ /**
111
+ * Context carrying the full {@link ProjectSnapshot}. `null` sentinel lets
112
+ * `useSwatchbookData()` tell "provider present" from "fall back to the
113
+ * virtual module".
114
+ */
115
+ declare const SwatchbookContext: _$react.Context<ProjectSnapshot | null>;
116
+ declare function useOptionalSwatchbookData(): ProjectSnapshot | null;
117
+ /**
118
+ * Active swatchbook theme for the current story/docs render. Populated by
119
+ * the addon's preview decorator and consumed by `useToken` + any future
120
+ * consumer hooks.
121
+ *
122
+ * This runs through plain React context rather than Storybook's
123
+ * `useGlobals` so the same hook works in autodocs / MDX renders where the
124
+ * preview-hooks context isn't available.
125
+ */
126
+ declare const ThemeContext: _$react.Context<string>;
127
+ declare function useActiveTheme(): string;
128
+ /**
129
+ * Active axis tuple for the current story/docs render — `Record<axisName,
130
+ * contextName>`. Derived from the same input as {@link ThemeContext}; split
131
+ * out so consumers needing per-axis info (toolbar, panel, tuple-aware
132
+ * blocks) don't have to reparse the composed permutation ID.
133
+ */
134
+ declare const AxesContext: _$react.Context<Readonly<Record<string, string>>>;
135
+ declare function useActiveAxes(): Readonly<Record<string, string>>;
136
+ /**
137
+ * Active color-display format for the current story/docs render. Populated
138
+ * by the addon's preview decorator from the `swatchbookColorFormat` global
139
+ * (per-story `globals` or toolbar dropdown) and consumed by blocks that
140
+ * render color-token values. Emitted CSS is unaffected.
141
+ *
142
+ * Runs through plain React context rather than Storybook's `useGlobals` so
143
+ * per-story seeded globals flow through on first render and the same hook
144
+ * is safe to call from MDX doc blocks (where the preview-hooks context
145
+ * isn't available).
146
+ */
147
+ declare const ColorFormatContext: _$react.Context<ColorFormat | null>;
148
+ declare function useColorFormat(): ColorFormat;
149
+ //#endregion
150
+ //#region src/internal/sort-tokens.d.ts
151
+ type SortBy = 'path' | 'value' | 'none';
152
+ type SortDir = 'asc' | 'desc';
153
+ //#endregion
49
154
  //#region src/BorderPreview.d.ts
50
155
  interface BorderPreviewProps {
51
156
  /**
@@ -55,10 +160,20 @@ interface BorderPreviewProps {
55
160
  filter?: string;
56
161
  /** Override the caption. */
57
162
  caption?: string;
163
+ /**
164
+ * Sort order. `'path'` (default) sorts lexicographically on the
165
+ * dot-path; `'value'` falls through to path (borders don't have a
166
+ * single-axis ordering); `'none'` preserves project order.
167
+ */
168
+ sortBy?: SortBy;
169
+ /** `'asc'` (default) or `'desc'`. */
170
+ sortDir?: SortDir;
58
171
  }
59
172
  declare function BorderPreview({
60
173
  filter,
61
- caption
174
+ caption,
175
+ sortBy,
176
+ sortDir
62
177
  }: BorderPreviewProps): ReactElement;
63
178
  //#endregion
64
179
  //#region src/border-preview/BorderSample.d.ts
@@ -92,13 +207,44 @@ interface ColorPaletteProps {
92
207
  groupBy?: number;
93
208
  /** Override the section caption. */
94
209
  caption?: string;
210
+ /**
211
+ * Sort order within each group.
212
+ * - `'path'` (default) — lexicographic on the dot-path.
213
+ * - `'value'` — perceptual ordering: oklch L → C → H (ramps read
214
+ * light→dark, then warm→cool within each lightness band).
215
+ * - `'none'` — preserve project iteration order.
216
+ */
217
+ sortBy?: SortBy;
218
+ /** `'asc'` (default) or `'desc'`. */
219
+ sortDir?: SortDir;
95
220
  }
96
221
  declare function ColorPalette({
97
222
  filter,
98
223
  groupBy,
99
- caption
224
+ caption,
225
+ sortBy,
226
+ sortDir
100
227
  }: ColorPaletteProps): ReactElement;
101
228
  //#endregion
229
+ //#region src/Diagnostics.d.ts
230
+ interface DiagnosticsProps {
231
+ /** Override the section caption. Defaults to a severity summary. */
232
+ caption?: string;
233
+ }
234
+ /**
235
+ * Render the project's load diagnostics — parser errors, resolver warnings,
236
+ * disabled-axes validation issues, etc. — as a collapsible list. Auto-opens
237
+ * when the project carries errors or warnings; stays collapsed for clean
238
+ * loads and info-only loads.
239
+ *
240
+ * Replaces the diagnostics section from the addon's (now-retired) Design
241
+ * Tokens panel. Consumers compose it alongside TokenNavigator / TokenTable
242
+ * on their own MDX pages.
243
+ */
244
+ declare function Diagnostics({
245
+ caption
246
+ }?: DiagnosticsProps): ReactElement;
247
+ //#endregion
102
248
  //#region src/dimension-scale/DimensionBar.d.ts
103
249
  type DimensionKind = 'length' | 'radius' | 'size';
104
250
  interface DimensionBarProps {
@@ -133,11 +279,23 @@ interface DimensionScaleProps {
133
279
  kind?: DimensionKind;
134
280
  /** Override the caption. */
135
281
  caption?: string;
282
+ /**
283
+ * Sort order.
284
+ * - `'value'` (default) — numeric by rendered pixel size (`px` / `rem` / `em`).
285
+ * Non-convertible units (ex/ch/%) land after the convertible ones.
286
+ * - `'path'` — lexicographic on the dot-path.
287
+ * - `'none'` — preserve project iteration order.
288
+ */
289
+ sortBy?: SortBy;
290
+ /** `'asc'` (default) or `'desc'`. */
291
+ sortDir?: SortDir;
136
292
  }
137
293
  declare function DimensionScale({
138
294
  filter,
139
295
  kind,
140
- caption
296
+ caption,
297
+ sortBy,
298
+ sortDir
141
299
  }: DimensionScaleProps): ReactElement;
142
300
  //#endregion
143
301
  //#region src/FontFamilySample.d.ts
@@ -151,11 +309,21 @@ interface FontFamilySampleProps {
151
309
  sample?: string;
152
310
  /** Override the caption. */
153
311
  caption?: string;
312
+ /**
313
+ * Sort order. `'path'` (default) sorts lexicographically on the
314
+ * dot-path; `'value'` ordering falls through to path for this block's
315
+ * type (composite / non-numeric); `'none'` preserves project order.
316
+ */
317
+ sortBy?: SortBy;
318
+ /** `'asc'` (default) or `'desc'`. */
319
+ sortDir?: SortDir;
154
320
  }
155
321
  declare function FontFamilySample({
156
322
  filter,
157
323
  sample,
158
- caption
324
+ caption,
325
+ sortBy,
326
+ sortDir
159
327
  }: FontFamilySampleProps): ReactElement;
160
328
  //#endregion
161
329
  //#region src/FontWeightScale.d.ts
@@ -169,11 +337,22 @@ interface FontWeightScaleProps {
169
337
  sample?: string;
170
338
  /** Override the caption. */
171
339
  caption?: string;
340
+ /**
341
+ * Sort order.
342
+ * - `'value'` (default) — ascending numeric by weight (100 → 900).
343
+ * - `'path'` — lexicographic on the dot-path.
344
+ * - `'none'` — preserve project iteration order.
345
+ */
346
+ sortBy?: SortBy;
347
+ /** `'asc'` (default) or `'desc'`. */
348
+ sortDir?: SortDir;
172
349
  }
173
350
  declare function FontWeightScale({
174
351
  filter,
175
352
  sample,
176
- caption
353
+ caption,
354
+ sortBy,
355
+ sortDir
177
356
  }: FontWeightScaleProps): ReactElement;
178
357
  //#endregion
179
358
  //#region src/GradientPalette.d.ts
@@ -185,10 +364,20 @@ interface GradientPaletteProps {
185
364
  filter?: string;
186
365
  /** Override the caption. */
187
366
  caption?: string;
367
+ /**
368
+ * Sort order. `'path'` (default) sorts lexicographically on the
369
+ * dot-path; `'value'` falls through to path (gradients don't have
370
+ * a single-axis ordering); `'none'` preserves project order.
371
+ */
372
+ sortBy?: SortBy;
373
+ /** `'asc'` (default) or `'desc'`. */
374
+ sortDir?: SortDir;
188
375
  }
189
376
  declare function GradientPalette({
190
377
  filter,
191
- caption
378
+ caption,
379
+ sortBy,
380
+ sortDir
192
381
  }: GradientPaletteProps): ReactElement;
193
382
  //#endregion
194
383
  //#region src/motion-preview/MotionSample.d.ts
@@ -226,107 +415,6 @@ declare function MotionPreview({
226
415
  caption
227
416
  }: MotionPreviewProps): ReactElement;
228
417
  //#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' | 'layered' | '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 | null>;
328
- declare function useColorFormat(): ColorFormat;
329
- //#endregion
330
418
  //#region src/provider.d.ts
331
419
  interface SwatchbookProviderProps {
332
420
  value: ProjectSnapshot;
@@ -361,10 +449,20 @@ interface ShadowPreviewProps {
361
449
  filter?: string;
362
450
  /** Override the caption. */
363
451
  caption?: string;
452
+ /**
453
+ * Sort order. `'path'` (default) sorts lexicographically on the
454
+ * dot-path; `'value'` falls through to path (shadows don't have a
455
+ * single-axis ordering); `'none'` preserves project order.
456
+ */
457
+ sortBy?: SortBy;
458
+ /** `'asc'` (default) or `'desc'`. */
459
+ sortDir?: SortDir;
364
460
  }
365
461
  declare function ShadowPreview({
366
462
  filter,
367
- caption
463
+ caption,
464
+ sortBy,
465
+ sortDir
368
466
  }: ShadowPreviewProps): ReactElement;
369
467
  //#endregion
370
468
  //#region src/shadow-preview/ShadowSample.d.ts
@@ -385,10 +483,20 @@ interface StrokeStyleSampleProps {
385
483
  filter?: string;
386
484
  /** Override the caption. */
387
485
  caption?: string;
486
+ /**
487
+ * Sort order. `'path'` (default) sorts lexicographically on the
488
+ * dot-path; `'value'` ordering falls through to path for this block's
489
+ * type (composite / non-numeric); `'none'` preserves project order.
490
+ */
491
+ sortBy?: SortBy;
492
+ /** `'asc'` (default) or `'desc'`. */
493
+ sortDir?: SortDir;
388
494
  }
389
495
  declare function StrokeStyleSample({
390
496
  filter,
391
- caption
497
+ caption,
498
+ sortBy,
499
+ sortDir
392
500
  }: StrokeStyleSampleProps): ReactElement;
393
501
  //#endregion
394
502
  //#region src/TokenDetail.d.ts
@@ -510,16 +618,34 @@ interface TokenTableProps {
510
618
  filter?: string;
511
619
  /** Restrict to one DTCG `$type`. */
512
620
  type?: string;
513
- /** Show the CSS variable reference column. Defaults to `true`. */
514
- showVar?: boolean;
515
621
  /** Override the table caption. */
516
622
  caption?: string;
623
+ /**
624
+ * Sort order.
625
+ * - `'path'` (default) — lexicographic on the dot-path.
626
+ * - `'value'` — per-`$type`: numeric for `dimension` / `duration` /
627
+ * `fontWeight`; perceptual (oklch L → C → H) for `color`; lexicographic
628
+ * for `fontFamily` / `strokeStyle`. Composite types fall through to
629
+ * path order.
630
+ * - `'none'` — preserve project iteration order.
631
+ */
632
+ sortBy?: SortBy;
633
+ /** `'asc'` (default) or `'desc'`. */
634
+ sortDir?: SortDir;
635
+ /**
636
+ * Called with the clicked row's dot-path. When set, the built-in
637
+ * `<TokenDetail>` slide-over is suppressed — the consumer owns the
638
+ * follow-up UI (inline panel, drill-down route, …).
639
+ */
640
+ onSelect?(path: string): void;
517
641
  }
518
642
  declare function TokenTable({
519
643
  filter,
520
644
  type,
521
- showVar,
522
- caption
645
+ caption,
646
+ sortBy,
647
+ sortDir,
648
+ onSelect
523
649
  }: TokenTableProps): ReactElement;
524
650
  //#endregion
525
651
  //#region src/TypographyScale.d.ts
@@ -533,12 +659,22 @@ interface TypographyScaleProps {
533
659
  sample?: string;
534
660
  /** Override the caption. */
535
661
  caption?: string;
662
+ /**
663
+ * Sort order. `'path'` (default) sorts lexicographically on the
664
+ * dot-path; `'value'` ordering falls through to path for this block's
665
+ * type (composite / non-numeric); `'none'` preserves project order.
666
+ */
667
+ sortBy?: SortBy;
668
+ /** `'asc'` (default) or `'desc'`. */
669
+ sortDir?: SortDir;
536
670
  }
537
671
  declare function TypographyScale({
538
672
  filter,
539
673
  sample,
540
- caption
674
+ caption,
675
+ sortBy,
676
+ sortDir
541
677
  }: TypographyScaleProps): ReactElement;
542
678
  //#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 };
679
+ 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, Diagnostics, type DiagnosticsProps, 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
680
  //# sourceMappingURL=index.d.mts.map