@kiosko/sdk 0.2.4 → 0.2.6

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/src/plugin.ts CHANGED
@@ -20,7 +20,7 @@
20
20
  import type { Canvas, Image, SKRSContext2D, createCanvas, loadImage } from '@napi-rs/canvas';
21
21
  import type * as Kit from '@loksly/lcd-canvas-kit';
22
22
  import type { Formatters } from './format.ts';
23
- import type { Localized } from './i18n.ts';
23
+ import type { Localized, PluralForms } from './i18n.ts';
24
24
  import type { Field, Infer, ObjectField } from './schema.ts';
25
25
  import type { Theme } from './theme.ts';
26
26
  import type { Workday } from './workday.ts';
@@ -32,6 +32,17 @@ export type { Canvas, Image };
32
32
  export interface CanvasApi {
33
33
  createCanvas: typeof createCanvas;
34
34
  loadImage: typeof loadImage;
35
+ /**
36
+ * Loads an image already shrunk to the size it will be shown at: decoded,
37
+ * scaled and prepared in another thread, so neither this nor the first
38
+ * paint of it holds the panels up. A press photo of 14 megapixels shown
39
+ * in a 600×462 tile cost up to 130 ms in that first paint; shrunk, a few.
40
+ * Never enlarges. `cover`: at least `width` × `height` (it will be
41
+ * cropped); `contain`: at most that (it will be shown whole).
42
+ * Kiosko 0.2.5 and later: check that it's there and fall back to
43
+ * `loadImage` otherwise. Not in the browser demo.
44
+ */
45
+ loadImageScaled?: (src: string | Buffer | Uint8Array, size: { width: number; height: number; fit?: 'cover' | 'contain' }) => Promise<Image>;
35
46
  }
36
47
 
37
48
  /** A rectangle in panel pixels. */
@@ -51,15 +62,15 @@ export interface Size {
51
62
  export type Category = 'agents' | 'system' | 'time' | 'productivity' | 'dev' | 'info' | 'media' | 'scene' | 'fun';
52
63
 
53
64
  export const CATEGORIES: { id: Category; label: Localized }[] = [
54
- { id: 'agents', label: { en: 'AI agents', es: 'Agentes IA' } },
55
- { id: 'system', label: { en: 'System', es: 'Sistema' } },
56
- { id: 'time', label: { en: 'Time & calendar', es: 'Tiempo y agenda' } },
57
- { id: 'productivity', label: { en: 'Productivity', es: 'Productividad' } },
58
- { id: 'dev', label: { en: 'Development', es: 'Desarrollo' } },
59
- { id: 'info', label: { en: 'News & world', es: 'Noticias y mundo' } },
60
- { id: 'media', label: { en: 'Media', es: 'Multimedia' } },
61
- { id: 'scene', label: { en: 'Scenes', es: 'Escenas' } },
62
- { id: 'fun', label: { en: 'Fun', es: 'Diversión' } },
65
+ { id: 'agents', label: { en: 'AI agents', es: 'Agentes IA', de: 'KI-Agenten', 'zh-Hant': 'AI 代理', 'zh-Hans': 'AI 智能体' } },
66
+ { id: 'system', label: { en: 'System', es: 'Sistema', de: 'System', 'zh-Hant': '系統', 'zh-Hans': '系统' } },
67
+ { id: 'time', label: { en: 'Time & calendar', es: 'Tiempo y agenda', de: 'Zeit & Kalender', 'zh-Hant': '時間與行事曆', 'zh-Hans': '时间与日历' } },
68
+ { id: 'productivity', label: { en: 'Productivity', es: 'Productividad', de: 'Produktivität', 'zh-Hant': '生產力', 'zh-Hans': '效率' } },
69
+ { id: 'dev', label: { en: 'Development', es: 'Desarrollo', de: 'Entwicklung', 'zh-Hant': '開發', 'zh-Hans': '开发' } },
70
+ { id: 'info', label: { en: 'News & world', es: 'Noticias y mundo', de: 'Nachrichten & Welt', 'zh-Hant': '新聞與世界', 'zh-Hans': '新闻与世界' } },
71
+ { id: 'media', label: { en: 'Media', es: 'Multimedia', de: 'Medien', 'zh-Hant': '多媒體', 'zh-Hans': '多媒体' } },
72
+ { id: 'scene', label: { en: 'Scenes', es: 'Escenas', de: 'Szenen', 'zh-Hant': '場景', 'zh-Hans': '场景' } },
73
+ { id: 'fun', label: { en: 'Fun', es: 'Diversión', de: 'Spaß', 'zh-Hant': '趣味', 'zh-Hans': '趣味' } },
63
74
  ];
64
75
 
65
76
  export interface Logger {
@@ -81,6 +92,18 @@ export interface BaseContext {
81
92
  locale: string;
82
93
  /** Picks the user's language from a `Localized` text. */
83
94
  t: (text: Localized) => string;
95
+ /**
96
+ * `{n} files` with the plural form the user's language asks for:
97
+ * `ctx.plural(n, { en: { one: '{n} file', other: '{n} files' }, 'zh-Hant': { other: '{n} 個檔案' } })`.
98
+ * Use it for any text with a count in it, rather than `n === 1 ? … : …`.
99
+ */
100
+ plural: (n: number, forms: Record<string, PluralForms>) => string;
101
+ /**
102
+ * Which of `available` (language tags) to use for this user: for tables
103
+ * kept one per language (`TABLES[ctx.pickLanguage(Object.keys(TABLES))]`).
104
+ * English when none fits, else the first.
105
+ */
106
+ pickLanguage: (available: readonly string[]) => string;
84
107
  /**
85
108
  * Times and lengths of time in the user's language and clock (Settings →
86
109
  * time format): `fmt.time(at)` "14:05" / "2:05 PM", `fmt.ago(at)`
@@ -419,7 +442,7 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
419
442
  * package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
420
443
  * it runs); the registry compares them with `satisfies`.
421
444
  */
422
- export const SDK_VERSION = '0.2.4';
445
+ export const SDK_VERSION = '0.2.6';
423
446
 
424
447
  /**
425
448
  * What a plugin does on the machine, declared for the person who installs
@@ -508,6 +531,15 @@ export interface PluginDefinition {
508
531
  optional?: string[];
509
532
  /** The operating systems it works on. Omitted: all. Also npm's `os` in package.json. */
510
533
  platforms?: Platform[];
534
+ /**
535
+ * The languages its texts come in, as BCP 47 tags, English first:
536
+ * `['en', 'es', 'zh-Hant', 'zh-Hans']`. Chinese goes by script (`zh-Hant`
537
+ * for Taiwan and Hong Kong, `zh-Hans` for mainland China), never a bare
538
+ * `zh`. Every `Localized` text of the plugin has them all (the linter
539
+ * says which lack one). Also `kiosko.languages` in package.json, so a
540
+ * catalogue knows without running it. Omitted: the ones its texts use.
541
+ */
542
+ languages?: string[];
511
543
  widgets?: WidgetDefinition<any, any>[];
512
544
  sources?: SourceDefinition<any, any>[];
513
545
  interludes?: InterludeDefinition<any>[];
package/src/schema.ts CHANGED
@@ -152,6 +152,9 @@ export const t = {
152
152
  export const FILTER_HELP: Localized = {
153
153
  en: 'Empty: all. Names or patterns, comma-separated: * matches anything, a leading ! leaves out (web, acme/*, !*-old).',
154
154
  es: 'Vacío: todos. Nombres o patrones separados por comas: * vale por cualquier cosa y un ! delante excluye (web, acme/*, !*-old).',
155
+ de: 'Leer: alle. Namen oder Muster, durch Kommas getrennt: * steht für alles, ein ! davor schließt aus (web, acme/*, !*-old).',
156
+ 'zh-Hant': '留空:全部。填入名稱或模式,以逗號分隔:* 代表任意字元,開頭加 ! 則排除(web, acme/*, !*-old)。',
157
+ 'zh-Hans': '留空:全部。填写名称或模式,用逗号分隔:* 匹配任意内容,开头加 ! 表示排除(web, acme/*, !*-old)。',
155
158
  };
156
159
 
157
160
  function clone<T>(v: T): T {
package/src/testing.ts CHANGED
@@ -149,13 +149,13 @@ export interface PluginIssue {
149
149
  /**
150
150
  * Paints every widget of a plugin with its demo data at its minimum and
151
151
  * 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
152
+ * language given (by default the ones the plugin declares), and lists what went wrong: a `render` that throws, one
153
153
  * that paints nothing, paints outside its box, or takes longer than
154
154
  * `slowMs` (Kiosko warns at 50 ms). An empty list is a pass.
155
155
  */
156
156
  export function checkPlugin(p: PluginDefinition, o: { locales?: string[]; themes?: string[]; slowMs?: number; extraSizes?: { w: number; h: number }[] } = {}): PluginIssue[] {
157
157
  const issues: PluginIssue[] = [];
158
- const locales = o.locales ?? ['en', 'es'];
158
+ const locales = o.locales ?? (p.languages?.length ? p.languages : ['en', 'es']);
159
159
  const themes = o.themes ?? THEMES.map((t) => t.id);
160
160
  const slow = o.slowMs ?? 50;
161
161
  for (const w of p.widgets ?? []) {