@liberation-data/desk 0.43.0 → 0.45.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 +238 -10
- 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 +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/core/types.d.ts +5 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/css/apps.css +52 -1
- package/dist/css/shell.css +100 -0
- package/dist/css/tokens.css +10 -0
- package/dist/css/windows.css +28 -0
- package/dist/desk.css +90 -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/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +11 -14
- package/dist/react/Desktop.js.map +1 -1
- 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 +65 -12
- package/dist/react/app.d.ts.map +1 -1
- package/dist/react/app.js +79 -21
- 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 +76 -28
- 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 +25 -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 +10 -5
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +6 -3
- 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 +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/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/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 +57 -20
- package/package.json +10 -1
- package/src/core/desk.ts +11 -2
- 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/core/types.ts +5 -0
- package/src/css/apps.css +52 -1
- package/src/css/shell.css +99 -0
- package/src/css/tokens.css +10 -0
- package/src/css/windows.css +28 -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/Desktop.tsx +16 -21
- package/src/react/Dock.tsx +34 -28
- package/src/react/MenuBar.tsx +22 -4
- package/src/react/app.tsx +116 -22
- package/src/react/appFrame.tsx +39 -14
- package/src/react/appPanels.tsx +102 -31
- package/src/react/appearance.tsx +36 -45
- package/src/react/context.tsx +99 -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 +12 -4
- package/src/react/mediaQuery.ts +18 -0
- package/src/react/shell.tsx +30 -3
- package/src/react/sidebar.tsx +10 -3
- package/src/react/windowDescription.ts +12 -1
- 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
package/src/core/location.ts
CHANGED
|
@@ -40,18 +40,35 @@ const decodeRoute = (route: string) => {
|
|
|
40
40
|
|
|
41
41
|
const warned = new Set<string>()
|
|
42
42
|
/** Said once per message: a warning on every parse would be noise, not help. */
|
|
43
|
-
const warnOnce = (message: string) => {
|
|
43
|
+
export const warnOnce = (message: string) => {
|
|
44
44
|
if (warned.has(message)) return
|
|
45
45
|
warned.add(message)
|
|
46
46
|
console.warn(message)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/*
|
|
50
|
+
* Windows a desk draws for itself, such as Settings and About for an app that declared itself. The React
|
|
51
|
+
* provider says which; the core reads only the answer, so it needs no React and no app declaration.
|
|
52
|
+
*/
|
|
53
|
+
const deskWindows = new WeakMap<Desk, (id: WindowId) => boolean>()
|
|
54
|
+
|
|
55
|
+
/** Says which windows this desk draws itself, so a link to them is kept. Returns a function that forgets it. */
|
|
56
|
+
export function deskDrawsWindows(desk: Desk, draws: (id: WindowId) => boolean): () => void {
|
|
57
|
+
deskWindows.set(desk, draws)
|
|
58
|
+
return () => {
|
|
59
|
+
if (deskWindows.get(desk) === draws) deskWindows.delete(desk)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
export interface LocationOptions {
|
|
50
64
|
/** Hash parameter that holds the windows. Default `w`. */
|
|
51
65
|
readonly key?: string
|
|
52
66
|
/** Hash parameter that holds the focused window. Default `f`. */
|
|
53
67
|
readonly focusKey?: string
|
|
54
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Ids the app can render. Anything else in a URL is dropped. With `syncWithLocation`, the windows the desk
|
|
70
|
+
* draws itself (Settings and About, for an app declared on its provider) are known too, unlisted.
|
|
71
|
+
*/
|
|
55
72
|
readonly isKnown?: (id: WindowId) => boolean
|
|
56
73
|
}
|
|
57
74
|
|
|
@@ -131,7 +148,10 @@ export function syncWithLocation(desk: Desk, stage: () => Size, options: Locatio
|
|
|
131
148
|
const keys = [options.key ?? 'w', options.focusKey ?? 'f']
|
|
132
149
|
const read = () => new URLSearchParams(target.location.hash.replace(/^#/, ''))
|
|
133
150
|
|
|
134
|
-
|
|
151
|
+
// The desk's own windows are known as well as the app's, asked at each read, so a declaration made later counts.
|
|
152
|
+
const given = options.isKnown
|
|
153
|
+
const reading: LocationOptions = given ? { ...options, isKnown: id => (deskWindows.get(desk)?.(id) ?? false) || given(id) } : options
|
|
154
|
+
const fromUrl = () => desk.restore(parse(read(), stage(), reading))
|
|
135
155
|
|
|
136
156
|
const toUrl = (state: DeskState, previous: DeskState) => {
|
|
137
157
|
const params = read()
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Where Desk keeps what a person chooses: the colour scheme, the look, the sounds. This browser's
|
|
3
|
+
* localStorage unless the app gives a store of its own, such as one kept with the person's account.
|
|
4
|
+
*
|
|
5
|
+
* The head script (`colorSchemeScript`) runs before any app code, so it can only read localStorage. With
|
|
6
|
+
* an app's store, Desk writes each value it reads or is told of through to localStorage under the same
|
|
7
|
+
* key: the app's store is the truth, and localStorage a copy for the first paint.
|
|
8
|
+
*/
|
|
9
|
+
import { COLOR_SCHEME_KEY, LOOK_KEY } from './scheme.js'
|
|
10
|
+
|
|
11
|
+
export interface PreferenceStore {
|
|
12
|
+
/**
|
|
13
|
+
* The value kept under the key, or null when there is none. `undefined` while the store does not know yet,
|
|
14
|
+
* as a remote store before its values arrive: Desk uses this browser's copy meanwhile.
|
|
15
|
+
*/
|
|
16
|
+
get(key: string): string | null | undefined
|
|
17
|
+
/** Keeps a value, or forgets it for null. */
|
|
18
|
+
set(key: string, value: string | null): void
|
|
19
|
+
/** Calls back when values change other than through `set`: arrived from a server, or set in another tab. Null: any key. */
|
|
20
|
+
subscribe?(listener: (key: string | null) => void): () => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* What storage refused, as a private window or a full one does: it applies until the page is closed. */
|
|
24
|
+
const unstored = new Map<string, string | null>()
|
|
25
|
+
|
|
26
|
+
const storage = () => globalThis.localStorage
|
|
27
|
+
|
|
28
|
+
function readLocal(key: string): string | null {
|
|
29
|
+
let kept: string | null | undefined
|
|
30
|
+
try {
|
|
31
|
+
kept = storage()?.getItem(key)
|
|
32
|
+
} catch {
|
|
33
|
+
// Unreadable: what was kept in memory, if anything.
|
|
34
|
+
}
|
|
35
|
+
return kept ?? unstored.get(key) ?? null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function writeLocal(key: string, value: string | null): void {
|
|
39
|
+
try {
|
|
40
|
+
if (value === null) storage()?.removeItem(key)
|
|
41
|
+
else storage()?.setItem(key, value)
|
|
42
|
+
unstored.delete(key)
|
|
43
|
+
} catch {
|
|
44
|
+
// What storage still holds is the old choice, read before this one, so it goes.
|
|
45
|
+
unstored.set(key, value)
|
|
46
|
+
try {
|
|
47
|
+
storage()?.removeItem(key)
|
|
48
|
+
} catch {
|
|
49
|
+
// Unreadable too: then it is never read.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The default: this browser's localStorage, following changes made in its other tabs. */
|
|
55
|
+
export const localPreferences: PreferenceStore = {
|
|
56
|
+
get: readLocal,
|
|
57
|
+
set: writeLocal,
|
|
58
|
+
subscribe(listener) {
|
|
59
|
+
if (typeof window === 'undefined') return () => {}
|
|
60
|
+
const fromAnotherTab = (event: StorageEvent) => listener(event.key)
|
|
61
|
+
window.addEventListener('storage', fromAnotherTab)
|
|
62
|
+
return () => window.removeEventListener('storage', fromAnotherTab)
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let store = localPreferences
|
|
67
|
+
const listeners = new Set<(key: string | null) => void>()
|
|
68
|
+
let unsubscribe: (() => void) | undefined
|
|
69
|
+
/* Every key Desk has asked for, so a change to "any key" brings all their copies up to date, the sounds' too. */
|
|
70
|
+
const keys = new Set([COLOR_SCHEME_KEY, LOOK_KEY])
|
|
71
|
+
|
|
72
|
+
/** A store's value, or undefined when it does not know yet or fails. */
|
|
73
|
+
function fromStore(key: string): string | null | undefined {
|
|
74
|
+
try {
|
|
75
|
+
return store.get(key)
|
|
76
|
+
} catch {
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* Brings this browser's copy up to the app's store, for the head script's next first paint. */
|
|
82
|
+
function copy(key: string): void {
|
|
83
|
+
const value = fromStore(key)
|
|
84
|
+
if (store !== localPreferences && value !== undefined && value !== readLocal(key)) writeLocal(key, value)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Tells everything that shows a choice that it may have changed. Null: any of them. */
|
|
88
|
+
export function preferenceChanged(key: string | null): void {
|
|
89
|
+
;(key === null ? [...keys] : [key]).forEach(copy)
|
|
90
|
+
listeners.forEach(listener => listener(key))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A remembered choice: the store's, or this browser's copy while the store does not know yet. */
|
|
94
|
+
export function getPreference(key: string): string | null {
|
|
95
|
+
keys.add(key)
|
|
96
|
+
const value = fromStore(key)
|
|
97
|
+
return value === undefined ? readLocal(key) : value
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Remembers a choice in the store, and in this browser's copy, and tells everything that shows it. */
|
|
101
|
+
export function setPreference(key: string, value: string | null): void {
|
|
102
|
+
try {
|
|
103
|
+
store.set(key, value)
|
|
104
|
+
} catch {
|
|
105
|
+
// The store refused: this browser's copy still has it.
|
|
106
|
+
}
|
|
107
|
+
if (store !== localPreferences) writeLocal(key, value)
|
|
108
|
+
preferenceChanged(key)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Called with the key when a remembered choice changes, here, in the store, or in another tab. */
|
|
112
|
+
export function subscribePreferences(listener: (key: string | null) => void): () => void {
|
|
113
|
+
if (!listeners.size) unsubscribe = store.subscribe?.(preferenceChanged)
|
|
114
|
+
listeners.add(listener)
|
|
115
|
+
return () => {
|
|
116
|
+
listeners.delete(listener)
|
|
117
|
+
if (listeners.size) return
|
|
118
|
+
unsubscribe?.()
|
|
119
|
+
unsubscribe = undefined
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Keeps every choice Desk remembers in this store from now on; none puts localStorage back. `DeskShell`'s
|
|
125
|
+
* `preferences` calls it. Its keys: `COLOR_SCHEME_KEY`, `LOOK_KEY` and `createFx`'s `storageKey`.
|
|
126
|
+
*/
|
|
127
|
+
export function setPreferenceStore(next: PreferenceStore = localPreferences): void {
|
|
128
|
+
unsubscribe?.()
|
|
129
|
+
store = next
|
|
130
|
+
unsubscribe = listeners.size ? next.subscribe?.(preferenceChanged) : undefined
|
|
131
|
+
preferenceChanged(null)
|
|
132
|
+
}
|
package/src/core/scheme.ts
CHANGED
|
@@ -7,15 +7,26 @@
|
|
|
7
7
|
/** Light, dark, or the system's, which the stylesheet follows through `prefers-color-scheme`. */
|
|
8
8
|
export type ColorScheme = 'system' | 'light' | 'dark'
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Where the chosen colour scheme is kept in localStorage: `light`, `dark` or `system`. Absent while the app's
|
|
12
|
+
* own default stands (`appearance.defaultScheme`, the system's unless it says otherwise).
|
|
13
|
+
*/
|
|
11
14
|
export const COLOR_SCHEME_KEY = 'desk.scheme'
|
|
12
15
|
|
|
13
16
|
/** Where the chosen look is kept in localStorage: `auto`, `mac`, `gnome` or `windows`; absent while the app's own stands. */
|
|
14
17
|
export const LOOK_KEY = 'desk.look'
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
|
-
* For the page's `<head>`, before anything paints: the remembered scheme on the root as `data-theme`,
|
|
18
|
-
* choice does not open light for a moment while the app
|
|
20
|
+
* For the page's `<head>`, before anything paints: the remembered scheme on the root as `data-theme`, or the
|
|
21
|
+
* app's default when none is remembered, so a dark choice does not open light for a moment while the app
|
|
22
|
+
* loads. Give it the same `defaultScheme` as Appearance.
|
|
19
23
|
*/
|
|
20
|
-
export
|
|
21
|
-
|
|
24
|
+
export function colorSchemeScript(defaultScheme: ColorScheme = 'system'): string {
|
|
25
|
+
return (
|
|
26
|
+
`try{var s=localStorage.getItem(${JSON.stringify(COLOR_SCHEME_KEY)});if(s!="light"&&s!="dark"&&s!="system")s=${JSON.stringify(defaultScheme)};` +
|
|
27
|
+
`var r=document.documentElement;if(s=="light"||s=="dark")r.setAttribute("data-theme",s);else r.removeAttribute("data-theme")}catch(e){}`
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The head script for an app whose default is the system's scheme: `colorSchemeScript()`. */
|
|
32
|
+
export const COLOR_SCHEME_SCRIPT = colorSchemeScript()
|
|
@@ -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/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
|
@@ -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.
|
|
@@ -203,3 +237,20 @@
|
|
|
203
237
|
flex-direction: column;
|
|
204
238
|
gap: var(--desk-space-5);
|
|
205
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
|
+
}
|
|
@@ -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/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/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,
|