UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

43 lines (42 loc) 1.2 kB
"use strict"; const clip_rgb = require("./utils/clip_rgb.cjs"); const type = require("./utils/type.cjs"); const last = require("./utils/last.cjs"); const input = require("./io/input.cjs"); class Color { constructor(...args) { const me = this; if (type(args[0]) === "object" && args[0].constructor && args[0].constructor === this.constructor) { return args[0]; } let mode = last(args); let autodetect = false; if (!mode) { autodetect = true; if (!input.sorted) { input.autodetect = input.autodetect.sort((a, b) => b.p - a.p); input.sorted = true; } for (let chk of input.autodetect) { mode = chk.test(...args); if (mode) break; } } if (input.format[mode]) { const rgb = input.format[mode].apply( null, autodetect ? args : args.slice(0, -1) ); me._rgb = clip_rgb(rgb); } else { throw new Error("unknown format: " + args); } if (me._rgb.length === 3) me._rgb.push(1); } toString() { if (type(this.hex) == "function") return this.hex(); return `[${this._rgb.join(",")}]`; } } module.exports = Color; //# sourceMappingURL=Color.cjs.map