svelte-highlight 7.23.2 → 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 (94) 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 -756
  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 +735 -18
  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/auto-detect.d.ts +52 -0
  48. package/auto-detect.js +208 -0
  49. package/code-region.d.ts +7 -0
  50. package/code-region.js +20 -0
  51. package/css-highlights.js +115 -0
  52. package/css-walk.js +50 -0
  53. package/diff-controller.d.ts +120 -0
  54. package/diff-controller.js +721 -0
  55. package/diff-edits.d.ts +101 -0
  56. package/diff-edits.js +890 -0
  57. package/diff-html.d.ts +8 -0
  58. package/diff-html.js +60 -0
  59. package/diff-languages.d.ts +4 -0
  60. package/diff-languages.js +73 -0
  61. package/diff.d.ts +161 -0
  62. package/diff.js +1111 -0
  63. package/editable-commands.js +81 -0
  64. package/editable-css-paint.js +5 -3
  65. package/editable-dom-paint.js +1 -1
  66. package/editable-history.js +199 -0
  67. package/editable-line-dom.js +176 -1
  68. package/editable-painter.js +356 -0
  69. package/editable.d.ts +118 -0
  70. package/editable.js +513 -0
  71. package/engine.d.ts +1 -1
  72. package/fence.js +1 -1
  73. package/highlight-cascade.js +679 -0
  74. package/highlight-theme.js +6 -47
  75. package/incremental-tokenize.js +1 -1
  76. package/index.d.ts +39 -6
  77. package/index.js +30 -0
  78. package/languages/detect-index.d.ts +16 -0
  79. package/languages/detect-index.js +6 -0
  80. package/languages/loaders.d.ts +8 -0
  81. package/languages/loaders.js +370 -0
  82. package/package.json +50 -2
  83. package/preprocessor.js +20 -5
  84. package/search.js +2 -2
  85. package/stream-highlighter.js +198 -0
  86. package/stream.css +16 -0
  87. package/stream.d.ts +60 -0
  88. package/stream.js +283 -0
  89. package/style-registry.js +34 -3
  90. package/themes/_base-css.d.ts +1 -0
  91. package/themes/_base-css.js +1 -0
  92. package/typewriter-units.d.ts +3 -0
  93. package/typewriter-units.js +43 -0
  94. package/virtual-window.js +9 -4
@@ -0,0 +1,99 @@
1
+ <script>
2
+ /**
3
+ * A controller from `createDiffController`.
4
+ * @type {import("./diff-controller.js").DiffController}
5
+ */
6
+ export let diff;
7
+
8
+ import { onMount } from "svelte";
9
+
10
+ $: ({ class: _class, ...rest } = $$restProps);
11
+ $: marks = $diff.marks();
12
+ $: total = $diff.rows().length;
13
+
14
+ let viewport = { start: 0, end: 0, count: 0 };
15
+
16
+ /** @param {MouseEvent} event */
17
+ function onClick(event) {
18
+ const rect = /** @type {HTMLElement} */ (
19
+ event.currentTarget
20
+ ).getBoundingClientRect();
21
+ diff.reveal(
22
+ Math.floor(((event.clientY - rect.top) / rect.height) * total),
23
+ "center",
24
+ );
25
+ }
26
+
27
+ onMount(() => diff.on("viewport", (v) => (viewport = v)));
28
+ </script>
29
+
30
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
31
+ <div
32
+ {...rest}
33
+ class="shl-diff-minimap shl-diff-theme {$$restProps.class ?? ''}"
34
+ title="Changes in this file. Click to jump."
35
+ role="presentation"
36
+ on:click={onClick}
37
+ >
38
+ {#each marks as mark (mark.rowIndex)}
39
+ <span
40
+ class="shl-diff-mark shl-diff-mark-{mark.kind}"
41
+ class:shl-diff-mark-rejected={mark.decision === "rejected"}
42
+ style="top: {mark.top * 100}%; height: max(2px, {mark.height * 100}%);"
43
+ ></span>
44
+ {/each}
45
+ {#if total > 0}
46
+ <span
47
+ class="shl-diff-mark-viewport"
48
+ style="top: {(viewport.start / total) * 100}%; height: {(Math.min(
49
+ total,
50
+ viewport.end - viewport.start,
51
+ ) /
52
+ total) *
53
+ 100}%;"
54
+ ></span>
55
+ {/if}
56
+ </div>
57
+
58
+ <style>
59
+ .shl-diff-minimap {
60
+ position: relative;
61
+ flex: none;
62
+ width: 10px;
63
+ cursor: pointer;
64
+ background: var(--shl-diff-rule, rgba(128, 128, 128, 0.15));
65
+ }
66
+
67
+ .shl-diff-mark {
68
+ position: absolute;
69
+ left: 1px;
70
+ right: 1px;
71
+ }
72
+
73
+ .shl-diff-mark-add {
74
+ background: var(--shl-diff-add-accent, #3fb950);
75
+ }
76
+
77
+ .shl-diff-mark-del {
78
+ background: var(--shl-diff-del-accent, #f85149);
79
+ }
80
+
81
+ .shl-diff-mark-mod {
82
+ background: linear-gradient(
83
+ var(--shl-diff-del-accent, #f85149) 50%,
84
+ var(--shl-diff-add-accent, #3fb950) 50%
85
+ );
86
+ }
87
+
88
+ .shl-diff-mark-rejected {
89
+ opacity: 0.3;
90
+ }
91
+
92
+ .shl-diff-mark-viewport {
93
+ position: absolute;
94
+ left: 0;
95
+ right: 0;
96
+ border: 1px solid color-mix(in srgb, currentColor 50%, transparent);
97
+ pointer-events: none;
98
+ }
99
+ </style>
@@ -0,0 +1,17 @@
1
+ import type { SvelteComponentTyped } from "svelte";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ import type { DiffController } from "./diff-controller";
4
+
5
+ export type DiffMinimapProps = HTMLAttributes<HTMLDivElement> & {
6
+ /**
7
+ * A controller from `createDiffController`. Shows one mark per change
8
+ * and the visible area of every `DiffView` on it. Click to jump.
9
+ */
10
+ diff: DiffController;
11
+ };
12
+
13
+ export default class DiffMinimap extends SvelteComponentTyped<
14
+ DiffMinimapProps,
15
+ Record<string, never>,
16
+ Record<string, never>
17
+ > {}
@@ -0,0 +1,43 @@
1
+ <script>
2
+ /**
3
+ * A controller from `createDiffController`.
4
+ * @type {import("./diff-controller.js").DiffController}
5
+ */
6
+ export let diff;
7
+
8
+ import { onMount } from "svelte";
9
+
10
+ $: ({ class: _class, ...rest } = $$restProps);
11
+ $: stats = $diff.stats();
12
+
13
+ /** @type {{ index: number, count: number } | null} */
14
+ let position = null;
15
+
16
+ onMount(() => diff.on("navigate", (detail) => (position = detail)));
17
+ </script>
18
+
19
+ <span {...rest} class="shl-diff-stats shl-diff-theme {$$restProps.class ?? ''}">
20
+ <span class="shl-diff-stats-add">+{stats.additions}</span>
21
+ <span class="shl-diff-stats-del">−{stats.deletions}</span>
22
+ <span>
23
+ · {stats.changes}
24
+ {stats.changes === 1 ? "change" : "changes"}
25
+ {#if position}
26
+ · {position.index + 1} of {position.count}
27
+ {/if}
28
+ </span>
29
+ </span>
30
+
31
+ <style>
32
+ .shl-diff-stats {
33
+ font-variant-numeric: tabular-nums;
34
+ }
35
+
36
+ .shl-diff-stats-add {
37
+ color: var(--shl-diff-add-accent, #3fb950);
38
+ }
39
+
40
+ .shl-diff-stats-del {
41
+ color: var(--shl-diff-del-accent, #f85149);
42
+ }
43
+ </style>
@@ -0,0 +1,17 @@
1
+ import type { SvelteComponentTyped } from "svelte";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ import type { DiffController } from "./diff-controller";
4
+
5
+ export type DiffStatsProps = HTMLAttributes<HTMLSpanElement> & {
6
+ /**
7
+ * A controller from `createDiffController`. Shows +additions,
8
+ * −deletions, the change count, and the position after navigating.
9
+ */
10
+ diff: DiffController;
11
+ };
12
+
13
+ export default class DiffStats extends SvelteComponentTyped<
14
+ DiffStatsProps,
15
+ Record<string, never>,
16
+ Record<string, never>
17
+ > {}