@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/i18n.ts
CHANGED
|
@@ -1,13 +1,166 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plugin texts can be a plain string (shown as is) or a map by language.
|
|
3
|
-
* The editor and the panel pick the user's locale
|
|
4
|
-
* first one available.
|
|
3
|
+
* The editor and the panel pick the user's locale (see `pickLocale`), then
|
|
4
|
+
* English, then the first one available.
|
|
5
|
+
*
|
|
6
|
+
* Chinese goes by script: write `zh-Hant` (Taiwan, Hong Kong) and `zh-Hans`
|
|
7
|
+
* (mainland China). `zh-TW` and `zh-CN` work too; a bare `zh` is read as
|
|
8
|
+
* Simplified and never shown to someone who reads Traditional. The same
|
|
9
|
+
* holds for any language written in two scripts (`sr-Latn`, `sr-Cyrl`).
|
|
5
10
|
*/
|
|
6
11
|
export type Localized = string | ({ en: string } & Partial<Record<string, string>>);
|
|
7
12
|
|
|
13
|
+
/** Old or other codes for the same language, as Intl leaves them. */
|
|
14
|
+
const ALIASES: Record<string, string> = { iw: 'he', in: 'id', ji: 'yi', tl: 'fil', no: 'nb', cmn: 'zh' };
|
|
15
|
+
/** Languages that read texts written for another one: Cantonese reads Chinese. */
|
|
16
|
+
const READS: Record<string, string> = { yue: 'zh', nn: 'nb' };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A language tag as Intl understands it, or null: POSIX forms cleaned
|
|
20
|
+
* (`zh_TW.UTF-8` → `zh-TW`, `sr_RS@latin` → `sr-Latn-RS`), old codes mapped
|
|
21
|
+
* (`iw` → `he`), case fixed.
|
|
22
|
+
*/
|
|
23
|
+
export function parseLocale(tag: string | undefined): Intl.Locale | null {
|
|
24
|
+
if (!tag) return null;
|
|
25
|
+
let t = tag.trim();
|
|
26
|
+
const latin = /@latin\b/i.test(t);
|
|
27
|
+
t = t.replace(/[.@].*$/, '').replace(/_/g, '-');
|
|
28
|
+
if (!t || t === 'C' || t === 'POSIX') return null;
|
|
29
|
+
try {
|
|
30
|
+
let l = new Intl.Locale(Intl.getCanonicalLocales(t)[0]!);
|
|
31
|
+
const alias = ALIASES[l.language];
|
|
32
|
+
if (alias) l = new Intl.Locale(alias, { ...(l.script ? { script: l.script } : {}), ...(l.region ? { region: l.region } : {}) });
|
|
33
|
+
if (latin && !l.script) l = new Intl.Locale(l.language, { script: 'Latn', ...(l.region ? { region: l.region } : {}) });
|
|
34
|
+
return l;
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Latin American regions: they read `es-419` (or the Mexican variant) before Spain's. */
|
|
41
|
+
const LATAM = new Set(['419', 'AR', 'BO', 'CL', 'CO', 'CR', 'CU', 'DO', 'EC', 'GT', 'HN', 'MX', 'NI', 'PA', 'PE', 'PR', 'PY', 'SV', 'US', 'UY', 'VE']);
|
|
42
|
+
/** Portuguese outside Brazil reads Portugal's before Brazil's. */
|
|
43
|
+
const PT_PT = new Set(['PT', 'AO', 'MZ', 'CV', 'GW', 'ST', 'TL', 'MO', 'GQ', 'LU', 'CH']);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The best of `available` (language tags, any case) for someone reading in
|
|
47
|
+
* `locale`, or undefined if none fits (the caller falls back to English).
|
|
48
|
+
*
|
|
49
|
+
* The same language and the same script, never another script: a reader
|
|
50
|
+
* of Traditional Chinese never gets Simplified (a bare `zh` is
|
|
51
|
+
* Simplified), nor a reader of Serbian in Latin letters Cyrillic. Among
|
|
52
|
+
* those: the exact tag, then the same region, then the region's usual
|
|
53
|
+
* variant (`es-419`/`es-MX` for Latin America, `pt-PT` outside Brazil),
|
|
54
|
+
* then the least specific one (`es` for `es-CL`), then any.
|
|
55
|
+
*/
|
|
56
|
+
export function pickLocale(available: readonly string[], locale: string | undefined): string | undefined {
|
|
57
|
+
if (!locale || !available.length) return undefined;
|
|
58
|
+
const exact = available.find((k) => k.toLowerCase() === locale.replace(/_/g, '-').toLowerCase());
|
|
59
|
+
if (exact) return exact;
|
|
60
|
+
const want = parseLocale(locale);
|
|
61
|
+
if (!want) return undefined;
|
|
62
|
+
const w = want.maximize();
|
|
63
|
+
const lang = READS[w.language] ?? w.language;
|
|
64
|
+
const fits = available
|
|
65
|
+
.map((k) => ({ k, l: parseLocale(k) }))
|
|
66
|
+
.filter((c): c is { k: string; l: Intl.Locale } => !!c.l)
|
|
67
|
+
.map((c) => ({ ...c, m: c.l.maximize() }))
|
|
68
|
+
.filter((c) => (READS[c.m.language] ?? c.m.language) === lang && c.m.script === w.script);
|
|
69
|
+
if (!fits.length) return undefined;
|
|
70
|
+
const same = (a: Intl.Locale, b: Intl.Locale) => a.baseName === b.baseName;
|
|
71
|
+
const byTag = fits.find((c) => same(c.l, want));
|
|
72
|
+
if (byTag) return byTag.k;
|
|
73
|
+
if (w.region) {
|
|
74
|
+
const byRegion = fits.find((c) => c.m.region === w.region && c.l.region);
|
|
75
|
+
if (byRegion) return byRegion.k;
|
|
76
|
+
const usual = (r: string) => (lang === 'es' && LATAM.has(w.region!) ? ['419', 'MX'].includes(r) : lang === 'pt' && PT_PT.has(w.region!) ? r === 'PT' : false);
|
|
77
|
+
const variant = fits.find((c) => c.l.region && usual(c.l.region));
|
|
78
|
+
if (variant) return variant.k;
|
|
79
|
+
}
|
|
80
|
+
// The least specific: `es` before `es-ES`, `zh-Hant` before `zh-TW`.
|
|
81
|
+
const plain = [...fits].sort((a, b) => a.l.baseName.split('-').length - b.l.baseName.split('-').length);
|
|
82
|
+
return plain[0]!.k;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Plural forms of a text, as Intl.PluralRules names them; `other` is required. */
|
|
86
|
+
export type PluralForms = Partial<Record<Intl.LDMLPluralRule, string>> & { other: string };
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `{n} files` in the user's language, with the plural form its rules ask
|
|
90
|
+
* for (Polish has four, Chinese one): `forms` by language, `{n}` filled in
|
|
91
|
+
* with the number written the language's way.
|
|
92
|
+
*/
|
|
93
|
+
export function plural(n: number, forms: Record<string, PluralForms>, locale = 'en'): string {
|
|
94
|
+
const key = pickLocale(Object.keys(forms), locale) ?? (forms.en ? 'en' : Object.keys(forms)[0]!);
|
|
95
|
+
const f = forms[key]!;
|
|
96
|
+
let rule: Intl.LDMLPluralRule = 'other';
|
|
97
|
+
try {
|
|
98
|
+
rule = new Intl.PluralRules(key).select(n);
|
|
99
|
+
} catch {
|
|
100
|
+
/* an odd tag: other */
|
|
101
|
+
}
|
|
102
|
+
const text = f[rule] ?? f.other;
|
|
103
|
+
let num = String(n);
|
|
104
|
+
try {
|
|
105
|
+
num = new Intl.NumberFormat(key).format(n);
|
|
106
|
+
} catch {
|
|
107
|
+
/* as is */
|
|
108
|
+
}
|
|
109
|
+
return text.replaceAll('{n}', num);
|
|
110
|
+
}
|
|
111
|
+
|
|
8
112
|
export function localize(text: Localized | undefined, locale = 'en'): string {
|
|
9
113
|
if (text === undefined) return '';
|
|
10
114
|
if (typeof text === 'string') return text;
|
|
11
|
-
const
|
|
12
|
-
return
|
|
115
|
+
const key = pickLocale(Object.keys(text), locale);
|
|
116
|
+
return (key ? text[key] : undefined) ?? text.en ?? Object.values(text).find((v) => typeof v === 'string') ?? '';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The Han writing a locale reads in, for picking glyphs: the same character
|
|
121
|
+
* is drawn differently in Taiwan (`Hant`), Hong Kong (`Hant-HK`), mainland
|
|
122
|
+
* China (`Hans`), Japan (`Jpan`) and Korea (`Kore`). `null` for locales
|
|
123
|
+
* that do not write with Han characters.
|
|
124
|
+
*
|
|
125
|
+
* Goes by script, not by region code: `zh-TW`, `zh-Hant` and `zh-MO` are
|
|
126
|
+
* Traditional, `zh`, `zh-CN` and `zh-SG` Simplified.
|
|
127
|
+
*/
|
|
128
|
+
export type HanScript = 'Hant' | 'Hant-HK' | 'Hans' | 'Jpan' | 'Kore';
|
|
129
|
+
|
|
130
|
+
export function hanScript(locale: string | undefined): HanScript | null {
|
|
131
|
+
const l = parseLocale(locale || 'en');
|
|
132
|
+
if (!l) return null;
|
|
133
|
+
const full = l.maximize();
|
|
134
|
+
switch (READS[full.language] ?? full.language) {
|
|
135
|
+
case 'zh':
|
|
136
|
+
if (full.script === 'Hant') return full.region === 'HK' || full.region === 'MO' ? 'Hant-HK' : 'Hant';
|
|
137
|
+
return 'Hans';
|
|
138
|
+
case 'ja':
|
|
139
|
+
return 'Jpan';
|
|
140
|
+
case 'ko':
|
|
141
|
+
return 'Kore';
|
|
142
|
+
default:
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* An error to show the user, in their language: `throw new PluginError({
|
|
149
|
+
* en: 'Set your place in Settings', 'zh-Hant': '請在設定中設定位置', … })`.
|
|
150
|
+
* Its `message` is the English one (logs); Kiosko shows `text` in the
|
|
151
|
+
* user's language in the editor and on the tile.
|
|
152
|
+
*/
|
|
153
|
+
export class PluginError extends Error {
|
|
154
|
+
readonly text: Localized;
|
|
155
|
+
constructor(text: Localized, options?: { cause?: unknown }) {
|
|
156
|
+
super(localize(text, 'en'), options);
|
|
157
|
+
this.name = 'PluginError';
|
|
158
|
+
this.text = text;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** What to show for an error: a PluginError's text in `locale`, else the message. */
|
|
163
|
+
export function errorMessage(err: unknown, locale = 'en'): string {
|
|
164
|
+
if (err instanceof Error && 'text' in err && (err as PluginError).text !== undefined) return localize((err as PluginError).text, locale);
|
|
165
|
+
return err instanceof Error ? err.message : String(err);
|
|
13
166
|
}
|
package/src/index.ts
CHANGED
package/src/languages.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The languages Kiosko speaks: the editor, the site, the panel's words for
|
|
3
|
+
* times (ctx.fmt) and the official plugins. One list, read by all of them;
|
|
4
|
+
* a test (packages/web/landing/languages.test.ts) checks that each has its
|
|
5
|
+
* dictionary, site page, time words and plugin texts. Adding a language
|
|
6
|
+
* starts here (CONTRIBUTING.md, "Translations").
|
|
7
|
+
*/
|
|
8
|
+
export interface Language {
|
|
9
|
+
/** BCP 47 tag, as the texts are keyed (`es`, `zh-Hant`). */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Its name in itself, for the language pickers. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** The locale the panel paints the site's samples in (dates, times): `zh-TW` for `zh-Hant`. */
|
|
14
|
+
panel: string;
|
|
15
|
+
/** Open Graph locale of its site page (`zh_TW`). */
|
|
16
|
+
ogLocale: string;
|
|
17
|
+
/** What its site page is declared to be for (`hreflang`); English is also `x-default`. */
|
|
18
|
+
hreflang: string[];
|
|
19
|
+
/** Writing direction. Right-to-left is not drawn right on the panel yet. */
|
|
20
|
+
dir: 'ltr' | 'rtl';
|
|
21
|
+
/**
|
|
22
|
+
* Where this language's readers live, the services some plugins need may not
|
|
23
|
+
* be offered. The site, the sample config and the editor's tour leave those
|
|
24
|
+
* plugins out for it (`without`), lead with others (`first`) and paint these
|
|
25
|
+
* widgets in place of the missing ones (`instead`, type by type).
|
|
26
|
+
*/
|
|
27
|
+
plugins?: { without: readonly string[]; first: readonly string[]; instead: Readonly<Record<string, string>> };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Simplified Chinese is read in mainland China, where Claude (and Gemini) are
|
|
32
|
+
* not offered: no AI-agent, cats-room nor Claude-usage plugins there, and local
|
|
33
|
+
* models (Qwen, DeepSeek… on your own GPU) in their place.
|
|
34
|
+
*/
|
|
35
|
+
const MAINLAND_CHINA: NonNullable<Language['plugins']> = {
|
|
36
|
+
without: ['agents', 'cats', 'usage'],
|
|
37
|
+
first: ['llm', 'gpu'],
|
|
38
|
+
instead: { 'agents/summary': 'llm/status', 'agents/sessions': 'llm/models', 'usage/rail': 'gpu/cards', 'cats/room': 'gpu/history' },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const LANGUAGES: readonly Language[] = [
|
|
42
|
+
{ id: 'en', name: 'English', panel: 'en', ogLocale: 'en_US', hreflang: ['en', 'x-default'], dir: 'ltr' },
|
|
43
|
+
{ id: 'es', name: 'Español', panel: 'es', ogLocale: 'es_ES', hreflang: ['es'], dir: 'ltr' },
|
|
44
|
+
{ id: 'de', name: 'Deutsch', panel: 'de', ogLocale: 'de_DE', hreflang: ['de'], dir: 'ltr' },
|
|
45
|
+
{ id: 'zh-Hant', name: '繁體中文', panel: 'zh-TW', ogLocale: 'zh_TW', hreflang: ['zh-Hant', 'zh-TW', 'zh-HK'], dir: 'ltr' },
|
|
46
|
+
{ id: 'zh-Hans', name: '简体中文', panel: 'zh-CN', ogLocale: 'zh_CN', hreflang: ['zh-Hans', 'zh-CN'], dir: 'ltr', plugins: MAINLAND_CHINA },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
export const LANGUAGE_IDS: readonly string[] = LANGUAGES.map((l) => l.id);
|
|
50
|
+
|
|
51
|
+
/** The language with this id (`zh-Hant`), if Kiosko speaks it. */
|
|
52
|
+
export function languageById(id: string): Language | undefined {
|
|
53
|
+
return LANGUAGES.find((l) => l.id === id);
|
|
54
|
+
}
|
package/src/list.ts
CHANGED
|
@@ -34,9 +34,9 @@ export type ListLayout = 'one-line' | 'detailed';
|
|
|
34
34
|
export type ListLayoutChoice = 'auto' | ListLayout;
|
|
35
35
|
|
|
36
36
|
const LAYOUT_LABELS: Record<ListLayoutChoice, Localized> = {
|
|
37
|
-
auto: { en: 'Automatic', es: 'Automático' },
|
|
38
|
-
'one-line': { en: 'One line', es: 'Una línea' },
|
|
39
|
-
detailed: { en: 'Detailed', es: 'Detallado' },
|
|
37
|
+
auto: { en: 'Automatic', es: 'Automático', de: 'Automatisch', 'zh-Hant': '自動', 'zh-Hans': '自动' },
|
|
38
|
+
'one-line': { en: 'One line', es: 'Una línea', de: 'Eine Zeile', 'zh-Hant': '單行', 'zh-Hans': '单行' },
|
|
39
|
+
detailed: { en: 'Detailed', es: 'Detallado', de: 'Ausführlich', 'zh-Hant': '詳細', 'zh-Hans': '详细' },
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const rowsField = (def: number): NumberField =>
|
|
@@ -44,10 +44,13 @@ const rowsField = (def: number): NumberField =>
|
|
|
44
44
|
default: def,
|
|
45
45
|
min: 0,
|
|
46
46
|
max: 30,
|
|
47
|
-
label: { en: 'Rows', es: 'Filas' },
|
|
47
|
+
label: { en: 'Rows', es: 'Filas', de: 'Zeilen', 'zh-Hant': '列數', 'zh-Hans': '行数' },
|
|
48
48
|
help: {
|
|
49
49
|
en: '0 = as many as fit. A number shows that many, in rows of a readable size (fewer when the tile is too small for them); the rest are counted in "+N more".',
|
|
50
50
|
es: '0 = las que quepan. Con un número se ven esas, en filas de un tamaño legible (menos si la tesela no da para ellas); el resto se cuenta en «+N más».',
|
|
51
|
+
de: '0 = so viele, wie passen. Eine Zahl zeigt so viele, in Zeilen lesbarer Größe (weniger, wenn die Kachel dafür zu klein ist); der Rest wird als „+N weitere“ gezählt.',
|
|
52
|
+
'zh-Hant': '0 = 盡量放滿。填數字則顯示該數量,並以易讀的大小排列(方格太小時會減少);其餘的計入「還有 N 個」。',
|
|
53
|
+
'zh-Hans': '0 = 尽量放满。填数字则显示该数量,并以易读的大小排列(格子太小时会减少);其余的计入“还有 N 个”。',
|
|
51
54
|
},
|
|
52
55
|
});
|
|
53
56
|
|
|
@@ -67,9 +70,9 @@ export function listOptions(o: { rows?: number; layouts?: readonly ListLayout[];
|
|
|
67
70
|
rows,
|
|
68
71
|
layout: t.enum(values, {
|
|
69
72
|
default: o.layout ?? 'auto',
|
|
70
|
-
label: { en: 'Row layout', es: 'Formato de fila' },
|
|
73
|
+
label: { en: 'Row layout', es: 'Formato de fila', de: 'Zeilenlayout', 'zh-Hant': '列版面', 'zh-Hans': '行布局' },
|
|
71
74
|
labels: Object.fromEntries(values.map((v) => [v, LAYOUT_LABELS[v]])),
|
|
72
|
-
help: { en: 'Automatic: the widget picks by the tile\'s shape.', es: 'Automático: el widget elige según la forma de la tesela.' },
|
|
75
|
+
help: { en: 'Automatic: the widget picks by the tile\'s shape.', es: 'Automático: el widget elige según la forma de la tesela.', de: 'Automatisch: Das Widget wählt nach der Form der Kachel.', 'zh-Hant': '自動:小工具依方格形狀選擇。', 'zh-Hans': '自动:小组件根据格子形状选择。' },
|
|
73
76
|
}),
|
|
74
77
|
};
|
|
75
78
|
}
|
|
@@ -182,7 +185,7 @@ export function listLayout<L extends ListLayout>(box: Box, count: number, option
|
|
|
182
185
|
|
|
183
186
|
/** `"+3 more"` / `"+3 más"`. */
|
|
184
187
|
export function moreLabel(n: number, tr: (text: Localized) => string): string {
|
|
185
|
-
return tr({ en: `+${n} more`, es: `+${n} más
|
|
188
|
+
return tr({ en: `+${n} more`, es: `+${n} más`, de: `+${n} weitere`, 'zh-Hant': `還有 ${n} 個`, 'zh-Hans': `还有 ${n} 个` });
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
type DrawCtx = Pick<RenderContext<unknown, unknown>, 'kit' | 'theme' | 't'>;
|
package/src/location.ts
CHANGED
|
@@ -18,11 +18,11 @@ export function locationOptions(): { latitude: NumberField; longitude: NumberFie
|
|
|
18
18
|
step: 0.0001,
|
|
19
19
|
unit: '°',
|
|
20
20
|
advanced: true,
|
|
21
|
-
label: { en: 'Latitude', es: 'Latitud' },
|
|
22
|
-
help: { en: 'Leave latitude and longitude at 0 to use the place in Settings.', es: 'Con latitud y longitud a 0 se usa el lugar de los ajustes.' },
|
|
21
|
+
label: { en: 'Latitude', es: 'Latitud', de: 'Breitengrad', 'zh-Hant': '緯度', 'zh-Hans': '纬度' },
|
|
22
|
+
help: { en: 'Leave latitude and longitude at 0 to use the place in Settings.', es: 'Con latitud y longitud a 0 se usa el lugar de los ajustes.', de: 'Breiten- und Längengrad auf 0 lassen, um den Ort aus den Einstellungen zu verwenden.', 'zh-Hant': '緯度和經度保持 0 即使用設定中的地點。', 'zh-Hans': '纬度和经度保持为 0 时使用设置中的地点。' },
|
|
23
23
|
}),
|
|
24
|
-
longitude: t.number({ default: 0, min: -180, max: 180, step: 0.0001, unit: '°', advanced: true, label: { en: 'Longitude', es: 'Longitud' } }),
|
|
25
|
-
placeName: t.string({ advanced: true, placeholder: 'Madrid', label: { en: 'Place name', es: 'Nombre del lugar' }, help: { en: 'Empty: the one in Settings.', es: 'Vacío: el de los ajustes.' } }),
|
|
24
|
+
longitude: t.number({ default: 0, min: -180, max: 180, step: 0.0001, unit: '°', advanced: true, label: { en: 'Longitude', es: 'Longitud', de: 'Längengrad', 'zh-Hant': '經度', 'zh-Hans': '经度' } }),
|
|
25
|
+
placeName: t.string({ advanced: true, placeholder: 'Madrid', label: { en: 'Place name', es: 'Nombre del lugar', de: 'Ortsname', 'zh-Hant': '地點名稱', 'zh-Hans': '地点名称' }, help: { en: 'Empty: the one in Settings.', es: 'Vacío: el de los ajustes.', de: 'Leer: der aus den Einstellungen.', 'zh-Hant': '留空:使用設定中的地點。', 'zh-Hans': '留空:使用设置中的地点。' } }),
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
|
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';
|
|
@@ -62,15 +62,15 @@ export interface Size {
|
|
|
62
62
|
export type Category = 'agents' | 'system' | 'time' | 'productivity' | 'dev' | 'info' | 'media' | 'scene' | 'fun';
|
|
63
63
|
|
|
64
64
|
export const CATEGORIES: { id: Category; label: Localized }[] = [
|
|
65
|
-
{ id: 'agents', label: { en: 'AI agents', es: 'Agentes IA' } },
|
|
66
|
-
{ id: 'system', label: { en: 'System', es: 'Sistema' } },
|
|
67
|
-
{ id: 'time', label: { en: 'Time & calendar', es: 'Tiempo y agenda' } },
|
|
68
|
-
{ id: 'productivity', label: { en: 'Productivity', es: 'Productividad' } },
|
|
69
|
-
{ id: 'dev', label: { en: 'Development', es: 'Desarrollo' } },
|
|
70
|
-
{ id: 'info', label: { en: 'News & world', es: 'Noticias y mundo' } },
|
|
71
|
-
{ id: 'media', label: { en: 'Media', es: 'Multimedia' } },
|
|
72
|
-
{ id: 'scene', label: { en: 'Scenes', es: 'Escenas' } },
|
|
73
|
-
{ 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': '趣味' } },
|
|
74
74
|
];
|
|
75
75
|
|
|
76
76
|
export interface Logger {
|
|
@@ -92,6 +92,18 @@ export interface BaseContext {
|
|
|
92
92
|
locale: string;
|
|
93
93
|
/** Picks the user's language from a `Localized` text. */
|
|
94
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;
|
|
95
107
|
/**
|
|
96
108
|
* Times and lengths of time in the user's language and clock (Settings →
|
|
97
109
|
* time format): `fmt.time(at)` "14:05" / "2:05 PM", `fmt.ago(at)`
|
|
@@ -234,6 +246,67 @@ export interface AnimationContext<O, D> extends StateContext<O, D> {
|
|
|
234
246
|
rnd: () => number;
|
|
235
247
|
}
|
|
236
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
|
+
|
|
237
310
|
/**
|
|
238
311
|
* When the widget must be repainted even though its data didn't change: a
|
|
239
312
|
* clock every second, a countdown every minute. Fewer repaints are fewer
|
|
@@ -308,6 +381,15 @@ export interface WidgetDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
308
381
|
urgent?: (ctx: StateContext<Infer<OF>, D>) => boolean;
|
|
309
382
|
/** Default of the instance's `takeOver` switch (keep the tile while urgent). Default true. */
|
|
310
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[];
|
|
311
393
|
/**
|
|
312
394
|
* Has nothing to list right now (no reviews, no tasks). Declaring it gives
|
|
313
395
|
* the widget a "hide when empty" switch (`hideWhenEmpty`): when on, an
|
|
@@ -354,10 +436,10 @@ export interface SourceDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
354
436
|
/** Global options, edited once in Settings → Sources. */
|
|
355
437
|
options?: OF;
|
|
356
438
|
/**
|
|
357
|
-
* Polled every `intervalMs` while some widget uses it
|
|
358
|
-
* the interval and the timeout in
|
|
359
|
-
* (`sources["plugin/source"].intervalMs` /
|
|
360
|
-
* 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.
|
|
361
443
|
*/
|
|
362
444
|
read?: (ctx: SourceContext<Infer<OF>>) => Promise<D>;
|
|
363
445
|
/** Default interval of `read`. Default: 30 s. */
|
|
@@ -372,6 +454,24 @@ export interface SourceDefinition<OF extends ObjectField<any> = ObjectField<any>
|
|
|
372
454
|
*/
|
|
373
455
|
watch?: (ctx: SourceContext<Infer<OF>>, emit: (data: D) => void) => () => void;
|
|
374
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;
|
|
375
475
|
/**
|
|
376
476
|
* Named lists of values for the editor to offer in options, made from
|
|
377
477
|
* this source's latest data (or its demo data before there is any): the
|
|
@@ -398,8 +498,32 @@ export interface InterludePlayer {
|
|
|
398
498
|
draw: (g: Graphics, i: number) => void | Promise<void>;
|
|
399
499
|
}
|
|
400
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
|
+
|
|
401
517
|
export interface InterludeContext<O> extends BaseContext {
|
|
402
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;
|
|
403
527
|
width: number;
|
|
404
528
|
height: number;
|
|
405
529
|
/** Deterministic per slot: the same quarter hour plays the same story. */
|
|
@@ -418,6 +542,18 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
|
|
|
418
542
|
sources?: string[];
|
|
419
543
|
/** Frames per second it was designed for. USB panels top out around 12-24 fps. */
|
|
420
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 };
|
|
421
557
|
/** Builds the animation. May be slow (it runs before playing, not during). */
|
|
422
558
|
prepare: (ctx: InterludeContext<Infer<OF>>) => Promise<InterludePlayer | null>;
|
|
423
559
|
/** Don't interrupt now (someone waits for a permission, a meeting is about to start). */
|
|
@@ -430,7 +566,7 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
|
|
|
430
566
|
* package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
|
|
431
567
|
* it runs); the registry compares them with `satisfies`.
|
|
432
568
|
*/
|
|
433
|
-
export const SDK_VERSION = '0.2.
|
|
569
|
+
export const SDK_VERSION = '0.2.7';
|
|
434
570
|
|
|
435
571
|
/**
|
|
436
572
|
* What a plugin does on the machine, declared for the person who installs
|
|
@@ -519,11 +655,53 @@ export interface PluginDefinition {
|
|
|
519
655
|
optional?: string[];
|
|
520
656
|
/** The operating systems it works on. Omitted: all. Also npm's `os` in package.json. */
|
|
521
657
|
platforms?: Platform[];
|
|
658
|
+
/**
|
|
659
|
+
* The languages its texts come in, as BCP 47 tags, English first:
|
|
660
|
+
* `['en', 'es', 'zh-Hant', 'zh-Hans']`. Chinese goes by script (`zh-Hant`
|
|
661
|
+
* for Taiwan and Hong Kong, `zh-Hans` for mainland China), never a bare
|
|
662
|
+
* `zh`. Every `Localized` text of the plugin has them all (the linter
|
|
663
|
+
* says which lack one). Also `kiosko.languages` in package.json, so a
|
|
664
|
+
* catalogue knows without running it. Omitted: the ones its texts use.
|
|
665
|
+
*/
|
|
666
|
+
languages?: string[];
|
|
522
667
|
widgets?: WidgetDefinition<any, any>[];
|
|
523
668
|
sources?: SourceDefinition<any, any>[];
|
|
524
669
|
interludes?: InterludeDefinition<any>[];
|
|
525
670
|
/** Page layouts the editor offers, built from its widgets (see `PageTemplate`). */
|
|
526
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;
|
|
527
705
|
}
|
|
528
706
|
|
|
529
707
|
/* Identity helpers: they only exist so TypeScript infers option and data types. */
|
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 {
|