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 🙏

© 2024 – Pkg Stats / Ryan Hefner

navmap

v0.3.1

Published

Show whatever you want in the scrollbar.

Downloads

6

Readme

navmap

Show all the titles on your page in the scrollbar. Playground

Install

npm install navmap

Usage

import navmap from 'navmap'
// hide scrollbar styles
import 'navmap/style.css'

const options: Options = { ... }

const unmount = navmap(options)

// cleanup
unmount()

Options

| Name | Type | Default | Description | | --- | --- | --- | --- | | viewport | HTMLElement | Element | document.body | The scrolling container you want to observe. | | plugins | Array | [] | The plugins you want to use. | | canvas | {width?:number; height?:number; className?:string} | {width: 15, height:window.innerHeight, className: ''} | The canvas options. |

Basic Plugin

The library has a built-in scrollbar plugin, and an additional contents plugin is available, and you can also build your own plugin according to the effect you want.

use Contents plugin

import Contents from 'navmap/contents'

const options: Options = {
  plugins: [
    Contents({
      fillStyle: '#ccc',
      selector: 'h1, h2, h3, h4, h5, p'
    })
  ]
}

navmap(options)

Plugin Types

type PluginStates = {
  scrollTop: number;
  scaleRatio: number;
  scrollHeight: number;
}

export type LifecycleFn<PluginContext> = (
  this: PluginContext,
  ctx: CanvasRenderingContext2D,
  opt: { states: PluginStates } & Pick<Options, 'viewport' | 'canvas'>
) => void

export type Plugin<Context = Record<string, any>> = {
  // The order in which the plug-in executes when invoked
  enforce?: 'pre' | 'post'

  // The plugin initializes the hook function (which executes only once)
  init?: LifecycleFn<Context>

  // Executed when viewport scrolls / viewport size changes
  draw?: LifecycleFn<Context>

  // When the viewport descendant element changes
  // (it will be executed immediately after the application is mounted)
  update?: LifecycleFn<Context>

  // The plugin destroys the hook function (which executes only once)
  destroy?: LifecycleFn<Context>
} & Context

Custom Plugin

The plugin has 4 hook functions, but they are all optional, meaning it is allowed not to set them. If you want to develop your own plugin, you can check the contents plugin example for extended development. The this inside the plug-in hook function points to the plug-in itself, so you can set other properties on the plug-in to help you complete the function you want.

import navmap, { Plugin } from 'navmap'

const MyObjectPlugin: Plugin = {
  init() {
    // ...
  },
  draw() {
    // ...
  },
  update() {
    // ...
  },
  destroy() {
    // ...
  }
}

const MyFunctionPlugin = (): Plugin => ({
  init() {
    // ...
  },
  draw() {
    // ...
  },
  update() {
    // ...
  },
  destroy() {
    // ...
  }
})

const options: Options = {
  plugins: [
    MyObjectPlugin,
    MyFunctionPlugin()
  ]
}

navmap(options)

Thank you for using. Finally, I wish you a good time. If you have any questions or dissatisfaction, you can leave a message in issues to discuss together.