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 🙏

© 2026 – Pkg Stats / Ryan Hefner

css-magic-gradient

v1.0.3

Published

Generate CSS gradients (linear, radial, conic) with zero dependencies. Vue plugin included.

Readme

css-magic-gradient

Generate CSS gradients (linear, radial, conic) with zero dependencies. TypeScript-first, Vue plugin included.

Installation

npm install css-magic-gradient

Usage (Vanilla/TypeScript)

import { createLinearGradient, createRadialGradient, createConicGradient } from 'css-magic-gradient';

const linear = createLinearGradient('#ff0000');
const radial = createRadialGradient('#00ff00');
const conic = createConicGradient('#0000ff');

API & Options

Linear Gradient

createLinearGradient(baseColor, options?)

  • baseColor (string): Base color (hex, CSS variable, etc)
  • options (object, optional):
    • offsetPercent (number): Brightness offset for the start color, -100 to 100 (default: 15)
    • direction (string): CSS direction, e.g. 'to right', 'to bottom', or custom (default: 'to bottom')
    • angle (number): Angle in degrees (overrides direction)
    • fallbackColor (string): Fallback color if variable not found (default: '#f5e477')

Custom color stops example:

For fully custom color stops and positions, pass an array of stops as the first argument to createLinearGradient:

import { createLinearGradient } from 'css-magic-gradient';

const gradient = createLinearGradient([
  { color: '#00f', position: '0%' },
  { color: '#fff', opacity: 0.5, position: '50%' },
  { color: '#f00', position: '100%' }
], {
  direction: 'to right'
});
// Produces a linear gradient with custom color stops and positions

Radial Gradient

createRadialGradient(baseColor, options?)

  • baseColor (string): Base color
  • options (object, optional):
    • offsetPercent (number): Brightness offset for the start color (default: 15)
    • fallbackColor (string): Fallback color (default: '#f5e477')
    • shape ('circle' | 'ellipse'): Shape of the gradient (default: 'ellipse')
    • size (string | { width: string, height: string }): Size, e.g. '50% 50%' or object (default: 'farthest-corner')
    • position (string): Center position, e.g. 'center', '50% 50%' (default: 'center')
    • useCustomColors (boolean): Use custom color stops (see below)
    • colors (array): Custom color stops: { color, opacity?, position? }
    • layers (array): Multi-layer gradients, each with its own shape/size/colors

Custom color stops example:

createRadialGradient('#00f', {
	useCustomColors: true,
	colors: [
		{ color: '#00f', position: '0%' },
		{ color: '#fff', opacity: 0.5, position: '100%' }
	]
})

Conic Gradient

createConicGradient(baseColor, options?)

  • baseColor (string): Base color
  • options (object, optional):
    • fromAngle (number): Start angle in degrees (default: 0)
    • position (string): Center position (default: '50% 50%')
    • fallbackColor (string): Fallback color (default: '#f5e477')
    • colors (array): Custom color stops: { color, opacity?, position? }
    • hueRotation (boolean): Use hue rotation for steps (default: false)
    • steps (number): Number of steps for auto-generation (default: 8)
    • offsetPercent (number): Brightness offset for steps (default: 20)

Custom color stops example:

createConicGradient('#f00', {
	colors: [
		{ color: '#f00', position: '0%' },
		{ color: '#0f0', position: '50%' },
		{ color: '#00f', position: '100%' }
	]
})

Color Utilities

The package also exports a set of helper utilities for working with colors. Import them from the package, for example: import { normalizeHex, isHexColor } from 'css-magic-gradient'.

  • isCssVariable: Check if a string is a CSS variable (e.g. var(--main)).
  • isHexColor: Detect hex color strings (3- or 6-digit, with or without #).
  • isRgbColor: Detect rgb() / rgba() color strings.
  • isHslColor: Detect hsl() / hsla() color strings.
  • getColorType: Returns the color type: hex, css-var, rgb, hsl, named, or unknown.
  • extractCssVariableName: Extracts the CSS variable name from var(--name).
  • normalizeHex: Normalizes and validates hex strings, returns a 6-digit lowercase hex (fallback #f5e477).
  • hexToRgb: Convert a hex color to an [r, g, b] tuple.
  • hexToRgba: Convert a hex color to an rgba(...) string with opacity.
  • hexToHsl: Convert a hex color to an [h, s, l] tuple.
  • hslToHex: Convert HSL values to a hex color string.
  • adjustHexBrightness: Lighten or darken a hex color by a percentage offset.
  • rotateHue: Rotate the hue of a hex color by degrees.

Vue 3 Plugin & Reactive Hooks

This package provides a Vue 3 plugin and composition API hooks for fully reactive gradients.

Register plugin (optional)

import { createApp } from 'vue';
import App from './App.vue';
import { VueGradientPlugin } from 'css-magic-gradient';

const app = createApp(App);
app.use(VueGradientPlugin);

Usage in setup()

import { ref } from 'vue';
import { useLinearGradient, useRadialGradient, useConicGradient } from 'css-magic-gradient';

const color = ref('#ff0000');
const options = ref({ direction: 'to right' });

const linearGradient = useLinearGradient(color, options); // ComputedRef<string>
const radialGradient = useRadialGradient(color);
const conicGradient = useConicGradient(color);

Usage via globalProperties (if plugin registered)

// In any component:
const gradient = this.$useLinearGradient('#00f');

Author

Danil Lisin Vladimirovich aka Macrulez

GitHub: macrulezru

Website: macrulez.ru

License

MIT