rn-shiki 0.0.37-20 → 0.0.37-22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) 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 +1 -1
  36. package/src/components/syntax/SyntaxHighlighter.tsx +62 -28
  37. package/src/utils/string.ts +1 -1
  38. package/lib/commonjs/components/syntax/SyntaxLine.js +0 -36
  39. package/lib/commonjs/components/syntax/SyntaxLine.js.map +0 -1
  40. package/lib/commonjs/components/syntax/index.js +0 -21
  41. package/lib/commonjs/components/syntax/index.js.map +0 -1
  42. package/lib/commonjs/syntax/highlighter/index.js.map +0 -1
  43. package/lib/commonjs/syntax/index.js +0 -19
  44. package/lib/commonjs/syntax/index.js.map +0 -1
  45. package/lib/commonjs/types/index.js +0 -2
  46. package/lib/commonjs/types/index.js.map +0 -1
  47. package/lib/commonjs/types/shiki.d.js +0 -6
  48. package/lib/commonjs/types/shiki.d.js.map +0 -1
  49. package/lib/commonjs/utils/index.js +0 -17
  50. package/lib/commonjs/utils/index.js.map +0 -1
  51. package/lib/module/components/syntax/SyntaxLine.js +0 -31
  52. package/lib/module/components/syntax/SyntaxLine.js.map +0 -1
  53. package/lib/module/components/syntax/index.js +0 -5
  54. package/lib/module/components/syntax/index.js.map +0 -1
  55. package/lib/module/syntax/highlighter/index.js +0 -34
  56. package/lib/module/syntax/highlighter/index.js.map +0 -1
  57. package/lib/module/syntax/index.js +0 -4
  58. package/lib/module/syntax/index.js.map +0 -1
  59. package/lib/module/types/index.js +0 -2
  60. package/lib/module/types/index.js.map +0 -1
  61. package/lib/module/types/shiki.d.js +0 -4
  62. package/lib/module/types/shiki.d.js.map +0 -1
  63. package/lib/module/utils/index.js +0 -4
  64. package/lib/module/utils/index.js.map +0 -1
  65. package/lib/typescript/components/syntax/SyntaxLine.d.ts +0 -9
  66. package/lib/typescript/components/syntax/SyntaxLine.d.ts.map +0 -1
  67. package/lib/typescript/components/syntax/index.d.ts +0 -3
  68. package/lib/typescript/components/syntax/index.d.ts.map +0 -1
  69. package/lib/typescript/syntax/highlighter/index.d.ts.map +0 -1
  70. package/lib/typescript/syntax/index.d.ts +0 -2
  71. package/lib/typescript/syntax/index.d.ts.map +0 -1
  72. package/lib/typescript/types/index.d.ts +0 -7
  73. package/lib/typescript/types/index.d.ts.map +0 -1
  74. package/lib/typescript/utils/index.d.ts +0 -2
  75. package/lib/typescript/utils/index.d.ts.map +0 -1
@@ -4,76 +4,84 @@ 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
+ const styles = _reactNative.StyleSheet.create({
20
+ scrollView: {
21
+ flex: 1,
22
+ minHeight: 20
23
+ },
24
+ lineContainer: {
25
+ flexDirection: 'row',
26
+ flexWrap: 'wrap'
27
+ }
28
+ });
29
+ const SyntaxHighlighter = ({
15
30
  text,
16
- lang = _typescript.default,
17
- langName = 'typescript',
18
- theme = _githubDark.default,
19
- themeName = 'github-dark',
20
- fontSize
21
- }) {
31
+ language,
32
+ languageId,
33
+ theme
34
+ }) => {
35
+ console.log('theme:', theme);
36
+ const stylesheet = (0, _react.useMemo)(() => {
37
+ const styles = (0, _styleTransformer.getRNStylesFromShikiStyle)(theme);
38
+ console.log('Generated stylesheet:', styles);
39
+ return styles;
40
+ }, [theme]);
22
41
  const {
23
- tokens,
24
- error,
25
- isLoading
42
+ tokens
26
43
  } = (0, _useSyntaxHighlighter.useSyntaxHighlighter)({
27
44
  text,
28
- lang,
29
- langName,
30
- theme,
31
- themeName
45
+ language,
46
+ languageId,
47
+ theme
32
48
  });
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]
41
- });
42
- }
43
- if (isLoading) {
49
+ const renderToken = (token, index, lineIndex) => {
50
+ // Ensure to collect all styles associated with the token's scopes
51
+ const tokenScopes = Array.isArray(token.scope) ? token.scope : [token.scope];
52
+ const tokenStylesArray = tokenScopes.map(scope => stylesheet[scope] || {});
53
+ const combinedStyles = _reactNative.StyleSheet.flatten([...tokenStylesArray, {
54
+ fontFamily: monospaceFont,
55
+ ...(token.color && {
56
+ color: token.color
57
+ }),
58
+ ...(token.fontStyle === 'italic' && stylesheet.italic),
59
+ ...(token.fontWeight === 'bold' && stylesheet.bold)
60
+ }]);
61
+ console.log(`Rendering token: ${token.content}, styles:`, combinedStyles);
44
62
  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}`))
63
+ style: combinedStyles,
64
+ children: token.content.replace(/ /g, '\u00A0')
65
+ }, `${lineIndex}-${index}`);
66
+ };
67
+
68
+ // In the renderLine and renderToken flow
69
+ const renderLine = (line, lineIndex) => {
70
+ console.log(`Rendering line ${lineIndex}:`, line);
71
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
72
+ style: styles.lineContainer,
73
+ children: line.map((token, tokenIndex) => renderToken(token, tokenIndex, lineIndex))
74
+ }, lineIndex);
75
+ };
76
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, {
77
+ horizontal: true,
78
+ showsHorizontalScrollIndicator: _reactNative.Platform.OS !== 'web',
79
+ style: styles.scrollView,
80
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
81
+ onStartShouldSetResponder: () => true,
82
+ children: tokens.map((line, index) => renderLine(line, index))
83
+ })
76
84
  });
77
- }
85
+ };
78
86
  var _default = exports.default = SyntaxHighlighter;
79
87
  //# 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,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,qBAAA,GAAAJ,OAAA;AAAuE,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAWvE,SAASG,iBAAiBA,CAAC;EAAEC,IAAI;EAAEC,IAAI,GAAGC,mBAAU;EAAEC,QAAQ,GAAG,YAAY;EAAEC,KAAK,GAAGC,mBAAU;EAAEC,SAAS,GAAG,aAAa;EAAEC;AAAiC,CAAC,EAAE;EAChK,MAAM;IAAEC,MAAM;IAAEC,KAAK;IAAEC;EAAU,CAAC,GAAG,IAAAC,0CAAoB,EAAC;IACxDX,IAAI;IACJC,IAAI;IACJE,QAAQ;IACRC,KAAK;IACLE;EACF,CAAC,CAAC;EAEF,IAAIG,KAAK,EAAE;IACT,oBACE,IAAAd,WAAA,CAAAiB,IAAA,EAACrB,YAAA,CAAAsB,IAAI;MAACC,KAAK,EAAE;QAAEC,KAAK,EAAE,SAAS;QAAEC,UAAU,EAAE,WAAW;QAAET;MAAS,CAA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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","styles","StyleSheet","create","scrollView","flex","minHeight","lineContainer","flexDirection","flexWrap","SyntaxHighlighter","text","language","languageId","theme","console","log","stylesheet","useMemo","getRNStylesFromShikiStyle","tokens","useSyntaxHighlighter","renderToken","token","index","lineIndex","tokenScopes","Array","isArray","scope","tokenStylesArray","map","combinedStyles","flatten","fontFamily","color","fontStyle","italic","fontWeight","bold","content","jsx","Text","style","children","replace","renderLine","line","View","tokenIndex","ScrollView","horizontal","showsHorizontalScrollIndicator","OS","onStartShouldSetResponder","_default","exports"],"sourceRoot":"../../../../src","sources":["components/syntax/SyntaxHighlighter.tsx"],"mappings":";;;;;;AAEA,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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ACvDrB,KAAK,CAACiB,OAAO,CAACK,OAAO,CAAC,IAAI,EAAE,QAAQ;IAAC,GAD7B,GAAGpB,SAAS,IAAID,KAAK,EAE1B,CAAC;EAEX,CAAC;;EAED;EACA,MAAMsB,UAAU,GAAGA,CAACC,IAAW,EAAEtB,SAAiB,KAAK;IACrDV,OAAO,CAACC,GAAG,CAAC,kBAAkBS,SAAS,GAAG,EAAEsB,IAAI,CAAC;IACjD,oBACE,IAAAxE,WAAA,CAAAkE,GAAA,EAACrE,YAAA,CAAA4E,IAAI;MAAiBL,KAAK,EAAE1C,MAAM,CAACM,aAAc;MAAAqC,QAAA,EAC/CG,IAAI,CAAChB,GAAG,CAAC,CAACR,KAAK,EAAE0B,UAAU,KAAK3B,WAAW,CAACC,KAAK,EAAE0B,UAAU,EAAExB,SAAS,CAAC;IAAC,GADlEA,SAEL,CAAC;EAEX,CAAC;EAED,oBACE,IAAAlD,WAAA,CAAAkE,GAAA,EAACrE,YAAA,CAAA8E,UAAU;IAACC,UAAU;IAACC,8BAA8B,EAAEvD,qBAAQ,CAACwD,EAAE,KAAK,KAAM;IAACV,KAAK,EAAE1C,MAAM,CAACG,UAAW;IAAAwC,QAAA,eACrG,IAAArE,WAAA,CAAAkE,GAAA,EAACrE,YAAA,CAAA4E,IAAI;MAACM,yBAAyB,EAAEA,CAAA,KAAM,IAAK;MAAAV,QAAA,EAAExB,MAAM,CAACW,GAAG,CAAC,CAACgB,IAAI,EAAEvB,KAAK,KAAKsB,UAAU,CAACC,IAAI,EAAEvB,KAAK,CAAC;IAAC,CAAO;EAAC,CAChG,CAAC;AAEjB,CAAC;AAAA,IAAA+B,QAAA,GAAAC,OAAA,CAAA1E,OAAA,GAEc4B,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","sources":["hooks/useSyntaxHighlighter.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEO,SAASE,oBAAoBA,CAAC;EAAEC,IAAI;EAAEC,IAAI;EAAEC,QAAQ;EAAEC,KAAK;EAAEC;AAAkC,CAAC,EAAE;EACvG,MAAM,CAACC,MAAM,EAAEC,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XD,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,CAACb,IAAI,EAAE;QACTU,YAAY,CAAC,KAAK,CAAC;QACnBL,SAAS,CAAC,EAAE,CAAC;QACb;MACF;MAEA,IAAI;QACF;QACA,MAAMS,WAAW,GAAG,MAAM,IAAAC,8BAAiB,EAAC;UAC1CC,KAAK,EAAE,CAACf,QAAQ,CAAC;UACjBgB,MAAM,EAAE,CAACd,KAAK;QAChB,CAAC,CAAC;;QAEF;QACA,MAAMe,aAAa,GAAGJ,WAAW,CAACK,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,CAACD,aAAa,EAAE;UAClB,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;QAC5C;;QAEA;QACA,MAAMC,MAAM,GAAGP,WAAW,CAACQ,YAAY,CAACtB,IAAI,EAAE;UAC5CuB,IAAI,EAAErB,UAAU;UAChBC,KAAK,EAAEe;QACT,CAAC,CAAiB;QAElB,IAAIN,OAAO,IAAIS,MAAM,CAACjB,MAAM,EAAE;UAC5BC,SAAS,CAACgB,MAAM,CAACjB,MAAM,CAAC;UACxBI,QAAQ,CAACgB,SAAS,CAAC;QACrB;MACF,CAAC,CACD,OAAOC,GAAG,EAAE;QACVC,OAAO,CAACnB,KAAK,CAAC,qBAAqB,EAAEkB,GAAG,CAAC;QACzC,IAAIb,OAAO,EAAE;UACXJ,QAAQ,CAACiB,GAAG,YAAYL,KAAK,GAAGK,GAAG,CAACE,OAAO,GAAG,4BAA4B,CAAC;UAC3EtB,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,CAACZ,IAAI,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,KAAK,CAAC,CAAC;EAEvC,OAAO;IAAEC,MAAM;IAAEG,KAAK;IAAEE;EAAU,CAAC;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
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;IACF,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,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertTokenColorsToReactStyle = convertTokenColorsToReactStyle;
7
+ exports.getRNStylesFromShikiStyle = getRNStylesFromShikiStyle;
8
+ var _cssToReactNative = _interopRequireDefault(require("css-to-react-native"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ // Helper function to convert hex color to RGB
11
+ function hexToRgb(hex) {
12
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
13
+ return result ? {
14
+ r: Number.parseInt(result[1], 16),
15
+ g: Number.parseInt(result[2], 16),
16
+ b: Number.parseInt(result[3], 16)
17
+ } : null;
18
+ }
19
+
20
+ // Helper function to normalize color values
21
+ function normalizeColor(color) {
22
+ if (!color) return 'transparent';
23
+
24
+ // Type guard to ensure color is string before we call string methods
25
+ if (typeof color === 'string' && color.startsWith('#')) {
26
+ const rgb = hexToRgb(color);
27
+ if (rgb) {
28
+ return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
29
+ }
30
+ }
31
+ return color;
32
+ }
33
+ function convertTokenColorsToReactStyle(tokenColors) {
34
+ const styleMap = {};
35
+
36
+ // Add default styles
37
+ styleMap.default = {
38
+ color: '#e1e4e8',
39
+ backgroundColor: 'transparent'
40
+ };
41
+ tokenColors.forEach(token => {
42
+ if (!token.settings || !token.scope) return;
43
+ const scopes = Array.isArray(token.scope) ? token.scope : [token.scope];
44
+ const styleEntries = [];
45
+
46
+ // Only add styles if they exist
47
+ if (token.settings.foreground) {
48
+ styleEntries.push(['color', normalizeColor(token.settings.foreground)]);
49
+ }
50
+ if (token.settings.background) {
51
+ styleEntries.push(['backgroundColor', normalizeColor(token.settings.background)]);
52
+ }
53
+ if (token.settings.fontStyle) {
54
+ if (token.settings.fontStyle.includes('italic')) {
55
+ styleEntries.push(['fontStyle', 'italic']);
56
+ }
57
+ if (token.settings.fontStyle.includes('bold')) {
58
+ styleEntries.push(['fontWeight', 'bold']);
59
+ }
60
+ }
61
+ if (styleEntries.length > 0) {
62
+ const transformedStyle = (0, _cssToReactNative.default)(styleEntries);
63
+ scopes.forEach(scope => {
64
+ if (typeof scope === 'string') {
65
+ styleMap[scope] = {
66
+ ...(styleMap[scope] || {}),
67
+ ...transformedStyle
68
+ };
69
+ }
70
+ });
71
+ }
72
+ });
73
+ return styleMap;
74
+ }
75
+ function getRNStylesFromShikiStyle(theme) {
76
+ if (!theme || !theme.tokenColors) {
77
+ console.error('Provided theme does not contain \'tokenColors\'.');
78
+ return {};
79
+ }
80
+ try {
81
+ // Convert theme colors to React Native styles
82
+ const styles = convertTokenColorsToReactStyle(theme.tokenColors);
83
+
84
+ // Add theme-specific base styles if they exist
85
+ if (theme.colors) {
86
+ styles.base = {
87
+ color: normalizeColor(theme.colors['editor.foreground']),
88
+ backgroundColor: normalizeColor(theme.colors['editor.background'])
89
+ };
90
+ }
91
+ return styles;
92
+ } catch {
93
+ console.error('Error converting theme styles');
94
+ return {};
95
+ }
96
+ }
97
+ //# sourceMappingURL=style-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_cssToReactNative","_interopRequireDefault","require","e","__esModule","default","hexToRgb","hex","result","exec","r","Number","parseInt","g","b","normalizeColor","color","startsWith","rgb","convertTokenColorsToReactStyle","tokenColors","styleMap","backgroundColor","forEach","token","settings","scope","scopes","Array","isArray","styleEntries","foreground","push","background","fontStyle","includes","length","transformedStyle","transform","getRNStylesFromShikiStyle","theme","console","error","styles","colors","base"],"sourceRoot":"../../../src","sources":["utils/style-transformer.ts"],"mappings":";;;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA2C,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAQ3C;AACA,SAASG,QAAQA,CAACC,GAAW,EAA8C;EACzE,MAAMC,MAAM,GAAG,2CAA2C,CAACC,IAAI,CAACF,GAAG,CAAC;EACpE,OAAOC,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;AACA,SAASO,cAAcA,CAACC,KAAyB,EAAU;EACzD,IAAI,CAACA,KAAK,EACR,OAAO,aAAa;;EAEtB;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,UAAU,CAAC,GAAG,CAAC,EAAE;IACtD,MAAMC,GAAG,GAAGZ,QAAQ,CAACU,KAAK,CAAC;IAC3B,IAAIE,GAAG,EAAE;MACP,OAAO,OAAOA,GAAG,CAACR,CAAC,KAAKQ,GAAG,CAACL,CAAC,KAAKK,GAAG,CAACJ,CAAC,GAAG;IAC5C;EACF;EACA,OAAOE,KAAK;AACd;AAEO,SAASG,8BAA8BA,CAACC,WAAkB,EAAc;EAC7E,MAAMC,QAAoB,GAAG,CAAC,CAAC;;EAE/B;EACAA,QAAQ,CAAChB,OAAO,GAAG;IACjBW,KAAK,EAAE,SAAS;IAChBM,eAAe,EAAE;EACnB,CAAC;EAEDF,WAAW,CAACG,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G;YAAE,IAAIL,QAAQ,CAACK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAAE,GAAGW;UAAiB,CAAC;QACvE;MACF,CAAC,CAAC;IACJ;EACF,CAAC,CAAC;EAEF,OAAOhB,QAAQ;AACjB;AAEO,SAASkB,yBAAyBA,CAACC,KAAU,EAAyB;EAC3E,IAAI,CAACA,KAAK,IAAI,CAACA,KAAK,CAACpB,WAAW,EAAE;IAChCqB,OAAO,CAACC,KAAK,CAAC,kDAAkD,CAAC;IACjE,OAAO,CAAC,CAAC;EACX;EAEA,IAAI;IACF;IACA,MAAMC,MAAM,GAAGxB,8BAA8B,CAACqB,KAAK,CAACpB,WAAW,CAAC;;IAEhE;IACA,IAAIoB,KAAK,CAACI,MAAM,EAAE;MAChBD,MAAM,CAACE,IAAI,GAAG;QACZ7B,KAAK,EAAED,cAAc,CAACyB,KAAK,CAACI,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACxDtB,eAAe,EAAEP,cAAc,CAACyB,KAAK,CAACI,MAAM,CAAC,mBAAmB,CAAC;MACnE,CAAC;IACH;IAEA,OAAOD,MAAM;EACf,CAAC,CACD,MAAM;IACJF,OAAO,CAACC,KAAK,CAAC,+BAA+B,CAAC;IAC9C,OAAO,CAAC,CAAC;EACX;AACF","ignoreList":[]}
@@ -1,74 +1,81 @@
1
1
  "use strict";
2
2
 
3
- import React from 'react';
4
- import { Text, View } from 'react-native';
5
- import typescript from 'shiki/langs/typescript.mjs';
6
- import githubDark from 'shiki/themes/github-dark.mjs';
3
+ import React, { useMemo } from 'react';
4
+ import { Platform, ScrollView, StyleSheet, Text, View } from 'react-native';
7
5
  import { useSyntaxHighlighter } from '../../hooks/useSyntaxHighlighter';
8
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
9
- function SyntaxHighlighter({
6
+ import { getRNStylesFromShikiStyle } from '../../utils/style-transformer';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const monospaceFont = Platform.select({
9
+ ios: 'Menlo',
10
+ android: 'monospace',
11
+ default: 'monospace'
12
+ });
13
+ const styles = StyleSheet.create({
14
+ scrollView: {
15
+ flex: 1,
16
+ minHeight: 20
17
+ },
18
+ lineContainer: {
19
+ flexDirection: 'row',
20
+ flexWrap: 'wrap'
21
+ }
22
+ });
23
+ const SyntaxHighlighter = ({
10
24
  text,
11
- lang = typescript,
12
- langName = 'typescript',
13
- theme = githubDark,
14
- themeName = 'github-dark',
15
- fontSize
16
- }) {
25
+ language,
26
+ languageId,
27
+ theme
28
+ }) => {
29
+ console.log('theme:', theme);
30
+ const stylesheet = useMemo(() => {
31
+ const styles = getRNStylesFromShikiStyle(theme);
32
+ console.log('Generated stylesheet:', styles);
33
+ return styles;
34
+ }, [theme]);
17
35
  const {
18
- tokens,
19
- error,
20
- isLoading
36
+ tokens
21
37
  } = useSyntaxHighlighter({
22
38
  text,
23
- lang,
24
- langName,
25
- theme,
26
- themeName
39
+ language,
40
+ languageId,
41
+ theme
27
42
  });
28
- if (error) {
29
- return /*#__PURE__*/_jsxs(Text, {
30
- style: {
31
- color: '#ff6b6b',
32
- fontFamily: 'monospace',
33
- fontSize
34
- },
35
- children: ["Error:", error]
36
- });
37
- }
38
- if (isLoading) {
43
+ const renderToken = (token, index, lineIndex) => {
44
+ // Ensure to collect all styles associated with the token's scopes
45
+ const tokenScopes = Array.isArray(token.scope) ? token.scope : [token.scope];
46
+ const tokenStylesArray = tokenScopes.map(scope => stylesheet[scope] || {});
47
+ const combinedStyles = StyleSheet.flatten([...tokenStylesArray, {
48
+ fontFamily: monospaceFont,
49
+ ...(token.color && {
50
+ color: token.color
51
+ }),
52
+ ...(token.fontStyle === 'italic' && stylesheet.italic),
53
+ ...(token.fontWeight === 'bold' && stylesheet.bold)
54
+ }]);
55
+ console.log(`Rendering token: ${token.content}, styles:`, combinedStyles);
39
56
  return /*#__PURE__*/_jsx(Text, {
40
- style: {
41
- color: '#f8f8f2',
42
- fontFamily: 'monospace',
43
- fontSize
44
- },
45
- children: "Loading..."
46
- });
47
- }
48
- return /*#__PURE__*/_jsx(View, {
49
- children: tokens.map((line, lineIndex) => /*#__PURE__*/_jsxs(View, {
50
- style: {
51
- flexDirection: 'row',
52
- flexWrap: 'wrap'
53
- },
54
- children: [line.map((token, tokenIndex) => /*#__PURE__*/_jsx(Text, {
55
- style: {
56
- color: token.color || '#FFFFFF',
57
- fontFamily: 'monospace',
58
- fontSize,
59
- fontStyle: token.fontStyle
60
- },
61
- children: token.content.replace(/ /g, '\u00A0')
62
- }, `${lineIndex}-${tokenIndex}`)), /*#__PURE__*/_jsx(Text, {
63
- style: {
64
- color: '#FFFFFF',
65
- fontFamily: 'monospace',
66
- fontSize
67
- },
68
- children: '\n'
69
- })]
70
- }, `line-${lineIndex}`))
57
+ style: combinedStyles,
58
+ children: token.content.replace(/ /g, '\u00A0')
59
+ }, `${lineIndex}-${index}`);
60
+ };
61
+
62
+ // In the renderLine and renderToken flow
63
+ const renderLine = (line, lineIndex) => {
64
+ console.log(`Rendering line ${lineIndex}:`, line);
65
+ return /*#__PURE__*/_jsx(View, {
66
+ style: styles.lineContainer,
67
+ children: line.map((token, tokenIndex) => renderToken(token, tokenIndex, lineIndex))
68
+ }, lineIndex);
69
+ };
70
+ return /*#__PURE__*/_jsx(ScrollView, {
71
+ horizontal: true,
72
+ showsHorizontalScrollIndicator: Platform.OS !== 'web',
73
+ style: styles.scrollView,
74
+ children: /*#__PURE__*/_jsx(View, {
75
+ onStartShouldSetResponder: () => true,
76
+ children: tokens.map((line, index) => renderLine(line, index))
77
+ })
71
78
  });
72
- }
79
+ };
73
80
  export default SyntaxHighlighter;
74
81
  //# sourceMappingURL=SyntaxHighlighter.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","Text","View","typescript","githubDark","useSyntaxHighlighter","jsxs","_jsxs","jsx","_jsx","SyntaxHighlighter","text","lang","langName","theme","themeName","fontSize","tokens","error","isLoading","style","color","fontFamily","children","map","line","lineIndex","flexDirection","flexWrap","token","tokenIndex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O,CAAE;MAAAL,QAAA,GAC/EE,IAAI,CAACD,GAAG,CAAC,CAACK,KAAK,EAAEC,UAAU,kBAC1BrB,IAAA,CAACR,IAAI;QAEHmB,KAAK,EAAE;UACLC,KAAK,EAAEQ,KAAK,CAACR,KAAK,IAAI,SAAS;UAC/BC,UAAU,EAAE,WAAW;UACvBN,QAAQ;UACRe,SAAS,EAAEF,KAAK,CAACE;QACnB,CAAE;QAAAR,QAAA,EAEDM,KAAK,CAACG,OAAO,CAACC,OAAO,CAAC,IAAI,EAAE,QAAQ;MAAC,GARjC,GAAGP,SAAS,IAAII,UAAU,EAS3B,CACP,CAAC,eACFrB,IAAA,CAACR,IAAI;QAACmB,KAAK,EAAE;UAAEC,KAAK,EAAE,SAAS;UAAEC,UAAU,EAAE,WAAW;UAAEN;QAAS,CAAE;QAAAO,QAAA,EAAE;MAAI,CAAO,CAAC;IAAA,GAd1E,QAAQG,SAAS,EAetB,CACP;EAAC,CACE,CAAC;AAEX;AAEA,eAAehB,iBAAiB","ignoreList":[]}
1
+ {"version":3,"names":["React","useMemo","Platform","ScrollView","StyleSheet","Text","View","useSyntaxHighlighter","getRNStylesFromShikiStyle","jsx","_jsx","monospaceFont","select","ios","android","default","styles","create","scrollView","flex","minHeight","lineContainer","flexDirection","flexWrap","SyntaxHighlighter","text","language","languageId","theme","console","log","stylesheet","tokens","renderToken","token","index","lineIndex","tokenScopes","Array","isArray","scope","tokenStylesArray","map","combinedStyles","flatten","fontFamily","color","fontStyle","italic","fontWeight","bold","content","style","children","replace","renderLine","line","tokenIndex","horizontal","showsHorizontalScrollIndicator","OS","onStartShouldSetResponder"],"sourceRoot":"../../../../src","sources":["components/syntax/SyntaxHighlighter.tsx"],"mappings":";;AAEA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,QAAQ,EAAEC,UAAU,EAAEC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAC3E,SAASC,oBAAoB,QAAQ,kCAAk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