UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

29 lines (28 loc) 843 B
"use strict"; const Color = require("../../Color.cjs"); const input = require("../input.cjs"); const type = require("../../utils/type.cjs"); const w3cx11 = require("../../colors/w3cx11.cjs"); const hex2rgb = require("../hex/hex2rgb.cjs"); const rgb2hex = require("../hex/rgb2hex.cjs"); Color.prototype.name = function() { const hex = rgb2hex(this._rgb, "rgb"); for (let n of Object.keys(w3cx11)) { if (w3cx11[n] === hex) return n.toLowerCase(); } return hex; }; input.format.named = (name) => { name = name.toLowerCase(); if (w3cx11[name]) return hex2rgb(w3cx11[name]); throw new Error("unknown color name: " + name); }; input.autodetect.push({ p: 5, test: (h, ...rest) => { if (!rest.length && type(h) === "string" && w3cx11[h.toLowerCase()]) { return "named"; } } }); //# sourceMappingURL=index.cjs.map