@samuelbradshaw/highlight-helper-js 0.7.3 → 0.7.5

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.
@@ -453,11 +453,12 @@ function Highlighter(options = hhDefaultOptions) {
453
453
  changes: appearanceChanges.concat(boundsChanges),
454
454
  }
455
455
 
456
- if (highlightId !== activeHighlightId) this.drawHighlights([highlightId]);
457
- if (highlightId === activeHighlightId && appearanceChanges.length > 0) {
458
- updateSelectionUi('appearance');
459
- } else if (triggeredByUserAction && highlightId !== activeHighlightId) {
456
+ if (triggeredByUserAction && !activeHighlightId) {
460
457
  this.activateHighlight(highlightId);
458
+ } else if (activeHighlightId && highlightId === activeHighlightId && appearanceChanges.length > 0) {
459
+ updateSelectionUi('appearance');
460
+ } else if (highlightId !== activeHighlightId) {
461
+ this.drawHighlights([highlightId]);
461
462
  }
462
463
 
463
464
  if (isNewHighlight) {
@@ -480,6 +481,7 @@ function Highlighter(options = hhDefaultOptions) {
480
481
  const highlightRange = highlightToActivate.rangeObj.cloneRange();
481
482
  activeHighlightId = highlightId;
482
483
  updateSelectionUi('appearance');
484
+ updateSelectionUi('bounds');
483
485
 
484
486
  // Update the selection range if needed
485
487
  // In Android Chrome, sometimes selection handles don't show when a selection is updated programmatically, so it's best to only update the selection if needed.
@@ -914,7 +916,7 @@ function Highlighter(options = hhDefaultOptions) {
914
916
 
915
917
  // Bring active highlight to the front
916
918
  const svgHighlight = svgBackground.querySelector(`g[data-highlight-id="${activeHighlightId}"]`);
917
- svgBackground.appendChild(svgHighlight);
919
+ if (svgHighlight) svgBackground.appendChild(svgHighlight);
918
920
  svgBackground.appendChild(svgActiveOverlay);
919
921
  }
920
922
 
@@ -1010,7 +1012,7 @@ function Highlighter(options = hhDefaultOptions) {
1010
1012
 
1011
1013
  // Prevent the range from starting or ending in an element that doesn't match the paragraph selector
1012
1014
  if (this.annotatableContainer.contains(range.commonAncestorContainer) && (!startNode.parentElement.closest(options.paragraphSelector) || !endNode.parentElement.closest(options.paragraphSelector))) {
1013
- annotatableParagraphsInRange = Array.from(this.annotatableParagraphs).filter((paragraph) => {
1015
+ const annotatableParagraphsInRange = Array.from(this.annotatableParagraphs).filter((paragraph) => {
1014
1016
  const relativeStartPosition = startNode.compareDocumentPosition(paragraph);
1015
1017
  const relativeEndPosition = endNode.compareDocumentPosition(paragraph);
1016
1018
  return (relativeStartPosition & Node.DOCUMENT_POSITION_FOLLOWING || relativeStartPosition & Node.DOCUMENT_POSITION_CONTAINS) && (relativeEndPosition & Node.DOCUMENT_POSITION_PRECEDING || relativeEndPosition & Node.DOCUMENT_POSITION_CONTAINS);
@@ -1263,6 +1265,7 @@ function Highlighter(options = hhDefaultOptions) {
1263
1265
  const elementRect = element.getBoundingClientRect();
1264
1266
  if (Math.round(elementRect.width) === Math.round(rect.width) && Math.round(elementRect.height) === Math.round(rect.height) && Math.round(elementRect.top) === Math.round(rect.top) && Math.round(elementRect.left) === Math.round(rect.left)) {
1265
1267
  unmergedRects.splice(ur, 1);
1268
+ break;
1266
1269
  }
1267
1270
  }
1268
1271
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samuelbradshaw/highlight-helper-js",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
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",