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

@jayfreestone/limelight.js

v2.1.0

Published

A tiny (and fast) JavaScript plugin that creates a spotlight around any element on the page.

Downloads

5

Readme

Limelight ✨

Banner image

A tiny (and fast) JavaScript plugin that creates a spotlight around any element on the page.

Docs

Installation

Import the module as you would any other ES6 module:

import Limelight from 'limelight';

And include the CSS file (dist/styles/style.css) either through a link tag or as part of your build process.

Setup/basic usage

In order to use Limelight, you'll need to have a 'wrapper' div around your site with position: relative set on it. This is the element Limelight will append its absolutely-positioned overlay to.

<body>
  <!-- Wrapper div -->
  <div class="site-wrapper">
	<!-- Your site content. -->
  </div>
</body>

Set up a new instance by passing the target (i.e. the element you want to highlight) as the first argument to the class, and your global site wrapper as the second argument:

const inst = new Limelight(
  document.querySelector('.target-to-highlight')
  document.querySelector('.site-wrapper'),
);

Then you can open the instance with the open method:

inst.open();

And change the target with refocus:

inst.refocus(document.querySelector('.new-target'));

Customisation/options

You can customise several options through CSS custom properties:

| Property | Description | Example | |:--|:--|:--| | --limelight-bg | The background colour of the overlay. | rgba(0, 0, 0, 0.8) | | --limelight-overlay-transition-duration | The transition-duration of the overlay | 0.3s | | --limelight-window-transition-duration | The transition-duration on the windows (i.e. when the target changes). | 1s | | --limelight-z-index | The z-index of the overlay. | 999 |

These can be applied directly as an override on the .limelight CSS class. Alternatively they can be applied on creation as part of the options object.

About

Most tooltip-tours include a blackout-style overlay that 'shines' a light on the target element. The problem is that it can be extremely hard to do that well. Traditionally you have two options:

  • Add an overlay and promote the target's z-index. This is pretty good, but it relies on the target having a background, or it'll just be placed over the overlay. The element also has to have positioning for the z-index to even work (even if it's just relative, this can mess with stuff).
  • Use an SVG mask. This works great, and was actually my first pass while creating this lib. However performance while animating (or even just repositioning) the mask was terrible in everything other than Blink, and Quantum doesn't event support transitions on mask transformations at all. Probably the best idea but not a great experience.
  • Create 4 boxes that surround the target and transform them appropriately. A solid approach, but can get super complex if there are multiple targets to 'cut out' of the backdrop. Also you're positioning 4 boxes simultaneously.

However I saw a really neat implementation in react-joyride that uses mix-blend-mode. Nothing is 'cut out' of the overlay, and the element still sits beneath it. However we can position a div on top of the area we want to make transparent, and use hard-light to give the appearance it's showing through.

Caveats

  • Absolutely positioned elements within the target (e.g. a tooltip) will not be visible, since we can't include them in the target calculations. This is where the z-index approach has us beat.
  • There needs to be a site wrapper (just a div after body is fine) that has a background-color, even if it's just white. Otherwise there's nothing to blend with. Weirdly it doesn't always work just putting it on body directly.
  • At this moment border-radius is not supported. This is due to the fact that the windows are just 1x1 boxes that are scaled up in order to meet the target dimensions. The solution here would be to FLIP the animations, meaning that the final width/height are properly applied. However even then the border-radius would be distorted pre/during the transition. I'm not convinced there's a great solution here.

Cool stuff

  • Auto-adjusts if the height of the target changes (or anything else on the page). Uses a MutationObserver to respond to any changes to the DOM.
  • Performant transitions between targets. Since we're just transforming a div, we don't suffer from the perf issues associated with an SVG mask.