primevue-mirror/components/lib/themes/helpers/dt.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-03-05 09:22:33 +00:00
import Theme, { SharedUtils } from 'primevue/themes';
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
};
export const dt = (theme = {}, tokenPath, fallback, type = 'variable') => {
2024-03-05 09:22:33 +00:00
if (tokenPath) {
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}}`;
const isStrictTransform = type === 'value' || transform === 'strict'; // @todo - TRANSFORM: strict | lenient(default)
2024-03-05 09:22:33 +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 '';
};
export const $dtp = (tokenPath) => {
2024-03-31 04:44:48 +00:00
const theme = Theme.getTheme();
2024-03-31 04:44:48 +00:00
const variable = dt(theme, tokenPath, undefined, 'variable');
const name = variable.match(/--[\w-]+/g)?.[0];
2024-03-31 04:44:48 +00:00
const value = dt(theme, tokenPath, undefined, 'value');
return {
variable,
name,
value
};
};