From 27780931d520fcdb94de9918a3539438f2b7ab17 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Fri, 7 Jun 2024 12:37:02 -0400 Subject: [PATCH] media query call stack --- gale.tsx | 19 +++++++++++-------- styler.tsx | 5 +++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gale.tsx b/gale.tsx index 588a3f0..f02907f 100644 --- a/gale.tsx +++ b/gale.tsx @@ -22,12 +22,12 @@ function Mapper>(className:string, propertyName { const build =(propertyValue:string, customPropertyName?:string):string=> { - const selector = `${className}-${(customPropertyName||propertyValue as string).replace(/[^a-zA-Z0-9]/g, "")}${activeQuery?"_"+activeQueryKey:""}`; + const selector = `${className}-${(customPropertyName||propertyValue as string).replace(/[^a-zA-Z0-9]/g, "")}${activeQuery.val?"_"+activeQuery.key:""}`; const check = styles.get(selector); if(!check) { const body = `{ ${propertyName}:${propertyValue}; }`; - styles.set(selector, activeQuery ? `{ @media(${activeQuery})${body}}` : body); + styles.set(selector, activeQuery.val ? `{ @media(${activeQuery.val})${body}}` : body); } return selector; } @@ -53,16 +53,19 @@ function MapperQuery>(lut:T) ) as Record & UseCustom; } -let activeQuery:false|string = false; -let activeQueryKey:false|string = false; + +let activeQuery:ActiveQuery; +type ActiveQuery = {key:string|false, val:string|false}; +const activeQueryStack:ActiveQuery[] = []; type QueryInvoker = (...args:string[])=>string function Query(amount:string, key?:string):QueryInvoker { - activeQuery = amount; - activeQueryKey = key||amount + activeQuery = {key:key||amount, val:amount}; + activeQueryStack.push(activeQuery); return (...args)=> { - activeQuery = false; - activeQueryKey = false; + + activeQueryStack.pop() + activeQuery = activeQueryStack.at(-1) || {key:false, val:false}; return args.join(" "); } } diff --git a/styler.tsx b/styler.tsx index 7c85c2f..b3b22e8 100644 --- a/styler.tsx +++ b/styler.tsx @@ -1,7 +1,8 @@ import Gale from "./gale-custom.tsx"; -const classes = Gale.Q.lg( Gale.Face.sans, Gale.Pad.small ); +const classes = Gale.Q.lg( Gale.Face.sans, Gale.Q.md(Gale.Pad.large), Gale.Pad.small ); console.log(classes); -console.log(Gale.Sheet()) \ No newline at end of file +console.log(Gale.Sheet()) +