@vdegenne/highlight-manager 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +6 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +13 -2
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -18,6 +18,10 @@ const defaults = {
|
|
|
18
18
|
};
|
|
19
19
|
// Local array of all declared highlighters for id control.
|
|
20
20
|
const highlighters = [];
|
|
21
|
+
let globalBeforeHighlight;
|
|
22
|
+
export function setGlobalBeforeHighlight(fct) {
|
|
23
|
+
globalBeforeHighlight = fct;
|
|
24
|
+
}
|
|
21
25
|
export class HighLightManager {
|
|
22
26
|
#cache;
|
|
23
27
|
#options;
|
|
@@ -161,6 +165,7 @@ export class HighLightManager {
|
|
|
161
165
|
return false;
|
|
162
166
|
}
|
|
163
167
|
// console.log(highlightIndexStart, highlightIndexEnd, start, end)
|
|
168
|
+
globalBeforeHighlight?.();
|
|
164
169
|
this.#options.beforeHighlight?.();
|
|
165
170
|
// playClick()
|
|
166
171
|
if (unhighlightAll) {
|
|
@@ -170,7 +175,7 @@ export class HighLightManager {
|
|
|
170
175
|
if (elementsToHighlight.length === 0) {
|
|
171
176
|
return false;
|
|
172
177
|
}
|
|
173
|
-
if (this.#options.scrollWhenOffscreen
|
|
178
|
+
if (this.#options.scrollWhenOffscreen &&
|
|
174
179
|
!isInViewport(elementsToHighlight[0])) {
|
|
175
180
|
elementsToHighlight[0]?.scrollIntoView({
|
|
176
181
|
behavior: 'smooth',
|
package/lib/utils.d.ts
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
export function sleep(milli = 1000) {
|
|
2
2
|
return new Promise((r) => setTimeout(r, milli));
|
|
3
3
|
}
|
|
4
|
+
// export function isInViewport(el: Element) {
|
|
5
|
+
// return (
|
|
6
|
+
// el.getBoundingClientRect().top >= 0 &&
|
|
7
|
+
// el.getBoundingClientRect().bottom <= window.innerHeight
|
|
8
|
+
// )
|
|
9
|
+
// }
|
|
4
10
|
export function isInViewport(el) {
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
const rect = el.getBoundingClientRect();
|
|
12
|
+
const viewHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
13
|
+
const viewWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
14
|
+
return (rect.bottom > 0 &&
|
|
15
|
+
rect.right > 0 &&
|
|
16
|
+
rect.top < viewHeight &&
|
|
17
|
+
rect.left < viewWidth);
|
|
7
18
|
}
|
|
8
19
|
//# sourceMappingURL=utils.js.map
|