svelte-highlight 7.12.0 → 7.13.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 +193 -0
- package/AnsiOutput.svelte.d.ts +112 -0
- package/CodeWindow.svelte +110 -0
- package/CodeWindow.svelte.d.ts +136 -0
- package/CopyButton.svelte +2 -5
- package/CopyButton.svelte.d.ts +16 -20
- package/FileTabs.svelte +161 -0
- package/FileTabs.svelte.d.ts +96 -0
- package/Highlight.svelte.d.ts +9 -10
- package/HighlightAuto.svelte.d.ts +2 -2
- package/HighlightEditable.svelte +385 -0
- package/HighlightEditable.svelte.d.ts +113 -0
- package/HighlightStyle.svelte +21 -6
- package/HighlightStyle.svelte.d.ts +22 -1
- package/HighlightSvelte.svelte.d.ts +1 -1
- package/LangTag.svelte.d.ts +3 -3
- package/LineNumbers.svelte.d.ts +10 -10
- package/README.md +567 -0
- package/Typewriter.svelte +238 -0
- package/Typewriter.svelte.d.ts +65 -0
- package/action.d.ts +20 -0
- package/action.js +25 -0
- package/ansi.d.ts +36 -0
- package/ansi.js +198 -0
- package/index.d.ts +10 -0
- package/index.js +8 -0
- package/load-language.d.ts +9 -0
- package/load-language.js +15 -0
- package/package.json +1 -1
- package/scoped.d.ts +12 -0
- package/scoped.js +55 -24
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {string} */
|
|
3
|
+
export let text;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Flip foreground to black/white when contrast on a background span is too low.
|
|
7
|
+
* @type {boolean}
|
|
8
|
+
*/
|
|
9
|
+
export let autoContrast = true;
|
|
10
|
+
|
|
11
|
+
import { parseAnsi } from "./ansi.js";
|
|
12
|
+
|
|
13
|
+
// Default foreground and minimum WCAG contrast ratio against backgrounds.
|
|
14
|
+
const FOREGROUND_FALLBACK = "#d4d4d4";
|
|
15
|
+
const CONTRAST_TARGET = 4.5;
|
|
16
|
+
/** @type {[number, number, number]} */
|
|
17
|
+
const BLACK = [0, 0, 0];
|
|
18
|
+
/** @type {[number, number, number]} */
|
|
19
|
+
const WHITE = [255, 255, 255];
|
|
20
|
+
|
|
21
|
+
// 16-color xterm defaults, each overridable via `--ansi-<name>`.
|
|
22
|
+
const DEFAULTS = {
|
|
23
|
+
black: "#000000",
|
|
24
|
+
red: "#cd0000",
|
|
25
|
+
green: "#00cd00",
|
|
26
|
+
yellow: "#cdcd00",
|
|
27
|
+
blue: "#0000ee",
|
|
28
|
+
magenta: "#cd00cd",
|
|
29
|
+
cyan: "#00cdcd",
|
|
30
|
+
white: "#e5e5e5",
|
|
31
|
+
"bright-black": "#7f7f7f",
|
|
32
|
+
"bright-red": "#ff0000",
|
|
33
|
+
"bright-green": "#00ff00",
|
|
34
|
+
"bright-yellow": "#ffff00",
|
|
35
|
+
"bright-blue": "#5c5cff",
|
|
36
|
+
"bright-magenta": "#ff00ff",
|
|
37
|
+
"bright-cyan": "#00ffff",
|
|
38
|
+
"bright-white": "#ffffff",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// 256-color cube steps (6×6×6).
|
|
42
|
+
const CUBE = [0, 95, 135, 175, 215, 255];
|
|
43
|
+
|
|
44
|
+
/** 256-color index → hex. */
|
|
45
|
+
function indexedHex(index) {
|
|
46
|
+
if (index >= 232) {
|
|
47
|
+
const value = (index - 232) * 10 + 8;
|
|
48
|
+
const hex = value.toString(16).padStart(2, "0");
|
|
49
|
+
return `#${hex}${hex}${hex}`;
|
|
50
|
+
}
|
|
51
|
+
const n = index - 16;
|
|
52
|
+
const r = CUBE[Math.floor(n / 36) % 6];
|
|
53
|
+
const g = CUBE[Math.floor(n / 6) % 6];
|
|
54
|
+
const b = CUBE[n % 6];
|
|
55
|
+
return `#${[r, g, b].map((c) => c.toString(16).padStart(2, "0")).join("")}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Parsed color → CSS (named colors use `--ansi-*` vars). */
|
|
59
|
+
function cssColor(color) {
|
|
60
|
+
if ("name" in color) {
|
|
61
|
+
return `var(--ansi-${color.name}, ${DEFAULTS[color.name]})`;
|
|
62
|
+
}
|
|
63
|
+
if ("rgb" in color) {
|
|
64
|
+
return `rgb(${color.rgb[0]}, ${color.rgb[1]}, ${color.rgb[2]})`;
|
|
65
|
+
}
|
|
66
|
+
return indexedHex(color.index);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {string} hex A `#rrggbb` string.
|
|
71
|
+
* @returns {[number, number, number]}
|
|
72
|
+
*/
|
|
73
|
+
function hexToRgb(hex) {
|
|
74
|
+
const value = hex.replace("#", "");
|
|
75
|
+
return [
|
|
76
|
+
Number.parseInt(value.slice(0, 2), 16),
|
|
77
|
+
Number.parseInt(value.slice(2, 4), 16),
|
|
78
|
+
Number.parseInt(value.slice(4, 6), 16),
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Named colors use the default palette (theme overrides aren't known here). */
|
|
83
|
+
function colorToRgb(color) {
|
|
84
|
+
if ("name" in color) return hexToRgb(DEFAULTS[color.name] ?? "#000000");
|
|
85
|
+
if ("rgb" in color) return color.rgb;
|
|
86
|
+
return hexToRgb(indexedHex(color.index));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** WCAG relative luminance. */
|
|
90
|
+
function luminance([r, g, b]) {
|
|
91
|
+
const channels = [r, g, b].map((c) => {
|
|
92
|
+
const v = c / 255;
|
|
93
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
94
|
+
});
|
|
95
|
+
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** WCAG contrast ratio. */
|
|
99
|
+
function contrastRatio(a, b) {
|
|
100
|
+
const la = luminance(a);
|
|
101
|
+
const lb = luminance(b);
|
|
102
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Black or white, whichever contrasts more with `bg`. */
|
|
106
|
+
function readableForeground(bg) {
|
|
107
|
+
return contrastRatio(BLACK, bg) >= contrastRatio(WHITE, bg)
|
|
108
|
+
? "#000000"
|
|
109
|
+
: "#ffffff";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Foreground CSS, with auto-contrast override when needed. */
|
|
113
|
+
function foregroundCss(segment) {
|
|
114
|
+
if (autoContrast && segment.bg) {
|
|
115
|
+
const bg = colorToRgb(segment.bg);
|
|
116
|
+
const fg = segment.fg
|
|
117
|
+
? colorToRgb(segment.fg)
|
|
118
|
+
: hexToRgb(FOREGROUND_FALLBACK);
|
|
119
|
+
if (contrastRatio(fg, bg) < CONTRAST_TARGET)
|
|
120
|
+
return readableForeground(bg);
|
|
121
|
+
}
|
|
122
|
+
return segment.fg ? cssColor(segment.fg) : undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @param {import("./ansi").AnsiSegment} segment */
|
|
126
|
+
function classNames(segment) {
|
|
127
|
+
const names = [];
|
|
128
|
+
if (segment.bold) names.push("bold");
|
|
129
|
+
if (segment.dim) names.push("dim");
|
|
130
|
+
if (segment.italic) names.push("italic");
|
|
131
|
+
if (segment.underline) names.push("underline");
|
|
132
|
+
return names.length ? names.join(" ") : undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @param {import("./ansi").AnsiSegment} segment */
|
|
136
|
+
function inlineStyle(segment) {
|
|
137
|
+
let style = "";
|
|
138
|
+
if (segment.bg) style += `background-color:${cssColor(segment.bg)};`;
|
|
139
|
+
const fg = foregroundCss(segment);
|
|
140
|
+
if (fg) style += `color:${fg};`;
|
|
141
|
+
return style || undefined;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Precompute class/style per segment. Parse only when `text` changes.
|
|
145
|
+
$: parsed = parseAnsi(text);
|
|
146
|
+
$: segments = parsed.map((segment) => ({
|
|
147
|
+
text: segment.text,
|
|
148
|
+
class: classNames(segment),
|
|
149
|
+
style: inlineStyle(segment),
|
|
150
|
+
}));
|
|
151
|
+
</script>
|
|
152
|
+
|
|
153
|
+
<pre class="ansi" {...$$restProps}><code
|
|
154
|
+
>{#each segments as segment}<span class={segment.class} style={segment.style}
|
|
155
|
+
>{segment.text}</span
|
|
156
|
+
>{/each}</code
|
|
157
|
+
></pre>
|
|
158
|
+
|
|
159
|
+
<style>
|
|
160
|
+
.ansi {
|
|
161
|
+
margin: 0;
|
|
162
|
+
overflow: auto;
|
|
163
|
+
padding: var(--ansi-padding, 1em);
|
|
164
|
+
background: var(--ansi-background, #1e1e1e);
|
|
165
|
+
color: var(--ansi-foreground, #d4d4d4);
|
|
166
|
+
font-family: var(
|
|
167
|
+
--ansi-font-family,
|
|
168
|
+
ui-monospace,
|
|
169
|
+
"SFMono-Regular",
|
|
170
|
+
"Menlo",
|
|
171
|
+
monospace
|
|
172
|
+
);
|
|
173
|
+
font-size: var(--ansi-font-size, 0.875em);
|
|
174
|
+
line-height: var(--ansi-line-height, 1.5);
|
|
175
|
+
tab-size: var(--ansi-tab-size, 4);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.bold {
|
|
179
|
+
font-weight: var(--ansi-bold-weight, 700);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.dim {
|
|
183
|
+
opacity: var(--ansi-dim-opacity, 0.5);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.italic {
|
|
187
|
+
font-style: italic;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.underline {
|
|
191
|
+
text-decoration: underline;
|
|
192
|
+
}
|
|
193
|
+
</style>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
|
|
4
|
+
export type AnsiOutputProps = HTMLAttributes<HTMLPreElement> & {
|
|
5
|
+
/**
|
|
6
|
+
* Terminal output, including ANSI SGR codes.
|
|
7
|
+
*/
|
|
8
|
+
text: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Flip foreground to black/white when contrast on a background is too low.
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
autoContrast?: boolean;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Output block padding.
|
|
18
|
+
* @default "1em"
|
|
19
|
+
*/
|
|
20
|
+
"--ansi-padding"?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Output block background.
|
|
24
|
+
* @default "#1e1e1e"
|
|
25
|
+
*/
|
|
26
|
+
"--ansi-background"?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Default text color.
|
|
30
|
+
* @default "#d4d4d4"
|
|
31
|
+
*/
|
|
32
|
+
"--ansi-foreground"?: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Monospace font family.
|
|
36
|
+
* @default "ui-monospace, SFMono-Regular, Menlo, monospace"
|
|
37
|
+
*/
|
|
38
|
+
"--ansi-font-family"?: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Font size.
|
|
42
|
+
* @default "0.875em"
|
|
43
|
+
*/
|
|
44
|
+
"--ansi-font-size"?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Line height.
|
|
48
|
+
* @default 1.5
|
|
49
|
+
*/
|
|
50
|
+
"--ansi-line-height"?: string | number;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Tab size.
|
|
54
|
+
* @default 4
|
|
55
|
+
*/
|
|
56
|
+
"--ansi-tab-size"?: string | number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Bold font weight.
|
|
60
|
+
* @default 700
|
|
61
|
+
*/
|
|
62
|
+
"--ansi-bold-weight"?: string | number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Dim opacity.
|
|
66
|
+
* @default 0.5
|
|
67
|
+
*/
|
|
68
|
+
"--ansi-dim-opacity"?: string | number;
|
|
69
|
+
|
|
70
|
+
/** Standard black. @default "#000000" */
|
|
71
|
+
"--ansi-black"?: string;
|
|
72
|
+
/** Standard red. @default "#cd0000" */
|
|
73
|
+
"--ansi-red"?: string;
|
|
74
|
+
/** Standard green. @default "#00cd00" */
|
|
75
|
+
"--ansi-green"?: string;
|
|
76
|
+
/** Standard yellow. @default "#cdcd00" */
|
|
77
|
+
"--ansi-yellow"?: string;
|
|
78
|
+
/** Standard blue. @default "#0000ee" */
|
|
79
|
+
"--ansi-blue"?: string;
|
|
80
|
+
/** Standard magenta. @default "#cd00cd" */
|
|
81
|
+
"--ansi-magenta"?: string;
|
|
82
|
+
/** Standard cyan. @default "#00cdcd" */
|
|
83
|
+
"--ansi-cyan"?: string;
|
|
84
|
+
/** Standard white. @default "#e5e5e5" */
|
|
85
|
+
"--ansi-white"?: string;
|
|
86
|
+
/** Bright black. @default "#7f7f7f" */
|
|
87
|
+
"--ansi-bright-black"?: string;
|
|
88
|
+
/** Bright red. @default "#ff0000" */
|
|
89
|
+
"--ansi-bright-red"?: string;
|
|
90
|
+
/** Bright green. @default "#00ff00" */
|
|
91
|
+
"--ansi-bright-green"?: string;
|
|
92
|
+
/** Bright yellow. @default "#ffff00" */
|
|
93
|
+
"--ansi-bright-yellow"?: string;
|
|
94
|
+
/** Bright blue. @default "#5c5cff" */
|
|
95
|
+
"--ansi-bright-blue"?: string;
|
|
96
|
+
/** Bright magenta. @default "#ff00ff" */
|
|
97
|
+
"--ansi-bright-magenta"?: string;
|
|
98
|
+
/** Bright cyan. @default "#00ffff" */
|
|
99
|
+
"--ansi-bright-cyan"?: string;
|
|
100
|
+
/** Bright white. @default "#ffffff" */
|
|
101
|
+
"--ansi-bright-white"?: string;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type AnsiOutputEvents = {};
|
|
105
|
+
|
|
106
|
+
export type AnsiOutputSlots = {};
|
|
107
|
+
|
|
108
|
+
export default class AnsiOutput extends SvelteComponentTyped<
|
|
109
|
+
AnsiOutputProps,
|
|
110
|
+
AnsiOutputEvents,
|
|
111
|
+
AnsiOutputSlots
|
|
112
|
+
> {}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {"macos" | "terminal" | "plain"} */
|
|
3
|
+
export let variant = "macos";
|
|
4
|
+
|
|
5
|
+
/** @type {string} */
|
|
6
|
+
export let title = "";
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div class="code-window {variant}" {...$$restProps}>
|
|
10
|
+
<div class="titlebar">
|
|
11
|
+
{#if variant === "macos"}
|
|
12
|
+
<span class="dots" aria-hidden="true">
|
|
13
|
+
<span class="dot close"></span>
|
|
14
|
+
<span class="dot minimize"></span>
|
|
15
|
+
<span class="dot maximize"></span>
|
|
16
|
+
</span>
|
|
17
|
+
{:else if variant === "terminal"}
|
|
18
|
+
<span class="prompt" aria-hidden="true">>_</span>
|
|
19
|
+
{/if}
|
|
20
|
+
|
|
21
|
+
{#if title}
|
|
22
|
+
<span class="title">{title}</span>
|
|
23
|
+
{/if}
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div class="content">
|
|
27
|
+
<slot />
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<style>
|
|
32
|
+
.code-window {
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
background: var(--window-background, #1e1e1e);
|
|
35
|
+
border: var(--window-border, 1px solid rgba(255, 255, 255, 0.1));
|
|
36
|
+
border-radius: var(--window-radius, 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.titlebar {
|
|
40
|
+
position: relative;
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
gap: var(--titlebar-gap, 0.5em);
|
|
44
|
+
padding: var(--titlebar-padding, 0.65em 1em);
|
|
45
|
+
background: var(--titlebar-background, #2d2d2d);
|
|
46
|
+
border-bottom: var(--titlebar-border, 1px solid rgba(255, 255, 255, 0.1));
|
|
47
|
+
color: var(--titlebar-color, rgba(255, 255, 255, 0.6));
|
|
48
|
+
font-family: var(
|
|
49
|
+
--titlebar-font-family,
|
|
50
|
+
system-ui,
|
|
51
|
+
-apple-system,
|
|
52
|
+
sans-serif
|
|
53
|
+
);
|
|
54
|
+
font-size: var(--titlebar-font-size, 0.8125em);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.dots {
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
gap: var(--dot-gap, 0.5em);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.dot {
|
|
64
|
+
width: var(--dot-size, 0.75em);
|
|
65
|
+
height: var(--dot-size, 0.75em);
|
|
66
|
+
border-radius: 50%;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.dot.close {
|
|
70
|
+
background: var(--dot-close, #ff5f56);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.dot.minimize {
|
|
74
|
+
background: var(--dot-minimize, #ffbd2e);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.dot.maximize {
|
|
78
|
+
background: var(--dot-maximize, #27c93f);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.prompt {
|
|
82
|
+
font-family: var(--prompt-font-family, ui-monospace, monospace);
|
|
83
|
+
font-weight: var(--prompt-font-weight, 700);
|
|
84
|
+
color: var(--prompt-color, inherit);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.title {
|
|
88
|
+
/* Center title across titlebar, ignoring dots/prompt. */
|
|
89
|
+
position: absolute;
|
|
90
|
+
left: 50%;
|
|
91
|
+
transform: translateX(-50%);
|
|
92
|
+
max-width: 70%;
|
|
93
|
+
overflow: hidden;
|
|
94
|
+
white-space: nowrap;
|
|
95
|
+
text-overflow: ellipsis;
|
|
96
|
+
pointer-events: none;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.plain .title {
|
|
100
|
+
/* Plain variant: no chrome, left-align title. */
|
|
101
|
+
position: static;
|
|
102
|
+
left: auto;
|
|
103
|
+
transform: none;
|
|
104
|
+
max-width: 100%;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.content {
|
|
108
|
+
overflow: auto;
|
|
109
|
+
}
|
|
110
|
+
</style>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
|
|
4
|
+
export type CodeWindowProps = HTMLAttributes<HTMLDivElement> & {
|
|
5
|
+
/**
|
|
6
|
+
* Window chrome style.
|
|
7
|
+
* @default "macos"
|
|
8
|
+
*/
|
|
9
|
+
variant?: "macos" | "terminal" | "plain";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Title bar text.
|
|
13
|
+
* @default ""
|
|
14
|
+
*/
|
|
15
|
+
title?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Window body background.
|
|
19
|
+
* @default "#1e1e1e"
|
|
20
|
+
*/
|
|
21
|
+
"--window-background"?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Window border.
|
|
25
|
+
* @default "1px solid rgba(255, 255, 255, 0.1)"
|
|
26
|
+
*/
|
|
27
|
+
"--window-border"?: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Window corner radius.
|
|
31
|
+
* @default "0"
|
|
32
|
+
*/
|
|
33
|
+
"--window-radius"?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Title bar gap.
|
|
37
|
+
* @default "0.5em"
|
|
38
|
+
*/
|
|
39
|
+
"--titlebar-gap"?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Title bar padding.
|
|
43
|
+
* @default "0.65em 1em"
|
|
44
|
+
*/
|
|
45
|
+
"--titlebar-padding"?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Title bar background.
|
|
49
|
+
* @default "#2d2d2d"
|
|
50
|
+
*/
|
|
51
|
+
"--titlebar-background"?: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Title bar bottom border.
|
|
55
|
+
* @default "1px solid rgba(255, 255, 255, 0.1)"
|
|
56
|
+
*/
|
|
57
|
+
"--titlebar-border"?: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Title bar text color.
|
|
61
|
+
* @default "rgba(255, 255, 255, 0.6)"
|
|
62
|
+
*/
|
|
63
|
+
"--titlebar-color"?: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Title bar font family.
|
|
67
|
+
* @default "system-ui, -apple-system, sans-serif"
|
|
68
|
+
*/
|
|
69
|
+
"--titlebar-font-family"?: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Title bar font size.
|
|
73
|
+
* @default "0.8125em"
|
|
74
|
+
*/
|
|
75
|
+
"--titlebar-font-size"?: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Traffic-light dot gap.
|
|
79
|
+
* @default "0.5em"
|
|
80
|
+
*/
|
|
81
|
+
"--dot-gap"?: string;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Traffic-light dot size.
|
|
85
|
+
* @default "0.75em"
|
|
86
|
+
*/
|
|
87
|
+
"--dot-size"?: string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Close dot color.
|
|
91
|
+
* @default "#ff5f56"
|
|
92
|
+
*/
|
|
93
|
+
"--dot-close"?: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Minimize dot color.
|
|
97
|
+
* @default "#ffbd2e"
|
|
98
|
+
*/
|
|
99
|
+
"--dot-minimize"?: string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Maximize dot color.
|
|
103
|
+
* @default "#27c93f"
|
|
104
|
+
*/
|
|
105
|
+
"--dot-maximize"?: string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Terminal prompt font family.
|
|
109
|
+
* @default "ui-monospace, monospace"
|
|
110
|
+
*/
|
|
111
|
+
"--prompt-font-family"?: string;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Terminal prompt font weight.
|
|
115
|
+
* @default 700
|
|
116
|
+
*/
|
|
117
|
+
"--prompt-font-weight"?: string | number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Terminal prompt color.
|
|
121
|
+
* @default "inherit"
|
|
122
|
+
*/
|
|
123
|
+
"--prompt-color"?: string;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type CodeWindowEvents = {};
|
|
127
|
+
|
|
128
|
+
export type CodeWindowSlots = {
|
|
129
|
+
default: {};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default class CodeWindow extends SvelteComponentTyped<
|
|
133
|
+
CodeWindowProps,
|
|
134
|
+
CodeWindowEvents,
|
|
135
|
+
CodeWindowSlots
|
|
136
|
+
> {}
|
package/CopyButton.svelte
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
export let code;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Override
|
|
7
|
-
* return a promise. When omitted, the native Clipboard API is used.
|
|
6
|
+
* Override copy behavior. Defaults to `navigator.clipboard.writeText`.
|
|
8
7
|
* @type {(code: string) => void | Promise<void>}
|
|
9
8
|
*/
|
|
10
9
|
export let copy = (code) => navigator.clipboard.writeText(code);
|
|
@@ -32,9 +31,7 @@
|
|
|
32
31
|
let timeoutId;
|
|
33
32
|
|
|
34
33
|
async function handleClick() {
|
|
35
|
-
// Ignore clicks while
|
|
36
|
-
// so no duplicate copy fires (even for slow async `copy` functions) and the
|
|
37
|
-
// "copied" icon stays visible until the timeout elapses.
|
|
34
|
+
// Ignore clicks while copying or showing "Copied".
|
|
38
35
|
if (copying || copied) return;
|
|
39
36
|
|
|
40
37
|
try {
|
package/CopyButton.svelte.d.ts
CHANGED
|
@@ -3,88 +3,86 @@ import type { HTMLButtonAttributes } from "svelte/elements";
|
|
|
3
3
|
|
|
4
4
|
export type CopyButtonProps = HTMLButtonAttributes & {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Text to copy.
|
|
7
7
|
*/
|
|
8
8
|
code: string;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* return a promise. When omitted, the native Clipboard API is used.
|
|
11
|
+
* Copy handler. Defaults to `navigator.clipboard.writeText`.
|
|
13
12
|
* @default (code) => navigator.clipboard.writeText(code)
|
|
14
13
|
*/
|
|
15
14
|
copy?: (code: string) => void | Promise<void>;
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
19
|
-
* "copied" state before reverting.
|
|
17
|
+
* How long the "copied" state lasts (ms).
|
|
20
18
|
* @default 2000
|
|
21
19
|
*/
|
|
22
20
|
timeout?: number;
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
|
-
*
|
|
23
|
+
* Copy button `aria-label`.
|
|
26
24
|
* Used as the fallback text only if the default icon slot is overridden.
|
|
27
25
|
* @default "Copy"
|
|
28
26
|
*/
|
|
29
27
|
text?: string;
|
|
30
28
|
|
|
31
29
|
/**
|
|
32
|
-
*
|
|
30
|
+
* Copied state `aria-label`.
|
|
33
31
|
* Used as the fallback text only if the default icon slot is overridden.
|
|
34
32
|
* @default "Copied!"
|
|
35
33
|
*/
|
|
36
34
|
copiedText?: string;
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
|
-
*
|
|
37
|
+
* Top offset.
|
|
40
38
|
* @default "0.5em"
|
|
41
39
|
*/
|
|
42
40
|
"--copy-top"?: string;
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
|
-
*
|
|
43
|
+
* Right offset.
|
|
46
44
|
* @default "0.5em"
|
|
47
45
|
*/
|
|
48
46
|
"--copy-right"?: string;
|
|
49
47
|
|
|
50
48
|
/**
|
|
51
|
-
*
|
|
49
|
+
* Button size.
|
|
52
50
|
* @default "2em"
|
|
53
51
|
*/
|
|
54
52
|
"--copy-size"?: string;
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
|
-
*
|
|
55
|
+
* Button padding.
|
|
58
56
|
* @default "0.5em"
|
|
59
57
|
*/
|
|
60
58
|
"--copy-padding"?: string;
|
|
61
59
|
|
|
62
60
|
/**
|
|
63
|
-
*
|
|
61
|
+
* Button background.
|
|
64
62
|
* @default "inherit"
|
|
65
63
|
*/
|
|
66
64
|
"--copy-background"?: string;
|
|
67
65
|
|
|
68
66
|
/**
|
|
69
|
-
*
|
|
67
|
+
* Button color.
|
|
70
68
|
* @default "inherit"
|
|
71
69
|
*/
|
|
72
70
|
"--copy-color"?: string;
|
|
73
71
|
|
|
74
72
|
/**
|
|
75
|
-
*
|
|
73
|
+
* Button border radius.
|
|
76
74
|
* @default "4px"
|
|
77
75
|
*/
|
|
78
76
|
"--copy-border-radius"?: string;
|
|
79
77
|
|
|
80
78
|
/**
|
|
81
|
-
*
|
|
79
|
+
* Button border.
|
|
82
80
|
* @default "none"
|
|
83
81
|
*/
|
|
84
82
|
"--copy-border"?: string;
|
|
85
83
|
|
|
86
84
|
/**
|
|
87
|
-
*
|
|
85
|
+
* Button z-index.
|
|
88
86
|
* @default 2
|
|
89
87
|
*/
|
|
90
88
|
"--copy-z-index"?: string | number;
|
|
@@ -105,8 +103,7 @@ export type CopyButtonEvents = {
|
|
|
105
103
|
}>;
|
|
106
104
|
|
|
107
105
|
/**
|
|
108
|
-
*
|
|
109
|
-
* an async copy on hover.
|
|
106
|
+
* Useful for prefetching an async copy on hover.
|
|
110
107
|
*/
|
|
111
108
|
mouseenter: MouseEvent;
|
|
112
109
|
|
|
@@ -124,8 +121,7 @@ export type CopyButtonSlots = {
|
|
|
124
121
|
copied: boolean;
|
|
125
122
|
|
|
126
123
|
/**
|
|
127
|
-
* `true` while
|
|
128
|
-
* Useful for rendering a pending state for slow copy functions.
|
|
124
|
+
* `true` while async `copy` is in flight.
|
|
129
125
|
*/
|
|
130
126
|
copying: boolean;
|
|
131
127
|
};
|