( e: any, preview_position: any, segments: Segment[], player: any, )
| 67 | } |
| 68 | |
| 69 | function setCurrentLabel( |
| 70 | e: any, |
| 71 | preview_position: any, |
| 72 | segments: Segment[], |
| 73 | player: any, |
| 74 | ) { |
| 75 | let currentLabel = segments[0].title; |
| 76 | |
| 77 | const currentPos = preview_position * player?.duration(); |
| 78 | if (preview_position !== 0) { |
| 79 | segments?.forEach((each: Segment) => { |
| 80 | if (each?.start < currentPos && each?.end > currentPos) { |
| 81 | currentLabel = each?.title; |
| 82 | } |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | const timelineLabel = document.querySelector( |
| 87 | '#timeline-label', |
| 88 | ) as HTMLDivElement; |
| 89 | const timelineContainer = document.querySelector( |
| 90 | '#timeline-container', |
| 91 | ) as HTMLDivElement; |
| 92 | |
| 93 | const rect = timelineContainer && timelineContainer?.getBoundingClientRect(); |
| 94 | |
| 95 | let timelineLabelWidth = timelineLabel?.offsetWidth / 2; |
| 96 | |
| 97 | if (timelineLabel && rect && timelineContainer) { |
| 98 | timelineLabel.innerHTML = `<div>${formatTime(preview_position.toFixed(2) * player?.duration())} - ${currentLabel}</div>`; |
| 99 | |
| 100 | if (Math.max(0, e?.x - rect?.x) < timelineLabel?.offsetWidth / 2) { |
| 101 | timelineLabelWidth = Math.max(0, e?.x - rect?.x); |
| 102 | } else if ( |
| 103 | Math.max(0, e?.x - rect?.x) > |
| 104 | timelineContainer.offsetWidth - timelineLabel?.offsetWidth / 2 |
| 105 | ) { |
| 106 | timelineLabelWidth = |
| 107 | timelineLabel?.offsetWidth - |
| 108 | (timelineContainer?.offsetWidth - (e?.x - rect?.x)); |
| 109 | } |
| 110 | |
| 111 | timelineLabel.style.left = `calc(${preview_position * 100}% - ${timelineLabelWidth}px)`; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | let isMouseOver = false; |
| 116 | let isMouseDown = false; |
no test coverage detected