@pierre/diffs 1.5.1 → 1.6.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/README.md +4 -3
  2. package/dist/components/CodeView.d.ts +2 -1
  3. package/dist/components/CodeView.d.ts.map +1 -1
  4. package/dist/components/CodeView.js +27 -16
  5. package/dist/components/CodeView.js.map +1 -1
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +14 -7
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +7 -4
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +16 -9
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/FileStream.d.ts +6 -4
  14. package/dist/components/FileStream.d.ts.map +1 -1
  15. package/dist/components/FileStream.js +49 -36
  16. package/dist/components/FileStream.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  18. package/dist/components/VirtualizedFile.js +10 -5
  19. package/dist/components/VirtualizedFile.js.map +1 -1
  20. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.js +3 -4
  22. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  23. package/dist/constants.d.ts +3 -2
  24. package/dist/constants.d.ts.map +1 -1
  25. package/dist/constants.js +2 -1
  26. package/dist/constants.js.map +1 -1
  27. package/dist/editor/editor.d.ts +2 -1
  28. package/dist/editor/editor.d.ts.map +1 -1
  29. package/dist/editor/editor.js +10 -3
  30. package/dist/editor/editor.js.map +1 -1
  31. package/dist/editor/getChangedDocumentLines.d.ts +6 -0
  32. package/dist/editor/getChangedDocumentLines.d.ts.map +1 -0
  33. package/dist/editor/getChangedDocumentLines.js +35 -0
  34. package/dist/editor/getChangedDocumentLines.js.map +1 -0
  35. package/dist/editor/tokenizer.d.ts +6 -4
  36. package/dist/editor/tokenizer.d.ts.map +1 -1
  37. package/dist/editor/tokenizer.js +25 -470
  38. package/dist/editor/tokenizer.js.map +1 -1
  39. package/dist/highlighter/DiffsEditorTokenizer.d.ts +16 -0
  40. package/dist/highlighter/DiffsEditorTokenizer.d.ts.map +1 -0
  41. package/dist/highlighter/DiffsEditorTokenizer.js +0 -0
  42. package/dist/highlighter/DiffsHighlighter.d.ts +41 -0
  43. package/dist/highlighter/DiffsHighlighter.d.ts.map +1 -0
  44. package/dist/highlighter/DiffsHighlighter.js +39 -0
  45. package/dist/highlighter/DiffsHighlighter.js.map +1 -0
  46. package/dist/highlighter/backends/highlights.d.ts +26 -0
  47. package/dist/highlighter/backends/highlights.d.ts.map +1 -0
  48. package/dist/highlighter/backends/highlights.js +71 -0
  49. package/dist/highlighter/backends/highlights.js.map +1 -0
  50. package/dist/highlighter/backends/shiki.d.ts +27 -0
  51. package/dist/highlighter/backends/shiki.d.ts.map +1 -0
  52. package/dist/highlighter/backends/shiki.js +107 -0
  53. package/dist/highlighter/backends/shiki.js.map +1 -0
  54. package/dist/highlighter/highlighterType.d.ts +13 -0
  55. package/dist/highlighter/highlighterType.d.ts.map +1 -0
  56. package/dist/highlighter/highlighterType.js +32 -0
  57. package/dist/highlighter/highlighterType.js.map +1 -0
  58. package/dist/highlighter/highlights-editor.d.ts +24 -0
  59. package/dist/highlighter/highlights-editor.d.ts.map +1 -0
  60. package/dist/highlighter/highlights-editor.js +166 -0
  61. package/dist/highlighter/highlights-editor.js.map +1 -0
  62. package/dist/highlighter/highlights-stream.d.ts +20 -0
  63. package/dist/highlighter/highlights-stream.d.ts.map +1 -0
  64. package/dist/highlighter/highlights-stream.js +93 -0
  65. package/dist/highlighter/highlights-stream.js.map +1 -0
  66. package/dist/highlighter/languages/areLanguagesAttached.d.ts +2 -1
  67. package/dist/highlighter/languages/areLanguagesAttached.d.ts.map +1 -1
  68. package/dist/highlighter/languages/areLanguagesAttached.js +4 -6
  69. package/dist/highlighter/languages/areLanguagesAttached.js.map +1 -1
  70. package/dist/highlighter/languages/attachResolvedLanguages.d.ts +6 -1
  71. package/dist/highlighter/languages/attachResolvedLanguages.d.ts.map +1 -1
  72. package/dist/highlighter/languages/attachResolvedLanguages.js +6 -11
  73. package/dist/highlighter/languages/attachResolvedLanguages.js.map +1 -1
  74. package/dist/highlighter/languages/constants.d.ts +1 -1
  75. package/dist/highlighter/languages/getResolvedLanguages.d.ts +1 -1
  76. package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts +1 -1
  77. package/dist/highlighter/languages/resolveLanguage.d.ts +1 -1
  78. package/dist/highlighter/languages/resolveLanguage.d.ts.map +1 -1
  79. package/dist/highlighter/languages/resolveLanguage.js +19 -16
  80. package/dist/highlighter/languages/resolveLanguage.js.map +1 -1
  81. package/dist/highlighter/languages/resolveLanguages.d.ts +1 -1
  82. package/dist/highlighter/shared_highlighter.d.ts +23 -9
  83. package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
  84. package/dist/highlighter/shared_highlighter.js +59 -47
  85. package/dist/highlighter/shared_highlighter.js.map +1 -1
  86. package/dist/highlighter/shiki-editor.d.ts +25 -0
  87. package/dist/highlighter/shiki-editor.d.ts.map +1 -0
  88. package/dist/highlighter/shiki-editor.js +483 -0
  89. package/dist/highlighter/shiki-editor.js.map +1 -0
  90. package/dist/highlighter/shiki-stream.d.ts +20 -0
  91. package/dist/highlighter/shiki-stream.d.ts.map +1 -0
  92. package/dist/highlighter/shiki-stream.js +60 -0
  93. package/dist/highlighter/shiki-stream.js.map +1 -0
  94. package/dist/highlighter/stream-tokenizer.d.ts +40 -0
  95. package/dist/highlighter/stream-tokenizer.d.ts.map +1 -0
  96. package/dist/highlighter/stream-tokenizer.js +70 -0
  97. package/dist/highlighter/stream-tokenizer.js.map +1 -0
  98. package/dist/highlighter/themes/areThemesAttached.d.ts +3 -2
  99. package/dist/highlighter/themes/areThemesAttached.d.ts.map +1 -1
  100. package/dist/highlighter/themes/areThemesAttached.js +5 -4
  101. package/dist/highlighter/themes/areThemesAttached.js.map +1 -1
  102. package/dist/highlighter/themes/attachResolvedThemes.d.ts +5 -2
  103. package/dist/highlighter/themes/attachResolvedThemes.d.ts.map +1 -1
  104. package/dist/highlighter/themes/attachResolvedThemes.js +4 -16
  105. package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
  106. package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts +3 -1
  107. package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts.map +1 -1
  108. package/dist/highlighter/themes/cleanUpResolvedThemes.js +8 -5
  109. package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
  110. package/dist/highlighter/themes/createCSSVariablesTheme.d.ts +7 -0
  111. package/dist/highlighter/themes/createCSSVariablesTheme.d.ts.map +1 -0
  112. package/dist/highlighter/themes/createCSSVariablesTheme.js +89 -0
  113. package/dist/highlighter/themes/createCSSVariablesTheme.js.map +1 -0
  114. package/dist/highlighter/themes/createCachedLoader.d.ts +5 -0
  115. package/dist/highlighter/themes/createCachedLoader.d.ts.map +1 -0
  116. package/dist/highlighter/themes/createCachedLoader.js +15 -0
  117. package/dist/highlighter/themes/createCachedLoader.js.map +1 -0
  118. package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts +3 -2
  119. package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts.map +1 -1
  120. package/dist/highlighter/themes/getResolvedOrResolveTheme.js +4 -4
  121. package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
  122. package/dist/highlighter/themes/getResolvedThemes.d.ts +3 -2
  123. package/dist/highlighter/themes/getResolvedThemes.d.ts.map +1 -1
  124. package/dist/highlighter/themes/getResolvedThemes.js +4 -3
  125. package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
  126. package/dist/highlighter/themes/hasResolvedThemes.d.ts +2 -2
  127. package/dist/highlighter/themes/hasResolvedThemes.d.ts.map +1 -1
  128. package/dist/highlighter/themes/hasResolvedThemes.js +4 -3
  129. package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
  130. package/dist/highlighter/themes/registerCustomCSSVariableTheme.d.ts.map +1 -1
  131. package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +3 -3
  132. package/dist/highlighter/themes/registerCustomCSSVariableTheme.js.map +1 -1
  133. package/dist/highlighter/themes/registerCustomTheme.d.ts +9 -4
  134. package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
  135. package/dist/highlighter/themes/registerCustomTheme.js +8 -16
  136. package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
  137. package/dist/highlighter/themes/resolveTheme.d.ts +3 -2
  138. package/dist/highlighter/themes/resolveTheme.d.ts.map +1 -1
  139. package/dist/highlighter/themes/resolveTheme.js +4 -7
  140. package/dist/highlighter/themes/resolveTheme.js.map +1 -1
  141. package/dist/highlighter/themes/resolveThemes.d.ts +3 -2
  142. package/dist/highlighter/themes/resolveThemes.d.ts.map +1 -1
  143. package/dist/highlighter/themes/resolveThemes.js +4 -7
  144. package/dist/highlighter/themes/resolveThemes.js.map +1 -1
  145. package/dist/highlighter/themes/themeResolver.d.ts +10 -4
  146. package/dist/highlighter/themes/themeResolver.d.ts.map +1 -1
  147. package/dist/highlighter/themes/themeResolver.js +141 -2
  148. package/dist/highlighter/themes/themeResolver.js.map +1 -1
  149. package/dist/highlighter/themes/types.d.ts +23 -0
  150. package/dist/highlighter/themes/types.d.ts.map +1 -0
  151. package/dist/highlighter/themes/types.js +0 -0
  152. package/dist/highlighter/tokenizer-types.d.ts +35 -0
  153. package/dist/highlighter/tokenizer-types.d.ts.map +1 -0
  154. package/dist/highlighter/tokenizer-types.js +0 -0
  155. package/dist/highlighter/types.d.ts +55 -0
  156. package/dist/highlighter/types.d.ts.map +1 -0
  157. package/dist/highlighter/types.js +0 -0
  158. package/dist/index.d.ts +14 -10
  159. package/dist/index.js +16 -18
  160. package/dist/managers/InteractionManager.d.ts.map +1 -1
  161. package/dist/managers/InteractionManager.js +2 -2
  162. package/dist/managers/InteractionManager.js.map +1 -1
  163. package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts +9 -1
  164. package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts.map +1 -1
  165. package/dist/react/CodeView.js +1 -1
  166. package/dist/react/index.d.ts +8 -3
  167. package/dist/renderers/DiffHunksRenderer.d.ts +3 -2
  168. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  169. package/dist/renderers/DiffHunksRenderer.js +50 -24
  170. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  171. package/dist/renderers/FileRenderer.d.ts +2 -1
  172. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  173. package/dist/renderers/FileRenderer.js +33 -24
  174. package/dist/renderers/FileRenderer.js.map +1 -1
  175. package/dist/shiki-stream/index.d.ts +3 -3
  176. package/dist/shiki-stream/index.js +1 -2
  177. package/dist/shiki-stream/stream.d.ts +4 -4
  178. package/dist/shiki-stream/stream.d.ts.map +1 -1
  179. package/dist/shiki-stream/stream.js +20 -9
  180. package/dist/shiki-stream/stream.js.map +1 -1
  181. package/dist/shiki-stream/types.d.ts +7 -38
  182. package/dist/shiki-stream/types.d.ts.map +1 -1
  183. package/dist/ssr/FileDiffReact.js +1 -1
  184. package/dist/ssr/index.d.ts +7 -2
  185. package/dist/ssr/renderHTML.js +2 -2
  186. package/dist/ssr/renderHTML.js.map +1 -1
  187. package/dist/style.js +1 -1
  188. package/dist/style.js.map +1 -1
  189. package/dist/types.d.ts +13 -13
  190. package/dist/types.d.ts.map +1 -1
  191. package/dist/utils/computeVirtualFileMetrics.d.ts +2 -1
  192. package/dist/utils/computeVirtualFileMetrics.d.ts.map +1 -1
  193. package/dist/utils/computeVirtualFileMetrics.js +5 -3
  194. package/dist/utils/computeVirtualFileMetrics.js.map +1 -1
  195. package/dist/utils/createSpanNodeFromToken.d.ts +3 -2
  196. package/dist/utils/createSpanNodeFromToken.d.ts.map +1 -1
  197. package/dist/utils/createSpanNodeFromToken.js +4 -5
  198. package/dist/utils/createSpanNodeFromToken.js.map +1 -1
  199. package/dist/utils/cssWrappers.d.ts.map +1 -1
  200. package/dist/utils/cssWrappers.js +12 -0
  201. package/dist/utils/cssWrappers.js.map +1 -1
  202. package/dist/utils/getDiffHunksRendererOptions.js +1 -0
  203. package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
  204. package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
  205. package/dist/utils/getFiletypeFromFileName.js +21 -3
  206. package/dist/utils/getFiletypeFromFileName.js.map +1 -1
  207. package/dist/utils/getHighlighterOptions.d.ts.map +1 -1
  208. package/dist/utils/getHighlighterOptions.js +3 -2
  209. package/dist/utils/getHighlighterOptions.js.map +1 -1
  210. package/dist/utils/getHighlighterThemeStyles.d.ts +2 -1
  211. package/dist/utils/getHighlighterThemeStyles.d.ts.map +1 -1
  212. package/dist/utils/getHighlighterThemeStyles.js +13 -3
  213. package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
  214. package/dist/utils/getTokenOptions.d.ts +7 -0
  215. package/dist/utils/getTokenOptions.d.ts.map +1 -0
  216. package/dist/utils/getTokenOptions.js +16 -0
  217. package/dist/utils/getTokenOptions.js.map +1 -0
  218. package/dist/utils/hastToHtml.d.ts +10 -0
  219. package/dist/utils/hastToHtml.d.ts.map +1 -0
  220. package/dist/utils/hastToHtml.js +125 -0
  221. package/dist/utils/hastToHtml.js.map +1 -0
  222. package/dist/utils/parseDiffDecorations.d.ts +2 -1
  223. package/dist/utils/parseDiffDecorations.d.ts.map +1 -1
  224. package/dist/utils/platform.d.ts +2 -1
  225. package/dist/utils/platform.d.ts.map +1 -1
  226. package/dist/utils/platform.js +6 -1
  227. package/dist/utils/platform.js.map +1 -1
  228. package/dist/utils/renderDiffWithHighlighter.d.ts +3 -2
  229. package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
  230. package/dist/utils/renderDiffWithHighlighter.js +33 -48
  231. package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  232. package/dist/utils/renderFileWithHighlighter.d.ts +3 -2
  233. package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
  234. package/dist/utils/renderFileWithHighlighter.js +10 -26
  235. package/dist/utils/renderFileWithHighlighter.js.map +1 -1
  236. package/dist/utils/renderTokenLines.d.ts +17 -0
  237. package/dist/utils/renderTokenLines.d.ts.map +1 -0
  238. package/dist/utils/renderTokenLines.js +246 -0
  239. package/dist/utils/renderTokenLines.js.map +1 -0
  240. package/dist/utils/resolvePreferredHighlighter.d.ts +13 -0
  241. package/dist/utils/resolvePreferredHighlighter.d.ts.map +1 -0
  242. package/dist/utils/resolvePreferredHighlighter.js +11 -0
  243. package/dist/utils/resolvePreferredHighlighter.js.map +1 -0
  244. package/dist/utils/setDeferredArrayItem.d.ts +5 -0
  245. package/dist/utils/setDeferredArrayItem.d.ts.map +1 -0
  246. package/dist/utils/setDeferredArrayItem.js +39 -0
  247. package/dist/utils/setDeferredArrayItem.js.map +1 -0
  248. package/dist/utils/tokenStyle.d.ts +7 -0
  249. package/dist/utils/tokenStyle.d.ts.map +1 -0
  250. package/dist/utils/tokenStyle.js +28 -0
  251. package/dist/utils/tokenStyle.js.map +1 -0
  252. package/dist/utils/tokensToHtml.d.ts +8 -0
  253. package/dist/utils/tokensToHtml.d.ts.map +1 -0
  254. package/dist/utils/tokensToHtml.js +45 -0
  255. package/dist/utils/tokensToHtml.js.map +1 -0
  256. package/dist/utils/wrapTokenFragments.js.map +1 -1
  257. package/dist/worker/WorkerPoolManager.d.ts +10 -2
  258. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  259. package/dist/worker/WorkerPoolManager.js +85 -60
  260. package/dist/worker/WorkerPoolManager.js.map +1 -1
  261. package/dist/worker/errors.d.ts +35 -0
  262. package/dist/worker/errors.d.ts.map +1 -0
  263. package/dist/worker/errors.js +52 -0
  264. package/dist/worker/errors.js.map +1 -0
  265. package/dist/worker/hastLinesTransport.d.ts +14 -0
  266. package/dist/worker/hastLinesTransport.d.ts.map +1 -0
  267. package/dist/worker/hastLinesTransport.js +156 -0
  268. package/dist/worker/hastLinesTransport.js.map +1 -0
  269. package/dist/worker/highlights-sAHlxqlf.js +317 -0
  270. package/dist/worker/highlights-sAHlxqlf.js.map +1 -0
  271. package/dist/worker/index.d.ts +2 -1
  272. package/dist/worker/index.js +2 -1
  273. package/dist/worker/shiki-Bx2JpdqZ.js +697 -0
  274. package/dist/worker/shiki-Bx2JpdqZ.js.map +1 -0
  275. package/dist/worker/stream-tokenizer-YZ6M1qSx.js +424 -0
  276. package/dist/worker/stream-tokenizer-YZ6M1qSx.js.map +1 -0
  277. package/dist/worker/types.d.ts +18 -3
  278. package/dist/worker/types.d.ts.map +1 -1
  279. package/dist/worker/worker-portable.js +41 -13319
  280. package/dist/worker/worker-portable.js.map +1 -1
  281. package/dist/worker/worker.js +693 -352
  282. package/dist/worker/worker.js.map +1 -1
  283. package/dist/worker/workerMessage.d.ts +24 -0
  284. package/dist/worker/workerMessage.d.ts.map +1 -0
  285. package/dist/worker/workerMessage.js +0 -0
  286. package/package.json +33 -29
  287. package/dist/highlighter/themes/constants.d.ts +0 -5
  288. package/dist/highlighter/themes/constants.d.ts.map +0 -1
  289. package/dist/highlighter/themes/constants.js +0 -6
  290. package/dist/highlighter/themes/constants.js.map +0 -1
  291. package/dist/highlighter/themes/themeResolution.d.ts +0 -7
  292. package/dist/highlighter/themes/themeResolution.d.ts.map +0 -1
  293. package/dist/highlighter/themes/themeResolution.js +0 -21
  294. package/dist/highlighter/themes/themeResolution.js.map +0 -1
  295. package/dist/shiki-stream/tokenizer.d.ts +0 -23
  296. package/dist/shiki-stream/tokenizer.d.ts.map +0 -1
  297. package/dist/shiki-stream/tokenizer.js +0 -72
  298. package/dist/shiki-stream/tokenizer.js.map +0 -1
  299. package/dist/utils/createTransformerWithState.d.ts +0 -12
  300. package/dist/utils/createTransformerWithState.d.ts.map +0 -1
  301. package/dist/utils/createTransformerWithState.js +0 -89
  302. package/dist/utils/createTransformerWithState.js.map +0 -1
  303. package/dist/worker/wasm-B9ZqxnKj.js +0 -8
  304. package/dist/worker/wasm-B9ZqxnKj.js.map +0 -1
@@ -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 {
@@ -23,52 +18,78 @@ Object.freeze({
23
18
  //#endregion
24
19
  //#region src/highlighter/languages/constants.ts
25
20
  const ResolvedLanguages = /* @__PURE__ */ new Map();
21
+ const ResolvingLanguages = /* @__PURE__ */ new Map();
22
+ const RegisteredCustomLanguages = /* @__PURE__ */ new Map();
26
23
  const AttachedLanguages = /* @__PURE__ */ new Set();
27
24
  //#endregion
28
25
  //#region src/highlighter/languages/attachResolvedLanguages.ts
26
+ /**
27
+ * Record resolved grammars in the shared language cache and attach them to a
28
+ * highlighter. Highlights bundles its lexers and ignores the grammars.
29
+ */
29
30
  function attachResolvedLanguages(resolvedLanguages, highlighter) {
30
- resolvedLanguages = Array.isArray(resolvedLanguages) ? resolvedLanguages : [resolvedLanguages];
31
- for (const resolvedLang of resolvedLanguages) {
32
- if (AttachedLanguages.has(resolvedLang.name)) continue;
31
+ for (const resolvedLang of Array.isArray(resolvedLanguages) ? resolvedLanguages : [resolvedLanguages]) {
33
32
  let lang = ResolvedLanguages.get(resolvedLang.name);
34
33
  if (lang == null) {
35
34
  lang = resolvedLang;
36
35
  ResolvedLanguages.set(resolvedLang.name, lang);
37
36
  }
38
- const grammar = lang.data.find((grammar) => grammar.name === lang.name || grammar.aliases?.includes(lang.name) === true);
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
- }
37
+ highlighter.attachLanguages([lang]);
46
38
  AttachedLanguages.add(lang.name);
47
39
  }
48
40
  }
49
41
  //#endregion
50
- //#region src/highlighter/themes/constants.ts
51
- const AttachedThemes = /* @__PURE__ */ new Set();
42
+ //#region src/highlighter/highlighterType.ts
43
+ let activeType;
44
+ let holds = 0;
45
+ var HighlighterDisposedError = class extends Error {
46
+ constructor() {
47
+ super("Highlighter is disposed");
48
+ this.name = "HighlighterDisposedError";
49
+ }
50
+ };
51
+ function resolveHighlighterType(type) {
52
+ return type ?? activeType ?? "shiki-js";
53
+ }
54
+ function assertHighlighterType(type) {
55
+ 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.`);
56
+ }
57
+ function acquireHighlighterType(type) {
58
+ assertHighlighterType(type);
59
+ activeType = type;
60
+ holds++;
61
+ }
62
+ function releaseHighlighterType() {
63
+ holds--;
64
+ if (holds === 0) activeType = void 0;
65
+ }
52
66
  //#endregion
53
- //#region src/highlighter/themes/themeResolver.ts
54
- const themeResolver = createThemeResolver();
67
+ //#region src/highlighter/shared_highlighter.ts
68
+ /**
69
+ * Creates an instance the caller must dispose. Defaults to the active type
70
+ * or DEFAULT_HIGHLIGHTER; rejects if a different type is already active.
71
+ */
72
+ async function createHighlighter(type) {
73
+ const resolvedType = resolveHighlighterType(type);
74
+ acquireHighlighterType(resolvedType);
75
+ try {
76
+ if (resolvedType === "highlights") {
77
+ const { HighlightsHighlighter } = await import("./highlights-sAHlxqlf.js");
78
+ return new HighlightsHighlighter();
79
+ }
80
+ const { ShikiHighlighter } = await import("./shiki-Bx2JpdqZ.js");
81
+ return await ShikiHighlighter.create(resolvedType);
82
+ } finally {
83
+ releaseHighlighterType();
84
+ }
85
+ }
55
86
  //#endregion
56
87
  //#region src/highlighter/themes/attachResolvedThemes.ts
88
+ /** Seed themes received from the main thread into the worker's backend resolver. */
57
89
  function attachResolvedThemes(themes, highlighter) {
58
- themes = Array.isArray(themes) ? themes : [themes];
59
- for (let themeRef of themes) {
60
- let resolvedTheme;
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);
90
+ for (const theme of Array.isArray(themes) ? themes : [themes]) {
91
+ const resolved = typeof theme === "string" ? highlighter.themeResolver.getResolvedThemes([theme])[0] : theme;
92
+ highlighter.themeResolver.seedResolvedTheme(resolved.name, resolved);
72
93
  }
73
94
  }
74
95
  //#endregion
@@ -281,6 +302,7 @@ const EXTENSION_TO_FILE_FORMAT = {
281
302
  mli: "ocaml",
282
303
  mll: "ocaml",
283
304
  mly: "ocaml",
305
+ odin: "odin",
284
306
  pas: "pascal",
285
307
  p: "pascal",
286
308
  pl: "prolog",
@@ -313,6 +335,17 @@ const EXTENSION_TO_FILE_FORMAT = {
313
335
  py: "python",
314
336
  pyw: "python",
315
337
  pyi: "python",
338
+ BUCK: "python",
339
+ BUILD: "python",
340
+ PACKAGE: "python",
341
+ WORKSPACE: "python",
342
+ Tiltfile: "python",
343
+ bazel: "python",
344
+ bxl: "python",
345
+ bzl: "python",
346
+ bzlmod: "python",
347
+ star: "python",
348
+ sky: "python",
316
349
  qml: "qml",
317
350
  qmldir: "qmldir",
318
351
  qss: "qss",
@@ -423,16 +456,22 @@ const EXTENSION_TO_FILE_FORMAT = {
423
456
  sty: "tex"
424
457
  };
425
458
  function getFiletypeFromFileName(fileName) {
459
+ const format = matchFiletypeFromName(fileName);
460
+ if (format != null) return format;
461
+ const baseName = fileName.split(/[/\\]/).pop() ?? fileName;
462
+ return baseName === fileName ? "text" : matchFiletypeFromName(baseName) ?? "text";
463
+ }
464
+ function matchFiletypeFromName(fileName) {
426
465
  if (CUSTOM_EXTENSION_TO_FILE_FORMAT.has(fileName)) return CUSTOM_EXTENSION_TO_FILE_FORMAT.get(fileName) ?? "text";
427
- if (EXTENSION_TO_FILE_FORMAT[fileName] != null) return EXTENSION_TO_FILE_FORMAT[fileName];
466
+ if (Object.hasOwn(EXTENSION_TO_FILE_FORMAT, fileName)) return EXTENSION_TO_FILE_FORMAT[fileName] ?? null;
428
467
  const compoundMatch = fileName.match(/\.([^/\\]+\.[^/\\]+)$/);
429
468
  if (compoundMatch != null) {
430
469
  if (CUSTOM_EXTENSION_TO_FILE_FORMAT.has(compoundMatch[1])) return CUSTOM_EXTENSION_TO_FILE_FORMAT.get(compoundMatch[1]) ?? "text";
431
- if (EXTENSION_TO_FILE_FORMAT[compoundMatch[1]] != null) return EXTENSION_TO_FILE_FORMAT[compoundMatch[1]] ?? "text";
470
+ if (Object.hasOwn(EXTENSION_TO_FILE_FORMAT, compoundMatch[1])) return EXTENSION_TO_FILE_FORMAT[compoundMatch[1]] ?? "text";
432
471
  }
433
472
  const simpleMatch = fileName.match(/\.([^.]+)$/)?.[1] ?? "";
434
473
  if (CUSTOM_EXTENSION_TO_FILE_FORMAT.has(simpleMatch)) return CUSTOM_EXTENSION_TO_FILE_FORMAT.get(simpleMatch) ?? "text";
435
- return EXTENSION_TO_FILE_FORMAT[simpleMatch] ?? "text";
474
+ return Object.hasOwn(EXTENSION_TO_FILE_FORMAT, simpleMatch) ? EXTENSION_TO_FILE_FORMAT[simpleMatch] ?? "text" : null;
436
475
  }
437
476
  function replaceCustomExtensions(version, map) {
438
477
  if (version <= customExtensionsVersion) return false;
@@ -460,210 +499,6 @@ function cleanLastNewline(contents) {
460
499
  return contents.slice(0, end);
461
500
  }
462
501
  //#endregion
463
- //#region src/utils/hast_utils.ts
464
- function createTextNodeElement(value) {
465
- return {
466
- type: "text",
467
- value
468
- };
469
- }
470
- function createHastElement({ tagName, children = [], properties = {} }) {
471
- return {
472
- type: "element",
473
- tagName,
474
- properties,
475
- children
476
- };
477
- }
478
- function findCodeElement(nodes) {
479
- let firstChild = nodes.children[0];
480
- while (firstChild != null) {
481
- if (firstChild.type === "element" && firstChild.tagName === "code") return firstChild;
482
- if ("children" in firstChild) firstChild = firstChild.children[0];
483
- else firstChild = null;
484
- }
485
- }
486
- //#endregion
487
- //#region src/utils/processLine.ts
488
- function processLine(node, line, state) {
489
- const lineInfo = typeof state.lineInfo === "function" ? state.lineInfo(line) : state.lineInfo[line - 1];
490
- if (lineInfo == null) {
491
- const errorMessage = `processLine: line ${line}, contains no state.lineInfo`;
492
- console.error(errorMessage, {
493
- node,
494
- line,
495
- state
496
- });
497
- throw new Error(errorMessage);
498
- }
499
- node.tagName = "div";
500
- node.properties["data-line"] = lineInfo.lineNumber;
501
- node.properties["data-alt-line"] = lineInfo.altLineNumber;
502
- node.properties["data-line-type"] = lineInfo.type;
503
- node.properties["data-line-index"] = lineInfo.lineIndex;
504
- if (node.children.length === 0) node.children.push(createTextNodeElement("\n"));
505
- return node;
506
- }
507
- //#endregion
508
- //#region src/utils/wrapTokenFragments.ts
509
- const NO_TOKEN = Symbol("no-token");
510
- const MULTIPLE_TOKENS = Symbol("multiple-tokens");
511
- function wrapTokenFragments(container) {
512
- const ownTokenChar = getTokenChar(container);
513
- if (ownTokenChar != null) return ownTokenChar;
514
- let containerTokenState = NO_TOKEN;
515
- const wrappedChildren = [];
516
- let currentTokenChildren = [];
517
- let currentTokenChar;
518
- const flushTokenChildren = () => {
519
- if (currentTokenChildren.length === 0 || currentTokenChar == null) {
520
- currentTokenChildren = [];
521
- currentTokenChar = void 0;
522
- return;
523
- }
524
- if (currentTokenChildren.length === 1) {
525
- const child = currentTokenChildren[0];
526
- if (child?.type === "element") {
527
- setTokenChar(child, currentTokenChar);
528
- for (const grandChild of child.children) stripTokenChar(grandChild);
529
- } else stripTokenChar(child);
530
- wrappedChildren.push(child);
531
- currentTokenChildren = [];
532
- currentTokenChar = void 0;
533
- return;
534
- }
535
- for (const child of currentTokenChildren) stripTokenChar(child);
536
- wrappedChildren.push(createHastElement({
537
- tagName: "span",
538
- properties: { "data-char": currentTokenChar },
539
- children: currentTokenChildren
540
- }));
541
- currentTokenChildren = [];
542
- currentTokenChar = void 0;
543
- };
544
- const mergeContainerTokenState = (childTokenState) => {
545
- if (childTokenState === NO_TOKEN) return;
546
- if (childTokenState === MULTIPLE_TOKENS) {
547
- containerTokenState = MULTIPLE_TOKENS;
548
- return;
549
- }
550
- if (containerTokenState === NO_TOKEN) {
551
- containerTokenState = childTokenState;
552
- return;
553
- }
554
- if (containerTokenState !== childTokenState) containerTokenState = MULTIPLE_TOKENS;
555
- };
556
- for (const child of container.children) {
557
- const childTokenState = child.type === "element" ? wrapTokenFragments(child) : NO_TOKEN;
558
- mergeContainerTokenState(childTokenState);
559
- if (typeof childTokenState !== "number") {
560
- flushTokenChildren();
561
- wrappedChildren.push(child);
562
- continue;
563
- }
564
- if (currentTokenChar != null && currentTokenChar !== childTokenState) flushTokenChildren();
565
- currentTokenChar ??= childTokenState;
566
- currentTokenChildren.push(child);
567
- }
568
- flushTokenChildren();
569
- container.children = wrappedChildren;
570
- return containerTokenState;
571
- }
572
- function getTokenChar(node) {
573
- const value = node.properties["data-char"];
574
- if (typeof value === "number") return value;
575
- }
576
- function stripTokenChar(node) {
577
- if (node.type !== "element") return;
578
- node.properties["data-char"] = void 0;
579
- for (const child of node.children) stripTokenChar(child);
580
- }
581
- function setTokenChar(node, char) {
582
- node.properties["data-char"] = char;
583
- }
584
- //#endregion
585
- //#region src/utils/createTransformerWithState.ts
586
- function createTransformerWithState(useTokenTransformer = false, useCSSClasses = false) {
587
- const state = { lineInfo: [] };
588
- const transformers = [{
589
- line(node) {
590
- delete node.properties.class;
591
- return node;
592
- },
593
- pre(pre) {
594
- const code = findCodeElement(pre);
595
- const children = [];
596
- if (code != null) {
597
- let index = 1;
598
- for (const node of code.children) {
599
- if (node.type !== "element") continue;
600
- if (useTokenTransformer) wrapTokenFragments(node);
601
- children.push(processLine(node, index, state));
602
- index++;
603
- }
604
- code.children = children;
605
- }
606
- return pre;
607
- },
608
- ...useTokenTransformer ? {
609
- tokens(lines) {
610
- for (const line of lines) {
611
- let col = 0;
612
- for (const token of line) {
613
- const tokenWithOriginalRange = token;
614
- tokenWithOriginalRange.__lineChar ??= col;
615
- col += token.content.length;
616
- }
617
- }
618
- },
619
- preprocess(_code, options) {
620
- options.mergeWhitespaces = "never";
621
- },
622
- span(hast, _line, _char, _lineElement, token) {
623
- if (token?.offset != null && token.content != null) {
624
- const tokenChar = token.__lineChar;
625
- if (tokenChar != null) hast.properties["data-char"] = tokenChar;
626
- return hast;
627
- }
628
- return hast;
629
- }
630
- } : null
631
- }];
632
- if (useCSSClasses) transformers.push(tokenStyleNormalizer, toClass);
633
- if (useTokenTransformer) transformers.push({ line: (node) => {
634
- if (node.type === "element" && node.children.length === 0) node.children.push({
635
- type: "element",
636
- tagName: "br",
637
- properties: {},
638
- children: []
639
- });
640
- return node;
641
- } });
642
- return {
643
- state,
644
- transformers,
645
- toClass
646
- };
647
- }
648
- const toClass = transformerStyleToClass({ classPrefix: "hl-" });
649
- const tokenStyleNormalizer = {
650
- name: "token-style-normalizer",
651
- tokens(lines) {
652
- for (const line of lines) for (const token of line) {
653
- if (token.htmlStyle != null) continue;
654
- const style = {};
655
- if (token.color != null) style.color = token.color;
656
- if (token.bgColor != null) style["background-color"] = token.bgColor;
657
- if (token.fontStyle != null && token.fontStyle !== 0) {
658
- if ((token.fontStyle & 1) !== 0) style["font-style"] = "italic";
659
- if ((token.fontStyle & 2) !== 0) style["font-weight"] = "bold";
660
- if ((token.fontStyle & 4) !== 0) style["text-decoration"] = "underline";
661
- }
662
- if (Object.keys(style).length > 0) token.htmlStyle = style;
663
- }
664
- }
665
- };
666
- //#endregion
667
502
  //#region src/utils/formatCSSVariablePrefix.ts
668
503
  function formatCSSVariablePrefix(type) {
669
504
  return `--${type === "token" ? "diffs-token" : "diffs"}-`;
@@ -674,7 +509,7 @@ function getHighlighterThemeStyles({ theme = DEFAULT_THEMES, highlighter, prefix
674
509
  let styles = "";
675
510
  if (typeof theme === "string") {
676
511
  const themeData = highlighter.getTheme(theme);
677
- const normalized = normalizeThemeColors(themeData);
512
+ const normalized = getThemeColors(themeData, highlighter);
678
513
  styles += `color:${normalized.fg};`;
679
514
  styles += `background-color:${normalized.bg};`;
680
515
  styles += `${formatCSSVariablePrefix("global")}fg:${normalized.fg};`;
@@ -682,18 +517,28 @@ function getHighlighterThemeStyles({ theme = DEFAULT_THEMES, highlighter, prefix
682
517
  styles += getGitVariables(themeData, prefix);
683
518
  } else {
684
519
  let themeData = highlighter.getTheme(theme.dark);
685
- let normalized = normalizeThemeColors(themeData);
520
+ let normalized = getThemeColors(themeData, highlighter);
686
521
  styles += `${formatCSSVariablePrefix("global")}dark:${normalized.fg};`;
687
522
  styles += `${formatCSSVariablePrefix("global")}dark-bg:${normalized.bg};`;
688
523
  styles += getGitVariables(themeData, "dark");
689
524
  themeData = highlighter.getTheme(theme.light);
690
- normalized = normalizeThemeColors(themeData);
525
+ normalized = getThemeColors(themeData, highlighter);
691
526
  styles += `${formatCSSVariablePrefix("global")}light:${normalized.fg};`;
692
527
  styles += `${formatCSSVariablePrefix("global")}light-bg:${normalized.bg};`;
693
528
  styles += getGitVariables(themeData, "light");
694
529
  }
695
530
  return styles;
696
531
  }
532
+ function getThemeColors(theme, highlighter) {
533
+ if (highlighter.name === "highlights" && theme.zed?.cssVariables === true) {
534
+ const prefix = formatCSSVariablePrefix("token");
535
+ return {
536
+ fg: `var(${prefix}foreground)`,
537
+ bg: `var(${prefix}background)`
538
+ };
539
+ }
540
+ return normalizeThemeColors(theme);
541
+ }
697
542
  function getGitVariables(themeData, modePrefix) {
698
543
  modePrefix = modePrefix != null ? `${modePrefix}-` : "";
699
544
  let styles = "";
@@ -706,16 +551,16 @@ function getGitVariables(themeData, modePrefix) {
706
551
  return styles;
707
552
  }
708
553
  //#endregion
709
- //#region src/utils/getLineNodes.ts
710
- function getLineNodes(nodes) {
711
- let firstChild = nodes.children[0];
712
- while (firstChild != null) {
713
- if (firstChild.type === "element" && firstChild.tagName === "code") return firstChild.children;
714
- if ("children" in firstChild) firstChild = firstChild.children[0];
715
- else firstChild = null;
716
- }
717
- console.error(nodes);
718
- throw new Error("getLineNodes: Unable to find children");
554
+ //#region src/utils/getTokenOptions.ts
555
+ function getTokenOptions(lang, theme, tokenizeMaxLineLength) {
556
+ return {
557
+ lang,
558
+ ...typeof theme === "string" ? { theme } : { themes: theme },
559
+ defaultColor: false,
560
+ cssVariablePrefix: formatCSSVariablePrefix("token"),
561
+ tokenizeMaxLineLength,
562
+ tokenizeTimeLimit: 0
563
+ };
719
564
  }
720
565
  //#endregion
721
566
  //#region src/utils/getHunkSideBoundaries.ts
@@ -1309,9 +1154,423 @@ function pushOrJoinSpan({ item, arr, enableJoin, isNeutral = false, isLastItem =
1309
1154
  arr.push([isNeutral ? 0 : 1, item.value]);
1310
1155
  }
1311
1156
  //#endregion
1157
+ //#region src/utils/hast_utils.ts
1158
+ function createTextNodeElement(value) {
1159
+ return {
1160
+ type: "text",
1161
+ value
1162
+ };
1163
+ }
1164
+ function createHastElement({ tagName, children = [], properties = {} }) {
1165
+ return {
1166
+ type: "element",
1167
+ tagName,
1168
+ properties,
1169
+ children
1170
+ };
1171
+ }
1172
+ //#endregion
1173
+ //#region src/utils/processLine.ts
1174
+ function processLine(node, line, state) {
1175
+ const lineInfo = typeof state.lineInfo === "function" ? state.lineInfo(line) : state.lineInfo[line - 1];
1176
+ if (lineInfo == null) {
1177
+ const errorMessage = `processLine: line ${line}, contains no state.lineInfo`;
1178
+ console.error(errorMessage, {
1179
+ node,
1180
+ line,
1181
+ state
1182
+ });
1183
+ throw new Error(errorMessage);
1184
+ }
1185
+ node.tagName = "div";
1186
+ node.properties["data-line"] = lineInfo.lineNumber;
1187
+ node.properties["data-alt-line"] = lineInfo.altLineNumber;
1188
+ node.properties["data-line-type"] = lineInfo.type;
1189
+ node.properties["data-line-index"] = lineInfo.lineIndex;
1190
+ if (node.children.length === 0) node.children.push(createTextNodeElement("\n"));
1191
+ return node;
1192
+ }
1193
+ //#endregion
1194
+ //#region src/utils/setDeferredArrayItem.ts
1195
+ function setDeferredArrayItem(array, index, create) {
1196
+ let initialized = false;
1197
+ let cached;
1198
+ Object.defineProperty(array, index, {
1199
+ configurable: true,
1200
+ enumerable: true,
1201
+ get() {
1202
+ if (!initialized) {
1203
+ cached = create();
1204
+ initialized = true;
1205
+ }
1206
+ if (Object.getOwnPropertyDescriptor(array, index)?.configurable === true) Object.defineProperty(array, index, {
1207
+ configurable: true,
1208
+ enumerable: true,
1209
+ writable: true,
1210
+ value: cached
1211
+ });
1212
+ return cached;
1213
+ },
1214
+ set(value) {
1215
+ if (Object.getOwnPropertyDescriptor(array, index)?.configurable === true) Object.defineProperty(array, index, {
1216
+ configurable: true,
1217
+ enumerable: true,
1218
+ writable: true,
1219
+ value
1220
+ });
1221
+ else if (Object.isFrozen(array)) throw new TypeError(`Cannot assign to read only array index '${index}'`);
1222
+ else {
1223
+ cached = value;
1224
+ initialized = true;
1225
+ }
1226
+ }
1227
+ });
1228
+ }
1229
+ //#endregion
1230
+ //#region src/utils/tokenStyle.ts
1231
+ const htmlStyleCache = /* @__PURE__ */ new WeakMap();
1232
+ function tokenStyle(token, cacheHtmlStyle) {
1233
+ const { htmlStyle } = token;
1234
+ if (htmlStyle != null) {
1235
+ let style = cacheHtmlStyle ? htmlStyleCache.get(htmlStyle) : void 0;
1236
+ if (style == null) {
1237
+ style = "";
1238
+ for (const name in htmlStyle) style += `${style === "" ? "" : ";"}${name}:${htmlStyle[name]}`;
1239
+ if (cacheHtmlStyle) htmlStyleCache.set(htmlStyle, style);
1240
+ }
1241
+ return style;
1242
+ }
1243
+ let style = token.color != null ? `color:${token.color}` : "";
1244
+ if (token.bgColor != null) style += `;background-color:${token.bgColor}`;
1245
+ if (token.fontStyle != null) {
1246
+ if ((token.fontStyle & 1) !== 0) style += ";font-style:italic";
1247
+ if ((token.fontStyle & 2) !== 0) style += ";font-weight:bold";
1248
+ const underline = (token.fontStyle & 4) !== 0;
1249
+ const strikethrough = (token.fontStyle & 8) !== 0;
1250
+ if (underline || strikethrough) style += `;text-decoration:${underline ? "underline" : ""}${underline && strikethrough ? " " : ""}${strikethrough ? "line-through" : ""}`;
1251
+ }
1252
+ return style.replace(/^;/, "");
1253
+ }
1254
+ //#endregion
1255
+ //#region src/utils/wrapTokenFragments.ts
1256
+ const NO_TOKEN = Symbol("no-token");
1257
+ const MULTIPLE_TOKENS = Symbol("multiple-tokens");
1258
+ function wrapTokenFragments(container) {
1259
+ const ownTokenChar = getTokenChar(container);
1260
+ if (ownTokenChar != null) return ownTokenChar;
1261
+ let containerTokenState = NO_TOKEN;
1262
+ const wrappedChildren = [];
1263
+ let currentTokenChildren = [];
1264
+ let currentTokenChar;
1265
+ const flushTokenChildren = () => {
1266
+ if (currentTokenChildren.length === 0 || currentTokenChar == null) {
1267
+ currentTokenChildren = [];
1268
+ currentTokenChar = void 0;
1269
+ return;
1270
+ }
1271
+ if (currentTokenChildren.length === 1) {
1272
+ const child = currentTokenChildren[0];
1273
+ if (child?.type === "element") {
1274
+ setTokenChar(child, currentTokenChar);
1275
+ for (const grandChild of child.children) stripTokenChar(grandChild);
1276
+ } else stripTokenChar(child);
1277
+ wrappedChildren.push(child);
1278
+ currentTokenChildren = [];
1279
+ currentTokenChar = void 0;
1280
+ return;
1281
+ }
1282
+ for (const child of currentTokenChildren) stripTokenChar(child);
1283
+ wrappedChildren.push(createHastElement({
1284
+ tagName: "span",
1285
+ properties: { "data-char": currentTokenChar },
1286
+ children: currentTokenChildren
1287
+ }));
1288
+ currentTokenChildren = [];
1289
+ currentTokenChar = void 0;
1290
+ };
1291
+ const mergeContainerTokenState = (childTokenState) => {
1292
+ if (childTokenState === NO_TOKEN) return;
1293
+ if (childTokenState === MULTIPLE_TOKENS) {
1294
+ containerTokenState = MULTIPLE_TOKENS;
1295
+ return;
1296
+ }
1297
+ if (containerTokenState === NO_TOKEN) {
1298
+ containerTokenState = childTokenState;
1299
+ return;
1300
+ }
1301
+ if (containerTokenState !== childTokenState) containerTokenState = MULTIPLE_TOKENS;
1302
+ };
1303
+ for (const child of container.children) {
1304
+ const childTokenState = child.type === "element" ? wrapTokenFragments(child) : NO_TOKEN;
1305
+ mergeContainerTokenState(childTokenState);
1306
+ if (typeof childTokenState !== "number") {
1307
+ flushTokenChildren();
1308
+ wrappedChildren.push(child);
1309
+ continue;
1310
+ }
1311
+ if (currentTokenChar != null && currentTokenChar !== childTokenState) flushTokenChildren();
1312
+ currentTokenChar ??= childTokenState;
1313
+ currentTokenChildren.push(child);
1314
+ }
1315
+ flushTokenChildren();
1316
+ container.children = wrappedChildren;
1317
+ return containerTokenState;
1318
+ }
1319
+ function getTokenChar(node) {
1320
+ const value = node.properties["data-char"];
1321
+ if (typeof value === "number") return value;
1322
+ }
1323
+ function stripTokenChar(node) {
1324
+ if (node.type !== "element") return;
1325
+ node.properties["data-char"] = void 0;
1326
+ for (const child of node.children) stripTokenChar(child);
1327
+ }
1328
+ function setTokenChar(node, char) {
1329
+ node.properties["data-char"] = char;
1330
+ }
1331
+ //#endregion
1332
+ //#region src/utils/renderTokenLines.ts
1333
+ function renderTokenLines(lines, { state, lazyLineAST = false, cacheHtmlStyles = false, useTokenTransformer = false, mergeWhitespaces = "always", decorations = [], lineOffsets = [] }) {
1334
+ let decorationsByLine;
1335
+ for (const decoration of decorations) {
1336
+ const byLine = decorationsByLine ??= /* @__PURE__ */ new Map();
1337
+ const normalized = {
1338
+ ...decoration,
1339
+ start: getDecorationPosition(decoration.start, lineOffsets),
1340
+ end: getDecorationPosition(decoration.end, lineOffsets)
1341
+ };
1342
+ const lastLine = Math.min(normalized.end.line, lines.length - 1);
1343
+ for (let line = normalized.start.line; line <= lastLine; line++) {
1344
+ let spans = byLine.get(line);
1345
+ if (spans == null) byLine.set(line, spans = []);
1346
+ spans.push(normalized);
1347
+ }
1348
+ }
1349
+ const renderLine = (tokens, lineIndex) => {
1350
+ let normalized;
1351
+ if (useTokenTransformer || mergeWhitespaces !== "never") {
1352
+ let pendingWhitespace = "";
1353
+ let whitespaceOffset = 0;
1354
+ for (let i = 0; i < tokens.length; i++) {
1355
+ let token = tokens[i];
1356
+ if (useTokenTransformer) {
1357
+ const content = token.content.trim();
1358
+ if (content !== "" && content !== token.content) {
1359
+ normalized ??= tokens.slice(0, i);
1360
+ const start = token.content.indexOf(content);
1361
+ if (start > 0) normalized.push({
1362
+ content: token.content.slice(0, start),
1363
+ offset: token.offset
1364
+ });
1365
+ normalized.push({
1366
+ ...token,
1367
+ content,
1368
+ offset: token.offset + start
1369
+ });
1370
+ const end = start + content.length;
1371
+ if (end < token.content.length) normalized.push({
1372
+ content: token.content.slice(end),
1373
+ offset: token.offset + end
1374
+ });
1375
+ continue;
1376
+ }
1377
+ } else {
1378
+ const decoratedWhitespace = ((token.fontStyle ?? 0) & 12) !== 0;
1379
+ if (!decoratedWhitespace && /^\s+$/.test(token.content) && i < tokens.length - 1) {
1380
+ normalized ??= tokens.slice(0, i);
1381
+ if (pendingWhitespace === "") whitespaceOffset = token.offset;
1382
+ pendingWhitespace += token.content;
1383
+ continue;
1384
+ }
1385
+ if (pendingWhitespace !== "" && normalized != null) {
1386
+ if (decoratedWhitespace) normalized.push({
1387
+ content: pendingWhitespace,
1388
+ offset: whitespaceOffset
1389
+ });
1390
+ else token = {
1391
+ ...token,
1392
+ content: pendingWhitespace + token.content,
1393
+ offset: whitespaceOffset
1394
+ };
1395
+ pendingWhitespace = "";
1396
+ }
1397
+ }
1398
+ normalized?.push(token);
1399
+ }
1400
+ }
1401
+ normalized ??= tokens;
1402
+ const line = {
1403
+ type: "element",
1404
+ tagName: state == null ? "span" : "div",
1405
+ properties: state == null ? { class: "line" } : {},
1406
+ children: []
1407
+ };
1408
+ const spans = decorationsByLine?.get(lineIndex);
1409
+ const column = spans == null ? appendTokens(line, normalized, useTokenTransformer, cacheHtmlStyles) : appendDecoratedTokens(line, normalized, spans, lineIndex, useTokenTransformer, cacheHtmlStyles);
1410
+ if (useTokenTransformer && column === 0) line.children.push({
1411
+ type: "element",
1412
+ tagName: "br",
1413
+ properties: {},
1414
+ children: []
1415
+ });
1416
+ if (useTokenTransformer && spans != null) wrapTokenFragments(line);
1417
+ return state == null ? line : processLine(line, lineIndex + 1, state);
1418
+ };
1419
+ if (!lazyLineAST) return lines.map(renderLine);
1420
+ const rows = new Array(lines.length);
1421
+ for (let index = 0; index < lines.length; index++) {
1422
+ const tokens = lines[index];
1423
+ setDeferredArrayItem(rows, index, () => renderLine(tokens, index));
1424
+ }
1425
+ return rows;
1426
+ }
1427
+ function appendTokens(line, tokens, useTokenTransformer, cacheHtmlStyles) {
1428
+ let column = 0;
1429
+ for (const token of tokens) {
1430
+ if (token.content === "") continue;
1431
+ line.children.push(createTokenSpan(token, tokenStyle(token, cacheHtmlStyles), token.content, column, useTokenTransformer));
1432
+ column += token.content.length;
1433
+ }
1434
+ return column;
1435
+ }
1436
+ function appendDecoratedTokens(line, tokens, spans, lineIndex, useTokenTransformer, cacheHtmlStyles) {
1437
+ if (spans.length > 1) spans.sort((a, b) => {
1438
+ if (a.start.line !== b.start.line) return a.start.line - b.start.line;
1439
+ if (a.start.character !== b.start.character) return a.start.character - b.start.character;
1440
+ if (a.end.line !== b.end.line) return b.end.line - a.end.line;
1441
+ return b.end.character - a.end.character;
1442
+ });
1443
+ const lineLength = tokens.reduce((length, token) => length + token.content.length, 0);
1444
+ const boundaries = [];
1445
+ for (let order = 0; order < spans.length; order++) {
1446
+ const decoration = spans[order];
1447
+ const range = {
1448
+ decoration,
1449
+ order,
1450
+ from: decoration.start.line === lineIndex ? decoration.start.character : 0,
1451
+ to: decoration.end.line === lineIndex ? decoration.end.character : lineLength
1452
+ };
1453
+ boundaries.push({
1454
+ position: Math.max(0, Math.min(range.from, lineLength)),
1455
+ range,
1456
+ start: true
1457
+ }, {
1458
+ position: Math.max(0, Math.min(range.to, lineLength)),
1459
+ range,
1460
+ start: false
1461
+ });
1462
+ }
1463
+ boundaries.sort((a, b) => a.position - b.position);
1464
+ const active = [];
1465
+ const decorationStack = [];
1466
+ let boundaryIndex = 0;
1467
+ const updateActive = (range, add) => {
1468
+ let low = 0;
1469
+ let high = active.length;
1470
+ while (low < high) {
1471
+ const middle = low + high >>> 1;
1472
+ if (active[middle].order < range.order) low = middle + 1;
1473
+ else high = middle;
1474
+ }
1475
+ if (add) active.splice(low, 0, range);
1476
+ else if (active[low] === range) active.splice(low, 1);
1477
+ };
1478
+ const getParent = () => {
1479
+ let parent = line;
1480
+ let depth = 0;
1481
+ for (const range of active) {
1482
+ if (decorationStack[depth]?.range !== range) {
1483
+ decorationStack.length = depth;
1484
+ const wrapper = {
1485
+ type: "element",
1486
+ tagName: "span",
1487
+ properties: { ...range.decoration.properties },
1488
+ children: []
1489
+ };
1490
+ parent.children.push(wrapper);
1491
+ decorationStack.push({
1492
+ range,
1493
+ node: wrapper
1494
+ });
1495
+ }
1496
+ parent = decorationStack[depth++].node;
1497
+ }
1498
+ decorationStack.length = depth;
1499
+ return parent;
1500
+ };
1501
+ let parent = line;
1502
+ const advanceBoundary = (position) => {
1503
+ const first = boundaryIndex;
1504
+ while (boundaries[boundaryIndex]?.position === position) boundaryIndex++;
1505
+ let hasMarker = false;
1506
+ for (let i = first; i < boundaryIndex; i++) {
1507
+ const { range, start } = boundaries[i];
1508
+ if (!start && range.from !== range.to && position < lineLength) updateActive(range, false);
1509
+ }
1510
+ for (let i = first; i < boundaryIndex; i++) {
1511
+ const { range, start } = boundaries[i];
1512
+ if (start && range.from <= position && range.to >= position && (range.to > position || range.from === position || position === lineLength)) {
1513
+ updateActive(range, true);
1514
+ if (range.from === range.to) hasMarker = true;
1515
+ }
1516
+ }
1517
+ if (hasMarker) {
1518
+ getParent();
1519
+ for (let i = first; i < boundaryIndex; i++) {
1520
+ const { range, start } = boundaries[i];
1521
+ if (start && range.from === range.to) updateActive(range, false);
1522
+ }
1523
+ }
1524
+ if (position < lineLength) parent = getParent();
1525
+ };
1526
+ let column = 0;
1527
+ for (const token of tokens) {
1528
+ if (token.content === "") continue;
1529
+ const start = column;
1530
+ const end = start + token.content.length;
1531
+ const style = tokenStyle(token, cacheHtmlStyles);
1532
+ while (column < end) {
1533
+ if (boundaries[boundaryIndex]?.position === column) advanceBoundary(column);
1534
+ const to = Math.min(end, boundaries[boundaryIndex]?.position ?? end);
1535
+ parent.children.push(createTokenSpan(token, style, column === start && to === end ? token.content : token.content.slice(column - start, to - start), start, useTokenTransformer));
1536
+ column = to;
1537
+ }
1538
+ }
1539
+ if (boundaries[boundaryIndex]?.position === column) advanceBoundary(column);
1540
+ return column;
1541
+ }
1542
+ function createTokenSpan(token, style, text, start, useTokenTransformer) {
1543
+ const properties = token.htmlAttrs != null ? { ...token.htmlAttrs } : {};
1544
+ if (style !== "") properties.style = style;
1545
+ if (useTokenTransformer) properties["data-char"] = start;
1546
+ return {
1547
+ type: "element",
1548
+ tagName: "span",
1549
+ properties,
1550
+ children: [{
1551
+ type: "text",
1552
+ value: text
1553
+ }]
1554
+ };
1555
+ }
1556
+ function getDecorationPosition(position, lineOffsets) {
1557
+ if (typeof position !== "number") return position;
1558
+ let low = 0;
1559
+ let high = lineOffsets.length;
1560
+ while (low + 1 < high) {
1561
+ const middle = low + high >>> 1;
1562
+ if (lineOffsets[middle] <= position) low = middle;
1563
+ else high = middle;
1564
+ }
1565
+ return {
1566
+ line: low,
1567
+ character: position - (lineOffsets[low] ?? 0)
1568
+ };
1569
+ }
1570
+ //#endregion
1312
1571
  //#region src/utils/renderDiffWithHighlighter.ts
1313
1572
  const DEFAULT_PLAIN_TEXT_OPTIONS$1 = { forcePlainText: false };
1314
- function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText, startingLine, totalLines, expandedHunks, collapsedContextThreshold = 1 } = DEFAULT_PLAIN_TEXT_OPTIONS$1) {
1573
+ function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText, lazyLineAST = false, startingLine, totalLines, expandedHunks, collapsedContextThreshold = 1 } = DEFAULT_PLAIN_TEXT_OPTIONS$1) {
1315
1574
  if (forcePlainText) {
1316
1575
  startingLine ??= 0;
1317
1576
  totalLines ??= Infinity;
@@ -1320,6 +1579,7 @@ function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText,
1320
1579
  totalLines = Infinity;
1321
1580
  }
1322
1581
  const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
1582
+ lazyLineAST &&= !forcePlainText && !options.useTokenTransformer;
1323
1583
  const baseThemeType = typeof options.theme === "string" ? highlighter.getTheme(options.theme).type : void 0;
1324
1584
  const themeStyles = getHighlighterThemeStyles({
1325
1585
  theme: options.theme,
@@ -1414,17 +1674,27 @@ function renderDiffWithHighlighter(diff, highlighter, options, { forcePlainText,
1414
1674
  additionDecorations: bucket.additionDecorations,
1415
1675
  highlighter,
1416
1676
  options,
1417
- languageOverride: forcePlainText ? "text" : diff.lang
1677
+ languageOverride: forcePlainText ? "text" : diff.lang,
1678
+ lazyLineAST
1418
1679
  });
1419
1680
  if (shouldGroupAll) {
1420
1681
  code.deletionLines = deletionLines;
1421
1682
  code.additionLines = additionLines;
1422
1683
  continue;
1423
1684
  }
1424
- if (bucket.deletionSegments.length > 0) for (const seg of bucket.deletionSegments) for (let i = 0; i < seg.count; i++) code.deletionLines[seg.targetIndex + i] = deletionLines[seg.originalOffset + i];
1425
- else appendItems(code.deletionLines, deletionLines);
1426
- if (bucket.additionSegments.length > 0) for (const seg of bucket.additionSegments) for (let i = 0; i < seg.count; i++) code.additionLines[seg.targetIndex + i] = additionLines[seg.originalOffset + i];
1427
- else appendItems(code.additionLines, additionLines);
1685
+ for (const [target, lines, segments] of [[
1686
+ code.deletionLines,
1687
+ deletionLines,
1688
+ bucket.deletionSegments
1689
+ ], [
1690
+ code.additionLines,
1691
+ additionLines,
1692
+ bucket.additionSegments
1693
+ ]]) 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];
1694
+ else if (lazyLineAST) {
1695
+ const offset = target.length;
1696
+ for (let index = 0; index < lines.length; index++) setDeferredArrayItem(target, offset + index, () => lines[index]);
1697
+ } else appendItems(target, lines);
1428
1698
  }
1429
1699
  return {
1430
1700
  code,
@@ -1556,46 +1826,20 @@ function createBucket() {
1556
1826
  additionSegments: []
1557
1827
  };
1558
1828
  }
1559
- function renderTwoFiles({ deletionFile, additionFile, deletionInfo, additionInfo, highlighter, deletionDecorations, additionDecorations, languageOverride, options: { theme: themeOrThemes, ...options } }) {
1560
- const deletionLang = languageOverride ?? getFiletypeFromFileName(deletionFile.name);
1561
- const additionLang = languageOverride ?? getFiletypeFromFileName(additionFile.name);
1562
- const { state, transformers } = createTransformerWithState(options.useTokenTransformer);
1563
- const hastConfig = (() => {
1564
- return typeof themeOrThemes === "string" ? {
1565
- ...options,
1566
- lang: "text",
1567
- theme: themeOrThemes,
1568
- transformers,
1569
- decorations: void 0,
1570
- defaultColor: false,
1571
- cssVariablePrefix: formatCSSVariablePrefix("token"),
1572
- tokenizeTimeLimit: 0
1573
- } : {
1574
- ...options,
1575
- lang: "text",
1576
- themes: themeOrThemes,
1577
- transformers,
1578
- decorations: void 0,
1579
- defaultColor: false,
1580
- cssVariablePrefix: formatCSSVariablePrefix("token"),
1581
- tokenizeTimeLimit: 0
1582
- };
1583
- })();
1829
+ function renderTwoFiles({ lazyLineAST, deletionFile, additionFile, deletionInfo, additionInfo, highlighter, deletionDecorations, additionDecorations, languageOverride, options: { theme, useTokenTransformer, tokenizeMaxLineLength } }) {
1830
+ const renderFile = (file, lineInfo, decorations) => {
1831
+ if (file.contents === "") return [];
1832
+ return renderTokenLines(highlighter.codeToTokens(cleanLastNewline(file.contents), getTokenOptions(languageOverride ?? getFiletypeFromFileName(file.name), theme, tokenizeMaxLineLength)).tokens, {
1833
+ state: { lineInfo },
1834
+ useTokenTransformer,
1835
+ decorations,
1836
+ lazyLineAST,
1837
+ cacheHtmlStyles: highlighter.name === "highlights"
1838
+ });
1839
+ };
1584
1840
  return {
1585
- deletionLines: (() => {
1586
- if (deletionFile.contents === "") return [];
1587
- hastConfig.lang = deletionLang;
1588
- state.lineInfo = deletionInfo;
1589
- hastConfig.decorations = deletionDecorations;
1590
- return getLineNodes(highlighter.codeToHast(cleanLastNewline(deletionFile.contents), hastConfig));
1591
- })(),
1592
- additionLines: (() => {
1593
- if (additionFile.contents === "") return [];
1594
- hastConfig.lang = additionLang;
1595
- hastConfig.decorations = additionDecorations;
1596
- state.lineInfo = additionInfo;
1597
- return getLineNodes(highlighter.codeToHast(cleanLastNewline(additionFile.contents), hastConfig));
1598
- })()
1841
+ deletionLines: renderFile(deletionFile, deletionInfo, deletionDecorations),
1842
+ additionLines: renderFile(additionFile, additionInfo, additionDecorations)
1599
1843
  };
1600
1844
  }
1601
1845
  //#endregion
@@ -1661,7 +1905,7 @@ function linesFromFileContents(contents) {
1661
1905
  //#endregion
1662
1906
  //#region src/utils/renderFileWithHighlighter.ts
1663
1907
  const DEFAULT_PLAIN_TEXT_OPTIONS = { forcePlainText: false };
1664
- function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLength, useTokenTransformer }, { forcePlainText, startingLine, totalLines, lines } = DEFAULT_PLAIN_TEXT_OPTIONS) {
1908
+ function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLength, useTokenTransformer }, { forcePlainText, lazyLineAST = false, startingLine, totalLines, lines } = DEFAULT_PLAIN_TEXT_OPTIONS) {
1665
1909
  if (forcePlainText) {
1666
1910
  startingLine ??= 0;
1667
1911
  totalLines ??= Infinity;
@@ -1670,7 +1914,7 @@ function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLe
1670
1914
  totalLines = Infinity;
1671
1915
  }
1672
1916
  const isWindowedHighlight = startingLine > 0 || totalLines < Infinity;
1673
- const { state, transformers } = createTransformerWithState(useTokenTransformer);
1917
+ const state = { lineInfo: [] };
1674
1918
  const lang = forcePlainText ? "text" : file.lang ?? getFiletypeFromFileName(file.name);
1675
1919
  const baseThemeType = typeof theme === "string" ? highlighter.getTheme(theme).type : void 0;
1676
1920
  const themeStyles = getHighlighterThemeStyles({
@@ -1682,27 +1926,12 @@ function renderFileWithHighlighter(file, highlighter, { theme, tokenizeMaxLineLe
1682
1926
  lineIndex: shikiLineNumber - 1 + startingLine,
1683
1927
  lineNumber: shikiLineNumber + startingLine
1684
1928
  });
1685
- const hastConfig = (() => {
1686
- if (typeof theme === "string") return {
1687
- lang,
1688
- theme,
1689
- transformers,
1690
- defaultColor: false,
1691
- cssVariablePrefix: formatCSSVariablePrefix("token"),
1692
- tokenizeMaxLineLength,
1693
- tokenizeTimeLimit: 0
1694
- };
1695
- return {
1696
- lang,
1697
- themes: theme,
1698
- transformers,
1699
- defaultColor: false,
1700
- cssVariablePrefix: formatCSSVariablePrefix("token"),
1701
- tokenizeMaxLineLength,
1702
- tokenizeTimeLimit: 0
1703
- };
1704
- })();
1705
- const highlightedLines = getLineNodes(highlighter.codeToHast(normalizeHighlightLineEndings(isWindowedHighlight ? extractWindowedFileContent(lines ?? linesFromFileContents(file.contents), startingLine, totalLines) : file.contents), hastConfig));
1929
+ const highlightedLines = renderTokenLines(highlighter.codeToTokens(normalizeHighlightLineEndings(isWindowedHighlight ? extractWindowedFileContent(lines ?? linesFromFileContents(file.contents), startingLine, totalLines) : file.contents), getTokenOptions(lang, theme, tokenizeMaxLineLength)).tokens, {
1930
+ state,
1931
+ useTokenTransformer,
1932
+ lazyLineAST: lazyLineAST && !forcePlainText && !useTokenTransformer,
1933
+ cacheHtmlStyles: highlighter.name === "highlights"
1934
+ });
1706
1935
  const code = isWindowedHighlight ? new Array(startingLine) : highlightedLines;
1707
1936
  if (isWindowedHighlight) appendItems(code, highlightedLines);
1708
1937
  return {
@@ -1720,8 +1949,102 @@ function extractWindowedFileContent(lines, startingLine, totalLines) {
1720
1949
  return lines.slice(startingLine, endLine).join("");
1721
1950
  }
1722
1951
  //#endregion
1952
+ //#region src/worker/hastLinesTransport.ts
1953
+ const HOLE = 0;
1954
+ const TEXT = 1;
1955
+ const ELEMENT = 2;
1956
+ const OTHER = 3;
1957
+ const UNDEFINED = 0;
1958
+ const NULL = 1;
1959
+ const TRUE = 2;
1960
+ const FALSE = 3;
1961
+ const STRING = 4;
1962
+ const INTEGER = 5;
1963
+ const EXTRA = 6;
1964
+ function encodeHastLines(lines) {
1965
+ let ops = new Int32Array(Math.max(32, Math.min(65536, lines.length * 32)));
1966
+ let length = 0;
1967
+ const offsets = new Uint32Array(lines.length * 2);
1968
+ const strings = [];
1969
+ const stringIds = /* @__PURE__ */ new Map();
1970
+ const extras = [];
1971
+ let text = "";
1972
+ function push(value) {
1973
+ if (length === ops.length) {
1974
+ const next = new Int32Array(ops.length * 2);
1975
+ next.set(ops);
1976
+ ops = next;
1977
+ }
1978
+ ops[length++] = value;
1979
+ }
1980
+ function intern(value) {
1981
+ let id = stringIds.get(value);
1982
+ if (id == null) {
1983
+ id = strings.length;
1984
+ strings.push(value);
1985
+ stringIds.set(value, id);
1986
+ }
1987
+ return id;
1988
+ }
1989
+ function encodeNode(node) {
1990
+ let keys = 0;
1991
+ for (const _ in node) keys++;
1992
+ if (node?.type === "text" && keys === 2) {
1993
+ push(TEXT);
1994
+ push(node.value.length);
1995
+ text += node.value;
1996
+ } else if (node?.type === "element" && keys === 4 && node.properties != null && Object.getPrototypeOf(node.properties) === Object.prototype) {
1997
+ push(ELEMENT);
1998
+ push(intern(node.tagName));
1999
+ let count = 0;
2000
+ for (const _ in node.properties) count++;
2001
+ push(count);
2002
+ for (const key in node.properties) {
2003
+ const value = node.properties[key];
2004
+ push(intern(key));
2005
+ if (value === void 0) push(UNDEFINED);
2006
+ else if (value === null) push(NULL);
2007
+ else if (value === true) push(TRUE);
2008
+ else if (value === false) push(FALSE);
2009
+ else if (typeof value === "string") {
2010
+ push(STRING);
2011
+ push(intern(value));
2012
+ } else if (typeof value === "number" && (value | 0) === value && !Object.is(value, -0)) {
2013
+ push(INTEGER);
2014
+ push(value);
2015
+ } else {
2016
+ push(EXTRA);
2017
+ push(extras.length);
2018
+ extras.push(value);
2019
+ }
2020
+ }
2021
+ push(node.children.length);
2022
+ for (let index = 0; index < node.children.length; index++) if (index in node.children) encodeNode(node.children[index]);
2023
+ else push(HOLE);
2024
+ } else {
2025
+ push(OTHER);
2026
+ push(extras.length);
2027
+ extras.push(node);
2028
+ }
2029
+ }
2030
+ for (let index = 0; index < lines.length; index++) {
2031
+ offsets[index * 2] = length;
2032
+ offsets[index * 2 + 1] = text.length;
2033
+ if (index in lines) encodeNode(lines[index]);
2034
+ else push(HOLE);
2035
+ }
2036
+ return {
2037
+ ops: ops.subarray(0, length),
2038
+ offsets,
2039
+ strings,
2040
+ text,
2041
+ extras
2042
+ };
2043
+ }
2044
+ //#endregion
1723
2045
  //#region src/worker/worker.ts
1724
2046
  let highlighter;
2047
+ let compactResults = false;
1725
2048
  let renderOptions = {
1726
2049
  theme: DEFAULT_THEMES,
1727
2050
  useTokenTransformer: false,
@@ -1731,7 +2054,7 @@ let renderOptions = {
1731
2054
  };
1732
2055
  const EMPTY_REGEXP = /(?:)/;
1733
2056
  self.addEventListener("error", (event) => {
1734
- console.error("[Shiki Worker] Unhandled error:", event.error);
2057
+ console.error("[Diffs Worker] Unhandled error:", event.error);
1735
2058
  });
1736
2059
  self.addEventListener("message", (event) => {
1737
2060
  handleMessage(event.data);
@@ -1760,7 +2083,7 @@ async function handleMessage(request) {
1760
2083
  EMPTY_REGEXP.exec("");
1761
2084
  }
1762
2085
  }
1763
- async function handleInitialize({ id, renderOptions: options, preferredHighlighter, resolvedThemes, resolvedLanguages, customExtensionsVersion, customExtensionMap }) {
2086
+ async function handleInitialize({ id, renderOptions: options, preferredHighlighter, resolvedThemes, resolvedLanguages, customExtensionsVersion, customExtensionMap, resultFormat }) {
1764
2087
  let highlighter = getHighlighter(preferredHighlighter);
1765
2088
  if ("then" in highlighter) highlighter = await highlighter;
1766
2089
  syncCustomExtensionsFromRequest({
@@ -1770,6 +2093,7 @@ async function handleInitialize({ id, renderOptions: options, preferredHighlight
1770
2093
  attachResolvedThemes(resolvedThemes, highlighter);
1771
2094
  if (resolvedLanguages != null) attachResolvedLanguages(resolvedLanguages, highlighter);
1772
2095
  renderOptions = options;
2096
+ compactResults = resultFormat === "hast-ops-v1";
1773
2097
  postMessage({
1774
2098
  type: "success",
1775
2099
  id,
@@ -1802,7 +2126,23 @@ async function handleRenderFile({ id, file, resolvedLanguages, customExtensionsV
1802
2126
  useTokenTransformer: renderOptions.useTokenTransformer,
1803
2127
  tokenizeMaxLineLength: renderOptions.tokenizeMaxLineLength
1804
2128
  };
1805
- sendFileSuccess(id, renderFileWithHighlighter(file, highlighter, fileOptions), fileOptions);
2129
+ const result = renderFileWithHighlighter(file, highlighter, fileOptions);
2130
+ const code = compactResults ? encodeHastLines(result.code) : void 0;
2131
+ const response = {
2132
+ type: "success",
2133
+ requestType: "file",
2134
+ id,
2135
+ result,
2136
+ options: fileOptions,
2137
+ sentAt: Date.now()
2138
+ };
2139
+ postMessage(code == null ? response : {
2140
+ ...response,
2141
+ result: {
2142
+ ...result,
2143
+ code
2144
+ }
2145
+ }, code == null ? [] : [code.ops.buffer, code.offsets.buffer]);
1806
2146
  }
1807
2147
  async function handleRenderDiff({ id, diff, resolvedLanguages, customExtensionsVersion, customExtensionMap }) {
1808
2148
  let highlighter = getHighlighter();
@@ -1812,14 +2152,34 @@ async function handleRenderDiff({ id, diff, resolvedLanguages, customExtensionsV
1812
2152
  customExtensionMap
1813
2153
  });
1814
2154
  if (resolvedLanguages != null) attachResolvedLanguages(resolvedLanguages, highlighter);
1815
- sendDiffSuccess(id, renderDiffWithHighlighter(diff, highlighter, renderOptions), renderOptions);
2155
+ const result = renderDiffWithHighlighter(diff, highlighter, renderOptions);
2156
+ const code = compactResults ? {
2157
+ deletionLines: encodeHastLines(result.code.deletionLines),
2158
+ additionLines: encodeHastLines(result.code.additionLines)
2159
+ } : void 0;
2160
+ const response = {
2161
+ type: "success",
2162
+ requestType: "diff",
2163
+ id,
2164
+ result,
2165
+ options: renderOptions,
2166
+ sentAt: Date.now()
2167
+ };
2168
+ postMessage(code == null ? response : {
2169
+ ...response,
2170
+ result: {
2171
+ ...result,
2172
+ code
2173
+ }
2174
+ }, code == null ? [] : [
2175
+ code.deletionLines.ops.buffer,
2176
+ code.deletionLines.offsets.buffer,
2177
+ code.additionLines.ops.buffer,
2178
+ code.additionLines.offsets.buffer
2179
+ ]);
1816
2180
  }
1817
- function getHighlighter(preferredHighlighter = "shiki-js") {
1818
- highlighter ??= createHighlighterCore({
1819
- themes: [],
1820
- langs: [],
1821
- engine: preferredHighlighter === "shiki-wasm" ? createOnigurumaEngine(import("shiki/wasm")) : createJavaScriptRegexEngine()
1822
- });
2181
+ function getHighlighter(preferredHighlighter) {
2182
+ highlighter ??= createHighlighter(preferredHighlighter);
1823
2183
  return highlighter;
1824
2184
  }
1825
2185
  function syncCustomExtensionsFromRequest({ customExtensionsVersion, customExtensionMap }) {
@@ -1827,26 +2187,6 @@ function syncCustomExtensionsFromRequest({ customExtensionsVersion, customExtens
1827
2187
  if (customExtensionsVersion == null || customExtensionMap == null) throw new Error("Worker request must include both customExtensionsVersion and customExtensionMap");
1828
2188
  replaceCustomExtensions(customExtensionsVersion, customExtensionMap);
1829
2189
  }
1830
- function sendFileSuccess(id, result, options) {
1831
- postMessage({
1832
- type: "success",
1833
- requestType: "file",
1834
- id,
1835
- result,
1836
- options,
1837
- sentAt: Date.now()
1838
- });
1839
- }
1840
- function sendDiffSuccess(id, result, options) {
1841
- postMessage({
1842
- type: "success",
1843
- requestType: "diff",
1844
- id,
1845
- result,
1846
- options,
1847
- sentAt: Date.now()
1848
- });
1849
- }
1850
2190
  function sendError(id, error) {
1851
2191
  const response = {
1852
2192
  type: "error",
@@ -1857,5 +2197,6 @@ function sendError(id, error) {
1857
2197
  postMessage(response);
1858
2198
  }
1859
2199
  //#endregion
2200
+ 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 };
1860
2201
 
1861
2202
  //# sourceMappingURL=worker.js.map