@pierre/diffs 1.5.2 → 1.6.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.
- package/README.md +4 -3
- package/dist/components/CodeView.d.ts +3 -2
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +24 -19
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +31 -9
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +176 -90
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +32 -9
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +225 -131
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts +6 -4
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/FileStream.js +49 -36
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +14 -4
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +35 -16
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +3 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +28 -20
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +3 -2
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +31 -24
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/constants.d.ts +4 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/editor/editor.d.ts +2 -1
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +5 -1
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/platform.d.ts +1 -1
- package/dist/editor/platform.js +5 -4
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +31 -6
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/tokenizer.d.ts +6 -4
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +25 -470
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/highlighter/DiffsEditorTokenizer.d.ts +16 -0
- package/dist/highlighter/DiffsEditorTokenizer.d.ts.map +1 -0
- package/dist/highlighter/DiffsEditorTokenizer.js +0 -0
- package/dist/highlighter/DiffsHighlighter.d.ts +41 -0
- package/dist/highlighter/DiffsHighlighter.d.ts.map +1 -0
- package/dist/highlighter/DiffsHighlighter.js +39 -0
- package/dist/highlighter/DiffsHighlighter.js.map +1 -0
- package/dist/highlighter/backends/highlights.d.ts +26 -0
- package/dist/highlighter/backends/highlights.d.ts.map +1 -0
- package/dist/highlighter/backends/highlights.js +71 -0
- package/dist/highlighter/backends/highlights.js.map +1 -0
- package/dist/highlighter/backends/shiki.d.ts +27 -0
- package/dist/highlighter/backends/shiki.d.ts.map +1 -0
- package/dist/highlighter/backends/shiki.js +107 -0
- package/dist/highlighter/backends/shiki.js.map +1 -0
- package/dist/highlighter/highlighterType.d.ts +13 -0
- package/dist/highlighter/highlighterType.d.ts.map +1 -0
- package/dist/highlighter/highlighterType.js +32 -0
- package/dist/highlighter/highlighterType.js.map +1 -0
- package/dist/highlighter/highlights-editor.d.ts +24 -0
- package/dist/highlighter/highlights-editor.d.ts.map +1 -0
- package/dist/highlighter/highlights-editor.js +166 -0
- package/dist/highlighter/highlights-editor.js.map +1 -0
- package/dist/highlighter/highlights-stream.d.ts +20 -0
- package/dist/highlighter/highlights-stream.d.ts.map +1 -0
- package/dist/highlighter/highlights-stream.js +93 -0
- package/dist/highlighter/highlights-stream.js.map +1 -0
- package/dist/highlighter/languages/areLanguagesAttached.d.ts +2 -1
- package/dist/highlighter/languages/areLanguagesAttached.d.ts.map +1 -1
- package/dist/highlighter/languages/areLanguagesAttached.js +4 -6
- package/dist/highlighter/languages/areLanguagesAttached.js.map +1 -1
- package/dist/highlighter/languages/attachResolvedLanguages.d.ts +6 -1
- package/dist/highlighter/languages/attachResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/attachResolvedLanguages.js +6 -11
- package/dist/highlighter/languages/attachResolvedLanguages.js.map +1 -1
- package/dist/highlighter/languages/constants.d.ts +1 -1
- package/dist/highlighter/languages/getResolvedLanguages.d.ts +1 -1
- package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts +1 -1
- package/dist/highlighter/languages/resolveLanguage.d.ts +1 -1
- package/dist/highlighter/languages/resolveLanguage.d.ts.map +1 -1
- package/dist/highlighter/languages/resolveLanguage.js +19 -16
- package/dist/highlighter/languages/resolveLanguage.js.map +1 -1
- package/dist/highlighter/languages/resolveLanguages.d.ts +1 -1
- package/dist/highlighter/shared_highlighter.d.ts +24 -9
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.js +59 -47
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/highlighter/shiki-editor.d.ts +25 -0
- package/dist/highlighter/shiki-editor.d.ts.map +1 -0
- package/dist/highlighter/shiki-editor.js +483 -0
- package/dist/highlighter/shiki-editor.js.map +1 -0
- package/dist/highlighter/shiki-stream.d.ts +20 -0
- package/dist/highlighter/shiki-stream.d.ts.map +1 -0
- package/dist/highlighter/shiki-stream.js +60 -0
- package/dist/highlighter/shiki-stream.js.map +1 -0
- package/dist/highlighter/stream-tokenizer.d.ts +40 -0
- package/dist/highlighter/stream-tokenizer.d.ts.map +1 -0
- package/dist/highlighter/stream-tokenizer.js +70 -0
- package/dist/highlighter/stream-tokenizer.js.map +1 -0
- package/dist/highlighter/themes/areThemesAttached.d.ts +3 -2
- package/dist/highlighter/themes/areThemesAttached.d.ts.map +1 -1
- package/dist/highlighter/themes/areThemesAttached.js +5 -4
- package/dist/highlighter/themes/areThemesAttached.js.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.d.ts +5 -2
- package/dist/highlighter/themes/attachResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.js +4 -16
- package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts +3 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.js +8 -5
- package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/createCSSVariablesTheme.d.ts +7 -0
- package/dist/highlighter/themes/createCSSVariablesTheme.d.ts.map +1 -0
- package/dist/highlighter/themes/createCSSVariablesTheme.js +89 -0
- package/dist/highlighter/themes/createCSSVariablesTheme.js.map +1 -0
- package/dist/highlighter/themes/createCachedLoader.d.ts +5 -0
- package/dist/highlighter/themes/createCachedLoader.d.ts.map +1 -0
- package/dist/highlighter/themes/createCachedLoader.js +15 -0
- package/dist/highlighter/themes/createCachedLoader.js.map +1 -0
- package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts +3 -2
- package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js +4 -4
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.d.ts +3 -2
- package/dist/highlighter/themes/getResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.js +4 -3
- package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.d.ts +2 -2
- package/dist/highlighter/themes/hasResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.js +4 -3
- package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +3 -3
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.js.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.d.ts +9 -4
- package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.js +8 -16
- package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveTheme.d.ts +3 -2
- package/dist/highlighter/themes/resolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveTheme.js +4 -7
- package/dist/highlighter/themes/resolveTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveThemes.d.ts +3 -2
- package/dist/highlighter/themes/resolveThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveThemes.js +4 -7
- package/dist/highlighter/themes/resolveThemes.js.map +1 -1
- package/dist/highlighter/themes/themeResolver.d.ts +10 -4
- package/dist/highlighter/themes/themeResolver.d.ts.map +1 -1
- package/dist/highlighter/themes/themeResolver.js +141 -2
- package/dist/highlighter/themes/themeResolver.js.map +1 -1
- package/dist/highlighter/themes/types.d.ts +23 -0
- package/dist/highlighter/themes/types.d.ts.map +1 -0
- package/dist/highlighter/themes/types.js +0 -0
- package/dist/highlighter/tokenizer-types.d.ts +35 -0
- package/dist/highlighter/tokenizer-types.d.ts.map +1 -0
- package/dist/highlighter/tokenizer-types.js +0 -0
- package/dist/highlighter/types.d.ts +55 -0
- package/dist/highlighter/types.d.ts.map +1 -0
- package/dist/highlighter/types.js +0 -0
- package/dist/index.d.ts +22 -13
- package/dist/index.js +21 -18
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +2 -2
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts +9 -1
- package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts.map +1 -1
- package/dist/react/CodeView.d.ts +4 -3
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +47 -38
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/File.js +3 -3
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.js +3 -3
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.js +2 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.js +3 -3
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.js +2 -2
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +9 -4
- package/dist/react/types.d.ts +4 -2
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +1 -1
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.js +1 -1
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +1 -0
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +29 -24
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +2 -0
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +38 -28
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useForceUpdate.d.ts +5 -0
- package/dist/react/utils/useForceUpdate.d.ts.map +1 -0
- package/dist/react/utils/useForceUpdate.js +27 -0
- package/dist/react/utils/useForceUpdate.js.map +1 -0
- package/dist/react/utils/useNextRenderData.d.ts +9 -0
- package/dist/react/utils/useNextRenderData.d.ts.map +1 -0
- package/dist/react/utils/useNextRenderData.js +9 -0
- package/dist/react/utils/useNextRenderData.js.map +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +26 -11
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +4 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +82 -43
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +6 -2
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +77 -43
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/shiki-stream/index.d.ts +3 -3
- package/dist/shiki-stream/index.js +1 -2
- package/dist/shiki-stream/stream.d.ts +4 -4
- package/dist/shiki-stream/stream.d.ts.map +1 -1
- package/dist/shiki-stream/stream.js +20 -9
- package/dist/shiki-stream/stream.js.map +1 -1
- package/dist/shiki-stream/types.d.ts +7 -38
- package/dist/shiki-stream/types.d.ts.map +1 -1
- package/dist/ssr/index.d.ts +7 -2
- package/dist/ssr/renderHTML.js +2 -2
- package/dist/ssr/renderHTML.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +20 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/canUseWASM.d.ts +13 -0
- package/dist/utils/canUseWASM.d.ts.map +1 -0
- package/dist/utils/canUseWASM.js +59 -0
- package/dist/utils/canUseWASM.js.map +1 -0
- package/dist/utils/createSpanNodeFromToken.d.ts +3 -2
- package/dist/utils/createSpanNodeFromToken.d.ts.map +1 -1
- package/dist/utils/createSpanNodeFromToken.js +4 -5
- package/dist/utils/createSpanNodeFromToken.js.map +1 -1
- package/dist/utils/cssWrappers.d.ts.map +1 -1
- package/dist/utils/cssWrappers.js +12 -0
- package/dist/utils/cssWrappers.js.map +1 -1
- package/dist/utils/getCodeViewItemRenderData.d.ts +10 -0
- package/dist/utils/getCodeViewItemRenderData.d.ts.map +1 -0
- package/dist/utils/getCodeViewItemRenderData.js +19 -0
- package/dist/utils/getCodeViewItemRenderData.js.map +1 -0
- package/dist/utils/getHighlighterOptions.d.ts.map +1 -1
- package/dist/utils/getHighlighterOptions.js +3 -2
- package/dist/utils/getHighlighterOptions.js.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.d.ts +2 -1
- package/dist/utils/getHighlighterThemeStyles.d.ts.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.js +13 -3
- package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
- package/dist/utils/getTokenOptions.d.ts +7 -0
- package/dist/utils/getTokenOptions.d.ts.map +1 -0
- package/dist/utils/getTokenOptions.js +16 -0
- package/dist/utils/getTokenOptions.js.map +1 -0
- package/dist/utils/hastToHtml.d.ts +10 -0
- package/dist/utils/hastToHtml.d.ts.map +1 -0
- package/dist/utils/hastToHtml.js +125 -0
- package/dist/utils/hastToHtml.js.map +1 -0
- package/dist/utils/hydratePartialDiff.js +4 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/parseDiffDecorations.d.ts +2 -1
- package/dist/utils/parseDiffDecorations.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.js +2 -0
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +24 -4
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts +3 -2
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +33 -48
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts +3 -2
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +10 -26
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/renderTokenLines.d.ts +22 -0
- package/dist/utils/renderTokenLines.d.ts.map +1 -0
- package/dist/utils/renderTokenLines.js +250 -0
- package/dist/utils/renderTokenLines.js.map +1 -0
- package/dist/utils/resolvePreferredHighlighter.d.ts +13 -0
- package/dist/utils/resolvePreferredHighlighter.d.ts.map +1 -0
- package/dist/utils/resolvePreferredHighlighter.js +11 -0
- package/dist/utils/resolvePreferredHighlighter.js.map +1 -0
- package/dist/utils/resolveRegion.js +20 -10
- package/dist/utils/resolveRegion.js.map +1 -1
- package/dist/utils/setDeferredArrayItem.d.ts +5 -0
- package/dist/utils/setDeferredArrayItem.d.ts.map +1 -0
- package/dist/utils/setDeferredArrayItem.js +39 -0
- package/dist/utils/setDeferredArrayItem.js.map +1 -0
- package/dist/utils/tokenStyle.d.ts +11 -0
- package/dist/utils/tokenStyle.d.ts.map +1 -0
- package/dist/utils/tokenStyle.js +32 -0
- package/dist/utils/tokenStyle.js.map +1 -0
- package/dist/utils/tokensToHtml.d.ts +11 -0
- package/dist/utils/tokensToHtml.d.ts.map +1 -0
- package/dist/utils/tokensToHtml.js +48 -0
- package/dist/utils/tokensToHtml.js.map +1 -0
- package/dist/utils/updateDiffHunks.d.ts +2 -2
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +7 -3
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/utils/wrapTokenFragments.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +14 -2
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +155 -67
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/hastLinesTransport.d.ts +14 -0
- package/dist/worker/hastLinesTransport.d.ts.map +1 -0
- package/dist/worker/hastLinesTransport.js +156 -0
- package/dist/worker/hastLinesTransport.js.map +1 -0
- package/dist/worker/highlights-CpZm9DAR.js +317 -0
- package/dist/worker/highlights-CpZm9DAR.js.map +1 -0
- package/dist/worker/index.d.ts +1 -1
- package/dist/worker/shiki-Ci4cdHsM.js +697 -0
- package/dist/worker/shiki-Ci4cdHsM.js.map +1 -0
- package/dist/worker/stream-tokenizer-DK9xp5M5.js +427 -0
- package/dist/worker/stream-tokenizer-DK9xp5M5.js.map +1 -0
- package/dist/worker/types.d.ts +16 -3
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +41 -13337
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +681 -349
- package/dist/worker/worker.js.map +1 -1
- package/dist/worker/workerMessage.d.ts +24 -0
- package/dist/worker/workerMessage.d.ts.map +1 -0
- package/dist/worker/workerMessage.js +0 -0
- package/package.json +5 -3
- package/dist/highlighter/themes/constants.d.ts +0 -5
- package/dist/highlighter/themes/constants.d.ts.map +0 -1
- package/dist/highlighter/themes/constants.js +0 -6
- package/dist/highlighter/themes/constants.js.map +0 -1
- package/dist/highlighter/themes/themeResolution.d.ts +0 -7
- package/dist/highlighter/themes/themeResolution.d.ts.map +0 -1
- package/dist/highlighter/themes/themeResolution.js +0 -21
- package/dist/highlighter/themes/themeResolution.js.map +0 -1
- package/dist/shiki-stream/tokenizer.d.ts +0 -23
- package/dist/shiki-stream/tokenizer.d.ts.map +0 -1
- package/dist/shiki-stream/tokenizer.js +0 -72
- package/dist/shiki-stream/tokenizer.js.map +0 -1
- package/dist/utils/createTransformerWithState.d.ts +0 -12
- package/dist/utils/createTransformerWithState.d.ts.map +0 -1
- package/dist/utils/createTransformerWithState.js +0 -89
- package/dist/utils/createTransformerWithState.js.map +0 -1
- package/dist/worker/wasm-B9ZqxnKj.js +0 -8
- package/dist/worker/wasm-B9ZqxnKj.js.map +0 -1
package/dist/worker/worker.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { createHighlighterCore } from "shiki/core";
|
|
2
|
-
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
3
|
-
import { createOnigurumaEngine } from "shiki/engine/oniguruma";
|
|
4
|
-
import { createThemeResolver } from "@pierre/theming";
|
|
5
1
|
import { diffChars, diffWordsWithSpace } from "diff";
|
|
6
|
-
import { transformerStyleToClass } from "@shikijs/transformers";
|
|
7
2
|
import { normalizeThemeColors } from "@pierre/theming/color";
|
|
8
3
|
(() => {
|
|
9
4
|
try {
|
|
@@ -20,55 +15,82 @@ Object.freeze({
|
|
|
20
15
|
fromStart: 0,
|
|
21
16
|
fromEnd: 0
|
|
22
17
|
});
|
|
18
|
+
Object.freeze([]);
|
|
23
19
|
//#endregion
|
|
24
20
|
//#region src/highlighter/languages/constants.ts
|
|
25
21
|
const ResolvedLanguages = /* @__PURE__ */ new Map();
|
|
22
|
+
const ResolvingLanguages = /* @__PURE__ */ new Map();
|
|
23
|
+
const RegisteredCustomLanguages = /* @__PURE__ */ new Map();
|
|
26
24
|
const AttachedLanguages = /* @__PURE__ */ new Set();
|
|
27
25
|
//#endregion
|
|
28
26
|
//#region src/highlighter/languages/attachResolvedLanguages.ts
|
|
27
|
+
/**
|
|
28
|
+
* Record resolved grammars in the shared language cache and attach them to a
|
|
29
|
+
* highlighter. Highlights bundles its lexers and ignores the grammars.
|
|
30
|
+
*/
|
|
29
31
|
function attachResolvedLanguages(resolvedLanguages, highlighter) {
|
|
30
|
-
|
|
31
|
-
for (const resolvedLang of resolvedLanguages) {
|
|
32
|
-
if (AttachedLanguages.has(resolvedLang.name)) continue;
|
|
32
|
+
for (const resolvedLang of Array.isArray(resolvedLanguages) ? resolvedLanguages : [resolvedLanguages]) {
|
|
33
33
|
let lang = ResolvedLanguages.get(resolvedLang.name);
|
|
34
34
|
if (lang == null) {
|
|
35
35
|
lang = resolvedLang;
|
|
36
36
|
ResolvedLanguages.set(resolvedLang.name, lang);
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
if (grammar == null) throw new Error(`attachResolvedLanguages: No returned grammar declares "${lang.name}" as its name or an alias.`);
|
|
40
|
-
highlighter.loadLanguageSync(lang.data);
|
|
41
|
-
try {
|
|
42
|
-
highlighter.getLanguage(lang.name);
|
|
43
|
-
} catch {
|
|
44
|
-
throw new Error(`attachResolvedLanguages: "${grammar.name}" is already loaded without alias "${lang.name}". Load the alias first or give the grammar a unique name.`);
|
|
45
|
-
}
|
|
38
|
+
highlighter.attachLanguages([lang]);
|
|
46
39
|
AttachedLanguages.add(lang.name);
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
42
|
//#endregion
|
|
50
|
-
//#region src/highlighter/
|
|
51
|
-
|
|
43
|
+
//#region src/highlighter/highlighterType.ts
|
|
44
|
+
let activeType;
|
|
45
|
+
let holds = 0;
|
|
46
|
+
var HighlighterDisposedError = class extends Error {
|
|
47
|
+
constructor() {
|
|
48
|
+
super("Highlighter is disposed");
|
|
49
|
+
this.name = "HighlighterDisposedError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function resolveHighlighterType(type) {
|
|
53
|
+
return type ?? activeType ?? "shiki-js";
|
|
54
|
+
}
|
|
55
|
+
function assertHighlighterType(type) {
|
|
56
|
+
if (activeType != null && activeType !== type) throw new Error(`Cannot load the "${type}" highlighter while "${activeType}" is in use. Only one highlighter type can be active at a time; dispose every "${activeType}" instance (disposeHighlighter() disposes the shared one) before switching.`);
|
|
57
|
+
}
|
|
58
|
+
function acquireHighlighterType(type) {
|
|
59
|
+
assertHighlighterType(type);
|
|
60
|
+
activeType = type;
|
|
61
|
+
holds++;
|
|
62
|
+
}
|
|
63
|
+
function releaseHighlighterType() {
|
|
64
|
+
holds--;
|
|
65
|
+
if (holds === 0) activeType = void 0;
|
|
66
|
+
}
|
|
52
67
|
//#endregion
|
|
53
|
-
//#region src/highlighter/
|
|
54
|
-
|
|
68
|
+
//#region src/highlighter/shared_highlighter.ts
|
|
69
|
+
/**
|
|
70
|
+
* Creates an instance the caller must dispose. Defaults to the active type
|
|
71
|
+
* or DEFAULT_HIGHLIGHTER; rejects if a different type is already active.
|
|
72
|
+
*/
|
|
73
|
+
async function createHighlighter(type) {
|
|
74
|
+
const resolvedType = resolveHighlighterType(type);
|
|
75
|
+
acquireHighlighterType(resolvedType);
|
|
76
|
+
try {
|
|
77
|
+
if (resolvedType === "highlights") {
|
|
78
|
+
const { HighlightsHighlighter } = await import("./highlights-CpZm9DAR.js");
|
|
79
|
+
return new HighlightsHighlighter();
|
|
80
|
+
}
|
|
81
|
+
const { ShikiHighlighter } = await import("./shiki-Ci4cdHsM.js");
|
|
82
|
+
return await ShikiHighlighter.create(resolvedType);
|
|
83
|
+
} finally {
|
|
84
|
+
releaseHighlighterType();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
55
87
|
//#endregion
|
|
56
88
|
//#region src/highlighter/themes/attachResolvedThemes.ts
|
|
89
|
+
/** Seed themes received from the main thread into the worker's backend resolver. */
|
|
57
90
|
function attachResolvedThemes(themes, highlighter) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (typeof themeRef === "string") {
|
|
62
|
-
resolvedTheme = themeResolver.getResolvedTheme(themeRef);
|
|
63
|
-
if (resolvedTheme == null) throw new Error(`loadResolvedThemes: ${themeRef} is not resolved, you must resolve it before calling loadResolvedThemes`);
|
|
64
|
-
} else {
|
|
65
|
-
resolvedTheme = themeRef;
|
|
66
|
-
themeRef = themeRef.name;
|
|
67
|
-
if (themeResolver.getResolvedTheme(themeRef) == null) themeResolver.seedResolvedTheme(themeRef, resolvedTheme);
|
|
68
|
-
}
|
|
69
|
-
if (AttachedThemes.has(themeRef)) continue;
|
|
70
|
-
AttachedThemes.add(themeRef);
|
|
71
|
-
highlighter.loadThemeSync(resolvedTheme);
|
|
91
|
+
for (const theme of Array.isArray(themes) ? themes : [themes]) {
|
|
92
|
+
const resolved = typeof theme === "string" ? highlighter.themeResolver.getResolvedThemes([theme])[0] : theme;
|
|
93
|
+
highlighter.themeResolver.seedResolvedTheme(resolved.name, resolved);
|
|
72
94
|
}
|
|
73
95
|
}
|
|
74
96
|
//#endregion
|
|
@@ -478,210 +500,6 @@ function cleanLastNewline(contents) {
|
|
|
478
500
|
return contents.slice(0, end);
|
|
479
501
|
}
|
|
480
502
|
//#endregion
|
|
481
|
-
//#region src/utils/hast_utils.ts
|
|
482
|
-
function createTextNodeElement(value) {
|
|
483
|
-
return {
|
|
484
|
-
type: "text",
|
|
485
|
-
value
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
function createHastElement({ tagName, children = [], properties = {} }) {
|
|
489
|
-
return {
|
|
490
|
-
type: "element",
|
|
491
|
-
tagName,
|
|
492
|
-
properties,
|
|
493
|
-
children
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
function findCodeElement(nodes) {
|
|
497
|
-
let firstChild = nodes.children[0];
|
|
498
|
-
while (firstChild != null) {
|
|
499
|
-
if (firstChild.type === "element" && firstChild.tagName === "code") return firstChild;
|
|
500
|
-
if ("children" in firstChild) firstChild = firstChild.children[0];
|
|
501
|
-
else firstChild = null;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
//#endregion
|
|
505
|
-
//#region src/utils/processLine.ts
|
|
506
|
-
function processLine(node, line, state) {
|
|
507
|
-
const lineInfo = typeof state.lineInfo === "function" ? state.lineInfo(line) : state.lineInfo[line - 1];
|
|
508
|
-
if (lineInfo == null) {
|
|
509
|
-
const errorMessage = `processLine: line ${line}, contains no state.lineInfo`;
|
|
510
|
-
console.error(errorMessage, {
|
|
511
|
-
node,
|
|
512
|
-
line,
|
|
513
|
-
state
|
|
514
|
-
});
|
|
515
|
-
throw new Error(errorMessage);
|
|
516
|
-
}
|
|
517
|
-
node.tagName = "div";
|
|
518
|
-
node.properties["data-line"] = lineInfo.lineNumber;
|
|
519
|
-
node.properties["data-alt-line"] = lineInfo.altLineNumber;
|
|
520
|
-
node.properties["data-line-type"] = lineInfo.type;
|
|
521
|
-
node.properties["data-line-index"] = lineInfo.lineIndex;
|
|
522
|
-
if (node.children.length === 0) node.children.push(createTextNodeElement("\n"));
|
|
523
|
-
return node;
|
|
524
|
-
}
|
|
525
|
-
//#endregion
|
|
526
|
-
//#region src/utils/wrapTokenFragments.ts
|
|
527
|
-
const NO_TOKEN = Symbol("no-token");
|
|
528
|
-
const MULTIPLE_TOKENS = Symbol("multiple-tokens");
|
|
529
|
-
function wrapTokenFragments(container) {
|
|
530
|
-
const ownTokenChar = getTokenChar(container);
|
|
531
|
-
if (ownTokenChar != null) return ownTokenChar;
|
|
532
|
-
let containerTokenState = NO_TOKEN;
|
|
533
|
-
const wrappedChildren = [];
|
|
534
|
-
let currentTokenChildren = [];
|
|
535
|
-
let currentTokenChar;
|
|
536
|
-
const flushTokenChildren = () => {
|
|
537
|
-
if (currentTokenChildren.length === 0 || currentTokenChar == null) {
|
|
538
|
-
currentTokenChildren = [];
|
|
539
|
-
currentTokenChar = void 0;
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
if (currentTokenChildren.length === 1) {
|
|
543
|
-
const child = currentTokenChildren[0];
|
|
544
|
-
if (child?.type === "element") {
|
|
545
|
-
setTokenChar(child, currentTokenChar);
|
|
546
|
-
for (const grandChild of child.children) stripTokenChar(grandChild);
|
|
547
|
-
} else stripTokenChar(child);
|
|
548
|
-
wrappedChildren.push(child);
|
|
549
|
-
currentTokenChildren = [];
|
|
550
|
-
currentTokenChar = void 0;
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
for (const child of currentTokenChildren) stripTokenChar(child);
|
|
554
|
-
wrappedChildren.push(createHastElement({
|
|
555
|
-
tagName: "span",
|
|
556
|
-
properties: { "data-char": currentTokenChar },
|
|
557
|
-
children: currentTokenChildren
|
|
558
|
-
}));
|
|
559
|
-
currentTokenChildren = [];
|
|
560
|
-
currentTokenChar = void 0;
|
|
561
|
-
};
|
|
562
|
-
const mergeContainerTokenState = (childTokenState) => {
|
|
563
|
-
if (childTokenState === NO_TOKEN) return;
|
|
564
|
-
if (childTokenState === MULTIPLE_TOKENS) {
|
|
565
|
-
containerTokenState = MULTIPLE_TOKENS;
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
if (containerTokenState === NO_TOKEN) {
|
|
569
|
-
containerTokenState = childTokenState;
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
if (containerTokenState !== childTokenState) containerTokenState = MULTIPLE_TOKENS;
|
|
573
|
-
};
|
|
574
|
-
for (const child of container.children) {
|
|
575
|
-
const childTokenState = child.type === "element" ? wrapTokenFragments(child) : NO_TOKEN;
|
|
576
|
-
mergeContainerTokenState(childTokenState);
|
|
577
|
-
if (typeof childTokenState !== "number") {
|
|
578
|
-
flushTokenChildren();
|
|
579
|
-
wrappedChildren.push(child);
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
if (currentTokenChar != null && currentTokenChar !== childTokenState) flushTokenChildren();
|
|
583
|
-
currentTokenChar ??= childTokenState;
|
|
584
|
-
currentTokenChildren.push(child);
|
|
585
|
-
}
|
|
586
|
-
flushTokenChildren();
|
|
587
|
-
container.children = wrappedChildren;
|
|
588
|
-
return containerTokenState;
|
|
589
|
-
}
|
|
590
|
-
function getTokenChar(node) {
|
|
591
|
-
const value = node.properties["data-char"];
|
|
592
|
-
if (typeof value === "number") return value;
|
|
593
|
-
}
|
|
594
|
-
function stripTokenChar(node) {
|
|
595
|
-
if (node.type !== "element") return;
|
|
596
|
-
node.properties["data-char"] = void 0;
|
|
597
|
-
for (const child of node.children) stripTokenChar(child);
|
|
598
|
-
}
|
|
599
|
-
function setTokenChar(node, char) {
|
|
600
|
-
node.properties["data-char"] = char;
|
|
601
|
-
}
|
|
602
|
-
//#endregion
|
|
603
|
-
//#region src/utils/createTransformerWithState.ts
|
|
604
|
-
function createTransformerWithState(useTokenTransformer = false, useCSSClasses = false) {
|
|
605
|
-
const state = { lineInfo: [] };
|
|
606
|
-
const transformers = [{
|
|
607
|
-
line(node) {
|
|
608
|
-
delete node.properties.class;
|
|
609
|
-
return node;
|
|
610
|
-
},
|
|
611
|
-
pre(pre) {
|
|
612
|
-
const code = findCodeElement(pre);
|
|
613
|
-
const children = [];
|
|
614
|
-
if (code != null) {
|
|
615
|
-
let index = 1;
|
|
616
|
-
for (const node of code.children) {
|
|
617
|
-
if (node.type !== "element") continue;
|
|
618
|
-
if (useTokenTransformer) wrapTokenFragments(node);
|
|
619
|
-
children.push(processLine(node, index, state));
|
|
620
|
-
index++;
|
|
621
|
-
}
|
|
622
|
-
code.children = children;
|
|
623
|
-
}
|
|
624
|
-
return pre;
|
|
625
|
-
},
|
|
626
|
-
...useTokenTransformer ? {
|
|
627
|
-
tokens(lines) {
|
|
628
|
-
for (const line of lines) {
|
|
629
|
-
let col = 0;
|
|
630
|
-
for (const token of line) {
|
|
631
|
-
const tokenWithOriginalRange = token;
|
|
632
|
-
tokenWithOriginalRange.__lineChar ??= col;
|
|
633
|
-
col += token.content.length;
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
},
|
|
637
|
-
preprocess(_code, options) {
|
|
638
|
-
options.mergeWhitespaces = "never";
|
|
639
|
-
},
|
|
640
|
-
span(hast, _line, _char, _lineElement, token) {
|
|
641
|
-
if (token?.offset != null && token.content != null) {
|
|
642
|
-
const tokenChar = token.__lineChar;
|
|
643
|
-
if (tokenChar != null) hast.properties["data-char"] = tokenChar;
|
|
644
|
-
return hast;
|
|
645
|
-
}
|
|
646
|
-
return hast;
|
|
647
|
-
}
|
|
648
|
-
} : null
|
|
649
|
-
}];
|
|
650
|
-
if (useCSSClasses) transformers.push(tokenStyleNormalizer, toClass);
|
|
651
|
-
if (useTokenTransformer) transformers.push({ line: (node) => {
|
|
652
|
-
if (node.type === "element" && node.children.length === 0) node.children.push({
|
|
653
|
-
type: "element",
|
|
654
|
-
tagName: "br",
|
|
655
|
-
properties: {},
|
|
656
|
-
children: []
|
|
657
|
-
});
|
|
658
|
-
return node;
|
|
659
|
-
} });
|
|
660
|
-
return {
|
|
661
|
-
state,
|
|
662
|
-
transformers,
|
|
663
|
-
toClass
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
const toClass = transformerStyleToClass({ classPrefix: "hl-" });
|
|
667
|
-
const tokenStyleNormalizer = {
|
|
668
|
-
name: "token-style-normalizer",
|
|
669
|
-
tokens(lines) {
|
|
670
|
-
for (const line of lines) for (const token of line) {
|
|
671
|
-
if (token.htmlStyle != null) continue;
|
|
672
|
-
const style = {};
|
|
673
|
-
if (token.color != null) style.color = token.color;
|
|
674
|
-
if (token.bgColor != null) style["background-color"] = token.bgColor;
|
|
675
|
-
if (token.fontStyle != null && token.fontStyle !== 0) {
|
|
676
|
-
if ((token.fontStyle & 1) !== 0) style["font-style"] = "italic";
|
|
677
|
-
if ((token.fontStyle & 2) !== 0) style["font-weight"] = "bold";
|
|
678
|
-
if ((token.fontStyle & 4) !== 0) style["text-decoration"] = "underline";
|
|
679
|
-
}
|
|
680
|
-
if (Object.keys(style).length > 0) token.htmlStyle = style;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
};
|
|
684
|
-
//#endregion
|
|
685
503
|
//#region src/utils/formatCSSVariablePrefix.ts
|
|
686
504
|
function formatCSSVariablePrefix(type) {
|
|
687
505
|
return `--${type === "token" ? "diffs-token" : "diffs"}-`;
|
|
@@ -692,7 +510,7 @@ function getHighlighterThemeStyles({ theme = DEFAULT_THEMES, highlighter, prefix
|
|
|
692
510
|
let styles = "";
|
|
693
511
|
if (typeof theme === "string") {
|
|
694
512
|
const themeData = highlighter.getTheme(theme);
|
|
695
|
-
const normalized =
|
|
513
|
+
const normalized = getThemeColors(themeData, highlighter);
|
|
696
514
|
styles += `color:${normalized.fg};`;
|
|
697
515
|
styles += `background-color:${normalized.bg};`;
|
|
698
516
|
styles += `${formatCSSVariablePrefix("global")}fg:${normalized.fg};`;
|
|
@@ -700,18 +518,28 @@ function getHighlighterThemeStyles({ theme = DEFAULT_THEMES, highlighter, prefix
|
|
|
700
518
|
styles += getGitVariables(themeData, prefix);
|
|
701
519
|
} else {
|
|
702
520
|
let themeData = highlighter.getTheme(theme.dark);
|
|
703
|
-
let normalized =
|
|
521
|
+
let normalized = getThemeColors(themeData, highlighter);
|
|
704
522
|
styles += `${formatCSSVariablePrefix("global")}dark:${normalized.fg};`;
|
|
705
523
|
styles += `${formatCSSVariablePrefix("global")}dark-bg:${normalized.bg};`;
|
|
706
524
|
styles += getGitVariables(themeData, "dark");
|
|
707
525
|
themeData = highlighter.getTheme(theme.light);
|
|
708
|
-
normalized =
|
|
526
|
+
normalized = getThemeColors(themeData, highlighter);
|
|
709
527
|
styles += `${formatCSSVariablePrefix("global")}light:${normalized.fg};`;
|
|
710
528
|
styles += `${formatCSSVariablePrefix("global")}light-bg:${normalized.bg};`;
|
|
711
529
|
styles += getGitVariables(themeData, "light");
|
|
712
530
|
}
|
|
713
531
|
return styles;
|
|
714
532
|
}
|
|
533
|
+
function getThemeColors(theme, highlighter) {
|
|
534
|
+
if (highlighter.name === "highlights" && theme.zed?.cssVariables === true) {
|
|
535
|
+
const prefix = formatCSSVariablePrefix("token");
|
|
536
|
+
return {
|
|
537
|
+
fg: `var(${prefix}foreground)`,
|
|
538
|
+
bg: `var(${prefix}background)`
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
return normalizeThemeColors(theme);
|
|
542
|
+
}
|
|
715
543
|
function getGitVariables(themeData, modePrefix) {
|
|
716
544
|
modePrefix = modePrefix != null ? `${modePrefix}-` : "";
|
|
717
545
|
let styles = "";
|
|
@@ -724,16 +552,16 @@ function getGitVariables(themeData, modePrefix) {
|
|
|
724
552
|
return styles;
|
|
725
553
|
}
|
|
726
554
|
//#endregion
|
|
727
|
-
//#region src/utils/
|
|
728
|
-
function
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
555
|
+
//#region src/utils/getTokenOptions.ts
|
|
556
|
+
function getTokenOptions(lang, theme, tokenizeMaxLineLength) {
|
|
557
|
+
return {
|
|
558
|
+
lang,
|
|
559
|
+
...typeof theme === "string" ? { theme } : { themes: theme },
|
|
560
|
+
defaultColor: false,
|
|
561
|
+
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
562
|
+
tokenizeMaxLineLength,
|
|
563
|
+
tokenizeTimeLimit: 0
|
|
564
|
+
};
|
|
737
565
|
}
|
|
738
566
|
//#endregion
|
|
739
567
|
//#region src/utils/getHunkSideBoundaries.ts
|
|
@@ -1327,9 +1155,431 @@ function pushOrJoinSpan({ item, arr, enableJoin, isNeutral = false, isLastItem =
|
|
|
1327
1155
|
arr.push([isNeutral ? 0 : 1, item.value]);
|
|
1328
1156
|
}
|
|
1329
1157
|
//#endregion
|
|
1158
|
+
//#region src/utils/hast_utils.ts
|
|
1159
|
+
function createTextNodeElement(value) {
|
|
1160
|
+
return {
|
|
1161
|
+
type: "text",
|
|
1162
|
+
value
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
function createHastElement({ tagName, children = [], properties = {} }) {
|
|
1166
|
+
return {
|
|
1167
|
+
type: "element",
|
|
1168
|
+
tagName,
|
|
1169
|
+
properties,
|
|
1170
|
+
children
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
//#endregion
|
|
1174
|
+
//#region src/utils/processLine.ts
|
|
1175
|
+
function processLine(node, line, state) {
|
|
1176
|
+
const lineInfo = typeof state.lineInfo === "function" ? state.lineInfo(line) : state.lineInfo[line - 1];
|
|
1177
|
+
if (lineInfo == null) {
|
|
1178
|
+
const errorMessage = `processLine: line ${line}, contains no state.lineInfo`;
|
|
1179
|
+
console.error(errorMessage, {
|
|
1180
|
+
node,
|
|
1181
|
+
line,
|
|
1182
|
+
state
|
|
1183
|
+
});
|
|
1184
|
+
throw new Error(errorMessage);
|
|
1185
|
+
}
|
|
1186
|
+
node.tagName = "div";
|
|
1187
|
+
node.properties["data-line"] = lineInfo.lineNumber;
|
|
1188
|
+
node.properties["data-alt-line"] = lineInfo.altLineNumber;
|
|
1189
|
+
node.properties["data-line-type"] = lineInfo.type;
|
|
1190
|
+
node.properties["data-line-index"] = lineInfo.lineIndex;
|
|
1191
|
+
if (node.children.length === 0) node.children.push(createTextNodeElement("\n"));
|
|
1192
|
+
return node;
|
|
1193
|
+
}
|
|
1194
|
+
//#endregion
|
|
1195
|
+
//#region src/utils/setDeferredArrayItem.ts
|
|
1196
|
+
function setDeferredArrayItem(array, index, create) {
|
|
1197
|
+
let initialized = false;
|
|
1198
|
+
let cached;
|
|
1199
|
+
Object.defineProperty(array, index, {
|
|
1200
|
+
configurable: true,
|
|
1201
|
+
enumerable: true,
|
|
1202
|
+
get() {
|
|
1203
|
+
if (!initialized) {
|
|
1204
|
+
cached = create();
|
|
1205
|
+
initialized = true;
|
|
1206
|
+
}
|
|
1207
|
+
if (Object.getOwnPropertyDescriptor(array, index)?.configurable === true) Object.defineProperty(array, index, {
|
|
1208
|
+
configurable: true,
|
|
1209
|
+
enumerable: true,
|
|
1210
|
+
writable: true,
|
|
1211
|
+
value: cached
|
|
1212
|
+
});
|
|
1213
|
+
return cached;
|
|
1214
|
+
},
|
|
1215
|
+
set(value) {
|
|
1216
|
+
if (Object.getOwnPropertyDescriptor(array, index)?.configurable === true) Object.defineProperty(array, index, {
|
|
1217
|
+
configurable: true,
|
|
1218
|
+
enumerable: true,
|
|
1219
|
+
writable: true,
|
|
1220
|
+
value
|
|
1221
|
+
});
|
|
1222
|
+
else if (Object.isFrozen(array)) throw new TypeError(`Cannot assign to read only array index '${index}'`);
|
|
1223
|
+
else {
|
|
1224
|
+
cached = value;
|
|
1225
|
+
initialized = true;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
//#endregion
|
|
1231
|
+
//#region src/utils/tokenStyle.ts
|
|
1232
|
+
const htmlStyleCache = /* @__PURE__ */ new WeakMap();
|
|
1233
|
+
/**
|
|
1234
|
+
* Returns CSS declarations for a highlighted token. Enable caching only when
|
|
1235
|
+
* htmlStyle objects are immutable and reused across tokens.
|
|
1236
|
+
*/
|
|
1237
|
+
function tokenStyle(token, cacheHtmlStyle = false) {
|
|
1238
|
+
const { htmlStyle } = token;
|
|
1239
|
+
if (htmlStyle != null) {
|
|
1240
|
+
let style = cacheHtmlStyle ? htmlStyleCache.get(htmlStyle) : void 0;
|
|
1241
|
+
if (style == null) {
|
|
1242
|
+
style = "";
|
|
1243
|
+
for (const name in htmlStyle) style += `${style === "" ? "" : ";"}${name}:${htmlStyle[name]}`;
|
|
1244
|
+
if (cacheHtmlStyle) htmlStyleCache.set(htmlStyle, style);
|
|
1245
|
+
}
|
|
1246
|
+
return style;
|
|
1247
|
+
}
|
|
1248
|
+
let style = token.color != null ? `color:${token.color}` : "";
|
|
1249
|
+
if (token.bgColor != null) style += `;background-color:${token.bgColor}`;
|
|
1250
|
+
if (token.fontStyle != null) {
|
|
1251
|
+
if ((token.fontStyle & 1) !== 0) style += ";font-style:italic";
|
|
1252
|
+
if ((token.fontStyle & 2) !== 0) style += ";font-weight:bold";
|
|
1253
|
+
const underline = (token.fontStyle & 4) !== 0;
|
|
1254
|
+
const strikethrough = (token.fontStyle & 8) !== 0;
|
|
1255
|
+
if (underline || strikethrough) style += `;text-decoration:${underline ? "underline" : ""}${underline && strikethrough ? " " : ""}${strikethrough ? "line-through" : ""}`;
|
|
1256
|
+
}
|
|
1257
|
+
return style.replace(/^;/, "");
|
|
1258
|
+
}
|
|
1259
|
+
//#endregion
|
|
1260
|
+
//#region src/utils/wrapTokenFragments.ts
|
|
1261
|
+
const NO_TOKEN = Symbol("no-token");
|
|
1262
|
+
const MULTIPLE_TOKENS = Symbol("multiple-tokens");
|
|
1263
|
+
function wrapTokenFragments(container) {
|
|
1264
|
+
const ownTokenChar = getTokenChar(container);
|
|
1265
|
+
if (ownTokenChar != null) return ownTokenChar;
|
|
1266
|
+
let containerTokenState = NO_TOKEN;
|
|
1267
|
+
const wrappedChildren = [];
|
|
1268
|
+
let currentTokenChildren = [];
|
|
1269
|
+
let currentTokenChar;
|
|
1270
|
+
const flushTokenChildren = () => {
|
|
1271
|
+
if (currentTokenChildren.length === 0 || currentTokenChar == null) {
|
|
1272
|
+
currentTokenChildren = [];
|
|
1273
|
+
currentTokenChar = void 0;
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
if (currentTokenChildren.length === 1) {
|
|
1277
|
+
const child = currentTokenChildren[0];
|
|
1278
|
+
if (child?.type === "element") {
|
|
1279
|
+
setTokenChar(child, currentTokenChar);
|
|
1280
|
+
for (const grandChild of child.children) stripTokenChar(grandChild);
|
|
1281
|
+
} else stripTokenChar(child);
|
|
1282
|
+
wrappedChildren.push(child);
|
|
1283
|
+
currentTokenChildren = [];
|
|
1284
|
+
currentTokenChar = void 0;
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
for (const child of currentTokenChildren) stripTokenChar(child);
|
|
1288
|
+
wrappedChildren.push(createHastElement({
|
|
1289
|
+
tagName: "span",
|
|
1290
|
+
properties: { "data-char": currentTokenChar },
|
|
1291
|
+
children: currentTokenChildren
|
|
1292
|
+
}));
|
|
1293
|
+
currentTokenChildren = [];
|
|
1294
|
+
currentTokenChar = void 0;
|
|
1295
|
+
};
|
|
1296
|
+
const mergeContainerTokenState = (childTokenState) => {
|
|
1297
|
+
if (childTokenState === NO_TOKEN) return;
|
|
1298
|
+
if (childTokenState === MULTIPLE_TOKENS) {
|
|
1299
|
+
containerTokenState = MULTIPLE_TOKENS;
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
if (containerTokenState === NO_TOKEN) {
|
|
1303
|
+
containerTokenState = childTokenState;
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
if (containerTokenState !== childTokenState) containerTokenState = MULTIPLE_TOKENS;
|
|
1307
|
+
};
|
|
1308
|
+
for (const child of container.children) {
|
|
1309
|
+
const childTokenState = child.type === "element" ? wrapTokenFragments(child) : NO_TOKEN;
|
|
1310
|
+
mergeContainerTokenState(childTokenState);
|
|
1311
|
+
if (typeof childTokenState !== "number") {
|
|
1312
|
+
flushTokenChildren();
|
|
1313
|
+
wrappedChildren.push(child);
|
|
1314
|
+
continue;
|
|
1315
|
+
}
|
|
1316
|
+
if (currentTokenChar != null && currentTokenChar !== childTokenState) flushTokenChildren();
|
|
1317
|
+
currentTokenChar ??= childTokenState;
|
|
1318
|
+
currentTokenChildren.push(child);
|
|
1319
|
+
}
|
|
1320
|
+
flushTokenChildren();
|
|
1321
|
+
container.children = wrappedChildren;
|
|
1322
|
+
return containerTokenState;
|
|
1323
|
+
}
|
|
1324
|
+
function getTokenChar(node) {
|
|
1325
|
+
const value = node.properties["data-char"];
|
|
1326
|
+
if (typeof value === "number") return value;
|
|
1327
|
+
}
|
|
1328
|
+
function stripTokenChar(node) {
|
|
1329
|
+
if (node.type !== "element") return;
|
|
1330
|
+
node.properties["data-char"] = void 0;
|
|
1331
|
+
for (const child of node.children) stripTokenChar(child);
|
|
1332
|
+
}
|
|
1333
|
+
function setTokenChar(node, char) {
|
|
1334
|
+
node.properties["data-char"] = char;
|
|
1335
|
+
}
|
|
1336
|
+
//#endregion
|
|
1337
|
+
//#region src/utils/renderTokenLines.ts
|
|
1338
|
+
/**
|
|
1339
|
+
* Converts highlighted tokens to one HAST element per line for custom renderers.
|
|
1340
|
+
* Callers provide any line separators and enclosing pre/code elements.
|
|
1341
|
+
*/
|
|
1342
|
+
function renderTokenLines(lines, { state, lazyLineAST = false, cacheHtmlStyles = false, useTokenTransformer = false, mergeWhitespaces = "always", decorations = [], lineOffsets = [] }) {
|
|
1343
|
+
let decorationsByLine;
|
|
1344
|
+
for (const decoration of decorations) {
|
|
1345
|
+
const byLine = decorationsByLine ??= /* @__PURE__ */ new Map();
|
|
1346
|
+
const normalized = {
|
|
1347
|
+
...decoration,
|
|
1348
|
+
start: getDecorationPosition(decoration.start, lineOffsets),
|
|
1349
|
+
end: getDecorationPosition(decoration.end, lineOffsets)
|
|
1350
|
+
};
|
|
1351
|
+
const lastLine = Math.min(normalized.end.line, lines.length - 1);
|
|
1352
|
+
for (let line = normalized.start.line; line <= lastLine; line++) {
|
|
1353
|
+
let spans = byLine.get(line);
|
|
1354
|
+
if (spans == null) byLine.set(line, spans = []);
|
|
1355
|
+
spans.push(normalized);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
const renderLine = (tokens, lineIndex) => {
|
|
1359
|
+
let normalized;
|
|
1360
|
+
if (useTokenTransformer || mergeWhitespaces !== "never") {
|
|
1361
|
+
let pendingWhitespace = "";
|
|
1362
|
+
let whitespaceOffset = 0;
|
|
1363
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
1364
|
+
let token = tokens[i];
|
|
1365
|
+
if (useTokenTransformer) {
|
|
1366
|
+
const content = token.content.trim();
|
|
1367
|
+
if (content !== "" && content !== token.content) {
|
|
1368
|
+
normalized ??= tokens.slice(0, i);
|
|
1369
|
+
const start = token.content.indexOf(content);
|
|
1370
|
+
if (start > 0) normalized.push({
|
|
1371
|
+
content: token.content.slice(0, start),
|
|
1372
|
+
offset: token.offset
|
|
1373
|
+
});
|
|
1374
|
+
normalized.push({
|
|
1375
|
+
...token,
|
|
1376
|
+
content,
|
|
1377
|
+
offset: token.offset + start
|
|
1378
|
+
});
|
|
1379
|
+
const end = start + content.length;
|
|
1380
|
+
if (end < token.content.length) normalized.push({
|
|
1381
|
+
content: token.content.slice(end),
|
|
1382
|
+
offset: token.offset + end
|
|
1383
|
+
});
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
} else {
|
|
1387
|
+
const decoratedWhitespace = ((token.fontStyle ?? 0) & 12) !== 0;
|
|
1388
|
+
if (!decoratedWhitespace && /^\s+$/.test(token.content) && i < tokens.length - 1) {
|
|
1389
|
+
normalized ??= tokens.slice(0, i);
|
|
1390
|
+
if (pendingWhitespace === "") whitespaceOffset = token.offset;
|
|
1391
|
+
pendingWhitespace += token.content;
|
|
1392
|
+
continue;
|
|
1393
|
+
}
|
|
1394
|
+
if (pendingWhitespace !== "" && normalized != null) {
|
|
1395
|
+
if (decoratedWhitespace) normalized.push({
|
|
1396
|
+
content: pendingWhitespace,
|
|
1397
|
+
offset: whitespaceOffset
|
|
1398
|
+
});
|
|
1399
|
+
else token = {
|
|
1400
|
+
...token,
|
|
1401
|
+
content: pendingWhitespace + token.content,
|
|
1402
|
+
offset: whitespaceOffset
|
|
1403
|
+
};
|
|
1404
|
+
pendingWhitespace = "";
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
normalized?.push(token);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
normalized ??= tokens;
|
|
1411
|
+
const line = {
|
|
1412
|
+
type: "element",
|
|
1413
|
+
tagName: state == null ? "span" : "div",
|
|
1414
|
+
properties: state == null ? { class: "line" } : {},
|
|
1415
|
+
children: []
|
|
1416
|
+
};
|
|
1417
|
+
const spans = decorationsByLine?.get(lineIndex);
|
|
1418
|
+
const column = spans == null ? appendTokens(line, normalized, useTokenTransformer, cacheHtmlStyles) : appendDecoratedTokens(line, normalized, spans, lineIndex, useTokenTransformer, cacheHtmlStyles);
|
|
1419
|
+
if (useTokenTransformer && column === 0) line.children.push({
|
|
1420
|
+
type: "element",
|
|
1421
|
+
tagName: "br",
|
|
1422
|
+
properties: {},
|
|
1423
|
+
children: []
|
|
1424
|
+
});
|
|
1425
|
+
if (useTokenTransformer && spans != null) wrapTokenFragments(line);
|
|
1426
|
+
return state == null ? line : processLine(line, lineIndex + 1, state);
|
|
1427
|
+
};
|
|
1428
|
+
if (!lazyLineAST) return lines.map(renderLine);
|
|
1429
|
+
const rows = new Array(lines.length);
|
|
1430
|
+
for (let index = 0; index < lines.length; index++) {
|
|
1431
|
+
const tokens = lines[index];
|
|
1432
|
+
setDeferredArrayItem(rows, index, () => renderLine(tokens, index));
|
|
1433
|
+
}
|
|
1434
|
+
return rows;
|
|
1435
|
+
}
|
|
1436
|
+
function appendTokens(line, tokens, useTokenTransformer, cacheHtmlStyles) {
|
|
1437
|
+
let column = 0;
|
|
1438
|
+
for (const token of tokens) {
|
|
1439
|
+
if (token.content === "") continue;
|
|
1440
|
+
line.children.push(createTokenSpan(token, tokenStyle(token, cacheHtmlStyles), token.content, column, useTokenTransformer));
|
|
1441
|
+
column += token.content.length;
|
|
1442
|
+
}
|
|
1443
|
+
return column;
|
|
1444
|
+
}
|
|
1445
|
+
function appendDecoratedTokens(line, tokens, spans, lineIndex, useTokenTransformer, cacheHtmlStyles) {
|
|
1446
|
+
if (spans.length > 1) spans.sort((a, b) => {
|
|
1447
|
+
if (a.start.line !== b.start.line) return a.start.line - b.start.line;
|
|
1448
|
+
if (a.start.character !== b.start.character) return a.start.character - b.start.character;
|
|
1449
|
+
if (a.end.line !== b.end.line) return b.end.line - a.end.line;
|
|
1450
|
+
return b.end.character - a.end.character;
|
|
1451
|
+
});
|
|
1452
|
+
const lineLength = tokens.reduce((length, token) => length + token.content.length, 0);
|
|
1453
|
+
const boundaries = [];
|
|
1454
|
+
for (let order = 0; order < spans.length; order++) {
|
|
1455
|
+
const decoration = spans[order];
|
|
1456
|
+
const range = {
|
|
1457
|
+
decoration,
|
|
1458
|
+
order,
|
|
1459
|
+
from: decoration.start.line === lineIndex ? decoration.start.character : 0,
|
|
1460
|
+
to: decoration.end.line === lineIndex ? decoration.end.character : lineLength
|
|
1461
|
+
};
|
|
1462
|
+
boundaries.push({
|
|
1463
|
+
position: Math.max(0, Math.min(range.from, lineLength)),
|
|
1464
|
+
range,
|
|
1465
|
+
start: true
|
|
1466
|
+
}, {
|
|
1467
|
+
position: Math.max(0, Math.min(range.to, lineLength)),
|
|
1468
|
+
range,
|
|
1469
|
+
start: false
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
boundaries.sort((a, b) => a.position - b.position);
|
|
1473
|
+
const active = [];
|
|
1474
|
+
const decorationStack = [];
|
|
1475
|
+
let boundaryIndex = 0;
|
|
1476
|
+
const updateActive = (range, add) => {
|
|
1477
|
+
let low = 0;
|
|
1478
|
+
let high = active.length;
|
|
1479
|
+
while (low < high) {
|
|
1480
|
+
const middle = low + high >>> 1;
|
|
1481
|
+
if (active[middle].order < range.order) low = middle + 1;
|
|
1482
|
+
else high = middle;
|
|
1483
|
+
}
|
|
1484
|
+
if (add) active.splice(low, 0, range);
|
|
1485
|
+
else if (active[low] === range) active.splice(low, 1);
|
|
1486
|
+
};
|
|
1487
|
+
const getParent = () => {
|
|
1488
|
+
let parent = line;
|
|
1489
|
+
let depth = 0;
|
|
1490
|
+
for (const range of active) {
|
|
1491
|
+
if (decorationStack[depth]?.range !== range) {
|
|
1492
|
+
decorationStack.length = depth;
|
|
1493
|
+
const wrapper = {
|
|
1494
|
+
type: "element",
|
|
1495
|
+
tagName: "span",
|
|
1496
|
+
properties: { ...range.decoration.properties },
|
|
1497
|
+
children: []
|
|
1498
|
+
};
|
|
1499
|
+
parent.children.push(wrapper);
|
|
1500
|
+
decorationStack.push({
|
|
1501
|
+
range,
|
|
1502
|
+
node: wrapper
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
parent = decorationStack[depth++].node;
|
|
1506
|
+
}
|
|
1507
|
+
decorationStack.length = depth;
|
|
1508
|
+
return parent;
|
|
1509
|
+
};
|
|
1510
|
+
let parent = line;
|
|
1511
|
+
const advanceBoundary = (position) => {
|
|
1512
|
+
const first = boundaryIndex;
|
|
1513
|
+
while (boundaries[boundaryIndex]?.position === position) boundaryIndex++;
|
|
1514
|
+
let hasMarker = false;
|
|
1515
|
+
for (let i = first; i < boundaryIndex; i++) {
|
|
1516
|
+
const { range, start } = boundaries[i];
|
|
1517
|
+
if (!start && range.from !== range.to && position < lineLength) updateActive(range, false);
|
|
1518
|
+
}
|
|
1519
|
+
for (let i = first; i < boundaryIndex; i++) {
|
|
1520
|
+
const { range, start } = boundaries[i];
|
|
1521
|
+
if (start && range.from <= position && range.to >= position && (range.to > position || range.from === position || position === lineLength)) {
|
|
1522
|
+
updateActive(range, true);
|
|
1523
|
+
if (range.from === range.to) hasMarker = true;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
if (hasMarker) {
|
|
1527
|
+
getParent();
|
|
1528
|
+
for (let i = first; i < boundaryIndex; i++) {
|
|
1529
|
+
const { range, start } = boundaries[i];
|
|
1530
|
+
if (start && range.from === range.to) updateActive(range, false);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
if (position < lineLength) parent = getParent();
|
|
1534
|
+
};
|
|
1535
|
+
let column = 0;
|
|
1536
|
+
for (const token of tokens) {
|
|
1537
|
+
if (token.content === "") continue;
|
|
1538
|
+
const start = column;
|
|
1539
|
+
const end = start + token.content.length;
|
|
1540
|
+
const style = tokenStyle(token, cacheHtmlStyles);
|
|
1541
|
+
while (column < end) {
|
|
1542
|
+
if (boundaries[boundaryIndex]?.position === column) advanceBoundary(column);
|
|
1543
|
+
const to = Math.min(end, boundaries[boundaryIndex]?.position ?? end);
|
|
1544
|
+
parent.children.push(createTokenSpan(token, style, column === start && to === end ? token.content : token.content.slice(column - start, to - start), start, useTokenTransformer));
|
|
1545
|
+
column = to;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
if (boundaries[boundaryIndex]?.position === column) advanceBoundary(column);
|
|
1549
|
+
return column;
|
|
1550
|
+
}
|
|
1551
|
+
function createTokenSpan(token, style, text, start, useTokenTransformer) {
|
|
1552
|
+
const properties = token.htmlAttrs != null ? { ...token.htmlAttrs } : {};
|
|
1553
|
+
if (style !== "") properties.style = style;
|
|
1554
|
+
if (useTokenTransformer) properties["data-char"] = start;
|
|
1555
|
+
return {
|
|
1556
|
+
type: "element",
|
|
1557
|
+
tagName: "span",
|
|
1558
|
+
properties,
|
|
1559
|
+
children: [{
|
|
1560
|
+
type: "text",
|
|
1561
|
+
value: text
|
|
1562
|
+
}]
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
function getDecorationPosition(position, lineOffsets) {
|
|
1566
|
+
if (typeof position !== "number") return position;
|
|
1567
|
+
let low = 0;
|
|
1568
|
+
let high = lineOffsets.length;
|
|
1569
|
+
while (low + 1 < high) {
|
|
1570
|
+
const middle = low + high >>> 1;
|
|
1571
|
+
if (lineOffsets[middle] <= position) low = middle;
|
|
1572
|
+
else high = middle;
|
|
1573
|
+
}
|
|
1574
|
+
return {
|
|
1575
|
+
line: low,
|
|
1576
|
+
character: position - (lineOffsets[low] ?? 0)
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
//#endregion
|
|
1330
1580
|
//#region src/utils/renderDiffWithHighlighter.ts
|
|
1331
1581
|
const DEFAULT_PLAIN_TEXT_OPTIONS$1 = { forcePlainText: false };
|
|
1332
|
-
function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText, startingLine, totalLines, expandedHunks, collapsedContextThreshold = 1 } = DEFAULT_PLAIN_TEXT_OPTIONS$1) {
|
|
1582
|
+
function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText, lazyLineAST = false, startingLine, totalLines, expandedHunks, collapsedContextThreshold = 1 } = DEFAULT_PLAIN_TEXT_OPTIONS$1) {
|
|
1333
1583
|
if (forcePlainText) {
|
|
1334
1584
|
startingLine ??= 0;
|
|
1335
1585
|
totalLines ??= Infinity;
|
|
@@ -1338,6 +1588,7 @@ function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText,
|
|
|
1338
1588
|
totalLines = Infinity;
|
|
1339
1589
|
}
|
|
1340
1590
|
const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
|
|
1591
|
+
lazyLineAST &&= !forcePlainText && !options.useTokenTransformer;
|
|
1341
1592
|
const baseThemeType = typeof options.theme === "string" ? highlighter.getTheme(options.theme).type : void 0;
|
|
1342
1593
|
const themeStyles = getHighlighterThemeStyles({
|
|
1343
1594
|
theme: options.theme,
|
|
@@ -1432,17 +1683,27 @@ function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText,
|
|
|
1432
1683
|
additionDecorations: bucket.additionDecorations,
|
|
1433
1684
|
highlighter,
|
|
1434
1685
|
options,
|
|
1435
|
-
languageOverride: forcePlainText ? "text" : diff.lang
|
|
1686
|
+
languageOverride: forcePlainText ? "text" : diff.lang,
|
|
1687
|
+
lazyLineAST
|
|
1436
1688
|
});
|
|
1437
1689
|
if (shouldGroupAll) {
|
|
1438
1690
|
code.deletionLines = deletionLines;
|
|
1439
1691
|
code.additionLines = additionLines;
|
|
1440
1692
|
continue;
|
|
1441
1693
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1694
|
+
for (const [target, lines, segments] of [[
|
|
1695
|
+
code.deletionLines,
|
|
1696
|
+
deletionLines,
|
|
1697
|
+
bucket.deletionSegments
|
|
1698
|
+
], [
|
|
1699
|
+
code.additionLines,
|
|
1700
|
+
additionLines,
|
|
1701
|
+
bucket.additionSegments
|
|
1702
|
+
]]) if (segments.length > 0) for (const segment of segments) for (let index = 0; index < segment.count; index++) target[segment.targetIndex + index] = lines[segment.originalOffset + index];
|
|
1703
|
+
else if (lazyLineAST) {
|
|
1704
|
+
const offset = target.length;
|
|
1705
|
+
for (let index = 0; index < lines.length; index++) setDeferredArrayItem(target, offset + index, () => lines[index]);
|
|
1706
|
+
} else appendItems(target, lines);
|
|
1446
1707
|
}
|
|
1447
1708
|
return {
|
|
1448
1709
|
code,
|
|
@@ -1574,46 +1835,20 @@ function createBucket() {
|
|
|
1574
1835
|
additionSegments: []
|
|
1575
1836
|
};
|
|
1576
1837
|
}
|
|
1577
|
-
function renderTwoFiles({ deletionFile, additionFile, deletionInfo, additionInfo, highlighter, deletionDecorations, additionDecorations, languageOverride, options: { theme
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
defaultColor: false,
|
|
1589
|
-
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
1590
|
-
tokenizeTimeLimit: 0
|
|
1591
|
-
} : {
|
|
1592
|
-
...options,
|
|
1593
|
-
lang: "text",
|
|
1594
|
-
themes: themeOrThemes,
|
|
1595
|
-
transformers,
|
|
1596
|
-
decorations: void 0,
|
|
1597
|
-
defaultColor: false,
|
|
1598
|
-
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
1599
|
-
tokenizeTimeLimit: 0
|
|
1600
|
-
};
|
|
1601
|
-
})();
|
|
1838
|
+
function renderTwoFiles({ lazyLineAST, deletionFile, additionFile, deletionInfo, additionInfo, highlighter, deletionDecorations, additionDecorations, languageOverride, options: { theme, useTokenTransformer, tokenizeMaxLineLength } }) {
|
|
1839
|
+
const renderFile = (file, lineInfo, decorations) => {
|
|
1840
|
+
if (file.contents === "") return [];
|
|
1841
|
+
return renderTokenLines(highlighter.codeToTokens(cleanLastNewline(file.contents), getTokenOptions(languageOverride ?? getFiletypeFromFileName(file.name), theme, tokenizeMaxLineLength)).tokens, {
|
|
1842
|
+
state: { lineInfo },
|
|
1843
|
+
useTokenTransformer,
|
|
1844
|
+
decorations,
|
|
1845
|
+
lazyLineAST,
|
|
1846
|
+
cacheHtmlStyles: highlighter.name === "highlights"
|
|
1847
|
+
});
|
|
1848
|
+
};
|
|
1602
1849
|
return {
|
|
1603
|
-
deletionLines: (
|
|
1604
|
-
|
|
1605
|
-
hastConfig.lang = deletionLang;
|
|
1606
|
-
state.lineInfo = deletionInfo;
|
|
1607
|
-
hastConfig.decorations = deletionDecorations;
|
|
1608
|
-
return getLineNodes(highlighter.codeToHast(cleanLastNewline(deletionFile.contents), hastConfig));
|
|
1609
|
-
})(),
|
|
1610
|
-
additionLines: (() => {
|
|
1611
|
-
if (additionFile.contents === "") return [];
|
|
1612
|
-
hastConfig.lang = additionLang;
|
|
1613
|
-
hastConfig.decorations = additionDecorations;
|
|
1614
|
-
state.lineInfo = additionInfo;
|
|
1615
|
-
return getLineNodes(highlighter.codeToHast(cleanLastNewline(additionFile.contents), hastConfig));
|
|
1616
|
-
})()
|
|
1850
|
+
deletionLines: renderFile(deletionFile, deletionInfo, deletionDecorations),
|
|
1851
|
+
additionLines: renderFile(additionFile, additionInfo, additionDecorations)
|
|
1617
1852
|
};
|
|
1618
1853
|
}
|
|
1619
1854
|
//#endregion
|
|
@@ -1679,7 +1914,7 @@ function linesFromFileContents(contents) {
|
|
|
1679
1914
|
//#endregion
|
|
1680
1915
|
//#region src/utils/renderFileWithHighlighter.ts
|
|
1681
1916
|
const DEFAULT_PLAIN_TEXT_OPTIONS = { forcePlainText: false };
|
|
1682
|
-
function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLength, useTokenTransformer }, { forcePlainText, startingLine, totalLines, lines } = DEFAULT_PLAIN_TEXT_OPTIONS) {
|
|
1917
|
+
function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLength, useTokenTransformer }, { forcePlainText, lazyLineAST = false, startingLine, totalLines, lines } = DEFAULT_PLAIN_TEXT_OPTIONS) {
|
|
1683
1918
|
if (forcePlainText) {
|
|
1684
1919
|
startingLine ??= 0;
|
|
1685
1920
|
totalLines ??= Infinity;
|
|
@@ -1688,7 +1923,7 @@ function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLe
|
|
|
1688
1923
|
totalLines = Infinity;
|
|
1689
1924
|
}
|
|
1690
1925
|
const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
|
|
1691
|
-
const {
|
|
1926
|
+
const state = { lineInfo: [] };
|
|
1692
1927
|
const lang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
|
|
1693
1928
|
const baseThemeType = typeof theme === "string" ? highlighter.getTheme(theme).type : void 0;
|
|
1694
1929
|
const themeStyles = getHighlighterThemeStyles({
|
|
@@ -1700,27 +1935,12 @@ function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLe
|
|
|
1700
1935
|
lineIndex: shikiLineNumber - 1 + startingLine,
|
|
1701
1936
|
lineNumber: shikiLineNumber + startingLine
|
|
1702
1937
|
});
|
|
1703
|
-
const
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
1710
|
-
tokenizeMaxLineLength,
|
|
1711
|
-
tokenizeTimeLimit: 0
|
|
1712
|
-
};
|
|
1713
|
-
return {
|
|
1714
|
-
lang,
|
|
1715
|
-
themes: theme,
|
|
1716
|
-
transformers,
|
|
1717
|
-
defaultColor: false,
|
|
1718
|
-
cssVariablePrefix: formatCSSVariablePrefix("token"),
|
|
1719
|
-
tokenizeMaxLineLength,
|
|
1720
|
-
tokenizeTimeLimit: 0
|
|
1721
|
-
};
|
|
1722
|
-
})();
|
|
1723
|
-
const highlightedLines = getLineNodes(highlighter.codeToHast(normalizeHighlightLineEndings(isWindowedHighlight ? extractWindowedFileContent(lines ?? linesFromFileContents(file.contents), startingLine, totalLines) : file.contents), hastConfig));
|
|
1938
|
+
const highlightedLines = renderTokenLines(highlighter.codeToTokens(normalizeHighlightLineEndings(isWindowedHighlight ? extractWindowedFileContent(lines ?? linesFromFileContents(file.contents), startingLine, totalLines) : file.contents), getTokenOptions(lang, theme, tokenizeMaxLineLength)).tokens, {
|
|
1939
|
+
state,
|
|
1940
|
+
useTokenTransformer,
|
|
1941
|
+
lazyLineAST: lazyLineAST && !forcePlainText && !useTokenTransformer,
|
|
1942
|
+
cacheHtmlStyles: highlighter.name === "highlights"
|
|
1943
|
+
});
|
|
1724
1944
|
const code = isWindowedHighlight ? new Array(startingLine) : highlightedLines;
|
|
1725
1945
|
if (isWindowedHighlight) appendItems(code, highlightedLines);
|
|
1726
1946
|
return {
|
|
@@ -1738,8 +1958,102 @@ function extractWindowedFileContent(lines, startingLine, totalLines) {
|
|
|
1738
1958
|
return lines.slice(startingLine, endLine).join("");
|
|
1739
1959
|
}
|
|
1740
1960
|
//#endregion
|
|
1961
|
+
//#region src/worker/hastLinesTransport.ts
|
|
1962
|
+
const HOLE = 0;
|
|
1963
|
+
const TEXT = 1;
|
|
1964
|
+
const ELEMENT = 2;
|
|
1965
|
+
const OTHER = 3;
|
|
1966
|
+
const UNDEFINED = 0;
|
|
1967
|
+
const NULL = 1;
|
|
1968
|
+
const TRUE = 2;
|
|
1969
|
+
const FALSE = 3;
|
|
1970
|
+
const STRING = 4;
|
|
1971
|
+
const INTEGER = 5;
|
|
1972
|
+
const EXTRA = 6;
|
|
1973
|
+
function encodeHastLines(lines) {
|
|
1974
|
+
let ops = new Int32Array(Math.max(32, Math.min(65536, lines.length * 32)));
|
|
1975
|
+
let length = 0;
|
|
1976
|
+
const offsets = new Uint32Array(lines.length * 2);
|
|
1977
|
+
const strings = [];
|
|
1978
|
+
const stringIds = /* @__PURE__ */ new Map();
|
|
1979
|
+
const extras = [];
|
|
1980
|
+
let text = "";
|
|
1981
|
+
function push(value) {
|
|
1982
|
+
if (length === ops.length) {
|
|
1983
|
+
const next = new Int32Array(ops.length * 2);
|
|
1984
|
+
next.set(ops);
|
|
1985
|
+
ops = next;
|
|
1986
|
+
}
|
|
1987
|
+
ops[length++] = value;
|
|
1988
|
+
}
|
|
1989
|
+
function intern(value) {
|
|
1990
|
+
let id = stringIds.get(value);
|
|
1991
|
+
if (id == null) {
|
|
1992
|
+
id = strings.length;
|
|
1993
|
+
strings.push(value);
|
|
1994
|
+
stringIds.set(value, id);
|
|
1995
|
+
}
|
|
1996
|
+
return id;
|
|
1997
|
+
}
|
|
1998
|
+
function encodeNode(node) {
|
|
1999
|
+
let keys = 0;
|
|
2000
|
+
for (const _ in node) keys++;
|
|
2001
|
+
if (node?.type === "text" && keys === 2) {
|
|
2002
|
+
push(TEXT);
|
|
2003
|
+
push(node.value.length);
|
|
2004
|
+
text += node.value;
|
|
2005
|
+
} else if (node?.type === "element" && keys === 4 && node.properties != null && Object.getPrototypeOf(node.properties) === Object.prototype) {
|
|
2006
|
+
push(ELEMENT);
|
|
2007
|
+
push(intern(node.tagName));
|
|
2008
|
+
let count = 0;
|
|
2009
|
+
for (const _ in node.properties) count++;
|
|
2010
|
+
push(count);
|
|
2011
|
+
for (const key in node.properties) {
|
|
2012
|
+
const value = node.properties[key];
|
|
2013
|
+
push(intern(key));
|
|
2014
|
+
if (value === void 0) push(UNDEFINED);
|
|
2015
|
+
else if (value === null) push(NULL);
|
|
2016
|
+
else if (value === true) push(TRUE);
|
|
2017
|
+
else if (value === false) push(FALSE);
|
|
2018
|
+
else if (typeof value === "string") {
|
|
2019
|
+
push(STRING);
|
|
2020
|
+
push(intern(value));
|
|
2021
|
+
} else if (typeof value === "number" && (value | 0) === value && !Object.is(value, -0)) {
|
|
2022
|
+
push(INTEGER);
|
|
2023
|
+
push(value);
|
|
2024
|
+
} else {
|
|
2025
|
+
push(EXTRA);
|
|
2026
|
+
push(extras.length);
|
|
2027
|
+
extras.push(value);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
push(node.children.length);
|
|
2031
|
+
for (let index = 0; index < node.children.length; index++) if (index in node.children) encodeNode(node.children[index]);
|
|
2032
|
+
else push(HOLE);
|
|
2033
|
+
} else {
|
|
2034
|
+
push(OTHER);
|
|
2035
|
+
push(extras.length);
|
|
2036
|
+
extras.push(node);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
for (let index = 0; index < lines.length; index++) {
|
|
2040
|
+
offsets[index * 2] = length;
|
|
2041
|
+
offsets[index * 2 + 1] = text.length;
|
|
2042
|
+
if (index in lines) encodeNode(lines[index]);
|
|
2043
|
+
else push(HOLE);
|
|
2044
|
+
}
|
|
2045
|
+
return {
|
|
2046
|
+
ops: ops.subarray(0, length),
|
|
2047
|
+
offsets,
|
|
2048
|
+
strings,
|
|
2049
|
+
text,
|
|
2050
|
+
extras
|
|
2051
|
+
};
|
|
2052
|
+
}
|
|
2053
|
+
//#endregion
|
|
1741
2054
|
//#region src/worker/worker.ts
|
|
1742
2055
|
let highlighter;
|
|
2056
|
+
let compactResults = false;
|
|
1743
2057
|
let renderOptions = {
|
|
1744
2058
|
theme: DEFAULT_THEMES,
|
|
1745
2059
|
useTokenTransformer: false,
|
|
@@ -1749,7 +2063,7 @@ let renderOptions = {
|
|
|
1749
2063
|
};
|
|
1750
2064
|
const EMPTY_REGEXP = /(?:)/;
|
|
1751
2065
|
self.addEventListener("error", (event) => {
|
|
1752
|
-
console.error("[
|
|
2066
|
+
console.error("[Diffs Worker] Unhandled error:", event.error);
|
|
1753
2067
|
});
|
|
1754
2068
|
self.addEventListener("message", (event) => {
|
|
1755
2069
|
handleMessage(event.data);
|
|
@@ -1778,7 +2092,7 @@ async function handleMessage(request) {
|
|
|
1778
2092
|
EMPTY_REGEXP.exec("");
|
|
1779
2093
|
}
|
|
1780
2094
|
}
|
|
1781
|
-
async function handleInitialize({ id, renderOptions: options, preferredHighlighter, resolvedThemes, resolvedLanguages, customExtensionsVersion, customExtensionMap }) {
|
|
2095
|
+
async function handleInitialize({ id, renderOptions: options, preferredHighlighter, resolvedThemes, resolvedLanguages, customExtensionsVersion, customExtensionMap, resultFormat }) {
|
|
1782
2096
|
let highlighter = getHighlighter(preferredHighlighter);
|
|
1783
2097
|
if ("then" in highlighter) highlighter = await highlighter;
|
|
1784
2098
|
syncCustomExtensionsFromRequest({
|
|
@@ -1788,6 +2102,7 @@ async function handleInitialize({ id, renderOptions: options, preferredHighlight
|
|
|
1788
2102
|
attachResolvedThemes(resolvedThemes, highlighter);
|
|
1789
2103
|
if (resolvedLanguages != null) attachResolvedLanguages(resolvedLanguages, highlighter);
|
|
1790
2104
|
renderOptions = options;
|
|
2105
|
+
compactResults = resultFormat === "hast-ops-v1";
|
|
1791
2106
|
postMessage({
|
|
1792
2107
|
type: "success",
|
|
1793
2108
|
id,
|
|
@@ -1820,7 +2135,23 @@ async function handleRenderFile({ id, file, resolvedLanguages, customExtensionsV
|
|
|
1820
2135
|
useTokenTransformer: renderOptions.useTokenTransformer,
|
|
1821
2136
|
tokenizeMaxLineLength: renderOptions.tokenizeMaxLineLength
|
|
1822
2137
|
};
|
|
1823
|
-
|
|
2138
|
+
const result = renderFileWithHighlighter(file, highlighter, fileOptions);
|
|
2139
|
+
const code = compactResults ? encodeHastLines(result.code) : void 0;
|
|
2140
|
+
const response = {
|
|
2141
|
+
type: "success",
|
|
2142
|
+
requestType: "file",
|
|
2143
|
+
id,
|
|
2144
|
+
result,
|
|
2145
|
+
options: fileOptions,
|
|
2146
|
+
sentAt: Date.now()
|
|
2147
|
+
};
|
|
2148
|
+
postMessage(code == null ? response : {
|
|
2149
|
+
...response,
|
|
2150
|
+
result: {
|
|
2151
|
+
...result,
|
|
2152
|
+
code
|
|
2153
|
+
}
|
|
2154
|
+
}, code == null ? [] : [code.ops.buffer, code.offsets.buffer]);
|
|
1824
2155
|
}
|
|
1825
2156
|
async function handleRenderDiff({ id, diff, resolvedLanguages, customExtensionsVersion, customExtensionMap }) {
|
|
1826
2157
|
let highlighter = getHighlighter();
|
|
@@ -1830,14 +2161,34 @@ async function handleRenderDiff({ id, diff, resolvedLanguages, customExtensionsV
|
|
|
1830
2161
|
customExtensionMap
|
|
1831
2162
|
});
|
|
1832
2163
|
if (resolvedLanguages != null) attachResolvedLanguages(resolvedLanguages, highlighter);
|
|
1833
|
-
|
|
2164
|
+
const result = renderDiffWithHighlighter(diff, highlighter, renderOptions);
|
|
2165
|
+
const code = compactResults ? {
|
|
2166
|
+
deletionLines: encodeHastLines(result.code.deletionLines),
|
|
2167
|
+
additionLines: encodeHastLines(result.code.additionLines)
|
|
2168
|
+
} : void 0;
|
|
2169
|
+
const response = {
|
|
2170
|
+
type: "success",
|
|
2171
|
+
requestType: "diff",
|
|
2172
|
+
id,
|
|
2173
|
+
result,
|
|
2174
|
+
options: renderOptions,
|
|
2175
|
+
sentAt: Date.now()
|
|
2176
|
+
};
|
|
2177
|
+
postMessage(code == null ? response : {
|
|
2178
|
+
...response,
|
|
2179
|
+
result: {
|
|
2180
|
+
...result,
|
|
2181
|
+
code
|
|
2182
|
+
}
|
|
2183
|
+
}, code == null ? [] : [
|
|
2184
|
+
code.deletionLines.ops.buffer,
|
|
2185
|
+
code.deletionLines.offsets.buffer,
|
|
2186
|
+
code.additionLines.ops.buffer,
|
|
2187
|
+
code.additionLines.offsets.buffer
|
|
2188
|
+
]);
|
|
1834
2189
|
}
|
|
1835
|
-
function getHighlighter(preferredHighlighter
|
|
1836
|
-
highlighter ??=
|
|
1837
|
-
themes: [],
|
|
1838
|
-
langs: [],
|
|
1839
|
-
engine: preferredHighlighter === "shiki-wasm" ? createOnigurumaEngine(import("shiki/wasm")) : createJavaScriptRegexEngine()
|
|
1840
|
-
});
|
|
2190
|
+
function getHighlighter(preferredHighlighter) {
|
|
2191
|
+
highlighter ??= createHighlighter(preferredHighlighter);
|
|
1841
2192
|
return highlighter;
|
|
1842
2193
|
}
|
|
1843
2194
|
function syncCustomExtensionsFromRequest({ customExtensionsVersion, customExtensionMap }) {
|
|
@@ -1845,26 +2196,6 @@ function syncCustomExtensionsFromRequest({ customExtensionsVersion, customExtens
|
|
|
1845
2196
|
if (customExtensionsVersion == null || customExtensionMap == null) throw new Error("Worker request must include both customExtensionsVersion and customExtensionMap");
|
|
1846
2197
|
replaceCustomExtensions(customExtensionsVersion, customExtensionMap);
|
|
1847
2198
|
}
|
|
1848
|
-
function sendFileSuccess(id, result, options) {
|
|
1849
|
-
postMessage({
|
|
1850
|
-
type: "success",
|
|
1851
|
-
requestType: "file",
|
|
1852
|
-
id,
|
|
1853
|
-
result,
|
|
1854
|
-
options,
|
|
1855
|
-
sentAt: Date.now()
|
|
1856
|
-
});
|
|
1857
|
-
}
|
|
1858
|
-
function sendDiffSuccess(id, result, options) {
|
|
1859
|
-
postMessage({
|
|
1860
|
-
type: "success",
|
|
1861
|
-
requestType: "diff",
|
|
1862
|
-
id,
|
|
1863
|
-
result,
|
|
1864
|
-
options,
|
|
1865
|
-
sentAt: Date.now()
|
|
1866
|
-
});
|
|
1867
|
-
}
|
|
1868
2199
|
function sendError(id, error) {
|
|
1869
2200
|
const response = {
|
|
1870
2201
|
type: "error",
|
|
@@ -1875,5 +2206,6 @@ function sendError(id, error) {
|
|
|
1875
2206
|
postMessage(response);
|
|
1876
2207
|
}
|
|
1877
2208
|
//#endregion
|
|
2209
|
+
export { acquireHighlighterType as a, RegisteredCustomLanguages as c, HighlighterDisposedError as i, ResolvedLanguages as l, formatCSSVariablePrefix as n, releaseHighlighterType as o, appendItems as r, attachResolvedLanguages as s, renderTokenLines as t, ResolvingLanguages as u };
|
|
1878
2210
|
|
|
1879
2211
|
//# sourceMappingURL=worker.js.map
|