@startside/swa 1.0.1 → 1.0.3

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/swa/1.0/swa.d.ts CHANGED
@@ -43,12 +43,18 @@ declare global {
43
43
  fullscreen: WidgetEvent<boolean>;
44
44
  /** Cancelable: canceling skips the refresh that follows. */
45
45
  settingschange: WidgetEvent<{ names: string[] }>;
46
+ /** One of the widget's own actions (declared in `<menu id="actions">`, 7.13) chosen in its options menu. */
47
+ action: WidgetEvent<{ id: string }>;
48
+ /** A picture opened with `openPhoto({ deletable: true, id })`, deleted by the person in the host's window. */
49
+ photodelete: WidgetEvent<{ id: string }>;
50
+ /** Its pictures (`storage.files`) changed: Sync, another copy of the page, or its own call. List them again. */
51
+ fileschange: WidgetEvent<null>;
46
52
  }
47
53
 
48
54
  interface Widget extends EventTarget {
49
55
  // 7.2 Identity and environment
50
56
  readonly id: string;
51
- /** The title shown: the person's name for the widget if they renamed it (then `settingschange` with `title`), else its own (7.3). */
57
+ /** The title shown: the widget's own, its file's `<title>` until it sets another (7.3). */
52
58
  readonly title: string;
53
59
  /** The widget file's address. */
54
60
  readonly uwaUrl: string;
@@ -106,8 +112,9 @@ declare global {
106
112
  clearPeriodical(name: string): void;
107
113
 
108
114
  // 7.7 Lists and grips
109
- countGrip(box: Element, itemSelector: string, options?: CountGripOptions): void;
110
- heightGrip(box: Element, scroller: Element, options?: HeightGripOptions): void;
115
+ /** `box` an HTML element: the grip sets its style. */
116
+ countGrip(box: HTMLElement, itemSelector: string, options?: CountGripOptions): void;
117
+ heightGrip(box: HTMLElement, scroller: HTMLElement, options?: HeightGripOptions): void;
111
118
 
112
119
  // 7.8 Memory and stored data
113
120
  readonly storage: WidgetStorage;
@@ -117,6 +124,11 @@ declare global {
117
124
  fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
118
125
  /** RSS, Atom or JSON Feed as a JSON Feed 1.1, kept by the host: a kept copy answers at once. */
119
126
  fetchFeed(url: string, options?: FetchFeedOptions): Promise<ContentFeed>;
127
+ /**
128
+ * A picture fetched by the host as itself (with its Referer; 8.6): an address to show in an `img`, the same for the
129
+ * same picture. https, a raster picture of 2 MB at most; rejects with a TypeError otherwise.
130
+ */
131
+ fetchImage(url: string, options?: { signal?: AbortSignal | null }): Promise<string>;
120
132
 
121
133
  // 7.10 Read state and counts
122
134
  readItems(box: Element, itemSelector: string, options?: { key?: (item: Element) => string }): void;
@@ -145,9 +157,12 @@ declare global {
145
157
  // 7.13 The page
146
158
  shareUrl(): string | null;
147
159
  share(data?: { text?: string; url?: string }): unknown;
160
+ /** Startside's extension: the page's Send to… for this widget; nothing where environment.people is null. */
161
+ sendTo(): void;
148
162
  /** Absent where no widget can be added (a preview, a widget on its own page): `if (widget.addWidget)`. */
149
163
  addWidget?(spec: AddWidgetSpec): unknown;
150
- dragWidget(element: Element, spec: AddWidgetSpec | (() => AddWidgetSpec)): boolean;
164
+ /** `spec`, or a function giving it as the drag starts, given the drag's event; nothing given, the drag doesn't start. */
165
+ dragWidget(element: Element, spec: AddWidgetSpec | ((event: DragEvent) => AddWidgetSpec | null | undefined)): boolean;
151
166
  readonly canFullSize: boolean;
152
167
  readonly fullSize: boolean;
153
168
  openFull(): void;
@@ -155,6 +170,30 @@ declare global {
155
170
  /** Full screen: the browser's, or the widget alone over the window where the browser has none (7.13). */
156
171
  readonly fullScreen: boolean;
157
172
  setFullScreen(on: boolean): void;
173
+ /**
174
+ * Changes the state of actions the file declares (`<menu id="actions">`, 7.13), by id: greyed, hidden, another
175
+ * label. An id the file doesn't declare throws a TypeError. States last while the widget runs.
176
+ */
177
+ setActionStates(states: Record<string, WidgetActionState>): void;
178
+ /**
179
+ * A file the widget made, for the person to keep (7.13): the host checks its name, its extension and its type,
180
+ * and delivers it. `options.action`: the `action` event of a choice of an action whose declaration carries
181
+ * `data-save`; one file per choice, within 30 seconds. Resolves once the host handed the file to the browser
182
+ * (not "saved"); rejects with a DOMException: NotAllowedError (no such choice, or already used), NotSupportedError
183
+ * (a name, an extension or a type the action or the host doesn't take), QuotaExceededError (over 8 MiB),
184
+ * AbortError (the person cancelled). Without `options.action`: NotAllowedError.
185
+ */
186
+ saveFile(file: WidgetSaveFile, options?: { action?: WidgetEvent<{ id: string }> }): Promise<void>;
187
+ }
188
+
189
+ /** A file a widget saves (7.13). */
190
+ interface WidgetSaveFile {
191
+ /** Its name, with its extension: one the action declares (`data-save`). The host cleans it. */
192
+ name: string;
193
+ /** Its type, one its extension takes ('' for the usual one): "text/plain;charset=utf-8". */
194
+ type: string;
195
+ /** Its content, 8 MiB at most (a string's as UTF-8); copied as the call is made. */
196
+ data: string | Blob | ArrayBuffer;
158
197
  }
159
198
 
160
199
  /** Settings typed by the control that declares them (7.5): a checkbox's a boolean, a range's or a number's a number. */
@@ -177,6 +216,31 @@ declare global {
177
216
  readonly memory: WidgetStorageArea;
178
217
  /** Across reloads, shared by every widget of the same file: scores. */
179
218
  readonly local: WidgetStorageArea;
219
+ /** Its own pictures, kept for good and the same on the person's other devices (synced): photos it took. */
220
+ readonly files: WidgetFiles;
221
+ }
222
+
223
+ /** A widget's pictures (7.8): JPEG, PNG, WebP or GIF, 10 MB each at most. */
224
+ interface WidgetFiles {
225
+ /** Every one, oldest first, from this device at once. */
226
+ list(): Promise<WidgetFile[]>;
227
+ /** Its bytes, from this device or the server; rejects `NotFoundError`, or `NetworkError` offline without them. */
228
+ get(id: string): Promise<Blob>;
229
+ /** Kept here at once, sent when the host can; its id. Rejects `TypeError` (not a picture, a meta not JSON or over 1,024 bytes), `RangeError` (over 10 MB). */
230
+ add(file: Blob, meta?: unknown): Promise<string>;
231
+ /** Deleted here and on the person's other devices. */
232
+ delete(id: string): Promise<void>;
233
+ }
234
+
235
+ interface WidgetFile {
236
+ readonly id: string;
237
+ /** `image/jpeg`, `image/png`, `image/webp` or `image/gif`, told by its bytes. */
238
+ readonly type: string;
239
+ readonly size: number;
240
+ /** When it was added, in milliseconds. */
241
+ readonly at: number;
242
+ /** What the widget gave `add`. */
243
+ readonly meta: unknown;
180
244
  }
181
245
 
182
246
  interface WidgetStorageArea {
@@ -192,6 +256,11 @@ declare global {
192
256
  readonly inline: boolean;
193
257
  /** The page's style, or "" standalone. */
194
258
  readonly style: string;
259
+ /**
260
+ * Startside's extension: who plays, in the beta's conversations (this person's name, and who sent this copy,
261
+ * null on their own page); null elsewhere.
262
+ */
263
+ readonly people: Readonly<{ me: string; from: string | null; to: string | null }> | null;
195
264
  }
196
265
 
197
266
  /** A setting as the file declares it: frozen, as `preferences` and `getPreference` give it. */
@@ -294,6 +363,20 @@ declare global {
294
363
  /** Played without a Referer, through the host's relay. */
295
364
  relay?: boolean;
296
365
  live?: boolean;
366
+ /**
367
+ * For a file (`live: false`): the files the host plays after it, each as the one before ends, with no further click,
368
+ * until a pause (7.12). `audioState.url` says which plays. 100 at most.
369
+ */
370
+ next?: NextAudio[];
371
+ }
372
+
373
+ interface NextAudio {
374
+ /** https */
375
+ url: string;
376
+ relay?: boolean;
377
+ /** What the host says plays as it starts (`audioInfo`'s title and artist). */
378
+ title?: string;
379
+ artist?: string;
297
380
  }
298
381
 
299
382
  interface AudioState {
@@ -304,6 +387,21 @@ declare global {
304
387
  /** Seconds, for a file. */
305
388
  time?: number | null;
306
389
  duration?: number | null;
390
+ /**
391
+ * A file (`live: false`) another widget of the page plays, playing or loading, else null. While this widget plays
392
+ * nothing itself, `pauseAudio` and `seekAudio` act on it; `playAudio` of a file another widget holds goes on there.
393
+ */
394
+ elsewhere?: ElsewhereAudio | null;
395
+ }
396
+
397
+ interface ElsewhereAudio {
398
+ url: string;
399
+ playing: boolean;
400
+ loading: boolean;
401
+ time: number | null;
402
+ duration: number | null;
403
+ /** Its `audioInfo`'s source. */
404
+ source: string | null;
307
405
  }
308
406
 
309
407
  interface AudioControls {
@@ -341,13 +439,57 @@ declare global {
341
439
  }
342
440
 
343
441
  interface PhotoSpec {
344
- src: string;
442
+ /** An `https` picture or one of the host's; `file` instead for one of the widget's own files. */
443
+ src?: string;
444
+ /** One of its own pictures (`storage.files`), by id: the host reads it, `src` aside. */
445
+ file?: string;
446
+ /** Its own pictures to step through from `file` (their ids, in order, 5,000 at most): ‹ › and the arrow keys. */
447
+ files?: string[];
345
448
  alt?: string;
346
449
  title?: string;
347
450
  preview?: string;
451
+ /** A larger picture of the same, asked only when the person zooms in. */
452
+ zoom?: string;
348
453
  width?: number;
349
454
  height?: number;
350
- credit?: string;
455
+ /** What the picture's licence asks to go with it. A plain string is its credit text. */
456
+ credit?: PhotoCredit | string;
457
+ /** The window offers Delete, which asks the person first; the widget hears it as `photodelete`. */
458
+ deletable?: boolean;
459
+ /** Given back in `photodelete`'s detail: which picture (100 characters at most). With `file`, the file's id instead. */
460
+ id?: string;
461
+ }
462
+
463
+ /**
464
+ * A picture's credit, in schema.org's ImageObject names (https://schema.org/ImageObject), every member optional.
465
+ * Addresses are `https`.
466
+ */
467
+ interface PhotoCredit {
468
+ /** The work's title. */
469
+ name?: string;
470
+ /** Who made it. */
471
+ creator?: string;
472
+ /** The credit line: who keeps or gives the picture (a museum, an agency). */
473
+ creditText?: string;
474
+ /** Who the licence says to name, as it asks ("Photo: …", "© …"). */
475
+ copyrightNotice?: string;
476
+ /** The licence's address. */
477
+ license?: string;
478
+ /** The picture's page at its source. */
479
+ url?: string;
480
+ }
481
+
482
+ /**
483
+ * What a running widget may change of an action its file declares (7.13). A field left out stays as it was; `null`
484
+ * puts it back to what the file declares.
485
+ */
486
+ interface WidgetActionState {
487
+ /** Greyed: nothing to act on. */
488
+ disabled?: boolean | null;
489
+ /** Not in the menu. */
490
+ hidden?: boolean | null;
491
+ /** Another label, 1 to 40 characters: a word that depends on its state, or a translation. */
492
+ label?: string | null;
351
493
  }
352
494
 
353
495
  interface AddWidgetSpec {