@jingyi0605/codingns 0.8.5 → 0.9.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 (439) hide show
  1. package/bin/codingns.mjs +7 -156
  2. package/dist/public/assets/AdaptiveButlerPage-B17QiMyT.js +2 -0
  3. package/dist/public/assets/{App-BOHBGFOd.js → App-CFBwDUNA.js} +6 -6
  4. package/dist/public/assets/{BootstrapPage-BxHQT4nA.js → BootstrapPage-W5wU3BPh.js} +1 -1
  5. package/dist/public/assets/{ConversationPage-DWFsF6BB.js → ConversationPage-DQLX1bUh.js} +6 -6
  6. package/dist/public/assets/{DesktopDetachPreviewPage-DOgEjYEf.js → DesktopDetachPreviewPage-DTPeuAW-.js} +1 -1
  7. package/dist/public/assets/DesktopModal-6ii53_Y9.js +1 -0
  8. package/dist/public/assets/DesktopWindowPage-D0blSuKd.js +2 -0
  9. package/dist/public/assets/FileContextPanel-BrKO8Xt6.js +1 -0
  10. package/dist/public/assets/GitSidebar-BdwiDtOr.js +6 -0
  11. package/dist/public/assets/MobileCreateSessionSheet-Cx_dBiBb.js +1 -0
  12. package/dist/public/assets/MobileSheet-opTWyRe1.js +1 -0
  13. package/dist/public/assets/{MobileTopHeaderFrame-lcp2GscV.js → MobileTopHeaderFrame-BbNON3Y4.js} +1 -1
  14. package/dist/public/assets/MobileWorkspaceSwitcherHeader-BZEzPeMj.js +1 -0
  15. package/dist/public/assets/{PluginAccessOverview-DGcKAMQl.js → PluginAccessOverview-mQDmAljp.js} +1 -1
  16. package/dist/public/assets/PluginContainerPage-CcxUJpM4.js +1 -0
  17. package/dist/public/assets/{PluginDetailPage-CAJ7LFpD.js → PluginDetailPage-D5--ACIt.js} +1 -1
  18. package/dist/public/assets/{PluginsListPage-BxZG1NyT.js → PluginsListPage-D_oJxYXT.js} +1 -1
  19. package/dist/public/assets/{RelayConnectEntryPage-CfNO_TIl.js → RelayConnectEntryPage-DROxpnkv.js} +1 -1
  20. package/dist/public/assets/{ServerSettingsModal-by36Z_5k.js → ServerSettingsModal-CUUOPqSe.js} +1 -1
  21. package/dist/public/assets/SessionIndexPage-C2Jxh6Gp.js +1 -0
  22. package/dist/public/assets/SettingsPage-BlAZCHsy.js +2 -0
  23. package/dist/public/assets/{TerminalManagerPanel-NVZRxxmH.js → TerminalManagerPanel-CjzbiWjl.js} +1 -1
  24. package/dist/public/assets/{TerminalPage-C4LNoPBp.js → TerminalPage-CwWyFDj8.js} +2 -2
  25. package/dist/public/assets/TerminalRuntimeFallbackModal-CSVVbO8r.js +1 -0
  26. package/dist/public/assets/{ToolFilesPage-47zbdgTW.js → ToolFilesPage-QBEY8oCf.js} +1 -1
  27. package/dist/public/assets/{ToolGitPage-Fuk_b_jg.js → ToolGitPage-BKoZ2l9v.js} +1 -1
  28. package/dist/public/assets/{ToolProcessesPage-sWSMWD-9.js → ToolProcessesPage-BOH0ib4G.js} +1 -1
  29. package/dist/public/assets/{ToolsHomePage-R1mZlbZi.js → ToolsHomePage-BcMZ3BCQ.js} +1 -1
  30. package/dist/public/assets/{WorkbenchLandingPage-CqmiFH2u.js → WorkbenchLandingPage-B5zoppEl.js} +1 -1
  31. package/dist/public/assets/WorkbenchLayout-BksVkkFF.css +1 -0
  32. package/dist/public/assets/WorkbenchLayout-CikJBS62.js +1019 -0
  33. package/dist/public/assets/{WorkbenchModal-C7qoQElW.js → WorkbenchModal-NGmPgqaE.js} +1 -1
  34. package/dist/public/assets/WorkbenchShellRoute-BbbSOiZw.js +1 -0
  35. package/dist/public/assets/WorkbenchShellRoute-DT3VMjWD.css +1 -0
  36. package/dist/public/assets/WorkspaceDebugDetailPage-CVivdPx5.js +1 -0
  37. package/dist/public/assets/{WorkspaceDetailPage-BPsrFffw.js → WorkspaceDetailPage-DgOSjscR.js} +1 -1
  38. package/dist/public/assets/{WorkspaceHomePage-KAtqZOAb.js → WorkspaceHomePage-HPa7M_Vh.js} +1 -1
  39. package/dist/public/assets/{client-runtime-manager-wmCJZKYd.js → client-runtime-manager-DXbI9K1K.js} +1 -1
  40. package/dist/public/assets/index-BxJPQpFM.css +1 -0
  41. package/dist/public/assets/index-CeXGOT_T.js +50 -0
  42. package/dist/public/assets/{login-direct-candidate-resolver-BOAgTuUf.js → login-direct-candidate-resolver-DkKyFtQJ.js} +1 -1
  43. package/dist/public/assets/{plugin-permission-copy-Cq99cnzV.js → plugin-permission-copy-CzN269Bk.js} +1 -1
  44. package/dist/public/assets/{plugins-api-BQTV5DOp.js → plugins-api-Bv9DHpLF.js} +1 -1
  45. package/dist/public/assets/{preferences-service-DJxbEEeg.js → preferences-service-D2ISL2Zz.js} +1 -1
  46. package/dist/public/assets/{relay-entry-D-LfvdiX.js → relay-entry-Bg0OisQy.js} +1 -1
  47. package/dist/public/assets/{terminal-runtime-meta-BJmy8dyK.js → terminal-runtime-meta-C8t-CIDF.js} +1 -1
  48. package/dist/public/assets/{useRegisteredDebugTemplates-DQAWVdCo.js → useRegisteredDebugTemplates-Bol3NVfN.js} +1 -1
  49. package/dist/public/assets/{workbench-navigation-MEzCSmsK.js → workbench-navigation-B7IjRQd8.js} +1 -1
  50. package/dist/public/index.html +2 -2
  51. package/dist/server/middlewares/auth-guard.js +10 -5
  52. package/dist/server/middlewares/auth-guard.js.map +1 -1
  53. package/dist/server/modules/affairs-indexer/contracts/src/errors/app-error.d.ts +11 -0
  54. package/dist/server/modules/affairs-indexer/contracts/src/errors/app-error.js +22 -0
  55. package/dist/server/modules/affairs-indexer/contracts/src/errors/app-error.js.map +1 -0
  56. package/dist/server/modules/affairs-indexer/contracts/src/errors/error-codes.d.ts +23 -0
  57. package/dist/server/modules/affairs-indexer/contracts/src/errors/error-codes.js +23 -0
  58. package/dist/server/modules/affairs-indexer/contracts/src/errors/error-codes.js.map +1 -0
  59. package/dist/server/modules/affairs-indexer/contracts/src/index.d.ts +4 -0
  60. package/dist/server/modules/affairs-indexer/contracts/src/index.js +5 -0
  61. package/dist/server/modules/affairs-indexer/contracts/src/index.js.map +1 -0
  62. package/dist/server/modules/affairs-indexer/contracts/src/types/cli-command-context.d.ts +7 -0
  63. package/dist/server/modules/affairs-indexer/contracts/src/types/cli-command-context.js +2 -0
  64. package/dist/server/modules/affairs-indexer/contracts/src/types/cli-command-context.js.map +1 -0
  65. package/dist/server/modules/affairs-indexer/contracts/src/types/runtime-config.d.ts +16 -0
  66. package/dist/server/modules/affairs-indexer/contracts/src/types/runtime-config.js +2 -0
  67. package/dist/server/modules/affairs-indexer/contracts/src/types/runtime-config.js.map +1 -0
  68. package/dist/server/modules/affairs-indexer/core/src/config/load-runtime-config.d.ts +10 -0
  69. package/dist/server/modules/affairs-indexer/core/src/config/load-runtime-config.js +215 -0
  70. package/dist/server/modules/affairs-indexer/core/src/config/load-runtime-config.js.map +1 -0
  71. package/dist/server/modules/affairs-indexer/core/src/index.d.ts +31 -0
  72. package/dist/server/modules/affairs-indexer/core/src/index.js +32 -0
  73. package/dist/server/modules/affairs-indexer/core/src/index.js.map +1 -0
  74. package/dist/server/modules/affairs-indexer/core/src/logging/structured-logger.d.ts +20 -0
  75. package/dist/server/modules/affairs-indexer/core/src/logging/structured-logger.js +47 -0
  76. package/dist/server/modules/affairs-indexer/core/src/logging/structured-logger.js.map +1 -0
  77. package/dist/server/modules/affairs-indexer/core/src/parser/base-complex-parser-adapter.d.ts +17 -0
  78. package/dist/server/modules/affairs-indexer/core/src/parser/base-complex-parser-adapter.js +63 -0
  79. package/dist/server/modules/affairs-indexer/core/src/parser/base-complex-parser-adapter.js.map +1 -0
  80. package/dist/server/modules/affairs-indexer/core/src/parser/complex-document-skip-adapter.d.ts +12 -0
  81. package/dist/server/modules/affairs-indexer/core/src/parser/complex-document-skip-adapter.js +42 -0
  82. package/dist/server/modules/affairs-indexer/core/src/parser/complex-document-skip-adapter.js.map +1 -0
  83. package/dist/server/modules/affairs-indexer/core/src/parser/csv-parser-adapter.d.ts +7 -0
  84. package/dist/server/modules/affairs-indexer/core/src/parser/csv-parser-adapter.js +107 -0
  85. package/dist/server/modules/affairs-indexer/core/src/parser/csv-parser-adapter.js.map +1 -0
  86. package/dist/server/modules/affairs-indexer/core/src/parser/document-parser.d.ts +19 -0
  87. package/dist/server/modules/affairs-indexer/core/src/parser/document-parser.js +37 -0
  88. package/dist/server/modules/affairs-indexer/core/src/parser/document-parser.js.map +1 -0
  89. package/dist/server/modules/affairs-indexer/core/src/parser/docx-parser-adapter.d.ts +7 -0
  90. package/dist/server/modules/affairs-indexer/core/src/parser/docx-parser-adapter.js +123 -0
  91. package/dist/server/modules/affairs-indexer/core/src/parser/docx-parser-adapter.js.map +1 -0
  92. package/dist/server/modules/affairs-indexer/core/src/parser/openxml-utils.d.ts +8 -0
  93. package/dist/server/modules/affairs-indexer/core/src/parser/openxml-utils.js +111 -0
  94. package/dist/server/modules/affairs-indexer/core/src/parser/openxml-utils.js.map +1 -0
  95. package/dist/server/modules/affairs-indexer/core/src/parser/parser-adapter.d.ts +42 -0
  96. package/dist/server/modules/affairs-indexer/core/src/parser/parser-adapter.js +2 -0
  97. package/dist/server/modules/affairs-indexer/core/src/parser/parser-adapter.js.map +1 -0
  98. package/dist/server/modules/affairs-indexer/core/src/parser/parser-capability-registry.d.ts +18 -0
  99. package/dist/server/modules/affairs-indexer/core/src/parser/parser-capability-registry.js +91 -0
  100. package/dist/server/modules/affairs-indexer/core/src/parser/parser-capability-registry.js.map +1 -0
  101. package/dist/server/modules/affairs-indexer/core/src/parser/parser-router.d.ts +18 -0
  102. package/dist/server/modules/affairs-indexer/core/src/parser/parser-router.js +59 -0
  103. package/dist/server/modules/affairs-indexer/core/src/parser/parser-router.js.map +1 -0
  104. package/dist/server/modules/affairs-indexer/core/src/parser/parser-skip-repository.d.ts +48 -0
  105. package/dist/server/modules/affairs-indexer/core/src/parser/parser-skip-repository.js +193 -0
  106. package/dist/server/modules/affairs-indexer/core/src/parser/parser-skip-repository.js.map +1 -0
  107. package/dist/server/modules/affairs-indexer/core/src/parser/pdf-parser-adapter.d.ts +7 -0
  108. package/dist/server/modules/affairs-indexer/core/src/parser/pdf-parser-adapter.js +371 -0
  109. package/dist/server/modules/affairs-indexer/core/src/parser/pdf-parser-adapter.js.map +1 -0
  110. package/dist/server/modules/affairs-indexer/core/src/parser/plain-text-parser-adapter.d.ts +10 -0
  111. package/dist/server/modules/affairs-indexer/core/src/parser/plain-text-parser-adapter.js +55 -0
  112. package/dist/server/modules/affairs-indexer/core/src/parser/plain-text-parser-adapter.js.map +1 -0
  113. package/dist/server/modules/affairs-indexer/core/src/parser/plain-text-parser.d.ts +9 -0
  114. package/dist/server/modules/affairs-indexer/core/src/parser/plain-text-parser.js +2 -0
  115. package/dist/server/modules/affairs-indexer/core/src/parser/plain-text-parser.js.map +1 -0
  116. package/dist/server/modules/affairs-indexer/core/src/parser/pptx-parser-adapter.d.ts +7 -0
  117. package/dist/server/modules/affairs-indexer/core/src/parser/pptx-parser-adapter.js +130 -0
  118. package/dist/server/modules/affairs-indexer/core/src/parser/pptx-parser-adapter.js.map +1 -0
  119. package/dist/server/modules/affairs-indexer/core/src/parser/xlsx-parser-adapter.d.ts +7 -0
  120. package/dist/server/modules/affairs-indexer/core/src/parser/xlsx-parser-adapter.js +228 -0
  121. package/dist/server/modules/affairs-indexer/core/src/parser/xlsx-parser-adapter.js.map +1 -0
  122. package/dist/server/modules/affairs-indexer/core/src/repositories/catalog-repository.d.ts +205 -0
  123. package/dist/server/modules/affairs-indexer/core/src/repositories/catalog-repository.js +1471 -0
  124. package/dist/server/modules/affairs-indexer/core/src/repositories/catalog-repository.js.map +1 -0
  125. package/dist/server/modules/affairs-indexer/core/src/repositories/catalog-write-repository.d.ts +161 -0
  126. package/dist/server/modules/affairs-indexer/core/src/repositories/catalog-write-repository.js +1350 -0
  127. package/dist/server/modules/affairs-indexer/core/src/repositories/catalog-write-repository.js.map +1 -0
  128. package/dist/server/modules/affairs-indexer/core/src/scanner/file-scanner.d.ts +32 -0
  129. package/dist/server/modules/affairs-indexer/core/src/scanner/file-scanner.js +208 -0
  130. package/dist/server/modules/affairs-indexer/core/src/scanner/file-scanner.js.map +1 -0
  131. package/dist/server/modules/affairs-indexer/core/src/services/dirty/dirty-scope-resolver.d.ts +30 -0
  132. package/dist/server/modules/affairs-indexer/core/src/services/dirty/dirty-scope-resolver.js +66 -0
  133. package/dist/server/modules/affairs-indexer/core/src/services/dirty/dirty-scope-resolver.js.map +1 -0
  134. package/dist/server/modules/affairs-indexer/core/src/services/export/export-builder.d.ts +33 -0
  135. package/dist/server/modules/affairs-indexer/core/src/services/export/export-builder.js +705 -0
  136. package/dist/server/modules/affairs-indexer/core/src/services/export/export-builder.js.map +1 -0
  137. package/dist/server/modules/affairs-indexer/core/src/services/indexer/allowed-extensions-diff-service.d.ts +80 -0
  138. package/dist/server/modules/affairs-indexer/core/src/services/indexer/allowed-extensions-diff-service.js +193 -0
  139. package/dist/server/modules/affairs-indexer/core/src/services/indexer/allowed-extensions-diff-service.js.map +1 -0
  140. package/dist/server/modules/affairs-indexer/core/src/services/indexer/text-indexer.d.ts +77 -0
  141. package/dist/server/modules/affairs-indexer/core/src/services/indexer/text-indexer.js +467 -0
  142. package/dist/server/modules/affairs-indexer/core/src/services/indexer/text-indexer.js.map +1 -0
  143. package/dist/server/modules/affairs-indexer/core/src/services/mcp/mcp-stdio-server.d.ts +17 -0
  144. package/dist/server/modules/affairs-indexer/core/src/services/mcp/mcp-stdio-server.js +264 -0
  145. package/dist/server/modules/affairs-indexer/core/src/services/mcp/mcp-stdio-server.js.map +1 -0
  146. package/dist/server/modules/affairs-indexer/core/src/services/search/offline-search-service.d.ts +11 -0
  147. package/dist/server/modules/affairs-indexer/core/src/services/search/offline-search-service.js +76 -0
  148. package/dist/server/modules/affairs-indexer/core/src/services/search/offline-search-service.js.map +1 -0
  149. package/dist/server/modules/affairs-indexer/core/src/services/search/search-index-builder.d.ts +26 -0
  150. package/dist/server/modules/affairs-indexer/core/src/services/search/search-index-builder.js +305 -0
  151. package/dist/server/modules/affairs-indexer/core/src/services/search/search-index-builder.js.map +1 -0
  152. package/dist/server/modules/affairs-indexer/core/src/services/tagging/tag-recompute-service.d.ts +53 -0
  153. package/dist/server/modules/affairs-indexer/core/src/services/tagging/tag-recompute-service.js +566 -0
  154. package/dist/server/modules/affairs-indexer/core/src/services/tagging/tag-recompute-service.js.map +1 -0
  155. package/dist/server/modules/affairs-indexer/core/src/services/watch/watch-service.d.ts +47 -0
  156. package/dist/server/modules/affairs-indexer/core/src/services/watch/watch-service.js +227 -0
  157. package/dist/server/modules/affairs-indexer/core/src/services/watch/watch-service.js.map +1 -0
  158. package/dist/server/modules/affairs-indexer/core/src/sqlite/catalog-schema.d.ts +5 -0
  159. package/dist/server/modules/affairs-indexer/core/src/sqlite/catalog-schema.js +245 -0
  160. package/dist/server/modules/affairs-indexer/core/src/sqlite/catalog-schema.js.map +1 -0
  161. package/dist/server/modules/affairs-indexer/core/src/sqlite/detect-catalog-schema.d.ts +14 -0
  162. package/dist/server/modules/affairs-indexer/core/src/sqlite/detect-catalog-schema.js +87 -0
  163. package/dist/server/modules/affairs-indexer/core/src/sqlite/detect-catalog-schema.js.map +1 -0
  164. package/dist/server/modules/affairs-indexer/core/src/sqlite/init-catalog.d.ts +13 -0
  165. package/dist/server/modules/affairs-indexer/core/src/sqlite/init-catalog.js +16 -0
  166. package/dist/server/modules/affairs-indexer/core/src/sqlite/init-catalog.js.map +1 -0
  167. package/dist/server/modules/affairs-indexer/core/src/sqlite/migration-runner.d.ts +22 -0
  168. package/dist/server/modules/affairs-indexer/core/src/sqlite/migration-runner.js +430 -0
  169. package/dist/server/modules/affairs-indexer/core/src/sqlite/migration-runner.js.map +1 -0
  170. package/dist/server/modules/affairs-indexer/core/src/sqlite/open-database.d.ts +9 -0
  171. package/dist/server/modules/affairs-indexer/core/src/sqlite/open-database.js +19 -0
  172. package/dist/server/modules/affairs-indexer/core/src/sqlite/open-database.js.map +1 -0
  173. package/dist/server/modules/affairs-indexer/core/src/tagging/simple-tag-inference.d.ts +21 -0
  174. package/dist/server/modules/affairs-indexer/core/src/tagging/simple-tag-inference.js +94 -0
  175. package/dist/server/modules/affairs-indexer/core/src/tagging/simple-tag-inference.js.map +1 -0
  176. package/dist/server/modules/affairs-indexer/core/src/utils/abort.d.ts +2 -0
  177. package/dist/server/modules/affairs-indexer/core/src/utils/abort.js +13 -0
  178. package/dist/server/modules/affairs-indexer/core/src/utils/abort.js.map +1 -0
  179. package/dist/server/modules/affairs-indexer/core/src/utils/file-streaming.d.ts +9 -0
  180. package/dist/server/modules/affairs-indexer/core/src/utils/file-streaming.js +64 -0
  181. package/dist/server/modules/affairs-indexer/core/src/utils/file-streaming.js.map +1 -0
  182. package/dist/server/modules/affairs-indexer/core/src/utils/root-command-lock.d.ts +10 -0
  183. package/dist/server/modules/affairs-indexer/core/src/utils/root-command-lock.js +230 -0
  184. package/dist/server/modules/affairs-indexer/core/src/utils/root-command-lock.js.map +1 -0
  185. package/dist/server/modules/affairs-indexer/core/src/utils/rss-log.d.ts +2 -0
  186. package/dist/server/modules/affairs-indexer/core/src/utils/rss-log.js +19 -0
  187. package/dist/server/modules/affairs-indexer/core/src/utils/rss-log.js.map +1 -0
  188. package/dist/server/modules/affairs-indexer/internal-command-runner.d.ts +31 -0
  189. package/dist/server/modules/affairs-indexer/internal-command-runner.js +643 -0
  190. package/dist/server/modules/affairs-indexer/internal-command-runner.js.map +1 -0
  191. package/dist/server/modules/assistant-capability/assistant-capability-controller.d.ts +0 -49
  192. package/dist/server/modules/assistant-capability/assistant-capability-controller.js +10 -56
  193. package/dist/server/modules/assistant-capability/assistant-capability-controller.js.map +1 -1
  194. package/dist/server/modules/assistant-capability/assistant-capability-service.d.ts +2 -46
  195. package/dist/server/modules/assistant-capability/assistant-capability-service.js +15 -158
  196. package/dist/server/modules/assistant-capability/assistant-capability-service.js.map +1 -1
  197. package/dist/server/modules/browser-runtime/opencli-bridge-browser-executor.d.ts +4 -2
  198. package/dist/server/modules/browser-runtime/opencli-bridge-browser-executor.js +62 -21
  199. package/dist/server/modules/browser-runtime/opencli-bridge-browser-executor.js.map +1 -1
  200. package/dist/server/modules/butler/butler-control-session-service.d.ts +3 -4
  201. package/dist/server/modules/butler/butler-control-session-service.js +39 -62
  202. package/dist/server/modules/butler/butler-control-session-service.js.map +1 -1
  203. package/dist/server/modules/butler/butler-controller.d.ts +11 -3
  204. package/dist/server/modules/butler/butler-controller.js +19 -4
  205. package/dist/server/modules/butler/butler-controller.js.map +1 -1
  206. package/dist/server/modules/butler/butler-follow-up-service.js.map +1 -1
  207. package/dist/server/modules/butler/butler-profile-service.d.ts +1 -1
  208. package/dist/server/modules/butler/butler-profile-service.js +34 -63
  209. package/dist/server/modules/butler/butler-profile-service.js.map +1 -1
  210. package/dist/server/modules/butler/butler-project-service.d.ts +1 -3
  211. package/dist/server/modules/butler/butler-project-service.js +1 -7
  212. package/dist/server/modules/butler/butler-project-service.js.map +1 -1
  213. package/dist/server/modules/butler/butler-session-service.d.ts +1 -0
  214. package/dist/server/modules/butler/butler-session-service.js +109 -0
  215. package/dist/server/modules/butler/butler-session-service.js.map +1 -1
  216. package/dist/server/modules/butler/butler-session-summary-service.js +0 -2
  217. package/dist/server/modules/butler/butler-session-summary-service.js.map +1 -1
  218. package/dist/server/modules/butler/butler-workspace-context.d.ts +5 -1
  219. package/dist/server/modules/butler/butler-workspace-context.js +21 -12
  220. package/dist/server/modules/butler/butler-workspace-context.js.map +1 -1
  221. package/dist/server/modules/file/file-content-service.d.ts +11 -0
  222. package/dist/server/modules/file/file-content-service.js +55 -0
  223. package/dist/server/modules/file/file-content-service.js.map +1 -1
  224. package/dist/server/modules/file/file-controller.d.ts +26 -1
  225. package/dist/server/modules/file/file-controller.js +59 -4
  226. package/dist/server/modules/file/file-controller.js.map +1 -1
  227. package/dist/server/modules/file/file-preview-link-service.d.ts +1 -0
  228. package/dist/server/modules/file/file-preview-link-service.js +25 -0
  229. package/dist/server/modules/file/file-preview-link-service.js.map +1 -1
  230. package/dist/server/modules/file/file-preview-service.js +15 -4
  231. package/dist/server/modules/file/file-preview-service.js.map +1 -1
  232. package/dist/server/modules/file/file-preview-types.d.ts +9 -1
  233. package/dist/server/modules/file/file-preview-types.js +8 -1
  234. package/dist/server/modules/file/file-preview-types.js.map +1 -1
  235. package/dist/server/modules/file/recent-modified-file-service.d.ts +15 -0
  236. package/dist/server/modules/file/recent-modified-file-service.js +102 -0
  237. package/dist/server/modules/file/recent-modified-file-service.js.map +1 -0
  238. package/dist/server/modules/file/runtime/codingns-workspace-bridge.js +6 -0
  239. package/dist/server/modules/file/workspace-file-bridge-service.d.ts +11 -0
  240. package/dist/server/modules/file/workspace-file-bridge-service.js +19 -0
  241. package/dist/server/modules/file/workspace-file-bridge-service.js.map +1 -1
  242. package/dist/server/modules/file/workspace-index-apply-service.d.ts +25 -0
  243. package/dist/server/modules/file/workspace-index-apply-service.js +42 -0
  244. package/dist/server/modules/file/workspace-index-apply-service.js.map +1 -0
  245. package/dist/server/modules/office/office-controller.d.ts +15 -1
  246. package/dist/server/modules/office/office-controller.js +26 -1
  247. package/dist/server/modules/office/office-controller.js.map +1 -1
  248. package/dist/server/modules/office/onlyoffice-integration-service.d.ts +78 -0
  249. package/dist/server/modules/office/onlyoffice-integration-service.js +610 -0
  250. package/dist/server/modules/office/onlyoffice-integration-service.js.map +1 -0
  251. package/dist/server/modules/plugins/plugin-file-gateway-service.d.ts +12 -0
  252. package/dist/server/modules/plugins/plugin-file-gateway-service.js +13 -0
  253. package/dist/server/modules/plugins/plugin-file-gateway-service.js.map +1 -1
  254. package/dist/server/modules/preferences/profile-service.d.ts +1 -0
  255. package/dist/server/modules/preferences/profile-service.js +27 -3
  256. package/dist/server/modules/preferences/profile-service.js.map +1 -1
  257. package/dist/server/modules/sessions/codex-app-server-helper-process.js +0 -8
  258. package/dist/server/modules/sessions/codex-app-server-helper-process.js.map +1 -1
  259. package/dist/server/modules/sessions/session-controller.d.ts +1 -0
  260. package/dist/server/modules/sessions/session-controller.js +3 -0
  261. package/dist/server/modules/sessions/session-controller.js.map +1 -1
  262. package/dist/server/modules/sessions/session-history-service.d.ts +2 -0
  263. package/dist/server/modules/sessions/session-history-service.js +78 -3
  264. package/dist/server/modules/sessions/session-history-service.js.map +1 -1
  265. package/dist/server/modules/sessions/session-live-runtime-service.d.ts +1 -0
  266. package/dist/server/modules/sessions/session-live-runtime-service.js +4 -0
  267. package/dist/server/modules/sessions/session-live-runtime-service.js.map +1 -1
  268. package/dist/server/modules/sessions/session-permission-request-service.js +0 -4
  269. package/dist/server/modules/sessions/session-permission-request-service.js.map +1 -1
  270. package/dist/server/modules/sessions/workspace-session-instruction-watch-service.d.ts +23 -0
  271. package/dist/server/modules/sessions/workspace-session-instruction-watch-service.js +122 -0
  272. package/dist/server/modules/sessions/workspace-session-instruction-watch-service.js.map +1 -0
  273. package/dist/server/modules/sessions/workspace-session-runtime-context-service.d.ts +15 -0
  274. package/dist/server/modules/sessions/workspace-session-runtime-context-service.js +93 -10
  275. package/dist/server/modules/sessions/workspace-session-runtime-context-service.js.map +1 -1
  276. package/dist/server/modules/skills/builtin-skills/codingns-assistant/SKILL.md +6 -7
  277. package/dist/server/modules/skills/builtin-skills/codingns-assistant/references/cli-workflow.md +2 -3
  278. package/dist/server/modules/system/host-resource-controller.d.ts +7 -0
  279. package/dist/server/modules/system/host-resource-controller.js +12 -0
  280. package/dist/server/modules/system/host-resource-controller.js.map +1 -0
  281. package/dist/server/modules/system/host-resource-service.d.ts +54 -0
  282. package/dist/server/modules/system/host-resource-service.js +162 -0
  283. package/dist/server/modules/system/host-resource-service.js.map +1 -0
  284. package/dist/server/modules/tasks/observability-service.d.ts +12 -2
  285. package/dist/server/modules/tasks/observability-service.js +13 -1
  286. package/dist/server/modules/tasks/observability-service.js.map +1 -1
  287. package/dist/server/modules/tasks/task-helper-client.d.ts +36 -2
  288. package/dist/server/modules/tasks/task-helper-client.js +201 -19
  289. package/dist/server/modules/tasks/task-helper-client.js.map +1 -1
  290. package/dist/server/modules/tasks/task-helper-pool.d.ts +37 -0
  291. package/dist/server/modules/tasks/task-helper-pool.js +173 -0
  292. package/dist/server/modules/tasks/task-helper-pool.js.map +1 -0
  293. package/dist/server/modules/tasks/task-helper-process-handlers.d.ts +27 -0
  294. package/dist/server/modules/tasks/task-helper-process-handlers.js +25 -1
  295. package/dist/server/modules/tasks/task-helper-process-handlers.js.map +1 -1
  296. package/dist/server/modules/tasks/task-helper-process.js +75 -26
  297. package/dist/server/modules/tasks/task-helper-process.js.map +1 -1
  298. package/dist/server/modules/tasks/task-helper-scheduling.d.ts +11 -0
  299. package/dist/server/modules/tasks/task-helper-scheduling.js +43 -0
  300. package/dist/server/modules/tasks/task-helper-scheduling.js.map +1 -0
  301. package/dist/server/modules/tasks/task-lane-executors.js +19 -3
  302. package/dist/server/modules/tasks/task-lane-executors.js.map +1 -1
  303. package/dist/server/modules/tasks/task-manager.d.ts +1 -0
  304. package/dist/server/modules/tasks/task-manager.js +3 -0
  305. package/dist/server/modules/tasks/task-manager.js.map +1 -1
  306. package/dist/server/modules/tasks/task-registry.d.ts +1 -0
  307. package/dist/server/modules/tasks/task-registry.js +3 -0
  308. package/dist/server/modules/tasks/task-registry.js.map +1 -1
  309. package/dist/server/modules/tasks/task-scheduler.d.ts +6 -0
  310. package/dist/server/modules/tasks/task-scheduler.js +162 -7
  311. package/dist/server/modules/tasks/task-scheduler.js.map +1 -1
  312. package/dist/server/modules/tasks/task-types.d.ts +28 -3
  313. package/dist/server/modules/tasks/task-types.js +14 -2
  314. package/dist/server/modules/tasks/task-types.js.map +1 -1
  315. package/dist/server/modules/workbench/affairs-assistant-session-snapshot-service.d.ts +68 -0
  316. package/dist/server/modules/workbench/affairs-assistant-session-snapshot-service.js +286 -0
  317. package/dist/server/modules/workbench/affairs-assistant-session-snapshot-service.js.map +1 -0
  318. package/dist/server/modules/workbench/workbench-controller.js +11 -1
  319. package/dist/server/modules/workbench/workbench-controller.js.map +1 -1
  320. package/dist/server/modules/workbench/workbench-service.d.ts +9 -2
  321. package/dist/server/modules/workbench/workbench-service.js +58 -18
  322. package/dist/server/modules/workbench/workbench-service.js.map +1 -1
  323. package/dist/server/modules/workspace/affairs-library-controller.d.ts +117 -0
  324. package/dist/server/modules/workspace/affairs-library-controller.js +164 -0
  325. package/dist/server/modules/workspace/affairs-library-controller.js.map +1 -0
  326. package/dist/server/modules/workspace/affairs-library-debug-log.d.ts +23 -0
  327. package/dist/server/modules/workspace/affairs-library-debug-log.js +107 -0
  328. package/dist/server/modules/workspace/affairs-library-debug-log.js.map +1 -0
  329. package/dist/server/modules/workspace/affairs-library-dirty-watch-service.d.ts +52 -0
  330. package/dist/server/modules/workspace/affairs-library-dirty-watch-service.js +555 -0
  331. package/dist/server/modules/workspace/affairs-library-dirty-watch-service.js.map +1 -0
  332. package/dist/server/modules/workspace/affairs-library-preview-link-service.d.ts +24 -0
  333. package/dist/server/modules/workspace/affairs-library-preview-link-service.js +157 -0
  334. package/dist/server/modules/workspace/affairs-library-preview-link-service.js.map +1 -0
  335. package/dist/server/modules/workspace/affairs-library-refresh-contract.d.ts +56 -0
  336. package/dist/server/modules/workspace/affairs-library-refresh-contract.js +48 -0
  337. package/dist/server/modules/workspace/affairs-library-refresh-contract.js.map +1 -0
  338. package/dist/server/modules/workspace/affairs-library-service.d.ts +344 -0
  339. package/dist/server/modules/workspace/affairs-library-service.js +3755 -0
  340. package/dist/server/modules/workspace/affairs-library-service.js.map +1 -0
  341. package/dist/server/modules/workspace/affairs-lightweight-session-controller.d.ts +78 -0
  342. package/dist/server/modules/workspace/affairs-lightweight-session-controller.js +146 -0
  343. package/dist/server/modules/workspace/affairs-lightweight-session-controller.js.map +1 -0
  344. package/dist/server/modules/workspace/affairs-lightweight-session-service.d.ts +133 -0
  345. package/dist/server/modules/workspace/affairs-lightweight-session-service.js +1447 -0
  346. package/dist/server/modules/workspace/affairs-lightweight-session-service.js.map +1 -0
  347. package/dist/server/modules/workspace/affairs-tag-controller.d.ts +107 -0
  348. package/dist/server/modules/workspace/affairs-tag-controller.js +97 -0
  349. package/dist/server/modules/workspace/affairs-tag-controller.js.map +1 -0
  350. package/dist/server/modules/workspace/affairs-tag-service.d.ts +153 -0
  351. package/dist/server/modules/workspace/affairs-tag-service.js +680 -0
  352. package/dist/server/modules/workspace/affairs-tag-service.js.map +1 -0
  353. package/dist/server/modules/workspace/workspace-controller.d.ts +2 -1
  354. package/dist/server/modules/workspace/workspace-controller.js +8 -2
  355. package/dist/server/modules/workspace/workspace-controller.js.map +1 -1
  356. package/dist/server/modules/workspace/workspace-service.js +60 -9
  357. package/dist/server/modules/workspace/workspace-service.js.map +1 -1
  358. package/dist/server/routes/affairs.d.ts +3 -0
  359. package/dist/server/routes/affairs.js +7 -0
  360. package/dist/server/routes/affairs.js.map +1 -0
  361. package/dist/server/routes/assistant.js +0 -5
  362. package/dist/server/routes/assistant.js.map +1 -1
  363. package/dist/server/routes/files.js +5 -0
  364. package/dist/server/routes/files.js.map +1 -1
  365. package/dist/server/routes/office.js +4 -0
  366. package/dist/server/routes/office.js.map +1 -1
  367. package/dist/server/routes/system.d.ts +2 -1
  368. package/dist/server/routes/system.js +2 -1
  369. package/dist/server/routes/system.js.map +1 -1
  370. package/dist/server/routes/workspaces.d.ts +4 -1
  371. package/dist/server/routes/workspaces.js +46 -1
  372. package/dist/server/routes/workspaces.js.map +1 -1
  373. package/dist/server/server/create-server.d.ts +6 -2
  374. package/dist/server/server/create-server.js +113 -32
  375. package/dist/server/server/create-server.js.map +1 -1
  376. package/dist/server/shared/http/error-handler.js +10 -0
  377. package/dist/server/shared/http/error-handler.js.map +1 -1
  378. package/dist/server/storage/repositories/affairs-assistant-session-snapshot-repository.d.ts +10 -0
  379. package/dist/server/storage/repositories/affairs-assistant-session-snapshot-repository.js +47 -0
  380. package/dist/server/storage/repositories/affairs-assistant-session-snapshot-repository.js.map +1 -0
  381. package/dist/server/storage/repositories/butler-profile-repository.js +7 -3
  382. package/dist/server/storage/repositories/butler-profile-repository.js.map +1 -1
  383. package/dist/server/storage/repositories/office-onlyoffice-setting-repository.d.ts +19 -0
  384. package/dist/server/storage/repositories/office-onlyoffice-setting-repository.js +55 -0
  385. package/dist/server/storage/repositories/office-onlyoffice-setting-repository.js.map +1 -0
  386. package/dist/server/storage/repositories/session-index-repository.js +9 -2
  387. package/dist/server/storage/repositories/session-index-repository.js.map +1 -1
  388. package/dist/server/storage/repositories/user-affairs-library-setting-repository.d.ts +10 -0
  389. package/dist/server/storage/repositories/user-affairs-library-setting-repository.js +69 -0
  390. package/dist/server/storage/repositories/user-affairs-library-setting-repository.js.map +1 -0
  391. package/dist/server/storage/repositories/user-preference-profile-repository.js +6 -3
  392. package/dist/server/storage/repositories/user-preference-profile-repository.js.map +1 -1
  393. package/dist/server/storage/repositories/workspace-navigation-state-repository.d.ts +3 -0
  394. package/dist/server/storage/repositories/workspace-navigation-state-repository.js +47 -4
  395. package/dist/server/storage/repositories/workspace-navigation-state-repository.js.map +1 -1
  396. package/dist/server/storage/sqlite/client.js +230 -123
  397. package/dist/server/storage/sqlite/client.js.map +1 -1
  398. package/dist/server/storage/sqlite/schema.sql +48 -25
  399. package/dist/server/types/domain.d.ts +27 -20
  400. package/dist/server/ws/workbench-ws-hub.js +2 -2
  401. package/dist/server/ws/workbench-ws-hub.js.map +1 -1
  402. package/node_modules/@codingns/session-sync-core/dist/runtime/codex-permissions.js +0 -2
  403. package/node_modules/@codingns/session-sync-core/dist/runtime/codex-permissions.js.map +1 -1
  404. package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.js +0 -6
  405. package/node_modules/@codingns/session-sync-core/dist/runtime/codex-runtime.js.map +1 -1
  406. package/package.json +1 -1
  407. package/dist/public/assets/AdaptiveButlerPage-B153lk5H.css +0 -1
  408. package/dist/public/assets/AdaptiveButlerPage-CJw8Ae62.js +0 -3
  409. package/dist/public/assets/DesktopModal-D_A8sgQU.js +0 -1
  410. package/dist/public/assets/DesktopWindowPage-DK7L7osV.js +0 -2
  411. package/dist/public/assets/FileContextPanel-BdCoubcJ.js +0 -1
  412. package/dist/public/assets/GitSidebar-BeZ0hj7A.js +0 -6
  413. package/dist/public/assets/MobileCreateSessionSheet-DfLMVu8q.js +0 -1
  414. package/dist/public/assets/MobileSheet-5kZ-w-gU.js +0 -1
  415. package/dist/public/assets/MobileWorkspaceSwitcherHeader-C6JMiOq_.js +0 -1
  416. package/dist/public/assets/PluginContainerPage-BlY-xJDh.js +0 -1
  417. package/dist/public/assets/SessionIndexPage-DkBp9Mqz.js +0 -1
  418. package/dist/public/assets/SettingsPage-C-ASmJAG.js +0 -2
  419. package/dist/public/assets/TerminalRuntimeFallbackModal-Bzum5nZ0.js +0 -1
  420. package/dist/public/assets/WorkbenchLayout-OFi6CWgH.js +0 -244
  421. package/dist/public/assets/WorkbenchShellRoute-B4XB8SwG.css +0 -1
  422. package/dist/public/assets/WorkbenchShellRoute-BAQe_E0O.js +0 -1
  423. package/dist/public/assets/WorkspaceDebugDetailPage-DhKa6e9y.js +0 -1
  424. package/dist/public/assets/file-tree-icon-Mg1DiBRX.js +0 -590
  425. package/dist/public/assets/index-C4t-vvqk.css +0 -1
  426. package/dist/public/assets/index-CL97fwWB.js +0 -42
  427. package/dist/public/assets/realtime-client-CLafKzzJ.js +0 -1
  428. package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.d.ts +0 -32
  429. package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.js +0 -93
  430. package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.js.map +0 -1
  431. package/dist/server/modules/butler/assistant-sandbox-service.d.ts +0 -69
  432. package/dist/server/modules/butler/assistant-sandbox-service.js +0 -399
  433. package/dist/server/modules/butler/assistant-sandbox-service.js.map +0 -1
  434. package/dist/server/modules/channels/wechat-claw-client.d.ts +0 -51
  435. package/dist/server/modules/channels/wechat-claw-client.js +0 -245
  436. package/dist/server/modules/channels/wechat-claw-client.js.map +0 -1
  437. package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.d.ts +0 -18
  438. package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.js +0 -191
  439. package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.js.map +0 -1
@@ -1,590 +0,0 @@
1
- import{C as J,t as p,b as y,j as a,K as rr,J as or,D as ir,A as Ot}from"./index-CL97fwWB.js";import{M as ar,D as sr}from"./DesktopModal-D_A8sgQU.js";import{i as Zt,f as fn,e as hn}from"./App-BOHBGFOd.js";import{bU as jt,bV as lr,bW as cr,bX as dr}from"./WorkbenchLayout-OFi6CWgH.js";function ur(e){const t=new URLSearchParams({workspaceId:e});return J.request(`/api/files/workspace-bridge/capabilities?${t.toString()}`)}function fr(e,t,n){return J.request("/api/files/workspace-bridge/list-dir",{method:"POST",body:JSON.stringify({workspaceId:e,path:t,options:n})})}function hr(e,t){return J.request("/api/files/workspace-bridge/read-text",{method:"POST",body:JSON.stringify({workspaceId:e,path:t})})}function pr(e,t){return J.request("/api/files/workspace-bridge/read-texts",{method:"POST",body:JSON.stringify({workspaceId:e,paths:t})})}function mr(e,t,n,r){return J.request("/api/files/workspace-bridge/write-text",{method:"POST",body:JSON.stringify({workspaceId:e,path:t,content:n,options:r})})}function gr(e,t,n){return J.request("/api/files/workspace-bridge/delete-file",{method:"POST",body:JSON.stringify({workspaceId:e,path:t,options:n})})}function xr(e,t){const n=new URLSearchParams({workspaceId:e,path:t});return J.request(`/api/files/workspace-bridge/stat?${n.toString()}`)}function yr(e,t){const n=new URLSearchParams({workspaceId:e,path:t});return J.request(`/api/files/workspace-bridge/exists?${n.toString()}`)}function vr(e,t){return J.request("/api/files/workspace-bridge/open-file",{method:"POST",body:JSON.stringify({workspaceId:e,path:t})})}function wr(e,t){return J.request("/api/files/workspace-bridge/reveal-in-file-manager",{method:"POST",body:JSON.stringify({workspaceId:e,path:t})})}function br(e,t,n){return J.request("/api/files/workspace-bridge/watch-dir",{method:"POST",body:JSON.stringify({workspaceId:e,path:t,options:n})})}function Qt(e){return J.request("/api/files/workspace-bridge/unwatch",{method:"POST",body:JSON.stringify({watchId:e})})}function Nr(e,t){const n=new URLSearchParams({watchId:e});return typeof t=="number"&&Number.isFinite(t)&&n.set("cursor",String(Math.floor(t))),J.request(`/api/files/workspace-bridge/watch-events?${n.toString()}`)}function Sr(e){var N;const t=new Map;let n=null;const r={lastEventOrigin:null,lastEventMatchedSource:!1,lastEventRequestId:null,lastEventAction:null,lastResponseId:null,lastResponseOrigin:null,lastHandledRequestId:null,currentIframeWindowMatches:!1};o("create",{hasIframe:!!e.iframe,hasContentWindow:!!((N=e.iframe)!=null&&N.contentWindow),workspaceId:e.workspaceId??null});function o(m,u){const P={at:new Date().toISOString(),source:"html-preview-host",stage:m,payload:u??{}};typeof console<"u"&&typeof console.debug=="function"&&console.debug(`[html-preview-bridge] ${m}`,u??{}),i(P)}function i(m){var P;const u=(P=e.iframe)==null?void 0:P.contentWindow;!u||typeof u.postMessage!="function"||u.postMessage({type:"codingns.workspace.debug",payload:m},n??"*")}function s(m,u,P,k,L){o("post-error",{id:u.id,action:u.action,code:P,message:k,path:L,origin:m.origin}),d(m,{type:"codingns.workspace.response",id:u.id,ok:!1,error:{code:P,message:k,path:L}})}function d(m,u){const P=m.source;if(r.lastResponseId=u.id,r.lastResponseOrigin=m.origin,o("post-response",{id:u.id,ok:u.ok,origin:m.origin,targetCanPostMessage:Tt(P)}),!Tt(P)){o("drop-response",{id:u.id,reason:"event.source cannot postMessage",origin:m.origin});return}P.postMessage(u,m.origin)}function g(m){var P;const u=(P=e.iframe)==null?void 0:P.contentWindow;if(!u||!n){o("drop-watch-event",{watchId:m.watchId,hasIframeWindow:!!u,iframeOrigin:n});return}o("post-watch-event",{watchId:m.watchId,iframeOrigin:n}),u.postMessage(m,n)}async function x(m,u){var $,G;const P=($=e.iframe)==null?void 0:$.contentWindow,k=((G=e.workspaceId)==null?void 0:G.trim())??"",L=Tt(m.source),j=!!(P&&m.source===P);if(r.lastEventOrigin=m.origin,r.lastEventMatchedSource=j,r.lastEventRequestId=u.id,r.lastEventAction=u.action,r.currentIframeWindowMatches=j,o("handle-request",{id:u.id,action:u.action,origin:m.origin,hasIframeWindow:!!P,sourceCanPostMessage:L,sourceMatchesCurrentIframe:j,workspaceId:k||null}),!P||!L){o("drop-request",{id:u.id,action:u.action,reason:P?"event.source cannot postMessage":"missing iframe.contentWindow",origin:m.origin});return}if(n=m.origin,!k){s(m,u,"INTERNAL_ERROR","当前预览缺少 workspaceId");return}try{let W;const M=u.payload??{};switch(u.action){case"capabilities":W=await ur(k);break;case"listDir":W=await fr(k,typeof M.path=="string"?M.path:"",dt(M.options)?M.options:void 0);break;case"readText":W=await hr(k,typeof M.path=="string"?M.path:"");break;case"readTexts":W=await pr(k,Array.isArray(M.paths)?M.paths.filter(A=>typeof A=="string"):[]);break;case"writeText":W=await mr(k,typeof M.path=="string"?M.path:"",typeof M.content=="string"?M.content:"",dt(M.options)?M.options:void 0);break;case"deleteFile":W=await gr(k,typeof M.path=="string"?M.path:"",dt(M.options)?M.options:void 0);break;case"stat":W=await xr(k,typeof M.path=="string"?M.path:"");break;case"exists":W=await yr(k,typeof M.path=="string"?M.path:"");break;case"openWorkspaceFile":{const A=await vr(k,typeof M.path=="string"?M.path:""),U=await Zt().fs.openFile(A.absolutePath);if(!U.ok)throw{code:U.errorCode??"DESKTOP_OPEN_FAILED",message:U.detail??"打开文件失败",path:A.relativePath};W=A;break}case"revealWorkspaceFile":{const A=await wr(k,typeof M.path=="string"?M.path:""),U=await Zt().fs.revealInFileManager(A.absolutePath);if(!U.ok)throw{code:U.errorCode??"DESKTOP_REVEAL_FAILED",message:U.detail??"打开所在目录失败",path:A.relativePath};W=A;break}case"watchDir":{const A=await br(k,typeof M.path=="string"?M.path:"",dt(M.options)?M.options:void 0);f(A.watchId),W=A;break}case"unwatch":{const A=typeof M.watchId=="string"?M.watchId.trim():"";if(!A){s(m,u,"INVALID_WATCH_ID","必须提供 watchId");return}w(A),W=await Qt(A);break}default:s(m,u,"INTERNAL_ERROR",`不支持的 workspace bridge 动作:${u.action}`);return}o("handle-success",{id:u.id,action:u.action,origin:m.origin}),d(m,{type:"codingns.workspace.response",id:u.id,ok:!0,payload:W}),r.lastHandledRequestId=u.id}catch(W){const M=en(W);o("handle-error",{id:u.id,action:u.action,code:M.code,message:M.message,path:M.path}),s(m,u,M.code,M.message,M.path)}}return{async onMessage(m){if(!kr(m.data)){const u=m.data;u&&typeof u=="object"&&typeof u.type=="string"&&u.type.startsWith("codingns.")&&o("ignore-message",{origin:m.origin,type:u.type,reason:"not workspace bridge request"});return}o("incoming-message",{origin:m.origin,id:m.data.id,action:m.data.action}),await x(m,m.data)},debug:r,dispose(){o("dispose",{activeWatchCount:t.size,lastEventRequestId:r.lastEventRequestId,lastHandledRequestId:r.lastHandledRequestId});for(const m of[...t.keys()])w(m),Qt(m).catch(()=>{})}};function f(m){if(!m||t.has(m))return;const u={stopped:!1,cursor:0};t.set(m,u),E(m,u)}function w(m){const u=t.get(m);u&&(u.stopped=!0,t.delete(m))}async function E(m,u){for(;!u.stopped;){try{const P=await Nr(m,u.cursor);u.cursor=P.nextCursor;for(const k of P.events)g({type:"codingns.workspace.event",watchId:m,payload:k})}catch(P){if(en(P).code==="WATCH_NOT_FOUND"){w(m);return}}await Ir(700)}}}function Tt(e){return!!e&&typeof e=="object"&&typeof e.postMessage=="function"}function kr(e){if(!e||typeof e!="object")return!1;const t=e;return t.type==="codingns.workspace.request"&&typeof t.id=="string"&&typeof t.action=="string"}function dt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function en(e){if(typeof e=="object"&&e!==null){const t=e;return{code:typeof t.code=="string"?t.code:"INTERNAL_ERROR",message:typeof t.message=="string"?t.message:typeof t.detail=="string"?t.detail:"请求失败",path:typeof t.path=="string"?t.path:void 0}}return e instanceof Error?{code:"INTERNAL_ERROR",message:e.message||"请求失败"}:{code:"INTERNAL_ERROR",message:"请求失败"}}function Ir(e){return new Promise(t=>{window.setTimeout(t,e)})}async function Pr(e){return await J.request("/api/presentation-exports",{method:"POST",body:JSON.stringify(e)})}async function Er(e){return await J.request(`/api/presentation-exports/${encodeURIComponent(e)}`)}async function Rr(e){const t=`/api/presentation-exports/${encodeURIComponent(e)}/download`,n=await J.requestRaw(t),r=await n.blob();return{fileName:Cr(e,r.type,n.headers.get("Content-Disposition")),blob:r}}function Cr(e,t,n){const r=jr(n);return r||(t==="application/pdf"?`${e}.pdf`:t==="application/vnd.openxmlformats-officedocument.presentationml.presentation"?`${e}.pptx`:e)}function jr(e){var o;if(!e)return null;const t=/filename\*=UTF-8''([^;]+)/i.exec(e);if(t!=null&&t[1])return decodeURIComponent(t[1]);const n=/filename="([^"]+)"/i.exec(e)??/filename=([^;]+)/i.exec(e),r=(o=n==null?void 0:n[1])==null?void 0:o.trim();return r?decodeURIComponent(r.replace(/^"|"$/g,"")):null}const ze={width:1600,height:900},pn=[{strategy:"deck-section-slide",selector:"body .deck > section.slide"},{strategy:"deck-direct-slide",selector:"body .deck > .slide"},{strategy:"section-slide",selector:"section.slide"},{strategy:"slide-data-title",selector:".slide[data-title]"},{strategy:"slide-data-slide",selector:".slide[data-slide]"},{strategy:"deck-direct-child",selector:"body > .deck > *"}],Tr=[".panel",".slide-shell",".content",".hero-main",".slide-inner"],Ht=new Set(["H1","H2","H3","H4","P","LI","SPAN","BUTTON","A"]),mn=[".slide-progress",".progress-bar",".ctrl-btn",".toc",".particle",".particles",".bg-glow",".bg-grid",".page","script"].join(", "),Mr=["card","panel","metric","kpi","module","feature","timeline","diagram","table","grid","shell","content"],Lr={position:"position",fontFamily:"font-family",fontSize:"font-size",fontWeight:"font-weight",fontStyle:"font-style",lineHeight:"line-height",letterSpacing:"letter-spacing",color:"color",textAlign:"text-align",textDecoration:"text-decoration",textDecorationColor:"text-decoration-color",whiteSpace:"white-space",padding:"padding",margin:"margin",borderRadius:"border-radius",borderWidth:"border-width",borderColor:"border-color",backgroundColor:"background-color",opacity:"opacity"};function _t(e,t){if(!/\.(html?|HTML?)$/.test(t))return At("unsupported-extension");const n=Ut(e);if(!(n!=null&&n.documentElement)||!n.querySelector("html"))return At("invalid-html");const r=mt(n);if(!r)return At("missing-page-structure");const o=[],i=r.elements.map((s,d)=>{s.querySelector("svg")&&o.push(`第 ${d+1} 页包含 SVG,只能先按只读节点导入。`),s.querySelector(mn)&&o.push(`第 ${d+1} 页包含展示壳或装饰层,导入时会过滤非内容节点。`);const g=wn(s,d);return{index:d,title:Gr(s,d),selector:g,sourceRef:{pageIndex:d,pageSelector:g,nodePath:[]}}});return{supported:!0,reason:null,mode:"presentation",strategy:r.strategy,pages:i,warnings:Tn(o),viewport:Jr(n)}}function Ar(e){const t=_t(e.html,e.filePath);if(!t.supported)return null;const n=Ut(e.html),r=mt(n,t.strategy??void 0);if(!r)return null;const o=t.warnings.map((g,x)=>({code:`probe-warning-${x+1}`,message:g})),i={},s=[],d=r.elements.map((g,x)=>{var u,P,k;const f=`page-${x+1}`,w=`${f}-root`,E=eo(g),N=wn(g,x),m=to(g,E);if(i[w]=Nn({id:w,name:((u=t.pages[x])==null?void 0:u.title)??`第 ${x+1} 页`,sourceRef:{pageIndex:x,pageSelector:N,nodePath:m},runtimeFlags:E.hasAttribute("data-cns-layout-freeze")?["layout-freeze-container"]:[]}),$t({pageElement:g,containerElement:E,pageIndex:x,pageSelector:N,containerPath:m,parentNodeId:w,nodeIdPrefix:w,nodes:i,assets:s}),!i[w].children.length){const L=((P=g.textContent)==null?void 0:P.replace(/\s+/g," ").trim())??"";if(L){const j=`${w}-fallback-text`;i[j]=kn({id:j,name:"正文",text:L,sourceRef:{pageIndex:x,pageSelector:N,nodePath:m}}),i[w].children.push(j)}}return{id:f,order:x,title:((k=t.pages[x])==null?void 0:k.title)??`第 ${x+1} 页`,frame:{width:t.viewport.width,height:t.viewport.height,background:null},rootNodeId:w,sourceRef:{pageIndex:x,pageSelector:N,nodePath:[]},runtimeHints:{hasActiveStateClass:g.classList.contains("active"),hasDeckShell:!!g.closest(".deck")}}});return{id:yo(e.filePath),schemaVersion:1,mode:"presentation",source:{kind:e.sourceKind??"codingns",path:e.filePath,version:e.version??null,entryHtmlHash:Yt(e.html)},canvas:{width:t.viewport.width,height:t.viewport.height,unit:"px",aspectRatioLocked:!0},pages:d,nodes:i,assets:xo(s),warnings:o,meta:{originalTitle:n.title||null,pageDetectionStrategy:r.strategy}}}function zr(e){return gn({html:e.html,project:e.project,pageIndex:e.pageIndex,selectedNodeId:e.selectedNodeId??null,selectedRunIndex:e.selectedRunIndex??null,inlineEditingNodeId:e.inlineEditingNodeId??null,baseHref:e.baseHref??null,mode:"preview"})}function Vr(e){return gn({html:e.html,project:e.project,pageIndex:0,selectedNodeId:null,mode:"save"})}function gn(e){const t=Ut(e.html),n=mt(t,e.project.meta.pageDetectionStrategy);if(!n)return null;Kr({document:t,project:e.project,pageElements:n.elements});const r=mt(t,e.project.meta.pageDetectionStrategy);if(!r)return null;if(e.mode==="preview"&&($r(t,e.project),Fr(t,e.baseHref??null)),r.elements.forEach((o,i)=>{e.mode==="preview"&&(o.setAttribute("data-cns-page-root","true"),i===e.pageIndex?o.setAttribute("data-cns-active-page","true"):o.removeAttribute("data-cns-active-page"),o.classList.remove("prev","next"),o.classList.add("active"))}),Object.values(e.project.nodes).forEach(o=>{if(Fe(o,"draft-clone")||!o.sourceRef)return;const i=Mn(r.elements,o.sourceRef);i&&(e.mode==="preview"?(i.setAttribute("data-cns-node-id",o.id),i.removeAttribute("data-cns-node-selected"),i.removeAttribute("data-cns-inline-editing"),e.selectedNodeId&&o.id===e.selectedNodeId&&i.setAttribute("data-cns-node-selected","true"),e.inlineEditingNodeId&&o.id===e.inlineEditingNodeId&&i.setAttribute("data-cns-inline-editing","true")):(i.removeAttribute("data-cns-node-id"),i.removeAttribute("data-cns-node-selected"),i.removeAttribute("data-cns-inline-editing")),Ln(i,o),e.mode==="preview"&&So(i,o,{selected:e.selectedNodeId===o.id,selectedRunIndex:e.selectedNodeId===o.id?e.selectedRunIndex??null:null}))}),Object.values(e.project.nodes).forEach(o=>{Fe(o,"draft-clone-root")&&To({project:e.project,pageElements:r.elements,cloneRootNode:o,selectedNodeId:e.mode==="preview"?e.selectedNodeId:null,mode:e.mode})}),e.mode==="preview"){Wr(t);const o=t.createElement("style");o.textContent=`
2
- [data-cns-page-root="true"]:not([data-cns-active-page="true"]) {
3
- display: none !important;
4
- opacity: 0 !important;
5
- pointer-events: none !important;
6
- visibility: hidden !important;
7
- }
8
-
9
- [data-cns-page-root="true"][data-cns-active-page="true"] {
10
- opacity: 1 !important;
11
- pointer-events: auto !important;
12
- visibility: visible !important;
13
- transform: none !important;
14
- transition: none !important;
15
- width: ${e.project.canvas.width}px !important;
16
- min-width: ${e.project.canvas.width}px !important;
17
- max-width: ${e.project.canvas.width}px !important;
18
- height: ${e.project.canvas.height}px !important;
19
- min-height: ${e.project.canvas.height}px !important;
20
- max-height: ${e.project.canvas.height}px !important;
21
- margin: 0 !important;
22
- box-sizing: border-box !important;
23
- }
24
-
25
- [data-cns-node-selected="true"] {
26
- outline: 2px solid #007aff !important;
27
- outline-offset: 2px !important;
28
- box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.14) !important;
29
- }
30
-
31
- [data-cns-node-host="true"] {
32
- outline: none !important;
33
- box-shadow: none !important;
34
- }
35
-
36
- [data-cns-inline-editing="true"] {
37
- color: transparent !important;
38
- text-shadow: none !important;
39
- caret-color: transparent !important;
40
- }
41
-
42
- .deck {
43
- width: ${e.project.canvas.width}px !important;
44
- min-width: ${e.project.canvas.width}px !important;
45
- max-width: ${e.project.canvas.width}px !important;
46
- margin: 0 !important;
47
- }
48
-
49
- html,
50
- body {
51
- width: ${e.project.canvas.width}px !important;
52
- min-width: ${e.project.canvas.width}px !important;
53
- max-width: ${e.project.canvas.width}px !important;
54
- height: ${e.project.canvas.height}px !important;
55
- min-height: ${e.project.canvas.height}px !important;
56
- max-height: ${e.project.canvas.height}px !important;
57
- margin: 0 !important;
58
- padding: 0 !important;
59
- overflow: hidden !important;
60
- }
61
-
62
- body {
63
- transform-origin: center center !important;
64
- }
65
-
66
- body[data-cns-preview-body-scale-reset="true"] {
67
- transform: none !important;
68
- }
69
-
70
- [data-cns-page-root="true"][data-cns-active-page="true"] .fade-up,
71
- [data-cns-page-root="true"][data-cns-active-page="true"] .roadmap-line,
72
- [data-cns-page-root="true"][data-cns-active-page="true"] [class*="fade-"],
73
- [data-cns-page-root="true"][data-cns-active-page="true"] [class*="reveal-"] {
74
- opacity: 1 !important;
75
- transform: none !important;
76
- transition: none !important;
77
- transition-delay: 0s !important;
78
- animation-delay: 0s !important;
79
- }
80
-
81
- [data-cns-page-root="true"][data-cns-active-page="true"] .typing-cursor {
82
- opacity: 1 !important;
83
- animation: none !important;
84
- }
85
- `,t.head.appendChild(o);const i=t.createElement("script");i.setAttribute("data-cns-preview-bridge","true"),i.textContent=`
86
- (() => {
87
- const eventTypes = ["pointerdown", "click", "dblclick"];
88
- let layoutModeEnabled = false;
89
- let activeLayoutPointer = null;
90
- let layoutHoveredNodeId = null;
91
- const parsePixelValue = (value) => {
92
- if (!value) {
93
- return 0;
94
- }
95
-
96
- const matched = /-?\\d+(?:\\.\\d+)?/.exec(value);
97
- return matched ? Number(matched[0]) : 0;
98
- };
99
- const isTransparentColor = (value) => {
100
- if (!value) {
101
- return true;
102
- }
103
-
104
- const normalized = value.trim().toLowerCase();
105
-
106
- if (normalized === "transparent") {
107
- return true;
108
- }
109
-
110
- if (/rgba\\((?:\\d+\\s*,\\s*){3}0(?:\\.0+)?\\)/.test(normalized)) {
111
- return true;
112
- }
113
-
114
- return false;
115
- };
116
- const resolveTextNodes = (element) => {
117
- if (!element) {
118
- return [];
119
- }
120
-
121
- const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, {
122
- acceptNode(node) {
123
- return node.textContent && node.textContent.trim()
124
- ? NodeFilter.FILTER_ACCEPT
125
- : NodeFilter.FILTER_REJECT;
126
- }
127
- });
128
- const textNodes = [];
129
- let current = walker.nextNode();
130
-
131
- while (current) {
132
- textNodes.push(current);
133
- current = walker.nextNode();
134
- }
135
-
136
- return textNodes;
137
- };
138
- const resolveEditableRect = (element, computedStyle) => {
139
- if (!element || !element.getBoundingClientRect) {
140
- return {
141
- rect: null,
142
- useContentRect: false
143
- };
144
- }
145
-
146
- const elementRect = element.getBoundingClientRect();
147
-
148
- if (!computedStyle) {
149
- return {
150
- rect: elementRect,
151
- useContentRect: false
152
- };
153
- }
154
-
155
- const paddingLeft = parsePixelValue(computedStyle.paddingLeft);
156
- const paddingTop = parsePixelValue(computedStyle.paddingTop);
157
- const paddingRight = parsePixelValue(computedStyle.paddingRight);
158
- const paddingBottom = parsePixelValue(computedStyle.paddingBottom);
159
- const borderLeftWidth = parsePixelValue(computedStyle.borderLeftWidth);
160
- const borderTopWidth = parsePixelValue(computedStyle.borderTopWidth);
161
- const borderRightWidth = parsePixelValue(computedStyle.borderRightWidth);
162
- const borderBottomWidth = parsePixelValue(computedStyle.borderBottomWidth);
163
- const hasSurface = !isTransparentColor(computedStyle.backgroundColor)
164
- || borderLeftWidth > 0
165
- || borderTopWidth > 0
166
- || borderRightWidth > 0
167
- || borderBottomWidth > 0
168
- || paddingLeft > 0
169
- || paddingTop > 0
170
- || paddingRight > 0
171
- || paddingBottom > 0;
172
-
173
- if (!hasSurface) {
174
- return {
175
- rect: elementRect,
176
- useContentRect: false
177
- };
178
- }
179
-
180
- const textNodes = resolveTextNodes(element);
181
-
182
- if (textNodes.length > 0) {
183
- const range = document.createRange();
184
- range.setStart(textNodes[0], 0);
185
- range.setEnd(textNodes[textNodes.length - 1], textNodes[textNodes.length - 1].textContent.length);
186
- const textRect = range.getBoundingClientRect();
187
-
188
- if (textRect && textRect.width > 0 && textRect.height > 0) {
189
- return {
190
- rect: textRect,
191
- useContentRect: true
192
- };
193
- }
194
- }
195
-
196
- const innerWidth = Math.max(1, elementRect.width - paddingLeft - paddingRight - borderLeftWidth - borderRightWidth);
197
- const innerHeight = Math.max(1, elementRect.height - paddingTop - paddingBottom - borderTopWidth - borderBottomWidth);
198
-
199
- return {
200
- rect: {
201
- left: elementRect.left + paddingLeft + borderLeftWidth,
202
- top: elementRect.top + paddingTop + borderTopWidth,
203
- width: innerWidth,
204
- height: innerHeight
205
- },
206
- useContentRect: true
207
- };
208
- };
209
- const resolveElement = (target) => {
210
- if (!target || typeof target !== "object") {
211
- return null;
212
- }
213
-
214
- if (target.nodeType === Node.TEXT_NODE) {
215
- return target.parentElement;
216
- }
217
-
218
- if (target.nodeType === Node.ELEMENT_NODE) {
219
- return target;
220
- }
221
-
222
- return null;
223
- };
224
- const resolveLayoutMeasurementElement = (nodeId) => {
225
- const hostElement = document.querySelector('[data-cns-node-host-id="' + CSS.escape(nodeId) + '"]');
226
-
227
- if (hostElement instanceof HTMLElement) {
228
- return hostElement;
229
- }
230
-
231
- const element = document.querySelector('[data-cns-node-id="' + CSS.escape(nodeId) + '"]');
232
-
233
- if (!(element instanceof HTMLElement)) {
234
- return null;
235
- }
236
-
237
- if (element.parentElement?.getAttribute("data-cns-node-host") === "true") {
238
- return element.parentElement;
239
- }
240
-
241
- const hostParent = element.closest('[data-cns-node-host="true"]');
242
- return hostParent instanceof HTMLElement ? hostParent : element;
243
- };
244
- const resolveLayoutParentElement = (element) => {
245
- if (!(element instanceof HTMLElement)) {
246
- return document.body instanceof HTMLElement ? document.body : null;
247
- }
248
-
249
- const positionedParent = element.offsetParent;
250
-
251
- if (positionedParent instanceof HTMLElement) {
252
- return positionedParent;
253
- }
254
-
255
- return document.body instanceof HTMLElement ? document.body : null;
256
- };
257
-
258
- const handler = (event) => {
259
- const element = resolveElement(event.target);
260
-
261
- if (!element) {
262
- return;
263
- }
264
-
265
- const matched = element.closest("[data-cns-node-id]");
266
-
267
- if (!matched) {
268
- return;
269
- }
270
-
271
- const nodeId = matched.getAttribute("data-cns-node-id");
272
- const runIndexValue = matched.getAttribute("data-cns-run-index");
273
- const runIndex = runIndexValue !== null ? Number.parseInt(runIndexValue, 10) : null;
274
-
275
- if (!nodeId) {
276
- return;
277
- }
278
-
279
- const computedStyle = window.getComputedStyle ? window.getComputedStyle(matched) : null;
280
- const editableRect = resolveEditableRect(matched, computedStyle);
281
- const payload = {
282
- type: "codingns-static-html-node-select",
283
- nodeId,
284
- runIndex: Number.isInteger(runIndex) ? runIndex : null,
285
- eventType: event.type,
286
- metaKey: Boolean(event.metaKey),
287
- ctrlKey: Boolean(event.ctrlKey),
288
- rect: editableRect.rect
289
- ? {
290
- left: editableRect.rect.left,
291
- top: editableRect.rect.top,
292
- width: editableRect.rect.width,
293
- height: editableRect.rect.height
294
- }
295
- : matched.getBoundingClientRect
296
- ? {
297
- left: matched.getBoundingClientRect().left,
298
- top: matched.getBoundingClientRect().top,
299
- width: matched.getBoundingClientRect().width,
300
- height: matched.getBoundingClientRect().height
301
- }
302
- : null,
303
- appearance: computedStyle
304
- ? {
305
- fontFamily: computedStyle.fontFamily || null,
306
- fontSize: computedStyle.fontSize || null,
307
- fontWeight: computedStyle.fontWeight || null,
308
- fontStyle: computedStyle.fontStyle || null,
309
- lineHeight: computedStyle.lineHeight || null,
310
- letterSpacing: computedStyle.letterSpacing || null,
311
- color: computedStyle.color || null,
312
- textAlign: computedStyle.textAlign || null,
313
- whiteSpace: computedStyle.whiteSpace || null,
314
- padding: editableRect.useContentRect ? "0px" : (computedStyle.padding || null),
315
- textTransform: computedStyle.textTransform || null
316
- }
317
- : null
318
- };
319
-
320
- window.parent?.postMessage(payload, "*");
321
-
322
- if (layoutModeEnabled && event.type === "pointerdown") {
323
- if (typeof matched.setPointerCapture === "function" && typeof event.pointerId === "number") {
324
- try {
325
- matched.setPointerCapture(event.pointerId);
326
- } catch {
327
- // ignore setPointerCapture failures
328
- }
329
- }
330
-
331
- activeLayoutPointer = {
332
- pointerId: typeof event.pointerId === "number" ? event.pointerId : null,
333
- nodeId
334
- };
335
-
336
- window.parent?.postMessage({
337
- type: "codingns-static-html-layout-pointer",
338
- phase: "start",
339
- nodeId,
340
- clientX: event.clientX,
341
- clientY: event.clientY,
342
- metaKey: Boolean(event.metaKey),
343
- ctrlKey: Boolean(event.ctrlKey)
344
- }, "*");
345
-
346
- event.preventDefault();
347
- }
348
- };
349
-
350
- const handlePointerOver = (event) => {
351
- if (!layoutModeEnabled) {
352
- return;
353
- }
354
-
355
- const element = resolveElement(event.target);
356
- const matched = element?.closest ? element.closest("[data-cns-node-id]") : null;
357
- const nodeId = matched?.getAttribute("data-cns-node-id")?.trim() || null;
358
-
359
- if (nodeId === layoutHoveredNodeId) {
360
- return;
361
- }
362
-
363
- layoutHoveredNodeId = nodeId;
364
- window.parent?.postMessage({
365
- type: "codingns-static-html-layout-hover",
366
- nodeId: nodeId || ""
367
- }, "*");
368
- };
369
-
370
- const handlePointerLeaveViewport = () => {
371
- if (!layoutModeEnabled || !layoutHoveredNodeId) {
372
- return;
373
- }
374
-
375
- layoutHoveredNodeId = null;
376
- window.parent?.postMessage({
377
- type: "codingns-static-html-layout-hover",
378
- nodeId: ""
379
- }, "*");
380
- };
381
-
382
- const syncSelectionState = (payload) => {
383
- layoutModeEnabled = Boolean(payload?.layoutModeEnabled);
384
- layoutHoveredNodeId = typeof payload?.layoutHoveredNodeId === "string" && payload.layoutHoveredNodeId.trim()
385
- ? payload.layoutHoveredNodeId.trim()
386
- : null;
387
- if (!layoutModeEnabled) {
388
- activeLayoutPointer = null;
389
- layoutHoveredNodeId = null;
390
- }
391
-
392
- const selectedNodeId = typeof payload?.selectedNodeId === "string" && payload.selectedNodeId.trim()
393
- ? payload.selectedNodeId.trim()
394
- : null;
395
- const selectedRunIndex = typeof payload?.selectedRunIndex === "number" && Number.isInteger(payload.selectedRunIndex)
396
- ? payload.selectedRunIndex
397
- : null;
398
- const inlineEditingNodeId = typeof payload?.inlineEditingNodeId === "string" && payload.inlineEditingNodeId.trim()
399
- ? payload.inlineEditingNodeId.trim()
400
- : null;
401
- const layoutSelectedNodeIds = Array.isArray(payload?.layoutSelectedNodeIds)
402
- ? payload.layoutSelectedNodeIds.filter((value) => typeof value === "string" && value.trim()).map((value) => value.trim())
403
- : [];
404
-
405
- document.querySelectorAll("[data-cns-node-selected]").forEach((element) => {
406
- if (element.getAttribute("data-cns-node-id") !== selectedNodeId) {
407
- element.removeAttribute("data-cns-node-selected");
408
- }
409
- });
410
-
411
- document.querySelectorAll("[data-cns-inline-editing]").forEach((element) => {
412
- if (element.getAttribute("data-cns-node-id") !== inlineEditingNodeId) {
413
- element.removeAttribute("data-cns-inline-editing");
414
- }
415
- });
416
-
417
- if (selectedNodeId) {
418
- if (selectedRunIndex !== null) {
419
- const selectedRunElement = document.querySelector(
420
- '[data-cns-node-id="' + CSS.escape(selectedNodeId) + '"][data-cns-run-index="' + String(selectedRunIndex) + '"]'
421
- );
422
-
423
- if (selectedRunElement) {
424
- selectedRunElement.setAttribute("data-cns-node-selected", "true");
425
- }
426
- } else {
427
- const selectedElement = document.querySelector('[data-cns-node-id="' + CSS.escape(selectedNodeId) + '"]');
428
-
429
- if (selectedElement) {
430
- selectedElement.setAttribute("data-cns-node-selected", "true");
431
- }
432
- }
433
- }
434
-
435
- document.querySelectorAll("[data-cns-layout-selected]").forEach((element) => {
436
- if (!layoutSelectedNodeIds.includes(element.getAttribute("data-cns-node-id") || "")) {
437
- element.removeAttribute("data-cns-layout-selected");
438
- }
439
- });
440
-
441
- document.querySelectorAll("[data-cns-layout-hovered]").forEach((element) => {
442
- if (element.getAttribute("data-cns-node-id") !== layoutHoveredNodeId) {
443
- element.removeAttribute("data-cns-layout-hovered");
444
- }
445
- });
446
-
447
- layoutSelectedNodeIds.forEach((nodeId) => {
448
- const layoutElement = resolveLayoutMeasurementElement(nodeId);
449
-
450
- if (layoutElement) {
451
- layoutElement.setAttribute("data-cns-layout-selected", "true");
452
- }
453
- });
454
-
455
- if (layoutHoveredNodeId) {
456
- const hoveredElement = resolveLayoutMeasurementElement(layoutHoveredNodeId);
457
-
458
- if (hoveredElement) {
459
- hoveredElement.setAttribute("data-cns-layout-hovered", "true");
460
- }
461
- }
462
-
463
- if (inlineEditingNodeId) {
464
- const editingElement = document.querySelector('[data-cns-node-id="' + CSS.escape(inlineEditingNodeId) + '"]');
465
-
466
- if (editingElement) {
467
- editingElement.setAttribute("data-cns-inline-editing", "true");
468
- }
469
- }
470
- };
471
-
472
- const postLayoutMeasurements = (payload) => {
473
- const nodeIds = Array.isArray(payload?.nodeIds)
474
- ? payload.nodeIds.filter((value) => typeof value === "string" && value.trim()).map((value) => value.trim())
475
- : [];
476
-
477
- const measurements = nodeIds
478
- .map((nodeId) => {
479
- const element = resolveLayoutMeasurementElement(nodeId);
480
-
481
- if (!(element instanceof HTMLElement)) {
482
- return null;
483
- }
484
-
485
- const rect = element.getBoundingClientRect();
486
- const parentElement = resolveLayoutParentElement(element);
487
- const parentRect = parentElement?.getBoundingClientRect?.() ?? null;
488
- const viewportRect = document.documentElement?.getBoundingClientRect?.() ?? null;
489
- const localLeft = element.offsetLeft;
490
- const localTop = element.offsetTop;
491
- const absoluteLeft = viewportRect ? rect.left - viewportRect.left : rect.left;
492
- const absoluteTop = viewportRect ? rect.top - viewportRect.top : rect.top;
493
- const parentLeft = parentRect ? rect.left - parentRect.left : localLeft;
494
- const parentTop = parentRect ? rect.top - parentRect.top : localTop;
495
-
496
- return {
497
- nodeId,
498
- left: absoluteLeft,
499
- top: absoluteTop,
500
- width: rect.width,
501
- height: rect.height,
502
- localLeft: Number.isFinite(localLeft) ? localLeft : parentLeft,
503
- localTop: Number.isFinite(localTop) ? localTop : parentTop
504
- };
505
- })
506
- .filter(Boolean);
507
-
508
- window.parent?.postMessage({
509
- type: "codingns-static-html-layout-measurements",
510
- measurements
511
- }, "*");
512
- };
513
-
514
- eventTypes.forEach((eventType) => {
515
- document.addEventListener(eventType, handler, true);
516
- });
517
-
518
- document.addEventListener("pointerover", handlePointerOver, true);
519
- document.addEventListener("pointerleave", handlePointerLeaveViewport, true);
520
-
521
- document.addEventListener("pointermove", (event) => {
522
- if (!layoutModeEnabled || !activeLayoutPointer) {
523
- return;
524
- }
525
-
526
- if (typeof activeLayoutPointer.pointerId === "number" && event.pointerId !== activeLayoutPointer.pointerId) {
527
- return;
528
- }
529
-
530
- window.parent?.postMessage({
531
- type: "codingns-static-html-layout-pointer",
532
- phase: "move",
533
- nodeId: activeLayoutPointer.nodeId,
534
- clientX: event.clientX,
535
- clientY: event.clientY
536
- }, "*");
537
- }, true);
538
-
539
- const finishLayoutPointer = (event, phase) => {
540
- if (!activeLayoutPointer) {
541
- return;
542
- }
543
-
544
- if (typeof activeLayoutPointer.pointerId === "number" && event.pointerId !== activeLayoutPointer.pointerId) {
545
- return;
546
- }
547
-
548
- window.parent?.postMessage({
549
- type: "codingns-static-html-layout-pointer",
550
- phase,
551
- nodeId: activeLayoutPointer.nodeId,
552
- clientX: event.clientX,
553
- clientY: event.clientY
554
- }, "*");
555
-
556
- activeLayoutPointer = null;
557
- };
558
-
559
- document.addEventListener("pointerup", (event) => {
560
- finishLayoutPointer(event, "end");
561
- }, true);
562
-
563
- document.addEventListener("pointercancel", (event) => {
564
- finishLayoutPointer(event, "cancel");
565
- }, true);
566
-
567
- window.addEventListener("message", (event) => {
568
- const payload = event.data;
569
-
570
- if (!payload || typeof payload !== "object") {
571
- return;
572
- }
573
-
574
- if (payload.type !== "codingns-static-html-selection-sync") {
575
- if (payload.type === "codingns-static-html-layout-measure-request") {
576
- postLayoutMeasurements(payload);
577
- }
578
-
579
- return;
580
- }
581
-
582
- syncSelectionState(payload);
583
- });
584
- })();
585
- `,t.body.appendChild(i)}else Ao(t);return t.documentElement.outerHTML}function Fr(e,t){const n=(t==null?void 0:t.trim())??"";if(!n)return;const r=e.head??e.querySelector("head");if(!(r instanceof HTMLHeadElement))return;const o=r.querySelector("base");if(o){o.setAttribute("href",n);return}const i=e.createElement("base");i.setAttribute("href",n),r.insertBefore(i,r.firstChild)}function Wr(e){e.querySelectorAll("script").forEach(t=>{t.remove()})}function $r(e,t){var i;const n=e.body;if(!n||!n.getAttribute)return;n.style.width=`${t.canvas.width}px`,n.style.minWidth=`${t.canvas.width}px`,n.style.maxWidth=`${t.canvas.width}px`,n.style.height=`${t.canvas.height}px`,n.style.minHeight=`${t.canvas.height}px`,n.style.maxHeight=`${t.canvas.height}px`;const r=((i=n.style.transform)==null?void 0:i.trim())??"",o=Array.from(e.querySelectorAll("style")).some(s=>{const d=s.textContent??"";return/body\s*\{[\s\S]*?transform\s*:\s*scale\(/i.test(d)});/scale\(/i.test(r)&&!/translate\(/i.test(r)&&(n.style.transform="none"),o?n.setAttribute("data-cns-preview-body-scale-reset","true"):n.removeAttribute("data-cns-preview-body-scale-reset")}function Mt(e,t,n){const r=e.nodes[t];return r?{...e,nodes:{...e.nodes,[t]:n(r)}}:e}function Br(e,t,n){if(t.length===0)return e;const r={...e.nodes};let o=!1;return t.forEach(i=>{const s=r[i];s&&(r[i]=n(s,i),o=!0)}),o?{...e,nodes:r}:e}function Dr(e,t){if(!e.nodes[t])return{project:e,duplicatedNodeId:null};const r=qr(e,t);if(!r)return{project:e,duplicatedNodeId:null};const o={...e.nodes},i=jo(e.nodes),s=An({project:e,sourceNodeId:t,nextNodes:o,idCounter:i,isRoot:!0}),d=o[r];if(!d)return{project:e,duplicatedNodeId:null};const g=d.children.indexOf(t),x=[...d.children];return x.splice(g>=0?g+1:x.length,0,s),o[r]={...d,children:x},{project:{...e,nodes:o},duplicatedNodeId:s}}function Or(e,t){const n=t!=null&&t.insertAfterPageId?e.pages.findIndex(f=>f.id===t.insertAfterPageId):-1,r=n>=0?n+1:e.pages.length,o=Sn(e),i=`${o}-root`,s=e.pages[Math.max(0,r-1)]??e.pages[e.pages.length-1]??null,d=Nn({id:i,name:p("conversation.fileViewerPresentationUntitled"),sourceRef:null}),g={id:o,order:r,title:p("conversation.fileViewerPresentationUntitled"),frame:(s==null?void 0:s.frame)??{width:e.canvas.width,height:e.canvas.height,background:null},rootNodeId:i,sourceRef:{pageIndex:r,pageSelector:`[data-cns-page-id="${o}"]`,nodePath:[]},runtimeHints:(s==null?void 0:s.runtimeHints)??{hasActiveStateClass:!1,hasDeckShell:!0}},x=[...e.pages];return x.splice(r,0,g),{pageId:o,project:xt({...e,pages:x,nodes:{...e.nodes,[i]:d}})}}function Hr(e,t){const n=e.pages.find(f=>f.id===t);if(!n)return{project:e,pageId:null};const r=e.pages.findIndex(f=>f.id===t),o=r>=0?r+1:e.pages.length,i=Sn(e),s=`${i}-root`,d={...e.nodes},g=n.sourceRef.pageIndex;zn({project:e,sourceNodeId:n.rootNodeId,targetNodeId:s,nextPageId:i,sourcePageIndex:g,nextNodes:d});const x=[...e.pages];return x.splice(o,0,{...n,id:i,order:o,title:n.title,rootNodeId:s,sourceRef:{...n.sourceRef}}),{pageId:i,project:xt({...e,pages:x,nodes:d})}}function _r(e,t){var g,x;if(e.pages.length<=1)return{project:e,nextPageId:((g=e.pages[0])==null?void 0:g.id)??null};const n=e.pages.find(f=>f.id===t);if(!n)return{project:e,nextPageId:((x=e.pages[0])==null?void 0:x.id)??null};const r=e.pages.findIndex(f=>f.id===t),o=e.pages.filter(f=>f.id!==t),i={...e.nodes};yn(i,n.rootNodeId);const s=xt({...e,pages:o,nodes:i}),d=s.pages[Math.min(r,s.pages.length-1)]??null;return{project:s,nextPageId:(d==null?void 0:d.id)??null}}function Ur(e,t,n){const r=e.pages.findIndex(d=>d.id===t);if(r<0)return{project:e,pageId:null};const o=Math.max(0,Math.min(n,e.pages.length-1));if(r===o)return{project:e,pageId:t};const i=[...e.pages],[s]=i.splice(r,1);return s?(i.splice(o,0,s),{project:xt({...e,pages:i}),pageId:t}):{project:e,pageId:null}}function Lt(e,t){const n=e.pages.find(o=>o.id===t);if(!n)return[];const r=[];return xn(e,n.rootNodeId,r,!0),r}function xn(e,t,n,r=!1){const o=e.nodes[t];o&&(r||n.push(t),o.children.forEach(i=>{xn(e,i,n)}))}function qr(e,t){var n;return((n=Object.values(e.nodes).find(r=>r.children.includes(t)))==null?void 0:n.id)??null}function Kr(e){var g;const{document:t,project:n}=e,r=[...e.pageElements],o=(g=r[0])==null?void 0:g.parentElement;if(!o)return;const i=r[r.length-1]??t.body.firstElementChild,s=new Set;n.pages.map((x,f)=>{const w=ro(t,r,x);if(w&&!s.has(w))return s.add(w),rn(w,x,!1,f),w;const E=oo(t,w??i,x,f,!!w);return E?(rn(E,x,!0,f),E):null}).filter(x=>x instanceof Element).forEach(x=>{o.appendChild(x)}),r.forEach(x=>{s.has(x)||x.remove()})}function yn(e,t){const n=e[t];n&&(n.children.forEach(r=>{yn(e,r)}),delete e[t])}function xt(e){return Yr(e)}function Yr(e){const t={...e.nodes};return{...e,pages:e.pages.map((n,r)=>{var o;return vn(t,n.rootNodeId,r),{...n,order:r,title:(o=n.title)!=null&&o.trim()?n.title:p("conversation.fileViewerPresentationUntitled"),sourceRef:{...n.sourceRef,pageIndex:r}}}),nodes:t}}function vn(e,t,n){const r=e[t];r&&(r.sourceRef&&(e[t]={...r,sourceRef:{...r.sourceRef,pageIndex:n}}),r.children.forEach(o=>{vn(e,o,n)}))}function Ut(e){return new DOMParser().parseFromString(e,"text/html")}function mt(e,t){if(t){const n=Xr(t),r=Array.from(e.querySelectorAll(n));if(r.length>0)return{strategy:t,elements:r}}return pn.map(n=>({strategy:n.strategy,elements:Array.from(e.querySelectorAll(n.selector))})).find(n=>n.elements.length>0)??null}function At(e){return{supported:!1,reason:e,mode:"presentation",strategy:null,pages:[],warnings:[],viewport:{width:ze.width,height:ze.height}}}function Xr(e){var t;return((t=pn.find(n=>n.strategy===e))==null?void 0:t.selector)??"section.slide"}function Gr(e,t){var i,s;const n=(i=e.getAttribute("data-title"))==null?void 0:i.trim();if(n)return n;const r=e.querySelector("h1, h2, h3, .slide-title, .title, .page-title"),o=(s=r==null?void 0:r.textContent)==null?void 0:s.replace(/\s+/g," ").trim();return o||`第 ${t+1} 页`}function wn(e,t){const n=e.getAttribute("data-title");return n?`.slide[data-title="${tn(n)}"]`:e.id?`#${tn(e.id)}`:`.slide:nth-of-type(${t+1})`}function tn(e){return e.replace(/"/g,'\\"')}function Jr(e,t){const n=Array.from(e.querySelectorAll("style")).map(s=>s.textContent??"").join(`
586
- `),r=nn(n,"--deck-width"),o=nn(n,"--deck-height");if(r&&o)return{width:r,height:o};const i=Zr(n);return i||{width:ze.width,height:ze.height}}function Zr(e){const t=Qr(e,".slide"),n=Xe(e,".slide","width"),r=Xe(e,".slide","height"),o=Xe(e,".slide","max-height");if(n&&r)return{width:n,height:r};if(n&&t)return{width:n,height:Math.round(n/t)};if(o&&t)return{width:Math.round(o*t),height:o};const i=Xe(e,".deck","width"),s=Xe(e,".deck","height");return i&&s?{width:i,height:s}:null}function nn(e,t){const n=new RegExp(`(?:^|[\\s;{])${Qe(t)}\\s*:\\s*(\\d{3,5})px`,"i").exec(e);return n?Number(n[1]):null}function Xe(e,t,n){const r=bn(e,t);if(!r)return null;const o=new RegExp(`(?:^|[\\s;])${Qe(n)}\\s*:\\s*(\\d{3,5})px`,"i").exec(r);if(o)return Number(o[1]);const i=new RegExp(`(?:^|[\\s;])${Qe(n)}\\s*:\\s*min\\(\\s*(\\d{3,5})px\\s*,`,"i").exec(r);if(i)return Number(i[1]);const s=new RegExp(`(?:^|[\\s;])${Qe(n)}\\s*:\\s*calc\\(\\s*100v[wh]\\s*-\\s*(\\d{1,4})px\\s*\\)`,"i").exec(r);return s?n.includes("height")?ze.height-Number(s[1]):ze.width-Number(s[1]):null}function Qr(e,t){const n=bn(e,t);if(!n)return null;const r=/aspect-ratio\s*:\s*(\d+(?:\.\d+)?)\s*\/\s*(\d+(?:\.\d+)?)/i.exec(n);if(!r)return null;const o=Number(r[1]),i=Number(r[2]);return!o||!i?null:o/i}function bn(e,t){const n=new RegExp(`${Qe(t)}\\s*\\{([\\s\\S]*?)\\}`,"i").exec(e);return(n==null?void 0:n[1])??null}function Qe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function eo(e){const t=vt(e);if(t.length===1){const r=t[0];if(r&&!fo(r))return r}for(const r of Tr){const o=e.querySelector(r);if(o)return o.parentElement===e&&t.length>1?e:o}const n=e.querySelector(".head + .content");return n||e}function to(e,t){if(e===t)return[];const n=[];let r=t;for(;r&&r!==e;){const o=r.parentElement;if(!o)return[];const s=Array.from(o.children).indexOf(r);if(s<0)return[];n.unshift(s),r=o}return n}function yt(e){if(e.matches(mn)||e.getAttribute("aria-hidden")==="true")return!0;const t=typeof e.className=="string"?e.className:"";return/(^|\s)(page|progress|ctrl|nav|particle|glow)(\s|$)/i.test(t)}function $t(e){const{containerElement:t,containerPath:n,pageIndex:r,pageSelector:o,parentNodeId:i,nodeIdPrefix:s,nodes:d,assets:g}=e;Array.from(t.children).forEach((f,w)=>{var P;if(yt(f))return;const E=[...n,w];if(Cn(f)){$t({...e,containerElement:f,containerPath:E,parentNodeId:i,nodeIdPrefix:s});return}const N=`${s}-node-${E.join("-")||"root"}`,m=no({element:f,pageIndex:r,pageSelector:o,nodePath:E,nodeId:N,assets:g});if(!m)return;const u=[...m.runtimeFlags];t.hasAttribute("data-cns-layout-freeze")&&!u.includes("layout-freeze-child")&&u.push("layout-freeze-child"),f.hasAttribute("data-cns-layout-freeze")&&!u.includes("layout-freeze-container")&&u.push("layout-freeze-container"),d[m.id]=u.length===m.runtimeFlags.length?m:{...m,runtimeFlags:u},(P=d[i])==null||P.children.push(m.id),m.type==="group"&&$t({...e,containerElement:f,containerPath:E,parentNodeId:m.id,nodeIdPrefix:m.id})})}function no(e){const{element:t,pageIndex:n,pageSelector:r,nodePath:o,nodeId:i,assets:s}=e,d={pageIndex:n,pageSelector:r,nodePath:o},g=vt(t);if(t.tagName==="IMG"){const f=t.getAttribute("src")??"",w=t.getAttribute("alt")??"";return f&&s.push({id:`asset-${Yt(f)}`,type:"image",src:f}),{id:i,type:"image",name:w||"图片",editable:!0,lockedReason:null,box:Ge(t),style:Ae(t),content:{src:f,alt:w},children:[],sourceRef:d,patchStrategy:"replace_node",runtimeFlags:[]}}if(t.tagName==="SVG"||t.querySelector(":scope > svg"))return{id:i,type:"svg",name:"SVG",editable:!1,lockedReason:"复杂 SVG 先按只读节点导入",box:Ge(t),style:Ae(t),content:{html:t.outerHTML},children:[],sourceRef:d,patchStrategy:"replace_node",runtimeFlags:["readonly"]};if(Ht.has(t.tagName)||En(t)||uo(t,g))return zt(i,t,d);if(!g.length){const f=zt(i,t,d);if(f)return f}if(g.length>0||go(t))return{id:i,type:"group",name:on(t),editable:!0,lockedReason:null,box:Ge(t),style:Ae(t),content:{},children:[],sourceRef:d,patchStrategy:"style_only",runtimeFlags:[]};const x=t.outerHTML.trim();return x?{id:i,type:"html",name:on(t),editable:!1,lockedReason:"复杂 HTML 片段先按只读节点导入",box:Ge(t),style:Ae(t),content:{html:x},children:[],sourceRef:d,patchStrategy:"replace_node",runtimeFlags:["readonly"]}:null}function zt(e,t,n){const r=ho(t),o=qt(r);return o?kn({id:e,name:o.slice(0,20),text:o,runs:r,sourceRef:n,style:Ae(t),box:Ge(t),preserveStructure:mo(t)}):null}function Nn(e){return{id:e.id,type:"group",name:e.name,editable:!0,lockedReason:null,box:In(),style:{},content:{},children:[],sourceRef:e.sourceRef,patchStrategy:"style_only",runtimeFlags:e.runtimeFlags??[]}}function Sn(e){return`page-${e.pages.reduce((n,r)=>{const o=/^page-(\d+)$/.exec(r.id);return o?Math.max(n,Number.parseInt(o[1]??"0",10)):n},0)+1}`}function ro(e,t,n){var i;const r=(i=n.sourceRef.pageSelector)==null?void 0:i.trim();if(r){const s=Array.from(e.querySelectorAll(r)).filter(d=>t.includes(d));if(s.length===1&&s[0]instanceof Element)return s[0];if(/^\[data-cns-page-id=/.test(r))return null}const o=t[n.sourceRef.pageIndex]??null;return o instanceof Element?o:null}function oo(e,t,n,r,o=!1){var g,x;if(o&&t instanceof Element){const f=t.cloneNode(!0);if(f instanceof Element)return f}const i=e.createElement(((g=t==null?void 0:t.tagName)==null?void 0:g.toLowerCase())||"section");t instanceof Element?io(t,i):i.className="slide";const s=e.createElement("div");s.className=ao(t);const d=e.createElement("h1");return d.textContent=((x=n.title)==null?void 0:x.trim())||p("conversation.fileViewerPresentationUntitled"),s.appendChild(d),i.appendChild(s),i}function rn(e,t,n,r){var s,d;const o=((s=t.title)==null?void 0:s.trim())||p("conversation.fileViewerPresentationUntitled");e.setAttribute("data-title",o),e.setAttribute("data-cns-page-id",t.id),e.setAttribute("data-cns-page-order",String(r));const i=e.querySelector("h1, h2, h3, .slide-title, .title, .page-title");i&&(n||!((d=i.textContent)!=null&&d.trim()))&&(i.textContent=o)}function io(e,t){Array.from(e.attributes).forEach(n=>{n.name==="data-title"||n.name.startsWith("data-cns-")||t.setAttribute(n.name,n.value)})}function ao(e){const t=e==null?void 0:e.querySelector(".slide-shell, .panel, .content, .slide-inner");return(typeof(t==null?void 0:t.className)=="string"?t.className.trim():"")||"slide-shell"}function kn(e){const t=!!e.preserveStructure||Array.isArray(e.runs)&&e.runs.some(n=>n.tagName||n.className||n.sourceKind==="element");return{id:e.id,type:"text",name:e.name,editable:!0,lockedReason:null,box:e.box??In(),style:e.style??{},content:{text:e.text,runs:e.runs??null},children:[],sourceRef:e.sourceRef,patchStrategy:"text_and_style",runtimeFlags:t?["preserve-text-structure"]:[]}}function In(){return{x:0,y:0,width:0,height:0,zIndex:0}}function Ae(e){const t=Pn(e);return{position:t.get("position")??null,fontFamily:t.get("font-family")??null,fontSize:Je(t.get("font-size")),fontWeight:t.get("font-weight")??null,fontStyle:t.get("font-style")??null,lineHeight:t.get("line-height")??null,letterSpacing:t.get("letter-spacing")??null,color:t.get("color")??null,textAlign:t.get("text-align")??null,textDecoration:t.get("text-decoration")??null,textDecorationColor:t.get("text-decoration-color")??null,whiteSpace:t.get("white-space")??null,padding:t.get("padding")??null,margin:t.get("margin")??null,borderRadius:t.get("border-radius")??null,borderWidth:t.get("border-width")??null,borderColor:t.get("border-color")??null,backgroundColor:t.get("background-color")??null,opacity:so(t.get("opacity"))}}function Ge(e){const t=Pn(e);return{x:Je(t.get("left"))??0,y:Je(t.get("top"))??0,width:Je(t.get("width"))??0,height:Je(t.get("height"))??0,zIndex:lo(t.get("z-index"))??0}}function Pn(e){const t=(e.getAttribute("style")??"").trim(),n=new Map;return t&&t.split(";").forEach(r=>{const[o,i]=r.split(":");!o||!i||n.set(o.trim(),i.trim())}),n}function Je(e){if(!e)return null;const t=/(-?\d+(?:\.\d+)?)px/i.exec(e);return t?Number(t[1]):null}function so(e){if(!e)return null;const t=Number(e);return Number.isFinite(t)?t:null}function lo(e){if(!e)return null;const t=Number.parseInt(e,10);return Number.isFinite(t)?t:null}function En(e){return e.tagName!=="SPAN"?!1:!!tt(e.textContent??"")&&e.children.length===0}function vt(e){return Array.from(e.children).filter(t=>!yt(t))}function Rn(e){return Array.from(e.childNodes).some(t=>t.nodeType!==Node.TEXT_NODE?!1:!!Ve(t.textContent??""))}const co=new Set(["SPAN","STRONG","B","I","EM","U","SMALL","MARK","SUB","SUP","CODE","A","BR"]);function uo(e,t){return gt(e,t)>0}function fo(e){return gt(e)>0}function gt(e,t){if(!tt(e.textContent??""))return 0;if(Ht.has(e.tagName))return 500;if(En(e))return 460;const r=t??vt(e);return r.length===0?420:r.every(i=>wt(i))&&Rn(e)?360:0}function Cn(e){if(yt(e)||gt(e)>0)return!1;const t=vt(e);if(t.length!==1||Rn(e))return!1;const n=t[0];return n?gt(n)>0?!0:Cn(n):!1}function wt(e){return!!(co.has(e.tagName)||e.tagName==="SPAN"&&e.children.length===0)}function ho(e){const t=[];return jn(e,t,e),po(t)}function jn(e,t,n){if(n.nodeType===Node.TEXT_NODE){const r=n.textContent??"";if(!Kt(r))return;const o=Ve(r);o&&t.push({text:o,sourceKind:"text"});return}if(n instanceof Element&&!(yt(n)&&n!==e)){if(n!==e&&wt(n)){const r=Ve(n.textContent??"");r&&t.push({text:r,tagName:n.tagName.toLowerCase(),className:typeof n.className=="string"&&n.className.trim()?n.className.trim():null,style:Ae(n),sourceKind:"element"});return}n.childNodes.forEach(r=>{jn(e,t,r)})}}function po(e){return e.map(n=>{const r=Ve(n.text);return r?{text:r,tagName:n.tagName??null,className:n.className??null,style:n.style??null,sourceKind:n.sourceKind??null}:null}).filter(n=>n!==null)}function qt(e){return tt(e.map(t=>t.text).join(" "))}function mo(e){if(e.querySelector("br"))return!0;let t=0;return e.childNodes.forEach(n=>{if(n.nodeType===Node.TEXT_NODE){Kt(n.textContent??"")&&(t+=1);return}n instanceof Element&&n.tagName!=="BR"&&wt(n)&&Ve(n.textContent??"")&&(t+=1)}),t>1}function go(e){const t=typeof e.className=="string"?e.className.toLowerCase():"";return Mr.some(n=>t.includes(n))}function on(e){const t=typeof e.className=="string"?e.className.trim():"";return t?t.split(/\s+/)[0]??e.tagName.toLowerCase():e.tagName.toLowerCase()}function tt(e){return e.replace(/\s+/g," ").trim()}function Ve(e){return e.replace(/\r\n/g,`
587
- `).replace(/[^\S\r\n]+/g," ")}function Kt(e){return!e||!/\S/.test(e)?!1:!/^[\n\r\t ]+$/.test(e)}function Tn(e){return Array.from(new Set(e))}function xo(e){const t=new Map;return e.forEach(n=>{t.set(n.id,n)}),Array.from(t.values())}function yo(e){return`static-html-${Yt(e)}`}function Mn(e,t){const n=e[t.pageIndex];if(!n)return null;let r=n;for(const o of t.nodePath){const i=r.children.item(o);if(!(i instanceof Element))return null;r=i}return r}function Ln(e,t){switch(t.type){case"text":Array.isArray(t.content.runs)&&t.content.runs.length>0?vo(e,t.content.runs,{preserveStructure:Fe(t,"preserve-text-structure")}):typeof t.content.text=="string"&&(e.textContent=t.content.text);break;case"image":typeof t.content.src=="string"&&t.content.src&&e.setAttribute("src",t.content.src),typeof t.content.alt=="string"&&e.setAttribute("alt",t.content.alt);break;default:!t.children.length&&typeof t.content.text=="string"&&t.content.text&&(e.textContent=t.content.text);break}bt(e,t.style),Po(e,t),Eo(e,t)}function vo(e,t,n){if(n!=null&&n.preserveStructure&&wo(e,t))return;const r=e.ownerDocument;if(!r){e.textContent=qt(t);return}for(;e.firstChild;)e.removeChild(e.firstChild);t.forEach(o=>{if(!o.text)return;if(!o.tagName){e.appendChild(r.createTextNode(o.text));return}const i=r.createElement(o.tagName);o.className&&i.setAttribute("class",o.className),i.textContent=o.text,bt(i,o.style??{}),e.appendChild(i)})}function wo(e,t){if(tt(e.textContent??"")===qt(t))return!0;const n=bo(t);if(!n.length)return!1;const r=No(e);if(!r.length||r.length!==n.length)return!1;for(let o=0;o<r.length;o+=1){const i=r[o],s=n[o];if(!i||!s||i.kind!==s.kind||i.kind==="element"&&((i.tagName??null)!==(s.tagName??null)||(i.className??null)!==(s.className??null)))return!1}return r.forEach((o,i)=>{const s=n[i];if(s){if(o.kind==="text"&&o.node.nodeType===Node.TEXT_NODE){o.node.textContent=s.text;return}o.node instanceof Element&&(o.node.textContent=s.text,bt(o.node,s.style??{}))}}),!0}function bo(e){return e.map(t=>{const n=t.text??"";return n?{kind:t.tagName||t.className||t.sourceKind==="element"?"element":"text",text:n,tagName:t.tagName??null,className:t.className??null,style:t.style??null}:null}).filter(t=>!!t)}function No(e){const t=[];return e.childNodes.forEach(n=>{if(n.nodeType===Node.TEXT_NODE){const o=n.textContent??"";if(!Kt(o))return;t.push({kind:"text",node:n,tagName:null,className:null});return}!(n instanceof Element)||n.tagName==="BR"||!wt(n)||!Ve(n.textContent??"")||t.push({kind:"element",node:n,tagName:n.tagName.toLowerCase(),className:typeof n.className=="string"&&n.className.trim()?n.className.trim():null})}),t}function So(e,t,n){if(t.type!=="text"||!ko(e,t))return;const r=typeof t.content.text=="string"?t.content.text:tt(e.textContent??""),o=Array.isArray(t.content.runs)?t.content.runs:[];if(!r)return;const i=e.ownerDocument;if(!i)return;const s=i.createElement("span");for(s.setAttribute("data-cns-text-proxy","true"),s.setAttribute("data-cns-node-id",t.id),e.setAttribute("data-cns-node-host","true"),e.setAttribute("data-cns-node-host-id",t.id),e.removeAttribute("data-cns-node-id"),n.selected&&(s.setAttribute("data-cns-node-selected","true"),e.removeAttribute("data-cns-node-selected")),s.setAttribute("style",["display: inline","background: transparent","border: none","padding: 0","margin: 0","white-space: inherit","color: inherit","font: inherit","letter-spacing: inherit","line-height: inherit","text-transform: inherit"].join("; ")),o.length>1?o.forEach((d,g)=>{const x=i.createElement(d.tagName||"span");x.setAttribute("data-cns-node-id",t.id),x.setAttribute("data-cns-run-index",String(g)),d.className&&x.setAttribute("class",d.className),n.selected&&n.selectedRunIndex===g&&x.setAttribute("data-cns-node-selected","true"),x.textContent=d.text,bt(x,d.style??{}),s.appendChild(x)}):s.textContent=r;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(s)}function ko(e,t){return e.childElementCount>0||Ht.has(e.tagName)?!1:Io(t.style)}function Io(e){return!!(e.backgroundColor||e.padding||e.borderRadius||e.borderWidth||e.borderColor)}function bt(e,t){for(const[n,r]of Object.entries(t)){const o=Lr[n];if(o){if(r==null||r===""){e instanceof HTMLElement?e.style.removeProperty(o):e.setAttribute("style",(e.getAttribute("style")??"").trim());continue}e.setAttribute("style",Ee(e.getAttribute("style")??"",o,Ro(n,r)))}}}function Po(e,t){if(!(Fe(t,"draft-clone")||Fe(t,"draft-box")))return;const r=e.getAttribute("style")??"";let o=Ee(r,"position","absolute");o=Ee(o,"left",`${t.box.x}px`),o=Ee(o,"top",`${t.box.y}px`),t.box.width>0&&(o=Ee(o,"width",`${t.box.width}px`)),t.box.height>0&&(o=Ee(o,"height",`${t.box.height}px`)),t.box.zIndex!==0&&(o=Ee(o,"z-index",String(t.box.zIndex))),e.setAttribute("style",o)}function Eo(e,t){if(Fe(t,"layout-freeze-container")){e.setAttribute("data-cns-layout-freeze","true");return}e.removeAttribute("data-cns-layout-freeze")}function Ee(e,t,n){const r=new Map;return e.split(";").forEach(o=>{const[i,s]=o.split(":");!i||!s||r.set(i.trim(),s.trim())}),r.set(t,n),Array.from(r.entries()).map(([o,i])=>`${o}: ${i}`).join("; ")}function Ro(e,t){return e==="fontSize"&&typeof t=="number"?`${t}px`:String(t)}function Yt(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)>>>0;return t.toString(16)}function An(e){const t=e.project.nodes[e.sourceNodeId];if(!t)return e.sourceNodeId;const n=Co(t.id,e.idCounter),r=`clone-source:${t.id}`,o=Tn([...t.runtimeFlags.filter(d=>!d.startsWith("clone-source:")),"draft-clone",e.isRoot?"draft-clone-root":"draft-clone-child",r]),i={...t,id:n,name:`${t.name} 副本`,sourceRef:t.sourceRef,box:{...t.box,x:t.box.x+24,y:t.box.y+24},children:[],runtimeFlags:o};e.nextNodes[n]=i;const s=t.children.map(d=>An({project:e.project,sourceNodeId:d,nextNodes:e.nextNodes,idCounter:e.idCounter,isRoot:!1}));return e.nextNodes[n]={...i,children:s},n}function zn(e){const t=e.project.nodes[e.sourceNodeId];if(!t)return e.targetNodeId;const n={...t,id:e.targetNodeId,sourceRef:t.sourceRef?{...t.sourceRef,pageIndex:e.sourcePageIndex}:null,children:[],runtimeFlags:t.runtimeFlags.filter(o=>o!=="draft-clone"&&o!=="draft-clone-root"&&o!=="draft-clone-child"&&!o.startsWith("clone-source:"))};e.nextNodes[e.targetNodeId]=n;const r=t.children.map((o,i)=>zn({project:e.project,sourceNodeId:o,targetNodeId:`${e.targetNodeId}-node-${i}`,nextPageId:e.nextPageId,sourcePageIndex:e.sourcePageIndex,nextNodes:e.nextNodes}));return e.nextNodes[e.targetNodeId]={...n,children:r},e.targetNodeId}function Co(e,t){const n=(t[e]??0)+1;return t[e]=n,`${e}-copy-${n}`}function jo(e){const t={};return Object.keys(e).forEach(n=>{const r=/^(.*)-copy-(\d+)$/.exec(n);if(!r)return;const o=r[1],i=Number.parseInt(r[2]??"0",10);!o||!Number.isFinite(i)||(t[o]=Math.max(t[o]??0,i))}),t}function To(e){const t=Lo(e.cloneRootNode);if(!t)return;const n=e.project.nodes[t];if(!(n!=null&&n.sourceRef))return;const r=Mn(e.pageElements,n.sourceRef);if(!(r!=null&&r.parentElement))return;const o=r.cloneNode(!0);o instanceof Element&&(r.parentElement.insertBefore(o,r.nextSibling),Vn({project:e.project,cloneNodeId:e.cloneRootNode.id,cloneElement:o,sourceRootPath:n.sourceRef.nodePath,selectedNodeId:e.selectedNodeId,mode:e.mode}))}function Vn(e){const t=e.project.nodes[e.cloneNodeId];t&&(e.cloneElement.setAttribute("data-cns-node-id",t.id),e.mode==="preview"?(e.cloneElement.removeAttribute("data-cns-node-selected"),e.selectedNodeId&&t.id===e.selectedNodeId&&e.cloneElement.setAttribute("data-cns-node-selected","true")):e.cloneElement.removeAttribute("data-cns-node-selected"),Ln(e.cloneElement,t),t.children.forEach(n=>{const r=e.project.nodes[n];if(!(r!=null&&r.sourceRef))return;const o=r.sourceRef.nodePath.slice(e.sourceRootPath.length),i=Mo(e.cloneElement,o);i&&Vn({project:e.project,cloneNodeId:n,cloneElement:i,sourceRootPath:e.sourceRootPath,selectedNodeId:e.selectedNodeId,mode:e.mode})}))}function Mo(e,t){let n=e;for(const r of t){const o=n.children.item(r);if(!(o instanceof Element))return null;n=o}return n}function Fe(e,t){return e.runtimeFlags.includes(t)}function Lo(e){const t=e.runtimeFlags.find(n=>n.startsWith("clone-source:"));return t?t.slice(13):null}function Ao(e){e.querySelectorAll("[data-cns-page-root]").forEach(t=>{t.removeAttribute("data-cns-page-root"),t.removeAttribute("data-cns-active-page")}),e.querySelectorAll("[data-cns-text-proxy]").forEach(t=>{const n=t.parentElement;if(!n){t.remove();return}n.textContent=t.textContent??"",n.removeAttribute("data-cns-node-host"),n.removeAttribute("data-cns-node-host-id")}),e.querySelectorAll("[data-cns-node-id]").forEach(t=>{t.removeAttribute("data-cns-node-id")}),e.querySelectorAll("[data-cns-node-selected]").forEach(t=>{t.removeAttribute("data-cns-node-selected")}),e.querySelectorAll("[data-cns-inline-editing]").forEach(t=>{t.removeAttribute("data-cns-inline-editing")}),e.querySelectorAll("[data-cns-node-host]").forEach(t=>{t.removeAttribute("data-cns-node-host"),t.removeAttribute("data-cns-node-host-id")}),e.querySelectorAll("[data-cns-page-id]").forEach(t=>{t.removeAttribute("data-cns-page-id"),t.removeAttribute("data-cns-page-order")}),e.querySelectorAll("style").forEach(t=>{var n;(n=t.textContent)!=null&&n.includes("[data-cns-page-root")&&t.remove()}),e.querySelectorAll('script[data-cns-preview-bridge="true"]').forEach(t=>{t.remove()})}const ut=24;function _(e){return{x:Number.isFinite(e.x)?Math.round(e.x):0,y:Number.isFinite(e.y)?Math.round(e.y):0,width:Math.max(ut,Number.isFinite(e.width)?Math.round(e.width):ut),height:Math.max(ut,Number.isFinite(e.height)?Math.round(e.height):ut),zIndex:Number.isFinite(e.zIndex)?Math.round(e.zIndex):0}}function zo(e,t){const n=_(t),r=e.runtimeFlags.includes("draft-box")?e.runtimeFlags:[...e.runtimeFlags,"draft-box"];return{...e,box:n,runtimeFlags:r}}function Vt(e,t){const n={...e.nodes};return Object.entries(t).forEach(([r,o])=>{const i=n[r];i&&(n[r]=zo(i,o))}),{...e,nodes:n}}function Vo(e,t){const n=Object.entries(e);if(n.length===0)return{};const r=Fo(n.map(([,i])=>i),t),o={};return n.forEach(([i,s])=>{const d=_(s);if(t==="left"){o[i]={...d,x:r};return}if(t==="right"){o[i]={...d,x:r-d.width};return}if(t==="top"){o[i]={...d,y:r};return}o[i]={...d,y:r-d.height}}),o}function Fo(e,t){return t==="left"?Math.min(...e.map(n=>n.x)):t==="right"?Math.max(...e.map(n=>n.x+n.width)):t==="top"?Math.min(...e.map(n=>n.y)):Math.max(...e.map(n=>n.y+n.height))}function Wo(e){if(e.length===0)return null;const t=Math.min(...e.map(i=>i.x)),n=Math.min(...e.map(i=>i.y)),r=Math.max(...e.map(i=>i.x+i.width)),o=Math.max(...e.map(i=>i.y+i.height));return _({x:t,y:n,width:r-t,height:o-n,zIndex:Math.max(...e.map(i=>i.zIndex))})}function an(e){return{verticals:[e.x,e.x+e.width/2,e.x+e.width],horizontals:[e.y,e.y+e.height/2,e.y+e.height]}}const $o=4;function Bo({filePath:e,html:t,baseHref:n,onProjectChange:r,onSave:o,canSave:i=!1,saving:s=!1}){const d=y.useMemo(()=>_t(t,e),[e,t]),g=y.useMemo(()=>Ar({html:t,filePath:e}),[e,t]),[x,f]=y.useState(g),[w,E]=y.useState(0),[N,m]=y.useState("content"),[u,P]=y.useState(null),[k,L]=y.useState([]),[j,$]=y.useState(null),[G,W]=y.useState(null),[M,A]=y.useState([]),[U,fe]=y.useState(null),[H,Q]=y.useState(null),[C,ee]=y.useState(null),ie=y.useRef(null),We=y.useRef(null),he=y.useRef(null),Z=y.useRef(null),ve=y.useRef(null),Re=y.useRef(null),we=y.useRef(g),Ce=y.useRef(1),be=y.useRef(null),te=y.useRef({}),ne=y.useRef(null),[q,$e]=y.useState(1),[je,ae]=y.useState(1),[D,O]=y.useState({}),[pe,Ie]=y.useState({}),[Ne,me]=y.useState([]),[ge,xe]=y.useState(null),v=x,V=(v==null?void 0:v.pages[w])??(v==null?void 0:v.pages[0])??null,K=y.useMemo(()=>!v||!V?[]:Lt(v,V.id),[V,v]);y.useEffect(()=>{f(g),E(0),m("content"),P(null),L([]),$(null),W(null),A([]),fe(null),Q(null),ee(null),O({}),Ie({}),me([]),xe(null),ne.current=null},[g]),y.useEffect(()=>{r==null||r(x)},[x,r]),y.useEffect(()=>{we.current=x},[x]),y.useEffect(()=>{Ce.current=q},[q]),y.useEffect(()=>{const l=ve.current,c=Re.current;if(!l||!c){ae(1);return}const h=()=>{const b=l.clientWidth,R=l.clientHeight,I=c.scrollWidth,T=c.scrollHeight;if(b<=0||R<=0||I<=0||T<=0){ae(1);return}const z=b/I,B=R/T,F=Math.min(1,z,B);ae(X=>Math.abs(X-F)<.01?X:F)};if(h(),typeof ResizeObserver>"u")return;const S=new ResizeObserver(()=>{h()});return S.observe(l),S.observe(c),()=>{S.disconnect()}},[N,u,k,G]),y.useEffect(()=>{be.current=ge},[ge]),y.useEffect(()=>{te.current=pe},[pe]),y.useEffect(()=>{if(!v||!V){P(null),L([]),$(null),W(null);return}const l=K.find(h=>{var S;return(S=v.nodes[h])==null?void 0:S.editable})??null,c=k.filter(h=>K.includes(h));c.length!==k.length&&L(c),j&&!K.includes(j)&&$(null),!(u&&K.includes(u))&&(P(l),L(l?[l]:[]),W(null))},[V,v,j,K,u,k]);const re=u&&v?v.nodes[u]??null:null,Be=N==="content"&&(re==null?void 0:re.type)==="html"?null:re,Te=y.useMemo(()=>k.map(l=>(v==null?void 0:v.nodes[l])??null).filter(l=>!!l),[v,k]),se=y.useMemo(()=>v?zr({html:t,project:v,pageIndex:w,baseHref:n??null}):null,[n,w,v,t]);y.useEffect(()=>{!Z.current||!C||(sn(Z.current,C.text),Ho(Z.current))},[C==null?void 0:C.nodeId]),y.useEffect(()=>{!Z.current||!C||sn(Z.current,C.text)},[C==null?void 0:C.text]),y.useEffect(()=>{if(!se||!v)return;const l=c=>{const h=c.data;if(!h||typeof h!="object")return;if(h.type==="codingns-static-html-layout-pointer"){const T=typeof h.phase=="string"?h.phase:"",z=typeof h.nodeId=="string"?h.nodeId.trim():"",B=typeof h.clientX=="number"?h.clientX:Number.NaN,F=typeof h.clientY=="number"?h.clientY:Number.NaN;if(!z||!Number.isFinite(B)||!Number.isFinite(F))return;if(T==="start"){if(N!=="layout")return;const Ke=v.nodes[z],er=ke(Ke),Ct=!!h.metaKey||!!h.ctrlKey?k.includes(z)?k:[...k,z]:[z];if(P(z),L(Ct),W(null),ee(null),!er.movable)return;const tr=Object.fromEntries(Ct.map(le=>{const Ye=v.nodes[le];return Ye?[le,ye(Ye,D[le])]:null}).filter(le=>!!le)),nr=Object.fromEntries(K.map(le=>{const Ye=v.nodes[le];return Ye?[le,ye(Ye,D[le])]:null}).filter(le=>!!le));xe({source:"iframe",handle:"move",nodeIds:Ct,pointerStartX:B,pointerStartY:F,activated:!1,startProject:v,startPageIndex:w,pageNodeIds:K,referenceBoxes:nr,startSelectedNodeId:u,startSelectedNodeIds:k,originBoxes:tr});return}const X=be.current;if(!X||X.source!=="iframe")return;if(T==="move"){Oe(X,B,F);return}if(T==="end"||T==="cancel"){at(X);return}return}if(h.type==="codingns-static-html-layout-hover"){if(N!=="layout")return;const T=typeof h.nodeId=="string"?h.nodeId.trim():"";$(T||null);return}if(h.type!=="codingns-static-html-node-select")return;const S=typeof h.nodeId=="string"?h.nodeId.trim():"",b=typeof h.runIndex=="number"&&Number.isInteger(h.runIndex)?h.runIndex:null;if(!S||!v.nodes[S])return;const R=v.pages.findIndex(T=>Lt(v,T.id).includes(S));R>=0&&R!==w&&E(R);const I=v.nodes[S];if(I){if(N==="layout"){if(I.type==="html")return;const T=ke(I);if(T.movable||T.resizable||T.alignable){const z=h.eventType==="click"&&(!!h.metaKey||!!h.ctrlKey);L(B=>{if(!z)return[S];if(B.includes(S)){const F=B.filter(X=>X!==S);return F.length>0?F:[S]}return[...B,S]})}P(S),W(null),ee(null);return}if(I.type!=="html"){if(P(S),L([S]),W(b),h.eventType==="dblclick"){const T=Array.isArray(I==null?void 0:I.content.runs)&&I.content.runs.length>1,z=(I==null?void 0:I.editable)&&(I.type==="text"||typeof I.content.text=="string"),B=Do(h.rect)?h.rect:null;if(z&&B&&!T&&b===null){const F={nodeId:S,text:I.content.text??"",rect:B,appearance:Oo(h.appearance,I.style)};ee(F);return}}ee(null)}}};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[w,v,N,D,se,u,k]),y.useEffect(()=>{var c;const l=(c=ie.current)==null?void 0:c.contentWindow;l&&l.postMessage({type:"codingns-static-html-selection-sync",selectedNodeId:u,selectedRunIndex:G,inlineEditingNodeId:(C==null?void 0:C.nodeId)??null,layoutModeEnabled:N==="layout",layoutHoveredNodeId:N==="layout"?j:null,layoutSelectedNodeIds:N==="layout"?k:[]},"*")},[j,C==null?void 0:C.nodeId,N,se,u,k,G]);const rt=(V==null?void 0:V.id)??null,kt=M.length>0;function It(){const l=M[M.length-1];l&&(ne.current=null,A(c=>c.slice(0,-1)),f(l.project),Ie({}),me([]),E(l.currentPageIndex),P(l.selectedNodeId),L(l.selectedNodeId?[l.selectedNodeId]:l.selectedNodeIds),W(null),ee(null),xe(null))}y.useEffect(()=>{if(!v||!he.current){$e(1);return}const l=he.current,c=()=>{const S=l.getBoundingClientRect(),b=24,R=Math.max(1,S.width-b),I=Math.max(1,S.height-b),T=R/v.canvas.width,z=I/v.canvas.height,B=Math.min(T,z,1);$e(B>0?B:1)};if(c(),window.addEventListener("resize",c),typeof ResizeObserver>"u")return()=>{window.removeEventListener("resize",c)};const h=new ResizeObserver(()=>{c()});return h.observe(l),()=>{h.disconnect(),window.removeEventListener("resize",c)}},[v]);const Se=y.useMemo(()=>{if(!v)return;const l=v.canvas.width*q,c=v.canvas.height*q;return{display:"flex",alignItems:"flex-start",justifyContent:"flex-start",width:`${l}px`,height:`${c}px`}},[v,q]),De=y.useMemo(()=>{if(v)return{position:"absolute",left:0,top:0,width:`${v.canvas.width}px`,height:`${v.canvas.height}px`,transform:`scale(${q})`,transformOrigin:"top left"}},[v,q]),oe=y.useMemo(()=>{var b,R;if(!C)return null;const l=(b=ie.current)==null?void 0:b.getBoundingClientRect(),c=(R=We.current)==null?void 0:R.getBoundingClientRect();if(!l||!c)return{left:Math.max(0,C.rect.left),top:Math.max(0,C.rect.top),width:Math.max(120,C.rect.width),minHeight:Math.max(48,C.rect.height)};const h=l.left-c.left+C.rect.left*q,S=l.top-c.top+C.rect.top*q;return{left:Math.max(0,h),top:Math.max(0,S),width:Math.max(120,C.rect.width*q),minHeight:Math.max(48,C.rect.height*q)}},[q,C]);y.useEffect(()=>{!Z.current||!oe||(Z.current.style.height=`${oe.minHeight}px`,Z.current.style.height=`${Math.max(oe.minHeight,Z.current.scrollHeight)}px`)},[C==null?void 0:C.nodeId,C==null?void 0:C.text,oe]);const Pt=y.useMemo(()=>{if(!(!C||!oe))return{left:`${oe.left}px`,top:`${oe.top}px`,width:`${oe.width}px`,minHeight:`${oe.minHeight}px`,fontFamily:C.appearance.fontFamily??void 0,fontSize:C.appearance.fontSize??void 0,fontWeight:C.appearance.fontWeight??void 0,fontStyle:C.appearance.fontStyle??void 0,lineHeight:C.appearance.lineHeight??void 0,letterSpacing:C.appearance.letterSpacing??void 0,color:C.appearance.color??void 0,caretColor:C.appearance.color??void 0,textAlign:Uo(C.appearance.textAlign),whiteSpace:qo(C.appearance.whiteSpace),padding:C.appearance.padding??void 0,textTransform:Ko(C.appearance.textTransform)}},[C,oe]);function ot(l,c){if(!l)return{nextIndex:0,nextSelectedNodeId:null};const h=c.pages.findIndex(I=>I.id===l),S=h>=0?h:0,b=c.pages[S]??null,R=b?Lt(c,b.id):[];return{nextIndex:S,nextSelectedNodeId:R.find(I=>{var T;return(T=c.nodes[I])==null?void 0:T.editable})??null}}function it(l,c){if(f(l),Ie({}),me([]),(c==null?void 0:c.focusPageId)!==void 0){const h=ot(c.focusPageId,l);E(h.nextIndex),P(c.selectedNodeId??h.nextSelectedNodeId),L(c.selectedNodeIds??(c.selectedNodeId?[c.selectedNodeId]:h.nextSelectedNodeId?[h.nextSelectedNodeId]:[]));return}(c==null?void 0:c.selectedNodeId)!==void 0&&P(c.selectedNodeId),(c==null?void 0:c.selectedNodeIds)!==void 0&&L(c.selectedNodeIds)}function Y(l){v&&((!l.historyKey||ne.current!==l.historyKey)&&A(c=>[...c,{project:v,currentPageIndex:w,selectedNodeId:u,selectedNodeIds:k}].slice(-10)),ne.current=l.historyKey??null,it(l.nextProject,{focusPageId:l.focusPageId,selectedNodeId:l.selectedNodeId,selectedNodeIds:l.selectedNodeIds}),l.preserveInlineEditor||ee(null))}function ue(l){A(c=>[...c,l].slice(-10))}function Oe(l,c,h){const S=Ce.current,b=S>0?(c-l.pointerStartX)/S:0,R=S>0?(h-l.pointerStartY)/S:0,I=Math.hypot(b,R);if(!l.activated&&l.handle==="move"&&I<$o)return;l.activated||xe(z=>z&&{...z,activated:!0});const T=Qo(l,b,R);Ie(T.previewBoxes),me(T.guideLines)}function at(l){const c=we.current,h=te.current;if(c&&l.activated&&Object.keys(h).length>0){const S=Object.fromEntries(Object.entries(h).map(([R,I])=>{const T=c.nodes[R],z=D[R];if(!T)return null;const B=Ze(T,z),F=ye(T,z),X=F.x-B.x,Ke=F.y-B.y;return[R,_({...I,x:I.x-X,y:I.y-Ke})]}).filter(R=>!!R)),b=Vt(c,S);ne.current=null,ue({project:l.startProject,currentPageIndex:l.startPageIndex,selectedNodeId:l.startSelectedNodeId,selectedNodeIds:l.startSelectedNodeIds}),f(b)}Ie({}),me([]),xe(null)}function He(l,c){if(!v||!v.nodes[l])return;const S=(c==null?void 0:c.additive)??!1;P(l),W(null),c!=null&&c.switchToLayout&&m("layout"),L(b=>{if(!S)return[l];if(b.includes(l)){const R=b.filter(I=>I!==l);return R.length>0?R:[l]}return[...b,l]})}function Et(l){var c;return v?((c=Object.values(v.nodes).find(h=>h.children.includes(l)))==null?void 0:c.id)??null:null}function _e(l){if(!v||!l)return null;const c=Et(l);if(!c)return null;const h=v.nodes[c];return!h||h.runtimeFlags.includes("layout-freeze-container")||!h.sourceRef?null:c}function Ue(l){if(!v)return!1;const c=_e(l);if(!c)return!1;const h=v.nodes[c];if(!h)return!1;const S=v.nodes[l??""];if(!S)return!1;const b=qe(c,h);return b?!!Le(S,b):!1}function Me(){if(!v||!u||!Ue(u))return;const l=_e(u);if(!l)return;const c=v.nodes[l];if(!c)return;const h=qe(l,c);if(!h)return;const S=Br(v,[l,...c.children],(b,R)=>{if(R===l){const z=b.runtimeFlags.includes("layout-freeze-container")?b.runtimeFlags:[...b.runtimeFlags,"layout-freeze-container"];return{...b,style:{...b.style,position:Wn(b.style.position)?b.style.position:"relative"},runtimeFlags:z}}const I=Le(b,h);if(!I)return b;const T=b.runtimeFlags.filter(z=>z!=="layout-freeze-container").concat(b.runtimeFlags.includes("layout-freeze-child")?[]:["layout-freeze-child"],b.runtimeFlags.includes("draft-box")?[]:["draft-box"]);return{...b,box:I,style:{...b.style,position:"absolute",margin:"0px"},runtimeFlags:T}});Y({nextProject:S,selectedNodeId:u,selectedNodeIds:[u],historyKey:`layout-freeze:${l}`}),m("layout")}function qe(l,c){const h=D[l];if(h)return ye(c,h);if(l===(V==null?void 0:V.rootNodeId))return _({x:0,y:0,width:(v==null?void 0:v.canvas.width)??c.box.width,height:(v==null?void 0:v.canvas.height)??c.box.height,zIndex:c.box.zIndex});for(const b of c.children){const R=v==null?void 0:v.nodes[b],I=D[b];if(!R||!I)continue;const T=I.left-I.localLeft,z=I.top-I.localTop,B=st(c);return _({x:T,y:z,width:B.width,height:B.height,zIndex:c.box.zIndex})}const S=st(c);return _({x:c.box.x,y:c.box.y,width:S.width,height:S.height,zIndex:c.box.zIndex})}function st(l){const c=l.children.map(I=>lt((v==null?void 0:v.nodes[I])??null)).filter(I=>!!I),h=l.box.width,S=l.box.height;if(!c.length)return{width:h,height:S};const b=c.reduce((I,T)=>Math.max(I,T.x+T.width),0),R=c.reduce((I,T)=>Math.max(I,T.y+T.height),0);return{width:Math.max(h,b),height:Math.max(S,R)}}function lt(l){if(!l)return null;const c=D[l.id];return _(c?{x:c.localLeft,y:c.localTop,width:c.width,height:c.height,zIndex:l.box.zIndex}:l.box)}function Le(l,c){const h=D[l.id];if(h){const b=ye(l,h);return _({x:b.x-c.x,y:b.y-c.y,width:b.width,height:b.height,zIndex:b.zIndex})}const S=lt(l);return S?_(S):null}function Rt(){if(!v||!u)return;const l=Dr(v,u);l.duplicatedNodeId&&(Y({nextProject:l.project,selectedNodeId:l.duplicatedNodeId,selectedNodeIds:[l.duplicatedNodeId],historyKey:`duplicate:${u}`}),m("layout"))}function ct(l){if(!v||!u)return;const c=v.nodes[u];if(!c)return;const h=Ze(c,D[u]),S=_({...h,x:l.x??h.x,y:l.y??h.y,width:l.width??h.width,height:l.height??h.height,zIndex:h.zIndex}),b=Vt(v,{[u]:S});Y({nextProject:b,selectedNodeId:u,selectedNodeIds:k,historyKey:`layout-box:${u}`})}function Pe(l){if(!v)return;const c=k.filter(b=>ke(v.nodes[b]).alignable);if(c.length<2)return;const h=Vo(Object.fromEntries(c.map(b=>{const R=v.nodes[b];return R?[b,Ze(R,D[b])]:null}).filter(b=>!!b)),l),S=Vt(v,h);Y({nextProject:S,selectedNodeId:u,selectedNodeIds:c,historyKey:`layout-align:${l}:${c.join(",")}`})}return y.useEffect(()=>{if(!se||N!=="layout"){O({});return}const l=c=>{const h=c.data;if(!h||typeof h!="object"||h.type!=="codingns-static-html-layout-measurements"||!Array.isArray(h.measurements))return;const S={};h.measurements.forEach(b=>{if(!b||typeof b!="object")return;const R=b,I=typeof R.nodeId=="string"?R.nodeId.trim():"",T=typeof R.left=="number"?R.left:Number.NaN,z=typeof R.top=="number"?R.top:Number.NaN,B=typeof R.width=="number"?R.width:Number.NaN,F=typeof R.height=="number"?R.height:Number.NaN,X=typeof R.localLeft=="number"?R.localLeft:T,Ke=typeof R.localTop=="number"?R.localTop:z;!I||!Number.isFinite(T)||!Number.isFinite(z)||!Number.isFinite(B)||!Number.isFinite(F)||(S[I]={left:T,top:z,width:B,height:F,localLeft:X,localTop:Ke})}),O(S)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[N,se]),y.useEffect(()=>{var c;if(N!=="layout"||!se)return;const l=(c=ie.current)==null?void 0:c.contentWindow;l&&l.postMessage({type:"codingns-static-html-layout-measure-request",nodeIds:Array.from(new Set([(V==null?void 0:V.rootNodeId)??"",...K].filter(h=>h&&(v==null?void 0:v.nodes[h]))))},"*")},[V==null?void 0:V.rootNodeId,v,N,K,se]),y.useEffect(()=>{if(!ge||ge.source!=="overlay")return;const l=h=>{Oe(ge,h.clientX,h.clientY)},c=()=>{at(ge)};return window.addEventListener("pointermove",l),window.addEventListener("pointerup",c),()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",c)}},[ge]),!d.supported||!v?a.jsxs("div",{className:"static-html-presentation-empty",children:[a.jsx("p",{className:"status-text",children:p("conversation.fileViewerPresentationUnsupported")}),d.reason?a.jsx("p",{className:"status-text",children:p("conversation.fileViewerPresentationUnsupportedReason").replace("{reason}",d.reason)}):null]}):a.jsxs("div",{className:"static-html-presentation-shell","data-testid":"static-html-presentation-view",children:[a.jsxs("aside",{className:"static-html-presentation-sidebar",children:[a.jsxs("div",{className:"static-html-presentation-sidebar-actions",children:[a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-sidebar-action-button",onClick:It,disabled:!kt,children:p("conversation.fileViewerPresentationUndoAction")}),a.jsx("button",{type:"button",className:"primary-button static-html-presentation-sidebar-action-button",onClick:o,disabled:!i||s,children:s?p("conversation.filePanelSaving"):p("conversation.filePanelSave")})]}),a.jsx("div",{className:"static-html-presentation-page-toolbar",children:a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-page-toolbar-button",onClick:()=>{const l=Or(v,{insertAfterPageId:rt});Y({nextProject:l.project,focusPageId:l.pageId})},children:p("conversation.fileViewerPresentationAddPage")})}),a.jsx("div",{className:"static-html-presentation-page-list",role:"list",children:v.pages.map((l,c)=>a.jsxs("div",{className:"static-html-presentation-page-item","data-active":l.id===rt?"true":void 0,"data-dragging":U===l.id?"true":void 0,"data-drop-target":(H==null?void 0:H.pageId)===l.id?"true":void 0,"data-drop-position":(H==null?void 0:H.pageId)===l.id?H.position:void 0,draggable:!0,onDragStart:h=>{h.dataTransfer.effectAllowed="move",h.dataTransfer.setData("text/plain",l.id),fe(l.id),Q(null)},onDragOver:h=>{h.preventDefault(),h.dataTransfer.dropEffect="move";const S=Yo(h);Q(b=>(b==null?void 0:b.pageId)===l.id&&b.position===S?b:{pageId:l.id,position:S})},onDrop:h=>{h.preventDefault();const S=h.dataTransfer.getData("text/plain")||U;if(!S||!H)return;const b=Xo(v.pages,S,H);if(b===null){fe(null),Q(null);return}const R=Ur(v,S,b);Y({nextProject:R.project,focusPageId:R.pageId}),fe(null),Q(null)},onDragEnd:()=>{fe(null),Q(null)},children:[(H==null?void 0:H.pageId)===l.id&&H.position==="before"?a.jsx("div",{className:"static-html-presentation-page-drop-indicator","data-position":"before"}):null,a.jsxs("button",{type:"button",className:"static-html-presentation-page-main",onClick:()=>{const h=v.pages.findIndex(S=>S.id===l.id);E(h>=0?h:0)},children:[a.jsx("span",{className:"static-html-presentation-page-no",children:String(c+1).padStart(2,"0")}),a.jsx("span",{className:"static-html-presentation-page-title",children:l.title??`第 ${c+1} 页`})]}),a.jsxs("div",{className:"static-html-presentation-page-actions","aria-label":p("conversation.fileViewerPresentationPageActions"),children:[a.jsx("span",{className:"static-html-presentation-page-drag-hint",children:p("conversation.fileViewerPresentationDragToSort")}),a.jsx("button",{type:"button",className:"static-html-presentation-page-action",onClick:()=>{const h=Hr(v,l.id);h.pageId&&Y({nextProject:h.project,focusPageId:h.pageId})},"aria-label":p("conversation.fileViewerPresentationDuplicatePage"),title:p("conversation.fileViewerPresentationDuplicatePage"),children:a.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",children:[a.jsx("rect",{x:"5",y:"5",width:"7",height:"7",rx:"1.5"}),a.jsx("path",{d:"M4 10H3.5A1.5 1.5 0 0 1 2 8.5v-5A1.5 1.5 0 0 1 3.5 2h5A1.5 1.5 0 0 1 10 3.5V4"})]})}),a.jsx("button",{type:"button",className:"static-html-presentation-page-action",onClick:()=>{const h=_r(v,l.id);Y({nextProject:h.project,focusPageId:h.nextPageId??rt})},disabled:v.pages.length<=1,"aria-label":p("conversation.fileViewerPresentationDeletePage"),title:p("conversation.fileViewerPresentationDeletePage"),children:"×"})]}),(H==null?void 0:H.pageId)===l.id&&H.position==="after"?a.jsx("div",{className:"static-html-presentation-page-drop-indicator","data-position":"after"}):null]},l.id))})]}),a.jsxs("section",{className:"static-html-presentation-stage",children:[a.jsxs("section",{className:"static-html-presentation-toolbar-panel",children:[a.jsx("div",{className:"static-html-presentation-toolbar-panel-header",children:a.jsxs("div",{className:"static-html-presentation-mode-switch",role:"group","aria-label":p("conversation.fileViewerModeLabel"),children:[a.jsx("button",{type:"button",className:"static-html-presentation-mode-button","data-active":N==="content"?"true":void 0,onClick:()=>m("content"),children:p("conversation.fileViewerPresentationTextMode")}),a.jsx("button",{type:"button",className:"static-html-presentation-mode-button","data-active":N==="layout"?"true":void 0,onClick:()=>{m("layout"),u&&L([u])},children:p("conversation.fileViewerPresentationLayoutMode")})]})}),a.jsx("div",{className:"static-html-presentation-toolbar-panel-body",children:a.jsx("div",{ref:ve,className:"static-html-presentation-toolbar-viewport",children:a.jsx("div",{ref:Re,className:"static-html-presentation-toolbar-scale-shell",style:{transform:`scale(${je})`,width:je<1?`${100/je}%`:"100%"},children:a.jsx("div",{className:"static-html-presentation-toolbar static-html-presentation-inspector",children:N==="layout"?a.jsx(ti,{selectedNode:re,selectedLayoutBox:re?Ze(re,u?D[u]:void 0):null,selectedNodes:Te,showFreezeContainerAction:!!(u&&_e(u)),canFreezeContainer:Ue(u),onDuplicate:Rt,onFreezeContainer:Me,onAlignLeft:()=>Pe("left"),onAlignRight:()=>Pe("right"),onAlignTop:()=>Pe("top"),onAlignBottom:()=>Pe("bottom"),onBoxChange:ct}):Be?a.jsx(ni,{node:Be,selectedRunIndex:G,onSelectedRunChange:W,compact:!0,onTextChange:({text:l,runs:c})=>{if(!u)return;const h=Mt(v,u,S=>({...S,content:{...S.content,text:l,runs:c??cn(S,l)}}));Y({nextProject:h,historyKey:`text:${u}`})},onStyleChange:l=>{if(!u)return;const c=Mt(v,u,h=>({...h,style:{...h.style,...l}}));Y({nextProject:c,historyKey:`style:${u}`})}}):a.jsx("div",{className:"static-html-presentation-toolbar-empty static-html-presentation-inspector-empty",children:a.jsx("p",{className:"status-text",children:p("conversation.fileViewerPresentationSelectNode")})})})})})})]}),a.jsx("section",{className:"static-html-presentation-content-panel",children:a.jsxs("div",{className:"static-html-presentation-workarea",children:[a.jsx("div",{className:"static-html-presentation-canvas-panel",children:a.jsx("div",{ref:he,className:"static-html-presentation-frame-shell",children:se?a.jsxs("div",{ref:We,className:"static-html-presentation-frame-stage",style:Se,children:[a.jsx("iframe",{ref:ie,className:"static-html-presentation-frame","data-testid":"static-html-presentation-frame",title:(V==null?void 0:V.title)??e,srcDoc:se,sandbox:"allow-forms allow-modals allow-scripts",style:De,onLoad:()=>{var l,c;(c=(l=ie.current)==null?void 0:l.contentWindow)==null||c.postMessage({type:"codingns-static-html-selection-sync",selectedNodeId:u,inlineEditingNodeId:(C==null?void 0:C.nodeId)??null,layoutModeEnabled:N==="layout",layoutHoveredNodeId:N==="layout"?j:null,layoutSelectedNodeIds:N==="layout"?k:[]},"*")}}),N==="layout"?a.jsxs("div",{className:"static-html-presentation-layout-overlay","data-testid":"static-html-presentation-layout-overlay",children:[Ne.map((l,c)=>a.jsx("div",{className:"static-html-presentation-layout-guide","data-orientation":l.orientation,style:Go(l,q)},`${l.orientation}-${l.position}-${c}`)),j&&!k.includes(j)&&D[j]?a.jsx("div",{className:"static-html-presentation-layout-box static-html-presentation-layout-box-hover","data-hovered":"true",style:Ft(D[j],q)}):null,k.map(l=>{const c=pe[l],h=D[l],S=v.nodes[l],b=ke(S),R=c?Ft({left:c.x,top:c.y,width:c.width,height:c.height,localLeft:c.x,localTop:c.y},q):h?Ft(h,q):void 0;return!R||!S?null:a.jsx("div",{className:"static-html-presentation-layout-box","data-primary":l===u?"true":void 0,"data-disabled":b.movable?void 0:"true",style:R,onPointerEnter:()=>{$(l)},onPointerLeave:()=>{$(I=>I===l?null:I)},onPointerDown:I=>{if(!b.movable)return;I.preventDefault(),I.stopPropagation(),He(l,{additive:I.metaKey||I.ctrlKey,switchToLayout:!0});const T=I.metaKey||I.ctrlKey?k.includes(l)?k:[...k,l]:[l],z=Object.fromEntries(T.map(F=>{const X=v.nodes[F];return X?[F,ye(X,D[F])]:null}).filter(F=>!!F)),B=Object.fromEntries(K.map(F=>{const X=v.nodes[F];return X?[F,ye(X,D[F])]:null}).filter(F=>!!F));xe({source:"overlay",handle:"move",nodeIds:T,pointerStartX:I.clientX,pointerStartY:I.clientY,startProject:v,startPageIndex:w,pageNodeIds:K,referenceBoxes:B,startSelectedNodeId:u,startSelectedNodeIds:k,activated:!1,originBoxes:z})},children:b.resizable?a.jsx("button",{type:"button",className:"static-html-presentation-layout-resize-handle","aria-label":p("conversation.fileViewerPresentationResizeHandle"),onPointerDown:I=>{I.preventDefault(),I.stopPropagation(),He(l,{switchToLayout:!0}),xe({source:"overlay",handle:"resize-se",nodeIds:[l],pointerStartX:I.clientX,pointerStartY:I.clientY,startProject:v,startPageIndex:w,pageNodeIds:K,referenceBoxes:Object.fromEntries(K.map(T=>{const z=v.nodes[T];return z?[T,ye(z,D[T])]:null}).filter(T=>!!T)),startSelectedNodeId:u,startSelectedNodeIds:k,activated:!0,originBoxes:{[l]:ye(v.nodes[l],D[l])}})},children:a.jsx("span",{})}):null},l)})]}):null,C?a.jsx("div",{ref:Z,className:"static-html-presentation-inline-editor","data-testid":"static-html-presentation-inline-editor",role:"textbox","aria-multiline":"true",contentEditable:!0,suppressContentEditableWarning:!0,spellCheck:!1,style:Pt,onInput:l=>{const c=Fn(l.currentTarget),h=C;if(ee(b=>b&&{...b,text:c}),!h||!v.nodes[h.nodeId])return;const S=Mt(v,h.nodeId,b=>({...b,content:{...b.content,text:c,runs:cn(b,c)}}));Y({nextProject:S,selectedNodeId:h.nodeId,historyKey:`inline-text:${h.nodeId}`,preserveInlineEditor:!0})},onBlur:()=>{ee(null)},onPaste:l=>{l.preventDefault();const c=l.clipboardData.getData("text/plain");_o(c)},onKeyDown:l=>{l.key==="Escape"&&(l.preventDefault(),ee(null))}}):null]}):a.jsx("p",{className:"status-text",children:p("conversation.fileViewerHtmlPreviewUnavailable")})})}),a.jsxs("aside",{className:"static-html-presentation-node-sidebar",children:[a.jsx("div",{className:"static-html-presentation-node-sidebar-header",children:a.jsx("p",{className:"static-html-presentation-node-sidebar-kicker",children:p("conversation.fileViewerPresentationComponentList")})}),a.jsx("div",{className:"static-html-presentation-node-strip",role:"list",children:K.map(l=>{const c=v.nodes[l];return c?a.jsxs("button",{type:"button",className:"static-html-presentation-node-chip","data-active":l===u?"true":void 0,"data-selected":k.includes(l)?"true":void 0,"data-locked":c.editable?void 0:"true",title:N==="layout"?ke(c).reason??void 0:void 0,onClick:h=>{He(l,{additive:N==="layout"&&(h.metaKey||h.ctrlKey),switchToLayout:N==="layout"})},children:[a.jsx("span",{className:"static-html-presentation-node-chip-type",children:c.type}),a.jsx("span",{className:"static-html-presentation-node-chip-name",children:c.name||c.id}),N==="layout"?a.jsx("span",{className:"static-html-presentation-node-chip-status",children:ke(c).reason?p("conversation.fileViewerPresentationLayoutLocked"):p("conversation.fileViewerPresentationLayoutEditable")}):null]},l):null})})]})]})})]})]})}function Do(e){if(!e||typeof e!="object")return!1;const t=e;return["left","top","width","height"].every(n=>typeof t[n]=="number")}function Oo(e,t){const n={fontFamily:t.fontFamily??null,fontSize:typeof t.fontSize=="number"?`${t.fontSize}px`:null,fontWeight:t.fontWeight??null,fontStyle:null,lineHeight:t.lineHeight??null,letterSpacing:t.letterSpacing??null,color:t.color??null,textAlign:t.textAlign??null,whiteSpace:t.whiteSpace??null,padding:t.padding??null,textTransform:null};if(!e||typeof e!="object")return n;const r=e;return{fontFamily:ce(r.fontFamily,n.fontFamily),fontSize:ce(r.fontSize,n.fontSize),fontWeight:ce(r.fontWeight,n.fontWeight),fontStyle:ce(r.fontStyle,n.fontStyle),lineHeight:ce(r.lineHeight,n.lineHeight),letterSpacing:ce(r.letterSpacing,n.letterSpacing),color:ce(r.color,n.color),textAlign:ce(r.textAlign,n.textAlign),whiteSpace:ce(r.whiteSpace,n.whiteSpace),padding:ce(r.padding,n.padding),textTransform:ce(r.textTransform,n.textTransform)}}function ce(e,t){return typeof e=="string"&&e.trim()?e:t}function sn(e,t){Fn(e)!==t&&(e.textContent=t)}function Ho(e){e.focus();const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}function Fn(e){return nt(typeof e.innerText=="string"?e.innerText:e.textContent??"")}function nt(e){return e.replace(/\r\n/g,`
588
- `).replace(/\u00a0/g," ")}function _o(e){const t=window.getSelection();if(!t||t.rangeCount===0)return;const n=t.getRangeAt(0);n.deleteContents();const r=document.createTextNode(e);n.insertNode(r),n.setStartAfter(r),n.collapse(!0),t.removeAllRanges(),t.addRange(n)}function Uo(e){if(!e)return;const t=e.trim().toLowerCase();if(t==="left"||t==="right"||t==="center"||t==="justify"||t==="start"||t==="end")return t}function qo(e){if(!e)return;const t=e.trim().toLowerCase();if(t==="normal"||t==="nowrap"||t==="pre"||t==="pre-wrap"||t==="pre-line"||t==="break-spaces")return t}function Ko(e){if(!e)return;const t=e.trim().toLowerCase();if(t==="none"||t==="capitalize"||t==="uppercase"||t==="lowercase")return t}function Yo(e){const t=e.currentTarget.getBoundingClientRect();return t.height<=0||e.clientY-t.top<t.height/2?"before":"after"}function Xo(e,t,n){const r=e.findIndex(d=>d.id===t),o=e.findIndex(d=>d.id===n.pageId);if(r<0||o<0)return null;const i=n.position==="before"?o:o+1,s=r<i?i-1:i;return Math.max(0,Math.min(s,e.length-1))}function ke(e){return e?e.editable?e.type==="svg"||e.type==="html"||e.type==="decoration"?{movable:!1,resizable:!1,alignable:!1,reason:p("conversation.fileViewerPresentationLayoutUnsupported"),strictModeLocked:!1}:e.id.endsWith("-root")?{movable:!1,resizable:!1,alignable:!1,reason:p("conversation.fileViewerPresentationLayoutRootLocked"),strictModeLocked:!1}:Jo(e)?{movable:!0,resizable:!0,alignable:!0,reason:null,strictModeLocked:!1}:{movable:!1,resizable:!1,alignable:!1,reason:p("conversation.fileViewerPresentationLayoutStrictLocked"),strictModeLocked:!0}:{movable:!1,resizable:!1,alignable:!1,reason:e.lockedReason||p("conversation.fileViewerPresentationLayoutUnsupported"),strictModeLocked:!1}:{movable:!1,resizable:!1,alignable:!1,reason:p("conversation.fileViewerPresentationLayoutUnsupported"),strictModeLocked:!1}}function Ft(e,t){return{left:`${e.left*t}px`,top:`${e.top*t}px`,width:`${e.width*t}px`,height:`${e.height*t}px`}}function Go(e,t){return e.orientation==="vertical"?{left:`${e.position*t}px`,top:`${e.start*t}px`,width:"1px",height:`${Math.max(0,(e.end-e.start)*t)}px`}:{left:`${e.start*t}px`,top:`${e.position*t}px`,width:`${Math.max(0,(e.end-e.start)*t)}px`,height:"1px"}}function Jo(e){return e.runtimeFlags.includes("draft-clone")||e.runtimeFlags.includes("draft-box")?!0:e.sourceRef?!!(e.runtimeFlags.includes("layout-freeze-child")||Wn(e.style.position)):!1}function Wn(e){const t=(e==null?void 0:e.trim().toLowerCase())??"";return t==="absolute"||t==="fixed"}function Ze(e,t){return e.runtimeFlags.includes("draft-clone")||e.runtimeFlags.includes("draft-box")?_(e.box):_(t?{x:t.localLeft,y:t.localTop,width:t.width,height:t.height,zIndex:e.box.zIndex}:e.box)}function ye(e,t){return _(t?{x:t.left,y:t.top,width:t.width,height:t.height,zIndex:e.box.zIndex}:e.box)}function Zo(e,t){if(e.nodeIds.length!==1)return[];const n=e.nodeIds[0],r=t[n];if(!n||!r)return[];const o=[r.x,r.x+r.width/2,r.x+r.width],i=[r.y,r.y+r.height/2,r.y+r.height],s=6,d=[];return Object.entries(e.originBoxes).forEach(([g])=>{}),Object.entries(e.startProject.nodes).forEach(([g,x])=>{if(g===n||e.nodeIds.includes(g))return;const f=e.startProject.nodes[g]?Ze(x,void 0):null;if(!f)return;const w=[f.x,f.x+f.width/2,f.x+f.width],E=[f.y,f.y+f.height/2,f.y+f.height];o.forEach(N=>{const m=w.find(u=>Math.abs(u-N)<=s);m!==void 0&&d.push({orientation:"vertical",position:m,start:Math.min(r.y,f.y),end:Math.max(r.y+r.height,f.y+f.height)})}),i.forEach(N=>{const m=E.find(u=>Math.abs(u-N)<=s);m!==void 0&&d.push({orientation:"horizontal",position:m,start:Math.min(r.x,f.x),end:Math.max(r.x+r.width,f.x+f.width)})})}),$n(d)}function Qo(e,t,n){const r={};if(e.nodeIds.forEach(i=>{const s=e.originBoxes[i];if(s){if(e.handle==="move"){r[i]=_({...s,x:s.x+t,y:s.y+n});return}r[i]=_({...s,width:s.width+t,height:s.height+n})}}),e.handle!=="move")return{previewBoxes:r,guideLines:Zo(e,r)};const o=ei(e,r);return{previewBoxes:o.previewBoxes,guideLines:o.guideLines}}function ei(e,t){const n=e.nodeIds.map(N=>t[N]).filter(N=>!!N),r=Wo(n);if(!r)return{previewBoxes:t,guideLines:[]};const o=6,i=an(r);let s=0,d=0,g=o+1,x=o+1;const f=[],w=e.pageNodeIds.filter(N=>!e.nodeIds.includes(N)).map(N=>e.referenceBoxes[N]).filter(N=>!!N&&N.width>0&&N.height>0),E={x:0,y:0,width:e.startProject.canvas.width,height:e.startProject.canvas.height,zIndex:0};return[...w,E].forEach(N=>{const m=an(N);i.verticals.forEach(u=>{m.verticals.forEach(P=>{const k=Math.abs(P-(u+s));k>o||k>=g||(g=k,s=P-u,f.push({orientation:"vertical",position:P,start:Math.min(r.y,N.y),end:Math.max(r.y+r.height,N.y+N.height)}))})}),i.horizontals.forEach(u=>{m.horizontals.forEach(P=>{const k=Math.abs(P-(u+d));k>o||k>=x||(x=k,d=P-u,f.push({orientation:"horizontal",position:P,start:Math.min(r.x,N.x),end:Math.max(r.x+r.width,N.x+N.width)}))})})}),(s!==0||d!==0)&&e.nodeIds.forEach(N=>{const m=t[N];m&&(t[N]=_({...m,x:m.x+s,y:m.y+d}))}),{previewBoxes:t,guideLines:$n(f)}}function $n(e){const t=new Map;return e.forEach(n=>{const r=`${n.orientation}:${Math.round(n.position)}`,o=t.get(r);if(!o){t.set(r,n);return}t.set(r,{...n,start:Math.min(o.start,n.start),end:Math.max(o.end,n.end)})}),Array.from(t.values())}function ft(e){return{x:e?String(e.x):"",y:e?String(e.y):"",width:e?String(e.width):"",height:e?String(e.height):""}}function ti({selectedNode:e,selectedLayoutBox:t,selectedNodes:n,showFreezeContainerAction:r,canFreezeContainer:o,onDuplicate:i,onFreezeContainer:s,onAlignLeft:d,onAlignRight:g,onAlignTop:x,onAlignBottom:f,onBoxChange:w}){const E=ke(e),m=n.length>1&&n.every(j=>ke(j).alignable),u=!!e&&E.strictModeLocked&&r,[P,k]=y.useState(()=>ft(t));y.useEffect(()=>{k(ft(t))},[e==null?void 0:e.id,t==null?void 0:t.x,t==null?void 0:t.y,t==null?void 0:t.width,t==null?void 0:t.height]);function L(j){if(!e)return;const $=P[j].trim();if(!$){k(ft(t));return}const G=Number($);if(!Number.isFinite(G)){k(ft(t));return}w({[j]:G})}return a.jsxs("div",{className:"static-html-presentation-layout-toolbar",children:[a.jsxs("div",{className:"static-html-presentation-layout-toolbar-row",children:[a.jsx("span",{className:"static-html-presentation-layout-badge",children:n.length>1?p("conversation.fileViewerPresentationLayoutSelectionCount").replace("{count}",String(n.length)):p("conversation.fileViewerPresentationLayoutMode")}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-layout-action",onClick:i,disabled:!e||!E.movable,children:p("conversation.fileViewerPresentationDuplicateAction")}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-layout-action",onClick:d,disabled:!m,children:p("conversation.fileViewerPresentationLayoutAlignLeft")}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-layout-action",onClick:g,disabled:!m,children:p("conversation.fileViewerPresentationLayoutAlignRight")}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-layout-action",onClick:x,disabled:!m,children:p("conversation.fileViewerPresentationLayoutAlignTop")}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-layout-action",onClick:f,disabled:!m,children:p("conversation.fileViewerPresentationLayoutAlignBottom")}),u?a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-layout-action",onClick:s,disabled:!o,children:p("conversation.fileViewerPresentationLayoutFreezeContainer")}):null]}),e?a.jsxs("div",{className:"static-html-presentation-layout-form",children:[a.jsxs("label",{className:"static-html-presentation-layout-field",children:[a.jsx("span",{children:p("conversation.fileViewerPresentationPositionXLabel")}),a.jsx("input",{type:"number",value:P.x,onChange:j=>k($=>({...$,x:j.target.value})),onBlur:()=>L("x"),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),L("x"))},disabled:!E.movable})]}),a.jsxs("label",{className:"static-html-presentation-layout-field",children:[a.jsx("span",{children:p("conversation.fileViewerPresentationPositionYLabel")}),a.jsx("input",{type:"number",value:P.y,onChange:j=>k($=>({...$,y:j.target.value})),onBlur:()=>L("y"),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),L("y"))},disabled:!E.movable})]}),a.jsxs("label",{className:"static-html-presentation-layout-field",children:[a.jsx("span",{children:p("conversation.fileViewerPresentationWidthLabel")}),a.jsx("input",{type:"number",value:P.width,onChange:j=>k($=>({...$,width:j.target.value})),onBlur:()=>L("width"),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),L("width"))},disabled:!E.resizable})]}),a.jsxs("label",{className:"static-html-presentation-layout-field",children:[a.jsx("span",{children:p("conversation.fileViewerPresentationHeightLabel")}),a.jsx("input",{type:"number",value:P.height,onChange:j=>k($=>({...$,height:j.target.value})),onBlur:()=>L("height"),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),L("height"))},disabled:!E.resizable})]}),E.reason?null:a.jsx("p",{className:"static-html-presentation-layout-hint",children:p("conversation.fileViewerPresentationLayoutHint")})]}):a.jsx("div",{className:"static-html-presentation-toolbar-empty static-html-presentation-inspector-empty",children:a.jsx("p",{className:"status-text",children:p("conversation.fileViewerPresentationLayoutSelectNode")})})]})}function ni({node:e,selectedRunIndex:t,onSelectedRunChange:n,compact:r=!1,onTextChange:o,onStyleChange:i}){const s=e.type==="text"||typeof e.content.text=="string",d=typeof e.style.fontSize=="number"?e.style.fontSize:null,g=e.style.fontFamily??"",x=oi(e.style.fontWeight),f=e.style.fontStyle??"",w=e.style.textDecoration??"",E=e.style.lineHeight??"",N=ln(e.style.color),m=ln(e.style.backgroundColor);return a.jsx("div",{className:"static-html-presentation-inspector-panel","data-compact":r?"true":void 0,children:a.jsx("div",{className:"static-html-presentation-inspector-controls","data-compact":r?"true":void 0,children:s?a.jsxs("div",{className:"static-html-presentation-text-edit-row",children:[a.jsx("div",{className:"static-html-presentation-text-toolbar",role:"toolbar","aria-label":p("conversation.fileViewerPresentationTextToolbar"),children:a.jsxs("div",{className:"static-html-presentation-text-toolbar-row",children:[a.jsxs("select",{className:"static-html-presentation-text-toolbar-select static-html-presentation-text-toolbar-font",value:g,onChange:u=>i({fontFamily:u.target.value||null}),disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationFontFamilyLabel"),children:[a.jsx("option",{value:"",children:p("conversation.fileViewerPresentationKeepOriginal")}),a.jsx("option",{value:'"PingFang SC", "Microsoft YaHei", sans-serif',children:p("conversation.fileViewerPresentationFontPresetTitle")}),a.jsx("option",{value:'"Noto Sans SC", "PingFang SC", sans-serif',children:p("conversation.fileViewerPresentationFontPresetSans")}),a.jsx("option",{value:'Georgia, "Times New Roman", serif',children:p("conversation.fileViewerPresentationFontPresetSerif")}),a.jsx("option",{value:'"SF Mono", "Cascadia Mono", monospace',children:p("conversation.fileViewerPresentationFontPresetMono")})]}),a.jsxs("select",{className:"static-html-presentation-text-toolbar-select static-html-presentation-text-toolbar-size",value:d?String(d):"",onChange:u=>{const P=u.target.value.trim();i({fontSize:P?Number(P):null})},disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationFontSizeLabel"),children:[a.jsx("option",{value:"",children:p("conversation.fileViewerPresentationKeepOriginal")}),[12,14,16,18,20,24,28,32,40,48,60].map(u=>a.jsx("option",{value:u,children:u},u))]}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-text-toolbar-button","data-active":x==="700"?"true":void 0,onClick:()=>i({fontWeight:x==="700"?null:"700"}),disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationBoldAction"),children:"B"}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-text-toolbar-button static-html-presentation-text-toolbar-button-italic","data-active":f==="italic"?"true":void 0,onClick:()=>i({fontStyle:f==="italic"?null:"italic"}),disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationItalicAction"),children:"I"}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-text-toolbar-button static-html-presentation-text-toolbar-button-underline","data-active":w.includes("underline")?"true":void 0,onClick:()=>i({textDecoration:w.includes("underline")?null:"underline"}),disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationUnderlineAction"),children:"U"}),a.jsxs("label",{className:"static-html-presentation-text-toolbar-color","aria-label":p("conversation.fileViewerPresentationTextColorLabel"),children:[a.jsx("span",{className:"static-html-presentation-text-toolbar-color-label",style:{"--static-html-toolbar-color":N},children:"A"}),a.jsx("input",{type:"color",value:N,onChange:u=>i({color:u.target.value}),disabled:!e.editable})]}),a.jsxs("label",{className:"static-html-presentation-text-toolbar-color","aria-label":p("conversation.fileViewerPresentationBackgroundColorLabel"),children:[a.jsx("span",{className:"static-html-presentation-text-toolbar-color-label static-html-presentation-text-toolbar-color-label-fill",style:{"--static-html-toolbar-color":m},children:"A"}),a.jsx("input",{type:"color",value:m,onChange:u=>i({backgroundColor:u.target.value}),disabled:!e.editable})]}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-text-toolbar-button",onClick:()=>i({fontSize:Math.max(8,(d??24)-2)}),disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationFontSizeDecreaseAction"),children:"A-"}),a.jsx("button",{type:"button",className:"secondary-button static-html-presentation-text-toolbar-button",onClick:()=>i({fontSize:Math.min(160,(d??24)+2)}),disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationFontSizeIncreaseAction"),children:"A+"}),a.jsxs("select",{className:"static-html-presentation-text-toolbar-select static-html-presentation-text-toolbar-line-height",value:E,onChange:u=>i({lineHeight:u.target.value||null}),disabled:!e.editable,"aria-label":p("conversation.fileViewerPresentationLineHeightLabel"),children:[a.jsx("option",{value:"",children:p("conversation.fileViewerPresentationLineHeightAuto")}),a.jsx("option",{value:"1",children:"1.0"}),a.jsx("option",{value:"1.2",children:"1.2"}),a.jsx("option",{value:"1.4",children:"1.4"}),a.jsx("option",{value:"1.6",children:"1.6"}),a.jsx("option",{value:"1.8",children:"1.8"}),a.jsx("option",{value:"2",children:"2.0"})]})]})}),a.jsx("textarea",{hidden:!0,readOnly:!0,value:e.content.text??"","aria-hidden":"true",tabIndex:-1}),a.jsx(ri,{node:e,selectedRunIndex:t,onSelectedRunChange:n,disabled:!e.editable,onChange:o})]}):a.jsx("p",{className:"static-html-presentation-inspector-warning",children:e.lockedReason||p("conversation.fileViewerPresentationReadOnlyHint")})})})}function ri({node:e,selectedRunIndex:t,onSelectedRunChange:n,disabled:r,onChange:o}){const i=y.useMemo(()=>ii(e),[e]),s=y.useMemo(()=>i.length?t!==null&&t>=0&&t<i.length?t:0:null,[i,t]);function d(g,x){const f=i.map((w,E)=>E===g?{...dn(w),text:nt(x)}:dn(w));o({text:ai(f),runs:f})}return a.jsx("div",{className:"static-html-presentation-textarea static-html-presentation-textarea-standalone static-html-presentation-runs-editor","data-testid":"static-html-presentation-runs-editor",role:"group","aria-label":p("conversation.fileViewerPresentationTextToolbar"),children:i.map((g,x)=>a.jsx("label",{className:g.className??void 0,"data-static-html-run":String(x),"data-static-html-run-wrapper":"true","data-active":s===x?"true":void 0,"data-static-html-run-text":g.text,children:a.jsx("textarea",{className:"static-html-presentation-run-input","data-static-html-run-input":"true",value:g.text,disabled:r,rows:1,spellCheck:!1,"aria-label":`${p("conversation.fileViewerPresentationNodeTextLabel")} ${x+1}`,onFocus:()=>n(x),onClick:()=>n(x),onChange:f=>{d(x,f.target.value)},style:li(g.style??null)})},`${x}-${g.tagName??"text"}-${g.className??"none"}`))})}function ln(e){if(!e||!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e.trim()))return"#000000";const t=e.trim();return t.length===4?`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`:t}function oi(e){return e?e==="bold"?"700":e:""}function cn(e,t){const n=nt(t),r=Array.isArray(e.content.runs)?e.content.runs:[];if(r.length===0)return n?[{text:n}]:null;const o=r.map(s=>({...s})),i=ci(o);return i<0?n?[{text:n}]:null:(o[i]={...o[i],text:n},o)}function ii(e){if(Array.isArray(e.content.runs)&&e.content.runs.length>0)return e.content.runs.map(n=>({...n,style:n.style?{...n.style}:null}));const t=nt(e.content.text??"");return t?[{text:t}]:[]}function ai(e){return!e||e.length===0?"":nt(e.map(t=>t.text).join(""))}function dn(e){return{...e,style:e.style?{...e.style}:null}}function si(e){if(e)return{fontFamily:e.fontFamily??void 0,fontSize:typeof e.fontSize=="number"?`${e.fontSize}px`:void 0,fontWeight:e.fontWeight??void 0,fontStyle:e.fontStyle??void 0,lineHeight:e.lineHeight??void 0,letterSpacing:e.letterSpacing??void 0,color:e.color??void 0,textDecoration:e.textDecoration??void 0,textDecorationColor:e.textDecorationColor??void 0,backgroundColor:e.backgroundColor??void 0,whiteSpace:"pre-wrap"}}function li(e){return{...si(e),width:"100%",minHeight:"34px",padding:"6px 8px",border:"none",outline:"none",resize:"none",overflow:"hidden",background:"transparent"}}function ci(e){let t=-1,n=-1;return e.forEach((r,o)=>{const i=r.text.trim().length;i>n&&(n=i,t=o)}),t}const pt="allow-forms allow-modals allow-scripts",di=`${pt} allow-same-origin`,ui=new Set(["abstract","as","async","await","break","case","catch","class","const","continue","default","delete","do","else","enum","export","extends","false","finally","for","from","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","readonly","return","static","super","switch","this","throw","true","try","type","typeof","undefined","var","void","while","with","yield"]),fi=new Set(["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","False","finally","for","from","global","if","import","in","is","lambda","None","nonlocal","not","or","pass","raise","return","True","try","while","with","yield"]),hi=new Set(["case","do","done","elif","else","esac","export","fi","for","function","if","in","local","readonly","return","then","until","while"]),pi=new Set(["add","alter","and","as","asc","between","by","create","delete","desc","drop","from","group","having","insert","into","join","left","like","limit","not","null","offset","on","or","order","right","select","set","table","union","update","values","where"]),mi=new Set(["add","arg","cmd","copy","entrypoint","env","expose","from","healthcheck","label","maintainer","onbuild","run","shell","stopsignal","user","volume","workdir","as"]),gi=new Set(["trace","debug","info","warn","warning","error","fatal"]);function ba(e){return a.jsx(xi,{...e,chrome:"modal"})}function xi({workspaceId:e,filePath:t,open:n,onClose:r,onSaved:o,diffContent:i,chrome:s="modal",windowTitle:d=null,showDetachAction:g=!1,onDetach:x}){var Pe,l;const[f,w]=y.useState(null),[E,N]=y.useState(""),[m,u]=y.useState(null),[P,k]=y.useState(!1),[L,j]=y.useState(!1),[$,G]=y.useState(!1),[W,M]=y.useState(!1),[A,U]=y.useState("preview"),[fe,H]=y.useState("regular"),[Q,C]=y.useState(0),[ee,ie]=y.useState("fit"),[We,he]=y.useState(1),[Z,ve]=y.useState(1),[Re,we]=y.useState(110),[Ce,be]=y.useState(!0),{showToast:te}=fn(),ne=hn(),q=y.useRef(r),$e=y.useRef(te),je=y.useMemo(()=>Gt(t),[t]),ae=y.useMemo(()=>fa(i),[i]),D=y.useMemo(()=>ha(E,ae),[E,ae]),O=(f==null?void 0:f.kind)??null,pe=!!((Pe=f==null?void 0:f.capabilities)!=null&&Pe.canEdit),Ie=!!((l=f==null?void 0:f.capabilities)!=null&&l.canRefresh),Ne=y.useMemo(()=>Ri(f,ne.isDesktop),[ne.isDesktop,f]),me=y.useMemo(()=>Ci(f,ne.isDesktop),[ne.isDesktop,f]),ge=y.useMemo(()=>Bt(Ne,Q),[Ne,Q]),xe=y.useMemo(()=>ji(Ne,Q,Z,Re,Ce),[Ne,Q,Z,Re,Ce]),v=y.useMemo(()=>Bt(Ne,Q),[Ne,Q]),V=(f==null?void 0:f.content)??"",K=y.useMemo(()=>O!=="html"||!m?null:Vr({html:V,project:m}),[V,m,O]),re=pe&&(E!==V||A==="presentation"&&!!K&&K!==V),Be=y.useMemo(()=>O!=="html"||!V.trim()?null:_t(V,t??"document.html"),[V,t,O]),Te=y.useMemo(()=>wi({filePath:t,html:V,probe:Be}),[V,t,Be]),se=On(O),kt=Hn(O)&&O!=="html",It=_n(O)&&pe,Se=ne.isMobile,De=s==="window",oe=s==="modal",Pt=A==="presentation"&&O==="html",ot=!De&&!Se&&O==="html",it=Se||ot?"full":fe;if(y.useEffect(()=>{q.current=r},[r]),y.useEffect(()=>{$e.current=te},[te]),y.useEffect(()=>{if(!n){w(null),N(""),u(null),k(!1),j(!1),G(!1),M(!1),U(Bn(t,null)),Dn({setResourceRefreshVersion:C,setImageScale:he,setImageScaleMode:ie,setPdfPage:ve,setPdfScale:we,setPdfFitWidth:be}),H("regular");return}if(!e||!t)return;const c=e,h=t;let S=!1;async function b(){k(!0);try{const R=await jt(c,h);S||Wt(R,h,{preserveMode:!1,setPreview:w,setEditorContent:N,setPresentationProject:u,setMode:U,setResourceRefreshVersion:C,setImageScale:he,setImageScaleMode:ie,setPdfPage:ve,setPdfScale:we,setPdfFitWidth:be})}catch(R){S||($e.current({title:ht(R,p("conversation.filePanelOpenFailed")),tone:"error"}),q.current())}finally{S||k(!1)}}return b(),()=>{S=!0}},[t,n,e]),!n||!t)return null;const Y=t,ue=e;async function Oe(){if(!(!ue||!(f!=null&&f.version)||!pe)){j(!0);try{await lr(ue,Y,A==="presentation"&&m?K??E:E,f.version);const h=await jt(ue,Y);Wt(h,Y,{preserveMode:!1,setPreview:w,setEditorContent:N,setPresentationProject:u,setMode:U,setResourceRefreshVersion:C,setImageScale:he,setImageScaleMode:ie,setPdfPage:ve,setPdfScale:we,setPdfFitWidth:be}),await o(Y),te({title:p("conversation.filePanelSaveSuccess"),tone:"success"})}catch(c){te({title:ht(c,p("conversation.filePanelSaveFailed")),tone:"error"})}finally{j(!1)}}}async function at(){if(!(!ue||!Ie||re)){k(!0);try{const c=await jt(ue,Y);Wt(c,Y,{preserveMode:!0,setPreview:w,setEditorContent:N,setPresentationProject:u,setMode:U,setResourceRefreshVersion:C,setImageScale:he,setImageScaleMode:ie,setPdfPage:ve,setPdfScale:we,setPdfFitWidth:be}),C(h=>h+1)}catch(c){te({title:ht(c,p("conversation.fileViewerRefreshFailed")),tone:"error"})}finally{k(!1)}}}async function He(){if(!me)return;const c=await ne.bridge.openExternal(me);c.ok||te({title:c.detail??p("conversation.fileViewerOpenExternalFailed"),tone:"error"})}async function Et(){await Ue("pdf")}async function _e(){await Ue("pptx")}async function Ue(c){if(!ue||O!=="html"||!Te||(c==="pdf"?$:W))return;const S=A==="presentation"&&m?K??E:E;if(!S.trim()){te({title:c==="pdf"?p("conversation.fileViewerExportPdfMissingHtml"):p("conversation.fileViewerExportPptxMissingHtml"),tone:"error"});return}c==="pdf"?G(!0):M(!0);try{const b=await Pr({workspaceId:ue,path:Y,htmlContent:S,format:c}),R=await ca(b.taskId);if(R.status!=="succeeded")throw new Ot(500,{detail:R.errorMessage??(c==="pdf"?p("conversation.fileViewerExportPdfFailed"):p("conversation.fileViewerExportPptxFailed")),error_code:"PRESENTATION_EXPORT_FAILED"});const I=await Rr(R.taskId);ma(I.fileName,I.blob),te({title:c==="pdf"?p("conversation.fileViewerExportPdfSuccess",{path:I.fileName}):p("conversation.fileViewerExportPptxSuccess",{path:I.fileName}),tone:"success"})}catch(b){te({title:ht(b,c==="pdf"?p("conversation.fileViewerExportPdfFailed"):p("conversation.fileViewerExportPptxFailed")),tone:"error"})}finally{c==="pdf"?G(!1):M(!1)}}const Me=Ii({canShowPresentationTab:Te,canShowPreviewTab:se,canShowCodeTab:kt,canShowEditTab:It}),qe=Pi({preview:f,canOpenExternal:!!me,canExportPdf:O==="html"&&Te,canExportPptx:O==="html"&&Te,exportingPdf:$,exportingPptx:W,isDirty:re,handleRefreshPreview:at,handleExportPdf:Et,handleExportPptx:_e,handleOpenExternal:He,imageScaleMode:ee,imageScale:We,setImageScale:he,setImageScaleMode:ie,pdfPage:Z,setPdfPage:ve,pdfScale:Re,setPdfScale:we,pdfFitWidth:Ce,setPdfFitWidth:be}),st=Se?qe.filter(Ei):qe,lt=pe&&A==="edit"&&!Pt,Le=a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"file-viewer-header-tabs",role:"tablist","aria-label":p("conversation.fileViewerModeLabel"),children:[Me.includes("presentation")?a.jsx("button",{type:"button",className:"file-viewer-tab","data-active":A==="presentation",role:"tab","aria-selected":A==="presentation",onClick:()=>U("presentation"),children:p("conversation.fileViewerPresentation")}):null,Me.includes("preview")?a.jsx("button",{type:"button",className:"file-viewer-tab","data-active":A==="preview",role:"tab","aria-selected":A==="preview",onClick:()=>U("preview"),children:p("conversation.fileViewerPreview")}):null,Me.includes("code")?a.jsx("button",{type:"button",className:"file-viewer-tab","data-active":A==="code",role:"tab","aria-selected":A==="code",onClick:()=>U("code"),children:p("conversation.fileViewerCode")}):null,Me.includes("edit")?a.jsx("button",{type:"button",className:"file-viewer-tab","data-active":A==="edit",role:"tab","aria-selected":A==="edit",onClick:()=>U("edit"),disabled:!pe,children:p("conversation.fileViewerEdit")}):null]}),!De&&!Se&&!ot?a.jsxs("div",{className:"file-viewer-size-group",role:"group","aria-label":p("conversation.fileViewerSizeLabel"),children:[a.jsx("button",{type:"button",className:"secondary-button file-viewer-action-button","data-active":fe==="regular",onClick:()=>H("regular"),children:p("conversation.fileViewerSizeDefault")}),a.jsx("button",{type:"button",className:"secondary-button file-viewer-action-button","data-active":fe==="full",onClick:()=>H("full"),children:p("conversation.fileViewerSizeFull")})]}):null,a.jsxs("div",{className:"file-viewer-header-action-buttons",children:[st.map(c=>a.jsx("button",{type:"button",className:"secondary-button file-viewer-action-button","data-active":c.active?"true":void 0,onClick:()=>void c.onClick(),disabled:c.disabled,children:c.label},c.id)),lt?a.jsx("button",{type:"button",className:"primary-button",onClick:()=>void Oe(),disabled:!re||L,children:L?p("conversation.filePanelSaving"):p("conversation.filePanelSave")}):null]})]}),Rt=g&&x?a.jsx("button",{type:"button",className:"workbench-modal-close file-viewer-detach-button","aria-label":p("conversation.fileViewerOpenInWindow"),title:p("conversation.fileViewerOpenInWindow"),onClick:()=>void x(),children:a.jsx("svg",{viewBox:"0 0 16 16",width:"16",height:"16","aria-hidden":"true",children:a.jsx("path",{d:"M5 3.5h7.5V11M12.5 3.5 7.8 8.2M3.5 6.5v6h6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})}):null,ct=a.jsxs(a.Fragment,{children:[Se&&oe?a.jsx("div",{className:"file-viewer-toolbar",children:Le}):null,a.jsx("div",{className:"file-viewer-body",children:P?a.jsx("p",{className:"status-text",children:p("common.loading")}):(f==null?void 0:f.supported)===!1?a.jsx("p",{className:"status-text",children:f.reason??p("conversation.filePanelUnsupported")}):A==="presentation"&&O==="html"?a.jsx(Bo,{filePath:t,html:E,baseHref:v,onProjectChange:u,onSave:()=>void Oe(),canSave:re,saving:L}):A==="edit"?a.jsx(Ai,{content:E,language:je,onContentChange:N}):A==="preview"&&O==="html"?a.jsx(Mi,{src:v,workspaceId:ue,filePath:t,overviewMarkers:ae,overviewTotalLines:D}):A==="preview"&&O==="image"?a.jsx(zi,{src:ge,filePath:t,scale:We,scaleMode:ee,overviewMarkers:ae,overviewTotalLines:D}):A==="preview"&&O==="pdf"?a.jsx(Vi,{src:xe,filePath:t,overviewMarkers:ae,overviewTotalLines:D}):A==="preview"&&O==="markdown"?a.jsx(Fi,{content:E,overviewMarkers:ae,overviewTotalLines:D}):a.jsx(Kn,{content:E,language:je,overviewMarkers:ae,overviewTotalLines:D})})]});return De?a.jsxs("section",{className:"file-viewer-window-panel","aria-label":d??t,children:[a.jsxs("header",{className:"file-viewer-window-header","data-tauri-drag-region":"",children:[a.jsx("div",{className:"file-viewer-window-title-wrap","data-tauri-drag-region":"",children:a.jsx("h1",{"data-tauri-drag-region":"",children:d??t})}),a.jsxs("div",{className:"file-viewer-header-controls file-viewer-window-controls","data-window-drag":"ignore",children:[Le,a.jsx(ar,{onClick:r})]})]}),a.jsx("div",{className:"file-viewer-modal-body file-viewer-window-body",children:ct})]}):a.jsx(sr,{open:n,title:t,size:it,layout:"viewer",className:`file-viewer-modal${ne.isDesktop&&it!=="full"?" is-resizable":""}`,bodyClassName:"file-viewer-modal-body",headerActions:Se?void 0:a.jsx("div",{className:"file-viewer-header-controls",children:Le}),beforeCloseButton:Rt,onClose:r,children:ct})}const yi=new Set(["slides","slide","presentations","presentation","deck","decks","ppt","pptx"]),vi=new Set(["tools","tool"]);function wi(e){const{filePath:t,html:n,probe:r}=e;if(!(r!=null&&r.supported)||!n.trim())return!1;const o=bi(t);return o.some(i=>vi.has(i))?!1:Ni(n)||o.some(i=>yi.has(i))?!0:r.strategy==="deck-direct-child"?!1:Si(n)}function bi(e){return e?e.split(/[\\/]+/).map(t=>t.trim().toLowerCase()).filter(Boolean):[]}function Ni(e){return/<meta[^>]+name=["'](?:codingns-preview-mode|codingns-presentation|cns-preview-mode|cns-presentation)["'][^>]+content=["']presentation["'][^>]*>/i.test(e)||/\bdata-(?:codingns|cns)-(?:preview-mode|presentation)\s*=\s*["']presentation["']/i.test(e)}function Si(e){const t=/\bclass\s*=\s*["'][^"']*\bdeck\b[^"']*["']/i.test(e),n=/\bclass\s*=\s*["'][^"']*\bslide\b[^"']*["']/i.test(e),r=/\bdata-(?:slide|title)\s*=\s*["'][^"']+["']/i.test(e),o=/--deck-width\s*:|--deck-height\s*:|aspect-ratio\s*:\s*16\s*\/\s*9/i.test(e);return n&&(t||r||o)}function Bn(e,t){return t==="markdown"||t==="html"||t==="image"||t==="pdf"||aa(e??"")||sa(e??"")?"preview":"code"}function Wt(e,t,n){n.setPreview(e),n.setEditorContent(e.content??""),n.setPresentationProject(null),n.setMode(r=>n.preserveMode&&ki(r,e.kind)?r:Bn(t,e.kind)),Dn(n)}function Dn(e){e.setResourceRefreshVersion(0),e.setImageScale(1),e.setImageScaleMode("fit"),e.setPdfPage(1),e.setPdfScale(110),e.setPdfFitWidth(!0)}function On(e){return e==="markdown"||e==="html"||e==="image"||e==="pdf"}function Hn(e){return e==="text"||e==="markdown"||e==="html"}function _n(e){return e==="text"||e==="markdown"||e==="html"}function ki(e,t){return e==="presentation"?t==="html":e==="preview"?On(t):e==="code"?Hn(t):_n(t)}function Ii(e){const t=[];return e.canShowPresentationTab&&t.push("presentation"),e.canShowPreviewTab&&t.push("preview"),e.canShowCodeTab&&t.push("code"),e.canShowEditTab&&t.push("edit"),t}function Pi(e){var r,o;if(!((r=e.preview)!=null&&r.supported))return[];const t=[],n=!((o=e.preview.capabilities)!=null&&o.canRefresh)||e.isDirty;return e.preview.kind==="image"&&t.push({id:"image-zoom-out",label:p("conversation.fileViewerZoomOut"),onClick:()=>{e.setImageScaleMode("custom"),e.setImageScale(i=>Math.max(.25,un(i-.25)))}},{id:"image-zoom-in",label:p("conversation.fileViewerZoomIn"),onClick:()=>{e.setImageScaleMode("custom"),e.setImageScale(i=>Math.min(4,un(i+.25)))}},{id:"image-fit",label:p("conversation.fileViewerFit"),active:e.imageScaleMode==="fit",onClick:()=>{e.setImageScaleMode("fit"),e.setImageScale(1)}},{id:"image-actual",label:p("conversation.fileViewerActualSize"),active:e.imageScaleMode==="actual",onClick:()=>{e.setImageScaleMode("actual"),e.setImageScale(1)}},{id:"image-refresh",label:p("conversation.fileViewerRefreshPreview"),disabled:n,onClick:e.handleRefreshPreview}),e.preview.kind==="pdf"&&t.push({id:"pdf-prev-page",label:p("conversation.fileViewerPreviousPage"),disabled:e.pdfPage<=1,onClick:()=>e.setPdfPage(i=>Math.max(1,i-1))},{id:"pdf-page-indicator",label:p("conversation.fileViewerPageIndicator").replace("{page}",String(e.pdfPage)),disabled:!0,onClick:()=>{}},{id:"pdf-next-page",label:p("conversation.fileViewerNextPage"),onClick:()=>e.setPdfPage(i=>i+1)},{id:"pdf-zoom-out",label:p("conversation.fileViewerZoomOut"),onClick:()=>{e.setPdfFitWidth(!1),e.setPdfScale(i=>Math.max(50,Math.round(i-10)))}},{id:"pdf-zoom-in",label:p("conversation.fileViewerZoomIn"),onClick:()=>{e.setPdfFitWidth(!1),e.setPdfScale(i=>Math.min(300,Math.round(i+10)))}},{id:"pdf-fit-width",label:p("conversation.fileViewerFitWidth"),active:e.pdfFitWidth,onClick:()=>e.setPdfFitWidth(!0)},{id:"pdf-refresh",label:p("conversation.fileViewerRefreshPreview"),disabled:n,onClick:e.handleRefreshPreview}),(e.preview.kind==="html"||e.preview.kind==="markdown"||e.preview.kind==="text")&&t.push({id:"text-refresh",label:p("conversation.fileViewerRefreshPreview"),disabled:n,onClick:e.handleRefreshPreview}),e.preview.kind==="html"&&e.canExportPdf&&t.push({id:"presentation-export-pdf",label:e.exportingPdf?p("conversation.fileViewerExportPdfRunning"):p("conversation.fileViewerExportPdf"),disabled:e.exportingPdf,onClick:e.handleExportPdf}),e.preview.kind==="html"&&e.canExportPptx&&t.push({id:"presentation-export-pptx",label:e.exportingPptx?p("conversation.fileViewerExportPptxRunning"):p("conversation.fileViewerExportPptx"),disabled:e.exportingPptx,onClick:e.handleExportPptx}),e.canOpenExternal&&t.push({id:"open-external",label:p("conversation.fileViewerOpenExternal"),onClick:e.handleOpenExternal}),t}function Ei(e){return e.id.endsWith("-refresh")||e.id==="text-refresh"||e.id==="presentation-export-pdf"||e.id==="presentation-export-pptx"}function Bt(e,t){if(!e)return null;const n=new URL(e,window.location.origin);return n.searchParams.set("_preview",String(t)),n.searchParams.set("_cns_parent_origin",window.location.origin),n.hash="",n.toString()}function Ri(e,t){var n;if(!e)return null;if(e.previewPath){if(!t&&typeof window<"u"&&((n=window.location)!=null&&n.origin))return new URL(e.previewPath,window.location.origin).toString();if(t){const r=Un(e.previewPath);if(r)return r}}return e.previewUrl??null}function Ci(e,t){var n;if(!e)return null;if(e.previewPath){if(!t&&typeof window<"u"&&((n=window.location)!=null&&n.origin))return new URL(e.previewPath,window.location.origin).toString();if(t){const r=Un(e.previewPath);if(r)return r}}return e.previewUrl??null}function Un(e){try{const t=rr(or()).baseUrl;return ir(e,t)}catch{return null}}function ji(e,t,n,r,o){const i=Bt(e,t);if(!i)return null;const s=new URL(i,window.location.origin),d=new URLSearchParams;return d.set("page",String(n)),d.set("zoom",o?"page-width":String(r)),s.hash=d.toString(),s.toString()}function Ti(e){var t;if(typeof window>"u"||!((t=window.location)!=null&&t.origin))return pt;try{if(new URL(e,window.location.origin).origin!==window.location.origin)return di}catch{return pt}return pt}function un(e){return Math.round(e*100)/100}function Mi({src:e,workspaceId:t,filePath:n,overviewMarkers:r,overviewTotalLines:o}){const i=y.useRef(null),s=y.useRef(null);if(y.useEffect(()=>{if(!e||!t)return;const g=Sr({iframe:s.current,workspaceId:t});function x(f){g.onMessage(f)}return window.addEventListener("message",x),()=>{window.removeEventListener("message",x),g.dispose()}},[e,t]),!e)return a.jsx("p",{className:"status-text",children:p("conversation.fileViewerHtmlPreviewUnavailable")});const d=Ti(e);return a.jsx(Nt,{overviewMarkers:r,overviewTotalLines:o,scrollContainerRef:i,children:a.jsx("div",{className:"file-viewer-html-frame-shell",ref:i,children:a.jsx("iframe",{ref:s,className:"file-viewer-html-frame","data-testid":"file-viewer-html-preview",title:n,src:e,sandbox:d},e)})})}function Nt({children:e,overviewMarkers:t,overviewTotalLines:n,scrollContainerRef:r}){const o=Li(t);return a.jsxs("div",{className:"file-viewer-preview-overview-shell",children:[e,o?a.jsx("div",{className:"file-viewer-preview-diff-badge","data-kind":o,children:o==="modify"?p("conversation.fileViewerDiffModified"):p("conversation.fileViewerDiffAdded")}):null,a.jsx(Qn,{markers:t,totalLines:n,scrollContainerRef:r,hideWithoutMarkers:!0})]})}function Li(e){return e.some(t=>t.kind==="modify")?"modify":e.some(t=>t.kind==="add")?"add":null}function Ai(e){return a.jsx(Kn,{content:e.content,language:e.language,overviewMarkers:[],overviewTotalLines:Math.max(1,e.content.split(/\r?\n/).length),editable:!0,onContentChange:e.onContentChange})}function zi({src:e,filePath:t,scale:n,scaleMode:r,overviewMarkers:o,overviewTotalLines:i}){const s=y.useRef(null);return e?a.jsx(Nt,{overviewMarkers:o,overviewTotalLines:i,scrollContainerRef:s,children:a.jsx("div",{className:"file-viewer-media-shell","data-mode":r,ref:s,children:a.jsx("div",{className:"file-viewer-image-stage",children:a.jsx("img",{className:"file-viewer-image","data-testid":"file-viewer-image-preview","data-mode":r,src:e,alt:t,style:r==="fit"?void 0:{transform:`scale(${n})`}})})})}):a.jsx("p",{className:"status-text",children:p("conversation.fileViewerImageUnavailable")})}function Vi({src:e,filePath:t,overviewMarkers:n,overviewTotalLines:r}){const o=y.useRef(null);return e?a.jsx(Nt,{overviewMarkers:n,overviewTotalLines:r,scrollContainerRef:o,children:a.jsx("div",{className:"file-viewer-pdf-shell",ref:o,children:a.jsx("iframe",{className:"file-viewer-pdf-frame","data-testid":"file-viewer-pdf-preview",title:t,src:e},e)})}):a.jsx("p",{className:"status-text",children:p("conversation.fileViewerPdfUnavailable")})}function Fi({content:e,overviewMarkers:t,overviewTotalLines:n}){const r=y.useRef(null),o=y.useMemo(()=>Wi(t),[t]),i=y.useMemo(()=>$i(o),[o]);return a.jsx(Nt,{overviewMarkers:t,overviewTotalLines:n,scrollContainerRef:r,children:a.jsx("div",{className:"markdown-content file-viewer-markdown",ref:r,children:a.jsx(cr,{remarkPlugins:[dr],components:i,children:e})})})}function Wi(e){return{ranges:e.map(t=>({start:t.line,end:t.line+t.span-1,kind:t.kind})).sort((t,n)=>t.start-n.start)}}function $i(e){return{h1(t){const{node:n,className:r,...o}=t;return a.jsx("h1",{...o,className:de(r,n,e)})},h2(t){const{node:n,className:r,...o}=t;return a.jsx("h2",{...o,className:de(r,n,e)})},h3(t){const{node:n,className:r,...o}=t;return a.jsx("h3",{...o,className:de(r,n,e)})},h4(t){const{node:n,className:r,...o}=t;return a.jsx("h4",{...o,className:de(r,n,e)})},h5(t){const{node:n,className:r,...o}=t;return a.jsx("h5",{...o,className:de(r,n,e)})},h6(t){const{node:n,className:r,...o}=t;return a.jsx("h6",{...o,className:de(r,n,e)})},p(t){const{node:n,className:r,...o}=t;return a.jsx("p",{...o,className:de(r,n,e)})},li(t){const{node:n,className:r,...o}=t;return a.jsx("li",{...o,className:de(r,n,e)})},blockquote(t){const{node:n,className:r,...o}=t;return a.jsx("blockquote",{...o,className:de(r,n,e)})},table(t){const{node:n,className:r,...o}=t;return a.jsx("table",{...o,className:de(r,n,e)})},pre(t){const{node:n,className:r}=t,o=Hi(t.children);return o?a.jsx(Oi,{content:o.content,language:o.language,codeClassName:o.codeClassName,changeKind:qn(n,e)}):a.jsx("pre",{className:de(r,n,e),children:t.children})},code(t){const n=typeof t.className=="string"?t.className:"";return a.jsx("code",{className:n||void 0,children:t.children})}}}function de(e,t,n){const r=typeof e=="string"?e:"",o=qn(t,n);return Yn(r,o?"markdown-diff-block":null,o?`diff-block-${o}`:null)}function qn(e,t){var s,d,g,x;const n=(d=(s=e==null?void 0:e.position)==null?void 0:s.start)==null?void 0:d.line,r=(x=(g=e==null?void 0:e.position)==null?void 0:g.end)==null?void 0:x.line;if(!n||!r)return null;let o=!1;const i=Bi(t.ranges,n);for(let f=i;f<t.ranges.length;f+=1){const w=t.ranges[f];if(!w||w.start>r)break;if(w.end>=n){if(w.kind==="modify")return"modify";o=!0}}return o?"add":null}function Bi(e,t){let n=0,r=e.length;for(;n<r;){const o=Math.floor((n+r)/2),i=e[o];i&&i.end<t?n=o+1:r=o}return n}function Kn({content:e,language:t,overviewMarkers:n=[],overviewTotalLines:r,editable:o=!1,onContentChange:i}){const s=e.split(/\r?\n/),d=y.useRef(null),g=y.useMemo(()=>{const x=new Map;for(const f of n)for(let w=0;w<f.span;w++)x.set(f.line+w,f.kind);return x},[n]);return a.jsxs("div",{className:"file-viewer-code-block",children:[a.jsxs("div",{className:"file-viewer-code-header",children:[a.jsx("span",{className:"file-viewer-code-header-label",children:Zn(t)}),a.jsx(Xn,{content:e})]}),a.jsxs("div",{className:"file-viewer-scroll-shell",children:[a.jsx("div",{className:"file-viewer-code-body","data-editable":o?"true":void 0,ref:d,children:o?a.jsx(Di,{content:e,language:t,onContentChange:i,lineChangeMap:g}):s.map((x,f)=>{const w=Gn(x,t),E=f+1,N=g.get(E);return a.jsxs("div",{className:`file-viewer-code-line${N?` diff-line-${N}`:""}`,children:[a.jsx("span",{className:"file-viewer-code-gutter",children:E}),a.jsx("code",{className:"file-viewer-code-content",children:w.length?w.map((m,u)=>a.jsx("span",{className:`code-token ${m.kind}`,children:m.text},`${f}-${u}-${m.text}`)):a.jsx("span",{className:"code-token plain",children:" "})})]},`${f}-${x}`)})}),a.jsx(Qn,{markers:n,totalLines:r,scrollContainerRef:d})]})]})}function Di({content:e,language:t,onContentChange:n,lineChangeMap:r}){const o=y.useRef(null),i=y.useRef(null),[s,d]=y.useState([]);y.useLayoutEffect(()=>{const f=o.current;if(!f)return;let w=0;const E=f;function N(){const k=Array.from(E.querySelectorAll("[data-editor-line-index]")).map(L=>Math.max(24,Math.ceil(L.getBoundingClientRect().height)));d(L=>L.length===k.length&&L.every((j,$)=>j===k[$])?L:k)}const m=globalThis.window;function u(){if(!m){N();return}m.cancelAnimationFrame(w),w=m.requestAnimationFrame(N)}u();const P=typeof ResizeObserver>"u"?null:new ResizeObserver(u);return P==null||P.observe(E),()=>{m==null||m.cancelAnimationFrame(w),P==null||P.disconnect()}},[e,t]);function g(f){const w=o.current,E=i.current;w&&(w.scrollTop=f.currentTarget.scrollTop,w.scrollLeft=f.currentTarget.scrollLeft,E&&(E.scrollTop=f.currentTarget.scrollTop))}const x=e.split(/\r?\n/);return a.jsxs("div",{className:"file-viewer-code-editor-shell",children:[a.jsx("div",{ref:i,className:"file-viewer-code-editor-gutter","aria-hidden":"true",children:x.map((f,w)=>{const E=w+1,N=r.get(E);return a.jsx("div",{className:`file-viewer-code-editor-gutter-line${N?` diff-line-${N}`:""}`,style:s[w]?{height:`${s[w]}px`}:void 0,children:a.jsx("span",{className:"file-viewer-code-gutter",children:E})},`gutter-${w}-${f}`)})}),a.jsxs("div",{className:"file-viewer-code-editor-pane",children:[a.jsx("div",{ref:o,className:"file-viewer-code-editor-render","data-testid":"file-viewer-inline-render","aria-hidden":"true",children:x.map((f,w)=>{const E=Gn(f,t),N=w+1,m=r.get(N);return a.jsx("div",{className:`file-viewer-code-editor-line${m?` diff-line-${m}`:""}`,"data-editor-line-index":w,children:a.jsx("code",{className:"file-viewer-code-content",children:E.length?E.map((u,P)=>a.jsx("span",{className:`code-token ${u.kind}`,children:u.text},`${w}-${P}-${u.text}`)):a.jsx("span",{className:"code-token plain",children:" "})})},`${w}-${f}`)})}),a.jsx("textarea",{className:"file-viewer-editor file-viewer-code-editor-input","data-testid":"file-viewer-editor",value:e,onChange:f=>n==null?void 0:n(f.target.value),onScroll:g,spellCheck:!1})]})]})}function Oi({content:e,language:t,codeClassName:n,changeKind:r=null}){const o=t?Jt(t):null;return a.jsxs("div",{className:Yn("file-viewer-markdown-copy-block",r?"markdown-diff-block":null,r?`diff-block-${r}`:null),children:[a.jsxs("div",{className:"file-viewer-markdown-copy-header",children:[a.jsx("span",{className:"file-viewer-markdown-copy-label",children:o?Zn(o):p("conversation.fileViewerPlainText")}),a.jsx(Xn,{content:e})]}),a.jsx("pre",{className:n,children:a.jsx("code",{children:e})})]})}function Yn(...e){return e.filter(Boolean).join(" ")||void 0}function Xn({content:e}){const{showToast:t}=fn(),n=hn(),[r,o]=y.useState(!1);if(!e.trim())return null;async function i(){if(!r){o(!0);try{await Ui(e,n),t({title:p("conversation.copyContentSuccess"),tone:"success"})}catch(s){t({title:s instanceof Error?s.message:p("conversation.copyContentFailed"),tone:"error"})}finally{o(!1)}}}return a.jsx("button",{type:"button",className:"file-viewer-copy-button","aria-label":p("conversation.copyAction"),title:p("conversation.copyAction"),onClick:()=>void i(),disabled:r,children:a.jsx(la,{})})}function Dt(e){var t;return typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(n=>Dt(n)).join(""):y.isValidElement(e)?Dt(((t=e.props)==null?void 0:t.children)??""):""}function Hi(e){const t=Array.isArray(e)?e[0]:e;if(!y.isValidElement(t))return null;const n=t.props,r=typeof n.className=="string"?n.className:"",o=/language-([^\s]+)/.exec(r);return{content:Dt(n.children).replace(/\n$/,""),codeClassName:r||void 0,language:(o==null?void 0:o[1])??null}}function _i(e){if(typeof document>"u"||typeof document.execCommand!="function")return!1;const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly","true"),t.style.position="fixed",t.style.top="-9999px",t.style.left="-9999px",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.select();try{return document.execCommand("copy")}catch{return!1}finally{document.body.removeChild(t)}}async function Ui(e,t){var n;if(!(t.isDesktop&&(await t.bridge.writeClipboardText(e)).ok)){if(typeof navigator<"u"&&((n=navigator.clipboard)!=null&&n.writeText))try{await navigator.clipboard.writeText(e);return}catch{}if(!_i(e))throw new Error(p("conversation.copyContentFailed"))}}function Gn(e,t){const n=Jt(t);return n==="json"?qi(e):n==="yaml"?Gi(e):n==="toml"?Ji(e):n==="ini"?Jn(e):n==="env"?Zi(e):n==="properties"?Qi(e):n==="conf"?ea(e):n==="editorconfig"?ta(e):n==="dockerfile"?na(e):n==="gitignore"?ra(e):n==="log"?oa(e):n==="python"?et(e,fi,"#"):n==="shell"?et(e,hi,"#"):n==="sql"?Xi(e):n==="html"||n==="xml"?Ki(e):n==="css"?Yi(e):n==="markdown"?[{text:e,kind:"plain"}]:et(e,ui,"//")}function et(e,t,n){const r=[];let o=0;for(;o<e.length;){const i=e.slice(o);if(i.startsWith(n)){r.push({text:i,kind:"comment"});break}const s=/^(?:'[^'\\]*(?:\\.[^'\\]*)*'|"[^"\\]*(?:\\.[^"\\]*)*"|`[^`\\]*(?:\\.[^`\\]*)*`)/.exec(i);if(s){r.push({text:s[0],kind:"string"}),o+=s[0].length;continue}const d=/^(?:0x[\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)/.exec(i);if(d){r.push({text:d[0],kind:"number"}),o+=d[0].length;continue}const g=/^[A-Za-z_][\w$-]*/.exec(i);if(g){const f=g[0],w=f.toLowerCase();f==="true"||f==="false"||w==="true"||w==="false"?r.push({text:f,kind:"boolean"}):f==="null"||f==="None"||w==="none"?r.push({text:f,kind:"null"}):t.has(f)||t.has(w)?r.push({text:f,kind:"keyword"}):r.push({text:f,kind:"plain"}),o+=f.length;continue}const x=/^(?:===|!==|==|!=|<=|>=|=>|&&|\|\||[+\-*/%=<>!?:|&^~]+)/.exec(i);if(x){r.push({text:x[0],kind:"operator"}),o+=x[0].length;continue}r.push({text:i[0]??"",kind:"plain"}),o+=1}return r}function qi(e){const t=[];let n=0;for(;n<e.length;){const r=e.slice(n),o=/^"(?:[^"\\]|\\.)*"/.exec(r);if(o){const g=e.slice(n+o[0].length).trimStart()[0];t.push({text:o[0],kind:g===":"?"attr":"string"}),n+=o[0].length;continue}const i=/^(?:-?\d+(?:\.\d+)?(?:e[+-]?\d+)?)/i.exec(r);if(i){t.push({text:i[0],kind:"number"}),n+=i[0].length;continue}const s=/^(?:true|false|null)\b/.exec(r);if(s){const g=s[0]==="null"?"null":"boolean";t.push({text:s[0],kind:g}),n+=s[0].length;continue}const d=/^(?::|,|\{|\}|\[|\])/.exec(r);if(d){t.push({text:d[0],kind:"operator"}),n+=d[0].length;continue}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function Ki(e){const t=[];let n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith("<!--")){t.push({text:r,kind:"comment"});break}const o=/^(<\/?[\w:-]+)/.exec(r);if(o){t.push({text:o[0],kind:"tag"}),n+=o[0].length;continue}const i=/^([\w:-]+)(=)/.exec(r);if(i){t.push({text:i[1]??"",kind:"attr"}),t.push({text:i[2]??"",kind:"operator"}),n+=i[0].length;continue}const s=/^(?:'[^']*'|"[^"]*")/.exec(r);if(s){t.push({text:s[0],kind:"string"}),n+=s[0].length;continue}const d=/^(?:\/?>)/.exec(r);if(d){t.push({text:d[0],kind:"operator"}),n+=d[0].length;continue}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function Yi(e){const t=[];let n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith("/*")){t.push({text:r,kind:"comment"});break}const o=/^(?:'[^']*'|"[^"]*")/.exec(r);if(o){t.push({text:o[0],kind:"string"}),n+=o[0].length;continue}const i=/^([A-Za-z-]+)(\s*:)/.exec(r);if(i){t.push({text:i[1]??"",kind:"attr"}),t.push({text:i[2]??"",kind:"operator"}),n+=i[0].length;continue}const s=/^(?:#(?:[\da-fA-F]{3,8})|\d+(?:\.\d+)?(?:px|rem|em|vh|vw|%)?)/.exec(r);if(s){t.push({text:s[0],kind:"number"}),n+=s[0].length;continue}const d=/^(?:@media|@supports|@import|@keyframes)\b/.exec(r);if(d){t.push({text:d[0],kind:"keyword"}),n+=d[0].length;continue}const g=/^(?:[{}:;(),.>])/.exec(r);if(g){t.push({text:g[0],kind:"operator"}),n+=g[0].length;continue}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function Xi(e){return et(e,pi,"--")}function Gi(e){const t=[];let n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith("#")){t.push({text:r,kind:"comment"});break}const o=/^([A-Za-z0-9_.-]+)(\s*:)/.exec(r);if(o){t.push({text:o[1]??"",kind:"attr"}),t.push({text:o[2]??"",kind:"operator"}),n+=o[0].length;continue}const i=/^(?:'[^']*'|"[^"]*")/.exec(r);if(i){t.push({text:i[0],kind:"string"}),n+=i[0].length;continue}const s=/^(?:-?\d+(?:\.\d+)?)/.exec(r);if(s){t.push({text:s[0],kind:"number"}),n+=s[0].length;continue}const d=/^(?:true|false|yes|no|null|~)\b/i.exec(r);if(d){const x=d[0].toLowerCase(),f=x==="null"||x==="~"?"null":"boolean";t.push({text:d[0],kind:f}),n+=d[0].length;continue}const g=/^(?:[-?:,[\]{}|>])/.exec(r);if(g){t.push({text:g[0],kind:"operator"}),n+=g[0].length;continue}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function Ji(e){const t=[];let n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith("#")){t.push({text:r,kind:"comment"});break}const o=/^(\[\[?[^\]]+\]?\])/.exec(r);if(o){t.push({text:o[0],kind:"tag"}),n+=o[0].length;continue}const i=/^([A-Za-z0-9_.-]+)(\s*=)/.exec(r);if(i){t.push({text:i[1]??"",kind:"attr"}),t.push({text:i[2]??"",kind:"operator"}),n+=i[0].length;continue}const s=St(r,{trueValues:["true"],falseValues:["false"],nullValues:[]});if(s){t.push(...s.tokens),n+=s.length;continue}const d=/^(?:[,[\]{}])/.exec(r);if(d){t.push({text:d[0],kind:"operator"}),n+=d[0].length;continue}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function Jn(e){const t=[];let n=0;for(;n<e.length;){const r=e.slice(n),o=r.trimStart();if(o.startsWith(";")||o.startsWith("#")){t.push({text:r,kind:"comment"});break}const i=/^(\[[^\]]+\])/.exec(r);if(i){t.push({text:i[0],kind:"tag"}),n+=i[0].length;continue}const s=/^([A-Za-z0-9_.-]+)(\s*[=:])/.exec(r);if(s){t.push({text:s[1]??"",kind:"attr"}),t.push({text:s[2]??"",kind:"operator"}),n+=s[0].length;continue}const d=St(r,{trueValues:["true","yes","on"],falseValues:["false","no","off"],nullValues:["null"]});if(d){t.push(...d.tokens),n+=d.length;continue}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function Zi(e){if(e.trimStart().startsWith("#"))return[{text:e,kind:"comment"}];const n=/^(\s*)(export)(\s+)/.exec(e),r=n?n[0].length:0,o=[];n&&(o.push({text:n[1]??"",kind:"plain"}),o.push({text:n[2]??"",kind:"keyword"}),o.push({text:n[3]??"",kind:"plain"}));const i=e.slice(r),s=/^([A-Za-z_][A-Za-z0-9_]*)(=)/.exec(i);if(!s)return Jn(e);o.push({text:s[1]??"",kind:"attr"}),o.push({text:s[2]??"",kind:"operator"});const d=i.slice(s[0].length),g=St(d,{trueValues:["true"],falseValues:["false"],nullValues:["null"]});return g?(o.push(...g.tokens),o):(o.push({text:d,kind:"plain"}),o)}function Qi(e){return Xt(e,{commentPrefixes:["#","!"],allowSection:!1,delimiters:["=",":"]})}function ea(e){return Xt(e,{commentPrefixes:["#",";"],allowSection:!0,delimiters:["=",":"]})}function ta(e){return Xt(e,{commentPrefixes:["#",";"],allowSection:!0,delimiters:["="]})}function na(e){return et(e,mi,"#")}function ra(e){const t=e.trimStart();if(!t)return[];if(t.startsWith("#"))return[{text:e,kind:"comment"}];if(t.startsWith("!")){const n=e.length-t.length,r=e.slice(0,n),o=t.slice(1);return[{text:r,kind:"plain"},{text:"!",kind:"operator"},{text:o,kind:"string"}]}return[{text:e,kind:"string"}]}function oa(e){const t=[];let n=0;for(;n<e.length;){const r=e.slice(n);if(r.startsWith("#")){t.push({text:r,kind:"comment"});break}const o=/^(?:\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:[.,]\d{3,6})?(?:Z|[+-]\d{2}:\d{2})?)/.exec(r);if(o){t.push({text:o[0],kind:"tag"}),n+=o[0].length;continue}const i=/^(?:\[(TRACE|DEBUG|INFO|WARN|WARNING|ERROR|FATAL)\])/.exec(r);if(i){t.push({text:r.slice(0,i[0].length),kind:"keyword"}),n+=i[0].length;continue}const s=/^[A-Za-z_][\w-]*/.exec(r);if(s){const g=s[0];gi.has(g.toLowerCase())?t.push({text:g,kind:"keyword"}):t.push({text:g,kind:"plain"}),n+=g.length;continue}const d=/^(?:\d+(?:\.\d+)?)/.exec(r);if(d){t.push({text:d[0],kind:"number"}),n+=d[0].length;continue}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function Xt(e,t){const n=e.trimStart();if(t.commentPrefixes.some(g=>n.startsWith(g)))return[{text:e,kind:"comment"}];if(t.allowSection){const g=/^(\[[^\]]+\])/.exec(e);if(g)return[{text:g[0],kind:"tag"}]}const r=/^([A-Za-z0-9_.\-*?]+)(\s*(?:=|:))/.exec(e);if(!r)return[{text:e,kind:"plain"}];const o=(r[2]??"").trim();if(!t.delimiters.includes(o))return[{text:e,kind:"plain"}];const i=[{text:r[1]??"",kind:"attr"},{text:r[2]??"",kind:"operator"}],s=e.slice(r[0].length),d=ia(s);return d.length&&i.push(...d),i}function ia(e){if(!e)return[];const t=[];let n=0;for(;n<e.length;){const r=e.slice(n),o=St(r,{trueValues:["true","yes","on"],falseValues:["false","no","off"],nullValues:["null"]});if(o){t.push(...o.tokens),n+=o.length;continue}if(r.startsWith("#")||r.startsWith(";")){t.push({text:r,kind:"comment"});break}t.push({text:r[0]??"",kind:"plain"}),n+=1}return t}function St(e,t){const n=/^(?:'[^']*'|"[^"]*")/.exec(e);if(n)return{tokens:[{text:n[0],kind:"string"}],length:n[0].length};const r=/^(?:-?\d+(?:\.\d+)?)/.exec(e);if(r)return{tokens:[{text:r[0],kind:"number"}],length:r[0].length};const o=/^[A-Za-z0-9_.:+/-]+/.exec(e);if(!o)return null;const i=o[0],s=i.toLowerCase();return t.trueValues.includes(s)?{tokens:[{text:i,kind:"boolean"}],length:i.length}:t.falseValues.includes(s)?{tokens:[{text:i,kind:"boolean"}],length:i.length}:t.nullValues.includes(s)?{tokens:[{text:i,kind:"null"}],length:i.length}:{tokens:[{text:i,kind:"plain"}],length:i.length}}function Gt(e){var r,o;if(!e)return"plain";const t=((r=e.split(/[\\/]/).pop())==null?void 0:r.toLowerCase())??"";if(t===".env"||t.startsWith(".env."))return"env";if(t===".editorconfig")return"editorconfig";if(t==="dockerfile"||t.endsWith(".dockerfile"))return"dockerfile";if(t===".gitignore")return"gitignore";switch(((o=e.split(".").pop())==null?void 0:o.toLowerCase())??""){case"md":case"markdown":return"markdown";case"ts":case"tsx":return"typescript";case"js":case"jsx":case"mjs":case"cjs":return"javascript";case"json":return"json";case"log":return"log";case"properties":return"properties";case"toml":return"toml";case"ini":return"ini";case"conf":return"conf";case"dockerfile":return"dockerfile";case"css":case"scss":case"less":return"css";case"html":case"htm":return"html";case"xml":case"svg":return"xml";case"py":return"python";case"sh":case"bash":case"zsh":return"shell";case"sql":return"sql";case"yml":case"yaml":return"yaml";case"rs":return"rust";case"go":return"go";case"java":return"java";case"c":case"h":case"cpp":case"cc":case"hpp":return"cpp";default:return"plain"}}function Jt(e){const t=e.toLowerCase();switch(t){case"ts":case"tsx":case"typescript":return"typescript";case"js":case"jsx":case"javascript":return"javascript";case"bash":case"shell":case"sh":case"zsh":return"shell";case"md":case"markdown":return"markdown";case"properties":return"properties";case"toml":return"toml";case"ini":return"ini";case"env":return"env";case"conf":return"conf";case"editorconfig":return"editorconfig";case"dockerfile":return"dockerfile";case"gitignore":return"gitignore";case"log":return"log";default:return t}}function Zn(e){switch(Jt(e)){case"typescript":return"TypeScript";case"javascript":return"JavaScript";case"markdown":return"Markdown";case"json":return"JSON";case"properties":return"Properties";case"toml":return"TOML";case"ini":return"INI";case"env":return"ENV";case"conf":return"CONF";case"editorconfig":return"EditorConfig";case"dockerfile":return"Dockerfile";case"gitignore":return"GitIgnore";case"log":return"Log";case"css":return"CSS";case"html":return"HTML";case"xml":return"XML";case"python":return"Python";case"shell":return"Shell";case"sql":return"SQL";case"yaml":return"YAML";case"rust":return"Rust";case"go":return"Go";case"java":return"Java";case"cpp":return"C/C++";default:return p("conversation.fileViewerPlainText")}}function aa(e){return Gt(e)==="markdown"}function sa(e){return Gt(e)==="html"}function la(){return a.jsxs("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:[a.jsx("path",{d:"M5 2.5h7.5v9H5z",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),a.jsx("path",{d:"M3.5 5H2.4V13.5H10V12.4",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]})}function ht(e,t){return e instanceof Ot?e.message:t}async function ca(e){const t=Date.now();for(;Date.now()-t<6e4;){const n=await Er(e);if(n.status==="queued"||n.status==="running"){await da(800);continue}return n}throw new Ot(408,{detail:p("conversation.fileViewerExportTaskTimeout"),error_code:"PRESENTATION_EXPORT_TIMEOUT"})}function da(e){return new Promise(t=>{window.setTimeout(t,e)})}function ua(e){const t=[],n=e.replace(/\r\n/g,`
589
- `).split(`
590
- `);let r=0,o=0;for(const i of n){if(i.startsWith("diff --git")||i.startsWith("index ")||i.startsWith("--- ")||i.startsWith("+++ ")){t.push({kind:"meta",text:i,oldLineNo:null,newLineNo:null});continue}const s=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(i);if(s){r=parseInt(s[1],10),o=parseInt(s[2],10),t.push({kind:"hunk",text:i,oldLineNo:null,newLineNo:null});continue}if(i.startsWith(" ")||i===""){t.push({kind:"context",text:i.slice(1),oldLineNo:r,newLineNo:o}),r++,o++;continue}if(i.startsWith("+")){t.push({kind:"add",text:i.slice(1),oldLineNo:null,newLineNo:o}),o++;continue}if(i.startsWith("-")){t.push({kind:"remove",text:i.slice(1),oldLineNo:r,newLineNo:null}),r++;continue}t.push({kind:"meta",text:i,oldLineNo:null,newLineNo:null})}return t}function fa(e){if(!(e!=null&&e.trim()))return[];const t=ua(e),n=[];let r=0,o=[];function i(){if(o.length===0){r=0;return}const s=r>0?"modify":"add";pa(n,o,s),r=0,o=[]}for(const s of t){if(s.kind==="remove"){r+=1;continue}if(s.kind==="add"){s.newLineNo!==null&&o.push(s.newLineNo);continue}i()}return i(),n}function ha(e,t){const n=e?e.split(/\r?\n/).length:1,r=t.reduce((o,i)=>Math.max(o,i.line+i.span-1),0);return Math.max(n,r,1)}function pa(e,t,n){const r=t.filter(s=>s>0);if(r.length===0)return;let o=r[0]??1,i=o;for(let s=1;s<r.length;s+=1){const d=r[s]??i;if(d===i+1){i=d;continue}e.push({line:o,span:i-o+1,kind:n}),o=d,i=d}e.push({line:o,span:i-o+1,kind:n})}function Qn({markers:e,totalLines:t,scrollContainerRef:n,hideWithoutMarkers:r=!1}){const o=y.useRef(null),i=!r||e.length>0;if(y.useEffect(()=>{const d=n.current,g=o.current;if(!d||!g||!i)return;const x=d,f=g;let w=null;function E(){w=null;const{clientHeight:m,scrollHeight:u,scrollTop:P}=x;if(u<=0||m<=0||u<=m){f.style.display="none";return}const k=m/u,L=Math.min(100,Math.max(12,k*100)),j=u-m,$=Math.max(0,100-L),G=j<=0?0:P/j*$;f.style.display="block",f.style.top=`${G}%`,f.style.height=`${L}%`}function N(){w===null&&(w=window.requestAnimationFrame(E))}return E(),x.addEventListener("scroll",N,{passive:!0}),window.addEventListener("resize",N),()=>{w!==null&&window.cancelAnimationFrame(w),x.removeEventListener("scroll",N),window.removeEventListener("resize",N)}},[n,i]),r&&e.length===0)return null;const s=Math.max(t,1);return a.jsxs("div",{className:"file-overview-ruler","data-testid":"file-overview-ruler","aria-hidden":"true",children:[e.map(d=>{const g=(d.line-1)/s*100,x=Math.max(2,d.span/s*100);return a.jsx("div",{className:`file-overview-marker is-${d.kind}`,"data-kind":d.kind,style:{top:`${g}%`,height:`${x}%`}},`${d.kind}-${d.line}-${d.span}`)}),i?a.jsx("div",{ref:o,className:"file-overview-viewport"}):null]})}function ma(e,t){if(typeof document>"u")throw new Error(p("conversation.filePanelDownloadFailed"));const n=window.URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.download=e,document.body.append(r),r.click(),r.remove(),window.URL.revokeObjectURL(n)}function Na(e){const t=e.toLowerCase();if(t===".env"||t.startsWith(".env."))return"ENV";if(t.endsWith(".d.ts"))return"DTS";switch(t.includes(".")?t.slice(t.lastIndexOf(".")+1):""){case"ts":return"TS";case"tsx":return"TSX";case"js":return"JS";case"jsx":return"JSX";case"json":return"{}";case"md":return"MD";case"css":return"CSS";case"scss":return"SASS";case"html":return"HTML";case"yml":case"yaml":return"YAML";case"png":case"jpg":case"jpeg":case"gif":case"svg":case"webp":return"IMG";case"txt":return"TXT";default:return"FILE"}}function Sa(e){const t=e.toLowerCase();return t===".env"||t.startsWith(".env.")?"env":t.endsWith(".md")?"md":t.endsWith(".css")||t.endsWith(".scss")?"style":t.endsWith(".png")||t.endsWith(".jpg")||t.endsWith(".jpeg")||t.endsWith(".gif")||t.endsWith(".svg")||t.endsWith(".webp")?"image":t.endsWith(".ts")||t.endsWith(".tsx")||t.endsWith(".js")||t.endsWith(".jsx")?"code":t.endsWith(".json")||t.endsWith(".yml")||t.endsWith(".yaml")?"data":"default"}export{xi as F,Sa as a,ba as b,Na as r};