@sarjallab09/figma-intelligence 1.0.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 +26 -0
- package/README.md +327 -0
- package/bin/cli.js +859 -0
- package/design-bridge/.env.example +5 -0
- package/design-bridge/bridge.js +196 -0
- package/design-bridge/lib/assets.js +367 -0
- package/design-bridge/lib/prompt.js +85 -0
- package/design-bridge/lib/server.js +66 -0
- package/design-bridge/lib/stitch.js +37 -0
- package/design-bridge/lib/tokens.js +82 -0
- package/design-bridge/package-lock.json +579 -0
- package/design-bridge/package.json +19 -0
- package/figma-bridge-plugin/README.md +97 -0
- package/figma-bridge-plugin/anthropic-chat-runner.js +192 -0
- package/figma-bridge-plugin/bridge-relay.js +2363 -0
- package/figma-bridge-plugin/chat-runner.js +459 -0
- package/figma-bridge-plugin/code.js +1528 -0
- package/figma-bridge-plugin/codex-runner.js +505 -0
- package/figma-bridge-plugin/component-schemas.js +110 -0
- package/figma-bridge-plugin/content-context.js +869 -0
- package/figma-bridge-plugin/create-button.js +216 -0
- package/figma-bridge-plugin/gemini-cli-runner.js +291 -0
- package/figma-bridge-plugin/gemini-runner.js +187 -0
- package/figma-bridge-plugin/html-to-figma.js +927 -0
- package/figma-bridge-plugin/knowledge-hub/.gitkeep +0 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/anatomy-spec.md +159 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/api-spec.md +162 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/color-spec.md +148 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/full-spec-template.md +314 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/property-spec.md +175 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/screen-reader-spec.md +180 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/structure-spec.md +165 -0
- package/figma-bridge-plugin/manifest.json +21 -0
- package/figma-bridge-plugin/package-lock.json +1936 -0
- package/figma-bridge-plugin/package.json +20 -0
- package/figma-bridge-plugin/perplexity-runner.js +188 -0
- package/figma-bridge-plugin/references/SKILL.md +178 -0
- package/figma-bridge-plugin/references/anatomy-spec.md +159 -0
- package/figma-bridge-plugin/references/api-spec.md +162 -0
- package/figma-bridge-plugin/references/color-spec.md +148 -0
- package/figma-bridge-plugin/references/full-spec-template.md +314 -0
- package/figma-bridge-plugin/references/property-spec.md +175 -0
- package/figma-bridge-plugin/references/screen-reader-spec.md +180 -0
- package/figma-bridge-plugin/references/structure-spec.md +165 -0
- package/figma-bridge-plugin/shared-prompt-config.js +604 -0
- package/figma-bridge-plugin/spec-helpers/build-table.js +269 -0
- package/figma-bridge-plugin/spec-helpers/classify-elements.js +189 -0
- package/figma-bridge-plugin/spec-helpers/index.js +35 -0
- package/figma-bridge-plugin/spec-helpers/parse-figma-link.js +49 -0
- package/figma-bridge-plugin/spec-helpers/position-markers.js +158 -0
- package/figma-bridge-plugin/stitch-auth.js +322 -0
- package/figma-bridge-plugin/stitch-runner.js +1427 -0
- package/figma-bridge-plugin/token-resolver.js +107 -0
- package/figma-bridge-plugin/ui.html +4467 -0
- package/figma-intelligence-layer/.env.example +39 -0
- package/figma-intelligence-layer/docs/local-image-generation.md +60 -0
- package/figma-intelligence-layer/examples/comfyui-workflow-template.example.json +101 -0
- package/figma-intelligence-layer/jest.config.js +14 -0
- package/figma-intelligence-layer/mcp-config.json +19 -0
- package/figma-intelligence-layer/package-lock.json +5892 -0
- package/figma-intelligence-layer/package.json +48 -0
- package/figma-intelligence-layer/scripts/setup-comfyui-local.sh +67 -0
- package/figma-intelligence-layer/scripts/start-comfyui.sh +33 -0
- package/figma-intelligence-layer/src/index.ts +2233 -0
- package/figma-intelligence-layer/src/shared/auto-layout-validator.ts +404 -0
- package/figma-intelligence-layer/src/shared/cache.ts +187 -0
- package/figma-intelligence-layer/src/shared/color-operations.ts +533 -0
- package/figma-intelligence-layer/src/shared/color-utils.ts +138 -0
- package/figma-intelligence-layer/src/shared/component-script-builder.ts +413 -0
- package/figma-intelligence-layer/src/shared/component-templates.ts +2767 -0
- package/figma-intelligence-layer/src/shared/concept-taxonomy.ts +694 -0
- package/figma-intelligence-layer/src/shared/decision-log.ts +128 -0
- package/figma-intelligence-layer/src/shared/design-system-context.ts +568 -0
- package/figma-intelligence-layer/src/shared/design-system-intelligence.ts +131 -0
- package/figma-intelligence-layer/src/shared/design-system-matcher.ts +184 -0
- package/figma-intelligence-layer/src/shared/design-system-normalizers.ts +196 -0
- package/figma-intelligence-layer/src/shared/design-system-tokens.ts +295 -0
- package/figma-intelligence-layer/src/shared/dtcg-validator.ts +530 -0
- package/figma-intelligence-layer/src/shared/enrichment-pipeline.ts +671 -0
- package/figma-intelligence-layer/src/shared/figma-bridge.ts +1408 -0
- package/figma-intelligence-layer/src/shared/font-config.ts +126 -0
- package/figma-intelligence-layer/src/shared/icon-catalog.ts +360 -0
- package/figma-intelligence-layer/src/shared/icon-fetch.ts +80 -0
- package/figma-intelligence-layer/src/shared/prototype-script-builder.ts +162 -0
- package/figma-intelligence-layer/src/shared/response-compression.ts +440 -0
- package/figma-intelligence-layer/src/shared/semantic-token-catalog.ts +324 -0
- package/figma-intelligence-layer/src/shared/token-binder.ts +505 -0
- package/figma-intelligence-layer/src/shared/token-math.ts +427 -0
- package/figma-intelligence-layer/src/shared/token-naming.ts +468 -0
- package/figma-intelligence-layer/src/shared/token-utils.ts +420 -0
- package/figma-intelligence-layer/src/shared/types.ts +346 -0
- package/figma-intelligence-layer/src/shared/typography-presets.ts +94 -0
- package/figma-intelligence-layer/src/shared/unsplash.ts +165 -0
- package/figma-intelligence-layer/src/shared/vision-client.ts +607 -0
- package/figma-intelligence-layer/src/shared/vision-provider-anthropic.ts +334 -0
- package/figma-intelligence-layer/src/shared/vision-provider-openai.ts +446 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-handler.ts +782 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-renderer.ts +496 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotation-kit.ts +230 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/colorblind-sim.ts +66 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/index.ts +810 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-analyzer.ts +1191 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-figma-page.ts +1346 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-handler.ts +148 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-figma-page.ts +499 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-report.ts +910 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-checker.ts +989 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-criteria.ts +1160 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/design-from-ref/index.ts +424 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/component-recognizer.ts +38 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/ds-matcher.ts +111 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/font-matcher.ts +114 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/icon-resolver.ts +103 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/index.ts +1060 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/layout-segmenter.ts +18 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/token-inferencer.ts +39 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/vision-pipeline.ts +58 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/sketch-to-design/index.ts +298 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/visual-audit/index.ts +197 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/component-audit/index.ts +494 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/intent-translator/index.ts +356 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/container-patterns.ts +123 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/index.ts +663 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/built-in-rules.yaml +56 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/index.ts +614 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/rule-engine.ts +113 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/color-theory.ts +178 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/index.ts +470 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/index.ts +429 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/token-override-maps.ts +226 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/ai-image-insert/index.ts +535 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/index.ts +660 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/pattern-fingerprints.ts +209 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/composition-builder/index.ts +540 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/figma-animated-build.ts +391 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/index.ts +2019 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/screen-templates.ts +131 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/prototype-map/index.ts +381 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/prototype-wire/index.ts +565 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/swarm-build/index.ts +764 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/system-drift/index.ts +535 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/unsplash-search/index.ts +84 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/url-to-frame/index.ts +401 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/css-animations.ts +68 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/framer-motion.ts +78 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/swift-animations.ts +93 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/index.ts +596 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/ci-check/index.ts +462 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/export-tokens/index.ts +1470 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/generate-component-code/index.ts +829 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/handoff-spec/index.ts +702 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/icon-library-sync/index.ts +483 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/index.ts +501 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/storybook-parser.ts +106 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/watch-docs/index.ts +676 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/webhook-listener/index.ts +560 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/apg-doc/index.ts +1043 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/component-detection.ts +620 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/anatomy.ts +331 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/color-tokens.ts +77 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/properties.ts +54 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/snapshot.ts +287 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/spacing.ts +71 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/states.ts +43 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/typography.ts +71 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/index.ts +221 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/_default.ts +166 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/accordion.ts +232 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/alert.ts +234 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar-group.ts +270 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar.ts +249 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/badge.ts +231 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/banner.ts +293 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/breadcrumb.ts +240 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/button.ts +243 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/calendar.ts +307 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/card.ts +143 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/checkbox.ts +227 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/chip.ts +233 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/combobox.ts +282 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/datepicker.ts +276 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/divider.ts +223 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/drawer.ts +255 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/dropdown-menu.ts +289 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/empty-state.ts +261 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/file-uploader.ts +290 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/form.ts +265 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/grid.ts +238 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/icon.ts +255 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/index.ts +128 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-edit.ts +286 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-message.ts +255 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/input.ts +330 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/link.ts +247 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/list.ts +250 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/menu.ts +247 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/modal.ts +144 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navbar.ts +264 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navigation.ts +251 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/number-input.ts +261 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/pagination.ts +248 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/popover.ts +270 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/progress.ts +251 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/radio.ts +142 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/range-slider.ts +282 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/rating.ts +250 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/search.ts +258 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/segmented-control.ts +265 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/select.ts +319 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/skeleton.ts +256 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/slider.ts +232 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/spinner.ts +239 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/status-dot.ts +252 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/stepper.ts +270 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/table.ts +244 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tabs.ts +143 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tag.ts +243 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/textarea.ts +259 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/time-picker.ts +293 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toast.ts +144 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toggle.ts +289 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toolbar.ts +267 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tooltip.ts +232 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/treeview.ts +257 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/typography.ts +319 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/legacy-compat.ts +121 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/anatomy-diagram.ts +430 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/figma-page.ts +312 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/json.ts +129 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/markdown.ts +78 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/visual-doc.ts +2333 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/accessibility.ts +100 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/anatomy.ts +32 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/color-tokens.ts +59 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/content-guidance.ts +18 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/design-tokens.ts +53 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/interaction-rules.ts +19 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/overview.ts +91 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/properties-api.ts +71 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/qa-criteria.ts +19 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/related-components.ts +110 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/responsive.ts +19 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/size-specs.ts +67 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/spacing-structure.ts +58 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/state-specs.ts +79 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/states.ts +50 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/type-hierarchy.ts +33 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/typography.ts +55 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/usage-guidelines.ts +73 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/variants.ts +81 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/types.ts +409 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/index.ts +198 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/renderer.ts +701 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/types.ts +88 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/decision-log/index.ts +135 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/design-decision-log/index.ts +491 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-primitives/index.ts +416 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-scaffolder/index.ts +722 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-variables/index.ts +449 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/health-report/index.ts +393 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/index.ts +406 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/figma-page.ts +292 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/json.ts +24 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/markdown.ts +172 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/naming-guide.ts +409 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-analytics/index.ts +594 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-docs/index.ts +710 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-migrate/index.ts +458 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-naming/index.ts +134 -0
- package/figma-intelligence-layer/tests/apg-doc.test.ts +101 -0
- package/figma-intelligence-layer/tests/design-system-context.test.ts +152 -0
- package/figma-intelligence-layer/tests/design-system-matcher.test.ts +144 -0
- package/figma-intelligence-layer/tests/figma-bridge.test.ts +83 -0
- package/figma-intelligence-layer/tests/generate-image-and-insert.test.ts +56 -0
- package/figma-intelligence-layer/tests/screen-cloner-regression.test.ts +69 -0
- package/figma-intelligence-layer/tests/smoke.test.ts +174 -0
- package/figma-intelligence-layer/tests/spec-generator.test.ts +127 -0
- package/figma-intelligence-layer/tests/token-migrate.test.ts +21 -0
- package/figma-intelligence-layer/tests/token-naming.test.ts +30 -0
- package/figma-intelligence-layer/tsconfig.json +19 -0
- package/package.json +35 -0
- package/scripts/clean-existing-chunks.js +179 -0
- package/scripts/connect-ai-tool.js +490 -0
- package/scripts/convert-hub-pdfs.js +425 -0
- package/scripts/figma-mcp-status.js +349 -0
- package/scripts/register-codex-mcp.js +96 -0
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* figma_token_docs — Living token documentation generator
|
|
3
|
+
*
|
|
4
|
+
* Fetches all design tokens from the Figma bridge, organizes them by category,
|
|
5
|
+
* and generates documentation in multiple output formats (Figma, Markdown, JSON, HTML).
|
|
6
|
+
* Token data is never fabricated — all values come from actual Figma variables.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getBridge } from "../../../shared/figma-bridge.js";
|
|
10
|
+
|
|
11
|
+
// ─── Types ──────────────────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
export interface TokenDocsArgs {
|
|
14
|
+
outputFormat: "figma" | "markdown" | "json" | "html";
|
|
15
|
+
categories?: string[];
|
|
16
|
+
collectionFilter?: string;
|
|
17
|
+
includeVisualSwatches?: boolean;
|
|
18
|
+
includeUsageExamples?: boolean;
|
|
19
|
+
includeAliasChains?: boolean;
|
|
20
|
+
pageName?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TokenDocsResult {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
format: TokenDocsArgs["outputFormat"];
|
|
26
|
+
tokenCount: number;
|
|
27
|
+
collectionCount: number;
|
|
28
|
+
categoryCount: number;
|
|
29
|
+
output: string | TokenDocsJsonOutput;
|
|
30
|
+
notes: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface RawVariable {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
resolvedType?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
valuesByMode?: Record<string, unknown>;
|
|
40
|
+
aliasOf?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface RawCollection {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
modes: Array<{ modeId: string; name: string }>;
|
|
47
|
+
variables: RawVariable[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface CategorizedToken {
|
|
51
|
+
name: string;
|
|
52
|
+
id: string;
|
|
53
|
+
collection: string;
|
|
54
|
+
resolvedType: string;
|
|
55
|
+
description: string;
|
|
56
|
+
values: Record<string, unknown>;
|
|
57
|
+
aliasOf?: string;
|
|
58
|
+
aliasChain?: string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface TokenCategory {
|
|
62
|
+
label: string;
|
|
63
|
+
tokens: CategorizedToken[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface TokenDocsJsonOutput {
|
|
67
|
+
generatedAt: string;
|
|
68
|
+
totalTokens: number;
|
|
69
|
+
collections: string[];
|
|
70
|
+
categories: Record<string, {
|
|
71
|
+
count: number;
|
|
72
|
+
tokens: Array<{
|
|
73
|
+
name: string;
|
|
74
|
+
resolvedType: string;
|
|
75
|
+
description: string;
|
|
76
|
+
values: Record<string, unknown>;
|
|
77
|
+
aliasOf?: string;
|
|
78
|
+
aliasChain?: string[];
|
|
79
|
+
}>;
|
|
80
|
+
}>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ─── Category Definitions ───────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
const CATEGORY_MATCHERS: Array<{ label: string; test: (name: string, type: string) => boolean }> = [
|
|
86
|
+
{ label: "Colors", test: (n, t) => t === "COLOR" || /color|fill|stroke|bg|background|foreground/i.test(n) },
|
|
87
|
+
{ label: "Spacing", test: (n, t) => t === "FLOAT" && /spacing|space|gap|padding|margin|inset/i.test(n) },
|
|
88
|
+
{ label: "Typography", test: (n, _) => /font|type|typography|text|letter-spacing|line-height/i.test(n) },
|
|
89
|
+
{ label: "Radius", test: (n, t) => t === "FLOAT" && /radius|corner|rounded/i.test(n) },
|
|
90
|
+
{ label: "Elevation", test: (n, _) => /elevation|shadow|box-shadow|drop-shadow/i.test(n) },
|
|
91
|
+
{ label: "Motion", test: (n, _) => /motion|animation|duration|easing|transition|delay/i.test(n) },
|
|
92
|
+
{ label: "Z-Index", test: (n, t) => t === "FLOAT" && /z-index|z-layer|layer/i.test(n) },
|
|
93
|
+
{ label: "Opacity", test: (n, t) => t === "FLOAT" && /opacity|alpha|transparency/i.test(n) },
|
|
94
|
+
{ label: "Border Width", test: (n, t) => t === "FLOAT" && /border-width|border-size|stroke-width/i.test(n) },
|
|
95
|
+
{ label: "Breakpoints", test: (n, t) => t === "FLOAT" && /breakpoint|screen|viewport/i.test(n) },
|
|
96
|
+
{ label: "Grid", test: (n, _) => /grid|column|gutter/i.test(n) },
|
|
97
|
+
{ label: "Density", test: (n, _) => /density|compact|comfortable|spacious/i.test(n) },
|
|
98
|
+
{ label: "Icon Sizes", test: (n, t) => t === "FLOAT" && /icon-size|icon-width|icon-height/i.test(n) },
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
const UNCATEGORIZED_LABEL = "Other";
|
|
102
|
+
|
|
103
|
+
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
function categorizeToken(name: string, type: string): string {
|
|
106
|
+
for (const matcher of CATEGORY_MATCHERS) {
|
|
107
|
+
if (matcher.test(name, type)) return matcher.label;
|
|
108
|
+
}
|
|
109
|
+
return UNCATEGORIZED_LABEL;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function formatColorValue(value: unknown): string {
|
|
113
|
+
if (typeof value === "string") return value;
|
|
114
|
+
if (value && typeof value === "object" && "r" in value) {
|
|
115
|
+
const c = value as { r: number; g: number; b: number; a?: number };
|
|
116
|
+
const r = Math.round(c.r * 255);
|
|
117
|
+
const g = Math.round(c.g * 255);
|
|
118
|
+
const b = Math.round(c.b * 255);
|
|
119
|
+
if (c.a !== undefined && c.a < 1) {
|
|
120
|
+
return `rgba(${r}, ${g}, ${b}, ${c.a.toFixed(2)})`;
|
|
121
|
+
}
|
|
122
|
+
return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`.toUpperCase();
|
|
123
|
+
}
|
|
124
|
+
return String(value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function formatValue(value: unknown, type: string): string {
|
|
128
|
+
if (value === null || value === undefined) return "—";
|
|
129
|
+
if (type === "COLOR") return formatColorValue(value);
|
|
130
|
+
if (typeof value === "object" && value !== null && "type" in value && (value as Record<string, unknown>).type === "VARIABLE_ALIAS") {
|
|
131
|
+
return `-> ${(value as unknown as { variableId: string }).variableId}`;
|
|
132
|
+
}
|
|
133
|
+
return String(value);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function resolveAliasChain(
|
|
137
|
+
variable: RawVariable,
|
|
138
|
+
allVariablesById: Map<string, RawVariable>,
|
|
139
|
+
maxDepth = 10
|
|
140
|
+
): string[] {
|
|
141
|
+
const chain: string[] = [];
|
|
142
|
+
let current = variable;
|
|
143
|
+
let depth = 0;
|
|
144
|
+
|
|
145
|
+
while (depth < maxDepth) {
|
|
146
|
+
const firstModeValue = current.valuesByMode
|
|
147
|
+
? Object.values(current.valuesByMode)[0]
|
|
148
|
+
: undefined;
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
firstModeValue &&
|
|
152
|
+
typeof firstModeValue === "object" &&
|
|
153
|
+
firstModeValue !== null &&
|
|
154
|
+
"type" in firstModeValue &&
|
|
155
|
+
(firstModeValue as Record<string, unknown>).type === "VARIABLE_ALIAS"
|
|
156
|
+
) {
|
|
157
|
+
const aliasId = (firstModeValue as unknown as { variableId: string }).variableId;
|
|
158
|
+
const target = allVariablesById.get(aliasId);
|
|
159
|
+
if (target) {
|
|
160
|
+
chain.push(target.name);
|
|
161
|
+
current = target;
|
|
162
|
+
depth++;
|
|
163
|
+
} else {
|
|
164
|
+
chain.push(`[unresolved: ${aliasId}]`);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return chain;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function todayStamp(): string {
|
|
176
|
+
const d = new Date();
|
|
177
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ─── Data Fetching & Organizing ─────────────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
async function fetchAndOrganizeTokens(
|
|
183
|
+
args: TokenDocsArgs
|
|
184
|
+
): Promise<{ categories: Map<string, TokenCategory>; collections: RawCollection[]; allTokenCount: number }> {
|
|
185
|
+
const bridge = await getBridge();
|
|
186
|
+
const raw = await bridge.getVariables(undefined, "full") as RawCollection[];
|
|
187
|
+
|
|
188
|
+
// Filter collections if requested
|
|
189
|
+
const collections = args.collectionFilter
|
|
190
|
+
? raw.filter((c) => c.name.toLowerCase().includes(args.collectionFilter!.toLowerCase()))
|
|
191
|
+
: raw;
|
|
192
|
+
|
|
193
|
+
// Build variable-by-id index for alias resolution
|
|
194
|
+
const allVariablesById = new Map<string, RawVariable>();
|
|
195
|
+
for (const col of raw) {
|
|
196
|
+
for (const v of col.variables) {
|
|
197
|
+
allVariablesById.set(v.id, v);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Organize tokens into categories
|
|
202
|
+
const categoryMap = new Map<string, TokenCategory>();
|
|
203
|
+
let allTokenCount = 0;
|
|
204
|
+
|
|
205
|
+
for (const collection of collections) {
|
|
206
|
+
const modeNames = collection.modes.map((m) => m.name);
|
|
207
|
+
|
|
208
|
+
for (const variable of collection.variables) {
|
|
209
|
+
const type = variable.resolvedType || variable.type || "STRING";
|
|
210
|
+
const category = categorizeToken(variable.name, type);
|
|
211
|
+
|
|
212
|
+
// Apply category filter if specified
|
|
213
|
+
if (args.categories && args.categories.length > 0) {
|
|
214
|
+
if (!args.categories.some((c) => c.toLowerCase() === category.toLowerCase())) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!categoryMap.has(category)) {
|
|
220
|
+
categoryMap.set(category, { label: category, tokens: [] });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Build mode values
|
|
224
|
+
const values: Record<string, unknown> = {};
|
|
225
|
+
if (variable.valuesByMode) {
|
|
226
|
+
const modeEntries = Object.entries(variable.valuesByMode);
|
|
227
|
+
for (let i = 0; i < modeEntries.length; i++) {
|
|
228
|
+
const modeName = modeNames[i] || modeEntries[i][0];
|
|
229
|
+
values[modeName] = modeEntries[i][1];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Resolve alias
|
|
234
|
+
let aliasOf: string | undefined;
|
|
235
|
+
let aliasChain: string[] | undefined;
|
|
236
|
+
const firstValue = variable.valuesByMode ? Object.values(variable.valuesByMode)[0] : undefined;
|
|
237
|
+
if (
|
|
238
|
+
firstValue &&
|
|
239
|
+
typeof firstValue === "object" &&
|
|
240
|
+
firstValue !== null &&
|
|
241
|
+
"type" in firstValue &&
|
|
242
|
+
(firstValue as Record<string, unknown>).type === "VARIABLE_ALIAS"
|
|
243
|
+
) {
|
|
244
|
+
const target = allVariablesById.get((firstValue as unknown as { variableId: string }).variableId);
|
|
245
|
+
aliasOf = target?.name || (firstValue as unknown as { variableId: string }).variableId;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (args.includeAliasChains) {
|
|
249
|
+
aliasChain = resolveAliasChain(variable, allVariablesById);
|
|
250
|
+
if (aliasChain.length === 0) aliasChain = undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
categoryMap.get(category)!.tokens.push({
|
|
254
|
+
name: variable.name,
|
|
255
|
+
id: variable.id,
|
|
256
|
+
collection: collection.name,
|
|
257
|
+
resolvedType: type,
|
|
258
|
+
description: variable.description || "",
|
|
259
|
+
values,
|
|
260
|
+
aliasOf,
|
|
261
|
+
aliasChain,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
allTokenCount++;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return { categories: categoryMap, collections, allTokenCount };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ─── Renderers ──────────────────────────────────────────────────────────────
|
|
272
|
+
|
|
273
|
+
function renderMarkdown(
|
|
274
|
+
categories: Map<string, TokenCategory>,
|
|
275
|
+
collections: RawCollection[],
|
|
276
|
+
allTokenCount: number,
|
|
277
|
+
args: TokenDocsArgs
|
|
278
|
+
): string {
|
|
279
|
+
const lines: string[] = [];
|
|
280
|
+
const date = todayStamp();
|
|
281
|
+
|
|
282
|
+
lines.push(`# Design Token Documentation`);
|
|
283
|
+
lines.push(`Generated: ${date} | Tokens: ${allTokenCount} | Collections: ${collections.length}`);
|
|
284
|
+
lines.push("");
|
|
285
|
+
|
|
286
|
+
for (const [, category] of categories) {
|
|
287
|
+
lines.push(`## ${category.label}`);
|
|
288
|
+
lines.push("");
|
|
289
|
+
|
|
290
|
+
if (category.tokens.length === 0) {
|
|
291
|
+
lines.push("_No tokens in this category._");
|
|
292
|
+
lines.push("");
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Determine mode columns from first token
|
|
297
|
+
const modeNames = Object.keys(category.tokens[0].values);
|
|
298
|
+
const isColor = category.label === "Colors";
|
|
299
|
+
const hasAlias = category.tokens.some((t) => t.aliasOf);
|
|
300
|
+
|
|
301
|
+
// Build header
|
|
302
|
+
const headerCols = ["Token"];
|
|
303
|
+
for (const mode of modeNames) headerCols.push(mode);
|
|
304
|
+
if (hasAlias) headerCols.push("Alias Of");
|
|
305
|
+
if (args.includeAliasChains) headerCols.push("Alias Chain");
|
|
306
|
+
headerCols.push("Description");
|
|
307
|
+
|
|
308
|
+
lines.push(`| ${headerCols.join(" | ")} |`);
|
|
309
|
+
lines.push(`| ${headerCols.map(() => "---").join(" | ")} |`);
|
|
310
|
+
|
|
311
|
+
for (const token of category.tokens) {
|
|
312
|
+
const row: string[] = [`\`${token.name}\``];
|
|
313
|
+
for (const mode of modeNames) {
|
|
314
|
+
row.push(formatValue(token.values[mode], token.resolvedType));
|
|
315
|
+
}
|
|
316
|
+
if (hasAlias) row.push(token.aliasOf ? `\`${token.aliasOf}\`` : "—");
|
|
317
|
+
if (args.includeAliasChains) {
|
|
318
|
+
row.push(token.aliasChain ? token.aliasChain.map((a) => `\`${a}\``).join(" -> ") : "—");
|
|
319
|
+
}
|
|
320
|
+
row.push(token.description || "—");
|
|
321
|
+
lines.push(`| ${row.join(" | ")} |`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
lines.push("");
|
|
325
|
+
|
|
326
|
+
if (args.includeUsageExamples && isColor) {
|
|
327
|
+
lines.push("### Usage Examples");
|
|
328
|
+
lines.push("```css");
|
|
329
|
+
for (const token of category.tokens.slice(0, 3)) {
|
|
330
|
+
const cssVar = token.name.replace(/\//g, "-");
|
|
331
|
+
lines.push(`.element { color: var(--${cssVar}); }`);
|
|
332
|
+
}
|
|
333
|
+
lines.push("```");
|
|
334
|
+
lines.push("");
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return lines.join("\n");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function renderJson(
|
|
342
|
+
categories: Map<string, TokenCategory>,
|
|
343
|
+
collections: RawCollection[],
|
|
344
|
+
allTokenCount: number,
|
|
345
|
+
_args: TokenDocsArgs
|
|
346
|
+
): TokenDocsJsonOutput {
|
|
347
|
+
const output: TokenDocsJsonOutput = {
|
|
348
|
+
generatedAt: todayStamp(),
|
|
349
|
+
totalTokens: allTokenCount,
|
|
350
|
+
collections: collections.map((c) => c.name),
|
|
351
|
+
categories: {},
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
for (const [key, category] of categories) {
|
|
355
|
+
output.categories[key] = {
|
|
356
|
+
count: category.tokens.length,
|
|
357
|
+
tokens: category.tokens.map((t) => ({
|
|
358
|
+
name: t.name,
|
|
359
|
+
resolvedType: t.resolvedType,
|
|
360
|
+
description: t.description,
|
|
361
|
+
values: t.values,
|
|
362
|
+
...(t.aliasOf ? { aliasOf: t.aliasOf } : {}),
|
|
363
|
+
...(t.aliasChain ? { aliasChain: t.aliasChain } : {}),
|
|
364
|
+
})),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return output;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function renderHtml(
|
|
372
|
+
categories: Map<string, TokenCategory>,
|
|
373
|
+
collections: RawCollection[],
|
|
374
|
+
allTokenCount: number,
|
|
375
|
+
args: TokenDocsArgs
|
|
376
|
+
): string {
|
|
377
|
+
const date = todayStamp();
|
|
378
|
+
const categoryEntries = Array.from(categories.entries());
|
|
379
|
+
|
|
380
|
+
return `<!DOCTYPE html>
|
|
381
|
+
<html lang="en">
|
|
382
|
+
<head>
|
|
383
|
+
<meta charset="UTF-8">
|
|
384
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
385
|
+
<title>Design Token Documentation</title>
|
|
386
|
+
<style>
|
|
387
|
+
:root { --bg: #ffffff; --fg: #1a1a1a; --muted: #6b7280; --border: #e5e7eb; --card-bg: #f9fafb; --accent: #2563eb; }
|
|
388
|
+
[data-theme="dark"] { --bg: #111827; --fg: #f3f4f6; --muted: #9ca3af; --border: #374151; --card-bg: #1f2937; --accent: #60a5fa; }
|
|
389
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
390
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--fg); padding: 2rem; max-width: 1200px; margin: 0 auto; transition: background 0.2s, color 0.2s; }
|
|
391
|
+
h1 { font-size: 2rem; margin-bottom: 0.25rem; }
|
|
392
|
+
.meta { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.875rem; }
|
|
393
|
+
.controls { display: flex; gap: 1rem; margin-bottom: 2rem; align-items: center; flex-wrap: wrap; }
|
|
394
|
+
.controls input { padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.875rem; background: var(--card-bg); color: var(--fg); min-width: 250px; }
|
|
395
|
+
.controls button { padding: 0.5rem 1rem; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; background: var(--card-bg); color: var(--fg); font-size: 0.875rem; }
|
|
396
|
+
.controls button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
|
|
397
|
+
.category { margin-bottom: 2.5rem; }
|
|
398
|
+
.category h2 { font-size: 1.4rem; margin-bottom: 1rem; border-bottom: 2px solid var(--accent); padding-bottom: 0.25rem; }
|
|
399
|
+
.token-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
|
|
400
|
+
.token-card { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; background: var(--card-bg); }
|
|
401
|
+
.token-name { font-family: 'SF Mono', Monaco, monospace; font-size: 0.8rem; color: var(--accent); cursor: pointer; word-break: break-all; }
|
|
402
|
+
.token-name:hover { text-decoration: underline; }
|
|
403
|
+
.token-values { margin-top: 0.5rem; font-size: 0.85rem; }
|
|
404
|
+
.token-values .mode { display: flex; justify-content: space-between; padding: 0.15rem 0; }
|
|
405
|
+
.token-values .mode-label { color: var(--muted); }
|
|
406
|
+
.token-desc { margin-top: 0.5rem; font-size: 0.8rem; color: var(--muted); }
|
|
407
|
+
.color-swatch { width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border); display: inline-block; vertical-align: middle; margin-right: 0.5rem; }
|
|
408
|
+
.spacing-bar { height: 8px; background: var(--accent); border-radius: 4px; margin-top: 0.25rem; min-width: 2px; }
|
|
409
|
+
.alias-chain { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
|
|
410
|
+
.shadow-preview { width: 60px; height: 40px; background: var(--bg); border-radius: 6px; margin-top: 0.5rem; }
|
|
411
|
+
.type-specimen { margin-top: 0.5rem; }
|
|
412
|
+
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; padding: 0.5rem 1rem; background: #10b981; color: #fff; border-radius: 6px; font-size: 0.85rem; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
|
|
413
|
+
.toast.show { opacity: 1; }
|
|
414
|
+
.nav-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
|
|
415
|
+
.nav-links a { font-size: 0.85rem; color: var(--accent); text-decoration: none; padding: 0.25rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; }
|
|
416
|
+
.nav-links a:hover { background: var(--accent); color: #fff; }
|
|
417
|
+
</style>
|
|
418
|
+
</head>
|
|
419
|
+
<body>
|
|
420
|
+
<h1>Design Token Documentation</h1>
|
|
421
|
+
<p class="meta">Generated: ${date} | Tokens: ${allTokenCount} | Collections: ${collections.length}</p>
|
|
422
|
+
|
|
423
|
+
<div class="controls">
|
|
424
|
+
<input type="text" id="search" placeholder="Search tokens..." oninput="filterTokens()">
|
|
425
|
+
<button onclick="toggleTheme()">Toggle Dark Mode</button>
|
|
426
|
+
</div>
|
|
427
|
+
|
|
428
|
+
<nav class="nav-links">
|
|
429
|
+
${categoryEntries.map(([key, cat]) => ` <a href="#cat-${encodeURIComponent(key)}">${cat.label} (${cat.tokens.length})</a>`).join("\n")}
|
|
430
|
+
</nav>
|
|
431
|
+
|
|
432
|
+
${categoryEntries.map(([key, category]) => {
|
|
433
|
+
const modeNames = category.tokens.length > 0 ? Object.keys(category.tokens[0].values) : [];
|
|
434
|
+
return `<section class="category" id="cat-${encodeURIComponent(key)}">
|
|
435
|
+
<h2>${category.label}</h2>
|
|
436
|
+
<div class="token-grid">
|
|
437
|
+
${category.tokens.map((token) => {
|
|
438
|
+
const isColor = token.resolvedType === "COLOR";
|
|
439
|
+
const isSpacing = /spacing|space|gap|padding|margin/i.test(token.name);
|
|
440
|
+
const isShadow = /shadow|elevation/i.test(token.name);
|
|
441
|
+
const isTypo = /font-size|font-weight|line-height|letter-spacing/i.test(token.name);
|
|
442
|
+
|
|
443
|
+
let extras = "";
|
|
444
|
+
if (isColor && args.includeVisualSwatches !== false) {
|
|
445
|
+
const val = formatValue(Object.values(token.values)[0], "COLOR");
|
|
446
|
+
extras += `<div class="color-swatch" style="background:${val};" title="${val}"></div>`;
|
|
447
|
+
}
|
|
448
|
+
if (isSpacing) {
|
|
449
|
+
const val = Object.values(token.values)[0];
|
|
450
|
+
const px = typeof val === "number" ? val : parseInt(String(val), 10) || 0;
|
|
451
|
+
extras += `<div class="spacing-bar" style="width:${Math.min(px, 200)}px;" title="${px}px"></div>`;
|
|
452
|
+
}
|
|
453
|
+
if (isShadow) {
|
|
454
|
+
extras += `<div class="shadow-preview" style="box-shadow: 0 2px 8px rgba(0,0,0,0.15);"></div>`;
|
|
455
|
+
}
|
|
456
|
+
if (isTypo) {
|
|
457
|
+
const val = Object.values(token.values)[0];
|
|
458
|
+
extras += `<div class="type-specimen" style="font-size:${typeof val === "number" ? val + "px" : val};">Aa Bb Cc 123</div>`;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const aliasHtml = token.aliasOf ? `<div class="alias-chain">Alias of: ${token.aliasOf}</div>` : "";
|
|
462
|
+
const chainHtml = token.aliasChain ? `<div class="alias-chain">Chain: ${token.aliasChain.join(" -> ")}</div>` : "";
|
|
463
|
+
|
|
464
|
+
return ` <div class="token-card" data-name="${token.name.toLowerCase()}">
|
|
465
|
+
<div class="token-name" onclick="copyToken('${token.name}')">${token.name}</div>
|
|
466
|
+
${extras}
|
|
467
|
+
<div class="token-values">
|
|
468
|
+
${modeNames.map((mode) => ` <div class="mode"><span class="mode-label">${mode}:</span> <span>${formatValue(token.values[mode], token.resolvedType)}</span></div>`).join("\n")}
|
|
469
|
+
</div>
|
|
470
|
+
${aliasHtml}${chainHtml}
|
|
471
|
+
${token.description ? `<div class="token-desc">${token.description}</div>` : ""}
|
|
472
|
+
</div>`;
|
|
473
|
+
}).join("\n")}
|
|
474
|
+
</div>
|
|
475
|
+
</section>`;
|
|
476
|
+
}).join("\n\n")}
|
|
477
|
+
|
|
478
|
+
<div class="toast" id="toast">Copied!</div>
|
|
479
|
+
|
|
480
|
+
<script>
|
|
481
|
+
function toggleTheme() {
|
|
482
|
+
const current = document.documentElement.getAttribute('data-theme');
|
|
483
|
+
document.documentElement.setAttribute('data-theme', current === 'dark' ? '' : 'dark');
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function filterTokens() {
|
|
487
|
+
const q = document.getElementById('search').value.toLowerCase();
|
|
488
|
+
document.querySelectorAll('.token-card').forEach(card => {
|
|
489
|
+
const name = card.getAttribute('data-name') || '';
|
|
490
|
+
card.style.display = name.includes(q) ? '' : 'none';
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function copyToken(name) {
|
|
495
|
+
navigator.clipboard.writeText(name).then(() => {
|
|
496
|
+
const toast = document.getElementById('toast');
|
|
497
|
+
toast.classList.add('show');
|
|
498
|
+
setTimeout(() => toast.classList.remove('show'), 1500);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
</script>
|
|
502
|
+
</body>
|
|
503
|
+
</html>`;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function renderFigmaPluginCode(
|
|
507
|
+
categories: Map<string, TokenCategory>,
|
|
508
|
+
_collections: RawCollection[],
|
|
509
|
+
_allTokenCount: number,
|
|
510
|
+
args: TokenDocsArgs
|
|
511
|
+
): string {
|
|
512
|
+
const pageName = args.pageName || "Token Documentation";
|
|
513
|
+
const categoryEntries = Array.from(categories.entries());
|
|
514
|
+
|
|
515
|
+
// Build Plugin API code string to be executed via bridge.execute()
|
|
516
|
+
const lines: string[] = [];
|
|
517
|
+
lines.push(`(async () => {`);
|
|
518
|
+
lines.push(` // Create or find documentation page`);
|
|
519
|
+
lines.push(` let page = figma.root.children.find(p => p.name === ${JSON.stringify(pageName)});`);
|
|
520
|
+
lines.push(` if (!page) {`);
|
|
521
|
+
lines.push(` page = figma.createPage();`);
|
|
522
|
+
lines.push(` page.name = ${JSON.stringify(pageName)};`);
|
|
523
|
+
lines.push(` }`);
|
|
524
|
+
lines.push(` figma.currentPage = page;`);
|
|
525
|
+
lines.push(``);
|
|
526
|
+
lines.push(` // Clear existing content on the page`);
|
|
527
|
+
lines.push(` for (const child of [...page.children]) child.remove();`);
|
|
528
|
+
lines.push(``);
|
|
529
|
+
lines.push(` // Root frame with auto layout`);
|
|
530
|
+
lines.push(` const root = figma.createFrame();`);
|
|
531
|
+
lines.push(` root.name = "Token Documentation";`);
|
|
532
|
+
lines.push(` root.layoutMode = "VERTICAL";`);
|
|
533
|
+
lines.push(` root.primaryAxisSizingMode = "AUTO";`);
|
|
534
|
+
lines.push(` root.counterAxisSizingMode = "AUTO";`);
|
|
535
|
+
lines.push(` root.itemSpacing = 48;`);
|
|
536
|
+
lines.push(` root.paddingTop = 40;`);
|
|
537
|
+
lines.push(` root.paddingBottom = 40;`);
|
|
538
|
+
lines.push(` root.paddingLeft = 40;`);
|
|
539
|
+
lines.push(` root.paddingRight = 40;`);
|
|
540
|
+
lines.push(` root.fills = [{ type: "SOLID", color: { r: 1, g: 1, b: 1 } }];`);
|
|
541
|
+
lines.push(` page.appendChild(root);`);
|
|
542
|
+
lines.push(``);
|
|
543
|
+
lines.push(` // Helper: create text node`);
|
|
544
|
+
lines.push(` async function makeText(content, fontSize, isBold) {`);
|
|
545
|
+
lines.push(` const t = figma.createText();`);
|
|
546
|
+
lines.push(` await figma.loadFontAsync({ family: "Inter", style: isBold ? "Bold" : "Regular" });`);
|
|
547
|
+
lines.push(` t.fontName = { family: "Inter", style: isBold ? "Bold" : "Regular" };`);
|
|
548
|
+
lines.push(` t.fontSize = fontSize;`);
|
|
549
|
+
lines.push(` t.characters = content;`);
|
|
550
|
+
lines.push(` return t;`);
|
|
551
|
+
lines.push(` }`);
|
|
552
|
+
lines.push(``);
|
|
553
|
+
lines.push(` // Title`);
|
|
554
|
+
lines.push(` const title = await makeText("Design Token Documentation", 32, true);`);
|
|
555
|
+
lines.push(` root.appendChild(title);`);
|
|
556
|
+
lines.push(``);
|
|
557
|
+
|
|
558
|
+
for (const [key, category] of categoryEntries) {
|
|
559
|
+
const safeKey = key.replace(/[^a-zA-Z0-9]/g, "_");
|
|
560
|
+
lines.push(` // ── ${category.label} ──`);
|
|
561
|
+
lines.push(` const section_${safeKey} = figma.createFrame();`);
|
|
562
|
+
lines.push(` section_${safeKey}.name = "Section: ${category.label}";`);
|
|
563
|
+
lines.push(` section_${safeKey}.layoutMode = "VERTICAL";`);
|
|
564
|
+
lines.push(` section_${safeKey}.primaryAxisSizingMode = "AUTO";`);
|
|
565
|
+
lines.push(` section_${safeKey}.counterAxisSizingMode = "AUTO";`);
|
|
566
|
+
lines.push(` section_${safeKey}.itemSpacing = 16;`);
|
|
567
|
+
lines.push(` section_${safeKey}.fills = [];`);
|
|
568
|
+
lines.push(` root.appendChild(section_${safeKey});`);
|
|
569
|
+
lines.push(``);
|
|
570
|
+
lines.push(` const header_${safeKey} = await makeText(${JSON.stringify(category.label)}, 24, true);`);
|
|
571
|
+
lines.push(` section_${safeKey}.appendChild(header_${safeKey});`);
|
|
572
|
+
lines.push(``);
|
|
573
|
+
|
|
574
|
+
// Token grid frame
|
|
575
|
+
lines.push(` const grid_${safeKey} = figma.createFrame();`);
|
|
576
|
+
lines.push(` grid_${safeKey}.name = "Tokens: ${category.label}";`);
|
|
577
|
+
lines.push(` grid_${safeKey}.layoutMode = "HORIZONTAL";`);
|
|
578
|
+
lines.push(` grid_${safeKey}.layoutWrap = "WRAP";`);
|
|
579
|
+
lines.push(` grid_${safeKey}.primaryAxisSizingMode = "FIXED";`);
|
|
580
|
+
lines.push(` grid_${safeKey}.resize(1000, 10);`);
|
|
581
|
+
lines.push(` grid_${safeKey}.counterAxisSizingMode = "AUTO";`);
|
|
582
|
+
lines.push(` grid_${safeKey}.itemSpacing = 12;`);
|
|
583
|
+
lines.push(` grid_${safeKey}.counterAxisSpacing = 12;`);
|
|
584
|
+
lines.push(` grid_${safeKey}.fills = [];`);
|
|
585
|
+
lines.push(` section_${safeKey}.appendChild(grid_${safeKey});`);
|
|
586
|
+
lines.push(``);
|
|
587
|
+
|
|
588
|
+
for (let i = 0; i < category.tokens.length; i++) {
|
|
589
|
+
const token = category.tokens[i];
|
|
590
|
+
const isColor = token.resolvedType === "COLOR";
|
|
591
|
+
const firstModeValue = Object.values(token.values)[0];
|
|
592
|
+
const modeNames = Object.keys(token.values);
|
|
593
|
+
const tId = `${safeKey}_t${i}`;
|
|
594
|
+
|
|
595
|
+
lines.push(` {`);
|
|
596
|
+
lines.push(` const card = figma.createFrame();`);
|
|
597
|
+
lines.push(` card.name = ${JSON.stringify(token.name)};`);
|
|
598
|
+
lines.push(` card.layoutMode = "VERTICAL";`);
|
|
599
|
+
lines.push(` card.primaryAxisSizingMode = "AUTO";`);
|
|
600
|
+
lines.push(` card.counterAxisSizingMode = "FIXED";`);
|
|
601
|
+
lines.push(` card.resize(200, 10);`);
|
|
602
|
+
lines.push(` card.itemSpacing = 4;`);
|
|
603
|
+
lines.push(` card.paddingTop = 8; card.paddingBottom = 8; card.paddingLeft = 8; card.paddingRight = 8;`);
|
|
604
|
+
lines.push(` card.cornerRadius = 8;`);
|
|
605
|
+
lines.push(` card.fills = [{ type: "SOLID", color: { r: 0.96, g: 0.96, b: 0.97 } }];`);
|
|
606
|
+
|
|
607
|
+
// Color swatch
|
|
608
|
+
if (isColor && args.includeVisualSwatches !== false) {
|
|
609
|
+
const colorVal = firstModeValue as { r?: number; g?: number; b?: number } | undefined;
|
|
610
|
+
if (colorVal && typeof colorVal === "object" && "r" in colorVal) {
|
|
611
|
+
lines.push(` const swatch = figma.createRectangle();`);
|
|
612
|
+
lines.push(` swatch.resize(184, 40);`);
|
|
613
|
+
lines.push(` swatch.cornerRadius = 4;`);
|
|
614
|
+
lines.push(` swatch.fills = [{ type: "SOLID", color: { r: ${colorVal.r}, g: ${colorVal.g}, b: ${colorVal.b} } }];`);
|
|
615
|
+
lines.push(` card.appendChild(swatch);`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
lines.push(` const label = await makeText(${JSON.stringify(token.name)}, 11, true);`);
|
|
620
|
+
lines.push(` card.appendChild(label);`);
|
|
621
|
+
|
|
622
|
+
// Show values per mode
|
|
623
|
+
for (const mode of modeNames) {
|
|
624
|
+
const val = formatValue(token.values[mode], token.resolvedType);
|
|
625
|
+
lines.push(` const val_${mode.replace(/[^a-zA-Z0-9]/g, "_")} = await makeText("${mode}: ${val.replace(/"/g, '\\"')}", 10, false);`);
|
|
626
|
+
lines.push(` card.appendChild(val_${mode.replace(/[^a-zA-Z0-9]/g, "_")});`);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
lines.push(` grid_${safeKey}.appendChild(card);`);
|
|
630
|
+
lines.push(` }`);
|
|
631
|
+
lines.push(``);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
lines.push(` figma.viewport.scrollAndZoomIntoView([root]);`);
|
|
636
|
+
lines.push(` return { success: true, page: page.name, nodeId: root.id };`);
|
|
637
|
+
lines.push(`})();`);
|
|
638
|
+
|
|
639
|
+
return lines.join("\n");
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// ─── Main Handler ───────────────────────────────────────────────────────────
|
|
643
|
+
|
|
644
|
+
export async function tokenDocsHandler(args: TokenDocsArgs): Promise<unknown> {
|
|
645
|
+
const notes: string[] = [];
|
|
646
|
+
const { categories, collections, allTokenCount } = await fetchAndOrganizeTokens(args);
|
|
647
|
+
|
|
648
|
+
if (allTokenCount === 0) {
|
|
649
|
+
return {
|
|
650
|
+
ok: true,
|
|
651
|
+
format: args.outputFormat,
|
|
652
|
+
tokenCount: 0,
|
|
653
|
+
collectionCount: collections.length,
|
|
654
|
+
categoryCount: 0,
|
|
655
|
+
output: args.outputFormat === "json" ? { generatedAt: todayStamp(), totalTokens: 0, collections: [], categories: {} } : "No tokens found.",
|
|
656
|
+
notes: ["No variables found in the current Figma file. Ensure variables exist and the bridge plugin is running."],
|
|
657
|
+
} satisfies TokenDocsResult;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
notes.push(`Found ${allTokenCount} tokens across ${collections.length} collection(s) in ${categories.size} categor${categories.size === 1 ? "y" : "ies"}.`);
|
|
661
|
+
|
|
662
|
+
let output: string | TokenDocsJsonOutput;
|
|
663
|
+
|
|
664
|
+
switch (args.outputFormat) {
|
|
665
|
+
case "markdown":
|
|
666
|
+
output = renderMarkdown(categories, collections, allTokenCount, args);
|
|
667
|
+
break;
|
|
668
|
+
|
|
669
|
+
case "json":
|
|
670
|
+
output = renderJson(categories, collections, allTokenCount, args);
|
|
671
|
+
break;
|
|
672
|
+
|
|
673
|
+
case "html":
|
|
674
|
+
output = renderHtml(categories, collections, allTokenCount, args);
|
|
675
|
+
break;
|
|
676
|
+
|
|
677
|
+
case "figma": {
|
|
678
|
+
const pluginCode = renderFigmaPluginCode(categories, collections, allTokenCount, args);
|
|
679
|
+
const bridge = await getBridge();
|
|
680
|
+
const result = await bridge.execute(pluginCode);
|
|
681
|
+
if (!result.success) {
|
|
682
|
+
return {
|
|
683
|
+
ok: false,
|
|
684
|
+
format: "figma",
|
|
685
|
+
tokenCount: allTokenCount,
|
|
686
|
+
collectionCount: collections.length,
|
|
687
|
+
categoryCount: categories.size,
|
|
688
|
+
output: `Figma plugin execution failed: ${JSON.stringify(result)}`,
|
|
689
|
+
notes: ["The Plugin API code failed to execute. Check that Figma is open and the bridge plugin is active."],
|
|
690
|
+
} satisfies TokenDocsResult;
|
|
691
|
+
}
|
|
692
|
+
output = `Documentation page created in Figma. ${JSON.stringify(result.result)}`;
|
|
693
|
+
notes.push("Created Figma documentation page with token swatches, labels, and values.");
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
default:
|
|
698
|
+
throw new Error(`Unsupported output format: ${args.outputFormat}`);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
return {
|
|
702
|
+
ok: true,
|
|
703
|
+
format: args.outputFormat,
|
|
704
|
+
tokenCount: allTokenCount,
|
|
705
|
+
collectionCount: collections.length,
|
|
706
|
+
categoryCount: categories.size,
|
|
707
|
+
output,
|
|
708
|
+
notes,
|
|
709
|
+
} satisfies TokenDocsResult;
|
|
710
|
+
}
|