effect-atom-svelte-devtools 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +122 -2
- package/dist/atom-devtools.svelte +753 -0
- package/dist/atom-devtools.svelte.d.ts +39 -0
- package/dist/graph/atom-graph.svelte +244 -0
- package/dist/graph/atom-graph.svelte.d.ts +38 -0
- package/dist/graph/frame-graph.svelte +408 -0
- package/dist/graph/frame-graph.svelte.d.ts +52 -0
- package/dist/graph/index.d.ts +5 -0
- package/dist/graph/index.js +7 -0
- package/dist/graph/layout.d.ts +65 -0
- package/dist/graph/layout.js +531 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/internal/format.d.ts +27 -0
- package/dist/internal/format.js +183 -0
- package/dist/internal/graph-view.svelte +134 -0
- package/dist/internal/graph-view.svelte.d.ts +10 -0
- package/dist/internal/label.d.ts +35 -0
- package/dist/internal/label.js +139 -0
- package/dist/internal/model.svelte.d.ts +75 -0
- package/dist/internal/model.svelte.js +286 -0
- package/dist/internal/names.d.ts +29 -0
- package/dist/internal/names.js +55 -0
- package/dist/internal/settings-view.svelte +198 -0
- package/dist/internal/settings-view.svelte.d.ts +16 -0
- package/dist/internal/sheets-view.svelte +453 -0
- package/dist/internal/sheets-view.svelte.d.ts +11 -0
- package/dist/internal/shortcut.d.ts +22 -0
- package/dist/internal/shortcut.js +91 -0
- package/dist/internal/timeline-view.svelte +291 -0
- package/dist/internal/timeline-view.svelte.d.ts +9 -0
- package/dist/internal/transform.d.ts +17 -0
- package/dist/internal/transform.js +401 -0
- package/dist/vite.d.ts +52 -0
- package/dist/vite.js +97 -0
- package/package.json +78 -4
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { preview, valueState } from "./format.js";
|
|
2
|
+
import { identify } from "./names.js";
|
|
3
|
+
/** How long a removed atom stays in the graph, crossed out, before it goes. */
|
|
4
|
+
export const lingerFor = 5000;
|
|
5
|
+
const timelineLength = 3000;
|
|
6
|
+
const removedKept = 300;
|
|
7
|
+
const emptyTotals = {
|
|
8
|
+
atoms: 0,
|
|
9
|
+
builds: 0,
|
|
10
|
+
finalizers: 0,
|
|
11
|
+
interruptions: 0,
|
|
12
|
+
plumbing: 0,
|
|
13
|
+
readers: 0,
|
|
14
|
+
states: {},
|
|
15
|
+
updates: 0,
|
|
16
|
+
};
|
|
17
|
+
const causeText = (cause, nameOf) => {
|
|
18
|
+
switch (cause._tag) {
|
|
19
|
+
case "FirstRead": {
|
|
20
|
+
return "first read";
|
|
21
|
+
}
|
|
22
|
+
case "Refreshed": {
|
|
23
|
+
return "refreshed";
|
|
24
|
+
}
|
|
25
|
+
case "ParentChanged": {
|
|
26
|
+
return `${cause.parents.map(nameOf).join(", ")} changed`;
|
|
27
|
+
}
|
|
28
|
+
default: {
|
|
29
|
+
return "invalidated";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export class Model {
|
|
34
|
+
/** Every atom the registry holds, and those removed a moment ago. */
|
|
35
|
+
atoms = $state.raw([]);
|
|
36
|
+
timeline = $state.raw([]);
|
|
37
|
+
totals = $state.raw(emptyTotals);
|
|
38
|
+
/** No atom has a label: the atomLabels plugin isn't installed. */
|
|
39
|
+
unlabelled = $state(false);
|
|
40
|
+
/** The registry isn't the implementation the inspector knows, so most events are missing. */
|
|
41
|
+
partial = $state(false);
|
|
42
|
+
#inspector;
|
|
43
|
+
#entries = new Map();
|
|
44
|
+
#byAtom = new WeakMap();
|
|
45
|
+
#nextId = 0;
|
|
46
|
+
#log = [];
|
|
47
|
+
#seq = 0;
|
|
48
|
+
#builds = 0;
|
|
49
|
+
#updates = 0;
|
|
50
|
+
#interruptions = 0;
|
|
51
|
+
#finalizers = 0;
|
|
52
|
+
#frame;
|
|
53
|
+
// Set once the model stops: a removal's timer may still fire, and must not schedule a frame.
|
|
54
|
+
#stopped = false;
|
|
55
|
+
#paused = false;
|
|
56
|
+
constructor(inspector) {
|
|
57
|
+
this.#inspector = inspector;
|
|
58
|
+
}
|
|
59
|
+
get registry() {
|
|
60
|
+
return this.#inspector.registry;
|
|
61
|
+
}
|
|
62
|
+
/** Starts following the registry; returns the function that stops. */
|
|
63
|
+
start() {
|
|
64
|
+
for (const node of this.registry.getNodes().values()) {
|
|
65
|
+
const entry = this.#entry(node.atom);
|
|
66
|
+
entry.node = node;
|
|
67
|
+
// A valid node's value is read without computing anything.
|
|
68
|
+
if (node.currentState() === "valid") {
|
|
69
|
+
entry.value = node.value();
|
|
70
|
+
entry.hasValue = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const unsubscribe = this.#inspector.subscribe((event) => this.#receive(event));
|
|
74
|
+
this.#schedule();
|
|
75
|
+
return () => {
|
|
76
|
+
unsubscribe();
|
|
77
|
+
this.#stopped = true;
|
|
78
|
+
if (this.#frame !== undefined) {
|
|
79
|
+
cancelAnimationFrame(this.#frame);
|
|
80
|
+
this.#frame = undefined;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Stops updating the timeline the views see, so it can be read; events are still recorded. */
|
|
85
|
+
set paused(paused) {
|
|
86
|
+
this.#paused = paused;
|
|
87
|
+
this.#schedule();
|
|
88
|
+
}
|
|
89
|
+
get paused() {
|
|
90
|
+
return this.#paused;
|
|
91
|
+
}
|
|
92
|
+
clearTimeline() {
|
|
93
|
+
this.#log = [];
|
|
94
|
+
this.#schedule();
|
|
95
|
+
}
|
|
96
|
+
#entry(atom) {
|
|
97
|
+
let entry = this.#byAtom.get(atom);
|
|
98
|
+
if (entry === undefined) {
|
|
99
|
+
entry = {
|
|
100
|
+
atom,
|
|
101
|
+
builds: 0,
|
|
102
|
+
hasValue: false,
|
|
103
|
+
id: this.#nextId,
|
|
104
|
+
identity: identify(atom),
|
|
105
|
+
interruptedAt: undefined,
|
|
106
|
+
interruptions: 0,
|
|
107
|
+
node: undefined,
|
|
108
|
+
removedAt: undefined,
|
|
109
|
+
updates: 0,
|
|
110
|
+
value: undefined,
|
|
111
|
+
};
|
|
112
|
+
this.#nextId += 1;
|
|
113
|
+
this.#byAtom.set(atom, entry);
|
|
114
|
+
this.#entries.set(entry.id, entry);
|
|
115
|
+
}
|
|
116
|
+
return entry;
|
|
117
|
+
}
|
|
118
|
+
#nameOf = (node) => this.#name(this.#entry(node.atom));
|
|
119
|
+
// Once atoms have labels, one without is plumbing; without the plugin, none has.
|
|
120
|
+
#labelled = false;
|
|
121
|
+
#name(entry) {
|
|
122
|
+
return (entry.identity.name ??
|
|
123
|
+
`${this.#labelled ? "plumbing" : "atom"} #${entry.id}`);
|
|
124
|
+
}
|
|
125
|
+
#receive(event) {
|
|
126
|
+
const entry = this.#entry(event.node.atom);
|
|
127
|
+
let detail = "";
|
|
128
|
+
let related = [];
|
|
129
|
+
let source;
|
|
130
|
+
switch (event._tag) {
|
|
131
|
+
case "NodeAdded": {
|
|
132
|
+
entry.node = event.node;
|
|
133
|
+
entry.removedAt = undefined;
|
|
134
|
+
detail = "added";
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "Built": {
|
|
138
|
+
entry.builds += 1;
|
|
139
|
+
this.#builds += 1;
|
|
140
|
+
detail = causeText(event.cause, this.#nameOf);
|
|
141
|
+
if (event.cause._tag === "ParentChanged") {
|
|
142
|
+
related = event.cause.parents.map((parent) => this.#entry(parent.atom).id);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "Updated": {
|
|
147
|
+
entry.value = event.value;
|
|
148
|
+
entry.hasValue = true;
|
|
149
|
+
entry.updates += 1;
|
|
150
|
+
this.#updates += 1;
|
|
151
|
+
({ source } = event);
|
|
152
|
+
detail = `→ ${preview(event.value, 60)}`;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
case "ReadersChanged": {
|
|
156
|
+
detail = `${event.readers} ${event.readers === 1 ? "reader" : "readers"}`;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "Interrupted": {
|
|
160
|
+
entry.interruptions += 1;
|
|
161
|
+
entry.interruptedAt = event.time;
|
|
162
|
+
this.#interruptions += 1;
|
|
163
|
+
detail = "its effect was interrupted";
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "Finalized": {
|
|
167
|
+
this.#finalizers += event.finalizers;
|
|
168
|
+
detail = `${event.finalizers} ${event.finalizers === 1 ? "finalizer" : "finalizers"} ran`;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
default: {
|
|
172
|
+
entry.node = undefined;
|
|
173
|
+
entry.removedAt = event.time;
|
|
174
|
+
detail = "removed";
|
|
175
|
+
// Again once it has lingered, to take it off the graph.
|
|
176
|
+
setTimeout(() => this.#schedule(), lingerFor + 50);
|
|
177
|
+
this.#prune();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
this.#seq += 1;
|
|
181
|
+
this.#log.push({
|
|
182
|
+
atom: entry.id,
|
|
183
|
+
detail,
|
|
184
|
+
related,
|
|
185
|
+
seq: this.#seq,
|
|
186
|
+
source,
|
|
187
|
+
tag: event._tag,
|
|
188
|
+
time: event.time,
|
|
189
|
+
});
|
|
190
|
+
if (this.#log.length > timelineLength) {
|
|
191
|
+
this.#log.splice(0, this.#log.length - timelineLength);
|
|
192
|
+
}
|
|
193
|
+
this.#schedule();
|
|
194
|
+
}
|
|
195
|
+
/** Forgets the atoms removed longest ago, beyond the last few hundred. */
|
|
196
|
+
#prune() {
|
|
197
|
+
const removed = [...this.#entries.values()].filter((entry) => entry.node === undefined);
|
|
198
|
+
for (const entry of removed.slice(0, Math.max(0, removed.length - removedKept))) {
|
|
199
|
+
this.#entries.delete(entry.id);
|
|
200
|
+
// An atom added again later starts a new entry, which the views see.
|
|
201
|
+
this.#byAtom.delete(entry.atom);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
#schedule() {
|
|
205
|
+
if (this.#stopped) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.#frame ??= requestAnimationFrame(() => {
|
|
209
|
+
this.#frame = undefined;
|
|
210
|
+
this.#publish();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
#publish() {
|
|
214
|
+
const now = performance.now();
|
|
215
|
+
const views = [];
|
|
216
|
+
const states = {};
|
|
217
|
+
let readers = 0;
|
|
218
|
+
let plumbing = 0;
|
|
219
|
+
// An atom can get its label after the panel first sees it, as a cache's atom does when a
|
|
220
|
+
// factory's call returns it later: read it again until it has one.
|
|
221
|
+
for (const entry of this.#entries.values()) {
|
|
222
|
+
if (entry.identity.name === undefined) {
|
|
223
|
+
entry.identity = identify(entry.atom);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const labelled = [...this.#entries.values()].some((entry) => entry.identity.name !== undefined);
|
|
227
|
+
this.#labelled = labelled;
|
|
228
|
+
for (const entry of this.#entries.values()) {
|
|
229
|
+
const { node } = entry;
|
|
230
|
+
const lingering = entry.removedAt !== undefined && now - entry.removedAt < lingerFor;
|
|
231
|
+
// Entries never in the registry since the panel started (a parent's id was taken) are skipped.
|
|
232
|
+
if (node === undefined && !lingering && entry.removedAt === undefined) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const isPlumbing = labelled && entry.identity.name === undefined;
|
|
236
|
+
const state = valueState(entry.value);
|
|
237
|
+
if (node !== undefined) {
|
|
238
|
+
readers += node.listeners.size;
|
|
239
|
+
plumbing += isPlumbing ? 1 : 0;
|
|
240
|
+
const stateKey = state._tag === "Value" ? "Value" : state._tag;
|
|
241
|
+
states[stateKey] = (states[stateKey] ?? 0) + 1;
|
|
242
|
+
}
|
|
243
|
+
views.push({
|
|
244
|
+
atom: entry.atom,
|
|
245
|
+
builds: entry.builds,
|
|
246
|
+
children: node === undefined
|
|
247
|
+
? []
|
|
248
|
+
: [...node.children].map((child) => this.#entry(child.atom).id),
|
|
249
|
+
hasValue: entry.hasValue,
|
|
250
|
+
id: entry.id,
|
|
251
|
+
identity: entry.identity,
|
|
252
|
+
idleTTL: this.#inspector.idleTTL(entry.atom),
|
|
253
|
+
interruptedAt: entry.interruptedAt,
|
|
254
|
+
interruptions: entry.interruptions,
|
|
255
|
+
keepAlive: entry.atom.keepAlive,
|
|
256
|
+
live: node !== undefined,
|
|
257
|
+
name: this.#name(entry),
|
|
258
|
+
parents: node === undefined
|
|
259
|
+
? []
|
|
260
|
+
: [...node.parents].map((parent) => this.#entry(parent.atom).id),
|
|
261
|
+
plumbing: isPlumbing,
|
|
262
|
+
readers: node?.listeners.size ?? 0,
|
|
263
|
+
removedAt: entry.removedAt,
|
|
264
|
+
state,
|
|
265
|
+
updates: entry.updates,
|
|
266
|
+
value: entry.value,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
this.atoms = views;
|
|
270
|
+
this.totals = {
|
|
271
|
+
atoms: views.filter((view) => view.live).length,
|
|
272
|
+
builds: this.#builds,
|
|
273
|
+
finalizers: this.#finalizers,
|
|
274
|
+
interruptions: this.#interruptions,
|
|
275
|
+
plumbing,
|
|
276
|
+
readers,
|
|
277
|
+
states,
|
|
278
|
+
updates: this.#updates,
|
|
279
|
+
};
|
|
280
|
+
if (!this.#paused) {
|
|
281
|
+
this.timeline = [...this.#log];
|
|
282
|
+
}
|
|
283
|
+
this.unlabelled = !labelled && views.length > 0;
|
|
284
|
+
this.partial = !this.#inspector.complete;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Atom } from "effect/reactivity";
|
|
2
|
+
/** Where an atom was declared: a file as the dev server addresses it, and a line and column. */
|
|
3
|
+
export interface Place {
|
|
4
|
+
readonly file: string;
|
|
5
|
+
readonly line: number;
|
|
6
|
+
readonly column: number;
|
|
7
|
+
}
|
|
8
|
+
/** What the panel knows of an atom from the atom itself. */
|
|
9
|
+
export interface Identity {
|
|
10
|
+
/** Its label: the variable's name from the atomLabels plugin, or one the code gave it. */
|
|
11
|
+
readonly name: string | undefined;
|
|
12
|
+
/** Its key, if it is serializable, such as `AtomRpc:listTodos:home-todos`. */
|
|
13
|
+
readonly key: string | undefined;
|
|
14
|
+
readonly place: Place | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The place a stack frame points at. The plugin's frames hold the file as the dev server addresses
|
|
18
|
+
* it; `Atom.withLabel`'s are the browser's, a URL with the dev server's origin and a query.
|
|
19
|
+
*/
|
|
20
|
+
export declare const parseFrame: (frame: string) => Place | undefined;
|
|
21
|
+
export declare const identify: (atom: Atom.Atom<unknown>) => Identity;
|
|
22
|
+
/** The file's name without its folders, for a short reference: `todos.ts:12`. */
|
|
23
|
+
export declare const shortPlace: (place: Place) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Opens the place in the editor, through the dev server's `/__open-in-editor`, which takes a path
|
|
26
|
+
* relative to the project's root or a full one: `/src/a.ts` becomes `src/a.ts`, and
|
|
27
|
+
* `/@fs/home/me/a.ts` or `/@fs/C:/a.ts` the full path after `/@fs`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const openInEditor: (place: Place) => Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// What the panel calls an atom, where it was declared, and whether it is the app's or plumbing.
|
|
2
|
+
import { Atom } from "effect/reactivity";
|
|
3
|
+
// The last `file:line:column` in a stack frame, with or without parentheses around it.
|
|
4
|
+
const framePattern = /(?<file>[^\s()]+):(?<line>\d+):(?<column>\d+)\)?\s*$/u;
|
|
5
|
+
/**
|
|
6
|
+
* The place a stack frame points at. The plugin's frames hold the file as the dev server addresses
|
|
7
|
+
* it; `Atom.withLabel`'s are the browser's, a URL with the dev server's origin and a query.
|
|
8
|
+
*/
|
|
9
|
+
export const parseFrame = (frame) => {
|
|
10
|
+
const groups = framePattern.exec(frame)?.groups;
|
|
11
|
+
if (groups?.file === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
let { file } = groups;
|
|
15
|
+
try {
|
|
16
|
+
file = new URL(file).pathname;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Not a URL: already a path.
|
|
20
|
+
}
|
|
21
|
+
return { column: Number(groups.column), file, line: Number(groups.line) };
|
|
22
|
+
};
|
|
23
|
+
export const identify = (atom) => {
|
|
24
|
+
const key = Atom.isSerializable(atom)
|
|
25
|
+
? atom[Atom.SerializableTypeId].key
|
|
26
|
+
: undefined;
|
|
27
|
+
const [name, frame] = atom.label ?? [];
|
|
28
|
+
return {
|
|
29
|
+
key,
|
|
30
|
+
name,
|
|
31
|
+
place: frame === undefined ? undefined : parseFrame(frame),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/** The file's name without its folders, for a short reference: `todos.ts:12`. */
|
|
35
|
+
export const shortPlace = (place) => `${place.file.split("/").at(-1) ?? place.file}:${place.line}`;
|
|
36
|
+
/**
|
|
37
|
+
* Opens the place in the editor, through the dev server's `/__open-in-editor`, which takes a path
|
|
38
|
+
* relative to the project's root or a full one: `/src/a.ts` becomes `src/a.ts`, and
|
|
39
|
+
* `/@fs/home/me/a.ts` or `/@fs/C:/a.ts` the full path after `/@fs`.
|
|
40
|
+
*/
|
|
41
|
+
export const openInEditor = async (place) => {
|
|
42
|
+
const full = place.file.startsWith("/@fs/")
|
|
43
|
+
? place.file.slice("/@fs".length)
|
|
44
|
+
: undefined;
|
|
45
|
+
let file = place.file.replace(/^\//u, "");
|
|
46
|
+
if (full !== undefined) {
|
|
47
|
+
file = /^\/[a-z]:\//iu.test(full) ? full.slice(1) : full;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
await fetch(`/__open-in-editor?file=${encodeURIComponent(`${file}:${place.line}:${place.column}`)}`);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Not a Vite dev server, or it isn't running: there is no editor to open.
|
|
54
|
+
}
|
|
55
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The panel's settings: the shortcut that opens and closes it, and where the launcher sits, how
|
|
3
|
+
opaque it is and how big. The panel saves them with the rest of its state.
|
|
4
|
+
-->
|
|
5
|
+
<script module lang="ts">
|
|
6
|
+
/** Where the launcher sits. */
|
|
7
|
+
export type Corner = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import {
|
|
12
|
+
formatShortcut,
|
|
13
|
+
parseShortcut,
|
|
14
|
+
shortcutFromEvent,
|
|
15
|
+
stringifyShortcut,
|
|
16
|
+
} from "./shortcut.js";
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
/** The shortcut, as "alt+shift+a". */
|
|
20
|
+
shortcut: string;
|
|
21
|
+
/** The shortcut the app set (`shortcut` prop), which Reset goes back to. */
|
|
22
|
+
readonly defaultShortcut: string;
|
|
23
|
+
corner: Corner;
|
|
24
|
+
/** The launcher's opacity while nothing points at it, from 0.2 to 1. */
|
|
25
|
+
opacity: number;
|
|
26
|
+
/** The launcher's size, from 0.75 to 1.5. */
|
|
27
|
+
scale: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
corner = $bindable(),
|
|
32
|
+
defaultShortcut,
|
|
33
|
+
opacity = $bindable(),
|
|
34
|
+
scale = $bindable(),
|
|
35
|
+
shortcut = $bindable(),
|
|
36
|
+
}: Props = $props();
|
|
37
|
+
|
|
38
|
+
const mac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/u.test(navigator.platform);
|
|
39
|
+
const shown = $derived.by(() => {
|
|
40
|
+
const parsed = parseShortcut(shortcut);
|
|
41
|
+
return parsed === undefined ? "none" : formatShortcut(parsed, mac);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// While recording, the next key press that can be a shortcut becomes it; Escape cancels.
|
|
45
|
+
let recording = $state(false);
|
|
46
|
+
const record = (event: KeyboardEvent) => {
|
|
47
|
+
if (!recording) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
if (event.key === "Escape") {
|
|
53
|
+
recording = false;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const next = shortcutFromEvent(event);
|
|
57
|
+
if (next !== undefined) {
|
|
58
|
+
shortcut = stringifyShortcut(next);
|
|
59
|
+
recording = false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const corners: readonly { readonly id: Corner; readonly label: string }[] = [
|
|
64
|
+
{ id: "top-left", label: "Top left" },
|
|
65
|
+
{ id: "top-right", label: "Top right" },
|
|
66
|
+
{ id: "bottom-left", label: "Bottom left" },
|
|
67
|
+
{ id: "bottom-right", label: "Bottom right" },
|
|
68
|
+
];
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<svelte:window onkeydowncapture={record} />
|
|
72
|
+
|
|
73
|
+
<div class="settings">
|
|
74
|
+
<div class="row">
|
|
75
|
+
<span class="key" id="devtools-shortcut">Shortcut</span>
|
|
76
|
+
<div class="value">
|
|
77
|
+
<kbd aria-labelledby="devtools-shortcut">{recording ? "Press a shortcut…" : shown}</kbd>
|
|
78
|
+
<button aria-pressed={recording} class="tool" onclick={() => (recording = !recording)} type="button">
|
|
79
|
+
{recording ? "Cancel" : "Change"}
|
|
80
|
+
</button>
|
|
81
|
+
<button class="tool" disabled={shortcut === defaultShortcut} onclick={() => (shortcut = defaultShortcut)} type="button">
|
|
82
|
+
Reset
|
|
83
|
+
</button>
|
|
84
|
+
<p class="note">
|
|
85
|
+
Opens and closes the panel anywhere on the page. It needs Ctrl, Alt or {mac ? "⌘" : "Meta"} (or a function key), so it can't catch typing.
|
|
86
|
+
</p>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
<div class="row">
|
|
90
|
+
<span class="key" id="devtools-corner">Button</span>
|
|
91
|
+
<div class="value">
|
|
92
|
+
<div aria-labelledby="devtools-corner" class="corners" role="group">
|
|
93
|
+
{#each corners as item (item.id)}
|
|
94
|
+
<button aria-pressed={corner === item.id} class="tool" onclick={() => (corner = item.id)} type="button">
|
|
95
|
+
{item.label}
|
|
96
|
+
</button>
|
|
97
|
+
{/each}
|
|
98
|
+
</div>
|
|
99
|
+
<p class="note">Or drag the button: it settles in the nearest corner.</p>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
<label class="row">
|
|
103
|
+
<span class="key">Opacity</span>
|
|
104
|
+
<span class="value">
|
|
105
|
+
<input bind:value={opacity} max="1" min="0.2" step="0.05" type="range" />
|
|
106
|
+
<output>{Math.round(opacity * 100)}%</output>
|
|
107
|
+
<span class="note">The button is opaque again while you point at it or focus it.</span>
|
|
108
|
+
</span>
|
|
109
|
+
</label>
|
|
110
|
+
<label class="row">
|
|
111
|
+
<span class="key">Size</span>
|
|
112
|
+
<span class="value">
|
|
113
|
+
<input bind:value={scale} max="1.5" min="0.75" step="0.05" type="range" />
|
|
114
|
+
<output>{Math.round(scale * 100)}%</output>
|
|
115
|
+
</span>
|
|
116
|
+
</label>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<style>
|
|
120
|
+
.settings {
|
|
121
|
+
font-family: var(--mono);
|
|
122
|
+
font-size: 0.74rem;
|
|
123
|
+
height: 100%;
|
|
124
|
+
overflow: auto;
|
|
125
|
+
}
|
|
126
|
+
.row {
|
|
127
|
+
align-items: baseline;
|
|
128
|
+
border-bottom: 1px solid var(--line);
|
|
129
|
+
display: grid;
|
|
130
|
+
gap: 1rem;
|
|
131
|
+
grid-template-columns: 7rem minmax(0, 1fr);
|
|
132
|
+
padding: 0.75rem 0.9rem;
|
|
133
|
+
}
|
|
134
|
+
.key {
|
|
135
|
+
color: var(--muted);
|
|
136
|
+
font-size: 10.5px;
|
|
137
|
+
letter-spacing: 0.08em;
|
|
138
|
+
text-transform: uppercase;
|
|
139
|
+
}
|
|
140
|
+
.value {
|
|
141
|
+
align-items: center;
|
|
142
|
+
display: flex;
|
|
143
|
+
flex-wrap: wrap;
|
|
144
|
+
gap: 0.5rem 0.75rem;
|
|
145
|
+
}
|
|
146
|
+
kbd {
|
|
147
|
+
border: 1px solid var(--line);
|
|
148
|
+
border-radius: 4px;
|
|
149
|
+
color: var(--ink);
|
|
150
|
+
font: inherit;
|
|
151
|
+
min-width: 6rem;
|
|
152
|
+
padding: 0.2rem 0.6rem;
|
|
153
|
+
text-align: center;
|
|
154
|
+
}
|
|
155
|
+
.corners {
|
|
156
|
+
display: flex;
|
|
157
|
+
flex-wrap: wrap;
|
|
158
|
+
gap: 0.4rem;
|
|
159
|
+
}
|
|
160
|
+
.tool {
|
|
161
|
+
background: none;
|
|
162
|
+
border: 1px solid var(--line);
|
|
163
|
+
border-radius: 4px;
|
|
164
|
+
color: var(--ink);
|
|
165
|
+
cursor: pointer;
|
|
166
|
+
font: inherit;
|
|
167
|
+
letter-spacing: 0.04em;
|
|
168
|
+
padding: 0.2rem 0.6rem;
|
|
169
|
+
}
|
|
170
|
+
.tool:hover:not(:disabled) {
|
|
171
|
+
border-color: var(--accent);
|
|
172
|
+
}
|
|
173
|
+
.tool:disabled {
|
|
174
|
+
color: var(--subtle);
|
|
175
|
+
cursor: default;
|
|
176
|
+
}
|
|
177
|
+
.tool[aria-pressed="true"] {
|
|
178
|
+
background: color-mix(in oklab, var(--accent) 12%, transparent);
|
|
179
|
+
border-color: var(--accent);
|
|
180
|
+
}
|
|
181
|
+
input[type="range"] {
|
|
182
|
+
accent-color: var(--accent);
|
|
183
|
+
width: 12rem;
|
|
184
|
+
}
|
|
185
|
+
output {
|
|
186
|
+
color: var(--ink);
|
|
187
|
+
font-variant-numeric: tabular-nums;
|
|
188
|
+
min-width: 3rem;
|
|
189
|
+
}
|
|
190
|
+
.note {
|
|
191
|
+
color: var(--muted);
|
|
192
|
+
flex-basis: 100%;
|
|
193
|
+
font-family: var(--serif);
|
|
194
|
+
font-size: 0.8rem;
|
|
195
|
+
font-style: italic;
|
|
196
|
+
margin: 0;
|
|
197
|
+
}
|
|
198
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Where the launcher sits. */
|
|
2
|
+
export type Corner = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The shortcut, as "alt+shift+a". */
|
|
5
|
+
shortcut: string;
|
|
6
|
+
/** The shortcut the app set (`shortcut` prop), which Reset goes back to. */
|
|
7
|
+
readonly defaultShortcut: string;
|
|
8
|
+
corner: Corner;
|
|
9
|
+
/** The launcher's opacity while nothing points at it, from 0.2 to 1. */
|
|
10
|
+
opacity: number;
|
|
11
|
+
/** The launcher's size, from 0.75 to 1.5. */
|
|
12
|
+
scale: number;
|
|
13
|
+
}
|
|
14
|
+
declare const SettingsView: import("svelte").Component<Props, {}, "corner" | "opacity" | "scale" | "shortcut">;
|
|
15
|
+
type SettingsView = ReturnType<typeof SettingsView>;
|
|
16
|
+
export default SettingsView;
|