@agent-native/core 0.103.1 → 0.105.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 (568) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +61 -0
  3. package/corpus/core/package.json +9 -2
  4. package/corpus/core/src/agent/engine/credential-errors.ts +2 -2
  5. package/corpus/core/src/agent/production-agent.ts +30 -0
  6. package/corpus/core/src/agent/run-store.ts +12 -2
  7. package/corpus/core/src/cli/create.ts +1 -0
  8. package/corpus/core/src/cli/skills-content/visual-plan-skill.ts +30 -11
  9. package/corpus/core/src/cli/templates-meta.ts +4 -3
  10. package/corpus/core/src/client/AgentAskPopover.tsx +89 -0
  11. package/corpus/core/src/client/AgentChatHome.tsx +4 -0
  12. package/corpus/core/src/client/AgentPanel.tsx +321 -223
  13. package/corpus/core/src/client/AssistantChat.tsx +6 -10
  14. package/corpus/core/src/client/MultiTabAssistantChat.tsx +53 -372
  15. package/corpus/core/src/client/agent-chat-adapter.ts +13 -1
  16. package/corpus/core/src/client/agent-page/AgentContextTab.tsx +133 -149
  17. package/corpus/core/src/client/agent-page/AgentEmptyState.tsx +44 -0
  18. package/corpus/core/src/client/agent-page/AgentJobsTab.tsx +153 -82
  19. package/corpus/core/src/client/agent-page/AgentTabFrame.tsx +39 -0
  20. package/corpus/core/src/client/agent-page/AgentTabsPage.tsx +368 -356
  21. package/corpus/core/src/client/agent-page/types.ts +1 -1
  22. package/corpus/core/src/client/analytics.ts +51 -5
  23. package/corpus/core/src/client/chat/run-recovery.tsx +12 -4
  24. package/corpus/core/src/client/composer/PromptComposer.tsx +5 -15
  25. package/corpus/core/src/client/composer/TiptapComposer.tsx +32 -3
  26. package/corpus/core/src/client/dynamic-suggestions.ts +3 -3
  27. package/corpus/core/src/client/index.ts +16 -1
  28. package/corpus/core/src/client/resources/ResourceTree.tsx +249 -38
  29. package/corpus/core/src/client/resources/ResourcesPanel.tsx +307 -140
  30. package/corpus/core/src/client/session-replay.ts +158 -5
  31. package/corpus/core/src/client/settings/AutomationsSection.tsx +30 -10
  32. package/corpus/core/src/client/settings/SettingsPanel.tsx +3 -2
  33. package/corpus/core/src/client/settings/SettingsTabsPage.tsx +2 -0
  34. package/corpus/core/src/client/settings/agent-settings-search.ts +2 -2
  35. package/corpus/core/src/client/use-chat-threads.ts +2 -0
  36. package/corpus/core/src/connections/catalog.ts +49 -7
  37. package/corpus/core/src/db/index.ts +6 -1
  38. package/corpus/core/src/deploy/build.ts +23 -0
  39. package/corpus/core/src/extensions/actions.ts +106 -16
  40. package/corpus/core/src/extensions/content-patch.ts +22 -0
  41. package/corpus/core/src/extensions/routes.ts +18 -0
  42. package/corpus/core/src/extensions/store.ts +8 -0
  43. package/corpus/core/src/index.ts +3 -0
  44. package/corpus/core/src/ingestion/docx.ts +158 -0
  45. package/corpus/core/src/ingestion/figma-node-to-html.ts +1860 -0
  46. package/corpus/core/src/ingestion/figma.ts +548 -0
  47. package/corpus/core/src/ingestion/index.ts +107 -0
  48. package/corpus/core/src/ingestion/media.ts +264 -0
  49. package/corpus/core/src/ingestion/notion.ts +121 -0
  50. package/corpus/core/src/ingestion/office.ts +214 -0
  51. package/corpus/core/src/ingestion/orchestration.ts +160 -0
  52. package/corpus/core/src/ingestion/pptx.ts +333 -0
  53. package/corpus/core/src/ingestion/selection.ts +81 -0
  54. package/corpus/core/src/ingestion/website.ts +151 -0
  55. package/corpus/core/src/integrations/plugin.ts +45 -37
  56. package/corpus/core/src/localization/default-messages.ts +35 -12
  57. package/corpus/core/src/observability/hosted-model-experiment.ts +118 -0
  58. package/corpus/core/src/observability/traces.ts +5 -3
  59. package/corpus/core/src/provider-api/index.ts +452 -8
  60. package/corpus/core/src/scripts/agent-engines/list-agent-engines.ts +18 -1
  61. package/corpus/core/src/search-utils/index.ts +112 -0
  62. package/corpus/core/src/secrets/register-framework-secrets.ts +61 -0
  63. package/corpus/core/src/server/action-discovery.ts +33 -8
  64. package/corpus/core/src/server/agent-chat/framework-prompts.ts +2 -2
  65. package/corpus/core/src/server/agent-chat/prompt-resources.ts +144 -0
  66. package/corpus/core/src/server/agent-chat-plugin.ts +6 -0
  67. package/corpus/core/src/server/core-routes-plugin.ts +12 -0
  68. package/corpus/core/src/server/index.ts +30 -0
  69. package/corpus/core/src/server/workspace-provider-oauth.ts +583 -0
  70. package/corpus/core/src/styles/agent-native.css +9 -0
  71. package/corpus/core/src/templates/default/app/i18n/en-US.ts +3 -3
  72. package/corpus/core/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
  73. package/corpus/core/src/templates/workspace-root/.env.example +12 -0
  74. package/corpus/core/src/workspace-connections/index.ts +6 -0
  75. package/corpus/core/src/workspace-connections/lifecycle.ts +43 -0
  76. package/corpus/core/src/workspace-connections/store.ts +16 -0
  77. package/corpus/templates/analytics/.agents/skills/dashboard-management/SKILL.md +46 -3
  78. package/corpus/templates/analytics/AGENTS.md +9 -0
  79. package/corpus/templates/analytics/actions/dashboard-mutation-api.ts +120 -6
  80. package/corpus/templates/analytics/actions/mutate-dashboard.ts +92 -30
  81. package/corpus/templates/analytics/actions/update-dashboard.ts +5 -5
  82. package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +313 -220
  83. package/corpus/templates/analytics/app/components/layout/CommandPalette.tsx +2 -2
  84. package/corpus/templates/analytics/app/components/layout/Layout.tsx +9 -6
  85. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +90 -64
  86. package/corpus/templates/analytics/app/i18n-data.ts +3 -3
  87. package/corpus/templates/analytics/app/lib/dashboard-list-loading.ts +25 -0
  88. package/corpus/templates/analytics/app/lib/item-popularity.ts +13 -4
  89. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/DashboardFilterBar.tsx +1 -1
  90. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/pivot.ts +8 -3
  91. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/types.ts +1 -0
  92. package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +15 -3
  93. package/corpus/templates/analytics/changelog/2026-07-16-dashboard-filter-defaults-can-now-be-changed-reliably-withou.md +6 -0
  94. package/corpus/templates/analytics/changelog/2026-07-16-dashboard-lists-load-in-one-stable-order-without-popping-bet.md +6 -0
  95. package/corpus/templates/analytics/changelog/2026-07-16-fixed-dashboard-filter-dropdown-text-alignment.md +6 -0
  96. package/corpus/templates/analytics/changelog/2026-07-16-recurring-signed-in-users-can-now-be-viewed-as-weekly-bars-b.md +6 -0
  97. package/corpus/templates/analytics/changelog/2026-07-16-the-analytics-agent-can-now-duplicate-a-chart-and-place-the-.md +6 -0
  98. package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +41 -1
  99. package/corpus/templates/analytics/server/lib/dashboard-catalog.ts +1 -1
  100. package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +47 -1
  101. package/corpus/templates/analytics/server/lib/session-replay.ts +68 -0
  102. package/corpus/templates/analytics/server/plugins/agent-chat.ts +1 -0
  103. package/corpus/templates/analytics/server/routes/sessions/lookup.get.ts +47 -0
  104. package/corpus/templates/assets/.agents/skills/asset-generation/SKILL.md +16 -9
  105. package/corpus/templates/assets/.agents/skills/creative-context/SKILL.md +86 -0
  106. package/corpus/templates/assets/AGENTS.md +10 -0
  107. package/corpus/templates/assets/actions/create-generation-session.ts +59 -1
  108. package/corpus/templates/assets/actions/edit-image.ts +2 -0
  109. package/corpus/templates/assets/actions/generate-asset.ts +52 -0
  110. package/corpus/templates/assets/actions/generate-image-batch.ts +55 -0
  111. package/corpus/templates/assets/actions/generate-image.ts +219 -1
  112. package/corpus/templates/assets/actions/open-asset-picker.ts +14 -0
  113. package/corpus/templates/assets/actions/refine-image.ts +3 -0
  114. package/corpus/templates/assets/actions/restyle-image.ts +2 -0
  115. package/corpus/templates/assets/agent-native.app-skill.json +4 -0
  116. package/corpus/templates/assets/app/components/layout/Layout.tsx +2 -0
  117. package/corpus/templates/assets/app/i18n/zh-TW.ts +3 -0
  118. package/corpus/templates/assets/app/i18n-data.ts +29 -13
  119. package/corpus/templates/assets/app/routes/agent.tsx +7 -1
  120. package/corpus/templates/assets/app/routes/library.tsx +9 -0
  121. package/corpus/templates/assets/app/routes/settings.tsx +3 -0
  122. package/corpus/templates/assets/changelog/2026-07-16-creative-context-library.md +6 -0
  123. package/corpus/templates/assets/package.json +1 -0
  124. package/corpus/templates/assets/server/lib/image-processing.ts +1 -22
  125. package/corpus/templates/assets/server/plugins/creative-context.ts +205 -0
  126. package/corpus/templates/brain/app/i18n-data.ts +3 -3
  127. package/corpus/templates/brain/app/lib/brain.ts +1 -1
  128. package/corpus/templates/brain/server/lib/search.ts +17 -67
  129. package/corpus/templates/calendar/app/i18n-data.ts +3 -3
  130. package/corpus/templates/calendar/app/pages/BookingLinksPage.tsx +19 -18
  131. package/corpus/templates/chat/app/i18n/en-US.ts +3 -3
  132. package/corpus/templates/chat/app/lib/agent-page.tsx +10 -1
  133. package/corpus/templates/clips/.agents/skills/meetings/SKILL.md +1 -1
  134. package/corpus/templates/clips/AGENTS.md +4 -0
  135. package/corpus/templates/clips/actions/cleanup-transcript.ts +35 -4
  136. package/corpus/templates/clips/actions/create-meeting.ts +6 -2
  137. package/corpus/templates/clips/actions/create-organization.ts +3 -2
  138. package/corpus/templates/clips/actions/create-recording.ts +4 -1
  139. package/corpus/templates/clips/actions/finalize-recording.ts +44 -7
  140. package/corpus/templates/clips/actions/import-loom-recording.ts +4 -1
  141. package/corpus/templates/clips/actions/lib/create-recording-schema.ts +2 -2
  142. package/corpus/templates/clips/actions/list-meetings.ts +23 -5
  143. package/corpus/templates/clips/actions/list-organization-state.ts +1 -1
  144. package/corpus/templates/clips/actions/remove-silences.ts +10 -1
  145. package/corpus/templates/clips/actions/request-transcript.ts +53 -11
  146. package/corpus/templates/clips/actions/search-recordings-utils.ts +7 -0
  147. package/corpus/templates/clips/actions/search-recordings.ts +5 -8
  148. package/corpus/templates/clips/actions/set-organization-branding.ts +2 -2
  149. package/corpus/templates/clips/actions/stitch-recordings.ts +10 -5
  150. package/corpus/templates/clips/actions/update-ai-request-status.ts +38 -0
  151. package/corpus/templates/clips/app/components/editor/editor-layout.tsx +3 -4
  152. package/corpus/templates/clips/app/components/editor/editor-selection.ts +19 -0
  153. package/corpus/templates/clips/app/components/editor/stitch-manager.tsx +10 -10
  154. package/corpus/templates/clips/app/components/library/bulk-action-toolbar.tsx +1 -2
  155. package/corpus/templates/clips/app/components/library/library-grid.tsx +101 -93
  156. package/corpus/templates/clips/app/components/player/video-player.tsx +11 -0
  157. package/corpus/templates/clips/app/components/workspace/branding-editor.tsx +53 -1
  158. package/corpus/templates/clips/app/i18n/ar-SA.ts +7 -1
  159. package/corpus/templates/clips/app/i18n/de-DE.ts +7 -1
  160. package/corpus/templates/clips/app/i18n/en-US.ts +10 -4
  161. package/corpus/templates/clips/app/i18n/es-ES.ts +7 -1
  162. package/corpus/templates/clips/app/i18n/fr-FR.ts +7 -1
  163. package/corpus/templates/clips/app/i18n/hi-IN.ts +7 -1
  164. package/corpus/templates/clips/app/i18n/ja-JP.ts +7 -1
  165. package/corpus/templates/clips/app/i18n/ko-KR.ts +7 -1
  166. package/corpus/templates/clips/app/i18n/pt-BR.ts +7 -1
  167. package/corpus/templates/clips/app/i18n/zh-CN.ts +6 -1
  168. package/corpus/templates/clips/app/i18n/zh-TW.ts +6 -1
  169. package/corpus/templates/clips/app/routes/_app.settings._index.tsx +5 -9
  170. package/corpus/templates/clips/app/routes/_app.settings.organization.tsx +6 -2
  171. package/corpus/templates/clips/app/routes/r.$recordingId.tsx +129 -27
  172. package/corpus/templates/clips/app/routes/record.tsx +23 -2
  173. package/corpus/templates/clips/app/routes/share.$shareId.tsx +6 -2
  174. package/corpus/templates/clips/app/routes.ts +3 -1
  175. package/corpus/templates/clips/changelog/2026-07-16-authorized-viewers-can-open-shared-private-clips-without-a-m.md +6 -0
  176. package/corpus/templates/clips/changelog/2026-07-16-camera-bubble-hover-controls-appear-above-the-face.md +6 -0
  177. package/corpus/templates/clips/changelog/2026-07-16-chrome-extension-recovers-stale-recorder-state.md +6 -0
  178. package/corpus/templates/clips/changelog/2026-07-16-clips-agent-chat-no-longer-shows-a-separate-workspace-header.md +6 -0
  179. package/corpus/templates/clips/changelog/2026-07-16-clips-search-now-matches-recording-content-without-requiring.md +6 -0
  180. package/corpus/templates/clips/changelog/2026-07-16-declined-meetings-no-longer-show-desktop-reminders.md +6 -0
  181. package/corpus/templates/clips/changelog/2026-07-16-failed-desktop-saves-now-show-their-local-recovery-copy.md +6 -0
  182. package/corpus/templates/clips/changelog/2026-07-16-long-desktop-clips-now-preserve-complete-playback-synced-aud.md +6 -0
  183. package/corpus/templates/clips/changelog/2026-07-16-long-recording-lists-keep-stitch-and-library-actions-visible.md +6 -0
  184. package/corpus/templates/clips/changelog/2026-07-16-organization-admins-can-choose-new-recording-visibility.md +6 -0
  185. package/corpus/templates/clips/changelog/2026-07-16-remove-silences-now-shows-queued-active-completed-and-failed.md +6 -0
  186. package/corpus/templates/clips/changelog/2026-07-16-settings-no-longer-repeats-the-builder-connection-status-in-.md +6 -0
  187. package/corpus/templates/clips/changelog/2026-07-16-transcripts-now-appear-from-native-browser-speech-sooner-wit.md +6 -0
  188. package/corpus/templates/clips/chrome-extension/public/manifest.json +1 -1
  189. package/corpus/templates/clips/chrome-extension/src/background.ts +73 -1
  190. package/corpus/templates/clips/chrome-extension/src/native-recording-state.ts +32 -0
  191. package/corpus/templates/clips/chrome-extension/src/native-transcription.ts +248 -0
  192. package/corpus/templates/clips/chrome-extension/src/offscreen.ts +106 -0
  193. package/corpus/templates/clips/desktop/src/app.tsx +66 -28
  194. package/corpus/templates/clips/desktop/src/lib/recorder.ts +335 -285
  195. package/corpus/templates/clips/desktop/src/lib/single-flight.ts +7 -0
  196. package/corpus/templates/clips/desktop/src/lib/upload-verification.ts +51 -0
  197. package/corpus/templates/clips/desktop/src/overlays/bubble.tsx +2 -2
  198. package/corpus/templates/clips/desktop/src/overlays/finalizing.tsx +10 -2
  199. package/corpus/templates/clips/desktop/src/styles.css +13 -11
  200. package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +8 -9
  201. package/corpus/templates/clips/desktop/src-tauri/src/meetings_watcher.rs +1 -0
  202. package/corpus/templates/clips/desktop/src-tauri/src/native_screen/custom_capture.rs +88 -13
  203. package/corpus/templates/clips/desktop/src-tauri/src/native_screen/live_upload.rs +13 -2
  204. package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +241 -6
  205. package/corpus/templates/clips/server/db/schema.ts +2 -2
  206. package/corpus/templates/clips/server/lib/builder-media-compression.ts +64 -67
  207. package/corpus/templates/clips/server/lib/calendar-event-classification.ts +19 -0
  208. package/corpus/templates/clips/server/lib/google-calendar-client.ts +1 -0
  209. package/corpus/templates/clips/server/lib/recordings.ts +40 -1
  210. package/corpus/templates/clips/server/plugins/agent-chat.ts +1 -0
  211. package/corpus/templates/clips/server/plugins/db.ts +2 -2
  212. package/corpus/templates/clips/server/routes/api/auth/google-calendar.get.ts +1 -1
  213. package/corpus/templates/clips/server/routes/api/public-recording.get.ts +14 -5
  214. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/chunk.post.ts +51 -1
  215. package/corpus/templates/clips/server/routes/api/video/[recordingId].get.ts +1 -64
  216. package/corpus/templates/clips/shared/media-worker-contract.ts +32 -15
  217. package/corpus/templates/content/.agents/skills/content/SKILL.md +16 -0
  218. package/corpus/templates/content/.agents/skills/creative-context/SKILL.md +85 -0
  219. package/corpus/templates/content/.agents/skills/notion-integration/SKILL.md +8 -0
  220. package/corpus/templates/content/AGENTS.md +9 -0
  221. package/corpus/templates/content/actions/create-document.ts +94 -0
  222. package/corpus/templates/content/actions/edit-document.ts +144 -4
  223. package/corpus/templates/content/actions/update-document.ts +138 -0
  224. package/corpus/templates/content/agent-native.app-skill.json +4 -0
  225. package/corpus/templates/content/app/components/layout/Layout.tsx +2 -0
  226. package/corpus/templates/content/app/i18n/zh-TW.ts +3 -0
  227. package/corpus/templates/content/app/i18n-data.ts +13 -4
  228. package/corpus/templates/content/app/routes/_app.agent.tsx +2 -1
  229. package/corpus/templates/content/app/routes/_app.settings.tsx +3 -0
  230. package/corpus/templates/content/changelog/2026-07-16-creative-context-library.md +6 -0
  231. package/corpus/templates/content/package.json +1 -0
  232. package/corpus/templates/content/server/plugins/creative-context.ts +31 -0
  233. package/corpus/templates/design/.agents/skills/creative-context/SKILL.md +116 -0
  234. package/corpus/templates/design/.agents/skills/design-generation/SKILL.md +16 -0
  235. package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +8 -0
  236. package/corpus/templates/design/AGENTS.md +6 -0
  237. package/corpus/templates/design/actions/clone-creative-context-design.ts +176 -0
  238. package/corpus/templates/design/actions/edit-design.ts +128 -0
  239. package/corpus/templates/design/actions/generate-design.ts +278 -14
  240. package/corpus/templates/design/actions/generate-screens.ts +42 -1
  241. package/corpus/templates/design/agent-native.app-skill.json +4 -0
  242. package/corpus/templates/design/app/components/layout/Layout.tsx +7 -3
  243. package/corpus/templates/design/app/i18n/zh-TW.ts +3 -0
  244. package/corpus/templates/design/app/i18n-data.ts +10 -4
  245. package/corpus/templates/design/app/routes/agent.tsx +2 -1
  246. package/corpus/templates/design/app/routes/settings.tsx +3 -0
  247. package/corpus/templates/design/changelog/2026-07-16-creative-context-library.md +6 -0
  248. package/corpus/templates/design/changelog/2026-07-16-design-agent-chat-no-longer-shows-a-separate-workspace-header.md +6 -0
  249. package/corpus/templates/design/package.json +1 -0
  250. package/corpus/templates/design/server/lib/figma-design-context.ts +5 -335
  251. package/corpus/templates/design/server/lib/figma-node-to-html.ts +1 -1859
  252. package/corpus/templates/design/server/lib/import-design-files.ts +6 -8
  253. package/corpus/templates/design/server/plugins/creative-context.ts +31 -0
  254. package/corpus/templates/design/shared/generation-session.ts +7 -0
  255. package/corpus/templates/dispatch/app/i18n-data.ts +3 -3
  256. package/corpus/templates/forms/app/i18n/en-US.ts +3 -3
  257. package/corpus/templates/macros/app/i18n/en-US.ts +3 -3
  258. package/corpus/templates/mail/app/components/email/EmailThread.tsx +35 -5
  259. package/corpus/templates/mail/app/i18n/en-US.ts +3 -3
  260. package/corpus/templates/mail/changelog/2026-07-16-mail-previews-now-expand-to-show-the-full-message-without-an.md +6 -0
  261. package/corpus/templates/plan/.agents/skills/visual-plan/SKILL.md +30 -11
  262. package/corpus/templates/plan/AGENTS.md +21 -1
  263. package/corpus/templates/plan/actions/get-visual-plan.ts +1 -1
  264. package/corpus/templates/plan/actions/patch-visual-plan-source.ts +161 -0
  265. package/corpus/templates/plan/actions/read-visual-plan-source.ts +1 -1
  266. package/corpus/templates/plan/actions/update-visual-plan.ts +126 -10
  267. package/corpus/templates/plan/app/hooks/use-plans.ts +2 -0
  268. package/corpus/templates/plan/app/i18n/en-US.ts +3 -3
  269. package/corpus/templates/plan/app/pages/PlansPage.tsx +65 -62
  270. package/corpus/templates/plan/changelog/2026-07-16-local-plan-previews-now-load-annotations-containing-html-lik.md +6 -0
  271. package/corpus/templates/plan/changelog/2026-07-16-plan-agents-now-prevent-stale-edits-from-overwriting-newer-p.md +6 -0
  272. package/corpus/templates/plan/server/plan-mdx.ts +75 -2
  273. package/corpus/templates/slides/.agents/skills/create-deck/SKILL.md +21 -4
  274. package/corpus/templates/slides/.agents/skills/creative-context/SKILL.md +122 -0
  275. package/corpus/templates/slides/.agents/skills/design-systems/SKILL.md +11 -0
  276. package/corpus/templates/slides/.agents/skills/slide-editing/SKILL.md +12 -3
  277. package/corpus/templates/slides/AGENTS.md +6 -0
  278. package/corpus/templates/slides/actions/add-slide.ts +230 -14
  279. package/corpus/templates/slides/actions/clone-context-slide.ts +302 -0
  280. package/corpus/templates/slides/actions/create-deck.ts +130 -0
  281. package/corpus/templates/slides/actions/extract-pdf.ts +6 -2
  282. package/corpus/templates/slides/actions/import-file.ts +5 -4
  283. package/corpus/templates/slides/actions/patch-deck.ts +200 -10
  284. package/corpus/templates/slides/actions/update-slide.ts +208 -15
  285. package/corpus/templates/slides/app/components/layout/Layout.tsx +2 -0
  286. package/corpus/templates/slides/app/components/visual-editor/CanvasCommentPins.tsx +16 -1
  287. package/corpus/templates/slides/app/i18n/ar-SA.ts +3 -0
  288. package/corpus/templates/slides/app/i18n/de-DE.ts +3 -0
  289. package/corpus/templates/slides/app/i18n/en-US.ts +6 -3
  290. package/corpus/templates/slides/app/i18n/es-ES.ts +3 -0
  291. package/corpus/templates/slides/app/i18n/fr-FR.ts +3 -0
  292. package/corpus/templates/slides/app/i18n/hi-IN.ts +3 -0
  293. package/corpus/templates/slides/app/i18n/ja-JP.ts +3 -0
  294. package/corpus/templates/slides/app/i18n/ko-KR.ts +3 -0
  295. package/corpus/templates/slides/app/i18n/pt-BR.ts +3 -0
  296. package/corpus/templates/slides/app/i18n/zh-CN.ts +3 -0
  297. package/corpus/templates/slides/app/i18n/zh-TW.ts +3 -0
  298. package/corpus/templates/slides/app/lib/validate-native-slide-html.ts +176 -0
  299. package/corpus/templates/slides/app/routes/agent.tsx +7 -1
  300. package/corpus/templates/slides/app/routes/settings.tsx +3 -0
  301. package/corpus/templates/slides/changelog/2026-07-16-creative-context-library.md +6 -0
  302. package/corpus/templates/slides/changelog/2026-07-16-google-slides-native-cloning.md +6 -0
  303. package/corpus/templates/slides/package.json +1 -0
  304. package/corpus/templates/slides/server/handlers/import/docx-parser.ts +4 -85
  305. package/corpus/templates/slides/server/handlers/import/pptx-parser.ts +7 -421
  306. package/corpus/templates/slides/server/plugins/creative-context.ts +166 -0
  307. package/dist/agent/engine/credential-errors.d.ts +1 -1
  308. package/dist/agent/engine/credential-errors.d.ts.map +1 -1
  309. package/dist/agent/engine/credential-errors.js +2 -2
  310. package/dist/agent/engine/credential-errors.js.map +1 -1
  311. package/dist/agent/production-agent.d.ts.map +1 -1
  312. package/dist/agent/production-agent.js +25 -0
  313. package/dist/agent/production-agent.js.map +1 -1
  314. package/dist/agent/run-store.d.ts.map +1 -1
  315. package/dist/agent/run-store.js +12 -2
  316. package/dist/agent/run-store.js.map +1 -1
  317. package/dist/cli/create.d.ts.map +1 -1
  318. package/dist/cli/create.js +1 -0
  319. package/dist/cli/create.js.map +1 -1
  320. package/dist/cli/skills-content/visual-plan-skill.d.ts +1 -1
  321. package/dist/cli/skills-content/visual-plan-skill.d.ts.map +1 -1
  322. package/dist/cli/skills-content/visual-plan-skill.js +30 -11
  323. package/dist/cli/skills-content/visual-plan-skill.js.map +1 -1
  324. package/dist/cli/templates-meta.d.ts.map +1 -1
  325. package/dist/cli/templates-meta.js +4 -3
  326. package/dist/cli/templates-meta.js.map +1 -1
  327. package/dist/client/AgentAskPopover.d.ts +11 -0
  328. package/dist/client/AgentAskPopover.d.ts.map +1 -0
  329. package/dist/client/AgentAskPopover.js +30 -0
  330. package/dist/client/AgentAskPopover.js.map +1 -0
  331. package/dist/client/AgentChatHome.d.ts +1 -1
  332. package/dist/client/AgentChatHome.d.ts.map +1 -1
  333. package/dist/client/AgentChatHome.js +2 -2
  334. package/dist/client/AgentChatHome.js.map +1 -1
  335. package/dist/client/AgentPanel.d.ts +9 -19
  336. package/dist/client/AgentPanel.d.ts.map +1 -1
  337. package/dist/client/AgentPanel.js +119 -80
  338. package/dist/client/AgentPanel.js.map +1 -1
  339. package/dist/client/AssistantChat.d.ts.map +1 -1
  340. package/dist/client/AssistantChat.js +4 -4
  341. package/dist/client/AssistantChat.js.map +1 -1
  342. package/dist/client/MultiTabAssistantChat.d.ts +3 -9
  343. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  344. package/dist/client/MultiTabAssistantChat.js +49 -189
  345. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  346. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  347. package/dist/client/agent-chat-adapter.js +12 -1
  348. package/dist/client/agent-chat-adapter.js.map +1 -1
  349. package/dist/client/agent-page/AgentContextTab.d.ts.map +1 -1
  350. package/dist/client/agent-page/AgentContextTab.js +26 -28
  351. package/dist/client/agent-page/AgentContextTab.js.map +1 -1
  352. package/dist/client/agent-page/AgentEmptyState.d.ts +13 -0
  353. package/dist/client/agent-page/AgentEmptyState.d.ts.map +1 -0
  354. package/dist/client/agent-page/AgentEmptyState.js +6 -0
  355. package/dist/client/agent-page/AgentEmptyState.js.map +1 -0
  356. package/dist/client/agent-page/AgentJobsTab.d.ts +1 -1
  357. package/dist/client/agent-page/AgentJobsTab.d.ts.map +1 -1
  358. package/dist/client/agent-page/AgentJobsTab.js +90 -58
  359. package/dist/client/agent-page/AgentJobsTab.js.map +1 -1
  360. package/dist/client/agent-page/AgentTabFrame.d.ts +12 -0
  361. package/dist/client/agent-page/AgentTabFrame.d.ts.map +1 -0
  362. package/dist/client/agent-page/AgentTabFrame.js +7 -0
  363. package/dist/client/agent-page/AgentTabFrame.js.map +1 -0
  364. package/dist/client/agent-page/AgentTabsPage.d.ts +9 -1
  365. package/dist/client/agent-page/AgentTabsPage.d.ts.map +1 -1
  366. package/dist/client/agent-page/AgentTabsPage.js +135 -99
  367. package/dist/client/agent-page/AgentTabsPage.js.map +1 -1
  368. package/dist/client/agent-page/types.d.ts +1 -1
  369. package/dist/client/agent-page/types.d.ts.map +1 -1
  370. package/dist/client/agent-page/types.js.map +1 -1
  371. package/dist/client/analytics.d.ts +10 -3
  372. package/dist/client/analytics.d.ts.map +1 -1
  373. package/dist/client/analytics.js +37 -2
  374. package/dist/client/analytics.js.map +1 -1
  375. package/dist/client/chat/run-recovery.d.ts.map +1 -1
  376. package/dist/client/chat/run-recovery.js +10 -3
  377. package/dist/client/chat/run-recovery.js.map +1 -1
  378. package/dist/client/composer/PromptComposer.d.ts.map +1 -1
  379. package/dist/client/composer/PromptComposer.js +2 -2
  380. package/dist/client/composer/PromptComposer.js.map +1 -1
  381. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  382. package/dist/client/composer/TiptapComposer.js +15 -3
  383. package/dist/client/composer/TiptapComposer.js.map +1 -1
  384. package/dist/client/dynamic-suggestions.js +3 -3
  385. package/dist/client/dynamic-suggestions.js.map +1 -1
  386. package/dist/client/index.d.ts +4 -3
  387. package/dist/client/index.d.ts.map +1 -1
  388. package/dist/client/index.js +3 -2
  389. package/dist/client/index.js.map +1 -1
  390. package/dist/client/resources/ResourceTree.d.ts +5 -1
  391. package/dist/client/resources/ResourceTree.d.ts.map +1 -1
  392. package/dist/client/resources/ResourceTree.js +74 -5
  393. package/dist/client/resources/ResourceTree.js.map +1 -1
  394. package/dist/client/resources/ResourcesPanel.d.ts +11 -2
  395. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  396. package/dist/client/resources/ResourcesPanel.js +105 -31
  397. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  398. package/dist/client/session-replay.d.ts +28 -0
  399. package/dist/client/session-replay.d.ts.map +1 -1
  400. package/dist/client/session-replay.js +122 -8
  401. package/dist/client/session-replay.js.map +1 -1
  402. package/dist/client/settings/AutomationsSection.d.ts +3 -1
  403. package/dist/client/settings/AutomationsSection.d.ts.map +1 -1
  404. package/dist/client/settings/AutomationsSection.js +16 -6
  405. package/dist/client/settings/AutomationsSection.js.map +1 -1
  406. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  407. package/dist/client/settings/SettingsPanel.js +3 -3
  408. package/dist/client/settings/SettingsPanel.js.map +1 -1
  409. package/dist/client/settings/SettingsTabsPage.d.ts +2 -0
  410. package/dist/client/settings/SettingsTabsPage.d.ts.map +1 -1
  411. package/dist/client/settings/SettingsTabsPage.js.map +1 -1
  412. package/dist/client/settings/agent-settings-search.js +2 -2
  413. package/dist/client/settings/agent-settings-search.js.map +1 -1
  414. package/dist/client/use-chat-threads.d.ts +2 -0
  415. package/dist/client/use-chat-threads.d.ts.map +1 -1
  416. package/dist/client/use-chat-threads.js.map +1 -1
  417. package/dist/connections/catalog.d.ts +41 -7
  418. package/dist/connections/catalog.d.ts.map +1 -1
  419. package/dist/connections/catalog.js +40 -7
  420. package/dist/connections/catalog.js.map +1 -1
  421. package/dist/db/index.d.ts +2 -2
  422. package/dist/db/index.d.ts.map +1 -1
  423. package/dist/db/index.js +2 -2
  424. package/dist/db/index.js.map +1 -1
  425. package/dist/deploy/build.d.ts.map +1 -1
  426. package/dist/deploy/build.js +17 -0
  427. package/dist/deploy/build.js.map +1 -1
  428. package/dist/extensions/actions.d.ts.map +1 -1
  429. package/dist/extensions/actions.js +85 -15
  430. package/dist/extensions/actions.js.map +1 -1
  431. package/dist/extensions/content-patch.d.ts +4 -0
  432. package/dist/extensions/content-patch.d.ts.map +1 -1
  433. package/dist/extensions/content-patch.js +18 -0
  434. package/dist/extensions/content-patch.js.map +1 -1
  435. package/dist/extensions/routes.d.ts.map +1 -1
  436. package/dist/extensions/routes.js +14 -0
  437. package/dist/extensions/routes.js.map +1 -1
  438. package/dist/extensions/store.d.ts +1 -0
  439. package/dist/extensions/store.d.ts.map +1 -1
  440. package/dist/extensions/store.js +4 -1
  441. package/dist/extensions/store.js.map +1 -1
  442. package/dist/index.d.ts +1 -1
  443. package/dist/index.d.ts.map +1 -1
  444. package/dist/index.js +1 -1
  445. package/dist/index.js.map +1 -1
  446. package/dist/ingestion/docx.d.ts +16 -0
  447. package/dist/ingestion/docx.d.ts.map +1 -0
  448. package/dist/ingestion/docx.js +129 -0
  449. package/dist/ingestion/docx.js.map +1 -0
  450. package/dist/ingestion/figma-node-to-html.d.ts +304 -0
  451. package/dist/ingestion/figma-node-to-html.d.ts.map +1 -0
  452. package/dist/ingestion/figma-node-to-html.js +1292 -0
  453. package/dist/ingestion/figma-node-to-html.js.map +1 -0
  454. package/dist/ingestion/figma.d.ts +115 -0
  455. package/dist/ingestion/figma.d.ts.map +1 -0
  456. package/dist/ingestion/figma.js +399 -0
  457. package/dist/ingestion/figma.js.map +1 -0
  458. package/dist/ingestion/index.d.ts +11 -0
  459. package/dist/ingestion/index.d.ts.map +1 -0
  460. package/dist/ingestion/index.js +11 -0
  461. package/dist/ingestion/index.js.map +1 -0
  462. package/dist/ingestion/media.d.ts +36 -0
  463. package/dist/ingestion/media.d.ts.map +1 -0
  464. package/dist/ingestion/media.js +178 -0
  465. package/dist/ingestion/media.js.map +1 -0
  466. package/dist/ingestion/notion.d.ts +12 -0
  467. package/dist/ingestion/notion.d.ts.map +1 -0
  468. package/dist/ingestion/notion.js +104 -0
  469. package/dist/ingestion/notion.js.map +1 -0
  470. package/dist/ingestion/office.d.ts +45 -0
  471. package/dist/ingestion/office.d.ts.map +1 -0
  472. package/dist/ingestion/office.js +141 -0
  473. package/dist/ingestion/office.js.map +1 -0
  474. package/dist/ingestion/orchestration.d.ts +52 -0
  475. package/dist/ingestion/orchestration.d.ts.map +1 -0
  476. package/dist/ingestion/orchestration.js +89 -0
  477. package/dist/ingestion/orchestration.js.map +1 -0
  478. package/dist/ingestion/pptx.d.ts +28 -0
  479. package/dist/ingestion/pptx.d.ts.map +1 -0
  480. package/dist/ingestion/pptx.js +255 -0
  481. package/dist/ingestion/pptx.js.map +1 -0
  482. package/dist/ingestion/selection.d.ts +20 -0
  483. package/dist/ingestion/selection.d.ts.map +1 -0
  484. package/dist/ingestion/selection.js +52 -0
  485. package/dist/ingestion/selection.js.map +1 -0
  486. package/dist/ingestion/website.d.ts +27 -0
  487. package/dist/ingestion/website.d.ts.map +1 -0
  488. package/dist/ingestion/website.js +100 -0
  489. package/dist/ingestion/website.js.map +1 -0
  490. package/dist/integrations/plugin.d.ts.map +1 -1
  491. package/dist/integrations/plugin.js +32 -27
  492. package/dist/integrations/plugin.js.map +1 -1
  493. package/dist/localization/default-messages.d.ts +22 -0
  494. package/dist/localization/default-messages.d.ts.map +1 -1
  495. package/dist/localization/default-messages.js +31 -9
  496. package/dist/localization/default-messages.js.map +1 -1
  497. package/dist/notifications/routes.d.ts +2 -2
  498. package/dist/observability/hosted-model-experiment.d.ts +39 -0
  499. package/dist/observability/hosted-model-experiment.d.ts.map +1 -0
  500. package/dist/observability/hosted-model-experiment.js +90 -0
  501. package/dist/observability/hosted-model-experiment.js.map +1 -0
  502. package/dist/observability/routes.d.ts +5 -5
  503. package/dist/observability/traces.d.ts.map +1 -1
  504. package/dist/observability/traces.js +5 -3
  505. package/dist/observability/traces.js.map +1 -1
  506. package/dist/provider-api/index.d.ts +35 -4
  507. package/dist/provider-api/index.d.ts.map +1 -1
  508. package/dist/provider-api/index.js +339 -8
  509. package/dist/provider-api/index.js.map +1 -1
  510. package/dist/scripts/agent-engines/list-agent-engines.d.ts.map +1 -1
  511. package/dist/scripts/agent-engines/list-agent-engines.js +18 -1
  512. package/dist/scripts/agent-engines/list-agent-engines.js.map +1 -1
  513. package/dist/search-utils/index.d.ts +12 -0
  514. package/dist/search-utils/index.d.ts.map +1 -0
  515. package/dist/search-utils/index.js +95 -0
  516. package/dist/search-utils/index.js.map +1 -0
  517. package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
  518. package/dist/secrets/register-framework-secrets.js +57 -0
  519. package/dist/secrets/register-framework-secrets.js.map +1 -1
  520. package/dist/secrets/routes.d.ts +9 -9
  521. package/dist/server/action-discovery.d.ts +8 -0
  522. package/dist/server/action-discovery.d.ts.map +1 -1
  523. package/dist/server/action-discovery.js +26 -9
  524. package/dist/server/action-discovery.js.map +1 -1
  525. package/dist/server/agent-chat/framework-prompts.js +2 -2
  526. package/dist/server/agent-chat/framework-prompts.js.map +1 -1
  527. package/dist/server/agent-chat/prompt-resources.d.ts +19 -0
  528. package/dist/server/agent-chat/prompt-resources.d.ts.map +1 -1
  529. package/dist/server/agent-chat/prompt-resources.js +95 -0
  530. package/dist/server/agent-chat/prompt-resources.js.map +1 -1
  531. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  532. package/dist/server/agent-chat-plugin.js +7 -0
  533. package/dist/server/agent-chat-plugin.js.map +1 -1
  534. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  535. package/dist/server/core-routes-plugin.js +5 -0
  536. package/dist/server/core-routes-plugin.js.map +1 -1
  537. package/dist/server/index.d.ts +5 -1
  538. package/dist/server/index.d.ts.map +1 -1
  539. package/dist/server/index.js +5 -1
  540. package/dist/server/index.js.map +1 -1
  541. package/dist/server/workspace-provider-oauth.d.ts +48 -0
  542. package/dist/server/workspace-provider-oauth.d.ts.map +1 -0
  543. package/dist/server/workspace-provider-oauth.js +415 -0
  544. package/dist/server/workspace-provider-oauth.js.map +1 -0
  545. package/dist/styles/agent-native.css +9 -0
  546. package/dist/templates/chat/app/i18n/en-US.ts +3 -3
  547. package/dist/templates/chat/app/lib/agent-page.tsx +10 -1
  548. package/dist/templates/default/app/i18n/en-US.ts +3 -3
  549. package/dist/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
  550. package/dist/templates/workspace-root/.env.example +12 -0
  551. package/dist/workspace-connections/index.d.ts +1 -0
  552. package/dist/workspace-connections/index.d.ts.map +1 -1
  553. package/dist/workspace-connections/index.js +1 -0
  554. package/dist/workspace-connections/index.js.map +1 -1
  555. package/dist/workspace-connections/lifecycle.d.ts +16 -0
  556. package/dist/workspace-connections/lifecycle.d.ts.map +1 -0
  557. package/dist/workspace-connections/lifecycle.js +14 -0
  558. package/dist/workspace-connections/lifecycle.js.map +1 -0
  559. package/dist/workspace-connections/store.d.ts.map +1 -1
  560. package/dist/workspace-connections/store.js +16 -0
  561. package/dist/workspace-connections/store.js.map +1 -1
  562. package/package.json +10 -3
  563. package/src/templates/chat/app/i18n/en-US.ts +3 -3
  564. package/src/templates/chat/app/lib/agent-page.spec.tsx +10 -1
  565. package/src/templates/chat/app/lib/agent-page.tsx +10 -1
  566. package/src/templates/default/app/i18n/en-US.ts +3 -3
  567. package/src/templates/workspace-core/.agents/skills/extensions/SKILL.md +14 -5
  568. package/src/templates/workspace-root/.env.example +12 -0
@@ -1,1859 +1 @@
1
- /**
2
- * Figma node JSON -> HTML mapper.
3
- *
4
- * Input is the `document` subtree returned by
5
- * `GET /v1/files/:fileKey/nodes?ids=...&geometry=paths` (or the file's root
6
- * `document` node). Output is a self-contained HTML fragment using absolute
7
- * positioning + inline styles, matching Figma's own canvas model 1:1 rather
8
- * than reconstructing a semantic/Tailwind layout — the goal is pixel fidelity
9
- * for an imported snapshot, not idiomatic hand-authored markup.
10
- *
11
- * This module is pure and synchronous: it never calls the network. The
12
- * caller (an action) is responsible for:
13
- * 1. Fetching the node JSON from the Figma REST API.
14
- * 2. Calling `collectFallbackNodeIds` / `collectImageFillRefs` to find out
15
- * which nodes need a rendered PNG fallback and which image fills need
16
- * resolved URLs.
17
- * 3. Fetching those via `/v1/images/:fileKey` (fallback renders) and
18
- * `/v1/files/:fileKey/images` (fill ref -> URL map).
19
- * 4. Calling `mapFigmaNodeToHtml` with the resulting maps.
20
- *
21
- * ## Pixel-perfect property coverage
22
- *
23
- * | Property | Fidelity | Notes |
24
- * | ------------------------------------------- | ------------- | ----- |
25
- * | Position/size (absoluteBoundingBox) | exact | frame-relative |
26
- * | Auto-layout (flex*) | exact | Figma auto-layout IS flexbox |
27
- * | Text font/size/weight/case/decoration/align | exact | |
28
- * | Line-height (px vs percent-of-font-size) | exact | resolved to px |
29
- * | Letter-spacing | exact | already px in REST API |
30
- * | Solid fills | exact | |
31
- * | Gradient fills (angle/position) | exact (linear)/approximated (radial/angular/diamond) | derived from gradientHandlePositions, not a default angle |
32
- * | Multiple fills (layering) | exact | reversed to match CSS background-image stacking |
33
- * | Image fills (scale modes) | exact (FILL/FIT/TILE/STRETCH-axis-aligned) / approximated (skewed imageTransform) | |
34
- * | Strokes (uniform, align) | exact | CENTER via outline+negative offset, INSIDE via inset box-shadow, OUTSIDE via outline |
35
- * | Strokes (per-side weights) | approximated | CSS has no per-side outline; falls back to per-side `border` (inside-only) |
36
- * | Corner radii (uniform + per-corner) | exact | |
37
- * | Effects: drop/inner shadow | exact | |
38
- * | Effects: layer/background blur | approximated | Figma <-> CSS blur radius scale is not publicly specified as 1:1 |
39
- * | Opacity | exact | |
40
- * | Blend modes (CSS-supported) | exact | |
41
- * | Blend modes (Figma-only: LINEAR_BURN/DODGE/LIGHTER/DARKER) | approximated | mapped to closest CSS equivalent |
42
- * | clipsContent | exact | overflow: hidden |
43
- * | Rotation | approximated | pivots about the bounding-box center (see below) |
44
- * | Vector networks / boolean ops / unsupported types | image fallback | never approximated structurally |
45
- *
46
- * ### Rotation caveat
47
- * The REST API docs describe `rotation` as being in degrees, but the field
48
- * is empirically returned in RADIANS (verified against known authored
49
- * rotations via the Plugin API); this mapper converts it to degrees before
50
- * use. `absoluteBoundingBox` is the *already-rotated* axis-aligned bounding
51
- * box —
52
- * Figma does not expose the pre-rotation box directly. We reconstruct the
53
- * unrotated box by treating the AABB's center as invariant under rotation
54
- * (true for a shape rotated about its own center) and rotate the CSS element
55
- * about `transform-origin: center` by `-rotation` degrees (Figma's rotation
56
- * is clockwise-negative relative to CSS's clockwise-positive convention).
57
- * This is exact when Figma pivots rotation about the shape's center and only
58
- * approximated if Figma's internal pivot differs (rare in practice; visually
59
- * indistinguishable in the overwhelming majority of designs). A fully exact
60
- * alternative would consume `relativeTransform` as a CSS `matrix()` directly,
61
- * which is a documented follow-up if a specific design surfaces a visible
62
- * mismatch.
63
- */
64
-
65
- export interface FigmaColor {
66
- r: number;
67
- g: number;
68
- b: number;
69
- a?: number;
70
- }
71
-
72
- export interface FigmaColorStop {
73
- position: number;
74
- color: FigmaColor;
75
- }
76
-
77
- export interface FigmaImageFilter {
78
- exposure?: number;
79
- contrast?: number;
80
- saturation?: number;
81
- temperature?: number;
82
- tint?: number;
83
- highlights?: number;
84
- shadows?: number;
85
- }
86
-
87
- export interface FigmaPaint {
88
- type:
89
- | "SOLID"
90
- | "GRADIENT_LINEAR"
91
- | "GRADIENT_RADIAL"
92
- | "GRADIENT_ANGULAR"
93
- | "GRADIENT_DIAMOND"
94
- | "IMAGE"
95
- | "EMOJI"
96
- | "VIDEO";
97
- visible?: boolean;
98
- opacity?: number;
99
- color?: FigmaColor;
100
- gradientHandlePositions?: Array<{ x: number; y: number }>;
101
- gradientStops?: FigmaColorStop[];
102
- imageRef?: string;
103
- scaleMode?: "FILL" | "FIT" | "TILE" | "STRETCH";
104
- imageTransform?: [[number, number, number], [number, number, number]];
105
- filters?: FigmaImageFilter;
106
- blendMode?: string;
107
- }
108
-
109
- export interface FigmaEffect {
110
- type: "DROP_SHADOW" | "INNER_SHADOW" | "LAYER_BLUR" | "BACKGROUND_BLUR";
111
- visible?: boolean;
112
- radius?: number;
113
- spread?: number;
114
- color?: FigmaColor;
115
- offset?: { x: number; y: number };
116
- blendMode?: string;
117
- }
118
-
119
- export interface FigmaTypeStyle {
120
- fontFamily?: string;
121
- fontPostScriptName?: string;
122
- fontWeight?: number;
123
- fontSize?: number;
124
- italic?: boolean;
125
- letterSpacing?: number;
126
- lineHeightPx?: number;
127
- lineHeightPercent?: number;
128
- lineHeightPercentFontSize?: number;
129
- lineHeightUnit?: "PIXELS" | "FONT_SIZE_%" | "INTRINSIC_%";
130
- textCase?: "ORIGINAL" | "UPPER" | "LOWER" | "TITLE";
131
- textDecoration?: "NONE" | "UNDERLINE" | "STRIKETHROUGH";
132
- textAlignHorizontal?: "LEFT" | "RIGHT" | "CENTER" | "JUSTIFIED";
133
- textAlignVertical?: "TOP" | "CENTER" | "BOTTOM";
134
- textAutoResize?: "NONE" | "WIDTH_AND_HEIGHT" | "HEIGHT" | "TRUNCATE";
135
- paragraphSpacing?: number;
136
- paragraphIndent?: number;
137
- listSpacing?: number;
138
- hangingPunctuation?: boolean;
139
- hangingList?: boolean;
140
- opentypeFlags?: Record<string, number>;
141
- hyperlink?: unknown;
142
- fills?: FigmaPaint[];
143
- }
144
-
145
- export interface FigmaIndividualStrokeWeights {
146
- top?: number;
147
- right?: number;
148
- bottom?: number;
149
- left?: number;
150
- }
151
-
152
- export interface FigmaBoundingBox {
153
- x: number;
154
- y: number;
155
- width: number;
156
- height: number;
157
- }
158
-
159
- export interface FigmaNode {
160
- id: string;
161
- name?: string;
162
- type: string;
163
- visible?: boolean;
164
- opacity?: number;
165
- blendMode?: string;
166
- rotation?: number;
167
- absoluteBoundingBox?: FigmaBoundingBox;
168
- /**
169
- * The node's actual visual extent, INCLUDING stroke/effect overflow --
170
- * e.g. an OUTSIDE-aligned stroke or a drop shadow makes this larger than
171
- * `absoluteBoundingBox` (the purely geometric fill bounds). Figma's own
172
- * `/v1/images` renders for a node are cropped to this box, not to
173
- * `absoluteBoundingBox` -- sizing an image-fallback `<img>` using the
174
- * geometric box instead squishes/crops the rendered PNG to the wrong
175
- * aspect ratio whenever a fallback node has stroke/effect overflow.
176
- */
177
- absoluteRenderBounds?: FigmaBoundingBox;
178
- size?: { x: number; y: number };
179
- clipsContent?: boolean;
180
- isMask?: boolean;
181
- maskType?: "ALPHA" | "VECTOR" | "LUMINANCE";
182
- arcData?: {
183
- startingAngle?: number;
184
- endingAngle?: number;
185
- innerRadius?: number;
186
- };
187
- characters?: string;
188
- style?: FigmaTypeStyle;
189
- characterStyleOverrides?: number[];
190
- styleOverrideTable?: Record<string, FigmaTypeStyle>;
191
- lineTypes?: string[];
192
- lineIndentations?: number[];
193
- fills?: FigmaPaint[];
194
- strokes?: FigmaPaint[];
195
- strokeWeight?: number;
196
- strokeAlign?: "INSIDE" | "OUTSIDE" | "CENTER";
197
- individualStrokeWeights?: FigmaIndividualStrokeWeights;
198
- strokeDashes?: number[];
199
- cornerRadius?: number;
200
- rectangleCornerRadii?: [number, number, number, number];
201
- effects?: FigmaEffect[];
202
- layoutMode?: "NONE" | "HORIZONTAL" | "VERTICAL" | "GRID";
203
- layoutPositioning?: "AUTO" | "ABSOLUTE";
204
- primaryAxisAlignItems?: "MIN" | "CENTER" | "MAX" | "SPACE_BETWEEN";
205
- counterAxisAlignItems?: "MIN" | "CENTER" | "MAX" | "BASELINE";
206
- layoutSizingHorizontal?: "FIXED" | "HUG" | "FILL";
207
- layoutSizingVertical?: "FIXED" | "HUG" | "FILL";
208
- layoutWrap?: "NO_WRAP" | "WRAP";
209
- itemSpacing?: number;
210
- counterAxisSpacing?: number;
211
- paddingLeft?: number;
212
- paddingRight?: number;
213
- paddingTop?: number;
214
- paddingBottom?: number;
215
- minWidth?: number | null;
216
- maxWidth?: number | null;
217
- minHeight?: number | null;
218
- maxHeight?: number | null;
219
- componentId?: string;
220
- componentProperties?: Record<string, unknown>;
221
- boundVariables?: Record<string, unknown>;
222
- interactions?: unknown[];
223
- children?: FigmaNode[];
224
- }
225
-
226
- export type FidelityLevel = "exact" | "approximated" | "image-fallback";
227
-
228
- export interface FidelityEntry {
229
- nodeId: string;
230
- nodeName: string;
231
- nodeType: string;
232
- level: FidelityLevel;
233
- notes: string[];
234
- }
235
-
236
- export interface FidelityReport {
237
- entries: FidelityEntry[];
238
- summary: {
239
- exact: number;
240
- approximated: number;
241
- imageFallback: number;
242
- };
243
- }
244
-
245
- export interface MapFigmaNodeOptions {
246
- /** imageRef hash -> resolved public URL, from `/v1/files/:key/images`. */
247
- imageFillUrls?: Record<string, string>;
248
- /** nodeId -> rendered PNG URL, from `/v1/images/:key` for fallback subtrees. */
249
- fallbackImageUrls?: Record<string, string>;
250
- /** Node ids that should be rendered as an image regardless of type. */
251
- forceImageFallbackNodeIds?: Set<string>;
252
- }
253
-
254
- export interface MapFigmaNodeResult {
255
- html: string;
256
- fidelity: FidelityReport;
257
- }
258
-
259
- const UNSUPPORTED_STRUCTURAL_TYPES = new Set([
260
- "BOOLEAN_OPERATION",
261
- "VECTOR",
262
- "STAR",
263
- "REGULAR_POLYGON",
264
- "SLICE",
265
- "STICKY",
266
- "SHAPE_WITH_TEXT",
267
- "CONNECTOR",
268
- "WASHI_TAPE",
269
- "TABLE",
270
- ]);
271
-
272
- const SUPPORTED_CONTAINER_TYPES = new Set([
273
- "FRAME",
274
- "GROUP",
275
- "COMPONENT",
276
- "COMPONENT_SET",
277
- "INSTANCE",
278
- "SECTION",
279
- ]);
280
-
281
- const MAX_FIGMA_NODE_COUNT = 75_000;
282
- const MAX_FIGMA_NODE_DEPTH = 256;
283
- const MAX_METADATA_ATTRIBUTE_CHARS = 16_384;
284
-
285
- // ---------------------------------------------------------------------------
286
- // Formatting helpers
287
- // ---------------------------------------------------------------------------
288
-
289
- function round(value: number, precision = 2): number {
290
- const factor = 10 ** precision;
291
- return Math.round(value * factor) / factor;
292
- }
293
-
294
- function px(value: number | undefined, precision = 2): string | undefined {
295
- if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
296
- return `${round(value, precision)}px`;
297
- }
298
-
299
- function colorToCss(
300
- color: FigmaColor | undefined,
301
- opacityMul = 1,
302
- ): string | null {
303
- if (!color) return null;
304
- const r = Math.round((color.r ?? 0) * 255);
305
- const g = Math.round((color.g ?? 0) * 255);
306
- const b = Math.round((color.b ?? 0) * 255);
307
- const a = round((color.a ?? 1) * opacityMul, 4);
308
- return `rgba(${r}, ${g}, ${b}, ${a})`;
309
- }
310
-
311
- function escapeHtml(value: string): string {
312
- return value
313
- .replace(/&/g, "&amp;")
314
- .replace(/</g, "&lt;")
315
- .replace(/>/g, "&gt;")
316
- .replace(/"/g, "&quot;");
317
- }
318
-
319
- function escapeAttr(value: string): string {
320
- return escapeHtml(value);
321
- }
322
-
323
- function metadataAttr(
324
- name: string,
325
- value: unknown,
326
- node: FigmaNode,
327
- tracker: FidelityTracker,
328
- ): string {
329
- if (value === undefined || value === null) return "";
330
- let serialized: string;
331
- try {
332
- serialized = typeof value === "string" ? value : JSON.stringify(value);
333
- } catch {
334
- tracker.record(
335
- node,
336
- "approximated",
337
- `${name} metadata could not be serialized and was omitted.`,
338
- );
339
- return "";
340
- }
341
- if (serialized.length > MAX_METADATA_ATTRIBUTE_CHARS) {
342
- tracker.record(
343
- node,
344
- "approximated",
345
- `${name} metadata exceeded ${MAX_METADATA_ATTRIBUTE_CHARS} characters and was omitted.`,
346
- );
347
- return "";
348
- }
349
- return ` ${name}="${escapeAttr(serialized)}"`;
350
- }
351
-
352
- /**
353
- * Builds the CSS text for a `style="..."` attribute AND escapes it for HTML
354
- * attribute context. This matters because at least one style value we emit
355
- * legitimately contains a literal double-quote character: font-family values
356
- * are built as `"Inter", sans-serif` (CSS requires quoting family names with
357
- * spaces). Without escaping here, that embedded `"` prematurely terminates
358
- * the enclosing `style="..."` attribute the moment a browser (or any other
359
- * HTML parser) reads it -- silently dropping every style declared after
360
- * font-family in object-key order (font-size, font-weight, line-height,
361
- * text-align, and the text node's own `display: flex` used to emulate
362
- * vertical alignment). The visible symptom is text rendering at the
363
- * browser's default font/size instead of the mapped Figma typography, with
364
- * no error anywhere -- caught here via a real headless-browser render that
365
- * showed a Figma TEXT node's own style attribute silently truncated at
366
- * `font-family: "`.
367
- */
368
- function styleAttr(styles: Record<string, string | undefined>): string {
369
- const parts = Object.entries(styles)
370
- .filter((entry): entry is [string, string] => typeof entry[1] === "string")
371
- .map(([key, value]) => `${key}: ${value}`);
372
- return escapeAttr(parts.join("; "));
373
- }
374
-
375
- // ---------------------------------------------------------------------------
376
- // Fidelity report builder
377
- // ---------------------------------------------------------------------------
378
-
379
- class FidelityTracker {
380
- private entries = new Map<string, FidelityEntry>();
381
-
382
- record(node: FigmaNode, level: FidelityLevel, note: string) {
383
- const existing = this.entries.get(node.id);
384
- if (existing) {
385
- // Never downgrade an image-fallback entry, and never upgrade below the
386
- // worst level recorded for this node.
387
- const rank: Record<FidelityLevel, number> = {
388
- exact: 0,
389
- approximated: 1,
390
- "image-fallback": 2,
391
- };
392
- if (rank[level] > rank[existing.level]) existing.level = level;
393
- existing.notes.push(note);
394
- return;
395
- }
396
- this.entries.set(node.id, {
397
- nodeId: node.id,
398
- nodeName: node.name ?? node.id,
399
- nodeType: node.type,
400
- level,
401
- notes: [note],
402
- });
403
- }
404
-
405
- build(): FidelityReport {
406
- const entries = [...this.entries.values()];
407
- const summary = entries.reduce(
408
- (acc, entry) => {
409
- if (entry.level === "exact") acc.exact += 1;
410
- else if (entry.level === "approximated") acc.approximated += 1;
411
- else acc.imageFallback += 1;
412
- return acc;
413
- },
414
- { exact: 0, approximated: 0, imageFallback: 0 },
415
- );
416
- return { entries, summary };
417
- }
418
- }
419
-
420
- // ---------------------------------------------------------------------------
421
- // Gradient angle / position derivation
422
- // ---------------------------------------------------------------------------
423
-
424
- interface GradientGeometry {
425
- start: { x: number; y: number };
426
- end: { x: number; y: number };
427
- width: { x: number; y: number };
428
- }
429
-
430
- function resolveGradientGeometry(paint: FigmaPaint): GradientGeometry | null {
431
- const handles = paint.gradientHandlePositions;
432
- if (!handles || handles.length < 3) return null;
433
- return { start: handles[0]!, end: handles[1]!, width: handles[2]! };
434
- }
435
-
436
- /**
437
- * Derive a CSS `linear-gradient()` angle (degrees) from Figma's normalized
438
- * `gradientHandlePositions`. Handle positions are normalized independently in
439
- * x and y (0..1 relative to the node's bounding box), so the angle must be
440
- * computed in actual pixel space using the node's real width/height —
441
- * otherwise a non-square box silently distorts the angle.
442
- *
443
- * Verified against Figma's documented identity handles
444
- * (start=(0,0.5), end=(1,0.5), width=(1,0), i.e. a plain left-to-right
445
- * gradient) which must resolve to CSS `90deg` ("to right"):
446
- * dx = 1*w, dy = 0 -> atan2(0, dx) = 0deg -> +90 = 90deg. Matches.
447
- * And a top-to-bottom gradient (start=(0.5,0), end=(0.5,1)) must resolve to
448
- * CSS `180deg` ("to bottom"):
449
- * dx = 0, dy = 1*h -> atan2(dy, 0) = 90deg -> +90 = 180deg. Matches.
450
- */
451
- export function gradientAngleDegrees(
452
- paint: FigmaPaint,
453
- box: { width: number; height: number },
454
- ): number | null {
455
- const geometry = resolveGradientGeometry(paint);
456
- if (!geometry) return null;
457
- const dx = (geometry.end.x - geometry.start.x) * box.width;
458
- const dy = (geometry.end.y - geometry.start.y) * box.height;
459
- const angleRad = Math.atan2(dy, dx);
460
- const angleDeg = (angleRad * 180) / Math.PI + 90;
461
- return ((angleDeg % 360) + 360) % 360;
462
- }
463
-
464
- function gradientStopsCss(
465
- paint: FigmaPaint,
466
- remapPosition?: (position: number) => number,
467
- ): string {
468
- const stops = paint.gradientStops ?? [];
469
- return stops
470
- .map((stop) => {
471
- const color = colorToCss(stop.color, paint.opacity ?? 1) ?? "transparent";
472
- const position = remapPosition
473
- ? remapPosition(stop.position)
474
- : stop.position;
475
- return `${color} ${round(position * 100, 2)}%`;
476
- })
477
- .join(", ");
478
- }
479
-
480
- /**
481
- * CSS `linear-gradient(angle, ...)` always stretches its 0%/100% stops
482
- * across the box's FULL diagonal extent at that angle (the CSS spec's
483
- * "gradient line" always spans corner-to-corner) -- it has no way to say
484
- * "start partway in, end partway in" the way Figma's actual gradient handles
485
- * can (a designer can drag the start/end handles anywhere, including short
486
- * of the shape's edges, or past them). Figma's own stop positions are
487
- * fractions of the literal start-handle-to-end-handle distance, which only
488
- * happens to coincide with the CSS full-box span when the handles are
489
- * dragged exactly corner-to-corner -- a common case, but far from the only
490
- * one, and the divergence gets worse the more the box's aspect ratio departs
491
- * from square (rotated/skewed handles included, e.g. gradientTransform-authored
492
- * paints). This projects each Figma stop's real pixel position onto the same
493
- * angle CSS will use and re-expresses it as a percentage of the CSS line's
494
- * length, so a partial/offset gradient renders at the same actual pixel
495
- * positions Figma draws it at instead of silently stretching to fill the box.
496
- */
497
- function remapLinearStopPosition(
498
- geometry: GradientGeometry,
499
- box: { width: number; height: number },
500
- angleDeg: number,
501
- ): (position: number) => number {
502
- const angleRad = (angleDeg * Math.PI) / 180;
503
- const ux = Math.sin(angleRad);
504
- const uy = -Math.cos(angleRad);
505
- const lineLength = box.width * Math.abs(ux) + box.height * Math.abs(uy);
506
- if (lineLength < 1e-6) return (position) => position;
507
- const startPx = {
508
- x: geometry.start.x * box.width,
509
- y: geometry.start.y * box.height,
510
- };
511
- const endPx = {
512
- x: geometry.end.x * box.width,
513
- y: geometry.end.y * box.height,
514
- };
515
- const centerX = box.width / 2;
516
- const centerY = box.height / 2;
517
- return (position: number) => {
518
- const pointX = startPx.x + position * (endPx.x - startPx.x);
519
- const pointY = startPx.y + position * (endPx.y - startPx.y);
520
- const projected = (pointX - centerX) * ux + (pointY - centerY) * uy;
521
- return (projected + lineLength / 2) / lineLength;
522
- };
523
- }
524
-
525
- function vectorLength(
526
- from: { x: number; y: number },
527
- to: { x: number; y: number },
528
- box: { width: number; height: number },
529
- ): number {
530
- const dx = (to.x - from.x) * box.width;
531
- const dy = (to.y - from.y) * box.height;
532
- return Math.sqrt(dx * dx + dy * dy);
533
- }
534
-
535
- /**
536
- * Convert one Figma paint layer to a CSS `background-image` value (or plain
537
- * color for a SOLID paint used standalone). Returns null for paints that
538
- * cannot be expressed as a background-image (handled elsewhere).
539
- */
540
- function paintToCssImage(
541
- paint: FigmaPaint,
542
- box: { width: number; height: number },
543
- tracker: FidelityTracker,
544
- node: FigmaNode,
545
- ): string | null {
546
- if (paint.visible === false) return null;
547
- const stops = gradientStopsCss(paint);
548
- if (!stops) return null;
549
-
550
- switch (paint.type) {
551
- case "GRADIENT_LINEAR": {
552
- const angle = gradientAngleDegrees(paint, box);
553
- const geometry = resolveGradientGeometry(paint);
554
- // Re-express Figma's handle-relative stop positions as percentages of
555
- // CSS's own full-box gradient line (see remapLinearStopPosition) so a
556
- // gradient whose handles don't span exactly corner-to-corner still
557
- // lands its color transitions at the same real pixel positions Figma
558
- // draws them at, instead of being stretched to fill the whole box.
559
- const linearStops =
560
- angle !== null && geometry
561
- ? gradientStopsCss(
562
- paint,
563
- remapLinearStopPosition(geometry, box, angle),
564
- )
565
- : stops;
566
- tracker.record(
567
- node,
568
- "exact",
569
- "Linear gradient angle and stop offsets derived from gradientHandlePositions.",
570
- );
571
- return `linear-gradient(${round(angle ?? 90, 2)}deg, ${linearStops})`;
572
- }
573
- case "GRADIENT_RADIAL": {
574
- const geometry = resolveGradientGeometry(paint);
575
- if (!geometry) return `radial-gradient(${stops})`;
576
- const cx = round(geometry.start.x * 100, 2);
577
- const cy = round(geometry.start.y * 100, 2);
578
- // Figma's handle[1] ("end") is the radius vector along the gradient's
579
- // own primary axis; handle[2] ("width") is the perpendicular radius.
580
- // For an axis-aligned box those map directly to the ellipse's
581
- // horizontal/vertical radii -- swapping them (as a prior version of
582
- // this code did) silently rotates the ellipse 90 degrees, which is
583
- // invisible for a square box but produces a badly wrong bowtie-shaped
584
- // gradient for any non-square rectangle (the common case).
585
- const radiusX = vectorLength(geometry.start, geometry.end, box);
586
- const radiusY = vectorLength(geometry.start, geometry.width, box);
587
- tracker.record(
588
- node,
589
- "approximated",
590
- "Radial gradient rendered as an axis-aligned ellipse sized from gradientHandlePositions; rotated/skewed radial gradients are not expressible in CSS radial-gradient().",
591
- );
592
- return `radial-gradient(ellipse ${round(radiusX, 2)}px ${round(radiusY, 2)}px at ${cx}% ${cy}%, ${stops})`;
593
- }
594
- case "GRADIENT_ANGULAR": {
595
- const geometry = resolveGradientGeometry(paint);
596
- const cx = geometry ? round(geometry.start.x * 100, 2) : 50;
597
- const cy = geometry ? round(geometry.start.y * 100, 2) : 50;
598
- const fromAngle = geometry ? gradientAngleDegrees(paint, box) : 0;
599
- tracker.record(
600
- node,
601
- "approximated",
602
- "Conic (angular) gradient start angle derived from gradientHandlePositions using the same angle formula as linear gradients; CSS conic-gradient() has no elliptical distortion so non-uniform boxes may render slightly differently than Figma.",
603
- );
604
- return `conic-gradient(from ${round(fromAngle ?? 0, 2)}deg at ${cx}% ${cy}%, ${stops})`;
605
- }
606
- case "GRADIENT_DIAMOND": {
607
- const geometry = resolveGradientGeometry(paint);
608
- const cx = geometry ? round(geometry.start.x * 100, 2) : 50;
609
- const cy = geometry ? round(geometry.start.y * 100, 2) : 50;
610
- // Same handle-to-axis mapping fix as GRADIENT_RADIAL above: handle[1]
611
- // ("end") is the primary-axis radius, handle[2] ("width") the
612
- // perpendicular one.
613
- const radiusX = geometry
614
- ? vectorLength(geometry.start, geometry.end, box)
615
- : box.width / 2;
616
- const radiusY = geometry
617
- ? vectorLength(geometry.start, geometry.width, box)
618
- : box.height / 2;
619
- tracker.record(
620
- node,
621
- "approximated",
622
- "Diamond gradient has no CSS equivalent; approximated as an axis-aligned elliptical radial-gradient sized from gradientHandlePositions. True diamond (rotated-square) falloff is not reproduced.",
623
- );
624
- return `radial-gradient(ellipse ${round(radiusX, 2)}px ${round(radiusY, 2)}px at ${cx}% ${cy}%, ${stops})`;
625
- }
626
- default:
627
- return null;
628
- }
629
- }
630
-
631
- // ---------------------------------------------------------------------------
632
- // Fills -> background
633
- // ---------------------------------------------------------------------------
634
-
635
- interface BackgroundResult {
636
- backgroundColor?: string;
637
- backgroundImage?: string;
638
- backgroundSize?: string;
639
- backgroundPosition?: string;
640
- backgroundRepeat?: string;
641
- color?: string; // for TEXT nodes, fill paints color the glyphs, not a background
642
- }
643
-
644
- function imageScaleModeCss(
645
- paint: FigmaPaint,
646
- node: FigmaNode,
647
- tracker: FidelityTracker,
648
- ): { size: string; position: string; repeat: string } {
649
- const transform = paint.imageTransform;
650
- const isAxisAligned =
651
- !transform ||
652
- (Math.abs(transform[0][1]) < 1e-6 && Math.abs(transform[1][0]) < 1e-6);
653
- if (!isAxisAligned) {
654
- tracker.record(
655
- node,
656
- "approximated",
657
- "Image fill has a non-axis-aligned imageTransform (rotated/skewed crop); approximated using the scale-mode-only CSS mapping without the transform matrix.",
658
- );
659
- }
660
- switch (paint.scaleMode) {
661
- case "FILL":
662
- return { size: "cover", position: "center", repeat: "no-repeat" };
663
- case "FIT":
664
- return { size: "contain", position: "center", repeat: "no-repeat" };
665
- case "TILE":
666
- return { size: "auto", position: "top left", repeat: "repeat" };
667
- case "STRETCH":
668
- return { size: "100% 100%", position: "center", repeat: "no-repeat" };
669
- default:
670
- return { size: "cover", position: "center", repeat: "no-repeat" };
671
- }
672
- }
673
-
674
- /**
675
- * Build the background-* properties for a node's fill stack. Figma paints
676
- * fills bottom-to-top (index 0 is the bottommost layer); CSS
677
- * `background-image` layers top-to-bottom (first value on top), so the
678
- * stack is reversed here to preserve visual order. A solid fill above other
679
- * layers is expressed as a flat `linear-gradient(color, color)` since CSS
680
- * `background-color` always paints *beneath every* background-image and
681
- * cannot be interleaved mid-stack.
682
- */
683
- function buildFills(
684
- node: FigmaNode,
685
- fills: FigmaPaint[] | undefined,
686
- box: { width: number; height: number },
687
- options: MapFigmaNodeOptions,
688
- tracker: FidelityTracker,
689
- isTextNode: boolean,
690
- ): BackgroundResult {
691
- const visible = (fills ?? []).filter((fill) => fill.visible !== false);
692
- if (visible.length === 0) return {};
693
-
694
- if (isTextNode) {
695
- // Text color comes from the topmost visible SOLID fill; gradient/image
696
- // text fills are a CSS `background-clip: text` trick we intentionally
697
- // skip for now (rare in practice) and record as approximated.
698
- const solid = [...visible].reverse().find((fill) => fill.type === "SOLID");
699
- if (solid) {
700
- return {
701
- color: colorToCss(solid.color, solid.opacity ?? 1) ?? undefined,
702
- };
703
- }
704
- tracker.record(
705
- node,
706
- "approximated",
707
- "Text fill is a gradient/image, not a solid color; rendered with the default text color instead of a background-clip: text gradient.",
708
- );
709
- return {};
710
- }
711
-
712
- const images: string[] = [];
713
- const sizes: string[] = [];
714
- const positions: string[] = [];
715
- const repeats: string[] = [];
716
- let backgroundColor: string | undefined;
717
-
718
- // Reverse so the topmost Figma fill becomes the first (topmost) CSS layer.
719
- const ordered = [...visible].reverse();
720
- for (let index = 0; index < ordered.length; index += 1) {
721
- const fill = ordered[index]!;
722
- const isBottommost = index === ordered.length - 1;
723
-
724
- if (fill.type === "SOLID") {
725
- const color = colorToCss(fill.color, fill.opacity ?? 1);
726
- if (!color) continue;
727
- if (isBottommost) {
728
- // A bottom-most solid always paints beneath every background-image
729
- // layer, so it can always become plain backgroundColor regardless of
730
- // how many gradient/image layers are stacked above it.
731
- backgroundColor = color;
732
- } else {
733
- // Solid above other layers: express as a flat gradient so it stacks
734
- // in the correct z-order alongside gradient/image layers.
735
- images.push(`linear-gradient(${color}, ${color})`);
736
- sizes.push("100% 100%");
737
- positions.push("center");
738
- repeats.push("no-repeat");
739
- }
740
- continue;
741
- }
742
-
743
- if (fill.type === "IMAGE") {
744
- const url = fill.imageRef
745
- ? options.imageFillUrls?.[fill.imageRef]
746
- : undefined;
747
- if (!url) {
748
- tracker.record(
749
- node,
750
- "approximated",
751
- `Image fill imageRef "${fill.imageRef ?? "unknown"}" had no resolved URL; layer omitted.`,
752
- );
753
- continue;
754
- }
755
- const mode = imageScaleModeCss(fill, node, tracker);
756
- images.push(`url("${url}")`);
757
- sizes.push(mode.size);
758
- positions.push(mode.position);
759
- repeats.push(mode.repeat);
760
- continue;
761
- }
762
-
763
- const cssImage = paintToCssImage(fill, box, tracker, node);
764
- if (cssImage) {
765
- images.push(cssImage);
766
- sizes.push("100% 100%");
767
- positions.push("center");
768
- repeats.push("no-repeat");
769
- }
770
- }
771
-
772
- const result: BackgroundResult = {};
773
- if (backgroundColor) result.backgroundColor = backgroundColor;
774
- if (images.length > 0) {
775
- result.backgroundImage = images.join(", ");
776
- result.backgroundSize = sizes.join(", ");
777
- result.backgroundPosition = positions.join(", ");
778
- result.backgroundRepeat = repeats.join(", ");
779
- }
780
- return result;
781
- }
782
-
783
- // ---------------------------------------------------------------------------
784
- // Strokes -> border / outline / box-shadow
785
- // ---------------------------------------------------------------------------
786
-
787
- interface StrokeResult {
788
- styles: Record<string, string | undefined>;
789
- insetShadow?: string;
790
- }
791
-
792
- function buildStrokes(node: FigmaNode, tracker: FidelityTracker): StrokeResult {
793
- const strokes = (node.strokes ?? []).filter(
794
- (stroke) => stroke.visible !== false,
795
- );
796
- if (strokes.length === 0) return { styles: {} };
797
-
798
- const first = strokes[0]!;
799
- const color =
800
- colorToCss(first.color, first.opacity ?? 1) ?? "rgba(0, 0, 0, 1)";
801
- const iw = node.individualStrokeWeights;
802
- const hasPerSide =
803
- iw &&
804
- (iw.top !== undefined ||
805
- iw.right !== undefined ||
806
- iw.bottom !== undefined ||
807
- iw.left !== undefined);
808
- const uniformWeight = node.strokeWeight ?? 0;
809
-
810
- if (hasPerSide) {
811
- // CSS `outline`/inset-`box-shadow` tricks are single-weight only; per-side
812
- // stroke weights can only be expressed as a real per-side `border`, which
813
- // always renders fully inside the border-box regardless of strokeAlign.
814
- // This is exact for INSIDE and an approximation for CENTER/OUTSIDE.
815
- const top = iw?.top ?? uniformWeight;
816
- const right = iw?.right ?? uniformWeight;
817
- const bottom = iw?.bottom ?? uniformWeight;
818
- const left = iw?.left ?? uniformWeight;
819
- tracker.record(
820
- node,
821
- node.strokeAlign === "INSIDE" || !node.strokeAlign
822
- ? "exact"
823
- : "approximated",
824
- `Per-side stroke weights rendered as CSS border (inside-aligned); strokeAlign="${node.strokeAlign ?? "INSIDE"}" cannot vary per-side with outline tricks.`,
825
- );
826
- return {
827
- styles: {
828
- "border-top": top ? `${px(top)} solid ${color}` : undefined,
829
- "border-right": right ? `${px(right)} solid ${color}` : undefined,
830
- "border-bottom": bottom ? `${px(bottom)} solid ${color}` : undefined,
831
- "border-left": left ? `${px(left)} solid ${color}` : undefined,
832
- },
833
- };
834
- }
835
-
836
- if (!uniformWeight) return { styles: {} };
837
-
838
- switch (node.strokeAlign) {
839
- case "OUTSIDE":
840
- tracker.record(
841
- node,
842
- "exact",
843
- "OUTSIDE stroke rendered via outline (offset 0).",
844
- );
845
- return {
846
- styles: {
847
- outline: `${px(uniformWeight)} solid ${color}`,
848
- "outline-offset": "0px",
849
- },
850
- };
851
- case "INSIDE":
852
- tracker.record(
853
- node,
854
- "exact",
855
- "INSIDE stroke rendered via inset box-shadow.",
856
- );
857
- return {
858
- styles: {},
859
- insetShadow: `inset 0 0 0 ${px(uniformWeight)} ${color}`,
860
- };
861
- case "CENTER":
862
- default:
863
- // outline-offset of -half the weight pulls the outline half inside,
864
- // half outside the border-box edge -- reproducing Figma's CENTER
865
- // straddle exactly (plain CSS `border` cannot straddle the edge).
866
- tracker.record(
867
- node,
868
- "exact",
869
- "CENTER stroke rendered via outline with outline-offset = -weight/2 (straddles the edge like Figma).",
870
- );
871
- return {
872
- styles: {
873
- outline: `${px(uniformWeight)} solid ${color}`,
874
- "outline-offset": px(-uniformWeight / 2),
875
- },
876
- };
877
- }
878
- }
879
-
880
- // ---------------------------------------------------------------------------
881
- // Corner radii
882
- // ---------------------------------------------------------------------------
883
-
884
- function buildCornerRadius(node: FigmaNode): string | undefined {
885
- if (node.rectangleCornerRadii) {
886
- const [tl, tr, br, bl] = node.rectangleCornerRadii;
887
- return `${px(tl) ?? "0px"} ${px(tr) ?? "0px"} ${px(br) ?? "0px"} ${px(bl) ?? "0px"}`;
888
- }
889
- if (typeof node.cornerRadius === "number" && node.cornerRadius > 0) {
890
- return px(node.cornerRadius);
891
- }
892
- return undefined;
893
- }
894
-
895
- // ---------------------------------------------------------------------------
896
- // Effects -> box-shadow / filter / backdrop-filter
897
- // ---------------------------------------------------------------------------
898
-
899
- interface EffectResult {
900
- boxShadowLayers: string[];
901
- filter?: string;
902
- backdropFilter?: string;
903
- }
904
-
905
- function buildEffects(
906
- node: FigmaNode,
907
- isTextNode: boolean,
908
- tracker: FidelityTracker,
909
- ): EffectResult {
910
- const effects = (node.effects ?? []).filter(
911
- (effect) => effect.visible !== false,
912
- );
913
- const boxShadowLayers: string[] = [];
914
- let filter: string | undefined;
915
- let backdropFilter: string | undefined;
916
-
917
- for (const effect of effects) {
918
- if (effect.type === "DROP_SHADOW" || effect.type === "INNER_SHADOW") {
919
- const color = colorToCss(effect.color, 1) ?? "rgba(0, 0, 0, 1)";
920
- const x = px(effect.offset?.x ?? 0) ?? "0px";
921
- const y = px(effect.offset?.y ?? 0) ?? "0px";
922
- const blur = px(effect.radius ?? 0) ?? "0px";
923
- const spread =
924
- !isTextNode && typeof effect.spread === "number"
925
- ? ` ${px(effect.spread)}`
926
- : "";
927
- const inset = effect.type === "INNER_SHADOW" ? "inset " : "";
928
- boxShadowLayers.push(`${inset}${x} ${y} ${blur}${spread} ${color}`);
929
- tracker.record(
930
- node,
931
- "exact",
932
- `${effect.type} rendered as ${isTextNode ? "text-shadow" : "box-shadow"}.`,
933
- );
934
- } else if (effect.type === "LAYER_BLUR") {
935
- const radius = px(effect.radius ?? 0) ?? "0px";
936
- filter = filter ? `${filter} blur(${radius})` : `blur(${radius})`;
937
- tracker.record(
938
- node,
939
- "approximated",
940
- "LAYER_BLUR mapped 1:1 to CSS filter: blur(); Figma's blur radius-to-CSS-stdDeviation scale is not publicly documented, so the rendered softness may differ slightly.",
941
- );
942
- } else if (effect.type === "BACKGROUND_BLUR") {
943
- const radius = px(effect.radius ?? 0) ?? "0px";
944
- backdropFilter = backdropFilter
945
- ? `${backdropFilter} blur(${radius})`
946
- : `blur(${radius})`;
947
- tracker.record(
948
- node,
949
- "approximated",
950
- "BACKGROUND_BLUR mapped 1:1 to CSS backdrop-filter: blur(); same radius-scale caveat as LAYER_BLUR.",
951
- );
952
- }
953
- }
954
-
955
- return { boxShadowLayers, filter, backdropFilter };
956
- }
957
-
958
- // ---------------------------------------------------------------------------
959
- // Blend modes
960
- // ---------------------------------------------------------------------------
961
-
962
- const CSS_BLEND_MODES = new Set([
963
- "multiply",
964
- "screen",
965
- "overlay",
966
- "darken",
967
- "lighten",
968
- "color-dodge",
969
- "color-burn",
970
- "hard-light",
971
- "soft-light",
972
- "difference",
973
- "exclusion",
974
- "hue",
975
- "saturation",
976
- "color",
977
- "luminosity",
978
- ]);
979
-
980
- const FIGMA_ONLY_BLEND_MODE_FALLBACK: Record<string, string> = {
981
- LINEAR_BURN: "multiply",
982
- LINEAR_DODGE: "plus-lighter",
983
- LIGHTER: "plus-lighter",
984
- DARKER: "darken",
985
- };
986
-
987
- function buildBlendMode(
988
- node: FigmaNode,
989
- tracker: FidelityTracker,
990
- ): string | undefined {
991
- const mode = node.blendMode;
992
- if (!mode || mode === "PASS_THROUGH" || mode === "NORMAL") return undefined;
993
- const cssMode = mode.toLowerCase().replace(/_/g, "-");
994
- if (CSS_BLEND_MODES.has(cssMode)) return cssMode;
995
- const fallback = FIGMA_ONLY_BLEND_MODE_FALLBACK[mode];
996
- if (fallback) {
997
- tracker.record(
998
- node,
999
- "approximated",
1000
- `Figma blend mode "${mode}" has no CSS equivalent; approximated as mix-blend-mode: ${fallback}.`,
1001
- );
1002
- return fallback;
1003
- }
1004
- return undefined;
1005
- }
1006
-
1007
- // ---------------------------------------------------------------------------
1008
- // Text styling
1009
- // ---------------------------------------------------------------------------
1010
-
1011
- function resolveLineHeight(style: FigmaTypeStyle): string | undefined {
1012
- if (
1013
- typeof style.lineHeightPx === "number" &&
1014
- style.lineHeightUnit !== "FONT_SIZE_%"
1015
- ) {
1016
- return px(style.lineHeightPx);
1017
- }
1018
- if (
1019
- typeof style.lineHeightPercentFontSize === "number" &&
1020
- typeof style.fontSize === "number"
1021
- ) {
1022
- // lineHeightPercentFontSize is literally "percent of the font's nominal
1023
- // size" -- resolve to an exact px value rather than a unitless ratio so
1024
- // the rendered line box matches Figma regardless of font metrics.
1025
- return px(style.fontSize * (style.lineHeightPercentFontSize / 100));
1026
- }
1027
- if (typeof style.lineHeightPx === "number") {
1028
- return px(style.lineHeightPx);
1029
- }
1030
- return undefined;
1031
- }
1032
-
1033
- function textTransformCss(
1034
- textCase: FigmaTypeStyle["textCase"],
1035
- ): string | undefined {
1036
- switch (textCase) {
1037
- case "UPPER":
1038
- return "uppercase";
1039
- case "LOWER":
1040
- return "lowercase";
1041
- case "TITLE":
1042
- return "capitalize";
1043
- default:
1044
- return undefined;
1045
- }
1046
- }
1047
-
1048
- function textDecorationCss(
1049
- decoration: FigmaTypeStyle["textDecoration"],
1050
- ): string | undefined {
1051
- switch (decoration) {
1052
- case "UNDERLINE":
1053
- return "underline";
1054
- case "STRIKETHROUGH":
1055
- return "line-through";
1056
- default:
1057
- return undefined;
1058
- }
1059
- }
1060
-
1061
- function textAlignCss(
1062
- align: FigmaTypeStyle["textAlignHorizontal"],
1063
- ): string | undefined {
1064
- switch (align) {
1065
- case "CENTER":
1066
- return "center";
1067
- case "RIGHT":
1068
- return "right";
1069
- case "JUSTIFIED":
1070
- return "justify";
1071
- case "LEFT":
1072
- return "left";
1073
- default:
1074
- return undefined;
1075
- }
1076
- }
1077
-
1078
- function verticalAlignJustifyContent(
1079
- align: FigmaTypeStyle["textAlignVertical"],
1080
- ): string {
1081
- switch (align) {
1082
- case "CENTER":
1083
- return "center";
1084
- case "BOTTOM":
1085
- return "flex-end";
1086
- default:
1087
- return "flex-start";
1088
- }
1089
- }
1090
-
1091
- // ---------------------------------------------------------------------------
1092
- // Auto-layout
1093
- // ---------------------------------------------------------------------------
1094
-
1095
- function primaryAxisJustify(align: FigmaNode["primaryAxisAlignItems"]): string {
1096
- switch (align) {
1097
- case "CENTER":
1098
- return "center";
1099
- case "MAX":
1100
- return "flex-end";
1101
- case "SPACE_BETWEEN":
1102
- return "space-between";
1103
- default:
1104
- return "flex-start";
1105
- }
1106
- }
1107
-
1108
- function counterAxisAlign(align: FigmaNode["counterAxisAlignItems"]): string {
1109
- switch (align) {
1110
- case "CENTER":
1111
- return "center";
1112
- case "MAX":
1113
- return "flex-end";
1114
- case "BASELINE":
1115
- return "baseline";
1116
- default:
1117
- return "flex-start";
1118
- }
1119
- }
1120
-
1121
- function buildAutoLayoutStyles(
1122
- node: FigmaNode,
1123
- ): Record<string, string | undefined> {
1124
- if (
1125
- !node.layoutMode ||
1126
- node.layoutMode === "NONE" ||
1127
- node.layoutMode === "GRID"
1128
- ) {
1129
- return {};
1130
- }
1131
- const isHorizontal = node.layoutMode === "HORIZONTAL";
1132
- const styles: Record<string, string | undefined> = {
1133
- display: "flex",
1134
- "flex-direction": isHorizontal ? "row" : "column",
1135
- "justify-content": primaryAxisJustify(node.primaryAxisAlignItems),
1136
- "align-items": counterAxisAlign(node.counterAxisAlignItems),
1137
- };
1138
- if (node.layoutWrap === "WRAP") styles["flex-wrap"] = "wrap";
1139
- if (typeof node.itemSpacing === "number" && node.itemSpacing !== 0) {
1140
- styles[isHorizontal ? "column-gap" : "row-gap"] = px(node.itemSpacing);
1141
- }
1142
- if (
1143
- typeof node.counterAxisSpacing === "number" &&
1144
- node.counterAxisSpacing !== 0
1145
- ) {
1146
- styles[isHorizontal ? "row-gap" : "column-gap"] = px(
1147
- node.counterAxisSpacing,
1148
- );
1149
- }
1150
- const padTop = node.paddingTop ?? 0;
1151
- const padRight = node.paddingRight ?? 0;
1152
- const padBottom = node.paddingBottom ?? 0;
1153
- const padLeft = node.paddingLeft ?? 0;
1154
- if (padTop || padRight || padBottom || padLeft) {
1155
- styles.padding = `${px(padTop)} ${px(padRight)} ${px(padBottom)} ${px(padLeft)}`;
1156
- }
1157
- return styles;
1158
- }
1159
-
1160
- /**
1161
- * "FILL" sizing must map to different CSS depending on which axis is the
1162
- * flex *main* axis for this node's parent: main-axis FILL grows via
1163
- * `flex-grow`/`flex-basis` (row parent -> horizontal FILL, column parent ->
1164
- * vertical FILL); cross-axis FILL stretches via `align-self: stretch` (row
1165
- * parent -> vertical FILL, column parent -> horizontal FILL). Passing only a
1166
- * `parentHasAutoLayout` boolean (as this used to) loses the row/column
1167
- * direction and always mapped horizontal-FILL to flex-grow — correct for row
1168
- * parents but wrong for column parents, where a FILL-width text/rect child
1169
- * got `width: auto` with no stretch and overflowed to its content width.
1170
- */
1171
- function buildChildSizingStyles(
1172
- node: FigmaNode,
1173
- parentLayoutMode: "NONE" | "HORIZONTAL" | "VERTICAL",
1174
- ): Record<string, string | undefined> {
1175
- if (parentLayoutMode === "NONE") return {};
1176
- const parentIsHorizontal = parentLayoutMode === "HORIZONTAL";
1177
- const styles: Record<string, string | undefined> = {};
1178
- if (node.layoutSizingHorizontal === "FILL") {
1179
- if (parentIsHorizontal) {
1180
- styles["flex-grow"] = "1";
1181
- styles["flex-basis"] = "0%";
1182
- } else {
1183
- styles["align-self"] = "stretch";
1184
- }
1185
- styles.width = "auto";
1186
- } else if (node.layoutSizingHorizontal === "HUG") {
1187
- styles.width = "auto";
1188
- }
1189
- if (node.layoutSizingVertical === "FILL") {
1190
- if (parentIsHorizontal) {
1191
- styles["align-self"] = "stretch";
1192
- } else {
1193
- styles["flex-grow"] = "1";
1194
- styles["flex-basis"] = "0%";
1195
- }
1196
- styles.height = "auto";
1197
- } else if (node.layoutSizingVertical === "HUG") {
1198
- styles.height = "auto";
1199
- }
1200
- return styles;
1201
- }
1202
-
1203
- // ---------------------------------------------------------------------------
1204
- // Node type classification
1205
- // ---------------------------------------------------------------------------
1206
-
1207
- function needsImageFallback(
1208
- node: FigmaNode,
1209
- options: MapFigmaNodeOptions,
1210
- ): boolean {
1211
- if (options.forceImageFallbackNodeIds?.has(node.id)) return true;
1212
- if (UNSUPPORTED_STRUCTURAL_TYPES.has(node.type)) return true;
1213
- // A Figma mask affects its following siblings, not just the mask node. CSS
1214
- // cannot reproduce that sibling-range operation on an arbitrary DOM tree,
1215
- // so render the smallest containing subtree rather than importing a visibly
1216
- // wrong unmasked composition. A mask imported as the root is also rendered.
1217
- if (node.isMask || node.children?.some((child) => child.isMask)) return true;
1218
- // A CSS div with an outline is not a Figma line. Partial/ring ellipses also
1219
- // need real path geometry, which this structural mapper intentionally does
1220
- // not request because geometry=paths makes ordinary REST payloads enormous.
1221
- if (node.type === "LINE") return true;
1222
- if (node.type === "ELLIPSE" && node.arcData) {
1223
- const start = node.arcData.startingAngle ?? 0;
1224
- const end = node.arcData.endingAngle ?? Math.PI * 2;
1225
- const span = Math.abs(end - start);
1226
- const isFullCircle =
1227
- Math.abs(span - Math.PI * 2) < 1e-4 &&
1228
- Math.abs(node.arcData.innerRadius ?? 0) < 1e-4;
1229
- if (!isFullCircle) return true;
1230
- }
1231
- const visibleStrokes = (node.strokes ?? []).filter(
1232
- (stroke) => stroke.visible !== false,
1233
- );
1234
- if (
1235
- visibleStrokes.length > 1 ||
1236
- visibleStrokes.some((stroke) => stroke.type !== "SOLID") ||
1237
- (node.strokeDashes?.length ?? 0) > 0
1238
- ) {
1239
- return true;
1240
- }
1241
- const visibleFills = (node.fills ?? []).filter(
1242
- (fill) => fill.visible !== false,
1243
- );
1244
- if (
1245
- visibleFills.some(
1246
- (fill) =>
1247
- fill.type === "VIDEO" ||
1248
- fill.type === "EMOJI" ||
1249
- (fill.blendMode &&
1250
- fill.blendMode !== "NORMAL" &&
1251
- fill.blendMode !== "PASS_THROUGH") ||
1252
- (fill.type === "IMAGE" &&
1253
- ((fill.imageTransform &&
1254
- (Math.abs(fill.imageTransform[0][1]) >= 1e-6 ||
1255
- Math.abs(fill.imageTransform[1][0]) >= 1e-6)) ||
1256
- Object.values(fill.filters ?? {}).some(
1257
- (value) => typeof value === "number" && Math.abs(value) > 1e-6,
1258
- ))),
1259
- ) ||
1260
- (node.type === "TEXT" && visibleFills.some((fill) => fill.type !== "SOLID"))
1261
- ) {
1262
- return true;
1263
- }
1264
- if (node.type === "TEXT") {
1265
- const styles = [
1266
- node.style,
1267
- ...Object.values(node.styleOverrideTable ?? {}),
1268
- ].filter((style): style is FigmaTypeStyle => Boolean(style));
1269
- const hasAdvancedTypography = styles.some(
1270
- (style) =>
1271
- Math.abs(style.paragraphSpacing ?? 0) > 1e-6 ||
1272
- Math.abs(style.paragraphIndent ?? 0) > 1e-6 ||
1273
- Math.abs(style.listSpacing ?? 0) > 1e-6 ||
1274
- style.hangingPunctuation === true ||
1275
- style.hangingList === true ||
1276
- style.hyperlink !== undefined ||
1277
- Object.values(style.opentypeFlags ?? {}).some((value) => value !== 0),
1278
- );
1279
- if (
1280
- hasAdvancedTypography ||
1281
- // Figma's REST API always returns one `lineTypes` entry per line —
1282
- // ordinary non-list text comes back as `["NONE", "NONE", ...]`, not an
1283
- // empty array. Checking `.length > 0` alone treats every multi-line
1284
- // text node in existence as an unsupported list and routes it to an
1285
- // image fallback; only a line whose type is actually "ORDERED" or
1286
- // "UNORDERED" means the text uses real list formatting.
1287
- (node.lineTypes?.some((type) => type !== "NONE") ?? false) ||
1288
- (node.lineIndentations?.some((value) => value !== 0) ?? false)
1289
- ) {
1290
- return true;
1291
- }
1292
- }
1293
- if (
1294
- (node.effects ?? []).some(
1295
- (effect) =>
1296
- effect.visible !== false &&
1297
- effect.blendMode &&
1298
- effect.blendMode !== "NORMAL" &&
1299
- effect.blendMode !== "PASS_THROUGH",
1300
- )
1301
- ) {
1302
- return true;
1303
- }
1304
- if (
1305
- !SUPPORTED_CONTAINER_TYPES.has(node.type) &&
1306
- node.type !== "RECTANGLE" &&
1307
- node.type !== "ELLIPSE" &&
1308
- node.type !== "TEXT"
1309
- ) {
1310
- return true;
1311
- }
1312
- return false;
1313
- }
1314
-
1315
- /** Fail clearly before recursive rendering can overflow or lock the worker. */
1316
- export function assertFigmaNodeTreeComplexity(node: FigmaNode): void {
1317
- const stack: Array<{ node: FigmaNode; depth: number }> = [{ node, depth: 1 }];
1318
- const ancestors = new WeakSet<object>();
1319
- let count = 0;
1320
- while (stack.length > 0) {
1321
- const current = stack.pop()!;
1322
- count += 1;
1323
- if (count > MAX_FIGMA_NODE_COUNT) {
1324
- throw new Error(
1325
- `Figma node tree is too large (max ${MAX_FIGMA_NODE_COUNT.toLocaleString("en-US")} nodes). Import a smaller frame or selection.`,
1326
- );
1327
- }
1328
- if (current.depth > MAX_FIGMA_NODE_DEPTH) {
1329
- throw new Error(
1330
- `Figma node tree is nested too deeply (max ${MAX_FIGMA_NODE_DEPTH} levels). Import a smaller frame or selection.`,
1331
- );
1332
- }
1333
- if (ancestors.has(current.node)) {
1334
- throw new Error("Figma node tree contains a cyclic child reference.");
1335
- }
1336
- ancestors.add(current.node);
1337
- for (const child of current.node.children ?? []) {
1338
- stack.push({ node: child, depth: current.depth + 1 });
1339
- }
1340
- }
1341
- }
1342
-
1343
- /**
1344
- * Walk a node tree and return the ids of every subtree that will render as a
1345
- * PNG image fallback (vector networks, boolean ops, and any node type this
1346
- * mapper does not model structurally). Call this before fetching node data
1347
- * so the caller can request rendered images for exactly these ids via
1348
- * `GET /v1/images/:fileKey?ids=...&scale=2`.
1349
- */
1350
- export function collectFallbackNodeIds(
1351
- node: FigmaNode,
1352
- options: MapFigmaNodeOptions = {},
1353
- ): string[] {
1354
- assertFigmaNodeTreeComplexity(node);
1355
- const ids: string[] = [];
1356
- const visit = (current: FigmaNode) => {
1357
- if (current.visible === false || current.opacity === 0) return;
1358
- if (needsImageFallback(current, options)) {
1359
- ids.push(current.id);
1360
- return; // Don't recurse into a subtree that's rendered as one image.
1361
- }
1362
- for (const child of current.children ?? []) visit(child);
1363
- };
1364
- visit(node);
1365
- return ids;
1366
- }
1367
-
1368
- /**
1369
- * Walk a node tree and return every distinct `imageRef` used by IMAGE fills
1370
- * (on fills or strokes) so the caller can resolve them to URLs via
1371
- * `GET /v1/files/:fileKey/images` before mapping.
1372
- */
1373
- export function collectImageFillRefs(
1374
- node: FigmaNode,
1375
- options: MapFigmaNodeOptions = {},
1376
- ): string[] {
1377
- assertFigmaNodeTreeComplexity(node);
1378
- const refs = new Set<string>();
1379
- const visitPaints = (paints: FigmaPaint[] | undefined) => {
1380
- for (const paint of paints ?? []) {
1381
- if (paint.type === "IMAGE" && paint.imageRef) refs.add(paint.imageRef);
1382
- }
1383
- };
1384
- const visit = (current: FigmaNode) => {
1385
- if (current.visible === false || current.opacity === 0) return;
1386
- if (needsImageFallback(current, options)) return;
1387
- visitPaints(current.fills);
1388
- visitPaints(current.strokes);
1389
- for (const child of current.children ?? []) visit(child);
1390
- };
1391
- visit(node);
1392
- return [...refs];
1393
- }
1394
-
1395
- export interface FigmaFontUsage {
1396
- family: string;
1397
- weight: number;
1398
- italic: boolean;
1399
- }
1400
-
1401
- function recordFontUsage(
1402
- style: FigmaTypeStyle | undefined,
1403
- usage: Map<string, FigmaFontUsage>,
1404
- ): void {
1405
- if (!style?.fontFamily) return;
1406
- const weight = typeof style.fontWeight === "number" ? style.fontWeight : 400;
1407
- const italic = Boolean(style.italic);
1408
- const key = `${style.fontFamily}|${weight}|${italic ? 1 : 0}`;
1409
- if (!usage.has(key))
1410
- usage.set(key, { family: style.fontFamily, weight, italic });
1411
- }
1412
-
1413
- /**
1414
- * Walk a node tree and return every distinct (font family, weight, italic)
1415
- * combination used by TEXT nodes -- including per-run character style
1416
- * overrides -- so the caller can request the actual web font (e.g. from
1417
- * Google Fonts) before the imported HTML is saved. Without this, an imported
1418
- * screen's CSS correctly names the intended font-family, but the browser has
1419
- * no way to load it and silently falls back to a generic sans-serif with
1420
- * different glyph advance widths -- individually invisible per character but
1421
- * compounding into a growing horizontal drift across any wrapped or
1422
- * multi-word line, worst on text-dense imports.
1423
- */
1424
- export function collectFontUsage(node: FigmaNode): FigmaFontUsage[] {
1425
- assertFigmaNodeTreeComplexity(node);
1426
- const usage = new Map<string, FigmaFontUsage>();
1427
- const visit = (current: FigmaNode) => {
1428
- if (current.visible === false || current.opacity === 0) return;
1429
- if (current.type === "TEXT") {
1430
- recordFontUsage(current.style, usage);
1431
- for (const style of Object.values(current.styleOverrideTable ?? {})) {
1432
- recordFontUsage(style, usage);
1433
- }
1434
- }
1435
- for (const child of current.children ?? []) visit(child);
1436
- };
1437
- visit(node);
1438
- return [...usage.values()];
1439
- }
1440
-
1441
- function textOverrideCss(
1442
- style: FigmaTypeStyle | undefined,
1443
- ): Record<string, string | undefined> {
1444
- const solidFill = [...(style?.fills ?? [])]
1445
- .reverse()
1446
- .find((fill) => fill.visible !== false && fill.type === "SOLID");
1447
- return {
1448
- "font-family": style?.fontFamily
1449
- ? `"${style.fontFamily.replace(/"/g, "")}", sans-serif`
1450
- : undefined,
1451
- "font-size": px(style?.fontSize),
1452
- "font-weight":
1453
- typeof style?.fontWeight === "number"
1454
- ? String(style.fontWeight)
1455
- : undefined,
1456
- "font-style": style?.italic ? "italic" : undefined,
1457
- "line-height": style ? resolveLineHeight(style) : undefined,
1458
- "letter-spacing":
1459
- typeof style?.letterSpacing === "number"
1460
- ? px(style.letterSpacing)
1461
- : undefined,
1462
- "text-transform": textTransformCss(style?.textCase),
1463
- "text-decoration": textDecorationCss(style?.textDecoration),
1464
- color: solidFill
1465
- ? (colorToCss(solidFill.color, solidFill.opacity ?? 1) ?? undefined)
1466
- : undefined,
1467
- };
1468
- }
1469
-
1470
- /** Render contiguous Figma character-style override runs as inline spans. */
1471
- function buildMixedTextHtml(
1472
- node: FigmaNode,
1473
- characters: string,
1474
- tracker: FidelityTracker,
1475
- ): string {
1476
- const overrideIds = node.characterStyleOverrides ?? [];
1477
- const table = node.styleOverrideTable ?? {};
1478
- if (
1479
- characters.length === 0 ||
1480
- !overrideIds.some((id) => id !== 0 && table[String(id)])
1481
- ) {
1482
- return escapeHtml(characters);
1483
- }
1484
-
1485
- const runs: Array<{ id: number; text: string }> = [];
1486
- for (let index = 0; index < characters.length; index += 1) {
1487
- const id = overrideIds[index] ?? 0;
1488
- const previous = runs[runs.length - 1];
1489
- if (previous?.id === id) previous.text += characters[index] ?? "";
1490
- else runs.push({ id, text: characters[index] ?? "" });
1491
- }
1492
-
1493
- tracker.record(
1494
- node,
1495
- "exact",
1496
- "Mixed character style overrides were preserved as inline text runs.",
1497
- );
1498
- return runs
1499
- .map((run) => {
1500
- if (run.id === 0) return escapeHtml(run.text);
1501
- const style = table[String(run.id)];
1502
- if (!style) return escapeHtml(run.text);
1503
- return `<span style="${styleAttr(textOverrideCss(style))}">${escapeHtml(run.text)}</span>`;
1504
- })
1505
- .join("");
1506
- }
1507
-
1508
- // ---------------------------------------------------------------------------
1509
- // Main mapper
1510
- // ---------------------------------------------------------------------------
1511
-
1512
- function frameRelativeBox(
1513
- node: FigmaNode,
1514
- parentBox: FigmaBoundingBox | null,
1515
- ): { left: number; top: number; width: number; height: number } {
1516
- const box = node.absoluteBoundingBox;
1517
- if (!box) return { left: 0, top: 0, width: 0, height: 0 };
1518
- return {
1519
- left: box.x - (parentBox?.x ?? box.x),
1520
- top: box.y - (parentBox?.y ?? box.y),
1521
- width: box.width,
1522
- height: box.height,
1523
- };
1524
- }
1525
-
1526
- /**
1527
- * Figma's `absoluteBoundingBox` for a rotated node is the axis-aligned
1528
- * bounding box of the ALREADY-ROTATED shape, not the shape's own (pre-
1529
- * rotation) width/height -- e.g. a 120x80 rectangle rotated 15 degrees comes
1530
- * back with an ~136.6x108.3 bounding box. Applying a CSS `rotate()` on TOP
1531
- * of a div already sized to that expanded AABB rotates an oversized box,
1532
- * producing a visibly wrong (too-large, wrong-aspect-ratio) rotated shape.
1533
- * This inverts the AABB formula (`W' = W*|cos| + H*|sin|`,
1534
- * `H' = W*|sin| + H*|cos|`) to recover the true pre-rotation width/height,
1535
- * then re-centers the (smaller) box at the same center point the AABB had --
1536
- * matching this module's existing "rotate about the AABB center" pivot
1537
- * assumption, so the CSS `rotate()` reproduces the original box exactly.
1538
- */
1539
- function unrotateBox(
1540
- box: { left: number; top: number; width: number; height: number },
1541
- rotationDeg: number,
1542
- ): { left: number; top: number; width: number; height: number } {
1543
- const theta = (rotationDeg * Math.PI) / 180;
1544
- const c = Math.abs(Math.cos(theta));
1545
- const s = Math.abs(Math.sin(theta));
1546
- const det = c * c - s * s;
1547
- // Near +-45/+-135 degrees the AABB<->true-size system is near-singular
1548
- // (many different true sizes produce almost the same AABB); fall back to
1549
- // the AABB dimensions rather than dividing by ~zero and producing a huge
1550
- // or negative "true" size.
1551
- if (Math.abs(det) < 0.05) return box;
1552
- const trueWidth = (c * box.width - s * box.height) / det;
1553
- const trueHeight = (c * box.height - s * box.width) / det;
1554
- if (
1555
- !Number.isFinite(trueWidth) ||
1556
- !Number.isFinite(trueHeight) ||
1557
- trueWidth <= 0 ||
1558
- trueHeight <= 0
1559
- ) {
1560
- return box;
1561
- }
1562
- const centerX = box.left + box.width / 2;
1563
- const centerY = box.top + box.height / 2;
1564
- return {
1565
- left: centerX - trueWidth / 2,
1566
- top: centerY - trueHeight / 2,
1567
- width: trueWidth,
1568
- height: trueHeight,
1569
- };
1570
- }
1571
-
1572
- /**
1573
- * Same as `frameRelativeBox` but sized/positioned from `absoluteRenderBounds`
1574
- * (falling back to `absoluteBoundingBox` when Figma didn't return render
1575
- * bounds). Used only for image-fallback `<img>` geometry -- see the
1576
- * `absoluteRenderBounds` field doc for why the geometric box is wrong there.
1577
- */
1578
- function frameRelativeRenderBox(
1579
- node: FigmaNode,
1580
- parentBox: FigmaBoundingBox | null,
1581
- ): { left: number; top: number; width: number; height: number } {
1582
- const box = node.absoluteRenderBounds ?? node.absoluteBoundingBox;
1583
- if (!box) return { left: 0, top: 0, width: 0, height: 0 };
1584
- return {
1585
- left: box.x - (parentBox?.x ?? box.x),
1586
- top: box.y - (parentBox?.y ?? box.y),
1587
- width: box.width,
1588
- height: box.height,
1589
- };
1590
- }
1591
-
1592
- function buildNode(
1593
- node: FigmaNode,
1594
- parentBox: FigmaBoundingBox | null,
1595
- parentLayoutMode: "NONE" | "HORIZONTAL" | "VERTICAL",
1596
- options: MapFigmaNodeOptions,
1597
- tracker: FidelityTracker,
1598
- isRoot: boolean,
1599
- ): string {
1600
- const parentHasAutoLayout = parentLayoutMode !== "NONE";
1601
- if (node.visible === false || node.opacity === 0) return "";
1602
-
1603
- let box = frameRelativeBox(node, parentBox);
1604
- // The Figma REST API's file-node-types docs describe `rotation` as
1605
- // "in degrees", but empirically (verified against known authored values
1606
- // via the Plugin API -- e.g. an authored 15deg/20deg rotation comes back
1607
- // as 0.2617993.../0.3490658... here) the REST API actually returns
1608
- // RADIANS. Treating that value as degrees silently shrinks every rotation
1609
- // by a factor of ~57 (pi/180), rendering rotated content as visually
1610
- // unrotated. Convert to degrees before using it anywhere below.
1611
- const rotationDeg =
1612
- typeof node.rotation === "number"
1613
- ? (node.rotation * 180) / Math.PI
1614
- : undefined;
1615
- const rotation =
1616
- rotationDeg !== undefined && Math.abs(rotationDeg) > 0.001
1617
- ? rotationDeg
1618
- : undefined;
1619
- if (rotation !== undefined) {
1620
- // `box` (from absoluteBoundingBox) is the rotated shape's AABB; recover
1621
- // the true pre-rotation width/height/position so fills/effects/strokes
1622
- // below -- and the CSS `rotate()` applied later -- operate on the
1623
- // correct box instead of an oversized one. See `unrotateBox`.
1624
- box = unrotateBox(box, rotation);
1625
- }
1626
- const nameAttr = node.name
1627
- ? ` data-agent-native-layer-name="${escapeAttr(node.name)}"`
1628
- : "";
1629
- const idAttr = ` data-figma-node-id="${escapeAttr(node.id)}"`;
1630
- const typeAttr = ` data-figma-node-type="${escapeAttr(node.type)}"`;
1631
- const semanticAttrs =
1632
- metadataAttr("data-figma-component-id", node.componentId, node, tracker) +
1633
- metadataAttr(
1634
- "data-figma-component-properties",
1635
- node.componentProperties,
1636
- node,
1637
- tracker,
1638
- ) +
1639
- metadataAttr(
1640
- "data-figma-bound-variables",
1641
- node.boundVariables,
1642
- node,
1643
- tracker,
1644
- ) +
1645
- metadataAttr("data-figma-interactions", node.interactions, node, tracker);
1646
- if (node.componentId || node.componentProperties) {
1647
- tracker.record(
1648
- node,
1649
- "approximated",
1650
- "Figma component/instance provenance was preserved as metadata, but the imported HTML is not linked to the original Figma component master.",
1651
- );
1652
- }
1653
- if (node.boundVariables && Object.keys(node.boundVariables).length > 0) {
1654
- tracker.record(
1655
- node,
1656
- "approximated",
1657
- "Figma variable bindings were preserved as metadata; resolved visual values are imported, but bindings are not live Design tokens.",
1658
- );
1659
- }
1660
- if (node.interactions && node.interactions.length > 0) {
1661
- tracker.record(
1662
- node,
1663
- "approximated",
1664
- "Prototype interactions were preserved as inert metadata and do not execute or navigate inside the editor preview.",
1665
- );
1666
- }
1667
-
1668
- if (needsImageFallback(node, options)) {
1669
- const imageUrl = options.fallbackImageUrls?.[node.id];
1670
- if (!imageUrl) {
1671
- tracker.record(
1672
- node,
1673
- "image-fallback",
1674
- `Node type "${node.type}" requires an image fallback but no rendered URL was provided; nothing was rendered for this node.`,
1675
- );
1676
- return "";
1677
- }
1678
- tracker.record(
1679
- node,
1680
- "image-fallback",
1681
- `Node type "${node.type}" cannot be reproduced structurally (vector network / boolean op / unsupported type); rendered as an exact PNG (scale=2) instead of an approximated structural guess.`,
1682
- );
1683
- const isFlowChild =
1684
- !isRoot && parentHasAutoLayout && node.layoutPositioning !== "ABSOLUTE";
1685
- // Use render bounds (not the geometric box) so a fallback PNG whose
1686
- // stroke/effects overflow the node's own bounding box (e.g. an
1687
- // OUTSIDE-aligned stroke) is placed at its natural size instead of being
1688
- // squished/cropped into the smaller geometric box.
1689
- const renderBox = frameRelativeRenderBox(node, parentBox);
1690
- const styles: Record<string, string | undefined> = {
1691
- position: isRoot || isFlowChild ? "relative" : "absolute",
1692
- left: isRoot || isFlowChild ? undefined : px(renderBox.left),
1693
- top: isRoot || isFlowChild ? undefined : px(renderBox.top),
1694
- width: px(renderBox.width),
1695
- height: px(renderBox.height),
1696
- opacity:
1697
- typeof node.opacity === "number" && node.opacity !== 1
1698
- ? String(round(node.opacity, 4))
1699
- : undefined,
1700
- };
1701
- return `<img${idAttr}${typeAttr}${nameAttr}${semanticAttrs} src="${escapeAttr(imageUrl)}" alt="${escapeAttr(node.name ?? "")}" style="${styleAttr(styles)}" />`;
1702
- }
1703
-
1704
- const isTextNode = node.type === "TEXT";
1705
- const isEllipse = node.type === "ELLIPSE";
1706
- const box2 = { width: box.width, height: box.height };
1707
-
1708
- const fills = buildFills(
1709
- node,
1710
- node.fills,
1711
- box2,
1712
- options,
1713
- tracker,
1714
- isTextNode,
1715
- );
1716
- const strokeResult = buildStrokes(node, tracker);
1717
- const effects = buildEffects(node, isTextNode, tracker);
1718
- const cornerRadius = isEllipse ? "50%" : buildCornerRadius(node);
1719
- const blendMode = buildBlendMode(node, tracker);
1720
-
1721
- const boxShadowParts = [...effects.boxShadowLayers];
1722
- if (strokeResult.insetShadow) boxShadowParts.push(strokeResult.insetShadow);
1723
-
1724
- if (rotation !== undefined) {
1725
- tracker.record(
1726
- node,
1727
- "approximated",
1728
- `Rotation (${round(rotation, 2)}deg) reconstructed by pivoting the unrotated box about the absoluteBoundingBox center; exact only when Figma's internal pivot is also the shape's center.`,
1729
- );
1730
- }
1731
-
1732
- const autoLayoutStyles = buildAutoLayoutStyles(node);
1733
- const childSizingStyles = buildChildSizingStyles(node, parentLayoutMode);
1734
- const hasAutoLayout = Boolean(autoLayoutStyles.display);
1735
- // A node is positioned relative to its parent's free canvas (absolute,
1736
- // left/top from absoluteBoundingBox) unless its *parent* is an auto-layout
1737
- // container, in which case it's a normal flex item (relative, no left/top)
1738
- // -- this mirrors Figma's own rule that auto-layout children give up
1739
- // manual x/y in favor of flex flow.
1740
- const isFlexChild =
1741
- !isRoot && parentHasAutoLayout && node.layoutPositioning !== "ABSOLUTE";
1742
-
1743
- const baseStyles: Record<string, string | undefined> = {
1744
- position: isRoot ? "relative" : isFlexChild ? "relative" : "absolute",
1745
- left: isRoot || isFlexChild ? undefined : px(box.left),
1746
- top: isRoot || isFlexChild ? undefined : px(box.top),
1747
- width: childSizingStyles.width ?? px(box.width),
1748
- height: childSizingStyles.height ?? px(box.height),
1749
- "background-color": fills.backgroundColor,
1750
- "background-image": fills.backgroundImage,
1751
- "background-size": fills.backgroundSize,
1752
- "background-position": fills.backgroundPosition,
1753
- "background-repeat": fills.backgroundRepeat,
1754
- color: fills.color,
1755
- "border-radius": cornerRadius,
1756
- "box-shadow":
1757
- boxShadowParts.length > 0 ? boxShadowParts.join(", ") : undefined,
1758
- filter: effects.filter,
1759
- "backdrop-filter": effects.backdropFilter,
1760
- "-webkit-backdrop-filter": effects.backdropFilter,
1761
- opacity:
1762
- typeof node.opacity === "number" && node.opacity !== 1
1763
- ? String(round(node.opacity, 4))
1764
- : undefined,
1765
- "mix-blend-mode": blendMode,
1766
- overflow: node.clipsContent ? "hidden" : undefined,
1767
- transform:
1768
- rotation !== undefined ? `rotate(${round(-rotation, 3)}deg)` : undefined,
1769
- "transform-origin": rotation !== undefined ? "center" : undefined,
1770
- "min-width": px(node.minWidth ?? undefined),
1771
- "max-width": px(node.maxWidth ?? undefined),
1772
- "min-height": px(node.minHeight ?? undefined),
1773
- "max-height": px(node.maxHeight ?? undefined),
1774
- ...autoLayoutStyles,
1775
- ...strokeResult.styles,
1776
- ...childSizingStyles,
1777
- };
1778
-
1779
- if (isTextNode) {
1780
- const style = node.style ?? {};
1781
- baseStyles["font-family"] = style.fontFamily
1782
- ? `"${style.fontFamily.replace(/"/g, "")}", sans-serif`
1783
- : undefined;
1784
- baseStyles["font-size"] = px(style.fontSize);
1785
- baseStyles["font-weight"] =
1786
- typeof style.fontWeight === "number"
1787
- ? String(style.fontWeight)
1788
- : undefined;
1789
- baseStyles["font-style"] = style.italic ? "italic" : undefined;
1790
- baseStyles["line-height"] = resolveLineHeight(style);
1791
- baseStyles["letter-spacing"] =
1792
- typeof style.letterSpacing === "number" && style.letterSpacing !== 0
1793
- ? px(style.letterSpacing)
1794
- : undefined;
1795
- baseStyles["text-transform"] = textTransformCss(style.textCase);
1796
- baseStyles["text-decoration"] = textDecorationCss(style.textDecoration);
1797
- baseStyles["text-align"] = textAlignCss(style.textAlignHorizontal);
1798
- if (style.textAutoResize === "TRUNCATE") {
1799
- baseStyles["white-space"] = "nowrap";
1800
- baseStyles.overflow = "hidden";
1801
- baseStyles["text-overflow"] = "ellipsis";
1802
- } else {
1803
- // Figma preserves explicit newlines and repeated spaces. Normal HTML
1804
- // whitespace collapsing changes both wrapping and measured geometry.
1805
- baseStyles["white-space"] = "pre-wrap";
1806
- }
1807
- baseStyles.display = "flex";
1808
- baseStyles["flex-direction"] = "column";
1809
- baseStyles["justify-content"] = verticalAlignJustifyContent(
1810
- style.textAlignVertical,
1811
- );
1812
- tracker.record(node, "exact", "Text styling mapped from TypeStyle fields.");
1813
-
1814
- const characters = node.characters ?? "";
1815
- const textHtml = buildMixedTextHtml(node, characters, tracker);
1816
- return `<div${idAttr}${typeAttr}${nameAttr}${semanticAttrs} style="${styleAttr(baseStyles)}"><span>${textHtml}</span></div>`;
1817
- }
1818
-
1819
- tracker.record(
1820
- node,
1821
- "exact",
1822
- "Position, size, fills, strokes, and effects mapped 1:1.",
1823
- );
1824
-
1825
- // hasAutoLayout guarantees node.layoutMode is "HORIZONTAL" or "VERTICAL"
1826
- // (buildAutoLayoutStyles returns {} -- no `display` -- for "NONE"/"GRID").
1827
- const childParentLayoutMode: "NONE" | "HORIZONTAL" | "VERTICAL" =
1828
- hasAutoLayout ? (node.layoutMode as "HORIZONTAL" | "VERTICAL") : "NONE";
1829
- const childrenHtml = (node.children ?? [])
1830
- .map((child) =>
1831
- buildNode(
1832
- child,
1833
- node.absoluteBoundingBox ?? null,
1834
- childParentLayoutMode,
1835
- options,
1836
- tracker,
1837
- false,
1838
- ),
1839
- )
1840
- .filter(Boolean)
1841
- .join("\n");
1842
-
1843
- return `<div${idAttr}${typeAttr}${nameAttr}${semanticAttrs} style="${styleAttr(baseStyles)}">\n${childrenHtml}\n</div>`;
1844
- }
1845
-
1846
- /**
1847
- * Map a Figma node (and its subtree) to an HTML fragment plus a fidelity
1848
- * report describing which properties were exact, approximated, or rendered
1849
- * as an image fallback.
1850
- */
1851
- export function mapFigmaNodeToHtml(
1852
- node: FigmaNode,
1853
- options: MapFigmaNodeOptions = {},
1854
- ): MapFigmaNodeResult {
1855
- assertFigmaNodeTreeComplexity(node);
1856
- const tracker = new FidelityTracker();
1857
- const html = buildNode(node, null, "NONE", options, tracker, true);
1858
- return { html, fidelity: tracker.build() };
1859
- }
1
+ export * from "@agent-native/core/ingestion";