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

@zachleat/heading-anchors

v1.0.1

Published

Adds and positions sibling anchor links for heading elements (h1,h2,h3,h4,h5,h6) when they have an `id` attribute.

Downloads

381

Readme

<heading-anchors> Web Component

A web component to add and position sibling anchor links for heading elements (h1h6) when they have an id attribute.

Inspired by David Darnes’ <heading-anchors>.

  • Demo on GitHub Pages

Installation

npm install @zachleat/heading-anchors

Include the heading-anchors.js file on your web site (via <script type="module">) and use <heading-anchors>.

Features

  • Useful when you want preserve heading text as is (selectable, able to nest other links, etc).
  • Useful when you want to exclude anchor links from your RSS feed.
  • Links are positioned alongside heading text, but not nested inside of headings (for improved screen-reader compatibility and accessibility)
  • Establishes a placeholder element to establish space for the anchor link and so that heading text doesn’t reflow during interaction
  • Prefers the CSS Anchoring API (where available) but works using JavaScript positioning when the API is not available.
  • Automatically matches font styling of the heading (font-family, line-height, font-size, and font-weight)

Options

  • Use the selector attribute to change the headings used, e.g. <heading-anchors selector="h2,h3,h4">
    • Default: h2,h3,h4,h5,h6
  • Internationalization (i18n) friendly using the prefix attribute to change the accessible text inside the anchor links, e.g. <heading-anchors prefix="Ir a la sección titulada">
    • Default: Jump to section titled
  • Use the content attribute to change the character used.
    • Default: #
  • Style the anchor link using .ha-placeholder selector (change font-family, etc).

Prior Art

  • https://github.com/daviddarnes/heading-anchors
  • https://amberwilson.co.uk/blog/are-your-anchor-links-accessible/ (which has a lot of good related content too)

Advanced

Eliminate Layout Shift

(Optional) There is a small layout shift by the addition of the # character. Add this CSS to make room for this pre-component definition:

heading-anchors:not(:defined) :is(h2,h3,h4,h5,h6):after {
	content: "#";
	padding: 0 .25em;
	opacity: 0;
}