UNPKG

rampensau

Version:

Color ramp generator using curves within the HSL color model

116 lines (115 loc) 3.98 kB
var fettepalette = (() => { var y = Object.defineProperty; var C = Math.pow; var I = (e) => y(e, "__esModule", { value: !0 }); var F = (e, r) => { I(e); for (var o in r) y(e, o, { get: r[o], enumerable: !0 }); }; var O = {}; F(O, { generateRandomColorRamp: () => G, generateRandomColorRampParams: () => N, hsv2hsl: () => R, hsv2hsx: () => c, pointOnCurve: () => M, }); var R = (e, r, o, t = o - (o * r) / 2, p = Math.min(t, 1 - t)) => [ e, p ? (o - t) / p : 0, t, ], c = (e, r, o, t) => (t === "hsl" ? R(e, r, o) : [e, r, o]), M = (e, r, o, t, p = [0, 0], m = [1, 1]) => { let x = Math.PI / 2, u = x / o, s = r / o, a = 0, n = 0; if (e === "lam\xE9") { let l = s * x, i = 2 / (2 + 20 * t), h = Math.cos(l), f = Math.sin(l); (a = Math.sign(h) * C(Math.abs(h), i)), (n = Math.sign(f) * C(Math.abs(f), i)); } else if (e === "arc") (n = Math.cos(-Math.PI / 2 + r * u + t)), (a = Math.sin(Math.PI / 2 + r * u - t)); else if (e === "pow") (a = Math.pow(1 - s, 1 - t)), (n = Math.pow(s, 1 - t)); else if (e === "powY") (a = Math.pow(1 - s, t)), (n = Math.pow(s, 1 - t)); else if (e === "powX") (a = Math.pow(s, t)), (n = Math.pow(s, 1 - t)); else if (typeof e == "function") (a = e(s)[0]), (n = e(s)[1]); else throw new Error( `pointOnCurve() curveAccent parameter is expected to be "lam\xE9" | "arc" | "pow" | "powY" | "powX" or a function but \`${e}\` given.` ); return ( (a = p[0] + Math.min(Math.max(a, 0), 1) * (m[0] - p[0])), (n = p[1] + Math.min(Math.max(n, 0), 1) * (m[1] - p[1])), [a, n] ); }; function G({ total: e = 3, centerHue: r = 0, hueCycle: o = 0.3, offsetTint: t = 0.1, offsetShade: p = 0.1, curveAccent: m = 0, tintShadeHueShift: x = 0.1, curveMethod: u = "arc", offsetCurveModTint: s = 0.03, offsetCurveModShade: a = 0.03, minSaturationLight: n = [0, 0], maxSaturationLight: l = [1, 1], colorModel: i = "hsl", } = {}) { let h = [], f = [], w = []; for (let b = 1; b < e + 1; b++) { let [S, T] = M(u, b, e + 1, m, n, l), d = (360 + (-180 * o + (r + b * (360 / (e + 1)) * o))) % 360, k = c(d, S, T, i); h.push(k); let [P, X] = M(u, b, e + 1, m + s, n, l), V = c(d, P, X, i); f.push([(d + 360 * x) % 360, V[1] - t, V[2] + t]); let [Y, H] = M(u, b, e + 1, m - a, n, l), g = c(d, Y, H, i); w.push([(360 + (d - 360 * x)) % 360, g[1] - p, g[2] - p]); } return { light: f, dark: w, base: h, all: [...f, ...h, ...w] }; } var N = { curveMethod: { default: "lam\xE9", props: { options: ["lam\xE9", "arc", "pow", "powY", "powX"] }, }, curveAccent: { default: 0, props: { min: -0.095, max: 1, step: 0.001 } }, total: { default: 9, props: { min: 3, max: 35, step: 1 } }, centerHue: { default: 0, props: { min: 0, max: 360, step: 0.1 } }, hueCycle: { default: 0.3, props: { min: -1.25, max: 1.5, step: 0.001 } }, offsetTint: { default: 0.01, props: { min: 0, max: 0.4, step: 0.001 } }, offsetShade: { default: 0.01, props: { min: 0, max: 0.4, step: 0.001 } }, tintShadeHueShift: { default: 0.01, props: { min: 0, max: 1, step: 0.001 }, }, offsetCurveModTint: { default: 0.03, props: { min: 0, max: 0.4, step: 1e-4 }, }, offsetCurveModShade: { default: 0.03, props: { min: 0, max: 0.4, step: 1e-4 }, }, minSaturation: { default: 0, props: { min: 0, max: 1, step: 0.001 } }, minLight: { default: 0, props: { min: 0, max: 1, step: 0.001 } }, maxSaturation: { default: 1, props: { min: 0, max: 1, step: 0.001 } }, maxLight: { default: 1, props: { min: 0, max: 1, step: 0.001 } }, }; return O; })();