@liberation-data/desk 0.43.0 → 0.44.0
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.
- package/README.md +225 -8
- package/dist/core/hosted.d.ts +222 -0
- package/dist/core/hosted.d.ts.map +1 -0
- package/dist/core/hosted.js +166 -0
- package/dist/core/hosted.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/location.d.ts +8 -1
- package/dist/core/location.d.ts.map +1 -1
- package/dist/core/location.js +18 -2
- package/dist/core/location.js.map +1 -1
- package/dist/core/preferences.d.ts +27 -0
- package/dist/core/preferences.d.ts.map +1 -0
- package/dist/core/preferences.js +121 -0
- package/dist/core/preferences.js.map +1 -0
- package/dist/core/scheme.d.ts +9 -3
- package/dist/core/scheme.d.ts.map +1 -1
- package/dist/core/scheme.js +13 -4
- package/dist/core/scheme.js.map +1 -1
- package/dist/core/theme.d.ts +41 -0
- package/dist/core/theme.d.ts.map +1 -0
- package/dist/core/theme.js +56 -0
- package/dist/core/theme.js.map +1 -0
- package/dist/core/themeChange.d.ts +25 -0
- package/dist/core/themeChange.d.ts.map +1 -0
- package/dist/core/themeChange.js +49 -0
- package/dist/core/themeChange.js.map +1 -0
- package/dist/css/apps.css +35 -1
- package/dist/css/shell.css +100 -0
- package/dist/css/tokens.css +10 -0
- package/dist/desk.css +45 -1
- package/dist/fx/fx.d.ts.map +1 -1
- package/dist/fx/fx.js +7 -31
- package/dist/fx/fx.js.map +1 -1
- package/dist/host/checkChrome.d.ts +20 -0
- package/dist/host/checkChrome.d.ts.map +1 -0
- package/dist/host/checkChrome.js +219 -0
- package/dist/host/checkChrome.js.map +1 -0
- package/dist/host/checkTheme.d.ts +35 -0
- package/dist/host/checkTheme.d.ts.map +1 -0
- package/dist/host/checkTheme.js +128 -0
- package/dist/host/checkTheme.js.map +1 -0
- package/dist/host/index.d.ts +7 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +8 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/router.d.ts +99 -0
- package/dist/host/router.d.ts.map +1 -0
- package/dist/host/router.js +279 -0
- package/dist/host/router.js.map +1 -0
- package/dist/react/Dock.d.ts +23 -4
- package/dist/react/Dock.d.ts.map +1 -1
- package/dist/react/Dock.js +17 -29
- package/dist/react/Dock.js.map +1 -1
- package/dist/react/MenuBar.d.ts +1 -1
- package/dist/react/MenuBar.d.ts.map +1 -1
- package/dist/react/MenuBar.js +20 -4
- package/dist/react/MenuBar.js.map +1 -1
- package/dist/react/app.d.ts +50 -9
- package/dist/react/app.d.ts.map +1 -1
- package/dist/react/app.js +59 -13
- package/dist/react/app.js.map +1 -1
- package/dist/react/appFrame.d.ts +11 -7
- package/dist/react/appFrame.d.ts.map +1 -1
- package/dist/react/appFrame.js +24 -6
- package/dist/react/appFrame.js.map +1 -1
- package/dist/react/appPanels.d.ts +4 -1
- package/dist/react/appPanels.d.ts.map +1 -1
- package/dist/react/appPanels.js +32 -23
- package/dist/react/appPanels.js.map +1 -1
- package/dist/react/appearance.d.ts +7 -1
- package/dist/react/appearance.d.ts.map +1 -1
- package/dist/react/appearance.js +32 -53
- package/dist/react/appearance.js.map +1 -1
- package/dist/react/context.d.ts +15 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +73 -14
- package/dist/react/context.js.map +1 -1
- package/dist/react/dockStatus.d.ts +19 -0
- package/dist/react/dockStatus.d.ts.map +1 -0
- package/dist/react/dockStatus.js +25 -0
- package/dist/react/dockStatus.js.map +1 -0
- package/dist/react/frameMenus.d.ts +28 -0
- package/dist/react/frameMenus.d.ts.map +1 -0
- package/dist/react/frameMenus.js +85 -0
- package/dist/react/frameMenus.js.map +1 -0
- package/dist/react/hostApp.d.ts +15 -0
- package/dist/react/hostApp.d.ts.map +1 -0
- package/dist/react/hostApp.js +77 -0
- package/dist/react/hostApp.js.map +1 -0
- package/dist/react/hostDock.d.ts +25 -0
- package/dist/react/hostDock.d.ts.map +1 -0
- package/dist/react/hostDock.js +98 -0
- package/dist/react/hostDock.js.map +1 -0
- package/dist/react/hostMenu.d.ts +2 -36
- package/dist/react/hostMenu.d.ts.map +1 -1
- package/dist/react/hostMenu.js.map +1 -1
- package/dist/react/hosted.d.ts +28 -0
- package/dist/react/hosted.d.ts.map +1 -0
- package/dist/react/hosted.js +53 -0
- package/dist/react/hosted.js.map +1 -0
- package/dist/react/index.d.ts +8 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/shell.d.ts +13 -1
- package/dist/react/shell.d.ts.map +1 -1
- package/dist/react/shell.js +19 -3
- package/dist/react/shell.js.map +1 -1
- package/dist/react/windowMenus.d.ts +19 -0
- package/dist/react/windowMenus.d.ts.map +1 -0
- package/dist/react/windowMenus.js +88 -0
- package/dist/react/windowMenus.js.map +1 -0
- package/dist/shell/HostShell.d.ts +53 -0
- package/dist/shell/HostShell.d.ts.map +1 -0
- package/dist/shell/HostShell.js +116 -0
- package/dist/shell/HostShell.js.map +1 -0
- package/dist/shell/index.d.ts +7 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +9 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/shell/keys.d.ts +47 -0
- package/dist/shell/keys.d.ts.map +1 -0
- package/dist/shell/keys.js +68 -0
- package/dist/shell/keys.js.map +1 -0
- package/dist/shell/motion.d.ts +72 -0
- package/dist/shell/motion.d.ts.map +1 -0
- package/dist/shell/motion.js +118 -0
- package/dist/shell/motion.js.map +1 -0
- package/llms.txt +48 -14
- package/package.json +10 -1
- package/src/core/hosted.ts +351 -0
- package/src/core/index.ts +28 -1
- package/src/core/location.ts +23 -3
- package/src/core/preferences.ts +132 -0
- package/src/core/scheme.ts +16 -5
- package/src/core/theme.ts +91 -0
- package/src/core/themeChange.ts +59 -0
- package/src/css/apps.css +35 -1
- package/src/css/shell.css +99 -0
- package/src/css/tokens.css +10 -0
- package/src/fx/fx.ts +7 -25
- package/src/host/checkChrome.ts +257 -0
- package/src/host/checkTheme.ts +134 -0
- package/src/host/index.ts +10 -0
- package/src/host/router.ts +374 -0
- package/src/react/Dock.tsx +34 -28
- package/src/react/MenuBar.tsx +22 -4
- package/src/react/app.tsx +84 -14
- package/src/react/appFrame.tsx +39 -14
- package/src/react/appPanels.tsx +38 -25
- package/src/react/appearance.tsx +36 -45
- package/src/react/context.tsx +88 -13
- package/src/react/dockStatus.ts +42 -0
- package/src/react/frameMenus.ts +100 -0
- package/src/react/hostApp.tsx +89 -0
- package/src/react/hostDock.tsx +118 -0
- package/src/react/hostMenu.ts +3 -38
- package/src/react/hosted.tsx +65 -0
- package/src/react/index.ts +9 -2
- package/src/react/shell.tsx +30 -3
- package/src/react/windowMenus.ts +107 -0
- package/src/shell/HostShell.tsx +220 -0
- package/src/shell/index.ts +11 -0
- package/src/shell/keys.ts +101 -0
- package/src/shell/motion.ts +163 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Look } from './look.js'
|
|
2
|
+
import { themeChanged, watchThemeChanges } from './themeChange.js'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* A LOOK ONE APP LENDS TO OTHERS.
|
|
6
|
+
*
|
|
7
|
+
* Some apps run inside something else: a framed page on the desk, or a whole Desk app hosted beside
|
|
8
|
+
* others under one menu bar. Either way the person chose one look for the whole thing, so the app
|
|
9
|
+
* inside should wear it, not whatever its author hard-coded.
|
|
10
|
+
*
|
|
11
|
+
* The theme travels as data. Its tokens are custom properties set on the receiving page's root, so
|
|
12
|
+
* CSS that reads them follows with nothing written. Because the theme restyles somebody else's page,
|
|
13
|
+
* it is checked before it is passed on (`checkTheme`): a value that could load something, or hide
|
|
14
|
+
* part of the page behind an image from elsewhere, never crosses.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** A page's palette, as a framed app gets it: which way round it is, and custom properties to set. */
|
|
18
|
+
export interface AppTheme {
|
|
19
|
+
readonly mode: 'light' | 'dark'
|
|
20
|
+
/** Custom properties, named as they will be set: `{ '--desk-accent': '#3478f6' }`. */
|
|
21
|
+
readonly tokens: Readonly<Record<string, string>>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A font the theme uses, for a page on another origin to load. */
|
|
25
|
+
export interface ThemeFont {
|
|
26
|
+
readonly family: string
|
|
27
|
+
/** A URL on the publisher's own origin, or a `data:` URI. */
|
|
28
|
+
readonly src: string
|
|
29
|
+
readonly weight?: string
|
|
30
|
+
readonly style?: 'normal' | 'italic'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A whole desk's look: an `AppTheme`, plus the platform chrome, its fonts and its wallpaper. */
|
|
34
|
+
export interface DeskTheme extends AppTheme {
|
|
35
|
+
readonly look: Look
|
|
36
|
+
readonly fonts?: readonly ThemeFont[]
|
|
37
|
+
/** A colour or gradient; or an image: a URL or path on the publisher's origin, or a `data:` image. */
|
|
38
|
+
readonly wallpaper?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A wallpaper that names an image, rather than being a colour or gradient: a `data:` URI, a URL on any
|
|
43
|
+
* scheme with a host (an Electron app's `app://` too), or a path.
|
|
44
|
+
*/
|
|
45
|
+
export const isImageRef = (wallpaper: string): boolean => /^(data:|[a-z][\w+.-]*:\/\/|\/)/i.test(wallpaper)
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The part of a theme every hosted app wears whatever else it does: light or dark, and the
|
|
49
|
+
* platform chrome. One desktop light and the next dark would look broken as they slide past each
|
|
50
|
+
* other, so these are not the app's to decline.
|
|
51
|
+
*/
|
|
52
|
+
export function applyThemeBasics(theme: Pick<DeskTheme, 'mode' | 'look'>, root: HTMLElement = document.documentElement): void {
|
|
53
|
+
watchThemeChanges(root.ownerDocument)
|
|
54
|
+
root.dataset.theme = theme.mode
|
|
55
|
+
root.dataset.look = theme.look
|
|
56
|
+
root.style.colorScheme = theme.mode
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const applied = new WeakMap<HTMLElement, { tokens: readonly string[]; fonts: FontFace[] }>()
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Wears a whole theme: the basics, every token on the root, its fonts, and its wallpaper as
|
|
63
|
+
* `--desk-wallpaper`. Tokens a previous theme set and this one does not are removed, so switching
|
|
64
|
+
* back and forth leaves nothing behind. The default way a hosted app takes the theme it is sent.
|
|
65
|
+
* New colours under the same scheme and look still fire `desk-themechange`, for a canvas to repaint.
|
|
66
|
+
*/
|
|
67
|
+
export function applyTheme(theme: DeskTheme, root: HTMLElement = document.documentElement): void {
|
|
68
|
+
const was = root.style.cssText
|
|
69
|
+
applyThemeBasics(theme, root)
|
|
70
|
+
const before = applied.get(root)
|
|
71
|
+
for (const name of before?.tokens ?? []) if (!(name in theme.tokens)) root.style.removeProperty(name)
|
|
72
|
+
for (const [name, value] of Object.entries(theme.tokens)) root.style.setProperty(name, value)
|
|
73
|
+
if (theme.wallpaper === undefined) root.style.removeProperty('--desk-wallpaper')
|
|
74
|
+
else root.style.setProperty('--desk-wallpaper', isImageRef(theme.wallpaper) ? `url(${JSON.stringify(theme.wallpaper)})` : theme.wallpaper)
|
|
75
|
+
|
|
76
|
+
const fonts = root.ownerDocument.fonts as FontFaceSet | undefined
|
|
77
|
+
for (const face of before?.fonts ?? []) fonts?.delete(face)
|
|
78
|
+
const faces: FontFace[] = []
|
|
79
|
+
if (fonts && typeof FontFace !== 'undefined') {
|
|
80
|
+
for (const font of theme.fonts ?? []) {
|
|
81
|
+
const face = new FontFace(font.family, `url(${JSON.stringify(font.src)})`, {
|
|
82
|
+
...(font.weight === undefined ? {} : { weight: font.weight }),
|
|
83
|
+
...(font.style === undefined ? {} : { style: font.style }),
|
|
84
|
+
})
|
|
85
|
+
fonts.add(face)
|
|
86
|
+
faces.push(face)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
applied.set(root, { tokens: Object.keys(theme.tokens), fonts: faces })
|
|
90
|
+
if (root.style.cssText !== was) themeChanged(root.ownerDocument)
|
|
91
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Look } from './look.js'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* ONE EVENT FOR EVERY CHANGE TO WHAT IS DRAWN, FOR CODE OUTSIDE REACT.
|
|
5
|
+
*
|
|
6
|
+
* Code that draws its own pixels (a canvas) must repaint when the colours change. Every source of a
|
|
7
|
+
* change ends on the root: a host's theme and the person's choice stamp `data-theme`, a look stamps
|
|
8
|
+
* `data-look`, and with neither the system's scheme shows through the stylesheet's media query. So one
|
|
9
|
+
* watcher of those, not a dispatch from each path, sees them all, and fires only when the scheme or
|
|
10
|
+
* look actually drawn has changed. The one change the root's attributes don't show is a host's theme
|
|
11
|
+
* with new colours under the same scheme and look, so `applyTheme` says so itself (`themeChanged`).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** The event's name, on `document`. */
|
|
15
|
+
export const THEME_CHANGE = 'desk-themechange'
|
|
16
|
+
|
|
17
|
+
/** What a `desk-themechange` carries: the scheme and look now drawn. */
|
|
18
|
+
export interface ThemeChange {
|
|
19
|
+
readonly scheme: 'light' | 'dark'
|
|
20
|
+
readonly look: Look
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const checks = new WeakMap<Document, (always?: boolean) => void>()
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The scheme and look drawn now, read as the stylesheet reads them: `data-theme` when it is light or dark,
|
|
27
|
+
* else the system's; `data-look`, else `mac`, which is what desk.css draws without one.
|
|
28
|
+
*/
|
|
29
|
+
export function drawnTheme(doc: Document = document): ThemeChange {
|
|
30
|
+
const root = doc.documentElement
|
|
31
|
+
const set = root.dataset.theme
|
|
32
|
+
const scheme = set === 'light' || set === 'dark' ? set : globalThis.matchMedia?.('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
|
33
|
+
return { scheme, look: (root.dataset.look as Look | undefined) ?? 'mac' }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Starts firing `desk-themechange` on `doc` whenever the drawn scheme or look changes, once per change.
|
|
38
|
+
* Desk starts it when a desk mounts or a theme is applied; calling it again does nothing.
|
|
39
|
+
*/
|
|
40
|
+
export function watchThemeChanges(doc: Document = document): void {
|
|
41
|
+
if (checks.has(doc) || typeof MutationObserver === 'undefined') return
|
|
42
|
+
let last = drawnTheme(doc)
|
|
43
|
+
const check = (always?: boolean) => {
|
|
44
|
+
const now = drawnTheme(doc)
|
|
45
|
+
if (!always && now.scheme === last.scheme && now.look === last.look) return
|
|
46
|
+
last = now
|
|
47
|
+
doc.dispatchEvent(new CustomEvent<ThemeChange>(THEME_CHANGE, { detail: now }))
|
|
48
|
+
}
|
|
49
|
+
checks.set(doc, check)
|
|
50
|
+
new MutationObserver(() => check()).observe(doc.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-look'] })
|
|
51
|
+
globalThis.matchMedia?.('(prefers-color-scheme: dark)').addEventListener?.('change', () => check())
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Fires `desk-themechange` now, if `doc` is watched, though the scheme and look are unchanged: for new
|
|
56
|
+
* colours the root's attributes don't show. Synchronous, so the observer's later look finds nothing new
|
|
57
|
+
* and a theme that also changed the scheme is still one event.
|
|
58
|
+
*/
|
|
59
|
+
export const themeChanged = (doc: Document = document): void => checks.get(doc)?.(true)
|
package/src/css/apps.css
CHANGED
|
@@ -91,6 +91,30 @@
|
|
|
91
91
|
font-weight: 600;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/* A wordmark: as wide as it is drawn, up to the panel, at a heading's height. The name stays, for screen readers. */
|
|
95
|
+
.desk-about-wordmark {
|
|
96
|
+
display: grid;
|
|
97
|
+
place-items: center;
|
|
98
|
+
max-width: 100%;
|
|
99
|
+
height: 40px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.desk-about-wordmark > svg,
|
|
103
|
+
.desk-about-wordmark > img {
|
|
104
|
+
height: 100%;
|
|
105
|
+
width: auto;
|
|
106
|
+
max-width: 100%;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.desk-about-name-hidden {
|
|
110
|
+
position: absolute;
|
|
111
|
+
width: 1px;
|
|
112
|
+
height: 1px;
|
|
113
|
+
overflow: hidden;
|
|
114
|
+
clip-path: inset(50%);
|
|
115
|
+
white-space: nowrap;
|
|
116
|
+
}
|
|
117
|
+
|
|
94
118
|
.desk-about-version,
|
|
95
119
|
.desk-about-description {
|
|
96
120
|
margin: 0;
|
|
@@ -103,10 +127,20 @@
|
|
|
103
127
|
gap: var(--desk-space-2) var(--desk-space-4);
|
|
104
128
|
}
|
|
105
129
|
|
|
106
|
-
|
|
130
|
+
/* The app's links, and a fact's: one colour for every link on the panel. */
|
|
131
|
+
.desk-about-links a,
|
|
132
|
+
.desk-about-fact-note a {
|
|
107
133
|
color: var(--desk-accent);
|
|
108
134
|
}
|
|
109
135
|
|
|
136
|
+
/* A group's heading takes a line of its own above its links. */
|
|
137
|
+
.desk-about-links-heading {
|
|
138
|
+
flex-basis: 100%;
|
|
139
|
+
margin: 0;
|
|
140
|
+
text-align: center;
|
|
141
|
+
font-weight: 500;
|
|
142
|
+
}
|
|
143
|
+
|
|
110
144
|
/*
|
|
111
145
|
* Name and value in two columns; a note sits under its value. Every section shares one grid, through
|
|
112
146
|
* subgrid, so the names are one column down the whole panel, as wide as the longest of them.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The shell of a host running several Desk apps: one dock and one switcher around their views. Not part
|
|
3
|
+
* of desk.css, since no app draws it: the host's page imports `@liberation-data/desk/css/shell.css`
|
|
4
|
+
* after desk.css.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
.desk-shell {
|
|
8
|
+
position: fixed;
|
|
9
|
+
inset: 0;
|
|
10
|
+
font-family: var(--desk-font);
|
|
11
|
+
color: var(--desk-ink);
|
|
12
|
+
background: var(--desk-ground);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.desk-shell-bar {
|
|
16
|
+
display: flex;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
align-items: center;
|
|
19
|
+
padding: var(--desk-space-2) var(--desk-space-3);
|
|
20
|
+
border-bottom: 1px solid var(--desk-rule);
|
|
21
|
+
background: var(--desk-titlebar);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.desk-shell-switcher {
|
|
25
|
+
display: flex;
|
|
26
|
+
gap: var(--desk-space-1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.desk-shell-workspace {
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
gap: var(--desk-space-2);
|
|
33
|
+
padding: var(--desk-space-1) var(--desk-space-3);
|
|
34
|
+
border: 1px solid transparent;
|
|
35
|
+
border-radius: 999px;
|
|
36
|
+
background: none;
|
|
37
|
+
color: var(--desk-muted);
|
|
38
|
+
font: inherit;
|
|
39
|
+
font-size: var(--desk-text-small);
|
|
40
|
+
cursor: default;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.desk-shell-workspace:hover {
|
|
44
|
+
color: var(--desk-ink);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.desk-shell-workspace[aria-current="true"] {
|
|
48
|
+
border-color: var(--desk-rule);
|
|
49
|
+
background: var(--desk-surface);
|
|
50
|
+
color: var(--desk-ink);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.desk-shell-workspace:focus-visible {
|
|
54
|
+
outline: 2px solid var(--desk-accent);
|
|
55
|
+
outline-offset: 2px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.desk-shell-workspace img,
|
|
59
|
+
.desk-shell-mark {
|
|
60
|
+
width: 14px;
|
|
61
|
+
height: 14px;
|
|
62
|
+
border-radius: 4px;
|
|
63
|
+
flex: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.desk-shell-mark {
|
|
67
|
+
background: var(--desk-accent);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Asleep or closed: there, and a visit away, but not running. */
|
|
71
|
+
.desk-shell-workspace:not([data-state="live"]) span {
|
|
72
|
+
opacity: 0.7;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.desk-shell-initial {
|
|
76
|
+
display: grid;
|
|
77
|
+
place-items: center;
|
|
78
|
+
width: 100%;
|
|
79
|
+
height: 100%;
|
|
80
|
+
font-weight: 600;
|
|
81
|
+
font-size: var(--desk-text-lead);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.desk-shell-dot {
|
|
85
|
+
display: inline-block;
|
|
86
|
+
width: 8px;
|
|
87
|
+
height: 8px;
|
|
88
|
+
border-radius: 50%;
|
|
89
|
+
background: currentcolor;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.desk-shell-announce {
|
|
93
|
+
position: absolute;
|
|
94
|
+
width: 1px;
|
|
95
|
+
height: 1px;
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
clip-path: inset(50%);
|
|
98
|
+
white-space: nowrap;
|
|
99
|
+
}
|
package/src/css/tokens.css
CHANGED
|
@@ -87,6 +87,12 @@
|
|
|
87
87
|
--desk-widget-width: 200px;
|
|
88
88
|
/* Room the stage leaves at the bottom for something of the app's own. An overlay dock makes its own. */
|
|
89
89
|
--desk-inset-bottom: 0px;
|
|
90
|
+
/* An overview of workspaces: tiles over a radial haze from fog to its far edge, in the theme's own
|
|
91
|
+
colours. The ground with a trace of the accent, moved toward mid grey so it reads as haze rather
|
|
92
|
+
than as the desktop; the far edge darker; the tiles' shadow a tint, not a box-shadow. */
|
|
93
|
+
--desk-overview-fog: color-mix(in oklab, color-mix(in oklab, var(--desk-ground) 82%, var(--desk-accent) 18%) 88%, #808080);
|
|
94
|
+
--desk-overview-fog-far: color-mix(in oklab, var(--desk-overview-fog) 92%, #000);
|
|
95
|
+
--desk-overview-shadow: rgb(0 0 0 / 0.28);
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
@media (prefers-color-scheme: dark) {
|
|
@@ -118,6 +124,8 @@
|
|
|
118
124
|
--desk-code-keyword: #d2a8ff;
|
|
119
125
|
--desk-code-number: #ffab70;
|
|
120
126
|
--desk-code-key: #7cc4ff;
|
|
127
|
+
--desk-overview-fog-far: color-mix(in oklab, var(--desk-overview-fog) 90%, #000);
|
|
128
|
+
--desk-overview-shadow: rgb(0 0 0 / 0.55);
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -149,4 +157,6 @@
|
|
|
149
157
|
--desk-code-keyword: #d2a8ff;
|
|
150
158
|
--desk-code-number: #ffab70;
|
|
151
159
|
--desk-code-key: #7cc4ff;
|
|
160
|
+
--desk-overview-fog-far: color-mix(in oklab, var(--desk-overview-fog) 90%, #000);
|
|
161
|
+
--desk-overview-shadow: rgb(0 0 0 / 0.55);
|
|
152
162
|
}
|
package/src/fx/fx.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* WHEN to make one is the app's decision and the hard part; see HIG.md, "Sound". This is the
|
|
5
5
|
* instrument: one audio context, opened on the first press, a repeat of the same sound inside a
|
|
6
|
-
* short window heard once, and a mute this browser
|
|
6
|
+
* short window heard once, and a mute the preference store remembers (this browser's localStorage unless the app gives its own).
|
|
7
7
|
*/
|
|
8
|
+
import { getPreference, setPreference, subscribePreferences } from '../core/preferences.js'
|
|
8
9
|
import { SCORES, scored, type BuiltInSound, type Sound } from './sounds.js'
|
|
9
10
|
|
|
10
11
|
export interface FxOptions<Extra extends string> {
|
|
@@ -50,7 +51,6 @@ export function createFx<Extra extends string = never>(
|
|
|
50
51
|
const builtIn = Object.fromEntries(Object.entries(SCORES).map(([name, score]) => [name, scored(score)]))
|
|
51
52
|
const sounds = { ...builtIn, ...options.sounds } as Record<Name, Sound>
|
|
52
53
|
const lastPlayed = new Map<string, number>()
|
|
53
|
-
const listeners = new Set<() => void>()
|
|
54
54
|
let audio: AudioContext | null = null
|
|
55
55
|
|
|
56
56
|
const context = (): AudioContext | null => {
|
|
@@ -65,13 +65,7 @@ export function createFx<Extra extends string = never>(
|
|
|
65
65
|
return audio
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const muted = (): boolean =>
|
|
69
|
-
try {
|
|
70
|
-
return localStorage.getItem(storageKey) === 'yes'
|
|
71
|
-
} catch {
|
|
72
|
-
return false
|
|
73
|
-
}
|
|
74
|
-
}
|
|
68
|
+
const muted = (): boolean => getPreference(storageKey) === 'yes'
|
|
75
69
|
|
|
76
70
|
const render = (ctx: BaseAudioContext, name: Name, out: AudioNode): void => {
|
|
77
71
|
const master = ctx.createGain()
|
|
@@ -119,25 +113,13 @@ export function createFx<Extra extends string = never>(
|
|
|
119
113
|
muted,
|
|
120
114
|
|
|
121
115
|
setMuted(next) {
|
|
122
|
-
|
|
123
|
-
if (next) localStorage.setItem(storageKey, 'yes')
|
|
124
|
-
else localStorage.removeItem(storageKey)
|
|
125
|
-
} catch {
|
|
126
|
-
// Blocked site data: sounds stay on, which is the default.
|
|
127
|
-
}
|
|
128
|
-
listeners.forEach((listener) => listener())
|
|
116
|
+
setPreference(storageKey, next ? 'yes' : null)
|
|
129
117
|
},
|
|
130
118
|
|
|
131
119
|
subscribe(listener) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
if (typeof window !== 'undefined') window.addEventListener('storage', fromAnotherTab)
|
|
137
|
-
return () => {
|
|
138
|
-
listeners.delete(listener)
|
|
139
|
-
if (typeof window !== 'undefined') window.removeEventListener('storage', fromAnotherTab)
|
|
140
|
-
}
|
|
120
|
+
return subscribePreferences(key => {
|
|
121
|
+
if (key === null || key === storageKey) listener()
|
|
122
|
+
})
|
|
141
123
|
},
|
|
142
124
|
|
|
143
125
|
render,
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import type { DeskChrome, HostAbout, HostAboutFact, HostDockEntry, HostDockItem, HostMenu, HostMenuItem, HostSettingsSection } from '../core/hosted.js'
|
|
2
|
+
import { fromOriginOrData, IMAGE_DATA, onOrigin } from './checkTheme.js'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* CHECKING CHROME BEFORE THE HOST DRAWS IT.
|
|
6
|
+
*
|
|
7
|
+
* An app's menus, dock, Settings sections and About are drawn in the host's own frame, so they are
|
|
8
|
+
* input the host must not trust. A link there could run script in that frame (`javascript:`), an image
|
|
9
|
+
* could make it fetch from anywhere, and a label could be a megabyte or a list a million long. So the
|
|
10
|
+
* host checks the chrome first and draws only a copy built from what passed, as it does a theme.
|
|
11
|
+
*
|
|
12
|
+
* One bad part costs only itself: a menu item, dock item, section, link or fact that fails is dropped,
|
|
13
|
+
* and an image or a fact's link that fails is dropped from its item, which is kept. The rest is drawn,
|
|
14
|
+
* and what was dropped is reported for the host to log. Only chrome of the wrong shape is refused
|
|
15
|
+
* whole: not an object, top-level fields that are not lists, too large, or nested deeper than the
|
|
16
|
+
* type goes (a stack in a stack, a menu in a menu).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** Chrome fit to draw, as a fresh copy, with why each dropped part was; or why it is refused whole. */
|
|
20
|
+
export type ChromeCheck =
|
|
21
|
+
| { readonly ok: true; readonly chrome: DeskChrome; readonly dropped: readonly string[] }
|
|
22
|
+
| { readonly ok: false; readonly reason: string }
|
|
23
|
+
|
|
24
|
+
/** The most the whole chrome may take as JSON: room for a dock of a few dozen `data:` icons. */
|
|
25
|
+
const MAX_CHROME = 2 * 1024 * 1024
|
|
26
|
+
const MAX_TEXT = 1000
|
|
27
|
+
const MAX_URL = 2048
|
|
28
|
+
/** One `data:` icon. */
|
|
29
|
+
const MAX_IMAGE = 256 * 1024
|
|
30
|
+
const MAX_MENUS = 50
|
|
31
|
+
const MAX_ROWS = 500
|
|
32
|
+
const MAX_SECTIONS = 200
|
|
33
|
+
const MAX_LINKS = 50
|
|
34
|
+
|
|
35
|
+
/** Thrown for a part that fails: the part is dropped, for this reason. */
|
|
36
|
+
class Refused extends Error {}
|
|
37
|
+
/** Thrown for chrome of the wrong shape: the whole message is refused. */
|
|
38
|
+
class Malformed extends Error {}
|
|
39
|
+
const refuse = (reason: string): never => {
|
|
40
|
+
throw new Refused(reason)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type Fields = Record<string, unknown>
|
|
44
|
+
/** One check's origin, and the reasons for what it dropped. */
|
|
45
|
+
interface Check {
|
|
46
|
+
readonly origin: string
|
|
47
|
+
readonly dropped: string[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const record = (value: unknown, what: string): Fields =>
|
|
51
|
+
typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Fields) : refuse(`${what} is not an object`)
|
|
52
|
+
|
|
53
|
+
/** `make()`, or `otherwise` with the reason noted when the part fails. */
|
|
54
|
+
const orDrop = <T,>(c: Check, make: () => T, otherwise: T): T => {
|
|
55
|
+
try {
|
|
56
|
+
return make()
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (!(error instanceof Refused)) throw error
|
|
59
|
+
c.dropped.push(error.message)
|
|
60
|
+
return otherwise
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The items of a list that pass `check`; the rest, and any past the first `max`, are dropped. */
|
|
65
|
+
const list = <T,>(c: Check, value: unknown, max: number, what: string, check: (value: unknown) => T): T[] => {
|
|
66
|
+
if (!Array.isArray(value)) return refuse(`${what} is not a list`)
|
|
67
|
+
if (value.length > max) c.dropped.push(`${what}: ${value.length - max} past the first ${max}`)
|
|
68
|
+
return value.slice(0, max).flatMap(item => orDrop(c, () => [check(item)], []))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Text a host draws: a string, not too long, with no control or direction-overriding characters. */
|
|
72
|
+
const text = (value: unknown, what: string): string =>
|
|
73
|
+
// eslint-disable-next-line no-control-regex
|
|
74
|
+
typeof value === 'string' && value.length <= MAX_TEXT && !/[\u0000-\u0008\u000b-\u001f\u007f--]/.test(value)
|
|
75
|
+
? value
|
|
76
|
+
: refuse(`${what} is not plain text`)
|
|
77
|
+
|
|
78
|
+
/** The field when present, checked by `check`; nothing when absent. */
|
|
79
|
+
const optional = <T,>(fields: Fields, key: string, check: (value: unknown, what: string) => T): { [k: string]: T } =>
|
|
80
|
+
fields[key] === undefined ? {} : { [key]: check(fields[key], key) }
|
|
81
|
+
|
|
82
|
+
const flag = (value: unknown, what: string): boolean => (typeof value === 'boolean' ? value : refuse(`${what} is not true or false`))
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A link a host may open, in the system browser or a mail app: http(s) or `mailto:` anywhere, or the
|
|
86
|
+
* app's own origin. Resolved, so a relative one points at the app and not at the host.
|
|
87
|
+
*/
|
|
88
|
+
const link = (value: unknown, what: string, origin: string): string => {
|
|
89
|
+
if (typeof value !== 'string' || value.length > MAX_URL) return refuse(`${what} is not a link`)
|
|
90
|
+
try {
|
|
91
|
+
const url = new URL(value, origin)
|
|
92
|
+
if (url.protocol === 'http:' || url.protocol === 'https:' || url.protocol === 'mailto:' || onOrigin(url, origin)) return url.href
|
|
93
|
+
} catch {
|
|
94
|
+
// Refused below.
|
|
95
|
+
}
|
|
96
|
+
return refuse(`${what} is not an http(s) or mailto: link`)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** An image the host may load, dropped from its item when it fails: from the app's origin, or a `data:` raster image. Never SVG, which can carry script. */
|
|
100
|
+
const image = (c: Check, fields: Fields, what: string): { image?: string } =>
|
|
101
|
+
orDrop(
|
|
102
|
+
c,
|
|
103
|
+
() =>
|
|
104
|
+
optional(fields, 'image', value =>
|
|
105
|
+
(typeof value === 'string' && value.length <= MAX_IMAGE && fromOriginOrData(value, c.origin, IMAGE_DATA)) || refuse(`${what}'s image is not from the app`),
|
|
106
|
+
),
|
|
107
|
+
{},
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
const menuItem = (value: unknown): HostMenuItem => {
|
|
111
|
+
const item = record(value, 'a menu item')
|
|
112
|
+
if (item.items !== undefined) throw new Malformed('a menu in a menu')
|
|
113
|
+
if (item.type !== 'item' && item.type !== 'separator' && item.type !== 'header') return refuse('a menu item has no type')
|
|
114
|
+
return {
|
|
115
|
+
type: item.type,
|
|
116
|
+
...optional(item, 'id', text),
|
|
117
|
+
...optional(item, 'label', text),
|
|
118
|
+
...optional(item, 'detail', text),
|
|
119
|
+
...optional(item, 'shortcut', text),
|
|
120
|
+
...optional(item, 'showOnly', flag),
|
|
121
|
+
...optional(item, 'enabled', flag),
|
|
122
|
+
...optional(item, 'checked', flag),
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const menu = (c: Check, value: unknown): HostMenu => {
|
|
127
|
+
const m = record(value, 'a menu')
|
|
128
|
+
return {
|
|
129
|
+
id: text(m.id, 'a menu id'),
|
|
130
|
+
label: text(m.label, 'a menu label'),
|
|
131
|
+
...optional(m, 'primary', flag),
|
|
132
|
+
...optional(m, 'status', flag),
|
|
133
|
+
items: list(c, m.items, MAX_ROWS, 'a menu', menuItem),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const dockItem = (c: Check, value: unknown): HostDockItem => {
|
|
138
|
+
const item = record(value, 'a dock item')
|
|
139
|
+
if (item.type === 'stack') throw new Malformed('a stack in a stack')
|
|
140
|
+
if (item.type !== 'item') return refuse('a dock item has no type')
|
|
141
|
+
return {
|
|
142
|
+
type: 'item',
|
|
143
|
+
id: text(item.id, 'a dock id'),
|
|
144
|
+
label: text(item.label, 'a dock label'),
|
|
145
|
+
...optional(item, 'description', text),
|
|
146
|
+
...image(c, item, 'a dock item'),
|
|
147
|
+
...optional(item, 'badge', text),
|
|
148
|
+
...optional(item, 'disabled', flag),
|
|
149
|
+
running: flag(item.running, 'running'),
|
|
150
|
+
focused: flag(item.focused, 'focused'),
|
|
151
|
+
minimized: flag(item.minimized, 'minimized'),
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const dockEntry = (c: Check, value: unknown): HostDockEntry => {
|
|
156
|
+
const entry = record(value, 'a dock entry')
|
|
157
|
+
if (entry.type === 'separator') return { type: 'separator', id: text(entry.id, 'a dock id') }
|
|
158
|
+
if (entry.type !== 'stack') return dockItem(c, entry)
|
|
159
|
+
return {
|
|
160
|
+
type: 'stack',
|
|
161
|
+
id: text(entry.id, 'a dock id'),
|
|
162
|
+
label: text(entry.label, 'a dock label'),
|
|
163
|
+
...image(c, entry, 'a stack'),
|
|
164
|
+
items: list(c, entry.items, MAX_ROWS, 'a stack', item => dockItem(c, item)),
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const settingsSection = (value: unknown): HostSettingsSection => {
|
|
169
|
+
const section = record(value, 'a settings section')
|
|
170
|
+
return {
|
|
171
|
+
id: text(section.id, 'a section id'),
|
|
172
|
+
title: text(section.title, 'a section title'),
|
|
173
|
+
...optional(section, 'group', text),
|
|
174
|
+
...optional(section, 'badge', text),
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const labelledLink = (c: Check, value: unknown) => {
|
|
179
|
+
const l = record(value, 'a link')
|
|
180
|
+
return { label: text(l.label, 'a link label'), url: link(l.url, 'a link', c.origin) }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const fact = (c: Check, value: unknown): HostAboutFact => {
|
|
184
|
+
const f = record(value, 'a fact')
|
|
185
|
+
if (f.copy !== undefined && f.copy !== false) return refuse('a fact has a bad copy')
|
|
186
|
+
return {
|
|
187
|
+
name: text(f.name, 'a fact name'),
|
|
188
|
+
value: text(f.value, 'a fact value'),
|
|
189
|
+
...(f.link === undefined ? {} : orDrop<{ link: NonNullable<HostAboutFact['link']> } | Record<string, never>>(c, () => ({ link: labelledLink(c, f.link) }), {})),
|
|
190
|
+
...(f.copy === false ? { copy: false as const } : {}),
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const about = (c: Check, value: unknown): HostAbout | null => {
|
|
195
|
+
if (value === null) return null
|
|
196
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Malformed('about is not an object')
|
|
197
|
+
const a = value as Fields
|
|
198
|
+
return orDrop(
|
|
199
|
+
c,
|
|
200
|
+
() => ({
|
|
201
|
+
name: text(a.name, 'the name'),
|
|
202
|
+
...optional(a, 'version', text),
|
|
203
|
+
links: list(c, a.links, MAX_LINKS, 'links', l => labelledLink(c, l)),
|
|
204
|
+
...optional(a, 'note', text),
|
|
205
|
+
facts:
|
|
206
|
+
a.facts === null
|
|
207
|
+
? null
|
|
208
|
+
: list(c, a.facts, MAX_SECTIONS, 'facts', s => {
|
|
209
|
+
const section = record(s, 'a section of facts')
|
|
210
|
+
return { ...optional(section, 'title', text), facts: list(c, section.facts, MAX_ROWS, 'a section of facts', f => fact(c, f)) }
|
|
211
|
+
}),
|
|
212
|
+
}),
|
|
213
|
+
null,
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** A top-level list: refused whole when it is not one. */
|
|
218
|
+
const topList = <T,>(c: Check, value: unknown, max: number, what: string, check: (value: unknown) => T): T[] => {
|
|
219
|
+
if (!Array.isArray(value)) throw new Malformed(`${what} is not a list`)
|
|
220
|
+
return list(c, value, max, what, check)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Checks the chrome an app at `origin` sent before the host draws it, and returns a copy with only the
|
|
225
|
+
* fields a `DeskChrome` has. Text must be strings of bounded length, lists bounded too, links http(s),
|
|
226
|
+
* `mailto:` or the app's own, and images from `origin` or `data:` PNG, JPEG, WebP, AVIF or GIF.
|
|
227
|
+
* Relative links and images come back resolved against `origin`, since the host's frame is elsewhere.
|
|
228
|
+
* A part that fails is dropped and the rest kept, with a short reason in `dropped` for each; chrome
|
|
229
|
+
* of the wrong shape (see above) is refused whole.
|
|
230
|
+
*/
|
|
231
|
+
export function checkChrome(value: unknown, origin: string): ChromeCheck {
|
|
232
|
+
let size: number
|
|
233
|
+
try {
|
|
234
|
+
size = JSON.stringify(value ?? null).length
|
|
235
|
+
} catch {
|
|
236
|
+
return { ok: false, reason: 'not data' }
|
|
237
|
+
}
|
|
238
|
+
if (size > MAX_CHROME) return { ok: false, reason: 'too large' }
|
|
239
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return { ok: false, reason: 'chrome is not an object' }
|
|
240
|
+
const chrome = value as Fields
|
|
241
|
+
const c: Check = { origin, dropped: [] }
|
|
242
|
+
try {
|
|
243
|
+
return {
|
|
244
|
+
ok: true,
|
|
245
|
+
chrome: {
|
|
246
|
+
menus: topList(c, chrome.menus, MAX_MENUS, 'menus', m => menu(c, m)),
|
|
247
|
+
dock: topList(c, chrome.dock, MAX_ROWS, 'the dock', entry => dockEntry(c, entry)),
|
|
248
|
+
settings: topList(c, chrome.settings, MAX_SECTIONS, 'settings', settingsSection),
|
|
249
|
+
about: about(c, chrome.about),
|
|
250
|
+
},
|
|
251
|
+
dropped: c.dropped,
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (error instanceof Malformed) return { ok: false, reason: error.message }
|
|
255
|
+
throw error
|
|
256
|
+
}
|
|
257
|
+
}
|