@liberation-data/desk 0.43.0 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/README.md +225 -8
  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 +9 -1
  7. package/dist/core/index.d.ts.map +1 -1
  8. package/dist/core/index.js +5 -1
  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 +9 -3
  19. package/dist/core/scheme.d.ts.map +1 -1
  20. package/dist/core/scheme.js +13 -4
  21. package/dist/core/scheme.js.map +1 -1
  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/css/apps.css +35 -1
  31. package/dist/css/shell.css +100 -0
  32. package/dist/css/tokens.css +10 -0
  33. package/dist/desk.css +45 -1
  34. package/dist/fx/fx.d.ts.map +1 -1
  35. package/dist/fx/fx.js +7 -31
  36. package/dist/fx/fx.js.map +1 -1
  37. package/dist/host/checkChrome.d.ts +20 -0
  38. package/dist/host/checkChrome.d.ts.map +1 -0
  39. package/dist/host/checkChrome.js +219 -0
  40. package/dist/host/checkChrome.js.map +1 -0
  41. package/dist/host/checkTheme.d.ts +35 -0
  42. package/dist/host/checkTheme.d.ts.map +1 -0
  43. package/dist/host/checkTheme.js +128 -0
  44. package/dist/host/checkTheme.js.map +1 -0
  45. package/dist/host/index.d.ts +7 -0
  46. package/dist/host/index.d.ts.map +1 -0
  47. package/dist/host/index.js +8 -0
  48. package/dist/host/index.js.map +1 -0
  49. package/dist/host/router.d.ts +99 -0
  50. package/dist/host/router.d.ts.map +1 -0
  51. package/dist/host/router.js +279 -0
  52. package/dist/host/router.js.map +1 -0
  53. package/dist/react/Dock.d.ts +23 -4
  54. package/dist/react/Dock.d.ts.map +1 -1
  55. package/dist/react/Dock.js +17 -29
  56. package/dist/react/Dock.js.map +1 -1
  57. package/dist/react/MenuBar.d.ts +1 -1
  58. package/dist/react/MenuBar.d.ts.map +1 -1
  59. package/dist/react/MenuBar.js +20 -4
  60. package/dist/react/MenuBar.js.map +1 -1
  61. package/dist/react/app.d.ts +50 -9
  62. package/dist/react/app.d.ts.map +1 -1
  63. package/dist/react/app.js +59 -13
  64. package/dist/react/app.js.map +1 -1
  65. package/dist/react/appFrame.d.ts +11 -7
  66. package/dist/react/appFrame.d.ts.map +1 -1
  67. package/dist/react/appFrame.js +24 -6
  68. package/dist/react/appFrame.js.map +1 -1
  69. package/dist/react/appPanels.d.ts +4 -1
  70. package/dist/react/appPanels.d.ts.map +1 -1
  71. package/dist/react/appPanels.js +32 -23
  72. package/dist/react/appPanels.js.map +1 -1
  73. package/dist/react/appearance.d.ts +7 -1
  74. package/dist/react/appearance.d.ts.map +1 -1
  75. package/dist/react/appearance.js +32 -53
  76. package/dist/react/appearance.js.map +1 -1
  77. package/dist/react/context.d.ts +15 -1
  78. package/dist/react/context.d.ts.map +1 -1
  79. package/dist/react/context.js +73 -14
  80. package/dist/react/context.js.map +1 -1
  81. package/dist/react/dockStatus.d.ts +19 -0
  82. package/dist/react/dockStatus.d.ts.map +1 -0
  83. package/dist/react/dockStatus.js +25 -0
  84. package/dist/react/dockStatus.js.map +1 -0
  85. package/dist/react/frameMenus.d.ts +28 -0
  86. package/dist/react/frameMenus.d.ts.map +1 -0
  87. package/dist/react/frameMenus.js +85 -0
  88. package/dist/react/frameMenus.js.map +1 -0
  89. package/dist/react/hostApp.d.ts +15 -0
  90. package/dist/react/hostApp.d.ts.map +1 -0
  91. package/dist/react/hostApp.js +77 -0
  92. package/dist/react/hostApp.js.map +1 -0
  93. package/dist/react/hostDock.d.ts +25 -0
  94. package/dist/react/hostDock.d.ts.map +1 -0
  95. package/dist/react/hostDock.js +98 -0
  96. package/dist/react/hostDock.js.map +1 -0
  97. package/dist/react/hostMenu.d.ts +2 -36
  98. package/dist/react/hostMenu.d.ts.map +1 -1
  99. package/dist/react/hostMenu.js.map +1 -1
  100. package/dist/react/hosted.d.ts +28 -0
  101. package/dist/react/hosted.d.ts.map +1 -0
  102. package/dist/react/hosted.js +53 -0
  103. package/dist/react/hosted.js.map +1 -0
  104. package/dist/react/index.d.ts +8 -3
  105. package/dist/react/index.d.ts.map +1 -1
  106. package/dist/react/index.js +5 -2
  107. package/dist/react/index.js.map +1 -1
  108. package/dist/react/shell.d.ts +13 -1
  109. package/dist/react/shell.d.ts.map +1 -1
  110. package/dist/react/shell.js +19 -3
  111. package/dist/react/shell.js.map +1 -1
  112. package/dist/react/windowMenus.d.ts +19 -0
  113. package/dist/react/windowMenus.d.ts.map +1 -0
  114. package/dist/react/windowMenus.js +88 -0
  115. package/dist/react/windowMenus.js.map +1 -0
  116. package/dist/shell/HostShell.d.ts +53 -0
  117. package/dist/shell/HostShell.d.ts.map +1 -0
  118. package/dist/shell/HostShell.js +116 -0
  119. package/dist/shell/HostShell.js.map +1 -0
  120. package/dist/shell/index.d.ts +7 -0
  121. package/dist/shell/index.d.ts.map +1 -0
  122. package/dist/shell/index.js +9 -0
  123. package/dist/shell/index.js.map +1 -0
  124. package/dist/shell/keys.d.ts +47 -0
  125. package/dist/shell/keys.d.ts.map +1 -0
  126. package/dist/shell/keys.js +68 -0
  127. package/dist/shell/keys.js.map +1 -0
  128. package/dist/shell/motion.d.ts +72 -0
  129. package/dist/shell/motion.d.ts.map +1 -0
  130. package/dist/shell/motion.js +118 -0
  131. package/dist/shell/motion.js.map +1 -0
  132. package/llms.txt +48 -14
  133. package/package.json +10 -1
  134. package/src/core/hosted.ts +351 -0
  135. package/src/core/index.ts +28 -1
  136. package/src/core/location.ts +23 -3
  137. package/src/core/preferences.ts +132 -0
  138. package/src/core/scheme.ts +16 -5
  139. package/src/core/theme.ts +91 -0
  140. package/src/core/themeChange.ts +59 -0
  141. package/src/css/apps.css +35 -1
  142. package/src/css/shell.css +99 -0
  143. package/src/css/tokens.css +10 -0
  144. package/src/fx/fx.ts +7 -25
  145. package/src/host/checkChrome.ts +257 -0
  146. package/src/host/checkTheme.ts +134 -0
  147. package/src/host/index.ts +10 -0
  148. package/src/host/router.ts +374 -0
  149. package/src/react/Dock.tsx +34 -28
  150. package/src/react/MenuBar.tsx +22 -4
  151. package/src/react/app.tsx +84 -14
  152. package/src/react/appFrame.tsx +39 -14
  153. package/src/react/appPanels.tsx +38 -25
  154. package/src/react/appearance.tsx +36 -45
  155. package/src/react/context.tsx +88 -13
  156. package/src/react/dockStatus.ts +42 -0
  157. package/src/react/frameMenus.ts +100 -0
  158. package/src/react/hostApp.tsx +89 -0
  159. package/src/react/hostDock.tsx +118 -0
  160. package/src/react/hostMenu.ts +3 -38
  161. package/src/react/hosted.tsx +65 -0
  162. package/src/react/index.ts +9 -2
  163. package/src/react/shell.tsx +30 -3
  164. package/src/react/windowMenus.ts +107 -0
  165. package/src/shell/HostShell.tsx +220 -0
  166. package/src/shell/index.ts +11 -0
  167. package/src/shell/keys.ts +101 -0
  168. package/src/shell/motion.ts +163 -0
@@ -0,0 +1,163 @@
1
+ /*
2
+ * THE SLIDE, AS NUMBERS.
3
+ *
4
+ * When a host switches workspaces it moves the apps' live views itself, from its own process, a frame
5
+ * at a time; the shell draws the chrome around them. Both must move on one curve, so the curve is
6
+ * here as plain functions, with no DOM: a host's main process steps its views' bounds from them, and
7
+ * the shell animates with the same ones.
8
+ *
9
+ * Progress runs from 0 (the workspace being left fills the desktop) to 1 (the one arriving does). The
10
+ * spring is critically damped: it arrives without overshooting, and it can start from any progress
11
+ * and speed, so a slide caught mid-flight, or flung, carries on from where it is.
12
+ */
13
+
14
+ /** How a switch is drawn: the desktops slide, or (reduced motion) the arriving one fades in over the other. */
15
+ export interface SlidePlan {
16
+ readonly kind: 'slide' | 'fade'
17
+ readonly durationMs: number
18
+ }
19
+
20
+ /** The default slide, and the short fade that replaces it under reduced motion. */
21
+ export const SLIDE_MS = 350
22
+ export const FADE_MS = 120
23
+
24
+ /** What a switch should do, given whether the person asked for less motion. */
25
+ export const slidePlan = (reducedMotion: boolean, durationMs = SLIDE_MS): SlidePlan =>
26
+ reducedMotion ? { kind: 'fade', durationMs: FADE_MS } : { kind: 'slide', durationMs }
27
+
28
+ /** The distance left that counts as arrived: under a tenth of a pixel on a 4K-wide desktop. */
29
+ const SETTLED = 0.00002
30
+
31
+ /**
32
+ * A critically damped spring towards 1, from `from` with a starting speed `velocity` (progress per
33
+ * second), stiff enough to settle within `durationMs`. Returns the progress at a time in milliseconds
34
+ * since it started: exactly 1 from `durationMs` on.
35
+ */
36
+ export function spring(durationMs = SLIDE_MS, from = 0, velocity = 0): (elapsedMs: number) => number {
37
+ // (1 + ωt)·e^(−ωt) falls to SETTLED when ωt is about 13.5: pick ω so that happens at durationMs.
38
+ const omega = settleConstant() / (durationMs / 1000)
39
+ const d0 = from - 1
40
+ const c2 = velocity + omega * d0
41
+ return elapsedMs => {
42
+ if (elapsedMs >= durationMs) return 1
43
+ const t = Math.max(0, elapsedMs) / 1000
44
+ // A hard fling would carry a critically damped spring past its target once: hold it at 1 instead.
45
+ return Math.min(1, 1 + (d0 + c2 * t) * Math.exp(-omega * t))
46
+ }
47
+ }
48
+
49
+ let settle: number | undefined
50
+ /** The ωt at which a critically damped spring from rest is within SETTLED of its target. */
51
+ function settleConstant(): number {
52
+ if (settle !== undefined) return settle
53
+ let x = 10
54
+ // Newton's method on f(x) = (1 + x)e^(−x) − SETTLED; a handful of steps is exact to the float.
55
+ for (let i = 0; i < 20; i++) x -= ((1 + x) * Math.exp(-x) - SETTLED) / (-x * Math.exp(-x))
56
+ return (settle = x)
57
+ }
58
+
59
+ /** A plain linear ramp, for the fade: opacity follows time evenly. */
60
+ export const linear = (durationMs: number) => (elapsedMs: number): number => Math.min(1, Math.max(0, elapsedMs / durationMs))
61
+
62
+ /** Where the two desktops sit at a given progress, in whole pixels from the desktop area's left edge. */
63
+ export interface SlideOffsets {
64
+ /** The workspace being left. */
65
+ readonly leaving: number
66
+ /** The workspace arriving. */
67
+ readonly arriving: number
68
+ }
69
+
70
+ /**
71
+ * The desktops' offsets at `progress`. Moving to a workspace further along (`direction` 1) the one
72
+ * being left goes out to the left and the next comes in from the right; back (`-1`), the other way.
73
+ * Rounded to whole pixels, as a view's bounds are, and with no gap or overlap between the two.
74
+ *
75
+ * Mid-slide both views reach past the desktop area, so the host must clip them to it (the area
76
+ * `onInsets` gives): a view placed at these offsets with nothing clipping it covers the dock beside.
77
+ */
78
+ export function slideOffsets(progress: number, direction: 1 | -1, width: number): SlideOffsets {
79
+ const whole = Math.round(width)
80
+ const leaving = -direction * Math.round(progress * whole)
81
+ return { leaving, arriving: leaving + direction * whole }
82
+ }
83
+
84
+ /** What `animate` needs to schedule frames: rAF in a page, a timer in a main process. */
85
+ export interface FrameClock {
86
+ readonly now: () => number
87
+ /** Calls back on the next frame. */
88
+ readonly frame: (callback: () => void) => void
89
+ /** Calls back after a delay, whatever the frames do. */
90
+ readonly after: (ms: number, callback: () => void) => void
91
+ }
92
+
93
+ /** A clock for a page: frames from requestAnimationFrame, which a hidden page never gives. */
94
+ export const pageClock = (): FrameClock => ({
95
+ now: () => performance.now(),
96
+ frame: callback => requestAnimationFrame(() => callback()),
97
+ after: (ms, callback) => setTimeout(callback, ms),
98
+ })
99
+
100
+ /** A clock for a process with no frames of its own, as an app host's main process: about 60 a second. */
101
+ export const timerClock = (frameMs = 1000 / 60): FrameClock => ({
102
+ now: () => performance.now(),
103
+ frame: callback => setTimeout(callback, frameMs),
104
+ after: (ms, callback) => setTimeout(callback, ms),
105
+ })
106
+
107
+ export interface AnimateOptions {
108
+ readonly durationMs: number
109
+ /** The curve: progress at a time; `spring(durationMs)` by default. */
110
+ readonly curve?: (elapsedMs: number) => number
111
+ /** Called with each frame's progress, and finally with 1. */
112
+ readonly step: (progress: number) => void
113
+ readonly clock?: FrameClock
114
+ /**
115
+ * How long past `durationMs` to wait for frames before jumping to the end. A window that is covered,
116
+ * minimised or on another desktop gets no frames, and an animation must never hang on them.
117
+ */
118
+ readonly timeoutMs?: number
119
+ }
120
+
121
+ /** A running animation. `stop` leaves it where it is; `done` resolves at the end, or when stopped. */
122
+ export interface Animation {
123
+ readonly done: Promise<'finished' | 'jumped' | 'stopped'>
124
+ /** Where it is now, for a gesture that catches it mid-flight. */
125
+ progress(): number
126
+ stop(): void
127
+ }
128
+
129
+ /**
130
+ * Steps `step` through a curve, frame by frame, from any clock. Ends at 1 when time is up, and jumps
131
+ * straight there if frames stop arriving for `timeoutMs`.
132
+ */
133
+ export function animate({ durationMs, curve = spring(durationMs), step, clock = pageClock(), timeoutMs = 250 }: AnimateOptions): Animation {
134
+ const start = clock.now()
135
+ let current = 0
136
+ let ended = false
137
+ let finish!: (how: 'finished' | 'jumped' | 'stopped') => void
138
+ const done = new Promise<'finished' | 'jumped' | 'stopped'>(resolve => (finish = resolve))
139
+ const end = (how: 'finished' | 'jumped' | 'stopped') => {
140
+ if (ended) return
141
+ ended = true
142
+ if (how !== 'stopped') step((current = 1))
143
+ finish(how)
144
+ }
145
+ let lastFrame = start
146
+ const watchdog = () => {
147
+ if (ended) return
148
+ // Frames have stalled past the end: jump. Otherwise look again later.
149
+ if (clock.now() - lastFrame >= timeoutMs && clock.now() - start >= durationMs) end('jumped')
150
+ else clock.after(timeoutMs, watchdog)
151
+ }
152
+ const tick = () => {
153
+ if (ended) return
154
+ lastFrame = clock.now()
155
+ const elapsed = lastFrame - start
156
+ if (elapsed >= durationMs) return end('finished')
157
+ step((current = curve(elapsed)))
158
+ clock.frame(tick)
159
+ }
160
+ clock.frame(tick)
161
+ clock.after(durationMs + timeoutMs, watchdog)
162
+ return { done, progress: () => current, stop: () => end('stopped') }
163
+ }