@sarjallab09/figma-intelligence 1.0.1 → 1.2.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 +67 -36
- package/dist/bin/cli.js +2 -0
- package/dist/design-bridge/bridge.js +2 -0
- package/dist/figma-bridge-plugin/bridge-relay.js +2 -0
- package/dist/figma-bridge-plugin/code.js +1 -0
- package/{figma-bridge-plugin → dist/figma-bridge-plugin}/package-lock.json +0 -3
- package/dist/figma-bridge-plugin/ui.html +4970 -0
- package/dist/figma-intelligence-layer/dist/index.js +2 -0
- package/dist/scripts/clean-existing-chunks.js +2 -0
- package/dist/scripts/connect-ai-tool.js +2 -0
- package/dist/scripts/convert-hub-pdfs.js +2 -0
- package/dist/scripts/figma-mcp-status.js +2 -0
- package/dist/scripts/register-codex-mcp.js +2 -0
- package/dist/scripts/test-copilot-chat.js +2 -0
- package/package.json +11 -8
- package/bin/cli.js +0 -859
- package/design-bridge/bridge.js +0 -196
- package/design-bridge/lib/assets.js +0 -367
- package/design-bridge/lib/prompt.js +0 -85
- package/design-bridge/lib/server.js +0 -66
- package/design-bridge/lib/stitch.js +0 -37
- package/design-bridge/lib/tokens.js +0 -82
- package/design-bridge/package-lock.json +0 -579
- package/figma-bridge-plugin/README.md +0 -97
- package/figma-bridge-plugin/anthropic-chat-runner.js +0 -192
- package/figma-bridge-plugin/bridge-relay.js +0 -2363
- package/figma-bridge-plugin/chat-runner.js +0 -459
- package/figma-bridge-plugin/code.js +0 -1528
- package/figma-bridge-plugin/codex-runner.js +0 -505
- package/figma-bridge-plugin/component-schemas.js +0 -110
- package/figma-bridge-plugin/content-context.js +0 -869
- package/figma-bridge-plugin/create-button.js +0 -216
- package/figma-bridge-plugin/gemini-cli-runner.js +0 -291
- package/figma-bridge-plugin/gemini-runner.js +0 -187
- package/figma-bridge-plugin/html-to-figma.js +0 -927
- package/figma-bridge-plugin/knowledge-hub/.gitkeep +0 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/anatomy-spec.md +0 -159
- package/figma-bridge-plugin/knowledge-hub/uspec-references/api-spec.md +0 -162
- package/figma-bridge-plugin/knowledge-hub/uspec-references/color-spec.md +0 -148
- package/figma-bridge-plugin/knowledge-hub/uspec-references/full-spec-template.md +0 -314
- package/figma-bridge-plugin/knowledge-hub/uspec-references/property-spec.md +0 -175
- package/figma-bridge-plugin/knowledge-hub/uspec-references/screen-reader-spec.md +0 -180
- package/figma-bridge-plugin/knowledge-hub/uspec-references/structure-spec.md +0 -165
- package/figma-bridge-plugin/perplexity-runner.js +0 -188
- package/figma-bridge-plugin/references/SKILL.md +0 -178
- package/figma-bridge-plugin/references/anatomy-spec.md +0 -159
- package/figma-bridge-plugin/references/api-spec.md +0 -162
- package/figma-bridge-plugin/references/color-spec.md +0 -148
- package/figma-bridge-plugin/references/full-spec-template.md +0 -314
- package/figma-bridge-plugin/references/property-spec.md +0 -175
- package/figma-bridge-plugin/references/screen-reader-spec.md +0 -180
- package/figma-bridge-plugin/references/structure-spec.md +0 -165
- package/figma-bridge-plugin/shared-prompt-config.js +0 -604
- package/figma-bridge-plugin/spec-helpers/build-table.js +0 -269
- package/figma-bridge-plugin/spec-helpers/classify-elements.js +0 -189
- package/figma-bridge-plugin/spec-helpers/index.js +0 -35
- package/figma-bridge-plugin/spec-helpers/parse-figma-link.js +0 -49
- package/figma-bridge-plugin/spec-helpers/position-markers.js +0 -158
- package/figma-bridge-plugin/stitch-auth.js +0 -322
- package/figma-bridge-plugin/stitch-runner.js +0 -1427
- package/figma-bridge-plugin/token-resolver.js +0 -107
- package/figma-bridge-plugin/ui.html +0 -4467
- package/figma-intelligence-layer/.env.example +0 -39
- package/figma-intelligence-layer/docs/local-image-generation.md +0 -60
- package/figma-intelligence-layer/examples/comfyui-workflow-template.example.json +0 -101
- package/figma-intelligence-layer/jest.config.js +0 -14
- package/figma-intelligence-layer/mcp-config.json +0 -19
- package/figma-intelligence-layer/package-lock.json +0 -5892
- package/figma-intelligence-layer/scripts/setup-comfyui-local.sh +0 -67
- package/figma-intelligence-layer/scripts/start-comfyui.sh +0 -33
- package/figma-intelligence-layer/src/index.ts +0 -2233
- package/figma-intelligence-layer/src/shared/auto-layout-validator.ts +0 -404
- package/figma-intelligence-layer/src/shared/cache.ts +0 -187
- package/figma-intelligence-layer/src/shared/color-operations.ts +0 -533
- package/figma-intelligence-layer/src/shared/color-utils.ts +0 -138
- package/figma-intelligence-layer/src/shared/component-script-builder.ts +0 -413
- package/figma-intelligence-layer/src/shared/component-templates.ts +0 -2767
- package/figma-intelligence-layer/src/shared/concept-taxonomy.ts +0 -694
- package/figma-intelligence-layer/src/shared/decision-log.ts +0 -128
- package/figma-intelligence-layer/src/shared/design-system-context.ts +0 -568
- package/figma-intelligence-layer/src/shared/design-system-intelligence.ts +0 -131
- package/figma-intelligence-layer/src/shared/design-system-matcher.ts +0 -184
- package/figma-intelligence-layer/src/shared/design-system-normalizers.ts +0 -196
- package/figma-intelligence-layer/src/shared/design-system-tokens.ts +0 -295
- package/figma-intelligence-layer/src/shared/dtcg-validator.ts +0 -530
- package/figma-intelligence-layer/src/shared/enrichment-pipeline.ts +0 -671
- package/figma-intelligence-layer/src/shared/figma-bridge.ts +0 -1408
- package/figma-intelligence-layer/src/shared/font-config.ts +0 -126
- package/figma-intelligence-layer/src/shared/icon-catalog.ts +0 -360
- package/figma-intelligence-layer/src/shared/icon-fetch.ts +0 -80
- package/figma-intelligence-layer/src/shared/prototype-script-builder.ts +0 -162
- package/figma-intelligence-layer/src/shared/response-compression.ts +0 -440
- package/figma-intelligence-layer/src/shared/semantic-token-catalog.ts +0 -324
- package/figma-intelligence-layer/src/shared/token-binder.ts +0 -505
- package/figma-intelligence-layer/src/shared/token-math.ts +0 -427
- package/figma-intelligence-layer/src/shared/token-naming.ts +0 -468
- package/figma-intelligence-layer/src/shared/token-utils.ts +0 -420
- package/figma-intelligence-layer/src/shared/types.ts +0 -346
- package/figma-intelligence-layer/src/shared/typography-presets.ts +0 -94
- package/figma-intelligence-layer/src/shared/unsplash.ts +0 -165
- package/figma-intelligence-layer/src/shared/vision-client.ts +0 -607
- package/figma-intelligence-layer/src/shared/vision-provider-anthropic.ts +0 -334
- package/figma-intelligence-layer/src/shared/vision-provider-openai.ts +0 -446
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-handler.ts +0 -782
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-renderer.ts +0 -496
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotation-kit.ts +0 -230
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/colorblind-sim.ts +0 -66
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/index.ts +0 -810
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-analyzer.ts +0 -1191
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-figma-page.ts +0 -1346
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-handler.ts +0 -148
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-figma-page.ts +0 -499
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-report.ts +0 -910
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-checker.ts +0 -989
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-criteria.ts +0 -1160
- package/figma-intelligence-layer/src/tools/phase1-vision/design-from-ref/index.ts +0 -424
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/component-recognizer.ts +0 -38
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/ds-matcher.ts +0 -111
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/font-matcher.ts +0 -114
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/icon-resolver.ts +0 -103
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/index.ts +0 -1060
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/layout-segmenter.ts +0 -18
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/token-inferencer.ts +0 -39
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/vision-pipeline.ts +0 -58
- package/figma-intelligence-layer/src/tools/phase1-vision/sketch-to-design/index.ts +0 -298
- package/figma-intelligence-layer/src/tools/phase1-vision/visual-audit/index.ts +0 -197
- package/figma-intelligence-layer/src/tools/phase2-accuracy/component-audit/index.ts +0 -494
- package/figma-intelligence-layer/src/tools/phase2-accuracy/intent-translator/index.ts +0 -356
- package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/container-patterns.ts +0 -123
- package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/index.ts +0 -663
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/built-in-rules.yaml +0 -56
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/index.ts +0 -614
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/rule-engine.ts +0 -113
- package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/color-theory.ts +0 -178
- package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/index.ts +0 -470
- package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/index.ts +0 -429
- package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/token-override-maps.ts +0 -226
- package/figma-intelligence-layer/src/tools/phase3-generation/ai-image-insert/index.ts +0 -535
- package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/index.ts +0 -660
- package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/pattern-fingerprints.ts +0 -209
- package/figma-intelligence-layer/src/tools/phase3-generation/composition-builder/index.ts +0 -540
- package/figma-intelligence-layer/src/tools/phase3-generation/figma-animated-build.ts +0 -391
- package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/index.ts +0 -2019
- package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/screen-templates.ts +0 -131
- package/figma-intelligence-layer/src/tools/phase3-generation/prototype-map/index.ts +0 -381
- package/figma-intelligence-layer/src/tools/phase3-generation/prototype-wire/index.ts +0 -565
- package/figma-intelligence-layer/src/tools/phase3-generation/swarm-build/index.ts +0 -764
- package/figma-intelligence-layer/src/tools/phase3-generation/system-drift/index.ts +0 -535
- package/figma-intelligence-layer/src/tools/phase3-generation/unsplash-search/index.ts +0 -84
- package/figma-intelligence-layer/src/tools/phase3-generation/url-to-frame/index.ts +0 -401
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/css-animations.ts +0 -68
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/framer-motion.ts +0 -78
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/swift-animations.ts +0 -93
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/index.ts +0 -596
- package/figma-intelligence-layer/src/tools/phase4-sync/ci-check/index.ts +0 -462
- package/figma-intelligence-layer/src/tools/phase4-sync/export-tokens/index.ts +0 -1470
- package/figma-intelligence-layer/src/tools/phase4-sync/generate-component-code/index.ts +0 -829
- package/figma-intelligence-layer/src/tools/phase4-sync/handoff-spec/index.ts +0 -702
- package/figma-intelligence-layer/src/tools/phase4-sync/icon-library-sync/index.ts +0 -483
- package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/index.ts +0 -501
- package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/storybook-parser.ts +0 -106
- package/figma-intelligence-layer/src/tools/phase4-sync/watch-docs/index.ts +0 -676
- package/figma-intelligence-layer/src/tools/phase4-sync/webhook-listener/index.ts +0 -560
- package/figma-intelligence-layer/src/tools/phase5-governance/apg-doc/index.ts +0 -1043
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/component-detection.ts +0 -620
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/anatomy.ts +0 -331
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/color-tokens.ts +0 -77
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/properties.ts +0 -54
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/snapshot.ts +0 -287
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/spacing.ts +0 -71
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/states.ts +0 -43
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/typography.ts +0 -71
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/index.ts +0 -221
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/_default.ts +0 -166
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/accordion.ts +0 -232
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/alert.ts +0 -234
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar-group.ts +0 -270
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar.ts +0 -249
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/badge.ts +0 -231
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/banner.ts +0 -293
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/breadcrumb.ts +0 -240
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/button.ts +0 -243
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/calendar.ts +0 -307
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/card.ts +0 -143
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/checkbox.ts +0 -227
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/chip.ts +0 -233
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/combobox.ts +0 -282
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/datepicker.ts +0 -276
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/divider.ts +0 -223
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/drawer.ts +0 -255
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/dropdown-menu.ts +0 -289
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/empty-state.ts +0 -261
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/file-uploader.ts +0 -290
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/form.ts +0 -265
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/grid.ts +0 -238
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/icon.ts +0 -255
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/index.ts +0 -128
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-edit.ts +0 -286
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-message.ts +0 -255
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/input.ts +0 -330
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/link.ts +0 -247
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/list.ts +0 -250
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/menu.ts +0 -247
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/modal.ts +0 -144
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navbar.ts +0 -264
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navigation.ts +0 -251
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/number-input.ts +0 -261
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/pagination.ts +0 -248
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/popover.ts +0 -270
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/progress.ts +0 -251
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/radio.ts +0 -142
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/range-slider.ts +0 -282
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/rating.ts +0 -250
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/search.ts +0 -258
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/segmented-control.ts +0 -265
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/select.ts +0 -319
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/skeleton.ts +0 -256
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/slider.ts +0 -232
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/spinner.ts +0 -239
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/status-dot.ts +0 -252
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/stepper.ts +0 -270
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/table.ts +0 -244
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tabs.ts +0 -143
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tag.ts +0 -243
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/textarea.ts +0 -259
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/time-picker.ts +0 -293
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toast.ts +0 -144
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toggle.ts +0 -289
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toolbar.ts +0 -267
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tooltip.ts +0 -232
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/treeview.ts +0 -257
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/typography.ts +0 -319
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/legacy-compat.ts +0 -121
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/anatomy-diagram.ts +0 -430
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/figma-page.ts +0 -312
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/json.ts +0 -129
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/markdown.ts +0 -78
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/visual-doc.ts +0 -2333
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/accessibility.ts +0 -100
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/anatomy.ts +0 -32
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/color-tokens.ts +0 -59
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/content-guidance.ts +0 -18
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/design-tokens.ts +0 -53
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/interaction-rules.ts +0 -19
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/overview.ts +0 -91
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/properties-api.ts +0 -71
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/qa-criteria.ts +0 -19
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/related-components.ts +0 -110
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/responsive.ts +0 -19
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/size-specs.ts +0 -67
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/spacing-structure.ts +0 -58
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/state-specs.ts +0 -79
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/states.ts +0 -50
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/type-hierarchy.ts +0 -33
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/typography.ts +0 -55
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/usage-guidelines.ts +0 -73
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/variants.ts +0 -81
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/types.ts +0 -409
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/index.ts +0 -198
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/renderer.ts +0 -701
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/types.ts +0 -88
- package/figma-intelligence-layer/src/tools/phase5-governance/decision-log/index.ts +0 -135
- package/figma-intelligence-layer/src/tools/phase5-governance/design-decision-log/index.ts +0 -491
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-primitives/index.ts +0 -416
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-scaffolder/index.ts +0 -722
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-variables/index.ts +0 -449
- package/figma-intelligence-layer/src/tools/phase5-governance/health-report/index.ts +0 -393
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/index.ts +0 -406
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/figma-page.ts +0 -292
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/json.ts +0 -24
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/markdown.ts +0 -172
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/naming-guide.ts +0 -409
- package/figma-intelligence-layer/src/tools/phase5-governance/token-analytics/index.ts +0 -594
- package/figma-intelligence-layer/src/tools/phase5-governance/token-docs/index.ts +0 -710
- package/figma-intelligence-layer/src/tools/phase5-governance/token-migrate/index.ts +0 -458
- package/figma-intelligence-layer/src/tools/phase5-governance/token-naming/index.ts +0 -134
- package/figma-intelligence-layer/tests/apg-doc.test.ts +0 -101
- package/figma-intelligence-layer/tests/design-system-context.test.ts +0 -152
- package/figma-intelligence-layer/tests/design-system-matcher.test.ts +0 -144
- package/figma-intelligence-layer/tests/figma-bridge.test.ts +0 -83
- package/figma-intelligence-layer/tests/generate-image-and-insert.test.ts +0 -56
- package/figma-intelligence-layer/tests/screen-cloner-regression.test.ts +0 -69
- package/figma-intelligence-layer/tests/smoke.test.ts +0 -174
- package/figma-intelligence-layer/tests/spec-generator.test.ts +0 -127
- package/figma-intelligence-layer/tests/token-migrate.test.ts +0 -21
- package/figma-intelligence-layer/tests/token-naming.test.ts +0 -30
- package/figma-intelligence-layer/tsconfig.json +0 -19
- package/scripts/clean-existing-chunks.js +0 -179
- package/scripts/connect-ai-tool.js +0 -490
- package/scripts/convert-hub-pdfs.js +0 -425
- package/scripts/figma-mcp-status.js +0 -349
- package/scripts/register-codex-mcp.js +0 -96
- /package/{design-bridge → dist/design-bridge}/.env.example +0 -0
- /package/{design-bridge → dist/design-bridge}/package.json +0 -0
- /package/{figma-bridge-plugin → dist/figma-bridge-plugin}/manifest.json +0 -0
- /package/{figma-bridge-plugin → dist/figma-bridge-plugin}/package.json +0 -0
- /package/{figma-intelligence-layer → dist/figma-intelligence-layer}/package.json +0 -0
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
-
// Token Binder
|
|
3
|
-
// Central module that generates Figma Plugin API scripts to bind design-system
|
|
4
|
-
// variables to node properties. Used by Page Architect, Component Archaeologist,
|
|
5
|
-
// DS Scaffolder, and Intent Translator to enforce token binding.
|
|
6
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
7
|
-
|
|
8
|
-
import { Token } from "./types.js";
|
|
9
|
-
import { getDesignSystemTokens } from "./design-system-tokens.js";
|
|
10
|
-
import { getConceptForComponent, getRequiredTokenPaths } from "./concept-taxonomy.js";
|
|
11
|
-
|
|
12
|
-
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
13
|
-
|
|
14
|
-
export interface TokenBinding {
|
|
15
|
-
nodeVar: string; // JS variable name referencing the node in the script
|
|
16
|
-
field: string; // Figma field: "fills" | "strokes" | "paddingLeft" | "cornerRadius" etc.
|
|
17
|
-
fillIndex?: number; // For paint bindings (fills/strokes), the array index
|
|
18
|
-
variableId: string; // Figma variable ID (e.g. "VariableID:123:456")
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SemanticTokenMap {
|
|
22
|
-
[semanticRole: string]: string; // role → variable ID
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Semantic roles that map component types to the token groups they need
|
|
26
|
-
const COMPONENT_TOKEN_ROLES: Record<string, string[]> = {
|
|
27
|
-
Button: ["color/semantic/actions/primary/bg/default", "color/semantic/text/on-color", "radius/semantic/control/default", "space/semantic/inset/control/md", "opacity/semantic/disabled"],
|
|
28
|
-
Modal: ["color/semantic/surface/overlay", "color/semantic/border/default", "radius/semantic/surface/default", "color/semantic/text/primary", "elevation/semantic/shadow/lg", "z-index/semantic/modal"],
|
|
29
|
-
Card: ["color/semantic/surface/raised", "color/semantic/border/default", "radius/semantic/surface/default", "color/semantic/text/primary", "color/semantic/text/secondary", "elevation/semantic/shadow/sm"],
|
|
30
|
-
Input: ["color/semantic/field/bg/default", "color/semantic/field/border/default", "radius/semantic/field/default", "color/semantic/text/primary", "color/semantic/text/disabled", "border-width/semantic/thin"],
|
|
31
|
-
Select: ["color/semantic/field/bg/default", "color/semantic/field/border/default", "radius/semantic/field/default", "color/semantic/text/primary", "border-width/semantic/thin"],
|
|
32
|
-
Checkbox: ["color/semantic/field/bg/default", "color/semantic/border/default", "color/semantic/text/primary"],
|
|
33
|
-
Toggle: ["color/semantic/border/default", "color/semantic/surface/default", "color/semantic/actions/primary/bg/default"],
|
|
34
|
-
Radio: ["color/semantic/field/bg/default", "color/semantic/border/default", "color/semantic/text/primary"],
|
|
35
|
-
Toast: ["color/semantic/feedback/success/bg", "color/semantic/feedback/success/text", "radius/semantic/control/default", "elevation/semantic/shadow/md", "z-index/semantic/toast"],
|
|
36
|
-
NavBar: ["color/semantic/surface/default", "color/semantic/border/subtle", "color/semantic/text/primary", "elevation/semantic/shadow/xs"],
|
|
37
|
-
Table: ["color/semantic/surface/default", "color/semantic/border/default", "color/semantic/text/primary", "color/semantic/surface/subtle"],
|
|
38
|
-
Avatar: ["color/semantic/surface/subtle", "radius/semantic/pill"],
|
|
39
|
-
Badge: ["color/semantic/actions/primary/bg/default", "color/semantic/text/on-color", "radius/semantic/pill"],
|
|
40
|
-
Tooltip: ["color/semantic/surface/inverse", "color/semantic/text/inverse", "elevation/semantic/shadow/md", "z-index/semantic/tooltip"],
|
|
41
|
-
Tabs: ["color/semantic/border/subtle", "color/semantic/text/primary", "color/semantic/actions/primary/bg/default"],
|
|
42
|
-
Breadcrumb: ["color/semantic/text/primary", "color/semantic/text/tertiary", "color/semantic/actions/primary/bg/default"],
|
|
43
|
-
Tag: ["color/semantic/surface/subtle", "color/semantic/border/default", "color/semantic/text/primary"],
|
|
44
|
-
Heading: ["color/semantic/text/primary"],
|
|
45
|
-
Link: ["color/semantic/actions/primary/bg/default"],
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// ─── Token resolution ────────────────────────────────────────────────────────
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Look up a Figma variable ID by token name from the available tokens.
|
|
52
|
-
* Supports partial matching: "color/semantic/primary" matches token named
|
|
53
|
-
* "color/semantic/primary" or "Brand Tokens/color/semantic/primary".
|
|
54
|
-
*/
|
|
55
|
-
export function resolveTokenId(tokenName: string, tokens: Token[]): string | null {
|
|
56
|
-
// Exact match first
|
|
57
|
-
const exact = tokens.find((t) => t.name === tokenName);
|
|
58
|
-
if (exact) return exact.id;
|
|
59
|
-
|
|
60
|
-
// Suffix match (token name ends with the requested name)
|
|
61
|
-
const suffix = tokens.find((t) => t.name.endsWith(`/${tokenName}`) || t.name.endsWith(tokenName));
|
|
62
|
-
if (suffix) return suffix.id;
|
|
63
|
-
|
|
64
|
-
// Normalized comparison (strip slashes and compare lowercase)
|
|
65
|
-
const normalizedTarget = tokenName.toLowerCase().replace(/[\/\-_]/g, "");
|
|
66
|
-
const normalized = tokens.find((t) => {
|
|
67
|
-
const n = t.name.toLowerCase().replace(/[\/\-_]/g, "");
|
|
68
|
-
return n === normalizedTarget || n.endsWith(normalizedTarget);
|
|
69
|
-
});
|
|
70
|
-
if (normalized) return normalized.id;
|
|
71
|
-
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Build a map of semantic role → variable ID from the available tokens.
|
|
77
|
-
* Used by tools that need to resolve multiple token references at once.
|
|
78
|
-
*/
|
|
79
|
-
export function buildTokenIdMap(tokens: Token[]): SemanticTokenMap {
|
|
80
|
-
const map: SemanticTokenMap = {};
|
|
81
|
-
|
|
82
|
-
for (const token of tokens) {
|
|
83
|
-
// Index by full name
|
|
84
|
-
map[token.name] = token.id;
|
|
85
|
-
|
|
86
|
-
// Also index by the last segment for quick lookup
|
|
87
|
-
const parts = token.name.split("/");
|
|
88
|
-
if (parts.length > 1) {
|
|
89
|
-
const shortName = parts.slice(-2).join("/");
|
|
90
|
-
if (!map[shortName]) {
|
|
91
|
-
map[shortName] = token.id;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return map;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Resolve which token names are relevant for a given component type.
|
|
101
|
-
* Tries static map first, then concept taxonomy, then defaults.
|
|
102
|
-
*/
|
|
103
|
-
export function getTokenRolesForComponent(componentType: string): string[] {
|
|
104
|
-
// Try exact match in static map first (hand-tuned, highest quality)
|
|
105
|
-
if (COMPONENT_TOKEN_ROLES[componentType]) {
|
|
106
|
-
return COMPONENT_TOKEN_ROLES[componentType];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Try case-insensitive match in static map
|
|
110
|
-
const lower = componentType.toLowerCase();
|
|
111
|
-
for (const [key, roles] of Object.entries(COMPONENT_TOKEN_ROLES)) {
|
|
112
|
-
if (key.toLowerCase() === lower) return roles;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Try concept taxonomy (covers all components via typicalForms mapping)
|
|
116
|
-
const concept = getConceptForComponent(componentType);
|
|
117
|
-
if (concept) {
|
|
118
|
-
return getRequiredTokenPaths(concept.id);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Default roles for unknown components
|
|
122
|
-
return ["color/surface/default", "color/text/primary", "color/border/default"];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Given a component type and available tokens, resolve the relevant token names
|
|
127
|
-
* to their variable IDs.
|
|
128
|
-
*/
|
|
129
|
-
export function resolveTokenRefsForComponent(
|
|
130
|
-
componentType: string,
|
|
131
|
-
tokens: Token[]
|
|
132
|
-
): string[] {
|
|
133
|
-
const roles = getTokenRolesForComponent(componentType);
|
|
134
|
-
const resolved: string[] = [];
|
|
135
|
-
|
|
136
|
-
for (const role of roles) {
|
|
137
|
-
const id = resolveTokenId(role, tokens);
|
|
138
|
-
if (id) {
|
|
139
|
-
// Return the token name (not the ID) for the tokenRefs field
|
|
140
|
-
const token = tokens.find((t) => t.id === id);
|
|
141
|
-
if (token) resolved.push(token.name);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return resolved;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// ─── Script generators ───────────────────────────────────────────────────────
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Generate a Figma Plugin API script line that binds a color variable
|
|
152
|
-
* to a paint fill on a node.
|
|
153
|
-
*
|
|
154
|
-
* Example output:
|
|
155
|
-
* const v = await figma.variables.getVariableByIdAsync("VariableID:1:2");
|
|
156
|
-
* if (v) node.setBoundVariable('fills', 0, v.id);
|
|
157
|
-
*/
|
|
158
|
-
export function bindColorScript(
|
|
159
|
-
nodeVar: string,
|
|
160
|
-
fillIndex: number,
|
|
161
|
-
variableId: string,
|
|
162
|
-
paintType: "fills" | "strokes" = "fills"
|
|
163
|
-
): string {
|
|
164
|
-
const varName = `__v_${fillIndex}_${paintType}`;
|
|
165
|
-
return `
|
|
166
|
-
{
|
|
167
|
-
const ${varName} = await figma.variables.getVariableByIdAsync(${JSON.stringify(variableId)});
|
|
168
|
-
if (${varName} && ${nodeVar}.${paintType} && ${nodeVar}.${paintType}.length > ${fillIndex}) {
|
|
169
|
-
const paints = [...${nodeVar}.${paintType}];
|
|
170
|
-
paints[${fillIndex}] = figma.variables.setBoundVariableForPaint(paints[${fillIndex}], 'color', ${varName});
|
|
171
|
-
${nodeVar}.${paintType} = paints;
|
|
172
|
-
}
|
|
173
|
-
}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Generate a Figma Plugin API script line that binds a float variable
|
|
178
|
-
* to a node property (spacing, radius, etc.).
|
|
179
|
-
*
|
|
180
|
-
* Example output:
|
|
181
|
-
* const v = await figma.variables.getVariableByIdAsync("VariableID:1:2");
|
|
182
|
-
* if (v) node.setBoundVariable('paddingLeft', v.id);
|
|
183
|
-
*/
|
|
184
|
-
export function bindFloatScript(
|
|
185
|
-
nodeVar: string,
|
|
186
|
-
field: string,
|
|
187
|
-
variableId: string
|
|
188
|
-
): string {
|
|
189
|
-
const safeField = field.replace(/[^a-zA-Z0-9_]/g, "");
|
|
190
|
-
const varName = `__v_${safeField}`;
|
|
191
|
-
return `
|
|
192
|
-
{
|
|
193
|
-
const ${varName} = await figma.variables.getVariableByIdAsync(${JSON.stringify(variableId)});
|
|
194
|
-
if (${varName}) ${nodeVar}.setBoundVariable('${field}', ${varName}.id);
|
|
195
|
-
}`;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Build a complete binding script for a single node, applying multiple
|
|
200
|
-
* token bindings. Returns empty string if no bindings.
|
|
201
|
-
*/
|
|
202
|
-
export function buildBindingScript(
|
|
203
|
-
nodeId: string,
|
|
204
|
-
bindings: TokenBinding[]
|
|
205
|
-
): string {
|
|
206
|
-
if (bindings.length === 0) return "";
|
|
207
|
-
|
|
208
|
-
const lines: string[] = [];
|
|
209
|
-
|
|
210
|
-
for (const binding of bindings) {
|
|
211
|
-
if (binding.field === "fills" || binding.field === "strokes") {
|
|
212
|
-
lines.push(
|
|
213
|
-
bindColorScript(
|
|
214
|
-
binding.nodeVar,
|
|
215
|
-
binding.fillIndex ?? 0,
|
|
216
|
-
binding.variableId,
|
|
217
|
-
binding.field as "fills" | "strokes"
|
|
218
|
-
)
|
|
219
|
-
);
|
|
220
|
-
} else {
|
|
221
|
-
lines.push(
|
|
222
|
-
bindFloatScript(binding.nodeVar, binding.field, binding.variableId)
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return `
|
|
228
|
-
// ── Token bindings ──
|
|
229
|
-
{
|
|
230
|
-
const __bindTarget = await figma.getNodeByIdAsync(${JSON.stringify(nodeId)});
|
|
231
|
-
if (__bindTarget) {
|
|
232
|
-
const ${bindings[0]?.nodeVar ?? "node"} = __bindTarget;
|
|
233
|
-
${lines.join("\n ")}
|
|
234
|
-
}
|
|
235
|
-
}`;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Build a batch binding script that binds variables to multiple nodes
|
|
240
|
-
* in a single execute call. Designed for use via bridge.execute().
|
|
241
|
-
*/
|
|
242
|
-
export function buildBatchBindingScript(
|
|
243
|
-
bindings: Array<{ nodeId: string; field: string; variableId: string; fillIndex?: number }>
|
|
244
|
-
): string {
|
|
245
|
-
if (bindings.length === 0) return "";
|
|
246
|
-
|
|
247
|
-
const bindingData = JSON.stringify(bindings);
|
|
248
|
-
|
|
249
|
-
return `
|
|
250
|
-
(async () => {
|
|
251
|
-
const bindings = ${bindingData};
|
|
252
|
-
let bound = 0;
|
|
253
|
-
|
|
254
|
-
for (const b of bindings) {
|
|
255
|
-
const node = await figma.getNodeByIdAsync(b.nodeId);
|
|
256
|
-
if (!node) continue;
|
|
257
|
-
|
|
258
|
-
const variable = await figma.variables.getVariableByIdAsync(b.variableId);
|
|
259
|
-
if (!variable) continue;
|
|
260
|
-
|
|
261
|
-
if (b.field === 'fills' || b.field === 'strokes') {
|
|
262
|
-
const idx = b.fillIndex ?? 0;
|
|
263
|
-
if (node[b.field] && node[b.field].length > idx) {
|
|
264
|
-
const paints = [...node[b.field]];
|
|
265
|
-
paints[idx] = figma.variables.setBoundVariableForPaint(paints[idx], 'color', variable);
|
|
266
|
-
node[b.field] = paints;
|
|
267
|
-
bound++;
|
|
268
|
-
}
|
|
269
|
-
} else {
|
|
270
|
-
try {
|
|
271
|
-
node.setBoundVariable(b.field, variable.id);
|
|
272
|
-
bound++;
|
|
273
|
-
} catch (e) { /* skip unsupported fields */ }
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return { bound, total: bindings.length };
|
|
278
|
-
})();
|
|
279
|
-
`.trim();
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// ─── Palette resolution ──────────────────────────────────────────────────────
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Resolve a design palette from tokens, returning both the RGB values (for
|
|
286
|
-
* immediate use in fills) and the variable IDs (for binding). Falls back to
|
|
287
|
-
* hardcoded values if no tokens are found.
|
|
288
|
-
*/
|
|
289
|
-
export interface ResolvedPalette {
|
|
290
|
-
primary: { rgb: string; variableId: string | null };
|
|
291
|
-
primaryText: { rgb: string; variableId: string | null };
|
|
292
|
-
surface: { rgb: string; variableId: string | null };
|
|
293
|
-
border: { rgb: string; variableId: string | null };
|
|
294
|
-
muted: { rgb: string; variableId: string | null };
|
|
295
|
-
accent: { rgb: string; variableId: string | null };
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
interface PaletteMapping {
|
|
299
|
-
role: keyof ResolvedPalette;
|
|
300
|
-
tokenNames: string[]; // Try these token names in order
|
|
301
|
-
fallbackRgb: string; // Figma RGB object literal as string
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const PALETTE_MAPPINGS: PaletteMapping[] = [
|
|
305
|
-
{ role: "primary", tokenNames: ["color/semantic/actions/primary/bg/default", "color/semantic/primary", "color/primary/500"], fallbackRgb: "{ r: 0.09, g: 0.09, b: 0.09 }" },
|
|
306
|
-
{ role: "primaryText", tokenNames: ["color/semantic/text/on-color", "color/text/on-primary", "color/semantic/primary-on"], fallbackRgb: "{ r: 1, g: 1, b: 1 }" },
|
|
307
|
-
{ role: "surface", tokenNames: ["color/semantic/surface/default", "color/surface/default", "color/neutral/50"], fallbackRgb: "{ r: 0.98, g: 0.98, b: 0.99 }" },
|
|
308
|
-
{ role: "border", tokenNames: ["color/semantic/border/default", "color/border/default", "color/neutral/200"], fallbackRgb: "{ r: 0.90, g: 0.91, b: 0.93 }" },
|
|
309
|
-
{ role: "muted", tokenNames: ["color/semantic/text/secondary", "color/text/secondary", "color/text/disabled"], fallbackRgb: "{ r: 0.45, g: 0.45, b: 0.50 }" },
|
|
310
|
-
{ role: "accent", tokenNames: ["color/semantic/actions/primary/bg/default", "color/semantic/primary", "color/primary/500"], fallbackRgb: "{ r: 0.22, g: 0.35, b: 0.96 }" },
|
|
311
|
-
];
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Convert a Figma color value (from a token) to an RGB string literal
|
|
315
|
-
* for use in generated scripts.
|
|
316
|
-
*/
|
|
317
|
-
function tokenValueToRgbString(value: unknown): string | null {
|
|
318
|
-
if (!value || typeof value !== "object") return null;
|
|
319
|
-
const v = value as Record<string, number>;
|
|
320
|
-
if (typeof v.r !== "number" || typeof v.g !== "number" || typeof v.b !== "number") return null;
|
|
321
|
-
return `{ r: ${v.r.toFixed(3)}, g: ${v.g.toFixed(3)}, b: ${v.b.toFixed(3)} }`;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Resolve a design palette.
|
|
326
|
-
*
|
|
327
|
-
* When a design system is selected (dsId is provided), its tokens are the
|
|
328
|
-
* **authoritative** source — Figma file tokens are ignored entirely.
|
|
329
|
-
* When no DS is selected (dsId is null), file tokens are used as before.
|
|
330
|
-
*/
|
|
331
|
-
export function resolveDesignPalette(tokens: Token[], dsId?: string | null): ResolvedPalette {
|
|
332
|
-
// DS tokens are authoritative when a design system is selected
|
|
333
|
-
const effectiveTokens = dsId ? getDesignSystemTokens(dsId) : tokens;
|
|
334
|
-
|
|
335
|
-
const palette = {} as ResolvedPalette;
|
|
336
|
-
|
|
337
|
-
for (const mapping of PALETTE_MAPPINGS) {
|
|
338
|
-
let resolved = false;
|
|
339
|
-
|
|
340
|
-
for (const tokenName of mapping.tokenNames) {
|
|
341
|
-
const token = effectiveTokens.find(
|
|
342
|
-
(t) => t.type === "COLOR" && (t.name === tokenName || t.name.endsWith(`/${tokenName}`))
|
|
343
|
-
);
|
|
344
|
-
if (token) {
|
|
345
|
-
const rgb = tokenValueToRgbString(token.value) ?? mapping.fallbackRgb;
|
|
346
|
-
palette[mapping.role] = { rgb, variableId: token.id };
|
|
347
|
-
resolved = true;
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if (!resolved) {
|
|
353
|
-
palette[mapping.role] = { rgb: mapping.fallbackRgb, variableId: null };
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return palette;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Resolve a float token (spacing, radius) value and variable ID.
|
|
362
|
-
* Returns the numeric value and optionally the variable ID for binding.
|
|
363
|
-
*/
|
|
364
|
-
export function resolveFloatToken(
|
|
365
|
-
tokenName: string,
|
|
366
|
-
tokens: Token[],
|
|
367
|
-
fallback: number
|
|
368
|
-
): { value: number; variableId: string | null } {
|
|
369
|
-
const token = tokens.find(
|
|
370
|
-
(t) => t.type === "FLOAT" && (t.name === tokenName || t.name.endsWith(`/${tokenName}`))
|
|
371
|
-
);
|
|
372
|
-
if (token && typeof token.value === "number") {
|
|
373
|
-
return { value: token.value, variableId: token.id };
|
|
374
|
-
}
|
|
375
|
-
return { value: fallback, variableId: null };
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// ─── Multi-mode variable binding ────────────────────────────────────────────
|
|
379
|
-
|
|
380
|
-
export interface MultiModeBinding {
|
|
381
|
-
nodeId: string;
|
|
382
|
-
field: string; // "fills" | "strokes" | "paddingLeft" | "cornerRadius" etc.
|
|
383
|
-
fillIndex?: number;
|
|
384
|
-
/** Variable ID of a semantic alias variable that already has Light/Dark values */
|
|
385
|
-
semanticVariableId: string;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Build a script that explicitly sets the *variable* mode on a frame and its
|
|
390
|
-
* descendants, ensuring components switch between Light/Dark (or any modes).
|
|
391
|
-
*
|
|
392
|
-
* Figma's mode switching works at the frame level via `setExplicitVariableModeForCollection`.
|
|
393
|
-
* This function:
|
|
394
|
-
* 1. Binds semantic variables to node properties (same as single-mode binding)
|
|
395
|
-
* 2. Sets the explicit variable mode on a container frame so all children
|
|
396
|
-
* resolve the correct mode values automatically
|
|
397
|
-
*
|
|
398
|
-
* Usage: Call this after creating variables with ds-variables (which creates
|
|
399
|
-
* Light/Dark mode values). The semantic variable already has mode-specific
|
|
400
|
-
* values — this script binds it to nodes and sets which mode is active.
|
|
401
|
-
*/
|
|
402
|
-
export function buildMultiModeBindingScript(
|
|
403
|
-
bindings: MultiModeBinding[],
|
|
404
|
-
/** Frame node ID to set the explicit mode on (typically the root component frame) */
|
|
405
|
-
targetFrameId: string,
|
|
406
|
-
/** Collection ID the semantic variables belong to */
|
|
407
|
-
collectionId: string,
|
|
408
|
-
/** Mode ID to activate (e.g. the Dark mode ID) */
|
|
409
|
-
activeModeId: string
|
|
410
|
-
): string {
|
|
411
|
-
if (bindings.length === 0 && !targetFrameId) return "";
|
|
412
|
-
|
|
413
|
-
const bindingData = JSON.stringify(bindings);
|
|
414
|
-
|
|
415
|
-
return `
|
|
416
|
-
(async () => {
|
|
417
|
-
const bindings = ${bindingData};
|
|
418
|
-
let bound = 0;
|
|
419
|
-
const errors = [];
|
|
420
|
-
|
|
421
|
-
// Step 1: Bind semantic variables to node properties
|
|
422
|
-
for (const b of bindings) {
|
|
423
|
-
try {
|
|
424
|
-
const node = await figma.getNodeByIdAsync(b.nodeId);
|
|
425
|
-
if (!node) { errors.push('Node not found: ' + b.nodeId); continue; }
|
|
426
|
-
|
|
427
|
-
const variable = await figma.variables.getVariableByIdAsync(b.semanticVariableId);
|
|
428
|
-
if (!variable) { errors.push('Variable not found: ' + b.semanticVariableId); continue; }
|
|
429
|
-
|
|
430
|
-
if (b.field === 'fills' || b.field === 'strokes') {
|
|
431
|
-
const idx = b.fillIndex ?? 0;
|
|
432
|
-
if (node[b.field] && node[b.field].length > idx) {
|
|
433
|
-
const paints = [...node[b.field]];
|
|
434
|
-
paints[idx] = figma.variables.setBoundVariableForPaint(paints[idx], 'color', variable);
|
|
435
|
-
node[b.field] = paints;
|
|
436
|
-
bound++;
|
|
437
|
-
}
|
|
438
|
-
} else {
|
|
439
|
-
node.setBoundVariable(b.field, variable.id);
|
|
440
|
-
bound++;
|
|
441
|
-
}
|
|
442
|
-
} catch (e) {
|
|
443
|
-
errors.push('Bind error: ' + (e.message || e));
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// Step 2: Set the explicit variable mode on the target frame
|
|
448
|
-
let modeSet = false;
|
|
449
|
-
if (${JSON.stringify(targetFrameId)} && ${JSON.stringify(collectionId)} && ${JSON.stringify(activeModeId)}) {
|
|
450
|
-
try {
|
|
451
|
-
const frame = await figma.getNodeByIdAsync(${JSON.stringify(targetFrameId)});
|
|
452
|
-
if (frame && 'setExplicitVariableModeForCollection' in frame) {
|
|
453
|
-
frame.setExplicitVariableModeForCollection(${JSON.stringify(collectionId)}, ${JSON.stringify(activeModeId)});
|
|
454
|
-
modeSet = true;
|
|
455
|
-
}
|
|
456
|
-
} catch (e) {
|
|
457
|
-
errors.push('Mode set error: ' + (e.message || e));
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return { bound, total: bindings.length, modeSet, errors: errors.length > 0 ? errors : undefined };
|
|
462
|
-
})();
|
|
463
|
-
`.trim();
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Build a script that resolves ALL modes for a collection and returns them,
|
|
468
|
-
* so callers can pick which mode ID to use for switching.
|
|
469
|
-
*/
|
|
470
|
-
export function buildListModesScript(collectionId: string): string {
|
|
471
|
-
return `
|
|
472
|
-
(async () => {
|
|
473
|
-
const col = await figma.variables.getVariableCollectionByIdAsync(${JSON.stringify(collectionId)});
|
|
474
|
-
if (!col) return { error: 'Collection not found' };
|
|
475
|
-
return {
|
|
476
|
-
collectionId: col.id,
|
|
477
|
-
collectionName: col.name,
|
|
478
|
-
modes: col.modes.map(m => ({ modeId: m.modeId, name: m.name })),
|
|
479
|
-
variableCount: col.variableIds.length,
|
|
480
|
-
};
|
|
481
|
-
})();
|
|
482
|
-
`.trim();
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* Build a script that switches a frame (and all its children) to a different
|
|
487
|
-
* variable mode. This is the simplest "theme switch" operation.
|
|
488
|
-
*/
|
|
489
|
-
export function buildModeSwitchScript(
|
|
490
|
-
frameId: string,
|
|
491
|
-
collectionId: string,
|
|
492
|
-
modeId: string
|
|
493
|
-
): string {
|
|
494
|
-
return `
|
|
495
|
-
(async () => {
|
|
496
|
-
const frame = await figma.getNodeByIdAsync(${JSON.stringify(frameId)});
|
|
497
|
-
if (!frame) return { error: 'Frame not found: ${frameId}' };
|
|
498
|
-
if (!('setExplicitVariableModeForCollection' in frame)) {
|
|
499
|
-
return { error: 'Node does not support explicit variable modes (must be a frame-like node)' };
|
|
500
|
-
}
|
|
501
|
-
frame.setExplicitVariableModeForCollection(${JSON.stringify(collectionId)}, ${JSON.stringify(modeId)});
|
|
502
|
-
return { success: true, frameId: frame.id, frameName: frame.name, collectionId: ${JSON.stringify(collectionId)}, modeId: ${JSON.stringify(modeId)} };
|
|
503
|
-
})();
|
|
504
|
-
`.trim();
|
|
505
|
-
}
|