UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

44 lines (43 loc) 1.16 kB
import Color from "../Color.js"; import type from "../utils/type.js"; Color.prototype.set = function(mc, value, mutate = false) { const [mode, channel] = mc.split("."); const src = this[mode](); if (channel) { const i = mode.indexOf(channel) - (mode.substr(0, 2) === "ok" ? 2 : 0); if (i > -1) { if (type(value) == "string") { switch (value.charAt(0)) { case "+": src[i] += +value; break; case "-": src[i] += +value; break; case "*": src[i] *= +value.substr(1); break; case "/": src[i] /= +value.substr(1); break; default: src[i] = +value; } } else if (type(value) === "number") { src[i] = value; } else { throw new Error(`unsupported value for Color.set`); } const out = new Color(src, mode); if (mutate) { this._rgb = out._rgb; return this; } return out; } throw new Error(`unknown channel ${channel} in mode ${mode}`); } else { return src; } }; //# sourceMappingURL=set.js.map