rn-shiki 0.0.37-27 → 0.0.37-28

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,28 +16,54 @@ const monospaceFont = _reactNative.Platform.select({
16
16
  android: 'monospace',
17
17
  default: 'monospace'
18
18
  });
19
- const styles = _reactNative.StyleSheet.create({
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({
20
27
  scrollView: {
21
28
  flex: 1,
22
29
  minHeight: 20
23
30
  },
24
31
  lineContainer: {
25
32
  flexDirection: 'row',
26
- flexWrap: 'wrap'
33
+ flexWrap: 'wrap',
34
+ paddingHorizontal: 16,
35
+ paddingVertical: 8
36
+ },
37
+ token: {
38
+ fontFamily: monospaceFont,
39
+ fontSize: 14
40
+ },
41
+ container: {
42
+ flex: 1
27
43
  }
28
44
  });
29
45
  const SyntaxHighlighter = ({
30
46
  text,
31
47
  language,
32
48
  languageId,
33
- theme
49
+ theme,
50
+ fontSize = 14
34
51
  }) => {
35
- console.log('theme:', theme);
36
52
  const stylesheet = (0, _react.useMemo)(() => {
37
- const styles = (0, _styleTransformer.getRNStylesFromShikiStyle)(theme);
38
- console.log('Generated stylesheet:', styles);
39
- return styles;
40
- }, [theme]);
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]);
41
67
  const {
42
68
  tokens
43
69
  } = (0, _useSyntaxHighlighter.useSyntaxHighlighter)({
@@ -47,40 +73,46 @@ const SyntaxHighlighter = ({
47
73
  theme
48
74
  });
49
75
  const renderToken = (token, index, lineIndex) => {
50
- // Ensure to collect all styles associated with the token's scopes
76
+ const styles = [stylesheet.token];
77
+
78
+ // Add token-specific styles from stylesheet based on scope
51
79
  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);
80
+ tokenScopes.forEach(scope => {
81
+ if (stylesheet[scope]) {
82
+ styles.push(stylesheet[scope]);
83
+ }
84
+ });
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);
62
101
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
63
- style: combinedStyles,
102
+ style: finalStyle,
64
103
  children: token.content.replace(/ /g, '\u00A0')
65
104
  }, `${lineIndex}-${index}`);
66
105
  };
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
- };
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);
76
110
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, {
77
111
  horizontal: true,
78
112
  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
- })
113
+ style: [baseStyles.scrollView, stylesheet.editor],
114
+ contentContainerStyle: baseStyles.container,
115
+ children: tokens.map((line, index) => renderLine(line, index))
84
116
  });
85
117
  };
86
118
  var _default = exports.default = SyntaxHighlighter;
@@ -1 +1 @@
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,OAA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AAA,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":[]}
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,YAAA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MqB,UAAU,GAAGA,CAACC,IAAW,EAAErB,SAAiB,kBAChD,IAAA5D,WAAA,CAAA0E,GAAA,EAAC7E,YAAA,CAAAqF,IAAI;IAAiBN,KAAK,EAAEhD,UAAU,CAACM,aAAc;IAAA2C,QAAA,EACnDI,IAAI,CAACE,GAAG,CAAC,CAAC5C,KAAK,EAAE6C,UAAU,KAAK1B,WAAW,CAACnB,KAAK,EAAE6C,UAAU,EAAExB,SAAS,CAAC;EAAC,GADlEA,SAEL,CACP;EAED,oBACE,IAAA5D,WAAA,CAAA0E,GAAA,EAAC7E,YAAA,CAAAwF,UAAU;IAACC,UAAU;IAACC,8BAA8B,EAAEjE,qBAAQ,CAACkE,EAAE,KAAK,KAAM;IAACZ,KAAK,EAAE,CAAChD,UAAU,CAACG,UAAU,EAAEgB,UAAU,CAACK,MAAM,CAAE;IAACqC,qBAAqB,EAAE7D,UAAU,CAACc,SAAU;IAAAmC,QAAA,EAC1KrB,MAAM,CAAC2B,GAAG,CAAC,CAACF,IAAI,EAAEtB,KAAK,KAAKqB,UAAU,CAACC,IAAI,EAAEtB,KAAK,CAAC;EAAC,CAC3C,CAAC;AAEjB,CAAC;AAAA,IAAA+B,QAAA,GAAAC,OAAA,CAAApF,OAAA,GAEcoC,iBAAiB","ignoreList":[]}
@@ -17,7 +17,7 @@ async function initializeHighlighter(langs, themes) {
17
17
  return await (0, _core.createHighlighterCore)({
18
18
  langs,
19
19
  themes,
20
- engine
20
+ engine // Pass the configured engine
21
21
  });
22
22
  } catch (err) {
23
23
  console.error('Error initializing highlighter:', err);
@@ -1 +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":[]}
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":[]}
@@ -5,24 +5,26 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.convertTokenColorsToReactStyle = convertTokenColorsToReactStyle;
7
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
8
  function hexToRgb(hex) {
12
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(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);
13
17
  return result ? {
14
18
  r: Number.parseInt(result[1], 16),
15
19
  g: Number.parseInt(result[2], 16),
16
20
  b: Number.parseInt(result[3], 16)
17
21
  } : null;
18
22
  }
19
-
20
- // Helper function to normalize color values
21
23
  function normalizeColor(color) {
22
24
  if (!color) return 'transparent';
23
25
 
24
- // Type guard to ensure color is string before we call string methods
25
- if (typeof color === 'string' && color.startsWith('#')) {
26
+ // Handle hex colors
27
+ if (color.startsWith('#')) {
26
28
  const rgb = hexToRgb(color);
27
29
  if (rgb) {
28
30
  return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
@@ -31,67 +33,71 @@ function normalizeColor(color) {
31
33
  return color;
32
34
  }
33
35
  function convertTokenColorsToReactStyle(tokenColors) {
36
+ if (!tokenColors) return {};
34
37
  const styleMap = {};
35
-
36
- // Add default styles
37
- styleMap.default = {
38
- color: '#e1e4e8',
39
- backgroundColor: 'transparent'
40
- };
41
38
  tokenColors.forEach(token => {
42
- if (!token.settings || !token.scope) return;
43
- const scopes = Array.isArray(token.scope) ? token.scope : [token.scope];
44
- const styleEntries = [];
39
+ if (!token.settings) return;
45
40
 
46
- // Only add styles if they exist
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 = {};
47
51
  if (token.settings.foreground) {
48
- styleEntries.push(['color', normalizeColor(token.settings.foreground)]);
52
+ style.color = normalizeColor(token.settings.foreground);
49
53
  }
50
54
  if (token.settings.background) {
51
- styleEntries.push(['backgroundColor', normalizeColor(token.settings.background)]);
55
+ style.backgroundColor = normalizeColor(token.settings.background);
52
56
  }
53
57
  if (token.settings.fontStyle) {
54
58
  if (token.settings.fontStyle.includes('italic')) {
55
- styleEntries.push(['fontStyle', 'italic']);
59
+ style.fontStyle = 'italic';
56
60
  }
57
61
  if (token.settings.fontStyle.includes('bold')) {
58
- styleEntries.push(['fontWeight', 'bold']);
62
+ style.fontWeight = 'bold';
59
63
  }
60
64
  }
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
- }
65
+ scopes.forEach(scope => {
66
+ styleMap[scope] = {
67
+ ...(styleMap[scope] || {}),
68
+ ...style
69
+ };
70
+ });
72
71
  });
73
72
  return styleMap;
74
73
  }
75
74
  function getRNStylesFromShikiStyle(theme) {
76
- if (!theme || !theme.tokenColors) {
77
- console.error('Provided theme does not contain \'tokenColors\'.');
78
- return {};
79
- }
75
+ if (!theme) return {};
80
76
  try {
81
- // Convert theme colors to React Native styles
82
- const styles = convertTokenColorsToReactStyle(theme.tokenColors);
77
+ const styles = {
78
+ editor: {
79
+ backgroundColor: normalizeColor(theme.colors?.['editor.background'])
80
+ },
81
+ base: {
82
+ color: normalizeColor(theme.colors?.['editor.foreground'])
83
+ }
84
+ };
83
85
 
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
- };
86
+ // Process token colors
87
+ if (theme.tokenColors) {
88
+ const tokenStyles = convertTokenColorsToReactStyle(theme.tokenColors);
89
+ Object.assign(styles, tokenStyles);
90
90
  }
91
91
  return styles;
92
92
  } catch {
93
- console.error('Error converting theme styles');
94
- return {};
93
+ return {
94
+ editor: {
95
+ backgroundColor: '#1e1e1e'
96
+ },
97
+ base: {
98
+ color: '#d4d4d4'
99
+ }
100
+ };
95
101
  }
96
102
  }
97
103
  //# sourceMappingURL=style-transformer.js.map
@@ -1 +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,CAA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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
+ {"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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,MAAM,CAACN,MAAM,EAAEI,WAAW,CAAC;IACpC;IAEA,OAAOJ,MAAM;EACf,CAAC,CACD,MAAM;IACJ,OAAO;MACLC,MAAM,EAAE;QAAEZ,eAAe,EAAE;MAAU,CAAC;MACtCc,IAAI,EAAE;QAAE1B,KAAK,EAAE;MAAU;IAC3B,CAAC;EACH;AACF","ignoreList":[]}
@@ -10,28 +10,54 @@ const monospaceFont = Platform.select({
10
10
  android: 'monospace',
11
11
  default: 'monospace'
12
12
  });
13
- const styles = StyleSheet.create({
13
+ // Helper function to extract theme registration from Shiki theme input
14
+ function getThemeRegistration(theme) {
15
+ if ('default' in theme) {
16
+ return theme.default;
17
+ }
18
+ return theme;
19
+ }
20
+ const baseStyles = StyleSheet.create({
14
21
  scrollView: {
15
22
  flex: 1,
16
23
  minHeight: 20
17
24
  },
18
25
  lineContainer: {
19
26
  flexDirection: 'row',
20
- flexWrap: 'wrap'
27
+ flexWrap: 'wrap',
28
+ paddingHorizontal: 16,
29
+ paddingVertical: 8
30
+ },
31
+ token: {
32
+ fontFamily: monospaceFont,
33
+ fontSize: 14
34
+ },
35
+ container: {
36
+ flex: 1
21
37
  }
22
38
  });
23
39
  const SyntaxHighlighter = ({
24
40
  text,
25
41
  language,
26
42
  languageId,
27
- theme
43
+ theme,
44
+ fontSize = 14
28
45
  }) => {
29
- console.log('theme:', theme);
30
46
  const stylesheet = useMemo(() => {
31
- const styles = getRNStylesFromShikiStyle(theme);
32
- console.log('Generated stylesheet:', styles);
33
- return styles;
34
- }, [theme]);
47
+ const themeRegistration = getThemeRegistration(theme);
48
+ const styles = getRNStylesFromShikiStyle(themeRegistration);
49
+ return StyleSheet.create({
50
+ ...styles,
51
+ editor: {
52
+ backgroundColor: themeRegistration.colors?.['editor.background'] || '#1e1e1e'
53
+ },
54
+ token: {
55
+ ...baseStyles.token,
56
+ fontSize,
57
+ color: themeRegistration.colors?.['editor.foreground'] || '#d4d4d4'
58
+ }
59
+ });
60
+ }, [theme, fontSize]);
35
61
  const {
36
62
  tokens
37
63
  } = useSyntaxHighlighter({
@@ -41,40 +67,46 @@ const SyntaxHighlighter = ({
41
67
  theme
42
68
  });
43
69
  const renderToken = (token, index, lineIndex) => {
44
- // Ensure to collect all styles associated with the token's scopes
70
+ const styles = [stylesheet.token];
71
+
72
+ // Add token-specific styles from stylesheet based on scope
45
73
  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);
74
+ tokenScopes.forEach(scope => {
75
+ if (stylesheet[scope]) {
76
+ styles.push(stylesheet[scope]);
77
+ }
78
+ });
79
+
80
+ // Add token-specific styles from the token itself
81
+ const tokenStyles = {};
82
+ if (token.color) {
83
+ tokenStyles.color = token.color;
84
+ }
85
+ if (token.fontStyle === 'italic') {
86
+ tokenStyles.fontStyle = 'italic';
87
+ }
88
+ if (token.fontWeight === 'bold') {
89
+ tokenStyles.fontWeight = 'bold';
90
+ }
91
+ if (Object.keys(tokenStyles).length > 0) {
92
+ styles.push(tokenStyles);
93
+ }
94
+ const finalStyle = StyleSheet.flatten(styles);
56
95
  return /*#__PURE__*/_jsx(Text, {
57
- style: combinedStyles,
96
+ style: finalStyle,
58
97
  children: token.content.replace(/ /g, '\u00A0')
59
98
  }, `${lineIndex}-${index}`);
60
99
  };
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
- };
100
+ const renderLine = (line, lineIndex) => /*#__PURE__*/_jsx(View, {
101
+ style: baseStyles.lineContainer,
102
+ children: line.map((token, tokenIndex) => renderToken(token, tokenIndex, lineIndex))
103
+ }, lineIndex);
70
104
  return /*#__PURE__*/_jsx(ScrollView, {
71
105
  horizontal: true,
72
106
  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
- })
107
+ style: [baseStyles.scrollView, stylesheet.editor],
108
+ contentContainerStyle: baseStyles.container,
109
+ children: tokens.map((line, index) => renderLine(line, index))
78
110
  });
79
111
  };
80
112
  export default SyntaxHighlighter;
@@ -1 +1 @@
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,kCAAkC;AACvE,SAASC,yBAAyB,QAAQ,+BAA+B;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAEzE,MAAMC,aAAa,GAAGT,QAAQ,CAACU,MAAM,CAAC;EACpCC,GAAG,EAAE,OAAO;EACZC,OAAO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AAK,CAAC;IAAC,CAAO;EAAC,CAChG,CAAC;AAEjB,CAAC;AAED,eAAeX,iBAAiB","ignoreList":[]}
1
+ {"version":3,"names":["React","useMemo","Platform","ScrollView","StyleSheet","Text","View","useSyntaxHighlighter","getRNStylesFromShikiStyle","jsx","_jsx","monospaceFont","select","ios","android","default","getThemeRegistration","theme","baseStyles","create","scrollView","flex","minHeight","lineContainer","flexDirection","flexWrap","paddingHorizontal","paddingVertical","token","fontFamily","fontSize","container","SyntaxHighlighter","text","language","languageId","stylesheet","themeRegistration","styles","editor","backgroundColor","colors","color","tokens","renderToken","index","lineIndex","tokenScopes","Array","isArray","scope","forEach","push","tokenStyles","fontStyle","fontWeight","Object","keys","length","finalStyle","flatten","style","children","content","replace","renderLine","line","map","tokenIndex","horizontal","showsHorizontalScrollIndicator","OS","contentContainerStyle"],"sourceRoot":"../../../../src","sources":["components/syntax/SyntaxHighlighter.tsx"],"mappings":";;AAGA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,QAAQ,EAAEC,UAAU,EAAEC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAC3E,SAASC,oBAAoB,QAAQ,kCAAkC;AACvE,SAASC,yBAAyB,QAAQ,+BAA+B;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAEzE,MAAMC,aAAa,GAAGT,QAAQ,CAACU,MAAM,CAAC;EACpCC,GAAG,EAAE,OAAO;EACZC,OAAO,EAAE,WAAW;EACpBC,OAAO,EAAE;AACX,CAAC,CAAC;AAeF;AACA,SAASC,oBAAoBA,CAACC,KAAiB,EAAqB;EAClE,IAAI,SAAS,IAAIA,KAAK,EAAE;IACtB,OAAOA,KAAK,CAACF,OAAO;EACtB;EACA,OAAOE,KAAK;AACd;AAEA,MAAMC,UAAU,GAAGd,UAAU,CAACe,MAAM,CAAC;EACnCC,UAAU,EAAE;IACVC,IAAI,EAAE,CAAC;IACPC,SAAS,EAAE;EACb,CAAC;EACDC,aAA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AAEtB,SAAS,CAAC;EAAC,GADlEA,SAEL,CACP;EAED,oBACEpC,IAAA,CAACP,UAAU;IAACkE,UAAU;IAACC,8BAA8B,EAAEpE,QAAQ,CAACqE,EAAE,KAAK,KAAM;IAACV,KAAK,EAAE,CAAC3C,UAAU,CAACE,UAAU,EAAEgB,UAAU,CAACG,MAAM,CAAE;IAACiC,qBAAqB,EAAEtD,UAAU,CAACa,SAAU;IAAA+B,QAAA,EAC1KnB,MAAM,CAACwB,GAAG,CAAC,CAACD,IAAI,EAAErB,KAAK,KAAKoB,UAAU,CAACC,IAAI,EAAErB,KAAK,CAAC;EAAC,CAC3C,CAAC;AAEjB,CAAC;AAED,eAAeb,iBAAiB","ignoreList":[]}
@@ -12,7 +12,7 @@ async function initializeHighlighter(langs, themes) {
12
12
  return await createHighlighterCore({
13
13
  langs,
14
14
  themes,
15
- engine
15
+ engine // Pass the configured engine
16
16
  });
17
17
  } catch (err) {
18
18
  console.error('Error initializing highlighter:', err);
@@ -1 +1 @@
1
- {"version":3,"names":["createHighlighterCore","createJavaScriptRegexEngine","engine","forgiving","simulation","cache","Map","initializeHighlighter","langs","themes","err","console","error","createHighlighter","length","Error","highlighter","processTokens","tokens","map","token","content","color","fontStyle","toString"],"sourceRoot":"../../../src","sources":["syntax/highlighter.ts"],"mappings":";;AAEA,SAASA,qBAAqB,QAAQ,qBAAqB;AAC3D,SAASC,2BAA2B,QAAQ,kCAAkC;AAE9E,MAAMC,MAAM,GAAGD,2BAA2B,CAAC;EACzCE,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,MAAMT,qBAAqB,CAAC;MACjCQ,KAAK;MACLC,MAAM;MACNP;IACF,CAAC,CAAC;EACJ,CAAC,CACD,OAAOQ,GAAG,EAAE;IACVC,OAAO,CAACC,KAAK,CAAC,iCAAiC,EAAEF,GAAG,CAAC;IACrD,MAAMA,GAAG;EACX;AACF;AAEA,OAAO,eAAeG,iBAAiBA,CAAC;EAAEL,KAAK;EAAEC;AAAyD,CAAC,EAAE;EAC3G,IAAI,CAACD,KAAK,EAAEM,MAAM,EAAE;IAClB,MAAM,IAAIC,KAAK,CAAC,uDAAuD,CAAC;EAC1E;EAEA,IAAI;IACF,MAAMC,WAAW,GAAG,MAAMT,qBAAqB,CAACC,KAAK,EAAEC,MAAM,CAAC;IAC9D,OAAOO,WAAW;EACpB,CAAC,CACD,OAAOJ,KAAK,EAAE;IACZD,OAAO,CAACC,KAAK,CAAC,+BAA+B,EAAEA,KAAK,CAAC;IACrD,MAAMA,KAAK;EACb;AACF;AAEA,OAAO,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":[]}
1
+ {"version":3,"names":["createHighlighterCore","createJavaScriptRegexEngine","engine","forgiving","simulation","cache","Map","initializeHighlighter","langs","themes","err","console","error","createHighlighter","length","Error","highlighter","processTokens","tokens","map","token","content","color","fontStyle","toString"],"sourceRoot":"../../../src","sources":["syntax/highlighter.ts"],"mappings":";;AAEA,SAASA,qBAAqB,QAAQ,qBAAqB;AAC3D,SAASC,2BAA2B,QAAQ,kCAAkC;AAE9E,MAAMC,MAAM,GAAGD,2BAA2B,CAAC;EACzCE,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,MAAMT,qBAAqB,CAAC;MACjCQ,KAAK;MACLC,MAAM;MACNP,MAAM,CAAE;IACV,CAAC,CAAC;EACJ,CAAC,CACD,OAAOQ,GAAG,EAAE;IACVC,OAAO,CAACC,KAAK,CAAC,iCAAiC,EAAEF,GAAG,CAAC;IACrD,MAAMA,GAAG;EACX;AACF;AAEA,OAAO,eAAeG,iBAAiBA,CAAC;EAAEL,KAAK;EAAEC;AAAyD,CAAC,EAAE;EAC3G,IAAI,CAACD,KAAK,EAAEM,MAAM,EAAE;IAClB,MAAM,IAAIC,KAAK,CAAC,uDAAuD,CAAC;EAC1E;EAEA,IAAI;IACF,MAAMC,WAAW,GAAG,MAAMT,qBAAqB,CAACC,KAAK,EAAEC,MAAM,CAAC;IAC9D,OAAOO,WAAW;EACpB,CAAC,CACD,OAAOJ,KAAK,EAAE;IACZD,OAAO,CAACC,KAAK,CAAC,+BAA+B,EAAEA,KAAK,CAAC;IACrD,MAAMA,KAAK;EACb;AACF;AAEA,OAAO,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":[]}
@@ -1,22 +1,25 @@
1
1
  "use strict";
2
2
 
3
- import transform from 'css-to-react-native';
4
- // Helper function to convert hex color to RGB
5
3
  function hexToRgb(hex) {
6
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
4
+ // Remove # if present
5
+ hex = hex.replace(/^#/, '');
6
+
7
+ // Handle both 3 and 6 digit hex
8
+ if (hex.length === 3) {
9
+ hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
10
+ }
11
+ const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
7
12
  return result ? {
8
13
  r: Number.parseInt(result[1], 16),
9
14
  g: Number.parseInt(result[2], 16),
10
15
  b: Number.parseInt(result[3], 16)
11
16
  } : null;
12
17
  }
13
-
14
- // Helper function to normalize color values
15
18
  function normalizeColor(color) {
16
19
  if (!color) return 'transparent';
17
20
 
18
- // Type guard to ensure color is string before we call string methods
19
- if (typeof color === 'string' && color.startsWith('#')) {
21
+ // Handle hex colors
22
+ if (color.startsWith('#')) {
20
23
  const rgb = hexToRgb(color);
21
24
  if (rgb) {
22
25
  return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
@@ -25,67 +28,71 @@ function normalizeColor(color) {
25
28
  return color;
26
29
  }
27
30
  export function convertTokenColorsToReactStyle(tokenColors) {
31
+ if (!tokenColors) return {};
28
32
  const styleMap = {};
29
-
30
- // Add default styles
31
- styleMap.default = {
32
- color: '#e1e4e8',
33
- backgroundColor: 'transparent'
34
- };
35
33
  tokenColors.forEach(token => {
36
- if (!token.settings || !token.scope) return;
37
- const scopes = Array.isArray(token.scope) ? token.scope : [token.scope];
38
- const styleEntries = [];
34
+ if (!token.settings) return;
39
35
 
40
- // Only add styles if they exist
36
+ // Handle global theme settings
37
+ if (!token.scope) {
38
+ styleMap.default = {
39
+ color: normalizeColor(token.settings.foreground),
40
+ backgroundColor: normalizeColor(token.settings.background)
41
+ };
42
+ return;
43
+ }
44
+ const scopes = Array.isArray(token.scope) ? token.scope : [token.scope];
45
+ const style = {};
41
46
  if (token.settings.foreground) {
42
- styleEntries.push(['color', normalizeColor(token.settings.foreground)]);
47
+ style.color = normalizeColor(token.settings.foreground);
43
48
  }
44
49
  if (token.settings.background) {
45
- styleEntries.push(['backgroundColor', normalizeColor(token.settings.background)]);
50
+ style.backgroundColor = normalizeColor(token.settings.background);
46
51
  }
47
52
  if (token.settings.fontStyle) {
48
53
  if (token.settings.fontStyle.includes('italic')) {
49
- styleEntries.push(['fontStyle', 'italic']);
54
+ style.fontStyle = 'italic';
50
55
  }
51
56
  if (token.settings.fontStyle.includes('bold')) {
52
- styleEntries.push(['fontWeight', 'bold']);
57
+ style.fontWeight = 'bold';
53
58
  }
54
59
  }
55
- if (styleEntries.length > 0) {
56
- const transformedStyle = transform(styleEntries);
57
- scopes.forEach(scope => {
58
- if (typeof scope === 'string') {
59
- styleMap[scope] = {
60
- ...(styleMap[scope] || {}),
61
- ...transformedStyle
62
- };
63
- }
64
- });
65
- }
60
+ scopes.forEach(scope => {
61
+ styleMap[scope] = {
62
+ ...(styleMap[scope] || {}),
63
+ ...style
64
+ };
65
+ });
66
66
  });
67
67
  return styleMap;
68
68
  }
69
69
  export function getRNStylesFromShikiStyle(theme) {
70
- if (!theme || !theme.tokenColors) {
71
- console.error('Provided theme does not contain \'tokenColors\'.');
72
- return {};
73
- }
70
+ if (!theme) return {};
74
71
  try {
75
- // Convert theme colors to React Native styles
76
- const styles = convertTokenColorsToReactStyle(theme.tokenColors);
72
+ const styles = {
73
+ editor: {
74
+ backgroundColor: normalizeColor(theme.colors?.['editor.background'])
75
+ },
76
+ base: {
77
+ color: normalizeColor(theme.colors?.['editor.foreground'])
78
+ }
79
+ };
77
80
 
78
- // Add theme-specific base styles if they exist
79
- if (theme.colors) {
80
- styles.base = {
81
- color: normalizeColor(theme.colors['editor.foreground']),
82
- backgroundColor: normalizeColor(theme.colors['editor.background'])
83
- };
81
+ // Process token colors
82
+ if (theme.tokenColors) {
83
+ const tokenStyles = convertTokenColorsToReactStyle(theme.tokenColors);
84
+ Object.assign(styles, tokenStyles);
84
85
  }
85
86
  return styles;
86
87
  } catch {
87
- console.error('Error converting theme styles');
88
- return {};
88
+ return {
89
+ editor: {
90
+ backgroundColor: '#1e1e1e'
91
+ },
92
+ base: {
93
+ color: '#d4d4d4'
94
+ }
95
+ };
89
96
  }
90
97
  }
91
98
  //# sourceMappingURL=style-transformer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["transform","hexToRgb","hex","result","exec","r","Number","parseInt","g","b","normalizeColor","color","startsWith","rgb","convertTokenColorsToReactStyle","tokenColors","styleMap","default","backgroundColor","forEach","token","settings","scope","scopes","Array","isArray","styleEntries","foreground","push","background","fontStyle","includes","length","transformedStyle","getRNStylesFromShikiStyle","theme","console","error","styles","colors","base"],"sourceRoot":"../../../src","sources":["utils/style-transformer.ts"],"mappings":";;AACA,OAAOA,SAAS,MAAM,qBAAqB;AAQ3C;AACA,SAASC,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;AAEA,OAAO,SAASG,8BAA8BA,CAACC,WAAkB,EAAc;EAC7E,MAAMC,QAAoB,GAAG,CAAC,CAAC;;EAE/B;EACAA,QAAQ,CAACC,OAAO,GAAG;IACjBN,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KAAK,KAAK,QAAQ,EAAE;UAC7BN,QAAQ,CAACM,KAAK,CAAC,GAAG;YAAE,IAAIN,QAAQ,CAACM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAAE,GAAGW;UAAiB,CAAC;QACvE;MACF,CAAC,CAAC;IACJ;EACF,CAAC,CAAC;EAEF,OAAOjB,QAAQ;AACjB;AAEA,OAAO,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;QACxDrB,eAAe,EAAER,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
+ {"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,CA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AAC,CAAC;EAEF,OAAOZ,QAAQ;AACjB;AAEA,OAAO,SAASgB,yBAAyBA,CAACC,KAAwB,EAAyB;EACzF,IAAI,CAACA,KAAK,EACR,OAAO,CAAC,CAAC;EAEX,IAAI;IACF,MAAMC,MAA6B,GAAG;MACpCC,MAAM,EAAE;QACNZ,eAAe,EAAEb,cAAc,CAACuB,KAAK,CAACG,MAAM,GAAG,mBAAmB,CAAC;MACrE,CAAC;MACDC,IAAI,EAAE;QACJ1B,KAAK,EAAED,cAAc,CAACuB,KAAK,CAACG,MAAM,GAAG,mBAAmB,CAAC;MAC3D;IACF,CAAC;;IAED;IACA,IAAIH,KAAK,CAAClB,WAAW,EAAE;MACrB,MAAMuB,WAAW,GAAGxB,8BAA8B,CAACmB,KAAK,CAAClB,WAAW,CAAC;MACrEwB,MAAM,CAACC,MAAM,CAACN,MAAM,EAAEI,WAAW,CAAC;IACpC;IAEA,OAAOJ,MAAM;EACf,CAAC,CACD,MAAM;IACJ,OAAO;MACLC,MAAM,EAAE;QAAEZ,eAAe,EAAE;MAAU,CAAC;MACtCc,IAAI,EAAE;QAAE1B,KAAK,EAAE;MAAU;IAC3B,CAAC;EACH;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"SyntaxHighlighter.d.ts","sourceRoot":"","sources":["../../../../src/components/syntax/SyntaxHighlighter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAE7D,OAAO,KAAkB,MAAM,OAAO,CAAA;AAsBtC,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAqDvD,CAAA;AAED,eAAe,iBAAiB,CAAA"}
1
+ {"version":3,"file":"SyntaxHighlighter.d.ts","sourceRoot":"","sources":["../../../../src/components/syntax/SyntaxHighlighter.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,KAAkB,MAAM,OAAO,CAAA;AAoDtC,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAuEvD,CAAA;AAED,eAAe,iBAAiB,CAAA"}
@@ -1,8 +1,9 @@
1
1
  import type { TextStyle } from 'react-native';
2
+ import type { ThemeRegistration } from 'shiki';
2
3
  export interface HighlighterStyleSheet {
3
4
  [key: string]: TextStyle;
4
5
  }
5
6
  export type ReactStyle = Record<string, TextStyle>;
6
- export declare function convertTokenColorsToReactStyle(tokenColors: any[]): ReactStyle;
7
- export declare function getRNStylesFromShikiStyle(theme: any): HighlighterStyleSheet;
7
+ export declare function convertTokenColorsToReactStyle(tokenColors: ThemeRegistration['tokenColors']): ReactStyle;
8
+ export declare function getRNStylesFromShikiStyle(theme: ThemeRegistration): HighlighterStyleSheet;
8
9
  //# sourceMappingURL=style-transformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"style-transformer.d.ts","sourceRoot":"","sources":["../../../src/utils/style-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAG7C,MAAM,WAAW,qBAAqB;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CACzB;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AA6BlD,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,UAAU,CA4C7E;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,GAAG,GAAG,qBAAqB,CAwB3E"}
1
+ {"version":3,"file":"style-transformer.d.ts","sourceRoot":"","sources":["../../../src/utils/style-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE9C,MAAM,WAAW,qBAAqB;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CACzB;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAoClD,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,iBAAiB,CAAC,aAAa,CAAC,GAAG,UAAU,CA2CxG;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,iBAAiB,GAAG,qBAAqB,CA4BzF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rn-shiki",
3
3
  "type": "module",
4
- "version": "0.0.37-27",
4
+ "version": "0.0.37-28",
5
5
  "description": "Shiki syntax highlighter for React Native.",
6
6
  "author": "Ryan Skinner <hello@ryanskinner.com>",
7
7
  "license": "MIT",
@@ -1,4 +1,5 @@
1
1
  import type { ColorValue, StyleProp, TextStyle } from 'react-native'
2
+ import type { ThemeInput, ThemeRegistration } from 'shiki'
2
3
  import type { SyntaxHighlighterProps } from 'src/types/shiki'
3
4
  import React, { useMemo } from 'react'
4
5
  import { Platform, ScrollView, StyleSheet, Text, View } from 'react-native'
@@ -24,14 +25,12 @@ interface Styles {
24
25
 
25
26
  type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
26
27
 
27
- interface ThemeColors {
28
- 'editor.background'?: string
29
- 'editor.foreground'?: string
30
- }
31
-
32
- interface Theme {
33
- colors?: ThemeColors
34
- tokenColors?: any[]
28
+ // Helper function to extract theme registration from Shiki theme input
29
+ function getThemeRegistration(theme: ThemeInput): ThemeRegistration {
30
+ if ('default' in theme) {
31
+ return theme.default
32
+ }
33
+ return theme as ThemeRegistration
35
34
  }
36
35
 
37
36
  const baseStyles = StyleSheet.create({
@@ -54,24 +53,19 @@ const baseStyles = StyleSheet.create({
54
53
  },
55
54
  })
56
55
 
57
- const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({
58
- text,
59
- language,
60
- languageId,
61
- theme,
62
- fontSize = 14,
63
- }) => {
56
+ const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({ text, language, languageId, theme, fontSize = 14 }) => {
64
57
  const stylesheet = useMemo(() => {
65
- const styles = getRNStylesFromShikiStyle(theme as Theme)
58
+ const themeRegistration = getThemeRegistration(theme)
59
+ const styles = getRNStylesFromShikiStyle(themeRegistration)
66
60
  return StyleSheet.create<Styles>({
67
61
  ...styles,
68
62
  editor: {
69
- backgroundColor: (theme as Theme).colors?.['editor.background'] || '#1e1e1e',
63
+ backgroundColor: themeRegistration.colors?.['editor.background'] || '#1e1e1e',
70
64
  },
71
65
  token: {
72
66
  ...baseStyles.token,
73
67
  fontSize,
74
- color: (theme as Theme).colors?.['editor.foreground'] || '#d4d4d4',
68
+ color: themeRegistration.colors?.['editor.foreground'] || '#d4d4d4',
75
69
  },
76
70
  })
77
71
  }, [theme, fontSize])
@@ -126,12 +120,7 @@ const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({
126
120
  )
127
121
 
128
122
  return (
129
- <ScrollView
130
- horizontal
131
- showsHorizontalScrollIndicator={Platform.OS !== 'web'}
132
- style={[baseStyles.scrollView, stylesheet.editor]}
133
- contentContainerStyle={baseStyles.container}
134
- >
123
+ <ScrollView horizontal showsHorizontalScrollIndicator={Platform.OS !== 'web'} style={[baseStyles.scrollView, stylesheet.editor]} contentContainerStyle={baseStyles.container}>
135
124
  {tokens.map((line, index) => renderLine(line, index))}
136
125
  </ScrollView>
137
126
  )
@@ -1,4 +1,5 @@
1
1
  import type { TextStyle } from 'react-native'
2
+ import type { ThemeRegistration } from 'shiki'
2
3
 
3
4
  export interface HighlighterStyleSheet {
4
5
  [key: string]: TextStyle
@@ -6,7 +7,6 @@ export interface HighlighterStyleSheet {
6
7
 
7
8
  export type ReactStyle = Record<string, TextStyle>
8
9
 
9
- // Helper function to convert hex color to RGB
10
10
  function hexToRgb(hex: string): { r: number, g: number, b: number } | null {
11
11
  // Remove # if present
12
12
  hex = hex.replace(/^#/, '')
@@ -27,9 +27,8 @@ function hexToRgb(hex: string): { r: number, g: number, b: number } | null {
27
27
  }
28
28
 
29
29
  function normalizeColor(color: string | undefined): string {
30
- if (!color) {
30
+ if (!color)
31
31
  return 'transparent'
32
- }
33
32
 
34
33
  // Handle hex colors
35
34
  if (color.startsWith('#')) {
@@ -39,23 +38,14 @@ function normalizeColor(color: string | undefined): string {
39
38
  }
40
39
  }
41
40
 
42
- // Handle rgb/rgba
43
- if (color.startsWith('rgb')) {
44
- return color
45
- }
46
-
47
- // Handle named colors
48
41
  return color
49
42
  }
50
43
 
51
- export function convertTokenColorsToReactStyle(tokenColors: any[]): ReactStyle {
52
- const styleMap: ReactStyle = {}
44
+ export function convertTokenColorsToReactStyle(tokenColors: ThemeRegistration['tokenColors']): ReactStyle {
45
+ if (!tokenColors)
46
+ return {}
53
47
 
54
- // Add default styles
55
- styleMap.default = {
56
- color: '#e1e4e8',
57
- backgroundColor: 'transparent',
58
- }
48
+ const styleMap: ReactStyle = {}
59
49
 
60
50
  tokenColors.forEach((token) => {
61
51
  if (!token.settings)
@@ -63,11 +53,9 @@ export function convertTokenColorsToReactStyle(tokenColors: any[]): ReactStyle {
63
53
 
64
54
  // Handle global theme settings
65
55
  if (!token.scope) {
66
- if (token.settings.foreground) {
67
- styleMap.default!.color = normalizeColor(token.settings.foreground)
68
- }
69
- if (token.settings.background) {
70
- styleMap.default!.backgroundColor = normalizeColor(token.settings.background)
56
+ styleMap.default = {
57
+ color: normalizeColor(token.settings.foreground),
58
+ backgroundColor: normalizeColor(token.settings.background),
71
59
  }
72
60
  return
73
61
  }
@@ -90,7 +78,7 @@ export function convertTokenColorsToReactStyle(tokenColors: any[]): ReactStyle {
90
78
  }
91
79
  }
92
80
 
93
- scopes.forEach((scope: string) => {
81
+ scopes.forEach((scope) => {
94
82
  styleMap[scope] = { ...(styleMap[scope] || {}), ...style }
95
83
  })
96
84
  })
@@ -98,23 +86,11 @@ export function convertTokenColorsToReactStyle(tokenColors: any[]): ReactStyle {
98
86
  return styleMap
99
87
  }
100
88
 
101
- interface ThemeColors {
102
- 'editor.background'?: string
103
- 'editor.foreground'?: string
104
- [key: string]: string | undefined
105
- }
106
-
107
- interface Theme {
108
- colors?: ThemeColors
109
- tokenColors?: any[]
110
- }
111
-
112
- export function getRNStylesFromShikiStyle(theme: Theme): HighlighterStyleSheet {
89
+ export function getRNStylesFromShikiStyle(theme: ThemeRegistration): HighlighterStyleSheet {
113
90
  if (!theme)
114
91
  return {}
115
92
 
116
93
  try {
117
- // Start with default styles
118
94
  const styles: HighlighterStyleSheet = {
119
95
  editor: {
120
96
  backgroundColor: normalizeColor(theme.colors?.['editor.background']),