rn-shiki 0.0.37-3 → 0.0.37-30

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 +100 -60
  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 +103 -0
  10. package/lib/commonjs/utils/style-transformer.js.map +1 -0
  11. package/lib/module/components/syntax/SyntaxHighlighter.js +100 -61
  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 +98 -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 +9 -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 +79 -36
  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 +50 -94
  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
@@ -4,76 +4,116 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
8
  var _reactNative = require("react-native");
9
- var _typescript = _interopRequireDefault(require("shiki/langs/typescript.mjs"));
10
- var _githubDark = _interopRequireDefault(require("shiki/themes/github-dark.mjs"));
11
9
  var _useSyntaxHighlighter = require("../../hooks/useSyntaxHighlighter");
10
+ var _styleTransformer = require("../../utils/style-transformer");
12
11
  var _jsxRuntime = require("react/jsx-runtime");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- function SyntaxHighlighter({
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const monospaceFont = _reactNative.Platform.select({
15
+ ios: 'Menlo',
16
+ android: 'monospace',
17
+ default: 'monospace'
18
+ });
19
+ // Helper function to extract theme registration from Shiki theme input
20
+ function getThemeRegistration(theme) {
21
+ if ('default' in theme) {
22
+ return theme.default;
23
+ }
24
+ return theme;
25
+ }
26
+ const baseStyles = _reactNative.StyleSheet.create({
27
+ scrollView: {
28
+ flex: 1,
29
+ minHeight: 20
30
+ },
31
+ lineContainer: {
32
+ flexDirection: 'row',
33
+ flexWrap: 'wrap',
34
+ paddingHorizontal: 16,
35
+ paddingVertical: 8
36
+ },
37
+ token: {
38
+ fontFamily: monospaceFont,
39
+ fontSize: 14
40
+ },
41
+ container: {
42
+ flex: 1
43
+ }
44
+ });
45
+ const SyntaxHighlighter = ({
15
46
  text,
16
- lang = _typescript.default,
17
- langName = 'typescript',
18
- theme = _githubDark.default,
19
- themeName = 'github-dark',
20
- fontSize
21
- }) {
47
+ language,
48
+ languageId,
49
+ theme,
50
+ fontSize = 14
51
+ }) => {
52
+ const stylesheet = (0, _react.useMemo)(() => {
53
+ const themeRegistration = getThemeRegistration(theme);
54
+ const styles = (0, _styleTransformer.getRNStylesFromShikiStyle)(themeRegistration);
55
+ return _reactNative.StyleSheet.create({
56
+ ...styles,
57
+ editor: {
58
+ backgroundColor: themeRegistration.colors?.['editor.background'] || '#1e1e1e'
59
+ },
60
+ token: {
61
+ ...baseStyles.token,
62
+ fontSize,
63
+ color: themeRegistration.colors?.['editor.foreground'] || '#d4d4d4'
64
+ }
65
+ });
66
+ }, [theme, fontSize]);
22
67
  const {
23
- tokens,
24
- error,
25
- isLoading
68
+ tokens
26
69
  } = (0, _useSyntaxHighlighter.useSyntaxHighlighter)({
27
70
  text,
28
- lang,
29
- langName,
30
- theme,
31
- themeName
71
+ language,
72
+ languageId,
73
+ theme
32
74
  });
33
- if (error) {
34
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, {
35
- style: {
36
- color: '#ff6b6b',
37
- fontFamily: 'monospace',
38
- fontSize
39
- },
40
- children: ["Error:", error]
75
+ const renderToken = (token, index, lineIndex) => {
76
+ const styles = [stylesheet.token];
77
+
78
+ // Add token-specific styles from stylesheet based on scope
79
+ const tokenScopes = Array.isArray(token.scope) ? token.scope : [token.scope];
80
+ tokenScopes.forEach(scope => {
81
+ if (stylesheet[scope]) {
82
+ styles.push(stylesheet[scope]);
83
+ }
41
84
  });
42
- }
43
- if (isLoading) {
85
+
86
+ // Add token-specific styles from the token itself
87
+ const tokenStyles = {};
88
+ if (token.color) {
89
+ tokenStyles.color = token.color;
90
+ }
91
+ if (token.fontStyle === 'italic') {
92
+ tokenStyles.fontStyle = 'italic';
93
+ }
94
+ if (token.fontWeight === 'bold') {
95
+ tokenStyles.fontWeight = 'bold';
96
+ }
97
+ if (Object.keys(tokenStyles).length > 0) {
98
+ styles.push(tokenStyles);
99
+ }
100
+ const finalStyle = _reactNative.StyleSheet.flatten(styles);
44
101
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
45
- style: {
46
- color: '#f8f8f2',
47
- fontFamily: 'monospace',
48
- fontSize
49
- },
50
- children: "Loading..."
51
- });
52
- }
53
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
54
- children: tokens.map((line, lineIndex) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
55
- style: {
56
- flexDirection: 'row',
57
- flexWrap: 'wrap'
58
- },
59
- children: [line.map((token, tokenIndex) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
60
- style: {
61
- color: token.color || '#FFFFFF',
62
- fontFamily: 'monospace',
63
- fontSize,
64
- fontStyle: token.fontStyle
65
- },
66
- children: token.content.replace(/ /g, '\u00A0')
67
- }, `${lineIndex}-${tokenIndex}`)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
68
- style: {
69
- color: '#FFFFFF',
70
- fontFamily: 'monospace',
71
- fontSize
72
- },
73
- children: '\n'
74
- })]
75
- }, `line-${lineIndex}`))
102
+ style: finalStyle,
103
+ children: token.content.replace(/ /g, '\u00A0')
104
+ }, `${lineIndex}-${index}`);
105
+ };
106
+ const renderLine = (line, lineIndex) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
107
+ style: baseStyles.lineContainer,
108
+ children: line.map((token, tokenIndex) => renderToken(token, tokenIndex, lineIndex))
109
+ }, lineIndex);
110
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, {
111
+ horizontal: true,
112
+ showsHorizontalScrollIndicator: _reactNative.Platform.OS !== 'web',
113
+ style: [baseStyles.scrollView, stylesheet.editor],
114
+ contentContainerStyle: baseStyles.container,
115
+ children: tokens.map((line, index) => renderLine(line, index))
76
116
  });
77
- }
117
+ };
78
118
  var _default = exports.default = SyntaxHighlighter;
79
119
  //# sourceMappingURL=SyntaxHighlighter.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_typescript","_githubDark","_useSyntaxHighlighter","_jsxRuntime","e","__esModule","default","SyntaxHighlighter","text","lang","typescript","langName","theme","githubDark","themeName","fontSize","tokens","error","isLoading","useSyntaxHighlighter","jsxs","Text","style","color","fontFamily","children","jsx","View","map","line","lineIndex","flexDirection","flexWrap","token","tokenIndex","fontStyle","content","replace","_default","exports"],"sourceRoot":"../../../../src","sources":["components/syntax/SyntaxHighlighter.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAA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AA2BL,KAAK,EAAE;QAAES,aAAa,EAAE,KAAK;QAAEC,QAAQ,EAAE;MAAO,CAAE;MAAAP,QAAA,GAC/EI,IAAI,CAACD,GAAG,CAAC,CAACK,KAAK,EAAEC,UAAU,kBAC1B,IAAA/B,WAAA,CAAAuB,GAAA,EAAC3B,YAAA,CAAAsB,IAAI;QAEHC,KAAK,EAAE;UACLC,KAAK,EAAEU,KAAK,CAACV,KAAK,IAAI,SAAS;UAC/BC,UAAU,EAAE,WAAW;UACvBT,QAAQ;UACRoB,SAAS,EAAEF,KAAK,CAACE;QACnB,CAAE;QAAAV,QAAA,EAEDQ,KAAK,CAACG,OAAO,CAACC,OAAO,CAAC,IAAI,EAAE,QAAQ;MAAC,GARjC,GAAGP,SAAS,IAAII,UAAU,EAS3B,CACP,CAAC,eACF,IAAA/B,WAAA,CAAAuB,GAAA,EAAC3B,YAAA,CAAAsB,IAAI;QAACC,KAAK,EAAE;UAAEC,KAAK,EAAE,SAAS;UAAEC,UAAU,EAAE,WAAW;UAAET;QAAS,CAAE;QAAAU,QAAA,EAAE;MAAI,CAAO,CAAC;IAAA,GAd1E,QAAQK,SAAS,EAetB,CACP;EAAC,CACE,CAAC;AAEX;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAAjC,OAAA,GAEcC,iBAAiB","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_useSyntaxHighlighter","_styleTransformer","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","monospaceFont","Platform","select","ios","android","getThemeRegistration","theme","baseStyles","StyleSheet","create","scrollView","flex","minHeight","lineContainer","flexDirection","flexWrap","paddingHorizontal","paddingVertical","token","fontFamily","fontSize","container","SyntaxHighlighter","text","language","languageId","stylesheet","useMemo","themeRegistration","styles","getRNStylesFromShikiStyle","editor","backgroundColor","colors","color","tokens","useSyntaxHighlighter","renderToken","index","lineIndex","tokenScopes","Array","isArray","scope","forEach","push","tokenStyles","fontStyle","fontWeight","keys","length","finalStyle","flatten","jsx","Text","style","children","content","replace","renderLine","line","View","map","tokenIndex","ScrollView","horizontal","showsHorizontalScrollIndicator","OS","contentContainerStyle","_default","exports"],"sourceRoot":"../../../../src","sources":["components/syntax/SyntaxHighlighter.tsx"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAAyE,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAA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;AAEjB,CAAC;AAAA,IAAA+B,QAAA,GAAAC,OAAA,CAAApF,OAAA,GAEcoC,iBAAiB","ignoreList":[]}
@@ -5,13 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useSyntaxHighlighter = useSyntaxHighlighter;
7
7
  var _react = require("react");
8
- var _syntax = require("../syntax");
8
+ var _highlighter = require("../syntax/highlighter");
9
9
  function useSyntaxHighlighter({
10
10
  text,
11
- lang,
12
- langName,
13
- theme,
14
- themeName
11
+ language,
12
+ languageId,
13
+ theme
15
14
  }) {
16
15
  const [tokens, setTokens] = (0, _react.useState)([]);
17
16
  const [error, setError] = (0, _react.useState)();
@@ -26,13 +25,22 @@ function useSyntaxHighlighter({
26
25
  return;
27
26
  }
28
27
  try {
29
- const highlighter = await (0, _syntax.createHighlighter)({
30
- langs: [lang],
28
+ // First create the highlighter
29
+ const highlighter = await (0, _highlighter.createHighlighter)({
30
+ langs: [language],
31
31
  themes: [theme]
32
32
  });
33
+
34
+ // Get resolved theme name
35
+ const themeResolved = highlighter.getLoadedThemes()?.[0];
36
+ if (!themeResolved) {
37
+ throw new Error('Failed to resolve theme');
38
+ }
39
+
40
+ // Use resolved theme for tokenization
33
41
  const result = highlighter.codeToTokens(text, {
34
- lang: langName,
35
- theme: themeName
42
+ lang: languageId,
43
+ theme: themeResolved
36
44
  });
37
45
  if (mounted && result.tokens) {
38
46
  setTokens(result.tokens);
@@ -54,7 +62,7 @@ function useSyntaxHighlighter({
54
62
  return () => {
55
63
  mounted = false;
56
64
  };
57
- }, [text, lang, langName, theme, themeName]);
65
+ }, [text, language, languageId, theme]);
58
66
  return {
59
67
  tokens,
60
68
  error,
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_syntax","useSyntaxHighlighter","text","lang","langName","theme","themeName","tokens","setTokens","useState","error","setError","isLoading","setIsLoading","useEffect","mounted","highlight","highlighter","createHighlighter","langs","themes","result","codeToTokens","undefined","err","console","Error","message"],"sourceRoot":"../../../src","s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Q,CAACa,GAAG,YAAYE,KAAK,GAAGF,GAAG,CAACG,OAAO,GAAG,4BAA4B,CAAC;UAC3EnB,SAAS,CAAC,EAAE,CAAC;QACf;MACF,CAAC,SACO;QACN,IAAIO,OAAO,EAAE;UACXF,YAAY,CAAC,KAAK,CAAC;QACrB;MACF;IACF;IAEAG,SAAS,CAAC,CAAC;IACX,OAAO,MAAM;MACXD,OAAO,GAAG,KAAK;IACjB,CAAC;EACH,CAAC,EAAE,CAACb,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,SAAS,CAAC,CAAC;EAE5C,OAAO;IAAEC,MAAM;IAAEG,KAAK;IAAEE;EAAU,CAAC;AACrC","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_highlighter","useSyntaxHighlighter","text","language","languageId","theme","tokens","setTokens","useState","error","setError","isLoading","setIsLoading","useEffect","mounted","highlight","highlighter","createHighlighter","langs","themes","themeResolved","getLoadedThemes","Error","result","codeToTokens","lang","undefined","err","console","message"],"sourceRoot":"../../../src","sources":["hooks/useSyntaxHighlighter.ts"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEO,SAASE,oBAAoBA,CAAC;EAAEC,IAAI;EAAEC,QAAQ;EAAEC,UAAU;EAAEC;AAA8B,CAAC,EAAE;EAClG,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAG,IAAAC,eAAQ,EAAkB,EAAE,CAAC;EACzD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAF,eAAQ,EAAS,CAAC;EAC5C,MAAM,CAACG,SAAS,EAAEC,YAAY,CAAC,GAAG,IAAAJ,eAAQ,EAAC,IAAI,CAAC;EAEhD,IAAAK,gBAAS,EAAC,MAAM;IACd,IAAIC,OAAO,GAAG,IAAI;IAClBF,YAAY,CAAC,IAAI,CAAC;IAElB,eAAeG,SAASA,CAAA,EAAG;MACzB,IAAI,CAAC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AAC;AACrC","ignoreList":[]}
@@ -3,35 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _exportNames = {
7
- SyntaxHighlighter: true,
8
- SyntaxLine: true
9
- };
10
6
  Object.defineProperty(exports, "SyntaxHighlighter", {
11
7
  enumerable: true,
12
8
  get: function () {
13
9
  return _SyntaxHighlighter.default;
14
10
  }
15
11
  });
16
- Object.defineProperty(exports, "SyntaxLine", {
17
- enumerable: true,
18
- get: function () {
19
- return _SyntaxLine.default;
20
- }
21
- });
22
12
  var _SyntaxHighlighter = _interopRequireDefault(require("./components/syntax/SyntaxHighlighter"));
23
- var _SyntaxLine = _interopRequireDefault(require("./components/syntax/SyntaxLine"));
24
- var _shiki = require("./types/shiki");
25
- Object.keys(_shiki).forEach(function (key) {
26
- if (key === "default" || key === "__esModule") return;
27
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
- if (key in exports && exports[key] === _shiki[key]) return;
29
- Object.defineProperty(exports, key, {
30
- enumerable: true,
31
- get: function () {
32
- return _shiki[key];
33
- }
34
- });
35
- });
36
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
37
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_SyntaxHighlighter","_interopRequireDefault","require","_SyntaxLine","_shiki","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","e","__esModule","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAA6B,SAAAP,uBAAAgB,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
1
+ {"version":3,"names":["_SyntaxHighlighter","_interopRequireDefault","require","e","__esModule","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAqE,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -5,21 +5,31 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createHighlighter = createHighlighter;
7
7
  exports.processTokens = processTokens;
8
- var _core = require("shiki/core");
9
- var _javascript = require("shiki/engine/javascript");
8
+ var _core = require("shiki/dist/core.mjs");
9
+ var _engineJavascript = require("shiki/dist/engine-javascript.mjs");
10
+ const engine = (0, _engineJavascript.createJavaScriptRegexEngine)({
11
+ forgiving: true,
12
+ simulation: true,
13
+ cache: new Map()
14
+ });
10
15
  async function initializeHighlighter(langs, themes) {
11
- return (0, _core.createHighlighterCore)({
12
- engine: (0, _javascript.createJavaScriptRegexEngine)(),
13
- langs,
14
- themes
15
- });
16
+ try {
17
+ return await (0, _core.createHighlighterCore)({
18
+ langs,
19
+ themes,
20
+ engine // Pass the configured engine
21
+ });
22
+ } catch (err) {
23
+ console.error('Error initializing highlighter:', err);
24
+ throw err;
25
+ }
16
26
  }
17
27
  async function createHighlighter({
18
28
  langs,
19
29
  themes
20
30
  }) {
21
- if (!langs?.length || !themes?.length) {
22
- throw new Error('Please provide both `langs` and `themes` when creating a highlighter.');
31
+ if (!langs?.length) {
32
+ throw new Error('Please provide languages when creating a highlighter.');
23
33
  }
24
34
  try {
25
35
  const highlighter = await initializeHighlighter(langs, themes);
@@ -36,4 +46,4 @@ function processTokens(tokens) {
36
46
  fontStyle: token.fontStyle?.toString()
37
47
  }));
38
48
  }
39
- //# sourceMappingURL=index.js.map
49
+ //# sourceMappingURL=highlighter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_core","require","_engineJavascript","engine","createJavaScriptRegexEngine","forgiving","simulation","cache","Map","initializeHighlighter","langs","themes","createHighlighterCore","err","console","error","createHighlighter","length","Error","highlighter","processTokens","tokens","map","token","content","color","fontStyle","toString"],"sourceRoot":"../../../src","sources":["syntax/highlighter.ts"],"mappings":";;;;;;;AAEA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,MAAME,MAAM,GAAG,IAAAC,6CAA2B,EAAC;EACzCC,SAAS,EAAE,IAAI;EACfC,UAAU,EAAE,IAAI;EAChBC,KAAK,EAAE,IAAIC,GAAG,CAAC;AACjB,CAAC,CAAC;AAEF,eAAeC,qBAAqBA,CAACC,KAAsB,EAAEC,MAAoB,EAAE;EACjF,IAAI;IACF,OAAO,MAAM,IAAAC,2BAAqB,EAAC;MACjCF,KAAK;MACLC,MAAM;MACNR,MAAM,CAAE;IACV,CAAC,CAAC;EACJ,CAAC,CACD,OAAOU,GAAG,EAAE;IACVC,OAAO,CAACC,KAAK,CAAC,iCAAiC,EAAEF,GAAG,CAAC;IACrD,MAAMA,GAAG;EACX;AACF;AAEO,eAAeG,iBAAiBA,CAAC;EAAEN,KAAK;EAAEC;AAAyD,CAAC,EAAE;EAC3G,IAAI,CAACD,KAAK,EAAEO,MAAM,EAAE;IAClB,MAAM,IAAIC,KAAK,CAAC,uDAAuD,CAAC;EAC1E;EAEA,IAAI;IACF,MAAMC,WAAW,GAAG,MAAMV,qBAAqB,CAACC,KAAK,EAAEC,MAAM,CAAC;IAC9D,OAAOQ,WAAW;EACpB,CAAC,CACD,OAAOJ,KAAK,EAAE;IACZD,OAAO,CAACC,KAAK,CAAC,+BAA+B,EAAEA,KAAK,CAAC;IACrD,MAAMA,KAAK;EACb;AACF;AAEO,SAASK,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":[]}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertTokenColorsToReactStyle = convertTokenColorsToReactStyle;
7
+ exports.getRNStylesFromShikiStyle = getRNStylesFromShikiStyle;
8
+ function hexToRgb(hex) {
9
+ // Remove # if present
10
+ hex = hex.replace(/^#/, '');
11
+
12
+ // Handle both 3 and 6 digit hex
13
+ if (hex.length === 3) {
14
+ hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
15
+ }
16
+ const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
17
+ return result ? {
18
+ r: Number.parseInt(result[1], 16),
19
+ g: Number.parseInt(result[2], 16),
20
+ b: Number.parseInt(result[3], 16)
21
+ } : null;
22
+ }
23
+ function normalizeColor(color) {
24
+ if (!color) return 'transparent';
25
+
26
+ // Handle hex colors
27
+ if (color.startsWith('#')) {
28
+ const rgb = hexToRgb(color);
29
+ if (rgb) {
30
+ return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
31
+ }
32
+ }
33
+ return color;
34
+ }
35
+ function convertTokenColorsToReactStyle(tokenColors) {
36
+ if (!tokenColors) return {};
37
+ const styleMap = {};
38
+ tokenColors.forEach(token => {
39
+ if (!token.settings) return;
40
+
41
+ // Handle global theme settings
42
+ if (!token.scope) {
43
+ styleMap.default = {
44
+ color: normalizeColor(token.settings.foreground),
45
+ backgroundColor: normalizeColor(token.settings.background)
46
+ };
47
+ return;
48
+ }
49
+ const scopes = Array.isArray(token.scope) ? token.scope : [token.scope];
50
+ const style = {};
51
+ if (token.settings.foreground) {
52
+ style.color = normalizeColor(token.settings.foreground);
53
+ }
54
+ if (token.settings.background) {
55
+ style.backgroundColor = normalizeColor(token.settings.background);
56
+ }
57
+ if (token.settings.fontStyle) {
58
+ if (token.settings.fontStyle.includes('italic')) {
59
+ style.fontStyle = 'italic';
60
+ }
61
+ if (token.settings.fontStyle.includes('bold')) {
62
+ style.fontWeight = 'bold';
63
+ }
64
+ }
65
+ scopes.forEach(scope => {
66
+ styleMap[scope] = {
67
+ ...(styleMap[scope] || {}),
68
+ ...style
69
+ };
70
+ });
71
+ });
72
+ return styleMap;
73
+ }
74
+ function getRNStylesFromShikiStyle(theme) {
75
+ if (!theme) return {};
76
+ try {
77
+ const styles = {
78
+ editor: {
79
+ backgroundColor: normalizeColor(theme.colors?.['editor.background'])
80
+ },
81
+ base: {
82
+ color: normalizeColor(theme.colors?.['editor.foreground'])
83
+ }
84
+ };
85
+
86
+ // Process token colors
87
+ if (theme.tokenColors) {
88
+ const tokenStyles = convertTokenColorsToReactStyle(theme.tokenColors);
89
+ Object.assign(styles, tokenStyles);
90
+ }
91
+ return styles;
92
+ } catch {
93
+ return {
94
+ editor: {
95
+ backgroundColor: '#1e1e1e'
96
+ },
97
+ base: {
98
+ color: '#d4d4d4'
99
+ }
100
+ };
101
+ }
102
+ }
103
+ //# sourceMappingURL=style-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["hexToRgb","hex","replace","length","result","exec","r","Number","parseInt","g","b","normalizeColor","color","startsWith","rgb","convertTokenColorsToReactStyle","tokenColors","styleMap","forEach","token","settings","scope","default","foreground","backgroundColor","background","scopes","Array","isArray","style","fontStyle","includes","fontWeight","getRNStylesFromShikiStyle","theme","styles","editor","colors","base","tokenStyles","Object","assign"],"sourceRoot":"../../../src","sources":["utils/style-transformer.ts"],"mappings":";;;;;;;AASA,SAASA,QAAQA,CAACC,GAAW,EAA8C;EACzE;EACAA,GAAG,GAAGA,GAAG,CAACC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;;EAE3B;EACA,IAAID,GAAG,CAACE,MAAM,KAAK,CAAC,EAAE;IACpBF,GAAG,GAAG,GAAGA,GAAG,CAAC,CAAC,CAAC,GAAGA,GAAG,CAAC,CAAC,CAAC,GAAGA,GAAG,CAAC,CAAC,CAAC,GAAGA,GAAG,CAAC,CAAC,CAAC,GAAGA,GAAG,CAAC,CAAC,CAAC,GAAGA,GAAG,CAAC,CAAC,CAAC,EAAE;EAChE;EAEA,MAAMG,MAAM,GAAG,yCAAyC,CAACC,IAAI,CAACJ,GAAG,CAAC;EAClE,OAAOG,MAAM,GACT;IACEE,CAAC,EAAEC,MAAM,CAACC,QAAQ,CAACJ,MAAM,CAAC,CAAC,CAAC,EAAG,EAAE,CAAC;IAClCK,CAAC,EAAEF,MAAM,CAACC,QAAQ,CAACJ,MAAM,CAAC,CAAC,CAAC,EAAG,EAAE,CAAC;IAClCM,CAAC,EAAEH,MAAM,CAACC,QAAQ,CAACJ,MAAM,CAAC,CAAC,CAAC,EAAG,EAAE;EACnC,CAAC,GACD,IAAI;AACV;AAEA,SAASO,cAAcA,CAACC,KAAyB,EAAU;EACzD,IAAI,CAACA,KAAK,EACR,OAAO,aAAa;;EAEtB;EACA,IAAIA,KAAK,CAACC,UAAU,CAAC,GAAG,CAAC,EAAE;IACzB,MAAMC,GAAG,GAAGd,QAAQ,CAACY,KAAK,CAAC;IAC3B,IAAIE,GAAG,EAAE;MACP,OAAO,OAA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