Skip to content

Commit 37d6559

Browse files
docs: add browser://theme protocol (#74)
* docs: add browser://theme protocol, and syntax highlighting to theming.md * docs: update theming.md for Peersky and Agregore vars.css usage
1 parent 44e2a3c commit 37d6559

File tree

1 file changed

+113
-17
lines changed

1 file changed

+113
-17
lines changed

docs/theming.md

Lines changed: 113 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ Agregore provides CSS variables for themeing the browser at the URL `agregore://
55
The contents of this look something like:
66

77
```css
8-
:root {
9-
--ag-color-purple: #6e2de5;
10-
--ag-color-black: #111;
11-
--ag-color-white: #F2F2F2;
12-
--ag-color-green: #2de56e;
13-
}
14-
15-
:root {
16-
--ag-theme-font-family: system-ui;
17-
--ag-theme-background: var(--ag-color-black);
18-
--ag-theme-text: var(--ag-color-white);
19-
--ag-theme-primary: var(--ag-color-purple);
20-
--ag-theme-secondary: var(--ag-color-green);
21-
}
8+
:root {
9+
--ag-color-purple: #6e2de5;
10+
--ag-color-black: #111;
11+
--ag-color-white: #f2f2f2;
12+
--ag-color-green: #2de56e;
13+
}
14+
15+
:root {
16+
--ag-theme-font-family: system-ui;
17+
--ag-theme-background: var(--ag-color-black);
18+
--ag-theme-text: var(--ag-color-white);
19+
--ag-theme-primary: var(--ag-color-purple);
20+
--ag-theme-secondary: var(--ag-color-green);
21+
}
2222
```
2323

2424
These can be imported anywhere you'd like to use browser styling.
@@ -51,11 +51,107 @@ You can replace the various values with any valid CSS values like Hex codes: `#F
5151

5252
More styles will be added here as needed. If you feel we should standardize on some sort of style, feel free to open an issue talking about what it is and why it should be added.
5353

54-
### Highlight.js
54+
## Syntax Highlighting Font
55+
56+
Agregore now uses a custom font for syntax highlighting in code blocks. The font file is located at `browser://theme/FontWithASyntaxHighlighter-Regular.woff2`.
57+
58+
To use this font for `code` elements, you can include the following CSS in your stylesheet:
59+
60+
```css
61+
@font-face {
62+
font-family: "FontWithASyntaxHighlighter";
63+
src: url("browser://theme/FontWithASyntaxHighlighter-Regular.woff2") format("woff2");
64+
}
65+
66+
code {
67+
font-family: "FontWithASyntaxHighlighter", monospace;
68+
}
69+
```
70+
71+
This font provides built-in syntax highlighting for code blocks, making it easier to read and understand code snippets.
72+
73+
## Theme Protocol (`browser://theme/`)
74+
75+
### Overview
76+
77+
The `browser://theme/` protocol provides a standardized way for web applications to access browser-level CSS styles and theme variables in Agregore and other compatible browsers, such as [Peersky](https://peersky.p2plabs.xyz/). This protocol ensures consistent theming across different browsers by serving CSS files with a common set of variables. It allows developers to build applications that adapt to the browser's theme without needing browser-specific code, making it suitable for any browser that implements the protocol.
78+
79+
## Purpose
80+
81+
The goal of the `browser://theme/` protocol is to:
82+
83+
- Enable cross-browser compatibility for theming in any browser, including p2p browsers like Peersky and Agregore.
84+
- Provide a unified set of theme variables using standardized `--browser-theme-` prefixes.
85+
- Allow web applications to import styles or variables without hardcoding browser-specific protocols (e.g., `peersky://` or `agregore://`).
86+
87+
## Implementation
88+
89+
### Protocol Handler
90+
91+
The `browser://theme/` protocol is implemented in Peersky via a custom Electron protocol handler (`theme-handler.js`). It serves CSS files from the `src/pages/theme/` directory when requests are made to URLs like `browser://theme/vars.css` or `browser://theme/base.css`.
5592

56-
For convenience, Agregore bundles highlight.js and a default theme for it.
93+
- **Location**: Files are stored in `src/pages/theme/` (e.g., `vars.css`, `base.css`, `index.css`).
94+
- **URL Structure**: Requests to `browser://theme/<filename>` map to `src/pages/theme/<filename>`.
95+
- **Example**: `browser://theme/vars.css` serves `src/pages/theme/vars.css`.
5796

58-
You can load it up using `agregore://theme/highlight.js` and `agregore://theme/highlight.css`.
97+
### Theme Variable Standardization
98+
99+
The `browser://theme/` protocol provides standardized theme variables prefixed with `--browser-theme-`, such as `--browser-theme-font-family`, `--browser-theme-background`, `--browser-theme-text-color`, `--browser-theme-primary-highlight`, and `--browser-theme-secondary-highlight`. These variables allow web applications to adapt to the host browser's theme without needing browser-specific code.
100+
101+
Each browser implements these standardized variables by mapping them to their internal theme variables. For example:
102+
103+
- In Peersky, `--browser-theme-background` is mapped to `--base01`, which is part of the Base16 color palette [Base16 Framework](https://github.com/chriskempson/base16).
104+
- In Agregore, `--browser-theme-background` is mapped to `--ag-theme-background`, which is defined in Agregore's theme configuration.
105+
106+
This ensures that applications built for one browser can work seamlessly in another, as long as they use the standardized `--browser-theme-` variables.
107+
108+
### Cross-Browser Compatibility
109+
110+
The `browser://theme/` protocol enables apps built for one browser to work seamlessly in another by providing standardized theme variables prefixed with `--browser-theme-`. These variables are mapped to each browser's internal theme variables, ensuring consistent theming across different browsers.
111+
112+
For example:
113+
114+
- In Peersky, `--browser-theme-background` is mapped to `--base01`, which is part of the Base16 color palette.
115+
- In Agregore, `--browser-theme-background` is mapped to `--ag-theme-background`, which is defined in Agregore's theme configuration.
116+
117+
As a result, an app using `--browser-theme-background` will render with the appropriate background color for each browser, whether it's based on Base16 (as in Peersky) or another theme system (as in Agregore).
118+
119+
Additionally, apps can use the full set of variables provided by each browser for more advanced theming, but for cross-browser compatibility, it's recommended to use the standardized `--browser-theme-` variables.
120+
121+
## Usage
122+
123+
### Importing Theme Styles
124+
125+
Web applications can import theme styles or variables using `<style>` tags or `<link>` elements. Examples:
126+
127+
- **Import Variables**:
128+
129+
```html
130+
<style>
131+
@import url("browser://theme/vars.css");
132+
body {
133+
background-color: var(--browser-theme-background);
134+
color: var(--browser-theme-text-color);
135+
}
136+
</style>
137+
```
138+
139+
- **Import Default Styles**:
140+
141+
```html
142+
<link rel="stylesheet" href="browser://theme/style.css" />
143+
```
144+
145+
- **Use Peersky Variables in Agregore**:
146+
```html
147+
<style>
148+
@import url("browser://theme/vars.css");
149+
body {
150+
background-color: var(
151+
--browser-theme-background); /* Maps to --ag-theme-background in Agregore */
152+
}
153+
</style>
154+
```
59155

60156
---
61157

0 commit comments

Comments
 (0)