@vdegenne/highlight-manager 0.1.1 → 0.1.3
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 +19 -5
- 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;
|
|
@@ -100,11 +104,20 @@ export class HighLightManager {
|
|
|
100
104
|
// const highlightIndexStart = elements.findIndex((el) =>
|
|
101
105
|
// el.hasAttribute('highlight'),
|
|
102
106
|
// );
|
|
103
|
-
if (!highlightElements || highlightElements.length === 0) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
// if (!highlightElements || highlightElements.length === 0) {
|
|
108
|
+
// console.warn("The highlighted element couldn't be found")
|
|
109
|
+
// return {
|
|
110
|
+
// highlightIndexStart: -1,
|
|
111
|
+
// highlightIndexEnd: -1,
|
|
112
|
+
// elements: []
|
|
113
|
+
// }
|
|
114
|
+
// }
|
|
115
|
+
const highlightIndexStart = highlightElements.length
|
|
116
|
+
? elements.indexOf(highlightElements[0])
|
|
117
|
+
: -1;
|
|
118
|
+
const highlightIndexEnd = highlightElements.length
|
|
119
|
+
? elements.indexOf(highlightElements[highlightElements.length - 1])
|
|
120
|
+
: -1;
|
|
108
121
|
if (highlightElements.length === 1) {
|
|
109
122
|
// const highlightElement = elements[highlightIndex];
|
|
110
123
|
}
|
|
@@ -152,6 +165,7 @@ export class HighLightManager {
|
|
|
152
165
|
return false;
|
|
153
166
|
}
|
|
154
167
|
// console.log(highlightIndexStart, highlightIndexEnd, start, end)
|
|
168
|
+
globalBeforeHighlight?.();
|
|
155
169
|
this.#options.beforeHighlight?.();
|
|
156
170
|
// playClick()
|
|
157
171
|
if (unhighlightAll) {
|
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
|