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-05 09:22:33 +00:00
|
|
|
const config = Theme.getPConfig();
|
|
|
|
|
2024-03-28 14:26:59 +00:00
|
|
|
return types.includes(param1) ? dt(config?.theme, tokenPath, undefined, param2) : dt(config?.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) => {
|
|
|
|
const config = Theme.getPConfig();
|
|
|
|
|
|
|
|
const variable = dt(config?.theme, tokenPath, undefined, 'variable');
|
|
|
|
const name = variable.match(/--[\w-]+/g)?.[0];
|
|
|
|
const value = dt(config?.theme, tokenPath, undefined, 'value');
|
|
|
|
|
|
|
|
return {
|
|
|
|
variable,
|
|
|
|
name,
|
|
|
|
value
|
|
|
|
};
|
|
|
|
};
|