()
| 8 | import { isHotkeyCombinationPressed } from '../utils/hotkey' |
| 9 | |
| 10 | export const SourceInspector = () => { |
| 11 | const { settings } = createDevtoolsSettings() |
| 12 | const highlightStateInit = () => ({ |
| 13 | element: null as HTMLElement | null, |
| 14 | bounding: { width: 0, height: 0, left: 0, top: 0 }, |
| 15 | dataSource: '', |
| 16 | }) |
| 17 | |
| 18 | const [highlightState, setHighlightState] = createStore(highlightStateInit()) |
| 19 | const resetHighlight = () => { |
| 20 | setHighlightState(highlightStateInit()) |
| 21 | } |
| 22 | |
| 23 | const [nameTagRef, setNameTagRef] = createSignal<HTMLDivElement | null>(null) |
| 24 | const nameTagSize = createElementSize(() => nameTagRef()) |
| 25 | |
| 26 | const [mousePosition, setMousePosition] = createStore({ x: 0, y: 0 }) |
| 27 | createEventListener(document, 'mousemove', (e) => { |
| 28 | setMousePosition({ x: e.clientX, y: e.clientY }) |
| 29 | }) |
| 30 | |
| 31 | const downList = getKeyDownList() |
| 32 | |
| 33 | const [disabledAfterClick, setDisabledAfterClick] = createSignal(false) |
| 34 | |
| 35 | const isHighlightingKeysHeld = createMemo(() => { |
| 36 | return isHotkeyCombinationPressed(downList(), settings().inspectHotkey) |
| 37 | }) |
| 38 | |
| 39 | createEffect(() => { |
| 40 | if (!isHighlightingKeysHeld()) { |
| 41 | setDisabledAfterClick(false) |
| 42 | } |
| 43 | }) |
| 44 | |
| 45 | const isActive = createMemo( |
| 46 | () => isHighlightingKeysHeld() && !disabledAfterClick(), |
| 47 | ) |
| 48 | |
| 49 | createEffect(() => { |
| 50 | if (isActive()) { |
| 51 | document.body.style.cursor = 'pointer' |
| 52 | } else { |
| 53 | document.body.style.cursor = '' |
| 54 | } |
| 55 | }) |
| 56 | |
| 57 | createEffect(() => { |
| 58 | if (!isActive()) { |
| 59 | resetHighlight() |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | const target = document.elementFromPoint(mousePosition.x, mousePosition.y) |
| 64 | |
| 65 | if (!(target instanceof HTMLElement)) { |
| 66 | resetHighlight() |
| 67 | return |
nothing calls this directly
no test coverage detected