@agent-native/core-corpus 0.213.1 → 0.216.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1108) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/templates/analytics/.agents/skills/actions/references/action-fields.md +1 -1
  3. package/corpus/templates/analytics/CHANGELOG.md +1 -0
  4. package/corpus/templates/analytics/changelog/2026-10-21-session-replay-quotas-count-the-compressed-size-analytics-st.md +6 -0
  5. package/corpus/templates/analytics/server/lib/session-replay.ts +40 -9
  6. package/corpus/templates/assets/.agents/skills/actions/references/action-fields.md +1 -1
  7. package/corpus/templates/brain/.agents/skills/actions/references/action-fields.md +1 -1
  8. package/corpus/templates/calendar/.agents/skills/actions/references/action-fields.md +1 -1
  9. package/corpus/templates/chat/.agents/skills/actions/references/action-fields.md +1 -1
  10. package/corpus/templates/clips/.agents/skills/actions/references/action-fields.md +1 -1
  11. package/corpus/templates/community/qr/package.json +1 -1
  12. package/corpus/templates/content/.agents/skills/actions/references/action-fields.md +1 -1
  13. package/corpus/templates/content/.agents/skills/content-product-development/references/verification.md +36 -0
  14. package/corpus/templates/content/.agents/skills/document-editing/SKILL.md +10 -0
  15. package/corpus/templates/content/.agents/skills/document-editing/references/databases.md +26 -1
  16. package/corpus/templates/content/.agents/skills/notion-integration/SKILL.md +4 -2
  17. package/corpus/templates/content/CHANGELOG.md +51 -0
  18. package/corpus/templates/content/acceptance/_writers.ts +604 -0
  19. package/corpus/templates/content/acceptance/generate-action-registry.ts +10 -0
  20. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/create-document.json +75 -0
  21. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/duplicate-page.json +75 -0
  22. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/edit-document-find-and-replace-without-a-revision.json +75 -0
  23. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/edit-document-find-and-replace.json +75 -0
  24. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/edit-document-initializecontent.json +75 -0
  25. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/import-content.json +75 -0
  26. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/local-files-import-content-source-existing-page.json +75 -0
  27. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/local-files-import-content-source-new-page.json +75 -0
  28. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/local-files-sync-local-folder-source-changed-file.json +75 -0
  29. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/local-files-sync-local-folder-source-new-file.json +75 -0
  30. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/restore-document-version.json +75 -0
  31. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/set-document-property-primary-blocks-field.json +75 -0
  32. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/set-image-alt-text.json +75 -0
  33. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/undo-content-import.json +75 -0
  34. package/corpus/templates/content/acceptance/golden/gate-off-stored-bytes/update-document-browser-full-rewrite.json +75 -0
  35. package/corpus/templates/content/acceptance/known-loss.ts +69 -0
  36. package/corpus/templates/content/acceptance/round-trip-corpus.ts +1397 -0
  37. package/corpus/templates/content/actions/_blocks-field-identity.ts +35 -1
  38. package/corpus/templates/content/actions/_content-database-lifecycle.ts +11 -11
  39. package/corpus/templates/content/actions/_content-database-personal-view.ts +2 -0
  40. package/corpus/templates/content/actions/_content-favorites.ts +37 -0
  41. package/corpus/templates/content/actions/_database-membership-lock.ts +39 -8
  42. package/corpus/templates/content/actions/_database-navigation.ts +19 -21
  43. package/corpus/templates/content/actions/_database-row-batch.ts +41 -18
  44. package/corpus/templates/content/actions/_database-row-mutation.ts +17 -28
  45. package/corpus/templates/content/actions/_database-source-utils.ts +18 -1
  46. package/corpus/templates/content/actions/_database-utils.ts +3 -0
  47. package/corpus/templates/content/actions/_database-view-setup.ts +321 -11
  48. package/corpus/templates/content/actions/_document-edit-mutation.ts +33 -32
  49. package/corpus/templates/content/actions/_document-flush.ts +593 -171
  50. package/corpus/templates/content/actions/_document-save-locks.ts +54 -0
  51. package/corpus/templates/content/actions/_document-save-row.ts +133 -0
  52. package/corpus/templates/content/actions/_github-source.ts +18 -8
  53. package/corpus/templates/content/actions/_move-page-to-space.ts +189 -25
  54. package/corpus/templates/content/actions/_nfm-syntax.ts +2 -0
  55. package/corpus/templates/content/actions/_property-utils.ts +3 -0
  56. package/corpus/templates/content/actions/_row-lock-order.ts +115 -0
  57. package/corpus/templates/content/actions/create-content-database.ts +11 -0
  58. package/corpus/templates/content/actions/create-document.ts +13 -1
  59. package/corpus/templates/content/actions/delete-content-database.ts +17 -14
  60. package/corpus/templates/content/actions/delete-document-property.ts +5 -0
  61. package/corpus/templates/content/actions/delete-document.ts +270 -97
  62. package/corpus/templates/content/actions/edit-document.ts +18 -5
  63. package/corpus/templates/content/actions/export-document.ts +3 -0
  64. package/corpus/templates/content/actions/get-blocks-field-word-count.ts +22 -5
  65. package/corpus/templates/content/actions/import-content-source.ts +170 -54
  66. package/corpus/templates/content/actions/move-document.ts +191 -73
  67. package/corpus/templates/content/actions/pull-document.ts +8 -2
  68. package/corpus/templates/content/actions/remove-database-items.ts +23 -4
  69. package/corpus/templates/content/actions/restore-content-database.ts +76 -55
  70. package/corpus/templates/content/actions/restore-document-version.ts +19 -35
  71. package/corpus/templates/content/actions/restore-document.ts +65 -53
  72. package/corpus/templates/content/actions/rollback-created-slash-document.ts +11 -16
  73. package/corpus/templates/content/actions/set-document-property.ts +15 -1
  74. package/corpus/templates/content/actions/share-local-file-document.ts +18 -14
  75. package/corpus/templates/content/actions/suggest-document-edit.ts +2 -3
  76. package/corpus/templates/content/actions/sync-local-folder-source.ts +35 -1
  77. package/corpus/templates/content/actions/undo-content-import.ts +16 -12
  78. package/corpus/templates/content/actions/update-content-database-view.ts +20 -2
  79. package/corpus/templates/content/actions/update-document.ts +19 -14
  80. package/corpus/templates/content/actions/view-screen.ts +12 -0
  81. package/corpus/templates/content/app/components/editor/BubbleToolbar.tsx +1 -6
  82. package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +49 -3
  83. package/corpus/templates/content/app/components/editor/ContentImportDialog.tsx +2 -0
  84. package/corpus/templates/content/app/components/editor/DocumentBlockFields.tsx +53 -11
  85. package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +608 -353
  86. package/corpus/templates/content/app/components/editor/StaticDocumentBody.tsx +765 -0
  87. package/corpus/templates/content/app/components/editor/VisualEditor.tsx +233 -80
  88. package/corpus/templates/content/app/components/editor/blockFieldSaveController.ts +32 -3
  89. package/corpus/templates/content/app/components/editor/blockFieldSaveRegistry.ts +88 -23
  90. package/corpus/templates/content/app/components/editor/comment-anchors.ts +19 -0
  91. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +296 -87
  92. package/corpus/templates/content/app/components/editor/database/ListItemLayout.tsx +410 -0
  93. package/corpus/templates/content/app/components/editor/database/ListItemRow.tsx +426 -0
  94. package/corpus/templates/content/app/components/editor/database/ListView.tsx +136 -18
  95. package/corpus/templates/content/app/components/editor/database/navigation-state.ts +3 -0
  96. package/corpus/templates/content/app/components/editor/database/settings.tsx +3 -3
  97. package/corpus/templates/content/app/components/editor/database/view-config.ts +4 -0
  98. package/corpus/templates/content/app/components/editor/document-flush-participant.ts +253 -0
  99. package/corpus/templates/content/app/components/editor/editor-transaction-meta.ts +28 -0
  100. package/corpus/templates/content/app/components/editor/extensions/AudioBlock.tsx +2 -1
  101. package/corpus/templates/content/app/components/editor/extensions/ImageBlock.tsx +27 -6
  102. package/corpus/templates/content/app/components/editor/extensions/LocalMdxComponentNode.tsx +0 -1
  103. package/corpus/templates/content/app/components/editor/extensions/NotionExtensions.tsx +4 -4
  104. package/corpus/templates/content/app/components/editor/extensions/SuggestionHighlight.ts +24 -2
  105. package/corpus/templates/content/app/components/editor/extensions/VideoBlock.tsx +25 -6
  106. package/corpus/templates/content/app/components/editor/pending-document-persistence.ts +59 -1
  107. package/corpus/templates/content/app/components/editor/stored-body-images.ts +27 -0
  108. package/corpus/templates/content/app/components/editor/suggestions/presentation-rebase.ts +17 -0
  109. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +11 -4
  110. package/corpus/templates/content/app/components/trash/TrashBrowser.tsx +4 -1
  111. package/corpus/templates/content/app/global.css +34 -0
  112. package/corpus/templates/content/app/hooks/use-content-trash.ts +8 -0
  113. package/corpus/templates/content/app/i18n-data.ts +32 -0
  114. package/corpus/templates/content/app/import-messages.ts +25 -0
  115. package/corpus/templates/content/app/trash-messages.ts +16 -0
  116. package/corpus/templates/content/changelog/2026-10-16-a-page-open-in-a-tab-that-shows-it-s-in-the-trash-reopens-wi.md +6 -0
  117. package/corpus/templates/content/changelog/2026-10-16-a-page-restored-from-trash-returns-to-its-place-in-its-colle.md +6 -0
  118. package/corpus/templates/content/changelog/2026-10-16-agent-written-markdown-keeps-nested-lists-indented-with-spac.md +6 -0
  119. package/corpus/templates/content/changelog/2026-10-16-opening-a-page-you-can-edit-no-longer-rebuilds-its-editor-on.md +6 -0
  120. package/corpus/templates/content/changelog/2026-10-16-pages-moved-or-imported-at-the-same-time-can-no-longer-end-u.md +6 -0
  121. package/corpus/templates/content/changelog/2026-10-16-re-importing-a-markdown-export-of-a-page-no-longer-reports-t.md +6 -0
  122. package/corpus/templates/content/changelog/2026-10-16-saving-a-page-or-restoring-one-of-its-versions-no-longer-fai.md +6 -0
  123. package/corpus/templates/content/changelog/2026-10-17-agents-reading-a-page-you-have-open-no-longer-wait-or-fail-w.md +6 -0
  124. package/corpus/templates/content/changelog/2026-10-19-fresh-document-reads-require-confirmation-from-every-open-ed.md +6 -0
  125. package/corpus/templates/content/changelog/2026-10-19-list-rows-can-be-customized.md +6 -0
  126. package/corpus/templates/content/changelog/2026-10-19-list-views-fit-phone-screens.md +6 -0
  127. package/corpus/templates/content/changelog/2026-10-20-html-table-cells-preserve-a-trailing-backslash-when-opening-.md +6 -0
  128. package/corpus/templates/content/changelog/2026-10-20-preserve-empty-paragraph-colors-and-refuse-unsupported-inlin.md +6 -0
  129. package/corpus/templates/content/changelog/2026-10-20-the-advanced-filter-and-each-filter-group-inside-it-have-the.md +6 -0
  130. package/corpus/templates/content/changelog/2026-10-21-blocks-fields-keep-unconfirmed-saves-visible-and-agent-reads.md +6 -0
  131. package/corpus/templates/content/changelog/2026-10-21-preserve-compact-table-row-groups-and-report-invalid-block-colors.md +6 -0
  132. package/corpus/templates/content/changelog/2026-10-21-suggested-edits-show-an-agent-s-whole-reason-open-a-group-to.md +6 -0
  133. package/corpus/templates/content/changelog/2026-10-21-suggestions-keep-refusing-unmatched-emphasis-in-stored-markd.md +6 -0
  134. package/corpus/templates/content/changelog/2026-10-22-accept-remaining-and-reject-remaining-show-the-result-for-ev.md +6 -0
  135. package/corpus/templates/content/changelog/2026-10-22-accepting-a-group-of-suggested-edits-saves-faster-and-adds-o.md +6 -0
  136. package/corpus/templates/content/changelog/2026-10-22-agents-read-saved-page-text-after-failed-icon-change.md +6 -0
  137. package/corpus/templates/content/changelog/2026-10-22-changes-made-from-a-menu-or-popover-such-as-an-image-s-alt-t.md +6 -0
  138. package/corpus/templates/content/changelog/2026-10-22-text-an-agent-writes-inside-a-callout-column-or-synced-block.md +6 -0
  139. package/corpus/templates/content/e2e/auth-files.ts +28 -0
  140. package/corpus/templates/content/e2e/convergence-summary.ts +84 -29
  141. package/corpus/templates/content/e2e/gate-arm.ts +15 -0
  142. package/corpus/templates/content/e2e/global-setup.ts +43 -75
  143. package/corpus/templates/content/e2e/global-teardown.ts +34 -0
  144. package/corpus/templates/content/e2e/helpers.ts +598 -92
  145. package/corpus/templates/content/e2e/live-body-gate.ts +188 -0
  146. package/corpus/templates/content/e2e/playwright.config.ts +12 -3
  147. package/corpus/templates/content/e2e/server-identity.ts +47 -0
  148. package/corpus/templates/content/e2e/stored-form/collab-blocks.ts +123 -0
  149. package/corpus/templates/content/package.json +1 -1
  150. package/corpus/templates/content/scripts/_stored-form-census-kinds.ts +30 -2
  151. package/corpus/templates/content/scripts/historical-icon-apply.ts +9 -1
  152. package/corpus/templates/content/scripts/trace-startup.mjs +460 -133
  153. package/corpus/templates/content/server/db/exec.ts +58 -0
  154. package/corpus/templates/content/server/db/schema.ts +1 -0
  155. package/corpus/templates/content/server/lib/content-trash-purge.ts +208 -144
  156. package/corpus/templates/content/server/lib/document-metadata-updated-at.ts +43 -1
  157. package/corpus/templates/content/server/lib/document-revision.ts +23 -0
  158. package/corpus/templates/content/server/lib/live-body-writer.ts +199 -0
  159. package/corpus/templates/content/server/lib/notion-sync.ts +63 -29
  160. package/corpus/templates/content/server/lib/notion.ts +5 -5
  161. package/corpus/templates/content/server/lib/suggested-edits.ts +357 -230
  162. package/corpus/templates/content/server/plugins/db.ts +5 -0
  163. package/corpus/templates/content/server/routes/api/documents/[id]/move.patch.ts +50 -168
  164. package/corpus/templates/content/shared/api.ts +20 -0
  165. package/corpus/templates/content/shared/blocks-fields-manifest.ts +106 -0
  166. package/corpus/templates/content/shared/database-item-layout.ts +591 -0
  167. package/corpus/templates/content/shared/database-query.ts +192 -30
  168. package/corpus/templates/content/shared/document-export.ts +12 -14
  169. package/corpus/templates/content/shared/document-flush-protocol.ts +88 -0
  170. package/corpus/templates/content/shared/editor-save-state.ts +97 -0
  171. package/corpus/templates/content/shared/feature-flags.ts +10 -0
  172. package/corpus/templates/content/shared/import/markdown.ts +91 -7
  173. package/corpus/templates/content/shared/import/types.ts +2 -0
  174. package/corpus/templates/content/shared/inline-math.ts +6 -4
  175. package/corpus/templates/content/shared/nfm-fidelity.ts +247 -0
  176. package/corpus/templates/content/shared/nfm.ts +1933 -340
  177. package/corpus/templates/content/shared/suggestion-diff.ts +13 -0
  178. package/corpus/templates/content/shared/suggestion-formatting.ts +143 -20
  179. package/corpus/templates/content/shared/suggestion-text.ts +39 -0
  180. package/corpus/templates/content/vitest.config.ts +10 -0
  181. package/corpus/templates/crm/.agents/skills/actions/references/action-fields.md +1 -1
  182. package/corpus/templates/design/.agents/skills/actions/references/action-fields.md +1 -1
  183. package/corpus/templates/design/.agents/skills/native-effects/SKILL.md +9 -2
  184. package/corpus/templates/design/.generated/bridge/shader-fill-preview.generated.ts +3 -249
  185. package/corpus/templates/design/.generated/bridge/shader-runtime.generated.ts +5 -88
  186. package/corpus/templates/design/AGENTS.md +1 -3
  187. package/corpus/templates/design/CHANGELOG.md +32 -0
  188. package/corpus/templates/design/CODE_NATIVE_DESIGN_STUDIO_IMPLEMENTATION_PLAN.md +1 -6
  189. package/corpus/templates/design/DESIGN-STUDIO-PLAN.md +5 -7
  190. package/corpus/templates/design/actions/_native-local-export-server.ts +44 -31
  191. package/corpus/templates/design/actions/_native-render-contexts.ts +76 -21
  192. package/corpus/templates/design/actions/claim-native-local-export.ts +5 -0
  193. package/corpus/templates/design/actions/finish-native-local-export.ts +13 -2
  194. package/corpus/templates/design/actions/get-native-shader-approvals.ts +35 -0
  195. package/corpus/templates/design/actions/get-shader.ts +134 -219
  196. package/corpus/templates/design/actions/list-design-extensions.ts +3 -58
  197. package/corpus/templates/design/actions/request-native-local-export.ts +32 -6
  198. package/corpus/templates/design/actions/run-design-extension-action.ts +0 -29
  199. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +131 -108
  200. package/corpus/templates/design/app/components/design/DesignExtensionsPanel.tsx +0 -218
  201. package/corpus/templates/design/app/components/design/DesignThumbnail.tsx +59 -3
  202. package/corpus/templates/design/app/components/design/EditPanel.tsx +35 -47
  203. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +242 -62
  204. package/corpus/templates/design/app/components/design/NativePreviewErrorBoundary.tsx +53 -0
  205. package/corpus/templates/design/app/components/design/bridge/codegen.ts +18 -3
  206. package/corpus/templates/design/app/components/design/bridge/native-composition-clock.ts +5 -4
  207. package/corpus/templates/design/app/components/design/bridge/native-dom.ts +37 -0
  208. package/corpus/templates/design/app/components/design/bridge/native-intrinsic-image.ts +2 -1
  209. package/corpus/templates/design/app/components/design/bridge/native-mesh-grid.ts +90 -0
  210. package/corpus/templates/design/app/components/design/bridge/native-opaque-public-asset.ts +363 -0
  211. package/corpus/templates/design/app/components/design/bridge/native-opaque-worker-lease.ts +179 -0
  212. package/corpus/templates/design/app/components/design/bridge/native-preview-geometry.ts +132 -7
  213. package/corpus/templates/design/app/components/design/bridge/native-preview-policy.ts +4 -0
  214. package/corpus/templates/design/app/components/design/bridge/native-preview-viewport-transport.ts +378 -0
  215. package/corpus/templates/design/app/components/design/bridge/native-scene-body-transform.ts +62 -0
  216. package/corpus/templates/design/app/components/design/bridge/native-scene-presentation-element.ts +10 -0
  217. package/corpus/templates/design/app/components/design/bridge/native-shader-runtime.bridge.ts +646 -167
  218. package/corpus/templates/design/app/components/design/bridge/native-source-provider.ts +246 -192
  219. package/corpus/templates/design/app/components/design/bridge/native-stateful-resource.ts +2 -2
  220. package/corpus/templates/design/app/components/design/bridge/native-stateless-compute.ts +5 -2
  221. package/corpus/templates/design/app/components/design/bridge/native-svg-source.ts +11 -1
  222. package/corpus/templates/design/app/components/design/bridge/native-worker-broker.ts +6 -0
  223. package/corpus/templates/design/app/components/design/bridge/native-worker-entry.ts +761 -303
  224. package/corpus/templates/design/app/components/design/bridge/native-worker-fill.ts +16 -6
  225. package/corpus/templates/design/app/components/design/bridge/native-worker-gpu.ts +854 -91
  226. package/corpus/templates/design/app/components/design/bridge/native-worker-host.ts +15 -1
  227. package/corpus/templates/design/app/components/design/bridge/native-worker-input-assets.ts +200 -0
  228. package/corpus/templates/design/app/components/design/bridge/native-worker-protocol.ts +40 -1
  229. package/corpus/templates/design/app/components/design/bridge/native-worker-scene-host.ts +425 -126
  230. package/corpus/templates/design/app/components/design/bridge/native-worker-source-snapshot.ts +21 -0
  231. package/corpus/templates/design/app/components/design/bridge/shader-fill-preview.bridge.ts +5 -371
  232. package/corpus/templates/design/app/components/design/bridge/shader-runtime.bridge.ts +4 -146
  233. package/corpus/templates/design/app/components/design/design-canvas/interact-document.ts +5 -9
  234. package/corpus/templates/design/app/components/design/design-canvas/native-preview-surface.ts +150 -0
  235. package/corpus/templates/design/app/components/design/design-canvas/native-public-asset-preview.ts +409 -0
  236. package/corpus/templates/design/app/components/design/design-canvas/native-public-worker-preview.ts +1086 -0
  237. package/corpus/templates/design/app/components/design/design-canvas/private-replay-screenshot-preview.ts +2 -2
  238. package/corpus/templates/design/app/components/design/edit-panel/effects-properties.tsx +15 -26
  239. package/corpus/templates/design/app/components/design/edit-panel/fill-properties.tsx +74 -67
  240. package/corpus/templates/design/app/components/design/edit-panel/panel-primitives.tsx +7 -19
  241. package/corpus/templates/design/app/components/design/inspector/DesignColorPicker.tsx +39 -30
  242. package/corpus/templates/design/app/components/design/inspector/GradientEditor.tsx +4 -0
  243. package/corpus/templates/design/app/components/design/inspector/NativeShaderColorControls.tsx +3 -7
  244. package/corpus/templates/design/app/components/design/inspector/NativeShaderPaintControls.tsx +12 -5
  245. package/corpus/templates/design/app/components/design/inspector/NativeShaderPanel.tsx +705 -190
  246. package/corpus/templates/design/app/components/design/inspector/fill-field-reading.ts +1 -2
  247. package/corpus/templates/design/app/components/design/inspector/index.ts +0 -6
  248. package/corpus/templates/design/app/components/design/inspector/native-catalog-display.ts +26 -5
  249. package/corpus/templates/design/app/components/design/inspector/native-shader-catalog-fixture.ts +42 -0
  250. package/corpus/templates/design/app/components/design/inspector/native-shader-catalog-preview.ts +51 -33
  251. package/corpus/templates/design/app/components/design/inspector/native-shader-paint.ts +1 -0
  252. package/corpus/templates/design/app/components/design/inspector/native-shader-property-draft.ts +89 -23
  253. package/corpus/templates/design/app/components/design/inspector/saved-glsl-shader.tsx +243 -0
  254. package/corpus/templates/design/app/components/design/multi-screen/board-surface-html.ts +54 -5
  255. package/corpus/templates/design/app/components/design/shader-source-coordination.ts +66 -0
  256. package/corpus/templates/design/app/components/design/use-native-shader-approvals.ts +36 -8
  257. package/corpus/templates/design/app/components/templates/TemplatePreview.tsx +60 -3
  258. package/corpus/templates/design/app/i18n/en-US.ts +78 -2
  259. package/corpus/templates/design/app/pages/Present.tsx +36 -1
  260. package/corpus/templates/design/app/pages/design-editor/commands/apply-file-content-update.ts +1 -1
  261. package/corpus/templates/design/app/pages/design-editor/commands/apply-local-content-update.ts +1 -1
  262. package/corpus/templates/design/app/pages/design-editor/commands/commit-visual-styles.ts +2 -3
  263. package/corpus/templates/design/app/pages/design-editor/commands/cross-screen-element-drop.ts +1 -1
  264. package/corpus/templates/design/app/pages/design-editor/commands/layer-move-to-screen.ts +1 -1
  265. package/corpus/templates/design/app/pages/design-editor/commands/paste-selection.ts +1 -1
  266. package/corpus/templates/design/app/pages/design-editor/commands/paste-svg-layer.ts +1 -1
  267. package/corpus/templates/design/app/pages/design-editor/commands/prepare-content-history-replay.ts +1 -1
  268. package/corpus/templates/design/app/pages/design-editor/commands/redo.ts +1 -1
  269. package/corpus/templates/design/app/pages/design-editor/commands/render-png-blob.ts +84 -41
  270. package/corpus/templates/design/app/pages/design-editor/commands/shader-source-edit.ts +1 -1
  271. package/corpus/templates/design/app/pages/design-editor/commands/undo.ts +1 -1
  272. package/corpus/templates/design/app/pages/design-editor/design-editor-view.tsx +0 -2
  273. package/corpus/templates/design/app/pages/design-editor/domains/use-editor-content-and-components.ts +4 -33
  274. package/corpus/templates/design/app/pages/design-editor/domains/use-editor-export-and-handoff.ts +2 -2
  275. package/corpus/templates/design/app/pages/design-editor/domains/use-editor-history.ts +0 -11
  276. package/corpus/templates/design/app/pages/design-editor/domains/use-editor-layer-models.ts +2 -55
  277. package/corpus/templates/design/app/pages/design-editor/domains/use-editor-screen-rendering.tsx +0 -3
  278. package/corpus/templates/design/app/pages/design-editor/domains/use-editor-selection-and-styles.ts +0 -24
  279. package/corpus/templates/design/app/pages/design-editor/text-edit-utils.ts +0 -16
  280. package/corpus/templates/design/app/pages/design-editor/use-native-local-export-requests.ts +70 -11
  281. package/corpus/templates/design/app/pages/design-editor/view/single-screen-canvas.tsx +0 -2
  282. package/corpus/templates/design/changelog/2026-10-20-folded-mesh-adds-an-animated-sculpted-fill-with-editable-col.md +6 -0
  283. package/corpus/templates/design/changelog/2026-10-20-read-only-design-views-render-native-shader-previews-in-nest.md +6 -0
  284. package/corpus/templates/design/changelog/2026-10-20-selected-screens-with-shader-effects-can-be-exported-togethe.md +6 -0
  285. package/corpus/templates/design/changelog/2026-10-20-shader-previews-reuse-validated-scene-data-while-panning-inc.md +6 -0
  286. package/corpus/templates/design/changelog/2026-10-20-shader-previews-stay-aligned-while-you-zoom.md +6 -0
  287. package/corpus/templates/design/changelog/2026-10-20-signed-out-sessions-no-longer-watch-for-private-png-export-r.md +6 -0
  288. package/corpus/templates/design/changelog/2026-10-21-effect-thumbnails-show-richer-previews.md +6 -0
  289. package/corpus/templates/design/changelog/2026-10-21-native-effects-render-across-previews.md +6 -0
  290. package/corpus/templates/design/changelog/2026-10-21-native-shader-previews-use-less-gpu-memory-when-many-mesh-ef.md +6 -0
  291. package/corpus/templates/design/changelog/2026-10-21-opening-design-no-longer-shows-png-export-errors-when-no-exp.md +6 -0
  292. package/corpus/templates/design/changelog/2026-10-21-pulsing-border-controls-grouped.md +6 -0
  293. package/corpus/templates/design/changelog/2026-10-21-pulsing-border-follows-element-outlines.md +6 -0
  294. package/corpus/templates/design/changelog/2026-10-21-remove-obsolete-shader-fills.md +6 -0
  295. package/corpus/templates/design/changelog/2026-10-21-shader-previews-recover-from-temporary-gpu-and-image-failure.md +6 -0
  296. package/corpus/templates/design/changelog/2026-10-22-shader-fills-and-effects-render-correctly-on-canvas-elements.md +6 -0
  297. package/corpus/templates/design/package.json +0 -1
  298. package/corpus/templates/design/playwright.config.ts +1 -1
  299. package/corpus/templates/design/scripts/runtime-budget-zoom.ts +9 -21
  300. package/corpus/templates/design/scripts/runtime-budget.ts +10 -24
  301. package/corpus/templates/design/server/plugins/agent-chat.ts +0 -2
  302. package/corpus/templates/design/shared/effect-graph.ts +46 -1
  303. package/corpus/templates/design/shared/generation-output-receipt.ts +0 -1
  304. package/corpus/templates/design/shared/native-effect-animation-capability.ts +6 -0
  305. package/corpus/templates/design/shared/native-effect-folded-mesh-v1.ts +268 -0
  306. package/corpus/templates/design/shared/native-effect-folded-mesh-v2.ts +310 -0
  307. package/corpus/templates/design/shared/native-effect-folded-mesh.ts +489 -0
  308. package/corpus/templates/design/shared/native-effect-gallery-additions.ts +2 -2
  309. package/corpus/templates/design/shared/native-effect-paint.ts +8 -0
  310. package/corpus/templates/design/shared/native-effect-parameter-constraints.ts +8 -1
  311. package/corpus/templates/design/shared/native-effect-presets.ts +18 -1
  312. package/corpus/templates/design/shared/native-effect-property-presentation.ts +81 -0
  313. package/corpus/templates/design/shared/native-effect-pulsing-border-v3.ts +281 -0
  314. package/corpus/templates/design/shared/native-effect-pulsing-border-v4.ts +284 -0
  315. package/corpus/templates/design/shared/native-effect-pulsing-border.ts +300 -0
  316. package/corpus/templates/design/shared/native-effect-trust.ts +6 -0
  317. package/corpus/templates/design/shared/native-effect-wgsl.ts +12 -0
  318. package/corpus/templates/design/shared/native-effects.ts +528 -15
  319. package/corpus/templates/design/shared/native-input-resources.ts +36 -0
  320. package/corpus/templates/design/shared/native-local-export.ts +14 -0
  321. package/corpus/templates/design/shared/native-parameter-animation.ts +1 -0
  322. package/corpus/templates/design/shared/native-pointer-input.ts +9 -11
  323. package/corpus/templates/design/shared/shader-fills.ts +0 -513
  324. package/corpus/templates/design/vitest.setup.ts +7 -1
  325. package/corpus/templates/dispatch/.agents/skills/actions/references/action-fields.md +1 -1
  326. package/corpus/templates/dispatch/.agents/skills/turn-into-app/SKILL.md +20 -18
  327. package/corpus/templates/factory/.agents/skills/actions/references/action-fields.md +1 -1
  328. package/corpus/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +36 -80
  329. package/corpus/templates/factory/.agents/skills/review-latest-feedback/references/channel-inventory.md +54 -16
  330. package/corpus/templates/factory/.agents/skills/review-latest-feedback/references/slack-reaction-replies.md +50 -73
  331. package/corpus/templates/factory/.agents/skills/turn-into-app/SKILL.md +20 -18
  332. package/corpus/templates/forms/.agents/skills/actions/references/action-fields.md +1 -1
  333. package/corpus/templates/mail/.agents/skills/actions/references/action-fields.md +1 -1
  334. package/corpus/templates/plan/.agents/skills/actions/references/action-fields.md +1 -1
  335. package/corpus/templates/slides/.agents/skills/actions/references/action-fields.md +1 -1
  336. package/corpus/templates/slides-2/.agents/skills/actions/SKILL.md +199 -0
  337. package/corpus/templates/slides-2/.agents/skills/actions/references/action-fields.md +145 -0
  338. package/corpus/templates/slides-2/.agents/skills/actions/references/examples.md +96 -0
  339. package/corpus/templates/slides-2/.agents/skills/actions/references/provider-apis.md +95 -0
  340. package/corpus/templates/slides-2/.agents/skills/adding-a-feature/SKILL.md +235 -0
  341. package/corpus/templates/slides-2/.agents/skills/agent-native-docs/SKILL.md +161 -0
  342. package/corpus/templates/slides-2/.agents/skills/agent-native-toolkit/SKILL.md +314 -0
  343. package/corpus/templates/slides-2/.agents/skills/analytics-data-for-decks/SKILL.md +44 -0
  344. package/corpus/templates/slides-2/.agents/skills/apply-slide-comments/SKILL.md +63 -0
  345. package/corpus/templates/slides-2/.agents/skills/client-side-routing/SKILL.md +87 -0
  346. package/corpus/templates/slides-2/.agents/skills/context-awareness/SKILL.md +282 -0
  347. package/corpus/templates/slides-2/.agents/skills/create-deck/SKILL.md +263 -0
  348. package/corpus/templates/slides-2/.agents/skills/create-deck/references/reference-inputs.md +72 -0
  349. package/corpus/templates/slides-2/.agents/skills/create-deck/references/slide-templates.md +93 -0
  350. package/corpus/templates/slides-2/.agents/skills/create-deck/references/source-material.md +16 -0
  351. package/corpus/templates/slides-2/.agents/skills/creative-context/SKILL.md +134 -0
  352. package/corpus/templates/slides-2/.agents/skills/customizing-agent-native/SKILL.md +219 -0
  353. package/corpus/templates/slides-2/.agents/skills/deck-management/SKILL.md +182 -0
  354. package/corpus/templates/slides-2/.agents/skills/delegate-to-agent/SKILL.md +62 -0
  355. package/corpus/templates/slides-2/.agents/skills/design-systems/SKILL.md +233 -0
  356. package/corpus/templates/slides-2/.agents/skills/external-agents/SKILL.md +549 -0
  357. package/corpus/templates/slides-2/.agents/skills/external-agents/references/mcp-apps-embedding.md +169 -0
  358. package/corpus/templates/slides-2/.agents/skills/frontend-design/SKILL.md +102 -0
  359. package/corpus/templates/slides-2/.agents/skills/frontend-design/references/visual-direction.md +102 -0
  360. package/corpus/templates/slides-2/.agents/skills/image-generation-via-a2a/SKILL.md +134 -0
  361. package/corpus/templates/slides-2/.agents/skills/performance/SKILL.md +79 -0
  362. package/corpus/templates/slides-2/.agents/skills/portability/SKILL.md +108 -0
  363. package/corpus/templates/slides-2/.agents/skills/real-time-sync/SKILL.md +146 -0
  364. package/corpus/templates/slides-2/.agents/skills/reliable-mutations/SKILL.md +72 -0
  365. package/corpus/templates/slides-2/.agents/skills/secrets/SKILL.md +82 -0
  366. package/corpus/templates/slides-2/.agents/skills/security/SKILL.md +80 -0
  367. package/corpus/templates/slides-2/.agents/skills/self-modifying-code/SKILL.md +123 -0
  368. package/corpus/templates/slides-2/.agents/skills/shadcn-ui/SKILL.md +71 -0
  369. package/corpus/templates/slides-2/.agents/skills/sharing/SKILL.md +286 -0
  370. package/corpus/templates/slides-2/.agents/skills/slide-design/SKILL.md +144 -0
  371. package/corpus/templates/slides-2/.agents/skills/slide-editing/SKILL.md +284 -0
  372. package/corpus/templates/slides-2/.agents/skills/slide-editing/references/animations.md +33 -0
  373. package/corpus/templates/slides-2/.agents/skills/slide-editing/references/freeform-objects.md +22 -0
  374. package/corpus/templates/slides-2/.agents/skills/slide-editing/references/restyling.md +69 -0
  375. package/corpus/templates/slides-2/.agents/skills/slide-editing/references/transitions.md +26 -0
  376. package/corpus/templates/slides-2/.agents/skills/slide-editing/references/video.md +45 -0
  377. package/corpus/templates/slides-2/.agents/skills/slide-images/SKILL.md +136 -0
  378. package/corpus/templates/slides-2/.agents/skills/storing-data/SKILL.md +234 -0
  379. package/corpus/templates/slides-2/.agents/skills/turn-into-skill/SKILL.md +112 -0
  380. package/corpus/templates/slides-2/.agents/skills/turn-into-skill/agents/openai.yaml +4 -0
  381. package/corpus/templates/slides-2/.agents/skills/workspace-conventions/SKILL.md +103 -0
  382. package/corpus/templates/slides-2/.builder/rules/deploy-app.mdc +22 -0
  383. package/corpus/templates/slides-2/.builder/rules/organize-ui.mdc +9 -0
  384. package/corpus/templates/slides-2/.dockerignore +61 -0
  385. package/corpus/templates/slides-2/.env.example +23 -0
  386. package/corpus/templates/slides-2/.ignore +3 -0
  387. package/corpus/templates/slides-2/.mcp.json +8 -0
  388. package/corpus/templates/slides-2/.oxfmtrc.json +8 -0
  389. package/corpus/templates/slides-2/AGENTS.md +66 -0
  390. package/corpus/templates/slides-2/CHANGELOG.md +76 -0
  391. package/corpus/templates/slides-2/DEVELOPING.md +157 -0
  392. package/corpus/templates/slides-2/README.md +58 -0
  393. package/corpus/templates/slides-2/THIRD_PARTY_NOTICES.md +33 -0
  394. package/corpus/templates/slides-2/_gitignore +38 -0
  395. package/corpus/templates/slides-2/actions/_agent-presence.ts +29 -0
  396. package/corpus/templates/slides-2/actions/_app-url.ts +37 -0
  397. package/corpus/templates/slides-2/actions/_deck-app-scope.ts +30 -0
  398. package/corpus/templates/slides-2/actions/_deck-tracking.ts +260 -0
  399. package/corpus/templates/slides-2/actions/_deck-write.ts +206 -0
  400. package/corpus/templates/slides-2/actions/_imported-slide-source.ts +162 -0
  401. package/corpus/templates/slides-2/actions/_inline-image-storage.ts +1013 -0
  402. package/corpus/templates/slides-2/actions/_linked-design-system.ts +83 -0
  403. package/corpus/templates/slides-2/actions/_presenter-notes.ts +83 -0
  404. package/corpus/templates/slides-2/actions/_render-artifacts.ts +111 -0
  405. package/corpus/templates/slides-2/actions/_slide-source.ts +344 -0
  406. package/corpus/templates/slides-2/actions/_tab-state.ts +51 -0
  407. package/corpus/templates/slides-2/actions/_test-brandfetch.ts +31 -0
  408. package/corpus/templates/slides-2/actions/_uploaded-files.ts +114 -0
  409. package/corpus/templates/slides-2/actions/add-deck.ts +123 -0
  410. package/corpus/templates/slides-2/actions/add-slide-comment.ts +267 -0
  411. package/corpus/templates/slides-2/actions/add-slide.ts +888 -0
  412. package/corpus/templates/slides-2/actions/analyze-brand-assets.ts +66 -0
  413. package/corpus/templates/slides-2/actions/apply-design-system.ts +111 -0
  414. package/corpus/templates/slides-2/actions/approve-deck-access-request.ts +287 -0
  415. package/corpus/templates/slides-2/actions/audit-contrast.ts +143 -0
  416. package/corpus/templates/slides-2/actions/check-image-gen.ts +17 -0
  417. package/corpus/templates/slides-2/actions/clone-context-slide.ts +340 -0
  418. package/corpus/templates/slides-2/actions/clone-creative-context-deck.ts +143 -0
  419. package/corpus/templates/slides-2/actions/control-deck-history.ts +186 -0
  420. package/corpus/templates/slides-2/actions/control-presenter.ts +117 -0
  421. package/corpus/templates/slides-2/actions/control-slide-editor.ts +267 -0
  422. package/corpus/templates/slides-2/actions/create-deck-from-template.ts +274 -0
  423. package/corpus/templates/slides-2/actions/create-deck.ts +1243 -0
  424. package/corpus/templates/slides-2/actions/create-design-system.ts +131 -0
  425. package/corpus/templates/slides-2/actions/create-share-link.ts +127 -0
  426. package/corpus/templates/slides-2/actions/db-health.ts +22 -0
  427. package/corpus/templates/slides-2/actions/delete-asset.ts +154 -0
  428. package/corpus/templates/slides-2/actions/delete-deck.ts +427 -0
  429. package/corpus/templates/slides-2/actions/delete-design-system.ts +167 -0
  430. package/corpus/templates/slides-2/actions/delete-slide-comment.ts +143 -0
  431. package/corpus/templates/slides-2/actions/delete-staged-dataset.ts +30 -0
  432. package/corpus/templates/slides-2/actions/duplicate-deck.ts +299 -0
  433. package/corpus/templates/slides-2/actions/export-google-slides.ts +41 -0
  434. package/corpus/templates/slides-2/actions/export-html.ts +770 -0
  435. package/corpus/templates/slides-2/actions/export-pptx.ts +2203 -0
  436. package/corpus/templates/slides-2/actions/extract-pdf.ts +49 -0
  437. package/corpus/templates/slides-2/actions/generate-image-api.ts +671 -0
  438. package/corpus/templates/slides-2/actions/generate-image.ts +492 -0
  439. package/corpus/templates/slides-2/actions/get-agent-access-deck.ts +52 -0
  440. package/corpus/templates/slides-2/actions/get-deck-access-status.ts +130 -0
  441. package/corpus/templates/slides-2/actions/get-deck-design-tokens.ts +62 -0
  442. package/corpus/templates/slides-2/actions/get-deck-reference-context.ts +232 -0
  443. package/corpus/templates/slides-2/actions/get-deck-template.ts +38 -0
  444. package/corpus/templates/slides-2/actions/get-deck-version.ts +85 -0
  445. package/corpus/templates/slides-2/actions/get-deck.ts +562 -0
  446. package/corpus/templates/slides-2/actions/get-design-system-decode-job-status.ts +57 -0
  447. package/corpus/templates/slides-2/actions/get-design-system-tier-limit.ts +12 -0
  448. package/corpus/templates/slides-2/actions/get-design-system.ts +453 -0
  449. package/corpus/templates/slides-2/actions/get-google-docs-status.ts +106 -0
  450. package/corpus/templates/slides-2/actions/get-google-picker-token.ts +84 -0
  451. package/corpus/templates/slides-2/actions/get-home-suggestions.ts +52 -0
  452. package/corpus/templates/slides-2/actions/get-layout-overflows.ts +192 -0
  453. package/corpus/templates/slides-2/actions/get-slide-render.ts +125 -0
  454. package/corpus/templates/slides-2/actions/get-slide-source.ts +115 -0
  455. package/corpus/templates/slides-2/actions/get-slide-theme-preview.ts +64 -0
  456. package/corpus/templates/slides-2/actions/get-slide-theme.ts +44 -0
  457. package/corpus/templates/slides-2/actions/get-slides-2-upload-storage-status.ts +17 -0
  458. package/corpus/templates/slides-2/actions/get-slides-notification-prefs.ts +37 -0
  459. package/corpus/templates/slides-2/actions/get-workspace-defaults.ts +51 -0
  460. package/corpus/templates/slides-2/actions/image-gen-status.ts +35 -0
  461. package/corpus/templates/slides-2/actions/import-code.ts +26 -0
  462. package/corpus/templates/slides-2/actions/import-design-project.ts +49 -0
  463. package/corpus/templates/slides-2/actions/import-document.ts +125 -0
  464. package/corpus/templates/slides-2/actions/import-docx.ts +57 -0
  465. package/corpus/templates/slides-2/actions/import-file.ts +1273 -0
  466. package/corpus/templates/slides-2/actions/import-from-url.ts +25 -0
  467. package/corpus/templates/slides-2/actions/import-google-doc.ts +208 -0
  468. package/corpus/templates/slides-2/actions/import-google-font.ts +110 -0
  469. package/corpus/templates/slides-2/actions/import-google-slides-reference.ts +667 -0
  470. package/corpus/templates/slides-2/actions/import-pptx.ts +564 -0
  471. package/corpus/templates/slides-2/actions/import-svgl-logo.ts +115 -0
  472. package/corpus/templates/slides-2/actions/index-design-system-with-builder.ts +181 -0
  473. package/corpus/templates/slides-2/actions/index-uploaded-design-system-files.ts +77 -0
  474. package/corpus/templates/slides-2/actions/list-assets.ts +286 -0
  475. package/corpus/templates/slides-2/actions/list-deck-templates.ts +83 -0
  476. package/corpus/templates/slides-2/actions/list-deck-versions.ts +185 -0
  477. package/corpus/templates/slides-2/actions/list-decks.ts +591 -0
  478. package/corpus/templates/slides-2/actions/list-design-systems.ts +180 -0
  479. package/corpus/templates/slides-2/actions/list-slide-comments.ts +128 -0
  480. package/corpus/templates/slides-2/actions/list-slide-themes.ts +17 -0
  481. package/corpus/templates/slides-2/actions/list-staged-datasets.ts +14 -0
  482. package/corpus/templates/slides-2/actions/logo-config.ts +13 -0
  483. package/corpus/templates/slides-2/actions/navigate.ts +158 -0
  484. package/corpus/templates/slides-2/actions/patch-deck.ts +2378 -0
  485. package/corpus/templates/slides-2/actions/provider-api-catalog.ts +25 -0
  486. package/corpus/templates/slides-2/actions/provider-api-docs.ts +83 -0
  487. package/corpus/templates/slides-2/actions/provider-api-request.ts +222 -0
  488. package/corpus/templates/slides-2/actions/query-staged-dataset.ts +83 -0
  489. package/corpus/templates/slides-2/actions/read-composer-source.ts +108 -0
  490. package/corpus/templates/slides-2/actions/request-deck-access.ts +803 -0
  491. package/corpus/templates/slides-2/actions/restore-deck-version.ts +203 -0
  492. package/corpus/templates/slides-2/actions/run.ts +2 -0
  493. package/corpus/templates/slides-2/actions/save-deck.ts +313 -0
  494. package/corpus/templates/slides-2/actions/search-google-fonts.ts +61 -0
  495. package/corpus/templates/slides-2/actions/search-images.ts +30 -0
  496. package/corpus/templates/slides-2/actions/search-logos.ts +23 -0
  497. package/corpus/templates/slides-2/actions/search-svgl-logos.ts +42 -0
  498. package/corpus/templates/slides-2/actions/set-default-design-system.ts +88 -0
  499. package/corpus/templates/slides-2/actions/set-workspace-defaults.ts +61 -0
  500. package/corpus/templates/slides-2/actions/start-design-system-upload.ts +80 -0
  501. package/corpus/templates/slides-2/actions/sync-design-system-with-builder.ts +84 -0
  502. package/corpus/templates/slides-2/actions/toggle-slide-comment-reaction.ts +150 -0
  503. package/corpus/templates/slides-2/actions/transform-slide-objects.ts +1528 -0
  504. package/corpus/templates/slides-2/actions/update-asset.ts +499 -0
  505. package/corpus/templates/slides-2/actions/update-deck-aspect-ratio.ts +95 -0
  506. package/corpus/templates/slides-2/actions/update-deck-design-tokens.ts +175 -0
  507. package/corpus/templates/slides-2/actions/update-design-system.ts +95 -0
  508. package/corpus/templates/slides-2/actions/update-slide-comment.ts +213 -0
  509. package/corpus/templates/slides-2/actions/update-slide-source.ts +353 -0
  510. package/corpus/templates/slides-2/actions/update-slide.ts +850 -0
  511. package/corpus/templates/slides-2/actions/update-slides-notification-prefs.ts +55 -0
  512. package/corpus/templates/slides-2/actions/view-screen.ts +1098 -0
  513. package/corpus/templates/slides-2/agent-native.app-skill.json +165 -0
  514. package/corpus/templates/slides-2/agent-native.config.ts +20 -0
  515. package/corpus/templates/slides-2/agent-native.json +18 -0
  516. package/corpus/templates/slides-2/app/components/ThemeToggle.tsx +47 -0
  517. package/corpus/templates/slides-2/app/components/comments/SlideCommentPins.tsx +781 -0
  518. package/corpus/templates/slides-2/app/components/comments/SlideCommentsPanel.tsx +1075 -0
  519. package/corpus/templates/slides-2/app/components/deck/DeckCard.tsx +304 -0
  520. package/corpus/templates/slides-2/app/components/deck/DeckFilterMenu.tsx +83 -0
  521. package/corpus/templates/slides-2/app/components/deck/ExcalidrawSlide.tsx +183 -0
  522. package/corpus/templates/slides-2/app/components/deck/MermaidRenderer.tsx +126 -0
  523. package/corpus/templates/slides-2/app/components/deck/SlideRenderer.tsx +1553 -0
  524. package/corpus/templates/slides-2/app/components/design-system/DesignSystemCard.tsx +235 -0
  525. package/corpus/templates/slides-2/app/components/design-system/DesignSystemSetup.tsx +2021 -0
  526. package/corpus/templates/slides-2/app/components/design-system/builder-design-system-upload.ts +200 -0
  527. package/corpus/templates/slides-2/app/components/design-system/builder-index-response.ts +104 -0
  528. package/corpus/templates/slides-2/app/components/editor/AddSlidePopover.tsx +461 -0
  529. package/corpus/templates/slides-2/app/components/editor/AiEditingMarker.tsx +24 -0
  530. package/corpus/templates/slides-2/app/components/editor/AlignmentGuides.tsx +82 -0
  531. package/corpus/templates/slides-2/app/components/editor/AnimationsPanel.tsx +698 -0
  532. package/corpus/templates/slides-2/app/components/editor/AppMenu.tsx +356 -0
  533. package/corpus/templates/slides-2/app/components/editor/AssetLibraryPanel.tsx +508 -0
  534. package/corpus/templates/slides-2/app/components/editor/BlockBubbleMenu.tsx +548 -0
  535. package/corpus/templates/slides-2/app/components/editor/DeckAccessDeniedPage.tsx +173 -0
  536. package/corpus/templates/slides-2/app/components/editor/DeckEditorSkeleton.tsx +35 -0
  537. package/corpus/templates/slides-2/app/components/editor/DeferredPopoverFallback.tsx +148 -0
  538. package/corpus/templates/slides-2/app/components/editor/EditorActionCluster.tsx +217 -0
  539. package/corpus/templates/slides-2/app/components/editor/EditorSidebar.tsx +1047 -0
  540. package/corpus/templates/slides-2/app/components/editor/EditorToolbar.tsx +1285 -0
  541. package/corpus/templates/slides-2/app/components/editor/ExportMenu.tsx +579 -0
  542. package/corpus/templates/slides-2/app/components/editor/GeneratingOverlay.tsx +21 -0
  543. package/corpus/templates/slides-2/app/components/editor/GeneratingSlidePreview.tsx +73 -0
  544. package/corpus/templates/slides-2/app/components/editor/GoogleDocImportHint.tsx +378 -0
  545. package/corpus/templates/slides-2/app/components/editor/GoogleDriveConnectionCta.tsx +154 -0
  546. package/corpus/templates/slides-2/app/components/editor/GoogleSlidesReferenceImport.tsx +299 -0
  547. package/corpus/templates/slides-2/app/components/editor/HistoryPanel.tsx +354 -0
  548. package/corpus/templates/slides-2/app/components/editor/HomeQuickStartDialog.tsx +202 -0
  549. package/corpus/templates/slides-2/app/components/editor/ImageCropOverlay.tsx +820 -0
  550. package/corpus/templates/slides-2/app/components/editor/ImageDropPromptPopover.tsx +280 -0
  551. package/corpus/templates/slides-2/app/components/editor/ImageGenPanel.tsx +244 -0
  552. package/corpus/templates/slides-2/app/components/editor/ImageOverlay.tsx +280 -0
  553. package/corpus/templates/slides-2/app/components/editor/ImageSearchPanel.tsx +183 -0
  554. package/corpus/templates/slides-2/app/components/editor/ImportDeckButton.tsx +247 -0
  555. package/corpus/templates/slides-2/app/components/editor/LogoSearchPanel.tsx +366 -0
  556. package/corpus/templates/slides-2/app/components/editor/MermaidToExcalidrawPanel.tsx +99 -0
  557. package/corpus/templates/slides-2/app/components/editor/MissingDeckAccessPane.tsx +219 -0
  558. package/corpus/templates/slides-2/app/components/editor/NewDeckReferenceStep.tsx +812 -0
  559. package/corpus/templates/slides-2/app/components/editor/PromptDialog.tsx +963 -0
  560. package/corpus/templates/slides-2/app/components/editor/QuestionFlow.tsx +119 -0
  561. package/corpus/templates/slides-2/app/components/editor/RequestDeckAccessDialog.tsx +101 -0
  562. package/corpus/templates/slides-2/app/components/editor/ShareDialog.tsx +126 -0
  563. package/corpus/templates/slides-2/app/components/editor/SlideContextToolbar.tsx +1471 -0
  564. package/corpus/templates/slides-2/app/components/editor/SlideEditor.tsx +11183 -0
  565. package/corpus/templates/slides-2/app/components/editor/SlideOverflowWarning.tsx +82 -0
  566. package/corpus/templates/slides-2/app/components/editor/SlideScrollStack.tsx +307 -0
  567. package/corpus/templates/slides-2/app/components/editor/SlideSlashCommandMenu.tsx +692 -0
  568. package/corpus/templates/slides-2/app/components/editor/SlideThumbnailContextMenu.tsx +52 -0
  569. package/corpus/templates/slides-2/app/components/editor/SlideTransitionControl.tsx +184 -0
  570. package/corpus/templates/slides-2/app/components/editor/SlidesComposerContext.tsx +789 -0
  571. package/corpus/templates/slides-2/app/components/editor/SlidesComposerContextProvider.tsx +74 -0
  572. package/corpus/templates/slides-2/app/components/editor/SlidesLayersPanel.tsx +377 -0
  573. package/corpus/templates/slides-2/app/components/editor/SpeakerNotesPanel.tsx +119 -0
  574. package/corpus/templates/slides-2/app/components/editor/TweaksPanel.tsx +77 -0
  575. package/corpus/templates/slides-2/app/components/editor/UploadStorageGate.tsx +37 -0
  576. package/corpus/templates/slides-2/app/components/editor/bullet-editing.ts +880 -0
  577. package/corpus/templates/slides-2/app/components/editor/canvas-interactions/index.ts +12 -0
  578. package/corpus/templates/slides-2/app/components/editor/canvas-interactions/slides-canvas-adapter.ts +119 -0
  579. package/corpus/templates/slides-2/app/components/editor/commit-active-edit.ts +14 -0
  580. package/corpus/templates/slides-2/app/components/editor/editor-command-model.ts +35 -0
  581. package/corpus/templates/slides-2/app/components/editor/fit-text-object.ts +31 -0
  582. package/corpus/templates/slides-2/app/components/editor/in-place-text-session.browser-cases.json +983 -0
  583. package/corpus/templates/slides-2/app/components/editor/in-place-text-session.browser-host.ts +747 -0
  584. package/corpus/templates/slides-2/app/components/editor/in-place-text-session.ts +6891 -0
  585. package/corpus/templates/slides-2/app/components/editor/inline-edit-session.ts +26 -0
  586. package/corpus/templates/slides-2/app/components/editor/list-editing.ts +501 -0
  587. package/corpus/templates/slides-2/app/components/editor/rich-text-selection.ts +975 -0
  588. package/corpus/templates/slides-2/app/components/editor/rte-test-utils.ts +265 -0
  589. package/corpus/templates/slides-2/app/components/editor/selection-overlay-measurement.ts +191 -0
  590. package/corpus/templates/slides-2/app/components/editor/slide-escape-arbiter.ts +34 -0
  591. package/corpus/templates/slides-2/app/components/editor/slide-object-interactions.ts +6362 -0
  592. package/corpus/templates/slides-2/app/components/editor/slide-object-transform.browser-host.ts +19 -0
  593. package/corpus/templates/slides-2/app/components/editor/slide-pointer-target.ts +432 -0
  594. package/corpus/templates/slides-2/app/components/editor/slide-presence.ts +13 -0
  595. package/corpus/templates/slides-2/app/components/editor/slide-style.ts +243 -0
  596. package/corpus/templates/slides-2/app/components/editor/slide-text-targets.ts +540 -0
  597. package/corpus/templates/slides-2/app/components/editor/style-clipboard.ts +102 -0
  598. package/corpus/templates/slides-2/app/components/editor/use-prompt-import.ts +159 -0
  599. package/corpus/templates/slides-2/app/components/home/SlidesHomeLibrary.tsx +79 -0
  600. package/corpus/templates/slides-2/app/components/layout/AgentWorkIndicator.tsx +193 -0
  601. package/corpus/templates/slides-2/app/components/layout/Header.tsx +110 -0
  602. package/corpus/templates/slides-2/app/components/layout/Layout.tsx +492 -0
  603. package/corpus/templates/slides-2/app/components/layout/Sidebar.tsx +109 -0
  604. package/corpus/templates/slides-2/app/components/layout/layout-route-policy.ts +28 -0
  605. package/corpus/templates/slides-2/app/components/presentation/PresentationView.tsx +1116 -0
  606. package/corpus/templates/slides-2/app/components/presentation/PresenterView.tsx +526 -0
  607. package/corpus/templates/slides-2/app/components/presentation/SlideTransitionStage.tsx +297 -0
  608. package/corpus/templates/slides-2/app/components/presentation/present-channel.ts +31 -0
  609. package/corpus/templates/slides-2/app/components/presentation/slide-build-steps.ts +231 -0
  610. package/corpus/templates/slides-2/app/components/presentation/slide-navigation.ts +273 -0
  611. package/corpus/templates/slides-2/app/components/presentation/slide-transition-motion.ts +258 -0
  612. package/corpus/templates/slides-2/app/components/presentation/voice-navigation.ts +61 -0
  613. package/corpus/templates/slides-2/app/components/settings/notification-settings.tsx +93 -0
  614. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2AssetBrowser.tsx +726 -0
  615. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2CommandMenu.tsx +453 -0
  616. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2Comments.tsx +571 -0
  617. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2DesignTokens.tsx +345 -0
  618. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2Editor.tsx +4804 -0
  619. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2ExportMenu.tsx +671 -0
  620. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2FontBrowser.tsx +342 -0
  621. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2ImageCropControls.tsx +487 -0
  622. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2Inspector.tsx +950 -0
  623. package/corpus/templates/slides-2/app/components/slides-2-editor/Slides2SvglLogoSearchDialog.tsx +332 -0
  624. package/corpus/templates/slides-2/app/components/slides-2-editor/cross-slide-edit-history.ts +151 -0
  625. package/corpus/templates/slides-2/app/components/slides-2-editor/design-token-presets.ts +140 -0
  626. package/corpus/templates/slides-2/app/components/slides-2-editor/editor-action-errors.ts +47 -0
  627. package/corpus/templates/slides-2/app/components/slides-2-editor/editor-export-errors.ts +60 -0
  628. package/corpus/templates/slides-2/app/components/slides-2-editor/geometry.ts +275 -0
  629. package/corpus/templates/slides-2/app/components/slides-2-editor/image-crop-style.ts +82 -0
  630. package/corpus/templates/slides-2/app/components/slides-2-editor/inline-text-editor.tsx +631 -0
  631. package/corpus/templates/slides-2/app/components/slides-2-editor/keyboard-shortcuts.ts +104 -0
  632. package/corpus/templates/slides-2/app/components/slides-2-editor/object-insertion.ts +13 -0
  633. package/corpus/templates/slides-2/app/components/slides-2-editor/preview-patches.ts +54 -0
  634. package/corpus/templates/slides-2/app/components/slides-2-editor/sandbox-render-errors.ts +23 -0
  635. package/corpus/templates/slides-2/app/components/slides-2-editor/source-structure.ts +634 -0
  636. package/corpus/templates/slides-2/app/components/slides-2-editor/types.ts +85 -0
  637. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2BlackoutOverlay.tsx +13 -0
  638. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2ControlBar.tsx +285 -0
  639. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2HelpDialog.tsx +72 -0
  640. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2JumpInput.tsx +38 -0
  641. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2LaserPointer.tsx +67 -0
  642. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2Overview.tsx +161 -0
  643. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2Player.tsx +839 -0
  644. package/corpus/templates/slides-2/app/components/slides-2-presenter/Slides2ProgressBar.tsx +23 -0
  645. package/corpus/templates/slides-2/app/components/slides-2-presenter/keyboard.ts +36 -0
  646. package/corpus/templates/slides-2/app/components/slides-2-presenter/presenter-channel.ts +131 -0
  647. package/corpus/templates/slides-2/app/components/slides-2-presenter/use-presenter-action-bridge.ts +296 -0
  648. package/corpus/templates/slides-2/app/components/slides-2-presenter/useSlides2TouchSwipe.ts +80 -0
  649. package/corpus/templates/slides-2/app/components/slides-2-runtime/SandboxedSlide.tsx +724 -0
  650. package/corpus/templates/slides-2/app/components/slides-2-runtime/SlideContentRenderer.tsx +137 -0
  651. package/corpus/templates/slides-2/app/components/slides-2-runtime/Slides2Canvas.tsx +99 -0
  652. package/corpus/templates/slides-2/app/components/slides-2-runtime/constants.ts +4 -0
  653. package/corpus/templates/slides-2/app/components/slides-2-runtime/protocol.ts +1400 -0
  654. package/corpus/templates/slides-2/app/components/slides-2-runtime/transition-frame.ts +439 -0
  655. package/corpus/templates/slides-2/app/components/templates/DeckTemplateLibrary.tsx +314 -0
  656. package/corpus/templates/slides-2/app/components/templates/DeckTemplatePreview.tsx +60 -0
  657. package/corpus/templates/slides-2/app/components/templates/DeckTemplateStage.tsx +45 -0
  658. package/corpus/templates/slides-2/app/components/ui/alert-dialog.tsx +1 -0
  659. package/corpus/templates/slides-2/app/components/ui/avatar.tsx +1 -0
  660. package/corpus/templates/slides-2/app/components/ui/button-group.tsx +1 -0
  661. package/corpus/templates/slides-2/app/components/ui/button.tsx +1 -0
  662. package/corpus/templates/slides-2/app/components/ui/card.tsx +1 -0
  663. package/corpus/templates/slides-2/app/components/ui/command.tsx +1 -0
  664. package/corpus/templates/slides-2/app/components/ui/context-menu.tsx +32 -0
  665. package/corpus/templates/slides-2/app/components/ui/dialog.tsx +1 -0
  666. package/corpus/templates/slides-2/app/components/ui/dropdown-menu.tsx +1 -0
  667. package/corpus/templates/slides-2/app/components/ui/filter-trigger.tsx +1 -0
  668. package/corpus/templates/slides-2/app/components/ui/input.tsx +1 -0
  669. package/corpus/templates/slides-2/app/components/ui/label.tsx +1 -0
  670. package/corpus/templates/slides-2/app/components/ui/popover.tsx +1 -0
  671. package/corpus/templates/slides-2/app/components/ui/progress.tsx +1 -0
  672. package/corpus/templates/slides-2/app/components/ui/scroll-area.tsx +1 -0
  673. package/corpus/templates/slides-2/app/components/ui/select.tsx +1 -0
  674. package/corpus/templates/slides-2/app/components/ui/separator.tsx +1 -0
  675. package/corpus/templates/slides-2/app/components/ui/sheet.tsx +1 -0
  676. package/corpus/templates/slides-2/app/components/ui/skeleton.tsx +1 -0
  677. package/corpus/templates/slides-2/app/components/ui/slider.tsx +1 -0
  678. package/corpus/templates/slides-2/app/components/ui/spinner.tsx +1 -0
  679. package/corpus/templates/slides-2/app/components/ui/switch.tsx +1 -0
  680. package/corpus/templates/slides-2/app/components/ui/tabs.tsx +59 -0
  681. package/corpus/templates/slides-2/app/components/ui/textarea.tsx +1 -0
  682. package/corpus/templates/slides-2/app/components/ui/toggle-group.tsx +1 -0
  683. package/corpus/templates/slides-2/app/components/ui/toolkit-provider.tsx +17 -0
  684. package/corpus/templates/slides-2/app/components/ui/tooltip.tsx +1 -0
  685. package/corpus/templates/slides-2/app/components/visual-editor/CanvasCommentPins.tsx +46 -0
  686. package/corpus/templates/slides-2/app/components/visual-editor/DrawOverlay.tsx +27 -0
  687. package/corpus/templates/slides-2/app/components/visual-editor/MultiSelectChip.tsx +97 -0
  688. package/corpus/templates/slides-2/app/components/visual-editor/SaveStatusIndicator.tsx +273 -0
  689. package/corpus/templates/slides-2/app/components/visual-editor/index.ts +4 -0
  690. package/corpus/templates/slides-2/app/context/DeckContext.tsx +7486 -0
  691. package/corpus/templates/slides-2/app/design-system.ts +3 -0
  692. package/corpus/templates/slides-2/app/entry.client.tsx +10 -0
  693. package/corpus/templates/slides-2/app/entry.server.tsx +10 -0
  694. package/corpus/templates/slides-2/app/global.css +1626 -0
  695. package/corpus/templates/slides-2/app/hooks/use-agent-generating.ts +517 -0
  696. package/corpus/templates/slides-2/app/hooks/use-compact-editor-layout.ts +26 -0
  697. package/corpus/templates/slides-2/app/hooks/use-contrast-audit-bridge.ts +49 -0
  698. package/corpus/templates/slides-2/app/hooks/use-deck-access-reload.ts +70 -0
  699. package/corpus/templates/slides-2/app/hooks/use-deck-access.ts +50 -0
  700. package/corpus/templates/slides-2/app/hooks/use-deck-design-system.ts +146 -0
  701. package/corpus/templates/slides-2/app/hooks/use-deck-history-action-bridge.ts +266 -0
  702. package/corpus/templates/slides-2/app/hooks/use-deck-presence.ts +89 -0
  703. package/corpus/templates/slides-2/app/hooks/use-deck-role.ts +46 -0
  704. package/corpus/templates/slides-2/app/hooks/use-deck-versions.ts +43 -0
  705. package/corpus/templates/slides-2/app/hooks/use-design-system-workflows.ts +11 -0
  706. package/corpus/templates/slides-2/app/hooks/use-design-systems.ts +31 -0
  707. package/corpus/templates/slides-2/app/hooks/use-generating-slide-preview.ts +115 -0
  708. package/corpus/templates/slides-2/app/hooks/use-navigation-state.ts +229 -0
  709. package/corpus/templates/slides-2/app/hooks/use-new-deck-generation-signal.ts +46 -0
  710. package/corpus/templates/slides-2/app/hooks/use-new-deck-generation.ts +710 -0
  711. package/corpus/templates/slides-2/app/hooks/use-sidebar-collapsed.ts +95 -0
  712. package/corpus/templates/slides-2/app/hooks/use-slide-comments.ts +202 -0
  713. package/corpus/templates/slides-2/app/hooks/use-slide-file-storage-status.ts +55 -0
  714. package/corpus/templates/slides-2/app/hooks/use-undo-selection.ts +66 -0
  715. package/corpus/templates/slides-2/app/hooks/use-workspace-defaults.ts +31 -0
  716. package/corpus/templates/slides-2/app/i18n/en-US.ts +1507 -0
  717. package/corpus/templates/slides-2/app/i18n/index.ts +19 -0
  718. package/corpus/templates/slides-2/app/lib/agent-visible-message.ts +21 -0
  719. package/corpus/templates/slides-2/app/lib/aspect-ratios.ts +7 -0
  720. package/corpus/templates/slides-2/app/lib/asset-error-copy.ts +59 -0
  721. package/corpus/templates/slides-2/app/lib/canvas-zoom.ts +47 -0
  722. package/corpus/templates/slides-2/app/lib/composer-context.ts +152 -0
  723. package/corpus/templates/slides-2/app/lib/composer-draft.ts +34 -0
  724. package/corpus/templates/slides-2/app/lib/contrast-audit.ts +390 -0
  725. package/corpus/templates/slides-2/app/lib/contrast-resolve.ts +240 -0
  726. package/corpus/templates/slides-2/app/lib/create-deck-generation.ts +938 -0
  727. package/corpus/templates/slides-2/app/lib/deck-access-lost.ts +4 -0
  728. package/corpus/templates/slides-2/app/lib/deck-backup.ts +186 -0
  729. package/corpus/templates/slides-2/app/lib/deck-editor-loading.ts +91 -0
  730. package/corpus/templates/slides-2/app/lib/deck-export-file-client.ts +77 -0
  731. package/corpus/templates/slides-2/app/lib/deck-filter.ts +52 -0
  732. package/corpus/templates/slides-2/app/lib/deck-list-loading.ts +16 -0
  733. package/corpus/templates/slides-2/app/lib/deck-preview-frame.ts +15 -0
  734. package/corpus/templates/slides-2/app/lib/deck-share-links.ts +9 -0
  735. package/corpus/templates/slides-2/app/lib/deck-sorting.ts +19 -0
  736. package/corpus/templates/slides-2/app/lib/deferred-editor-surfaces.ts +24 -0
  737. package/corpus/templates/slides-2/app/lib/design-system-selection.ts +11 -0
  738. package/corpus/templates/slides-2/app/lib/design-systems.ts +231 -0
  739. package/corpus/templates/slides-2/app/lib/dynamic-import.ts +50 -0
  740. package/corpus/templates/slides-2/app/lib/editor-agent-handoff.ts +92 -0
  741. package/corpus/templates/slides-2/app/lib/editor-shortcuts.ts +153 -0
  742. package/corpus/templates/slides-2/app/lib/export-google-slides-client.ts +168 -0
  743. package/corpus/templates/slides-2/app/lib/export-pdf-client.ts +684 -0
  744. package/corpus/templates/slides-2/app/lib/export-pptx-client.ts +2420 -0
  745. package/corpus/templates/slides-2/app/lib/generation-lifecycle.ts +24 -0
  746. package/corpus/templates/slides-2/app/lib/generation-state.ts +247 -0
  747. package/corpus/templates/slides-2/app/lib/google-docs-client.ts +110 -0
  748. package/corpus/templates/slides-2/app/lib/google-slides-export-availability-client.ts +53 -0
  749. package/corpus/templates/slides-2/app/lib/google-slides-reference-source.ts +18 -0
  750. package/corpus/templates/slides-2/app/lib/image-download.ts +85 -0
  751. package/corpus/templates/slides-2/app/lib/image-drop-to-agent.ts +210 -0
  752. package/corpus/templates/slides-2/app/lib/import-uploaded-deck.ts +132 -0
  753. package/corpus/templates/slides-2/app/lib/inline-edit-remote.ts +55 -0
  754. package/corpus/templates/slides-2/app/lib/localize-slides-changelog.ts +47 -0
  755. package/corpus/templates/slides-2/app/lib/mermaid-blocks.ts +18 -0
  756. package/corpus/templates/slides-2/app/lib/new-deck-reference-selection.ts +174 -0
  757. package/corpus/templates/slides-2/app/lib/normalize-slide-padding.ts +74 -0
  758. package/corpus/templates/slides-2/app/lib/pending-deck-changes.ts +33 -0
  759. package/corpus/templates/slides-2/app/lib/portaled-layer.ts +7 -0
  760. package/corpus/templates/slides-2/app/lib/pptx-google-slides.ts +204 -0
  761. package/corpus/templates/slides-2/app/lib/prompt-attachment-adapter.ts +37 -0
  762. package/corpus/templates/slides-2/app/lib/prompt-file-uploads.ts +557 -0
  763. package/corpus/templates/slides-2/app/lib/recent-references.ts +106 -0
  764. package/corpus/templates/slides-2/app/lib/reference-document-hydration.ts +406 -0
  765. package/corpus/templates/slides-2/app/lib/register-chat-renderers.tsx +645 -0
  766. package/corpus/templates/slides-2/app/lib/reveal-after-delete.ts +55 -0
  767. package/corpus/templates/slides-2/app/lib/sanitize-slide-html.ts +752 -0
  768. package/corpus/templates/slides-2/app/lib/slide-agent-context.ts +148 -0
  769. package/corpus/templates/slides-2/app/lib/slide-animation-elements.ts +900 -0
  770. package/corpus/templates/slides-2/app/lib/slide-clipboard.ts +534 -0
  771. package/corpus/templates/slides-2/app/lib/slide-comment-anchor.ts +286 -0
  772. package/corpus/templates/slides-2/app/lib/slide-content-merge.ts +295 -0
  773. package/corpus/templates/slides-2/app/lib/slide-image-replacement.ts +1919 -0
  774. package/corpus/templates/slides-2/app/lib/slide-live-remote.ts +215 -0
  775. package/corpus/templates/slides-2/app/lib/slide-scroll.ts +56 -0
  776. package/corpus/templates/slides-2/app/lib/slide-source-map.ts +1099 -0
  777. package/corpus/templates/slides-2/app/lib/slide-video.ts +390 -0
  778. package/corpus/templates/slides-2/app/lib/slides-relay-tracking.ts +114 -0
  779. package/corpus/templates/slides-2/app/lib/streaming-slide-html.ts +77 -0
  780. package/corpus/templates/slides-2/app/lib/tab-id.ts +3 -0
  781. package/corpus/templates/slides-2/app/lib/template-navigation.ts +15 -0
  782. package/corpus/templates/slides-2/app/lib/text-tool-shortcut.ts +75 -0
  783. package/corpus/templates/slides-2/app/lib/undo-reveal.ts +332 -0
  784. package/corpus/templates/slides-2/app/lib/upload-response.ts +107 -0
  785. package/corpus/templates/slides-2/app/lib/utils.ts +38 -0
  786. package/corpus/templates/slides-2/app/lib/validate-native-slide-html.ts +177 -0
  787. package/corpus/templates/slides-2/app/lib/video-upload.ts +354 -0
  788. package/corpus/templates/slides-2/app/pages/DeckEditor.tsx +6158 -0
  789. package/corpus/templates/slides-2/app/pages/DesignSystems.tsx +363 -0
  790. package/corpus/templates/slides-2/app/pages/Index.tsx +3254 -0
  791. package/corpus/templates/slides-2/app/pages/NotFound.tsx +33 -0
  792. package/corpus/templates/slides-2/app/pages/Presentation.tsx +120 -0
  793. package/corpus/templates/slides-2/app/pages/SharedPresentation.tsx +174 -0
  794. package/corpus/templates/slides-2/app/pages/SlideThemeDetail.tsx +227 -0
  795. package/corpus/templates/slides-2/app/pages/SlideThemes.tsx +155 -0
  796. package/corpus/templates/slides-2/app/pages/Slides2EditorPage.tsx +1618 -0
  797. package/corpus/templates/slides-2/app/pages/Slides2PresenterConsolePage.tsx +937 -0
  798. package/corpus/templates/slides-2/app/pages/Slides2PresenterPage.tsx +979 -0
  799. package/corpus/templates/slides-2/app/pages/Templates.tsx +32 -0
  800. package/corpus/templates/slides-2/app/root.tsx +391 -0
  801. package/corpus/templates/slides-2/app/routes/$.tsx +10 -0
  802. package/corpus/templates/slides-2/app/routes/_index.tsx +1 -0
  803. package/corpus/templates/slides-2/app/routes/access-request.approve.tsx +276 -0
  804. package/corpus/templates/slides-2/app/routes/agent.tsx +19 -0
  805. package/corpus/templates/slides-2/app/routes/chat.$threadId.tsx +1 -0
  806. package/corpus/templates/slides-2/app/routes/chat.tsx +190 -0
  807. package/corpus/templates/slides-2/app/routes/deck.$id.tsx +10 -0
  808. package/corpus/templates/slides-2/app/routes/deck.$id_.present.tsx +10 -0
  809. package/corpus/templates/slides-2/app/routes/design-systems.tsx +10 -0
  810. package/corpus/templates/slides-2/app/routes/extensions.$id.$slug.tsx +2 -0
  811. package/corpus/templates/slides-2/app/routes/extensions.$id.tsx +5 -0
  812. package/corpus/templates/slides-2/app/routes/extensions._index.tsx +5 -0
  813. package/corpus/templates/slides-2/app/routes/extensions.tsx +5 -0
  814. package/corpus/templates/slides-2/app/routes/home-layout.tsx +31 -0
  815. package/corpus/templates/slides-2/app/routes/home.tsx +22 -0
  816. package/corpus/templates/slides-2/app/routes/p.$id.tsx +195 -0
  817. package/corpus/templates/slides-2/app/routes/settings.$.tsx +1 -0
  818. package/corpus/templates/slides-2/app/routes/settings.tsx +131 -0
  819. package/corpus/templates/slides-2/app/routes/share.$token.tsx +137 -0
  820. package/corpus/templates/slides-2/app/routes/slide.tsx +209 -0
  821. package/corpus/templates/slides-2/app/routes/team.tsx +11 -0
  822. package/corpus/templates/slides-2/app/routes/templates.tsx +1 -0
  823. package/corpus/templates/slides-2/app/routes/themes.$id.tsx +1 -0
  824. package/corpus/templates/slides-2/app/routes/themes.tsx +1 -0
  825. package/corpus/templates/slides-2/app/routes.ts +24 -0
  826. package/corpus/templates/slides-2/app/vite-env.d.ts +24 -0
  827. package/corpus/templates/slides-2/changelog/2026-10-17-find-and-switch-decks-from-the-presenter-console.md +6 -0
  828. package/corpus/templates/slides-2/changelog/2026-10-17-meet-slides-2-create-and-refine-editable-slide-decks-with-an.md +6 -0
  829. package/corpus/templates/slides-2/changelog/2026-10-17-pptx-image-export.md +6 -0
  830. package/corpus/templates/slides-2/changelog/2026-10-17-visual-editor.md +6 -0
  831. package/corpus/templates/slides-2/changelog/2026-10-18-apply-an-accessible-design-system-to-an-existing-deck-before.md +6 -0
  832. package/corpus/templates/slides-2/changelog/2026-10-18-choose-a-template-or-start-a-new-presentation-from-the-slide.md +6 -0
  833. package/corpus/templates/slides-2/changelog/2026-10-18-generate-decks-from-a-prompt-then-edit-slide-elements-direct.md +6 -0
  834. package/corpus/templates/slides-2/changelog/2026-10-18-generate-presentation-decks-from-a-prompt-and-edit-every-sli.md +6 -0
  835. package/corpus/templates/slides-2/changelog/2026-10-18-new-presentation-drafts-save-before-generation-starts-so-you.md +6 -0
  836. package/corpus/templates/slides-2/changelog/2026-10-18-the-assistant-can-undo-redo-and-save-pending-edits-in-the-vi.md +6 -0
  837. package/corpus/templates/slides-2/changelog/2026-10-19-agents-can-insert-duplicate-and-delete-canvas-objects-in-sou.md +6 -0
  838. package/corpus/templates/slides-2/changelog/2026-10-19-browse-slide-themes.md +6 -0
  839. package/corpus/templates/slides-2/changelog/2026-10-19-clicking-a-slide-preview-in-overview-selects-that-slide.md +6 -0
  840. package/corpus/templates/slides-2/changelog/2026-10-19-create-decks-from-a-prompt-and-edit-slides-directly-on-the-c.md +6 -0
  841. package/corpus/templates/slides-2/changelog/2026-10-19-creating-and-editing-decks-now-starts-with-the-tools-most-re.md +6 -0
  842. package/corpus/templates/slides-2/changelog/2026-10-19-deleting-decks-revokes-public-links.md +7 -0
  843. package/corpus/templates/slides-2/changelog/2026-10-19-escape-cancels-an-in-progress-slide-drag-without-losing-earl.md +6 -0
  844. package/corpus/templates/slides-2/changelog/2026-10-19-import-failures-now-show-clear-localized-descriptions-instea.md +6 -0
  845. package/corpus/templates/slides-2/changelog/2026-10-19-presenter-controls-stay-responsive-when-moving-over-the-slid.md +6 -0
  846. package/corpus/templates/slides-2/changelog/2026-10-19-presenter-notes-stay-private-from-viewers-and-commenters.md +6 -0
  847. package/corpus/templates/slides-2/changelog/2026-10-19-preview-generated-slides-in-chat.md +6 -0
  848. package/corpus/templates/slides-2/changelog/2026-10-19-remote-image-previews-accept-supported-raster-formats.md +6 -0
  849. package/corpus/templates/slides-2/changelog/2026-10-19-search-the-svgl-catalog-and-add-svg-logos-to-a-deck-or-the-g.md +6 -0
  850. package/corpus/templates/slides-2/changelog/2026-10-19-slide-generation-explains-when-react-effect-hooks-cannot-run.md +6 -0
  851. package/corpus/templates/slides-2/changelog/2026-10-19-the-editor-highlights-hovered-objects-and-keeps-image-replac.md +6 -0
  852. package/corpus/templates/slides-2/changelog/2026-10-19-the-slide-editor-uses-the-shared-agent-native-controls.md +6 -0
  853. package/corpus/templates/slides-2/changelog/2026-10-20-deck-editing-controls-match-the-workspace.md +6 -0
  854. package/corpus/templates/slides-2/changelog/2026-10-20-google-slides-imports-now-report-missing-image-data-instead-.md +6 -0
  855. package/corpus/templates/slides-2/changelog/2026-10-20-imports-and-previews-handle-large-content-safely.md +6 -0
  856. package/corpus/templates/slides-2/changelog/2026-10-20-public-deck-pages-can-export-source-backed-slides-to-pdf.md +6 -0
  857. package/corpus/templates/slides-2/changelog/2026-10-20-saved-slide-images-stay-available.md +6 -0
  858. package/corpus/templates/slides-2/changelog/2026-10-20-scope-global-media-picks-to-assets-the-current-deck-can-reso.md +6 -0
  859. package/corpus/templates/slides-2/components.json +20 -0
  860. package/corpus/templates/slides-2/drizzle.config.ts +3 -0
  861. package/corpus/templates/slides-2/learnings.defaults.md +5 -0
  862. package/corpus/templates/slides-2/netlify.toml +24 -0
  863. package/corpus/templates/slides-2/package.json +147 -0
  864. package/corpus/templates/slides-2/public/agent-native-icon-dark.svg +10 -0
  865. package/corpus/templates/slides-2/public/agent-native-icon-light.svg +10 -0
  866. package/corpus/templates/slides-2/public/agent-native-logo-dark.svg +21 -0
  867. package/corpus/templates/slides-2/public/agent-native-logo-light.svg +21 -0
  868. package/corpus/templates/slides-2/public/assets/builder-logo-white.svg +15 -0
  869. package/corpus/templates/slides-2/public/assets/generated/preview.html +61 -0
  870. package/corpus/templates/slides-2/public/assets/intuit-logo-white.svg +6 -0
  871. package/corpus/templates/slides-2/public/assets/walmart-logo-white.svg +6 -0
  872. package/corpus/templates/slides-2/public/chatgpt-plugin-icon.svg +7 -0
  873. package/corpus/templates/slides-2/public/favicon.svg +1 -0
  874. package/corpus/templates/slides-2/public/icon-180.svg +1 -0
  875. package/corpus/templates/slides-2/public/icon-192.svg +1 -0
  876. package/corpus/templates/slides-2/public/icon-512.svg +1 -0
  877. package/corpus/templates/slides-2/public/manifest.json +20 -0
  878. package/corpus/templates/slides-2/public/placeholder.svg +1 -0
  879. package/corpus/templates/slides-2/public/robots.txt +14 -0
  880. package/corpus/templates/slides-2/public/visual-edit-structure-proof.html +99 -0
  881. package/corpus/templates/slides-2/react-router.config.ts +7 -0
  882. package/corpus/templates/slides-2/scripts/edit-fidelity/README.md +499 -0
  883. package/corpus/templates/slides-2/scripts/edit-fidelity/authoring-fuzz.ts +9517 -0
  884. package/corpus/templates/slides-2/scripts/edit-fidelity/baseline.json +16427 -0
  885. package/corpus/templates/slides-2/scripts/edit-fidelity/dev-server-url.ts +10 -0
  886. package/corpus/templates/slides-2/scripts/edit-fidelity/lib/in-page.ts +1975 -0
  887. package/corpus/templates/slides-2/scripts/edit-fidelity/lib/metrics.ts +1401 -0
  888. package/corpus/templates/slides-2/scripts/edit-fidelity/retry-infra.ts +7 -0
  889. package/corpus/templates/slides-2/scripts/edit-fidelity/run-options.ts +21 -0
  890. package/corpus/templates/slides-2/scripts/edit-fidelity/run-outcomes.ts +127 -0
  891. package/corpus/templates/slides-2/scripts/edit-fidelity/run.ts +8451 -0
  892. package/corpus/templates/slides-2/scripts/export-fidelity/README.md +116 -0
  893. package/corpus/templates/slides-2/scripts/export-fidelity/compare-layout-lib.ts +241 -0
  894. package/corpus/templates/slides-2/scripts/export-fidelity/compare-layout.ts +30 -0
  895. package/corpus/templates/slides-2/scripts/export-fidelity/diff.ts +222 -0
  896. package/corpus/templates/slides-2/scripts/export-fidelity/export.ts +765 -0
  897. package/corpus/templates/slides-2/scripts/export-fidelity/fixtures/agent-dark-deck.json +48 -0
  898. package/corpus/templates/slides-2/scripts/export-fidelity/generate-calibration.ts +765 -0
  899. package/corpus/templates/slides-2/scripts/export-fidelity/google-export.ts +137 -0
  900. package/corpus/templates/slides-2/scripts/export-fidelity/google-layout.ts +82 -0
  901. package/corpus/templates/slides-2/scripts/export-fidelity/resolve-pkg.ts +29 -0
  902. package/corpus/templates/slides-2/scripts/migrate-production.ts +22 -0
  903. package/corpus/templates/slides-2/server/db/index.ts +73 -0
  904. package/corpus/templates/slides-2/server/db/schema.ts +189 -0
  905. package/corpus/templates/slides-2/server/handlers/assets-url.ts +13 -0
  906. package/corpus/templates/slides-2/server/handlers/assets.ts +3217 -0
  907. package/corpus/templates/slides-2/server/handlers/decks.ts +185 -0
  908. package/corpus/templates/slides-2/server/handlers/demo.ts +9 -0
  909. package/corpus/templates/slides-2/server/handlers/design-systems.ts +219 -0
  910. package/corpus/templates/slides-2/server/handlers/google-docs-auth.ts +165 -0
  911. package/corpus/templates/slides-2/server/handlers/image-gen.ts +153 -0
  912. package/corpus/templates/slides-2/server/handlers/image-providers/gemini.ts +209 -0
  913. package/corpus/templates/slides-2/server/handlers/image-providers/index.ts +61 -0
  914. package/corpus/templates/slides-2/server/handlers/image-providers/openai.ts +288 -0
  915. package/corpus/templates/slides-2/server/handlers/image-providers/types.ts +35 -0
  916. package/corpus/templates/slides-2/server/handlers/import/docx-parser.ts +31 -0
  917. package/corpus/templates/slides-2/server/handlers/import/html-converter.ts +1534 -0
  918. package/corpus/templates/slides-2/server/handlers/import/pdf-fidelity-parser.ts +1039 -0
  919. package/corpus/templates/slides-2/server/handlers/import/pdf-sidecar-reader.ts +81 -0
  920. package/corpus/templates/slides-2/server/handlers/import/pdf-style-digest.ts +187 -0
  921. package/corpus/templates/slides-2/server/handlers/import/pptx-assets.ts +155 -0
  922. package/corpus/templates/slides-2/server/handlers/import/pptx-parser.ts +57 -0
  923. package/corpus/templates/slides-2/server/handlers/request-auth-context.ts +108 -0
  924. package/corpus/templates/slides-2/server/handlers/share.ts +52 -0
  925. package/corpus/templates/slides-2/server/handlers/uploads-chunked.ts +1066 -0
  926. package/corpus/templates/slides-2/server/handlers/uploads.ts +457 -0
  927. package/corpus/templates/slides-2/server/lib/access-request-email.ts +66 -0
  928. package/corpus/templates/slides-2/server/lib/assets-image-delegation.ts +331 -0
  929. package/corpus/templates/slides-2/server/lib/bounded-multipart.ts +49 -0
  930. package/corpus/templates/slides-2/server/lib/builder-design-system-proxy.ts +122 -0
  931. package/corpus/templates/slides-2/server/lib/chat-attachments.ts +425 -0
  932. package/corpus/templates/slides-2/server/lib/chatgpt-directory-tools.ts +246 -0
  933. package/corpus/templates/slides-2/server/lib/chunked-upload-session.ts +195 -0
  934. package/corpus/templates/slides-2/server/lib/comment-notifications.ts +184 -0
  935. package/corpus/templates/slides-2/server/lib/deck-access-requests.ts +102 -0
  936. package/corpus/templates/slides-2/server/lib/deck-asset-scope.ts +150 -0
  937. package/corpus/templates/slides-2/server/lib/deck-export-tracking.ts +119 -0
  938. package/corpus/templates/slides-2/server/lib/deck-templates/a-case-study.ts +154 -0
  939. package/corpus/templates/slides-2/server/lib/deck-templates/a-company.ts +160 -0
  940. package/corpus/templates/slides-2/server/lib/deck-templates/a-pitch.ts +151 -0
  941. package/corpus/templates/slides-2/server/lib/deck-templates/a-quarterly.ts +264 -0
  942. package/corpus/templates/slides-2/server/lib/deck-templates/a-shared.ts +35 -0
  943. package/corpus/templates/slides-2/server/lib/deck-templates/a-update.ts +188 -0
  944. package/corpus/templates/slides-2/server/lib/deck-templates/a-workshop.ts +196 -0
  945. package/corpus/templates/slides-2/server/lib/deck-templates/b-keynote.ts +131 -0
  946. package/corpus/templates/slides-2/server/lib/deck-templates/b-lesson.ts +209 -0
  947. package/corpus/templates/slides-2/server/lib/deck-templates/b-manifesto.ts +149 -0
  948. package/corpus/templates/slides-2/server/lib/deck-templates/b-portfolio.ts +144 -0
  949. package/corpus/templates/slides-2/server/lib/deck-templates/b-research.ts +221 -0
  950. package/corpus/templates/slides-2/server/lib/deck-templates/b-roadmap.ts +264 -0
  951. package/corpus/templates/slides-2/server/lib/deck-templates/b-shared.ts +44 -0
  952. package/corpus/templates/slides-2/server/lib/deck-templates/group-a.ts +16 -0
  953. package/corpus/templates/slides-2/server/lib/deck-templates/group-b.ts +16 -0
  954. package/corpus/templates/slides-2/server/lib/deck-templates/legacy.ts +567 -0
  955. package/corpus/templates/slides-2/server/lib/deck-templates.ts +60 -0
  956. package/corpus/templates/slides-2/server/lib/deck-versions.ts +233 -0
  957. package/corpus/templates/slides-2/server/lib/design-system-workflows.ts +22 -0
  958. package/corpus/templates/slides-2/server/lib/emails.ts +84 -0
  959. package/corpus/templates/slides-2/server/lib/env-config.ts +15 -0
  960. package/corpus/templates/slides-2/server/lib/fetch-remote-image.ts +245 -0
  961. package/corpus/templates/slides-2/server/lib/generation-completion.ts +278 -0
  962. package/corpus/templates/slides-2/server/lib/google-docs-access.ts +51 -0
  963. package/corpus/templates/slides-2/server/lib/google-docs-error.ts +54 -0
  964. package/corpus/templates/slides-2/server/lib/google-docs-oauth.ts +422 -0
  965. package/corpus/templates/slides-2/server/lib/google-fonts.ts +509 -0
  966. package/corpus/templates/slides-2/server/lib/google-oauth-preflight.ts +119 -0
  967. package/corpus/templates/slides-2/server/lib/google-slides-export-availability.ts +55 -0
  968. package/corpus/templates/slides-2/server/lib/image-proxy-response.ts +16 -0
  969. package/corpus/templates/slides-2/server/lib/image-proxy-url.ts +155 -0
  970. package/corpus/templates/slides-2/server/lib/import-asset-storage.ts +214 -0
  971. package/corpus/templates/slides-2/server/lib/imported-asset-batch.ts +218 -0
  972. package/corpus/templates/slides-2/server/lib/legacy-slide-source.ts +692 -0
  973. package/corpus/templates/slides-2/server/lib/media-search-providers.ts +216 -0
  974. package/corpus/templates/slides-2/server/lib/native-creative-context.ts +295 -0
  975. package/corpus/templates/slides-2/server/lib/pdf-parse-setup.ts +115 -0
  976. package/corpus/templates/slides-2/server/lib/provider-api.ts +57 -0
  977. package/corpus/templates/slides-2/server/lib/request-wait-until.ts +30 -0
  978. package/corpus/templates/slides-2/server/lib/shared-deck.ts +29 -0
  979. package/corpus/templates/slides-2/server/lib/slide-asset-references.ts +309 -0
  980. package/corpus/templates/slides-2/server/lib/slide-content-patch.ts +1004 -0
  981. package/corpus/templates/slides-2/server/lib/slide-hygiene.ts +731 -0
  982. package/corpus/templates/slides-2/server/lib/slide-image-insertion.ts +136 -0
  983. package/corpus/templates/slides-2/server/lib/slide-reveal-issues.ts +41 -0
  984. package/corpus/templates/slides-2/server/lib/slide-source-editing/babel-walk.ts +117 -0
  985. package/corpus/templates/slides-2/server/lib/slide-source-editing/batch-edit.ts +152 -0
  986. package/corpus/templates/slides-2/server/lib/slide-source-editing/edit-ops.ts +1478 -0
  987. package/corpus/templates/slides-2/server/lib/slide-source-editing/image-target.ts +128 -0
  988. package/corpus/templates/slides-2/server/lib/slide-source-editing/text-diff.ts +23 -0
  989. package/corpus/templates/slides-2/server/lib/slide-source-limits.ts +9 -0
  990. package/corpus/templates/slides-2/server/lib/slide-source.ts +1786 -0
  991. package/corpus/templates/slides-2/server/lib/slide-theme-demo-sources.ts +2106 -0
  992. package/corpus/templates/slides-2/server/lib/slide-themes.ts +2174 -0
  993. package/corpus/templates/slides-2/server/lib/slide-worker-runtime.ts +1995 -0
  994. package/corpus/templates/slides-2/server/lib/slides-tracking.ts +73 -0
  995. package/corpus/templates/slides-2/server/lib/source-import.ts +213 -0
  996. package/corpus/templates/slides-2/server/lib/svgl.ts +364 -0
  997. package/corpus/templates/slides-2/server/lib/tenant-files.ts +179 -0
  998. package/corpus/templates/slides-2/server/lib/upload-storage-status.ts +9 -0
  999. package/corpus/templates/slides-2/server/lib/uploaded-asset-cleanup-outbox.ts +521 -0
  1000. package/corpus/templates/slides-2/server/lib/uploaded-asset-object-lifecycle.ts +404 -0
  1001. package/corpus/templates/slides-2/server/lib/uploaded-fonts.ts +696 -0
  1002. package/corpus/templates/slides-2/server/lib/uploaded-reference-storage.ts +77 -0
  1003. package/corpus/templates/slides-2/server/lib/validate-slide-animations.ts +341 -0
  1004. package/corpus/templates/slides-2/server/middleware/auth.ts +6 -0
  1005. package/corpus/templates/slides-2/server/plugins/_dev-upload-stub.ts +6 -0
  1006. package/corpus/templates/slides-2/server/plugins/agent-chat.ts +402 -0
  1007. package/corpus/templates/slides-2/server/plugins/auth.ts +31 -0
  1008. package/corpus/templates/slides-2/server/plugins/collab.ts +30 -0
  1009. package/corpus/templates/slides-2/server/plugins/config.ts +6 -0
  1010. package/corpus/templates/slides-2/server/plugins/core-routes.ts +30 -0
  1011. package/corpus/templates/slides-2/server/plugins/creative-context.ts +187 -0
  1012. package/corpus/templates/slides-2/server/plugins/db.ts +462 -0
  1013. package/corpus/templates/slides-2/server/plugins/feature-flags.ts +5 -0
  1014. package/corpus/templates/slides-2/server/plugins/labs.ts +8 -0
  1015. package/corpus/templates/slides-2/server/plugins/orphaned-asset-cleanup.ts +17 -0
  1016. package/corpus/templates/slides-2/server/plugins/otel.ts +6 -0
  1017. package/corpus/templates/slides-2/server/plugins/transactional-emails.ts +5 -0
  1018. package/corpus/templates/slides-2/server/register-secrets.ts +209 -0
  1019. package/corpus/templates/slides-2/server/routes/[...page].get.ts +5 -0
  1020. package/corpus/templates/slides-2/server/routes/[...page].head.ts +1 -0
  1021. package/corpus/templates/slides-2/server/routes/[base]/_agent-native/google-docs/auth-url.get.ts +1 -0
  1022. package/corpus/templates/slides-2/server/routes/[base]/_agent-native/google-docs/callback.get.ts +1 -0
  1023. package/corpus/templates/slides-2/server/routes/_agent-native/google-docs/auth-url.get.ts +1 -0
  1024. package/corpus/templates/slides-2/server/routes/_agent-native/google-docs/callback.get.ts +1 -0
  1025. package/corpus/templates/slides-2/server/routes/api/assets/upload-video.post.ts +1 -0
  1026. package/corpus/templates/slides-2/server/routes/api/assets/upload.post.ts +1 -0
  1027. package/corpus/templates/slides-2/server/routes/api/assets/video-uploads.delete.ts +1 -0
  1028. package/corpus/templates/slides-2/server/routes/api/deck-agent-context.json.get.ts +105 -0
  1029. package/corpus/templates/slides-2/server/routes/api/decks/events.get.ts +1 -0
  1030. package/corpus/templates/slides-2/server/routes/api/demo.get.ts +1 -0
  1031. package/corpus/templates/slides-2/server/routes/api/exports/[filename].get.ts +221 -0
  1032. package/corpus/templates/slides-2/server/routes/api/exports/google-slides.post.ts +240 -0
  1033. package/corpus/templates/slides-2/server/routes/api/exports/html.post.ts +67 -0
  1034. package/corpus/templates/slides-2/server/routes/api/exports/pptx.post.ts +100 -0
  1035. package/corpus/templates/slides-2/server/routes/api/gen-preview/[...].get.ts +24 -0
  1036. package/corpus/templates/slides-2/server/routes/api/generated/[...].get.ts +24 -0
  1037. package/corpus/templates/slides-2/server/routes/api/image-proxy.get.ts +518 -0
  1038. package/corpus/templates/slides-2/server/routes/api/import-assets/[token].get.ts +70 -0
  1039. package/corpus/templates/slides-2/server/routes/api/preview-images.get.ts +20 -0
  1040. package/corpus/templates/slides-2/server/routes/api/share/[token].get.ts +1 -0
  1041. package/corpus/templates/slides-2/server/routes/api/uploads-chunked/[sessionId]/chunk.post.ts +1 -0
  1042. package/corpus/templates/slides-2/server/routes/api/uploads-chunked/[sessionId]/status.get.ts +1 -0
  1043. package/corpus/templates/slides-2/server/routes/api/uploads-chunked/[sessionId].delete.ts +1 -0
  1044. package/corpus/templates/slides-2/server/routes/api/uploads-chunked/start.post.ts +1 -0
  1045. package/corpus/templates/slides-2/server/routes/api/uploads.delete.ts +1 -0
  1046. package/corpus/templates/slides-2/server/routes/api/uploads.post.ts +1 -0
  1047. package/corpus/templates/slides-2/server/workspace-defaults.ts +196 -0
  1048. package/corpus/templates/slides-2/shared/action-ui.ts +147 -0
  1049. package/corpus/templates/slides-2/shared/agent-readable.ts +2 -0
  1050. package/corpus/templates/slides-2/shared/api.ts +406 -0
  1051. package/corpus/templates/slides-2/shared/app-state-tabs.ts +30 -0
  1052. package/corpus/templates/slides-2/shared/app-storage.ts +9 -0
  1053. package/corpus/templates/slides-2/shared/aspect-ratios.ts +49 -0
  1054. package/corpus/templates/slides-2/shared/blank-slide.ts +179 -0
  1055. package/corpus/templates/slides-2/shared/client-compatibility.ts +2 -0
  1056. package/corpus/templates/slides-2/shared/contrast-audit.ts +255 -0
  1057. package/corpus/templates/slides-2/shared/deck-access.ts +26 -0
  1058. package/corpus/templates/slides-2/shared/deck-app-scope.ts +14 -0
  1059. package/corpus/templates/slides-2/shared/deck-content.ts +37 -0
  1060. package/corpus/templates/slides-2/shared/deck-history-control.ts +79 -0
  1061. package/corpus/templates/slides-2/shared/deck-scope.ts +5 -0
  1062. package/corpus/templates/slides-2/shared/deck-title.ts +199 -0
  1063. package/corpus/templates/slides-2/shared/deck-write.ts +61 -0
  1064. package/corpus/templates/slides-2/shared/design-flags.ts +7 -0
  1065. package/corpus/templates/slides-2/shared/design-system-validation.ts +88 -0
  1066. package/corpus/templates/slides-2/shared/editor-control.ts +120 -0
  1067. package/corpus/templates/slides-2/shared/generation-timing.ts +19 -0
  1068. package/corpus/templates/slides-2/shared/google-docs.ts +69 -0
  1069. package/corpus/templates/slides-2/shared/labs.ts +10 -0
  1070. package/corpus/templates/slides-2/shared/overview-navigation.ts +34 -0
  1071. package/corpus/templates/slides-2/shared/ownership.ts +6 -0
  1072. package/corpus/templates/slides-2/shared/pdf-sidecar.ts +130 -0
  1073. package/corpus/templates/slides-2/shared/presenter-control.ts +111 -0
  1074. package/corpus/templates/slides-2/shared/representative-slide.ts +89 -0
  1075. package/corpus/templates/slides-2/shared/slide-background.ts +30 -0
  1076. package/corpus/templates/slides-2/shared/slide-comment-anchor.ts +117 -0
  1077. package/corpus/templates/slides-2/shared/slide-comment-reactions.ts +47 -0
  1078. package/corpus/templates/slides-2/shared/slide-design-tokens.ts +92 -0
  1079. package/corpus/templates/slides-2/shared/slide-fit.ts +78 -0
  1080. package/corpus/templates/slides-2/shared/slide-ids.ts +133 -0
  1081. package/corpus/templates/slides-2/shared/slide-number.ts +124 -0
  1082. package/corpus/templates/slides-2/shared/slide-object-structure.ts +790 -0
  1083. package/corpus/templates/slides-2/shared/slide-text-range-selection.ts +50 -0
  1084. package/corpus/templates/slides-2/shared/slide-transitions.ts +70 -0
  1085. package/corpus/templates/slides-2/shared/slides-2-transition.ts +194 -0
  1086. package/corpus/templates/slides-2/shared/slides-user-prefs.ts +22 -0
  1087. package/corpus/templates/slides-2/shared/source-import-errors.ts +12 -0
  1088. package/corpus/templates/slides-2/shared/source-runtime-export.ts +76 -0
  1089. package/corpus/templates/slides-2/shared/upload-types.ts +41 -0
  1090. package/corpus/templates/slides-2/ssr-entry.ts +11 -0
  1091. package/corpus/templates/slides-2/tsconfig.json +27 -0
  1092. package/corpus/templates/slides-2/vite.config.ts +77 -0
  1093. package/corpus/templates/slides-2/vitest.config.ts +28 -0
  1094. package/corpus/templates/tasks/.agents/skills/actions/references/action-fields.md +1 -1
  1095. package/package.json +1 -1
  1096. package/corpus/templates/design/.agents/skills/shader-fills/SKILL.md +0 -182
  1097. package/corpus/templates/design/actions/apply-shader-fill.ts +0 -450
  1098. package/corpus/templates/design/actions/apply-shader.ts +0 -257
  1099. package/corpus/templates/design/actions/preview-shader-fill.ts +0 -157
  1100. package/corpus/templates/design/app/components/design/inspector/GlslShaderPanel.tsx +0 -1144
  1101. package/corpus/templates/design/app/components/design/inspector/SHADER_INTEGRATION.md +0 -450
  1102. package/corpus/templates/design/app/components/design/inspector/ShaderControls.stories.tsx +0 -71
  1103. package/corpus/templates/design/app/components/design/inspector/ShaderControls.tsx +0 -555
  1104. package/corpus/templates/design/app/components/design/inspector/ShaderEffectRow.tsx +0 -105
  1105. package/corpus/templates/design/app/components/design/inspector/ShaderFillsPanel.tsx +0 -433
  1106. package/corpus/templates/design/app/components/design/inspector/color-picker-shader-pane.tsx +0 -648
  1107. package/corpus/templates/design/shared/shader-fill.ts +0 -174
  1108. package/corpus/templates/design/shared/shader-presets.ts +0 -1523
@@ -0,0 +1,4804 @@
1
+ import {
2
+ compareAndSetClientAppState,
3
+ readClientAppState,
4
+ writeClientAppState,
5
+ } from "@agent-native/core/client/application-state";
6
+ import {
7
+ useActionQuery,
8
+ useChangeVersion,
9
+ useDbSync,
10
+ } from "@agent-native/core/client/hooks";
11
+ import { useT } from "@agent-native/core/client/i18n";
12
+ import type { useT as useTranslator } from "@agent-native/core/client/i18n";
13
+ import { parse } from "@babel/parser";
14
+ import {
15
+ closestCenter,
16
+ DndContext,
17
+ KeyboardSensor,
18
+ PointerSensor,
19
+ useSensor,
20
+ useSensors,
21
+ type DragEndEvent,
22
+ type DragStartEvent,
23
+ } from "@dnd-kit/core";
24
+ import {
25
+ SortableContext,
26
+ sortableKeyboardCoordinates,
27
+ useSortable,
28
+ verticalListSortingStrategy,
29
+ } from "@dnd-kit/sortable";
30
+ import { CSS } from "@dnd-kit/utilities";
31
+ import { appStateKey, appStateKeyForBrowserTab } from "@shared/app-state-tabs";
32
+ import {
33
+ completeSlideEditorCommand,
34
+ isSlideEditorOperationAvailable,
35
+ slideEditorCommandMatchesEditorState,
36
+ slideEditorCommandSchema,
37
+ slideEditorStatusSchema,
38
+ SLIDE_EDITOR_COMMAND_KEY,
39
+ SLIDE_EDITOR_STATUS_KEY,
40
+ type SlideEditorCommand,
41
+ } from "@shared/editor-control";
42
+ import { overviewFocusNavigationIndex } from "@shared/overview-navigation";
43
+ import type { SlideCommentAnchor } from "@shared/slide-comment-anchor";
44
+ import {
45
+ currentSlideTextRangeSelection,
46
+ MAX_SLIDE_TEXT_RANGE_EXPECTED_TEXT_LENGTH,
47
+ } from "@shared/slide-text-range-selection";
48
+ import type { SlideTextRangeSelection } from "@shared/slide-text-range-selection";
49
+ import {
50
+ IconArrowLeft,
51
+ IconChevronLeft,
52
+ IconChevronRight,
53
+ IconCheck,
54
+ IconCrop,
55
+ IconPlayerPlay,
56
+ IconMinus,
57
+ IconPlus,
58
+ IconArrowBackUp,
59
+ IconArrowForwardUp,
60
+ IconArrowDown,
61
+ IconArrowUp,
62
+ IconPhoto,
63
+ IconCopy,
64
+ IconMessageCircle,
65
+ IconSearch,
66
+ IconTrash,
67
+ IconEye,
68
+ IconPencil,
69
+ IconLayoutSidebarRightCollapse,
70
+ IconLayoutSidebarRightExpand,
71
+ } from "@tabler/icons-react";
72
+ import { nanoid } from "nanoid";
73
+ import {
74
+ useCallback,
75
+ useEffect,
76
+ useMemo,
77
+ useRef,
78
+ useState,
79
+ type KeyboardEvent as ReactKeyboardEvent,
80
+ type PointerEvent as ReactPointerEvent,
81
+ } from "react";
82
+ import { Link } from "react-router";
83
+ import { toast } from "sonner";
84
+
85
+ import { Button } from "@/components/ui/button";
86
+ import {
87
+ ContextMenu,
88
+ ContextMenuContent,
89
+ ContextMenuItem,
90
+ ContextMenuSeparator,
91
+ ContextMenuTrigger,
92
+ } from "@/components/ui/context-menu";
93
+ import {
94
+ Dialog,
95
+ DialogContent,
96
+ DialogHeader,
97
+ DialogTitle,
98
+ } from "@/components/ui/dialog";
99
+ import {
100
+ DropdownMenu,
101
+ DropdownMenuContent,
102
+ DropdownMenuItem,
103
+ DropdownMenuTrigger,
104
+ } from "@/components/ui/dropdown-menu";
105
+ import { Skeleton } from "@/components/ui/skeleton";
106
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
107
+ import { Textarea } from "@/components/ui/textarea";
108
+ import type { AspectRatio } from "@/lib/aspect-ratios";
109
+ import {
110
+ slideCommentAnchorAtPoint,
111
+ slideCommentAnchorForRegion,
112
+ } from "@/lib/slide-comment-anchor";
113
+ import { TAB_ID } from "@/lib/tab-id";
114
+
115
+ import {
116
+ SLIDES_2_CANVAS_HEIGHT,
117
+ SLIDES_2_CANVAS_WIDTH,
118
+ } from "../slides-2-runtime/constants";
119
+ import type {
120
+ SlideDesignTokens,
121
+ SlideFrameNavigationInput,
122
+ SlideRenderArtifact,
123
+ SlideFrameTextRangeStyle,
124
+ } from "../slides-2-runtime/protocol";
125
+ import {
126
+ SandboxedSlide,
127
+ type FrameKeyboard,
128
+ type FramePointer,
129
+ type SlideFrameController,
130
+ } from "../slides-2-runtime/SandboxedSlide";
131
+ import { Slides2Canvas } from "../slides-2-runtime/Slides2Canvas";
132
+ import type {
133
+ CrossSlideHistorySelection,
134
+ CrossSlideSourceCommitEntry,
135
+ CrossSlideSourceRestoreRequest,
136
+ } from "./cross-slide-edit-history";
137
+ import { getEditorActionErrorTranslationKey } from "./editor-action-errors";
138
+ import {
139
+ alignRects,
140
+ constrainMoveDelta,
141
+ distributeRects,
142
+ SLIDES_2_BOUNDS,
143
+ rectContains,
144
+ rectsIntersect,
145
+ resizeRect,
146
+ snapMove,
147
+ snapRotationTo15Degrees,
148
+ solveResizeDimensions,
149
+ unionRects,
150
+ type Alignment,
151
+ type Point,
152
+ type Rect,
153
+ type ResizeHandle,
154
+ } from "./geometry";
155
+ import {
156
+ imageCropStyleEdits,
157
+ objectViewBoxToCropRect,
158
+ } from "./image-crop-style";
159
+ import { InlineTextEditor } from "./inline-text-editor";
160
+ import { getSlides2EditorShortcut } from "./keyboard-shortcuts";
161
+ import {
162
+ insertSourceObject,
163
+ getDefaultComponentRootRange,
164
+ type Slides2ObjectKind,
165
+ } from "./object-insertion";
166
+ import { getPreviewPatches } from "./preview-patches";
167
+ import { Slides2AssetBrowser } from "./Slides2AssetBrowser";
168
+ import { Slides2CommandMenu } from "./Slides2CommandMenu";
169
+ import { Slides2Comments } from "./Slides2Comments";
170
+ import { Slides2DesignTokens } from "./Slides2DesignTokens";
171
+ import {
172
+ Slides2ExportMenu,
173
+ type Slides2ExportFormat,
174
+ type Slides2ExportMenuHandle,
175
+ } from "./Slides2ExportMenu";
176
+ import {
177
+ Slides2ImageCropControls,
178
+ type Slides2ImageCropResult,
179
+ } from "./Slides2ImageCropControls";
180
+ import { Slides2Inspector } from "./Slides2Inspector";
181
+ import {
182
+ deleteSourceElement,
183
+ duplicateSourceElement,
184
+ getParentSourceSelection,
185
+ getSelectedAssetId,
186
+ insertAssetOnCanvas,
187
+ staticPositionZOrderEdits,
188
+ type SourceSelection,
189
+ } from "./source-structure";
190
+ import type {
191
+ ElementSnapshot,
192
+ SlideSource,
193
+ SourceEdit,
194
+ SourceEditOp,
195
+ } from "./types";
196
+
197
+ type Translate = ReturnType<typeof useTranslator>;
198
+ export type Slides2InspectorPanel = "format" | "design" | "notes";
199
+ export type Slides2EditorMode = "edit" | "preview";
200
+
201
+ type PreviewStepState = {
202
+ artifactKey: string | null;
203
+ stepCount: number | null;
204
+ revealedSteps: number;
205
+ };
206
+
207
+ type SourceVersion = Pick<SlideSource, "revision" | "sourceHash">;
208
+
209
+ const activeSlideEditorCommands = new Set<string>();
210
+ const completedSlideEditorCommands = new Map<string, SlideEditorCommand>();
211
+ const slideEditorCommandAckRetryAttempts = new Map<string, number>();
212
+
213
+ type SlideSummary = {
214
+ id: string;
215
+ slideNumber: number;
216
+ textPreview?: string;
217
+ isBlank?: boolean;
218
+ };
219
+
220
+ type Props = {
221
+ deckId: string;
222
+ title: string;
223
+ slides: SlideSummary[];
224
+ activeIndex: number;
225
+ source: SlideSource;
226
+ notes: string;
227
+ artifact: SlideRenderArtifact | null;
228
+ designTokens: SlideDesignTokens | null;
229
+ savingDesignTokens: boolean;
230
+ savingNotes: boolean;
231
+ loading: boolean;
232
+ loadingError?: string | null;
233
+ saving: boolean;
234
+ sourceConflict: boolean;
235
+ structuralSaving: boolean;
236
+ structuralError?: string | null;
237
+ canEdit: boolean;
238
+ canComment: boolean;
239
+ backHref: string;
240
+ presentHref: string;
241
+ aspectRatio?: AspectRatio;
242
+ zoom?: number;
243
+ onZoomChange?: (zoom: number) => void;
244
+ slideRailWidth?: number;
245
+ onSlideRailWidthChange?: (width: number) => void;
246
+ activePanel?: Slides2InspectorPanel;
247
+ previousPanel?: Slides2InspectorPanel;
248
+ onActivePanelChange?: (panel: Slides2InspectorPanel) => void;
249
+ inspectorOpen?: boolean;
250
+ onInspectorOpenChange?: (open: boolean) => void;
251
+ inspectorBeforePreview?: boolean | null;
252
+ onInspectorBeforePreviewChange?: (open: boolean | null) => void;
253
+ inspectorToggledInPreview?: boolean;
254
+ onInspectorToggledInPreviewChange?: (toggled: boolean) => void;
255
+ overviewOpen?: boolean;
256
+ onOverviewOpenChange?: (open: boolean) => void;
257
+ t?: Translate;
258
+ onSelectSlide: (index: number) => void;
259
+ onPresent: (mode?: "fullscreen" | "windowed") => void;
260
+ onOpenPresenter?: () => void;
261
+ onSave: (
262
+ edits: SourceEdit[],
263
+ ) => Promise<Pick<SlideSource, "sourceTsx" | "revision" | "sourceHash">>;
264
+ onReloadSource: () => Promise<SlideSource>;
265
+ onRestore: (
266
+ sourceTsx: string,
267
+ expected?: SourceVersion,
268
+ ) => Promise<Pick<SlideSource, "sourceTsx" | "revision" | "sourceHash">>;
269
+ onSaveDesignTokens: (tokens: SlideDesignTokens) => Promise<void>;
270
+ onSaveNotes: (notes: string) => Promise<void>;
271
+ onSelectionChange: (
272
+ selected: ElementSnapshot[],
273
+ textRange: SlideTextRangeSelection | null,
274
+ ) => void;
275
+ editorMode?: Slides2EditorMode;
276
+ onPanelChange?: (panel: Slides2InspectorPanel | null) => void;
277
+ onEditorModeChange?: (mode: Slides2EditorMode) => void;
278
+ onAddSlide: () => void;
279
+ onDuplicateSlide: (index: number) => void;
280
+ onDeleteSlide: (index: number) => void;
281
+ onMoveSlide: (from: number, to: number) => void;
282
+ crossSlideHistory?: {
283
+ editBatches: SourceEdit[][];
284
+ historyIndex: number;
285
+ canUndo: boolean;
286
+ canRedo: boolean;
287
+ append: (edits: SourceEdit[]) => void;
288
+ undo: () => boolean | Promise<boolean>;
289
+ redo: () => boolean | Promise<boolean>;
290
+ commit: (entry: Omit<CrossSlideSourceCommitEntry, "type">) => void;
291
+ clear: () => void;
292
+ selection?: CrossSlideHistorySelection | null;
293
+ onSelectionApplied: (requestId: string) => void;
294
+ restoreRequest?: CrossSlideSourceRestoreRequest | null;
295
+ onSourceRestoreComplete?: (
296
+ requestId: string,
297
+ source: Pick<SlideSource, "revision" | "sourceHash"> | null,
298
+ ) => void;
299
+ };
300
+ };
301
+
302
+ type EditBatch = SourceEdit[];
303
+ export const SLIDE_RAIL_WIDTH_STATE_KEY = appStateKey(
304
+ "slides-2-editor-rail-width",
305
+ );
306
+ export const DEFAULT_SLIDE_RAIL_WIDTH = 264;
307
+ const MIN_SLIDE_RAIL_WIDTH = 200;
308
+ const MAX_SLIDE_RAIL_WIDTH = 480;
309
+
310
+ function clampSlideRailWidth(width: number): number {
311
+ return Math.min(
312
+ MAX_SLIDE_RAIL_WIDTH,
313
+ Math.max(MIN_SLIDE_RAIL_WIDTH, Math.round(width)),
314
+ );
315
+ }
316
+
317
+ export function readSlideRailWidth(value: unknown): number | null {
318
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
319
+ const width = (value as { width?: unknown }).width;
320
+ return typeof width === "number" && Number.isFinite(width)
321
+ ? clampSlideRailWidth(width)
322
+ : null;
323
+ }
324
+
325
+ type DragMode = "move" | "marquee" | "resize" | "rotate";
326
+ type DragState = {
327
+ mode: DragMode;
328
+ pointerId: number;
329
+ start: Point;
330
+ moved: boolean;
331
+ nodeIds: string[];
332
+ initial: ElementSnapshot[];
333
+ handle?: ResizeHandle;
334
+ initialRect?: Rect;
335
+ initialRotation?: number;
336
+ marquee?: Rect;
337
+ additive?: boolean;
338
+ initialSelection?: string[];
339
+ guides?: ReturnType<typeof snapMove>["guides"];
340
+ };
341
+
342
+ const EDIT_HISTORY_LIMIT = 50;
343
+ const MIN_ZOOM = 0.25;
344
+ const MAX_ZOOM = 2;
345
+ const ZOOM_STEP = 0.1;
346
+ const RESIZE_HANDLES: Array<{ key: ResizeHandle; cursor: string }> = [
347
+ { key: "nw", cursor: "nwse-resize" },
348
+ { key: "n", cursor: "ns-resize" },
349
+ { key: "ne", cursor: "nesw-resize" },
350
+ { key: "e", cursor: "ew-resize" },
351
+ { key: "se", cursor: "nwse-resize" },
352
+ { key: "s", cursor: "ns-resize" },
353
+ { key: "sw", cursor: "nesw-resize" },
354
+ { key: "w", cursor: "ew-resize" },
355
+ ];
356
+
357
+ function round(value: number): number {
358
+ return Math.round(value * 100) / 100;
359
+ }
360
+
361
+ function isFullSlideBounds(bounds: Rect): boolean {
362
+ return (
363
+ Math.abs(bounds.x) < 1 &&
364
+ Math.abs(bounds.y) < 1 &&
365
+ bounds.width >= SLIDES_2_CANVAS_WIDTH - 1 &&
366
+ bounds.height >= SLIDES_2_CANVAS_HEIGHT - 1
367
+ );
368
+ }
369
+
370
+ function elementAtPoint(
371
+ nodes: ElementSnapshot[],
372
+ point: Point,
373
+ ): ElementSnapshot | null {
374
+ let target: ElementSnapshot | null = null;
375
+ let targetArea = Number.POSITIVE_INFINITY;
376
+
377
+ for (const node of nodes) {
378
+ const bounds = node.bounds;
379
+ if (
380
+ isFullSlideBounds(bounds) ||
381
+ point.x < bounds.x ||
382
+ point.y < bounds.y ||
383
+ point.x >= bounds.x + bounds.width ||
384
+ point.y >= bounds.y + bounds.height
385
+ ) {
386
+ continue;
387
+ }
388
+
389
+ const area = bounds.width * bounds.height;
390
+ if (area <= targetArea) {
391
+ target = node;
392
+ targetArea = area;
393
+ }
394
+ }
395
+
396
+ return target;
397
+ }
398
+
399
+ function uniqueByLocator(nodes: ElementSnapshot[]): ElementSnapshot[] {
400
+ const seen = new Set<string>();
401
+ return nodes.filter((node) => {
402
+ const key = `${node.line}:${node.column}`;
403
+ if (seen.has(key)) return false;
404
+ seen.add(key);
405
+ return true;
406
+ });
407
+ }
408
+
409
+ function sourceLocatorKey(node: Pick<ElementSnapshot, "line" | "column">) {
410
+ return `${node.line}:${node.column}`;
411
+ }
412
+
413
+ function isSourceAncestor(
414
+ ancestor: ElementSnapshot,
415
+ descendant: ElementSnapshot,
416
+ ): boolean | null {
417
+ const locators = descendant.ancestorLocators;
418
+ if (!Array.isArray(locators)) return null;
419
+ if (locators?.includes(sourceLocatorKey(ancestor))) return true;
420
+ return descendant.ancestorLocatorsComplete === true ? false : null;
421
+ }
422
+
423
+ function selectionRelation(
424
+ first: ElementSnapshot,
425
+ second: ElementSnapshot,
426
+ ): "same" | "related" | "independent" | "unknown" {
427
+ if (first.nodeId === second.nodeId) return "same";
428
+ const firstIsAncestor = isSourceAncestor(first, second);
429
+ const secondIsAncestor = isSourceAncestor(second, first);
430
+ if (firstIsAncestor === true || secondIsAncestor === true) return "related";
431
+ if (firstIsAncestor === false && secondIsAncestor === false)
432
+ return "independent";
433
+ return "unknown";
434
+ }
435
+
436
+ function hasTransformableBounds(node: ElementSnapshot): boolean {
437
+ const { x, y, width, height } = node.bounds;
438
+ return (
439
+ Number.isFinite(x) &&
440
+ Number.isFinite(y) &&
441
+ Number.isFinite(width) &&
442
+ Number.isFinite(height) &&
443
+ width > 0 &&
444
+ height > 0
445
+ );
446
+ }
447
+
448
+ function independentTransformTargets(
449
+ nodes: ElementSnapshot[],
450
+ ): ElementSnapshot[] {
451
+ const candidates = uniqueByLocator(nodes).filter(
452
+ (node) => hasTransformableBounds(node) && !isFullSlideBounds(node.bounds),
453
+ );
454
+ const candidateLocators = new Set(candidates.map(sourceLocatorKey));
455
+ return candidates.filter((node) => {
456
+ if (
457
+ node.ancestorLocatorsComplete !== true ||
458
+ !Array.isArray(node.ancestorLocators)
459
+ ) {
460
+ return false;
461
+ }
462
+ return !node.ancestorLocators?.some((ancestor) =>
463
+ candidateLocators.has(ancestor),
464
+ );
465
+ });
466
+ }
467
+
468
+ function marqueeTransformTargets(
469
+ rect: Rect,
470
+ nodes: ElementSnapshot[],
471
+ ): ElementSnapshot[] {
472
+ const hits = nodes.filter(
473
+ (node) =>
474
+ hasTransformableBounds(node) &&
475
+ !isFullSlideBounds(node.bounds) &&
476
+ rectsIntersect(rect, node.bounds),
477
+ );
478
+ const preferredHits = hits.filter(
479
+ (node) =>
480
+ rectContains(rect, node.bounds) ||
481
+ !hits.some(
482
+ (other) =>
483
+ other.nodeId !== node.nodeId &&
484
+ isSourceAncestor(node, other) === true,
485
+ ),
486
+ );
487
+ return independentTransformTargets(preferredHits);
488
+ }
489
+
490
+ function marqueeSelectionIds(
491
+ rect: Rect,
492
+ nodes: ElementSnapshot[],
493
+ initialSelection: string[] = [],
494
+ ): string[] {
495
+ const existing = initialSelection.flatMap((id) =>
496
+ nodes.filter((node) => node.nodeId === id),
497
+ );
498
+ return independentTransformTargets([
499
+ ...existing,
500
+ ...marqueeTransformTargets(rect, nodes),
501
+ ]).map((node) => node.nodeId);
502
+ }
503
+
504
+ function removeRelatedSelectionIds(
505
+ ids: string[],
506
+ target: ElementSnapshot,
507
+ nodes: ElementSnapshot[],
508
+ ): string[] | null {
509
+ const next: string[] = [];
510
+ for (const id of ids) {
511
+ const selected = nodes.find((node) => node.nodeId === id);
512
+ if (!selected) return null;
513
+ const relation = selectionRelation(selected, target);
514
+ if (relation === "unknown") return null;
515
+ if (relation === "independent") next.push(id);
516
+ }
517
+ return next;
518
+ }
519
+
520
+ function isBareDesignPanelShortcut(
521
+ keyboard: Pick<KeyboardEvent, "key" | "altKey" | "ctrlKey" | "metaKey">,
522
+ ): boolean {
523
+ return (
524
+ import.meta.env.DEV &&
525
+ keyboard.key.toLowerCase() === "d" &&
526
+ !keyboard.altKey &&
527
+ !keyboard.ctrlKey &&
528
+ !keyboard.metaKey
529
+ );
530
+ }
531
+
532
+ function localTranslateForBounds(
533
+ node: ElementSnapshot,
534
+ x: number,
535
+ y: number,
536
+ ): string {
537
+ const transform = node.transform;
538
+ const basis = transform?.basis ?? { a: 1, b: 0, c: 0, d: 1 };
539
+ const translate = transform?.translate ?? { x: 0, y: 0 };
540
+ const determinant = basis.a * basis.d - basis.b * basis.c;
541
+ const dx = x - node.bounds.x;
542
+ const dy = y - node.bounds.y;
543
+ const local =
544
+ Math.abs(determinant) < 0.000001
545
+ ? { x: dx, y: dy }
546
+ : {
547
+ x: (basis.d * dx - basis.c * dy) / determinant,
548
+ y: (basis.a * dy - basis.b * dx) / determinant,
549
+ };
550
+ return `${round(translate.x + local.x)}px ${round(translate.y + local.y)}px`;
551
+ }
552
+
553
+ function resizeDimensionsForBounds(
554
+ node: ElementSnapshot,
555
+ size: Pick<Rect, "width" | "height">,
556
+ initialBounds: Rect,
557
+ nextBounds: Rect,
558
+ ): Pick<Rect, "width" | "height"> {
559
+ const basis = node.transform?.basis ?? { a: 1, b: 0, c: 0, d: 1 };
560
+ return solveResizeDimensions(
561
+ size,
562
+ {
563
+ a: Math.abs(basis.a),
564
+ b: Math.abs(basis.b),
565
+ c: Math.abs(basis.c),
566
+ d: Math.abs(basis.d),
567
+ },
568
+ {
569
+ x: nextBounds.width - initialBounds.width,
570
+ y: nextBounds.height - initialBounds.height,
571
+ },
572
+ );
573
+ }
574
+
575
+ function editFor(node: ElementSnapshot, ops: SourceEditOp[]): SourceEdit {
576
+ return { line: node.line, column: node.column, ops };
577
+ }
578
+
579
+ function sourceString(value: string): string {
580
+ return JSON.stringify(value)
581
+ .replace(/</g, "\\u003c")
582
+ .replace(/\u2028/g, "\\u2028")
583
+ .replace(/\u2029/g, "\\u2029");
584
+ }
585
+
586
+ function insertVideoAssetOnCanvas(
587
+ sourceTsx: string,
588
+ assetId: string,
589
+ filename: string,
590
+ ): { sourceTsx: string; selection?: SourceSelection } | null {
591
+ if (!/^[A-Za-z0-9_-]{1,200}$/.test(assetId)) return null;
592
+ const rootRange = getDefaultComponentRootRange(sourceTsx);
593
+ if (!rootRange) return null;
594
+ const rawRoot = sourceTsx.slice(rootRange.start, rootRange.end);
595
+ const newline = sourceTsx.includes("\r\n") ? "\r\n" : "\n";
596
+ const indentedRoot = rawRoot
597
+ .split(/\r?\n/)
598
+ .map((line) => ` ${line}`)
599
+ .join(newline);
600
+ const video = `<video src={${sourceString(`asset://${assetId}`)}} aria-label={${sourceString(filename)}} controls playsInline preload="metadata" style={{ position: "absolute", left: "760px", top: "390px", width: "400px", height: "300px", objectFit: "contain" }} />`;
601
+ const wrapper = `<div style={{ position: "relative", width: "${SLIDES_2_BOUNDS.width}px", height: "${SLIDES_2_BOUNDS.height}px", boxSizing: "border-box", overflow: "hidden" }}>${newline}${indentedRoot}${newline} ${video}${newline}</div>`;
602
+ const nextSource =
603
+ sourceTsx.slice(0, rootRange.start) +
604
+ wrapper +
605
+ sourceTsx.slice(rootRange.end);
606
+ const start = rootRange.start + wrapper.lastIndexOf(video);
607
+ const ast = parse(nextSource, {
608
+ sourceType: "module",
609
+ plugins: ["jsx", "typescript"],
610
+ });
611
+ let selection: SourceSelection | undefined;
612
+ const visit = (value: unknown) => {
613
+ if (!value || typeof value !== "object") return;
614
+ if (Array.isArray(value)) {
615
+ for (const child of value) visit(child);
616
+ return;
617
+ }
618
+ const node = value as {
619
+ type?: string;
620
+ start?: number | null;
621
+ loc?: { start?: { line?: number; column?: number } };
622
+ [key: string]: unknown;
623
+ };
624
+ if (node.type === "JSXElement" && node.start === start) {
625
+ const line = node.loc?.start?.line;
626
+ const column = node.loc?.start?.column;
627
+ if (Number.isInteger(line) && Number.isInteger(column)) {
628
+ selection = { line: line as number, column: column as number };
629
+ }
630
+ return;
631
+ }
632
+ for (const child of Object.values(node)) visit(child);
633
+ };
634
+ visit(ast);
635
+ return selection ? { sourceTsx: nextSource, selection } : null;
636
+ }
637
+
638
+ function replaceVideoAssetSource(
639
+ sourceTsx: string,
640
+ target: SourceSelection,
641
+ assetId: string,
642
+ ): string | null {
643
+ if (!/^[A-Za-z0-9_-]{1,200}$/.test(assetId)) return null;
644
+ const ast = parse(sourceTsx, {
645
+ sourceType: "module",
646
+ plugins: ["jsx", "typescript"],
647
+ });
648
+ let nextSource: string | null = null;
649
+ const visit = (value: unknown) => {
650
+ if (nextSource || !value || typeof value !== "object") return;
651
+ if (Array.isArray(value)) {
652
+ for (const child of value) visit(child);
653
+ return;
654
+ }
655
+ const node = value as {
656
+ type?: string;
657
+ loc?: { start?: { line?: number; column?: number } };
658
+ openingElement?: {
659
+ name?: { name?: string };
660
+ attributes?: Array<{
661
+ type?: string;
662
+ name?: { name?: string };
663
+ start?: number | null;
664
+ end?: number | null;
665
+ }>;
666
+ };
667
+ [key: string]: unknown;
668
+ };
669
+ if (
670
+ node.type === "JSXElement" &&
671
+ node.loc?.start?.line === target.line &&
672
+ node.loc.start.column === target.column
673
+ ) {
674
+ if (node.openingElement?.name?.name !== "video") return;
675
+ const src = node.openingElement.attributes?.find(
676
+ (attribute) =>
677
+ attribute.type === "JSXAttribute" && attribute.name?.name === "src",
678
+ );
679
+ if (
680
+ typeof src?.start !== "number" ||
681
+ typeof src.end !== "number" ||
682
+ src.end <= src.start
683
+ ) {
684
+ return;
685
+ }
686
+ nextSource =
687
+ sourceTsx.slice(0, src.start) +
688
+ `src={${sourceString(`asset://${assetId}`)}}` +
689
+ sourceTsx.slice(src.end);
690
+ return;
691
+ }
692
+ for (const child of Object.values(node)) visit(child);
693
+ };
694
+ visit(ast);
695
+ return nextSource;
696
+ }
697
+
698
+ function isImagePlaceholder(node: ElementSnapshot, sourceTsx: string): boolean {
699
+ if (node.tagName.toLowerCase() === "img") return true;
700
+ const line = sourceTsx.split(/\r?\n/)[node.line - 1];
701
+ if (!line || node.column > line.length) return false;
702
+ return /^<ImagePlaceholder(?=[\s/>]|$)/.test(line.slice(node.column));
703
+ }
704
+
705
+ function cropImageUrl(value: string | undefined): string | null {
706
+ if (!value) return null;
707
+ try {
708
+ const url = new URL(value, window.location.origin);
709
+ return url.protocol === "https:" || url.origin === window.location.origin
710
+ ? url.toString()
711
+ : null;
712
+ } catch {
713
+ // coercion-ok: malformed source URLs cannot provide a safe crop image and are omitted.
714
+ return null;
715
+ }
716
+ }
717
+
718
+ function objectPositionPercent(value: string | undefined): {
719
+ x: number;
720
+ y: number;
721
+ } {
722
+ const tokens = (value ?? "50% 50%").trim().split(/\s+/);
723
+ const read = (token: string | undefined) => {
724
+ if (!token) return 50;
725
+ if (token.endsWith("%")) {
726
+ const parsed = Number.parseFloat(token);
727
+ return Number.isFinite(parsed) ? Math.max(0, Math.min(100, parsed)) : 50;
728
+ }
729
+ if (token === "left" || token === "top") return 0;
730
+ if (token === "right" || token === "bottom") return 100;
731
+ return 50;
732
+ };
733
+ return {
734
+ x: read(tokens[0]),
735
+ y: read(tokens[1] ?? "center"),
736
+ };
737
+ }
738
+
739
+ function SlideThumbnail({
740
+ deckId,
741
+ slide,
742
+ slideIndex,
743
+ selected,
744
+ dragDisabled,
745
+ onSelect,
746
+ onNavigate,
747
+ }: {
748
+ deckId: string;
749
+ slide: SlideSummary;
750
+ slideIndex: number;
751
+ selected: boolean;
752
+ dragDisabled: boolean;
753
+ onSelect: () => void;
754
+ onNavigate: (direction: -1 | 1) => void;
755
+ }) {
756
+ const t = useT();
757
+ const {
758
+ attributes,
759
+ isDragging,
760
+ listeners,
761
+ setNodeRef,
762
+ transform,
763
+ transition,
764
+ } = useSortable({ id: slide.id, disabled: dragDisabled });
765
+ const frameRef = useRef<HTMLDivElement>(null);
766
+ const [visible, setVisible] = useState(false);
767
+ const render = useActionQuery(
768
+ "get-slide-render",
769
+ { deckId, slideId: slide.id },
770
+ { enabled: visible },
771
+ );
772
+
773
+ useEffect(() => {
774
+ const element = frameRef.current;
775
+ if (!element) return;
776
+ const observer = new IntersectionObserver(
777
+ (entries) => setVisible(entries.some((entry) => entry.isIntersecting)),
778
+ { rootMargin: "180px" },
779
+ );
780
+ observer.observe(element);
781
+ return () => observer.disconnect();
782
+ }, []);
783
+
784
+ return (
785
+ <Button
786
+ asChild
787
+ variant="ghost"
788
+ size="sm"
789
+ className={`group grid h-auto w-full grid-cols-[28px_minmax(0,1fr)] items-start gap-2 rounded-md p-2 text-start font-normal transition-colors active:scale-100 ${selected ? "bg-accent text-accent-foreground" : "hover:bg-accent/50"}`}
790
+ >
791
+ <button
792
+ ref={setNodeRef}
793
+ type="button"
794
+ onClick={onSelect}
795
+ {...attributes}
796
+ {...listeners}
797
+ onKeyDown={(event) => {
798
+ listeners?.onKeyDown?.(event);
799
+ if (
800
+ event.defaultPrevented ||
801
+ isDragging ||
802
+ event.altKey ||
803
+ event.ctrlKey ||
804
+ event.metaKey ||
805
+ event.shiftKey
806
+ ) {
807
+ return;
808
+ }
809
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
810
+ event.preventDefault();
811
+ event.stopPropagation();
812
+ onNavigate(event.key === "ArrowUp" ? -1 : 1);
813
+ }
814
+ }}
815
+ data-slides-2-thumbnail-index={slideIndex}
816
+ aria-label={t("editorSidebar.selectSlide", {
817
+ number: slide.slideNumber,
818
+ })}
819
+ aria-current={selected ? "true" : undefined}
820
+ style={{
821
+ transform: CSS.Transform.toString(transform),
822
+ transition,
823
+ touchAction: dragDisabled ? undefined : "none",
824
+ opacity: isDragging ? 0.6 : undefined,
825
+ }}
826
+ >
827
+ <span className="pt-1 text-xs tabular-nums text-muted-foreground">
828
+ {slide.slideNumber}
829
+ </span>
830
+ <span className="min-w-0">
831
+ <span
832
+ ref={frameRef}
833
+ className={
834
+ /* guard:allow-raw-color — thumbnail previews render the fixed white slide canvas. */ `relative block aspect-video overflow-hidden rounded border bg-white ${selected ? "border-primary" : "border-border"}`
835
+ }
836
+ >
837
+ {visible && render.data ? (
838
+ <Slides2Canvas scale={0.085} flat blockInteractions>
839
+ <SandboxedSlide
840
+ artifact={render.data}
841
+ title={t("slides2Presenter.slideLabel", {
842
+ index: slide.slideNumber,
843
+ })}
844
+ onNodes={() => {}}
845
+ onPointer={() => {}}
846
+ />
847
+ </Slides2Canvas>
848
+ ) : (
849
+ <span className="absolute inset-0 flex items-center justify-center bg-muted/40 px-3 text-center text-[10px] text-muted-foreground">
850
+ {slide.textPreview || ""}
851
+ </span>
852
+ )}
853
+ </span>
854
+ {slide.textPreview ? (
855
+ <span className="mt-1 block truncate text-[11px] text-muted-foreground">
856
+ {slide.textPreview}
857
+ </span>
858
+ ) : null}
859
+ </span>
860
+ </button>
861
+ </Button>
862
+ );
863
+ }
864
+
865
+ function SlideOverviewThumbnail({
866
+ deckId,
867
+ slide,
868
+ index,
869
+ selected,
870
+ focused,
871
+ total,
872
+ onSelect,
873
+ onFocus,
874
+ }: {
875
+ deckId: string;
876
+ slide: SlideSummary;
877
+ index: number;
878
+ selected: boolean;
879
+ focused: boolean;
880
+ total: number;
881
+ onSelect: () => void;
882
+ onFocus: (index: number) => void;
883
+ }) {
884
+ const t = useT();
885
+ const frameRef = useRef<HTMLDivElement>(null);
886
+ const [visible, setVisible] = useState(false);
887
+ const render = useActionQuery(
888
+ "get-slide-render",
889
+ { deckId, slideId: slide.id },
890
+ { enabled: visible },
891
+ );
892
+
893
+ useEffect(() => {
894
+ const element = frameRef.current;
895
+ if (!element) return;
896
+ const observer = new IntersectionObserver(
897
+ (entries) => setVisible(entries.some((entry) => entry.isIntersecting)),
898
+ { rootMargin: "180px" },
899
+ );
900
+ observer.observe(element);
901
+ return () => observer.disconnect();
902
+ }, []);
903
+
904
+ return (
905
+ <Button
906
+ asChild
907
+ variant="ghost"
908
+ size="sm"
909
+ className={`group flex h-[216px] w-full min-w-0 flex-col gap-1.5 rounded-md p-1 text-start font-normal outline-none transition-colors active:scale-100 hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-0 ${focused ? "bg-accent ring-2 ring-primary" : selected ? "bg-accent" : ""}`}
910
+ >
911
+ <button
912
+ type="button"
913
+ autoFocus={selected}
914
+ data-slide-overview-index={index}
915
+ data-slide-overview-active={selected ? "true" : undefined}
916
+ aria-label={t("slides2Presenter.slideLabel", {
917
+ index: slide.slideNumber,
918
+ })}
919
+ aria-current={selected ? "true" : undefined}
920
+ onFocus={() => onFocus(index)}
921
+ onClick={onSelect}
922
+ >
923
+ <span
924
+ ref={frameRef}
925
+ className="pointer-events-none relative block aspect-video w-full overflow-hidden rounded border border-border bg-muted"
926
+ >
927
+ {visible && render.data ? (
928
+ <Slides2Canvas flat>
929
+ <SandboxedSlide
930
+ artifact={render.data}
931
+ title={t("slides2Presenter.slideLabel", {
932
+ index: slide.slideNumber,
933
+ })}
934
+ onNodes={() => {}}
935
+ onPointer={() => {}}
936
+ />
937
+ </Slides2Canvas>
938
+ ) : (
939
+ <span className="absolute inset-0 grid place-items-center bg-muted/40 text-2xl font-semibold text-muted-foreground">
940
+ {slide.slideNumber}
941
+ </span>
942
+ )}
943
+ {selected ? (
944
+ <span
945
+ aria-hidden="true"
946
+ className="absolute right-2 top-2 rounded-sm bg-destructive px-2 py-0.5 text-[10px] leading-4 font-semibold tracking-wide text-destructive-foreground"
947
+ >
948
+ {t("slides2Editor.now")}
949
+ </span>
950
+ ) : null}
951
+ </span>
952
+ <span className="px-1 text-xs text-muted-foreground">
953
+ {t("slides2Presenter.position", {
954
+ index: slide.slideNumber,
955
+ total,
956
+ })}
957
+ </span>
958
+ </button>
959
+ </Button>
960
+ );
961
+ }
962
+
963
+ function handlePoint(rect: Rect, handle: ResizeHandle): Point {
964
+ return {
965
+ x: handle.includes("w")
966
+ ? rect.x
967
+ : handle.includes("e")
968
+ ? rect.x + rect.width
969
+ : rect.x + rect.width / 2,
970
+ y: handle.includes("n")
971
+ ? rect.y
972
+ : handle.includes("s")
973
+ ? rect.y + rect.height
974
+ : rect.y + rect.height / 2,
975
+ };
976
+ }
977
+
978
+ function applyTranslate(
979
+ node: ElementSnapshot,
980
+ dx: number,
981
+ dy: number,
982
+ ): SourceEdit {
983
+ return editFor(node, [
984
+ {
985
+ kind: "set-style",
986
+ key: "translate",
987
+ value: localTranslateForBounds(
988
+ node,
989
+ node.bounds.x + dx,
990
+ node.bounds.y + dy,
991
+ ),
992
+ ...(node.text ? { prevText: node.text } : {}),
993
+ },
994
+ ]);
995
+ }
996
+
997
+ export function Slides2Editor({
998
+ deckId,
999
+ title,
1000
+ slides,
1001
+ activeIndex,
1002
+ source,
1003
+ notes,
1004
+ artifact,
1005
+ designTokens,
1006
+ savingDesignTokens,
1007
+ savingNotes,
1008
+ loading,
1009
+ loadingError,
1010
+ saving,
1011
+ sourceConflict,
1012
+ structuralSaving,
1013
+ structuralError,
1014
+ canEdit: hasEditPermission,
1015
+ canComment,
1016
+ backHref,
1017
+ presentHref,
1018
+ aspectRatio,
1019
+ zoom: suppliedZoom,
1020
+ onZoomChange,
1021
+ slideRailWidth: suppliedSlideRailWidth,
1022
+ onSlideRailWidthChange,
1023
+ activePanel: suppliedActivePanel,
1024
+ previousPanel: suppliedPreviousPanel,
1025
+ onActivePanelChange,
1026
+ inspectorOpen: suppliedInspectorOpen,
1027
+ onInspectorOpenChange,
1028
+ inspectorBeforePreview: suppliedInspectorBeforePreview,
1029
+ onInspectorBeforePreviewChange,
1030
+ inspectorToggledInPreview: suppliedInspectorToggledInPreview,
1031
+ onInspectorToggledInPreviewChange,
1032
+ overviewOpen: suppliedOverviewOpen,
1033
+ onOverviewOpenChange,
1034
+ t: suppliedT,
1035
+ onSelectSlide,
1036
+ onPresent,
1037
+ onOpenPresenter,
1038
+ onSave,
1039
+ onReloadSource,
1040
+ onRestore,
1041
+ onSaveDesignTokens,
1042
+ onSaveNotes,
1043
+ onSelectionChange,
1044
+ editorMode: suppliedEditorMode,
1045
+ onPanelChange,
1046
+ onEditorModeChange,
1047
+ onAddSlide,
1048
+ onDuplicateSlide,
1049
+ onDeleteSlide,
1050
+ onMoveSlide,
1051
+ crossSlideHistory,
1052
+ }: Props) {
1053
+ const defaultT = useT();
1054
+ const t = suppliedT ?? defaultT;
1055
+ const editorCommandKey = appStateKeyForBrowserTab(
1056
+ appStateKey(SLIDE_EDITOR_COMMAND_KEY),
1057
+ TAB_ID,
1058
+ );
1059
+ const editorCommandVersion = useChangeVersion(
1060
+ `app-state:${appStateKey(SLIDE_EDITOR_COMMAND_KEY)}`,
1061
+ );
1062
+ useDbSync({
1063
+ ignoreSource: TAB_ID,
1064
+ pauseWhenHidden: false,
1065
+ });
1066
+ const [localZoom, setLocalZoom] = useState(1);
1067
+ const zoom = suppliedZoom ?? localZoom;
1068
+ const setZoom = useCallback(
1069
+ (update: number | ((value: number) => number)) => {
1070
+ const nextZoom = typeof update === "function" ? update(zoom) : update;
1071
+ if (suppliedZoom === undefined) setLocalZoom(nextZoom);
1072
+ onZoomChange?.(nextZoom);
1073
+ },
1074
+ [onZoomChange, suppliedZoom, zoom],
1075
+ );
1076
+ const [fitScale, setFitScale] = useState(1);
1077
+ const [localSlideRailWidth, setLocalSlideRailWidth] = useState(
1078
+ DEFAULT_SLIDE_RAIL_WIDTH,
1079
+ );
1080
+ const slideRailWidth = suppliedSlideRailWidth ?? localSlideRailWidth;
1081
+ const slideRailWidthRef = useRef(slideRailWidth);
1082
+ slideRailWidthRef.current = slideRailWidth;
1083
+ const slideRailTouchedRef = useRef(false);
1084
+ const slideRailResizeRef = useRef<{
1085
+ pointerId: number;
1086
+ startX: number;
1087
+ startWidth: number;
1088
+ } | null>(null);
1089
+ const slideRailListRef = useRef<HTMLDivElement>(null);
1090
+ const [nodes, setNodes] = useState<ElementSnapshot[]>([]);
1091
+ const [hoveredTarget, setHoveredTarget] = useState<{
1092
+ slideId: string;
1093
+ nodeId: string;
1094
+ } | null>(null);
1095
+ const [textRangeStyleSnapshot, setTextRangeStyleSnapshot] =
1096
+ useState<SlideFrameTextRangeStyle | null>(null);
1097
+ const [selectedTextRange, setSelectedTextRange] =
1098
+ useState<SlideTextRangeSelection | null>(null);
1099
+ const [inlineNode, setInlineNode] = useState<ElementSnapshot | null>(null);
1100
+ const [inlineTextPoint, setInlineTextPoint] = useState<Point | null>(null);
1101
+ const [selectedIds, setSelectedIds] = useState<string[]>([]);
1102
+ const selectedIdsRef = useRef(selectedIds);
1103
+ selectedIdsRef.current = selectedIds;
1104
+ const [gestureSelectionIds, setGestureSelectionIds] = useState<
1105
+ string[] | null
1106
+ >(null);
1107
+ const [guideLines, setGuideLines] = useState<
1108
+ ReturnType<typeof snapMove>["guides"]
1109
+ >([]);
1110
+ const [smartGuidesEnabled, setSmartGuidesEnabled] = useState(true);
1111
+ const [alignToSlide, setAlignToSlide] = useState(false);
1112
+ const [marquee, setMarquee] = useState<Rect | null>(null);
1113
+ const [editBatches, setEditBatches] = useState<EditBatch[]>([]);
1114
+ const [historyIndex, setHistoryIndex] = useState(0);
1115
+ const currentEditBatches = crossSlideHistory?.editBatches ?? editBatches;
1116
+ const currentHistoryIndex = crossSlideHistory?.historyIndex ?? historyIndex;
1117
+ const [committedSource, setCommittedSource] = useState(() => ({
1118
+ sourceTsx: source.sourceTsx,
1119
+ revision: source.revision,
1120
+ sourceHash: source.sourceHash,
1121
+ }));
1122
+ const committedSourceRef = useRef(committedSource);
1123
+ const [committedHistory, setCommittedHistory] = useState<string[]>([
1124
+ source.sourceTsx,
1125
+ ]);
1126
+ const committedHistoryRef = useRef(committedHistory);
1127
+ const [committedHistoryIndex, setCommittedHistoryIndex] = useState(0);
1128
+ const committedHistoryIndexRef = useRef(0);
1129
+ const [historyVersion, setHistoryVersion] = useState(0);
1130
+ const historyVersionRef = useRef(0);
1131
+ const editorSessionIdRef = useRef<string | null>(null);
1132
+ if (editorSessionIdRef.current === null) {
1133
+ editorSessionIdRef.current = nanoid();
1134
+ }
1135
+ const [pendingSourceSelection, setPendingSourceSelection] = useState<{
1136
+ revision: number;
1137
+ selection: SourceSelection;
1138
+ } | null>(null);
1139
+ const appliedHistorySelectionRef = useRef<string | null>(null);
1140
+ const processingHistoryRestoreRef = useRef<string | null>(null);
1141
+ const [localActivePanel, setLocalActivePanel] =
1142
+ useState<Slides2InspectorPanel>("format");
1143
+ const activePanel = suppliedActivePanel ?? localActivePanel;
1144
+ const setActivePanel = useCallback(
1145
+ (
1146
+ update:
1147
+ | Slides2InspectorPanel
1148
+ | ((panel: Slides2InspectorPanel) => Slides2InspectorPanel),
1149
+ ) => {
1150
+ const nextPanel =
1151
+ typeof update === "function" ? update(activePanel) : update;
1152
+ if (suppliedActivePanel === undefined) setLocalActivePanel(nextPanel);
1153
+ onActivePanelChange?.(nextPanel);
1154
+ },
1155
+ [activePanel, onActivePanelChange, suppliedActivePanel],
1156
+ );
1157
+ const [localInspectorOpen, setLocalInspectorOpen] = useState(
1158
+ suppliedEditorMode !== "preview",
1159
+ );
1160
+ const inspectorOpen = suppliedInspectorOpen ?? localInspectorOpen;
1161
+ const setInspectorOpen = useCallback(
1162
+ (update: boolean | ((open: boolean) => boolean)) => {
1163
+ const nextOpen =
1164
+ typeof update === "function" ? update(inspectorOpen) : update;
1165
+ if (suppliedInspectorOpen === undefined) setLocalInspectorOpen(nextOpen);
1166
+ onInspectorOpenChange?.(nextOpen);
1167
+ },
1168
+ [inspectorOpen, onInspectorOpenChange, suppliedInspectorOpen],
1169
+ );
1170
+ const [localEditorMode, setLocalEditorMode] =
1171
+ useState<Slides2EditorMode>("edit");
1172
+ const previewMode = (suppliedEditorMode ?? localEditorMode) === "preview";
1173
+ const previewModeRef = useRef(previewMode);
1174
+ previewModeRef.current = previewMode;
1175
+ const [previewStepState, setPreviewStepState] = useState<PreviewStepState>({
1176
+ artifactKey: null,
1177
+ stepCount: null,
1178
+ revealedSteps: 0,
1179
+ });
1180
+ const previewStepStateRef = useRef(previewStepState);
1181
+ previewStepStateRef.current = previewStepState;
1182
+ const previewWheelRef = useRef({
1183
+ accumulated: 0,
1184
+ lastAt: 0,
1185
+ lastNavigationAt: 0,
1186
+ });
1187
+ const inspectorBeforePreviewRef = useRef<boolean | null>(
1188
+ suppliedInspectorBeforePreview ?? null,
1189
+ );
1190
+ const inspectorToggledInPreviewRef = useRef(
1191
+ suppliedInspectorToggledInPreview ?? false,
1192
+ );
1193
+ const previewArtifactKey = artifact
1194
+ ? `${artifact.deckId}:${artifact.slideId}:${artifact.revision}:${artifact.sourceHash}`
1195
+ : null;
1196
+ const previousPanelRef = useRef<Slides2InspectorPanel>(
1197
+ suppliedPreviousPanel ??
1198
+ (suppliedActivePanel === "design"
1199
+ ? "format"
1200
+ : (suppliedActivePanel ?? "format")),
1201
+ );
1202
+ useEffect(() => {
1203
+ if (activePanel !== "design") previousPanelRef.current = activePanel;
1204
+ }, [activePanel]);
1205
+ const toggleDesignPanel = useCallback(() => {
1206
+ setActivePanel((panel) =>
1207
+ panel === "design" ? previousPanelRef.current : "design",
1208
+ );
1209
+ }, [setActivePanel]);
1210
+ const toggleInspector = useCallback(() => {
1211
+ if (previewModeRef.current) {
1212
+ inspectorToggledInPreviewRef.current = true;
1213
+ onInspectorToggledInPreviewChange?.(true);
1214
+ }
1215
+ setInspectorOpen((open) => !open);
1216
+ }, [onInspectorToggledInPreviewChange, setInspectorOpen]);
1217
+ const [saveError, setSaveError] = useState<string | null>(null);
1218
+ const [reloadingSource, setReloadingSource] = useState(false);
1219
+ const pendingSourceRestore =
1220
+ crossSlideHistory?.restoreRequest?.deckId === deckId;
1221
+ const canEdit = hasEditPermission && !sourceConflict && !pendingSourceRestore;
1222
+ const [notesDraft, setNotesDraft] = useState(notes);
1223
+ const [assetBrowserOpen, setAssetBrowserOpen] = useState(false);
1224
+ const [imageCropOpen, setImageCropOpen] = useState(false);
1225
+ const [commandMenuOpen, setCommandMenuOpen] = useState(false);
1226
+ const [localOverviewOpen, setLocalOverviewOpen] = useState(false);
1227
+ const overviewOpen = suppliedOverviewOpen ?? localOverviewOpen;
1228
+ const setOverviewOpen = useCallback(
1229
+ (update: boolean | ((open: boolean) => boolean)) => {
1230
+ const nextOpen =
1231
+ typeof update === "function" ? update(overviewOpen) : update;
1232
+ if (suppliedOverviewOpen === undefined) setLocalOverviewOpen(nextOpen);
1233
+ onOverviewOpenChange?.(nextOpen);
1234
+ },
1235
+ [onOverviewOpenChange, overviewOpen, suppliedOverviewOpen],
1236
+ );
1237
+ const [focusedOverviewIndex, setFocusedOverviewIndex] = useState(activeIndex);
1238
+ const [commentMode, setCommentMode] = useState(false);
1239
+ const [commentDraftAnchor, setCommentDraftAnchor] =
1240
+ useState<SlideCommentAnchor | null>(null);
1241
+ const exportMenuRef = useRef<Slides2ExportMenuHandle>(null);
1242
+ const controllerRef = useRef<SlideFrameController | null>(null);
1243
+ const stageRef = useRef<HTMLDivElement>(null);
1244
+ const overviewGridRef = useRef<HTMLDivElement>(null);
1245
+ const dragRef = useRef<DragState | null>(null);
1246
+ const commentGestureRef = useRef<{
1247
+ pointerId: number;
1248
+ start: Point;
1249
+ moved: boolean;
1250
+ target: ElementSnapshot | null;
1251
+ } | null>(null);
1252
+ const saveRef = useRef<() => Promise<boolean>>(async () => false);
1253
+ const editorCommandHandlerRef = useRef<
1254
+ (operation: SlideEditorCommand["operation"]) => Promise<boolean>
1255
+ >(async () => false);
1256
+ const editorCommandPollRetryAttemptsRef = useRef(0);
1257
+ const editorCommandPollActiveRef = useRef(false);
1258
+ const editorCommandPollRequestedRef = useRef(false);
1259
+ const editorCommandPollRef = useRef<(() => Promise<void>) | null>(null);
1260
+ const bumpHistoryVersion = useCallback(() => {
1261
+ const nextVersion = historyVersionRef.current + 1;
1262
+ historyVersionRef.current = nextVersion;
1263
+ setHistoryVersion(nextVersion);
1264
+ }, []);
1265
+ const dndSensors = useSensors(
1266
+ useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
1267
+ useSensor(KeyboardSensor, {
1268
+ coordinateGetter: sortableKeyboardCoordinates,
1269
+ }),
1270
+ );
1271
+
1272
+ useEffect(() => {
1273
+ if (overviewOpen) setFocusedOverviewIndex(activeIndex);
1274
+ }, [activeIndex, overviewOpen]);
1275
+
1276
+ useEffect(() => {
1277
+ if (!overviewOpen) return;
1278
+ const button = overviewGridRef.current?.querySelector<HTMLButtonElement>(
1279
+ `[data-slide-overview-index="${focusedOverviewIndex}"]`,
1280
+ );
1281
+ button?.focus();
1282
+ button?.scrollIntoView({ block: "nearest", behavior: "auto" });
1283
+ }, [focusedOverviewIndex, overviewOpen]);
1284
+
1285
+ useEffect(() => {
1286
+ setTextRangeStyleSnapshot(null);
1287
+ setSelectedTextRange(null);
1288
+ }, [source.id, source.revision, source.sourceHash]);
1289
+
1290
+ useEffect(() => {
1291
+ if (suppliedSlideRailWidth !== undefined) return;
1292
+ let cancelled = false;
1293
+ void readClientAppState<unknown>(SLIDE_RAIL_WIDTH_STATE_KEY)
1294
+ .then((savedState) => {
1295
+ if (cancelled || slideRailTouchedRef.current) return;
1296
+ if (savedState === null) return;
1297
+ const savedWidth = readSlideRailWidth(savedState);
1298
+ if (savedWidth === null) {
1299
+ console.error("The saved slide rail width preference is invalid.");
1300
+ return;
1301
+ }
1302
+ slideRailWidthRef.current = savedWidth;
1303
+ setLocalSlideRailWidth(savedWidth);
1304
+ })
1305
+ .catch((error) => {
1306
+ if (!cancelled) {
1307
+ console.error(
1308
+ "Could not read the slide rail width preference.",
1309
+ error,
1310
+ );
1311
+ }
1312
+ });
1313
+ return () => {
1314
+ cancelled = true;
1315
+ };
1316
+ }, [suppliedSlideRailWidth]);
1317
+
1318
+ const updateSlideRailWidth = useCallback(
1319
+ (width: number) => {
1320
+ const nextWidth = clampSlideRailWidth(width);
1321
+ slideRailTouchedRef.current = true;
1322
+ slideRailWidthRef.current = nextWidth;
1323
+ if (suppliedSlideRailWidth === undefined)
1324
+ setLocalSlideRailWidth(nextWidth);
1325
+ onSlideRailWidthChange?.(nextWidth);
1326
+ return nextWidth;
1327
+ },
1328
+ [onSlideRailWidthChange, suppliedSlideRailWidth],
1329
+ );
1330
+
1331
+ const persistSlideRailWidth = useCallback((width: number) => {
1332
+ void writeClientAppState(
1333
+ SLIDE_RAIL_WIDTH_STATE_KEY,
1334
+ { width },
1335
+ { keepalive: true, requestSource: TAB_ID },
1336
+ ).catch((error) => {
1337
+ console.error("Could not save the slide rail width preference.", error);
1338
+ });
1339
+ }, []);
1340
+
1341
+ const handleSlideRailResizeStart = useCallback(
1342
+ (event: ReactPointerEvent<HTMLDivElement>) => {
1343
+ if (event.button !== 0) return;
1344
+ event.preventDefault();
1345
+ slideRailTouchedRef.current = true;
1346
+ slideRailResizeRef.current = {
1347
+ pointerId: event.pointerId,
1348
+ startX: event.clientX,
1349
+ startWidth: slideRailWidthRef.current,
1350
+ };
1351
+ event.currentTarget.setPointerCapture(event.pointerId);
1352
+ },
1353
+ [],
1354
+ );
1355
+
1356
+ const handleSlideRailResizeMove = useCallback(
1357
+ (event: ReactPointerEvent<HTMLDivElement>) => {
1358
+ const resize = slideRailResizeRef.current;
1359
+ if (!resize || resize.pointerId !== event.pointerId) return;
1360
+ updateSlideRailWidth(resize.startWidth + event.clientX - resize.startX);
1361
+ },
1362
+ [updateSlideRailWidth],
1363
+ );
1364
+
1365
+ const finishSlideRailResize = useCallback(
1366
+ (event: ReactPointerEvent<HTMLDivElement>) => {
1367
+ const resize = slideRailResizeRef.current;
1368
+ if (!resize || resize.pointerId !== event.pointerId) return;
1369
+ slideRailResizeRef.current = null;
1370
+ const width = slideRailWidthRef.current;
1371
+ if (width !== resize.startWidth) persistSlideRailWidth(width);
1372
+ },
1373
+ [persistSlideRailWidth],
1374
+ );
1375
+
1376
+ const handleSlideRailResizeKeyDown = useCallback(
1377
+ (event: ReactKeyboardEvent<HTMLDivElement>) => {
1378
+ if (
1379
+ ![
1380
+ "ArrowLeft",
1381
+ "ArrowRight",
1382
+ "ArrowUp",
1383
+ "ArrowDown",
1384
+ "Home",
1385
+ "End",
1386
+ ].includes(event.key)
1387
+ ) {
1388
+ return;
1389
+ }
1390
+ event.stopPropagation();
1391
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
1392
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
1393
+ event.preventDefault();
1394
+ return;
1395
+ }
1396
+ const step = event.shiftKey ? 32 : 8;
1397
+ let nextWidth: number | null = null;
1398
+ if (event.key === "ArrowLeft") {
1399
+ nextWidth = slideRailWidthRef.current - step;
1400
+ } else if (event.key === "ArrowRight") {
1401
+ nextWidth = slideRailWidthRef.current + step;
1402
+ } else if (event.key === "Home") {
1403
+ nextWidth = MIN_SLIDE_RAIL_WIDTH;
1404
+ } else if (event.key === "End") {
1405
+ nextWidth = MAX_SLIDE_RAIL_WIDTH;
1406
+ }
1407
+ if (nextWidth === null) return;
1408
+ event.preventDefault();
1409
+ event.stopPropagation();
1410
+ const previousWidth = slideRailWidthRef.current;
1411
+ const width = updateSlideRailWidth(nextWidth);
1412
+ if (width !== previousWidth) persistSlideRailWidth(width);
1413
+ },
1414
+ [persistSlideRailWidth, updateSlideRailWidth],
1415
+ );
1416
+
1417
+ const selected = useMemo(
1418
+ () =>
1419
+ selectedIds.flatMap((id) => nodes.filter((node) => node.nodeId === id)),
1420
+ [nodes, selectedIds],
1421
+ );
1422
+ const overlaySelected = useMemo(
1423
+ () =>
1424
+ (gestureSelectionIds ?? selectedIds).flatMap((id) =>
1425
+ nodes.filter((node) => node.nodeId === id),
1426
+ ),
1427
+ [gestureSelectionIds, nodes, selectedIds],
1428
+ );
1429
+ const distinctSelected = useMemo(() => uniqueByLocator(selected), [selected]);
1430
+ const inspectSelectedTextRange = useCallback(
1431
+ (range: { start: number; end: number; expectedText: string } | null) => {
1432
+ if (!range) {
1433
+ setSelectedTextRange(null);
1434
+ setTextRangeStyleSnapshot(null);
1435
+ return;
1436
+ }
1437
+ const target = distinctSelected.length === 1 ? distinctSelected[0] : null;
1438
+ if (
1439
+ !target ||
1440
+ range.expectedText.length > MAX_SLIDE_TEXT_RANGE_EXPECTED_TEXT_LENGTH ||
1441
+ !Number.isInteger(range.start) ||
1442
+ !Number.isInteger(range.end) ||
1443
+ range.start < 0 ||
1444
+ range.end <= range.start ||
1445
+ range.end > range.expectedText.length
1446
+ ) {
1447
+ setSelectedTextRange(null);
1448
+ setTextRangeStyleSnapshot(null);
1449
+ return;
1450
+ }
1451
+ const nextRange = {
1452
+ slideId: source.id,
1453
+ sourceLine: target.line,
1454
+ sourceColumn: target.column,
1455
+ sourceRevision: source.revision,
1456
+ sourceHash: source.sourceHash,
1457
+ ...range,
1458
+ };
1459
+ if (
1460
+ !currentSlideTextRangeSelection(
1461
+ nextRange,
1462
+ {
1463
+ slideId: source.id,
1464
+ revision: source.revision,
1465
+ sourceHash: source.sourceHash,
1466
+ },
1467
+ { line: target.line, column: target.column },
1468
+ )
1469
+ ) {
1470
+ setSelectedTextRange(null);
1471
+ setTextRangeStyleSnapshot(null);
1472
+ return;
1473
+ }
1474
+ setSelectedTextRange(nextRange);
1475
+ controllerRef.current?.send({
1476
+ type: "inspect-text-range",
1477
+ target: {
1478
+ line: target.line,
1479
+ column: target.column,
1480
+ nodeId: target.nodeId,
1481
+ },
1482
+ ...range,
1483
+ });
1484
+ },
1485
+ [distinctSelected, source.id, source.revision, source.sourceHash],
1486
+ );
1487
+ const selectedParentNode = useMemo(() => {
1488
+ if (distinctSelected.length !== 1) return null;
1489
+ const parent = getParentSourceSelection(
1490
+ committedSource.sourceTsx,
1491
+ distinctSelected[0]!,
1492
+ );
1493
+ return parent
1494
+ ? (nodes.find(
1495
+ (node) => node.line === parent.line && node.column === parent.column,
1496
+ ) ?? null)
1497
+ : null;
1498
+ }, [committedSource.sourceTsx, distinctSelected, nodes]);
1499
+ const selectedImage =
1500
+ distinctSelected.length === 1 &&
1501
+ distinctSelected[0]?.tagName.toLowerCase() === "img"
1502
+ ? distinctSelected[0]
1503
+ : null;
1504
+ const selectedImageAssetId = useMemo(
1505
+ () =>
1506
+ selectedImage
1507
+ ? getSelectedAssetId(source.sourceTsx, selectedImage)
1508
+ : null,
1509
+ [selectedImage, source.sourceTsx],
1510
+ );
1511
+ const imageAssetsQuery = useActionQuery(
1512
+ "list-assets",
1513
+ { scope: "deck", deckId },
1514
+ { enabled: Boolean(selectedImageAssetId) },
1515
+ );
1516
+ const selectedImageAsset = imageAssetsQuery.data?.find(
1517
+ (asset) => asset.id === selectedImageAssetId,
1518
+ );
1519
+ const selectedImageSrc = cropImageUrl(selectedImageAsset?.url);
1520
+ const selectionBounds = useMemo(
1521
+ () => unionRects(selected.map((node) => node.bounds)),
1522
+ [selected],
1523
+ );
1524
+ const overlaySelectionBounds = useMemo(
1525
+ () => unionRects(overlaySelected.map((node) => node.bounds)),
1526
+ [overlaySelected],
1527
+ );
1528
+ const hasUnsavedEdits = currentHistoryIndex > 0;
1529
+ const hasPendingUndo = crossSlideHistory
1530
+ ? crossSlideHistory.canUndo
1531
+ : currentHistoryIndex > 0;
1532
+ const hasPendingRedo = crossSlideHistory
1533
+ ? crossSlideHistory.canRedo
1534
+ : currentHistoryIndex < currentEditBatches.length;
1535
+ const canUndo = crossSlideHistory
1536
+ ? crossSlideHistory.canUndo
1537
+ : hasPendingUndo || (!hasUnsavedEdits && committedHistoryIndex > 0);
1538
+ const canRedo = crossSlideHistory
1539
+ ? crossSlideHistory.canRedo
1540
+ : hasPendingRedo ||
1541
+ (!hasUnsavedEdits && committedHistoryIndex < committedHistory.length - 1);
1542
+ const activeEdits = useMemo(
1543
+ () => currentEditBatches.slice(0, currentHistoryIndex).flat(),
1544
+ [currentEditBatches, currentHistoryIndex],
1545
+ );
1546
+ const restoreActivePreview = useCallback(() => {
1547
+ const controller = controllerRef.current;
1548
+ if (!controller) return;
1549
+ const patches = getPreviewPatches(activeEdits);
1550
+ if (patches.length) controller.send({ type: "preview", patches });
1551
+ else controller.send({ type: "clear-preview" });
1552
+ }, [activeEdits]);
1553
+ const activeSlide = slides[activeIndex];
1554
+ const canEditSelectedText =
1555
+ canEdit &&
1556
+ !commentMode &&
1557
+ !inlineNode &&
1558
+ !commandMenuOpen &&
1559
+ !assetBrowserOpen &&
1560
+ !imageCropOpen &&
1561
+ !overviewOpen &&
1562
+ distinctSelected.length === 1 &&
1563
+ Boolean(distinctSelected[0]?.text.trim());
1564
+ const assetTarget =
1565
+ distinctSelected.length === 1 ? distinctSelected[0] : null;
1566
+ const hasImageTarget =
1567
+ assetTarget !== null && isImagePlaceholder(assetTarget, source.sourceTsx);
1568
+
1569
+ const editorStatus = useMemo(
1570
+ () =>
1571
+ slideEditorStatusSchema.parse({
1572
+ protocolVersion: 1,
1573
+ deckId,
1574
+ slideId: source.id,
1575
+ editorSessionId: editorSessionIdRef.current,
1576
+ historyVersion,
1577
+ sourceRevision: committedSource.revision,
1578
+ sourceHash: committedSource.sourceHash,
1579
+ hasPendingEdits: hasUnsavedEdits,
1580
+ canUndo:
1581
+ canUndo &&
1582
+ canEdit &&
1583
+ !saving &&
1584
+ !structuralSaving &&
1585
+ !reloadingSource,
1586
+ canRedo:
1587
+ canRedo &&
1588
+ canEdit &&
1589
+ !saving &&
1590
+ !structuralSaving &&
1591
+ !reloadingSource,
1592
+ canSave:
1593
+ hasUnsavedEdits &&
1594
+ canEdit &&
1595
+ !saving &&
1596
+ !structuralSaving &&
1597
+ !reloadingSource,
1598
+ }),
1599
+ [
1600
+ canEdit,
1601
+ canRedo,
1602
+ canUndo,
1603
+ committedSource.revision,
1604
+ committedSource.sourceHash,
1605
+ deckId,
1606
+ hasUnsavedEdits,
1607
+ historyVersion,
1608
+ reloadingSource,
1609
+ saving,
1610
+ source.id,
1611
+ structuralSaving,
1612
+ ],
1613
+ );
1614
+ const editorStatusRef = useRef(editorStatus);
1615
+ editorStatusRef.current = editorStatus;
1616
+ useEffect(() => {
1617
+ const key = appStateKeyForBrowserTab(
1618
+ appStateKey(SLIDE_EDITOR_STATUS_KEY),
1619
+ TAB_ID,
1620
+ );
1621
+ void writeClientAppState(key, editorStatus, {
1622
+ requestSource: TAB_ID,
1623
+ }).catch((error) =>
1624
+ console.error("Could not update the slide editor status.", error),
1625
+ );
1626
+ }, [editorStatus]);
1627
+
1628
+ const selectParent = useCallback(() => {
1629
+ if (selectedParentNode) setSelectedIds([selectedParentNode.nodeId]);
1630
+ }, [selectedParentNode]);
1631
+
1632
+ const recordCommittedSource = useCallback(
1633
+ (
1634
+ nextSource: Pick<SlideSource, "sourceTsx" | "revision" | "sourceHash">,
1635
+ addToHistory = true,
1636
+ ) => {
1637
+ bumpHistoryVersion();
1638
+ const previous = committedSourceRef.current;
1639
+ const next = { ...previous, ...nextSource };
1640
+ committedSourceRef.current = next;
1641
+ setCommittedSource(next);
1642
+ if (addToHistory) {
1643
+ if (crossSlideHistory) {
1644
+ crossSlideHistory.commit({
1645
+ slideId: source.id,
1646
+ beforeSourceTsx: previous.sourceTsx,
1647
+ beforeSourceHash: previous.sourceHash,
1648
+ afterSourceTsx: next.sourceTsx,
1649
+ afterSourceHash: next.sourceHash,
1650
+ selection: null,
1651
+ });
1652
+ } else {
1653
+ const history = [
1654
+ ...committedHistoryRef.current.slice(
1655
+ 0,
1656
+ committedHistoryIndexRef.current + 1,
1657
+ ),
1658
+ next.sourceTsx,
1659
+ ].slice(-EDIT_HISTORY_LIMIT);
1660
+ committedHistoryRef.current = history;
1661
+ committedHistoryIndexRef.current = history.length - 1;
1662
+ setCommittedHistory(history);
1663
+ setCommittedHistoryIndex(history.length - 1);
1664
+ }
1665
+ }
1666
+ },
1667
+ [bumpHistoryVersion, crossSlideHistory, source.id],
1668
+ );
1669
+
1670
+ useEffect(() => {
1671
+ const request = crossSlideHistory?.restoreRequest;
1672
+ if (
1673
+ !request ||
1674
+ request.deckId !== deckId ||
1675
+ request.slideId !== source.id
1676
+ ) {
1677
+ if (!request || request.deckId !== deckId) {
1678
+ processingHistoryRestoreRef.current = null;
1679
+ }
1680
+ return;
1681
+ }
1682
+ if (processingHistoryRestoreRef.current === request.requestId) return;
1683
+ processingHistoryRestoreRef.current = request.requestId;
1684
+
1685
+ const restoreSource = async () => {
1686
+ if (source.sourceHash !== request.expectedSourceHash) {
1687
+ setSaveError(t("editorErrors.slideChanged"));
1688
+ crossSlideHistory?.onSourceRestoreComplete?.(request.requestId, null);
1689
+ return;
1690
+ }
1691
+ bumpHistoryVersion();
1692
+ setSaveError(null);
1693
+ try {
1694
+ const result = await onRestore(request.sourceTsx, {
1695
+ revision: source.revision,
1696
+ sourceHash: source.sourceHash,
1697
+ });
1698
+ recordCommittedSource(result, false);
1699
+ setEditBatches([]);
1700
+ setHistoryIndex(0);
1701
+ selectedIdsRef.current = [];
1702
+ setSelectedIds([]);
1703
+ controllerRef.current?.send({ type: "clear-preview" });
1704
+ crossSlideHistory?.onSourceRestoreComplete?.(request.requestId, {
1705
+ revision: result.revision,
1706
+ sourceHash: result.sourceHash,
1707
+ });
1708
+ } catch (error) {
1709
+ setSaveError(
1710
+ t(getEditorActionErrorTranslationKey(error) ?? "settings.saveFailed"),
1711
+ );
1712
+ crossSlideHistory?.onSourceRestoreComplete?.(request.requestId, null);
1713
+ }
1714
+ };
1715
+
1716
+ void restoreSource();
1717
+ }, [
1718
+ bumpHistoryVersion,
1719
+ crossSlideHistory,
1720
+ deckId,
1721
+ onRestore,
1722
+ recordCommittedSource,
1723
+ source,
1724
+ t,
1725
+ ]);
1726
+
1727
+ const reloadConflictedSource = useCallback(async () => {
1728
+ if (!sourceConflict || reloadingSource) return;
1729
+ setReloadingSource(true);
1730
+ try {
1731
+ const latest = await onReloadSource();
1732
+ bumpHistoryVersion();
1733
+ const committed = {
1734
+ sourceTsx: latest.sourceTsx,
1735
+ revision: latest.revision,
1736
+ sourceHash: latest.sourceHash,
1737
+ };
1738
+ committedSourceRef.current = committed;
1739
+ setCommittedSource(committed);
1740
+ const history = [latest.sourceTsx];
1741
+ committedHistoryRef.current = history;
1742
+ committedHistoryIndexRef.current = 0;
1743
+ setCommittedHistory(history);
1744
+ setCommittedHistoryIndex(0);
1745
+ setEditBatches([]);
1746
+ setHistoryIndex(0);
1747
+ crossSlideHistory?.clear();
1748
+ selectedIdsRef.current = [];
1749
+ setSelectedIds([]);
1750
+ setNodes([]);
1751
+ setTextRangeStyleSnapshot(null);
1752
+ setInlineNode(null);
1753
+ setPendingSourceSelection(null);
1754
+ controllerRef.current?.send({ type: "clear-preview" });
1755
+ setSaveError(null);
1756
+ } catch (error) {
1757
+ setSaveError(
1758
+ t(
1759
+ getEditorActionErrorTranslationKey(error) ??
1760
+ "editorErrors.deckDataUnavailable",
1761
+ ),
1762
+ );
1763
+ } finally {
1764
+ setReloadingSource(false);
1765
+ }
1766
+ }, [
1767
+ bumpHistoryVersion,
1768
+ crossSlideHistory,
1769
+ onReloadSource,
1770
+ reloadingSource,
1771
+ sourceConflict,
1772
+ t,
1773
+ ]);
1774
+
1775
+ useEffect(() => setNotesDraft(notes), [notes]);
1776
+
1777
+ const handleThumbnailNavigate = useCallback(
1778
+ (index: number, direction: -1 | 1) => {
1779
+ const nextIndex = index + direction;
1780
+ if (nextIndex < 0 || nextIndex >= slides.length) return;
1781
+ slideRailListRef.current
1782
+ ?.querySelector<HTMLButtonElement>(
1783
+ `[data-slides-2-thumbnail-index="${nextIndex}"]`,
1784
+ )
1785
+ ?.focus();
1786
+ onSelectSlide(nextIndex);
1787
+ },
1788
+ [onSelectSlide, slides.length],
1789
+ );
1790
+
1791
+ const handleThumbnailDragStart = useCallback(
1792
+ (event: DragStartEvent) => {
1793
+ const index = slides.findIndex((slide) => slide.id === event.active.id);
1794
+ if (index >= 0) onSelectSlide(index);
1795
+ },
1796
+ [onSelectSlide, slides],
1797
+ );
1798
+
1799
+ const handleThumbnailDragEnd = useCallback(
1800
+ (event: DragEndEvent) => {
1801
+ if (!event.over || event.active.id === event.over.id) return;
1802
+ const from = slides.findIndex((slide) => slide.id === event.active.id);
1803
+ const to = slides.findIndex((slide) => slide.id === event.over?.id);
1804
+ if (from >= 0 && to >= 0) onMoveSlide(from, to);
1805
+ },
1806
+ [onMoveSlide, slides],
1807
+ );
1808
+
1809
+ useEffect(() => {
1810
+ if (source.sourceHash === committedSource.sourceHash || hasUnsavedEdits)
1811
+ return;
1812
+ bumpHistoryVersion();
1813
+ const history = [...committedHistoryRef.current, source.sourceTsx].slice(
1814
+ -EDIT_HISTORY_LIMIT,
1815
+ );
1816
+ setCommittedSource({
1817
+ sourceTsx: source.sourceTsx,
1818
+ revision: source.revision,
1819
+ sourceHash: source.sourceHash,
1820
+ });
1821
+ committedSourceRef.current = {
1822
+ sourceTsx: source.sourceTsx,
1823
+ revision: source.revision,
1824
+ sourceHash: source.sourceHash,
1825
+ };
1826
+ committedHistoryRef.current = history;
1827
+ committedHistoryIndexRef.current = history.length - 1;
1828
+ setCommittedHistory(history);
1829
+ setCommittedHistoryIndex(history.length - 1);
1830
+ setEditBatches([]);
1831
+ setHistoryIndex(0);
1832
+ crossSlideHistory?.clear();
1833
+ selectedIdsRef.current = [];
1834
+ setSelectedIds([]);
1835
+ }, [
1836
+ committedHistory,
1837
+ committedSource.sourceHash,
1838
+ hasUnsavedEdits,
1839
+ source.revision,
1840
+ source.sourceHash,
1841
+ source.sourceTsx,
1842
+ bumpHistoryVersion,
1843
+ crossSlideHistory,
1844
+ ]);
1845
+
1846
+ useEffect(() => {
1847
+ const target = distinctSelected.length === 1 ? distinctSelected[0] : null;
1848
+ const textRange = currentSlideTextRangeSelection(
1849
+ selectedTextRange,
1850
+ {
1851
+ slideId: source.id,
1852
+ revision: source.revision,
1853
+ sourceHash: source.sourceHash,
1854
+ },
1855
+ target ? { line: target.line, column: target.column } : null,
1856
+ );
1857
+ onSelectionChange(selected, textRange);
1858
+ }, [
1859
+ distinctSelected,
1860
+ onSelectionChange,
1861
+ selected,
1862
+ selectedTextRange,
1863
+ source.id,
1864
+ source.revision,
1865
+ source.sourceHash,
1866
+ ]);
1867
+
1868
+ useEffect(() => {
1869
+ onPanelChange?.(inspectorOpen ? activePanel : null);
1870
+ }, [activePanel, inspectorOpen, onPanelChange]);
1871
+
1872
+ useEffect(() => {
1873
+ if (!pendingSourceSelection) return;
1874
+ if (artifact?.revision !== pendingSourceSelection.revision) {
1875
+ if (
1876
+ typeof artifact?.revision === "number" &&
1877
+ artifact.revision > pendingSourceSelection.revision
1878
+ ) {
1879
+ setPendingSourceSelection(null);
1880
+ }
1881
+ return;
1882
+ }
1883
+ const target = nodes.find(
1884
+ (node) =>
1885
+ node.line === pendingSourceSelection.selection.line &&
1886
+ node.column === pendingSourceSelection.selection.column,
1887
+ );
1888
+ if (!target) return;
1889
+ selectedIdsRef.current = [target.nodeId];
1890
+ setSelectedIds([target.nodeId]);
1891
+ controllerRef.current?.send({
1892
+ type: "inspect",
1893
+ targets: [
1894
+ { line: target.line, column: target.column, nodeId: target.nodeId },
1895
+ ],
1896
+ });
1897
+ setPendingSourceSelection(null);
1898
+ }, [artifact?.revision, nodes, pendingSourceSelection]);
1899
+
1900
+ useEffect(() => {
1901
+ const request = crossSlideHistory?.selection;
1902
+ if (!request || request.slideId !== source.id) return;
1903
+ if (appliedHistorySelectionRef.current === request.requestId) return;
1904
+ if (
1905
+ request.sourceRevision !== source.revision ||
1906
+ request.sourceHash !== source.sourceHash
1907
+ ) {
1908
+ appliedHistorySelectionRef.current = request.requestId;
1909
+ crossSlideHistory.onSelectionApplied(request.requestId);
1910
+ return;
1911
+ }
1912
+ if (
1913
+ artifact?.revision !== request.sourceRevision ||
1914
+ artifact?.sourceHash !== request.sourceHash
1915
+ ) {
1916
+ return;
1917
+ }
1918
+ const target = nodes.find(
1919
+ (node) => node.line === request.line && node.column === request.column,
1920
+ );
1921
+ if (!target) return;
1922
+ appliedHistorySelectionRef.current = request.requestId;
1923
+ selectedIdsRef.current = [target.nodeId];
1924
+ setSelectedIds([target.nodeId]);
1925
+ setSelectedTextRange(null);
1926
+ controllerRef.current?.send({
1927
+ type: "inspect",
1928
+ targets: [
1929
+ { line: target.line, column: target.column, nodeId: target.nodeId },
1930
+ ],
1931
+ });
1932
+ crossSlideHistory.onSelectionApplied(request.requestId);
1933
+ }, [
1934
+ artifact?.revision,
1935
+ artifact?.sourceHash,
1936
+ crossSlideHistory,
1937
+ nodes,
1938
+ source,
1939
+ ]);
1940
+
1941
+ useEffect(() => {
1942
+ const controller = controllerRef.current;
1943
+ if (!controller) return;
1944
+ const patches = getPreviewPatches(activeEdits);
1945
+ if (patches.length) controller.send({ type: "preview", patches });
1946
+ else controller.send({ type: "clear-preview" });
1947
+ }, [activeEdits, artifact?.sourceHash]);
1948
+
1949
+ const handleDesignTokenPreview = useCallback((tokens: SlideDesignTokens) => {
1950
+ controllerRef.current?.send({ type: "set-design-tokens", tokens });
1951
+ }, []);
1952
+
1953
+ const appendEdits = useCallback(
1954
+ (edits: SourceEdit[]) => {
1955
+ if (!edits.length) return;
1956
+ bumpHistoryVersion();
1957
+ setSaveError(null);
1958
+ if (crossSlideHistory) {
1959
+ crossSlideHistory.append(edits);
1960
+ } else {
1961
+ const bounded = [...editBatches.slice(0, historyIndex), edits].slice(
1962
+ -EDIT_HISTORY_LIMIT,
1963
+ );
1964
+ setEditBatches(bounded);
1965
+ setHistoryIndex(bounded.length);
1966
+ }
1967
+ },
1968
+ [bumpHistoryVersion, crossSlideHistory, editBatches, historyIndex],
1969
+ );
1970
+
1971
+ const applyImageCrop = useCallback(
1972
+ (result: Slides2ImageCropResult) => {
1973
+ const node = selectedImage;
1974
+ if (!node) return;
1975
+ const ops: SourceEditOp[] = imageCropStyleEdits(result).map(
1976
+ ({ key, value }) => ({
1977
+ kind: "set-style" as const,
1978
+ key,
1979
+ value,
1980
+ ...(node.text ? { prevText: node.text } : {}),
1981
+ }),
1982
+ );
1983
+ appendEdits([editFor(node, ops)]);
1984
+ setImageCropOpen(false);
1985
+ },
1986
+ [appendEdits, selectedImage],
1987
+ );
1988
+
1989
+ const inspect = useCallback(
1990
+ (ids: string[]) => {
1991
+ const targets = ids.flatMap((nodeId) => {
1992
+ const node = nodes.find((entry) => entry.nodeId === nodeId);
1993
+ return node ? [{ line: node.line, column: node.column, nodeId }] : [];
1994
+ });
1995
+ if (targets.length)
1996
+ controllerRef.current?.send({ type: "inspect", targets });
1997
+ },
1998
+ [nodes],
1999
+ );
2000
+
2001
+ const openInlineTextEditor = useCallback(
2002
+ (target: ElementSnapshot | null | undefined, point?: Point) => {
2003
+ if (!canEdit || !target?.text.trim()) return;
2004
+ setHoveredTarget(null);
2005
+ const ids = [target.nodeId];
2006
+ selectedIdsRef.current = ids;
2007
+ setSelectedIds(ids);
2008
+ setNodes((current) => [
2009
+ ...current.filter((node) => node.nodeId !== target.nodeId),
2010
+ target,
2011
+ ]);
2012
+ setGuideLines([]);
2013
+ setInlineNode(target);
2014
+ setInlineTextPoint(point ?? null);
2015
+ controllerRef.current?.send({
2016
+ type: "inspect",
2017
+ targets: [
2018
+ { line: target.line, column: target.column, nodeId: target.nodeId },
2019
+ ],
2020
+ });
2021
+ },
2022
+ [canEdit],
2023
+ );
2024
+
2025
+ const handleNodes = useCallback((nextNodes: ElementSnapshot[]) => {
2026
+ setNodes((current) => {
2027
+ const currentById = new Map(current.map((node) => [node.nodeId, node]));
2028
+ const nextById = new Map(nextNodes.map((node) => [node.nodeId, node]));
2029
+ for (const node of nextNodes) {
2030
+ const previous = currentById.get(node.nodeId);
2031
+ if (previous?.transform && !node.transform)
2032
+ nextById.set(node.nodeId, { ...node, transform: previous.transform });
2033
+ }
2034
+ return [...nextById.values()];
2035
+ });
2036
+ }, []);
2037
+
2038
+ const setHoveredNode = useCallback(
2039
+ (nodeId: string | null) => {
2040
+ setHoveredTarget((current) => {
2041
+ if (nodeId === null) return current === null ? current : null;
2042
+ if (current?.slideId === source.id && current.nodeId === nodeId) {
2043
+ return current;
2044
+ }
2045
+ return { slideId: source.id, nodeId };
2046
+ });
2047
+ },
2048
+ [source.id],
2049
+ );
2050
+
2051
+ useEffect(() => {
2052
+ if (commentMode) setHoveredNode(null);
2053
+ }, [commentMode, setHoveredNode]);
2054
+
2055
+ const selectionNodes = useCallback(
2056
+ (ids: string[]) =>
2057
+ uniqueByLocator(
2058
+ ids.flatMap((id) => nodes.filter((node) => node.nodeId === id)),
2059
+ ),
2060
+ [nodes],
2061
+ );
2062
+
2063
+ const updatePreviewForMove = useCallback(
2064
+ (
2065
+ initial: ElementSnapshot[],
2066
+ dx: number,
2067
+ dy: number,
2068
+ snap = true,
2069
+ lockAxis = false,
2070
+ ) => {
2071
+ const primary = initial[0];
2072
+ if (!primary)
2073
+ return { dx, dy, guides: [] as ReturnType<typeof snapMove>["guides"] };
2074
+ const horizontal = lockAxis && Math.abs(dx) >= Math.abs(dy);
2075
+ const vertical = lockAxis && !horizontal;
2076
+ const delta = constrainMoveDelta({ x: dx, y: dy }, lockAxis);
2077
+ const movingBounds =
2078
+ unionRects(initial.map((node) => node.bounds)) ?? primary.bounds;
2079
+ const otherRects = nodes
2080
+ .filter(
2081
+ (node) => !initial.some((entry) => entry.nodeId === node.nodeId),
2082
+ )
2083
+ .map((node) => node.bounds);
2084
+ const targets = [...otherRects, SLIDES_2_BOUNDS];
2085
+ const stageWidth = stageRef.current?.getBoundingClientRect().width;
2086
+ const canvasScale = stageWidth ? stageWidth / 1920 : 1;
2087
+ const result = snap
2088
+ ? snapMove(movingBounds, delta, targets, 6 / canvasScale)
2089
+ : { delta, guides: [] };
2090
+ const snappedDelta = {
2091
+ x: vertical ? 0 : result.delta.x,
2092
+ y: horizontal ? 0 : result.delta.y,
2093
+ };
2094
+ const guides = result.guides.filter(
2095
+ (guide) =>
2096
+ !(horizontal && guide.axis === "y") &&
2097
+ !(vertical && guide.axis === "x"),
2098
+ );
2099
+ setGuideLines(guides);
2100
+ const patches = uniqueByLocator(initial).map((node) => {
2101
+ const edit = applyTranslate(node, snappedDelta.x, snappedDelta.y);
2102
+ return {
2103
+ line: edit.line,
2104
+ column: edit.column,
2105
+ styles: {
2106
+ translate:
2107
+ edit.ops[0]?.kind === "set-style" ? edit.ops[0].value : null,
2108
+ },
2109
+ };
2110
+ });
2111
+ controllerRef.current?.send({ type: "preview", patches });
2112
+ return { dx: snappedDelta.x, dy: snappedDelta.y, guides };
2113
+ },
2114
+ [nodes],
2115
+ );
2116
+
2117
+ const beginPointerInteraction = useCallback(
2118
+ (pointer: FramePointer) => {
2119
+ if (pointer.phase !== "down" || pointer.button !== 0) return;
2120
+ const hitTarget = pointer.target?.snapshot;
2121
+ const target =
2122
+ hitTarget &&
2123
+ isFullSlideBounds(hitTarget.bounds) &&
2124
+ !selectedIdsRef.current.includes(hitTarget.nodeId)
2125
+ ? null
2126
+ : hitTarget;
2127
+ if (!target) {
2128
+ setGestureSelectionIds(
2129
+ pointer.shiftKey ? [...selectedIdsRef.current] : [],
2130
+ );
2131
+ dragRef.current = {
2132
+ mode: "marquee",
2133
+ pointerId: pointer.pointerId,
2134
+ start: { x: pointer.x, y: pointer.y },
2135
+ moved: false,
2136
+ nodeIds: [],
2137
+ initial: [],
2138
+ additive: pointer.shiftKey,
2139
+ ...(pointer.shiftKey
2140
+ ? { initialSelection: [...selectedIdsRef.current] }
2141
+ : {}),
2142
+ marquee: { x: pointer.x, y: pointer.y, width: 0, height: 0 },
2143
+ };
2144
+ return;
2145
+ }
2146
+
2147
+ const previousIds = selectedIdsRef.current;
2148
+ const previousNodes = previousIds.flatMap((id) => {
2149
+ const node =
2150
+ id === target.nodeId
2151
+ ? target
2152
+ : nodes.find((candidate) => candidate.nodeId === id);
2153
+ return node ? [node] : [];
2154
+ });
2155
+ const selectedAncestor = previousNodes.find(
2156
+ (node) => isSourceAncestor(node, target) === true,
2157
+ );
2158
+ const wasSelected = previousIds.includes(target.nodeId);
2159
+ const commandModifier = pointer.ctrlKey || pointer.metaKey;
2160
+ const hasUnprovenRelation = previousIds.some((id) => {
2161
+ if (id === target.nodeId) return false;
2162
+ const node = previousNodes.find((candidate) => candidate.nodeId === id);
2163
+ return !node || selectionRelation(node, target) === "unknown";
2164
+ });
2165
+ if (hasUnprovenRelation && !wasSelected) {
2166
+ dragRef.current = null;
2167
+ return;
2168
+ }
2169
+ let nextIds: string[];
2170
+ if (pointer.shiftKey && wasSelected) {
2171
+ nextIds = previousIds.filter((id) => id !== target.nodeId);
2172
+ } else if (pointer.shiftKey || (commandModifier && selectedAncestor)) {
2173
+ const independentIds = removeRelatedSelectionIds(
2174
+ previousIds.filter((id) => id !== target.nodeId),
2175
+ target,
2176
+ [...nodes, target],
2177
+ );
2178
+ if (independentIds === null) {
2179
+ dragRef.current = null;
2180
+ return;
2181
+ }
2182
+ nextIds = [...independentIds, target.nodeId];
2183
+ } else if (selectedAncestor || wasSelected) {
2184
+ nextIds = previousIds;
2185
+ } else {
2186
+ nextIds = [target.nodeId];
2187
+ }
2188
+ selectedIdsRef.current = nextIds;
2189
+ setSelectedIds(nextIds);
2190
+ setNodes((current) => {
2191
+ const exists = current.some((node) => node.nodeId === target.nodeId);
2192
+ return exists
2193
+ ? current.map((node) =>
2194
+ node.nodeId === target.nodeId ? target : node,
2195
+ )
2196
+ : [...current, target];
2197
+ });
2198
+ if (!canEdit) {
2199
+ dragRef.current = null;
2200
+ window.requestAnimationFrame(() => inspect(nextIds));
2201
+ return;
2202
+ }
2203
+ const dragIds = pointer.shiftKey && wasSelected ? previousIds : nextIds;
2204
+ const selectedBase = selectionNodes(dragIds).map((node) =>
2205
+ node.nodeId === target.nodeId ? target : node,
2206
+ );
2207
+ if (
2208
+ nextIds.includes(target.nodeId) &&
2209
+ !selectedBase.some((node) => node.nodeId === target.nodeId)
2210
+ ) {
2211
+ selectedBase.push(target);
2212
+ }
2213
+ dragRef.current = {
2214
+ mode: "move",
2215
+ pointerId: pointer.pointerId,
2216
+ start: { x: pointer.x, y: pointer.y },
2217
+ moved: false,
2218
+ nodeIds: dragIds,
2219
+ initial: selectedBase,
2220
+ };
2221
+ window.requestAnimationFrame(() => inspect(nextIds));
2222
+ },
2223
+ [canEdit, inspect, selectionNodes],
2224
+ );
2225
+
2226
+ const handleFramePointer = useCallback(
2227
+ (pointer: FramePointer) => {
2228
+ if (commentMode) {
2229
+ if (pointer.phase === "down" && pointer.button === 0) {
2230
+ commentGestureRef.current = {
2231
+ pointerId: pointer.pointerId,
2232
+ start: { x: pointer.x, y: pointer.y },
2233
+ moved: false,
2234
+ target: pointer.target?.snapshot ?? null,
2235
+ };
2236
+ return;
2237
+ }
2238
+ const gesture = commentGestureRef.current;
2239
+ if (!gesture || gesture.pointerId !== pointer.pointerId) return;
2240
+ if (pointer.phase === "move") {
2241
+ gesture.moved ||=
2242
+ Math.hypot(
2243
+ pointer.x - gesture.start.x,
2244
+ pointer.y - gesture.start.y,
2245
+ ) > 4;
2246
+ return;
2247
+ }
2248
+ if (pointer.phase === "up" || pointer.phase === "cancel") {
2249
+ commentGestureRef.current = null;
2250
+ if (pointer.phase !== "up") return;
2251
+
2252
+ const target = pointer.target?.snapshot ?? gesture.target;
2253
+ const slideRect = { left: 0, top: 0, width: 1920, height: 1080 };
2254
+ void (async () => {
2255
+ let sourceHash =
2256
+ artifact?.sourceHash === committedSource.sourceHash
2257
+ ? committedSource.sourceHash
2258
+ : null;
2259
+ if (hasUnsavedEdits) {
2260
+ if (!(await saveRef.current())) return;
2261
+ sourceHash = committedSourceRef.current.sourceHash;
2262
+ }
2263
+
2264
+ if (gesture.moved) {
2265
+ if (!sourceHash) return;
2266
+ const left = Math.min(gesture.start.x, pointer.x);
2267
+ const top = Math.min(gesture.start.y, pointer.y);
2268
+ const right = Math.max(gesture.start.x, pointer.x);
2269
+ const bottom = Math.max(gesture.start.y, pointer.y);
2270
+ const regionTarget =
2271
+ nodes
2272
+ .filter(
2273
+ (node) =>
2274
+ node.bounds.x <= left &&
2275
+ node.bounds.y <= top &&
2276
+ node.bounds.x + node.bounds.width >= right &&
2277
+ node.bounds.y + node.bounds.height >= bottom,
2278
+ )
2279
+ .sort(
2280
+ (a, b) =>
2281
+ a.bounds.width * a.bounds.height -
2282
+ b.bounds.width * b.bounds.height,
2283
+ )[0] ??
2284
+ nodes
2285
+ .slice()
2286
+ .sort(
2287
+ (a, b) =>
2288
+ b.bounds.width * b.bounds.height -
2289
+ a.bounds.width * a.bounds.height,
2290
+ )[0];
2291
+ setCommentDraftAnchor(
2292
+ slideCommentAnchorForRegion({
2293
+ start: gesture.start,
2294
+ end: { x: pointer.x, y: pointer.y },
2295
+ slideRect,
2296
+ sourceHash,
2297
+ ...(regionTarget
2298
+ ? {
2299
+ sourceLocator: {
2300
+ line: regionTarget.line,
2301
+ column: regionTarget.column,
2302
+ },
2303
+ }
2304
+ : {}),
2305
+ }),
2306
+ );
2307
+ return;
2308
+ }
2309
+
2310
+ setCommentDraftAnchor(
2311
+ slideCommentAnchorAtPoint({
2312
+ clientX: pointer.x,
2313
+ clientY: pointer.y,
2314
+ slideRect,
2315
+ objectRect: target
2316
+ ? {
2317
+ left: target.bounds.x,
2318
+ top: target.bounds.y,
2319
+ width: target.bounds.width,
2320
+ height: target.bounds.height,
2321
+ }
2322
+ : undefined,
2323
+ sourceHash: sourceHash ?? undefined,
2324
+ sourceLocator:
2325
+ sourceHash && target
2326
+ ? { line: target.line, column: target.column }
2327
+ : undefined,
2328
+ }),
2329
+ );
2330
+ })();
2331
+ }
2332
+ return;
2333
+ }
2334
+ if (pointer.phase === "double-click") {
2335
+ openInlineTextEditor(pointer.target?.snapshot, {
2336
+ x: pointer.x,
2337
+ y: pointer.y,
2338
+ });
2339
+ return;
2340
+ }
2341
+ if (inlineNode) return;
2342
+ if (pointer.phase === "down") {
2343
+ setHoveredNode(
2344
+ pointer.pointerType === "touch"
2345
+ ? null
2346
+ : (pointer.target?.nodeId ?? null),
2347
+ );
2348
+ beginPointerInteraction(pointer);
2349
+ return;
2350
+ }
2351
+ const drag = dragRef.current;
2352
+ if (!drag) {
2353
+ if (pointer.phase === "move") {
2354
+ setHoveredNode(
2355
+ pointer.pointerType === "touch"
2356
+ ? null
2357
+ : (elementAtPoint(nodes, { x: pointer.x, y: pointer.y })
2358
+ ?.nodeId ?? null),
2359
+ );
2360
+ }
2361
+ return;
2362
+ }
2363
+ if (drag.pointerId !== pointer.pointerId) return;
2364
+ if (pointer.phase === "move") {
2365
+ const dx = pointer.x - drag.start.x;
2366
+ const dy = pointer.y - drag.start.y;
2367
+ drag.moved ||= Math.hypot(dx, dy) * fitScale >= 3;
2368
+ if (!drag.moved) return;
2369
+ if (drag.mode === "move") {
2370
+ const snapped = updatePreviewForMove(
2371
+ drag.initial,
2372
+ dx,
2373
+ dy,
2374
+ smartGuidesEnabled && !pointer.altKey,
2375
+ pointer.shiftKey,
2376
+ );
2377
+ drag.guides = snapped.guides;
2378
+ } else if (drag.mode === "marquee") {
2379
+ const nextRect = {
2380
+ x: Math.min(drag.start.x, pointer.x),
2381
+ y: Math.min(drag.start.y, pointer.y),
2382
+ width: Math.abs(pointer.x - drag.start.x),
2383
+ height: Math.abs(pointer.y - drag.start.y),
2384
+ };
2385
+ drag.marquee = nextRect;
2386
+ setMarquee(nextRect);
2387
+ setGestureSelectionIds(
2388
+ marqueeSelectionIds(
2389
+ nextRect,
2390
+ nodes,
2391
+ drag.additive ? (drag.initialSelection ?? []) : [],
2392
+ ),
2393
+ );
2394
+ }
2395
+ return;
2396
+ }
2397
+ if (pointer.phase !== "up" && pointer.phase !== "cancel") return;
2398
+
2399
+ if (pointer.phase === "up") {
2400
+ const nextRect = {
2401
+ x: Math.min(drag.start.x, pointer.x),
2402
+ y: Math.min(drag.start.y, pointer.y),
2403
+ width: Math.abs(pointer.x - drag.start.x),
2404
+ height: Math.abs(pointer.y - drag.start.y),
2405
+ };
2406
+ drag.moved ||=
2407
+ Math.hypot(pointer.x - drag.start.x, pointer.y - drag.start.y) *
2408
+ fitScale >=
2409
+ 3;
2410
+ if (drag.mode === "marquee" && drag.moved) {
2411
+ drag.marquee = nextRect;
2412
+ setMarquee(nextRect);
2413
+ setGestureSelectionIds(
2414
+ marqueeSelectionIds(
2415
+ nextRect,
2416
+ nodes,
2417
+ drag.additive ? (drag.initialSelection ?? []) : [],
2418
+ ),
2419
+ );
2420
+ }
2421
+ }
2422
+
2423
+ if (pointer.phase === "cancel" && drag.mode === "move" && drag.moved) {
2424
+ restoreActivePreview();
2425
+ }
2426
+
2427
+ if (drag.mode === "move" && drag.moved && pointer.phase === "up") {
2428
+ const dx = pointer.x - drag.start.x;
2429
+ const dy = pointer.y - drag.start.y;
2430
+ const final = updatePreviewForMove(
2431
+ drag.initial,
2432
+ dx,
2433
+ dy,
2434
+ smartGuidesEnabled && !pointer.altKey,
2435
+ pointer.shiftKey,
2436
+ );
2437
+ appendEdits(
2438
+ uniqueByLocator(drag.initial).map((node) =>
2439
+ applyTranslate(node, final.dx, final.dy),
2440
+ ),
2441
+ );
2442
+ selectedIdsRef.current = drag.nodeIds;
2443
+ setSelectedIds(drag.nodeIds);
2444
+ window.requestAnimationFrame(() => inspect(drag.nodeIds));
2445
+ } else if (
2446
+ drag.mode === "marquee" &&
2447
+ drag.moved &&
2448
+ drag.marquee &&
2449
+ pointer.phase === "up"
2450
+ ) {
2451
+ const nextIds = marqueeSelectionIds(
2452
+ drag.marquee,
2453
+ nodes,
2454
+ drag.additive ? (drag.initialSelection ?? []) : [],
2455
+ );
2456
+ selectedIdsRef.current = nextIds;
2457
+ setSelectedIds(nextIds);
2458
+ inspect(nextIds);
2459
+ } else if (
2460
+ drag.mode === "marquee" &&
2461
+ !drag.moved &&
2462
+ pointer.phase === "up"
2463
+ ) {
2464
+ if (!drag.additive) {
2465
+ selectedIdsRef.current = [];
2466
+ setSelectedIds([]);
2467
+ inspect([]);
2468
+ }
2469
+ }
2470
+ if (drag.mode === "marquee") setGestureSelectionIds(null);
2471
+ dragRef.current = null;
2472
+ setMarquee(null);
2473
+ setGuideLines([]);
2474
+ setHoveredNode(
2475
+ pointer.pointerType === "touch"
2476
+ ? null
2477
+ : (pointer.target?.nodeId ?? null),
2478
+ );
2479
+ },
2480
+ [
2481
+ appendEdits,
2482
+ beginPointerInteraction,
2483
+ canEdit,
2484
+ artifact?.sourceHash,
2485
+ committedSource.sourceHash,
2486
+ commentMode,
2487
+ hasUnsavedEdits,
2488
+ inspect,
2489
+ inlineNode,
2490
+ nodes,
2491
+ openInlineTextEditor,
2492
+ restoreActivePreview,
2493
+ setCommentDraftAnchor,
2494
+ setCommentMode,
2495
+ setHoveredNode,
2496
+ updatePreviewForMove,
2497
+ smartGuidesEnabled,
2498
+ fitScale,
2499
+ ],
2500
+ );
2501
+
2502
+ const eventPoint = (event: ReactPointerEvent<HTMLElement>): Point => {
2503
+ const rect = stageRef.current?.getBoundingClientRect();
2504
+ const scale = rect?.width ? rect.width / 1920 : 1;
2505
+ return {
2506
+ x: (event.clientX - (rect?.left ?? 0)) / scale,
2507
+ y: (event.clientY - (rect?.top ?? 0)) / scale,
2508
+ };
2509
+ };
2510
+
2511
+ const startHandle = (
2512
+ event: ReactPointerEvent<HTMLButtonElement>,
2513
+ handle: ResizeHandle | "rotate",
2514
+ ) => {
2515
+ event.preventDefault();
2516
+ event.stopPropagation();
2517
+ const bounds = selectionBounds;
2518
+ const node = selected[0];
2519
+ if (!bounds || !node || selected.length !== 1) return;
2520
+ const start = eventPoint(event);
2521
+ const center = {
2522
+ x: bounds.x + bounds.width / 2,
2523
+ y: bounds.y + bounds.height / 2,
2524
+ };
2525
+ dragRef.current = {
2526
+ mode: handle === "rotate" ? "rotate" : "resize",
2527
+ pointerId: event.pointerId,
2528
+ start,
2529
+ moved: false,
2530
+ nodeIds: [node.nodeId],
2531
+ initial: [node],
2532
+ ...(handle === "rotate" ? {} : { handle }),
2533
+ initialRect: bounds,
2534
+ initialRotation: node.transform?.rotation ?? 0,
2535
+ ...(handle === "rotate"
2536
+ ? {
2537
+ marquee: {
2538
+ x: Math.atan2(start.y - center.y, start.x - center.x),
2539
+ y: 0,
2540
+ width: 0,
2541
+ height: 0,
2542
+ },
2543
+ }
2544
+ : {}),
2545
+ };
2546
+ event.currentTarget.setPointerCapture(event.pointerId);
2547
+ };
2548
+
2549
+ const handleOverlayPointerMove = (
2550
+ event: ReactPointerEvent<HTMLDivElement>,
2551
+ ) => {
2552
+ const drag = dragRef.current;
2553
+ if (
2554
+ !drag ||
2555
+ drag.pointerId !== event.pointerId ||
2556
+ drag.mode === "move" ||
2557
+ drag.mode === "marquee"
2558
+ )
2559
+ return;
2560
+ const point = eventPoint(event);
2561
+ const node = drag.initial[0];
2562
+ if (!node || !drag.initialRect) return;
2563
+ const dx = point.x - drag.start.x;
2564
+ const dy = point.y - drag.start.y;
2565
+ drag.moved ||= Math.hypot(dx, dy) * fitScale >= 3;
2566
+ if (!drag.moved) return;
2567
+ if (drag.mode === "rotate") {
2568
+ const bounds = drag.initialRect;
2569
+ const center = {
2570
+ x: bounds.x + bounds.width / 2,
2571
+ y: bounds.y + bounds.height / 2,
2572
+ };
2573
+ const startAngle = drag.marquee?.x ?? 0;
2574
+ const angle = Math.atan2(point.y - center.y, point.x - center.x);
2575
+ const rotation = snapRotationTo15Degrees(
2576
+ (drag.initialRotation ?? 0) + ((angle - startAngle) * 180) / Math.PI,
2577
+ event.shiftKey,
2578
+ );
2579
+ controllerRef.current?.send({
2580
+ type: "preview",
2581
+ patches: [
2582
+ {
2583
+ line: node.line,
2584
+ column: node.column,
2585
+ styles: { rotate: `${round(rotation)}deg` },
2586
+ },
2587
+ ],
2588
+ });
2589
+ } else {
2590
+ const handle = drag.handle ?? "se";
2591
+ const initialSize = {
2592
+ width: node.transform?.width ?? node.bounds.width,
2593
+ height: node.transform?.height ?? node.bounds.height,
2594
+ };
2595
+ const next = resizeRect(
2596
+ drag.initialRect,
2597
+ handle,
2598
+ { x: dx, y: dy },
2599
+ event.shiftKey,
2600
+ );
2601
+ const solved = resizeDimensionsForBounds(
2602
+ node,
2603
+ initialSize,
2604
+ drag.initialRect,
2605
+ next,
2606
+ );
2607
+ const patches = [
2608
+ {
2609
+ line: node.line,
2610
+ column: node.column,
2611
+ styles: {
2612
+ width: `${Math.max(8, round(solved.width))}px`,
2613
+ height: `${Math.max(8, round(solved.height))}px`,
2614
+ translate: localTranslateForBounds(node, next.x, next.y),
2615
+ },
2616
+ },
2617
+ ];
2618
+ controllerRef.current?.send({ type: "preview", patches });
2619
+ }
2620
+ };
2621
+
2622
+ const finishOverlayPointer = (event: ReactPointerEvent<HTMLDivElement>) => {
2623
+ const drag = dragRef.current;
2624
+ if (
2625
+ !drag ||
2626
+ drag.pointerId !== event.pointerId ||
2627
+ drag.mode === "move" ||
2628
+ drag.mode === "marquee"
2629
+ )
2630
+ return;
2631
+ if (event.type === "pointercancel") {
2632
+ restoreActivePreview();
2633
+ dragRef.current = null;
2634
+ setGuideLines([]);
2635
+ return;
2636
+ }
2637
+ const point = eventPoint(event);
2638
+ const dx = point.x - drag.start.x;
2639
+ const dy = point.y - drag.start.y;
2640
+ drag.moved ||= Math.hypot(dx, dy) * fitScale >= 3;
2641
+ if (drag.moved) {
2642
+ const node = drag.initial[0];
2643
+ if (node && drag.mode === "rotate") {
2644
+ const bounds = drag.initialRect;
2645
+ if (bounds) {
2646
+ const center = {
2647
+ x: bounds.x + bounds.width / 2,
2648
+ y: bounds.y + bounds.height / 2,
2649
+ };
2650
+ const startAngle = drag.marquee?.x ?? 0;
2651
+ const angle = Math.atan2(point.y - center.y, point.x - center.x);
2652
+ const rotation = snapRotationTo15Degrees(
2653
+ (drag.initialRotation ?? 0) +
2654
+ ((angle - startAngle) * 180) / Math.PI,
2655
+ event.shiftKey,
2656
+ );
2657
+ appendEdits([
2658
+ editFor(node, [
2659
+ {
2660
+ kind: "set-style",
2661
+ key: "rotate",
2662
+ value: `${round(rotation)}deg`,
2663
+ ...(node.text ? { prevText: node.text } : {}),
2664
+ },
2665
+ ]),
2666
+ ]);
2667
+ }
2668
+ } else if (node && drag.initialRect) {
2669
+ const handle = drag.handle ?? "se";
2670
+ const initialSize = {
2671
+ width: node.transform?.width ?? node.bounds.width,
2672
+ height: node.transform?.height ?? node.bounds.height,
2673
+ };
2674
+ const next = resizeRect(
2675
+ drag.initialRect,
2676
+ handle,
2677
+ { x: dx, y: dy },
2678
+ event.shiftKey,
2679
+ );
2680
+ const solved = resizeDimensionsForBounds(
2681
+ node,
2682
+ initialSize,
2683
+ drag.initialRect,
2684
+ next,
2685
+ );
2686
+ appendEdits([
2687
+ editFor(node, [
2688
+ {
2689
+ kind: "set-style",
2690
+ key: "width",
2691
+ value: `${Math.max(8, round(solved.width))}px`,
2692
+ ...(node.text ? { prevText: node.text } : {}),
2693
+ },
2694
+ {
2695
+ kind: "set-style",
2696
+ key: "height",
2697
+ value: `${Math.max(8, round(solved.height))}px`,
2698
+ ...(node.text ? { prevText: node.text } : {}),
2699
+ },
2700
+ {
2701
+ kind: "set-style",
2702
+ key: "translate",
2703
+ value: localTranslateForBounds(node, next.x, next.y),
2704
+ ...(node.text ? { prevText: node.text } : {}),
2705
+ },
2706
+ ]),
2707
+ ]);
2708
+ }
2709
+ }
2710
+ dragRef.current = null;
2711
+ };
2712
+
2713
+ const editSelected = (ops: SourceEditOp[]) => {
2714
+ const node = selected[0];
2715
+ if (!node) return;
2716
+ appendEdits([editFor(node, ops)]);
2717
+ };
2718
+
2719
+ const alignSelection = (alignment: Alignment, toSlide: boolean) => {
2720
+ const rects = distinctSelected.map((node) => node.bounds);
2721
+ const deltas = alignRects(
2722
+ rects,
2723
+ alignment,
2724
+ toSlide || rects.length === 1 ? SLIDES_2_BOUNDS : undefined,
2725
+ );
2726
+ appendEdits(
2727
+ distinctSelected.map((node, index) =>
2728
+ applyTranslate(node, deltas[index]?.x ?? 0, deltas[index]?.y ?? 0),
2729
+ ),
2730
+ );
2731
+ };
2732
+
2733
+ const distributeSelection = (axis: "x" | "y") => {
2734
+ const deltas = distributeRects(
2735
+ distinctSelected.map((node) => node.bounds),
2736
+ axis,
2737
+ );
2738
+ appendEdits(
2739
+ distinctSelected.map((node, index) =>
2740
+ applyTranslate(node, deltas[index]?.x ?? 0, deltas[index]?.y ?? 0),
2741
+ ),
2742
+ );
2743
+ };
2744
+
2745
+ const arrangeSelection = (
2746
+ direction: "front" | "forward" | "backward" | "back",
2747
+ ) => {
2748
+ if (!distinctSelected.length) return;
2749
+ const locator = (node: ElementSnapshot) => `${node.line}:${node.column}`;
2750
+ const selectedLocators = new Set(distinctSelected.map(locator));
2751
+ const zIndex = (node: ElementSnapshot) => {
2752
+ const value = Number.parseFloat(node.styles.zIndex ?? "0");
2753
+ return Number.isFinite(value) ? value : 0;
2754
+ };
2755
+ const selectedLevels = distinctSelected.map(zIndex);
2756
+ const otherLevels = uniqueByLocator(nodes)
2757
+ .filter((node) => !selectedLocators.has(locator(node)))
2758
+ .map(zIndex);
2759
+ let delta = 0;
2760
+ if (direction === "forward") delta = 1;
2761
+ else if (direction === "backward") delta = -1;
2762
+ else if (direction === "front") {
2763
+ delta = Math.max(0, ...otherLevels) + 1 - Math.max(...selectedLevels);
2764
+ } else {
2765
+ delta = Math.min(0, ...otherLevels) - 1 - Math.min(...selectedLevels);
2766
+ }
2767
+ if (!delta) return;
2768
+ const positionEdits = staticPositionZOrderEdits(
2769
+ committedSourceRef.current.sourceTsx,
2770
+ distinctSelected,
2771
+ nodes,
2772
+ );
2773
+ if (!positionEdits) {
2774
+ toast.error(t("slides2Editor.objectStructureUnsupported"));
2775
+ return;
2776
+ }
2777
+ const editsByLocator = new Map(
2778
+ positionEdits.map((edit) => [`${edit.line}:${edit.column}`, edit]),
2779
+ );
2780
+ for (const node of distinctSelected) {
2781
+ const key = locator(node);
2782
+ const edit = editsByLocator.get(key);
2783
+ const zIndexOp: SourceEditOp = {
2784
+ kind: "set-style",
2785
+ key: "zIndex",
2786
+ value: String(zIndex(node) + delta),
2787
+ ...(node.text ? { prevText: node.text } : {}),
2788
+ };
2789
+ if (edit) edit.ops.push(zIndexOp);
2790
+ else editsByLocator.set(key, editFor(node, [zIndexOp]));
2791
+ }
2792
+ appendEdits([...editsByLocator.values()]);
2793
+ };
2794
+
2795
+ const persistEdits = async (edits: SourceEdit[]): Promise<boolean> => {
2796
+ if (!edits.length) return true;
2797
+ if (saving || !canEdit) return false;
2798
+ bumpHistoryVersion();
2799
+ setSaveError(null);
2800
+ try {
2801
+ const result = await onSave(edits);
2802
+ recordCommittedSource(result);
2803
+ setEditBatches([]);
2804
+ setHistoryIndex(0);
2805
+ return true;
2806
+ } catch (error) {
2807
+ setSaveError(
2808
+ t(getEditorActionErrorTranslationKey(error) ?? "settings.saveFailed"),
2809
+ );
2810
+ return false;
2811
+ }
2812
+ };
2813
+
2814
+ const save = async (): Promise<boolean> => {
2815
+ if (!hasUnsavedEdits) return true;
2816
+ return persistEdits(activeEdits);
2817
+ };
2818
+ saveRef.current = save;
2819
+
2820
+ const commitInlineEdits = async (edits: SourceEdit[]): Promise<boolean> => {
2821
+ if (saving || !canEdit) return false;
2822
+ const offset = activeEdits.length;
2823
+ return persistEdits([
2824
+ ...activeEdits,
2825
+ ...edits.map((edit) =>
2826
+ edit.dependsOn === undefined
2827
+ ? edit
2828
+ : { ...edit, dependsOn: edit.dependsOn + offset },
2829
+ ),
2830
+ ]);
2831
+ };
2832
+
2833
+ const commitSourceReplacement = async (
2834
+ sourceTsx: string,
2835
+ selection?: SourceSelection,
2836
+ ): Promise<boolean> => {
2837
+ if (!canEdit || saving) return false;
2838
+ if (hasUnsavedEdits) {
2839
+ setSaveError(t("slides2Editor.saveBeforeStructureEdit"));
2840
+ return false;
2841
+ }
2842
+ bumpHistoryVersion();
2843
+ setSaveError(null);
2844
+ try {
2845
+ const result = await onRestore(sourceTsx, committedSourceRef.current);
2846
+ recordCommittedSource(result);
2847
+ setEditBatches([]);
2848
+ setHistoryIndex(0);
2849
+ selectedIdsRef.current = [];
2850
+ setSelectedIds([]);
2851
+ setNodes([]);
2852
+ setPendingSourceSelection(
2853
+ selection ? { revision: result.revision, selection } : null,
2854
+ );
2855
+ controllerRef.current?.send({ type: "clear-preview" });
2856
+ return true;
2857
+ } catch (error) {
2858
+ setSaveError(
2859
+ t(getEditorActionErrorTranslationKey(error) ?? "settings.saveFailed"),
2860
+ );
2861
+ return false;
2862
+ }
2863
+ };
2864
+
2865
+ const duplicateObject = async () => {
2866
+ const target = distinctSelected.length === 1 ? distinctSelected[0] : null;
2867
+ if (!canEdit || saving || !target) return;
2868
+ if (hasUnsavedEdits) {
2869
+ setSaveError(t("slides2Editor.saveBeforeStructureEdit"));
2870
+ return;
2871
+ }
2872
+ const result = duplicateSourceElement(
2873
+ committedSourceRef.current.sourceTsx,
2874
+ {
2875
+ line: target.line,
2876
+ column: target.column,
2877
+ },
2878
+ );
2879
+ if (!result) {
2880
+ setSaveError(t("slides2Editor.objectStructureUnsupported"));
2881
+ return;
2882
+ }
2883
+ await commitSourceReplacement(result.sourceTsx, result.selection);
2884
+ };
2885
+
2886
+ const deleteObject = async () => {
2887
+ const target = distinctSelected.length === 1 ? distinctSelected[0] : null;
2888
+ if (!canEdit || saving || !target) return;
2889
+ if (hasUnsavedEdits) {
2890
+ setSaveError(t("slides2Editor.saveBeforeStructureEdit"));
2891
+ return;
2892
+ }
2893
+ const result = deleteSourceElement(committedSourceRef.current.sourceTsx, {
2894
+ line: target.line,
2895
+ column: target.column,
2896
+ });
2897
+ if (!result) {
2898
+ setSaveError(t("slides2Editor.objectStructureUnsupported"));
2899
+ return;
2900
+ }
2901
+ await commitSourceReplacement(result.sourceTsx);
2902
+ };
2903
+
2904
+ const insertAsset = async (
2905
+ assetId: string,
2906
+ filename: string,
2907
+ type: string,
2908
+ ): Promise<string | null> => {
2909
+ const isVideo = type === "video/mp4" || type === "video/webm";
2910
+ const failureKey = isVideo
2911
+ ? "slides2Editor.videoInsertFailed"
2912
+ : "slides2Editor.imageInsertFailed";
2913
+ if (!canEdit || saving) return t(failureKey);
2914
+ if (hasUnsavedEdits) return t("slides2Editor.saveBeforeStructureEdit");
2915
+ if (isVideo && assetTarget?.tagName.toLowerCase() === "video") {
2916
+ const sourceTsx = replaceVideoAssetSource(
2917
+ committedSourceRef.current.sourceTsx,
2918
+ { line: assetTarget.line, column: assetTarget.column },
2919
+ assetId,
2920
+ );
2921
+ if (!sourceTsx) return t(failureKey);
2922
+ const saved = await commitSourceReplacement(sourceTsx, {
2923
+ line: assetTarget.line,
2924
+ column: assetTarget.column,
2925
+ });
2926
+ return saved ? null : t(failureKey);
2927
+ }
2928
+ if (type.startsWith("video/") && !isVideo) return t(failureKey);
2929
+ if (isVideo) {
2930
+ const result = insertVideoAssetOnCanvas(
2931
+ committedSourceRef.current.sourceTsx,
2932
+ assetId,
2933
+ filename,
2934
+ );
2935
+ if (!result) return t("slides2Editor.objectStructureUnsupported");
2936
+ const saved = await commitSourceReplacement(
2937
+ result.sourceTsx,
2938
+ result.selection,
2939
+ );
2940
+ return saved ? null : t(failureKey);
2941
+ }
2942
+ if (assetTarget && hasImageTarget) {
2943
+ const op: SourceEditOp =
2944
+ assetTarget.tagName.toLowerCase() === "img"
2945
+ ? { kind: "set-attr-asset", attr: "src", assetId }
2946
+ : { kind: "replace-placeholder-with-image", assetId };
2947
+ const saved = await commitInlineEdits([editFor(assetTarget, [op])]);
2948
+ return saved ? null : t(failureKey);
2949
+ }
2950
+ const result = insertAssetOnCanvas(
2951
+ committedSourceRef.current.sourceTsx,
2952
+ assetId,
2953
+ filename,
2954
+ );
2955
+ if (!result) return t("slides2Editor.objectStructureUnsupported");
2956
+ const saved = await commitSourceReplacement(
2957
+ result.sourceTsx,
2958
+ result.selection,
2959
+ );
2960
+ return saved ? null : t(failureKey);
2961
+ };
2962
+
2963
+ const insertObject = async (kind: Slides2ObjectKind) => {
2964
+ if (!canEdit || saving || structuralSaving) return;
2965
+ if (hasUnsavedEdits) {
2966
+ setSaveError(t("slides2Editor.saveBeforeStructureEdit"));
2967
+ return;
2968
+ }
2969
+ const result = insertSourceObject(committedSourceRef.current.sourceTsx, {
2970
+ kind,
2971
+ ...(kind === "text" ? { text: t("slides2Editor.newTextObject") } : {}),
2972
+ });
2973
+ if (!result) {
2974
+ setSaveError(t("slides2Editor.objectStructureUnsupported"));
2975
+ return;
2976
+ }
2977
+ await commitSourceReplacement(result.sourceTsx, result.selection);
2978
+ };
2979
+
2980
+ const restoreCommittedHistory = useCallback(
2981
+ async (index: number): Promise<boolean> => {
2982
+ const target = committedHistory[index];
2983
+ if (typeof target !== "string" || saving || !canEdit) return false;
2984
+ bumpHistoryVersion();
2985
+ setSaveError(null);
2986
+ try {
2987
+ const result = await onRestore(target, committedSourceRef.current);
2988
+ recordCommittedSource(result, false);
2989
+ committedHistoryIndexRef.current = index;
2990
+ setCommittedHistoryIndex(index);
2991
+ return true;
2992
+ } catch (error) {
2993
+ setSaveError(
2994
+ t(getEditorActionErrorTranslationKey(error) ?? "settings.saveFailed"),
2995
+ );
2996
+ return false;
2997
+ }
2998
+ },
2999
+ [
3000
+ bumpHistoryVersion,
3001
+ canEdit,
3002
+ committedHistory,
3003
+ onRestore,
3004
+ recordCommittedSource,
3005
+ saving,
3006
+ t,
3007
+ ],
3008
+ );
3009
+
3010
+ const present = async (mode: "fullscreen" | "windowed" = "fullscreen") => {
3011
+ if (hasUnsavedEdits && !(await save())) return;
3012
+ onPresent(mode);
3013
+ };
3014
+
3015
+ const changePreviewRevealedSteps = useCallback(
3016
+ (revealedSteps: number) => {
3017
+ const current = previewStepStateRef.current;
3018
+ if (
3019
+ current.artifactKey !== previewArtifactKey ||
3020
+ current.stepCount === null
3021
+ ) {
3022
+ return;
3023
+ }
3024
+ const nextRevealedSteps = Math.max(
3025
+ 0,
3026
+ Math.min(current.stepCount, revealedSteps),
3027
+ );
3028
+ if (nextRevealedSteps === current.revealedSteps) return;
3029
+ const next = { ...current, revealedSteps: nextRevealedSteps };
3030
+ previewStepStateRef.current = next;
3031
+ setPreviewStepState(next);
3032
+ controllerRef.current?.send({
3033
+ type: "set-revealed-steps",
3034
+ revealedSteps: nextRevealedSteps,
3035
+ });
3036
+ },
3037
+ [previewArtifactKey],
3038
+ );
3039
+
3040
+ const goPreviewNext = useCallback(() => {
3041
+ const current = previewStepStateRef.current;
3042
+ if (
3043
+ current.artifactKey !== previewArtifactKey ||
3044
+ current.stepCount === null
3045
+ ) {
3046
+ return;
3047
+ }
3048
+ if (current.revealedSteps < current.stepCount) {
3049
+ changePreviewRevealedSteps(current.revealedSteps + 1);
3050
+ } else if (activeIndex < slides.length - 1) {
3051
+ onSelectSlide(activeIndex + 1);
3052
+ }
3053
+ }, [
3054
+ activeIndex,
3055
+ changePreviewRevealedSteps,
3056
+ onSelectSlide,
3057
+ previewArtifactKey,
3058
+ slides.length,
3059
+ ]);
3060
+
3061
+ const goPreviewPrevious = useCallback(() => {
3062
+ const current = previewStepStateRef.current;
3063
+ if (
3064
+ current.artifactKey !== previewArtifactKey ||
3065
+ current.stepCount === null
3066
+ ) {
3067
+ return;
3068
+ }
3069
+ if (current.revealedSteps > 0) {
3070
+ changePreviewRevealedSteps(current.revealedSteps - 1);
3071
+ } else if (activeIndex > 0) {
3072
+ onSelectSlide(activeIndex - 1);
3073
+ }
3074
+ }, [
3075
+ activeIndex,
3076
+ changePreviewRevealedSteps,
3077
+ onSelectSlide,
3078
+ previewArtifactKey,
3079
+ ]);
3080
+
3081
+ const handlePreviewStepCount = useCallback(
3082
+ (stepCount: number) => {
3083
+ if (!previewArtifactKey) return;
3084
+ const current = previewStepStateRef.current;
3085
+ const revealedSteps = previewModeRef.current
3086
+ ? current.artifactKey === previewArtifactKey
3087
+ ? Math.min(current.revealedSteps, stepCount)
3088
+ : 0
3089
+ : stepCount;
3090
+ const next = {
3091
+ artifactKey: previewArtifactKey,
3092
+ stepCount,
3093
+ revealedSteps,
3094
+ };
3095
+ previewStepStateRef.current = next;
3096
+ setPreviewStepState(next);
3097
+ },
3098
+ [previewArtifactKey],
3099
+ );
3100
+
3101
+ const handlePreviewNavigationInput = useCallback(
3102
+ (input: SlideFrameNavigationInput) => {
3103
+ if (!previewMode) return;
3104
+ if (input.type === "click") {
3105
+ if (
3106
+ input.button === 0 &&
3107
+ !input.defaultPrevented &&
3108
+ !input.interactive &&
3109
+ !input.hasSelection
3110
+ ) {
3111
+ goPreviewNext();
3112
+ }
3113
+ return;
3114
+ }
3115
+ if (input.ctrlKey) return;
3116
+ const delta =
3117
+ input.deltaMode === 1
3118
+ ? input.deltaY * 16
3119
+ : input.deltaMode === 2
3120
+ ? input.deltaY * 800
3121
+ : input.deltaY;
3122
+ const now = performance.now();
3123
+ const wheel = previewWheelRef.current;
3124
+ if (now - wheel.lastAt > 400) wheel.accumulated = 0;
3125
+ wheel.lastAt = now;
3126
+ if (now - wheel.lastNavigationAt < 450) return;
3127
+ wheel.accumulated += delta;
3128
+ if (Math.abs(wheel.accumulated) < 80) return;
3129
+ const direction = Math.sign(wheel.accumulated);
3130
+ wheel.accumulated = 0;
3131
+ wheel.lastNavigationAt = now;
3132
+ if (direction > 0) goPreviewNext();
3133
+ else goPreviewPrevious();
3134
+ },
3135
+ [goPreviewNext, goPreviewPrevious, previewMode],
3136
+ );
3137
+
3138
+ const togglePreviewMode = useCallback(() => {
3139
+ const nextPreviewMode = !previewMode;
3140
+ if (nextPreviewMode) {
3141
+ inspectorBeforePreviewRef.current = inspectorOpen;
3142
+ inspectorToggledInPreviewRef.current = false;
3143
+ onInspectorBeforePreviewChange?.(inspectorOpen);
3144
+ onInspectorToggledInPreviewChange?.(false);
3145
+ setInspectorOpen(false);
3146
+ setCommentMode(false);
3147
+ selectedIdsRef.current = [];
3148
+ setSelectedIds([]);
3149
+ setSelectedTextRange(null);
3150
+ setGuideLines([]);
3151
+ setMarquee(null);
3152
+ const current = previewStepStateRef.current;
3153
+ const next = {
3154
+ artifactKey: previewArtifactKey,
3155
+ stepCount:
3156
+ current.artifactKey === previewArtifactKey ? current.stepCount : null,
3157
+ revealedSteps: 0,
3158
+ };
3159
+ previewStepStateRef.current = next;
3160
+ setPreviewStepState(next);
3161
+ } else if (!inspectorToggledInPreviewRef.current) {
3162
+ setInspectorOpen(inspectorBeforePreviewRef.current ?? true);
3163
+ }
3164
+ if (!nextPreviewMode) {
3165
+ inspectorBeforePreviewRef.current = null;
3166
+ inspectorToggledInPreviewRef.current = false;
3167
+ onInspectorBeforePreviewChange?.(null);
3168
+ onInspectorToggledInPreviewChange?.(false);
3169
+ }
3170
+ if (onEditorModeChange) {
3171
+ onEditorModeChange(nextPreviewMode ? "preview" : "edit");
3172
+ } else {
3173
+ setLocalEditorMode(nextPreviewMode ? "preview" : "edit");
3174
+ }
3175
+ }, [
3176
+ inspectorOpen,
3177
+ onEditorModeChange,
3178
+ onInspectorBeforePreviewChange,
3179
+ onInspectorToggledInPreviewChange,
3180
+ previewArtifactKey,
3181
+ previewMode,
3182
+ setInspectorOpen,
3183
+ ]);
3184
+
3185
+ const copyLink = async () => {
3186
+ try {
3187
+ await navigator.clipboard.writeText(window.location.href);
3188
+ toast.success(t("share.copied"));
3189
+ } catch {
3190
+ toast.error(t("slides2Editor.copyLinkFailed"));
3191
+ }
3192
+ };
3193
+
3194
+ const selectAllElements = () => {
3195
+ const ids = independentTransformTargets(nodes).map((node) => node.nodeId);
3196
+ selectedIdsRef.current = ids;
3197
+ setSelectedIds(ids);
3198
+ setGuideLines([]);
3199
+ if (ids.length) window.requestAnimationFrame(() => inspect(ids));
3200
+ };
3201
+
3202
+ const dispatchEditorShortcut = (action: string) => {
3203
+ switch (action) {
3204
+ case "select-all":
3205
+ if (
3206
+ overviewOpen ||
3207
+ commandMenuOpen ||
3208
+ assetBrowserOpen ||
3209
+ imageCropOpen ||
3210
+ commentMode
3211
+ )
3212
+ return;
3213
+ selectAllElements();
3214
+ break;
3215
+ case "save":
3216
+ void saveRef.current();
3217
+ break;
3218
+ case "toggle-overview":
3219
+ setOverviewOpen((open) => !open);
3220
+ break;
3221
+ case "toggle-inspector":
3222
+ toggleInspector();
3223
+ break;
3224
+ case "present-fullscreen":
3225
+ void present("fullscreen");
3226
+ break;
3227
+ case "present-windowed":
3228
+ void present("windowed");
3229
+ break;
3230
+ case "open-presenter-view":
3231
+ onOpenPresenter?.();
3232
+ void present("windowed");
3233
+ break;
3234
+ case "edit-selected-text":
3235
+ openInlineTextEditor(selectionNodes(selectedIdsRef.current)[0]);
3236
+ break;
3237
+ case "previous-slide":
3238
+ onSelectSlide(Math.max(0, activeIndex - 1));
3239
+ break;
3240
+ case "next-slide":
3241
+ onSelectSlide(Math.min(slides.length - 1, activeIndex + 1));
3242
+ break;
3243
+ }
3244
+ };
3245
+
3246
+ const undo = useCallback((): boolean | Promise<boolean> => {
3247
+ if (crossSlideHistory) {
3248
+ return crossSlideHistory.canUndo ? crossSlideHistory.undo() : false;
3249
+ }
3250
+ if (historyIndex > 0) {
3251
+ bumpHistoryVersion();
3252
+ setHistoryIndex((index) => Math.max(0, index - 1));
3253
+ return true;
3254
+ } else if (!hasUnsavedEdits && committedHistoryIndex > 0) {
3255
+ return restoreCommittedHistory(committedHistoryIndex - 1);
3256
+ }
3257
+ return false;
3258
+ }, [
3259
+ bumpHistoryVersion,
3260
+ committedHistoryIndex,
3261
+ crossSlideHistory,
3262
+ hasUnsavedEdits,
3263
+ historyIndex,
3264
+ restoreCommittedHistory,
3265
+ ]);
3266
+ const redo = useCallback((): boolean | Promise<boolean> => {
3267
+ if (crossSlideHistory) {
3268
+ return crossSlideHistory.canRedo ? crossSlideHistory.redo() : false;
3269
+ }
3270
+ if (historyIndex < editBatches.length) {
3271
+ bumpHistoryVersion();
3272
+ setHistoryIndex((index) => Math.min(editBatches.length, index + 1));
3273
+ return true;
3274
+ } else if (
3275
+ !hasUnsavedEdits &&
3276
+ committedHistoryIndex < committedHistory.length - 1
3277
+ ) {
3278
+ return restoreCommittedHistory(committedHistoryIndex + 1);
3279
+ }
3280
+ return false;
3281
+ }, [
3282
+ bumpHistoryVersion,
3283
+ committedHistory.length,
3284
+ committedHistoryIndex,
3285
+ crossSlideHistory,
3286
+ editBatches.length,
3287
+ hasUnsavedEdits,
3288
+ historyIndex,
3289
+ restoreCommittedHistory,
3290
+ ]);
3291
+
3292
+ editorCommandHandlerRef.current = async (operation) => {
3293
+ if (operation === "undo") return await undo();
3294
+ if (operation === "redo") return await redo();
3295
+ return saveRef.current();
3296
+ };
3297
+
3298
+ useEffect(() => {
3299
+ let cancelled = false;
3300
+ let retryTimer: ReturnType<typeof setTimeout> | null = null;
3301
+ const retryDelay = (attempt: number) =>
3302
+ Math.min(250 * 2 ** Math.min(attempt - 1, 7), 30_000);
3303
+ const clearRetryTimer = () => {
3304
+ if (retryTimer === null) return;
3305
+ clearTimeout(retryTimer);
3306
+ retryTimer = null;
3307
+ };
3308
+ const schedulePollRetry = (commandId?: string) => {
3309
+ if (cancelled || retryTimer !== null) return;
3310
+ let attempt: number;
3311
+ if (commandId) {
3312
+ const retryKey = `${editorCommandKey}:${commandId}`;
3313
+ attempt = (slideEditorCommandAckRetryAttempts.get(retryKey) ?? 0) + 1;
3314
+ slideEditorCommandAckRetryAttempts.set(retryKey, attempt);
3315
+ const attempts = slideEditorCommandAckRetryAttempts;
3316
+ if (attempts.size > 16) {
3317
+ const oldestCommandId = attempts.keys().next().value;
3318
+ if (oldestCommandId) attempts.delete(oldestCommandId);
3319
+ }
3320
+ } else {
3321
+ attempt = ++editorCommandPollRetryAttemptsRef.current;
3322
+ }
3323
+ retryTimer = setTimeout(() => {
3324
+ retryTimer = null;
3325
+ void editorCommandPollRef.current?.();
3326
+ }, retryDelay(attempt));
3327
+ };
3328
+ const clearCommandRetry = (commandId: string) => {
3329
+ const retryKey = `${editorCommandKey}:${commandId}`;
3330
+ completedSlideEditorCommands.delete(retryKey);
3331
+ slideEditorCommandAckRetryAttempts.delete(retryKey);
3332
+ clearRetryTimer();
3333
+ };
3334
+ const commandExecutionKey = (commandId: string) =>
3335
+ `${editorCommandKey}:${commandId}`;
3336
+ const commandStateMatches = (
3337
+ value: unknown,
3338
+ expected: SlideEditorCommand,
3339
+ ) => {
3340
+ const parsed = slideEditorCommandSchema.safeParse(value);
3341
+ return (
3342
+ parsed.success &&
3343
+ JSON.stringify(parsed.data) === JSON.stringify(expected)
3344
+ );
3345
+ };
3346
+ const commandIdentityMatches = (
3347
+ left: SlideEditorCommand,
3348
+ right: SlideEditorCommand,
3349
+ ) =>
3350
+ left.protocolVersion === right.protocolVersion &&
3351
+ left.commandId === right.commandId &&
3352
+ left.operation === right.operation &&
3353
+ left.deckId === right.deckId &&
3354
+ left.slideId === right.slideId &&
3355
+ left.editorSessionId === right.editorSessionId &&
3356
+ left.historyVersion === right.historyVersion &&
3357
+ left.sourceRevision === right.sourceRevision &&
3358
+ left.sourceHash === right.sourceHash;
3359
+ const acknowledge = async (
3360
+ pending: SlideEditorCommand,
3361
+ terminal: SlideEditorCommand,
3362
+ expectedPending: Record<string, unknown>,
3363
+ ) => {
3364
+ const key = commandExecutionKey(pending.commandId);
3365
+ completedSlideEditorCommands.set(key, terminal);
3366
+ const ordered = [...completedSlideEditorCommands.entries()];
3367
+ if (ordered.length > 16) {
3368
+ completedSlideEditorCommands.delete(ordered[0]![0]);
3369
+ }
3370
+ try {
3371
+ const changed = await compareAndSetClientAppState(
3372
+ editorCommandKey,
3373
+ expectedPending,
3374
+ terminal as unknown as Record<string, unknown>,
3375
+ { requestSource: TAB_ID },
3376
+ );
3377
+ if (changed) {
3378
+ clearCommandRetry(pending.commandId);
3379
+ return;
3380
+ }
3381
+ const current = await readClientAppState<unknown>(editorCommandKey);
3382
+ if (commandStateMatches(current, terminal)) {
3383
+ clearCommandRetry(pending.commandId);
3384
+ } else if (commandStateMatches(current, pending)) {
3385
+ schedulePollRetry(pending.commandId);
3386
+ } else {
3387
+ clearCommandRetry(pending.commandId);
3388
+ }
3389
+ } catch (error) {
3390
+ console.error("Could not acknowledge the slide editor command.", error);
3391
+ schedulePollRetry(pending.commandId);
3392
+ }
3393
+ };
3394
+ const poll = async () => {
3395
+ if (cancelled) return;
3396
+ if (editorCommandPollActiveRef.current) {
3397
+ editorCommandPollRequestedRef.current = true;
3398
+ return;
3399
+ }
3400
+ editorCommandPollActiveRef.current = true;
3401
+ try {
3402
+ const state = await readClientAppState<unknown>(editorCommandKey);
3403
+ if (cancelled) return;
3404
+ const parsed = slideEditorCommandSchema.safeParse(state);
3405
+ if (!parsed.success) return;
3406
+ if (parsed.data.status !== "pending") {
3407
+ clearCommandRetry(parsed.data.commandId);
3408
+ return;
3409
+ }
3410
+ editorCommandPollRetryAttemptsRef.current = 0;
3411
+ const pending = parsed.data;
3412
+ const executionKey = commandExecutionKey(pending.commandId);
3413
+ if (activeSlideEditorCommands.has(executionKey)) {
3414
+ schedulePollRetry();
3415
+ return;
3416
+ }
3417
+ const previousResult = completedSlideEditorCommands.get(executionKey);
3418
+ if (previousResult) {
3419
+ if (commandIdentityMatches(pending, previousResult)) {
3420
+ await acknowledge(
3421
+ pending,
3422
+ previousResult,
3423
+ state as Record<string, unknown>,
3424
+ );
3425
+ return;
3426
+ }
3427
+ completedSlideEditorCommands.delete(executionKey);
3428
+ }
3429
+
3430
+ const status = editorStatusRef.current;
3431
+ const editorState = {
3432
+ deckId,
3433
+ slideId: source.id,
3434
+ editorSessionId: editorSessionIdRef.current ?? "",
3435
+ historyVersion: historyVersionRef.current,
3436
+ sourceRevision: committedSourceRef.current.revision,
3437
+ sourceHash: committedSourceRef.current.sourceHash,
3438
+ };
3439
+ let outcome:
3440
+ | { status: "applied" }
3441
+ | {
3442
+ status: "rejected";
3443
+ failureCode: NonNullable<SlideEditorCommand["failureCode"]>;
3444
+ };
3445
+ if (
3446
+ !slideEditorCommandMatchesEditorState(pending, status, editorState)
3447
+ ) {
3448
+ outcome = {
3449
+ status: "rejected",
3450
+ failureCode: "stale_editor_state",
3451
+ };
3452
+ } else if (
3453
+ !isSlideEditorOperationAvailable(status, pending.operation)
3454
+ ) {
3455
+ outcome = {
3456
+ status: "rejected",
3457
+ failureCode: "command_unavailable",
3458
+ };
3459
+ } else {
3460
+ activeSlideEditorCommands.add(executionKey);
3461
+ try {
3462
+ try {
3463
+ outcome = (await editorCommandHandlerRef.current(
3464
+ pending.operation,
3465
+ ))
3466
+ ? { status: "applied" }
3467
+ : {
3468
+ status: "rejected",
3469
+ failureCode: "command_failed",
3470
+ };
3471
+ } catch (error) {
3472
+ console.error("Could not apply the slide editor command.", error);
3473
+ outcome = {
3474
+ status: "rejected",
3475
+ failureCode: "command_failed",
3476
+ };
3477
+ }
3478
+ await acknowledge(
3479
+ pending,
3480
+ completeSlideEditorCommand(pending, outcome),
3481
+ state as Record<string, unknown>,
3482
+ );
3483
+ } finally {
3484
+ activeSlideEditorCommands.delete(executionKey);
3485
+ }
3486
+ return;
3487
+ }
3488
+ await acknowledge(
3489
+ pending,
3490
+ completeSlideEditorCommand(pending, outcome),
3491
+ state as Record<string, unknown>,
3492
+ );
3493
+ } catch (error) {
3494
+ console.error("Could not read the slide editor command.", error);
3495
+ schedulePollRetry();
3496
+ } finally {
3497
+ editorCommandPollActiveRef.current = false;
3498
+ if (editorCommandPollRequestedRef.current) {
3499
+ editorCommandPollRequestedRef.current = false;
3500
+ queueMicrotask(() => void editorCommandPollRef.current?.());
3501
+ }
3502
+ }
3503
+ };
3504
+ editorCommandPollRef.current = poll;
3505
+ void poll();
3506
+ return () => {
3507
+ cancelled = true;
3508
+ clearRetryTimer();
3509
+ };
3510
+ }, [deckId, editorCommandKey, editorCommandVersion, source.id]);
3511
+
3512
+ const keyCommand = useCallback(
3513
+ (
3514
+ key: string,
3515
+ modifiers: {
3516
+ shiftKey: boolean;
3517
+ altKey: boolean;
3518
+ ctrlKey: boolean;
3519
+ metaKey: boolean;
3520
+ },
3521
+ ) => {
3522
+ const command = modifiers.ctrlKey || modifiers.metaKey;
3523
+ if (!modifiers.altKey && command && key.toLowerCase() === "z") {
3524
+ if (modifiers.shiftKey) redo();
3525
+ else undo();
3526
+ return;
3527
+ }
3528
+ if (!modifiers.altKey && command && key.toLowerCase() === "y") {
3529
+ redo();
3530
+ return;
3531
+ }
3532
+ if (key === "Escape") {
3533
+ if (dragRef.current) {
3534
+ if (dragRef.current.moved) restoreActivePreview();
3535
+ dragRef.current = null;
3536
+ setMarquee(null);
3537
+ setGestureSelectionIds(null);
3538
+ setGuideLines([]);
3539
+ return;
3540
+ }
3541
+ selectedIdsRef.current = [];
3542
+ setSelectedIds([]);
3543
+ setGestureSelectionIds(null);
3544
+ setGuideLines([]);
3545
+ return;
3546
+ }
3547
+ if (
3548
+ canEdit &&
3549
+ !commentMode &&
3550
+ selectedIdsRef.current.length &&
3551
+ !modifiers.altKey &&
3552
+ !modifiers.ctrlKey &&
3553
+ !modifiers.metaKey &&
3554
+ ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(key)
3555
+ ) {
3556
+ const delta = modifiers.shiftKey ? 10 : 1;
3557
+ const dx =
3558
+ key === "ArrowLeft" ? -delta : key === "ArrowRight" ? delta : 0;
3559
+ const dy = key === "ArrowUp" ? -delta : key === "ArrowDown" ? delta : 0;
3560
+ const selectedNodes = selectionNodes(selectedIdsRef.current);
3561
+ appendEdits(selectedNodes.map((node) => applyTranslate(node, dx, dy)));
3562
+ return;
3563
+ }
3564
+ if (key === "PageDown" || key === "ArrowRight" || key === " ") {
3565
+ if (activeIndex < slides.length - 1) onSelectSlide(activeIndex + 1);
3566
+ return;
3567
+ }
3568
+ if (key === "PageUp" || key === "ArrowLeft") {
3569
+ if (activeIndex > 0) onSelectSlide(activeIndex - 1);
3570
+ return;
3571
+ }
3572
+ if (key === "Home") onSelectSlide(0);
3573
+ if (key === "End") onSelectSlide(Math.max(0, slides.length - 1));
3574
+ },
3575
+ [
3576
+ activeIndex,
3577
+ appendEdits,
3578
+ canEdit,
3579
+ commentMode,
3580
+ onSelectSlide,
3581
+ redo,
3582
+ restoreActivePreview,
3583
+ selectionNodes,
3584
+ slides.length,
3585
+ undo,
3586
+ ],
3587
+ );
3588
+
3589
+ useEffect(() => {
3590
+ const handleKeyDown = (event: KeyboardEvent) => {
3591
+ if (event.defaultPrevented || event.isComposing || event.keyCode === 229)
3592
+ return;
3593
+
3594
+ const selectedNudge =
3595
+ canEdit &&
3596
+ !commentMode &&
3597
+ selectedIdsRef.current.length > 0 &&
3598
+ !event.altKey &&
3599
+ !event.ctrlKey &&
3600
+ !event.metaKey &&
3601
+ ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key);
3602
+ const shortcut = selectedNudge
3603
+ ? null
3604
+ : getSlides2EditorShortcut(event, {
3605
+ overviewOpen,
3606
+ hasSelectedText: canEditSelectedText,
3607
+ });
3608
+ if (shortcut) {
3609
+ if (shortcut.preventDefault) event.preventDefault();
3610
+ if (previewMode && shortcut.action === "previous-slide") {
3611
+ goPreviewPrevious();
3612
+ } else if (previewMode && shortcut.action === "next-slide") {
3613
+ goPreviewNext();
3614
+ } else {
3615
+ dispatchEditorShortcut(shortcut.action);
3616
+ }
3617
+ return;
3618
+ }
3619
+ if (previewMode) {
3620
+ const target = event.target;
3621
+ if (
3622
+ target instanceof Element &&
3623
+ ((target instanceof HTMLElement && target.isContentEditable) ||
3624
+ target.closest(
3625
+ "input, textarea, select, button, a, [role='dialog'], [role='menu'], [role='menuitem'], [role='menuitemcheckbox'], [role='menuitemradio'], [role='listbox'], [role='option'], [role='tablist'], [data-inspector-ui], [data-design-ui]",
3626
+ ))
3627
+ ) {
3628
+ return;
3629
+ }
3630
+ if (
3631
+ overviewOpen ||
3632
+ commandMenuOpen ||
3633
+ assetBrowserOpen ||
3634
+ imageCropOpen
3635
+ )
3636
+ return;
3637
+ if (event.key === "Escape") {
3638
+ event.preventDefault();
3639
+ togglePreviewMode();
3640
+ } else if (event.key === "ArrowLeft" || event.key === "PageUp") {
3641
+ event.preventDefault();
3642
+ goPreviewPrevious();
3643
+ } else if (
3644
+ event.key === "ArrowRight" ||
3645
+ event.key === "PageDown" ||
3646
+ event.key === " "
3647
+ ) {
3648
+ event.preventDefault();
3649
+ goPreviewNext();
3650
+ } else if (event.key === "Home") {
3651
+ event.preventDefault();
3652
+ onSelectSlide(0);
3653
+ } else if (event.key === "End") {
3654
+ event.preventDefault();
3655
+ onSelectSlide(Math.max(0, slides.length - 1));
3656
+ }
3657
+ return;
3658
+ }
3659
+ if (overviewOpen || commandMenuOpen || assetBrowserOpen || imageCropOpen)
3660
+ return;
3661
+ const target = event.target;
3662
+ if (
3663
+ target instanceof Element &&
3664
+ ((target instanceof HTMLElement && target.isContentEditable) ||
3665
+ target.closest(
3666
+ "input, textarea, select, button, a, [role='dialog'], [role='menu'], [role='menuitem'], [role='menuitemcheckbox'], [role='menuitemradio'], [role='listbox'], [role='option'], [role='tablist'], [data-inspector-ui], [data-design-ui]",
3667
+ ))
3668
+ )
3669
+ return;
3670
+ if (
3671
+ !event.isComposing &&
3672
+ event.keyCode !== 229 &&
3673
+ !event.defaultPrevented &&
3674
+ isBareDesignPanelShortcut(event)
3675
+ ) {
3676
+ toggleDesignPanel();
3677
+ return;
3678
+ }
3679
+ if (event.key === "Escape" && commentMode) {
3680
+ event.preventDefault();
3681
+ commentGestureRef.current = null;
3682
+ setCommentMode(false);
3683
+ return;
3684
+ }
3685
+ if (
3686
+ event.key === "Escape" ||
3687
+ event.key === "PageDown" ||
3688
+ event.key === "PageUp" ||
3689
+ event.key === "ArrowRight" ||
3690
+ event.key === "ArrowLeft" ||
3691
+ event.key === "ArrowUp" ||
3692
+ event.key === "ArrowDown" ||
3693
+ event.key === "Home" ||
3694
+ event.key === "End" ||
3695
+ event.key === " " ||
3696
+ (!event.altKey &&
3697
+ (event.ctrlKey || event.metaKey) &&
3698
+ ["z", "y"].includes(event.key.toLowerCase()))
3699
+ ) {
3700
+ event.preventDefault();
3701
+ keyCommand(event.key, event);
3702
+ }
3703
+ };
3704
+ window.addEventListener("keydown", handleKeyDown);
3705
+ return () => window.removeEventListener("keydown", handleKeyDown);
3706
+ }, [
3707
+ assetBrowserOpen,
3708
+ commentMode,
3709
+ commandMenuOpen,
3710
+ canEdit,
3711
+ canEditSelectedText,
3712
+ dispatchEditorShortcut,
3713
+ goPreviewNext,
3714
+ goPreviewPrevious,
3715
+ imageCropOpen,
3716
+ keyCommand,
3717
+ onSelectSlide,
3718
+ overviewOpen,
3719
+ previewMode,
3720
+ slides.length,
3721
+ togglePreviewMode,
3722
+ toggleDesignPanel,
3723
+ ]);
3724
+
3725
+ const handlePreviewFrameKeyboard = useCallback(
3726
+ (keyboard: FrameKeyboard) => {
3727
+ if (
3728
+ keyboard.isTypingTarget ||
3729
+ keyboard.isControlTarget ||
3730
+ keyboard.isComposing ||
3731
+ keyboard.keyCode === 229
3732
+ ) {
3733
+ return;
3734
+ }
3735
+ const shortcut = getSlides2EditorShortcut(
3736
+ new KeyboardEvent("keydown", keyboard),
3737
+ {
3738
+ overviewOpen,
3739
+ isTypingTarget: keyboard.isTypingTarget,
3740
+ isControlTarget: keyboard.isControlTarget,
3741
+ isComposing: keyboard.isComposing,
3742
+ keyCode: keyboard.keyCode,
3743
+ },
3744
+ );
3745
+ if (shortcut) {
3746
+ if (shortcut.action === "previous-slide") goPreviewPrevious();
3747
+ else if (shortcut.action === "next-slide") goPreviewNext();
3748
+ else dispatchEditorShortcut(shortcut.action);
3749
+ return;
3750
+ }
3751
+ if (keyboard.key === "Escape") togglePreviewMode();
3752
+ else if (keyboard.key === "ArrowLeft" || keyboard.key === "PageUp")
3753
+ goPreviewPrevious();
3754
+ else if (
3755
+ keyboard.key === "ArrowRight" ||
3756
+ keyboard.key === "PageDown" ||
3757
+ keyboard.key === " "
3758
+ )
3759
+ goPreviewNext();
3760
+ else if (keyboard.key === "Home") onSelectSlide(0);
3761
+ else if (keyboard.key === "End")
3762
+ onSelectSlide(Math.max(0, slides.length - 1));
3763
+ },
3764
+ [
3765
+ dispatchEditorShortcut,
3766
+ goPreviewNext,
3767
+ goPreviewPrevious,
3768
+ onSelectSlide,
3769
+ overviewOpen,
3770
+ slides.length,
3771
+ togglePreviewMode,
3772
+ ],
3773
+ );
3774
+
3775
+ const handleFrameKeyboard = useCallback(
3776
+ (keyboard: FrameKeyboard) => {
3777
+ if (previewMode) {
3778
+ handlePreviewFrameKeyboard(keyboard);
3779
+ return;
3780
+ }
3781
+ const selectedNudge =
3782
+ canEdit &&
3783
+ !commentMode &&
3784
+ selectedIdsRef.current.length > 0 &&
3785
+ !keyboard.isTypingTarget &&
3786
+ !keyboard.isControlTarget &&
3787
+ !keyboard.isComposing &&
3788
+ keyboard.keyCode !== 229 &&
3789
+ !keyboard.altKey &&
3790
+ !keyboard.ctrlKey &&
3791
+ !keyboard.metaKey &&
3792
+ ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(
3793
+ keyboard.key,
3794
+ );
3795
+ const shortcut = selectedNudge
3796
+ ? null
3797
+ : getSlides2EditorShortcut(new KeyboardEvent("keydown", keyboard), {
3798
+ overviewOpen,
3799
+ hasSelectedText: canEditSelectedText,
3800
+ isTypingTarget: keyboard.isTypingTarget,
3801
+ isControlTarget: keyboard.isControlTarget,
3802
+ isComposing: keyboard.isComposing,
3803
+ keyCode: keyboard.keyCode,
3804
+ });
3805
+ if (shortcut) {
3806
+ dispatchEditorShortcut(shortcut.action);
3807
+ return;
3808
+ }
3809
+ if (
3810
+ keyboard.isTypingTarget ||
3811
+ keyboard.isControlTarget ||
3812
+ keyboard.isComposing ||
3813
+ keyboard.keyCode === 229
3814
+ )
3815
+ return;
3816
+ if (keyboard.key === "Escape" && commentMode) {
3817
+ commentGestureRef.current = null;
3818
+ setCommentMode(false);
3819
+ return;
3820
+ }
3821
+ if (overviewOpen || commandMenuOpen || assetBrowserOpen || imageCropOpen)
3822
+ return;
3823
+ if (isBareDesignPanelShortcut(keyboard)) {
3824
+ toggleDesignPanel();
3825
+ return;
3826
+ }
3827
+ keyCommand(keyboard.key, keyboard);
3828
+ },
3829
+ [
3830
+ assetBrowserOpen,
3831
+ canEdit,
3832
+ canEditSelectedText,
3833
+ commentMode,
3834
+ commandMenuOpen,
3835
+ dispatchEditorShortcut,
3836
+ handlePreviewFrameKeyboard,
3837
+ imageCropOpen,
3838
+ keyCommand,
3839
+ overviewOpen,
3840
+ previewMode,
3841
+ toggleDesignPanel,
3842
+ ],
3843
+ );
3844
+
3845
+ const setFrameController = useCallback(
3846
+ (controller: SlideFrameController | null) => {
3847
+ controllerRef.current = controller;
3848
+ if (controller) {
3849
+ const patches = getPreviewPatches(activeEdits);
3850
+ if (patches.length) controller.send({ type: "preview", patches });
3851
+ if (designTokens)
3852
+ controller.send({ type: "set-design-tokens", tokens: designTokens });
3853
+ }
3854
+ },
3855
+ [activeEdits, designTokens],
3856
+ );
3857
+ const handleOverviewKeyDown = useCallback(
3858
+ (event: ReactKeyboardEvent<HTMLDivElement>) => {
3859
+ if (
3860
+ ![
3861
+ "ArrowUp",
3862
+ "ArrowDown",
3863
+ "ArrowLeft",
3864
+ "ArrowRight",
3865
+ "Home",
3866
+ "End",
3867
+ ].includes(event.key) ||
3868
+ event.altKey ||
3869
+ event.ctrlKey ||
3870
+ event.metaKey ||
3871
+ event.shiftKey ||
3872
+ !(event.target instanceof HTMLElement) ||
3873
+ !event.target.closest("[data-slide-overview-index]")
3874
+ ) {
3875
+ return;
3876
+ }
3877
+ const focusedButton = (event.target as HTMLElement).closest<HTMLElement>(
3878
+ "[data-slide-overview-index]",
3879
+ );
3880
+ const focusedIndex = Number(focusedButton?.dataset.slideOverviewIndex);
3881
+ if (!Number.isInteger(focusedIndex)) return;
3882
+ event.preventDefault();
3883
+ event.stopPropagation();
3884
+ const grid = overviewGridRef.current;
3885
+ const columns = grid
3886
+ ? Math.max(
3887
+ 1,
3888
+ getComputedStyle(grid)
3889
+ .gridTemplateColumns.split(" ")
3890
+ .filter(Boolean).length,
3891
+ )
3892
+ : 1;
3893
+ const nextIndex = overviewFocusNavigationIndex(
3894
+ focusedIndex,
3895
+ slides.length,
3896
+ event.key,
3897
+ columns,
3898
+ );
3899
+ if (nextIndex === null) return;
3900
+ setFocusedOverviewIndex(nextIndex);
3901
+ window.requestAnimationFrame(() => {
3902
+ const button =
3903
+ overviewGridRef.current?.querySelector<HTMLButtonElement>(
3904
+ `[data-slide-overview-index="${nextIndex}"]`,
3905
+ );
3906
+ button?.focus();
3907
+ button?.scrollIntoView({ block: "nearest", behavior: "auto" });
3908
+ });
3909
+ },
3910
+ [slides.length],
3911
+ );
3912
+
3913
+ const selectedRect = overlaySelectionBounds;
3914
+ const hoveredNode =
3915
+ hoveredTarget?.slideId === source.id
3916
+ ? (nodes.find((node) => node.nodeId === hoveredTarget.nodeId) ?? null)
3917
+ : null;
3918
+ const canvasScale = fitScale > 0 ? fitScale : 1;
3919
+ const sliderPosition = activeSlide?.slideNumber ?? activeIndex + 1;
3920
+ const fitToScreen = () => setZoom(1);
3921
+
3922
+ return (
3923
+ <div className="flex h-full min-h-0 flex-col overflow-hidden bg-background text-foreground">
3924
+ <header className="grid h-12 shrink-0 grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-2 border-b border-[hsl(var(--sidebar-border))] bg-[hsl(var(--surface))] px-3">
3925
+ <div className="flex min-w-0 items-center gap-1">
3926
+ <Button asChild type="button" variant="ghost" size="icon">
3927
+ <Link to={backHref} aria-label={t("editorToolbar.backToDecks")}>
3928
+ <IconArrowLeft className="size-4" />
3929
+ </Link>
3930
+ </Button>
3931
+ <div className={previewMode ? "hidden" : "flex items-center gap-1"}>
3932
+ <Button
3933
+ type="button"
3934
+ variant="ghost"
3935
+ size="icon"
3936
+ onClick={undo}
3937
+ disabled={!canUndo || saving}
3938
+ aria-label={t("editorToolbar.undo")}
3939
+ >
3940
+ <IconArrowBackUp className="size-4" />
3941
+ </Button>
3942
+ <Button
3943
+ type="button"
3944
+ variant="ghost"
3945
+ size="icon"
3946
+ onClick={redo}
3947
+ disabled={!canRedo || saving}
3948
+ aria-label={t("editorToolbar.redo")}
3949
+ >
3950
+ <IconArrowForwardUp className="size-4" />
3951
+ </Button>
3952
+ <Button
3953
+ type="button"
3954
+ variant="ghost"
3955
+ size="icon"
3956
+ onClick={() => setAssetBrowserOpen(true)}
3957
+ aria-label={t("editorToolbar.assetLibrary")}
3958
+ title={t("editorToolbar.assetLibrary")}
3959
+ >
3960
+ <IconPhoto className="size-4" aria-hidden="true" />
3961
+ </Button>
3962
+ {canComment ? (
3963
+ <Button
3964
+ type="button"
3965
+ variant={commentMode ? "secondary" : "ghost"}
3966
+ size="icon"
3967
+ aria-label={t("comments.addComment")}
3968
+ aria-pressed={commentMode}
3969
+ title={t("comments.clickToAddComment")}
3970
+ onClick={() => {
3971
+ commentGestureRef.current = null;
3972
+ setCommentMode((value) => !value);
3973
+ }}
3974
+ >
3975
+ <IconMessageCircle className="size-4" aria-hidden="true" />
3976
+ </Button>
3977
+ ) : null}
3978
+ <DropdownMenu>
3979
+ <DropdownMenuTrigger asChild>
3980
+ <Button
3981
+ type="button"
3982
+ variant="ghost"
3983
+ size="sm"
3984
+ disabled={!canEdit || saving || structuralSaving}
3985
+ aria-label={t("slides2Editor.insertObjects")}
3986
+ title={t("slides2Editor.insertObjects")}
3987
+ >
3988
+ <IconPlus className="me-1 size-4" aria-hidden="true" />
3989
+ {t("slides2Editor.insertObjects")}
3990
+ </Button>
3991
+ </DropdownMenuTrigger>
3992
+ <DropdownMenuContent align="start">
3993
+ <DropdownMenuItem onSelect={() => void insertObject("text")}>
3994
+ {t("slides2Editor.insertTextBox")}
3995
+ </DropdownMenuItem>
3996
+ <DropdownMenuItem
3997
+ onSelect={() => void insertObject("rectangle")}
3998
+ >
3999
+ {t("slides2Editor.insertRectangle")}
4000
+ </DropdownMenuItem>
4001
+ <DropdownMenuItem onSelect={() => void insertObject("ellipse")}>
4002
+ {t("slides2Editor.insertEllipse")}
4003
+ </DropdownMenuItem>
4004
+ <DropdownMenuItem onSelect={() => void insertObject("line")}>
4005
+ {t("slides2Editor.insertLine")}
4006
+ </DropdownMenuItem>
4007
+ </DropdownMenuContent>
4008
+ </DropdownMenu>
4009
+ <Button
4010
+ type="button"
4011
+ variant="ghost"
4012
+ size="icon"
4013
+ onClick={() => setCommandMenuOpen(true)}
4014
+ aria-label={t("slides2Editor.commands")}
4015
+ title={t("slides2Editor.commandShortcutHint")}
4016
+ >
4017
+ <IconSearch className="size-4" aria-hidden="true" />
4018
+ </Button>
4019
+ </div>
4020
+ </div>
4021
+ <span className="min-w-0 max-w-[28rem] justify-self-center truncate text-center text-sm font-medium">
4022
+ {title}
4023
+ </span>
4024
+ <div className="flex min-w-0 items-center justify-end gap-1">
4025
+ <div className={previewMode ? "hidden" : "flex items-center gap-1"}>
4026
+ <Slides2ExportMenu
4027
+ ref={exportMenuRef}
4028
+ deckId={deckId}
4029
+ title={title}
4030
+ slides={slides}
4031
+ aspectRatio={aspectRatio}
4032
+ onBeforeExport={save}
4033
+ />
4034
+ <Button
4035
+ type="button"
4036
+ variant="outline"
4037
+ size="sm"
4038
+ onClick={() => void save()}
4039
+ disabled={!hasUnsavedEdits || saving || !canEdit}
4040
+ >
4041
+ <IconCheck className="me-1 size-4" />
4042
+ {saving
4043
+ ? t("designSystemSetup.saving")
4044
+ : t("designSystemSetup.saveChanges")}
4045
+ </Button>
4046
+ </div>
4047
+ {hasUnsavedEdits ? (
4048
+ <Button
4049
+ type="button"
4050
+ size="sm"
4051
+ onClick={() => void present()}
4052
+ disabled={slides.length === 0 || saving}
4053
+ >
4054
+ <IconPlayerPlay className="me-1 size-4" />
4055
+ {t("editorToolbar.present")}
4056
+ </Button>
4057
+ ) : slides.length > 0 ? (
4058
+ <Button asChild size="sm">
4059
+ <Link to={presentHref}>
4060
+ <IconPlayerPlay className="me-1 size-4" />
4061
+ {t("editorToolbar.present")}
4062
+ </Link>
4063
+ </Button>
4064
+ ) : (
4065
+ <Button size="sm" disabled>
4066
+ <IconPlayerPlay className="me-1 size-4" />
4067
+ {t("editorToolbar.present")}
4068
+ </Button>
4069
+ )}
4070
+ <Button
4071
+ type="button"
4072
+ variant="ghost"
4073
+ size="icon"
4074
+ aria-label={t(
4075
+ inspectorOpen
4076
+ ? "slides2Editor.hideInspector"
4077
+ : "slides2Editor.showInspector",
4078
+ )}
4079
+ title={t(
4080
+ inspectorOpen
4081
+ ? "slides2Editor.hideInspector"
4082
+ : "slides2Editor.showInspector",
4083
+ )}
4084
+ aria-pressed={inspectorOpen}
4085
+ onClick={toggleInspector}
4086
+ >
4087
+ {inspectorOpen ? (
4088
+ <IconLayoutSidebarRightCollapse
4089
+ className="size-4"
4090
+ aria-hidden="true"
4091
+ />
4092
+ ) : (
4093
+ <IconLayoutSidebarRightExpand
4094
+ className="size-4"
4095
+ aria-hidden="true"
4096
+ />
4097
+ )}
4098
+ </Button>
4099
+ <Button
4100
+ type="button"
4101
+ variant={previewMode ? "secondary" : "outline"}
4102
+ size="sm"
4103
+ aria-label={t(
4104
+ previewMode ? "slides2Editor.edit" : "slides2Editor.preview",
4105
+ )}
4106
+ aria-pressed={previewMode}
4107
+ onClick={togglePreviewMode}
4108
+ >
4109
+ {previewMode ? (
4110
+ <IconPencil className="me-1 size-4" aria-hidden="true" />
4111
+ ) : (
4112
+ <IconEye className="me-1 size-4" aria-hidden="true" />
4113
+ )}
4114
+ {t(previewMode ? "slides2Editor.edit" : "slides2Editor.preview")}
4115
+ </Button>
4116
+ </div>
4117
+ </header>
4118
+ <div className="flex min-h-0 flex-1 gap-2">
4119
+ <aside
4120
+ className={`relative shrink-0 bg-[hsl(var(--surface))] ${previewMode ? "hidden" : ""}`}
4121
+ style={{ width: slideRailWidth }}
4122
+ >
4123
+ <div
4124
+ ref={slideRailListRef}
4125
+ id="slides-2-slide-list"
4126
+ className="h-full overflow-y-auto border-e border-[hsl(var(--sidebar-border))] px-3 py-2"
4127
+ >
4128
+ <Button
4129
+ type="button"
4130
+ variant="outline"
4131
+ size="sm"
4132
+ className="mb-2 w-full"
4133
+ disabled={!canEdit || structuralSaving || saving}
4134
+ onClick={onAddSlide}
4135
+ >
4136
+ <IconPlus className="me-1 size-4" />
4137
+ {t("editorSidebar.addEmptySlide")}
4138
+ </Button>
4139
+ <DndContext
4140
+ sensors={dndSensors}
4141
+ collisionDetection={closestCenter}
4142
+ onDragStart={handleThumbnailDragStart}
4143
+ onDragEnd={handleThumbnailDragEnd}
4144
+ >
4145
+ <SortableContext
4146
+ items={slides.map((slide) => slide.id)}
4147
+ strategy={verticalListSortingStrategy}
4148
+ >
4149
+ {slides.map((slide, index) => (
4150
+ <ContextMenu key={slide.id}>
4151
+ <ContextMenuTrigger
4152
+ asChild
4153
+ onContextMenu={() => onSelectSlide(index)}
4154
+ >
4155
+ <SlideThumbnail
4156
+ deckId={deckId}
4157
+ slide={slide}
4158
+ slideIndex={index}
4159
+ selected={index === activeIndex}
4160
+ dragDisabled={!canEdit || structuralSaving || saving}
4161
+ onSelect={() => onSelectSlide(index)}
4162
+ onNavigate={(direction) =>
4163
+ handleThumbnailNavigate(index, direction)
4164
+ }
4165
+ />
4166
+ </ContextMenuTrigger>
4167
+ <ContextMenuContent>
4168
+ <ContextMenuItem
4169
+ disabled={!canEdit || structuralSaving || saving}
4170
+ onSelect={() => onDuplicateSlide(index)}
4171
+ >
4172
+ <IconCopy className="me-2 size-4" />
4173
+ {t("editorSidebar.duplicateSlide")}
4174
+ </ContextMenuItem>
4175
+ <ContextMenuSeparator />
4176
+ <ContextMenuItem
4177
+ disabled={
4178
+ !canEdit || structuralSaving || saving || index === 0
4179
+ }
4180
+ onSelect={() => onMoveSlide(index, index - 1)}
4181
+ >
4182
+ <IconArrowUp className="me-2 size-4" />
4183
+ {t("editorSidebar.moveSlideUp")}
4184
+ </ContextMenuItem>
4185
+ <ContextMenuItem
4186
+ disabled={
4187
+ !canEdit ||
4188
+ structuralSaving ||
4189
+ saving ||
4190
+ index === slides.length - 1
4191
+ }
4192
+ onSelect={() => onMoveSlide(index, index + 1)}
4193
+ >
4194
+ <IconArrowDown className="me-2 size-4" />
4195
+ {t("editorSidebar.moveSlideDown")}
4196
+ </ContextMenuItem>
4197
+ <ContextMenuSeparator />
4198
+ <ContextMenuItem
4199
+ disabled={
4200
+ !canEdit ||
4201
+ structuralSaving ||
4202
+ saving ||
4203
+ slides.length <= 1
4204
+ }
4205
+ onSelect={() => onDeleteSlide(index)}
4206
+ className="text-destructive focus:text-destructive"
4207
+ >
4208
+ <IconTrash className="me-2 size-4" />
4209
+ {t("editorSidebar.deleteSlide")}
4210
+ </ContextMenuItem>
4211
+ </ContextMenuContent>
4212
+ </ContextMenu>
4213
+ ))}
4214
+ </SortableContext>
4215
+ </DndContext>
4216
+ </div>
4217
+ <div
4218
+ role="separator"
4219
+ aria-label={t("editorToolbar.resizeSlideList")}
4220
+ aria-orientation="vertical"
4221
+ aria-controls="slides-2-slide-list"
4222
+ aria-valuemin={MIN_SLIDE_RAIL_WIDTH}
4223
+ aria-valuemax={MAX_SLIDE_RAIL_WIDTH}
4224
+ aria-valuenow={slideRailWidth}
4225
+ tabIndex={0}
4226
+ className="absolute inset-y-0 end-[-3px] z-20 w-[6px] cursor-col-resize touch-none bg-transparent hover:bg-primary/10 focus-visible:bg-primary/10"
4227
+ onPointerDown={handleSlideRailResizeStart}
4228
+ onPointerMove={handleSlideRailResizeMove}
4229
+ onPointerUp={finishSlideRailResize}
4230
+ onPointerCancel={finishSlideRailResize}
4231
+ onLostPointerCapture={finishSlideRailResize}
4232
+ onKeyDown={handleSlideRailResizeKeyDown}
4233
+ />
4234
+ </aside>
4235
+ <main className="relative flex min-w-0 flex-1 flex-col bg-[hsl(var(--surface))] pb-2">
4236
+ <div className="relative min-h-0 flex-1 px-10 py-5">
4237
+ {loading ? (
4238
+ <div className="absolute inset-x-10 inset-y-5 flex items-center justify-center">
4239
+ <Skeleton className="aspect-video w-full max-w-5xl" />
4240
+ </div>
4241
+ ) : artifact ? (
4242
+ <Slides2Canvas zoom={zoom} onScaleChange={setFitScale}>
4243
+ <div
4244
+ ref={stageRef}
4245
+ className="absolute left-0 top-0 h-[1080px] w-[1920px]"
4246
+ data-slides-2-stage-inner
4247
+ onPointerLeave={() => setHoveredNode(null)}
4248
+ >
4249
+ <SandboxedSlide
4250
+ artifact={artifact}
4251
+ title={title}
4252
+ onNodes={handleNodes}
4253
+ onPointer={previewMode ? () => {} : handleFramePointer}
4254
+ onKeyboard={handleFrameKeyboard}
4255
+ onController={setFrameController}
4256
+ onNavigationInput={handlePreviewNavigationInput}
4257
+ onStepCount={handlePreviewStepCount}
4258
+ initialRevealedSteps={previewMode ? 0 : null}
4259
+ onTextRangeStyle={setTextRangeStyleSnapshot}
4260
+ onError={setSaveError}
4261
+ className="absolute inset-0"
4262
+ />
4263
+ <Slides2Comments
4264
+ deckId={deckId}
4265
+ slideId={source.id}
4266
+ canComment={canComment}
4267
+ canEdit={hasEditPermission}
4268
+ active={!previewMode && commentMode}
4269
+ sourceHash={hasUnsavedEdits ? null : source.sourceHash}
4270
+ sourceNodes={nodes}
4271
+ draftAnchor={commentDraftAnchor}
4272
+ onDraftDone={() => setCommentDraftAnchor(null)}
4273
+ />
4274
+ <div
4275
+ className={`absolute inset-0 pointer-events-none ${previewMode ? "hidden" : ""}`}
4276
+ onPointerMove={handleOverlayPointerMove}
4277
+ onPointerUp={finishOverlayPointer}
4278
+ onPointerCancel={finishOverlayPointer}
4279
+ >
4280
+ {hoveredNode &&
4281
+ !overlaySelected.some(
4282
+ (node) => node.nodeId === hoveredNode.nodeId,
4283
+ ) &&
4284
+ !commentMode &&
4285
+ !inlineNode &&
4286
+ !dragRef.current ? (
4287
+ <div
4288
+ className="absolute border border-dashed border-primary/70"
4289
+ style={{
4290
+ left: hoveredNode.bounds.x,
4291
+ top: hoveredNode.bounds.y,
4292
+ width: hoveredNode.bounds.width,
4293
+ height: hoveredNode.bounds.height,
4294
+ }}
4295
+ />
4296
+ ) : null}
4297
+ {overlaySelected.map((node) => (
4298
+ <div
4299
+ key={node.nodeId}
4300
+ className="absolute border-2 border-primary ring-1 ring-background"
4301
+ style={{
4302
+ left: node.bounds.x,
4303
+ top: node.bounds.y,
4304
+ width: node.bounds.width,
4305
+ height: node.bounds.height,
4306
+ }}
4307
+ />
4308
+ ))}
4309
+ {selectedRect && overlaySelected.length === 1 ? (
4310
+ <div
4311
+ className="absolute"
4312
+ style={{
4313
+ left: selectedRect.x,
4314
+ top: selectedRect.y,
4315
+ width: selectedRect.width,
4316
+ height: selectedRect.height,
4317
+ }}
4318
+ >
4319
+ {/* guard:allow-raw-color — white handle centers stay visible over arbitrary slide backgrounds. */}
4320
+ {RESIZE_HANDLES.map(({ key, cursor }) => {
4321
+ const point = handlePoint(selectedRect, key);
4322
+ return (
4323
+ <button
4324
+ key={key}
4325
+ type="button"
4326
+ disabled={!canEdit || saving || structuralSaving}
4327
+ aria-label={t("styleInspector.resizeHandle", {
4328
+ handle: key,
4329
+ })}
4330
+ onPointerDown={(event) => startHandle(event, key)}
4331
+ className={
4332
+ /* guard:allow-raw-color — resize handles stay visible over arbitrary slide fills. */ "pointer-events-auto absolute size-2.5 rounded-sm border border-primary bg-white shadow-sm focus-visible:outline-2 focus-visible:outline-primary"
4333
+ }
4334
+ style={{
4335
+ left: point.x - selectedRect.x - 5,
4336
+ top: point.y - selectedRect.y - 5,
4337
+ cursor,
4338
+ }}
4339
+ />
4340
+ );
4341
+ })}
4342
+ <button
4343
+ type="button"
4344
+ disabled={!canEdit || saving || structuralSaving}
4345
+ aria-label={t("styleInspector.rotateHandle")}
4346
+ onPointerDown={(event) =>
4347
+ startHandle(event, "rotate")
4348
+ }
4349
+ className={
4350
+ /* guard:allow-raw-color — rotate handle stays visible over arbitrary slide fills. */ "pointer-events-auto absolute left-1/2 top-0 size-3 -translate-x-1/2 -translate-y-6 cursor-grab rounded-full border border-primary bg-white shadow-sm focus-visible:outline-2 focus-visible:outline-primary"
4351
+ }
4352
+ />
4353
+ </div>
4354
+ ) : null}
4355
+ {selectedRect && overlaySelected.length > 1 ? (
4356
+ <div
4357
+ className="absolute border border-primary"
4358
+ style={{
4359
+ left: selectedRect.x,
4360
+ top: selectedRect.y,
4361
+ width: selectedRect.width,
4362
+ height: selectedRect.height,
4363
+ }}
4364
+ />
4365
+ ) : null}
4366
+ {selectedRect &&
4367
+ selected.length === 1 &&
4368
+ hasImageTarget &&
4369
+ !dragRef.current ? (
4370
+ <div
4371
+ className="pointer-events-auto absolute z-10 flex rounded-md border border-border bg-popover p-1 shadow-md"
4372
+ style={{
4373
+ left: selectedRect.x + selectedRect.width / 2,
4374
+ top:
4375
+ selectedRect.y +
4376
+ selectedRect.height +
4377
+ 10 / canvasScale,
4378
+ gap: 4 / canvasScale,
4379
+ padding: 4 / canvasScale,
4380
+ transform: "translateX(-50%)",
4381
+ }}
4382
+ >
4383
+ <Button
4384
+ type="button"
4385
+ variant="ghost"
4386
+ size="icon"
4387
+ className="shrink-0"
4388
+ disabled={!canEdit || saving || structuralSaving}
4389
+ aria-label={t("contextToolbar.replaceImage")}
4390
+ title={t("contextToolbar.replaceImage")}
4391
+ onClick={() => setAssetBrowserOpen(true)}
4392
+ style={{
4393
+ width: 28 / canvasScale,
4394
+ height: 28 / canvasScale,
4395
+ }}
4396
+ >
4397
+ <IconPhoto
4398
+ aria-hidden="true"
4399
+ style={{
4400
+ width: 14 / canvasScale,
4401
+ height: 14 / canvasScale,
4402
+ }}
4403
+ />
4404
+ </Button>
4405
+ {selectedImage ? (
4406
+ <Button
4407
+ type="button"
4408
+ variant="ghost"
4409
+ size="icon"
4410
+ className="shrink-0"
4411
+ disabled={
4412
+ !canEdit ||
4413
+ saving ||
4414
+ structuralSaving ||
4415
+ !selectedImageSrc
4416
+ }
4417
+ aria-label={t("editorToolbar.cropImage")}
4418
+ title={t("editorToolbar.cropImage")}
4419
+ onClick={() => setImageCropOpen(true)}
4420
+ style={{
4421
+ width: 28 / canvasScale,
4422
+ height: 28 / canvasScale,
4423
+ }}
4424
+ >
4425
+ <IconCrop
4426
+ aria-hidden="true"
4427
+ style={{
4428
+ width: 14 / canvasScale,
4429
+ height: 14 / canvasScale,
4430
+ }}
4431
+ />
4432
+ </Button>
4433
+ ) : null}
4434
+ </div>
4435
+ ) : null}
4436
+ {guideLines.map((guide, index) => (
4437
+ <div
4438
+ key={`${guide.axis}:${guide.position}:${index}`}
4439
+ className="absolute border-primary"
4440
+ style={
4441
+ guide.axis === "x"
4442
+ ? {
4443
+ left: guide.position,
4444
+ top: guide.start,
4445
+ height: guide.end - guide.start,
4446
+ borderLeftWidth: 1,
4447
+ }
4448
+ : {
4449
+ top: guide.position,
4450
+ left: guide.start,
4451
+ width: guide.end - guide.start,
4452
+ borderTopWidth: 1,
4453
+ }
4454
+ }
4455
+ />
4456
+ ))}
4457
+ {marquee ? (
4458
+ <div
4459
+ className="absolute border border-primary bg-primary/10"
4460
+ style={{
4461
+ left: marquee.x,
4462
+ top: marquee.y,
4463
+ width: marquee.width,
4464
+ height: marquee.height,
4465
+ }}
4466
+ />
4467
+ ) : null}
4468
+ {inlineNode ? (
4469
+ <InlineTextEditor
4470
+ key={inlineNode.nodeId}
4471
+ node={inlineNode}
4472
+ initialPoint={inlineTextPoint ?? undefined}
4473
+ disabled={!canEdit || saving}
4474
+ t={t}
4475
+ onCommit={commitInlineEdits}
4476
+ onCancel={() => setInlineNode(null)}
4477
+ onUndo={() => void undo()}
4478
+ onRedo={() => void redo()}
4479
+ />
4480
+ ) : null}
4481
+ </div>
4482
+ </div>
4483
+ </Slides2Canvas>
4484
+ ) : (
4485
+ <div className="absolute inset-0 grid place-items-center p-8 text-sm text-muted-foreground">
4486
+ {loadingError ?? t("presentation.loadFailed")}
4487
+ </div>
4488
+ )}
4489
+ </div>
4490
+ </main>
4491
+ {inspectorOpen ? (
4492
+ <aside className="h-full w-[320px] shrink-0 border-s border-border bg-background">
4493
+ <Tabs
4494
+ value={activePanel}
4495
+ onValueChange={(value) => {
4496
+ if (
4497
+ value === "format" ||
4498
+ value === "design" ||
4499
+ value === "notes"
4500
+ )
4501
+ setActivePanel(value);
4502
+ }}
4503
+ className="flex h-full flex-col"
4504
+ >
4505
+ <TabsList
4506
+ variant="line"
4507
+ className="h-9 w-full shrink-0 justify-start px-2"
4508
+ >
4509
+ <TabsTrigger value="format" className="px-2 text-xs">
4510
+ {t("styleInspector.title")}
4511
+ </TabsTrigger>
4512
+ <TabsTrigger value="design" className="px-2 text-xs">
4513
+ {t("slides2DesignTokens.title")}
4514
+ </TabsTrigger>
4515
+ <TabsTrigger value="notes" className="px-2 text-xs">
4516
+ {t("presentation.speakerNotes")}
4517
+ </TabsTrigger>
4518
+ </TabsList>
4519
+ <TabsContent
4520
+ value="format"
4521
+ className="mt-0 min-h-0 flex-1 overflow-hidden"
4522
+ >
4523
+ <Slides2Inspector
4524
+ selected={
4525
+ distinctSelected.length === 1
4526
+ ? (distinctSelected[0] ?? null)
4527
+ : null
4528
+ }
4529
+ rangeStyleSnapshot={textRangeStyleSnapshot}
4530
+ selectionCount={distinctSelected.length}
4531
+ disabled={!canEdit || saving || structuralSaving}
4532
+ t={t}
4533
+ onInspectTextRange={inspectSelectedTextRange}
4534
+ onEdit={editSelected}
4535
+ onAlign={alignSelection}
4536
+ alignToSlide={alignToSlide}
4537
+ onAlignToSlideChange={setAlignToSlide}
4538
+ smartGuidesEnabled={smartGuidesEnabled}
4539
+ onSmartGuidesChange={(enabled) => {
4540
+ setSmartGuidesEnabled(enabled);
4541
+ if (!enabled) setGuideLines([]);
4542
+ }}
4543
+ onDistribute={distributeSelection}
4544
+ onArrange={arrangeSelection}
4545
+ onDuplicateObject={() => void duplicateObject()}
4546
+ onDeleteObject={() => void deleteObject()}
4547
+ canSelectParent={Boolean(selectedParentNode)}
4548
+ onSelectParent={selectParent}
4549
+ />
4550
+ </TabsContent>
4551
+ <TabsContent
4552
+ value="design"
4553
+ className="mt-0 min-h-0 flex-1 overflow-hidden"
4554
+ >
4555
+ <Slides2DesignTokens
4556
+ tokens={designTokens}
4557
+ disabled={!canEdit}
4558
+ saving={savingDesignTokens}
4559
+ onPreview={handleDesignTokenPreview}
4560
+ onSave={onSaveDesignTokens}
4561
+ />
4562
+ </TabsContent>
4563
+ <TabsContent
4564
+ value="notes"
4565
+ className="mt-0 min-h-0 flex-1 overflow-hidden"
4566
+ >
4567
+ <div className="grid h-full grid-rows-[minmax(0,1fr)_auto] gap-3 p-4">
4568
+ <Textarea
4569
+ value={notesDraft}
4570
+ disabled={!canEdit || savingNotes}
4571
+ aria-label={t("presentation.speakerNotes")}
4572
+ placeholder={t("presentation.noNotesForSlide")}
4573
+ onChange={(event) =>
4574
+ setNotesDraft(event.currentTarget.value)
4575
+ }
4576
+ className="min-h-0 resize-none text-foreground"
4577
+ />
4578
+ <Button
4579
+ type="button"
4580
+ disabled={!canEdit || savingNotes || notesDraft === notes}
4581
+ onClick={() => void onSaveNotes(notesDraft)}
4582
+ >
4583
+ {savingNotes
4584
+ ? t("designSystemSetup.saving")
4585
+ : t("designSystemSetup.saveChanges")}
4586
+ </Button>
4587
+ </div>
4588
+ </TabsContent>
4589
+ </Tabs>
4590
+ </aside>
4591
+ ) : null}
4592
+ </div>
4593
+ <footer className="flex h-9 shrink-0 items-center justify-between border-t border-border px-4 text-xs text-muted-foreground">
4594
+ <div className="flex items-center gap-1">
4595
+ <Button
4596
+ type="button"
4597
+ variant="ghost"
4598
+ size="icon"
4599
+ className="size-7"
4600
+ aria-label={t("presentation.previousSlide")}
4601
+ disabled={activeIndex <= 0}
4602
+ onClick={() => onSelectSlide(Math.max(0, activeIndex - 1))}
4603
+ >
4604
+ <IconChevronLeft className="size-4" />
4605
+ </Button>
4606
+ <span>
4607
+ {t("slides2Presenter.position", {
4608
+ index: sliderPosition,
4609
+ total: slides.length,
4610
+ })}
4611
+ </span>
4612
+ <Button
4613
+ type="button"
4614
+ variant="ghost"
4615
+ size="icon"
4616
+ className="size-7"
4617
+ aria-label={t("presentation.nextSlide")}
4618
+ disabled={activeIndex >= slides.length - 1}
4619
+ onClick={() =>
4620
+ onSelectSlide(Math.min(slides.length - 1, activeIndex + 1))
4621
+ }
4622
+ >
4623
+ <IconChevronRight className="size-4" />
4624
+ </Button>
4625
+ </div>
4626
+ {structuralSaving ? (
4627
+ <span>{t("designSystemSetup.saving")}</span>
4628
+ ) : saveError || structuralError || loadingError ? (
4629
+ <div className="flex max-w-[55%] items-center gap-2">
4630
+ <span className="min-w-0 truncate text-destructive">
4631
+ {saveError ?? structuralError ?? loadingError}
4632
+ </span>
4633
+ {sourceConflict ? (
4634
+ <Button
4635
+ type="button"
4636
+ variant="outline"
4637
+ size="sm"
4638
+ className="h-7 shrink-0 px-2 text-xs"
4639
+ disabled={reloadingSource}
4640
+ onClick={() => void reloadConflictedSource()}
4641
+ >
4642
+ {t("raw.reload")}
4643
+ </Button>
4644
+ ) : null}
4645
+ </div>
4646
+ ) : null}
4647
+ <div className="flex items-center gap-1">
4648
+ <Button
4649
+ type="button"
4650
+ variant="ghost"
4651
+ size="icon"
4652
+ className="size-8"
4653
+ aria-label={t("raw.zoomOut")}
4654
+ onClick={() =>
4655
+ setZoom((value) => Math.max(MIN_ZOOM, round(value - ZOOM_STEP)))
4656
+ }
4657
+ >
4658
+ <IconMinus className="size-3.5" />
4659
+ </Button>
4660
+ <Button
4661
+ type="button"
4662
+ variant="ghost"
4663
+ size="sm"
4664
+ onClick={fitToScreen}
4665
+ className="h-auto min-w-12 rounded px-1 py-1 text-center text-xs font-normal text-muted-foreground transition-none hover:bg-accent hover:text-muted-foreground active:scale-100"
4666
+ aria-label={t("raw.fitSlideToScreen")}
4667
+ >
4668
+ {Math.round(fitScale * 100)}%
4669
+ </Button>
4670
+ <Button
4671
+ type="button"
4672
+ variant="ghost"
4673
+ size="icon"
4674
+ className="size-8"
4675
+ aria-label={t("raw.zoomIn")}
4676
+ onClick={() =>
4677
+ setZoom((value) => Math.min(MAX_ZOOM, round(value + ZOOM_STEP)))
4678
+ }
4679
+ >
4680
+ <IconPlus className="size-3.5" />
4681
+ </Button>
4682
+ </div>
4683
+ </footer>
4684
+ <Slides2AssetBrowser
4685
+ deckId={deckId}
4686
+ slideId={activeSlide?.id ?? ""}
4687
+ open={assetBrowserOpen}
4688
+ onOpenChange={setAssetBrowserOpen}
4689
+ canInsert={canEdit && !saving && !structuralSaving}
4690
+ onInsert={insertAsset}
4691
+ />
4692
+ {imageCropOpen && selectedImage && selectedImageSrc ? (
4693
+ <Slides2ImageCropControls
4694
+ src={selectedImageSrc}
4695
+ targetWidth={Math.max(1, selectedImage.bounds.width)}
4696
+ targetHeight={Math.max(1, selectedImage.bounds.height)}
4697
+ initialFit={
4698
+ selectedImage.styles.objectFit === "contain" ? "contain" : "cover"
4699
+ }
4700
+ initialPosition={objectPositionPercent(
4701
+ selectedImage.styles.objectPosition,
4702
+ )}
4703
+ initialRect={objectViewBoxToCropRect(
4704
+ selectedImage.styles.objectViewBox,
4705
+ )}
4706
+ labels={{
4707
+ title: t("editorToolbar.cropImage"),
4708
+ description: t("slides2Editor.cropDescription"),
4709
+ fitMode: t("slides2Editor.cropFitMode"),
4710
+ fitCover: t("contextToolbar.fitCover"),
4711
+ fitContain: t("contextToolbar.fitContain"),
4712
+ cropRegion: t("slides2Editor.cropRegion"),
4713
+ close: t("comments.close"),
4714
+ cancel: t("slideTextMenu.cancel"),
4715
+ apply: t("slideTextMenu.apply"),
4716
+ }}
4717
+ onClose={() => setImageCropOpen(false)}
4718
+ onApply={applyImageCrop}
4719
+ />
4720
+ ) : null}
4721
+ <Dialog open={overviewOpen} onOpenChange={setOverviewOpen}>
4722
+ <DialogContent
4723
+ closeLabel={t("comments.close")}
4724
+ onOpenAutoFocus={(event) => {
4725
+ event.preventDefault();
4726
+ window.requestAnimationFrame(() => {
4727
+ document
4728
+ .querySelector<HTMLButtonElement>(
4729
+ "[data-slide-overview-active='true']",
4730
+ )
4731
+ ?.focus();
4732
+ });
4733
+ }}
4734
+ overlayClassName="top-12 bg-popover/95 backdrop-blur-none"
4735
+ className="inset-x-0 bottom-0 left-0 top-12 flex h-auto max-h-none w-full max-w-none translate-x-0 translate-y-0 flex-col gap-0 overflow-hidden rounded-none border-0 bg-popover/95 p-0 shadow-none"
4736
+ >
4737
+ <DialogHeader className="flex h-[60px] shrink-0 flex-row items-center justify-between border-b border-border/60 px-6">
4738
+ <DialogTitle className="text-xs font-semibold uppercase tracking-widest">
4739
+ {`${t("slides2Presenter.overview")} ${String(activeIndex + 1).padStart(2, "0")} · ${slides.length}`}
4740
+ </DialogTitle>
4741
+ </DialogHeader>
4742
+ <div className="min-h-0 flex-1 overflow-y-auto px-8 pb-6 pt-0">
4743
+ <div
4744
+ ref={overviewGridRef}
4745
+ onKeyDown={handleOverviewKeyDown}
4746
+ className="mx-auto grid w-full max-w-[1000px] grid-cols-1 content-start gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3"
4747
+ >
4748
+ {slides.map((slide, index) => (
4749
+ <SlideOverviewThumbnail
4750
+ key={slide.id}
4751
+ deckId={deckId}
4752
+ slide={slide}
4753
+ index={index}
4754
+ selected={index === activeIndex}
4755
+ focused={index === focusedOverviewIndex}
4756
+ total={slides.length}
4757
+ onFocus={setFocusedOverviewIndex}
4758
+ onSelect={() => {
4759
+ onSelectSlide(index);
4760
+ setOverviewOpen(false);
4761
+ }}
4762
+ />
4763
+ ))}
4764
+ </div>
4765
+ </div>
4766
+ </DialogContent>
4767
+ </Dialog>
4768
+ <Slides2CommandMenu
4769
+ open={commandMenuOpen}
4770
+ onOpenChange={setCommandMenuOpen}
4771
+ backHref={backHref}
4772
+ slides={slides}
4773
+ activeIndex={activeIndex}
4774
+ canEdit={canEdit && !saving && !structuralSaving}
4775
+ canComment={canComment}
4776
+ canUndo={canUndo && !saving}
4777
+ canRedo={canRedo && !saving}
4778
+ onSelectSlide={onSelectSlide}
4779
+ onAddSlide={onAddSlide}
4780
+ onInsertObject={insertObject}
4781
+ onDuplicateSlide={onDuplicateSlide}
4782
+ onDeleteSlide={onDeleteSlide}
4783
+ onUndo={undo}
4784
+ onRedo={redo}
4785
+ onPresent={(mode) => void present(mode)}
4786
+ onOpenPresenter={() => {
4787
+ onOpenPresenter?.();
4788
+ void present("windowed");
4789
+ }}
4790
+ onOpenOverview={() => setOverviewOpen(true)}
4791
+ onToggleDesignPanel={toggleDesignPanel}
4792
+ onToggleCommentMode={() => {
4793
+ commentGestureRef.current = null;
4794
+ setCommentMode((value) => !value);
4795
+ }}
4796
+ onCopyLink={() => void copyLink()}
4797
+ onOpenAssets={() => setAssetBrowserOpen(true)}
4798
+ onExport={(format: Slides2ExportFormat) =>
4799
+ exportMenuRef.current?.run(format)
4800
+ }
4801
+ />
4802
+ </div>
4803
+ );
4804
+ }