figma-console-mcp 1.27.0 → 1.28.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 +25 -18
- package/dist/core/tokens/formatters/dtcg.d.ts +3 -2
- package/dist/core/tokens/formatters/dtcg.d.ts.map +1 -1
- package/dist/core/tokens/formatters/dtcg.js +3 -2
- package/dist/core/tokens/formatters/dtcg.js.map +1 -1
- package/dist/core/tokens/formatters/json.d.ts +34 -2
- package/dist/core/tokens/formatters/json.d.ts.map +1 -1
- package/dist/core/tokens/formatters/json.js +176 -5
- package/dist/core/tokens/formatters/json.js.map +1 -1
- package/dist/core/tokens/formatters/scss.d.ts +23 -1
- package/dist/core/tokens/formatters/scss.d.ts.map +1 -1
- package/dist/core/tokens/formatters/scss.js +251 -3
- package/dist/core/tokens/formatters/scss.js.map +1 -1
- package/dist/core/tokens/formatters/stubs.d.ts +3 -2
- package/dist/core/tokens/formatters/stubs.d.ts.map +1 -1
- package/dist/core/tokens/formatters/stubs.js +4 -3
- package/dist/core/tokens/formatters/stubs.js.map +1 -1
- package/dist/core/tokens/formatters/style-dictionary-v3.d.ts +42 -1
- package/dist/core/tokens/formatters/style-dictionary-v3.d.ts.map +1 -1
- package/dist/core/tokens/formatters/style-dictionary-v3.js +206 -3
- package/dist/core/tokens/formatters/style-dictionary-v3.js.map +1 -1
- package/dist/core/tokens/formatters/tailwind-v3.d.ts +34 -1
- package/dist/core/tokens/formatters/tailwind-v3.d.ts.map +1 -1
- package/dist/core/tokens/formatters/tailwind-v3.js +222 -3
- package/dist/core/tokens/formatters/tailwind-v3.js.map +1 -1
- package/dist/core/tokens/formatters/tailwind-v4.d.ts +38 -1
- package/dist/core/tokens/formatters/tailwind-v4.d.ts.map +1 -1
- package/dist/core/tokens/formatters/tailwind-v4.js +313 -3
- package/dist/core/tokens/formatters/tailwind-v4.js.map +1 -1
- package/dist/core/tokens/formatters/tokens-studio.d.ts +41 -1
- package/dist/core/tokens/formatters/tokens-studio.d.ts.map +1 -1
- package/dist/core/tokens/formatters/tokens-studio.js +249 -3
- package/dist/core/tokens/formatters/tokens-studio.js.map +1 -1
- package/dist/core/tokens/formatters/ts-module.d.ts +32 -1
- package/dist/core/tokens/formatters/ts-module.d.ts.map +1 -1
- package/dist/core/tokens/formatters/ts-module.js +190 -3
- package/dist/core/tokens/formatters/ts-module.js.map +1 -1
- package/dist/core/tokens/parsers/stubs.d.ts +4 -3
- package/dist/core/tokens/parsers/stubs.d.ts.map +1 -1
- package/dist/core/tokens/parsers/stubs.js +5 -4
- package/dist/core/tokens/parsers/stubs.js.map +1 -1
- package/dist/core/tokens/transforms/color.d.ts +3 -1
- package/dist/core/tokens/transforms/color.d.ts.map +1 -1
- package/dist/core/tokens/transforms/color.js +6 -3
- package/dist/core/tokens/transforms/color.js.map +1 -1
- package/dist/core/tokens/transforms/index.d.ts +4 -2
- package/dist/core/tokens/transforms/index.d.ts.map +1 -1
- package/dist/core/tokens/transforms/index.js +4 -2
- package/dist/core/tokens/transforms/index.js.map +1 -1
- package/dist/core/tokens/transforms/size.d.ts +2 -1
- package/dist/core/tokens/transforms/size.d.ts.map +1 -1
- package/dist/core/tokens/transforms/size.js +2 -1
- package/dist/core/tokens/transforms/size.js.map +1 -1
- package/dist/core/tokens-tools.d.ts +14 -8
- package/dist/core/tokens-tools.d.ts.map +1 -1
- package/dist/core/tokens-tools.js +40 -21
- package/dist/core/tokens-tools.js.map +1 -1
- package/figma-desktop-bridge/code.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,21 +6,25 @@
|
|
|
6
6
|
[](https://docs.figma-console-mcp.southleft.com)
|
|
7
7
|
[](https://github.com/sponsors/southleft)
|
|
8
8
|
|
|
9
|
-
> **Your design system as an API.** Model Context Protocol server that bridges design and development—giving AI assistants complete access to Figma for **extraction**, **creation**, and **
|
|
9
|
+
> **Your design system as an API.** Model Context Protocol server that bridges design and development—giving AI assistants complete access to Figma for **extraction**, **creation**, **debugging**, and **bidirectional token sync**.
|
|
10
10
|
|
|
11
|
-
> **🆕
|
|
11
|
+
> **🆕 Token Sync — Full Formatter Coverage (v1.28.0):** `figma_export_tokens` now ships **10 fully-implemented output formats**: DTCG JSON (canonical), CSS custom properties, Tailwind v4 `@theme inline`, Tailwind v3 config, SCSS, TypeScript module, JSON (flat + nested), Style Dictionary v3, and Tokens Studio multi-file. Pull Figma variables and emit code in whatever styling flavor your project uses — no Style Dictionary or Tokens Studio install required. Diff-aware merge for round-trip; one Figma API call per changed value, not full rewrites. 103 tools total. [See what's new →](CHANGELOG.md#1280---2026-05-18)
|
|
12
12
|
|
|
13
13
|
## What is this?
|
|
14
14
|
|
|
15
15
|
Figma Console MCP connects AI assistants (like Claude) to Figma, enabling:
|
|
16
16
|
|
|
17
17
|
- **🎨 Design system extraction** - Pull variables, components, and styles
|
|
18
|
+
- **🔁 Bidirectional token sync** - Export Figma variables to DTCG JSON + CSS custom properties; push code-side edits back to Figma. Replaces Style Dictionary and Tokens Studio's export pipeline.
|
|
18
19
|
- **📸 Visual debugging** - Take screenshots for context
|
|
19
20
|
- **✏️ Design creation** - Create UI components, frames, and layouts directly in Figma
|
|
20
21
|
- **🔧 Variable management** - Create, update, rename, and delete design tokens
|
|
22
|
+
- **🕰 Version history & time-series awareness** - List versions, diff snapshots, generate markdown changelogs, trace property/variant introduction via binary-search blame
|
|
21
23
|
- **⚡ Real-time monitoring** - Watch console logs from the Desktop Bridge plugin
|
|
22
24
|
- **📌 FigJam boards** - Create stickies, flowcharts, tables, and code blocks on collaborative boards
|
|
25
|
+
- **🎞️ Slides presentations** - Build and manage Figma Slides decks programmatically
|
|
23
26
|
- **♿ Accessibility scanning** - 14 WCAG design checks with conformance level tagging, component scorecards, axe-core code scanning, design-to-code parity
|
|
27
|
+
- **🛡 Cross-MCP identity** - Every tool response carries `_mcp: "figma-console-mcp"` and errors are prefixed `[figma-console-mcp]` so attribution stays unambiguous in agents running multiple Figma MCPs
|
|
24
28
|
- **☁️ Cloud Write Relay** - Web AI clients (Claude.ai, v0, Replit) can design in Figma via cloud pairing
|
|
25
29
|
- **🔄 Four ways to connect** - Remote SSE, Cloud Mode, NPX, or Local Git
|
|
26
30
|
|
|
@@ -51,7 +55,7 @@ Figma Console MCP connects AI assistants (like Claude) to Figma, enabling:
|
|
|
51
55
|
| Real-time monitoring (console, selection) | ✅ | ❌ | ❌ |
|
|
52
56
|
| Desktop Bridge plugin | ✅ | ✅ | ❌ |
|
|
53
57
|
| Requires Node.js | Yes | **No** | No |
|
|
54
|
-
| **Total tools available** | **103** | **
|
|
58
|
+
| **Total tools available** | **103** | **95** | **9** |
|
|
55
59
|
|
|
56
60
|
> **Bottom line:** Remote SSE is **read-only** with ~38% of the tools. **Cloud Mode** unlocks write access from web AI clients without Node.js. NPX/Local Git gives the full 103 tools with real-time monitoring.
|
|
57
61
|
|
|
@@ -304,7 +308,7 @@ AI Client → Cloud MCP Server → Durable Object Relay → Desktop Bridge Plugi
|
|
|
304
308
|
| Feature | NPX (Recommended) | Cloud Mode | Local Git | Remote SSE |
|
|
305
309
|
|---------|-------------------|------------|-----------|------------|
|
|
306
310
|
| **Setup time** | ~10 minutes | ~5 minutes | ~15 minutes | ~2 minutes |
|
|
307
|
-
| **Total tools** | **103** | **
|
|
311
|
+
| **Total tools** | **103** | **95** | **103** | **9** (read-only) |
|
|
308
312
|
| **Design creation** | ✅ | ✅ | ✅ | ❌ |
|
|
309
313
|
| **Variable management** | ✅ | ✅ | ✅ | ❌ |
|
|
310
314
|
| **Component instantiation** | ✅ | ✅ | ✅ | ❌ |
|
|
@@ -798,27 +802,30 @@ The architecture supports adding new apps with minimal boilerplate — each app
|
|
|
798
802
|
|
|
799
803
|
## 🛤️ Roadmap
|
|
800
804
|
|
|
801
|
-
**Current Status:** v1.
|
|
805
|
+
**Current Status:** v1.28.0 (Stable) - Production-ready with 10-format token export pipeline (DTCG, CSS, Tailwind v4, Tailwind v3, SCSS, TS module, JSON flat/nested, Style Dictionary v3, Tokens Studio), bidirectional Figma↔code token sync, version history & time-series awareness, FigJam + Slides support, Cloud Write Relay, Design System Kit, WebSocket-only connectivity, smart multi-file tracking, **103 tools** (Local) / **95 tools** (Cloud) / **9 tools** (Remote read-only), Comments API, cross-MCP identity disambiguation, and MCP Apps.
|
|
802
806
|
|
|
803
807
|
**Recent Releases:**
|
|
804
|
-
- [x] **v1.
|
|
805
|
-
- [x] **v1.
|
|
806
|
-
- [x] **v1.
|
|
807
|
-
- [x] **v1.
|
|
808
|
-
- [x] **v1.
|
|
809
|
-
- [x] **v1.
|
|
810
|
-
- [x] **v1.
|
|
811
|
-
- [x] **v1.
|
|
812
|
-
- [x] **v1.
|
|
813
|
-
- [x] **v1.
|
|
814
|
-
- [x] **v1.
|
|
815
|
-
- [x] **v1.
|
|
808
|
+
- [x] **v1.28.0** - Full formatter coverage for `figma_export_tokens`. Seven new output formats: Tailwind v4 `@theme inline`, Tailwind v3 config, SCSS variables, TypeScript module, JSON flat/nested, Style Dictionary v3, Tokens Studio multi-file. Combined with DTCG + CSS variables, ships **10 fully-implemented output formats** with zero third-party build-tool dependencies. Tool description updated, docs/tools.md table all-green. 22 new Jest tests, 1151 total passing.
|
|
809
|
+
- [x] **v1.27.1** - Documentation patch. No code behavior changes. Sweeps stale "Phase 1 ships with DTCG only" claims across tool descriptions, error messages, and internal comments after CSS variables formatter and the apply phase shipped during the v1.27.0 dev cycle. Refreshes README banner + capability bullets + roadmap. Adds `Phase 3.5: Stale-Content Audit` to the release runbook so future releases get a strict pre-publish grep sweep across banners, tool descriptions, error messages, source comments, and tool-count consistency.
|
|
810
|
+
- [x] **v1.27.0** - Bidirectional token sync: `figma_export_tokens` + `figma_import_tokens` replace Style Dictionary and Tokens Studio's export pipeline. Canonical DTCG JSON + CSS custom properties. Diff-aware merge with round-trip ID preservation via `$extensions["figma-console-mcp"]`. Apply phase pushes hex-value edits back to Figma via the plugin bridge. Verified end-to-end against 713-token + 280-token design systems.
|
|
811
|
+
- [x] **v1.26.0** - Internal cleanup + cross-MCP identity: Local-mode CDP/Puppeteer transport removed entirely (WebSocket-only). `figma_diagnose` tool for designer-readable health checks. Every response tagged `_mcp: "figma-console-mcp"`; errors prefixed `[figma-console-mcp]` so attribution is unambiguous when running multiple Figma MCPs. Plugin status pill now reads `Local · ready` / `Cloud · ready` / `Local + Cloud · ready`. Net diff: −7,299 lines, plugin re-import optional.
|
|
812
|
+
- [x] **v1.25.0** - Description + Dev Mode annotation tracking in `figma_diff_versions` via plugin session buffer. Description and annotation edits made during a session now appear in diff output (REST API doesn't return these — bridged through the plugin's `documentchange` listener).
|
|
813
|
+
- [x] **v1.24.0** - Honest scope coverage on version diffs. `scope_coverage` object surfaces what `figma_diff_versions` does and doesn't track; always-on coverage warnings prevent silent invisibility on token-value changes and component-instance placements.
|
|
814
|
+
- [x] **v1.23.0** - Version History & Time-Series Awareness: 6 new tools (list versions, snapshot any past version, diff two versions for component/binding deltas, generate markdown changelogs, trace property/variant introduction via binary-search blame walker). Author attribution flows from autosaves, not just labeled releases.
|
|
815
|
+
- [x] **v1.17.0** - Figma Slides support: 15 tools for managing presentations.
|
|
816
|
+
- [x] **v1.16.0** - FigJam support: 9 tools for creating and reading FigJam boards.
|
|
817
|
+
- [x] **v1.12.0** - Cloud Write Relay: web AI clients can create and modify Figma designs without Node.js.
|
|
818
|
+
- [x] **v1.11.0** - Complete CDP removal, improved multi-file active tracking with focus detection.
|
|
819
|
+
- [x] **v1.10.0** - Multi-instance support (dynamic port fallback 9223–9232, multi-connection plugin, instance discovery).
|
|
820
|
+
- [x] **v1.9.0** - Figma Comments tools, improved port conflict detection.
|
|
821
|
+
- [x] **v1.8.0** - WebSocket Bridge transport (CDP-free connectivity), real-time selection/document tracking.
|
|
822
|
+
- [x] **v1.7.0** - MCP Apps (Token Browser, Design System Dashboard), batch variable operations, design-code parity tools.
|
|
816
823
|
|
|
817
824
|
**Coming Next:**
|
|
825
|
+
- [ ] **Token sync — parsers + import-side apply expansion** - Parsers for non-DTCG input (Tokens Studio, CSS vars, Tailwind v4, Tailwind v3 config, SCSS, Style Dictionary v3, JSON flat/nested). Plus `toCreate` apply orchestration, `toDelete` for `replace` strategy, alias-target updates, and cross-library variable resolution via `getVariableByIdAsync` so cross-library aliases render as real `var(--target)` references instead of comments.
|
|
818
826
|
- [ ] **Component template library** - Common UI pattern generation
|
|
819
827
|
- [ ] **Visual regression testing** - Screenshot diff capabilities
|
|
820
828
|
- [ ] **Design linting** - Automated compliance and accessibility checks
|
|
821
|
-
- [ ] **AI enhancements** - Intelligent component suggestions and auto-layout optimization
|
|
822
829
|
|
|
823
830
|
**📖 [Full Roadmap](docs/ROADMAP.md)**
|
|
824
831
|
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
* 3. Composite tokens (typography, shadow, gradient) emit DTCG's
|
|
19
19
|
* structured $value form. Aliases emit `"$value": "{path.to.target}"`.
|
|
20
20
|
*
|
|
21
|
-
* This formatter is the canonical
|
|
22
|
-
* formatter (
|
|
21
|
+
* This formatter is the canonical output — the format every other
|
|
22
|
+
* formatter (CSS variables today, Tailwind/SCSS/etc. in future minor
|
|
23
|
+
* versions) ultimately derives from.
|
|
23
24
|
*/
|
|
24
25
|
import type { TokenDocument } from "../types.js";
|
|
25
26
|
import type { FormatOptions, FormatResult } from "./index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dtcg.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/dtcg.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dtcg.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/dtcg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAEV,aAAa,EAGd,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAoB9D,wBAAgB,UAAU,CACxB,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,aAAa,GAClB,YAAY,CA+Dd"}
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
* 3. Composite tokens (typography, shadow, gradient) emit DTCG's
|
|
19
19
|
* structured $value form. Aliases emit `"$value": "{path.to.target}"`.
|
|
20
20
|
*
|
|
21
|
-
* This formatter is the canonical
|
|
22
|
-
* formatter (
|
|
21
|
+
* This formatter is the canonical output — the format every other
|
|
22
|
+
* formatter (CSS variables today, Tailwind/SCSS/etc. in future minor
|
|
23
|
+
* versions) ultimately derives from.
|
|
23
24
|
*/
|
|
24
25
|
import { FIGMA_MCP_EXTENSION_KEY } from "../types.js";
|
|
25
26
|
import { formatDtcgReference } from "../alias-resolver.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dtcg.js","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/dtcg.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dtcg.js","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/dtcg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAqB3D,MAAM,UAAU,UAAU,CACxB,GAAkB,EAClB,IAAmB;IAEnB,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,KAAK,GAA0B,EAAE,CAAC;IAExC,sEAAsE;IACtE,2BAA2B;IAC3B,uEAAuE;IACvE,wDAAwD;IACxD,mEAAmE;IACnE,0CAA0C;IAE1C,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC;IACrD,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,IAAI,KAAK,CAAC;IAEjE,IAAI,WAAW,IAAI,iBAAiB,EAAE,CAAC;QACrC,KAAK,MAAM,GAAG,I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These are dumps without the DTCG `$type`/`$value` envelope, for custom
|
|
5
|
+
* build scripts that just need a key-value map of resolved tokens.
|
|
6
|
+
*
|
|
7
|
+
* Flat shape:
|
|
8
|
+
*
|
|
9
|
+
* {
|
|
10
|
+
* "ds-color-primary": "#4085F2",
|
|
11
|
+
* "ds-spacing-md": "16px",
|
|
12
|
+
* "ds-color-bg--dark": "#0A0A0A"
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* Multi-mode tokens flatten with `--<mode>` suffix (primary mode keeps
|
|
16
|
+
* the bare name; other modes get suffixed).
|
|
17
|
+
*
|
|
18
|
+
* Nested shape:
|
|
19
|
+
*
|
|
20
|
+
* {
|
|
21
|
+
* "color": {
|
|
22
|
+
* "primary": "#4085F2",
|
|
23
|
+
* "brand": { "primary": "#FF00AA" }
|
|
24
|
+
* },
|
|
25
|
+
* "spacing": { "md": "16px" }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* Multi-mode tokens become objects: `{ Light: "...", Dark: "..." }`.
|
|
29
|
+
*
|
|
30
|
+
* Aliases resolve to the literal value where possible; cross-library
|
|
31
|
+
* aliases get a `null` (caller can decide how to fill those in).
|
|
32
|
+
*/
|
|
1
33
|
import type { TokenDocument } from "../types.js";
|
|
2
34
|
import type { FormatOptions, FormatResult } from "./index.js";
|
|
3
|
-
export declare function formatJsonFlat(
|
|
4
|
-
export declare function formatJsonNested(
|
|
35
|
+
export declare function formatJsonFlat(doc: TokenDocument, opts: FormatOptions): FormatResult;
|
|
36
|
+
export declare function formatJsonNested(doc: TokenDocument, opts: FormatOptions): FormatResult;
|
|
5
37
|
//# sourceMappingURL=json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAS,aAAa,EAAwB,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,cAAc,CAC5B,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,aAAa,GAClB,YAAY,CAsBd;AAED,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,aAAa,GAClB,YAAY,CAqBd"}
|
|
@@ -1,8 +1,179 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Plain JSON formatters — flat and nested.
|
|
3
|
+
*
|
|
4
|
+
* These are dumps without the DTCG `$type`/`$value` envelope, for custom
|
|
5
|
+
* build scripts that just need a key-value map of resolved tokens.
|
|
6
|
+
*
|
|
7
|
+
* Flat shape:
|
|
8
|
+
*
|
|
9
|
+
* {
|
|
10
|
+
* "ds-color-primary": "#4085F2",
|
|
11
|
+
* "ds-spacing-md": "16px",
|
|
12
|
+
* "ds-color-bg--dark": "#0A0A0A"
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* Multi-mode tokens flatten with `--<mode>` suffix (primary mode keeps
|
|
16
|
+
* the bare name; other modes get suffixed).
|
|
17
|
+
*
|
|
18
|
+
* Nested shape:
|
|
19
|
+
*
|
|
20
|
+
* {
|
|
21
|
+
* "color": {
|
|
22
|
+
* "primary": "#4085F2",
|
|
23
|
+
* "brand": { "primary": "#FF00AA" }
|
|
24
|
+
* },
|
|
25
|
+
* "spacing": { "md": "16px" }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* Multi-mode tokens become objects: `{ Light: "...", Dark: "..." }`.
|
|
29
|
+
*
|
|
30
|
+
* Aliases resolve to the literal value where possible; cross-library
|
|
31
|
+
* aliases get a `null` (caller can decide how to fill those in).
|
|
32
|
+
*/
|
|
33
|
+
export function formatJsonFlat(doc, opts) {
|
|
34
|
+
const warnings = [];
|
|
35
|
+
const files = [];
|
|
36
|
+
const splitByCollection = opts.target.splitByCollection ?? false;
|
|
37
|
+
const prefix = opts.target.prefix ?? "";
|
|
38
|
+
if (splitByCollection) {
|
|
39
|
+
for (const set of doc.sets) {
|
|
40
|
+
files.push({
|
|
41
|
+
path: filenameFor(opts, set, "flat"),
|
|
42
|
+
content: renderFlat([set], prefix, warnings),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
files.push({
|
|
48
|
+
path: filenameFor(opts, undefined, "flat"),
|
|
49
|
+
content: renderFlat(doc.sets, prefix, warnings),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { files, warnings };
|
|
4
53
|
}
|
|
5
|
-
export function formatJsonNested(
|
|
6
|
-
|
|
54
|
+
export function formatJsonNested(doc, opts) {
|
|
55
|
+
const warnings = [];
|
|
56
|
+
const files = [];
|
|
57
|
+
const splitByCollection = opts.target.splitByCollection ?? false;
|
|
58
|
+
if (splitByCollection) {
|
|
59
|
+
for (const set of doc.sets) {
|
|
60
|
+
files.push({
|
|
61
|
+
path: filenameFor(opts, set, "nested"),
|
|
62
|
+
content: renderNested([set], warnings),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
files.push({
|
|
68
|
+
path: filenameFor(opts, undefined, "nested"),
|
|
69
|
+
content: renderNested(doc.sets, warnings),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return { files, warnings };
|
|
73
|
+
}
|
|
74
|
+
function filenameFor(opts, set, shape) {
|
|
75
|
+
if (opts.target.filename)
|
|
76
|
+
return opts.target.filename;
|
|
77
|
+
const parts = [];
|
|
78
|
+
if (set)
|
|
79
|
+
parts.push(slugify(set.name));
|
|
80
|
+
parts.push(`tokens.${shape}`);
|
|
81
|
+
return `${parts.join(".")}.json`;
|
|
82
|
+
}
|
|
83
|
+
function slugify(s) {
|
|
84
|
+
return s
|
|
85
|
+
.trim()
|
|
86
|
+
.toLowerCase()
|
|
87
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
88
|
+
.replace(/^-+|-+$/g, "");
|
|
89
|
+
}
|
|
90
|
+
function renderFlat(sets, prefix, warnings) {
|
|
91
|
+
const out = {};
|
|
92
|
+
for (const set of sets) {
|
|
93
|
+
const primaryMode = pickPrimaryMode(set.modes);
|
|
94
|
+
for (const token of set.tokens) {
|
|
95
|
+
const baseName = `${prefix}${token.path.map(slugify).join("-")}`;
|
|
96
|
+
for (const [modeName, value] of Object.entries(token.values)) {
|
|
97
|
+
const key = modeName === primaryMode
|
|
98
|
+
? baseName
|
|
99
|
+
: `${baseName}--${slugify(modeName)}`;
|
|
100
|
+
const resolved = resolveValue(value, token, warnings);
|
|
101
|
+
if (resolved !== undefined)
|
|
102
|
+
out[key] = resolved;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Sort keys for deterministic output.
|
|
107
|
+
const sorted = Object.fromEntries(Object.entries(out).sort(([a], [b]) => a.localeCompare(b)));
|
|
108
|
+
return JSON.stringify(sorted, null, 2) + "\n";
|
|
109
|
+
}
|
|
110
|
+
function renderNested(sets, warnings) {
|
|
111
|
+
const out = {};
|
|
112
|
+
for (const set of sets) {
|
|
113
|
+
const isMultiMode = set.modes.length > 1;
|
|
114
|
+
for (const token of set.tokens) {
|
|
115
|
+
let cursor = out;
|
|
116
|
+
for (let i = 0; i < token.path.length - 1; i++) {
|
|
117
|
+
const segment = token.path[i];
|
|
118
|
+
if (!cursor[segment] ||
|
|
119
|
+
typeof cursor[segment] !== "object" ||
|
|
120
|
+
Array.isArray(cursor[segment])) {
|
|
121
|
+
cursor[segment] = {};
|
|
122
|
+
}
|
|
123
|
+
cursor = cursor[segment];
|
|
124
|
+
}
|
|
125
|
+
const leafKey = token.path[token.path.length - 1];
|
|
126
|
+
if (isMultiMode) {
|
|
127
|
+
const modeValues = {};
|
|
128
|
+
for (const [modeName, value] of Object.entries(token.values)) {
|
|
129
|
+
const resolved = resolveValue(value, token, warnings);
|
|
130
|
+
if (resolved !== undefined)
|
|
131
|
+
modeValues[modeName] = resolved;
|
|
132
|
+
}
|
|
133
|
+
cursor[leafKey] = modeValues;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const onlyValue = Object.values(token.values)[0];
|
|
137
|
+
if (onlyValue) {
|
|
138
|
+
const resolved = resolveValue(onlyValue, token, warnings);
|
|
139
|
+
if (resolved !== undefined)
|
|
140
|
+
cursor[leafKey] = resolved;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return JSON.stringify(sortKeys(out), null, 2) + "\n";
|
|
146
|
+
}
|
|
147
|
+
function pickPrimaryMode(modes) {
|
|
148
|
+
return modes.find((m) => /^(default|light|value)$/i.test(m)) ?? modes[0];
|
|
149
|
+
}
|
|
150
|
+
function resolveValue(value, token, warnings) {
|
|
151
|
+
if (value.reference) {
|
|
152
|
+
const bare = value.reference.replace(/^\{|\}$/g, "");
|
|
153
|
+
if (bare.startsWith("__library:") || bare === "unknown") {
|
|
154
|
+
warnings.push(`Skipped ${token.path.join(".")} in JSON — cross-library alias unresolved.`);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
// Local alias: emit as the reference path. Caller can resolve.
|
|
158
|
+
return `{${bare}}`;
|
|
159
|
+
}
|
|
160
|
+
if (value.literal === undefined || value.literal === null)
|
|
161
|
+
return undefined;
|
|
162
|
+
if (typeof value.literal === "number") {
|
|
163
|
+
if (token.type === "dimension")
|
|
164
|
+
return `${value.literal}px`;
|
|
165
|
+
return value.literal;
|
|
166
|
+
}
|
|
167
|
+
return value.literal;
|
|
168
|
+
}
|
|
169
|
+
function sortKeys(obj) {
|
|
170
|
+
if (obj === null || typeof obj !== "object" || Array.isArray(obj))
|
|
171
|
+
return obj;
|
|
172
|
+
const sorted = {};
|
|
173
|
+
const keys = Object.keys(obj).sort();
|
|
174
|
+
for (const k of keys) {
|
|
175
|
+
sorted[k] = sortKeys(obj[k]);
|
|
176
|
+
}
|
|
177
|
+
return sorted;
|
|
7
178
|
}
|
|
8
179
|
//# sourceMappingURL=json.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/json.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAKH,MAAM,UAAU,cAAc,CAC5B,GAAkB,EAClB,IAAmB;IAEnB,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,KAAK,GAA0B,EAAE,CAAC;IAExC,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,IAAI,KAAK,CAAC;IACjE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;IAExC,IAAI,iBAAiB,EAAE,CAAC;QACtB,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC;gBACpC,OAAO,EAAE,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC;aAC7C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC;YAC1C,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC;SAChD,C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10
|
+
* // map for runtime mode access
|
|
11
|
+
* $ds-colors: (
|
|
12
|
+
* "primary": $ds-color-primary,
|
|
13
|
+
* ...
|
|
14
|
+
* );
|
|
15
|
+
*
|
|
16
|
+
* Modes: SCSS doesn't have CSS's runtime cascading, so multi-mode output
|
|
17
|
+
* either emits one file per mode (splitByMode: true) or generates SCSS
|
|
18
|
+
* maps keyed by mode name that consumers can `map-get` from.
|
|
19
|
+
*
|
|
20
|
+
* Composite tokens (typography, shadow) expand into multiple primitive
|
|
21
|
+
* variables since SCSS variables hold a single value.
|
|
22
|
+
*/
|
|
1
23
|
import type { TokenDocument } from "../types.js";
|
|
2
24
|
import type { FormatOptions, FormatResult } from "./index.js";
|
|
3
|
-
export declare function formatScss(
|
|
25
|
+
export declare function formatScss(doc: TokenDocument, opts: FormatOptions): FormatResult;
|
|
4
26
|
//# sourceMappingURL=scss.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scss.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/scss.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"scss.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/scss.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAS,aAAa,EAAwB,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,UAAU,CACxB,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,aAAa,GAClB,YAAY,CA0Cd"}
|