11import React from "react"
22import { CodeAnnotation } from "../smooth-code"
3- import { getColor , transparent , ColorName } from "../utils"
4- import { LineWithElement } from "../smooth-code/partial-step-parser"
3+ import { transparent } from "../utils"
4+ import {
5+ AnnotationProps ,
6+ LineWithElement ,
7+ } from "../smooth-code/partial-step-parser"
58import { CopyButton } from "../smooth-code/copy-button"
9+ import { CSSV } from "utils/light/css"
610
711export function Annotation ( ) {
812 return (
@@ -36,35 +40,19 @@ function MultilineMark({
3640 children,
3741 data,
3842 style,
39- theme,
4043 lines,
4144} : {
4245 data : string
4346 children : React . ReactNode
4447 style ?: React . CSSProperties
45- theme ?: any
4648 lines ?: LineWithElement [ ]
4749} ) {
4850 const content = getContent ( lines )
4951 const className = `ch-code-multiline-mark ` + ( data ?? "" )
50- const bg = getColor (
51- theme ,
52- ColorName . RangeHighlightBackground
53- )
54- const border = getColor (
55- theme ,
56- ColorName . EditorInfoForeground
57- )
5852
5953 return (
60- < div
61- style = { { ...style , background : bg } }
62- className = { className }
63- >
64- < span
65- className = "ch-code-multiline-mark-border"
66- style = { { background : border } }
67- />
54+ < div style = { style } className = { className } >
55+ < span className = "ch-code-multiline-mark-border" />
6856 { children }
6957 < CopyButton
7058 className = "ch-code-button"
@@ -88,25 +76,15 @@ function getContent(lines: LineWithElement[]) {
8876 . join ( "\n" )
8977}
9078
91- function InlineMark ( {
92- children,
93- data,
94- theme,
95- } : {
96- data : any
97- children : React . ReactNode
98- theme : any
99- } ) {
100- const bg =
101- tryGuessColor ( children ) ||
102- transparent (
103- getColor ( theme , ColorName . CodeForeground ) ,
104- 0.2
105- )
106-
79+ function InlineMark ( { children, data } : AnnotationProps ) {
10780 const className = "ch-code-inline-mark " + ( data ?? "" )
10881 return (
109- < span className = { className } style = { { background : bg } } >
82+ < span
83+ className = { className }
84+ style = { {
85+ background : tryGuessColor ( children ) || undefined ,
86+ } }
87+ >
11088 { children }
11189 </ span >
11290 )
@@ -115,44 +93,34 @@ function InlineMark({
11593function tryGuessColor (
11694 children : React . ReactNode
11795) : string | undefined {
118- const child = React . Children . toArray ( children ) [ 0 ] as any
119-
120- const grandChild = React . Children . toArray (
121- child ?. props ?. children || [ ]
122- ) [ 0 ] as any
123-
124- const grandGrandChild = React . Children . toArray (
125- grandChild ?. props ?. children || [ ]
126- ) [ 0 ] as any
127-
128- const { color } = grandGrandChild ?. props ?. style || { }
129-
130- if ( color ) {
131- return transparent ( color as string , 0.2 )
96+ try {
97+ const child = React . Children . toArray ( children ) [ 0 ] as any
98+
99+ const grandChild = React . Children . toArray (
100+ child ?. props ?. children || [ ]
101+ ) [ 0 ] as any
102+
103+ const grandGrandChild = React . Children . toArray (
104+ grandChild ?. props ?. children || [ ]
105+ ) [ 0 ] as any
106+ const { color } = grandGrandChild ?. props ?. style || { }
107+
108+ if ( color ) {
109+ return transparent ( color as string , 0.2 )
110+ }
111+ return undefined
112+ } catch ( e ) {
113+ return undefined
132114 }
133-
134- return undefined
135115}
136116
137- function Box ( {
138- children,
139- data,
140- theme,
141- } : {
142- data : any
143- children : React . ReactNode
144- theme : any
145- } ) {
146- const border =
147- typeof data === "string"
148- ? data
149- : theme . tokenColors . find ( ( tc : any ) =>
150- tc . scope ?. includes ( "string" )
151- ) ?. settings ?. foreground || "yellow"
117+ function Box ( { children, data } : AnnotationProps ) {
118+ const outlineColor =
119+ typeof data === "string" ? data : undefined
152120 return (
153121 < span
154122 className = "ch-code-box-annotation"
155- style = { { outline : `2px solid ${ border } ` } }
123+ style = { { outlineColor } }
156124 >
157125 { children }
158126 </ span >
@@ -163,38 +131,16 @@ function WithClass({
163131 children,
164132 data,
165133 style,
166- theme,
167- } : {
168- data : any
169- children : React . ReactNode
170- style ?: React . CSSProperties
171- theme : any
172- } ) {
173- const className = data as string
134+ } : AnnotationProps ) {
174135 return (
175- < span style = { style } className = { className } >
136+ < span style = { style } className = { data as string } >
176137 { children }
177138 </ span >
178139 )
179140}
180141
181- function Label ( {
182- children,
183- data,
184- style,
185- theme,
186- } : {
187- data : any
188- children : React . ReactNode
189- style ?: React . CSSProperties
190- theme ?: any
191- } ) {
192- const bg = ( ( theme as any ) . colors [
193- "editor.lineHighlightBackground"
194- ] ||
195- ( theme as any ) . colors [
196- "editor.selectionHighlightBackground"
197- ] ) as string
142+ function Label ( { children, data, style } : AnnotationProps ) {
143+ const bg = CSSV . editor . lineHighlightBackground
198144 const [ hover , setHover ] = React . useState ( false )
199145
200146 return (
0 commit comments