@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,596 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// Animation Specifier
|
|
3
|
+
// Extracts prototype animation data from Figma connections and generates
|
|
4
|
+
// production-ready animation code for framer-motion, CSS, Swift, and Android.
|
|
5
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
import { getBridge } from "../../../shared/figma-bridge.js";
|
|
8
|
+
import { decisionLog } from "../../../shared/decision-log.js";
|
|
9
|
+
|
|
10
|
+
// ─── Public types ─────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
export interface AnimationSpecifierArgs {
|
|
13
|
+
fileKey?: string;
|
|
14
|
+
frameNodeId?: string;
|
|
15
|
+
outputFormat: "json" | "framer-motion" | "css" | "swift" | "android" | "all";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AnimationSpec {
|
|
19
|
+
name: string;
|
|
20
|
+
fromId: string;
|
|
21
|
+
toId: string;
|
|
22
|
+
duration: number;
|
|
23
|
+
easing: string;
|
|
24
|
+
easingValues: number[];
|
|
25
|
+
direction: string;
|
|
26
|
+
type: string;
|
|
27
|
+
isSpring: boolean;
|
|
28
|
+
springStiffness?: number;
|
|
29
|
+
springDamping?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AnimationSpecifierResult {
|
|
33
|
+
animations: AnimationSpec[];
|
|
34
|
+
code: {
|
|
35
|
+
json?: string;
|
|
36
|
+
framerMotion?: string;
|
|
37
|
+
css?: string;
|
|
38
|
+
swift?: string;
|
|
39
|
+
android?: string;
|
|
40
|
+
};
|
|
41
|
+
totalConnections: number;
|
|
42
|
+
animatedConnections: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ─── Easing maps ──────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
const EASING_CSS_MAP: Record<string, string> = {
|
|
48
|
+
EASE_IN: "cubic-bezier(0.4, 0, 1, 1)",
|
|
49
|
+
EASE_OUT: "cubic-bezier(0, 0, 0.2, 1)",
|
|
50
|
+
EASE_IN_OUT: "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
51
|
+
LINEAR: "cubic-bezier(0, 0, 1, 1)",
|
|
52
|
+
SPRING: "cubic-bezier(0.4, 0, 0.2, 1)", // approximation for CSS
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const EASING_SWIFT_MAP: Record<string, string> = {
|
|
56
|
+
EASE_IN: ".easeIn",
|
|
57
|
+
EASE_OUT: ".easeOut",
|
|
58
|
+
EASE_IN_OUT: ".easeInOut",
|
|
59
|
+
LINEAR: ".linear",
|
|
60
|
+
SPRING: ".spring(response: 0.4, dampingFraction: 0.7)",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const EASING_CUBIC_MAP: Record<string, number[]> = {
|
|
64
|
+
EASE_IN: [0.4, 0, 1, 1],
|
|
65
|
+
EASE_OUT: [0, 0, 0.2, 1],
|
|
66
|
+
EASE_IN_OUT: [0.4, 0, 0.2, 1],
|
|
67
|
+
LINEAR: [0, 0, 1, 1],
|
|
68
|
+
SPRING: [0.4, 0, 0.2, 1],
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ─── Connection parser ────────────────────────────────────────────────────────
|
|
72
|
+
|
|
73
|
+
interface RawConnection {
|
|
74
|
+
fromId: string;
|
|
75
|
+
fromName: string;
|
|
76
|
+
toId: string;
|
|
77
|
+
toName: string;
|
|
78
|
+
trigger: Record<string, unknown>;
|
|
79
|
+
action: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function sanitizeName(name: string): string {
|
|
83
|
+
return name
|
|
84
|
+
.replace(/[^a-zA-Z0-9_\s]/g, "")
|
|
85
|
+
.trim()
|
|
86
|
+
.replace(/\s+(.)/g, (_, c: string) => c.toUpperCase())
|
|
87
|
+
.replace(/^\w/, (c) => c.toLowerCase());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function detectEasing(action: Record<string, unknown>): string {
|
|
91
|
+
const transition = action["transition"] as Record<string, unknown> | undefined;
|
|
92
|
+
if (!transition) return "EASE_IN_OUT";
|
|
93
|
+
|
|
94
|
+
const easing = transition["easing"] as Record<string, unknown> | string | undefined;
|
|
95
|
+
if (!easing) return "EASE_IN_OUT";
|
|
96
|
+
|
|
97
|
+
if (typeof easing === "string") return easing;
|
|
98
|
+
|
|
99
|
+
const type = (easing["type"] as string | undefined)?.toUpperCase();
|
|
100
|
+
if (!type) return "EASE_IN_OUT";
|
|
101
|
+
|
|
102
|
+
if (type.includes("SPRING") || type === "SPRING_PRESET") return "SPRING";
|
|
103
|
+
if (type.includes("EASE_IN_AND_OUT") || type.includes("EASE_IN_OUT")) return "EASE_IN_OUT";
|
|
104
|
+
if (type.includes("EASE_IN")) return "EASE_IN";
|
|
105
|
+
if (type.includes("EASE_OUT")) return "EASE_OUT";
|
|
106
|
+
if (type.includes("LINEAR")) return "LINEAR";
|
|
107
|
+
return "EASE_IN_OUT";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function detectTransitionType(action: Record<string, unknown>): { type: string; direction: string } {
|
|
111
|
+
const transition = action["transition"] as Record<string, unknown> | undefined;
|
|
112
|
+
if (!transition) return { type: "DISSOLVE", direction: "none" };
|
|
113
|
+
|
|
114
|
+
const rawType = (transition["type"] as string | undefined)?.toUpperCase() ?? "DISSOLVE";
|
|
115
|
+
const direction = (transition["direction"] as string | undefined)?.toUpperCase() ?? "none";
|
|
116
|
+
|
|
117
|
+
return { type: rawType, direction };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function parseConnections(connections: RawConnection[]): AnimationSpec[] {
|
|
121
|
+
const specs: AnimationSpec[] = [];
|
|
122
|
+
|
|
123
|
+
for (const conn of connections) {
|
|
124
|
+
const transition = (conn.action["transition"] as Record<string, unknown> | undefined);
|
|
125
|
+
if (!transition) continue;
|
|
126
|
+
|
|
127
|
+
const durationRaw = transition["duration"] as number | undefined;
|
|
128
|
+
const duration = typeof durationRaw === "number" ? durationRaw : 0.3;
|
|
129
|
+
|
|
130
|
+
const easingKey = detectEasing(conn.action);
|
|
131
|
+
const { type, direction } = detectTransitionType(conn.action);
|
|
132
|
+
const isSpring = easingKey === "SPRING";
|
|
133
|
+
|
|
134
|
+
const spec: AnimationSpec = {
|
|
135
|
+
name: sanitizeName(`${conn.fromName}To${conn.toName}`),
|
|
136
|
+
fromId: conn.fromId,
|
|
137
|
+
toId: conn.toId,
|
|
138
|
+
duration,
|
|
139
|
+
easing: easingKey,
|
|
140
|
+
easingValues: EASING_CUBIC_MAP[easingKey] ?? [0.4, 0, 0.2, 1],
|
|
141
|
+
direction,
|
|
142
|
+
type,
|
|
143
|
+
isSpring,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
if (isSpring) {
|
|
147
|
+
spec.springStiffness = 300;
|
|
148
|
+
spec.springDamping = 30;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
specs.push(spec);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return specs;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ─── Code generators ──────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
function getSlideAxis(type: string, direction: string): { axis: "x" | "y"; sign: number } {
|
|
160
|
+
const dir = direction.toUpperCase();
|
|
161
|
+
|
|
162
|
+
if (type === "PUSH" || type === "SLIDE_IN" || type === "SLIDE_OUT" ||
|
|
163
|
+
type === "MOVE_IN" || type === "MOVE_OUT") {
|
|
164
|
+
if (dir === "LEFT") return { axis: "x", sign: -1 };
|
|
165
|
+
if (dir === "RIGHT") return { axis: "x", sign: 1 };
|
|
166
|
+
if (dir === "UP") return { axis: "y", sign: -1 };
|
|
167
|
+
if (dir === "DOWN") return { axis: "y", sign: 1 };
|
|
168
|
+
}
|
|
169
|
+
return { axis: "x", sign: 1 };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function getClosedVariant(spec: AnimationSpec): Record<string, unknown> {
|
|
173
|
+
const type = spec.type.toUpperCase();
|
|
174
|
+
const dir = spec.direction.toUpperCase();
|
|
175
|
+
|
|
176
|
+
if (type === "DISSOLVE") {
|
|
177
|
+
return { opacity: 0 };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (type === "SMART_ANIMATE") {
|
|
181
|
+
return { opacity: 0, scale: 0.95 };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (
|
|
185
|
+
type === "PUSH" || type === "SLIDE_IN" || type === "SLIDE_OUT" ||
|
|
186
|
+
type === "MOVE_IN" || type === "MOVE_OUT"
|
|
187
|
+
) {
|
|
188
|
+
const { axis, sign } = getSlideAxis(type, dir);
|
|
189
|
+
const closed: Record<string, unknown> = { opacity: 0 };
|
|
190
|
+
closed[axis] = sign * 100;
|
|
191
|
+
return closed;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return { opacity: 0 };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function generateFramerMotion(specs: AnimationSpec[]): string {
|
|
198
|
+
const lines: string[] = [
|
|
199
|
+
'// Generated by figma-intelligence-layer animation-specifier',
|
|
200
|
+
'import { Variants } from "framer-motion";',
|
|
201
|
+
"",
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
for (const spec of specs) {
|
|
205
|
+
const varName = `${spec.name}Variants`;
|
|
206
|
+
const closedVariant = getClosedVariant(spec);
|
|
207
|
+
const openVariant: Record<string, unknown> = { opacity: 1 };
|
|
208
|
+
|
|
209
|
+
// Mirror positional closed values to zero in open
|
|
210
|
+
for (const key of Object.keys(closedVariant)) {
|
|
211
|
+
if (key !== "opacity" && key !== "scale") openVariant[key] = 0;
|
|
212
|
+
if (key === "scale") openVariant[key] = 1;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let transition: Record<string, unknown>;
|
|
216
|
+
if (spec.isSpring) {
|
|
217
|
+
transition = {
|
|
218
|
+
type: "spring",
|
|
219
|
+
stiffness: spec.springStiffness ?? 300,
|
|
220
|
+
damping: spec.springDamping ?? 30,
|
|
221
|
+
};
|
|
222
|
+
} else {
|
|
223
|
+
transition = {
|
|
224
|
+
duration: spec.duration,
|
|
225
|
+
ease: spec.easingValues,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
lines.push(`export const ${varName}: Variants = {`);
|
|
230
|
+
lines.push(` closed: ${JSON.stringify(closedVariant)},`);
|
|
231
|
+
lines.push(` open: {`);
|
|
232
|
+
lines.push(` ...${JSON.stringify(openVariant)},`);
|
|
233
|
+
lines.push(` transition: ${JSON.stringify(transition)},`);
|
|
234
|
+
lines.push(` },`);
|
|
235
|
+
lines.push(`};`);
|
|
236
|
+
lines.push("");
|
|
237
|
+
|
|
238
|
+
// Add a helper component usage comment
|
|
239
|
+
lines.push(`// Usage: <motion.div variants={${varName}} initial="closed" animate="open" />`);
|
|
240
|
+
lines.push("");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return lines.join("\n");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function generateCSS(specs: AnimationSpec[]): string {
|
|
247
|
+
const lines: string[] = [
|
|
248
|
+
"/* Generated by figma-intelligence-layer animation-specifier */",
|
|
249
|
+
"",
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
for (const spec of specs) {
|
|
253
|
+
const type = spec.type.toUpperCase();
|
|
254
|
+
const dir = spec.direction.toUpperCase();
|
|
255
|
+
const name = spec.name;
|
|
256
|
+
const durationMs = Math.round(spec.duration * 1000);
|
|
257
|
+
const easingCss = EASING_CSS_MAP[spec.easing] ?? "ease-in-out";
|
|
258
|
+
|
|
259
|
+
if (type === "DISSOLVE") {
|
|
260
|
+
lines.push(`@keyframes ${name}FadeIn {`);
|
|
261
|
+
lines.push(` from { opacity: 0; }`);
|
|
262
|
+
lines.push(` to { opacity: 1; }`);
|
|
263
|
+
lines.push(`}`);
|
|
264
|
+
lines.push("");
|
|
265
|
+
lines.push(`.${name} {`);
|
|
266
|
+
lines.push(` animation: ${name}FadeIn ${durationMs}ms ${easingCss} forwards;`);
|
|
267
|
+
lines.push(`}`);
|
|
268
|
+
} else if (type === "SMART_ANIMATE") {
|
|
269
|
+
lines.push(`@keyframes ${name}Morph {`);
|
|
270
|
+
lines.push(` from { opacity: 0; transform: scale(0.95); }`);
|
|
271
|
+
lines.push(` to { opacity: 1; transform: scale(1); }`);
|
|
272
|
+
lines.push(`}`);
|
|
273
|
+
lines.push("");
|
|
274
|
+
lines.push(`.${name} {`);
|
|
275
|
+
lines.push(` animation: ${name}Morph ${durationMs}ms ${easingCss} forwards;`);
|
|
276
|
+
lines.push(`}`);
|
|
277
|
+
} else if (
|
|
278
|
+
type === "PUSH" || type === "SLIDE_IN" || type === "SLIDE_OUT" ||
|
|
279
|
+
type === "MOVE_IN" || type === "MOVE_OUT"
|
|
280
|
+
) {
|
|
281
|
+
const { axis, sign } = getSlideAxis(type, dir);
|
|
282
|
+
const translateFn = axis === "x" ? "translateX" : "translateY";
|
|
283
|
+
const fromVal = `${sign * 100}%`;
|
|
284
|
+
|
|
285
|
+
lines.push(`@keyframes ${name}SlideIn {`);
|
|
286
|
+
lines.push(` from { opacity: 0; transform: ${translateFn}(${fromVal}); }`);
|
|
287
|
+
lines.push(` to { opacity: 1; transform: ${translateFn}(0); }`);
|
|
288
|
+
lines.push(`}`);
|
|
289
|
+
lines.push("");
|
|
290
|
+
lines.push(`.${name} {`);
|
|
291
|
+
lines.push(` animation: ${name}SlideIn ${durationMs}ms ${easingCss} forwards;`);
|
|
292
|
+
lines.push(`}`);
|
|
293
|
+
} else {
|
|
294
|
+
lines.push(`@keyframes ${name} {`);
|
|
295
|
+
lines.push(` from { opacity: 0; }`);
|
|
296
|
+
lines.push(` to { opacity: 1; }`);
|
|
297
|
+
lines.push(`}`);
|
|
298
|
+
lines.push("");
|
|
299
|
+
lines.push(`.${name} {`);
|
|
300
|
+
lines.push(` animation: ${name} ${durationMs}ms ${easingCss} forwards;`);
|
|
301
|
+
lines.push(`}`);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
lines.push("");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return lines.join("\n");
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function generateSwift(specs: AnimationSpec[]): string {
|
|
311
|
+
const lines: string[] = [
|
|
312
|
+
"// Generated by figma-intelligence-layer animation-specifier",
|
|
313
|
+
"import SwiftUI",
|
|
314
|
+
"import UIKit",
|
|
315
|
+
"",
|
|
316
|
+
"// MARK: - SwiftUI Animations",
|
|
317
|
+
"",
|
|
318
|
+
];
|
|
319
|
+
|
|
320
|
+
for (const spec of specs) {
|
|
321
|
+
const type = spec.type.toUpperCase();
|
|
322
|
+
const dir = spec.direction.toUpperCase();
|
|
323
|
+
const swiftEasing = EASING_SWIFT_MAP[spec.easing] ?? ".easeInOut";
|
|
324
|
+
const durationStr = spec.duration.toFixed(3);
|
|
325
|
+
const name = spec.name;
|
|
326
|
+
|
|
327
|
+
lines.push(`// Transition: ${spec.fromId} → ${spec.toId}`);
|
|
328
|
+
|
|
329
|
+
if (spec.isSpring) {
|
|
330
|
+
lines.push(`func ${name}Animation(isVisible: Binding<Bool>) -> some View {`);
|
|
331
|
+
lines.push(` content`);
|
|
332
|
+
lines.push(` .opacity(isVisible.wrappedValue ? 1 : 0)`);
|
|
333
|
+
lines.push(` .animation(.spring(response: ${durationStr}, dampingFraction: 0.7), value: isVisible.wrappedValue)`);
|
|
334
|
+
lines.push(`}`);
|
|
335
|
+
} else if (type === "DISSOLVE") {
|
|
336
|
+
lines.push(`func ${name}Animation(isVisible: Binding<Bool>) -> some View {`);
|
|
337
|
+
lines.push(` content`);
|
|
338
|
+
lines.push(` .opacity(isVisible.wrappedValue ? 1 : 0)`);
|
|
339
|
+
lines.push(` .animation(.easeInOut(duration: ${durationStr}), value: isVisible.wrappedValue)`);
|
|
340
|
+
lines.push(`}`);
|
|
341
|
+
} else if (type === "SMART_ANIMATE") {
|
|
342
|
+
lines.push(`func ${name}Animation(isVisible: Binding<Bool>) -> some View {`);
|
|
343
|
+
lines.push(` content`);
|
|
344
|
+
lines.push(` .opacity(isVisible.wrappedValue ? 1 : 0)`);
|
|
345
|
+
lines.push(` .scaleEffect(isVisible.wrappedValue ? 1 : 0.95)`);
|
|
346
|
+
lines.push(` .animation(${swiftEasing}(duration: ${durationStr}), value: isVisible.wrappedValue)`);
|
|
347
|
+
lines.push(`}`);
|
|
348
|
+
} else if (
|
|
349
|
+
type === "PUSH" || type === "SLIDE_IN" || type === "SLIDE_OUT" ||
|
|
350
|
+
type === "MOVE_IN" || type === "MOVE_OUT"
|
|
351
|
+
) {
|
|
352
|
+
const isHorizontal = dir === "LEFT" || dir === "RIGHT";
|
|
353
|
+
const offsetEdge = dir === "LEFT" ? "-UIScreen.main.bounds.width"
|
|
354
|
+
: dir === "RIGHT" ? "UIScreen.main.bounds.width"
|
|
355
|
+
: dir === "UP" ? "-UIScreen.main.bounds.height"
|
|
356
|
+
: "UIScreen.main.bounds.height";
|
|
357
|
+
|
|
358
|
+
lines.push(`func ${name}Animation(isVisible: Binding<Bool>) -> some View {`);
|
|
359
|
+
if (isHorizontal) {
|
|
360
|
+
lines.push(` content`);
|
|
361
|
+
lines.push(` .offset(x: isVisible.wrappedValue ? 0 : ${offsetEdge})`);
|
|
362
|
+
lines.push(` .opacity(isVisible.wrappedValue ? 1 : 0)`);
|
|
363
|
+
lines.push(` .animation(${swiftEasing}(duration: ${durationStr}), value: isVisible.wrappedValue)`);
|
|
364
|
+
} else {
|
|
365
|
+
lines.push(` content`);
|
|
366
|
+
lines.push(` .offset(y: isVisible.wrappedValue ? 0 : ${offsetEdge})`);
|
|
367
|
+
lines.push(` .opacity(isVisible.wrappedValue ? 1 : 0)`);
|
|
368
|
+
lines.push(` .animation(${swiftEasing}(duration: ${durationStr}), value: isVisible.wrappedValue)`);
|
|
369
|
+
}
|
|
370
|
+
lines.push(`}`);
|
|
371
|
+
} else {
|
|
372
|
+
lines.push(`func ${name}Animation(isVisible: Binding<Bool>) -> some View {`);
|
|
373
|
+
lines.push(` content`);
|
|
374
|
+
lines.push(` .opacity(isVisible.wrappedValue ? 1 : 0)`);
|
|
375
|
+
lines.push(` .animation(${swiftEasing}(duration: ${durationStr}), value: isVisible.wrappedValue)`);
|
|
376
|
+
lines.push(`}`);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
lines.push("");
|
|
380
|
+
|
|
381
|
+
// UIKit version
|
|
382
|
+
lines.push(`// UIKit equivalent for ${name}`);
|
|
383
|
+
lines.push(`func ${name}UIKitAnimate(view: UIView, isShowing: Bool) {`);
|
|
384
|
+
if (spec.isSpring) {
|
|
385
|
+
lines.push(` let animator = UIViewPropertyAnimator(duration: ${durationStr}, dampingRatio: 0.7) {`);
|
|
386
|
+
lines.push(` view.alpha = isShowing ? 1 : 0`);
|
|
387
|
+
lines.push(` view.transform = isShowing ? .identity : CGAffineTransform(scaleX: 0.95, y: 0.95)`);
|
|
388
|
+
lines.push(` }`);
|
|
389
|
+
} else {
|
|
390
|
+
lines.push(` let animator = UIViewPropertyAnimator(duration: ${durationStr}, curve: ${swiftEasing.replace(".", ".")}) {`);
|
|
391
|
+
lines.push(` view.alpha = isShowing ? 1 : 0`);
|
|
392
|
+
lines.push(` }`);
|
|
393
|
+
}
|
|
394
|
+
lines.push(` animator.startAnimation()`);
|
|
395
|
+
lines.push(`}`);
|
|
396
|
+
lines.push("");
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return lines.join("\n");
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function generateAndroid(specs: AnimationSpec[]): string {
|
|
403
|
+
const lines: string[] = [
|
|
404
|
+
"// Generated by figma-intelligence-layer animation-specifier",
|
|
405
|
+
"// Kotlin — place these in your animation utilities file",
|
|
406
|
+
"",
|
|
407
|
+
"import android.animation.AnimatorSet",
|
|
408
|
+
"import android.animation.ObjectAnimator",
|
|
409
|
+
"import android.view.View",
|
|
410
|
+
"import android.view.animation.AccelerateDecelerateInterpolator",
|
|
411
|
+
"import android.view.animation.AccelerateInterpolator",
|
|
412
|
+
"import android.view.animation.DecelerateInterpolator",
|
|
413
|
+
"import android.view.animation.LinearInterpolator",
|
|
414
|
+
"import androidx.interpolator.view.animation.FastOutSlowInInterpolator",
|
|
415
|
+
"",
|
|
416
|
+
"object FigmaAnimations {",
|
|
417
|
+
"",
|
|
418
|
+
];
|
|
419
|
+
|
|
420
|
+
for (const spec of specs) {
|
|
421
|
+
const type = spec.type.toUpperCase();
|
|
422
|
+
const dir = spec.direction.toUpperCase();
|
|
423
|
+
const durationMs = Math.round(spec.duration * 1000);
|
|
424
|
+
const name = spec.name;
|
|
425
|
+
|
|
426
|
+
const interpolatorMap: Record<string, string> = {
|
|
427
|
+
EASE_IN: "AccelerateInterpolator()",
|
|
428
|
+
EASE_OUT: "DecelerateInterpolator()",
|
|
429
|
+
EASE_IN_OUT: "FastOutSlowInInterpolator()",
|
|
430
|
+
LINEAR: "LinearInterpolator()",
|
|
431
|
+
SPRING: "FastOutSlowInInterpolator()",
|
|
432
|
+
};
|
|
433
|
+
const interpolator = interpolatorMap[spec.easing] ?? "FastOutSlowInInterpolator()";
|
|
434
|
+
|
|
435
|
+
lines.push(` // ${spec.fromId} → ${spec.toId}`);
|
|
436
|
+
lines.push(` fun ${name}(view: View, isEntering: Boolean) {`);
|
|
437
|
+
|
|
438
|
+
if (type === "DISSOLVE") {
|
|
439
|
+
lines.push(` val alpha = ObjectAnimator.ofFloat(`);
|
|
440
|
+
lines.push(` view, "alpha", if (isEntering) 0f else 1f, if (isEntering) 1f else 0f`);
|
|
441
|
+
lines.push(` )`);
|
|
442
|
+
lines.push(` alpha.duration = ${durationMs}L`);
|
|
443
|
+
lines.push(` alpha.interpolator = ${interpolator}`);
|
|
444
|
+
lines.push(` alpha.start()`);
|
|
445
|
+
} else if (type === "SMART_ANIMATE") {
|
|
446
|
+
lines.push(` val alpha = ObjectAnimator.ofFloat(`);
|
|
447
|
+
lines.push(` view, "alpha", if (isEntering) 0f else 1f, if (isEntering) 1f else 0f`);
|
|
448
|
+
lines.push(` )`);
|
|
449
|
+
lines.push(` val scaleX = ObjectAnimator.ofFloat(`);
|
|
450
|
+
lines.push(` view, "scaleX", if (isEntering) 0.95f else 1f, if (isEntering) 1f else 0.95f`);
|
|
451
|
+
lines.push(` )`);
|
|
452
|
+
lines.push(` val scaleY = ObjectAnimator.ofFloat(`);
|
|
453
|
+
lines.push(` view, "scaleY", if (isEntering) 0.95f else 1f, if (isEntering) 1f else 0.95f`);
|
|
454
|
+
lines.push(` )`);
|
|
455
|
+
lines.push(` val set = AnimatorSet()`);
|
|
456
|
+
lines.push(` set.playTogether(alpha, scaleX, scaleY)`);
|
|
457
|
+
lines.push(` set.duration = ${durationMs}L`);
|
|
458
|
+
lines.push(` set.interpolator = ${interpolator}`);
|
|
459
|
+
lines.push(` set.start()`);
|
|
460
|
+
} else if (
|
|
461
|
+
type === "PUSH" || type === "SLIDE_IN" || type === "SLIDE_OUT" ||
|
|
462
|
+
type === "MOVE_IN" || type === "MOVE_OUT"
|
|
463
|
+
) {
|
|
464
|
+
const { axis, sign } = getSlideAxis(type, dir);
|
|
465
|
+
const property = axis === "x" ? "translationX" : "translationY";
|
|
466
|
+
const fromExpr = `if (isEntering) ${sign * 500}f else 0f`;
|
|
467
|
+
const toExpr = `if (isEntering) 0f else ${sign * 500}f`;
|
|
468
|
+
|
|
469
|
+
lines.push(` val translate = ObjectAnimator.ofFloat(`);
|
|
470
|
+
lines.push(` view, "${property}", ${fromExpr}, ${toExpr}`);
|
|
471
|
+
lines.push(` )`);
|
|
472
|
+
lines.push(` val alpha = ObjectAnimator.ofFloat(`);
|
|
473
|
+
lines.push(` view, "alpha", if (isEntering) 0f else 1f, if (isEntering) 1f else 0f`);
|
|
474
|
+
lines.push(` )`);
|
|
475
|
+
lines.push(` val set = AnimatorSet()`);
|
|
476
|
+
lines.push(` set.playTogether(translate, alpha)`);
|
|
477
|
+
lines.push(` set.duration = ${durationMs}L`);
|
|
478
|
+
lines.push(` set.interpolator = ${interpolator}`);
|
|
479
|
+
lines.push(` set.start()`);
|
|
480
|
+
} else {
|
|
481
|
+
lines.push(` val alpha = ObjectAnimator.ofFloat(`);
|
|
482
|
+
lines.push(` view, "alpha", if (isEntering) 0f else 1f, if (isEntering) 1f else 0f`);
|
|
483
|
+
lines.push(` )`);
|
|
484
|
+
lines.push(` alpha.duration = ${durationMs}L`);
|
|
485
|
+
lines.push(` alpha.interpolator = ${interpolator}`);
|
|
486
|
+
lines.push(` alpha.start()`);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
lines.push(` }`);
|
|
490
|
+
lines.push("");
|
|
491
|
+
|
|
492
|
+
// XML resource comment
|
|
493
|
+
lines.push(` /*`);
|
|
494
|
+
lines.push(` * res/animator/${name.toLowerCase()}.xml`);
|
|
495
|
+
lines.push(` * <set xmlns:android="http://schemas.android.com/apk/res/android">`);
|
|
496
|
+
|
|
497
|
+
if (type === "DISSOLVE") {
|
|
498
|
+
lines.push(` * <objectAnimator android:propertyName="alpha"`);
|
|
499
|
+
lines.push(` * android:valueFrom="0" android:valueTo="1"`);
|
|
500
|
+
lines.push(` * android:duration="${durationMs}" />`);
|
|
501
|
+
} else if (
|
|
502
|
+
type === "PUSH" || type === "SLIDE_IN" || type === "SLIDE_OUT" ||
|
|
503
|
+
type === "MOVE_IN" || type === "MOVE_OUT"
|
|
504
|
+
) {
|
|
505
|
+
const { axis, sign } = getSlideAxis(type, dir);
|
|
506
|
+
const property = axis === "x" ? "translationX" : "translationY";
|
|
507
|
+
lines.push(` * <objectAnimator android:propertyName="${property}"`);
|
|
508
|
+
lines.push(` * android:valueFrom="${sign * 500}" android:valueTo="0"`);
|
|
509
|
+
lines.push(` * android:duration="${durationMs}" />`);
|
|
510
|
+
lines.push(` * <objectAnimator android:propertyName="alpha"`);
|
|
511
|
+
lines.push(` * android:valueFrom="0" android:valueTo="1"`);
|
|
512
|
+
lines.push(` * android:duration="${durationMs}" />`);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
lines.push(` * </set>`);
|
|
516
|
+
lines.push(` */`);
|
|
517
|
+
lines.push("");
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
lines.push("}");
|
|
521
|
+
return lines.join("\n");
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// ─── Main handler ─────────────────────────────────────────────────────────────
|
|
525
|
+
|
|
526
|
+
export async function animationSpecifierHandler(
|
|
527
|
+
args: AnimationSpecifierArgs
|
|
528
|
+
): Promise<AnimationSpecifierResult> {
|
|
529
|
+
const { frameNodeId, outputFormat } = args;
|
|
530
|
+
|
|
531
|
+
const bridge = await getBridge();
|
|
532
|
+
|
|
533
|
+
// 1. Retrieve all prototype connections
|
|
534
|
+
let rawConnections = await bridge.getPrototypeConnections();
|
|
535
|
+
|
|
536
|
+
// 2. Filter to the requested frame if specified
|
|
537
|
+
if (frameNodeId) {
|
|
538
|
+
rawConnections = rawConnections.filter(
|
|
539
|
+
(c) => c.fromId === frameNodeId || c.toId === frameNodeId
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const totalConnections = rawConnections.length;
|
|
544
|
+
|
|
545
|
+
// 3. Filter to connections that carry animation data
|
|
546
|
+
const animatedRaw = rawConnections.filter((c) => {
|
|
547
|
+
const transition = (c.action["transition"] as Record<string, unknown> | undefined);
|
|
548
|
+
return transition !== undefined && transition !== null;
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
const animatedConnections = animatedRaw.length;
|
|
552
|
+
|
|
553
|
+
// 4. Parse into AnimationSpec objects
|
|
554
|
+
const animations = parseConnections(animatedRaw);
|
|
555
|
+
|
|
556
|
+
// 5. Generate code in the requested format(s)
|
|
557
|
+
const code: AnimationSpecifierResult["code"] = {};
|
|
558
|
+
const needsAll = outputFormat === "all";
|
|
559
|
+
|
|
560
|
+
if (outputFormat === "json" || needsAll) {
|
|
561
|
+
code.json = JSON.stringify(animations, null, 2);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (outputFormat === "framer-motion" || needsAll) {
|
|
565
|
+
code.framerMotion = generateFramerMotion(animations);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (outputFormat === "css" || needsAll) {
|
|
569
|
+
code.css = generateCSS(animations);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (outputFormat === "swift" || needsAll) {
|
|
573
|
+
code.swift = generateSwift(animations);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (outputFormat === "android" || needsAll) {
|
|
577
|
+
code.android = generateAndroid(animations);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// 6. Log the action
|
|
581
|
+
await decisionLog.log({
|
|
582
|
+
tool: "animation-specifier",
|
|
583
|
+
nodeIds: frameNodeId ? [frameNodeId] : animations.map((a) => a.fromId).slice(0, 20),
|
|
584
|
+
rationale: `Extracted ${animatedConnections} animated prototype connections from ${totalConnections} total. Generated ${outputFormat} animation code for ${animations.length} transitions.`,
|
|
585
|
+
reversible: false,
|
|
586
|
+
metadata: {
|
|
587
|
+
frameNodeId,
|
|
588
|
+
outputFormat,
|
|
589
|
+
totalConnections,
|
|
590
|
+
animatedConnections,
|
|
591
|
+
animationCount: animations.length,
|
|
592
|
+
},
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
return { animations, code, totalConnections, animatedConnections };
|
|
596
|
+
}
|