@liberation-data/desk 0.44.0 → 0.46.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 +72 -9
- package/dist/core/desk.d.ts +2 -0
- package/dist/core/desk.d.ts.map +1 -1
- package/dist/core/desk.js +11 -2
- package/dist/core/desk.js.map +1 -1
- package/dist/core/hosted.d.ts +15 -0
- package/dist/core/hosted.d.ts.map +1 -1
- package/dist/core/hosted.js +28 -0
- package/dist/core/hosted.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/theme.d.ts +15 -0
- package/dist/core/theme.d.ts.map +1 -1
- package/dist/core/theme.js +73 -1
- package/dist/core/theme.js.map +1 -1
- package/dist/core/types.d.ts +5 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/css/apps.css +17 -0
- package/dist/css/shell.css +89 -0
- package/dist/css/windows.css +28 -0
- package/dist/desk.css +45 -0
- package/dist/host/checkTheme.d.ts +2 -7
- package/dist/host/checkTheme.d.ts.map +1 -1
- package/dist/host/checkTheme.js +3 -27
- package/dist/host/checkTheme.js.map +1 -1
- package/dist/host/router.d.ts +1 -0
- package/dist/host/router.d.ts.map +1 -1
- package/dist/host/router.js +11 -0
- package/dist/host/router.js.map +1 -1
- package/dist/react/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +11 -14
- package/dist/react/Desktop.js.map +1 -1
- package/dist/react/app.d.ts +15 -3
- package/dist/react/app.d.ts.map +1 -1
- package/dist/react/app.js +20 -8
- package/dist/react/app.js.map +1 -1
- package/dist/react/appPanels.d.ts.map +1 -1
- package/dist/react/appPanels.js +44 -5
- package/dist/react/appPanels.js.map +1 -1
- package/dist/react/context.d.ts +16 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +5 -3
- package/dist/react/context.js.map +1 -1
- package/dist/react/hostApp.d.ts +3 -1
- package/dist/react/hostApp.d.ts.map +1 -1
- package/dist/react/hostApp.js +3 -2
- package/dist/react/hostApp.js.map +1 -1
- package/dist/react/hosted.d.ts +10 -3
- package/dist/react/hosted.d.ts.map +1 -1
- package/dist/react/hosted.js +68 -8
- package/dist/react/hosted.js.map +1 -1
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/mediaQuery.d.ts +3 -0
- package/dist/react/mediaQuery.d.ts.map +1 -0
- package/dist/react/mediaQuery.js +11 -0
- package/dist/react/mediaQuery.js.map +1 -0
- package/dist/react/shell.d.ts +3 -1
- package/dist/react/shell.d.ts.map +1 -1
- package/dist/react/shell.js +2 -2
- package/dist/react/shell.js.map +1 -1
- package/dist/react/sidebar.d.ts +6 -1
- package/dist/react/sidebar.d.ts.map +1 -1
- package/dist/react/sidebar.js +6 -3
- package/dist/react/sidebar.js.map +1 -1
- package/dist/react/windowDescription.d.ts +7 -0
- package/dist/react/windowDescription.d.ts.map +1 -1
- package/dist/react/windowDescription.js +9 -0
- package/dist/react/windowDescription.js.map +1 -1
- package/dist/shell/HostOverview.d.ts +41 -0
- package/dist/shell/HostOverview.d.ts.map +1 -0
- package/dist/shell/HostOverview.js +219 -0
- package/dist/shell/HostOverview.js.map +1 -0
- package/dist/shell/HostShell.d.ts +3 -1
- package/dist/shell/HostShell.d.ts.map +1 -1
- package/dist/shell/HostShell.js +6 -4
- package/dist/shell/HostShell.js.map +1 -1
- package/dist/shell/index.d.ts +4 -0
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -0
- package/dist/shell/index.js.map +1 -1
- package/dist/shell/zoom.d.ts +62 -0
- package/dist/shell/zoom.d.ts.map +1 -0
- package/dist/shell/zoom.js +116 -0
- package/dist/shell/zoom.js.map +1 -0
- package/llms.txt +18 -10
- package/package.json +12 -7
- package/src/core/desk.ts +11 -2
- package/src/core/hosted.ts +33 -0
- package/src/core/index.ts +1 -1
- package/src/core/theme.ts +69 -1
- package/src/core/types.ts +5 -0
- package/src/css/apps.css +17 -0
- package/src/css/shell.css +89 -0
- package/src/css/windows.css +28 -0
- package/src/host/checkTheme.ts +3 -25
- package/src/host/router.ts +12 -0
- package/src/react/Desktop.tsx +16 -21
- package/src/react/app.tsx +32 -8
- package/src/react/appPanels.tsx +64 -6
- package/src/react/context.tsx +20 -2
- package/src/react/hostApp.tsx +3 -2
- package/src/react/hosted.tsx +68 -8
- package/src/react/index.ts +3 -2
- package/src/react/mediaQuery.ts +18 -0
- package/src/react/shell.tsx +4 -2
- package/src/react/sidebar.tsx +10 -3
- package/src/react/windowDescription.ts +12 -1
- package/src/shell/HostOverview.tsx +317 -0
- package/src/shell/HostShell.tsx +8 -5
- package/src/shell/index.ts +18 -0
- package/src/shell/zoom.ts +151 -0
package/llms.txt
CHANGED
|
@@ -64,7 +64,8 @@ fitFrame(frame, stage, min?): Frame | null; stepFrom(frame, open: Frame[], stage
|
|
|
64
64
|
interface Desk {
|
|
65
65
|
getState(): DeskState
|
|
66
66
|
subscribe(listener: (state: DeskState) => void): () => void
|
|
67
|
-
open(id: string, options?: { mode?: 'filled' | 'floating'; frame?: Frame; route?: string }): void // default fills; a frame floats;
|
|
67
|
+
open(id: string, options?: { mode?: 'filled' | 'floating'; frame?: Frame; size?: Size; route?: string }): void // default fills; a frame floats;
|
|
68
|
+
// size: free, centred at that size, unless left filled or placed last time;
|
|
68
69
|
// a route moves it there, open already or not
|
|
69
70
|
openInstance(type: string, options?): string // 'query', then 'query#2' — returns the id it opened
|
|
70
71
|
close(id: string): void
|
|
@@ -264,6 +265,7 @@ useWindowRoute(): [route, setRoute] // where this window is insi
|
|
|
264
265
|
useWindowProgress({ value, max, label } | null): boolean // a real count in this window's title bar; false outside one
|
|
265
266
|
useWindowNote(note: ReactNode): boolean // this view's note in place of the window's; null defers, false hides
|
|
266
267
|
useWindowInfo(info: ReactNode): boolean // this view's (i) in place of the window's; null defers
|
|
268
|
+
useWindowBack({ label, title, onBack } | null): boolean // a view one step in: "‹ label" (named "Back to label") before the title, which becomes `title`
|
|
267
269
|
|
|
268
270
|
<Desktop
|
|
269
271
|
renderWindow={(id) => ReactNode} // memoised: chrome re-renders, content does not
|
|
@@ -379,17 +381,21 @@ useWindowMenus(menus: Menu[]) // inside a window: its menus join the bar while
|
|
|
379
381
|
// about: { name, version?, links, note? (text only), facts: { title?, facts: { name, value, link?, copy?: false }[] }[] | null } from the app declaration; facts null while read, [] for nothing to report. Hosted implies themeFromHost; the primary declares themeFromHost: false to keep its Appearance and its own theme.
|
|
380
382
|
interface DeskHostBridge { version: 1; send(m: AppToHost): void; onMessage(l: (m: HostToApp) => void): () => void }
|
|
381
383
|
connectHost(bridge): HostClient // core, for a page without React; DeskProvider calls it
|
|
382
|
-
useHost(): HostClient | null // publish(topic, payload); subscribe(publisher: appId | 'primary', topic, handler); onCommand; setChrome
|
|
383
|
-
|
|
384
|
+
useHost(): HostClient | null // publish(topic, payload); subscribe(publisher: appId | 'primary', topic, handler); onCommand; setChrome; primary(): boolean | null; onRole(l: (primary) => void)
|
|
385
|
+
// connectHost sends { kind: 'hello' }; the host answers { kind: 'role', primary: boolean }, again on any change (createBroadcastRouter does; a host without it must). No answer: nothing published by default.
|
|
386
|
+
// The primary publishes appliedTheme(root?) (scheme, look, --desk-* tokens as worn; url() tokens and fonts left out) by default, again on change; <DeskShell|DeskProvider publishTheme={false}> turns it off
|
|
387
|
+
useHosted(): boolean; useHostBroadcast(publisher, topic, handler); usePublishTheme(theme: DeskTheme | null) // publishes this theme instead of appliedTheme while mounted
|
|
384
388
|
interface DeskTheme { mode: 'light'|'dark'; look: Look; tokens: Record<`--${string}`, string>; fonts?: { family; src; weight?; style? }[]; wallpaper?: string }
|
|
385
389
|
<DeskShell onTheme={theme => …}> // keep some looks of your own; mode and look always apply. Default: applyTheme(theme)
|
|
386
390
|
hostDockModel(entries, state): { model: HostDockEntry[]; run: Map<id, DockItem> } // the dock as data, as HostedDock sends it
|
|
387
391
|
// '@liberation-data/desk/host' (the host's half): createBroadcastRouter({ deliver, chrome?: (appId, chrome, dropped: string[]) => void, check?, maxPayload?, limits?: { burst?, perSecond?, topics?, maxTopics? }, clock? }), router.limited(appId), checkTheme(theme, origin), checkChrome(chrome, origin): { ok: true, chrome, dropped } | { ok: false, reason }, createMemoryHost()
|
|
388
|
-
// '@liberation-data/desk/shell' (the host's page only, with css/shell.css): <HostShell workspaces={{ id, title, accent?, icon?, primary?, state: 'live'|'suspended'|'discarded' }[]} current chrome={Record<appId, DeskChrome|null>} theme? snapshots?={Record<id, imageUrl>} keys?={SwitchKeys|null} clickSwitch?={'slide'} dockSide? onSwitch={(id, how) => …} onCommand={(appId, 'dock'|'menu'|'settings', itemId) => …} onInsets?={({ top, right, bottom, left }) => …} />
|
|
392
|
+
// '@liberation-data/desk/shell' (the host's page only, with css/shell.css): <HostShell workspaces={{ id, title, accent?, icon?, primary?, state: 'live'|'suspended'|'discarded' }[]} current chrome={Record<appId, DeskChrome|null>} theme? snapshots?={Record<id, imageUrl>} keys?={SwitchKeys|null} clickSwitch?={'zoom'|'slide'} dockSide? onSwitch={(id, how) => …} onOverview?={() => …} onCommand={(appId, 'dock'|'menu'|'settings', itemId) => …} onInsets?={({ top, right, bottom, left }) => …} />
|
|
389
393
|
// It draws the current app's dock and a switcher (one Tab stop, arrows/Home/End, title announced once on arrival); the host moves the views and passes the new current.
|
|
390
394
|
// switchKeys(platformOf(process.platform)): mac Ctrl+Opt+←/→/↑, Linux Super+Alt, Windows Ctrl+Alt; switchKeyAction(pageEvent | electronInput, keys): 'previous'|'next'|'overview'|null (key releases ignored); neighbour(workspaces, current, step) | null at the ends
|
|
391
395
|
// slidePlan(reducedMotion): { kind: 'slide', 350 } | { kind: 'fade', 120 }; spring(ms, from?, velocity?) → t => progress, no overshoot; slideOffsets(progress, 1|-1, width): { leaving, arriving } whole px, no gap: clip views to the desktop area or they cover the dock
|
|
392
396
|
// animate({ durationMs, step, curve?, clock?: pageClock()|timerClock(), timeoutMs? = 250 }): { done: 'finished'|'jumped'|'stopped', progress(), stop() }; jumps to 1 when frames stop
|
|
397
|
+
// <HostOverview workspaces current snapshots?={Record<id, imageUrl>} request={{ kind: 'open' } | { kind: 'switch', to } | null} theme? insets? visible? reducedMotion? pose? onWantCapture?={id => …} onCover?={() => …} onArrive={id => …} /> // an overlay over the views; capture on onWantCapture into snapshots and return a promise of its URL (an identical picture still counts; waits 100 ms at most), hide views on onCover, swap the view in and clear request on onArrive; each once per move; the host revokes its own snapshot URLs
|
|
398
|
+
// planZoom(from, to, reducedMotion?): { phases: out 200 / across 250 / in 200 | fade 120, durationMs, to }; poseAt(plan, ms): { zoom, centre, fog, opacity }; overviewTiles(count, pose, width): { x, z, scale, opacity, layer }[]
|
|
393
399
|
// Rate limits per publisher+topic: 20 then 10/s (theme 2 then 1/s), 64 topics at once; over it the latest is held (never queued), so subscribers end on the last value; order holds within a topic.
|
|
394
400
|
// register({ id, origin, primary?, publishes? }): the primary's publishes must include 'theme'. A deliver that throws for one app still lets the rest hear; the error is thrown after.
|
|
395
401
|
// chrome(appId, null) when an app is unregistered: stop drawing its chrome. The primary's last theme is kept while it is down and replayed to subscribers of 'primary'.
|
|
@@ -425,9 +431,9 @@ interface DeskApp { name; icon?; wordmark?: ReactNode; version?; description?; l
|
|
|
425
431
|
facts?: () => AboutSection[] | null; // a HOOK, called inside the About panel; null = still reading, [] = nothing, no Copy
|
|
426
432
|
settings?: AppSettings } // leave out: no gear, no "Settings…", no ⌘,
|
|
427
433
|
interface AboutSection { title?; pending?: boolean; facts: { name; value: string; copyValue?: string; note?: ReactNode; link?: { label, url }; copy?: false }[] } // copy:false = shown, not copied; note and link never copied; copyValue copied in place of value; pending = "Checking", left out of Copy
|
|
428
|
-
interface AppSettings { sections?: SettingsSection[]; layout?: 'panel' | 'sidebar'; badge?: ReactNode;
|
|
434
|
+
interface AppSettings { sections?: SettingsSection[]; layout?: 'panel' | 'sidebar'; badge?: ReactNode; limits?: WindowLimits; // limits: the sidebar layout's
|
|
429
435
|
open?: (route?: string) => void } // open: the app's own Settings window; Desk draws none
|
|
430
|
-
interface SettingsSection { id; title; group?; icon?; badge?; content: ReactNode } // id = the route of `settings
|
|
436
|
+
interface SettingsSection { id; title; group?; icon?; badge?; note?: ReactNode; content: ReactNode } // id = the route of `settings`; note: the window's note while open (one page: under the heading)
|
|
431
437
|
// AppSettings.appearance?: true | { scheme?; defaultScheme?: 'system'|'light'|'dark'; look?; sounds?: Fx; soundsDescription?; theme?: ReactNode } // Desk's first section
|
|
432
438
|
// defaultScheme: what applies while nothing is chosen (default 'system'); give colorSchemeScript the same
|
|
433
439
|
// DeskApp.themeFromHost?: boolean // receives its theme from a host: no scheme/look/theme rows (sounds stay); default: found from the bridge
|
|
@@ -443,7 +449,7 @@ setPreferenceStore(store?); getPreference(key); setPreference(key, value); subsc
|
|
|
443
449
|
dockSettings(); dockAbout() // markers: where the gear / About go, among dock entries OR in a stack's items
|
|
444
450
|
// (a System stack); placed, Desk adds no loose one. Default: end of the system group
|
|
445
451
|
SETTINGS_WINDOW = 'settings'; ABOUT_WINDOW = 'about'; SettingsCommand = 'desk.settings'; SYSTEM_GROUP = 'system'
|
|
446
|
-
PANEL_LIMITS; SIDEBAR_LIMITS
|
|
452
|
+
PANEL_LIMITS; SIDEBAR_LIMITS; SIDEBAR_SIZE // the panel fits its content; the sidebar layout opens free at SIDEBAR_SIZE (720 × 640), resizable and fillable; Desktop `limits` for those ids overrides
|
|
447
453
|
openAbout(desk) // About as the dock opens it: a centred panel, or forward where it is
|
|
448
454
|
useOpenSettings(): (route?) => void // Settings as the gear opens it (the app's own `open` too); nothing without settings
|
|
449
455
|
openSettings(desk, route?) // the same, outside React (search results, link handlers); reads the provider's declaration
|
|
@@ -456,7 +462,8 @@ Declared, Desk adds: in the Dock, the gear (when there are settings) and About a
|
|
|
456
462
|
group (entries after `dockSeparator('system')`; a separator and group of their own when there is none); in the
|
|
457
463
|
MenuBar's app menu (first with `emphasis`, else one is made, named `name`) "About <name>", separator,
|
|
458
464
|
"Settings…" (mod+comma), separator, then the app's items; Desktop draws the `about` and (with `settings` and no `open`) `settings` windows as
|
|
459
|
-
centred panels (sidebar layout: a
|
|
465
|
+
centred panels (sidebar layout: a window like any other, with a Sidebar grouped by `group`; on a narrow screen,
|
|
466
|
+
(max-width: 600px), the list alone, then the section, its title in the title row after "‹ Settings"; arrows move, Enter opens). Gear, menu and ⌘, focus an
|
|
460
467
|
open panel where it is. ⌘, is bound by the provider on the command, so it works with no MenuBar; the menu item only
|
|
461
468
|
shows it. A `host` menu bar gets the same items through the same publish; the host owns ⌘, while it is up.
|
|
462
469
|
With facts, About has Copy: name + version, then each section's copyable facts. Never put credentials in facts.
|
|
@@ -616,7 +623,7 @@ interface Column<Row> { key; header; render?; align?; numeric?; sortable?; width
|
|
|
616
623
|
interface Sort { key: string; direction: 'ascending' | 'descending' }
|
|
617
624
|
|
|
618
625
|
<Sidebar sections={{ id, label?, items: { id, label, icon?, badge?, disabled? }[] }[]}
|
|
619
|
-
value onChange label footer? />
|
|
626
|
+
value onChange label footer? focusOnly? /> // focusOnly: arrows move focus only, Enter/click chooses (a list shown alone)
|
|
620
627
|
|
|
621
628
|
<Outline rows={{ id, label, depth, disabled? }[]} value={string | null} onChange showing? label />
|
|
622
629
|
```
|
|
@@ -748,4 +755,5 @@ in the accessibility tree.
|
|
|
748
755
|
- `npm run size` enforces a budget on each entry, measured gzipped without comments (so explanations cost nothing): core 13.5 KiB, react 70.5, css 14, fx 4, host 7.5; each is the measured size plus 1 KiB, rounded up to a half.
|
|
749
756
|
- `fx.play` never resumes audio itself: outside a press a browser's resume may never settle. Call
|
|
750
757
|
`fx.unlock()` at startup, or nothing sounds until a press after the sound was due.
|
|
751
|
-
- The package is ESM
|
|
758
|
+
- The package is ESM, with `"sideEffects": ["**/*.css"]`. CommonJS code (an Electron main process) can `require()` every
|
|
759
|
+
entry on Node 22.12 or later.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liberation-data/desk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "A desktop environment for React apps: windows, a dock, menus and commands, controls, tours and setup assistants.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -36,23 +36,28 @@
|
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
38
|
"types": "./dist/core/index.d.ts",
|
|
39
|
-
"import": "./dist/core/index.js"
|
|
39
|
+
"import": "./dist/core/index.js",
|
|
40
|
+
"default": "./dist/core/index.js"
|
|
40
41
|
},
|
|
41
42
|
"./react": {
|
|
42
43
|
"types": "./dist/react/index.d.ts",
|
|
43
|
-
"import": "./dist/react/index.js"
|
|
44
|
+
"import": "./dist/react/index.js",
|
|
45
|
+
"default": "./dist/react/index.js"
|
|
44
46
|
},
|
|
45
47
|
"./host": {
|
|
46
48
|
"types": "./dist/host/index.d.ts",
|
|
47
|
-
"import": "./dist/host/index.js"
|
|
49
|
+
"import": "./dist/host/index.js",
|
|
50
|
+
"default": "./dist/host/index.js"
|
|
48
51
|
},
|
|
49
52
|
"./shell": {
|
|
50
53
|
"types": "./dist/shell/index.d.ts",
|
|
51
|
-
"import": "./dist/shell/index.js"
|
|
54
|
+
"import": "./dist/shell/index.js",
|
|
55
|
+
"default": "./dist/shell/index.js"
|
|
52
56
|
},
|
|
53
57
|
"./fx": {
|
|
54
58
|
"types": "./dist/fx/index.d.ts",
|
|
55
|
-
"import": "./dist/fx/index.js"
|
|
59
|
+
"import": "./dist/fx/index.js",
|
|
60
|
+
"default": "./dist/fx/index.js"
|
|
56
61
|
},
|
|
57
62
|
"./desk.css": "./dist/desk.css",
|
|
58
63
|
"./css/*": "./dist/css/*"
|
|
@@ -64,7 +69,7 @@
|
|
|
64
69
|
"example": "vite examples/garage",
|
|
65
70
|
"prepublishOnly": "npm run typecheck && npm test && npm run build",
|
|
66
71
|
"size": "node scripts/size.mjs",
|
|
67
|
-
"check": "npm run typecheck && npm test && npm run build && npm run size",
|
|
72
|
+
"check": "npm run typecheck && npm test && npm run build && npm run size && node scripts/require.mjs",
|
|
68
73
|
"check:browser": "node scripts/browser-check.mjs",
|
|
69
74
|
"screenshots": "node scripts/screenshots.mjs"
|
|
70
75
|
},
|
package/src/core/desk.ts
CHANGED
|
@@ -139,6 +139,15 @@ export function nextCascadeFrame(windows: readonly DeskWindow[], stage: Size, op
|
|
|
139
139
|
return cascadeFrame(taken.size % options.wrap, stage, options)
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
/** A frame of this size in the middle of the stage, made smaller where the stage is, keeping a margin. */
|
|
143
|
+
export function centredFrame(size: Size, stage: Size, margin: number): Frame {
|
|
144
|
+
// A stage not measured yet has no size to fit to: the size as asked, at the margin.
|
|
145
|
+
if (stage.width <= 0 || stage.height <= 0) return { x: margin, y: margin, ...size }
|
|
146
|
+
const width = Math.max(0, Math.min(size.width, stage.width - margin * 2))
|
|
147
|
+
const height = Math.max(0, Math.min(size.height, stage.height - margin * 2))
|
|
148
|
+
return { x: Math.round((stage.width - width) / 2), y: Math.round((stage.height - height) / 2), width, height }
|
|
149
|
+
}
|
|
150
|
+
|
|
142
151
|
/** Is this frame wholly on a desk of this size? */
|
|
143
152
|
const withinStage = (frame: Frame, stage: Size) =>
|
|
144
153
|
frame.x >= 0 && frame.y >= 0 && frame.x + frame.width <= stage.width && frame.y + frame.height <= stage.height
|
|
@@ -279,10 +288,10 @@ export function createDesk(options: DeskOptions = {}): Desk {
|
|
|
279
288
|
}
|
|
280
289
|
const saved = opts.mode || opts.frame ? undefined : layouts?.load(windowType(id))
|
|
281
290
|
const kept = saved?.mode === 'floating' ? fitFrame(saved.frame, stage()) : null
|
|
282
|
-
const mode = opts.mode ?? (opts.frame || kept ? 'floating' : 'filled')
|
|
291
|
+
const mode = opts.mode ?? (opts.frame || kept || (opts.size && !saved) ? 'floating' : 'filled')
|
|
283
292
|
const frame = () => {
|
|
284
293
|
if (opts.frame) return opts.frame
|
|
285
|
-
if (!kept) return nextFrame(state)
|
|
294
|
+
if (!kept) return opts.size ? centredFrame(opts.size, stage(), cascade.margin) : nextFrame(state)
|
|
286
295
|
const siblings = state.stack.flatMap(other => {
|
|
287
296
|
const w = find(other)
|
|
288
297
|
return w?.mode === 'floating' && windowType(w.id) === windowType(id) ? [w.frame] : []
|
package/src/core/hosted.ts
CHANGED
|
@@ -171,12 +171,16 @@ export type AppToHost =
|
|
|
171
171
|
| { readonly desk: 1; readonly kind: 'publish'; readonly topic: string; readonly payload: unknown }
|
|
172
172
|
| { readonly desk: 1; readonly kind: 'subscribe'; readonly publisher: Publisher; readonly topic: string }
|
|
173
173
|
| { readonly desk: 1; readonly kind: 'unsubscribe'; readonly publisher: Publisher; readonly topic: string }
|
|
174
|
+
/** Sent on connecting: the host answers with the app's `role`. */
|
|
175
|
+
| { readonly desk: 1; readonly kind: 'hello' }
|
|
174
176
|
|
|
175
177
|
/** What a host sends an app: a choice from the chrome it draws, or another app's broadcast, stamped. */
|
|
176
178
|
export type HostToApp =
|
|
177
179
|
/** A menu item or dock item chosen by its id, or Settings opened at a section's id (`''` for the first). */
|
|
178
180
|
| { readonly desk: 1; readonly kind: 'command'; readonly target: CommandTarget; readonly id: string }
|
|
179
181
|
| { readonly desk: 1; readonly kind: 'broadcast'; readonly from: BroadcastSender; readonly topic: string; readonly payload: unknown }
|
|
182
|
+
/** Whether the app is the primary, whose theme the others wear: the answer to `hello`, and again when it changes. */
|
|
183
|
+
| { readonly desk: 1; readonly kind: 'role'; readonly primary: boolean }
|
|
180
184
|
|
|
181
185
|
/**
|
|
182
186
|
* The app's end of the connection to its host. The host provides it — an Electron preload through
|
|
@@ -219,6 +223,8 @@ export function isAppToHost(value: unknown): value is AppToHost {
|
|
|
219
223
|
case 'subscribe':
|
|
220
224
|
case 'unsubscribe':
|
|
221
225
|
return isString(value.publisher) && isString(value.topic) && value.topic.length > 0
|
|
226
|
+
case 'hello':
|
|
227
|
+
return true
|
|
222
228
|
default:
|
|
223
229
|
return false
|
|
224
230
|
}
|
|
@@ -232,6 +238,8 @@ export function isHostToApp(value: unknown): value is HostToApp {
|
|
|
232
238
|
return (value.target === 'menu' || value.target === 'dock' || value.target === 'settings') && isString(value.id)
|
|
233
239
|
case 'broadcast':
|
|
234
240
|
return isRecord(value.from) && isString(value.from.id) && isString(value.topic)
|
|
241
|
+
case 'role':
|
|
242
|
+
return typeof value.primary === 'boolean'
|
|
235
243
|
default:
|
|
236
244
|
return false
|
|
237
245
|
}
|
|
@@ -258,6 +266,10 @@ export interface HostClient {
|
|
|
258
266
|
* one straight away, so an app that starts late still hears the current theme.
|
|
259
267
|
*/
|
|
260
268
|
subscribe<T = unknown>(publisher: Publisher, topic: string, handler: (broadcast: Broadcast<T>) => void): () => void
|
|
269
|
+
/** Whether the host says this app is the primary; null until it has said. */
|
|
270
|
+
primary(): boolean | null
|
|
271
|
+
/** Calls the listener when the host says whether this app is the primary, now and on any change. */
|
|
272
|
+
onRole(listener: (primary: boolean) => void): () => void
|
|
261
273
|
/** Stops listening, and takes the chrome away. */
|
|
262
274
|
close(): void
|
|
263
275
|
}
|
|
@@ -274,9 +286,17 @@ export function connectHost(bridge: DeskHostBridge): HostClient {
|
|
|
274
286
|
/** Per subscription, the broadcasts last heard on each topic it covers, for a second handler that joins later. */
|
|
275
287
|
const subscriptions = new Map<string, { publisher: Publisher; topic: string; handlers: Set<Handler>; last: Map<string, Broadcast> }>()
|
|
276
288
|
const keyOf = (publisher: string, topic: string) => `${publisher}\u0000${topic}`
|
|
289
|
+
let primary: boolean | null = null
|
|
290
|
+
const roles = new Set<(primary: boolean) => void>()
|
|
277
291
|
|
|
278
292
|
const stop = bridge.onMessage(message => {
|
|
279
293
|
if (closed || !isHostToApp(message)) return
|
|
294
|
+
if (message.kind === 'role') {
|
|
295
|
+
if (primary === message.primary) return
|
|
296
|
+
primary = message.primary
|
|
297
|
+
for (const listener of [...roles]) if (roles.has(listener)) listener(message.primary)
|
|
298
|
+
return
|
|
299
|
+
}
|
|
280
300
|
if (message.kind === 'command') {
|
|
281
301
|
const listeners = commands[message.target]
|
|
282
302
|
// Copied, and each still checked: a listener may take another away while this one runs.
|
|
@@ -293,6 +313,9 @@ export function connectHost(bridge: DeskHostBridge): HostClient {
|
|
|
293
313
|
}
|
|
294
314
|
})
|
|
295
315
|
|
|
316
|
+
// Listening first, so a host that answers at once is heard.
|
|
317
|
+
bridge.send({ desk: DESK_PROTOCOL, kind: 'hello' })
|
|
318
|
+
|
|
296
319
|
return {
|
|
297
320
|
bridge,
|
|
298
321
|
setChrome(part) {
|
|
@@ -337,8 +360,18 @@ export function connectHost(bridge: DeskHostBridge): HostClient {
|
|
|
337
360
|
}
|
|
338
361
|
}
|
|
339
362
|
},
|
|
363
|
+
primary: () => primary,
|
|
364
|
+
onRole(listener) {
|
|
365
|
+
roles.add(listener)
|
|
366
|
+
if (primary !== null) listener(primary)
|
|
367
|
+
return () => {
|
|
368
|
+
roles.delete(listener)
|
|
369
|
+
}
|
|
370
|
+
},
|
|
340
371
|
close() {
|
|
341
372
|
if (closed) return
|
|
373
|
+
roles.clear()
|
|
374
|
+
primary = null
|
|
342
375
|
bridge.send({ desk: DESK_PROTOCOL, kind: 'chrome', chrome: EMPTY_CHROME })
|
|
343
376
|
// So the host stops sending what nobody here hears.
|
|
344
377
|
for (const { publisher, topic } of subscriptions.values()) bridge.send({ desk: DESK_PROTOCOL, kind: 'unsubscribe', publisher, topic })
|
package/src/core/index.ts
CHANGED
|
@@ -39,7 +39,7 @@ export { COLOR_SCHEME_KEY, COLOR_SCHEME_SCRIPT, colorSchemeScript, LOOK_KEY } fr
|
|
|
39
39
|
export { getPreference, localPreferences, setPreference, setPreferenceStore, subscribePreferences } from './preferences.js'
|
|
40
40
|
export type { PreferenceStore } from './preferences.js'
|
|
41
41
|
export type { ColorScheme } from './scheme.js'
|
|
42
|
-
export { applyTheme, applyThemeBasics } from './theme.js'
|
|
42
|
+
export { applyTheme, applyThemeBasics, appliedTheme } from './theme.js'
|
|
43
43
|
export { drawnTheme, THEME_CHANGE, watchThemeChanges } from './themeChange.js'
|
|
44
44
|
export type { ThemeChange } from './themeChange.js'
|
|
45
45
|
export type { AppTheme, DeskTheme, ThemeFont } from './theme.js'
|
package/src/core/theme.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Look } from './look.js'
|
|
2
|
-
import { themeChanged, watchThemeChanges } from './themeChange.js'
|
|
2
|
+
import { drawnTheme, themeChanged, watchThemeChanges } from './themeChange.js'
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* A LOOK ONE APP LENDS TO OTHERS.
|
|
@@ -44,6 +44,30 @@ export interface DeskTheme extends AppTheme {
|
|
|
44
44
|
*/
|
|
45
45
|
export const isImageRef = (wallpaper: string): boolean => /^(data:|[a-z][\w+.-]*:\/\/|\/)/i.test(wallpaper)
|
|
46
46
|
|
|
47
|
+
/** The CSS functions a token may use: colours, maths, gradients and other custom properties. Nothing that loads. */
|
|
48
|
+
const FUNCTIONS = new Set([
|
|
49
|
+
'rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color', 'color-mix', 'light-dark',
|
|
50
|
+
'var', 'calc', 'min', 'max', 'clamp',
|
|
51
|
+
'linear-gradient', 'radial-gradient', 'conic-gradient', 'repeating-linear-gradient', 'repeating-radial-gradient',
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
const MAX_VALUE = 300
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether a custom property's value is plain: a colour, a length, a number, a font list or a gradient.
|
|
58
|
+
* Only letters, digits, spaces and `#.,%/'"+-()*` may appear, every function is one of `FUNCTIONS`, and
|
|
59
|
+
* nothing may escape, end the declaration or open a block. So `url(…)`, `image-set(…)`, `\75rl(` and
|
|
60
|
+
* `red; background: …` are all refused.
|
|
61
|
+
*/
|
|
62
|
+
export function isPlainValue(value: string): boolean {
|
|
63
|
+
if (value.length > MAX_VALUE) return false
|
|
64
|
+
if (!/^[\w\s#.,%/'"+*()-]*$/.test(value)) return false
|
|
65
|
+
for (const match of value.matchAll(/([\w-]*)\s*\(/g)) {
|
|
66
|
+
if (!FUNCTIONS.has((match[1] ?? '').toLowerCase())) return false
|
|
67
|
+
}
|
|
68
|
+
return true
|
|
69
|
+
}
|
|
70
|
+
|
|
47
71
|
/**
|
|
48
72
|
* The part of a theme every hosted app wears whatever else it does: light or dark, and the
|
|
49
73
|
* platform chrome. One desktop light and the next dark would look broken as they slide past each
|
|
@@ -89,3 +113,47 @@ export function applyTheme(theme: DeskTheme, root: HTMLElement = document.docume
|
|
|
89
113
|
applied.set(root, { tokens: Object.keys(theme.tokens), fonts: faces })
|
|
90
114
|
if (root.style.cssText !== was) themeChanged(root.ownerDocument)
|
|
91
115
|
}
|
|
116
|
+
|
|
117
|
+
/** The most tokens a theme may carry: `checkTheme` refuses more, and `appliedTheme` takes no more. */
|
|
118
|
+
export const MAX_THEME_TOKENS = 400
|
|
119
|
+
|
|
120
|
+
/** Desk's custom properties the page sets on its root: in rules on the root, and in the root's own style. */
|
|
121
|
+
function rootTokens(root: HTMLElement): Set<string> {
|
|
122
|
+
const names = new Set<string>()
|
|
123
|
+
const take = (style: CSSStyleDeclaration) => {
|
|
124
|
+
for (let i = 0; i < style.length; i++) if (style[i]!.startsWith('--desk-')) names.add(style[i]!)
|
|
125
|
+
}
|
|
126
|
+
const walk = (sheet: { readonly cssRules: CSSRuleList } | null) => {
|
|
127
|
+
let rules: CSSRule[]
|
|
128
|
+
try {
|
|
129
|
+
rules = Array.from(sheet?.cssRules ?? [])
|
|
130
|
+
} catch {
|
|
131
|
+
// Another origin's stylesheet can't be read, and sets none of Desk's tokens.
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
for (const rule of rules) {
|
|
135
|
+
if ('selectorText' in rule && /:root|html|\[data-(theme|look)/.test((rule as CSSStyleRule).selectorText)) take((rule as CSSStyleRule).style)
|
|
136
|
+
// A block (@media, @layer, @supports) or an @import's sheet, such as desk.css imported by the app's own.
|
|
137
|
+
else if ('cssRules' in rule || 'styleSheet' in rule) walk('styleSheet' in rule ? (rule as CSSImportRule).styleSheet : (rule as CSSGroupingRule))
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const sheet of Array.from(root.ownerDocument.styleSheets)) walk(sheet)
|
|
141
|
+
take(root.style)
|
|
142
|
+
return names
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The theme this page wears now, as data another page can wear: light or dark and the look as drawn,
|
|
147
|
+
* and Desk's tokens as they apply on the root. Only what `checkTheme` would pass is taken: a token that
|
|
148
|
+
* loads something (`url(…)`) is left out, and so are fonts, which the page loads its own way.
|
|
149
|
+
*/
|
|
150
|
+
export function appliedTheme(root: HTMLElement = document.documentElement): DeskTheme {
|
|
151
|
+
const drawn = drawnTheme(root.ownerDocument)
|
|
152
|
+
const computed = getComputedStyle(root)
|
|
153
|
+
const tokens: Record<string, string> = {}
|
|
154
|
+
for (const name of [...rootTokens(root)].sort()) {
|
|
155
|
+
const value = computed.getPropertyValue(name).trim()
|
|
156
|
+
if (value && isPlainValue(value) && Object.keys(tokens).length < MAX_THEME_TOKENS) tokens[name] = value
|
|
157
|
+
}
|
|
158
|
+
return { mode: drawn.scheme, look: drawn.look, tokens }
|
|
159
|
+
}
|
package/src/core/types.ts
CHANGED
|
@@ -62,6 +62,11 @@ export interface OpenOptions {
|
|
|
62
62
|
/** Open as a free window rather than filling the desk. Given a frame, it floats there. */
|
|
63
63
|
readonly mode?: WindowMode
|
|
64
64
|
readonly frame?: Frame
|
|
65
|
+
/**
|
|
66
|
+
* A window that is best free at a size of its own, such as a big Settings: unless the person left it filled
|
|
67
|
+
* or at a frame last time, it opens free at this size, centred and fitted to the desk.
|
|
68
|
+
*/
|
|
69
|
+
readonly size?: Size
|
|
65
70
|
/** Where inside the window: given to a window already open, it moves there as it comes forward. */
|
|
66
71
|
readonly route?: string
|
|
67
72
|
}
|
package/src/css/apps.css
CHANGED
|
@@ -237,3 +237,20 @@
|
|
|
237
237
|
flex-direction: column;
|
|
238
238
|
gap: var(--desk-space-5);
|
|
239
239
|
}
|
|
240
|
+
|
|
241
|
+
/* A section's note, where there is no title bar to carry it: under its heading. */
|
|
242
|
+
.desk-settings-note {
|
|
243
|
+
margin: 0 0 var(--desk-space-3);
|
|
244
|
+
font-size: var(--desk-text-small);
|
|
245
|
+
color: var(--desk-muted);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* On a narrow screen, the list alone fills Settings, and Back leads a section. */
|
|
249
|
+
.desk-settings-list {
|
|
250
|
+
height: 100%;
|
|
251
|
+
overflow: auto;
|
|
252
|
+
}
|
|
253
|
+
.desk-settings-back {
|
|
254
|
+
align-self: flex-start;
|
|
255
|
+
margin-bottom: var(--desk-space-3);
|
|
256
|
+
}
|
package/src/css/shell.css
CHANGED
|
@@ -97,3 +97,92 @@
|
|
|
97
97
|
clip-path: inset(50%);
|
|
98
98
|
white-space: nowrap;
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
/* ── The overview: tiles floating in a fog, drawn on an overlay over the apps' views ── */
|
|
102
|
+
|
|
103
|
+
.desk-overview {
|
|
104
|
+
position: fixed;
|
|
105
|
+
overflow: hidden;
|
|
106
|
+
perspective: 1600px;
|
|
107
|
+
font-family: var(--desk-font);
|
|
108
|
+
color: var(--desk-ink);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.desk-overview-fog {
|
|
112
|
+
position: absolute;
|
|
113
|
+
inset: 0;
|
|
114
|
+
opacity: 0;
|
|
115
|
+
background: radial-gradient(ellipse at center, var(--desk-overview-fog), var(--desk-overview-fog-far));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* Each tile is the desktop area's full size, moved and scaled by transform alone, so the compositor does it. */
|
|
119
|
+
.desk-overview-tile {
|
|
120
|
+
position: absolute;
|
|
121
|
+
inset: 0;
|
|
122
|
+
padding: 0;
|
|
123
|
+
border: 0;
|
|
124
|
+
border-radius: 14px;
|
|
125
|
+
background: var(--desk-ground);
|
|
126
|
+
color: inherit;
|
|
127
|
+
font: inherit;
|
|
128
|
+
opacity: 0;
|
|
129
|
+
transform-origin: center;
|
|
130
|
+
will-change: transform, opacity;
|
|
131
|
+
cursor: default;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.desk-overview-tile img {
|
|
135
|
+
position: absolute;
|
|
136
|
+
inset: 0;
|
|
137
|
+
width: 100%;
|
|
138
|
+
height: 100%;
|
|
139
|
+
object-fit: cover;
|
|
140
|
+
border-radius: inherit;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
* The shadow is a small blurred picture, sliced in nine and tinted with the shadow token, not a
|
|
145
|
+
* box-shadow on a layer the size of a desktop. It grows in as the tile goes back.
|
|
146
|
+
*/
|
|
147
|
+
.desk-overview-shadow {
|
|
148
|
+
position: absolute;
|
|
149
|
+
inset: -40px;
|
|
150
|
+
background: var(--desk-overview-shadow);
|
|
151
|
+
-webkit-mask-box-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='b' x='-1' y='-1' width='3' height='3'%3E%3CfeGaussianBlur stdDeviation='14'/%3E%3C/filter%3E%3Crect x='40' y='46' width='80' height='80' rx='14' filter='url(%23b)'/%3E%3C/svg%3E") 60 fill / 60px;
|
|
152
|
+
opacity: var(--desk-overview-depth, 0);
|
|
153
|
+
pointer-events: none;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.desk-overview-note {
|
|
157
|
+
position: absolute;
|
|
158
|
+
inset: 0;
|
|
159
|
+
display: grid;
|
|
160
|
+
place-content: center;
|
|
161
|
+
gap: var(--desk-space-2);
|
|
162
|
+
text-align: center;
|
|
163
|
+
border-radius: inherit;
|
|
164
|
+
background: var(--desk-surface);
|
|
165
|
+
color: var(--desk-muted);
|
|
166
|
+
font-size: var(--desk-text-hero);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.desk-overview-note strong {
|
|
170
|
+
color: var(--desk-ink);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* The title under each tile, at a size that reads once the tile is small. */
|
|
174
|
+
.desk-overview-title {
|
|
175
|
+
position: absolute;
|
|
176
|
+
top: calc(100% + 24px);
|
|
177
|
+
left: 0;
|
|
178
|
+
right: 0;
|
|
179
|
+
text-align: center;
|
|
180
|
+
font-size: var(--desk-text-hero);
|
|
181
|
+
font-weight: 600;
|
|
182
|
+
opacity: var(--desk-overview-depth, 0);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.desk-overview-tile:focus-visible {
|
|
186
|
+
outline: 5px solid var(--desk-accent);
|
|
187
|
+
outline-offset: 6px;
|
|
188
|
+
}
|
package/src/css/windows.css
CHANGED
|
@@ -172,6 +172,34 @@
|
|
|
172
172
|
color: var(--desk-muted);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/* The way back from a view one step in, before the title: "‹ Settings", as a phone's navigation bar has it. */
|
|
176
|
+
.desk-window-back {
|
|
177
|
+
flex: none;
|
|
178
|
+
display: inline-flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
gap: 2px;
|
|
181
|
+
margin: 0 var(--desk-space-2) 0 0;
|
|
182
|
+
padding: 2px var(--desk-space-1);
|
|
183
|
+
border: 0;
|
|
184
|
+
border-radius: 6px;
|
|
185
|
+
background: none;
|
|
186
|
+
color: var(--desk-accent);
|
|
187
|
+
font: inherit;
|
|
188
|
+
font-size: var(--desk-text-body);
|
|
189
|
+
cursor: pointer;
|
|
190
|
+
}
|
|
191
|
+
.desk-window-back > span {
|
|
192
|
+
font-size: var(--desk-text-title);
|
|
193
|
+
line-height: 1;
|
|
194
|
+
}
|
|
195
|
+
.desk-window-back:hover {
|
|
196
|
+
background: color-mix(in oklab, var(--desk-accent) 12%, transparent);
|
|
197
|
+
}
|
|
198
|
+
.desk-window-back:focus-visible {
|
|
199
|
+
outline: 2px solid var(--desk-accent);
|
|
200
|
+
outline-offset: 1px;
|
|
201
|
+
}
|
|
202
|
+
|
|
175
203
|
.desk-window-note {
|
|
176
204
|
margin: 0 0 0 auto;
|
|
177
205
|
min-width: 0;
|
package/src/host/checkTheme.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isImageRef } from '../core/theme.js'
|
|
1
|
+
import { isImageRef, isPlainValue, MAX_THEME_TOKENS } from '../core/theme.js'
|
|
2
2
|
import type { DeskTheme, ThemeFont } from '../core/theme.js'
|
|
3
3
|
import type { Look } from '../core/look.js'
|
|
4
4
|
|
|
@@ -16,32 +16,10 @@ export type ThemeCheck = { readonly ok: true; readonly theme: DeskTheme } | { re
|
|
|
16
16
|
|
|
17
17
|
const LOOKS: readonly string[] = ['mac', 'gnome', 'windows']
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
const FUNCTIONS = new Set([
|
|
21
|
-
'rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color', 'color-mix', 'light-dark',
|
|
22
|
-
'var', 'calc', 'min', 'max', 'clamp',
|
|
23
|
-
'linear-gradient', 'radial-gradient', 'conic-gradient', 'repeating-linear-gradient', 'repeating-radial-gradient',
|
|
24
|
-
])
|
|
19
|
+
export { isPlainValue }
|
|
25
20
|
|
|
26
|
-
const MAX_VALUE = 300
|
|
27
|
-
const MAX_TOKENS = 400
|
|
28
21
|
const MAX_FONTS = 16
|
|
29
22
|
|
|
30
|
-
/**
|
|
31
|
-
* Whether a custom property's value is plain: a colour, a length, a number, a font list or a gradient.
|
|
32
|
-
* Only letters, digits, spaces and `#.,%/'"+-()*` may appear, every function is one of `FUNCTIONS`, and
|
|
33
|
-
* nothing may escape, end the declaration or open a block. So `url(…)`, `image-set(…)`, `\75rl(` and
|
|
34
|
-
* `red; background: …` are all refused.
|
|
35
|
-
*/
|
|
36
|
-
export function isPlainValue(value: string): boolean {
|
|
37
|
-
if (value.length > MAX_VALUE) return false
|
|
38
|
-
if (!/^[\w\s#.,%/'"+*()-]*$/.test(value)) return false
|
|
39
|
-
for (const match of value.matchAll(/([\w-]*)\s*\(/g)) {
|
|
40
|
-
if (!FUNCTIONS.has((match[1] ?? '').toLowerCase())) return false
|
|
41
|
-
}
|
|
42
|
-
return true
|
|
43
|
-
}
|
|
44
|
-
|
|
45
23
|
/**
|
|
46
24
|
* Whether `url` is on `origin`: the same scheme and host. Compared by hand rather than by `URL.origin`,
|
|
47
25
|
* which is `'null'` for every scheme a browser does not know (an Electron app's `app://` among them,
|
|
@@ -84,7 +62,7 @@ export function checkTheme(value: unknown, origin: string): ThemeCheck {
|
|
|
84
62
|
if (typeof theme.look !== 'string' || !LOOKS.includes(theme.look)) return fail('look must be mac, gnome or windows')
|
|
85
63
|
if (typeof theme.tokens !== 'object' || theme.tokens === null) return fail('tokens must be an object')
|
|
86
64
|
const entries = Object.entries(theme.tokens as Record<string, unknown>)
|
|
87
|
-
if (entries.length >
|
|
65
|
+
if (entries.length > MAX_THEME_TOKENS) return fail('too many tokens')
|
|
88
66
|
const tokens: Record<string, string> = {}
|
|
89
67
|
for (const [name, token] of entries) {
|
|
90
68
|
if (!/^--[\w-]+$/.test(name)) return fail(`${name} is not a custom property`)
|
package/src/host/router.ts
CHANGED
|
@@ -77,6 +77,7 @@ export interface BroadcastRouter {
|
|
|
77
77
|
/**
|
|
78
78
|
* Adds an app, or updates one. Throws for a second primary: two looks cannot both be worn. An update
|
|
79
79
|
* drops what the app had held over its rate, unsent: it was vetted under the grants and origin it replaces.
|
|
80
|
+
* One that changes `primary` tells the app its new `role`, if it has said `hello`.
|
|
80
81
|
*/
|
|
81
82
|
register(app: HostedApp): void
|
|
82
83
|
/** Forgets an app: its chrome (`chrome` is called with null), its subscriptions, and what it published, except its last theme. */
|
|
@@ -256,6 +257,10 @@ export function createBroadcastRouter(options: BroadcastRouterOptions): Broadcas
|
|
|
256
257
|
}
|
|
257
258
|
}
|
|
258
259
|
|
|
260
|
+
/** Apps that have said hello, told their role again when it changes. */
|
|
261
|
+
const greeted = new Set<string>()
|
|
262
|
+
const tellRole = (app: HostedApp) => options.deliver(app.id, { desk: DESK_PROTOCOL, kind: 'role', primary: Boolean(app.primary) })
|
|
263
|
+
|
|
259
264
|
/** Cancels what an app held over its rate. */
|
|
260
265
|
const dropHeld = (appId: string) => {
|
|
261
266
|
for (const bucket of buckets.get(appId)?.values() ?? []) bucket.held?.cancel(), delete bucket.held
|
|
@@ -265,7 +270,9 @@ export function createBroadcastRouter(options: BroadcastRouterOptions): Broadcas
|
|
|
265
270
|
register(app) {
|
|
266
271
|
if (app.primary && primaryId() !== null && primaryId() !== app.id) throw new Error(`${primaryId()} is already the primary`)
|
|
267
272
|
dropHeld(app.id)
|
|
273
|
+
const was = apps.get(app.id)
|
|
268
274
|
apps.set(app.id, app)
|
|
275
|
+
if (was && Boolean(was.primary) !== Boolean(app.primary) && greeted.has(app.id)) tellRole(app)
|
|
269
276
|
if (app.primary) lastPrimary = app.id
|
|
270
277
|
else if (lastPrimary === app.id) lastPrimary = null
|
|
271
278
|
// A primary registered again after it went: what it kept still carries its role.
|
|
@@ -274,6 +281,7 @@ export function createBroadcastRouter(options: BroadcastRouterOptions): Broadcas
|
|
|
274
281
|
},
|
|
275
282
|
|
|
276
283
|
unregister(appId) {
|
|
284
|
+
greeted.delete(appId)
|
|
277
285
|
if (apps.delete(appId)) options.chrome?.(appId, null, [])
|
|
278
286
|
// What it had held goes with it, unsent.
|
|
279
287
|
dropHeld(appId)
|
|
@@ -309,6 +317,10 @@ export function createBroadcastRouter(options: BroadcastRouterOptions): Broadcas
|
|
|
309
317
|
case 'unsubscribe':
|
|
310
318
|
subscriptions.get(appId)?.delete(`${message.publisher}\u0000${message.topic}`)
|
|
311
319
|
return null
|
|
320
|
+
case 'hello':
|
|
321
|
+
greeted.add(appId)
|
|
322
|
+
tellRole(app)
|
|
323
|
+
return null
|
|
312
324
|
}
|
|
313
325
|
},
|
|
314
326
|
|