@edgestation/sdk 0.2.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.
package/README.md CHANGED
@@ -206,4 +206,4 @@ To share the widget, ship the folder with `manifest.json`, `dist/` and any files
206
206
 
207
207
  ## Types
208
208
 
209
- Everything is exported from `@edgestation/sdk` as types: `WidgetApi`, `WidgetModule`, `WidgetManifest`, `WidgetProps`, the settings types and the results of `api.system()`, `api.media`, `api.apps` and `api.storage`.
209
+ Everything is exported from `@edgestation/sdk` as types: `WidgetApi`, `WidgetModule`, `WidgetManifest`, `WidgetProps`, the settings types and the results of `api.system()`, `api.media`, `api.audio`, `api.apps` and `api.storage`.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { WidgetModule } from './types.js';
2
2
  export type * from './types.js';
3
3
  /**
4
- * Types a widget's default export, so editors know `el` and `api` without annotations, in
5
- * plain JavaScript too:
4
+ * Gives the types to the default export of a widget. Editors then know `el` and `api` without
5
+ * annotations, also in plain JavaScript:
6
6
  *
7
7
  * ```js
8
8
  * export default defineWidget({
@@ -12,6 +12,6 @@ export type * from './types.js';
12
12
  * });
13
13
  * ```
14
14
  *
15
- * Returns `widget` unchanged: the host only needs the object.
15
+ * Returns `widget` with no change. The host only needs the object.
16
16
  */
17
17
  export declare function defineWidget(widget: WidgetModule): WidgetModule;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Types a widget's default export, so editors know `el` and `api` without annotations, in
3
- * plain JavaScript too:
2
+ * Gives the types to the default export of a widget. Editors then know `el` and `api` without
3
+ * annotations, also in plain JavaScript:
4
4
  *
5
5
  * ```js
6
6
  * export default defineWidget({
@@ -10,7 +10,7 @@
10
10
  * });
11
11
  * ```
12
12
  *
13
- * Returns `widget` unchanged: the host only needs the object.
13
+ * Returns `widget` with no change. The host only needs the object.
14
14
  */
15
15
  export function defineWidget(widget) {
16
16
  return widget;
package/dist/react.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { type ComponentType } from 'react';
2
2
  import type { WidgetModule, WidgetProps } from './types.js';
3
3
  /**
4
- * Makes a widget out of a React component: `export default reactWidget(Clock)`. The component
5
- * is rendered in a React root on the widget's root with the `api` as its prop, and the root is
6
- * unmounted with the widget.
4
+ * Makes a widget from a React component: `export default reactWidget(Clock)`. The adapter
5
+ * renders the component in a React root on the root of the widget, with the `api` as its prop.
6
+ * It unmounts the React root when the widget unmounts.
7
7
  *
8
- * With React 19, an error thrown while rendering that no error boundary of yours catches shows
9
- * the widget's error card.
8
+ * With React 19, the widget shows its error card when the component throws an error in render
9
+ * and none of your error boundaries catches it.
10
10
  */
11
11
  export declare function reactWidget(component: ComponentType<WidgetProps>): WidgetModule;
package/dist/react.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { createElement } from 'react';
2
2
  import { createRoot } from 'react-dom/client';
3
- import { report } from './report.js';
3
+ import { report } from './report-error.js';
4
4
  /**
5
- * Makes a widget out of a React component: `export default reactWidget(Clock)`. The component
6
- * is rendered in a React root on the widget's root with the `api` as its prop, and the root is
7
- * unmounted with the widget.
5
+ * Makes a widget from a React component: `export default reactWidget(Clock)`. The adapter
6
+ * renders the component in a React root on the root of the widget, with the `api` as its prop.
7
+ * It unmounts the React root when the widget unmounts.
8
8
  *
9
- * With React 19, an error thrown while rendering that no error boundary of yours catches shows
10
- * the widget's error card.
9
+ * With React 19, the widget shows its error card when the component throws an error in render
10
+ * and none of your error boundaries catches it.
11
11
  */
12
12
  export function reactWidget(component) {
13
13
  return {
@@ -0,0 +1,6 @@
1
+ import type { WidgetApi } from './types.js';
2
+ /**
3
+ * Shows `error` on the error card of the widget. The API has no direct call for this, so a
4
+ * guarded callback throws the error.
5
+ */
6
+ export declare function report(api: WidgetApi, error: unknown): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shows `error` on the error card of the widget. The API has no direct call for this, so a
3
+ * guarded callback throws the error.
4
+ */
5
+ export function report(api, error) {
6
+ api.guard(() => {
7
+ throw error;
8
+ })();
9
+ }
package/dist/svelte.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { type Component } from 'svelte';
2
2
  import type { WidgetModule, WidgetProps } from './types.js';
3
3
  /**
4
- * Makes a widget out of a Svelte 5 component: `export default svelteWidget(Clock)`. The
5
- * component is mounted in the widget's root with the `api` as its prop, and unmounted with
6
- * the widget.
4
+ * Makes a widget from a Svelte 5 component: `export default svelteWidget(Clock)`. The adapter
5
+ * mounts the component in the root of the widget with the `api` as its prop, and unmounts it
6
+ * with the widget.
7
7
  *
8
- * Its `<style>` blocks reach the widget's shadow root when the component is compiled with
9
- * injected CSS (`svelte({ emitCss: false })` in the Vite config). Errors thrown while Svelte
10
- * draws don't show the error card; errors in callbacks wrapped with `api.guard`,
11
- * `api.every` or `api.after` do.
8
+ * The `<style>` blocks of the component get into the shadow root of the widget only if you
9
+ * compile it with injected CSS. For this, use `svelte({ emitCss: false })` in the Vite config.
10
+ * An error that the component throws when Svelte draws it does not show the error card. An
11
+ * error in a callback that `api.guard`, `api.every` or `api.after` wraps shows it.
12
12
  */
13
13
  export declare function svelteWidget(component: Component<WidgetProps>): WidgetModule;
package/dist/svelte.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { mount, unmount } from 'svelte';
2
2
  /**
3
- * Makes a widget out of a Svelte 5 component: `export default svelteWidget(Clock)`. The
4
- * component is mounted in the widget's root with the `api` as its prop, and unmounted with
5
- * the widget.
3
+ * Makes a widget from a Svelte 5 component: `export default svelteWidget(Clock)`. The adapter
4
+ * mounts the component in the root of the widget with the `api` as its prop, and unmounts it
5
+ * with the widget.
6
6
  *
7
- * Its `<style>` blocks reach the widget's shadow root when the component is compiled with
8
- * injected CSS (`svelte({ emitCss: false })` in the Vite config). Errors thrown while Svelte
9
- * draws don't show the error card; errors in callbacks wrapped with `api.guard`,
10
- * `api.every` or `api.after` do.
7
+ * The `<style>` blocks of the component get into the shadow root of the widget only if you
8
+ * compile it with injected CSS. For this, use `svelte({ emitCss: false })` in the Vite config.
9
+ * An error that the component throws when Svelte draws it does not show the error card. An
10
+ * error in a callback that `api.guard`, `api.every` or `api.after` wraps shows it.
11
11
  */
12
12
  export function svelteWidget(component) {
13
13
  return {
@@ -0,0 +1,28 @@
1
+ /** The apps in the All apps list of the Start menu, which is the Apps folder of the shell. */
2
+ export interface AppsApi {
3
+ /** All apps in name order. The host reads them when you call this function. */
4
+ list(): Promise<AppInfo[]>;
5
+ /**
6
+ * Starts the app `id` as the Start menu does. It asks for the app window on the main screen,
7
+ * not on the Edge. An app that keeps its last position can still open there. Rejects if the
8
+ * app is gone.
9
+ */
10
+ launch(id: string): Promise<void>;
11
+ /**
12
+ * The URL of the icon of the app `id`, for an `<img>`. The icon is a square PNG of `size`
13
+ * pixels (16 to 256, default 64). Ask for the size that it shows at, in device pixels. Icons
14
+ * at a larger size are sharper.
15
+ */
16
+ icon(id: string, size?: number): string;
17
+ }
18
+ /** An app as the Start menu lists it. */
19
+ export interface AppInfo {
20
+ /**
21
+ * The value that launches the app and draws its icon. It is the name of the app in the Apps
22
+ * folder of the shell. This is the AppUserModelID of the app or, for a program without one,
23
+ * a path to the program. It stays the same across restarts, so widgets can save it.
24
+ */
25
+ id: string;
26
+ /** The name that the Start menu shows. */
27
+ name: string;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ import type { Cleanup } from '../cleanup.js';
2
+ /**
3
+ * The sound of the machine, as the Windows volume mixer shows it. Nothing listens between
4
+ * calls.
5
+ */
6
+ export interface AudioApi {
7
+ /**
8
+ * The default output and microphone, and the apps on that output. The host reads them when
9
+ * you call this function.
10
+ */
11
+ mixer(): Promise<AudioMixer>;
12
+ /** How loud the default output, the microphone and each app are now. */
13
+ levels(): Promise<AudioLevels>;
14
+ /**
15
+ * Calls `fn` when the mixer changes: a volume, a mute, the default device, or the sound of an
16
+ * app when it opens, closes, starts or stops. Then read `mixer()`. Windows tells the app
17
+ * about changes, so nothing polls. While the page of the widget is off screen or the Edge is
18
+ * frozen, it waits and calls `fn` once when the widget shows again. It stops on unmount, and
19
+ * the returned function stops it earlier.
20
+ */
21
+ onChange(fn: () => unknown): Cleanup;
22
+ /**
23
+ * Calls `fn` with the levels 25 times a second while there is sound, and for two seconds
24
+ * after, so meters can fall. Then it does not call `fn` until there is sound again. New sound
25
+ * shows within a quarter of a second. It calls `fn` only while the page of the widget shows
26
+ * and the Edge is not frozen. It stops on unmount, and the returned function stops it earlier.
27
+ */
28
+ onLevels(fn: (levels: AudioLevels) => unknown): Cleanup;
29
+ /**
30
+ * Sets the volume of `target`, from 0 to 1. It clamps values outside this range. Resolves to
31
+ * `false` if `target` is gone: the app closed, or the device is not there anymore.
32
+ */
33
+ setVolume(target: AudioTarget, volume: number): Promise<boolean>;
34
+ /**
35
+ * Mutes or unmutes `target`, like `setVolume`. For `'input'`, it mutes the default
36
+ * microphone. If the default microphone for calls is a different device, it mutes it too.
37
+ */
38
+ setMuted(target: AudioTarget, muted: boolean): Promise<boolean>;
39
+ /**
40
+ * The output devices that are plugged in and enabled, in name order. The host reads them when
41
+ * you call this function.
42
+ */
43
+ outputs(): Promise<AudioOutput[]>;
44
+ /**
45
+ * Makes the output `id` the default output, as "Set as default device" in Sound settings
46
+ * does. Calls keep the device that the user selected for them. Resolves to `false` if the
47
+ * device is not plugged in anymore. Windows has no public API for this, so it uses the API
48
+ * of Sound settings.
49
+ */
50
+ setOutput(id: string): Promise<boolean>;
51
+ /**
52
+ * The URL of the icon of the executable of an app (`AudioApp.path`), for an `<img>`. The icon
53
+ * is a square PNG of `size` pixels (16 to 256, default 64).
54
+ */
55
+ icon(path: string, size?: number): string;
56
+ }
57
+ /** What `setVolume` and `setMuted` change: the default output, the microphone, or an app `id`. */
58
+ export type AudioTarget = 'output' | 'input' | (string & {});
59
+ export interface AudioMixer {
60
+ /** The default output, which the volume flyout shows. `null` if there is none. */
61
+ output: AudioDevice | null;
62
+ /**
63
+ * The default microphone. `null` if there is none. `muted` is `true` only if the default
64
+ * microphone for calls is also muted.
65
+ */
66
+ input: AudioDevice | null;
67
+ /** The apps with a sound session on the default output, in name order, System sounds last. */
68
+ apps: AudioApp[];
69
+ }
70
+ /** A sound device. */
71
+ export interface AudioDevice {
72
+ /** The Windows id of the device, as `outputs()` lists it. */
73
+ id: string;
74
+ /** The name that Sound settings shows, such as `Speakers (Realtek(R) Audio)`. */
75
+ name: string;
76
+ /** From 0 to 1, as the volume flyout shows it. */
77
+ volume: number;
78
+ muted: boolean;
79
+ }
80
+ /** The sound of an app: all the sessions that the Windows volume mixer shows as one. */
81
+ export interface AudioApp {
82
+ /**
83
+ * Identifies the sound of the app while it runs, for `setVolume` and `levels()`. It does not
84
+ * stay the same across restarts.
85
+ */
86
+ id: string;
87
+ /**
88
+ * The name that the app gives its sound. Else, the name that Task Manager shows, which is the
89
+ * description of its executable. Else, the file name of its executable.
90
+ */
91
+ name: string;
92
+ /** The path of its executable, for `icon()`. `null` for System sounds. */
93
+ path: string | null;
94
+ /**
95
+ * The file name of its executable, such as `Discord.exe`. It identifies the app across
96
+ * restarts and updates, so save this value. The folder of the app can change with them.
97
+ * `null` for System sounds.
98
+ */
99
+ program: string | null;
100
+ /** From 0 to 1, as a part of the output volume. */
101
+ volume: number;
102
+ muted: boolean;
103
+ /** `true` if the app plays sound now, `false` if it is open and silent. */
104
+ active: boolean;
105
+ }
106
+ /** The peak levels of the last few milliseconds, from 0 to 1. */
107
+ export interface AudioLevels {
108
+ output: number;
109
+ /** The default microphone while an app records from it. 0 at other times. */
110
+ input: number;
111
+ /** By app `id`. */
112
+ apps: Record<string, number>;
113
+ }
114
+ /** An output device that `setOutput` can switch to. */
115
+ export interface AudioOutput {
116
+ id: string;
117
+ name: string;
118
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ export interface MediaApi {
2
+ /** The session that Windows thinks is current, which the media keys control. `null` if none. */
3
+ current(): Promise<MediaInfo | null>;
4
+ /** The album art of the track from the last `current()` call, as a data URL. `null` if none. */
5
+ art(): Promise<string | null>;
6
+ /** Asks the app of the current session to play, pause or skip. Resolves `false` if it refused. */
7
+ control(action: MediaAction): Promise<boolean>;
8
+ }
9
+ export type MediaAction = 'play' | 'pause' | 'next' | 'previous';
10
+ /**
11
+ * A media session, as an app publishes it to Windows. The fields that the app does not set are
12
+ * empty.
13
+ */
14
+ export interface MediaInfo {
15
+ /** The app that owns the session, as Windows names it (`Spotify.exe`, `MSEdge`, ...). */
16
+ app: string;
17
+ title: string;
18
+ artist: string;
19
+ album: string;
20
+ playing: boolean;
21
+ /**
22
+ * The position in the track at the time of the call, in seconds. `null` if the app gives no
23
+ * timeline. Some apps clear it, for example Zen and Firefox about once a minute. Then it
24
+ * continues from the last position, if calls come at least every 5 seconds.
25
+ */
26
+ position: number | null;
27
+ duration: number | null;
28
+ /** Changes each time the album art changes. Then call `art()`. `null` if there is no art. */
29
+ art: number | null;
30
+ /** The `control()` actions that the app accepts now. */
31
+ can: Record<MediaAction, boolean>;
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ /** Where a widget saves data. Select the scope that fits each value. */
2
+ export interface StorageApi {
3
+ /** Shared by all placements of this widget. */
4
+ readonly widget: WidgetStorage;
5
+ /** Only for this placement. Other copies of the widget do not see it. */
6
+ readonly instance: WidgetStorage;
7
+ }
8
+ /** Saved data: JSON values by key. The host writes them to disk shortly after each change. */
9
+ export interface WidgetStorage {
10
+ /** The value saved under `key`. `undefined` if there is none. */
11
+ get<T = unknown>(key: string): Promise<T | undefined>;
12
+ /** Saves `value` under `key` and replaces the previous value. JSON must be able to hold it. */
13
+ set(key: string, value: unknown): Promise<void>;
14
+ /** Removes `key`. Resolves `true` if it had a value. */
15
+ delete(key: string): Promise<boolean>;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ /** Network throughput in bytes per second. */
2
+ export interface NetRate {
3
+ down: number;
4
+ up: number;
5
+ }
6
+ /**
7
+ * The performance of the machine at the time of the call. The host measures the CPU load and
8
+ * network speeds since the previous call from any widget. Calls less than 500 ms apart share
9
+ * one reading.
10
+ */
11
+ export interface SystemInfo {
12
+ hostname: string;
13
+ /** The name of the connected Wi-Fi network (its Windows profile name). `null` if none. */
14
+ wifi: string | null;
15
+ /** The load of all CPU cores, in percent. */
16
+ cpu: {
17
+ load: number;
18
+ };
19
+ /** The first NVIDIA GPU (load in percent, temperature in °C). `null` if there is none. */
20
+ gpu: {
21
+ load: number;
22
+ temperature: number;
23
+ } | null;
24
+ /**
25
+ * The rate since the previous call, and the averages over the calls of the last 1, 5 and 15
26
+ * minutes. An average covers its full period while widgets continue to ask. It covers less
27
+ * time just after they start or resume.
28
+ */
29
+ net: NetRate & {
30
+ avg1m: NetRate;
31
+ avg5m: NetRate;
32
+ avg15m: NetRate;
33
+ };
34
+ }
35
+ /** The CPU use of a program: the sum of all processes that show the same name. */
36
+ export interface ProgramUsage {
37
+ /**
38
+ * The name that Task Manager shows. This is the description of its executable (`THE FINALS`,
39
+ * `Google Chrome`), else the executable file name (`crashpad_handler.exe`).
40
+ */
41
+ name: string;
42
+ /** The percent of all logical processors, as in Task Manager. */
43
+ cpu: number;
44
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ /** How `api.webview` opens its page. */
2
+ export interface WebviewOptions {
3
+ /**
4
+ * Shows the view to sites as Chrome on a phone, with the user agent and client hints. This
5
+ * applies to each page that the view loads. Sites that select their layout from the browser
6
+ * then serve their mobile layout. Sites that only follow the width fit the cell in both cases.
7
+ */
8
+ mobile?: boolean;
9
+ /**
10
+ * Shows a round Home button over the bottom right corner of the view, above the keyboard
11
+ * button. The button shows while the view is away from `url`, and takes the view back there.
12
+ * The view leaves a hole for it, because the button is an element in the root of the widget,
13
+ * like the picture. A page that `url` redirects to when it loads counts as `url`.
14
+ */
15
+ homeButton?: boolean;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,116 @@
1
+ import type { AppsApi } from './api/apps.js';
2
+ import type { AudioApi } from './api/audio.js';
3
+ import type { MediaApi } from './api/media.js';
4
+ import type { StorageApi } from './api/storage.js';
5
+ import type { ProgramUsage, SystemInfo } from './api/system.js';
6
+ import type { WebviewOptions } from './api/webview.js';
7
+ import type { Cleanup } from './cleanup.js';
8
+ import type { WidgetManifest } from './manifest.js';
9
+ import type { WidgetSettingValues } from './settings.js';
10
+ /**
11
+ * What a widget gets from the host. It is small on purpose, because the full API is not
12
+ * designed yet. When the widget unmounts, the host releases all that the widget registered here.
13
+ * The members marked "Needs" work only if the `permissions` of the manifest list that
14
+ * permission. Else a call shows the error card and throws.
15
+ */
16
+ export interface WidgetApi {
17
+ /** The id of this placement. Two copies of a widget get different ids. */
18
+ readonly instanceId: string;
19
+ readonly manifest: WidgetManifest;
20
+ /**
21
+ * The settings of this placement. It has each key that the manifest declares, with its
22
+ * default if the user did not set it. The host mounts the widget again when the user
23
+ * changes a setting.
24
+ */
25
+ readonly settings: Readonly<WidgetSettingValues>;
26
+ /**
27
+ * The performance of the machine, read when you call it. Nothing monitors between calls.
28
+ * Needs `system`.
29
+ */
30
+ system(): Promise<SystemInfo>;
31
+ /**
32
+ * The programs that used the most CPU since the previous call from any widget, busiest
33
+ * first. It gives `count` programs at most, or fewer if fewer programs used the CPU. The
34
+ * host reads them when you call it. Needs `system`.
35
+ */
36
+ topPrograms(count: number): Promise<ProgramUsage[]>;
37
+ /**
38
+ * The media that plays on the machine, read when you call it, and its playback controls.
39
+ * Needs `media`.
40
+ */
41
+ readonly media: MediaApi;
42
+ /**
43
+ * The apps of the Start menu. It lists them when you call it, starts them and gives their
44
+ * icons. Needs `apps`.
45
+ */
46
+ readonly apps: AppsApi;
47
+ /**
48
+ * The sound of the machine, as the volume mixer shows it. This is the default output and
49
+ * microphone, the apps that play sound, their volumes and how loud they are. The host reads
50
+ * and changes these values when you call it. Needs `audio`.
51
+ */
52
+ readonly audio: AudioApi;
53
+ /**
54
+ * The web `fetch`, but the app sends the request, not the Edge page. Thus CORS does not
55
+ * apply, and any `http` or `https` URL answers as it would answer a server. You cannot set
56
+ * the headers that browsers forbid (`Cookie`, `Origin`, `Referer`, ...). The app keeps the
57
+ * cookies that sites set across restarts, and all widgets share them. If a request has no
58
+ * answer when the widget unmounts, the app cancels it. Needs `fetch`.
59
+ */
60
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
61
+ /**
62
+ * Data that stays across remounts and restarts. All placements of the widget share it, or
63
+ * this placement owns it. The host never deletes data in it automatically.
64
+ */
65
+ readonly storage: StorageApi;
66
+ /** The URL of a file in the widget folder (images, data, ...). */
67
+ asset(path: string): string;
68
+ /** Wraps a callback. If the callback throws an error, the error card of this widget shows it. */
69
+ guard<A extends unknown[]>(fn: (...args: A) => unknown): (...args: A) => void;
70
+ /**
71
+ * Tells the host that the widget loads data until `task` settles, and returns `task`. Until
72
+ * the first load ends, three dots show in the middle of the card and the widget stays hidden.
73
+ * Then the widget fades in. Each later load shows a bar at the top of the card. Loads that
74
+ * run at the same time show one indicator. Put all of the first load in one call, else the
75
+ * widget shows before it is ready. The page loads of `webview` count as loads too.
76
+ */
77
+ loading<T>(task: Promise<T>): Promise<T>;
78
+ /**
79
+ * A guarded `setInterval` that the host clears when the widget unmounts. It stops while the
80
+ * page of the widget is off screen or the Edge is frozen. The Edge is frozen when another
81
+ * app is full screen. When it starts again, it ticks immediately. Returns a function that
82
+ * stops it earlier.
83
+ */
84
+ every(ms: number, fn: () => unknown): Cleanup;
85
+ /**
86
+ * A guarded `setTimeout` that the host clears if the widget unmounts first. It waits while
87
+ * the page of the widget is off screen. If its time came in that period, it fires when the
88
+ * page is back. Unlike `every`, it still fires while the Edge is frozen. Returns a function
89
+ * that cancels it.
90
+ */
91
+ after(ms: number, fn: () => unknown): Cleanup;
92
+ /**
93
+ * Shows the web page `url` in a native browser view that lies over `target` and gets the
94
+ * touches there, for sites that refuse an iframe. The view is above the Edge, so it hides
95
+ * while pages slide and while `target` is not fully on screen. At these times, after its
96
+ * first show, a picture of it covers `target` (an `<img>` in the root of the widget). Its page
97
+ * loads show on the card as `loading` shows them. It opens the first time `target` is fully on
98
+ * screen, so a view on a page that nobody visits costs nothing. It stays hidden until its
99
+ * first page loads, so the dots show in place of a blank page. It uses the browser profile
100
+ * from the placement settings, Default if the user selects no other, and sign-ins in it stay
101
+ * across restarts. Needs `webview`. The host closes it when the widget unmounts, and the
102
+ * returned function closes it earlier.
103
+ */
104
+ webview(target: HTMLElement, url: string, options?: WebviewOptions): Cleanup;
105
+ /**
106
+ * Replaces the native scrollbars of `viewport` with the overlay scrollbars of the app.
107
+ * `viewport` is an element of the widget that scrolls, and the overlay scrollbars show while
108
+ * it scrolls. The app draws them in the parent of `viewport`, so put `viewport` in an element
109
+ * of its own. This parent takes the place of `viewport` in the layout, and `viewport` fills
110
+ * it. The host removes them when the widget unmounts, and the returned function removes them
111
+ * earlier.
112
+ */
113
+ scrollbars(viewport: HTMLElement): Cleanup;
114
+ /** Runs `fn` when the widget unmounts. */
115
+ onDispose(fn: Cleanup): void;
116
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type Cleanup = () => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import type { WidgetSetting } from './settings.js';
2
+ /**
3
+ * A part of `api` that a widget must ask for in `permissions`. `system` also gives
4
+ * `topPrograms`. The other members of `api` need no permission.
5
+ */
6
+ export type WidgetPermission = 'system' | 'media' | 'apps' | 'audio' | 'fetch' | 'webview';
7
+ /**
8
+ * The contents of the `manifest.json` of a widget, as the host gives it to the widget in
9
+ * `api.manifest`. The file does not contain `id`. The host sets `id` to the folder name of the
10
+ * widget.
11
+ */
12
+ export interface WidgetManifest {
13
+ id: string;
14
+ name: string;
15
+ version?: string;
16
+ description?: string;
17
+ author?: string;
18
+ /**
19
+ * The oldest EdgeStation version that the widget runs on, such as `"0.1.0"`. This is the
20
+ * version whose `api` the widget uses. Older versions show the error card of the widget and
21
+ * do not load it.
22
+ */
23
+ minAppVersion?: string;
24
+ /** The entry module, relative to the widget folder. The default is `main.js`. */
25
+ main?: string;
26
+ /** A stylesheet that the host loads into the shadow root of the widget. */
27
+ styles?: string;
28
+ /**
29
+ * An image that settings show next to the name of the widget, relative to the widget folder.
30
+ * Only its shape is important, because the host draws it in the accent color.
31
+ */
32
+ icon?: string;
33
+ /** The default size in grid cells when the user adds the widget to a page. */
34
+ size?: {
35
+ w: number;
36
+ h: number;
37
+ };
38
+ /** The options that the user can set for each placement, in display order. */
39
+ settings?: WidgetSetting[];
40
+ /**
41
+ * The parts of `api` that the widget uses. The marketplace tells the user what each one lets
42
+ * the widget do before the install, and before an update that adds one. A call to a part that
43
+ * is not in this list shows the error card and throws. `webview` also adds a Profile choice to
44
+ * the settings of the widget.
45
+ */
46
+ permissions?: WidgetPermission[];
47
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ /** An option with a value for each placement. The manifest declares it. */
2
+ export type WidgetSetting = SelectSetting | TextSetting;
3
+ interface SettingBase {
4
+ key: string;
5
+ label: string;
6
+ /**
7
+ * The setting shows only while each setting in this list has the given value. At other
8
+ * times, its value has no meaning.
9
+ */
10
+ when?: Record<string, string>;
11
+ }
12
+ /** A setting with one value from a list. */
13
+ export interface SelectSetting extends SettingBase {
14
+ type: 'select';
15
+ options: {
16
+ value: string;
17
+ label: string;
18
+ }[];
19
+ /**
20
+ * Adds the choices of a list after `options`. EdgeStation reads this list when the settings
21
+ * show. A saved value can be missing from the list, for example an app that does not run.
22
+ * This value stays saved, and the widget gets it as it is.
23
+ */
24
+ source?: SettingSource;
25
+ /** The value until the user selects an option. If you do not set it, it is the first option. */
26
+ default?: string;
27
+ }
28
+ /**
29
+ * The lists that a select setting can add choices from:
30
+ * - `audioApps`: the apps with sound on the default output (`api.audio`). The setting saves
31
+ * each app as the file name of its executable (`AudioApp.program`, such as `Discord.exe`).
32
+ */
33
+ export type SettingSource = 'audioApps';
34
+ /** Free text, such as a URL. */
35
+ export interface TextSetting extends SettingBase {
36
+ type: 'text';
37
+ /** The value until the user types something. If you do not set it, the value is empty. */
38
+ default?: string;
39
+ /** A hint that shows while the field is empty. */
40
+ placeholder?: string;
41
+ }
42
+ /** The saved setting values of one placement, by key. */
43
+ export type WidgetSettingValues = Record<string, string>;
44
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -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,280 +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
- /** Used until the user picks something. Defaults to the first option. */
51
- default?: string;
52
- }
53
- /** Free text, such as a URL. */
54
- export interface TextSetting extends SettingBase {
55
- type: 'text';
56
- /** Used until the user types something. Defaults to empty. */
57
- default?: string;
58
- /** Hint shown while the field is empty. */
59
- placeholder?: string;
60
- }
61
- /** Saved setting values of one placement, by key. */
62
- export type WidgetSettingValues = Record<string, string>;
63
- export type Cleanup = () => void;
64
- /**
65
- * What a widget receives from the host. Deliberately small for now: the full API is still
66
- * to be designed. Everything registered here is released when the widget unmounts.
67
- */
68
- export interface WidgetApi {
69
- /** Id of this placement; two copies of a widget get different ids. */
70
- readonly instanceId: string;
71
- readonly manifest: WidgetManifest;
72
- /**
73
- * This placement's settings: every key declared in the manifest, with its default when
74
- * unset. The widget is remounted when the user changes one.
75
- */
76
- readonly settings: Readonly<WidgetSettingValues>;
77
- /** The machine's performance, read when called; nothing is monitored in between. */
78
- system(): Promise<SystemInfo>;
79
- /**
80
- * The programs that used the most CPU since the previous call (from any widget), busiest
81
- * first: at most `count`, fewer when not that many used any. Read when called.
82
- */
83
- topPrograms(count: number): Promise<ProgramUsage[]>;
84
- /** What is playing on the machine, read when called, and its playback controls. */
85
- readonly media: MediaApi;
86
- /** The apps of the Start menu: listed when called, started, and their icons. */
87
- readonly apps: AppsApi;
88
- /**
89
- * The web's `fetch`, sent by the app rather than the Edge page, so CORS doesn't apply: any
90
- * `http` or `https` URL answers as it would answer a server. Headers browsers forbid
91
- * (`Cookie`, `Origin`, `Referer`, ...) can't be set. Cookies that sites set are kept across
92
- * restarts and shared by every widget. A request still unanswered when the widget unmounts
93
- * is cancelled.
94
- */
95
- fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
96
- /**
97
- * Data kept across remounts and restarts, shared by the widget's placements or owned by
98
- * this one. Nothing in it is ever deleted automatically.
99
- */
100
- readonly storage: StorageApi;
101
- /** URL of a file inside the widget folder (images, data, ...). */
102
- asset(path: string): string;
103
- /** Wraps a callback so an error thrown in it shows this widget's error card. */
104
- guard<A extends unknown[]>(fn: (...args: A) => unknown): (...args: A) => void;
105
- /**
106
- * A guarded `setInterval`, cleared when the widget unmounts. It stops while the widget's
107
- * page is off screen or the Edge is frozen (another app is full screen), and ticks right
108
- * away when it resumes. Returns a function that stops it sooner.
109
- */
110
- every(ms: number, fn: () => unknown): Cleanup;
111
- /**
112
- * A guarded `setTimeout`, cleared if the widget unmounts first. It waits while the widget's
113
- * page is off screen, and fires as soon as the page is back if it came due meanwhile.
114
- * Unlike `every`, it still fires while the Edge is frozen. Returns a function that
115
- * cancels it.
116
- */
117
- after(ms: number, fn: () => unknown): Cleanup;
118
- /**
119
- * Shows web page `url` in a native browser view laid over `target`, for sites that refuse
120
- * to load in an iframe. It draws above the Edge, so it hides while pages slide and while
121
- * `target` is not fully on screen: once it has shown, a picture of it lies over `target`
122
- * in its place meanwhile (an `<img>` added to the widget's root). It takes the touches on
123
- * its area. It opens in the
124
- * browser profile picked in the placement's settings (Default unless the user picks
125
- * another): sign-ins last across restarts. Needs `"webview": true` in the manifest, else
126
- * it shows the error card. Closed when the widget unmounts; returns a function that closes
127
- * it sooner.
128
- */
129
- webview(target: HTMLElement, url: string, options?: WebviewOptions): Cleanup;
130
- /**
131
- * Swaps the native scrollbars of `viewport`, an element of the widget that scrolls, for the
132
- * app's overlay ones, which show while it scrolls. They are drawn in its parent, so wrap
133
- * `viewport` in an element of its own: the parent takes the place `viewport` had in the
134
- * layout, and `viewport` fills it. Removed when the widget unmounts; returns a function that
135
- * removes them sooner.
136
- */
137
- scrollbars(viewport: HTMLElement): Cleanup;
138
- /** Runs `fn` when the widget unmounts. */
139
- onDispose(fn: Cleanup): void;
140
- }
141
- /** How `api.webview` opens its page. */
142
- export interface WebviewOptions {
143
- /**
144
- * Presents the view as Chrome on a phone (user agent and client hints), for every page it
145
- * loads, so that sites which pick their layout from the browser serve their mobile one.
146
- * Sites that only follow the width already fit the cell either way.
147
- */
148
- mobile?: boolean;
149
- /**
150
- * Shows a Home button in the view's top right corner while it is away from `url`, which
151
- * takes it back there. The view leaves that corner to the button (an element added to the
152
- * widget's root, like the picture). Where `url` redirects to as it loads counts as `url`.
153
- */
154
- homeButton?: boolean;
155
- }
156
- /** Where a widget saves data: pick the scope that fits each value. */
157
- export interface StorageApi {
158
- /** Shared by every placement of this widget. */
159
- readonly widget: WidgetStorage;
160
- /** This placement's own; other copies of the widget don't see it. */
161
- readonly instance: WidgetStorage;
162
- }
163
- /** Saved data: JSON values by key, written to disk shortly after each change. */
164
- export interface WidgetStorage {
165
- /** The value saved under `key`; `undefined` when there is none. */
166
- get<T = unknown>(key: string): Promise<T | undefined>;
167
- /** Saves `value` (anything JSON can hold) under `key`, replacing the previous one. */
168
- set(key: string, value: unknown): Promise<void>;
169
- /** Removes `key`. Resolves `true` if it had a value. */
170
- delete(key: string): Promise<boolean>;
171
- }
172
- /** Network throughput in bytes per second. */
173
- export interface NetRate {
174
- down: number;
175
- up: number;
176
- }
177
- /**
178
- * The machine's performance at the time of the call. CPU load and network speeds are
179
- * measured since the previous call (from any widget); calls less than 500 ms apart share
180
- * one reading.
181
- */
182
- export interface SystemInfo {
183
- hostname: string;
184
- /** Name of the connected Wi-Fi network (its Windows profile name); `null` when not connected. */
185
- wifi: string | null;
186
- /** Load of all CPU cores, in percent. */
187
- cpu: {
188
- load: number;
189
- };
190
- /** First NVIDIA GPU (load in percent, temperature in °C); `null` when there is none. */
191
- gpu: {
192
- load: number;
193
- temperature: number;
194
- } | null;
195
- /**
196
- * Since the previous call, plus averages over the calls of the last 1, 5 and 15 minutes:
197
- * the full window while widgets keep asking, less right after they start or resume.
198
- */
199
- net: NetRate & {
200
- avg1m: NetRate;
201
- avg5m: NetRate;
202
- avg15m: NetRate;
203
- };
204
- }
205
- /** A program's CPU use: every process that shows the same name, added together. */
206
- export interface ProgramUsage {
207
- /**
208
- * What Task Manager calls it: its executable's description (`THE FINALS`, `Google Chrome`),
209
- * else the executable file name (`crashpad_handler.exe`).
210
- */
211
- name: string;
212
- /** Percent of all logical processors, like Task Manager. */
213
- cpu: number;
214
- }
215
- export interface MediaApi {
216
- /** The session Windows considers current (the one media keys control); `null` when none. */
217
- current(): Promise<MediaInfo | null>;
218
- /** Album art of the track from the latest `current()` call, as a data URL; `null` when none. */
219
- art(): Promise<string | null>;
220
- /** Asks the current session's app to play, pause or skip. Resolves `false` if it declined. */
221
- control(action: MediaAction): Promise<boolean>;
222
- }
223
- export type MediaAction = 'play' | 'pause' | 'next' | 'previous';
224
- /** A media session as an app publishes it to Windows. Fields the app doesn't set are empty. */
225
- export interface MediaInfo {
226
- /** App that owns the session, as Windows names it (`Spotify.exe`, `MSEdge`, ...). */
227
- app: string;
228
- title: string;
229
- artist: string;
230
- album: string;
231
- playing: boolean;
232
- /**
233
- * Seconds into the track at the time of the call; `null` when the app reports no timeline.
234
- * When the app blanks it out (Zen and Firefox do, about once a minute), it carries on from
235
- * the last one reported, as long as calls come at least every 5 seconds.
236
- */
237
- position: number | null;
238
- duration: number | null;
239
- /** Changes whenever the album art does: call `art()` then. `null` when there is no art. */
240
- art: number | null;
241
- /** Which `control()` actions the app accepts right now. */
242
- can: Record<MediaAction, boolean>;
243
- }
244
- /** The apps of the Start menu's All apps list (the shell's Apps folder). */
245
- export interface AppsApi {
246
- /** Every app, by name, read when called. */
247
- list(): Promise<AppInfo[]>;
248
- /**
249
- * Starts app `id` as the Start menu does, asking for its window on the main screen rather
250
- * than the Edge (apps that remember their position may still open where they were).
251
- * Rejects when the app is gone.
252
- */
253
- launch(id: string): Promise<void>;
254
- /**
255
- * URL of the icon of app `id`, for an `<img>`: a PNG `size` pixels square (16 to 256,
256
- * default 64). Ask for the size it shows at in device pixels: icons drawn larger are sharper.
257
- */
258
- icon(id: string, size?: number): string;
259
- }
260
- /** An app as the Start menu lists it. */
261
- export interface AppInfo {
262
- /**
263
- * Launches it and draws its icon: its name in the shell's Apps folder, the app's
264
- * AppUserModelID or, for a program without one, a path to it. Stays the same across
265
- * restarts, so widgets can save it.
266
- */
267
- id: string;
268
- /** What the Start menu calls it. */
269
- name: string;
270
- }
271
- /** The default export of a widget's entry module. */
272
- export interface WidgetModule {
273
- /** Render into `el`. May return (or resolve to) a cleanup function. */
274
- mount(el: HTMLElement, api: WidgetApi): void | Cleanup | Promise<void | Cleanup>;
275
- }
276
- /** Props of a widget's root component in the Svelte, React and Vue adapters. */
277
- export interface WidgetProps {
278
- api: WidgetApi;
279
- }
280
- 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",
@@ -87,6 +89,10 @@
87
89
  }
88
90
  }
89
91
  },
92
+ "source": {
93
+ "enum": ["audioApps"],
94
+ "description": "Adds the choices of a list EdgeStation reads when the settings show, after options. audioApps: the apps with sound, saved as their executable's file name. A saved value missing from the list stays saved."
95
+ },
90
96
  "default": {
91
97
  "type": "string",
92
98
  "description": "Value until the user picks one. Defaults to the first option."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgestation/sdk",
3
- "version": "0.2.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
- }