@shikijs/twoslash 1.16.2 → 1.17.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/dist/core.d.mts CHANGED
@@ -1,5 +1,5 @@
1
+ import { CodeToHastOptions, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformer } from '@shikijs/types';
1
2
  import { TwoslashReturn, TwoslashExecuteOptions, TwoslashGenericFunction, TwoslashOptions, NodeError, NodeTag, NodeQuery, NodeCompletion, NodeHover, NodeHighlight } from 'twoslash';
2
- import { CodeToHastOptions, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformer } from '@shikijs/core';
3
3
  import { ElementContent, Element, Text } from 'hast';
4
4
 
5
5
  type TwoslashShikiReturn = Pick<TwoslashReturn, 'nodes' | 'code'> & {
@@ -78,6 +78,19 @@ interface TwoslashRenderer {
78
78
  nodesHighlight?: (this: ShikiTransformerContext, highlight: NodeHighlight, nodes: ElementContent[]) => ElementContent[];
79
79
  }
80
80
 
81
+ declare class ShikiTwoslashError extends Error {
82
+ constructor(message: string);
83
+ }
84
+
85
+ type CompletionItem = NonNullable<NodeCompletion['completions']>[number];
86
+ declare const defaultCompletionIcons: Record<string, Element | undefined>;
87
+ declare const defaultCustomTagIcons: Record<string, Element | undefined>;
88
+
89
+ /**
90
+ * The default renderer aligning with the original `@shikijs/twoslash` output.
91
+ */
92
+ declare function rendererClassic(): TwoslashRenderer;
93
+
81
94
  interface RendererRichOptions {
82
95
  /**
83
96
  * Render JSDoc comments in hover popup.
@@ -259,24 +272,6 @@ declare function rendererRich(options?: RendererRichOptions): TwoslashRenderer;
259
272
  */
260
273
  declare function defaultHoverInfoProcessor(type: string): string;
261
274
 
262
- /**
263
- * The default renderer aligning with the original `@shikijs/twoslash` output.
264
- */
265
- declare function rendererClassic(): TwoslashRenderer;
266
-
267
- type CompletionItem = NonNullable<NodeCompletion['completions']>[number];
268
- declare const defaultCompletionIcons: Record<string, Element | undefined>;
269
- declare const defaultCustomTagIcons: Record<string, Element | undefined>;
270
-
271
- declare class ShikiTwoslashError extends Error {
272
- constructor(message: string);
273
- }
274
-
275
- /**
276
- * This file is the core of the @shikijs/twoslash package,
277
- * Decoupled from twoslash's implementation and allowing to introduce custom implementation or cache system.
278
- */
279
-
280
275
  declare function defaultTwoslashOptions(): TwoslashExecuteOptions;
281
276
  declare function createTransformerFactory(defaultTwoslasher: TwoslashShikiFunction | TwoslashGenericFunction, defaultRenderer?: TwoslashRenderer): (options?: TransformerTwoslashOptions) => ShikiTransformer;
282
277
 
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { CodeToHastOptions, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformer } from '@shikijs/types';
1
2
  import { TwoslashReturn, TwoslashExecuteOptions, TwoslashGenericFunction, TwoslashOptions, NodeError, NodeTag, NodeQuery, NodeCompletion, NodeHover, NodeHighlight } from 'twoslash';
2
- import { CodeToHastOptions, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformer } from '@shikijs/core';
3
3
  import { ElementContent, Element, Text } from 'hast';
4
4
 
5
5
  type TwoslashShikiReturn = Pick<TwoslashReturn, 'nodes' | 'code'> & {
@@ -78,6 +78,19 @@ interface TwoslashRenderer {
78
78
  nodesHighlight?: (this: ShikiTransformerContext, highlight: NodeHighlight, nodes: ElementContent[]) => ElementContent[];
79
79
  }
80
80
 
81
+ declare class ShikiTwoslashError extends Error {
82
+ constructor(message: string);
83
+ }
84
+
85
+ type CompletionItem = NonNullable<NodeCompletion['completions']>[number];
86
+ declare const defaultCompletionIcons: Record<string, Element | undefined>;
87
+ declare const defaultCustomTagIcons: Record<string, Element | undefined>;
88
+
89
+ /**
90
+ * The default renderer aligning with the original `@shikijs/twoslash` output.
91
+ */
92
+ declare function rendererClassic(): TwoslashRenderer;
93
+
81
94
  interface RendererRichOptions {
82
95
  /**
83
96
  * Render JSDoc comments in hover popup.
@@ -259,24 +272,6 @@ declare function rendererRich(options?: RendererRichOptions): TwoslashRenderer;
259
272
  */
260
273
  declare function defaultHoverInfoProcessor(type: string): string;
261
274
 
262
- /**
263
- * The default renderer aligning with the original `@shikijs/twoslash` output.
264
- */
265
- declare function rendererClassic(): TwoslashRenderer;
266
-
267
- type CompletionItem = NonNullable<NodeCompletion['completions']>[number];
268
- declare const defaultCompletionIcons: Record<string, Element | undefined>;
269
- declare const defaultCustomTagIcons: Record<string, Element | undefined>;
270
-
271
- declare class ShikiTwoslashError extends Error {
272
- constructor(message: string);
273
- }
274
-
275
- /**
276
- * This file is the core of the @shikijs/twoslash package,
277
- * Decoupled from twoslash's implementation and allowing to introduce custom implementation or cache system.
278
- */
279
-
280
275
  declare function defaultTwoslashOptions(): TwoslashExecuteOptions;
281
276
  declare function createTransformerFactory(defaultTwoslasher: TwoslashShikiFunction | TwoslashGenericFunction, defaultRenderer?: TwoslashRenderer): (options?: TransformerTwoslashOptions) => ShikiTransformer;
282
277
 
package/dist/core.mjs CHANGED
@@ -419,6 +419,183 @@ const tagIcons = {
419
419
  const defaultCompletionIcons = completionIcons;
420
420
  const defaultCustomTagIcons = tagIcons;
421
421
 
422
+ function rendererClassic() {
423
+ return {
424
+ nodeStaticInfo(info, node) {
425
+ return {
426
+ type: "element",
427
+ tagName: "data-lsp",
428
+ properties: {
429
+ lsp: info.text
430
+ },
431
+ children: [node]
432
+ };
433
+ },
434
+ nodeError(_, node) {
435
+ return {
436
+ type: "element",
437
+ tagName: "data-err",
438
+ properties: {},
439
+ children: [node]
440
+ };
441
+ },
442
+ lineError(error) {
443
+ return [
444
+ {
445
+ type: "element",
446
+ tagName: "div",
447
+ properties: {
448
+ class: "error"
449
+ },
450
+ children: [
451
+ {
452
+ type: "element",
453
+ tagName: "span",
454
+ properties: {},
455
+ children: [
456
+ {
457
+ type: "text",
458
+ value: error.text
459
+ }
460
+ ]
461
+ },
462
+ {
463
+ type: "element",
464
+ tagName: "span",
465
+ properties: {
466
+ class: "code"
467
+ },
468
+ children: [
469
+ {
470
+ type: "text",
471
+ value: String(error.code)
472
+ }
473
+ ]
474
+ }
475
+ ]
476
+ },
477
+ {
478
+ type: "element",
479
+ tagName: "span",
480
+ properties: {
481
+ class: "error-behind"
482
+ },
483
+ children: [
484
+ {
485
+ type: "text",
486
+ value: error.text
487
+ }
488
+ ]
489
+ }
490
+ ];
491
+ },
492
+ lineCompletion(query) {
493
+ return [
494
+ {
495
+ type: "element",
496
+ tagName: "div",
497
+ properties: { class: "meta-line" },
498
+ children: [
499
+ { type: "text", value: " ".repeat(query.character) },
500
+ {
501
+ type: "element",
502
+ tagName: "span",
503
+ properties: { class: "inline-completions" },
504
+ children: [{
505
+ type: "element",
506
+ tagName: "ul",
507
+ properties: { class: "dropdown" },
508
+ children: query.completions.filter((i) => i.name.startsWith(query.completionsPrefix || "____")).map((i) => ({
509
+ type: "element",
510
+ tagName: "li",
511
+ properties: {
512
+ class: "kindModifiers" in i && typeof i.kindModifiers === "string" && i.kindModifiers?.split(",").includes("deprecated") ? "deprecated" : void 0
513
+ },
514
+ children: [{
515
+ type: "element",
516
+ tagName: "span",
517
+ properties: {},
518
+ children: [
519
+ {
520
+ type: "element",
521
+ tagName: "span",
522
+ properties: { class: "result-found" },
523
+ children: [
524
+ {
525
+ type: "text",
526
+ value: query.completionsPrefix || ""
527
+ }
528
+ ]
529
+ },
530
+ {
531
+ type: "text",
532
+ value: i.name.slice(query.completionsPrefix?.length || 0)
533
+ }
534
+ ]
535
+ }]
536
+ }))
537
+ }]
538
+ }
539
+ ]
540
+ }
541
+ ];
542
+ },
543
+ lineQuery(query, targetNode) {
544
+ const targetText = targetNode?.type === "text" ? targetNode.value : "";
545
+ const offset = Math.max(0, (query.character || 0) + Math.floor(targetText.length / 2) - 1);
546
+ return [
547
+ {
548
+ type: "element",
549
+ tagName: "div",
550
+ properties: { class: "meta-line" },
551
+ children: [
552
+ { type: "text", value: " ".repeat(offset) },
553
+ {
554
+ type: "element",
555
+ tagName: "span",
556
+ properties: { class: "popover" },
557
+ children: [
558
+ {
559
+ type: "element",
560
+ tagName: "div",
561
+ properties: { class: "arrow" },
562
+ children: []
563
+ },
564
+ {
565
+ type: "text",
566
+ value: query.text || ""
567
+ }
568
+ ]
569
+ }
570
+ ]
571
+ }
572
+ ];
573
+ },
574
+ lineCustomTag(tag) {
575
+ return [
576
+ {
577
+ type: "element",
578
+ tagName: "div",
579
+ properties: { class: `meta-line logger ${tag.name}-log` },
580
+ children: [
581
+ {
582
+ type: "element",
583
+ tagName: "span",
584
+ properties: { class: "message" },
585
+ children: [
586
+ {
587
+ type: "text",
588
+ value: tag.text || ""
589
+ }
590
+ ]
591
+ }
592
+ ]
593
+ }
594
+ ];
595
+ }
596
+ };
597
+ }
598
+
422
599
  function extend(extension, node) {
423
600
  if (!extension)
424
601
  return node;
@@ -898,183 +1075,6 @@ function getErrorLevelClass(error) {
898
1075
  }
899
1076
  }
900
1077
 
901
- function rendererClassic() {
902
- return {
903
- nodeStaticInfo(info, node) {
904
- return {
905
- type: "element",
906
- tagName: "data-lsp",
907
- properties: {
908
- lsp: info.text
909
- },
910
- children: [node]
911
- };
912
- },
913
- nodeError(_, node) {
914
- return {
915
- type: "element",
916
- tagName: "data-err",
917
- properties: {},
918
- children: [node]
919
- };
920
- },
921
- lineError(error) {
922
- return [
923
- {
924
- type: "element",
925
- tagName: "div",
926
- properties: {
927
- class: "error"
928
- },
929
- children: [
930
- {
931
- type: "element",
932
- tagName: "span",
933
- properties: {},
934
- children: [
935
- {
936
- type: "text",
937
- value: error.text
938
- }
939
- ]
940
- },
941
- {
942
- type: "element",
943
- tagName: "span",
944
- properties: {
945
- class: "code"
946
- },
947
- children: [
948
- {
949
- type: "text",
950
- value: String(error.code)
951
- }
952
- ]
953
- }
954
- ]
955
- },
956
- {
957
- type: "element",
958
- tagName: "span",
959
- properties: {
960
- class: "error-behind"
961
- },
962
- children: [
963
- {
964
- type: "text",
965
- value: error.text
966
- }
967
- ]
968
- }
969
- ];
970
- },
971
- lineCompletion(query) {
972
- return [
973
- {
974
- type: "element",
975
- tagName: "div",
976
- properties: { class: "meta-line" },
977
- children: [
978
- { type: "text", value: " ".repeat(query.character) },
979
- {
980
- type: "element",
981
- tagName: "span",
982
- properties: { class: "inline-completions" },
983
- children: [{
984
- type: "element",
985
- tagName: "ul",
986
- properties: { class: "dropdown" },
987
- children: query.completions.filter((i) => i.name.startsWith(query.completionsPrefix || "____")).map((i) => ({
988
- type: "element",
989
- tagName: "li",
990
- properties: {
991
- class: "kindModifiers" in i && typeof i.kindModifiers === "string" && i.kindModifiers?.split(",").includes("deprecated") ? "deprecated" : void 0
992
- },
993
- children: [{
994
- type: "element",
995
- tagName: "span",
996
- properties: {},
997
- children: [
998
- {
999
- type: "element",
1000
- tagName: "span",
1001
- properties: { class: "result-found" },
1002
- children: [
1003
- {
1004
- type: "text",
1005
- value: query.completionsPrefix || ""
1006
- }
1007
- ]
1008
- },
1009
- {
1010
- type: "text",
1011
- value: i.name.slice(query.completionsPrefix?.length || 0)
1012
- }
1013
- ]
1014
- }]
1015
- }))
1016
- }]
1017
- }
1018
- ]
1019
- }
1020
- ];
1021
- },
1022
- lineQuery(query, targetNode) {
1023
- const targetText = targetNode?.type === "text" ? targetNode.value : "";
1024
- const offset = Math.max(0, (query.character || 0) + Math.floor(targetText.length / 2) - 1);
1025
- return [
1026
- {
1027
- type: "element",
1028
- tagName: "div",
1029
- properties: { class: "meta-line" },
1030
- children: [
1031
- { type: "text", value: " ".repeat(offset) },
1032
- {
1033
- type: "element",
1034
- tagName: "span",
1035
- properties: { class: "popover" },
1036
- children: [
1037
- {
1038
- type: "element",
1039
- tagName: "div",
1040
- properties: { class: "arrow" },
1041
- children: []
1042
- },
1043
- {
1044
- type: "text",
1045
- value: query.text || ""
1046
- }
1047
- ]
1048
- }
1049
- ]
1050
- }
1051
- ];
1052
- },
1053
- lineCustomTag(tag) {
1054
- return [
1055
- {
1056
- type: "element",
1057
- tagName: "div",
1058
- properties: { class: `meta-line logger ${tag.name}-log` },
1059
- children: [
1060
- {
1061
- type: "element",
1062
- tagName: "span",
1063
- properties: { class: "message" },
1064
- children: [
1065
- {
1066
- type: "text",
1067
- value: tag.text || ""
1068
- }
1069
- ]
1070
- }
1071
- ]
1072
- }
1073
- ];
1074
- }
1075
- };
1076
- }
1077
-
1078
1078
  function defaultTwoslashOptions() {
1079
1079
  return {
1080
1080
  customTags: ["annotate", "log", "warn", "error"]
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as _shikijs_core from '@shikijs/core';
1
+ import * as _shikijs_types from '@shikijs/types';
2
2
  import { CreateTwoslashOptions } from 'twoslash';
3
3
  import { TransformerTwoslashOptions, RendererRichOptions } from './core.mjs';
4
4
  export { CompletionItem, HastExtension, ShikiTwoslashError, TwoslashRenderer, TwoslashShikiFunction, TwoslashShikiReturn, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich } from './core.mjs';
@@ -15,6 +15,6 @@ interface TransformerTwoslashIndexOptions extends TransformerTwoslashOptions, Pi
15
15
  /**
16
16
  * Factory function to create a Shiki transformer for twoslash integrations.
17
17
  */
18
- declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions): _shikijs_core.ShikiTransformer;
18
+ declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions): _shikijs_types.ShikiTransformer;
19
19
 
20
20
  export { RendererRichOptions, type TransformerTwoslashIndexOptions, TransformerTwoslashOptions, transformerTwoslash };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as _shikijs_core from '@shikijs/core';
1
+ import * as _shikijs_types from '@shikijs/types';
2
2
  import { CreateTwoslashOptions } from 'twoslash';
3
3
  import { TransformerTwoslashOptions, RendererRichOptions } from './core.js';
4
4
  export { CompletionItem, HastExtension, ShikiTwoslashError, TwoslashRenderer, TwoslashShikiFunction, TwoslashShikiReturn, createTransformerFactory, defaultCompletionIcons, defaultCustomTagIcons, defaultHoverInfoProcessor, defaultTwoslashOptions, rendererClassic, rendererRich } from './core.js';
@@ -15,6 +15,6 @@ interface TransformerTwoslashIndexOptions extends TransformerTwoslashOptions, Pi
15
15
  /**
16
16
  * Factory function to create a Shiki transformer for twoslash integrations.
17
17
  */
18
- declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions): _shikijs_core.ShikiTransformer;
18
+ declare function transformerTwoslash(options?: TransformerTwoslashIndexOptions): _shikijs_types.ShikiTransformer;
19
19
 
20
20
  export { RendererRichOptions, type TransformerTwoslashIndexOptions, TransformerTwoslashOptions, transformerTwoslash };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/twoslash",
3
3
  "type": "module",
4
- "version": "1.16.2",
4
+ "version": "1.17.0",
5
5
  "description": "Shiki transformer for twoslash",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -49,15 +49,16 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "twoslash": "^0.2.10",
53
- "@shikijs/core": "1.16.2"
52
+ "twoslash": "^0.2.11",
53
+ "@shikijs/core": "1.17.0",
54
+ "@shikijs/types": "1.17.0"
54
55
  },
55
56
  "devDependencies": {
56
57
  "@iconify-json/carbon": "^1.2.1",
57
58
  "@iconify-json/codicon": "^1.2.0",
58
59
  "hast-util-from-html": "^2.0.2",
59
- "typescript": "^5.5.4",
60
- "@shikijs/twoslash": "1.16.2"
60
+ "typescript": "^5.6.2",
61
+ "@shikijs/twoslash": "1.17.0"
61
62
  },
62
63
  "scripts": {
63
64
  "build": "unbuild",