more polish
This commit is contained in:
parent
7eb8688af1
commit
120508659d
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"deno.enable": true
|
||||||
|
}
|
||||||
101
main.ts
101
main.ts
@ -1,6 +1,6 @@
|
|||||||
// tss.ts
|
// tss.ts
|
||||||
type PseudoKeys = ["hover"|"before"|"after"] | ["hover", "after"|"before"];
|
type PseudoKeys = ["hover"|"before"|"after"] | ["hover", "after"|"before"];
|
||||||
type ValueSignature = (...args:number[])=>void
|
type ValueSignature = (...args:any[])=>string
|
||||||
type EnumDefinition<Signature> = [property:string, options:Record<string, string>, values?:Signature];
|
type EnumDefinition<Signature> = [property:string, options:Record<string, string>, values?:Signature];
|
||||||
type EnumBlock<Signature> = Record<string, EnumDefinition<Signature>>;
|
type EnumBlock<Signature> = Record<string, EnumDefinition<Signature>>;
|
||||||
type RecursiveObject<Sig extends ValueSignature, Obj extends EnumBlock<Sig>> =
|
type RecursiveObject<Sig extends ValueSignature, Obj extends EnumBlock<Sig>> =
|
||||||
@ -25,31 +25,37 @@ function Block<Signature extends ValueSignature, Fields extends EnumBlock<Signat
|
|||||||
const proxyOuter = new Proxy(
|
const proxyOuter = new Proxy(
|
||||||
function(...args)
|
function(...args)
|
||||||
{
|
{
|
||||||
console.log("outer: core call", ...args)
|
// OUTER context called as function:
|
||||||
if(args.length)
|
|
||||||
|
if(args.length) // pseudo elements are being declared, capture and return the OUTER context
|
||||||
{
|
{
|
||||||
list.push(`${(pseudo||query) ? "}" : ""} &:${args.join("::")}{`);
|
list.push(`${(pseudo||query) ? "}" : ""} &:${args.join("::")}{`);
|
||||||
pseudo = true;
|
pseudo = true;
|
||||||
query = false;
|
query = false;
|
||||||
return proxyOuter;
|
return proxyOuter;
|
||||||
}
|
}
|
||||||
pseudo && list.push("}");
|
else // css dump requested:
|
||||||
query && list.push("}");
|
{
|
||||||
pseudo = false;
|
pseudo && list.push("}");
|
||||||
query = false;
|
query && list.push("}");
|
||||||
return list;
|
pseudo = false;
|
||||||
|
query = false;
|
||||||
|
return list;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
get(_target, propName)
|
get(_target, propName)
|
||||||
{
|
{
|
||||||
console.log("outer: reading property", propName);
|
// OUTER context property access:
|
||||||
const sizeCheck = parseInt(propName)
|
|
||||||
if(sizeCheck)
|
if(parseInt(propName)) // if a number was used as a property, treat that as a mobile-first media query in px units, and return the OUTER context
|
||||||
{
|
{
|
||||||
list.push(`${(query) ? "}" : ""} @media(min-width:${sizeCheck}px){`);
|
list.push(`${(query) ? "}" : ""} @media(min-width:${propName}px){`);
|
||||||
query = true;
|
query = true;
|
||||||
return proxyOuter;
|
return proxyOuter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a css property alias was accessed, look up the mapped css property name from the declaration array, push that, and return the OUTER context
|
||||||
fieldLookup = options[propName];
|
fieldLookup = options[propName];
|
||||||
if(fieldLookup)
|
if(fieldLookup)
|
||||||
{
|
{
|
||||||
@ -63,20 +69,23 @@ function Block<Signature extends ValueSignature, Fields extends EnumBlock<Signat
|
|||||||
const proxyInner = new Proxy(
|
const proxyInner = new Proxy(
|
||||||
function(...args)
|
function(...args)
|
||||||
{
|
{
|
||||||
console.log("inner: core call", ...args)
|
// INNER context called as function
|
||||||
list.push(`:${args.join(" ")};`);
|
|
||||||
|
// capture the evalued dynamic values and return the OUTER context
|
||||||
|
list.push(`:${fieldLookup[2](...args)};`);
|
||||||
return proxyOuter;
|
return proxyOuter;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
get(_target, valName)
|
get(_target, valName)
|
||||||
{
|
{
|
||||||
console.log("inner: reading property", valName);
|
// INNER context property access
|
||||||
try
|
|
||||||
|
try // capture the mapped css value and return the OUTER context
|
||||||
{
|
{
|
||||||
list.push(`:${fieldLookup[1][valName]};`);
|
list.push(`:${fieldLookup[1][valName]};`);
|
||||||
return proxyOuter;
|
return proxyOuter;
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(_e)
|
||||||
{
|
{
|
||||||
console.warn("someone is trying to stringify a style proxy");
|
console.warn("someone is trying to stringify a style proxy");
|
||||||
return ()=>"[StyleProxy]";
|
return ()=>"[StyleProxy]";
|
||||||
@ -88,16 +97,40 @@ function Block<Signature extends ValueSignature, Fields extends EnumBlock<Signat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Measure = "px" | "em" | "rem" | "vh" | "vw" | "%";
|
||||||
|
type UnitString = `${number}${Measure}`;
|
||||||
|
|
||||||
|
const funcUnitSingle = (amount:UnitString)=>amount
|
||||||
|
const funcUnitTRBL = (...args:[t:UnitString, r?:UnitString, b?:UnitString, l?:UnitString])=>args.join(" ")
|
||||||
|
|
||||||
const styles = Block(
|
const styles = Block(
|
||||||
{
|
{
|
||||||
Pos:["position", { Abs:"absolute", Rel:"relative" }],
|
Pos:["position", { Abs:"absolute", Rel:"relative", Fix:"fixed", Pin:"sticky", No:"static" }],
|
||||||
Display:[ "display", { Flex:"flex", Grid:"grid", None:"none", Block:"block", InlineBlock:"inline-block" }],
|
Dis:["display", { Flex:"flex", Grid:"grid", None:"none", Block:"block", InlineBlock:"inline-block" }],
|
||||||
Left:[ "left", { Auto:"auto" }, (left)=>{}]
|
Box:["box-sizing", { Border:"border-box", Content:"content-box" }],
|
||||||
|
|
||||||
|
L:[ "left", { Auto:"auto"}, funcUnitSingle],
|
||||||
|
R:[ "right", { Auto:"auto"}, funcUnitSingle],
|
||||||
|
T:[ "top", { Auto:"auto"}, funcUnitSingle],
|
||||||
|
B:[ "bottom", { Auto:"auto"}, funcUnitSingle],
|
||||||
|
|
||||||
|
Pad: ["padding", {}, funcUnitTRBL ],
|
||||||
|
PadT:["padding-top", {}, funcUnitSingle],
|
||||||
|
PadR:["padding-right", {}, funcUnitSingle],
|
||||||
|
PadB:["padding-bottom", {}, funcUnitSingle],
|
||||||
|
PadL:["padding-left", {}, funcUnitSingle],
|
||||||
|
|
||||||
|
Mar: ["margin", {}, funcUnitTRBL ],
|
||||||
|
MarT:["margin-top", {}, funcUnitSingle],
|
||||||
|
MarR:["margin-right", {}, funcUnitSingle],
|
||||||
|
MarB:["margin-bottom", {}, funcUnitSingle],
|
||||||
|
MarL:["margin-left", {}, funcUnitSingle]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let masterSheet = [];
|
let masterSheet = [];
|
||||||
export function Sheet<UserClasses extends Record<string, (CSS:ReturnType<typeof styles>)=>void >>(userClasses:UserClasses):{[Class in keyof UserClasses]:string}
|
|
||||||
|
export function Sheet<UserClasses extends Record<string, (this:ReturnType<typeof styles>)=>void >>(userClasses:UserClasses):{[Class in keyof UserClasses]:string}
|
||||||
{
|
{
|
||||||
const hash = Math.floor(Math.random()*10000);
|
const hash = Math.floor(Math.random()*10000);
|
||||||
return new Proxy(function(){}, {get(_target, className){
|
return new Proxy(function(){}, {get(_target, className){
|
||||||
@ -122,28 +155,4 @@ export function Sheet<UserClasses extends Record<string, (CSS:ReturnType<typeof
|
|||||||
export function Divulge()
|
export function Divulge()
|
||||||
{
|
{
|
||||||
return masterSheet.join("\n");
|
return masterSheet.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////// testing: ////////
|
|
||||||
|
|
||||||
const sheet = Sheet({
|
|
||||||
SpecialLink(styles)
|
|
||||||
{
|
|
||||||
styles
|
|
||||||
.Pos.Abs
|
|
||||||
("hover","after")
|
|
||||||
.Pos.Rel
|
|
||||||
.Left(20)
|
|
||||||
[512]
|
|
||||||
.Left(100)
|
|
||||||
},
|
|
||||||
Profile(styles)
|
|
||||||
{
|
|
||||||
styles.Display.Block
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const el1 = [sheet.Profile, sheet.SpecialLink];
|
|
||||||
|
|
||||||
console.log(Divulge());
|
|
||||||
10
main_test.ts
10
main_test.ts
@ -1,10 +0,0 @@
|
|||||||
import * as Test from "@std/assert";
|
|
||||||
|
|
||||||
Deno.test(function()
|
|
||||||
{
|
|
||||||
|
|
||||||
Test.assertEquals();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
6
user-layout.ts
Normal file
6
user-layout.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Divulge } from "./main.ts";
|
||||||
|
|
||||||
|
import Styles from "./user-sheet.ts"
|
||||||
|
|
||||||
|
const classes = [Styles.Profile, Styles.SpecialLink];
|
||||||
|
console.log(Divulge());
|
||||||
34
user-sheet.ts
Normal file
34
user-sheet.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { Sheet } from "./main.ts";
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
"5px"
|
||||||
|
Unit(5).px
|
||||||
|
[5,"px"]
|
||||||
|
px(5)
|
||||||
|
Unit.px(5)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default Sheet(
|
||||||
|
{
|
||||||
|
|
||||||
|
SpecialLink()
|
||||||
|
{
|
||||||
|
this
|
||||||
|
.Pos.Abs
|
||||||
|
("hover","after")
|
||||||
|
.Pos.Rel
|
||||||
|
.L("3rem")
|
||||||
|
[512]
|
||||||
|
.L("100px")
|
||||||
|
},
|
||||||
|
|
||||||
|
Profile()
|
||||||
|
{
|
||||||
|
this
|
||||||
|
.Dis.Block
|
||||||
|
.Pad("5px", "6px")
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user