@samuelbradshaw/highlight-helper-js 0.7.1 → 0.7.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.
@@ -263,6 +263,7 @@ function Highlighter(options = hhDefaultOptions) {
263
263
  } else {
264
264
  // Draw highlights with Custom Highlight API
265
265
  if (options.drawingMode === 'highlight-api' && supportsHighlightApi) {
266
+ let highlightObj;
266
267
  if (CSS.highlights.has(highlightId)) {
267
268
  highlightObj = CSS.highlights.get(highlightId);
268
269
  highlightObj.clear();
@@ -701,7 +702,7 @@ function Highlighter(options = hhDefaultOptions) {
701
702
 
702
703
  // Long press in annotatable container (triggered by setTimeout() in pointerdown event)
703
704
  const respondToLongPress = (event) => {
704
- respondToPointerUp(event, isLongPress = true);
705
+ respondToPointerUp(event, true);
705
706
  tapResult = null;
706
707
  }
707
708
 
@@ -1270,7 +1271,6 @@ function Highlighter(options = hhDefaultOptions) {
1270
1271
  for (const paragraph of paragraphs) {
1271
1272
  const paragraphRect = paragraph.getBoundingClientRect();
1272
1273
  const computedParagraphStyle = window.getComputedStyle(paragraph);
1273
- const paragraphLineHeight = parseInt((computedParagraphStyle.lineHeight === 'normal' ? computedParagraphStyle.fontSize : computedParagraphStyle.lineHeight).replace('px', ''));
1274
1274
  const paragraphTopPadding = parseInt(computedParagraphStyle.getPropertyValue('padding-top').replace('px', ''));
1275
1275
 
1276
1276
  // Get line positions (bottom edge of each line)
@@ -1278,13 +1278,11 @@ function Highlighter(options = hhDefaultOptions) {
1278
1278
  let lineWalker = document.createTreeWalker(paragraph, NodeFilter.SHOW_TEXT);
1279
1279
  let textNode;
1280
1280
  while (textNode = lineWalker.nextNode()) {
1281
- const computedStyle = window.getComputedStyle(textNode.parentElement);
1282
- const lineHeight = parseInt((computedStyle.lineHeight === 'normal' ? computedStyle.fontSize : computedStyle.lineHeight).replace('px', ''));
1283
- if (lineHeight >= paragraphLineHeight) {
1284
- const referenceRange = document.createRange();
1285
- referenceRange.selectNode(textNode);
1286
- for (const rangeRect of referenceRange.getClientRects()) linePositions.add(rangeRect.bottom);
1287
- }
1281
+ // Skip text nodes in elements that are higher or lower than surrounding text
1282
+ if (textNode.parentElement.closest('sup, sub, rt')) continue;
1283
+ const referenceRange = document.createRange();
1284
+ referenceRange.selectNode(textNode);
1285
+ for (const rangeRect of referenceRange.getClientRects()) linePositions.add(rangeRect.bottom);
1288
1286
  }
1289
1287
  linePositions = Array.from(linePositions);
1290
1288
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samuelbradshaw/highlight-helper-js",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "JavaScript tool that enables highlighting or underlining text in an HTML page.",
5
5
  "type": "module",
6
6
  "main": "highlight-helper.mjs",