@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
@@ -0,0 +1,602 @@
1
+ // edit-ops/clip-carry.ts — #122 (122-A): the object clipboard carries what the copy reads.
2
+ // Contract: client/v2/contracts/122-cross-canvas-clipboard.md §5.1 (the clip) + §5.2 (paste rules).
3
+ //
4
+ // A copied object or artboard reads names from around it: a module-level `const W = 1440`, a same-file
5
+ // `function Pill`, an imported `<Card>`. Pasted on another canvas without them it renders an error card. So:
6
+ //
7
+ // carryOf(source, ranges, from) at COPY time: every import and module-level declaration the ranges read
8
+ // (identifiers, JSX tag roots, type references — `freeRefsOf`), transitively,
9
+ // declarations in dependency order. Function-scope names (props, hook state)
10
+ // and what can not travel (`let` / `var`, an enum, a destructured const, the
11
+ // default export, anything naming DesignCanvas) stay `needs` (refused elsewhere).
12
+ // planCarry(target, at, …) at PASTE time on another canvas: add what the target lacks, reuse what is
13
+ // identical, rename what clashes (`W` → `W2`, `Card as Card2`), re-point
14
+ // relative imports from the target's folder. Every import it ADDS passes the
15
+ // C4 import rule (`importAllowed`, access/closure.ts) — never a canvas, never a
16
+ // `_` runtime file, only importable extensions, resolving — or nothing is written.
17
+ // renameRefs(text, renames) the copied text's own references to a renamed name, and nothing else.
18
+ //
19
+ // The module behind a carried import is never copied (contract §4.2). Pure: text in, text out; files are read
20
+ // only through the reader the dispatcher hands the op (`req.readFile`), at clamped designRoot-relative paths.
21
+
22
+ import path from 'node:path';
23
+
24
+ import MagicString from 'magic-string';
25
+
26
+ import {
27
+ importAllowed,
28
+ perUsePhotoRefs,
29
+ specCandidates,
30
+ staticAssetRefs,
31
+ } from '../access/closure.ts';
32
+ import {
33
+ type FreeRef,
34
+ freeRefsIn,
35
+ functionScopeAt,
36
+ type ScopeModule,
37
+ scopeModule,
38
+ } from './scope-names.ts';
39
+
40
+ /**
41
+ * The file kinds a clip may carry as an asset: pictures, video, sound and fonts — never code, styles, data or a
42
+ * document (those could become a module or a canvas in the other project). Mirrored in Rust `clip_bridge.rs`
43
+ * `MEDIA_EXT`. An SVG also has to be what the import-asset sanitizer leaves (shell/clip-transfer.ts).
44
+ */
45
+ export const CLIP_MEDIA_EXT = [
46
+ 'png',
47
+ 'jpg',
48
+ 'jpeg',
49
+ 'gif',
50
+ 'webp',
51
+ 'avif',
52
+ 'svg',
53
+ 'mp4',
54
+ 'mov',
55
+ 'm4v',
56
+ 'webm',
57
+ 'mp3',
58
+ 'm4a',
59
+ 'wav',
60
+ 'ogg',
61
+ 'aac',
62
+ 'woff',
63
+ 'woff2',
64
+ 'ttf',
65
+ 'otf',
66
+ ] as const;
67
+ const MEDIA_RE = new RegExp(`\\.(?:${CLIP_MEDIA_EXT.join('|')})$`);
68
+
69
+ /** `assets/….<media ext>` (lower-case extension). */
70
+ export const isClipMedia = (rel: string): boolean => MEDIA_RE.test(rel);
71
+
72
+ export interface Carry {
73
+ /** source order */
74
+ imports: CarriedImport[];
75
+ /** module-level, dependency order (a declaration after what it reads) */
76
+ decls: CarriedDecl[];
77
+ /** `assets/<sha8>.<ext>` (+ `.photo.json` sidecars) the items name */
78
+ assets: string[];
79
+ }
80
+
81
+ export interface CarriedImport {
82
+ /** the name the items use */
83
+ local: string;
84
+ /** what the module exports under it */
85
+ imported: string;
86
+ /** as written in the source */
87
+ spec: string;
88
+ /** designRoot-relative resolved file; null = bare / virtual (`react`, `@maude/canvas-lib`) */
89
+ module: string | null;
90
+ typeOnly?: boolean;
91
+ }
92
+
93
+ export interface CarriedDecl {
94
+ name: string;
95
+ /** the whole top-level statement, `export` dropped (one declarator of a `const a = 1, b = 2`) */
96
+ text: string;
97
+ kind: 'const' | 'function' | 'class' | 'type';
98
+ }
99
+
100
+ /** Imports + declarations one clip may carry (contract §5.1). */
101
+ export const MAX_CARRIED = 32;
102
+ export const NO_CARRY: Carry = Object.freeze({ imports: [], decls: [], assets: [] }) as Carry;
103
+ export const TOO_MUCH_TO_CARRY =
104
+ 'That copy reads too much from its canvas to paste on another one; copy the whole component instead.';
105
+
106
+ /** designRoot-relative text of a project file; null = no such file. */
107
+ export interface ModuleReader {
108
+ text(rel: string): string | null;
109
+ }
110
+
111
+ type Node = { type: string; start: number; end: number; [k: string]: unknown };
112
+ const isNode = (v: unknown): v is Node =>
113
+ v !== null && typeof v === 'object' && typeof (v as Node).type === 'string';
114
+
115
+ // ── the module's own bindings ───────────────────────────────────────────────────────────────────
116
+
117
+ interface ImportBinding {
118
+ kind: 'import';
119
+ local: string;
120
+ imported: string;
121
+ spec: string;
122
+ typeOnly: boolean;
123
+ decl: Node;
124
+ }
125
+ interface DeclBinding {
126
+ kind: 'decl';
127
+ name: string;
128
+ /** null = can not travel (a `let`, the default export, …) */
129
+ text: string | null;
130
+ declKind: CarriedDecl['kind'];
131
+ /** the range its own reads are asked over */
132
+ start: number;
133
+ end: number;
134
+ /** the end of its whole top-level statement */
135
+ stmtEnd: number;
136
+ }
137
+ interface Table {
138
+ bindings: Map<string, ImportBinding | DeclBinding>;
139
+ imports: ImportBinding[];
140
+ lastImportEnd: number;
141
+ }
142
+
143
+ const nameOf = (n: unknown): string =>
144
+ isNode(n) ? String(n.type === 'Literal' ? n.value : n.name) : '';
145
+
146
+ /** The names a binding pattern declares (`const { a, b: [c] } = …`). */
147
+ function bindingNames(p: unknown, out: string[]): void {
148
+ if (!isNode(p)) return;
149
+ if (p.type === 'Identifier') out.push(String(p.name));
150
+ else if (p.type === 'ObjectPattern')
151
+ for (const prop of (p.properties as unknown[]) ?? [])
152
+ bindingNames(
153
+ isNode(prop) && prop.type === 'RestElement' ? prop.argument : (prop as Node)?.value,
154
+ out
155
+ );
156
+ else if (p.type === 'ArrayPattern')
157
+ for (const e of (p.elements as unknown[]) ?? []) bindingNames(e, out);
158
+ else if (p.type === 'RestElement') bindingNames(p.argument, out);
159
+ else if (p.type === 'AssignmentPattern') bindingNames(p.left, out);
160
+ }
161
+
162
+ const NAMES_CANVAS = /\bDesignCanvas\b/;
163
+
164
+ function tableOf(mod: ScopeModule): Table {
165
+ const program = mod.program as Node;
166
+ const source = mod.source;
167
+ const bindings = new Map<string, ImportBinding | DeclBinding>();
168
+ const imports: ImportBinding[] = [];
169
+ let lastImportEnd = 0;
170
+ for (const st of (program.body as Node[]) ?? []) {
171
+ if (st.type === 'ImportDeclaration') {
172
+ lastImportEnd = st.end;
173
+ const spec = String((st.source as Node).value);
174
+ for (const s of (st.specifiers as Node[]) ?? []) {
175
+ const b: ImportBinding = {
176
+ kind: 'import',
177
+ local: nameOf(s.local),
178
+ imported:
179
+ s.type === 'ImportDefaultSpecifier'
180
+ ? 'default'
181
+ : s.type === 'ImportNamespaceSpecifier'
182
+ ? '*'
183
+ : nameOf(s.imported),
184
+ spec,
185
+ typeOnly: st.importKind === 'type' || s.importKind === 'type',
186
+ decl: st,
187
+ };
188
+ imports.push(b);
189
+ bindings.set(b.local, b);
190
+ }
191
+ continue;
192
+ }
193
+ const isDefault = st.type === 'ExportDefaultDeclaration';
194
+ const inner = st.type === 'ExportNamedDeclaration' || isDefault ? st.declaration : st;
195
+ if (!isNode(inner)) continue;
196
+ const add = (
197
+ name: string,
198
+ text: string | null,
199
+ declKind: CarriedDecl['kind'],
200
+ start: number,
201
+ end: number
202
+ ) => {
203
+ if (!name || bindings.has(name)) return;
204
+ const travels = text !== null && !isDefault && !NAMES_CANVAS.test(text);
205
+ bindings.set(name, {
206
+ kind: 'decl',
207
+ name,
208
+ text: travels ? text : null,
209
+ declKind,
210
+ start,
211
+ end,
212
+ stmtEnd: st.end,
213
+ });
214
+ };
215
+ const whole = () => (inner.declare ? null : source.slice(inner.start, inner.end));
216
+ switch (inner.type) {
217
+ case 'VariableDeclaration': {
218
+ const travels = inner.kind === 'const' && !inner.declare;
219
+ for (const d of (inner.declarations as Node[]) ?? []) {
220
+ const id = d.id as Node;
221
+ if (travels && id.type === 'Identifier' && isNode(d.init))
222
+ add(String(id.name), `const ${source.slice(d.start, d.end)};`, 'const', d.start, d.end);
223
+ else {
224
+ const names: string[] = [];
225
+ bindingNames(id, names);
226
+ for (const n of names) add(n, null, 'const', d.start, d.end);
227
+ }
228
+ }
229
+ break;
230
+ }
231
+ case 'FunctionDeclaration':
232
+ add(
233
+ nameOf(inner.id),
234
+ isNode(inner.body) ? whole() : null,
235
+ 'function',
236
+ inner.start,
237
+ inner.end
238
+ );
239
+ break;
240
+ case 'ClassDeclaration':
241
+ add(nameOf(inner.id), whole(), 'class', inner.start, inner.end);
242
+ break;
243
+ case 'TSTypeAliasDeclaration':
244
+ case 'TSInterfaceDeclaration':
245
+ add(nameOf(inner.id), source.slice(inner.start, inner.end), 'type', inner.start, inner.end);
246
+ break;
247
+ case 'TSEnumDeclaration':
248
+ add(nameOf(inner.id), null, 'const', inner.start, inner.end);
249
+ break;
250
+ default:
251
+ }
252
+ }
253
+ return { bindings, imports, lastImportEnd };
254
+ }
255
+
256
+ // ── specifiers ──────────────────────────────────────────────────────────────────────────────────
257
+
258
+ const VROOT = '/__maude_carry__';
259
+
260
+ /** A relative specifier written in `fromRel`, as a designRoot-relative path (unresolved: no extension probing). */
261
+ const baseOf = (spec: string, fromRel: string): string =>
262
+ path.posix.normalize(path.posix.join(path.posix.dirname(fromRel), spec));
263
+
264
+ /** The file a relative specifier resolves to (the first candidate the reader has), else its base path. */
265
+ function moduleOf(spec: string, fromRel: string, reader?: ModuleReader): string | null {
266
+ if (!spec.startsWith('.')) return null;
267
+ if (reader)
268
+ for (const abs of specCandidates(spec, `${VROOT}/${fromRel}`, VROOT)) {
269
+ const rel = abs
270
+ .slice(VROOT.length + 1)
271
+ .split(path.sep)
272
+ .join('/');
273
+ if (reader.text(rel) !== null) return rel;
274
+ }
275
+ return baseOf(spec, fromRel);
276
+ }
277
+
278
+ /** `spec` (written in `fromRel`) as written from `toRel`'s folder: `./`-prefixed, the extension kept. */
279
+ export function respec(spec: string, fromRel: string, toRel: string): string {
280
+ if (!spec.startsWith('.')) return spec;
281
+ const target = path.posix.join(path.posix.dirname(fromRel), spec);
282
+ let rel = path.posix.relative(path.posix.dirname(toRel), target);
283
+ if (spec.endsWith('/') && !rel.endsWith('/')) rel += '/';
284
+ return rel.startsWith('.') ? rel : `./${rel || '.'}`;
285
+ }
286
+
287
+ const importKey = (spec: string, module: string | null): string =>
288
+ spec.startsWith('.') ? `file:${module ?? ''}` : `bare:${spec}`;
289
+
290
+ // ── the copy ────────────────────────────────────────────────────────────────────────────────────
291
+
292
+ export interface CarryRead {
293
+ carry: Carry;
294
+ /** names the copy reads that can not travel: a function's (props, state), a `let`, the default export */
295
+ needs: string[];
296
+ /** set when the carry is too big to keep: a paste on another canvas is refused with these words */
297
+ refused: string | null;
298
+ }
299
+
300
+ /**
301
+ * What the ranges `[from, to)` of `source` (a canvas at `fromRel`) read from around them. `texts` are the clip
302
+ * items as kept (their asset references ride too). Null when the source does not parse.
303
+ */
304
+ export function carryOf(
305
+ source: string,
306
+ ranges: ReadonlyArray<readonly [number, number]>,
307
+ fromRel: string,
308
+ texts: readonly string[],
309
+ reader?: ModuleReader
310
+ ): CarryRead | null {
311
+ const mod = scopeModule(source);
312
+ if (!mod) return null;
313
+ const table = tableOf(mod);
314
+ const needs = new Set<string>();
315
+ const imports = new Map<string, CarriedImport>();
316
+ const decls: CarriedDecl[] = [];
317
+ const visited = new Set<string>();
318
+ const want = (r: FreeRef): void => {
319
+ if (r.scope === 'function') {
320
+ needs.add(r.name);
321
+ return;
322
+ }
323
+ if (r.scope === 'global') return;
324
+ const b = table.bindings.get(r.name);
325
+ if (!b) {
326
+ needs.add(r.name);
327
+ return;
328
+ }
329
+ if (b.kind === 'import') {
330
+ if (!imports.has(b.local))
331
+ imports.set(b.local, {
332
+ local: b.local,
333
+ imported: b.imported,
334
+ spec: b.spec,
335
+ module: moduleOf(b.spec, fromRel, reader),
336
+ ...(b.typeOnly ? { typeOnly: true } : {}),
337
+ });
338
+ return;
339
+ }
340
+ if (b.text === null) {
341
+ needs.add(b.name);
342
+ return;
343
+ }
344
+ if (visited.has(b.name)) return;
345
+ visited.add(b.name);
346
+ for (const d of freeRefsIn(mod, b.start, b.end)) if (d.name !== b.name) want(d);
347
+ decls.push({ name: b.name, text: b.text, kind: b.declKind });
348
+ };
349
+ for (const [from, to] of ranges) for (const r of freeRefsIn(mod, from, to)) want(r);
350
+ const order = [...imports.values()].sort(
351
+ (a, b) =>
352
+ (table.bindings.get(a.local) as ImportBinding).decl.start -
353
+ (table.bindings.get(b.local) as ImportBinding).decl.start
354
+ );
355
+ if (order.length + decls.length > MAX_CARRIED)
356
+ return { carry: NO_CARRY, needs: [...needs].sort(), refused: TOO_MUCH_TO_CARRY };
357
+ return {
358
+ carry: {
359
+ imports: order,
360
+ decls,
361
+ assets: assetsOf([...texts, ...decls.map((d) => d.text)], reader),
362
+ },
363
+ needs: [...needs].sort(),
364
+ refused: null,
365
+ };
366
+ }
367
+
368
+ /**
369
+ * The `assets/…` files the texts name, and the `.photo.json` sidecars the reader has (small JSON). The pictures
370
+ * themselves are named, not read here (a cross-project import verifies their bytes, contract §5.6).
371
+ */
372
+ function assetsOf(texts: readonly string[], reader?: ModuleReader): string[] {
373
+ const out = new Set<string>();
374
+ for (const t of texts) {
375
+ for (const ref of staticAssetRefs(t)) {
376
+ const rel = ref.replace(/^(?:\.\.?\/|\.design\/|\/)+/, '');
377
+ if (!rel.startsWith('assets/') || rel.split('/').includes('..') || !isClipMedia(rel))
378
+ continue;
379
+ out.add(rel);
380
+ const photo = rel.replace(/\.[^./]+$/, '.photo.json');
381
+ if (reader && photo !== rel && reader.text(photo) !== null) out.add(photo);
382
+ }
383
+ for (const rel of perUsePhotoRefs(t)) if (!reader || reader.text(rel) !== null) out.add(rel);
384
+ }
385
+ return [...out].sort();
386
+ }
387
+
388
+ // ── the paste ───────────────────────────────────────────────────────────────────────────────────
389
+
390
+ /** `detail.carried` (contract §5.2). */
391
+ export interface CarriedSummary {
392
+ imports: number;
393
+ decls: number;
394
+ renamed: Array<{ from: string; to: string }>;
395
+ }
396
+
397
+ export interface CarryPlan {
398
+ /** the copied text's names → the names they have here */
399
+ renames: ReadonlyMap<string, string>;
400
+ /** writes the added imports and declarations into the target's MagicString */
401
+ apply(s: MagicString): void;
402
+ carried: CarriedSummary;
403
+ }
404
+
405
+ const normal = (t: string) => t.replace(/\s+/g, ' ').replace(/;\s*$/, '').trim();
406
+ const IDENT_RE = /^[A-Za-z_$][\w$]*$/;
407
+
408
+ /**
409
+ * The plan for pasting a clip read from `fromRel` at `at` in `target` (another canvas, `targetRel`). `what`
410
+ * names the copy in a refusal ("object" / "artboard"); `fail` throws it (nothing is written).
411
+ */
412
+ export function planCarry(
413
+ target: string,
414
+ at: number,
415
+ carry: Carry,
416
+ fromRel: string,
417
+ targetRel: string,
418
+ what: string,
419
+ reader: ModuleReader | undefined,
420
+ fail: (message: string) => never
421
+ ): CarryPlan {
422
+ const mod = scopeModule(target);
423
+ if (!mod) return fail('This canvas does not parse; fix it before editing.');
424
+ const table = tableOf(mod);
425
+ const shadow = functionScopeAt(target, at) ?? new Set<string>();
426
+ const taken = new Set<string>([...table.bindings.keys(), ...shadow]);
427
+ const reserved = new Set<string>([
428
+ ...carry.imports.map((i) => i.local),
429
+ ...carry.decls.map((d) => d.name),
430
+ ]);
431
+ const fresh = (base: string): string => {
432
+ let n = 2;
433
+ while (taken.has(`${base}${n}`) || reserved.has(`${base}${n}`)) n++;
434
+ return `${base}${n}`;
435
+ };
436
+ const renames = new Map<string, string>();
437
+ const renamed: Array<{ from: string; to: string }> = [];
438
+ const read: ModuleReader = reader ?? { text: () => null };
439
+
440
+ // imports: reuse, alias, join an import of the same module, or a new line
441
+ const targetImports = table.imports.map((b) => ({
442
+ b,
443
+ key: importKey(b.spec, moduleOf(b.spec, targetRel, reader)),
444
+ }));
445
+ const joins: Array<{ at: number; text: string }> = [];
446
+ const lines = new Map<
447
+ string,
448
+ { spec: string; def?: string; ns?: string; named: string[]; type: boolean }
449
+ >();
450
+ let added = 0;
451
+ for (const ci of carry.imports) {
452
+ const key = importKey(
453
+ ci.spec,
454
+ ci.module ?? (ci.spec.startsWith('.') ? baseOf(ci.spec, fromRel) : null)
455
+ );
456
+ const same = targetImports.find(
457
+ (t) => t.key === key && t.b.imported === ci.imported && (!t.b.typeOnly || ci.typeOnly)
458
+ );
459
+ if (same && !shadow.has(same.b.local)) {
460
+ if (same.b.local !== ci.local) renames.set(ci.local, same.b.local);
461
+ continue;
462
+ }
463
+ let local = ci.local;
464
+ if (taken.has(local)) {
465
+ local = fresh(local);
466
+ renames.set(ci.local, local);
467
+ renamed.push({ from: ci.local, to: local });
468
+ }
469
+ taken.add(local);
470
+ const spec = respec(ci.spec, fromRel, targetRel);
471
+ // ONE refusal for a canvas, a runtime file and a missing one (as the C4 walk's own: a planted import is
472
+ // no probe of what exists), naming the import as written, never what it resolved to
473
+ if (spec.startsWith('.') && !importAllowed(spec, targetRel, read).ok)
474
+ return fail(
475
+ `That ${what} uses ${ci.local} from ${baseOf(ci.spec, fromRel)}, which a canvas can’t import (another canvas, a runtime file, or one that isn’t there); it can’t be pasted here. Move the shared part into a component.`
476
+ );
477
+ added++;
478
+ const named =
479
+ ci.imported === local
480
+ ? local
481
+ : `${IDENT_RE.test(ci.imported) ? ci.imported : JSON.stringify(ci.imported)} as ${local}`;
482
+ // another name from a module the target already imports joins that import
483
+ const host =
484
+ ci.imported !== 'default' && ci.imported !== '*' && !ci.typeOnly
485
+ ? targetImports.find(
486
+ (t) =>
487
+ t.key === key &&
488
+ !t.b.typeOnly &&
489
+ t.b.decl.importKind !== 'type' &&
490
+ !(t.b.decl.specifiers as Node[]).some((s) => s.type === 'ImportNamespaceSpecifier')
491
+ )
492
+ : undefined;
493
+ if (host) {
494
+ const specs = host.b.decl.specifiers as Node[];
495
+ const last = [...specs].reverse().find((s) => s.type === 'ImportSpecifier');
496
+ joins.push(
497
+ last
498
+ ? { at: last.end, text: `, ${named}` }
499
+ : { at: (specs[0] as Node).end, text: `, { ${named} }` }
500
+ );
501
+ continue;
502
+ }
503
+ const lineKey = `${ci.typeOnly ? 'type:' : ''}${spec}`;
504
+ const line = lines.get(lineKey) ?? { spec, named: [], type: !!ci.typeOnly };
505
+ if (ci.imported === 'default' && !line.def && !line.ns) line.def = local;
506
+ else if (ci.imported === '*' && !line.def && !line.ns && line.named.length === 0)
507
+ line.ns = local;
508
+ else if (ci.imported !== 'default' && ci.imported !== '*' && !line.ns) line.named.push(named);
509
+ else {
510
+ // a second default / namespace from one module: its own line
511
+ lines.set(`${lineKey}#${local}`, {
512
+ spec,
513
+ named: [],
514
+ type: !!ci.typeOnly,
515
+ ...(ci.imported === '*' ? { ns: local } : { def: local }),
516
+ });
517
+ continue;
518
+ }
519
+ lines.set(lineKey, line);
520
+ }
521
+
522
+ // declarations, in dependency order: reuse an identical one, rename on a clash, else insert
523
+ const decls: string[] = [];
524
+ let declAt = table.lastImportEnd;
525
+ for (const d of carry.decls) {
526
+ let text = renameRefs(d.text, renames, false);
527
+ const tb = table.bindings.get(d.name);
528
+ if (
529
+ tb?.kind === 'decl' &&
530
+ tb.text !== null &&
531
+ normal(tb.text) === normal(text) &&
532
+ !shadow.has(d.name)
533
+ ) {
534
+ declAt = Math.max(declAt, tb.stmtEnd); // after what it reuses: a const read before it is declared throws
535
+ continue;
536
+ }
537
+ if (taken.has(d.name)) {
538
+ const to = fresh(d.name);
539
+ renames.set(d.name, to);
540
+ renamed.push({ from: d.name, to });
541
+ text = renameRefs(text, new Map([[d.name, to]]), false);
542
+ taken.add(to);
543
+ } else taken.add(d.name);
544
+ decls.push(text);
545
+ }
546
+
547
+ const importAt = table.lastImportEnd;
548
+ const importLines = [...lines.values()].map((l) => {
549
+ const parts = [
550
+ ...(l.def ? [l.def] : []),
551
+ ...(l.ns ? [`* as ${l.ns}`] : []),
552
+ ...(l.named.length ? [`{ ${l.named.join(', ')} }`] : []),
553
+ ];
554
+ return `import ${l.type ? 'type ' : ''}${parts.join(', ')} from '${l.spec}';`;
555
+ });
556
+ return {
557
+ renames,
558
+ carried: { imports: added, decls: decls.length, renamed },
559
+ apply(s) {
560
+ for (const j of joins) s.appendLeft(j.at, j.text);
561
+ if (importLines.length)
562
+ s.appendLeft(
563
+ importAt,
564
+ importAt === 0 ? `${importLines.join('\n')}\n` : `\n${importLines.join('\n')}`
565
+ );
566
+ if (decls.length)
567
+ s.appendLeft(
568
+ declAt,
569
+ declAt === 0 ? `${decls.join('\n\n')}\n\n` : `\n\n${decls.join('\n\n')}`
570
+ );
571
+ },
572
+ };
573
+ }
574
+
575
+ const ITEM_HEAD = 'const __maudeClip = (\n';
576
+ const ITEM_TAIL = '\n);\n';
577
+
578
+ /**
579
+ * `text` with its references to the names in `renames` rewritten — a reference that something inside the text
580
+ * declares (a callback's parameter) is left alone, a shorthand `{ W }` becomes `{ W: W2 }`. `asItem`: the text is
581
+ * one clip item (a JSX element), else a top-level statement (its own declared name is renamed too).
582
+ */
583
+ export function renameRefs(
584
+ text: string,
585
+ renames: ReadonlyMap<string, string>,
586
+ asItem: boolean
587
+ ): string {
588
+ if (renames.size === 0) return text;
589
+ const head = asItem ? ITEM_HEAD : '';
590
+ const tail = asItem ? ITEM_TAIL : '';
591
+ const synth = `${head}${text}${tail}`;
592
+ const mod = scopeModule(synth);
593
+ if (!mod) return text;
594
+ const ms = new MagicString(synth);
595
+ for (const r of freeRefsIn(mod, head.length, head.length + text.length)) {
596
+ if (r.scope === 'function') continue;
597
+ const to = renames.get(r.name);
598
+ if (to) ms.overwrite(r.start, r.end, r.shorthand ? `${r.name}: ${to}` : to);
599
+ }
600
+ const out = ms.toString();
601
+ return out.slice(head.length, out.length - tail.length);
602
+ }