svelte-highlight 7.14.0 → 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/FileTabs.svelte +2 -1
- package/Highlight.svelte +26 -15
- package/HighlightAuto.svelte +25 -20
- 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 +24 -15
- package/LineNumbers.svelte +4 -2
- package/README.md +119 -3
- package/Typewriter.svelte +111 -58
- package/action.js +29 -3
- 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 +8 -0
- package/index.js +8 -0
- package/languages/astro.js +6 -0
- package/languages/hcl.js +4 -4
- package/languages/hlsl.js +6 -2
- package/languages/jq.js +2 -2
- package/languages/just.js +1 -1
- package/languages/kql.js +1 -0
- package/languages/rescript.js +3 -2
- package/languages/solidity.js +1 -1
- package/languages/svelte.js +6 -5
- package/languages/wgsl.js +32 -6
- package/languages/zig.js +2 -2
- package/package.json +19 -3
- package/split-lines.d.ts +6 -0
- package/split-lines.js +50 -0
- 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/core.js +0 -22
- package/highlighter.svelte.js +0 -22
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a highlight.js theme's `.hljs-<scope>` class rules into
|
|
3
|
+
* `::highlight(hljs-<scope>)` rules for the CSS Custom Highlight API, used
|
|
4
|
+
* by the `HighlightEditable` "css-highlights" engine.
|
|
5
|
+
*
|
|
6
|
+
* `::highlight()` only supports `color`/`background-color` across browsers
|
|
7
|
+
* (no `text-decoration`/`text-shadow` everywhere), so every other
|
|
8
|
+
* declaration is dropped. Compound (`.hljs-title.class_`) and descendant
|
|
9
|
+
* (`.hljs-meta .hljs-keyword`) selectors have no `::highlight()` equivalent
|
|
10
|
+
* and are dropped too; only single-class `.hljs-<scope>` selectors convert.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const STYLE_TAG = /^(\s*<style>)([\s\S]*?)(<\/style>\s*)$/;
|
|
14
|
+
const SIMPLE_SCOPE_SELECTOR = /^\.hljs-([\w-]+)$/;
|
|
15
|
+
const SUPPORTED_PROPERTIES = new Set(["color", "background-color"]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} css
|
|
19
|
+
* @param {number} start
|
|
20
|
+
*/
|
|
21
|
+
function findStringEnd(css, start) {
|
|
22
|
+
const quote = css[start];
|
|
23
|
+
let i = start + 1;
|
|
24
|
+
while (i < css.length) {
|
|
25
|
+
const ch = css[i];
|
|
26
|
+
if (ch === "\\") {
|
|
27
|
+
i += 2;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (ch === quote) return i + 1;
|
|
31
|
+
i += 1;
|
|
32
|
+
}
|
|
33
|
+
return css.length;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Index after the `}` that closes the block starting at `start`.
|
|
38
|
+
* @param {string} css
|
|
39
|
+
* @param {number} start
|
|
40
|
+
*/
|
|
41
|
+
function findBlockEnd(css, start) {
|
|
42
|
+
let depth = 1;
|
|
43
|
+
let i = start;
|
|
44
|
+
while (i < css.length) {
|
|
45
|
+
const ch = css[i];
|
|
46
|
+
if (ch === "/" && css[i + 1] === "*") {
|
|
47
|
+
const end = css.indexOf("*/", i + 2);
|
|
48
|
+
i = end === -1 ? css.length : end + 2;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (ch === '"' || ch === "'") {
|
|
52
|
+
i = findStringEnd(css, i);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (ch === "{") {
|
|
56
|
+
depth += 1;
|
|
57
|
+
} else if (ch === "}") {
|
|
58
|
+
depth -= 1;
|
|
59
|
+
if (depth === 0) return i;
|
|
60
|
+
}
|
|
61
|
+
i += 1;
|
|
62
|
+
}
|
|
63
|
+
return css.length;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Split on `delim`, skipping nested strings and comments.
|
|
68
|
+
* @param {string} str
|
|
69
|
+
* @param {string} delim
|
|
70
|
+
*/
|
|
71
|
+
function splitTopLevel(str, delim) {
|
|
72
|
+
const parts = [];
|
|
73
|
+
let current = "";
|
|
74
|
+
let i = 0;
|
|
75
|
+
while (i < str.length) {
|
|
76
|
+
const ch = str[i];
|
|
77
|
+
if (ch === "/" && str[i + 1] === "*") {
|
|
78
|
+
const end = str.indexOf("*/", i + 2);
|
|
79
|
+
const stop = end === -1 ? str.length : end + 2;
|
|
80
|
+
current += str.slice(i, stop);
|
|
81
|
+
i = stop;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (ch === '"' || ch === "'") {
|
|
85
|
+
const stop = findStringEnd(str, i);
|
|
86
|
+
current += str.slice(i, stop);
|
|
87
|
+
i = stop;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (ch === delim) {
|
|
91
|
+
parts.push(current);
|
|
92
|
+
current = "";
|
|
93
|
+
} else {
|
|
94
|
+
current += ch;
|
|
95
|
+
}
|
|
96
|
+
i += 1;
|
|
97
|
+
}
|
|
98
|
+
parts.push(current);
|
|
99
|
+
return parts;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @param {string} body */
|
|
103
|
+
function colorDeclarations(body) {
|
|
104
|
+
return splitTopLevel(body, ";")
|
|
105
|
+
.map((declaration) => {
|
|
106
|
+
const colon = declaration.indexOf(":");
|
|
107
|
+
if (colon === -1) return null;
|
|
108
|
+
const prop = declaration.slice(0, colon).trim().toLowerCase();
|
|
109
|
+
const value = declaration.slice(colon + 1).trim();
|
|
110
|
+
return value && SUPPORTED_PROPERTIES.has(prop) ? { prop, value } : null;
|
|
111
|
+
})
|
|
112
|
+
.filter((declaration) => declaration !== null);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {string} prelude Selector list preceding a rule's `{`.
|
|
117
|
+
* @param {string} body Declarations between the matching `{` and `}`.
|
|
118
|
+
*/
|
|
119
|
+
function highlightRulesFor(prelude, body) {
|
|
120
|
+
const declarations = colorDeclarations(body);
|
|
121
|
+
if (declarations.length === 0) return "";
|
|
122
|
+
const decl = declarations
|
|
123
|
+
.map(({ prop, value }) => `${prop}:${value}`)
|
|
124
|
+
.join(";");
|
|
125
|
+
|
|
126
|
+
return splitTopLevel(prelude, ",")
|
|
127
|
+
.map((selector) => SIMPLE_SCOPE_SELECTOR.exec(selector.trim()))
|
|
128
|
+
.filter((match) => match !== null)
|
|
129
|
+
.map((match) => `::highlight(hljs-${match[1]}){${decl}}`)
|
|
130
|
+
.join("");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {string} theme Theme CSS (optionally `<style>`-wrapped).
|
|
135
|
+
* @returns {string} Converted `::highlight()` rules, concatenated.
|
|
136
|
+
*/
|
|
137
|
+
export function highlightRules(theme) {
|
|
138
|
+
const match = STYLE_TAG.exec(theme);
|
|
139
|
+
const css = match ? (match[2] ?? "") : theme;
|
|
140
|
+
|
|
141
|
+
let out = "";
|
|
142
|
+
let prelude = "";
|
|
143
|
+
let i = 0;
|
|
144
|
+
while (i < css.length) {
|
|
145
|
+
const ch = css[i];
|
|
146
|
+
if (ch === "/" && css[i + 1] === "*") {
|
|
147
|
+
const end = css.indexOf("*/", i + 2);
|
|
148
|
+
i = end === -1 ? css.length : end + 2;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (ch === '"' || ch === "'") {
|
|
152
|
+
const stop = findStringEnd(css, i);
|
|
153
|
+
prelude += css.slice(i, stop);
|
|
154
|
+
i = stop;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (ch === "{") {
|
|
158
|
+
const bodyEnd = findBlockEnd(css, i + 1);
|
|
159
|
+
if (!prelude.trim().startsWith("@")) {
|
|
160
|
+
out += highlightRulesFor(prelude, css.slice(i + 1, bodyEnd));
|
|
161
|
+
}
|
|
162
|
+
prelude = "";
|
|
163
|
+
i = bodyEnd + 1;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (ch === ";") {
|
|
167
|
+
// Blockless at-rule (@import, etc.): nothing to convert.
|
|
168
|
+
prelude = "";
|
|
169
|
+
i += 1;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
prelude += ch;
|
|
173
|
+
i += 1;
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -5,13 +5,21 @@ export type { AnsiColor, AnsiSegment, AnsiStyle } from "./ansi";
|
|
|
5
5
|
export { parseAnsi } from "./ansi";
|
|
6
6
|
export { default as CodeWindow } from "./CodeWindow.svelte";
|
|
7
7
|
export { default as CopyButton } from "./CopyButton.svelte";
|
|
8
|
+
export { stripDiffMarkers, stripPrompts } from "./copy-transforms";
|
|
8
9
|
export { default as FileTabs } from "./FileTabs.svelte";
|
|
9
10
|
export { default as Highlight, default } from "./Highlight.svelte";
|
|
10
11
|
export { default as HighlightAuto } from "./HighlightAuto.svelte";
|
|
11
12
|
export { default as HighlightEditable } from "./HighlightEditable.svelte";
|
|
13
|
+
export { default as HighlightStream } from "./HighlightStream.svelte";
|
|
12
14
|
export { default as HighlightStyle } from "./HighlightStyle.svelte";
|
|
13
15
|
export { default as HighlightSvelte } from "./HighlightSvelte.svelte";
|
|
14
16
|
export { default as LineNumbers } from "./LineNumbers.svelte";
|
|
15
17
|
export type { LanguageName, LanguageType } from "./languages";
|
|
16
18
|
export { loadLanguage } from "./load-language";
|
|
19
|
+
export {
|
|
20
|
+
dualStyle,
|
|
21
|
+
scopeClassFor,
|
|
22
|
+
scopeSelectors,
|
|
23
|
+
scopeStyle,
|
|
24
|
+
} from "./scoped";
|
|
17
25
|
export { default as Typewriter } from "./Typewriter.svelte";
|
package/index.js
CHANGED
|
@@ -3,12 +3,20 @@ export { highlight } from "./action.js";
|
|
|
3
3
|
export { parseAnsi } from "./ansi.js";
|
|
4
4
|
export { default as CodeWindow } from "./CodeWindow.svelte";
|
|
5
5
|
export { default as CopyButton } from "./CopyButton.svelte";
|
|
6
|
+
export { stripDiffMarkers, stripPrompts } from "./copy-transforms.js";
|
|
6
7
|
export { default as FileTabs } from "./FileTabs.svelte";
|
|
7
8
|
export { default, default as Highlight } from "./Highlight.svelte";
|
|
8
9
|
export { default as HighlightAuto } from "./HighlightAuto.svelte";
|
|
9
10
|
export { default as HighlightEditable } from "./HighlightEditable.svelte";
|
|
11
|
+
export { default as HighlightStream } from "./HighlightStream.svelte";
|
|
10
12
|
export { default as HighlightStyle } from "./HighlightStyle.svelte";
|
|
11
13
|
export { default as HighlightSvelte } from "./HighlightSvelte.svelte";
|
|
12
14
|
export { default as LineNumbers } from "./LineNumbers.svelte";
|
|
13
15
|
export { loadLanguage } from "./load-language.js";
|
|
16
|
+
export {
|
|
17
|
+
dualStyle,
|
|
18
|
+
scopeClassFor,
|
|
19
|
+
scopeSelectors,
|
|
20
|
+
scopeStyle,
|
|
21
|
+
} from "./scoped.js";
|
|
14
22
|
export { default as Typewriter } from "./Typewriter.svelte";
|
package/languages/astro.js
CHANGED
|
@@ -16,6 +16,12 @@ function defineAstro(hljs) {
|
|
|
16
16
|
excludeBegin: true,
|
|
17
17
|
excludeEnd: true,
|
|
18
18
|
relevance: 100,
|
|
19
|
+
/** @type {import("highlight.js").ModeCallback} */
|
|
20
|
+
"on:begin": (match, response) => {
|
|
21
|
+
if (match.index !== 0) {
|
|
22
|
+
response.ignoreMatch();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
19
25
|
},
|
|
20
26
|
{
|
|
21
27
|
begin: /^---\s*$/m,
|
package/languages/hcl.js
CHANGED
|
@@ -35,13 +35,13 @@ function defineHcl(hljs) {
|
|
|
35
35
|
contains: [hljs.BACKSLASH_ESCAPE, INTERPOLATION],
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const HEREDOC = {
|
|
38
|
+
const HEREDOC = hljs.END_SAME_AS_BEGIN({
|
|
39
39
|
className: "string",
|
|
40
|
-
begin: /<<-?\s*(
|
|
41
|
-
end: /^\s
|
|
40
|
+
begin: /<<-?\s*(\w+)\s*\n/,
|
|
41
|
+
end: /^\s*(\w+)\s*$/,
|
|
42
42
|
contains: [INTERPOLATION],
|
|
43
43
|
relevance: 10,
|
|
44
|
-
};
|
|
44
|
+
});
|
|
45
45
|
|
|
46
46
|
return {
|
|
47
47
|
name: "HCL",
|
package/languages/hlsl.js
CHANGED
|
@@ -52,8 +52,12 @@ function defineHlsl(hljs) {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
const ATTRIBUTE = {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// A leading word character or `]` means this is array indexing (e.g.
|
|
56
|
+
// `arr[i]`, `buf[0][process(x)]`) rather than an HLSL attribute, so the
|
|
57
|
+
// guard character is matched in its own group and left unscoped
|
|
58
|
+
// instead of excluded with a negative lookbehind.
|
|
59
|
+
begin: [/(?:^|[^\w\]])/, /\[[a-zA-Z_]\w*(?:\([^)]*\))\]/],
|
|
60
|
+
beginScope: { 2: "meta" },
|
|
57
61
|
relevance: 0,
|
|
58
62
|
};
|
|
59
63
|
|
package/languages/jq.js
CHANGED
package/languages/just.js
CHANGED
package/languages/kql.js
CHANGED
package/languages/rescript.js
CHANGED
|
@@ -90,8 +90,9 @@ function defineReScript(hljs) {
|
|
|
90
90
|
// `</` unambiguously starts a JSX closing tag. A bare `<` immediately
|
|
91
91
|
// preceded by a word character (e.g. `array<int>`, `option<string>`,
|
|
92
92
|
// `text<div>`) is generic-type application syntax instead, so that case
|
|
93
|
-
// is excluded with
|
|
94
|
-
|
|
93
|
+
// is excluded with `\B`, which only holds when the preceding character
|
|
94
|
+
// has the same word-ness as `<` (i.e. is not a word character).
|
|
95
|
+
begin: /<\/(?=[A-Za-z])|\B<(?=[A-Za-z])/,
|
|
95
96
|
end: /\/?>/,
|
|
96
97
|
relevance: 0,
|
|
97
98
|
contains: [
|
package/languages/solidity.js
CHANGED
|
@@ -13,7 +13,7 @@ const SOLIDITY_LITERALS =
|
|
|
13
13
|
|
|
14
14
|
const SOLIDITY_BUILT_INS =
|
|
15
15
|
"msg block tx abi require assert keccak256 sha256 ripemd160 ecrecover " +
|
|
16
|
-
"addmod
|
|
16
|
+
"addmod mulmod gasleft blockhash now";
|
|
17
17
|
|
|
18
18
|
const SOLIDITY_TYPE = {
|
|
19
19
|
className: "type",
|
package/languages/svelte.js
CHANGED
|
@@ -2,28 +2,29 @@ import typescriptRegister from "highlight.js/lib/languages/typescript";
|
|
|
2
2
|
import html from "./html.js";
|
|
3
3
|
|
|
4
4
|
const RUNE_NAMES = "state|derived|effect|props|bindable|inspect|host";
|
|
5
|
-
const RUNE_SUFFIXES =
|
|
5
|
+
const RUNE_SUFFIXES =
|
|
6
|
+
"raw|snapshot|by|eager|pre|tracking|pending|root|id|trace";
|
|
6
7
|
const SVELTE_DIRECTIVES =
|
|
7
8
|
"on|bind|use|transition|in|out|animate|class|style|let";
|
|
8
9
|
const TS_LANG = "(?:ts|typescript)";
|
|
9
10
|
const SCRIPT_TS_BEGIN = new RegExp(
|
|
10
11
|
String.raw`<script(?=[^>]*\slang=["']${TS_LANG}["'])[^>]*>`,
|
|
11
|
-
"
|
|
12
|
+
"m",
|
|
12
13
|
);
|
|
13
14
|
const SCRIPT_JS_MODULE_BEGIN = new RegExp(
|
|
14
15
|
String.raw`<script(?=[^>]*(?:\scontext=["']module["']|\smodule\b))(?![^>]*\slang=["']${TS_LANG}["'])[^>]*>`,
|
|
15
|
-
"
|
|
16
|
+
"m",
|
|
16
17
|
);
|
|
17
18
|
const SCRIPT_JS_BEGIN = new RegExp(
|
|
18
19
|
String.raw`<script(?![^>]*\slang=["']${TS_LANG}["'])[^>]*>`,
|
|
19
|
-
"
|
|
20
|
+
"m",
|
|
20
21
|
);
|
|
21
22
|
|
|
22
23
|
/** @param {import("highlight.js").HLJSApi} hljs */
|
|
23
24
|
function defineSvelte(hljs) {
|
|
24
25
|
const runePattern = {
|
|
25
26
|
begin: new RegExp(
|
|
26
|
-
String.raw`\$(?:${RUNE_NAMES})(?:\.(?:${RUNE_SUFFIXES}))?(?=\s|\(|,|;|\)|\}
|
|
27
|
+
String.raw`\$(?:${RUNE_NAMES})(?:\.(?:${RUNE_SUFFIXES}))?(?=\s|\(|,|;|\)|\}|<|$)`,
|
|
27
28
|
),
|
|
28
29
|
className: "keyword",
|
|
29
30
|
relevance: 10,
|
package/languages/wgsl.js
CHANGED
|
@@ -2,12 +2,18 @@ const WGSL_KEYWORDS =
|
|
|
2
2
|
"alias break case const const_assert continue continuing default diagnostic discard else enable fn for if let loop override requires return struct switch var while";
|
|
3
3
|
|
|
4
4
|
const WGSL_TYPES =
|
|
5
|
-
"bool f16 f32 i32 u32 vec2 vec3 vec4 mat2x2 mat2x3 mat2x4 mat3x2 mat3x3 mat3x4 mat4x2 mat4x3 mat4x4 array atomic ptr sampler sampler_comparison texture_1d texture_2d texture_2d_array texture_3d texture_cube texture_cube_array texture_multisampled_2d texture_storage_1d texture_storage_2d texture_storage_2d_array texture_storage_3d texture_depth_2d texture_depth_2d_array texture_depth_cube texture_depth_cube_array texture_depth_multisampled_2d";
|
|
5
|
+
"bool f16 f32 i32 u32 vec2 vec3 vec4 vec2f vec3f vec4f vec2h vec3h vec4h vec2i vec3i vec4i vec2u vec3u vec4u mat2x2 mat2x3 mat2x4 mat3x2 mat3x3 mat3x4 mat4x2 mat4x3 mat4x4 mat2x2f mat2x3f mat2x4f mat3x2f mat3x3f mat3x4f mat4x2f mat4x3f mat4x4f mat2x2h mat2x3h mat2x4h mat3x2h mat3x3h mat3x4h mat4x2h mat4x3h mat4x4h array atomic ptr sampler sampler_comparison texture_1d texture_2d texture_2d_array texture_3d texture_cube texture_cube_array texture_multisampled_2d texture_storage_1d texture_storage_2d texture_storage_2d_array texture_storage_3d texture_depth_2d texture_depth_2d_array texture_depth_cube texture_depth_cube_array texture_depth_multisampled_2d";
|
|
6
6
|
|
|
7
7
|
const WGSL_LITERALS = "true false";
|
|
8
8
|
|
|
9
9
|
const WGSL_BUILTINS =
|
|
10
|
-
"vertex_index instance_index position frag_depth sample_index sample_mask local_invocation_id global_invocation_id workgroup_id num_workgroups front_facing";
|
|
10
|
+
"vertex_index instance_index position frag_depth sample_index sample_mask local_invocation_id local_invocation_index global_invocation_id workgroup_id num_workgroups front_facing subgroup_invocation_id subgroup_size";
|
|
11
|
+
|
|
12
|
+
const WGSL_ADDRESS_SPACE_KEYWORDS =
|
|
13
|
+
"storage uniform workgroup private function handle read write read_write";
|
|
14
|
+
|
|
15
|
+
const WGSL_BUILTIN_FUNCTIONS =
|
|
16
|
+
"all any select arrayLength abs acos acosh asin asinh atan atanh atan2 ceil clamp cos cosh countLeadingZeros countOneBits countTrailingZeros cross degrees determinant distance dot dot4U8Packed dot4I8Packed exp exp2 extractBits faceForward firstLeadingBit firstTrailingBit floor fma fract frexp insertBits inverseSqrt ldexp length log log2 max min mix modf normalize pow quantizeToF16 radians reflect refract reverseBits round saturate sign sin sinh smoothstep sqrt step tan tanh transpose trunc dpdx dpdxCoarse dpdxFine dpdy dpdyCoarse dpdyFine fwidth fwidthCoarse fwidthFine textureDimensions textureGather textureGatherCompare textureLoad textureNumLayers textureNumLevels textureNumSamples textureSample textureSampleBias textureSampleCompare textureSampleCompareLevel textureSampleGrad textureSampleLevel textureSampleBaseClampToEdge textureStore atomicLoad atomicStore atomicAdd atomicSub atomicMax atomicMin atomicAnd atomicOr atomicXor atomicExchange atomicCompareExchangeWeak pack4x8snorm pack4x8unorm pack4xI8 pack4xU8 pack4xI8Clamp pack4xU8Clamp pack2x16snorm pack2x16unorm pack2x16float unpack4x8snorm unpack4x8unorm unpack4xI8 unpack4xU8 unpack2x16snorm unpack2x16unorm unpack2x16float storageBarrier textureBarrier workgroupBarrier workgroupUniformLoad subgroupAdd subgroupExclusiveAdd subgroupInclusiveAdd subgroupAll subgroupAnd subgroupAny subgroupBallot subgroupBroadcast subgroupBroadcastFirst subgroupElect subgroupMax subgroupMin subgroupMul subgroupExclusiveMul subgroupInclusiveMul subgroupOr subgroupShuffle subgroupShuffleDown subgroupShuffleUp subgroupShuffleXor subgroupXor quadBroadcast quadSwapDiagonal quadSwapX quadSwapY bitcast";
|
|
11
17
|
|
|
12
18
|
/** @param {import("highlight.js").HLJSApi} hljs */
|
|
13
19
|
function defineWgsl(hljs) {
|
|
@@ -32,13 +38,31 @@ function defineWgsl(hljs) {
|
|
|
32
38
|
beginScope: { 1: "keyword", 3: "title.function" },
|
|
33
39
|
};
|
|
34
40
|
|
|
41
|
+
const BUILTIN_FUNCTION_CALL = {
|
|
42
|
+
className: "built_in",
|
|
43
|
+
begin: new RegExp(
|
|
44
|
+
`\\b(?:${WGSL_BUILTIN_FUNCTIONS.split(" ").join("|")})(?=\\s*\\()`,
|
|
45
|
+
),
|
|
46
|
+
relevance: 0,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const ADDRESS_SPACE_KEYWORDS = {
|
|
50
|
+
keyword: WGSL_ADDRESS_SPACE_KEYWORDS,
|
|
51
|
+
type: WGSL_TYPES,
|
|
52
|
+
};
|
|
53
|
+
|
|
35
54
|
const VAR_ADDRESS_SPACE = {
|
|
36
|
-
begin: [/\bvar/, /\s*</],
|
|
55
|
+
begin: [/\bvar\b/, /\s*</],
|
|
37
56
|
beginScope: { 1: "keyword" },
|
|
38
57
|
end: />/,
|
|
39
|
-
keywords:
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
keywords: ADDRESS_SPACE_KEYWORDS,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const PTR_ADDRESS_SPACE = {
|
|
62
|
+
begin: [/\bptr\b/, /\s*</],
|
|
63
|
+
beginScope: { 1: "type" },
|
|
64
|
+
end: />/,
|
|
65
|
+
keywords: ADDRESS_SPACE_KEYWORDS,
|
|
42
66
|
};
|
|
43
67
|
|
|
44
68
|
return {
|
|
@@ -55,7 +79,9 @@ function defineWgsl(hljs) {
|
|
|
55
79
|
hljs.C_BLOCK_COMMENT_MODE,
|
|
56
80
|
ATTRIBUTE,
|
|
57
81
|
VAR_ADDRESS_SPACE,
|
|
82
|
+
PTR_ADDRESS_SPACE,
|
|
58
83
|
FUNCTION,
|
|
84
|
+
BUILTIN_FUNCTION_CALL,
|
|
59
85
|
NUMBER,
|
|
60
86
|
],
|
|
61
87
|
};
|
package/languages/zig.js
CHANGED
|
@@ -4,12 +4,12 @@ const ZIG_KEYWORDS =
|
|
|
4
4
|
"error test and or orelse unreachable async await suspend resume " +
|
|
5
5
|
"nosuspend export extern packed align allowzero volatile linksection " +
|
|
6
6
|
"threadlocal usingnamespace asm anytype noalias callconv opaque " +
|
|
7
|
-
"anyframe
|
|
7
|
+
"anyframe";
|
|
8
8
|
|
|
9
9
|
const ZIG_LITERALS = "true false null undefined";
|
|
10
10
|
|
|
11
11
|
const ZIG_TYPES =
|
|
12
|
-
"bool void type anyerror anytype noreturn comptime_int comptime_float " +
|
|
12
|
+
"bool void type anyerror anytype anyopaque noreturn comptime_int comptime_float " +
|
|
13
13
|
"isize usize c_char c_short c_ushort c_int c_uint c_long c_ulong " +
|
|
14
14
|
"c_longlong c_ulonglong c_longdouble f16 f32 f64 f80 f128";
|
|
15
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-highlight",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.15.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Svelte component library for highlighting code using highlight.js",
|
|
6
6
|
"author": "Eric Liu (https://github.com/metonym)",
|
|
@@ -65,12 +65,28 @@
|
|
|
65
65
|
"types": "./languages/*.d.ts",
|
|
66
66
|
"import": "./languages/*.js"
|
|
67
67
|
},
|
|
68
|
+
"./ansi": {
|
|
69
|
+
"types": "./ansi.d.ts",
|
|
70
|
+
"default": "./ansi.js"
|
|
71
|
+
},
|
|
72
|
+
"./copy-transforms": {
|
|
73
|
+
"types": "./copy-transforms.d.ts",
|
|
74
|
+
"default": "./copy-transforms.js"
|
|
75
|
+
},
|
|
76
|
+
"./load-language": {
|
|
77
|
+
"types": "./load-language.d.ts",
|
|
78
|
+
"default": "./load-language.js"
|
|
79
|
+
},
|
|
80
|
+
"./scoped": {
|
|
81
|
+
"types": "./scoped.d.ts",
|
|
82
|
+
"default": "./scoped.js"
|
|
83
|
+
},
|
|
68
84
|
"./package.json": "./package.json"
|
|
69
85
|
},
|
|
70
86
|
"svelte": "./index.js",
|
|
71
87
|
"types": "./index.d.ts",
|
|
72
88
|
"sideEffects": [
|
|
73
|
-
"
|
|
74
|
-
"
|
|
89
|
+
"styles/*.css",
|
|
90
|
+
"langtag.css"
|
|
75
91
|
]
|
|
76
92
|
}
|
package/split-lines.d.ts
ADDED
package/split-lines.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits highlight.js output HTML into lines without corrupting `<span>`
|
|
3
|
+
* elements that wrap a line break (block comments, template literals).
|
|
4
|
+
* Open spans are closed at the end of a line and the same stack is
|
|
5
|
+
* reopened, in order, at the start of the next line -- the strategy
|
|
6
|
+
* Prism and Shiki use for line-level transforms.
|
|
7
|
+
* @param {string} html
|
|
8
|
+
* @returns {string[]}
|
|
9
|
+
*/
|
|
10
|
+
export function splitLines(html) {
|
|
11
|
+
const lines = [];
|
|
12
|
+
/** @type {string[]} */
|
|
13
|
+
const stack = [];
|
|
14
|
+
let current = "";
|
|
15
|
+
let i = 0;
|
|
16
|
+
|
|
17
|
+
while (i < html.length) {
|
|
18
|
+
const char = html[i];
|
|
19
|
+
|
|
20
|
+
if (char === "<") {
|
|
21
|
+
const tagEnd = html.indexOf(">", i);
|
|
22
|
+
const tag = html.slice(i, tagEnd + 1);
|
|
23
|
+
|
|
24
|
+
if (tag.startsWith("</span")) {
|
|
25
|
+
stack.pop();
|
|
26
|
+
} else if (tag.startsWith("<span")) {
|
|
27
|
+
stack.push(tag);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
current += tag;
|
|
31
|
+
i = tagEnd + 1;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (char === "\n") {
|
|
36
|
+
current += "</span>".repeat(stack.length);
|
|
37
|
+
lines.push(current);
|
|
38
|
+
current = stack.join("");
|
|
39
|
+
i++;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
current += char;
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
lines.push(current);
|
|
48
|
+
|
|
49
|
+
return lines;
|
|
50
|
+
}
|
package/text-diff.d.ts
ADDED
package/text-diff.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const HIGH_SURROGATE_MIN = 0xd800;
|
|
2
|
+
const HIGH_SURROGATE_MAX = 0xdbff;
|
|
3
|
+
const LOW_SURROGATE_MIN = 0xdc00;
|
|
4
|
+
const LOW_SURROGATE_MAX = 0xdfff;
|
|
5
|
+
|
|
6
|
+
/** @param {number} code */
|
|
7
|
+
function isHighSurrogate(code) {
|
|
8
|
+
return code >= HIGH_SURROGATE_MIN && code <= HIGH_SURROGATE_MAX;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** @param {number} code */
|
|
12
|
+
function isLowSurrogate(code) {
|
|
13
|
+
return code >= LOW_SURROGATE_MIN && code <= LOW_SURROGATE_MAX;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Diffs two strings down to a common-prefix/suffix trim. Trims on Unicode
|
|
18
|
+
* code points (never splitting a surrogate pair between the shared prefix
|
|
19
|
+
* or suffix and the changed middle).
|
|
20
|
+
* @param {string} before
|
|
21
|
+
* @param {string} after
|
|
22
|
+
* @returns {{ start: number; removed: string; inserted: string }}
|
|
23
|
+
*/
|
|
24
|
+
export function diffText(before, after) {
|
|
25
|
+
const minLength = Math.min(before.length, after.length);
|
|
26
|
+
|
|
27
|
+
let prefix = 0;
|
|
28
|
+
while (prefix < minLength && before[prefix] === after[prefix]) prefix++;
|
|
29
|
+
if (isHighSurrogate(before.charCodeAt(prefix - 1))) prefix--;
|
|
30
|
+
|
|
31
|
+
let suffix = 0;
|
|
32
|
+
const maxSuffix = minLength - prefix;
|
|
33
|
+
while (
|
|
34
|
+
suffix < maxSuffix &&
|
|
35
|
+
before[before.length - 1 - suffix] === after[after.length - 1 - suffix]
|
|
36
|
+
) {
|
|
37
|
+
suffix++;
|
|
38
|
+
}
|
|
39
|
+
if (isLowSurrogate(before.charCodeAt(before.length - suffix))) suffix--;
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
start: prefix,
|
|
43
|
+
removed: before.slice(prefix, before.length - suffix),
|
|
44
|
+
inserted: after.slice(prefix, after.length - suffix),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface TokenRange {
|
|
2
|
+
/** Character offset into `code` where the token starts. */
|
|
3
|
+
start: number;
|
|
4
|
+
/** Character offset into `code` where the token ends. */
|
|
5
|
+
end: number;
|
|
6
|
+
/**
|
|
7
|
+
* hljs scope name (e.g. `"keyword"`, `"title.function"`), as passed to
|
|
8
|
+
* `startScope`. Dotted/tiered names are kept as-is, not split into
|
|
9
|
+
* multiple classes.
|
|
10
|
+
*/
|
|
11
|
+
scope: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Tokenize `code` into flat, non-overlapping scope ranges instead of HTML.
|
|
16
|
+
* `languageName` must already be registered with hljs.
|
|
17
|
+
*/
|
|
18
|
+
export function tokenize(code: string, languageName: string): TokenRange[];
|