2024-05-13 21:57:53 +00:00
|
|
|
import { SharedUtils, Theme } from 'primevue/themes';
|
2024-03-05 09:22:33 +00:00
|
|
|
|
2024-04-15 09:17:29 +00:00
|
|
|
export const $dt = (tokenPath) => {
|
2024-03-31 04:44:48 +00:00
|
|
|
const theme = Theme.getTheme();
|
2024-03-05 09:22:33 +00:00
|
|
|
|
2024-04-15 09:17:29 +00:00
|
|
|
const variable = dtwt(theme, tokenPath, undefined, 'variable');
|
|
|
|
const name = variable.match(/--[\w-]+/g)?.[0];
|
|
|
|
const value = dtwt(theme, tokenPath, undefined, 'value');
|
|
|
|
|
|
|
|
return {
|
|
|
|
name,
|
|
|
|
variable,
|
|
|
|
value
|
|
|
|
};
|
2024-03-05 09:22:33 +00:00
|
|
|
};
|
|
|
|
|
2024-04-15 09:17:29 +00:00
|
|
|
export const dt = (...args) => {
|
|
|
|
return dtwt(Theme.getTheme(), ...args);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const dtwt = (theme = {}, tokenPath, fallback, type = 'variable') => {
|
2024-03-05 09:22:33 +00:00
|
|
|
if (tokenPath) {
|
2024-03-27 13:12:22 +00:00
|
|
|
const VARIABLE = Theme.defaults.variable;
|
2024-03-05 09:22:33 +00:00
|
|
|
const { prefix, transform } = theme?.options || {};
|
|
|
|
const regex = /{([^}]*)}/g;
|
|
|
|
const token = SharedUtils.object.test(regex, tokenPath) ? tokenPath : `{${tokenPath}}`;
|
2024-03-19 12:50:54 +00:00
|
|
|
const isStrictTransform = type === 'value' || transform === 'strict'; // @todo - TRANSFORM: strict | lenient(default)
|
2024-03-05 09:22:33 +00:00
|
|
|
|
2024-03-28 13:01:28 +00:00
|
|
|
return isStrictTransform ? Theme.getTokenValue(tokenPath) : SharedUtils.object.getVariableValue(token, undefined, prefix, [VARIABLE.excludedKeyRegex], fallback);
|
2024-03-05 09:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
};
|