|
| 1 | +# Theme Protocol (`browser://theme/`) |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `browser://theme/` protocol provides a standardized way for web applications to access browser-level CSS styles and theme variables in [Peersky](https://peersky.p2plabs.xyz/) and other compatible browsers, such as [Agregore](https://agregore.mauve.moe/). 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. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## Purpose |
| 10 | + |
| 11 | +The goal of the `browser://theme/` protocol is to: |
| 12 | + |
| 13 | +- Enable cross-browser compatibility for theming in any browser, including p2p browsers like Peersky and Agregore. |
| 14 | +- Provide a unified set of theme variables using standardized `--browser-theme-` prefixes. |
| 15 | +- Allow web applications to import styles or variables without hardcoding browser-specific protocols (e.g., `peersky://` or `agregore://`). |
| 16 | + |
| 17 | +## Implementation |
| 18 | + |
| 19 | +### Protocol Handler |
| 20 | + |
| 21 | +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/style.css`. |
| 22 | + |
| 23 | +- **Location**: Files are stored in `src/pages/theme/` (e.g., `vars.css`, `style.css`, `base.css`, `index.css`). |
| 24 | +- **URL Structure**: Requests to `browser://theme/<filename>` map to `src/pages/theme/<filename>`. |
| 25 | +- **Example**: `browser://theme/vars.css` serves `src/pages/theme/vars.css`. |
| 26 | + |
| 27 | +### Theme Variable Standardization |
| 28 | + |
| 29 | +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. |
| 30 | + |
| 31 | +Each browser implements these standardized variables by mapping them to their internal theme variables. For example: |
| 32 | + |
| 33 | +- In Peersky, `--browser-theme-background` is mapped to `--base01`, which is part of the Base16 color palette [Base16 Framework](https://github.com/chriskempson/base16). |
| 34 | +- In Agregore, `--browser-theme-background` is mapped to `--ag-theme-background`, which is defined in Agregore's theme configuration. |
| 35 | + |
| 36 | +This ensures that applications built for one browser can work seamlessly in another, as long as they use the standardized `--browser-theme-` variables. |
| 37 | + |
| 38 | +### Cross-Browser Compatibility |
| 39 | + |
| 40 | +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. |
| 41 | + |
| 42 | +For example: |
| 43 | + |
| 44 | +- In Peersky, `--browser-theme-background` is mapped to `--base01`, which is part of the Base16 color palette. |
| 45 | +- In Agregore, `--browser-theme-background` is mapped to `--ag-theme-background`, which is defined in Agregore's theme configuration. |
| 46 | + |
| 47 | +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). |
| 48 | + |
| 49 | +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. |
| 50 | + |
| 51 | +## Usage |
| 52 | + |
| 53 | +### Importing Theme Styles |
| 54 | + |
| 55 | +Web applications can import theme styles or variables using `<style>` tags or `<link>` elements. Examples: |
| 56 | + |
| 57 | +- **Import Variables**: |
| 58 | + |
| 59 | + ```html |
| 60 | + <style> |
| 61 | + @import url("browser://theme/vars.css"); |
| 62 | + body { |
| 63 | + background-color: var(--browser-theme-background); |
| 64 | + color: var(--browser-theme-text-color); |
| 65 | + } |
| 66 | + </style> |
| 67 | + ``` |
| 68 | + |
| 69 | +- **Import Default Styles**: |
| 70 | + |
| 71 | + ```html |
| 72 | + <link rel="stylesheet" href="browser://theme/style.css" /> |
| 73 | + ``` |
| 74 | + |
| 75 | +- **Use Browser-Specific Variables** (for Agregore apps in Peersky): |
| 76 | + ```html |
| 77 | + <style> |
| 78 | + @import url("browser://theme/vars.css"); |
| 79 | + body { |
| 80 | + background-color: var( |
| 81 | + --ag-theme-background |
| 82 | + ); /* Maps to --browser-theme-background */ |
| 83 | + } |
| 84 | + </style> |
| 85 | + ``` |
| 86 | + |
| 87 | +## Theme Files (`browser://theme/`) |
| 88 | + |
| 89 | +- `vars.css`: Defines standardized `--browser-theme-`, Base16, and Peersky-specific CSS variables for theming. |
| 90 | +- `base.css`: Applies minimal default styles for unstyled pages, auto-injected by preload. |
| 91 | +- `style.css`: Opt-in comprehensive styling for web apps |
| 92 | +- `index.css`: Styles Peersky’s browser UI (e.g., navigation bar, URL input). |
| 93 | +- `home.css`: Styles Peersky’s home page with a background image and sidebar. |
0 commit comments