@edgestation/sdk 0.4.0 → 0.5.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.
@@ -0,0 +1,11 @@
1
+ import type { WidgetApi } from './api.js';
2
+ import type { Cleanup } from './cleanup.js';
3
+ /** The default export of a widget's entry module. */
4
+ export interface WidgetModule {
5
+ /** Renders the widget into `el`. It can return a cleanup function, or a promise of one. */
6
+ mount(el: HTMLElement, api: WidgetApi): void | Cleanup | Promise<void | Cleanup>;
7
+ }
8
+ /** The props of the root component of a widget in the Svelte, React and Vue adapters. */
9
+ export interface WidgetProps {
10
+ api: WidgetApi;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/types.d.ts CHANGED
@@ -1,401 +1,11 @@
1
- /**
2
- * Contents of a widget's `manifest.json`, as the host hands it to the widget in `api.manifest`.
3
- * `id` is not written in the file: the host sets it to the widget's folder name.
4
- */
5
- export interface WidgetManifest {
6
- id: string;
7
- name: string;
8
- version?: string;
9
- description?: string;
10
- author?: string;
11
- /**
12
- * Oldest EdgeStation version the widget runs on, such as `"0.1.0"`: the one whose `api` it
13
- * uses. Older versions show the widget's error card instead of loading it.
14
- */
15
- minAppVersion?: string;
16
- /** Entry module, relative to the widget folder. Defaults to `main.js`. */
17
- main?: string;
18
- /** Stylesheet loaded into the widget's shadow root. */
19
- styles?: string;
20
- /**
21
- * Image shown next to the widget's name in settings, relative to the widget folder. Only its
22
- * shape counts: it is drawn in the accent color.
23
- */
24
- icon?: string;
25
- /** Default size in grid cells when added to a page. */
26
- size?: {
27
- w: number;
28
- h: number;
29
- };
30
- /** Options the user can set per placement, in display order. */
31
- settings?: WidgetSetting[];
32
- /** Lets the widget call `api.webview`, and gives its settings a Profile choice. */
33
- webview?: boolean;
34
- }
35
- /** One per-placement option, declared in the manifest. */
36
- export type WidgetSetting = SelectSetting | TextSetting;
37
- interface SettingBase {
38
- key: string;
39
- label: string;
40
- /** Only shown (and only meaningful) while every listed setting has the given value. */
41
- when?: Record<string, string>;
42
- }
43
- /** One value out of a list. */
44
- export interface SelectSetting extends SettingBase {
45
- type: 'select';
46
- options: {
47
- value: string;
48
- label: string;
49
- }[];
50
- /**
51
- * Adds the choices of a list EdgeStation reads when the settings show, after `options`. A
52
- * saved value that isn't in the list then (an app that isn't running) stays saved, and the
53
- * widget gets it as it is.
54
- */
55
- source?: SettingSource;
56
- /** Used until the user picks something. Defaults to the first option. */
57
- default?: string;
58
- }
59
- /**
60
- * Lists a select setting can add choices from:
61
- * - `audioApps`: the apps with sound on the default output (`api.audio`), each saved as its
62
- * executable's file name (`AudioApp.program`, such as `Discord.exe`).
63
- */
64
- export type SettingSource = 'audioApps';
65
- /** Free text, such as a URL. */
66
- export interface TextSetting extends SettingBase {
67
- type: 'text';
68
- /** Used until the user types something. Defaults to empty. */
69
- default?: string;
70
- /** Hint shown while the field is empty. */
71
- placeholder?: string;
72
- }
73
- /** Saved setting values of one placement, by key. */
74
- export type WidgetSettingValues = Record<string, string>;
75
- export type Cleanup = () => void;
76
- /**
77
- * What a widget receives from the host. Deliberately small for now: the full API is still
78
- * to be designed. Everything registered here is released when the widget unmounts.
79
- */
80
- export interface WidgetApi {
81
- /** Id of this placement; two copies of a widget get different ids. */
82
- readonly instanceId: string;
83
- readonly manifest: WidgetManifest;
84
- /**
85
- * This placement's settings: every key declared in the manifest, with its default when
86
- * unset. The widget is remounted when the user changes one.
87
- */
88
- readonly settings: Readonly<WidgetSettingValues>;
89
- /** The machine's performance, read when called; nothing is monitored in between. */
90
- system(): Promise<SystemInfo>;
91
- /**
92
- * The programs that used the most CPU since the previous call (from any widget), busiest
93
- * first: at most `count`, fewer when not that many used any. Read when called.
94
- */
95
- topPrograms(count: number): Promise<ProgramUsage[]>;
96
- /** What is playing on the machine, read when called, and its playback controls. */
97
- readonly media: MediaApi;
98
- /** The apps of the Start menu: listed when called, started, and their icons. */
99
- readonly apps: AppsApi;
100
- /**
101
- * The machine's sound as the volume mixer shows it: the default output and microphone, the
102
- * apps playing, their volumes and how loud they are. Read and changed when called.
103
- */
104
- readonly audio: AudioApi;
105
- /**
106
- * The web's `fetch`, sent by the app rather than the Edge page, so CORS doesn't apply: any
107
- * `http` or `https` URL answers as it would answer a server. Headers browsers forbid
108
- * (`Cookie`, `Origin`, `Referer`, ...) can't be set. Cookies that sites set are kept across
109
- * restarts and shared by every widget. A request still unanswered when the widget unmounts
110
- * is cancelled.
111
- */
112
- fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
113
- /**
114
- * Data kept across remounts and restarts, shared by the widget's placements or owned by
115
- * this one. Nothing in it is ever deleted automatically.
116
- */
117
- readonly storage: StorageApi;
118
- /** URL of a file inside the widget folder (images, data, ...). */
119
- asset(path: string): string;
120
- /** Wraps a callback so an error thrown in it shows this widget's error card. */
121
- guard<A extends unknown[]>(fn: (...args: A) => unknown): (...args: A) => void;
122
- /**
123
- * A guarded `setInterval`, cleared when the widget unmounts. It stops while the widget's
124
- * page is off screen or the Edge is frozen (another app is full screen), and ticks right
125
- * away when it resumes. Returns a function that stops it sooner.
126
- */
127
- every(ms: number, fn: () => unknown): Cleanup;
128
- /**
129
- * A guarded `setTimeout`, cleared if the widget unmounts first. It waits while the widget's
130
- * page is off screen, and fires as soon as the page is back if it came due meanwhile.
131
- * Unlike `every`, it still fires while the Edge is frozen. Returns a function that
132
- * cancels it.
133
- */
134
- after(ms: number, fn: () => unknown): Cleanup;
135
- /**
136
- * Shows web page `url` in a native browser view laid over `target`, for sites that refuse
137
- * to load in an iframe. It draws above the Edge, so it hides while pages slide and while
138
- * `target` is not fully on screen: once it has shown, a picture of it lies over `target`
139
- * in its place meanwhile (an `<img>` added to the widget's root). It takes the touches on
140
- * its area. It opens in the
141
- * browser profile picked in the placement's settings (Default unless the user picks
142
- * another): sign-ins last across restarts. Needs `"webview": true` in the manifest, else
143
- * it shows the error card. Closed when the widget unmounts; returns a function that closes
144
- * it sooner.
145
- */
146
- webview(target: HTMLElement, url: string, options?: WebviewOptions): Cleanup;
147
- /**
148
- * Swaps the native scrollbars of `viewport`, an element of the widget that scrolls, for the
149
- * app's overlay ones, which show while it scrolls. They are drawn in its parent, so wrap
150
- * `viewport` in an element of its own: the parent takes the place `viewport` had in the
151
- * layout, and `viewport` fills it. Removed when the widget unmounts; returns a function that
152
- * removes them sooner.
153
- */
154
- scrollbars(viewport: HTMLElement): Cleanup;
155
- /** Runs `fn` when the widget unmounts. */
156
- onDispose(fn: Cleanup): void;
157
- }
158
- /** How `api.webview` opens its page. */
159
- export interface WebviewOptions {
160
- /**
161
- * Presents the view as Chrome on a phone (user agent and client hints), for every page it
162
- * loads, so that sites which pick their layout from the browser serve their mobile one.
163
- * Sites that only follow the width already fit the cell either way.
164
- */
165
- mobile?: boolean;
166
- /**
167
- * Shows a round Home button above the keyboard button, over the view's bottom right corner,
168
- * while it is away from `url`, which takes it back there. The view leaves a hole for it (an
169
- * element added to the widget's root, like the picture). Where `url` redirects to as it loads
170
- * counts as `url`.
171
- */
172
- homeButton?: boolean;
173
- }
174
- /** Where a widget saves data: pick the scope that fits each value. */
175
- export interface StorageApi {
176
- /** Shared by every placement of this widget. */
177
- readonly widget: WidgetStorage;
178
- /** This placement's own; other copies of the widget don't see it. */
179
- readonly instance: WidgetStorage;
180
- }
181
- /** Saved data: JSON values by key, written to disk shortly after each change. */
182
- export interface WidgetStorage {
183
- /** The value saved under `key`; `undefined` when there is none. */
184
- get<T = unknown>(key: string): Promise<T | undefined>;
185
- /** Saves `value` (anything JSON can hold) under `key`, replacing the previous one. */
186
- set(key: string, value: unknown): Promise<void>;
187
- /** Removes `key`. Resolves `true` if it had a value. */
188
- delete(key: string): Promise<boolean>;
189
- }
190
- /** Network throughput in bytes per second. */
191
- export interface NetRate {
192
- down: number;
193
- up: number;
194
- }
195
- /**
196
- * The machine's performance at the time of the call. CPU load and network speeds are
197
- * measured since the previous call (from any widget); calls less than 500 ms apart share
198
- * one reading.
199
- */
200
- export interface SystemInfo {
201
- hostname: string;
202
- /** Name of the connected Wi-Fi network (its Windows profile name); `null` when not connected. */
203
- wifi: string | null;
204
- /** Load of all CPU cores, in percent. */
205
- cpu: {
206
- load: number;
207
- };
208
- /** First NVIDIA GPU (load in percent, temperature in °C); `null` when there is none. */
209
- gpu: {
210
- load: number;
211
- temperature: number;
212
- } | null;
213
- /**
214
- * Since the previous call, plus averages over the calls of the last 1, 5 and 15 minutes:
215
- * the full window while widgets keep asking, less right after they start or resume.
216
- */
217
- net: NetRate & {
218
- avg1m: NetRate;
219
- avg5m: NetRate;
220
- avg15m: NetRate;
221
- };
222
- }
223
- /** A program's CPU use: every process that shows the same name, added together. */
224
- export interface ProgramUsage {
225
- /**
226
- * What Task Manager calls it: its executable's description (`THE FINALS`, `Google Chrome`),
227
- * else the executable file name (`crashpad_handler.exe`).
228
- */
229
- name: string;
230
- /** Percent of all logical processors, like Task Manager. */
231
- cpu: number;
232
- }
233
- export interface MediaApi {
234
- /** The session Windows considers current (the one media keys control); `null` when none. */
235
- current(): Promise<MediaInfo | null>;
236
- /** Album art of the track from the latest `current()` call, as a data URL; `null` when none. */
237
- art(): Promise<string | null>;
238
- /** Asks the current session's app to play, pause or skip. Resolves `false` if it declined. */
239
- control(action: MediaAction): Promise<boolean>;
240
- }
241
- export type MediaAction = 'play' | 'pause' | 'next' | 'previous';
242
- /** A media session as an app publishes it to Windows. Fields the app doesn't set are empty. */
243
- export interface MediaInfo {
244
- /** App that owns the session, as Windows names it (`Spotify.exe`, `MSEdge`, ...). */
245
- app: string;
246
- title: string;
247
- artist: string;
248
- album: string;
249
- playing: boolean;
250
- /**
251
- * Seconds into the track at the time of the call; `null` when the app reports no timeline.
252
- * When the app blanks it out (Zen and Firefox do, about once a minute), it carries on from
253
- * the last one reported, as long as calls come at least every 5 seconds.
254
- */
255
- position: number | null;
256
- duration: number | null;
257
- /** Changes whenever the album art does: call `art()` then. `null` when there is no art. */
258
- art: number | null;
259
- /** Which `control()` actions the app accepts right now. */
260
- can: Record<MediaAction, boolean>;
261
- }
262
- /** The apps of the Start menu's All apps list (the shell's Apps folder). */
263
- export interface AppsApi {
264
- /** Every app, by name, read when called. */
265
- list(): Promise<AppInfo[]>;
266
- /**
267
- * Starts app `id` as the Start menu does, asking for its window on the main screen rather
268
- * than the Edge (apps that remember their position may still open where they were).
269
- * Rejects when the app is gone.
270
- */
271
- launch(id: string): Promise<void>;
272
- /**
273
- * URL of the icon of app `id`, for an `<img>`: a PNG `size` pixels square (16 to 256,
274
- * default 64). Ask for the size it shows at in device pixels: icons drawn larger are sharper.
275
- */
276
- icon(id: string, size?: number): string;
277
- }
278
- /** An app as the Start menu lists it. */
279
- export interface AppInfo {
280
- /**
281
- * Launches it and draws its icon: its name in the shell's Apps folder, the app's
282
- * AppUserModelID or, for a program without one, a path to it. Stays the same across
283
- * restarts, so widgets can save it.
284
- */
285
- id: string;
286
- /** What the Start menu calls it. */
287
- name: string;
288
- }
289
- /** The machine's sound, as Windows' volume mixer shows it. Nothing listens in between calls. */
290
- export interface AudioApi {
291
- /** The default output and microphone, and the apps on that output, read when called. */
292
- mixer(): Promise<AudioMixer>;
293
- /** How loud the default output, the microphone and each app are right now. */
294
- levels(): Promise<AudioLevels>;
295
- /**
296
- * Calls `fn` when the mixer changes: a volume or mute, an app's sound opening, closing,
297
- * starting or stopping, the default device. Read `mixer()` then. Windows tells the app, so
298
- * nothing polls. While the widget's page is off screen or the Edge is frozen it waits, then
299
- * calls `fn` once when the widget shows again. Stops on unmount; returns a function that stops
300
- * it sooner.
301
- */
302
- onChange(fn: () => unknown): Cleanup;
303
- /**
304
- * Calls `fn` with the levels 25 times a second while there is sound, and for two seconds
305
- * after, so meters can fall; then not at all until there is sound again (it shows within a
306
- * quarter of a second). Only while the widget's page shows and the Edge isn't frozen. Stops
307
- * on unmount; returns a function that stops it sooner.
308
- */
309
- onLevels(fn: (levels: AudioLevels) => unknown): Cleanup;
310
- /**
311
- * Sets the volume of `target`, from 0 to 1 (values outside are clamped). Resolves `false`
312
- * when it is gone: the app closed, or there is no such device anymore.
313
- */
314
- setVolume(target: AudioTarget, volume: number): Promise<boolean>;
315
- /**
316
- * Mutes or unmutes `target`, like `setVolume`. Muting `'input'` mutes the default
317
- * microphone and, when it is another device, the default one for calls.
318
- */
319
- setMuted(target: AudioTarget, muted: boolean): Promise<boolean>;
320
- /** The output devices plugged in and enabled, by name, read when called. */
321
- outputs(): Promise<AudioOutput[]>;
322
- /**
323
- * Makes output `id` the default one, as Sound settings' "Set as default device" does: calls
324
- * keep the device picked for them. Resolves `false` when it is no longer plugged in. Windows
325
- * has no public API for this: it uses the one Sound settings uses.
326
- */
327
- setOutput(id: string): Promise<boolean>;
328
- /**
329
- * URL of the icon of an app's executable (`AudioApp.path`), for an `<img>`: a PNG `size`
330
- * pixels square (16 to 256, default 64).
331
- */
332
- icon(path: string, size?: number): string;
333
- }
334
- /** What `setVolume` and `setMuted` change: the default output, the microphone, or an app's `id`. */
335
- export type AudioTarget = 'output' | 'input' | (string & {});
336
- export interface AudioMixer {
337
- /** The default output, the one the volume flyout shows; `null` without one. */
338
- output: AudioDevice | null;
339
- /**
340
- * The default microphone; `null` without one. `muted` is `true` only when the default one
341
- * for calls is muted too.
342
- */
343
- input: AudioDevice | null;
344
- /** The apps with a sound session on the default output, by name, System sounds last. */
345
- apps: AudioApp[];
346
- }
347
- /** A sound device. */
348
- export interface AudioDevice {
349
- /** Windows' id of the device, as `outputs()` lists it. */
350
- id: string;
351
- /** What Sound settings calls it (`Speakers (Realtek(R) Audio)`). */
352
- name: string;
353
- /** From 0 to 1, as the volume flyout shows it. */
354
- volume: number;
355
- muted: boolean;
356
- }
357
- /** An app's sound: every session Windows' volume mixer shows as one. */
358
- export interface AudioApp {
359
- /** Names the app's sound while it runs, for `setVolume` and `levels()`. Not kept across restarts. */
360
- id: string;
361
- /**
362
- * The name the app gives its sound, else what Task Manager calls it (its executable's
363
- * description), else its executable's file name.
364
- */
365
- name: string;
366
- /** Its executable, for `icon()`; `null` for System sounds. */
367
- path: string | null;
368
- /**
369
- * Its executable's file name (`Discord.exe`): it names the app across restarts and updates
370
- * (its folder may change with them), so save this one. `null` for System sounds.
371
- */
372
- program: string | null;
373
- /** From 0 to 1, a share of the output's volume. */
374
- volume: number;
375
- muted: boolean;
376
- /** Playing right now, rather than open and silent. */
377
- active: boolean;
378
- }
379
- /** Peak levels of the last few milliseconds, from 0 to 1. */
380
- export interface AudioLevels {
381
- output: number;
382
- /** The default microphone, while an app records from it; 0 otherwise. */
383
- input: number;
384
- /** By app `id`. */
385
- apps: Record<string, number>;
386
- }
387
- /** An output device `setOutput` can switch to. */
388
- export interface AudioOutput {
389
- id: string;
390
- name: string;
391
- }
392
- /** The default export of a widget's entry module. */
393
- export interface WidgetModule {
394
- /** Render into `el`. May return (or resolve to) a cleanup function. */
395
- mount(el: HTMLElement, api: WidgetApi): void | Cleanup | Promise<void | Cleanup>;
396
- }
397
- /** Props of a widget's root component in the Svelte, React and Vue adapters. */
398
- export interface WidgetProps {
399
- api: WidgetApi;
400
- }
401
- export {};
1
+ export type * from './types/manifest.js';
2
+ export type * from './types/settings.js';
3
+ export type * from './types/cleanup.js';
4
+ export type * from './types/api.js';
5
+ export type * from './types/api/webview.js';
6
+ export type * from './types/api/storage.js';
7
+ export type * from './types/api/system.js';
8
+ export type * from './types/api/media.js';
9
+ export type * from './types/api/apps.js';
10
+ export type * from './types/api/audio.js';
11
+ export type * from './types/widget-module.js';
package/dist/vite.d.ts CHANGED
@@ -1,22 +1,23 @@
1
1
  import type { Plugin } from 'vite';
2
2
  export interface WidgetBuildOptions {
3
3
  /**
4
- * Entry module, relative to the project root. Defaults to the first of `src/main.ts`,
5
- * `src/main.tsx`, `src/main.js` and `src/main.jsx` that exists.
4
+ * The entry module, relative to the project root. The default is the first file that exists
5
+ * of `src/main.ts`, `src/main.tsx`, `src/main.js` and `src/main.jsx`.
6
6
  */
7
7
  entry?: string;
8
8
  }
9
9
  /**
10
- * Builds the widget into what EdgeStation loads: one self-contained ES module,
11
- * `dist/main.js`, with every dependency bundled in (frameworks included), plus `dist/main.css`
12
- * when the code imports CSS. Add your framework's Vite plugin next to it:
10
+ * Builds the widget into what EdgeStation loads: one self-contained ES module, `dist/main.js`,
11
+ * with all dependencies and frameworks in it. If the code imports CSS, it also writes
12
+ * `dist/main.css`. Add the Vite plugin of your framework next to it:
13
13
  *
14
14
  * ```ts
15
15
  * export default defineConfig({ plugins: [react(), widget()] });
16
16
  * ```
17
17
  *
18
- * It also replaces `process.env.NODE_ENV`, which React and Vue read and a browser lacks, and
19
- * warns when `manifest.json` doesn't point at the files it writes, or when the widget's own
20
- * code (not its dependencies) calls `setTimeout` or `setInterval`, which don't pause with it.
18
+ * It also replaces `process.env.NODE_ENV`, because React and Vue read it and a browser does not
19
+ * have it. It warns if `manifest.json` does not point to the files that it writes. It also warns
20
+ * if the code of the widget, not of its dependencies, calls `setTimeout` or `setInterval`,
21
+ * because these timers do not pause with the widget.
21
22
  */
22
23
  export declare function widget(options?: WidgetBuildOptions): Plugin;
package/dist/vite.js CHANGED
@@ -1,10 +1,11 @@
1
- // Loaded by Node from the widget's Vite config: no relative imports, only erasable TypeScript.
1
+ // Node loads this file from the Vite config of the widget. Thus use no relative imports, and
2
+ // only erasable TypeScript.
2
3
  import { existsSync, readFileSync } from 'node:fs';
3
4
  import { join, relative, resolve } from 'node:path';
4
5
  const ENTRIES = ['src/main.ts', 'src/main.tsx', 'src/main.js', 'src/main.jsx'];
5
- /** Forward slashes and no leading `./`, as paths are written in `manifest.json`. */
6
+ /** Writes a path as `manifest.json` does, with forward slashes and no leading `./`. */
6
7
  const normalize = (path) => path.replace(/\\/g, '/').replace(/^\.\//, '');
7
- /** What each global timer does that the `api` one doesn't. */
8
+ /** What each global timer does that the `api` timer does not do. */
8
9
  const TIMERS = {
9
10
  setInterval: "keeps running while the widget's page is off screen or the Edge is frozen, and after " +
10
11
  'the widget unmounts: use api.every instead',
@@ -12,7 +13,7 @@ const TIMERS = {
12
13
  'api.after instead'
13
14
  };
14
15
  const GLOBALS = new Set(['window', 'globalThis', 'self']);
15
- /** A file of the widget's own, by its module id: not a dependency, a virtual module or a query. */
16
+ /** Matches the module id of a file of the widget, not a dependency, a virtual module or a query. */
16
17
  const OWN = /^[^\0?]+\.(?:[cm]?[jt]sx?|svelte|vue)$/;
17
18
  /** The global timer that `callee` names (`setTimeout`, `window.setInterval`, ...), if any. */
18
19
  function timerName(callee) {
@@ -24,7 +25,7 @@ function timerName(callee) {
24
25
  const name = global ? property?.name : callee.type === 'Identifier' ? callee.name : undefined;
25
26
  return name !== undefined && Object.hasOwn(TIMERS, name) ? name : undefined;
26
27
  }
27
- /** The global timers called anywhere in `node`, an ESTree node or a list of them. */
28
+ /** The global timers that the code calls anywhere in `node`, an ESTree node or a list of nodes. */
28
29
  function timersCalled(node, found = new Set()) {
29
30
  if (node && typeof node === 'object') {
30
31
  const { type, callee } = node;
@@ -37,23 +38,24 @@ function timersCalled(node, found = new Set()) {
37
38
  return found;
38
39
  }
39
40
  /**
40
- * Builds the widget into what EdgeStation loads: one self-contained ES module,
41
- * `dist/main.js`, with every dependency bundled in (frameworks included), plus `dist/main.css`
42
- * when the code imports CSS. Add your framework's Vite plugin next to it:
41
+ * Builds the widget into what EdgeStation loads: one self-contained ES module, `dist/main.js`,
42
+ * with all dependencies and frameworks in it. If the code imports CSS, it also writes
43
+ * `dist/main.css`. Add the Vite plugin of your framework next to it:
43
44
  *
44
45
  * ```ts
45
46
  * export default defineConfig({ plugins: [react(), widget()] });
46
47
  * ```
47
48
  *
48
- * It also replaces `process.env.NODE_ENV`, which React and Vue read and a browser lacks, and
49
- * warns when `manifest.json` doesn't point at the files it writes, or when the widget's own
50
- * code (not its dependencies) calls `setTimeout` or `setInterval`, which don't pause with it.
49
+ * It also replaces `process.env.NODE_ENV`, because React and Vue read it and a browser does not
50
+ * have it. It warns if `manifest.json` does not point to the files that it writes. It also warns
51
+ * if the code of the widget, not of its dependencies, calls `setTimeout` or `setInterval`,
52
+ * because these timers do not pause with the widget.
51
53
  */
52
54
  export function widget(options = {}) {
53
55
  let root = process.cwd();
54
56
  let outDir = 'dist';
55
57
  let manifest;
56
- /** Path of a built file as `manifest.json` should name it. */
58
+ /** The path of a built file, as `manifest.json` must name it. */
57
59
  const built = (file) => normalize(relative(root, resolve(root, outDir, file)));
58
60
  return {
59
61
  name: 'edgestation-widget',
@@ -99,8 +101,8 @@ export function widget(options = {}) {
99
101
  `set "main": "${built('main.js')}".`);
100
102
  }
101
103
  },
102
- // Last, so TypeScript, Svelte and Vue files are plain JavaScript by then, whatever the
103
- // plugin order. A dependency's timers are its own business.
104
+ // Run last, so TypeScript, Svelte and Vue files are plain JavaScript at this time, in any
105
+ // plugin order. Do not check dependencies, because their timers are their own concern.
104
106
  transform: {
105
107
  order: 'post',
106
108
  handler(code, id) {
@@ -113,7 +115,7 @@ export function widget(options = {}) {
113
115
  }
114
116
  }
115
117
  },
116
- // Not `generateBundle`: Vite's CSS plugin adds main.css to the bundle after it.
118
+ // Not `generateBundle`, because the Vite CSS plugin adds main.css to the bundle after it.
117
119
  writeBundle(_, bundle) {
118
120
  const css = built('main.css');
119
121
  const styles = typeof manifest?.styles === 'string' ? normalize(manifest.styles) : undefined;
package/dist/vue.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { type Component } from 'vue';
2
2
  import type { WidgetModule } from './types.js';
3
3
  /**
4
- * Makes a widget out of a Vue 3 component: `export default vueWidget(Clock)`. The component is
5
- * mounted as a Vue app on the widget's root with the `api` as its prop
6
- * (`defineProps<WidgetProps>()`), and unmounted with the widget.
4
+ * Makes a widget from a Vue 3 component: `export default vueWidget(Clock)`. The adapter mounts
5
+ * the component as a Vue app on the root of the widget, and unmounts it with the widget. The
6
+ * component gets the `api` as its prop. Declare it with `defineProps<WidgetProps>()`.
7
7
  *
8
- * Errors Vue catches (in rendering, lifecycle hooks, watchers and template event handlers)
9
- * show the widget's error card.
8
+ * The error card of the widget shows the errors that Vue catches. These are errors in render,
9
+ * lifecycle hooks, watchers and template event handlers.
10
10
  */
11
11
  export declare function vueWidget(component: Component): WidgetModule;
package/dist/vue.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { createApp } from 'vue';
2
- import { report } from './report.js';
2
+ import { report } from './report-error.js';
3
3
  /**
4
- * Makes a widget out of a Vue 3 component: `export default vueWidget(Clock)`. The component is
5
- * mounted as a Vue app on the widget's root with the `api` as its prop
6
- * (`defineProps<WidgetProps>()`), and unmounted with the widget.
4
+ * Makes a widget from a Vue 3 component: `export default vueWidget(Clock)`. The adapter mounts
5
+ * the component as a Vue app on the root of the widget, and unmounts it with the widget. The
6
+ * component gets the `api` as its prop. Declare it with `defineProps<WidgetProps>()`.
7
7
  *
8
- * Errors Vue catches (in rendering, lifecycle hooks, watchers and template event handlers)
9
- * show the widget's error card.
8
+ * The error card of the widget shows the errors that Vue catches. These are errors in render,
9
+ * lifecycle hooks, watchers and template event handlers.
10
10
  */
11
11
  export function vueWidget(component) {
12
12
  return {
@@ -43,9 +43,11 @@
43
43
  "h": { "type": "integer", "minimum": 1 }
44
44
  }
45
45
  },
46
- "webview": {
47
- "type": "boolean",
48
- "description": "Lets the widget call api.webview, and gives its settings a Profile choice."
46
+ "permissions": {
47
+ "type": "array",
48
+ "description": "The parts of api the widget uses. The marketplace shows what each one allows before an install. A call to a part not listed here shows the error card. system also gives api.topPrograms. webview also gives the widget's settings a Profile choice.",
49
+ "uniqueItems": true,
50
+ "items": { "enum": ["system", "media", "apps", "audio", "fetch", "webview"] }
49
51
  },
50
52
  "settings": {
51
53
  "type": "array",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgestation/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Types and build helpers to write widgets for EdgeStation, the secondary display dashboard made for the Corsair Xeneon Edge, in plain JavaScript, Svelte, React or Vue.",
5
5
  "keywords": [
6
6
  "edgestation",
package/dist/report.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { WidgetApi } from './types.js';
2
- /** Shows `error` on the widget's error card, as if a guarded callback had thrown it. */
3
- export declare function report(api: WidgetApi, error: unknown): void;
package/dist/report.js DELETED
@@ -1,6 +0,0 @@
1
- /** Shows `error` on the widget's error card, as if a guarded callback had thrown it. */
2
- export function report(api, error) {
3
- api.guard(() => {
4
- throw error;
5
- })();
6
- }