2024-04-28 22:21:18 -04:00
|
|
|
|
|
|
|
const typeface = {
|
|
|
|
sans: "sans serif",
|
|
|
|
serif: "Times New Roman"
|
|
|
|
};
|
|
|
|
const sizes = {
|
|
|
|
small: "1rem",
|
|
|
|
large: "3rem"
|
|
|
|
};
|
|
|
|
const colors = {
|
|
|
|
red: "#ff2200",
|
|
|
|
blue: "#0022ff"
|
|
|
|
};
|
|
|
|
|
2024-05-13 08:42:44 -04:00
|
|
|
|
|
|
|
const styles = new Map<string, string>();
|
|
|
|
function Mapper<T extends Record<string, string>>(className:string, propertyName:string, lut:T)
|
2024-04-28 22:21:18 -04:00
|
|
|
{
|
2024-05-13 08:42:44 -04:00
|
|
|
const build =(_:T, propertyValue:string, customPropertyName?:string)=>
|
|
|
|
{
|
|
|
|
const selector = `${className}-${(customPropertyName||propertyValue as string).replace(/[^a-zA-Z0-9]/g, "")}${activeQuery?"_"+activeQuery:""}`;
|
2024-05-11 23:33:50 -04:00
|
|
|
const check = styles.get(selector);
|
|
|
|
if(!check)
|
|
|
|
{
|
2024-05-13 08:42:44 -04:00
|
|
|
const body = `{ ${propertyName}:${propertyValue}; }`;
|
2024-05-11 23:33:50 -04:00
|
|
|
styles.set(selector, activeQuery ? `{ @media(${activeQuery})${body}}` : body);
|
|
|
|
}
|
|
|
|
return selector;
|
2024-05-13 08:42:44 -04:00
|
|
|
}
|
|
|
|
type UseCustom = (custom:string)=>string;
|
|
|
|
return new Proxy(function(override:string)
|
|
|
|
{
|
|
|
|
return build(lut, override);
|
|
|
|
} as UseCustom,
|
|
|
|
{
|
|
|
|
get(target, prop){
|
|
|
|
|
|
|
|
return build(lut, lut[prop as string], prop as string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
) as T & UseCustom;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Complex<Obj extends Record<string, string>, F extends CallableFunction>(obj:Obj, func:F)
|
|
|
|
{
|
|
|
|
return new Proxy(func, {get(target, prop){
|
|
|
|
return obj[prop as string]
|
|
|
|
}}) as Obj & F
|
2024-04-28 22:21:18 -04:00
|
|
|
}
|
2024-05-11 23:33:50 -04:00
|
|
|
|
|
|
|
let activeQuery:false|string = false
|
|
|
|
function Query(amount:string)
|
2024-04-28 22:21:18 -04:00
|
|
|
{
|
2024-05-11 23:33:50 -04:00
|
|
|
activeQuery = amount;
|
|
|
|
return (...args:string[])=> {
|
|
|
|
activeQuery = false;
|
|
|
|
return args.join(" ");
|
2024-04-28 22:21:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function config<T>(obj:T)
|
|
|
|
{
|
|
|
|
const CSS = {
|
2024-05-11 23:33:50 -04:00
|
|
|
Sheet()
|
|
|
|
{
|
2024-05-13 08:42:44 -04:00
|
|
|
const rules = [];
|
2024-05-11 23:33:50 -04:00
|
|
|
for(const [key, value] of styles.entries())
|
|
|
|
{
|
|
|
|
rules.push(key+value);
|
|
|
|
}
|
|
|
|
return rules.join("\n");
|
|
|
|
},
|
2024-04-28 22:21:18 -04:00
|
|
|
get MD()
|
|
|
|
{
|
2024-05-11 23:33:50 -04:00
|
|
|
return Query("768px");
|
2024-04-28 22:21:18 -04:00
|
|
|
},
|
2024-05-11 23:33:50 -04:00
|
|
|
Face: Mapper("Face", "font-family", {...typeface, ...obj}),
|
|
|
|
Pad: Mapper("P", "padding", sizes)
|
2024-04-28 22:21:18 -04:00
|
|
|
};
|
|
|
|
return CSS;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default config({});
|