@obra-studio/figma-console-mcp 1.32.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/LICENSE +21 -0
- package/README.md +879 -0
- package/dist/apps/design-system-dashboard/scoring/accessibility.d.ts +14 -0
- package/dist/apps/design-system-dashboard/scoring/accessibility.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/accessibility.js +278 -0
- package/dist/apps/design-system-dashboard/scoring/accessibility.js.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/component-metadata.d.ts +29 -0
- package/dist/apps/design-system-dashboard/scoring/component-metadata.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/component-metadata.js +358 -0
- package/dist/apps/design-system-dashboard/scoring/component-metadata.js.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/consistency.d.ts +14 -0
- package/dist/apps/design-system-dashboard/scoring/consistency.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/consistency.js +342 -0
- package/dist/apps/design-system-dashboard/scoring/consistency.js.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/coverage.d.ts +14 -0
- package/dist/apps/design-system-dashboard/scoring/coverage.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/coverage.js +231 -0
- package/dist/apps/design-system-dashboard/scoring/coverage.js.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/engine.d.ts +27 -0
- package/dist/apps/design-system-dashboard/scoring/engine.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/engine.js +93 -0
- package/dist/apps/design-system-dashboard/scoring/engine.js.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/naming-semantics.d.ts +14 -0
- package/dist/apps/design-system-dashboard/scoring/naming-semantics.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/naming-semantics.js +309 -0
- package/dist/apps/design-system-dashboard/scoring/naming-semantics.js.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/token-architecture.d.ts +14 -0
- package/dist/apps/design-system-dashboard/scoring/token-architecture.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/token-architecture.js +350 -0
- package/dist/apps/design-system-dashboard/scoring/token-architecture.js.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/types.d.ts +89 -0
- package/dist/apps/design-system-dashboard/scoring/types.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/scoring/types.js +41 -0
- package/dist/apps/design-system-dashboard/scoring/types.js.map +1 -0
- package/dist/apps/design-system-dashboard/server.d.ts +24 -0
- package/dist/apps/design-system-dashboard/server.d.ts.map +1 -0
- package/dist/apps/design-system-dashboard/server.js +160 -0
- package/dist/apps/design-system-dashboard/server.js.map +1 -0
- package/dist/apps/token-browser/server.d.ts +26 -0
- package/dist/apps/token-browser/server.d.ts.map +1 -0
- package/dist/apps/token-browser/server.js +137 -0
- package/dist/apps/token-browser/server.js.map +1 -0
- package/dist/browser/base.d.ts +58 -0
- package/dist/browser/base.d.ts.map +1 -0
- package/dist/browser/base.js +6 -0
- package/dist/browser/base.js.map +1 -0
- package/dist/browser/local.d.ts +87 -0
- package/dist/browser/local.d.ts.map +1 -0
- package/dist/browser/local.js +318 -0
- package/dist/browser/local.js.map +1 -0
- package/dist/core/accessibility-tools.d.ts +21 -0
- package/dist/core/accessibility-tools.d.ts.map +1 -0
- package/dist/core/accessibility-tools.js +307 -0
- package/dist/core/accessibility-tools.js.map +1 -0
- package/dist/core/annotation-tools.d.ts +14 -0
- package/dist/core/annotation-tools.d.ts.map +1 -0
- package/dist/core/annotation-tools.js +231 -0
- package/dist/core/annotation-tools.js.map +1 -0
- package/dist/core/autodocs-tools.d.ts +7 -0
- package/dist/core/autodocs-tools.d.ts.map +1 -0
- package/dist/core/autodocs-tools.js +195 -0
- package/dist/core/autodocs-tools.js.map +1 -0
- package/dist/core/comment-tools.d.ts +11 -0
- package/dist/core/comment-tools.d.ts.map +1 -0
- package/dist/core/comment-tools.js +293 -0
- package/dist/core/comment-tools.js.map +1 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +154 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/console-monitor.d.ts +82 -0
- package/dist/core/console-monitor.d.ts.map +1 -0
- package/dist/core/console-monitor.js +428 -0
- package/dist/core/console-monitor.js.map +1 -0
- package/dist/core/deep-component-tools.d.ts +14 -0
- package/dist/core/deep-component-tools.d.ts.map +1 -0
- package/dist/core/deep-component-tools.js +129 -0
- package/dist/core/deep-component-tools.js.map +1 -0
- package/dist/core/design-code-tools.d.ts +116 -0
- package/dist/core/design-code-tools.d.ts.map +1 -0
- package/dist/core/design-code-tools.js +2751 -0
- package/dist/core/design-code-tools.js.map +1 -0
- package/dist/core/design-system-manifest.d.ts +272 -0
- package/dist/core/design-system-manifest.d.ts.map +1 -0
- package/dist/core/design-system-manifest.js +261 -0
- package/dist/core/design-system-manifest.js.map +1 -0
- package/dist/core/design-system-tools.d.ts +67 -0
- package/dist/core/design-system-tools.d.ts.map +1 -0
- package/dist/core/design-system-tools.js +874 -0
- package/dist/core/design-system-tools.js.map +1 -0
- package/dist/core/diagnose-tool.d.ts +33 -0
- package/dist/core/diagnose-tool.d.ts.map +1 -0
- package/dist/core/diagnose-tool.js +97 -0
- package/dist/core/diagnose-tool.js.map +1 -0
- package/dist/core/diff/changelog-formatter.d.ts +35 -0
- package/dist/core/diff/changelog-formatter.d.ts.map +1 -0
- package/dist/core/diff/changelog-formatter.js +276 -0
- package/dist/core/diff/changelog-formatter.js.map +1 -0
- package/dist/core/diff/diff-engine.d.ts +127 -0
- package/dist/core/diff/diff-engine.d.ts.map +1 -0
- package/dist/core/diff/diff-engine.js +335 -0
- package/dist/core/diff/diff-engine.js.map +1 -0
- package/dist/core/diff/property-compare.d.ts +19 -0
- package/dist/core/diff/property-compare.d.ts.map +1 -0
- package/dist/core/diff/property-compare.js +37 -0
- package/dist/core/diff/property-compare.js.map +1 -0
- package/dist/core/diff/version-cache.d.ts +40 -0
- package/dist/core/diff/version-cache.d.ts.map +1 -0
- package/dist/core/diff/version-cache.js +75 -0
- package/dist/core/diff/version-cache.js.map +1 -0
- package/dist/core/enrichment/enrichment-service.d.ts +52 -0
- package/dist/core/enrichment/enrichment-service.d.ts.map +1 -0
- package/dist/core/enrichment/enrichment-service.js +369 -0
- package/dist/core/enrichment/enrichment-service.js.map +1 -0
- package/dist/core/enrichment/index.d.ts +8 -0
- package/dist/core/enrichment/index.d.ts.map +1 -0
- package/dist/core/enrichment/index.js +8 -0
- package/dist/core/enrichment/index.js.map +1 -0
- package/dist/core/enrichment/relationship-mapper.d.ts +106 -0
- package/dist/core/enrichment/relationship-mapper.d.ts.map +1 -0
- package/dist/core/enrichment/relationship-mapper.js +352 -0
- package/dist/core/enrichment/relationship-mapper.js.map +1 -0
- package/dist/core/enrichment/style-resolver.d.ts +80 -0
- package/dist/core/enrichment/style-resolver.d.ts.map +1 -0
- package/dist/core/enrichment/style-resolver.js +327 -0
- package/dist/core/enrichment/style-resolver.js.map +1 -0
- package/dist/core/figjam-tools.d.ts +8 -0
- package/dist/core/figjam-tools.d.ts.map +1 -0
- package/dist/core/figjam-tools.js +548 -0
- package/dist/core/figjam-tools.js.map +1 -0
- package/dist/core/figma-api.d.ts +245 -0
- package/dist/core/figma-api.d.ts.map +1 -0
- package/dist/core/figma-api.js +446 -0
- package/dist/core/figma-api.js.map +1 -0
- package/dist/core/figma-connector.d.ts +180 -0
- package/dist/core/figma-connector.d.ts.map +1 -0
- package/dist/core/figma-connector.js +8 -0
- package/dist/core/figma-connector.js.map +1 -0
- package/dist/core/figma-desktop-connector.d.ts +312 -0
- package/dist/core/figma-desktop-connector.d.ts.map +1 -0
- package/dist/core/figma-desktop-connector.js +1298 -0
- package/dist/core/figma-desktop-connector.js.map +1 -0
- package/dist/core/figma-reconstruction-spec.d.ts +166 -0
- package/dist/core/figma-reconstruction-spec.d.ts.map +1 -0
- package/dist/core/figma-reconstruction-spec.js +403 -0
- package/dist/core/figma-reconstruction-spec.js.map +1 -0
- package/dist/core/figma-style-extractor.d.ts +76 -0
- package/dist/core/figma-style-extractor.d.ts.map +1 -0
- package/dist/core/figma-style-extractor.js +312 -0
- package/dist/core/figma-style-extractor.js.map +1 -0
- package/dist/core/figma-tools.d.ts +22 -0
- package/dist/core/figma-tools.d.ts.map +1 -0
- package/dist/core/figma-tools.js +3187 -0
- package/dist/core/figma-tools.js.map +1 -0
- package/dist/core/identity.d.ts +41 -0
- package/dist/core/identity.d.ts.map +1 -0
- package/dist/core/identity.js +97 -0
- package/dist/core/identity.js.map +1 -0
- package/dist/core/library-tools.d.ts +17 -0
- package/dist/core/library-tools.d.ts.map +1 -0
- package/dist/core/library-tools.js +581 -0
- package/dist/core/library-tools.js.map +1 -0
- package/dist/core/logger.d.ts +22 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +54 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/port-discovery.d.ts +171 -0
- package/dist/core/port-discovery.d.ts.map +1 -0
- package/dist/core/port-discovery.js +563 -0
- package/dist/core/port-discovery.js.map +1 -0
- package/dist/core/resolve-package-root.d.ts +2 -0
- package/dist/core/resolve-package-root.d.ts.map +1 -0
- package/dist/core/resolve-package-root.js +12 -0
- package/dist/core/resolve-package-root.js.map +1 -0
- package/dist/core/slides-tools.d.ts +8 -0
- package/dist/core/slides-tools.d.ts.map +1 -0
- package/dist/core/slides-tools.js +715 -0
- package/dist/core/slides-tools.js.map +1 -0
- package/dist/core/snippet-injector.d.ts +24 -0
- package/dist/core/snippet-injector.d.ts.map +1 -0
- package/dist/core/snippet-injector.js +97 -0
- package/dist/core/snippet-injector.js.map +1 -0
- package/dist/core/tokens/alias-resolver.d.ts +55 -0
- package/dist/core/tokens/alias-resolver.d.ts.map +1 -0
- package/dist/core/tokens/alias-resolver.js +136 -0
- package/dist/core/tokens/alias-resolver.js.map +1 -0
- package/dist/core/tokens/config.d.ts +87 -0
- package/dist/core/tokens/config.d.ts.map +1 -0
- package/dist/core/tokens/config.js +285 -0
- package/dist/core/tokens/config.js.map +1 -0
- package/dist/core/tokens/figma-converter.d.ts +81 -0
- package/dist/core/tokens/figma-converter.d.ts.map +1 -0
- package/dist/core/tokens/figma-converter.js +196 -0
- package/dist/core/tokens/figma-converter.js.map +1 -0
- package/dist/core/tokens/formatters/css-vars.d.ts +24 -0
- package/dist/core/tokens/formatters/css-vars.d.ts.map +1 -0
- package/dist/core/tokens/formatters/css-vars.js +330 -0
- package/dist/core/tokens/formatters/css-vars.js.map +1 -0
- package/dist/core/tokens/formatters/dtcg.d.ts +28 -0
- package/dist/core/tokens/formatters/dtcg.d.ts.map +1 -0
- package/dist/core/tokens/formatters/dtcg.js +301 -0
- package/dist/core/tokens/formatters/dtcg.js.map +1 -0
- package/dist/core/tokens/formatters/index.d.ts +30 -0
- package/dist/core/tokens/formatters/index.d.ts.map +1 -0
- package/dist/core/tokens/formatters/index.js +46 -0
- package/dist/core/tokens/formatters/index.js.map +1 -0
- package/dist/core/tokens/formatters/json.d.ts +37 -0
- package/dist/core/tokens/formatters/json.d.ts.map +1 -0
- package/dist/core/tokens/formatters/json.js +188 -0
- package/dist/core/tokens/formatters/json.js.map +1 -0
- package/dist/core/tokens/formatters/less.d.ts +4 -0
- package/dist/core/tokens/formatters/less.d.ts.map +1 -0
- package/dist/core/tokens/formatters/less.js +5 -0
- package/dist/core/tokens/formatters/less.js.map +1 -0
- package/dist/core/tokens/formatters/scss.d.ts +26 -0
- package/dist/core/tokens/formatters/scss.d.ts.map +1 -0
- package/dist/core/tokens/formatters/scss.js +253 -0
- package/dist/core/tokens/formatters/scss.js.map +1 -0
- package/dist/core/tokens/formatters/stubs.d.ts +9 -0
- package/dist/core/tokens/formatters/stubs.d.ts.map +1 -0
- package/dist/core/tokens/formatters/stubs.js +14 -0
- package/dist/core/tokens/formatters/stubs.js.map +1 -0
- package/dist/core/tokens/formatters/style-dictionary-v3.d.ts +45 -0
- package/dist/core/tokens/formatters/style-dictionary-v3.d.ts.map +1 -0
- package/dist/core/tokens/formatters/style-dictionary-v3.js +208 -0
- package/dist/core/tokens/formatters/style-dictionary-v3.js.map +1 -0
- package/dist/core/tokens/formatters/tailwind-v3.d.ts +37 -0
- package/dist/core/tokens/formatters/tailwind-v3.d.ts.map +1 -0
- package/dist/core/tokens/formatters/tailwind-v3.js +238 -0
- package/dist/core/tokens/formatters/tailwind-v3.js.map +1 -0
- package/dist/core/tokens/formatters/tailwind-v4.d.ts +41 -0
- package/dist/core/tokens/formatters/tailwind-v4.d.ts.map +1 -0
- package/dist/core/tokens/formatters/tailwind-v4.js +331 -0
- package/dist/core/tokens/formatters/tailwind-v4.js.map +1 -0
- package/dist/core/tokens/formatters/tokens-studio.d.ts +44 -0
- package/dist/core/tokens/formatters/tokens-studio.d.ts.map +1 -0
- package/dist/core/tokens/formatters/tokens-studio.js +251 -0
- package/dist/core/tokens/formatters/tokens-studio.js.map +1 -0
- package/dist/core/tokens/formatters/ts-module.d.ts +35 -0
- package/dist/core/tokens/formatters/ts-module.d.ts.map +1 -0
- package/dist/core/tokens/formatters/ts-module.js +199 -0
- package/dist/core/tokens/formatters/ts-module.js.map +1 -0
- package/dist/core/tokens/index.d.ts +17 -0
- package/dist/core/tokens/index.d.ts.map +1 -0
- package/dist/core/tokens/index.js +16 -0
- package/dist/core/tokens/index.js.map +1 -0
- package/dist/core/tokens/parsers/css-vars.d.ts +3 -0
- package/dist/core/tokens/parsers/css-vars.d.ts.map +1 -0
- package/dist/core/tokens/parsers/css-vars.js +5 -0
- package/dist/core/tokens/parsers/css-vars.js.map +1 -0
- package/dist/core/tokens/parsers/dtcg.d.ts +21 -0
- package/dist/core/tokens/parsers/dtcg.d.ts.map +1 -0
- package/dist/core/tokens/parsers/dtcg.js +254 -0
- package/dist/core/tokens/parsers/dtcg.js.map +1 -0
- package/dist/core/tokens/parsers/index.d.ts +37 -0
- package/dist/core/tokens/parsers/index.d.ts.map +1 -0
- package/dist/core/tokens/parsers/index.js +139 -0
- package/dist/core/tokens/parsers/index.js.map +1 -0
- package/dist/core/tokens/parsers/json.d.ts +4 -0
- package/dist/core/tokens/parsers/json.d.ts.map +1 -0
- package/dist/core/tokens/parsers/json.js +8 -0
- package/dist/core/tokens/parsers/json.js.map +1 -0
- package/dist/core/tokens/parsers/scss.d.ts +3 -0
- package/dist/core/tokens/parsers/scss.d.ts.map +1 -0
- package/dist/core/tokens/parsers/scss.js +5 -0
- package/dist/core/tokens/parsers/scss.js.map +1 -0
- package/dist/core/tokens/parsers/stubs.d.ts +15 -0
- package/dist/core/tokens/parsers/stubs.d.ts.map +1 -0
- package/dist/core/tokens/parsers/stubs.js +21 -0
- package/dist/core/tokens/parsers/stubs.js.map +1 -0
- package/dist/core/tokens/parsers/style-dictionary-v3.d.ts +3 -0
- package/dist/core/tokens/parsers/style-dictionary-v3.d.ts.map +1 -0
- package/dist/core/tokens/parsers/style-dictionary-v3.js +5 -0
- package/dist/core/tokens/parsers/style-dictionary-v3.js.map +1 -0
- package/dist/core/tokens/parsers/tailwind-v3.d.ts +3 -0
- package/dist/core/tokens/parsers/tailwind-v3.d.ts.map +1 -0
- package/dist/core/tokens/parsers/tailwind-v3.js +5 -0
- package/dist/core/tokens/parsers/tailwind-v3.js.map +1 -0
- package/dist/core/tokens/parsers/tailwind-v4.d.ts +3 -0
- package/dist/core/tokens/parsers/tailwind-v4.d.ts.map +1 -0
- package/dist/core/tokens/parsers/tailwind-v4.js +5 -0
- package/dist/core/tokens/parsers/tailwind-v4.js.map +1 -0
- package/dist/core/tokens/parsers/tokens-studio.d.ts +3 -0
- package/dist/core/tokens/parsers/tokens-studio.d.ts.map +1 -0
- package/dist/core/tokens/parsers/tokens-studio.js +5 -0
- package/dist/core/tokens/parsers/tokens-studio.js.map +1 -0
- package/dist/core/tokens/schemas.d.ts +31 -0
- package/dist/core/tokens/schemas.d.ts.map +1 -0
- package/dist/core/tokens/schemas.js +149 -0
- package/dist/core/tokens/schemas.js.map +1 -0
- package/dist/core/tokens/transforms/color.d.ts +9 -0
- package/dist/core/tokens/transforms/color.d.ts.map +1 -0
- package/dist/core/tokens/transforms/color.js +13 -0
- package/dist/core/tokens/transforms/color.js.map +1 -0
- package/dist/core/tokens/transforms/index.d.ts +36 -0
- package/dist/core/tokens/transforms/index.d.ts.map +1 -0
- package/dist/core/tokens/transforms/index.js +30 -0
- package/dist/core/tokens/transforms/index.js.map +1 -0
- package/dist/core/tokens/transforms/size.d.ts +7 -0
- package/dist/core/tokens/transforms/size.d.ts.map +1 -0
- package/dist/core/tokens/transforms/size.js +8 -0
- package/dist/core/tokens/transforms/size.js.map +1 -0
- package/dist/core/tokens/types.d.ts +228 -0
- package/dist/core/tokens/types.d.ts.map +1 -0
- package/dist/core/tokens/types.js +19 -0
- package/dist/core/tokens/types.js.map +1 -0
- package/dist/core/tokens-tools.d.ts +42 -0
- package/dist/core/tokens-tools.d.ts.map +1 -0
- package/dist/core/tokens-tools.js +860 -0
- package/dist/core/tokens-tools.js.map +1 -0
- package/dist/core/types/design-code.d.ts +271 -0
- package/dist/core/types/design-code.d.ts.map +1 -0
- package/dist/core/types/design-code.js +5 -0
- package/dist/core/types/design-code.js.map +1 -0
- package/dist/core/types/enriched.d.ts +213 -0
- package/dist/core/types/enriched.d.ts.map +1 -0
- package/dist/core/types/enriched.js +6 -0
- package/dist/core/types/enriched.js.map +1 -0
- package/dist/core/types/index.d.ts +104 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/index.js +5 -0
- package/dist/core/types/index.js.map +1 -0
- package/dist/core/variable-resolver.d.ts +45 -0
- package/dist/core/variable-resolver.d.ts.map +1 -0
- package/dist/core/variable-resolver.js +86 -0
- package/dist/core/variable-resolver.js.map +1 -0
- package/dist/core/version-tools.d.ts +59 -0
- package/dist/core/version-tools.d.ts.map +1 -0
- package/dist/core/version-tools.js +1159 -0
- package/dist/core/version-tools.js.map +1 -0
- package/dist/core/websocket-connector.d.ts +187 -0
- package/dist/core/websocket-connector.d.ts.map +1 -0
- package/dist/core/websocket-connector.js +378 -0
- package/dist/core/websocket-connector.js.map +1 -0
- package/dist/core/websocket-server.js +866 -0
- package/dist/core/websocket-server.js.map +1 -0
- package/dist/core/write-tools.d.ts +7 -0
- package/dist/core/write-tools.d.ts.map +1 -0
- package/dist/core/write-tools.js +2172 -0
- package/dist/core/write-tools.js.map +1 -0
- package/dist/local.d.ts +95 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +3036 -0
- package/dist/local.js.map +1 -0
- package/dist/vendor/obra-autodocs/autodocs-body.generated.d.ts +2 -0
- package/dist/vendor/obra-autodocs/autodocs-body.generated.d.ts.map +1 -0
- package/dist/vendor/obra-autodocs/autodocs-body.generated.js +6 -0
- package/dist/vendor/obra-autodocs/autodocs-body.generated.js.map +1 -0
- package/figma-desktop-bridge/README.md +365 -0
- package/figma-desktop-bridge/code.js +6504 -0
- package/figma-desktop-bridge/icon.png +0 -0
- package/figma-desktop-bridge/manifest.json +67 -0
- package/figma-desktop-bridge/ui.html +2441 -0
- package/package.json +98 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript module formatter.
|
|
3
|
+
*
|
|
4
|
+
* Output shape:
|
|
5
|
+
*
|
|
6
|
+
* // tokens.ts
|
|
7
|
+
* export const tokens = {
|
|
8
|
+
* color: {
|
|
9
|
+
* primary: "#4085F2",
|
|
10
|
+
* brand: { primary: "#FF00AA" }
|
|
11
|
+
* },
|
|
12
|
+
* spacing: {
|
|
13
|
+
* md: "16px"
|
|
14
|
+
* }
|
|
15
|
+
* } as const;
|
|
16
|
+
*
|
|
17
|
+
* export type Tokens = typeof tokens;
|
|
18
|
+
*
|
|
19
|
+
* Multi-mode tokens emit as nested objects keyed by mode name:
|
|
20
|
+
*
|
|
21
|
+
* export const tokens = {
|
|
22
|
+
* mode: {
|
|
23
|
+
* primary: { Light: "#FFFFFF", Dark: "#000000" }
|
|
24
|
+
* }
|
|
25
|
+
* } as const;
|
|
26
|
+
*
|
|
27
|
+
* Aliases get resolved at write time to the literal value (TypeScript
|
|
28
|
+
* can't natively express references). Cross-library aliases get emitted
|
|
29
|
+
* as `null` with a "TODO: cross-library alias unresolved" comment so
|
|
30
|
+
* consumers see the gap.
|
|
31
|
+
*/
|
|
32
|
+
import type { TokenDocument } from "../types.js";
|
|
33
|
+
import type { FormatOptions, FormatResult } from "./index.js";
|
|
34
|
+
export declare function formatTsModule(doc: TokenDocument, opts: FormatOptions): FormatResult;
|
|
35
|
+
//# sourceMappingURL=ts-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-module.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/formatters/ts-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAS,aAAa,EAAwB,MAAM,aAAa,CAAC;AAE9E,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,cAAc,CAC5B,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,aAAa,GAClB,YAAY,CA+Bd"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript module formatter.
|
|
3
|
+
*
|
|
4
|
+
* Output shape:
|
|
5
|
+
*
|
|
6
|
+
* // tokens.ts
|
|
7
|
+
* export const tokens = {
|
|
8
|
+
* color: {
|
|
9
|
+
* primary: "#4085F2",
|
|
10
|
+
* brand: { primary: "#FF00AA" }
|
|
11
|
+
* },
|
|
12
|
+
* spacing: {
|
|
13
|
+
* md: "16px"
|
|
14
|
+
* }
|
|
15
|
+
* } as const;
|
|
16
|
+
*
|
|
17
|
+
* export type Tokens = typeof tokens;
|
|
18
|
+
*
|
|
19
|
+
* Multi-mode tokens emit as nested objects keyed by mode name:
|
|
20
|
+
*
|
|
21
|
+
* export const tokens = {
|
|
22
|
+
* mode: {
|
|
23
|
+
* primary: { Light: "#FFFFFF", Dark: "#000000" }
|
|
24
|
+
* }
|
|
25
|
+
* } as const;
|
|
26
|
+
*
|
|
27
|
+
* Aliases get resolved at write time to the literal value (TypeScript
|
|
28
|
+
* can't natively express references). Cross-library aliases get emitted
|
|
29
|
+
* as `null` with a "TODO: cross-library alias unresolved" comment so
|
|
30
|
+
* consumers see the gap.
|
|
31
|
+
*/
|
|
32
|
+
import { buildTokenIndex, resolveAliasChain } from "../alias-resolver.js";
|
|
33
|
+
export function formatTsModule(doc, opts) {
|
|
34
|
+
const warnings = [];
|
|
35
|
+
const files = [];
|
|
36
|
+
const splitByCollection = opts.target.splitByCollection ?? false;
|
|
37
|
+
// splitByMode doesn't make conceptual sense for a TypeScript module
|
|
38
|
+
// (the value is held in-memory at runtime, not selected by CSS cascade).
|
|
39
|
+
// TypeScript modules can't natively express alias references — runtime
|
|
40
|
+
// code reading tokens.color.X gets a string at runtime, no resolution
|
|
41
|
+
// logic. Build a document-wide token index so aliases resolve to their
|
|
42
|
+
// literal target at export time. The index spans every set even when
|
|
43
|
+
// splitByCollection writes single-set files, because aliases often
|
|
44
|
+
// cross set boundaries (semantic → primitives).
|
|
45
|
+
const tokenIndex = buildTokenIndex(doc);
|
|
46
|
+
if (splitByCollection) {
|
|
47
|
+
for (const set of doc.sets) {
|
|
48
|
+
files.push({
|
|
49
|
+
path: filenameFor(opts, set),
|
|
50
|
+
content: renderTsFile([set], opts, tokenIndex, warnings),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
files.push({
|
|
56
|
+
path: filenameFor(opts),
|
|
57
|
+
content: renderTsFile(doc.sets, opts, tokenIndex, warnings),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return { files, warnings };
|
|
61
|
+
}
|
|
62
|
+
function filenameFor(opts, set) {
|
|
63
|
+
if (opts.target.filename)
|
|
64
|
+
return opts.target.filename;
|
|
65
|
+
if (set)
|
|
66
|
+
return `${slugify(set.name)}.tokens.ts`;
|
|
67
|
+
return "tokens.ts";
|
|
68
|
+
}
|
|
69
|
+
function slugify(s) {
|
|
70
|
+
return s
|
|
71
|
+
.trim()
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
74
|
+
.replace(/^-+|-+$/g, "");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert a path segment to a valid JS identifier or quoted-key form.
|
|
78
|
+
* Numeric leading chars, hyphens, etc. → quoted string key.
|
|
79
|
+
*/
|
|
80
|
+
function jsKey(segment) {
|
|
81
|
+
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(segment))
|
|
82
|
+
return segment;
|
|
83
|
+
return JSON.stringify(segment);
|
|
84
|
+
}
|
|
85
|
+
function renderTsFile(sets, opts, tokenIndex, warnings) {
|
|
86
|
+
const prefix = opts.target.prefix ?? "";
|
|
87
|
+
const lines = [];
|
|
88
|
+
lines.push("/**");
|
|
89
|
+
lines.push(" * Generated by figma-console-mcp — do not edit by hand.");
|
|
90
|
+
lines.push(" * Regenerate with: figma_export_tokens (or your npm tokens:export script)");
|
|
91
|
+
lines.push(" */");
|
|
92
|
+
lines.push("");
|
|
93
|
+
const constName = prefix
|
|
94
|
+
? `${prefix.replace(/-+$/, "").replace(/-(\w)/g, (_, c) => c.toUpperCase())}Tokens`
|
|
95
|
+
: "tokens";
|
|
96
|
+
// Build the nested object structure by walking each set's tokens.
|
|
97
|
+
const tree = {};
|
|
98
|
+
for (const set of sets) {
|
|
99
|
+
for (const token of set.tokens) {
|
|
100
|
+
writeTokenIntoTree(tree, token, set, tokenIndex, warnings);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
lines.push(`export const ${constName} = ${renderTree(tree, 0)} as const;`);
|
|
104
|
+
lines.push("");
|
|
105
|
+
lines.push(`export type ${constName[0].toUpperCase()}${constName.slice(1)} = typeof ${constName};`);
|
|
106
|
+
lines.push("");
|
|
107
|
+
return lines.join("\n");
|
|
108
|
+
}
|
|
109
|
+
function writeTokenIntoTree(tree, token, set, tokenIndex, warnings) {
|
|
110
|
+
let cursor = tree;
|
|
111
|
+
for (let i = 0; i < token.path.length - 1; i++) {
|
|
112
|
+
const segment = token.path[i];
|
|
113
|
+
let next = cursor[segment];
|
|
114
|
+
if (!next || isLeaf(next)) {
|
|
115
|
+
next = {};
|
|
116
|
+
cursor[segment] = next;
|
|
117
|
+
}
|
|
118
|
+
cursor = next;
|
|
119
|
+
}
|
|
120
|
+
const leafKey = token.path[token.path.length - 1];
|
|
121
|
+
const isMulti = set.modes.length > 1;
|
|
122
|
+
const resolvedValues = {};
|
|
123
|
+
for (const [modeName, value] of Object.entries(token.values)) {
|
|
124
|
+
let effective = value;
|
|
125
|
+
if (value.reference) {
|
|
126
|
+
effective = resolveAliasChain(value, modeName, tokenIndex);
|
|
127
|
+
if (!effective) {
|
|
128
|
+
const bare = value.reference.replace(/^\{|\}$/g, "");
|
|
129
|
+
const reason = bare.startsWith("__library:") || bare === "unknown"
|
|
130
|
+
? "cross-library alias"
|
|
131
|
+
: "alias target not found";
|
|
132
|
+
warnings.push(`Skipped ${token.path.join(".")} (mode "${modeName}") in TS module — ${reason}: ${value.reference}.`);
|
|
133
|
+
resolvedValues[modeName] = null;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!effective || effective.literal === undefined || effective.literal === null)
|
|
138
|
+
continue;
|
|
139
|
+
resolvedValues[modeName] = formatLiteral(effective.literal, token.type);
|
|
140
|
+
}
|
|
141
|
+
cursor[leafKey] = {
|
|
142
|
+
__leaf: true,
|
|
143
|
+
values: resolvedValues,
|
|
144
|
+
type: token.type,
|
|
145
|
+
isMultiMode: isMulti,
|
|
146
|
+
description: token.description,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function isLeaf(node) {
|
|
150
|
+
return node.__leaf === true;
|
|
151
|
+
}
|
|
152
|
+
function renderTree(tree, indent) {
|
|
153
|
+
const ind = " ".repeat(indent);
|
|
154
|
+
const innerInd = " ".repeat(indent + 1);
|
|
155
|
+
const entries = [];
|
|
156
|
+
for (const [key, value] of Object.entries(tree)) {
|
|
157
|
+
const k = jsKey(key);
|
|
158
|
+
if (isLeaf(value)) {
|
|
159
|
+
const leaf = value;
|
|
160
|
+
if (leaf.isMultiMode) {
|
|
161
|
+
// Emit as { Mode: value } object
|
|
162
|
+
const modeEntries = [];
|
|
163
|
+
for (const [m, v] of Object.entries(leaf.values)) {
|
|
164
|
+
modeEntries.push(`${jsKey(m)}: ${renderValue(v)}`);
|
|
165
|
+
}
|
|
166
|
+
entries.push(`${innerInd}${k}: { ${modeEntries.join(", ")} }`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// Single-mode: emit value directly
|
|
170
|
+
const onlyValue = Object.values(leaf.values)[0];
|
|
171
|
+
entries.push(`${innerInd}${k}: ${renderValue(onlyValue)}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
entries.push(`${innerInd}${k}: ${renderTree(value, indent + 1)}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (entries.length === 0)
|
|
179
|
+
return "{}";
|
|
180
|
+
return `{\n${entries.join(",\n")},\n${ind}}`;
|
|
181
|
+
}
|
|
182
|
+
function renderValue(v) {
|
|
183
|
+
if (v === null)
|
|
184
|
+
return "null /* TODO: cross-library alias unresolved */";
|
|
185
|
+
if (typeof v === "string")
|
|
186
|
+
return JSON.stringify(v);
|
|
187
|
+
if (typeof v === "number" || typeof v === "boolean")
|
|
188
|
+
return String(v);
|
|
189
|
+
return JSON.stringify(v);
|
|
190
|
+
}
|
|
191
|
+
function formatLiteral(value, type) {
|
|
192
|
+
if (typeof value === "number") {
|
|
193
|
+
if (type === "dimension")
|
|
194
|
+
return `${value}px`;
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=ts-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D,OAAO,CAAC,IAAI,CAAC,GAAG,QAAQ,GAAG,CAAC,KAAK,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;aAC5D;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,GAAG,QAAQ,GAAG,CAAC,KAAK,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;SACnE;KACF;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC;AAC/C,CAAC;AAED,SAAS,WAAW,CAAC,CAAU;IAC7B,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,iDAAiD,CAAC;IACzE,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACpD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,aAAa,CAAC,KAAc,EAAE,IAAY;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAI,IAAI,KAAK,WAAW;YAAE,OAAO,GAAG,KAAK,IAAI,CAAC;QAC9C,OAAO,KAAK,CAAC;KACd;IACD,OAAO,KAA2C,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of the token sync engine.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the canonical types, the parser/formatter dispatchers, the
|
|
5
|
+
* config loader, the alias resolver, and the Figma converter. External
|
|
6
|
+
* callers (tools, tests) should import from here rather than reaching into
|
|
7
|
+
* subdirectories.
|
|
8
|
+
*/
|
|
9
|
+
export type { Token, TokenDocument, TokenSet, TokenType, TokenValue, TokenDiff, FigmaMcpExtensions, SyncStrategy, ConflictResolution, ExportFormat, ImportFormat, TypographyValue, ShadowValue, GradientValue, GradientStop, BorderValue, TransitionValue, } from "./types.js";
|
|
10
|
+
export { FIGMA_MCP_EXTENSION_KEY } from "./types.js";
|
|
11
|
+
export { TokensConfigSchema, type TokensConfig, type OutputTarget, type LoadedTokensConfig, loadTokensConfig, findTokensConfig, DEFAULT_TOKENS_CONFIG, buildSuggestedScaffold, resolveOutputTargets, resolveConflictStrategy, } from "./config.js";
|
|
12
|
+
export { ExportTokensInputSchema, ImportTokensInputSchema, ExportFormatSchema, ImportFormatSchema, SyncStrategySchema, ConflictResolutionSchema, type ExportTokensInput, type ImportTokensInput, } from "./schemas.js";
|
|
13
|
+
export { parse, detectFormat, type ParseInput, type ParseResult, } from "./parsers/index.js";
|
|
14
|
+
export { format, type FormatOptions, type FormatResult, } from "./formatters/index.js";
|
|
15
|
+
export { buildTokenIndex, resolveReference, resolveAliasChain, validateAliases, formatDtcgReference, parseDtcgReference, } from "./alias-resolver.js";
|
|
16
|
+
export { convertFigmaVariablesToDocument, type FigmaVariablesPayload, type ConvertOptions, type ConvertResult, } from "./figma-converter.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tokens/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,KAAK,EACL,aAAa,EACb,QAAQ,EACR,SAAS,EACT,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,EACL,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,KAAK,EACL,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,MAAM,EACN,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,+BAA+B,EAC/B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of the token sync engine.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the canonical types, the parser/formatter dispatchers, the
|
|
5
|
+
* config loader, the alias resolver, and the Figma converter. External
|
|
6
|
+
* callers (tools, tests) should import from here rather than reaching into
|
|
7
|
+
* subdirectories.
|
|
8
|
+
*/
|
|
9
|
+
export { FIGMA_MCP_EXTENSION_KEY } from "./types.js";
|
|
10
|
+
export { TokensConfigSchema, loadTokensConfig, findTokensConfig, DEFAULT_TOKENS_CONFIG, buildSuggestedScaffold, resolveOutputTargets, resolveConflictStrategy, } from "./config.js";
|
|
11
|
+
export { ExportTokensInputSchema, ImportTokensInputSchema, ExportFormatSchema, ImportFormatSchema, SyncStrategySchema, ConflictResolutionSchema, } from "./schemas.js";
|
|
12
|
+
export { parse, detectFormat, } from "./parsers/index.js";
|
|
13
|
+
export { format, } from "./formatters/index.js";
|
|
14
|
+
export { buildTokenIndex, resolveReference, resolveAliasChain, validateAliases, formatDtcgReference, parseDtcgReference, } from "./alias-resolver.js";
|
|
15
|
+
export { convertFigmaVariablesToDocument, } from "./figma-converter.js";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tokens/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAsBH,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,EACL,kBAAkB,EAIlB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GAGzB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,KAAK,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,MAAM,GAGP,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,+BAA+B,GAIhC,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-vars.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/parsers/css-vars.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG1D,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,CAE5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-vars.js","sourceRoot":"","sources":["../../../../src/core/tokens/parsers/css-vars.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAE5D,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,MAAM,IAAI,8BAA8B,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DTCG (Design Tokens Community Group) JSON parser.
|
|
3
|
+
*
|
|
4
|
+
* Reads DTCG-spec JSON (https://tr.designtokens.org/format/) and produces our
|
|
5
|
+
* canonical internal TokenDocument. Designed for non-destructive round-trip:
|
|
6
|
+
* a document serialized by `formatDtcg` then parsed back through this module
|
|
7
|
+
* is equal to the original (modulo key ordering, which the formatter sorts
|
|
8
|
+
* for stable diffs).
|
|
9
|
+
*
|
|
10
|
+
* Handles:
|
|
11
|
+
* - Group nesting with arbitrary depth
|
|
12
|
+
* - $value / $type / $description / $extensions on leaf tokens
|
|
13
|
+
* - Alias references: `"$value": "{path.to.token}"`
|
|
14
|
+
* - Group-level $type inheritance per the DTCG spec (tokens without their
|
|
15
|
+
* own $type inherit from their nearest ancestor group that has one)
|
|
16
|
+
* - Our $extensions["figma-console-mcp"] metadata for round-trip ID preservation
|
|
17
|
+
* - Multi-mode tokens stashed in $extensions.modes by our formatter
|
|
18
|
+
*/
|
|
19
|
+
import type { ParseInput, ParseResult } from "./index.js";
|
|
20
|
+
export declare function parseDtcg(input: ParseInput): ParseResult;
|
|
21
|
+
//# sourceMappingURL=dtcg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dtcg.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/parsers/dtcg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA2B1D,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CA6CxD"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DTCG (Design Tokens Community Group) JSON parser.
|
|
3
|
+
*
|
|
4
|
+
* Reads DTCG-spec JSON (https://tr.designtokens.org/format/) and produces our
|
|
5
|
+
* canonical internal TokenDocument. Designed for non-destructive round-trip:
|
|
6
|
+
* a document serialized by `formatDtcg` then parsed back through this module
|
|
7
|
+
* is equal to the original (modulo key ordering, which the formatter sorts
|
|
8
|
+
* for stable diffs).
|
|
9
|
+
*
|
|
10
|
+
* Handles:
|
|
11
|
+
* - Group nesting with arbitrary depth
|
|
12
|
+
* - $value / $type / $description / $extensions on leaf tokens
|
|
13
|
+
* - Alias references: `"$value": "{path.to.token}"`
|
|
14
|
+
* - Group-level $type inheritance per the DTCG spec (tokens without their
|
|
15
|
+
* own $type inherit from their nearest ancestor group that has one)
|
|
16
|
+
* - Our $extensions["figma-console-mcp"] metadata for round-trip ID preservation
|
|
17
|
+
* - Multi-mode tokens stashed in $extensions.modes by our formatter
|
|
18
|
+
*/
|
|
19
|
+
import { FIGMA_MCP_EXTENSION_KEY } from "../types.js";
|
|
20
|
+
import { parseDtcgReference } from "../alias-resolver.js";
|
|
21
|
+
const DTCG_TYPES = new Set([
|
|
22
|
+
"color",
|
|
23
|
+
"dimension",
|
|
24
|
+
"fontFamily",
|
|
25
|
+
"fontWeight",
|
|
26
|
+
"duration",
|
|
27
|
+
"cubicBezier",
|
|
28
|
+
"number",
|
|
29
|
+
"string",
|
|
30
|
+
"boolean",
|
|
31
|
+
"shadow",
|
|
32
|
+
"typography",
|
|
33
|
+
"gradient",
|
|
34
|
+
"border",
|
|
35
|
+
"transition",
|
|
36
|
+
"strokeStyle",
|
|
37
|
+
]);
|
|
38
|
+
export function parseDtcg(input) {
|
|
39
|
+
const warnings = [];
|
|
40
|
+
const root = parseJson(input);
|
|
41
|
+
// Document-level $extensions: pull out our MCP metadata if present.
|
|
42
|
+
// `fileMode` is the critical piece for splitByMode round-trip — when set,
|
|
43
|
+
// every token in the file represents that mode's value, so we label them
|
|
44
|
+
// accordingly instead of falling back to "Default".
|
|
45
|
+
const meta = {};
|
|
46
|
+
let fileMode;
|
|
47
|
+
const rootExt = root.$extensions;
|
|
48
|
+
if (rootExt && typeof rootExt === "object") {
|
|
49
|
+
const mcpMeta = rootExt[FIGMA_MCP_EXTENSION_KEY];
|
|
50
|
+
if (mcpMeta && typeof mcpMeta === "object") {
|
|
51
|
+
const m = mcpMeta;
|
|
52
|
+
if (typeof m.figmaFileKey === "string")
|
|
53
|
+
meta.figmaFileKey = m.figmaFileKey;
|
|
54
|
+
if (typeof m.exportedAt === "string")
|
|
55
|
+
meta.exportedAt = m.exportedAt;
|
|
56
|
+
if (typeof m.mcpVersion === "string")
|
|
57
|
+
meta.mcpVersion = m.mcpVersion;
|
|
58
|
+
if (typeof m.fileMode === "string")
|
|
59
|
+
fileMode = m.fileMode;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Each top-level group is a TokenSet. Walk it to extract its tokens.
|
|
63
|
+
const sets = [];
|
|
64
|
+
for (const [setKey, setNode] of Object.entries(root)) {
|
|
65
|
+
if (setKey.startsWith("$"))
|
|
66
|
+
continue; // $extensions etc.
|
|
67
|
+
if (!setNode || typeof setNode !== "object") {
|
|
68
|
+
warnings.push(`Top-level entry "${setKey}" is not a group; skipping. Expected object.`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
sets.push(extractSet(setKey, setNode, warnings, fileMode));
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
document: {
|
|
75
|
+
$schema: "https://figma-console-mcp.southleft.com/schemas/dtcg-extended-v1.json",
|
|
76
|
+
sets,
|
|
77
|
+
meta: Object.keys(meta).length > 0 ? meta : undefined,
|
|
78
|
+
},
|
|
79
|
+
detectedFormat: "dtcg",
|
|
80
|
+
warnings,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function parseJson(input) {
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(input.payload);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
throw new Error(`[figma-console-mcp] Failed to parse DTCG JSON${input.sourcePath ? ` at ${input.sourcePath}` : ""}: ${err instanceof Error ? err.message : String(err)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function extractSet(setKey, setNode, warnings, fileMode) {
|
|
92
|
+
const tokens = [];
|
|
93
|
+
const modes = new Set();
|
|
94
|
+
// Set-level metadata pulled from $extensions["figma-console-mcp"]. We
|
|
95
|
+
// recover the original (un-slugified) set name from `originalName` so
|
|
96
|
+
// round-trip matching works even after slugification.
|
|
97
|
+
const setExt = setNode.$extensions;
|
|
98
|
+
let figmaCollectionId;
|
|
99
|
+
let originalName;
|
|
100
|
+
if (setExt && typeof setExt === "object") {
|
|
101
|
+
const mcp = setExt[FIGMA_MCP_EXTENSION_KEY];
|
|
102
|
+
if (mcp && typeof mcp === "object") {
|
|
103
|
+
const m = mcp;
|
|
104
|
+
if (typeof m.figmaCollectionId === "string") {
|
|
105
|
+
figmaCollectionId = m.figmaCollectionId;
|
|
106
|
+
}
|
|
107
|
+
if (typeof m.originalName === "string") {
|
|
108
|
+
originalName = m.originalName;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Walk the set's tree, collecting tokens.
|
|
113
|
+
walkGroup(setNode, [], undefined, tokens, modes, warnings, fileMode);
|
|
114
|
+
return {
|
|
115
|
+
name: originalName ?? setKey,
|
|
116
|
+
description: typeof setNode.$description === "string" ? setNode.$description : undefined,
|
|
117
|
+
modes: modes.size > 0 ? [...modes] : ["Default"],
|
|
118
|
+
tokens,
|
|
119
|
+
meta: figmaCollectionId ? { figmaCollectionId } : undefined,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function walkGroup(node, path, inheritedType, tokens, modes, warnings, fileMode) {
|
|
123
|
+
// Group-level $type provides inheritance for descendant tokens that lack
|
|
124
|
+
// their own $type, per the DTCG spec.
|
|
125
|
+
const groupType = typeof node.$type === "string" && DTCG_TYPES.has(node.$type)
|
|
126
|
+
? node.$type
|
|
127
|
+
: inheritedType;
|
|
128
|
+
for (const [key, value] of Object.entries(node)) {
|
|
129
|
+
if (key.startsWith("$"))
|
|
130
|
+
continue;
|
|
131
|
+
if (!value || typeof value !== "object") {
|
|
132
|
+
warnings.push(`Non-group, non-token entry at ${[...path, key].join(".")}; skipping.`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const childPath = [...path, key];
|
|
136
|
+
if (isLeafToken(value)) {
|
|
137
|
+
const token = extractToken(childPath, value, groupType, warnings, fileMode);
|
|
138
|
+
tokens.push(token);
|
|
139
|
+
for (const mode of Object.keys(token.values))
|
|
140
|
+
modes.add(mode);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
walkGroup(value, childPath, groupType, tokens, modes, warnings, fileMode);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function isLeafToken(node) {
|
|
148
|
+
return "$value" in node;
|
|
149
|
+
}
|
|
150
|
+
function extractToken(path, node, inheritedType, warnings, fileMode) {
|
|
151
|
+
const rawType = node.$type;
|
|
152
|
+
let type;
|
|
153
|
+
if (typeof rawType === "string" && DTCG_TYPES.has(rawType)) {
|
|
154
|
+
type = rawType;
|
|
155
|
+
}
|
|
156
|
+
else if (inheritedType) {
|
|
157
|
+
type = inheritedType;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
type = inferType(node.$value);
|
|
161
|
+
warnings.push(`Token ${path.join(".")} has no $type and no group $type inherited; inferred "${type}".`);
|
|
162
|
+
}
|
|
163
|
+
const description = typeof node.$description === "string" ? node.$description : undefined;
|
|
164
|
+
// Detect multi-mode stashed in $extensions.{FIGMA_MCP_EXTENSION_KEY}.modes
|
|
165
|
+
// (placed there by our own formatter for one-file-multi-mode output).
|
|
166
|
+
const values = {};
|
|
167
|
+
const ext = node.$extensions;
|
|
168
|
+
const mcpExt = ext && typeof ext === "object"
|
|
169
|
+
? ext[FIGMA_MCP_EXTENSION_KEY]
|
|
170
|
+
: undefined;
|
|
171
|
+
const stashedModes = mcpExt?.modes;
|
|
172
|
+
// Decide which mode name to assign to the primary $value.
|
|
173
|
+
// 1. If the file declares a fileMode (splitByMode output), use that.
|
|
174
|
+
// 2. Otherwise fall back to "Default" — the parser can't know the
|
|
175
|
+
// mode without that hint.
|
|
176
|
+
// Then absorb any stashedModes (one-file-multi-mode output) verbatim.
|
|
177
|
+
const primaryMode = fileMode ?? "Default";
|
|
178
|
+
values[primaryMode] = decodeValue(node.$value);
|
|
179
|
+
if (stashedModes) {
|
|
180
|
+
for (const [modeName, modeValue] of Object.entries(stashedModes)) {
|
|
181
|
+
// Don't overwrite the primary if a stashed entry collides with it.
|
|
182
|
+
if (modeName !== primaryMode) {
|
|
183
|
+
values[modeName] = decodeValue(modeValue);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Preserve all other vendor extensions verbatim.
|
|
188
|
+
let extensions;
|
|
189
|
+
if (ext && typeof ext === "object") {
|
|
190
|
+
extensions = {};
|
|
191
|
+
for (const [vendor, payload] of Object.entries(ext)) {
|
|
192
|
+
if (vendor === FIGMA_MCP_EXTENSION_KEY &&
|
|
193
|
+
payload &&
|
|
194
|
+
typeof payload === "object") {
|
|
195
|
+
// Strip the "modes" we already absorbed into values.
|
|
196
|
+
const cleaned = { ...payload };
|
|
197
|
+
delete cleaned.modes;
|
|
198
|
+
if (Object.keys(cleaned).length > 0) {
|
|
199
|
+
extensions[vendor] = cleaned;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
extensions[vendor] = payload;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (Object.keys(extensions).length === 0)
|
|
207
|
+
extensions = undefined;
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
path,
|
|
211
|
+
type,
|
|
212
|
+
description,
|
|
213
|
+
values,
|
|
214
|
+
extensions,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Convert a DTCG $value to our internal TokenValue. Detects alias references
|
|
219
|
+
* (strings of the form `{path.to.token}`) and unwraps them into TokenValue.reference.
|
|
220
|
+
*/
|
|
221
|
+
function decodeValue(rawValue) {
|
|
222
|
+
if (typeof rawValue === "string") {
|
|
223
|
+
const refPath = parseDtcgReference(rawValue);
|
|
224
|
+
if (refPath) {
|
|
225
|
+
return { reference: rawValue };
|
|
226
|
+
}
|
|
227
|
+
return { literal: rawValue };
|
|
228
|
+
}
|
|
229
|
+
if (rawValue === null ||
|
|
230
|
+
typeof rawValue === "number" ||
|
|
231
|
+
typeof rawValue === "boolean") {
|
|
232
|
+
return { literal: rawValue ?? "" };
|
|
233
|
+
}
|
|
234
|
+
// Composite values (typography, shadow, etc.) — preserve verbatim.
|
|
235
|
+
return { literal: rawValue };
|
|
236
|
+
}
|
|
237
|
+
function inferType(rawValue) {
|
|
238
|
+
if (typeof rawValue === "string") {
|
|
239
|
+
// Heuristics: color-ish strings → color; px/rem/em → dimension; else string.
|
|
240
|
+
if (/^#[0-9a-f]{3,8}$/i.test(rawValue))
|
|
241
|
+
return "color";
|
|
242
|
+
if (/^(rgb|hsl|oklch)/i.test(rawValue))
|
|
243
|
+
return "color";
|
|
244
|
+
if (/^[\d.]+(px|rem|em|pt|dp)$/i.test(rawValue))
|
|
245
|
+
return "dimension";
|
|
246
|
+
return "string";
|
|
247
|
+
}
|
|
248
|
+
if (typeof rawValue === "number")
|
|
249
|
+
return "number";
|
|
250
|
+
if (typeof rawValue === "boolean")
|
|
251
|
+
return "boolean";
|
|
252
|
+
return "string";
|
|
253
|
+
}
|
|
254
|
+
//#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,QAAiB;IACpC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,OAAO,EAAE;YACX,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;SAChC;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;KAC9B;IACD,IACE,QAAQ,KAAK,IAAI;QACjB,OAAO,QAAQ,KAAK,QAAQ;QAC5B,OAAO,QAAQ,KAAK,SAAS,EAC7B;QACA,OAAO,EAAE,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC;KACpC;IACD,mEAAmE;IACnE,OAAO,EAAE,OAAO,EAAE,QAAmC,EAAE,CAAC;AAC1D,CAAC;AAED,SAAS,SAAS,CAAC,QAAiB;IAClC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,6EAA6E;QAC7E,IAAI,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAE,OAAO,OAAO,CAAC;QACvD,IAAI,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAE,OAAO,OAAO,CAAC;QACvD,IAAI,4BAA4B,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAE,OAAO,WAAW,CAAC;QACpE,OAAO,QAAQ,CAAC;KACjB;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAClD,IAAI,OAAO,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACpD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser dispatcher. Each parser converts an input format into our canonical
|
|
3
|
+
* internal TokenDocument model.
|
|
4
|
+
*/
|
|
5
|
+
import type { ImportFormat, TokenDocument } from "../types.js";
|
|
6
|
+
export interface ParseInput {
|
|
7
|
+
/** Raw text content of the source file. */
|
|
8
|
+
payload: string;
|
|
9
|
+
/** Optional file path — used for auto-detection by extension and for error messages. */
|
|
10
|
+
sourcePath?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ParseResult {
|
|
13
|
+
document: TokenDocument;
|
|
14
|
+
/** Format the parser used (resolved from 'auto' when applicable). */
|
|
15
|
+
detectedFormat: Exclude<ImportFormat, "auto">;
|
|
16
|
+
/** Non-fatal warnings to surface to the user (unknown $type, etc.). */
|
|
17
|
+
warnings: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse a payload using the given format. When format is 'auto', sniffs the
|
|
21
|
+
* payload to pick the right parser.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parse(format: ImportFormat, input: ParseInput): ParseResult;
|
|
24
|
+
/**
|
|
25
|
+
* Sniff the payload to determine its format. Order matters — earlier checks
|
|
26
|
+
* are higher-priority signals.
|
|
27
|
+
*
|
|
28
|
+
* 1. JSON content with DTCG markers ($value/$type at any depth)
|
|
29
|
+
* 2. JSON content with Tokens Studio markers ($themes.json or $metadata)
|
|
30
|
+
* 3. JSON content with Style Dictionary v3 markers (bare value/type)
|
|
31
|
+
* 4. Tailwind v4 `@theme` block
|
|
32
|
+
* 5. CSS custom properties (`:root { --foo: bar; }`)
|
|
33
|
+
* 6. SCSS variables (`$foo: bar;`)
|
|
34
|
+
* 7. File extension as a last-resort hint
|
|
35
|
+
*/
|
|
36
|
+
export declare function detectFormat(input: ParseInput): Exclude<ImportFormat, "auto">;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/tokens/parsers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAW/D,MAAM,WAAW,UAAU;IACzB,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,wFAAwF;IACxF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,aAAa,CAAC;IACxB,qEAAqE;IACrE,cAAc,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC9C,uEAAuE;IACvE,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,GAAG,WAAW,CA0B1E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,CAsC7E"}
|