rn-shiki 0.0.37-2 → 0.0.37-21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. package/lib/commonjs/components/syntax/SyntaxHighlighter.js +69 -61
  2. package/lib/commonjs/components/syntax/SyntaxHighlighter.js.map +1 -1
  3. package/lib/commonjs/hooks/useSyntaxHighlighter.js +18 -10
  4. package/lib/commonjs/hooks/useSyntaxHighlighter.js.map +1 -1
  5. package/lib/commonjs/index.js +0 -23
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/syntax/{highlighter/index.js → highlighter.js} +20 -10
  8. package/lib/commonjs/syntax/highlighter.js.map +1 -0
  9. package/lib/commonjs/utils/style-transformer.js +97 -0
  10. package/lib/commonjs/utils/style-transformer.js.map +1 -0
  11. package/lib/module/components/syntax/SyntaxHighlighter.js +69 -62
  12. package/lib/module/components/syntax/SyntaxHighlighter.js.map +1 -1
  13. package/lib/module/hooks/useSyntaxHighlighter.js +17 -9
  14. package/lib/module/hooks/useSyntaxHighlighter.js.map +1 -1
  15. package/lib/module/index.js +1 -3
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/module/syntax/highlighter.js +44 -0
  18. package/lib/module/syntax/highlighter.js.map +1 -0
  19. package/lib/module/utils/style-transformer.js +91 -0
  20. package/lib/module/utils/style-transformer.js.map +1 -0
  21. package/lib/typescript/components/syntax/SyntaxHighlighter.d.ts +2 -10
  22. package/lib/typescript/components/syntax/SyntaxHighlighter.d.ts.map +1 -1
  23. package/lib/typescript/hooks/useSyntaxHighlighter.d.ts +3 -2
  24. package/lib/typescript/hooks/useSyntaxHighlighter.d.ts.map +1 -1
  25. package/lib/typescript/index.d.ts +1 -3
  26. package/lib/typescript/index.d.ts.map +1 -1
  27. package/lib/typescript/syntax/{highlighter/index.d.ts → highlighter.d.ts} +3 -4
  28. package/lib/typescript/syntax/highlighter.d.ts.map +1 -0
  29. package/lib/typescript/types/shiki.d.ts +10 -8
  30. package/lib/typescript/types/shiki.d.ts.map +1 -1
  31. package/lib/typescript/utils/string.d.ts +1 -1
  32. package/lib/typescript/utils/string.d.ts.map +1 -1
  33. package/lib/typescript/utils/style-transformer.d.ts +8 -0
  34. package/lib/typescript/utils/style-transformer.d.ts.map +1 -0
  35. package/package.json +2 -6
  36. package/src/components/syntax/SyntaxHighlighter.tsx +43 -56
  37. package/src/hooks/useSyntaxHighlighter.ts +13 -4
  38. package/src/index.ts +1 -4
  39. package/src/syntax/{highlighter/index.ts → highlighter.ts} +22 -10
  40. package/src/types/shiki.ts +7 -8
  41. package/src/utils/string.ts +1 -1
  42. package/src/utils/style-transformer.ts +89 -53
  43. package/lib/commonjs/components/syntax/SyntaxLine.js +0 -36
  44. package/lib/commonjs/components/syntax/SyntaxLine.js.map +0 -1
  45. package/lib/commonjs/components/syntax/index.js +0 -21
  46. package/lib/commonjs/components/syntax/index.js.map +0 -1
  47. package/lib/commonjs/syntax/highlighter/index.js.map +0 -1
  48. package/lib/commonjs/syntax/index.js +0 -19
  49. package/lib/commonjs/syntax/index.js.map +0 -1
  50. package/lib/commonjs/types/index.js +0 -2
  51. package/lib/commonjs/types/index.js.map +0 -1
  52. package/lib/commonjs/types/shiki.d.js +0 -6
  53. package/lib/commonjs/types/shiki.d.js.map +0 -1
  54. package/lib/commonjs/utils/index.js +0 -17
  55. package/lib/commonjs/utils/index.js.map +0 -1
  56. package/lib/module/components/syntax/SyntaxLine.js +0 -31
  57. package/lib/module/components/syntax/SyntaxLine.js.map +0 -1
  58. package/lib/module/components/syntax/index.js +0 -5
  59. package/lib/module/components/syntax/index.js.map +0 -1
  60. package/lib/module/syntax/highlighter/index.js +0 -34
  61. package/lib/module/syntax/highlighter/index.js.map +0 -1
  62. package/lib/module/syntax/index.js +0 -4
  63. package/lib/module/syntax/index.js.map +0 -1
  64. package/lib/module/types/index.js +0 -2
  65. package/lib/module/types/index.js.map +0 -1
  66. package/lib/module/types/shiki.d.js +0 -4
  67. package/lib/module/types/shiki.d.js.map +0 -1
  68. package/lib/module/utils/index.js +0 -4
  69. package/lib/module/utils/index.js.map +0 -1
  70. package/lib/typescript/components/syntax/SyntaxLine.d.ts +0 -9
  71. package/lib/typescript/components/syntax/SyntaxLine.d.ts.map +0 -1
  72. package/lib/typescript/components/syntax/index.d.ts +0 -3
  73. package/lib/typescript/components/syntax/index.d.ts.map +0 -1
  74. package/lib/typescript/syntax/highlighter/index.d.ts.map +0 -1
  75. package/lib/typescript/syntax/index.d.ts +0 -2
  76. package/lib/typescript/syntax/index.d.ts.map +0 -1
  77. package/lib/typescript/types/index.d.ts +0 -7
  78. package/lib/typescript/types/index.d.ts.map +0 -1
  79. package/lib/typescript/utils/index.d.ts +0 -2
  80. package/lib/typescript/utils/index.d.ts.map +0 -1
  81. package/src/components/syntax/SyntaxLine.tsx +0 -81
  82. package/src/components/syntax/index.ts +0 -2
  83. package/src/syntax/index.ts +0 -1
  84. package/src/types/index.ts +0 -6
  85. package/src/utils/index.ts +0 -1
@@ -1,20 +1,19 @@
1
- import type { LanguageInput, ThemeRegistrationAny } from 'shiki'
1
+ import type { LanguageInput, ThemedToken, ThemeInput } from 'shiki'
2
2
 
3
- export interface ThemedToken {
3
+ export interface TokenType {
4
4
  content: string
5
5
  color?: string
6
6
  fontStyle?: string
7
- fontWeight?: string
8
- }
9
-
10
- export interface TokensResult {
11
- tokens: ThemedToken[][]
12
7
  }
13
8
 
14
9
  export interface SyntaxHighlighterProps {
15
10
  text: string
16
11
  language: LanguageInput
17
12
  languageId: string
18
- theme?: ThemeRegistrationAny
13
+ theme: ThemeInput
19
14
  fontSize?: number
20
15
  }
16
+
17
+ export interface TokensResult {
18
+ tokens: ThemedToken[][]
19
+ }
@@ -1,4 +1,4 @@
1
- import type { TokenType } from '../types'
1
+ import type { TokenType } from '../types/shiki'
2
2
 
3
3
  export function createContentPreview(tokens: TokenType[], maxLength: number = 20): string {
4
4
  return tokens
@@ -1,71 +1,107 @@
1
1
  import type { TextStyle } from 'react-native'
2
- import type { ThemeRegistrationAny } from 'shiki'
2
+ import transform from 'css-to-react-native'
3
3
 
4
- export interface RNTokenStyle {
5
- color?: string
6
- backgroundColor?: string
7
- fontWeight?: TextStyle['fontWeight']
8
- fontStyle?: TextStyle['fontStyle']
4
+ export interface HighlighterStyleSheet {
5
+ [key: string]: TextStyle
9
6
  }
10
7
 
11
- const ALLOWED_STYLE_PROPERTIES = {
12
- 'color': true,
13
- 'background': true,
14
- 'background-color': true,
15
- 'font-weight': true,
16
- 'font-style': true,
17
- } as const
18
-
19
- function transformValue(key: string, value: string): any {
20
- switch (key) {
21
- case 'background':
22
- case 'background-color':
23
- return ['backgroundColor', value]
24
- case 'font-weight':
25
- return ['fontWeight', value === 'bold' ? 'bold' : 'normal']
26
- case 'font-style':
27
- return ['fontStyle', value === 'italic' ? 'italic' : 'normal']
28
- default:
29
- return [key, value]
8
+ export type ReactStyle = Record<string, TextStyle>
9
+
10
+ // Helper function to convert hex color to RGB
11
+ function hexToRgb(hex: string): { r: number, g: number, b: number } | null {
12
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
13
+ return result
14
+ ? {
15
+ r: Number.parseInt(result[1]!, 16),
16
+ g: Number.parseInt(result[2]!, 16),
17
+ b: Number.parseInt(result[3]!, 16),
18
+ }
19
+ : null
20
+ }
21
+
22
+ // Helper function to normalize color values
23
+ function normalizeColor(color: string | undefined): string {
24
+ if (!color)
25
+ return 'transparent'
26
+
27
+ // Type guard to ensure color is string before we call string methods
28
+ if (typeof color === 'string' && color.startsWith('#')) {
29
+ const rgb = hexToRgb(color)
30
+ if (rgb) {
31
+ return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`
32
+ }
30
33
  }
34
+ return color
31
35
  }
32
36
 
33
- export function convertShikiTheme(theme: ThemeRegistrationAny): {
34
- backgroundColor: string
35
- defaultColor: string
36
- styles: Record<string, RNTokenStyle>
37
- } {
38
- // Extract theme colors
39
- const backgroundColor = theme.bg || '#1e1e1e'
40
- const defaultColor = theme.fg || '#d4d4d4'
37
+ export function convertTokenColorsToReactStyle(tokenColors: any[]): ReactStyle {
38
+ const styleMap: ReactStyle = {}
41
39
 
42
- // Convert token colors
43
- const styles: Record<string, RNTokenStyle> = {}
40
+ // Add default styles
41
+ styleMap.default = {
42
+ color: '#e1e4e8',
43
+ backgroundColor: 'transparent',
44
+ }
44
45
 
45
- theme.settings?.forEach((setting) => {
46
- if (!setting.scope || !setting.settings)
46
+ tokenColors.forEach((token) => {
47
+ if (!token.settings || !token.scope)
47
48
  return
48
49
 
49
- const scopes = Array.isArray(setting.scope) ? setting.scope : [setting.scope]
50
- const style: RNTokenStyle = {}
50
+ const scopes = Array.isArray(token.scope) ? token.scope : [token.scope]
51
+ const styleEntries: Array<[string, string]> = []
51
52
 
52
- // Convert CSS-style properties to RN style properties
53
- Object.entries(setting.settings).forEach(([key, value]) => {
54
- if (ALLOWED_STYLE_PROPERTIES[key as keyof typeof ALLOWED_STYLE_PROPERTIES]) {
55
- const [rnKey, rnValue] = transformValue(key, value as string)
56
- style[rnKey as keyof RNTokenStyle] = rnValue
53
+ // Only add styles if they exist
54
+ if (token.settings.foreground) {
55
+ styleEntries.push(['color', normalizeColor(token.settings.foreground)])
56
+ }
57
+ if (token.settings.background) {
58
+ styleEntries.push(['backgroundColor', normalizeColor(token.settings.background)])
59
+ }
60
+ if (token.settings.fontStyle) {
61
+ if (token.settings.fontStyle.includes('italic')) {
62
+ styleEntries.push(['fontStyle', 'italic'])
57
63
  }
58
- })
64
+ if (token.settings.fontStyle.includes('bold')) {
65
+ styleEntries.push(['fontWeight', 'bold'])
66
+ }
67
+ }
68
+
69
+ if (styleEntries.length > 0) {
70
+ const transformedStyle = transform(styleEntries)
59
71
 
60
- // Apply style to each scope
61
- scopes.forEach((scope) => {
62
- styles[scope] = style
63
- })
72
+ scopes.forEach((scope: string) => {
73
+ if (typeof scope === 'string') {
74
+ styleMap[scope] = { ...(styleMap[scope] || {}), ...transformedStyle }
75
+ }
76
+ })
77
+ }
64
78
  })
65
79
 
66
- return {
67
- backgroundColor,
68
- defaultColor,
69
- styles,
80
+ return styleMap
81
+ }
82
+
83
+ export function getRNStylesFromShikiStyle(theme: any): HighlighterStyleSheet {
84
+ if (!theme || !theme.tokenColors) {
85
+ console.error('Provided theme does not contain \'tokenColors\'.')
86
+ return {}
87
+ }
88
+
89
+ try {
90
+ // Convert theme colors to React Native styles
91
+ const styles = convertTokenColorsToReactStyle(theme.tokenColors)
92
+
93
+ // Add theme-specific base styles if they exist
94
+ if (theme.colors) {
95
+ styles.base = {
96
+ color: normalizeColor(theme.colors['editor.foreground']),
97
+ backgroundColor: normalizeColor(theme.colors['editor.background']),
98
+ }
99
+ }
100
+
101
+ return styles
102
+ }
103
+ catch {
104
+ console.error('Error converting theme styles')
105
+ return {}
70
106
  }
71
107
  }
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _reactNative = require("react-native");
9
- var _jsxRuntime = require("react/jsx-runtime");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- function SyntaxLine({
12
- line,
13
- fontSize
14
- }) {
15
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
16
- style: {
17
- flexDirection: 'row',
18
- flexWrap: 'wrap'
19
- },
20
- children: line.map((token, tokenIndex) => {
21
- // Preserve whitespace
22
- const content = token.content.replace(/ /g, '\u00A0');
23
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
24
- style: {
25
- color: token.color,
26
- fontFamily: 'monospace',
27
- fontSize,
28
- fontStyle: token.fontStyle
29
- },
30
- children: content
31
- }, `${content}-${tokenIndex}`);
32
- })
33
- });
34
- }
35
- var _default = exports.default = SyntaxLine;
36
- //# sourceMappingURL=SyntaxLine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_jsxRuntime","e","__esModule","default","SyntaxLine","line","fontSize","jsx","View","style","flexDirection","flexWrap","children","map","token","tokenIndex","content","replace","Text","color","fontFamily","fontStyle","_default","exports"],"sourceRoot":"../../../../src","sources":["components/syntax/SyntaxLine.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAAyC,IAAAE,WAAA,GAAAF,OAAA;AAAA,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAOzC,SAASG,UAAUA,CAAC;EAAEC,IAAI;EAAEC;AAA0B,CAAC,EAAE;EACvD,oBACE,IAAAN,WAAA,CAAAO,GAAA,EAACR,YAAA,CAAAS,IAAI;IAACC,KAAK,EAAE;MAAEC,aAAa,EAAE,KAAK;MAAEC,QAAQ,EAAE;IAAO,CAAE;IAAAC,QAAA,EACrDP,IAAI,CAACQ,GAAG,CAAC,CAACC,KAAK,EAAEC,UAAU,KAAK;MAC/B;MACA,MAAMC,OAAO,GAAGF,KAAK,CAACE,OAAO,CAACC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;MACrD,oBACE,IAAAjB,WAAA,CAAAO,GAAA,EAACR,YAAA,CAAAmB,IAAI;QAEHT,KAAK,EAAE;UACLU,KAAK,EAAEL,KAAK,CAACK,KAAK;UAClBC,UAAU,EAAE,WAAW;UACvBd,QAAQ;UACRe,SAAS,EAAEP,KAAK,CAACO;QACnB,CAAE;QAAAT,QAAA,EAEDI;MAAO,GARH,GAAGA,OAAO,IAAID,UAAU,EASzB,CAAC;IAEX,CAAC;EAAC,CACE,CAAC;AAEX;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAApB,OAAA,GAEcC,UAAU","ignoreList":[]}
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "SyntaxHighlighter", {
7
- enumerable: true,
8
- get: function () {
9
- return _SyntaxHighlighter.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "SyntaxLine", {
13
- enumerable: true,
14
- get: function () {
15
- return _SyntaxLine.default;
16
- }
17
- });
18
- var _SyntaxHighlighter = _interopRequireDefault(require("./SyntaxHighlighter"));
19
- var _SyntaxLine = _interopRequireDefault(require("./SyntaxLine"));
20
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_SyntaxHighlighter","_interopRequireDefault","require","_SyntaxLine","e","__esModule","default"],"sourceRoot":"../../../../src","sources":["components/syntax/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAoD,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["_core","require","_javascript","initializeHighlighter","langs","themes","createHighlighterCore","engine","createJavaScriptRegexEngine","createHighlighter","length","Error","highlighter","error","console","processTokens","tokens","map","token","content","color","fontStyle","toString"],"sourceRoot":"../../../../src","sources":["syntax/highlighter/index.ts"],"mappings":";;;;;;;AAEA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA,eAAeE,qBAAqBA,CAACC,KAAsB,EAAEC,MAAoB,EAA8D;EAC7I,OAAO,IAAAC,2BAAqB,EAAC;IAC3BC,MAAM,EAAE,IAAAC,uCAA2B,EAAC,CAAC;IACrCJ,KAAK;IACLC;EACF,CAAC,CAAC;AACJ;AAEO,eAAeI,iBAAiBA,CAAC;EAAEL,KAAK;EAAEC;AAAyD,CAAC,EAA8D;EACvK,IAAI,CAACD,KAAK,EAAEM,MAAM,IAAI,CAACL,MAAM,EAAEK,MAAM,EAAE;IACrC,MAAM,IAAIC,KAAK,CAAC,uEAAuE,CAAC;EAC1F;EAEA,IAAI;IACF,MAAMC,WAAW,GAAG,MAAMT,qBAAqB,CAACC,KAAK,EAAEC,MAAM,CAAC;IAC9D,OAAOO,WAAW;EACpB,CAAC,CACD,OAAOC,KAAK,EAAE;IACZC,OAAO,CAACD,KAAK,CAAC,+BAA+B,EAAEA,KAAK,CAAC;IACrD,MAAMA,KAAK;EACb;AACF;AAEO,SAASE,aAAaA,CAACC,MAAqB,EAAe;EAChE,OAAOA,MAAM,CAACC,GAAG,CAACC,KAAK,KAAK;IAC1BC,OAAO,EAAED,KAAK,CAACC,OAAO;IACtBC,KAAK,EAAEF,KAAK,CAACE,KAAK,IAAI,SAAS;IAC/BC,SAAS,EAAEH,KAAK,CAACG,SAAS,EAAEC,QAAQ,CAAC;EACvC,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "createHighlighter", {
7
- enumerable: true,
8
- get: function () {
9
- return _highlighter.createHighlighter;
10
- }
11
- });
12
- Object.defineProperty(exports, "processTokens", {
13
- enumerable: true,
14
- get: function () {
15
- return _highlighter.processTokens;
16
- }
17
- });
18
- var _highlighter = require("./highlighter");
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_highlighter","require"],"sourceRoot":"../../../src","sources":["syntax/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"","ignoreList":[]}
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=shiki.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/shiki.d.ts"],"mappings":"","ignoreList":[]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _string = require("./string");
7
- Object.keys(_string).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _string[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _string[key];
14
- }
15
- });
16
- });
17
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_string","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- import React from 'react';
4
- import { Text, View } from 'react-native';
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- function SyntaxLine({
7
- line,
8
- fontSize
9
- }) {
10
- return /*#__PURE__*/_jsx(View, {
11
- style: {
12
- flexDirection: 'row',
13
- flexWrap: 'wrap'
14
- },
15
- children: line.map((token, tokenIndex) => {
16
- // Preserve whitespace
17
- const content = token.content.replace(/ /g, '\u00A0');
18
- return /*#__PURE__*/_jsx(Text, {
19
- style: {
20
- color: token.color,
21
- fontFamily: 'monospace',
22
- fontSize,
23
- fontStyle: token.fontStyle
24
- },
25
- children: content
26
- }, `${content}-${tokenIndex}`);
27
- })
28
- });
29
- }
30
- export default SyntaxLine;
31
- //# sourceMappingURL=SyntaxLine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","Text","View","jsx","_jsx","SyntaxLine","line","fontSize","style","flexDirection","flexWrap","children","map","token","tokenIndex","content","replace","color","fontFamily","fontStyle"],"sourceRoot":"../../../../src","sources":["components/syntax/SyntaxLine.tsx"],"mappings":";;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAOzC,SAASC,UAAUA,CAAC;EAAEC,IAAI;EAAEC;AAA0B,CAAC,EAAE;EACvD,oBACEH,IAAA,CAACF,IAAI;IAACM,KAAK,EAAE;MAAEC,aAAa,EAAE,KAAK;MAAEC,QAAQ,EAAE;IAAO,CAAE;IAAAC,QAAA,EACrDL,IAAI,CAACM,GAAG,CAAC,CAACC,KAAK,EAAEC,UAAU,KAAK;MAC/B;MACA,MAAMC,OAAO,GAAGF,KAAK,CAACE,OAAO,CAACC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;MACrD,oBACEZ,IAAA,CAACH,IAAI;QAEHO,KAAK,EAAE;UACLS,KAAK,EAAEJ,KAAK,CAACI,KAAK;UAClBC,UAAU,EAAE,WAAW;UACvBX,QAAQ;UACRY,SAAS,EAAEN,KAAK,CAACM;QACnB,CAAE;QAAAR,QAAA,EAEDI;MAAO,GARH,GAAGA,OAAO,IAAID,UAAU,EASzB,CAAC;IAEX,CAAC;EAAC,CACE,CAAC;AAEX;AAEA,eAAeT,UAAU","ignoreList":[]}
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- export { default as SyntaxHighlighter } from './SyntaxHighlighter';
4
- export { default as SyntaxLine } from './SyntaxLine';
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["default","SyntaxHighlighter","SyntaxLine"],"sourceRoot":"../../../../src","sources":["components/syntax/index.ts"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,iBAAiB,QAAQ,qBAAqB;AAClE,SAASD,OAAO,IAAIE,UAAU,QAAQ,cAAc","ignoreList":[]}
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- import { createHighlighterCore } from 'shiki/core';
4
- import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
5
- async function initializeHighlighter(langs, themes) {
6
- return createHighlighterCore({
7
- engine: createJavaScriptRegexEngine(),
8
- langs,
9
- themes
10
- });
11
- }
12
- export async function createHighlighter({
13
- langs,
14
- themes
15
- }) {
16
- if (!langs?.length || !themes?.length) {
17
- throw new Error('Please provide both `langs` and `themes` when creating a highlighter.');
18
- }
19
- try {
20
- const highlighter = await initializeHighlighter(langs, themes);
21
- return highlighter;
22
- } catch (error) {
23
- console.error('Failed to create highlighter:', error);
24
- throw error;
25
- }
26
- }
27
- export function processTokens(tokens) {
28
- return tokens.map(token => ({
29
- content: token.content,
30
- color: token.color || '#000000',
31
- fontStyle: token.fontStyle?.toString()
32
- }));
33
- }
34
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["createHighlighterCore","createJavaScriptRegexEngine","initializeHighlighter","langs","themes","engine","createHighlighter","length","Error","highlighter","error","console","processTokens","tokens","map","token","content","color","fontStyle","toString"],"sourceRoot":"../../../../src","sources":["syntax/highlighter/index.ts"],"mappings":";;AAEA,SAASA,qBAAqB,QAAQ,YAAY;AAClD,SAASC,2BAA2B,QAAQ,yBAAyB;AAErE,eAAeC,qBAAqBA,CAACC,KAAsB,EAAEC,MAAoB,EAA8D;EAC7I,OAAOJ,qBAAqB,CAAC;IAC3BK,MAAM,EAAEJ,2BAA2B,CAAC,CAAC;IACrCE,KAAK;IACLC;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,eAAeE,iBAAiBA,CAAC;EAAEH,KAAK;EAAEC;AAAyD,CAAC,EAA8D;EACvK,IAAI,CAACD,KAAK,EAAEI,MAAM,IAAI,CAACH,MAAM,EAAEG,MAAM,EAAE;IACrC,MAAM,IAAIC,KAAK,CAAC,uEAAuE,CAAC;EAC1F;EAEA,IAAI;IACF,MAAMC,WAAW,GAAG,MAAMP,qBAAqB,CAACC,KAAK,EAAEC,MAAM,CAAC;IAC9D,OAAOK,WAAW;EACpB,CAAC,CACD,OAAOC,KAAK,EAAE;IACZC,OAAO,CAACD,KAAK,CAAC,+BAA+B,EAAEA,KAAK,CAAC;IACrD,MAAMA,KAAK;EACb;AACF;AAEA,OAAO,SAASE,aAAaA,CAACC,MAAqB,EAAe;EAChE,OAAOA,MAAM,CAACC,GAAG,CAACC,KAAK,KAAK;IAC1BC,OAAO,EAAED,KAAK,CAACC,OAAO;IACtBC,KAAK,EAAEF,KAAK,CAACE,KAAK,IAAI,SAAS;IAC/BC,SAAS,EAAEH,KAAK,CAACG,SAAS,EAAEC,QAAQ,CAAC;EACvC,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- export { createHighlighter, processTokens } from './highlighter';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["createHighlighter","processTokens"],"sourceRoot":"../../../src","sources":["syntax/index.ts"],"mappings":";;AAAA,SAASA,iBAAiB,EAAEC,aAAa,QAAQ,eAAe","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"","ignoreList":[]}
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- export {};
4
- //# sourceMappingURL=shiki.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/shiki.d.ts"],"mappings":"","ignoreList":[]}
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- export * from './string';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;AAAA,cAAc,UAAU","ignoreList":[]}
@@ -1,9 +0,0 @@
1
- import type { TokenType } from '../../types';
2
- import React from 'react';
3
- interface SyntaxLineProps {
4
- line: TokenType[];
5
- fontSize?: number;
6
- }
7
- declare function SyntaxLine({ line, fontSize }: SyntaxLineProps): React.JSX.Element;
8
- export default SyntaxLine;
9
- //# sourceMappingURL=SyntaxLine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SyntaxLine.d.ts","sourceRoot":"","sources":["../../../../src/components/syntax/SyntaxLine.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,UAAU,eAAe;IACvB,IAAI,EAAE,SAAS,EAAE,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,iBAAS,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,eAAe,qBAsBtD;AAED,eAAe,UAAU,CAAA"}
@@ -1,3 +0,0 @@
1
- export { default as SyntaxHighlighter } from './SyntaxHighlighter';
2
- export { default as SyntaxLine } from './SyntaxLine';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/syntax/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/syntax/highlighter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAWlD,wBAAsB,iBAAiB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAavK;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,EAAE,CAMhE"}
@@ -1,2 +0,0 @@
1
- export { createHighlighter, processTokens } from './highlighter';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/syntax/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA"}
@@ -1,7 +0,0 @@
1
- export interface TokenType {
2
- content: string;
3
- color: string;
4
- fontStyle?: string;
5
- fontWeight?: string;
6
- }
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
@@ -1,2 +0,0 @@
1
- export * from './string';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -1,81 +0,0 @@
1
- import type { TokenType } from '../../types'
2
- import type { RNTokenStyle } from '../../utils/style-transformer'
3
- import React from 'react'
4
- import { Platform, StyleSheet, Text, View } from 'react-native'
5
-
6
- const monospaceFont = Platform.select({
7
- ios: 'Menlo',
8
- android: 'monospace',
9
- default: 'monospace',
10
- })
11
-
12
- const styles = StyleSheet.create({
13
- lineContainer: {
14
- flexDirection: 'row',
15
- flexWrap: 'wrap',
16
- },
17
- token: {
18
- includeFontPadding: false,
19
- },
20
- })
21
-
22
- interface SyntaxLineProps {
23
- line: TokenType[]
24
- fontSize?: number
25
- isLastLine?: boolean
26
- themeStyles: {
27
- backgroundColor: string
28
- defaultColor: string
29
- styles: Record<string, RNTokenStyle>
30
- }
31
- }
32
-
33
- function SyntaxLine({ line, fontSize = 14, isLastLine = false, themeStyles }: SyntaxLineProps) {
34
- const lineHeight = Math.floor(fontSize * 1.5)
35
-
36
- return (
37
- <View
38
- style={[
39
- styles.lineContainer,
40
- {
41
- minHeight: lineHeight,
42
- paddingBottom: !isLastLine ? 4 : 0,
43
- },
44
- ]}
45
- >
46
- {line.map((token, tokenIndex) => {
47
- const content = token.content.replace(/ /g, '\u00A0')
48
- // Use converted theme styles
49
- const tokenStyle = token.color ? { color: token.color } : { color: themeStyles.defaultColor }
50
-
51
- return (
52
- <Text
53
- key={`${tokenIndex}-${content.slice(0, 8)}`}
54
- style={[
55
- styles.token,
56
- {
57
- ...tokenStyle,
58
- fontFamily: monospaceFont,
59
- fontSize,
60
- fontStyle: token.fontStyle as 'normal' | 'italic',
61
- fontWeight: token.fontWeight as 'normal' | 'bold',
62
- lineHeight,
63
- height: lineHeight,
64
- textAlignVertical: 'center',
65
- ...(Platform.OS === 'ios'
66
- ? {
67
- paddingTop: 2,
68
- }
69
- : {}),
70
- },
71
- ]}
72
- >
73
- {content}
74
- </Text>
75
- )
76
- })}
77
- </View>
78
- )
79
- }
80
-
81
- export default SyntaxLine
@@ -1,2 +0,0 @@
1
- export { default as SyntaxHighlighter } from './SyntaxHighlighter'
2
- export { default as SyntaxLine } from './SyntaxLine'
@@ -1 +0,0 @@
1
- export { createHighlighter, processTokens } from './highlighter'
@@ -1,6 +0,0 @@
1
- export interface TokenType {
2
- content: string
3
- color?: string
4
- fontStyle?: string
5
- fontWeight?: string
6
- }
@@ -1 +0,0 @@
1
- export * from './string'