@vdegenne/highlight-manager 0.1.8 → 0.1.10
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 +11 -5
- package/lib/index.js +12 -9
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -20,9 +20,13 @@ interface ScrollStrategy {
|
|
|
20
20
|
*/
|
|
21
21
|
behavior: ScrollBehavior;
|
|
22
22
|
/**
|
|
23
|
-
* @default
|
|
23
|
+
* @default undefined
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
block: ScrollLogicalPosition | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* @default undefined
|
|
28
|
+
*/
|
|
29
|
+
inline: ScrollLogicalPosition | undefined;
|
|
26
30
|
}
|
|
27
31
|
interface Options {
|
|
28
32
|
css: string;
|
|
@@ -47,9 +51,11 @@ interface Options {
|
|
|
47
51
|
*/
|
|
48
52
|
applyStyleSheetTo: Document | HTMLElement | ShadowRoot;
|
|
49
53
|
/**
|
|
54
|
+
* Set to at least `{}` to activate scrolling when offscreen
|
|
55
|
+
*
|
|
50
56
|
* @default undefined
|
|
51
57
|
*/
|
|
52
|
-
scrollStrategy: ScrollStrategy | undefined;
|
|
58
|
+
scrollStrategy: Partial<ScrollStrategy> | undefined;
|
|
53
59
|
/**
|
|
54
60
|
* If true, will select the next visible candidate if the highlight is offscreen.
|
|
55
61
|
*
|
|
@@ -59,7 +65,7 @@ interface Options {
|
|
|
59
65
|
}
|
|
60
66
|
export declare function setGlobalBeforeHighlight(fct: () => void): void;
|
|
61
67
|
interface HighlightOptions {
|
|
62
|
-
scrollStrategy: ScrollStrategy | undefined;
|
|
68
|
+
scrollStrategy: Partial<ScrollStrategy> | undefined;
|
|
63
69
|
}
|
|
64
70
|
export declare class HighLightManager {
|
|
65
71
|
#private;
|
|
@@ -78,7 +84,7 @@ export declare class HighLightManager {
|
|
|
78
84
|
/**
|
|
79
85
|
* @returns {boolean} true if the highlight succeeded, false otherwise.
|
|
80
86
|
*/
|
|
81
|
-
highlight(start: number, end?: number, unhighlightAll?: boolean, cache?: boolean, options?: HighlightOptions): boolean;
|
|
87
|
+
highlight(start: number, end?: number, unhighlightAll?: boolean, cache?: boolean, options?: Partial<HighlightOptions>): boolean;
|
|
82
88
|
previous(step?: number, cache?: boolean): void;
|
|
83
89
|
next(step?: number, cache?: boolean): void;
|
|
84
90
|
extendLeftHighlight(step?: number, cache?: boolean): void;
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,8 @@ import { isInViewport, sleep } from './utils.js';
|
|
|
3
3
|
const scrollStrategyDefaults = {
|
|
4
4
|
whenWhatPartIsHidden: 'center',
|
|
5
5
|
behavior: 'smooth',
|
|
6
|
-
|
|
6
|
+
block: undefined,
|
|
7
|
+
inline: undefined,
|
|
7
8
|
};
|
|
8
9
|
const defaults = {
|
|
9
10
|
atomicSelection(_element) {
|
|
@@ -155,7 +156,7 @@ export class HighLightManager {
|
|
|
155
156
|
/**
|
|
156
157
|
* @returns {boolean} true if the highlight succeeded, false otherwise.
|
|
157
158
|
*/
|
|
158
|
-
highlight(start, end, unhighlightAll = true, cache = false, options) {
|
|
159
|
+
highlight(start, end, unhighlightAll = true, cache = false, options = {}) {
|
|
159
160
|
if (end === undefined) {
|
|
160
161
|
end = start;
|
|
161
162
|
}
|
|
@@ -172,11 +173,13 @@ export class HighLightManager {
|
|
|
172
173
|
}
|
|
173
174
|
// console.log(highlightIndexStart, highlightIndexEnd, start, end)
|
|
174
175
|
const _options = {
|
|
175
|
-
scrollStrategy:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
scrollStrategy: options?.scrollStrategy || this.#options.scrollStrategy
|
|
177
|
+
? {
|
|
178
|
+
...scrollStrategyDefaults,
|
|
179
|
+
...this.#options.scrollStrategy,
|
|
180
|
+
...options?.scrollStrategy,
|
|
181
|
+
}
|
|
182
|
+
: undefined,
|
|
180
183
|
};
|
|
181
184
|
globalBeforeHighlight?.();
|
|
182
185
|
this.#options.beforeHighlight?.();
|
|
@@ -192,8 +195,8 @@ export class HighLightManager {
|
|
|
192
195
|
!isInViewport(elementsToHighlight[0], _options.scrollStrategy.whenWhatPartIsHidden)) {
|
|
193
196
|
elementsToHighlight[0]?.scrollIntoView({
|
|
194
197
|
behavior: _options.scrollStrategy.behavior,
|
|
195
|
-
block: _options.scrollStrategy.
|
|
196
|
-
inline: _options.scrollStrategy.
|
|
198
|
+
block: _options.scrollStrategy.block,
|
|
199
|
+
inline: _options.scrollStrategy.block,
|
|
197
200
|
});
|
|
198
201
|
}
|
|
199
202
|
elementsToHighlight.forEach((el) => el.setAttribute(`highlight${this.#id}`, ''));
|