@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
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
import { i as isWorkerContext, n as DiffsHighlighter, r as createDiffsThemeResolver, t as BaseStreamTokenizer } from "./stream-tokenizer-DK9xp5M5.js";
|
|
2
|
+
import { c as RegisteredCustomLanguages, l as ResolvedLanguages, r as appendItems, s as attachResolvedLanguages, u as ResolvingLanguages } from "./worker.js";
|
|
3
|
+
import { createCssVariablesTheme, createHighlighterCore } from "shiki/core";
|
|
4
|
+
import { EncodedTokenMetadata, INITIAL } from "shiki/textmate";
|
|
5
|
+
//#region src/highlighter/languages/resolveLanguage.ts
|
|
6
|
+
async function resolveLanguage(lang) {
|
|
7
|
+
if (typeof __DIFFS_WORKER__ !== "undefined" ? __DIFFS_WORKER__ : isWorkerContext()) throw new Error(`resolveLanguage("${lang}") cannot be called from a worker context. Languages must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.`);
|
|
8
|
+
const pending = ResolvingLanguages.get(lang);
|
|
9
|
+
if (pending != null) return pending;
|
|
10
|
+
const resolver = (async () => {
|
|
11
|
+
let loader = RegisteredCustomLanguages.get(lang);
|
|
12
|
+
if (loader == null) {
|
|
13
|
+
const { bundledLanguages } = await import("shiki/langs");
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(bundledLanguages, lang)) loader = bundledLanguages[lang];
|
|
15
|
+
}
|
|
16
|
+
if (loader == null) throw new Error(`resolveLanguage: "${lang}" not found in bundled or custom languages`);
|
|
17
|
+
const { default: data } = await loader();
|
|
18
|
+
const resolvedLang = {
|
|
19
|
+
name: lang,
|
|
20
|
+
data
|
|
21
|
+
};
|
|
22
|
+
if (!ResolvedLanguages.has(lang)) ResolvedLanguages.set(lang, resolvedLang);
|
|
23
|
+
return resolvedLang;
|
|
24
|
+
})();
|
|
25
|
+
ResolvingLanguages.set(lang, resolver);
|
|
26
|
+
try {
|
|
27
|
+
return await resolver;
|
|
28
|
+
} finally {
|
|
29
|
+
if (ResolvingLanguages.get(lang) === resolver) ResolvingLanguages.delete(lang);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/highlighter/languages/getResolvedOrResolveLanguage.ts
|
|
34
|
+
function getResolvedOrResolveLanguage(language) {
|
|
35
|
+
return ResolvedLanguages.get(language) ?? resolveLanguage(language);
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/highlighter/languages/resolveLanguages.ts
|
|
39
|
+
async function resolveLanguages(languages) {
|
|
40
|
+
const resolvedLanguages = [];
|
|
41
|
+
const languagesToResolve = [];
|
|
42
|
+
for (const language of languages) {
|
|
43
|
+
if (language === "text" || language === "ansi") continue;
|
|
44
|
+
const maybeResolvedLanguage = getResolvedOrResolveLanguage(language) ?? resolveLanguage(language);
|
|
45
|
+
if ("then" in maybeResolvedLanguage) languagesToResolve.push(maybeResolvedLanguage);
|
|
46
|
+
else resolvedLanguages.push(maybeResolvedLanguage);
|
|
47
|
+
}
|
|
48
|
+
if (languagesToResolve.length > 0) await Promise.all(languagesToResolve).then((_resolvedLanguages) => {
|
|
49
|
+
for (const resolvedLanguage of _resolvedLanguages) {
|
|
50
|
+
if (resolvedLanguage == null) throw new Error("resolvedLanguages: unable to resolve language");
|
|
51
|
+
resolvedLanguages.push(resolvedLanguage);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return resolvedLanguages;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/editor/utils.ts
|
|
58
|
+
function debounce(func, wait) {
|
|
59
|
+
let timeout;
|
|
60
|
+
return function(...args) {
|
|
61
|
+
clearTimeout(timeout);
|
|
62
|
+
timeout = setTimeout(() => func.apply(this, args), wait);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/highlighter/shiki-editor.ts
|
|
67
|
+
const TOKENIZE_TIME_LIMIT = 0;
|
|
68
|
+
let nextTokenizerId = 0;
|
|
69
|
+
/** TextMate state caching and background work for a single editable document. */
|
|
70
|
+
var ShikiEditorTokenizer = class {
|
|
71
|
+
backend;
|
|
72
|
+
#highlighter;
|
|
73
|
+
#grammar;
|
|
74
|
+
#themeName;
|
|
75
|
+
#colorMap;
|
|
76
|
+
#textDocument;
|
|
77
|
+
#tokenizeMaxLineLength;
|
|
78
|
+
#onDeferTokenize;
|
|
79
|
+
#matchBrackets;
|
|
80
|
+
#debug;
|
|
81
|
+
#isCleanedUp = false;
|
|
82
|
+
#stateStack = [INITIAL];
|
|
83
|
+
#comparisonStateStack = [];
|
|
84
|
+
#comparisonStateStackStart = 0;
|
|
85
|
+
#comparisonLineChanges = [];
|
|
86
|
+
#lastLine = -1;
|
|
87
|
+
#isStopped = true;
|
|
88
|
+
#isPaused = false;
|
|
89
|
+
#backgroundJobId = 0;
|
|
90
|
+
#tokenizerId = ++nextTokenizerId;
|
|
91
|
+
#backgroundPrebuildEndLine = -1;
|
|
92
|
+
#pendingPrebuildEndLine = -1;
|
|
93
|
+
#backgroundChangedLineRanges;
|
|
94
|
+
#backgroundChangedRangeIndex = 0;
|
|
95
|
+
#bracketIgnoredRanges = [];
|
|
96
|
+
#isMessageListenerAttached = false;
|
|
97
|
+
#prebuildStateStack = debounce(async (renderRange) => {
|
|
98
|
+
if (this.#isCleanedUp) return;
|
|
99
|
+
const { startingLine = 0, totalLines = Infinity } = renderRange ?? {};
|
|
100
|
+
const endLine = Math.min(totalLines === Infinity ? Infinity : startingLine + totalLines, this.#textDocument.lineCount);
|
|
101
|
+
if (this.#grammar == null && !isGrammarlessLanguage(this.#textDocument.languageId)) {
|
|
102
|
+
await this.backend?.loadLanguages([this.#textDocument.languageId]);
|
|
103
|
+
if (this.#isCleanedUp) return;
|
|
104
|
+
this.#grammar = this.#highlighter.getLanguage(this.#textDocument.languageId);
|
|
105
|
+
}
|
|
106
|
+
this.#ensureActiveTheme();
|
|
107
|
+
this.#scheduleStatePrebuild(endLine);
|
|
108
|
+
}, 500);
|
|
109
|
+
#onMessage = ({ data }) => {
|
|
110
|
+
if (typeof data !== "object" || data === null) return;
|
|
111
|
+
const { type, tokenizerId, jobId } = data;
|
|
112
|
+
if (type === "tokenize" && tokenizerId === this.#tokenizerId && typeof jobId === "number" && jobId === this.#backgroundJobId) {
|
|
113
|
+
if (this.#backgroundPrebuildEndLine >= 0) this.#backgroundPrebuild(jobId);
|
|
114
|
+
else this.#backgroundTokenize(jobId);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
getStringCommentRegexpRangesInLine(lineIndex) {
|
|
118
|
+
if (!this.#matchBrackets || lineIndex < 0 || lineIndex >= this.#textDocument.lineCount) return null;
|
|
119
|
+
this.#ensureGrammar();
|
|
120
|
+
if (this.#grammar == null) return null;
|
|
121
|
+
if (this.#bracketIgnoredRanges[lineIndex] === void 0) {
|
|
122
|
+
this.#buildStateStack(lineIndex);
|
|
123
|
+
const state = this.#stateStack[lineIndex] ?? INITIAL;
|
|
124
|
+
const result = this.#tokenizeLineAt(lineIndex, state);
|
|
125
|
+
this.#stateStack[lineIndex + 1] = result.state;
|
|
126
|
+
}
|
|
127
|
+
return this.#bracketIgnoredRanges[lineIndex] ?? null;
|
|
128
|
+
}
|
|
129
|
+
constructor(highlighter, options, backend) {
|
|
130
|
+
this.backend = backend;
|
|
131
|
+
this.#highlighter = highlighter;
|
|
132
|
+
this.#textDocument = options.textDocument;
|
|
133
|
+
this.#themeName = options.theme;
|
|
134
|
+
this.#colorMap = [];
|
|
135
|
+
this.#tokenizeMaxLineLength = options.tokenizeMaxLineLength ?? 1e3;
|
|
136
|
+
this.#onDeferTokenize = options.onDeferTokenize;
|
|
137
|
+
this.#matchBrackets = options.matchBrackets !== false;
|
|
138
|
+
this.#debug = options.__debug ?? false;
|
|
139
|
+
this.#ensureGrammar();
|
|
140
|
+
this.#ensureActiveTheme();
|
|
141
|
+
}
|
|
142
|
+
setTheme(themeName) {
|
|
143
|
+
if (this.#themeName === themeName) return;
|
|
144
|
+
this.#themeName = themeName;
|
|
145
|
+
this.#ensureActiveTheme();
|
|
146
|
+
this.stopBackgroundTokenize();
|
|
147
|
+
this.#stateStack = [INITIAL];
|
|
148
|
+
this.#comparisonStateStack = [];
|
|
149
|
+
this.#comparisonStateStackStart = 0;
|
|
150
|
+
this.#comparisonLineChanges = [];
|
|
151
|
+
if (this.#grammar != null && this.#textDocument.lineCount > 0) this.#scheduleBackgroundTokenize(0);
|
|
152
|
+
}
|
|
153
|
+
#ensureActiveTheme() {
|
|
154
|
+
if (this.#themeName === "") return;
|
|
155
|
+
this.backend?.getTheme(this.#themeName);
|
|
156
|
+
const { colorMap } = this.#highlighter.setTheme(this.#themeName);
|
|
157
|
+
this.#colorMap = colorMap;
|
|
158
|
+
}
|
|
159
|
+
dispose() {
|
|
160
|
+
this.#isCleanedUp = true;
|
|
161
|
+
this.stopBackgroundTokenize();
|
|
162
|
+
this.#detachMessageListener();
|
|
163
|
+
}
|
|
164
|
+
tokenize(change, renderRange, hostRealignsRows = false) {
|
|
165
|
+
this.#ensureGrammar();
|
|
166
|
+
this.#ensureActiveTheme();
|
|
167
|
+
if (this.#grammar == null && !isGrammarlessLanguage(this.#textDocument.languageId)) throw new Error(`Grammar for language "${this.#textDocument.languageId}" not loaded`);
|
|
168
|
+
const { lineCount } = this.#textDocument;
|
|
169
|
+
const { startingLine = 0, totalLines = Infinity } = renderRange ?? {};
|
|
170
|
+
const renderRangeEndLine = totalLines === Infinity ? lineCount : Math.min(startingLine + totalLines, lineCount);
|
|
171
|
+
const dirtyStart = change.startLine;
|
|
172
|
+
const viewStart = Math.max(startingLine, dirtyStart);
|
|
173
|
+
const crossesRenderRangeEnd = renderRange != null && totalLines !== Infinity && change.lineDelta > 0 && dirtyStart < renderRangeEndLine && change.endLine >= renderRangeEndLine;
|
|
174
|
+
const canReuseCachedStates = change.lineDelta === 0 && (change.changedLineChanges?.every(([, , lineDelta]) => lineDelta === 0) ?? true);
|
|
175
|
+
if (this.#matchBrackets && !canReuseCachedStates) this.#bracketIgnoredRanges.length = Math.min(this.#bracketIgnoredRanges.length, change.startLine);
|
|
176
|
+
const canReuseShiftedStates = hostRealignsRows && change.lineDelta !== 0 && dirtyStart >= startingLine;
|
|
177
|
+
const canCacheTokenizedStates = canReuseCachedStates || renderRange == null || dirtyStart >= viewStart;
|
|
178
|
+
const changedLineRanges = change.changedLineRanges ?? [[dirtyStart, change.endLine]];
|
|
179
|
+
this.#comparisonStateStack = [];
|
|
180
|
+
this.#comparisonStateStackStart = 0;
|
|
181
|
+
this.#comparisonLineChanges = [];
|
|
182
|
+
let offscreenSyncEnd = -1;
|
|
183
|
+
if (dirtyStart < viewStart) {
|
|
184
|
+
for (const [rangeStart, rangeEnd] of changedLineRanges) if (rangeStart < viewStart) offscreenSyncEnd = Math.max(offscreenSyncEnd, Math.min(rangeEnd, viewStart - 1));
|
|
185
|
+
}
|
|
186
|
+
const shouldFlushOffscreenLines = offscreenSyncEnd >= dirtyStart && (canReuseCachedStates || change.lineDelta < 0);
|
|
187
|
+
if (canReuseCachedStates) this.#buildStateStack(dirtyStart);
|
|
188
|
+
else {
|
|
189
|
+
this.#shiftComparisonStateStack(change);
|
|
190
|
+
if (renderRange == null || dirtyStart >= viewStart) this.#buildStateStack(viewStart);
|
|
191
|
+
}
|
|
192
|
+
let changedRangeIndex = 0;
|
|
193
|
+
let currentChangedRangeEnd = changedLineRanges[changedRangeIndex][1];
|
|
194
|
+
let backgroundStartLine;
|
|
195
|
+
let backgroundChangedRangeIndex = 0;
|
|
196
|
+
let line = canReuseCachedStates ? changedLineRanges[changedRangeIndex][0] : viewStart;
|
|
197
|
+
let settled = false;
|
|
198
|
+
const dirtyLines = /* @__PURE__ */ new Map();
|
|
199
|
+
const offscreenDirtyLines = shouldFlushOffscreenLines ? /* @__PURE__ */ new Map() : void 0;
|
|
200
|
+
if (offscreenDirtyLines != null && !canReuseCachedStates) {
|
|
201
|
+
const offscreenEnd = Math.min(offscreenSyncEnd + 1, viewStart, renderRangeEndLine);
|
|
202
|
+
if (offscreenEnd > dirtyStart) {
|
|
203
|
+
this.#buildStateStack(offscreenEnd);
|
|
204
|
+
let offscreenLine = dirtyStart;
|
|
205
|
+
let offscreenState = this.#stateStack[offscreenLine] ?? INITIAL;
|
|
206
|
+
for (; offscreenLine < offscreenEnd; offscreenLine++) {
|
|
207
|
+
const resolved = this.#tokenizeLineAt(offscreenLine, offscreenState);
|
|
208
|
+
offscreenState = resolved.state;
|
|
209
|
+
offscreenDirtyLines.set(offscreenLine, resolved.resolvedTokens);
|
|
210
|
+
}
|
|
211
|
+
this.#stateStack[offscreenEnd] = offscreenState;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
let state = this.#stateStack[line] ?? INITIAL;
|
|
215
|
+
for (; line < renderRangeEndLine;) {
|
|
216
|
+
const previousNextState = canReuseCachedStates ? this.#stateStack[line + 1] : canReuseShiftedStates ? this.#getPreviousEndState(line + 1) : void 0;
|
|
217
|
+
if (canCacheTokenizedStates) this.#stateStack[line] = state;
|
|
218
|
+
const { resolvedTokens, state: nextState } = this.#tokenizeLineAt(line, state);
|
|
219
|
+
state = nextState;
|
|
220
|
+
if (line >= viewStart) dirtyLines.set(line, resolvedTokens);
|
|
221
|
+
else offscreenDirtyLines?.set(line, resolvedTokens);
|
|
222
|
+
if (canCacheTokenizedStates) this.#stateStack[line + 1] = state;
|
|
223
|
+
settled = line >= currentChangedRangeEnd && (canReuseCachedStates || canReuseShiftedStates) && previousNextState != null && state.equals(previousNextState);
|
|
224
|
+
if (settled) {
|
|
225
|
+
changedRangeIndex++;
|
|
226
|
+
const nextRange = changedLineRanges[changedRangeIndex];
|
|
227
|
+
if (nextRange == null) break;
|
|
228
|
+
if (nextRange[0] >= renderRangeEndLine) {
|
|
229
|
+
backgroundStartLine = nextRange[0];
|
|
230
|
+
backgroundChangedRangeIndex = changedRangeIndex;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
let nextState = this.#stateStack[nextRange[0]];
|
|
234
|
+
if (canReuseShiftedStates) for (let stateLine = line + 2; stateLine <= nextRange[0]; stateLine++) {
|
|
235
|
+
nextState = this.#getPreviousEndState(stateLine);
|
|
236
|
+
if (nextState == null) break;
|
|
237
|
+
this.#stateStack[stateLine] = nextState;
|
|
238
|
+
}
|
|
239
|
+
if (nextState == null) {
|
|
240
|
+
currentChangedRangeEnd = nextRange[1];
|
|
241
|
+
line++;
|
|
242
|
+
} else {
|
|
243
|
+
line = nextRange[0];
|
|
244
|
+
state = nextState;
|
|
245
|
+
currentChangedRangeEnd = nextRange[1];
|
|
246
|
+
}
|
|
247
|
+
settled = false;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
line++;
|
|
251
|
+
}
|
|
252
|
+
if (canCacheTokenizedStates) {
|
|
253
|
+
if (line < renderRangeEndLine) this.#stateStack[line + 1] = state;
|
|
254
|
+
else this.#stateStack[line] = state;
|
|
255
|
+
}
|
|
256
|
+
if (settled && canReuseShiftedStates && backgroundStartLine == null) {
|
|
257
|
+
for (let stateLine = line + 2; stateLine <= lineCount; stateLine++) {
|
|
258
|
+
const previousState = this.#getPreviousEndState(stateLine);
|
|
259
|
+
if (previousState == null) break;
|
|
260
|
+
this.#stateStack[stateLine] = previousState;
|
|
261
|
+
}
|
|
262
|
+
this.#comparisonStateStack = [];
|
|
263
|
+
this.#comparisonStateStackStart = 0;
|
|
264
|
+
this.#comparisonLineChanges = [];
|
|
265
|
+
}
|
|
266
|
+
if (offscreenDirtyLines != null && offscreenDirtyLines.size > 0) this.#onDeferTokenize(offscreenDirtyLines);
|
|
267
|
+
if (backgroundStartLine != null) {
|
|
268
|
+
if (this.#matchBrackets && canReuseCachedStates) this.#bracketIgnoredRanges.length = Math.min(this.#bracketIgnoredRanges.length, backgroundStartLine);
|
|
269
|
+
this.#scheduleBackgroundTokenize(backgroundStartLine, changedLineRanges, backgroundChangedRangeIndex);
|
|
270
|
+
} else if (!settled && line < lineCount) {
|
|
271
|
+
const backgroundLine = crossesRenderRangeEnd && dirtyStart >= viewStart ? renderRangeEndLine : dirtyStart < viewStart && !canReuseCachedStates ? dirtyStart : line;
|
|
272
|
+
if (this.#matchBrackets && canReuseCachedStates) this.#bracketIgnoredRanges.length = Math.min(this.#bracketIgnoredRanges.length, backgroundLine);
|
|
273
|
+
this.#scheduleBackgroundTokenize(backgroundLine, changedLineRanges, changedRangeIndex);
|
|
274
|
+
}
|
|
275
|
+
return dirtyLines;
|
|
276
|
+
}
|
|
277
|
+
prebuildStateStack(renderRange) {
|
|
278
|
+
this.#ensureGrammar();
|
|
279
|
+
this.#prebuildStateStack(renderRange);
|
|
280
|
+
}
|
|
281
|
+
stopBackgroundTokenize() {
|
|
282
|
+
this.#pendingPrebuildEndLine = -1;
|
|
283
|
+
if (this.#isStopped) return;
|
|
284
|
+
this.#isStopped = true;
|
|
285
|
+
this.#isPaused = false;
|
|
286
|
+
this.#lastLine = -1;
|
|
287
|
+
this.#backgroundPrebuildEndLine = -1;
|
|
288
|
+
this.#backgroundChangedLineRanges = void 0;
|
|
289
|
+
this.#backgroundChangedRangeIndex = 0;
|
|
290
|
+
this.#comparisonStateStack = [];
|
|
291
|
+
this.#comparisonStateStackStart = 0;
|
|
292
|
+
this.#comparisonLineChanges = [];
|
|
293
|
+
this.#detachMessageListener();
|
|
294
|
+
}
|
|
295
|
+
pauseBackgroundTokenize() {
|
|
296
|
+
if (this.#isStopped || this.#isPaused) return;
|
|
297
|
+
if (this.#debug) console.log("[diffs/editor] background tokenization paused", { jobId: this.#backgroundJobId });
|
|
298
|
+
this.#isPaused = true;
|
|
299
|
+
}
|
|
300
|
+
resumeBackgroundTokenize() {
|
|
301
|
+
if (this.#isStopped || !this.#isPaused || this.#grammar == null || this.#lastLine < 0) return;
|
|
302
|
+
if (this.#debug) console.log("[diffs/editor] background tokenization resumed", { jobId: this.#backgroundJobId });
|
|
303
|
+
this.#isPaused = false;
|
|
304
|
+
this.#postTokenizeMessage(this.#backgroundJobId);
|
|
305
|
+
}
|
|
306
|
+
#ensureGrammar() {
|
|
307
|
+
if (this.#grammar == null && !isGrammarlessLanguage(this.#textDocument.languageId) && this.#highlighter.getLoadedLanguages().includes(this.#textDocument.languageId)) this.#grammar = this.#highlighter.getLanguage(this.#textDocument.languageId);
|
|
308
|
+
}
|
|
309
|
+
#attachMessageListener() {
|
|
310
|
+
if (this.#isMessageListenerAttached) return;
|
|
311
|
+
globalThis.addEventListener("message", this.#onMessage);
|
|
312
|
+
this.#isMessageListenerAttached = true;
|
|
313
|
+
}
|
|
314
|
+
#detachMessageListener() {
|
|
315
|
+
if (!this.#isMessageListenerAttached) return;
|
|
316
|
+
globalThis.removeEventListener("message", this.#onMessage);
|
|
317
|
+
this.#isMessageListenerAttached = false;
|
|
318
|
+
}
|
|
319
|
+
#postTokenizeMessage(jobId) {
|
|
320
|
+
globalThis.postMessage({
|
|
321
|
+
type: "tokenize",
|
|
322
|
+
tokenizerId: this.#tokenizerId,
|
|
323
|
+
jobId
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
#scheduleBackgroundTokenize(startLine, changedLineRanges, changedRangeIndex = 0) {
|
|
327
|
+
if (isGrammarlessLanguage(this.#textDocument.languageId)) return;
|
|
328
|
+
const jobId = ++this.#backgroundJobId;
|
|
329
|
+
if (this.#debug) console.log("[diffs/editor] background tokenization scheduled", {
|
|
330
|
+
jobId,
|
|
331
|
+
startLine,
|
|
332
|
+
changedLineRanges,
|
|
333
|
+
changedRangeIndex
|
|
334
|
+
});
|
|
335
|
+
this.#isStopped = false;
|
|
336
|
+
this.#isPaused = false;
|
|
337
|
+
this.#lastLine = startLine;
|
|
338
|
+
if (this.#backgroundPrebuildEndLine >= 0) this.#pendingPrebuildEndLine = Math.max(this.#pendingPrebuildEndLine, this.#backgroundPrebuildEndLine);
|
|
339
|
+
this.#backgroundPrebuildEndLine = -1;
|
|
340
|
+
this.#backgroundChangedLineRanges = changedLineRanges;
|
|
341
|
+
this.#backgroundChangedRangeIndex = changedRangeIndex;
|
|
342
|
+
this.#attachMessageListener();
|
|
343
|
+
this.#postTokenizeMessage(jobId);
|
|
344
|
+
}
|
|
345
|
+
#scheduleStatePrebuild(endLine) {
|
|
346
|
+
if (this.#grammar == null || this.#stateStack.length > endLine) return;
|
|
347
|
+
if (!this.#isStopped) {
|
|
348
|
+
if (this.#backgroundPrebuildEndLine >= 0) this.#backgroundPrebuildEndLine = Math.max(this.#backgroundPrebuildEndLine, endLine);
|
|
349
|
+
else this.#pendingPrebuildEndLine = Math.max(this.#pendingPrebuildEndLine, endLine);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const jobId = ++this.#backgroundJobId;
|
|
353
|
+
this.#isStopped = false;
|
|
354
|
+
this.#isPaused = false;
|
|
355
|
+
this.#lastLine = this.#stateStack.length - 1;
|
|
356
|
+
this.#backgroundPrebuildEndLine = endLine;
|
|
357
|
+
this.#pendingPrebuildEndLine = -1;
|
|
358
|
+
this.#backgroundChangedLineRanges = void 0;
|
|
359
|
+
this.#backgroundChangedRangeIndex = 0;
|
|
360
|
+
this.#attachMessageListener();
|
|
361
|
+
this.#postTokenizeMessage(jobId);
|
|
362
|
+
}
|
|
363
|
+
#tokenizeLineAt(line, state) {
|
|
364
|
+
const lineText = this.#textDocument.getLineText(line);
|
|
365
|
+
if (lineText.length >= this.#tokenizeMaxLineLength) {
|
|
366
|
+
console.warn(`[diffs] Line(${line}) too long to tokenize: ${lineText.length}`);
|
|
367
|
+
this.#cacheBracketIgnoredRanges(line, null);
|
|
368
|
+
return {
|
|
369
|
+
resolvedTokens: [[
|
|
370
|
+
0,
|
|
371
|
+
"",
|
|
372
|
+
lineText
|
|
373
|
+
]],
|
|
374
|
+
state
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (this.#grammar == null || lineText === "" || lineText.trim() === "") {
|
|
378
|
+
this.#cacheBracketIgnoredRanges(line, null);
|
|
379
|
+
return {
|
|
380
|
+
resolvedTokens: [[
|
|
381
|
+
0,
|
|
382
|
+
"",
|
|
383
|
+
lineText
|
|
384
|
+
]],
|
|
385
|
+
state
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const result = tokenizeLine(this.#grammar, this.#colorMap, lineText, state, TOKENIZE_TIME_LIMIT, this.#matchBrackets);
|
|
389
|
+
this.#cacheBracketIgnoredRanges(line, result.bracketIgnoredRanges);
|
|
390
|
+
return {
|
|
391
|
+
resolvedTokens: result.resolvedTokens,
|
|
392
|
+
state: result.ruleStack
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
#cacheBracketIgnoredRanges(line, ranges) {
|
|
396
|
+
if (this.#matchBrackets) this.#bracketIgnoredRanges[line] = ranges;
|
|
397
|
+
}
|
|
398
|
+
#shiftComparisonStateStack(change) {
|
|
399
|
+
const lineChanges = change.changedLineChanges ?? [[
|
|
400
|
+
change.startLine,
|
|
401
|
+
change.endLine,
|
|
402
|
+
change.lineDelta
|
|
403
|
+
]];
|
|
404
|
+
const comparisonStart = change.startLine + 1;
|
|
405
|
+
if (comparisonStart <= this.#stateStack.length - comparisonStart) {
|
|
406
|
+
this.#comparisonStateStack = this.#stateStack;
|
|
407
|
+
this.#comparisonStateStackStart = 0;
|
|
408
|
+
this.#stateStack = this.#stateStack.slice(0, comparisonStart);
|
|
409
|
+
} else {
|
|
410
|
+
this.#comparisonStateStackStart = comparisonStart;
|
|
411
|
+
this.#comparisonStateStack = this.#stateStack.slice(comparisonStart);
|
|
412
|
+
this.#stateStack.length = Math.min(this.#stateStack.length, comparisonStart);
|
|
413
|
+
}
|
|
414
|
+
this.#comparisonLineChanges = lineChanges;
|
|
415
|
+
}
|
|
416
|
+
#getPreviousEndState(line) {
|
|
417
|
+
let previousLine = line;
|
|
418
|
+
for (let index = this.#comparisonLineChanges.length - 1; index >= 0; index--) {
|
|
419
|
+
const [startLine, endLine, lineDelta] = this.#comparisonLineChanges[index];
|
|
420
|
+
if (lineDelta === 0) continue;
|
|
421
|
+
if (previousLine > endLine) previousLine -= lineDelta;
|
|
422
|
+
else if (previousLine > startLine) return this.#stateStack[line];
|
|
423
|
+
}
|
|
424
|
+
return this.#comparisonStateStack[previousLine - this.#comparisonStateStackStart] ?? this.#stateStack[line];
|
|
425
|
+
}
|
|
426
|
+
#buildStateStack(endAt, timeBudget) {
|
|
427
|
+
const boundedEndAt = Math.min(Math.max(0, endAt), this.#textDocument.lineCount);
|
|
428
|
+
if (this.#stateStack.length > boundedEndAt || this.#grammar == null) return true;
|
|
429
|
+
const startedAt = timeBudget == null ? 0 : performance.now();
|
|
430
|
+
let line = this.#stateStack.length - 1;
|
|
431
|
+
let state = this.#stateStack[line] ?? INITIAL;
|
|
432
|
+
while (line < boundedEndAt) {
|
|
433
|
+
this.#stateStack[line] = state;
|
|
434
|
+
const lineText = this.#textDocument.getLineText(line);
|
|
435
|
+
if (lineText.length < this.#tokenizeMaxLineLength && lineText !== "" && lineText.trim() !== "") {
|
|
436
|
+
const result = tokenizeLine(this.#grammar, this.#colorMap, lineText, state, TOKENIZE_TIME_LIMIT, this.#matchBrackets, false);
|
|
437
|
+
this.#cacheBracketIgnoredRanges(line, result.bracketIgnoredRanges);
|
|
438
|
+
state = result.ruleStack;
|
|
439
|
+
} else this.#cacheBracketIgnoredRanges(line, null);
|
|
440
|
+
line++;
|
|
441
|
+
this.#stateStack[line] = state;
|
|
442
|
+
if (timeBudget != null && performance.now() - startedAt > timeBudget) break;
|
|
443
|
+
}
|
|
444
|
+
return line >= boundedEndAt;
|
|
445
|
+
}
|
|
446
|
+
#backgroundPrebuild(jobId) {
|
|
447
|
+
if (this.#isStopped || this.#isPaused || this.#grammar == null || jobId !== this.#backgroundJobId) return;
|
|
448
|
+
this.#ensureActiveTheme();
|
|
449
|
+
const complete = this.#buildStateStack(this.#backgroundPrebuildEndLine, 1);
|
|
450
|
+
if (this.#isStopped || this.#isPaused || jobId !== this.#backgroundJobId) return;
|
|
451
|
+
if (complete) {
|
|
452
|
+
this.stopBackgroundTokenize();
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
this.#lastLine = this.#stateStack.length - 1;
|
|
456
|
+
this.#postTokenizeMessage(jobId);
|
|
457
|
+
}
|
|
458
|
+
#backgroundTokenize(jobId) {
|
|
459
|
+
if (this.#isStopped || this.#isPaused || this.#grammar == null || jobId !== this.#backgroundJobId) return;
|
|
460
|
+
this.#ensureActiveTheme();
|
|
461
|
+
const t = performance.now();
|
|
462
|
+
const lines = /* @__PURE__ */ new Map();
|
|
463
|
+
const totalLines = this.#textDocument.lineCount;
|
|
464
|
+
const changedLineRanges = this.#backgroundChangedLineRanges;
|
|
465
|
+
let line = this.#lastLine;
|
|
466
|
+
let state = this.#stateStack[line] ?? INITIAL;
|
|
467
|
+
let settled = false;
|
|
468
|
+
let changedRangeIndex = this.#backgroundChangedRangeIndex;
|
|
469
|
+
let currentChangedRangeEnd = changedLineRanges?.[changedRangeIndex]?.[1];
|
|
470
|
+
for (; line < totalLines;) {
|
|
471
|
+
this.#stateStack[line] = state;
|
|
472
|
+
const previousNextState = currentChangedRangeEnd != null ? this.#getPreviousEndState(line + 1) : void 0;
|
|
473
|
+
const result = this.#tokenizeLineAt(line, state);
|
|
474
|
+
lines.set(line, result.resolvedTokens);
|
|
475
|
+
state = result.state;
|
|
476
|
+
this.#stateStack[line + 1] = state;
|
|
477
|
+
settled = currentChangedRangeEnd != null && line >= currentChangedRangeEnd && previousNextState != null && state.equals(previousNextState);
|
|
478
|
+
line++;
|
|
479
|
+
if (settled) {
|
|
480
|
+
changedRangeIndex++;
|
|
481
|
+
const nextRange = changedLineRanges?.[changedRangeIndex];
|
|
482
|
+
if (nextRange == null) break;
|
|
483
|
+
currentChangedRangeEnd = nextRange[1];
|
|
484
|
+
if (this.#stateStack[nextRange[0]] == null) settled = false;
|
|
485
|
+
else {
|
|
486
|
+
line = nextRange[0];
|
|
487
|
+
state = this.#stateStack[line] ?? state;
|
|
488
|
+
settled = false;
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (performance.now() - t > 1) break;
|
|
493
|
+
}
|
|
494
|
+
this.#onDeferTokenize(lines);
|
|
495
|
+
if (this.#isStopped || this.#isPaused || jobId !== this.#backgroundJobId) return;
|
|
496
|
+
if (settled || line >= totalLines) {
|
|
497
|
+
const pendingPrebuildEndLine = this.#pendingPrebuildEndLine;
|
|
498
|
+
this.stopBackgroundTokenize();
|
|
499
|
+
if (pendingPrebuildEndLine >= 0) this.#scheduleStatePrebuild(pendingPrebuildEndLine);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
this.#lastLine = line;
|
|
503
|
+
this.#backgroundChangedRangeIndex = changedRangeIndex;
|
|
504
|
+
this.#postTokenizeMessage(jobId);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
function tokenizeLine(grammar, colorMap, lineText, stateStack, timeLimit, collectBracketIgnoredRanges = true, resolveTokens = true) {
|
|
508
|
+
const result = grammar.tokenizeLine2(lineText, stateStack, timeLimit);
|
|
509
|
+
if (result.stoppedEarly) console.warn(`[diffs] Time limit reached when tokenizing line: ${lineText.substring(0, 100)}`);
|
|
510
|
+
const rawTokens = result.tokens;
|
|
511
|
+
const tokensLength = rawTokens.length / 2;
|
|
512
|
+
const resolvedTokens = [];
|
|
513
|
+
const bracketIgnoredRanges = [];
|
|
514
|
+
if (!resolveTokens && !collectBracketIgnoredRanges) return {
|
|
515
|
+
ruleStack: result.ruleStack,
|
|
516
|
+
resolvedTokens,
|
|
517
|
+
bracketIgnoredRanges
|
|
518
|
+
};
|
|
519
|
+
for (let j = 0; j < tokensLength; j++) {
|
|
520
|
+
const offset = rawTokens[2 * j];
|
|
521
|
+
const nextOffset = j + 1 < tokensLength ? rawTokens[2 * j + 2] : lineText.length;
|
|
522
|
+
if (offset === nextOffset) continue;
|
|
523
|
+
const metadata = rawTokens[2 * j + 1];
|
|
524
|
+
if (resolveTokens) {
|
|
525
|
+
const fg = EncodedTokenMetadata.getForeground(metadata);
|
|
526
|
+
resolvedTokens.push([
|
|
527
|
+
offset,
|
|
528
|
+
colorMap[fg],
|
|
529
|
+
lineText.slice(offset, nextOffset)
|
|
530
|
+
]);
|
|
531
|
+
}
|
|
532
|
+
if (collectBracketIgnoredRanges && EncodedTokenMetadata.getTokenType(metadata) > 0) bracketIgnoredRanges.push([offset, nextOffset]);
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
ruleStack: result.ruleStack,
|
|
536
|
+
resolvedTokens,
|
|
537
|
+
bracketIgnoredRanges
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function isGrammarlessLanguage(languageId) {
|
|
541
|
+
return languageId === "text" || languageId === "ansi";
|
|
542
|
+
}
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/highlighter/shiki-stream.ts
|
|
545
|
+
var ShikiStreamTokenizer = class ShikiStreamTokenizer extends BaseStreamTokenizer {
|
|
546
|
+
highlighter;
|
|
547
|
+
options;
|
|
548
|
+
#tail = "";
|
|
549
|
+
#grammarState;
|
|
550
|
+
constructor(highlighter, options) {
|
|
551
|
+
super();
|
|
552
|
+
this.highlighter = highlighter;
|
|
553
|
+
this.options = options;
|
|
554
|
+
}
|
|
555
|
+
tokenizeChunk(chunk, stable) {
|
|
556
|
+
const chunkLines = (this.#tail + chunk).split(/(\r\n|\r|\n)/);
|
|
557
|
+
let unstable = [];
|
|
558
|
+
for (let i = 0; i < chunkLines.length; i += 2) {
|
|
559
|
+
const line = chunkLines[i];
|
|
560
|
+
const result = this.highlighter.codeToTokens(line, {
|
|
561
|
+
...this.options,
|
|
562
|
+
grammarState: this.#grammarState
|
|
563
|
+
});
|
|
564
|
+
const tokens = result.tokens[0].map((token) => ({
|
|
565
|
+
...token,
|
|
566
|
+
offset: token.offset + this.stableOffset
|
|
567
|
+
}));
|
|
568
|
+
if (i + 1 < chunkLines.length) {
|
|
569
|
+
appendItems(stable, tokens);
|
|
570
|
+
this.pushLineBreak(stable, line.length, chunkLines[i + 1]);
|
|
571
|
+
this.#grammarState = result.grammarState;
|
|
572
|
+
} else {
|
|
573
|
+
unstable = tokens;
|
|
574
|
+
this.#tail = line;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
unstable,
|
|
579
|
+
tailLength: this.#tail.length
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
clone() {
|
|
583
|
+
this.assertActive();
|
|
584
|
+
const clone = new ShikiStreamTokenizer(this.highlighter, this.options);
|
|
585
|
+
this.copyStateTo(clone);
|
|
586
|
+
clone.#tail = this.#tail;
|
|
587
|
+
clone.#grammarState = this.#grammarState;
|
|
588
|
+
return clone;
|
|
589
|
+
}
|
|
590
|
+
resetSource() {
|
|
591
|
+
this.#tail = "";
|
|
592
|
+
this.#grammarState = void 0;
|
|
593
|
+
}
|
|
594
|
+
releaseSource() {
|
|
595
|
+
this.resetSource();
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/highlighter/backends/shiki.ts
|
|
600
|
+
var ShikiHighlighter = class ShikiHighlighter extends DiffsHighlighter {
|
|
601
|
+
raw;
|
|
602
|
+
loadedThemes = /* @__PURE__ */ new Map();
|
|
603
|
+
attachedLanguages = /* @__PURE__ */ new Set(["text", "ansi"]);
|
|
604
|
+
static async create(name) {
|
|
605
|
+
const engine = name === "shiki-wasm" ? (await import("shiki/engine/oniguruma")).createOnigurumaEngine(import("shiki/wasm")) : (await import("shiki/engine/javascript")).createJavaScriptRegexEngine();
|
|
606
|
+
const raw = await createHighlighterCore({
|
|
607
|
+
themes: [],
|
|
608
|
+
langs: [],
|
|
609
|
+
engine
|
|
610
|
+
});
|
|
611
|
+
return new ShikiHighlighter(name, raw);
|
|
612
|
+
}
|
|
613
|
+
constructor(name, raw) {
|
|
614
|
+
super(name, createDiffsThemeResolver(name));
|
|
615
|
+
this.raw = raw;
|
|
616
|
+
}
|
|
617
|
+
getTheme(themeName) {
|
|
618
|
+
this.assertNotDisposed();
|
|
619
|
+
const loaded = this.loadedThemes.get(themeName);
|
|
620
|
+
const theme = this.themeResolver.getResolvedTheme(themeName) ?? loaded;
|
|
621
|
+
if (theme == null) throw new Error(`Theme "${themeName}" has not been resolved`);
|
|
622
|
+
if (loaded !== theme) {
|
|
623
|
+
const textmate = theme.textmate ?? (theme.cssVariables != null ? createCssVariablesTheme(theme.cssVariables) : void 0);
|
|
624
|
+
if (textmate == null) throw new Error(`Theme "${themeName}" does not support Shiki`);
|
|
625
|
+
this.raw.setTheme({
|
|
626
|
+
...textmate,
|
|
627
|
+
name: themeName
|
|
628
|
+
});
|
|
629
|
+
this.loadedThemes.set(themeName, theme);
|
|
630
|
+
}
|
|
631
|
+
return theme;
|
|
632
|
+
}
|
|
633
|
+
codeToTokens(code, options) {
|
|
634
|
+
return this.raw.codeToTokens(code, this.resolveOptions(options));
|
|
635
|
+
}
|
|
636
|
+
createEditorTokenizer(options) {
|
|
637
|
+
return new ShikiEditorTokenizer(this.raw, options, this);
|
|
638
|
+
}
|
|
639
|
+
createStreamTokenizer(options) {
|
|
640
|
+
return new ShikiStreamTokenizer(this.raw, this.resolveOptions(options));
|
|
641
|
+
}
|
|
642
|
+
async loadLanguages(languages) {
|
|
643
|
+
this.assertNotDisposed();
|
|
644
|
+
const missing = languages.filter((language) => !this.attachedLanguages.has(language));
|
|
645
|
+
attachResolvedLanguages(await resolveLanguages(missing), this);
|
|
646
|
+
}
|
|
647
|
+
hasLoadedLanguages(languages) {
|
|
648
|
+
if (this.disposed) return false;
|
|
649
|
+
let loaded;
|
|
650
|
+
return languages.every((lang) => {
|
|
651
|
+
if (this.attachedLanguages.has(lang)) return true;
|
|
652
|
+
if (RegisteredCustomLanguages.has(lang)) return false;
|
|
653
|
+
loaded ??= this.raw.getLoadedLanguages();
|
|
654
|
+
return loaded.includes(lang);
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
attachLanguages(languages) {
|
|
658
|
+
this.assertNotDisposed();
|
|
659
|
+
for (const lang of languages) {
|
|
660
|
+
if (this.attachedLanguages.has(lang.name)) continue;
|
|
661
|
+
const grammar = lang.data.find((grammar) => grammar.name === lang.name || grammar.aliases?.includes(lang.name) === true);
|
|
662
|
+
if (grammar == null) throw new Error(`attachResolvedLanguages: No returned grammar declares "${lang.name}" as its name or an alias.`);
|
|
663
|
+
this.raw.loadLanguageSync(lang.data);
|
|
664
|
+
try {
|
|
665
|
+
this.raw.getLanguage(lang.name);
|
|
666
|
+
} catch {
|
|
667
|
+
throw new Error(`attachResolvedLanguages: "${grammar.name}" is already loaded without alias "${lang.name}". Load the alias first or give the grammar a unique name.`);
|
|
668
|
+
}
|
|
669
|
+
this.attachedLanguages.add(lang.name);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
releaseResources() {
|
|
673
|
+
this.loadedThemes.clear();
|
|
674
|
+
this.attachedLanguages.clear();
|
|
675
|
+
this.raw.dispose();
|
|
676
|
+
}
|
|
677
|
+
resolveOptions({ theme, themes, ...options }) {
|
|
678
|
+
this.assertNotDisposed();
|
|
679
|
+
if (theme != null) {
|
|
680
|
+
this.getTheme(theme);
|
|
681
|
+
return {
|
|
682
|
+
...options,
|
|
683
|
+
theme
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
if (themes == null) throw new Error("A theme or themes option is required");
|
|
687
|
+
for (const name of Object.values(themes)) this.getTheme(name);
|
|
688
|
+
return {
|
|
689
|
+
...options,
|
|
690
|
+
themes
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
//#endregion
|
|
695
|
+
export { ShikiHighlighter };
|
|
696
|
+
|
|
697
|
+
//# sourceMappingURL=shiki-Ci4cdHsM.js.map
|