2024-03-05 09:22:33 +00:00
|
|
|
import Theme, { SharedUtils } from 'primevue/themes';
|
|
|
|
|
2024-03-13 12:05:23 +00:00
|
|
|
const VARIABLE = Theme.defaults.variable;
|
2024-03-05 09:22:33 +00:00
|
|
|
|
2024-03-19 12:50:54 +00:00
|
|
|
export const $dt = (tokenPath, type) => {
|
2024-03-05 09:22:33 +00:00
|
|
|
const config = Theme.getPConfig();
|
|
|
|
|
2024-03-19 12:50:54 +00:00
|
|
|
return dt(config?.theme, tokenPath, type);
|
2024-03-05 09:22:33 +00:00
|
|
|
};
|
|
|
|
|
2024-03-19 12:50:54 +00:00
|
|
|
export const dt = (theme = {}, tokenPath, type) => {
|
2024-03-05 09:22:33 +00:00
|
|
|
if (tokenPath) {
|
|
|
|
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-19 12:50:54 +00:00
|
|
|
return isStrictTransform ? Theme.getTokenValue(tokenPath) : SharedUtils.object.getVariableValue(token, undefined, prefix, [VARIABLE.excludedKeyRegex]);
|
2024-03-05 09:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
};
|