@sixb/app 0.2.1 → 0.2.3

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 (422) hide show
  1. package/dist/agent/agent-chat.d.ts +9 -2
  2. package/dist/agent/agent-chat.d.ts.map +1 -1
  3. package/dist/agent/agent-panel.d.ts +9 -1
  4. package/dist/agent/agent-panel.d.ts.map +1 -1
  5. package/dist/agent/agent-surface.d.ts.map +1 -1
  6. package/dist/agent/artifact-card.d.ts +3 -1
  7. package/dist/agent/artifact-card.d.ts.map +1 -1
  8. package/dist/agent/artifact-panel.d.ts +7 -1
  9. package/dist/agent/artifact-panel.d.ts.map +1 -1
  10. package/dist/agent/components/composer-place.d.ts +3 -1
  11. package/dist/agent/components/composer-place.d.ts.map +1 -1
  12. package/dist/agent/components/composer.d.ts +20 -1
  13. package/dist/agent/components/composer.d.ts.map +1 -1
  14. package/dist/agent/components/context-chips.d.ts.map +1 -1
  15. package/dist/agent/components/context-meter.d.ts +1 -1
  16. package/dist/agent/components/conversation-panel.d.ts +3 -1
  17. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  18. package/dist/agent/components/message-parts.d.ts +3 -1
  19. package/dist/agent/components/message-parts.d.ts.map +1 -1
  20. package/dist/agent/components/thread-artifacts-menu.d.ts.map +1 -1
  21. package/dist/agent/composer-insertion.d.ts +24 -0
  22. package/dist/agent/composer-insertion.d.ts.map +1 -0
  23. package/dist/agent/delegation/use-children.d.ts +5 -5
  24. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  25. package/dist/agent/hooks/use-agent-conversation.d.ts +10 -4
  26. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  27. package/dist/agent/hooks/use-new-thread-place.d.ts +39 -17
  28. package/dist/agent/hooks/use-new-thread-place.d.ts.map +1 -1
  29. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  30. package/dist/agent/i18n/en.d.ts +14 -0
  31. package/dist/agent/i18n/en.d.ts.map +1 -1
  32. package/dist/agent/i18n/fr.d.ts.map +1 -1
  33. package/dist/agent/i18n/index.d.ts +20 -0
  34. package/dist/agent/i18n/index.d.ts.map +1 -1
  35. package/dist/agent/publish-artifact/interpret.d.ts +8 -2
  36. package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
  37. package/dist/agent/publish-artifact/open-artifact-tool-view.d.ts +9 -0
  38. package/dist/agent/publish-artifact/open-artifact-tool-view.d.ts.map +1 -0
  39. package/dist/agent/publish-artifact/publish-artifact-tool-view.d.ts +4 -2
  40. package/dist/agent/publish-artifact/publish-artifact-tool-view.d.ts.map +1 -1
  41. package/dist/agent/publish-artifact/use-live-publishes.d.ts +3 -3
  42. package/dist/agent/publish-artifact/use-live-publishes.d.ts.map +1 -1
  43. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  44. package/dist/agent/types.d.ts +3 -1
  45. package/dist/agent/types.d.ts.map +1 -1
  46. package/dist/artifacts/artifact-page.d.ts.map +1 -1
  47. package/dist/artifacts/artifact-viewer.d.ts +16 -0
  48. package/dist/artifacts/artifact-viewer.d.ts.map +1 -0
  49. package/dist/artifacts/card-details.d.ts +1 -1
  50. package/dist/artifacts/card-details.d.ts.map +1 -1
  51. package/dist/artifacts/card-preview.d.ts.map +1 -1
  52. package/dist/artifacts/comments-context.d.ts +48 -0
  53. package/dist/artifacts/comments-context.d.ts.map +1 -0
  54. package/dist/artifacts/edit-session.d.ts +6 -6
  55. package/dist/artifacts/edit-session.d.ts.map +1 -1
  56. package/dist/artifacts/file-source.d.ts.map +1 -1
  57. package/dist/artifacts/frame.d.ts +10 -2
  58. package/dist/artifacts/frame.d.ts.map +1 -1
  59. package/dist/artifacts/guest-badge.d.ts +8 -0
  60. package/dist/artifacts/guest-badge.d.ts.map +1 -0
  61. package/dist/artifacts/held-artifact.d.ts +19 -0
  62. package/dist/artifacts/held-artifact.d.ts.map +1 -0
  63. package/dist/artifacts/holders.d.ts +10 -0
  64. package/dist/artifacts/holders.d.ts.map +1 -0
  65. package/dist/artifacts/live/boards.d.ts +15 -0
  66. package/dist/artifacts/live/boards.d.ts.map +1 -0
  67. package/dist/artifacts/live/canvas.d.ts +79 -0
  68. package/dist/artifacts/live/canvas.d.ts.map +1 -0
  69. package/dist/artifacts/live/header.d.ts +29 -0
  70. package/dist/artifacts/live/header.d.ts.map +1 -0
  71. package/dist/artifacts/live/hooks.d.ts +21 -0
  72. package/dist/artifacts/live/hooks.d.ts.map +1 -0
  73. package/dist/artifacts/live/presence.d.ts +32 -0
  74. package/dist/artifacts/live/presence.d.ts.map +1 -0
  75. package/dist/artifacts/live/session.d.ts +130 -0
  76. package/dist/artifacts/live/session.d.ts.map +1 -0
  77. package/dist/artifacts/live/view.d.ts +28 -0
  78. package/dist/artifacts/live/view.d.ts.map +1 -0
  79. package/dist/artifacts/messages.d.ts +424 -14
  80. package/dist/artifacts/messages.d.ts.map +1 -1
  81. package/dist/artifacts/page-queries.d.ts +2 -2
  82. package/dist/artifacts/page-queries.d.ts.map +1 -1
  83. package/dist/artifacts/page-state.d.ts.map +1 -1
  84. package/dist/artifacts/publish-edit.d.ts +24 -14
  85. package/dist/artifacts/publish-edit.d.ts.map +1 -1
  86. package/dist/artifacts/queries.d.ts +490 -9
  87. package/dist/artifacts/queries.d.ts.map +1 -1
  88. package/dist/artifacts/references/references.d.ts.map +1 -1
  89. package/dist/artifacts/renderers/canvas/arrows.d.ts +0 -18
  90. package/dist/artifacts/renderers/canvas/arrows.d.ts.map +1 -1
  91. package/dist/artifacts/renderers/canvas/board-editor.d.ts +43 -0
  92. package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -0
  93. package/dist/artifacts/renderers/canvas/board-properties.d.ts +37 -0
  94. package/dist/artifacts/renderers/canvas/board-properties.d.ts.map +1 -0
  95. package/dist/artifacts/renderers/canvas/board-source.d.ts +18 -0
  96. package/dist/artifacts/renderers/canvas/board-source.d.ts.map +1 -0
  97. package/dist/artifacts/renderers/canvas/board.d.ts +64 -19
  98. package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
  99. package/dist/artifacts/renderers/canvas/canvas.d.ts +13 -4
  100. package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -1
  101. package/dist/artifacts/renderers/canvas/comment-pins.d.ts +84 -0
  102. package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -0
  103. package/dist/artifacts/renderers/canvas/commenting.d.ts +58 -0
  104. package/dist/artifacts/renderers/canvas/commenting.d.ts.map +1 -0
  105. package/dist/artifacts/renderers/canvas/comments-panel.d.ts +27 -0
  106. package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -0
  107. package/dist/artifacts/renderers/canvas/comments.d.ts +56 -0
  108. package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -0
  109. package/dist/artifacts/renderers/canvas/draft.d.ts +7 -6
  110. package/dist/artifacts/renderers/canvas/draft.d.ts.map +1 -1
  111. package/dist/artifacts/renderers/canvas/edit-mode.d.ts +19 -2
  112. package/dist/artifacts/renderers/canvas/edit-mode.d.ts.map +1 -1
  113. package/dist/artifacts/renderers/canvas/focus.d.ts +40 -5
  114. package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
  115. package/dist/artifacts/renderers/canvas/items.d.ts +47 -4
  116. package/dist/artifacts/renderers/canvas/items.d.ts.map +1 -1
  117. package/dist/artifacts/renderers/canvas/layout.d.ts +5 -8
  118. package/dist/artifacts/renderers/canvas/layout.d.ts.map +1 -1
  119. package/dist/artifacts/renderers/canvas/presence.d.ts +21 -0
  120. package/dist/artifacts/renderers/canvas/presence.d.ts.map +1 -0
  121. package/dist/artifacts/renderers/canvas/previews.d.ts +54 -0
  122. package/dist/artifacts/renderers/canvas/previews.d.ts.map +1 -0
  123. package/dist/artifacts/renderers/canvas/renderer.d.ts +11 -2
  124. package/dist/artifacts/renderers/canvas/renderer.d.ts.map +1 -1
  125. package/dist/artifacts/renderers/canvas/thumbnail.d.ts +5 -2
  126. package/dist/artifacts/renderers/canvas/thumbnail.d.ts.map +1 -1
  127. package/dist/artifacts/version-menu.d.ts +19 -0
  128. package/dist/artifacts/version-menu.d.ts.map +1 -0
  129. package/dist/artifacts/view-context.d.ts +43 -0
  130. package/dist/artifacts/view-context.d.ts.map +1 -0
  131. package/dist/artifacts/viewer.d.ts.map +1 -1
  132. package/dist/build.d.ts +5 -0
  133. package/dist/build.d.ts.map +1 -1
  134. package/dist/{chunk-ytadd0b5.js → chunk-001c4gnk.js} +6871 -3756
  135. package/dist/chunk-001c4gnk.js.map +204 -0
  136. package/dist/chunk-00wggsst.js +7 -0
  137. package/dist/chunk-00wggsst.js.map +10 -0
  138. package/dist/chunk-5crvhjp2.js +4704 -0
  139. package/dist/chunk-5crvhjp2.js.map +28 -0
  140. package/dist/{chunk-q69001w3.js → chunk-694m74s7.js} +7 -1
  141. package/dist/{chunk-q69001w3.js.map → chunk-694m74s7.js.map} +3 -3
  142. package/dist/{chunk-4mprsd2n.js → chunk-fg6thecb.js} +25 -1
  143. package/dist/chunk-fg6thecb.js.map +10 -0
  144. package/dist/{chunk-j8g956dt.js → chunk-fwb9mxwm.js} +1 -1
  145. package/dist/{chunk-7fj9cfkw.js → chunk-kes4ygmz.js} +1 -1
  146. package/dist/{chunk-kwbw4dyk.js → chunk-ryed2jq8.js} +1 -1
  147. package/dist/codegen.d.ts.map +1 -1
  148. package/dist/createCustomApp.d.ts.map +1 -1
  149. package/dist/index.d.ts +7 -1
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +930 -309
  152. package/dist/index.js.map +15 -10
  153. package/dist/locale-messages.d.ts +12 -0
  154. package/dist/locale-messages.d.ts.map +1 -1
  155. package/dist/locale.d.ts +12 -0
  156. package/dist/locale.d.ts.map +1 -1
  157. package/dist/locale.js +1 -1
  158. package/dist/metadata.d.ts +8 -0
  159. package/dist/metadata.d.ts.map +1 -1
  160. package/dist/pages/console/action-run.d.ts.map +1 -1
  161. package/dist/pages/console/data/connectors.d.ts.map +1 -1
  162. package/dist/pages/console/data/datasets.d.ts.map +1 -1
  163. package/dist/pages/console/data/lake-health.d.ts +3 -0
  164. package/dist/pages/console/data/lake-health.d.ts.map +1 -0
  165. package/dist/pages/console/data/messages.d.ts +98 -2
  166. package/dist/pages/console/data/messages.d.ts.map +1 -1
  167. package/dist/pages/console/data/pipelines.d.ts.map +1 -1
  168. package/dist/pages/console/data/projections.d.ts.map +1 -1
  169. package/dist/pages/console/data/syncs.d.ts.map +1 -1
  170. package/dist/pages/console/ontology/action-runs.d.ts.map +1 -1
  171. package/dist/pages/console/ontology/actions.d.ts.map +1 -1
  172. package/dist/pages/console/ontology/components/action-button.d.ts.map +1 -1
  173. package/dist/pages/console/ontology/components/artifact-picker.d.ts +36 -0
  174. package/dist/pages/console/ontology/components/artifact-picker.d.ts.map +1 -0
  175. package/dist/pages/console/ontology/components/object-query-bar.d.ts.map +1 -1
  176. package/dist/pages/console/ontology/lib/action-params.d.ts +2 -0
  177. package/dist/pages/console/ontology/lib/action-params.d.ts.map +1 -1
  178. package/dist/pages/console/ontology/lineage/properties-panel.d.ts +2 -1
  179. package/dist/pages/console/ontology/lineage/properties-panel.d.ts.map +1 -1
  180. package/dist/pages/console/ontology/object-page.d.ts.map +1 -1
  181. package/dist/pages/console/ontology/object-type.d.ts.map +1 -1
  182. package/dist/pages/console/ontology/object-types.d.ts.map +1 -1
  183. package/dist/pages/console/ontology/objects.d.ts.map +1 -1
  184. package/dist/pages/console/ontology/rules.d.ts.map +1 -1
  185. package/dist/pages/console/ontology/workflow.d.ts.map +1 -1
  186. package/dist/pages/console/ontology/workflows/run-input-form.d.ts.map +1 -1
  187. package/dist/pages/console/ontology/workflows/schema-shape.d.ts.map +1 -1
  188. package/dist/pages/console/ontology/workflows.d.ts.map +1 -1
  189. package/dist/pages/console/skeletons.d.ts +30 -0
  190. package/dist/pages/console/skeletons.d.ts.map +1 -0
  191. package/dist/pages/console/workflow-run.d.ts.map +1 -1
  192. package/dist/pages/section-page.d.ts +11 -1
  193. package/dist/pages/section-page.d.ts.map +1 -1
  194. package/dist/pages/section-ui.d.ts +25 -3
  195. package/dist/pages/section-ui.d.ts.map +1 -1
  196. package/dist/pages/settings/activity/calendar.d.ts.map +1 -1
  197. package/dist/pages/settings/activity/connections.d.ts.map +1 -1
  198. package/dist/pages/settings/activity/page.d.ts.map +1 -1
  199. package/dist/pages/settings/activity/thread.d.ts.map +1 -1
  200. package/dist/pages/settings/activity/timeline.d.ts +2 -0
  201. package/dist/pages/settings/activity/timeline.d.ts.map +1 -1
  202. package/dist/pages/settings/controls.d.ts +4 -0
  203. package/dist/pages/settings/controls.d.ts.map +1 -1
  204. package/dist/pages/settings/members.d.ts.map +1 -1
  205. package/dist/pages/settings/memory-history.d.ts +2 -0
  206. package/dist/pages/settings/memory-history.d.ts.map +1 -1
  207. package/dist/pages/settings/memory.d.ts.map +1 -1
  208. package/dist/pages/settings/service-accounts.d.ts.map +1 -1
  209. package/dist/pages/settings/sessions.d.ts.map +1 -1
  210. package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
  211. package/dist/pages/settings/usage/limits.d.ts.map +1 -1
  212. package/dist/pages/settings/usage/messages.d.ts +0 -2
  213. package/dist/pages/settings/usage/messages.d.ts.map +1 -1
  214. package/dist/pages/settings/usage/runs.d.ts +8 -2
  215. package/dist/pages/settings/usage/runs.d.ts.map +1 -1
  216. package/dist/pages/settings/usage/spend-chart.d.ts.map +1 -1
  217. package/dist/pages/settings/usage/spend-model.d.ts +5 -0
  218. package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
  219. package/dist/pages/values.d.ts +6 -0
  220. package/dist/pages/values.d.ts.map +1 -1
  221. package/dist/pages.d.ts +4 -0
  222. package/dist/pages.d.ts.map +1 -1
  223. package/dist/pages.js +8188 -4841
  224. package/dist/pages.js.map +56 -47
  225. package/dist/sections/catalog.d.ts.map +1 -1
  226. package/dist/sections/sections.d.ts.map +1 -1
  227. package/dist/server.js +294 -23
  228. package/dist/server.js.map +8 -7
  229. package/dist/service-worker.d.ts +39 -0
  230. package/dist/service-worker.d.ts.map +1 -0
  231. package/dist/shared-session.d.ts +25 -0
  232. package/dist/shared-session.d.ts.map +1 -0
  233. package/dist/shell/app-return.d.ts +35 -0
  234. package/dist/shell/app-return.d.ts.map +1 -0
  235. package/dist/shell/app-shell.d.ts +1 -1
  236. package/dist/shell/app-shell.d.ts.map +1 -1
  237. package/dist/shell/nav-items.d.ts +2 -0
  238. package/dist/shell/nav-items.d.ts.map +1 -1
  239. package/dist/shell/phone/back.d.ts +6 -0
  240. package/dist/shell/phone/back.d.ts.map +1 -0
  241. package/dist/shell/phone/launch.d.ts +7 -0
  242. package/dist/shell/phone/launch.d.ts.map +1 -0
  243. package/dist/shell/phone/more-sheet.d.ts +36 -0
  244. package/dist/shell/phone/more-sheet.d.ts.map +1 -0
  245. package/dist/shell/phone/phone-foundations.d.ts +9 -0
  246. package/dist/shell/phone/phone-foundations.d.ts.map +1 -0
  247. package/dist/shell/phone/pull-to-refresh.d.ts +9 -0
  248. package/dist/shell/phone/pull-to-refresh.d.ts.map +1 -0
  249. package/dist/shell/phone/routes.d.ts +12 -0
  250. package/dist/shell/phone/routes.d.ts.map +1 -0
  251. package/dist/shell/phone/screen-motion.d.ts +11 -0
  252. package/dist/shell/phone/screen-motion.d.ts.map +1 -0
  253. package/dist/shell/phone/scroll-restoration.d.ts +7 -0
  254. package/dist/shell/phone/scroll-restoration.d.ts.map +1 -0
  255. package/dist/shell/phone/startup-image.d.ts +17 -0
  256. package/dist/shell/phone/startup-image.d.ts.map +1 -0
  257. package/dist/shell/phone/tab-bar.d.ts +14 -0
  258. package/dist/shell/phone/tab-bar.d.ts.map +1 -0
  259. package/dist/shell/phone/top-bar.d.ts +24 -0
  260. package/dist/shell/phone/top-bar.d.ts.map +1 -0
  261. package/dist/shell/search-command.d.ts +3 -1
  262. package/dist/shell/search-command.d.ts.map +1 -1
  263. package/dist/shell/user-menu.d.ts +2 -0
  264. package/dist/shell/user-menu.d.ts.map +1 -1
  265. package/package.json +8 -5
  266. package/src/agent/agent-chat.tsx +51 -8
  267. package/src/agent/agent-panel.tsx +12 -0
  268. package/src/agent/agent-surface.tsx +4 -0
  269. package/src/agent/artifact-card.tsx +84 -16
  270. package/src/agent/artifact-panel.tsx +63 -43
  271. package/src/agent/components/agent-message-body.tsx +1 -1
  272. package/src/agent/components/composer-place.tsx +77 -53
  273. package/src/agent/components/composer.tsx +92 -7
  274. package/src/agent/components/context-chips.tsx +72 -2
  275. package/src/agent/components/conversation-panel.tsx +3 -2
  276. package/src/agent/components/message-parts.tsx +6 -1
  277. package/src/agent/components/thread-artifacts-menu.tsx +22 -5
  278. package/src/agent/composer-insertion.ts +36 -0
  279. package/src/agent/hooks/use-agent-conversation.ts +41 -10
  280. package/src/agent/hooks/use-new-thread-place.ts +149 -25
  281. package/src/agent/i18n/en.ts +14 -0
  282. package/src/agent/i18n/fr.ts +12 -0
  283. package/src/agent/publish-artifact/interpret.ts +27 -5
  284. package/src/agent/publish-artifact/open-artifact-tool-view.tsx +49 -0
  285. package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +14 -8
  286. package/src/agent/publish-artifact/use-live-publishes.ts +7 -11
  287. package/src/agent/react-router.tsx +2 -2
  288. package/src/agent/tool-views/built-in.tsx +3 -0
  289. package/src/agent/types.ts +4 -0
  290. package/src/artifacts/artifact-page.tsx +42 -17
  291. package/src/artifacts/artifact-viewer.tsx +56 -0
  292. package/src/artifacts/artifacts.css +80 -0
  293. package/src/artifacts/card-details.ts +2 -2
  294. package/src/artifacts/card-preview.tsx +17 -3
  295. package/src/artifacts/comments-context.ts +125 -0
  296. package/src/artifacts/edit-session.tsx +6 -6
  297. package/src/artifacts/file-source.ts +10 -3
  298. package/src/artifacts/frame.tsx +50 -12
  299. package/src/artifacts/gallery.tsx +9 -11
  300. package/src/artifacts/guest-badge.tsx +21 -0
  301. package/src/artifacts/held-artifact.tsx +241 -0
  302. package/src/artifacts/holders.tsx +170 -0
  303. package/src/artifacts/live/boards.ts +95 -0
  304. package/src/artifacts/live/canvas.ts +402 -0
  305. package/src/artifacts/live/header.tsx +137 -0
  306. package/src/artifacts/live/hooks.ts +94 -0
  307. package/src/artifacts/live/presence.ts +147 -0
  308. package/src/artifacts/live/session.ts +520 -0
  309. package/src/artifacts/live/view.ts +81 -0
  310. package/src/artifacts/messages.ts +415 -24
  311. package/src/artifacts/page-queries.ts +2 -3
  312. package/src/artifacts/page-state.ts +16 -7
  313. package/src/artifacts/publish-edit.ts +50 -22
  314. package/src/artifacts/queries.ts +108 -10
  315. package/src/artifacts/references/references.tsx +6 -9
  316. package/src/artifacts/renderers/canvas/arrows.tsx +12 -39
  317. package/src/artifacts/renderers/canvas/board-editor.tsx +817 -0
  318. package/src/artifacts/renderers/canvas/board-properties.tsx +488 -0
  319. package/src/artifacts/renderers/canvas/board-source.ts +110 -0
  320. package/src/artifacts/renderers/canvas/board.tsx +309 -33
  321. package/src/artifacts/renderers/canvas/canvas.tsx +387 -72
  322. package/src/artifacts/renderers/canvas/comment-pins.tsx +465 -0
  323. package/src/artifacts/renderers/canvas/commenting.tsx +319 -0
  324. package/src/artifacts/renderers/canvas/comments-panel.tsx +574 -0
  325. package/src/artifacts/renderers/canvas/comments.ts +225 -0
  326. package/src/artifacts/renderers/canvas/draft.ts +41 -50
  327. package/src/artifacts/renderers/canvas/edit-mode.tsx +145 -20
  328. package/src/artifacts/renderers/canvas/focus.tsx +175 -24
  329. package/src/artifacts/renderers/canvas/items.tsx +179 -52
  330. package/src/artifacts/renderers/canvas/layout.ts +99 -47
  331. package/src/artifacts/renderers/canvas/presence.tsx +184 -0
  332. package/src/artifacts/renderers/canvas/previews.ts +127 -0
  333. package/src/artifacts/renderers/canvas/renderer.tsx +87 -22
  334. package/src/artifacts/renderers/canvas/thumbnail.tsx +56 -15
  335. package/src/artifacts/renderers/canvas/toolbar.tsx +1 -1
  336. package/src/artifacts/renderers/slides/slides.tsx +1 -1
  337. package/src/artifacts/version-menu.tsx +438 -0
  338. package/src/artifacts/view-context.ts +102 -0
  339. package/src/artifacts/viewer.tsx +205 -147
  340. package/src/build.ts +96 -11
  341. package/src/codegen.ts +83 -5
  342. package/src/createCustomApp.ts +20 -7
  343. package/src/index.ts +12 -0
  344. package/src/locale-messages.ts +24 -0
  345. package/src/metadata.ts +12 -0
  346. package/src/pages/console/action-run.tsx +20 -0
  347. package/src/pages/console/data/connectors.tsx +27 -3
  348. package/src/pages/console/data/datasets.tsx +30 -1
  349. package/src/pages/console/data/lake-health.tsx +299 -0
  350. package/src/pages/console/data/messages.ts +143 -2
  351. package/src/pages/console/data/pipelines.tsx +91 -3
  352. package/src/pages/console/data/projections.tsx +23 -4
  353. package/src/pages/console/data/syncs.tsx +39 -2
  354. package/src/pages/console/ontology/action-runs.tsx +8 -2
  355. package/src/pages/console/ontology/actions.tsx +39 -15
  356. package/src/pages/console/ontology/components/action-button.tsx +10 -0
  357. package/src/pages/console/ontology/components/artifact-picker.tsx +522 -0
  358. package/src/pages/console/ontology/components/object-query-bar.tsx +21 -5
  359. package/src/pages/console/ontology/lib/action-params.ts +10 -0
  360. package/src/pages/console/ontology/lineage/properties-panel.tsx +32 -24
  361. package/src/pages/console/ontology/object-page.tsx +2 -0
  362. package/src/pages/console/ontology/object-type.tsx +73 -14
  363. package/src/pages/console/ontology/object-types.tsx +56 -7
  364. package/src/pages/console/ontology/objects.tsx +167 -19
  365. package/src/pages/console/ontology/rules.tsx +186 -30
  366. package/src/pages/console/ontology/workflow.tsx +130 -74
  367. package/src/pages/console/ontology/workflows/run-input-form.tsx +21 -2
  368. package/src/pages/console/ontology/workflows/schema-shape.tsx +3 -0
  369. package/src/pages/console/ontology/workflows.tsx +34 -21
  370. package/src/pages/console/skeletons.tsx +99 -0
  371. package/src/pages/console/workflow-run.tsx +20 -0
  372. package/src/pages/section-page.tsx +37 -7
  373. package/src/pages/section-ui.tsx +96 -13
  374. package/src/pages/settings/activity/calendar.tsx +13 -6
  375. package/src/pages/settings/activity/connections.tsx +26 -9
  376. package/src/pages/settings/activity/page.tsx +31 -4
  377. package/src/pages/settings/activity/thread.tsx +32 -18
  378. package/src/pages/settings/activity/timeline.tsx +39 -0
  379. package/src/pages/settings/controls.tsx +19 -1
  380. package/src/pages/settings/developers.tsx +2 -2
  381. package/src/pages/settings/members.tsx +42 -9
  382. package/src/pages/settings/memory-history.tsx +76 -10
  383. package/src/pages/settings/memory.tsx +47 -5
  384. package/src/pages/settings/service-accounts.tsx +7 -2
  385. package/src/pages/settings/sessions.tsx +6 -2
  386. package/src/pages/settings/usage/breakdown.tsx +62 -2
  387. package/src/pages/settings/usage/limits.tsx +45 -3
  388. package/src/pages/settings/usage/messages.ts +0 -2
  389. package/src/pages/settings/usage/page.tsx +99 -52
  390. package/src/pages/settings/usage/runs.tsx +105 -8
  391. package/src/pages/settings/usage/spend-chart.tsx +79 -45
  392. package/src/pages/settings/usage/spend-model.ts +16 -0
  393. package/src/pages/values.tsx +72 -6
  394. package/src/pages.ts +4 -0
  395. package/src/sections/catalog.ts +6 -0
  396. package/src/sections/sections.tsx +2 -0
  397. package/src/service-worker.ts +176 -0
  398. package/src/shared-session.ts +73 -0
  399. package/src/shell/app-return.ts +115 -0
  400. package/src/shell/app-shell.tsx +125 -27
  401. package/src/shell/nav-items.tsx +2 -0
  402. package/src/shell/phone/back.ts +16 -0
  403. package/src/shell/phone/launch.ts +6 -0
  404. package/src/shell/phone/more-sheet.tsx +249 -0
  405. package/src/shell/phone/phone-foundations.tsx +43 -0
  406. package/src/shell/phone/phone.css +660 -0
  407. package/src/shell/phone/pull-to-refresh.tsx +201 -0
  408. package/src/shell/phone/routes.ts +34 -0
  409. package/src/shell/phone/screen-motion.ts +292 -0
  410. package/src/shell/phone/scroll-restoration.tsx +70 -0
  411. package/src/shell/phone/startup-image.ts +119 -0
  412. package/src/shell/phone/tab-bar.tsx +95 -0
  413. package/src/shell/phone/top-bar.tsx +195 -0
  414. package/src/shell/search-command.tsx +30 -14
  415. package/src/shell/user-menu.tsx +2 -1
  416. package/dist/chunk-4j3c3p72.js +0 -1487
  417. package/dist/chunk-4j3c3p72.js.map +0 -18
  418. package/dist/chunk-4mprsd2n.js.map +0 -10
  419. package/dist/chunk-ytadd0b5.js.map +0 -188
  420. /package/dist/{chunk-j8g956dt.js.map → chunk-fwb9mxwm.js.map} +0 -0
  421. /package/dist/{chunk-7fj9cfkw.js.map → chunk-kes4ygmz.js.map} +0 -0
  422. /package/dist/{chunk-kwbw4dyk.js.map → chunk-ryed2jq8.js.map} +0 -0
@@ -0,0 +1,4704 @@
1
+ // @bun
2
+ import {
3
+ useArtifactView,
4
+ useAgentDraft,
5
+ formatFileSize,
6
+ useArtifactMessages,
7
+ artifactChanged,
8
+ useFileText,
9
+ versionFileSource,
10
+ useBoardPreviews,
11
+ boardPreviewSize,
12
+ boardPreviewUrl,
13
+ livePersonName,
14
+ useLivePresence,
15
+ moveItems,
16
+ resizeItem,
17
+ addItem,
18
+ removeItems,
19
+ duplicateItems,
20
+ setItemText,
21
+ connectItems,
22
+ styleItems,
23
+ TONE_COLORS,
24
+ ArtifactFrame,
25
+ useSharedGuest2,
26
+ useGiveGuestName,
27
+ PersonAvatar,
28
+ useCurrentUser2,
29
+ commentsContext,
30
+ canvasGraph,
31
+ ArtifactLink,
32
+ ArtifactEmbed
33
+ } from "./chunk-001c4gnk.js";
34
+
35
+ // src/artifacts/renderers/canvas/canvas.tsx
36
+ import { CANVAS_FIT_PADDING } from "@sixb/core/artifacts";
37
+ import { cn as cn11 } from "@sixb/ui/lib/utils";
38
+ import {
39
+ Background,
40
+ BackgroundVariant,
41
+ Panel as Panel3,
42
+ ReactFlow,
43
+ ReactFlowProvider,
44
+ useReactFlow as useReactFlow2,
45
+ useStore as useStore4,
46
+ useStoreApi as useStoreApi4
47
+ } from "@xyflow/react";
48
+ import {
49
+ memo as memo5,
50
+ useCallback as useCallback8,
51
+ useEffect as useEffect8,
52
+ useMemo as useMemo6,
53
+ useRef as useRef8,
54
+ useState as useState11
55
+ } from "react";
56
+
57
+ // src/artifacts/renderers/canvas/arrows.tsx
58
+ import { ARTIFACT_LIMITS as ARTIFACT_LIMITS2, canvasArrowLine } from "@sixb/core/artifacts";
59
+ import {
60
+ EdgeLabelRenderer,
61
+ useInternalNode
62
+ } from "@xyflow/react";
63
+ import { memo as memo2 } from "react";
64
+
65
+ // src/artifacts/renderers/canvas/items.tsx
66
+ import { CANVAS_TEXT_PIXELS, canvasNoteFontSize, canvasShapeFontSize } from "@sixb/core/artifacts";
67
+ import { cn as cn3 } from "@sixb/ui/lib/utils";
68
+ import { useQueryClient } from "@tanstack/react-query";
69
+ import { Handle as Handle2, Position as Position2, useStoreApi as useStoreApi2 } from "@xyflow/react";
70
+ import { AppWindow, ArrowUpRight, Link2, Maximize2 } from "lucide-react";
71
+ import { memo, useSyncExternalStore as useSyncExternalStore2 } from "react";
72
+
73
+ // src/artifacts/renderers/canvas/board.tsx
74
+ import { CANVAS_FILE } from "@sixb/core/artifacts";
75
+ import { cn } from "@sixb/ui/lib/utils";
76
+ import { useStoreApi } from "@xyflow/react";
77
+ import {
78
+ createContext,
79
+ useContext,
80
+ useEffect,
81
+ useRef,
82
+ useState,
83
+ useSyncExternalStore
84
+ } from "react";
85
+ import { jsx, jsxs } from "react/jsx-runtime";
86
+ var MAX_LIVE_BOARDS = 8;
87
+ var LIVE_FROM_SCALE = 0.5;
88
+ var LIVE_FROM_WIDTH = 360;
89
+ function liveBoards(boards, view, running = new Set) {
90
+ const [panX, panY, zoom] = view.transform;
91
+ const centerX = view.width / 2;
92
+ const centerY = view.height / 2;
93
+ const candidates = boards.flatMap((board) => {
94
+ const left = board.x * zoom + panX;
95
+ const top = board.y * zoom + panY;
96
+ const width = board.w * zoom;
97
+ const height = board.h * zoom;
98
+ const onScreen = left < view.width && left + width > 0 && top < view.height && top + height > 0;
99
+ const half = board.w * LIVE_FROM_SCALE;
100
+ const large = width >= (board.pictured ? half : Math.min(half, LIVE_FROM_WIDTH));
101
+ const kept = running.has(board.id);
102
+ if (!onScreen || !large && !kept)
103
+ return [];
104
+ const distance = Math.hypot(left + width / 2 - centerX, top + height / 2 - centerY);
105
+ return [{ id: board.id, kept, distance }];
106
+ });
107
+ candidates.sort((a, b) => Number(b.kept) - Number(a.kept) || a.distance - b.distance);
108
+ return new Set(candidates.slice(0, MAX_LIVE_BOARDS).map((candidate) => candidate.id));
109
+ }
110
+ function useLiveSet(places) {
111
+ const store = useStoreApi();
112
+ const [live] = useState(createLiveSet);
113
+ useEffect(() => {
114
+ let last = null;
115
+ const update = () => {
116
+ const { transform, width, height, fitViewQueued } = store.getState();
117
+ if (fitViewQueued)
118
+ return;
119
+ if (last && last.width === width && last.height === height && last.transform.every((value, index) => value === transform[index])) {
120
+ return;
121
+ }
122
+ last = { transform, width, height };
123
+ live.set(liveBoards(places, last, live.current()));
124
+ };
125
+ update();
126
+ return store.subscribe(update);
127
+ }, [store, places, live]);
128
+ return live;
129
+ }
130
+ function createLiveSet() {
131
+ let current = new Set;
132
+ const listeners = new Set;
133
+ return {
134
+ has: (id) => current.has(id),
135
+ current: () => current,
136
+ set: (next) => {
137
+ if (next.size === current.size && [...next].every((id) => current.has(id)))
138
+ return;
139
+ current = next;
140
+ for (const listener of listeners)
141
+ listener();
142
+ },
143
+ subscribe: (listener) => {
144
+ listeners.add(listener);
145
+ return () => listeners.delete(listener);
146
+ }
147
+ };
148
+ }
149
+ var NOTHING_LIVE = { has: () => false, subscribe: () => () => {} };
150
+ var LiveBoardsContext = createContext({
151
+ version: null,
152
+ live: NOTHING_LIVE,
153
+ previews: {},
154
+ mode: "light"
155
+ });
156
+ function useLiveBoards() {
157
+ return useContext(LiveBoardsContext);
158
+ }
159
+ function useLive(id) {
160
+ const { live } = useContext(LiveBoardsContext);
161
+ return useSyncExternalStore(live.subscribe, () => live.has(id), () => false);
162
+ }
163
+ function LiveBoardsProvider({
164
+ value,
165
+ children
166
+ }) {
167
+ return /* @__PURE__ */ jsx(LiveBoardsContext.Provider, {
168
+ value,
169
+ children
170
+ });
171
+ }
172
+ function ItemTile({
173
+ icon: Icon,
174
+ preview,
175
+ fallback,
176
+ pending = false,
177
+ onFail
178
+ }) {
179
+ const picture = usePicture(preview, fallback, pending, onFail);
180
+ if (picture.src) {
181
+ return /* @__PURE__ */ jsx("img", {
182
+ src: picture.src,
183
+ alt: "",
184
+ decoding: "async",
185
+ loading: "lazy",
186
+ draggable: false,
187
+ onError: picture.fail,
188
+ className: cn("block size-full object-contain object-top", pending && "motion-safe:animate-pulse"),
189
+ ...pending ? { "aria-busy": true } : {}
190
+ });
191
+ }
192
+ return /* @__PURE__ */ jsx("div", {
193
+ className: "flex size-full items-center justify-center bg-card",
194
+ ...pending ? { "aria-busy": true } : {},
195
+ children: /* @__PURE__ */ jsx(Icon, {
196
+ className: cn("size-12 text-muted-foreground/30", pending && "motion-safe:animate-pulse"),
197
+ strokeWidth: 1,
198
+ "aria-hidden": "true"
199
+ })
200
+ });
201
+ }
202
+ var NOTHING_FAILED = new Set;
203
+ function usePicture(preview, fallback, pending, onFail) {
204
+ const [failed, setFailed] = useState(NOTHING_FAILED);
205
+ const onFailRef = useRef(onFail);
206
+ onFailRef.current = onFail;
207
+ const wanted = [preview, fallback].find((src) => src !== undefined && !failed.has(src)) ?? null;
208
+ const [shown, setShown] = useState(wanted);
209
+ const showing = shown !== null && !failed.has(shown);
210
+ useEffect(() => {
211
+ if (wanted === shown)
212
+ return;
213
+ if (!wanted && pending && showing)
214
+ return;
215
+ if (!wanted || !showing) {
216
+ setShown(wanted);
217
+ return;
218
+ }
219
+ let current = true;
220
+ const next = new Image;
221
+ next.src = wanted;
222
+ next.decode().then(() => {
223
+ if (current)
224
+ setShown(wanted);
225
+ }, () => {
226
+ if (!current)
227
+ return;
228
+ setFailed((all) => new Set(all).add(wanted));
229
+ onFailRef.current?.();
230
+ });
231
+ return () => {
232
+ current = false;
233
+ };
234
+ }, [wanted, shown, showing, pending]);
235
+ return {
236
+ src: showing ? shown : wanted,
237
+ fail: () => {
238
+ const src = showing ? shown : wanted;
239
+ if (!src)
240
+ return;
241
+ setFailed((all) => new Set(all).add(src));
242
+ onFailRef.current?.();
243
+ }
244
+ };
245
+ }
246
+ function usePagesVersion(version) {
247
+ const kept = useRef(null);
248
+ if (!version)
249
+ return null;
250
+ const pages = `${version.artifactId}@${version.version}
251
+ ${version.files.filter((file) => file.path !== CANVAS_FILE).map((file) => `${file.path}:${file.file.digest}`).join(`
252
+ `)}`;
253
+ if (kept.current?.pages !== pages)
254
+ kept.current = { version, pages };
255
+ return kept.current.version;
256
+ }
257
+ function LiveBoard({
258
+ id,
259
+ file,
260
+ title,
261
+ tile
262
+ }) {
263
+ const { version } = useContext(LiveBoardsContext);
264
+ const live = useLive(id);
265
+ const pages = usePagesVersion(version);
266
+ const [ready, setReady] = useState(null);
267
+ const running = live && pages !== null && ready === pages;
268
+ return /* @__PURE__ */ jsxs("div", {
269
+ className: "group/board relative size-full",
270
+ "data-running": running ? "" : undefined,
271
+ children: [
272
+ /* @__PURE__ */ jsx("div", {
273
+ className: "size-full transition-[visibility] delay-300 group-data-[running]/board:invisible",
274
+ children: tile
275
+ }),
276
+ pages && live ? /* @__PURE__ */ jsx(ArtifactFrame, {
277
+ version: pages,
278
+ entry: file,
279
+ title,
280
+ decorative: true,
281
+ className: "absolute inset-0 overflow-hidden rounded-[10px]",
282
+ onEvent: (event) => {
283
+ if (event.event === "ready")
284
+ setReady(pages);
285
+ }
286
+ }) : null
287
+ ]
288
+ });
289
+ }
290
+
291
+ // src/artifacts/renderers/canvas/editing.tsx
292
+ import { ARTIFACT_LIMITS } from "@sixb/core/artifacts";
293
+ import { cn as cn2 } from "@sixb/ui/lib/utils";
294
+ import { Handle, NodeResizer, Position } from "@xyflow/react";
295
+ import {
296
+ createContext as createContext2,
297
+ useContext as useContext2,
298
+ useLayoutEffect,
299
+ useRef as useRef2,
300
+ useState as useState2
301
+ } from "react";
302
+ import { jsx as jsx2, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
303
+ var CanvasEditingContext = createContext2(null);
304
+ function CanvasEditingProvider({
305
+ value,
306
+ children
307
+ }) {
308
+ return /* @__PURE__ */ jsx2(CanvasEditingContext.Provider, {
309
+ value,
310
+ children
311
+ });
312
+ }
313
+ function useCanvasEditing() {
314
+ return useContext2(CanvasEditingContext);
315
+ }
316
+ var SIDES = [
317
+ ["top", Position.Top],
318
+ ["right", Position.Right],
319
+ ["bottom", Position.Bottom],
320
+ ["left", Position.Left]
321
+ ];
322
+ function EditChrome({
323
+ id,
324
+ selected,
325
+ resizable = true
326
+ }) {
327
+ const editing = useCanvasEditing();
328
+ if (!editing)
329
+ return null;
330
+ return /* @__PURE__ */ jsxs2(Fragment, {
331
+ children: [
332
+ SIDES.map(([side, position]) => /* @__PURE__ */ jsx2(Handle, {
333
+ id: side,
334
+ type: "source",
335
+ position,
336
+ className: "sixb-connect",
337
+ "data-selected": selected ? "" : undefined
338
+ }, side)),
339
+ resizable ? /* @__PURE__ */ jsx2(NodeResizer, {
340
+ isVisible: selected && editing.typing !== id,
341
+ minWidth: 40,
342
+ minHeight: 40,
343
+ color: "var(--primary)",
344
+ handleClassName: "sixb-resize-handle",
345
+ lineClassName: "sixb-resize-line",
346
+ onResizeEnd: (_, box) => editing.resize(id, { x: box.x, y: box.y, w: box.width, h: box.height })
347
+ }) : null
348
+ ]
349
+ });
350
+ }
351
+ function InPlaceText({
352
+ id,
353
+ value,
354
+ multiline = false,
355
+ placeholder,
356
+ className,
357
+ style
358
+ }) {
359
+ const editing = useCanvasEditing();
360
+ const [text, setText] = useState2(value);
361
+ const field = useRef2(null);
362
+ const done = useRef2(false);
363
+ useLayoutEffect(() => {
364
+ let frame = 0;
365
+ let tries = 0;
366
+ const take = () => {
367
+ const element = field.current;
368
+ if (!element)
369
+ return;
370
+ fitHeight(element);
371
+ element.focus({ preventScroll: true });
372
+ if (element.ownerDocument.activeElement === element)
373
+ element.select();
374
+ else if (tries++ < 10)
375
+ frame = requestAnimationFrame(take);
376
+ };
377
+ take();
378
+ return () => cancelAnimationFrame(frame);
379
+ }, []);
380
+ if (!editing)
381
+ return null;
382
+ const commit = () => {
383
+ if (done.current)
384
+ return;
385
+ done.current = true;
386
+ editing.commitText(id, text);
387
+ };
388
+ const onKeyDown = (event) => {
389
+ event.stopPropagation();
390
+ if (event.key === "Escape" || event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey)) {
391
+ event.preventDefault();
392
+ commit();
393
+ }
394
+ };
395
+ const shared = {
396
+ value: text,
397
+ maxLength: multiline ? ARTIFACT_LIMITS.maxCanvasTextLength : ARTIFACT_LIMITS.maxCanvasLabelLength,
398
+ placeholder,
399
+ spellCheck: true,
400
+ onBlur: commit,
401
+ onKeyDown,
402
+ style,
403
+ className: cn2("nodrag nopan nowheel block w-full resize-none border-0 bg-transparent p-0 [font:inherit] [letter-spacing:inherit] text-inherit outline-none placeholder:text-current/40", className)
404
+ };
405
+ return multiline ? /* @__PURE__ */ jsx2("textarea", {
406
+ ref: field,
407
+ rows: 1,
408
+ ...shared,
409
+ onChange: (event) => {
410
+ setText(event.target.value);
411
+ fitHeight(event.target);
412
+ }
413
+ }) : /* @__PURE__ */ jsx2("input", {
414
+ ref: field,
415
+ ...shared,
416
+ onChange: (event) => setText(event.target.value)
417
+ });
418
+ }
419
+ function fitHeight(element) {
420
+ if (element.tagName !== "TEXTAREA")
421
+ return;
422
+ element.style.height = "auto";
423
+ element.style.height = `${element.scrollHeight}px`;
424
+ }
425
+
426
+ // src/artifacts/renderers/canvas/items.tsx
427
+ import { jsx as jsx3, jsxs as jsxs3, Fragment as Fragment2 } from "react/jsx-runtime";
428
+ var CANVAS_NODE_TYPES = {
429
+ board: memo(BoardNode),
430
+ section: memo(SectionNode),
431
+ note: memo(NoteNode),
432
+ text: memo(TextNode),
433
+ shape: memo(ShapeNode),
434
+ embed: memo(EmbedNode),
435
+ point: memo(PointNode)
436
+ };
437
+ function Ends() {
438
+ return /* @__PURE__ */ jsxs3(Fragment2, {
439
+ children: [
440
+ /* @__PURE__ */ jsx3(Handle2, {
441
+ type: "source",
442
+ position: Position2.Top,
443
+ isConnectable: false,
444
+ className: "!invisible"
445
+ }),
446
+ /* @__PURE__ */ jsx3(Handle2, {
447
+ type: "target",
448
+ position: Position2.Top,
449
+ isConnectable: false,
450
+ className: "!invisible"
451
+ })
452
+ ]
453
+ });
454
+ }
455
+ var NAMES_FROM_ZOOM = 0.35;
456
+ var MAX_NAME_SCALE = 2;
457
+ var NAMED_FROM_WIDTH = 120;
458
+ var NAME_SCALE = "--sixb-name-scale";
459
+ var NAME_SCALE_VALUE = `var(${NAME_SCALE}, 1)`;
460
+ function nameScale(zoom) {
461
+ return Math.min(MAX_NAME_SCALE, Math.max(1, 1 / zoom));
462
+ }
463
+ var FAR_BELOW_ZOOM = 0.2;
464
+ function zoomMarks(zoom) {
465
+ return { nameScale: nameScale(zoom).toFixed(3), far: zoom < FAR_BELOW_ZOOM };
466
+ }
467
+ var zooms = new WeakMap;
468
+ function zoomOf(source) {
469
+ let entry = zooms.get(source);
470
+ if (entry)
471
+ return entry;
472
+ const read = () => {
473
+ const { transform, fitViewQueued } = source.getState();
474
+ return { zoom: transform[2], fitViewQueued };
475
+ };
476
+ let current = read();
477
+ const listeners = new Set;
478
+ let unsubscribe = null;
479
+ entry = {
480
+ get: () => {
481
+ if (!unsubscribe)
482
+ current = same(current, read());
483
+ return current;
484
+ },
485
+ subscribe: (listener) => {
486
+ listeners.add(listener);
487
+ unsubscribe ??= source.subscribe(() => {
488
+ const next = same(current, read());
489
+ if (next === current)
490
+ return;
491
+ current = next;
492
+ for (const each of listeners)
493
+ each();
494
+ });
495
+ return () => {
496
+ listeners.delete(listener);
497
+ if (listeners.size > 0 || !unsubscribe)
498
+ return;
499
+ unsubscribe();
500
+ unsubscribe = null;
501
+ };
502
+ }
503
+ };
504
+ zooms.set(source, entry);
505
+ return entry;
506
+ }
507
+ function same(last, next) {
508
+ return last.zoom === next.zoom && last.fitViewQueued === next.fitViewQueued ? last : next;
509
+ }
510
+ function useZoomed(select) {
511
+ const zoom = zoomOf(useStoreApi2());
512
+ return useSyncExternalStore2(zoom.subscribe, () => select(zoom.get()));
513
+ }
514
+ function useNamesShown() {
515
+ return useZoomed(({ zoom }) => zoom >= NAMES_FROM_ZOOM);
516
+ }
517
+ function useNamed(width) {
518
+ return useZoomed(({ zoom }) => width * zoom >= NAMED_FROM_WIDTH);
519
+ }
520
+ function NameRow({
521
+ width,
522
+ icon,
523
+ name,
524
+ action
525
+ }) {
526
+ return /* @__PURE__ */ jsxs3("div", {
527
+ className: "pointer-events-none absolute bottom-full left-0 flex h-7 origin-bottom-left items-center gap-1.5 pb-1.5 text-[13px] font-medium text-muted-foreground",
528
+ style: {
529
+ width: `calc(${width}px / ${NAME_SCALE_VALUE})`,
530
+ transform: `scale(${NAME_SCALE_VALUE})`
531
+ },
532
+ children: [
533
+ /* @__PURE__ */ jsx3("span", {
534
+ className: "shrink-0 [&>svg]:size-3.5",
535
+ "aria-hidden": "true",
536
+ children: icon
537
+ }),
538
+ /* @__PURE__ */ jsx3("span", {
539
+ className: "min-w-0 flex-1 truncate",
540
+ children: name
541
+ }),
542
+ action
543
+ ]
544
+ });
545
+ }
546
+ function itemOf(props) {
547
+ return props.data.item;
548
+ }
549
+ function BoardNode(props) {
550
+ const board = itemOf(props);
551
+ const messages = useArtifactMessages().canvas;
552
+ const { version, previews, mode, open } = useLiveBoards();
553
+ const queries = useQueryClient();
554
+ const previewSize = useZoomed(({ zoom, fitViewQueued }) => fitViewQueued ? "small" : boardPreviewSize(board.w * zoom, window.devicePixelRatio || 1));
555
+ const shown = useNamesShown();
556
+ const named = useNamed(board.w);
557
+ const title = board.title ?? board.id;
558
+ return /* @__PURE__ */ jsxs3("div", {
559
+ className: "relative size-full",
560
+ children: [
561
+ /* @__PURE__ */ jsx3(Ends, {}),
562
+ /* @__PURE__ */ jsx3(EditChrome, {
563
+ id: board.id,
564
+ selected: props.selected
565
+ }),
566
+ shown && named ? /* @__PURE__ */ jsx3(NameRow, {
567
+ width: board.w,
568
+ icon: /* @__PURE__ */ jsx3(AppWindow, {}),
569
+ name: title,
570
+ action: open ? /* @__PURE__ */ jsx3("button", {
571
+ type: "button",
572
+ className: "nodrag nopan pointer-events-auto -my-1 flex size-6 shrink-0 items-center justify-center rounded-md outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
573
+ "aria-label": messages.openBoard(title),
574
+ title: messages.openBoard(title),
575
+ onClick: () => open(board.id),
576
+ children: /* @__PURE__ */ jsx3(Maximize2, {
577
+ className: "size-3.5",
578
+ "aria-hidden": "true"
579
+ })
580
+ }) : null
581
+ }) : null,
582
+ /* @__PURE__ */ jsx3("div", {
583
+ className: "sixb-canvas-surface size-full overflow-hidden",
584
+ children: /* @__PURE__ */ jsx3(LiveBoard, {
585
+ id: board.id,
586
+ file: board.file,
587
+ title,
588
+ tile: /* @__PURE__ */ jsx3(ItemTile, {
589
+ icon: AppWindow,
590
+ ...version && previews[board.id] === "ready" ? {
591
+ preview: boardPreviewUrl(version, board.id, mode, previewSize),
592
+ ...previewSize === "small" ? { fallback: boardPreviewUrl(version, board.id, mode) } : {}
593
+ } : {},
594
+ pending: previews[board.id] === "pending",
595
+ ...version ? { onFail: () => artifactChanged(queries, version.artifactId) } : {}
596
+ })
597
+ })
598
+ })
599
+ ]
600
+ });
601
+ }
602
+ function SectionNode(props) {
603
+ const section = itemOf(props);
604
+ const shown = useNamesShown();
605
+ const editing = useCanvasEditing();
606
+ const heading = "absolute top-0 left-0 m-0 origin-top-left text-base leading-6 font-semibold tracking-[-0.01em] text-foreground";
607
+ return /* @__PURE__ */ jsxs3("div", {
608
+ className: "relative size-full",
609
+ children: [
610
+ /* @__PURE__ */ jsx3(Ends, {}),
611
+ /* @__PURE__ */ jsx3(EditChrome, {
612
+ id: section.id,
613
+ selected: props.selected
614
+ }),
615
+ editing?.typing === section.id ? /* @__PURE__ */ jsx3("div", {
616
+ className: cn3(heading, "pointer-events-auto"),
617
+ style: { width: section.w },
618
+ children: /* @__PURE__ */ jsx3(InPlaceText, {
619
+ id: section.id,
620
+ value: section.title ?? ""
621
+ })
622
+ }) : section.title && shown ? /* @__PURE__ */ jsx3("h3", {
623
+ className: cn3(heading, "truncate", editing ? "pointer-events-auto cursor-grab" : "pointer-events-none"),
624
+ style: {
625
+ maxWidth: `calc(${section.w}px / ${NAME_SCALE_VALUE})`,
626
+ transform: `scale(${NAME_SCALE_VALUE})`
627
+ },
628
+ children: section.title
629
+ }) : null
630
+ ]
631
+ });
632
+ }
633
+ function NoteNode(props) {
634
+ const note = itemOf(props);
635
+ const tone = note.tone ?? "warning";
636
+ const editing = useCanvasEditing();
637
+ return /* @__PURE__ */ jsxs3("div", {
638
+ className: cn3("relative rounded-[4px] px-[1em] py-[0.85em] leading-[1.4] font-medium whitespace-pre-wrap text-foreground", tone === "neutral" ? "sixb-canvas-surface" : "shadow-[0_1px_2px_rgb(0_0_0/0.06),0_10px_24px_-14px_rgb(0_0_0/0.28)]"),
639
+ style: {
640
+ width: "100%",
641
+ minHeight: `max(${note.h ?? Math.min(note.w, 112)}px, 100%)`,
642
+ fontSize: canvasNoteFontSize(note.w),
643
+ ...tone === "neutral" ? {} : { backgroundColor: `color-mix(in oklab, ${TONE_COLORS[tone]} 20%, var(--card))` }
644
+ },
645
+ children: [
646
+ /* @__PURE__ */ jsx3(Ends, {}),
647
+ /* @__PURE__ */ jsx3(EditChrome, {
648
+ id: note.id,
649
+ selected: props.selected
650
+ }),
651
+ editing?.typing === note.id ? /* @__PURE__ */ jsx3(InPlaceText, {
652
+ id: note.id,
653
+ value: note.text,
654
+ multiline: true,
655
+ className: "leading-[1.4] font-medium"
656
+ }) : note.text
657
+ ]
658
+ });
659
+ }
660
+ function TextNode(props) {
661
+ const text = itemOf(props);
662
+ const size = CANVAS_TEXT_PIXELS[text.size];
663
+ const editing = useCanvasEditing();
664
+ return /* @__PURE__ */ jsxs3("div", {
665
+ className: cn3("relative whitespace-pre-wrap text-foreground", (text.size === "xl" || text.size === "xxl") && "font-bold tracking-[-0.025em]", text.size === "l" && "font-semibold tracking-[-0.015em]", text.size === "s" && "text-muted-foreground"),
666
+ style: {
667
+ fontSize: size,
668
+ lineHeight: text.size === "s" || text.size === "m" ? 1.45 : 1.15,
669
+ ...text.w === undefined ? { width: "max-content", minWidth: "100%" } : { width: "100%" }
670
+ },
671
+ children: [
672
+ /* @__PURE__ */ jsx3(Ends, {}),
673
+ /* @__PURE__ */ jsx3(EditChrome, {
674
+ id: text.id,
675
+ selected: props.selected
676
+ }),
677
+ editing?.typing === text.id ? /* @__PURE__ */ jsx3(InPlaceText, {
678
+ id: text.id,
679
+ value: text.text,
680
+ multiline: true,
681
+ className: "min-w-[8ch]"
682
+ }) : text.text
683
+ ]
684
+ });
685
+ }
686
+ function ShapeNode(props) {
687
+ const shape = itemOf(props);
688
+ const fill = shape.tone ? `color-mix(in oklab, ${TONE_COLORS[shape.tone]} 16%, var(--card))` : "var(--card)";
689
+ const stroke = "color-mix(in oklab, var(--foreground) 32%, transparent)";
690
+ const editing = useCanvasEditing();
691
+ const fontSize = canvasShapeFontSize(shape.w, shape.h);
692
+ const textBox = cn3("relative text-center leading-snug font-medium text-foreground", shape.shape === "diamond" ? "max-w-[60%]" : "max-w-[80%]");
693
+ return /* @__PURE__ */ jsxs3("div", {
694
+ className: "relative flex size-full items-center justify-center",
695
+ children: [
696
+ /* @__PURE__ */ jsx3(Ends, {}),
697
+ /* @__PURE__ */ jsx3(EditChrome, {
698
+ id: shape.id,
699
+ selected: props.selected
700
+ }),
701
+ /* @__PURE__ */ jsx3("svg", {
702
+ viewBox: `0 0 ${shape.w} ${shape.h}`,
703
+ className: "absolute inset-0 size-full overflow-visible",
704
+ "aria-hidden": "true",
705
+ children: shape.shape === "ellipse" ? /* @__PURE__ */ jsx3("ellipse", {
706
+ cx: shape.w / 2,
707
+ cy: shape.h / 2,
708
+ rx: shape.w / 2,
709
+ ry: shape.h / 2,
710
+ style: { fill, stroke },
711
+ strokeWidth: 1.5
712
+ }) : shape.shape === "diamond" ? /* @__PURE__ */ jsx3("polygon", {
713
+ points: `${shape.w / 2},0 ${shape.w},${shape.h / 2} ${shape.w / 2},${shape.h} 0,${shape.h / 2}`,
714
+ style: { fill, stroke },
715
+ strokeWidth: 1.5,
716
+ strokeLinejoin: "round"
717
+ }) : /* @__PURE__ */ jsx3("rect", {
718
+ width: shape.w,
719
+ height: shape.h,
720
+ rx: 10,
721
+ style: { fill, stroke },
722
+ strokeWidth: 1.5
723
+ })
724
+ }),
725
+ editing?.typing === shape.id ? /* @__PURE__ */ jsx3("div", {
726
+ className: cn3(textBox, "w-full"),
727
+ style: { fontSize },
728
+ children: /* @__PURE__ */ jsx3(InPlaceText, {
729
+ id: shape.id,
730
+ value: shape.text ?? "",
731
+ className: "text-center"
732
+ })
733
+ }) : shape.text ? /* @__PURE__ */ jsx3("span", {
734
+ className: textBox,
735
+ style: { fontSize },
736
+ children: shape.text
737
+ }) : null
738
+ ]
739
+ });
740
+ }
741
+ function EmbedNode(props) {
742
+ const embed = itemOf(props);
743
+ const messages = useArtifactMessages().canvas;
744
+ const live = useLive(embed.id);
745
+ const shown = useNamesShown();
746
+ const named = useNamed(embed.w) && shown && Boolean(embed.title);
747
+ return /* @__PURE__ */ jsxs3("div", {
748
+ className: "relative size-full",
749
+ children: [
750
+ /* @__PURE__ */ jsx3(Ends, {}),
751
+ /* @__PURE__ */ jsx3(EditChrome, {
752
+ id: embed.id,
753
+ selected: props.selected
754
+ }),
755
+ named && embed.title ? /* @__PURE__ */ jsx3(NameRow, {
756
+ width: embed.w,
757
+ icon: /* @__PURE__ */ jsx3(Link2, {}),
758
+ name: embed.title,
759
+ action: /* @__PURE__ */ jsxs3(ArtifactLink, {
760
+ address: embed.src,
761
+ className: "nodrag nopan pointer-events-auto -my-1 flex size-6 shrink-0 items-center justify-center rounded-md outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
762
+ children: [
763
+ /* @__PURE__ */ jsx3(ArrowUpRight, {
764
+ className: "size-3.5",
765
+ "aria-hidden": "true"
766
+ }),
767
+ /* @__PURE__ */ jsx3("span", {
768
+ className: "sr-only",
769
+ children: messages.open
770
+ })
771
+ ]
772
+ })
773
+ }) : null,
774
+ /* @__PURE__ */ jsx3("div", {
775
+ className: "sixb-canvas-surface sixb-canvas-embed size-full overflow-hidden",
776
+ ...named ? { "data-named": "" } : {},
777
+ children: live ? /* @__PURE__ */ jsx3(ArtifactEmbed, {
778
+ address: embed.src,
779
+ caption: embed.title ?? "",
780
+ fill: true
781
+ }) : /* @__PURE__ */ jsx3(ItemTile, {
782
+ icon: Link2
783
+ })
784
+ })
785
+ ]
786
+ });
787
+ }
788
+ function PointNode() {
789
+ return /* @__PURE__ */ jsx3("div", {
790
+ className: "size-px",
791
+ children: /* @__PURE__ */ jsx3(Ends, {})
792
+ });
793
+ }
794
+
795
+ // src/artifacts/renderers/canvas/arrows.tsx
796
+ import { jsx as jsx4, jsxs as jsxs4, Fragment as Fragment3 } from "react/jsx-runtime";
797
+ var CANVAS_EDGE_TYPES = { floating: memo2(FloatingArrow) };
798
+ var HEAD_LENGTH = 13;
799
+ var HEAD_WIDTH = 11;
800
+ var LABEL_LAYER = ARTIFACT_LIMITS2.maxCanvasItems + 1;
801
+ var LABEL_SHARE = 0.7;
802
+ function rectOf(node) {
803
+ return {
804
+ x: node.internals.positionAbsolute.x,
805
+ y: node.internals.positionAbsolute.y,
806
+ width: node.measured.width ?? node.width ?? 0,
807
+ height: node.measured.height ?? node.height ?? 0
808
+ };
809
+ }
810
+ function FloatingArrow({ id, source, target, data, selected }) {
811
+ const from = useInternalNode(source);
812
+ const to = useInternalNode(target);
813
+ const shown = useNamesShown();
814
+ if (!from || !to)
815
+ return null;
816
+ const a = rectOf(from);
817
+ const b = rectOf(to);
818
+ const { start, end } = canvasArrowLine(a, b);
819
+ const angle = Math.atan2(end.y - start.y, end.x - start.x);
820
+ const stem = {
821
+ x: end.x - Math.cos(angle) * (HEAD_LENGTH - 1),
822
+ y: end.y - Math.sin(angle) * (HEAD_LENGTH - 1)
823
+ };
824
+ const side = (sign) => ({
825
+ x: end.x - Math.cos(angle) * HEAD_LENGTH + Math.sin(angle) * (HEAD_WIDTH / 2) * sign,
826
+ y: end.y - Math.sin(angle) * HEAD_LENGTH - Math.cos(angle) * (HEAD_WIDTH / 2) * sign
827
+ });
828
+ const left = side(1);
829
+ const right = side(-1);
830
+ const room = LABEL_SHARE * Math.hypot(end.x - start.x, end.y - start.y) / ((data?.label?.length ?? 0) * 6.6 + 24);
831
+ const labelScale = `min(${NAME_SCALE_VALUE}, ${Math.max(1, room)})`;
832
+ const color = selected ? "var(--primary)" : "color-mix(in oklab, var(--foreground) 62%, transparent)";
833
+ return /* @__PURE__ */ jsxs4(Fragment3, {
834
+ children: [
835
+ /* @__PURE__ */ jsx4("path", {
836
+ d: `M${start.x},${start.y} L${end.x},${end.y}`,
837
+ fill: "none",
838
+ stroke: "transparent",
839
+ strokeWidth: 18,
840
+ className: "react-flow__edge-interaction"
841
+ }),
842
+ /* @__PURE__ */ jsx4("path", {
843
+ id,
844
+ d: `M${start.x},${start.y} L${stem.x},${stem.y}`,
845
+ fill: "none",
846
+ style: { stroke: color },
847
+ strokeWidth: 2,
848
+ strokeLinecap: "round",
849
+ strokeDasharray: data?.dashed ? "7 7" : undefined
850
+ }),
851
+ /* @__PURE__ */ jsx4("path", {
852
+ d: `M${end.x},${end.y} L${left.x},${left.y} L${right.x},${right.y} Z`,
853
+ style: { fill: color },
854
+ strokeLinejoin: "round"
855
+ }),
856
+ data?.label && shown ? /* @__PURE__ */ jsx4(EdgeLabelRenderer, {
857
+ children: /* @__PURE__ */ jsx4("span", {
858
+ className: "pointer-events-none absolute rounded-full border border-border bg-background px-2.5 py-0.5 text-[12px] font-medium whitespace-nowrap text-foreground shadow-sm",
859
+ style: {
860
+ zIndex: LABEL_LAYER,
861
+ transform: `translate(${(start.x + end.x) / 2}px, ${(start.y + end.y) / 2}px) translate(-50%, -50%) scale(${labelScale})`
862
+ },
863
+ children: data.label
864
+ })
865
+ }) : null
866
+ ]
867
+ });
868
+ }
869
+
870
+ // src/artifacts/renderers/canvas/comment-pins.tsx
871
+ import { cn as cn5 } from "@sixb/ui/lib/utils";
872
+ import { useStore, ViewportPortal } from "@xyflow/react";
873
+ import { ArrowUp, LoaderCircle, X } from "lucide-react";
874
+ import {
875
+ memo as memo3,
876
+ useCallback,
877
+ useId,
878
+ useState as useState3
879
+ } from "react";
880
+
881
+ // src/artifacts/guest-badge.tsx
882
+ import { cn as cn4 } from "@sixb/ui/lib/utils";
883
+ import { jsx as jsx5 } from "react/jsx-runtime";
884
+ function GuestBadge({ className }) {
885
+ const messages = useArtifactMessages().canvas.comments;
886
+ return /* @__PURE__ */ jsx5("span", {
887
+ title: messages.guestHint,
888
+ className: cn4("inline-flex h-4 shrink-0 items-center rounded-full bg-muted px-1.5 text-[10.5px] leading-none font-medium tracking-[0.01em] text-muted-foreground ring-1 ring-border/70 ring-inset", className),
889
+ children: messages.guest
890
+ });
891
+ }
892
+
893
+ // src/artifacts/renderers/canvas/comments.ts
894
+ import {
895
+ addArtifactComment,
896
+ deleteArtifactComment,
897
+ isSixbApiError,
898
+ resolveArtifactComment
899
+ } from "@sixb/client";
900
+ import { listArtifactCommentsOptions, listArtifactCommentsQueryKey } from "@sixb/client/hooks";
901
+ import { useQuery } from "@tanstack/react-query";
902
+ import { useMemo } from "react";
903
+ class CommentActionError extends Error {
904
+ failure;
905
+ name = "CommentActionError";
906
+ constructor(failure) {
907
+ super(`[SixbApp] The comment action failed: ${failure}.`);
908
+ this.failure = failure;
909
+ }
910
+ }
911
+ function commentThreads(comments) {
912
+ const replies = new Map;
913
+ for (const comment of comments) {
914
+ if (!comment.parentId)
915
+ continue;
916
+ const list = replies.get(comment.parentId) ?? [];
917
+ list.push(comment);
918
+ replies.set(comment.parentId, list);
919
+ }
920
+ return comments.filter((comment) => !comment.parentId).map((comment, index) => ({
921
+ comment,
922
+ replies: replies.get(comment.id) ?? [],
923
+ number: index + 1
924
+ }));
925
+ }
926
+ var NO_COMMENTS = [];
927
+ function useArtifactComments(artifactId) {
928
+ const query = useQuery({
929
+ ...listArtifactCommentsOptions({ path: { artifactId: artifactId ?? "" } }),
930
+ enabled: artifactId !== null,
931
+ retry: false
932
+ });
933
+ const comments = query.data?.comments ?? NO_COMMENTS;
934
+ const threads = useMemo(() => commentThreads(comments), [comments]);
935
+ return { threads, loading: query.isLoading, failed: query.isError };
936
+ }
937
+ function commentsKey(artifactId) {
938
+ return listArtifactCommentsQueryKey({ path: { artifactId } });
939
+ }
940
+ function updateCached(queries, artifactId, update) {
941
+ queries.setQueryData(commentsKey(artifactId), (current) => current ? { ...current, comments: [...update(current.comments)] } : current);
942
+ }
943
+ async function addComment(queries, artifactId, body) {
944
+ try {
945
+ const { data } = await addArtifactComment({
946
+ path: { artifactId },
947
+ body,
948
+ throwOnError: true
949
+ });
950
+ updateCached(queries, artifactId, (comments) => comments.some((comment) => comment.id === data.id) ? comments : [...comments, data]);
951
+ return data;
952
+ } catch (error) {
953
+ throw commentError(error);
954
+ }
955
+ }
956
+ async function resolveComment(queries, artifactId, commentId, resolved) {
957
+ try {
958
+ const { data } = await resolveArtifactComment({
959
+ path: { artifactId, commentId },
960
+ body: { resolved },
961
+ throwOnError: true
962
+ });
963
+ updateCached(queries, artifactId, (comments) => comments.map((comment) => comment.id === data.id ? data : comment));
964
+ } catch (error) {
965
+ throw commentError(error);
966
+ }
967
+ }
968
+ async function deleteComment(queries, artifactId, commentId) {
969
+ try {
970
+ await deleteArtifactComment({ path: { artifactId, commentId }, throwOnError: true });
971
+ updateCached(queries, artifactId, (comments) => comments.filter((comment) => comment.id !== commentId && comment.parentId !== commentId));
972
+ } catch (error) {
973
+ throw commentError(error);
974
+ }
975
+ }
976
+ function commentError(error) {
977
+ if (!isSixbApiError(error))
978
+ return new CommentActionError("failed");
979
+ switch (error.code) {
980
+ case "comments_full":
981
+ return new CommentActionError("full");
982
+ case "invalid_comment":
983
+ return new CommentActionError("invalid");
984
+ case "name_required":
985
+ case "invalid_name":
986
+ return new CommentActionError("name");
987
+ case "not_allowed":
988
+ return new CommentActionError("notAllowed");
989
+ case "comment_not_found":
990
+ case "artifact_not_found":
991
+ return new CommentActionError("gone");
992
+ default:
993
+ return new CommentActionError("failed");
994
+ }
995
+ }
996
+ function canManageComment(comment, access, userId) {
997
+ if (access === "owner" || access === "update")
998
+ return true;
999
+ return comment.author.type === "user" && comment.author.id === userId;
1000
+ }
1001
+ function useCommentAuthors() {
1002
+ const user = useCurrentUser2();
1003
+ const guest = useSharedGuest2();
1004
+ const messages = useArtifactMessages().canvas.comments;
1005
+ return ({ author, authorName, origin }) => {
1006
+ if (author.type === "guest") {
1007
+ const name = authorName ?? messages.guest;
1008
+ return { name, you: author.id === guest?.id, guest: true };
1009
+ }
1010
+ const own = author.type === "user" && author.id === user?.id;
1011
+ if (origin) {
1012
+ const name = own ? messages.you.toLowerCase() : authorName ?? messages.someone;
1013
+ return { name: messages.agentFor(name), you: false, agent: true };
1014
+ }
1015
+ if (own)
1016
+ return { name: user.displayName ?? user.email ?? authorName ?? "", you: true };
1017
+ return authorName ? { name: authorName, you: false } : null;
1018
+ };
1019
+ }
1020
+
1021
+ // src/artifacts/renderers/canvas/comment-pins.tsx
1022
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1023
+ function pinPoint(pin, index) {
1024
+ return pin.point ?? { x: 1, y: 0.02 + index * 0.06 };
1025
+ }
1026
+ var CARD_WIDTH = 288;
1027
+ function cardPlace(x, width) {
1028
+ const card = Math.min(CARD_WIDTH, width - 16);
1029
+ const beside = 36;
1030
+ const left = Math.max(8 - x, Math.min(beside, width - 8 - card - x));
1031
+ return { left, width: card };
1032
+ }
1033
+ function CommentPin({
1034
+ number,
1035
+ label,
1036
+ active,
1037
+ resolved,
1038
+ draft = false,
1039
+ onClick,
1040
+ style
1041
+ }) {
1042
+ return /* @__PURE__ */ jsx6("button", {
1043
+ type: "button",
1044
+ "aria-label": label,
1045
+ title: label,
1046
+ "aria-pressed": onClick ? active : undefined,
1047
+ "data-comment-pin": number ?? "draft",
1048
+ onClick: (event) => {
1049
+ event.stopPropagation();
1050
+ onClick?.();
1051
+ },
1052
+ className: cn5("nodrag nopan nowheel pointer-events-auto absolute flex h-7 min-w-7 origin-bottom-left -translate-y-full items-center justify-center rounded-full rounded-bl-[4px] px-1.5 text-[12px] font-semibold tabular-nums shadow-[0_1px_2px_rgb(0_0_0/0.12),0_6px_16px_-6px_rgb(0_0_0/0.35)] outline-none ring-2 ring-background transition-[transform,background-color] duration-150 focus-visible:ring-ring motion-safe:hover:scale-110", draft || active ? "bg-primary text-primary-foreground" : resolved ? "bg-muted text-muted-foreground" : "bg-foreground text-background", draft && "motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in-0"),
1053
+ style,
1054
+ children: draft ? /* @__PURE__ */ jsx6("span", {
1055
+ className: "size-1.5 rounded-full bg-current",
1056
+ "aria-hidden": "true"
1057
+ }) : number
1058
+ });
1059
+ }
1060
+ function CommentComposer({
1061
+ placeholder,
1062
+ onSubmit,
1063
+ onCancel,
1064
+ autoFocus = true,
1065
+ compact = false,
1066
+ className
1067
+ }) {
1068
+ const messages = useArtifactMessages().canvas.comments;
1069
+ const guest = useSharedGuest2();
1070
+ const giveName = useGiveGuestName();
1071
+ const [body, setBody] = useState3("");
1072
+ const [name, setName] = useState3("");
1073
+ const [sending, setSending] = useState3(false);
1074
+ const [failure, setFailure] = useState3(null);
1075
+ const naming = guest !== null && guest.name === undefined;
1076
+ const ready = body.trim().length > 0 && (!naming || name.trim().length > 0) && !sending;
1077
+ const submit = async () => {
1078
+ if (!ready)
1079
+ return;
1080
+ setSending(true);
1081
+ setFailure(null);
1082
+ try {
1083
+ if (naming) {
1084
+ await giveName(name).catch(() => {
1085
+ throw new CommentActionError("name");
1086
+ });
1087
+ }
1088
+ await onSubmit(body.trim());
1089
+ setBody("");
1090
+ } catch (error) {
1091
+ setFailure(error instanceof CommentActionError ? error.failure : "failed");
1092
+ } finally {
1093
+ setSending(false);
1094
+ }
1095
+ };
1096
+ const onKeyDown = (event) => {
1097
+ event.stopPropagation();
1098
+ const composing = event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229;
1099
+ if (event.key === "Enter" && !event.shiftKey && !composing) {
1100
+ event.preventDefault();
1101
+ submit();
1102
+ }
1103
+ if (event.key === "Escape") {
1104
+ event.preventDefault();
1105
+ onCancel?.();
1106
+ }
1107
+ };
1108
+ return /* @__PURE__ */ jsxs5("div", {
1109
+ className: cn5("flex flex-col gap-1.5", className),
1110
+ "data-board-tools": "",
1111
+ children: [
1112
+ naming ? /* @__PURE__ */ jsx6(GuestNameField, {
1113
+ value: name,
1114
+ onChange: setName,
1115
+ autoFocus,
1116
+ invalid: failure === "name",
1117
+ onKeyDown
1118
+ }) : null,
1119
+ /* @__PURE__ */ jsxs5("div", {
1120
+ className: "flex items-end gap-1.5 rounded-xl border border-border bg-background px-2.5 py-1.5 focus-within:ring-2 focus-within:ring-ring/40",
1121
+ children: [
1122
+ /* @__PURE__ */ jsx6("textarea", {
1123
+ autoFocus: autoFocus && !naming,
1124
+ value: body,
1125
+ rows: 1,
1126
+ maxLength: 4000,
1127
+ "aria-label": placeholder,
1128
+ placeholder,
1129
+ onChange: (event) => setBody(event.target.value),
1130
+ onKeyDown,
1131
+ className: "max-h-40 min-h-6 flex-1 resize-none bg-transparent py-0.5 text-sm leading-5 outline-none [field-sizing:content] placeholder:text-muted-foreground"
1132
+ }),
1133
+ /* @__PURE__ */ jsx6("button", {
1134
+ type: "button",
1135
+ "aria-label": compact ? messages.reply : messages.post,
1136
+ title: compact ? messages.reply : messages.post,
1137
+ disabled: !ready,
1138
+ onClick: () => void submit(),
1139
+ className: "mb-0.5 flex size-6 shrink-0 items-center justify-center rounded-full bg-foreground text-background outline-none transition-colors hover:bg-foreground/85 focus-visible:ring-2 focus-visible:ring-ring disabled:bg-foreground/20 [&_svg]:size-3.5",
1140
+ children: sending ? /* @__PURE__ */ jsx6(LoaderCircle, {
1141
+ className: "animate-spin motion-reduce:animate-none",
1142
+ "aria-hidden": "true"
1143
+ }) : /* @__PURE__ */ jsx6(ArrowUp, {
1144
+ "aria-hidden": "true"
1145
+ })
1146
+ })
1147
+ ]
1148
+ }),
1149
+ failure ? /* @__PURE__ */ jsx6("p", {
1150
+ role: "alert",
1151
+ className: "m-0 px-1 text-xs text-destructive",
1152
+ children: messages.failures[failure]
1153
+ }) : null
1154
+ ]
1155
+ });
1156
+ }
1157
+ function GuestNameField({
1158
+ value,
1159
+ onChange,
1160
+ autoFocus,
1161
+ invalid,
1162
+ onKeyDown
1163
+ }) {
1164
+ const messages = useArtifactMessages().canvas.comments;
1165
+ const id = useId();
1166
+ return /* @__PURE__ */ jsxs5("div", {
1167
+ className: "flex flex-col gap-1 px-1 pt-0.5",
1168
+ children: [
1169
+ /* @__PURE__ */ jsxs5("div", {
1170
+ className: "flex items-center gap-2",
1171
+ children: [
1172
+ /* @__PURE__ */ jsx6(PersonAvatar, {
1173
+ name: value.trim() || messages.guest,
1174
+ size: "xs"
1175
+ }),
1176
+ /* @__PURE__ */ jsx6("input", {
1177
+ id,
1178
+ autoFocus,
1179
+ value,
1180
+ maxLength: GUEST_NAME_INPUT_LENGTH,
1181
+ autoComplete: "name",
1182
+ "aria-label": messages.guestName,
1183
+ "aria-invalid": invalid,
1184
+ "aria-describedby": `${id}-hint`,
1185
+ placeholder: messages.guestName,
1186
+ onChange: (event) => onChange(event.target.value),
1187
+ onKeyDown,
1188
+ className: "h-7 min-w-0 flex-1 bg-transparent text-sm font-medium text-foreground outline-none placeholder:font-normal placeholder:text-muted-foreground"
1189
+ }),
1190
+ /* @__PURE__ */ jsx6(GuestBadge, {})
1191
+ ]
1192
+ }),
1193
+ /* @__PURE__ */ jsx6("p", {
1194
+ id: `${id}-hint`,
1195
+ className: "m-0 pl-7 text-[11px] leading-4 text-muted-foreground",
1196
+ children: messages.guestNameHint
1197
+ })
1198
+ ]
1199
+ });
1200
+ }
1201
+ var GUEST_NAME_INPUT_LENGTH = 80;
1202
+ function DraftCard({
1203
+ anchor,
1204
+ onSubmit,
1205
+ onCancel
1206
+ }) {
1207
+ const messages = useArtifactMessages().canvas.comments;
1208
+ return /* @__PURE__ */ jsxs5("div", {
1209
+ role: "dialog",
1210
+ "aria-label": messages.newPin,
1211
+ className: "nodrag nopan nowheel pointer-events-auto w-full min-w-56 rounded-2xl border border-border bg-popover p-1.5 text-popover-foreground shadow-[0_2px_4px_rgb(0_0_0/0.06),0_18px_40px_-16px_rgb(0_0_0/0.35)] motion-safe:animate-in motion-safe:fade-in-0 motion-safe:zoom-in-95 motion-safe:slide-in-from-top-1",
1212
+ onPointerDown: (event) => event.stopPropagation(),
1213
+ children: [
1214
+ /* @__PURE__ */ jsxs5("div", {
1215
+ className: "flex h-7 items-center gap-1 pr-0.5 pl-2",
1216
+ children: [
1217
+ /* @__PURE__ */ jsx6("p", {
1218
+ className: "m-0 min-w-0 flex-1 truncate text-xs text-muted-foreground",
1219
+ children: anchor ? messages.about(anchor) : messages.newPin
1220
+ }),
1221
+ /* @__PURE__ */ jsx6("button", {
1222
+ type: "button",
1223
+ "aria-label": messages.cancel,
1224
+ title: messages.cancel,
1225
+ onClick: onCancel,
1226
+ className: "flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5",
1227
+ children: /* @__PURE__ */ jsx6(X, {
1228
+ "aria-hidden": "true"
1229
+ })
1230
+ })
1231
+ ]
1232
+ }),
1233
+ /* @__PURE__ */ jsx6(CommentComposer, {
1234
+ placeholder: messages.placeholder,
1235
+ onSubmit,
1236
+ onCancel
1237
+ })
1238
+ ]
1239
+ });
1240
+ }
1241
+ var CanvasCommentPins = memo3(function CanvasCommentPins({
1242
+ pins,
1243
+ active,
1244
+ draft,
1245
+ onOpen,
1246
+ onSubmitDraft,
1247
+ onCancelDraft
1248
+ }) {
1249
+ const messages = useArtifactMessages().canvas.comments;
1250
+ const zoom = useStore((state) => state.transform[2]);
1251
+ const view = useStore(viewOf, sameView);
1252
+ const boards = [...new Set([...pins.map((pin) => pin.board), ...draft ? [draft.board] : []])];
1253
+ const boxes = useBoardBoxes(boards);
1254
+ const unplaced = new Map;
1255
+ const scale = `scale(${1 / zoom})`;
1256
+ const draftBox = draft ? boxes.get(draft.board) : undefined;
1257
+ if (boxes.size === 0)
1258
+ return null;
1259
+ return /* @__PURE__ */ jsxs5(ViewportPortal, {
1260
+ children: [
1261
+ pins.map((pin) => {
1262
+ const box = boxes.get(pin.board);
1263
+ if (!box)
1264
+ return null;
1265
+ const index = pin.point ? 0 : unplaced.get(pin.board) ?? 0;
1266
+ if (!pin.point)
1267
+ unplaced.set(pin.board, index + 1);
1268
+ const at = pinPoint(pin, index);
1269
+ return /* @__PURE__ */ jsx6("div", {
1270
+ className: "pointer-events-none absolute top-0 left-0",
1271
+ style: {
1272
+ transform: `translate(${box.x + at.x * box.w}px, ${box.y + at.y * box.h}px) ${scale}`,
1273
+ transformOrigin: "0 0"
1274
+ },
1275
+ children: /* @__PURE__ */ jsx6(CommentPin, {
1276
+ number: pin.number,
1277
+ label: pin.label,
1278
+ active: active === pin.id,
1279
+ resolved: pin.resolved,
1280
+ onClick: () => onOpen(pin.id)
1281
+ })
1282
+ }, pin.id);
1283
+ }),
1284
+ draft && draftBox ? /* @__PURE__ */ jsxs5(DraftAt, {
1285
+ box: draftBox,
1286
+ draft,
1287
+ scale,
1288
+ children: [
1289
+ /* @__PURE__ */ jsx6(CommentPin, {
1290
+ label: messages.newPin,
1291
+ active: true,
1292
+ resolved: false,
1293
+ draft: true
1294
+ }),
1295
+ /* @__PURE__ */ jsx6("div", {
1296
+ className: "absolute top-0",
1297
+ style: cardPlace(view.x + (draftBox.x + draft.point.x * draftBox.w) * zoom, view.width),
1298
+ children: /* @__PURE__ */ jsx6(DraftCard, {
1299
+ ...draft.anchor ? { anchor: draft.anchor } : {},
1300
+ onSubmit: onSubmitDraft,
1301
+ onCancel: onCancelDraft
1302
+ })
1303
+ })
1304
+ ]
1305
+ }) : null
1306
+ ]
1307
+ });
1308
+ });
1309
+ function DraftAt({
1310
+ box,
1311
+ draft,
1312
+ scale,
1313
+ children
1314
+ }) {
1315
+ return /* @__PURE__ */ jsx6("div", {
1316
+ className: "pointer-events-none absolute top-0 left-0",
1317
+ style: {
1318
+ transform: `translate(${box.x + draft.point.x * box.w}px, ${box.y + draft.point.y * box.h}px) ${scale}`,
1319
+ transformOrigin: "0 0"
1320
+ },
1321
+ children
1322
+ });
1323
+ }
1324
+ function viewOf(state) {
1325
+ return { x: state.transform[0] ?? 0, width: state.width };
1326
+ }
1327
+ function sameView(left, right) {
1328
+ return left.x === right.x && left.width === right.width;
1329
+ }
1330
+ function useBoardBoxes(ids) {
1331
+ const key = ids.join(`
1332
+ `);
1333
+ const select = useCallback((state) => {
1334
+ const boxes = new Map;
1335
+ for (const id of key ? key.split(`
1336
+ `) : []) {
1337
+ const node = state.nodeLookup.get(id);
1338
+ const w = node?.measured.width ?? node?.width;
1339
+ const h = node?.measured.height ?? node?.height;
1340
+ if (!node || w === undefined || h === undefined)
1341
+ continue;
1342
+ const { x, y } = node.internals.positionAbsolute;
1343
+ boxes.set(id, { x, y, w, h });
1344
+ }
1345
+ return boxes;
1346
+ }, [key]);
1347
+ return useStore(select, sameBoxes);
1348
+ }
1349
+ function sameBoxes(left, right) {
1350
+ if (left.size !== right.size)
1351
+ return false;
1352
+ for (const [id, box] of left) {
1353
+ const other = right.get(id);
1354
+ if (!other || other.x !== box.x || other.y !== box.y || other.w !== box.w || other.h !== box.h) {
1355
+ return false;
1356
+ }
1357
+ }
1358
+ return true;
1359
+ }
1360
+
1361
+ // src/artifacts/renderers/canvas/commenting.tsx
1362
+ import { boardElements } from "@sixb/core/artifacts/live";
1363
+ import { cn as cn6 } from "@sixb/ui/lib/utils";
1364
+ import { useQueryClient as useQueryClient2 } from "@tanstack/react-query";
1365
+ import { MessageSquare, MessageSquarePlus } from "lucide-react";
1366
+ import { useCallback as useCallback3, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
1367
+
1368
+ // src/artifacts/live/boards.ts
1369
+ import { LIVE_FILES } from "@sixb/core/artifacts/live";
1370
+ import { useCallback as useCallback2, useMemo as useMemo2, useSyncExternalStore as useSyncExternalStore3 } from "react";
1371
+ import * as Y from "yjs";
1372
+ function liveBoardSource(doc, path) {
1373
+ const entry = doc.getMap(LIVE_FILES).get(path);
1374
+ return entry instanceof Y.Text ? entry.toString() : null;
1375
+ }
1376
+ function liveStoredFiles(doc) {
1377
+ const files = new Map;
1378
+ doc.getMap(LIVE_FILES).forEach((entry, path) => {
1379
+ if (entry instanceof Y.Text || entry instanceof Y.Map)
1380
+ return;
1381
+ if (isFileRef(entry))
1382
+ files.set(path, entry);
1383
+ });
1384
+ return files;
1385
+ }
1386
+ function isFileRef(value) {
1387
+ return typeof value === "object" && value !== null && typeof value.blobId === "string";
1388
+ }
1389
+ function useLiveBoardSource(live, path) {
1390
+ const subscribe = useCallback2((listener) => {
1391
+ if (!live)
1392
+ return () => {};
1393
+ const files = live.doc.getMap(LIVE_FILES);
1394
+ let text = null;
1395
+ const follow = () => {
1396
+ text?.unobserve(listener);
1397
+ const entry = files.get(path);
1398
+ text = entry instanceof Y.Text ? entry : null;
1399
+ text?.observe(listener);
1400
+ };
1401
+ const onFiles = (event) => {
1402
+ if (!event.keysChanged.has(path))
1403
+ return;
1404
+ follow();
1405
+ listener();
1406
+ };
1407
+ follow();
1408
+ files.observe(onFiles);
1409
+ return () => {
1410
+ files.unobserve(onFiles);
1411
+ text?.unobserve(listener);
1412
+ };
1413
+ }, [live, path]);
1414
+ return useSyncExternalStore3(subscribe, () => live ? liveBoardSource(live.doc, path) : null, () => null);
1415
+ }
1416
+ function useLiveStoredFiles(live) {
1417
+ const subscribe = useCallback2((listener) => {
1418
+ if (!live)
1419
+ return () => {};
1420
+ const files = live.doc.getMap(LIVE_FILES);
1421
+ files.observe(listener);
1422
+ return () => files.unobserve(listener);
1423
+ }, [live]);
1424
+ const snapshot = useCallback2(() => live ? storedFilesKey(live.doc) : "", [live]);
1425
+ const key = useSyncExternalStore3(subscribe, snapshot, () => "");
1426
+ return useMemo2(() => live ? liveStoredFiles(live.doc) : new Map, [live, key]);
1427
+ }
1428
+ function storedFilesKey(doc) {
1429
+ return [...liveStoredFiles(doc)].map(([path, ref]) => `${path}:${ref.digest}`).join(`
1430
+ `);
1431
+ }
1432
+
1433
+ // src/artifacts/renderers/canvas/commenting.tsx
1434
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
1435
+ function useCanvasCommenting({
1436
+ artifactId,
1437
+ live,
1438
+ title,
1439
+ boards,
1440
+ revision
1441
+ }) {
1442
+ const messages = useArtifactMessages().canvas.comments;
1443
+ const queries = useQueryClient2();
1444
+ const view = useArtifactView();
1445
+ const user = useCurrentUser2();
1446
+ const agentDraft = useAgentDraft();
1447
+ const { threads, loading, failed } = useArtifactComments(artifactId);
1448
+ const nameOf = useCommentAuthors();
1449
+ const [commenting, setCommenting] = useState4(false);
1450
+ const [panel, setPanel] = useState4(false);
1451
+ const [filter, setFilter] = useState4("open");
1452
+ const [active, setActive] = useState4(null);
1453
+ const [draft, setDraft] = useState4(null);
1454
+ const titles = useMemo3(() => new Map(boards.map((board) => [board.id, board.title ?? board.id])), [boards]);
1455
+ const addresses = useRef3(new Map);
1456
+ const placeOf = useCallback3((thread) => {
1457
+ const { anchor } = thread.comment;
1458
+ const board = anchor.board ? boards.find((each) => each.id === anchor.board) : undefined;
1459
+ const name = anchor.board ? titles.get(anchor.board) ?? anchor.board : null;
1460
+ let gone = Boolean(anchor.board) && !board;
1461
+ if (board && anchor.element && live) {
1462
+ const source = liveBoardSource(live.doc, board.file);
1463
+ if (source !== null) {
1464
+ let known = addresses.current.get(board.file);
1465
+ if (known?.source !== source) {
1466
+ known = {
1467
+ source,
1468
+ addresses: new Set(boardElements(source).map((element) => element.address))
1469
+ };
1470
+ addresses.current.set(board.file, known);
1471
+ }
1472
+ gone = !known.addresses.has(anchor.element);
1473
+ }
1474
+ }
1475
+ return {
1476
+ board: name,
1477
+ element: anchor.element ? anchor.label ?? null : null,
1478
+ gone
1479
+ };
1480
+ }, [boards, titles, live]);
1481
+ const pins = useMemo3(() => threads.flatMap((thread) => {
1482
+ const { comment } = thread;
1483
+ const resolved = Boolean(comment.resolvedAt);
1484
+ if (!comment.anchor.board)
1485
+ return [];
1486
+ if (resolved !== (filter === "resolved"))
1487
+ return [];
1488
+ return [
1489
+ {
1490
+ id: comment.id,
1491
+ number: thread.number,
1492
+ board: comment.anchor.board,
1493
+ ...comment.anchor.point ? { point: comment.anchor.point } : {},
1494
+ resolved,
1495
+ label: messages.pin(thread.number, nameOf(comment)?.name ?? messages.someone)
1496
+ }
1497
+ ];
1498
+ }), [threads, filter, messages, nameOf]);
1499
+ const pick = useCallback3((board, place, where) => setDraft({
1500
+ board,
1501
+ ...place,
1502
+ anchor: place.anchor ?? (place.label ? `\u201C${place.label}\u201D` : titles.get(board) ?? board),
1503
+ where
1504
+ }), [titles]);
1505
+ const submitDraft = useCallback3(async (body) => {
1506
+ if (!draft || !artifactId)
1507
+ return;
1508
+ const created = await addComment(queries, artifactId, {
1509
+ body,
1510
+ anchor: {
1511
+ board: draft.board,
1512
+ ...draft.element ? { element: draft.element } : {},
1513
+ ...draft.label ? { label: draft.label } : {},
1514
+ point: draft.point,
1515
+ revision
1516
+ }
1517
+ });
1518
+ setDraft(null);
1519
+ setActive(created.id);
1520
+ setFilter("open");
1521
+ setPanel(true);
1522
+ }, [draft, artifactId, queries, revision]);
1523
+ const reply = useCallback3(async (thread, body) => {
1524
+ if (!artifactId)
1525
+ return;
1526
+ await addComment(queries, artifactId, { body, parentId: thread.comment.id });
1527
+ }, [artifactId, queries]);
1528
+ const resolve = useCallback3(async (thread, resolved) => {
1529
+ if (!artifactId)
1530
+ return;
1531
+ await resolveComment(queries, artifactId, thread.comment.id, resolved);
1532
+ if (resolved)
1533
+ setActive((current) => current === thread.comment.id ? null : current);
1534
+ }, [artifactId, queries]);
1535
+ const remove = useCallback3(async (thread) => {
1536
+ if (!artifactId)
1537
+ return;
1538
+ await deleteComment(queries, artifactId, thread.comment.id);
1539
+ setActive((current) => current === thread.comment.id ? null : current);
1540
+ }, [artifactId, queries]);
1541
+ const send = useMemo3(() => agentDraft && artifactId ? (chosen) => {
1542
+ if (chosen.length === 0)
1543
+ return;
1544
+ const { context } = commentsContext({
1545
+ artifactId,
1546
+ title,
1547
+ label: (count) => messages.contextLabel(count, title),
1548
+ threads: chosen
1549
+ });
1550
+ agentDraft({ text: messages.askAgent, context });
1551
+ } : null, [agentDraft, messages, title, artifactId]);
1552
+ const access = view?.access ?? "read";
1553
+ const userId = user?.id ?? null;
1554
+ const canManage = useCallback3((comment) => canManageComment(comment, access, userId), [access, userId]);
1555
+ return {
1556
+ enabled: artifactId !== null,
1557
+ threads,
1558
+ loading,
1559
+ failed,
1560
+ open: threads.filter((thread) => !thread.comment.resolvedAt).length,
1561
+ pins,
1562
+ nameOf,
1563
+ placeOf,
1564
+ canManage,
1565
+ commenting,
1566
+ setCommenting,
1567
+ toggleCommenting: () => {
1568
+ setCommenting((current) => !current);
1569
+ setDraft(null);
1570
+ },
1571
+ panel,
1572
+ setPanel,
1573
+ filter,
1574
+ setFilter,
1575
+ active,
1576
+ setActive,
1577
+ draft,
1578
+ pick,
1579
+ cancelDraft: () => setDraft(null),
1580
+ submitDraft,
1581
+ reply,
1582
+ resolve,
1583
+ remove,
1584
+ send
1585
+ };
1586
+ }
1587
+ function CommentTools({
1588
+ commenting,
1589
+ className
1590
+ }) {
1591
+ const messages = useArtifactMessages().canvas.comments;
1592
+ const active = commenting.commenting;
1593
+ return /* @__PURE__ */ jsxs6("div", {
1594
+ className: cn6("flex items-center gap-0.5 rounded-xl border border-border bg-background/95 p-1 shadow-[0_1px_2px_rgb(0_0_0/0.06),0_8px_24px_-12px_rgb(0_0_0/0.25)] backdrop-blur", className),
1595
+ role: "group",
1596
+ "aria-label": messages.title,
1597
+ children: [
1598
+ /* @__PURE__ */ jsx7("button", {
1599
+ type: "button",
1600
+ "aria-label": messages.tool,
1601
+ title: messages.toolHint,
1602
+ "aria-pressed": active,
1603
+ "aria-keyshortcuts": "C",
1604
+ onClick: commenting.toggleCommenting,
1605
+ className: cn6("flex size-8 items-center justify-center rounded-lg text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4", active && "bg-primary text-primary-foreground hover:bg-primary/90 hover:text-primary-foreground"),
1606
+ children: /* @__PURE__ */ jsx7(MessageSquarePlus, {
1607
+ "aria-hidden": "true"
1608
+ })
1609
+ }),
1610
+ /* @__PURE__ */ jsxs6("button", {
1611
+ type: "button",
1612
+ "aria-label": messages.toggle(commenting.open),
1613
+ title: messages.toggle(commenting.open),
1614
+ "aria-pressed": commenting.panel,
1615
+ onClick: () => commenting.setPanel(!commenting.panel),
1616
+ className: cn6("flex h-8 items-center gap-1.5 rounded-lg px-2 text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4", commenting.panel && "bg-muted text-foreground"),
1617
+ children: [
1618
+ /* @__PURE__ */ jsx7(MessageSquare, {
1619
+ "aria-hidden": "true"
1620
+ }),
1621
+ commenting.open > 0 ? /* @__PURE__ */ jsx7("span", {
1622
+ className: "text-xs font-medium tabular-nums",
1623
+ children: commenting.open
1624
+ }) : null
1625
+ ]
1626
+ })
1627
+ ]
1628
+ });
1629
+ }
1630
+ function CommentModeHint({ onExit }) {
1631
+ const messages = useArtifactMessages().canvas.comments;
1632
+ return /* @__PURE__ */ jsxs6("div", {
1633
+ role: "status",
1634
+ className: "pointer-events-auto flex max-w-[calc(100vw-2rem)] items-center gap-2 rounded-full border border-border bg-background/95 py-1 pr-1 pl-3 text-xs text-muted-foreground shadow-[0_1px_2px_rgb(0_0_0/0.06),0_8px_24px_-12px_rgb(0_0_0/0.25)] backdrop-blur motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-bottom-1",
1635
+ children: [
1636
+ /* @__PURE__ */ jsx7(MessageSquarePlus, {
1637
+ className: "size-3.5 shrink-0 text-foreground",
1638
+ "aria-hidden": "true"
1639
+ }),
1640
+ /* @__PURE__ */ jsx7("span", {
1641
+ className: "min-w-0 truncate",
1642
+ children: messages.modeHint
1643
+ }),
1644
+ /* @__PURE__ */ jsx7("button", {
1645
+ type: "button",
1646
+ onClick: onExit,
1647
+ "aria-label": messages.exit,
1648
+ title: messages.exit,
1649
+ className: "shrink-0 rounded-full border border-border bg-muted px-1.5 font-mono text-[10px] leading-4 font-medium text-foreground outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring",
1650
+ children: "Esc"
1651
+ })
1652
+ ]
1653
+ });
1654
+ }
1655
+
1656
+ // src/artifacts/renderers/canvas/comments-panel.tsx
1657
+ import {
1658
+ AlertDialog,
1659
+ AlertDialogAction,
1660
+ AlertDialogCancel,
1661
+ AlertDialogContent,
1662
+ AlertDialogDescription,
1663
+ AlertDialogFooter,
1664
+ AlertDialogHeader,
1665
+ AlertDialogTitle,
1666
+ Checkbox,
1667
+ DropdownMenu,
1668
+ DropdownMenuContent,
1669
+ DropdownMenuItem,
1670
+ DropdownMenuTrigger
1671
+ } from "@sixb/ui/components";
1672
+ import { useLocale } from "@sixb/ui/lib/i18n";
1673
+ import { cn as cn7 } from "@sixb/ui/lib/utils";
1674
+ import {
1675
+ Check,
1676
+ CornerDownRight,
1677
+ MessageSquare as MessageSquare2,
1678
+ MessageSquarePlus as MessageSquarePlus2,
1679
+ MoreHorizontal,
1680
+ RotateCcw,
1681
+ Sparkles,
1682
+ Trash2,
1683
+ X as X2
1684
+ } from "lucide-react";
1685
+ import {
1686
+ forwardRef,
1687
+ useEffect as useEffect2,
1688
+ useRef as useRef4,
1689
+ useState as useState5
1690
+ } from "react";
1691
+ import { jsx as jsx8, jsxs as jsxs7, Fragment as Fragment4 } from "react/jsx-runtime";
1692
+ function CommentsPanel({
1693
+ threads,
1694
+ loading,
1695
+ failed,
1696
+ filter,
1697
+ active,
1698
+ placeOf,
1699
+ nameOf,
1700
+ canManage,
1701
+ onFilter,
1702
+ onActivate,
1703
+ onReply,
1704
+ onResolve,
1705
+ onDelete,
1706
+ onSend,
1707
+ onClose
1708
+ }) {
1709
+ const messages = useArtifactMessages().canvas.comments;
1710
+ const open = threads.filter((thread) => !thread.comment.resolvedAt);
1711
+ const resolved = threads.filter((thread) => thread.comment.resolvedAt);
1712
+ const shown = filter === "open" ? open : resolved;
1713
+ const [choosing, setChoosing] = useState5(false);
1714
+ const [chosen, setChosen] = useState5(new Set);
1715
+ const [sent, setSent] = useState5(false);
1716
+ const [failure, setFailure] = useState5(null);
1717
+ useEffect2(() => {
1718
+ setChosen((current) => {
1719
+ const ids = new Set(shown.map((thread) => thread.comment.id));
1720
+ const kept = [...current].filter((id) => ids.has(id));
1721
+ return kept.length === current.size ? current : new Set(kept);
1722
+ });
1723
+ }, [shown]);
1724
+ useEffect2(() => {
1725
+ if (!sent)
1726
+ return;
1727
+ const timer = window.setTimeout(() => setSent(false), 4000);
1728
+ return () => window.clearTimeout(timer);
1729
+ }, [sent]);
1730
+ const act = async (action) => {
1731
+ setFailure(null);
1732
+ try {
1733
+ await action();
1734
+ } catch (error) {
1735
+ setFailure(messages.failures[error instanceof CommentActionError ? error.failure : "failed"]);
1736
+ }
1737
+ };
1738
+ const send = () => {
1739
+ if (!onSend)
1740
+ return;
1741
+ onSend(shown.filter((thread) => chosen.has(thread.comment.id)));
1742
+ setChoosing(false);
1743
+ setChosen(new Set);
1744
+ setSent(true);
1745
+ };
1746
+ return /* @__PURE__ */ jsxs7("aside", {
1747
+ "aria-label": messages.panel,
1748
+ "data-comments-panel": "",
1749
+ className: cn7("absolute inset-x-0 bottom-0 z-30 flex max-h-[68%] flex-col rounded-t-2xl border-t border-border bg-background text-foreground shadow-[0_-12px_32px_-18px_rgb(0_0_0/0.35)]", "motion-safe:animate-in motion-safe:slide-in-from-bottom-4 motion-safe:fade-in-0", "@3xl/canvas:relative @3xl/canvas:inset-auto @3xl/canvas:z-auto @3xl/canvas:h-full @3xl/canvas:max-h-none @3xl/canvas:w-[22rem] @3xl/canvas:shrink-0 @3xl/canvas:rounded-none @3xl/canvas:border-t-0 @3xl/canvas:border-l @3xl/canvas:shadow-none @3xl/canvas:slide-in-from-right-4 @3xl/canvas:slide-in-from-bottom-0"),
1750
+ children: [
1751
+ /* @__PURE__ */ jsx8("span", {
1752
+ "aria-hidden": "true",
1753
+ className: "mx-auto mt-2 h-1 w-9 shrink-0 rounded-full bg-border @3xl/canvas:hidden"
1754
+ }),
1755
+ /* @__PURE__ */ jsxs7("header", {
1756
+ className: "flex h-12 shrink-0 items-center gap-2 px-3",
1757
+ children: [
1758
+ /* @__PURE__ */ jsx8("h2", {
1759
+ className: "m-0 text-sm font-semibold",
1760
+ children: messages.title
1761
+ }),
1762
+ open.length > 0 ? /* @__PURE__ */ jsx8("span", {
1763
+ className: "rounded-full bg-muted px-1.5 text-xs font-medium text-muted-foreground tabular-nums",
1764
+ children: open.length
1765
+ }) : null,
1766
+ /* @__PURE__ */ jsxs7("div", {
1767
+ className: "ml-auto flex items-center gap-1",
1768
+ children: [
1769
+ onSend && filter === "open" && open.length > 0 && !choosing ? /* @__PURE__ */ jsxs7("button", {
1770
+ type: "button",
1771
+ onClick: () => setChoosing(true),
1772
+ className: "flex h-7 items-center gap-1.5 rounded-lg px-2 text-xs font-medium text-primary outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--primary)_10%,transparent)] focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5",
1773
+ children: [
1774
+ /* @__PURE__ */ jsx8(Sparkles, {
1775
+ "aria-hidden": "true"
1776
+ }),
1777
+ messages.select
1778
+ ]
1779
+ }) : null,
1780
+ /* @__PURE__ */ jsx8(IconButton, {
1781
+ label: messages.close,
1782
+ onClick: onClose,
1783
+ children: /* @__PURE__ */ jsx8(X2, {})
1784
+ })
1785
+ ]
1786
+ })
1787
+ ]
1788
+ }),
1789
+ /* @__PURE__ */ jsx8("div", {
1790
+ className: "flex shrink-0 items-center gap-2 px-3 pb-2",
1791
+ children: /* @__PURE__ */ jsx8("div", {
1792
+ role: "group",
1793
+ "aria-label": messages.filter,
1794
+ className: "flex flex-1 items-center rounded-lg bg-muted/70 p-0.5",
1795
+ children: ["open", "resolved"].map((each) => /* @__PURE__ */ jsxs7("button", {
1796
+ type: "button",
1797
+ "aria-pressed": filter === each,
1798
+ onClick: () => {
1799
+ onFilter(each);
1800
+ setChoosing(false);
1801
+ },
1802
+ className: cn7("flex h-7 flex-1 items-center justify-center gap-1.5 rounded-md text-xs font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring", filter === each && "bg-background text-foreground shadow-sm"),
1803
+ children: [
1804
+ messages[each],
1805
+ /* @__PURE__ */ jsx8("span", {
1806
+ className: "tabular-nums opacity-60",
1807
+ children: (each === "open" ? open : resolved).length
1808
+ })
1809
+ ]
1810
+ }, each))
1811
+ })
1812
+ }),
1813
+ choosing ? /* @__PURE__ */ jsx8("p", {
1814
+ className: "m-0 shrink-0 px-4 pb-2 text-xs text-muted-foreground",
1815
+ children: messages.chooseHint
1816
+ }) : null,
1817
+ failure ? /* @__PURE__ */ jsx8("p", {
1818
+ role: "alert",
1819
+ className: "m-0 shrink-0 px-4 pb-2 text-xs text-destructive",
1820
+ children: failure
1821
+ }) : null,
1822
+ /* @__PURE__ */ jsx8("div", {
1823
+ className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-2 pb-3",
1824
+ children: failed ? /* @__PURE__ */ jsx8(Empty, {
1825
+ title: messages.loadFailed
1826
+ }) : loading ? /* @__PURE__ */ jsx8("div", {
1827
+ className: "flex flex-col gap-2 p-1",
1828
+ "aria-busy": "true",
1829
+ children: [0, 1].map((index) => /* @__PURE__ */ jsx8("div", {
1830
+ className: "h-20 animate-pulse rounded-xl bg-muted/60"
1831
+ }, index))
1832
+ }) : shown.length === 0 ? filter === "open" ? resolved.length > 0 ? /* @__PURE__ */ jsx8(Empty, {
1833
+ title: messages.emptyOpen
1834
+ }) : /* @__PURE__ */ jsx8(Empty, {
1835
+ title: messages.empty,
1836
+ hint: /* @__PURE__ */ jsxs7(Fragment4, {
1837
+ children: [
1838
+ messages.emptyHint.before,
1839
+ " ",
1840
+ /* @__PURE__ */ jsx8(MessageSquarePlus2, {
1841
+ className: "inline size-3.5 align-[-0.2em] text-foreground",
1842
+ "aria-label": messages.tool
1843
+ }),
1844
+ " ",
1845
+ messages.emptyHint.after
1846
+ ]
1847
+ })
1848
+ }) : /* @__PURE__ */ jsx8(Empty, {
1849
+ title: messages.emptyResolved
1850
+ }) : /* @__PURE__ */ jsx8("ul", {
1851
+ className: "m-0 flex list-none flex-col gap-1.5 p-0",
1852
+ children: shown.map((thread) => /* @__PURE__ */ jsx8(ThreadCard, {
1853
+ thread,
1854
+ place: placeOf(thread),
1855
+ active: active === thread.comment.id,
1856
+ choosing,
1857
+ chosen: chosen.has(thread.comment.id),
1858
+ nameOf,
1859
+ manages: canManage(thread.comment),
1860
+ onChoose: (next) => setChosen((current) => {
1861
+ const updated = new Set(current);
1862
+ if (next)
1863
+ updated.add(thread.comment.id);
1864
+ else
1865
+ updated.delete(thread.comment.id);
1866
+ return updated;
1867
+ }),
1868
+ onActivate: () => onActivate(thread.comment.id),
1869
+ onReply: (body) => onReply(thread, body),
1870
+ onResolve: (next) => act(() => onResolve(thread, next)),
1871
+ onDelete: () => act(() => onDelete(thread))
1872
+ }, thread.comment.id))
1873
+ })
1874
+ }),
1875
+ choosing ? /* @__PURE__ */ jsxs7("footer", {
1876
+ className: "flex shrink-0 items-center gap-2 border-t border-border px-3 py-2.5 pb-[max(0.625rem,env(safe-area-inset-bottom))]",
1877
+ children: [
1878
+ /* @__PURE__ */ jsx8("button", {
1879
+ type: "button",
1880
+ onClick: () => {
1881
+ setChoosing(false);
1882
+ setChosen(new Set);
1883
+ },
1884
+ className: "h-8 rounded-lg px-3 text-sm text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
1885
+ children: messages.cancelSelect
1886
+ }),
1887
+ /* @__PURE__ */ jsxs7("button", {
1888
+ type: "button",
1889
+ disabled: chosen.size === 0,
1890
+ onClick: send,
1891
+ className: "ml-auto flex h-8 items-center gap-1.5 rounded-lg bg-primary px-3 text-sm font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-40 [&_svg]:size-4",
1892
+ children: [
1893
+ /* @__PURE__ */ jsx8(Sparkles, {
1894
+ "aria-hidden": "true"
1895
+ }),
1896
+ messages.send(chosen.size)
1897
+ ]
1898
+ })
1899
+ ]
1900
+ }) : sent ? /* @__PURE__ */ jsxs7("p", {
1901
+ role: "status",
1902
+ className: "m-0 flex shrink-0 items-center gap-2 border-t border-border px-4 py-2.5 text-xs text-muted-foreground",
1903
+ children: [
1904
+ /* @__PURE__ */ jsx8(Check, {
1905
+ className: "size-3.5 text-primary",
1906
+ "aria-hidden": "true"
1907
+ }),
1908
+ messages.sent
1909
+ ]
1910
+ }) : null
1911
+ ]
1912
+ });
1913
+ }
1914
+ function ThreadCard({
1915
+ thread,
1916
+ place,
1917
+ active,
1918
+ choosing,
1919
+ chosen,
1920
+ nameOf,
1921
+ manages,
1922
+ onChoose,
1923
+ onActivate,
1924
+ onReply,
1925
+ onResolve,
1926
+ onDelete
1927
+ }) {
1928
+ const messages = useArtifactMessages().canvas.comments;
1929
+ const { comment, replies, number } = thread;
1930
+ const resolved = Boolean(comment.resolvedAt);
1931
+ const [replying, setReplying] = useState5(false);
1932
+ const [confirming, setConfirming] = useState5(false);
1933
+ const card = useRef4(null);
1934
+ useEffect2(() => {
1935
+ if (active)
1936
+ card.current?.scrollIntoView({ block: "nearest", behavior: "smooth" });
1937
+ }, [active]);
1938
+ return /* @__PURE__ */ jsxs7("li", {
1939
+ children: [
1940
+ /* @__PURE__ */ jsxs7("article", {
1941
+ ref: card,
1942
+ "aria-label": messages.pin(number, nameOf(comment)?.name ?? messages.someone),
1943
+ "data-comment-thread": comment.id,
1944
+ "data-active": active ? "" : undefined,
1945
+ className: cn7("group relative flex gap-2.5 rounded-xl px-2.5 py-2.5 transition-colors", active ? "bg-[color-mix(in_oklab,var(--primary)_7%,var(--background))] ring-1 ring-[color-mix(in_oklab,var(--primary)_30%,transparent)]" : "hover:bg-muted/50", resolved && "opacity-80"),
1946
+ children: [
1947
+ choosing ? /* @__PURE__ */ jsx8(Checkbox, {
1948
+ checked: chosen,
1949
+ onCheckedChange: (value) => onChoose(value === true),
1950
+ "aria-label": messages.selectLabel(number),
1951
+ className: "mt-0.5"
1952
+ }) : /* @__PURE__ */ jsx8("span", {
1953
+ "aria-hidden": "true",
1954
+ className: cn7("mt-px flex h-5 min-w-5 items-center justify-center rounded-full rounded-bl-[3px] px-1 text-[10.5px] font-semibold tabular-nums", active ? "bg-primary text-primary-foreground" : resolved ? "bg-muted text-muted-foreground" : "bg-foreground text-background"),
1955
+ children: number
1956
+ }),
1957
+ /* @__PURE__ */ jsxs7("div", {
1958
+ className: "min-w-0 flex-1",
1959
+ children: [
1960
+ /* @__PURE__ */ jsxs7("div", {
1961
+ className: "flex items-start gap-1",
1962
+ children: [
1963
+ /* @__PURE__ */ jsx8("button", {
1964
+ type: "button",
1965
+ onClick: onActivate,
1966
+ className: "min-w-0 flex-1 rounded-sm text-left text-xs text-muted-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring",
1967
+ children: /* @__PURE__ */ jsx8(Where, {
1968
+ place
1969
+ })
1970
+ }),
1971
+ manages ? /* @__PURE__ */ jsxs7("div", {
1972
+ className: "-mt-1 -mr-1 flex shrink-0 items-center opacity-100 transition-opacity @3xl/canvas:opacity-0 @3xl/canvas:group-focus-within:opacity-100 @3xl/canvas:group-hover:opacity-100 @3xl/canvas:group-data-[active]:opacity-100",
1973
+ children: [
1974
+ /* @__PURE__ */ jsx8(IconButton, {
1975
+ label: resolved ? messages.reopen : messages.resolve,
1976
+ onClick: () => void onResolve(!resolved),
1977
+ children: resolved ? /* @__PURE__ */ jsx8(RotateCcw, {}) : /* @__PURE__ */ jsx8(Check, {})
1978
+ }),
1979
+ /* @__PURE__ */ jsxs7(DropdownMenu, {
1980
+ modal: false,
1981
+ children: [
1982
+ /* @__PURE__ */ jsx8(DropdownMenuTrigger, {
1983
+ asChild: true,
1984
+ children: /* @__PURE__ */ jsx8(IconButton, {
1985
+ label: messages.more,
1986
+ children: /* @__PURE__ */ jsx8(MoreHorizontal, {})
1987
+ })
1988
+ }),
1989
+ /* @__PURE__ */ jsx8(DropdownMenuContent, {
1990
+ align: "end",
1991
+ children: /* @__PURE__ */ jsxs7(DropdownMenuItem, {
1992
+ variant: "destructive",
1993
+ onSelect: () => setConfirming(true),
1994
+ children: [
1995
+ /* @__PURE__ */ jsx8(Trash2, {
1996
+ "aria-hidden": "true"
1997
+ }),
1998
+ messages.delete
1999
+ ]
2000
+ })
2001
+ })
2002
+ ]
2003
+ })
2004
+ ]
2005
+ }) : null
2006
+ ]
2007
+ }),
2008
+ /* @__PURE__ */ jsx8(Message, {
2009
+ comment,
2010
+ nameOf
2011
+ }),
2012
+ replies.map((reply) => /* @__PURE__ */ jsx8("div", {
2013
+ className: "mt-2.5 border-l-2 border-border/70 pl-2.5",
2014
+ children: /* @__PURE__ */ jsx8(Message, {
2015
+ comment: reply,
2016
+ nameOf
2017
+ })
2018
+ }, reply.id)),
2019
+ resolved ? null : replying || active ? /* @__PURE__ */ jsx8(CommentComposer, {
2020
+ compact: true,
2021
+ autoFocus: replying,
2022
+ placeholder: messages.replyPlaceholder,
2023
+ onSubmit: async (body) => {
2024
+ await onReply(body);
2025
+ setReplying(false);
2026
+ },
2027
+ onCancel: () => setReplying(false),
2028
+ className: "mt-2.5"
2029
+ }) : /* @__PURE__ */ jsxs7("button", {
2030
+ type: "button",
2031
+ onClick: () => setReplying(true),
2032
+ className: "mt-1.5 flex items-center gap-1 rounded-sm text-xs text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3",
2033
+ children: [
2034
+ /* @__PURE__ */ jsx8(CornerDownRight, {
2035
+ "aria-hidden": "true"
2036
+ }),
2037
+ replies.length > 0 ? messages.replies(replies.length) : messages.reply
2038
+ ]
2039
+ })
2040
+ ]
2041
+ })
2042
+ ]
2043
+ }),
2044
+ /* @__PURE__ */ jsx8(AlertDialog, {
2045
+ open: confirming,
2046
+ onOpenChange: setConfirming,
2047
+ children: /* @__PURE__ */ jsxs7(AlertDialogContent, {
2048
+ children: [
2049
+ /* @__PURE__ */ jsxs7(AlertDialogHeader, {
2050
+ children: [
2051
+ /* @__PURE__ */ jsx8(AlertDialogTitle, {
2052
+ children: messages.deleteTitle
2053
+ }),
2054
+ /* @__PURE__ */ jsx8(AlertDialogDescription, {
2055
+ children: messages.deleteDescription
2056
+ })
2057
+ ]
2058
+ }),
2059
+ /* @__PURE__ */ jsxs7(AlertDialogFooter, {
2060
+ children: [
2061
+ /* @__PURE__ */ jsx8(AlertDialogCancel, {
2062
+ children: messages.cancel
2063
+ }),
2064
+ /* @__PURE__ */ jsx8(AlertDialogAction, {
2065
+ variant: "destructive",
2066
+ onClick: () => void onDelete(),
2067
+ children: messages.delete
2068
+ })
2069
+ ]
2070
+ })
2071
+ ]
2072
+ })
2073
+ })
2074
+ ]
2075
+ });
2076
+ }
2077
+ function Where({ place }) {
2078
+ const messages = useArtifactMessages().canvas.comments;
2079
+ return /* @__PURE__ */ jsxs7("span", {
2080
+ className: "flex min-w-0 flex-wrap items-center gap-x-1 gap-y-0.5",
2081
+ children: [
2082
+ /* @__PURE__ */ jsx8("span", {
2083
+ className: "truncate font-medium text-foreground/80",
2084
+ children: place.board ?? messages.onCanvas
2085
+ }),
2086
+ place.board ? /* @__PURE__ */ jsxs7(Fragment4, {
2087
+ children: [
2088
+ /* @__PURE__ */ jsx8("span", {
2089
+ "aria-hidden": "true",
2090
+ children: "\xB7"
2091
+ }),
2092
+ /* @__PURE__ */ jsx8("span", {
2093
+ className: cn7("min-w-0 truncate", place.gone && "line-through decoration-1"),
2094
+ children: place.element ? `\u201C${place.element}\u201D` : messages.wholeBoard
2095
+ })
2096
+ ]
2097
+ }) : null,
2098
+ place.gone ? /* @__PURE__ */ jsx8("span", {
2099
+ className: "rounded-sm bg-muted px-1 text-[10.5px] text-muted-foreground",
2100
+ children: messages.elementGone
2101
+ }) : null
2102
+ ]
2103
+ });
2104
+ }
2105
+ function Message({
2106
+ comment,
2107
+ nameOf
2108
+ }) {
2109
+ const messages = useArtifactMessages().canvas.comments;
2110
+ const when = useWhen();
2111
+ const author = nameOf(comment);
2112
+ const name = author ? author.you ? messages.you : author.name : messages.someone;
2113
+ return /* @__PURE__ */ jsxs7("div", {
2114
+ className: "mt-1.5",
2115
+ children: [
2116
+ /* @__PURE__ */ jsxs7("div", {
2117
+ className: "flex items-center gap-1.5 text-xs",
2118
+ children: [
2119
+ author?.agent ? /* @__PURE__ */ jsx8("span", {
2120
+ className: "flex size-5 shrink-0 items-center justify-center rounded-full bg-[color-mix(in_oklab,var(--primary)_14%,var(--background))] text-primary",
2121
+ children: /* @__PURE__ */ jsx8(Sparkles, {
2122
+ className: "size-3",
2123
+ "aria-hidden": "true"
2124
+ })
2125
+ }) : /* @__PURE__ */ jsx8(PersonAvatar, {
2126
+ name: author?.name || name,
2127
+ size: "xs"
2128
+ }),
2129
+ /* @__PURE__ */ jsx8("span", {
2130
+ className: "truncate font-medium text-foreground",
2131
+ children: name
2132
+ }),
2133
+ author?.guest ? /* @__PURE__ */ jsx8(GuestBadge, {}) : null,
2134
+ /* @__PURE__ */ jsx8("time", {
2135
+ dateTime: comment.createdAt,
2136
+ className: "shrink-0 text-muted-foreground",
2137
+ children: when(comment.createdAt)
2138
+ })
2139
+ ]
2140
+ }),
2141
+ /* @__PURE__ */ jsx8("p", {
2142
+ className: "m-0 mt-1 text-sm leading-5 break-words whitespace-pre-wrap text-foreground",
2143
+ children: comment.body
2144
+ })
2145
+ ]
2146
+ });
2147
+ }
2148
+ function useWhen() {
2149
+ const locale = useLocale();
2150
+ return (iso) => {
2151
+ const date = new Date(iso);
2152
+ const today = date.toDateString() === new Date().toDateString();
2153
+ return date.toLocaleString(locale, {
2154
+ ...today ? {} : { month: "short", day: "numeric" },
2155
+ hour: "numeric",
2156
+ minute: "2-digit"
2157
+ });
2158
+ };
2159
+ }
2160
+ function Empty({ title, hint }) {
2161
+ return /* @__PURE__ */ jsxs7("div", {
2162
+ className: "flex flex-col items-center gap-2 px-6 py-10 text-center",
2163
+ children: [
2164
+ /* @__PURE__ */ jsx8("span", {
2165
+ className: "flex size-10 items-center justify-center rounded-full bg-muted text-muted-foreground",
2166
+ children: /* @__PURE__ */ jsx8(MessageSquare2, {
2167
+ className: "size-4",
2168
+ "aria-hidden": "true"
2169
+ })
2170
+ }),
2171
+ /* @__PURE__ */ jsx8("p", {
2172
+ className: "m-0 text-sm font-medium text-foreground",
2173
+ children: title
2174
+ }),
2175
+ hint ? /* @__PURE__ */ jsx8("p", {
2176
+ className: "m-0 max-w-[24ch] text-xs text-muted-foreground",
2177
+ children: hint
2178
+ }) : null
2179
+ ]
2180
+ });
2181
+ }
2182
+ var IconButton = forwardRef(function IconButton({ label, children, ...props }, ref) {
2183
+ return /* @__PURE__ */ jsx8("button", {
2184
+ ref,
2185
+ type: "button",
2186
+ "aria-label": label,
2187
+ title: label,
2188
+ className: "flex size-7 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-muted [&_svg]:size-4",
2189
+ ...props,
2190
+ children
2191
+ });
2192
+ });
2193
+
2194
+ // src/artifacts/renderers/canvas/controls.tsx
2195
+ import { Panel, useReactFlow, useStore as useStore2 } from "@xyflow/react";
2196
+ import { Maximize, Minus, Plus } from "lucide-react";
2197
+ import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
2198
+ var DURATION = 220;
2199
+ function CanvasControls({ padding }) {
2200
+ const messages = useArtifactMessages().canvas;
2201
+ const { zoomIn, zoomOut, zoomTo, fitView } = useReactFlow();
2202
+ const zoom = useStore2((state) => state.transform[2]);
2203
+ return /* @__PURE__ */ jsx9(Panel, {
2204
+ position: "bottom-left",
2205
+ className: "!m-3",
2206
+ children: /* @__PURE__ */ jsxs8("div", {
2207
+ className: "flex items-center gap-0.5 rounded-xl border border-border bg-background/90 p-1 shadow-[0_1px_2px_rgb(0_0_0/0.06),0_8px_24px_-12px_rgb(0_0_0/0.25)] backdrop-blur",
2208
+ children: [
2209
+ /* @__PURE__ */ jsx9(Control, {
2210
+ label: messages.zoomOut,
2211
+ onClick: () => zoomOut({ duration: DURATION }),
2212
+ children: /* @__PURE__ */ jsx9(Minus, {
2213
+ className: "size-4",
2214
+ "aria-hidden": "true"
2215
+ })
2216
+ }),
2217
+ /* @__PURE__ */ jsxs8("button", {
2218
+ type: "button",
2219
+ title: messages.actualSize,
2220
+ onClick: () => void zoomTo(1, { duration: DURATION }),
2221
+ className: "h-8 w-12 rounded-lg text-center text-xs font-medium text-muted-foreground tabular-nums outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
2222
+ children: [
2223
+ /* @__PURE__ */ jsx9("span", {
2224
+ "aria-live": "polite",
2225
+ children: messages.zoom(Math.round(zoom * 100))
2226
+ }),
2227
+ /* @__PURE__ */ jsxs8("span", {
2228
+ className: "sr-only",
2229
+ children: [
2230
+ ", ",
2231
+ messages.actualSize
2232
+ ]
2233
+ })
2234
+ ]
2235
+ }),
2236
+ /* @__PURE__ */ jsx9(Control, {
2237
+ label: messages.zoomIn,
2238
+ onClick: () => zoomIn({ duration: DURATION }),
2239
+ children: /* @__PURE__ */ jsx9(Plus, {
2240
+ className: "size-4",
2241
+ "aria-hidden": "true"
2242
+ })
2243
+ }),
2244
+ /* @__PURE__ */ jsx9("span", {
2245
+ className: "mx-1 h-5 w-px bg-border",
2246
+ "aria-hidden": "true"
2247
+ }),
2248
+ /* @__PURE__ */ jsxs8(Control, {
2249
+ label: messages.fitView,
2250
+ onClick: () => void fitView({ padding, duration: DURATION }),
2251
+ wide: true,
2252
+ children: [
2253
+ /* @__PURE__ */ jsx9(Maximize, {
2254
+ className: "size-3.5",
2255
+ "aria-hidden": "true"
2256
+ }),
2257
+ /* @__PURE__ */ jsx9("span", {
2258
+ className: "text-xs font-medium",
2259
+ children: messages.fit
2260
+ })
2261
+ ]
2262
+ })
2263
+ ]
2264
+ })
2265
+ });
2266
+ }
2267
+ function Control({
2268
+ label,
2269
+ onClick,
2270
+ wide = false,
2271
+ children
2272
+ }) {
2273
+ return /* @__PURE__ */ jsx9("button", {
2274
+ type: "button",
2275
+ "aria-label": label,
2276
+ title: label,
2277
+ onClick,
2278
+ className: wide ? "flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring" : "flex size-8 items-center justify-center rounded-lg text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
2279
+ children
2280
+ });
2281
+ }
2282
+
2283
+ // src/artifacts/renderers/canvas/edit-mode.tsx
2284
+ import {
2285
+ applyEdgeChanges,
2286
+ applyNodeChanges,
2287
+ ConnectionMode,
2288
+ useStoreApi as useStoreApi3
2289
+ } from "@xyflow/react";
2290
+ import {
2291
+ useCallback as useCallback4,
2292
+ useEffect as useEffect4,
2293
+ useMemo as useMemo4,
2294
+ useRef as useRef5,
2295
+ useState as useState7
2296
+ } from "react";
2297
+
2298
+ // src/artifacts/renderers/canvas/toolbar.tsx
2299
+ import {
2300
+ DropdownMenu as DropdownMenu2,
2301
+ DropdownMenuContent as DropdownMenuContent2,
2302
+ DropdownMenuItem as DropdownMenuItem2,
2303
+ DropdownMenuTrigger as DropdownMenuTrigger2
2304
+ } from "@sixb/ui/components";
2305
+ import { cn as cn8 } from "@sixb/ui/lib/utils";
2306
+ import { Panel as Panel2 } from "@xyflow/react";
2307
+ import {
2308
+ ChevronDown,
2309
+ Circle,
2310
+ Copy,
2311
+ Diamond,
2312
+ Frame,
2313
+ RectangleHorizontal,
2314
+ Spline,
2315
+ StickyNote,
2316
+ Trash2 as Trash22,
2317
+ Type
2318
+ } from "lucide-react";
2319
+ import { useEffect as useEffect3, useState as useState6 } from "react";
2320
+ import { jsx as jsx10, jsxs as jsxs9, Fragment as Fragment5 } from "react/jsx-runtime";
2321
+ var NOTE_TONES = [
2322
+ null,
2323
+ "positive",
2324
+ "negative",
2325
+ "neutral",
2326
+ "chart-1",
2327
+ "chart-3"
2328
+ ];
2329
+ var SHAPE_TONES = [
2330
+ null,
2331
+ "positive",
2332
+ "warning",
2333
+ "negative",
2334
+ "chart-1",
2335
+ "chart-3"
2336
+ ];
2337
+ var SIZES = ["s", "m", "l", "xl", "xxl"];
2338
+ var SHAPES = [
2339
+ { shape: "rect", icon: RectangleHorizontal },
2340
+ { shape: "ellipse", icon: Circle },
2341
+ { shape: "diamond", icon: Diamond }
2342
+ ];
2343
+ function CanvasToolbar({
2344
+ selection,
2345
+ onAdd,
2346
+ onStyle,
2347
+ onDuplicate,
2348
+ onDelete
2349
+ }) {
2350
+ const messages = useArtifactMessages().canvas.toolbar;
2351
+ const toned = selection.filter((item) => item.type === "note" || item.type === "shape");
2352
+ const texts = selection.filter((item) => item.type === "text");
2353
+ const shapes = selection.filter((item) => item.type === "shape");
2354
+ const arrows = selection.filter((item) => item.type === "arrow");
2355
+ const arrow = arrows.length === 1 ? arrows[0] : undefined;
2356
+ const one = (values) => values.every((value) => value === values[0]) ? values[0] : undefined;
2357
+ const tone = one(toned.map((item) => ("tone" in item) ? item.tone ?? null : null));
2358
+ const tones = toned.some((item) => item.type === "note") ? NOTE_TONES : SHAPE_TONES;
2359
+ const size = one(texts.map((item) => item.type === "text" ? item.size : undefined));
2360
+ const shape = one(shapes.map((item) => item.type === "shape" ? item.shape : undefined));
2361
+ const dashed = one(arrows.map((item) => item.type === "arrow" ? item.dashed : false));
2362
+ return /* @__PURE__ */ jsx10(Panel2, {
2363
+ position: "top-center",
2364
+ className: "!mt-3",
2365
+ children: /* @__PURE__ */ jsxs9("div", {
2366
+ role: "toolbar",
2367
+ "aria-label": messages.label,
2368
+ className: "flex items-center gap-0.5 rounded-xl border border-border bg-background/95 p-1 shadow-[0_1px_2px_rgb(0_0_0/0.06),0_10px_28px_-14px_rgb(0_0_0/0.3)] backdrop-blur",
2369
+ children: [
2370
+ /* @__PURE__ */ jsx10(Tool, {
2371
+ label: messages.note,
2372
+ onClick: () => onAdd("note"),
2373
+ children: /* @__PURE__ */ jsx10(StickyNote, {})
2374
+ }),
2375
+ /* @__PURE__ */ jsx10(Tool, {
2376
+ label: messages.text,
2377
+ onClick: () => onAdd("text"),
2378
+ children: /* @__PURE__ */ jsx10(Type, {})
2379
+ }),
2380
+ /* @__PURE__ */ jsxs9(DropdownMenu2, {
2381
+ modal: false,
2382
+ children: [
2383
+ /* @__PURE__ */ jsxs9(DropdownMenuTrigger2, {
2384
+ "aria-label": messages.shape,
2385
+ title: messages.shape,
2386
+ className: cn8(TOOL, "w-auto gap-0.5 px-1.5"),
2387
+ children: [
2388
+ /* @__PURE__ */ jsx10(RectangleHorizontal, {}),
2389
+ /* @__PURE__ */ jsx10(ChevronDown, {
2390
+ className: "!size-3 opacity-60"
2391
+ })
2392
+ ]
2393
+ }),
2394
+ /* @__PURE__ */ jsx10(DropdownMenuContent2, {
2395
+ align: "center",
2396
+ sideOffset: 8,
2397
+ children: SHAPES.map(({ shape: kind, icon: Icon }) => /* @__PURE__ */ jsxs9(DropdownMenuItem2, {
2398
+ onSelect: () => onAdd("shape", kind),
2399
+ children: [
2400
+ /* @__PURE__ */ jsx10(Icon, {
2401
+ "aria-hidden": "true"
2402
+ }),
2403
+ messages.shapes[kind]
2404
+ ]
2405
+ }, kind))
2406
+ })
2407
+ ]
2408
+ }),
2409
+ /* @__PURE__ */ jsx10(Tool, {
2410
+ label: messages.section,
2411
+ onClick: () => onAdd("section"),
2412
+ children: /* @__PURE__ */ jsx10(Frame, {})
2413
+ }),
2414
+ selection.length > 0 ? /* @__PURE__ */ jsxs9(Fragment5, {
2415
+ children: [
2416
+ /* @__PURE__ */ jsx10(Divider, {}),
2417
+ toned.length > 0 ? /* @__PURE__ */ jsx10("div", {
2418
+ className: "flex items-center gap-1 px-1",
2419
+ role: "group",
2420
+ "aria-label": messages.color,
2421
+ children: tones.map((entry) => /* @__PURE__ */ jsx10("button", {
2422
+ type: "button",
2423
+ "aria-label": messages.tones[entry ?? "default"],
2424
+ title: messages.tones[entry ?? "default"],
2425
+ "aria-pressed": tone === entry,
2426
+ onClick: () => onStyle({ tone: entry }),
2427
+ className: "flex size-6 items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring",
2428
+ children: /* @__PURE__ */ jsx10("span", {
2429
+ "aria-hidden": "true",
2430
+ className: cn8("size-[18px] rounded-full ring-1 ring-[color-mix(in_oklab,var(--foreground)_14%,transparent)] transition-shadow", tone === entry && "ring-2 ring-foreground ring-offset-2 ring-offset-background"),
2431
+ style: { background: swatch(entry, toned) }
2432
+ })
2433
+ }, entry ?? "default"))
2434
+ }) : null,
2435
+ texts.length > 0 ? /* @__PURE__ */ jsx10(Segments, {
2436
+ label: messages.size,
2437
+ children: SIZES.map((entry) => /* @__PURE__ */ jsx10(Segment, {
2438
+ label: messages.sizes[entry],
2439
+ pressed: size === entry,
2440
+ onClick: () => onStyle({ size: entry }),
2441
+ children: /* @__PURE__ */ jsx10("span", {
2442
+ className: "text-xs font-semibold uppercase",
2443
+ children: entry
2444
+ })
2445
+ }, entry))
2446
+ }) : null,
2447
+ shapes.length > 0 ? /* @__PURE__ */ jsx10(Segments, {
2448
+ label: messages.shape,
2449
+ children: SHAPES.map(({ shape: kind, icon: Icon }) => /* @__PURE__ */ jsx10(Segment, {
2450
+ label: messages.shapes[kind],
2451
+ pressed: shape === kind,
2452
+ onClick: () => onStyle({ shape: kind }),
2453
+ children: /* @__PURE__ */ jsx10(Icon, {})
2454
+ }, kind))
2455
+ }) : null,
2456
+ arrows.length > 0 ? /* @__PURE__ */ jsxs9(Segments, {
2457
+ label: messages.line,
2458
+ children: [
2459
+ /* @__PURE__ */ jsx10(Segment, {
2460
+ label: messages.solid,
2461
+ pressed: dashed === false,
2462
+ onClick: () => onStyle({ dashed: false }),
2463
+ children: /* @__PURE__ */ jsx10(Spline, {})
2464
+ }),
2465
+ /* @__PURE__ */ jsx10(Segment, {
2466
+ label: messages.dashed,
2467
+ pressed: dashed === true,
2468
+ onClick: () => onStyle({ dashed: true }),
2469
+ children: /* @__PURE__ */ jsx10(Spline, {
2470
+ className: "[stroke-dasharray:3_3]"
2471
+ })
2472
+ })
2473
+ ]
2474
+ }) : null,
2475
+ arrow?.type === "arrow" ? /* @__PURE__ */ jsx10(LabelField, {
2476
+ value: arrow.label ?? "",
2477
+ placeholder: messages.label_,
2478
+ onCommit: (label) => onStyle({ label })
2479
+ }, arrow.id) : null,
2480
+ /* @__PURE__ */ jsx10(Divider, {}),
2481
+ /* @__PURE__ */ jsx10(Tool, {
2482
+ label: messages.duplicate,
2483
+ onClick: onDuplicate,
2484
+ children: /* @__PURE__ */ jsx10(Copy, {})
2485
+ }),
2486
+ /* @__PURE__ */ jsx10(Tool, {
2487
+ label: messages.delete,
2488
+ onClick: onDelete,
2489
+ children: /* @__PURE__ */ jsx10(Trash22, {})
2490
+ })
2491
+ ]
2492
+ }) : null
2493
+ ]
2494
+ })
2495
+ });
2496
+ }
2497
+ function swatch(tone, items) {
2498
+ const note = items.some((item) => item.type === "note");
2499
+ if (tone === null) {
2500
+ return note ? `color-mix(in oklab, ${TONE_COLORS.warning} 32%, var(--card))` : "var(--card)";
2501
+ }
2502
+ if (tone === "neutral")
2503
+ return "var(--card)";
2504
+ return `color-mix(in oklab, ${TONE_COLORS[tone]} 40%, var(--card))`;
2505
+ }
2506
+ function LabelField({
2507
+ value,
2508
+ placeholder,
2509
+ onCommit
2510
+ }) {
2511
+ const [text, setText] = useState6(value);
2512
+ useEffect3(() => setText(value), [value]);
2513
+ return /* @__PURE__ */ jsx10("input", {
2514
+ value: text,
2515
+ "aria-label": placeholder,
2516
+ placeholder,
2517
+ maxLength: 120,
2518
+ onChange: (event) => setText(event.target.value),
2519
+ onBlur: () => onCommit(text),
2520
+ onKeyDown: (event) => {
2521
+ event.stopPropagation();
2522
+ if (event.key === "Enter")
2523
+ onCommit(text);
2524
+ },
2525
+ className: "mx-1 h-7 w-36 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring"
2526
+ });
2527
+ }
2528
+ var TOOL = "flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4";
2529
+ function Tool({
2530
+ label,
2531
+ onClick,
2532
+ children
2533
+ }) {
2534
+ return /* @__PURE__ */ jsx10("button", {
2535
+ type: "button",
2536
+ "aria-label": label,
2537
+ title: label,
2538
+ onClick,
2539
+ className: TOOL,
2540
+ children
2541
+ });
2542
+ }
2543
+ function Segments({ label, children }) {
2544
+ return /* @__PURE__ */ jsx10("div", {
2545
+ role: "group",
2546
+ "aria-label": label,
2547
+ className: "flex items-center rounded-lg bg-muted/60 p-0.5",
2548
+ children
2549
+ });
2550
+ }
2551
+ function Segment({
2552
+ label,
2553
+ pressed,
2554
+ onClick,
2555
+ children
2556
+ }) {
2557
+ return /* @__PURE__ */ jsx10("button", {
2558
+ type: "button",
2559
+ "aria-label": label,
2560
+ title: label,
2561
+ "aria-pressed": pressed,
2562
+ onClick,
2563
+ className: cn8("flex h-7 min-w-7 items-center justify-center rounded-md px-1.5 text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4", pressed && "bg-background text-foreground shadow-sm"),
2564
+ children
2565
+ });
2566
+ }
2567
+ function Divider() {
2568
+ return /* @__PURE__ */ jsx10("span", {
2569
+ "aria-hidden": "true",
2570
+ className: "mx-1 h-5 w-px bg-border"
2571
+ });
2572
+ }
2573
+
2574
+ // src/artifacts/renderers/canvas/edit-mode.tsx
2575
+ import { jsx as jsx11 } from "react/jsx-runtime";
2576
+ var DRAG_SHARE_MS = 50;
2577
+ var GRID = 8;
2578
+ var NEW_SIZES = {
2579
+ note: [240, 112],
2580
+ text: [200, 40],
2581
+ shape: [200, 120],
2582
+ section: [640, 400]
2583
+ };
2584
+ function useBoardEditing(canvas, edit, onOpenBoard) {
2585
+ const messages = useArtifactMessages().canvas.toolbar;
2586
+ const store = useStoreApi3();
2587
+ const graph = useMemo4(() => canvasGraph(canvas), [canvas]);
2588
+ const read = useReadGraph(graph, store);
2589
+ const editing = !!edit;
2590
+ const [nodes, setNodes] = useState7(graph.nodes);
2591
+ const [edges, setEdges] = useState7(graph.edges);
2592
+ const [madeFrom] = useState7(() => new WeakMap);
2593
+ const selected = useRef5(new Set);
2594
+ const [selection, setSelection] = useState7(new Set);
2595
+ const [typing, setTyping] = useState7(null);
2596
+ const root = useRef5(null);
2597
+ const [drawnFrom, setDrawnFrom] = useState7({ graph: null, editing: false });
2598
+ if (drawnFrom.graph !== graph || drawnFrom.editing !== editing) {
2599
+ if (editing || drawnFrom.editing)
2600
+ setDrawnFrom({ graph, editing });
2601
+ if (editing) {
2602
+ const chosen = selected.current;
2603
+ setNodes((current) => {
2604
+ const drawn = new Map(current.map((node) => [node.id, node]));
2605
+ const next = graph.nodes.map((node) => {
2606
+ const was = drawn.get(node.id);
2607
+ const choose = node.type !== "point";
2608
+ const isSelected = choose && chosen.has(node.id);
2609
+ const same = was && madeFrom.get(was) === node && !!was.draggable === choose && !!was.selected === isSelected && !was.dragging;
2610
+ if (same)
2611
+ return was;
2612
+ const next = {
2613
+ ...node,
2614
+ ...choose ? { draggable: true, selectable: true, selected: isSelected } : {},
2615
+ ...was?.measured ? { measured: was.measured } : {},
2616
+ ...was?.dragging ? { position: was.position, dragging: true } : {}
2617
+ };
2618
+ madeFrom.set(next, node);
2619
+ return next;
2620
+ });
2621
+ return sameItems(current, next) ? current : next;
2622
+ });
2623
+ setEdges((current) => {
2624
+ const drawn = new Map(current.map((edge) => [edge.id, edge]));
2625
+ const next = graph.edges.map((edge) => {
2626
+ const was = drawn.get(edge.id);
2627
+ const isSelected = chosen.has(edge.id);
2628
+ const same = was && madeFrom.get(was) === edge && !!was.selectable && !!was.selected === isSelected;
2629
+ if (same)
2630
+ return was;
2631
+ const next = { ...edge, selectable: true, selected: isSelected };
2632
+ madeFrom.set(next, edge);
2633
+ return next;
2634
+ });
2635
+ return sameItems(current, next) ? current : next;
2636
+ });
2637
+ }
2638
+ }
2639
+ useEffect4(() => {
2640
+ if (!editing) {
2641
+ selected.current = new Set;
2642
+ setSelection(new Set);
2643
+ setTyping(null);
2644
+ }
2645
+ }, [editing]);
2646
+ const select = useCallback4((ids) => {
2647
+ const chosen = new Set(ids);
2648
+ selected.current = chosen;
2649
+ setSelection(chosen);
2650
+ setNodes((current) => current.map((node) => ({ ...node, selected: chosen.has(node.id) })));
2651
+ setEdges((current) => current.map((edge) => ({ ...edge, selected: chosen.has(edge.id) })));
2652
+ }, []);
2653
+ const chose = (changes) => {
2654
+ const next = new Set(selected.current);
2655
+ for (const change of changes) {
2656
+ if (change.type !== "select")
2657
+ continue;
2658
+ if (change.selected)
2659
+ next.add(change.id);
2660
+ else
2661
+ next.delete(change.id);
2662
+ }
2663
+ selected.current = next;
2664
+ setSelection(next);
2665
+ };
2666
+ const focusBoard = useCallback4(() => root.current?.focus({ preventScroll: true }), []);
2667
+ const share = edit?.live?.select;
2668
+ useEffect4(() => {
2669
+ share?.([...selection]);
2670
+ }, [share, selection]);
2671
+ useEffect4(() => () => share?.([]), [share]);
2672
+ const dragShared = useRef5(0);
2673
+ const items = useMemo4(() => edit ? {
2674
+ typing,
2675
+ startTyping: setTyping,
2676
+ commitText: (id, text) => {
2677
+ edit.apply(setItemText(id, text));
2678
+ setTyping(null);
2679
+ focusBoard();
2680
+ },
2681
+ resize: (id, box) => edit.apply(resizeItem(id, box))
2682
+ } : null, [edit, typing, focusBoard]);
2683
+ if (!edit) {
2684
+ return { nodes: read.nodes, edges: read.edges, editing: false, root };
2685
+ }
2686
+ const chosenItems = canvas.items.filter((item) => selection.has(item.id));
2687
+ const add = (kind, shape) => {
2688
+ const { width, height, transform } = store.getState();
2689
+ const [x, y, zoom] = transform;
2690
+ const [w, h] = NEW_SIZES[kind];
2691
+ const snap = (value) => Math.round(value / GRID) * GRID;
2692
+ const at = {
2693
+ x: snap((width / 2 - x) / zoom - w / 2),
2694
+ y: snap((height / 2 - y) / zoom - h / 2)
2695
+ };
2696
+ const text = kind === "text" ? messages.newText : kind === "section" ? messages.newSection : "";
2697
+ const added = addItem(kind, at, text);
2698
+ const id = added.id;
2699
+ edit.apply((current) => {
2700
+ const next = added.change(current);
2701
+ return shape && shape !== "rect" ? styleItems(new Set([id]), { shape })(next) : next;
2702
+ });
2703
+ select([id]);
2704
+ if (kind !== "shape")
2705
+ setTyping(id);
2706
+ };
2707
+ const remove = () => {
2708
+ if (selection.size === 0)
2709
+ return;
2710
+ edit.apply(removeItems(selection));
2711
+ select([]);
2712
+ };
2713
+ const duplicate = () => {
2714
+ if (selection.size === 0)
2715
+ return;
2716
+ const copies = duplicateItems(selection);
2717
+ const ids = copies.copies(canvas);
2718
+ edit.apply(copies.change);
2719
+ select(ids);
2720
+ };
2721
+ const nudge = (dx, dy) => {
2722
+ const positions = new Map(chosenItems.flatMap((item) => item.type === "arrow" ? [] : [[item.id, { x: item.x + dx, y: item.y + dy }]]));
2723
+ if (positions.size > 0)
2724
+ edit.apply(moveItems(positions));
2725
+ };
2726
+ const onKeyDown = (event) => {
2727
+ const target = event.target;
2728
+ if (target.closest("input, textarea, select, [contenteditable], [role=dialog], [role=menu]")) {
2729
+ return;
2730
+ }
2731
+ const command = event.metaKey || event.ctrlKey;
2732
+ const key = event.key.toLowerCase();
2733
+ const handled = (() => {
2734
+ if (command && (key === "z" || key === "y")) {
2735
+ if (key === "y" || event.shiftKey)
2736
+ edit.redo();
2737
+ else
2738
+ edit.undo();
2739
+ return true;
2740
+ }
2741
+ if (command && key === "d") {
2742
+ duplicate();
2743
+ return true;
2744
+ }
2745
+ if (command && key === "a") {
2746
+ select(canvas.items.map((item) => item.id));
2747
+ return true;
2748
+ }
2749
+ if (command)
2750
+ return false;
2751
+ if (event.key === "Delete" || event.key === "Backspace") {
2752
+ remove();
2753
+ return true;
2754
+ }
2755
+ if (event.key === "Escape") {
2756
+ select([]);
2757
+ return true;
2758
+ }
2759
+ const only = chosenItems.length === 1 ? chosenItems[0] : undefined;
2760
+ if (event.key === "Enter" && only) {
2761
+ if (only.type === "board")
2762
+ onOpenBoard?.(only.id);
2763
+ else if (only.type !== "embed" && only.type !== "arrow")
2764
+ setTyping(only.id);
2765
+ return true;
2766
+ }
2767
+ const step = event.shiftKey ? GRID : 1;
2768
+ const moves = {
2769
+ ArrowLeft: [-step, 0],
2770
+ ArrowRight: [step, 0],
2771
+ ArrowUp: [0, -step],
2772
+ ArrowDown: [0, step]
2773
+ };
2774
+ const move = moves[event.key];
2775
+ if (move && chosenItems.length > 0) {
2776
+ nudge(move[0], move[1]);
2777
+ return true;
2778
+ }
2779
+ return false;
2780
+ })();
2781
+ if (handled) {
2782
+ event.preventDefault();
2783
+ event.stopPropagation();
2784
+ }
2785
+ };
2786
+ const toolbar = /* @__PURE__ */ jsx11(CanvasToolbar, {
2787
+ selection: chosenItems,
2788
+ onAdd: add,
2789
+ onStyle: (style) => edit.apply(styleItems(selection, style)),
2790
+ onDuplicate: duplicate,
2791
+ onDelete: remove
2792
+ });
2793
+ return {
2794
+ nodes,
2795
+ edges,
2796
+ editing: true,
2797
+ root,
2798
+ items,
2799
+ toolbar,
2800
+ onKeyDown,
2801
+ flow: {
2802
+ onNodesChange: (changes) => {
2803
+ setNodes((current) => applyNodeChanges(changes, current));
2804
+ if (changes.some((change) => change.type === "select"))
2805
+ chose(changes);
2806
+ },
2807
+ onEdgesChange: (changes) => {
2808
+ setEdges((current) => applyEdgeChanges(changes, current));
2809
+ if (changes.some((change) => change.type === "select"))
2810
+ chose(changes);
2811
+ },
2812
+ onNodeDragStart: () => edit.live?.startDrag(),
2813
+ onNodeDrag: (_, __, dragged) => {
2814
+ if (!edit.live)
2815
+ return;
2816
+ const now = performance.now();
2817
+ if (now - dragShared.current < DRAG_SHARE_MS)
2818
+ return;
2819
+ dragShared.current = now;
2820
+ edit.apply(moveItems(new Map(dragged.map((node) => [node.id, node.position]))));
2821
+ },
2822
+ onNodeDragStop: (_, __, dragged) => {
2823
+ edit.apply(moveItems(new Map(dragged.map((node) => [node.id, node.position]))));
2824
+ edit.live?.endDrag();
2825
+ },
2826
+ onConnect: (connection) => edit.apply(connectItems(connection.source, connection.target)),
2827
+ onNodeDoubleClick: (_, node) => {
2828
+ if (node.type === "board")
2829
+ onOpenBoard?.(node.id);
2830
+ else if (node.type !== "embed" && node.type !== "point")
2831
+ setTyping(node.id);
2832
+ },
2833
+ nodesDraggable: true,
2834
+ nodesConnectable: true,
2835
+ elementsSelectable: true,
2836
+ connectionMode: ConnectionMode.Loose,
2837
+ snapToGrid: true,
2838
+ snapGrid: [GRID, GRID],
2839
+ deleteKeyCode: null,
2840
+ multiSelectionKeyCode: ["Meta", "Control", "Shift"],
2841
+ connectionLineStyle: {
2842
+ stroke: "color-mix(in oklab, var(--primary) 70%, transparent)",
2843
+ strokeWidth: 2
2844
+ }
2845
+ }
2846
+ };
2847
+ }
2848
+ function sameItems(left, right) {
2849
+ return left.length === right.length && left.every((item, index) => item === right[index]);
2850
+ }
2851
+ function useReadGraph(graph, store) {
2852
+ const [measuredFrom] = useState7(() => new WeakMap);
2853
+ const last = useRef5(null);
2854
+ const { nodeLookup } = store.getState();
2855
+ const measured = graph.nodes.map((node) => {
2856
+ const kept = measuredFrom.get(node);
2857
+ if (kept)
2858
+ return kept;
2859
+ const drawn = nodeLookup.get(node.id);
2860
+ const same = drawn?.measured.width !== undefined && drawn.measured.height !== undefined && drawn.internals.userNode.width === node.width && drawn.internals.userNode.height === node.height;
2861
+ const next = same ? { ...node, measured: { ...drawn.measured } } : node;
2862
+ measuredFrom.set(node, next);
2863
+ return next;
2864
+ });
2865
+ const nodes = last.current && sameItems(last.current.nodes, measured) ? last.current.nodes : measured;
2866
+ const edges = last.current && sameItems(last.current.edges, graph.edges) ? last.current.edges : graph.edges;
2867
+ if (nodes !== last.current?.nodes || edges !== last.current?.edges)
2868
+ last.current = { nodes, edges };
2869
+ return last.current;
2870
+ }
2871
+
2872
+ // src/artifacts/renderers/canvas/focus.tsx
2873
+ import { ArrowLeft, ChevronLeft, ChevronRight } from "lucide-react";
2874
+ import { useCallback as useCallback6, useEffect as useEffect7, useState as useState10 } from "react";
2875
+
2876
+ // src/artifacts/renderers/canvas/board-editor.tsx
2877
+ import { uploadFile } from "@sixb/client";
2878
+ import {
2879
+ ARTIFACT_LIMITS as ARTIFACT_LIMITS3,
2880
+ parseFrameEvent
2881
+ } from "@sixb/core/artifacts";
2882
+ import {
2883
+ boardFilePath,
2884
+ boardFramePatches,
2885
+ mergeBoardText,
2886
+ setBoardImage,
2887
+ setBoardStyle
2888
+ } from "@sixb/core/artifacts/live";
2889
+ import { Popover, PopoverContent, PopoverTrigger } from "@sixb/ui/components";
2890
+ import { useLocale as useLocale2 } from "@sixb/ui/lib/i18n";
2891
+ import { cn as cn10 } from "@sixb/ui/lib/utils";
2892
+ import { Code2, ImageIcon as ImageIcon2, LoaderCircle as LoaderCircle3, MessageSquarePlus as MessageSquarePlus3, Paintbrush } from "lucide-react";
2893
+ import {
2894
+ forwardRef as forwardRef2,
2895
+ useCallback as useCallback5,
2896
+ useEffect as useEffect6,
2897
+ useLayoutEffect as useLayoutEffect2,
2898
+ useMemo as useMemo5,
2899
+ useRef as useRef7,
2900
+ useState as useState9
2901
+ } from "react";
2902
+
2903
+ // src/artifacts/renderers/canvas/board-properties.tsx
2904
+ import { cn as cn9 } from "@sixb/ui/lib/utils";
2905
+ import {
2906
+ AlignCenter,
2907
+ AlignLeft,
2908
+ AlignRight,
2909
+ ImageIcon,
2910
+ ImageUp,
2911
+ LoaderCircle as LoaderCircle2,
2912
+ RotateCcw as RotateCcw2
2913
+ } from "lucide-react";
2914
+ import { useEffect as useEffect5, useId as useId2, useRef as useRef6, useState as useState8 } from "react";
2915
+ import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
2916
+ var SWATCHES = [
2917
+ "#0f172a",
2918
+ "#475569",
2919
+ "#ffffff",
2920
+ "#2563eb",
2921
+ "#7c3aed",
2922
+ "#db2777",
2923
+ "#dc2626",
2924
+ "#ea580c",
2925
+ "#ca8a04",
2926
+ "#16a34a",
2927
+ "#0d9488"
2928
+ ];
2929
+ var WEIGHTS = ["400", "500", "600", "700"];
2930
+ var ALIGNS = [
2931
+ { value: "left", icon: AlignLeft },
2932
+ { value: "center", icon: AlignCenter },
2933
+ { value: "right", icon: AlignRight }
2934
+ ];
2935
+ function StylePanel({
2936
+ style,
2937
+ words,
2938
+ onChange
2939
+ }) {
2940
+ const messages = useArtifactMessages().canvas.edit;
2941
+ const background = style.background ?? style["background-color"];
2942
+ const setBackground = (value) => onChange(style.background !== undefined ? { background: value } : { "background-color": null, background: value });
2943
+ return /* @__PURE__ */ jsxs10("div", {
2944
+ className: "flex w-[17rem] flex-col gap-3.5",
2945
+ "data-board-tools": "",
2946
+ children: [
2947
+ /* @__PURE__ */ jsxs10(Section, {
2948
+ title: messages.colors,
2949
+ children: [
2950
+ /* @__PURE__ */ jsx12(ColorField, {
2951
+ label: messages.textColor,
2952
+ value: style.color,
2953
+ onChange: (value) => onChange({ color: value })
2954
+ }),
2955
+ /* @__PURE__ */ jsx12(ColorField, {
2956
+ label: messages.background,
2957
+ value: background,
2958
+ onChange: setBackground
2959
+ })
2960
+ ]
2961
+ }),
2962
+ words ? /* @__PURE__ */ jsxs10(Section, {
2963
+ title: messages.typography,
2964
+ children: [
2965
+ /* @__PURE__ */ jsx12(LengthField, {
2966
+ label: messages.fontSize,
2967
+ value: style["font-size"],
2968
+ onChange: (value) => onChange({ "font-size": value })
2969
+ }),
2970
+ /* @__PURE__ */ jsx12(Row, {
2971
+ label: messages.weight,
2972
+ children: /* @__PURE__ */ jsx12(Segments2, {
2973
+ label: messages.weight,
2974
+ children: WEIGHTS.map((weight) => /* @__PURE__ */ jsx12(Segment2, {
2975
+ label: messages.weights[weight],
2976
+ pressed: normalWeight(style["font-weight"]) === weight,
2977
+ onClick: () => onChange({
2978
+ "font-weight": normalWeight(style["font-weight"]) === weight ? null : weight
2979
+ }),
2980
+ children: /* @__PURE__ */ jsx12("span", {
2981
+ className: "text-xs",
2982
+ style: { fontWeight: Number(weight) },
2983
+ children: "Aa"
2984
+ })
2985
+ }, weight))
2986
+ })
2987
+ }),
2988
+ /* @__PURE__ */ jsx12(Row, {
2989
+ label: messages.align,
2990
+ children: /* @__PURE__ */ jsx12(Segments2, {
2991
+ label: messages.align,
2992
+ children: ALIGNS.map(({ value, icon: Icon }) => /* @__PURE__ */ jsx12(Segment2, {
2993
+ label: messages.aligns[value],
2994
+ pressed: style["text-align"] === value,
2995
+ onClick: () => onChange({ "text-align": style["text-align"] === value ? null : value }),
2996
+ children: /* @__PURE__ */ jsx12(Icon, {})
2997
+ }, value))
2998
+ })
2999
+ })
3000
+ ]
3001
+ }) : null,
3002
+ /* @__PURE__ */ jsxs10(Section, {
3003
+ title: messages.layout,
3004
+ children: [
3005
+ /* @__PURE__ */ jsx12(LengthField, {
3006
+ label: messages.padding,
3007
+ value: style.padding,
3008
+ onChange: (value) => onChange({ padding: value })
3009
+ }),
3010
+ /* @__PURE__ */ jsx12(LengthField, {
3011
+ label: messages.gap,
3012
+ value: style.gap,
3013
+ onChange: (value) => onChange({ gap: value })
3014
+ }),
3015
+ /* @__PURE__ */ jsx12(LengthField, {
3016
+ label: messages.radius,
3017
+ value: style["border-radius"],
3018
+ onChange: (value) => onChange({ "border-radius": value })
3019
+ })
3020
+ ]
3021
+ })
3022
+ ]
3023
+ });
3024
+ }
3025
+ function normalWeight(weight) {
3026
+ if (weight === "normal")
3027
+ return "400";
3028
+ if (weight === "bold")
3029
+ return "700";
3030
+ return weight;
3031
+ }
3032
+ function Section({ title, children }) {
3033
+ return /* @__PURE__ */ jsxs10("section", {
3034
+ className: "flex flex-col gap-2",
3035
+ children: [
3036
+ /* @__PURE__ */ jsx12("h3", {
3037
+ className: "m-0 text-[11px] font-semibold tracking-wide text-muted-foreground uppercase",
3038
+ children: title
3039
+ }),
3040
+ children
3041
+ ]
3042
+ });
3043
+ }
3044
+ function Row({ label, children }) {
3045
+ return /* @__PURE__ */ jsxs10("div", {
3046
+ className: "flex items-center justify-between gap-3",
3047
+ children: [
3048
+ /* @__PURE__ */ jsx12("span", {
3049
+ className: "text-xs text-foreground/80",
3050
+ children: label
3051
+ }),
3052
+ children
3053
+ ]
3054
+ });
3055
+ }
3056
+ function ColorField({
3057
+ label,
3058
+ value,
3059
+ onChange
3060
+ }) {
3061
+ const messages = useArtifactMessages().canvas.edit;
3062
+ return /* @__PURE__ */ jsxs10("div", {
3063
+ className: "flex flex-col gap-1.5",
3064
+ children: [
3065
+ /* @__PURE__ */ jsx12(ValueField, {
3066
+ label,
3067
+ value,
3068
+ onChange,
3069
+ swatch: value
3070
+ }),
3071
+ /* @__PURE__ */ jsx12("div", {
3072
+ className: "flex flex-wrap gap-1",
3073
+ role: "group",
3074
+ "aria-label": label,
3075
+ children: SWATCHES.map((color) => /* @__PURE__ */ jsx12("button", {
3076
+ type: "button",
3077
+ "aria-label": messages.swatch(color),
3078
+ title: color,
3079
+ "aria-pressed": value?.toLowerCase() === color,
3080
+ onClick: () => onChange(color),
3081
+ className: "flex size-5 items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring",
3082
+ children: /* @__PURE__ */ jsx12("span", {
3083
+ "aria-hidden": "true",
3084
+ className: cn9("size-4 rounded-full ring-1 ring-[color-mix(in_oklab,var(--foreground)_16%,transparent)]", value?.toLowerCase() === color && "ring-2 ring-foreground ring-offset-1 ring-offset-popover"),
3085
+ style: { background: color }
3086
+ })
3087
+ }, color))
3088
+ })
3089
+ ]
3090
+ });
3091
+ }
3092
+ function LengthField({
3093
+ label,
3094
+ value,
3095
+ onChange
3096
+ }) {
3097
+ return /* @__PURE__ */ jsx12(ValueField, {
3098
+ label,
3099
+ value,
3100
+ onChange: (next) => onChange(next !== null && /^\d+(\.\d+)?$/.test(next) ? `${next}px` : next)
3101
+ });
3102
+ }
3103
+ function ValueField({
3104
+ label,
3105
+ value,
3106
+ onChange,
3107
+ swatch
3108
+ }) {
3109
+ const messages = useArtifactMessages().canvas.edit;
3110
+ const id = useId2();
3111
+ const [text, setText] = useState8(value ?? "");
3112
+ const [invalid, setInvalid] = useState8(false);
3113
+ useEffect5(() => {
3114
+ setText(value ?? "");
3115
+ setInvalid(false);
3116
+ }, [value]);
3117
+ const commit = () => {
3118
+ const next = text.trim();
3119
+ if (next === (value ?? ""))
3120
+ return;
3121
+ setInvalid(!onChange(next === "" ? null : next));
3122
+ };
3123
+ return /* @__PURE__ */ jsxs10("div", {
3124
+ className: "flex items-center justify-between gap-3",
3125
+ children: [
3126
+ /* @__PURE__ */ jsx12("label", {
3127
+ htmlFor: id,
3128
+ className: "text-xs text-foreground/80",
3129
+ children: label
3130
+ }),
3131
+ /* @__PURE__ */ jsxs10("div", {
3132
+ className: "flex items-center gap-1",
3133
+ children: [
3134
+ /* @__PURE__ */ jsxs10("div", {
3135
+ className: cn9("flex h-7 w-[8.5rem] items-center gap-1.5 rounded-md border bg-background px-1.5 text-xs focus-within:ring-2 focus-within:ring-ring", invalid ? "border-destructive" : "border-border"),
3136
+ children: [
3137
+ swatch !== undefined ? /* @__PURE__ */ jsx12("span", {
3138
+ "aria-hidden": "true",
3139
+ className: "size-3.5 shrink-0 rounded-[4px] ring-1 ring-[color-mix(in_oklab,var(--foreground)_16%,transparent)]",
3140
+ style: { background: swatch || "transparent" }
3141
+ }) : null,
3142
+ /* @__PURE__ */ jsx12("input", {
3143
+ id,
3144
+ value: text,
3145
+ placeholder: messages.inherited,
3146
+ "aria-invalid": invalid || undefined,
3147
+ spellCheck: false,
3148
+ onChange: (event) => setText(event.target.value),
3149
+ onBlur: commit,
3150
+ onKeyDown: (event) => {
3151
+ event.stopPropagation();
3152
+ if (event.key === "Enter")
3153
+ commit();
3154
+ },
3155
+ className: "h-full min-w-0 flex-1 bg-transparent font-mono text-[11px] outline-none placeholder:font-sans placeholder:text-muted-foreground/70"
3156
+ })
3157
+ ]
3158
+ }),
3159
+ /* @__PURE__ */ jsx12("button", {
3160
+ type: "button",
3161
+ "aria-label": messages.reset(label),
3162
+ title: messages.reset(label),
3163
+ disabled: value === undefined,
3164
+ onClick: () => onChange(null),
3165
+ className: "flex size-6 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-30 [&_svg]:size-3.5",
3166
+ children: /* @__PURE__ */ jsx12(RotateCcw2, {})
3167
+ })
3168
+ ]
3169
+ }),
3170
+ invalid ? /* @__PURE__ */ jsx12("span", {
3171
+ role: "alert",
3172
+ className: "sr-only",
3173
+ children: messages.invalid
3174
+ }) : null
3175
+ ]
3176
+ });
3177
+ }
3178
+ function Segments2({ label, children }) {
3179
+ return /* @__PURE__ */ jsx12("div", {
3180
+ role: "group",
3181
+ "aria-label": label,
3182
+ className: "flex items-center rounded-lg bg-muted/70 p-0.5",
3183
+ children
3184
+ });
3185
+ }
3186
+ function Segment2({
3187
+ label,
3188
+ pressed,
3189
+ onClick,
3190
+ children
3191
+ }) {
3192
+ return /* @__PURE__ */ jsx12("button", {
3193
+ type: "button",
3194
+ "aria-label": label,
3195
+ title: label,
3196
+ "aria-pressed": pressed,
3197
+ onClick,
3198
+ className: cn9("flex h-6 min-w-7 items-center justify-center rounded-md px-1.5 text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5", pressed && "bg-background text-foreground shadow-sm"),
3199
+ children
3200
+ });
3201
+ }
3202
+ function ImagePanel({
3203
+ current,
3204
+ alt,
3205
+ images,
3206
+ uploading,
3207
+ failure,
3208
+ onUpload,
3209
+ onPick,
3210
+ onAlt
3211
+ }) {
3212
+ const messages = useArtifactMessages().canvas.edit;
3213
+ const input = useRef6(null);
3214
+ const altId = useId2();
3215
+ const description = useRef6(null);
3216
+ const [text, setText] = useState8(alt);
3217
+ useEffect5(() => setText(alt), [alt]);
3218
+ const others = images.filter((image) => image.path !== current);
3219
+ const replaced = (shown) => {
3220
+ if (shown)
3221
+ description.current?.focus();
3222
+ };
3223
+ return /* @__PURE__ */ jsxs10("div", {
3224
+ className: "flex w-[17rem] flex-col gap-3",
3225
+ "data-board-tools": "",
3226
+ children: [
3227
+ /* @__PURE__ */ jsx12("input", {
3228
+ ref: input,
3229
+ type: "file",
3230
+ accept: "image/*",
3231
+ className: "sr-only",
3232
+ tabIndex: -1,
3233
+ "aria-hidden": "true",
3234
+ onChange: (event) => {
3235
+ const file = event.target.files?.[0];
3236
+ event.target.value = "";
3237
+ if (file)
3238
+ onUpload(file).then(replaced);
3239
+ }
3240
+ }),
3241
+ /* @__PURE__ */ jsxs10("button", {
3242
+ type: "button",
3243
+ disabled: uploading,
3244
+ onClick: () => input.current?.click(),
3245
+ className: "flex h-9 items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-muted/40 text-sm font-medium text-foreground outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 [&_svg]:size-4",
3246
+ children: [
3247
+ uploading ? /* @__PURE__ */ jsx12(LoaderCircle2, {
3248
+ className: "animate-spin motion-reduce:animate-none",
3249
+ "aria-hidden": "true"
3250
+ }) : /* @__PURE__ */ jsx12(ImageUp, {
3251
+ "aria-hidden": "true"
3252
+ }),
3253
+ uploading ? messages.uploading : messages.upload
3254
+ ]
3255
+ }),
3256
+ failure ? /* @__PURE__ */ jsx12("p", {
3257
+ role: "alert",
3258
+ className: "m-0 text-xs text-destructive",
3259
+ children: failure
3260
+ }) : null,
3261
+ /* @__PURE__ */ jsxs10("section", {
3262
+ className: "flex flex-col gap-2",
3263
+ children: [
3264
+ /* @__PURE__ */ jsx12("h3", {
3265
+ className: "m-0 text-[11px] font-semibold tracking-wide text-muted-foreground uppercase",
3266
+ children: messages.fromCanvas
3267
+ }),
3268
+ others.length > 0 ? /* @__PURE__ */ jsx12("div", {
3269
+ className: "grid max-h-40 grid-cols-4 gap-1.5 overflow-y-auto p-0.5",
3270
+ children: others.map((image) => /* @__PURE__ */ jsx12("button", {
3271
+ type: "button",
3272
+ title: image.path,
3273
+ "aria-label": image.path,
3274
+ onClick: () => replaced(onPick(image.path)),
3275
+ className: "flex aspect-square items-center justify-center overflow-hidden rounded-md bg-muted outline-none ring-1 ring-border transition-shadow hover:ring-2 hover:ring-primary focus-visible:ring-2 focus-visible:ring-ring",
3276
+ children: image.url ? /* @__PURE__ */ jsx12("img", {
3277
+ src: image.url,
3278
+ alt: "",
3279
+ loading: "lazy",
3280
+ className: "size-full object-cover",
3281
+ draggable: false
3282
+ }) : /* @__PURE__ */ jsx12(ImageIcon, {
3283
+ className: "size-4 text-muted-foreground",
3284
+ "aria-hidden": "true"
3285
+ })
3286
+ }, image.path))
3287
+ }) : /* @__PURE__ */ jsx12("p", {
3288
+ className: "m-0 text-xs text-muted-foreground",
3289
+ children: messages.noImages
3290
+ })
3291
+ ]
3292
+ }),
3293
+ /* @__PURE__ */ jsxs10("div", {
3294
+ className: "flex flex-col gap-1.5",
3295
+ children: [
3296
+ /* @__PURE__ */ jsx12("label", {
3297
+ htmlFor: altId,
3298
+ className: "text-xs text-foreground/80",
3299
+ children: messages.description
3300
+ }),
3301
+ /* @__PURE__ */ jsx12("input", {
3302
+ ref: description,
3303
+ id: altId,
3304
+ value: text,
3305
+ placeholder: messages.descriptionPlaceholder,
3306
+ onChange: (event) => setText(event.target.value),
3307
+ onBlur: () => {
3308
+ if (text !== alt)
3309
+ onAlt(text);
3310
+ },
3311
+ onKeyDown: (event) => {
3312
+ event.stopPropagation();
3313
+ if (event.key === "Enter" && text !== alt)
3314
+ onAlt(text);
3315
+ },
3316
+ className: "h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring"
3317
+ })
3318
+ ]
3319
+ })
3320
+ ]
3321
+ });
3322
+ }
3323
+
3324
+ // src/artifacts/renderers/canvas/board-source.ts
3325
+ import { boardElement } from "@sixb/core/artifacts/live";
3326
+ function boardAttribute(source, address, name) {
3327
+ const element = boardElement(source, address);
3328
+ if (!element)
3329
+ return null;
3330
+ const tag = startTag(source.slice(element.start, element.end));
3331
+ const pattern = new RegExp(`\\s${name}\\s*=\\s*("([^"]*)"|'([^']*)'|([^\\s"'=<>\`]+))`, "i");
3332
+ const match = pattern.exec(tag);
3333
+ if (!match)
3334
+ return null;
3335
+ return decodeAttribute(match[2] ?? match[3] ?? match[4] ?? "");
3336
+ }
3337
+ function boardInlineStyle(source, address) {
3338
+ const style = boardAttribute(source, address, "style") ?? "";
3339
+ const declarations = {};
3340
+ for (const declaration of style.split(";")) {
3341
+ const colon = declaration.indexOf(":");
3342
+ if (colon <= 0)
3343
+ continue;
3344
+ const property = declaration.slice(0, colon).trim().toLowerCase();
3345
+ const value = declaration.slice(colon + 1).trim();
3346
+ if (property && value)
3347
+ declarations[property] = value;
3348
+ }
3349
+ return declarations;
3350
+ }
3351
+ function startTag(html) {
3352
+ let quote = null;
3353
+ for (let index = 0;index < html.length; index += 1) {
3354
+ const char = html[index];
3355
+ if (quote) {
3356
+ if (char === quote)
3357
+ quote = null;
3358
+ } else if (char === '"' || char === "'")
3359
+ quote = char;
3360
+ else if (char === ">")
3361
+ return html.slice(0, index);
3362
+ }
3363
+ return html;
3364
+ }
3365
+ function decodeAttribute(value) {
3366
+ return value.replace(/&quot;/g, '"').replace(/&#39;|&apos;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
3367
+ }
3368
+ function boardReferencePath(board, reference) {
3369
+ if (/^[a-z][a-z0-9+.-]*:|^\/\/|^\/|^#/i.test(reference))
3370
+ return null;
3371
+ const parts = board.split("/").slice(0, -1);
3372
+ for (const part of reference.split(/[?#]/)[0]?.split("/") ?? []) {
3373
+ if (part === "" || part === ".")
3374
+ continue;
3375
+ if (part === "..") {
3376
+ if (parts.length === 0)
3377
+ return null;
3378
+ parts.pop();
3379
+ continue;
3380
+ }
3381
+ try {
3382
+ parts.push(decodeURIComponent(part));
3383
+ } catch {
3384
+ return null;
3385
+ }
3386
+ }
3387
+ return parts.join("/");
3388
+ }
3389
+ function showablePatches(patches, board, holds, previews) {
3390
+ let waiting = false;
3391
+ const shown = [];
3392
+ for (const patch of patches) {
3393
+ const src = patch.attributes?.src;
3394
+ const path = src === undefined ? null : boardReferencePath(board, src);
3395
+ if (src === undefined || path === null || holds(path)) {
3396
+ shown.push(patch);
3397
+ continue;
3398
+ }
3399
+ const preview = previews.get(path);
3400
+ if (preview && patch.attributes) {
3401
+ shown.push({ ...patch, attributes: { ...patch.attributes, src: preview } });
3402
+ continue;
3403
+ }
3404
+ waiting = true;
3405
+ }
3406
+ return { patches: shown, waiting };
3407
+ }
3408
+
3409
+ // src/artifacts/renderers/canvas/board-editor.tsx
3410
+ import { jsx as jsx13, jsxs as jsxs11, Fragment as Fragment6 } from "react/jsx-runtime";
3411
+ var IMAGE_EXTENSIONS = /\.(png|jpe?g|gif|webp|avif|svg)$/i;
3412
+ function useBoardFrame({
3413
+ version,
3414
+ board,
3415
+ live
3416
+ }) {
3417
+ const source = useLiveBoardSource(live, board.file);
3418
+ const patching = source !== null;
3419
+ const [pinned, setPinned] = useState9(version);
3420
+ const shows = patching ? pinned : version;
3421
+ const stored = useFileText(patching ? versionFileSource(pinned, board.file) : null).text;
3422
+ const handle = useRef7(null);
3423
+ const [loads, setLoads] = useState9(0);
3424
+ const shown = useRef7(null);
3425
+ const previews = useRef7(new Map);
3426
+ const [stale, setStale] = useState9(false);
3427
+ const [moved, setMoved] = useState9(false);
3428
+ const [holding, setHolding] = useState9(false);
3429
+ const ready = useCallback5(() => {
3430
+ shown.current = null;
3431
+ setLoads((count) => count + 1);
3432
+ }, []);
3433
+ useEffect6(() => {
3434
+ if (loads === 0 || stored === undefined || source === null)
3435
+ return;
3436
+ const patches = boardFramePatches(shown.current ?? stored, source);
3437
+ if (patches === null) {
3438
+ setStale(true);
3439
+ setMoved(true);
3440
+ return;
3441
+ }
3442
+ setMoved(false);
3443
+ const holds = (path) => shows.files.some((file) => file.path === path);
3444
+ const showable = showablePatches(patches, board.file, holds, previews.current);
3445
+ if (showable.waiting)
3446
+ setStale(true);
3447
+ shown.current = source;
3448
+ if (showable.patches.length === 0)
3449
+ return;
3450
+ handle.current?.send("edit.patch", { patches: showable.patches }).catch(() => {});
3451
+ }, [loads, stored, source, shows, board.file]);
3452
+ useEffect6(() => {
3453
+ if (!stale || holding && !moved || version.revision <= pinned.revision)
3454
+ return;
3455
+ setStale(false);
3456
+ setPinned(version);
3457
+ }, [stale, holding, moved, version, pinned.revision]);
3458
+ const resync = useCallback5(() => {
3459
+ shown.current = null;
3460
+ handle.current?.send("reload", {}).catch(() => {});
3461
+ }, []);
3462
+ return {
3463
+ shows,
3464
+ source,
3465
+ handle,
3466
+ loads,
3467
+ ready,
3468
+ resync,
3469
+ stale,
3470
+ moved,
3471
+ previews: previews.current,
3472
+ hold: setHolding
3473
+ };
3474
+ }
3475
+ function BoardStage({
3476
+ version,
3477
+ board,
3478
+ title,
3479
+ scale,
3480
+ live,
3481
+ canvas,
3482
+ mode,
3483
+ pins,
3484
+ activePin,
3485
+ draft,
3486
+ fallback,
3487
+ failure,
3488
+ onPress,
3489
+ onPick,
3490
+ onOpenPin,
3491
+ onSubmitDraft,
3492
+ onCancelDraft
3493
+ }) {
3494
+ const messages = useArtifactMessages().canvas;
3495
+ const frame = useBoardFrame({ version, board, live });
3496
+ const editing = mode === "edit" && canvas !== null;
3497
+ const [selected, setSelected] = useState9(null);
3498
+ const [hovered, setHovered] = useState9(null);
3499
+ const commenting = mode === "comment";
3500
+ const picked = useRef7(null);
3501
+ picked.current = editing ? selected : null;
3502
+ const moved = useRef7(frame.moved);
3503
+ moved.current = frame.moved;
3504
+ const { hold } = frame;
3505
+ useEffect6(() => {
3506
+ hold(editing && selected?.kind === "text");
3507
+ }, [hold, editing, selected]);
3508
+ useEffect6(() => {
3509
+ if (!editing || frame.moved) {
3510
+ picked.current = null;
3511
+ setSelected(null);
3512
+ }
3513
+ }, [editing, frame.moved]);
3514
+ useEffect6(() => {
3515
+ if (!commenting || frame.moved)
3516
+ setHovered(null);
3517
+ }, [commenting, frame.moved]);
3518
+ useEffect6(() => {
3519
+ if (!draft)
3520
+ setHovered(null);
3521
+ }, [draft]);
3522
+ const port = useRef7(null);
3523
+ const onEditRef = useRef7(() => {});
3524
+ useEffect6(() => {
3525
+ if (frame.loads === 0)
3526
+ return;
3527
+ const channel = new MessageChannel;
3528
+ channel.port1.onmessage = (message) => {
3529
+ const event = parseFrameEvent(message.data);
3530
+ if (event?.event.startsWith("edit."))
3531
+ onEditRef.current(event);
3532
+ };
3533
+ port.current = { mine: channel.port1, handed: channel.port2 };
3534
+ return () => channel.port1.close();
3535
+ }, [frame.loads]);
3536
+ const send = frame.handle;
3537
+ useEffect6(() => {
3538
+ if (frame.loads === 0)
3539
+ return;
3540
+ const handed = port.current?.handed;
3541
+ if (port.current)
3542
+ port.current.handed = null;
3543
+ send.current?.send("edit", { on: mode !== "read" && !frame.moved, typing: editing }, handed ? [handed] : []).catch(() => {});
3544
+ }, [frame.loads, frame.moved, mode, editing, send]);
3545
+ const point = useCallback5((at, rect) => {
3546
+ const x = at?.x ?? rect.x + rect.width;
3547
+ const y = at?.y ?? rect.y;
3548
+ return {
3549
+ x: Math.min(1, Math.max(0, x / board.w)),
3550
+ y: Math.min(1, Math.max(0, y / board.h))
3551
+ };
3552
+ }, [board.w, board.h]);
3553
+ const onEvent = useCallback5((event) => {
3554
+ if (event.event === "ready") {
3555
+ picked.current = null;
3556
+ setSelected(null);
3557
+ setHovered(null);
3558
+ frame.ready();
3559
+ } else if (event.event === "press") {
3560
+ onPress(event.params.text);
3561
+ }
3562
+ }, [frame, onPress]);
3563
+ onEditRef.current = (event) => {
3564
+ if (moved.current)
3565
+ return;
3566
+ switch (event.event) {
3567
+ case "edit.hover": {
3568
+ if (commenting)
3569
+ setHovered(event.params.target);
3570
+ return;
3571
+ }
3572
+ case "edit.select": {
3573
+ const { target, at } = event.params;
3574
+ if (commenting) {
3575
+ if (!target)
3576
+ return;
3577
+ setHovered(null);
3578
+ const element = target.address ?? target.within ?? undefined;
3579
+ onPick({
3580
+ ...element ? { element } : {},
3581
+ ...target.label ? { label: target.label } : {},
3582
+ ...target.address === "body" ? { anchor: title } : {},
3583
+ point: point(at, target.rect),
3584
+ under: Math.min(1, (target.rect.y + target.rect.height) / board.h)
3585
+ });
3586
+ return;
3587
+ }
3588
+ if (!editing)
3589
+ return;
3590
+ picked.current = target;
3591
+ setSelected(target);
3592
+ return;
3593
+ }
3594
+ case "edit.text": {
3595
+ const chosen = picked.current;
3596
+ const { address, base, text } = event.params;
3597
+ if (!canvas || chosen?.kind !== "text" || chosen.address !== address)
3598
+ return;
3599
+ try {
3600
+ canvas.editBoard(board.file, (source) => mergeBoardText(source, address, base, text));
3601
+ } catch {
3602
+ picked.current = null;
3603
+ setSelected(null);
3604
+ frame.resync();
3605
+ }
3606
+ return;
3607
+ }
3608
+ default:
3609
+ return;
3610
+ }
3611
+ };
3612
+ return /* @__PURE__ */ jsxs11("div", {
3613
+ className: "relative size-full",
3614
+ children: [
3615
+ /* @__PURE__ */ jsx13("div", {
3616
+ className: "absolute inset-0 overflow-hidden rounded-[inherit]",
3617
+ children: /* @__PURE__ */ jsx13("div", {
3618
+ className: "absolute top-0 left-0 origin-top-left",
3619
+ style: { width: board.w, height: board.h, transform: `scale(${scale})` },
3620
+ children: /* @__PURE__ */ jsx13(ArtifactFrame, {
3621
+ version: frame.shows,
3622
+ entry: board.file,
3623
+ title: messages.boardFrame(title),
3624
+ className: "size-full",
3625
+ editable: true,
3626
+ handle: frame.handle,
3627
+ onEvent,
3628
+ fallback,
3629
+ failure
3630
+ }, board.id)
3631
+ })
3632
+ }),
3633
+ /* @__PURE__ */ jsxs11("div", {
3634
+ className: "pointer-events-none absolute inset-0",
3635
+ "data-board-overlay": "",
3636
+ children: [
3637
+ pins.map((pin, index) => {
3638
+ const at = pinPoint(pin, pin.point ? 0 : index);
3639
+ return /* @__PURE__ */ jsx13("div", {
3640
+ className: "absolute",
3641
+ style: { left: at.x * board.w * scale, top: at.y * board.h * scale },
3642
+ children: /* @__PURE__ */ jsx13(CommentPin, {
3643
+ number: pin.number,
3644
+ label: pin.label,
3645
+ active: activePin === pin.id,
3646
+ resolved: pin.resolved,
3647
+ onClick: () => onOpenPin(pin.id)
3648
+ })
3649
+ }, pin.id);
3650
+ }),
3651
+ commenting && hovered && !draft ? /* @__PURE__ */ jsx13(HoverTag, {
3652
+ target: hovered,
3653
+ scale
3654
+ }) : null,
3655
+ draft ? /* @__PURE__ */ jsxs11("div", {
3656
+ className: "absolute",
3657
+ style: { left: draft.point.x * board.w * scale, top: draft.point.y * board.h * scale },
3658
+ children: [
3659
+ /* @__PURE__ */ jsx13(CommentPin, {
3660
+ label: messages.comments.newPin,
3661
+ active: true,
3662
+ resolved: false,
3663
+ draft: true
3664
+ }),
3665
+ /* @__PURE__ */ jsx13("div", {
3666
+ className: cn10("absolute", draftAbove(draft) ? "bottom-9" : null),
3667
+ style: {
3668
+ ...cardPlace(draft.point.x * board.w * scale, board.w * scale),
3669
+ ...draftAbove(draft) ? {} : {
3670
+ top: Math.max(0, ((draft.under ?? draft.point.y) - draft.point.y) * board.h * scale) + 10
3671
+ }
3672
+ },
3673
+ children: /* @__PURE__ */ jsx13(DraftCard, {
3674
+ ...draft.anchor ? { anchor: draft.anchor } : {},
3675
+ onSubmit: onSubmitDraft,
3676
+ onCancel: onCancelDraft
3677
+ })
3678
+ })
3679
+ ]
3680
+ }) : null,
3681
+ editing && selected ? /* @__PURE__ */ jsx13(ElementTools, {
3682
+ target: selected,
3683
+ scale,
3684
+ board,
3685
+ version,
3686
+ live,
3687
+ canvas,
3688
+ source: frame.source,
3689
+ previews: frame.previews,
3690
+ onComment: () => onPick({
3691
+ ...selected.address !== null ? { element: selected.address, label: selected.label } : selected.within ? { element: selected.within } : {},
3692
+ point: point(undefined, selected.rect)
3693
+ })
3694
+ }, selected.address ?? "scripted") : null
3695
+ ]
3696
+ }),
3697
+ frame.stale ? /* @__PURE__ */ jsxs11("span", {
3698
+ role: "status",
3699
+ className: "absolute right-3 bottom-3 flex items-center gap-1.5 rounded-full bg-background/95 px-2.5 py-1 text-xs text-muted-foreground shadow-sm ring-1 ring-border",
3700
+ children: [
3701
+ /* @__PURE__ */ jsx13(LoaderCircle3, {
3702
+ className: "size-3 animate-spin motion-reduce:animate-none",
3703
+ "aria-hidden": true
3704
+ }),
3705
+ messages.edit.updating
3706
+ ]
3707
+ }) : null
3708
+ ]
3709
+ });
3710
+ }
3711
+ function draftAbove(draft) {
3712
+ return (draft.under ?? draft.point.y) > 0.7 && draft.point.y > 0.5;
3713
+ }
3714
+ function HoverTag({ target, scale }) {
3715
+ const messages = useArtifactMessages().canvas;
3716
+ const name = target.address === "body" ? messages.comments.wholeBoard : target.label ? `\u201C${target.label}\u201D` : target.address === null ? messages.comments.elsewhere : messages.edit.kinds[target.kind];
3717
+ const top = target.rect.y * scale;
3718
+ return /* @__PURE__ */ jsx13("div", {
3719
+ "aria-hidden": "true",
3720
+ className: cn10("absolute max-w-64 truncate rounded-md bg-[#0a84ff] px-1.5 py-0.5 text-[11px] leading-4 font-medium text-white shadow-sm", top < 24 ? "translate-y-1" : "-translate-y-[calc(100%+5px)]"),
3721
+ style: { left: target.rect.x * scale - 3, top },
3722
+ children: name
3723
+ });
3724
+ }
3725
+ function ElementTools({
3726
+ target,
3727
+ scale,
3728
+ board,
3729
+ version,
3730
+ live,
3731
+ canvas,
3732
+ source,
3733
+ previews,
3734
+ onComment
3735
+ }) {
3736
+ const messages = useArtifactMessages().canvas;
3737
+ const rect = target.rect;
3738
+ const toolbar = useRef7(null);
3739
+ const [width, setWidth] = useState9(0);
3740
+ useLayoutEffect2(() => {
3741
+ setWidth(toolbar.current?.offsetWidth ?? 0);
3742
+ });
3743
+ const left = Math.max(4, Math.min(rect.x * scale, board.w * scale - width - 4));
3744
+ const above = rect.y * scale >= 44;
3745
+ const top = above ? rect.y * scale - 40 : (rect.y + rect.height) * scale + 8;
3746
+ return /* @__PURE__ */ jsxs11("div", {
3747
+ ref: toolbar,
3748
+ role: "toolbar",
3749
+ "aria-label": messages.edit.tools,
3750
+ "data-board-tools": "",
3751
+ className: "pointer-events-auto absolute flex max-w-[calc(100%-8px)] items-center gap-0.5 rounded-xl border border-border bg-background/95 p-1 shadow-[0_1px_2px_rgb(0_0_0/0.08),0_10px_28px_-14px_rgb(0_0_0/0.35)] backdrop-blur motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-bottom-1",
3752
+ style: { left, top },
3753
+ children: [
3754
+ target.kind === "scripted" ? /* @__PURE__ */ jsxs11("span", {
3755
+ className: "flex min-w-0 items-center gap-2 px-2 text-xs",
3756
+ children: [
3757
+ /* @__PURE__ */ jsx13(Code2, {
3758
+ className: "size-3.5 shrink-0 text-muted-foreground",
3759
+ "aria-hidden": "true"
3760
+ }),
3761
+ /* @__PURE__ */ jsxs11("span", {
3762
+ className: "min-w-0",
3763
+ children: [
3764
+ /* @__PURE__ */ jsx13("span", {
3765
+ className: "font-medium text-foreground",
3766
+ children: messages.edit.scripted
3767
+ }),
3768
+ /* @__PURE__ */ jsxs11("span", {
3769
+ className: "text-muted-foreground",
3770
+ children: [
3771
+ " \xB7 ",
3772
+ messages.edit.scriptedHint
3773
+ ]
3774
+ })
3775
+ ]
3776
+ })
3777
+ ]
3778
+ }) : /* @__PURE__ */ jsxs11(Fragment6, {
3779
+ children: [
3780
+ /* @__PURE__ */ jsx13("span", {
3781
+ className: "max-w-40 truncate px-2 text-xs font-medium text-foreground",
3782
+ children: messages.edit.element(messages.edit.kinds[target.kind], tagOf(target.address))
3783
+ }),
3784
+ /* @__PURE__ */ jsx13("span", {
3785
+ "aria-hidden": "true",
3786
+ className: "mx-0.5 h-5 w-px bg-border"
3787
+ }),
3788
+ target.kind === "image" ? /* @__PURE__ */ jsx13(ImageTool, {
3789
+ address: target.address,
3790
+ board,
3791
+ version,
3792
+ live,
3793
+ canvas,
3794
+ source,
3795
+ previews
3796
+ }) : null,
3797
+ /* @__PURE__ */ jsx13(StyleTool, {
3798
+ address: target.address,
3799
+ words: target.kind === "text" || target.kind === "box",
3800
+ board,
3801
+ canvas,
3802
+ source
3803
+ })
3804
+ ]
3805
+ }),
3806
+ /* @__PURE__ */ jsx13("span", {
3807
+ "aria-hidden": "true",
3808
+ className: "mx-0.5 h-5 w-px bg-border"
3809
+ }),
3810
+ /* @__PURE__ */ jsx13(ToolButton, {
3811
+ label: messages.toolbar.comment,
3812
+ onClick: onComment,
3813
+ children: /* @__PURE__ */ jsx13(MessageSquarePlus3, {})
3814
+ })
3815
+ ]
3816
+ });
3817
+ }
3818
+ function tagOf(address) {
3819
+ return address.split(">").at(-1)?.split(":")[0] ?? "";
3820
+ }
3821
+ function StyleTool({
3822
+ address,
3823
+ words,
3824
+ board,
3825
+ canvas,
3826
+ source
3827
+ }) {
3828
+ const messages = useArtifactMessages().canvas.edit;
3829
+ const style = useMemo5(() => source === null ? {} : boardInlineStyle(source, address), [source, address]);
3830
+ const change = (properties) => {
3831
+ try {
3832
+ canvas.stopCapturing();
3833
+ canvas.editBoard(board.file, (page) => setBoardStyle(page, address, properties));
3834
+ canvas.stopCapturing();
3835
+ return true;
3836
+ } catch {
3837
+ return false;
3838
+ }
3839
+ };
3840
+ return /* @__PURE__ */ jsxs11(Popover, {
3841
+ modal: false,
3842
+ children: [
3843
+ /* @__PURE__ */ jsx13(PopoverTrigger, {
3844
+ asChild: true,
3845
+ children: /* @__PURE__ */ jsx13(ToolButton, {
3846
+ label: messages.style,
3847
+ children: /* @__PURE__ */ jsx13(Paintbrush, {})
3848
+ })
3849
+ }),
3850
+ /* @__PURE__ */ jsx13(PopoverContent, {
3851
+ align: "start",
3852
+ sideOffset: 8,
3853
+ className: "w-auto p-3",
3854
+ onOpenAutoFocus: (event) => event.preventDefault(),
3855
+ children: /* @__PURE__ */ jsx13(StylePanel, {
3856
+ style,
3857
+ words,
3858
+ onChange: change
3859
+ })
3860
+ })
3861
+ ]
3862
+ });
3863
+ }
3864
+ function ImageTool({
3865
+ address,
3866
+ board,
3867
+ version,
3868
+ live,
3869
+ canvas,
3870
+ source,
3871
+ previews
3872
+ }) {
3873
+ const messages = useArtifactMessages().canvas.edit;
3874
+ const locale = useLocale2();
3875
+ const files = useArtifactMessages();
3876
+ const stored = useLiveStoredFiles(live);
3877
+ const [uploading, setUploading] = useState9(false);
3878
+ const [failure, setFailure] = useState9(null);
3879
+ const src = source === null ? null : boardAttribute(source, address, "src");
3880
+ const alt = source === null ? "" : boardAttribute(source, address, "alt") ?? "";
3881
+ const current = src === null ? null : boardReferencePath(board.file, src);
3882
+ const images = useMemo5(() => {
3883
+ const listed = new Map;
3884
+ for (const file of version.files) {
3885
+ if (!IMAGE_EXTENSIONS.test(file.path))
3886
+ continue;
3887
+ const url = versionFileSource(version, file.path)?.inlineUrl;
3888
+ listed.set(file.path, { path: file.path, ...url ? { url } : {} });
3889
+ }
3890
+ for (const path of stored.keys()) {
3891
+ if (IMAGE_EXTENSIONS.test(path) && !listed.has(path)) {
3892
+ const preview = previews.get(path);
3893
+ listed.set(path, { path, ...preview ? { url: preview } : {} });
3894
+ }
3895
+ }
3896
+ return [...listed.values()];
3897
+ }, [version, stored, previews]);
3898
+ const change = (image, files = {}) => {
3899
+ try {
3900
+ canvas.stopCapturing();
3901
+ canvas.editBoard(board.file, (page) => setBoardImage(page, address, image), files);
3902
+ canvas.stopCapturing();
3903
+ return true;
3904
+ } catch {
3905
+ setFailure(messages.notImage);
3906
+ return false;
3907
+ }
3908
+ };
3909
+ const show = (path, files = {}) => change({ src: boardFilePath(board.file, path), alt: "" }, files);
3910
+ const upload = async (file) => {
3911
+ if (file.size > ARTIFACT_LIMITS3.maxFileBytes) {
3912
+ setFailure(messages.tooLarge(formatFileSize(ARTIFACT_LIMITS3.maxFileBytes, locale, files.files)));
3913
+ return false;
3914
+ }
3915
+ setUploading(true);
3916
+ setFailure(null);
3917
+ try {
3918
+ const path = imagePath(board.file, file.name);
3919
+ const [ref, preview] = await Promise.all([
3920
+ uploadFile(file, { fileName: path.split("/").at(-1) ?? path }),
3921
+ dataUrl(file).catch(() => null)
3922
+ ]);
3923
+ if (preview)
3924
+ previews.set(path, preview);
3925
+ return show(path, { [path]: ref });
3926
+ } catch {
3927
+ setFailure(messages.uploadFailed);
3928
+ return false;
3929
+ } finally {
3930
+ setUploading(false);
3931
+ }
3932
+ };
3933
+ return /* @__PURE__ */ jsxs11(Popover, {
3934
+ modal: false,
3935
+ children: [
3936
+ /* @__PURE__ */ jsx13(PopoverTrigger, {
3937
+ asChild: true,
3938
+ children: /* @__PURE__ */ jsx13(ToolButton, {
3939
+ label: messages.replace,
3940
+ children: /* @__PURE__ */ jsx13(ImageIcon2, {})
3941
+ })
3942
+ }),
3943
+ /* @__PURE__ */ jsx13(PopoverContent, {
3944
+ align: "start",
3945
+ sideOffset: 8,
3946
+ className: "w-auto p-3",
3947
+ onOpenAutoFocus: (event) => event.preventDefault(),
3948
+ children: /* @__PURE__ */ jsx13(ImagePanel, {
3949
+ current,
3950
+ alt,
3951
+ images,
3952
+ uploading,
3953
+ failure,
3954
+ onUpload: upload,
3955
+ onPick: show,
3956
+ onAlt: (text) => {
3957
+ change({ alt: text });
3958
+ }
3959
+ })
3960
+ })
3961
+ ]
3962
+ });
3963
+ }
3964
+ function imagePath(board, name) {
3965
+ const folder = board.split("/").slice(0, -1);
3966
+ const extension = /\.([a-z0-9]{1,5})$/i.exec(name)?.[1]?.toLowerCase() ?? "png";
3967
+ const stem = name.replace(/\.[^.]*$/, "").toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || "image";
3968
+ const suffix = Array.from(crypto.getRandomValues(new Uint8Array(6)), (byte) => String.fromCharCode(97 + byte % 26)).join("");
3969
+ return [...folder, "images", `${stem}-${suffix}.${extension}`].join("/");
3970
+ }
3971
+ async function dataUrl(file) {
3972
+ const bytes = new Uint8Array(await file.arrayBuffer());
3973
+ let binary = "";
3974
+ for (let at = 0;at < bytes.length; at += 32768) {
3975
+ binary += String.fromCharCode(...bytes.subarray(at, at + 32768));
3976
+ }
3977
+ return `data:${file.type || "application/octet-stream"};base64,${btoa(binary)}`;
3978
+ }
3979
+ var TOOL2 = "flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-muted data-[state=open]:text-foreground [&_svg]:size-4";
3980
+ var ToolButton = forwardRef2(function ToolButton({ label, children, ...props }, ref) {
3981
+ return /* @__PURE__ */ jsx13("button", {
3982
+ ref,
3983
+ type: "button",
3984
+ "aria-label": label,
3985
+ title: label,
3986
+ className: TOOL2,
3987
+ ...props,
3988
+ children
3989
+ });
3990
+ });
3991
+
3992
+ // src/artifacts/renderers/canvas/focus.tsx
3993
+ import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
3994
+ function BoardFocus({
3995
+ version,
3996
+ boards,
3997
+ arrows,
3998
+ id,
3999
+ pictureOf,
4000
+ onOpen,
4001
+ onClose,
4002
+ live = null,
4003
+ canvas = null,
4004
+ mode = "read",
4005
+ pins = [],
4006
+ activePin = null,
4007
+ draft = null,
4008
+ tools,
4009
+ onEscape,
4010
+ onPick,
4011
+ onOpenPin,
4012
+ onSubmitDraft,
4013
+ onCancelDraft
4014
+ }) {
4015
+ const messages = useArtifactMessages().canvas;
4016
+ const index = boards.findIndex((board) => board.id === id);
4017
+ const board = boards[index];
4018
+ const previous = boards[index - 1];
4019
+ const next = boards[index + 1];
4020
+ const [stage, setStage] = useState10(null);
4021
+ const room = useSize(stage);
4022
+ const onPress = useCallback6((text) => {
4023
+ const to = followedArrow(arrows, boards, id, text);
4024
+ if (to)
4025
+ onOpen(to);
4026
+ }, [arrows, boards, id, onOpen]);
4027
+ const pick = useCallback6((place) => onPick?.(id, place), [onPick, id]);
4028
+ useEffect7(() => {
4029
+ const onKey = (event) => {
4030
+ if (event.metaKey || event.ctrlKey || event.altKey)
4031
+ return;
4032
+ const target = event.target;
4033
+ if (target instanceof Element && target.closest("input, textarea, select, [contenteditable], [data-board-tools]")) {
4034
+ return;
4035
+ }
4036
+ if (event.key === "Escape") {
4037
+ if (!onEscape?.())
4038
+ onClose();
4039
+ } else if (event.key === "ArrowLeft" && previous)
4040
+ onOpen(previous.id);
4041
+ else if (event.key === "ArrowRight" && next)
4042
+ onOpen(next.id);
4043
+ else
4044
+ return;
4045
+ event.preventDefault();
4046
+ };
4047
+ window.addEventListener("keydown", onKey);
4048
+ return () => window.removeEventListener("keydown", onKey);
4049
+ }, [previous, next, onOpen, onClose, onEscape]);
4050
+ if (!board)
4051
+ return null;
4052
+ const title = board.title ?? board.id;
4053
+ const scale = room ? Math.min(MAX_SCALE, room.width / board.w, room.height / board.h) : 0;
4054
+ const picture = pictureOf?.(board.id);
4055
+ return /* @__PURE__ */ jsxs12("div", {
4056
+ role: "dialog",
4057
+ "aria-label": messages.focused(title),
4058
+ className: "absolute inset-0 z-10 flex flex-col bg-background motion-safe:animate-in motion-safe:fade-in motion-safe:duration-200",
4059
+ children: [
4060
+ /* @__PURE__ */ jsxs12("div", {
4061
+ className: "flex h-12 shrink-0 items-center gap-2 border-b border-border/70 px-2",
4062
+ children: [
4063
+ /* @__PURE__ */ jsxs12("button", {
4064
+ type: "button",
4065
+ onClick: onClose,
4066
+ className: "flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-sm font-medium text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
4067
+ children: [
4068
+ /* @__PURE__ */ jsx14(ArrowLeft, {
4069
+ className: "size-4",
4070
+ "aria-hidden": "true"
4071
+ }),
4072
+ messages.back
4073
+ ]
4074
+ }),
4075
+ /* @__PURE__ */ jsx14("span", {
4076
+ className: "h-5 w-px bg-border",
4077
+ "aria-hidden": "true"
4078
+ }),
4079
+ /* @__PURE__ */ jsx14("span", {
4080
+ className: "min-w-0 truncate px-1 text-sm font-semibold",
4081
+ children: title
4082
+ }),
4083
+ mode === "edit" || mode === "comment" ? /* @__PURE__ */ jsx14("span", {
4084
+ className: "hidden min-w-0 truncate text-xs text-muted-foreground @5xl/canvas:inline",
4085
+ children: mode === "edit" ? messages.edit.hint : messages.comments.modeHint
4086
+ }) : null,
4087
+ tools ? /* @__PURE__ */ jsx14("div", {
4088
+ className: "ml-auto flex shrink-0 items-center",
4089
+ children: tools
4090
+ }) : null,
4091
+ /* @__PURE__ */ jsx14("span", {
4092
+ className: `${tools ? "" : "ml-auto "}shrink-0 text-xs whitespace-nowrap text-muted-foreground tabular-nums max-sm:hidden`,
4093
+ children: messages.position(index + 1, boards.length)
4094
+ }),
4095
+ /* @__PURE__ */ jsx14(Step, {
4096
+ label: messages.previousBoard,
4097
+ disabled: !previous,
4098
+ onClick: () => previous && onOpen(previous.id),
4099
+ children: /* @__PURE__ */ jsx14(ChevronLeft, {
4100
+ className: "size-4",
4101
+ "aria-hidden": "true"
4102
+ })
4103
+ }),
4104
+ /* @__PURE__ */ jsx14(Step, {
4105
+ label: messages.nextBoard,
4106
+ disabled: !next,
4107
+ onClick: () => next && onOpen(next.id),
4108
+ children: /* @__PURE__ */ jsx14(ChevronRight, {
4109
+ className: "size-4",
4110
+ "aria-hidden": "true"
4111
+ })
4112
+ })
4113
+ ]
4114
+ }),
4115
+ /* @__PURE__ */ jsx14("div", {
4116
+ className: "flex min-h-0 flex-1 overflow-hidden bg-muted/40 p-3 sm:p-6",
4117
+ children: /* @__PURE__ */ jsx14("div", {
4118
+ ref: setStage,
4119
+ className: "flex min-h-0 min-w-0 flex-1 items-center justify-center",
4120
+ children: scale > 0 ? /* @__PURE__ */ jsx14("div", {
4121
+ className: "sixb-canvas-surface relative shrink-0 motion-safe:animate-in motion-safe:fade-in motion-safe:zoom-in-97 motion-safe:duration-300 motion-safe:ease-out",
4122
+ style: { width: board.w * scale, height: board.h * scale },
4123
+ children: /* @__PURE__ */ jsx14(BoardStage, {
4124
+ version,
4125
+ board,
4126
+ title,
4127
+ scale,
4128
+ live,
4129
+ canvas,
4130
+ mode,
4131
+ pins: pins.filter((pin) => pin.board === board.id),
4132
+ activePin,
4133
+ draft: draft?.board === board.id ? draft : null,
4134
+ fallback: picture ? /* @__PURE__ */ jsx14(BoardPicture, {
4135
+ src: picture
4136
+ }) : undefined,
4137
+ failure: /* @__PURE__ */ jsxs12("div", {
4138
+ className: "relative size-full",
4139
+ children: [
4140
+ picture ? /* @__PURE__ */ jsx14(BoardPicture, {
4141
+ src: picture
4142
+ }) : null,
4143
+ /* @__PURE__ */ jsx14("p", {
4144
+ className: "absolute inset-x-0 bottom-0 m-0 bg-background/90 px-4 py-2 text-sm text-muted-foreground",
4145
+ children: messages.boardFailed
4146
+ })
4147
+ ]
4148
+ }),
4149
+ onPress,
4150
+ onPick: pick,
4151
+ onOpenPin: (pin) => onOpenPin?.(pin),
4152
+ onSubmitDraft: (body) => onSubmitDraft?.(body) ?? Promise.resolve(),
4153
+ onCancelDraft: () => onCancelDraft?.()
4154
+ })
4155
+ }, board.id) : null
4156
+ })
4157
+ })
4158
+ ]
4159
+ });
4160
+ }
4161
+ function followedArrow(arrows, boards, from, pressed) {
4162
+ const words = wordsOf(pressed);
4163
+ for (const arrow of arrows) {
4164
+ const to = arrow.to;
4165
+ if (arrow.from !== from || typeof to !== "string" || !arrow.label)
4166
+ continue;
4167
+ if (wordsOf(arrow.label) !== words)
4168
+ continue;
4169
+ if (boards.some((board) => board.id === to))
4170
+ return to;
4171
+ }
4172
+ return null;
4173
+ }
4174
+ function wordsOf(text) {
4175
+ return text.replace(/\s+/g, " ").trim().toLowerCase();
4176
+ }
4177
+ var MAX_SCALE = 2.5;
4178
+ function BoardPicture({ src }) {
4179
+ return /* @__PURE__ */ jsx14("img", {
4180
+ src,
4181
+ alt: "",
4182
+ decoding: "async",
4183
+ draggable: false,
4184
+ className: "absolute inset-0 block size-full object-contain object-top"
4185
+ });
4186
+ }
4187
+ function useSize(element) {
4188
+ const [size, setSize] = useState10(null);
4189
+ useEffect7(() => {
4190
+ if (!element)
4191
+ return;
4192
+ const measure = () => {
4193
+ const width = element.clientWidth;
4194
+ const height = element.clientHeight;
4195
+ setSize((last) => last && last.width === width && last.height === height ? last : { width, height });
4196
+ };
4197
+ measure();
4198
+ const observer = new ResizeObserver(measure);
4199
+ observer.observe(element);
4200
+ return () => observer.disconnect();
4201
+ }, [element]);
4202
+ return size;
4203
+ }
4204
+ function Step({
4205
+ label,
4206
+ disabled,
4207
+ onClick,
4208
+ children
4209
+ }) {
4210
+ return /* @__PURE__ */ jsx14("button", {
4211
+ type: "button",
4212
+ "aria-label": label,
4213
+ title: label,
4214
+ disabled,
4215
+ onClick,
4216
+ className: "flex size-8 items-center justify-center rounded-lg text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-35",
4217
+ children
4218
+ });
4219
+ }
4220
+
4221
+ // src/artifacts/renderers/canvas/presence.tsx
4222
+ import { useStore as useStore3, ViewportPortal as ViewportPortal2 } from "@xyflow/react";
4223
+ import { Sparkles as Sparkles2 } from "lucide-react";
4224
+ import { memo as memo4, useCallback as useCallback7 } from "react";
4225
+ import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
4226
+ var NAME_CLEARANCE = 96;
4227
+ function nameBelow(box, transform) {
4228
+ const [, panY = 0, zoom = 1] = transform;
4229
+ return box.y * zoom + panY < NAME_CLEARANCE;
4230
+ }
4231
+ var PresenceLayer = memo4(function PresenceLayer({
4232
+ live
4233
+ }) {
4234
+ const messages = useArtifactMessages().canvas.live;
4235
+ const all = useArtifactMessages();
4236
+ const guestLabel = all.canvas.comments.guest;
4237
+ const labels = { guest: guestLabel, teamMember: all.live.teamMember };
4238
+ const { peers, agents } = useLivePresence(live);
4239
+ const selected = new Map;
4240
+ for (const peer of peers) {
4241
+ for (const id of peer.selection)
4242
+ if (!selected.has(id))
4243
+ selected.set(id, peer.user);
4244
+ }
4245
+ const changing = [...new Set(agents.flatMap((agent) => agent.boards))];
4246
+ const boxes = useBoxes([...selected.keys(), ...changing]);
4247
+ const below = useStore3(useCallback7((state) => [...boxes].filter(([, box]) => nameBelow(box, state.transform)).map(([id]) => id).join(`
4248
+ `), [boxes]));
4249
+ if (boxes.size === 0)
4250
+ return null;
4251
+ return /* @__PURE__ */ jsxs13(ViewportPortal2, {
4252
+ children: [
4253
+ changing.map((id) => {
4254
+ const box = boxes.get(id);
4255
+ return box ? /* @__PURE__ */ jsx15("div", {
4256
+ "data-agent-board": id,
4257
+ className: "sixb-agent-board pointer-events-none absolute rounded-[12px]",
4258
+ style: place(box, 4),
4259
+ children: /* @__PURE__ */ jsx15("div", {
4260
+ className: "@container absolute top-3 right-3 flex origin-top-right justify-end",
4261
+ style: {
4262
+ width: `calc(${Math.max(box.w - 16, 0)}px / ${NAME_SCALE_VALUE})`,
4263
+ transform: `scale(${NAME_SCALE_VALUE})`
4264
+ },
4265
+ children: /* @__PURE__ */ jsxs13("span", {
4266
+ title: messages.agentChanging,
4267
+ className: "flex max-w-full min-w-0 items-center gap-1.5 rounded-full bg-background/95 px-2.5 py-1 text-[12px] font-medium whitespace-nowrap text-primary shadow-[0_1px_2px_rgb(0_0_0/0.08),0_6px_16px_-8px_rgb(0_0_0/0.3)] ring-1 ring-[color-mix(in_oklab,var(--primary)_25%,transparent)] @max-[8rem]:px-1.5",
4268
+ children: [
4269
+ /* @__PURE__ */ jsx15(Sparkles2, {
4270
+ className: "size-3.5 shrink-0 motion-safe:animate-pulse",
4271
+ "aria-hidden": "true"
4272
+ }),
4273
+ /* @__PURE__ */ jsx15("span", {
4274
+ className: "min-w-0 truncate @max-[8rem]:sr-only",
4275
+ children: messages.agentChanging
4276
+ })
4277
+ ]
4278
+ })
4279
+ })
4280
+ }, `agent:${id}`) : null;
4281
+ }),
4282
+ [...selected].map(([id, user]) => {
4283
+ const box = boxes.get(id);
4284
+ return box ? /* @__PURE__ */ jsx15("div", {
4285
+ "data-peer-selection": id,
4286
+ className: "pointer-events-none absolute rounded-[6px]",
4287
+ style: {
4288
+ ...place(box, 3),
4289
+ boxShadow: `0 0 0 calc(2px * ${NAME_SCALE_VALUE}) ${user.color}`
4290
+ },
4291
+ children: /* @__PURE__ */ jsxs13("span", {
4292
+ "data-name": below.split(`
4293
+ `).includes(id) ? "below" : "above",
4294
+ className: "absolute left-0 rounded-[4px] px-1.5 py-px text-[11px] leading-4 font-medium whitespace-nowrap text-white data-[name=above]:bottom-full data-[name=above]:mb-1 data-[name=above]:origin-bottom-left data-[name=below]:top-1 data-[name=below]:left-1 data-[name=below]:origin-top-left",
4295
+ style: { backgroundColor: user.color, transform: `scale(${NAME_SCALE_VALUE})` },
4296
+ children: [
4297
+ livePersonName(user, labels),
4298
+ user.guest && user.name ? /* @__PURE__ */ jsxs13("span", {
4299
+ className: "opacity-75",
4300
+ children: [
4301
+ " \xB7 ",
4302
+ guestLabel
4303
+ ]
4304
+ }) : null
4305
+ ]
4306
+ })
4307
+ }, `peer:${id}`) : null;
4308
+ })
4309
+ ]
4310
+ });
4311
+ });
4312
+ function place(box, margin) {
4313
+ return {
4314
+ transform: `translate(${box.x - margin}px, ${box.y - margin}px)`,
4315
+ width: box.w + margin * 2,
4316
+ height: box.h + margin * 2
4317
+ };
4318
+ }
4319
+ function useBoxes(ids) {
4320
+ const key = ids.join(`
4321
+ `);
4322
+ const select = useCallback7((state) => {
4323
+ const boxes = new Map;
4324
+ for (const id of key ? key.split(`
4325
+ `) : []) {
4326
+ const node = state.nodeLookup.get(id);
4327
+ const box = node ? boxOf(node) : null;
4328
+ if (box)
4329
+ boxes.set(id, box);
4330
+ }
4331
+ return boxes;
4332
+ }, [key]);
4333
+ return useStore3(select, sameBoxes2);
4334
+ }
4335
+ function boxOf(node) {
4336
+ const w = node.measured.width ?? node.width;
4337
+ const h = node.measured.height ?? node.height;
4338
+ if (w === undefined || h === undefined)
4339
+ return null;
4340
+ const { x, y } = node.internals.positionAbsolute;
4341
+ return { x, y, w, h };
4342
+ }
4343
+ function sameBoxes2(left, right) {
4344
+ if (left.size !== right.size)
4345
+ return false;
4346
+ for (const [id, box] of left) {
4347
+ const other = right.get(id);
4348
+ if (!other || other.x !== box.x || other.y !== box.y || other.w !== box.w || other.h !== box.h) {
4349
+ return false;
4350
+ }
4351
+ }
4352
+ return true;
4353
+ }
4354
+
4355
+ // src/artifacts/renderers/canvas/canvas.tsx
4356
+ import { jsx as jsx16, jsxs as jsxs14, Fragment as Fragment7 } from "react/jsx-runtime";
4357
+ var canvas_default = memo5(function CanvasBoard({
4358
+ canvas,
4359
+ version,
4360
+ title,
4361
+ mode,
4362
+ focus,
4363
+ edit,
4364
+ live,
4365
+ theme
4366
+ }) {
4367
+ return /* @__PURE__ */ jsx16(ReactFlowProvider, {
4368
+ children: /* @__PURE__ */ jsx16(Board, {
4369
+ canvas,
4370
+ title,
4371
+ mode,
4372
+ ...version ? { version } : {},
4373
+ ...focus ? { focus } : {},
4374
+ ...edit ? { edit } : {},
4375
+ ...live ? { liveArtifact: live } : {},
4376
+ ...theme ? { theme } : {}
4377
+ })
4378
+ });
4379
+ });
4380
+ function Board({
4381
+ canvas,
4382
+ version,
4383
+ title,
4384
+ mode,
4385
+ focus,
4386
+ edit,
4387
+ liveArtifact,
4388
+ theme
4389
+ }) {
4390
+ const messages = useArtifactMessages().canvas;
4391
+ const boards = useMemo6(() => canvas.items.filter((item) => item.type === "board"), [canvas]);
4392
+ const arrows = useMemo6(() => canvas.items.filter((item) => item.type === "arrow"), [canvas]);
4393
+ const previews = useBoardPreviews(version);
4394
+ const places = useMemo6(() => canvas.items.flatMap((item) => item.type === "board" || item.type === "embed" ? [{ ...item, pictured: previews[item.id] === "ready" }] : []), [canvas, previews]);
4395
+ const running = useLiveSet(places);
4396
+ const [opened, setOpened] = useState11(() => focus && boards.some((board) => board.id === focus) ? focus : null);
4397
+ const { fitView } = useReactFlow2();
4398
+ const close = useCallback8(() => {
4399
+ const id = opened;
4400
+ setOpened(null);
4401
+ if (!id)
4402
+ return;
4403
+ fitView({ nodes: [{ id }], padding: CANVAS_FIT_PADDING, maxZoom: 1, duration: 220 });
4404
+ }, [opened, fitView]);
4405
+ const live = useMemo6(() => ({
4406
+ version: version ?? null,
4407
+ live: running,
4408
+ previews,
4409
+ mode,
4410
+ ...version ? { open: setOpened } : {}
4411
+ }), [version, running, previews, mode]);
4412
+ const pictureOf = useCallback8((id) => version && previews[id] === "ready" ? boardPreviewUrl(version, id, mode) : undefined, [version, previews, mode]);
4413
+ const board = useBoardEditing(canvas, edit, version ? setOpened : undefined);
4414
+ const editBoard = edit?.live?.editBoard;
4415
+ const stopCapturing = edit?.live?.stopCapturing;
4416
+ const boardEditor = useMemo6(() => editBoard && stopCapturing ? { editBoard, stopCapturing } : null, [editBoard, stopCapturing]);
4417
+ useNameScaleVariable(board.root);
4418
+ const view = useArtifactView();
4419
+ const commenting = useCanvasCommenting({
4420
+ artifactId: version && view && version.version === view.latestVersion ? version.artifactId : null,
4421
+ live: liveArtifact ?? null,
4422
+ title,
4423
+ boards,
4424
+ revision: view?.revision ?? version?.revision ?? 1
4425
+ });
4426
+ const { getInternalNode, screenToFlowPosition } = useReactFlow2();
4427
+ const { setCommenting, cancelDraft, draft } = commenting;
4428
+ const pointed = useRef8(false);
4429
+ useEffect8(() => {
4430
+ if (!commenting.enabled)
4431
+ return;
4432
+ const onKey = (event) => {
4433
+ if (event.metaKey || event.ctrlKey || event.altKey)
4434
+ return;
4435
+ const here = board.root.current;
4436
+ if (!here || !(pointed.current || here.contains(document.activeElement)))
4437
+ return;
4438
+ const target = event.target;
4439
+ if (target instanceof Element && target.closest("input, textarea, select, [contenteditable]")) {
4440
+ return;
4441
+ }
4442
+ if (event.key.toLowerCase() === "c" && !event.repeat) {
4443
+ event.preventDefault();
4444
+ commenting.toggleCommenting();
4445
+ } else if (event.key === "Escape" && !opened && (draft || commenting.commenting)) {
4446
+ event.preventDefault();
4447
+ if (draft)
4448
+ cancelDraft();
4449
+ else
4450
+ setCommenting(false);
4451
+ }
4452
+ };
4453
+ window.addEventListener("keydown", onKey);
4454
+ return () => window.removeEventListener("keydown", onKey);
4455
+ }, [commenting, opened, draft, cancelDraft, setCommenting, board.root]);
4456
+ const placing = useMemo6(() => commenting.commenting ? {
4457
+ nodesDraggable: false,
4458
+ nodesConnectable: false,
4459
+ elementsSelectable: false,
4460
+ onNodeClick: (event, node) => {
4461
+ if (node.type !== "board")
4462
+ return;
4463
+ const internal = getInternalNode(node.id);
4464
+ const item = boards.find((each) => each.id === node.id);
4465
+ if (!internal || !item)
4466
+ return;
4467
+ const at = screenToFlowPosition({ x: event.clientX, y: event.clientY });
4468
+ const { x, y } = internal.internals.positionAbsolute;
4469
+ commenting.pick(node.id, {
4470
+ point: {
4471
+ x: Math.min(1, Math.max(0, (at.x - x) / item.w)),
4472
+ y: Math.min(1, Math.max(0, (at.y - y) / item.h))
4473
+ }
4474
+ }, "canvas");
4475
+ },
4476
+ onPaneClick: () => cancelDraft()
4477
+ } : {}, [commenting, getInternalNode, screenToFlowPosition, boards, cancelDraft]);
4478
+ const showThread = useCallback8((id) => {
4479
+ commenting.setActive(id);
4480
+ const thread = commenting.threads.find((each) => each.comment.id === id);
4481
+ const on = thread?.comment.anchor.board;
4482
+ if (!on || !boards.some((each) => each.id === on))
4483
+ return;
4484
+ if (opened) {
4485
+ if (opened !== on)
4486
+ setOpened(on);
4487
+ return;
4488
+ }
4489
+ fitView({ nodes: [{ id: on }], padding: CANVAS_FIT_PADDING, maxZoom: 1, duration: 260 });
4490
+ }, [commenting, boards, opened, fitView]);
4491
+ const open = live.open;
4492
+ const reading = useMemo6(() => ({
4493
+ nodesDraggable: false,
4494
+ nodesConnectable: false,
4495
+ elementsSelectable: false,
4496
+ onNodeDoubleClick: (_, node) => {
4497
+ if (node.type === "board")
4498
+ open?.(node.id);
4499
+ }
4500
+ }), [open]);
4501
+ const framed = useMemo6(() => {
4502
+ const item = focus ? canvas.items.find((candidate) => candidate.id === focus) : undefined;
4503
+ return item && item.type !== "arrow" && item.type !== "text" ? item.id : undefined;
4504
+ }, [canvas, focus]);
4505
+ const fitOptions = useMemo6(() => ({
4506
+ padding: CANVAS_FIT_PADDING,
4507
+ maxZoom: 1,
4508
+ ...framed ? { nodes: [{ id: framed }] } : {}
4509
+ }), [framed]);
4510
+ return /* @__PURE__ */ jsxs14("div", {
4511
+ ref: board.root,
4512
+ tabIndex: board.editing ? -1 : undefined,
4513
+ className: "sixb-canvas sixb-artboard @container/canvas relative flex size-full bg-background outline-none",
4514
+ "data-editing": board.editing ? "" : undefined,
4515
+ "data-commenting": commenting.commenting ? "" : undefined,
4516
+ onPointerEnter: () => {
4517
+ pointed.current = true;
4518
+ },
4519
+ onPointerLeave: () => {
4520
+ pointed.current = false;
4521
+ },
4522
+ "data-live": liveArtifact ? "" : undefined,
4523
+ role: "region",
4524
+ "aria-label": messages.canvas(title),
4525
+ onKeyDown: (event) => {
4526
+ if (event.target.closest(COMMENTS))
4527
+ return;
4528
+ if (board.editing) {
4529
+ board.onKeyDown(event);
4530
+ return;
4531
+ }
4532
+ if (event.key !== "Enter" || !live.open)
4533
+ return;
4534
+ const id = event.target.closest(".react-flow__node")?.getAttribute("data-id");
4535
+ if (id && boards.some((board) => board.id === id))
4536
+ live.open(id);
4537
+ },
4538
+ children: [
4539
+ /* @__PURE__ */ jsxs14("div", {
4540
+ className: cn11("relative h-full min-w-0 flex-1 bg-background text-foreground", theme?.className),
4541
+ style: theme?.style,
4542
+ children: [
4543
+ /* @__PURE__ */ jsx16(LiveBoardsProvider, {
4544
+ value: live,
4545
+ children: /* @__PURE__ */ jsx16(CanvasEditingProvider, {
4546
+ value: board.editing ? board.items : null,
4547
+ children: /* @__PURE__ */ jsxs14(ReactFlow, {
4548
+ nodes: board.nodes,
4549
+ edges: board.edges,
4550
+ nodeTypes: CANVAS_NODE_TYPES,
4551
+ edgeTypes: CANVAS_EDGE_TYPES,
4552
+ colorMode: mode,
4553
+ fitView: true,
4554
+ fitViewOptions: fitOptions,
4555
+ onlyRenderVisibleElements: true,
4556
+ minZoom: 0.04,
4557
+ maxZoom: 2.5,
4558
+ panOnScroll: true,
4559
+ zoomOnScroll: false,
4560
+ zoomOnPinch: true,
4561
+ zoomActivationKeyCode: ["Meta", "Control"],
4562
+ zoomOnDoubleClick: false,
4563
+ panOnDrag: true,
4564
+ ...board.editing ? board.flow : reading,
4565
+ ...placing,
4566
+ proOptions: { hideAttribution: true },
4567
+ children: [
4568
+ /* @__PURE__ */ jsx16(Background, {
4569
+ variant: BackgroundVariant.Dots,
4570
+ gap: 24,
4571
+ size: 1.3
4572
+ }),
4573
+ /* @__PURE__ */ jsx16(CanvasControls, {
4574
+ padding: CANVAS_FIT_PADDING
4575
+ }),
4576
+ liveArtifact ? /* @__PURE__ */ jsx16(PresenceLayer, {
4577
+ live: liveArtifact
4578
+ }) : null,
4579
+ board.editing ? board.toolbar : null,
4580
+ commenting.enabled ? /* @__PURE__ */ jsxs14(Fragment7, {
4581
+ children: [
4582
+ /* @__PURE__ */ jsx16(CanvasCommentPins, {
4583
+ pins: commenting.pins,
4584
+ active: commenting.active,
4585
+ draft: draft?.where === "canvas" ? draft : null,
4586
+ onOpen: (id) => {
4587
+ commenting.setActive(id);
4588
+ commenting.setPanel(true);
4589
+ },
4590
+ onSubmitDraft: commenting.submitDraft,
4591
+ onCancelDraft: cancelDraft
4592
+ }),
4593
+ /* @__PURE__ */ jsx16(Panel3, {
4594
+ position: "top-right",
4595
+ className: "!m-3",
4596
+ children: /* @__PURE__ */ jsx16(CommentTools, {
4597
+ commenting
4598
+ })
4599
+ }),
4600
+ commenting.commenting ? /* @__PURE__ */ jsx16(ZoomVariable, {
4601
+ root: board.root
4602
+ }) : null
4603
+ ]
4604
+ }) : null
4605
+ ]
4606
+ })
4607
+ })
4608
+ }),
4609
+ commenting.enabled && commenting.commenting && !draft && !opened ? /* @__PURE__ */ jsx16("div", {
4610
+ className: "pointer-events-none absolute inset-x-0 bottom-4 z-20 flex justify-center px-4 max-sm:bottom-20",
4611
+ children: /* @__PURE__ */ jsx16(CommentModeHint, {
4612
+ onExit: () => setCommenting(false)
4613
+ })
4614
+ }) : null,
4615
+ opened && version ? /* @__PURE__ */ jsx16(BoardFocus, {
4616
+ version,
4617
+ boards,
4618
+ arrows,
4619
+ id: opened,
4620
+ pictureOf,
4621
+ onOpen: setOpened,
4622
+ onClose: close,
4623
+ live: liveArtifact ?? null,
4624
+ canvas: boardEditor,
4625
+ mode: commenting.commenting ? "comment" : boardEditor ? "edit" : "read",
4626
+ ...commenting.enabled ? {
4627
+ pins: commenting.pins,
4628
+ activePin: commenting.active,
4629
+ draft: draft?.where === "focus" ? draft : null,
4630
+ tools: /* @__PURE__ */ jsx16(CommentTools, {
4631
+ commenting,
4632
+ className: "border-0 bg-transparent p-0 shadow-none"
4633
+ }),
4634
+ onEscape: () => {
4635
+ if (draft)
4636
+ cancelDraft();
4637
+ else if (commenting.commenting)
4638
+ setCommenting(false);
4639
+ else
4640
+ return false;
4641
+ return true;
4642
+ },
4643
+ onPick: (id, pick) => commenting.pick(id, pick, "focus"),
4644
+ onOpenPin: (id) => {
4645
+ commenting.setActive(id);
4646
+ commenting.setPanel(true);
4647
+ },
4648
+ onSubmitDraft: commenting.submitDraft,
4649
+ onCancelDraft: cancelDraft
4650
+ } : {}
4651
+ }) : null
4652
+ ]
4653
+ }),
4654
+ commenting.enabled && commenting.panel ? /* @__PURE__ */ jsx16(CommentsPanel, {
4655
+ threads: commenting.threads,
4656
+ loading: commenting.loading,
4657
+ failed: commenting.failed,
4658
+ filter: commenting.filter,
4659
+ active: commenting.active,
4660
+ placeOf: commenting.placeOf,
4661
+ nameOf: commenting.nameOf,
4662
+ canManage: commenting.canManage,
4663
+ onFilter: commenting.setFilter,
4664
+ onActivate: showThread,
4665
+ onReply: commenting.reply,
4666
+ onResolve: commenting.resolve,
4667
+ onDelete: commenting.remove,
4668
+ onSend: commenting.send,
4669
+ onClose: () => commenting.setPanel(false)
4670
+ }) : null
4671
+ ]
4672
+ });
4673
+ }
4674
+ var COMMENTS = "[data-comments-panel], [data-comment-pin], [data-board-tools]";
4675
+ function useNameScaleVariable(root) {
4676
+ const store = useStoreApi4();
4677
+ useEffect8(() => {
4678
+ let last = "";
4679
+ const update = () => {
4680
+ const element = root.current;
4681
+ const marks = zoomMarks(store.getState().transform[2]);
4682
+ const key = `${marks.nameScale} ${marks.far}`;
4683
+ if (!element || key === last)
4684
+ return;
4685
+ last = key;
4686
+ element.style.setProperty(NAME_SCALE, marks.nameScale);
4687
+ element.toggleAttribute("data-far", marks.far);
4688
+ };
4689
+ update();
4690
+ return store.subscribe(update);
4691
+ }, [store, root]);
4692
+ }
4693
+ function ZoomVariable({ root }) {
4694
+ const zoom = useStore4((state) => state.transform[2]);
4695
+ useEffect8(() => {
4696
+ root.current?.style.setProperty("--sixb-zoom", String(zoom));
4697
+ }, [root, zoom]);
4698
+ return null;
4699
+ }
4700
+ export {
4701
+ canvas_default as default
4702
+ };
4703
+
4704
+ //# debugId=061BF88EBA02626C64756E2164756E21