@liberation-data/desk 0.42.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.
Files changed (200) hide show
  1. package/README.md +312 -5
  2. package/dist/core/hosted.d.ts +222 -0
  3. package/dist/core/hosted.d.ts.map +1 -0
  4. package/dist/core/hosted.js +166 -0
  5. package/dist/core/hosted.js.map +1 -0
  6. package/dist/core/index.d.ts +10 -0
  7. package/dist/core/index.d.ts.map +1 -1
  8. package/dist/core/index.js +5 -0
  9. package/dist/core/index.js.map +1 -1
  10. package/dist/core/location.d.ts +8 -1
  11. package/dist/core/location.d.ts.map +1 -1
  12. package/dist/core/location.js +18 -2
  13. package/dist/core/location.js.map +1 -1
  14. package/dist/core/preferences.d.ts +27 -0
  15. package/dist/core/preferences.d.ts.map +1 -0
  16. package/dist/core/preferences.js +121 -0
  17. package/dist/core/preferences.js.map +1 -0
  18. package/dist/core/scheme.d.ts +18 -0
  19. package/dist/core/scheme.d.ts.map +1 -0
  20. package/dist/core/scheme.js +24 -0
  21. package/dist/core/scheme.js.map +1 -0
  22. package/dist/core/theme.d.ts +41 -0
  23. package/dist/core/theme.d.ts.map +1 -0
  24. package/dist/core/theme.js +56 -0
  25. package/dist/core/theme.js.map +1 -0
  26. package/dist/core/themeChange.d.ts +25 -0
  27. package/dist/core/themeChange.d.ts.map +1 -0
  28. package/dist/core/themeChange.js +49 -0
  29. package/dist/core/themeChange.js.map +1 -0
  30. package/dist/core/types.d.ts +6 -0
  31. package/dist/core/types.d.ts.map +1 -1
  32. package/dist/css/apps.css +183 -0
  33. package/dist/css/overlays.css +6 -0
  34. package/dist/css/shell.css +100 -0
  35. package/dist/css/tokens.css +10 -0
  36. package/dist/css/windows.css +21 -0
  37. package/dist/desk.css +220 -0
  38. package/dist/fx/fx.d.ts.map +1 -1
  39. package/dist/fx/fx.js +7 -31
  40. package/dist/fx/fx.js.map +1 -1
  41. package/dist/host/checkChrome.d.ts +20 -0
  42. package/dist/host/checkChrome.d.ts.map +1 -0
  43. package/dist/host/checkChrome.js +219 -0
  44. package/dist/host/checkChrome.js.map +1 -0
  45. package/dist/host/checkTheme.d.ts +35 -0
  46. package/dist/host/checkTheme.d.ts.map +1 -0
  47. package/dist/host/checkTheme.js +128 -0
  48. package/dist/host/checkTheme.js.map +1 -0
  49. package/dist/host/index.d.ts +7 -0
  50. package/dist/host/index.d.ts.map +1 -0
  51. package/dist/host/index.js +8 -0
  52. package/dist/host/index.js.map +1 -0
  53. package/dist/host/router.d.ts +99 -0
  54. package/dist/host/router.d.ts.map +1 -0
  55. package/dist/host/router.js +279 -0
  56. package/dist/host/router.js.map +1 -0
  57. package/dist/react/Desktop.d.ts.map +1 -1
  58. package/dist/react/Desktop.js +13 -2
  59. package/dist/react/Desktop.js.map +1 -1
  60. package/dist/react/Dock.d.ts +26 -2
  61. package/dist/react/Dock.d.ts.map +1 -1
  62. package/dist/react/Dock.js +23 -27
  63. package/dist/react/Dock.js.map +1 -1
  64. package/dist/react/MenuBar.d.ts +1 -1
  65. package/dist/react/MenuBar.d.ts.map +1 -1
  66. package/dist/react/MenuBar.js +36 -6
  67. package/dist/react/MenuBar.js.map +1 -1
  68. package/dist/react/app.d.ts +215 -0
  69. package/dist/react/app.d.ts.map +1 -0
  70. package/dist/react/app.js +192 -0
  71. package/dist/react/app.js.map +1 -0
  72. package/dist/react/appFrame.d.ts +11 -7
  73. package/dist/react/appFrame.d.ts.map +1 -1
  74. package/dist/react/appFrame.js +24 -6
  75. package/dist/react/appFrame.js.map +1 -1
  76. package/dist/react/appPanels.d.ts +25 -0
  77. package/dist/react/appPanels.d.ts.map +1 -0
  78. package/dist/react/appPanels.js +123 -0
  79. package/dist/react/appPanels.js.map +1 -0
  80. package/dist/react/appearance.d.ts +61 -0
  81. package/dist/react/appearance.d.ts.map +1 -0
  82. package/dist/react/appearance.js +119 -0
  83. package/dist/react/appearance.js.map +1 -0
  84. package/dist/react/codeBlock.d.ts.map +1 -1
  85. package/dist/react/codeBlock.js +6 -60
  86. package/dist/react/codeBlock.js.map +1 -1
  87. package/dist/react/context.d.ts +23 -1
  88. package/dist/react/context.d.ts.map +1 -1
  89. package/dist/react/context.js +108 -5
  90. package/dist/react/context.js.map +1 -1
  91. package/dist/react/copy.d.ts +22 -0
  92. package/dist/react/copy.d.ts.map +1 -0
  93. package/dist/react/copy.js +68 -0
  94. package/dist/react/copy.js.map +1 -0
  95. package/dist/react/dockStatus.d.ts +19 -0
  96. package/dist/react/dockStatus.d.ts.map +1 -0
  97. package/dist/react/dockStatus.js +25 -0
  98. package/dist/react/dockStatus.js.map +1 -0
  99. package/dist/react/documentTitle.d.ts.map +1 -1
  100. package/dist/react/documentTitle.js +4 -1
  101. package/dist/react/documentTitle.js.map +1 -1
  102. package/dist/react/frameMenus.d.ts +28 -0
  103. package/dist/react/frameMenus.d.ts.map +1 -0
  104. package/dist/react/frameMenus.js +85 -0
  105. package/dist/react/frameMenus.js.map +1 -0
  106. package/dist/react/hostApp.d.ts +15 -0
  107. package/dist/react/hostApp.d.ts.map +1 -0
  108. package/dist/react/hostApp.js +77 -0
  109. package/dist/react/hostApp.js.map +1 -0
  110. package/dist/react/hostDock.d.ts +25 -0
  111. package/dist/react/hostDock.d.ts.map +1 -0
  112. package/dist/react/hostDock.js +98 -0
  113. package/dist/react/hostDock.js.map +1 -0
  114. package/dist/react/hostMenu.d.ts +2 -36
  115. package/dist/react/hostMenu.d.ts.map +1 -1
  116. package/dist/react/hostMenu.js.map +1 -1
  117. package/dist/react/hosted.d.ts +28 -0
  118. package/dist/react/hosted.d.ts.map +1 -0
  119. package/dist/react/hosted.js +53 -0
  120. package/dist/react/hosted.js.map +1 -0
  121. package/dist/react/index.d.ts +12 -0
  122. package/dist/react/index.d.ts.map +1 -1
  123. package/dist/react/index.js +8 -0
  124. package/dist/react/index.js.map +1 -1
  125. package/dist/react/layers.d.ts.map +1 -1
  126. package/dist/react/layers.js +7 -2
  127. package/dist/react/layers.js.map +1 -1
  128. package/dist/react/overlays.d.ts.map +1 -1
  129. package/dist/react/overlays.js +29 -12
  130. package/dist/react/overlays.js.map +1 -1
  131. package/dist/react/shell.d.ts +16 -1
  132. package/dist/react/shell.d.ts.map +1 -1
  133. package/dist/react/shell.js +19 -3
  134. package/dist/react/shell.js.map +1 -1
  135. package/dist/react/windowMenus.d.ts +19 -0
  136. package/dist/react/windowMenus.d.ts.map +1 -0
  137. package/dist/react/windowMenus.js +88 -0
  138. package/dist/react/windowMenus.js.map +1 -0
  139. package/dist/shell/HostShell.d.ts +53 -0
  140. package/dist/shell/HostShell.d.ts.map +1 -0
  141. package/dist/shell/HostShell.js +116 -0
  142. package/dist/shell/HostShell.js.map +1 -0
  143. package/dist/shell/index.d.ts +7 -0
  144. package/dist/shell/index.d.ts.map +1 -0
  145. package/dist/shell/index.js +9 -0
  146. package/dist/shell/index.js.map +1 -0
  147. package/dist/shell/keys.d.ts +47 -0
  148. package/dist/shell/keys.d.ts.map +1 -0
  149. package/dist/shell/keys.js +68 -0
  150. package/dist/shell/keys.js.map +1 -0
  151. package/dist/shell/motion.d.ts +72 -0
  152. package/dist/shell/motion.d.ts.map +1 -0
  153. package/dist/shell/motion.js +118 -0
  154. package/dist/shell/motion.js.map +1 -0
  155. package/llms.txt +84 -9
  156. package/package.json +10 -1
  157. package/src/core/hosted.ts +351 -0
  158. package/src/core/index.ts +29 -0
  159. package/src/core/location.ts +23 -3
  160. package/src/core/preferences.ts +132 -0
  161. package/src/core/scheme.ts +32 -0
  162. package/src/core/theme.ts +91 -0
  163. package/src/core/themeChange.ts +59 -0
  164. package/src/core/types.ts +6 -0
  165. package/src/css/apps.css +183 -0
  166. package/src/css/overlays.css +6 -0
  167. package/src/css/shell.css +99 -0
  168. package/src/css/tokens.css +10 -0
  169. package/src/css/windows.css +21 -0
  170. package/src/fx/fx.ts +7 -25
  171. package/src/host/checkChrome.ts +257 -0
  172. package/src/host/checkTheme.ts +134 -0
  173. package/src/host/index.ts +10 -0
  174. package/src/host/router.ts +374 -0
  175. package/src/react/Desktop.tsx +21 -3
  176. package/src/react/Dock.tsx +40 -24
  177. package/src/react/MenuBar.tsx +39 -6
  178. package/src/react/app.tsx +354 -0
  179. package/src/react/appFrame.tsx +39 -14
  180. package/src/react/appPanels.tsx +210 -0
  181. package/src/react/appearance.tsx +195 -0
  182. package/src/react/codeBlock.tsx +7 -65
  183. package/src/react/context.tsx +131 -4
  184. package/src/react/copy.ts +81 -0
  185. package/src/react/dockStatus.ts +42 -0
  186. package/src/react/documentTitle.ts +4 -1
  187. package/src/react/frameMenus.ts +100 -0
  188. package/src/react/hostApp.tsx +89 -0
  189. package/src/react/hostDock.tsx +118 -0
  190. package/src/react/hostMenu.ts +3 -38
  191. package/src/react/hosted.tsx +65 -0
  192. package/src/react/index.ts +34 -0
  193. package/src/react/layers.ts +7 -2
  194. package/src/react/overlays.tsx +30 -12
  195. package/src/react/shell.tsx +33 -3
  196. package/src/react/windowMenus.ts +107 -0
  197. package/src/shell/HostShell.tsx +220 -0
  198. package/src/shell/index.ts +11 -0
  199. package/src/shell/keys.ts +101 -0
  200. package/src/shell/motion.ts +163 -0
@@ -1,13 +1,29 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useState } from 'react';
2
+ import { useLayoutEffect, useState } from 'react';
3
3
  import { createDesk } from '../core/desk.js';
4
+ import { setPreferenceStore } from '../core/preferences.js';
4
5
  import { DeskProvider } from './context.js';
5
6
  import { BusProvider } from './events.js';
6
7
  import { ToastProvider } from './overlays.js';
8
+ /* The stores mounted shells were given, the latest last: it is the one in use, until its shell goes. */
9
+ const givenStores = [];
7
10
  /** Everything an app needs around it, in one component: the desk, its bus, and toasts. */
8
- export function DeskShell({ desk, options, bus, toasts = true, look = 'auto', services = [], children }) {
11
+ export function DeskShell({ desk, options, bus, toasts = true, look = 'auto', services = [], app, host, onTheme, preferences, children }) {
9
12
  const [made] = useState(() => desk ?? createDesk(options));
13
+ useLayoutEffect(() => {
14
+ if (!preferences)
15
+ return;
16
+ givenStores.push(preferences);
17
+ setPreferenceStore(preferences);
18
+ return () => {
19
+ const inUse = givenStores.at(-1);
20
+ givenStores.splice(givenStores.lastIndexOf(preferences), 1);
21
+ if (givenStores.at(-1) !== inUse)
22
+ setPreferenceStore(givenStores.at(-1));
23
+ };
24
+ }, [preferences]);
10
25
  const inner = toasts ? _jsx(ToastProvider, { children: children }) : children;
11
- return _jsx(DeskProvider, { desk: made, look: look, services: services, children: bus ? _jsx(BusProvider, { bus: bus, children: inner }) : inner });
26
+ const given = { ...(app ? { app } : {}), ...(host === undefined ? {} : { host }), ...(onTheme === undefined ? {} : { onTheme }) };
27
+ return _jsx(DeskProvider, { desk: made, look: look, services: services, ...given, children: bus ? _jsx(BusProvider, { bus: bus, children: inner }) : inner });
12
28
  }
13
29
  //# sourceMappingURL=shell.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/react/shell.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAM5C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAiB7C,0FAA0F;AAC1F,MAAM,UAAU,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,QAAQ,EAAkB;IACrH,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;IAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,KAAC,aAAa,cAAE,QAAQ,GAAiB,CAAC,CA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AK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YAChC,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;YAC3D,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK;gBAAE,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1E,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IACjB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,KAAC,aAAa,cAAE,QAAQ,GAAiB,CAAC,CAAC,CAAC,QAAQ,CAAA;IAC3E,MAAM,KAAK,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAA;IACjI,OAAO,KAAC,YAAY,IAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,KAAM,KAAK,YAAG,GAAG,CAAC,CAAC,CAAC,KAAC,WAAW,IAAC,GAAG,EAAE,GAAG,YAAG,KAAK,GAAe,CAAC,CAAC,CAAC,KAAK,GAAgB,CAAA;AACzJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Desk } from '../core/desk.js';
2
+ import type { WindowId } from '../core/types.js';
3
+ import type { Menu } from './MenuBar.js';
4
+ /** Adds `menus` to the bar while `window` is in front, each id prefixed with the window's. Returns a remover. */
5
+ export declare function addWindowMenus(desk: Desk, window: WindowId, menus: readonly Menu[]): () => void;
6
+ /**
7
+ * Menus this window adds to the bar while it has focus. Call it inside a window's content (outside one it
8
+ * does nothing), with a stable array (`useMemo`).
9
+ */
10
+ export declare function useWindowMenus(menus: readonly Menu[]): void;
11
+ /** The menus the window in front has added; none when nothing has focus. */
12
+ export declare function useFrontMenus(desk: Desk): readonly Menu[];
13
+ /**
14
+ * The app's menus with the front window's joined in, before the ones with ids `window` and `help` (or at
15
+ * the end). A front item asking for a shortcut the app's menus, its `status` menus or Desk use loses it.
16
+ * Function items stay so.
17
+ */
18
+ export declare function joinFrontMenus(own: readonly Menu[], front: readonly Menu[], status?: readonly Menu[]): readonly Menu[];
19
+ //# sourceMappingURL=windowMenus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowMenus.d.ts","sourceRoot":"","sources":["../../src/react/windowMenus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAKhD,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,cAAc,CAAA;AA0BlD,iHAAiH;AACjH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,IAAI,CAQ/F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,IAAI,CAI3D;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,IAAI,EAAE,CAazD;AAeD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,MAAM,GAAE,SAAS,IAAI,EAAO,GAAG,SAAS,IAAI,EAAE,CAiB1H"}
@@ -0,0 +1,88 @@
1
+ import { useEffect, useMemo, useSyncExternalStore } from 'react';
2
+ import { focusedId } from '../core/desk.js';
3
+ import { parseShortcut, isApplePlatform } from '../core/shortcuts.js';
4
+ import { warnOnce } from '../core/location.js';
5
+ import { DESK_SHORTCUTS } from './app.js';
6
+ import { useOptionalDesk, useWindowId } from './context.js';
7
+ const registries = new WeakMap();
8
+ const registryOf = (desk) => {
9
+ let registry = registries.get(desk);
10
+ if (!registry)
11
+ registries.set(desk, (registry = { sources: new Set(), listeners: new Set(), version: 0 }));
12
+ return registry;
13
+ };
14
+ const changed = (registry) => {
15
+ registry.version++;
16
+ registry.listeners.forEach(listener => listener());
17
+ };
18
+ /** Adds `menus` to the bar while `window` is in front, each id prefixed with the window's. Returns a remover. */
19
+ export function addWindowMenus(desk, window, menus) {
20
+ const registry = registryOf(desk);
21
+ const source = { window, menus: menus.map(menu => ({ ...menu, id: `${window}/${menu.id}` })) };
22
+ registry.sources.add(source);
23
+ changed(registry);
24
+ return () => {
25
+ if (registry.sources.delete(source))
26
+ changed(registry);
27
+ };
28
+ }
29
+ /**
30
+ * Menus this window adds to the bar while it has focus. Call it inside a window's content (outside one it
31
+ * does nothing), with a stable array (`useMemo`).
32
+ */
33
+ export function useWindowMenus(menus) {
34
+ const desk = useOptionalDesk();
35
+ const window = useWindowId();
36
+ useEffect(() => (desk && window !== null && menus.length ? addWindowMenus(desk, window, menus) : undefined), [desk, window, menus]);
37
+ }
38
+ /** The menus the window in front has added; none when nothing has focus. */
39
+ export function useFrontMenus(desk) {
40
+ const registry = registryOf(desk);
41
+ const subscribe = (listener) => {
42
+ registry.listeners.add(listener);
43
+ const stop = desk.subscribe(listener);
44
+ return () => {
45
+ registry.listeners.delete(listener);
46
+ stop();
47
+ };
48
+ };
49
+ const front = focusedId(useSyncExternalStore(desk.subscribe, desk.getState));
50
+ const version = useSyncExternalStore(subscribe, () => registry.version);
51
+ return useMemo(() => [...registry.sources].filter(s => s.window === front).flatMap(s => s.menus), [registry, front, version]);
52
+ }
53
+ /** The keys a shortcut stands for, as `matchesShortcut` reads it here: `MOD+E`, and `ctrl+e` off a Mac, are `mod+e`. */
54
+ const keysOf = (shortcut) => {
55
+ const s = parseShortcut(shortcut);
56
+ const apple = isApplePlatform();
57
+ return [s.key, s.shift, s.alt, apple && s.mod, s.ctrl || (!apple && s.mod)].join('|');
58
+ };
59
+ const shortcutsOf = (menus) => new Set([
60
+ ...Object.keys(DESK_SHORTCUTS),
61
+ ...menus.flatMap(m => (typeof m.items === 'function' ? m.items() : m.items)).flatMap(i => ('shortcut' in i && i.shortcut ? [i.shortcut] : [])),
62
+ ].map(keysOf));
63
+ /**
64
+ * The app's menus with the front window's joined in, before the ones with ids `window` and `help` (or at
65
+ * the end). A front item asking for a shortcut the app's menus, its `status` menus or Desk use loses it.
66
+ * Function items stay so.
67
+ */
68
+ export function joinFrontMenus(own, front, status = []) {
69
+ if (front.length === 0)
70
+ return own;
71
+ const yielding = (menu, items) => {
72
+ const taken = shortcutsOf([...own, ...status]);
73
+ return items.map(item => {
74
+ if (!('shortcut' in item) || !item.shortcut || !taken.has(keysOf(item.shortcut)))
75
+ return item;
76
+ warnOnce(`desk: "${item.label}" in the ${menu.label} menu asks for ${item.shortcut}, which the app uses. The app's keeps it.`);
77
+ const { shortcut: _taken, ...rest } = item;
78
+ return rest;
79
+ });
80
+ };
81
+ const joined = front.map(menu => {
82
+ const { items } = menu;
83
+ return { ...menu, items: typeof items === 'function' ? () => yielding(menu, items()) : yielding(menu, items) };
84
+ });
85
+ const at = own.findIndex(menu => menu.id === 'window' || menu.id === 'help');
86
+ return at < 0 ? [...own, ...joined] : [...own.slice(0, at), ...joined, ...own.slice(at)];
87
+ }
88
+ //# sourceMappingURL=windowMenus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowMenus.js","sourceRoot":"","sources":["../../src/react/windowMenus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM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E,KAAK,CAAC,EAAE,CAAA;IAChH,CAAC,CAAC,CAAA;IACF,MAAM,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,CAAA;IAC5E,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;AAC1F,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { CommandTarget, DeskChrome, HostDockEntry } from '../core/hosted.js';
2
+ import type { DeskTheme } from '../core/theme.js';
3
+ import type { DockEntry, DockSide } from '../react/Dock.js';
4
+ import type { SwitchKeys } from './keys.js';
5
+ /** One app the host runs, as the switcher shows it. */
6
+ export interface ShellWorkspace {
7
+ readonly id: string;
8
+ readonly title: string;
9
+ /** A CSS colour: the switcher entry's mark. */
10
+ readonly accent?: string;
11
+ /** An image URL or `data:` URI. */
12
+ readonly icon?: string;
13
+ /** The app whose theme every workspace wears. */
14
+ readonly primary?: boolean;
15
+ /** Running and drawn; asleep, with a snapshot; or closed, with a snapshot, until it is visited again. */
16
+ readonly state: 'live' | 'suspended' | 'discarded';
17
+ }
18
+ /** How the host should show a switch: the desktops slide, or (from the overview) zoom. */
19
+ export type SwitchHow = 'slide' | 'zoom';
20
+ /** The room the chrome takes on each side of the window, in CSS pixels: the apps go inside it. */
21
+ export interface ShellInsets {
22
+ readonly top: number;
23
+ readonly right: number;
24
+ readonly bottom: number;
25
+ readonly left: number;
26
+ }
27
+ export interface HostShellProps {
28
+ /** In the switcher's order: the primary first, then as the host registered them. */
29
+ readonly workspaces: readonly ShellWorkspace[];
30
+ /** The workspace on screen. Changes when the host has finished moving to another. */
31
+ readonly current: string;
32
+ /** What each app last sent of its chrome, by workspace id; missing or null until it has. */
33
+ readonly chrome: Readonly<Record<string, DeskChrome | null | undefined>>;
34
+ /** The primary's theme, applied to this page. */
35
+ readonly theme?: DeskTheme | null;
36
+ /** A picture of each workspace that isn't live, for the overview. */
37
+ readonly snapshots?: Readonly<Record<string, string>>;
38
+ /** The person asked for another workspace. */
39
+ readonly onSwitch: (id: string, how: SwitchHow) => void;
40
+ /** The person chose one of an app's items: `target` says from where, `itemId` is the app's own id for it. */
41
+ readonly onCommand: (appId: string, target: CommandTarget, itemId: string) => void;
42
+ /** The room the chrome takes, whenever it changes: bound the apps' views inside it. */
43
+ readonly onInsets?: (insets: ShellInsets) => void;
44
+ /** The switching keys; the platform's defaults if left out, none at all with null. */
45
+ readonly keys?: SwitchKeys | null;
46
+ /** How a click in the switcher switches. */
47
+ readonly clickSwitch?: SwitchHow;
48
+ readonly dockSide?: DockSide;
49
+ }
50
+ /** An app's dock entries, as data, turned back into entries the drawn dock draws; choosing one asks the host. */
51
+ export declare function dockFromHost(entries: readonly HostDockEntry[], choose: (itemId: string) => void): DockEntry[];
52
+ export declare function HostShell(props: HostShellProps): import("react").JSX.Element;
53
+ //# sourceMappingURL=HostShell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostShell.d.ts","sourceRoot":"","sources":["../../src/shell/HostShell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAgB,MAAM,mBAAmB,CAAA;AAE/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAY,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAe3C,uDAAuD;AACvD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,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G,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAClF,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAA;IACjD,sFAAsF;IACtF,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IACjC,4CAA4C;IAC5C,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,CAAA;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAC7B;AAKD,iHAAiH;AACjH,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,EAAE,CAgB7G;AAID,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,+BAO9C"}
@@ -0,0 +1,116 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
3
+ import { applyTheme } from '../core/theme.js';
4
+ import { DeskProvider } from '../react/context.js';
5
+ import { Dock, roveFocus } from '../react/Dock.js';
6
+ import { neighbour, platformOf, switchKeyAction, switchKeys } from './keys.js';
7
+ const imageIcon = (label, image) => image ? _jsx("img", { src: image, alt: "", draggable: false }) : _jsx("span", { className: "desk-shell-initial", children: label.slice(0, 1).toUpperCase() });
8
+ /** An app's dock entries, as data, turned back into entries the drawn dock draws; choosing one asks the host. */
9
+ export function dockFromHost(entries, choose) {
10
+ const item = (entry) => ({
11
+ id: entry.id,
12
+ label: entry.label,
13
+ icon: imageIcon(entry.label, entry.image),
14
+ ...(entry.description === undefined ? {} : { description: entry.description }),
15
+ ...(entry.badge === undefined ? {} : { badge: entry.badge === '' ? _jsx("span", { className: "desk-shell-dot" }) : entry.badge }),
16
+ ...(entry.disabled ? { disabled: true } : {}),
17
+ status: { running: entry.running, focused: entry.focused, minimized: entry.minimized },
18
+ onSelect: () => choose(entry.id),
19
+ });
20
+ return entries.map((entry) => {
21
+ if (entry.type === 'separator')
22
+ return { type: 'separator', id: entry.id };
23
+ if (entry.type === 'item')
24
+ return { type: 'item', ...item(entry) };
25
+ return { type: 'stack', id: entry.id, label: entry.label, icon: imageIcon(entry.label, entry.image), items: entry.items.map(item) };
26
+ });
27
+ }
28
+ const defaultKeys = () => switchKeys(platformOf(typeof navigator === 'undefined' ? '' : navigator.platform || navigator.userAgent));
29
+ export function HostShell(props) {
30
+ // Its own desk, never hosted: this page is the host's, drawing for the apps.
31
+ return (_jsx(DeskProvider, { host: null, look: props.theme?.look ?? 'auto', children: _jsx(Shell, { ...props }) }));
32
+ }
33
+ function Shell({ workspaces, current, chrome, theme, onSwitch, onCommand, onInsets, keys, clickSwitch = 'slide', dockSide = 'left' }) {
34
+ useLayoutEffect(() => {
35
+ if (theme)
36
+ applyTheme(theme);
37
+ }, [theme]);
38
+ const entries = useMemo(() => dockFromHost(chrome[current]?.dock ?? [], itemId => onCommand(current, 'dock', itemId)), [chrome, current, onCommand]);
39
+ // The arrived workspace's title, said once, politely: only on a change, never on first showing.
40
+ const [arrived, setArrived] = useState('');
41
+ const shown = useRef(current);
42
+ useEffect(() => {
43
+ if (shown.current === current)
44
+ return;
45
+ shown.current = current;
46
+ setArrived(workspaces.find(w => w.id === current)?.title ?? '');
47
+ }, [current, workspaces]);
48
+ // The switching keys, when this page has focus; a host catches them first when an app has it.
49
+ const bound = useMemo(() => (keys === null ? null : keys ?? defaultKeys()), [keys]);
50
+ useEffect(() => {
51
+ if (!bound)
52
+ return;
53
+ const onKey = (event) => {
54
+ const action = switchKeyAction(event, bound);
55
+ if (action !== 'previous' && action !== 'next')
56
+ return;
57
+ const to = neighbour(workspaces, current, action);
58
+ event.preventDefault();
59
+ if (to)
60
+ onSwitch(to.id, 'slide');
61
+ };
62
+ window.addEventListener('keydown', onKey);
63
+ return () => window.removeEventListener('keydown', onKey);
64
+ }, [bound, workspaces, current, onSwitch]);
65
+ const root = useRef(null);
66
+ useInsets(root, dockSide, onInsets);
67
+ return (_jsxs("div", { ref: root, className: "desk-shell", "data-dock-side": dockSide, children: [_jsx("div", { className: "desk-shell-bar", children: _jsx(Switcher, { workspaces: workspaces, current: current, onChoose: id => id !== current && onSwitch(id, clickSwitch) }) }), _jsx(Dock, { entries: entries, side: dockSide, label: `${workspaces.find(w => w.id === current)?.title ?? 'App'} dock` }), _jsx("div", { className: "desk-shell-announce", role: "status", "aria-live": "polite", children: arrived })] }));
68
+ }
69
+ function Switcher({ workspaces, current, onChoose }) {
70
+ // One Tab stop: the current workspace's, or the first while the current one is not listed.
71
+ const stop = workspaces.some(w => w.id === current) ? current : workspaces[0]?.id;
72
+ const toolbar = useRef(null);
73
+ // Arrowing moves the stop by hand; once the host has moved, it is the current workspace's again.
74
+ useLayoutEffect(() => {
75
+ toolbar.current?.querySelectorAll('button').forEach(b => (b.tabIndex = b.dataset.workspace === stop ? 0 : -1));
76
+ }, [stop, workspaces]);
77
+ return (_jsx("div", { ref: toolbar, role: "toolbar", "aria-label": "Workspaces", className: "desk-shell-switcher", onKeyDown: event => {
78
+ // A held modifier makes the arrow a switching key, which the page's listener handles: don't rove too.
79
+ if (!event.ctrlKey && !event.altKey && !event.metaKey)
80
+ roveFocus(event, { next: ['ArrowRight'], previous: ['ArrowLeft'] });
81
+ }, children: workspaces.map(w => (_jsxs("button", { type: "button", className: "desk-shell-workspace", "data-rove": true, "data-workspace": w.id, tabIndex: w.id === stop ? 0 : -1, "aria-current": w.id === current ? 'true' : undefined, "data-state": w.state, onClick: () => onChoose(w.id), children: [w.icon ? _jsx("img", { src: w.icon, alt: "", draggable: false }) : _jsx("span", { className: "desk-shell-mark", style: w.accent ? { background: w.accent } : undefined, "aria-hidden": "true" }), _jsx("span", { children: w.title })] }, w.id))) }));
82
+ }
83
+ /** Reports the room the bar and the dock take, whenever either changes size. */
84
+ function useInsets(root, side, onInsets) {
85
+ const last = useRef('');
86
+ useLayoutEffect(() => {
87
+ const el = root.current;
88
+ if (!el || !onInsets)
89
+ return;
90
+ const measure = () => {
91
+ const bounds = el.getBoundingClientRect();
92
+ const bar = el.querySelector('.desk-shell-bar')?.getBoundingClientRect();
93
+ const dock = el.querySelector('.desk-dock')?.getBoundingClientRect();
94
+ const gap = dock && dock.width > 0 ? 1 : 0;
95
+ const insets = {
96
+ top: Math.ceil(bar ? bar.bottom - bounds.top : 0),
97
+ left: side === 'left' && gap ? Math.ceil(dock.right - bounds.left) : 0,
98
+ right: side === 'right' && gap ? Math.ceil(bounds.right - dock.left) : 0,
99
+ bottom: side === 'bottom' && gap ? Math.ceil(bounds.bottom - dock.top) : 0,
100
+ };
101
+ const key = JSON.stringify(insets);
102
+ if (key === last.current)
103
+ return;
104
+ last.current = key;
105
+ onInsets(insets);
106
+ };
107
+ measure();
108
+ if (typeof ResizeObserver === 'undefined')
109
+ return;
110
+ const observer = new ResizeObserver(measure);
111
+ observer.observe(el);
112
+ el.querySelectorAll('.desk-shell-bar, .desk-dock').forEach(node => observer.observe(node));
113
+ return () => observer.disconnect();
114
+ });
115
+ }
116
+ //# sourceMappingURL=HostShell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostShell.js","sourceRoot":"","sources":["../../src/shell/HostShell.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAG7E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;A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;QAC5C,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACpB,EAAE,CAAC,gBAAgB,CAAC,6BAA6B,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QAC1F,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { dockFromHost, HostShell } from './HostShell.js';
2
+ export type { HostShellProps, ShellInsets, ShellWorkspace, SwitchHow } from './HostShell.js';
3
+ export { neighbour, platformOf, switchKeyAction, switchKeys } from './keys.js';
4
+ export type { KeyInput, ShellPlatform, SwitchKey, SwitchKeys } from './keys.js';
5
+ export { animate, FADE_MS, linear, pageClock, SLIDE_MS, slideOffsets, slidePlan, spring, timerClock } from './motion.js';
6
+ export type { Animation, AnimateOptions, FrameClock, SlideOffsets, SlidePlan } from './motion.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shell/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACxD,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC5F,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC9E,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC/E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxH,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,9 @@
1
+ /*
2
+ * The shell of a host that runs several Desk apps side by side: one dock and one switcher drawn for
3
+ * all of them, and the curve the host moves their views on. Only the host's own page loads it; no
4
+ * app does, and nothing in core or react imports it.
5
+ */
6
+ export { dockFromHost, HostShell } from './HostShell.js';
7
+ export { neighbour, platformOf, switchKeyAction, switchKeys } from './keys.js';
8
+ export { animate, FADE_MS, linear, pageClock, SLIDE_MS, slideOffsets, slidePlan, spring, timerClock } from './motion.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shell/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,47 @@
1
+ /** One key with its modifiers. `meta` is ⌘ on a Mac, Super (the Windows key) elsewhere. */
2
+ export interface SwitchKey {
3
+ readonly key: string;
4
+ readonly ctrl?: boolean;
5
+ readonly alt?: boolean;
6
+ readonly meta?: boolean;
7
+ readonly shift?: boolean;
8
+ }
9
+ /** What each switching key does. */
10
+ export interface SwitchKeys {
11
+ readonly previous: SwitchKey;
12
+ readonly next: SwitchKey;
13
+ /** Opens the overview, once there is one to open. */
14
+ readonly overview: SwitchKey;
15
+ }
16
+ export type ShellPlatform = 'mac' | 'linux' | 'windows';
17
+ /**
18
+ * The platform, from a browser's `navigator.platform` or user agent, or a Node `process.platform`
19
+ * ('darwin', 'linux', 'win32').
20
+ */
21
+ export declare function platformOf(name: string): ShellPlatform;
22
+ /** The default keys on a platform: Ctrl+Option on a Mac, Super+Alt on Linux, Ctrl+Alt on Windows. */
23
+ export declare function switchKeys(platform: ShellPlatform): SwitchKeys;
24
+ /** A key event from a page (`ctrlKey`…) or from Electron's `before-input-event` (`control`…). */
25
+ export interface KeyInput {
26
+ readonly key: string;
27
+ /** `keydown`/`keyup` from a page, `keyDown`/`keyUp` from Electron: only a key going down switches. */
28
+ readonly type?: string;
29
+ readonly ctrlKey?: boolean;
30
+ readonly altKey?: boolean;
31
+ readonly metaKey?: boolean;
32
+ readonly shiftKey?: boolean;
33
+ readonly control?: boolean;
34
+ readonly alt?: boolean;
35
+ readonly meta?: boolean;
36
+ readonly shift?: boolean;
37
+ }
38
+ /** What a key does, if it is one of the switching keys: modifiers must match exactly. */
39
+ export declare function switchKeyAction(input: KeyInput, keys: SwitchKeys): 'previous' | 'next' | 'overview' | null;
40
+ /**
41
+ * The workspace one step from `current`, in the order given (the switcher's order), or null at
42
+ * either end: like the OS's own workspaces, switching does not wrap round.
43
+ */
44
+ export declare function neighbour<T extends {
45
+ readonly id: string;
46
+ }>(workspaces: readonly T[], current: string, step: 'previous' | 'next'): T | null;
47
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/shell/keys.ts"],"names":[],"mappings":"AAaA,2FAA2F;AAC3F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,oCAAoC;AACpC,MAAM,WAAW,UAAU;IACzB,QAAQ,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UAAU,GAAG,MAAM,GAAG,CAAC,GAAG,IAAI,CAI3I"}
@@ -0,0 +1,68 @@
1
+ /*
2
+ * THE KEYS THAT SWITCH WORKSPACES, PER PLATFORM.
3
+ *
4
+ * Every OS has keys of its own for its own workspaces, and a host's must never fight them: macOS takes
5
+ * Ctrl+←/→ for Spaces and Ctrl+↑ for Mission Control; GNOME takes Ctrl+Alt+←/→ (and Super+PageUp/Down),
6
+ * KDE Meta+Ctrl+←/→; Windows takes Ctrl+Win+←/→ for its virtual desktops. So the defaults step around
7
+ * each, and a host can offer its own in Settings.
8
+ *
9
+ * A key reaches whichever view has focus, usually an app's. So a host catches these before the app
10
+ * does (in Electron, `before-input-event`) and asks `switchKeyAction` what the key means; the shell's
11
+ * own page uses the same function for the keys it sees itself.
12
+ */
13
+ /**
14
+ * The platform, from a browser's `navigator.platform` or user agent, or a Node `process.platform`
15
+ * ('darwin', 'linux', 'win32').
16
+ */
17
+ export function platformOf(name) {
18
+ if (/mac|darwin|iphone|ipad/i.test(name))
19
+ return 'mac';
20
+ if (/win/i.test(name))
21
+ return 'windows';
22
+ return 'linux';
23
+ }
24
+ const arrows = (mods) => ({
25
+ previous: { key: 'ArrowLeft', ...mods },
26
+ next: { key: 'ArrowRight', ...mods },
27
+ overview: { key: 'ArrowUp', ...mods },
28
+ });
29
+ /** The default keys on a platform: Ctrl+Option on a Mac, Super+Alt on Linux, Ctrl+Alt on Windows. */
30
+ export function switchKeys(platform) {
31
+ switch (platform) {
32
+ case 'mac':
33
+ return arrows({ ctrl: true, alt: true });
34
+ case 'linux':
35
+ return arrows({ meta: true, alt: true });
36
+ case 'windows':
37
+ return arrows({ ctrl: true, alt: true });
38
+ }
39
+ }
40
+ const matches = (input, key) => input.key === key.key &&
41
+ Boolean(input.ctrlKey ?? input.control) === Boolean(key.ctrl) &&
42
+ Boolean(input.altKey ?? input.alt) === Boolean(key.alt) &&
43
+ Boolean(input.metaKey ?? input.meta) === Boolean(key.meta) &&
44
+ Boolean(input.shiftKey ?? input.shift) === Boolean(key.shift);
45
+ /** What a key does, if it is one of the switching keys: modifiers must match exactly. */
46
+ export function switchKeyAction(input, keys) {
47
+ // Electron's before-input-event sends the key's release too: one press must switch once.
48
+ if (/up$/i.test(input.type ?? ''))
49
+ return null;
50
+ if (matches(input, keys.previous))
51
+ return 'previous';
52
+ if (matches(input, keys.next))
53
+ return 'next';
54
+ if (matches(input, keys.overview))
55
+ return 'overview';
56
+ return null;
57
+ }
58
+ /**
59
+ * The workspace one step from `current`, in the order given (the switcher's order), or null at
60
+ * either end: like the OS's own workspaces, switching does not wrap round.
61
+ */
62
+ export function neighbour(workspaces, current, step) {
63
+ const index = workspaces.findIndex(w => w.id === current);
64
+ if (index < 0)
65
+ return null;
66
+ return workspaces[index + (step === 'next' ? 1 : -1)] ?? null;
67
+ }
68
+ //# sourceMappingURL=keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/shell/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAqBH;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IACtD,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAA;IACvC,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,IAA4B,EAAc,EAAE,CAAC,CAAC;IAC5D,QAAQ,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE;IACvC,IAAI,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE;IACpC,QAAQ,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE;CACtC,CAAC,CAAA;AAEF,qGAAqG;AACrG,MAAM,UAAU,UAAU,CAAC,QAAuB;IAChD,QAAQ,QAAQ,E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AAC;QAAE,OAAO,MAAM,CAAA;IAC5C,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,UAAU,CAAA;IACpD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAoC,UAAwB,EAAE,OAAe,EAAE,IAAyB;IAC/H,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,CAAA;IACzD,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAA;IAC1B,OAAO,UAAU,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,72 @@
1
+ /** How a switch is drawn: the desktops slide, or (reduced motion) the arriving one fades in over the other. */
2
+ export interface SlidePlan {
3
+ readonly kind: 'slide' | 'fade';
4
+ readonly durationMs: number;
5
+ }
6
+ /** The default slide, and the short fade that replaces it under reduced motion. */
7
+ export declare const SLIDE_MS = 350;
8
+ export declare const FADE_MS = 120;
9
+ /** What a switch should do, given whether the person asked for less motion. */
10
+ export declare const slidePlan: (reducedMotion: boolean, durationMs?: number) => SlidePlan;
11
+ /**
12
+ * A critically damped spring towards 1, from `from` with a starting speed `velocity` (progress per
13
+ * second), stiff enough to settle within `durationMs`. Returns the progress at a time in milliseconds
14
+ * since it started: exactly 1 from `durationMs` on.
15
+ */
16
+ export declare function spring(durationMs?: number, from?: number, velocity?: number): (elapsedMs: number) => number;
17
+ /** A plain linear ramp, for the fade: opacity follows time evenly. */
18
+ export declare const linear: (durationMs: number) => (elapsedMs: number) => number;
19
+ /** Where the two desktops sit at a given progress, in whole pixels from the desktop area's left edge. */
20
+ export interface SlideOffsets {
21
+ /** The workspace being left. */
22
+ readonly leaving: number;
23
+ /** The workspace arriving. */
24
+ readonly arriving: number;
25
+ }
26
+ /**
27
+ * The desktops' offsets at `progress`. Moving to a workspace further along (`direction` 1) the one
28
+ * being left goes out to the left and the next comes in from the right; back (`-1`), the other way.
29
+ * Rounded to whole pixels, as a view's bounds are, and with no gap or overlap between the two.
30
+ *
31
+ * Mid-slide both views reach past the desktop area, so the host must clip them to it (the area
32
+ * `onInsets` gives): a view placed at these offsets with nothing clipping it covers the dock beside.
33
+ */
34
+ export declare function slideOffsets(progress: number, direction: 1 | -1, width: number): SlideOffsets;
35
+ /** What `animate` needs to schedule frames: rAF in a page, a timer in a main process. */
36
+ export interface FrameClock {
37
+ readonly now: () => number;
38
+ /** Calls back on the next frame. */
39
+ readonly frame: (callback: () => void) => void;
40
+ /** Calls back after a delay, whatever the frames do. */
41
+ readonly after: (ms: number, callback: () => void) => void;
42
+ }
43
+ /** A clock for a page: frames from requestAnimationFrame, which a hidden page never gives. */
44
+ export declare const pageClock: () => FrameClock;
45
+ /** A clock for a process with no frames of its own, as an app host's main process: about 60 a second. */
46
+ export declare const timerClock: (frameMs?: number) => FrameClock;
47
+ export interface AnimateOptions {
48
+ readonly durationMs: number;
49
+ /** The curve: progress at a time; `spring(durationMs)` by default. */
50
+ readonly curve?: (elapsedMs: number) => number;
51
+ /** Called with each frame's progress, and finally with 1. */
52
+ readonly step: (progress: number) => void;
53
+ readonly clock?: FrameClock;
54
+ /**
55
+ * How long past `durationMs` to wait for frames before jumping to the end. A window that is covered,
56
+ * minimised or on another desktop gets no frames, and an animation must never hang on them.
57
+ */
58
+ readonly timeoutMs?: number;
59
+ }
60
+ /** A running animation. `stop` leaves it where it is; `done` resolves at the end, or when stopped. */
61
+ export interface Animation {
62
+ readonly done: Promise<'finished' | 'jumped' | 'stopped'>;
63
+ /** Where it is now, for a gesture that catches it mid-flight. */
64
+ progress(): number;
65
+ stop(): void;
66
+ }
67
+ /**
68
+ * Steps `step` through a curve, frame by frame, from any clock. Ends at 1 when time is up, and jumps
69
+ * straight there if frames stop arriving for `timeoutMs`.
70
+ */
71
+ export declare function animate({ durationMs, curve, step, clock, timeoutMs }: AnimateOptions): Animation;
72
+ //# sourceMappingURL=motion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../../src/shell/motion.ts"],"names":[],"mappings":"AAaA,+GAA+G;AAC/G,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAA;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAED,mFAAmF;AACnF,eAAO,MAAM,QAAQ,MAAM,CAAA;AAC3B,eAAO,MAAM,OAAO,MAAM,CAAA;AAE1B,+EAA+E;AAC/E,eAAO,MAAM,SAAS,kBAAmB,OAAO,0BAA0B,SACa,CAAA;AAKvF;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,UAAU,SAAW,EAAE,IAAI,SAAI,EAAE,QAAQ,SAAI,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAWnG;AAYD,sEAAsE;AACtE,eAAO,MAAM,MAAM,eAAgB,MAAM,iBAAiB,MAAM,KAAG,MAA0D,CAAA;AAE7H,yGAAyG;AACzG,MAAM,WAAW,YAAY;IAC3B,gCAAgC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,8BAA8B;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAI7F;AAED,yFAAyF;AACzF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAA;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,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