@bridgebrew/shell 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ // The sidebar's ink on a wallpaper (CAP-8): the sidebar lies bare on the image, so its text takes the ink that reads
2
+ // best on what is under it, light on a dark image and dark on a bright one. The page draws the window's background
3
+ // small (the theme's canvas, the image laid by its fit) and reads the sidebar's column of it; kept by image and fit.
4
+ import * as React from 'react';
5
+ import type { wallpaperFits } from '@bridge/kernel/look';
6
+ import { isRecord } from '@bridge/kernel/json';
7
+
8
+ export type Ink = 'light' | 'dark';
9
+ type Fit = (typeof wallpaperFits)[number];
10
+
11
+ /** Sent on `window` when the wallpaper theme's rules change (@bridge/ui's wallpaper-sheet.ts `WALLPAPER_RULES_EVENT`). */
12
+ const WALLPAPER_RULES_EVENT = 'bridge-wallpaper-rules';
13
+
14
+ /** The two inks' luminances (./look.css `--canvas-ink`: oklch 96 % and 22 %). */
15
+ const LIGHT_INK = 0.88;
16
+ const DARK_INK = 0.03;
17
+
18
+ /** The ink that reads best on RGBA `pixels` (their mean relative luminance): dark when it contrasts more there.
19
+ * Transparent pixels skipped; none left: undefined. */
20
+ export function inkOfPixels(pixels: ArrayLike<number>): Ink | undefined {
21
+ const linear = (channel: number) => {
22
+ const c = channel / 255;
23
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
24
+ };
25
+ let sum = 0;
26
+ let count = 0;
27
+ for (let at = 0; at + 3 < pixels.length; at += 4) {
28
+ if (pixels[at + 3]! < 128) continue;
29
+ sum +=
30
+ 0.2126 * linear(pixels[at]!) +
31
+ 0.7152 * linear(pixels[at + 1]!) +
32
+ 0.0722 * linear(pixels[at + 2]!);
33
+ count++;
34
+ }
35
+ if (count === 0) return undefined;
36
+ const y = sum / count;
37
+ return (y + 0.05) / (DARK_INK + 0.05) > (LIGHT_INK + 0.05) / (y + 0.05) ? 'dark' : 'light';
38
+ }
39
+
40
+ /** Where `fit` lays an image of `iw`×`ih` in a `vw`×`vh` box, as the shell's background does (./look.ts `fits`): its
41
+ * rectangle (x, y, width, height); `tile` its first, repeated from the box's origin. */
42
+ export function layOut(
43
+ fit: Fit,
44
+ iw: number,
45
+ ih: number,
46
+ vw: number,
47
+ vh: number,
48
+ ): [number, number, number, number] {
49
+ if (fit === 'tile') return [0, 0, iw, ih];
50
+ const scale =
51
+ fit === 'cover'
52
+ ? Math.max(vw / iw, vh / ih)
53
+ : fit === 'contain'
54
+ ? Math.min(vw / iw, vh / ih)
55
+ : 1;
56
+ const [w, h] = [iw * scale, ih * scale];
57
+ return [(vw - w) / 2, (vh - h) / 2, w, h];
58
+ }
59
+
60
+ /** The ink read on `url` laid by `fit` under the shell's sidebar, kept by `named` (what names the image) and the fit;
61
+ * again when the window or the sidebar changes size. None without an image or a sidebar. */
62
+ export function useWallpaperInk(
63
+ url: string | undefined,
64
+ fit: Fit | undefined,
65
+ named: string,
66
+ ): Ink | undefined {
67
+ const key = `${named}|${fit}`;
68
+ const [ink, setInk] = React.useState<Ink | undefined>(() => kept()[key]);
69
+ React.useEffect(() => {
70
+ if (url === undefined || fit === undefined) return setInk(undefined);
71
+ setInk(kept()[key]);
72
+ let live = true;
73
+ let timer: ReturnType<typeof setTimeout> | undefined;
74
+ const read = () =>
75
+ void inkUnderSidebar(url, fit)
76
+ .then((next) => {
77
+ if (!live || next === undefined) return;
78
+ setInk(next);
79
+ keep(key, next);
80
+ })
81
+ .catch(() => undefined);
82
+ read();
83
+ const shell = document.querySelector('[data-slot="shell"]');
84
+ const sidebar = document.querySelector('[data-slot="shell-sidebar"]');
85
+ const later = () => {
86
+ clearTimeout(timer);
87
+ timer = setTimeout(read, 300);
88
+ };
89
+ const observer = new ResizeObserver(later);
90
+ for (const each of [shell, sidebar]) if (each) observer.observe(each);
91
+ // The theme's canvas under a contained or transparent image: drawn again from the wallpaper's own colours.
92
+ window.addEventListener(WALLPAPER_RULES_EVENT, later);
93
+ return () => {
94
+ live = false;
95
+ clearTimeout(timer);
96
+ observer.disconnect();
97
+ window.removeEventListener(WALLPAPER_RULES_EVENT, later);
98
+ };
99
+ }, [url, fit, key]);
100
+ return ink;
101
+ }
102
+
103
+ /** The window's background drawn 96 px wide (the shell's canvas colour, the image by its fit), the sidebar's column read. */
104
+ async function inkUnderSidebar(url: string, fit: Fit): Promise<Ink | undefined> {
105
+ const shell = document.querySelector<HTMLElement>('[data-slot="shell"]');
106
+ const sidebar = document.querySelector<HTMLElement>('[data-slot="shell-sidebar"]');
107
+ if (!shell || !sidebar) return undefined;
108
+ const box = shell.getBoundingClientRect();
109
+ const column = sidebar.getBoundingClientRect();
110
+ if (box.width === 0 || column.width === 0) return undefined;
111
+ const image = new Image();
112
+ image.src = url;
113
+ await image.decode();
114
+ const k = 96 / box.width;
115
+ const canvas = Object.assign(document.createElement('canvas'), {
116
+ width: 96,
117
+ height: Math.max(1, Math.round(box.height * k)),
118
+ });
119
+ const context = canvas.getContext('2d', { willReadFrequently: true });
120
+ if (!context) return undefined;
121
+ context.fillStyle = getComputedStyle(shell).backgroundColor;
122
+ context.fillRect(0, 0, canvas.width, canvas.height);
123
+ context.scale(k, k);
124
+ if (fit === 'tile') {
125
+ context.fillStyle = context.createPattern(image, 'repeat') ?? 'transparent';
126
+ context.fillRect(0, 0, box.width, box.height);
127
+ } else {
128
+ const [x, y, w, h] = layOut(
129
+ fit,
130
+ image.naturalWidth,
131
+ image.naturalHeight,
132
+ box.width,
133
+ box.height,
134
+ );
135
+ context.drawImage(image, x, y, w, h);
136
+ }
137
+ const from = Math.max(0, Math.floor((column.left - box.left) * k));
138
+ const to = Math.min(96, Math.ceil((column.right - box.left) * k));
139
+ return to > from
140
+ ? inkOfPixels(context.getImageData(from, 0, to - from, canvas.height).data)
141
+ : undefined;
142
+ }
143
+
144
+ const INK_KEY = 'bridge.wallpaper-ink';
145
+ /** The kept inks by image and fit; a stored value of another shape (not an object, or an entry that is not an ink) is
146
+ * dropped rather than thrown, so one bad value never loses the rest. */
147
+ export const kept = (): Record<string, Ink> => {
148
+ try {
149
+ const stored: unknown = JSON.parse(localStorage.getItem(INK_KEY) ?? '{}');
150
+ if (!isRecord(stored)) return {};
151
+ const inks: Record<string, Ink> = {};
152
+ for (const [key, ink] of Object.entries(stored))
153
+ if (ink === 'light' || ink === 'dark') inks[key] = ink;
154
+ return inks;
155
+ } catch {
156
+ return {};
157
+ }
158
+ };
159
+ const keep = (key: string, ink: Ink) => {
160
+ try {
161
+ const all = kept();
162
+ if (all[key] === ink) return;
163
+ localStorage.setItem(INK_KEY, JSON.stringify({ ...all, [key]: ink }));
164
+ } catch {
165
+ // storage blocked or full: read again next time
166
+ }
167
+ };
@@ -0,0 +1,9 @@
1
+ /* The shell's flat frame (no window manager, or one set aside: ./browser.tsx `flatFrame`), the minimum frame Bridge had
2
+ before windows: a line between each zone. The window draws its own against the sidebar; this one goes between the
3
+ rail and the sidebar column, in the canvas's ink (on a painted canvas, a tint of it), inside the column's width. A
4
+ window manager's windows stand on the canvas: no line. A file, not a `<style>`: the page's CSP forbids inline
5
+ styles. */
6
+ [data-slot='shell']:has([data-slot='shell-window'][data-flat]) [data-slot='shell-sidebar'] {
7
+ box-sizing: border-box;
8
+ border-left: 1px solid var(--border);
9
+ }
package/package.json CHANGED
@@ -1,6 +1,91 @@
1
1
  {
2
2
  "name": "@bridgebrew/shell",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "description": "The page around everything: the rail, the sidebar column, the stage beside it and the theme controls.",
6
+ "keywords": [
7
+ "bridge-plugin"
8
+ ],
9
+ "type": "module",
10
+ "files": [
11
+ "*.json",
12
+ "browser/",
13
+ "!**/*.test.ts",
14
+ "!**/*.test.tsx"
15
+ ],
16
+ "bridge": {
17
+ "kind": "extension",
18
+ "category": "foundation",
19
+ "title": "Shell",
20
+ "icon": "monitor",
21
+ "domain": "interface",
22
+ "browser": "./browser/browser.tsx",
23
+ "settings": {
24
+ "type": "object",
25
+ "properties": {
26
+ "workspaceTransitionEnabled": {
27
+ "type": "boolean",
28
+ "title": "Animate workspace switch",
29
+ "description": "Animate the change of workspace.",
30
+ "x-bridge-details": "Off, the page changes at once (for a machine that draws it badly). A browser asking for reduced motion gets none either way.",
31
+ "default": true,
32
+ "applies": "live"
33
+ },
34
+ "workspaceTransition": {
35
+ "type": "string",
36
+ "title": "Workspace switch",
37
+ "description": "How the change of workspace is animated.",
38
+ "x-bridge-details": "A fade with a short slide the way the rail goes, or a fade only.",
39
+ "enum": [
40
+ "slide",
41
+ "fade"
42
+ ],
43
+ "x-bridge-labels": [
44
+ "Fade and slide",
45
+ "Fade"
46
+ ],
47
+ "default": "slide",
48
+ "applies": "live"
49
+ },
50
+ "workspaceTransitionDuration": {
51
+ "type": "integer",
52
+ "x-bridge-advanced": true,
53
+ "title": "Workspace switch duration (ms)",
54
+ "description": "How long the change of workspace takes.",
55
+ "x-bridge-details": "From 100 ms (quick) to 2000 ms (slow).",
56
+ "minimum": 100,
57
+ "maximum": 2000,
58
+ "default": 220,
59
+ "applies": "live"
60
+ },
61
+ "themeMenu": {
62
+ "type": "boolean",
63
+ "title": "Theme menu (Legacy)",
64
+ "description": "Show the theme menu's button beside the light/dark toggle.",
65
+ "x-bridge-details": "The menu sets Mine's style, icons, theme, window manager and navigation for the workspace shown; Settings › Look › Mine does the same. Off, the button shows only when a window manager failed and its toast's \"Choose\" asks for the menu.",
66
+ "default": false,
67
+ "applies": "live"
68
+ }
69
+ }
70
+ },
71
+ "provenance": "official",
72
+ "placement": "host",
73
+ "implements": [
74
+ "shell"
75
+ ]
76
+ },
77
+ "peerDependencies": {
78
+ "@bridge/kernel": ">=0.0.1",
79
+ "@bridge/ui": ">=0.0.1",
80
+ "cordis": "4.0.0-rc.11",
81
+ "react": "19.3.0"
82
+ },
83
+ "releaseStage": "dev",
84
+ "scripts": {
85
+ "test": "node ../bridge/node_modules/vitest/vitest.mjs run --config ../scripts/vitest.config.ts",
86
+ "typecheck": "bridge plugin check ."
87
+ },
88
+ "engines": {
89
+ "bridge": ">=0.0.1-nightly.20261117.1"
90
+ }
91
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./.bridge/tsconfig.json",
3
+ "//": "jsx: its page tests that are .ts (routing, shell-state) import the page, and are typed with the server project (bridge plugin check)",
4
+ "compilerOptions": { "jsx": "react-jsx" }
5
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.