rn-shiki 0.0.37-3 → 0.0.37-32
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/components/syntax/SyntaxHighlighter.js +100 -60
- package/lib/commonjs/components/syntax/SyntaxHighlighter.js.map +1 -1
- package/lib/commonjs/hooks/useSyntaxHighlighter.js +18 -10
- package/lib/commonjs/hooks/useSyntaxHighlighter.js.map +1 -1
- package/lib/commonjs/index.js +0 -23
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/syntax/{highlighter/index.js → highlighter.js} +20 -10
- package/lib/commonjs/syntax/highlighter.js.map +1 -0
- package/lib/commonjs/utils/style-transformer.js +103 -0
- package/lib/commonjs/utils/style-transformer.js.map +1 -0
- package/lib/module/components/syntax/SyntaxHighlighter.js +100 -61
- package/lib/module/components/syntax/SyntaxHighlighter.js.map +1 -1
- package/lib/module/hooks/useSyntaxHighlighter.js +17 -9
- package/lib/module/hooks/useSyntaxHighlighter.js.map +1 -1
- package/lib/module/index.js +1 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/syntax/highlighter.js +44 -0
- package/lib/module/syntax/highlighter.js.map +1 -0
- package/lib/module/utils/style-transformer.js +98 -0
- package/lib/module/utils/style-transformer.js.map +1 -0
- package/lib/typescript/components/syntax/SyntaxHighlighter.d.ts +2 -10
- package/lib/typescript/components/syntax/SyntaxHighlighter.d.ts.map +1 -1
- package/lib/typescript/hooks/useSyntaxHighlighter.d.ts +3 -2
- package/lib/typescript/hooks/useSyntaxHighlighter.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/syntax/{highlighter/index.d.ts → highlighter.d.ts} +3 -4
- package/lib/typescript/syntax/highlighter.d.ts.map +1 -0
- package/lib/typescript/types/shiki.d.ts +10 -8
- package/lib/typescript/types/shiki.d.ts.map +1 -1
- package/lib/typescript/utils/string.d.ts +1 -1
- package/lib/typescript/utils/string.d.ts.map +1 -1
- package/lib/typescript/utils/style-transformer.d.ts +9 -0
- package/lib/typescript/utils/style-transformer.d.ts.map +1 -0
- package/package.json +2 -6
- package/src/components/syntax/SyntaxHighlighter.tsx +85 -33
- package/src/hooks/useSyntaxHighlighter.ts +13 -4
- package/src/index.ts +1 -4
- package/src/syntax/{highlighter/index.ts → highlighter.ts} +22 -10
- package/src/types/shiki.ts +7 -8
- package/src/utils/string.ts +1 -1
- package/src/utils/style-transformer.ts +50 -94
- package/lib/commonjs/components/syntax/SyntaxLine.js +0 -36
- package/lib/commonjs/components/syntax/SyntaxLine.js.map +0 -1
- package/lib/commonjs/components/syntax/index.js +0 -21
- package/lib/commonjs/components/syntax/index.js.map +0 -1
- package/lib/commonjs/syntax/highlighter/index.js.map +0 -1
- package/lib/commonjs/syntax/index.js +0 -19
- package/lib/commonjs/syntax/index.js.map +0 -1
- package/lib/commonjs/types/index.js +0 -2
- package/lib/commonjs/types/index.js.map +0 -1
- package/lib/commonjs/types/shiki.d.js +0 -6
- package/lib/commonjs/types/shiki.d.js.map +0 -1
- package/lib/commonjs/utils/index.js +0 -17
- package/lib/commonjs/utils/index.js.map +0 -1
- package/lib/module/components/syntax/SyntaxLine.js +0 -31
- package/lib/module/components/syntax/SyntaxLine.js.map +0 -1
- package/lib/module/components/syntax/index.js +0 -5
- package/lib/module/components/syntax/index.js.map +0 -1
- package/lib/module/syntax/highlighter/index.js +0 -34
- package/lib/module/syntax/highlighter/index.js.map +0 -1
- package/lib/module/syntax/index.js +0 -4
- package/lib/module/syntax/index.js.map +0 -1
- package/lib/module/types/index.js +0 -2
- package/lib/module/types/index.js.map +0 -1
- package/lib/module/types/shiki.d.js +0 -4
- package/lib/module/types/shiki.d.js.map +0 -1
- package/lib/module/utils/index.js +0 -4
- package/lib/module/utils/index.js.map +0 -1
- package/lib/typescript/components/syntax/SyntaxLine.d.ts +0 -9
- package/lib/typescript/components/syntax/SyntaxLine.d.ts.map +0 -1
- package/lib/typescript/components/syntax/index.d.ts +0 -3
- package/lib/typescript/components/syntax/index.d.ts.map +0 -1
- package/lib/typescript/syntax/highlighter/index.d.ts.map +0 -1
- package/lib/typescript/syntax/index.d.ts +0 -2
- package/lib/typescript/syntax/index.d.ts.map +0 -1
- package/lib/typescript/types/index.d.ts +0 -7
- package/lib/typescript/types/index.d.ts.map +0 -1
- package/lib/typescript/utils/index.d.ts +0 -2
- package/lib/typescript/utils/index.d.ts.map +0 -1
- package/src/components/syntax/SyntaxLine.tsx +0 -81
- package/src/components/syntax/index.ts +0 -2
- package/src/syntax/index.ts +0 -1
- package/src/types/index.ts +0 -6
- package/src/utils/index.ts +0 -1
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
import { createHighlighterCore } from 'shiki/core';
|
4
|
-
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
5
|
-
async function initializeHighlighter(langs, themes) {
|
6
|
-
return createHighlighterCore({
|
7
|
-
engine: createJavaScriptRegexEngine(),
|
8
|
-
langs,
|
9
|
-
themes
|
10
|
-
});
|
11
|
-
}
|
12
|
-
export async function createHighlighter({
|
13
|
-
langs,
|
14
|
-
themes
|
15
|
-
}) {
|
16
|
-
if (!langs?.length || !themes?.length) {
|
17
|
-
throw new Error('Please provide both `langs` and `themes` when creating a highlighter.');
|
18
|
-
}
|
19
|
-
try {
|
20
|
-
const highlighter = await initializeHighlighter(langs, themes);
|
21
|
-
return highlighter;
|
22
|
-
} catch (error) {
|
23
|
-
console.error('Failed to create highlighter:', error);
|
24
|
-
throw error;
|
25
|
-
}
|
26
|
-
}
|
27
|
-
export function processTokens(tokens) {
|
28
|
-
return tokens.map(token => ({
|
29
|
-
content: token.content,
|
30
|
-
color: token.color || '#000000',
|
31
|
-
fontStyle: token.fontStyle?.toString()
|
32
|
-
}));
|
33
|
-
}
|
34
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["createHighlighterCore","createJavaScriptRegexEngine","initializeHighlighter","langs","themes","engine","createHighlighter","length","Error","highlighter","error","console","processTokens","tokens","map","token","content","color","fontStyle","toString"],"sourceRoot":"../../../../src","sources":["syntax/highlighter/index.ts"],"mappings":";;AAEA,SAASA,qBAAqB,QAAQ,YAAY;AAClD,SAASC,2BAA2B,QAAQ,yBAAyB;AAErE,eAAeC,qBAAqBA,CAACC,KAAsB,EAAEC,MAAoB,EAA8D;EAC7I,OAAOJ,qBAAqB,CAAC;IAC3BK,MAAM,EAAEJ,2BAA2B,CAAC,CAAC;IACrCE,KAAK;IACLC;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,eAAeE,iBAAiBA,CAAC;EAAEH,KAAK;EAAEC;AAAyD,CAAC,EAA8D;EACvK,IAAI,CAACD,KAAK,EAAEI,MAAM,IAAI,CAACH,MAAM,EAAEG,MAAM,EAAE;IACrC,MAAM,IAAIC,KAAK,CAAC,uEAAuE,CAAC;EAC1F;EAEA,IAAI;IACF,MAAMC,WAAW,GAAG,MAAMP,qBAAqB,CAACC,KAAK,EAAEC,MAAM,CAAC;IAC9D,OAAOK,WAAW;EACpB,CAAC,CACD,OAAOC,KAAK,EAAE;IACZC,OAAO,CAACD,KAAK,CAAC,+BAA+B,EAAEA,KAAK,CAAC;IACrD,MAAMA,KAAK;EACb;AACF;AAEA,OAAO,SAASE,aAAaA,CAACC,MAAqB,EAAe;EAChE,OAAOA,MAAM,CAACC,GAAG,CAACC,KAAK,KAAK;IAC1BC,OAAO,EAAED,KAAK,CAACC,OAAO;IACtBC,KAAK,EAAEF,KAAK,CAACE,KAAK,IAAI,SAAS;IAC/BC,SAAS,EAAEH,KAAK,CAACG,SAAS,EAAEC,QAAQ,CAAC;EACvC,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["createHighlighter","processTokens"],"sourceRoot":"../../../src","sources":["syntax/index.ts"],"mappings":";;AAAA,SAASA,iBAAiB,EAAEC,aAAa,QAAQ,eAAe","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/shiki.d.ts"],"mappings":"","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":";;AAAA,cAAc,UAAU","ignoreList":[]}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import type { TokenType } from '../../types';
|
2
|
-
import React from 'react';
|
3
|
-
interface SyntaxLineProps {
|
4
|
-
line: TokenType[];
|
5
|
-
fontSize?: number;
|
6
|
-
}
|
7
|
-
declare function SyntaxLine({ line, fontSize }: SyntaxLineProps): React.JSX.Element;
|
8
|
-
export default SyntaxLine;
|
9
|
-
//# sourceMappingURL=SyntaxLine.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"SyntaxLine.d.ts","sourceRoot":"","sources":["../../../../src/components/syntax/SyntaxLine.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,UAAU,eAAe;IACvB,IAAI,EAAE,SAAS,EAAE,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,iBAAS,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,eAAe,qBAsBtD;AAED,eAAe,UAAU,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/syntax/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/syntax/highlighter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAWlD,wBAAsB,iBAAiB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAavK;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,EAAE,CAMhE"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/syntax/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
@@ -1,81 +0,0 @@
|
|
1
|
-
import type { TokenType } from '../../types'
|
2
|
-
import type { RNTokenStyle } from '../../utils/style-transformer'
|
3
|
-
import React from 'react'
|
4
|
-
import { Platform, StyleSheet, Text, View } from 'react-native'
|
5
|
-
|
6
|
-
const monospaceFont = Platform.select({
|
7
|
-
ios: 'Menlo',
|
8
|
-
android: 'monospace',
|
9
|
-
default: 'monospace',
|
10
|
-
})
|
11
|
-
|
12
|
-
const styles = StyleSheet.create({
|
13
|
-
lineContainer: {
|
14
|
-
flexDirection: 'row',
|
15
|
-
flexWrap: 'wrap',
|
16
|
-
},
|
17
|
-
token: {
|
18
|
-
includeFontPadding: false,
|
19
|
-
},
|
20
|
-
})
|
21
|
-
|
22
|
-
interface SyntaxLineProps {
|
23
|
-
line: TokenType[]
|
24
|
-
fontSize?: number
|
25
|
-
isLastLine?: boolean
|
26
|
-
themeStyles: {
|
27
|
-
backgroundColor: string
|
28
|
-
defaultColor: string
|
29
|
-
styles: Record<string, RNTokenStyle>
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
function SyntaxLine({ line, fontSize = 14, isLastLine = false, themeStyles }: SyntaxLineProps) {
|
34
|
-
const lineHeight = Math.floor(fontSize * 1.5)
|
35
|
-
|
36
|
-
return (
|
37
|
-
<View
|
38
|
-
style={[
|
39
|
-
styles.lineContainer,
|
40
|
-
{
|
41
|
-
minHeight: lineHeight,
|
42
|
-
paddingBottom: !isLastLine ? 4 : 0,
|
43
|
-
},
|
44
|
-
]}
|
45
|
-
>
|
46
|
-
{line.map((token, tokenIndex) => {
|
47
|
-
const content = token.content.replace(/ /g, '\u00A0')
|
48
|
-
// Use converted theme styles
|
49
|
-
const tokenStyle = token.color ? { color: token.color } : { color: themeStyles.defaultColor }
|
50
|
-
|
51
|
-
return (
|
52
|
-
<Text
|
53
|
-
key={`${tokenIndex}-${content.slice(0, 8)}`}
|
54
|
-
style={[
|
55
|
-
styles.token,
|
56
|
-
{
|
57
|
-
...tokenStyle,
|
58
|
-
fontFamily: monospaceFont,
|
59
|
-
fontSize,
|
60
|
-
fontStyle: token.fontStyle as 'normal' | 'italic',
|
61
|
-
fontWeight: token.fontWeight as 'normal' | 'bold',
|
62
|
-
lineHeight,
|
63
|
-
height: lineHeight,
|
64
|
-
textAlignVertical: 'center',
|
65
|
-
...(Platform.OS === 'ios'
|
66
|
-
? {
|
67
|
-
paddingTop: 2,
|
68
|
-
}
|
69
|
-
: {}),
|
70
|
-
},
|
71
|
-
]}
|
72
|
-
>
|
73
|
-
{content}
|
74
|
-
</Text>
|
75
|
-
)
|
76
|
-
})}
|
77
|
-
</View>
|
78
|
-
)
|
79
|
-
}
|
80
|
-
|
81
|
-
export default SyntaxLine
|
package/src/syntax/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { createHighlighter, processTokens } from './highlighter'
|
package/src/types/index.ts
DELETED
package/src/utils/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './string'
|