svelte-highlight 7.14.1 → 7.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AnsiOutput.svelte +22 -3
- package/CopyButton.svelte +10 -2
- package/CopyButton.svelte.d.ts +8 -1
- package/Highlight.svelte +2 -1
- package/HighlightAuto.svelte +1 -1
- package/HighlightEditable.svelte +434 -43
- package/HighlightEditable.svelte.d.ts +31 -0
- package/HighlightStream.svelte +154 -0
- package/HighlightStream.svelte.d.ts +90 -0
- package/HighlightStyle.svelte +70 -5
- package/HighlightSvelte.svelte +2 -1
- package/README.md +119 -3
- package/Typewriter.svelte +111 -58
- package/action.js +27 -4
- package/ansi.d.ts +9 -0
- package/ansi.js +112 -4
- package/copy-transforms.d.ts +13 -0
- package/copy-transforms.js +41 -0
- package/highlight-theme.d.ts +7 -0
- package/highlight-theme.js +176 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/languages/wgsl.js +32 -6
- package/package.json +5 -1
- package/text-diff.d.ts +8 -0
- package/text-diff.js +46 -0
- package/token-ranges.d.ts +18 -0
- package/token-ranges.js +112 -0
- package/typewriter-units.d.ts +13 -0
- package/typewriter-units.js +73 -0
package/AnsiOutput.svelte
CHANGED
|
@@ -111,6 +111,8 @@
|
|
|
111
111
|
|
|
112
112
|
/** Foreground CSS, with auto-contrast override when needed. */
|
|
113
113
|
function foregroundCss(segment) {
|
|
114
|
+
// Concealed text is rendered transparent (layout and copy text stay).
|
|
115
|
+
if (segment.conceal) return "transparent";
|
|
114
116
|
if (autoContrast && segment.bg) {
|
|
115
117
|
const bg = colorToRgb(segment.bg);
|
|
116
118
|
const fg = segment.fg
|
|
@@ -129,6 +131,7 @@
|
|
|
129
131
|
if (segment.dim) names.push("dim");
|
|
130
132
|
if (segment.italic) names.push("italic");
|
|
131
133
|
if (segment.underline) names.push("underline");
|
|
134
|
+
if (segment.strikethrough) names.push("strikethrough");
|
|
132
135
|
return names.length ? names.join(" ") : undefined;
|
|
133
136
|
}
|
|
134
137
|
|
|
@@ -147,13 +150,16 @@
|
|
|
147
150
|
text: segment.text,
|
|
148
151
|
class: classNames(segment),
|
|
149
152
|
style: inlineStyle(segment),
|
|
153
|
+
link: segment.link,
|
|
150
154
|
}));
|
|
151
155
|
</script>
|
|
152
156
|
|
|
153
157
|
<pre class="ansi" {...$$restProps}><code
|
|
154
|
-
>{#each segments as segment}<
|
|
158
|
+
>{#each segments as segment}{#if segment.link}<a href={segment.link} rel="noopener noreferrer" class={segment.class} style={segment.style}
|
|
159
|
+
>{segment.text}</a
|
|
160
|
+
>{:else}<span class={segment.class} style={segment.style}
|
|
155
161
|
>{segment.text}</span
|
|
156
|
-
>{/each}</code
|
|
162
|
+
>{/if}{/each}</code
|
|
157
163
|
></pre>
|
|
158
164
|
|
|
159
165
|
<style>
|
|
@@ -187,7 +193,20 @@
|
|
|
187
193
|
font-style: italic;
|
|
188
194
|
}
|
|
189
195
|
|
|
190
|
-
.
|
|
196
|
+
.ansi a {
|
|
197
|
+
color: inherit;
|
|
198
|
+
text-decoration: none;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.ansi .underline {
|
|
191
202
|
text-decoration: underline;
|
|
192
203
|
}
|
|
204
|
+
|
|
205
|
+
.ansi .strikethrough {
|
|
206
|
+
text-decoration: line-through;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.ansi .underline.strikethrough {
|
|
210
|
+
text-decoration: underline line-through;
|
|
211
|
+
}
|
|
193
212
|
</style>
|
package/CopyButton.svelte
CHANGED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export let copy = (code) => navigator.clipboard.writeText(code);
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Transform `code` before it is passed to `copy`. Defaults to identity.
|
|
13
|
+
* The transformed string is what `on:copy` reports in `detail.code`.
|
|
14
|
+
* @type {(code: string) => string}
|
|
15
|
+
*/
|
|
16
|
+
export let transform = (code) => code;
|
|
17
|
+
|
|
11
18
|
/** @type {number} */
|
|
12
19
|
export let timeout = 2_000;
|
|
13
20
|
|
|
@@ -36,9 +43,10 @@
|
|
|
36
43
|
|
|
37
44
|
try {
|
|
38
45
|
copying = true;
|
|
39
|
-
|
|
46
|
+
const transformed = transform(code);
|
|
47
|
+
await copy(transformed);
|
|
40
48
|
copied = true;
|
|
41
|
-
dispatch("copy", { code });
|
|
49
|
+
dispatch("copy", { code: transformed });
|
|
42
50
|
timeoutId = setTimeout(() => {
|
|
43
51
|
copied = false;
|
|
44
52
|
}, timeout);
|
package/CopyButton.svelte.d.ts
CHANGED
|
@@ -13,6 +13,13 @@ export type CopyButtonProps = HTMLButtonAttributes & {
|
|
|
13
13
|
*/
|
|
14
14
|
copy?: (code: string) => void | Promise<void>;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Transform `code` before it is passed to `copy`. Defaults to identity.
|
|
18
|
+
* The transformed string is what `on:copy` reports in `detail.code`.
|
|
19
|
+
* @default (code) => code
|
|
20
|
+
*/
|
|
21
|
+
transform?: (code: string) => string;
|
|
22
|
+
|
|
16
23
|
/**
|
|
17
24
|
* How long the "copied" state lasts (ms).
|
|
18
25
|
* @default 2000
|
|
@@ -91,7 +98,7 @@ export type CopyButtonProps = HTMLButtonAttributes & {
|
|
|
91
98
|
export type CopyButtonEvents = {
|
|
92
99
|
copy: CustomEvent<{
|
|
93
100
|
/**
|
|
94
|
-
* The code that was copied.
|
|
101
|
+
* The code that was copied, after `transform` is applied.
|
|
95
102
|
*/
|
|
96
103
|
code: string;
|
|
97
104
|
}>;
|
package/Highlight.svelte
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|
$: {
|
|
25
25
|
hljs.registerLanguage(language.name, language.register);
|
|
26
|
-
|
|
26
|
+
const source = typeof code === "string" ? code : String(code ?? "");
|
|
27
|
+
highlighted = hljs.highlight(source, { language: language.name }).value;
|
|
27
28
|
}
|
|
28
29
|
</script>
|
|
29
30
|
|