UNPKG

flowbite-angular

Version:

<div align="center"> <h1>:construction: flowbite-angular (unreleased) :construction:</h1> <p> <a href="https://flowbite.com"> <img alt="Flowbite - Tailwind CSS components" width="350" src="https://flowbite.s3.amazonaws.com/github/logo-github

211 lines (201 loc) 6.38 kB
/** * Check if the provided parameter is an object or not. * * @param item The unknown type parameter. * @returns true if it's an ibject ; false otherwise. */ function isObject(item) { return item !== null && typeof item === 'object' && item.constructor === Object; } /** * Function that return the cloned type of the provided generic type. * * @param source Generic object to be cloned. * @returns The clone type of th eprovided type. */ function cloneDeep(source) { if (!isObject(source)) { return source; } const output = {}; for (const key in source) { output[key] = cloneDeep(source[key]); } return output; } /** * This function is used to create classes for component's while keeping the intellisens up for TailwindCSS and other extensions. * * @param input Generic type to be created. * @returns The generic type's definition. */ function createClass(input) { return input; } /** * This function is used to create themes for component's while keeping the intellisens up for TailwindCSS and other extensions. * * @param input Generic type to be created. * @returns The generic type's definition. */ function createTheme(input) { return input; } /** * Merge two objects into one. * * @param target Object to be merged. * @param source Object to be merged. * @returns The merged object. */ function mergeTheme(target, source) { if (isObject(source) && Object.keys(source).length === 0) { return cloneDeep({ ...target, ...source }); } const output = { ...target, ...source }; if (isObject(source) && isObject(target)) { for (const key in source) { if (isObject(source[key]) && key in target && isObject(target[key])) { output[key] = mergeTheme(target[key], source[key]); } else { output[key] = isObject(source[key]) ? cloneDeep(source[key]) : source[key]; } } } return output; } /** * Return theme value to an indented string. * * @param value The theme to be stringify. * @returns The theme as string. */ function themeToString(value) { return JSON.stringify(value, undefined, 2); } const CLOSE_SVG_ICON = ` <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18 17.94 6M18 18 6.06 6" /> </svg> `; const CHEVRON_UP_SVG_ICON = ` <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m16 14-4-4-4 4" /> </svg> `; const CHEVRON_DOWN_SVG_ICON = ` <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m8 10 4 4 4-4" /> </svg> `; const CHEVRON_RIGHT_SVG_ICON = ` <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m10 16 4-4-4-4" /> </svg> `; const SUN_SVG_ICON = ` <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5V3m0 18v-2M7.05 7.05 5.636 5.636m12.728 12.728L16.95 16.95M5 12H3m18 0h-2M7.05 16.95l-1.414 1.414M18.364 5.636 16.95 7.05M16 12a4 4 0 1 1-8 0 4 4 0 0 1 8 0Z" /> </svg> `; const MOON_SVG_ICON = ` <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 21a9 9 0 0 1-.5-17.986V3c-.354.966-.5 1.911-.5 3a9 9 0 0 0 9 9c.239 0 .254.018.488 0A9.004 9.004 0 0 1 12 21Z" /> </svg> `; const BARS_SVG_ICON = ` <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M5 7h14M5 12h14M5 17h14" /> </svg> `; /** * This class provide an implementation of Guid used as id for flowbite-angular components. * * @see https://gist.github.com/emptyother/1fd97db034ef848f38eca3354fa9ee90 */ class Guid { /** * If value is given and if the value is a valid Guid, then return a Guid from the string ; Otherwise or if no value is given, create a Guid class without value. * * @param value Guid as string if you want to get a Guid type from string */ constructor(value) { this.value = this.empty; if (value) { if (Guid.isValid(value)) { this.value = value; } } } /** * Function that generate new Guid. * * @returns New Guid. */ static newGuid() { return new Guid(crypto.randomUUID()); } /** * Function that generate an empty Guid. * * @return "00000000-0000-0000-0000-000000000000". */ static get empty() { return '00000000-0000-0000-0000-000000000000'; } /** * Function that generate an empty Guid. * * @return "00000000-0000-0000-0000-000000000000". */ get empty() { return Guid.empty; } /** * Check if the provided Guid is valid. * * @param str The Guid to check. * @returns true if the Guid is valid ; false otherwise. */ static isValid(str) { const validRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; return validRegex.test(str); } /** * ToString base method. * * @returns Value as string. */ toString() { return this.value; } /** * ToJson base method. * * @returns Value as Json compatible string. */ toJSON() { return this.value; } } /** * Function that return a new Guid. * * @returns New {@link Guid}. * * @see `Guid` */ function generateId() { return Guid.newGuid(); } /** * Generated bundle index. Do not edit. */ export { BARS_SVG_ICON, CHEVRON_DOWN_SVG_ICON, CHEVRON_RIGHT_SVG_ICON, CHEVRON_UP_SVG_ICON, CLOSE_SVG_ICON, Guid, MOON_SVG_ICON, SUN_SVG_ICON, cloneDeep, createClass, createTheme, generateId, isObject, mergeTheme, themeToString }; //# sourceMappingURL=flowbite-angular-utils.mjs.map