@shikijs/twoslash 1.0.0-beta.2 → 1.0.0-beta.4
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/dist/core.d.mts +5 -1
- package/dist/core.d.ts +5 -1
- package/dist/core.mjs +19 -18
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/style-rich.css +5 -5
package/dist/core.d.mts
CHANGED
|
@@ -218,6 +218,10 @@ declare function defaultHoverInfoProcessor(type: string): string;
|
|
|
218
218
|
*/
|
|
219
219
|
declare function rendererClassic(): TwoslashRenderer;
|
|
220
220
|
|
|
221
|
+
declare class ShikiTwoslashError extends Error {
|
|
222
|
+
constructor(message: string);
|
|
223
|
+
}
|
|
224
|
+
|
|
221
225
|
/**
|
|
222
226
|
* This file is the core of the @shikijs/twoslash package,
|
|
223
227
|
* Decoupled from twoslash's implementation and allowing to introduce custom implementation or cache system.
|
|
@@ -227,4 +231,4 @@ declare function defaultTwoslashOptions(): TwoslashExecuteOptions;
|
|
|
227
231
|
type TwoslashFunction = (code: string, lang?: string, options?: TwoslashExecuteOptions) => TwoslashReturn;
|
|
228
232
|
declare function createTransformerFactory(defaultTwoslasher: TwoslashFunction, defaultRenderer?: TwoslashRenderer): (options?: TransformerTwoslashOptions) => ShikiTransformer;
|
|
229
233
|
|
|
230
|
-
export { type CompletionItem, type HastExtension, type RendererRichOptions, type TransformerTwoslashOptions, type TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich };
|
|
234
|
+
export { type CompletionItem, type HastExtension, type RendererRichOptions, ShikiTwoslashError, type TransformerTwoslashOptions, type TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich };
|
package/dist/core.d.ts
CHANGED
|
@@ -218,6 +218,10 @@ declare function defaultHoverInfoProcessor(type: string): string;
|
|
|
218
218
|
*/
|
|
219
219
|
declare function rendererClassic(): TwoslashRenderer;
|
|
220
220
|
|
|
221
|
+
declare class ShikiTwoslashError extends Error {
|
|
222
|
+
constructor(message: string);
|
|
223
|
+
}
|
|
224
|
+
|
|
221
225
|
/**
|
|
222
226
|
* This file is the core of the @shikijs/twoslash package,
|
|
223
227
|
* Decoupled from twoslash's implementation and allowing to introduce custom implementation or cache system.
|
|
@@ -227,4 +231,4 @@ declare function defaultTwoslashOptions(): TwoslashExecuteOptions;
|
|
|
227
231
|
type TwoslashFunction = (code: string, lang?: string, options?: TwoslashExecuteOptions) => TwoslashReturn;
|
|
228
232
|
declare function createTransformerFactory(defaultTwoslasher: TwoslashFunction, defaultRenderer?: TwoslashRenderer): (options?: TransformerTwoslashOptions) => ShikiTransformer;
|
|
229
233
|
|
|
230
|
-
export { type CompletionItem, type HastExtension, type RendererRichOptions, type TransformerTwoslashOptions, type TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich };
|
|
234
|
+
export { type CompletionItem, type HastExtension, type RendererRichOptions, ShikiTwoslashError, type TransformerTwoslashOptions, type TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich };
|
package/dist/core.mjs
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { splitTokens } from '@shikijs/core';
|
|
2
|
+
|
|
3
|
+
class ShikiTwoslashError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "ShikiTwoslashError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
2
9
|
|
|
3
10
|
const module = {
|
|
4
11
|
type: "element",
|
|
@@ -549,7 +556,7 @@ function rendererRich(options = {}) {
|
|
|
549
556
|
},
|
|
550
557
|
nodeCompletion(query, node) {
|
|
551
558
|
if (node.type !== "text")
|
|
552
|
-
throw new
|
|
559
|
+
throw new ShikiTwoslashError(`Renderer hook nodeCompletion only works on text nodes, got ${node.type}`);
|
|
553
560
|
const items = query.completions.map((i) => ({
|
|
554
561
|
type: "element",
|
|
555
562
|
tagName: "li",
|
|
@@ -920,7 +927,7 @@ function createTransformerFactory(defaultTwoslasher, defaultRenderer) {
|
|
|
920
927
|
throws = true
|
|
921
928
|
} = options;
|
|
922
929
|
if (!renderer)
|
|
923
|
-
throw new
|
|
930
|
+
throw new ShikiTwoslashError("Missing renderer");
|
|
924
931
|
const filter = options.filter || ((lang, _, options2) => langs.includes(lang) && (!explicitTrigger || /\btwoslash\b/.test(options2.meta?.__raw || "")));
|
|
925
932
|
return {
|
|
926
933
|
preprocess(code) {
|
|
@@ -928,7 +935,6 @@ function createTransformerFactory(defaultTwoslasher, defaultRenderer) {
|
|
|
928
935
|
if (lang in langAlias)
|
|
929
936
|
lang = langAlias[this.options.lang];
|
|
930
937
|
if (filter(lang, code, this.options)) {
|
|
931
|
-
this.options.mergeWhitespaces = "never";
|
|
932
938
|
const twoslash = twoslasher(code, lang, twoslashOptions);
|
|
933
939
|
this.meta.twoslash = twoslash;
|
|
934
940
|
this.options.lang = twoslash.meta.extension || lang;
|
|
@@ -938,17 +944,12 @@ function createTransformerFactory(defaultTwoslasher, defaultRenderer) {
|
|
|
938
944
|
tokens(tokens) {
|
|
939
945
|
if (!this.meta.twoslash)
|
|
940
946
|
return;
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
if (!breakpointsInToken.length)
|
|
948
|
-
return token;
|
|
949
|
-
return splitToken(token, breakpointsInToken);
|
|
950
|
-
});
|
|
951
|
-
});
|
|
947
|
+
return splitTokens(
|
|
948
|
+
tokens,
|
|
949
|
+
this.meta.twoslash.nodes.flatMap(
|
|
950
|
+
(i) => ["hover", "error", "query", "highlight", "completion"].includes(i.type) ? [i.start, i.start + i.length] : []
|
|
951
|
+
)
|
|
952
|
+
);
|
|
952
953
|
},
|
|
953
954
|
pre(pre) {
|
|
954
955
|
if (this.meta.twoslash)
|
|
@@ -969,7 +970,7 @@ function createTransformerFactory(defaultTwoslasher, defaultRenderer) {
|
|
|
969
970
|
index = codeEl.children.indexOf(lineEl);
|
|
970
971
|
if (index === -1) {
|
|
971
972
|
if (throws)
|
|
972
|
-
throw new
|
|
973
|
+
throw new ShikiTwoslashError(`Cannot find line ${line} in code element`);
|
|
973
974
|
return;
|
|
974
975
|
}
|
|
975
976
|
}
|
|
@@ -1082,7 +1083,7 @@ function createTransformerFactory(defaultTwoslasher, defaultRenderer) {
|
|
|
1082
1083
|
}
|
|
1083
1084
|
default: {
|
|
1084
1085
|
if (throws)
|
|
1085
|
-
throw new
|
|
1086
|
+
throw new ShikiTwoslashError(`Unknown node type: ${node.type}`);
|
|
1086
1087
|
}
|
|
1087
1088
|
}
|
|
1088
1089
|
}
|
|
@@ -1098,4 +1099,4 @@ function getTokenString(token) {
|
|
|
1098
1099
|
return token.children?.map(getTokenString).join("") || "";
|
|
1099
1100
|
}
|
|
1100
1101
|
|
|
1101
|
-
export { createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich };
|
|
1102
|
+
export { ShikiTwoslashError, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _shikijs_core_dist_chunk_tokens_mjs from '@shikijs/core/dist/chunk-tokens.mjs';
|
|
2
2
|
import { CreateTwoslashOptions } from 'twoslash';
|
|
3
3
|
import { TransformerTwoslashOptions, RendererRichOptions } from './core.mjs';
|
|
4
|
-
export { CompletionItem, HastExtension, TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich } from './core.mjs';
|
|
4
|
+
export { CompletionItem, HastExtension, ShikiTwoslashError, TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich } from './core.mjs';
|
|
5
5
|
import '@shikijs/core';
|
|
6
6
|
import 'hast';
|
|
7
7
|
|
|
@@ -16,6 +16,6 @@ interface TransformerTwoslashIndexOptions extends TransformerTwoslashOptions, Pi
|
|
|
16
16
|
/**
|
|
17
17
|
* Factory function to create a Shiki transformer for twoslash integrations.
|
|
18
18
|
*/
|
|
19
|
-
declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions):
|
|
19
|
+
declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions): _shikijs_core_dist_chunk_tokens_mjs.y;
|
|
20
20
|
|
|
21
21
|
export { RendererRichOptions, type TransformerTwoslashIndexOptions, TransformerTwoslashOptions, transformerTwoslash };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _shikijs_core_dist_chunk_tokens_mjs from '@shikijs/core/dist/chunk-tokens.mjs';
|
|
2
2
|
import { CreateTwoslashOptions } from 'twoslash';
|
|
3
3
|
import { TransformerTwoslashOptions, RendererRichOptions } from './core.js';
|
|
4
|
-
export { CompletionItem, HastExtension, TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich } from './core.js';
|
|
4
|
+
export { CompletionItem, HastExtension, ShikiTwoslashError, TwoslashRenderer, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich } from './core.js';
|
|
5
5
|
import '@shikijs/core';
|
|
6
6
|
import 'hast';
|
|
7
7
|
|
|
@@ -16,6 +16,6 @@ interface TransformerTwoslashIndexOptions extends TransformerTwoslashOptions, Pi
|
|
|
16
16
|
/**
|
|
17
17
|
* Factory function to create a Shiki transformer for twoslash integrations.
|
|
18
18
|
*/
|
|
19
|
-
declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions):
|
|
19
|
+
declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions): _shikijs_core_dist_chunk_tokens_mjs.y;
|
|
20
20
|
|
|
21
21
|
export { RendererRichOptions, type TransformerTwoslashIndexOptions, TransformerTwoslashOptions, transformerTwoslash };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createTwoslasher } from 'twoslash';
|
|
2
2
|
import { createTransformerFactory, rendererRich } from './core.mjs';
|
|
3
|
-
export { defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic } from './core.mjs';
|
|
3
|
+
export { ShikiTwoslashError, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic } from './core.mjs';
|
|
4
4
|
import '@shikijs/core';
|
|
5
5
|
|
|
6
6
|
function transformerTwoslash(options = {}) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/twoslash",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.4",
|
|
5
5
|
"description": "Shiki transformer for twoslash",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"twoslash": "^0.1.0",
|
|
53
|
-
"@shikijs/core": "1.0.0-beta.
|
|
53
|
+
"@shikijs/core": "1.0.0-beta.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@iconify-json/carbon": "^1.1.28",
|
package/style-rich.css
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
--twoslash-popup-shadow: rgba(0, 0, 0.08) 0px 1px 4px;
|
|
10
10
|
--twoslash-docs-color: #888;
|
|
11
11
|
--twoslash-docs-font: sans-serif;
|
|
12
|
-
--
|
|
13
|
-
--
|
|
12
|
+
--twoslash-code-font: inherit;
|
|
13
|
+
--twoslash-code-font-size: 1em;
|
|
14
14
|
--twoslash-matched-color: inherit;
|
|
15
15
|
--twoslash-unmatched-color: #888;
|
|
16
16
|
--twoslash-cursor-color: #8888;
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
.twoslash .twoslash-popup-code {
|
|
98
|
-
font-family: var(--
|
|
99
|
-
font-size: var(--
|
|
98
|
+
font-family: var(--twoslash-code-font);
|
|
99
|
+
font-size: var(--twoslash-code-font-size);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
.twoslash .twoslash-popup-docs {
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
.twoslash .twoslash-popup-docs-tag-name {
|
|
121
|
-
font-family: var(--
|
|
121
|
+
font-family: var(--twoslash-code-font);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/* ===== Error Line ===== */
|