@8wave/ai-elements 0.123.0-beta.15 → 0.123.0-beta.16

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 (149) hide show
  1. package/dist/_chunks/{PkChatbotFilePreview-Dgikkf9Y.js → PkChatbotFilePreview-Dk748hZ0.js} +2 -2
  2. package/dist/_chunks/{PkChatbotFilePreview-Dgikkf9Y.js.map → PkChatbotFilePreview-Dk748hZ0.js.map} +1 -1
  3. package/dist/_chunks/{PkFilePreview-CG9peejh.js → PkFilePreview-Bcdfci6i.js} +2 -2
  4. package/dist/_chunks/{PkFilePreview-CG9peejh.js.map → PkFilePreview-Bcdfci6i.js.map} +1 -1
  5. package/dist/_chunks/{PkFilePreviewDialog-jzUvrw9R.js → PkFilePreviewDialog-nibxELSF.js} +2 -2
  6. package/dist/_chunks/{PkFilePreviewDialog-jzUvrw9R.js.map → PkFilePreviewDialog-nibxELSF.js.map} +1 -1
  7. package/dist/_chunks/{PkStreamingMarkdown-DI1AjsVC.js → PkStreamingMarkdown-C6cFkf82.js} +4 -4
  8. package/dist/_chunks/{PkStreamingMarkdown-DI1AjsVC.js.map → PkStreamingMarkdown-C6cFkf82.js.map} +1 -1
  9. package/dist/_chunks/{PkToolChatFile-BKX_7nJp.js → PkToolChatFile-5t_1vL81.js} +3 -3
  10. package/dist/_chunks/{PkToolChatFile-BKX_7nJp.js.map → PkToolChatFile-5t_1vL81.js.map} +1 -1
  11. package/dist/_chunks/{PkToolRequestOAuthConnection-BYXzi6XB.js → PkToolRequestOAuthConnection-ST3-OlS4.js} +2 -2
  12. package/dist/_chunks/{PkToolRequestOAuthConnection-BYXzi6XB.js.map → PkToolRequestOAuthConnection-ST3-OlS4.js.map} +1 -1
  13. package/dist/_chunks/{PkToolShareDocument-D2uV6p8t.js → PkToolShareDocument-1zhZDa0R.js} +2 -2
  14. package/dist/_chunks/{PkToolShareDocument-D2uV6p8t.js.map → PkToolShareDocument-1zhZDa0R.js.map} +1 -1
  15. package/dist/_chunks/{PkToolShowArtifact-CyKWxAff.js → PkToolShowArtifact-DV78g_yD.js} +2 -2
  16. package/dist/_chunks/{PkToolShowArtifact-CyKWxAff.js.map → PkToolShowArtifact-DV78g_yD.js.map} +1 -1
  17. package/dist/_chunks/{PkToolShowCalendarEvent-BF2aXrwP.js → PkToolShowCalendarEvent-Dvp1SwBY.js} +2 -2
  18. package/dist/_chunks/{PkToolShowCalendarEvent-BF2aXrwP.js.map → PkToolShowCalendarEvent-Dvp1SwBY.js.map} +1 -1
  19. package/dist/_chunks/{PkToolShowContactForm-C-U785n6.js → PkToolShowContactForm-Bnjy0g50.js} +4 -4
  20. package/dist/_chunks/{PkToolShowContactForm-C-U785n6.js.map → PkToolShowContactForm-Bnjy0g50.js.map} +1 -1
  21. package/dist/_chunks/{PkToolShowDiagram-Bs5Ri9df.js → PkToolShowDiagram-C1Q5jhbk.js} +3 -3
  22. package/dist/_chunks/{PkToolShowDiagram-Bs5Ri9df.js.map → PkToolShowDiagram-C1Q5jhbk.js.map} +1 -1
  23. package/dist/_chunks/{PkToolShowForm-CN5jvQqQ.js → PkToolShowForm-CT5_ln9b.js} +3 -3
  24. package/dist/_chunks/{PkToolShowForm-CN5jvQqQ.js.map → PkToolShowForm-CT5_ln9b.js.map} +1 -1
  25. package/dist/_chunks/{PkToolShowImageGallery-BtgWr1lk.js → PkToolShowImageGallery-BMP-xuYr.js} +4 -4
  26. package/dist/_chunks/{PkToolShowImageGallery-BtgWr1lk.js.map → PkToolShowImageGallery-BMP-xuYr.js.map} +1 -1
  27. package/dist/_chunks/{PkToolShowLocation-COmQJbXp.js → PkToolShowLocation-Drq1nnwN.js} +2 -2
  28. package/dist/_chunks/{PkToolShowLocation-COmQJbXp.js.map → PkToolShowLocation-Drq1nnwN.js.map} +1 -1
  29. package/dist/_chunks/{PkToolShowProductList-CRy6jNPa.js → PkToolShowProductList-AkLG4dBV.js} +2 -2
  30. package/dist/_chunks/{PkToolShowProductList-CRy6jNPa.js.map → PkToolShowProductList-AkLG4dBV.js.map} +1 -1
  31. package/dist/_chunks/{PkToolShowSources-CQweChKW.js → PkToolShowSources-DhZ5I_J-.js} +3 -3
  32. package/dist/_chunks/{PkToolShowSources-CQweChKW.js.map → PkToolShowSources-DhZ5I_J-.js.map} +1 -1
  33. package/dist/_chunks/{PkToolShowVideo-C8dP8I-g.js → PkToolShowVideo-C5jqPYXw.js} +3 -3
  34. package/dist/_chunks/{PkToolShowVideo-C8dP8I-g.js.map → PkToolShowVideo-C5jqPYXw.js.map} +1 -1
  35. package/dist/_chunks/{PkToolShowWeather-sx72yMH6.js → PkToolShowWeather-7_f5k1pX.js} +2 -2
  36. package/dist/_chunks/{PkToolShowWeather-sx72yMH6.js.map → PkToolShowWeather-7_f5k1pX.js.map} +1 -1
  37. package/dist/_chunks/{PkToolShowWebPages-fXkqV27c.js → PkToolShowWebPages-BqL9PjpM.js} +3 -3
  38. package/dist/_chunks/{PkToolShowWebPages-fXkqV27c.js.map → PkToolShowWebPages-BqL9PjpM.js.map} +1 -1
  39. package/dist/_chunks/{browser-CwAulEhA.js → browser-DnbodHv5.js} +32 -18
  40. package/dist/_chunks/browser-DnbodHv5.js.map +1 -0
  41. package/dist/_chunks/{chatImagePolicy-B183jp31.js → chatImagePolicy-ZiVuD6nX.js} +2 -2
  42. package/dist/_chunks/{chatImagePolicy-B183jp31.js.map → chatImagePolicy-ZiVuD6nX.js.map} +1 -1
  43. package/dist/_chunks/{index.es-DYy-Q9hZ.js → index.es-DRbDRAW5.js} +2 -2
  44. package/dist/_chunks/{index.es-DYy-Q9hZ.js.map → index.es-DRbDRAW5.js.map} +1 -1
  45. package/dist/_chunks/src-JJyCGvqH.js +183 -0
  46. package/dist/_chunks/src-JJyCGvqH.js.map +1 -0
  47. package/dist/_chunks/{useLightbox-B575Qxeu.js → useLightbox-BigL4WLe.js} +2 -2
  48. package/dist/_chunks/{useLightbox-B575Qxeu.js.map → useLightbox-BigL4WLe.js.map} +1 -1
  49. package/dist/_chunks/{utils-COV6n6VV.js → utils-B5VcWm3g.js} +2 -2
  50. package/dist/_chunks/{utils-COV6n6VV.js.map → utils-B5VcWm3g.js.map} +1 -1
  51. package/dist/ai-elements.es.js +23 -23
  52. package/dist-vue/PkChatbot.js +1 -1
  53. package/dist-vue/PkChatbotAudioTranscript.js +1 -1
  54. package/dist-vue/PkChatbotEmptyState.js +1 -1
  55. package/dist-vue/PkChatbotFilePreview.js +1 -1
  56. package/dist-vue/PkChatbotInput.js +1 -1
  57. package/dist-vue/PkChatbotMessages.js +1 -1
  58. package/dist-vue/PkChatbotStepPayload.js +1 -1
  59. package/dist-vue/PkChatbotStepToolDetail.js +1 -1
  60. package/dist-vue/PkChatbotSteps.js +1 -1
  61. package/dist-vue/PkChatbotViewChat.js +1 -1
  62. package/dist-vue/PkChatbotViewConversations.js +1 -1
  63. package/dist-vue/PkChatbotViewFiles.js +1 -1
  64. package/dist-vue/PkChatbotViewProfile.js +1 -1
  65. package/dist-vue/_chunks/{PkChatbot-DGut25cv.js → PkChatbot-tq-fJUij.js} +8 -8
  66. package/dist-vue/_chunks/{PkChatbot-DGut25cv.js.map → PkChatbot-tq-fJUij.js.map} +1 -1
  67. package/dist-vue/_chunks/{PkChatbotAudioTranscript-DiZ7BEEH.js → PkChatbotAudioTranscript-SSTh074Z.js} +2 -2
  68. package/dist-vue/_chunks/{PkChatbotAudioTranscript-DiZ7BEEH.js.map → PkChatbotAudioTranscript-SSTh074Z.js.map} +1 -1
  69. package/dist-vue/_chunks/{PkChatbotEmptyState-DT9Pxyjt.js → PkChatbotEmptyState-Dp0_UPJm.js} +2 -2
  70. package/dist-vue/_chunks/{PkChatbotEmptyState-DT9Pxyjt.js.map → PkChatbotEmptyState-Dp0_UPJm.js.map} +1 -1
  71. package/dist-vue/_chunks/{PkChatbotFilePreview-BiurawUn.js → PkChatbotFilePreview-KxVpL0UT.js} +2 -2
  72. package/dist-vue/_chunks/{PkChatbotFilePreview-BiurawUn.js.map → PkChatbotFilePreview-KxVpL0UT.js.map} +1 -1
  73. package/dist-vue/_chunks/{PkChatbotInput-liQNntaY.js → PkChatbotInput-B_kPnNNB.js} +3 -3
  74. package/dist-vue/_chunks/{PkChatbotInput-liQNntaY.js.map → PkChatbotInput-B_kPnNNB.js.map} +1 -1
  75. package/dist-vue/_chunks/{PkChatbotMessages-CDhi_NvV.js → PkChatbotMessages-BTZOic9V.js} +22 -22
  76. package/dist-vue/_chunks/{PkChatbotMessages-CDhi_NvV.js.map → PkChatbotMessages-BTZOic9V.js.map} +1 -1
  77. package/dist-vue/_chunks/{PkChatbotStepPayload-XMAC8eoc.js → PkChatbotStepPayload-CoGCHBhJ.js} +2 -2
  78. package/dist-vue/_chunks/{PkChatbotStepPayload-XMAC8eoc.js.map → PkChatbotStepPayload-CoGCHBhJ.js.map} +1 -1
  79. package/dist-vue/_chunks/{PkChatbotStepToolDetail-CPWnpmuB.js → PkChatbotStepToolDetail-BJtIZBF0.js} +3 -3
  80. package/dist-vue/_chunks/{PkChatbotStepToolDetail-CPWnpmuB.js.map → PkChatbotStepToolDetail-BJtIZBF0.js.map} +1 -1
  81. package/dist-vue/_chunks/{PkChatbotSteps-CyT4Ck3C.js → PkChatbotSteps-CEJNclG4.js} +5 -5
  82. package/dist-vue/_chunks/{PkChatbotSteps-CyT4Ck3C.js.map → PkChatbotSteps-CEJNclG4.js.map} +1 -1
  83. package/dist-vue/_chunks/{PkChatbotViewChat-8Ss2bt2I.js → PkChatbotViewChat-CnEOSH32.js} +8 -8
  84. package/dist-vue/_chunks/{PkChatbotViewChat-8Ss2bt2I.js.map → PkChatbotViewChat-CnEOSH32.js.map} +1 -1
  85. package/dist-vue/_chunks/{PkChatbotViewConversations-ImCdmkUi.js → PkChatbotViewConversations-D7j5P1RO.js} +4 -4
  86. package/dist-vue/_chunks/{PkChatbotViewConversations-ImCdmkUi.js.map → PkChatbotViewConversations-D7j5P1RO.js.map} +1 -1
  87. package/dist-vue/_chunks/{PkChatbotViewFiles-Ccti1JAS.js → PkChatbotViewFiles-B1mncBOo.js} +2 -2
  88. package/dist-vue/_chunks/{PkChatbotViewFiles-Ccti1JAS.js.map → PkChatbotViewFiles-B1mncBOo.js.map} +1 -1
  89. package/dist-vue/_chunks/{PkChatbotViewProfile-ChEItAHZ.js → PkChatbotViewProfile--TWIrhYk.js} +2 -2
  90. package/dist-vue/_chunks/{PkChatbotViewProfile-ChEItAHZ.js.map → PkChatbotViewProfile--TWIrhYk.js.map} +1 -1
  91. package/dist-vue/_chunks/{PkFilePreview-CfzGAziV.js → PkFilePreview-BKwnNsyV.js} +2 -2
  92. package/dist-vue/_chunks/{PkFilePreview-CfzGAziV.js.map → PkFilePreview-BKwnNsyV.js.map} +1 -1
  93. package/dist-vue/_chunks/{PkFilePreviewDialog-DXIGcmYa.js → PkFilePreviewDialog-Cic7gmVR.js} +2 -2
  94. package/dist-vue/_chunks/{PkFilePreviewDialog-DXIGcmYa.js.map → PkFilePreviewDialog-Cic7gmVR.js.map} +1 -1
  95. package/dist-vue/_chunks/{PkStreamingMarkdown-BTcd7ku7.js → PkStreamingMarkdown-CYlCIfA0.js} +3 -3
  96. package/dist-vue/_chunks/{PkStreamingMarkdown-BTcd7ku7.js.map → PkStreamingMarkdown-CYlCIfA0.js.map} +1 -1
  97. package/dist-vue/_chunks/{PkSvgViewer-CvKzI689.js → PkSvgViewer-DBYr0CUi.js} +2 -2
  98. package/dist-vue/_chunks/{PkSvgViewer-CvKzI689.js.map → PkSvgViewer-DBYr0CUi.js.map} +1 -1
  99. package/dist-vue/_chunks/{PkToolChatFile-DHZjc9cf.js → PkToolChatFile-B_PeJef8.js} +3 -3
  100. package/dist-vue/_chunks/{PkToolChatFile-DHZjc9cf.js.map → PkToolChatFile-B_PeJef8.js.map} +1 -1
  101. package/dist-vue/_chunks/{PkToolRequestOAuthConnection-Dy0GXNwC.js → PkToolRequestOAuthConnection-C9_w8V0T.js} +2 -2
  102. package/dist-vue/_chunks/{PkToolRequestOAuthConnection-Dy0GXNwC.js.map → PkToolRequestOAuthConnection-C9_w8V0T.js.map} +1 -1
  103. package/dist-vue/_chunks/{PkToolShareDocument-DHrzH95L.js → PkToolShareDocument-CsS5OTDj.js} +2 -2
  104. package/dist-vue/_chunks/{PkToolShareDocument-DHrzH95L.js.map → PkToolShareDocument-CsS5OTDj.js.map} +1 -1
  105. package/dist-vue/_chunks/{PkToolShowArtifact-BDfqYsCD.js → PkToolShowArtifact-Bh-jIo0V.js} +2 -2
  106. package/dist-vue/_chunks/{PkToolShowArtifact-BDfqYsCD.js.map → PkToolShowArtifact-Bh-jIo0V.js.map} +1 -1
  107. package/dist-vue/_chunks/{PkToolShowCalendarEvent-75TaGeMf.js → PkToolShowCalendarEvent-BsAOYLjp.js} +2 -2
  108. package/dist-vue/_chunks/{PkToolShowCalendarEvent-75TaGeMf.js.map → PkToolShowCalendarEvent-BsAOYLjp.js.map} +1 -1
  109. package/dist-vue/_chunks/{PkToolShowContactForm-4f3q-cfC.js → PkToolShowContactForm-BjfRuNuj.js} +4 -4
  110. package/dist-vue/_chunks/{PkToolShowContactForm-4f3q-cfC.js.map → PkToolShowContactForm-BjfRuNuj.js.map} +1 -1
  111. package/dist-vue/_chunks/{PkToolShowDiagram-CwowbfOT.js → PkToolShowDiagram-_NnrFDGT.js} +4 -4
  112. package/dist-vue/_chunks/{PkToolShowDiagram-CwowbfOT.js.map → PkToolShowDiagram-_NnrFDGT.js.map} +1 -1
  113. package/dist-vue/_chunks/{PkToolShowForm-xFFBo17s.js → PkToolShowForm-AqEY4_do.js} +3 -3
  114. package/dist-vue/_chunks/{PkToolShowForm-xFFBo17s.js.map → PkToolShowForm-AqEY4_do.js.map} +1 -1
  115. package/dist-vue/_chunks/{PkToolShowImageGallery-_hd3FyqC.js → PkToolShowImageGallery-DM5AJNZ3.js} +4 -4
  116. package/dist-vue/_chunks/{PkToolShowImageGallery-_hd3FyqC.js.map → PkToolShowImageGallery-DM5AJNZ3.js.map} +1 -1
  117. package/dist-vue/_chunks/{PkToolShowLocation-C7hBRwq8.js → PkToolShowLocation-DAQEuCuQ.js} +2 -2
  118. package/dist-vue/_chunks/{PkToolShowLocation-C7hBRwq8.js.map → PkToolShowLocation-DAQEuCuQ.js.map} +1 -1
  119. package/dist-vue/_chunks/{PkToolShowProductList-BPSYoZVU.js → PkToolShowProductList-CAV8be9a.js} +2 -2
  120. package/dist-vue/_chunks/{PkToolShowProductList-BPSYoZVU.js.map → PkToolShowProductList-CAV8be9a.js.map} +1 -1
  121. package/dist-vue/_chunks/{PkToolShowSources-CzFNTuWy.js → PkToolShowSources-CriswKr_.js} +3 -3
  122. package/dist-vue/_chunks/{PkToolShowSources-CzFNTuWy.js.map → PkToolShowSources-CriswKr_.js.map} +1 -1
  123. package/dist-vue/_chunks/{PkToolShowVideo-Dr7UtU-3.js → PkToolShowVideo-FSWM5MOl.js} +3 -3
  124. package/dist-vue/_chunks/{PkToolShowVideo-Dr7UtU-3.js.map → PkToolShowVideo-FSWM5MOl.js.map} +1 -1
  125. package/dist-vue/_chunks/{PkToolShowWeather-Z6vCrhh9.js → PkToolShowWeather-BC-Rx-sI.js} +2 -2
  126. package/dist-vue/_chunks/{PkToolShowWeather-Z6vCrhh9.js.map → PkToolShowWeather-BC-Rx-sI.js.map} +1 -1
  127. package/dist-vue/_chunks/{PkToolShowWebPages-CAeOJ5xx.js → PkToolShowWebPages-CPhm2ba3.js} +3 -3
  128. package/dist-vue/_chunks/{PkToolShowWebPages-CAeOJ5xx.js.map → PkToolShowWebPages-CPhm2ba3.js.map} +1 -1
  129. package/dist-vue/_chunks/{createChatbotApiClient-CuqGJGHD.js → createChatbotApiClient-CFKeOgEA.js} +2 -2
  130. package/dist-vue/_chunks/{createChatbotApiClient-CuqGJGHD.js.map → createChatbotApiClient-CFKeOgEA.js.map} +1 -1
  131. package/dist-vue/_chunks/{mcpOAuthReport-BdegDfcz.js → mcpOAuthReport-D-MtFYwN.js} +2 -2
  132. package/dist-vue/_chunks/{mcpOAuthReport-BdegDfcz.js.map → mcpOAuthReport-D-MtFYwN.js.map} +1 -1
  133. package/dist-vue/_chunks/src-nb8MU1sh.js +183 -0
  134. package/dist-vue/_chunks/src-nb8MU1sh.js.map +1 -0
  135. package/dist-vue/_chunks/{useChatbotStore-C1lW6qXE.js → useChatbotStore--6ws3cew.js} +4 -4
  136. package/dist-vue/_chunks/{useChatbotStore-C1lW6qXE.js.map → useChatbotStore--6ws3cew.js.map} +1 -1
  137. package/dist-vue/_chunks/{useSafeLocalStorage-DImmddot.js → useSafeLocalStorage-Bn4SsL8C.js} +2 -2
  138. package/dist-vue/_chunks/{useSafeLocalStorage-DImmddot.js.map → useSafeLocalStorage-Bn4SsL8C.js.map} +1 -1
  139. package/dist-vue/_chunks/{utils-D9BAduwQ.js → utils-BgvjC1Pu.js} +2 -2
  140. package/dist-vue/_chunks/{utils-D9BAduwQ.js.map → utils-BgvjC1Pu.js.map} +1 -1
  141. package/dist-vue/api.js +1 -1
  142. package/dist-vue/composables.js +4 -4
  143. package/dist-vue/index.js +31 -31
  144. package/package.json +1 -1
  145. package/dist/_chunks/browser-CwAulEhA.js.map +0 -1
  146. package/dist/_chunks/src-Bg96usAF.js +0 -132
  147. package/dist/_chunks/src-Bg96usAF.js.map +0 -1
  148. package/dist-vue/_chunks/src-j7iLdNe4.js +0 -132
  149. package/dist-vue/_chunks/src-j7iLdNe4.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"PkFilePreview-CG9peejh.js","names":["_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","_hoisted_17","_hoisted_18","_useModel","__unplugin_components_0","_openBlock","_createElementBlock","_createElementVNode","_unref","_toDisplayString","_normalizeClass","_normalizeStyle","_Fragment","_renderList","_isMemoSame","_withModifiers","_createCommentVNode","_createTextVNode","_createVNode","_sfc_main","_style_0","_hoisted_1","_hoisted_2","_hoisted_3","_openBlock","_createElementBlock","_Fragment","_renderList","_toDisplayString","_unref","_normalizeStyle","_sfc_main","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_openBlock","_createElementBlock","_normalizeClass","_Fragment","_renderList","_normalizeStyle","_createCommentVNode","_createElementVNode","_createVNode","PkWordPreviewRuns","_toDisplayString","_sfc_main","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","_useModel","__unplugin_components_0","_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_toDisplayString","_createCommentVNode","_Fragment","_renderList","_normalizeStyle","_createBlock","PkWordPreviewBlock","_createVNode","_sfc_main","_style_0","_useModel","__unplugin_components_0","__unplugin_components_1","_openBlock","_createElementBlock","_createElementVNode","_createVNode","_normalizeClass","_toDisplayString","_unref","_createCommentVNode","_createBlock","PkEditorRadioButtons","_withCtx","_Fragment","_renderList","PkWordPreview","PkSpreadsheetPreview","_sfc_main","_style_0","__exportAll","normalizeClass","nextTick","onBeforeUnmount","useModel","onMounted","mergeModels","normalizeStyle","watch","createVNode","init_shared_esm_bundler","renderList","useTemplateRef","createBlock","withModifiers","Fragment","ref","computed","isMemoSame","init_runtime_core_esm_bundler","toDisplayString","init_reactivity_esm_bundler","init_runtime_dom_esm_bundler","withCtx","createCommentVNode","defineComponent","unref","createTextVNode","createElementBlock","openBlock","useI18n","wordLineFactor","wordFontStack","useElementSize","Ce","VvButtonLocalized","_plugin_vue_export_helper_default","PkEditorRadioButtons_default","_hoisted_1$4","_hoisted_2$4","_hoisted_3$4","_hoisted_4$3","_hoisted_5$2","_hoisted_6$2","_hoisted_7$2","_hoisted_8$2","_hoisted_9$2","_hoisted_10$2","_hoisted_11$2","_hoisted_12$2","_hoisted_13$2","_hoisted_14$2","_hoisted_15$2","_hoisted_16$2","_hoisted_17$1","_hoisted_18$1","COLUMN_WIDTH","ROW_HEIGHT","HEAD_HEIGHT","ROW_HEAD_WIDTH","PkSpreadsheetPreview_default","\"sheet\"","\"sheetModifiers\"","\"zoom\"","\"zoomModifiers\"","props","__props","$t","active","zoom","scrollEl","viewWidth","viewHeight","sheet","letters","s","c","n","columns","hidden","widths","out","used","room","col","width","gridWidth","columnsKey","rowObjects","rows","heights","r","fill","last","known","seen","i","row","cells","map","covered","dr","dc","cellAt","shownSpan","span","styleOf","cell","numberText","digits","locale","v","dateText","date","textOf","barText","border","side","cellCss","numeric","css","lines","pad","frozenCss","f","anchor","focus","range","inRange","isFocus","rowSelection","dragging","pick","event","extend","move","step","rowList","colList","ownerOf","at","start","next","nr","nc","focusCell","stats","r1","r2","c1","c2","count","sum","numbers","first","zoomBy","_component_VvButton","createBaseVNode","_cache","_memo","_cached","_item","$event","_hoisted_1$3","_hoisted_2$3","_hoisted_3$3","PkWordPreviewRuns_default","shown","run","marked","cssOf","changeCss","titleOf","k","_hoisted_1$2","_hoisted_2$2","_hoisted_3$2","_hoisted_4$2","PkWordPreviewBlock_default","paragraphCss","labelCss","hanging","changed","tableRow","total","a","b","w","rowChanged","_hoisted_1$1","_hoisted_2$1","_hoisted_3$1","_hoisted_4$1","_hoisted_5$1","_hoisted_6$1","_hoisted_7$1","_hoisted_8$1","_hoisted_9$1","_hoisted_10$1","_hoisted_11$1","_hoisted_12$1","_hoisted_13$1","_hoisted_14$1","_hoisted_15$1","_hoisted_16$1","_hoisted_17","_hoisted_18","_hoisted_19","_hoisted_20","_hoisted_21","_hoisted_22","_hoisted_23","_hoisted_24","PX","PkWordPreview_default","\"fit\"","\"fitModifiers\"","kept","runs","hasText","items","block","rootEl","measureEl","scrollWidth","paged","wide","page","textCss","pageCss","measureCss","measure","els","el","pages","all","h","item","fit","manual","currentPage","currentHeading","locate","box","pageEls","heading","headings","frame","onScroll","clip","changes","removed","added","tab","sideOpen","goTo","key","words","authors","p","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","PkFilePreview_vue_vue_type_script_setup_true_lang_default","\"mode\"","\"modeModifiers\"","__emit","emit","versions","position","previous","mode","modes","hasRevisions","_component_VvIcon","PkFilePreview_vue_vue_type_style_index_0_inline_lang_default","PkFilePreview_exports","PkFilePreview_default"],"sources":["../../../../packages/components/src/chat/PkSpreadsheetPreview.vue","../../../../packages/components/src/chat/PkSpreadsheetPreview.vue","../../../../packages/components/src/chat/PkSpreadsheetPreview.vue","../../../../packages/components/src/chat/PkWordPreviewRuns.vue","../../../../packages/components/src/chat/PkWordPreviewRuns.vue","../../../../packages/components/src/chat/PkWordPreviewBlock.vue","../../../../packages/components/src/chat/PkWordPreviewBlock.vue","../../../../packages/components/src/chat/PkWordPreview.vue","../../../../packages/components/src/chat/PkWordPreview.vue","../../../../packages/components/src/chat/PkWordPreview.vue","../../../../packages/components/src/chat/PkFilePreview.vue","../../../../packages/components/src/chat/PkFilePreview.vue","../../../../packages/components/src/chat/PkFilePreview.vue"],"sourcesContent":["<script setup lang=\"ts\">\n import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n import type { CSSProperties } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type {\n SpreadsheetPreview,\n SpreadsheetPreviewCell,\n SpreadsheetPreviewStyle,\n } from 'models'\n\n /**\n * A spreadsheet stored in the chat, drawn as Excel draws it (spec\n * `chat-office-files.md`, F6, item 4, and the viewer of its follow-ups):\n * column letters and row numbers that stay in view, the widths, heights,\n * fonts, fills and borders of the file, merged cells and frozen panes.\n * A cell is picked with a click, a range with a drag or shift, and the\n * arrows move it: the formula bar shows its formula, the status bar the\n * sum of a range. The sheets are tabs at the bottom. The grid keeps the\n * file's white in the dark theme, as a page does; the bars around it\n * follow the theme. Framed by `PkFilePreview`.\n */\n const props = defineProps<{ preview: SpreadsheetPreview }>()\n\n const { t: $t, locale } = useI18n({ useScope: 'global' })\n\n /** Excel's defaults, in pixels. */\n const COLUMN_WIDTH = 64\n const ROW_HEIGHT = 20\n const HEAD_HEIGHT = 28\n const ROW_HEAD_WIDTH = 44\n\n // Models, so the sheet and the zoom stay when the viewer moves between\n // the panel and the dialog (`PkChatbotViewChat` keeps them).\n const active = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const scrollEl = useTemplateRef<HTMLDivElement>('scrollEl')\n // The border box, scroll bars included: the grid that fills the view\n // makes them appear, and measured without them the view shrank, the\n // grid changed again, and the two went on in a loop.\n const { width: viewWidth, height: viewHeight } = useElementSize(\n scrollEl,\n { width: 0, height: 0 },\n { box: 'border-box' },\n )\n const sheet = computed(\n () => props.preview.sheets[active.value] ?? props.preview.sheets[0],\n )\n watch(\n () => props.preview,\n () => {\n active.value = 0\n },\n )\n\n const letters = (n: number): string => {\n let s = ''\n for (let c = n; c > 0; c = Math.floor((c - 1) / 26)) {\n s = String.fromCharCode(65 + ((c - 1) % 26)) + s\n }\n return s\n }\n\n // Empty rows and columns after the data up to the edges of the view, as\n // Excel's grid goes on, unless the file goes on past what the preview\n // holds: an empty column there would say the sheet ends.\n const columns = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(\n s.columns.filter((c) => c.hidden).map((c) => c.col),\n )\n const widths = new Map(s.columns.map((c) => [c.col, c.width]))\n const out: Array<{ col: number; width: number }> = []\n let used = ROW_HEAD_WIDTH\n const room = viewWidth.value / zoom.value\n for (\n let col = 1;\n col <= s.lastColumn ||\n (!s.moreColumns && (col <= s.lastColumn + 2 || used < room));\n col++\n ) {\n if (hidden.has(col)) {\n continue\n }\n const width = widths.get(col) ?? COLUMN_WIDTH\n out.push({ col, width })\n used += width\n }\n return out\n })\n /** A fixed layout needs the table's width, or the columns shrink. */\n const gridWidth = computed(() =>\n columns.value.reduce((n, c) => n + c.width, ROW_HEAD_WIDTH),\n )\n /** The columns as a value: the same set at another zoom, for the memo. */\n const columnsKey = computed(() =>\n columns.value.map((c) => `${c.col}:${c.width}`).join(','),\n )\n // One object per row while its sheet is shown, so a row's memo holds\n // when the view adds rows to fill itself.\n const rowObjects = new WeakMap<\n object,\n Map<number, { row: number; height: number }>\n >()\n const rows = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(s.hiddenRows ?? [])\n const heights = new Map(s.rows.map((r) => [r.row, r.height]))\n const fill = Math.ceil(\n (viewHeight.value / zoom.value - HEAD_HEIGHT) / ROW_HEIGHT,\n )\n const last = s.moreRows\n ? s.lastRow\n : Math.max(s.lastRow + 5, fill + hidden.size)\n let known = rowObjects.get(s)\n if (!known) {\n known = new Map()\n rowObjects.set(s, known)\n }\n const seen = known\n return Array.from({ length: last }, (_, i) => i + 1)\n .filter((row) => !hidden.has(row))\n .map((row) => {\n let r = seen.get(row)\n if (!r) {\n r = { row, height: heights.get(row) ?? ROW_HEIGHT }\n seen.set(row, r)\n }\n return r\n })\n })\n const cells = computed(() => {\n const map = new Map<string, SpreadsheetPreviewCell>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n map.set(`${r.row},${c.col}`, c)\n }\n }\n return map\n })\n /** The cells a merge covers, each with the first cell that draws it. */\n const covered = computed(() => {\n const map = new Map<string, { row: number; col: number }>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n if (!c.span) {\n continue\n }\n for (let dr = 0; dr < c.span.rows; dr++) {\n for (let dc = 0; dc < c.span.cols; dc++) {\n if (dr || dc) {\n map.set(`${r.row + dr},${c.col + dc}`, {\n row: r.row,\n col: c.col,\n })\n }\n }\n }\n }\n }\n return map\n })\n const cellAt = (row: number, col: number) =>\n cells.value.get(`${row},${col}`)\n /**\n * A merge's span over the rows and columns the grid draws: the file\n * counts the hidden ones too, and the merge ran into the next column.\n */\n const shownSpan = (row: number, col: number) => {\n const span = cellAt(row, col)?.span\n if (!span) {\n return undefined\n }\n return {\n rows: rows.value.filter(\n (r) => r.row >= row && r.row < row + span.rows,\n ).length,\n cols: columns.value.filter(\n (c) => c.col >= col && c.col < col + span.cols,\n ).length,\n }\n }\n const styleOf = (\n cell: SpreadsheetPreviewCell | undefined,\n ): SpreadsheetPreviewStyle | undefined =>\n cell?.style === undefined ? undefined : props.preview.styles[cell.style]\n\n // #region the text of a cell\n const numberText = (cell: SpreadsheetPreviewCell, v: number) => {\n const digits =\n cell.decimals !== undefined\n ? {\n minimumFractionDigits: cell.decimals,\n maximumFractionDigits: cell.maxDecimals ?? cell.decimals,\n }\n : { maximumFractionDigits: 10 }\n return new Intl.NumberFormat(locale.value, {\n ...digits,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n ...(cell.format === 'currency' && cell.currency\n ? { style: 'currency', currency: cell.currency }\n : {}),\n }).format(v)\n }\n\n const dateText = (v: string) => {\n const date = new Date(`${v}T00:00:00Z`)\n return Number.isNaN(date.getTime())\n ? v\n : new Intl.DateTimeFormat(locale.value, {\n dateStyle: 'short',\n timeZone: 'UTC',\n }).format(date)\n }\n\n /** The cell's text: a number in the reader's language, a date, a word. */\n const textOf = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.missing) {\n return '—'\n }\n const v = cell.value\n if (v === undefined) {\n return ''\n }\n if (typeof v === 'boolean') {\n return v ? $t('chatFilePreview.true') : $t('chatFilePreview.false')\n }\n if (cell.format === 'date' && typeof v === 'string') {\n return dateText(v)\n }\n if (typeof v === 'number') {\n return numberText(cell, v)\n }\n return v\n }\n\n /** What Excel's bar shows: the formula, or the value as typed. */\n const barText = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.formula) {\n return `=${cell.formula}`\n }\n const v = cell.value\n if (typeof v === 'number') {\n return new Intl.NumberFormat(locale.value, {\n useGrouping: false,\n maximumFractionDigits: 15,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n }).format(v)\n }\n return textOf(cell)\n }\n // #endregion\n\n // #region the look of a cell\n const border = (side?: { color: string; width: number }) =>\n side ? `${side.width}px solid ${side.color}` : undefined\n\n const cellCss = (\n cell: SpreadsheetPreviewCell | undefined,\n row: number,\n col: number,\n ): CSSProperties => {\n const s = styleOf(cell)\n const v = cell?.value\n const numeric = typeof v === 'number' || !!cell?.missing\n const css: CSSProperties = {\n textAlign:\n s?.align ??\n (numeric\n ? 'right'\n : typeof v === 'boolean' || cell?.format === 'error'\n ? 'center'\n : 'left'),\n verticalAlign:\n s?.valign === 'top'\n ? 'top'\n : s?.valign === 'middle'\n ? 'middle'\n : 'bottom',\n whiteSpace: s?.wrap ? 'pre-wrap' : 'nowrap',\n }\n if (s?.bold) {\n css.fontWeight = 700\n }\n if (s?.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n s?.underline ? 'underline' : '',\n s?.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (s?.size) {\n css.fontSize = `${s.size}pt`\n }\n if (s?.color) {\n css.color = s.color\n }\n if (s?.fill) {\n css.backgroundColor = s.fill\n }\n if (s?.indent) {\n const pad = `${4 + s.indent * 9}px`\n if (css.textAlign === 'right') {\n css.paddingRight = pad\n } else {\n css.paddingLeft = pad\n }\n }\n css.borderTop = border(s?.borders?.top)\n css.borderRight = border(s?.borders?.right)\n css.borderBottom = border(s?.borders?.bottom)\n css.borderLeft = border(s?.borders?.left)\n Object.assign(css, frozenCss(row, col))\n return css\n }\n\n /** Where a frozen row or column sticks, under the headers. */\n const frozenCss = (row: number, col: number): CSSProperties => {\n const f = sheet.value?.frozen\n if (!f) {\n return {}\n }\n const css: CSSProperties = {}\n if (row <= f.rows) {\n css.position = 'sticky'\n css.top = `${\n HEAD_HEIGHT +\n rows.value\n .filter((r) => r.row < row)\n .reduce((n, r) => n + r.height, 0)\n }px`\n css.zIndex = 2\n }\n if (col <= f.cols) {\n css.position = 'sticky'\n css.left = `${\n ROW_HEAD_WIDTH +\n columns.value\n .filter((c) => c.col < col)\n .reduce((n, c) => n + c.width, 0)\n }px`\n css.zIndex = row <= f.rows ? 3 : 2\n }\n return css\n }\n // #endregion\n\n // #region selection\n type At = { row: number; col: number }\n const anchor = ref<At>({ row: 1, col: 1 })\n const focus = ref<At>({ row: 1, col: 1 })\n watch(sheet, () => {\n anchor.value = { row: 1, col: 1 }\n focus.value = { row: 1, col: 1 }\n })\n const range = computed(() => ({\n r1: Math.min(anchor.value.row, focus.value.row),\n r2: Math.max(anchor.value.row, focus.value.row),\n c1: Math.min(anchor.value.col, focus.value.col),\n c2: Math.max(anchor.value.col, focus.value.col),\n }))\n const inRange = (row: number, col: number) =>\n row >= range.value.r1 &&\n row <= range.value.r2 &&\n col >= range.value.c1 &&\n col <= range.value.c2\n const isFocus = (row: number, col: number) =>\n focus.value.row === row && focus.value.col === col\n /**\n * What a row draws of the selection. A row is drawn again only when\n * this, its sheet, the columns or the language of the numbers change: a\n * sheet of thousands of cells drew them all at each step of a drag,\n * seconds per selection.\n */\n const rowSelection = (row: number) =>\n row >= range.value.r1 && row <= range.value.r2\n ? `${range.value.c1}:${range.value.c2}:${\n focus.value.row === row ? focus.value.col : 0\n }`\n : ''\n\n const dragging = ref(false)\n const pick = (row: number, col: number, event: MouseEvent) => {\n // The click keeps its default off (no text selection while dragging),\n // so the grid takes the keyboard here.\n scrollEl.value?.focus({ preventScroll: true })\n focus.value = { row, col }\n if (!event.shiftKey) {\n anchor.value = { row, col }\n }\n dragging.value = true\n }\n const extend = (row: number, col: number) => {\n if (dragging.value) {\n focus.value = { row, col }\n }\n }\n\n const move = (event: KeyboardEvent) => {\n const steps: Record<string, [number, number]> = {\n ArrowUp: [-1, 0],\n ArrowDown: [1, 0],\n ArrowLeft: [0, -1],\n ArrowRight: [0, 1],\n Enter: [1, 0],\n Tab: [0, 1],\n }\n const step = steps[event.key]\n if (!step) {\n return\n }\n event.preventDefault()\n const rowList = rows.value.map((r) => r.row)\n const colList = columns.value.map((c) => c.col)\n const ownerOf = (at: At) =>\n covered.value.get(`${at.row},${at.col}`) ?? at\n // As in Excel, a merge is one cell: the step goes past the cells it\n // covers, and a step into one lands on the cell that draws it.\n const start = ownerOf(focus.value)\n let r = rowList.indexOf(focus.value.row)\n let c = colList.indexOf(focus.value.col)\n let next = start\n for (;;) {\n const nr = Math.min(rowList.length - 1, Math.max(0, r + step[0]))\n const nc = Math.min(colList.length - 1, Math.max(0, c + step[1]))\n if (nr === r && nc === c) {\n break\n }\n r = nr\n c = nc\n next = ownerOf({ row: rowList[r], col: colList[c] })\n if (next.row !== start.row || next.col !== start.col) {\n break\n }\n }\n focus.value = next\n if (!event.shiftKey) {\n anchor.value = next\n }\n nextTick(() =>\n scrollEl.value\n ?.querySelector('[data-focus]')\n ?.scrollIntoView({ block: 'nearest', inline: 'nearest' }),\n )\n }\n\n const focusCell = computed(() => cellAt(focus.value.row, focus.value.col))\n /** Count, average and sum of a range, as Excel's status bar shows them. */\n const stats = computed(() => {\n const { r1, r2, c1, c2 } = range.value\n if (r1 === r2 && c1 === c2) {\n return undefined\n }\n let count = 0\n let sum = 0\n let numbers = 0\n let first: SpreadsheetPreviewCell | undefined\n for (let r = r1; r <= r2; r++) {\n for (let c = c1; c <= c2; c++) {\n const cell = cellAt(r, c)\n if (!cell || (cell.value === undefined && !cell.missing)) {\n continue\n }\n count++\n if (typeof cell.value === 'number') {\n sum += cell.value\n numbers++\n first ??= cell\n }\n }\n }\n if (!count) {\n return undefined\n }\n return {\n count,\n sum: first ? numberText(first, sum) : undefined,\n // One number among text is still an average, as in Excel\n average: first ? numberText(first, sum / numbers) : undefined,\n }\n })\n // #endregion\n\n // #region zoom\n const zoomBy = (step: number) => {\n zoom.value = Math.min(\n 2,\n Math.max(0.5, Math.round((zoom.value + step) * 10) / 10),\n )\n }\n // #endregion\n</script>\n\n<template>\n <div class=\"pk-spreadsheet-preview\">\n <div class=\"pk-spreadsheet-preview__bar\">\n <span\n class=\"pk-spreadsheet-preview__ref\"\n :aria-label=\"$t('chatFilePreview.cell')\">\n {{ letters(focus.col) }}{{ focus.row }}\n </span>\n <span class=\"pk-spreadsheet-preview__fx\" aria-hidden=\"true\"\n >fx</span\n >\n <output\n class=\"pk-spreadsheet-preview__formula\"\n :aria-label=\"$t('chatFilePreview.formulaBar')\">\n {{ barText(focusCell) }}\n </output>\n </div>\n <div\n ref=\"scrollEl\"\n class=\"pk-spreadsheet-preview__scroll\"\n tabindex=\"0\"\n role=\"grid\"\n :aria-label=\"sheet?.name\"\n @keydown=\"move\"\n @mouseup=\"dragging = false\"\n @mouseleave=\"dragging = false\">\n <table\n v-if=\"sheet\"\n class=\"pk-spreadsheet-preview__grid\"\n :class=\"{\n 'pk-spreadsheet-preview__grid--lines': sheet.gridlines,\n }\"\n :style=\"{ zoom, width: `${gridWidth}px` }\">\n <colgroup>\n <col :style=\"{ width: `${ROW_HEAD_WIDTH}px` }\" />\n <col\n v-for=\"c in columns\"\n :key=\"c.col\"\n :style=\"{ width: `${c.width}px` }\" />\n </colgroup>\n <thead>\n <tr :style=\"{ height: `${HEAD_HEIGHT}px` }\">\n <th class=\"pk-spreadsheet-preview__corner\" />\n <th\n v-for=\"c in columns\"\n :key=\"c.col\"\n scope=\"col\"\n class=\"pk-spreadsheet-preview__head\"\n :class=\"{\n 'pk-spreadsheet-preview__head--current':\n c.col >= range.c1 && c.col <= range.c2,\n }\">\n {{ letters(c.col) }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n v-for=\"r in rows\"\n :key=\"r.row\"\n v-memo=\"[\n r,\n sheet,\n columnsKey,\n locale,\n rowSelection(r.row),\n ]\"\n :style=\"{ height: `${r.height}px` }\">\n <th\n scope=\"row\"\n class=\"pk-spreadsheet-preview__row\"\n :class=\"{\n 'pk-spreadsheet-preview__row--current':\n r.row >= range.r1 && r.row <= range.r2,\n }\"\n :style=\"\n sheet.frozen && r.row <= sheet.frozen.rows\n ? {\n ...frozenCss(r.row, 0),\n left: 0,\n zIndex: 4,\n }\n : undefined\n \">\n {{ r.row }}\n </th>\n <template v-for=\"c in columns\" :key=\"c.col\">\n <td\n v-if=\"!covered.has(`${r.row},${c.col}`)\"\n :rowspan=\"shownSpan(r.row, c.col)?.rows\"\n :colspan=\"shownSpan(r.row, c.col)?.cols\"\n class=\"pk-spreadsheet-preview__cell\"\n :class=\"{\n 'pk-spreadsheet-preview__cell--range':\n inRange(r.row, c.col) &&\n !isFocus(r.row, c.col),\n 'pk-spreadsheet-preview__cell--missing':\n cellAt(r.row, c.col)?.missing,\n }\"\n :style=\"\n cellCss(cellAt(r.row, c.col), r.row, c.col)\n \"\n :data-focus=\"\n isFocus(r.row, c.col) ? '' : undefined\n \"\n :title=\"\n cellAt(r.row, c.col)?.missing\n ? $t('chatFilePreview.missingValue')\n : undefined\n \"\n @mousedown.prevent=\"pick(r.row, c.col, $event)\"\n @mouseenter=\"extend(r.row, c.col)\">\n {{ textOf(cellAt(r.row, c.col)) }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <p\n v-if=\"sheet && (sheet.moreRows || sheet.moreColumns)\"\n class=\"pk-spreadsheet-preview__more\">\n <template v-if=\"sheet.moreRows\">\n {{ $t('chatFilePreview.moreRows', sheet.moreRows) }}\n </template>\n <template v-if=\"sheet.moreColumns\">\n {{ $t('chatFilePreview.moreColumns', sheet.moreColumns) }}\n </template>\n </p>\n </div>\n <nav\n class=\"pk-spreadsheet-preview__sheets\"\n :aria-label=\"$t('chatFilePreview.sheets')\">\n <button\n v-for=\"(s, i) in preview.sheets\"\n :key=\"s.name\"\n type=\"button\"\n class=\"pk-spreadsheet-preview__sheet\"\n :aria-current=\"i === active ? 'page' : undefined\"\n @click=\"active = i\">\n {{ s.name }}\n </button>\n </nav>\n <div class=\"pk-spreadsheet-preview__status\">\n <p class=\"pk-spreadsheet-preview__info\">\n <span\n v-if=\"preview.staleFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.staleFormulas')\">\n {{ $t('chatFilePreview.staleFormulas') }}\n </span>\n <span\n v-else-if=\"preview.computedFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.computedFormulas')\">\n {{ $t('chatFilePreview.computedFormulas') }}\n </span>\n <span v-if=\"stats\" class=\"pk-spreadsheet-preview__stats\">\n <span\n v-if=\"stats.average\"\n class=\"pk-spreadsheet-preview__average\">\n {{ $t('chatFilePreview.average') }} {{ stats.average }}\n </span>\n <span>\n {{ $t('chatFilePreview.count') }} {{ stats.count }}\n </span>\n <span v-if=\"stats.sum\">\n {{ $t('chatFilePreview.sum') }} {{ stats.sum }}\n </span>\n </span>\n </p>\n <div class=\"pk-spreadsheet-preview__zoom\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.5\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-spreadsheet-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-spreadsheet-preview {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n // Excel's green marks the active cell, its column and row and the\n // current sheet, as in Excel (decided 2026-10-29). The cells keep\n // their paper in both themes; the headers lighten it on the dark one.\n --pk-spreadsheet-green: #217346;\n --pk-spreadsheet-green-head: #217346;\n\n // The formula bar: the cell, fx and its content, as in Excel\n &__bar {\n display: flex;\n align-items: stretch;\n min-height: var(--spacing-40);\n border-bottom: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n font-size: var(--text-14);\n }\n\n &__ref {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n width: var(--spacing-96);\n padding: 0 var(--spacing-12);\n box-sizing: border-box;\n border-right: var(--border) solid var(--color-surface-3);\n font-variant-numeric: tabular-nums;\n }\n\n &__fx {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-40);\n border-right: var(--border) solid var(--color-surface-3);\n color: var(--color-word-3);\n font-family: Georgia, serif;\n font-style: italic;\n }\n\n &__formula {\n display: flex;\n flex: 1;\n align-items: center;\n min-width: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n // The grid scrolls both ways; its headers stay\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n background-color: #fff;\n outline: none;\n cursor: cell;\n\n &:focus-visible {\n box-shadow: inset 0 0 0 var(--spacing-2)\n var(--input-focus-color);\n }\n }\n\n &__grid {\n border-collapse: collapse;\n table-layout: fixed;\n color: #000;\n font-family: Calibri, Carlito, 'Segoe UI', Arial, sans-serif;\n font-size: 11pt;\n user-select: none;\n\n td {\n overflow: hidden;\n max-width: 0;\n padding: 0 var(--spacing-4);\n background-color: #fff;\n line-height: 1.2;\n text-overflow: clip;\n }\n\n &--lines td {\n border: var(--border) solid #e1e1e1;\n }\n }\n\n // The letters and the numbers follow the theme, the cells do not\n &__corner,\n &__head,\n &__row {\n position: sticky;\n z-index: 1;\n border: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-3);\n font-family: var(--font-family-sans);\n font-size: var(--text-12);\n font-weight: var(--font-normal);\n text-align: center;\n }\n\n // The letters sit in the middle of their row, room above and below\n &__corner,\n &__head {\n top: 0;\n padding: var(--spacing-4) var(--spacing-4) var(--spacing-2);\n line-height: 1;\n vertical-align: middle;\n }\n\n &__row {\n vertical-align: middle;\n }\n\n &__corner {\n left: 0;\n z-index: 5;\n }\n\n &__row {\n left: 0;\n padding: 0 var(--spacing-4);\n font-variant-numeric: tabular-nums;\n }\n\n // Where the selection is, as Excel shows it: one step of surface,\n // and the letter and a thin line in its green\n &__head--current {\n background-color: var(--color-surface-2);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__row--current {\n background-color: var(--color-surface-2);\n box-shadow: inset calc(var(--spacing-2) * -1) 0 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__cell[data-focus] {\n outline: var(--spacing-2) solid var(--pk-spreadsheet-green);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n\n &__cell--range {\n box-shadow: inset 0 0 0 100vmax rgb(31 29 43 / 8%);\n }\n\n &__cell--missing {\n color: #6b6880;\n }\n\n &__more {\n position: sticky;\n left: 0;\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n color: #6b6880;\n font-size: var(--text-12);\n }\n\n // The sheets at the bottom, as Excel draws its tabs, and the status\n // bar below them: two rows, as in Excel, so the sums of a selection\n // never push the sheets or the note out of a narrow frame\n &__sheets {\n display: flex;\n flex-shrink: 0;\n min-height: var(--spacing-32);\n overflow-x: auto;\n padding-left: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n\n @media (pointer: coarse) {\n min-height: var(--spacing-40);\n }\n }\n\n &__status {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n min-height: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n font-size: var(--text-12);\n }\n\n &__sheet {\n flex-shrink: 0;\n padding: 0 var(--spacing-16);\n border: 0;\n border-right: var(--border) solid var(--color-surface-3);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-12);\n white-space: nowrap;\n cursor: pointer;\n\n &:first-child {\n border-left: var(--border) solid var(--color-surface-3);\n }\n\n &:hover {\n background-color: var(--color-surface-2);\n }\n\n &[aria-current='page'] {\n background-color: var(--color-surface);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-semibold);\n }\n }\n\n // The note on the left, as Excel's messages, the sums on the right:\n // the note gives way to them\n &__info {\n display: flex;\n flex: 1;\n align-items: center;\n gap: var(--spacing-16);\n min-width: 0;\n margin: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__note {\n min-width: 0;\n overflow: hidden;\n color: var(--color-word-3);\n text-overflow: ellipsis;\n }\n\n &__stats {\n display: flex;\n flex-shrink: 0;\n gap: var(--spacing-12);\n margin-left: auto;\n }\n\n // A phone keeps the count and the sum of a selection\n @container (width < 26rem) {\n &__average {\n display: none;\n }\n }\n\n &__zoom {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n gap: var(--spacing-2);\n padding-right: var(--spacing-8);\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n\n // On the dark headers Excel's green reads too dark: a lighter step of it\n @media (prefers-color-scheme: dark) {\n :where(:host, :root, .theme):not(.theme--light)\n .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n }\n\n :where(.theme.theme--dark) .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n import type { CSSProperties } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type {\n SpreadsheetPreview,\n SpreadsheetPreviewCell,\n SpreadsheetPreviewStyle,\n } from 'models'\n\n /**\n * A spreadsheet stored in the chat, drawn as Excel draws it (spec\n * `chat-office-files.md`, F6, item 4, and the viewer of its follow-ups):\n * column letters and row numbers that stay in view, the widths, heights,\n * fonts, fills and borders of the file, merged cells and frozen panes.\n * A cell is picked with a click, a range with a drag or shift, and the\n * arrows move it: the formula bar shows its formula, the status bar the\n * sum of a range. The sheets are tabs at the bottom. The grid keeps the\n * file's white in the dark theme, as a page does; the bars around it\n * follow the theme. Framed by `PkFilePreview`.\n */\n const props = defineProps<{ preview: SpreadsheetPreview }>()\n\n const { t: $t, locale } = useI18n({ useScope: 'global' })\n\n /** Excel's defaults, in pixels. */\n const COLUMN_WIDTH = 64\n const ROW_HEIGHT = 20\n const HEAD_HEIGHT = 28\n const ROW_HEAD_WIDTH = 44\n\n // Models, so the sheet and the zoom stay when the viewer moves between\n // the panel and the dialog (`PkChatbotViewChat` keeps them).\n const active = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const scrollEl = useTemplateRef<HTMLDivElement>('scrollEl')\n // The border box, scroll bars included: the grid that fills the view\n // makes them appear, and measured without them the view shrank, the\n // grid changed again, and the two went on in a loop.\n const { width: viewWidth, height: viewHeight } = useElementSize(\n scrollEl,\n { width: 0, height: 0 },\n { box: 'border-box' },\n )\n const sheet = computed(\n () => props.preview.sheets[active.value] ?? props.preview.sheets[0],\n )\n watch(\n () => props.preview,\n () => {\n active.value = 0\n },\n )\n\n const letters = (n: number): string => {\n let s = ''\n for (let c = n; c > 0; c = Math.floor((c - 1) / 26)) {\n s = String.fromCharCode(65 + ((c - 1) % 26)) + s\n }\n return s\n }\n\n // Empty rows and columns after the data up to the edges of the view, as\n // Excel's grid goes on, unless the file goes on past what the preview\n // holds: an empty column there would say the sheet ends.\n const columns = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(\n s.columns.filter((c) => c.hidden).map((c) => c.col),\n )\n const widths = new Map(s.columns.map((c) => [c.col, c.width]))\n const out: Array<{ col: number; width: number }> = []\n let used = ROW_HEAD_WIDTH\n const room = viewWidth.value / zoom.value\n for (\n let col = 1;\n col <= s.lastColumn ||\n (!s.moreColumns && (col <= s.lastColumn + 2 || used < room));\n col++\n ) {\n if (hidden.has(col)) {\n continue\n }\n const width = widths.get(col) ?? COLUMN_WIDTH\n out.push({ col, width })\n used += width\n }\n return out\n })\n /** A fixed layout needs the table's width, or the columns shrink. */\n const gridWidth = computed(() =>\n columns.value.reduce((n, c) => n + c.width, ROW_HEAD_WIDTH),\n )\n /** The columns as a value: the same set at another zoom, for the memo. */\n const columnsKey = computed(() =>\n columns.value.map((c) => `${c.col}:${c.width}`).join(','),\n )\n // One object per row while its sheet is shown, so a row's memo holds\n // when the view adds rows to fill itself.\n const rowObjects = new WeakMap<\n object,\n Map<number, { row: number; height: number }>\n >()\n const rows = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(s.hiddenRows ?? [])\n const heights = new Map(s.rows.map((r) => [r.row, r.height]))\n const fill = Math.ceil(\n (viewHeight.value / zoom.value - HEAD_HEIGHT) / ROW_HEIGHT,\n )\n const last = s.moreRows\n ? s.lastRow\n : Math.max(s.lastRow + 5, fill + hidden.size)\n let known = rowObjects.get(s)\n if (!known) {\n known = new Map()\n rowObjects.set(s, known)\n }\n const seen = known\n return Array.from({ length: last }, (_, i) => i + 1)\n .filter((row) => !hidden.has(row))\n .map((row) => {\n let r = seen.get(row)\n if (!r) {\n r = { row, height: heights.get(row) ?? ROW_HEIGHT }\n seen.set(row, r)\n }\n return r\n })\n })\n const cells = computed(() => {\n const map = new Map<string, SpreadsheetPreviewCell>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n map.set(`${r.row},${c.col}`, c)\n }\n }\n return map\n })\n /** The cells a merge covers, each with the first cell that draws it. */\n const covered = computed(() => {\n const map = new Map<string, { row: number; col: number }>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n if (!c.span) {\n continue\n }\n for (let dr = 0; dr < c.span.rows; dr++) {\n for (let dc = 0; dc < c.span.cols; dc++) {\n if (dr || dc) {\n map.set(`${r.row + dr},${c.col + dc}`, {\n row: r.row,\n col: c.col,\n })\n }\n }\n }\n }\n }\n return map\n })\n const cellAt = (row: number, col: number) =>\n cells.value.get(`${row},${col}`)\n /**\n * A merge's span over the rows and columns the grid draws: the file\n * counts the hidden ones too, and the merge ran into the next column.\n */\n const shownSpan = (row: number, col: number) => {\n const span = cellAt(row, col)?.span\n if (!span) {\n return undefined\n }\n return {\n rows: rows.value.filter(\n (r) => r.row >= row && r.row < row + span.rows,\n ).length,\n cols: columns.value.filter(\n (c) => c.col >= col && c.col < col + span.cols,\n ).length,\n }\n }\n const styleOf = (\n cell: SpreadsheetPreviewCell | undefined,\n ): SpreadsheetPreviewStyle | undefined =>\n cell?.style === undefined ? undefined : props.preview.styles[cell.style]\n\n // #region the text of a cell\n const numberText = (cell: SpreadsheetPreviewCell, v: number) => {\n const digits =\n cell.decimals !== undefined\n ? {\n minimumFractionDigits: cell.decimals,\n maximumFractionDigits: cell.maxDecimals ?? cell.decimals,\n }\n : { maximumFractionDigits: 10 }\n return new Intl.NumberFormat(locale.value, {\n ...digits,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n ...(cell.format === 'currency' && cell.currency\n ? { style: 'currency', currency: cell.currency }\n : {}),\n }).format(v)\n }\n\n const dateText = (v: string) => {\n const date = new Date(`${v}T00:00:00Z`)\n return Number.isNaN(date.getTime())\n ? v\n : new Intl.DateTimeFormat(locale.value, {\n dateStyle: 'short',\n timeZone: 'UTC',\n }).format(date)\n }\n\n /** The cell's text: a number in the reader's language, a date, a word. */\n const textOf = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.missing) {\n return '—'\n }\n const v = cell.value\n if (v === undefined) {\n return ''\n }\n if (typeof v === 'boolean') {\n return v ? $t('chatFilePreview.true') : $t('chatFilePreview.false')\n }\n if (cell.format === 'date' && typeof v === 'string') {\n return dateText(v)\n }\n if (typeof v === 'number') {\n return numberText(cell, v)\n }\n return v\n }\n\n /** What Excel's bar shows: the formula, or the value as typed. */\n const barText = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.formula) {\n return `=${cell.formula}`\n }\n const v = cell.value\n if (typeof v === 'number') {\n return new Intl.NumberFormat(locale.value, {\n useGrouping: false,\n maximumFractionDigits: 15,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n }).format(v)\n }\n return textOf(cell)\n }\n // #endregion\n\n // #region the look of a cell\n const border = (side?: { color: string; width: number }) =>\n side ? `${side.width}px solid ${side.color}` : undefined\n\n const cellCss = (\n cell: SpreadsheetPreviewCell | undefined,\n row: number,\n col: number,\n ): CSSProperties => {\n const s = styleOf(cell)\n const v = cell?.value\n const numeric = typeof v === 'number' || !!cell?.missing\n const css: CSSProperties = {\n textAlign:\n s?.align ??\n (numeric\n ? 'right'\n : typeof v === 'boolean' || cell?.format === 'error'\n ? 'center'\n : 'left'),\n verticalAlign:\n s?.valign === 'top'\n ? 'top'\n : s?.valign === 'middle'\n ? 'middle'\n : 'bottom',\n whiteSpace: s?.wrap ? 'pre-wrap' : 'nowrap',\n }\n if (s?.bold) {\n css.fontWeight = 700\n }\n if (s?.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n s?.underline ? 'underline' : '',\n s?.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (s?.size) {\n css.fontSize = `${s.size}pt`\n }\n if (s?.color) {\n css.color = s.color\n }\n if (s?.fill) {\n css.backgroundColor = s.fill\n }\n if (s?.indent) {\n const pad = `${4 + s.indent * 9}px`\n if (css.textAlign === 'right') {\n css.paddingRight = pad\n } else {\n css.paddingLeft = pad\n }\n }\n css.borderTop = border(s?.borders?.top)\n css.borderRight = border(s?.borders?.right)\n css.borderBottom = border(s?.borders?.bottom)\n css.borderLeft = border(s?.borders?.left)\n Object.assign(css, frozenCss(row, col))\n return css\n }\n\n /** Where a frozen row or column sticks, under the headers. */\n const frozenCss = (row: number, col: number): CSSProperties => {\n const f = sheet.value?.frozen\n if (!f) {\n return {}\n }\n const css: CSSProperties = {}\n if (row <= f.rows) {\n css.position = 'sticky'\n css.top = `${\n HEAD_HEIGHT +\n rows.value\n .filter((r) => r.row < row)\n .reduce((n, r) => n + r.height, 0)\n }px`\n css.zIndex = 2\n }\n if (col <= f.cols) {\n css.position = 'sticky'\n css.left = `${\n ROW_HEAD_WIDTH +\n columns.value\n .filter((c) => c.col < col)\n .reduce((n, c) => n + c.width, 0)\n }px`\n css.zIndex = row <= f.rows ? 3 : 2\n }\n return css\n }\n // #endregion\n\n // #region selection\n type At = { row: number; col: number }\n const anchor = ref<At>({ row: 1, col: 1 })\n const focus = ref<At>({ row: 1, col: 1 })\n watch(sheet, () => {\n anchor.value = { row: 1, col: 1 }\n focus.value = { row: 1, col: 1 }\n })\n const range = computed(() => ({\n r1: Math.min(anchor.value.row, focus.value.row),\n r2: Math.max(anchor.value.row, focus.value.row),\n c1: Math.min(anchor.value.col, focus.value.col),\n c2: Math.max(anchor.value.col, focus.value.col),\n }))\n const inRange = (row: number, col: number) =>\n row >= range.value.r1 &&\n row <= range.value.r2 &&\n col >= range.value.c1 &&\n col <= range.value.c2\n const isFocus = (row: number, col: number) =>\n focus.value.row === row && focus.value.col === col\n /**\n * What a row draws of the selection. A row is drawn again only when\n * this, its sheet, the columns or the language of the numbers change: a\n * sheet of thousands of cells drew them all at each step of a drag,\n * seconds per selection.\n */\n const rowSelection = (row: number) =>\n row >= range.value.r1 && row <= range.value.r2\n ? `${range.value.c1}:${range.value.c2}:${\n focus.value.row === row ? focus.value.col : 0\n }`\n : ''\n\n const dragging = ref(false)\n const pick = (row: number, col: number, event: MouseEvent) => {\n // The click keeps its default off (no text selection while dragging),\n // so the grid takes the keyboard here.\n scrollEl.value?.focus({ preventScroll: true })\n focus.value = { row, col }\n if (!event.shiftKey) {\n anchor.value = { row, col }\n }\n dragging.value = true\n }\n const extend = (row: number, col: number) => {\n if (dragging.value) {\n focus.value = { row, col }\n }\n }\n\n const move = (event: KeyboardEvent) => {\n const steps: Record<string, [number, number]> = {\n ArrowUp: [-1, 0],\n ArrowDown: [1, 0],\n ArrowLeft: [0, -1],\n ArrowRight: [0, 1],\n Enter: [1, 0],\n Tab: [0, 1],\n }\n const step = steps[event.key]\n if (!step) {\n return\n }\n event.preventDefault()\n const rowList = rows.value.map((r) => r.row)\n const colList = columns.value.map((c) => c.col)\n const ownerOf = (at: At) =>\n covered.value.get(`${at.row},${at.col}`) ?? at\n // As in Excel, a merge is one cell: the step goes past the cells it\n // covers, and a step into one lands on the cell that draws it.\n const start = ownerOf(focus.value)\n let r = rowList.indexOf(focus.value.row)\n let c = colList.indexOf(focus.value.col)\n let next = start\n for (;;) {\n const nr = Math.min(rowList.length - 1, Math.max(0, r + step[0]))\n const nc = Math.min(colList.length - 1, Math.max(0, c + step[1]))\n if (nr === r && nc === c) {\n break\n }\n r = nr\n c = nc\n next = ownerOf({ row: rowList[r], col: colList[c] })\n if (next.row !== start.row || next.col !== start.col) {\n break\n }\n }\n focus.value = next\n if (!event.shiftKey) {\n anchor.value = next\n }\n nextTick(() =>\n scrollEl.value\n ?.querySelector('[data-focus]')\n ?.scrollIntoView({ block: 'nearest', inline: 'nearest' }),\n )\n }\n\n const focusCell = computed(() => cellAt(focus.value.row, focus.value.col))\n /** Count, average and sum of a range, as Excel's status bar shows them. */\n const stats = computed(() => {\n const { r1, r2, c1, c2 } = range.value\n if (r1 === r2 && c1 === c2) {\n return undefined\n }\n let count = 0\n let sum = 0\n let numbers = 0\n let first: SpreadsheetPreviewCell | undefined\n for (let r = r1; r <= r2; r++) {\n for (let c = c1; c <= c2; c++) {\n const cell = cellAt(r, c)\n if (!cell || (cell.value === undefined && !cell.missing)) {\n continue\n }\n count++\n if (typeof cell.value === 'number') {\n sum += cell.value\n numbers++\n first ??= cell\n }\n }\n }\n if (!count) {\n return undefined\n }\n return {\n count,\n sum: first ? numberText(first, sum) : undefined,\n // One number among text is still an average, as in Excel\n average: first ? numberText(first, sum / numbers) : undefined,\n }\n })\n // #endregion\n\n // #region zoom\n const zoomBy = (step: number) => {\n zoom.value = Math.min(\n 2,\n Math.max(0.5, Math.round((zoom.value + step) * 10) / 10),\n )\n }\n // #endregion\n</script>\n\n<template>\n <div class=\"pk-spreadsheet-preview\">\n <div class=\"pk-spreadsheet-preview__bar\">\n <span\n class=\"pk-spreadsheet-preview__ref\"\n :aria-label=\"$t('chatFilePreview.cell')\">\n {{ letters(focus.col) }}{{ focus.row }}\n </span>\n <span class=\"pk-spreadsheet-preview__fx\" aria-hidden=\"true\"\n >fx</span\n >\n <output\n class=\"pk-spreadsheet-preview__formula\"\n :aria-label=\"$t('chatFilePreview.formulaBar')\">\n {{ barText(focusCell) }}\n </output>\n </div>\n <div\n ref=\"scrollEl\"\n class=\"pk-spreadsheet-preview__scroll\"\n tabindex=\"0\"\n role=\"grid\"\n :aria-label=\"sheet?.name\"\n @keydown=\"move\"\n @mouseup=\"dragging = false\"\n @mouseleave=\"dragging = false\">\n <table\n v-if=\"sheet\"\n class=\"pk-spreadsheet-preview__grid\"\n :class=\"{\n 'pk-spreadsheet-preview__grid--lines': sheet.gridlines,\n }\"\n :style=\"{ zoom, width: `${gridWidth}px` }\">\n <colgroup>\n <col :style=\"{ width: `${ROW_HEAD_WIDTH}px` }\" />\n <col\n v-for=\"c in columns\"\n :key=\"c.col\"\n :style=\"{ width: `${c.width}px` }\" />\n </colgroup>\n <thead>\n <tr :style=\"{ height: `${HEAD_HEIGHT}px` }\">\n <th class=\"pk-spreadsheet-preview__corner\" />\n <th\n v-for=\"c in columns\"\n :key=\"c.col\"\n scope=\"col\"\n class=\"pk-spreadsheet-preview__head\"\n :class=\"{\n 'pk-spreadsheet-preview__head--current':\n c.col >= range.c1 && c.col <= range.c2,\n }\">\n {{ letters(c.col) }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n v-for=\"r in rows\"\n :key=\"r.row\"\n v-memo=\"[\n r,\n sheet,\n columnsKey,\n locale,\n rowSelection(r.row),\n ]\"\n :style=\"{ height: `${r.height}px` }\">\n <th\n scope=\"row\"\n class=\"pk-spreadsheet-preview__row\"\n :class=\"{\n 'pk-spreadsheet-preview__row--current':\n r.row >= range.r1 && r.row <= range.r2,\n }\"\n :style=\"\n sheet.frozen && r.row <= sheet.frozen.rows\n ? {\n ...frozenCss(r.row, 0),\n left: 0,\n zIndex: 4,\n }\n : undefined\n \">\n {{ r.row }}\n </th>\n <template v-for=\"c in columns\" :key=\"c.col\">\n <td\n v-if=\"!covered.has(`${r.row},${c.col}`)\"\n :rowspan=\"shownSpan(r.row, c.col)?.rows\"\n :colspan=\"shownSpan(r.row, c.col)?.cols\"\n class=\"pk-spreadsheet-preview__cell\"\n :class=\"{\n 'pk-spreadsheet-preview__cell--range':\n inRange(r.row, c.col) &&\n !isFocus(r.row, c.col),\n 'pk-spreadsheet-preview__cell--missing':\n cellAt(r.row, c.col)?.missing,\n }\"\n :style=\"\n cellCss(cellAt(r.row, c.col), r.row, c.col)\n \"\n :data-focus=\"\n isFocus(r.row, c.col) ? '' : undefined\n \"\n :title=\"\n cellAt(r.row, c.col)?.missing\n ? $t('chatFilePreview.missingValue')\n : undefined\n \"\n @mousedown.prevent=\"pick(r.row, c.col, $event)\"\n @mouseenter=\"extend(r.row, c.col)\">\n {{ textOf(cellAt(r.row, c.col)) }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <p\n v-if=\"sheet && (sheet.moreRows || sheet.moreColumns)\"\n class=\"pk-spreadsheet-preview__more\">\n <template v-if=\"sheet.moreRows\">\n {{ $t('chatFilePreview.moreRows', sheet.moreRows) }}\n </template>\n <template v-if=\"sheet.moreColumns\">\n {{ $t('chatFilePreview.moreColumns', sheet.moreColumns) }}\n </template>\n </p>\n </div>\n <nav\n class=\"pk-spreadsheet-preview__sheets\"\n :aria-label=\"$t('chatFilePreview.sheets')\">\n <button\n v-for=\"(s, i) in preview.sheets\"\n :key=\"s.name\"\n type=\"button\"\n class=\"pk-spreadsheet-preview__sheet\"\n :aria-current=\"i === active ? 'page' : undefined\"\n @click=\"active = i\">\n {{ s.name }}\n </button>\n </nav>\n <div class=\"pk-spreadsheet-preview__status\">\n <p class=\"pk-spreadsheet-preview__info\">\n <span\n v-if=\"preview.staleFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.staleFormulas')\">\n {{ $t('chatFilePreview.staleFormulas') }}\n </span>\n <span\n v-else-if=\"preview.computedFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.computedFormulas')\">\n {{ $t('chatFilePreview.computedFormulas') }}\n </span>\n <span v-if=\"stats\" class=\"pk-spreadsheet-preview__stats\">\n <span\n v-if=\"stats.average\"\n class=\"pk-spreadsheet-preview__average\">\n {{ $t('chatFilePreview.average') }} {{ stats.average }}\n </span>\n <span>\n {{ $t('chatFilePreview.count') }} {{ stats.count }}\n </span>\n <span v-if=\"stats.sum\">\n {{ $t('chatFilePreview.sum') }} {{ stats.sum }}\n </span>\n </span>\n </p>\n <div class=\"pk-spreadsheet-preview__zoom\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.5\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-spreadsheet-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-spreadsheet-preview {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n // Excel's green marks the active cell, its column and row and the\n // current sheet, as in Excel (decided 2026-10-29). The cells keep\n // their paper in both themes; the headers lighten it on the dark one.\n --pk-spreadsheet-green: #217346;\n --pk-spreadsheet-green-head: #217346;\n\n // The formula bar: the cell, fx and its content, as in Excel\n &__bar {\n display: flex;\n align-items: stretch;\n min-height: var(--spacing-40);\n border-bottom: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n font-size: var(--text-14);\n }\n\n &__ref {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n width: var(--spacing-96);\n padding: 0 var(--spacing-12);\n box-sizing: border-box;\n border-right: var(--border) solid var(--color-surface-3);\n font-variant-numeric: tabular-nums;\n }\n\n &__fx {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-40);\n border-right: var(--border) solid var(--color-surface-3);\n color: var(--color-word-3);\n font-family: Georgia, serif;\n font-style: italic;\n }\n\n &__formula {\n display: flex;\n flex: 1;\n align-items: center;\n min-width: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n // The grid scrolls both ways; its headers stay\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n background-color: #fff;\n outline: none;\n cursor: cell;\n\n &:focus-visible {\n box-shadow: inset 0 0 0 var(--spacing-2)\n var(--input-focus-color);\n }\n }\n\n &__grid {\n border-collapse: collapse;\n table-layout: fixed;\n color: #000;\n font-family: Calibri, Carlito, 'Segoe UI', Arial, sans-serif;\n font-size: 11pt;\n user-select: none;\n\n td {\n overflow: hidden;\n max-width: 0;\n padding: 0 var(--spacing-4);\n background-color: #fff;\n line-height: 1.2;\n text-overflow: clip;\n }\n\n &--lines td {\n border: var(--border) solid #e1e1e1;\n }\n }\n\n // The letters and the numbers follow the theme, the cells do not\n &__corner,\n &__head,\n &__row {\n position: sticky;\n z-index: 1;\n border: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-3);\n font-family: var(--font-family-sans);\n font-size: var(--text-12);\n font-weight: var(--font-normal);\n text-align: center;\n }\n\n // The letters sit in the middle of their row, room above and below\n &__corner,\n &__head {\n top: 0;\n padding: var(--spacing-4) var(--spacing-4) var(--spacing-2);\n line-height: 1;\n vertical-align: middle;\n }\n\n &__row {\n vertical-align: middle;\n }\n\n &__corner {\n left: 0;\n z-index: 5;\n }\n\n &__row {\n left: 0;\n padding: 0 var(--spacing-4);\n font-variant-numeric: tabular-nums;\n }\n\n // Where the selection is, as Excel shows it: one step of surface,\n // and the letter and a thin line in its green\n &__head--current {\n background-color: var(--color-surface-2);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__row--current {\n background-color: var(--color-surface-2);\n box-shadow: inset calc(var(--spacing-2) * -1) 0 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__cell[data-focus] {\n outline: var(--spacing-2) solid var(--pk-spreadsheet-green);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n\n &__cell--range {\n box-shadow: inset 0 0 0 100vmax rgb(31 29 43 / 8%);\n }\n\n &__cell--missing {\n color: #6b6880;\n }\n\n &__more {\n position: sticky;\n left: 0;\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n color: #6b6880;\n font-size: var(--text-12);\n }\n\n // The sheets at the bottom, as Excel draws its tabs, and the status\n // bar below them: two rows, as in Excel, so the sums of a selection\n // never push the sheets or the note out of a narrow frame\n &__sheets {\n display: flex;\n flex-shrink: 0;\n min-height: var(--spacing-32);\n overflow-x: auto;\n padding-left: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n\n @media (pointer: coarse) {\n min-height: var(--spacing-40);\n }\n }\n\n &__status {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n min-height: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n font-size: var(--text-12);\n }\n\n &__sheet {\n flex-shrink: 0;\n padding: 0 var(--spacing-16);\n border: 0;\n border-right: var(--border) solid var(--color-surface-3);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-12);\n white-space: nowrap;\n cursor: pointer;\n\n &:first-child {\n border-left: var(--border) solid var(--color-surface-3);\n }\n\n &:hover {\n background-color: var(--color-surface-2);\n }\n\n &[aria-current='page'] {\n background-color: var(--color-surface);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-semibold);\n }\n }\n\n // The note on the left, as Excel's messages, the sums on the right:\n // the note gives way to them\n &__info {\n display: flex;\n flex: 1;\n align-items: center;\n gap: var(--spacing-16);\n min-width: 0;\n margin: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__note {\n min-width: 0;\n overflow: hidden;\n color: var(--color-word-3);\n text-overflow: ellipsis;\n }\n\n &__stats {\n display: flex;\n flex-shrink: 0;\n gap: var(--spacing-12);\n margin-left: auto;\n }\n\n // A phone keeps the count and the sum of a selection\n @container (width < 26rem) {\n &__average {\n display: none;\n }\n }\n\n &__zoom {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n gap: var(--spacing-2);\n padding-right: var(--spacing-8);\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n\n // On the dark headers Excel's green reads too dark: a lighter step of it\n @media (prefers-color-scheme: dark) {\n :where(:host, :root, .theme):not(.theme--light)\n .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n }\n\n :where(.theme.theme--dark) .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n import type { CSSProperties } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type {\n SpreadsheetPreview,\n SpreadsheetPreviewCell,\n SpreadsheetPreviewStyle,\n } from 'models'\n\n /**\n * A spreadsheet stored in the chat, drawn as Excel draws it (spec\n * `chat-office-files.md`, F6, item 4, and the viewer of its follow-ups):\n * column letters and row numbers that stay in view, the widths, heights,\n * fonts, fills and borders of the file, merged cells and frozen panes.\n * A cell is picked with a click, a range with a drag or shift, and the\n * arrows move it: the formula bar shows its formula, the status bar the\n * sum of a range. The sheets are tabs at the bottom. The grid keeps the\n * file's white in the dark theme, as a page does; the bars around it\n * follow the theme. Framed by `PkFilePreview`.\n */\n const props = defineProps<{ preview: SpreadsheetPreview }>()\n\n const { t: $t, locale } = useI18n({ useScope: 'global' })\n\n /** Excel's defaults, in pixels. */\n const COLUMN_WIDTH = 64\n const ROW_HEIGHT = 20\n const HEAD_HEIGHT = 28\n const ROW_HEAD_WIDTH = 44\n\n // Models, so the sheet and the zoom stay when the viewer moves between\n // the panel and the dialog (`PkChatbotViewChat` keeps them).\n const active = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const scrollEl = useTemplateRef<HTMLDivElement>('scrollEl')\n // The border box, scroll bars included: the grid that fills the view\n // makes them appear, and measured without them the view shrank, the\n // grid changed again, and the two went on in a loop.\n const { width: viewWidth, height: viewHeight } = useElementSize(\n scrollEl,\n { width: 0, height: 0 },\n { box: 'border-box' },\n )\n const sheet = computed(\n () => props.preview.sheets[active.value] ?? props.preview.sheets[0],\n )\n watch(\n () => props.preview,\n () => {\n active.value = 0\n },\n )\n\n const letters = (n: number): string => {\n let s = ''\n for (let c = n; c > 0; c = Math.floor((c - 1) / 26)) {\n s = String.fromCharCode(65 + ((c - 1) % 26)) + s\n }\n return s\n }\n\n // Empty rows and columns after the data up to the edges of the view, as\n // Excel's grid goes on, unless the file goes on past what the preview\n // holds: an empty column there would say the sheet ends.\n const columns = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(\n s.columns.filter((c) => c.hidden).map((c) => c.col),\n )\n const widths = new Map(s.columns.map((c) => [c.col, c.width]))\n const out: Array<{ col: number; width: number }> = []\n let used = ROW_HEAD_WIDTH\n const room = viewWidth.value / zoom.value\n for (\n let col = 1;\n col <= s.lastColumn ||\n (!s.moreColumns && (col <= s.lastColumn + 2 || used < room));\n col++\n ) {\n if (hidden.has(col)) {\n continue\n }\n const width = widths.get(col) ?? COLUMN_WIDTH\n out.push({ col, width })\n used += width\n }\n return out\n })\n /** A fixed layout needs the table's width, or the columns shrink. */\n const gridWidth = computed(() =>\n columns.value.reduce((n, c) => n + c.width, ROW_HEAD_WIDTH),\n )\n /** The columns as a value: the same set at another zoom, for the memo. */\n const columnsKey = computed(() =>\n columns.value.map((c) => `${c.col}:${c.width}`).join(','),\n )\n // One object per row while its sheet is shown, so a row's memo holds\n // when the view adds rows to fill itself.\n const rowObjects = new WeakMap<\n object,\n Map<number, { row: number; height: number }>\n >()\n const rows = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(s.hiddenRows ?? [])\n const heights = new Map(s.rows.map((r) => [r.row, r.height]))\n const fill = Math.ceil(\n (viewHeight.value / zoom.value - HEAD_HEIGHT) / ROW_HEIGHT,\n )\n const last = s.moreRows\n ? s.lastRow\n : Math.max(s.lastRow + 5, fill + hidden.size)\n let known = rowObjects.get(s)\n if (!known) {\n known = new Map()\n rowObjects.set(s, known)\n }\n const seen = known\n return Array.from({ length: last }, (_, i) => i + 1)\n .filter((row) => !hidden.has(row))\n .map((row) => {\n let r = seen.get(row)\n if (!r) {\n r = { row, height: heights.get(row) ?? ROW_HEIGHT }\n seen.set(row, r)\n }\n return r\n })\n })\n const cells = computed(() => {\n const map = new Map<string, SpreadsheetPreviewCell>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n map.set(`${r.row},${c.col}`, c)\n }\n }\n return map\n })\n /** The cells a merge covers, each with the first cell that draws it. */\n const covered = computed(() => {\n const map = new Map<string, { row: number; col: number }>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n if (!c.span) {\n continue\n }\n for (let dr = 0; dr < c.span.rows; dr++) {\n for (let dc = 0; dc < c.span.cols; dc++) {\n if (dr || dc) {\n map.set(`${r.row + dr},${c.col + dc}`, {\n row: r.row,\n col: c.col,\n })\n }\n }\n }\n }\n }\n return map\n })\n const cellAt = (row: number, col: number) =>\n cells.value.get(`${row},${col}`)\n /**\n * A merge's span over the rows and columns the grid draws: the file\n * counts the hidden ones too, and the merge ran into the next column.\n */\n const shownSpan = (row: number, col: number) => {\n const span = cellAt(row, col)?.span\n if (!span) {\n return undefined\n }\n return {\n rows: rows.value.filter(\n (r) => r.row >= row && r.row < row + span.rows,\n ).length,\n cols: columns.value.filter(\n (c) => c.col >= col && c.col < col + span.cols,\n ).length,\n }\n }\n const styleOf = (\n cell: SpreadsheetPreviewCell | undefined,\n ): SpreadsheetPreviewStyle | undefined =>\n cell?.style === undefined ? undefined : props.preview.styles[cell.style]\n\n // #region the text of a cell\n const numberText = (cell: SpreadsheetPreviewCell, v: number) => {\n const digits =\n cell.decimals !== undefined\n ? {\n minimumFractionDigits: cell.decimals,\n maximumFractionDigits: cell.maxDecimals ?? cell.decimals,\n }\n : { maximumFractionDigits: 10 }\n return new Intl.NumberFormat(locale.value, {\n ...digits,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n ...(cell.format === 'currency' && cell.currency\n ? { style: 'currency', currency: cell.currency }\n : {}),\n }).format(v)\n }\n\n const dateText = (v: string) => {\n const date = new Date(`${v}T00:00:00Z`)\n return Number.isNaN(date.getTime())\n ? v\n : new Intl.DateTimeFormat(locale.value, {\n dateStyle: 'short',\n timeZone: 'UTC',\n }).format(date)\n }\n\n /** The cell's text: a number in the reader's language, a date, a word. */\n const textOf = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.missing) {\n return '—'\n }\n const v = cell.value\n if (v === undefined) {\n return ''\n }\n if (typeof v === 'boolean') {\n return v ? $t('chatFilePreview.true') : $t('chatFilePreview.false')\n }\n if (cell.format === 'date' && typeof v === 'string') {\n return dateText(v)\n }\n if (typeof v === 'number') {\n return numberText(cell, v)\n }\n return v\n }\n\n /** What Excel's bar shows: the formula, or the value as typed. */\n const barText = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.formula) {\n return `=${cell.formula}`\n }\n const v = cell.value\n if (typeof v === 'number') {\n return new Intl.NumberFormat(locale.value, {\n useGrouping: false,\n maximumFractionDigits: 15,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n }).format(v)\n }\n return textOf(cell)\n }\n // #endregion\n\n // #region the look of a cell\n const border = (side?: { color: string; width: number }) =>\n side ? `${side.width}px solid ${side.color}` : undefined\n\n const cellCss = (\n cell: SpreadsheetPreviewCell | undefined,\n row: number,\n col: number,\n ): CSSProperties => {\n const s = styleOf(cell)\n const v = cell?.value\n const numeric = typeof v === 'number' || !!cell?.missing\n const css: CSSProperties = {\n textAlign:\n s?.align ??\n (numeric\n ? 'right'\n : typeof v === 'boolean' || cell?.format === 'error'\n ? 'center'\n : 'left'),\n verticalAlign:\n s?.valign === 'top'\n ? 'top'\n : s?.valign === 'middle'\n ? 'middle'\n : 'bottom',\n whiteSpace: s?.wrap ? 'pre-wrap' : 'nowrap',\n }\n if (s?.bold) {\n css.fontWeight = 700\n }\n if (s?.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n s?.underline ? 'underline' : '',\n s?.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (s?.size) {\n css.fontSize = `${s.size}pt`\n }\n if (s?.color) {\n css.color = s.color\n }\n if (s?.fill) {\n css.backgroundColor = s.fill\n }\n if (s?.indent) {\n const pad = `${4 + s.indent * 9}px`\n if (css.textAlign === 'right') {\n css.paddingRight = pad\n } else {\n css.paddingLeft = pad\n }\n }\n css.borderTop = border(s?.borders?.top)\n css.borderRight = border(s?.borders?.right)\n css.borderBottom = border(s?.borders?.bottom)\n css.borderLeft = border(s?.borders?.left)\n Object.assign(css, frozenCss(row, col))\n return css\n }\n\n /** Where a frozen row or column sticks, under the headers. */\n const frozenCss = (row: number, col: number): CSSProperties => {\n const f = sheet.value?.frozen\n if (!f) {\n return {}\n }\n const css: CSSProperties = {}\n if (row <= f.rows) {\n css.position = 'sticky'\n css.top = `${\n HEAD_HEIGHT +\n rows.value\n .filter((r) => r.row < row)\n .reduce((n, r) => n + r.height, 0)\n }px`\n css.zIndex = 2\n }\n if (col <= f.cols) {\n css.position = 'sticky'\n css.left = `${\n ROW_HEAD_WIDTH +\n columns.value\n .filter((c) => c.col < col)\n .reduce((n, c) => n + c.width, 0)\n }px`\n css.zIndex = row <= f.rows ? 3 : 2\n }\n return css\n }\n // #endregion\n\n // #region selection\n type At = { row: number; col: number }\n const anchor = ref<At>({ row: 1, col: 1 })\n const focus = ref<At>({ row: 1, col: 1 })\n watch(sheet, () => {\n anchor.value = { row: 1, col: 1 }\n focus.value = { row: 1, col: 1 }\n })\n const range = computed(() => ({\n r1: Math.min(anchor.value.row, focus.value.row),\n r2: Math.max(anchor.value.row, focus.value.row),\n c1: Math.min(anchor.value.col, focus.value.col),\n c2: Math.max(anchor.value.col, focus.value.col),\n }))\n const inRange = (row: number, col: number) =>\n row >= range.value.r1 &&\n row <= range.value.r2 &&\n col >= range.value.c1 &&\n col <= range.value.c2\n const isFocus = (row: number, col: number) =>\n focus.value.row === row && focus.value.col === col\n /**\n * What a row draws of the selection. A row is drawn again only when\n * this, its sheet, the columns or the language of the numbers change: a\n * sheet of thousands of cells drew them all at each step of a drag,\n * seconds per selection.\n */\n const rowSelection = (row: number) =>\n row >= range.value.r1 && row <= range.value.r2\n ? `${range.value.c1}:${range.value.c2}:${\n focus.value.row === row ? focus.value.col : 0\n }`\n : ''\n\n const dragging = ref(false)\n const pick = (row: number, col: number, event: MouseEvent) => {\n // The click keeps its default off (no text selection while dragging),\n // so the grid takes the keyboard here.\n scrollEl.value?.focus({ preventScroll: true })\n focus.value = { row, col }\n if (!event.shiftKey) {\n anchor.value = { row, col }\n }\n dragging.value = true\n }\n const extend = (row: number, col: number) => {\n if (dragging.value) {\n focus.value = { row, col }\n }\n }\n\n const move = (event: KeyboardEvent) => {\n const steps: Record<string, [number, number]> = {\n ArrowUp: [-1, 0],\n ArrowDown: [1, 0],\n ArrowLeft: [0, -1],\n ArrowRight: [0, 1],\n Enter: [1, 0],\n Tab: [0, 1],\n }\n const step = steps[event.key]\n if (!step) {\n return\n }\n event.preventDefault()\n const rowList = rows.value.map((r) => r.row)\n const colList = columns.value.map((c) => c.col)\n const ownerOf = (at: At) =>\n covered.value.get(`${at.row},${at.col}`) ?? at\n // As in Excel, a merge is one cell: the step goes past the cells it\n // covers, and a step into one lands on the cell that draws it.\n const start = ownerOf(focus.value)\n let r = rowList.indexOf(focus.value.row)\n let c = colList.indexOf(focus.value.col)\n let next = start\n for (;;) {\n const nr = Math.min(rowList.length - 1, Math.max(0, r + step[0]))\n const nc = Math.min(colList.length - 1, Math.max(0, c + step[1]))\n if (nr === r && nc === c) {\n break\n }\n r = nr\n c = nc\n next = ownerOf({ row: rowList[r], col: colList[c] })\n if (next.row !== start.row || next.col !== start.col) {\n break\n }\n }\n focus.value = next\n if (!event.shiftKey) {\n anchor.value = next\n }\n nextTick(() =>\n scrollEl.value\n ?.querySelector('[data-focus]')\n ?.scrollIntoView({ block: 'nearest', inline: 'nearest' }),\n )\n }\n\n const focusCell = computed(() => cellAt(focus.value.row, focus.value.col))\n /** Count, average and sum of a range, as Excel's status bar shows them. */\n const stats = computed(() => {\n const { r1, r2, c1, c2 } = range.value\n if (r1 === r2 && c1 === c2) {\n return undefined\n }\n let count = 0\n let sum = 0\n let numbers = 0\n let first: SpreadsheetPreviewCell | undefined\n for (let r = r1; r <= r2; r++) {\n for (let c = c1; c <= c2; c++) {\n const cell = cellAt(r, c)\n if (!cell || (cell.value === undefined && !cell.missing)) {\n continue\n }\n count++\n if (typeof cell.value === 'number') {\n sum += cell.value\n numbers++\n first ??= cell\n }\n }\n }\n if (!count) {\n return undefined\n }\n return {\n count,\n sum: first ? numberText(first, sum) : undefined,\n // One number among text is still an average, as in Excel\n average: first ? numberText(first, sum / numbers) : undefined,\n }\n })\n // #endregion\n\n // #region zoom\n const zoomBy = (step: number) => {\n zoom.value = Math.min(\n 2,\n Math.max(0.5, Math.round((zoom.value + step) * 10) / 10),\n )\n }\n // #endregion\n</script>\n\n<template>\n <div class=\"pk-spreadsheet-preview\">\n <div class=\"pk-spreadsheet-preview__bar\">\n <span\n class=\"pk-spreadsheet-preview__ref\"\n :aria-label=\"$t('chatFilePreview.cell')\">\n {{ letters(focus.col) }}{{ focus.row }}\n </span>\n <span class=\"pk-spreadsheet-preview__fx\" aria-hidden=\"true\"\n >fx</span\n >\n <output\n class=\"pk-spreadsheet-preview__formula\"\n :aria-label=\"$t('chatFilePreview.formulaBar')\">\n {{ barText(focusCell) }}\n </output>\n </div>\n <div\n ref=\"scrollEl\"\n class=\"pk-spreadsheet-preview__scroll\"\n tabindex=\"0\"\n role=\"grid\"\n :aria-label=\"sheet?.name\"\n @keydown=\"move\"\n @mouseup=\"dragging = false\"\n @mouseleave=\"dragging = false\">\n <table\n v-if=\"sheet\"\n class=\"pk-spreadsheet-preview__grid\"\n :class=\"{\n 'pk-spreadsheet-preview__grid--lines': sheet.gridlines,\n }\"\n :style=\"{ zoom, width: `${gridWidth}px` }\">\n <colgroup>\n <col :style=\"{ width: `${ROW_HEAD_WIDTH}px` }\" />\n <col\n v-for=\"c in columns\"\n :key=\"c.col\"\n :style=\"{ width: `${c.width}px` }\" />\n </colgroup>\n <thead>\n <tr :style=\"{ height: `${HEAD_HEIGHT}px` }\">\n <th class=\"pk-spreadsheet-preview__corner\" />\n <th\n v-for=\"c in columns\"\n :key=\"c.col\"\n scope=\"col\"\n class=\"pk-spreadsheet-preview__head\"\n :class=\"{\n 'pk-spreadsheet-preview__head--current':\n c.col >= range.c1 && c.col <= range.c2,\n }\">\n {{ letters(c.col) }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n v-for=\"r in rows\"\n :key=\"r.row\"\n v-memo=\"[\n r,\n sheet,\n columnsKey,\n locale,\n rowSelection(r.row),\n ]\"\n :style=\"{ height: `${r.height}px` }\">\n <th\n scope=\"row\"\n class=\"pk-spreadsheet-preview__row\"\n :class=\"{\n 'pk-spreadsheet-preview__row--current':\n r.row >= range.r1 && r.row <= range.r2,\n }\"\n :style=\"\n sheet.frozen && r.row <= sheet.frozen.rows\n ? {\n ...frozenCss(r.row, 0),\n left: 0,\n zIndex: 4,\n }\n : undefined\n \">\n {{ r.row }}\n </th>\n <template v-for=\"c in columns\" :key=\"c.col\">\n <td\n v-if=\"!covered.has(`${r.row},${c.col}`)\"\n :rowspan=\"shownSpan(r.row, c.col)?.rows\"\n :colspan=\"shownSpan(r.row, c.col)?.cols\"\n class=\"pk-spreadsheet-preview__cell\"\n :class=\"{\n 'pk-spreadsheet-preview__cell--range':\n inRange(r.row, c.col) &&\n !isFocus(r.row, c.col),\n 'pk-spreadsheet-preview__cell--missing':\n cellAt(r.row, c.col)?.missing,\n }\"\n :style=\"\n cellCss(cellAt(r.row, c.col), r.row, c.col)\n \"\n :data-focus=\"\n isFocus(r.row, c.col) ? '' : undefined\n \"\n :title=\"\n cellAt(r.row, c.col)?.missing\n ? $t('chatFilePreview.missingValue')\n : undefined\n \"\n @mousedown.prevent=\"pick(r.row, c.col, $event)\"\n @mouseenter=\"extend(r.row, c.col)\">\n {{ textOf(cellAt(r.row, c.col)) }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <p\n v-if=\"sheet && (sheet.moreRows || sheet.moreColumns)\"\n class=\"pk-spreadsheet-preview__more\">\n <template v-if=\"sheet.moreRows\">\n {{ $t('chatFilePreview.moreRows', sheet.moreRows) }}\n </template>\n <template v-if=\"sheet.moreColumns\">\n {{ $t('chatFilePreview.moreColumns', sheet.moreColumns) }}\n </template>\n </p>\n </div>\n <nav\n class=\"pk-spreadsheet-preview__sheets\"\n :aria-label=\"$t('chatFilePreview.sheets')\">\n <button\n v-for=\"(s, i) in preview.sheets\"\n :key=\"s.name\"\n type=\"button\"\n class=\"pk-spreadsheet-preview__sheet\"\n :aria-current=\"i === active ? 'page' : undefined\"\n @click=\"active = i\">\n {{ s.name }}\n </button>\n </nav>\n <div class=\"pk-spreadsheet-preview__status\">\n <p class=\"pk-spreadsheet-preview__info\">\n <span\n v-if=\"preview.staleFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.staleFormulas')\">\n {{ $t('chatFilePreview.staleFormulas') }}\n </span>\n <span\n v-else-if=\"preview.computedFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.computedFormulas')\">\n {{ $t('chatFilePreview.computedFormulas') }}\n </span>\n <span v-if=\"stats\" class=\"pk-spreadsheet-preview__stats\">\n <span\n v-if=\"stats.average\"\n class=\"pk-spreadsheet-preview__average\">\n {{ $t('chatFilePreview.average') }} {{ stats.average }}\n </span>\n <span>\n {{ $t('chatFilePreview.count') }} {{ stats.count }}\n </span>\n <span v-if=\"stats.sum\">\n {{ $t('chatFilePreview.sum') }} {{ stats.sum }}\n </span>\n </span>\n </p>\n <div class=\"pk-spreadsheet-preview__zoom\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.5\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-spreadsheet-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-spreadsheet-preview {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n // Excel's green marks the active cell, its column and row and the\n // current sheet, as in Excel (decided 2026-10-29). The cells keep\n // their paper in both themes; the headers lighten it on the dark one.\n --pk-spreadsheet-green: #217346;\n --pk-spreadsheet-green-head: #217346;\n\n // The formula bar: the cell, fx and its content, as in Excel\n &__bar {\n display: flex;\n align-items: stretch;\n min-height: var(--spacing-40);\n border-bottom: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n font-size: var(--text-14);\n }\n\n &__ref {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n width: var(--spacing-96);\n padding: 0 var(--spacing-12);\n box-sizing: border-box;\n border-right: var(--border) solid var(--color-surface-3);\n font-variant-numeric: tabular-nums;\n }\n\n &__fx {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-40);\n border-right: var(--border) solid var(--color-surface-3);\n color: var(--color-word-3);\n font-family: Georgia, serif;\n font-style: italic;\n }\n\n &__formula {\n display: flex;\n flex: 1;\n align-items: center;\n min-width: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n // The grid scrolls both ways; its headers stay\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n background-color: #fff;\n outline: none;\n cursor: cell;\n\n &:focus-visible {\n box-shadow: inset 0 0 0 var(--spacing-2)\n var(--input-focus-color);\n }\n }\n\n &__grid {\n border-collapse: collapse;\n table-layout: fixed;\n color: #000;\n font-family: Calibri, Carlito, 'Segoe UI', Arial, sans-serif;\n font-size: 11pt;\n user-select: none;\n\n td {\n overflow: hidden;\n max-width: 0;\n padding: 0 var(--spacing-4);\n background-color: #fff;\n line-height: 1.2;\n text-overflow: clip;\n }\n\n &--lines td {\n border: var(--border) solid #e1e1e1;\n }\n }\n\n // The letters and the numbers follow the theme, the cells do not\n &__corner,\n &__head,\n &__row {\n position: sticky;\n z-index: 1;\n border: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-3);\n font-family: var(--font-family-sans);\n font-size: var(--text-12);\n font-weight: var(--font-normal);\n text-align: center;\n }\n\n // The letters sit in the middle of their row, room above and below\n &__corner,\n &__head {\n top: 0;\n padding: var(--spacing-4) var(--spacing-4) var(--spacing-2);\n line-height: 1;\n vertical-align: middle;\n }\n\n &__row {\n vertical-align: middle;\n }\n\n &__corner {\n left: 0;\n z-index: 5;\n }\n\n &__row {\n left: 0;\n padding: 0 var(--spacing-4);\n font-variant-numeric: tabular-nums;\n }\n\n // Where the selection is, as Excel shows it: one step of surface,\n // and the letter and a thin line in its green\n &__head--current {\n background-color: var(--color-surface-2);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__row--current {\n background-color: var(--color-surface-2);\n box-shadow: inset calc(var(--spacing-2) * -1) 0 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__cell[data-focus] {\n outline: var(--spacing-2) solid var(--pk-spreadsheet-green);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n\n &__cell--range {\n box-shadow: inset 0 0 0 100vmax rgb(31 29 43 / 8%);\n }\n\n &__cell--missing {\n color: #6b6880;\n }\n\n &__more {\n position: sticky;\n left: 0;\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n color: #6b6880;\n font-size: var(--text-12);\n }\n\n // The sheets at the bottom, as Excel draws its tabs, and the status\n // bar below them: two rows, as in Excel, so the sums of a selection\n // never push the sheets or the note out of a narrow frame\n &__sheets {\n display: flex;\n flex-shrink: 0;\n min-height: var(--spacing-32);\n overflow-x: auto;\n padding-left: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n\n @media (pointer: coarse) {\n min-height: var(--spacing-40);\n }\n }\n\n &__status {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n min-height: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n font-size: var(--text-12);\n }\n\n &__sheet {\n flex-shrink: 0;\n padding: 0 var(--spacing-16);\n border: 0;\n border-right: var(--border) solid var(--color-surface-3);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-12);\n white-space: nowrap;\n cursor: pointer;\n\n &:first-child {\n border-left: var(--border) solid var(--color-surface-3);\n }\n\n &:hover {\n background-color: var(--color-surface-2);\n }\n\n &[aria-current='page'] {\n background-color: var(--color-surface);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-semibold);\n }\n }\n\n // The note on the left, as Excel's messages, the sums on the right:\n // the note gives way to them\n &__info {\n display: flex;\n flex: 1;\n align-items: center;\n gap: var(--spacing-16);\n min-width: 0;\n margin: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__note {\n min-width: 0;\n overflow: hidden;\n color: var(--color-word-3);\n text-overflow: ellipsis;\n }\n\n &__stats {\n display: flex;\n flex-shrink: 0;\n gap: var(--spacing-12);\n margin-left: auto;\n }\n\n // A phone keeps the count and the sum of a selection\n @container (width < 26rem) {\n &__average {\n display: none;\n }\n }\n\n &__zoom {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n gap: var(--spacing-2);\n padding-right: var(--spacing-8);\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n\n // On the dark headers Excel's green reads too dark: a lighter step of it\n @media (prefers-color-scheme: dark) {\n :where(:host, :root, .theme):not(.theme--light)\n .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n }\n\n :where(.theme.theme--dark) .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n</style>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { WordPreviewRun } from 'models'\n import { wordFontStack, type WordPreviewMode } from './utils'\n\n /**\n * The runs of a paragraph or a cell of a Word document in the viewer, as\n * text with the look the document gives them: font, size, color,\n * highlight, bold, italic, underline, capitals. With the revisions in\n * sight, a tracked change is struck where words went and underlined\n * where they came, its author said on hover; as if accepted or as before\n * them, the changed text is plain. An image is a placeholder.\n */\n const props = defineProps<{\n runs: WordPreviewRun[]\n mode?: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** The runs the mode keeps: a deletion is gone once accepted. */\n const shown = computed(() =>\n props.runs.filter((run) =>\n props.mode === 'accepted'\n ? run.change !== 'deleted'\n : props.mode === 'original'\n ? run.change !== 'inserted'\n : true,\n ),\n )\n const marked = computed(() => !props.mode || props.mode === 'markup')\n\n const cssOf = (run: WordPreviewRun): CSSProperties => {\n const css: CSSProperties = {}\n if (run.font) {\n css.fontFamily = wordFontStack(run.font)\n }\n if (run.size) {\n css.fontSize = `${run.size}pt`\n }\n if (run.color) {\n css.color = run.color\n }\n if (run.highlight) {\n css.backgroundColor = run.highlight\n }\n if (run.bold) {\n css.fontWeight = 700\n }\n if (run.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n run.underline ? 'underline' : '',\n run.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (run.caps) {\n css.textTransform = 'uppercase'\n }\n if (run.vertAlign) {\n css.verticalAlign = run.vertAlign\n css.fontSize = `${(run.size ?? 11) * 0.65}pt`\n }\n return css\n }\n\n /** A tracked change keeps its mark over the run's own lines. */\n const changeCss = (run: WordPreviewRun): CSSProperties => {\n const css = cssOf(run)\n const lines = new Set(\n String(css.textDecoration ?? '')\n .split(' ')\n .filter(Boolean),\n )\n lines.add(run.change === 'deleted' ? 'line-through' : 'underline')\n return { ...css, textDecoration: [...lines].join(' ') }\n }\n\n const titleOf = (run: WordPreviewRun) =>\n run.author\n ? $t('chatFilePreview.revisionBy', { author: run.author })\n : undefined\n</script>\n\n<template>\n <!-- Each text sits against its tags: the block keeps whitespace\n (pre-wrap), so a line break inside a tag would draw a space in the\n middle of a word split across runs. -->\n <template v-for=\"(run, k) in shown\" :key=\"k\">\n <span v-if=\"run.image\" class=\"pk-word-preview__image\">{{\n $t('chatFilePreview.image')\n }}</span>\n <del\n v-else-if=\"marked && run.change === 'deleted'\"\n class=\"pk-word-preview__removed\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</del\n >\n <ins\n v-else-if=\"marked && run.change === 'inserted'\"\n class=\"pk-word-preview__added\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</ins\n >\n <span v-else :style=\"cssOf(run)\">{{ run.text }}</span>\n </template>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { WordPreviewRun } from 'models'\n import { wordFontStack, type WordPreviewMode } from './utils'\n\n /**\n * The runs of a paragraph or a cell of a Word document in the viewer, as\n * text with the look the document gives them: font, size, color,\n * highlight, bold, italic, underline, capitals. With the revisions in\n * sight, a tracked change is struck where words went and underlined\n * where they came, its author said on hover; as if accepted or as before\n * them, the changed text is plain. An image is a placeholder.\n */\n const props = defineProps<{\n runs: WordPreviewRun[]\n mode?: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** The runs the mode keeps: a deletion is gone once accepted. */\n const shown = computed(() =>\n props.runs.filter((run) =>\n props.mode === 'accepted'\n ? run.change !== 'deleted'\n : props.mode === 'original'\n ? run.change !== 'inserted'\n : true,\n ),\n )\n const marked = computed(() => !props.mode || props.mode === 'markup')\n\n const cssOf = (run: WordPreviewRun): CSSProperties => {\n const css: CSSProperties = {}\n if (run.font) {\n css.fontFamily = wordFontStack(run.font)\n }\n if (run.size) {\n css.fontSize = `${run.size}pt`\n }\n if (run.color) {\n css.color = run.color\n }\n if (run.highlight) {\n css.backgroundColor = run.highlight\n }\n if (run.bold) {\n css.fontWeight = 700\n }\n if (run.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n run.underline ? 'underline' : '',\n run.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (run.caps) {\n css.textTransform = 'uppercase'\n }\n if (run.vertAlign) {\n css.verticalAlign = run.vertAlign\n css.fontSize = `${(run.size ?? 11) * 0.65}pt`\n }\n return css\n }\n\n /** A tracked change keeps its mark over the run's own lines. */\n const changeCss = (run: WordPreviewRun): CSSProperties => {\n const css = cssOf(run)\n const lines = new Set(\n String(css.textDecoration ?? '')\n .split(' ')\n .filter(Boolean),\n )\n lines.add(run.change === 'deleted' ? 'line-through' : 'underline')\n return { ...css, textDecoration: [...lines].join(' ') }\n }\n\n const titleOf = (run: WordPreviewRun) =>\n run.author\n ? $t('chatFilePreview.revisionBy', { author: run.author })\n : undefined\n</script>\n\n<template>\n <!-- Each text sits against its tags: the block keeps whitespace\n (pre-wrap), so a line break inside a tag would draw a space in the\n middle of a word split across runs. -->\n <template v-for=\"(run, k) in shown\" :key=\"k\">\n <span v-if=\"run.image\" class=\"pk-word-preview__image\">{{\n $t('chatFilePreview.image')\n }}</span>\n <del\n v-else-if=\"marked && run.change === 'deleted'\"\n class=\"pk-word-preview__removed\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</del\n >\n <ins\n v-else-if=\"marked && run.change === 'inserted'\"\n class=\"pk-word-preview__added\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</ins\n >\n <span v-else :style=\"cssOf(run)\">{{ run.text }}</span>\n </template>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import type { WordPreviewBlock } from 'models'\n import PkWordPreviewRuns from './PkWordPreviewRuns.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * One piece of a Word document's flow in the viewer: a paragraph or a\n * heading laid out as its style says (alignment, indents, spacing, line\n * height, the number of a list item in its hanging indent), or one row of\n * a table, so a table can break between pages as Word breaks it. A\n * paragraph with a tracked change carries Word's bar in the margin.\n */\n const props = defineProps<{\n block: WordPreviewBlock\n /** The row of a table this piece draws. */\n row?: number\n mode: WordPreviewMode\n }>()\n\n const paragraphCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const s = props.block.style ?? {}\n return {\n textAlign: s.align,\n paddingLeft: s.indentLeft ? `${s.indentLeft}pt` : undefined,\n paddingRight: s.indentRight ? `${s.indentRight}pt` : undefined,\n textIndent: s.firstLine ? `${s.firstLine}pt` : undefined,\n // Padding, so each block is measured with its spaces. Between two\n // paragraphs Word keeps the larger space, not both: the preview\n // already took the space after from the next one's space before.\n paddingTop: s.spaceBefore ? `${s.spaceBefore}pt` : undefined,\n paddingBottom: s.spaceAfter ? `${s.spaceAfter}pt` : undefined,\n // A multiple of Word's single line for the document's font,\n // which the viewer sets as `--pk-word-line`; \"At least\" is that\n // line or the points, the higher.\n lineHeight: s.lineExact\n ? `${s.lineExact}pt`\n : s.lineAtLeast\n ? `max(calc(var(--pk-word-line, 1.17) * 1em), ${s.lineAtLeast}pt)`\n : `calc(var(--pk-word-line, 1.17) * ${s.lineHeight ?? 1})`,\n backgroundColor: s.shading,\n }\n })\n\n /** The number hangs in the indent, the text starts where Word puts it. */\n const labelCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const hanging = -(props.block.style?.firstLine ?? 0)\n return hanging > 0\n ? { minWidth: `${hanging}pt` }\n : { paddingRight: '6pt' }\n })\n\n const changed = computed(\n () =>\n props.mode === 'markup' &&\n props.block.kind !== 'table' &&\n props.block.runs.some((r) => r.change),\n )\n\n const tableRow = computed(() =>\n props.block.kind === 'table' && props.row !== undefined\n ? props.block.rows[props.row]\n : undefined,\n )\n const columns = computed(() => {\n if (props.block.kind !== 'table') {\n return []\n }\n const widths = props.block.widths ?? []\n const total = widths.reduce((a, b) => a + b, 0)\n return total ? widths.map((w) => `${(w / total) * 100}%`) : []\n })\n const rowChanged = computed(\n () =>\n props.mode === 'markup' &&\n !!tableRow.value?.some((cell) => cell.runs.some((r) => r.change)),\n )\n</script>\n\n<template>\n <table\n v-if=\"block.kind === 'table' && tableRow\"\n class=\"pk-word-preview__table\"\n :class=\"{\n 'pk-word-preview__table--lines': block.borders,\n 'pk-word-preview__table--next': row !== 0,\n 'pk-word-preview__changed': rowChanged,\n }\">\n <colgroup v-if=\"columns.length\">\n <col v-for=\"(w, i) in columns\" :key=\"i\" :style=\"{ width: w }\" />\n </colgroup>\n <tbody>\n <tr>\n <td\n v-for=\"(cell, c) in tableRow\"\n :key=\"c\"\n :colspan=\"cell.span\"\n :style=\"{\n backgroundColor: cell.fill,\n textAlign: cell.align,\n }\">\n <PkWordPreviewRuns :runs=\"cell.runs\" :mode />\n </td>\n </tr>\n </tbody>\n </table>\n <div\n v-else-if=\"block.kind !== 'table'\"\n class=\"pk-word-preview__block\"\n :class=\"{ 'pk-word-preview__changed': changed }\"\n :role=\"block.kind === 'heading' ? 'heading' : undefined\"\n :aria-level=\"\n block.kind === 'heading' ? Math.max(1, block.level) : undefined\n \"\n :style=\"paragraphCss\">\n <span\n v-if=\"block.label\"\n class=\"pk-word-preview__label\"\n :style=\"labelCss\"\n >{{ block.label }}</span\n ><PkWordPreviewRuns :runs=\"block.runs\" :mode />\n <!-- An empty paragraph of the document is a blank line, as in Word -->\n <br v-if=\"!block.label && !block.runs.length\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import type { WordPreviewBlock } from 'models'\n import PkWordPreviewRuns from './PkWordPreviewRuns.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * One piece of a Word document's flow in the viewer: a paragraph or a\n * heading laid out as its style says (alignment, indents, spacing, line\n * height, the number of a list item in its hanging indent), or one row of\n * a table, so a table can break between pages as Word breaks it. A\n * paragraph with a tracked change carries Word's bar in the margin.\n */\n const props = defineProps<{\n block: WordPreviewBlock\n /** The row of a table this piece draws. */\n row?: number\n mode: WordPreviewMode\n }>()\n\n const paragraphCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const s = props.block.style ?? {}\n return {\n textAlign: s.align,\n paddingLeft: s.indentLeft ? `${s.indentLeft}pt` : undefined,\n paddingRight: s.indentRight ? `${s.indentRight}pt` : undefined,\n textIndent: s.firstLine ? `${s.firstLine}pt` : undefined,\n // Padding, so each block is measured with its spaces. Between two\n // paragraphs Word keeps the larger space, not both: the preview\n // already took the space after from the next one's space before.\n paddingTop: s.spaceBefore ? `${s.spaceBefore}pt` : undefined,\n paddingBottom: s.spaceAfter ? `${s.spaceAfter}pt` : undefined,\n // A multiple of Word's single line for the document's font,\n // which the viewer sets as `--pk-word-line`; \"At least\" is that\n // line or the points, the higher.\n lineHeight: s.lineExact\n ? `${s.lineExact}pt`\n : s.lineAtLeast\n ? `max(calc(var(--pk-word-line, 1.17) * 1em), ${s.lineAtLeast}pt)`\n : `calc(var(--pk-word-line, 1.17) * ${s.lineHeight ?? 1})`,\n backgroundColor: s.shading,\n }\n })\n\n /** The number hangs in the indent, the text starts where Word puts it. */\n const labelCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const hanging = -(props.block.style?.firstLine ?? 0)\n return hanging > 0\n ? { minWidth: `${hanging}pt` }\n : { paddingRight: '6pt' }\n })\n\n const changed = computed(\n () =>\n props.mode === 'markup' &&\n props.block.kind !== 'table' &&\n props.block.runs.some((r) => r.change),\n )\n\n const tableRow = computed(() =>\n props.block.kind === 'table' && props.row !== undefined\n ? props.block.rows[props.row]\n : undefined,\n )\n const columns = computed(() => {\n if (props.block.kind !== 'table') {\n return []\n }\n const widths = props.block.widths ?? []\n const total = widths.reduce((a, b) => a + b, 0)\n return total ? widths.map((w) => `${(w / total) * 100}%`) : []\n })\n const rowChanged = computed(\n () =>\n props.mode === 'markup' &&\n !!tableRow.value?.some((cell) => cell.runs.some((r) => r.change)),\n )\n</script>\n\n<template>\n <table\n v-if=\"block.kind === 'table' && tableRow\"\n class=\"pk-word-preview__table\"\n :class=\"{\n 'pk-word-preview__table--lines': block.borders,\n 'pk-word-preview__table--next': row !== 0,\n 'pk-word-preview__changed': rowChanged,\n }\">\n <colgroup v-if=\"columns.length\">\n <col v-for=\"(w, i) in columns\" :key=\"i\" :style=\"{ width: w }\" />\n </colgroup>\n <tbody>\n <tr>\n <td\n v-for=\"(cell, c) in tableRow\"\n :key=\"c\"\n :colspan=\"cell.span\"\n :style=\"{\n backgroundColor: cell.fill,\n textAlign: cell.align,\n }\">\n <PkWordPreviewRuns :runs=\"cell.runs\" :mode />\n </td>\n </tr>\n </tbody>\n </table>\n <div\n v-else-if=\"block.kind !== 'table'\"\n class=\"pk-word-preview__block\"\n :class=\"{ 'pk-word-preview__changed': changed }\"\n :role=\"block.kind === 'heading' ? 'heading' : undefined\"\n :aria-level=\"\n block.kind === 'heading' ? Math.max(1, block.level) : undefined\n \"\n :style=\"paragraphCss\">\n <span\n v-if=\"block.label\"\n class=\"pk-word-preview__label\"\n :style=\"labelCss\"\n >{{ block.label }}</span\n ><PkWordPreviewRuns :runs=\"block.runs\" :mode />\n <!-- An empty paragraph of the document is a blank line, as in Word -->\n <br v-if=\"!block.label && !block.runs.length\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type { WordPreview, WordPreviewRun } from 'models'\n import PkWordPreviewBlock from './PkWordPreviewBlock.vue'\n import {\n wordFontStack,\n wordLineFactor,\n type WordPreviewMode,\n } from './utils'\n\n /**\n * A Word document stored in the chat, drawn in pages as Word draws it\n * (spec `chat-office-files.md`, F6, item 3, and the viewer of its\n * follow-ups): white pages of the document's size and margins on a grey\n * ground, its fonts and its layout. The pages are computed here: each\n * paragraph and each table row is measured at the width of the page and\n * placed on the next page when it does not fit, or where the document\n * breaks the page, so they come close to Word's without matching them.\n * Below 640 pixels the text flows at the width of the screen. A side\n * panel lists the headings and the tracked changes, and leads to them.\n * The pages keep their white in the dark theme. Framed by\n * `PkFilePreview`.\n */\n const props = defineProps<{\n preview: WordPreview\n mode: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** Pixels in a point. */\n const PX = 96 / 72\n\n // #region the flow: paragraphs and table rows\n const kept = (runs: WordPreviewRun[]) =>\n runs.filter((r) =>\n props.mode === 'accepted'\n ? r.change !== 'deleted'\n : props.mode === 'original'\n ? r.change !== 'inserted'\n : true,\n )\n const hasText = (runs: WordPreviewRun[]) =>\n runs.some((r) => r.image || r.text.trim())\n\n type Item = {\n key: string\n block: number\n row?: number\n breakBefore: boolean\n }\n /**\n * What the pages hold, in order. A paragraph or a table row a mode\n * empties is gone (a row inserted, as the original); one empty in the\n * document stays, a blank line as in Word.\n */\n const items = computed(() => {\n const out: Item[] = []\n props.preview.blocks.forEach((block, b) => {\n if (block.kind === 'table') {\n let first = true\n block.rows.forEach((cells, r) => {\n const filled = cells.some((cell) => cell.runs.length)\n if (\n filled &&\n !cells.some((cell) => hasText(kept(cell.runs)))\n ) {\n return\n }\n out.push({\n key: `${b}:${r}`,\n block: b,\n row: r,\n breakBefore: first && !!block.pageBreakBefore,\n })\n first = false\n })\n } else if (!block.runs.length || hasText(kept(block.runs))) {\n out.push({\n key: `${b}`,\n block: b,\n breakBefore: !!block.style?.pageBreakBefore,\n })\n }\n })\n return out\n })\n // #endregion\n\n // #region pages\n const rootEl = useTemplateRef<HTMLElement>('rootEl')\n const scrollEl = useTemplateRef<HTMLElement>('scrollEl')\n const measureEl = useTemplateRef<HTMLElement>('measureEl')\n const { width } = useElementSize(rootEl)\n const { width: scrollWidth } = useElementSize(scrollEl)\n const paged = computed(() => width.value === 0 || width.value >= 640)\n const wide = computed(() => width.value >= 1000)\n\n const page = computed(() => props.preview.page)\n const textCss = computed((): CSSProperties => ({\n fontFamily: wordFontStack(props.preview.defaults.font),\n fontSize: `${props.preview.defaults.size}pt`,\n color: props.preview.defaults.color ?? '#000000',\n '--pk-word-line': wordLineFactor(props.preview.defaults.font),\n }))\n const pageCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${page.value.width}pt`,\n minHeight: `${page.value.height}pt`,\n padding: `${page.value.margins.top}pt ${page.value.margins.right}pt ${page.value.margins.bottom}pt ${page.value.margins.left}pt`,\n }))\n const measureCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${\n page.value.width -\n page.value.margins.left -\n page.value.margins.right\n }pt`,\n }))\n\n const heights = ref<number[]>([])\n const measure = async () => {\n await nextTick()\n const els =\n measureEl.value?.querySelectorAll<HTMLElement>('[data-item]')\n heights.value = [...(els ?? [])].map(\n (el) => el.getBoundingClientRect().height,\n )\n }\n watch([items, paged], measure, { flush: 'post' })\n onMounted(() => {\n measure()\n // The document's fonts change the lines once they arrive.\n document.fonts?.ready.then(measure)\n })\n\n /** The items of each page, by their index in `items`. */\n const pages = computed(() => {\n const all = items.value.map((_, i) => i)\n if (!paged.value || heights.value.length !== items.value.length) {\n return [all]\n }\n const room =\n (page.value.height -\n page.value.margins.top -\n page.value.margins.bottom) *\n PX\n const out: number[][] = [[]]\n let used = 0\n items.value.forEach((item, i) => {\n const h = heights.value[i]\n if (\n out[out.length - 1].length &&\n (item.breakBefore || used + h > room)\n ) {\n out.push([])\n used = 0\n }\n out[out.length - 1].push(i)\n used += h\n })\n return out\n })\n // #endregion\n\n // #region zoom and the page in view\n // Models, so the zoom stays when the viewer moves between the panel and\n // the dialog (`PkChatbotViewChat` keeps it).\n const fit = defineModel<boolean>('fit', { default: true })\n const manual = defineModel<number>('zoom', { default: 1 })\n const zoom = computed(() =>\n fit.value\n ? Math.min(\n 1.25,\n Math.max(\n 0.3,\n (scrollWidth.value - 48) / (page.value.width * PX),\n ),\n )\n : manual.value,\n )\n const zoomBy = (step: number) => {\n manual.value = Math.min(\n 2,\n Math.max(0.3, Math.round((zoom.value + step) * 10) / 10),\n )\n fit.value = false\n }\n\n const currentPage = ref(0)\n const currentHeading = ref<string>()\n /**\n * The page and the heading being read. Pages and headings go down in\n * order, so the search stops at the first one below the line; and it runs\n * once a frame, however many scroll events come.\n */\n const locate = () => {\n const box = scrollEl.value?.getBoundingClientRect()\n if (!box) {\n return\n }\n const pageEls = scrollEl.value?.querySelectorAll('[data-page]') ?? []\n let n = 0\n for (const [i, el] of [...pageEls].entries()) {\n if (el.getBoundingClientRect().top - box.top > box.height / 3) {\n break\n }\n n = i\n }\n currentPage.value = n\n let heading: string | undefined\n for (const h of headings.value) {\n const el = scrollEl.value?.querySelector(`[data-key=\"${h.key}\"]`)\n if (!el) {\n continue\n }\n if (el.getBoundingClientRect().top - box.top > 48) {\n break\n }\n heading = h.key\n }\n currentHeading.value = heading ?? headings.value[0]?.key\n }\n let frame = 0\n const onScroll = () => {\n frame ||= requestAnimationFrame(() => {\n frame = 0\n locate()\n })\n }\n onBeforeUnmount(() => cancelAnimationFrame(frame))\n watch(pages, () => nextTick(onScroll))\n // #endregion\n\n // #region the side panel: headings and tracked changes\n const textOf = (runs: WordPreviewRun[]) =>\n kept(runs)\n .map((r) => r.text)\n .join('')\n .replace(/\\s+/g, ' ')\n .trim()\n\n const headings = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n return block.kind === 'heading' && block.level <= 3\n ? [\n {\n key: item.key,\n level: block.level,\n text: [block.label, textOf(block.runs)]\n .filter(Boolean)\n .join(' '),\n },\n ]\n : []\n }),\n )\n\n const clip = (s: string) => (s.length > 60 ? `${s.slice(0, 60)}…` : s)\n const changes = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n const runs =\n block.kind === 'table'\n ? (block.rows[item.row ?? 0] ?? []).flatMap((c) => c.runs)\n : block.runs\n const removed = runs\n .filter((r) => r.change === 'deleted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n const added = runs\n .filter((r) => r.change === 'inserted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n return removed || added\n ? [\n {\n key: item.key,\n removed: clip(removed),\n added: clip(added),\n },\n ]\n : []\n }),\n )\n\n const tab = ref<'outline' | 'changes'>('outline')\n const sideOpen = ref(false)\n const goTo = (key: string) => {\n scrollEl.value\n ?.querySelector(`[data-key=\"${key}\"]`)\n ?.scrollIntoView({ block: 'start', behavior: 'smooth' })\n if (!wide.value) {\n sideOpen.value = false\n }\n }\n // #endregion\n\n const words = computed(\n () =>\n props.preview.blocks\n .flatMap((b) =>\n b.kind === 'table'\n ? b.rows.flat().map((c) => textOf(c.runs))\n : [textOf(b.runs)],\n )\n .join(' ')\n .split(/\\s+/)\n .filter(Boolean).length,\n )\n const authors = computed(() => props.preview.revisionAuthors.join(', '))\n</script>\n\n<template>\n <div\n ref=\"rootEl\"\n class=\"pk-word-preview\"\n :class=\"{ 'pk-word-preview--paged': paged }\">\n <aside\n v-if=\"(wide || sideOpen) && (headings.length || changes.length)\"\n class=\"pk-word-preview__side\"\n :class=\"{ 'pk-word-preview__side--over': !wide }\"\n :aria-label=\"$t('chatFilePreview.outline')\">\n <div class=\"pk-word-preview__tabs\" role=\"tablist\">\n <button\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'outline'\"\n @click=\"tab = 'outline'\">\n {{ $t('chatFilePreview.outline') }}\n </button>\n <button\n v-if=\"changes.length\"\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'changes'\"\n @click=\"tab = 'changes'\">\n {{\n $t('chatFilePreview.changes', { count: changes.length })\n }}\n </button>\n </div>\n <nav\n v-if=\"tab === 'outline' || !changes.length\"\n class=\"pk-word-preview__list\">\n <button\n v-for=\"h in headings\"\n :key=\"h.key\"\n type=\"button\"\n class=\"pk-word-preview__entry\"\n :class=\"`pk-word-preview__entry--${Math.min(h.level, 3)}`\"\n :aria-current=\"\n currentHeading === h.key ? 'location' : undefined\n \"\n @click=\"goTo(h.key)\">\n <span class=\"pk-word-preview__entry-text\">{{\n h.text\n }}</span>\n <span\n v-if=\"changes.some((c) => c.key === h.key)\"\n class=\"u-dot\" />\n </button>\n <p v-if=\"!headings.length\" class=\"pk-word-preview__none\">\n {{ $t('chatFilePreview.noHeadings') }}\n </p>\n </nav>\n <nav v-else class=\"pk-word-preview__list\">\n <button\n v-for=\"c in changes\"\n :key=\"c.key\"\n type=\"button\"\n class=\"pk-word-preview__entry pk-word-preview__entry--change\"\n @click=\"goTo(c.key)\">\n <del v-if=\"c.removed\" class=\"pk-word-preview__removed\">{{\n c.removed\n }}</del>\n <ins v-if=\"c.added\" class=\"pk-word-preview__added\">{{\n c.added\n }}</ins>\n </button>\n </nav>\n </aside>\n <div class=\"pk-word-preview__main\">\n <div\n ref=\"scrollEl\"\n class=\"pk-word-preview__scroll\"\n @scroll=\"onScroll\">\n <div\n v-if=\"paged\"\n class=\"pk-word-preview__pages\"\n :style=\"{ zoom }\">\n <article\n v-for=\"(p, n) in pages\"\n :key=\"n\"\n data-page\n class=\"pk-word-preview__page\"\n :aria-label=\"\n $t('chatFilePreview.pageOf', {\n page: n + 1,\n count: pages.length,\n })\n \"\n :style=\"pageCss\">\n <PkWordPreviewBlock\n v-for=\"i in p\"\n :key=\"items[i].key\"\n :data-key=\"items[i].key\"\n :block=\"preview.blocks[items[i].block]\"\n :row=\"items[i].row\"\n :mode />\n </article>\n </div>\n <article\n v-else\n class=\"pk-word-preview__page pk-word-preview__page--flow\"\n :style=\"textCss\">\n <PkWordPreviewBlock\n v-for=\"item in items\"\n :key=\"item.key\"\n :data-key=\"item.key\"\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </article>\n <p v-if=\"preview.truncated\" class=\"pk-word-preview__truncated\">\n {{ $t('chatFilePreview.truncated') }}\n </p>\n </div>\n <div class=\"pk-word-preview__status\">\n <span v-if=\"paged\" class=\"pk-word-preview__count\">\n {{\n $t('chatFilePreview.pageOf', {\n page: currentPage + 1,\n count: pages.length,\n })\n }}\n </span>\n <span class=\"pk-word-preview__count\">\n {{ $t('chatFilePreview.words', words) }}\n </span>\n <span\n v-if=\"mode === 'markup' && preview.revisionAuthors.length\"\n class=\"pk-word-preview__legend\">\n <span\n class=\"pk-word-preview__legend-text\"\n :title=\"$t('chatFilePreview.revisionsOf', { authors })\">\n {{ $t('chatFilePreview.revisionsOf', { authors }) }}\n </span>\n <del class=\"pk-word-preview__removed\">{{\n $t('chatFilePreview.removed')\n }}</del>\n <ins class=\"pk-word-preview__added\">{{\n $t('chatFilePreview.added')\n }}</ins>\n </span>\n <span class=\"pk-word-preview__spacer\" />\n <VvButton\n v-if=\"!wide && (headings.length || changes.length)\"\n class=\"pk-word-preview__outline-toggle\"\n modifiers=\"action-quiet\"\n icon=\"ri:list-unordered\"\n :label=\"$t('chatFilePreview.outline')\"\n :title=\"$t('chatFilePreview.outline')\"\n :aria-label=\"$t('chatFilePreview.outline')\"\n :aria-expanded=\"sideOpen\"\n @click=\"sideOpen = !sideOpen\" />\n <template v-if=\"paged\">\n <VvButton\n modifiers=\"action-quiet\"\n :label=\"$t('chatFilePreview.fitWidth')\"\n :disabled=\"fit\"\n @click=\"fit = true\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.3\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-word-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </template>\n </div>\n </div>\n <!-- Each paragraph and row at the page's width, to find its height -->\n <div\n v-if=\"paged\"\n ref=\"measureEl\"\n class=\"pk-word-preview__measure\"\n aria-hidden=\"true\"\n :style=\"measureCss\">\n <div v-for=\"item in items\" :key=\"item.key\" data-item>\n <PkWordPreviewBlock\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-word-preview {\n position: relative;\n display: flex;\n flex: 1;\n min-height: 0;\n\n // The headings and the changes, beside the pages or over them\n &__side {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-12);\n width: 16.5rem;\n flex-shrink: 0;\n padding: var(--spacing-12);\n box-sizing: border-box;\n overflow-y: auto;\n border-right: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n\n &--over {\n position: absolute;\n inset: 0 auto var(--spacing-40) 0;\n z-index: 3;\n box-shadow: var(--shadow-lg);\n }\n }\n\n &__tabs {\n display: flex;\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__tab {\n flex: 1;\n min-height: var(--spacing-40);\n border: 0;\n background: none;\n color: var(--color-word-3);\n font: inherit;\n font-size: var(--text-14);\n cursor: pointer;\n\n &[aria-selected='true'] {\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--color-word-1);\n color: var(--color-word-1);\n font-weight: var(--font-semibold);\n }\n }\n\n // One frame, hairline rows (DESIGN.md, principle 4)\n &__list {\n display: flex;\n flex-direction: column;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n overflow: hidden;\n }\n\n &__entry {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n min-height: var(--spacing-40);\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-bottom: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-14);\n text-align: start;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:last-child {\n border-bottom: 0;\n }\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n // The heading in view: surface and bar (DESIGN.md, principle 3)\n &[aria-current='location'] {\n background-color: var(--color-surface-2);\n box-shadow: inset var(--spacing-3) 0 0 var(--color-word-2);\n color: var(--color-word-1);\n font-weight: var(--font-medium);\n }\n\n &--0 {\n font-weight: var(--font-semibold);\n }\n\n &--2 {\n padding-left: var(--spacing-24);\n }\n\n &--3 {\n padding-left: var(--spacing-36);\n }\n\n &--change {\n flex-wrap: wrap;\n gap: var(--spacing-4) var(--spacing-8);\n font-size: var(--text-12);\n }\n }\n\n &__entry-text {\n flex: 1;\n min-width: 0;\n }\n\n &__none {\n margin: 0;\n padding: var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__main {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n }\n\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n padding: var(--spacing-md);\n background-color: var(--color-surface-2);\n }\n\n &__pages {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--spacing-24);\n width: max-content;\n min-width: 100%;\n }\n\n // A sheet of the document's size; white in both themes, as printed\n &__page {\n position: relative;\n box-sizing: border-box;\n background-color: #fff;\n box-shadow:\n 0 1px 3px rgb(20 14 51 / 16%),\n 0 10px 28px rgb(20 14 51 / 8%);\n line-height: var(--pk-word-line, 1.17);\n overflow-wrap: break-word;\n\n &--flow {\n width: 100%;\n padding: var(--spacing-24) var(--spacing-20);\n }\n }\n\n &__measure {\n position: absolute;\n top: 0;\n left: -100000px;\n visibility: hidden;\n pointer-events: none;\n line-height: var(--pk-word-line, 1.17);\n\n // As the page breaks a long word, or a link measures one line\n // and draws three\n overflow-wrap: break-word;\n }\n\n &__block {\n position: relative;\n margin: 0;\n\n // A tab or a line break of the document stays where Word put it\n white-space: pre-wrap;\n }\n\n &__label {\n display: inline-block;\n text-indent: 0;\n }\n\n // Word's bar in the margin beside a changed paragraph\n &__changed::before {\n content: '';\n position: absolute;\n top: 0;\n bottom: 0;\n left: -14pt;\n width: 1.5pt;\n background-color: #3f3c51;\n }\n\n &__table {\n position: relative;\n width: 100%;\n margin: 0;\n border-collapse: collapse;\n table-layout: fixed;\n\n td {\n padding: 0 5.4pt;\n vertical-align: top;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n &--lines td {\n border: 0.5pt solid #000;\n }\n\n // A row after the first: its top line is the row's above\n &--lines.pk-word-preview__table--next td {\n border-top: 0;\n }\n }\n\n // The marks of the card of an edit (PkToolChatFile.vue): the change is\n // the verdict the preview shows, the exception of DESIGN.md principle 2.\n // The base styles take the line off `del`.\n &__removed {\n color: var(--u-danger-text, #c42b3c);\n text-decoration: line-through;\n }\n\n &__added {\n color: var(--u-success-text, #178230);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n // Inside the white page the marks keep the light theme's colors\n &__page &__removed {\n color: #c42b3c;\n }\n\n &__page &__added {\n color: #178230;\n }\n\n // A word replaced: what went and what came, not run together\n &__removed + &__added {\n margin-inline-start: 0.15em;\n }\n\n &__image {\n display: inline-block;\n padding: var(--spacing-2) var(--spacing-8);\n border: var(--border) dashed #c9c8d2;\n border-radius: var(--rounded);\n color: #6b6880;\n font-size: 9pt;\n text-indent: 0;\n }\n\n &__truncated {\n margin: var(--spacing-md) 0 0;\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__status {\n display: flex;\n align-items: center;\n gap: var(--spacing-16);\n min-height: var(--spacing-40);\n padding: 0 var(--spacing-8) 0 var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n font-size: var(--text-12);\n white-space: nowrap;\n\n // Only the legend's words give way in a narrow frame\n > * {\n flex-shrink: 0;\n }\n }\n\n &__count {\n font-variant-numeric: tabular-nums;\n }\n\n &__status > &__legend {\n display: flex;\n flex-shrink: 1;\n gap: var(--spacing-8);\n min-width: 0;\n }\n\n // The words shorten, the two marks they explain stay\n &__legend-text {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n\n &__legend > &__removed,\n &__legend > &__added {\n flex-shrink: 0;\n }\n\n &__spacer {\n flex: 1;\n }\n\n // A phone keeps the outline's icon\n @container (width < 30rem) {\n &__outline-toggle .vv-button__label {\n display: none;\n }\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type { WordPreview, WordPreviewRun } from 'models'\n import PkWordPreviewBlock from './PkWordPreviewBlock.vue'\n import {\n wordFontStack,\n wordLineFactor,\n type WordPreviewMode,\n } from './utils'\n\n /**\n * A Word document stored in the chat, drawn in pages as Word draws it\n * (spec `chat-office-files.md`, F6, item 3, and the viewer of its\n * follow-ups): white pages of the document's size and margins on a grey\n * ground, its fonts and its layout. The pages are computed here: each\n * paragraph and each table row is measured at the width of the page and\n * placed on the next page when it does not fit, or where the document\n * breaks the page, so they come close to Word's without matching them.\n * Below 640 pixels the text flows at the width of the screen. A side\n * panel lists the headings and the tracked changes, and leads to them.\n * The pages keep their white in the dark theme. Framed by\n * `PkFilePreview`.\n */\n const props = defineProps<{\n preview: WordPreview\n mode: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** Pixels in a point. */\n const PX = 96 / 72\n\n // #region the flow: paragraphs and table rows\n const kept = (runs: WordPreviewRun[]) =>\n runs.filter((r) =>\n props.mode === 'accepted'\n ? r.change !== 'deleted'\n : props.mode === 'original'\n ? r.change !== 'inserted'\n : true,\n )\n const hasText = (runs: WordPreviewRun[]) =>\n runs.some((r) => r.image || r.text.trim())\n\n type Item = {\n key: string\n block: number\n row?: number\n breakBefore: boolean\n }\n /**\n * What the pages hold, in order. A paragraph or a table row a mode\n * empties is gone (a row inserted, as the original); one empty in the\n * document stays, a blank line as in Word.\n */\n const items = computed(() => {\n const out: Item[] = []\n props.preview.blocks.forEach((block, b) => {\n if (block.kind === 'table') {\n let first = true\n block.rows.forEach((cells, r) => {\n const filled = cells.some((cell) => cell.runs.length)\n if (\n filled &&\n !cells.some((cell) => hasText(kept(cell.runs)))\n ) {\n return\n }\n out.push({\n key: `${b}:${r}`,\n block: b,\n row: r,\n breakBefore: first && !!block.pageBreakBefore,\n })\n first = false\n })\n } else if (!block.runs.length || hasText(kept(block.runs))) {\n out.push({\n key: `${b}`,\n block: b,\n breakBefore: !!block.style?.pageBreakBefore,\n })\n }\n })\n return out\n })\n // #endregion\n\n // #region pages\n const rootEl = useTemplateRef<HTMLElement>('rootEl')\n const scrollEl = useTemplateRef<HTMLElement>('scrollEl')\n const measureEl = useTemplateRef<HTMLElement>('measureEl')\n const { width } = useElementSize(rootEl)\n const { width: scrollWidth } = useElementSize(scrollEl)\n const paged = computed(() => width.value === 0 || width.value >= 640)\n const wide = computed(() => width.value >= 1000)\n\n const page = computed(() => props.preview.page)\n const textCss = computed((): CSSProperties => ({\n fontFamily: wordFontStack(props.preview.defaults.font),\n fontSize: `${props.preview.defaults.size}pt`,\n color: props.preview.defaults.color ?? '#000000',\n '--pk-word-line': wordLineFactor(props.preview.defaults.font),\n }))\n const pageCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${page.value.width}pt`,\n minHeight: `${page.value.height}pt`,\n padding: `${page.value.margins.top}pt ${page.value.margins.right}pt ${page.value.margins.bottom}pt ${page.value.margins.left}pt`,\n }))\n const measureCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${\n page.value.width -\n page.value.margins.left -\n page.value.margins.right\n }pt`,\n }))\n\n const heights = ref<number[]>([])\n const measure = async () => {\n await nextTick()\n const els =\n measureEl.value?.querySelectorAll<HTMLElement>('[data-item]')\n heights.value = [...(els ?? [])].map(\n (el) => el.getBoundingClientRect().height,\n )\n }\n watch([items, paged], measure, { flush: 'post' })\n onMounted(() => {\n measure()\n // The document's fonts change the lines once they arrive.\n document.fonts?.ready.then(measure)\n })\n\n /** The items of each page, by their index in `items`. */\n const pages = computed(() => {\n const all = items.value.map((_, i) => i)\n if (!paged.value || heights.value.length !== items.value.length) {\n return [all]\n }\n const room =\n (page.value.height -\n page.value.margins.top -\n page.value.margins.bottom) *\n PX\n const out: number[][] = [[]]\n let used = 0\n items.value.forEach((item, i) => {\n const h = heights.value[i]\n if (\n out[out.length - 1].length &&\n (item.breakBefore || used + h > room)\n ) {\n out.push([])\n used = 0\n }\n out[out.length - 1].push(i)\n used += h\n })\n return out\n })\n // #endregion\n\n // #region zoom and the page in view\n // Models, so the zoom stays when the viewer moves between the panel and\n // the dialog (`PkChatbotViewChat` keeps it).\n const fit = defineModel<boolean>('fit', { default: true })\n const manual = defineModel<number>('zoom', { default: 1 })\n const zoom = computed(() =>\n fit.value\n ? Math.min(\n 1.25,\n Math.max(\n 0.3,\n (scrollWidth.value - 48) / (page.value.width * PX),\n ),\n )\n : manual.value,\n )\n const zoomBy = (step: number) => {\n manual.value = Math.min(\n 2,\n Math.max(0.3, Math.round((zoom.value + step) * 10) / 10),\n )\n fit.value = false\n }\n\n const currentPage = ref(0)\n const currentHeading = ref<string>()\n /**\n * The page and the heading being read. Pages and headings go down in\n * order, so the search stops at the first one below the line; and it runs\n * once a frame, however many scroll events come.\n */\n const locate = () => {\n const box = scrollEl.value?.getBoundingClientRect()\n if (!box) {\n return\n }\n const pageEls = scrollEl.value?.querySelectorAll('[data-page]') ?? []\n let n = 0\n for (const [i, el] of [...pageEls].entries()) {\n if (el.getBoundingClientRect().top - box.top > box.height / 3) {\n break\n }\n n = i\n }\n currentPage.value = n\n let heading: string | undefined\n for (const h of headings.value) {\n const el = scrollEl.value?.querySelector(`[data-key=\"${h.key}\"]`)\n if (!el) {\n continue\n }\n if (el.getBoundingClientRect().top - box.top > 48) {\n break\n }\n heading = h.key\n }\n currentHeading.value = heading ?? headings.value[0]?.key\n }\n let frame = 0\n const onScroll = () => {\n frame ||= requestAnimationFrame(() => {\n frame = 0\n locate()\n })\n }\n onBeforeUnmount(() => cancelAnimationFrame(frame))\n watch(pages, () => nextTick(onScroll))\n // #endregion\n\n // #region the side panel: headings and tracked changes\n const textOf = (runs: WordPreviewRun[]) =>\n kept(runs)\n .map((r) => r.text)\n .join('')\n .replace(/\\s+/g, ' ')\n .trim()\n\n const headings = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n return block.kind === 'heading' && block.level <= 3\n ? [\n {\n key: item.key,\n level: block.level,\n text: [block.label, textOf(block.runs)]\n .filter(Boolean)\n .join(' '),\n },\n ]\n : []\n }),\n )\n\n const clip = (s: string) => (s.length > 60 ? `${s.slice(0, 60)}…` : s)\n const changes = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n const runs =\n block.kind === 'table'\n ? (block.rows[item.row ?? 0] ?? []).flatMap((c) => c.runs)\n : block.runs\n const removed = runs\n .filter((r) => r.change === 'deleted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n const added = runs\n .filter((r) => r.change === 'inserted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n return removed || added\n ? [\n {\n key: item.key,\n removed: clip(removed),\n added: clip(added),\n },\n ]\n : []\n }),\n )\n\n const tab = ref<'outline' | 'changes'>('outline')\n const sideOpen = ref(false)\n const goTo = (key: string) => {\n scrollEl.value\n ?.querySelector(`[data-key=\"${key}\"]`)\n ?.scrollIntoView({ block: 'start', behavior: 'smooth' })\n if (!wide.value) {\n sideOpen.value = false\n }\n }\n // #endregion\n\n const words = computed(\n () =>\n props.preview.blocks\n .flatMap((b) =>\n b.kind === 'table'\n ? b.rows.flat().map((c) => textOf(c.runs))\n : [textOf(b.runs)],\n )\n .join(' ')\n .split(/\\s+/)\n .filter(Boolean).length,\n )\n const authors = computed(() => props.preview.revisionAuthors.join(', '))\n</script>\n\n<template>\n <div\n ref=\"rootEl\"\n class=\"pk-word-preview\"\n :class=\"{ 'pk-word-preview--paged': paged }\">\n <aside\n v-if=\"(wide || sideOpen) && (headings.length || changes.length)\"\n class=\"pk-word-preview__side\"\n :class=\"{ 'pk-word-preview__side--over': !wide }\"\n :aria-label=\"$t('chatFilePreview.outline')\">\n <div class=\"pk-word-preview__tabs\" role=\"tablist\">\n <button\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'outline'\"\n @click=\"tab = 'outline'\">\n {{ $t('chatFilePreview.outline') }}\n </button>\n <button\n v-if=\"changes.length\"\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'changes'\"\n @click=\"tab = 'changes'\">\n {{\n $t('chatFilePreview.changes', { count: changes.length })\n }}\n </button>\n </div>\n <nav\n v-if=\"tab === 'outline' || !changes.length\"\n class=\"pk-word-preview__list\">\n <button\n v-for=\"h in headings\"\n :key=\"h.key\"\n type=\"button\"\n class=\"pk-word-preview__entry\"\n :class=\"`pk-word-preview__entry--${Math.min(h.level, 3)}`\"\n :aria-current=\"\n currentHeading === h.key ? 'location' : undefined\n \"\n @click=\"goTo(h.key)\">\n <span class=\"pk-word-preview__entry-text\">{{\n h.text\n }}</span>\n <span\n v-if=\"changes.some((c) => c.key === h.key)\"\n class=\"u-dot\" />\n </button>\n <p v-if=\"!headings.length\" class=\"pk-word-preview__none\">\n {{ $t('chatFilePreview.noHeadings') }}\n </p>\n </nav>\n <nav v-else class=\"pk-word-preview__list\">\n <button\n v-for=\"c in changes\"\n :key=\"c.key\"\n type=\"button\"\n class=\"pk-word-preview__entry pk-word-preview__entry--change\"\n @click=\"goTo(c.key)\">\n <del v-if=\"c.removed\" class=\"pk-word-preview__removed\">{{\n c.removed\n }}</del>\n <ins v-if=\"c.added\" class=\"pk-word-preview__added\">{{\n c.added\n }}</ins>\n </button>\n </nav>\n </aside>\n <div class=\"pk-word-preview__main\">\n <div\n ref=\"scrollEl\"\n class=\"pk-word-preview__scroll\"\n @scroll=\"onScroll\">\n <div\n v-if=\"paged\"\n class=\"pk-word-preview__pages\"\n :style=\"{ zoom }\">\n <article\n v-for=\"(p, n) in pages\"\n :key=\"n\"\n data-page\n class=\"pk-word-preview__page\"\n :aria-label=\"\n $t('chatFilePreview.pageOf', {\n page: n + 1,\n count: pages.length,\n })\n \"\n :style=\"pageCss\">\n <PkWordPreviewBlock\n v-for=\"i in p\"\n :key=\"items[i].key\"\n :data-key=\"items[i].key\"\n :block=\"preview.blocks[items[i].block]\"\n :row=\"items[i].row\"\n :mode />\n </article>\n </div>\n <article\n v-else\n class=\"pk-word-preview__page pk-word-preview__page--flow\"\n :style=\"textCss\">\n <PkWordPreviewBlock\n v-for=\"item in items\"\n :key=\"item.key\"\n :data-key=\"item.key\"\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </article>\n <p v-if=\"preview.truncated\" class=\"pk-word-preview__truncated\">\n {{ $t('chatFilePreview.truncated') }}\n </p>\n </div>\n <div class=\"pk-word-preview__status\">\n <span v-if=\"paged\" class=\"pk-word-preview__count\">\n {{\n $t('chatFilePreview.pageOf', {\n page: currentPage + 1,\n count: pages.length,\n })\n }}\n </span>\n <span class=\"pk-word-preview__count\">\n {{ $t('chatFilePreview.words', words) }}\n </span>\n <span\n v-if=\"mode === 'markup' && preview.revisionAuthors.length\"\n class=\"pk-word-preview__legend\">\n <span\n class=\"pk-word-preview__legend-text\"\n :title=\"$t('chatFilePreview.revisionsOf', { authors })\">\n {{ $t('chatFilePreview.revisionsOf', { authors }) }}\n </span>\n <del class=\"pk-word-preview__removed\">{{\n $t('chatFilePreview.removed')\n }}</del>\n <ins class=\"pk-word-preview__added\">{{\n $t('chatFilePreview.added')\n }}</ins>\n </span>\n <span class=\"pk-word-preview__spacer\" />\n <VvButton\n v-if=\"!wide && (headings.length || changes.length)\"\n class=\"pk-word-preview__outline-toggle\"\n modifiers=\"action-quiet\"\n icon=\"ri:list-unordered\"\n :label=\"$t('chatFilePreview.outline')\"\n :title=\"$t('chatFilePreview.outline')\"\n :aria-label=\"$t('chatFilePreview.outline')\"\n :aria-expanded=\"sideOpen\"\n @click=\"sideOpen = !sideOpen\" />\n <template v-if=\"paged\">\n <VvButton\n modifiers=\"action-quiet\"\n :label=\"$t('chatFilePreview.fitWidth')\"\n :disabled=\"fit\"\n @click=\"fit = true\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.3\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-word-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </template>\n </div>\n </div>\n <!-- Each paragraph and row at the page's width, to find its height -->\n <div\n v-if=\"paged\"\n ref=\"measureEl\"\n class=\"pk-word-preview__measure\"\n aria-hidden=\"true\"\n :style=\"measureCss\">\n <div v-for=\"item in items\" :key=\"item.key\" data-item>\n <PkWordPreviewBlock\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-word-preview {\n position: relative;\n display: flex;\n flex: 1;\n min-height: 0;\n\n // The headings and the changes, beside the pages or over them\n &__side {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-12);\n width: 16.5rem;\n flex-shrink: 0;\n padding: var(--spacing-12);\n box-sizing: border-box;\n overflow-y: auto;\n border-right: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n\n &--over {\n position: absolute;\n inset: 0 auto var(--spacing-40) 0;\n z-index: 3;\n box-shadow: var(--shadow-lg);\n }\n }\n\n &__tabs {\n display: flex;\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__tab {\n flex: 1;\n min-height: var(--spacing-40);\n border: 0;\n background: none;\n color: var(--color-word-3);\n font: inherit;\n font-size: var(--text-14);\n cursor: pointer;\n\n &[aria-selected='true'] {\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--color-word-1);\n color: var(--color-word-1);\n font-weight: var(--font-semibold);\n }\n }\n\n // One frame, hairline rows (DESIGN.md, principle 4)\n &__list {\n display: flex;\n flex-direction: column;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n overflow: hidden;\n }\n\n &__entry {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n min-height: var(--spacing-40);\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-bottom: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-14);\n text-align: start;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:last-child {\n border-bottom: 0;\n }\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n // The heading in view: surface and bar (DESIGN.md, principle 3)\n &[aria-current='location'] {\n background-color: var(--color-surface-2);\n box-shadow: inset var(--spacing-3) 0 0 var(--color-word-2);\n color: var(--color-word-1);\n font-weight: var(--font-medium);\n }\n\n &--0 {\n font-weight: var(--font-semibold);\n }\n\n &--2 {\n padding-left: var(--spacing-24);\n }\n\n &--3 {\n padding-left: var(--spacing-36);\n }\n\n &--change {\n flex-wrap: wrap;\n gap: var(--spacing-4) var(--spacing-8);\n font-size: var(--text-12);\n }\n }\n\n &__entry-text {\n flex: 1;\n min-width: 0;\n }\n\n &__none {\n margin: 0;\n padding: var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__main {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n }\n\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n padding: var(--spacing-md);\n background-color: var(--color-surface-2);\n }\n\n &__pages {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--spacing-24);\n width: max-content;\n min-width: 100%;\n }\n\n // A sheet of the document's size; white in both themes, as printed\n &__page {\n position: relative;\n box-sizing: border-box;\n background-color: #fff;\n box-shadow:\n 0 1px 3px rgb(20 14 51 / 16%),\n 0 10px 28px rgb(20 14 51 / 8%);\n line-height: var(--pk-word-line, 1.17);\n overflow-wrap: break-word;\n\n &--flow {\n width: 100%;\n padding: var(--spacing-24) var(--spacing-20);\n }\n }\n\n &__measure {\n position: absolute;\n top: 0;\n left: -100000px;\n visibility: hidden;\n pointer-events: none;\n line-height: var(--pk-word-line, 1.17);\n\n // As the page breaks a long word, or a link measures one line\n // and draws three\n overflow-wrap: break-word;\n }\n\n &__block {\n position: relative;\n margin: 0;\n\n // A tab or a line break of the document stays where Word put it\n white-space: pre-wrap;\n }\n\n &__label {\n display: inline-block;\n text-indent: 0;\n }\n\n // Word's bar in the margin beside a changed paragraph\n &__changed::before {\n content: '';\n position: absolute;\n top: 0;\n bottom: 0;\n left: -14pt;\n width: 1.5pt;\n background-color: #3f3c51;\n }\n\n &__table {\n position: relative;\n width: 100%;\n margin: 0;\n border-collapse: collapse;\n table-layout: fixed;\n\n td {\n padding: 0 5.4pt;\n vertical-align: top;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n &--lines td {\n border: 0.5pt solid #000;\n }\n\n // A row after the first: its top line is the row's above\n &--lines.pk-word-preview__table--next td {\n border-top: 0;\n }\n }\n\n // The marks of the card of an edit (PkToolChatFile.vue): the change is\n // the verdict the preview shows, the exception of DESIGN.md principle 2.\n // The base styles take the line off `del`.\n &__removed {\n color: var(--u-danger-text, #c42b3c);\n text-decoration: line-through;\n }\n\n &__added {\n color: var(--u-success-text, #178230);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n // Inside the white page the marks keep the light theme's colors\n &__page &__removed {\n color: #c42b3c;\n }\n\n &__page &__added {\n color: #178230;\n }\n\n // A word replaced: what went and what came, not run together\n &__removed + &__added {\n margin-inline-start: 0.15em;\n }\n\n &__image {\n display: inline-block;\n padding: var(--spacing-2) var(--spacing-8);\n border: var(--border) dashed #c9c8d2;\n border-radius: var(--rounded);\n color: #6b6880;\n font-size: 9pt;\n text-indent: 0;\n }\n\n &__truncated {\n margin: var(--spacing-md) 0 0;\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__status {\n display: flex;\n align-items: center;\n gap: var(--spacing-16);\n min-height: var(--spacing-40);\n padding: 0 var(--spacing-8) 0 var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n font-size: var(--text-12);\n white-space: nowrap;\n\n // Only the legend's words give way in a narrow frame\n > * {\n flex-shrink: 0;\n }\n }\n\n &__count {\n font-variant-numeric: tabular-nums;\n }\n\n &__status > &__legend {\n display: flex;\n flex-shrink: 1;\n gap: var(--spacing-8);\n min-width: 0;\n }\n\n // The words shorten, the two marks they explain stay\n &__legend-text {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n\n &__legend > &__removed,\n &__legend > &__added {\n flex-shrink: 0;\n }\n\n &__spacer {\n flex: 1;\n }\n\n // A phone keeps the outline's icon\n @container (width < 30rem) {\n &__outline-toggle .vv-button__label {\n display: none;\n }\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type { WordPreview, WordPreviewRun } from 'models'\n import PkWordPreviewBlock from './PkWordPreviewBlock.vue'\n import {\n wordFontStack,\n wordLineFactor,\n type WordPreviewMode,\n } from './utils'\n\n /**\n * A Word document stored in the chat, drawn in pages as Word draws it\n * (spec `chat-office-files.md`, F6, item 3, and the viewer of its\n * follow-ups): white pages of the document's size and margins on a grey\n * ground, its fonts and its layout. The pages are computed here: each\n * paragraph and each table row is measured at the width of the page and\n * placed on the next page when it does not fit, or where the document\n * breaks the page, so they come close to Word's without matching them.\n * Below 640 pixels the text flows at the width of the screen. A side\n * panel lists the headings and the tracked changes, and leads to them.\n * The pages keep their white in the dark theme. Framed by\n * `PkFilePreview`.\n */\n const props = defineProps<{\n preview: WordPreview\n mode: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** Pixels in a point. */\n const PX = 96 / 72\n\n // #region the flow: paragraphs and table rows\n const kept = (runs: WordPreviewRun[]) =>\n runs.filter((r) =>\n props.mode === 'accepted'\n ? r.change !== 'deleted'\n : props.mode === 'original'\n ? r.change !== 'inserted'\n : true,\n )\n const hasText = (runs: WordPreviewRun[]) =>\n runs.some((r) => r.image || r.text.trim())\n\n type Item = {\n key: string\n block: number\n row?: number\n breakBefore: boolean\n }\n /**\n * What the pages hold, in order. A paragraph or a table row a mode\n * empties is gone (a row inserted, as the original); one empty in the\n * document stays, a blank line as in Word.\n */\n const items = computed(() => {\n const out: Item[] = []\n props.preview.blocks.forEach((block, b) => {\n if (block.kind === 'table') {\n let first = true\n block.rows.forEach((cells, r) => {\n const filled = cells.some((cell) => cell.runs.length)\n if (\n filled &&\n !cells.some((cell) => hasText(kept(cell.runs)))\n ) {\n return\n }\n out.push({\n key: `${b}:${r}`,\n block: b,\n row: r,\n breakBefore: first && !!block.pageBreakBefore,\n })\n first = false\n })\n } else if (!block.runs.length || hasText(kept(block.runs))) {\n out.push({\n key: `${b}`,\n block: b,\n breakBefore: !!block.style?.pageBreakBefore,\n })\n }\n })\n return out\n })\n // #endregion\n\n // #region pages\n const rootEl = useTemplateRef<HTMLElement>('rootEl')\n const scrollEl = useTemplateRef<HTMLElement>('scrollEl')\n const measureEl = useTemplateRef<HTMLElement>('measureEl')\n const { width } = useElementSize(rootEl)\n const { width: scrollWidth } = useElementSize(scrollEl)\n const paged = computed(() => width.value === 0 || width.value >= 640)\n const wide = computed(() => width.value >= 1000)\n\n const page = computed(() => props.preview.page)\n const textCss = computed((): CSSProperties => ({\n fontFamily: wordFontStack(props.preview.defaults.font),\n fontSize: `${props.preview.defaults.size}pt`,\n color: props.preview.defaults.color ?? '#000000',\n '--pk-word-line': wordLineFactor(props.preview.defaults.font),\n }))\n const pageCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${page.value.width}pt`,\n minHeight: `${page.value.height}pt`,\n padding: `${page.value.margins.top}pt ${page.value.margins.right}pt ${page.value.margins.bottom}pt ${page.value.margins.left}pt`,\n }))\n const measureCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${\n page.value.width -\n page.value.margins.left -\n page.value.margins.right\n }pt`,\n }))\n\n const heights = ref<number[]>([])\n const measure = async () => {\n await nextTick()\n const els =\n measureEl.value?.querySelectorAll<HTMLElement>('[data-item]')\n heights.value = [...(els ?? [])].map(\n (el) => el.getBoundingClientRect().height,\n )\n }\n watch([items, paged], measure, { flush: 'post' })\n onMounted(() => {\n measure()\n // The document's fonts change the lines once they arrive.\n document.fonts?.ready.then(measure)\n })\n\n /** The items of each page, by their index in `items`. */\n const pages = computed(() => {\n const all = items.value.map((_, i) => i)\n if (!paged.value || heights.value.length !== items.value.length) {\n return [all]\n }\n const room =\n (page.value.height -\n page.value.margins.top -\n page.value.margins.bottom) *\n PX\n const out: number[][] = [[]]\n let used = 0\n items.value.forEach((item, i) => {\n const h = heights.value[i]\n if (\n out[out.length - 1].length &&\n (item.breakBefore || used + h > room)\n ) {\n out.push([])\n used = 0\n }\n out[out.length - 1].push(i)\n used += h\n })\n return out\n })\n // #endregion\n\n // #region zoom and the page in view\n // Models, so the zoom stays when the viewer moves between the panel and\n // the dialog (`PkChatbotViewChat` keeps it).\n const fit = defineModel<boolean>('fit', { default: true })\n const manual = defineModel<number>('zoom', { default: 1 })\n const zoom = computed(() =>\n fit.value\n ? Math.min(\n 1.25,\n Math.max(\n 0.3,\n (scrollWidth.value - 48) / (page.value.width * PX),\n ),\n )\n : manual.value,\n )\n const zoomBy = (step: number) => {\n manual.value = Math.min(\n 2,\n Math.max(0.3, Math.round((zoom.value + step) * 10) / 10),\n )\n fit.value = false\n }\n\n const currentPage = ref(0)\n const currentHeading = ref<string>()\n /**\n * The page and the heading being read. Pages and headings go down in\n * order, so the search stops at the first one below the line; and it runs\n * once a frame, however many scroll events come.\n */\n const locate = () => {\n const box = scrollEl.value?.getBoundingClientRect()\n if (!box) {\n return\n }\n const pageEls = scrollEl.value?.querySelectorAll('[data-page]') ?? []\n let n = 0\n for (const [i, el] of [...pageEls].entries()) {\n if (el.getBoundingClientRect().top - box.top > box.height / 3) {\n break\n }\n n = i\n }\n currentPage.value = n\n let heading: string | undefined\n for (const h of headings.value) {\n const el = scrollEl.value?.querySelector(`[data-key=\"${h.key}\"]`)\n if (!el) {\n continue\n }\n if (el.getBoundingClientRect().top - box.top > 48) {\n break\n }\n heading = h.key\n }\n currentHeading.value = heading ?? headings.value[0]?.key\n }\n let frame = 0\n const onScroll = () => {\n frame ||= requestAnimationFrame(() => {\n frame = 0\n locate()\n })\n }\n onBeforeUnmount(() => cancelAnimationFrame(frame))\n watch(pages, () => nextTick(onScroll))\n // #endregion\n\n // #region the side panel: headings and tracked changes\n const textOf = (runs: WordPreviewRun[]) =>\n kept(runs)\n .map((r) => r.text)\n .join('')\n .replace(/\\s+/g, ' ')\n .trim()\n\n const headings = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n return block.kind === 'heading' && block.level <= 3\n ? [\n {\n key: item.key,\n level: block.level,\n text: [block.label, textOf(block.runs)]\n .filter(Boolean)\n .join(' '),\n },\n ]\n : []\n }),\n )\n\n const clip = (s: string) => (s.length > 60 ? `${s.slice(0, 60)}…` : s)\n const changes = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n const runs =\n block.kind === 'table'\n ? (block.rows[item.row ?? 0] ?? []).flatMap((c) => c.runs)\n : block.runs\n const removed = runs\n .filter((r) => r.change === 'deleted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n const added = runs\n .filter((r) => r.change === 'inserted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n return removed || added\n ? [\n {\n key: item.key,\n removed: clip(removed),\n added: clip(added),\n },\n ]\n : []\n }),\n )\n\n const tab = ref<'outline' | 'changes'>('outline')\n const sideOpen = ref(false)\n const goTo = (key: string) => {\n scrollEl.value\n ?.querySelector(`[data-key=\"${key}\"]`)\n ?.scrollIntoView({ block: 'start', behavior: 'smooth' })\n if (!wide.value) {\n sideOpen.value = false\n }\n }\n // #endregion\n\n const words = computed(\n () =>\n props.preview.blocks\n .flatMap((b) =>\n b.kind === 'table'\n ? b.rows.flat().map((c) => textOf(c.runs))\n : [textOf(b.runs)],\n )\n .join(' ')\n .split(/\\s+/)\n .filter(Boolean).length,\n )\n const authors = computed(() => props.preview.revisionAuthors.join(', '))\n</script>\n\n<template>\n <div\n ref=\"rootEl\"\n class=\"pk-word-preview\"\n :class=\"{ 'pk-word-preview--paged': paged }\">\n <aside\n v-if=\"(wide || sideOpen) && (headings.length || changes.length)\"\n class=\"pk-word-preview__side\"\n :class=\"{ 'pk-word-preview__side--over': !wide }\"\n :aria-label=\"$t('chatFilePreview.outline')\">\n <div class=\"pk-word-preview__tabs\" role=\"tablist\">\n <button\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'outline'\"\n @click=\"tab = 'outline'\">\n {{ $t('chatFilePreview.outline') }}\n </button>\n <button\n v-if=\"changes.length\"\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'changes'\"\n @click=\"tab = 'changes'\">\n {{\n $t('chatFilePreview.changes', { count: changes.length })\n }}\n </button>\n </div>\n <nav\n v-if=\"tab === 'outline' || !changes.length\"\n class=\"pk-word-preview__list\">\n <button\n v-for=\"h in headings\"\n :key=\"h.key\"\n type=\"button\"\n class=\"pk-word-preview__entry\"\n :class=\"`pk-word-preview__entry--${Math.min(h.level, 3)}`\"\n :aria-current=\"\n currentHeading === h.key ? 'location' : undefined\n \"\n @click=\"goTo(h.key)\">\n <span class=\"pk-word-preview__entry-text\">{{\n h.text\n }}</span>\n <span\n v-if=\"changes.some((c) => c.key === h.key)\"\n class=\"u-dot\" />\n </button>\n <p v-if=\"!headings.length\" class=\"pk-word-preview__none\">\n {{ $t('chatFilePreview.noHeadings') }}\n </p>\n </nav>\n <nav v-else class=\"pk-word-preview__list\">\n <button\n v-for=\"c in changes\"\n :key=\"c.key\"\n type=\"button\"\n class=\"pk-word-preview__entry pk-word-preview__entry--change\"\n @click=\"goTo(c.key)\">\n <del v-if=\"c.removed\" class=\"pk-word-preview__removed\">{{\n c.removed\n }}</del>\n <ins v-if=\"c.added\" class=\"pk-word-preview__added\">{{\n c.added\n }}</ins>\n </button>\n </nav>\n </aside>\n <div class=\"pk-word-preview__main\">\n <div\n ref=\"scrollEl\"\n class=\"pk-word-preview__scroll\"\n @scroll=\"onScroll\">\n <div\n v-if=\"paged\"\n class=\"pk-word-preview__pages\"\n :style=\"{ zoom }\">\n <article\n v-for=\"(p, n) in pages\"\n :key=\"n\"\n data-page\n class=\"pk-word-preview__page\"\n :aria-label=\"\n $t('chatFilePreview.pageOf', {\n page: n + 1,\n count: pages.length,\n })\n \"\n :style=\"pageCss\">\n <PkWordPreviewBlock\n v-for=\"i in p\"\n :key=\"items[i].key\"\n :data-key=\"items[i].key\"\n :block=\"preview.blocks[items[i].block]\"\n :row=\"items[i].row\"\n :mode />\n </article>\n </div>\n <article\n v-else\n class=\"pk-word-preview__page pk-word-preview__page--flow\"\n :style=\"textCss\">\n <PkWordPreviewBlock\n v-for=\"item in items\"\n :key=\"item.key\"\n :data-key=\"item.key\"\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </article>\n <p v-if=\"preview.truncated\" class=\"pk-word-preview__truncated\">\n {{ $t('chatFilePreview.truncated') }}\n </p>\n </div>\n <div class=\"pk-word-preview__status\">\n <span v-if=\"paged\" class=\"pk-word-preview__count\">\n {{\n $t('chatFilePreview.pageOf', {\n page: currentPage + 1,\n count: pages.length,\n })\n }}\n </span>\n <span class=\"pk-word-preview__count\">\n {{ $t('chatFilePreview.words', words) }}\n </span>\n <span\n v-if=\"mode === 'markup' && preview.revisionAuthors.length\"\n class=\"pk-word-preview__legend\">\n <span\n class=\"pk-word-preview__legend-text\"\n :title=\"$t('chatFilePreview.revisionsOf', { authors })\">\n {{ $t('chatFilePreview.revisionsOf', { authors }) }}\n </span>\n <del class=\"pk-word-preview__removed\">{{\n $t('chatFilePreview.removed')\n }}</del>\n <ins class=\"pk-word-preview__added\">{{\n $t('chatFilePreview.added')\n }}</ins>\n </span>\n <span class=\"pk-word-preview__spacer\" />\n <VvButton\n v-if=\"!wide && (headings.length || changes.length)\"\n class=\"pk-word-preview__outline-toggle\"\n modifiers=\"action-quiet\"\n icon=\"ri:list-unordered\"\n :label=\"$t('chatFilePreview.outline')\"\n :title=\"$t('chatFilePreview.outline')\"\n :aria-label=\"$t('chatFilePreview.outline')\"\n :aria-expanded=\"sideOpen\"\n @click=\"sideOpen = !sideOpen\" />\n <template v-if=\"paged\">\n <VvButton\n modifiers=\"action-quiet\"\n :label=\"$t('chatFilePreview.fitWidth')\"\n :disabled=\"fit\"\n @click=\"fit = true\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.3\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-word-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </template>\n </div>\n </div>\n <!-- Each paragraph and row at the page's width, to find its height -->\n <div\n v-if=\"paged\"\n ref=\"measureEl\"\n class=\"pk-word-preview__measure\"\n aria-hidden=\"true\"\n :style=\"measureCss\">\n <div v-for=\"item in items\" :key=\"item.key\" data-item>\n <PkWordPreviewBlock\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-word-preview {\n position: relative;\n display: flex;\n flex: 1;\n min-height: 0;\n\n // The headings and the changes, beside the pages or over them\n &__side {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-12);\n width: 16.5rem;\n flex-shrink: 0;\n padding: var(--spacing-12);\n box-sizing: border-box;\n overflow-y: auto;\n border-right: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n\n &--over {\n position: absolute;\n inset: 0 auto var(--spacing-40) 0;\n z-index: 3;\n box-shadow: var(--shadow-lg);\n }\n }\n\n &__tabs {\n display: flex;\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__tab {\n flex: 1;\n min-height: var(--spacing-40);\n border: 0;\n background: none;\n color: var(--color-word-3);\n font: inherit;\n font-size: var(--text-14);\n cursor: pointer;\n\n &[aria-selected='true'] {\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--color-word-1);\n color: var(--color-word-1);\n font-weight: var(--font-semibold);\n }\n }\n\n // One frame, hairline rows (DESIGN.md, principle 4)\n &__list {\n display: flex;\n flex-direction: column;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n overflow: hidden;\n }\n\n &__entry {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n min-height: var(--spacing-40);\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-bottom: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-14);\n text-align: start;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:last-child {\n border-bottom: 0;\n }\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n // The heading in view: surface and bar (DESIGN.md, principle 3)\n &[aria-current='location'] {\n background-color: var(--color-surface-2);\n box-shadow: inset var(--spacing-3) 0 0 var(--color-word-2);\n color: var(--color-word-1);\n font-weight: var(--font-medium);\n }\n\n &--0 {\n font-weight: var(--font-semibold);\n }\n\n &--2 {\n padding-left: var(--spacing-24);\n }\n\n &--3 {\n padding-left: var(--spacing-36);\n }\n\n &--change {\n flex-wrap: wrap;\n gap: var(--spacing-4) var(--spacing-8);\n font-size: var(--text-12);\n }\n }\n\n &__entry-text {\n flex: 1;\n min-width: 0;\n }\n\n &__none {\n margin: 0;\n padding: var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__main {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n }\n\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n padding: var(--spacing-md);\n background-color: var(--color-surface-2);\n }\n\n &__pages {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--spacing-24);\n width: max-content;\n min-width: 100%;\n }\n\n // A sheet of the document's size; white in both themes, as printed\n &__page {\n position: relative;\n box-sizing: border-box;\n background-color: #fff;\n box-shadow:\n 0 1px 3px rgb(20 14 51 / 16%),\n 0 10px 28px rgb(20 14 51 / 8%);\n line-height: var(--pk-word-line, 1.17);\n overflow-wrap: break-word;\n\n &--flow {\n width: 100%;\n padding: var(--spacing-24) var(--spacing-20);\n }\n }\n\n &__measure {\n position: absolute;\n top: 0;\n left: -100000px;\n visibility: hidden;\n pointer-events: none;\n line-height: var(--pk-word-line, 1.17);\n\n // As the page breaks a long word, or a link measures one line\n // and draws three\n overflow-wrap: break-word;\n }\n\n &__block {\n position: relative;\n margin: 0;\n\n // A tab or a line break of the document stays where Word put it\n white-space: pre-wrap;\n }\n\n &__label {\n display: inline-block;\n text-indent: 0;\n }\n\n // Word's bar in the margin beside a changed paragraph\n &__changed::before {\n content: '';\n position: absolute;\n top: 0;\n bottom: 0;\n left: -14pt;\n width: 1.5pt;\n background-color: #3f3c51;\n }\n\n &__table {\n position: relative;\n width: 100%;\n margin: 0;\n border-collapse: collapse;\n table-layout: fixed;\n\n td {\n padding: 0 5.4pt;\n vertical-align: top;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n &--lines td {\n border: 0.5pt solid #000;\n }\n\n // A row after the first: its top line is the row's above\n &--lines.pk-word-preview__table--next td {\n border-top: 0;\n }\n }\n\n // The marks of the card of an edit (PkToolChatFile.vue): the change is\n // the verdict the preview shows, the exception of DESIGN.md principle 2.\n // The base styles take the line off `del`.\n &__removed {\n color: var(--u-danger-text, #c42b3c);\n text-decoration: line-through;\n }\n\n &__added {\n color: var(--u-success-text, #178230);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n // Inside the white page the marks keep the light theme's colors\n &__page &__removed {\n color: #c42b3c;\n }\n\n &__page &__added {\n color: #178230;\n }\n\n // A word replaced: what went and what came, not run together\n &__removed + &__added {\n margin-inline-start: 0.15em;\n }\n\n &__image {\n display: inline-block;\n padding: var(--spacing-2) var(--spacing-8);\n border: var(--border) dashed #c9c8d2;\n border-radius: var(--rounded);\n color: #6b6880;\n font-size: 9pt;\n text-indent: 0;\n }\n\n &__truncated {\n margin: var(--spacing-md) 0 0;\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__status {\n display: flex;\n align-items: center;\n gap: var(--spacing-16);\n min-height: var(--spacing-40);\n padding: 0 var(--spacing-8) 0 var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n font-size: var(--text-12);\n white-space: nowrap;\n\n // Only the legend's words give way in a narrow frame\n > * {\n flex-shrink: 0;\n }\n }\n\n &__count {\n font-variant-numeric: tabular-nums;\n }\n\n &__status > &__legend {\n display: flex;\n flex-shrink: 1;\n gap: var(--spacing-8);\n min-width: 0;\n }\n\n // The words shorten, the two marks they explain stay\n &__legend-text {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n\n &__legend > &__removed,\n &__legend > &__added {\n flex-shrink: 0;\n }\n\n &__spacer {\n flex: 1;\n }\n\n // A phone keeps the outline's icon\n @container (width < 30rem) {\n &__outline-toggle .vv-button__label {\n display: none;\n }\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, watch } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { ChatFilePreview } from 'models'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import PkSpreadsheetPreview from './PkSpreadsheetPreview.vue'\n import PkWordPreview from './PkWordPreview.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * The viewer of a Word document or a spreadsheet stored in the chat (spec\n * `chat-office-files.md`, F6, items 3 and 4, and their follow-ups): a head\n * with the file, its versions in the conversation, how to show the\n * revisions of a Word document, restore, download, a larger frame and\n * close, over the document drawn as Word or Excel draws it. The same\n * viewer goes in the panel beside the chat and in a dialog over it.\n */\n const props = defineProps<{\n kind: 'word' | 'spreadsheet'\n /** The name of the file, not of its version. */\n filename: string\n version?: number\n /** The versions of the file in the conversation, from 1. */\n versions?: number[]\n /** The authenticated download URL of the shown version. */\n downloadUrl: string\n preview?: ChatFilePreview\n loading?: boolean\n error?: boolean\n /** The shown version can be written again as the newest one. */\n restorable?: boolean\n /** Offers to move to the larger frame, or back to the panel. */\n resize?: 'expand' | 'shrink'\n }>()\n\n const emit = defineEmits<{\n close: []\n version: [version: number]\n restore: []\n resize: []\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const versions = computed(() => props.versions ?? [])\n const position = computed(() =>\n props.version ? versions.value.indexOf(props.version) : -1,\n )\n const previous = computed(() =>\n position.value > 0 ? versions.value[position.value - 1] : undefined,\n )\n const next = computed(() =>\n position.value >= 0 && position.value < versions.value.length - 1\n ? versions.value[position.value + 1]\n : undefined,\n )\n\n /**\n * How a Word document with tracked changes is drawn, and the sheet and\n * the zoom: models, so they stay when the viewer moves between the panel\n * and the dialog, where it is drawn anew.\n */\n const mode = defineModel<WordPreviewMode>('mode', { default: 'markup' })\n const sheet = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const fit = defineModel<boolean>('fit', { default: true })\n const modes = computed(() => [\n { value: 'markup', label: $t('chatFilePreview.modeMarkup') },\n { value: 'accepted', label: $t('chatFilePreview.modeAccepted') },\n { value: 'original', label: $t('chatFilePreview.modeOriginal') },\n ])\n const hasRevisions = computed(\n () =>\n props.preview?.kind === 'word' &&\n props.preview.revisionAuthors.length > 0,\n )\n // Another version starts with its revisions in sight.\n watch(\n () => props.version,\n () => {\n mode.value = 'markup'\n },\n )\n</script>\n\n<template>\n <!-- A dialog gives the focus to its first control, the arrow of the\n versions: it goes to the viewer, and the keyboard starts from here -->\n <section\n class=\"pk-file-preview\"\n :aria-label=\"filename\"\n tabindex=\"-1\"\n autofocus>\n <header class=\"pk-file-preview__head\">\n <div class=\"pk-file-preview__file\">\n <span class=\"pk-file-preview__tile\" aria-hidden=\"true\">\n <VvIcon\n :name=\"\n kind === 'word'\n ? 'ri:file-word-2-line'\n : 'ri:file-excel-2-line'\n \"\n :class=\"\n kind === 'word'\n ? 'pk-file-preview__icon--word'\n : 'pk-file-preview__icon--sheet'\n \" />\n </span>\n <div class=\"pk-file-preview__name\">\n <strong class=\"pk-file-preview__title\">\n {{ filename }}\n </strong>\n <span class=\"pk-file-preview__note\">\n {{ $t('chatFilePreview.readOnly') }}\n </span>\n </div>\n </div>\n <div\n v-if=\"(version && versions.length > 1) || hasRevisions\"\n class=\"pk-file-preview__tools\">\n <nav\n v-if=\"version && versions.length > 1\"\n class=\"pk-file-preview__versions\"\n :aria-label=\"$t('chatFilePreview.versions')\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-left-s-line\"\n :aria-label=\"$t('chatFilePreview.previousVersion')\"\n :disabled=\"!previous\"\n @click=\"previous && emit('version', previous)\" />\n <span class=\"pk-file-preview__version\">\n {{\n $t('chatFilePreview.versionOf', {\n version,\n count: versions.length,\n })\n }}\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-right-s-line\"\n :aria-label=\"$t('chatFilePreview.nextVersion')\"\n :disabled=\"!next\"\n @click=\"next && emit('version', next)\" />\n </nav>\n <PkEditorRadioButtons\n v-if=\"hasRevisions\"\n v-model=\"mode\"\n name=\"revisions\"\n segmented\n class=\"pk-file-preview__modes u-segmented-fit mb-0\"\n :aria-label=\"$t('chatFilePreview.modes')\"\n :options=\"modes\">\n <!-- The short name where the long one leaves the\n versions no room on the line -->\n <template #markup>\n <span class=\"pk-file-preview__mode-long\">\n {{ $t('chatFilePreview.modeMarkup') }}\n </span>\n <span class=\"pk-file-preview__mode-short\">\n {{ $t('chatFilePreview.modeMarkupShort') }}\n </span>\n </template>\n </PkEditorRadioButtons>\n </div>\n <div class=\"pk-file-preview__actions\">\n <VvButton\n v-if=\"restorable\"\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :label=\"$t('chatFilePreview.restore')\"\n @click=\"emit('restore')\" />\n <VvButton\n :href=\"downloadUrl\"\n download\n modifiers=\"action-quiet\"\n icon=\"ri:download-line\"\n :title=\"$t('chatFilePreview.download')\"\n :aria-label=\"$t('chatFilePreview.download')\" />\n <VvButton\n v-if=\"resize === 'expand'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-line\"\n :title=\"$t('chatFilePreview.expand')\"\n :aria-label=\"$t('chatFilePreview.expand')\"\n @click=\"emit('resize')\" />\n <VvButton\n v-else-if=\"resize === 'shrink'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-exit-line\"\n :title=\"$t('chatFilePreview.shrink')\"\n :aria-label=\"$t('chatFilePreview.shrink')\"\n @click=\"emit('resize')\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:close-line\"\n :title=\"$t('chatFilePreview.close')\"\n :aria-label=\"$t('chatFilePreview.close')\"\n @click=\"emit('close')\" />\n </div>\n </header>\n <div class=\"pk-file-preview__body\">\n <div v-if=\"loading\" class=\"pk-file-preview__skeleton vv-skeleton\">\n <div\n v-for=\"i in 8\"\n :key=\"i\"\n class=\"vv-skeleton__item pk-file-preview__skeleton-line\"\n :class=\"i % 3 ? 'w-full' : 'w-128'\" />\n </div>\n <p v-else-if=\"error || !preview\" class=\"pk-file-preview__empty\">\n {{ $t('chatFilePreview.unavailable') }}\n </p>\n <PkWordPreview\n v-else-if=\"preview.kind === 'word'\"\n v-model:zoom=\"zoom\"\n v-model:fit=\"fit\"\n :preview\n :mode=\"hasRevisions ? mode : 'markup'\" />\n <PkSpreadsheetPreview\n v-else\n v-model:sheet=\"sheet\"\n v-model:zoom=\"zoom\"\n :preview />\n </div>\n </section>\n</template>\n\n<style lang=\"scss\">\n .pk-file-preview {\n container-type: inline-size;\n display: flex;\n flex-direction: column;\n min-height: 0;\n height: 100%;\n outline: none;\n background-color: var(--color-surface);\n color: var(--color-word-1);\n\n &__head {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n padding: var(--spacing-12) var(--spacing-12) var(--spacing-12)\n var(--spacing-md);\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__file {\n display: flex;\n flex: 1 1 12rem;\n align-items: center;\n gap: var(--spacing-12);\n min-width: 0;\n }\n\n &__tile {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-32);\n height: var(--spacing-32);\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n\n .vv-icon {\n width: var(--spacing-18);\n height: var(--spacing-18);\n }\n }\n\n // The colors the file chip of the chat gives the two kinds\n &__icon--word {\n color: #2b7de9;\n }\n\n &__icon--sheet {\n color: #1f9d57;\n }\n\n &__name {\n display: flex;\n flex-direction: column;\n min-width: 0;\n }\n\n &__title {\n overflow: hidden;\n font-size: var(--text-14);\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n &__note {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n &__tools {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n }\n\n &__versions {\n display: flex;\n align-items: center;\n gap: var(--spacing-2);\n }\n\n &__version {\n font-size: var(--text-14);\n font-weight: var(--font-semibold);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__actions {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n margin-left: auto;\n }\n\n // In a narrow frame the file and its actions keep the first line,\n // the versions and the revisions take the second.\n @container (width < 52rem) {\n &__file {\n order: 1;\n }\n\n &__actions {\n order: 2;\n }\n\n &__tools {\n order: 3;\n flex-basis: 100%;\n }\n\n // The ways to show the revisions fill what the versions leave,\n // or go to a line of their own: never narrower than their words\n &__tools &__modes {\n flex: 1 1 auto;\n }\n }\n\n &__mode-short {\n display: none;\n }\n\n // Below this the long name puts the modes on a line of their own\n @container (width < 38rem) {\n &__mode-long {\n display: none;\n }\n\n &__mode-short {\n display: inline;\n }\n }\n\n // A phone gives them a line of their own, with less padding\n @container (width < 30rem) {\n &__tools &__modes {\n flex: 1 1 100%;\n\n .vv-radio {\n padding-inline: var(--spacing-4);\n }\n }\n }\n\n // The document scrolls inside its viewer, so the head stays in view\n &__body {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n background-color: var(--color-surface-1);\n }\n\n &__skeleton {\n width: min(42rem, calc(100% - 2 * var(--spacing-md)));\n margin: var(--spacing-md) auto;\n padding: var(--spacing-lg);\n box-sizing: border-box;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n background-color: var(--color-surface);\n }\n\n &__skeleton-line {\n height: var(--spacing-12);\n margin-bottom: var(--spacing-12);\n border-radius: var(--rounded);\n }\n\n &__empty {\n margin: var(--spacing-lg) var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-14);\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, watch } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { ChatFilePreview } from 'models'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import PkSpreadsheetPreview from './PkSpreadsheetPreview.vue'\n import PkWordPreview from './PkWordPreview.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * The viewer of a Word document or a spreadsheet stored in the chat (spec\n * `chat-office-files.md`, F6, items 3 and 4, and their follow-ups): a head\n * with the file, its versions in the conversation, how to show the\n * revisions of a Word document, restore, download, a larger frame and\n * close, over the document drawn as Word or Excel draws it. The same\n * viewer goes in the panel beside the chat and in a dialog over it.\n */\n const props = defineProps<{\n kind: 'word' | 'spreadsheet'\n /** The name of the file, not of its version. */\n filename: string\n version?: number\n /** The versions of the file in the conversation, from 1. */\n versions?: number[]\n /** The authenticated download URL of the shown version. */\n downloadUrl: string\n preview?: ChatFilePreview\n loading?: boolean\n error?: boolean\n /** The shown version can be written again as the newest one. */\n restorable?: boolean\n /** Offers to move to the larger frame, or back to the panel. */\n resize?: 'expand' | 'shrink'\n }>()\n\n const emit = defineEmits<{\n close: []\n version: [version: number]\n restore: []\n resize: []\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const versions = computed(() => props.versions ?? [])\n const position = computed(() =>\n props.version ? versions.value.indexOf(props.version) : -1,\n )\n const previous = computed(() =>\n position.value > 0 ? versions.value[position.value - 1] : undefined,\n )\n const next = computed(() =>\n position.value >= 0 && position.value < versions.value.length - 1\n ? versions.value[position.value + 1]\n : undefined,\n )\n\n /**\n * How a Word document with tracked changes is drawn, and the sheet and\n * the zoom: models, so they stay when the viewer moves between the panel\n * and the dialog, where it is drawn anew.\n */\n const mode = defineModel<WordPreviewMode>('mode', { default: 'markup' })\n const sheet = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const fit = defineModel<boolean>('fit', { default: true })\n const modes = computed(() => [\n { value: 'markup', label: $t('chatFilePreview.modeMarkup') },\n { value: 'accepted', label: $t('chatFilePreview.modeAccepted') },\n { value: 'original', label: $t('chatFilePreview.modeOriginal') },\n ])\n const hasRevisions = computed(\n () =>\n props.preview?.kind === 'word' &&\n props.preview.revisionAuthors.length > 0,\n )\n // Another version starts with its revisions in sight.\n watch(\n () => props.version,\n () => {\n mode.value = 'markup'\n },\n )\n</script>\n\n<template>\n <!-- A dialog gives the focus to its first control, the arrow of the\n versions: it goes to the viewer, and the keyboard starts from here -->\n <section\n class=\"pk-file-preview\"\n :aria-label=\"filename\"\n tabindex=\"-1\"\n autofocus>\n <header class=\"pk-file-preview__head\">\n <div class=\"pk-file-preview__file\">\n <span class=\"pk-file-preview__tile\" aria-hidden=\"true\">\n <VvIcon\n :name=\"\n kind === 'word'\n ? 'ri:file-word-2-line'\n : 'ri:file-excel-2-line'\n \"\n :class=\"\n kind === 'word'\n ? 'pk-file-preview__icon--word'\n : 'pk-file-preview__icon--sheet'\n \" />\n </span>\n <div class=\"pk-file-preview__name\">\n <strong class=\"pk-file-preview__title\">\n {{ filename }}\n </strong>\n <span class=\"pk-file-preview__note\">\n {{ $t('chatFilePreview.readOnly') }}\n </span>\n </div>\n </div>\n <div\n v-if=\"(version && versions.length > 1) || hasRevisions\"\n class=\"pk-file-preview__tools\">\n <nav\n v-if=\"version && versions.length > 1\"\n class=\"pk-file-preview__versions\"\n :aria-label=\"$t('chatFilePreview.versions')\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-left-s-line\"\n :aria-label=\"$t('chatFilePreview.previousVersion')\"\n :disabled=\"!previous\"\n @click=\"previous && emit('version', previous)\" />\n <span class=\"pk-file-preview__version\">\n {{\n $t('chatFilePreview.versionOf', {\n version,\n count: versions.length,\n })\n }}\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-right-s-line\"\n :aria-label=\"$t('chatFilePreview.nextVersion')\"\n :disabled=\"!next\"\n @click=\"next && emit('version', next)\" />\n </nav>\n <PkEditorRadioButtons\n v-if=\"hasRevisions\"\n v-model=\"mode\"\n name=\"revisions\"\n segmented\n class=\"pk-file-preview__modes u-segmented-fit mb-0\"\n :aria-label=\"$t('chatFilePreview.modes')\"\n :options=\"modes\">\n <!-- The short name where the long one leaves the\n versions no room on the line -->\n <template #markup>\n <span class=\"pk-file-preview__mode-long\">\n {{ $t('chatFilePreview.modeMarkup') }}\n </span>\n <span class=\"pk-file-preview__mode-short\">\n {{ $t('chatFilePreview.modeMarkupShort') }}\n </span>\n </template>\n </PkEditorRadioButtons>\n </div>\n <div class=\"pk-file-preview__actions\">\n <VvButton\n v-if=\"restorable\"\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :label=\"$t('chatFilePreview.restore')\"\n @click=\"emit('restore')\" />\n <VvButton\n :href=\"downloadUrl\"\n download\n modifiers=\"action-quiet\"\n icon=\"ri:download-line\"\n :title=\"$t('chatFilePreview.download')\"\n :aria-label=\"$t('chatFilePreview.download')\" />\n <VvButton\n v-if=\"resize === 'expand'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-line\"\n :title=\"$t('chatFilePreview.expand')\"\n :aria-label=\"$t('chatFilePreview.expand')\"\n @click=\"emit('resize')\" />\n <VvButton\n v-else-if=\"resize === 'shrink'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-exit-line\"\n :title=\"$t('chatFilePreview.shrink')\"\n :aria-label=\"$t('chatFilePreview.shrink')\"\n @click=\"emit('resize')\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:close-line\"\n :title=\"$t('chatFilePreview.close')\"\n :aria-label=\"$t('chatFilePreview.close')\"\n @click=\"emit('close')\" />\n </div>\n </header>\n <div class=\"pk-file-preview__body\">\n <div v-if=\"loading\" class=\"pk-file-preview__skeleton vv-skeleton\">\n <div\n v-for=\"i in 8\"\n :key=\"i\"\n class=\"vv-skeleton__item pk-file-preview__skeleton-line\"\n :class=\"i % 3 ? 'w-full' : 'w-128'\" />\n </div>\n <p v-else-if=\"error || !preview\" class=\"pk-file-preview__empty\">\n {{ $t('chatFilePreview.unavailable') }}\n </p>\n <PkWordPreview\n v-else-if=\"preview.kind === 'word'\"\n v-model:zoom=\"zoom\"\n v-model:fit=\"fit\"\n :preview\n :mode=\"hasRevisions ? mode : 'markup'\" />\n <PkSpreadsheetPreview\n v-else\n v-model:sheet=\"sheet\"\n v-model:zoom=\"zoom\"\n :preview />\n </div>\n </section>\n</template>\n\n<style lang=\"scss\">\n .pk-file-preview {\n container-type: inline-size;\n display: flex;\n flex-direction: column;\n min-height: 0;\n height: 100%;\n outline: none;\n background-color: var(--color-surface);\n color: var(--color-word-1);\n\n &__head {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n padding: var(--spacing-12) var(--spacing-12) var(--spacing-12)\n var(--spacing-md);\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__file {\n display: flex;\n flex: 1 1 12rem;\n align-items: center;\n gap: var(--spacing-12);\n min-width: 0;\n }\n\n &__tile {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-32);\n height: var(--spacing-32);\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n\n .vv-icon {\n width: var(--spacing-18);\n height: var(--spacing-18);\n }\n }\n\n // The colors the file chip of the chat gives the two kinds\n &__icon--word {\n color: #2b7de9;\n }\n\n &__icon--sheet {\n color: #1f9d57;\n }\n\n &__name {\n display: flex;\n flex-direction: column;\n min-width: 0;\n }\n\n &__title {\n overflow: hidden;\n font-size: var(--text-14);\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n &__note {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n &__tools {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n }\n\n &__versions {\n display: flex;\n align-items: center;\n gap: var(--spacing-2);\n }\n\n &__version {\n font-size: var(--text-14);\n font-weight: var(--font-semibold);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__actions {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n margin-left: auto;\n }\n\n // In a narrow frame the file and its actions keep the first line,\n // the versions and the revisions take the second.\n @container (width < 52rem) {\n &__file {\n order: 1;\n }\n\n &__actions {\n order: 2;\n }\n\n &__tools {\n order: 3;\n flex-basis: 100%;\n }\n\n // The ways to show the revisions fill what the versions leave,\n // or go to a line of their own: never narrower than their words\n &__tools &__modes {\n flex: 1 1 auto;\n }\n }\n\n &__mode-short {\n display: none;\n }\n\n // Below this the long name puts the modes on a line of their own\n @container (width < 38rem) {\n &__mode-long {\n display: none;\n }\n\n &__mode-short {\n display: inline;\n }\n }\n\n // A phone gives them a line of their own, with less padding\n @container (width < 30rem) {\n &__tools &__modes {\n flex: 1 1 100%;\n\n .vv-radio {\n padding-inline: var(--spacing-4);\n }\n }\n }\n\n // The document scrolls inside its viewer, so the head stays in view\n &__body {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n background-color: var(--color-surface-1);\n }\n\n &__skeleton {\n width: min(42rem, calc(100% - 2 * var(--spacing-md)));\n margin: var(--spacing-md) auto;\n padding: var(--spacing-lg);\n box-sizing: border-box;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n background-color: var(--color-surface);\n }\n\n &__skeleton-line {\n height: var(--spacing-12);\n margin-bottom: var(--spacing-12);\n border-radius: var(--rounded);\n }\n\n &__empty {\n margin: var(--spacing-lg) var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-14);\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, watch } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { ChatFilePreview } from 'models'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import PkSpreadsheetPreview from './PkSpreadsheetPreview.vue'\n import PkWordPreview from './PkWordPreview.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * The viewer of a Word document or a spreadsheet stored in the chat (spec\n * `chat-office-files.md`, F6, items 3 and 4, and their follow-ups): a head\n * with the file, its versions in the conversation, how to show the\n * revisions of a Word document, restore, download, a larger frame and\n * close, over the document drawn as Word or Excel draws it. The same\n * viewer goes in the panel beside the chat and in a dialog over it.\n */\n const props = defineProps<{\n kind: 'word' | 'spreadsheet'\n /** The name of the file, not of its version. */\n filename: string\n version?: number\n /** The versions of the file in the conversation, from 1. */\n versions?: number[]\n /** The authenticated download URL of the shown version. */\n downloadUrl: string\n preview?: ChatFilePreview\n loading?: boolean\n error?: boolean\n /** The shown version can be written again as the newest one. */\n restorable?: boolean\n /** Offers to move to the larger frame, or back to the panel. */\n resize?: 'expand' | 'shrink'\n }>()\n\n const emit = defineEmits<{\n close: []\n version: [version: number]\n restore: []\n resize: []\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const versions = computed(() => props.versions ?? [])\n const position = computed(() =>\n props.version ? versions.value.indexOf(props.version) : -1,\n )\n const previous = computed(() =>\n position.value > 0 ? versions.value[position.value - 1] : undefined,\n )\n const next = computed(() =>\n position.value >= 0 && position.value < versions.value.length - 1\n ? versions.value[position.value + 1]\n : undefined,\n )\n\n /**\n * How a Word document with tracked changes is drawn, and the sheet and\n * the zoom: models, so they stay when the viewer moves between the panel\n * and the dialog, where it is drawn anew.\n */\n const mode = defineModel<WordPreviewMode>('mode', { default: 'markup' })\n const sheet = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const fit = defineModel<boolean>('fit', { default: true })\n const modes = computed(() => [\n { value: 'markup', label: $t('chatFilePreview.modeMarkup') },\n { value: 'accepted', label: $t('chatFilePreview.modeAccepted') },\n { value: 'original', label: $t('chatFilePreview.modeOriginal') },\n ])\n const hasRevisions = computed(\n () =>\n props.preview?.kind === 'word' &&\n props.preview.revisionAuthors.length > 0,\n )\n // Another version starts with its revisions in sight.\n watch(\n () => props.version,\n () => {\n mode.value = 'markup'\n },\n )\n</script>\n\n<template>\n <!-- A dialog gives the focus to its first control, the arrow of the\n versions: it goes to the viewer, and the keyboard starts from here -->\n <section\n class=\"pk-file-preview\"\n :aria-label=\"filename\"\n tabindex=\"-1\"\n autofocus>\n <header class=\"pk-file-preview__head\">\n <div class=\"pk-file-preview__file\">\n <span class=\"pk-file-preview__tile\" aria-hidden=\"true\">\n <VvIcon\n :name=\"\n kind === 'word'\n ? 'ri:file-word-2-line'\n : 'ri:file-excel-2-line'\n \"\n :class=\"\n kind === 'word'\n ? 'pk-file-preview__icon--word'\n : 'pk-file-preview__icon--sheet'\n \" />\n </span>\n <div class=\"pk-file-preview__name\">\n <strong class=\"pk-file-preview__title\">\n {{ filename }}\n </strong>\n <span class=\"pk-file-preview__note\">\n {{ $t('chatFilePreview.readOnly') }}\n </span>\n </div>\n </div>\n <div\n v-if=\"(version && versions.length > 1) || hasRevisions\"\n class=\"pk-file-preview__tools\">\n <nav\n v-if=\"version && versions.length > 1\"\n class=\"pk-file-preview__versions\"\n :aria-label=\"$t('chatFilePreview.versions')\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-left-s-line\"\n :aria-label=\"$t('chatFilePreview.previousVersion')\"\n :disabled=\"!previous\"\n @click=\"previous && emit('version', previous)\" />\n <span class=\"pk-file-preview__version\">\n {{\n $t('chatFilePreview.versionOf', {\n version,\n count: versions.length,\n })\n }}\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-right-s-line\"\n :aria-label=\"$t('chatFilePreview.nextVersion')\"\n :disabled=\"!next\"\n @click=\"next && emit('version', next)\" />\n </nav>\n <PkEditorRadioButtons\n v-if=\"hasRevisions\"\n v-model=\"mode\"\n name=\"revisions\"\n segmented\n class=\"pk-file-preview__modes u-segmented-fit mb-0\"\n :aria-label=\"$t('chatFilePreview.modes')\"\n :options=\"modes\">\n <!-- The short name where the long one leaves the\n versions no room on the line -->\n <template #markup>\n <span class=\"pk-file-preview__mode-long\">\n {{ $t('chatFilePreview.modeMarkup') }}\n </span>\n <span class=\"pk-file-preview__mode-short\">\n {{ $t('chatFilePreview.modeMarkupShort') }}\n </span>\n </template>\n </PkEditorRadioButtons>\n </div>\n <div class=\"pk-file-preview__actions\">\n <VvButton\n v-if=\"restorable\"\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :label=\"$t('chatFilePreview.restore')\"\n @click=\"emit('restore')\" />\n <VvButton\n :href=\"downloadUrl\"\n download\n modifiers=\"action-quiet\"\n icon=\"ri:download-line\"\n :title=\"$t('chatFilePreview.download')\"\n :aria-label=\"$t('chatFilePreview.download')\" />\n <VvButton\n v-if=\"resize === 'expand'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-line\"\n :title=\"$t('chatFilePreview.expand')\"\n :aria-label=\"$t('chatFilePreview.expand')\"\n @click=\"emit('resize')\" />\n <VvButton\n v-else-if=\"resize === 'shrink'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-exit-line\"\n :title=\"$t('chatFilePreview.shrink')\"\n :aria-label=\"$t('chatFilePreview.shrink')\"\n @click=\"emit('resize')\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:close-line\"\n :title=\"$t('chatFilePreview.close')\"\n :aria-label=\"$t('chatFilePreview.close')\"\n @click=\"emit('close')\" />\n </div>\n </header>\n <div class=\"pk-file-preview__body\">\n <div v-if=\"loading\" class=\"pk-file-preview__skeleton vv-skeleton\">\n <div\n v-for=\"i in 8\"\n :key=\"i\"\n class=\"vv-skeleton__item pk-file-preview__skeleton-line\"\n :class=\"i % 3 ? 'w-full' : 'w-128'\" />\n </div>\n <p v-else-if=\"error || !preview\" class=\"pk-file-preview__empty\">\n {{ $t('chatFilePreview.unavailable') }}\n </p>\n <PkWordPreview\n v-else-if=\"preview.kind === 'word'\"\n v-model:zoom=\"zoom\"\n v-model:fit=\"fit\"\n :preview\n :mode=\"hasRevisions ? mode : 'markup'\" />\n <PkSpreadsheetPreview\n v-else\n v-model:sheet=\"sheet\"\n v-model:zoom=\"zoom\"\n :preview />\n </div>\n </section>\n</template>\n\n<style lang=\"scss\">\n .pk-file-preview {\n container-type: inline-size;\n display: flex;\n flex-direction: column;\n min-height: 0;\n height: 100%;\n outline: none;\n background-color: var(--color-surface);\n color: var(--color-word-1);\n\n &__head {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n padding: var(--spacing-12) var(--spacing-12) var(--spacing-12)\n var(--spacing-md);\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__file {\n display: flex;\n flex: 1 1 12rem;\n align-items: center;\n gap: var(--spacing-12);\n min-width: 0;\n }\n\n &__tile {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-32);\n height: var(--spacing-32);\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n\n .vv-icon {\n width: var(--spacing-18);\n height: var(--spacing-18);\n }\n }\n\n // The colors the file chip of the chat gives the two kinds\n &__icon--word {\n color: #2b7de9;\n }\n\n &__icon--sheet {\n color: #1f9d57;\n }\n\n &__name {\n display: flex;\n flex-direction: column;\n min-width: 0;\n }\n\n &__title {\n overflow: hidden;\n font-size: var(--text-14);\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n &__note {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n &__tools {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n }\n\n &__versions {\n display: flex;\n align-items: center;\n gap: var(--spacing-2);\n }\n\n &__version {\n font-size: var(--text-14);\n font-weight: var(--font-semibold);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__actions {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n margin-left: auto;\n }\n\n // In a narrow frame the file and its actions keep the first line,\n // the versions and the revisions take the second.\n @container (width < 52rem) {\n &__file {\n order: 1;\n }\n\n &__actions {\n order: 2;\n }\n\n &__tools {\n order: 3;\n flex-basis: 100%;\n }\n\n // The ways to show the revisions fill what the versions leave,\n // or go to a line of their own: never narrower than their words\n &__tools &__modes {\n flex: 1 1 auto;\n }\n }\n\n &__mode-short {\n display: none;\n }\n\n // Below this the long name puts the modes on a line of their own\n @container (width < 38rem) {\n &__mode-long {\n display: none;\n }\n\n &__mode-short {\n display: inline;\n }\n }\n\n // A phone gives them a line of their own, with less padding\n @container (width < 30rem) {\n &__tools &__modes {\n flex: 1 1 100%;\n\n .vv-radio {\n padding-inline: var(--spacing-4);\n }\n }\n }\n\n // The document scrolls inside its viewer, so the head stays in view\n &__body {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n background-color: var(--color-surface-1);\n }\n\n &__skeleton {\n width: min(42rem, calc(100% - 2 * var(--spacing-md)));\n margin: var(--spacing-md) auto;\n padding: var(--spacing-lg);\n box-sizing: border-box;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n background-color: var(--color-surface);\n }\n\n &__skeleton-line {\n height: var(--spacing-12);\n margin-bottom: var(--spacing-12);\n border-radius: var(--rounded);\n }\n\n &__empty {\n margin: var(--spacing-lg) var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-14);\n text-align: center;\n }\n }\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;A,qHA2BU4K,IAAe,IACfC,IAAa,IACbC,IAAc,IACdC,IAAiB,I;;;;;;;;;;EARvB,IAAMM,IAAQC,GAER,EAAE,GAAGC,GAAI,cAAWrC,EAAQ,EAAE,UAAU,SAAS,CAAC,GAUlDsC,IAAStK,EAAmBoK,GAAC,OAAuB,GACpDG,IAAOvK,EAAmBoK,GAAC,MAAsB,GACjDI,IAAW1D,EAA+B,UAAU,GAIpD,EAAE,OAAO2D,GAAW,QAAQC,MAAevC,GAC7CqC,GACA;GAAE,OAAO;GAAG,QAAQ;EAAE,GACtB,EAAE,KAAK,aAAa,CACxB,GACMG,IAAQxD,QACJgD,EAAM,QAAQ,OAAOG,EAAO,UAAUH,EAAM,QAAQ,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AAA,CAAE,CAAA,uBAAA;MACT,cAAY9E,EAAA8E,CAAA,CAAE,CAAA,uBAAA;MACd,SAAK,AAAA2F,EAAA,QAAA,MAAE0H,EAAI,OAAA;;;G,IAGxBvS,EAsBM,OAtBNgS,IAsBM,CArBS/M,EAAA,WAAXnF,EAAA,GAAAC,EAMM,OANNkS,IAMM,EALFnS,EAAA,GAAAC,EAI0CU,GAAA,MAAAC,EAH1B,IAAL,MADXV,EAI0C,OAAA;IAFrC,KAAK+G;IACN,OAAK7G,EAAA,CAAC,oDACE6G,IAAC,IAAA,WAAA,OAAA,CAAA;G,wBAEH9B,EAAA,SAAK,CAAKA,EAAA,WAAxBnF,EAAA,GAAAC,EAEI,KAFJmS,IAEI/R,EADGC,EAAA8E,CAAA,CAAE,CAAA,6BAAA,CAAA,GAAA,CAAA,KAGMD,EAAA,QAAQ,SAAI,UAD3BnF,EAAA,GAAAQ,EAK6CK,IAAA;;IAHjC,MAAMyE,EAAA;IAAA,iBAAA,AAAAyF,EAAA,QAAA,MAAA,EAAI,QAAAI;IACV,KAAK4E,EAAA;IAAA,gBAAA,AAAAhF,EAAA,QAAA,MAAA,EAAG,QAAAI;IACf,SAAAhG,EAAA;IACA,MAAM4N,EAAA,QAAeF,EAAA,QAAI;;;;;;G,OAC9B7S,EAAA,GAAAQ,EAIeM,IAAA;;IAFH,OAAO4E,EAAA;IAAA,kBAAA,AAAAqF,EAAA,QAAA,MAAA,EAAK,QAAAI;IACZ,MAAM7F,EAAA;IAAA,iBAAA,AAAAyF,EAAA,SAAA,MAAA,EAAI,QAAAI;IACjB,SAAAhG,EAAA"}
1
+ {"version":3,"file":"PkFilePreview-Bcdfci6i.js","names":["_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","_hoisted_17","_hoisted_18","_useModel","__unplugin_components_0","_openBlock","_createElementBlock","_createElementVNode","_unref","_toDisplayString","_normalizeClass","_normalizeStyle","_Fragment","_renderList","_isMemoSame","_withModifiers","_createCommentVNode","_createTextVNode","_createVNode","_sfc_main","_style_0","_hoisted_1","_hoisted_2","_hoisted_3","_openBlock","_createElementBlock","_Fragment","_renderList","_toDisplayString","_unref","_normalizeStyle","_sfc_main","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_openBlock","_createElementBlock","_normalizeClass","_Fragment","_renderList","_normalizeStyle","_createCommentVNode","_createElementVNode","_createVNode","PkWordPreviewRuns","_toDisplayString","_sfc_main","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","_useModel","__unplugin_components_0","_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_toDisplayString","_createCommentVNode","_Fragment","_renderList","_normalizeStyle","_createBlock","PkWordPreviewBlock","_createVNode","_sfc_main","_style_0","_useModel","__unplugin_components_0","__unplugin_components_1","_openBlock","_createElementBlock","_createElementVNode","_createVNode","_normalizeClass","_toDisplayString","_unref","_createCommentVNode","_createBlock","PkEditorRadioButtons","_withCtx","_Fragment","_renderList","PkWordPreview","PkSpreadsheetPreview","_sfc_main","_style_0","__exportAll","normalizeClass","nextTick","onBeforeUnmount","useModel","onMounted","mergeModels","normalizeStyle","watch","createVNode","init_shared_esm_bundler","renderList","useTemplateRef","createBlock","withModifiers","Fragment","ref","computed","isMemoSame","init_runtime_core_esm_bundler","toDisplayString","init_reactivity_esm_bundler","init_runtime_dom_esm_bundler","withCtx","createCommentVNode","defineComponent","unref","createTextVNode","createElementBlock","openBlock","useI18n","wordLineFactor","wordFontStack","useElementSize","Ce","VvButtonLocalized","_plugin_vue_export_helper_default","PkEditorRadioButtons_default","_hoisted_1$4","_hoisted_2$4","_hoisted_3$4","_hoisted_4$3","_hoisted_5$2","_hoisted_6$2","_hoisted_7$2","_hoisted_8$2","_hoisted_9$2","_hoisted_10$2","_hoisted_11$2","_hoisted_12$2","_hoisted_13$2","_hoisted_14$2","_hoisted_15$2","_hoisted_16$2","_hoisted_17$1","_hoisted_18$1","COLUMN_WIDTH","ROW_HEIGHT","HEAD_HEIGHT","ROW_HEAD_WIDTH","PkSpreadsheetPreview_default","\"sheet\"","\"sheetModifiers\"","\"zoom\"","\"zoomModifiers\"","props","__props","$t","active","zoom","scrollEl","viewWidth","viewHeight","sheet","letters","s","c","n","columns","hidden","widths","out","used","room","col","width","gridWidth","columnsKey","rowObjects","rows","heights","r","fill","last","known","seen","i","row","cells","map","covered","dr","dc","cellAt","shownSpan","span","styleOf","cell","numberText","digits","locale","v","dateText","date","textOf","barText","border","side","cellCss","numeric","css","lines","pad","frozenCss","f","anchor","focus","range","inRange","isFocus","rowSelection","dragging","pick","event","extend","move","step","rowList","colList","ownerOf","at","start","next","nr","nc","focusCell","stats","r1","r2","c1","c2","count","sum","numbers","first","zoomBy","_component_VvButton","createBaseVNode","_cache","_memo","_cached","_item","$event","_hoisted_1$3","_hoisted_2$3","_hoisted_3$3","PkWordPreviewRuns_default","shown","run","marked","cssOf","changeCss","titleOf","k","_hoisted_1$2","_hoisted_2$2","_hoisted_3$2","_hoisted_4$2","PkWordPreviewBlock_default","paragraphCss","labelCss","hanging","changed","tableRow","total","a","b","w","rowChanged","_hoisted_1$1","_hoisted_2$1","_hoisted_3$1","_hoisted_4$1","_hoisted_5$1","_hoisted_6$1","_hoisted_7$1","_hoisted_8$1","_hoisted_9$1","_hoisted_10$1","_hoisted_11$1","_hoisted_12$1","_hoisted_13$1","_hoisted_14$1","_hoisted_15$1","_hoisted_16$1","_hoisted_17","_hoisted_18","_hoisted_19","_hoisted_20","_hoisted_21","_hoisted_22","_hoisted_23","_hoisted_24","PX","PkWordPreview_default","\"fit\"","\"fitModifiers\"","kept","runs","hasText","items","block","rootEl","measureEl","scrollWidth","paged","wide","page","textCss","pageCss","measureCss","measure","els","el","pages","all","h","item","fit","manual","currentPage","currentHeading","locate","box","pageEls","heading","headings","frame","onScroll","clip","changes","removed","added","tab","sideOpen","goTo","key","words","authors","p","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","PkFilePreview_vue_vue_type_script_setup_true_lang_default","\"mode\"","\"modeModifiers\"","__emit","emit","versions","position","previous","mode","modes","hasRevisions","_component_VvIcon","PkFilePreview_vue_vue_type_style_index_0_inline_lang_default","PkFilePreview_exports","PkFilePreview_default"],"sources":["../../../../packages/components/src/chat/PkSpreadsheetPreview.vue","../../../../packages/components/src/chat/PkSpreadsheetPreview.vue","../../../../packages/components/src/chat/PkSpreadsheetPreview.vue","../../../../packages/components/src/chat/PkWordPreviewRuns.vue","../../../../packages/components/src/chat/PkWordPreviewRuns.vue","../../../../packages/components/src/chat/PkWordPreviewBlock.vue","../../../../packages/components/src/chat/PkWordPreviewBlock.vue","../../../../packages/components/src/chat/PkWordPreview.vue","../../../../packages/components/src/chat/PkWordPreview.vue","../../../../packages/components/src/chat/PkWordPreview.vue","../../../../packages/components/src/chat/PkFilePreview.vue","../../../../packages/components/src/chat/PkFilePreview.vue","../../../../packages/components/src/chat/PkFilePreview.vue"],"sourcesContent":["<script setup lang=\"ts\">\n import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n import type { CSSProperties } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type {\n SpreadsheetPreview,\n SpreadsheetPreviewCell,\n SpreadsheetPreviewStyle,\n } from 'models'\n\n /**\n * A spreadsheet stored in the chat, drawn as Excel draws it (spec\n * `chat-office-files.md`, F6, item 4, and the viewer of its follow-ups):\n * column letters and row numbers that stay in view, the widths, heights,\n * fonts, fills and borders of the file, merged cells and frozen panes.\n * A cell is picked with a click, a range with a drag or shift, and the\n * arrows move it: the formula bar shows its formula, the status bar the\n * sum of a range. The sheets are tabs at the bottom. The grid keeps the\n * file's white in the dark theme, as a page does; the bars around it\n * follow the theme. Framed by `PkFilePreview`.\n */\n const props = defineProps<{ preview: SpreadsheetPreview }>()\n\n const { t: $t, locale } = useI18n({ useScope: 'global' })\n\n /** Excel's defaults, in pixels. */\n const COLUMN_WIDTH = 64\n const ROW_HEIGHT = 20\n const HEAD_HEIGHT = 28\n const ROW_HEAD_WIDTH = 44\n\n // Models, so the sheet and the zoom stay when the viewer moves between\n // the panel and the dialog (`PkChatbotViewChat` keeps them).\n const active = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const scrollEl = useTemplateRef<HTMLDivElement>('scrollEl')\n // The border box, scroll bars included: the grid that fills the view\n // makes them appear, and measured without them the view shrank, the\n // grid changed again, and the two went on in a loop.\n const { width: viewWidth, height: viewHeight } = useElementSize(\n scrollEl,\n { width: 0, height: 0 },\n { box: 'border-box' },\n )\n const sheet = computed(\n () => props.preview.sheets[active.value] ?? props.preview.sheets[0],\n )\n watch(\n () => props.preview,\n () => {\n active.value = 0\n },\n )\n\n const letters = (n: number): string => {\n let s = ''\n for (let c = n; c > 0; c = Math.floor((c - 1) / 26)) {\n s = String.fromCharCode(65 + ((c - 1) % 26)) + s\n }\n return s\n }\n\n // Empty rows and columns after the data up to the edges of the view, as\n // Excel's grid goes on, unless the file goes on past what the preview\n // holds: an empty column there would say the sheet ends.\n const columns = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(\n s.columns.filter((c) => c.hidden).map((c) => c.col),\n )\n const widths = new Map(s.columns.map((c) => [c.col, c.width]))\n const out: Array<{ col: number; width: number }> = []\n let used = ROW_HEAD_WIDTH\n const room = viewWidth.value / zoom.value\n for (\n let col = 1;\n col <= s.lastColumn ||\n (!s.moreColumns && (col <= s.lastColumn + 2 || used < room));\n col++\n ) {\n if (hidden.has(col)) {\n continue\n }\n const width = widths.get(col) ?? COLUMN_WIDTH\n out.push({ col, width })\n used += width\n }\n return out\n })\n /** A fixed layout needs the table's width, or the columns shrink. */\n const gridWidth = computed(() =>\n columns.value.reduce((n, c) => n + c.width, ROW_HEAD_WIDTH),\n )\n /** The columns as a value: the same set at another zoom, for the memo. */\n const columnsKey = computed(() =>\n columns.value.map((c) => `${c.col}:${c.width}`).join(','),\n )\n // One object per row while its sheet is shown, so a row's memo holds\n // when the view adds rows to fill itself.\n const rowObjects = new WeakMap<\n object,\n Map<number, { row: number; height: number }>\n >()\n const rows = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(s.hiddenRows ?? [])\n const heights = new Map(s.rows.map((r) => [r.row, r.height]))\n const fill = Math.ceil(\n (viewHeight.value / zoom.value - HEAD_HEIGHT) / ROW_HEIGHT,\n )\n const last = s.moreRows\n ? s.lastRow\n : Math.max(s.lastRow + 5, fill + hidden.size)\n let known = rowObjects.get(s)\n if (!known) {\n known = new Map()\n rowObjects.set(s, known)\n }\n const seen = known\n return Array.from({ length: last }, (_, i) => i + 1)\n .filter((row) => !hidden.has(row))\n .map((row) => {\n let r = seen.get(row)\n if (!r) {\n r = { row, height: heights.get(row) ?? ROW_HEIGHT }\n seen.set(row, r)\n }\n return r\n })\n })\n const cells = computed(() => {\n const map = new Map<string, SpreadsheetPreviewCell>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n map.set(`${r.row},${c.col}`, c)\n }\n }\n return map\n })\n /** The cells a merge covers, each with the first cell that draws it. */\n const covered = computed(() => {\n const map = new Map<string, { row: number; col: number }>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n if (!c.span) {\n continue\n }\n for (let dr = 0; dr < c.span.rows; dr++) {\n for (let dc = 0; dc < c.span.cols; dc++) {\n if (dr || dc) {\n map.set(`${r.row + dr},${c.col + dc}`, {\n row: r.row,\n col: c.col,\n })\n }\n }\n }\n }\n }\n return map\n })\n const cellAt = (row: number, col: number) =>\n cells.value.get(`${row},${col}`)\n /**\n * A merge's span over the rows and columns the grid draws: the file\n * counts the hidden ones too, and the merge ran into the next column.\n */\n const shownSpan = (row: number, col: number) => {\n const span = cellAt(row, col)?.span\n if (!span) {\n return undefined\n }\n return {\n rows: rows.value.filter(\n (r) => r.row >= row && r.row < row + span.rows,\n ).length,\n cols: columns.value.filter(\n (c) => c.col >= col && c.col < col + span.cols,\n ).length,\n }\n }\n const styleOf = (\n cell: SpreadsheetPreviewCell | undefined,\n ): SpreadsheetPreviewStyle | undefined =>\n cell?.style === undefined ? undefined : props.preview.styles[cell.style]\n\n // #region the text of a cell\n const numberText = (cell: SpreadsheetPreviewCell, v: number) => {\n const digits =\n cell.decimals !== undefined\n ? {\n minimumFractionDigits: cell.decimals,\n maximumFractionDigits: cell.maxDecimals ?? cell.decimals,\n }\n : { maximumFractionDigits: 10 }\n return new Intl.NumberFormat(locale.value, {\n ...digits,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n ...(cell.format === 'currency' && cell.currency\n ? { style: 'currency', currency: cell.currency }\n : {}),\n }).format(v)\n }\n\n const dateText = (v: string) => {\n const date = new Date(`${v}T00:00:00Z`)\n return Number.isNaN(date.getTime())\n ? v\n : new Intl.DateTimeFormat(locale.value, {\n dateStyle: 'short',\n timeZone: 'UTC',\n }).format(date)\n }\n\n /** The cell's text: a number in the reader's language, a date, a word. */\n const textOf = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.missing) {\n return '—'\n }\n const v = cell.value\n if (v === undefined) {\n return ''\n }\n if (typeof v === 'boolean') {\n return v ? $t('chatFilePreview.true') : $t('chatFilePreview.false')\n }\n if (cell.format === 'date' && typeof v === 'string') {\n return dateText(v)\n }\n if (typeof v === 'number') {\n return numberText(cell, v)\n }\n return v\n }\n\n /** What Excel's bar shows: the formula, or the value as typed. */\n const barText = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.formula) {\n return `=${cell.formula}`\n }\n const v = cell.value\n if (typeof v === 'number') {\n return new Intl.NumberFormat(locale.value, {\n useGrouping: false,\n maximumFractionDigits: 15,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n }).format(v)\n }\n return textOf(cell)\n }\n // #endregion\n\n // #region the look of a cell\n const border = (side?: { color: string; width: number }) =>\n side ? `${side.width}px solid ${side.color}` : undefined\n\n const cellCss = (\n cell: SpreadsheetPreviewCell | undefined,\n row: number,\n col: number,\n ): CSSProperties => {\n const s = styleOf(cell)\n const v = cell?.value\n const numeric = typeof v === 'number' || !!cell?.missing\n const css: CSSProperties = {\n textAlign:\n s?.align ??\n (numeric\n ? 'right'\n : typeof v === 'boolean' || cell?.format === 'error'\n ? 'center'\n : 'left'),\n verticalAlign:\n s?.valign === 'top'\n ? 'top'\n : s?.valign === 'middle'\n ? 'middle'\n : 'bottom',\n whiteSpace: s?.wrap ? 'pre-wrap' : 'nowrap',\n }\n if (s?.bold) {\n css.fontWeight = 700\n }\n if (s?.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n s?.underline ? 'underline' : '',\n s?.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (s?.size) {\n css.fontSize = `${s.size}pt`\n }\n if (s?.color) {\n css.color = s.color\n }\n if (s?.fill) {\n css.backgroundColor = s.fill\n }\n if (s?.indent) {\n const pad = `${4 + s.indent * 9}px`\n if (css.textAlign === 'right') {\n css.paddingRight = pad\n } else {\n css.paddingLeft = pad\n }\n }\n css.borderTop = border(s?.borders?.top)\n css.borderRight = border(s?.borders?.right)\n css.borderBottom = border(s?.borders?.bottom)\n css.borderLeft = border(s?.borders?.left)\n Object.assign(css, frozenCss(row, col))\n return css\n }\n\n /** Where a frozen row or column sticks, under the headers. */\n const frozenCss = (row: number, col: number): CSSProperties => {\n const f = sheet.value?.frozen\n if (!f) {\n return {}\n }\n const css: CSSProperties = {}\n if (row <= f.rows) {\n css.position = 'sticky'\n css.top = `${\n HEAD_HEIGHT +\n rows.value\n .filter((r) => r.row < row)\n .reduce((n, r) => n + r.height, 0)\n }px`\n css.zIndex = 2\n }\n if (col <= f.cols) {\n css.position = 'sticky'\n css.left = `${\n ROW_HEAD_WIDTH +\n columns.value\n .filter((c) => c.col < col)\n .reduce((n, c) => n + c.width, 0)\n }px`\n css.zIndex = row <= f.rows ? 3 : 2\n }\n return css\n }\n // #endregion\n\n // #region selection\n type At = { row: number; col: number }\n const anchor = ref<At>({ row: 1, col: 1 })\n const focus = ref<At>({ row: 1, col: 1 })\n watch(sheet, () => {\n anchor.value = { row: 1, col: 1 }\n focus.value = { row: 1, col: 1 }\n })\n const range = computed(() => ({\n r1: Math.min(anchor.value.row, focus.value.row),\n r2: Math.max(anchor.value.row, focus.value.row),\n c1: Math.min(anchor.value.col, focus.value.col),\n c2: Math.max(anchor.value.col, focus.value.col),\n }))\n const inRange = (row: number, col: number) =>\n row >= range.value.r1 &&\n row <= range.value.r2 &&\n col >= range.value.c1 &&\n col <= range.value.c2\n const isFocus = (row: number, col: number) =>\n focus.value.row === row && focus.value.col === col\n /**\n * What a row draws of the selection. A row is drawn again only when\n * this, its sheet, the columns or the language of the numbers change: a\n * sheet of thousands of cells drew them all at each step of a drag,\n * seconds per selection.\n */\n const rowSelection = (row: number) =>\n row >= range.value.r1 && row <= range.value.r2\n ? `${range.value.c1}:${range.value.c2}:${\n focus.value.row === row ? focus.value.col : 0\n }`\n : ''\n\n const dragging = ref(false)\n const pick = (row: number, col: number, event: MouseEvent) => {\n // The click keeps its default off (no text selection while dragging),\n // so the grid takes the keyboard here.\n scrollEl.value?.focus({ preventScroll: true })\n focus.value = { row, col }\n if (!event.shiftKey) {\n anchor.value = { row, col }\n }\n dragging.value = true\n }\n const extend = (row: number, col: number) => {\n if (dragging.value) {\n focus.value = { row, col }\n }\n }\n\n const move = (event: KeyboardEvent) => {\n const steps: Record<string, [number, number]> = {\n ArrowUp: [-1, 0],\n ArrowDown: [1, 0],\n ArrowLeft: [0, -1],\n ArrowRight: [0, 1],\n Enter: [1, 0],\n Tab: [0, 1],\n }\n const step = steps[event.key]\n if (!step) {\n return\n }\n event.preventDefault()\n const rowList = rows.value.map((r) => r.row)\n const colList = columns.value.map((c) => c.col)\n const ownerOf = (at: At) =>\n covered.value.get(`${at.row},${at.col}`) ?? at\n // As in Excel, a merge is one cell: the step goes past the cells it\n // covers, and a step into one lands on the cell that draws it.\n const start = ownerOf(focus.value)\n let r = rowList.indexOf(focus.value.row)\n let c = colList.indexOf(focus.value.col)\n let next = start\n for (;;) {\n const nr = Math.min(rowList.length - 1, Math.max(0, r + step[0]))\n const nc = Math.min(colList.length - 1, Math.max(0, c + step[1]))\n if (nr === r && nc === c) {\n break\n }\n r = nr\n c = nc\n next = ownerOf({ row: rowList[r], col: colList[c] })\n if (next.row !== start.row || next.col !== start.col) {\n break\n }\n }\n focus.value = next\n if (!event.shiftKey) {\n anchor.value = next\n }\n nextTick(() =>\n scrollEl.value\n ?.querySelector('[data-focus]')\n ?.scrollIntoView({ block: 'nearest', inline: 'nearest' }),\n )\n }\n\n const focusCell = computed(() => cellAt(focus.value.row, focus.value.col))\n /** Count, average and sum of a range, as Excel's status bar shows them. */\n const stats = computed(() => {\n const { r1, r2, c1, c2 } = range.value\n if (r1 === r2 && c1 === c2) {\n return undefined\n }\n let count = 0\n let sum = 0\n let numbers = 0\n let first: SpreadsheetPreviewCell | undefined\n for (let r = r1; r <= r2; r++) {\n for (let c = c1; c <= c2; c++) {\n const cell = cellAt(r, c)\n if (!cell || (cell.value === undefined && !cell.missing)) {\n continue\n }\n count++\n if (typeof cell.value === 'number') {\n sum += cell.value\n numbers++\n first ??= cell\n }\n }\n }\n if (!count) {\n return undefined\n }\n return {\n count,\n sum: first ? numberText(first, sum) : undefined,\n // One number among text is still an average, as in Excel\n average: first ? numberText(first, sum / numbers) : undefined,\n }\n })\n // #endregion\n\n // #region zoom\n const zoomBy = (step: number) => {\n zoom.value = Math.min(\n 2,\n Math.max(0.5, Math.round((zoom.value + step) * 10) / 10),\n )\n }\n // #endregion\n</script>\n\n<template>\n <div class=\"pk-spreadsheet-preview\">\n <div class=\"pk-spreadsheet-preview__bar\">\n <span\n class=\"pk-spreadsheet-preview__ref\"\n :aria-label=\"$t('chatFilePreview.cell')\">\n {{ letters(focus.col) }}{{ focus.row }}\n </span>\n <span class=\"pk-spreadsheet-preview__fx\" aria-hidden=\"true\"\n >fx</span\n >\n <output\n class=\"pk-spreadsheet-preview__formula\"\n :aria-label=\"$t('chatFilePreview.formulaBar')\">\n {{ barText(focusCell) }}\n </output>\n </div>\n <div\n ref=\"scrollEl\"\n class=\"pk-spreadsheet-preview__scroll\"\n tabindex=\"0\"\n role=\"grid\"\n :aria-label=\"sheet?.name\"\n @keydown=\"move\"\n @mouseup=\"dragging = false\"\n @mouseleave=\"dragging = false\">\n <table\n v-if=\"sheet\"\n class=\"pk-spreadsheet-preview__grid\"\n :class=\"{\n 'pk-spreadsheet-preview__grid--lines': sheet.gridlines,\n }\"\n :style=\"{ zoom, width: `${gridWidth}px` }\">\n <colgroup>\n <col :style=\"{ width: `${ROW_HEAD_WIDTH}px` }\" />\n <col\n v-for=\"c in columns\"\n :key=\"c.col\"\n :style=\"{ width: `${c.width}px` }\" />\n </colgroup>\n <thead>\n <tr :style=\"{ height: `${HEAD_HEIGHT}px` }\">\n <th class=\"pk-spreadsheet-preview__corner\" />\n <th\n v-for=\"c in columns\"\n :key=\"c.col\"\n scope=\"col\"\n class=\"pk-spreadsheet-preview__head\"\n :class=\"{\n 'pk-spreadsheet-preview__head--current':\n c.col >= range.c1 && c.col <= range.c2,\n }\">\n {{ letters(c.col) }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n v-for=\"r in rows\"\n :key=\"r.row\"\n v-memo=\"[\n r,\n sheet,\n columnsKey,\n locale,\n rowSelection(r.row),\n ]\"\n :style=\"{ height: `${r.height}px` }\">\n <th\n scope=\"row\"\n class=\"pk-spreadsheet-preview__row\"\n :class=\"{\n 'pk-spreadsheet-preview__row--current':\n r.row >= range.r1 && r.row <= range.r2,\n }\"\n :style=\"\n sheet.frozen && r.row <= sheet.frozen.rows\n ? {\n ...frozenCss(r.row, 0),\n left: 0,\n zIndex: 4,\n }\n : undefined\n \">\n {{ r.row }}\n </th>\n <template v-for=\"c in columns\" :key=\"c.col\">\n <td\n v-if=\"!covered.has(`${r.row},${c.col}`)\"\n :rowspan=\"shownSpan(r.row, c.col)?.rows\"\n :colspan=\"shownSpan(r.row, c.col)?.cols\"\n class=\"pk-spreadsheet-preview__cell\"\n :class=\"{\n 'pk-spreadsheet-preview__cell--range':\n inRange(r.row, c.col) &&\n !isFocus(r.row, c.col),\n 'pk-spreadsheet-preview__cell--missing':\n cellAt(r.row, c.col)?.missing,\n }\"\n :style=\"\n cellCss(cellAt(r.row, c.col), r.row, c.col)\n \"\n :data-focus=\"\n isFocus(r.row, c.col) ? '' : undefined\n \"\n :title=\"\n cellAt(r.row, c.col)?.missing\n ? $t('chatFilePreview.missingValue')\n : undefined\n \"\n @mousedown.prevent=\"pick(r.row, c.col, $event)\"\n @mouseenter=\"extend(r.row, c.col)\">\n {{ textOf(cellAt(r.row, c.col)) }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <p\n v-if=\"sheet && (sheet.moreRows || sheet.moreColumns)\"\n class=\"pk-spreadsheet-preview__more\">\n <template v-if=\"sheet.moreRows\">\n {{ $t('chatFilePreview.moreRows', sheet.moreRows) }}\n </template>\n <template v-if=\"sheet.moreColumns\">\n {{ $t('chatFilePreview.moreColumns', sheet.moreColumns) }}\n </template>\n </p>\n </div>\n <nav\n class=\"pk-spreadsheet-preview__sheets\"\n :aria-label=\"$t('chatFilePreview.sheets')\">\n <button\n v-for=\"(s, i) in preview.sheets\"\n :key=\"s.name\"\n type=\"button\"\n class=\"pk-spreadsheet-preview__sheet\"\n :aria-current=\"i === active ? 'page' : undefined\"\n @click=\"active = i\">\n {{ s.name }}\n </button>\n </nav>\n <div class=\"pk-spreadsheet-preview__status\">\n <p class=\"pk-spreadsheet-preview__info\">\n <span\n v-if=\"preview.staleFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.staleFormulas')\">\n {{ $t('chatFilePreview.staleFormulas') }}\n </span>\n <span\n v-else-if=\"preview.computedFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.computedFormulas')\">\n {{ $t('chatFilePreview.computedFormulas') }}\n </span>\n <span v-if=\"stats\" class=\"pk-spreadsheet-preview__stats\">\n <span\n v-if=\"stats.average\"\n class=\"pk-spreadsheet-preview__average\">\n {{ $t('chatFilePreview.average') }} {{ stats.average }}\n </span>\n <span>\n {{ $t('chatFilePreview.count') }} {{ stats.count }}\n </span>\n <span v-if=\"stats.sum\">\n {{ $t('chatFilePreview.sum') }} {{ stats.sum }}\n </span>\n </span>\n </p>\n <div class=\"pk-spreadsheet-preview__zoom\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.5\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-spreadsheet-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-spreadsheet-preview {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n // Excel's green marks the active cell, its column and row and the\n // current sheet, as in Excel (decided 2026-10-29). The cells keep\n // their paper in both themes; the headers lighten it on the dark one.\n --pk-spreadsheet-green: #217346;\n --pk-spreadsheet-green-head: #217346;\n\n // The formula bar: the cell, fx and its content, as in Excel\n &__bar {\n display: flex;\n align-items: stretch;\n min-height: var(--spacing-40);\n border-bottom: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n font-size: var(--text-14);\n }\n\n &__ref {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n width: var(--spacing-96);\n padding: 0 var(--spacing-12);\n box-sizing: border-box;\n border-right: var(--border) solid var(--color-surface-3);\n font-variant-numeric: tabular-nums;\n }\n\n &__fx {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-40);\n border-right: var(--border) solid var(--color-surface-3);\n color: var(--color-word-3);\n font-family: Georgia, serif;\n font-style: italic;\n }\n\n &__formula {\n display: flex;\n flex: 1;\n align-items: center;\n min-width: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n // The grid scrolls both ways; its headers stay\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n background-color: #fff;\n outline: none;\n cursor: cell;\n\n &:focus-visible {\n box-shadow: inset 0 0 0 var(--spacing-2)\n var(--input-focus-color);\n }\n }\n\n &__grid {\n border-collapse: collapse;\n table-layout: fixed;\n color: #000;\n font-family: Calibri, Carlito, 'Segoe UI', Arial, sans-serif;\n font-size: 11pt;\n user-select: none;\n\n td {\n overflow: hidden;\n max-width: 0;\n padding: 0 var(--spacing-4);\n background-color: #fff;\n line-height: 1.2;\n text-overflow: clip;\n }\n\n &--lines td {\n border: var(--border) solid #e1e1e1;\n }\n }\n\n // The letters and the numbers follow the theme, the cells do not\n &__corner,\n &__head,\n &__row {\n position: sticky;\n z-index: 1;\n border: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-3);\n font-family: var(--font-family-sans);\n font-size: var(--text-12);\n font-weight: var(--font-normal);\n text-align: center;\n }\n\n // The letters sit in the middle of their row, room above and below\n &__corner,\n &__head {\n top: 0;\n padding: var(--spacing-4) var(--spacing-4) var(--spacing-2);\n line-height: 1;\n vertical-align: middle;\n }\n\n &__row {\n vertical-align: middle;\n }\n\n &__corner {\n left: 0;\n z-index: 5;\n }\n\n &__row {\n left: 0;\n padding: 0 var(--spacing-4);\n font-variant-numeric: tabular-nums;\n }\n\n // Where the selection is, as Excel shows it: one step of surface,\n // and the letter and a thin line in its green\n &__head--current {\n background-color: var(--color-surface-2);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__row--current {\n background-color: var(--color-surface-2);\n box-shadow: inset calc(var(--spacing-2) * -1) 0 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__cell[data-focus] {\n outline: var(--spacing-2) solid var(--pk-spreadsheet-green);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n\n &__cell--range {\n box-shadow: inset 0 0 0 100vmax rgb(31 29 43 / 8%);\n }\n\n &__cell--missing {\n color: #6b6880;\n }\n\n &__more {\n position: sticky;\n left: 0;\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n color: #6b6880;\n font-size: var(--text-12);\n }\n\n // The sheets at the bottom, as Excel draws its tabs, and the status\n // bar below them: two rows, as in Excel, so the sums of a selection\n // never push the sheets or the note out of a narrow frame\n &__sheets {\n display: flex;\n flex-shrink: 0;\n min-height: var(--spacing-32);\n overflow-x: auto;\n padding-left: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n\n @media (pointer: coarse) {\n min-height: var(--spacing-40);\n }\n }\n\n &__status {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n min-height: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n font-size: var(--text-12);\n }\n\n &__sheet {\n flex-shrink: 0;\n padding: 0 var(--spacing-16);\n border: 0;\n border-right: var(--border) solid var(--color-surface-3);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-12);\n white-space: nowrap;\n cursor: pointer;\n\n &:first-child {\n border-left: var(--border) solid var(--color-surface-3);\n }\n\n &:hover {\n background-color: var(--color-surface-2);\n }\n\n &[aria-current='page'] {\n background-color: var(--color-surface);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-semibold);\n }\n }\n\n // The note on the left, as Excel's messages, the sums on the right:\n // the note gives way to them\n &__info {\n display: flex;\n flex: 1;\n align-items: center;\n gap: var(--spacing-16);\n min-width: 0;\n margin: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__note {\n min-width: 0;\n overflow: hidden;\n color: var(--color-word-3);\n text-overflow: ellipsis;\n }\n\n &__stats {\n display: flex;\n flex-shrink: 0;\n gap: var(--spacing-12);\n margin-left: auto;\n }\n\n // A phone keeps the count and the sum of a selection\n @container (width < 26rem) {\n &__average {\n display: none;\n }\n }\n\n &__zoom {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n gap: var(--spacing-2);\n padding-right: var(--spacing-8);\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n\n // On the dark headers Excel's green reads too dark: a lighter step of it\n @media (prefers-color-scheme: dark) {\n :where(:host, :root, .theme):not(.theme--light)\n .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n }\n\n :where(.theme.theme--dark) .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n import type { CSSProperties } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type {\n SpreadsheetPreview,\n SpreadsheetPreviewCell,\n SpreadsheetPreviewStyle,\n } from 'models'\n\n /**\n * A spreadsheet stored in the chat, drawn as Excel draws it (spec\n * `chat-office-files.md`, F6, item 4, and the viewer of its follow-ups):\n * column letters and row numbers that stay in view, the widths, heights,\n * fonts, fills and borders of the file, merged cells and frozen panes.\n * A cell is picked with a click, a range with a drag or shift, and the\n * arrows move it: the formula bar shows its formula, the status bar the\n * sum of a range. The sheets are tabs at the bottom. The grid keeps the\n * file's white in the dark theme, as a page does; the bars around it\n * follow the theme. Framed by `PkFilePreview`.\n */\n const props = defineProps<{ preview: SpreadsheetPreview }>()\n\n const { t: $t, locale } = useI18n({ useScope: 'global' })\n\n /** Excel's defaults, in pixels. */\n const COLUMN_WIDTH = 64\n const ROW_HEIGHT = 20\n const HEAD_HEIGHT = 28\n const ROW_HEAD_WIDTH = 44\n\n // Models, so the sheet and the zoom stay when the viewer moves between\n // the panel and the dialog (`PkChatbotViewChat` keeps them).\n const active = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const scrollEl = useTemplateRef<HTMLDivElement>('scrollEl')\n // The border box, scroll bars included: the grid that fills the view\n // makes them appear, and measured without them the view shrank, the\n // grid changed again, and the two went on in a loop.\n const { width: viewWidth, height: viewHeight } = useElementSize(\n scrollEl,\n { width: 0, height: 0 },\n { box: 'border-box' },\n )\n const sheet = computed(\n () => props.preview.sheets[active.value] ?? props.preview.sheets[0],\n )\n watch(\n () => props.preview,\n () => {\n active.value = 0\n },\n )\n\n const letters = (n: number): string => {\n let s = ''\n for (let c = n; c > 0; c = Math.floor((c - 1) / 26)) {\n s = String.fromCharCode(65 + ((c - 1) % 26)) + s\n }\n return s\n }\n\n // Empty rows and columns after the data up to the edges of the view, as\n // Excel's grid goes on, unless the file goes on past what the preview\n // holds: an empty column there would say the sheet ends.\n const columns = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(\n s.columns.filter((c) => c.hidden).map((c) => c.col),\n )\n const widths = new Map(s.columns.map((c) => [c.col, c.width]))\n const out: Array<{ col: number; width: number }> = []\n let used = ROW_HEAD_WIDTH\n const room = viewWidth.value / zoom.value\n for (\n let col = 1;\n col <= s.lastColumn ||\n (!s.moreColumns && (col <= s.lastColumn + 2 || used < room));\n col++\n ) {\n if (hidden.has(col)) {\n continue\n }\n const width = widths.get(col) ?? COLUMN_WIDTH\n out.push({ col, width })\n used += width\n }\n return out\n })\n /** A fixed layout needs the table's width, or the columns shrink. */\n const gridWidth = computed(() =>\n columns.value.reduce((n, c) => n + c.width, ROW_HEAD_WIDTH),\n )\n /** The columns as a value: the same set at another zoom, for the memo. */\n const columnsKey = computed(() =>\n columns.value.map((c) => `${c.col}:${c.width}`).join(','),\n )\n // One object per row while its sheet is shown, so a row's memo holds\n // when the view adds rows to fill itself.\n const rowObjects = new WeakMap<\n object,\n Map<number, { row: number; height: number }>\n >()\n const rows = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(s.hiddenRows ?? [])\n const heights = new Map(s.rows.map((r) => [r.row, r.height]))\n const fill = Math.ceil(\n (viewHeight.value / zoom.value - HEAD_HEIGHT) / ROW_HEIGHT,\n )\n const last = s.moreRows\n ? s.lastRow\n : Math.max(s.lastRow + 5, fill + hidden.size)\n let known = rowObjects.get(s)\n if (!known) {\n known = new Map()\n rowObjects.set(s, known)\n }\n const seen = known\n return Array.from({ length: last }, (_, i) => i + 1)\n .filter((row) => !hidden.has(row))\n .map((row) => {\n let r = seen.get(row)\n if (!r) {\n r = { row, height: heights.get(row) ?? ROW_HEIGHT }\n seen.set(row, r)\n }\n return r\n })\n })\n const cells = computed(() => {\n const map = new Map<string, SpreadsheetPreviewCell>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n map.set(`${r.row},${c.col}`, c)\n }\n }\n return map\n })\n /** The cells a merge covers, each with the first cell that draws it. */\n const covered = computed(() => {\n const map = new Map<string, { row: number; col: number }>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n if (!c.span) {\n continue\n }\n for (let dr = 0; dr < c.span.rows; dr++) {\n for (let dc = 0; dc < c.span.cols; dc++) {\n if (dr || dc) {\n map.set(`${r.row + dr},${c.col + dc}`, {\n row: r.row,\n col: c.col,\n })\n }\n }\n }\n }\n }\n return map\n })\n const cellAt = (row: number, col: number) =>\n cells.value.get(`${row},${col}`)\n /**\n * A merge's span over the rows and columns the grid draws: the file\n * counts the hidden ones too, and the merge ran into the next column.\n */\n const shownSpan = (row: number, col: number) => {\n const span = cellAt(row, col)?.span\n if (!span) {\n return undefined\n }\n return {\n rows: rows.value.filter(\n (r) => r.row >= row && r.row < row + span.rows,\n ).length,\n cols: columns.value.filter(\n (c) => c.col >= col && c.col < col + span.cols,\n ).length,\n }\n }\n const styleOf = (\n cell: SpreadsheetPreviewCell | undefined,\n ): SpreadsheetPreviewStyle | undefined =>\n cell?.style === undefined ? undefined : props.preview.styles[cell.style]\n\n // #region the text of a cell\n const numberText = (cell: SpreadsheetPreviewCell, v: number) => {\n const digits =\n cell.decimals !== undefined\n ? {\n minimumFractionDigits: cell.decimals,\n maximumFractionDigits: cell.maxDecimals ?? cell.decimals,\n }\n : { maximumFractionDigits: 10 }\n return new Intl.NumberFormat(locale.value, {\n ...digits,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n ...(cell.format === 'currency' && cell.currency\n ? { style: 'currency', currency: cell.currency }\n : {}),\n }).format(v)\n }\n\n const dateText = (v: string) => {\n const date = new Date(`${v}T00:00:00Z`)\n return Number.isNaN(date.getTime())\n ? v\n : new Intl.DateTimeFormat(locale.value, {\n dateStyle: 'short',\n timeZone: 'UTC',\n }).format(date)\n }\n\n /** The cell's text: a number in the reader's language, a date, a word. */\n const textOf = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.missing) {\n return '—'\n }\n const v = cell.value\n if (v === undefined) {\n return ''\n }\n if (typeof v === 'boolean') {\n return v ? $t('chatFilePreview.true') : $t('chatFilePreview.false')\n }\n if (cell.format === 'date' && typeof v === 'string') {\n return dateText(v)\n }\n if (typeof v === 'number') {\n return numberText(cell, v)\n }\n return v\n }\n\n /** What Excel's bar shows: the formula, or the value as typed. */\n const barText = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.formula) {\n return `=${cell.formula}`\n }\n const v = cell.value\n if (typeof v === 'number') {\n return new Intl.NumberFormat(locale.value, {\n useGrouping: false,\n maximumFractionDigits: 15,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n }).format(v)\n }\n return textOf(cell)\n }\n // #endregion\n\n // #region the look of a cell\n const border = (side?: { color: string; width: number }) =>\n side ? `${side.width}px solid ${side.color}` : undefined\n\n const cellCss = (\n cell: SpreadsheetPreviewCell | undefined,\n row: number,\n col: number,\n ): CSSProperties => {\n const s = styleOf(cell)\n const v = cell?.value\n const numeric = typeof v === 'number' || !!cell?.missing\n const css: CSSProperties = {\n textAlign:\n s?.align ??\n (numeric\n ? 'right'\n : typeof v === 'boolean' || cell?.format === 'error'\n ? 'center'\n : 'left'),\n verticalAlign:\n s?.valign === 'top'\n ? 'top'\n : s?.valign === 'middle'\n ? 'middle'\n : 'bottom',\n whiteSpace: s?.wrap ? 'pre-wrap' : 'nowrap',\n }\n if (s?.bold) {\n css.fontWeight = 700\n }\n if (s?.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n s?.underline ? 'underline' : '',\n s?.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (s?.size) {\n css.fontSize = `${s.size}pt`\n }\n if (s?.color) {\n css.color = s.color\n }\n if (s?.fill) {\n css.backgroundColor = s.fill\n }\n if (s?.indent) {\n const pad = `${4 + s.indent * 9}px`\n if (css.textAlign === 'right') {\n css.paddingRight = pad\n } else {\n css.paddingLeft = pad\n }\n }\n css.borderTop = border(s?.borders?.top)\n css.borderRight = border(s?.borders?.right)\n css.borderBottom = border(s?.borders?.bottom)\n css.borderLeft = border(s?.borders?.left)\n Object.assign(css, frozenCss(row, col))\n return css\n }\n\n /** Where a frozen row or column sticks, under the headers. */\n const frozenCss = (row: number, col: number): CSSProperties => {\n const f = sheet.value?.frozen\n if (!f) {\n return {}\n }\n const css: CSSProperties = {}\n if (row <= f.rows) {\n css.position = 'sticky'\n css.top = `${\n HEAD_HEIGHT +\n rows.value\n .filter((r) => r.row < row)\n .reduce((n, r) => n + r.height, 0)\n }px`\n css.zIndex = 2\n }\n if (col <= f.cols) {\n css.position = 'sticky'\n css.left = `${\n ROW_HEAD_WIDTH +\n columns.value\n .filter((c) => c.col < col)\n .reduce((n, c) => n + c.width, 0)\n }px`\n css.zIndex = row <= f.rows ? 3 : 2\n }\n return css\n }\n // #endregion\n\n // #region selection\n type At = { row: number; col: number }\n const anchor = ref<At>({ row: 1, col: 1 })\n const focus = ref<At>({ row: 1, col: 1 })\n watch(sheet, () => {\n anchor.value = { row: 1, col: 1 }\n focus.value = { row: 1, col: 1 }\n })\n const range = computed(() => ({\n r1: Math.min(anchor.value.row, focus.value.row),\n r2: Math.max(anchor.value.row, focus.value.row),\n c1: Math.min(anchor.value.col, focus.value.col),\n c2: Math.max(anchor.value.col, focus.value.col),\n }))\n const inRange = (row: number, col: number) =>\n row >= range.value.r1 &&\n row <= range.value.r2 &&\n col >= range.value.c1 &&\n col <= range.value.c2\n const isFocus = (row: number, col: number) =>\n focus.value.row === row && focus.value.col === col\n /**\n * What a row draws of the selection. A row is drawn again only when\n * this, its sheet, the columns or the language of the numbers change: a\n * sheet of thousands of cells drew them all at each step of a drag,\n * seconds per selection.\n */\n const rowSelection = (row: number) =>\n row >= range.value.r1 && row <= range.value.r2\n ? `${range.value.c1}:${range.value.c2}:${\n focus.value.row === row ? focus.value.col : 0\n }`\n : ''\n\n const dragging = ref(false)\n const pick = (row: number, col: number, event: MouseEvent) => {\n // The click keeps its default off (no text selection while dragging),\n // so the grid takes the keyboard here.\n scrollEl.value?.focus({ preventScroll: true })\n focus.value = { row, col }\n if (!event.shiftKey) {\n anchor.value = { row, col }\n }\n dragging.value = true\n }\n const extend = (row: number, col: number) => {\n if (dragging.value) {\n focus.value = { row, col }\n }\n }\n\n const move = (event: KeyboardEvent) => {\n const steps: Record<string, [number, number]> = {\n ArrowUp: [-1, 0],\n ArrowDown: [1, 0],\n ArrowLeft: [0, -1],\n ArrowRight: [0, 1],\n Enter: [1, 0],\n Tab: [0, 1],\n }\n const step = steps[event.key]\n if (!step) {\n return\n }\n event.preventDefault()\n const rowList = rows.value.map((r) => r.row)\n const colList = columns.value.map((c) => c.col)\n const ownerOf = (at: At) =>\n covered.value.get(`${at.row},${at.col}`) ?? at\n // As in Excel, a merge is one cell: the step goes past the cells it\n // covers, and a step into one lands on the cell that draws it.\n const start = ownerOf(focus.value)\n let r = rowList.indexOf(focus.value.row)\n let c = colList.indexOf(focus.value.col)\n let next = start\n for (;;) {\n const nr = Math.min(rowList.length - 1, Math.max(0, r + step[0]))\n const nc = Math.min(colList.length - 1, Math.max(0, c + step[1]))\n if (nr === r && nc === c) {\n break\n }\n r = nr\n c = nc\n next = ownerOf({ row: rowList[r], col: colList[c] })\n if (next.row !== start.row || next.col !== start.col) {\n break\n }\n }\n focus.value = next\n if (!event.shiftKey) {\n anchor.value = next\n }\n nextTick(() =>\n scrollEl.value\n ?.querySelector('[data-focus]')\n ?.scrollIntoView({ block: 'nearest', inline: 'nearest' }),\n )\n }\n\n const focusCell = computed(() => cellAt(focus.value.row, focus.value.col))\n /** Count, average and sum of a range, as Excel's status bar shows them. */\n const stats = computed(() => {\n const { r1, r2, c1, c2 } = range.value\n if (r1 === r2 && c1 === c2) {\n return undefined\n }\n let count = 0\n let sum = 0\n let numbers = 0\n let first: SpreadsheetPreviewCell | undefined\n for (let r = r1; r <= r2; r++) {\n for (let c = c1; c <= c2; c++) {\n const cell = cellAt(r, c)\n if (!cell || (cell.value === undefined && !cell.missing)) {\n continue\n }\n count++\n if (typeof cell.value === 'number') {\n sum += cell.value\n numbers++\n first ??= cell\n }\n }\n }\n if (!count) {\n return undefined\n }\n return {\n count,\n sum: first ? numberText(first, sum) : undefined,\n // One number among text is still an average, as in Excel\n average: first ? numberText(first, sum / numbers) : undefined,\n }\n })\n // #endregion\n\n // #region zoom\n const zoomBy = (step: number) => {\n zoom.value = Math.min(\n 2,\n Math.max(0.5, Math.round((zoom.value + step) * 10) / 10),\n )\n }\n // #endregion\n</script>\n\n<template>\n <div class=\"pk-spreadsheet-preview\">\n <div class=\"pk-spreadsheet-preview__bar\">\n <span\n class=\"pk-spreadsheet-preview__ref\"\n :aria-label=\"$t('chatFilePreview.cell')\">\n {{ letters(focus.col) }}{{ focus.row }}\n </span>\n <span class=\"pk-spreadsheet-preview__fx\" aria-hidden=\"true\"\n >fx</span\n >\n <output\n class=\"pk-spreadsheet-preview__formula\"\n :aria-label=\"$t('chatFilePreview.formulaBar')\">\n {{ barText(focusCell) }}\n </output>\n </div>\n <div\n ref=\"scrollEl\"\n class=\"pk-spreadsheet-preview__scroll\"\n tabindex=\"0\"\n role=\"grid\"\n :aria-label=\"sheet?.name\"\n @keydown=\"move\"\n @mouseup=\"dragging = false\"\n @mouseleave=\"dragging = false\">\n <table\n v-if=\"sheet\"\n class=\"pk-spreadsheet-preview__grid\"\n :class=\"{\n 'pk-spreadsheet-preview__grid--lines': sheet.gridlines,\n }\"\n :style=\"{ zoom, width: `${gridWidth}px` }\">\n <colgroup>\n <col :style=\"{ width: `${ROW_HEAD_WIDTH}px` }\" />\n <col\n v-for=\"c in columns\"\n :key=\"c.col\"\n :style=\"{ width: `${c.width}px` }\" />\n </colgroup>\n <thead>\n <tr :style=\"{ height: `${HEAD_HEIGHT}px` }\">\n <th class=\"pk-spreadsheet-preview__corner\" />\n <th\n v-for=\"c in columns\"\n :key=\"c.col\"\n scope=\"col\"\n class=\"pk-spreadsheet-preview__head\"\n :class=\"{\n 'pk-spreadsheet-preview__head--current':\n c.col >= range.c1 && c.col <= range.c2,\n }\">\n {{ letters(c.col) }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n v-for=\"r in rows\"\n :key=\"r.row\"\n v-memo=\"[\n r,\n sheet,\n columnsKey,\n locale,\n rowSelection(r.row),\n ]\"\n :style=\"{ height: `${r.height}px` }\">\n <th\n scope=\"row\"\n class=\"pk-spreadsheet-preview__row\"\n :class=\"{\n 'pk-spreadsheet-preview__row--current':\n r.row >= range.r1 && r.row <= range.r2,\n }\"\n :style=\"\n sheet.frozen && r.row <= sheet.frozen.rows\n ? {\n ...frozenCss(r.row, 0),\n left: 0,\n zIndex: 4,\n }\n : undefined\n \">\n {{ r.row }}\n </th>\n <template v-for=\"c in columns\" :key=\"c.col\">\n <td\n v-if=\"!covered.has(`${r.row},${c.col}`)\"\n :rowspan=\"shownSpan(r.row, c.col)?.rows\"\n :colspan=\"shownSpan(r.row, c.col)?.cols\"\n class=\"pk-spreadsheet-preview__cell\"\n :class=\"{\n 'pk-spreadsheet-preview__cell--range':\n inRange(r.row, c.col) &&\n !isFocus(r.row, c.col),\n 'pk-spreadsheet-preview__cell--missing':\n cellAt(r.row, c.col)?.missing,\n }\"\n :style=\"\n cellCss(cellAt(r.row, c.col), r.row, c.col)\n \"\n :data-focus=\"\n isFocus(r.row, c.col) ? '' : undefined\n \"\n :title=\"\n cellAt(r.row, c.col)?.missing\n ? $t('chatFilePreview.missingValue')\n : undefined\n \"\n @mousedown.prevent=\"pick(r.row, c.col, $event)\"\n @mouseenter=\"extend(r.row, c.col)\">\n {{ textOf(cellAt(r.row, c.col)) }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <p\n v-if=\"sheet && (sheet.moreRows || sheet.moreColumns)\"\n class=\"pk-spreadsheet-preview__more\">\n <template v-if=\"sheet.moreRows\">\n {{ $t('chatFilePreview.moreRows', sheet.moreRows) }}\n </template>\n <template v-if=\"sheet.moreColumns\">\n {{ $t('chatFilePreview.moreColumns', sheet.moreColumns) }}\n </template>\n </p>\n </div>\n <nav\n class=\"pk-spreadsheet-preview__sheets\"\n :aria-label=\"$t('chatFilePreview.sheets')\">\n <button\n v-for=\"(s, i) in preview.sheets\"\n :key=\"s.name\"\n type=\"button\"\n class=\"pk-spreadsheet-preview__sheet\"\n :aria-current=\"i === active ? 'page' : undefined\"\n @click=\"active = i\">\n {{ s.name }}\n </button>\n </nav>\n <div class=\"pk-spreadsheet-preview__status\">\n <p class=\"pk-spreadsheet-preview__info\">\n <span\n v-if=\"preview.staleFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.staleFormulas')\">\n {{ $t('chatFilePreview.staleFormulas') }}\n </span>\n <span\n v-else-if=\"preview.computedFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.computedFormulas')\">\n {{ $t('chatFilePreview.computedFormulas') }}\n </span>\n <span v-if=\"stats\" class=\"pk-spreadsheet-preview__stats\">\n <span\n v-if=\"stats.average\"\n class=\"pk-spreadsheet-preview__average\">\n {{ $t('chatFilePreview.average') }} {{ stats.average }}\n </span>\n <span>\n {{ $t('chatFilePreview.count') }} {{ stats.count }}\n </span>\n <span v-if=\"stats.sum\">\n {{ $t('chatFilePreview.sum') }} {{ stats.sum }}\n </span>\n </span>\n </p>\n <div class=\"pk-spreadsheet-preview__zoom\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.5\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-spreadsheet-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-spreadsheet-preview {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n // Excel's green marks the active cell, its column and row and the\n // current sheet, as in Excel (decided 2026-10-29). The cells keep\n // their paper in both themes; the headers lighten it on the dark one.\n --pk-spreadsheet-green: #217346;\n --pk-spreadsheet-green-head: #217346;\n\n // The formula bar: the cell, fx and its content, as in Excel\n &__bar {\n display: flex;\n align-items: stretch;\n min-height: var(--spacing-40);\n border-bottom: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n font-size: var(--text-14);\n }\n\n &__ref {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n width: var(--spacing-96);\n padding: 0 var(--spacing-12);\n box-sizing: border-box;\n border-right: var(--border) solid var(--color-surface-3);\n font-variant-numeric: tabular-nums;\n }\n\n &__fx {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-40);\n border-right: var(--border) solid var(--color-surface-3);\n color: var(--color-word-3);\n font-family: Georgia, serif;\n font-style: italic;\n }\n\n &__formula {\n display: flex;\n flex: 1;\n align-items: center;\n min-width: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n // The grid scrolls both ways; its headers stay\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n background-color: #fff;\n outline: none;\n cursor: cell;\n\n &:focus-visible {\n box-shadow: inset 0 0 0 var(--spacing-2)\n var(--input-focus-color);\n }\n }\n\n &__grid {\n border-collapse: collapse;\n table-layout: fixed;\n color: #000;\n font-family: Calibri, Carlito, 'Segoe UI', Arial, sans-serif;\n font-size: 11pt;\n user-select: none;\n\n td {\n overflow: hidden;\n max-width: 0;\n padding: 0 var(--spacing-4);\n background-color: #fff;\n line-height: 1.2;\n text-overflow: clip;\n }\n\n &--lines td {\n border: var(--border) solid #e1e1e1;\n }\n }\n\n // The letters and the numbers follow the theme, the cells do not\n &__corner,\n &__head,\n &__row {\n position: sticky;\n z-index: 1;\n border: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-3);\n font-family: var(--font-family-sans);\n font-size: var(--text-12);\n font-weight: var(--font-normal);\n text-align: center;\n }\n\n // The letters sit in the middle of their row, room above and below\n &__corner,\n &__head {\n top: 0;\n padding: var(--spacing-4) var(--spacing-4) var(--spacing-2);\n line-height: 1;\n vertical-align: middle;\n }\n\n &__row {\n vertical-align: middle;\n }\n\n &__corner {\n left: 0;\n z-index: 5;\n }\n\n &__row {\n left: 0;\n padding: 0 var(--spacing-4);\n font-variant-numeric: tabular-nums;\n }\n\n // Where the selection is, as Excel shows it: one step of surface,\n // and the letter and a thin line in its green\n &__head--current {\n background-color: var(--color-surface-2);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__row--current {\n background-color: var(--color-surface-2);\n box-shadow: inset calc(var(--spacing-2) * -1) 0 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__cell[data-focus] {\n outline: var(--spacing-2) solid var(--pk-spreadsheet-green);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n\n &__cell--range {\n box-shadow: inset 0 0 0 100vmax rgb(31 29 43 / 8%);\n }\n\n &__cell--missing {\n color: #6b6880;\n }\n\n &__more {\n position: sticky;\n left: 0;\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n color: #6b6880;\n font-size: var(--text-12);\n }\n\n // The sheets at the bottom, as Excel draws its tabs, and the status\n // bar below them: two rows, as in Excel, so the sums of a selection\n // never push the sheets or the note out of a narrow frame\n &__sheets {\n display: flex;\n flex-shrink: 0;\n min-height: var(--spacing-32);\n overflow-x: auto;\n padding-left: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n\n @media (pointer: coarse) {\n min-height: var(--spacing-40);\n }\n }\n\n &__status {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n min-height: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n font-size: var(--text-12);\n }\n\n &__sheet {\n flex-shrink: 0;\n padding: 0 var(--spacing-16);\n border: 0;\n border-right: var(--border) solid var(--color-surface-3);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-12);\n white-space: nowrap;\n cursor: pointer;\n\n &:first-child {\n border-left: var(--border) solid var(--color-surface-3);\n }\n\n &:hover {\n background-color: var(--color-surface-2);\n }\n\n &[aria-current='page'] {\n background-color: var(--color-surface);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-semibold);\n }\n }\n\n // The note on the left, as Excel's messages, the sums on the right:\n // the note gives way to them\n &__info {\n display: flex;\n flex: 1;\n align-items: center;\n gap: var(--spacing-16);\n min-width: 0;\n margin: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__note {\n min-width: 0;\n overflow: hidden;\n color: var(--color-word-3);\n text-overflow: ellipsis;\n }\n\n &__stats {\n display: flex;\n flex-shrink: 0;\n gap: var(--spacing-12);\n margin-left: auto;\n }\n\n // A phone keeps the count and the sum of a selection\n @container (width < 26rem) {\n &__average {\n display: none;\n }\n }\n\n &__zoom {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n gap: var(--spacing-2);\n padding-right: var(--spacing-8);\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n\n // On the dark headers Excel's green reads too dark: a lighter step of it\n @media (prefers-color-scheme: dark) {\n :where(:host, :root, .theme):not(.theme--light)\n .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n }\n\n :where(.theme.theme--dark) .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n import type { CSSProperties } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type {\n SpreadsheetPreview,\n SpreadsheetPreviewCell,\n SpreadsheetPreviewStyle,\n } from 'models'\n\n /**\n * A spreadsheet stored in the chat, drawn as Excel draws it (spec\n * `chat-office-files.md`, F6, item 4, and the viewer of its follow-ups):\n * column letters and row numbers that stay in view, the widths, heights,\n * fonts, fills and borders of the file, merged cells and frozen panes.\n * A cell is picked with a click, a range with a drag or shift, and the\n * arrows move it: the formula bar shows its formula, the status bar the\n * sum of a range. The sheets are tabs at the bottom. The grid keeps the\n * file's white in the dark theme, as a page does; the bars around it\n * follow the theme. Framed by `PkFilePreview`.\n */\n const props = defineProps<{ preview: SpreadsheetPreview }>()\n\n const { t: $t, locale } = useI18n({ useScope: 'global' })\n\n /** Excel's defaults, in pixels. */\n const COLUMN_WIDTH = 64\n const ROW_HEIGHT = 20\n const HEAD_HEIGHT = 28\n const ROW_HEAD_WIDTH = 44\n\n // Models, so the sheet and the zoom stay when the viewer moves between\n // the panel and the dialog (`PkChatbotViewChat` keeps them).\n const active = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const scrollEl = useTemplateRef<HTMLDivElement>('scrollEl')\n // The border box, scroll bars included: the grid that fills the view\n // makes them appear, and measured without them the view shrank, the\n // grid changed again, and the two went on in a loop.\n const { width: viewWidth, height: viewHeight } = useElementSize(\n scrollEl,\n { width: 0, height: 0 },\n { box: 'border-box' },\n )\n const sheet = computed(\n () => props.preview.sheets[active.value] ?? props.preview.sheets[0],\n )\n watch(\n () => props.preview,\n () => {\n active.value = 0\n },\n )\n\n const letters = (n: number): string => {\n let s = ''\n for (let c = n; c > 0; c = Math.floor((c - 1) / 26)) {\n s = String.fromCharCode(65 + ((c - 1) % 26)) + s\n }\n return s\n }\n\n // Empty rows and columns after the data up to the edges of the view, as\n // Excel's grid goes on, unless the file goes on past what the preview\n // holds: an empty column there would say the sheet ends.\n const columns = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(\n s.columns.filter((c) => c.hidden).map((c) => c.col),\n )\n const widths = new Map(s.columns.map((c) => [c.col, c.width]))\n const out: Array<{ col: number; width: number }> = []\n let used = ROW_HEAD_WIDTH\n const room = viewWidth.value / zoom.value\n for (\n let col = 1;\n col <= s.lastColumn ||\n (!s.moreColumns && (col <= s.lastColumn + 2 || used < room));\n col++\n ) {\n if (hidden.has(col)) {\n continue\n }\n const width = widths.get(col) ?? COLUMN_WIDTH\n out.push({ col, width })\n used += width\n }\n return out\n })\n /** A fixed layout needs the table's width, or the columns shrink. */\n const gridWidth = computed(() =>\n columns.value.reduce((n, c) => n + c.width, ROW_HEAD_WIDTH),\n )\n /** The columns as a value: the same set at another zoom, for the memo. */\n const columnsKey = computed(() =>\n columns.value.map((c) => `${c.col}:${c.width}`).join(','),\n )\n // One object per row while its sheet is shown, so a row's memo holds\n // when the view adds rows to fill itself.\n const rowObjects = new WeakMap<\n object,\n Map<number, { row: number; height: number }>\n >()\n const rows = computed(() => {\n const s = sheet.value\n if (!s) {\n return []\n }\n const hidden = new Set(s.hiddenRows ?? [])\n const heights = new Map(s.rows.map((r) => [r.row, r.height]))\n const fill = Math.ceil(\n (viewHeight.value / zoom.value - HEAD_HEIGHT) / ROW_HEIGHT,\n )\n const last = s.moreRows\n ? s.lastRow\n : Math.max(s.lastRow + 5, fill + hidden.size)\n let known = rowObjects.get(s)\n if (!known) {\n known = new Map()\n rowObjects.set(s, known)\n }\n const seen = known\n return Array.from({ length: last }, (_, i) => i + 1)\n .filter((row) => !hidden.has(row))\n .map((row) => {\n let r = seen.get(row)\n if (!r) {\n r = { row, height: heights.get(row) ?? ROW_HEIGHT }\n seen.set(row, r)\n }\n return r\n })\n })\n const cells = computed(() => {\n const map = new Map<string, SpreadsheetPreviewCell>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n map.set(`${r.row},${c.col}`, c)\n }\n }\n return map\n })\n /** The cells a merge covers, each with the first cell that draws it. */\n const covered = computed(() => {\n const map = new Map<string, { row: number; col: number }>()\n for (const r of sheet.value?.rows ?? []) {\n for (const c of r.cells) {\n if (!c.span) {\n continue\n }\n for (let dr = 0; dr < c.span.rows; dr++) {\n for (let dc = 0; dc < c.span.cols; dc++) {\n if (dr || dc) {\n map.set(`${r.row + dr},${c.col + dc}`, {\n row: r.row,\n col: c.col,\n })\n }\n }\n }\n }\n }\n return map\n })\n const cellAt = (row: number, col: number) =>\n cells.value.get(`${row},${col}`)\n /**\n * A merge's span over the rows and columns the grid draws: the file\n * counts the hidden ones too, and the merge ran into the next column.\n */\n const shownSpan = (row: number, col: number) => {\n const span = cellAt(row, col)?.span\n if (!span) {\n return undefined\n }\n return {\n rows: rows.value.filter(\n (r) => r.row >= row && r.row < row + span.rows,\n ).length,\n cols: columns.value.filter(\n (c) => c.col >= col && c.col < col + span.cols,\n ).length,\n }\n }\n const styleOf = (\n cell: SpreadsheetPreviewCell | undefined,\n ): SpreadsheetPreviewStyle | undefined =>\n cell?.style === undefined ? undefined : props.preview.styles[cell.style]\n\n // #region the text of a cell\n const numberText = (cell: SpreadsheetPreviewCell, v: number) => {\n const digits =\n cell.decimals !== undefined\n ? {\n minimumFractionDigits: cell.decimals,\n maximumFractionDigits: cell.maxDecimals ?? cell.decimals,\n }\n : { maximumFractionDigits: 10 }\n return new Intl.NumberFormat(locale.value, {\n ...digits,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n ...(cell.format === 'currency' && cell.currency\n ? { style: 'currency', currency: cell.currency }\n : {}),\n }).format(v)\n }\n\n const dateText = (v: string) => {\n const date = new Date(`${v}T00:00:00Z`)\n return Number.isNaN(date.getTime())\n ? v\n : new Intl.DateTimeFormat(locale.value, {\n dateStyle: 'short',\n timeZone: 'UTC',\n }).format(date)\n }\n\n /** The cell's text: a number in the reader's language, a date, a word. */\n const textOf = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.missing) {\n return '—'\n }\n const v = cell.value\n if (v === undefined) {\n return ''\n }\n if (typeof v === 'boolean') {\n return v ? $t('chatFilePreview.true') : $t('chatFilePreview.false')\n }\n if (cell.format === 'date' && typeof v === 'string') {\n return dateText(v)\n }\n if (typeof v === 'number') {\n return numberText(cell, v)\n }\n return v\n }\n\n /** What Excel's bar shows: the formula, or the value as typed. */\n const barText = (cell: SpreadsheetPreviewCell | undefined): string => {\n if (!cell) {\n return ''\n }\n if (cell.formula) {\n return `=${cell.formula}`\n }\n const v = cell.value\n if (typeof v === 'number') {\n return new Intl.NumberFormat(locale.value, {\n useGrouping: false,\n maximumFractionDigits: 15,\n ...(cell.format === 'percent' ? { style: 'percent' } : {}),\n }).format(v)\n }\n return textOf(cell)\n }\n // #endregion\n\n // #region the look of a cell\n const border = (side?: { color: string; width: number }) =>\n side ? `${side.width}px solid ${side.color}` : undefined\n\n const cellCss = (\n cell: SpreadsheetPreviewCell | undefined,\n row: number,\n col: number,\n ): CSSProperties => {\n const s = styleOf(cell)\n const v = cell?.value\n const numeric = typeof v === 'number' || !!cell?.missing\n const css: CSSProperties = {\n textAlign:\n s?.align ??\n (numeric\n ? 'right'\n : typeof v === 'boolean' || cell?.format === 'error'\n ? 'center'\n : 'left'),\n verticalAlign:\n s?.valign === 'top'\n ? 'top'\n : s?.valign === 'middle'\n ? 'middle'\n : 'bottom',\n whiteSpace: s?.wrap ? 'pre-wrap' : 'nowrap',\n }\n if (s?.bold) {\n css.fontWeight = 700\n }\n if (s?.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n s?.underline ? 'underline' : '',\n s?.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (s?.size) {\n css.fontSize = `${s.size}pt`\n }\n if (s?.color) {\n css.color = s.color\n }\n if (s?.fill) {\n css.backgroundColor = s.fill\n }\n if (s?.indent) {\n const pad = `${4 + s.indent * 9}px`\n if (css.textAlign === 'right') {\n css.paddingRight = pad\n } else {\n css.paddingLeft = pad\n }\n }\n css.borderTop = border(s?.borders?.top)\n css.borderRight = border(s?.borders?.right)\n css.borderBottom = border(s?.borders?.bottom)\n css.borderLeft = border(s?.borders?.left)\n Object.assign(css, frozenCss(row, col))\n return css\n }\n\n /** Where a frozen row or column sticks, under the headers. */\n const frozenCss = (row: number, col: number): CSSProperties => {\n const f = sheet.value?.frozen\n if (!f) {\n return {}\n }\n const css: CSSProperties = {}\n if (row <= f.rows) {\n css.position = 'sticky'\n css.top = `${\n HEAD_HEIGHT +\n rows.value\n .filter((r) => r.row < row)\n .reduce((n, r) => n + r.height, 0)\n }px`\n css.zIndex = 2\n }\n if (col <= f.cols) {\n css.position = 'sticky'\n css.left = `${\n ROW_HEAD_WIDTH +\n columns.value\n .filter((c) => c.col < col)\n .reduce((n, c) => n + c.width, 0)\n }px`\n css.zIndex = row <= f.rows ? 3 : 2\n }\n return css\n }\n // #endregion\n\n // #region selection\n type At = { row: number; col: number }\n const anchor = ref<At>({ row: 1, col: 1 })\n const focus = ref<At>({ row: 1, col: 1 })\n watch(sheet, () => {\n anchor.value = { row: 1, col: 1 }\n focus.value = { row: 1, col: 1 }\n })\n const range = computed(() => ({\n r1: Math.min(anchor.value.row, focus.value.row),\n r2: Math.max(anchor.value.row, focus.value.row),\n c1: Math.min(anchor.value.col, focus.value.col),\n c2: Math.max(anchor.value.col, focus.value.col),\n }))\n const inRange = (row: number, col: number) =>\n row >= range.value.r1 &&\n row <= range.value.r2 &&\n col >= range.value.c1 &&\n col <= range.value.c2\n const isFocus = (row: number, col: number) =>\n focus.value.row === row && focus.value.col === col\n /**\n * What a row draws of the selection. A row is drawn again only when\n * this, its sheet, the columns or the language of the numbers change: a\n * sheet of thousands of cells drew them all at each step of a drag,\n * seconds per selection.\n */\n const rowSelection = (row: number) =>\n row >= range.value.r1 && row <= range.value.r2\n ? `${range.value.c1}:${range.value.c2}:${\n focus.value.row === row ? focus.value.col : 0\n }`\n : ''\n\n const dragging = ref(false)\n const pick = (row: number, col: number, event: MouseEvent) => {\n // The click keeps its default off (no text selection while dragging),\n // so the grid takes the keyboard here.\n scrollEl.value?.focus({ preventScroll: true })\n focus.value = { row, col }\n if (!event.shiftKey) {\n anchor.value = { row, col }\n }\n dragging.value = true\n }\n const extend = (row: number, col: number) => {\n if (dragging.value) {\n focus.value = { row, col }\n }\n }\n\n const move = (event: KeyboardEvent) => {\n const steps: Record<string, [number, number]> = {\n ArrowUp: [-1, 0],\n ArrowDown: [1, 0],\n ArrowLeft: [0, -1],\n ArrowRight: [0, 1],\n Enter: [1, 0],\n Tab: [0, 1],\n }\n const step = steps[event.key]\n if (!step) {\n return\n }\n event.preventDefault()\n const rowList = rows.value.map((r) => r.row)\n const colList = columns.value.map((c) => c.col)\n const ownerOf = (at: At) =>\n covered.value.get(`${at.row},${at.col}`) ?? at\n // As in Excel, a merge is one cell: the step goes past the cells it\n // covers, and a step into one lands on the cell that draws it.\n const start = ownerOf(focus.value)\n let r = rowList.indexOf(focus.value.row)\n let c = colList.indexOf(focus.value.col)\n let next = start\n for (;;) {\n const nr = Math.min(rowList.length - 1, Math.max(0, r + step[0]))\n const nc = Math.min(colList.length - 1, Math.max(0, c + step[1]))\n if (nr === r && nc === c) {\n break\n }\n r = nr\n c = nc\n next = ownerOf({ row: rowList[r], col: colList[c] })\n if (next.row !== start.row || next.col !== start.col) {\n break\n }\n }\n focus.value = next\n if (!event.shiftKey) {\n anchor.value = next\n }\n nextTick(() =>\n scrollEl.value\n ?.querySelector('[data-focus]')\n ?.scrollIntoView({ block: 'nearest', inline: 'nearest' }),\n )\n }\n\n const focusCell = computed(() => cellAt(focus.value.row, focus.value.col))\n /** Count, average and sum of a range, as Excel's status bar shows them. */\n const stats = computed(() => {\n const { r1, r2, c1, c2 } = range.value\n if (r1 === r2 && c1 === c2) {\n return undefined\n }\n let count = 0\n let sum = 0\n let numbers = 0\n let first: SpreadsheetPreviewCell | undefined\n for (let r = r1; r <= r2; r++) {\n for (let c = c1; c <= c2; c++) {\n const cell = cellAt(r, c)\n if (!cell || (cell.value === undefined && !cell.missing)) {\n continue\n }\n count++\n if (typeof cell.value === 'number') {\n sum += cell.value\n numbers++\n first ??= cell\n }\n }\n }\n if (!count) {\n return undefined\n }\n return {\n count,\n sum: first ? numberText(first, sum) : undefined,\n // One number among text is still an average, as in Excel\n average: first ? numberText(first, sum / numbers) : undefined,\n }\n })\n // #endregion\n\n // #region zoom\n const zoomBy = (step: number) => {\n zoom.value = Math.min(\n 2,\n Math.max(0.5, Math.round((zoom.value + step) * 10) / 10),\n )\n }\n // #endregion\n</script>\n\n<template>\n <div class=\"pk-spreadsheet-preview\">\n <div class=\"pk-spreadsheet-preview__bar\">\n <span\n class=\"pk-spreadsheet-preview__ref\"\n :aria-label=\"$t('chatFilePreview.cell')\">\n {{ letters(focus.col) }}{{ focus.row }}\n </span>\n <span class=\"pk-spreadsheet-preview__fx\" aria-hidden=\"true\"\n >fx</span\n >\n <output\n class=\"pk-spreadsheet-preview__formula\"\n :aria-label=\"$t('chatFilePreview.formulaBar')\">\n {{ barText(focusCell) }}\n </output>\n </div>\n <div\n ref=\"scrollEl\"\n class=\"pk-spreadsheet-preview__scroll\"\n tabindex=\"0\"\n role=\"grid\"\n :aria-label=\"sheet?.name\"\n @keydown=\"move\"\n @mouseup=\"dragging = false\"\n @mouseleave=\"dragging = false\">\n <table\n v-if=\"sheet\"\n class=\"pk-spreadsheet-preview__grid\"\n :class=\"{\n 'pk-spreadsheet-preview__grid--lines': sheet.gridlines,\n }\"\n :style=\"{ zoom, width: `${gridWidth}px` }\">\n <colgroup>\n <col :style=\"{ width: `${ROW_HEAD_WIDTH}px` }\" />\n <col\n v-for=\"c in columns\"\n :key=\"c.col\"\n :style=\"{ width: `${c.width}px` }\" />\n </colgroup>\n <thead>\n <tr :style=\"{ height: `${HEAD_HEIGHT}px` }\">\n <th class=\"pk-spreadsheet-preview__corner\" />\n <th\n v-for=\"c in columns\"\n :key=\"c.col\"\n scope=\"col\"\n class=\"pk-spreadsheet-preview__head\"\n :class=\"{\n 'pk-spreadsheet-preview__head--current':\n c.col >= range.c1 && c.col <= range.c2,\n }\">\n {{ letters(c.col) }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n v-for=\"r in rows\"\n :key=\"r.row\"\n v-memo=\"[\n r,\n sheet,\n columnsKey,\n locale,\n rowSelection(r.row),\n ]\"\n :style=\"{ height: `${r.height}px` }\">\n <th\n scope=\"row\"\n class=\"pk-spreadsheet-preview__row\"\n :class=\"{\n 'pk-spreadsheet-preview__row--current':\n r.row >= range.r1 && r.row <= range.r2,\n }\"\n :style=\"\n sheet.frozen && r.row <= sheet.frozen.rows\n ? {\n ...frozenCss(r.row, 0),\n left: 0,\n zIndex: 4,\n }\n : undefined\n \">\n {{ r.row }}\n </th>\n <template v-for=\"c in columns\" :key=\"c.col\">\n <td\n v-if=\"!covered.has(`${r.row},${c.col}`)\"\n :rowspan=\"shownSpan(r.row, c.col)?.rows\"\n :colspan=\"shownSpan(r.row, c.col)?.cols\"\n class=\"pk-spreadsheet-preview__cell\"\n :class=\"{\n 'pk-spreadsheet-preview__cell--range':\n inRange(r.row, c.col) &&\n !isFocus(r.row, c.col),\n 'pk-spreadsheet-preview__cell--missing':\n cellAt(r.row, c.col)?.missing,\n }\"\n :style=\"\n cellCss(cellAt(r.row, c.col), r.row, c.col)\n \"\n :data-focus=\"\n isFocus(r.row, c.col) ? '' : undefined\n \"\n :title=\"\n cellAt(r.row, c.col)?.missing\n ? $t('chatFilePreview.missingValue')\n : undefined\n \"\n @mousedown.prevent=\"pick(r.row, c.col, $event)\"\n @mouseenter=\"extend(r.row, c.col)\">\n {{ textOf(cellAt(r.row, c.col)) }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <p\n v-if=\"sheet && (sheet.moreRows || sheet.moreColumns)\"\n class=\"pk-spreadsheet-preview__more\">\n <template v-if=\"sheet.moreRows\">\n {{ $t('chatFilePreview.moreRows', sheet.moreRows) }}\n </template>\n <template v-if=\"sheet.moreColumns\">\n {{ $t('chatFilePreview.moreColumns', sheet.moreColumns) }}\n </template>\n </p>\n </div>\n <nav\n class=\"pk-spreadsheet-preview__sheets\"\n :aria-label=\"$t('chatFilePreview.sheets')\">\n <button\n v-for=\"(s, i) in preview.sheets\"\n :key=\"s.name\"\n type=\"button\"\n class=\"pk-spreadsheet-preview__sheet\"\n :aria-current=\"i === active ? 'page' : undefined\"\n @click=\"active = i\">\n {{ s.name }}\n </button>\n </nav>\n <div class=\"pk-spreadsheet-preview__status\">\n <p class=\"pk-spreadsheet-preview__info\">\n <span\n v-if=\"preview.staleFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.staleFormulas')\">\n {{ $t('chatFilePreview.staleFormulas') }}\n </span>\n <span\n v-else-if=\"preview.computedFormulas\"\n class=\"pk-spreadsheet-preview__note\"\n :title=\"$t('chatFilePreview.computedFormulas')\">\n {{ $t('chatFilePreview.computedFormulas') }}\n </span>\n <span v-if=\"stats\" class=\"pk-spreadsheet-preview__stats\">\n <span\n v-if=\"stats.average\"\n class=\"pk-spreadsheet-preview__average\">\n {{ $t('chatFilePreview.average') }} {{ stats.average }}\n </span>\n <span>\n {{ $t('chatFilePreview.count') }} {{ stats.count }}\n </span>\n <span v-if=\"stats.sum\">\n {{ $t('chatFilePreview.sum') }} {{ stats.sum }}\n </span>\n </span>\n </p>\n <div class=\"pk-spreadsheet-preview__zoom\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.5\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-spreadsheet-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-spreadsheet-preview {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n\n // Excel's green marks the active cell, its column and row and the\n // current sheet, as in Excel (decided 2026-10-29). The cells keep\n // their paper in both themes; the headers lighten it on the dark one.\n --pk-spreadsheet-green: #217346;\n --pk-spreadsheet-green-head: #217346;\n\n // The formula bar: the cell, fx and its content, as in Excel\n &__bar {\n display: flex;\n align-items: stretch;\n min-height: var(--spacing-40);\n border-bottom: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n font-size: var(--text-14);\n }\n\n &__ref {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n width: var(--spacing-96);\n padding: 0 var(--spacing-12);\n box-sizing: border-box;\n border-right: var(--border) solid var(--color-surface-3);\n font-variant-numeric: tabular-nums;\n }\n\n &__fx {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-40);\n border-right: var(--border) solid var(--color-surface-3);\n color: var(--color-word-3);\n font-family: Georgia, serif;\n font-style: italic;\n }\n\n &__formula {\n display: flex;\n flex: 1;\n align-items: center;\n min-width: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n // The grid scrolls both ways; its headers stay\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n background-color: #fff;\n outline: none;\n cursor: cell;\n\n &:focus-visible {\n box-shadow: inset 0 0 0 var(--spacing-2)\n var(--input-focus-color);\n }\n }\n\n &__grid {\n border-collapse: collapse;\n table-layout: fixed;\n color: #000;\n font-family: Calibri, Carlito, 'Segoe UI', Arial, sans-serif;\n font-size: 11pt;\n user-select: none;\n\n td {\n overflow: hidden;\n max-width: 0;\n padding: 0 var(--spacing-4);\n background-color: #fff;\n line-height: 1.2;\n text-overflow: clip;\n }\n\n &--lines td {\n border: var(--border) solid #e1e1e1;\n }\n }\n\n // The letters and the numbers follow the theme, the cells do not\n &__corner,\n &__head,\n &__row {\n position: sticky;\n z-index: 1;\n border: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-3);\n font-family: var(--font-family-sans);\n font-size: var(--text-12);\n font-weight: var(--font-normal);\n text-align: center;\n }\n\n // The letters sit in the middle of their row, room above and below\n &__corner,\n &__head {\n top: 0;\n padding: var(--spacing-4) var(--spacing-4) var(--spacing-2);\n line-height: 1;\n vertical-align: middle;\n }\n\n &__row {\n vertical-align: middle;\n }\n\n &__corner {\n left: 0;\n z-index: 5;\n }\n\n &__row {\n left: 0;\n padding: 0 var(--spacing-4);\n font-variant-numeric: tabular-nums;\n }\n\n // Where the selection is, as Excel shows it: one step of surface,\n // and the letter and a thin line in its green\n &__head--current {\n background-color: var(--color-surface-2);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__row--current {\n background-color: var(--color-surface-2);\n box-shadow: inset calc(var(--spacing-2) * -1) 0 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-medium);\n }\n\n &__cell[data-focus] {\n outline: var(--spacing-2) solid var(--pk-spreadsheet-green);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n\n &__cell--range {\n box-shadow: inset 0 0 0 100vmax rgb(31 29 43 / 8%);\n }\n\n &__cell--missing {\n color: #6b6880;\n }\n\n &__more {\n position: sticky;\n left: 0;\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n color: #6b6880;\n font-size: var(--text-12);\n }\n\n // The sheets at the bottom, as Excel draws its tabs, and the status\n // bar below them: two rows, as in Excel, so the sums of a selection\n // never push the sheets or the note out of a narrow frame\n &__sheets {\n display: flex;\n flex-shrink: 0;\n min-height: var(--spacing-32);\n overflow-x: auto;\n padding-left: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n\n @media (pointer: coarse) {\n min-height: var(--spacing-40);\n }\n }\n\n &__status {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n min-height: var(--spacing-40);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n font-size: var(--text-12);\n }\n\n &__sheet {\n flex-shrink: 0;\n padding: 0 var(--spacing-16);\n border: 0;\n border-right: var(--border) solid var(--color-surface-3);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-12);\n white-space: nowrap;\n cursor: pointer;\n\n &:first-child {\n border-left: var(--border) solid var(--color-surface-3);\n }\n\n &:hover {\n background-color: var(--color-surface-2);\n }\n\n &[aria-current='page'] {\n background-color: var(--color-surface);\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--pk-spreadsheet-green-head);\n color: var(--pk-spreadsheet-green-head);\n font-weight: var(--font-semibold);\n }\n }\n\n // The note on the left, as Excel's messages, the sums on the right:\n // the note gives way to them\n &__info {\n display: flex;\n flex: 1;\n align-items: center;\n gap: var(--spacing-16);\n min-width: 0;\n margin: 0;\n padding: 0 var(--spacing-12);\n overflow: hidden;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__note {\n min-width: 0;\n overflow: hidden;\n color: var(--color-word-3);\n text-overflow: ellipsis;\n }\n\n &__stats {\n display: flex;\n flex-shrink: 0;\n gap: var(--spacing-12);\n margin-left: auto;\n }\n\n // A phone keeps the count and the sum of a selection\n @container (width < 26rem) {\n &__average {\n display: none;\n }\n }\n\n &__zoom {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n gap: var(--spacing-2);\n padding-right: var(--spacing-8);\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n\n // On the dark headers Excel's green reads too dark: a lighter step of it\n @media (prefers-color-scheme: dark) {\n :where(:host, :root, .theme):not(.theme--light)\n .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n }\n\n :where(.theme.theme--dark) .pk-spreadsheet-preview {\n --pk-spreadsheet-green-head: #5fbf8f;\n }\n</style>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { WordPreviewRun } from 'models'\n import { wordFontStack, type WordPreviewMode } from './utils'\n\n /**\n * The runs of a paragraph or a cell of a Word document in the viewer, as\n * text with the look the document gives them: font, size, color,\n * highlight, bold, italic, underline, capitals. With the revisions in\n * sight, a tracked change is struck where words went and underlined\n * where they came, its author said on hover; as if accepted or as before\n * them, the changed text is plain. An image is a placeholder.\n */\n const props = defineProps<{\n runs: WordPreviewRun[]\n mode?: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** The runs the mode keeps: a deletion is gone once accepted. */\n const shown = computed(() =>\n props.runs.filter((run) =>\n props.mode === 'accepted'\n ? run.change !== 'deleted'\n : props.mode === 'original'\n ? run.change !== 'inserted'\n : true,\n ),\n )\n const marked = computed(() => !props.mode || props.mode === 'markup')\n\n const cssOf = (run: WordPreviewRun): CSSProperties => {\n const css: CSSProperties = {}\n if (run.font) {\n css.fontFamily = wordFontStack(run.font)\n }\n if (run.size) {\n css.fontSize = `${run.size}pt`\n }\n if (run.color) {\n css.color = run.color\n }\n if (run.highlight) {\n css.backgroundColor = run.highlight\n }\n if (run.bold) {\n css.fontWeight = 700\n }\n if (run.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n run.underline ? 'underline' : '',\n run.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (run.caps) {\n css.textTransform = 'uppercase'\n }\n if (run.vertAlign) {\n css.verticalAlign = run.vertAlign\n css.fontSize = `${(run.size ?? 11) * 0.65}pt`\n }\n return css\n }\n\n /** A tracked change keeps its mark over the run's own lines. */\n const changeCss = (run: WordPreviewRun): CSSProperties => {\n const css = cssOf(run)\n const lines = new Set(\n String(css.textDecoration ?? '')\n .split(' ')\n .filter(Boolean),\n )\n lines.add(run.change === 'deleted' ? 'line-through' : 'underline')\n return { ...css, textDecoration: [...lines].join(' ') }\n }\n\n const titleOf = (run: WordPreviewRun) =>\n run.author\n ? $t('chatFilePreview.revisionBy', { author: run.author })\n : undefined\n</script>\n\n<template>\n <!-- Each text sits against its tags: the block keeps whitespace\n (pre-wrap), so a line break inside a tag would draw a space in the\n middle of a word split across runs. -->\n <template v-for=\"(run, k) in shown\" :key=\"k\">\n <span v-if=\"run.image\" class=\"pk-word-preview__image\">{{\n $t('chatFilePreview.image')\n }}</span>\n <del\n v-else-if=\"marked && run.change === 'deleted'\"\n class=\"pk-word-preview__removed\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</del\n >\n <ins\n v-else-if=\"marked && run.change === 'inserted'\"\n class=\"pk-word-preview__added\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</ins\n >\n <span v-else :style=\"cssOf(run)\">{{ run.text }}</span>\n </template>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { WordPreviewRun } from 'models'\n import { wordFontStack, type WordPreviewMode } from './utils'\n\n /**\n * The runs of a paragraph or a cell of a Word document in the viewer, as\n * text with the look the document gives them: font, size, color,\n * highlight, bold, italic, underline, capitals. With the revisions in\n * sight, a tracked change is struck where words went and underlined\n * where they came, its author said on hover; as if accepted or as before\n * them, the changed text is plain. An image is a placeholder.\n */\n const props = defineProps<{\n runs: WordPreviewRun[]\n mode?: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** The runs the mode keeps: a deletion is gone once accepted. */\n const shown = computed(() =>\n props.runs.filter((run) =>\n props.mode === 'accepted'\n ? run.change !== 'deleted'\n : props.mode === 'original'\n ? run.change !== 'inserted'\n : true,\n ),\n )\n const marked = computed(() => !props.mode || props.mode === 'markup')\n\n const cssOf = (run: WordPreviewRun): CSSProperties => {\n const css: CSSProperties = {}\n if (run.font) {\n css.fontFamily = wordFontStack(run.font)\n }\n if (run.size) {\n css.fontSize = `${run.size}pt`\n }\n if (run.color) {\n css.color = run.color\n }\n if (run.highlight) {\n css.backgroundColor = run.highlight\n }\n if (run.bold) {\n css.fontWeight = 700\n }\n if (run.italic) {\n css.fontStyle = 'italic'\n }\n const lines = [\n run.underline ? 'underline' : '',\n run.strike ? 'line-through' : '',\n ]\n .filter(Boolean)\n .join(' ')\n if (lines) {\n css.textDecoration = lines\n }\n if (run.caps) {\n css.textTransform = 'uppercase'\n }\n if (run.vertAlign) {\n css.verticalAlign = run.vertAlign\n css.fontSize = `${(run.size ?? 11) * 0.65}pt`\n }\n return css\n }\n\n /** A tracked change keeps its mark over the run's own lines. */\n const changeCss = (run: WordPreviewRun): CSSProperties => {\n const css = cssOf(run)\n const lines = new Set(\n String(css.textDecoration ?? '')\n .split(' ')\n .filter(Boolean),\n )\n lines.add(run.change === 'deleted' ? 'line-through' : 'underline')\n return { ...css, textDecoration: [...lines].join(' ') }\n }\n\n const titleOf = (run: WordPreviewRun) =>\n run.author\n ? $t('chatFilePreview.revisionBy', { author: run.author })\n : undefined\n</script>\n\n<template>\n <!-- Each text sits against its tags: the block keeps whitespace\n (pre-wrap), so a line break inside a tag would draw a space in the\n middle of a word split across runs. -->\n <template v-for=\"(run, k) in shown\" :key=\"k\">\n <span v-if=\"run.image\" class=\"pk-word-preview__image\">{{\n $t('chatFilePreview.image')\n }}</span>\n <del\n v-else-if=\"marked && run.change === 'deleted'\"\n class=\"pk-word-preview__removed\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</del\n >\n <ins\n v-else-if=\"marked && run.change === 'inserted'\"\n class=\"pk-word-preview__added\"\n :style=\"changeCss(run)\"\n :title=\"titleOf(run)\"\n >{{ run.text }}</ins\n >\n <span v-else :style=\"cssOf(run)\">{{ run.text }}</span>\n </template>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import type { WordPreviewBlock } from 'models'\n import PkWordPreviewRuns from './PkWordPreviewRuns.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * One piece of a Word document's flow in the viewer: a paragraph or a\n * heading laid out as its style says (alignment, indents, spacing, line\n * height, the number of a list item in its hanging indent), or one row of\n * a table, so a table can break between pages as Word breaks it. A\n * paragraph with a tracked change carries Word's bar in the margin.\n */\n const props = defineProps<{\n block: WordPreviewBlock\n /** The row of a table this piece draws. */\n row?: number\n mode: WordPreviewMode\n }>()\n\n const paragraphCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const s = props.block.style ?? {}\n return {\n textAlign: s.align,\n paddingLeft: s.indentLeft ? `${s.indentLeft}pt` : undefined,\n paddingRight: s.indentRight ? `${s.indentRight}pt` : undefined,\n textIndent: s.firstLine ? `${s.firstLine}pt` : undefined,\n // Padding, so each block is measured with its spaces. Between two\n // paragraphs Word keeps the larger space, not both: the preview\n // already took the space after from the next one's space before.\n paddingTop: s.spaceBefore ? `${s.spaceBefore}pt` : undefined,\n paddingBottom: s.spaceAfter ? `${s.spaceAfter}pt` : undefined,\n // A multiple of Word's single line for the document's font,\n // which the viewer sets as `--pk-word-line`; \"At least\" is that\n // line or the points, the higher.\n lineHeight: s.lineExact\n ? `${s.lineExact}pt`\n : s.lineAtLeast\n ? `max(calc(var(--pk-word-line, 1.17) * 1em), ${s.lineAtLeast}pt)`\n : `calc(var(--pk-word-line, 1.17) * ${s.lineHeight ?? 1})`,\n backgroundColor: s.shading,\n }\n })\n\n /** The number hangs in the indent, the text starts where Word puts it. */\n const labelCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const hanging = -(props.block.style?.firstLine ?? 0)\n return hanging > 0\n ? { minWidth: `${hanging}pt` }\n : { paddingRight: '6pt' }\n })\n\n const changed = computed(\n () =>\n props.mode === 'markup' &&\n props.block.kind !== 'table' &&\n props.block.runs.some((r) => r.change),\n )\n\n const tableRow = computed(() =>\n props.block.kind === 'table' && props.row !== undefined\n ? props.block.rows[props.row]\n : undefined,\n )\n const columns = computed(() => {\n if (props.block.kind !== 'table') {\n return []\n }\n const widths = props.block.widths ?? []\n const total = widths.reduce((a, b) => a + b, 0)\n return total ? widths.map((w) => `${(w / total) * 100}%`) : []\n })\n const rowChanged = computed(\n () =>\n props.mode === 'markup' &&\n !!tableRow.value?.some((cell) => cell.runs.some((r) => r.change)),\n )\n</script>\n\n<template>\n <table\n v-if=\"block.kind === 'table' && tableRow\"\n class=\"pk-word-preview__table\"\n :class=\"{\n 'pk-word-preview__table--lines': block.borders,\n 'pk-word-preview__table--next': row !== 0,\n 'pk-word-preview__changed': rowChanged,\n }\">\n <colgroup v-if=\"columns.length\">\n <col v-for=\"(w, i) in columns\" :key=\"i\" :style=\"{ width: w }\" />\n </colgroup>\n <tbody>\n <tr>\n <td\n v-for=\"(cell, c) in tableRow\"\n :key=\"c\"\n :colspan=\"cell.span\"\n :style=\"{\n backgroundColor: cell.fill,\n textAlign: cell.align,\n }\">\n <PkWordPreviewRuns :runs=\"cell.runs\" :mode />\n </td>\n </tr>\n </tbody>\n </table>\n <div\n v-else-if=\"block.kind !== 'table'\"\n class=\"pk-word-preview__block\"\n :class=\"{ 'pk-word-preview__changed': changed }\"\n :role=\"block.kind === 'heading' ? 'heading' : undefined\"\n :aria-level=\"\n block.kind === 'heading' ? Math.max(1, block.level) : undefined\n \"\n :style=\"paragraphCss\">\n <span\n v-if=\"block.label\"\n class=\"pk-word-preview__label\"\n :style=\"labelCss\"\n >{{ block.label }}</span\n ><PkWordPreviewRuns :runs=\"block.runs\" :mode />\n <!-- An empty paragraph of the document is a blank line, as in Word -->\n <br v-if=\"!block.label && !block.runs.length\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import { computed } from 'vue'\n import type { WordPreviewBlock } from 'models'\n import PkWordPreviewRuns from './PkWordPreviewRuns.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * One piece of a Word document's flow in the viewer: a paragraph or a\n * heading laid out as its style says (alignment, indents, spacing, line\n * height, the number of a list item in its hanging indent), or one row of\n * a table, so a table can break between pages as Word breaks it. A\n * paragraph with a tracked change carries Word's bar in the margin.\n */\n const props = defineProps<{\n block: WordPreviewBlock\n /** The row of a table this piece draws. */\n row?: number\n mode: WordPreviewMode\n }>()\n\n const paragraphCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const s = props.block.style ?? {}\n return {\n textAlign: s.align,\n paddingLeft: s.indentLeft ? `${s.indentLeft}pt` : undefined,\n paddingRight: s.indentRight ? `${s.indentRight}pt` : undefined,\n textIndent: s.firstLine ? `${s.firstLine}pt` : undefined,\n // Padding, so each block is measured with its spaces. Between two\n // paragraphs Word keeps the larger space, not both: the preview\n // already took the space after from the next one's space before.\n paddingTop: s.spaceBefore ? `${s.spaceBefore}pt` : undefined,\n paddingBottom: s.spaceAfter ? `${s.spaceAfter}pt` : undefined,\n // A multiple of Word's single line for the document's font,\n // which the viewer sets as `--pk-word-line`; \"At least\" is that\n // line or the points, the higher.\n lineHeight: s.lineExact\n ? `${s.lineExact}pt`\n : s.lineAtLeast\n ? `max(calc(var(--pk-word-line, 1.17) * 1em), ${s.lineAtLeast}pt)`\n : `calc(var(--pk-word-line, 1.17) * ${s.lineHeight ?? 1})`,\n backgroundColor: s.shading,\n }\n })\n\n /** The number hangs in the indent, the text starts where Word puts it. */\n const labelCss = computed((): CSSProperties => {\n if (props.block.kind === 'table') {\n return {}\n }\n const hanging = -(props.block.style?.firstLine ?? 0)\n return hanging > 0\n ? { minWidth: `${hanging}pt` }\n : { paddingRight: '6pt' }\n })\n\n const changed = computed(\n () =>\n props.mode === 'markup' &&\n props.block.kind !== 'table' &&\n props.block.runs.some((r) => r.change),\n )\n\n const tableRow = computed(() =>\n props.block.kind === 'table' && props.row !== undefined\n ? props.block.rows[props.row]\n : undefined,\n )\n const columns = computed(() => {\n if (props.block.kind !== 'table') {\n return []\n }\n const widths = props.block.widths ?? []\n const total = widths.reduce((a, b) => a + b, 0)\n return total ? widths.map((w) => `${(w / total) * 100}%`) : []\n })\n const rowChanged = computed(\n () =>\n props.mode === 'markup' &&\n !!tableRow.value?.some((cell) => cell.runs.some((r) => r.change)),\n )\n</script>\n\n<template>\n <table\n v-if=\"block.kind === 'table' && tableRow\"\n class=\"pk-word-preview__table\"\n :class=\"{\n 'pk-word-preview__table--lines': block.borders,\n 'pk-word-preview__table--next': row !== 0,\n 'pk-word-preview__changed': rowChanged,\n }\">\n <colgroup v-if=\"columns.length\">\n <col v-for=\"(w, i) in columns\" :key=\"i\" :style=\"{ width: w }\" />\n </colgroup>\n <tbody>\n <tr>\n <td\n v-for=\"(cell, c) in tableRow\"\n :key=\"c\"\n :colspan=\"cell.span\"\n :style=\"{\n backgroundColor: cell.fill,\n textAlign: cell.align,\n }\">\n <PkWordPreviewRuns :runs=\"cell.runs\" :mode />\n </td>\n </tr>\n </tbody>\n </table>\n <div\n v-else-if=\"block.kind !== 'table'\"\n class=\"pk-word-preview__block\"\n :class=\"{ 'pk-word-preview__changed': changed }\"\n :role=\"block.kind === 'heading' ? 'heading' : undefined\"\n :aria-level=\"\n block.kind === 'heading' ? Math.max(1, block.level) : undefined\n \"\n :style=\"paragraphCss\">\n <span\n v-if=\"block.label\"\n class=\"pk-word-preview__label\"\n :style=\"labelCss\"\n >{{ block.label }}</span\n ><PkWordPreviewRuns :runs=\"block.runs\" :mode />\n <!-- An empty paragraph of the document is a blank line, as in Word -->\n <br v-if=\"!block.label && !block.runs.length\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type { WordPreview, WordPreviewRun } from 'models'\n import PkWordPreviewBlock from './PkWordPreviewBlock.vue'\n import {\n wordFontStack,\n wordLineFactor,\n type WordPreviewMode,\n } from './utils'\n\n /**\n * A Word document stored in the chat, drawn in pages as Word draws it\n * (spec `chat-office-files.md`, F6, item 3, and the viewer of its\n * follow-ups): white pages of the document's size and margins on a grey\n * ground, its fonts and its layout. The pages are computed here: each\n * paragraph and each table row is measured at the width of the page and\n * placed on the next page when it does not fit, or where the document\n * breaks the page, so they come close to Word's without matching them.\n * Below 640 pixels the text flows at the width of the screen. A side\n * panel lists the headings and the tracked changes, and leads to them.\n * The pages keep their white in the dark theme. Framed by\n * `PkFilePreview`.\n */\n const props = defineProps<{\n preview: WordPreview\n mode: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** Pixels in a point. */\n const PX = 96 / 72\n\n // #region the flow: paragraphs and table rows\n const kept = (runs: WordPreviewRun[]) =>\n runs.filter((r) =>\n props.mode === 'accepted'\n ? r.change !== 'deleted'\n : props.mode === 'original'\n ? r.change !== 'inserted'\n : true,\n )\n const hasText = (runs: WordPreviewRun[]) =>\n runs.some((r) => r.image || r.text.trim())\n\n type Item = {\n key: string\n block: number\n row?: number\n breakBefore: boolean\n }\n /**\n * What the pages hold, in order. A paragraph or a table row a mode\n * empties is gone (a row inserted, as the original); one empty in the\n * document stays, a blank line as in Word.\n */\n const items = computed(() => {\n const out: Item[] = []\n props.preview.blocks.forEach((block, b) => {\n if (block.kind === 'table') {\n let first = true\n block.rows.forEach((cells, r) => {\n const filled = cells.some((cell) => cell.runs.length)\n if (\n filled &&\n !cells.some((cell) => hasText(kept(cell.runs)))\n ) {\n return\n }\n out.push({\n key: `${b}:${r}`,\n block: b,\n row: r,\n breakBefore: first && !!block.pageBreakBefore,\n })\n first = false\n })\n } else if (!block.runs.length || hasText(kept(block.runs))) {\n out.push({\n key: `${b}`,\n block: b,\n breakBefore: !!block.style?.pageBreakBefore,\n })\n }\n })\n return out\n })\n // #endregion\n\n // #region pages\n const rootEl = useTemplateRef<HTMLElement>('rootEl')\n const scrollEl = useTemplateRef<HTMLElement>('scrollEl')\n const measureEl = useTemplateRef<HTMLElement>('measureEl')\n const { width } = useElementSize(rootEl)\n const { width: scrollWidth } = useElementSize(scrollEl)\n const paged = computed(() => width.value === 0 || width.value >= 640)\n const wide = computed(() => width.value >= 1000)\n\n const page = computed(() => props.preview.page)\n const textCss = computed((): CSSProperties => ({\n fontFamily: wordFontStack(props.preview.defaults.font),\n fontSize: `${props.preview.defaults.size}pt`,\n color: props.preview.defaults.color ?? '#000000',\n '--pk-word-line': wordLineFactor(props.preview.defaults.font),\n }))\n const pageCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${page.value.width}pt`,\n minHeight: `${page.value.height}pt`,\n padding: `${page.value.margins.top}pt ${page.value.margins.right}pt ${page.value.margins.bottom}pt ${page.value.margins.left}pt`,\n }))\n const measureCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${\n page.value.width -\n page.value.margins.left -\n page.value.margins.right\n }pt`,\n }))\n\n const heights = ref<number[]>([])\n const measure = async () => {\n await nextTick()\n const els =\n measureEl.value?.querySelectorAll<HTMLElement>('[data-item]')\n heights.value = [...(els ?? [])].map(\n (el) => el.getBoundingClientRect().height,\n )\n }\n watch([items, paged], measure, { flush: 'post' })\n onMounted(() => {\n measure()\n // The document's fonts change the lines once they arrive.\n document.fonts?.ready.then(measure)\n })\n\n /** The items of each page, by their index in `items`. */\n const pages = computed(() => {\n const all = items.value.map((_, i) => i)\n if (!paged.value || heights.value.length !== items.value.length) {\n return [all]\n }\n const room =\n (page.value.height -\n page.value.margins.top -\n page.value.margins.bottom) *\n PX\n const out: number[][] = [[]]\n let used = 0\n items.value.forEach((item, i) => {\n const h = heights.value[i]\n if (\n out[out.length - 1].length &&\n (item.breakBefore || used + h > room)\n ) {\n out.push([])\n used = 0\n }\n out[out.length - 1].push(i)\n used += h\n })\n return out\n })\n // #endregion\n\n // #region zoom and the page in view\n // Models, so the zoom stays when the viewer moves between the panel and\n // the dialog (`PkChatbotViewChat` keeps it).\n const fit = defineModel<boolean>('fit', { default: true })\n const manual = defineModel<number>('zoom', { default: 1 })\n const zoom = computed(() =>\n fit.value\n ? Math.min(\n 1.25,\n Math.max(\n 0.3,\n (scrollWidth.value - 48) / (page.value.width * PX),\n ),\n )\n : manual.value,\n )\n const zoomBy = (step: number) => {\n manual.value = Math.min(\n 2,\n Math.max(0.3, Math.round((zoom.value + step) * 10) / 10),\n )\n fit.value = false\n }\n\n const currentPage = ref(0)\n const currentHeading = ref<string>()\n /**\n * The page and the heading being read. Pages and headings go down in\n * order, so the search stops at the first one below the line; and it runs\n * once a frame, however many scroll events come.\n */\n const locate = () => {\n const box = scrollEl.value?.getBoundingClientRect()\n if (!box) {\n return\n }\n const pageEls = scrollEl.value?.querySelectorAll('[data-page]') ?? []\n let n = 0\n for (const [i, el] of [...pageEls].entries()) {\n if (el.getBoundingClientRect().top - box.top > box.height / 3) {\n break\n }\n n = i\n }\n currentPage.value = n\n let heading: string | undefined\n for (const h of headings.value) {\n const el = scrollEl.value?.querySelector(`[data-key=\"${h.key}\"]`)\n if (!el) {\n continue\n }\n if (el.getBoundingClientRect().top - box.top > 48) {\n break\n }\n heading = h.key\n }\n currentHeading.value = heading ?? headings.value[0]?.key\n }\n let frame = 0\n const onScroll = () => {\n frame ||= requestAnimationFrame(() => {\n frame = 0\n locate()\n })\n }\n onBeforeUnmount(() => cancelAnimationFrame(frame))\n watch(pages, () => nextTick(onScroll))\n // #endregion\n\n // #region the side panel: headings and tracked changes\n const textOf = (runs: WordPreviewRun[]) =>\n kept(runs)\n .map((r) => r.text)\n .join('')\n .replace(/\\s+/g, ' ')\n .trim()\n\n const headings = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n return block.kind === 'heading' && block.level <= 3\n ? [\n {\n key: item.key,\n level: block.level,\n text: [block.label, textOf(block.runs)]\n .filter(Boolean)\n .join(' '),\n },\n ]\n : []\n }),\n )\n\n const clip = (s: string) => (s.length > 60 ? `${s.slice(0, 60)}…` : s)\n const changes = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n const runs =\n block.kind === 'table'\n ? (block.rows[item.row ?? 0] ?? []).flatMap((c) => c.runs)\n : block.runs\n const removed = runs\n .filter((r) => r.change === 'deleted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n const added = runs\n .filter((r) => r.change === 'inserted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n return removed || added\n ? [\n {\n key: item.key,\n removed: clip(removed),\n added: clip(added),\n },\n ]\n : []\n }),\n )\n\n const tab = ref<'outline' | 'changes'>('outline')\n const sideOpen = ref(false)\n const goTo = (key: string) => {\n scrollEl.value\n ?.querySelector(`[data-key=\"${key}\"]`)\n ?.scrollIntoView({ block: 'start', behavior: 'smooth' })\n if (!wide.value) {\n sideOpen.value = false\n }\n }\n // #endregion\n\n const words = computed(\n () =>\n props.preview.blocks\n .flatMap((b) =>\n b.kind === 'table'\n ? b.rows.flat().map((c) => textOf(c.runs))\n : [textOf(b.runs)],\n )\n .join(' ')\n .split(/\\s+/)\n .filter(Boolean).length,\n )\n const authors = computed(() => props.preview.revisionAuthors.join(', '))\n</script>\n\n<template>\n <div\n ref=\"rootEl\"\n class=\"pk-word-preview\"\n :class=\"{ 'pk-word-preview--paged': paged }\">\n <aside\n v-if=\"(wide || sideOpen) && (headings.length || changes.length)\"\n class=\"pk-word-preview__side\"\n :class=\"{ 'pk-word-preview__side--over': !wide }\"\n :aria-label=\"$t('chatFilePreview.outline')\">\n <div class=\"pk-word-preview__tabs\" role=\"tablist\">\n <button\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'outline'\"\n @click=\"tab = 'outline'\">\n {{ $t('chatFilePreview.outline') }}\n </button>\n <button\n v-if=\"changes.length\"\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'changes'\"\n @click=\"tab = 'changes'\">\n {{\n $t('chatFilePreview.changes', { count: changes.length })\n }}\n </button>\n </div>\n <nav\n v-if=\"tab === 'outline' || !changes.length\"\n class=\"pk-word-preview__list\">\n <button\n v-for=\"h in headings\"\n :key=\"h.key\"\n type=\"button\"\n class=\"pk-word-preview__entry\"\n :class=\"`pk-word-preview__entry--${Math.min(h.level, 3)}`\"\n :aria-current=\"\n currentHeading === h.key ? 'location' : undefined\n \"\n @click=\"goTo(h.key)\">\n <span class=\"pk-word-preview__entry-text\">{{\n h.text\n }}</span>\n <span\n v-if=\"changes.some((c) => c.key === h.key)\"\n class=\"u-dot\" />\n </button>\n <p v-if=\"!headings.length\" class=\"pk-word-preview__none\">\n {{ $t('chatFilePreview.noHeadings') }}\n </p>\n </nav>\n <nav v-else class=\"pk-word-preview__list\">\n <button\n v-for=\"c in changes\"\n :key=\"c.key\"\n type=\"button\"\n class=\"pk-word-preview__entry pk-word-preview__entry--change\"\n @click=\"goTo(c.key)\">\n <del v-if=\"c.removed\" class=\"pk-word-preview__removed\">{{\n c.removed\n }}</del>\n <ins v-if=\"c.added\" class=\"pk-word-preview__added\">{{\n c.added\n }}</ins>\n </button>\n </nav>\n </aside>\n <div class=\"pk-word-preview__main\">\n <div\n ref=\"scrollEl\"\n class=\"pk-word-preview__scroll\"\n @scroll=\"onScroll\">\n <div\n v-if=\"paged\"\n class=\"pk-word-preview__pages\"\n :style=\"{ zoom }\">\n <article\n v-for=\"(p, n) in pages\"\n :key=\"n\"\n data-page\n class=\"pk-word-preview__page\"\n :aria-label=\"\n $t('chatFilePreview.pageOf', {\n page: n + 1,\n count: pages.length,\n })\n \"\n :style=\"pageCss\">\n <PkWordPreviewBlock\n v-for=\"i in p\"\n :key=\"items[i].key\"\n :data-key=\"items[i].key\"\n :block=\"preview.blocks[items[i].block]\"\n :row=\"items[i].row\"\n :mode />\n </article>\n </div>\n <article\n v-else\n class=\"pk-word-preview__page pk-word-preview__page--flow\"\n :style=\"textCss\">\n <PkWordPreviewBlock\n v-for=\"item in items\"\n :key=\"item.key\"\n :data-key=\"item.key\"\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </article>\n <p v-if=\"preview.truncated\" class=\"pk-word-preview__truncated\">\n {{ $t('chatFilePreview.truncated') }}\n </p>\n </div>\n <div class=\"pk-word-preview__status\">\n <span v-if=\"paged\" class=\"pk-word-preview__count\">\n {{\n $t('chatFilePreview.pageOf', {\n page: currentPage + 1,\n count: pages.length,\n })\n }}\n </span>\n <span class=\"pk-word-preview__count\">\n {{ $t('chatFilePreview.words', words) }}\n </span>\n <span\n v-if=\"mode === 'markup' && preview.revisionAuthors.length\"\n class=\"pk-word-preview__legend\">\n <span\n class=\"pk-word-preview__legend-text\"\n :title=\"$t('chatFilePreview.revisionsOf', { authors })\">\n {{ $t('chatFilePreview.revisionsOf', { authors }) }}\n </span>\n <del class=\"pk-word-preview__removed\">{{\n $t('chatFilePreview.removed')\n }}</del>\n <ins class=\"pk-word-preview__added\">{{\n $t('chatFilePreview.added')\n }}</ins>\n </span>\n <span class=\"pk-word-preview__spacer\" />\n <VvButton\n v-if=\"!wide && (headings.length || changes.length)\"\n class=\"pk-word-preview__outline-toggle\"\n modifiers=\"action-quiet\"\n icon=\"ri:list-unordered\"\n :label=\"$t('chatFilePreview.outline')\"\n :title=\"$t('chatFilePreview.outline')\"\n :aria-label=\"$t('chatFilePreview.outline')\"\n :aria-expanded=\"sideOpen\"\n @click=\"sideOpen = !sideOpen\" />\n <template v-if=\"paged\">\n <VvButton\n modifiers=\"action-quiet\"\n :label=\"$t('chatFilePreview.fitWidth')\"\n :disabled=\"fit\"\n @click=\"fit = true\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.3\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-word-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </template>\n </div>\n </div>\n <!-- Each paragraph and row at the page's width, to find its height -->\n <div\n v-if=\"paged\"\n ref=\"measureEl\"\n class=\"pk-word-preview__measure\"\n aria-hidden=\"true\"\n :style=\"measureCss\">\n <div v-for=\"item in items\" :key=\"item.key\" data-item>\n <PkWordPreviewBlock\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-word-preview {\n position: relative;\n display: flex;\n flex: 1;\n min-height: 0;\n\n // The headings and the changes, beside the pages or over them\n &__side {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-12);\n width: 16.5rem;\n flex-shrink: 0;\n padding: var(--spacing-12);\n box-sizing: border-box;\n overflow-y: auto;\n border-right: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n\n &--over {\n position: absolute;\n inset: 0 auto var(--spacing-40) 0;\n z-index: 3;\n box-shadow: var(--shadow-lg);\n }\n }\n\n &__tabs {\n display: flex;\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__tab {\n flex: 1;\n min-height: var(--spacing-40);\n border: 0;\n background: none;\n color: var(--color-word-3);\n font: inherit;\n font-size: var(--text-14);\n cursor: pointer;\n\n &[aria-selected='true'] {\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--color-word-1);\n color: var(--color-word-1);\n font-weight: var(--font-semibold);\n }\n }\n\n // One frame, hairline rows (DESIGN.md, principle 4)\n &__list {\n display: flex;\n flex-direction: column;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n overflow: hidden;\n }\n\n &__entry {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n min-height: var(--spacing-40);\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-bottom: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-14);\n text-align: start;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:last-child {\n border-bottom: 0;\n }\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n // The heading in view: surface and bar (DESIGN.md, principle 3)\n &[aria-current='location'] {\n background-color: var(--color-surface-2);\n box-shadow: inset var(--spacing-3) 0 0 var(--color-word-2);\n color: var(--color-word-1);\n font-weight: var(--font-medium);\n }\n\n &--0 {\n font-weight: var(--font-semibold);\n }\n\n &--2 {\n padding-left: var(--spacing-24);\n }\n\n &--3 {\n padding-left: var(--spacing-36);\n }\n\n &--change {\n flex-wrap: wrap;\n gap: var(--spacing-4) var(--spacing-8);\n font-size: var(--text-12);\n }\n }\n\n &__entry-text {\n flex: 1;\n min-width: 0;\n }\n\n &__none {\n margin: 0;\n padding: var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__main {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n }\n\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n padding: var(--spacing-md);\n background-color: var(--color-surface-2);\n }\n\n &__pages {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--spacing-24);\n width: max-content;\n min-width: 100%;\n }\n\n // A sheet of the document's size; white in both themes, as printed\n &__page {\n position: relative;\n box-sizing: border-box;\n background-color: #fff;\n box-shadow:\n 0 1px 3px rgb(20 14 51 / 16%),\n 0 10px 28px rgb(20 14 51 / 8%);\n line-height: var(--pk-word-line, 1.17);\n overflow-wrap: break-word;\n\n &--flow {\n width: 100%;\n padding: var(--spacing-24) var(--spacing-20);\n }\n }\n\n &__measure {\n position: absolute;\n top: 0;\n left: -100000px;\n visibility: hidden;\n pointer-events: none;\n line-height: var(--pk-word-line, 1.17);\n\n // As the page breaks a long word, or a link measures one line\n // and draws three\n overflow-wrap: break-word;\n }\n\n &__block {\n position: relative;\n margin: 0;\n\n // A tab or a line break of the document stays where Word put it\n white-space: pre-wrap;\n }\n\n &__label {\n display: inline-block;\n text-indent: 0;\n }\n\n // Word's bar in the margin beside a changed paragraph\n &__changed::before {\n content: '';\n position: absolute;\n top: 0;\n bottom: 0;\n left: -14pt;\n width: 1.5pt;\n background-color: #3f3c51;\n }\n\n &__table {\n position: relative;\n width: 100%;\n margin: 0;\n border-collapse: collapse;\n table-layout: fixed;\n\n td {\n padding: 0 5.4pt;\n vertical-align: top;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n &--lines td {\n border: 0.5pt solid #000;\n }\n\n // A row after the first: its top line is the row's above\n &--lines.pk-word-preview__table--next td {\n border-top: 0;\n }\n }\n\n // The marks of the card of an edit (PkToolChatFile.vue): the change is\n // the verdict the preview shows, the exception of DESIGN.md principle 2.\n // The base styles take the line off `del`.\n &__removed {\n color: var(--u-danger-text, #c42b3c);\n text-decoration: line-through;\n }\n\n &__added {\n color: var(--u-success-text, #178230);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n // Inside the white page the marks keep the light theme's colors\n &__page &__removed {\n color: #c42b3c;\n }\n\n &__page &__added {\n color: #178230;\n }\n\n // A word replaced: what went and what came, not run together\n &__removed + &__added {\n margin-inline-start: 0.15em;\n }\n\n &__image {\n display: inline-block;\n padding: var(--spacing-2) var(--spacing-8);\n border: var(--border) dashed #c9c8d2;\n border-radius: var(--rounded);\n color: #6b6880;\n font-size: 9pt;\n text-indent: 0;\n }\n\n &__truncated {\n margin: var(--spacing-md) 0 0;\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__status {\n display: flex;\n align-items: center;\n gap: var(--spacing-16);\n min-height: var(--spacing-40);\n padding: 0 var(--spacing-8) 0 var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n font-size: var(--text-12);\n white-space: nowrap;\n\n // Only the legend's words give way in a narrow frame\n > * {\n flex-shrink: 0;\n }\n }\n\n &__count {\n font-variant-numeric: tabular-nums;\n }\n\n &__status > &__legend {\n display: flex;\n flex-shrink: 1;\n gap: var(--spacing-8);\n min-width: 0;\n }\n\n // The words shorten, the two marks they explain stay\n &__legend-text {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n\n &__legend > &__removed,\n &__legend > &__added {\n flex-shrink: 0;\n }\n\n &__spacer {\n flex: 1;\n }\n\n // A phone keeps the outline's icon\n @container (width < 30rem) {\n &__outline-toggle .vv-button__label {\n display: none;\n }\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type { WordPreview, WordPreviewRun } from 'models'\n import PkWordPreviewBlock from './PkWordPreviewBlock.vue'\n import {\n wordFontStack,\n wordLineFactor,\n type WordPreviewMode,\n } from './utils'\n\n /**\n * A Word document stored in the chat, drawn in pages as Word draws it\n * (spec `chat-office-files.md`, F6, item 3, and the viewer of its\n * follow-ups): white pages of the document's size and margins on a grey\n * ground, its fonts and its layout. The pages are computed here: each\n * paragraph and each table row is measured at the width of the page and\n * placed on the next page when it does not fit, or where the document\n * breaks the page, so they come close to Word's without matching them.\n * Below 640 pixels the text flows at the width of the screen. A side\n * panel lists the headings and the tracked changes, and leads to them.\n * The pages keep their white in the dark theme. Framed by\n * `PkFilePreview`.\n */\n const props = defineProps<{\n preview: WordPreview\n mode: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** Pixels in a point. */\n const PX = 96 / 72\n\n // #region the flow: paragraphs and table rows\n const kept = (runs: WordPreviewRun[]) =>\n runs.filter((r) =>\n props.mode === 'accepted'\n ? r.change !== 'deleted'\n : props.mode === 'original'\n ? r.change !== 'inserted'\n : true,\n )\n const hasText = (runs: WordPreviewRun[]) =>\n runs.some((r) => r.image || r.text.trim())\n\n type Item = {\n key: string\n block: number\n row?: number\n breakBefore: boolean\n }\n /**\n * What the pages hold, in order. A paragraph or a table row a mode\n * empties is gone (a row inserted, as the original); one empty in the\n * document stays, a blank line as in Word.\n */\n const items = computed(() => {\n const out: Item[] = []\n props.preview.blocks.forEach((block, b) => {\n if (block.kind === 'table') {\n let first = true\n block.rows.forEach((cells, r) => {\n const filled = cells.some((cell) => cell.runs.length)\n if (\n filled &&\n !cells.some((cell) => hasText(kept(cell.runs)))\n ) {\n return\n }\n out.push({\n key: `${b}:${r}`,\n block: b,\n row: r,\n breakBefore: first && !!block.pageBreakBefore,\n })\n first = false\n })\n } else if (!block.runs.length || hasText(kept(block.runs))) {\n out.push({\n key: `${b}`,\n block: b,\n breakBefore: !!block.style?.pageBreakBefore,\n })\n }\n })\n return out\n })\n // #endregion\n\n // #region pages\n const rootEl = useTemplateRef<HTMLElement>('rootEl')\n const scrollEl = useTemplateRef<HTMLElement>('scrollEl')\n const measureEl = useTemplateRef<HTMLElement>('measureEl')\n const { width } = useElementSize(rootEl)\n const { width: scrollWidth } = useElementSize(scrollEl)\n const paged = computed(() => width.value === 0 || width.value >= 640)\n const wide = computed(() => width.value >= 1000)\n\n const page = computed(() => props.preview.page)\n const textCss = computed((): CSSProperties => ({\n fontFamily: wordFontStack(props.preview.defaults.font),\n fontSize: `${props.preview.defaults.size}pt`,\n color: props.preview.defaults.color ?? '#000000',\n '--pk-word-line': wordLineFactor(props.preview.defaults.font),\n }))\n const pageCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${page.value.width}pt`,\n minHeight: `${page.value.height}pt`,\n padding: `${page.value.margins.top}pt ${page.value.margins.right}pt ${page.value.margins.bottom}pt ${page.value.margins.left}pt`,\n }))\n const measureCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${\n page.value.width -\n page.value.margins.left -\n page.value.margins.right\n }pt`,\n }))\n\n const heights = ref<number[]>([])\n const measure = async () => {\n await nextTick()\n const els =\n measureEl.value?.querySelectorAll<HTMLElement>('[data-item]')\n heights.value = [...(els ?? [])].map(\n (el) => el.getBoundingClientRect().height,\n )\n }\n watch([items, paged], measure, { flush: 'post' })\n onMounted(() => {\n measure()\n // The document's fonts change the lines once they arrive.\n document.fonts?.ready.then(measure)\n })\n\n /** The items of each page, by their index in `items`. */\n const pages = computed(() => {\n const all = items.value.map((_, i) => i)\n if (!paged.value || heights.value.length !== items.value.length) {\n return [all]\n }\n const room =\n (page.value.height -\n page.value.margins.top -\n page.value.margins.bottom) *\n PX\n const out: number[][] = [[]]\n let used = 0\n items.value.forEach((item, i) => {\n const h = heights.value[i]\n if (\n out[out.length - 1].length &&\n (item.breakBefore || used + h > room)\n ) {\n out.push([])\n used = 0\n }\n out[out.length - 1].push(i)\n used += h\n })\n return out\n })\n // #endregion\n\n // #region zoom and the page in view\n // Models, so the zoom stays when the viewer moves between the panel and\n // the dialog (`PkChatbotViewChat` keeps it).\n const fit = defineModel<boolean>('fit', { default: true })\n const manual = defineModel<number>('zoom', { default: 1 })\n const zoom = computed(() =>\n fit.value\n ? Math.min(\n 1.25,\n Math.max(\n 0.3,\n (scrollWidth.value - 48) / (page.value.width * PX),\n ),\n )\n : manual.value,\n )\n const zoomBy = (step: number) => {\n manual.value = Math.min(\n 2,\n Math.max(0.3, Math.round((zoom.value + step) * 10) / 10),\n )\n fit.value = false\n }\n\n const currentPage = ref(0)\n const currentHeading = ref<string>()\n /**\n * The page and the heading being read. Pages and headings go down in\n * order, so the search stops at the first one below the line; and it runs\n * once a frame, however many scroll events come.\n */\n const locate = () => {\n const box = scrollEl.value?.getBoundingClientRect()\n if (!box) {\n return\n }\n const pageEls = scrollEl.value?.querySelectorAll('[data-page]') ?? []\n let n = 0\n for (const [i, el] of [...pageEls].entries()) {\n if (el.getBoundingClientRect().top - box.top > box.height / 3) {\n break\n }\n n = i\n }\n currentPage.value = n\n let heading: string | undefined\n for (const h of headings.value) {\n const el = scrollEl.value?.querySelector(`[data-key=\"${h.key}\"]`)\n if (!el) {\n continue\n }\n if (el.getBoundingClientRect().top - box.top > 48) {\n break\n }\n heading = h.key\n }\n currentHeading.value = heading ?? headings.value[0]?.key\n }\n let frame = 0\n const onScroll = () => {\n frame ||= requestAnimationFrame(() => {\n frame = 0\n locate()\n })\n }\n onBeforeUnmount(() => cancelAnimationFrame(frame))\n watch(pages, () => nextTick(onScroll))\n // #endregion\n\n // #region the side panel: headings and tracked changes\n const textOf = (runs: WordPreviewRun[]) =>\n kept(runs)\n .map((r) => r.text)\n .join('')\n .replace(/\\s+/g, ' ')\n .trim()\n\n const headings = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n return block.kind === 'heading' && block.level <= 3\n ? [\n {\n key: item.key,\n level: block.level,\n text: [block.label, textOf(block.runs)]\n .filter(Boolean)\n .join(' '),\n },\n ]\n : []\n }),\n )\n\n const clip = (s: string) => (s.length > 60 ? `${s.slice(0, 60)}…` : s)\n const changes = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n const runs =\n block.kind === 'table'\n ? (block.rows[item.row ?? 0] ?? []).flatMap((c) => c.runs)\n : block.runs\n const removed = runs\n .filter((r) => r.change === 'deleted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n const added = runs\n .filter((r) => r.change === 'inserted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n return removed || added\n ? [\n {\n key: item.key,\n removed: clip(removed),\n added: clip(added),\n },\n ]\n : []\n }),\n )\n\n const tab = ref<'outline' | 'changes'>('outline')\n const sideOpen = ref(false)\n const goTo = (key: string) => {\n scrollEl.value\n ?.querySelector(`[data-key=\"${key}\"]`)\n ?.scrollIntoView({ block: 'start', behavior: 'smooth' })\n if (!wide.value) {\n sideOpen.value = false\n }\n }\n // #endregion\n\n const words = computed(\n () =>\n props.preview.blocks\n .flatMap((b) =>\n b.kind === 'table'\n ? b.rows.flat().map((c) => textOf(c.runs))\n : [textOf(b.runs)],\n )\n .join(' ')\n .split(/\\s+/)\n .filter(Boolean).length,\n )\n const authors = computed(() => props.preview.revisionAuthors.join(', '))\n</script>\n\n<template>\n <div\n ref=\"rootEl\"\n class=\"pk-word-preview\"\n :class=\"{ 'pk-word-preview--paged': paged }\">\n <aside\n v-if=\"(wide || sideOpen) && (headings.length || changes.length)\"\n class=\"pk-word-preview__side\"\n :class=\"{ 'pk-word-preview__side--over': !wide }\"\n :aria-label=\"$t('chatFilePreview.outline')\">\n <div class=\"pk-word-preview__tabs\" role=\"tablist\">\n <button\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'outline'\"\n @click=\"tab = 'outline'\">\n {{ $t('chatFilePreview.outline') }}\n </button>\n <button\n v-if=\"changes.length\"\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'changes'\"\n @click=\"tab = 'changes'\">\n {{\n $t('chatFilePreview.changes', { count: changes.length })\n }}\n </button>\n </div>\n <nav\n v-if=\"tab === 'outline' || !changes.length\"\n class=\"pk-word-preview__list\">\n <button\n v-for=\"h in headings\"\n :key=\"h.key\"\n type=\"button\"\n class=\"pk-word-preview__entry\"\n :class=\"`pk-word-preview__entry--${Math.min(h.level, 3)}`\"\n :aria-current=\"\n currentHeading === h.key ? 'location' : undefined\n \"\n @click=\"goTo(h.key)\">\n <span class=\"pk-word-preview__entry-text\">{{\n h.text\n }}</span>\n <span\n v-if=\"changes.some((c) => c.key === h.key)\"\n class=\"u-dot\" />\n </button>\n <p v-if=\"!headings.length\" class=\"pk-word-preview__none\">\n {{ $t('chatFilePreview.noHeadings') }}\n </p>\n </nav>\n <nav v-else class=\"pk-word-preview__list\">\n <button\n v-for=\"c in changes\"\n :key=\"c.key\"\n type=\"button\"\n class=\"pk-word-preview__entry pk-word-preview__entry--change\"\n @click=\"goTo(c.key)\">\n <del v-if=\"c.removed\" class=\"pk-word-preview__removed\">{{\n c.removed\n }}</del>\n <ins v-if=\"c.added\" class=\"pk-word-preview__added\">{{\n c.added\n }}</ins>\n </button>\n </nav>\n </aside>\n <div class=\"pk-word-preview__main\">\n <div\n ref=\"scrollEl\"\n class=\"pk-word-preview__scroll\"\n @scroll=\"onScroll\">\n <div\n v-if=\"paged\"\n class=\"pk-word-preview__pages\"\n :style=\"{ zoom }\">\n <article\n v-for=\"(p, n) in pages\"\n :key=\"n\"\n data-page\n class=\"pk-word-preview__page\"\n :aria-label=\"\n $t('chatFilePreview.pageOf', {\n page: n + 1,\n count: pages.length,\n })\n \"\n :style=\"pageCss\">\n <PkWordPreviewBlock\n v-for=\"i in p\"\n :key=\"items[i].key\"\n :data-key=\"items[i].key\"\n :block=\"preview.blocks[items[i].block]\"\n :row=\"items[i].row\"\n :mode />\n </article>\n </div>\n <article\n v-else\n class=\"pk-word-preview__page pk-word-preview__page--flow\"\n :style=\"textCss\">\n <PkWordPreviewBlock\n v-for=\"item in items\"\n :key=\"item.key\"\n :data-key=\"item.key\"\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </article>\n <p v-if=\"preview.truncated\" class=\"pk-word-preview__truncated\">\n {{ $t('chatFilePreview.truncated') }}\n </p>\n </div>\n <div class=\"pk-word-preview__status\">\n <span v-if=\"paged\" class=\"pk-word-preview__count\">\n {{\n $t('chatFilePreview.pageOf', {\n page: currentPage + 1,\n count: pages.length,\n })\n }}\n </span>\n <span class=\"pk-word-preview__count\">\n {{ $t('chatFilePreview.words', words) }}\n </span>\n <span\n v-if=\"mode === 'markup' && preview.revisionAuthors.length\"\n class=\"pk-word-preview__legend\">\n <span\n class=\"pk-word-preview__legend-text\"\n :title=\"$t('chatFilePreview.revisionsOf', { authors })\">\n {{ $t('chatFilePreview.revisionsOf', { authors }) }}\n </span>\n <del class=\"pk-word-preview__removed\">{{\n $t('chatFilePreview.removed')\n }}</del>\n <ins class=\"pk-word-preview__added\">{{\n $t('chatFilePreview.added')\n }}</ins>\n </span>\n <span class=\"pk-word-preview__spacer\" />\n <VvButton\n v-if=\"!wide && (headings.length || changes.length)\"\n class=\"pk-word-preview__outline-toggle\"\n modifiers=\"action-quiet\"\n icon=\"ri:list-unordered\"\n :label=\"$t('chatFilePreview.outline')\"\n :title=\"$t('chatFilePreview.outline')\"\n :aria-label=\"$t('chatFilePreview.outline')\"\n :aria-expanded=\"sideOpen\"\n @click=\"sideOpen = !sideOpen\" />\n <template v-if=\"paged\">\n <VvButton\n modifiers=\"action-quiet\"\n :label=\"$t('chatFilePreview.fitWidth')\"\n :disabled=\"fit\"\n @click=\"fit = true\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.3\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-word-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </template>\n </div>\n </div>\n <!-- Each paragraph and row at the page's width, to find its height -->\n <div\n v-if=\"paged\"\n ref=\"measureEl\"\n class=\"pk-word-preview__measure\"\n aria-hidden=\"true\"\n :style=\"measureCss\">\n <div v-for=\"item in items\" :key=\"item.key\" data-item>\n <PkWordPreviewBlock\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-word-preview {\n position: relative;\n display: flex;\n flex: 1;\n min-height: 0;\n\n // The headings and the changes, beside the pages or over them\n &__side {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-12);\n width: 16.5rem;\n flex-shrink: 0;\n padding: var(--spacing-12);\n box-sizing: border-box;\n overflow-y: auto;\n border-right: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n\n &--over {\n position: absolute;\n inset: 0 auto var(--spacing-40) 0;\n z-index: 3;\n box-shadow: var(--shadow-lg);\n }\n }\n\n &__tabs {\n display: flex;\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__tab {\n flex: 1;\n min-height: var(--spacing-40);\n border: 0;\n background: none;\n color: var(--color-word-3);\n font: inherit;\n font-size: var(--text-14);\n cursor: pointer;\n\n &[aria-selected='true'] {\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--color-word-1);\n color: var(--color-word-1);\n font-weight: var(--font-semibold);\n }\n }\n\n // One frame, hairline rows (DESIGN.md, principle 4)\n &__list {\n display: flex;\n flex-direction: column;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n overflow: hidden;\n }\n\n &__entry {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n min-height: var(--spacing-40);\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-bottom: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-14);\n text-align: start;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:last-child {\n border-bottom: 0;\n }\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n // The heading in view: surface and bar (DESIGN.md, principle 3)\n &[aria-current='location'] {\n background-color: var(--color-surface-2);\n box-shadow: inset var(--spacing-3) 0 0 var(--color-word-2);\n color: var(--color-word-1);\n font-weight: var(--font-medium);\n }\n\n &--0 {\n font-weight: var(--font-semibold);\n }\n\n &--2 {\n padding-left: var(--spacing-24);\n }\n\n &--3 {\n padding-left: var(--spacing-36);\n }\n\n &--change {\n flex-wrap: wrap;\n gap: var(--spacing-4) var(--spacing-8);\n font-size: var(--text-12);\n }\n }\n\n &__entry-text {\n flex: 1;\n min-width: 0;\n }\n\n &__none {\n margin: 0;\n padding: var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__main {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n }\n\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n padding: var(--spacing-md);\n background-color: var(--color-surface-2);\n }\n\n &__pages {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--spacing-24);\n width: max-content;\n min-width: 100%;\n }\n\n // A sheet of the document's size; white in both themes, as printed\n &__page {\n position: relative;\n box-sizing: border-box;\n background-color: #fff;\n box-shadow:\n 0 1px 3px rgb(20 14 51 / 16%),\n 0 10px 28px rgb(20 14 51 / 8%);\n line-height: var(--pk-word-line, 1.17);\n overflow-wrap: break-word;\n\n &--flow {\n width: 100%;\n padding: var(--spacing-24) var(--spacing-20);\n }\n }\n\n &__measure {\n position: absolute;\n top: 0;\n left: -100000px;\n visibility: hidden;\n pointer-events: none;\n line-height: var(--pk-word-line, 1.17);\n\n // As the page breaks a long word, or a link measures one line\n // and draws three\n overflow-wrap: break-word;\n }\n\n &__block {\n position: relative;\n margin: 0;\n\n // A tab or a line break of the document stays where Word put it\n white-space: pre-wrap;\n }\n\n &__label {\n display: inline-block;\n text-indent: 0;\n }\n\n // Word's bar in the margin beside a changed paragraph\n &__changed::before {\n content: '';\n position: absolute;\n top: 0;\n bottom: 0;\n left: -14pt;\n width: 1.5pt;\n background-color: #3f3c51;\n }\n\n &__table {\n position: relative;\n width: 100%;\n margin: 0;\n border-collapse: collapse;\n table-layout: fixed;\n\n td {\n padding: 0 5.4pt;\n vertical-align: top;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n &--lines td {\n border: 0.5pt solid #000;\n }\n\n // A row after the first: its top line is the row's above\n &--lines.pk-word-preview__table--next td {\n border-top: 0;\n }\n }\n\n // The marks of the card of an edit (PkToolChatFile.vue): the change is\n // the verdict the preview shows, the exception of DESIGN.md principle 2.\n // The base styles take the line off `del`.\n &__removed {\n color: var(--u-danger-text, #c42b3c);\n text-decoration: line-through;\n }\n\n &__added {\n color: var(--u-success-text, #178230);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n // Inside the white page the marks keep the light theme's colors\n &__page &__removed {\n color: #c42b3c;\n }\n\n &__page &__added {\n color: #178230;\n }\n\n // A word replaced: what went and what came, not run together\n &__removed + &__added {\n margin-inline-start: 0.15em;\n }\n\n &__image {\n display: inline-block;\n padding: var(--spacing-2) var(--spacing-8);\n border: var(--border) dashed #c9c8d2;\n border-radius: var(--rounded);\n color: #6b6880;\n font-size: 9pt;\n text-indent: 0;\n }\n\n &__truncated {\n margin: var(--spacing-md) 0 0;\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__status {\n display: flex;\n align-items: center;\n gap: var(--spacing-16);\n min-height: var(--spacing-40);\n padding: 0 var(--spacing-8) 0 var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n font-size: var(--text-12);\n white-space: nowrap;\n\n // Only the legend's words give way in a narrow frame\n > * {\n flex-shrink: 0;\n }\n }\n\n &__count {\n font-variant-numeric: tabular-nums;\n }\n\n &__status > &__legend {\n display: flex;\n flex-shrink: 1;\n gap: var(--spacing-8);\n min-width: 0;\n }\n\n // The words shorten, the two marks they explain stay\n &__legend-text {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n\n &__legend > &__removed,\n &__legend > &__added {\n flex-shrink: 0;\n }\n\n &__spacer {\n flex: 1;\n }\n\n // A phone keeps the outline's icon\n @container (width < 30rem) {\n &__outline-toggle .vv-button__label {\n display: none;\n }\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import type { CSSProperties } from 'vue'\n import {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n } from 'vue'\n import { useElementSize } from '@vueuse/core'\n import { useI18n } from 'vue-i18n'\n import type { WordPreview, WordPreviewRun } from 'models'\n import PkWordPreviewBlock from './PkWordPreviewBlock.vue'\n import {\n wordFontStack,\n wordLineFactor,\n type WordPreviewMode,\n } from './utils'\n\n /**\n * A Word document stored in the chat, drawn in pages as Word draws it\n * (spec `chat-office-files.md`, F6, item 3, and the viewer of its\n * follow-ups): white pages of the document's size and margins on a grey\n * ground, its fonts and its layout. The pages are computed here: each\n * paragraph and each table row is measured at the width of the page and\n * placed on the next page when it does not fit, or where the document\n * breaks the page, so they come close to Word's without matching them.\n * Below 640 pixels the text flows at the width of the screen. A side\n * panel lists the headings and the tracked changes, and leads to them.\n * The pages keep their white in the dark theme. Framed by\n * `PkFilePreview`.\n */\n const props = defineProps<{\n preview: WordPreview\n mode: WordPreviewMode\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n /** Pixels in a point. */\n const PX = 96 / 72\n\n // #region the flow: paragraphs and table rows\n const kept = (runs: WordPreviewRun[]) =>\n runs.filter((r) =>\n props.mode === 'accepted'\n ? r.change !== 'deleted'\n : props.mode === 'original'\n ? r.change !== 'inserted'\n : true,\n )\n const hasText = (runs: WordPreviewRun[]) =>\n runs.some((r) => r.image || r.text.trim())\n\n type Item = {\n key: string\n block: number\n row?: number\n breakBefore: boolean\n }\n /**\n * What the pages hold, in order. A paragraph or a table row a mode\n * empties is gone (a row inserted, as the original); one empty in the\n * document stays, a blank line as in Word.\n */\n const items = computed(() => {\n const out: Item[] = []\n props.preview.blocks.forEach((block, b) => {\n if (block.kind === 'table') {\n let first = true\n block.rows.forEach((cells, r) => {\n const filled = cells.some((cell) => cell.runs.length)\n if (\n filled &&\n !cells.some((cell) => hasText(kept(cell.runs)))\n ) {\n return\n }\n out.push({\n key: `${b}:${r}`,\n block: b,\n row: r,\n breakBefore: first && !!block.pageBreakBefore,\n })\n first = false\n })\n } else if (!block.runs.length || hasText(kept(block.runs))) {\n out.push({\n key: `${b}`,\n block: b,\n breakBefore: !!block.style?.pageBreakBefore,\n })\n }\n })\n return out\n })\n // #endregion\n\n // #region pages\n const rootEl = useTemplateRef<HTMLElement>('rootEl')\n const scrollEl = useTemplateRef<HTMLElement>('scrollEl')\n const measureEl = useTemplateRef<HTMLElement>('measureEl')\n const { width } = useElementSize(rootEl)\n const { width: scrollWidth } = useElementSize(scrollEl)\n const paged = computed(() => width.value === 0 || width.value >= 640)\n const wide = computed(() => width.value >= 1000)\n\n const page = computed(() => props.preview.page)\n const textCss = computed((): CSSProperties => ({\n fontFamily: wordFontStack(props.preview.defaults.font),\n fontSize: `${props.preview.defaults.size}pt`,\n color: props.preview.defaults.color ?? '#000000',\n '--pk-word-line': wordLineFactor(props.preview.defaults.font),\n }))\n const pageCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${page.value.width}pt`,\n minHeight: `${page.value.height}pt`,\n padding: `${page.value.margins.top}pt ${page.value.margins.right}pt ${page.value.margins.bottom}pt ${page.value.margins.left}pt`,\n }))\n const measureCss = computed((): CSSProperties => ({\n ...textCss.value,\n width: `${\n page.value.width -\n page.value.margins.left -\n page.value.margins.right\n }pt`,\n }))\n\n const heights = ref<number[]>([])\n const measure = async () => {\n await nextTick()\n const els =\n measureEl.value?.querySelectorAll<HTMLElement>('[data-item]')\n heights.value = [...(els ?? [])].map(\n (el) => el.getBoundingClientRect().height,\n )\n }\n watch([items, paged], measure, { flush: 'post' })\n onMounted(() => {\n measure()\n // The document's fonts change the lines once they arrive.\n document.fonts?.ready.then(measure)\n })\n\n /** The items of each page, by their index in `items`. */\n const pages = computed(() => {\n const all = items.value.map((_, i) => i)\n if (!paged.value || heights.value.length !== items.value.length) {\n return [all]\n }\n const room =\n (page.value.height -\n page.value.margins.top -\n page.value.margins.bottom) *\n PX\n const out: number[][] = [[]]\n let used = 0\n items.value.forEach((item, i) => {\n const h = heights.value[i]\n if (\n out[out.length - 1].length &&\n (item.breakBefore || used + h > room)\n ) {\n out.push([])\n used = 0\n }\n out[out.length - 1].push(i)\n used += h\n })\n return out\n })\n // #endregion\n\n // #region zoom and the page in view\n // Models, so the zoom stays when the viewer moves between the panel and\n // the dialog (`PkChatbotViewChat` keeps it).\n const fit = defineModel<boolean>('fit', { default: true })\n const manual = defineModel<number>('zoom', { default: 1 })\n const zoom = computed(() =>\n fit.value\n ? Math.min(\n 1.25,\n Math.max(\n 0.3,\n (scrollWidth.value - 48) / (page.value.width * PX),\n ),\n )\n : manual.value,\n )\n const zoomBy = (step: number) => {\n manual.value = Math.min(\n 2,\n Math.max(0.3, Math.round((zoom.value + step) * 10) / 10),\n )\n fit.value = false\n }\n\n const currentPage = ref(0)\n const currentHeading = ref<string>()\n /**\n * The page and the heading being read. Pages and headings go down in\n * order, so the search stops at the first one below the line; and it runs\n * once a frame, however many scroll events come.\n */\n const locate = () => {\n const box = scrollEl.value?.getBoundingClientRect()\n if (!box) {\n return\n }\n const pageEls = scrollEl.value?.querySelectorAll('[data-page]') ?? []\n let n = 0\n for (const [i, el] of [...pageEls].entries()) {\n if (el.getBoundingClientRect().top - box.top > box.height / 3) {\n break\n }\n n = i\n }\n currentPage.value = n\n let heading: string | undefined\n for (const h of headings.value) {\n const el = scrollEl.value?.querySelector(`[data-key=\"${h.key}\"]`)\n if (!el) {\n continue\n }\n if (el.getBoundingClientRect().top - box.top > 48) {\n break\n }\n heading = h.key\n }\n currentHeading.value = heading ?? headings.value[0]?.key\n }\n let frame = 0\n const onScroll = () => {\n frame ||= requestAnimationFrame(() => {\n frame = 0\n locate()\n })\n }\n onBeforeUnmount(() => cancelAnimationFrame(frame))\n watch(pages, () => nextTick(onScroll))\n // #endregion\n\n // #region the side panel: headings and tracked changes\n const textOf = (runs: WordPreviewRun[]) =>\n kept(runs)\n .map((r) => r.text)\n .join('')\n .replace(/\\s+/g, ' ')\n .trim()\n\n const headings = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n return block.kind === 'heading' && block.level <= 3\n ? [\n {\n key: item.key,\n level: block.level,\n text: [block.label, textOf(block.runs)]\n .filter(Boolean)\n .join(' '),\n },\n ]\n : []\n }),\n )\n\n const clip = (s: string) => (s.length > 60 ? `${s.slice(0, 60)}…` : s)\n const changes = computed(() =>\n items.value.flatMap((item) => {\n const block = props.preview.blocks[item.block]\n const runs =\n block.kind === 'table'\n ? (block.rows[item.row ?? 0] ?? []).flatMap((c) => c.runs)\n : block.runs\n const removed = runs\n .filter((r) => r.change === 'deleted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n const added = runs\n .filter((r) => r.change === 'inserted')\n .map((r) => r.text)\n .join(' ')\n .trim()\n return removed || added\n ? [\n {\n key: item.key,\n removed: clip(removed),\n added: clip(added),\n },\n ]\n : []\n }),\n )\n\n const tab = ref<'outline' | 'changes'>('outline')\n const sideOpen = ref(false)\n const goTo = (key: string) => {\n scrollEl.value\n ?.querySelector(`[data-key=\"${key}\"]`)\n ?.scrollIntoView({ block: 'start', behavior: 'smooth' })\n if (!wide.value) {\n sideOpen.value = false\n }\n }\n // #endregion\n\n const words = computed(\n () =>\n props.preview.blocks\n .flatMap((b) =>\n b.kind === 'table'\n ? b.rows.flat().map((c) => textOf(c.runs))\n : [textOf(b.runs)],\n )\n .join(' ')\n .split(/\\s+/)\n .filter(Boolean).length,\n )\n const authors = computed(() => props.preview.revisionAuthors.join(', '))\n</script>\n\n<template>\n <div\n ref=\"rootEl\"\n class=\"pk-word-preview\"\n :class=\"{ 'pk-word-preview--paged': paged }\">\n <aside\n v-if=\"(wide || sideOpen) && (headings.length || changes.length)\"\n class=\"pk-word-preview__side\"\n :class=\"{ 'pk-word-preview__side--over': !wide }\"\n :aria-label=\"$t('chatFilePreview.outline')\">\n <div class=\"pk-word-preview__tabs\" role=\"tablist\">\n <button\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'outline'\"\n @click=\"tab = 'outline'\">\n {{ $t('chatFilePreview.outline') }}\n </button>\n <button\n v-if=\"changes.length\"\n type=\"button\"\n role=\"tab\"\n class=\"pk-word-preview__tab\"\n :aria-selected=\"tab === 'changes'\"\n @click=\"tab = 'changes'\">\n {{\n $t('chatFilePreview.changes', { count: changes.length })\n }}\n </button>\n </div>\n <nav\n v-if=\"tab === 'outline' || !changes.length\"\n class=\"pk-word-preview__list\">\n <button\n v-for=\"h in headings\"\n :key=\"h.key\"\n type=\"button\"\n class=\"pk-word-preview__entry\"\n :class=\"`pk-word-preview__entry--${Math.min(h.level, 3)}`\"\n :aria-current=\"\n currentHeading === h.key ? 'location' : undefined\n \"\n @click=\"goTo(h.key)\">\n <span class=\"pk-word-preview__entry-text\">{{\n h.text\n }}</span>\n <span\n v-if=\"changes.some((c) => c.key === h.key)\"\n class=\"u-dot\" />\n </button>\n <p v-if=\"!headings.length\" class=\"pk-word-preview__none\">\n {{ $t('chatFilePreview.noHeadings') }}\n </p>\n </nav>\n <nav v-else class=\"pk-word-preview__list\">\n <button\n v-for=\"c in changes\"\n :key=\"c.key\"\n type=\"button\"\n class=\"pk-word-preview__entry pk-word-preview__entry--change\"\n @click=\"goTo(c.key)\">\n <del v-if=\"c.removed\" class=\"pk-word-preview__removed\">{{\n c.removed\n }}</del>\n <ins v-if=\"c.added\" class=\"pk-word-preview__added\">{{\n c.added\n }}</ins>\n </button>\n </nav>\n </aside>\n <div class=\"pk-word-preview__main\">\n <div\n ref=\"scrollEl\"\n class=\"pk-word-preview__scroll\"\n @scroll=\"onScroll\">\n <div\n v-if=\"paged\"\n class=\"pk-word-preview__pages\"\n :style=\"{ zoom }\">\n <article\n v-for=\"(p, n) in pages\"\n :key=\"n\"\n data-page\n class=\"pk-word-preview__page\"\n :aria-label=\"\n $t('chatFilePreview.pageOf', {\n page: n + 1,\n count: pages.length,\n })\n \"\n :style=\"pageCss\">\n <PkWordPreviewBlock\n v-for=\"i in p\"\n :key=\"items[i].key\"\n :data-key=\"items[i].key\"\n :block=\"preview.blocks[items[i].block]\"\n :row=\"items[i].row\"\n :mode />\n </article>\n </div>\n <article\n v-else\n class=\"pk-word-preview__page pk-word-preview__page--flow\"\n :style=\"textCss\">\n <PkWordPreviewBlock\n v-for=\"item in items\"\n :key=\"item.key\"\n :data-key=\"item.key\"\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </article>\n <p v-if=\"preview.truncated\" class=\"pk-word-preview__truncated\">\n {{ $t('chatFilePreview.truncated') }}\n </p>\n </div>\n <div class=\"pk-word-preview__status\">\n <span v-if=\"paged\" class=\"pk-word-preview__count\">\n {{\n $t('chatFilePreview.pageOf', {\n page: currentPage + 1,\n count: pages.length,\n })\n }}\n </span>\n <span class=\"pk-word-preview__count\">\n {{ $t('chatFilePreview.words', words) }}\n </span>\n <span\n v-if=\"mode === 'markup' && preview.revisionAuthors.length\"\n class=\"pk-word-preview__legend\">\n <span\n class=\"pk-word-preview__legend-text\"\n :title=\"$t('chatFilePreview.revisionsOf', { authors })\">\n {{ $t('chatFilePreview.revisionsOf', { authors }) }}\n </span>\n <del class=\"pk-word-preview__removed\">{{\n $t('chatFilePreview.removed')\n }}</del>\n <ins class=\"pk-word-preview__added\">{{\n $t('chatFilePreview.added')\n }}</ins>\n </span>\n <span class=\"pk-word-preview__spacer\" />\n <VvButton\n v-if=\"!wide && (headings.length || changes.length)\"\n class=\"pk-word-preview__outline-toggle\"\n modifiers=\"action-quiet\"\n icon=\"ri:list-unordered\"\n :label=\"$t('chatFilePreview.outline')\"\n :title=\"$t('chatFilePreview.outline')\"\n :aria-label=\"$t('chatFilePreview.outline')\"\n :aria-expanded=\"sideOpen\"\n @click=\"sideOpen = !sideOpen\" />\n <template v-if=\"paged\">\n <VvButton\n modifiers=\"action-quiet\"\n :label=\"$t('chatFilePreview.fitWidth')\"\n :disabled=\"fit\"\n @click=\"fit = true\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:subtract-line\"\n :aria-label=\"$t('chatFilePreview.zoomOut')\"\n :disabled=\"zoom <= 0.3\"\n @click=\"zoomBy(-0.1)\" />\n <span class=\"pk-word-preview__percent\">\n {{ Math.round(zoom * 100) }}%\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:add-line\"\n :aria-label=\"$t('chatFilePreview.zoomIn')\"\n :disabled=\"zoom >= 2\"\n @click=\"zoomBy(0.1)\" />\n </template>\n </div>\n </div>\n <!-- Each paragraph and row at the page's width, to find its height -->\n <div\n v-if=\"paged\"\n ref=\"measureEl\"\n class=\"pk-word-preview__measure\"\n aria-hidden=\"true\"\n :style=\"measureCss\">\n <div v-for=\"item in items\" :key=\"item.key\" data-item>\n <PkWordPreviewBlock\n :block=\"preview.blocks[item.block]\"\n :row=\"item.row\"\n :mode />\n </div>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n .pk-word-preview {\n position: relative;\n display: flex;\n flex: 1;\n min-height: 0;\n\n // The headings and the changes, beside the pages or over them\n &__side {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-12);\n width: 16.5rem;\n flex-shrink: 0;\n padding: var(--spacing-12);\n box-sizing: border-box;\n overflow-y: auto;\n border-right: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface);\n\n &--over {\n position: absolute;\n inset: 0 auto var(--spacing-40) 0;\n z-index: 3;\n box-shadow: var(--shadow-lg);\n }\n }\n\n &__tabs {\n display: flex;\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__tab {\n flex: 1;\n min-height: var(--spacing-40);\n border: 0;\n background: none;\n color: var(--color-word-3);\n font: inherit;\n font-size: var(--text-14);\n cursor: pointer;\n\n &[aria-selected='true'] {\n box-shadow: inset 0 calc(var(--spacing-2) * -1) 0\n var(--color-word-1);\n color: var(--color-word-1);\n font-weight: var(--font-semibold);\n }\n }\n\n // One frame, hairline rows (DESIGN.md, principle 4)\n &__list {\n display: flex;\n flex-direction: column;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n overflow: hidden;\n }\n\n &__entry {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n min-height: var(--spacing-40);\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-bottom: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n font-size: var(--text-14);\n text-align: start;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:last-child {\n border-bottom: 0;\n }\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n // The heading in view: surface and bar (DESIGN.md, principle 3)\n &[aria-current='location'] {\n background-color: var(--color-surface-2);\n box-shadow: inset var(--spacing-3) 0 0 var(--color-word-2);\n color: var(--color-word-1);\n font-weight: var(--font-medium);\n }\n\n &--0 {\n font-weight: var(--font-semibold);\n }\n\n &--2 {\n padding-left: var(--spacing-24);\n }\n\n &--3 {\n padding-left: var(--spacing-36);\n }\n\n &--change {\n flex-wrap: wrap;\n gap: var(--spacing-4) var(--spacing-8);\n font-size: var(--text-12);\n }\n }\n\n &__entry-text {\n flex: 1;\n min-width: 0;\n }\n\n &__none {\n margin: 0;\n padding: var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__main {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n }\n\n &__scroll {\n flex: 1;\n min-height: 0;\n overflow: auto;\n padding: var(--spacing-md);\n background-color: var(--color-surface-2);\n }\n\n &__pages {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: var(--spacing-24);\n width: max-content;\n min-width: 100%;\n }\n\n // A sheet of the document's size; white in both themes, as printed\n &__page {\n position: relative;\n box-sizing: border-box;\n background-color: #fff;\n box-shadow:\n 0 1px 3px rgb(20 14 51 / 16%),\n 0 10px 28px rgb(20 14 51 / 8%);\n line-height: var(--pk-word-line, 1.17);\n overflow-wrap: break-word;\n\n &--flow {\n width: 100%;\n padding: var(--spacing-24) var(--spacing-20);\n }\n }\n\n &__measure {\n position: absolute;\n top: 0;\n left: -100000px;\n visibility: hidden;\n pointer-events: none;\n line-height: var(--pk-word-line, 1.17);\n\n // As the page breaks a long word, or a link measures one line\n // and draws three\n overflow-wrap: break-word;\n }\n\n &__block {\n position: relative;\n margin: 0;\n\n // A tab or a line break of the document stays where Word put it\n white-space: pre-wrap;\n }\n\n &__label {\n display: inline-block;\n text-indent: 0;\n }\n\n // Word's bar in the margin beside a changed paragraph\n &__changed::before {\n content: '';\n position: absolute;\n top: 0;\n bottom: 0;\n left: -14pt;\n width: 1.5pt;\n background-color: #3f3c51;\n }\n\n &__table {\n position: relative;\n width: 100%;\n margin: 0;\n border-collapse: collapse;\n table-layout: fixed;\n\n td {\n padding: 0 5.4pt;\n vertical-align: top;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n }\n\n &--lines td {\n border: 0.5pt solid #000;\n }\n\n // A row after the first: its top line is the row's above\n &--lines.pk-word-preview__table--next td {\n border-top: 0;\n }\n }\n\n // The marks of the card of an edit (PkToolChatFile.vue): the change is\n // the verdict the preview shows, the exception of DESIGN.md principle 2.\n // The base styles take the line off `del`.\n &__removed {\n color: var(--u-danger-text, #c42b3c);\n text-decoration: line-through;\n }\n\n &__added {\n color: var(--u-success-text, #178230);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n // Inside the white page the marks keep the light theme's colors\n &__page &__removed {\n color: #c42b3c;\n }\n\n &__page &__added {\n color: #178230;\n }\n\n // A word replaced: what went and what came, not run together\n &__removed + &__added {\n margin-inline-start: 0.15em;\n }\n\n &__image {\n display: inline-block;\n padding: var(--spacing-2) var(--spacing-8);\n border: var(--border) dashed #c9c8d2;\n border-radius: var(--rounded);\n color: #6b6880;\n font-size: 9pt;\n text-indent: 0;\n }\n\n &__truncated {\n margin: var(--spacing-md) 0 0;\n color: var(--color-word-3);\n font-size: var(--text-12);\n text-align: center;\n }\n\n &__status {\n display: flex;\n align-items: center;\n gap: var(--spacing-16);\n min-height: var(--spacing-40);\n padding: 0 var(--spacing-8) 0 var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-3);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n font-size: var(--text-12);\n white-space: nowrap;\n\n // Only the legend's words give way in a narrow frame\n > * {\n flex-shrink: 0;\n }\n }\n\n &__count {\n font-variant-numeric: tabular-nums;\n }\n\n &__status > &__legend {\n display: flex;\n flex-shrink: 1;\n gap: var(--spacing-8);\n min-width: 0;\n }\n\n // The words shorten, the two marks they explain stay\n &__legend-text {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n\n &__legend > &__removed,\n &__legend > &__added {\n flex-shrink: 0;\n }\n\n &__spacer {\n flex: 1;\n }\n\n // A phone keeps the outline's icon\n @container (width < 30rem) {\n &__outline-toggle .vv-button__label {\n display: none;\n }\n }\n\n &__percent {\n min-width: var(--spacing-40);\n font-variant-numeric: tabular-nums;\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, watch } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { ChatFilePreview } from 'models'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import PkSpreadsheetPreview from './PkSpreadsheetPreview.vue'\n import PkWordPreview from './PkWordPreview.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * The viewer of a Word document or a spreadsheet stored in the chat (spec\n * `chat-office-files.md`, F6, items 3 and 4, and their follow-ups): a head\n * with the file, its versions in the conversation, how to show the\n * revisions of a Word document, restore, download, a larger frame and\n * close, over the document drawn as Word or Excel draws it. The same\n * viewer goes in the panel beside the chat and in a dialog over it.\n */\n const props = defineProps<{\n kind: 'word' | 'spreadsheet'\n /** The name of the file, not of its version. */\n filename: string\n version?: number\n /** The versions of the file in the conversation, from 1. */\n versions?: number[]\n /** The authenticated download URL of the shown version. */\n downloadUrl: string\n preview?: ChatFilePreview\n loading?: boolean\n error?: boolean\n /** The shown version can be written again as the newest one. */\n restorable?: boolean\n /** Offers to move to the larger frame, or back to the panel. */\n resize?: 'expand' | 'shrink'\n }>()\n\n const emit = defineEmits<{\n close: []\n version: [version: number]\n restore: []\n resize: []\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const versions = computed(() => props.versions ?? [])\n const position = computed(() =>\n props.version ? versions.value.indexOf(props.version) : -1,\n )\n const previous = computed(() =>\n position.value > 0 ? versions.value[position.value - 1] : undefined,\n )\n const next = computed(() =>\n position.value >= 0 && position.value < versions.value.length - 1\n ? versions.value[position.value + 1]\n : undefined,\n )\n\n /**\n * How a Word document with tracked changes is drawn, and the sheet and\n * the zoom: models, so they stay when the viewer moves between the panel\n * and the dialog, where it is drawn anew.\n */\n const mode = defineModel<WordPreviewMode>('mode', { default: 'markup' })\n const sheet = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const fit = defineModel<boolean>('fit', { default: true })\n const modes = computed(() => [\n { value: 'markup', label: $t('chatFilePreview.modeMarkup') },\n { value: 'accepted', label: $t('chatFilePreview.modeAccepted') },\n { value: 'original', label: $t('chatFilePreview.modeOriginal') },\n ])\n const hasRevisions = computed(\n () =>\n props.preview?.kind === 'word' &&\n props.preview.revisionAuthors.length > 0,\n )\n // Another version starts with its revisions in sight.\n watch(\n () => props.version,\n () => {\n mode.value = 'markup'\n },\n )\n</script>\n\n<template>\n <!-- A dialog gives the focus to its first control, the arrow of the\n versions: it goes to the viewer, and the keyboard starts from here -->\n <section\n class=\"pk-file-preview\"\n :aria-label=\"filename\"\n tabindex=\"-1\"\n autofocus>\n <header class=\"pk-file-preview__head\">\n <div class=\"pk-file-preview__file\">\n <span class=\"pk-file-preview__tile\" aria-hidden=\"true\">\n <VvIcon\n :name=\"\n kind === 'word'\n ? 'ri:file-word-2-line'\n : 'ri:file-excel-2-line'\n \"\n :class=\"\n kind === 'word'\n ? 'pk-file-preview__icon--word'\n : 'pk-file-preview__icon--sheet'\n \" />\n </span>\n <div class=\"pk-file-preview__name\">\n <strong class=\"pk-file-preview__title\">\n {{ filename }}\n </strong>\n <span class=\"pk-file-preview__note\">\n {{ $t('chatFilePreview.readOnly') }}\n </span>\n </div>\n </div>\n <div\n v-if=\"(version && versions.length > 1) || hasRevisions\"\n class=\"pk-file-preview__tools\">\n <nav\n v-if=\"version && versions.length > 1\"\n class=\"pk-file-preview__versions\"\n :aria-label=\"$t('chatFilePreview.versions')\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-left-s-line\"\n :aria-label=\"$t('chatFilePreview.previousVersion')\"\n :disabled=\"!previous\"\n @click=\"previous && emit('version', previous)\" />\n <span class=\"pk-file-preview__version\">\n {{\n $t('chatFilePreview.versionOf', {\n version,\n count: versions.length,\n })\n }}\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-right-s-line\"\n :aria-label=\"$t('chatFilePreview.nextVersion')\"\n :disabled=\"!next\"\n @click=\"next && emit('version', next)\" />\n </nav>\n <PkEditorRadioButtons\n v-if=\"hasRevisions\"\n v-model=\"mode\"\n name=\"revisions\"\n segmented\n class=\"pk-file-preview__modes u-segmented-fit mb-0\"\n :aria-label=\"$t('chatFilePreview.modes')\"\n :options=\"modes\">\n <!-- The short name where the long one leaves the\n versions no room on the line -->\n <template #markup>\n <span class=\"pk-file-preview__mode-long\">\n {{ $t('chatFilePreview.modeMarkup') }}\n </span>\n <span class=\"pk-file-preview__mode-short\">\n {{ $t('chatFilePreview.modeMarkupShort') }}\n </span>\n </template>\n </PkEditorRadioButtons>\n </div>\n <div class=\"pk-file-preview__actions\">\n <VvButton\n v-if=\"restorable\"\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :label=\"$t('chatFilePreview.restore')\"\n @click=\"emit('restore')\" />\n <VvButton\n :href=\"downloadUrl\"\n download\n modifiers=\"action-quiet\"\n icon=\"ri:download-line\"\n :title=\"$t('chatFilePreview.download')\"\n :aria-label=\"$t('chatFilePreview.download')\" />\n <VvButton\n v-if=\"resize === 'expand'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-line\"\n :title=\"$t('chatFilePreview.expand')\"\n :aria-label=\"$t('chatFilePreview.expand')\"\n @click=\"emit('resize')\" />\n <VvButton\n v-else-if=\"resize === 'shrink'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-exit-line\"\n :title=\"$t('chatFilePreview.shrink')\"\n :aria-label=\"$t('chatFilePreview.shrink')\"\n @click=\"emit('resize')\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:close-line\"\n :title=\"$t('chatFilePreview.close')\"\n :aria-label=\"$t('chatFilePreview.close')\"\n @click=\"emit('close')\" />\n </div>\n </header>\n <div class=\"pk-file-preview__body\">\n <div v-if=\"loading\" class=\"pk-file-preview__skeleton vv-skeleton\">\n <div\n v-for=\"i in 8\"\n :key=\"i\"\n class=\"vv-skeleton__item pk-file-preview__skeleton-line\"\n :class=\"i % 3 ? 'w-full' : 'w-128'\" />\n </div>\n <p v-else-if=\"error || !preview\" class=\"pk-file-preview__empty\">\n {{ $t('chatFilePreview.unavailable') }}\n </p>\n <PkWordPreview\n v-else-if=\"preview.kind === 'word'\"\n v-model:zoom=\"zoom\"\n v-model:fit=\"fit\"\n :preview\n :mode=\"hasRevisions ? mode : 'markup'\" />\n <PkSpreadsheetPreview\n v-else\n v-model:sheet=\"sheet\"\n v-model:zoom=\"zoom\"\n :preview />\n </div>\n </section>\n</template>\n\n<style lang=\"scss\">\n .pk-file-preview {\n container-type: inline-size;\n display: flex;\n flex-direction: column;\n min-height: 0;\n height: 100%;\n outline: none;\n background-color: var(--color-surface);\n color: var(--color-word-1);\n\n &__head {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n padding: var(--spacing-12) var(--spacing-12) var(--spacing-12)\n var(--spacing-md);\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__file {\n display: flex;\n flex: 1 1 12rem;\n align-items: center;\n gap: var(--spacing-12);\n min-width: 0;\n }\n\n &__tile {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-32);\n height: var(--spacing-32);\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n\n .vv-icon {\n width: var(--spacing-18);\n height: var(--spacing-18);\n }\n }\n\n // The colors the file chip of the chat gives the two kinds\n &__icon--word {\n color: #2b7de9;\n }\n\n &__icon--sheet {\n color: #1f9d57;\n }\n\n &__name {\n display: flex;\n flex-direction: column;\n min-width: 0;\n }\n\n &__title {\n overflow: hidden;\n font-size: var(--text-14);\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n &__note {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n &__tools {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n }\n\n &__versions {\n display: flex;\n align-items: center;\n gap: var(--spacing-2);\n }\n\n &__version {\n font-size: var(--text-14);\n font-weight: var(--font-semibold);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__actions {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n margin-left: auto;\n }\n\n // In a narrow frame the file and its actions keep the first line,\n // the versions and the revisions take the second.\n @container (width < 52rem) {\n &__file {\n order: 1;\n }\n\n &__actions {\n order: 2;\n }\n\n &__tools {\n order: 3;\n flex-basis: 100%;\n }\n\n // The ways to show the revisions fill what the versions leave,\n // or go to a line of their own: never narrower than their words\n &__tools &__modes {\n flex: 1 1 auto;\n }\n }\n\n &__mode-short {\n display: none;\n }\n\n // Below this the long name puts the modes on a line of their own\n @container (width < 38rem) {\n &__mode-long {\n display: none;\n }\n\n &__mode-short {\n display: inline;\n }\n }\n\n // A phone gives them a line of their own, with less padding\n @container (width < 30rem) {\n &__tools &__modes {\n flex: 1 1 100%;\n\n .vv-radio {\n padding-inline: var(--spacing-4);\n }\n }\n }\n\n // The document scrolls inside its viewer, so the head stays in view\n &__body {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n background-color: var(--color-surface-1);\n }\n\n &__skeleton {\n width: min(42rem, calc(100% - 2 * var(--spacing-md)));\n margin: var(--spacing-md) auto;\n padding: var(--spacing-lg);\n box-sizing: border-box;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n background-color: var(--color-surface);\n }\n\n &__skeleton-line {\n height: var(--spacing-12);\n margin-bottom: var(--spacing-12);\n border-radius: var(--rounded);\n }\n\n &__empty {\n margin: var(--spacing-lg) var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-14);\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, watch } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { ChatFilePreview } from 'models'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import PkSpreadsheetPreview from './PkSpreadsheetPreview.vue'\n import PkWordPreview from './PkWordPreview.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * The viewer of a Word document or a spreadsheet stored in the chat (spec\n * `chat-office-files.md`, F6, items 3 and 4, and their follow-ups): a head\n * with the file, its versions in the conversation, how to show the\n * revisions of a Word document, restore, download, a larger frame and\n * close, over the document drawn as Word or Excel draws it. The same\n * viewer goes in the panel beside the chat and in a dialog over it.\n */\n const props = defineProps<{\n kind: 'word' | 'spreadsheet'\n /** The name of the file, not of its version. */\n filename: string\n version?: number\n /** The versions of the file in the conversation, from 1. */\n versions?: number[]\n /** The authenticated download URL of the shown version. */\n downloadUrl: string\n preview?: ChatFilePreview\n loading?: boolean\n error?: boolean\n /** The shown version can be written again as the newest one. */\n restorable?: boolean\n /** Offers to move to the larger frame, or back to the panel. */\n resize?: 'expand' | 'shrink'\n }>()\n\n const emit = defineEmits<{\n close: []\n version: [version: number]\n restore: []\n resize: []\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const versions = computed(() => props.versions ?? [])\n const position = computed(() =>\n props.version ? versions.value.indexOf(props.version) : -1,\n )\n const previous = computed(() =>\n position.value > 0 ? versions.value[position.value - 1] : undefined,\n )\n const next = computed(() =>\n position.value >= 0 && position.value < versions.value.length - 1\n ? versions.value[position.value + 1]\n : undefined,\n )\n\n /**\n * How a Word document with tracked changes is drawn, and the sheet and\n * the zoom: models, so they stay when the viewer moves between the panel\n * and the dialog, where it is drawn anew.\n */\n const mode = defineModel<WordPreviewMode>('mode', { default: 'markup' })\n const sheet = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const fit = defineModel<boolean>('fit', { default: true })\n const modes = computed(() => [\n { value: 'markup', label: $t('chatFilePreview.modeMarkup') },\n { value: 'accepted', label: $t('chatFilePreview.modeAccepted') },\n { value: 'original', label: $t('chatFilePreview.modeOriginal') },\n ])\n const hasRevisions = computed(\n () =>\n props.preview?.kind === 'word' &&\n props.preview.revisionAuthors.length > 0,\n )\n // Another version starts with its revisions in sight.\n watch(\n () => props.version,\n () => {\n mode.value = 'markup'\n },\n )\n</script>\n\n<template>\n <!-- A dialog gives the focus to its first control, the arrow of the\n versions: it goes to the viewer, and the keyboard starts from here -->\n <section\n class=\"pk-file-preview\"\n :aria-label=\"filename\"\n tabindex=\"-1\"\n autofocus>\n <header class=\"pk-file-preview__head\">\n <div class=\"pk-file-preview__file\">\n <span class=\"pk-file-preview__tile\" aria-hidden=\"true\">\n <VvIcon\n :name=\"\n kind === 'word'\n ? 'ri:file-word-2-line'\n : 'ri:file-excel-2-line'\n \"\n :class=\"\n kind === 'word'\n ? 'pk-file-preview__icon--word'\n : 'pk-file-preview__icon--sheet'\n \" />\n </span>\n <div class=\"pk-file-preview__name\">\n <strong class=\"pk-file-preview__title\">\n {{ filename }}\n </strong>\n <span class=\"pk-file-preview__note\">\n {{ $t('chatFilePreview.readOnly') }}\n </span>\n </div>\n </div>\n <div\n v-if=\"(version && versions.length > 1) || hasRevisions\"\n class=\"pk-file-preview__tools\">\n <nav\n v-if=\"version && versions.length > 1\"\n class=\"pk-file-preview__versions\"\n :aria-label=\"$t('chatFilePreview.versions')\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-left-s-line\"\n :aria-label=\"$t('chatFilePreview.previousVersion')\"\n :disabled=\"!previous\"\n @click=\"previous && emit('version', previous)\" />\n <span class=\"pk-file-preview__version\">\n {{\n $t('chatFilePreview.versionOf', {\n version,\n count: versions.length,\n })\n }}\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-right-s-line\"\n :aria-label=\"$t('chatFilePreview.nextVersion')\"\n :disabled=\"!next\"\n @click=\"next && emit('version', next)\" />\n </nav>\n <PkEditorRadioButtons\n v-if=\"hasRevisions\"\n v-model=\"mode\"\n name=\"revisions\"\n segmented\n class=\"pk-file-preview__modes u-segmented-fit mb-0\"\n :aria-label=\"$t('chatFilePreview.modes')\"\n :options=\"modes\">\n <!-- The short name where the long one leaves the\n versions no room on the line -->\n <template #markup>\n <span class=\"pk-file-preview__mode-long\">\n {{ $t('chatFilePreview.modeMarkup') }}\n </span>\n <span class=\"pk-file-preview__mode-short\">\n {{ $t('chatFilePreview.modeMarkupShort') }}\n </span>\n </template>\n </PkEditorRadioButtons>\n </div>\n <div class=\"pk-file-preview__actions\">\n <VvButton\n v-if=\"restorable\"\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :label=\"$t('chatFilePreview.restore')\"\n @click=\"emit('restore')\" />\n <VvButton\n :href=\"downloadUrl\"\n download\n modifiers=\"action-quiet\"\n icon=\"ri:download-line\"\n :title=\"$t('chatFilePreview.download')\"\n :aria-label=\"$t('chatFilePreview.download')\" />\n <VvButton\n v-if=\"resize === 'expand'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-line\"\n :title=\"$t('chatFilePreview.expand')\"\n :aria-label=\"$t('chatFilePreview.expand')\"\n @click=\"emit('resize')\" />\n <VvButton\n v-else-if=\"resize === 'shrink'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-exit-line\"\n :title=\"$t('chatFilePreview.shrink')\"\n :aria-label=\"$t('chatFilePreview.shrink')\"\n @click=\"emit('resize')\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:close-line\"\n :title=\"$t('chatFilePreview.close')\"\n :aria-label=\"$t('chatFilePreview.close')\"\n @click=\"emit('close')\" />\n </div>\n </header>\n <div class=\"pk-file-preview__body\">\n <div v-if=\"loading\" class=\"pk-file-preview__skeleton vv-skeleton\">\n <div\n v-for=\"i in 8\"\n :key=\"i\"\n class=\"vv-skeleton__item pk-file-preview__skeleton-line\"\n :class=\"i % 3 ? 'w-full' : 'w-128'\" />\n </div>\n <p v-else-if=\"error || !preview\" class=\"pk-file-preview__empty\">\n {{ $t('chatFilePreview.unavailable') }}\n </p>\n <PkWordPreview\n v-else-if=\"preview.kind === 'word'\"\n v-model:zoom=\"zoom\"\n v-model:fit=\"fit\"\n :preview\n :mode=\"hasRevisions ? mode : 'markup'\" />\n <PkSpreadsheetPreview\n v-else\n v-model:sheet=\"sheet\"\n v-model:zoom=\"zoom\"\n :preview />\n </div>\n </section>\n</template>\n\n<style lang=\"scss\">\n .pk-file-preview {\n container-type: inline-size;\n display: flex;\n flex-direction: column;\n min-height: 0;\n height: 100%;\n outline: none;\n background-color: var(--color-surface);\n color: var(--color-word-1);\n\n &__head {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n padding: var(--spacing-12) var(--spacing-12) var(--spacing-12)\n var(--spacing-md);\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__file {\n display: flex;\n flex: 1 1 12rem;\n align-items: center;\n gap: var(--spacing-12);\n min-width: 0;\n }\n\n &__tile {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-32);\n height: var(--spacing-32);\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n\n .vv-icon {\n width: var(--spacing-18);\n height: var(--spacing-18);\n }\n }\n\n // The colors the file chip of the chat gives the two kinds\n &__icon--word {\n color: #2b7de9;\n }\n\n &__icon--sheet {\n color: #1f9d57;\n }\n\n &__name {\n display: flex;\n flex-direction: column;\n min-width: 0;\n }\n\n &__title {\n overflow: hidden;\n font-size: var(--text-14);\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n &__note {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n &__tools {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n }\n\n &__versions {\n display: flex;\n align-items: center;\n gap: var(--spacing-2);\n }\n\n &__version {\n font-size: var(--text-14);\n font-weight: var(--font-semibold);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__actions {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n margin-left: auto;\n }\n\n // In a narrow frame the file and its actions keep the first line,\n // the versions and the revisions take the second.\n @container (width < 52rem) {\n &__file {\n order: 1;\n }\n\n &__actions {\n order: 2;\n }\n\n &__tools {\n order: 3;\n flex-basis: 100%;\n }\n\n // The ways to show the revisions fill what the versions leave,\n // or go to a line of their own: never narrower than their words\n &__tools &__modes {\n flex: 1 1 auto;\n }\n }\n\n &__mode-short {\n display: none;\n }\n\n // Below this the long name puts the modes on a line of their own\n @container (width < 38rem) {\n &__mode-long {\n display: none;\n }\n\n &__mode-short {\n display: inline;\n }\n }\n\n // A phone gives them a line of their own, with less padding\n @container (width < 30rem) {\n &__tools &__modes {\n flex: 1 1 100%;\n\n .vv-radio {\n padding-inline: var(--spacing-4);\n }\n }\n }\n\n // The document scrolls inside its viewer, so the head stays in view\n &__body {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n background-color: var(--color-surface-1);\n }\n\n &__skeleton {\n width: min(42rem, calc(100% - 2 * var(--spacing-md)));\n margin: var(--spacing-md) auto;\n padding: var(--spacing-lg);\n box-sizing: border-box;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n background-color: var(--color-surface);\n }\n\n &__skeleton-line {\n height: var(--spacing-12);\n margin-bottom: var(--spacing-12);\n border-radius: var(--rounded);\n }\n\n &__empty {\n margin: var(--spacing-lg) var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-14);\n text-align: center;\n }\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, watch } from 'vue'\n import { useI18n } from 'vue-i18n'\n import type { ChatFilePreview } from 'models'\n import PkEditorRadioButtons from '../PkEditorRadioButtons.vue'\n import PkSpreadsheetPreview from './PkSpreadsheetPreview.vue'\n import PkWordPreview from './PkWordPreview.vue'\n import type { WordPreviewMode } from './utils'\n\n /**\n * The viewer of a Word document or a spreadsheet stored in the chat (spec\n * `chat-office-files.md`, F6, items 3 and 4, and their follow-ups): a head\n * with the file, its versions in the conversation, how to show the\n * revisions of a Word document, restore, download, a larger frame and\n * close, over the document drawn as Word or Excel draws it. The same\n * viewer goes in the panel beside the chat and in a dialog over it.\n */\n const props = defineProps<{\n kind: 'word' | 'spreadsheet'\n /** The name of the file, not of its version. */\n filename: string\n version?: number\n /** The versions of the file in the conversation, from 1. */\n versions?: number[]\n /** The authenticated download URL of the shown version. */\n downloadUrl: string\n preview?: ChatFilePreview\n loading?: boolean\n error?: boolean\n /** The shown version can be written again as the newest one. */\n restorable?: boolean\n /** Offers to move to the larger frame, or back to the panel. */\n resize?: 'expand' | 'shrink'\n }>()\n\n const emit = defineEmits<{\n close: []\n version: [version: number]\n restore: []\n resize: []\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const versions = computed(() => props.versions ?? [])\n const position = computed(() =>\n props.version ? versions.value.indexOf(props.version) : -1,\n )\n const previous = computed(() =>\n position.value > 0 ? versions.value[position.value - 1] : undefined,\n )\n const next = computed(() =>\n position.value >= 0 && position.value < versions.value.length - 1\n ? versions.value[position.value + 1]\n : undefined,\n )\n\n /**\n * How a Word document with tracked changes is drawn, and the sheet and\n * the zoom: models, so they stay when the viewer moves between the panel\n * and the dialog, where it is drawn anew.\n */\n const mode = defineModel<WordPreviewMode>('mode', { default: 'markup' })\n const sheet = defineModel<number>('sheet', { default: 0 })\n const zoom = defineModel<number>('zoom', { default: 1 })\n const fit = defineModel<boolean>('fit', { default: true })\n const modes = computed(() => [\n { value: 'markup', label: $t('chatFilePreview.modeMarkup') },\n { value: 'accepted', label: $t('chatFilePreview.modeAccepted') },\n { value: 'original', label: $t('chatFilePreview.modeOriginal') },\n ])\n const hasRevisions = computed(\n () =>\n props.preview?.kind === 'word' &&\n props.preview.revisionAuthors.length > 0,\n )\n // Another version starts with its revisions in sight.\n watch(\n () => props.version,\n () => {\n mode.value = 'markup'\n },\n )\n</script>\n\n<template>\n <!-- A dialog gives the focus to its first control, the arrow of the\n versions: it goes to the viewer, and the keyboard starts from here -->\n <section\n class=\"pk-file-preview\"\n :aria-label=\"filename\"\n tabindex=\"-1\"\n autofocus>\n <header class=\"pk-file-preview__head\">\n <div class=\"pk-file-preview__file\">\n <span class=\"pk-file-preview__tile\" aria-hidden=\"true\">\n <VvIcon\n :name=\"\n kind === 'word'\n ? 'ri:file-word-2-line'\n : 'ri:file-excel-2-line'\n \"\n :class=\"\n kind === 'word'\n ? 'pk-file-preview__icon--word'\n : 'pk-file-preview__icon--sheet'\n \" />\n </span>\n <div class=\"pk-file-preview__name\">\n <strong class=\"pk-file-preview__title\">\n {{ filename }}\n </strong>\n <span class=\"pk-file-preview__note\">\n {{ $t('chatFilePreview.readOnly') }}\n </span>\n </div>\n </div>\n <div\n v-if=\"(version && versions.length > 1) || hasRevisions\"\n class=\"pk-file-preview__tools\">\n <nav\n v-if=\"version && versions.length > 1\"\n class=\"pk-file-preview__versions\"\n :aria-label=\"$t('chatFilePreview.versions')\">\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-left-s-line\"\n :aria-label=\"$t('chatFilePreview.previousVersion')\"\n :disabled=\"!previous\"\n @click=\"previous && emit('version', previous)\" />\n <span class=\"pk-file-preview__version\">\n {{\n $t('chatFilePreview.versionOf', {\n version,\n count: versions.length,\n })\n }}\n </span>\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-right-s-line\"\n :aria-label=\"$t('chatFilePreview.nextVersion')\"\n :disabled=\"!next\"\n @click=\"next && emit('version', next)\" />\n </nav>\n <PkEditorRadioButtons\n v-if=\"hasRevisions\"\n v-model=\"mode\"\n name=\"revisions\"\n segmented\n class=\"pk-file-preview__modes u-segmented-fit mb-0\"\n :aria-label=\"$t('chatFilePreview.modes')\"\n :options=\"modes\">\n <!-- The short name where the long one leaves the\n versions no room on the line -->\n <template #markup>\n <span class=\"pk-file-preview__mode-long\">\n {{ $t('chatFilePreview.modeMarkup') }}\n </span>\n <span class=\"pk-file-preview__mode-short\">\n {{ $t('chatFilePreview.modeMarkupShort') }}\n </span>\n </template>\n </PkEditorRadioButtons>\n </div>\n <div class=\"pk-file-preview__actions\">\n <VvButton\n v-if=\"restorable\"\n modifiers=\"action-quiet\"\n icon=\"ri:arrow-go-back-line\"\n :label=\"$t('chatFilePreview.restore')\"\n @click=\"emit('restore')\" />\n <VvButton\n :href=\"downloadUrl\"\n download\n modifiers=\"action-quiet\"\n icon=\"ri:download-line\"\n :title=\"$t('chatFilePreview.download')\"\n :aria-label=\"$t('chatFilePreview.download')\" />\n <VvButton\n v-if=\"resize === 'expand'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-line\"\n :title=\"$t('chatFilePreview.expand')\"\n :aria-label=\"$t('chatFilePreview.expand')\"\n @click=\"emit('resize')\" />\n <VvButton\n v-else-if=\"resize === 'shrink'\"\n modifiers=\"action-quiet\"\n icon=\"ri:fullscreen-exit-line\"\n :title=\"$t('chatFilePreview.shrink')\"\n :aria-label=\"$t('chatFilePreview.shrink')\"\n @click=\"emit('resize')\" />\n <VvButton\n modifiers=\"action-quiet\"\n icon=\"ri:close-line\"\n :title=\"$t('chatFilePreview.close')\"\n :aria-label=\"$t('chatFilePreview.close')\"\n @click=\"emit('close')\" />\n </div>\n </header>\n <div class=\"pk-file-preview__body\">\n <div v-if=\"loading\" class=\"pk-file-preview__skeleton vv-skeleton\">\n <div\n v-for=\"i in 8\"\n :key=\"i\"\n class=\"vv-skeleton__item pk-file-preview__skeleton-line\"\n :class=\"i % 3 ? 'w-full' : 'w-128'\" />\n </div>\n <p v-else-if=\"error || !preview\" class=\"pk-file-preview__empty\">\n {{ $t('chatFilePreview.unavailable') }}\n </p>\n <PkWordPreview\n v-else-if=\"preview.kind === 'word'\"\n v-model:zoom=\"zoom\"\n v-model:fit=\"fit\"\n :preview\n :mode=\"hasRevisions ? mode : 'markup'\" />\n <PkSpreadsheetPreview\n v-else\n v-model:sheet=\"sheet\"\n v-model:zoom=\"zoom\"\n :preview />\n </div>\n </section>\n</template>\n\n<style lang=\"scss\">\n .pk-file-preview {\n container-type: inline-size;\n display: flex;\n flex-direction: column;\n min-height: 0;\n height: 100%;\n outline: none;\n background-color: var(--color-surface);\n color: var(--color-word-1);\n\n &__head {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n padding: var(--spacing-12) var(--spacing-12) var(--spacing-12)\n var(--spacing-md);\n border-bottom: var(--border) solid var(--color-surface-3);\n }\n\n &__file {\n display: flex;\n flex: 1 1 12rem;\n align-items: center;\n gap: var(--spacing-12);\n min-width: 0;\n }\n\n &__tile {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n width: var(--spacing-32);\n height: var(--spacing-32);\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n\n .vv-icon {\n width: var(--spacing-18);\n height: var(--spacing-18);\n }\n }\n\n // The colors the file chip of the chat gives the two kinds\n &__icon--word {\n color: #2b7de9;\n }\n\n &__icon--sheet {\n color: #1f9d57;\n }\n\n &__name {\n display: flex;\n flex-direction: column;\n min-width: 0;\n }\n\n &__title {\n overflow: hidden;\n font-size: var(--text-14);\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n &__note {\n color: var(--color-word-3);\n font-size: var(--text-12);\n }\n\n &__tools {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--spacing-8) var(--spacing-12);\n }\n\n &__versions {\n display: flex;\n align-items: center;\n gap: var(--spacing-2);\n }\n\n &__version {\n font-size: var(--text-14);\n font-weight: var(--font-semibold);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n &__actions {\n display: flex;\n align-items: center;\n gap: var(--spacing-8);\n margin-left: auto;\n }\n\n // In a narrow frame the file and its actions keep the first line,\n // the versions and the revisions take the second.\n @container (width < 52rem) {\n &__file {\n order: 1;\n }\n\n &__actions {\n order: 2;\n }\n\n &__tools {\n order: 3;\n flex-basis: 100%;\n }\n\n // The ways to show the revisions fill what the versions leave,\n // or go to a line of their own: never narrower than their words\n &__tools &__modes {\n flex: 1 1 auto;\n }\n }\n\n &__mode-short {\n display: none;\n }\n\n // Below this the long name puts the modes on a line of their own\n @container (width < 38rem) {\n &__mode-long {\n display: none;\n }\n\n &__mode-short {\n display: inline;\n }\n }\n\n // A phone gives them a line of their own, with less padding\n @container (width < 30rem) {\n &__tools &__modes {\n flex: 1 1 100%;\n\n .vv-radio {\n padding-inline: var(--spacing-4);\n }\n }\n }\n\n // The document scrolls inside its viewer, so the head stays in view\n &__body {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n background-color: var(--color-surface-1);\n }\n\n &__skeleton {\n width: min(42rem, calc(100% - 2 * var(--spacing-md)));\n margin: var(--spacing-md) auto;\n padding: var(--spacing-lg);\n box-sizing: border-box;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded);\n background-color: var(--color-surface);\n }\n\n &__skeleton-line {\n height: var(--spacing-12);\n margin-bottom: var(--spacing-12);\n border-radius: var(--rounded);\n }\n\n &__empty {\n margin: var(--spacing-lg) var(--spacing-md);\n color: var(--color-word-3);\n font-size: var(--text-14);\n text-align: center;\n }\n }\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;A,qHA2BU4K,IAAe,IACfC,IAAa,IACbC,IAAc,IACdC,IAAiB,I;;;;;;;;;;EARvB,IAAMM,IAAQC,GAER,EAAE,GAAGC,GAAI,cAAWrC,EAAQ,EAAE,UAAU,SAAS,CAAC,GAUlDsC,IAAStK,EAAmBoK,GAAC,OAAuB,GACpDG,IAAOvK,EAAmBoK,GAAC,MAAsB,GACjDI,IAAW1D,EAA+B,UAAU,GAIpD,EAAE,OAAO2D,GAAW,QAAQC,MAAevC,GAC7CqC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