npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@notelix/web-marker

v2.0.9

Published

a web page highlighter

Readme

web-marker

logo

A web page highlighter that features

  • accurate serialization and deserialization which makes it possible to correctly restore the highlights, even if part of the web page has changed
  • nested highlighting
  • configurable overlapping highlight handling
  • no runtime-dependency

demo

How to run

git clone https://github.com/notelix/web-marker
cd web-marker
npm i
npm start

How to use

npm install @notelix/web-marker
import {Marker} from "@notelix/web-marker"

const marker = new Marker({
    rootElement: document.body,
    eventHandler: {
        onHighlightClick: (context, element) => {
            marker.unpaint(context.serializedRange);
        },
        onHighlightHoverStateChange: (context, element, hovering) => {
            if (hovering) {
                element.style.backgroundColor = "#f0d8ff";
            } else {
                element.style.backgroundColor = "";
            }
        }
    },
    highlightPainter: {
        paintHighlight: (context, element) => {
            element.style.color = "red";
        }
    }
});

marker.addEventListeners();

document.addEventListener('mouseup', (e) => {
    const selection = window.getSelection();
    if (!selection.rangeCount) {
        return null;
    }
    const serialized = marker.serializeRange(selection.getRangeAt(0));
    console.log(JSON.stringify(serialized));
    marker.paint(serialized);
})

Overlapping Highlight Handling

The library supports four modes for handling overlapping highlights:

Configuration

const marker = new Marker({
    rootElement: document.body,
    overlappingHighlight: 'merge', // or 'dontCreateNewHighlight', 'deleteOverlappedHighlight', or 'allow' (default)
    eventHandler: {
        onHighlightDeleted: (context) => {
            // Called when a highlight is automatically deleted due to overlap
            console.log('Highlight deleted:', context.serializedRange.uid);
            // Clean up from your storage here
        }
    }
});

Modes

"allow" (default)

  • Permits overlapping highlights to coexist
  • Multiple highlights can exist in the same text region
  • Original behavior

"dontCreateNewHighlight"

  • Prevents creating new highlights that overlap with existing ones
  • serializeRange() returns null if overlap is detected
  • No existing highlights are modified
  • Useful when you want to prevent overlapping annotations
const serialized = marker.serializeRange(range);
if (!serialized) {
    alert('Cannot create highlight: overlaps with existing highlight');
} else {
    marker.paint(serialized);
}

"deleteOverlappedHighlight"

  • Automatically removes existing highlights that intersect with the new selection
  • The onHighlightDeleted event handler is called for each deleted highlight
  • Allows applications to clean up their state (localStorage, database, etc.)
  • Useful when the most recent highlight should take precedence
const highlights = {};

const marker = new Marker({
    overlappingHighlight: 'deleteOverlappedHighlight',
    eventHandler: {
        onHighlightDeleted: (context) => {
            const uid = context.serializedRange.uid;
            delete highlights[uid];
            localStorage.setItem('highlights', JSON.stringify(highlights));
        }
    }
});

"merge"

  • Automatically expands the selection to encompass all overlapping highlights
  • Creates one unified highlight that covers the entire merged range
  • Existing overlapping highlights are removed and onHighlightDeleted is called for each
  • The user's selection visually "snaps" outward to show the merged boundaries
  • Useful for combining adjacent or overlapping annotations into a single continuous highlight
const highlights = {};

const marker = new Marker({
    overlappingHighlight: 'merge',
    eventHandler: {
        onHighlightDeleted: (context) => {
            // Clean up the old fragments that were merged
            const uid = context.serializedRange.uid;
            delete highlights[uid];
            localStorage.setItem('highlights', JSON.stringify(highlights));
        }
    }
});

// When user creates a highlight that overlaps existing ones,
// it will automatically expand to cover all overlapping highlights

How to build library

npm run build-lib
npm pack

Built with web-marker

  • notelix/notelix: An open source web note taking / highlighter software (chrome extension with backend)