UNPKG

@privjs/gradients

Version:

Javascript utility to generate beautiful gradient backgrounds. Built by the team behind [privjs.com](https://privjs.com)

26 lines (25 loc) 1.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStopsArray = exports.genStops = void 0; const chroma_js_1 = __importDefault(require("chroma-js")); const utils_1 = require("./utils"); const genStops = ({ color1, color2, numOfStops }) => { return chroma_js_1.default.scale([color1, color2]).mode('lch').colors(numOfStops, 'hsl'); }; exports.genStops = genStops; const getStopsArray = (stops, easingCurve) => { return stops.map((color, index) => { const xTarget = index / (stops.length - 1); let y = (0, utils_1.getYValueForBezier)(xTarget, 1 - easingCurve[0].y, easingCurve[0].x, 1 - easingCurve[1].y, easingCurve[1].x); y = Math.round((0, utils_1.normalize)(y, 0, 1, 0, 100)); // If this color is grayscale const hue = isNaN(color[0]) ? 0 : Math.round(color[0]); // const hslString = `hsl(${hue}deg ${}% ${}%)`; const hslString = `hsl(${hue}deg ${Math.round(color[1] * 100)}% ${Math.round(color[2] * 100)}%)`; return `${hslString} ${y}%`; }); }; exports.getStopsArray = getStopsArray;