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

unlight

v2.1.1

Published

Unlight is a powerful library that helps you quickly convert your website into a rich and dynamic dark mode. It's fast, reliable, and highly customizable. Get started with Unlight to create great dark modes.

Downloads

4

Readme

Unlight

Unlight is a powerful library that helps you quickly convert your website into a rich and dynamic dark mode. It's fast, reliable, and highly customizable. Get started with Unlight to create great dark modes.

Getting Started

Unlight offers you the option to assign special classes to specific elements when activating a certain site-wide theme. You can them style these element classes to make it suitable for your site.

Importing Unlight

Unlight CDN

<!-- Import the Unlight CDN -->
<script src="//cdn.jsdelivr.net/npm/unlight/index.js"></script>

<!-- Rest of the code should be AFTER all the body and Unlight script tag -->
<script src="script.js"></script>

Hosting Unlight Locally

Download the Unlight index.js file and import it the same as how you would import the CDN:

<!-- Import the locally hosted Unlight lib -->
<script src="/path/to/unlight.js"></script>

<!-- Rest of the code should be AFTER all the body and Unlight script tag -->
<script src="script.js"></script>

Activating Unlight Dark Mode/Other Themes

Please note that Unlight does not automatically style everything for you. It will only style the background color you define when Unlight is activated. Styling will require CSS after all class definitions have been made. Familiarize yourself with the Unlight class definition:

const unlight = new Unlight({
	background: "black", // default: #141414
	classes: {
		"*": "darkmode", // assigns .darkmode class to all elements
		h1: "override" // adds .override class on h1
	},

	// Organizes persistence so the theme is saved in the browser
	persistent: true,
	persistenceIdentifier: "myID"
});

unlight.activate(); // Calls activate function

Custom background (optional)

// this defines the background color of body
const unlight = new Unlight({
	background: "black", // default: #141414
});

unlight.activate(); // Calls activate function

Assign dark mode classes (required)

// This assigns custom classes to the h1 and p tags.
const unlight = new Unlight({
	classes: {
		h1: "darkmode-h1",
		p: "darkmode-p"
	}
});

unlight.activate(); // Calls activate function

Note: If you want to assign a class to everything, use "*": "class-name" for the selector. You may use other special CSS selectors as well.

Adding styles

Now that you've assigned classes to everything you want, let's style them using CSS!

JS:

const unlight = new Unlight({
	background: "black", // default: #141414
	classes: {
		"*": "darkmode", // assigns .darkmode class to all elements
		h1: "override" // override .darkmode class on h1
	}
});

unlight.activate(); // Calls activate function

CSS:

.darkmode {
	color: white;
}

.darkmode code {
	background-color: #373737;
}

.override {
	color: mediumseagreen;
}

There we go! We've just added all the styles for our custom dark theme.

Deactivating Unlight

After activating Unlight, you will definitely need to deactivate it at some point.

Deactivating is very simple (after you've activated it already):

unlight.deactivate(); // Calls deactivate function

Persistence

Unlight offers a reliable persistence feature for custom themes. User preferences for themes will be saved in the browser localStorage. Additionally, this feature is fully backwards compatible, but it's always best to use the latest version as support will eventually drop for older versions.

To activate persistence in your theme declaration:

const unlight = new Unlight({
	background: "black",
	classes: {
		p: "classforpara",
		"*": "dark",
		h1: "override"
	},
	// Add these //
	persistence: true,
	// Make sure you declare a UNIQUE identifier
	// It is used to seperate different persistent classes
	persistenceIdentifier: "mycustomtheme"
});

The persistence identifer allows Unlight to manage multiple declared themes which are all persistent. By default, persistence is turned off. persistenceIdentifier is NECESSARY if you choose to make the theme persistent.

Note: If you have multiple themes, and you activate one of them, all of the other themes will automatically be turned off. This is to prevent overlapping or unappealing, unintended theme mixing.

Restricted Variable unlightInstances

Unlight persistent uses a variable which cannot be redeclared or should not be modified unless intentional. The variable is called unlightInstances. It monitors all the instances in which Unlight is declared on. This is how persistence is kept track of and how all the Unlight instances can interact with each other. If the name unlightInstances interferes with your code, download Unlight code and replace all occurances of unlightInstances with a preferred variable name.

Other VERY USEFUL Things

If you want to know whether or not dark mode is active, check the unlight.isActive property. It will return true if Unlight is active and false if not.

As stated earlier, when assigning classes to specific elements in Unlight, you can also use special CSS selectors e.g.

// special class to input elements with type 'text'
const unlight = new Unlight({
	background: "black",

	classes: {
		h1: "darkmode-h1",
		// Only selects text inputs
		"input[type=\"text\"]": "darkmode-textinputs"
	}
});

unlight.activate();

When deactivating Unlight, not want to revert completely and keep a few classes active. Normally, Unlight switches itself off by removing all the classes you've defined in the Unlight class definition. So in the deactivate() function, you can define your own restoreState. The restore state is an array of all the classes to be removed when the deactivate() function is called. But note that if you don't want the background to restore, pass false into the second parameter:

// Unlight will remove all the classes in this array 
unlight.deactivate(["remove-this-class", "and-this"], false);
// false prevents the background from reverting to the original

Unlight is licensed under the MIT license