2024-02-16 08:48:00 +00:00
|
|
|
import ObjectUtils from '../../utils/ObjectUtils';
|
|
|
|
|
|
|
|
export const getDeclaration = (property, value) => {
|
|
|
|
return [property]
|
|
|
|
.flat()
|
|
|
|
.map((prop) => ObjectUtils.css.getDeclaration(ObjectUtils.toKebabCase(prop), value))
|
|
|
|
.join('');
|
|
|
|
};
|
|
|
|
|
2024-02-16 14:34:35 +00:00
|
|
|
const importantRegex = /.*!$/;
|
|
|
|
|
2024-02-16 08:48:00 +00:00
|
|
|
export const token = {
|
|
|
|
spacing: (property, options) => {
|
|
|
|
return {
|
|
|
|
type: 'spacing',
|
|
|
|
property,
|
|
|
|
transform(value) {
|
2024-02-16 14:34:35 +00:00
|
|
|
return importantRegex.test(value) ? value + 'important' : value;
|
2024-02-16 08:48:00 +00:00
|
|
|
},
|
|
|
|
toString(value, options) {
|
|
|
|
return getDeclaration(property, this.transform(value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
sizing: (property) => {
|
|
|
|
return {
|
|
|
|
type: 'sizing',
|
|
|
|
property,
|
|
|
|
declaration: (value) => declaration(property, value)
|
|
|
|
};
|
|
|
|
},
|
|
|
|
prop: (property) => {
|
|
|
|
return {
|
|
|
|
property
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-17 23:42:39 +00:00
|
|
|
export const defineDeclarations = (...args) => {
|
|
|
|
const getData = (keys, props, declarations) => {
|
|
|
|
return {
|
|
|
|
keys,
|
|
|
|
props,
|
|
|
|
declarations,
|
|
|
|
getStyleDeclarations(options) {
|
|
|
|
return Object.entries(declarations)
|
|
|
|
.reduce((acc, [key, value]) => {
|
|
|
|
const v = props[key];
|
2024-02-16 08:48:00 +00:00
|
|
|
|
2024-02-17 23:42:39 +00:00
|
|
|
ObjectUtils.isNotEmpty(v) && acc.push(value.toString(v, options));
|
2024-02-16 14:34:35 +00:00
|
|
|
|
2024-02-17 23:42:39 +00:00
|
|
|
return acc;
|
|
|
|
}, [])
|
|
|
|
.join('');
|
|
|
|
},
|
|
|
|
filterP(inProps) {
|
|
|
|
const _props = Object.entries(inProps)
|
|
|
|
.filter(([key]) => keys.includes(key))
|
|
|
|
.reduce((acc, [key, value]) => ((acc[key] = value), acc), {});
|
|
|
|
const _keys = Object.keys(_props);
|
|
|
|
const _declarations = Object.entries(_props).reduce((acc, [key]) => ((acc[key] = declarations[key]), acc), {});
|
2024-02-16 14:34:35 +00:00
|
|
|
|
2024-02-17 23:42:39 +00:00
|
|
|
return getData(_keys, _props, _declarations);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2024-02-16 14:34:35 +00:00
|
|
|
|
2024-02-17 23:42:39 +00:00
|
|
|
const declarations = Object.assign({}, ...args);
|
|
|
|
const keys = Object.keys(declarations);
|
|
|
|
const props = keys.reduce((acc, k) => ((acc[k] = undefined), acc), {});
|
2024-02-16 14:34:35 +00:00
|
|
|
|
2024-02-17 23:42:39 +00:00
|
|
|
return getData(keys, props, declarations);
|
2024-02-16 08:48:00 +00:00
|
|
|
};
|