/*!
 * Custom elements for Nanopore-Digital Web applications
 */
export const hostContext = (selector, el) => {
    return el.closest(selector) !== null;
};
/**
 * Create the mode and color classes for the component based on the classes passed in
 * @param color
 * @param cssClassMap
 * @returns an jsx class map
 */
export const createColorClasses = (color, cssClassMap) => {
    return typeof color === 'string' && color.length > 0
        ? {
            [color]: true,
            ...cssClassMap,
        }
        : cssClassMap;
};
/**
 * @param classes
 * @returns an array of trimmed class names
 */
const getClassList = (classes) => {
    if (classes !== undefined) {
        const array = Array.isArray(classes) ? classes : classes.split(' ');
        return array
            .filter((c) => c != null)
            .map((c) => c.trim())
            .filter((c) => c !== '');
    }
    return [];
};
/**
 * turns a string, or array of strings into a jsx class map
 * @param classes
 * @returns a jsx class map
 */
export const getClassMap = (classes) => {
    const map = {};
    getClassList(classes).forEach((c) => (map[c] = true));
    return map;
};
