@kiosko/sdk 0.2.5 → 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/context.js +3 -1
- package/dist/format.d.ts +12 -3
- package/dist/format.js +64 -14
- package/dist/i18n.d.ts +60 -2
- package/dist/i18n.js +145 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/languages.d.ts +36 -0
- package/dist/languages.js +22 -0
- package/dist/list.js +10 -7
- package/dist/location.js +4 -4
- package/dist/plugin.d.ts +190 -6
- package/dist/plugin.js +13 -10
- package/dist/schema.js +3 -0
- package/dist/testing.d.ts +20 -2
- package/dist/testing.js +21 -2
- package/package.json +16 -1
- package/src/context.ts +3 -1
- package/src/format.ts +87 -17
- package/src/i18n.ts +157 -4
- package/src/index.ts +1 -0
- package/src/languages.ts +54 -0
- package/src/list.ts +10 -7
- package/src/location.ts +4 -4
- package/src/plugin.ts +193 -15
- package/src/schema.ts +3 -0
- package/src/testing.ts +34 -3
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;
|
|
@@ -149,13 +180,13 @@ export interface PluginIssue {
|
|
|
149
180
|
/**
|
|
150
181
|
* Paints every widget of a plugin with its demo data at its minimum and
|
|
151
182
|
* preferred sizes and a wide and a tall one, in every theme and in each
|
|
152
|
-
* language given, and lists what went wrong: a `render` that throws, one
|
|
183
|
+
* language given (by default the ones the plugin declares), and lists what went wrong: a `render` that throws, one
|
|
153
184
|
* that paints nothing, paints outside its box, or takes longer than
|
|
154
185
|
* `slowMs` (Kiosko warns at 50 ms). An empty list is a pass.
|
|
155
186
|
*/
|
|
156
187
|
export function checkPlugin(p: PluginDefinition, o: { locales?: string[]; themes?: string[]; slowMs?: number; extraSizes?: { w: number; h: number }[] } = {}): PluginIssue[] {
|
|
157
188
|
const issues: PluginIssue[] = [];
|
|
158
|
-
const locales = o.locales ?? ['en', 'es'];
|
|
189
|
+
const locales = o.locales ?? (p.languages?.length ? p.languages : ['en', 'es']);
|
|
159
190
|
const themes = o.themes ?? THEMES.map((t) => t.id);
|
|
160
191
|
const slow = o.slowMs ?? 50;
|
|
161
192
|
for (const w of p.widgets ?? []) {
|