UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

36 lines (35 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const chroma = require("../../chroma.cjs"); const Color = require("../../Color.cjs"); const input = require("../input.cjs"); const type = require("../../utils/type.cjs"); const unpack = require("../../utils/unpack.cjs"); const { round } = Math; Color.prototype.rgb = function(rnd = true) { if (rnd === false) return this._rgb.slice(0, 3); return this._rgb.slice(0, 3).map(round); }; Color.prototype.rgba = function(rnd = true) { return this._rgb.slice(0, 4).map((v, i) => { return i < 3 ? rnd === false ? v : round(v) : v; }); }; const rgb = (...args) => new Color(...args, "rgb"); Object.assign(chroma, { rgb }); input.format.rgb = (...args) => { const rgba = unpack(args, "rgba"); if (rgba[3] === void 0) rgba[3] = 1; return rgba; }; input.autodetect.push({ p: 3, test: (...args) => { args = unpack(args, "rgba"); if (type(args) === "array" && (args.length === 3 || args.length === 4 && type(args[3]) == "number" && args[3] >= 0 && args[3] <= 1)) { return "rgb"; } } }); exports.rgb = rgb; //# sourceMappingURL=index.cjs.map