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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@net7/annotator

v1.0.1

Published

Anchoring and highlighting library for web documents

Readme

@net7/annotator

npm version TypeScript License Build Status

A framework-agnostic TypeScript library for anchoring and highlighting text in web documents with intelligent fallback strategies.

✨ Features

  • 🎯 Multiple anchoring strategies with automatic fallback
  • 📝 Text highlighting with customizable styles
  • 🌐 Framework-agnostic - works with any JavaScript framework
  • 🔧 TypeScript support with full type definitions
  • 📱 PDF document support for complex layouts
  • Event-driven architecture for reactive applications
  • 🎨 Context-aware filtering for multi-document apps

🚀 Quick Start

Installation

npm install @net7/annotator
# or
yarn add @net7/annotator

Basic Usage

import { Annotator } from '@net7/annotator';

// Create annotator instance
const annotator = new Annotator();

// Set document context
annotator.setContext({ documentId: 'doc-123' });

// Create annotation from user selection
const selection = window.getSelection();
if (selection && selection.rangeCount > 0) {
  const result = annotator.createAnnotation({
    root: document.body,
    range: selection.getRangeAt(0),
    context: { documentId: 'doc-123' },
    color: '#FFFF00',
    metadata: { comment: 'Important note' },
  });

  console.log('Annotation created:', result);
}

📖 API Reference

Annotator Class

Constructor

new Annotator(options?: { allowWhitespace?: boolean })

Key Methods

| Method | Description | | -------------------------- | -------------------------------------- | | setContext(context) | Set document context for filtering | | createAnnotation(params) | Create annotation from DOM range | | load(annotations, root) | Load multiple annotations | | remove(annotationId) | Remove annotation by ID | | getEvents() | Get event emitter for highlight events |

Event Handling

// Listen to highlight events
annotator.getEvents().on('highlight', (event) => {
  console.log('Highlight event:', event.type, event.payload);
});

🏗️ Architecture

The library uses a smart anchoring system with automatic fallback:

  1. RangeSelector (Most precise) - DOM node references
  2. TextPositionSelector (Reliable) - Character offsets
  3. TextQuoteSelector (Robust) - Text content matching

When one strategy fails, it automatically tries the next one, ensuring maximum reliability across different document states.

📊 Advanced Usage

Loading Multiple Annotations

// Load existing annotations
const annotations = await fetchAnnotations();
annotator.load(annotations, document.body);

// Context-aware filtering
annotator.setContext({
  documentId: 'doc-123',
  pageNumber: 5,
  userId: 'user-456',
});

Custom Event Handling

const annotator = new Annotator({ allowWhitespace: true });

annotator.getEvents().on('highlight', (event) => {
  if (event.type === 'click') {
    showAnnotationDetails(event.payload);
  }
});

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for your changes
  4. Ensure all tests pass (npm test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

🧪 Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Build library
npm run build

# Lint code
npm run lint

📚 Examples

Check out the docs/ directory for:

  • Basic usage examples
  • Advanced demo with full UI
  • TypeScript integration examples

📄 License

This project is licensed under the BSD-2-Clause License - see the LICENSE file for details.

Third-Party Attributions

This library incorporates code from:

See NOTICE for complete attribution details.