From de5ae48d56d84f30de60d363a1ed9c400758b616 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Tue, 21 Oct 2025 13:06:06 -0400 Subject: [PATCH] pseudo selectors working --- main.ts | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/main.ts b/main.ts index f3164a0..c830387 100644 --- a/main.ts +++ b/main.ts @@ -1,26 +1,41 @@ +type PseudoKeys = ["hover"|"before"|"after"] | ["hover", "after"|"before"]; type ValueSignature = (...args:number[])=>void type EnumDefinition = [property:string, options:Record, values?:Signature]; type EnumBlock = Record>; type RecursiveObject> = { - [F in keyof Obj]: Obj[F][2] extends Sig ? ((...args:Parameters)=>RecursiveObject&Array>)&{ - [E in keyof Obj[F][1]]:RecursiveObject&Array> + [F in keyof Obj]: Obj[F][2] extends Sig ? ((...args:Parameters)=> RecursiveObject&((...args:PseudoKeys)=>RecursiveObject)&Array>)&{ + [E in keyof Obj[F][1]]:RecursiveObject&((...args:PseudoKeys)=>RecursiveObject)&Array> } : { - [E in keyof Obj[F][1]]:RecursiveObject&Array> + [E in keyof Obj[F][1]]:RecursiveObject&((...args:PseudoKeys)=>RecursiveObject)&Array> } } function Block>(options:Fields):()=>RecursiveObject { return ()=>{ - const list = ["@media(min-width:0px){"]; + + let pseudo = false; + let query = false; + const list = []; let fieldLookup = {}; const proxyOuter = new Proxy( function(...args) { console.log("outer: core call", ...args) + if(args.length) + { + list.push(`${(pseudo||query) ? "}" : ""} &:${args.join("::")}{`); + pseudo = true; + query = false; + return proxyOuter; + } + pseudo && list.push("}"); + query && list.push("}"); + pseudo = false; + query = false; return list; }, { @@ -30,7 +45,8 @@ function Block{}] + Pos:["position", { Abs:"absolute", Rel:"relative" }], + Display:[ "display", { Flex:"flex", Grid:"grid", None:"none", Block:"block", InlineBlock:"inline-block" }], + Left:[ "left", { Auto:"auto" }, (left)=>{}] } ); const userDeclaredStyleBlock = -styles() - .Pos.Abs - .Left(10) -[512] - .Pos.Rel - .Left.Auto +(styles() + .Pos.Abs + ("hover", "after") + .Pos.Rel + .Left(20) + [512] + .Left(100)) + // internal stringification -console.log(userDeclaredStyleBlock().join("")+"}"); +console.log(userDeclaredStyleBlock().join("")); function Sheet>>(userClasses:UserClasses):{[Class in keyof UserClasses]:string} {