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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cytoscape-css-variables

v0.1.4

Published

[![Example Link](./docs/example.jpg)](https://cytoscape-css-variables.netlify.app/)

Downloads

290

Readme

🎨 Example

Example Link

📦 Install

Download the library:

  • via npm: npm install cytoscape-css-variables,
  • via unpkg: https://unpkg.com/cytoscape-css-variables/dist/cytoscape-css-variables.js

Import the library as appropriate for your project:

ES import:

import cytoscape from 'cytoscape';
import cssVars from 'cytoscape-css-variables';

cytoscape.use( cssVars );

CommonJS require:

let cytoscape = require('cytoscape');
let cssVars = require('cytoscape-css-variables');

cytoscape.use( cssVars ); // register extension

AMD:

require(['cytoscape', 'cytoscape-css-variables'], function( cytoscape, cssVars ){
  cssVars( cytoscape ); // register extension
});

Plain HTML/JS has the extension registered for you automatically, because no require() is needed.

🔥 API

// core cytoscape instance
let cy

// cssVars extension instance
let css_vars

// Can't call css_vars before it is initiated, so declaring the function here
const getVar = (variable) => (css_vars ? css_vars.getVar(variable) : null)

cy = cytoscape({
  container: document.getElementById('cy'),
  style: [
    {
      selector: 'node',
      style: {
        // Use getVar() with the css variable name to use it
        // - this can be used for more than just colors
        // - getVar() here is a local function, NOT the extension function
        'background-color': () => getVar('--theme-primary'),
      },
    },
  ],
  // your array elements go here
  elements: [],
})

// cssVars takes two (optional) values,
// initialVars object and the domEl to assign the vars to/from
cy.cssVars({
  initialVars: {
    '--theme-primary': 'rgb(245, 204, 0)',
    '--theme-secondary': 'rgb(0, 8, 20)',
    '--theme-tertiary': 'rgb(234,84,85)',
    '--cy-node-size': 30,
  },
  domEl: document.body,
})

// no updates will be made until update() is called (even on init)
// this allows you to bulk change css vars but only run one update
// NOTE: this will need to be run after any set of set/get/remove functions
css_vars.update()

// assigns a value to a variable
css_vars.setVar('--theme-primary', 'rgb(245, 204, 0)')

// removes a variable and its value by the variable name
css_vars.removeVar()

// returns an object of css variables and their values
// will match the initialVars object to be passed in on init
css_vars.getVars()

// bulk add variables
// will match the initialVars object to be passed in on init
css_vars.addVars()

// removes all variables and their values
css_vars.resetVars()

// sets the current active DOM element
css_vars.setDomEl()

📢 Publishing

Make sure you have np installed

  1. Commit changes to Github
  2. Run yarn publish
  3. Profit 💰