svelte-highlight 7.23.1 → 7.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (502) hide show
  1. package/AnsiOutput.svelte +33 -6
  2. package/AnsiOutput.svelte.d.ts +8 -0
  3. package/CodeToolbar.svelte +144 -0
  4. package/CodeToolbar.svelte.d.ts +125 -0
  5. package/CodeWindow.svelte +19 -0
  6. package/CodeWindow.svelte.d.ts +10 -0
  7. package/CopyButton.svelte +107 -3
  8. package/CopyButton.svelte.d.ts +17 -1
  9. package/DiffFileList.svelte +523 -0
  10. package/DiffFileList.svelte.d.ts +94 -0
  11. package/DiffFileListItem.svelte +44 -0
  12. package/DiffMinimap.svelte +99 -0
  13. package/DiffMinimap.svelte.d.ts +17 -0
  14. package/DiffStats.svelte +43 -0
  15. package/DiffStats.svelte.d.ts +17 -0
  16. package/DiffView.svelte +1213 -0
  17. package/DiffView.svelte.d.ts +76 -0
  18. package/FileTabs.svelte +2 -5
  19. package/Highlight.svelte +158 -2
  20. package/Highlight.svelte.d.ts +50 -2
  21. package/HighlightAuto.svelte.d.ts +3 -2
  22. package/HighlightAutoLazy.svelte +112 -0
  23. package/HighlightAutoLazy.svelte.d.ts +66 -0
  24. package/HighlightDiff.svelte +162 -0
  25. package/HighlightDiff.svelte.d.ts +102 -0
  26. package/HighlightEditable.svelte +65 -766
  27. package/HighlightEditable.svelte.d.ts +15 -5
  28. package/HighlightStream.svelte +117 -218
  29. package/HighlightStream.svelte.d.ts +8 -0
  30. package/HighlightSvelte.svelte.d.ts +3 -2
  31. package/HighlightVirtual.svelte +41 -8
  32. package/HighlightVirtual.svelte.d.ts +8 -0
  33. package/LangTag.svelte +33 -4
  34. package/LangTag.svelte.d.ts +6 -2
  35. package/LineNumbers.svelte +25 -4
  36. package/LineNumbers.svelte.d.ts +8 -0
  37. package/MarkdownStream.svelte +1 -0
  38. package/README.md +736 -19
  39. package/ToolbarButton.svelte +90 -0
  40. package/ToolbarButton.svelte.d.ts +106 -0
  41. package/Typewriter.svelte +59 -10
  42. package/Typewriter.svelte.d.ts +7 -0
  43. package/WrapToggle.svelte +34 -0
  44. package/WrapToggle.svelte.d.ts +39 -0
  45. package/action.js +7 -3
  46. package/ansi.d.ts +1 -3
  47. package/ansi.js +44 -12
  48. package/auto-detect.d.ts +52 -0
  49. package/auto-detect.js +208 -0
  50. package/code-region.d.ts +7 -0
  51. package/code-region.js +20 -0
  52. package/css-highlights.js +115 -0
  53. package/css-walk.js +50 -0
  54. package/diff-controller.d.ts +120 -0
  55. package/diff-controller.js +721 -0
  56. package/diff-edits.d.ts +101 -0
  57. package/diff-edits.js +890 -0
  58. package/diff-html.d.ts +8 -0
  59. package/diff-html.js +60 -0
  60. package/diff-languages.d.ts +4 -0
  61. package/diff-languages.js +73 -0
  62. package/diff.d.ts +161 -0
  63. package/diff.js +1111 -0
  64. package/editable-commands.js +81 -0
  65. package/editable-css-paint.js +5 -3
  66. package/editable-dom-paint.js +1 -1
  67. package/editable-history.js +199 -0
  68. package/editable-line-dom.js +176 -1
  69. package/editable-painter.js +356 -0
  70. package/editable.d.ts +118 -0
  71. package/editable.js +513 -0
  72. package/engine.d.ts +1 -1
  73. package/fence.js +1 -1
  74. package/highlight-cascade.js +679 -0
  75. package/highlight-theme.d.ts +7 -0
  76. package/highlight-theme.js +23 -46
  77. package/incremental-tokenize.js +1 -1
  78. package/index.d.ts +39 -6
  79. package/index.js +30 -0
  80. package/languages/detect-index.d.ts +16 -0
  81. package/languages/detect-index.js +6 -0
  82. package/languages/loaders.d.ts +8 -0
  83. package/languages/loaders.js +370 -0
  84. package/package.json +50 -2
  85. package/preprocessor.js +20 -5
  86. package/search.js +2 -2
  87. package/stream-highlighter.js +198 -0
  88. package/stream.css +16 -0
  89. package/stream.d.ts +60 -0
  90. package/stream.js +283 -0
  91. package/style-registry.js +34 -3
  92. package/styles/3024.css +1 -1
  93. package/styles/3024.js +1 -1
  94. package/styles/apathy.css +1 -1
  95. package/styles/apathy.js +1 -1
  96. package/styles/apprentice.css +1 -1
  97. package/styles/apprentice.js +1 -1
  98. package/styles/ashes.css +1 -1
  99. package/styles/ashes.js +1 -1
  100. package/styles/atelier-cave-light.css +1 -1
  101. package/styles/atelier-cave-light.js +1 -1
  102. package/styles/atelier-cave.css +1 -1
  103. package/styles/atelier-cave.js +1 -1
  104. package/styles/atelier-dune-light.css +1 -1
  105. package/styles/atelier-dune-light.js +1 -1
  106. package/styles/atelier-dune.css +1 -1
  107. package/styles/atelier-dune.js +1 -1
  108. package/styles/atelier-estuary-light.css +1 -1
  109. package/styles/atelier-estuary-light.js +1 -1
  110. package/styles/atelier-estuary.css +1 -1
  111. package/styles/atelier-estuary.js +1 -1
  112. package/styles/atelier-forest-light.css +1 -1
  113. package/styles/atelier-forest-light.js +1 -1
  114. package/styles/atelier-forest.css +1 -1
  115. package/styles/atelier-forest.js +1 -1
  116. package/styles/atelier-heath-light.css +1 -1
  117. package/styles/atelier-heath-light.js +1 -1
  118. package/styles/atelier-heath.css +1 -1
  119. package/styles/atelier-heath.js +1 -1
  120. package/styles/atelier-lakeside-light.css +1 -1
  121. package/styles/atelier-lakeside-light.js +1 -1
  122. package/styles/atelier-lakeside.css +1 -1
  123. package/styles/atelier-lakeside.js +1 -1
  124. package/styles/atelier-plateau-light.css +1 -1
  125. package/styles/atelier-plateau-light.js +1 -1
  126. package/styles/atelier-plateau.css +1 -1
  127. package/styles/atelier-plateau.js +1 -1
  128. package/styles/atelier-savanna-light.css +1 -1
  129. package/styles/atelier-savanna-light.js +1 -1
  130. package/styles/atelier-savanna.css +1 -1
  131. package/styles/atelier-savanna.js +1 -1
  132. package/styles/atelier-seaside-light.css +1 -1
  133. package/styles/atelier-seaside-light.js +1 -1
  134. package/styles/atelier-seaside.css +1 -1
  135. package/styles/atelier-seaside.js +1 -1
  136. package/styles/atelier-sulphurpool-light.css +1 -1
  137. package/styles/atelier-sulphurpool-light.js +1 -1
  138. package/styles/atelier-sulphurpool.css +1 -1
  139. package/styles/atelier-sulphurpool.js +1 -1
  140. package/styles/atlas.css +1 -1
  141. package/styles/atlas.js +1 -1
  142. package/styles/base16-github.css +1 -1
  143. package/styles/base16-github.js +1 -1
  144. package/styles/base16-ir-black.css +1 -1
  145. package/styles/base16-ir-black.js +1 -1
  146. package/styles/base16-monokai.css +1 -1
  147. package/styles/base16-monokai.js +1 -1
  148. package/styles/base16-nord.css +1 -1
  149. package/styles/base16-nord.js +1 -1
  150. package/styles/bespin.css +1 -1
  151. package/styles/bespin.js +1 -1
  152. package/styles/black-metal-bathory.css +1 -1
  153. package/styles/black-metal-bathory.js +1 -1
  154. package/styles/black-metal-burzum.css +1 -1
  155. package/styles/black-metal-burzum.js +1 -1
  156. package/styles/black-metal-dark-funeral.css +1 -1
  157. package/styles/black-metal-dark-funeral.js +1 -1
  158. package/styles/black-metal-gorgoroth.css +1 -1
  159. package/styles/black-metal-gorgoroth.js +1 -1
  160. package/styles/black-metal-immortal.css +1 -1
  161. package/styles/black-metal-immortal.js +1 -1
  162. package/styles/black-metal-khold.css +1 -1
  163. package/styles/black-metal-khold.js +1 -1
  164. package/styles/black-metal-marduk.css +1 -1
  165. package/styles/black-metal-marduk.js +1 -1
  166. package/styles/black-metal-mayhem.css +1 -1
  167. package/styles/black-metal-mayhem.js +1 -1
  168. package/styles/black-metal-nile.css +1 -1
  169. package/styles/black-metal-nile.js +1 -1
  170. package/styles/black-metal-venom.css +1 -1
  171. package/styles/black-metal-venom.js +1 -1
  172. package/styles/black-metal.css +1 -1
  173. package/styles/black-metal.js +1 -1
  174. package/styles/brewer.css +1 -1
  175. package/styles/brewer.js +1 -1
  176. package/styles/bright.css +1 -1
  177. package/styles/bright.js +1 -1
  178. package/styles/brogrammer.css +1 -1
  179. package/styles/brogrammer.js +1 -1
  180. package/styles/brush-trees-dark.css +1 -1
  181. package/styles/brush-trees-dark.js +1 -1
  182. package/styles/brush-trees.css +1 -1
  183. package/styles/brush-trees.js +1 -1
  184. package/styles/chalk.css +1 -1
  185. package/styles/chalk.js +1 -1
  186. package/styles/circus.css +1 -1
  187. package/styles/circus.js +1 -1
  188. package/styles/classic-dark.css +1 -1
  189. package/styles/classic-dark.js +1 -1
  190. package/styles/classic-light.css +1 -1
  191. package/styles/classic-light.js +1 -1
  192. package/styles/codeschool.css +1 -1
  193. package/styles/codeschool.js +1 -1
  194. package/styles/colors.css +1 -1
  195. package/styles/colors.js +1 -1
  196. package/styles/cupcake.css +1 -1
  197. package/styles/cupcake.js +1 -1
  198. package/styles/cupertino.css +1 -1
  199. package/styles/cupertino.js +1 -1
  200. package/styles/cybertopia-cherry.css +2 -1
  201. package/styles/cybertopia-cherry.js +2 -1
  202. package/styles/cybertopia-dimmer.css +2 -1
  203. package/styles/cybertopia-dimmer.js +2 -1
  204. package/styles/cybertopia-icecap.css +2 -1
  205. package/styles/cybertopia-icecap.js +2 -1
  206. package/styles/cybertopia-saturated.css +2 -1
  207. package/styles/cybertopia-saturated.js +2 -1
  208. package/styles/danqing.css +1 -1
  209. package/styles/danqing.js +1 -1
  210. package/styles/darcula.css +1 -1
  211. package/styles/darcula.js +1 -1
  212. package/styles/dark-violet.css +1 -1
  213. package/styles/dark-violet.js +1 -1
  214. package/styles/darkmoss.css +1 -1
  215. package/styles/darkmoss.js +1 -1
  216. package/styles/darktooth.css +1 -1
  217. package/styles/darktooth.js +1 -1
  218. package/styles/decaf.css +1 -1
  219. package/styles/decaf.js +1 -1
  220. package/styles/default-dark.css +1 -1
  221. package/styles/default-dark.js +1 -1
  222. package/styles/default-light.css +1 -1
  223. package/styles/default-light.js +1 -1
  224. package/styles/dirtysea.css +1 -1
  225. package/styles/dirtysea.js +1 -1
  226. package/styles/docco.css +1 -1
  227. package/styles/docco.js +1 -1
  228. package/styles/dracula.css +1 -1
  229. package/styles/dracula.js +1 -1
  230. package/styles/edge-dark.css +1 -1
  231. package/styles/edge-dark.js +1 -1
  232. package/styles/edge-light.css +1 -1
  233. package/styles/edge-light.js +1 -1
  234. package/styles/eighties.css +1 -1
  235. package/styles/eighties.js +1 -1
  236. package/styles/embers.css +1 -1
  237. package/styles/embers.js +1 -1
  238. package/styles/equilibrium-dark.css +1 -1
  239. package/styles/equilibrium-dark.js +1 -1
  240. package/styles/equilibrium-gray-dark.css +1 -1
  241. package/styles/equilibrium-gray-dark.js +1 -1
  242. package/styles/equilibrium-gray-light.css +1 -1
  243. package/styles/equilibrium-gray-light.js +1 -1
  244. package/styles/equilibrium-light.css +1 -1
  245. package/styles/equilibrium-light.js +1 -1
  246. package/styles/espresso.css +1 -1
  247. package/styles/espresso.js +1 -1
  248. package/styles/eva-dim.css +1 -1
  249. package/styles/eva-dim.js +1 -1
  250. package/styles/eva.css +1 -1
  251. package/styles/eva.js +1 -1
  252. package/styles/flat.css +1 -1
  253. package/styles/flat.js +1 -1
  254. package/styles/framer.css +1 -1
  255. package/styles/framer.js +1 -1
  256. package/styles/fruit-soda.css +1 -1
  257. package/styles/fruit-soda.js +1 -1
  258. package/styles/gigavolt.css +1 -1
  259. package/styles/gigavolt.js +1 -1
  260. package/styles/gml.css +1 -1
  261. package/styles/gml.js +1 -1
  262. package/styles/google-dark.css +1 -1
  263. package/styles/google-dark.js +1 -1
  264. package/styles/google-light.css +1 -1
  265. package/styles/google-light.js +1 -1
  266. package/styles/googlecode.css +1 -1
  267. package/styles/googlecode.js +1 -1
  268. package/styles/grayscale-dark.css +1 -1
  269. package/styles/grayscale-dark.js +1 -1
  270. package/styles/grayscale-light.css +1 -1
  271. package/styles/grayscale-light.js +1 -1
  272. package/styles/grayscale.css +1 -1
  273. package/styles/grayscale.js +1 -1
  274. package/styles/green-screen.css +1 -1
  275. package/styles/green-screen.js +1 -1
  276. package/styles/gruvbox-dark-hard.css +1 -1
  277. package/styles/gruvbox-dark-hard.js +1 -1
  278. package/styles/gruvbox-dark-medium.css +1 -1
  279. package/styles/gruvbox-dark-medium.js +1 -1
  280. package/styles/gruvbox-dark-pale.css +1 -1
  281. package/styles/gruvbox-dark-pale.js +1 -1
  282. package/styles/gruvbox-dark-soft.css +1 -1
  283. package/styles/gruvbox-dark-soft.js +1 -1
  284. package/styles/gruvbox-light-hard.css +1 -1
  285. package/styles/gruvbox-light-hard.js +1 -1
  286. package/styles/gruvbox-light-medium.css +1 -1
  287. package/styles/gruvbox-light-medium.js +1 -1
  288. package/styles/gruvbox-light-soft.css +1 -1
  289. package/styles/gruvbox-light-soft.js +1 -1
  290. package/styles/hardcore.css +1 -1
  291. package/styles/hardcore.js +1 -1
  292. package/styles/harmonic16-dark.css +1 -1
  293. package/styles/harmonic16-dark.js +1 -1
  294. package/styles/harmonic16-light.css +1 -1
  295. package/styles/harmonic16-light.js +1 -1
  296. package/styles/heetch-dark.css +1 -1
  297. package/styles/heetch-dark.js +1 -1
  298. package/styles/heetch-light.css +1 -1
  299. package/styles/heetch-light.js +1 -1
  300. package/styles/helios.css +1 -1
  301. package/styles/helios.js +1 -1
  302. package/styles/hopscotch.css +1 -1
  303. package/styles/hopscotch.js +1 -1
  304. package/styles/horizon-dark.css +1 -1
  305. package/styles/horizon-dark.js +1 -1
  306. package/styles/horizon-light.css +1 -1
  307. package/styles/horizon-light.js +1 -1
  308. package/styles/humanoid-dark.css +1 -1
  309. package/styles/humanoid-dark.js +1 -1
  310. package/styles/humanoid-light.css +1 -1
  311. package/styles/humanoid-light.js +1 -1
  312. package/styles/ia-dark.css +1 -1
  313. package/styles/ia-dark.js +1 -1
  314. package/styles/ia-light.css +1 -1
  315. package/styles/ia-light.js +1 -1
  316. package/styles/icy-dark.css +1 -1
  317. package/styles/icy-dark.js +1 -1
  318. package/styles/idea.css +1 -1
  319. package/styles/idea.js +1 -1
  320. package/styles/intellij-light.css +1 -1
  321. package/styles/intellij-light.js +1 -1
  322. package/styles/ir-black.css +1 -1
  323. package/styles/ir-black.js +1 -1
  324. package/styles/isotope.css +1 -1
  325. package/styles/isotope.js +1 -1
  326. package/styles/kimber.css +1 -1
  327. package/styles/kimber.js +1 -1
  328. package/styles/kimbie-dark.css +1 -1
  329. package/styles/kimbie-dark.js +1 -1
  330. package/styles/kimbie-light.css +1 -1
  331. package/styles/kimbie-light.js +1 -1
  332. package/styles/london-tube.css +1 -1
  333. package/styles/london-tube.js +1 -1
  334. package/styles/macintosh.css +1 -1
  335. package/styles/macintosh.js +1 -1
  336. package/styles/marrakesh.css +1 -1
  337. package/styles/marrakesh.js +1 -1
  338. package/styles/materia.css +1 -1
  339. package/styles/materia.js +1 -1
  340. package/styles/material-darker.css +1 -1
  341. package/styles/material-darker.js +1 -1
  342. package/styles/material-lighter.css +1 -1
  343. package/styles/material-lighter.js +1 -1
  344. package/styles/material-palenight.css +1 -1
  345. package/styles/material-palenight.js +1 -1
  346. package/styles/material-vivid.css +1 -1
  347. package/styles/material-vivid.js +1 -1
  348. package/styles/material.css +1 -1
  349. package/styles/material.js +1 -1
  350. package/styles/mellow-purple.css +1 -1
  351. package/styles/mellow-purple.js +1 -1
  352. package/styles/mexico-light.css +1 -1
  353. package/styles/mexico-light.js +1 -1
  354. package/styles/mocha.css +1 -1
  355. package/styles/mocha.js +1 -1
  356. package/styles/nebula.css +1 -1
  357. package/styles/nebula.js +1 -1
  358. package/styles/nnfx-dark.css +1 -1
  359. package/styles/nnfx-dark.js +1 -1
  360. package/styles/nnfx-light.css +1 -1
  361. package/styles/nnfx-light.js +1 -1
  362. package/styles/nord.css +1 -1
  363. package/styles/nord.js +1 -1
  364. package/styles/nova.css +1 -1
  365. package/styles/nova.js +1 -1
  366. package/styles/ocean.css +1 -1
  367. package/styles/ocean.js +1 -1
  368. package/styles/oceanicnext.css +1 -1
  369. package/styles/oceanicnext.js +1 -1
  370. package/styles/one-light.css +1 -1
  371. package/styles/one-light.js +1 -1
  372. package/styles/onedark.css +1 -1
  373. package/styles/onedark.js +1 -1
  374. package/styles/outrun-dark.css +1 -1
  375. package/styles/outrun-dark.js +1 -1
  376. package/styles/papercolor-dark.css +1 -1
  377. package/styles/papercolor-dark.js +1 -1
  378. package/styles/papercolor-light.css +1 -1
  379. package/styles/papercolor-light.js +1 -1
  380. package/styles/paraiso.css +1 -1
  381. package/styles/paraiso.js +1 -1
  382. package/styles/pasque.css +1 -1
  383. package/styles/pasque.js +1 -1
  384. package/styles/phd.css +1 -1
  385. package/styles/phd.js +1 -1
  386. package/styles/pico.css +1 -1
  387. package/styles/pico.js +1 -1
  388. package/styles/pojoaque.css +1 -1
  389. package/styles/pojoaque.js +1 -1
  390. package/styles/pop.css +1 -1
  391. package/styles/pop.js +1 -1
  392. package/styles/porple.css +1 -1
  393. package/styles/porple.js +1 -1
  394. package/styles/qualia.css +1 -1
  395. package/styles/qualia.js +1 -1
  396. package/styles/railscasts.css +1 -1
  397. package/styles/railscasts.js +1 -1
  398. package/styles/rebecca.css +1 -1
  399. package/styles/rebecca.js +1 -1
  400. package/styles/ros-pine-dawn.css +1 -1
  401. package/styles/ros-pine-dawn.js +1 -1
  402. package/styles/ros-pine-moon.css +1 -1
  403. package/styles/ros-pine-moon.js +1 -1
  404. package/styles/ros-pine.css +1 -1
  405. package/styles/ros-pine.js +1 -1
  406. package/styles/sagelight.css +1 -1
  407. package/styles/sagelight.js +1 -1
  408. package/styles/sandcastle.css +1 -1
  409. package/styles/sandcastle.js +1 -1
  410. package/styles/school-book.css +1 -1
  411. package/styles/school-book.js +1 -1
  412. package/styles/seti-ui.css +1 -1
  413. package/styles/seti-ui.js +1 -1
  414. package/styles/shapeshifter.css +1 -1
  415. package/styles/shapeshifter.js +1 -1
  416. package/styles/silk-dark.css +1 -1
  417. package/styles/silk-dark.js +1 -1
  418. package/styles/silk-light.css +1 -1
  419. package/styles/silk-light.js +1 -1
  420. package/styles/snazzy.css +1 -1
  421. package/styles/snazzy.js +1 -1
  422. package/styles/solar-flare-light.css +1 -1
  423. package/styles/solar-flare-light.js +1 -1
  424. package/styles/solar-flare.css +1 -1
  425. package/styles/solar-flare.js +1 -1
  426. package/styles/solarized-dark.css +1 -1
  427. package/styles/solarized-dark.js +1 -1
  428. package/styles/solarized-light.css +1 -1
  429. package/styles/solarized-light.js +1 -1
  430. package/styles/spacemacs.css +1 -1
  431. package/styles/spacemacs.js +1 -1
  432. package/styles/stackoverflow-dark.css +1 -1
  433. package/styles/stackoverflow-dark.js +1 -1
  434. package/styles/stackoverflow-light.css +1 -1
  435. package/styles/stackoverflow-light.js +1 -1
  436. package/styles/summercamp.css +1 -1
  437. package/styles/summercamp.js +1 -1
  438. package/styles/summerfruit-dark.css +1 -1
  439. package/styles/summerfruit-dark.js +1 -1
  440. package/styles/summerfruit-light.css +1 -1
  441. package/styles/summerfruit-light.js +1 -1
  442. package/styles/synth-midnight-terminal-dark.css +1 -1
  443. package/styles/synth-midnight-terminal-dark.js +1 -1
  444. package/styles/synth-midnight-terminal-light.css +1 -1
  445. package/styles/synth-midnight-terminal-light.js +1 -1
  446. package/styles/tango.css +1 -1
  447. package/styles/tango.js +1 -1
  448. package/styles/tender.css +1 -1
  449. package/styles/tender.js +1 -1
  450. package/styles/tomorrow-night.css +1 -1
  451. package/styles/tomorrow-night.js +1 -1
  452. package/styles/tomorrow.css +1 -1
  453. package/styles/tomorrow.js +1 -1
  454. package/styles/twilight.css +1 -1
  455. package/styles/twilight.js +1 -1
  456. package/styles/unikitty-dark.css +1 -1
  457. package/styles/unikitty-dark.js +1 -1
  458. package/styles/unikitty-light.css +1 -1
  459. package/styles/unikitty-light.js +1 -1
  460. package/styles/vs2015.css +1 -1
  461. package/styles/vs2015.js +1 -1
  462. package/styles/vulcan.css +1 -1
  463. package/styles/vulcan.js +1 -1
  464. package/styles/windows-10-light.css +1 -1
  465. package/styles/windows-10-light.js +1 -1
  466. package/styles/windows-10.css +1 -1
  467. package/styles/windows-10.js +1 -1
  468. package/styles/windows-95-light.css +1 -1
  469. package/styles/windows-95-light.js +1 -1
  470. package/styles/windows-95.css +1 -1
  471. package/styles/windows-95.js +1 -1
  472. package/styles/windows-high-contrast-light.css +1 -1
  473. package/styles/windows-high-contrast-light.js +1 -1
  474. package/styles/windows-high-contrast.css +1 -1
  475. package/styles/windows-high-contrast.js +1 -1
  476. package/styles/windows-nt-light.css +1 -1
  477. package/styles/windows-nt-light.js +1 -1
  478. package/styles/windows-nt.css +1 -1
  479. package/styles/windows-nt.js +1 -1
  480. package/styles/woodland.css +1 -1
  481. package/styles/woodland.js +1 -1
  482. package/styles/xcode-dusk.css +1 -1
  483. package/styles/xcode-dusk.js +1 -1
  484. package/styles/xcode.css +1 -1
  485. package/styles/xcode.js +1 -1
  486. package/styles/xt256.css +1 -1
  487. package/styles/xt256.js +1 -1
  488. package/styles/zenburn.css +1 -1
  489. package/styles/zenburn.js +1 -1
  490. package/themes/_base-css.d.ts +1 -0
  491. package/themes/_base-css.js +1 -0
  492. package/themes/cybertopia-cherry.css +5 -1
  493. package/themes/cybertopia-cherry.js +1 -1
  494. package/themes/cybertopia-dimmer.css +5 -1
  495. package/themes/cybertopia-dimmer.js +1 -1
  496. package/themes/cybertopia-icecap.css +5 -1
  497. package/themes/cybertopia-icecap.js +1 -1
  498. package/themes/cybertopia-saturated.css +5 -1
  499. package/themes/cybertopia-saturated.js +1 -1
  500. package/typewriter-units.d.ts +3 -0
  501. package/typewriter-units.js +43 -0
  502. package/virtual-window.js +9 -4
@@ -0,0 +1,1213 @@
1
+ <script>
2
+ /**
3
+ * A controller from `createDiffController`.
4
+ * @type {import("./diff-controller.js").DiffController}
5
+ */
6
+ export let diff;
7
+
8
+ /** While streaming, keep the newest row in view. */
9
+ export let follow = true;
10
+
11
+ /** Show accept/reject controls per change (or fill the `actions` slot). */
12
+ export let review = false;
13
+
14
+ /** Wrap long lines instead of scrolling sideways. */
15
+ export let wrap = false;
16
+
17
+ /** @type {"default" | "colorblind"} */
18
+ export let palette = "default";
19
+
20
+ /** Extra rows rendered above and below the viewport. */
21
+ export let overscan = 10;
22
+
23
+ /** Handle n/p/e/c/v (and a/r/u with `review`) when focused. */
24
+ export let keyboard = true;
25
+
26
+ /**
27
+ * Render only the rows in view. `"auto"` virtualizes past 500 rows, so
28
+ * small diffs keep browser find, printing, and server rendering.
29
+ * @type {"auto" | boolean}
30
+ */
31
+ export let virtualize = "auto";
32
+
33
+ import { afterUpdate, onMount, tick } from "svelte";
34
+ import { watchLineHeight } from "./virtual-window.js";
35
+
36
+ $: ({ class: _class, style: _style, ...rest } = $$restProps);
37
+
38
+ /** @type {HTMLElement} */
39
+ let container;
40
+ /** @type {HTMLElement} */
41
+ let windowEl;
42
+ /** @type {HTMLElement} */
43
+ let probe;
44
+ /** @type {HTMLElement} */
45
+ let charProbe;
46
+ /** @type {HTMLElement | undefined} */
47
+ let hbarOld;
48
+ /** @type {HTMLElement | undefined} */
49
+ let hbarNew;
50
+
51
+ let lineHeight = 18;
52
+ let charWidth = 8;
53
+ let codeWidth = 0;
54
+ let scrollTop = 0;
55
+ let clientHeight = 600;
56
+ let clientWidth = 0;
57
+ let scrollOld = 0;
58
+ let scrollNew = 0;
59
+ let hydrated = false;
60
+ let userScrolled = false;
61
+
62
+ /** @type {"old" | "new" | null} */
63
+ let selectSide = null;
64
+
65
+ $: options = $diff.options();
66
+ $: view = options.view;
67
+ $: state = $diff.state();
68
+ $: rows = $diff.rows();
69
+ $: columns = $diff.columns();
70
+ $: decisions = $diff.decisions();
71
+ $: current = $diff.current();
72
+
73
+ // --- row heights ---
74
+ //
75
+ // Rows are estimated, then measured once rendered. Measured heights are
76
+ // cached by row key until something that changes them does: wrapping,
77
+ // the view, the width, notes, or a new (not just grown) document.
78
+
79
+ /** @type {Map<string, number>} */
80
+ let measured = new Map();
81
+ let layoutVersion = 0;
82
+
83
+ function resetHeights() {
84
+ measured = new Map();
85
+ layoutVersion++;
86
+ }
87
+
88
+ /** @type {unknown[]} */
89
+ let heightDeps = [];
90
+ $: {
91
+ const next = [
92
+ wrap,
93
+ view,
94
+ options.annotations,
95
+ lineHeight,
96
+ state.streaming ? null : state,
97
+ ];
98
+ if (wrap) next.push(clientWidth);
99
+ if (next.some((v, i) => v !== heightDeps[i])) {
100
+ heightDeps = next;
101
+ resetHeights();
102
+ }
103
+ }
104
+
105
+ /** @param {import("./diff-controller.js").ViewRow} row */
106
+ function textLength(row) {
107
+ const oldLen =
108
+ row.old === undefined ? 0 : (state.beforeLines[row.old]?.length ?? 0);
109
+ const newLen =
110
+ row.new === undefined
111
+ ? 0
112
+ : row.kind === "incoming"
113
+ ? (state.partial?.length ?? 0)
114
+ : (state.afterLines[row.new]?.length ?? 0);
115
+ if (view === "split") return Math.max(oldLen, newLen);
116
+ return row.kind === "del" ? oldLen : newLen;
117
+ }
118
+
119
+ /** @param {import("./diff-controller.js").ViewRow} row */
120
+ function estimate(row) {
121
+ if (row.note)
122
+ return (row.note.body.split("\n").length + 1) * lineHeight + 6;
123
+ if (!wrap || row.kind === "fold" || row.kind === "pending")
124
+ return lineHeight;
125
+ const perLine = Math.max(1, Math.floor((codeWidth || 600) / charWidth));
126
+ return lineHeight * Math.max(1, Math.ceil(textLength(row) / perLine));
127
+ }
128
+
129
+ $: offsets = (() => {
130
+ void layoutVersion;
131
+ const out = new Float64Array(rows.length + 1);
132
+ for (let i = 0; i < rows.length; i++) {
133
+ const row = /** @type {import("./diff-controller.js").ViewRow} */ (
134
+ rows[i]
135
+ );
136
+ out[i + 1] =
137
+ /** @type {number} */ (out[i]) +
138
+ (measured.get(row.key) ?? estimate(row));
139
+ }
140
+ return out;
141
+ })();
142
+ $: total = /** @type {number} */ (offsets[rows.length] ?? 0);
143
+
144
+ /** Last row whose top is at or above `px`. */
145
+ function indexAt(
146
+ /** @type {number} */ px,
147
+ /** @type {Float64Array} */ table = offsets,
148
+ ) {
149
+ let lo = 0;
150
+ let hi = rows.length - 1;
151
+ let found = 0;
152
+ while (lo <= hi) {
153
+ const mid = (lo + hi) >> 1;
154
+ if (/** @type {number} */ (table[mid]) <= px) {
155
+ found = mid;
156
+ lo = mid + 1;
157
+ } else {
158
+ hi = mid - 1;
159
+ }
160
+ }
161
+ return found;
162
+ }
163
+
164
+ $: virtualized = virtualize === "auto" ? rows.length > 500 : virtualize;
165
+ $: start = virtualized
166
+ ? Math.max(0, indexAt(scrollTop, offsets) - overscan)
167
+ : 0;
168
+ $: end = virtualized
169
+ ? Math.min(
170
+ rows.length,
171
+ indexAt(scrollTop + clientHeight, offsets) + 1 + overscan,
172
+ )
173
+ : rows.length;
174
+ $: visible = $diff.renderRows(start, end);
175
+ $: windowTop = /** @type {number} */ (offsets[start] ?? 0);
176
+
177
+ $: if (hydrated) {
178
+ void offsets;
179
+ diff.setViewport(indexAt(scrollTop), indexAt(scrollTop + clientHeight) + 1);
180
+ }
181
+
182
+ // Measure rendered rows. Growth above the first visible row shifts
183
+ // scrollTop by the same amount, so the content under the reader stays put.
184
+ afterUpdate(() => {
185
+ if (!windowEl || !container) return;
186
+ const anchor = indexAt(container.scrollTop);
187
+ let changed = false;
188
+ let shift = 0;
189
+ for (const el of /** @type {HTMLElement[]} */ ([...windowEl.children])) {
190
+ const key = el.dataset.key;
191
+ const index = Number(el.dataset.index);
192
+ if (key === undefined || Number.isNaN(index)) continue;
193
+ const height = el.getBoundingClientRect().height;
194
+ const used =
195
+ /** @type {number} */ (offsets[index + 1]) -
196
+ /** @type {number} */ (offsets[index]);
197
+ if (Math.abs(height - used) > 0.5) {
198
+ measured.set(key, height);
199
+ changed = true;
200
+ if (index < anchor) shift += height - used;
201
+ }
202
+ }
203
+ const cell = /** @type {HTMLElement | null} */ (
204
+ windowEl.querySelector(".shl-diff-code")
205
+ );
206
+ if (cell && cell.clientWidth > 0) codeWidth = cell.clientWidth;
207
+ if (!changed) return;
208
+ layoutVersion++;
209
+ if (shift !== 0) setScrollTop(container.scrollTop + shift);
210
+ });
211
+
212
+ /** @param {number} row @param {"start" | "center" | "third"} align */
213
+ function scrollToRow(row, align) {
214
+ if (!container) return;
215
+ const top = /** @type {number} */ (
216
+ offsets[Math.max(0, Math.min(row, rows.length))] ?? 0
217
+ );
218
+ const offset =
219
+ align === "center"
220
+ ? container.clientHeight / 2
221
+ : align === "third"
222
+ ? container.clientHeight / 3
223
+ : 0;
224
+ setScrollTop(Math.max(0, top - offset));
225
+ }
226
+
227
+ // Where DiffView last put the scroll position. A scroll that lands
228
+ // anywhere else came from the reader: a scrollbar drag, a key, a swipe.
229
+ let ownScrollTop = -1;
230
+ /** @param {number} value */
231
+ function setScrollTop(value) {
232
+ container.scrollTop = value;
233
+ scrollTop = ownScrollTop = container.scrollTop;
234
+ }
235
+
236
+ /** @type {number | undefined} */
237
+ let frame;
238
+ function onScroll() {
239
+ if (
240
+ state.streaming &&
241
+ container &&
242
+ Math.abs(container.scrollTop - ownScrollTop) > 1
243
+ ) {
244
+ // If the content shrank under our position, the browser clamped it.
245
+ const max = container.scrollHeight - container.clientHeight;
246
+ if (ownScrollTop > max + 1) ownScrollTop = container.scrollTop;
247
+ else userScrolled = true;
248
+ }
249
+ if (frame !== undefined) return;
250
+ frame = requestAnimationFrame(() => {
251
+ frame = undefined;
252
+ if (container) scrollTop = container.scrollTop;
253
+ });
254
+ }
255
+
256
+ /** @param {WheelEvent} event */
257
+ function onWheel(event) {
258
+ const dx =
259
+ event.shiftKey && event.deltaX === 0 ? event.deltaY : event.deltaX;
260
+ if (
261
+ dx === 0 ||
262
+ (Math.abs(dx) < Math.abs(event.deltaY) && !event.shiftKey)
263
+ ) {
264
+ userScrolled = true;
265
+ return;
266
+ }
267
+ if (wrap) return;
268
+ const side = /** @type {HTMLElement} */ (event.target)
269
+ .closest?.("[data-side]")
270
+ ?.getAttribute("data-side");
271
+ const bar = view === "split" && side === "old" ? hbarOld : hbarNew;
272
+ if (!bar) return;
273
+ event.preventDefault();
274
+ bar.scrollLeft += dx;
275
+ }
276
+
277
+ /** @param {KeyboardEvent} event */
278
+ function onKeydown(event) {
279
+ if (!keyboard || event.metaKey || event.ctrlKey || event.altKey) return;
280
+ if (
281
+ /** @type {HTMLElement} */ (event.target).closest(
282
+ "button, input, textarea",
283
+ )
284
+ )
285
+ return;
286
+ const key = event.key;
287
+ if (key === "n" || key === "]" || key === "j") diff.nextChange();
288
+ else if (key === "p" || key === "[" || key === "k") diff.prevChange();
289
+ else if (key === "e") diff.expandAll();
290
+ else if (key === "c") diff.collapseAll();
291
+ else if (key === "v")
292
+ diff.setOptions({ view: view === "split" ? "unified" : "split" });
293
+ else if (review && current >= 0 && key === "a")
294
+ diff.decide(current, "accepted");
295
+ else if (review && current >= 0 && key === "r")
296
+ diff.decide(current, "rejected");
297
+ else if (review && current >= 0 && key === "u")
298
+ diff.decide(current, undefined);
299
+ else return;
300
+ event.preventDefault();
301
+ }
302
+
303
+ /** @param {MouseEvent} event */
304
+ function onMousedown(event) {
305
+ const side = /** @type {HTMLElement} */ (event.target)
306
+ .closest?.("[data-side]")
307
+ ?.getAttribute("data-side");
308
+ selectSide =
309
+ view === "split" && (side === "old" || side === "new") ? side : null;
310
+ }
311
+
312
+ // --- copy ---
313
+
314
+ /**
315
+ * Copies one file's text: in split view, the side the selection started
316
+ * on; in unified view, the new text, or the old text if only removed lines
317
+ * are selected. Fully selected lines come from the source, so tabs and
318
+ * carriage returns survive.
319
+ * @param {ClipboardEvent} event
320
+ */
321
+ function onCopy(event) {
322
+ const selection = window.getSelection();
323
+ if (!selection || selection.rangeCount === 0 || selection.isCollapsed)
324
+ return;
325
+ const range = selection.getRangeAt(0);
326
+ /** @type {Array<{ row: import("./diff-controller.js").ViewRow, el: HTMLElement }>} */
327
+ const picked = [];
328
+ for (const el of /** @type {HTMLElement[]} */ ([...windowEl.children])) {
329
+ const item = visible[Number(el.dataset.index) - start];
330
+ if (!item || !range.intersectsNode(el)) continue;
331
+ const kind = item.row.kind;
332
+ if (kind === "fold" || kind === "pending" || item.row.note) continue;
333
+ picked.push({ row: item.row, el });
334
+ }
335
+ if (picked.length < 2) return;
336
+
337
+ /** @type {"old" | "new"} */
338
+ let side = "new";
339
+ if (view === "split") side = selectSide ?? "new";
340
+ else if (picked.every(({ row }) => row.kind === "del")) side = "old";
341
+
342
+ /** @type {string[]} */
343
+ const lines = [];
344
+ for (const { row, el } of picked) {
345
+ if (
346
+ view === "unified" &&
347
+ (side === "new" ? row.kind === "del" : row.kind !== "del")
348
+ )
349
+ continue;
350
+ const index = side === "old" ? row.old : row.new;
351
+ if (index === undefined) continue;
352
+ const cell = el.querySelector(
353
+ view === "split"
354
+ ? `.shl-diff-code[data-side="${side}"] .shl-diff-text`
355
+ : ".shl-diff-code .shl-diff-text",
356
+ );
357
+ if (!cell) continue;
358
+ const whole = document.createRange();
359
+ whole.selectNodeContents(cell);
360
+ const startsInside =
361
+ range.compareBoundaryPoints(Range.START_TO_START, whole) > 0;
362
+ const endsInside =
363
+ range.compareBoundaryPoints(Range.END_TO_END, whole) < 0;
364
+ if (!startsInside && !endsInside) {
365
+ const source =
366
+ side === "old"
367
+ ? state.beforeLines[index]
368
+ : row.kind === "incoming"
369
+ ? state.partial
370
+ : state.afterLines[index];
371
+ lines.push(source ?? "");
372
+ continue;
373
+ }
374
+ const part = whole.cloneRange();
375
+ if (startsInside) part.setStart(range.startContainer, range.startOffset);
376
+ if (endsInside) part.setEnd(range.endContainer, range.endOffset);
377
+ lines.push(part.toString().replace(/\u200b/g, ""));
378
+ }
379
+ if (lines.length === 0 || !event.clipboardData) return;
380
+ event.clipboardData.setData("text/plain", lines.join("\n"));
381
+ event.preventDefault();
382
+ }
383
+
384
+ // Follow the streaming frontier unless the reader scrolled away.
385
+ let followQueued = false;
386
+ function followFrontier() {
387
+ if (
388
+ followQueued ||
389
+ !hydrated ||
390
+ !state.streaming ||
391
+ !follow ||
392
+ userScrolled
393
+ )
394
+ return;
395
+ followQueued = true;
396
+ requestAnimationFrame(() => {
397
+ followQueued = false;
398
+ if (!container || userScrolled) return;
399
+ const frontier = rows.findIndex(
400
+ (r) => r.kind === "incoming" || r.kind === "pending",
401
+ );
402
+ const index = frontier === -1 ? rows.length - 1 : frontier;
403
+ const top = /** @type {number} */ (offsets[index] ?? 0);
404
+ const max = Math.max(0, total - container.clientHeight);
405
+ const target = Math.min(
406
+ max,
407
+ Math.max(0, top - container.clientHeight * 0.6),
408
+ );
409
+ if (Math.abs(container.scrollTop - target) > lineHeight)
410
+ setScrollTop(target);
411
+ });
412
+ }
413
+ $: if (rows) followFrontier();
414
+ $: if (!state.streaming) userScrolled = false;
415
+
416
+ /** @param {import("./diff-controller.js").ViewRow} row */
417
+ function rowLabel(row) {
418
+ if (row.kind === "del") return `Removed line ${(row.old ?? 0) + 1}`;
419
+ if (row.kind === "add") return `Added line ${(row.new ?? 0) + 1}`;
420
+ if (row.kind === "change") {
421
+ const parts = [];
422
+ if (row.old !== undefined) parts.push(`removed line ${row.old + 1}`);
423
+ if (row.new !== undefined) parts.push(`added line ${row.new + 1}`);
424
+ return parts.join(", ");
425
+ }
426
+ return undefined;
427
+ }
428
+
429
+ /** @param {import("./diff-controller.js").ViewRow} row */
430
+ function moveTitle(row) {
431
+ if (row.movedTo !== undefined) return `Moved to line ${row.movedTo + 1}`;
432
+ if (row.movedFrom !== undefined)
433
+ return `Moved from line ${row.movedFrom + 1}`;
434
+ return undefined;
435
+ }
436
+
437
+ /**
438
+ * Without `wrap`, code rows are exactly one line tall.
439
+ * @param {import("./diff-controller.js").ViewRow} row
440
+ * @param {boolean} wrapped
441
+ * @param {number} height
442
+ */
443
+ function rowStyle(row, wrapped, height) {
444
+ return wrapped || row.note
445
+ ? `min-height: ${height}px;`
446
+ : `height: ${height}px;`;
447
+ }
448
+
449
+ onMount(() => {
450
+ watchLineHeight(
451
+ () => probe,
452
+ () => lineHeight,
453
+ (height) => (lineHeight = height),
454
+ );
455
+ tick().then(() => {
456
+ if (charProbe)
457
+ charWidth = charProbe.getBoundingClientRect().width / 10 || charWidth;
458
+ });
459
+ hydrated = true;
460
+ clientHeight = container.clientHeight;
461
+ clientWidth = container.clientWidth;
462
+ const observer = new ResizeObserver(() => {
463
+ if (!container) return;
464
+ clientHeight = container.clientHeight;
465
+ clientWidth = container.clientWidth;
466
+ });
467
+ observer.observe(container);
468
+ const offReveal = diff.on("reveal", ({ row, align }) =>
469
+ scrollToRow(row, align),
470
+ );
471
+ return () => {
472
+ observer.disconnect();
473
+ offReveal();
474
+ if (frame !== undefined) cancelAnimationFrame(frame);
475
+ };
476
+ });
477
+ </script>
478
+
479
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
480
+ <section
481
+ class="shl-diff shl-diff-theme {_class ?? ''}"
482
+ class:shl-diff-split={view === "split"}
483
+ class:shl-diff-colorblind={palette === "colorblind"}
484
+ class:shl-diff-streaming={state.streaming}
485
+ class:shl-diff-wrap={wrap}
486
+ data-select={selectSide}
487
+ aria-label="Diff: {$diff.stats().additions} additions, {$diff.stats()
488
+ .deletions} deletions"
489
+ tabindex="0"
490
+ {...rest}
491
+ style="--shl-diff-gutter: {columns.gutter}ch; --shl-diff-line: {lineHeight}px; tab-size: {options.tabSize}; {_style ??
492
+ ''}"
493
+ on:keydown={onKeydown}
494
+ on:mousedown={onMousedown}
495
+ on:copy={onCopy}
496
+ >
497
+ <div class="shl-diff-frame hljs">
498
+ <div
499
+ class="shl-diff-body"
500
+ bind:this={container}
501
+ on:scroll={onScroll}
502
+ on:wheel={onWheel}
503
+ role="table"
504
+ aria-rowcount={rows.length}
505
+ >
506
+ <div
507
+ class="shl-diff-sizer"
508
+ style={virtualized ? `height: ${total}px;` : undefined}
509
+ >
510
+ <div
511
+ bind:this={windowEl}
512
+ class="shl-diff-window"
513
+ class:shl-diff-window-flat={!virtualized}
514
+ style={virtualized
515
+ ? `transform: translateY(${windowTop}px);`
516
+ : undefined}
517
+ >
518
+ {#each visible as item (item.row.key)}
519
+ {@const row = item.row}
520
+ {@const decision =
521
+ row.change === undefined ? undefined : decisions.get(row.change)}
522
+ <div
523
+ class="shl-diff-row shl-diff-{row.kind}"
524
+ class:shl-diff-moved={row.moved !== undefined}
525
+ class:shl-diff-current={row.change !== undefined &&
526
+ row.change === current}
527
+ class:shl-diff-accepted={decision === "accepted"}
528
+ class:shl-diff-rejected={decision === "rejected"}
529
+ class:shl-diff-unpaired-old={row.kind === "change" &&
530
+ row.old === undefined}
531
+ class:shl-diff-unpaired-new={row.kind === "change" &&
532
+ row.new === undefined}
533
+ style={rowStyle(row, wrap, lineHeight)}
534
+ data-key={row.key}
535
+ data-index={item.index}
536
+ role="row"
537
+ aria-rowindex={item.index + 1}
538
+ aria-label={rowLabel(row)}
539
+ title={moveTitle(row)}
540
+ >
541
+ {#if row.kind === "fold" && row.fold}
542
+ <span class="shl-diff-fold-cell" role="cell">
543
+ <slot
544
+ name="fold"
545
+ fold={row.fold}
546
+ count={row.count}
547
+ toggle={() => diff.toggleFold(row.key)}
548
+ >
549
+ {#if row.fold.unknown}
550
+ <span class="shl-diff-fold-label">
551
+ <span class="shl-diff-fold-icon" aria-hidden="true"
552
+ >⋯</span
553
+ >
554
+ {`${row.count} lines not in patch`}
555
+ <span class="shl-diff-hunk">{row.fold.header}</span>
556
+ </span>
557
+ {:else}
558
+ <button
559
+ type="button"
560
+ class="shl-diff-fold-label"
561
+ on:click={() => diff.toggleFold(row.key)}
562
+ >
563
+ <span class="shl-diff-fold-icon" aria-hidden="true"
564
+ >↕</span
565
+ >
566
+ {`Expand ${row.count} unchanged ${row.count === 1 ? "line" : "lines"}`}
567
+ <span class="shl-diff-hunk">{row.fold.header}</span>
568
+ </button>
569
+ {/if}
570
+ </slot>
571
+ </span>
572
+ {:else if row.kind === "pending"}
573
+ <span class="shl-diff-fold-label" role="cell">
574
+ <span class="shl-diff-spinner" aria-hidden="true"></span>
575
+ {`${row.count} ${row.count === 1 ? "line" : "lines"} not reached yet`}
576
+ </span>
577
+ {:else if row.note}
578
+ <div class="shl-diff-note-slot" role="cell">
579
+ <slot name="note" note={row.note}>
580
+ <div
581
+ class="shl-diff-note-card shl-diff-note-{row.note.tone ??
582
+ 'info'}"
583
+ >
584
+ {#if row.note.author}
585
+ <strong>{row.note.author}</strong>
586
+ {/if}
587
+ <span>{row.note.body}</span>
588
+ </div>
589
+ </slot>
590
+ </div>
591
+ {:else if view === "split"}
592
+ <span class="shl-diff-num" aria-hidden="true"
593
+ >{row.old === undefined ? "" : row.old + 1}</span
594
+ >
595
+ <span
596
+ class="shl-diff-marker shl-diff-side-old"
597
+ data-side="old"
598
+ role="cell"
599
+ >{row.kind === "change" && row.old !== undefined
600
+ ? "-"
601
+ : ""}</span
602
+ >
603
+ <span
604
+ class="shl-diff-code shl-diff-side-old"
605
+ data-side="old"
606
+ role="cell"
607
+ ><span
608
+ class="shl-diff-text"
609
+ style={wrap
610
+ ? undefined
611
+ : `transform: translateX(${-scrollOld}px);`}
612
+ >{@html row.old === undefined
613
+ ? ""
614
+ : item.oldHtml || "​"}</span
615
+ ></span
616
+ >
617
+ <span class="shl-diff-num shl-diff-num-new" aria-hidden="true"
618
+ >{row.new === undefined ? "" : row.new + 1}</span
619
+ >
620
+ <span
621
+ class="shl-diff-marker shl-diff-side-new"
622
+ data-side="new"
623
+ role="cell"
624
+ >{row.kind === "change" && row.new !== undefined
625
+ ? "+"
626
+ : ""}</span
627
+ >
628
+ <span
629
+ class="shl-diff-code shl-diff-side-new"
630
+ data-side="new"
631
+ role="cell"
632
+ ><span
633
+ class="shl-diff-text"
634
+ style={wrap
635
+ ? undefined
636
+ : `transform: translateX(${-scrollNew}px);`}
637
+ >{@html row.new === undefined
638
+ ? ""
639
+ : item.newHtml || "​"}</span
640
+ >
641
+ {#if row.kind === "incoming"}
642
+ <span class="shl-diff-caret" aria-hidden="true"></span>
643
+ {/if}</span
644
+ >
645
+ {:else}
646
+ <span class="shl-diff-num" aria-hidden="true"
647
+ >{row.old === undefined ? "" : row.old + 1}</span
648
+ >
649
+ <span class="shl-diff-num" aria-hidden="true"
650
+ >{row.new === undefined ? "" : row.new + 1}</span
651
+ >
652
+ <span class="shl-diff-marker" role="cell"
653
+ >{row.kind === "del"
654
+ ? "-"
655
+ : row.kind === "add" || row.kind === "incoming"
656
+ ? "+"
657
+ : ""}</span
658
+ >
659
+ <span class="shl-diff-code" data-side="new" role="cell"
660
+ ><span
661
+ class="shl-diff-text"
662
+ style={wrap
663
+ ? undefined
664
+ : `transform: translateX(${-scrollNew}px);`}
665
+ >{@html (row.kind === "del"
666
+ ? item.oldHtml
667
+ : item.newHtml) || "​"}</span
668
+ >
669
+ {#if row.kind === "incoming"}
670
+ <span class="shl-diff-caret" aria-hidden="true"></span>
671
+ {/if}</span
672
+ >
673
+ {/if}
674
+ {#if row.first && row.change !== undefined && (review || $$slots.actions)}
675
+ {@const change = row.change}
676
+ <span class="shl-diff-actions" role="cell">
677
+ <slot
678
+ name="actions"
679
+ {change}
680
+ {decision}
681
+ decide={(
682
+ /** @type {"accepted" | "rejected" | undefined} */ d,
683
+ ) => diff.decide(change, d)}
684
+ >
685
+ {#if decision}
686
+ <span class="shl-diff-decision">{decision}</span>
687
+ <button
688
+ type="button"
689
+ on:click={() => diff.decide(change, undefined)}
690
+ >
691
+ Undo
692
+ </button>
693
+ {:else}
694
+ <button
695
+ type="button"
696
+ class="shl-diff-accept"
697
+ on:click={() => diff.decide(change, "accepted")}
698
+ >
699
+ Accept
700
+ </button>
701
+ <button
702
+ type="button"
703
+ class="shl-diff-reject"
704
+ on:click={() => diff.decide(change, "rejected")}
705
+ >
706
+ Reject
707
+ </button>
708
+ {/if}
709
+ </slot>
710
+ </span>
711
+ {/if}
712
+ </div>
713
+ {/each}
714
+ </div>
715
+ </div>
716
+ </div>
717
+ {#if !wrap}
718
+ <div class="shl-diff-hbar-row" aria-hidden="true">
719
+ {#if view === "split"}
720
+ <span></span><span></span>
721
+ <div
722
+ class="shl-diff-hbar"
723
+ bind:this={hbarOld}
724
+ on:scroll={() => (scrollOld = hbarOld?.scrollLeft ?? 0)}
725
+ >
726
+ <div
727
+ style="width: {(columns.old + 2) * charWidth}px; height: 1px;"
728
+ ></div>
729
+ </div>
730
+ <span></span><span></span>
731
+ <div
732
+ class="shl-diff-hbar"
733
+ bind:this={hbarNew}
734
+ on:scroll={() => (scrollNew = hbarNew?.scrollLeft ?? 0)}
735
+ >
736
+ <div
737
+ style="width: {(columns.new + 2) * charWidth}px; height: 1px;"
738
+ ></div>
739
+ </div>
740
+ {:else}
741
+ <span></span><span></span><span></span>
742
+ <div
743
+ class="shl-diff-hbar"
744
+ bind:this={hbarNew}
745
+ on:scroll={() => (scrollNew = hbarNew?.scrollLeft ?? 0)}
746
+ >
747
+ <div
748
+ style="width: {(Math.max(columns.old, columns.new) + 2) *
749
+ charWidth}px; height: 1px;"
750
+ ></div>
751
+ </div>
752
+ {/if}
753
+ </div>
754
+ {/if}
755
+ <span
756
+ class="shl-diff-probe shl-diff-row"
757
+ bind:this={probe}
758
+ aria-hidden="true"><span class="shl-diff-code">&nbsp;</span></span
759
+ >
760
+ <span class="shl-diff-char-probe" bind:this={charProbe} aria-hidden="true"
761
+ >0000000000</span
762
+ >
763
+ </div>
764
+ </section>
765
+
766
+ <style>
767
+ :global(.shl-diff-theme) {
768
+ --shl-diff-add: rgba(46, 160, 67, 0.16);
769
+ --shl-diff-add-word: rgba(46, 160, 67, 0.45);
770
+ --shl-diff-add-accent: #3fb950;
771
+ --shl-diff-del: rgba(248, 81, 73, 0.16);
772
+ --shl-diff-del-word: rgba(248, 81, 73, 0.45);
773
+ --shl-diff-del-accent: #f85149;
774
+ --shl-diff-move: rgba(163, 113, 247, 0.18);
775
+ --shl-diff-move-accent: #a371f7;
776
+ --shl-diff-muted: color-mix(in srgb, currentColor 45%, transparent);
777
+ --shl-diff-rule: color-mix(in srgb, currentColor 12%, transparent);
778
+ }
779
+
780
+ :global(.shl-diff-theme.shl-diff-colorblind) {
781
+ --shl-diff-add: rgba(56, 139, 253, 0.18);
782
+ --shl-diff-add-word: rgba(56, 139, 253, 0.5);
783
+ --shl-diff-add-accent: #58a6ff;
784
+ --shl-diff-del: rgba(219, 109, 40, 0.18);
785
+ --shl-diff-del-word: rgba(219, 109, 40, 0.5);
786
+ --shl-diff-del-accent: #db6d28;
787
+ }
788
+
789
+ .shl-diff {
790
+ position: relative;
791
+ display: flex;
792
+ flex-direction: column;
793
+ height: 400px;
794
+ min-width: 0;
795
+ outline: none;
796
+ font-family: var(
797
+ --shl-diff-font,
798
+ ui-monospace,
799
+ SFMono-Regular,
800
+ Menlo,
801
+ Consolas,
802
+ monospace
803
+ );
804
+ font-size: var(--shl-diff-font-size, 13px);
805
+ }
806
+
807
+ .shl-diff:focus-visible {
808
+ box-shadow: 0 0 0 2px var(--shl-diff-move-accent);
809
+ }
810
+
811
+ .shl-diff-frame {
812
+ position: relative;
813
+ display: flex;
814
+ flex: 1;
815
+ flex-direction: column;
816
+ min-height: 0;
817
+ }
818
+
819
+ /* Beat a theme's `.hljs` padding without `!important`. */
820
+ .shl-diff .shl-diff-frame.hljs {
821
+ padding: 0;
822
+ }
823
+
824
+ .shl-diff-body {
825
+ overflow-anchor: none;
826
+ position: relative;
827
+ flex: 1;
828
+ min-height: 0;
829
+ overflow-x: hidden;
830
+ overflow-y: auto;
831
+ scrollbar-gutter: stable;
832
+ }
833
+
834
+ .shl-diff-sizer {
835
+ position: relative;
836
+ }
837
+
838
+ .shl-diff-window {
839
+ position: absolute;
840
+ top: 0;
841
+ left: 0;
842
+ right: 0;
843
+ }
844
+
845
+ .shl-diff-window-flat {
846
+ position: static;
847
+ }
848
+
849
+ .shl-diff-row,
850
+ .shl-diff-hbar-row {
851
+ display: grid;
852
+ grid-template-columns:
853
+ var(--shl-diff-gutter) var(--shl-diff-gutter)
854
+ 2ch minmax(0, 1fr);
855
+ align-items: start;
856
+ line-height: var(--shl-diff-line);
857
+ white-space: pre;
858
+ position: relative;
859
+ }
860
+
861
+ .shl-diff-hbar-row {
862
+ scrollbar-gutter: stable;
863
+ overflow-y: hidden;
864
+ }
865
+
866
+ .shl-diff-split .shl-diff-row,
867
+ .shl-diff-split .shl-diff-hbar-row {
868
+ grid-template-columns:
869
+ var(--shl-diff-gutter) 2ch minmax(0, 1fr)
870
+ var(--shl-diff-gutter) 2ch minmax(0, 1fr);
871
+ }
872
+
873
+ .shl-diff-hbar {
874
+ overflow-x: auto;
875
+ overflow-y: hidden;
876
+ height: 10px;
877
+ }
878
+
879
+ .shl-diff-num {
880
+ padding-right: 1ch;
881
+ text-align: right;
882
+ color: var(--shl-diff-muted);
883
+ user-select: none;
884
+ }
885
+
886
+ .shl-diff-num-new {
887
+ border-left: 1px solid var(--shl-diff-rule);
888
+ }
889
+
890
+ .shl-diff-marker {
891
+ color: var(--shl-diff-muted);
892
+ user-select: none;
893
+ text-align: center;
894
+ }
895
+
896
+ .shl-diff-code {
897
+ overflow: hidden;
898
+ padding-right: 2ch;
899
+ }
900
+
901
+ .shl-diff-text {
902
+ display: inline-block;
903
+ }
904
+
905
+ .shl-diff-wrap .shl-diff-row {
906
+ white-space: pre-wrap;
907
+ }
908
+
909
+ .shl-diff-wrap .shl-diff-row .shl-diff-code {
910
+ overflow-wrap: anywhere;
911
+ }
912
+
913
+ .shl-diff-wrap .shl-diff-text {
914
+ display: inline;
915
+ }
916
+
917
+ /* Unified */
918
+ .shl-diff-del {
919
+ background: var(--shl-diff-del);
920
+ }
921
+
922
+ .shl-diff-add,
923
+ .shl-diff-incoming {
924
+ background: var(--shl-diff-add);
925
+ }
926
+
927
+ .shl-diff-del .shl-diff-marker {
928
+ color: var(--shl-diff-del-accent);
929
+ }
930
+
931
+ .shl-diff-add .shl-diff-marker,
932
+ .shl-diff-incoming .shl-diff-marker {
933
+ color: var(--shl-diff-add-accent);
934
+ }
935
+
936
+ .shl-diff-del :global(.shl-diff-word) {
937
+ background: var(--shl-diff-del-word);
938
+ border-radius: 2px;
939
+ }
940
+
941
+ .shl-diff-add :global(.shl-diff-word),
942
+ .shl-diff-side-new :global(.shl-diff-word) {
943
+ background: var(--shl-diff-add-word);
944
+ border-radius: 2px;
945
+ }
946
+
947
+ /* Split: color each side on its own. */
948
+ .shl-diff-split .shl-diff-change > .shl-diff-side-old {
949
+ background: var(--shl-diff-del);
950
+ }
951
+
952
+ .shl-diff-split .shl-diff-change > .shl-diff-side-new {
953
+ background: var(--shl-diff-add);
954
+ }
955
+
956
+ .shl-diff-split .shl-diff-change > .shl-diff-marker.shl-diff-side-old {
957
+ color: var(--shl-diff-del-accent);
958
+ }
959
+
960
+ .shl-diff-split .shl-diff-change > .shl-diff-marker.shl-diff-side-new {
961
+ color: var(--shl-diff-add-accent);
962
+ }
963
+
964
+ .shl-diff-split .shl-diff-side-old :global(.shl-diff-word) {
965
+ background: var(--shl-diff-del-word);
966
+ border-radius: 2px;
967
+ }
968
+
969
+ .shl-diff-split .shl-diff-unpaired-old > .shl-diff-side-old,
970
+ .shl-diff-split .shl-diff-unpaired-new > .shl-diff-side-new {
971
+ background: repeating-linear-gradient(
972
+ -45deg,
973
+ transparent 0 4px,
974
+ var(--shl-diff-rule) 4px 5px
975
+ );
976
+ }
977
+
978
+ .shl-diff-split .shl-diff-incoming > .shl-diff-side-new {
979
+ background: var(--shl-diff-add);
980
+ }
981
+
982
+ .shl-diff-split .shl-diff-incoming {
983
+ background: none;
984
+ }
985
+
986
+ /* Moved blocks */
987
+ .shl-diff-row.shl-diff-moved,
988
+ .shl-diff-split .shl-diff-moved > .shl-diff-code,
989
+ .shl-diff-split .shl-diff-moved > .shl-diff-marker {
990
+ background: var(--shl-diff-move);
991
+ }
992
+
993
+ .shl-diff .shl-diff-row.shl-diff-moved .shl-diff-marker {
994
+ color: var(--shl-diff-move-accent);
995
+ }
996
+
997
+ .shl-diff-moved::after {
998
+ content: "";
999
+ position: absolute;
1000
+ left: 0;
1001
+ top: 0;
1002
+ bottom: 0;
1003
+ width: 2px;
1004
+ background: var(--shl-diff-move-accent);
1005
+ }
1006
+
1007
+ /* Folds and status rows */
1008
+ .shl-diff-fold,
1009
+ .shl-diff-pending {
1010
+ display: flex;
1011
+ overflow: hidden;
1012
+ white-space: nowrap;
1013
+ background: color-mix(in srgb, var(--shl-diff-move-accent) 8%, transparent);
1014
+ color: var(--shl-diff-muted);
1015
+ }
1016
+
1017
+ .shl-diff-fold-cell {
1018
+ display: flex;
1019
+ flex: 1;
1020
+ min-width: 0;
1021
+ height: 100%;
1022
+ }
1023
+
1024
+ .shl-diff-fold-label {
1025
+ font: inherit;
1026
+ height: 100%;
1027
+ margin: 0;
1028
+ padding: 0 0 0 1ch;
1029
+ display: flex;
1030
+ gap: 1ch;
1031
+ align-items: center;
1032
+ color: inherit;
1033
+ background: none;
1034
+ border: 0;
1035
+ cursor: default;
1036
+ width: 100%;
1037
+ text-align: left;
1038
+ user-select: none;
1039
+ }
1040
+
1041
+ button.shl-diff-fold-label {
1042
+ cursor: pointer;
1043
+ }
1044
+
1045
+ button.shl-diff-fold-label:hover {
1046
+ color: var(--shl-diff-move-accent);
1047
+ }
1048
+
1049
+ .shl-diff-hunk {
1050
+ opacity: 0.8;
1051
+ margin-left: auto;
1052
+ padding-right: 2ch;
1053
+ }
1054
+
1055
+ .shl-diff-spinner {
1056
+ width: 0.8em;
1057
+ height: 0.8em;
1058
+ border: 2px solid currentColor;
1059
+ border-right-color: transparent;
1060
+ border-radius: 50%;
1061
+ animation: shl-diff-spin 0.8s linear infinite;
1062
+ }
1063
+
1064
+ @keyframes shl-diff-spin {
1065
+ to {
1066
+ transform: rotate(360deg);
1067
+ }
1068
+ }
1069
+
1070
+ .shl-diff-caret {
1071
+ display: inline-block;
1072
+ width: 0.55em;
1073
+ height: 1.1em;
1074
+ vertical-align: text-bottom;
1075
+ background: var(--shl-diff-add-accent);
1076
+ animation: shl-diff-blink 1s steps(1) infinite;
1077
+ }
1078
+
1079
+ @keyframes shl-diff-blink {
1080
+ 50% {
1081
+ opacity: 0;
1082
+ }
1083
+ }
1084
+
1085
+ @media (prefers-reduced-motion: reduce) {
1086
+ .shl-diff-caret,
1087
+ .shl-diff-spinner {
1088
+ animation: none;
1089
+ }
1090
+ }
1091
+
1092
+ /* Review */
1093
+ .shl-diff-current {
1094
+ box-shadow: inset 3px 0 0 var(--shl-diff-move-accent);
1095
+ }
1096
+
1097
+ .shl-diff-rejected {
1098
+ opacity: 0.45;
1099
+ }
1100
+
1101
+ .shl-diff-row.shl-diff-rejected.shl-diff-add .shl-diff-code,
1102
+ .shl-diff-split .shl-diff-rejected > .shl-diff-side-new {
1103
+ text-decoration: line-through;
1104
+ }
1105
+
1106
+ .shl-diff-row.shl-diff-accepted.shl-diff-del .shl-diff-code,
1107
+ .shl-diff-split .shl-diff-accepted > .shl-diff-side-old {
1108
+ text-decoration: line-through;
1109
+ opacity: 0.6;
1110
+ }
1111
+
1112
+ .shl-diff-actions {
1113
+ position: absolute;
1114
+ right: 1ch;
1115
+ top: 0;
1116
+ display: flex;
1117
+ gap: 4px;
1118
+ z-index: 1;
1119
+ }
1120
+
1121
+ .shl-diff-actions button {
1122
+ font: inherit;
1123
+ font-size: 0.85em;
1124
+ line-height: 1.4;
1125
+ padding: 0 0.6em;
1126
+ border-radius: 3px;
1127
+ border: 1px solid var(--shl-diff-rule);
1128
+ background: color-mix(in srgb, Canvas 85%, transparent);
1129
+ color: CanvasText;
1130
+ cursor: pointer;
1131
+ }
1132
+
1133
+ .shl-diff-accept:hover {
1134
+ border-color: var(--shl-diff-add-accent);
1135
+ }
1136
+
1137
+ .shl-diff-reject:hover {
1138
+ border-color: var(--shl-diff-del-accent);
1139
+ }
1140
+
1141
+ .shl-diff-decision {
1142
+ font-size: 0.85em;
1143
+ text-transform: uppercase;
1144
+ letter-spacing: 0.05em;
1145
+ color: var(--shl-diff-muted);
1146
+ }
1147
+
1148
+ /* Notes */
1149
+ .shl-diff-note-slot {
1150
+ grid-column: 1 / -1;
1151
+ white-space: normal;
1152
+ }
1153
+
1154
+ .shl-diff-note-card {
1155
+ margin: 2px 2ch 2px calc(var(--shl-diff-gutter) * 2);
1156
+ padding: 0 1ch;
1157
+ border-left: 3px solid var(--shl-diff-move-accent);
1158
+ background: color-mix(
1159
+ in srgb,
1160
+ var(--shl-diff-move-accent) 10%,
1161
+ transparent
1162
+ );
1163
+ white-space: pre-wrap;
1164
+ overflow: hidden;
1165
+ font-family: system-ui, sans-serif;
1166
+ font-size: 0.92em;
1167
+ }
1168
+
1169
+ .shl-diff-note-card strong {
1170
+ margin-right: 1ch;
1171
+ }
1172
+
1173
+ .shl-diff-note-card.shl-diff-note-warning {
1174
+ border-color: #d29922;
1175
+ background: rgba(210, 153, 34, 0.12);
1176
+ }
1177
+
1178
+ .shl-diff-note-card.shl-diff-note-error {
1179
+ border-color: var(--shl-diff-del-accent);
1180
+ background: var(--shl-diff-del);
1181
+ }
1182
+
1183
+ .shl-diff-note-card.shl-diff-note-suggestion {
1184
+ border-color: var(--shl-diff-add-accent);
1185
+ background: var(--shl-diff-add);
1186
+ }
1187
+
1188
+ /* Split selection: copy from one side only. */
1189
+ .shl-diff[data-select="old"] [data-side="new"],
1190
+ .shl-diff[data-select="new"] [data-side="old"] {
1191
+ user-select: none;
1192
+ }
1193
+
1194
+ .shl-diff-code :global(.shl-diff-cr)::after {
1195
+ content: "␍";
1196
+ opacity: 0.6;
1197
+ }
1198
+
1199
+ .shl-diff-code :global(.shl-diff-noeol)::after {
1200
+ content: " ⊘ no newline at end of file";
1201
+ color: var(--shl-diff-muted);
1202
+ font-style: italic;
1203
+ user-select: none;
1204
+ }
1205
+
1206
+ .shl-diff-probe,
1207
+ .shl-diff-char-probe {
1208
+ position: absolute;
1209
+ visibility: hidden;
1210
+ pointer-events: none;
1211
+ white-space: pre;
1212
+ }
1213
+ </style>