@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.
Files changed (286) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +327 -0
  3. package/bin/cli.js +859 -0
  4. package/design-bridge/.env.example +5 -0
  5. package/design-bridge/bridge.js +196 -0
  6. package/design-bridge/lib/assets.js +367 -0
  7. package/design-bridge/lib/prompt.js +85 -0
  8. package/design-bridge/lib/server.js +66 -0
  9. package/design-bridge/lib/stitch.js +37 -0
  10. package/design-bridge/lib/tokens.js +82 -0
  11. package/design-bridge/package-lock.json +579 -0
  12. package/design-bridge/package.json +19 -0
  13. package/figma-bridge-plugin/README.md +97 -0
  14. package/figma-bridge-plugin/anthropic-chat-runner.js +192 -0
  15. package/figma-bridge-plugin/bridge-relay.js +2363 -0
  16. package/figma-bridge-plugin/chat-runner.js +459 -0
  17. package/figma-bridge-plugin/code.js +1528 -0
  18. package/figma-bridge-plugin/codex-runner.js +505 -0
  19. package/figma-bridge-plugin/component-schemas.js +110 -0
  20. package/figma-bridge-plugin/content-context.js +869 -0
  21. package/figma-bridge-plugin/create-button.js +216 -0
  22. package/figma-bridge-plugin/gemini-cli-runner.js +291 -0
  23. package/figma-bridge-plugin/gemini-runner.js +187 -0
  24. package/figma-bridge-plugin/html-to-figma.js +927 -0
  25. package/figma-bridge-plugin/knowledge-hub/.gitkeep +0 -0
  26. package/figma-bridge-plugin/knowledge-hub/uspec-references/anatomy-spec.md +159 -0
  27. package/figma-bridge-plugin/knowledge-hub/uspec-references/api-spec.md +162 -0
  28. package/figma-bridge-plugin/knowledge-hub/uspec-references/color-spec.md +148 -0
  29. package/figma-bridge-plugin/knowledge-hub/uspec-references/full-spec-template.md +314 -0
  30. package/figma-bridge-plugin/knowledge-hub/uspec-references/property-spec.md +175 -0
  31. package/figma-bridge-plugin/knowledge-hub/uspec-references/screen-reader-spec.md +180 -0
  32. package/figma-bridge-plugin/knowledge-hub/uspec-references/structure-spec.md +165 -0
  33. package/figma-bridge-plugin/manifest.json +21 -0
  34. package/figma-bridge-plugin/package-lock.json +1936 -0
  35. package/figma-bridge-plugin/package.json +20 -0
  36. package/figma-bridge-plugin/perplexity-runner.js +188 -0
  37. package/figma-bridge-plugin/references/SKILL.md +178 -0
  38. package/figma-bridge-plugin/references/anatomy-spec.md +159 -0
  39. package/figma-bridge-plugin/references/api-spec.md +162 -0
  40. package/figma-bridge-plugin/references/color-spec.md +148 -0
  41. package/figma-bridge-plugin/references/full-spec-template.md +314 -0
  42. package/figma-bridge-plugin/references/property-spec.md +175 -0
  43. package/figma-bridge-plugin/references/screen-reader-spec.md +180 -0
  44. package/figma-bridge-plugin/references/structure-spec.md +165 -0
  45. package/figma-bridge-plugin/shared-prompt-config.js +604 -0
  46. package/figma-bridge-plugin/spec-helpers/build-table.js +269 -0
  47. package/figma-bridge-plugin/spec-helpers/classify-elements.js +189 -0
  48. package/figma-bridge-plugin/spec-helpers/index.js +35 -0
  49. package/figma-bridge-plugin/spec-helpers/parse-figma-link.js +49 -0
  50. package/figma-bridge-plugin/spec-helpers/position-markers.js +158 -0
  51. package/figma-bridge-plugin/stitch-auth.js +322 -0
  52. package/figma-bridge-plugin/stitch-runner.js +1427 -0
  53. package/figma-bridge-plugin/token-resolver.js +107 -0
  54. package/figma-bridge-plugin/ui.html +4467 -0
  55. package/figma-intelligence-layer/.env.example +39 -0
  56. package/figma-intelligence-layer/docs/local-image-generation.md +60 -0
  57. package/figma-intelligence-layer/examples/comfyui-workflow-template.example.json +101 -0
  58. package/figma-intelligence-layer/jest.config.js +14 -0
  59. package/figma-intelligence-layer/mcp-config.json +19 -0
  60. package/figma-intelligence-layer/package-lock.json +5892 -0
  61. package/figma-intelligence-layer/package.json +48 -0
  62. package/figma-intelligence-layer/scripts/setup-comfyui-local.sh +67 -0
  63. package/figma-intelligence-layer/scripts/start-comfyui.sh +33 -0
  64. package/figma-intelligence-layer/src/index.ts +2233 -0
  65. package/figma-intelligence-layer/src/shared/auto-layout-validator.ts +404 -0
  66. package/figma-intelligence-layer/src/shared/cache.ts +187 -0
  67. package/figma-intelligence-layer/src/shared/color-operations.ts +533 -0
  68. package/figma-intelligence-layer/src/shared/color-utils.ts +138 -0
  69. package/figma-intelligence-layer/src/shared/component-script-builder.ts +413 -0
  70. package/figma-intelligence-layer/src/shared/component-templates.ts +2767 -0
  71. package/figma-intelligence-layer/src/shared/concept-taxonomy.ts +694 -0
  72. package/figma-intelligence-layer/src/shared/decision-log.ts +128 -0
  73. package/figma-intelligence-layer/src/shared/design-system-context.ts +568 -0
  74. package/figma-intelligence-layer/src/shared/design-system-intelligence.ts +131 -0
  75. package/figma-intelligence-layer/src/shared/design-system-matcher.ts +184 -0
  76. package/figma-intelligence-layer/src/shared/design-system-normalizers.ts +196 -0
  77. package/figma-intelligence-layer/src/shared/design-system-tokens.ts +295 -0
  78. package/figma-intelligence-layer/src/shared/dtcg-validator.ts +530 -0
  79. package/figma-intelligence-layer/src/shared/enrichment-pipeline.ts +671 -0
  80. package/figma-intelligence-layer/src/shared/figma-bridge.ts +1408 -0
  81. package/figma-intelligence-layer/src/shared/font-config.ts +126 -0
  82. package/figma-intelligence-layer/src/shared/icon-catalog.ts +360 -0
  83. package/figma-intelligence-layer/src/shared/icon-fetch.ts +80 -0
  84. package/figma-intelligence-layer/src/shared/prototype-script-builder.ts +162 -0
  85. package/figma-intelligence-layer/src/shared/response-compression.ts +440 -0
  86. package/figma-intelligence-layer/src/shared/semantic-token-catalog.ts +324 -0
  87. package/figma-intelligence-layer/src/shared/token-binder.ts +505 -0
  88. package/figma-intelligence-layer/src/shared/token-math.ts +427 -0
  89. package/figma-intelligence-layer/src/shared/token-naming.ts +468 -0
  90. package/figma-intelligence-layer/src/shared/token-utils.ts +420 -0
  91. package/figma-intelligence-layer/src/shared/types.ts +346 -0
  92. package/figma-intelligence-layer/src/shared/typography-presets.ts +94 -0
  93. package/figma-intelligence-layer/src/shared/unsplash.ts +165 -0
  94. package/figma-intelligence-layer/src/shared/vision-client.ts +607 -0
  95. package/figma-intelligence-layer/src/shared/vision-provider-anthropic.ts +334 -0
  96. package/figma-intelligence-layer/src/shared/vision-provider-openai.ts +446 -0
  97. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-handler.ts +782 -0
  98. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-renderer.ts +496 -0
  99. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotation-kit.ts +230 -0
  100. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/colorblind-sim.ts +66 -0
  101. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/index.ts +810 -0
  102. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-analyzer.ts +1191 -0
  103. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-figma-page.ts +1346 -0
  104. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-handler.ts +148 -0
  105. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-figma-page.ts +499 -0
  106. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-report.ts +910 -0
  107. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-checker.ts +989 -0
  108. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-criteria.ts +1160 -0
  109. package/figma-intelligence-layer/src/tools/phase1-vision/design-from-ref/index.ts +424 -0
  110. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/component-recognizer.ts +38 -0
  111. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/ds-matcher.ts +111 -0
  112. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/font-matcher.ts +114 -0
  113. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/icon-resolver.ts +103 -0
  114. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/index.ts +1060 -0
  115. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/layout-segmenter.ts +18 -0
  116. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/token-inferencer.ts +39 -0
  117. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/vision-pipeline.ts +58 -0
  118. package/figma-intelligence-layer/src/tools/phase1-vision/sketch-to-design/index.ts +298 -0
  119. package/figma-intelligence-layer/src/tools/phase1-vision/visual-audit/index.ts +197 -0
  120. package/figma-intelligence-layer/src/tools/phase2-accuracy/component-audit/index.ts +494 -0
  121. package/figma-intelligence-layer/src/tools/phase2-accuracy/intent-translator/index.ts +356 -0
  122. package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/container-patterns.ts +123 -0
  123. package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/index.ts +663 -0
  124. package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/built-in-rules.yaml +56 -0
  125. package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/index.ts +614 -0
  126. package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/rule-engine.ts +113 -0
  127. package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/color-theory.ts +178 -0
  128. package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/index.ts +470 -0
  129. package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/index.ts +429 -0
  130. package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/token-override-maps.ts +226 -0
  131. package/figma-intelligence-layer/src/tools/phase3-generation/ai-image-insert/index.ts +535 -0
  132. package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/index.ts +660 -0
  133. package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/pattern-fingerprints.ts +209 -0
  134. package/figma-intelligence-layer/src/tools/phase3-generation/composition-builder/index.ts +540 -0
  135. package/figma-intelligence-layer/src/tools/phase3-generation/figma-animated-build.ts +391 -0
  136. package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/index.ts +2019 -0
  137. package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/screen-templates.ts +131 -0
  138. package/figma-intelligence-layer/src/tools/phase3-generation/prototype-map/index.ts +381 -0
  139. package/figma-intelligence-layer/src/tools/phase3-generation/prototype-wire/index.ts +565 -0
  140. package/figma-intelligence-layer/src/tools/phase3-generation/swarm-build/index.ts +764 -0
  141. package/figma-intelligence-layer/src/tools/phase3-generation/system-drift/index.ts +535 -0
  142. package/figma-intelligence-layer/src/tools/phase3-generation/unsplash-search/index.ts +84 -0
  143. package/figma-intelligence-layer/src/tools/phase3-generation/url-to-frame/index.ts +401 -0
  144. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/css-animations.ts +68 -0
  145. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/framer-motion.ts +78 -0
  146. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/swift-animations.ts +93 -0
  147. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/index.ts +596 -0
  148. package/figma-intelligence-layer/src/tools/phase4-sync/ci-check/index.ts +462 -0
  149. package/figma-intelligence-layer/src/tools/phase4-sync/export-tokens/index.ts +1470 -0
  150. package/figma-intelligence-layer/src/tools/phase4-sync/generate-component-code/index.ts +829 -0
  151. package/figma-intelligence-layer/src/tools/phase4-sync/handoff-spec/index.ts +702 -0
  152. package/figma-intelligence-layer/src/tools/phase4-sync/icon-library-sync/index.ts +483 -0
  153. package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/index.ts +501 -0
  154. package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/storybook-parser.ts +106 -0
  155. package/figma-intelligence-layer/src/tools/phase4-sync/watch-docs/index.ts +676 -0
  156. package/figma-intelligence-layer/src/tools/phase4-sync/webhook-listener/index.ts +560 -0
  157. package/figma-intelligence-layer/src/tools/phase5-governance/apg-doc/index.ts +1043 -0
  158. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/component-detection.ts +620 -0
  159. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/anatomy.ts +331 -0
  160. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/color-tokens.ts +77 -0
  161. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/properties.ts +54 -0
  162. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/snapshot.ts +287 -0
  163. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/spacing.ts +71 -0
  164. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/states.ts +43 -0
  165. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/typography.ts +71 -0
  166. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/index.ts +221 -0
  167. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/_default.ts +166 -0
  168. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/accordion.ts +232 -0
  169. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/alert.ts +234 -0
  170. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar-group.ts +270 -0
  171. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar.ts +249 -0
  172. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/badge.ts +231 -0
  173. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/banner.ts +293 -0
  174. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/breadcrumb.ts +240 -0
  175. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/button.ts +243 -0
  176. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/calendar.ts +307 -0
  177. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/card.ts +143 -0
  178. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/checkbox.ts +227 -0
  179. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/chip.ts +233 -0
  180. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/combobox.ts +282 -0
  181. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/datepicker.ts +276 -0
  182. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/divider.ts +223 -0
  183. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/drawer.ts +255 -0
  184. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/dropdown-menu.ts +289 -0
  185. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/empty-state.ts +261 -0
  186. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/file-uploader.ts +290 -0
  187. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/form.ts +265 -0
  188. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/grid.ts +238 -0
  189. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/icon.ts +255 -0
  190. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/index.ts +128 -0
  191. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-edit.ts +286 -0
  192. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-message.ts +255 -0
  193. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/input.ts +330 -0
  194. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/link.ts +247 -0
  195. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/list.ts +250 -0
  196. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/menu.ts +247 -0
  197. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/modal.ts +144 -0
  198. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navbar.ts +264 -0
  199. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navigation.ts +251 -0
  200. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/number-input.ts +261 -0
  201. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/pagination.ts +248 -0
  202. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/popover.ts +270 -0
  203. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/progress.ts +251 -0
  204. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/radio.ts +142 -0
  205. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/range-slider.ts +282 -0
  206. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/rating.ts +250 -0
  207. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/search.ts +258 -0
  208. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/segmented-control.ts +265 -0
  209. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/select.ts +319 -0
  210. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/skeleton.ts +256 -0
  211. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/slider.ts +232 -0
  212. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/spinner.ts +239 -0
  213. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/status-dot.ts +252 -0
  214. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/stepper.ts +270 -0
  215. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/table.ts +244 -0
  216. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tabs.ts +143 -0
  217. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tag.ts +243 -0
  218. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/textarea.ts +259 -0
  219. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/time-picker.ts +293 -0
  220. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toast.ts +144 -0
  221. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toggle.ts +289 -0
  222. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toolbar.ts +267 -0
  223. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tooltip.ts +232 -0
  224. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/treeview.ts +257 -0
  225. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/typography.ts +319 -0
  226. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/legacy-compat.ts +121 -0
  227. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/anatomy-diagram.ts +430 -0
  228. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/figma-page.ts +312 -0
  229. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/json.ts +129 -0
  230. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/markdown.ts +78 -0
  231. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/visual-doc.ts +2333 -0
  232. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/accessibility.ts +100 -0
  233. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/anatomy.ts +32 -0
  234. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/color-tokens.ts +59 -0
  235. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/content-guidance.ts +18 -0
  236. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/design-tokens.ts +53 -0
  237. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/interaction-rules.ts +19 -0
  238. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/overview.ts +91 -0
  239. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/properties-api.ts +71 -0
  240. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/qa-criteria.ts +19 -0
  241. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/related-components.ts +110 -0
  242. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/responsive.ts +19 -0
  243. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/size-specs.ts +67 -0
  244. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/spacing-structure.ts +58 -0
  245. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/state-specs.ts +79 -0
  246. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/states.ts +50 -0
  247. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/type-hierarchy.ts +33 -0
  248. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/typography.ts +55 -0
  249. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/usage-guidelines.ts +73 -0
  250. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/variants.ts +81 -0
  251. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/types.ts +409 -0
  252. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/index.ts +198 -0
  253. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/renderer.ts +701 -0
  254. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/types.ts +88 -0
  255. package/figma-intelligence-layer/src/tools/phase5-governance/decision-log/index.ts +135 -0
  256. package/figma-intelligence-layer/src/tools/phase5-governance/design-decision-log/index.ts +491 -0
  257. package/figma-intelligence-layer/src/tools/phase5-governance/ds-primitives/index.ts +416 -0
  258. package/figma-intelligence-layer/src/tools/phase5-governance/ds-scaffolder/index.ts +722 -0
  259. package/figma-intelligence-layer/src/tools/phase5-governance/ds-variables/index.ts +449 -0
  260. package/figma-intelligence-layer/src/tools/phase5-governance/health-report/index.ts +393 -0
  261. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/index.ts +406 -0
  262. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/figma-page.ts +292 -0
  263. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/json.ts +24 -0
  264. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/markdown.ts +172 -0
  265. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/naming-guide.ts +409 -0
  266. package/figma-intelligence-layer/src/tools/phase5-governance/token-analytics/index.ts +594 -0
  267. package/figma-intelligence-layer/src/tools/phase5-governance/token-docs/index.ts +710 -0
  268. package/figma-intelligence-layer/src/tools/phase5-governance/token-migrate/index.ts +458 -0
  269. package/figma-intelligence-layer/src/tools/phase5-governance/token-naming/index.ts +134 -0
  270. package/figma-intelligence-layer/tests/apg-doc.test.ts +101 -0
  271. package/figma-intelligence-layer/tests/design-system-context.test.ts +152 -0
  272. package/figma-intelligence-layer/tests/design-system-matcher.test.ts +144 -0
  273. package/figma-intelligence-layer/tests/figma-bridge.test.ts +83 -0
  274. package/figma-intelligence-layer/tests/generate-image-and-insert.test.ts +56 -0
  275. package/figma-intelligence-layer/tests/screen-cloner-regression.test.ts +69 -0
  276. package/figma-intelligence-layer/tests/smoke.test.ts +174 -0
  277. package/figma-intelligence-layer/tests/spec-generator.test.ts +127 -0
  278. package/figma-intelligence-layer/tests/token-migrate.test.ts +21 -0
  279. package/figma-intelligence-layer/tests/token-naming.test.ts +30 -0
  280. package/figma-intelligence-layer/tsconfig.json +19 -0
  281. package/package.json +35 -0
  282. package/scripts/clean-existing-chunks.js +179 -0
  283. package/scripts/connect-ai-tool.js +490 -0
  284. package/scripts/convert-hub-pdfs.js +425 -0
  285. package/scripts/figma-mcp-status.js +349 -0
  286. package/scripts/register-codex-mcp.js +96 -0
@@ -0,0 +1,989 @@
1
+ // ─────────────────────────────────────────────────────────────────────────────
2
+ // WCAG Checker
3
+ // Pure-function WCAG 2.2 compliance checks that operate on Figma node data.
4
+ // Used by the a11y-audit tool.
5
+ // ─────────────────────────────────────────────────────────────────────────────
6
+
7
+ import { FigmaNode, WCAGIssue, RGBA } from "../../../shared/types.js";
8
+ import {
9
+ computeContrastRatio,
10
+ figmaRgbaToHex,
11
+ meetsWCAG,
12
+ } from "../../../shared/token-utils.js";
13
+
14
+ /** Minimum interactive touch target (WCAG 2.5.5). */
15
+ export const MIN_TOUCH_TARGET = 44;
16
+
17
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
18
+
19
+ export function extractSolidColor(node: FigmaNode): RGBA | null {
20
+ if (!node.fills || node.fills.length === 0) return null;
21
+ const solid = node.fills.find((f) => f.type === "SOLID" && f.color);
22
+ return solid?.color ?? null;
23
+ }
24
+
25
+ export function findParentBgColor(
26
+ nodeId: string,
27
+ allNodes: FigmaNode[]
28
+ ): RGBA | null {
29
+ function findParent(id: string, nodes: FigmaNode[]): FigmaNode | null {
30
+ for (const n of nodes) {
31
+ if (n.children?.some((c) => c.id === id)) return n;
32
+ if (n.children) {
33
+ const found = findParent(id, n.children);
34
+ if (found) return found;
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+
40
+ let current = nodeId;
41
+ for (let depth = 0; depth < 12; depth++) {
42
+ const parent = findParent(current, allNodes);
43
+ if (!parent) break;
44
+ const color = extractSolidColor(parent);
45
+ if (color) return color;
46
+ current = parent.id;
47
+ }
48
+ return { r: 1, g: 1, b: 1, a: 1 };
49
+ }
50
+
51
+ // ─── Individual checks ───────────────────────────────────────────────────────
52
+
53
+ export function checkTextContrast(
54
+ textNode: FigmaNode,
55
+ allNodes: FigmaNode[],
56
+ wcagLevel: "A" | "AA" | "AAA"
57
+ ): WCAGIssue | null {
58
+ const fgColor = extractSolidColor(textNode);
59
+ if (!fgColor) return null;
60
+
61
+ const bgColor = findParentBgColor(textNode.id, allNodes);
62
+ if (!bgColor) return null;
63
+
64
+ const fgHex = figmaRgbaToHex(fgColor.r, fgColor.g, fgColor.b);
65
+ const bgHex = figmaRgbaToHex(bgColor.r, bgColor.g, bgColor.b);
66
+
67
+ const fontSize = textNode.style?.fontSize ?? 16;
68
+ const fontWeight = textNode.style?.fontWeight ?? 400;
69
+ const isLargeText = fontSize >= 18 || (fontSize >= 14 && fontWeight >= 700);
70
+
71
+ const ratio = computeContrastRatio(fgHex, bgHex);
72
+ const effectiveLevel: "AA" | "AAA" = wcagLevel === "AAA" ? "AAA" : "AA";
73
+ const passes = meetsWCAG(ratio, effectiveLevel, isLargeText);
74
+
75
+ if (passes) return null;
76
+
77
+ const minRatio = isLargeText
78
+ ? (effectiveLevel === "AAA" ? 4.5 : 3.0)
79
+ : (effectiveLevel === "AAA" ? 7.0 : 4.5);
80
+
81
+ return {
82
+ severity: ratio < 3.0 ? "error" : "warning",
83
+ criterion: wcagLevel === "AAA" ? "1.4.6" : "1.4.3",
84
+ nodeId: textNode.id,
85
+ nodeName: textNode.name,
86
+ issue: `Contrast ratio ${ratio.toFixed(2)}:1 below ${effectiveLevel} threshold (${minRatio}:1) for ${isLargeText ? "large" : "normal"} text`,
87
+ currentValue: `${ratio.toFixed(2)}:1`,
88
+ suggestedFix: `Increase contrast to at least ${minRatio}:1`,
89
+ autoFixAvailable: true,
90
+ };
91
+ }
92
+
93
+ export function checkTouchTarget(node: FigmaNode): WCAGIssue | null {
94
+ if (!node.absoluteBoundingBox) return null;
95
+ const w = node.width ?? 0;
96
+ const h = node.height ?? 0;
97
+
98
+ if (w < MIN_TOUCH_TARGET || h < MIN_TOUCH_TARGET) {
99
+ return {
100
+ severity: "error",
101
+ criterion: "2.5.5",
102
+ nodeId: node.id,
103
+ nodeName: node.name,
104
+ issue: `Interactive element is ${w}×${h}px, below the minimum ${MIN_TOUCH_TARGET}×${MIN_TOUCH_TARGET}px touch target`,
105
+ currentValue: `${w}×${h}px`,
106
+ suggestedFix: `Resize to at least ${MIN_TOUCH_TARGET}×${MIN_TOUCH_TARGET}px`,
107
+ autoFixAvailable: true,
108
+ };
109
+ }
110
+ return null;
111
+ }
112
+
113
+ export function checkFocusState(node: FigmaNode): WCAGIssue | null {
114
+ if (node.type !== "COMPONENT_SET") return null;
115
+ const hasFocus =
116
+ Object.values(node.variantProperties ?? {}).some(
117
+ (v) => typeof v === "string" && v.toLowerCase().includes("focus")
118
+ ) ||
119
+ node.children?.some(
120
+ (c) =>
121
+ c.name.toLowerCase().includes("focus") ||
122
+ Object.values(c.variantProperties ?? {}).some(
123
+ (v) => typeof v === "string" && v.toLowerCase().includes("focus")
124
+ )
125
+ );
126
+
127
+ if (!hasFocus) {
128
+ return {
129
+ severity: "warning",
130
+ criterion: "2.4.7",
131
+ nodeId: node.id,
132
+ nodeName: node.name,
133
+ issue: "Component set has no focus state variant",
134
+ currentValue: "No focus variant",
135
+ suggestedFix: 'Add a "State=Focus" variant with a visible 2px focus ring',
136
+ autoFixAvailable: false,
137
+ };
138
+ }
139
+ return null;
140
+ }
141
+
142
+ export function checkFixedHeightTextContainer(node: FigmaNode): WCAGIssue | null {
143
+ if (!node.children) return null;
144
+ const hasTextChild = node.children.some((c) => c.type === "TEXT");
145
+ if (!hasTextChild) return null;
146
+
147
+ const isFixedHeight =
148
+ node.primaryAxisSizingMode === "FIXED" ||
149
+ (node.height !== undefined && node.primaryAxisSizingMode !== "AUTO");
150
+
151
+ if (isFixedHeight && node.layoutMode && node.layoutMode !== "NONE") {
152
+ return {
153
+ severity: "warning",
154
+ criterion: "1.4.4",
155
+ nodeId: node.id,
156
+ nodeName: node.name,
157
+ issue: "Text container has fixed height which may clip text on resize",
158
+ currentValue: `height: ${node.height}px (fixed)`,
159
+ suggestedFix: 'Set vertical sizing to "Hug contents" (AUTO)',
160
+ autoFixAvailable: true,
161
+ };
162
+ }
163
+ return null;
164
+ }
165
+
166
+ // ─── New checks for comprehensive VPAT coverage ─────────────────────────────
167
+
168
+ /** WCAG 2.5.8 Target Size (Minimum) – 24×24px at Level AA. */
169
+ export const MIN_TARGET_SIZE_AA = 24;
170
+
171
+ export function checkTargetSizeMinimum(node: FigmaNode): WCAGIssue | null {
172
+ if (!node.absoluteBoundingBox) return null;
173
+ const w = node.width ?? 0;
174
+ const h = node.height ?? 0;
175
+
176
+ if (w < MIN_TARGET_SIZE_AA || h < MIN_TARGET_SIZE_AA) {
177
+ return {
178
+ severity: "error",
179
+ criterion: "2.5.8",
180
+ nodeId: node.id,
181
+ nodeName: node.name,
182
+ issue: `Interactive element is ${w}×${h}px, below the minimum ${MIN_TARGET_SIZE_AA}×${MIN_TARGET_SIZE_AA}px target size`,
183
+ currentValue: `${w}×${h}px`,
184
+ suggestedFix: `Resize to at least ${MIN_TARGET_SIZE_AA}×${MIN_TARGET_SIZE_AA}px`,
185
+ autoFixAvailable: true,
186
+ };
187
+ }
188
+ return null;
189
+ }
190
+
191
+ /** WCAG 1.1.1 Non-text Content – heuristic check for images without descriptions. */
192
+ export function checkNonTextContent(
193
+ node: FigmaNode,
194
+ allNodes: FigmaNode[]
195
+ ): WCAGIssue | null {
196
+ // Check IMAGE fill nodes and VECTOR nodes
197
+ const isImage =
198
+ node.fills?.some((f) => f.type === "IMAGE") ||
199
+ node.type === "VECTOR" ||
200
+ node.type === "BOOLEAN_OPERATION";
201
+ if (!isImage) return null;
202
+
203
+ // Skip decorative-sounding nodes
204
+ const name = node.name.toLowerCase();
205
+ if (name.includes("decorative") || name.includes("divider") || name.includes("separator")) {
206
+ return null;
207
+ }
208
+
209
+ // Check if node has a description
210
+ if (node.description && node.description.trim().length > 0) return null;
211
+
212
+ // Check if a sibling TEXT node acts as a label
213
+ const parent = findParentNode(node.id, allNodes);
214
+ if (parent?.children) {
215
+ const hasSiblingLabel = parent.children.some(
216
+ (c) => c.type === "TEXT" && c.id !== node.id
217
+ );
218
+ if (hasSiblingLabel) return null;
219
+ }
220
+
221
+ return {
222
+ severity: "warning",
223
+ criterion: "1.1.1",
224
+ nodeId: node.id,
225
+ nodeName: node.name,
226
+ issue: "Non-text content has no description or adjacent text label",
227
+ currentValue: "No alt text / description",
228
+ suggestedFix: "Add a description property or provide an adjacent text label. Mark decorative images by including 'decorative' in the name.",
229
+ autoFixAvailable: false,
230
+ };
231
+ }
232
+
233
+ /** WCAG 1.3.1 Info and Relationships – heuristic heading hierarchy check. */
234
+ export function checkInfoAndRelationships(
235
+ textNodes: FigmaNode[]
236
+ ): WCAGIssue[] {
237
+ const issues: WCAGIssue[] = [];
238
+
239
+ // Identify heading-like text (large or bold)
240
+ const headings = textNodes.filter((n) => {
241
+ const fontSize = n.style?.fontSize ?? 16;
242
+ const fontWeight = n.style?.fontWeight ?? 400;
243
+ return fontSize >= 20 || fontWeight >= 700;
244
+ });
245
+
246
+ // Sort headings by visual position (top to bottom)
247
+ headings.sort((a, b) => {
248
+ const ay = a.absoluteBoundingBox?.y ?? 0;
249
+ const by = b.absoluteBoundingBox?.y ?? 0;
250
+ return ay - by;
251
+ });
252
+
253
+ // Check for logical hierarchy (font sizes should decrease or stay same going down)
254
+ let prevFontSize = Infinity;
255
+ for (const heading of headings) {
256
+ const fontSize = heading.style?.fontSize ?? 16;
257
+ if (fontSize > prevFontSize) {
258
+ issues.push({
259
+ severity: "warning",
260
+ criterion: "1.3.1",
261
+ nodeId: heading.id,
262
+ nodeName: heading.name,
263
+ issue: `Heading text (${fontSize}px) appears after smaller heading (${prevFontSize}px), suggesting inconsistent heading hierarchy`,
264
+ currentValue: `${fontSize}px after ${prevFontSize}px`,
265
+ suggestedFix: "Ensure headings follow a logical hierarchy (h1 > h2 > h3). Larger text should not appear after smaller headings.",
266
+ autoFixAvailable: false,
267
+ });
268
+ }
269
+ prevFontSize = fontSize;
270
+ }
271
+
272
+ return issues;
273
+ }
274
+
275
+ /** WCAG 1.3.2 Meaningful Sequence – heuristic reading order check. */
276
+ export function checkMeaningfulSequence(
277
+ allNodes: FigmaNode[]
278
+ ): WCAGIssue[] {
279
+ const issues: WCAGIssue[] = [];
280
+
281
+ // Check top-level children: node tree order vs visual position
282
+ for (const node of allNodes) {
283
+ if (!node.children || node.children.length < 2) continue;
284
+
285
+ const childrenWithPos = node.children
286
+ .filter((c) => c.absoluteBoundingBox)
287
+ .map((c, idx) => ({
288
+ node: c,
289
+ treeIndex: idx,
290
+ visualY: c.absoluteBoundingBox!.y,
291
+ visualX: c.absoluteBoundingBox!.x,
292
+ }));
293
+
294
+ // Sort by visual reading order (top-to-bottom, left-to-right)
295
+ const visualOrder = [...childrenWithPos].sort(
296
+ (a, b) => a.visualY - b.visualY || a.visualX - b.visualX
297
+ );
298
+
299
+ // Count significant order mismatches
300
+ let mismatches = 0;
301
+ for (let i = 0; i < visualOrder.length; i++) {
302
+ if (visualOrder[i].treeIndex !== childrenWithPos[i]?.treeIndex) {
303
+ mismatches++;
304
+ }
305
+ }
306
+
307
+ // Only flag if more than 30% of children are out of order (to avoid noise)
308
+ if (mismatches > childrenWithPos.length * 0.3 && mismatches >= 3) {
309
+ issues.push({
310
+ severity: "warning",
311
+ criterion: "1.3.2",
312
+ nodeId: node.id,
313
+ nodeName: node.name,
314
+ issue: `Layer order differs significantly from visual reading order (${mismatches} of ${childrenWithPos.length} elements mismatched)`,
315
+ currentValue: `${mismatches} order mismatches`,
316
+ suggestedFix: "Reorder layers to match the visual reading flow (top-to-bottom, left-to-right) so screen readers follow the intended sequence.",
317
+ autoFixAvailable: false,
318
+ });
319
+ }
320
+ }
321
+
322
+ return issues;
323
+ }
324
+
325
+ /** WCAG 1.4.1 Use of Color – heuristic check for colour-only state differentiation. */
326
+ export function checkUseOfColor(
327
+ componentSetNodes: FigmaNode[]
328
+ ): WCAGIssue[] {
329
+ const issues: WCAGIssue[] = [];
330
+
331
+ for (const set of componentSetNodes) {
332
+ if (!set.children || set.children.length < 2) continue;
333
+
334
+ // Compare variants pairwise for colour-only differences
335
+ for (let i = 0; i < set.children.length - 1; i++) {
336
+ for (let j = i + 1; j < set.children.length; j++) {
337
+ const a = set.children[i];
338
+ const b = set.children[j];
339
+
340
+ const aColor = extractSolidColor(a);
341
+ const bColor = extractSolidColor(b);
342
+
343
+ // Both have fills and they differ
344
+ if (aColor && bColor && !colorsEqual(aColor, bColor)) {
345
+ // Check if structural content also differs (children count, types)
346
+ const structurallyDifferent = hasStructuralDifference(a, b);
347
+
348
+ if (!structurallyDifferent) {
349
+ issues.push({
350
+ severity: "warning",
351
+ criterion: "1.4.1",
352
+ nodeId: set.id,
353
+ nodeName: set.name,
354
+ issue: `Variants "${a.name}" and "${b.name}" differ only by colour — add an icon, text label, or pattern to distinguish states`,
355
+ currentValue: "Colour-only differentiation",
356
+ suggestedFix: "Add a non-colour indicator (icon, underline, text badge) to differentiate states for users who cannot perceive colour.",
357
+ autoFixAvailable: false,
358
+ });
359
+ break; // One issue per component set is enough
360
+ }
361
+ }
362
+ }
363
+ if (issues.some((i) => i.nodeId === set.id)) break;
364
+ }
365
+ }
366
+
367
+ return issues;
368
+ }
369
+
370
+ /** WCAG 1.4.11 Non-text Contrast – check stroke/border contrast against background. */
371
+ export function checkNonTextContrast(
372
+ node: FigmaNode,
373
+ allNodes: FigmaNode[]
374
+ ): WCAGIssue | null {
375
+ // Check strokes on interactive/UI elements
376
+ if (!node.strokes || node.strokes.length === 0) return null;
377
+
378
+ const strokeColor = node.strokes.find(
379
+ (s) => s.type === "SOLID" && s.color
380
+ )?.color;
381
+ if (!strokeColor) return null;
382
+
383
+ const bgColor = findParentBgColor(node.id, allNodes);
384
+ if (!bgColor) return null;
385
+
386
+ const strokeHex = figmaRgbaToHex(strokeColor.r, strokeColor.g, strokeColor.b);
387
+ const bgHex = figmaRgbaToHex(bgColor.r, bgColor.g, bgColor.b);
388
+
389
+ const ratio = computeContrastRatio(strokeHex, bgHex);
390
+ const MIN_NON_TEXT_CONTRAST = 3.0;
391
+
392
+ if (ratio < MIN_NON_TEXT_CONTRAST) {
393
+ return {
394
+ severity: "error",
395
+ criterion: "1.4.11",
396
+ nodeId: node.id,
397
+ nodeName: node.name,
398
+ issue: `UI component border contrast ${ratio.toFixed(2)}:1 is below the ${MIN_NON_TEXT_CONTRAST}:1 minimum for non-text elements`,
399
+ currentValue: `${ratio.toFixed(2)}:1`,
400
+ suggestedFix: `Increase border/stroke contrast to at least ${MIN_NON_TEXT_CONTRAST}:1`,
401
+ autoFixAvailable: true,
402
+ };
403
+ }
404
+ return null;
405
+ }
406
+
407
+ /** WCAG 1.4.12 Text Spacing – check line-height, letter-spacing on text nodes. */
408
+ export function checkTextSpacing(textNode: FigmaNode): WCAGIssue | null {
409
+ if (textNode.type !== "TEXT") return null;
410
+ const style = textNode.style;
411
+ if (!style) return null;
412
+
413
+ const fontSize = style.fontSize;
414
+ const lineHeight = style.lineHeightPx;
415
+ const letterSpacing = style.letterSpacing;
416
+
417
+ // Line height should be >= 1.5x font size
418
+ if (lineHeight > 0 && lineHeight < fontSize * 1.5) {
419
+ return {
420
+ severity: "warning",
421
+ criterion: "1.4.12",
422
+ nodeId: textNode.id,
423
+ nodeName: textNode.name,
424
+ issue: `Line height (${lineHeight.toFixed(1)}px) is less than 1.5x the font size (${fontSize}px = ${(fontSize * 1.5).toFixed(1)}px minimum)`,
425
+ currentValue: `lineHeight: ${lineHeight.toFixed(1)}px (${(lineHeight / fontSize).toFixed(2)}x)`,
426
+ suggestedFix: `Set line height to at least ${(fontSize * 1.5).toFixed(0)}px (1.5x font size)`,
427
+ autoFixAvailable: true,
428
+ };
429
+ }
430
+
431
+ // Letter spacing should not be negative (which would prevent user override)
432
+ if (letterSpacing < 0) {
433
+ return {
434
+ severity: "warning",
435
+ criterion: "1.4.12",
436
+ nodeId: textNode.id,
437
+ nodeName: textNode.name,
438
+ issue: `Negative letter spacing (${letterSpacing}px) may prevent text spacing overrides`,
439
+ currentValue: `letterSpacing: ${letterSpacing}px`,
440
+ suggestedFix: "Use non-negative letter spacing to allow user text spacing adjustments",
441
+ autoFixAvailable: true,
442
+ };
443
+ }
444
+
445
+ return null;
446
+ }
447
+
448
+ /** WCAG 1.4.10 Reflow – heuristic check for responsive layout usage. */
449
+ export function checkReflow(frameNodes: FigmaNode[]): WCAGIssue[] {
450
+ const issues: WCAGIssue[] = [];
451
+
452
+ for (const frame of frameNodes) {
453
+ // Only check top-level or large frames (likely page/section containers)
454
+ const width = frame.width ?? 0;
455
+ if (width < 320) continue; // Skip small components
456
+
457
+ const hasAutoLayout = frame.layoutMode && frame.layoutMode !== "NONE";
458
+ const isFixedWidth =
459
+ frame.counterAxisSizingMode === "FIXED" ||
460
+ frame.primaryAxisSizingMode === "FIXED";
461
+
462
+ if (!hasAutoLayout && isFixedWidth && frame.children && frame.children.length > 2) {
463
+ issues.push({
464
+ severity: "warning",
465
+ criterion: "1.4.10",
466
+ nodeId: frame.id,
467
+ nodeName: frame.name,
468
+ issue: "Large container uses fixed sizing without auto-layout, may not reflow at narrow viewports",
469
+ currentValue: `${width}px wide, no auto-layout`,
470
+ suggestedFix: "Use auto-layout with fill/hug sizing so content reflows at 320px viewport width without horizontal scrolling.",
471
+ autoFixAvailable: false,
472
+ });
473
+ }
474
+ }
475
+
476
+ return issues;
477
+ }
478
+
479
+ /** WCAG 1.4.5 / 1.4.9 Images of Text – detect rasterised text. */
480
+ export function checkImagesOfText(allNodes: FigmaNode[]): WCAGIssue[] {
481
+ const issues: WCAGIssue[] = [];
482
+ const textHints = ["text", "label", "title", "heading", "caption", "body", "paragraph", "description"];
483
+
484
+ for (const node of allNodes) {
485
+ const hasImageFill = node.fills?.some((f) => f.type === "IMAGE");
486
+ if (!hasImageFill) continue;
487
+
488
+ const nameLower = node.name.toLowerCase();
489
+ const looksLikeText = textHints.some((hint) => nameLower.includes(hint));
490
+
491
+ if (looksLikeText) {
492
+ issues.push({
493
+ severity: "warning",
494
+ criterion: "1.4.5",
495
+ nodeId: node.id,
496
+ nodeName: node.name,
497
+ issue: `Node "${node.name}" has an image fill but its name suggests it may contain text — use real text instead of images of text`,
498
+ currentValue: "IMAGE fill with text-like name",
499
+ suggestedFix: "Replace image of text with a real TEXT node. If the image is essential (e.g., logo), document that in the description.",
500
+ autoFixAvailable: false,
501
+ });
502
+ }
503
+ }
504
+
505
+ return issues;
506
+ }
507
+
508
+ /** WCAG 1.4.13 Content on Hover or Focus – heuristic tooltip/hover pattern check. */
509
+ export function checkContentOnHover(
510
+ componentSetNodes: FigmaNode[]
511
+ ): WCAGIssue[] {
512
+ const issues: WCAGIssue[] = [];
513
+
514
+ for (const set of componentSetNodes) {
515
+ if (!set.children) continue;
516
+
517
+ const hoverVariant = set.children.find((c) => {
518
+ const name = c.name.toLowerCase();
519
+ return name.includes("hover") || name.includes("tooltip");
520
+ });
521
+
522
+ if (!hoverVariant) continue;
523
+
524
+ // Check if the hover variant has significantly more children (added content)
525
+ const defaultVariant = set.children.find((c) => {
526
+ const name = c.name.toLowerCase();
527
+ return name.includes("default") || name.includes("rest") || name.includes("idle");
528
+ }) || set.children[0];
529
+
530
+ const defaultChildCount = countDescendants(defaultVariant);
531
+ const hoverChildCount = countDescendants(hoverVariant);
532
+
533
+ if (hoverChildCount > defaultChildCount + 1) {
534
+ // Additional content appears on hover — check for dismiss mechanism
535
+ const hasDismiss = hoverVariant.children?.some((c) => {
536
+ const name = c.name.toLowerCase();
537
+ return name.includes("close") || name.includes("dismiss") || name.includes("x");
538
+ });
539
+
540
+ if (!hasDismiss) {
541
+ issues.push({
542
+ severity: "warning",
543
+ criterion: "1.4.13",
544
+ nodeId: set.id,
545
+ nodeName: set.name,
546
+ issue: "Additional content appears on hover without a visible dismiss mechanism",
547
+ currentValue: "Hover-triggered content, no close control",
548
+ suggestedFix: "Ensure hover/focus-triggered content is: (1) dismissable via Escape, (2) hoverable without disappearing, (3) persistent until dismissed.",
549
+ autoFixAvailable: false,
550
+ });
551
+ }
552
+ }
553
+ }
554
+
555
+ return issues;
556
+ }
557
+
558
+ /** WCAG 2.4.3 Focus Order – heuristic check for tab order mismatches. */
559
+ export function checkFocusOrder(
560
+ interactiveNodes: FigmaNode[]
561
+ ): WCAGIssue[] {
562
+ const issues: WCAGIssue[] = [];
563
+
564
+ const withPos = interactiveNodes
565
+ .filter((n) => n.absoluteBoundingBox)
566
+ .map((n, idx) => ({
567
+ node: n,
568
+ treeIndex: idx,
569
+ y: n.absoluteBoundingBox!.y,
570
+ x: n.absoluteBoundingBox!.x,
571
+ }));
572
+
573
+ if (withPos.length < 2) return issues;
574
+
575
+ // Expected visual order: top-to-bottom, left-to-right
576
+ const visualOrder = [...withPos].sort(
577
+ (a, b) => a.y - b.y || a.x - b.x
578
+ );
579
+
580
+ let mismatches = 0;
581
+ for (let i = 0; i < visualOrder.length; i++) {
582
+ if (visualOrder[i].treeIndex !== withPos[i]?.treeIndex) {
583
+ mismatches++;
584
+ }
585
+ }
586
+
587
+ if (mismatches > withPos.length * 0.25 && mismatches >= 2) {
588
+ issues.push({
589
+ severity: "warning",
590
+ criterion: "2.4.3",
591
+ nodeId: withPos[0].node.id,
592
+ nodeName: "Interactive elements",
593
+ issue: `Focus order (layer order) differs from visual reading order for ${mismatches} of ${withPos.length} interactive elements`,
594
+ currentValue: `${mismatches} order mismatches`,
595
+ suggestedFix: "Reorder interactive element layers to match the visual top-to-bottom, left-to-right flow for logical tab order.",
596
+ autoFixAvailable: false,
597
+ });
598
+ }
599
+
600
+ return issues;
601
+ }
602
+
603
+ /** WCAG 2.4.4 / 2.4.9 Link Purpose – detect vague link text. */
604
+ const VAGUE_LINK_TEXTS = [
605
+ "click here",
606
+ "read more",
607
+ "learn more",
608
+ "more",
609
+ "here",
610
+ "link",
611
+ "go",
612
+ "see more",
613
+ "details",
614
+ "info",
615
+ ];
616
+
617
+ export function checkLinkPurpose(
618
+ interactiveNodes: FigmaNode[]
619
+ ): WCAGIssue[] {
620
+ const issues: WCAGIssue[] = [];
621
+
622
+ for (const node of interactiveNodes) {
623
+ const name = node.name.toLowerCase();
624
+ const isLink =
625
+ name.includes("link") ||
626
+ name.includes("anchor") ||
627
+ name.includes("cta") ||
628
+ node.type === "INSTANCE";
629
+
630
+ if (!isLink) continue;
631
+
632
+ // Check visible text content
633
+ const textContent = findTextContent(node);
634
+ if (!textContent) continue;
635
+
636
+ const normalised = textContent.toLowerCase().trim();
637
+ if (VAGUE_LINK_TEXTS.includes(normalised)) {
638
+ issues.push({
639
+ severity: "warning",
640
+ criterion: "2.4.4",
641
+ nodeId: node.id,
642
+ nodeName: node.name,
643
+ issue: `Link text "${textContent}" is vague and does not describe its purpose`,
644
+ currentValue: `"${textContent}"`,
645
+ suggestedFix: `Replace with descriptive text that explains where the link goes (e.g., "View order details" instead of "${textContent}").`,
646
+ autoFixAvailable: false,
647
+ });
648
+ }
649
+ }
650
+
651
+ return issues;
652
+ }
653
+
654
+ /** WCAG 2.4.6 Headings and Labels – check sections for heading presence. */
655
+ export function checkHeadingsAndLabels(
656
+ frameNodes: FigmaNode[]
657
+ ): WCAGIssue[] {
658
+ const issues: WCAGIssue[] = [];
659
+
660
+ for (const frame of frameNodes) {
661
+ // Only check substantial frames (likely content sections)
662
+ if (!frame.children || frame.children.length < 3) continue;
663
+ const width = frame.width ?? 0;
664
+ const height = frame.height ?? 0;
665
+ if (width < 200 || height < 100) continue;
666
+
667
+ // Check if frame has any heading-like text child
668
+ const hasHeading = hasHeadingChild(frame);
669
+
670
+ if (!hasHeading) {
671
+ issues.push({
672
+ severity: "suggestion",
673
+ criterion: "2.4.6",
674
+ nodeId: frame.id,
675
+ nodeName: frame.name,
676
+ issue: "Content section has no visible heading text",
677
+ currentValue: "No heading found",
678
+ suggestedFix: "Add a descriptive heading to help users understand the section's topic or purpose.",
679
+ autoFixAvailable: false,
680
+ });
681
+ }
682
+ }
683
+
684
+ return issues;
685
+ }
686
+
687
+ /** WCAG 2.4.11 Focus Not Obscured – check focus variants for overlapping elements. */
688
+ export function checkFocusNotObscured(
689
+ componentSetNodes: FigmaNode[]
690
+ ): WCAGIssue[] {
691
+ const issues: WCAGIssue[] = [];
692
+
693
+ for (const set of componentSetNodes) {
694
+ if (!set.children) continue;
695
+
696
+ const focusVariant = set.children.find((c) => {
697
+ const name = c.name.toLowerCase();
698
+ return name.includes("focus");
699
+ });
700
+
701
+ if (!focusVariant || !focusVariant.children) continue;
702
+
703
+ // Check if any child in the focus variant is positioned to overlap the main content
704
+ // Heuristic: look for overlay/backdrop children that are full-size
705
+ const overlays = focusVariant.children.filter((c) => {
706
+ const name = c.name.toLowerCase();
707
+ return name.includes("overlay") || name.includes("backdrop") || name.includes("scrim");
708
+ });
709
+
710
+ for (const overlay of overlays) {
711
+ const overlayW = overlay.width ?? 0;
712
+ const overlayH = overlay.height ?? 0;
713
+ const parentW = focusVariant.width ?? 0;
714
+ const parentH = focusVariant.height ?? 0;
715
+
716
+ if (overlayW >= parentW * 0.8 && overlayH >= parentH * 0.8) {
717
+ issues.push({
718
+ severity: "warning",
719
+ criterion: "2.4.11",
720
+ nodeId: set.id,
721
+ nodeName: set.name,
722
+ issue: `Focus variant contains an overlay ("${overlay.name}") that may obscure the focused element`,
723
+ currentValue: `Overlay ${overlayW}×${overlayH}px over ${parentW}×${parentH}px parent`,
724
+ suggestedFix: "Ensure the focused element is not obscured by overlays. The focus indicator should remain fully visible.",
725
+ autoFixAvailable: false,
726
+ });
727
+ }
728
+ }
729
+ }
730
+
731
+ return issues;
732
+ }
733
+
734
+ /** WCAG 3.3.1 Error Identification – check error state variants for descriptive text. */
735
+ export function checkErrorIdentification(
736
+ componentSetNodes: FigmaNode[]
737
+ ): WCAGIssue[] {
738
+ const issues: WCAGIssue[] = [];
739
+
740
+ for (const set of componentSetNodes) {
741
+ if (!set.children) continue;
742
+
743
+ const errorVariant = set.children.find((c) => {
744
+ const name = c.name.toLowerCase();
745
+ return name.includes("error") || name.includes("invalid") || name.includes("destructive");
746
+ });
747
+
748
+ if (!errorVariant) continue;
749
+
750
+ // Check if the error variant has text describing the error
751
+ const errorText = findTextContent(errorVariant);
752
+ const hasErrorDescription =
753
+ errorText &&
754
+ errorText.length > 3 &&
755
+ !errorText.toLowerCase().includes("placeholder");
756
+
757
+ if (!hasErrorDescription) {
758
+ // Check if only colour indicates the error (red fill without text)
759
+ issues.push({
760
+ severity: "warning",
761
+ criterion: "3.3.1",
762
+ nodeId: set.id,
763
+ nodeName: set.name,
764
+ issue: `Error variant "${errorVariant.name}" lacks descriptive error text — errors should be identified in text, not just by colour`,
765
+ currentValue: "No error description text found",
766
+ suggestedFix: "Add a text element describing the error (e.g., 'Email address is required') to the error state variant.",
767
+ autoFixAvailable: false,
768
+ });
769
+ }
770
+ }
771
+
772
+ return issues;
773
+ }
774
+
775
+ /** WCAG 3.3.2 Labels or Instructions – check form inputs for visible labels. */
776
+ export function checkLabelsOrInstructions(
777
+ interactiveNodes: FigmaNode[],
778
+ allNodes: FigmaNode[]
779
+ ): WCAGIssue[] {
780
+ const issues: WCAGIssue[] = [];
781
+ const inputHints = ["input", "text field", "textfield", "textarea", "select", "dropdown", "combobox", "search", "form"];
782
+
783
+ for (const node of interactiveNodes) {
784
+ const name = node.name.toLowerCase();
785
+ const isInput = inputHints.some((hint) => name.includes(hint));
786
+ if (!isInput) continue;
787
+
788
+ // Check for a visible label — either a child TEXT or a sibling TEXT
789
+ const hasInternalLabel = node.children?.some(
790
+ (c) =>
791
+ c.type === "TEXT" &&
792
+ c.characters &&
793
+ c.characters.trim().length > 0 &&
794
+ !c.name.toLowerCase().includes("placeholder")
795
+ );
796
+
797
+ if (hasInternalLabel) continue;
798
+
799
+ // Check sibling labels
800
+ const parent = findParentNode(node.id, allNodes);
801
+ const hasSiblingLabel = parent?.children?.some(
802
+ (c) =>
803
+ c.type === "TEXT" &&
804
+ c.id !== node.id &&
805
+ c.characters &&
806
+ c.characters.trim().length > 0 &&
807
+ !c.name.toLowerCase().includes("placeholder")
808
+ );
809
+
810
+ if (hasSiblingLabel) continue;
811
+
812
+ issues.push({
813
+ severity: "warning",
814
+ criterion: "3.3.2",
815
+ nodeId: node.id,
816
+ nodeName: node.name,
817
+ issue: `Form input "${node.name}" has no visible label text`,
818
+ currentValue: "No label found",
819
+ suggestedFix: "Add a visible text label above or beside the input field. Do not rely solely on placeholder text as a label.",
820
+ autoFixAvailable: false,
821
+ });
822
+ }
823
+
824
+ return issues;
825
+ }
826
+
827
+ /** WCAG 4.1.2 Name, Role, Value – check interactive components for name/description. */
828
+ export function checkNameRoleValue(
829
+ interactiveNodes: FigmaNode[]
830
+ ): WCAGIssue[] {
831
+ const issues: WCAGIssue[] = [];
832
+
833
+ for (const node of interactiveNodes) {
834
+ // Icon-only interactive elements need accessible names
835
+ const hasVisibleText = findTextContent(node);
836
+ const hasDescription = node.description && node.description.trim().length > 0;
837
+
838
+ if (!hasVisibleText && !hasDescription) {
839
+ const name = node.name.toLowerCase();
840
+ // Only flag icon-like elements (small, no text)
841
+ const w = node.width ?? 0;
842
+ const h = node.height ?? 0;
843
+ if (w <= 48 && h <= 48) {
844
+ issues.push({
845
+ severity: "warning",
846
+ criterion: "4.1.2",
847
+ nodeId: node.id,
848
+ nodeName: node.name,
849
+ issue: `Interactive element "${node.name}" has no visible text or description — screen readers need an accessible name`,
850
+ currentValue: "No accessible name",
851
+ suggestedFix: "Add an aria-label (via description property in Figma) or include visible text for icon-only interactive elements.",
852
+ autoFixAvailable: false,
853
+ });
854
+ }
855
+ }
856
+ }
857
+
858
+ return issues;
859
+ }
860
+
861
+ /** WCAG 1.3.4 Orientation – check for portrait/landscape variant presence. */
862
+ export function checkOrientation(
863
+ componentSetNodes: FigmaNode[]
864
+ ): WCAGIssue[] {
865
+ // This is a page-level concern; at the component level, we just flag awareness
866
+ // Only meaningful for screen/page-level component sets
867
+ return [];
868
+ }
869
+
870
+ /** WCAG 1.3.5 Identify Input Purpose – check input names for autocomplete hints. */
871
+ export function checkIdentifyInputPurpose(
872
+ interactiveNodes: FigmaNode[]
873
+ ): WCAGIssue[] {
874
+ const issues: WCAGIssue[] = [];
875
+ const purposeHints = [
876
+ "name", "email", "tel", "phone", "address", "city", "state", "zip",
877
+ "postal", "country", "password", "username", "birthday", "cc-number",
878
+ "cc-name", "cc-exp", "credit",
879
+ ];
880
+
881
+ for (const node of interactiveNodes) {
882
+ const name = node.name.toLowerCase();
883
+ const isInput =
884
+ name.includes("input") ||
885
+ name.includes("text field") ||
886
+ name.includes("textfield");
887
+ if (!isInput) continue;
888
+
889
+ // Check if the input name or description hints at a known purpose
890
+ const matchesPurpose = purposeHints.some(
891
+ (hint) => name.includes(hint) || (node.description ?? "").toLowerCase().includes(hint)
892
+ );
893
+
894
+ if (matchesPurpose && !node.description?.toLowerCase().includes("autocomplete")) {
895
+ issues.push({
896
+ severity: "suggestion",
897
+ criterion: "1.3.5",
898
+ nodeId: node.id,
899
+ nodeName: node.name,
900
+ issue: `Input "${node.name}" appears to collect personal data — annotate with autocomplete purpose (e.g., autocomplete="email")`,
901
+ currentValue: "No autocomplete annotation",
902
+ suggestedFix: "Add autocomplete purpose annotation in the description property to support browser autofill.",
903
+ autoFixAvailable: false,
904
+ });
905
+ }
906
+ }
907
+
908
+ return issues;
909
+ }
910
+
911
+ // ─── Internal helpers for new checks ────────────────────────────────────────
912
+
913
+ function findParentNode(
914
+ nodeId: string,
915
+ allNodes: FigmaNode[]
916
+ ): FigmaNode | null {
917
+ for (const n of allNodes) {
918
+ if (n.children?.some((c) => c.id === nodeId)) return n;
919
+ if (n.children) {
920
+ const found = findParentNode(nodeId, n.children);
921
+ if (found) return found;
922
+ }
923
+ }
924
+ return null;
925
+ }
926
+
927
+ function colorsEqual(a: RGBA, b: RGBA): boolean {
928
+ return (
929
+ Math.abs(a.r - b.r) < 0.01 &&
930
+ Math.abs(a.g - b.g) < 0.01 &&
931
+ Math.abs(a.b - b.b) < 0.01
932
+ );
933
+ }
934
+
935
+ function hasStructuralDifference(a: FigmaNode, b: FigmaNode): boolean {
936
+ const aChildren = a.children || [];
937
+ const bChildren = b.children || [];
938
+
939
+ // Different child count
940
+ if (aChildren.length !== bChildren.length) return true;
941
+
942
+ // Different child types
943
+ for (let i = 0; i < aChildren.length; i++) {
944
+ if (aChildren[i].type !== bChildren[i]?.type) return true;
945
+ }
946
+
947
+ // Check for text content differences
948
+ const aTexts = aChildren
949
+ .filter((c) => c.type === "TEXT")
950
+ .map((c) => c.characters ?? "");
951
+ const bTexts = bChildren
952
+ .filter((c) => c.type === "TEXT")
953
+ .map((c) => c.characters ?? "");
954
+ if (aTexts.join("|") !== bTexts.join("|")) return true;
955
+
956
+ return false;
957
+ }
958
+
959
+ function countDescendants(node: FigmaNode): number {
960
+ if (!node.children) return 0;
961
+ let count = node.children.length;
962
+ for (const child of node.children) {
963
+ count += countDescendants(child);
964
+ }
965
+ return count;
966
+ }
967
+
968
+ function findTextContent(node: FigmaNode): string | null {
969
+ if (node.type === "TEXT" && node.characters) return node.characters;
970
+ if (node.children) {
971
+ for (const child of node.children) {
972
+ const text = findTextContent(child);
973
+ if (text) return text;
974
+ }
975
+ }
976
+ return null;
977
+ }
978
+
979
+ function hasHeadingChild(node: FigmaNode): boolean {
980
+ if (node.type === "TEXT") {
981
+ const fontSize = node.style?.fontSize ?? 16;
982
+ const fontWeight = node.style?.fontWeight ?? 400;
983
+ return fontSize >= 20 || fontWeight >= 700;
984
+ }
985
+ if (node.children) {
986
+ return node.children.some((c) => hasHeadingChild(c));
987
+ }
988
+ return false;
989
+ }