2024-03-05 09:22:33 +00:00
|
|
|
import Theme, { SharedUtils } from 'primevue/themes';
|
|
|
|
|
2024-03-28 14:26:59 +00:00
|
|
|
const types = ['value', 'variable'];
|
|
|
|
|
|
|
|
export const $dt = (tokenPath, param1, param2) => {
|
2024-03-31 04:44:48 +00:00
|
|
|
const theme = Theme.getTheme();
|
2024-03-05 09:22:33 +00:00
|
|
|
|
2024-03-31 04:44:48 +00:00
|
|
|
return types.includes(param1) ? dt(theme, tokenPath, undefined, param1) : dt(theme, tokenPath, param1, param2);
|
2024-03-05 09:22:33 +00:00
|
|
|
};
|
|
|
|
|
2024-03-28 14:26:59 +00:00
|
|
|
export const dt = (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 '';
|
|
|
|
};
|
2024-03-28 14:26:59 +00:00
|
|
|
|
|
|
|
export const $dtp = (tokenPath) => {
|
2024-03-31 04:44:48 +00:00
|
|
|
const theme = Theme.getTheme();
|
2024-03-28 14:26:59 +00:00
|
|
|
|
2024-03-31 04:44:48 +00:00
|
|
|
const variable = dt(theme, tokenPath, undefined, 'variable');
|
2024-03-28 14:26:59 +00:00
|
|
|
const name = variable.match(/--[\w-]+/g)?.[0];
|
2024-03-31 04:44:48 +00:00
|
|
|
const value = dt(theme, tokenPath, undefined, 'value');
|
2024-03-28 14:26:59 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
variable,
|
|
|
|
name,
|
|
|
|
value
|
|
|
|
};
|
|
|
|
};
|