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

themepark

v2.2.0

Published

Reactive CSS Variables

Downloads

15

Readme


Features

  • Write reactive CSS with minimal overhead
  • Isomorphic (importable on both server and browser)
  • Works on all modern browsers: Browser Compatibility
  • Super easy to support night mode

Usage

1. Import Themepark

Install package (via npm)

npm i themepark
// ESM syntax
import { themepark } from 'themepark';
// CJS syntax
var { themepark } = require('themepark')

Script tag (via unpkg):

<!-- Available as global variable themepark -->
<script src="https://unpkg.com/themepark"></script>
<!-- Later -->
<script>
  let theme = themepark(/***/); // theme parameters / definitions go here
</script>

Browser Module (via skypack):

import { themepark } from 'https://cdn.skypack.dev/themepark';

2. Create and use theme

  // Initialize theme
  let theme = themepark({
    night: false,
    hue: 220
  }, ({ night, hue }) => ({
    primary: `hsl(${hue}, 100%, 50%)`,
    background: night ? `hsl(${primary}, 20%, 20%)` : `white`,
    text: night ? `white` : `hsl(200, 20%, 20%)`
  }))

  // Subscribe to changes in the theme
  let unsub = theme.$(({ night, hue, primary, background, text }) => {
    console.log(night) // false
    console.log(primary) // hsl(220,100%,50%)
  })

  // Unsubcribe from updates
  unsub()

  // Apply CSS var definitions to the body element and auto-subscribe to updates
  theme.$('body')

  // Directly access values (sync)
  console.log(theme.$.primary) // `hsl(220,100%,50%)`
  console.log(theme.$.night) // false

  // Update theme granularly
  theme.hue = 120;

  // Update theme with multiple changes
  theme({
    hue: 320,
    night: true
  })

  // Get CSS var definitions as string
  console.log(theme.toString()) // --primary:hsl(320,100%,50%);--background:hsl(320,20%,20%);--text:white;

  // Get var reference as string
  console.log(theme.text) // var(--text)
  

API

let theme = themepark(parameters, definitions)

Creates a new instance of Themepark

parameters: stateful values that can be used by definitions and can updated to trigger a recalculation of styles definitions: a function that takes parameters as its input and returns an object corresponding to the desired CSS variables

Example

let theme = themepark({
  night: true,
  hue: 220
}, ({ night, hue }) => ({
  primary: `hsl(${hue}, 100%, 50%)`, // primary color depends on the hue in parameters
  bg: night ? `#112` : `#fff` // if night mode, dark background - else, white background
}))

theme.$(() => {})

Subscribe to theme updates


theme.$(CSS_Query)

Finds all DOM elements with matching CSS query and automatically style those elements


theme.$[var_name]

Synchronously get the value of var_name


theme[var_name]

Get the string of the CSS variable (for inserting directly into styles)

Ex: theme.primary ~> "var(--primary)"


theme[param] = value

Update a parameter, recompute css vars, and trigger all subscribers to update


theme(obj)

Assigns all properties in obj to params and triggers all subscribers to update


License

MIT © Marshall Brandt