UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

44 lines (43 loc) 1.17 kB
import clip_rgb from "./utils/clip_rgb.js"; import type from "./utils/type.js"; import last from "./utils/last.js"; import input from "./io/input.js"; 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(",")}]`; } } export { Color as default }; //# sourceMappingURL=Color.js.map