@liberation-data/desk 0.12.0 → 0.15.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 +70 -7
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/look.d.ts +12 -0
- package/dist/core/look.d.ts.map +1 -0
- package/dist/core/look.js +26 -0
- package/dist/core/look.js.map +1 -0
- package/dist/css/controls.css +37 -0
- package/dist/css/dock.css +123 -3
- package/dist/css/looks.css +258 -0
- package/dist/css/tokens.css +8 -1
- package/dist/desk.css +427 -4
- package/dist/fx/fx.d.ts +29 -0
- package/dist/fx/fx.d.ts.map +1 -0
- package/dist/fx/fx.js +119 -0
- package/dist/fx/fx.js.map +1 -0
- package/dist/fx/index.d.ts +7 -0
- package/dist/fx/index.d.ts.map +1 -0
- package/dist/fx/index.js +4 -0
- package/dist/fx/index.js.map +1 -0
- package/dist/fx/measure.d.ts +18 -0
- package/dist/fx/measure.d.ts.map +1 -0
- package/dist/fx/measure.js +37 -0
- package/dist/fx/measure.js.map +1 -0
- package/dist/fx/sounds.d.ts +108 -0
- package/dist/fx/sounds.d.ts.map +1 -0
- package/dist/fx/sounds.js +148 -0
- package/dist/fx/sounds.js.map +1 -0
- package/dist/react/Desktop.d.ts.map +1 -1
- package/dist/react/Desktop.js +44 -9
- package/dist/react/Desktop.js.map +1 -1
- package/dist/react/Dock.d.ts +11 -1
- package/dist/react/Dock.d.ts.map +1 -1
- package/dist/react/Dock.js +4 -3
- package/dist/react/Dock.js.map +1 -1
- package/dist/react/context.d.ts +9 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +15 -3
- package/dist/react/context.js.map +1 -1
- package/dist/react/controls.d.ts +11 -1
- package/dist/react/controls.d.ts.map +1 -1
- package/dist/react/controls.js +2 -2
- package/dist/react/controls.js.map +1 -1
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/shell.d.ts +4 -1
- package/dist/react/shell.d.ts.map +1 -1
- package/dist/react/shell.js +2 -2
- package/dist/react/shell.js.map +1 -1
- package/dist/react/soundsToggle.d.ts +14 -0
- package/dist/react/soundsToggle.d.ts.map +1 -0
- package/dist/react/soundsToggle.js +12 -0
- package/dist/react/soundsToggle.js.map +1 -0
- package/llms.txt +45 -14
- package/package.json +7 -2
- package/src/core/index.ts +2 -0
- package/src/core/look.ts +43 -0
- package/src/css/controls.css +37 -0
- package/src/css/dock.css +123 -3
- package/src/css/looks.css +257 -0
- package/src/css/tokens.css +8 -1
- package/src/fx/fx.ts +145 -0
- package/src/fx/index.ts +6 -0
- package/src/fx/measure.ts +70 -0
- package/src/fx/sounds.ts +213 -0
- package/src/react/Desktop.tsx +97 -29
- package/src/react/Dock.tsx +16 -3
- package/src/react/context.tsx +25 -3
- package/src/react/controls.tsx +12 -2
- package/src/react/index.ts +4 -2
- package/src/react/shell.tsx +5 -2
- package/src/react/soundsToggle.tsx +19 -0
package/src/fx/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createFx } from './fx.js'
|
|
2
|
+
export type { Fx, FxOptions } from './fx.js'
|
|
3
|
+
export { BELL, GROWL, SCORES, scored } from './sounds.js'
|
|
4
|
+
export type { BuiltInSound, Note, Overtone, Score, Sound, Voice } from './sounds.js'
|
|
5
|
+
export { measureLoudness } from './measure.js'
|
|
6
|
+
export type { Loudness, MeasureOptions } from './measure.js'
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How loud a sound is to a listener, measured rather than judged by ear: rendered offline,
|
|
3
|
+
* K-weighted (ITU-R BS.1770: a +4 dB shelf above ~1.7 kHz and a high-pass near 38 Hz, roughly the
|
|
4
|
+
* ear's sensitivity), and scored by its loudest 400 ms — momentary loudness, the right figure for
|
|
5
|
+
* a sound shorter than the gated programme measure. Browser only: it needs OfflineAudioContext.
|
|
6
|
+
*/
|
|
7
|
+
import type { Fx } from './fx.js'
|
|
8
|
+
|
|
9
|
+
export interface Loudness {
|
|
10
|
+
/** Momentary loudness, LUFS. */
|
|
11
|
+
readonly lufs: number
|
|
12
|
+
/** Sample peak before weighting, dBFS: how close it comes to clipping. */
|
|
13
|
+
readonly peakDb: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MeasureOptions {
|
|
17
|
+
/**
|
|
18
|
+
* `laptop` adds a 4th-order high-pass at 200 Hz, about where small speakers give up. Level for
|
|
19
|
+
* that one: it is what most people have.
|
|
20
|
+
*/
|
|
21
|
+
readonly speaker?: 'full' | 'laptop'
|
|
22
|
+
/** Seconds rendered; longer than the sound. */
|
|
23
|
+
readonly seconds?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const RATE = 48000
|
|
27
|
+
|
|
28
|
+
// Web Audio reads a pass filter's Q in dB, not linear.
|
|
29
|
+
const dB = (q: number): number => 20 * Math.log10(q)
|
|
30
|
+
|
|
31
|
+
export async function measureLoudness<Name extends string>(
|
|
32
|
+
fx: Fx<Name>,
|
|
33
|
+
name: Name,
|
|
34
|
+
{ speaker = 'full', seconds = 3 }: MeasureOptions = {},
|
|
35
|
+
): Promise<Loudness> {
|
|
36
|
+
const weighted = new OfflineAudioContext(1, RATE * seconds, RATE)
|
|
37
|
+
const shelf = new BiquadFilterNode(weighted, { type: 'highshelf', frequency: 1682, gain: 4 })
|
|
38
|
+
const rest = [
|
|
39
|
+
new BiquadFilterNode(weighted, { type: 'highpass', frequency: 38, Q: dB(0.5) }),
|
|
40
|
+
...(speaker === 'laptop'
|
|
41
|
+
? [
|
|
42
|
+
new BiquadFilterNode(weighted, { type: 'highpass', frequency: 200, Q: dB(0.541) }),
|
|
43
|
+
new BiquadFilterNode(weighted, { type: 'highpass', frequency: 200, Q: dB(1.307) }),
|
|
44
|
+
]
|
|
45
|
+
: []),
|
|
46
|
+
]
|
|
47
|
+
const last = rest.reduce<AudioNode>((from, to) => (from.connect(to), to), shelf)
|
|
48
|
+
last.connect(weighted.destination)
|
|
49
|
+
fx.render(weighted, name, shelf)
|
|
50
|
+
|
|
51
|
+
const plain = new OfflineAudioContext(1, RATE * seconds, RATE)
|
|
52
|
+
fx.render(plain, name, plain.destination)
|
|
53
|
+
|
|
54
|
+
const [w, p] = await Promise.all([weighted.startRendering(), plain.startRendering()])
|
|
55
|
+
return { lufs: momentary(w.getChannelData(0)), peakDb: 20 * Math.log10(peak(p.getChannelData(0))) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function momentary(x: Float32Array): number {
|
|
59
|
+
const window = RATE * 0.4
|
|
60
|
+
const hop = RATE * 0.1
|
|
61
|
+
const starts = Array.from({ length: Math.max(0, Math.floor((x.length - window) / hop) + 1) }, (_, i) => i * hop)
|
|
62
|
+
const loudest = starts.reduce((best, start) => {
|
|
63
|
+
let sum = 0
|
|
64
|
+
for (let j = start; j < start + window; j++) sum += (x[j] ?? 0) ** 2
|
|
65
|
+
return Math.max(best, sum / window)
|
|
66
|
+
}, 0)
|
|
67
|
+
return -0.691 + 10 * Math.log10(loudest)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const peak = (x: Float32Array): number => x.reduce((m, v) => Math.max(m, Math.abs(v)), 0)
|
package/src/fx/sounds.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The sounds themselves: synthesised, so nothing to fetch, decode or license, and a pitch or a level
|
|
3
|
+
* is a code change.
|
|
4
|
+
*
|
|
5
|
+
* One family, in D major, told apart by contour and register rather than by timbre alone, because
|
|
6
|
+
* people learn a few categories and never a catalogue: attention rises, ready is small and high,
|
|
7
|
+
* failed growls low and sags.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Schedules one sound into `out`, starting at `at` on the context's clock. */
|
|
11
|
+
export type Sound = (ctx: BaseAudioContext, out: AudioNode, at: number) => void
|
|
12
|
+
|
|
13
|
+
export interface Overtone {
|
|
14
|
+
/** Multiple of the note's pitch. */
|
|
15
|
+
readonly ratio: number
|
|
16
|
+
readonly weight: number
|
|
17
|
+
readonly wave: OscillatorType
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Voice {
|
|
21
|
+
readonly partials: readonly Overtone[]
|
|
22
|
+
/** Seconds to swell in: a bell is struck, a horn is blown. */
|
|
23
|
+
readonly attack: number
|
|
24
|
+
/**
|
|
25
|
+
* A low-pass that opens as each note starts and settles back, as multiples of the note's pitch.
|
|
26
|
+
* On a sawtooth this is what makes a horn rather than a buzz. `q` is in dB, as Web Audio reads it.
|
|
27
|
+
*/
|
|
28
|
+
readonly brass?: { readonly closed: number; readonly open: number; readonly settle: number; readonly q: number }
|
|
29
|
+
/** A fast amplitude wobble. Near 20 Hz it is neither pulses nor pitch: a growl. */
|
|
30
|
+
readonly flutter?: { readonly hz: number; readonly depth: number }
|
|
31
|
+
/** Cents the pitch sags over each note. */
|
|
32
|
+
readonly droopCents?: number
|
|
33
|
+
/** A high-pass over the whole sound, in Hz. */
|
|
34
|
+
readonly cutHz?: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Note {
|
|
38
|
+
readonly hz: number
|
|
39
|
+
/** Seconds after the sound starts. */
|
|
40
|
+
readonly at: number
|
|
41
|
+
readonly gain: number
|
|
42
|
+
/** Seconds to decay to silence. */
|
|
43
|
+
readonly ring: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface Score {
|
|
47
|
+
readonly voice: Voice
|
|
48
|
+
readonly notes: readonly Note[]
|
|
49
|
+
/** Trim so sounds are equally loud rather than equally strong. Set by measuring, not by ear. */
|
|
50
|
+
readonly levelDb: number
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The bell: sine partials, with the inharmonic 2.76 a struck bar has and a synth does not. */
|
|
54
|
+
export const BELL: Voice = {
|
|
55
|
+
partials: [
|
|
56
|
+
{ ratio: 1, weight: 1, wave: 'sine' },
|
|
57
|
+
{ ratio: 2, weight: 0.18, wave: 'sine' },
|
|
58
|
+
{ ratio: 2.76, weight: 0.06, wave: 'sine' },
|
|
59
|
+
],
|
|
60
|
+
attack: 0.008,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* The growl: two sawtooths 2% apart beat about one and a half times a second; a quiet third a
|
|
65
|
+
* tritone up (√2) sours it without being heard as a second note; the brass filter snarls.
|
|
66
|
+
*
|
|
67
|
+
* Pitched below what a laptop speaker reproduces, which works because a sawtooth carries every
|
|
68
|
+
* harmonic and the ear supplies the missing fundamental. The cut at 140 Hz is for level matching:
|
|
69
|
+
* below it is energy only headphones play, and left in it made this 10 dB louder on them than on a
|
|
70
|
+
* laptop, so no one trim suited both. Cut, the gap is 3 dB.
|
|
71
|
+
*/
|
|
72
|
+
export const GROWL: Voice = {
|
|
73
|
+
partials: [
|
|
74
|
+
{ ratio: 1, weight: 0.5, wave: 'sine' },
|
|
75
|
+
{ ratio: 1, weight: 0.6, wave: 'sawtooth' },
|
|
76
|
+
{ ratio: 1.02, weight: 0.4, wave: 'sawtooth' },
|
|
77
|
+
{ ratio: Math.SQRT2, weight: 0.16, wave: 'sawtooth' },
|
|
78
|
+
],
|
|
79
|
+
attack: 0.05,
|
|
80
|
+
brass: { closed: 5, open: 20, settle: 9, q: 4.5 },
|
|
81
|
+
flutter: { hz: 22, depth: 0.85 },
|
|
82
|
+
droopCents: 90,
|
|
83
|
+
cutHz: 140,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const D2 = 73.42
|
|
87
|
+
const A4 = 440
|
|
88
|
+
const D5 = 587.33
|
|
89
|
+
const A5 = 880
|
|
90
|
+
const D6 = 1174.66
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Levels put each at -27 LUFS momentary through a 200 Hz high-pass standing in for a laptop speaker,
|
|
94
|
+
* the common case. Failed runs about 3 dB over that on headphones.
|
|
95
|
+
*/
|
|
96
|
+
export const SCORES = {
|
|
97
|
+
/** Something is waiting on this person: a rising fourth, twice. */
|
|
98
|
+
attention: {
|
|
99
|
+
voice: BELL,
|
|
100
|
+
levelDb: -7,
|
|
101
|
+
notes: [
|
|
102
|
+
{ hz: A4, at: 0, gain: 0.32, ring: 0.9 },
|
|
103
|
+
{ hz: D5, at: 0.13, gain: 0.34, ring: 1.3 },
|
|
104
|
+
{ hz: A4, at: 0.55, gain: 0.26, ring: 0.9 },
|
|
105
|
+
{ hz: D5, at: 0.68, gain: 0.28, ring: 1.6 },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
/** Something to look at when they are ready: a grace note up to D6, over almost at once. */
|
|
109
|
+
ready: {
|
|
110
|
+
voice: BELL,
|
|
111
|
+
levelDb: 4,
|
|
112
|
+
notes: [
|
|
113
|
+
{ hz: A5, at: 0, gain: 0.09, ring: 0.35 },
|
|
114
|
+
{ hz: D6, at: 0.06, gain: 0.11, ring: 0.8 },
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
/** Their work did not finish: one low D that growls and sags. */
|
|
118
|
+
failed: {
|
|
119
|
+
voice: GROWL,
|
|
120
|
+
levelDb: 9.5,
|
|
121
|
+
notes: [{ hz: D2, at: 0, gain: 0.33, ring: 1.75 }],
|
|
122
|
+
},
|
|
123
|
+
} as const satisfies Record<string, Score>
|
|
124
|
+
|
|
125
|
+
export type BuiltInSound = keyof typeof SCORES
|
|
126
|
+
|
|
127
|
+
/** A sound from a score: every note of it, through its voice. */
|
|
128
|
+
export function scored(score: Score): Sound {
|
|
129
|
+
return (ctx, out, at) => {
|
|
130
|
+
const level = ctx.createGain()
|
|
131
|
+
level.gain.setValueAtTime(10 ** (score.levelDb / 20), at)
|
|
132
|
+
level.connect(out)
|
|
133
|
+
const { voice } = score
|
|
134
|
+
const bus = voice.cutHz ? highpass(ctx, level, voice.cutHz) : level
|
|
135
|
+
for (const note of score.notes) {
|
|
136
|
+
const t = at + note.at
|
|
137
|
+
const fluttered = voice.flutter ? flutter(ctx, bus, t, note, voice.flutter) : bus
|
|
138
|
+
const into = voice.brass ? brass(ctx, fluttered, t, note, voice.brass, voice.attack) : fluttered
|
|
139
|
+
for (const partial of voice.partials) strike(ctx, into, t, note, partial, voice)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function highpass(ctx: BaseAudioContext, out: AudioNode, hz: number): AudioNode {
|
|
145
|
+
const filter = ctx.createBiquadFilter()
|
|
146
|
+
filter.type = 'highpass'
|
|
147
|
+
filter.frequency.value = hz
|
|
148
|
+
// -3 dB is a linear Q of 0.707: flat, with no bump at the corner.
|
|
149
|
+
filter.Q.value = -3
|
|
150
|
+
filter.connect(out)
|
|
151
|
+
return filter
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function brass(
|
|
155
|
+
ctx: BaseAudioContext,
|
|
156
|
+
out: AudioNode,
|
|
157
|
+
t: number,
|
|
158
|
+
note: Note,
|
|
159
|
+
spec: NonNullable<Voice['brass']>,
|
|
160
|
+
attack: number,
|
|
161
|
+
): AudioNode {
|
|
162
|
+
const filter = ctx.createBiquadFilter()
|
|
163
|
+
filter.type = 'lowpass'
|
|
164
|
+
filter.Q.value = spec.q
|
|
165
|
+
filter.frequency.setValueAtTime(note.hz * spec.closed, t)
|
|
166
|
+
filter.frequency.exponentialRampToValueAtTime(note.hz * spec.open, t + attack + 0.06)
|
|
167
|
+
filter.frequency.exponentialRampToValueAtTime(note.hz * spec.settle, t + note.ring)
|
|
168
|
+
filter.connect(out)
|
|
169
|
+
return filter
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function flutter(
|
|
173
|
+
ctx: BaseAudioContext,
|
|
174
|
+
out: AudioNode,
|
|
175
|
+
t: number,
|
|
176
|
+
note: Note,
|
|
177
|
+
spec: NonNullable<Voice['flutter']>,
|
|
178
|
+
): AudioNode {
|
|
179
|
+
const tremolo = ctx.createGain()
|
|
180
|
+
tremolo.gain.value = 1 - spec.depth / 2
|
|
181
|
+
const lfo = ctx.createOscillator()
|
|
182
|
+
const swing = ctx.createGain()
|
|
183
|
+
lfo.type = 'triangle'
|
|
184
|
+
lfo.frequency.value = spec.hz
|
|
185
|
+
swing.gain.value = spec.depth / 2
|
|
186
|
+
lfo.connect(swing)
|
|
187
|
+
swing.connect(tremolo.gain)
|
|
188
|
+
tremolo.connect(out)
|
|
189
|
+
lfo.start(t)
|
|
190
|
+
lfo.stop(t + note.ring + 0.05)
|
|
191
|
+
return tremolo
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function strike(ctx: BaseAudioContext, out: AudioNode, t: number, note: Note, partial: Overtone, voice: Voice): void {
|
|
195
|
+
// Upper partials die sooner than the fundamental: most of what "bell" means.
|
|
196
|
+
const ring = note.ring / Math.max(partial.ratio, 1) ** 0.5
|
|
197
|
+
const osc = ctx.createOscillator()
|
|
198
|
+
const envelope = ctx.createGain()
|
|
199
|
+
osc.type = partial.wave
|
|
200
|
+
osc.frequency.value = note.hz * partial.ratio
|
|
201
|
+
// A few cents sharp and settling (or sagging): tuning that is perfect from the first millisecond
|
|
202
|
+
// sounds like a test tone.
|
|
203
|
+
osc.detune.setValueAtTime(6, t)
|
|
204
|
+
osc.detune.linearRampToValueAtTime(-(voice.droopCents ?? 0), t + ring)
|
|
205
|
+
// Never from or to zero: an exponential ramp cannot, and a linear edge on a sine clicks.
|
|
206
|
+
envelope.gain.setValueAtTime(0.0001, t)
|
|
207
|
+
envelope.gain.exponentialRampToValueAtTime(note.gain * partial.weight, t + voice.attack)
|
|
208
|
+
envelope.gain.exponentialRampToValueAtTime(0.0001, t + ring)
|
|
209
|
+
osc.connect(envelope)
|
|
210
|
+
envelope.connect(out)
|
|
211
|
+
osc.start(t)
|
|
212
|
+
osc.stop(t + ring + 0.05)
|
|
213
|
+
}
|
package/src/react/Desktop.tsx
CHANGED
|
@@ -3,10 +3,11 @@ import type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from
|
|
|
3
3
|
import { addCommandHandler, addDeskCommands, DeskCommands, STAGE_ATTRIBUTE, WINDOW_ATTRIBUTE, windowElement } from '../core/commands.js'
|
|
4
4
|
import { focusedId, isMinimized, onDesk } from '../core/desk.js'
|
|
5
5
|
import type { Desk } from '../core/desk.js'
|
|
6
|
+
import type { Look } from '../core/look.js'
|
|
6
7
|
import type { DeskWindow, Frame, WindowId, WindowLimits } from '../core/types.js'
|
|
7
8
|
import { arrangement } from './arrange.js'
|
|
8
9
|
import { InfoTip } from './infoTip.js'
|
|
9
|
-
import { useDesk, useDeskState, WindowContext } from './context.js'
|
|
10
|
+
import { useDesk, useDeskState, useLook, WindowContext } from './context.js'
|
|
10
11
|
import { WindowBoundary } from './windowBoundary.js'
|
|
11
12
|
import type { WindowFailed, WindowLoading } from './windowBoundary.js'
|
|
12
13
|
|
|
@@ -229,23 +230,78 @@ const WindowContent = memo(function WindowContent({ id, render, loading, failed
|
|
|
229
230
|
)
|
|
230
231
|
})
|
|
231
232
|
|
|
233
|
+
type ControlGlyph = 'close' | 'minimize' | 'maximize' | 'restore'
|
|
234
|
+
|
|
232
235
|
/*
|
|
233
|
-
* What each
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
+
* What each control does, drawn rather than lettered: a font puts its own cross where it likes, and
|
|
237
|
+
* these are 12px wide. On a Mac the marks come up together when the pointer arrives over the cluster,
|
|
238
|
+
* so a control is never chosen on colour alone, and zoom has one mark whichever way it goes. GNOME
|
|
239
|
+
* and Windows show their marks all the time, and draw maximize and restore differently, as they do.
|
|
236
240
|
*/
|
|
237
|
-
const
|
|
241
|
+
const MAC = {
|
|
238
242
|
close: <path d="M4.1 4.1 7.9 7.9M7.9 4.1 4.1 7.9" />,
|
|
239
243
|
minimize: <path d="M3.6 6h4.8" />,
|
|
240
|
-
|
|
244
|
+
maximize: <path d="M3.8 3.8h2.6L3.8 6.4zM8.2 8.2H5.6L8.2 5.6z" fill="currentColor" stroke="none" />,
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const GLYPHS: Record<Look, Record<ControlGlyph, ReactNode>> = {
|
|
248
|
+
mac: { ...MAC, restore: MAC.maximize },
|
|
249
|
+
gnome: {
|
|
250
|
+
close: <path d="M3.5 3.5 8.5 8.5M8.5 3.5 3.5 8.5" />,
|
|
251
|
+
minimize: <path d="M3.5 8.5h5" />,
|
|
252
|
+
maximize: <path d="M3.5 3.5h5v5h-5z" />,
|
|
253
|
+
restore: <path d="M5 3h4v4M3 5h4v4H3z" />,
|
|
254
|
+
},
|
|
255
|
+
windows: {
|
|
256
|
+
close: <path d="M2.5 2.5 9.5 9.5M9.5 2.5 2.5 9.5" />,
|
|
257
|
+
minimize: <path d="M2 6h8" />,
|
|
258
|
+
maximize: <path d="M2.5 2.5h7v7h-7z" />,
|
|
259
|
+
restore: <path d="M4 2.5h5.5V8M2.5 4H8v5.5H2.5z" />,
|
|
260
|
+
},
|
|
241
261
|
}
|
|
242
262
|
|
|
243
|
-
const Glyph = ({ control }: { readonly
|
|
263
|
+
const Glyph = ({ look, control }: { readonly look: Look; readonly control: ControlGlyph }) => (
|
|
244
264
|
<svg className="desk-control-glyph" viewBox="0 0 12 12" aria-hidden="true">
|
|
245
|
-
{GLYPHS[control]}
|
|
265
|
+
{GLYPHS[look][control]}
|
|
246
266
|
</svg>
|
|
247
267
|
)
|
|
248
268
|
|
|
269
|
+
interface WindowControlsProps {
|
|
270
|
+
readonly look: Look
|
|
271
|
+
readonly layout: DeskLayout
|
|
272
|
+
readonly filled: boolean
|
|
273
|
+
readonly onClose: () => void
|
|
274
|
+
readonly onMinimize: () => void
|
|
275
|
+
readonly onZoom: () => void
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Close, minimize and zoom, in the platform's order and in the document in that order — never
|
|
280
|
+
* reordered by CSS — so Tab walks them the way they read. One window at a time offers only Close.
|
|
281
|
+
*/
|
|
282
|
+
function WindowControls({ look, layout, filled, onClose, onMinimize, onZoom }: WindowControlsProps) {
|
|
283
|
+
const close = (
|
|
284
|
+
<button key="close" type="button" className="desk-control" data-control="close" aria-label="Close" onClick={onClose}>
|
|
285
|
+
<Glyph look={look} control="close" />
|
|
286
|
+
</button>
|
|
287
|
+
)
|
|
288
|
+
if (layout !== 'desktop') return <div className="desk-controls">{close}</div>
|
|
289
|
+
// Off the desk, still open: nothing is unmounted, so nothing inside it is lost.
|
|
290
|
+
const minimize = (
|
|
291
|
+
<button key="minimize" type="button" className="desk-control" data-control="minimize" aria-label="Minimize" onClick={onMinimize}>
|
|
292
|
+
<Glyph look={look} control="minimize" />
|
|
293
|
+
</button>
|
|
294
|
+
)
|
|
295
|
+
// The same act everywhere — fill the desk and back — named and drawn the way each platform does.
|
|
296
|
+
const label = look === 'mac' ? 'Zoom' : filled ? 'Restore' : 'Maximize'
|
|
297
|
+
const zoom = (
|
|
298
|
+
<button key="mode" type="button" className="desk-control" data-control="mode" aria-label={label} onClick={onZoom}>
|
|
299
|
+
<Glyph look={look} control={filled ? 'restore' : 'maximize'} />
|
|
300
|
+
</button>
|
|
301
|
+
)
|
|
302
|
+
return <div className="desk-controls">{look === 'mac' ? [close, minimize, zoom] : [minimize, zoom, close]}</div>
|
|
303
|
+
}
|
|
304
|
+
|
|
249
305
|
interface WindowViewProps {
|
|
250
306
|
readonly window: DeskWindow
|
|
251
307
|
readonly layout: DeskLayout
|
|
@@ -311,6 +367,7 @@ function reshape(gesture: Gesture, origin: Frame, dx: number, dy: number): Frame
|
|
|
311
367
|
|
|
312
368
|
function WindowView({ window, layout, hidden, minimized, depth, focused, title, note, info, actions, limits, children }: WindowViewProps) {
|
|
313
369
|
const desk = useDesk()
|
|
370
|
+
const look = useLook()
|
|
314
371
|
// While dragging, the frame lives here and commits once on release, so a drag
|
|
315
372
|
// re-renders one window rather than notifying every subscriber per pixel.
|
|
316
373
|
const [live, setLive] = useState<Frame | null>(null)
|
|
@@ -382,7 +439,7 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
382
439
|
handle.addEventListener('pointercancel', onUp)
|
|
383
440
|
}
|
|
384
441
|
|
|
385
|
-
// Double-clicking a title bar, or the
|
|
442
|
+
// Double-clicking a title bar, or the zoom control, fills the desk with the window and back.
|
|
386
443
|
const zoom = () => {
|
|
387
444
|
if (layout === 'desktop') desk.toggleMode(window.id)
|
|
388
445
|
}
|
|
@@ -408,6 +465,23 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
408
465
|
? { left: frame.x, top: frame.y, width: frame.width, height: frame.height, zIndex: 10 + depth, ...capped }
|
|
409
466
|
: { zIndex: 10 + depth, ...capped }
|
|
410
467
|
|
|
468
|
+
const controls = (
|
|
469
|
+
<WindowControls
|
|
470
|
+
look={look}
|
|
471
|
+
layout={layout}
|
|
472
|
+
filled={window.mode === 'filled' && !live}
|
|
473
|
+
onClose={() => desk.close(window.id)}
|
|
474
|
+
onMinimize={() => desk.minimize(window.id)}
|
|
475
|
+
onZoom={zoom}
|
|
476
|
+
/>
|
|
477
|
+
)
|
|
478
|
+
const heading = (
|
|
479
|
+
<h2 id={titleId} className="desk-title">
|
|
480
|
+
{title}
|
|
481
|
+
</h2>
|
|
482
|
+
)
|
|
483
|
+
const windowNote = note != null && note !== false && <p className="desk-window-note">{note}</p>
|
|
484
|
+
|
|
411
485
|
return (
|
|
412
486
|
<WindowContext.Provider value={context}>
|
|
413
487
|
<section
|
|
@@ -435,26 +509,19 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
435
509
|
}}
|
|
436
510
|
data-draggable={layout === 'desktop' || undefined}
|
|
437
511
|
>
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
</>
|
|
452
|
-
)}
|
|
453
|
-
</div>
|
|
454
|
-
<h2 id={titleId} className="desk-title">
|
|
455
|
-
{title}
|
|
456
|
-
</h2>
|
|
457
|
-
{note != null && note !== false && <p className="desk-window-note">{note}</p>}
|
|
512
|
+
{look === 'mac' && controls}
|
|
513
|
+
{look === 'gnome' ? (
|
|
514
|
+
// Title and note stacked in the middle of the bar, as a GNOME header bar carries them.
|
|
515
|
+
<div className="desk-titlebar-heading">
|
|
516
|
+
{heading}
|
|
517
|
+
{windowNote}
|
|
518
|
+
</div>
|
|
519
|
+
) : (
|
|
520
|
+
<>
|
|
521
|
+
{heading}
|
|
522
|
+
{windowNote}
|
|
523
|
+
</>
|
|
524
|
+
)}
|
|
458
525
|
{info != null && info !== false && (
|
|
459
526
|
<InfoTip
|
|
460
527
|
className="desk-window-info"
|
|
@@ -465,6 +532,7 @@ function WindowView({ window, layout, hidden, minimized, depth, focused, title,
|
|
|
465
532
|
</InfoTip>
|
|
466
533
|
)}
|
|
467
534
|
{actions && <div className="desk-window-actions">{actions}</div>}
|
|
535
|
+
{look !== 'mac' && controls}
|
|
468
536
|
</header>
|
|
469
537
|
<div className="desk-body">{children}</div>
|
|
470
538
|
{layout === 'desktop' && (
|
package/src/react/Dock.tsx
CHANGED
|
@@ -60,11 +60,22 @@ export const dockItem = (item: DockItem): DockEntry => ({ type: 'item', ...item
|
|
|
60
60
|
export const dockStack = (stack: DockStack): DockEntry => ({ type: 'stack', ...stack })
|
|
61
61
|
export const dockSeparator = (id: string): DockEntry => ({ type: 'separator', id })
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Which edge of the desk the dock stands against. Left by default: a bottom dock takes height from
|
|
65
|
+
* every window, which is what a laptop has least of, and on a Mac it sits on top of the real one.
|
|
66
|
+
*/
|
|
67
|
+
export type DockSide = 'left' | 'right' | 'bottom'
|
|
68
|
+
|
|
63
69
|
export interface DockProps {
|
|
64
70
|
readonly entries: readonly DockEntry[]
|
|
65
71
|
readonly label?: string
|
|
66
72
|
/** `overlay` floats the dock over the bottom of its positioned parent; `inline` leaves layout to you. */
|
|
67
73
|
readonly placement?: 'overlay' | 'inline'
|
|
74
|
+
/**
|
|
75
|
+
* An overlay dock on the left or right stands in a column, and makes its own room: a stage beside
|
|
76
|
+
* it starts where the dock ends, so no window opens underneath it.
|
|
77
|
+
*/
|
|
78
|
+
readonly side?: DockSide
|
|
68
79
|
readonly className?: string
|
|
69
80
|
readonly pins?: DockPins
|
|
70
81
|
}
|
|
@@ -104,7 +115,8 @@ function roveFocus(event: KeyboardEvent<HTMLElement>, keys: { next: string[]; pr
|
|
|
104
115
|
target.focus()
|
|
105
116
|
}
|
|
106
117
|
|
|
107
|
-
export function Dock({ entries, label = 'Dock', placement = 'overlay', className, pins }: DockProps) {
|
|
118
|
+
export function Dock({ entries, label = 'Dock', placement = 'overlay', side = 'left', className, pins }: DockProps) {
|
|
119
|
+
const vertical = side !== 'bottom'
|
|
108
120
|
const [openStack, setOpenStack] = useState<string | null>(null)
|
|
109
121
|
const firstFocusable = entries.find(e => e.type !== 'separator')?.id
|
|
110
122
|
const { dropProps } = useDropTarget({
|
|
@@ -117,13 +129,14 @@ export function Dock({ entries, label = 'Dock', placement = 'overlay', className
|
|
|
117
129
|
<div
|
|
118
130
|
role="toolbar"
|
|
119
131
|
aria-label={label}
|
|
120
|
-
aria-orientation=
|
|
132
|
+
aria-orientation={vertical ? 'vertical' : 'horizontal'}
|
|
121
133
|
className={['desk-dock', className].filter(Boolean).join(' ')}
|
|
122
134
|
data-placement={placement}
|
|
135
|
+
data-side={side}
|
|
123
136
|
{...dropProps}
|
|
124
137
|
onKeyDown={event => {
|
|
125
138
|
if ((event.target as HTMLElement).closest('.desk-stack')) return
|
|
126
|
-
roveFocus(event, { next: ['ArrowRight'], previous: ['ArrowLeft'] })
|
|
139
|
+
roveFocus(event, vertical ? { next: ['ArrowDown'], previous: ['ArrowUp'] } : { next: ['ArrowRight'], previous: ['ArrowLeft'] })
|
|
127
140
|
}}
|
|
128
141
|
>
|
|
129
142
|
{entries.map(entry => {
|
package/src/react/context.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { createContext, useContext, useState, useSyncExternalStore } from 'react'
|
|
1
|
+
import { createContext, useContext, useLayoutEffect, useState, useSyncExternalStore } from 'react'
|
|
2
2
|
import type { ReactNode, RefObject } from 'react'
|
|
3
3
|
import { createBus } from '../core/events.js'
|
|
4
4
|
import type { Bus } from '../core/events.js'
|
|
5
5
|
import { createDesk } from '../core/desk.js'
|
|
6
|
+
import { deviceLook, resolveLook } from '../core/look.js'
|
|
7
|
+
import type { Look, LookChoice } from '../core/look.js'
|
|
6
8
|
import { DragProvider } from './dragContext.js'
|
|
7
9
|
import { missingProvider } from './missingProvider.js'
|
|
8
10
|
import type { Desk } from '../core/desk.js'
|
|
@@ -10,6 +12,8 @@ import type { DeskOptions, DeskState, WindowId } from '../core/types.js'
|
|
|
10
12
|
|
|
11
13
|
const DeskContext = createContext<Desk | null>(null)
|
|
12
14
|
|
|
15
|
+
const LookContext = createContext<Look | null>(null)
|
|
16
|
+
|
|
13
17
|
/** Every desk comes with a bus; <BusProvider> only matters when one has to be shared or supplied. */
|
|
14
18
|
export const BusContext = createContext<Bus | null>(null)
|
|
15
19
|
|
|
@@ -18,21 +22,39 @@ export interface DeskProviderProps {
|
|
|
18
22
|
readonly desk?: Desk
|
|
19
23
|
/** Used to create a desk when none is given. Read once. */
|
|
20
24
|
readonly options?: DeskOptions
|
|
25
|
+
/**
|
|
26
|
+
* The platform chrome: `auto` (the default) matches the device, or the app passes the one its user
|
|
27
|
+
* chose. The app keeps that choice where it keeps its other preferences; the desk does not store it.
|
|
28
|
+
*/
|
|
29
|
+
readonly look?: LookChoice
|
|
21
30
|
readonly children: ReactNode
|
|
22
31
|
}
|
|
23
32
|
|
|
24
|
-
export function DeskProvider({ desk, options, children }: DeskProviderProps) {
|
|
33
|
+
export function DeskProvider({ desk, options, look = 'auto', children }: DeskProviderProps) {
|
|
25
34
|
const [value] = useState(() => desk ?? createDesk(options))
|
|
26
35
|
const [bus] = useState(createBus)
|
|
36
|
+
const resolved = resolveLook(look)
|
|
37
|
+
// On the root, not the desk: menus and popovers are portalled out of it, and are chrome too.
|
|
38
|
+
useLayoutEffect(() => {
|
|
39
|
+
document.documentElement.dataset.look = resolved
|
|
40
|
+
return () => {
|
|
41
|
+
delete document.documentElement.dataset.look
|
|
42
|
+
}
|
|
43
|
+
}, [resolved])
|
|
27
44
|
return (
|
|
28
45
|
<DeskContext.Provider value={value}>
|
|
29
46
|
<BusContext.Provider value={bus}>
|
|
30
|
-
<
|
|
47
|
+
<LookContext.Provider value={resolved}>
|
|
48
|
+
<DragProvider>{children}</DragProvider>
|
|
49
|
+
</LookContext.Provider>
|
|
31
50
|
</BusContext.Provider>
|
|
32
51
|
</DeskContext.Provider>
|
|
33
52
|
)
|
|
34
53
|
}
|
|
35
54
|
|
|
55
|
+
/** The look the desk is wearing, for an app that draws chrome of its own. Outside a desk, the device's. */
|
|
56
|
+
export const useLook = (): Look => useContext(LookContext) ?? deviceLook()
|
|
57
|
+
|
|
36
58
|
/** The desk above, or null outside one: for parts that work on a desk and off one, like a context menu. */
|
|
37
59
|
export const useOptionalDesk = (): Desk | null => useContext(DeskContext)
|
|
38
60
|
|
package/src/react/controls.tsx
CHANGED
|
@@ -53,9 +53,19 @@ export interface SegmentedControlProps<T extends string> {
|
|
|
53
53
|
readonly label: string
|
|
54
54
|
readonly size?: 'regular' | 'small'
|
|
55
55
|
readonly disabled?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* `fit` (the default) sizes each option to its own label, which is right for a control that sits
|
|
58
|
+
* beside other things in a toolbar.
|
|
59
|
+
*
|
|
60
|
+
* `fill` spans the row and gives every option the same width. Use it when the control is the
|
|
61
|
+
* heading of what it governs rather than one item among several: "Direct" and "Via an endpoint"
|
|
62
|
+
* are the same kind of answer, and sizing them by how many letters they happen to have says the
|
|
63
|
+
* short one is the lesser choice.
|
|
64
|
+
*/
|
|
65
|
+
readonly width?: 'fit' | 'fill'
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
export function SegmentedControl<T extends string>({ options, value, onChange, label, size = 'regular', disabled }: SegmentedControlProps<T>) {
|
|
68
|
+
export function SegmentedControl<T extends string>({ options, value, onChange, label, size = 'regular', disabled, width = 'fit' }: SegmentedControlProps<T>) {
|
|
59
69
|
const group = useRef<HTMLDivElement>(null)
|
|
60
70
|
|
|
61
71
|
const move = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
@@ -73,7 +83,7 @@ export function SegmentedControl<T extends string>({ options, value, onChange, l
|
|
|
73
83
|
}
|
|
74
84
|
|
|
75
85
|
return (
|
|
76
|
-
<div ref={group} role="radiogroup" aria-label={label} className="desk-segmented" data-size={size} onKeyDown={move}>
|
|
86
|
+
<div ref={group} role="radiogroup" aria-label={label} className="desk-segmented" data-size={size} data-width={width} onKeyDown={move}>
|
|
77
87
|
{options.map(option => {
|
|
78
88
|
const selected = option.value === value
|
|
79
89
|
return (
|
package/src/react/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type {
|
|
|
13
13
|
} from './dnd.js'
|
|
14
14
|
export { DeskShell } from './shell.js'
|
|
15
15
|
export type { DeskShellProps } from './shell.js'
|
|
16
|
-
export { DeskProvider, useDesk, useDeskState, useWindowId } from './context.js'
|
|
16
|
+
export { DeskProvider, useDesk, useDeskState, useLook, useWindowId } from './context.js'
|
|
17
17
|
export type { DeskProviderProps } from './context.js'
|
|
18
18
|
export { useCanPerform, useCommand, usePerform, useShortcuts } from './commands.js'
|
|
19
19
|
export type { UseCommandOptions } from './commands.js'
|
|
@@ -38,6 +38,8 @@ export type {
|
|
|
38
38
|
TextFieldProps,
|
|
39
39
|
ToggleProps,
|
|
40
40
|
} from './controls.js'
|
|
41
|
+
export { SoundsToggle } from './soundsToggle.js'
|
|
42
|
+
export type { SoundsToggleProps } from './soundsToggle.js'
|
|
41
43
|
export { Loading, Spinner } from './progress.js'
|
|
42
44
|
export type { LoadingProps, SpinnerProps, SpinnerSize } from './progress.js'
|
|
43
45
|
export { Pane, Toolbar } from './pane.js'
|
|
@@ -73,4 +75,4 @@ export type { Menu, MenuBarProps, MenuItem } from './MenuBar.js'
|
|
|
73
75
|
export { IconView } from './iconView.js'
|
|
74
76
|
export type { IconViewItem, IconViewProps } from './iconView.js'
|
|
75
77
|
export { Dock, DOCK_ITEM, dockItem, dockSeparator, dockStack } from './Dock.js'
|
|
76
|
-
export type { DockEntry, DockItem, DockPins, DockProps, DockStack } from './Dock.js'
|
|
78
|
+
export type { DockEntry, DockItem, DockPins, DockProps, DockSide, DockStack } from './Dock.js'
|
package/src/react/shell.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import type { ReactNode } from 'react'
|
|
|
3
3
|
import { createDesk } from '../core/desk.js'
|
|
4
4
|
import type { Desk } from '../core/desk.js'
|
|
5
5
|
import type { Bus } from '../core/events.js'
|
|
6
|
+
import type { LookChoice } from '../core/look.js'
|
|
6
7
|
import type { DeskOptions } from '../core/types.js'
|
|
7
8
|
import { DeskProvider } from './context.js'
|
|
8
9
|
import { BusProvider } from './events.js'
|
|
@@ -16,12 +17,14 @@ export interface DeskShellProps {
|
|
|
16
17
|
readonly bus?: Bus
|
|
17
18
|
/** Leave toasts out when the app does not use them. Default true. */
|
|
18
19
|
readonly toasts?: boolean
|
|
20
|
+
/** The platform chrome: `auto` (the default) matches the device. See `DeskProviderProps.look`. */
|
|
21
|
+
readonly look?: LookChoice
|
|
19
22
|
readonly children: ReactNode
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
/** Everything an app needs around it, in one component: the desk, its bus, and toasts. */
|
|
23
|
-
export function DeskShell({ desk, options, bus, toasts = true, children }: DeskShellProps) {
|
|
26
|
+
export function DeskShell({ desk, options, bus, toasts = true, look = 'auto', children }: DeskShellProps) {
|
|
24
27
|
const [made] = useState(() => desk ?? createDesk(options))
|
|
25
28
|
const inner = toasts ? <ToastProvider>{children}</ToastProvider> : children
|
|
26
|
-
return <DeskProvider desk={made}>{bus ? <BusProvider bus={bus}>{inner}</BusProvider> : inner}</DeskProvider>
|
|
29
|
+
return <DeskProvider desk={made} look={look}>{bus ? <BusProvider bus={bus}>{inner}</BusProvider> : inner}</DeskProvider>
|
|
27
30
|
}
|