ui-foundations 0.1.1 → 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.
Files changed (45) hide show
  1. package/README.md +68 -227
  2. package/dist/core/index.css +7 -7
  3. package/dist/main.css +462 -289
  4. package/dist/react/index.js +1 -0
  5. package/dist/react/switch.js +45 -0
  6. package/dist/tokens/css/{color.dark.tokens.css → appearance-(modes).tokens.mode-dark.css} +2 -2
  7. package/dist/tokens/css/{color.light.tokens.css → appearance-(modes).tokens.mode-light.css} +3 -3
  8. package/dist/tokens/css/{component.tokens.css → components-(ui).tokens.css} +70 -54
  9. package/dist/tokens/css/{primitives.tokens.css → core-(primitives).tokens.css} +21 -21
  10. package/dist/tokens/css/{semantic.tokens.css → semantics-(roles).tokens.css} +7 -6
  11. package/dist/tokens/css/{brand-a.tokens.css → themes-(brands).tokens.brand-a.css} +11 -11
  12. package/dist/tokens/css/{brand-b.tokens.css → themes-(brands).tokens.brand-b.css} +10 -10
  13. package/dist/tokens/json/appearance-(modes).tokens.mode-dark.json +182 -0
  14. package/dist/tokens/json/appearance-(modes).tokens.mode-light.json +182 -0
  15. package/dist/tokens/json/components-(ui).tokens.json +739 -0
  16. package/dist/tokens/json/{primitives.tokens.json → core-(primitives).tokens.json} +766 -772
  17. package/dist/tokens/json/semantics-(roles).tokens.json +203 -0
  18. package/dist/tokens/json/themes-(brands).tokens.brand-a.json +115 -0
  19. package/dist/tokens/json/themes-(brands).tokens.brand-b.json +115 -0
  20. package/dist/tokens/tokens.yaml +1068 -847
  21. package/dist/tokens/ts/{color.dark.tokens.ts → appearance-(modes).tokens.mode-dark.ts} +3 -3
  22. package/dist/tokens/ts/{color.light.tokens.ts → appearance-(modes).tokens.mode-light.ts} +4 -4
  23. package/dist/tokens/ts/{component.tokens.ts → components-(ui).tokens.ts} +71 -55
  24. package/dist/tokens/ts/{primitives.tokens.ts → core-(primitives).tokens.ts} +22 -22
  25. package/dist/tokens/ts/{semantic.tokens.ts → semantics-(roles).tokens.ts} +7 -6
  26. package/dist/tokens/ts/{brand-a.tokens.ts → themes-(brands).tokens.brand-a.ts} +13 -13
  27. package/dist/tokens/ts/{brand-b.tokens.ts → themes-(brands).tokens.brand-b.ts} +12 -12
  28. package/dist/ui/index.css +1 -0
  29. package/dist/ui/patterns/button.css +1 -0
  30. package/dist/ui/patterns/switch.css +155 -0
  31. package/docs/agentic/assistant-behavior-rules.md +16 -0
  32. package/docs/agentic/skills/README.md +51 -0
  33. package/docs/agentic/skills/design-ops-specialist/SKILL.md +60 -0
  34. package/docs/agentic/skills/design-system-architect/SKILL.md +106 -0
  35. package/docs/agentic/team-ai-playbook.md +226 -0
  36. package/docs/foundations/foundation-010-implementation-and-pipeline-workflow.md +82 -0
  37. package/docs/foundations/foundation-011-branching-and-release-governance.md +42 -0
  38. package/docs/foundations/foundation-012-minimal-markup-and-composition.md +42 -0
  39. package/package.json +24 -12
  40. package/dist/tokens/json/brand-a.tokens.json +0 -192
  41. package/dist/tokens/json/brand-b.tokens.json +0 -192
  42. package/dist/tokens/json/color.dark.tokens.json +0 -364
  43. package/dist/tokens/json/color.light.tokens.json +0 -364
  44. package/dist/tokens/json/component.tokens.json +0 -1101
  45. package/dist/tokens/json/semantic.tokens.json +0 -206
package/README.md CHANGED
@@ -1,259 +1,100 @@
1
1
  # UI Foundations
2
2
 
3
- This repository contains the **foundation layer** of our UI platform:
3
+ A token-first design system that uses Figma as the single source of truth and automatically generates CSS, JSON, and TypeScript tokens.
4
4
 
5
- - Design tokens (core primitives, color modes, semantic roles)
6
- - Component token APIs (variants, parts, properties, states)
7
- - Foundational architecture rules for long-term consistency
8
- - Docs/playground generated with Eleventy
5
+ ## Pipeline
9
6
 
10
- ## What this is
11
-
12
- - A **token-first** foundation that aligns **Figma Variables** with **CSS custom properties**
13
- - A **multi-brand** and **multi-mode** ready architecture
14
- - A place to document foundational rules that must remain stable over time
15
-
16
- ## What this is not (yet)
17
-
18
- - A full “product design system” with all patterns, usage guidelines, and governance
19
- - Product-specific application rules (these live downstream in product repositories)
20
-
21
- ## Architecture (4 layers)
22
-
23
- 1. **Core (Primitives)**
24
- Raw physical values: spacing, radii, borders, typography primitives, layout constants.
25
-
26
- 2. **Color Modes (Light/Dark)**
27
- Theme palettes: brand colors, neutrals, overlays. No semantic meaning.
28
-
29
- 3. **Semantics (Roles)**
30
- Meaning-based roles: `Color.Text.*`, `Color.Fill.*`, `Color.Border.*`, `Typography.*`, `Corner.*`.
31
- Supports brand modes (e.g. TUI, ROBINSON, LTUR).
32
-
33
- 4. **Components (APIs)**
34
- Component-level API rules: variants, parts, properties, states.
35
- Components reference semantic roles—**never raw values**.
36
-
37
- ## Naming conventions
38
-
39
- Component tokens use a **variant-first** grouping:
40
-
41
- `Component.variant.part.property.state`
42
-
43
- Example:
44
-
45
- - `Button.solid.container.background.default`
46
- - `Button.outline.container.border-color.hover`
47
-
48
- Rules:
49
-
50
- - **Typography never includes color** (color lives in `Color.Text.*`)
51
- - **Components never introduce new colors** (they reference semantic roles)
52
- - Layout primitives (breakpoints, container sizes, z-index) live in **Core**
53
-
54
- ## Repository structure
55
-
56
- - `figma/exports/` — token source exports from Figma
57
- - `dist/tokens/` — generated token artifacts (CSS/JSON/TS)
58
- - `src/` — package source layers (Core/UI/React)
59
- - `site/` — Eleventy preview/docs site (templates + docs-specific CSS)
60
- - `docs/foundations/` — foundational architecture and token rules (source of truth)
61
- - `docs/agentic/` — assistant behavior rules and AI collaboration playbooks
62
- - `figma/` — Figma exports, mappings, Code Connect notes
63
- - `AGENTS.md` — entrypoint for AI coding agents
64
-
65
- Docs structure (`site/`):
66
- - `_includes/layouts/` — shared Nunjucks layouts
67
- - `tokens/*.md` — token docs pages (Eleventy collection)
68
- - `components/*.md` — component docs pages (Eleventy collection)
69
- - `assets/docs.css` — docs-only styling
7
+ ```
8
+ Figma Variables → Plugin Export → figma/exports/*.tokens.json → extract-tokens.js → dist/ (CSS, JSON, TS, YAML)
9
+ ```
70
10
 
71
- AI collaboration:
72
- - `AGENTS.md` — quick entrypoint and baseline checks for agents
73
- - `docs/agentic/assistant-behavior-rules.md` — assistant-specific guardrails
74
- - `docs/agentic/team-ai-playbook.md` — standard AI-assisted workflows for component incubation and token roundtrips
11
+ ## Features
75
12
 
76
- ## Flow: Add a new component
13
+ - 5 variable collections: Core Primitives, Themes (Brands), Appearance (Modes), Semantics (Roles), Components (UI)
14
+ - Multi-brand support (Brand A/B) via `data-brand` selectors
15
+ - Dark/light mode via `data-mode` selectors
16
+ - Content-based scope detection (independent of filenames)
17
+ - Figma plugin with Validate + Export tabs (see `figma/plugin/README.md`)
18
+ - CI pipeline: lint, unit tests, build, smoke check, docs build
19
+ - Docs site with Eleventy, auto-generated from token data
77
20
 
78
- ```text
79
- Figma
80
- ├─ 0) Run boundary + utility check
81
- │ ├─ Is this a standalone component or composition of an existing one?
82
- │ └─ Snowflake check: one-off local case vs shared cross-context utility
83
- ├─ 1) Create/update component tokens
84
- │ └─ figma/exports/Component.tokens.json
85
- ├─ 2) (Optional) Add/update Code Connect mapping
86
- │ └─ figma/connections/web-<component>.figma.ts
87
- └─ 3) Regenerate generated artifacts
88
- └─ npm run build:all
89
- ├─ dist/tokens/*
90
- ├─ dist/ui/*
91
- ├─ dist/react/*
92
- └─ dist/main.css
21
+ ## Tech Stack
93
22
 
94
- Repository implementation
95
- ├─ 4) Add CSS pattern
96
- │ └─ src/ui/patterns/<component>.css
97
- ├─ 5) Export pattern in UI bundle
98
- │ └─ src/ui/index.css
99
- ├─ 6) Add React wrapper (if needed)
100
- │ ├─ src/react/<component>.js
101
- │ └─ src/react/index.js
102
- └─ 7) Add assets (if needed)
103
- └─ src/assets/*
23
+ Vanilla CSS (Custom Properties, Layers), Node.js scripts, Eleventy, Figma Plugin API, MCP.
104
24
 
105
- Documentation + Playground
106
- ├─ 8) Add component docs page
107
- │ └─ site/components/<component>.md
108
- ├─ 9) Add playground page
109
- │ └─ site/components/<component>-playground.md
110
- ├─ 10) Extend macros (if needed)
111
- │ └─ site/_includes/macros/{ui.njk,playground.njk}
112
- └─ 11) Extend playground runtime (only for new behavior)
113
- └─ site/assets/playground/{renderers.js,state.js,code.js,shared.js}
25
+ ## Install
114
26
 
115
- Validation
116
- ├─ npm run test:unit
117
- ├─ npm run build:all
118
- ├─ npm run docs:site
119
- └─ npm run ci:check
27
+ ```bash
28
+ npm install ui-foundations
120
29
  ```
121
30
 
122
- ## Flow: AI-assisted component incubation
123
-
124
- This project is designed for a collaborative build loop between design and implementation, not only for one-way token export.
31
+ ## Usage
125
32
 
126
- ```text
127
- Collaborative loop (real-world workflow)
128
- ├─ 0) Run boundary + utility check
129
- │ ├─ standalone component or composition inside an existing component family
130
- │ └─ Snowflake check: solves one local case or reusable across contexts
131
- ├─ 1) Ask the assistant for a proposed component setup
132
- │ ├─ component structure (HTML/CSS/React)
133
- │ ├─ token naming proposal
134
- │ └─ docs/playground example
135
- ├─ 2) Review and adapt the proposal
136
- │ └─ align names and states with your design language
137
- ├─ 3) Create/import the proposed tokens in Figma
138
- │ └─ refine values and variants in design
139
- ├─ 4) Export from Figma back into this repository
140
- │ └─ figma/exports/*.tokens.json
141
- ├─ 5) Let the assistant integrate and align implementation
142
- │ ├─ src/ui/patterns/<component>.css
143
- │ ├─ src/react/<component>.js
144
- │ ├─ site/components/<component>.md
145
- │ ├─ site/components/<component>-playground.md
146
- │ └─ figma/connections/web-<component>.figma.ts (if needed)
147
- └─ 6) Validate and iterate
148
- ├─ npm run ci:check
149
- └─ repeat loop for naming, states, a11y, and behavior refinements
33
+ ```js
34
+ import "ui-foundations/core.css";
35
+ import "ui-foundations/ui.css";
150
36
  ```
151
37
 
152
- Why this matters:
153
- - It closes the gap between design intent and production implementation.
154
- - It keeps token naming and component APIs consistent across Figma and code.
155
- - It makes component incubation faster while staying auditable in Git.
156
-
157
- ## Script locations
158
-
159
- - `scripts/` — build, token extraction, validation, lint and smoke-check automation for local/CI usage
160
- - `site/assets/playground/` — browser runtime modules for docs playground (shared helpers, state, code formatting, renderers)
161
- - `tests/` — unit tests for extraction helpers and edge-case behavior
162
-
163
- ## CSS variable naming
164
-
165
- CSS custom property names are derived from `com.figma.codeSyntax.WEB`.
166
- If a token is missing `codeSyntax.WEB`, a warning is logged and the build
167
- falls back to an auto-derived token name.
168
-
169
- Scopes are derived from export filenames:
170
-
171
- - `Brand X.tokens.json` -> `:root[data-brand="x"]`
172
- - `Mode Light.tokens.json` -> `:root`
173
- - `Mode Dark.tokens.json` -> `:root[data-mode="dark"]`
38
+ Runtime scope switching:
174
39
 
175
- ## Specification compliance
40
+ ```js
41
+ const root = document.documentElement;
42
+ root.dataset.brand = "a"; // "a" | "b"
43
+ root.dataset.mode = "light"; // "light" | "dark"
44
+ ```
176
45
 
177
- Generated JSON tokens follow the official Design Tokens Community Group format where applicable:
46
+ ## Local Development
178
47
 
179
- - W3C DTCG format: `https://www.designtokens.org/tr/drafts/format/`
180
- - Export normalization maps Figma values to spec-friendly types (for example `dimension`, `fontFamily`, `fontWeight`)
181
- - `fontWeight` values are emitted numerically in generated JSON, even if authored as strings in Figma
182
- - Distributed JSON in `dist/tokens/json/*.json` strips `com.figma.*` metadata for cleaner consumer output
183
- - Optional: include Figma metadata sidecars with `npm run tokens:generate -- --include-figma-metadata` (writes `*.figma.json`)
48
+ ```bash
49
+ npm run build:all # generate tokens + build CSS
50
+ npm run docs:dev # build + serve docs site
51
+ ```
184
52
 
185
- ## Quick start (local)
53
+ Figma sync workflow:
186
54
 
187
- 1. Read the foundation rules in `docs/foundations/`
188
- 2. Inspect source tokens in `figma/exports/` and generated tokens in `dist/tokens/`
189
- 3. Run `npm run docs:dev`
55
+ ```bash
56
+ # 1. Export tokens via Figma plugin (📦 Export tab)
57
+ # 2. Place JSON files in figma/exports/
58
+ # 3. Build
59
+ npm run build:all
60
+ ```
190
61
 
191
- ## Prompt to UI Component
62
+ Validation:
192
63
 
193
- Use this copy/paste prompt with AI when you want a new component scaffolded and implemented in this repo:
64
+ ```bash
65
+ npm run lint
66
+ npm run test:unit
67
+ npm run ci:check
68
+ ```
194
69
 
195
- ```text
196
- Scaffold and implement a new UI component named <component-name> in this repository.
70
+ ## MCP Integration
197
71
 
198
- Follow these sources strictly:
199
- - docs/agentic/team-ai-playbook.md
200
- - docs/agentic/assistant-behavior-rules.md
201
- - docs/foundations/*
72
+ This repo supports Figma integration via MCP (Model Context Protocol). Two servers are used:
202
73
 
203
- Execution requirements:
204
- 1) Run the Component Boundary Check first and state the decision (composition vs standalone).
205
- 2) Keep scope small, incremental, and reviewable in Git.
206
- 3) Implement token-first and reuse existing patterns:
207
- - src/ui/patterns/<component>.css
208
- - src/react/<component>.js and src/react/index.js (if needed)
209
- - site/components/<component>.md
210
- - site/components/<component>-playground.md
211
- - figma/connections/web-<component>.figma.ts (only if a publishable top-level Figma component/component-set exists)
212
- 4) Validate before handoff:
213
- - npm run lint
214
- - npm run test:unit
215
- - npm run ci:check
74
+ - `figma-developer-mcp` — REST API read access (requires `FIGMA_TOKEN` in `.env`)
75
+ - Figma Desktop MCP local server via Figma Desktop app (enable in Dev Mode inspect panel)
216
76
 
217
- Mandatory progress tracker for this task type:
218
- - Start with: Tasks completion: 0/4
219
- - Update after each phase: 1/4, 2/4, 3/4, 4/4
77
+ Configure these in your agent's MCP config. Example for the REST API server:
220
78
 
221
- Handoff format:
222
- - boundary decision result
223
- - files changed
224
- - validation results
225
- - open follow-ups (if any)
79
+ ```json
80
+ {
81
+ "command": "npx",
82
+ "args": ["-y", "figma-developer-mcp", "--figma-api-key=YOUR_TOKEN", "--stdio"]
83
+ }
226
84
  ```
227
85
 
228
- ## Build (local)
229
-
230
- 1. Optional syntax lint for JS files: `npm run lint`
231
- 2. Optional unit tests for extractor helpers: `npm run test:unit`
232
- 3. Generate token outputs (after Figma export updates): `npm run tokens:generate`
233
- 4. Build CSS bundles from already generated tokens: `npm run build:css`
234
- 5. Full refresh in one command (tokens + CSS): `npm run build:all`
235
- 6. Run smoke checks for generated artifacts: `npm run smoke:check`
236
- 7. Build docs: `npm run docs:site`
237
- 8. Run CI-equivalent checks locally: `npm run ci:check`
86
+ ## Documentation
238
87
 
239
- `npm run build:css` fails if `dist/tokens/css/*.tokens.css` does not exist yet.
88
+ - Foundations: `docs/foundations/`
89
+ - AI playbook: `docs/agentic/team-ai-playbook.md`
90
+ - Figma plugin (Token Foundry): `figma/plugin/README.md`
91
+ - Docs site: `site/`
92
+ - Vanilla starter: `site/examples/vanilla-starter.md`
240
93
 
241
- ## Token Pipeline Internals
94
+ ## Release
242
95
 
243
- `scripts/extract-tokens.js` is the orchestration entry point.
244
-
245
- Main helper modules:
246
- - `scripts/extract-tokens.utils.js` — parsing + normalization helpers (`readJsonLike`, `parseWebSyntax`, length/path utilities)
247
- - `scripts/extract-tokens.lookup.js` — alias lookup + cycle/missing-target handling
248
- - `scripts/extract-tokens.value.js` — token grouping + output value formatting
249
- - `scripts/extract-tokens.scope.js` — scope parsing and selector/output-base normalization
250
-
251
- Data flow:
252
- 1. Read `figma/exports/*.tokens.json` (JSON/JSONC supported)
253
- 2. Flatten tokens + resolve aliases across the combined lookup
254
- 3. Assign CSS variable names from `com.figma.codeSyntax.WEB`
255
- 4. Emit `dist/tokens/{css,json,ts}` and `dist/tokens/tokens.yaml`
256
-
257
- Fallback behavior:
258
- - Missing or invalid `com.figma.codeSyntax.WEB` values fall back to auto-derived CSS variable names and are reported in the extract summary.
259
- - Missing alias targets and alias cycles fall back to literal values and are reported.
96
+ ```bash
97
+ npm run release:patch # or release:minor / release:major
98
+ npm run release:push
99
+ npm run release:publish
100
+ ```
@@ -2,11 +2,11 @@
2
2
  @import url("./base/fonts.css") layer(base);
3
3
  @import url("./base/base.css") layer(base);
4
4
  @import url("./base/typography.css") layer(base);
5
- @import url("../tokens/css/primitives.tokens.css") layer(tokens);
6
- @import url("../tokens/css/brand-a.tokens.css") layer(tokens);
7
- @import url("../tokens/css/brand-b.tokens.css") layer(tokens);
8
- @import url("../tokens/css/semantic.tokens.css") layer(tokens);
9
- @import url("../tokens/css/component.tokens.css") layer(tokens);
10
- @import url("../tokens/css/color.light.tokens.css") layer(tokens);
11
- @import url("../tokens/css/color.dark.tokens.css") layer(tokens);
5
+ @import url("../tokens/css/semantics-(roles).tokens.css") layer(tokens);
6
+ @import url("../tokens/css/components-(ui).tokens.css") layer(tokens);
7
+ @import url("../tokens/css/appearance-(modes).tokens.mode-dark.css") layer(tokens);
8
+ @import url("../tokens/css/appearance-(modes).tokens.mode-light.css") layer(tokens);
9
+ @import url("../tokens/css/core-(primitives).tokens.css") layer(tokens);
10
+ @import url("../tokens/css/themes-(brands).tokens.brand-a.css") layer(tokens);
11
+ @import url("../tokens/css/themes-(brands).tokens.brand-b.css") layer(tokens);
12
12
  @import url("./themes/mode.css") layer(themes);