material-chalk
Version:
Generate beautiful colors from namespaces based on color theory
31 lines (30 loc) • 969 B
JavaScript
import { TonalPalette, } from "@material/material-color-utilities";
/**
* Overrides the primaryPalette of the DynamicScheme at constructor-time
*/
export function sourceAsPrimary(baseScheme) {
class DirectScheme extends baseScheme {
constructor(...args) {
super(...args);
// cast away "readonly"
this.primaryPalette = TonalPalette.fromHct(this.sourceColorHct);
}
}
return DirectScheme;
}
/**
* Overrides the primaryPalette of the DynamicScheme at runtime
*/
export function overrideSourceAsPrimary(dynamicScheme) {
// cast away "readonly"
dynamicScheme.primaryPalette = TonalPalette.fromHct(dynamicScheme.sourceColorHct);
return dynamicScheme;
}
/**
* Returns a DynamicScheme constructor with the first parameter pre-filled with the constructed color
*/
export function buildScheme(Scheme, fixedValue) {
return (...args) => {
return new Scheme(fixedValue, ...args);
};
}