@shikijs/cli 1.24.1 → 1.24.2

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/cli.mjs CHANGED
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
2
2
  import { parse } from 'node:path';
3
3
  import process from 'node:process';
4
4
  import minimist from 'minimist';
5
- import { codeToANSI } from './index.mjs';
5
+ import { c as codeToANSI } from './shared/cli.Bb-o0pCq.mjs';
6
6
  import '@shikijs/vscode-textmate';
7
7
  import 'chalk';
8
8
  import 'shiki';
package/dist/index.mjs CHANGED
@@ -1,66 +1,4 @@
1
- import { FontStyle } from '@shikijs/vscode-textmate';
2
- import c from 'chalk';
3
- import { codeToTokensBase, getSingletonHighlighter } from 'shiki';
4
-
5
- function normalizeHex(hex) {
6
- hex = hex.replace(/#/, "");
7
- if (hex.length === 3)
8
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
9
- if (hex.length === 4)
10
- hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
11
- if (hex.length === 6)
12
- hex = `${hex}ff`;
13
- return hex.toLowerCase();
14
- }
15
- function hexToRgba(hex) {
16
- hex = normalizeHex(hex);
17
- const r = Number.parseInt(hex.slice(0, 2), 16);
18
- const g = Number.parseInt(hex.slice(2, 4), 16);
19
- const b = Number.parseInt(hex.slice(4, 6), 16);
20
- const a = Number.parseInt(hex.slice(6, 8), 16) / 255;
21
- return { r, g, b, a };
22
- }
23
- function RgbToHex(r, g, b) {
24
- return [r, g, b].map((x) => {
25
- const hex = x.toString(16);
26
- return hex.length === 1 ? `0${hex}` : hex;
27
- }).join("");
28
- }
29
- function hexApplyAlpha(hex, type = "dark") {
30
- const { r, g, b, a } = hexToRgba(hex);
31
- if (type === "dark")
32
- return RgbToHex(r * a, g * a, b * a);
33
- else
34
- return RgbToHex(r * a + 255 * (1 - a), g * a + 255 * (1 - a), b * a + 255 * (1 - a));
35
- }
36
-
37
- async function codeToANSI(code, lang, theme) {
38
- let output = "";
39
- const lines = await codeToTokensBase(code, {
40
- lang,
41
- theme
42
- });
43
- const highlight = await getSingletonHighlighter();
44
- const themeReg = highlight.getTheme(theme);
45
- for (const line of lines) {
46
- for (const token of line) {
47
- let text = token.content;
48
- const color = token.color || themeReg.fg;
49
- if (color)
50
- text = c.hex(hexApplyAlpha(color, themeReg.type))(text);
51
- if (token.fontStyle) {
52
- if (token.fontStyle & FontStyle.Bold)
53
- text = c.bold(text);
54
- if (token.fontStyle & FontStyle.Italic)
55
- text = c.italic(text);
56
- if (token.fontStyle & FontStyle.Underline)
57
- text = c.underline(text);
58
- }
59
- output += text;
60
- }
61
- output += "\n";
62
- }
63
- return output;
64
- }
65
-
66
- export { codeToANSI };
1
+ export { c as codeToANSI } from './shared/cli.Bb-o0pCq.mjs';
2
+ import '@shikijs/vscode-textmate';
3
+ import 'chalk';
4
+ import 'shiki';
@@ -0,0 +1,66 @@
1
+ import { FontStyle } from '@shikijs/vscode-textmate';
2
+ import c from 'chalk';
3
+ import { codeToTokensBase, getSingletonHighlighter } from 'shiki';
4
+
5
+ function normalizeHex(hex) {
6
+ hex = hex.replace(/#/, "");
7
+ if (hex.length === 3)
8
+ hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
9
+ if (hex.length === 4)
10
+ hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
11
+ if (hex.length === 6)
12
+ hex = `${hex}ff`;
13
+ return hex.toLowerCase();
14
+ }
15
+ function hexToRgba(hex) {
16
+ hex = normalizeHex(hex);
17
+ const r = Number.parseInt(hex.slice(0, 2), 16);
18
+ const g = Number.parseInt(hex.slice(2, 4), 16);
19
+ const b = Number.parseInt(hex.slice(4, 6), 16);
20
+ const a = Number.parseInt(hex.slice(6, 8), 16) / 255;
21
+ return { r, g, b, a };
22
+ }
23
+ function RgbToHex(r, g, b) {
24
+ return [r, g, b].map((x) => {
25
+ const hex = x.toString(16);
26
+ return hex.length === 1 ? `0${hex}` : hex;
27
+ }).join("");
28
+ }
29
+ function hexApplyAlpha(hex, type = "dark") {
30
+ const { r, g, b, a } = hexToRgba(hex);
31
+ if (type === "dark")
32
+ return RgbToHex(r * a, g * a, b * a);
33
+ else
34
+ return RgbToHex(r * a + 255 * (1 - a), g * a + 255 * (1 - a), b * a + 255 * (1 - a));
35
+ }
36
+
37
+ async function codeToANSI(code, lang, theme) {
38
+ let output = "";
39
+ const lines = await codeToTokensBase(code, {
40
+ lang,
41
+ theme
42
+ });
43
+ const highlight = await getSingletonHighlighter();
44
+ const themeReg = highlight.getTheme(theme);
45
+ for (const line of lines) {
46
+ for (const token of line) {
47
+ let text = token.content;
48
+ const color = token.color || themeReg.fg;
49
+ if (color)
50
+ text = c.hex(hexApplyAlpha(color, themeReg.type))(text);
51
+ if (token.fontStyle) {
52
+ if (token.fontStyle & FontStyle.Bold)
53
+ text = c.bold(text);
54
+ if (token.fontStyle & FontStyle.Italic)
55
+ text = c.italic(text);
56
+ if (token.fontStyle & FontStyle.Underline)
57
+ text = c.underline(text);
58
+ }
59
+ output += text;
60
+ }
61
+ output += "\n";
62
+ }
63
+ return output;
64
+ }
65
+
66
+ export { codeToANSI as c };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/cli",
3
3
  "type": "module",
4
- "version": "1.24.1",
4
+ "version": "1.24.2",
5
5
  "description": "Shiki in the command line",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "@shikijs/vscode-textmate": "^9.3.0",
46
46
  "chalk": "^5.3.0",
47
47
  "minimist": "^1.2.8",
48
- "shiki": "1.24.1"
48
+ "shiki": "1.24.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/minimist": "^1.2.5"