Skip to content

Commit 1b61255

Browse files
committed
cleanup: Layers
1 parent 605ba68 commit 1b61255

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

demo/layer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Horizontal, Layer, PlainText, Vertical, View, WebGen } from "../mod.ts";
22

33
WebGen({
4-
// primiaryColor: "#6750A4",
4+
primiaryColor: "hsl(256, 34%, 40%)",
55
});
66

77
View(() => Horizontal(
@@ -35,7 +35,7 @@ View(() => Horizontal(
3535
PlainText("Hello World! 0")
3636
.setFont(1.5).setPadding("0 .5rem"),
3737
0
38-
)
38+
).setGrow()
3939
).setGap("2.5rem").setGrow(),
4040
Vertical(
4141
Layer(
@@ -67,7 +67,7 @@ View(() => Horizontal(
6767
PlainText("Hello World! 0")
6868
.setFont(1.5).setPadding("0 .5rem"),
6969
0, "tint"
70-
),
70+
).setGrow(),
7171
).setGap("2.5rem").setGrow(),
7272
Vertical(
7373
Layer(
@@ -99,6 +99,6 @@ View(() => Horizontal(
9999
PlainText("Hello World! 0")
100100
.setFont(1.5).setPadding("0 .5rem"),
101101
0, "tint-shadow"
102-
),
102+
).setGrow(),
103103
).setGap("2.5rem").setGrow()
104104
).setGap("2.5rem").setPadding("2.5rem")).appendOn(document.body);

src/components/generic/Layer.css

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
--layer-shadow: 0px 8px 12px 6px rgba(0, 0, 0, 0.15), 0px 4px 4px rgba(0, 0, 0, 0.3);
3535
}
3636

37-
.wlayer.tint-shadow,
38-
.wlayer.shadow {
37+
.wlayer:is(.shadow, .tint-shadow) {
3938
box-shadow: var(--layer-shadow, none);
4039
}
4140

@@ -47,11 +46,10 @@
4746
}
4847

4948

50-
.wlayer.tint-shadow .wlayer-inner,
51-
.wlayer.tint .wlayer-inner {
49+
.wlayer:is(.tint-shadow, .tint) .wlayer-inner {
5250
position: absolute;
5351
inset: 0;
54-
background: var(--webgen-primary-color);
52+
background: hsl(var(--webgen-primary-hue), var(--webgen-primary-sat), 40%);
5553
opacity: calc(calc(var(--color-overlay, 0%) * 1.8) - 5%);
5654
}
5755

@@ -63,7 +61,6 @@
6361
--layer-shadow: none;
6462
}
6563

66-
[data-theme="dark"] .wlayer:is(.tint-shadow, .tint) {
67-
/* We don't have any color-mix or lsh functions so we use this hack */
68-
box-shadow: 0 0 0 10000rem rgba(255, 255, 255, calc(calc(var(--color-overlay, 0%) * 1.7) - 18%)) inset;
64+
[data-theme="dark"] .wlayer:is(.tint-shadow, .tint) .wlayer-inner {
65+
background: hsl(var(--webgen-primary-hue), var(--webgen-primary-sat), 80%);
6966
}

src/css/00.colors.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
:root {
2-
--layer-background: #ececec;
2+
--layer-background: #e6e6e6;
33
--layer-color: #000000;
44
--layer-foreground-hue: 102;
55
--layer-foreground-sat: 34%;
66
}
77

88
[data-theme="dark"] {
9-
--layer-background: #141314;
9+
--layer-background: #0a0a0a;
1010
--layer-color: #FFFFFF;
1111
}

src/lib/Style.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export class Style {
1414
const styleAppendTo = options.defaultElementToHookStylesIn ?? document.documentElement;
1515
this.options = options;
1616
this.theme = styleAppendTo;
17-
document.adoptedStyleSheets.push(css`:root{ --webgen-primary-color: ${options.primiaryColor ?? "#5A7BF2"};}`);
17+
const data = (options.primiaryColor ?? "hsl(200, 50%, 40%)")?.match(/hsl\((?<hue>\d+), (?<saturation>\d+%), .*%\)/);
18+
if (!(data && data.groups && data.groups.hue && data.groups.saturation)) throw new Error("Bad Primary Color");
19+
document.adoptedStyleSheets.push(css`:root{ --webgen-primary-hue: ${data.groups.hue}; --webgen-primary-sat: ${data.groups.saturation};}`);
20+
1821
this.mediaQuery.addEventListener('change', e => {
1922
if (this.current == SupportedThemes.autoDark || this.current == SupportedThemes.autoLight)
2023
this.updateTheme(e.matches ? SupportedThemes.autoDark : SupportedThemes.autoLight);

src/webgen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export * from "./Components.ts";
4040

4141
export type WebGenOptions = {
4242
updateThemeOnInit?: false,
43-
primiaryColor?: string,
43+
primiaryColor?: `hsl(${number}, ${number}%, 40%)`,
4444
colors?: ColorDef,
4545
icon?: Icons,
4646
events?: {

0 commit comments

Comments
 (0)