({ tab, definition })
| 60 | definition: string |
| 61 | } |
| 62 | const Definition: React.FC<DefinitionProps> = ({ tab, definition }) => { |
| 63 | const setAction = useSetAction() |
| 64 | const { rendition, currentHref } = useSnapshot(tab) |
| 65 | |
| 66 | useEffect(() => { |
| 67 | const result = tab.searchInSection(definition) |
| 68 | const matches = result?.subitems |
| 69 | |
| 70 | matches?.forEach((m) => { |
| 71 | try { |
| 72 | const h = rendition?.annotations.highlight( |
| 73 | m.cfi!, |
| 74 | undefined, |
| 75 | undefined, |
| 76 | undefined, |
| 77 | { |
| 78 | // tailwind gray-600 |
| 79 | fill: 'rgba(75, 85, 99, 0.15)', |
| 80 | 'fill-opacity': 'unset', |
| 81 | }, |
| 82 | ) |
| 83 | |
| 84 | const g = h?.mark.element as SVGGElement |
| 85 | |
| 86 | // `<rect>` should be reserved to response `click` |
| 87 | g?.addEventListener('click', () => { |
| 88 | tab.setAnnotationRange(m.cfi!) |
| 89 | setClickedAnnotation(true) |
| 90 | }) |
| 91 | } catch (error) { |
| 92 | // ignore matched text in `<title>` |
| 93 | } |
| 94 | }) |
| 95 | |
| 96 | return () => { |
| 97 | matches?.forEach((m) => |
| 98 | rendition?.annotations.remove(m.cfi!, 'highlight'), |
| 99 | ) |
| 100 | } |
| 101 | }, [currentHref, definition, rendition?.annotations, setAction, tab]) |
| 102 | |
| 103 | return null |
| 104 | } |
| 105 | |
| 106 | interface AnnotationProps { |
| 107 | tab: BookTab |
nothing calls this directly
no test coverage detected