@startside/swa 1.0.0 → 1.0.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 +60 -0
- package/README.md +39 -4
- package/bin/swa.mjs +33 -0
- package/package.json +10 -3
- package/swa/1.0/agents.md +638 -0
- package/swa/1.0/quickstart.md +145 -0
- package/swa/1.0/runtime.js +1 -1
- package/swa/1.0/spec.md +2125 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startside/swa",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "The Startside Widget API (SWA): the runtime a widget file loads,
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "The Startside Widget API (SWA): the runtime a widget file loads, its TypeScript types, its specification in Markdown, and a command to check a widget file and inline its runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"swa",
|
|
7
7
|
"startside",
|
|
@@ -11,14 +11,21 @@
|
|
|
11
11
|
"uwa"
|
|
12
12
|
],
|
|
13
13
|
"homepage": "https://startside.app/swa/1.0/",
|
|
14
|
-
"license": "MIT",
|
|
14
|
+
"license": "(MIT AND CC-BY-4.0)",
|
|
15
15
|
"author": "François Hodierne",
|
|
16
16
|
"types": "swa/1.0/swa.d.ts",
|
|
17
|
+
"bin": {
|
|
18
|
+
"swa": "bin/swa.mjs"
|
|
19
|
+
},
|
|
17
20
|
"files": [
|
|
18
21
|
"swa/",
|
|
22
|
+
"bin/",
|
|
19
23
|
"README.md",
|
|
20
24
|
"LICENSE"
|
|
21
25
|
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
22
29
|
"publishConfig": {
|
|
23
30
|
"access": "public"
|
|
24
31
|
}
|
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
> **For an agent writing SWA widgets.** This text is published at https://startside.app/swa/1.0/agents.md, kept short enough
|
|
2
|
+
> to read whole (a web fetcher cuts long pages): *SWA in 60 lines* (a complete widget, the rules as a table, a
|
|
3
|
+
> checklist), the tools for authors, the TypeScript types, and an index of the full specification, whose sections you
|
|
4
|
+
> read as you need them, at https://startside.app/swa/1.0/ (Markdown: https://startside.app/swa/1.0/spec.md). Examples 6 and 7 (a game, a small
|
|
5
|
+
> application) are in its Appendix A. To try a widget, open its file in a browser; `#mode=dark&width=300` after its
|
|
6
|
+
> address opens it dark and narrow.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# SWA in 60 lines
|
|
11
|
+
|
|
12
|
+
**A quickstart for the Startside Widget API (SWA) 1.0.** The full specification, [swa-spec.md](https://startside.app/swa/1.0/spec.md), is the
|
|
13
|
+
reference; this page is what you need to write a widget that conforms to it: one complete widget, the rules as a
|
|
14
|
+
table, and a checklist.
|
|
15
|
+
|
|
16
|
+
## What a widget is
|
|
17
|
+
|
|
18
|
+
One HTML file, named `<name>.swa.html`: its metadata in the head, its settings as a hidden form, its markup in the
|
|
19
|
+
body, its code in a script, all talking to one global `widget`. A Startside page runs it in a sandboxed frame; opened
|
|
20
|
+
in a browser, it runs on its own page, with a menu, light and dark, and a width you can drag. Nothing to build or
|
|
21
|
+
install.
|
|
22
|
+
|
|
23
|
+
## A complete widget
|
|
24
|
+
|
|
25
|
+
The latest headlines of a feed, chosen in its settings:
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<!doctype html>
|
|
29
|
+
<html lang="en">
|
|
30
|
+
<head>
|
|
31
|
+
<script src="https://startside.app/swa/1.0/runtime.js"></script>
|
|
32
|
+
<title>Headlines</title>
|
|
33
|
+
<meta name="description" content="The latest headlines of a feed." />
|
|
34
|
+
<meta name="apiVersion" content="1.0" />
|
|
35
|
+
<meta name="category" content="News" />
|
|
36
|
+
<style>
|
|
37
|
+
.news ul { list-style: none; margin: 0; padding: 0; }
|
|
38
|
+
.news li { padding: 3px 0; border-bottom: 1px solid light-dark(#e5e7eb, #333a42); }
|
|
39
|
+
.news a { color: var(--link, #1e5bb8); }
|
|
40
|
+
.news .uwa-read a { color: var(--muted, #6b7280); }
|
|
41
|
+
.news [hidden] { display: none; }
|
|
42
|
+
</style>
|
|
43
|
+
</head>
|
|
44
|
+
<body>
|
|
45
|
+
<form id="preferences" hidden>
|
|
46
|
+
<label>Feed <input type="url" name="feed" value="https://daringfireball.net/feeds/main" /></label>
|
|
47
|
+
<label>Items <input type="range" name="count" min="1" max="20" value="5" /></label>
|
|
48
|
+
</form>
|
|
49
|
+
<div class="news">
|
|
50
|
+
<p class="state waiting">Loading…</p>
|
|
51
|
+
<p class="state failed" role="alert" hidden>Could not read the feed.</p>
|
|
52
|
+
<ul hidden></ul>
|
|
53
|
+
<template><li><a class="ext-link"></a></li></template>
|
|
54
|
+
</div>
|
|
55
|
+
<script>
|
|
56
|
+
const News = {
|
|
57
|
+
show(state) {
|
|
58
|
+
for (const el of widget.body.querySelectorAll('.state')) el.hidden = !el.classList.contains(state);
|
|
59
|
+
},
|
|
60
|
+
draw(feed) {
|
|
61
|
+
const list = widget.body.querySelector('ul');
|
|
62
|
+
const row = widget.body.querySelector('template').content.firstElementChild;
|
|
63
|
+
const items = feed.items.slice(0, widget.settings.get('count'));
|
|
64
|
+
list.replaceChildren(...items.map((item) => {
|
|
65
|
+
const li = row.cloneNode(true);
|
|
66
|
+
const a = li.querySelector('a');
|
|
67
|
+
a.href = item.url;
|
|
68
|
+
a.textContent = item.title || item.url; // text, never markup
|
|
69
|
+
return li;
|
|
70
|
+
}));
|
|
71
|
+
list.hidden = false;
|
|
72
|
+
News.show('none');
|
|
73
|
+
},
|
|
74
|
+
load(event, fresh) {
|
|
75
|
+
const url = String(widget.settings.get('feed'));
|
|
76
|
+
return widget.fetchFeed(url, { signal: event.signal, fresh }).then(News.draw, (error) => {
|
|
77
|
+
if (error.name !== 'AbortError' && !widget.body.querySelector('li')) News.show('failed');
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
widget.addEventListener('load', (event) => {
|
|
82
|
+
const list = widget.body.querySelector('ul');
|
|
83
|
+
list.addEventListener('click', (e) => {
|
|
84
|
+
const a = e.target.closest('a');
|
|
85
|
+
if (a) (e.preventDefault(), widget.openURL(a.href));
|
|
86
|
+
});
|
|
87
|
+
widget.readItems(list, 'li');
|
|
88
|
+
event.waitUntil(News.load(event, false));
|
|
89
|
+
});
|
|
90
|
+
widget.addEventListener('refresh', (event) => event.waitUntil(News.load(event, true)));
|
|
91
|
+
</script>
|
|
92
|
+
</body>
|
|
93
|
+
</html>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
What it shows, in order:
|
|
97
|
+
|
|
98
|
+
1. **The runtime** in the head, by its full address, so the file also runs opened from disk.
|
|
99
|
+
2. **Metadata**: a title and a description; `category` places it in a catalogue.
|
|
100
|
+
3. **Settings as a hidden form**: a control per setting, its `name` the setting's, its `value` the default, its
|
|
101
|
+
label the setting's label. `widget.settings.get()` gives each typed: a range a number, a checkbox a boolean.
|
|
102
|
+
4. **Markup in the file**: every state (loading, failed, the list) is there from the start, shown or hidden with
|
|
103
|
+
`hidden`; a `template` gives each row.
|
|
104
|
+
5. **Code in one object**, wired once in `load`: one listener on the list for every row, the read state from
|
|
105
|
+
`readItems`. `load` and `refresh` give `waitUntil` their promise, and pass on the `signal` that cancels a request
|
|
106
|
+
when the next load starts.
|
|
107
|
+
6. **Text set with `textContent`**, never fetched text as markup.
|
|
108
|
+
7. **Colors from the host's properties**, each with a fallback, and `light-dark()` for both modes.
|
|
109
|
+
|
|
110
|
+
## The rules
|
|
111
|
+
|
|
112
|
+
| | Rule | Section |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| MUST | Name the file `<name>.swa.html`, begin it with `<!doctype html>` | 4.1, 4.2 |
|
|
115
|
+
| MUST | Load the runtime once, in the head: `https://startside.app/swa/1.0/runtime.js` (where startside.app can't be loaded, the npm package on a CDN, `https://cdn.jsdelivr.net/npm/@startside/swa@1/swa/1.0/runtime.js`; or inlined: `<script data-runtime="swa/1.0">`) | 4.3 |
|
|
116
|
+
| MUST | Declare settings in `<form id="preferences" hidden>`, one named control each | 5 |
|
|
117
|
+
| MUST NOT | Use `localStorage`, `sessionStorage`, IndexedDB or cookies: `widget.storage` or a hidden setting | 4.8, 7.8 |
|
|
118
|
+
| MUST NOT | Use UWA's API (`onLoad`, `getValue`, `UWA.Data`): events, `widget.settings`, `widget.fetch`, `widget.fetchFeed` | 7, 8, 11 |
|
|
119
|
+
| MUST NOT | Style or script the page around the widget on its own page | 10.3 |
|
|
120
|
+
| MUST | Work framed: no inline mode, no access to the page | 10.1, 10.2 |
|
|
121
|
+
| MUST NOT | Use `alert()`, `confirm()` or `prompt()` (off in a frame): ask in the widget's own box | 10.1 |
|
|
122
|
+
| SHOULD | Write the markup in the file and update it in place; `setBody` only for content made whole at each draw | 4.9, 7.3.1 |
|
|
123
|
+
| SHOULD NOT | Put fetched or typed text into markup (`innerHTML`, a `setBody` string) | 7.3 |
|
|
124
|
+
| SHOULD | Keep a game in progress or the person's data in a hidden setting, read defensively, and under the host's limit if it grows (Startside: 20,000 characters a setting) | 7.5, 7.8 |
|
|
125
|
+
| SHOULD | Let the host set the width; the height is the content's; never `100vh` | 7.3.2 |
|
|
126
|
+
| SHOULD | Make a board, a grid or a list moved through with the arrow keys one Tab stop, the keys heard on the widget's own element; a list of plain links, as above, keeps its links in the Tab order | 7.3.1, 14 |
|
|
127
|
+
| SHOULD | Announce results and errors in a `role="status"` element present from the start, nothing as it first draws; keep the focus through updates | 14 |
|
|
128
|
+
| SHOULD | Write colors with `light-dark()`, other dark-mode changes under `:root[data-color-scheme="dark"]`, not `prefers-color-scheme` | 4.7 |
|
|
129
|
+
| SHOULD | Scope every rule under the widget's root class (`.news li`); give each host property a fallback, `var(--text, #222)`; avoid the host's class names (`loading`, `spinner`) | 4.7 |
|
|
130
|
+
| SHOULD | Do nothing at rest: an animation that draws the eye plays a few times; timers only for what changes on screen | 7.3.1 |
|
|
131
|
+
| SHOULD | Follow its width with a `ResizeObserver` on its own element when its layout depends on it | 7.3.2 |
|
|
132
|
+
| SHOULD | Meet WCAG 2.2 AA: keyboard alone, names on controls, 4.5:1 text, `prefers-reduced-motion` | 14 |
|
|
133
|
+
| MAY | Carry its icon in the file: `<link rel="icon" href="data:image/svg+xml,…">`, kept when the file is shared by itself (best: an SVG drawn for 16 pixels, or a 64 × 64 PNG) | 4.6 |
|
|
134
|
+
|
|
135
|
+
## Checklist
|
|
136
|
+
|
|
137
|
+
- [ ] It opens in a browser, from disk and from a server, with no error in the widget or the console.
|
|
138
|
+
- [ ] Each setting changed in the menu (▾) applies, and Refresh keeps what it should.
|
|
139
|
+
- [ ] It reads well light and dark, narrow (300 pixels) and wide, maximized: open it as
|
|
140
|
+
`name.swa.html#mode=dark&width=300`, then light and wider.
|
|
141
|
+
- [ ] Everything works with the keyboard alone; the focus is visible and never lost.
|
|
142
|
+
- [ ] Saved data from an older version, or edited by hand, doesn't break it.
|
|
143
|
+
- [ ] Nothing moves or runs when nobody uses it.
|
|
144
|
+
|
|
145
|
+
## Next
|
|
146
|
+
|
|
147
|
+
- The types, for an editor: `https://startside.app/swa/1.0/swa.d.ts` (Appendix F).
|
|
148
|
+
- More examples: a blog (Example 4), a game (Example 6), a to-do list (Example 7), in Appendix A of the specification.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
*Published at https://startside.app/swa/1.0/quickstart.html (Markdown: https://startside.app/swa/1.0/quickstart.md). ©
|
|
153
|
+
2026 François Hodierne, shared under the [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/)
|
|
154
|
+
licence (CC BY 4.0).*
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Tools for authors
|
|
160
|
+
|
|
161
|
+
*This appendix is non-normative.*
|
|
162
|
+
|
|
163
|
+
- **This specification, published.** `https://startside.app/swa/1.0/`, and as Markdown, `spec.md` beside it; *SWA in
|
|
164
|
+
60 lines* at `quickstart.html` (`quickstart.md`); for an agent, `agents.md`, short enough to read whole: the
|
|
165
|
+
quickstart, these tools, the types and an index of this specification's sections.
|
|
166
|
+
- **Types.** SWA 1.0's TypeScript types are served beside the runtime, at `https://startside.app/swa/1.0/swa.d.ts`:
|
|
167
|
+
saved next to a widget's scripts, with `/// <reference path="swa.d.ts" />` (or a `jsconfig.json` naming it),
|
|
168
|
+
`widget` is typed in an editor, its events with their `detail`, and what the host freezes read-only. The npm package
|
|
169
|
+
`@startside/swa` carries them too: installed, `"types": ["@startside/swa"]` in a `tsconfig.json` or `jsconfig.json`'s
|
|
170
|
+
`compilerOptions`.
|
|
171
|
+
- **The npm package `@startside/swa`.** The runtime (`swa/1.0/runtime.js`, the text startside.app serves) and the types
|
|
172
|
+
(`swa/1.0/swa.d.ts`), under the MIT licence; and, since 1.0.1, this specification, the quickstart and the guide for
|
|
173
|
+
agents as published here (`swa/1.0/spec.md`, `quickstart.md`, `agents.md`), under CC BY 4.0, as they were at the
|
|
174
|
+
package's release: for an author or an agent that can reach npm or a CDN but not this site
|
|
175
|
+
(`https://cdn.jsdelivr.net/npm/@startside/swa@1/swa/1.0/agents.md`). Served by jsDelivr and unpkg (4.3), installed
|
|
176
|
+
with `npm install @startside/swa`. Since 1.0.1 too, a command, for Node 20 or later, with nothing else to install:
|
|
177
|
+
`validate` and `inline`, below.
|
|
178
|
+
- **Checking a file.** `npx @startside/swa validate my-widget.swa.html` reads a widget file without running it, with no
|
|
179
|
+
network: the file's name and document, its runtime tag, metadata and settings form, and its scripts against this
|
|
180
|
+
API, UWA's members and globals named with what replaces them. Each finding is `file:line:col: error|warning:
|
|
181
|
+
message`, citing its section; `--json` gives them as a list of `{ file, line, col, level, message }`. It exits 1 on
|
|
182
|
+
an error. Run it after each edit: a file it passes can still fail as it runs, which only trying it shows.
|
|
183
|
+
- **Trying a widget.** A widget file opened in a browser, from disk or any server, runs on its own page with the
|
|
184
|
+
runtime its head loads (4.3): its options menu (▾) shows its title, color and settings, applied as they change, and
|
|
185
|
+
its `fetch` and `fetchFeed` go through Startside's proxies, which answer any origin. Errors show in the widget and
|
|
186
|
+
in the browser's console. `widget.html#mode=dark&width=300` opens it dark and 300 pixels wide (10.3), for a test or
|
|
187
|
+
a screenshot, rather than reaching into the page's own menu and switches, which may change.
|
|
188
|
+
- **A copy with the runtime inlined** (4.3), for a place that loads no script from another site: the file with its
|
|
189
|
+
runtime tag replaced by `<script data-runtime="swa/1.0">` holding the text of `https://startside.app/swa/1.0/runtime.js`,
|
|
190
|
+
fetched as the copy is made; nothing else changed. Make it again after the runtime changes, and keep the file that
|
|
191
|
+
loads the runtime by its address as the widget's own. `npx @startside/swa inline my-widget.swa.html` writes that
|
|
192
|
+
copy, `my-widget-inline.swa.html` (`-o` names another, never the file itself), with the package's runtime, its
|
|
193
|
+
`data-host` kept, then checks it; `npx @startside/swa@latest` gets the latest release's runtime.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## The types (`https://startside.app/swa/1.0/swa.d.ts`)
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
// SWA 1.0, the Startside Widget API: its types, for a widget file's scripts (docs/swa-spec.md, section 7, its Web IDL).
|
|
201
|
+
// Served at /swa/1.0/swa.d.ts. In an editor, next to a widget's code:
|
|
202
|
+
//
|
|
203
|
+
// /// <reference path="./swa.d.ts" />
|
|
204
|
+
//
|
|
205
|
+
// or in a jsconfig.json / tsconfig.json, "files": ["swa.d.ts"]. The global `widget` is then typed, with completion.
|
|
206
|
+
// scripts/check/swa-api.mjs checks that the runtime's `widget` has every member named here, and nothing else public, and
|
|
207
|
+
// that the readonly attributes are: assigning one throws in strict code, and what they give is frozen.
|
|
208
|
+
|
|
209
|
+
export {};
|
|
210
|
+
|
|
211
|
+
declare global {
|
|
212
|
+
/** The widget the file's code runs in (SWA 1.0, 7.1). */
|
|
213
|
+
const widget: SWA.Widget;
|
|
214
|
+
|
|
215
|
+
/** Every event the host fires at a widget (SWA 1.0, 7.6.1). */
|
|
216
|
+
class WidgetEvent<D = unknown> extends Event {
|
|
217
|
+
constructor(type: string, init?: EventInit & { detail?: D });
|
|
218
|
+
/** The event's data, as the table of 7.6.1 says: `fullsize`'s new value, `audiostate`'s state… */
|
|
219
|
+
readonly detail: D;
|
|
220
|
+
/** A load's (`load`, `refresh`): aborted when the next load starts or the widget goes. Null on other events. */
|
|
221
|
+
readonly signal: AbortSignal | null;
|
|
222
|
+
/** Extends a load (`load`, `refresh`) until `promise` settles; a rejection is reported in the widget. */
|
|
223
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
namespace SWA {
|
|
227
|
+
/** The events a widget listens for (SWA 1.0, 7.6.1), each with its `detail`. */
|
|
228
|
+
interface WidgetEventMap {
|
|
229
|
+
load: WidgetEvent<null>;
|
|
230
|
+
loadcomplete: WidgetEvent<null>;
|
|
231
|
+
refresh: WidgetEvent<null>;
|
|
232
|
+
resize: WidgetEvent<null>;
|
|
233
|
+
updatebody: WidgetEvent<null>;
|
|
234
|
+
updatepreferences: WidgetEvent<null>;
|
|
235
|
+
hideedit: WidgetEvent<null>;
|
|
236
|
+
/** Cancelable: canceling skips marking `readItems`' items read. */
|
|
237
|
+
readall: WidgetEvent<null>;
|
|
238
|
+
audiostate: WidgetEvent<AudioState>;
|
|
239
|
+
audioresume: WidgetEvent<null>;
|
|
240
|
+
videostate: WidgetEvent<VideoState | null>;
|
|
241
|
+
fullsize: WidgetEvent<boolean>;
|
|
242
|
+
fullscreen: WidgetEvent<boolean>;
|
|
243
|
+
/** Cancelable: canceling skips the refresh that follows. */
|
|
244
|
+
settingschange: WidgetEvent<{ names: string[] }>;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface Widget extends EventTarget {
|
|
248
|
+
// 7.2 Identity and environment
|
|
249
|
+
readonly id: string;
|
|
250
|
+
/** The title shown: the person's name for the widget if they renamed it (then `settingschange` with `title`), else its own (7.3). */
|
|
251
|
+
readonly title: string;
|
|
252
|
+
/** The widget file's address. */
|
|
253
|
+
readonly uwaUrl: string;
|
|
254
|
+
/** The person's language in UWA's form, `en_US`: `lang.replace('_', '-')` is a language tag for `Intl`. */
|
|
255
|
+
readonly lang: string;
|
|
256
|
+
/** The person's region, `us`. */
|
|
257
|
+
readonly locale: string;
|
|
258
|
+
/** The file's metadata (`<meta name content>`), by name. */
|
|
259
|
+
readonly metas: Readonly<Record<string, string>>;
|
|
260
|
+
/** The settings the file declares, frozen. */
|
|
261
|
+
readonly preferences: readonly WidgetSetting[];
|
|
262
|
+
/** Frozen. */
|
|
263
|
+
readonly environment: Readonly<WidgetEnvironment>;
|
|
264
|
+
/** The widget's content: set from `load` on, in every environment (SWA 1.0, 7.3.1). */
|
|
265
|
+
readonly body: HTMLElement;
|
|
266
|
+
log(...data: unknown[]): void;
|
|
267
|
+
|
|
268
|
+
// 7.3 Content and title
|
|
269
|
+
setBody(content: string | Node): void;
|
|
270
|
+
addBody(content: string | Node): void;
|
|
271
|
+
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, attributes?: Record<string, unknown>): HTMLElementTagNameMap[K];
|
|
272
|
+
createElement(tagName: string, attributes?: Record<string, unknown>): HTMLElement;
|
|
273
|
+
setTitle(title: string): void;
|
|
274
|
+
getTitle(): string;
|
|
275
|
+
setStyle(css: string): void;
|
|
276
|
+
|
|
277
|
+
// 7.4 Appearance
|
|
278
|
+
setIcon(url: string | null): void;
|
|
279
|
+
setChromeColor(color: string | null, options?: { background?: string | null }): void;
|
|
280
|
+
|
|
281
|
+
// 7.5 Settings
|
|
282
|
+
readonly settings: WidgetSettings;
|
|
283
|
+
getPreference(name: string): WidgetSetting | null;
|
|
284
|
+
setMaxValue(name: string, max: number): void;
|
|
285
|
+
openPreferences(): void;
|
|
286
|
+
withPreferencesLink(text: string): HTMLSpanElement;
|
|
287
|
+
|
|
288
|
+
// 7.6 Events and lifecycle
|
|
289
|
+
addEventListener<K extends keyof WidgetEventMap>(
|
|
290
|
+
type: K,
|
|
291
|
+
listener: (this: Widget, event: WidgetEventMap[K]) => unknown,
|
|
292
|
+
options?: boolean | AddEventListenerOptions,
|
|
293
|
+
): void;
|
|
294
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
|
|
295
|
+
removeEventListener<K extends keyof WidgetEventMap>(
|
|
296
|
+
type: K,
|
|
297
|
+
listener: (this: Widget, event: WidgetEventMap[K]) => unknown,
|
|
298
|
+
options?: boolean | EventListenerOptions,
|
|
299
|
+
): void;
|
|
300
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
|
|
301
|
+
/** A refresh the widget asks for itself, as when its settings apply. */
|
|
302
|
+
refresh(): void;
|
|
303
|
+
setAutoRefresh(minutes: number): void;
|
|
304
|
+
setPeriodical(name: string, callback: () => void, delay: number, now?: boolean): void;
|
|
305
|
+
clearPeriodical(name: string): void;
|
|
306
|
+
|
|
307
|
+
// 7.7 Lists and grips
|
|
308
|
+
countGrip(box: Element, itemSelector: string, options?: CountGripOptions): void;
|
|
309
|
+
heightGrip(box: Element, scroller: Element, options?: HeightGripOptions): void;
|
|
310
|
+
|
|
311
|
+
// 7.8 Memory and stored data
|
|
312
|
+
readonly storage: WidgetStorage;
|
|
313
|
+
|
|
314
|
+
// 8 Data access
|
|
315
|
+
/** The web's fetch, through the host's proxy: GET only, the body as text; an HTTP error a Response, not a rejection. */
|
|
316
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
317
|
+
/** RSS, Atom or JSON Feed as a JSON Feed 1.1, kept by the host: a kept copy answers at once. */
|
|
318
|
+
fetchFeed(url: string, options?: FetchFeedOptions): Promise<ContentFeed>;
|
|
319
|
+
|
|
320
|
+
// 7.10 Read state and counts
|
|
321
|
+
readItems(box: Element, itemSelector: string, options?: { key?: (item: Element) => string }): void;
|
|
322
|
+
isRead(key: string): boolean;
|
|
323
|
+
setRead(keys: string | string[], read?: boolean): void;
|
|
324
|
+
setUnreadCount(count: number): void;
|
|
325
|
+
setSearchResultCount(count: number): void;
|
|
326
|
+
|
|
327
|
+
// 7.11 The reader (activation-gated)
|
|
328
|
+
openURL(url: string): void;
|
|
329
|
+
openItems(items: ReaderItem[], index: number, options?: OpenItemsOptions): void;
|
|
330
|
+
|
|
331
|
+
// 7.12 Sound, video, pictures
|
|
332
|
+
/** Frozen: a new object at each change (`audiostate`). */
|
|
333
|
+
readonly audioState: Readonly<AudioState>;
|
|
334
|
+
playAudio(options: PlayAudioOptions): unknown;
|
|
335
|
+
pauseAudio(): unknown;
|
|
336
|
+
seekAudio(seconds: number): unknown;
|
|
337
|
+
audioStarted(stop: () => void, controls?: AudioControls): void;
|
|
338
|
+
audioStopped(): void;
|
|
339
|
+
audioInfo(info?: AudioInfo): void;
|
|
340
|
+
readonly videoState: Readonly<VideoState> | null;
|
|
341
|
+
playVideo(video: VideoSpec): unknown;
|
|
342
|
+
openPhoto(photo: PhotoSpec): unknown;
|
|
343
|
+
|
|
344
|
+
// 7.13 The page
|
|
345
|
+
shareUrl(): string | null;
|
|
346
|
+
share(data?: { text?: string; url?: string }): unknown;
|
|
347
|
+
/** Absent where no widget can be added (a preview, a widget on its own page): `if (widget.addWidget)`. */
|
|
348
|
+
addWidget?(spec: AddWidgetSpec): unknown;
|
|
349
|
+
dragWidget(element: Element, spec: AddWidgetSpec | (() => AddWidgetSpec)): boolean;
|
|
350
|
+
readonly canFullSize: boolean;
|
|
351
|
+
readonly fullSize: boolean;
|
|
352
|
+
openFull(): void;
|
|
353
|
+
closeFull(): void;
|
|
354
|
+
/** Full screen: the browser's, or the widget alone over the window where the browser has none (7.13). */
|
|
355
|
+
readonly fullScreen: boolean;
|
|
356
|
+
setFullScreen(on: boolean): void;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Settings typed by the control that declares them (7.5): a checkbox's a boolean, a range's or a number's a number. */
|
|
360
|
+
interface WidgetSettings {
|
|
361
|
+
/** The setting's value; `undefined` for a name the form doesn't declare. `title`: the widget's title (7.3, 7.5). */
|
|
362
|
+
get(name: string): string | number | boolean | null | undefined;
|
|
363
|
+
/**
|
|
364
|
+
* Saved without a refresh; a checkbox's takes a boolean, a range's or a number's a number, any other's a string
|
|
365
|
+
* (null or undefined: empty). A wrong type, or an undeclared name, throws a TypeError. A host may limit a value's
|
|
366
|
+
* length (Startside: 20,000 characters): one over it isn't kept, and the widget's console says so (7.5).
|
|
367
|
+
* `set('title', name)`: the person's name for the widget, typed in it ('' for its own; 7.5).
|
|
368
|
+
*/
|
|
369
|
+
set(name: string, value: string | number | boolean | null | undefined): void;
|
|
370
|
+
reset(name: string): void;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** What a widget keeps (7.8): JSON values, copied in and out. */
|
|
374
|
+
interface WidgetStorage {
|
|
375
|
+
/** Across rebuilds (a tab switch) and, unless the person turned it off, reloads: a cache, which the host may drop. A game in progress is a hidden setting (`settings.set`), not memory. */
|
|
376
|
+
readonly memory: WidgetStorageArea;
|
|
377
|
+
/** Across reloads, shared by every widget of the same file: scores. */
|
|
378
|
+
readonly local: WidgetStorageArea;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
interface WidgetStorageArea {
|
|
382
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
383
|
+
set(key: string, value: unknown): Promise<void>;
|
|
384
|
+
delete(key: string): Promise<void>;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
interface WidgetEnvironment {
|
|
388
|
+
readonly name: string;
|
|
389
|
+
readonly standalone: boolean;
|
|
390
|
+
/** false: an SWA widget never runs inline (SWA 1.0, 10.2). */
|
|
391
|
+
readonly inline: boolean;
|
|
392
|
+
/** The page's style, or "" standalone. */
|
|
393
|
+
readonly style: string;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** A setting as the file declares it: frozen, as `preferences` and `getPreference` give it. */
|
|
397
|
+
interface WidgetSetting {
|
|
398
|
+
readonly name: string;
|
|
399
|
+
readonly type: 'text' | 'password' | 'hidden' | 'boolean' | 'list' | 'range' | 'number' | 'url';
|
|
400
|
+
readonly label?: string;
|
|
401
|
+
readonly defaultValue?: string;
|
|
402
|
+
readonly options?: readonly { readonly value: string; readonly label?: string; readonly feed?: string }[];
|
|
403
|
+
readonly min?: number;
|
|
404
|
+
readonly max?: number;
|
|
405
|
+
readonly step?: number;
|
|
406
|
+
readonly hint?: string;
|
|
407
|
+
readonly when?: string;
|
|
408
|
+
readonly commit?: 'ok';
|
|
409
|
+
readonly shareable?: boolean;
|
|
410
|
+
readonly load?: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface CountGripOptions {
|
|
414
|
+
/** Adds the items not shown yet. */
|
|
415
|
+
onStart?: () => void;
|
|
416
|
+
onDone?: (count: number) => void;
|
|
417
|
+
min?: number;
|
|
418
|
+
/** The setting holding the count: a double-click restores its default. */
|
|
419
|
+
setting?: string;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
interface HeightGripOptions {
|
|
423
|
+
height?: number;
|
|
424
|
+
min?: number;
|
|
425
|
+
/** A selector: the list's items. */
|
|
426
|
+
items?: string;
|
|
427
|
+
onDone?: (pixels: number) => void;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
interface FetchFeedOptions {
|
|
431
|
+
signal?: AbortSignal | null;
|
|
432
|
+
/** Skip the kept copy (a refresh the person asked for). */
|
|
433
|
+
fresh?: boolean;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** A JSON Feed 1.1 document with the host's extensions (8.5). Its schema is SWA's Issue 11. */
|
|
437
|
+
interface ContentFeed {
|
|
438
|
+
version: string;
|
|
439
|
+
title?: string;
|
|
440
|
+
home_page_url?: string;
|
|
441
|
+
feed_url?: string;
|
|
442
|
+
items: ContentItem[];
|
|
443
|
+
_myvibes?: Record<string, unknown>;
|
|
444
|
+
[extension: `_${string}`]: unknown;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
interface ContentItem {
|
|
448
|
+
id: string;
|
|
449
|
+
url?: string;
|
|
450
|
+
external_url?: string;
|
|
451
|
+
title?: string;
|
|
452
|
+
summary?: string;
|
|
453
|
+
content_html?: string;
|
|
454
|
+
content_text?: string;
|
|
455
|
+
image?: string;
|
|
456
|
+
date_published?: string;
|
|
457
|
+
date_modified?: string;
|
|
458
|
+
authors?: { name?: string; url?: string; avatar?: string }[];
|
|
459
|
+
tags?: string[];
|
|
460
|
+
attachments?: { url: string; mime_type: string; title?: string; size_in_bytes?: number; duration_in_seconds?: number }[];
|
|
461
|
+
_myvibes?: Record<string, unknown>;
|
|
462
|
+
[extension: `_${string}`]: unknown;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
interface ReaderItem {
|
|
466
|
+
url: string;
|
|
467
|
+
/** Where its headline points, when not `url`. */
|
|
468
|
+
link?: string;
|
|
469
|
+
title?: string;
|
|
470
|
+
/** HTML, the reader's text. */
|
|
471
|
+
content?: string;
|
|
472
|
+
/** Its first view. */
|
|
473
|
+
prefer?: 'feed' | 'page' | 'reader';
|
|
474
|
+
/** An RFC 3339 date, in the reader's list. */
|
|
475
|
+
date?: string;
|
|
476
|
+
/** A short excerpt, in the reader's list. */
|
|
477
|
+
summary?: string;
|
|
478
|
+
author?: string;
|
|
479
|
+
image?: string;
|
|
480
|
+
read?: boolean;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
interface OpenItemsOptions {
|
|
484
|
+
prefer?: 'feed' | 'page' | 'reader';
|
|
485
|
+
/** Sites that allow being framed. */
|
|
486
|
+
frameable?: string[];
|
|
487
|
+
onOpen?: (index: number) => void;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
interface PlayAudioOptions {
|
|
491
|
+
/** https */
|
|
492
|
+
url: string;
|
|
493
|
+
/** Played without a Referer, through the host's relay. */
|
|
494
|
+
relay?: boolean;
|
|
495
|
+
live?: boolean;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
interface AudioState {
|
|
499
|
+
url: string | null;
|
|
500
|
+
playing: boolean;
|
|
501
|
+
loading: boolean;
|
|
502
|
+
error: null | 'blocked' | 'failed';
|
|
503
|
+
/** Seconds, for a file. */
|
|
504
|
+
time?: number | null;
|
|
505
|
+
duration?: number | null;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
interface AudioControls {
|
|
509
|
+
resume?: () => void;
|
|
510
|
+
/** 0 to 1. */
|
|
511
|
+
setVolume?: (volume: number) => void;
|
|
512
|
+
next?: () => void;
|
|
513
|
+
previous?: () => void;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
interface AudioInfo {
|
|
517
|
+
source?: string;
|
|
518
|
+
title?: string;
|
|
519
|
+
artist?: string;
|
|
520
|
+
artwork?: string;
|
|
521
|
+
artworkType?: string;
|
|
522
|
+
artworkSizes?: string;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
interface VideoSpec {
|
|
526
|
+
provider: 'youtube' | 'vimeo' | 'arte';
|
|
527
|
+
id: string;
|
|
528
|
+
title?: string;
|
|
529
|
+
/** A YouTube playlist. */
|
|
530
|
+
list?: string;
|
|
531
|
+
/** An ARTE language. */
|
|
532
|
+
lang?: string;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
interface VideoState {
|
|
536
|
+
provider: string;
|
|
537
|
+
id: string;
|
|
538
|
+
list?: string;
|
|
539
|
+
playing: boolean;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
interface PhotoSpec {
|
|
543
|
+
src: string;
|
|
544
|
+
alt?: string;
|
|
545
|
+
title?: string;
|
|
546
|
+
preview?: string;
|
|
547
|
+
width?: number;
|
|
548
|
+
height?: number;
|
|
549
|
+
credit?: string;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
interface AddWidgetSpec {
|
|
553
|
+
/** A file of the host's widget directory. */
|
|
554
|
+
file: string;
|
|
555
|
+
title?: string;
|
|
556
|
+
/** At most 12, 200 characters each. */
|
|
557
|
+
values?: Record<string, string>;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
## The specification, by section
|
|
566
|
+
|
|
567
|
+
The full text: https://startside.app/swa/1.0/ (Markdown: https://startside.app/swa/1.0/spec.md).
|
|
568
|
+
|
|
569
|
+
- [Abstract](https://startside.app/swa/1.0/#abstract)
|
|
570
|
+
- [Status of This Document](https://startside.app/swa/1.0/#status-of-this-document)
|
|
571
|
+
- [1. Introduction](https://startside.app/swa/1.0/#1-introduction)
|
|
572
|
+
- [2. Conformance](https://startside.app/swa/1.0/#2-conformance)
|
|
573
|
+
- [3. Terminology](https://startside.app/swa/1.0/#3-terminology)
|
|
574
|
+
- [4. Widget files](https://startside.app/swa/1.0/#4-widget-files)
|
|
575
|
+
- [4.1 File names and keys](https://startside.app/swa/1.0/#41-file-names-and-keys)
|
|
576
|
+
- [4.2 Document requirements](https://startside.app/swa/1.0/#42-document-requirements)
|
|
577
|
+
- [4.3 The runtime script](https://startside.app/swa/1.0/#43-the-runtime-script)
|
|
578
|
+
- [4.4 The title](https://startside.app/swa/1.0/#44-the-title)
|
|
579
|
+
- [4.5 Metadata](https://startside.app/swa/1.0/#45-metadata)
|
|
580
|
+
- [4.6 Icon and thumbnail](https://startside.app/swa/1.0/#46-icon-and-thumbnail)
|
|
581
|
+
- [4.7 Styles](https://startside.app/swa/1.0/#47-styles)
|
|
582
|
+
- [4.8 Scripts](https://startside.app/swa/1.0/#48-scripts)
|
|
583
|
+
- [4.9 Initial content](https://startside.app/swa/1.0/#49-initial-content)
|
|
584
|
+
- [5. The settings form](https://startside.app/swa/1.0/#5-the-settings-form)
|
|
585
|
+
- [5.1 The `preferences` form](https://startside.app/swa/1.0/#51-the-preferences-form)
|
|
586
|
+
- [5.2 Controls](https://startside.app/swa/1.0/#52-controls)
|
|
587
|
+
- [5.3 Attributes](https://startside.app/swa/1.0/#53-attributes)
|
|
588
|
+
- [6. Processing model](https://startside.app/swa/1.0/#6-processing-model)
|
|
589
|
+
- [6.1 Widget records](https://startside.app/swa/1.0/#61-widget-records)
|
|
590
|
+
- [6.2 Reading a widget file](https://startside.app/swa/1.0/#62-reading-a-widget-file)
|
|
591
|
+
- [6.3 Extracting the settings](https://startside.app/swa/1.0/#63-extracting-the-settings)
|
|
592
|
+
- [6.4 Resolving the declared feed](https://startside.app/swa/1.0/#64-resolving-the-declared-feed)
|
|
593
|
+
- [6.5 Applying a setting](https://startside.app/swa/1.0/#65-applying-a-setting)
|
|
594
|
+
- [6.6 Starting and refreshing](https://startside.app/swa/1.0/#66-starting-and-refreshing)
|
|
595
|
+
- [6.7 Activation-gated operations](https://startside.app/swa/1.0/#67-activation-gated-operations)
|
|
596
|
+
- [7. The `Widget` interface](https://startside.app/swa/1.0/#7-the-widget-interface)
|
|
597
|
+
- [7.1 The `widget` object](https://startside.app/swa/1.0/#71-the-widget-object)
|
|
598
|
+
- [7.2 Identity and environment](https://startside.app/swa/1.0/#72-identity-and-environment)
|
|
599
|
+
- [7.3 Content and title](https://startside.app/swa/1.0/#73-content-and-title)
|
|
600
|
+
- [7.4 Appearance](https://startside.app/swa/1.0/#74-appearance)
|
|
601
|
+
- [7.5 Settings](https://startside.app/swa/1.0/#75-settings)
|
|
602
|
+
- [7.6 Events and lifecycle](https://startside.app/swa/1.0/#76-events-and-lifecycle)
|
|
603
|
+
- [7.7 Lists and grips](https://startside.app/swa/1.0/#77-lists-and-grips)
|
|
604
|
+
- [7.8 Memory and stored data](https://startside.app/swa/1.0/#78-memory-and-stored-data)
|
|
605
|
+
- [7.9 Kept feeds](https://startside.app/swa/1.0/#79-kept-feeds)
|
|
606
|
+
- [7.10 Read state and counts](https://startside.app/swa/1.0/#710-read-state-and-counts)
|
|
607
|
+
- [7.11 The reader](https://startside.app/swa/1.0/#711-the-reader)
|
|
608
|
+
- [7.12 Sound, video and pictures](https://startside.app/swa/1.0/#712-sound-video-and-pictures)
|
|
609
|
+
- [7.13 The page](https://startside.app/swa/1.0/#713-the-page)
|
|
610
|
+
- [7.14 Absent members](https://startside.app/swa/1.0/#714-absent-members)
|
|
611
|
+
- [7.15 Error reports](https://startside.app/swa/1.0/#715-error-reports)
|
|
612
|
+
- [8. Data access](https://startside.app/swa/1.0/#8-data-access)
|
|
613
|
+
- [8.1 Fetching](https://startside.app/swa/1.0/#81-fetching)
|
|
614
|
+
- [8.2 `widget.fetch`](https://startside.app/swa/1.0/#82-widgetfetch)
|
|
615
|
+
- [8.3 `widget.fetchFeed`](https://startside.app/swa/1.0/#83-widgetfetchfeed)
|
|
616
|
+
- [8.4 Freshness](https://startside.app/swa/1.0/#84-freshness)
|
|
617
|
+
- [8.5 Content feeds](https://startside.app/swa/1.0/#85-content-feeds)
|
|
618
|
+
- [9. Built-in objects](https://startside.app/swa/1.0/#9-built-in-objects)
|
|
619
|
+
- [10. Execution environments](https://startside.app/swa/1.0/#10-execution-environments)
|
|
620
|
+
- [10.1 Framed](https://startside.app/swa/1.0/#101-framed)
|
|
621
|
+
- [10.2 No inline mode](https://startside.app/swa/1.0/#102-no-inline-mode)
|
|
622
|
+
- [10.3 Standalone](https://startside.app/swa/1.0/#103-standalone)
|
|
623
|
+
- [10.4 Trust](https://startside.app/swa/1.0/#104-trust)
|
|
624
|
+
- [11. Compatibility with UWA 1.2](https://startside.app/swa/1.0/#11-compatibility-with-uwa-12)
|
|
625
|
+
- [11.1 Files and preferences](https://startside.app/swa/1.0/#111-files-and-preferences)
|
|
626
|
+
- [11.2 UWA's extensions of built-in objects](https://startside.app/swa/1.0/#112-uwas-extensions-of-built-in-objects)
|
|
627
|
+
- [11.3 UWA's callbacks](https://startside.app/swa/1.0/#113-uwas-callbacks)
|
|
628
|
+
- [12. Security Considerations](https://startside.app/swa/1.0/#12-security-considerations)
|
|
629
|
+
- [13. Privacy Considerations](https://startside.app/swa/1.0/#13-privacy-considerations)
|
|
630
|
+
- [14. Accessibility Considerations](https://startside.app/swa/1.0/#14-accessibility-considerations)
|
|
631
|
+
- [Appendix A. Examples](https://startside.app/swa/1.0/#appendix-a-examples)
|
|
632
|
+
- [Appendix B. Changes from UWA 1.2.4](https://startside.app/swa/1.0/#appendix-b-changes-from-uwa-124)
|
|
633
|
+
- [Appendix C. Implementation status and features at risk](https://startside.app/swa/1.0/#appendix-c-implementation-status-and-features-at-risk)
|
|
634
|
+
- [Appendix D. IDL Index](https://startside.app/swa/1.0/#appendix-d-idl-index)
|
|
635
|
+
- [Appendix E. Open issues](https://startside.app/swa/1.0/#appendix-e-open-issues)
|
|
636
|
+
- [Appendix F. Tools for authors](https://startside.app/swa/1.0/#appendix-f-tools-for-authors)
|
|
637
|
+
- [Normative references](https://startside.app/swa/1.0/#normative-references)
|
|
638
|
+
- [Informative references](https://startside.app/swa/1.0/#informative-references)
|