Skip to content

Commit fea8742

Browse files
📝 Add docstrings to ts
Docstrings generation was requested by @kasumi-1. * #1 (comment) The following files were modified: * `examples/react-bundler/src/index.jsx` * `packages/react/coverage/block-navigation.js` * `packages/react/coverage/lcov-report/block-navigation.js` * `packages/react/coverage/lcov-report/prettify.js` * `packages/react/coverage/lcov-report/sorter.js` * `packages/react/coverage/prettify.js` * `packages/react/coverage/sorter.js` * `packages/react/src/index.ts` * `packages/web/src/logging.ts` * `packages/web/src/utils.ts` * `packages/web/src/validation.ts`
1 parent b562b93 commit fea8742

11 files changed

Lines changed: 1512 additions & 93 deletions

File tree

examples/react-bundler/src/index.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMicVAD, utils } from "@ricky0123/vad-react"
1+
import { useMicVAD, utils } from "@semperai/vad-react"
22
import React, { useState } from "react"
33
import ReactDOM from "react-dom"
44

@@ -8,6 +8,13 @@ const domContainer = document.querySelector("#root")
88
const root = ReactDOM.createRoot(domContainer)
99
root.render(<App />)
1010

11+
/**
12+
* Root React component demonstrating useMicVAD and a recorded-audio playlist.
13+
*
14+
* Renders controls to toggle voice activity detection, live VAD status and user-speaking indicators, and a playlist of captured audio clips saved as WAV data URLs.
15+
*
16+
* @returns {JSX.Element} The rendered App component.
17+
*/
1118
function App() {
1219
const [audioList, setAudioList] = useState([])
1320
const vad = useMicVAD({
@@ -23,7 +30,7 @@ function App() {
2330
})
2431
return (
2532
<div>
26-
<h1>Demo of @ricky0123/vad-react</h1>
33+
<h1>Demo of @semperai/vad-react</h1>
2734
<button onClick={vad.toggle}>Toggle VAD</button>
2835
{vad.listening && <div>VAD is running</div>}
2936
{!vad.listening && <div>VAD is NOT running</div>}
@@ -48,4 +55,4 @@ function UserSpeaking() {
4855

4956
function UserNotSpeaking() {
5057
return <span style={{ color: "red" }}>user is not speaking</span>
51-
}
58+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* eslint-disable */
2+
var jumpToCode = (function init() {
3+
// Classes of code we would like to highlight in the file view
4+
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
5+
6+
// Elements to highlight in the file listing view
7+
var fileListingElements = ['td.pct.low'];
8+
9+
// We don't want to select elements that are direct descendants of another match
10+
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
11+
12+
// Selector that finds elements on the page to which we can jump
13+
var selector =
14+
fileListingElements.join(', ') +
15+
', ' +
16+
notSelector +
17+
missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
18+
19+
// The NodeList of matching elements
20+
var missingCoverageElements = document.querySelectorAll(selector);
21+
22+
var currentIndex;
23+
24+
/**
25+
* Move the 'highlighted' CSS class from the currently highlighted element to the element at the given index.
26+
* @param {number} index - Index into `missingCoverageElements` of the element to receive the 'highlighted' class.
27+
*/
28+
function toggleClass(index) {
29+
missingCoverageElements
30+
.item(currentIndex)
31+
.classList.remove('highlighted');
32+
missingCoverageElements.item(index).classList.add('highlighted');
33+
}
34+
35+
/**
36+
* Set the specified element as the current highlighted item and scroll it into view.
37+
* @param {number} index - Index within `missingCoverageElements` to highlight and bring to center view.
38+
*/
39+
function makeCurrent(index) {
40+
toggleClass(index);
41+
currentIndex = index;
42+
missingCoverageElements.item(index).scrollIntoView({
43+
behavior: 'smooth',
44+
block: 'center',
45+
inline: 'center'
46+
});
47+
}
48+
49+
/**
50+
* Move the current highlight to the previous coverage element and scroll it into view.
51+
*
52+
* If no element is currently selected or the selection is at the first element, the selection wraps to the last element.
53+
*/
54+
function goToPrevious() {
55+
var nextIndex = 0;
56+
if (typeof currentIndex !== 'number' || currentIndex === 0) {
57+
nextIndex = missingCoverageElements.length - 1;
58+
} else if (missingCoverageElements.length > 1) {
59+
nextIndex = currentIndex - 1;
60+
}
61+
62+
makeCurrent(nextIndex);
63+
}
64+
65+
/**
66+
* Advance the highlighted element to the next item in the list, wrapping to the first item when at the end or when there is no current selection.
67+
*
68+
* Updates the current highlighted index and scrolls the newly selected element into view by delegating to makeCurrent.
69+
*/
70+
function goToNext() {
71+
var nextIndex = 0;
72+
73+
if (
74+
typeof currentIndex === 'number' &&
75+
currentIndex < missingCoverageElements.length - 1
76+
) {
77+
nextIndex = currentIndex + 1;
78+
}
79+
80+
makeCurrent(nextIndex);
81+
}
82+
83+
return function jump(event) {
84+
if (
85+
document.getElementById('fileSearch') === document.activeElement &&
86+
document.activeElement != null
87+
) {
88+
// if we're currently focused on the search input, we don't want to navigate
89+
return;
90+
}
91+
92+
switch (event.which) {
93+
case 78: // n
94+
case 74: // j
95+
goToNext();
96+
break;
97+
case 66: // b
98+
case 75: // k
99+
case 80: // p
100+
goToPrevious();
101+
break;
102+
}
103+
};
104+
})();
105+
window.addEventListener('keydown', jumpToCode);
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* eslint-disable */
2+
var jumpToCode = (function init() {
3+
// Classes of code we would like to highlight in the file view
4+
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
5+
6+
// Elements to highlight in the file listing view
7+
var fileListingElements = ['td.pct.low'];
8+
9+
// We don't want to select elements that are direct descendants of another match
10+
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
11+
12+
// Selector that finds elements on the page to which we can jump
13+
var selector =
14+
fileListingElements.join(', ') +
15+
', ' +
16+
notSelector +
17+
missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
18+
19+
// The NodeList of matching elements
20+
var missingCoverageElements = document.querySelectorAll(selector);
21+
22+
var currentIndex;
23+
24+
/**
25+
* Toggle the 'highlighted' class from the currently highlighted element to the element at the specified index.
26+
* @param {number} index - Index of the element in `missingCoverageElements` to add the `highlighted` class to; the current highlighted element (at `currentIndex`) will have the class removed if present.
27+
*/
28+
function toggleClass(index) {
29+
missingCoverageElements
30+
.item(currentIndex)
31+
.classList.remove('highlighted');
32+
missingCoverageElements.item(index).classList.add('highlighted');
33+
}
34+
35+
/**
36+
* Make the element at the given index the current highlighted item and scroll it into view centered with a smooth animation.
37+
* @param {number} index - Index within `missingCoverageElements` of the element to activate and scroll into view.
38+
*/
39+
function makeCurrent(index) {
40+
toggleClass(index);
41+
currentIndex = index;
42+
missingCoverageElements.item(index).scrollIntoView({
43+
behavior: 'smooth',
44+
block: 'center',
45+
inline: 'center'
46+
});
47+
}
48+
49+
/**
50+
* Move the current highlight to the previous matching element, wrapping to the last when at the start or when no current index is set.
51+
*/
52+
function goToPrevious() {
53+
var nextIndex = 0;
54+
if (typeof currentIndex !== 'number' || currentIndex === 0) {
55+
nextIndex = missingCoverageElements.length - 1;
56+
} else if (missingCoverageElements.length > 1) {
57+
nextIndex = currentIndex - 1;
58+
}
59+
60+
makeCurrent(nextIndex);
61+
}
62+
63+
/**
64+
* Move the highlighted selection to the next missing-coverage or file-listing element.
65+
*
66+
* If a current selection exists and is not the last element, advances to the following element;
67+
* otherwise selects the first element.
68+
*/
69+
function goToNext() {
70+
var nextIndex = 0;
71+
72+
if (
73+
typeof currentIndex === 'number' &&
74+
currentIndex < missingCoverageElements.length - 1
75+
) {
76+
nextIndex = currentIndex + 1;
77+
}
78+
79+
makeCurrent(nextIndex);
80+
}
81+
82+
return function jump(event) {
83+
if (
84+
document.getElementById('fileSearch') === document.activeElement &&
85+
document.activeElement != null
86+
) {
87+
// if we're currently focused on the search input, we don't want to navigate
88+
return;
89+
}
90+
91+
switch (event.which) {
92+
case 78: // n
93+
case 74: // j
94+
goToNext();
95+
break;
96+
case 66: // b
97+
case 75: // k
98+
case 80: // p
99+
goToPrevious();
100+
break;
101+
}
102+
};
103+
})();
104+
window.addEventListener('keydown', jumpToCode);

0 commit comments

Comments
 (0)