@sandlada/vue-mdc
Version:

42 lines (41 loc) • 1.47 kB
JavaScript
/**
* @license
* Copyright 2024 Sandlada & Kai Orion
* SPDX-License-Identifier: MIT
*/
import { isServer } from "../utils/is-server.js";
import { MaterialDesignSystem } from "../utils/material-design-system.js";
const setElementColorProperty = (element, property, value) => {
element.style.setProperty(property === "text" ? "color" : "background-color", value);
};
const directive = (property) => ({
mounted: (el, binding) => {
if (isServer()) {
return;
}
let colorRaw = binding.value;
if (typeof colorRaw === "undefined" || colorRaw === null) {
console.warn(`v-text-color accepts a string of hexadecimal color values. v-text-color received an unexpected value [${colorRaw}].`);
colorRaw = MaterialDesignSystem.Color.OnSurface;
}
setElementColorProperty(el, property, colorRaw);
},
updated: (el, binding) => {
if (binding.oldValue === binding.value) {
return;
}
let colorRaw = binding.value;
if (typeof colorRaw === "undefined" || colorRaw === null) {
console.warn(`v-text-color accepts a string of hexadecimal color values. v-text-color received an unexpected value [${colorRaw}].`);
colorRaw = MaterialDesignSystem.Color.OnSurface;
}
setElementColorProperty(el, property, colorRaw);
}
});
const vTextColor = directive("text");
const vBackgroundColor = directive("background");
export {
vBackgroundColor,
vTextColor
};
//# sourceMappingURL=color-directive.js.map