@kiosko/sdk 0.2.6 → 0.2.7
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/dist/plugin.d.ts +168 -5
- package/dist/plugin.js +4 -1
- package/dist/testing.d.ts +19 -1
- package/dist/testing.js +19 -0
- package/package.json +6 -1
- package/src/plugin.ts +162 -5
- package/src/testing.ts +32 -1
package/dist/plugin.d.ts
CHANGED
|
@@ -232,6 +232,64 @@ export interface AnimationContext<O, D> extends StateContext<O, D> {
|
|
|
232
232
|
/** Random numbers in [0, 1). Use these and not `Math.random`, so tests can seed them. */
|
|
233
233
|
rnd: () => number;
|
|
234
234
|
}
|
|
235
|
+
/** How much an alert matters: the panel's frame turns blue, amber or red. */
|
|
236
|
+
export type AlertLevel = 'info' | 'warn' | 'critical';
|
|
237
|
+
/** From least to most. */
|
|
238
|
+
export declare const ALERT_LEVELS: readonly AlertLevel[];
|
|
239
|
+
/**
|
|
240
|
+
* Something that must be seen from across the room (the panel has no
|
|
241
|
+
* sound): smoke, a leak, the doorbell, a call, `main` broken, a typhoon
|
|
242
|
+
* warning. Returned by a widget's or a source's `alerts`, decided from its
|
|
243
|
+
* data like `urgent`; Kiosko decides how it is shown: over everything, on
|
|
244
|
+
* every screen whose settings let that level through (the rest keep it in
|
|
245
|
+
* the editor's band), with a flashing frame and the text still and huge.
|
|
246
|
+
* Kiosko 0.2.7 and later; older ones ignore `alerts`.
|
|
247
|
+
*/
|
|
248
|
+
export interface Alert {
|
|
249
|
+
/**
|
|
250
|
+
* Stable while it is the same event, new for a new one (`smoke-kitchen`,
|
|
251
|
+
* `pipeline-4711`): an alert the user has seen ("Seen") stays hidden while
|
|
252
|
+
* the plugin keeps returning the same id, and shows again with a new id.
|
|
253
|
+
*/
|
|
254
|
+
id: string;
|
|
255
|
+
level: AlertLevel;
|
|
256
|
+
/** A few words, painted as big as the panel allows: "Smoke in the kitchen". */
|
|
257
|
+
title: Localized;
|
|
258
|
+
/** One short line under it: "Sensor 2 · since 14:05". */
|
|
259
|
+
text?: Localized;
|
|
260
|
+
/**
|
|
261
|
+
* Who published it, a few letters, painted small in a corner next to the
|
|
262
|
+
* time: "IGN", "NWS", "AEMET", "气象署". Name the authority when the alert
|
|
263
|
+
* is someone else's: their licences ask for it, and the user must know
|
|
264
|
+
* where it comes from. Kiosko 0.2.7 and later; older ones ignore it.
|
|
265
|
+
*/
|
|
266
|
+
source?: Localized;
|
|
267
|
+
/**
|
|
268
|
+
* A second line under `text`, to be read after it: the authority's own
|
|
269
|
+
* instruction ("Move away from the coast and go to high ground"), as it
|
|
270
|
+
* is. Painted smaller than the title and only as far as it fits. Kiosko
|
|
271
|
+
* 0.2.7 and later; older ones ignore it.
|
|
272
|
+
*/
|
|
273
|
+
detail?: Localized;
|
|
274
|
+
/**
|
|
275
|
+
* An icon of Lucide's (`flame`, `droplet`, `bell-ring`, `phone-incoming`,
|
|
276
|
+
* `activity`, `cloud-lightning`, `git-branch`…; see docs/plugins.md for
|
|
277
|
+
* those the panel draws) or one or two characters (`震`). Default: by level.
|
|
278
|
+
*/
|
|
279
|
+
icon?: string;
|
|
280
|
+
/** When it stops on its own (epoch ms). */
|
|
281
|
+
expiresAt?: number;
|
|
282
|
+
/** Or how long it lasts from when Kiosko first sees it, in ms. */
|
|
283
|
+
ttlMs?: number;
|
|
284
|
+
/** Whether "Seen" (or snoozing it) may hide it. Default true; `false` stays while the plugin returns it. */
|
|
285
|
+
dismissible?: boolean;
|
|
286
|
+
}
|
|
287
|
+
/** What a source's `alerts` is asked with. */
|
|
288
|
+
export interface SourceAlertContext<O, D> {
|
|
289
|
+
data: D | undefined;
|
|
290
|
+
options: O;
|
|
291
|
+
now: number;
|
|
292
|
+
}
|
|
235
293
|
/**
|
|
236
294
|
* When the widget must be repainted even though its data didn't change: a
|
|
237
295
|
* clock every second, a countdown every minute. Fewer repaints are fewer
|
|
@@ -317,6 +375,15 @@ export interface WidgetDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
317
375
|
urgent?: (ctx: StateContext<Infer<OF>, D>) => boolean;
|
|
318
376
|
/** Default of the instance's `takeOver` switch (keep the tile while urgent). Default true. */
|
|
319
377
|
takeOver?: boolean;
|
|
378
|
+
/**
|
|
379
|
+
* Alerts to show full-screen (see `Alert`): a smoke sensor going off, the
|
|
380
|
+
* pipeline of `main` failing. Plain and quick, from the data alone: it is
|
|
381
|
+
* asked for every instance on any page of an enabled screen (not only the
|
|
382
|
+
* one shown) whenever its data changes, and every few seconds. Return `[]`
|
|
383
|
+
* when there is nothing. Several instances of the widget returning the
|
|
384
|
+
* same `id` are one alert. Kiosko 0.2.7 and later.
|
|
385
|
+
*/
|
|
386
|
+
alerts?: (ctx: StateContext<Infer<OF>, D>) => Alert[];
|
|
320
387
|
/**
|
|
321
388
|
* Has nothing to list right now (no reviews, no tasks). Declaring it gives
|
|
322
389
|
* the widget a "hide when empty" switch (`hideWhenEmpty`): when on, an
|
|
@@ -369,10 +436,10 @@ export interface SourceDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
369
436
|
/** Global options, edited once in Settings → Sources. */
|
|
370
437
|
options?: OF;
|
|
371
438
|
/**
|
|
372
|
-
* Polled every `intervalMs` while some widget uses it
|
|
373
|
-
* the interval and the timeout in
|
|
374
|
-
* (`sources["plugin/source"].intervalMs` /
|
|
375
|
-
* of your own for them.
|
|
439
|
+
* Polled every `intervalMs` while some widget uses it (or always, see
|
|
440
|
+
* `background`). The user can change the interval and the timeout in
|
|
441
|
+
* Settings → Data sources (`sources["plugin/source"].intervalMs` /
|
|
442
|
+
* `.timeoutMs`): don't add options of your own for them.
|
|
376
443
|
*/
|
|
377
444
|
read?: (ctx: SourceContext<Infer<OF>>) => Promise<D>;
|
|
378
445
|
/** Default interval of `read`. Default: 30 s. */
|
|
@@ -390,6 +457,24 @@ export interface SourceDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
390
457
|
now: number;
|
|
391
458
|
locale: string;
|
|
392
459
|
}) => D;
|
|
460
|
+
/**
|
|
461
|
+
* Alerts to show full-screen (see `Alert`), from the source's latest data:
|
|
462
|
+
* like a widget's `alerts`, for alerts that belong to the data itself (a
|
|
463
|
+
* Home Assistant smoke sensor, an earthquake report). Asked while the
|
|
464
|
+
* source runs: while some widget uses it, or always if it runs in the
|
|
465
|
+
* `background`. Kiosko 0.2.7 and later.
|
|
466
|
+
*/
|
|
467
|
+
alerts?: (ctx: SourceAlertContext<Infer<OF>, D>) => Alert[];
|
|
468
|
+
/**
|
|
469
|
+
* May run with no widget using it, for its `alerts` alone (official
|
|
470
|
+
* warnings, earthquake reports): Settings → Data sources then offers a
|
|
471
|
+
* switch, "Watch for alerts without a widget", off by default
|
|
472
|
+
* (`sources["plugin/source"].background`). While it is on and the plugin
|
|
473
|
+
* is enabled, Kiosko reads (or watches) the source and asks its `alerts`
|
|
474
|
+
* even if no tile shows it. Only with `alerts`; Kiosko 0.2.7 and later,
|
|
475
|
+
* older ones ignore it (the source runs only while a widget uses it).
|
|
476
|
+
*/
|
|
477
|
+
background?: boolean;
|
|
393
478
|
/**
|
|
394
479
|
* Named lists of values for the editor to offer in options, made from
|
|
395
480
|
* this source's latest data (or its demo data before there is any): the
|
|
@@ -416,8 +501,29 @@ export interface InterludePlayer {
|
|
|
416
501
|
/** Paints frame `i` on a canvas of the full panel size. May be async (to decode a prerendered frame). */
|
|
417
502
|
draw: (g: Graphics, i: number) => void | Promise<void>;
|
|
418
503
|
}
|
|
504
|
+
/** A button of the Play page's pad: a game controller's, the keyboard's arrows and keys, or the phone's touch pad. */
|
|
505
|
+
export type PadKey = 'up' | 'down' | 'left' | 'right' | 'a' | 'b' | 'x' | 'y' | 'l' | 'r' | 'start' | 'select';
|
|
506
|
+
export declare const PAD_KEYS: readonly PadKey[];
|
|
507
|
+
/** A button pressed or let go on the Play page. */
|
|
508
|
+
export interface PadEvent {
|
|
509
|
+
key: PadKey;
|
|
510
|
+
pressed: boolean;
|
|
511
|
+
}
|
|
512
|
+
/** The player's buttons, for an interlude being played (see `InterludeDefinition.input`). */
|
|
513
|
+
export interface InterludeInput {
|
|
514
|
+
/** Calls `listener` for every button pressed or let go; returns what stops it. */
|
|
515
|
+
on(listener: (e: PadEvent) => void): () => void;
|
|
516
|
+
}
|
|
419
517
|
export interface InterludeContext<O> extends BaseContext {
|
|
420
518
|
options: O;
|
|
519
|
+
/**
|
|
520
|
+
* Someone is playing it from the editor's Play page (only for an
|
|
521
|
+
* interlude with `input: true`): their buttons. It then lasts while they
|
|
522
|
+
* play (no `maxSeconds`; a minute without a button ends it), and `frames`
|
|
523
|
+
* may be `Infinity`. Undefined when it plays at its time slot. Kiosko
|
|
524
|
+
* 0.2.7 and later.
|
|
525
|
+
*/
|
|
526
|
+
input?: InterludeInput;
|
|
421
527
|
width: number;
|
|
422
528
|
height: number;
|
|
423
529
|
/** Deterministic per slot: the same quarter hour plays the same story. */
|
|
@@ -435,6 +541,21 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
|
|
|
435
541
|
sources?: string[];
|
|
436
542
|
/** Frames per second it was designed for. USB panels top out around 12-24 fps. */
|
|
437
543
|
fps: number;
|
|
544
|
+
/**
|
|
545
|
+
* It can be played: the editor's Play page offers it, and when started
|
|
546
|
+
* from there `ctx.input` brings the player's buttons. Kiosko 0.2.7 and
|
|
547
|
+
* later.
|
|
548
|
+
*/
|
|
549
|
+
input?: boolean;
|
|
550
|
+
/**
|
|
551
|
+
* A short recording for the plugin store, relative to its package
|
|
552
|
+
* (`docs/<id>.webm`, 6–10 s, and a still `docs/<id>.jpg` for where video
|
|
553
|
+
* doesn't play).
|
|
554
|
+
*/
|
|
555
|
+
preview?: {
|
|
556
|
+
video?: string;
|
|
557
|
+
poster: string;
|
|
558
|
+
};
|
|
438
559
|
/** Builds the animation. May be slow (it runs before playing, not during). */
|
|
439
560
|
prepare: (ctx: InterludeContext<Infer<OF>>) => Promise<InterludePlayer | null>;
|
|
440
561
|
/** Don't interrupt now (someone waits for a permission, a meeting is about to start). */
|
|
@@ -450,7 +571,7 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
|
|
|
450
571
|
* package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
|
|
451
572
|
* it runs); the registry compares them with `satisfies`.
|
|
452
573
|
*/
|
|
453
|
-
export declare const SDK_VERSION = "0.2.
|
|
574
|
+
export declare const SDK_VERSION = "0.2.7";
|
|
454
575
|
/**
|
|
455
576
|
* What a plugin does on the machine, declared for the person who installs
|
|
456
577
|
* it: the Plugins page and the plugin store show it next to the plugin. It
|
|
@@ -548,6 +669,48 @@ export interface PluginDefinition {
|
|
|
548
669
|
interludes?: InterludeDefinition<any>[];
|
|
549
670
|
/** Page layouts the editor offers, built from its widgets (see `PageTemplate`). */
|
|
550
671
|
templates?: PageTemplate[];
|
|
672
|
+
/**
|
|
673
|
+
* The category it is browsed under in the plugin store when it has no
|
|
674
|
+
* widgets of its own (only interludes, say): `fun` or `scene`. With widgets,
|
|
675
|
+
* the store takes theirs.
|
|
676
|
+
*/
|
|
677
|
+
category?: Category;
|
|
678
|
+
/**
|
|
679
|
+
* Where it is useful, for the plugin store (see `PluginMarkets`): only in
|
|
680
|
+
* Spain (an electricity tariff), not where its service isn't offered.
|
|
681
|
+
*/
|
|
682
|
+
markets?: PluginMarkets;
|
|
683
|
+
/** Where to ask for help. Missing: `bugs` and `homepage` of package.json. */
|
|
684
|
+
support?: {
|
|
685
|
+
issues?: string;
|
|
686
|
+
discussions?: string;
|
|
687
|
+
docs?: string;
|
|
688
|
+
};
|
|
689
|
+
/** How it is sold. Only `free` for now: paid plugins are not there yet. */
|
|
690
|
+
pricing?: {
|
|
691
|
+
model: 'free';
|
|
692
|
+
};
|
|
693
|
+
/** A page to support its author (also `funding` in package.json). */
|
|
694
|
+
funding?: string;
|
|
695
|
+
/** What it costs to run, roughly, for the store (`memoryMb` while painting, `cpu`). */
|
|
696
|
+
resources?: {
|
|
697
|
+
memoryMb?: number;
|
|
698
|
+
cpu?: 'low' | 'medium' | 'high';
|
|
699
|
+
note?: Localized;
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Where a plugin is useful, as regions: ISO 3166-1 alpha-2 country codes
|
|
704
|
+
* (`ES`, `TW`) or `EU`. The store marks it ("only useful in Spain") and its
|
|
705
|
+
* "available in my region" filter uses it; it is never hidden from search.
|
|
706
|
+
*/
|
|
707
|
+
export interface PluginMarkets {
|
|
708
|
+
/** Only useful here (a country's tariff, a city's metro). */
|
|
709
|
+
only?: string[];
|
|
710
|
+
/** Its service isn't offered here. */
|
|
711
|
+
without?: string[];
|
|
712
|
+
/** What it needs there ("an account with Red Eléctrica"). */
|
|
713
|
+
note?: Localized;
|
|
551
714
|
}
|
|
552
715
|
export declare function defineWidget<OF extends ObjectField<any> = ObjectField<{}>, D = undefined>(w: WidgetDefinition<OF, D>): WidgetDefinition<OF, D>;
|
|
553
716
|
export declare function defineSource<OF extends ObjectField<any> = ObjectField<{}>, D = unknown>(s: SourceDefinition<OF, D>): SourceDefinition<OF, D>;
|
package/dist/plugin.js
CHANGED
|
@@ -9,13 +9,16 @@ export const CATEGORIES = [
|
|
|
9
9
|
{ id: 'scene', label: { en: 'Scenes', es: 'Escenas', de: 'Szenen', 'zh-Hant': '場景', 'zh-Hans': '场景' } },
|
|
10
10
|
{ id: 'fun', label: { en: 'Fun', es: 'Diversión', de: 'Spaß', 'zh-Hant': '趣味', 'zh-Hans': '趣味' } },
|
|
11
11
|
];
|
|
12
|
+
/** From least to most. */
|
|
13
|
+
export const ALERT_LEVELS = ['info', 'warn', 'critical'];
|
|
14
|
+
export const PAD_KEYS = ['up', 'down', 'left', 'right', 'a', 'b', 'x', 'y', 'l', 'r', 'start', 'select'];
|
|
12
15
|
/**
|
|
13
16
|
* The version of the plugin API this Kiosko speaks. A plugin says which
|
|
14
17
|
* versions it was written for in `PluginDefinition.sdk` (and in its
|
|
15
18
|
* package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
|
|
16
19
|
* it runs); the registry compares them with `satisfies`.
|
|
17
20
|
*/
|
|
18
|
-
export const SDK_VERSION = '0.2.
|
|
21
|
+
export const SDK_VERSION = '0.2.7';
|
|
19
22
|
/* Identity helpers: they only exist so TypeScript infers option and data types. */
|
|
20
23
|
export function defineWidget(w) {
|
|
21
24
|
return w;
|
package/dist/testing.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { type Canvas } from '@napi-rs/canvas';
|
|
18
18
|
import type { TimeFormat } from './format.ts';
|
|
19
|
-
import type { Box, PluginDefinition, WidgetDefinition } from './plugin.ts';
|
|
19
|
+
import type { Alert, Box, PluginDefinition, SourceDefinition, WidgetDefinition } from './plugin.ts';
|
|
20
20
|
import { type Theme } from './theme.ts';
|
|
21
21
|
export interface RenderOptions {
|
|
22
22
|
/** The instance's options (validated against the widget's schema, defaults filled in). Default: the demo's, if any. */
|
|
@@ -61,6 +61,24 @@ export interface RenderResult {
|
|
|
61
61
|
export declare function renderWidget(w: WidgetDefinition<any, any>, o?: RenderOptions): RenderResult;
|
|
62
62
|
/** Asks a widget's `urgent`, `idle`, `empty` or `visible` with the same inputs `renderWidget` would use. */
|
|
63
63
|
export declare function widgetState(w: WidgetDefinition<any, any>, hook: 'urgent' | 'idle' | 'empty' | 'visible', o?: RenderOptions): boolean | undefined;
|
|
64
|
+
/** Asks a widget's `alerts` with the same inputs `renderWidget` would use; `[]` when it has none. */
|
|
65
|
+
export declare function widgetAlerts(w: WidgetDefinition<any, any>, o?: RenderOptions): Alert[];
|
|
66
|
+
export interface SourceAlertOptions {
|
|
67
|
+
/** The source's options (validated against its schema, defaults filled in). */
|
|
68
|
+
options?: Record<string, unknown>;
|
|
69
|
+
/** Its latest data. Default: its `demo` data. */
|
|
70
|
+
data?: unknown;
|
|
71
|
+
now?: number;
|
|
72
|
+
/** For its `demo`. */
|
|
73
|
+
locale?: string;
|
|
74
|
+
/** Use the source's `demo` when `data` isn't given. Default true. */
|
|
75
|
+
demo?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Asks a source's `alerts` the way Kiosko does: its options validated with
|
|
79
|
+
* their defaults, its demo data unless given other; `[]` when it has none.
|
|
80
|
+
*/
|
|
81
|
+
export declare function sourceAlerts(s: SourceDefinition<any, any>, o?: SourceAlertOptions): Alert[];
|
|
64
82
|
export interface PluginIssue {
|
|
65
83
|
/** `plugin/widget`. */
|
|
66
84
|
type: string;
|
package/dist/testing.js
CHANGED
|
@@ -97,6 +97,25 @@ export function widgetState(w, hook, o = {}) {
|
|
|
97
97
|
const ctx = { options, data, sources, now, working: true, workday: DEFAULT_WORKDAY };
|
|
98
98
|
return fn(ctx);
|
|
99
99
|
}
|
|
100
|
+
/** Asks a widget's `alerts` with the same inputs `renderWidget` would use; `[]` when it has none. */
|
|
101
|
+
export function widgetAlerts(w, o = {}) {
|
|
102
|
+
if (!w.alerts)
|
|
103
|
+
return [];
|
|
104
|
+
const { now, options, data, sources } = resolve(w, o);
|
|
105
|
+
return w.alerts({ options, data, sources, now, working: true, workday: DEFAULT_WORKDAY });
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Asks a source's `alerts` the way Kiosko does: its options validated with
|
|
109
|
+
* their defaults, its demo data unless given other; `[]` when it has none.
|
|
110
|
+
*/
|
|
111
|
+
export function sourceAlerts(s, o = {}) {
|
|
112
|
+
if (!s.alerts)
|
|
113
|
+
return [];
|
|
114
|
+
const now = o.now ?? Date.UTC(2026, 10, 5, 9, 42);
|
|
115
|
+
const options = s.options ? validate(s.options, o.options ?? {}).value : {};
|
|
116
|
+
const data = 'data' in o ? o.data : o.demo === false ? undefined : s.demo?.({ now, locale: o.locale ?? 'en' });
|
|
117
|
+
return s.alerts({ data, options, now });
|
|
118
|
+
}
|
|
100
119
|
/**
|
|
101
120
|
* Paints every widget of a plugin with its demo data at its minimum and
|
|
102
121
|
* preferred sizes and a wide and a tall one, in every theme and in each
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiosko/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Plugin SDK for Kiosko: define widgets, data sources and interludes for small always-on LCD panels.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"source": "./src/testing.ts",
|
|
35
35
|
"types": "./dist/testing.d.ts",
|
|
36
36
|
"default": "./dist/testing.js"
|
|
37
|
+
},
|
|
38
|
+
"./semver": {
|
|
39
|
+
"source": "./src/semver.ts",
|
|
40
|
+
"types": "./dist/semver.d.ts",
|
|
41
|
+
"default": "./dist/semver.js"
|
|
37
42
|
}
|
|
38
43
|
},
|
|
39
44
|
"files": [
|
package/src/plugin.ts
CHANGED
|
@@ -246,6 +246,67 @@ export interface AnimationContext<O, D> extends StateContext<O, D> {
|
|
|
246
246
|
rnd: () => number;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/** How much an alert matters: the panel's frame turns blue, amber or red. */
|
|
250
|
+
export type AlertLevel = 'info' | 'warn' | 'critical';
|
|
251
|
+
/** From least to most. */
|
|
252
|
+
export const ALERT_LEVELS: readonly AlertLevel[] = ['info', 'warn', 'critical'];
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Something that must be seen from across the room (the panel has no
|
|
256
|
+
* sound): smoke, a leak, the doorbell, a call, `main` broken, a typhoon
|
|
257
|
+
* warning. Returned by a widget's or a source's `alerts`, decided from its
|
|
258
|
+
* data like `urgent`; Kiosko decides how it is shown: over everything, on
|
|
259
|
+
* every screen whose settings let that level through (the rest keep it in
|
|
260
|
+
* the editor's band), with a flashing frame and the text still and huge.
|
|
261
|
+
* Kiosko 0.2.7 and later; older ones ignore `alerts`.
|
|
262
|
+
*/
|
|
263
|
+
export interface Alert {
|
|
264
|
+
/**
|
|
265
|
+
* Stable while it is the same event, new for a new one (`smoke-kitchen`,
|
|
266
|
+
* `pipeline-4711`): an alert the user has seen ("Seen") stays hidden while
|
|
267
|
+
* the plugin keeps returning the same id, and shows again with a new id.
|
|
268
|
+
*/
|
|
269
|
+
id: string;
|
|
270
|
+
level: AlertLevel;
|
|
271
|
+
/** A few words, painted as big as the panel allows: "Smoke in the kitchen". */
|
|
272
|
+
title: Localized;
|
|
273
|
+
/** One short line under it: "Sensor 2 · since 14:05". */
|
|
274
|
+
text?: Localized;
|
|
275
|
+
/**
|
|
276
|
+
* Who published it, a few letters, painted small in a corner next to the
|
|
277
|
+
* time: "IGN", "NWS", "AEMET", "气象署". Name the authority when the alert
|
|
278
|
+
* is someone else's: their licences ask for it, and the user must know
|
|
279
|
+
* where it comes from. Kiosko 0.2.7 and later; older ones ignore it.
|
|
280
|
+
*/
|
|
281
|
+
source?: Localized;
|
|
282
|
+
/**
|
|
283
|
+
* A second line under `text`, to be read after it: the authority's own
|
|
284
|
+
* instruction ("Move away from the coast and go to high ground"), as it
|
|
285
|
+
* is. Painted smaller than the title and only as far as it fits. Kiosko
|
|
286
|
+
* 0.2.7 and later; older ones ignore it.
|
|
287
|
+
*/
|
|
288
|
+
detail?: Localized;
|
|
289
|
+
/**
|
|
290
|
+
* An icon of Lucide's (`flame`, `droplet`, `bell-ring`, `phone-incoming`,
|
|
291
|
+
* `activity`, `cloud-lightning`, `git-branch`…; see docs/plugins.md for
|
|
292
|
+
* those the panel draws) or one or two characters (`震`). Default: by level.
|
|
293
|
+
*/
|
|
294
|
+
icon?: string;
|
|
295
|
+
/** When it stops on its own (epoch ms). */
|
|
296
|
+
expiresAt?: number;
|
|
297
|
+
/** Or how long it lasts from when Kiosko first sees it, in ms. */
|
|
298
|
+
ttlMs?: number;
|
|
299
|
+
/** Whether "Seen" (or snoozing it) may hide it. Default true; `false` stays while the plugin returns it. */
|
|
300
|
+
dismissible?: boolean;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** What a source's `alerts` is asked with. */
|
|
304
|
+
export interface SourceAlertContext<O, D> {
|
|
305
|
+
data: D | undefined;
|
|
306
|
+
options: O;
|
|
307
|
+
now: number;
|
|
308
|
+
}
|
|
309
|
+
|
|
249
310
|
/**
|
|
250
311
|
* When the widget must be repainted even though its data didn't change: a
|
|
251
312
|
* clock every second, a countdown every minute. Fewer repaints are fewer
|
|
@@ -320,6 +381,15 @@ export interface WidgetDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
320
381
|
urgent?: (ctx: StateContext<Infer<OF>, D>) => boolean;
|
|
321
382
|
/** Default of the instance's `takeOver` switch (keep the tile while urgent). Default true. */
|
|
322
383
|
takeOver?: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Alerts to show full-screen (see `Alert`): a smoke sensor going off, the
|
|
386
|
+
* pipeline of `main` failing. Plain and quick, from the data alone: it is
|
|
387
|
+
* asked for every instance on any page of an enabled screen (not only the
|
|
388
|
+
* one shown) whenever its data changes, and every few seconds. Return `[]`
|
|
389
|
+
* when there is nothing. Several instances of the widget returning the
|
|
390
|
+
* same `id` are one alert. Kiosko 0.2.7 and later.
|
|
391
|
+
*/
|
|
392
|
+
alerts?: (ctx: StateContext<Infer<OF>, D>) => Alert[];
|
|
323
393
|
/**
|
|
324
394
|
* Has nothing to list right now (no reviews, no tasks). Declaring it gives
|
|
325
395
|
* the widget a "hide when empty" switch (`hideWhenEmpty`): when on, an
|
|
@@ -366,10 +436,10 @@ export interface SourceDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
366
436
|
/** Global options, edited once in Settings → Sources. */
|
|
367
437
|
options?: OF;
|
|
368
438
|
/**
|
|
369
|
-
* Polled every `intervalMs` while some widget uses it
|
|
370
|
-
* the interval and the timeout in
|
|
371
|
-
* (`sources["plugin/source"].intervalMs` /
|
|
372
|
-
* of your own for them.
|
|
439
|
+
* Polled every `intervalMs` while some widget uses it (or always, see
|
|
440
|
+
* `background`). The user can change the interval and the timeout in
|
|
441
|
+
* Settings → Data sources (`sources["plugin/source"].intervalMs` /
|
|
442
|
+
* `.timeoutMs`): don't add options of your own for them.
|
|
373
443
|
*/
|
|
374
444
|
read?: (ctx: SourceContext<Infer<OF>>) => Promise<D>;
|
|
375
445
|
/** Default interval of `read`. Default: 30 s. */
|
|
@@ -384,6 +454,24 @@ export interface SourceDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
384
454
|
*/
|
|
385
455
|
watch?: (ctx: SourceContext<Infer<OF>>, emit: (data: D) => void) => () => void;
|
|
386
456
|
demo?: (ctx: { now: number; locale: string }) => D;
|
|
457
|
+
/**
|
|
458
|
+
* Alerts to show full-screen (see `Alert`), from the source's latest data:
|
|
459
|
+
* like a widget's `alerts`, for alerts that belong to the data itself (a
|
|
460
|
+
* Home Assistant smoke sensor, an earthquake report). Asked while the
|
|
461
|
+
* source runs: while some widget uses it, or always if it runs in the
|
|
462
|
+
* `background`. Kiosko 0.2.7 and later.
|
|
463
|
+
*/
|
|
464
|
+
alerts?: (ctx: SourceAlertContext<Infer<OF>, D>) => Alert[];
|
|
465
|
+
/**
|
|
466
|
+
* May run with no widget using it, for its `alerts` alone (official
|
|
467
|
+
* warnings, earthquake reports): Settings → Data sources then offers a
|
|
468
|
+
* switch, "Watch for alerts without a widget", off by default
|
|
469
|
+
* (`sources["plugin/source"].background`). While it is on and the plugin
|
|
470
|
+
* is enabled, Kiosko reads (or watches) the source and asks its `alerts`
|
|
471
|
+
* even if no tile shows it. Only with `alerts`; Kiosko 0.2.7 and later,
|
|
472
|
+
* older ones ignore it (the source runs only while a widget uses it).
|
|
473
|
+
*/
|
|
474
|
+
background?: boolean;
|
|
387
475
|
/**
|
|
388
476
|
* Named lists of values for the editor to offer in options, made from
|
|
389
477
|
* this source's latest data (or its demo data before there is any): the
|
|
@@ -410,8 +498,32 @@ export interface InterludePlayer {
|
|
|
410
498
|
draw: (g: Graphics, i: number) => void | Promise<void>;
|
|
411
499
|
}
|
|
412
500
|
|
|
501
|
+
/** A button of the Play page's pad: a game controller's, the keyboard's arrows and keys, or the phone's touch pad. */
|
|
502
|
+
export type PadKey = 'up' | 'down' | 'left' | 'right' | 'a' | 'b' | 'x' | 'y' | 'l' | 'r' | 'start' | 'select';
|
|
503
|
+
export const PAD_KEYS: readonly PadKey[] = ['up', 'down', 'left', 'right', 'a', 'b', 'x', 'y', 'l', 'r', 'start', 'select'];
|
|
504
|
+
|
|
505
|
+
/** A button pressed or let go on the Play page. */
|
|
506
|
+
export interface PadEvent {
|
|
507
|
+
key: PadKey;
|
|
508
|
+
pressed: boolean;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** The player's buttons, for an interlude being played (see `InterludeDefinition.input`). */
|
|
512
|
+
export interface InterludeInput {
|
|
513
|
+
/** Calls `listener` for every button pressed or let go; returns what stops it. */
|
|
514
|
+
on(listener: (e: PadEvent) => void): () => void;
|
|
515
|
+
}
|
|
516
|
+
|
|
413
517
|
export interface InterludeContext<O> extends BaseContext {
|
|
414
518
|
options: O;
|
|
519
|
+
/**
|
|
520
|
+
* Someone is playing it from the editor's Play page (only for an
|
|
521
|
+
* interlude with `input: true`): their buttons. It then lasts while they
|
|
522
|
+
* play (no `maxSeconds`; a minute without a button ends it), and `frames`
|
|
523
|
+
* may be `Infinity`. Undefined when it plays at its time slot. Kiosko
|
|
524
|
+
* 0.2.7 and later.
|
|
525
|
+
*/
|
|
526
|
+
input?: InterludeInput;
|
|
415
527
|
width: number;
|
|
416
528
|
height: number;
|
|
417
529
|
/** Deterministic per slot: the same quarter hour plays the same story. */
|
|
@@ -430,6 +542,18 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
|
|
|
430
542
|
sources?: string[];
|
|
431
543
|
/** Frames per second it was designed for. USB panels top out around 12-24 fps. */
|
|
432
544
|
fps: number;
|
|
545
|
+
/**
|
|
546
|
+
* It can be played: the editor's Play page offers it, and when started
|
|
547
|
+
* from there `ctx.input` brings the player's buttons. Kiosko 0.2.7 and
|
|
548
|
+
* later.
|
|
549
|
+
*/
|
|
550
|
+
input?: boolean;
|
|
551
|
+
/**
|
|
552
|
+
* A short recording for the plugin store, relative to its package
|
|
553
|
+
* (`docs/<id>.webm`, 6–10 s, and a still `docs/<id>.jpg` for where video
|
|
554
|
+
* doesn't play).
|
|
555
|
+
*/
|
|
556
|
+
preview?: { video?: string; poster: string };
|
|
433
557
|
/** Builds the animation. May be slow (it runs before playing, not during). */
|
|
434
558
|
prepare: (ctx: InterludeContext<Infer<OF>>) => Promise<InterludePlayer | null>;
|
|
435
559
|
/** Don't interrupt now (someone waits for a permission, a meeting is about to start). */
|
|
@@ -442,7 +566,7 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
|
|
|
442
566
|
* package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
|
|
443
567
|
* it runs); the registry compares them with `satisfies`.
|
|
444
568
|
*/
|
|
445
|
-
export const SDK_VERSION = '0.2.
|
|
569
|
+
export const SDK_VERSION = '0.2.7';
|
|
446
570
|
|
|
447
571
|
/**
|
|
448
572
|
* What a plugin does on the machine, declared for the person who installs
|
|
@@ -545,6 +669,39 @@ export interface PluginDefinition {
|
|
|
545
669
|
interludes?: InterludeDefinition<any>[];
|
|
546
670
|
/** Page layouts the editor offers, built from its widgets (see `PageTemplate`). */
|
|
547
671
|
templates?: PageTemplate[];
|
|
672
|
+
/**
|
|
673
|
+
* The category it is browsed under in the plugin store when it has no
|
|
674
|
+
* widgets of its own (only interludes, say): `fun` or `scene`. With widgets,
|
|
675
|
+
* the store takes theirs.
|
|
676
|
+
*/
|
|
677
|
+
category?: Category;
|
|
678
|
+
/**
|
|
679
|
+
* Where it is useful, for the plugin store (see `PluginMarkets`): only in
|
|
680
|
+
* Spain (an electricity tariff), not where its service isn't offered.
|
|
681
|
+
*/
|
|
682
|
+
markets?: PluginMarkets;
|
|
683
|
+
/** Where to ask for help. Missing: `bugs` and `homepage` of package.json. */
|
|
684
|
+
support?: { issues?: string; discussions?: string; docs?: string };
|
|
685
|
+
/** How it is sold. Only `free` for now: paid plugins are not there yet. */
|
|
686
|
+
pricing?: { model: 'free' };
|
|
687
|
+
/** A page to support its author (also `funding` in package.json). */
|
|
688
|
+
funding?: string;
|
|
689
|
+
/** What it costs to run, roughly, for the store (`memoryMb` while painting, `cpu`). */
|
|
690
|
+
resources?: { memoryMb?: number; cpu?: 'low' | 'medium' | 'high'; note?: Localized };
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Where a plugin is useful, as regions: ISO 3166-1 alpha-2 country codes
|
|
695
|
+
* (`ES`, `TW`) or `EU`. The store marks it ("only useful in Spain") and its
|
|
696
|
+
* "available in my region" filter uses it; it is never hidden from search.
|
|
697
|
+
*/
|
|
698
|
+
export interface PluginMarkets {
|
|
699
|
+
/** Only useful here (a country's tariff, a city's metro). */
|
|
700
|
+
only?: string[];
|
|
701
|
+
/** Its service isn't offered here. */
|
|
702
|
+
without?: string[];
|
|
703
|
+
/** What it needs there ("an account with Red Eléctrica"). */
|
|
704
|
+
note?: Localized;
|
|
548
705
|
}
|
|
549
706
|
|
|
550
707
|
/* Identity helpers: they only exist so TypeScript infers option and data types. */
|
package/src/testing.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { createCanvas, loadImage, type Canvas } from '@napi-rs/canvas';
|
|
|
18
18
|
import * as kit from '@loksly/lcd-canvas-kit';
|
|
19
19
|
import { createBaseContext } from './context.ts';
|
|
20
20
|
import type { TimeFormat } from './format.ts';
|
|
21
|
-
import type { Box, PluginDefinition, RenderContext, StateContext, WidgetDefinition } from './plugin.ts';
|
|
21
|
+
import type { Alert, Box, PluginDefinition, RenderContext, SourceDefinition, StateContext, WidgetDefinition } from './plugin.ts';
|
|
22
22
|
import { validate } from './schema.ts';
|
|
23
23
|
import { THEMES, themeById, type Theme } from './theme.ts';
|
|
24
24
|
import { DEFAULT_WORKDAY } from './workday.ts';
|
|
@@ -138,6 +138,37 @@ export function widgetState(w: WidgetDefinition<any, any>, hook: 'urgent' | 'idl
|
|
|
138
138
|
return fn(ctx);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/** Asks a widget's `alerts` with the same inputs `renderWidget` would use; `[]` when it has none. */
|
|
142
|
+
export function widgetAlerts(w: WidgetDefinition<any, any>, o: RenderOptions = {}): Alert[] {
|
|
143
|
+
if (!w.alerts) return [];
|
|
144
|
+
const { now, options, data, sources } = resolve(w, o);
|
|
145
|
+
return w.alerts({ options, data, sources, now, working: true, workday: DEFAULT_WORKDAY });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface SourceAlertOptions {
|
|
149
|
+
/** The source's options (validated against its schema, defaults filled in). */
|
|
150
|
+
options?: Record<string, unknown>;
|
|
151
|
+
/** Its latest data. Default: its `demo` data. */
|
|
152
|
+
data?: unknown;
|
|
153
|
+
now?: number;
|
|
154
|
+
/** For its `demo`. */
|
|
155
|
+
locale?: string;
|
|
156
|
+
/** Use the source's `demo` when `data` isn't given. Default true. */
|
|
157
|
+
demo?: boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Asks a source's `alerts` the way Kiosko does: its options validated with
|
|
162
|
+
* their defaults, its demo data unless given other; `[]` when it has none.
|
|
163
|
+
*/
|
|
164
|
+
export function sourceAlerts(s: SourceDefinition<any, any>, o: SourceAlertOptions = {}): Alert[] {
|
|
165
|
+
if (!s.alerts) return [];
|
|
166
|
+
const now = o.now ?? Date.UTC(2026, 10, 5, 9, 42);
|
|
167
|
+
const options = s.options ? (validate(s.options, o.options ?? {}).value as Record<string, unknown>) : {};
|
|
168
|
+
const data = 'data' in o ? o.data : o.demo === false ? undefined : s.demo?.({ now, locale: o.locale ?? 'en' });
|
|
169
|
+
return s.alerts({ data, options, now });
|
|
170
|
+
}
|
|
171
|
+
|
|
141
172
|
export interface PluginIssue {
|
|
142
173
|
/** `plugin/widget`. */
|
|
143
174
|
type: string;
|