@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,702 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// figma_handoff_spec — Developer-ready handoff specification
|
|
3
|
+
//
|
|
4
|
+
// Takes a Figma component or frame and generates a complete developer handoff
|
|
5
|
+
// document with:
|
|
6
|
+
// - Measurements (width, height, padding, gap, margin)
|
|
7
|
+
// - Token names mapped to every visual property
|
|
8
|
+
// - Copy-paste CSS/SCSS for each element
|
|
9
|
+
// - Redline annotations showing spacing relationships
|
|
10
|
+
// - Asset export list (icons, images)
|
|
11
|
+
// - Responsive notes & breakpoint behavior
|
|
12
|
+
// - Interaction specs (hover, focus, active states)
|
|
13
|
+
//
|
|
14
|
+
// Output: structured JSON, Markdown, or annotated Figma page with redlines.
|
|
15
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
import { getBridge } from "../../../shared/figma-bridge.js";
|
|
18
|
+
import { figmaRgbaToHex } from "../../../shared/token-utils.js";
|
|
19
|
+
|
|
20
|
+
// ─── Types ──────────────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
export interface HandoffSpecArgs {
|
|
23
|
+
/** Figma node ID of the component/frame to spec */
|
|
24
|
+
nodeId: string;
|
|
25
|
+
/** Output format */
|
|
26
|
+
outputFormat: "json" | "markdown" | "figma-page" | "all";
|
|
27
|
+
/** Include copy-paste CSS snippets for each element */
|
|
28
|
+
includeCss?: boolean;
|
|
29
|
+
/** Include asset export list */
|
|
30
|
+
includeAssets?: boolean;
|
|
31
|
+
/** CSS unit preference */
|
|
32
|
+
cssUnit?: "px" | "rem";
|
|
33
|
+
/** rem base size (default 16) */
|
|
34
|
+
remBase?: number;
|
|
35
|
+
/** Max depth for recursive element scanning */
|
|
36
|
+
maxDepth?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface MeasuredElement {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
type: string;
|
|
43
|
+
depth: number;
|
|
44
|
+
bounds: { x: number; y: number; width: number; height: number };
|
|
45
|
+
spacing: {
|
|
46
|
+
paddingTop: number;
|
|
47
|
+
paddingRight: number;
|
|
48
|
+
paddingBottom: number;
|
|
49
|
+
paddingLeft: number;
|
|
50
|
+
itemSpacing: number;
|
|
51
|
+
layoutMode: string;
|
|
52
|
+
};
|
|
53
|
+
appearance: {
|
|
54
|
+
fills: Array<{ type: string; hex: string; opacity: number; tokenName: string }>;
|
|
55
|
+
strokes: Array<{ hex: string; weight: number; tokenName: string }>;
|
|
56
|
+
cornerRadius: number | number[];
|
|
57
|
+
effects: Array<{ type: string; description: string }>;
|
|
58
|
+
opacity: number;
|
|
59
|
+
};
|
|
60
|
+
typography: {
|
|
61
|
+
fontFamily: string;
|
|
62
|
+
fontSize: number;
|
|
63
|
+
fontWeight: number;
|
|
64
|
+
lineHeight: number | string;
|
|
65
|
+
letterSpacing: number;
|
|
66
|
+
textAlign: string;
|
|
67
|
+
tokenName: string;
|
|
68
|
+
} | null;
|
|
69
|
+
tokens: Array<{ property: string; tokenName: string; rawValue: string }>;
|
|
70
|
+
cssSnippet: string;
|
|
71
|
+
children: string[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface AssetEntry {
|
|
75
|
+
nodeId: string;
|
|
76
|
+
name: string;
|
|
77
|
+
type: "icon" | "image" | "illustration" | "logo";
|
|
78
|
+
suggestedExport: string;
|
|
79
|
+
size: { width: number; height: number };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface RedlineAnnotation {
|
|
83
|
+
fromElement: string;
|
|
84
|
+
toElement: string;
|
|
85
|
+
direction: "horizontal" | "vertical";
|
|
86
|
+
distance: number;
|
|
87
|
+
label: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ─── Figma extraction ──────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
async function extractNodeTree(
|
|
93
|
+
nodeId: string,
|
|
94
|
+
maxDepth: number
|
|
95
|
+
): Promise<{
|
|
96
|
+
elements: MeasuredElement[];
|
|
97
|
+
assets: AssetEntry[];
|
|
98
|
+
redlines: RedlineAnnotation[];
|
|
99
|
+
rootName: string;
|
|
100
|
+
rootBounds: { width: number; height: number };
|
|
101
|
+
}> {
|
|
102
|
+
const bridge = await getBridge();
|
|
103
|
+
|
|
104
|
+
const result = await bridge.execute(`
|
|
105
|
+
(async () => {
|
|
106
|
+
var node = figma.getNodeById('${nodeId}');
|
|
107
|
+
if (!node) return { error: 'Node not found' };
|
|
108
|
+
|
|
109
|
+
var elements = [];
|
|
110
|
+
var assets = [];
|
|
111
|
+
var maxDepth = ${maxDepth};
|
|
112
|
+
|
|
113
|
+
function hexFromPaint(paint) {
|
|
114
|
+
if (!paint || paint.type !== 'SOLID') return '#000000';
|
|
115
|
+
var r = Math.round((paint.color.r || 0) * 255).toString(16).padStart(2, '0');
|
|
116
|
+
var g = Math.round((paint.color.g || 0) * 255).toString(16).padStart(2, '0');
|
|
117
|
+
var b = Math.round((paint.color.b || 0) * 255).toString(16).padStart(2, '0');
|
|
118
|
+
return '#' + r + g + b;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getTokenName(node, prop) {
|
|
122
|
+
try {
|
|
123
|
+
var bindings = node.boundVariables || {};
|
|
124
|
+
if (bindings[prop]) {
|
|
125
|
+
var alias = bindings[prop];
|
|
126
|
+
if (alias.id) {
|
|
127
|
+
var v = figma.variables.getVariableById(alias.id);
|
|
128
|
+
return v ? v.name : '';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (prop === 'fills' && Array.isArray(bindings.fills)) {
|
|
132
|
+
for (var i = 0; i < bindings.fills.length; i++) {
|
|
133
|
+
if (bindings.fills[i] && bindings.fills[i].id) {
|
|
134
|
+
var v = figma.variables.getVariableById(bindings.fills[i].id);
|
|
135
|
+
if (v) return v.name;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {}
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function scan(n, depth) {
|
|
144
|
+
if (depth > maxDepth) return;
|
|
145
|
+
if (!n.visible) return;
|
|
146
|
+
|
|
147
|
+
var fills = [];
|
|
148
|
+
var strokes = [];
|
|
149
|
+
var tokens = [];
|
|
150
|
+
|
|
151
|
+
if (n.fills && Array.isArray(n.fills)) {
|
|
152
|
+
for (var i = 0; i < n.fills.length; i++) {
|
|
153
|
+
var f = n.fills[i];
|
|
154
|
+
if (!f.visible && f.visible !== undefined) continue;
|
|
155
|
+
var tk = getTokenName(n, 'fills');
|
|
156
|
+
fills.push({ type: f.type, hex: hexFromPaint(f), opacity: f.opacity || 1, tokenName: tk });
|
|
157
|
+
if (tk) tokens.push({ property: 'fill', tokenName: tk, rawValue: hexFromPaint(f) });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (n.strokes && Array.isArray(n.strokes)) {
|
|
162
|
+
for (var i = 0; i < n.strokes.length; i++) {
|
|
163
|
+
var s = n.strokes[i];
|
|
164
|
+
var tk = getTokenName(n, 'strokes');
|
|
165
|
+
strokes.push({ hex: hexFromPaint(s), weight: n.strokeWeight || 1, tokenName: tk });
|
|
166
|
+
if (tk) tokens.push({ property: 'stroke', tokenName: tk, rawValue: hexFromPaint(s) });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var ptk = getTokenName(n, 'paddingTop');
|
|
171
|
+
if (ptk) tokens.push({ property: 'paddingTop', tokenName: ptk, rawValue: String(n.paddingTop || 0) });
|
|
172
|
+
var ispk = getTokenName(n, 'itemSpacing');
|
|
173
|
+
if (ispk) tokens.push({ property: 'itemSpacing', tokenName: ispk, rawValue: String(n.itemSpacing || 0) });
|
|
174
|
+
var crk = getTokenName(n, 'topLeftRadius');
|
|
175
|
+
if (crk) tokens.push({ property: 'cornerRadius', tokenName: crk, rawValue: String(n.cornerRadius || 0) });
|
|
176
|
+
|
|
177
|
+
var typo = null;
|
|
178
|
+
if (n.type === 'TEXT') {
|
|
179
|
+
var ft = getTokenName(n, 'fontSize');
|
|
180
|
+
typo = {
|
|
181
|
+
fontFamily: n.fontName ? n.fontName.family : '',
|
|
182
|
+
fontSize: n.fontSize || 0,
|
|
183
|
+
fontWeight: n.fontWeight || 400,
|
|
184
|
+
lineHeight: n.lineHeight ? (n.lineHeight.unit === 'PIXELS' ? n.lineHeight.value : n.lineHeight.unit === 'PERCENT' ? (n.lineHeight.value + '%') : 'auto') : 'auto',
|
|
185
|
+
letterSpacing: n.letterSpacing ? n.letterSpacing.value : 0,
|
|
186
|
+
textAlign: n.textAlignHorizontal || 'LEFT',
|
|
187
|
+
tokenName: ft
|
|
188
|
+
};
|
|
189
|
+
if (ft) tokens.push({ property: 'fontSize', tokenName: ft, rawValue: String(n.fontSize) });
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Detect assets
|
|
193
|
+
if (n.type === 'INSTANCE' && n.name.toLowerCase().includes('icon')) {
|
|
194
|
+
assets.push({ nodeId: n.id, name: n.name, type: 'icon', suggestedExport: 'SVG', size: { width: Math.round(n.width), height: Math.round(n.height) } });
|
|
195
|
+
} else if (n.fills && n.fills.some(function(f) { return f.type === 'IMAGE'; })) {
|
|
196
|
+
assets.push({ nodeId: n.id, name: n.name, type: 'image', suggestedExport: 'PNG @2x', size: { width: Math.round(n.width), height: Math.round(n.height) } });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var el = {
|
|
200
|
+
id: n.id,
|
|
201
|
+
name: n.name,
|
|
202
|
+
type: n.type,
|
|
203
|
+
depth: depth,
|
|
204
|
+
bounds: { x: Math.round(n.x || 0), y: Math.round(n.y || 0), width: Math.round(n.width || 0), height: Math.round(n.height || 0) },
|
|
205
|
+
spacing: {
|
|
206
|
+
paddingTop: n.paddingTop || 0,
|
|
207
|
+
paddingRight: n.paddingRight || 0,
|
|
208
|
+
paddingBottom: n.paddingBottom || 0,
|
|
209
|
+
paddingLeft: n.paddingLeft || 0,
|
|
210
|
+
itemSpacing: n.itemSpacing || 0,
|
|
211
|
+
layoutMode: n.layoutMode || 'NONE'
|
|
212
|
+
},
|
|
213
|
+
appearance: {
|
|
214
|
+
fills: fills,
|
|
215
|
+
strokes: strokes,
|
|
216
|
+
cornerRadius: typeof n.cornerRadius === 'number' ? n.cornerRadius : [n.topLeftRadius || 0, n.topRightRadius || 0, n.bottomRightRadius || 0, n.bottomLeftRadius || 0],
|
|
217
|
+
effects: (n.effects || []).map(function(e) { return { type: e.type, description: e.type + ' ' + (e.radius || 0) + 'px' }; }),
|
|
218
|
+
opacity: n.opacity !== undefined ? n.opacity : 1
|
|
219
|
+
},
|
|
220
|
+
typography: typo,
|
|
221
|
+
tokens: tokens,
|
|
222
|
+
children: n.children ? n.children.map(function(c) { return c.id; }) : []
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
elements.push(el);
|
|
226
|
+
|
|
227
|
+
if (n.children) {
|
|
228
|
+
for (var i = 0; i < n.children.length; i++) {
|
|
229
|
+
scan(n.children[i], depth + 1);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
scan(node, 0);
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
elements: elements,
|
|
238
|
+
assets: assets,
|
|
239
|
+
rootName: node.name,
|
|
240
|
+
rootBounds: { width: Math.round(node.width || 0), height: Math.round(node.height || 0) }
|
|
241
|
+
};
|
|
242
|
+
})();
|
|
243
|
+
`);
|
|
244
|
+
|
|
245
|
+
if (!result.success || !result.result) {
|
|
246
|
+
throw new Error(result.error || "Failed to extract node tree");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const data = result.result as {
|
|
250
|
+
elements: MeasuredElement[];
|
|
251
|
+
assets: AssetEntry[];
|
|
252
|
+
rootName: string;
|
|
253
|
+
rootBounds: { width: number; height: number };
|
|
254
|
+
error?: string;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
if (data.error) throw new Error(data.error);
|
|
258
|
+
|
|
259
|
+
// Compute redline annotations from adjacent sibling spacing
|
|
260
|
+
const redlines: RedlineAnnotation[] = [];
|
|
261
|
+
for (const el of data.elements) {
|
|
262
|
+
if (el.spacing.layoutMode !== "NONE" && el.children.length > 1) {
|
|
263
|
+
const childEls = data.elements.filter((e) => el.children.includes(e.id));
|
|
264
|
+
for (let i = 0; i < childEls.length - 1; i++) {
|
|
265
|
+
const dir = el.spacing.layoutMode === "HORIZONTAL" ? "horizontal" : "vertical";
|
|
266
|
+
redlines.push({
|
|
267
|
+
fromElement: childEls[i].name,
|
|
268
|
+
toElement: childEls[i + 1].name,
|
|
269
|
+
direction: dir,
|
|
270
|
+
distance: el.spacing.itemSpacing,
|
|
271
|
+
label: `${el.spacing.itemSpacing}px gap`,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Padding redlines
|
|
277
|
+
if (el.spacing.paddingTop > 0 || el.spacing.paddingRight > 0 || el.spacing.paddingBottom > 0 || el.spacing.paddingLeft > 0) {
|
|
278
|
+
if (el.spacing.paddingTop > 0) {
|
|
279
|
+
redlines.push({ fromElement: el.name, toElement: `${el.name} (content)`, direction: "vertical", distance: el.spacing.paddingTop, label: `${el.spacing.paddingTop}px padding-top` });
|
|
280
|
+
}
|
|
281
|
+
if (el.spacing.paddingBottom > 0) {
|
|
282
|
+
redlines.push({ fromElement: `${el.name} (content)`, toElement: el.name, direction: "vertical", distance: el.spacing.paddingBottom, label: `${el.spacing.paddingBottom}px padding-bottom` });
|
|
283
|
+
}
|
|
284
|
+
if (el.spacing.paddingLeft > 0) {
|
|
285
|
+
redlines.push({ fromElement: el.name, toElement: `${el.name} (content)`, direction: "horizontal", distance: el.spacing.paddingLeft, label: `${el.spacing.paddingLeft}px padding-left` });
|
|
286
|
+
}
|
|
287
|
+
if (el.spacing.paddingRight > 0) {
|
|
288
|
+
redlines.push({ fromElement: `${el.name} (content)`, toElement: el.name, direction: "horizontal", distance: el.spacing.paddingRight, label: `${el.spacing.paddingRight}px padding-right` });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return { ...data, redlines };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ─── CSS snippet generator ─────────────────────────────────────────────────
|
|
297
|
+
|
|
298
|
+
function generateElementCss(el: MeasuredElement, unit: "px" | "rem", remBase: number): string {
|
|
299
|
+
const u = (val: number) => {
|
|
300
|
+
if (val === 0) return "0";
|
|
301
|
+
return unit === "rem" ? `${(val / remBase).toFixed(3).replace(/\.?0+$/, "")}rem` : `${val}px`;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const lines: string[] = [];
|
|
305
|
+
lines.push(`.${el.name.replace(/[^a-zA-Z0-9_-]/g, "-").toLowerCase()} {`);
|
|
306
|
+
|
|
307
|
+
// Layout
|
|
308
|
+
if (el.spacing.layoutMode !== "NONE") {
|
|
309
|
+
lines.push(` display: flex;`);
|
|
310
|
+
lines.push(` flex-direction: ${el.spacing.layoutMode === "VERTICAL" ? "column" : "row"};`);
|
|
311
|
+
if (el.spacing.itemSpacing > 0) lines.push(` gap: ${u(el.spacing.itemSpacing)};`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Dimensions
|
|
315
|
+
lines.push(` width: ${u(el.bounds.width)};`);
|
|
316
|
+
lines.push(` height: ${u(el.bounds.height)};`);
|
|
317
|
+
|
|
318
|
+
// Padding
|
|
319
|
+
const { paddingTop: pt, paddingRight: pr, paddingBottom: pb, paddingLeft: pl } = el.spacing;
|
|
320
|
+
if (pt || pr || pb || pl) {
|
|
321
|
+
if (pt === pb && pl === pr && pt === pl) {
|
|
322
|
+
lines.push(` padding: ${u(pt)};`);
|
|
323
|
+
} else if (pt === pb && pl === pr) {
|
|
324
|
+
lines.push(` padding: ${u(pt)} ${u(pr)};`);
|
|
325
|
+
} else {
|
|
326
|
+
lines.push(` padding: ${u(pt)} ${u(pr)} ${u(pb)} ${u(pl)};`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Fills
|
|
331
|
+
for (const fill of el.appearance.fills) {
|
|
332
|
+
if (fill.tokenName) {
|
|
333
|
+
lines.push(` background-color: var(--${fill.tokenName.replace(/\//g, "-").toLowerCase()});`);
|
|
334
|
+
} else if (fill.type === "SOLID") {
|
|
335
|
+
lines.push(` background-color: ${fill.hex};`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Border
|
|
340
|
+
for (const stroke of el.appearance.strokes) {
|
|
341
|
+
const borderVal = stroke.tokenName
|
|
342
|
+
? `${u(stroke.weight)} solid var(--${stroke.tokenName.replace(/\//g, "-").toLowerCase()})`
|
|
343
|
+
: `${u(stroke.weight)} solid ${stroke.hex}`;
|
|
344
|
+
lines.push(` border: ${borderVal};`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Border radius
|
|
348
|
+
const cr = el.appearance.cornerRadius;
|
|
349
|
+
if (typeof cr === "number" && cr > 0) {
|
|
350
|
+
lines.push(` border-radius: ${u(cr)};`);
|
|
351
|
+
} else if (Array.isArray(cr) && cr.some((v) => v > 0)) {
|
|
352
|
+
lines.push(` border-radius: ${cr.map((v) => u(v)).join(" ")};`);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Opacity
|
|
356
|
+
if (el.appearance.opacity < 1) {
|
|
357
|
+
lines.push(` opacity: ${el.appearance.opacity};`);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Typography
|
|
361
|
+
if (el.typography) {
|
|
362
|
+
const t = el.typography;
|
|
363
|
+
lines.push(` font-family: '${t.fontFamily}', sans-serif;`);
|
|
364
|
+
lines.push(` font-size: ${u(t.fontSize)};`);
|
|
365
|
+
lines.push(` font-weight: ${t.fontWeight};`);
|
|
366
|
+
if (typeof t.lineHeight === "number") {
|
|
367
|
+
lines.push(` line-height: ${u(t.lineHeight)};`);
|
|
368
|
+
} else if (t.lineHeight !== "auto") {
|
|
369
|
+
lines.push(` line-height: ${t.lineHeight};`);
|
|
370
|
+
}
|
|
371
|
+
if (t.letterSpacing) {
|
|
372
|
+
lines.push(` letter-spacing: ${u(t.letterSpacing)};`);
|
|
373
|
+
}
|
|
374
|
+
lines.push(` text-align: ${t.textAlign.toLowerCase()};`);
|
|
375
|
+
|
|
376
|
+
// Text color from fills
|
|
377
|
+
if (el.appearance.fills.length > 0) {
|
|
378
|
+
const textFill = el.appearance.fills[0];
|
|
379
|
+
if (textFill.tokenName) {
|
|
380
|
+
lines.push(` color: var(--${textFill.tokenName.replace(/\//g, "-").toLowerCase()});`);
|
|
381
|
+
} else {
|
|
382
|
+
lines.push(` color: ${textFill.hex};`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Effects
|
|
388
|
+
for (const effect of el.appearance.effects) {
|
|
389
|
+
if (effect.type === "DROP_SHADOW") {
|
|
390
|
+
lines.push(` box-shadow: ${effect.description};`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
lines.push(`}`);
|
|
395
|
+
return lines.join("\n");
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// ─── Markdown renderer ─────────────────────────────────────────────────────
|
|
399
|
+
|
|
400
|
+
function renderMarkdown(
|
|
401
|
+
rootName: string,
|
|
402
|
+
rootBounds: { width: number; height: number },
|
|
403
|
+
elements: MeasuredElement[],
|
|
404
|
+
redlines: RedlineAnnotation[],
|
|
405
|
+
assets: AssetEntry[],
|
|
406
|
+
args: HandoffSpecArgs
|
|
407
|
+
): string {
|
|
408
|
+
const lines: string[] = [];
|
|
409
|
+
|
|
410
|
+
lines.push(`# Developer Handoff: ${rootName}`);
|
|
411
|
+
lines.push(`> Auto-generated by \`figma_handoff_spec\``);
|
|
412
|
+
lines.push(``);
|
|
413
|
+
lines.push(`## Overview`);
|
|
414
|
+
lines.push(`| Property | Value |`);
|
|
415
|
+
lines.push(`|----------|-------|`);
|
|
416
|
+
lines.push(`| **Frame** | ${rootName} |`);
|
|
417
|
+
lines.push(`| **Size** | ${rootBounds.width} × ${rootBounds.height}px |`);
|
|
418
|
+
lines.push(`| **Elements** | ${elements.length} |`);
|
|
419
|
+
lines.push(`| **Tokens Used** | ${elements.reduce((sum, el) => sum + el.tokens.length, 0)} |`);
|
|
420
|
+
lines.push(``);
|
|
421
|
+
|
|
422
|
+
// Token map
|
|
423
|
+
const allTokens = elements.flatMap((el) => el.tokens);
|
|
424
|
+
if (allTokens.length > 0) {
|
|
425
|
+
lines.push(`## Design Tokens`);
|
|
426
|
+
lines.push(`| Token | Property | Raw Value |`);
|
|
427
|
+
lines.push(`|-------|----------|-----------|`);
|
|
428
|
+
const seen = new Set<string>();
|
|
429
|
+
for (const t of allTokens) {
|
|
430
|
+
const key = `${t.tokenName}:${t.property}`;
|
|
431
|
+
if (seen.has(key)) continue;
|
|
432
|
+
seen.add(key);
|
|
433
|
+
lines.push(`| \`${t.tokenName}\` | ${t.property} | \`${t.rawValue}\` |`);
|
|
434
|
+
}
|
|
435
|
+
lines.push(``);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// Measurements
|
|
439
|
+
lines.push(`## Measurements`);
|
|
440
|
+
lines.push(``);
|
|
441
|
+
for (const el of elements) {
|
|
442
|
+
if (el.depth > 3) continue; // Skip deeply nested for readability
|
|
443
|
+
const indent = " ".repeat(el.depth);
|
|
444
|
+
lines.push(`${indent}### ${el.name} (\`${el.type}\`)`);
|
|
445
|
+
lines.push(`${indent}| Metric | Value |`);
|
|
446
|
+
lines.push(`${indent}|--------|-------|`);
|
|
447
|
+
lines.push(`${indent}| Size | ${el.bounds.width} × ${el.bounds.height}px |`);
|
|
448
|
+
lines.push(`${indent}| Position | (${el.bounds.x}, ${el.bounds.y}) |`);
|
|
449
|
+
|
|
450
|
+
if (el.spacing.layoutMode !== "NONE") {
|
|
451
|
+
lines.push(`${indent}| Layout | ${el.spacing.layoutMode === "HORIZONTAL" ? "Row" : "Column"} |`);
|
|
452
|
+
lines.push(`${indent}| Gap | ${el.spacing.itemSpacing}px |`);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const { paddingTop: pt, paddingRight: pr, paddingBottom: pb, paddingLeft: pl } = el.spacing;
|
|
456
|
+
if (pt || pr || pb || pl) {
|
|
457
|
+
lines.push(`${indent}| Padding | ${pt} / ${pr} / ${pb} / ${pl} |`);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (el.appearance.cornerRadius) {
|
|
461
|
+
const cr = el.appearance.cornerRadius;
|
|
462
|
+
const crStr = typeof cr === "number" ? `${cr}px` : `${cr.join(" / ")}px`;
|
|
463
|
+
if (crStr !== "0px" && crStr !== "0 / 0 / 0 / 0px") {
|
|
464
|
+
lines.push(`${indent}| Border Radius | ${crStr} |`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (el.typography) {
|
|
469
|
+
const t = el.typography;
|
|
470
|
+
lines.push(`${indent}| Font | ${t.fontFamily} ${t.fontWeight} |`);
|
|
471
|
+
lines.push(`${indent}| Font Size | ${t.fontSize}px |`);
|
|
472
|
+
lines.push(`${indent}| Line Height | ${t.lineHeight} |`);
|
|
473
|
+
if (t.letterSpacing) lines.push(`${indent}| Letter Spacing | ${t.letterSpacing}px |`);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
lines.push(``);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Redlines
|
|
480
|
+
if (redlines.length > 0) {
|
|
481
|
+
lines.push(`## Spacing Redlines`);
|
|
482
|
+
lines.push(`| From | To | Direction | Distance |`);
|
|
483
|
+
lines.push(`|------|----|-----------|----------|`);
|
|
484
|
+
for (const r of redlines) {
|
|
485
|
+
lines.push(`| ${r.fromElement} | ${r.toElement} | ${r.direction} | ${r.distance}px |`);
|
|
486
|
+
}
|
|
487
|
+
lines.push(``);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Assets
|
|
491
|
+
if (assets.length > 0 && args.includeAssets !== false) {
|
|
492
|
+
lines.push(`## Assets to Export`);
|
|
493
|
+
lines.push(`| Name | Type | Size | Format |`);
|
|
494
|
+
lines.push(`|------|------|------|--------|`);
|
|
495
|
+
for (const a of assets) {
|
|
496
|
+
lines.push(`| ${a.name} | ${a.type} | ${a.size.width}×${a.size.height} | ${a.suggestedExport} |`);
|
|
497
|
+
}
|
|
498
|
+
lines.push(``);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// CSS snippets
|
|
502
|
+
if (args.includeCss !== false) {
|
|
503
|
+
lines.push(`## CSS Snippets`);
|
|
504
|
+
lines.push(``);
|
|
505
|
+
for (const el of elements) {
|
|
506
|
+
if (el.depth > 2) continue;
|
|
507
|
+
lines.push("```css");
|
|
508
|
+
lines.push(el.cssSnippet);
|
|
509
|
+
lines.push("```");
|
|
510
|
+
lines.push(``);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return lines.join("\n");
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// ─── Figma page renderer ───────────────────────────────────────────────────
|
|
518
|
+
|
|
519
|
+
async function createHandoffPage(
|
|
520
|
+
nodeId: string,
|
|
521
|
+
rootName: string,
|
|
522
|
+
elements: MeasuredElement[],
|
|
523
|
+
redlines: RedlineAnnotation[]
|
|
524
|
+
): Promise<string> {
|
|
525
|
+
const bridge = await getBridge();
|
|
526
|
+
|
|
527
|
+
const result = await bridge.execute(`
|
|
528
|
+
(async () => {
|
|
529
|
+
// Create handoff annotation page
|
|
530
|
+
var pageName = '📐 Handoff: ' + '${rootName.replace(/'/g, "\\'")}';
|
|
531
|
+
var existing = figma.root.children.find(function(p) { return p.name === pageName; });
|
|
532
|
+
if (existing) existing.remove();
|
|
533
|
+
|
|
534
|
+
var page = figma.createPage();
|
|
535
|
+
page.name = pageName;
|
|
536
|
+
figma.currentPage = page;
|
|
537
|
+
|
|
538
|
+
// Title
|
|
539
|
+
var title = figma.createText();
|
|
540
|
+
await figma.loadFontAsync({ family: "Inter", style: "Bold" });
|
|
541
|
+
await figma.loadFontAsync({ family: "Inter", style: "Regular" });
|
|
542
|
+
await figma.loadFontAsync({ family: "Inter", style: "Medium" });
|
|
543
|
+
title.fontName = { family: "Inter", style: "Bold" };
|
|
544
|
+
title.fontSize = 32;
|
|
545
|
+
title.characters = 'Developer Handoff: ${rootName.replace(/'/g, "\\'")}';
|
|
546
|
+
title.x = 40;
|
|
547
|
+
title.y = 40;
|
|
548
|
+
page.appendChild(title);
|
|
549
|
+
|
|
550
|
+
// Subtitle
|
|
551
|
+
var sub = figma.createText();
|
|
552
|
+
sub.fontName = { family: "Inter", style: "Regular" };
|
|
553
|
+
sub.fontSize = 14;
|
|
554
|
+
sub.characters = 'Auto-generated by figma_handoff_spec | ${new Date().toISOString().slice(0, 10)}';
|
|
555
|
+
sub.x = 40;
|
|
556
|
+
sub.y = 90;
|
|
557
|
+
sub.fills = [{ type: 'SOLID', color: { r: 0.4, g: 0.4, b: 0.4 } }];
|
|
558
|
+
page.appendChild(sub);
|
|
559
|
+
|
|
560
|
+
// Clone the source node for reference
|
|
561
|
+
var sourceNode = figma.getNodeById('${nodeId}');
|
|
562
|
+
if (sourceNode) {
|
|
563
|
+
var clone = sourceNode.clone();
|
|
564
|
+
clone.x = 40;
|
|
565
|
+
clone.y = 140;
|
|
566
|
+
page.appendChild(clone);
|
|
567
|
+
|
|
568
|
+
// Add measurement annotations as red lines
|
|
569
|
+
var yOffset = 140 + Math.round(sourceNode.height) + 60;
|
|
570
|
+
|
|
571
|
+
${JSON.stringify(redlines.slice(0, 50))}.forEach(function(r, i) {
|
|
572
|
+
var annotation = figma.createFrame();
|
|
573
|
+
annotation.name = 'Redline: ' + r.label;
|
|
574
|
+
annotation.resize(400, 28);
|
|
575
|
+
annotation.x = 40;
|
|
576
|
+
annotation.y = yOffset + (i * 36);
|
|
577
|
+
annotation.layoutMode = 'HORIZONTAL';
|
|
578
|
+
annotation.itemSpacing = 8;
|
|
579
|
+
annotation.paddingLeft = 8;
|
|
580
|
+
annotation.paddingRight = 8;
|
|
581
|
+
annotation.paddingTop = 4;
|
|
582
|
+
annotation.paddingBottom = 4;
|
|
583
|
+
annotation.fills = [{ type: 'SOLID', color: { r: 1, g: 0.9, b: 0.9 } }];
|
|
584
|
+
annotation.cornerRadius = 4;
|
|
585
|
+
annotation.primaryAxisSizingMode = 'AUTO';
|
|
586
|
+
annotation.counterAxisSizingMode = 'AUTO';
|
|
587
|
+
|
|
588
|
+
var label = figma.createText();
|
|
589
|
+
label.fontName = { family: "Inter", style: "Medium" };
|
|
590
|
+
label.fontSize = 12;
|
|
591
|
+
label.characters = r.fromElement + ' → ' + r.toElement + ': ' + r.label;
|
|
592
|
+
label.fills = [{ type: 'SOLID', color: { r: 0.8, g: 0, b: 0 } }];
|
|
593
|
+
annotation.appendChild(label);
|
|
594
|
+
|
|
595
|
+
page.appendChild(annotation);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// Token summary section
|
|
599
|
+
var tokenY = yOffset + (${Math.min(redlines.length, 50)} * 36) + 40;
|
|
600
|
+
var tokenTitle = figma.createText();
|
|
601
|
+
tokenTitle.fontName = { family: "Inter", style: "Bold" };
|
|
602
|
+
tokenTitle.fontSize = 20;
|
|
603
|
+
tokenTitle.characters = 'Token Reference';
|
|
604
|
+
tokenTitle.x = 40;
|
|
605
|
+
tokenTitle.y = tokenY;
|
|
606
|
+
page.appendChild(tokenTitle);
|
|
607
|
+
|
|
608
|
+
// Token entries
|
|
609
|
+
var tokenEntries = ${JSON.stringify(
|
|
610
|
+
elements.flatMap((el) => el.tokens).filter((t, i, arr) =>
|
|
611
|
+
arr.findIndex((o) => o.tokenName === t.tokenName) === i
|
|
612
|
+
).slice(0, 40)
|
|
613
|
+
)};
|
|
614
|
+
|
|
615
|
+
tokenEntries.forEach(function(t, i) {
|
|
616
|
+
var entry = figma.createText();
|
|
617
|
+
entry.fontName = { family: "Inter", style: "Regular" };
|
|
618
|
+
entry.fontSize = 12;
|
|
619
|
+
entry.characters = t.property + ' → ' + t.tokenName + ' = ' + t.rawValue;
|
|
620
|
+
entry.x = 60;
|
|
621
|
+
entry.y = tokenY + 36 + (i * 20);
|
|
622
|
+
entry.fills = [{ type: 'SOLID', color: { r: 0.2, g: 0.2, b: 0.2 } }];
|
|
623
|
+
page.appendChild(entry);
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
return { pageId: page.id, pageName: page.name };
|
|
628
|
+
})();
|
|
629
|
+
`);
|
|
630
|
+
|
|
631
|
+
if (!result.success || !result.result) {
|
|
632
|
+
throw new Error(result.error || "Failed to create handoff page");
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
return (result.result as { pageId: string }).pageId;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// ─── Main handler ──────────────────────────────────────────────────────────
|
|
639
|
+
|
|
640
|
+
export async function handoffSpecHandler(args: HandoffSpecArgs): Promise<unknown> {
|
|
641
|
+
const maxDepth = args.maxDepth ?? 6;
|
|
642
|
+
const cssUnit = args.cssUnit ?? "px";
|
|
643
|
+
const remBase = args.remBase ?? 16;
|
|
644
|
+
|
|
645
|
+
const { elements, assets, redlines, rootName, rootBounds } = await extractNodeTree(
|
|
646
|
+
args.nodeId,
|
|
647
|
+
maxDepth
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
// Generate CSS snippets for each element
|
|
651
|
+
for (const el of elements) {
|
|
652
|
+
el.cssSnippet = generateElementCss(el, cssUnit, remBase);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
const outputs: Record<string, unknown> = {};
|
|
656
|
+
|
|
657
|
+
// JSON
|
|
658
|
+
if (args.outputFormat === "json" || args.outputFormat === "all") {
|
|
659
|
+
outputs.spec = {
|
|
660
|
+
component: rootName,
|
|
661
|
+
dimensions: rootBounds,
|
|
662
|
+
elements: elements.map((el) => ({
|
|
663
|
+
name: el.name,
|
|
664
|
+
type: el.type,
|
|
665
|
+
depth: el.depth,
|
|
666
|
+
bounds: el.bounds,
|
|
667
|
+
spacing: el.spacing,
|
|
668
|
+
tokens: el.tokens,
|
|
669
|
+
typography: el.typography,
|
|
670
|
+
css: el.cssSnippet,
|
|
671
|
+
})),
|
|
672
|
+
redlines,
|
|
673
|
+
assets,
|
|
674
|
+
tokenSummary: {
|
|
675
|
+
total: elements.reduce((sum, el) => sum + el.tokens.length, 0),
|
|
676
|
+
unique: [...new Set(elements.flatMap((el) => el.tokens.map((t) => t.tokenName)))],
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Markdown
|
|
682
|
+
if (args.outputFormat === "markdown" || args.outputFormat === "all") {
|
|
683
|
+
outputs.markdown = renderMarkdown(rootName, rootBounds, elements, redlines, assets, args);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Figma page
|
|
687
|
+
let figmaPageId: string | undefined;
|
|
688
|
+
if (args.outputFormat === "figma-page" || args.outputFormat === "all") {
|
|
689
|
+
figmaPageId = await createHandoffPage(args.nodeId, rootName, elements, redlines);
|
|
690
|
+
outputs.figmaPageId = figmaPageId;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return {
|
|
694
|
+
component: rootName,
|
|
695
|
+
dimensions: rootBounds,
|
|
696
|
+
elementCount: elements.length,
|
|
697
|
+
tokenCount: elements.reduce((sum, el) => sum + el.tokens.length, 0),
|
|
698
|
+
assetCount: assets.length,
|
|
699
|
+
redlineCount: redlines.length,
|
|
700
|
+
...outputs,
|
|
701
|
+
};
|
|
702
|
+
}
|