Files
amazon-city-of-gold/utils/styles.js
Andrey Sharshov 9487728656 initial
2025-11-16 18:54:31 +01:00

20 lines
590 B
JavaScript

export const createStyles = (sheet) => {
return new Proxy(sheet, {
get: (target, property, receiver) => {
const medias = getMedia(target).filter((media) => {
if (!target[media].hasOwnProperty(property)) return false;
return matchMedia(media).matches;
});
if (medias.length === 0) return target[property];
return target[medias[medias.length-1]][property];
}
})
}
function getMedia(target) {
const properties = Object.keys(target);
const regex = new RegExp(/\(.*\)/);
return properties.filter((property) => regex.test(property))
}