@startside/swa 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startside/swa",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
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",
package/swa/1.0/agents.md CHANGED
@@ -123,29 +123,38 @@ What it shows, in order:
123
123
  | SHOULD NOT | Put fetched or typed text into markup (`innerHTML`, a `setBody` string) | 7.3 |
124
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
125
  | SHOULD | Let the host set the width; the height is the content's; never `100vh` | 7.3.2 |
126
+ | SHOULD | While it loads, show a placeholder at the size of what's coming (a skeleton of its rows, its picture's box), not a one-line "Loading…": the widget doesn't change size as its content arrives | 7.3.1 |
126
127
  | 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 |
128
+ | SHOULD | Mark where the keyboard lands when the host moves the focus into the widget, when that isn't its first control: `autofocus` on a game's board (`<div class="board" tabindex="0" autofocus>`). Call `preventDefault()` on the Escape and arrow keys it uses itself: left uncancelled, a host may use Escape to leave the widget and an arrow to go to the next | 6.8 |
127
129
  | 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
130
  | SHOULD | Write colors with `light-dark()`, other dark-mode changes under `:root[data-color-scheme="dark"]`, not `prefers-color-scheme` | 4.7 |
129
131
  | 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
132
  | 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
133
  | SHOULD | Follow its width with a `ResizeObserver` on its own element when its layout depends on it | 7.3.2 |
132
134
  | SHOULD | Meet WCAG 2.2 AA: keyboard alone, names on controls, 4.5:1 text, `prefers-reduced-motion` | 14 |
135
+ | MUST | Show only pictures it may show (public domain, or a licence or permission that allows it), their required credits kept; a picture opened large carries its own: `widget.openPhoto({ src, alt, credit })` | 7.12 |
136
+ | MAY | Declare actions of its own for its options menu, in the file: `<menu id="actions" hidden>` with one `<button type="button" name="reset">Reset</button>` each, five at most (`disabled` or `hidden` as it starts, `data-confirm="…?"` for a question the host asks first). Answer the `action` event (`event.detail.id`), and change their state as the widget's does with `widget.setActionStates({ reset: { disabled: false } })` | 7.13 |
137
+ | MAY | Hand the person a file it makes, from one of those actions only: `data-save=".cook"` on its button, then `widget.saveFile({ name, type, data }, { action: event })` in its `action` listener | 7.13 |
133
138
  | 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
139
 
135
140
  ## Checklist
136
141
 
142
+ - [ ] `npx @startside/swa validate name.swa.html` reports no error (Appendix F): it reads the file without running it.
137
143
  - [ ] It opens in a browser, from disk and from a server, with no error in the widget or the console.
138
144
  - [ ] Each setting changed in the menu (▾) applies, and Refresh keeps what it should.
139
145
  - [ ] It reads well light and dark, narrow (300 pixels) and wide, maximized: open it as
140
146
  `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.
147
+ - [ ] Everything works with the keyboard alone; the focus is visible and never lost. A game plays with its keys once the
148
+ focus is on it, and the keys it doesn't use are left uncancelled.
142
149
  - [ ] Saved data from an older version, or edited by hand, doesn't break it.
143
150
  - [ ] Nothing moves or runs when nobody uses it.
144
151
 
145
152
  ## Next
146
153
 
147
154
  - 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.
155
+ - The tools: the npm package `@startside/swa`, its `validate` and `inline` commands (Appendix F).
156
+ - More examples: a blog (Example 4), a game (Example 6), a to-do list with an action of its own in the options menu
157
+ (Example 7), in Appendix A of the specification.
149
158
 
150
159
  ---
151
160
 
@@ -242,6 +251,8 @@ declare global {
242
251
  fullscreen: WidgetEvent<boolean>;
243
252
  /** Cancelable: canceling skips the refresh that follows. */
244
253
  settingschange: WidgetEvent<{ names: string[] }>;
254
+ /** One of the widget's own actions (declared in `<menu id="actions">`, 7.13) chosen in its options menu. */
255
+ action: WidgetEvent<{ id: string }>;
245
256
  }
246
257
 
247
258
  interface Widget extends EventTarget {
@@ -305,8 +316,9 @@ declare global {
305
316
  clearPeriodical(name: string): void;
306
317
 
307
318
  // 7.7 Lists and grips
308
- countGrip(box: Element, itemSelector: string, options?: CountGripOptions): void;
309
- heightGrip(box: Element, scroller: Element, options?: HeightGripOptions): void;
319
+ /** `box` an HTML element: the grip sets its style. */
320
+ countGrip(box: HTMLElement, itemSelector: string, options?: CountGripOptions): void;
321
+ heightGrip(box: HTMLElement, scroller: HTMLElement, options?: HeightGripOptions): void;
310
322
 
311
323
  // 7.8 Memory and stored data
312
324
  readonly storage: WidgetStorage;
@@ -346,7 +358,8 @@ declare global {
346
358
  share(data?: { text?: string; url?: string }): unknown;
347
359
  /** Absent where no widget can be added (a preview, a widget on its own page): `if (widget.addWidget)`. */
348
360
  addWidget?(spec: AddWidgetSpec): unknown;
349
- dragWidget(element: Element, spec: AddWidgetSpec | (() => AddWidgetSpec)): boolean;
361
+ /** `spec`, or a function giving it as the drag starts, given the drag's event; nothing given, the drag doesn't start. */
362
+ dragWidget(element: Element, spec: AddWidgetSpec | ((event: DragEvent) => AddWidgetSpec | null | undefined)): boolean;
350
363
  readonly canFullSize: boolean;
351
364
  readonly fullSize: boolean;
352
365
  openFull(): void;
@@ -354,6 +367,30 @@ declare global {
354
367
  /** Full screen: the browser's, or the widget alone over the window where the browser has none (7.13). */
355
368
  readonly fullScreen: boolean;
356
369
  setFullScreen(on: boolean): void;
370
+ /**
371
+ * Changes the state of actions the file declares (`<menu id="actions">`, 7.13), by id: greyed, hidden, another
372
+ * label. An id the file doesn't declare throws a TypeError. States last while the widget runs.
373
+ */
374
+ setActionStates(states: Record<string, WidgetActionState>): void;
375
+ /**
376
+ * A file the widget made, for the person to keep (7.13): the host checks its name, its extension and its type,
377
+ * and delivers it. `options.action`: the `action` event of a choice of an action whose declaration carries
378
+ * `data-save`; one file per choice, within 30 seconds. Resolves once the host handed the file to the browser
379
+ * (not "saved"); rejects with a DOMException: NotAllowedError (no such choice, or already used), NotSupportedError
380
+ * (a name, an extension or a type the action or the host doesn't take), QuotaExceededError (over 8 MiB),
381
+ * AbortError (the person cancelled). Without `options.action`: NotAllowedError.
382
+ */
383
+ saveFile(file: WidgetSaveFile, options?: { action?: WidgetEvent<{ id: string }> }): Promise<void>;
384
+ }
385
+
386
+ /** A file a widget saves (7.13). */
387
+ interface WidgetSaveFile {
388
+ /** Its name, with its extension: one the action declares (`data-save`). The host cleans it. */
389
+ name: string;
390
+ /** Its type, one its extension takes ('' for the usual one): "text/plain;charset=utf-8". */
391
+ type: string;
392
+ /** Its content, 8 MiB at most (a string's as UTF-8); copied as the call is made. */
393
+ data: string | Blob | ArrayBuffer;
357
394
  }
358
395
 
359
396
  /** Settings typed by the control that declares them (7.5): a checkbox's a boolean, a range's or a number's a number. */
@@ -544,9 +581,44 @@ declare global {
544
581
  alt?: string;
545
582
  title?: string;
546
583
  preview?: string;
584
+ /** A larger picture of the same, asked only when the person zooms in. */
585
+ zoom?: string;
547
586
  width?: number;
548
587
  height?: number;
549
- credit?: string;
588
+ /** What the picture's licence asks to go with it. A plain string is its credit text. */
589
+ credit?: PhotoCredit | string;
590
+ }
591
+
592
+ /**
593
+ * A picture's credit, in schema.org's ImageObject names (https://schema.org/ImageObject), every member optional.
594
+ * Addresses are `https`.
595
+ */
596
+ interface PhotoCredit {
597
+ /** The work's title. */
598
+ name?: string;
599
+ /** Who made it. */
600
+ creator?: string;
601
+ /** The credit line: who keeps or gives the picture (a museum, an agency). */
602
+ creditText?: string;
603
+ /** Who the licence says to name, as it asks ("Photo: …", "© …"). */
604
+ copyrightNotice?: string;
605
+ /** The licence's address. */
606
+ license?: string;
607
+ /** The picture's page at its source. */
608
+ url?: string;
609
+ }
610
+
611
+ /**
612
+ * What a running widget may change of an action its file declares (7.13). A field left out stays as it was; `null`
613
+ * puts it back to what the file declares.
614
+ */
615
+ interface WidgetActionState {
616
+ /** Greyed: nothing to act on. */
617
+ disabled?: boolean | null;
618
+ /** Not in the menu. */
619
+ hidden?: boolean | null;
620
+ /** Another label, 1 to 40 characters: a word that depends on its state, or a translation. */
621
+ label?: string | null;
550
622
  }
551
623
 
552
624
  interface AddWidgetSpec {
@@ -593,6 +665,7 @@ The full text: https://startside.app/swa/1.0/ (Markdown: https://startside.app/s
593
665
  - [6.5 Applying a setting](https://startside.app/swa/1.0/#65-applying-a-setting)
594
666
  - [6.6 Starting and refreshing](https://startside.app/swa/1.0/#66-starting-and-refreshing)
595
667
  - [6.7 Activation-gated operations](https://startside.app/swa/1.0/#67-activation-gated-operations)
668
+ - [6.8 The keyboard coming into a widget](https://startside.app/swa/1.0/#68-the-keyboard-coming-into-a-widget)
596
669
  - [7. The `Widget` interface](https://startside.app/swa/1.0/#7-the-widget-interface)
597
670
  - [7.1 The `widget` object](https://startside.app/swa/1.0/#71-the-widget-object)
598
671
  - [7.2 Identity and environment](https://startside.app/swa/1.0/#72-identity-and-environment)
@@ -114,29 +114,38 @@ What it shows, in order:
114
114
  | SHOULD NOT | Put fetched or typed text into markup (`innerHTML`, a `setBody` string) | 7.3 |
115
115
  | 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 |
116
116
  | SHOULD | Let the host set the width; the height is the content's; never `100vh` | 7.3.2 |
117
+ | SHOULD | While it loads, show a placeholder at the size of what's coming (a skeleton of its rows, its picture's box), not a one-line "Loading…": the widget doesn't change size as its content arrives | 7.3.1 |
117
118
  | 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 |
119
+ | SHOULD | Mark where the keyboard lands when the host moves the focus into the widget, when that isn't its first control: `autofocus` on a game's board (`<div class="board" tabindex="0" autofocus>`). Call `preventDefault()` on the Escape and arrow keys it uses itself: left uncancelled, a host may use Escape to leave the widget and an arrow to go to the next | 6.8 |
118
120
  | 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 |
119
121
  | SHOULD | Write colors with `light-dark()`, other dark-mode changes under `:root[data-color-scheme="dark"]`, not `prefers-color-scheme` | 4.7 |
120
122
  | 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 |
121
123
  | 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 |
122
124
  | SHOULD | Follow its width with a `ResizeObserver` on its own element when its layout depends on it | 7.3.2 |
123
125
  | SHOULD | Meet WCAG 2.2 AA: keyboard alone, names on controls, 4.5:1 text, `prefers-reduced-motion` | 14 |
126
+ | MUST | Show only pictures it may show (public domain, or a licence or permission that allows it), their required credits kept; a picture opened large carries its own: `widget.openPhoto({ src, alt, credit })` | 7.12 |
127
+ | MAY | Declare actions of its own for its options menu, in the file: `<menu id="actions" hidden>` with one `<button type="button" name="reset">Reset</button>` each, five at most (`disabled` or `hidden` as it starts, `data-confirm="…?"` for a question the host asks first). Answer the `action` event (`event.detail.id`), and change their state as the widget's does with `widget.setActionStates({ reset: { disabled: false } })` | 7.13 |
128
+ | MAY | Hand the person a file it makes, from one of those actions only: `data-save=".cook"` on its button, then `widget.saveFile({ name, type, data }, { action: event })` in its `action` listener | 7.13 |
124
129
  | 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 |
125
130
 
126
131
  ## Checklist
127
132
 
133
+ - [ ] `npx @startside/swa validate name.swa.html` reports no error (Appendix F): it reads the file without running it.
128
134
  - [ ] It opens in a browser, from disk and from a server, with no error in the widget or the console.
129
135
  - [ ] Each setting changed in the menu (▾) applies, and Refresh keeps what it should.
130
136
  - [ ] It reads well light and dark, narrow (300 pixels) and wide, maximized: open it as
131
137
  `name.swa.html#mode=dark&width=300`, then light and wider.
132
- - [ ] Everything works with the keyboard alone; the focus is visible and never lost.
138
+ - [ ] Everything works with the keyboard alone; the focus is visible and never lost. A game plays with its keys once the
139
+ focus is on it, and the keys it doesn't use are left uncancelled.
133
140
  - [ ] Saved data from an older version, or edited by hand, doesn't break it.
134
141
  - [ ] Nothing moves or runs when nobody uses it.
135
142
 
136
143
  ## Next
137
144
 
138
145
  - The types, for an editor: `https://startside.app/swa/1.0/swa.d.ts` (Appendix F).
139
- - More examples: a blog (Example 4), a game (Example 6), a to-do list (Example 7), in Appendix A of the specification.
146
+ - The tools: the npm package `@startside/swa`, its `validate` and `inline` commands (Appendix F).
147
+ - More examples: a blog (Example 4), a game (Example 6), a to-do list with an action of its own in the options menu
148
+ (Example 7), in Appendix A of the specification.
140
149
 
141
150
  ---
142
151