@1agh/maude 2.0.8 → 2.1.1

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 (401) hide show
  1. package/README.md +2 -1
  2. package/apps/hub/src/project-transactions/kernel.mjs +13 -7
  3. package/apps/studio/access/closure.ts +86 -10
  4. package/apps/studio/access/filters.ts +18 -1
  5. package/apps/studio/access/request.ts +8 -0
  6. package/apps/studio/acp/design-write-verb.ts +12 -2
  7. package/apps/studio/acp/env.ts +7 -2
  8. package/apps/studio/acp/index.ts +15 -4
  9. package/apps/studio/acp/login-state.ts +22 -5
  10. package/apps/studio/acp/may-scope.ts +38 -1
  11. package/apps/studio/acp/plugin-bootstrap.ts +13 -1
  12. package/apps/studio/acp/probe.ts +11 -4
  13. package/apps/studio/actions/agents.ts +110 -28
  14. package/apps/studio/actions/canvas-keys.ts +4 -2
  15. package/apps/studio/actions/ctx.ts +3 -0
  16. package/apps/studio/actions/defs/annotation.ts +84 -2
  17. package/apps/studio/actions/defs/app.ts +28 -1
  18. package/apps/studio/actions/defs/edit.ts +13 -0
  19. package/apps/studio/actions/defs/export.ts +12 -0
  20. package/apps/studio/actions/defs/sync.ts +18 -0
  21. package/apps/studio/actions/defs/video.ts +9 -0
  22. package/apps/studio/actions/documents.ts +6 -1
  23. package/apps/studio/actions/keymap.gen.ts +147 -9
  24. package/apps/studio/actions/menu.ts +5 -1
  25. package/apps/studio/actions/types.ts +4 -2
  26. package/apps/studio/actions/verbs.ts +9 -0
  27. package/apps/studio/actions.manifest.json +300 -45
  28. package/apps/studio/actions.parity.json +19 -1
  29. package/apps/studio/ai/save-hold.ts +2 -1
  30. package/apps/studio/ai/write-claim-scope.ts +7 -1
  31. package/apps/studio/ai/write-claim.ts +154 -3
  32. package/apps/studio/annotations/ai-read.ts +42 -6
  33. package/apps/studio/annotations/ai-write.ts +145 -2
  34. package/apps/studio/annotations/board-ops.ts +34 -3
  35. package/apps/studio/annotations/checklist-ops.ts +374 -0
  36. package/apps/studio/annotations/elements/checkitem.model.ts +129 -0
  37. package/apps/studio/annotations/elements/sticky.model.ts +54 -2
  38. package/apps/studio/annotations/ops.ts +30 -0
  39. package/apps/studio/annotations/registry.ts +9 -1
  40. package/apps/studio/annotations/templates.ts +4 -2
  41. package/apps/studio/annotations/text-steps.ts +114 -10
  42. package/apps/studio/annotations/ui/checklist-wire.ts +129 -0
  43. package/apps/studio/annotations/ui/checklist.tsx +429 -0
  44. package/apps/studio/annotations/ui/element-node.tsx +48 -2
  45. package/apps/studio/annotations/ui/template-place.ts +11 -1
  46. package/apps/studio/annotations/v1-adapter.ts +22 -3
  47. package/apps/studio/annotations-context-toolbar.tsx +12 -0
  48. package/apps/studio/annotations-layer.tsx +442 -49
  49. package/apps/studio/annotations-model.ts +4 -2
  50. package/apps/studio/api.ts +148 -21
  51. package/apps/studio/artboard-live-gate.tsx +54 -17
  52. package/apps/studio/artboard-still-persist.ts +166 -0
  53. package/apps/studio/artboard-still-raster.ts +6 -2
  54. package/apps/studio/artboard-still.ts +390 -20
  55. package/apps/studio/asset-added.ts +154 -0
  56. package/apps/studio/asset-details.ts +46 -3
  57. package/apps/studio/asset-origins.ts +5 -3
  58. package/apps/studio/asset-trash.ts +6 -1
  59. package/apps/studio/bin/_agent-browser-safe.mjs +3 -4
  60. package/apps/studio/bin/_annotate-post.mjs +14 -5
  61. package/apps/studio/bin/_audio-search.mjs +8 -2
  62. package/apps/studio/bin/_curl-local.mjs +7 -4
  63. package/apps/studio/bin/_desktop-locate.sh +145 -0
  64. package/apps/studio/bin/_ds-check-live.mjs +2 -1
  65. package/apps/studio/bin/_exports.mjs +38 -2
  66. package/apps/studio/bin/_history.mjs +79 -8
  67. package/apps/studio/bin/_import-asset.mjs +14 -9
  68. package/apps/studio/bin/_import-figma.mjs +510 -98
  69. package/apps/studio/bin/_index-cli.mjs +10 -21
  70. package/apps/studio/bin/_ingest-footage.mjs +24 -6
  71. package/apps/studio/bin/_media-probe.mjs +232 -0
  72. package/apps/studio/bin/_perf-probe-open.mjs +6 -0
  73. package/apps/studio/bin/_perf-probe-safari.mjs +6 -0
  74. package/apps/studio/bin/_perf-probe-studio.mjs +6 -1
  75. package/apps/studio/bin/_perf-probe.mjs +8 -3
  76. package/apps/studio/bin/_perf-sweep-shared.mjs +789 -0
  77. package/apps/studio/bin/_perf-sweep.mjs +240 -0
  78. package/apps/studio/bin/_record-shot.sh +33 -8
  79. package/apps/studio/bin/_screenshot-playwright.mjs +45 -2
  80. package/apps/studio/bin/_studio-verb.mjs +8 -3
  81. package/apps/studio/bin/_thumb-route.mjs +21 -0
  82. package/apps/studio/bin/_thumbs-playwright.mjs +83 -1
  83. package/apps/studio/bin/_transcribe.mjs +22 -6
  84. package/apps/studio/bin/_unsynced-refs.mjs +22 -0
  85. package/apps/studio/bin/_url-guard.mjs +120 -5
  86. package/apps/studio/bin/_url-guard.sh +29 -7
  87. package/apps/studio/bin/_video-limits.mjs +104 -0
  88. package/apps/studio/bin/_video-playwright.mjs +119 -19
  89. package/apps/studio/bin/_video-proxy.mjs +130 -0
  90. package/apps/studio/bin/_write-claim.mjs +38 -16
  91. package/apps/studio/bin/annotate.mjs +12 -2
  92. package/apps/studio/bin/canvas-rects.sh +19 -4
  93. package/apps/studio/bin/chat-open.sh +7 -1
  94. package/apps/studio/bin/draw-proof.sh +6 -2
  95. package/apps/studio/bin/generate.sh +32 -10
  96. package/apps/studio/bin/handoff.sh +2 -2
  97. package/apps/studio/bin/perf.sh +96 -15
  98. package/apps/studio/bin/photo-adjust.sh +6 -3
  99. package/apps/studio/bin/photo-bg-remove.sh +2 -2
  100. package/apps/studio/bin/prep.sh +21 -4
  101. package/apps/studio/bin/read-annotations.mjs +3 -0
  102. package/apps/studio/bin/runtime-health.sh +27 -1
  103. package/apps/studio/bin/screenshot.sh +152 -12
  104. package/apps/studio/bin/server-up.sh +64 -6
  105. package/apps/studio/bin/smoke.sh +43 -8
  106. package/apps/studio/bin/to-lottie.sh +3 -2
  107. package/apps/studio/bin/video-proxy.sh +27 -0
  108. package/apps/studio/bin/visual-sanity.sh +3 -1
  109. package/apps/studio/bridge/dgn-protocol.ts +157 -1
  110. package/apps/studio/bridge/mode-shows.ts +8 -6
  111. package/apps/studio/bridge/still-webp.ts +233 -0
  112. package/apps/studio/build.ts +18 -0
  113. package/apps/studio/canvas-build.ts +93 -11
  114. package/apps/studio/canvas-comment-mount.tsx +53 -8
  115. package/apps/studio/canvas-edit.ts +34 -1
  116. package/apps/studio/canvas-lib-module.ts +210 -0
  117. package/apps/studio/canvas-lib.tsx +3 -12
  118. package/apps/studio/canvas-pipeline.ts +111 -5
  119. package/apps/studio/canvas-shell.tsx +8 -11
  120. package/apps/studio/canvas-theme-pill.tsx +5 -3
  121. package/apps/studio/check/index.ts +12 -5
  122. package/apps/studio/check/video.ts +18 -2
  123. package/apps/studio/client/app.jsx +65 -7
  124. package/apps/studio/client/clipboard-relay.ts +193 -16
  125. package/apps/studio/client/comments-overlay.css +18 -0
  126. package/apps/studio/client/export-center.jsx +30 -0
  127. package/apps/studio/client/generate-dialog.jsx +49 -4
  128. package/apps/studio/client/github.js +7 -0
  129. package/apps/studio/client/home/HomeAccountsRow.jsx +221 -0
  130. package/apps/studio/client/home/HomeConnection.jsx +111 -0
  131. package/apps/studio/client/home/home-accounts-model.js +110 -1
  132. package/apps/studio/client/home/home-api.js +9 -2
  133. package/apps/studio/client/home/home-app.jsx +126 -13
  134. package/apps/studio/client/home/home-model.js +69 -1
  135. package/apps/studio/client/home/home-where-model.js +105 -0
  136. package/apps/studio/client/home/home.css +239 -1
  137. package/apps/studio/client/hooks/use-canvas-bridge.jsx +173 -98
  138. package/apps/studio/client/hooks/use-palette-and-panels.jsx +5 -1
  139. package/apps/studio/client/hooks/use-tabs.jsx +11 -4
  140. package/apps/studio/client/panels/DiffView.jsx +7 -1
  141. package/apps/studio/client/panels/TeamProjects.jsx +137 -134
  142. package/apps/studio/client/panels/chat-context.js +2 -0
  143. package/apps/studio/client/panels/slash-commands.gen.js +13 -13
  144. package/apps/studio/client/selection-scope.js +16 -9
  145. package/apps/studio/client/share-link.js +12 -0
  146. package/apps/studio/client/shell/viewport.jsx +11 -1
  147. package/apps/studio/client/shell-events.js +8 -0
  148. package/apps/studio/client/styles/3-kit-maude-v2.css +16 -0
  149. package/apps/studio/client/styles/_index.css +4 -0
  150. package/apps/studio/client/v2/ai/Feed.jsx +1 -1
  151. package/apps/studio/client/v2/ai/OfferCard.jsx +34 -0
  152. package/apps/studio/client/v2/ai/activity-line.js +54 -1
  153. package/apps/studio/client/v2/ai/ai-offer.js +21 -1
  154. package/apps/studio/client/v2/ai/run-model.js +3 -1
  155. package/apps/studio/client/v2/annotations/vote-store.js +28 -4
  156. package/apps/studio/client/v2/assets/asset-drop-session.js +37 -2
  157. package/apps/studio/client/v2/assets/canvas-drop-catcher.jsx +7 -5
  158. package/apps/studio/client/v2/assets/details-model.js +1 -1
  159. package/apps/studio/client/v2/assets/details.jsx +5 -0
  160. package/apps/studio/client/v2/assets/tile-drag.js +11 -7
  161. package/apps/studio/client/v2/comments/comments-panel.jsx +22 -3
  162. package/apps/studio/client/v2/create/duplicate-done.js +6 -2
  163. package/apps/studio/client/v2/diagnostics/diagnostics-host.jsx +1 -0
  164. package/apps/studio/client/v2/diagnostics/diagnostics-model.js +32 -2
  165. package/apps/studio/client/v2/diagnostics/diagnostics-sheet.jsx +35 -8
  166. package/apps/studio/client/v2/diagnostics/diagnostics.css +34 -0
  167. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +113 -3
  168. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +343 -6
  169. package/apps/studio/client/v2/diagnostics/sync-details/unsynced-refs.js +55 -0
  170. package/apps/studio/client/v2/ds/review.css +1 -1
  171. package/apps/studio/client/v2/export/exports-model.js +7 -0
  172. package/apps/studio/client/v2/export/exports-panel.jsx +1 -0
  173. package/apps/studio/client/v2/export/job-row.jsx +32 -2
  174. package/apps/studio/client/v2/handoff/ready-card.jsx +1 -1
  175. package/apps/studio/client/v2/history/compare-view.jsx +1 -0
  176. package/apps/studio/client/v2/inspector/css-write.js +6 -1
  177. package/apps/studio/client/v2/inspector/frame.jsx +28 -4
  178. package/apps/studio/client/v2/inspector/kinds/clip-model.js +51 -0
  179. package/apps/studio/client/v2/inspector/kinds/clip.jsx +75 -2
  180. package/apps/studio/client/v2/inspector/model.js +21 -0
  181. package/apps/studio/client/v2/inspector/sections/fill.jsx +12 -3
  182. package/apps/studio/client/v2/inspector/sections/recent-colours.js +8 -5
  183. package/apps/studio/client/v2/inspector/view-mode.jsx +11 -1
  184. package/apps/studio/client/v2/link-server/LinkServerDialog.jsx +492 -0
  185. package/apps/studio/client/v2/link-server/LinkServerHost.jsx +42 -0
  186. package/apps/studio/client/v2/link-server/link-server-api.js +142 -0
  187. package/apps/studio/client/v2/link-server/link-server-model.js +438 -0
  188. package/apps/studio/client/v2/link-server/link-server.css +109 -0
  189. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +31 -86
  190. package/apps/studio/client/v2/onboarding/onboarding-model.js +1 -18
  191. package/apps/studio/client/v2/preview/link-follow.js +4 -2
  192. package/apps/studio/client/v2/preview/preview-chrome-host.jsx +16 -6
  193. package/apps/studio/client/v2/search/help-model.js +2 -0
  194. package/apps/studio/client/v2/search/search-keywords.js +3 -2
  195. package/apps/studio/client/v2/settings/account.jsx +4 -2
  196. package/apps/studio/client/v2/settings/advanced-section.jsx +344 -137
  197. package/apps/studio/client/v2/settings/connection-row.jsx +3 -59
  198. package/apps/studio/client/v2/settings/connections-section.jsx +118 -425
  199. package/apps/studio/client/v2/settings/general-section.jsx +155 -24
  200. package/apps/studio/client/v2/settings/project-sync-settings.jsx +4 -3
  201. package/apps/studio/client/v2/settings/reset-section.jsx +14 -3
  202. package/apps/studio/client/v2/settings/settings-card.jsx +142 -0
  203. package/apps/studio/client/v2/settings/settings-cards.js +220 -0
  204. package/apps/studio/client/v2/settings/settings-handlers.js +7 -6
  205. package/apps/studio/client/v2/settings/settings-model.js +100 -31
  206. package/apps/studio/client/v2/settings/settings-sheet.jsx +25 -6
  207. package/apps/studio/client/v2/settings/settings.css +374 -64
  208. package/apps/studio/client/v2/settings/this-project-card.jsx +730 -0
  209. package/apps/studio/client/v2/settings/this-project-model.js +172 -0
  210. package/apps/studio/client/v2/settings/use-connections.js +3 -2
  211. package/apps/studio/client/v2/settings/use-open-card.js +37 -0
  212. package/apps/studio/client/v2/share/share-sheet.jsx +28 -11
  213. package/apps/studio/client/v2/shell/api-session-boot.js +6 -0
  214. package/apps/studio/client/v2/shell/api-session.js +126 -0
  215. package/apps/studio/client/v2/shell/connection-state.js +197 -0
  216. package/apps/studio/client/v2/shell/floating-panels.css +31 -1
  217. package/apps/studio/client/v2/shell/image-pick.js +61 -8
  218. package/apps/studio/client/v2/shell/menu-aim.js +43 -0
  219. package/apps/studio/client/v2/shell/menu-runner.js +25 -7
  220. package/apps/studio/client/v2/shell/occlusion-insets.js +18 -1
  221. package/apps/studio/client/v2/shell/project-account-bus.js +36 -0
  222. package/apps/studio/client/v2/shell/project-account-card.jsx +357 -148
  223. package/apps/studio/client/v2/shell/project-account-model.js +272 -149
  224. package/apps/studio/client/v2/shell/project-account-toast.js +66 -0
  225. package/apps/studio/client/v2/shell/project-account.css +237 -0
  226. package/apps/studio/client/v2/shell/project-pill.jsx +52 -6
  227. package/apps/studio/client/v2/shell/share-cluster-host.jsx +166 -83
  228. package/apps/studio/client/v2/shell/shell-parity.js +3 -2
  229. package/apps/studio/client/v2/shell/shell-parity.json +71 -36
  230. package/apps/studio/client/v2/shell/still-bridge.js +194 -0
  231. package/apps/studio/client/v2/shell/still-store.js +319 -0
  232. package/apps/studio/client/v2/shell/use-account.js +2 -0
  233. package/apps/studio/client/v2/shell/use-tool-panels.js +2 -1
  234. package/apps/studio/client/v2/signin/use-signin.js +1 -1
  235. package/apps/studio/client/v2/timeline/Timeline.jsx +15 -0
  236. package/apps/studio/client/v2/timeline/frame-handle-model.js +142 -0
  237. package/apps/studio/client/v2/timeline/frame-handle.jsx +151 -0
  238. package/apps/studio/clip-ops.ts +126 -8
  239. package/apps/studio/cloud/endpoints.ts +29 -4
  240. package/apps/studio/collab/ai-activity.ts +10 -8
  241. package/apps/studio/collab/awareness-bridge.ts +34 -9
  242. package/apps/studio/collab/index.ts +3 -0
  243. package/apps/studio/collab/registry.ts +41 -10
  244. package/apps/studio/comment-reattach.ts +149 -0
  245. package/apps/studio/comments/mine-stamp.ts +15 -7
  246. package/apps/studio/comments/ops.ts +52 -8
  247. package/apps/studio/comments-overlay.tsx +146 -9
  248. package/apps/studio/dist/client.bundle.js +892 -885
  249. package/apps/studio/dist/comment-mount.js +2 -2
  250. package/apps/studio/dist/styles.css +1 -1
  251. package/apps/studio/dom-selection.ts +87 -18
  252. package/apps/studio/ds/board/directions.css +8 -0
  253. package/apps/studio/ds/board/outline.tsx +16 -0
  254. package/apps/studio/ds/canvas-check.ts +6 -0
  255. package/apps/studio/edit-ops/clip/reframe.ts +19 -3
  256. package/apps/studio/edit-ops/clip-carry.ts +602 -0
  257. package/apps/studio/edit-ops/clipboard.ts +318 -23
  258. package/apps/studio/edit-ops/dispatch.ts +20 -2
  259. package/apps/studio/edit-ops/scope-names.ts +249 -40
  260. package/apps/studio/edit-ops/slot-defaults.ts +3 -0
  261. package/apps/studio/edit-ops/types.ts +6 -0
  262. package/apps/studio/editing/align-bar.tsx +33 -9
  263. package/apps/studio/editing/artboard-actions.ts +5 -0
  264. package/apps/studio/editing/artboard-menu.tsx +6 -2
  265. package/apps/studio/editing/click-to-type.ts +1 -1
  266. package/apps/studio/editing/clip-words.ts +48 -0
  267. package/apps/studio/editing/clipboard.ts +21 -6
  268. package/apps/studio/editing/declared-background.ts +25 -0
  269. package/apps/studio/editing/index.tsx +3 -0
  270. package/apps/studio/editing/object-keys.ts +4 -4
  271. package/apps/studio/editing/object-menu.tsx +13 -3
  272. package/apps/studio/editing/pen/points.tsx +61 -0
  273. package/apps/studio/editing/text-in-place.tsx +11 -0
  274. package/apps/studio/editing/video-frame-handle.tsx +425 -0
  275. package/apps/studio/exporters/capture-prepass.ts +374 -0
  276. package/apps/studio/exporters/degraded.ts +148 -0
  277. package/apps/studio/exporters/hub-render-door.ts +28 -2
  278. package/apps/studio/exporters/index.ts +3 -1
  279. package/apps/studio/exporters/job-budget.ts +93 -0
  280. package/apps/studio/exporters/jobs.ts +215 -28
  281. package/apps/studio/exporters/parity-check.ts +254 -0
  282. package/apps/studio/exporters/remote.ts +209 -15
  283. package/apps/studio/exporters/svg-inline.ts +87 -0
  284. package/apps/studio/exporters/video-render-lib.ts +88 -26
  285. package/apps/studio/exporters/video.ts +29 -6
  286. package/apps/studio/figma/assets.ts +58 -43
  287. package/apps/studio/figma/codegen-fonts.ts +100 -0
  288. package/apps/studio/figma/fig-decode.ts +390 -25
  289. package/apps/studio/figma/fig-kiwi.ts +18 -4
  290. package/apps/studio/figma/fig-vector.ts +59 -3
  291. package/apps/studio/figma/sanitize.ts +2 -0
  292. package/apps/studio/figma/style-map.ts +293 -48
  293. package/apps/studio/figma/to-artboard.ts +455 -69
  294. package/apps/studio/figma/to-strokes.ts +44 -11
  295. package/apps/studio/figma/types.ts +13 -0
  296. package/apps/studio/footage/schema.ts +3 -3
  297. package/apps/studio/generation/adapters/elevenlabs.ts +7 -1
  298. package/apps/studio/generation/adapters/groq.ts +8 -1
  299. package/apps/studio/generation/spend.ts +312 -0
  300. package/apps/studio/generation/types.ts +12 -0
  301. package/apps/studio/handoff/run.ts +1 -1
  302. package/apps/studio/handoff/targets.ts +2 -2
  303. package/apps/studio/handoff/write-scopes.ts +1 -1
  304. package/apps/studio/history/describe-annotations.ts +4 -0
  305. package/apps/studio/home/accounts.ts +30 -11
  306. package/apps/studio/home/cloud.ts +6 -1
  307. package/apps/studio/home/create-local.ts +32 -3
  308. package/apps/studio/home/hub-health.ts +76 -0
  309. package/apps/studio/home/routes.ts +15 -4
  310. package/apps/studio/http.ts +438 -86
  311. package/apps/studio/imported-module-ids.ts +91 -0
  312. package/apps/studio/inspect.ts +2 -0
  313. package/apps/studio/migrate/hub.ts +8 -1
  314. package/apps/studio/notifications.tsx +47 -5
  315. package/apps/studio/paths.ts +10 -1
  316. package/apps/studio/port.ts +3 -2
  317. package/apps/studio/preview/preview-camera.tsx +15 -382
  318. package/apps/studio/readiness.ts +10 -1
  319. package/apps/studio/release-build.ts +51 -0
  320. package/apps/studio/routes/agent.ts +188 -9
  321. package/apps/studio/routes/ai.ts +43 -11
  322. package/apps/studio/routes/annotations.ts +27 -1
  323. package/apps/studio/routes/assets.ts +18 -1
  324. package/apps/studio/routes/canvas-origin.ts +12 -9
  325. package/apps/studio/routes/cloud-move.ts +15 -0
  326. package/apps/studio/routes/edit.ts +3 -0
  327. package/apps/studio/routes/export.ts +51 -0
  328. package/apps/studio/routes/generate.ts +42 -12
  329. package/apps/studio/routes/hub-link-folder.ts +334 -0
  330. package/apps/studio/routes/hub-signin.ts +78 -1
  331. package/apps/studio/routes/index.ts +9 -1
  332. package/apps/studio/routes/shell.ts +217 -5
  333. package/apps/studio/routes/sync.ts +136 -8
  334. package/apps/studio/routes/votes.ts +2 -1
  335. package/apps/studio/schema/annotations.v2.schema.json +143 -1
  336. package/apps/studio/schema/beats.v1.schema.json +1 -1
  337. package/apps/studio/schema/edl.v1.schema.json +1 -1
  338. package/apps/studio/schema/formats.ts +3 -3
  339. package/apps/studio/schema/transcript.v1.schema.json +1 -1
  340. package/apps/studio/server.ts +142 -43
  341. package/apps/studio/shell/api-key.ts +503 -0
  342. package/apps/studio/shell/attest.ts +59 -0
  343. package/apps/studio/shell/capture-url.ts +20 -0
  344. package/apps/studio/shell/cli-yield.ts +276 -0
  345. package/apps/studio/shell/clip-transfer.ts +302 -0
  346. package/apps/studio/shell/key-file.ts +108 -0
  347. package/apps/studio/shell/server-json.ts +75 -0
  348. package/apps/studio/shell/worktree.ts +19 -0
  349. package/apps/studio/spoof-chars.ts +9 -0
  350. package/apps/studio/studio-page-host.ts +1 -1
  351. package/apps/studio/sync/accepted-cold-start.ts +144 -8
  352. package/apps/studio/sync/accepted-link.ts +76 -29
  353. package/apps/studio/sync/action-stage.ts +575 -44
  354. package/apps/studio/sync/adopt-held.ts +85 -0
  355. package/apps/studio/sync/ctl-heal.ts +58 -0
  356. package/apps/studio/sync/file-ledger.ts +38 -4
  357. package/apps/studio/sync/file-membership.ts +16 -1
  358. package/apps/studio/sync/file-plane.ts +289 -22
  359. package/apps/studio/sync/held-deletes.ts +86 -5
  360. package/apps/studio/sync/hub-link.ts +8 -0
  361. package/apps/studio/sync/index.ts +196 -12
  362. package/apps/studio/sync/journal-client.ts +50 -4
  363. package/apps/studio/sync/link-consent.ts +22 -75
  364. package/apps/studio/sync/link-survey.ts +252 -0
  365. package/apps/studio/sync/local-kernel.ts +296 -8
  366. package/apps/studio/sync/projection.ts +22 -3
  367. package/apps/studio/sync/seed-progress.ts +12 -0
  368. package/apps/studio/sync/source-recovery.ts +59 -3
  369. package/apps/studio/sync/status.ts +19 -2
  370. package/apps/studio/sync/unsynced-refs.ts +397 -0
  371. package/apps/studio/sync/writer-registry.ts +20 -0
  372. package/apps/studio/thumbs/service.ts +4 -1
  373. package/apps/studio/tool-palette.tsx +23 -0
  374. package/apps/studio/ui-prefs.ts +40 -0
  375. package/apps/studio/use-agent-presence.tsx +2 -2
  376. package/apps/studio/use-canvas-keys.ts +6 -1
  377. package/apps/studio/video/format-ids.ts +2 -2
  378. package/apps/studio/video/inject.ts +31 -0
  379. package/apps/studio/video/media-risk.ts +58 -0
  380. package/apps/studio/video/object-fit.ts +137 -0
  381. package/apps/studio/video/provider-transcript.ts +141 -0
  382. package/apps/studio/whats-new.json +137 -0
  383. package/apps/studio/workspace-mode.ts +1 -0
  384. package/apps/studio/ws.ts +5 -0
  385. package/cli/commands/design.mjs +119 -8
  386. package/cli/lib/bash-guard.mjs +366 -6
  387. package/cli/lib/confine-read.mjs +1 -0
  388. package/cli/lib/design-help.gen.mjs +3 -2
  389. package/cli/lib/design-hook.mjs +387 -81
  390. package/cli/lib/design-link.mjs +16 -1
  391. package/cli/lib/design-open.mjs +49 -3
  392. package/cli/lib/desktop-locate.mjs +770 -0
  393. package/cli/lib/handoff.mjs +1 -1
  394. package/cli/lib/hook-state.mjs +291 -0
  395. package/cli/lib/pkg-root.mjs +65 -13
  396. package/cli/lib/studio-locate.mjs +59 -16
  397. package/package.json +15 -8
  398. package/plugins/design/templates/_shell.html +13 -0
  399. package/apps/studio/client/v2/onboarding/HubSheet.jsx +0 -212
  400. package/apps/studio/client/v2/shell/account-card-model.js +0 -114
  401. package/apps/studio/client/v2/shell/account-card.jsx +0 -189
@@ -29,12 +29,13 @@ import { inflateRawSync, zstdDecompressSync } from 'node:zlib';
29
29
 
30
30
  import { styleToWeight } from './codegen-fonts.ts';
31
31
  import { decodeKiwi, findRootDefinition, type KiwiSchema, parseKiwiSchema } from './fig-kiwi.ts';
32
- import { pathFromBlob, type VectorPath } from './fig-vector.ts';
32
+ import { pathFromBlob, type VectorGradient, type VectorPath } from './fig-vector.ts';
33
33
  import { FigZipError, readFigZip } from './fig-zip.ts';
34
34
  import { reportToken } from './sanitize.ts';
35
35
  import {
36
36
  KNOWN_NODE_TYPES,
37
37
  MAX_NODE_COUNT,
38
+ MAX_TREE_DEPTH,
38
39
  type NormalizedDocument,
39
40
  normalizeDocument,
40
41
  } from './types.ts';
@@ -44,6 +45,9 @@ import {
44
45
  /** The 8-byte ASCII prelude is the ONLY editor discriminator. */
45
46
  const PRELUDES: Record<string, 'design' | 'board'> = {
46
47
  'fig-kiwi': 'design',
48
+ // Figma Slides. Same container, same schema; only the prelude differs
49
+ // (#155 §9). Its slides sit under Presentation > Row and read as a design.
50
+ 'fig-deck': 'design',
47
51
  'fig-jam.': 'board',
48
52
  };
49
53
 
@@ -126,8 +130,37 @@ export interface FigDecodeReport {
126
130
  * known-lossy fields are named, never silently degraded.
127
131
  */
128
132
  lossyFields: Array<{ field: string; count: number; why: string }>;
133
+ /**
134
+ * Nodes that could not be read cleanly. One bad node no longer fails the
135
+ * whole file (#155 §5): it is degraded where there is a safe degradation and
136
+ * named here so the importer can print it. Bounded to `MAX_NODE_ERRORS`
137
+ * entries; `nodeErrorCount` is the true total.
138
+ */
139
+ nodeErrors: Array<{ nodeId: string; type: string; message: string }>;
140
+ nodeErrorCount: number;
141
+ /** Component instances expanded to their component's children (#155 §6), and why any were not. */
142
+ instances: InstanceReport;
143
+ }
144
+
145
+ export interface InstanceReport {
146
+ expanded: number;
147
+ /** Skipped: the component (transitively) contains an instance of itself. */
148
+ cycle: number;
149
+ /** Skipped or cut short: expanding would pass the node or depth cap. */
150
+ budget: number;
151
+ /** Skipped: the component the instance names is not in the file. */
152
+ missing: number;
153
+ /**
154
+ * Expanded, but the instance is a different size from its component: the
155
+ * children keep the component's own layout (the file's per-instance layout
156
+ * pass is not replayed), so they may not fill or fit the instance.
157
+ */
158
+ resized: number;
129
159
  }
130
160
 
161
+ /** Cap on the itemised node-error list — a hostile file cannot grow the report. */
162
+ export const MAX_NODE_ERRORS = 100;
163
+
131
164
  export interface FigDecodeResult {
132
165
  document: NormalizedDocument;
133
166
  report: FigDecodeReport;
@@ -362,6 +395,7 @@ function restType(change: Record<string, unknown>): string | undefined {
362
395
  */
363
396
  function toRestPaint(paint: unknown): unknown {
364
397
  const p = obj(paint);
398
+ if (p && Array.isArray(p.stops) && p.gradientStops === undefined) return toRestGradient(p);
365
399
  if (!p || p.imageRef !== undefined) return paint;
366
400
  const hash = obj(p.image)?.hash;
367
401
  if (!Array.isArray(hash) || hash.length === 0 || hash.length > 64) return paint;
@@ -374,6 +408,53 @@ function toRestPaint(paint: unknown): unknown {
374
408
  return { ...p, imageRef: hex };
375
409
  }
376
410
 
411
+ /**
412
+ * A `.fig` gradient paint -> the REST one. `.fig` says `stops` + a `transform`
413
+ * (node box -> gradient space); REST says `gradientStops` + three handle points
414
+ * in the node's own normalised box. The CSS lane reads the REST shape, so
415
+ * without this a `.fig` gradient reached the vector geometry but never the
416
+ * rectangle's `background` (#155 §4).
417
+ *
418
+ * The handles are gradient-space anchors carried back through
419
+ * `inverse(transform)`: linear = start / end / width, the rest = centre /
420
+ * x-radius / y-radius. A singular transform yields no handles (stops only), so
421
+ * the mapper falls back to a box-centred gradient rather than a guessed angle.
422
+ */
423
+ function toRestGradient(p: Record<string, unknown>): Record<string, unknown> {
424
+ const { stops, transform, ...rest } = p;
425
+ const out: Record<string, unknown> = { ...rest, gradientStops: stops };
426
+ const t = obj(transform);
427
+ const m00 = num(t?.m00) ?? 1;
428
+ const m01 = num(t?.m01) ?? 0;
429
+ const m02 = num(t?.m02) ?? 0;
430
+ const m10 = num(t?.m10) ?? 0;
431
+ const m11 = num(t?.m11) ?? 1;
432
+ const m12 = num(t?.m12) ?? 0;
433
+ const det = m00 * m11 - m01 * m10;
434
+ if (!Number.isFinite(det) || Math.abs(det) < 1e-9) return out;
435
+ const linear = str(p.type) === 'GRADIENT_LINEAR';
436
+ const anchors = linear
437
+ ? [
438
+ [0, 0.5],
439
+ [1, 0.5],
440
+ [0, 1],
441
+ ]
442
+ : [
443
+ [0.5, 0.5],
444
+ [1, 0.5],
445
+ [0.5, 1],
446
+ ];
447
+ const round = (v: number) => Math.round(v * 1e6) / 1e6 + 0;
448
+ const handles = anchors.map(([gx, gy]) => ({
449
+ x: round((m11 * gx - m01 * gy + (m01 * m12 - m11 * m02)) / det),
450
+ y: round((-m10 * gx + m00 * gy + (m10 * m02 - m00 * m12)) / det),
451
+ }));
452
+ if (handles.every((h) => Number.isFinite(h.x) && Number.isFinite(h.y))) {
453
+ out.gradientHandlePositions = handles;
454
+ }
455
+ return out;
456
+ }
457
+
377
458
  function overrides(change: Record<string, unknown>): unknown[] {
378
459
  const list = obj(change.nodeGenerationData)?.overrides;
379
460
  return Array.isArray(list) ? list : [];
@@ -554,16 +635,20 @@ function vectorOf(change: Record<string, unknown>, blobs: readonly unknown[]): V
554
635
  return null;
555
636
  }
556
637
 
557
- const paint = (Array.isArray(change.fillPaints) ? change.fillPaints : []).find(
558
- (p) => obj(p)?.type === 'SOLID' && obj(p)?.visible !== false
559
- );
638
+ // The first visible SOLID or GRADIENT fill. A gradient used to be skipped, so
639
+ // a gradient blob collapsed to no fill at all (#155 §10).
640
+ const paint = (Array.isArray(change.fillPaints) ? change.fillPaints : []).find((p) => {
641
+ const t = str(obj(p)?.type);
642
+ return (t === 'SOLID' || (t?.startsWith('GRADIENT_') ?? false)) && obj(p)?.visible !== false;
643
+ });
644
+ const gradient = gradientOf(obj(paint), obj(change.size));
560
645
  const colour = obj(obj(paint)?.color);
561
- const hex =
562
- colour === undefined
646
+ const hex = (c: Record<string, unknown> | undefined): string | null =>
647
+ c === undefined
563
648
  ? null
564
649
  : `#${(['r', 'g', 'b'] as const)
565
650
  .map((k) => {
566
- const v = num(colour[k]) ?? 0;
651
+ const v = num(c[k]) ?? 0;
567
652
  return Math.max(0, Math.min(255, Math.round(v * 255)))
568
653
  .toString(16)
569
654
  .padStart(2, '0');
@@ -572,7 +657,14 @@ function vectorOf(change: Record<string, unknown>, blobs: readonly unknown[]): V
572
657
 
573
658
  return {
574
659
  d,
575
- fill: hex,
660
+ // A gradient owns the fill; an ANGULAR one (no SVG equivalent) falls back
661
+ // to its first stop rather than to nothing.
662
+ fill: gradient
663
+ ? null
664
+ : str(obj(paint)?.type) === 'SOLID'
665
+ ? hex(colour)
666
+ : hex(obj(obj((obj(paint)?.stops as unknown[] | undefined)?.[0])?.color)),
667
+ ...(gradient ? { gradient } : {}),
576
668
  fillOpacity: num(obj(paint)?.opacity) ?? 1,
577
669
  fillRule: str(first?.windingRule) === 'EVENODD' ? 'evenodd' : 'nonzero',
578
670
  x: 0,
@@ -580,13 +672,86 @@ function vectorOf(change: Record<string, unknown>, blobs: readonly unknown[]): V
580
672
  };
581
673
  }
582
674
 
583
- interface RebuildResult {
675
+ /**
676
+ * A `.fig` gradient paint -> `VectorGradient`. `stops` (REST: `gradientStops`)
677
+ * and `transform` are the file's own names; `transform` maps the node's
678
+ * normalised box into gradient space, so `diag(size) * inverse(transform)`
679
+ * carries gradient space back to the node. LINEAR and RADIAL map exactly;
680
+ * DIAMOND is drawn as a radial one (the nearest SVG has); ANGULAR has no SVG
681
+ * equivalent and returns null. A singular transform also returns null, since
682
+ * guessing an orientation would draw a plausible wrong gradient.
683
+ */
684
+ function gradientOf(
685
+ paint: Record<string, unknown> | undefined,
686
+ size: Record<string, unknown> | undefined
687
+ ): VectorGradient | null {
688
+ const type = str(paint?.type);
689
+ const kind =
690
+ type === 'GRADIENT_LINEAR'
691
+ ? 'linear'
692
+ : type === 'GRADIENT_RADIAL' || type === 'GRADIENT_DIAMOND'
693
+ ? 'radial'
694
+ : null;
695
+ if (!kind || !Array.isArray(paint?.stops)) return null;
696
+
697
+ const stops: VectorGradient['stops'] = [];
698
+ for (const raw of (paint.stops as unknown[]).slice(0, 32)) {
699
+ const st = obj(raw);
700
+ const c = obj(st?.color);
701
+ const position = num(st?.position);
702
+ if (!c || position === undefined) continue;
703
+ const channel = (k: string) =>
704
+ Math.max(0, Math.min(255, Math.round((num(c[k]) ?? 0) * 255)))
705
+ .toString(16)
706
+ .padStart(2, '0');
707
+ stops.push({
708
+ offset: Math.max(0, Math.min(1, position)),
709
+ color: `#${channel('r')}${channel('g')}${channel('b')}`,
710
+ opacity: Math.max(0, Math.min(1, num(c.a) ?? 1)),
711
+ });
712
+ }
713
+ if (stops.length < 2) return null;
714
+
715
+ const t = obj(paint?.transform);
716
+ const m = {
717
+ m00: num(t?.m00) ?? 1,
718
+ m01: num(t?.m01) ?? 0,
719
+ m02: num(t?.m02) ?? 0,
720
+ m10: num(t?.m10) ?? 0,
721
+ m11: num(t?.m11) ?? 1,
722
+ m12: num(t?.m12) ?? 0,
723
+ };
724
+ const det = m.m00 * m.m11 - m.m01 * m.m10;
725
+ if (!Number.isFinite(det) || Math.abs(det) < 1e-9) return null;
726
+ // inverse(transform): gradient space -> normalised box.
727
+ const ia = m.m11 / det;
728
+ const ic = -m.m01 / det;
729
+ const ib = -m.m10 / det;
730
+ const id = m.m00 / det;
731
+ const ie = (m.m01 * m.m12 - m.m11 * m.m02) / det;
732
+ const iff = (m.m10 * m.m02 - m.m00 * m.m12) / det;
733
+ const w = num(size?.x) ?? 0;
734
+ const h = num(size?.y) ?? 0;
735
+ if (w <= 0 || h <= 0) return null;
736
+ // diag(size) * that: normalised box -> node space.
737
+ // `+ 0` folds a -0 (from negating a zero) into 0.
738
+ const matrix = [ia * w, ib * h, ic * w, id * h, ie * w, iff * h].map(
739
+ (v) => v + 0
740
+ ) as VectorGradient['matrix'];
741
+ if (!matrix.every(Number.isFinite)) return null;
742
+ return { kind, stops, matrix };
743
+ }
744
+
745
+ export interface RebuildResult {
584
746
  root: Record<string, unknown>;
585
747
  unmapped: Map<string, number>;
586
748
  internalSkipped: number;
587
749
  nodeCount: number;
588
750
  lossyLineHeights: number;
589
751
  vectors: Map<string, VectorPath>;
752
+ nodeErrors: Array<{ nodeId: string; type: string; message: string }>;
753
+ nodeErrorCount: number;
754
+ instances: InstanceReport;
590
755
  }
591
756
 
592
757
  /**
@@ -595,7 +760,7 @@ interface RebuildResult {
595
760
  * that the Kiwi decode-depth cap does not bound (A8/F4) — hence the explicit
596
761
  * cycle, duplicate, orphan and single-root controls here.
597
762
  */
598
- function rebuildTree(changes: unknown[], blobs: readonly unknown[]): RebuildResult {
763
+ export function rebuildTree(changes: unknown[], blobs: readonly unknown[]): RebuildResult {
599
764
  if (changes.length > MAX_NODE_COUNT) {
600
765
  throw new FigDecodeError(
601
766
  `file carries ${changes.length} nodes, over the ${MAX_NODE_COUNT} limit. Import a specific frame instead.`
@@ -659,6 +824,8 @@ function rebuildTree(changes: unknown[], blobs: readonly unknown[]): RebuildResu
659
824
  const onStack = new Set<string>();
660
825
  const vectors = new Map<string, VectorPath>();
661
826
  const lossy = { lineHeights: 0 };
827
+ const nodeErrors: RebuildResult['nodeErrors'] = [];
828
+ let nodeErrorCount = 0;
662
829
  let nodeCount = 0;
663
830
  let internalSkipped = 0;
664
831
 
@@ -671,14 +838,143 @@ function rebuildTree(changes: unknown[], blobs: readonly unknown[]): RebuildResu
671
838
  return n;
672
839
  };
673
840
 
674
- const build = (id: string, parentAbsolute: Matrix, depth: number): Record<string, unknown> => {
675
- // Cycle detection. A→B→A would otherwise recurse until the stack dies.
676
- if (onStack.has(id)) throw new FigDecodeError(`node parentage forms a cycle at ${id}`);
677
- onStack.add(id);
841
+ // ── INSTANCE expansion (#155 §6) ──
842
+ //
843
+ // An INSTANCE has no children in the file: it names a SYMBOL, and the symbol's
844
+ // children are what it draws. They are rebuilt under the instance with ids
845
+ // `I<instance>;<child>` (REST's own convention for a node inside an instance).
846
+ // Three controls bound it: a symbol already being expanded is a CYCLE and is
847
+ // skipped (A contains B contains A would otherwise recurse forever); the whole
848
+ // tree stays under the node cap, so a file with thousands of instances
849
+ // degrades instead of failing; and every skip is counted for the report.
850
+ const instances = { expanded: 0, cycle: 0, budget: 0, missing: 0, resized: 0 };
851
+ const expanding: string[] = [];
852
+ /**
853
+ * Headroom below the cap: the normalizer counts the same nodes and refuses
854
+ * past MAX_NODE_COUNT. Every ORIGINAL node is reserved up front (`changes`),
855
+ * so an early instance cannot starve the nodes still to come into a refusal.
856
+ */
857
+ const NODE_BUDGET = MAX_NODE_COUNT - 16;
858
+ let expandedNodes = 0;
859
+ const descendantMemo = new Map<string, number>();
860
+ /** Nodes under a component, nested instances not counted (they check their own budget). */
861
+ const descendantsOf = (symbolId: string): number => {
862
+ const known = descendantMemo.get(symbolId);
863
+ if (known !== undefined) return known;
864
+ let n = 0;
865
+ const stack = [...(childIds.get(symbolId) ?? [])];
866
+ const seen = new Set<string>();
867
+ while (stack.length > 0) {
868
+ const next = stack.pop() as string;
869
+ if (seen.has(next)) continue;
870
+ seen.add(next);
871
+ n++;
872
+ stack.push(...(childIds.get(next) ?? []));
873
+ }
874
+ descendantMemo.set(symbolId, n);
875
+ return n;
876
+ };
877
+ const DEPTH_BUDGET = MAX_TREE_DEPTH - 2;
878
+
879
+ interface Expansion {
880
+ /** The id a child gets before its own: `I2:14`, then `I2:14;5:5` for a nested instance. */
881
+ prefix: string;
882
+ /** Original-id path from the outermost instance down to the node being built. */
883
+ path: string[];
884
+ /** Overrides by path from the outermost instance. */
885
+ overrides: Map<string, Record<string, unknown>>;
886
+ }
678
887
 
679
- const change = byId.get(id) as Record<string, unknown>;
680
- const absolute = compose(parentAbsolute, matrixOf(change.transform));
888
+ /**
889
+ * The fields an instance override may change — a HARDCODED list (A8/F5): the
890
+ * override object is the file's, so its keys never choose what they touch.
891
+ */
892
+ const OVERRIDE_FIELDS = [
893
+ 'textData',
894
+ 'fillPaints',
895
+ 'strokePaints',
896
+ 'effects',
897
+ 'visible',
898
+ 'opacity',
899
+ 'fontSize',
900
+ 'fontName',
901
+ 'lineHeight',
902
+ 'textAlignHorizontal',
903
+ ] as const;
904
+
905
+ const pathKey = (path: readonly string[]) => path.join('/');
906
+
907
+ const overridesOf = (
908
+ change: Record<string, unknown>,
909
+ base: readonly string[],
910
+ into: Map<string, Record<string, unknown>>
911
+ ) => {
912
+ const list = obj(change.symbolData)?.symbolOverrides;
913
+ if (!Array.isArray(list)) return;
914
+ for (const entry of list.slice(0, 5000)) {
915
+ const o = obj(entry);
916
+ const guids = obj(o?.guidPath)?.guids;
917
+ if (!o || !Array.isArray(guids) || guids.length === 0 || guids.length > 16) continue;
918
+ const rel = guids.map(guidOf);
919
+ if (rel.some((x) => x === undefined)) continue;
920
+ const key = pathKey([...base, ...(rel as string[])]);
921
+ // The outer instance's override beats the inner one's own.
922
+ if (!into.has(key)) into.set(key, o);
923
+ }
924
+ };
925
+
926
+ const withOverride = (
927
+ change: Record<string, unknown>,
928
+ override: Record<string, unknown> | undefined
929
+ ): Record<string, unknown> => {
930
+ if (!override) return change;
931
+ const merged = { ...change };
932
+ for (const field of OVERRIDE_FIELDS) {
933
+ if (override[field] !== undefined) merged[field] = override[field];
934
+ }
935
+ return merged;
936
+ };
937
+
938
+ const build = (
939
+ id: string,
940
+ parentAbsolute: Matrix,
941
+ depth: number,
942
+ x?: Expansion
943
+ ): Record<string, unknown> => {
944
+ // The id this node carries in the output: inside an instance it is the
945
+ // instance's path. Cycle detection keys on it, because the SAME original
946
+ // node is legitimately built once per instance.
947
+ const outId = x ? `${x.prefix};${id}` : id;
948
+ // Cycle detection. A→B→A would otherwise recurse until the stack dies.
949
+ if (onStack.has(outId)) throw new FigDecodeError(`node parentage forms a cycle at ${id}`);
950
+ onStack.add(outId);
951
+
952
+ const original = byId.get(id) as Record<string, unknown>;
953
+ const change = x ? withOverride(original, x.overrides.get(pathKey(x.path))) : original;
954
+ // ONE bad node must not fail the file (#155 §5). An unreadable transform
955
+ // places the node at its parent's origin (the identity) — and says so in
956
+ // `report.nodeErrors`, so it is never the silent plausible-but-wrong
957
+ // placement the old hard refusal existed to prevent.
958
+ let local: Matrix;
959
+ try {
960
+ local = matrixOf(change.transform);
961
+ } catch (err) {
962
+ local = IDENTITY;
963
+ nodeErrorCount++;
964
+ if (nodeErrors.length < MAX_NODE_ERRORS) {
965
+ nodeErrors.push({
966
+ nodeId: id,
967
+ type: reportToken(str(change.type) ?? ''),
968
+ message: String((err as Error).message).slice(0, 200),
969
+ });
970
+ }
971
+ }
972
+ const absolute = compose(parentAbsolute, local);
681
973
  const node = toRestNode(change, absolute, lossy);
974
+ if (x) {
975
+ node.id = outId;
976
+ expandedNodes++;
977
+ }
682
978
  nodeCount++;
683
979
 
684
980
  const art = vectorOf(change, blobs);
@@ -699,22 +995,78 @@ function rebuildTree(changes: unknown[], blobs: readonly unknown[]): RebuildResu
699
995
  unmapped.set(label, (unmapped.get(label) ?? 0) + 1);
700
996
  }
701
997
 
702
- const kids = childIds.get(id);
703
- if (kids?.length) {
998
+ // A component being built in place is "being expanded" too: an instance of
999
+ // it inside itself is a cycle.
1000
+ const isSymbol = str(original.type) === 'SYMBOL';
1001
+ if (isSymbol && !x) expanding.push(id);
1002
+
1003
+ const buildKids = (parentId: string, ex?: Expansion) => {
704
1004
  const kept: Array<Record<string, unknown>> = [];
705
- for (const kid of kids) {
1005
+ for (const kid of childIds.get(parentId) ?? []) {
706
1006
  // Prune Figma's internal-only nodes as WHOLE SUBTREES here, where the
707
1007
  // parentage is already resolved, rather than dropping them up front.
708
1008
  if (byId.get(kid)?.internalOnly === true) {
709
1009
  internalSkipped += countSubtree(kid, new Set());
710
1010
  continue;
711
1011
  }
712
- kept.push(build(kid, absolute, depth + 1));
1012
+ if (ex) {
1013
+ // Expansions respect the budget at every node, so a deep or wide
1014
+ // component cannot run past the cap the normalizer enforces.
1015
+ if (expandedNodes + changes.length >= NODE_BUDGET || depth + 1 > DEPTH_BUDGET) {
1016
+ instances.budget++;
1017
+ continue;
1018
+ }
1019
+ kept.push(build(kid, absolute, depth + 1, { ...ex, path: [...ex.path, kid] }));
1020
+ } else {
1021
+ kept.push(build(kid, absolute, depth + 1));
1022
+ }
713
1023
  }
1024
+ return kept;
1025
+ };
1026
+
1027
+ const kids = childIds.get(id);
1028
+ if (kids?.length) {
1029
+ const kept = buildKids(id, x ? { ...x } : undefined);
714
1030
  if (kept.length > 0) node.children = kept;
1031
+ } else if (str(original.type) === 'INSTANCE') {
1032
+ const symbolId = guidOf(obj(original.symbolData)?.symbolID);
1033
+ const symbol = symbolId === undefined ? undefined : byId.get(symbolId);
1034
+ if (symbolId === undefined || !symbol) {
1035
+ instances.missing++;
1036
+ } else if (expanding.includes(symbolId)) {
1037
+ instances.cycle++;
1038
+ } else if (
1039
+ depth + 1 > DEPTH_BUDGET ||
1040
+ expandedNodes + descendantsOf(symbolId) + changes.length > NODE_BUDGET
1041
+ ) {
1042
+ instances.budget++;
1043
+ } else {
1044
+ const overrides = new Map(x?.overrides ?? []);
1045
+ const here = x ? [...x.path] : [];
1046
+ overridesOf(change, here, overrides);
1047
+ expanding.push(symbolId);
1048
+ const kept = buildKids(symbolId, {
1049
+ // REST's spelling: `I<instance>;<child>`, and nested instances extend it.
1050
+ prefix: x ? outId : `I${outId}`,
1051
+ path: here,
1052
+ overrides,
1053
+ });
1054
+ expanding.pop();
1055
+ instances.expanded++;
1056
+ const isz = obj(original.size);
1057
+ const ssz = obj(symbol.size);
1058
+ if (
1059
+ Math.abs((num(isz?.x) ?? 0) - (num(ssz?.x) ?? 0)) > 0.5 ||
1060
+ Math.abs((num(isz?.y) ?? 0) - (num(ssz?.y) ?? 0)) > 0.5
1061
+ ) {
1062
+ instances.resized++;
1063
+ }
1064
+ if (kept.length > 0) node.children = kept;
1065
+ }
715
1066
  }
716
1067
 
717
- onStack.delete(id);
1068
+ if (isSymbol && !x) expanding.pop();
1069
+ onStack.delete(outId);
718
1070
  return node;
719
1071
  };
720
1072
 
@@ -729,6 +1081,9 @@ function rebuildTree(changes: unknown[], blobs: readonly unknown[]): RebuildResu
729
1081
  nodeCount,
730
1082
  lossyLineHeights: lossy.lineHeights,
731
1083
  vectors,
1084
+ nodeErrors,
1085
+ nodeErrorCount,
1086
+ instances,
732
1087
  };
733
1088
  }
734
1089
 
@@ -777,10 +1132,17 @@ export function decodeFigArchive(archive: Uint8Array, opts: DecodeFigOptions): F
777
1132
  }
778
1133
 
779
1134
  const blobs = Array.isArray(message?.blobs) ? message.blobs : [];
780
- const { root, unmapped, internalSkipped, nodeCount, lossyLineHeights, vectors } = rebuildTree(
781
- changes,
782
- blobs
783
- );
1135
+ const {
1136
+ root,
1137
+ unmapped,
1138
+ internalSkipped,
1139
+ nodeCount,
1140
+ lossyLineHeights,
1141
+ vectors,
1142
+ nodeErrors,
1143
+ nodeErrorCount,
1144
+ instances,
1145
+ } = rebuildTree(changes, blobs);
784
1146
 
785
1147
  const document = normalizeDocument(root, {
786
1148
  fileKey: opts.fileKey,
@@ -802,6 +1164,9 @@ export function decodeFigArchive(archive: Uint8Array, opts: DecodeFigOptions): F
802
1164
  .sort((a, b) => b.count - a.count),
803
1165
  internalNodesSkipped: internalSkipped,
804
1166
  lossyFields: lossyLineHeights > 0 ? [{ ...LOSSY_LINE_HEIGHT, count: lossyLineHeights }] : [],
1167
+ nodeErrors,
1168
+ nodeErrorCount,
1169
+ instances,
805
1170
  },
806
1171
  };
807
1172
  }
@@ -115,17 +115,30 @@ class Reader {
115
115
  return v & 1 ? ~(v >>> 1) : v >>> 1;
116
116
  }
117
117
 
118
+ /**
119
+ * Kiwi's 64-bit varuint: 7 bits per byte with a continuation flag for the
120
+ * first EIGHT bytes, then a NINTH byte that carries a full 8 bits (it has no
121
+ * continuation flag — 8 x 7 + 8 = 64). Reading it as plain LEB128 treated that
122
+ * last byte's top bit as "more follows" and walked into the next field, which
123
+ * surfaced as `malformed varuint64: more than 10 bytes` on any value >= 2^63
124
+ * (#155 §10).
125
+ */
118
126
  varuint64(): bigint {
119
127
  let value = 0n;
120
128
  let shift = 0n;
121
- for (;;) {
129
+ for (let i = 0; i < 8; i++) {
122
130
  const b = this.byte();
123
131
  value |= BigInt(b & 0x7f) << shift;
132
+ if ((b & 0x80) === 0) return value;
124
133
  shift += 7n;
125
- if ((b & 0x80) === 0) break;
126
- if (shift > 63n) throw new FigKiwiError('malformed varuint64: more than 10 bytes');
127
134
  }
128
- return value;
135
+ return value | (BigInt(this.byte()) << 56n);
136
+ }
137
+
138
+ /** Zig-zag signed form of `varuint64`, same as `varint()` is of `varuint()`. */
139
+ varint64(): bigint {
140
+ const v = this.varuint64();
141
+ return v & 1n ? ~(v >> 1n) : v >> 1n;
129
142
  }
130
143
 
131
144
  /**
@@ -336,6 +349,7 @@ function readValue(
336
349
  case TYPE_STRING:
337
350
  return r.string();
338
351
  case TYPE_INT64:
352
+ return r.varint64();
339
353
  case TYPE_UINT64:
340
354
  return r.varuint64();
341
355
  default:
@@ -101,11 +101,26 @@ export function pathFromBlob(bytes: Uint8Array): string {
101
101
  return parts.join(' ');
102
102
  }
103
103
 
104
+ /**
105
+ * A gradient fill (#155 §10) — without it a gradient blob collapsed to no fill
106
+ * at all. `matrix` is an SVG matrix `[a b c d e f]` mapping Figma's GRADIENT
107
+ * space (where a linear gradient runs along x from 0 to 1 and a radial one is
108
+ * the circle of radius 0.5 around (0.5, 0.5)) into the node's own space, i.e.
109
+ * `diag(size) * inverse(paint.transform)`.
110
+ */
111
+ export interface VectorGradient {
112
+ kind: 'linear' | 'radial';
113
+ stops: Array<{ offset: number; color: string; opacity: number }>;
114
+ matrix: [number, number, number, number, number, number];
115
+ }
116
+
104
117
  export interface VectorPath {
105
118
  /** SVG `d`, in the owning node's own coordinate space. */
106
119
  d: string;
107
120
  /** `#rrggbb` of the first visible solid fill, or null when there is none. */
108
121
  fill: string | null;
122
+ /** Set when the first visible fill is a gradient; `fill` is then null. */
123
+ gradient?: VectorGradient;
109
124
  fillOpacity: number;
110
125
  /** `nonzero` | `evenodd`, straight from the geometry record. */
111
126
  fillRule: string;
@@ -133,13 +148,54 @@ export interface VectorArt {
133
148
  export function artToSvg(art: VectorArt): string {
134
149
  const w = Math.max(1, Math.round(art.width));
135
150
  const h = Math.max(1, Math.round(art.height));
151
+ const defs: string[] = [];
136
152
  const body = art.paths
137
- .map((p) => {
153
+ .map((p, i) => {
138
154
  const transform = p.x !== 0 || p.y !== 0 ? ` transform="translate(${n(p.x)} ${n(p.y)})"` : '';
139
155
  const opacity = p.fillOpacity < 1 ? ` fill-opacity="${n(p.fillOpacity)}"` : '';
140
156
  const rule = p.fillRule === 'evenodd' ? ' fill-rule="evenodd"' : '';
141
- return `<path d="${p.d}" fill="${p.fill ?? 'none'}"${opacity}${rule}${transform}/>`;
157
+ let fill = p.fill ?? 'none';
158
+ if (p.gradient) {
159
+ defs.push(gradientDef(`g${i}`, p.gradient, w));
160
+ fill = `url(#g${i})`;
161
+ }
162
+ return `<path d="${p.d}" fill="${fill}"${opacity}${rule}${transform}/>`;
142
163
  })
143
164
  .join('');
144
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" fill="none">${body}</svg>`;
165
+ const defsEl = defs.length > 0 ? `<defs>${defs.join('')}</defs>` : '';
166
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" fill="none">${defsEl}${body}</svg>`;
167
+ }
168
+
169
+ /** Matrix terms need more precision than a coordinate: a/width is ~0.004. */
170
+ function fine(v: number): string {
171
+ if (!Number.isFinite(v)) throw new FigVectorError('gradient matrix is not finite');
172
+ const r = Math.round(v * 1e6) / 1e6;
173
+ return Object.is(r, -0) ? '0' : String(r);
174
+ }
175
+
176
+ /**
177
+ * One gradient definition, written ONLY with attributes the DDR-167 allowlist
178
+ * keeps (`x1`..`y2` are not among them, so they are never relied on).
179
+ *
180
+ * userSpaceOnUse with a `gradientTransform`. A radial gradient is the unit
181
+ * circle in gradient space (`cx`/`cy`/`r` survive the sanitizer). A linear one
182
+ * needs its vector to be the SVG DEFAULT — (0,0) to (viewport width, 0) — so
183
+ * that, if the sanitizer strips the explicit `x1`..`y2` written here, the
184
+ * result is identical; the matrix is therefore scaled by 1/width.
185
+ */
186
+ function gradientDef(id: string, g: VectorGradient, viewportWidth: number): string {
187
+ const stops = g.stops
188
+ .map(
189
+ (s) =>
190
+ `<stop offset="${n(s.offset)}" stop-color="${s.color}"${s.opacity < 1 ? ` stop-opacity="${n(s.opacity)}"` : ''}/>`
191
+ )
192
+ .join('');
193
+ const [a, b, c, d, e, f] = g.matrix;
194
+ if (g.kind === 'radial') {
195
+ const m = [a, b, c, d, e, f].map(fine).join(' ');
196
+ return `<radialGradient id="${id}" cx="0.5" cy="0.5" r="0.5" gradientUnits="userSpaceOnUse" gradientTransform="matrix(${m})">${stops}</radialGradient>`;
197
+ }
198
+ const k = 1 / viewportWidth;
199
+ const m = [a * k, b * k, c * k, d * k, e, f].map(fine).join(' ');
200
+ return `<linearGradient id="${id}" x1="0" y1="0" x2="${viewportWidth}" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(${m})">${stops}</linearGradient>`;
145
201
  }
@@ -80,6 +80,8 @@ export const DISPOSITIONS = Object.freeze([
80
80
  'asset-unavailable-offline',
81
81
  'jsx-cap-reached',
82
82
  'value-rejected',
83
+ /** A paint or effect CSS has no exact twin for (diamond gradient, a blend mode), drawn by the nearest one. */
84
+ 'paint-approximated',
83
85
  // ── The codegen route (DDR-219 D9). Three dispositions, one rule: what makes
84
86
  // them safe is that `detail` carries a BOUNDED token plus a count, never the
85
87
  // upstream family or utility name verbatim — `detail` is the one field on the