@shikijs/twoslash 1.6.1 → 1.6.3
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 +7 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.mjs +52 -0
- package/package.json +3 -3
- package/style-rich.css +9 -1
package/dist/core.d.mts
CHANGED
|
@@ -139,6 +139,13 @@ interface RendererRichOptions {
|
|
|
139
139
|
* By default it pass-through the markdown.
|
|
140
140
|
*/
|
|
141
141
|
renderMarkdownInline?: (this: ShikiTransformerContextCommon, markdown: string, context: string) => ElementContent[];
|
|
142
|
+
/**
|
|
143
|
+
* The way query should be rendered.
|
|
144
|
+
* - `'popup'`: Render the query in the absolute popup
|
|
145
|
+
* - `'line'`: Render the query line after the line of code
|
|
146
|
+
* @default 'popup'
|
|
147
|
+
*/
|
|
148
|
+
queryRendering?: 'popup' | 'line';
|
|
142
149
|
/**
|
|
143
150
|
* Extensions for the genreated HAST tree.
|
|
144
151
|
*/
|
package/dist/core.d.ts
CHANGED
|
@@ -139,6 +139,13 @@ interface RendererRichOptions {
|
|
|
139
139
|
* By default it pass-through the markdown.
|
|
140
140
|
*/
|
|
141
141
|
renderMarkdownInline?: (this: ShikiTransformerContextCommon, markdown: string, context: string) => ElementContent[];
|
|
142
|
+
/**
|
|
143
|
+
* The way query should be rendered.
|
|
144
|
+
* - `'popup'`: Render the query in the absolute popup
|
|
145
|
+
* - `'line'`: Render the query line after the line of code
|
|
146
|
+
* @default 'popup'
|
|
147
|
+
*/
|
|
148
|
+
queryRendering?: 'popup' | 'line';
|
|
142
149
|
/**
|
|
143
150
|
* Extensions for the genreated HAST tree.
|
|
144
151
|
*/
|
package/dist/core.mjs
CHANGED
|
@@ -404,6 +404,7 @@ function rendererRich(options = {}) {
|
|
|
404
404
|
classExtra = "",
|
|
405
405
|
jsdoc = true,
|
|
406
406
|
errorRendering = "line",
|
|
407
|
+
queryRendering = "popup",
|
|
407
408
|
renderMarkdown = renderMarkdownPassThrough,
|
|
408
409
|
renderMarkdownInline = renderMarkdownPassThrough,
|
|
409
410
|
hast
|
|
@@ -529,6 +530,21 @@ function rendererRich(options = {}) {
|
|
|
529
530
|
if (!query.text)
|
|
530
531
|
return {};
|
|
531
532
|
const themedContent = highlightPopupContent.call(this, query);
|
|
533
|
+
if (queryRendering !== "popup") {
|
|
534
|
+
return extend(
|
|
535
|
+
hast?.queryToken,
|
|
536
|
+
{
|
|
537
|
+
type: "element",
|
|
538
|
+
tagName: "span",
|
|
539
|
+
properties: {
|
|
540
|
+
class: "twoslash-hover"
|
|
541
|
+
},
|
|
542
|
+
children: [
|
|
543
|
+
node
|
|
544
|
+
]
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
}
|
|
532
548
|
const popup = extend(
|
|
533
549
|
hast?.queryPopup,
|
|
534
550
|
{
|
|
@@ -715,6 +731,42 @@ function rendererRich(options = {}) {
|
|
|
715
731
|
)
|
|
716
732
|
];
|
|
717
733
|
},
|
|
734
|
+
lineQuery(query, node) {
|
|
735
|
+
if (queryRendering !== "line")
|
|
736
|
+
return [];
|
|
737
|
+
const themedContent = highlightPopupContent.call(this, query);
|
|
738
|
+
const targetNode = node?.type === "element" ? node.children[0] : void 0;
|
|
739
|
+
const targetText = targetNode?.type === "text" ? targetNode.value : "";
|
|
740
|
+
const offset = Math.max(0, (query.character || 0) + Math.floor(targetText.length / 2) - 2);
|
|
741
|
+
return [
|
|
742
|
+
{
|
|
743
|
+
type: "element",
|
|
744
|
+
tagName: "div",
|
|
745
|
+
properties: {
|
|
746
|
+
class: ["twoslash-meta-line twoslash-query-line", classExtra].filter(Boolean).join(" ")
|
|
747
|
+
},
|
|
748
|
+
children: [
|
|
749
|
+
{ type: "text", value: " ".repeat(offset) },
|
|
750
|
+
{
|
|
751
|
+
type: "element",
|
|
752
|
+
tagName: "span",
|
|
753
|
+
properties: {
|
|
754
|
+
class: ["twoslash-popup-container", classExtra].filter(Boolean).join(" ")
|
|
755
|
+
},
|
|
756
|
+
children: [
|
|
757
|
+
{
|
|
758
|
+
type: "element",
|
|
759
|
+
tagName: "div",
|
|
760
|
+
properties: { class: "twoslash-popup-arrow" },
|
|
761
|
+
children: []
|
|
762
|
+
},
|
|
763
|
+
...themedContent
|
|
764
|
+
]
|
|
765
|
+
}
|
|
766
|
+
]
|
|
767
|
+
}
|
|
768
|
+
];
|
|
769
|
+
},
|
|
718
770
|
lineError(error) {
|
|
719
771
|
if (errorRendering !== "line")
|
|
720
772
|
return [];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/twoslash",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.3",
|
|
5
5
|
"description": "Shiki transformer for twoslash",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"twoslash": "^0.2.6",
|
|
53
|
-
"@shikijs/core": "1.6.
|
|
53
|
+
"@shikijs/core": "1.6.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@iconify-json/carbon": "^1.1.
|
|
56
|
+
"@iconify-json/carbon": "^1.1.35",
|
|
57
57
|
"@iconify-json/codicon": "^1.1.49",
|
|
58
58
|
"@shikijs/twoslash": "^3.1.2",
|
|
59
59
|
"hast-util-from-html": "^2.0.1",
|
package/style-rich.css
CHANGED
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
|
|
71
71
|
.twoslash .twoslash-hover:hover .twoslash-popup-container,
|
|
72
72
|
.twoslash .twoslash-error-hover:hover .twoslash-popup-container,
|
|
73
|
-
.twoslash .twoslash-query-presisted .twoslash-popup-container
|
|
73
|
+
.twoslash .twoslash-query-presisted .twoslash-popup-container,
|
|
74
|
+
.twoslash .twoslash-query-line .twoslash-popup-container {
|
|
74
75
|
opacity: 1;
|
|
75
76
|
pointer-events: auto;
|
|
76
77
|
}
|
|
@@ -132,6 +133,13 @@
|
|
|
132
133
|
font-family: var(--twoslash-code-font);
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
/* ===== Query Line ===== */
|
|
137
|
+
.twoslash .twoslash-query-line .twoslash-popup-container {
|
|
138
|
+
position: relative;
|
|
139
|
+
margin-bottom: 1.4em;
|
|
140
|
+
transform: translateY(0.6em);
|
|
141
|
+
}
|
|
142
|
+
|
|
135
143
|
/* ===== Error Line ===== */
|
|
136
144
|
.twoslash .twoslash-error-line {
|
|
137
145
|
position: relative;
|