@unpunnyfuns/swatchbook-blocks 1.0.0-alpha.0 → 1.0.0-alpha.2

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
@@ -62,7 +62,7 @@ interface VirtualTokenShape {
62
62
  * the single canonical wire shape; both the addon's plugin (server-side
63
63
  * emit) and blocks (consumer-side read) reference the same definition.
64
64
  */
65
- type VirtualTokenListingShape = SlimListedToken;
65
+ type VirtualTokenListing = SlimListedToken;
66
66
  type VirtualPresetShape = Preset;
67
67
  /**
68
68
  * Wire shape of the token graph — aliased from core's authoritative
@@ -88,7 +88,13 @@ interface ProjectSnapshot {
88
88
  */
89
89
  indicators?: Readonly<Record<string, boolean>>;
90
90
  diagnostics: readonly VirtualDiagnosticShape[];
91
- css: string;
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;
92
98
  /**
93
99
  * Path-indexed Token Listing data produced by
94
100
  * `@terrazzo/plugin-token-listing`. Blocks prefer reading authoritative
@@ -96,7 +102,7 @@ interface ProjectSnapshot {
96
102
  * projects. Treat as enrichment — fall back gracefully when a path is
97
103
  * absent.
98
104
  */
99
- listing?: Readonly<Record<string, VirtualTokenListingShape>>;
105
+ listing?: Readonly<Record<string, VirtualTokenListing>>;
100
106
  /**
101
107
  * Pre-built token graph for the project. JSON-serializable; nodes
102
108
  * carry per-axis writes plus alias edges. The blocks hook backs
@@ -117,12 +123,6 @@ interface ProjectSnapshot {
117
123
  */
118
124
  resolveAt?: (tuple: Record<string, string>) => Record<string, VirtualTokenShape>;
119
125
  }
120
- /**
121
- * Context carrying the full {@link ProjectSnapshot}. `null` sentinel lets
122
- * `useSwatchbookData()` tell "provider present" from "fall back to the
123
- * virtual module".
124
- */
125
- declare const SwatchbookContext: _$react.Context<ProjectSnapshot | null>;
126
126
  declare function useOptionalSwatchbookData(): ProjectSnapshot | null;
127
127
  /**
128
128
  * Active swatchbook theme for the current story/docs render. Populated by
@@ -341,9 +341,11 @@ declare function Diagnostics({
341
341
  caption
342
342
  }?: DiagnosticsProps): ReactElement;
343
343
  //#endregion
344
- //#region src/dimension-scale/DimensionBar.d.ts
344
+ //#region src/dimension-scale/DimensionSample.d.ts
345
+ /** The visual treatment for a dimension sample: a length bar, a radius square, or a sized square. */
345
346
  type DimensionVisual = 'length' | 'radius' | 'size';
346
- interface DimensionBarProps {
347
+ /** Props for the connected {@link DimensionSample} block. */
348
+ interface DimensionSampleProps {
347
349
  /** Full dot-path of the dimension token to preview. */
348
350
  path: string;
349
351
  /**
@@ -354,10 +356,11 @@ interface DimensionBarProps {
354
356
  */
355
357
  visual?: DimensionVisual;
356
358
  }
357
- declare function DimensionBar({
359
+ /** Connected block: resolves `path` against the active project and renders its dimension sample. */
360
+ declare function DimensionSample({
358
361
  path,
359
362
  visual
360
- }: DimensionBarProps): ReactElement;
363
+ }: DimensionSampleProps): ReactElement;
361
364
  //#endregion
362
365
  //#region src/DimensionScale.d.ts
363
366
  interface DimensionScaleProps {
@@ -497,6 +500,13 @@ declare function MotionSample({
497
500
  }: MotionSampleProps): ReactElement;
498
501
  //#endregion
499
502
  //#region src/MotionPreview.d.ts
503
+ /**
504
+ * Unlike the other filter/caption/sortBy/sortDir blocks in this family,
505
+ * `MotionPreview` has no `sortBy`/`sortDir` — rows are always ordered by
506
+ * kind (`transition` / `duration` / `cubicBezier`) then path. There's no
507
+ * single numeric axis across the three kinds that a sort would meaningfully
508
+ * order by.
509
+ */
500
510
  interface MotionPreviewProps {
501
511
  /**
502
512
  * Token-path filter. Defaults to transition + duration + cubicBezier
@@ -580,6 +590,12 @@ declare function useChannelGlobals(): ChannelGlobals;
580
590
  //#endregion
581
591
  //#region src/internal/channel.d.ts
582
592
  /**
593
+ * Host adapter API — a distinct tier from the components/hooks/
594
+ * `SwatchbookProvider` surface that MDX/story authors use. This is how a
595
+ * host (Storybook's addon, or an alternative embedding) injects live data
596
+ * into blocks without blocks depending on that host. Most consumers never
597
+ * touch this; it exists for whoever builds the next integration.
598
+ *
583
599
  * Minimal event-source contract blocks need from their host. Storybook's
584
600
  * preview Channel satisfies it structurally; a plain emitter or a test double
585
601
  * does too. Blocks never import `storybook/preview-api` — the addon, which
@@ -591,13 +607,19 @@ interface BlockChannel {
591
607
  on<T>(event: string, listener: (payload: T) => void): void;
592
608
  }
593
609
  /**
594
- * Inject the host channel. Called once by the addon preview at init. Runs any
595
- * subscribers that registered before the channel existed, then clears the
596
- * queue. Idempotent for consumers: each subscriber guards its own attach, so a
597
- * re-register (HMR) does not double-wire.
610
+ * Host adapter API. The single most load-bearing function in the host
611
+ * contract the addon calls it once at preview init.
612
+ *
613
+ * Inject the host channel. Runs any subscribers that queued before the
614
+ * channel existed, then clears the queue. The host contract does NOT dedupe:
615
+ * on HMR a subscriber's module re-runs {@link onChannel}, which re-attaches
616
+ * immediately once the channel is set, so each subscriber MUST guard its own
617
+ * attach to stay single-wired.
598
618
  */
599
619
  declare function registerChannel(next: BlockChannel): void;
600
620
  /**
621
+ * Host adapter API — see {@link registerChannel}.
622
+ *
601
623
  * Attach a subscriber to the host channel now if one is registered, else queue
602
624
  * it to run the moment {@link registerChannel} fires. Blocks call this at
603
625
  * module load; the queue absorbs the gap until the addon injects the channel.
@@ -631,6 +653,12 @@ declare function useSwatchbookData(): ProjectSnapshot;
631
653
  //#endregion
632
654
  //#region src/internal/channel-tokens.d.ts
633
655
  /**
656
+ * Host adapter API — same integration tier as {@link BlockChannel} /
657
+ * {@link registerChannel} / {@link onChannel}, distinct from the
658
+ * components/hooks/`SwatchbookProvider` surface MDX/story authors use.
659
+ * Most consumers never touch this; it exists for whoever builds the next
660
+ * host integration.
661
+ *
634
662
  * Live token snapshot backed by the addon's preview dev-time HMR event.
635
663
  *
636
664
  * The initial snapshot is *injected* by the addon preview via
@@ -646,6 +674,7 @@ declare function useSwatchbookData(): ProjectSnapshot;
646
674
  * `useSyncExternalStore`, so hooks re-render in place on each token save.
647
675
  */
648
676
  declare const TOKENS_UPDATED_EVENT = "swatchbook/tokens-updated";
677
+ /** Host adapter API — see {@link registerTokenSource}. */
649
678
  interface TokenSnapshot {
650
679
  readonly axes: readonly VirtualAxisShape[];
651
680
  readonly presets: readonly {
@@ -658,13 +687,15 @@ interface TokenSnapshot {
658
687
  readonly cssVarPrefix: string;
659
688
  /** Project-wide baseline for the row-indicator strip from `config.indicators`. */
660
689
  readonly indicators: Readonly<Record<string, boolean>>;
661
- readonly listing: Readonly<Record<string, VirtualTokenListingShape>>;
690
+ readonly listing: Readonly<Record<string, VirtualTokenListing>>;
662
691
  readonly tokenGraph: VirtualTokenGraph;
663
692
  readonly defaultTuple: Record<string, string>;
664
693
  /** Monotonic counter, bumped on each update. Useful as a React key. */
665
694
  readonly version: number;
666
695
  }
667
696
  /**
697
+ * Host adapter API — same integration tier as {@link registerChannel}.
698
+ *
668
699
  * Seed the initial token snapshot. The addon preview calls this once at
669
700
  * init with the build-time `virtual:swatchbook/tokens` data. Keeping the
670
701
  * virtual-module read on the addon side (the package that owns it) lets
@@ -672,6 +703,12 @@ interface TokenSnapshot {
672
703
  * snapshot, so a partial source is safe.
673
704
  */
674
705
  declare function registerTokenSource(source: Partial<TokenSnapshot>): void;
706
+ /**
707
+ * Host adapter API — same integration tier as {@link registerChannel}. Most
708
+ * consumers read project data through `useSwatchbookData()` /
709
+ * `SwatchbookProvider` instead; this is the internal subscription
710
+ * `useProject()`'s fallback path uses to read the live channel-fed snapshot.
711
+ */
675
712
  declare function useTokenSnapshot(): TokenSnapshot;
676
713
  //#endregion
677
714
  //#region src/ShadowPreview.d.ts
@@ -822,7 +859,13 @@ declare function TokenUsageSnippet({
822
859
  //#endregion
823
860
  //#region src/TokenNavigator.d.ts
824
861
  interface TokenNavigatorProps {
825
- /** If provided, mount at this dot-path subtree and hide everything outside it. */
862
+ /**
863
+ * If provided, mount at this dot-path subtree and hide everything outside
864
+ * it. Unlike every other listing block's `filter` (a glob over paths,
865
+ * inclusion-only), `root` is a single literal path that also affects
866
+ * where the tree mounts and how breadcrumbs render — it re-roots the
867
+ * navigator, not just narrows its rows.
868
+ */
826
869
  root?: string;
827
870
  /**
828
871
  * Restrict the tree to tokens with the given DTCG `$type`(s). Pass a single
@@ -830,6 +873,10 @@ interface TokenNavigatorProps {
830
873
  * small-multiples view (`type={['duration', 'cubicBezier', 'transition']}`).
831
874
  * Composes with `root` — both constraints must hold. Group nodes that end
832
875
  * up with no surviving leaves collapse out.
876
+ *
877
+ * Accepts `string | readonly string[]` — wider than `TokenTableProps.type`
878
+ * (`string`-only) because a small-multiples tree view benefits from
879
+ * multi-type scoping in a way a flat table doesn't.
833
880
  */
834
881
  type?: string | readonly string[];
835
882
  /**
@@ -966,5 +1013,5 @@ declare function TypographyScale({
966
1013
  sortDir
967
1014
  }: TypographyScaleProps): ReactElement;
968
1015
  //#endregion
969
- export { AliasChain, type AliasChainProps, AliasedBy, type AliasedByProps, AxesContext, AxisVariance, type AxisVarianceProps, type BlockChannel, BorderPreview, type BorderPreviewProps, BorderSample, type BorderSampleProps, COLOR_FORMATS, type ChannelGlobals, type ColorFormat, ColorFormatContext, ColorPalette, type ColorPaletteProps, ColorTable, type ColorTableProps, CompositeBreakdown, type CompositeBreakdownProps, CompositePreview, type CompositePreviewProps, ConsumerOutput, type ConsumerOutputProps, Diagnostics, type DiagnosticsProps, DimensionBar, type DimensionBarProps, DimensionScale, type DimensionScaleProps, type DimensionVisual, FontFamilyPreview, type FontFamilyPreviewProps, FontWeightScale, type FontWeightScaleProps, type FormatColorResult, GradientPalette, type GradientPaletteProps, MotionPreview, type MotionPreviewProps, MotionSample, type MotionSampleProps, type MotionSpeed, type NormalizedColor, OpacityScale, type OpacityScaleProps, type ProjectSnapshot, ShadowPreview, type ShadowPreviewProps, ShadowSample, type ShadowSampleProps, StrokeStylePreview, type StrokeStylePreviewProps, SwatchbookContext, SwatchbookProvider, type SwatchbookProviderProps, TOKENS_UPDATED_EVENT, ThemeContext, TokenDetail, type TokenDetailProps, TokenHeader, type TokenHeaderProps, TokenNavigator, type TokenNavigatorProps, type TokenSnapshot, 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 VirtualTokenShape as VirtualToken, type VirtualTokenShape, type VirtualTokenGraph, type VirtualTokenListingShape, formatColor, onChannel, registerChannel, registerTokenSource, useActiveAxes, useActiveTheme, useChannelGlobals, useColorFormat, useOptionalSwatchbookData, useSwatchbookData, useTokenSnapshot };
1016
+ export { AliasChain, type AliasChainProps, AliasedBy, type AliasedByProps, AxesContext, AxisVariance, type AxisVarianceProps, type BlockChannel, BorderPreview, type BorderPreviewProps, BorderSample, type BorderSampleProps, COLOR_FORMATS, type ChannelGlobals, type ColorFormat, ColorFormatContext, ColorPalette, type ColorPaletteProps, ColorTable, type ColorTableProps, CompositeBreakdown, type CompositeBreakdownProps, CompositePreview, type CompositePreviewProps, ConsumerOutput, type ConsumerOutputProps, Diagnostics, type DiagnosticsProps, DimensionSample, type DimensionSampleProps, DimensionScale, type DimensionScaleProps, type DimensionVisual, FontFamilyPreview, type FontFamilyPreviewProps, FontWeightScale, type FontWeightScaleProps, type FormatColorResult, GradientPalette, type GradientPaletteProps, type IndicatorName, type IndicatorsProp, MotionPreview, type MotionPreviewProps, MotionSample, type MotionSampleProps, type MotionSpeed, type NormalizedColor, OpacityScale, type OpacityScaleProps, type ProjectSnapshot, ShadowPreview, type ShadowPreviewProps, ShadowSample, type ShadowSampleProps, type SortBy, type SortDir, StrokeStylePreview, type StrokeStylePreviewProps, SwatchbookProvider, type SwatchbookProviderProps, TOKENS_UPDATED_EVENT, ThemeContext, TokenDetail, type TokenDetailProps, TokenHeader, type TokenHeaderProps, TokenNavigator, type TokenNavigatorProps, type TokenSnapshot, TokenTable, type TokenTableProps, TokenUsageSnippet, type TokenUsageSnippetProps, TypographyScale, type TypographyScaleProps, type VirtualAxisShape as VirtualAxis, type VirtualDiagnosticShape as VirtualDiagnostic, type VirtualPresetShape as VirtualPreset, type VirtualTokenShape as VirtualToken, type VirtualTokenGraph, type VirtualTokenListing, formatColor, onChannel, registerChannel, registerTokenSource, useActiveAxes, useActiveTheme, useChannelGlobals, useColorFormat, useOptionalSwatchbookData, useSwatchbookData, useTokenSnapshot };
970
1017
  //# sourceMappingURL=index.d.mts.map