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
package/scoped.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Scope highlight.js theme CSS under a class
|
|
3
|
-
* Used by
|
|
2
|
+
* Scope highlight.js theme CSS under a class.
|
|
3
|
+
* Used by HighlightStyle and the docs styles build.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// @media, @supports, etc.: recurse into the block body.
|
|
7
7
|
const GROUP_AT_RULES = new Set([
|
|
8
8
|
"media",
|
|
9
9
|
"supports",
|
|
@@ -18,7 +18,6 @@ const AT_RULE_NAME = /^@([a-zA-Z-]+)/;
|
|
|
18
18
|
const WHITESPACE = /\s/;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Returns the index just past a string literal starting at `start`.
|
|
22
21
|
* @param {string} css
|
|
23
22
|
* @param {number} start
|
|
24
23
|
*/
|
|
@@ -38,8 +37,7 @@ function findStringEnd(css, start) {
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
|
-
*
|
|
42
|
-
* `start`, accounting for nested blocks, comments and strings.
|
|
40
|
+
* Index after the `}` that closes the block starting at `start`.
|
|
43
41
|
* @param {string} css
|
|
44
42
|
* @param {number} start
|
|
45
43
|
*/
|
|
@@ -69,8 +67,7 @@ function findBlockEnd(css, start) {
|
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
/**
|
|
72
|
-
*
|
|
73
|
-
* parentheses, brackets, strings or comments (e.g. commas in `:not(a, b)`).
|
|
70
|
+
* Split on `delim`, skipping nested `()`, `[]`, strings, and comments.
|
|
74
71
|
* @param {string} str
|
|
75
72
|
* @param {string} delim
|
|
76
73
|
*/
|
|
@@ -110,8 +107,6 @@ function splitTopLevel(str, delim) {
|
|
|
110
107
|
}
|
|
111
108
|
|
|
112
109
|
/**
|
|
113
|
-
* Splits a single selector into leading trivia (whitespace/comments), its
|
|
114
|
-
* significant core, and trailing whitespace, so a transform only sees the core.
|
|
115
110
|
* @param {string} selector
|
|
116
111
|
* @returns {[string, string, string]} `[leading, core, trailing]`
|
|
117
112
|
*/
|
|
@@ -155,7 +150,7 @@ function rewriteSelectorList(selectorList, transform) {
|
|
|
155
150
|
return splitTopLevel(selectorList, ",")
|
|
156
151
|
.map((selector) => {
|
|
157
152
|
const [leading, core, trailing] = splitTrivia(selector);
|
|
158
|
-
//
|
|
153
|
+
// Whitespace/comments only.
|
|
159
154
|
if (core === "") return selector;
|
|
160
155
|
return `${leading}${transform(core)}${trailing}`;
|
|
161
156
|
})
|
|
@@ -173,19 +168,17 @@ function rewriteBlock(prelude, body, transform) {
|
|
|
173
168
|
const match = AT_RULE_NAME.exec(trimmed);
|
|
174
169
|
const name = match?.[1]?.toLowerCase() ?? "";
|
|
175
170
|
if (GROUP_AT_RULES.has(name)) {
|
|
176
|
-
//
|
|
171
|
+
// @media etc.: scope nested rules.
|
|
177
172
|
return `${prelude}{${rewriteRules(body, transform)}}`;
|
|
178
173
|
}
|
|
179
|
-
// @keyframes, @font-face
|
|
174
|
+
// @keyframes, @font-face: leave body alone.
|
|
180
175
|
return `${prelude}{${body}}`;
|
|
181
176
|
}
|
|
182
177
|
return `${rewriteSelectorList(prelude, transform)}{${body}}`;
|
|
183
178
|
}
|
|
184
179
|
|
|
185
180
|
/**
|
|
186
|
-
*
|
|
187
|
-
* selector of every style rule while preserving comments, strings and
|
|
188
|
-
* at-rules (descending into conditional group rules like `@media`).
|
|
181
|
+
* Walk CSS rules and run `transform` on each selector.
|
|
189
182
|
* @param {string} css
|
|
190
183
|
* @param {(selector: string) => string} transform
|
|
191
184
|
*/
|
|
@@ -216,7 +209,7 @@ function rewriteRules(css, transform) {
|
|
|
216
209
|
continue;
|
|
217
210
|
}
|
|
218
211
|
if (ch === ";") {
|
|
219
|
-
//
|
|
212
|
+
// Blockless at-rule (@import): emit as-is.
|
|
220
213
|
out += prelude + ch;
|
|
221
214
|
prelude = "";
|
|
222
215
|
i += 1;
|
|
@@ -247,17 +240,55 @@ export function scopeSelectors(css, transform) {
|
|
|
247
240
|
* @returns {string}
|
|
248
241
|
*/
|
|
249
242
|
export function scopeStyle(style, scope) {
|
|
250
|
-
const
|
|
243
|
+
const body = scopedBody(style, scope);
|
|
244
|
+
const match = STYLE_TAG.exec(style);
|
|
245
|
+
return match ? `${match[1] ?? ""}${body}${match[3] ?? ""}` : body;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Scope under `.scope`, strip any `<style>` wrapper, return bare CSS.
|
|
250
|
+
* @param {string} style
|
|
251
|
+
* @param {string} scope
|
|
252
|
+
* @param {string} [prefix]
|
|
253
|
+
* @returns {string}
|
|
254
|
+
*/
|
|
255
|
+
function scopedBody(style, scope, prefix = "") {
|
|
256
|
+
const scopeSelector = prefix ? `${prefix} .${scope}` : `.${scope}`;
|
|
251
257
|
/** @type {(selector: string) => string} */
|
|
252
258
|
const transform = (selector) => `${scopeSelector} ${selector}`;
|
|
253
259
|
const match = STYLE_TAG.exec(style);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
260
|
+
const css = match ? (match[2] ?? "") : style;
|
|
261
|
+
return scopeSelectors(css, transform);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Build a combined light/dark stylesheet scoped under `.scope`.
|
|
266
|
+
*
|
|
267
|
+
* - `"auto"` wraps each theme in `@media (prefers-color-scheme: …)`.
|
|
268
|
+
* - `"light"` / `"dark"` emit only that single theme.
|
|
269
|
+
* - any other string is treated as a CSS selector that gates the dark block
|
|
270
|
+
* (light stays the default), e.g. `[data-theme="dark"]`.
|
|
271
|
+
*
|
|
272
|
+
* @param {string} light Light theme CSS (optionally `<style>`-wrapped).
|
|
273
|
+
* @param {string} dark Dark theme CSS (optionally `<style>`-wrapped).
|
|
274
|
+
* @param {string} scope Scope class name without a leading `.`.
|
|
275
|
+
* @param {string} [mode] `"auto"` | `"light"` | `"dark"` | a CSS selector.
|
|
276
|
+
* @returns {string}
|
|
277
|
+
*/
|
|
278
|
+
export function dualStyle(light, dark, scope, mode = "auto") {
|
|
279
|
+
let css;
|
|
280
|
+
if (mode === "light") {
|
|
281
|
+
css = scopedBody(light, scope);
|
|
282
|
+
} else if (mode === "dark") {
|
|
283
|
+
css = scopedBody(dark, scope);
|
|
284
|
+
} else if (mode === "auto") {
|
|
285
|
+
css =
|
|
286
|
+
`@media (prefers-color-scheme: light){${scopedBody(light, scope)}}` +
|
|
287
|
+
`@media (prefers-color-scheme: dark){${scopedBody(dark, scope)}}`;
|
|
288
|
+
} else {
|
|
289
|
+
css = scopedBody(light, scope) + scopedBody(dark, scope, mode);
|
|
259
290
|
}
|
|
260
|
-
return
|
|
291
|
+
return `<style>${css}</style>`;
|
|
261
292
|
}
|
|
262
293
|
|
|
263
294
|
/**
|