@thatch-health/slab-tokens 0.0.5 → 0.0.6

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 CHANGED
@@ -2,9 +2,85 @@
2
2
 
3
3
  This package is the pipeline for importing Figma tokens defined in [Token Foundations](https://www.figma.com/design/AMVtHovyyMCo78skFvePV4/Token-Foundations?node-id=32-93&p=f&t=fLz0IYz5irefoKsl-11) and then outputing in appropriate formats for web, the marketing website, and slab design system itself. This package uses [Terrazzo](https://terrazzo.app/) to manage the conversion from the [Design Token Community Group](https://www.designtokens.org/) specification which is a universal token specification. The package itself exports a few endpoints for consumers to use:
4
4
 
5
+ - `@thatch-health/slab-tokens` - The `getToken` and `mergeToken` JavaScript API for querying token metadata
5
6
  - `@thatch-health/slab-tokens/tokens-raw` - The raw JSON values of the DTCG specification downloaded from Figma
6
- - `@thatch-health/slab-tokens/css` - The output from terrazzo using the css plugin
7
- - `@thatch-health/slab-tokens/tailwind-v3-plugin` - A plugin for tailwind v3 that maps css variables
7
+ - `@thatch-health/slab-tokens/css/app` - CSS custom properties output from Terrazzo (import in a root CSS file)
8
+ - `@thatch-health/slab-tokens/tailwind-v3-plugin` - A plugin for Tailwind v3 that maps CSS variables to utility classes
9
+ - `@thatch-health/slab-tokens/tailwind-v4-plugin` - A CSS plugin for Tailwind v4 that maps CSS variables to utility classes
10
+
11
+ ## Installation
12
+
13
+ Install the package:
14
+
15
+ ```bash
16
+ npm i @thatch-health/slab-tokens
17
+ ```
18
+
19
+ ### Import CSS
20
+
21
+ In a root `.css` file, import the token styles:
22
+
23
+ ```css
24
+ @import "@thatch-health/slab-tokens/css/app";
25
+ ```
26
+
27
+ ### Tailwind v3
28
+
29
+ In your `tailwind.config.js`, import the plugin and add it to your plugins array:
30
+
31
+ ```ts
32
+ import slabPlugin from "@thatch-health/slab-tokens/tailwind-v3-plugin";
33
+
34
+ const config = {
35
+ plugins: [slabPlugin],
36
+ };
37
+
38
+ export default config;
39
+ ```
40
+
41
+ ### Tailwind v4
42
+
43
+ In the CSS file where you import Tailwind, add both the CSS tokens and the v4 plugin:
44
+
45
+ ```css
46
+ @import "tailwindcss";
47
+ @import "@thatch-health/slab-tokens/css/app";
48
+ @import "@thatch-health/slab-tokens/tailwind-v4-plugin";
49
+ ```
50
+
51
+ ## `getToken` API
52
+
53
+ The package exposes a `getToken` function for querying token metadata programmatically. This is useful for MCP servers, documentation tooling, or any code that needs to discover which tokens apply to a given design intent.
54
+
55
+ ```ts
56
+ import { getToken } from "@thatch-health/slab-tokens";
57
+ ```
58
+
59
+ `getToken` accepts an options object where **at least one field is required**. Multiple fields are ANDed together to narrow results.
60
+
61
+ | Option | Type | Description |
62
+ | ---------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
63
+ | `category` | `TokenCategory` | Filter by design intent: `"surface"`, `"action"`, `"form"`, `"typography"`, `"dimension"`, `"radius"`, `"gap"`, `"spacing"`, `"stroke"` |
64
+ | `scope` | `Scope` | Filter by broad token kind: `"color"`, `"spacing"`, or `"typography"` |
65
+ | `property` | `CSSProperty` | Filter by the CSS property the token applies to (e.g. `"background"`, `"padding"`, `"font-size"`) |
66
+ | `name` | `string` | Fuzzy-match on token name (e.g. `"action primary bg"` matches `"action.default.primary.bg"`) |
67
+
68
+ Each result is a `MergedToken` which includes the DTCG token fields plus a `$extensions["thatch.slab"]` entry describing the CSS variable, Tailwind class(es), and applicable CSS properties.
69
+
70
+ ### Examples
71
+
72
+ ```ts
73
+ // All action color tokens
74
+ getToken({ category: "action", scope: "color" });
75
+
76
+ // Tokens that set the background property on action components, filtered by name
77
+ getToken({ property: "background", category: "action", name: "default" });
78
+ // → ["action.default.ghost.bg", "action.default.primary.bg", ...]
79
+
80
+ // Fuzzy search by name
81
+ getToken({ name: "action.default.primary.bg" });
82
+ // → includes "action.default.primary.bg", "action.default.primary.bg-end", etc.
83
+ ```
8
84
 
9
85
  ## Development
10
86
 
package/dist/index.d.mts CHANGED
@@ -1754,8 +1754,9 @@ interface FigmaToken {
1754
1754
  $description?: string;
1755
1755
  $extensions?: FigmaExtensions;
1756
1756
  }
1757
+ type RequireAtLeastOne<T> = { [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>> }[keyof T];
1757
1758
  //#endregion
1758
- //#region src/index.d.ts
1759
+ //#region src/merge-token.d.ts
1759
1760
  declare const COLOR_MODES: readonly ["neutral", "danger", "info", "neutral-inverted", "success", "warning"];
1760
1761
  type ColorMode = (typeof COLOR_MODES)[number];
1761
1762
  type SlabEntry = {
@@ -1772,6 +1773,7 @@ type SlabEntry = {
1772
1773
  note?: string;
1773
1774
  };
1774
1775
  type MergedToken = FigmaToken & {
1776
+ $name: string;
1775
1777
  $extensions: {
1776
1778
  "com.figma.variableId"?: string;
1777
1779
  "thatch.slab": SlabEntry;
@@ -1780,5 +1782,43 @@ type MergedToken = FigmaToken & {
1780
1782
  };
1781
1783
  declare function mergeToken(key: keyof typeof tokenMap): MergedToken | null;
1782
1784
  //#endregion
1783
- export { ColorMode, MergedToken, SlabEntry, mergeToken };
1785
+ //#region src/get-token.d.ts
1786
+ /**
1787
+ * A semantic grouping of tokens by their design intent.
1788
+ * Use `category` to narrow results to a specific part of the design system.
1789
+ */
1790
+ type TokenCategory = /** Page backgrounds, cards, banners, and other non-interactive containers. */"surface" /** Base page background. Primary surfaces sit at the bottom of the visual stack. */ | "surface-primary" /** Elevated containers such as sidebars, panels, or cards placed on a primary surface. */ | "surface-secondary" /** Badges, nav bars, or chips that sit on top of primary or secondary surfaces. */ | "surface-tertiary" /** Buttons, links, dropdowns, and other interactive controls. */ | "action" /** The most prominent interactive element on a view. Use sparingly — one per view. Includes default, hover, and disabled states. */ | "action-primary" /** Supporting interactive elements like secondary buttons or sidebar nav rows. Includes default, hover, and disabled states. */ | "action-secondary" /** Interactive elements that appear as plain text until engaged, like cancel buttons. Includes default, hover, and disabled states. */ | "action-ghost" /** Link-style interactive elements that use color to signal interactivity. Includes default, hover, and disabled states. */ | "action-tertiary" /** Text fields, selects, checkboxes, radio buttons, and other form inputs. */ | "form" /** Primary form control surfaces — input backgrounds, borders, and text. Includes default, disabled, and active states. */ | "form-primary" /** Secondary form text — helper text and supplemental labels. Includes default, disabled, and active states. */ | "form-secondary" /** All typography tokens. Use sub-categories below for narrower results. */ | "typography" /** Display/heading type tokens — large expressive text. */ | "display" /** Header tokens — section headings. */ | "header" /** Body tokens — default reading text. */ | "body" /** Control tokens — labels, buttons, and UI chrome. */ | "control" /** Mono tokens — code and tabular data. */ | "mono" /** Fixed-size tokens for elements like buttons or badges (width / height). */ | "dimension" /** Border-radius tokens. */ | "radius" /** Gap tokens for flex and grid layouts (inline and stack). */ | "gap" /** Inset tokens for padding and margin. */ | "spacing" /** Border-width tokens. */ | "stroke";
1791
+ /**
1792
+ * The broad kind of a token.
1793
+ * - `"color"` — fills, text colors, border colors, and gradients.
1794
+ * - `"spacing"` — padding, margin, gap, size, border-radius, and border-width.
1795
+ * - `"typography"` — font-family, font-size, font-weight, line-height, letter-spacing.
1796
+ */
1797
+ type Scope = "color" | "spacing" | "typography";
1798
+ /**
1799
+ * The CSS property a token directly applies to.
1800
+ * Scoped to properties that are actually present in the shipped token set.
1801
+ */
1802
+ type CSSProperty = "background" | "color" | "border-color" | "outline-color" | "--tw-gradient-from" | "--tw-gradient-to" | "font-family" | "font-size" | "font-weight" | "line-height" | "letter-spacing" | "padding" | "padding-top" | "padding-right" | "padding-bottom" | "padding-left" | "margin" | "margin-top" | "margin-right" | "margin-bottom" | "margin-left" | "border-width" | "border-top-width" | "border-right-width" | "border-bottom-width" | "border-left-width" | "gap" | "column-gap" | "row-gap" | "width" | "height" | "min-width" | "min-height" | "border-radius";
1803
+ /**
1804
+ * Options for {@link getToken}. At least one field must be provided.
1805
+ * Multiple fields are ANDed — each one further narrows the result set.
1806
+ */
1807
+ type GetTokenOptions = RequireAtLeastOne<{
1808
+ /** Narrow by design intent (e.g. `"action"` returns button/link tokens). */category: TokenCategory; /** Narrow by broad token kind: color, spacing, or typography. */
1809
+ scope: Scope; /** Narrow by the CSS property the token sets. */
1810
+ property: CSSProperty;
1811
+ /**
1812
+ * Fuzzy-match on the token name using fuse.js.
1813
+ * e.g. `"action primary bg"` will match `"action.default.primary.bg"`.
1814
+ */
1815
+ name: string;
1816
+ }>;
1817
+ /**
1818
+ * Search for design tokens matching the given options.
1819
+ * At least one option must be provided. Multiple options are ANDed together.
1820
+ */
1821
+ declare function getToken(options: GetTokenOptions): MergedToken[];
1822
+ //#endregion
1823
+ export { type CSSProperty, type ColorMode, type GetTokenOptions, type MergedToken, type Scope, type SlabEntry, type TokenCategory, getToken, mergeToken };
1784
1824
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/token-map.ts","../src/utils/types.ts","../src/index.ts"],"mappings":";cASa,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAb;;;;;;UCDiB,cAAA;EACf,gBAAA;EACA,kBAAA;EACA,qBAAA;AAAA;;;;;KAOU,aAAA;AAAA,UAyBK,eAAA;EACf,sBAAA;EACA,kBAAA,GAAqB,aAAA;EACrB,sBAAA;IACE,GAAA;EAAA;EAEF,gCAAA;EACA,sBAAA;EACA,oBAAA;EACA,gBAAA;EACA,qBAAA,GAAwB,cAAA;AAAA;AAAA,UAGT,eAAA;EACf,UAAA;EACA,UAAA;EACA,KAAA;EACA,GAAA;AAAA;AAAA,UAGe,UAAA;EACf,KAAA;EACA,MAAA,oBAA0B,eAAA;EAC1B,YAAA;EACA,WAAA,GAAc,eAAA;AAAA;;;cCvDV,WAAA;AAAA,KAQM,SAAA,WAAoB,WAAA;AAAA,KAEpB,SAAA;EACV,WAAA;EACA,IAAA;EACA,QAAA;iFAEE,WAAA;IAEA,aAAA;EAAA;;;;;EAMF,IAAA;AAAA;AAAA,KAGU,WAAA,GAAc,UAAA;EACxB,WAAA;IACE,sBAAA;IACA,aAAA,EAAe,SAAA;IACf,cAAA,GAAiB,MAAA,CAAO,SAAA;EAAA;AAAA;AAAA,iBA8EZ,UAAA,CAAW,GAAA,eAAkB,QAAA,GAAW,WAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/token-map.ts","../src/utils/types.ts","../src/merge-token.ts","../src/get-token.ts"],"mappings":";cASa,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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