@codingame/monaco-vscode-api 37.1.0 → 37.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/missing-services.js +6 -26
  2. package/package.json +8 -8
  3. package/services.d.ts +1 -1
  4. package/services.js +3 -3
  5. package/tools.d.ts +4 -0
  6. package/tools.js +24 -1
  7. package/vscode/src/vs/platform/product/common/product.js +1 -1
  8. package/vscode/src/vs/platform/webWorker/browser/webWorkerServiceImpl.js +2 -2
  9. package/vscode/src/vs/workbench/api/browser/mainThreadDocuments.d.ts +63 -0
  10. package/vscode/src/vs/workbench/api/browser/mainThreadDocuments.js +305 -0
  11. package/vscode/src/vs/workbench/api/common/extHost.protocol.d.ts +2 -2
  12. package/vscode/src/vs/workbench/api/common/extHostLanguageModelTools.js +1 -2
  13. package/vscode/src/vs/workbench/api/common/extHostTypeConverters.js +1 -1
  14. package/vscode/src/vs/workbench/browser/media/code-icon.svg +1 -0
  15. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatConstants.d.ts +1 -0
  16. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatConstants.js +2 -1
  17. package/vscode/src/vs/workbench/contrib/chat/browser/agentPluginActions.d.ts +2 -2
  18. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostActiveClientService.service.d.ts +1 -1
  19. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsBanner.d.ts +30 -0
  20. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsBanner.js +39 -0
  21. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsService.service.d.ts +1 -1
  22. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/experiments/agentSessionProjectionService.service.d.ts +1 -1
  23. package/vscode/src/vs/workbench/contrib/chat/browser/chat.d.ts +1 -1
  24. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatInputNotificationService.service.d.ts +1 -1
  25. package/vscode/src/vs/workbench/contrib/chat/common/attachments/chatVariableEntries.d.ts +1 -1
  26. package/vscode/src/vs/workbench/contrib/chat/common/attachments/chatVariables.service.d.ts +1 -1
  27. package/vscode/src/vs/workbench/contrib/chat/common/chatDebugService.service.d.ts +1 -1
  28. package/vscode/src/vs/workbench/contrib/chat/common/chatImageBuffer.d.ts +1 -0
  29. package/vscode/src/vs/workbench/contrib/chat/common/chatImageBuffer.js +29 -0
  30. package/vscode/src/vs/workbench/contrib/chat/common/chatService/chatService.d.ts +2 -2
  31. package/vscode/src/vs/workbench/contrib/chat/common/customizationHarnessService.service.d.ts +1 -1
  32. package/vscode/src/vs/workbench/contrib/chat/common/plugins/agentPluginRepositoryService.d.ts +1 -1
  33. package/vscode/src/vs/workbench/contrib/chat/common/plugins/agentPluginRepositoryService.service.d.ts +2 -2
  34. package/vscode/src/vs/workbench/contrib/chat/common/plugins/agentPluginService.service.d.ts +1 -1
  35. package/vscode/src/vs/workbench/contrib/chat/common/plugins/pluginInstallService.d.ts +1 -1
  36. package/vscode/src/vs/workbench/contrib/chat/common/plugins/pluginInstallService.service.d.ts +1 -1
  37. package/vscode/src/vs/workbench/contrib/chat/common/plugins/pluginMarketplaceService.service.d.ts +2 -2
  38. package/vscode/src/vs/workbench/contrib/chat/common/plugins/pluginSource.d.ts +1 -1
  39. package/vscode/src/vs/workbench/contrib/chat/common/requestParser/chatParserTypes.d.ts +1 -1
  40. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/toolIds.d.ts +3 -0
  41. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/toolIds.js +7 -0
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookBrowser.d.ts +3 -3
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorService.service.d.ts +1 -1
  44. package/vscode/src/vs/workbench/contrib/notebook/common/notebookCommon.d.ts +1 -1
  45. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorInput.d.ts +1 -1
  46. package/vscode/src/vs/workbench/contrib/notebook/common/notebookExecutionService.d.ts +1 -1
  47. package/vscode/src/vs/workbench/contrib/notebook/common/notebookExecutionService.service.d.ts +1 -1
  48. package/vscode/src/vs/workbench/contrib/notebook/common/notebookExecutionStateService.service.d.ts +1 -1
  49. package/vscode/src/vs/workbench/contrib/notebook/common/notebookService.service.d.ts +1 -1
  50. package/vscode/src/vs/workbench/contrib/search/browser/AISearch/aiSearchModel.d.ts +1 -1
  51. package/vscode/src/vs/workbench/contrib/search/browser/notebookSearch/notebookSearchModel.d.ts +1 -1
  52. package/vscode/src/vs/workbench/contrib/search/browser/notebookSearch/notebookSearchModelBase.d.ts +1 -1
  53. package/vscode/src/vs/workbench/contrib/search/browser/searchTreeModel/folderMatch.d.ts +1 -1
  54. package/vscode/src/vs/workbench/contrib/search/browser/searchTreeModel/searchTreeCommon.d.ts +1 -1
  55. package/vscode/src/vs/workbench/contrib/search/browser/searchView.js +4 -3
  56. package/vscode/src/vs/workbench/contrib/welcomeAgentSessions/browser/agentSessionsWelcomeInput.d.ts +34 -0
  57. package/vscode/src/vs/workbench/contrib/welcomeAgentSessions/browser/agentSessionsWelcomeInput.js +72 -0
  58. package/vscode/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput.d.ts +44 -0
  59. package/vscode/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput.js +96 -0
  60. package/vscode/src/vs/workbench/contrib/welcomeGettingStarted/browser/media/gettingStarted.css +1148 -0
  61. package/vscode/src/vs/workbench/contrib/welcomeOnboarding/common/onboardingTypes.d.ts +81 -0
  62. package/vscode/src/vs/workbench/contrib/welcomeOnboarding/common/onboardingTypes.js +97 -0
  63. package/vscode/src/vs/workbench/services/extensions/common/extHostCustomers.d.ts +32 -0
  64. package/vscode/src/vs/workbench/services/extensions/common/extHostCustomers.js +45 -0
  65. package/vscode/src/vs/platform/agentHost/common/agentHostEnablementService.d.ts +0 -7
  66. package/vscode/src/vs/platform/agentHost/common/agentHostEnablementService.js +0 -92
  67. package/vscode/src/vs/platform/layout/browser/zIndexRegistry.d.ts +0 -12
  68. package/vscode/src/vs/platform/layout/browser/zIndexRegistry.js +0 -64
  69. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.d.ts +0 -262
  70. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js +0 -865
  71. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/chatDynamicVariables.d.ts +0 -57
  72. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/chatDynamicVariables.js +0 -311
  73. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/chatVariables.d.ts +0 -15
  74. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/chatVariables.js +0 -80
  75. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessionDescription.d.ts +0 -2
  76. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessionDescription.js +0 -57
  77. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.d.ts +0 -231
  78. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.js +0 -1850
  79. package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup/chatSetup.d.ts +0 -109
  80. package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup/chatSetup.js +0 -85
  81. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatInputNotificationService.d.ts +0 -140
  82. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatInputNotificationService.js +0 -186
  83. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/editor/chatDynamicVariablesConstant.d.ts +0 -1
  84. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/editor/chatDynamicVariablesConstant.js +0 -5
  85. package/vscode/src/vs/workbench/contrib/chat/common/attachments/chatVariables.d.ts +0 -46
  86. package/vscode/src/vs/workbench/contrib/chat/common/attachments/chatVariables.js +0 -17
  87. package/vscode/src/vs/workbench/contrib/chat/common/chatDebugService.d.ts +0 -253
  88. package/vscode/src/vs/workbench/contrib/chat/common/chatDebugService.js +0 -20
  89. package/vscode/src/vs/workbench/contrib/chat/common/chatImageExtraction.d.ts +0 -34
  90. package/vscode/src/vs/workbench/contrib/chat/common/chatImageExtraction.js +0 -194
  91. package/vscode/src/vs/workbench/contrib/chat/common/chatSelectedModel.d.ts +0 -87
  92. package/vscode/src/vs/workbench/contrib/chat/common/chatSelectedModel.js +0 -69
  93. package/vscode/src/vs/workbench/contrib/chat/common/customizationHarnessService.d.ts +0 -300
  94. package/vscode/src/vs/workbench/contrib/chat/common/customizationHarnessService.js +0 -272
  95. package/vscode/src/vs/workbench/contrib/chat/common/plugins/agentPluginEnablement.d.ts +0 -25
  96. package/vscode/src/vs/workbench/contrib/chat/common/plugins/agentPluginEnablement.js +0 -178
  97. package/vscode/src/vs/workbench/contrib/chat/common/plugins/agentPluginService.d.ts +0 -78
  98. package/vscode/src/vs/workbench/contrib/chat/common/plugins/agentPluginService.js +0 -51
  99. package/vscode/src/vs/workbench/contrib/chat/common/plugins/fileBackedInstalledPluginsStore.d.ts +0 -67
  100. package/vscode/src/vs/workbench/contrib/chat/common/plugins/fileBackedInstalledPluginsStore.js +0 -195
  101. package/vscode/src/vs/workbench/contrib/chat/common/plugins/marketplaceReference.d.ts +0 -67
  102. package/vscode/src/vs/workbench/contrib/chat/common/plugins/marketplaceReference.js +0 -294
  103. package/vscode/src/vs/workbench/contrib/chat/common/plugins/pluginMarketplaceService.d.ts +0 -212
  104. package/vscode/src/vs/workbench/contrib/chat/common/plugins/pluginMarketplaceService.js +0 -955
  105. package/vscode/src/vs/workbench/contrib/chat/common/plugins/strictKnownMarketplaces.d.ts +0 -31
  106. package/vscode/src/vs/workbench/contrib/chat/common/plugins/strictKnownMarketplaces.js +0 -122
  107. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/computeAutomaticInstructions.d.ts +0 -65
  108. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/computeAutomaticInstructions.js +0 -697
  109. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/config/config.d.ts +0 -150
  110. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/config/config.js +0 -142
  111. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/hookClaudeCompat.d.ts +0 -50
  112. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/hookClaudeCompat.js +0 -77
  113. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/hookCompatibility.d.ts +0 -77
  114. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/hookCompatibility.js +0 -120
  115. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/hookCopilotCliCompat.d.ts +0 -10
  116. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/hookCopilotCliCompat.js +0 -23
  117. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/extensionPromptFileService.d.ts +0 -92
  118. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/extensionPromptFileService.js +0 -335
  119. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.d.ts +0 -235
  120. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.js +0 -1673
  121. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.d.ts +0 -202
  122. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.js +0 -872
  123. package/vscode/src/vs/workbench/contrib/chat/common/requestParser/chatRequestParser.d.ts +0 -35
  124. package/vscode/src/vs/workbench/contrib/chat/common/requestParser/chatRequestParser.js +0 -289
  125. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/askQuestionsTool.d.ts +0 -72
  126. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/askQuestionsTool.js +0 -600
  127. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/confirmationTool.d.ts +0 -36
  128. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/confirmationTool.js +0 -239
  129. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/editFileTool.d.ts +0 -22
  130. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/editFileTool.js +0 -143
  131. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/manageTodoListTool.d.ts +0 -24
  132. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/manageTodoListTool.js +0 -298
  133. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/reviewPlanTool.d.ts +0 -25
  134. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/reviewPlanTool.js +0 -177
  135. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/runSubagentTool.d.ts +0 -73
  136. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/runSubagentTool.js +0 -577
  137. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/setArtifactRulesTool.d.ts +0 -11
  138. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/setArtifactRulesTool.js +0 -90
  139. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/setArtifactsTool.d.ts +0 -16
  140. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/setArtifactsTool.js +0 -130
  141. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/taskCompleteTool.d.ts +0 -12
  142. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/taskCompleteTool.js +0 -53
  143. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/toolHelpers.d.ts +0 -5
  144. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/toolHelpers.js +0 -12
  145. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/tools.d.ts +0 -10
  146. package/vscode/src/vs/workbench/contrib/chat/common/tools/builtinTools/tools.js +0 -92
  147. package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.d.ts +0 -38
  148. package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.js +0 -518
  149. package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsParametersSchema.d.ts +0 -6
  150. package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsParametersSchema.js +0 -231
  151. package/vscode/src/vs/workbench/contrib/chat/common/tools/terminalToolIds.d.ts +0 -20
  152. package/vscode/src/vs/workbench/contrib/chat/common/tools/terminalToolIds.js +0 -17
  153. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOutputActions.d.ts +0 -6
  154. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOutputActions.js +0 -283
  155. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/coreActions.d.ts +0 -91
  156. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/coreActions.js +0 -340
  157. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/foldingController.d.ts +0 -17
  158. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/foldingController.js +0 -272
  159. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebook.css +0 -686
  160. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookCellChat.css +0 -348
  161. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookCellEditorHint.css +0 -8
  162. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookCellInsertToolbar.css +0 -92
  163. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookCellOutput.css +0 -119
  164. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookCellStatusBar.css +0 -79
  165. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookCellTitleToolbar.css +0 -61
  166. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookChatEditController.css +0 -55
  167. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookChatEditorOverlay.css +0 -63
  168. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookDnd.css +0 -79
  169. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookEditorStickyScroll.css +0 -63
  170. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookFocusIndicator.css +0 -92
  171. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookFolding.css +0 -79
  172. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookKernelActionViewItem.css +0 -24
  173. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookOutline.css +0 -61
  174. package/vscode/src/vs/workbench/contrib/notebook/browser/media/notebookToolbar.css +0 -102
  175. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibilityProvider.d.ts +0 -27
  176. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibilityProvider.js +0 -131
  177. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookCellLayoutManager.d.ts +0 -18
  178. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookCellLayoutManager.js +0 -92
  179. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookEditor.d.ts +0 -105
  180. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookEditor.js +0 -673
  181. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookEditorExtensions.d.ts +0 -9
  182. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookEditorExtensions.js +0 -37
  183. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.d.ts +0 -354
  184. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.js +0 -2926
  185. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookIcons.d.ts +0 -29
  186. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookIcons.js +0 -36
  187. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookLogger.d.ts +0 -1
  188. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookLogger.js +0 -19
  189. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookOptions.d.ts +0 -200
  190. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookOptions.js +0 -591
  191. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookViewEvents.d.ts +0 -56
  192. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookViewEvents.js +0 -30
  193. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellPart.d.ts +0 -99
  194. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellPart.js +0 -131
  195. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellActionView.d.ts +0 -30
  196. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellActionView.js +0 -115
  197. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.d.ts +0 -28
  198. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.js +0 -158
  199. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys.d.ts +0 -40
  200. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys.js +0 -183
  201. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDecorations.d.ts +0 -10
  202. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDecorations.js +0 -66
  203. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDnd.d.ts +0 -52
  204. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDnd.js +0 -429
  205. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDragRenderer.d.ts +0 -6
  206. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDragRenderer.js +0 -108
  207. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellEditorOptions.d.ts +0 -36
  208. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellEditorOptions.js +0 -221
  209. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellExecution.d.ts +0 -17
  210. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellExecution.js +0 -142
  211. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellFocus.d.ts +0 -5
  212. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellFocus.js +0 -23
  213. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellFocusIndicator.d.ts +0 -18
  214. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellFocusIndicator.js +0 -104
  215. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellOutput.d.ts +0 -92
  216. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellOutput.js +0 -762
  217. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellProgressBar.d.ts +0 -15
  218. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellProgressBar.js +0 -58
  219. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellStatusPart.d.ts +0 -36
  220. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellStatusPart.js +0 -357
  221. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbarStickyScroll.d.ts +0 -6
  222. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbarStickyScroll.js +0 -32
  223. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.d.ts +0 -47
  224. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.js +0 -260
  225. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellWidgets.d.ts +0 -9
  226. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellWidgets.js +0 -10
  227. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/chat/cellChatPart.d.ts +0 -10
  228. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/chat/cellChatPart.js +0 -24
  229. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.d.ts +0 -182
  230. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.js +0 -796
  231. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCellExecutionIcon.d.ts +0 -13
  232. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCellExecutionIcon.js +0 -79
  233. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCellRunToolbar.d.ts +0 -30
  234. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCellRunToolbar.js +0 -126
  235. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/collapsedCellInput.d.ts +0 -6
  236. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/collapsedCellInput.js +0 -32
  237. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/collapsedCellOutput.d.ts +0 -8
  238. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/collapsedCellOutput.js +0 -50
  239. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/foldedCellHint.d.ts +0 -18
  240. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/foldedCellHint.js +0 -119
  241. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/markupCell.d.ts +0 -57
  242. package/vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/markupCell.js +0 -443
  243. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellAnchor.d.ts +0 -20
  244. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellAnchor.js +0 -56
  245. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellEditorPool.d.ts +0 -24
  246. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellEditorPool.js +0 -121
  247. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.d.ts +0 -152
  248. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.js +0 -1288
  249. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellListView.d.ts +0 -59
  250. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookCellListView.js +0 -287
  251. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon.d.ts +0 -117
  252. package/vscode/src/vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon.js +0 -6
  253. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.d.ts +0 -222
  254. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.js +0 -1840
  255. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.d.ts +0 -63
  256. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.js +0 -449
  257. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewMessages.d.ts +0 -432
  258. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.d.ts +0 -18
  259. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.js +0 -2546
  260. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewThemeMapping.d.ts +0 -8
  261. package/vscode/src/vs/workbench/contrib/notebook/browser/view/renderers/webviewThemeMapping.js +0 -105
  262. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.d.ts +0 -137
  263. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.js +0 -646
  264. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions.d.ts +0 -21
  265. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions.js +0 -101
  266. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellOutputTextHelper.d.ts +0 -13
  267. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellOutputTextHelper.js +0 -111
  268. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellOutputViewModel.d.ts +0 -30
  269. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellOutputViewModel.js +0 -65
  270. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellSelectionCollection.d.ts +0 -13
  271. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/cellSelectionCollection.js +0 -49
  272. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.d.ts +0 -89
  273. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.js +0 -472
  274. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher.d.ts +0 -11
  275. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher.js +0 -34
  276. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/foldingModel.d.ts +0 -33
  277. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/foldingModel.js +0 -275
  278. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel.d.ts +0 -69
  279. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel.js +0 -269
  280. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.d.ts +0 -125
  281. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.js +0 -958
  282. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/viewContext.d.ts +0 -9
  283. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/viewContext.js +0 -11
  284. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookCellOverlays.d.ts +0 -20
  285. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookCellOverlays.js +0 -101
  286. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorStickyScroll.d.ts +0 -65
  287. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorStickyScroll.js +0 -458
  288. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorToolbar.d.ts +0 -80
  289. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorToolbar.js +0 -708
  290. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.d.ts +0 -37
  291. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.js +0 -193
  292. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookHorizontalTracker.d.ts +0 -7
  293. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookHorizontalTracker.js +0 -62
  294. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookKernelQuickPickStrategy.d.ts +0 -108
  295. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookKernelQuickPickStrategy.js +0 -717
  296. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookKernelView.d.ts +0 -23
  297. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookKernelView.js +0 -183
  298. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookOverviewRuler.d.ts +0 -11
  299. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookOverviewRuler.js +0 -134
  300. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookTopCellToolbar.d.ts +0 -20
  301. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookTopCellToolbar.js +0 -135
  302. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookViewZones.d.ts +0 -27
  303. package/vscode/src/vs/workbench/contrib/notebook/browser/viewParts/notebookViewZones.js +0 -213
  304. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookCellOutputTextModel.d.ts +0 -27
  305. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookCellOutputTextModel.js +0 -104
  306. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.d.ts +0 -115
  307. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.js +0 -480
  308. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModel.d.ts +0 -87
  309. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModel.js +0 -352
  310. package/vscode/src/vs/workbench/contrib/notebook/common/notebookExecutionStateService.d.ts +0 -81
  311. package/vscode/src/vs/workbench/contrib/notebook/common/notebookExecutionStateService.js +0 -9
  312. package/vscode/src/vs/workbench/contrib/notebook/common/notebookPerformance.d.ts +0 -10
  313. package/vscode/src/vs/workbench/contrib/notebook/common/notebookPerformance.js +0 -19
@@ -1,2546 +0,0 @@
1
-
2
-
3
- async function webviewPreloads(ctx) {
4
- const userAgent = navigator.userAgent;
5
- const isChrome = (userAgent.indexOf("Chrome") >= 0);
6
- const textEncoder = ( new TextEncoder());
7
- const textDecoder = ( new TextDecoder());
8
- function promiseWithResolvers() {
9
- let resolve;
10
- let reject;
11
- const promise = ( new Promise((res, rej) => {
12
- resolve = res;
13
- reject = rej;
14
- }));
15
- return {
16
- promise,
17
- resolve: resolve,
18
- reject: reject
19
- };
20
- }
21
- let currentOptions = ctx.options;
22
- const isWorkspaceTrusted = ctx.isWorkspaceTrusted;
23
- let currentRenderOptions = ctx.renderOptions;
24
- const settingChange = createEmitter();
25
- const acquireVsCodeApi = globalThis.acquireVsCodeApi;
26
- const vscode = acquireVsCodeApi();
27
- delete globalThis.acquireVsCodeApi;
28
- const tokenizationStyle = ( new CSSStyleSheet());
29
- tokenizationStyle.replaceSync(ctx.style.tokenizationCss);
30
- const runWhenIdle = (typeof requestIdleCallback !== "function" || typeof cancelIdleCallback !== "function") ? runner => {
31
- setTimeout(() => {
32
- if (disposed) {
33
- return;
34
- }
35
- const end = Date.now() + 15;
36
- runner(( Object.freeze({
37
- didTimeout: true,
38
- timeRemaining() {
39
- return Math.max(0, end - Date.now());
40
- }
41
- })));
42
- });
43
- let disposed = false;
44
- return {
45
- dispose() {
46
- if (disposed) {
47
- return;
48
- }
49
- disposed = true;
50
- }
51
- };
52
- } : (runner, timeout) => {
53
- const handle = requestIdleCallback(runner, typeof timeout === "number" ? {
54
- timeout
55
- } : undefined);
56
- let disposed = false;
57
- return {
58
- dispose() {
59
- if (disposed) {
60
- return;
61
- }
62
- disposed = true;
63
- cancelIdleCallback(handle);
64
- }
65
- };
66
- };
67
- function getOutputContainer(event) {
68
- for (const node of event.composedPath()) {
69
- if (node instanceof HTMLElement && node.classList.contains("output")) {
70
- return {
71
- id: node.id
72
- };
73
- }
74
- }
75
- return;
76
- }
77
- let lastFocusedOutput = undefined;
78
- const handleOutputFocusOut = event => {
79
- const outputFocus = event && getOutputContainer(event);
80
- if (!outputFocus) {
81
- return;
82
- }
83
- lastFocusedOutput = undefined;
84
- setTimeout(() => {
85
- if (lastFocusedOutput?.id === outputFocus.id) {
86
- return;
87
- }
88
- postNotebookMessage("outputBlur", outputFocus);
89
- }, 0);
90
- };
91
- const hasActiveEditableElement = (parent, root = document) => {
92
- const element = root.activeElement;
93
- return !!(element && parent.contains(element) && (element.matches(":read-write") || element.tagName.toLowerCase() === "select" || (element.shadowRoot && hasActiveEditableElement(element.shadowRoot, element.shadowRoot))));
94
- };
95
- const checkOutputInputFocus = e => {
96
- lastFocusedOutput = getOutputContainer(e);
97
- const activeElement = window.document.activeElement;
98
- if (!activeElement) {
99
- return;
100
- }
101
- const id = lastFocusedOutput?.id;
102
- if (id && (hasActiveEditableElement(activeElement, window.document))) {
103
- postNotebookMessage("outputInputFocus", {
104
- inputFocused: true,
105
- id
106
- });
107
- activeElement.addEventListener("blur", () => {
108
- postNotebookMessage("outputInputFocus", {
109
- inputFocused: false,
110
- id
111
- });
112
- }, {
113
- once: true
114
- });
115
- }
116
- };
117
- const handleInnerClick = event => {
118
- if (!event || !event.view || !event.view.document) {
119
- return;
120
- }
121
- const outputFocus = lastFocusedOutput = getOutputContainer(event);
122
- for (const node of event.composedPath()) {
123
- if (node instanceof HTMLAnchorElement && node.href) {
124
- if (node.href.startsWith("blob:")) {
125
- if (outputFocus) {
126
- postNotebookMessage("outputFocus", outputFocus);
127
- }
128
- handleBlobUrlClick(node.href, node.download);
129
- } else if (node.href.startsWith("data:")) {
130
- if (outputFocus) {
131
- postNotebookMessage("outputFocus", outputFocus);
132
- }
133
- handleDataUrl(node.href, node.download);
134
- } else if (node.getAttribute("href")?.trim().startsWith("#")) {
135
- if (!node.hash) {
136
- postNotebookMessage("scroll-to-reveal", {
137
- scrollTop: 0
138
- });
139
- return;
140
- }
141
- const targetId = node.hash.substring(1);
142
- let scrollTarget = event.view.document.getElementById(targetId);
143
- if (!scrollTarget) {
144
- for (const preview of event.view.document.querySelectorAll(".preview")) {
145
- scrollTarget = preview.shadowRoot?.getElementById(targetId);
146
- if (scrollTarget) {
147
- break;
148
- }
149
- }
150
- }
151
- if (scrollTarget) {
152
- const scrollTop = scrollTarget.getBoundingClientRect().top + event.view.scrollY;
153
- postNotebookMessage("scroll-to-reveal", {
154
- scrollTop
155
- });
156
- return;
157
- }
158
- } else {
159
- const href = node.getAttribute("href");
160
- if (href) {
161
- if (href.startsWith("command:") && outputFocus) {
162
- postNotebookMessage("outputFocus", outputFocus);
163
- }
164
- postNotebookMessage("clicked-link", {
165
- href
166
- });
167
- }
168
- }
169
- event.preventDefault();
170
- event.stopPropagation();
171
- return;
172
- }
173
- }
174
- if (outputFocus) {
175
- postNotebookMessage("outputFocus", outputFocus);
176
- }
177
- };
178
- const blurOutput = () => {
179
- const selection = window.getSelection();
180
- if (!selection) {
181
- return;
182
- }
183
- selection.removeAllRanges();
184
- };
185
- const selectOutputContents = cellOrOutputId => {
186
- const selection = window.getSelection();
187
- if (!selection) {
188
- return;
189
- }
190
- const cellOutputContainer = window.document.getElementById(cellOrOutputId);
191
- if (!cellOutputContainer) {
192
- return;
193
- }
194
- selection.removeAllRanges();
195
- const range = document.createRange();
196
- range.selectNode(cellOutputContainer);
197
- selection.addRange(range);
198
- };
199
- const selectInputContents = cellOrOutputId => {
200
- const cellOutputContainer = window.document.getElementById(cellOrOutputId);
201
- if (!cellOutputContainer) {
202
- return;
203
- }
204
- const activeElement = window.document.activeElement;
205
- if (activeElement && hasActiveEditableElement(activeElement, window.document)) {
206
- activeElement.select();
207
- }
208
- };
209
- const onPageUpDownSelectionHandler = e => {
210
- if (!lastFocusedOutput?.id || !e.shiftKey) {
211
- return;
212
- }
213
- if (e.shiftKey && (e.code === "ArrowUp" || e.code === "ArrowDown")) {
214
- e.stopPropagation();
215
- return;
216
- }
217
- if (!(e.code === "PageUp" || e.code === "PageDown") && !(e.metaKey && (e.code === "ArrowDown" || e.code === "ArrowUp"))) {
218
- return;
219
- }
220
- const outputContainer = window.document.getElementById(lastFocusedOutput.id);
221
- const selection = window.getSelection();
222
- if (!outputContainer || !selection?.anchorNode) {
223
- return;
224
- }
225
- const activeElement = window.document.activeElement;
226
- if (activeElement && hasActiveEditableElement(activeElement, window.document)) {
227
- return;
228
- }
229
- e.stopPropagation();
230
- e.preventDefault();
231
- const {
232
- anchorNode,
233
- anchorOffset
234
- } = selection;
235
- const range = document.createRange();
236
- if (e.code === "PageDown" || e.code === "ArrowDown") {
237
- range.setStart(anchorNode, anchorOffset);
238
- range.setEnd(outputContainer, 1);
239
- } else {
240
- range.setStart(outputContainer, 0);
241
- range.setEnd(anchorNode, anchorOffset);
242
- }
243
- selection.removeAllRanges();
244
- selection.addRange(range);
245
- };
246
- const disableNativeSelectAll = e => {
247
- if (!lastFocusedOutput?.id) {
248
- return;
249
- }
250
- const activeElement = window.document.activeElement;
251
- if (activeElement && hasActiveEditableElement(activeElement, window.document)) {
252
- return;
253
- }
254
- if ((e.key === "a" && e.ctrlKey) || (e.metaKey && e.key === "a")) {
255
- e.preventDefault();
256
- return;
257
- }
258
- };
259
- const handleDataUrl = async (data, downloadName) => {
260
- postNotebookMessage("clicked-data-url", {
261
- data,
262
- downloadName
263
- });
264
- };
265
- const handleBlobUrlClick = async (url, downloadName) => {
266
- try {
267
- const response = await fetch(url);
268
- const blob = await response.blob();
269
- const reader = ( new FileReader());
270
- reader.addEventListener("load", () => {
271
- handleDataUrl(reader.result, downloadName);
272
- });
273
- reader.readAsDataURL(blob);
274
- } catch (e) {
275
- console.error(e.message);
276
- }
277
- };
278
- window.document.body.addEventListener("click", handleInnerClick);
279
- window.document.body.addEventListener("focusin", checkOutputInputFocus);
280
- window.document.body.addEventListener("focusout", handleOutputFocusOut);
281
- window.document.body.addEventListener("keydown", onPageUpDownSelectionHandler);
282
- window.document.body.addEventListener("keydown", disableNativeSelectAll);
283
- function createKernelContext() {
284
- return ( Object.freeze({
285
- onDidReceiveKernelMessage: onDidReceiveKernelMessage.event,
286
- postKernelMessage: data => postNotebookMessage("customKernelMessage", {
287
- message: data
288
- })
289
- }));
290
- }
291
- async function runKernelPreload(url) {
292
- try {
293
- return await activateModuleKernelPreload(url);
294
- } catch (e) {
295
- console.error(e);
296
- throw e;
297
- }
298
- }
299
- async function activateModuleKernelPreload(url) {
300
- const module = await __import(url);
301
- if (!module.activate) {
302
- console.error(
303
- `Notebook preload '${url}' was expected to be a module but it does not export an 'activate' function`
304
- );
305
- return;
306
- }
307
- return module.activate(createKernelContext());
308
- }
309
- const dimensionUpdater = new (class {
310
- constructor() {
311
- this.pending = ( new Map());
312
- }
313
- updateHeight(id, height, options) {
314
- if (!this.pending.size) {
315
- setTimeout(() => {
316
- this.updateImmediately();
317
- }, 0);
318
- }
319
- const update = this.pending.get(id);
320
- if (update && update.isOutput) {
321
- this.pending.set(id, {
322
- id,
323
- height,
324
- init: update.init,
325
- isOutput: update.isOutput
326
- });
327
- } else {
328
- this.pending.set(id, {
329
- id,
330
- height,
331
- ...options
332
- });
333
- }
334
- }
335
- updateImmediately() {
336
- if (!this.pending.size) {
337
- return;
338
- }
339
- postNotebookMessage("dimension", {
340
- updates: Array.from(( this.pending.values()))
341
- });
342
- this.pending.clear();
343
- }
344
- })();
345
- function elementHasContent(height) {
346
- return height > 2.1;
347
- }
348
- const resizeObserver = new (class {
349
- constructor() {
350
- this._observedElements = ( new WeakMap());
351
- this._observer = ( new ResizeObserver(entries => {
352
- for (const entry of entries) {
353
- if (!window.document.body.contains(entry.target)) {
354
- continue;
355
- }
356
- const observedElementInfo = this._observedElements.get(entry.target);
357
- if (!observedElementInfo) {
358
- continue;
359
- }
360
- this.postResizeMessage(observedElementInfo.cellId);
361
- if (entry.target.id !== observedElementInfo.id) {
362
- continue;
363
- }
364
- if (!entry.contentRect) {
365
- continue;
366
- }
367
- if (!observedElementInfo.output) {
368
- this.updateHeight(observedElementInfo, entry.target.offsetHeight);
369
- continue;
370
- }
371
- const hasContent = elementHasContent(entry.contentRect.height);
372
- const shouldUpdatePadding = (hasContent && observedElementInfo.lastKnownPadding === 0) || (!hasContent && observedElementInfo.lastKnownPadding !== 0);
373
- if (shouldUpdatePadding) {
374
- window.requestAnimationFrame(() => {
375
- if (hasContent) {
376
- entry.target.style.padding = `${ctx.style.outputNodePadding}px ${ctx.style.outputNodePadding}px ${ctx.style.outputNodePadding}px ${ctx.style.outputNodeLeftPadding}px`;
377
- } else {
378
- entry.target.style.padding = `0px`;
379
- }
380
- this.updateHeight(observedElementInfo, hasContent ? entry.target.offsetHeight : 0);
381
- });
382
- } else {
383
- this.updateHeight(observedElementInfo, hasContent ? entry.target.offsetHeight : 0);
384
- }
385
- }
386
- }));
387
- }
388
- updateHeight(observedElementInfo, offsetHeight) {
389
- if (observedElementInfo.lastKnownHeight !== offsetHeight) {
390
- observedElementInfo.lastKnownHeight = offsetHeight;
391
- dimensionUpdater.updateHeight(observedElementInfo.id, offsetHeight, {
392
- isOutput: observedElementInfo.output
393
- });
394
- }
395
- }
396
- observe(container, id, output, cellId) {
397
- if (( this._observedElements.has(container))) {
398
- return;
399
- }
400
- this._observedElements.set(container, {
401
- id,
402
- output,
403
- lastKnownPadding: ctx.style.outputNodePadding,
404
- lastKnownHeight: -1,
405
- cellId
406
- });
407
- this._observer.observe(container);
408
- }
409
- postResizeMessage(cellId) {
410
- clearTimeout(this._outputResizeTimer);
411
- this._outputResizeTimer = setTimeout(() => {
412
- postNotebookMessage("outputResized", {
413
- cellId
414
- });
415
- }, 250);
416
- }
417
- })();
418
- let previousDelta;
419
- let scrollTimeout;
420
- let scrolledElement;
421
- let lastTimeScrolled;
422
- function flagRecentlyScrolled(node, deltaY) {
423
- scrolledElement = node;
424
- if (deltaY === undefined) {
425
- lastTimeScrolled = Date.now();
426
- previousDelta = undefined;
427
- node.setAttribute("recentlyScrolled", "true");
428
- clearTimeout(scrollTimeout);
429
- scrollTimeout = setTimeout(() => {
430
- scrolledElement?.removeAttribute("recentlyScrolled");
431
- }, 300);
432
- return true;
433
- }
434
- if (node.hasAttribute("recentlyScrolled")) {
435
- if (lastTimeScrolled && Date.now() - lastTimeScrolled > 400) {
436
- if (!!previousDelta && deltaY < 0 && deltaY < previousDelta - 8) {
437
- clearTimeout(scrollTimeout);
438
- scrolledElement?.removeAttribute("recentlyScrolled");
439
- return false;
440
- } else if (!!previousDelta && deltaY > 0 && deltaY > previousDelta + 8) {
441
- clearTimeout(scrollTimeout);
442
- scrolledElement?.removeAttribute("recentlyScrolled");
443
- return false;
444
- }
445
- clearTimeout(scrollTimeout);
446
- scrollTimeout = setTimeout(() => {
447
- scrolledElement?.removeAttribute("recentlyScrolled");
448
- }, 50);
449
- } else {
450
- clearTimeout(scrollTimeout);
451
- scrollTimeout = setTimeout(() => {
452
- scrolledElement?.removeAttribute("recentlyScrolled");
453
- }, 300);
454
- }
455
- previousDelta = deltaY;
456
- return true;
457
- }
458
- return false;
459
- }
460
- function eventTargetShouldHandleScroll(event) {
461
- for (let node = event.target; node; node = node.parentNode) {
462
- if (!(node instanceof Element) || node.id === "container" || node.classList.contains("cell_container") || node.classList.contains("markup") || node.classList.contains("output_container")) {
463
- return false;
464
- }
465
- if (event.deltaY < 0 && node.scrollTop > 0) {
466
- flagRecentlyScrolled(node);
467
- return true;
468
- }
469
- if (event.deltaY > 0 && node.scrollTop + node.clientHeight < node.scrollHeight) {
470
- if (node.scrollHeight - node.scrollTop - node.clientHeight < 2) {
471
- continue;
472
- }
473
- const overflowY = window.getComputedStyle(node).overflowY;
474
- if (overflowY === "hidden" || overflowY === "visible") {
475
- continue;
476
- }
477
- flagRecentlyScrolled(node);
478
- return true;
479
- }
480
- if (flagRecentlyScrolled(node, event.deltaY)) {
481
- return true;
482
- }
483
- }
484
- return false;
485
- }
486
- const handleWheel = event => {
487
- if (event.defaultPrevented || eventTargetShouldHandleScroll(event)) {
488
- return;
489
- }
490
- postNotebookMessage("did-scroll-wheel", {
491
- payload: {
492
- deltaMode: event.deltaMode,
493
- deltaX: event.deltaX,
494
- deltaY: event.deltaY,
495
- deltaZ: event.deltaZ,
496
- wheelDelta: event.wheelDelta && isChrome ? (event.wheelDelta / window.devicePixelRatio) : event.wheelDelta,
497
- wheelDeltaX: event.wheelDeltaX && isChrome ? (event.wheelDeltaX / window.devicePixelRatio) : event.wheelDeltaX,
498
- wheelDeltaY: event.wheelDeltaY && isChrome ? (event.wheelDeltaY / window.devicePixelRatio) : event.wheelDeltaY,
499
- detail: event.detail,
500
- shiftKey: event.shiftKey,
501
- type: event.type
502
- }
503
- });
504
- };
505
- function focusFirstFocusableOrContainerInOutput(cellOrOutputId, alternateId) {
506
- const cellOutputContainer = window.document.getElementById(cellOrOutputId) ?? (!!alternateId ? window.document.getElementById(alternateId) : undefined);
507
- if (!!cellOutputContainer) {
508
- if (cellOutputContainer.contains(window.document.activeElement)) {
509
- return;
510
- }
511
- let focusableElement = cellOutputContainer.querySelector("[tabindex=\"0\"], [href], button, input, option, select, textarea");
512
- if (!focusableElement) {
513
- focusableElement = cellOutputContainer;
514
- focusableElement.tabIndex = -1;
515
- }
516
- if (lastFocusedOutput?.id !== cellOutputContainer.id) {
517
- lastFocusedOutput = cellOutputContainer;
518
- postNotebookMessage("outputFocus", {
519
- id: cellOutputContainer.id
520
- });
521
- }
522
- focusableElement.focus();
523
- }
524
- }
525
- function createFocusSink(cellId, focusNext) {
526
- const element = document.createElement("div");
527
- element.id = `focus-sink-${cellId}`;
528
- element.tabIndex = 0;
529
- element.addEventListener("focus", () => {
530
- postNotebookMessage("focus-editor", {
531
- cellId: cellId,
532
- focusNext
533
- });
534
- });
535
- return element;
536
- }
537
- function _internalHighlightRange(range, tagName = "mark", attributes = {}) {
538
- function _textNodesInRange(range) {
539
- if (!range.startContainer.ownerDocument) {
540
- return [];
541
- }
542
- if (range.startContainer.nodeType === Node.TEXT_NODE && range.startOffset > 0) {
543
- const startContainer = range.startContainer;
544
- const endOffset = range.endOffset;
545
- const createdNode = startContainer.splitText(range.startOffset);
546
- if (range.endContainer === startContainer) {
547
- range.setEnd(createdNode, endOffset - range.startOffset);
548
- }
549
- range.setStart(createdNode, 0);
550
- }
551
- if (range.endContainer.nodeType === Node.TEXT_NODE && range.endOffset < range.endContainer.length) {
552
- range.endContainer.splitText(range.endOffset);
553
- }
554
- const walker = range.startContainer.ownerDocument.createTreeWalker(
555
- range.commonAncestorContainer,
556
- NodeFilter.SHOW_TEXT,
557
- node => range.intersectsNode(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
558
- );
559
- walker.currentNode = range.startContainer;
560
- const nodes = [];
561
- if (walker.currentNode.nodeType === Node.TEXT_NODE) {
562
- nodes.push(walker.currentNode);
563
- }
564
- while (walker.nextNode() && range.comparePoint(walker.currentNode, 0) !== 1) {
565
- if (walker.currentNode.nodeType === Node.TEXT_NODE) {
566
- nodes.push(walker.currentNode);
567
- }
568
- }
569
- return nodes;
570
- }
571
- function wrapNodeInHighlight(node, tagName, attributes) {
572
- const highlightElement = node.ownerDocument.createElement(tagName);
573
- ( Object.keys(attributes)).forEach(key => {
574
- highlightElement.setAttribute(key, attributes[key]);
575
- });
576
- const tempRange = node.ownerDocument.createRange();
577
- tempRange.selectNode(node);
578
- tempRange.surroundContents(highlightElement);
579
- return highlightElement;
580
- }
581
- if (range.collapsed) {
582
- return {
583
- remove: () => {},
584
- update: () => {}
585
- };
586
- }
587
- const nodes = _textNodesInRange(range);
588
- const highlightElements = [];
589
- for (const nodeIdx in nodes) {
590
- const highlightElement = wrapNodeInHighlight(nodes[nodeIdx], tagName, attributes);
591
- highlightElements.push(highlightElement);
592
- }
593
- function _removeHighlight(highlightElement) {
594
- if (highlightElement.childNodes.length === 1) {
595
- highlightElement.replaceWith(highlightElement.firstChild);
596
- } else {
597
- while (highlightElement.firstChild) {
598
- highlightElement.parentNode?.insertBefore(highlightElement.firstChild, highlightElement);
599
- }
600
- highlightElement.remove();
601
- }
602
- }
603
- function _removeHighlights() {
604
- for (const highlightIdx in highlightElements) {
605
- _removeHighlight(highlightElements[highlightIdx]);
606
- }
607
- }
608
- function _updateHighlight(highlightElement, attributes = {}) {
609
- ( Object.keys(attributes)).forEach(key => {
610
- highlightElement.setAttribute(key, attributes[key]);
611
- });
612
- }
613
- function updateHighlights(attributes) {
614
- for (const highlightIdx in highlightElements) {
615
- _updateHighlight(highlightElements[highlightIdx], attributes);
616
- }
617
- }
618
- return {
619
- remove: _removeHighlights,
620
- update: updateHighlights
621
- };
622
- }
623
- function highlightRange(range, useCustom, tagName = "mark", attributes = {}) {
624
- {
625
- const ret = _internalHighlightRange(range, tagName, attributes);
626
- return {
627
- range: range,
628
- dispose: ret.remove,
629
- update: (color, className) => {
630
- if (className === undefined) {
631
- ret.update({
632
- "style": `background-color: ${color}`
633
- });
634
- } else {
635
- ret.update({
636
- "class": className
637
- });
638
- }
639
- }
640
- };
641
- }
642
- }
643
- function createEmitter(listenerChange = () => undefined) {
644
- const listeners = ( new Set());
645
- return {
646
- fire(data) {
647
- for (const listener of [...listeners]) {
648
- listener.fn.call(listener.thisArg, data);
649
- }
650
- },
651
- event(fn, thisArg, disposables) {
652
- const listenerObj = {
653
- fn,
654
- thisArg
655
- };
656
- const disposable = {
657
- dispose: () => {
658
- listeners.delete(listenerObj);
659
- listenerChange(listeners);
660
- }
661
- };
662
- listeners.add(listenerObj);
663
- listenerChange(listeners);
664
- if (disposables instanceof Array) {
665
- disposables.push(disposable);
666
- } else if (disposables) {
667
- disposables.add(disposable);
668
- }
669
- return disposable;
670
- }
671
- };
672
- }
673
- function showRenderError(errorText, outputNode, errors) {
674
- outputNode.innerText = errorText;
675
- const errList = document.createElement("ul");
676
- for (const result of errors) {
677
- console.error(result);
678
- const item = document.createElement("li");
679
- item.innerText = result.message;
680
- errList.appendChild(item);
681
- }
682
- outputNode.appendChild(errList);
683
- }
684
- const outputItemRequests = new (class {
685
- constructor() {
686
- this._requestPool = 0;
687
- this._requests = ( new Map());
688
- }
689
- getOutputItem(outputId, mime) {
690
- const requestId = this._requestPool++;
691
- const {
692
- promise,
693
- resolve
694
- } = promiseWithResolvers();
695
- this._requests.set(requestId, {
696
- resolve
697
- });
698
- postNotebookMessage("getOutputItem", {
699
- requestId,
700
- outputId,
701
- mime
702
- });
703
- return promise;
704
- }
705
- resolveOutputItem(requestId, output) {
706
- const request = this._requests.get(requestId);
707
- if (!request) {
708
- return;
709
- }
710
- this._requests.delete(requestId);
711
- request.resolve(output);
712
- }
713
- })();
714
- let hasWarnedAboutAllOutputItemsProposal = false;
715
- function createOutputItem(id, mime, metadata, valueBytes, allOutputItemData, appended) {
716
- function create(id, mime, metadata, valueBytes, appended) {
717
- return ( Object.freeze({
718
- id,
719
- mime,
720
- metadata,
721
- appendedText() {
722
- if (appended) {
723
- return textDecoder.decode(appended.valueBytes);
724
- }
725
- return undefined;
726
- },
727
- data() {
728
- return valueBytes;
729
- },
730
- text() {
731
- return textDecoder.decode(valueBytes);
732
- },
733
- json() {
734
- return JSON.parse(this.text());
735
- },
736
- blob() {
737
- return ( new Blob([valueBytes], {
738
- type: this.mime
739
- }));
740
- },
741
- get _allOutputItems() {
742
- if (!hasWarnedAboutAllOutputItemsProposal) {
743
- hasWarnedAboutAllOutputItemsProposal = true;
744
- console.warn(
745
- `'_allOutputItems' is proposed API. DO NOT ship an extension that depends on it!`
746
- );
747
- }
748
- return allOutputItemList;
749
- }
750
- }));
751
- }
752
- const allOutputItemCache = ( new Map());
753
- const allOutputItemList = ( Object.freeze(( allOutputItemData.map(outputItem => {
754
- const mime = outputItem.mime;
755
- return ( Object.freeze({
756
- mime,
757
- getItem() {
758
- const existingTask = allOutputItemCache.get(mime);
759
- if (existingTask) {
760
- return existingTask;
761
- }
762
- const task = outputItemRequests.getOutputItem(id, mime).then(item => {
763
- return item ? create(id, item.mime, metadata, item.valueBytes) : undefined;
764
- });
765
- allOutputItemCache.set(mime, task);
766
- return task;
767
- }
768
- }));
769
- }))));
770
- const item = create(id, mime, metadata, valueBytes, appended);
771
- allOutputItemCache.set(mime, Promise.resolve(item));
772
- return item;
773
- }
774
- const onDidReceiveKernelMessage = createEmitter();
775
- const ttPolicy = window.trustedTypes?.createPolicy("notebookRenderer", {
776
- createHTML: value => value,
777
- createScript: value => value
778
- });
779
- window.addEventListener("wheel", handleWheel);
780
- const matchColor = window.getComputedStyle(window.document.getElementById("_defaultColorPalatte")).color;
781
- const currentMatchColor = window.getComputedStyle(window.document.getElementById("_defaultColorPalatte")).backgroundColor;
782
- class JSHighlighter {
783
- constructor() {
784
- this._activeHighlightInfo = ( new Map());
785
- }
786
- addHighlights(matches, ownerID) {
787
- for (let i = matches.length - 1; i >= 0; i--) {
788
- const match = matches[i];
789
- const ret = highlightRange(match.originalRange, true, "mark", match.isShadow ? {
790
- "style": "background-color: " + matchColor + ";"
791
- } : {
792
- "class": "find-match"
793
- });
794
- match.highlightResult = ret;
795
- }
796
- const highlightInfo = {
797
- matches,
798
- currentMatchIndex: -1
799
- };
800
- this._activeHighlightInfo.set(ownerID, highlightInfo);
801
- }
802
- removeHighlights(ownerID) {
803
- this._activeHighlightInfo.get(ownerID)?.matches.forEach(match => {
804
- match.highlightResult?.dispose();
805
- });
806
- this._activeHighlightInfo.delete(ownerID);
807
- }
808
- highlightCurrentMatch(index, ownerID) {
809
- const highlightInfo = this._activeHighlightInfo.get(ownerID);
810
- if (!highlightInfo) {
811
- console.error("Modified current highlight match before adding highlight list.");
812
- return;
813
- }
814
- const oldMatch = highlightInfo.matches[highlightInfo.currentMatchIndex];
815
- oldMatch?.highlightResult?.update(matchColor, oldMatch.isShadow ? undefined : "find-match");
816
- const match = highlightInfo.matches[index];
817
- highlightInfo.currentMatchIndex = index;
818
- const sel = window.getSelection();
819
- if (!!match && !!sel && match.highlightResult) {
820
- let offset = 0;
821
- try {
822
- const outputOffset = window.document.getElementById(match.id).getBoundingClientRect().top;
823
- const tempRange = document.createRange();
824
- tempRange.selectNode(match.highlightResult.range.startContainer);
825
- match.highlightResult.range.startContainer.parentElement?.scrollIntoView({
826
- behavior: "auto",
827
- block: "end",
828
- inline: "nearest"
829
- });
830
- const rangeOffset = tempRange.getBoundingClientRect().top;
831
- tempRange.detach();
832
- offset = rangeOffset - outputOffset;
833
- } catch (e) {
834
- console.error(e);
835
- }
836
- match.highlightResult?.update(currentMatchColor, match.isShadow ? undefined : "current-find-match");
837
- window.document.getSelection()?.removeAllRanges();
838
- postNotebookMessage("didFindHighlightCurrent", {
839
- offset
840
- });
841
- }
842
- }
843
- unHighlightCurrentMatch(index, ownerID) {
844
- const highlightInfo = this._activeHighlightInfo.get(ownerID);
845
- if (!highlightInfo) {
846
- return;
847
- }
848
- const oldMatch = highlightInfo.matches[index];
849
- if (oldMatch && oldMatch.highlightResult) {
850
- oldMatch.highlightResult.update(matchColor, oldMatch.isShadow ? undefined : "find-match");
851
- }
852
- }
853
- dispose() {
854
- window.document.getSelection()?.removeAllRanges();
855
- this._activeHighlightInfo.forEach(highlightInfo => {
856
- highlightInfo.matches.forEach(match => {
857
- match.highlightResult?.dispose();
858
- });
859
- });
860
- }
861
- }
862
- class CSSHighlighter {
863
- constructor() {
864
- this._activeHighlightInfo = ( new Map());
865
- this._matchesHighlight = ( new Highlight());
866
- this._matchesHighlight.priority = 1;
867
- this._currentMatchesHighlight = ( new Highlight());
868
- this._currentMatchesHighlight.priority = 2;
869
- CSS.highlights?.set(`find-highlight`, this._matchesHighlight);
870
- CSS.highlights?.set(`current-find-highlight`, this._currentMatchesHighlight);
871
- }
872
- _refreshRegistry(updateMatchesHighlight = true) {
873
- if (updateMatchesHighlight) {
874
- this._matchesHighlight.clear();
875
- }
876
- this._currentMatchesHighlight.clear();
877
- this._activeHighlightInfo.forEach(highlightInfo => {
878
- if (updateMatchesHighlight) {
879
- for (let i = 0; i < highlightInfo.matches.length; i++) {
880
- this._matchesHighlight.add(highlightInfo.matches[i].originalRange);
881
- }
882
- }
883
- if (highlightInfo.currentMatchIndex < highlightInfo.matches.length && highlightInfo.currentMatchIndex >= 0) {
884
- this._currentMatchesHighlight.add(highlightInfo.matches[highlightInfo.currentMatchIndex].originalRange);
885
- }
886
- });
887
- }
888
- addHighlights(matches, ownerID) {
889
- for (let i = 0; i < matches.length; i++) {
890
- this._matchesHighlight.add(matches[i].originalRange);
891
- }
892
- const newEntry = {
893
- matches,
894
- currentMatchIndex: -1
895
- };
896
- this._activeHighlightInfo.set(ownerID, newEntry);
897
- }
898
- highlightCurrentMatch(index, ownerID) {
899
- const highlightInfo = this._activeHighlightInfo.get(ownerID);
900
- if (!highlightInfo) {
901
- console.error("Modified current highlight match before adding highlight list.");
902
- return;
903
- }
904
- highlightInfo.currentMatchIndex = index;
905
- const match = highlightInfo.matches[index];
906
- if (match) {
907
- let offset = 0;
908
- try {
909
- const outputOffset = window.document.getElementById(match.id).getBoundingClientRect().top;
910
- match.originalRange.startContainer.parentElement?.scrollIntoView({
911
- behavior: "auto",
912
- block: "end",
913
- inline: "nearest"
914
- });
915
- const rangeOffset = match.originalRange.getBoundingClientRect().top;
916
- offset = rangeOffset - outputOffset;
917
- postNotebookMessage("didFindHighlightCurrent", {
918
- offset
919
- });
920
- } catch (e) {
921
- console.error(e);
922
- }
923
- }
924
- this._refreshRegistry(false);
925
- }
926
- unHighlightCurrentMatch(index, ownerID) {
927
- const highlightInfo = this._activeHighlightInfo.get(ownerID);
928
- if (!highlightInfo) {
929
- return;
930
- }
931
- highlightInfo.currentMatchIndex = -1;
932
- }
933
- removeHighlights(ownerID) {
934
- this._activeHighlightInfo.delete(ownerID);
935
- this._refreshRegistry();
936
- }
937
- dispose() {
938
- window.document.getSelection()?.removeAllRanges();
939
- this._currentMatchesHighlight.clear();
940
- this._matchesHighlight.clear();
941
- }
942
- }
943
- const _highlighter = (CSS.highlights) ? ( new CSSHighlighter()) : ( new JSHighlighter());
944
- function extractSelectionLine(selection) {
945
- const range = selection.getRangeAt(0);
946
- const oldRange = range.cloneRange();
947
- const captureLength = ( selection.toString()).length;
948
- selection.collapseToStart();
949
- selection.modify("move", "backward", "lineboundary");
950
- selection.modify("extend", "forward", "lineboundary");
951
- const line = ( selection.toString());
952
- const rangeStart = getStartOffset(selection.getRangeAt(0), oldRange);
953
- const lineRange = {
954
- start: rangeStart,
955
- end: rangeStart + captureLength
956
- };
957
- selection.removeAllRanges();
958
- selection.addRange(oldRange);
959
- return {
960
- line,
961
- range: lineRange
962
- };
963
- }
964
- function getStartOffset(lineRange, originalRange) {
965
- const firstCommonAncestor = findFirstCommonAncestor(lineRange.startContainer, originalRange.startContainer);
966
- const selectionOffset = getSelectionOffsetRelativeTo(firstCommonAncestor, lineRange.startContainer) + lineRange.startOffset;
967
- const textOffset = getSelectionOffsetRelativeTo(firstCommonAncestor, originalRange.startContainer) + originalRange.startOffset;
968
- return textOffset - selectionOffset;
969
- }
970
- function findFirstCommonAncestor(nodeA, nodeB) {
971
- const range = ( new Range());
972
- range.setStart(nodeA, 0);
973
- range.setEnd(nodeB, 0);
974
- return range.commonAncestorContainer;
975
- }
976
- function getTextContentLength(node) {
977
- let length = 0;
978
- if (node.nodeType === Node.TEXT_NODE) {
979
- length += node.textContent?.length || 0;
980
- } else {
981
- for (const childNode of node.childNodes) {
982
- length += getTextContentLength(childNode);
983
- }
984
- }
985
- return length;
986
- }
987
- function getSelectionOffsetRelativeTo(parentElement, currentNode) {
988
- if (!currentNode) {
989
- return 0;
990
- }
991
- let offset = 0;
992
- if (currentNode === parentElement || !parentElement.contains(currentNode)) {
993
- return offset;
994
- }
995
- let prevSibling = currentNode.previousSibling;
996
- while (prevSibling) {
997
- offset += getTextContentLength(prevSibling);
998
- prevSibling = prevSibling.previousSibling;
999
- }
1000
- return offset + getSelectionOffsetRelativeTo(parentElement, currentNode.parentNode);
1001
- }
1002
- const find = (query, options) => {
1003
- let find = true;
1004
- let matches = [];
1005
- const range = document.createRange();
1006
- range.selectNodeContents(window.document.getElementById("findStart"));
1007
- const sel = window.getSelection();
1008
- sel?.removeAllRanges();
1009
- sel?.addRange(range);
1010
- viewModel.toggleDragDropEnabled(false);
1011
- try {
1012
- document.designMode = "On";
1013
- while (find && matches.length < 500) {
1014
- find = window.find(
1015
- query,
1016
- !!options.caseSensitive,
1017
- false,
1018
- false,
1019
- !!options.wholeWord,
1020
- true,
1021
- false
1022
- );
1023
- if (find) {
1024
- const selection = window.getSelection();
1025
- if (!selection) {
1026
- console.log("no selection");
1027
- break;
1028
- }
1029
- if (options.includeMarkup && selection.rangeCount > 0 && selection.getRangeAt(0).startContainer.nodeType === 1 && selection.getRangeAt(0).startContainer.classList.contains("markup")) {
1030
- const preview = selection.anchorNode?.firstChild;
1031
- const root = preview.shadowRoot;
1032
- const shadowSelection = root?.getSelection ? root?.getSelection() : null;
1033
- if (shadowSelection && shadowSelection.anchorNode) {
1034
- matches.push({
1035
- type: "preview",
1036
- id: preview.id,
1037
- cellId: preview.id,
1038
- container: preview,
1039
- isShadow: true,
1040
- originalRange: shadowSelection.getRangeAt(0),
1041
- searchPreviewInfo: options.shouldGetSearchPreviewInfo ? extractSelectionLine(shadowSelection) : undefined
1042
- });
1043
- }
1044
- }
1045
- if (options.includeOutput && selection.rangeCount > 0 && selection.getRangeAt(0).startContainer.nodeType === 1 && selection.getRangeAt(0).startContainer.classList.contains("output_container")) {
1046
- const cellId = selection.getRangeAt(0).startContainer.parentElement.id;
1047
- const outputNode = selection.anchorNode?.firstChild;
1048
- const root = outputNode.shadowRoot;
1049
- const shadowSelection = root?.getSelection ? root?.getSelection() : null;
1050
- if (shadowSelection && shadowSelection.anchorNode) {
1051
- matches.push({
1052
- type: "output",
1053
- id: outputNode.id,
1054
- cellId: cellId,
1055
- container: outputNode,
1056
- isShadow: true,
1057
- originalRange: shadowSelection.getRangeAt(0),
1058
- searchPreviewInfo: options.shouldGetSearchPreviewInfo ? extractSelectionLine(shadowSelection) : undefined
1059
- });
1060
- }
1061
- }
1062
- const anchorNode = selection.anchorNode?.parentElement;
1063
- if (anchorNode) {
1064
- const lastEl = matches.length ? matches[matches.length - 1] : null;
1065
- if (lastEl && lastEl.container.contains(anchorNode) && options.includeOutput) {
1066
- matches.push({
1067
- type: lastEl.type,
1068
- id: lastEl.id,
1069
- cellId: lastEl.cellId,
1070
- container: lastEl.container,
1071
- isShadow: false,
1072
- originalRange: selection.getRangeAt(0),
1073
- searchPreviewInfo: options.shouldGetSearchPreviewInfo ? extractSelectionLine(selection) : undefined
1074
- });
1075
- } else {
1076
- for (let node = anchorNode; node; node = node.parentElement) {
1077
- if (!(node instanceof Element)) {
1078
- break;
1079
- }
1080
- if (node.classList.contains("output") && options.includeOutput) {
1081
- const cellId = node.parentElement?.parentElement?.id;
1082
- if (cellId) {
1083
- matches.push({
1084
- type: "output",
1085
- id: node.id,
1086
- cellId: cellId,
1087
- container: node,
1088
- isShadow: false,
1089
- originalRange: selection.getRangeAt(0),
1090
- searchPreviewInfo: options.shouldGetSearchPreviewInfo ? extractSelectionLine(selection) : undefined
1091
- });
1092
- }
1093
- break;
1094
- }
1095
- if (node.id === "container" || node === window.document.body) {
1096
- break;
1097
- }
1098
- }
1099
- }
1100
- } else {
1101
- break;
1102
- }
1103
- }
1104
- }
1105
- } catch (e) {
1106
- console.log(e);
1107
- }
1108
- matches = matches.filter(
1109
- match => options.findIds.length ? options.findIds.includes(match.cellId) : true
1110
- );
1111
- _highlighter.addHighlights(matches, options.ownerID);
1112
- window.document.getSelection()?.removeAllRanges();
1113
- viewModel.toggleDragDropEnabled(currentOptions.dragAndDropEnabled);
1114
- document.designMode = "Off";
1115
- postNotebookMessage("didFind", {
1116
- matches: ( matches.map((match, index) => ({
1117
- type: match.type,
1118
- id: match.id,
1119
- cellId: match.cellId,
1120
- index,
1121
- searchPreviewInfo: match.searchPreviewInfo
1122
- })))
1123
- });
1124
- };
1125
- const copyOutputImage = async (outputId, altOutputId, textAlternates, retries = 5) => {
1126
- if (!window.document.hasFocus() && retries > 0) {
1127
- setTimeout(() => {
1128
- copyOutputImage(outputId, altOutputId, textAlternates, retries - 1);
1129
- }, 50);
1130
- return;
1131
- }
1132
- try {
1133
- const outputElement = window.document.getElementById(outputId) ?? window.document.getElementById(altOutputId);
1134
- let image = outputElement?.querySelector("img");
1135
- if (!image) {
1136
- const svgImage = outputElement?.querySelector("svg.output-image") ?? outputElement?.querySelector("div.svgContainerStyle > svg");
1137
- if (svgImage) {
1138
- image = ( new Image());
1139
- image.src = "data:image/svg+xml," + encodeURIComponent(svgImage.outerHTML);
1140
- }
1141
- }
1142
- if (image) {
1143
- const ensureImageLoaded = img => {
1144
- return ( new Promise((resolve, reject) => {
1145
- if (img.complete && img.naturalWidth > 0) {
1146
- resolve(img);
1147
- } else {
1148
- img.onload = () => resolve(img);
1149
- img.onerror = () => reject(( new Error("Failed to load image")));
1150
- setTimeout(() => reject(( new Error("Image load timeout"))), 5000);
1151
- }
1152
- }));
1153
- };
1154
- const imageToCopy = await ensureImageLoaded(image);
1155
- const clipboardData = {
1156
- "image/png": ( new Promise(resolve => {
1157
- const canvas = document.createElement("canvas");
1158
- canvas.width = imageToCopy.naturalWidth;
1159
- canvas.height = imageToCopy.naturalHeight;
1160
- const context = canvas.getContext("2d");
1161
- context.drawImage(imageToCopy, 0, 0);
1162
- canvas.toBlob(blob => {
1163
- if (blob) {
1164
- resolve(blob);
1165
- } else {
1166
- console.error("No blob data to write to clipboard");
1167
- }
1168
- canvas.remove();
1169
- }, "image/png");
1170
- }))
1171
- };
1172
- if (textAlternates) {
1173
- for (const alternate of textAlternates) {
1174
- clipboardData[alternate.mimeType] = alternate.content;
1175
- }
1176
- }
1177
- await navigator.clipboard.write([( new ClipboardItem(clipboardData))]);
1178
- } else {
1179
- console.error("Could not find image element to copy for output with id", outputId);
1180
- }
1181
- } catch (e) {
1182
- console.error("Could not copy image:", e);
1183
- }
1184
- };
1185
- window.addEventListener("message", async rawEvent => {
1186
- const event = rawEvent;
1187
- switch (event.data.type) {
1188
- case "initializeMarkup":
1189
- {
1190
- try {
1191
- await Promise.all(( event.data.cells.map(info => viewModel.ensureMarkupCell(info))));
1192
- } finally {
1193
- dimensionUpdater.updateImmediately();
1194
- postNotebookMessage("initializedMarkup", {
1195
- requestId: event.data.requestId
1196
- });
1197
- }
1198
- break;
1199
- }
1200
- case "createMarkupCell":
1201
- viewModel.ensureMarkupCell(event.data.cell);
1202
- break;
1203
- case "showMarkupCell":
1204
- viewModel.showMarkupCell(event.data.id, event.data.top, event.data.content, event.data.metadata);
1205
- break;
1206
- case "hideMarkupCells":
1207
- for (const id of event.data.ids) {
1208
- viewModel.hideMarkupCell(id);
1209
- }
1210
- break;
1211
- case "unhideMarkupCells":
1212
- for (const id of event.data.ids) {
1213
- viewModel.unhideMarkupCell(id);
1214
- }
1215
- break;
1216
- case "deleteMarkupCell":
1217
- for (const id of event.data.ids) {
1218
- viewModel.deleteMarkupCell(id);
1219
- }
1220
- break;
1221
- case "updateSelectedMarkupCells":
1222
- viewModel.updateSelectedCells(event.data.selectedCellIds);
1223
- break;
1224
- case "html":
1225
- {
1226
- const data = event.data;
1227
- if (data.createOnIdle) {
1228
- outputRunner.enqueueIdle(data.outputId, signal => {
1229
- return viewModel.renderOutputCell(data, signal);
1230
- });
1231
- } else {
1232
- outputRunner.enqueue(data.outputId, signal => {
1233
- return viewModel.renderOutputCell(data, signal);
1234
- });
1235
- }
1236
- break;
1237
- }
1238
- case "view-scroll":
1239
- {
1240
- event.data.widgets.forEach(widget => {
1241
- outputRunner.enqueue(widget.outputId, () => {
1242
- viewModel.updateOutputsScroll([widget]);
1243
- });
1244
- });
1245
- viewModel.updateMarkupScrolls(event.data.markupCells);
1246
- break;
1247
- }
1248
- case "clear":
1249
- renderers.clearAll();
1250
- viewModel.clearAll();
1251
- window.document.getElementById("container").innerText = "";
1252
- break;
1253
- case "clearOutput":
1254
- {
1255
- const {
1256
- cellId,
1257
- rendererId,
1258
- outputId
1259
- } = event.data;
1260
- outputRunner.cancelOutput(outputId);
1261
- viewModel.clearOutput(cellId, outputId, rendererId);
1262
- break;
1263
- }
1264
- case "hideOutput":
1265
- {
1266
- const {
1267
- cellId,
1268
- outputId
1269
- } = event.data;
1270
- outputRunner.enqueue(outputId, () => {
1271
- viewModel.hideOutput(cellId);
1272
- });
1273
- break;
1274
- }
1275
- case "showOutput":
1276
- {
1277
- const {
1278
- outputId,
1279
- cellTop,
1280
- cellId,
1281
- content
1282
- } = event.data;
1283
- outputRunner.enqueue(outputId, () => {
1284
- viewModel.showOutput(cellId, outputId, cellTop);
1285
- if (content) {
1286
- viewModel.updateAndRerender(cellId, outputId, content);
1287
- }
1288
- });
1289
- break;
1290
- }
1291
- case "copyImage":
1292
- {
1293
- await copyOutputImage(event.data.outputId, event.data.altOutputId, event.data.textAlternates);
1294
- break;
1295
- }
1296
- case "ack-dimension":
1297
- {
1298
- for (const {
1299
- cellId,
1300
- outputId,
1301
- height
1302
- } of event.data.updates) {
1303
- viewModel.updateOutputHeight(cellId, outputId, height);
1304
- }
1305
- break;
1306
- }
1307
- case "preload":
1308
- {
1309
- const resources = event.data.resources;
1310
- for (const {
1311
- uri
1312
- } of resources) {
1313
- kernelPreloads.load(uri);
1314
- }
1315
- break;
1316
- }
1317
- case "updateRenderers":
1318
- {
1319
- const {
1320
- rendererData
1321
- } = event.data;
1322
- renderers.updateRendererData(rendererData);
1323
- break;
1324
- }
1325
- case "focus-output":
1326
- focusFirstFocusableOrContainerInOutput(event.data.cellOrOutputId, event.data.alternateId);
1327
- break;
1328
- case "blur-output":
1329
- blurOutput();
1330
- break;
1331
- case "select-output-contents":
1332
- selectOutputContents(event.data.cellOrOutputId);
1333
- break;
1334
- case "select-input-contents":
1335
- selectInputContents(event.data.cellOrOutputId);
1336
- break;
1337
- case "decorations":
1338
- {
1339
- let outputContainer = window.document.getElementById(event.data.cellId);
1340
- if (!outputContainer) {
1341
- viewModel.ensureOutputCell(event.data.cellId, -1e5, true);
1342
- outputContainer = window.document.getElementById(event.data.cellId);
1343
- }
1344
- outputContainer?.classList.add(...event.data.addedClassNames);
1345
- outputContainer?.classList.remove(...event.data.removedClassNames);
1346
- break;
1347
- }
1348
- case "markupDecorations":
1349
- {
1350
- const markupCell = window.document.getElementById(event.data.cellId);
1351
- if (markupCell) {
1352
- markupCell?.classList.add(...event.data.addedClassNames);
1353
- markupCell?.classList.remove(...event.data.removedClassNames);
1354
- }
1355
- break;
1356
- }
1357
- case "customKernelMessage":
1358
- onDidReceiveKernelMessage.fire(event.data.message);
1359
- break;
1360
- case "customRendererMessage":
1361
- renderers.getRenderer(event.data.rendererId)?.receiveMessage(event.data.message);
1362
- break;
1363
- case "notebookStyles":
1364
- {
1365
- const documentStyle = window.document.documentElement.style;
1366
- for (let i = documentStyle.length - 1; i >= 0; i--) {
1367
- const property = documentStyle[i];
1368
- if (property && property.startsWith("--notebook-")) {
1369
- documentStyle.removeProperty(property);
1370
- }
1371
- }
1372
- for (const [name, value] of Object.entries(event.data.styles)) {
1373
- documentStyle.setProperty(`--${name}`, value);
1374
- }
1375
- break;
1376
- }
1377
- case "notebookOptions":
1378
- currentOptions = event.data.options;
1379
- viewModel.toggleDragDropEnabled(currentOptions.dragAndDropEnabled);
1380
- currentRenderOptions = event.data.renderOptions;
1381
- settingChange.fire(currentRenderOptions);
1382
- break;
1383
- case "tokenizedCodeBlock":
1384
- {
1385
- const {
1386
- codeBlockId,
1387
- html
1388
- } = event.data;
1389
- MarkdownCodeBlock.highlightCodeBlock(codeBlockId, html);
1390
- break;
1391
- }
1392
- case "tokenizedStylesChanged":
1393
- {
1394
- tokenizationStyle.replaceSync(event.data.css);
1395
- break;
1396
- }
1397
- case "find":
1398
- {
1399
- _highlighter.removeHighlights(event.data.options.ownerID);
1400
- find(event.data.query, event.data.options);
1401
- break;
1402
- }
1403
- case "findHighlightCurrent":
1404
- {
1405
- _highlighter?.highlightCurrentMatch(event.data.index, event.data.ownerID);
1406
- break;
1407
- }
1408
- case "findUnHighlightCurrent":
1409
- {
1410
- _highlighter?.unHighlightCurrentMatch(event.data.index, event.data.ownerID);
1411
- break;
1412
- }
1413
- case "findStop":
1414
- {
1415
- _highlighter.removeHighlights(event.data.ownerID);
1416
- break;
1417
- }
1418
- case "returnOutputItem":
1419
- {
1420
- outputItemRequests.resolveOutputItem(event.data.requestId, event.data.output);
1421
- }
1422
- }
1423
- });
1424
- const renderFallbackErrorName = "vscode.fallbackToNextRenderer";
1425
- class Renderer {
1426
- constructor(data) {
1427
- this.data = data;
1428
- this._onMessageEvent = createEmitter();
1429
- }
1430
- receiveMessage(message) {
1431
- this._onMessageEvent.fire(message);
1432
- }
1433
- async renderOutputItem(item, element, signal) {
1434
- try {
1435
- await this.load();
1436
- } catch (e) {
1437
- if (!signal.aborted) {
1438
- showRenderError(
1439
- `Error loading renderer '${this.data.id}'`,
1440
- element,
1441
- e instanceof Error ? [e] : []
1442
- );
1443
- }
1444
- return;
1445
- }
1446
- if (!this._api) {
1447
- if (!signal.aborted) {
1448
- showRenderError(
1449
- `Renderer '${this.data.id}' does not implement renderOutputItem`,
1450
- element,
1451
- []
1452
- );
1453
- }
1454
- return;
1455
- }
1456
- try {
1457
- const renderStart = performance.now();
1458
- await this._api.renderOutputItem(item, element, signal);
1459
- this.postDebugMessage("Rendered output item", {
1460
- id: item.id,
1461
- duration: `${performance.now() - renderStart}ms`
1462
- });
1463
- } catch (e) {
1464
- if (signal.aborted) {
1465
- return;
1466
- }
1467
- if (e instanceof Error && e.name === renderFallbackErrorName) {
1468
- throw e;
1469
- }
1470
- showRenderError(
1471
- `Error rendering output item using '${this.data.id}'`,
1472
- element,
1473
- e instanceof Error ? [e] : []
1474
- );
1475
- this.postDebugMessage("Rendering output item failed", {
1476
- id: item.id,
1477
- error: e + ""
1478
- });
1479
- }
1480
- }
1481
- disposeOutputItem(id) {
1482
- this._api?.disposeOutputItem?.(id);
1483
- }
1484
- createRendererContext() {
1485
- const {
1486
- id,
1487
- messaging
1488
- } = this.data;
1489
- const context = {
1490
- setState: newState => vscode.setState({
1491
- ...vscode.getState(),
1492
- [id]: newState
1493
- }),
1494
- getState: () => {
1495
- const state = vscode.getState();
1496
- return typeof state === "object" && state ? state[id] : undefined;
1497
- },
1498
- getRenderer: async id => {
1499
- const renderer = renderers.getRenderer(id);
1500
- if (!renderer) {
1501
- return undefined;
1502
- }
1503
- if (renderer._api) {
1504
- return renderer._api;
1505
- }
1506
- return renderer.load();
1507
- },
1508
- workspace: {
1509
- get isTrusted() {
1510
- return isWorkspaceTrusted;
1511
- }
1512
- },
1513
- settings: {
1514
- get lineLimit() {
1515
- return currentRenderOptions.lineLimit;
1516
- },
1517
- get outputScrolling() {
1518
- return currentRenderOptions.outputScrolling;
1519
- },
1520
- get outputWordWrap() {
1521
- return currentRenderOptions.outputWordWrap;
1522
- },
1523
- get linkifyFilePaths() {
1524
- return currentRenderOptions.linkifyFilePaths;
1525
- },
1526
- get minimalError() {
1527
- return currentRenderOptions.minimalError;
1528
- }
1529
- },
1530
- get onDidChangeSettings() {
1531
- return settingChange.event;
1532
- }
1533
- };
1534
- if (messaging) {
1535
- context.onDidReceiveMessage = this._onMessageEvent.event;
1536
- context.postMessage = message => postNotebookMessage("customRendererMessage", {
1537
- rendererId: id,
1538
- message
1539
- });
1540
- }
1541
- return ( Object.freeze(context));
1542
- }
1543
- load() {
1544
- this._loadPromise ??= this._load();
1545
- return this._loadPromise;
1546
- }
1547
- async _load() {
1548
- this.postDebugMessage("Start loading renderer");
1549
- try {
1550
- await kernelPreloads.waitForAllCurrent();
1551
- const importStart = performance.now();
1552
- const module = await __import(this.data.entrypoint.path);
1553
- this.postDebugMessage("Imported renderer", {
1554
- duration: `${performance.now() - importStart}ms`
1555
- });
1556
- if (!module) {
1557
- return;
1558
- }
1559
- this._api = await module.activate(this.createRendererContext());
1560
- this.postDebugMessage("Activated renderer", {
1561
- duration: `${performance.now() - importStart}ms`
1562
- });
1563
- const dependantRenderers = ctx.rendererData.filter(d => d.entrypoint.extends === this.data.id);
1564
- if (dependantRenderers.length) {
1565
- this.postDebugMessage("Activating dependant renderers", {
1566
- dependents: ( dependantRenderers.map(x => x.id)).join(", ")
1567
- });
1568
- }
1569
- await Promise.all(( dependantRenderers.map(async d => {
1570
- const renderer = renderers.getRenderer(d.id);
1571
- if (!renderer) {
1572
- throw ( new Error(`Could not find extending renderer: ${d.id}`));
1573
- }
1574
- try {
1575
- return await renderer.load();
1576
- } catch (e) {
1577
- console.error(e);
1578
- this.postDebugMessage("Activating dependant renderer failed", {
1579
- dependent: d.id,
1580
- error: e + ""
1581
- });
1582
- return undefined;
1583
- }
1584
- })));
1585
- return this._api;
1586
- } catch (e) {
1587
- this.postDebugMessage("Loading renderer failed");
1588
- throw e;
1589
- }
1590
- }
1591
- postDebugMessage(msg, data) {
1592
- postNotebookMessage("logRendererDebugMessage", {
1593
- message: `[renderer ${this.data.id}] - ${msg}`,
1594
- data
1595
- });
1596
- }
1597
- }
1598
- const kernelPreloads = new (class {
1599
- constructor() {
1600
- this.preloads = ( new Map());
1601
- }
1602
- waitFor(uri) {
1603
- return this.preloads.get(uri) || Promise.resolve(( new Error(`Preload not ready: ${uri}`)));
1604
- }
1605
- load(uri) {
1606
- const promise = Promise.all([runKernelPreload(uri), this.waitForAllCurrent()]);
1607
- this.preloads.set(uri, promise);
1608
- return promise;
1609
- }
1610
- waitForAllCurrent() {
1611
- return Promise.all(( [...( this.preloads.values())].map(p => p.catch(err => err))));
1612
- }
1613
- })();
1614
- const outputRunner = new (class {
1615
- constructor() {
1616
- this.outputs = ( new Map());
1617
- this.pendingOutputCreationRequest = ( new Map());
1618
- }
1619
- enqueue(outputId, action) {
1620
- this.pendingOutputCreationRequest.get(outputId)?.dispose();
1621
- this.pendingOutputCreationRequest.delete(outputId);
1622
- const record = this.outputs.get(outputId);
1623
- if (!record) {
1624
- const controller = ( new AbortController());
1625
- this.outputs.set(outputId, {
1626
- abort: controller,
1627
- queue: ( new Promise(r => r(action(controller.signal))))
1628
- });
1629
- } else {
1630
- record.queue = record.queue.then(async r => {
1631
- if (!record.abort.signal.aborted) {
1632
- await action(record.abort.signal);
1633
- }
1634
- });
1635
- }
1636
- }
1637
- enqueueIdle(outputId, action) {
1638
- this.pendingOutputCreationRequest.get(outputId)?.dispose();
1639
- outputRunner.pendingOutputCreationRequest.set(outputId, runWhenIdle(() => {
1640
- outputRunner.enqueue(outputId, action);
1641
- outputRunner.pendingOutputCreationRequest.delete(outputId);
1642
- }));
1643
- }
1644
- cancelAll() {
1645
- this.pendingOutputCreationRequest.forEach(r => r.dispose());
1646
- this.pendingOutputCreationRequest.clear();
1647
- for (const {
1648
- abort
1649
- } of ( this.outputs.values())) {
1650
- abort.abort();
1651
- }
1652
- this.outputs.clear();
1653
- }
1654
- cancelOutput(outputId) {
1655
- this.pendingOutputCreationRequest.get(outputId)?.dispose();
1656
- this.pendingOutputCreationRequest.delete(outputId);
1657
- const output = this.outputs.get(outputId);
1658
- if (output) {
1659
- output.abort.abort();
1660
- this.outputs.delete(outputId);
1661
- }
1662
- }
1663
- })();
1664
- const renderers = new (class {
1665
- constructor() {
1666
- this._renderers = ( new Map());
1667
- for (const renderer of ctx.rendererData) {
1668
- this.addRenderer(renderer);
1669
- }
1670
- }
1671
- getRenderer(id) {
1672
- return this._renderers.get(id);
1673
- }
1674
- rendererEqual(a, b) {
1675
- if (a.id !== b.id || a.entrypoint.path !== b.entrypoint.path || a.entrypoint.extends !== b.entrypoint.extends || a.messaging !== b.messaging) {
1676
- return false;
1677
- }
1678
- if (a.mimeTypes.length !== b.mimeTypes.length) {
1679
- return false;
1680
- }
1681
- for (let i = 0; i < a.mimeTypes.length; i++) {
1682
- if (a.mimeTypes[i] !== b.mimeTypes[i]) {
1683
- return false;
1684
- }
1685
- }
1686
- return true;
1687
- }
1688
- updateRendererData(rendererData) {
1689
- const oldKeys = ( new Set(( this._renderers.keys())));
1690
- const newKeys = ( new Set(( rendererData.map(d => d.id))));
1691
- for (const renderer of rendererData) {
1692
- const existing = this._renderers.get(renderer.id);
1693
- if (existing && this.rendererEqual(existing.data, renderer)) {
1694
- continue;
1695
- }
1696
- this.addRenderer(renderer);
1697
- }
1698
- for (const key of oldKeys) {
1699
- if (!( newKeys.has(key))) {
1700
- this._renderers.delete(key);
1701
- }
1702
- }
1703
- }
1704
- addRenderer(renderer) {
1705
- this._renderers.set(renderer.id, ( new Renderer(renderer)));
1706
- }
1707
- clearAll() {
1708
- outputRunner.cancelAll();
1709
- for (const renderer of ( this._renderers.values())) {
1710
- renderer.disposeOutputItem();
1711
- }
1712
- }
1713
- clearOutput(rendererId, outputId) {
1714
- outputRunner.cancelOutput(outputId);
1715
- this._renderers.get(rendererId)?.disposeOutputItem(outputId);
1716
- }
1717
- async render(item, preferredRendererId, element, signal) {
1718
- const primaryRenderer = this.findRenderer(preferredRendererId, item);
1719
- if (!primaryRenderer) {
1720
- const errorMessage = (window.document.documentElement.style.getPropertyValue("--notebook-cell-renderer-not-found-error") || "").replace("$0", () => item.mime);
1721
- this.showRenderError(item, element, errorMessage);
1722
- return;
1723
- }
1724
- if (!(await this._doRender(item, element, primaryRenderer, signal)).continue) {
1725
- return;
1726
- }
1727
- for (const additionalItemData of item._allOutputItems) {
1728
- if (additionalItemData.mime === item.mime) {
1729
- continue;
1730
- }
1731
- const additionalItem = await additionalItemData.getItem();
1732
- if (signal.aborted) {
1733
- return;
1734
- }
1735
- if (additionalItem) {
1736
- const renderer = this.findRenderer(undefined, additionalItem);
1737
- if (renderer) {
1738
- if (!(await this._doRender(additionalItem, element, renderer, signal)).continue) {
1739
- return;
1740
- }
1741
- }
1742
- }
1743
- }
1744
- const errorMessage = (window.document.documentElement.style.getPropertyValue("--notebook-cell-renderer-fallbacks-exhausted") || "").replace("$0", () => item.mime);
1745
- this.showRenderError(item, element, errorMessage);
1746
- }
1747
- async _doRender(item, element, renderer, signal) {
1748
- try {
1749
- await renderer.renderOutputItem(item, element, signal);
1750
- return {
1751
- continue: false
1752
- };
1753
- } catch (e) {
1754
- if (signal.aborted) {
1755
- return {
1756
- continue: false
1757
- };
1758
- }
1759
- if (e instanceof Error && e.name === renderFallbackErrorName) {
1760
- return {
1761
- continue: true
1762
- };
1763
- } else {
1764
- throw e;
1765
- }
1766
- }
1767
- }
1768
- findRenderer(preferredRendererId, info) {
1769
- let renderer;
1770
- if (typeof preferredRendererId === "string") {
1771
- renderer = Array.from(( this._renderers.values())).find(renderer => renderer.data.id === preferredRendererId);
1772
- } else {
1773
- const renderers = Array.from(( this._renderers.values())).filter(
1774
- renderer => renderer.data.mimeTypes.includes(info.mime) && !renderer.data.entrypoint.extends
1775
- );
1776
- if (renderers.length) {
1777
- renderers.sort((a, b) => +a.data.isBuiltin - +b.data.isBuiltin);
1778
- renderer = renderers[0];
1779
- }
1780
- }
1781
- return renderer;
1782
- }
1783
- showRenderError(info, element, errorMessage) {
1784
- const errorContainer = document.createElement("div");
1785
- const error = document.createElement("div");
1786
- error.className = "no-renderer-error";
1787
- error.innerText = errorMessage;
1788
- const cellText = document.createElement("div");
1789
- cellText.innerText = info.text();
1790
- errorContainer.appendChild(error);
1791
- errorContainer.appendChild(cellText);
1792
- element.innerText = "";
1793
- element.appendChild(errorContainer);
1794
- }
1795
- })();
1796
- const viewModel = new (class ViewModel {
1797
- constructor() {
1798
- this._markupCells = ( new Map());
1799
- this._outputCells = ( new Map());
1800
- }
1801
- clearAll() {
1802
- for (const cell of ( this._markupCells.values())) {
1803
- cell.dispose();
1804
- }
1805
- this._markupCells.clear();
1806
- for (const output of ( this._outputCells.values())) {
1807
- output.dispose();
1808
- }
1809
- this._outputCells.clear();
1810
- }
1811
- async createMarkupCell(init, top, visible) {
1812
- const existing = this._markupCells.get(init.cellId);
1813
- if (existing) {
1814
- console.error(`Trying to create markup that already exists: ${init.cellId}`);
1815
- return existing;
1816
- }
1817
- const cell = ( new MarkupCell(init.cellId, init.mime, init.content, top, init.metadata));
1818
- cell.element.style.visibility = visible ? "" : "hidden";
1819
- this._markupCells.set(init.cellId, cell);
1820
- await cell.ready;
1821
- return cell;
1822
- }
1823
- async ensureMarkupCell(info) {
1824
- let cell = this._markupCells.get(info.cellId);
1825
- if (cell) {
1826
- cell.element.style.visibility = info.visible ? "" : "hidden";
1827
- await cell.updateContentAndRender(info.content, info.metadata);
1828
- } else {
1829
- cell = await this.createMarkupCell(info, info.offset, info.visible);
1830
- }
1831
- }
1832
- deleteMarkupCell(id) {
1833
- const cell = this.getExpectedMarkupCell(id);
1834
- if (cell) {
1835
- cell.remove();
1836
- cell.dispose();
1837
- this._markupCells.delete(id);
1838
- }
1839
- }
1840
- async updateMarkupContent(id, newContent, metadata) {
1841
- const cell = this.getExpectedMarkupCell(id);
1842
- await cell?.updateContentAndRender(newContent, metadata);
1843
- }
1844
- showMarkupCell(id, top, newContent, metadata) {
1845
- const cell = this.getExpectedMarkupCell(id);
1846
- cell?.show(top, newContent, metadata);
1847
- }
1848
- hideMarkupCell(id) {
1849
- const cell = this.getExpectedMarkupCell(id);
1850
- cell?.hide();
1851
- }
1852
- unhideMarkupCell(id) {
1853
- const cell = this.getExpectedMarkupCell(id);
1854
- cell?.unhide();
1855
- }
1856
- getExpectedMarkupCell(id) {
1857
- const cell = this._markupCells.get(id);
1858
- if (!cell) {
1859
- console.log(`Could not find markup cell '${id}'`);
1860
- return undefined;
1861
- }
1862
- return cell;
1863
- }
1864
- updateSelectedCells(selectedCellIds) {
1865
- const selectedCellSet = ( new Set(selectedCellIds));
1866
- for (const cell of ( this._markupCells.values())) {
1867
- cell.setSelected(( selectedCellSet.has(cell.id)));
1868
- }
1869
- }
1870
- toggleDragDropEnabled(dragAndDropEnabled) {
1871
- for (const cell of ( this._markupCells.values())) {
1872
- cell.toggleDragDropEnabled(dragAndDropEnabled);
1873
- }
1874
- }
1875
- updateMarkupScrolls(markupCells) {
1876
- for (const {
1877
- id,
1878
- top
1879
- } of markupCells) {
1880
- const cell = this._markupCells.get(id);
1881
- if (cell) {
1882
- cell.element.style.top = `${top}px`;
1883
- }
1884
- }
1885
- }
1886
- async renderOutputCell(data, signal) {
1887
- const preloadErrors = await Promise.all(( data.requiredPreloads.map(p => kernelPreloads.waitFor(p.uri).then(() => undefined, err => err))));
1888
- if (signal.aborted) {
1889
- return;
1890
- }
1891
- const cellOutput = this.ensureOutputCell(data.cellId, data.cellTop, false);
1892
- return cellOutput.renderOutputElement(data, preloadErrors, signal);
1893
- }
1894
- ensureOutputCell(cellId, cellTop, skipCellTopUpdateIfExist) {
1895
- let cell = this._outputCells.get(cellId);
1896
- const existed = !!cell;
1897
- if (!cell) {
1898
- cell = ( new OutputCell(cellId));
1899
- this._outputCells.set(cellId, cell);
1900
- }
1901
- if (existed && skipCellTopUpdateIfExist) {
1902
- return cell;
1903
- }
1904
- cell.element.style.top = cellTop + "px";
1905
- return cell;
1906
- }
1907
- clearOutput(cellId, outputId, rendererId) {
1908
- const cell = this._outputCells.get(cellId);
1909
- cell?.clearOutput(outputId, rendererId);
1910
- }
1911
- showOutput(cellId, outputId, top) {
1912
- const cell = this._outputCells.get(cellId);
1913
- cell?.show(outputId, top);
1914
- }
1915
- updateAndRerender(cellId, outputId, content) {
1916
- const cell = this._outputCells.get(cellId);
1917
- cell?.updateContentAndRerender(outputId, content);
1918
- }
1919
- hideOutput(cellId) {
1920
- const cell = this._outputCells.get(cellId);
1921
- cell?.hide();
1922
- }
1923
- updateOutputHeight(cellId, outputId, height) {
1924
- const cell = this._outputCells.get(cellId);
1925
- cell?.updateOutputHeight(outputId, height);
1926
- }
1927
- updateOutputsScroll(updates) {
1928
- for (const request of updates) {
1929
- const cell = this._outputCells.get(request.cellId);
1930
- cell?.updateScroll(request);
1931
- }
1932
- }
1933
- })();
1934
- class MarkdownCodeBlock {
1935
- static {
1936
- this.pendingCodeBlocksToHighlight = ( new Map());
1937
- }
1938
- static highlightCodeBlock(id, html) {
1939
- const el = MarkdownCodeBlock.pendingCodeBlocksToHighlight.get(id);
1940
- if (!el) {
1941
- return;
1942
- }
1943
- const trustedHtml = ttPolicy?.createHTML(html) ?? html;
1944
- el.innerHTML = trustedHtml;
1945
- const root = el.getRootNode();
1946
- if (root instanceof ShadowRoot) {
1947
- if (!root.adoptedStyleSheets.includes(tokenizationStyle)) {
1948
- root.adoptedStyleSheets.push(tokenizationStyle);
1949
- }
1950
- }
1951
- }
1952
- static requestHighlightCodeBlock(root) {
1953
- const codeBlocks = [];
1954
- let i = 0;
1955
- for (const el of root.querySelectorAll(".vscode-code-block")) {
1956
- const lang = el.getAttribute("data-vscode-code-block-lang");
1957
- if (el.textContent && lang) {
1958
- const id = `${Date.now()}-${i++}`;
1959
- codeBlocks.push({
1960
- value: el.textContent,
1961
- lang: lang,
1962
- id
1963
- });
1964
- MarkdownCodeBlock.pendingCodeBlocksToHighlight.set(id, el);
1965
- }
1966
- }
1967
- return codeBlocks;
1968
- }
1969
- }
1970
- class MarkupCell {
1971
- constructor(id, mime, content, top, metadata) {
1972
- this._isDisposed = false;
1973
- const self = this;
1974
- this.id = id;
1975
- this._content = {
1976
- value: content,
1977
- version: 0,
1978
- metadata: metadata
1979
- };
1980
- const {
1981
- promise,
1982
- resolve,
1983
- reject
1984
- } = promiseWithResolvers();
1985
- this.ready = promise;
1986
- let cachedData;
1987
- this.outputItem = ( Object.freeze({
1988
- id,
1989
- mime,
1990
- get metadata() {
1991
- return self._content.metadata;
1992
- },
1993
- text: () => {
1994
- return this._content.value;
1995
- },
1996
- json: () => {
1997
- return undefined;
1998
- },
1999
- data: () => {
2000
- if (cachedData?.version === this._content.version) {
2001
- return cachedData.value;
2002
- }
2003
- const data = textEncoder.encode(this._content.value);
2004
- cachedData = {
2005
- version: this._content.version,
2006
- value: data
2007
- };
2008
- return data;
2009
- },
2010
- blob() {
2011
- return ( new Blob([this.data()], {
2012
- type: this.mime
2013
- }));
2014
- },
2015
- _allOutputItems: [{
2016
- mime,
2017
- getItem: async () => this.outputItem
2018
- }]
2019
- }));
2020
- const root = window.document.getElementById("container");
2021
- const markupCell = document.createElement("div");
2022
- markupCell.className = "markup";
2023
- markupCell.style.position = "absolute";
2024
- markupCell.style.width = "100%";
2025
- this.element = document.createElement("div");
2026
- this.element.id = this.id;
2027
- this.element.classList.add("preview");
2028
- this.element.style.position = "absolute";
2029
- this.element.style.top = top + "px";
2030
- this.toggleDragDropEnabled(currentOptions.dragAndDropEnabled);
2031
- markupCell.appendChild(this.element);
2032
- root.appendChild(markupCell);
2033
- this.addEventListeners();
2034
- this.updateContentAndRender(this._content.value, this._content.metadata).then(() => {
2035
- if (!this._isDisposed) {
2036
- resizeObserver.observe(this.element, this.id, false, this.id);
2037
- }
2038
- resolve();
2039
- }, () => reject());
2040
- }
2041
- dispose() {
2042
- this._isDisposed = true;
2043
- this.renderTaskAbort?.abort();
2044
- this.renderTaskAbort = undefined;
2045
- }
2046
- addEventListeners() {
2047
- this.element.addEventListener("dblclick", () => {
2048
- postNotebookMessage("toggleMarkupPreview", {
2049
- cellId: this.id
2050
- });
2051
- });
2052
- this.element.addEventListener("click", e => {
2053
- postNotebookMessage("clickMarkupCell", {
2054
- cellId: this.id,
2055
- altKey: e.altKey,
2056
- ctrlKey: e.ctrlKey,
2057
- metaKey: e.metaKey,
2058
- shiftKey: e.shiftKey
2059
- });
2060
- });
2061
- this.element.addEventListener("contextmenu", e => {
2062
- postNotebookMessage("contextMenuMarkupCell", {
2063
- cellId: this.id,
2064
- clientX: e.clientX,
2065
- clientY: e.clientY
2066
- });
2067
- });
2068
- this.element.addEventListener("mouseenter", () => {
2069
- postNotebookMessage("mouseEnterMarkupCell", {
2070
- cellId: this.id
2071
- });
2072
- });
2073
- this.element.addEventListener("mouseleave", () => {
2074
- postNotebookMessage("mouseLeaveMarkupCell", {
2075
- cellId: this.id
2076
- });
2077
- });
2078
- this.element.addEventListener("dragstart", e => {
2079
- markupCellDragManager.startDrag(e, this.id);
2080
- });
2081
- this.element.addEventListener("drag", e => {
2082
- markupCellDragManager.updateDrag(e, this.id);
2083
- });
2084
- this.element.addEventListener("dragend", e => {
2085
- markupCellDragManager.endDrag(e, this.id);
2086
- });
2087
- }
2088
- async updateContentAndRender(newContent, metadata) {
2089
- this._content = {
2090
- value: newContent,
2091
- version: this._content.version + 1,
2092
- metadata
2093
- };
2094
- this.renderTaskAbort?.abort();
2095
- const controller = ( new AbortController());
2096
- this.renderTaskAbort = controller;
2097
- try {
2098
- await renderers.render(this.outputItem, undefined, this.element, this.renderTaskAbort.signal);
2099
- } finally {
2100
- if (this.renderTaskAbort === controller) {
2101
- this.renderTaskAbort = undefined;
2102
- }
2103
- }
2104
- const root = (this.element.shadowRoot ?? this.element);
2105
- const html = [];
2106
- for (const child of root.children) {
2107
- switch (child.tagName) {
2108
- case "LINK":
2109
- case "SCRIPT":
2110
- case "STYLE":
2111
- break;
2112
- default:
2113
- html.push(child.outerHTML);
2114
- break;
2115
- }
2116
- }
2117
- const codeBlocks = MarkdownCodeBlock.requestHighlightCodeBlock(root);
2118
- postNotebookMessage("renderedMarkup", {
2119
- cellId: this.id,
2120
- html: html.join(""),
2121
- codeBlocks
2122
- });
2123
- dimensionUpdater.updateHeight(this.id, this.element.offsetHeight, {
2124
- isOutput: false
2125
- });
2126
- }
2127
- show(top, newContent, metadata) {
2128
- this.element.style.visibility = "";
2129
- this.element.style.top = `${top}px`;
2130
- if (typeof newContent === "string" || metadata) {
2131
- this.updateContentAndRender(newContent ?? this._content.value, metadata ?? this._content.metadata);
2132
- } else {
2133
- this.updateMarkupDimensions();
2134
- }
2135
- }
2136
- hide() {
2137
- this.element.style.visibility = "hidden";
2138
- }
2139
- unhide() {
2140
- this.element.style.visibility = "";
2141
- this.updateMarkupDimensions();
2142
- }
2143
- remove() {
2144
- this.element.remove();
2145
- }
2146
- async updateMarkupDimensions() {
2147
- dimensionUpdater.updateHeight(this.id, this.element.offsetHeight, {
2148
- isOutput: false
2149
- });
2150
- }
2151
- setSelected(selected) {
2152
- this.element.classList.toggle("selected", selected);
2153
- }
2154
- toggleDragDropEnabled(enabled) {
2155
- if (enabled) {
2156
- this.element.classList.add("draggable");
2157
- this.element.setAttribute("draggable", "true");
2158
- } else {
2159
- this.element.classList.remove("draggable");
2160
- this.element.removeAttribute("draggable");
2161
- }
2162
- }
2163
- }
2164
- class OutputCell {
2165
- constructor(cellId) {
2166
- this.outputElements = ( new Map());
2167
- const container = window.document.getElementById("container");
2168
- const upperWrapperElement = createFocusSink(cellId);
2169
- container.appendChild(upperWrapperElement);
2170
- this.element = document.createElement("div");
2171
- this.element.style.position = "absolute";
2172
- this.element.style.outline = "0";
2173
- this.element.id = cellId;
2174
- this.element.classList.add("cell_container");
2175
- container.appendChild(this.element);
2176
- this.element = this.element;
2177
- const lowerWrapperElement = createFocusSink(cellId, true);
2178
- container.appendChild(lowerWrapperElement);
2179
- }
2180
- dispose() {
2181
- for (const output of ( this.outputElements.values())) {
2182
- output.dispose();
2183
- }
2184
- this.outputElements.clear();
2185
- }
2186
- createOutputElement(data) {
2187
- let outputContainer = this.outputElements.get(data.outputId);
2188
- if (!outputContainer) {
2189
- outputContainer = ( new OutputContainer(data.outputId));
2190
- this.element.appendChild(outputContainer.element);
2191
- this.outputElements.set(data.outputId, outputContainer);
2192
- }
2193
- return outputContainer.createOutputElement(data.outputId, data.outputOffset, data.left, data.cellId);
2194
- }
2195
- async renderOutputElement(data, preloadErrors, signal) {
2196
- const startTime = Date.now();
2197
- const outputElement = this.createOutputElement(data);
2198
- await outputElement.render(data.content, data.rendererId, preloadErrors, signal);
2199
- outputElement .element.style.visibility = data.initiallyHidden ? "hidden" : "";
2200
- if (!!data.executionId && !!data.rendererId) {
2201
- let outputSize = undefined;
2202
- if (data.content.type === 1 ) {
2203
- outputSize = data.content.output.valueBytes.length;
2204
- }
2205
- if (outputSize !== undefined && outputSize > 0 && outputSize < 100 * 1024) {
2206
- postNotebookMessage("notebookPerformanceMessage", {
2207
- cellId: data.cellId,
2208
- executionId: data.executionId,
2209
- duration: Date.now() - startTime,
2210
- rendererId: data.rendererId,
2211
- outputSize
2212
- });
2213
- }
2214
- }
2215
- }
2216
- clearOutput(outputId, rendererId) {
2217
- const output = this.outputElements.get(outputId);
2218
- output?.clear(rendererId);
2219
- output?.dispose();
2220
- this.outputElements.delete(outputId);
2221
- }
2222
- show(outputId, top) {
2223
- const outputContainer = this.outputElements.get(outputId);
2224
- if (!outputContainer) {
2225
- return;
2226
- }
2227
- this.element.style.visibility = "";
2228
- this.element.style.top = `${top}px`;
2229
- }
2230
- hide() {
2231
- this.element.style.visibility = "hidden";
2232
- }
2233
- updateContentAndRerender(outputId, content) {
2234
- this.outputElements.get(outputId)?.updateContentAndRender(content);
2235
- }
2236
- updateOutputHeight(outputId, height) {
2237
- this.outputElements.get(outputId)?.updateHeight(height);
2238
- }
2239
- updateScroll(request) {
2240
- this.element.style.top = `${request.cellTop}px`;
2241
- const outputElement = this.outputElements.get(request.outputId);
2242
- if (outputElement) {
2243
- outputElement.updateScroll(request.outputOffset);
2244
- if (request.forceDisplay && outputElement.outputNode) {
2245
- outputElement.outputNode.element.style.visibility = "";
2246
- }
2247
- }
2248
- if (request.forceDisplay) {
2249
- this.element.style.visibility = "";
2250
- }
2251
- }
2252
- }
2253
- class OutputContainer {
2254
- get outputNode() {
2255
- return this._outputNode;
2256
- }
2257
- constructor(outputId) {
2258
- this.outputId = outputId;
2259
- this.element = document.createElement("div");
2260
- this.element.classList.add("output_container");
2261
- this.element.setAttribute("data-vscode-context", JSON.stringify({
2262
- "preventDefaultContextMenuItems": true
2263
- }));
2264
- this.element.style.position = "absolute";
2265
- this.element.style.overflow = "hidden";
2266
- }
2267
- dispose() {
2268
- this._outputNode?.dispose();
2269
- }
2270
- clear(rendererId) {
2271
- if (rendererId) {
2272
- renderers.clearOutput(rendererId, this.outputId);
2273
- }
2274
- this.element.remove();
2275
- }
2276
- updateHeight(height) {
2277
- this.element.style.maxHeight = `${height}px`;
2278
- this.element.style.height = `${height}px`;
2279
- }
2280
- updateScroll(outputOffset) {
2281
- this.element.style.top = `${outputOffset}px`;
2282
- }
2283
- createOutputElement(outputId, outputOffset, left, cellId) {
2284
- this.element.innerText = "";
2285
- this.element.style.maxHeight = "0px";
2286
- this.element.style.top = `${outputOffset}px`;
2287
- this._outputNode?.dispose();
2288
- this._outputNode = ( new OutputElement(outputId, left, cellId));
2289
- this.element.appendChild(this._outputNode.element);
2290
- return this._outputNode;
2291
- }
2292
- updateContentAndRender(content) {
2293
- this._outputNode?.updateAndRerender(content);
2294
- }
2295
- }
2296
- vscode.postMessage({
2297
- __vscode_notebook_message: true,
2298
- type: "initialized"
2299
- });
2300
- for (const preload of ctx.staticPreloadsData) {
2301
- kernelPreloads.load(preload.entrypoint);
2302
- }
2303
- function postNotebookMessage(type, properties) {
2304
- vscode.postMessage({
2305
- __vscode_notebook_message: true,
2306
- type,
2307
- ...properties
2308
- });
2309
- }
2310
- class OutputElement {
2311
- constructor(outputId, left, cellId) {
2312
- this.outputId = outputId;
2313
- this.cellId = cellId;
2314
- this.hasResizeObserver = false;
2315
- this.isImageOutput = false;
2316
- this.element = document.createElement("div");
2317
- this.element.id = outputId;
2318
- this.element.classList.add("output");
2319
- this.element.style.position = "absolute";
2320
- this.element.style.top = `0px`;
2321
- this.element.style.left = left + "px";
2322
- this.element.style.padding = `${ctx.style.outputNodePadding}px ${ctx.style.outputNodePadding}px ${ctx.style.outputNodePadding}px ${ctx.style.outputNodeLeftPadding}`;
2323
- this.element.addEventListener("mouseenter", () => {
2324
- postNotebookMessage("mouseenter", {
2325
- id: outputId
2326
- });
2327
- });
2328
- this.element.addEventListener("mouseleave", () => {
2329
- postNotebookMessage("mouseleave", {
2330
- id: outputId
2331
- });
2332
- });
2333
- this.element.addEventListener("dragstart", e => {
2334
- if (!e.dataTransfer) {
2335
- return;
2336
- }
2337
- const outputData = {
2338
- outputId: this.outputId
2339
- };
2340
- e.dataTransfer.setData("notebook-cell-output", JSON.stringify(outputData));
2341
- });
2342
- window.addEventListener("keydown", e => {
2343
- if (e.altKey) {
2344
- this.element.draggable = true;
2345
- }
2346
- });
2347
- window.addEventListener("keyup", e => {
2348
- if (!e.altKey) {
2349
- this.element.draggable = this.isImageOutput;
2350
- }
2351
- });
2352
- window.addEventListener("blur", () => {
2353
- this.element.draggable = this.isImageOutput;
2354
- });
2355
- }
2356
- dispose() {
2357
- this.renderTaskAbort?.abort();
2358
- this.renderTaskAbort = undefined;
2359
- }
2360
- async render(content, preferredRendererId, preloadErrors, signal) {
2361
- this.renderTaskAbort?.abort();
2362
- this.renderTaskAbort = undefined;
2363
- this._content = {
2364
- preferredRendererId,
2365
- preloadErrors
2366
- };
2367
- if (content.type === 0 ) {
2368
- const trustedHtml = ttPolicy?.createHTML(content.htmlContent) ?? content.htmlContent;
2369
- this.element.innerHTML = trustedHtml;
2370
- } else if (( preloadErrors.some(e => e instanceof Error))) {
2371
- const errors = preloadErrors.filter(e => e instanceof Error);
2372
- showRenderError(`Error loading preloads`, this.element, errors);
2373
- } else {
2374
- const imageMimeTypes = ["image/png", "image/jpeg", "image/svg"];
2375
- this.isImageOutput = imageMimeTypes.includes(content.output.mime);
2376
- this.element.draggable = this.isImageOutput;
2377
- const item = createOutputItem(
2378
- this.outputId,
2379
- content.output.mime,
2380
- content.metadata,
2381
- content.output.valueBytes,
2382
- content.allOutputs,
2383
- content.output.appended
2384
- );
2385
- const controller = ( new AbortController());
2386
- this.renderTaskAbort = controller;
2387
- signal?.addEventListener("abort", () => controller.abort());
2388
- try {
2389
- await renderers.render(item, preferredRendererId, this.element, controller.signal);
2390
- } finally {
2391
- if (this.renderTaskAbort === controller) {
2392
- this.renderTaskAbort = undefined;
2393
- }
2394
- }
2395
- }
2396
- if (!this.hasResizeObserver) {
2397
- this.hasResizeObserver = true;
2398
- resizeObserver.observe(this.element, this.outputId, true, this.cellId);
2399
- }
2400
- const offsetHeight = this.element.offsetHeight;
2401
- const cps = document.defaultView.getComputedStyle(this.element);
2402
- const verticalPadding = parseFloat(cps.paddingTop) + parseFloat(cps.paddingBottom);
2403
- const contentHeight = offsetHeight - verticalPadding;
2404
- if (elementHasContent(contentHeight) && cps.padding === "0px") {
2405
- dimensionUpdater.updateHeight(this.outputId, offsetHeight + ctx.style.outputNodePadding * 2, {
2406
- isOutput: true,
2407
- init: true
2408
- });
2409
- this.element.style.padding = `${ctx.style.outputNodePadding}px ${ctx.style.outputNodePadding}px ${ctx.style.outputNodePadding}px ${ctx.style.outputNodeLeftPadding}`;
2410
- } else if (elementHasContent(contentHeight)) {
2411
- dimensionUpdater.updateHeight(this.outputId, this.element.offsetHeight, {
2412
- isOutput: true,
2413
- init: true
2414
- });
2415
- this.element.style.padding = `0 ${ctx.style.outputNodePadding}px 0 ${ctx.style.outputNodeLeftPadding}`;
2416
- } else {
2417
- dimensionUpdater.updateHeight(this.outputId, 0, {
2418
- isOutput: true,
2419
- init: true
2420
- });
2421
- }
2422
- const root = this.element.shadowRoot ?? this.element;
2423
- const codeBlocks = MarkdownCodeBlock.requestHighlightCodeBlock(root);
2424
- if (codeBlocks.length > 0) {
2425
- postNotebookMessage("renderedCellOutput", {
2426
- codeBlocks
2427
- });
2428
- }
2429
- }
2430
- updateAndRerender(content) {
2431
- if (this._content) {
2432
- this.render(content, this._content.preferredRendererId, this._content.preloadErrors);
2433
- }
2434
- }
2435
- }
2436
- const markupCellDragManager = new (class MarkupCellDragManager {
2437
- constructor() {
2438
- window.document.addEventListener("dragover", e => {
2439
- e.preventDefault();
2440
- });
2441
- window.document.addEventListener("drop", e => {
2442
- e.preventDefault();
2443
- const drag = this.currentDrag;
2444
- if (!drag) {
2445
- return;
2446
- }
2447
- this.currentDrag = undefined;
2448
- postNotebookMessage("cell-drop", {
2449
- cellId: drag.cellId,
2450
- ctrlKey: e.ctrlKey,
2451
- altKey: e.altKey,
2452
- dragOffsetY: e.clientY
2453
- });
2454
- });
2455
- }
2456
- startDrag(e, cellId) {
2457
- if (!e.dataTransfer) {
2458
- return;
2459
- }
2460
- if (!currentOptions.dragAndDropEnabled) {
2461
- return;
2462
- }
2463
- this.currentDrag = {
2464
- cellId,
2465
- clientY: e.clientY
2466
- };
2467
- const overlayZIndex = 9999;
2468
- if (!this.dragOverlay) {
2469
- this.dragOverlay = document.createElement("div");
2470
- this.dragOverlay.style.position = "absolute";
2471
- this.dragOverlay.style.top = "0";
2472
- this.dragOverlay.style.left = "0";
2473
- this.dragOverlay.style.zIndex = `${overlayZIndex}`;
2474
- this.dragOverlay.style.width = "100%";
2475
- this.dragOverlay.style.height = "100%";
2476
- this.dragOverlay.style.background = "transparent";
2477
- window.document.body.appendChild(this.dragOverlay);
2478
- }
2479
- e.target.style.zIndex = `${overlayZIndex + 1}`;
2480
- e.target.classList.add("dragging");
2481
- postNotebookMessage("cell-drag-start", {
2482
- cellId: cellId,
2483
- dragOffsetY: e.clientY
2484
- });
2485
- const trySendDragUpdate = () => {
2486
- if (this.currentDrag?.cellId !== cellId) {
2487
- return;
2488
- }
2489
- postNotebookMessage("cell-drag", {
2490
- cellId: cellId,
2491
- dragOffsetY: this.currentDrag.clientY
2492
- });
2493
- window.requestAnimationFrame(trySendDragUpdate);
2494
- };
2495
- window.requestAnimationFrame(trySendDragUpdate);
2496
- }
2497
- updateDrag(e, cellId) {
2498
- if (cellId !== this.currentDrag?.cellId) {
2499
- this.currentDrag = undefined;
2500
- } else {
2501
- this.currentDrag = {
2502
- cellId,
2503
- clientY: e.clientY
2504
- };
2505
- }
2506
- }
2507
- endDrag(e, cellId) {
2508
- this.currentDrag = undefined;
2509
- e.target.classList.remove("dragging");
2510
- postNotebookMessage("cell-drag-end", {
2511
- cellId: cellId
2512
- });
2513
- if (this.dragOverlay) {
2514
- this.dragOverlay.remove();
2515
- this.dragOverlay = undefined;
2516
- }
2517
- e.target.style.zIndex = "";
2518
- }
2519
- })();
2520
- }
2521
- function preloadsScriptStr(
2522
- styleValues,
2523
- options,
2524
- renderOptions,
2525
- renderers,
2526
- preloads,
2527
- isWorkspaceTrusted,
2528
- nonce
2529
- ) {
2530
- const ctx = {
2531
- style: styleValues,
2532
- options,
2533
- renderOptions,
2534
- rendererData: renderers,
2535
- staticPreloadsData: preloads,
2536
- isWorkspaceTrusted,
2537
- nonce
2538
- };
2539
- return `
2540
- const __import = (x) => import(x);
2541
- (${webviewPreloads})(
2542
- JSON.parse(decodeURIComponent("${encodeURIComponent(JSON.stringify(ctx))}"))
2543
- )\n//# sourceURL=notebookWebviewPreloads.js\n`;
2544
- }
2545
-
2546
- export { preloadsScriptStr };