@vdegenne/highlight-manager 0.1.9 → 0.1.11

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 CHANGED
@@ -20,9 +20,13 @@ interface ScrollStrategy {
20
20
  */
21
21
  behavior: ScrollBehavior;
22
22
  /**
23
- * @default 'start'
23
+ * @default undefined
24
24
  */
25
- logicalPosition: ScrollLogicalPosition;
25
+ block: ScrollLogicalPosition | undefined;
26
+ /**
27
+ * @default undefined
28
+ */
29
+ inline: ScrollLogicalPosition | undefined;
26
30
  }
27
31
  interface Options {
28
32
  css: string;
@@ -47,6 +51,8 @@ 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
58
  scrollStrategy: Partial<ScrollStrategy> | undefined;
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
- logicalPosition: 'start',
6
+ block: undefined,
7
+ inline: undefined,
7
8
  };
8
9
  const defaults = {
9
10
  atomicSelection(_element) {
@@ -171,12 +172,12 @@ export class HighLightManager {
171
172
  return false;
172
173
  }
173
174
  // console.log(highlightIndexStart, highlightIndexEnd, start, end)
175
+ const baseScrollStrategy = options?.scrollStrategy ?? this.#options.scrollStrategy;
174
176
  const _options = {
175
- scrollStrategy: options?.scrollStrategy || this.#options.scrollStrategy
177
+ scrollStrategy: baseScrollStrategy
176
178
  ? {
177
179
  ...scrollStrategyDefaults,
178
- ...this.#options.scrollStrategy,
179
- ...options?.scrollStrategy,
180
+ ...baseScrollStrategy,
180
181
  }
181
182
  : undefined,
182
183
  };
@@ -194,8 +195,8 @@ export class HighLightManager {
194
195
  !isInViewport(elementsToHighlight[0], _options.scrollStrategy.whenWhatPartIsHidden)) {
195
196
  elementsToHighlight[0]?.scrollIntoView({
196
197
  behavior: _options.scrollStrategy.behavior,
197
- block: _options.scrollStrategy.logicalPosition,
198
- inline: _options.scrollStrategy.logicalPosition,
198
+ block: _options.scrollStrategy.block,
199
+ inline: _options.scrollStrategy.block,
199
200
  });
200
201
  }
201
202
  elementsToHighlight.forEach((el) => el.setAttribute(`highlight${this.#id}`, ''));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vdegenne/highlight-manager",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "helper to navigate/highlight elements in a page based on a css selector",
5
5
  "type": "module",
6
6
  "exports": {