@liberation-data/desk 0.45.0 → 0.47.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 +73 -7
- package/dist/core/hosted.d.ts +39 -1
- package/dist/core/hosted.d.ts.map +1 -1
- package/dist/core/hosted.js +44 -0
- package/dist/core/hosted.js.map +1 -1
- package/dist/core/index.d.ts +5 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/swipe.d.ts +15 -0
- package/dist/core/swipe.d.ts.map +1 -0
- package/dist/core/swipe.js +77 -0
- package/dist/core/swipe.js.map +1 -0
- package/dist/core/theme.d.ts +15 -0
- package/dist/core/theme.d.ts.map +1 -1
- package/dist/core/theme.js +73 -1
- package/dist/core/theme.js.map +1 -1
- package/dist/css/shell.css +89 -0
- package/dist/host/checkTheme.d.ts +2 -7
- package/dist/host/checkTheme.d.ts.map +1 -1
- package/dist/host/checkTheme.js +3 -27
- package/dist/host/checkTheme.js.map +1 -1
- package/dist/host/router.d.ts +17 -4
- package/dist/host/router.d.ts.map +1 -1
- package/dist/host/router.js +94 -2
- package/dist/host/router.js.map +1 -1
- package/dist/react/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +5 -0
- package/dist/react/Desktop.js.map +1 -1
- package/dist/react/context.d.ts +6 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +5 -3
- package/dist/react/context.js.map +1 -1
- package/dist/react/hostApp.d.ts +3 -1
- package/dist/react/hostApp.d.ts.map +1 -1
- package/dist/react/hostApp.js +3 -2
- package/dist/react/hostApp.js.map +1 -1
- package/dist/react/hosted.d.ts +10 -3
- package/dist/react/hosted.d.ts.map +1 -1
- package/dist/react/hosted.js +68 -8
- package/dist/react/hosted.js.map +1 -1
- package/dist/react/shell.d.ts +3 -1
- package/dist/react/shell.d.ts.map +1 -1
- package/dist/react/shell.js +2 -2
- package/dist/react/shell.js.map +1 -1
- package/dist/shell/HostOverview.d.ts +41 -0
- package/dist/shell/HostOverview.d.ts.map +1 -0
- package/dist/shell/HostOverview.js +219 -0
- package/dist/shell/HostOverview.js.map +1 -0
- package/dist/shell/HostShell.d.ts +3 -1
- package/dist/shell/HostShell.d.ts.map +1 -1
- package/dist/shell/HostShell.js +6 -4
- package/dist/shell/HostShell.js.map +1 -1
- package/dist/shell/index.d.ts +6 -0
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +3 -0
- package/dist/shell/index.js.map +1 -1
- package/dist/shell/swipe.d.ts +60 -0
- package/dist/shell/swipe.d.ts.map +1 -0
- package/dist/shell/swipe.js +158 -0
- package/dist/shell/swipe.js.map +1 -0
- package/dist/shell/zoom.d.ts +62 -0
- package/dist/shell/zoom.d.ts.map +1 -0
- package/dist/shell/zoom.js +116 -0
- package/dist/shell/zoom.js.map +1 -0
- package/llms.txt +14 -5
- package/package.json +12 -7
- package/src/core/hosted.ts +70 -1
- package/src/core/index.ts +5 -2
- package/src/core/swipe.ts +101 -0
- package/src/core/theme.ts +69 -1
- package/src/css/shell.css +89 -0
- package/src/host/checkTheme.ts +3 -25
- package/src/host/router.ts +100 -6
- package/src/react/Desktop.tsx +6 -0
- package/src/react/context.tsx +9 -2
- package/src/react/hostApp.tsx +3 -2
- package/src/react/hosted.tsx +68 -8
- package/src/react/shell.tsx +4 -2
- package/src/shell/HostOverview.tsx +317 -0
- package/src/shell/HostShell.tsx +8 -5
- package/src/shell/index.ts +20 -0
- package/src/shell/swipe.ts +202 -0
- package/src/shell/zoom.ts +151 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THE OVERVIEW AND THE ZOOM, AS NUMBERS.
|
|
3
|
+
*
|
|
4
|
+
* A live view can't be scaled (smaller bounds relay it out), so the zoom is drawn with pictures on an
|
|
5
|
+
* overlay: the current workspace's capture sits exactly over its live view, shrinks back into a fog
|
|
6
|
+
* where the workspaces float, the row moves across, and the target grows back to full size, where the
|
|
7
|
+
* host swaps its live view in. This file is where everything stands at each moment, with no DOM: the
|
|
8
|
+
* overlay draws from it, and a host can read the same plan to know how long a move takes.
|
|
9
|
+
*
|
|
10
|
+
* A pose is one moment: how far zoomed out (0 is a full-size desktop, 1 the overview), which workspace
|
|
11
|
+
* is centred (fractional while the row moves), how much fog shows, and how opaque the tiles are.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Zooming out, moving across, zooming in, and the capture wait, in ms. */
|
|
15
|
+
export const ZOOM_OUT_MS = 200
|
|
16
|
+
export const ZOOM_ACROSS_MS = 250
|
|
17
|
+
export const ZOOM_IN_MS = 200
|
|
18
|
+
/** How long to wait for a fresh capture of the current workspace before zooming from the picture already held. */
|
|
19
|
+
export const CAPTURE_WAIT_MS = 100
|
|
20
|
+
/** Reduced motion: every move is this cross-fade, in place. */
|
|
21
|
+
export const ZOOM_FADE_MS = 120
|
|
22
|
+
|
|
23
|
+
/** A CSS `cubic-bezier`, as a function of time from 0 to 1. */
|
|
24
|
+
export function cubicBezier(x1: number, y1: number, x2: number, y2: number): (t: number) => number {
|
|
25
|
+
const at = (a: number, b: number, s: number) => 3 * a * s * (1 - s) ** 2 + 3 * b * s * s * (1 - s) + s ** 3
|
|
26
|
+
return t => {
|
|
27
|
+
if (t <= 0) return 0
|
|
28
|
+
if (t >= 1) return 1
|
|
29
|
+
// Find s with x(s) = t by bisection: x is increasing, and 20 halvings are well under a pixel.
|
|
30
|
+
let lo = 0
|
|
31
|
+
let hi = 1
|
|
32
|
+
for (let i = 0; i < 20; i++) {
|
|
33
|
+
const mid = (lo + hi) / 2
|
|
34
|
+
if (at(x1, x2, mid) < t) lo = mid
|
|
35
|
+
else hi = mid
|
|
36
|
+
}
|
|
37
|
+
return at(y1, y2, (lo + hi) / 2)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const easeOut = cubicBezier(0, 0, 0.58, 1)
|
|
42
|
+
export const easeIn = cubicBezier(0.42, 0, 1, 1)
|
|
43
|
+
export const easeInOut = cubicBezier(0.42, 0, 0.58, 1)
|
|
44
|
+
const straight = (t: number) => Math.min(1, Math.max(0, t))
|
|
45
|
+
|
|
46
|
+
export interface OverviewPose {
|
|
47
|
+
/** 0 is a full-size desktop, 1 the overview. */
|
|
48
|
+
readonly zoom: number
|
|
49
|
+
/** The index of the centred workspace; fractional while the row moves. */
|
|
50
|
+
readonly centre: number
|
|
51
|
+
readonly fog: number
|
|
52
|
+
readonly opacity: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ZoomPhase {
|
|
56
|
+
readonly name: 'out' | 'across' | 'in' | 'fade'
|
|
57
|
+
readonly durationMs: number
|
|
58
|
+
readonly from: OverviewPose
|
|
59
|
+
readonly to: OverviewPose
|
|
60
|
+
readonly ease: (t: number) => number
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ZoomPlan {
|
|
64
|
+
readonly phases: readonly ZoomPhase[]
|
|
65
|
+
readonly durationMs: number
|
|
66
|
+
/** The pose asked for: what poseAt gives for a plan with nothing to do (no phases). */
|
|
67
|
+
readonly to: OverviewPose
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* How to get from one pose to another. Out of a full-size desktop first if the row must move or the
|
|
72
|
+
* overview is the goal (200 ms, ease-out); across if another workspace is to be centred (250 ms,
|
|
73
|
+
* ease-in-out); then in, if the goal is a desktop (200 ms, ease-in). A click on another workspace is
|
|
74
|
+
* all three, about 650 ms. Under reduced motion it is one 120 ms fade in at the goal.
|
|
75
|
+
*/
|
|
76
|
+
export function planZoom(from: OverviewPose, to: OverviewPose, reducedMotion = false): ZoomPlan {
|
|
77
|
+
if (reducedMotion) {
|
|
78
|
+
const phases = [{ name: 'fade' as const, durationMs: ZOOM_FADE_MS, from: { ...to, opacity: 0 }, to: { ...to, opacity: 1 }, ease: straight }]
|
|
79
|
+
return { phases, durationMs: ZOOM_FADE_MS, to }
|
|
80
|
+
}
|
|
81
|
+
const phases: ZoomPhase[] = []
|
|
82
|
+
let at = from
|
|
83
|
+
const go = (name: ZoomPhase['name'], durationMs: number, ease: (t: number) => number, next: OverviewPose) => {
|
|
84
|
+
phases.push({ name, durationMs, from: at, to: next, ease })
|
|
85
|
+
at = next
|
|
86
|
+
}
|
|
87
|
+
const moves = from.centre !== to.centre
|
|
88
|
+
if (at.zoom < 1 && (moves || to.zoom === 1)) go('out', ZOOM_OUT_MS, easeOut, { zoom: 1, centre: at.centre, fog: Math.max(at.fog, to.fog), opacity: 1 })
|
|
89
|
+
if (moves) go('across', ZOOM_ACROSS_MS, easeInOut, { ...at, centre: to.centre })
|
|
90
|
+
if (to.zoom < at.zoom) go('in', ZOOM_IN_MS, easeIn, { ...to, centre: to.centre })
|
|
91
|
+
return { phases, durationMs: phases.reduce((total, p) => total + p.durationMs, 0), to }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const lerp = (a: number, b: number, t: number) => a + (b - a) * t
|
|
95
|
+
|
|
96
|
+
/** Where a plan stands `elapsedMs` after it started: its goal from its duration on. */
|
|
97
|
+
export function poseAt(plan: ZoomPlan, elapsedMs: number): OverviewPose {
|
|
98
|
+
let left = elapsedMs
|
|
99
|
+
for (const phase of plan.phases) {
|
|
100
|
+
if (left < phase.durationMs) {
|
|
101
|
+
const t = phase.ease(left / phase.durationMs)
|
|
102
|
+
return {
|
|
103
|
+
zoom: lerp(phase.from.zoom, phase.to.zoom, t),
|
|
104
|
+
centre: lerp(phase.from.centre, phase.to.centre, t),
|
|
105
|
+
fog: lerp(phase.from.fog, phase.to.fog, t),
|
|
106
|
+
opacity: lerp(phase.from.opacity, phase.to.opacity, t),
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
left -= phase.durationMs
|
|
110
|
+
}
|
|
111
|
+
return plan.phases.at(-1)?.to ?? plan.to
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** One tile as drawn: offsets in px from the desktop area's centre, a scale, and an opacity. */
|
|
115
|
+
export interface TilePlace {
|
|
116
|
+
readonly x: number
|
|
117
|
+
/** Into the screen, under the layer's perspective: negative is further back. */
|
|
118
|
+
readonly z: number
|
|
119
|
+
readonly scale: number
|
|
120
|
+
readonly opacity: number
|
|
121
|
+
/** Paint order: the centred tile on top. */
|
|
122
|
+
readonly layer: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The centred tile's scale in the overview, and how much space is between tiles. */
|
|
126
|
+
export const OVERVIEW_SCALE = 0.62
|
|
127
|
+
const GAP = 1.08
|
|
128
|
+
/** Each step away from the centre: this far back, this much smaller, this much fainter. */
|
|
129
|
+
const STEP_BACK = 80
|
|
130
|
+
const STEP_SCALE = 0.92
|
|
131
|
+
const STEP_OPACITY = 0.85
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Every tile's place at a pose, for a desktop area `width` px wide. At zoom 0 the centred tile fills
|
|
135
|
+
* the area and its neighbours sit just beside it, as in the slide; at 1 the row floats in the fog,
|
|
136
|
+
* neighbours further back, smaller and fainter, and nothing rotates.
|
|
137
|
+
*/
|
|
138
|
+
export function overviewTiles(count: number, pose: OverviewPose, width: number): TilePlace[] {
|
|
139
|
+
const scale = lerp(1, OVERVIEW_SCALE, pose.zoom)
|
|
140
|
+
const pitch = width * lerp(1, OVERVIEW_SCALE * GAP, pose.zoom)
|
|
141
|
+
return Array.from({ length: count }, (_, i) => {
|
|
142
|
+
const away = Math.min(Math.abs(i - pose.centre), 2)
|
|
143
|
+
return {
|
|
144
|
+
x: Math.round((i - pose.centre) * pitch),
|
|
145
|
+
z: -STEP_BACK * away * pose.zoom,
|
|
146
|
+
scale: scale * lerp(1, STEP_SCALE ** away, pose.zoom),
|
|
147
|
+
opacity: lerp(1, STEP_OPACITY ** away, pose.zoom),
|
|
148
|
+
layer: count - Math.round(Math.abs(i - pose.centre)),
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
}
|