UNPKG

material-chalk

Version:

Generate beautiful colors from namespaces based on color theory

44 lines (43 loc) 2.07 kB
"use strict"; /** * File for opinionated ways to format common cases */ Object.defineProperty(exports, "__esModule", { value: true }); exports.chainedMessage = chainedMessage; exports.matchColor = matchColor; const material_color_utilities_1 = require("@material/material-color-utilities"); const core_js_1 = require("./core.js"); function chainedMessage(chalk, namespace, ...s) { const header = []; const chalkFormat = core_js_1.Format.Chalk(chalk); if (typeof namespace === "string") { const fullNamespace = (0, core_js_1.createMaterial)(namespace).formatAs(chalkFormat); return `${fullNamespace.inverse(namespace)}: ${fullNamespace(...s)}`; } for (let i = 0; i < namespace.length; i++) { const currStep = (0, core_js_1.createMaterial)(namespace[i]); const mix = i + 1 < namespace.length ? currStep.subMaterial(namespace[i + 1]) : null; const baseChalk = currStep.formatAs(chalkFormat); header.push(i === namespace.length - 1 || i === 0 ? baseChalk.inverse(namespace[i]) : baseChalk(namespace[i])); if (mix != null) { header.push(mix.formatAs(chalkFormat)("-")); } } const fullNamespace = (0, core_js_1.createMaterial)(namespace[namespace.length - 1]).formatAs(chalkFormat); return `${header.join("")}: ${fullNamespace(...s)}`; } function matchColor(color) { const desiredColor = (() => { const desiredColor = typeof color === "string" ? material_color_utilities_1.Hct.fromInt((0, material_color_utilities_1.argbFromHex)(color)) : color; if (desiredColor.tone < core_js_1.TONE_RANGE.Min) { return material_color_utilities_1.Hct.from(desiredColor.hue, desiredColor.chroma, core_js_1.TONE_RANGE.Min); } if (desiredColor.tone > core_js_1.TONE_RANGE.Max) { return material_color_utilities_1.Hct.from(desiredColor.hue, desiredColor.chroma, core_js_1.TONE_RANGE.Max); } return desiredColor; })(); return (0, core_js_1.colorToNamespace)(desiredColor); }