r/learnjavascript • u/Infamous_Treat_1804 • 16d ago
I built Spotlight.JS — A lightweight, zero-dependency JavaScript library for interactive page highlights and spotlights
Hey everyone! 👋
I wanted to share an open-source library I've been building and refining called Spotlight.JS.
Why did I build it? I needed a dead-simple, highly customizable way to highlight DOM elements, build guided product tours, or draw user attention to specific UI components without pulling in bloated dependencies or heavy styling frameworks.
Key Features:
🚀 Zero Dependencies: Extremely lightweight and fast.
🎯 Precise Positioning: Automatic viewport boundary detection, custom offsets, and smooth scrolling.
🎨 Flexible Styling: Easy-to-override classes and smooth backdrop masking.
🧩 Interactive Popovers: Built-in support for titles, descriptions, step-by-step navigation buttons, and custom rendering.
Tech Stack / Implementation: Built in vanilla JavaScript/ESM modules, making it framework-agnostic (works seamlessly with React, Vue, Vanilla JS, etc.).
Links:
GitHub Repo:https://github.com/Rahulchaube1/-Spotlight.JS
I’d love for you to check it out, test it, and let me know what you think! PRs, issues, and feature requests are very welcome. If you find it useful, a star on GitHub would mean the world to me ⭐!
1
u/unicornshedsocial 15d ago
The hard part isn't drawing the mask, it's cleanup: if the target element unmounts mid-tour, the spotlight should close instead of pointing at empty space. Does it watch for the target being removed?
1
u/Discordbothost 14d ago
one thing i always check with overlay tours: does it still line up if the target lives in a shadow root? a lot of these measure getBoundingClientRect on a light-dom selector and then the hole draws in the wrong place. also the repo slug starting with a hyphen (-Spotlight.JS) is easy to mistype when someone is looking for the actual script file — might be why people can't find a drop-in build.
-1
u/patryk_builds 16d ago
Nice, product tours are one of those things where most libraries pull in way more than you need.
Two things i'd check first with any spotlight library:
- what happens when the target element is inside a scrollable container, not the page? that's where a lot of positioning breaks
- accessibility: does the popover trap focus, close on Escape, and announce itself to screen readers? tours that only work with a mouse lock out keyboard users completely
Also mentioning the bundle size in KB in the README would make lightweight a lot more convincing
-3
u/Infamous_Treat_1804 16d ago
Spot on! Those are literally the two biggest pain points with most tour libraries. Here’s how Spotlight.js tackles both:
Really appreciate the thoughtful feedback! If you test it in your app, I’d love to hear how it holds up with your scroll containers.
5
u/TylerDurdenJunior 16d ago
Hi LLM.
You forgot to actually mention how you tackle them.
Christ. Even the comments are slop
6
u/theGlitchedSide 16d ago
I have some difficult to find the right script... Is it vibe coding?