Skip to content

Commit 75928a7

Browse files
authored
[web] Update shell styles (#260)
* [web] Update shell styles * Update theme * Update themes
1 parent d1d4b5d commit 75928a7

File tree

35 files changed

+3699
-928
lines changed

35 files changed

+3699
-928
lines changed

editor/theme/theme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ export const theme: v0_8.Types.Theme = {
375375
h1: h1Light,
376376
h2: h2Light,
377377
h3: h3Light,
378+
h4: {},
379+
h5: {},
378380
iframe,
379381
input: inputLight,
380382
p: pLight,
@@ -389,7 +391,6 @@ export const theme: v0_8.Types.Theme = {
389391
h3: [...Object.keys(h3Light)],
390392
h4: [],
391393
h5: [],
392-
h6: [],
393394
ul: [...Object.keys(unorderedListLight)],
394395
ol: [...Object.keys(orderedListLight)],
395396
li: [...Object.keys(listItemLight)],

renderers/lit/src/0.8/styles/colors.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const color = <C extends PaletteKeyVals>(src: PaletteKey<C>) =>
4545
background-color: light-dark(oklch(from var(${toProp(
4646
key
4747
)}) l c h / calc(alpha * ${o.toFixed(1)})), oklch(from var(${toProp(
48-
inverseKey
49-
)}) l c h / calc(alpha * ${o.toFixed(1)})) );
48+
inverseKey
49+
)}) l c h / calc(alpha * ${o.toFixed(1)})) );
5050
}
5151
`);
5252
}
@@ -92,5 +92,9 @@ export const colors = [
9292
.color-bgc-transparent {
9393
background-color: transparent;
9494
}
95+
96+
:host {
97+
color-scheme: var(--color-scheme);
98+
}
9599
`,
96100
];

renderers/lit/src/0.8/styles/type.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ export const type = `
136136
white-space: pre-line;
137137
}
138138
139+
.typography-ws-nw {
140+
white-space: nowrap;
141+
}
142+
143+
.typography-td-none {
144+
text-decoration: none;
145+
}
146+
139147
/** Weights **/
140148
141149
${new Array(9)

renderers/lit/src/0.8/types/types.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export type Theme = {
138138
h1: Record<string, boolean>;
139139
h2: Record<string, boolean>;
140140
h3: Record<string, boolean>;
141+
h4: Record<string, boolean>;
142+
h5: Record<string, boolean>;
141143
iframe: Record<string, boolean>;
142144
input: Record<string, boolean>;
143145
p: Record<string, boolean>;
@@ -152,7 +154,6 @@ export type Theme = {
152154
h3: string[];
153155
h4: string[];
154156
h5: string[];
155-
h6: string[];
156157
ul: string[];
157158
ol: string[];
158159
li: string[];
@@ -177,7 +178,17 @@ export type Theme = {
177178
Row?: Record<string, string>;
178179
Slider?: Record<string, string>;
179180
Tabs?: Record<string, string>;
180-
Text?: Record<string, string>;
181+
Text?:
182+
| Record<string, string>
183+
| {
184+
h1: Record<string, string>;
185+
h2: Record<string, string>;
186+
h3: Record<string, string>;
187+
h4: Record<string, string>;
188+
h5: Record<string, string>;
189+
body: Record<string, string>;
190+
caption: Record<string, string>;
191+
};
181192
TextField?: Record<string, string>;
182193
Video?: Record<string, string>;
183194
};
@@ -274,7 +285,7 @@ export type ValueMap = DataObject & {
274285
valueNumber?: number;
275286
valueBoolean?: boolean;
276287
valueMap?: ValueMap[];
277-
}
288+
};
278289

279290
export interface DeleteSurfaceMessage {
280291
surfaceId: string;

renderers/lit/src/0.8/ui/button.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class Button extends Root {
3535
display: block;
3636
flex: var(--weight);
3737
min-height: 0;
38-
overflow: auto;
3938
}
4039
`,
4140
];

renderers/lit/src/0.8/ui/component-registry.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
import { CustomElementConstructorOf } from "./ui.js";
1818

1919
export class ComponentRegistry {
20-
private registry: Map<string, CustomElementConstructorOf<HTMLElement>> = new Map();
20+
private registry: Map<string, CustomElementConstructorOf<HTMLElement>> =
21+
new Map();
2122

2223
register(
2324
typeName: string,
2425
constructor: CustomElementConstructorOf<HTMLElement>,
2526
tagName?: string
2627
) {
2728
if (!/^[a-zA-Z0-9]+$/.test(typeName)) {
28-
throw new Error(`[Registry] Invalid typeName '${typeName}'. Must be alphanumeric.`);
29+
throw new Error(
30+
`[Registry] Invalid typeName '${typeName}'. Must be alphanumeric.`
31+
);
2932
}
3033

3134
this.registry.set(typeName, constructor);
@@ -35,7 +38,9 @@ export class ComponentRegistry {
3538
if (existingName) {
3639
// Constructor is already registered.
3740
if (existingName !== actualTagName) {
38-
throw new Error(`Component ${typeName} is already registered as ${existingName}, but requested as ${actualTagName}.`);
41+
throw new Error(
42+
`Component ${typeName} is already registered as ${existingName}, but requested as ${actualTagName}.`
43+
);
3944
}
4045
return;
4146
}
@@ -50,4 +55,4 @@ export class ComponentRegistry {
5055
}
5156
}
5257

53-
export const REGISTRY = new ComponentRegistry();
58+
export const componentRegistry = new ComponentRegistry();

renderers/lit/src/0.8/ui/directives/markdown.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class MarkdownDirective extends Directive {
6161

6262
#originalClassMap = new Map<string, RenderRule | undefined>();
6363
#applyTagClassMap(tagClassMap: Record<string, string[]>) {
64-
Object.entries(tagClassMap).forEach(([tag, classes]) => {
64+
Object.entries(tagClassMap).forEach(([tag]) => {
6565
let tokenName;
6666
switch (tag) {
6767
case "p":
@@ -100,34 +100,27 @@ class MarkdownDirective extends Directive {
100100
}
101101

102102
const key = `${tokenName}_open`;
103-
const original: RenderRule | undefined =
104-
this.#markdownIt.renderer.rules[key];
105-
this.#originalClassMap.set(key, original);
106-
107103
this.#markdownIt.renderer.rules[key] = (
108104
tokens,
109105
idx,
110106
options,
111-
env,
107+
_env,
112108
self
113109
) => {
114110
const token = tokens[idx];
115-
for (const clazz of classes) {
111+
const tokenClasses = tagClassMap[token.tag] ?? [];
112+
for (const clazz of tokenClasses) {
116113
token.attrJoin("class", clazz);
117114
}
118115

119-
if (original) {
120-
return original.call(this, tokens, idx, options, env, self);
121-
} else {
122-
return self.renderToken(tokens, idx, options);
123-
}
116+
return self.renderToken(tokens, idx, options);
124117
};
125118
});
126119
}
127120

128121
#unapplyTagClassMap() {
129-
for (const [key, original] of this.#originalClassMap) {
130-
this.#markdownIt.renderer.rules[key] = original;
122+
for (const [key] of this.#originalClassMap) {
123+
delete this.#markdownIt.renderer.rules[key];
131124
}
132125

133126
this.#originalClassMap.clear();

renderers/lit/src/0.8/ui/root.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import { StringValue } from "../types/primitives.js";
3333
import { Theme, AnyComponentNode, SurfaceID } from "../types/types.js";
3434
import { themeContext } from "./context/theme.js";
3535
import { structuralStyles } from "./styles.js";
36-
import { ComponentRegistry, REGISTRY } from './component-registry.js';
37-
import { ThemeManager } from "./theme/manager.js";
36+
import { componentRegistry } from "./component-registry.js";
3837

3938
type NodeOfType<T extends AnyComponentNode["type"]> = Extract<
4039
AnyComponentNode,
@@ -82,6 +81,7 @@ export class Root extends SignalWatcher(LitElement) {
8281
css`
8382
:host {
8483
display: flex;
84+
flex-direction: column;
8585
gap: 8px;
8686
max-height: 80%;
8787
}
@@ -94,23 +94,6 @@ export class Root extends SignalWatcher(LitElement) {
9494
*/
9595
#lightDomEffectDisposer: null | (() => void) = null;
9696

97-
#themeUnsubscribe: null | (() => void) = null;
98-
99-
connectedCallback() {
100-
super.connectedCallback();
101-
this.#themeUnsubscribe = ThemeManager.subscribe((sheets) => {
102-
if (this.shadowRoot) {
103-
const elementStyles = (this.constructor as typeof LitElement).elementStyles;
104-
const baseStyles = elementStyles.map(s => {
105-
if (s instanceof CSSStyleSheet) return s;
106-
return s.styleSheet;
107-
}).filter((s): s is CSSStyleSheet => !!s);
108-
109-
this.shadowRoot.adoptedStyleSheets = [...baseStyles, ...sheets];
110-
}
111-
});
112-
}
113-
11497
protected willUpdate(changedProperties: PropertyValues<this>): void {
11598
if (changedProperties.has("childComponents")) {
11699
if (this.#lightDomEffectDisposer) {
@@ -140,10 +123,6 @@ export class Root extends SignalWatcher(LitElement) {
140123
if (this.#lightDomEffectDisposer) {
141124
this.#lightDomEffectDisposer();
142125
}
143-
144-
if (this.#themeUnsubscribe) {
145-
this.#themeUnsubscribe();
146-
}
147126
}
148127

149128
/**
@@ -163,7 +142,7 @@ export class Root extends SignalWatcher(LitElement) {
163142
return html` ${map(components, (component) => {
164143
// 1. Check if there is a registered custom component or override.
165144
if (this.enableCustomElements) {
166-
const registeredCtor = REGISTRY.get(component.type);
145+
const registeredCtor = componentRegistry.get(component.type);
167146
// We also check customElements.get for non-registered but defined elements
168147
const elCtor = registeredCtor || customElements.get(component.type);
169148
@@ -522,7 +501,7 @@ export class Root extends SignalWatcher(LitElement) {
522501
}
523502

524503
const node = component as AnyComponentNode;
525-
const registeredCtor = REGISTRY.get(component.type);
504+
const registeredCtor = componentRegistry.get(component.type);
526505
const elCtor = registeredCtor || customElements.get(component.type);
527506

528507
if (!elCtor) {

renderers/lit/src/0.8/ui/surface.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export class Surface extends Root {
3737
:host {
3838
display: flex;
3939
min-height: 0;
40-
overflow: auto;
4140
max-height: 100%;
4241
flex-direction: column;
4342
gap: 16px;
@@ -75,17 +74,19 @@ export class Surface extends Root {
7574
for (const [key, value] of Object.entries(this.surface.styles)) {
7675
switch (key) {
7776
case "primaryColor": {
78-
for (let i = 0; i <= 100; i++) {
79-
styles[`--p-${i}`] = `color-mix(in srgb, ${value} ${
80-
100 - i
81-
}%, #fff ${i}%)`;
82-
}
77+
// Ignored for now.
78+
// for (let i = 0; i <= 100; i++) {
79+
// styles[`--p-${i}`] = `color-mix(in srgb, ${value} ${
80+
// 100 - i
81+
// }%, #fff ${i}%)`;
82+
// }
8383
break;
8484
}
8585

8686
case "font": {
87-
styles["--font-family"] = value;
88-
styles["--font-family-flex"] = value;
87+
// Ignored for now.
88+
// styles["--font-family"] = value;
89+
// styles["--font-family-flex"] = value;
8990
break;
9091
}
9192
}

renderers/lit/src/0.8/ui/text.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export class Text extends Root {
4141
display: block;
4242
flex: var(--weight);
4343
}
44+
45+
h1,
46+
h2,
47+
h3,
48+
h4,
49+
h5 {
50+
line-height: inherit;
51+
font: inherit;
52+
}
4453
`,
4554
];
4655

@@ -109,10 +118,21 @@ export class Text extends Root {
109118
this.usageHint ? this.theme.components.Text[this.usageHint] : {}
110119
);
111120

121+
let additionalStyles: Record<string, string> = {};
122+
const styles = this.theme.additionalStyles?.Text;
123+
if (styles) {
124+
if ("h1" in styles) {
125+
const hint = this.usageHint ?? "body";
126+
additionalStyles = styles[hint] as Record<string, string>;
127+
} else {
128+
additionalStyles = styles;
129+
}
130+
}
131+
112132
return html`<section
113133
class=${classMap(classes)}
114134
style=${this.theme.additionalStyles?.Text
115-
? styleMap(this.theme.additionalStyles?.Text)
135+
? styleMap(additionalStyles)
116136
: nothing}
117137
>
118138
${this.#renderText()}

0 commit comments

Comments
 (0)