kiosko 0.2.8 → 0.2.10
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/README.md +45 -3
- package/cli.js +2956 -406
- package/package.json +1 -1
- package/screen-thread.js +391 -19
- package/sdk.js +1 -1
- package/web/assets/app.js +70 -4
- package/web/assets/styles.css +1 -1
package/package.json
CHANGED
package/screen-thread.js
CHANGED
|
@@ -47,6 +47,12 @@ function toPx(r, grid, width, height) {
|
|
|
47
47
|
|
|
48
48
|
// packages/core/src/config/model.ts
|
|
49
49
|
var CONFIG_VERSION = 1;
|
|
50
|
+
function deviceRotates(d) {
|
|
51
|
+
return d.driver === "remote";
|
|
52
|
+
}
|
|
53
|
+
function paintTurn(s) {
|
|
54
|
+
return deviceRotates(s.device) ? 0 : s.rotate;
|
|
55
|
+
}
|
|
50
56
|
var ZOOM = { min: 0.5, max: 2, step: 0.1 };
|
|
51
57
|
function zoomOf(inst) {
|
|
52
58
|
const z = inst.zoom;
|
|
@@ -54,6 +60,10 @@ function zoomOf(inst) {
|
|
|
54
60
|
return Math.round(Math.min(ZOOM.max, Math.max(ZOOM.min, z)) * 100) / 100;
|
|
55
61
|
}
|
|
56
62
|
var READING_CM = { near: 40, normal: 60, far: 90 };
|
|
63
|
+
var STARTER_NAMES = {
|
|
64
|
+
screen: { en: "My panel", es: "Mi panel", de: "Mein Panel", "zh-Hant": "\u6211\u7684\u9762\u677F", "zh-Hans": "\u6211\u7684\u5C4F\u5E55" },
|
|
65
|
+
page: { en: "Home", es: "Inicio", de: "Start", "zh-Hant": "\u9996\u9801", "zh-Hans": "\u9996\u9875" }
|
|
66
|
+
};
|
|
57
67
|
var DEFAULT_CONFIG = {
|
|
58
68
|
version: CONFIG_VERSION,
|
|
59
69
|
locale: "auto",
|
|
@@ -106,7 +116,7 @@ import { homedir as homedir2, platform } from "node:os";
|
|
|
106
116
|
|
|
107
117
|
// packages/sdk/src/plugin.ts
|
|
108
118
|
var PAD_KEYS = ["up", "down", "left", "right", "a", "b", "x", "y", "l", "r", "start", "select"];
|
|
109
|
-
var SDK_VERSION = "0.2.
|
|
119
|
+
var SDK_VERSION = "0.2.10";
|
|
110
120
|
function defineWidget(w) {
|
|
111
121
|
return w;
|
|
112
122
|
}
|
|
@@ -805,6 +815,20 @@ function sourceOptionsField(def) {
|
|
|
805
815
|
return merged.get(def) ?? void 0;
|
|
806
816
|
}
|
|
807
817
|
|
|
818
|
+
// packages/core/src/config/starter.ts
|
|
819
|
+
var STARTER_TYPES = /* @__PURE__ */ new Set(["agents/sessions", "core/text", "core/clock", "core/date", "weather/forecast", "mirror/compliments", "usage/rail", "vitals/vitals", "system/health", "mirror/countdown"]);
|
|
820
|
+
function looksLikeStarter(c) {
|
|
821
|
+
if (c.screens.length !== 1) return false;
|
|
822
|
+
const s = c.screens[0];
|
|
823
|
+
const named = (name, names) => Object.values(names).includes(name);
|
|
824
|
+
if (s.device.driver !== "virtual" || !named(s.name, STARTER_NAMES.screen) || s.pages.length !== 1) return false;
|
|
825
|
+
const p = s.pages[0];
|
|
826
|
+
return named(p.name, STARTER_NAMES.page) && p.tiles.length <= 4 && p.tiles.every((t2) => t2.widgets.every((w) => STARTER_TYPES.has(w.type)));
|
|
827
|
+
}
|
|
828
|
+
function offersSetup(c) {
|
|
829
|
+
return c.setup === "pending" || !c.setup && (c.screens.length === 0 || looksLikeStarter(c));
|
|
830
|
+
}
|
|
831
|
+
|
|
808
832
|
// packages/core/src/layout/stack.ts
|
|
809
833
|
function pickInStack(entries, now, rotateMs) {
|
|
810
834
|
const urgent = entries.find((e) => e.visible && e.urgent);
|
|
@@ -1597,7 +1621,7 @@ var PROBE = "\u9AD4";
|
|
|
1597
1621
|
var missingPixels = /* @__PURE__ */ new Map();
|
|
1598
1622
|
var available = /* @__PURE__ */ new Map();
|
|
1599
1623
|
var probeCanvas = null;
|
|
1600
|
-
function pixelsOf(font,
|
|
1624
|
+
function pixelsOf(font, probe2 = PROBE) {
|
|
1601
1625
|
probeCanvas ??= createCanvas4(40, 40);
|
|
1602
1626
|
const g = probeCanvas.getContext("2d");
|
|
1603
1627
|
g.clearRect(0, 0, 40, 40);
|
|
@@ -1605,16 +1629,16 @@ function pixelsOf(font, probe = PROBE) {
|
|
|
1605
1629
|
else g.font = font;
|
|
1606
1630
|
g.fillStyle = "#000";
|
|
1607
1631
|
g.textBaseline = "top";
|
|
1608
|
-
g.fillText(
|
|
1632
|
+
g.fillText(probe2, 4, 4);
|
|
1609
1633
|
return Buffer.from(g.getImageData(0, 0, 40, 40).data.buffer).toString("base64");
|
|
1610
1634
|
}
|
|
1611
|
-
function hasFontFamily(family,
|
|
1612
|
-
const key = `${family}\0${
|
|
1635
|
+
function hasFontFamily(family, probe2 = PROBE) {
|
|
1636
|
+
const key = `${family}\0${probe2}`;
|
|
1613
1637
|
let yes = available.get(key);
|
|
1614
1638
|
if (yes === void 0) {
|
|
1615
|
-
let missing = missingPixels.get(
|
|
1616
|
-
if (missing === void 0) missingPixels.set(
|
|
1617
|
-
yes = pixelsOf(`28px "${family.replace(/"/g, "")}"`,
|
|
1639
|
+
let missing = missingPixels.get(probe2);
|
|
1640
|
+
if (missing === void 0) missingPixels.set(probe2, missing = pixelsOf('28px "Kiosko Missing Font"', probe2));
|
|
1641
|
+
yes = pixelsOf(`28px "${family.replace(/"/g, "")}"`, probe2) !== missing;
|
|
1618
1642
|
available.set(key, yes);
|
|
1619
1643
|
}
|
|
1620
1644
|
return yes;
|
|
@@ -2024,10 +2048,13 @@ var DEFAULT_SNOOZE_MS = 10 * 6e4;
|
|
|
2024
2048
|
// packages/core/src/data.ts
|
|
2025
2049
|
var DEFAULT_FETCH_MS = 10 * 6e4;
|
|
2026
2050
|
|
|
2051
|
+
// packages/core/src/remote/link.ts
|
|
2052
|
+
var MAX_MSG = 1 << 20;
|
|
2053
|
+
|
|
2027
2054
|
// packages/core/src/devices.ts
|
|
2028
2055
|
function encodeFor(device, jpegQuality) {
|
|
2029
2056
|
if (device.driver === "file") return device.format ?? "jpeg";
|
|
2030
|
-
if (device.driver === "usb") return "jpeg";
|
|
2057
|
+
if (device.driver === "usb" || device.driver === "remote") return "jpeg";
|
|
2031
2058
|
return jpegQuality > 0 ? "jpeg" : "png";
|
|
2032
2059
|
}
|
|
2033
2060
|
|
|
@@ -2213,6 +2240,245 @@ function paintAlert(g, w, h, shown, o) {
|
|
|
2213
2240
|
g.restore();
|
|
2214
2241
|
}
|
|
2215
2242
|
|
|
2243
|
+
// packages/core/src/welcome.ts
|
|
2244
|
+
var BOOT_MS = 2400;
|
|
2245
|
+
var BOOT_WINDOW_MS = 6e4;
|
|
2246
|
+
var CARD_EVERY_MS = 10 * 6e4;
|
|
2247
|
+
var CARD_MS = 15e3;
|
|
2248
|
+
var FIRST_CARD_MS = 3e4;
|
|
2249
|
+
var BOOT_FPS = 15;
|
|
2250
|
+
function welcomeDue(cfg, s) {
|
|
2251
|
+
const pending2 = offersSetup(cfg);
|
|
2252
|
+
if (!s.booted) {
|
|
2253
|
+
if (s.sinceStartMs < BOOT_WINDOW_MS && (cfg.bootAnimation !== false || pending2)) return "boot";
|
|
2254
|
+
return pending2 ? "card" : null;
|
|
2255
|
+
}
|
|
2256
|
+
if (!pending2) return null;
|
|
2257
|
+
const slot = Math.floor(s.now / CARD_EVERY_MS);
|
|
2258
|
+
return slot !== s.cardSlot && s.now - slot * CARD_EVERY_MS < 6e4 ? "card" : null;
|
|
2259
|
+
}
|
|
2260
|
+
var TEXTS = {
|
|
2261
|
+
running: { en: "Kiosko is running", es: "Kiosko est\xE1 en marcha", de: "Kiosko l\xE4uft", "zh-Hant": "Kiosko \u5DF2\u5728\u57F7\u884C", "zh-Hans": "Kiosko \u5DF2\u5728\u8FD0\u884C" },
|
|
2262
|
+
open: { en: "Open the editor to set up this panel:", es: "Abre el editor para configurar este panel:", de: "\xD6ffne den Editor, um dieses Panel einzurichten:", "zh-Hant": "\u958B\u555F\u7DE8\u8F2F\u5668\u4F86\u8A2D\u5B9A\u9019\u584A\u9762\u677F\uFF1A", "zh-Hans": "\u6253\u5F00\u7F16\u8F91\u5668\u6765\u8BBE\u7F6E\u8FD9\u5757\u526F\u5C4F\uFF1A" },
|
|
2263
|
+
or: { en: "or go to", es: "o entra en", de: "oder \xF6ffne", "zh-Hant": "\u6216\u524D\u5F80", "zh-Hans": "\u6216\u8BBF\u95EE" },
|
|
2264
|
+
hint: { en: "This card goes away once the setup is done.", es: "Esta tarjeta se va cuando termines la configuraci\xF3n.", de: "Diese Karte verschwindet, sobald die Einrichtung fertig ist.", "zh-Hant": "\u5B8C\u6210\u8A2D\u5B9A\u5F8C\uFF0C\u9019\u5F35\u5361\u7247\u5C31\u6703\u6D88\u5931\u3002", "zh-Hans": "\u5B8C\u6210\u8BBE\u7F6E\u540E\uFF0C\u8FD9\u5F20\u5361\u7247\u5C31\u4F1A\u6D88\u5931\u3002" }
|
|
2265
|
+
};
|
|
2266
|
+
function welcomeTexts(locale) {
|
|
2267
|
+
return Object.fromEntries(Object.entries(TEXTS).map(([k, v]) => [k, localize(v, locale)]));
|
|
2268
|
+
}
|
|
2269
|
+
function editorUrl(cfg) {
|
|
2270
|
+
const host = !cfg.server.host || cfg.server.host === "0.0.0.0" || cfg.server.host === "::" ? "127.0.0.1" : cfg.server.host;
|
|
2271
|
+
return `http://${host.includes(":") ? `[${host}]` : host}:${cfg.server.port}`;
|
|
2272
|
+
}
|
|
2273
|
+
function cardUrl(listening, cfg) {
|
|
2274
|
+
return listening ?? editorUrl(cfg);
|
|
2275
|
+
}
|
|
2276
|
+
var clamp01 = (x) => Math.max(0, Math.min(1, x));
|
|
2277
|
+
var easeOut = (x) => 1 - (1 - clamp01(x)) ** 3;
|
|
2278
|
+
var easeBack = (x) => {
|
|
2279
|
+
const t2 = clamp01(x) - 1;
|
|
2280
|
+
return 1 + 2.2 * t2 ** 3 + 1.2 * t2 ** 2;
|
|
2281
|
+
};
|
|
2282
|
+
var TILES = [
|
|
2283
|
+
{ x: 6, y: 6, w: 30, h: 22, grad: true, alpha: 1 },
|
|
2284
|
+
{ x: 40, y: 6, w: 18, h: 22, grad: false, tone: 1, alpha: 0.55 },
|
|
2285
|
+
{ x: 6, y: 32, w: 18, h: 26, grad: false, tone: 0, alpha: 0.55 },
|
|
2286
|
+
{ x: 28, y: 32, w: 30, h: 26, grad: true, alpha: 0.85 }
|
|
2287
|
+
];
|
|
2288
|
+
function brand(theme) {
|
|
2289
|
+
return [theme.colors.accent, theme.colors.info];
|
|
2290
|
+
}
|
|
2291
|
+
function paintMark(g, x, y, size, theme, t2 = 1, glint = -1) {
|
|
2292
|
+
const k = size / 64;
|
|
2293
|
+
const [c1, c2] = brand(theme);
|
|
2294
|
+
TILES.forEach((tile, i) => {
|
|
2295
|
+
const p = clamp01((t2 - i * 0.12) / 0.52);
|
|
2296
|
+
if (p <= 0) return;
|
|
2297
|
+
const s = 0.55 + 0.45 * easeBack(p);
|
|
2298
|
+
const cx = x + (tile.x + tile.w / 2) * k;
|
|
2299
|
+
const cy = y + (tile.y + tile.h / 2) * k;
|
|
2300
|
+
const dx = (tile.x + tile.w / 2 - 32) * k * 0.6 * (1 - easeOut(p));
|
|
2301
|
+
const dy = (tile.y + tile.h / 2 - 32) * k * 0.6 * (1 - easeOut(p));
|
|
2302
|
+
const w = tile.w * k * s;
|
|
2303
|
+
const h = tile.h * k * s;
|
|
2304
|
+
g.save();
|
|
2305
|
+
g.globalAlpha = tile.alpha * easeOut(p);
|
|
2306
|
+
if (tile.grad) {
|
|
2307
|
+
const gr = g.createLinearGradient(x, y, x + size, y + size);
|
|
2308
|
+
gr.addColorStop(0, c1);
|
|
2309
|
+
gr.addColorStop(1, c2);
|
|
2310
|
+
g.fillStyle = gr;
|
|
2311
|
+
} else g.fillStyle = "tone" in tile && tile.tone ? c2 : c1;
|
|
2312
|
+
g.beginPath();
|
|
2313
|
+
g.roundRect(cx + dx - w / 2, cy + dy - h / 2, w, h, 5 * k * s);
|
|
2314
|
+
g.fill();
|
|
2315
|
+
g.restore();
|
|
2316
|
+
});
|
|
2317
|
+
if (glint >= 0 && glint <= 1) {
|
|
2318
|
+
g.save();
|
|
2319
|
+
g.beginPath();
|
|
2320
|
+
for (const tile of TILES) g.roundRect(x + tile.x * k, y + tile.y * k, tile.w * k, tile.h * k, 5 * k);
|
|
2321
|
+
g.clip();
|
|
2322
|
+
const bx = x - size * 0.6 + glint * size * 2.2;
|
|
2323
|
+
const gr = g.createLinearGradient(bx, y, bx + size * 0.5, y + size);
|
|
2324
|
+
gr.addColorStop(0, "rgba(255,255,255,0)");
|
|
2325
|
+
gr.addColorStop(0.5, "rgba(255,255,255,0.45)");
|
|
2326
|
+
gr.addColorStop(1, "rgba(255,255,255,0)");
|
|
2327
|
+
g.fillStyle = gr;
|
|
2328
|
+
g.fillRect(x, y, size, size);
|
|
2329
|
+
g.restore();
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
function paintBackground(g, w, h, theme, cx, cy, glow) {
|
|
2333
|
+
g.fillStyle = theme.colors.bg;
|
|
2334
|
+
g.fillRect(0, 0, w, h);
|
|
2335
|
+
if (glow <= 0) return;
|
|
2336
|
+
const r = Math.max(w, h) * 0.55;
|
|
2337
|
+
const gr = g.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
2338
|
+
const [c1] = brand(theme);
|
|
2339
|
+
gr.addColorStop(0, css(hex(c1), 0.16 * glow));
|
|
2340
|
+
gr.addColorStop(1, css(hex(c1), 0));
|
|
2341
|
+
g.fillStyle = gr;
|
|
2342
|
+
g.fillRect(0, 0, w, h);
|
|
2343
|
+
}
|
|
2344
|
+
function shapeOf(w, h) {
|
|
2345
|
+
const r = w / h;
|
|
2346
|
+
return r >= 1.6 ? "wide" : r <= 0.7 ? "tall" : "square";
|
|
2347
|
+
}
|
|
2348
|
+
function paintBoot(g, w, h, ms, look) {
|
|
2349
|
+
const { theme } = look;
|
|
2350
|
+
const shape = shapeOf(w, h);
|
|
2351
|
+
const bold = theme.fonts.sansBold;
|
|
2352
|
+
const word = "Kiosko";
|
|
2353
|
+
const mark = shape === "wide" ? Math.round(h * 0.5) : Math.round(Math.min(w * (shape === "tall" ? 0.62 : 0.42), h * 0.42));
|
|
2354
|
+
let size = Math.round(mark * (shape === "wide" ? 0.62 : 0.4));
|
|
2355
|
+
size = fitSize(g, word, shape === "wide" ? w * 0.5 : w * 0.86, { size, family: bold }, 10);
|
|
2356
|
+
const wordW = measureTracked(g, word, { size, family: bold });
|
|
2357
|
+
const gap = Math.round(mark * 0.22);
|
|
2358
|
+
const groupW = shape === "wide" ? mark + gap + wordW : Math.max(mark, wordW);
|
|
2359
|
+
const groupH = shape === "wide" ? mark : mark + gap + size;
|
|
2360
|
+
const gx = Math.round((w - groupW) / 2);
|
|
2361
|
+
const gy = Math.round((h - groupH) / 2);
|
|
2362
|
+
const mx = shape === "wide" ? gx : Math.round((w - mark) / 2);
|
|
2363
|
+
const fade = 1 - clamp01((ms - (BOOT_MS - 380)) / 380);
|
|
2364
|
+
paintBackground(g, w, h, theme, mx + mark / 2, gy + mark / 2, easeOut(ms / 900) * fade);
|
|
2365
|
+
g.save();
|
|
2366
|
+
g.globalAlpha = fade;
|
|
2367
|
+
paintMark(g, mx, gy, mark, theme, ms / 1e3, (ms - 1350) / 650);
|
|
2368
|
+
const p = easeOut((ms - 650) / 700);
|
|
2369
|
+
if (p > 0) {
|
|
2370
|
+
const wx = shape === "wide" ? gx + mark + gap : Math.round((w - wordW) / 2);
|
|
2371
|
+
const base2 = shape === "wide" ? gy + mark / 2 + size * 0.36 : gy + mark + gap + size * 0.82;
|
|
2372
|
+
g.save();
|
|
2373
|
+
g.beginPath();
|
|
2374
|
+
if (shape === "wide") g.rect(wx - 2, 0, (wordW + 4) * p, h);
|
|
2375
|
+
else g.rect(0, 0, w, h);
|
|
2376
|
+
g.clip();
|
|
2377
|
+
g.globalAlpha = fade * (shape === "wide" ? 1 : p);
|
|
2378
|
+
drawTracked(g, word, wx, base2 + (1 - p) * size * 0.25, { size, family: bold, color: theme.colors.ink });
|
|
2379
|
+
g.restore();
|
|
2380
|
+
const u = easeOut((ms - 1150) / 600);
|
|
2381
|
+
if (u > 0) {
|
|
2382
|
+
const [c1, c2] = brand(theme);
|
|
2383
|
+
const gr = g.createLinearGradient(wx, 0, wx + wordW, 0);
|
|
2384
|
+
gr.addColorStop(0, c1);
|
|
2385
|
+
gr.addColorStop(1, c2);
|
|
2386
|
+
g.fillStyle = gr;
|
|
2387
|
+
const uh = Math.max(2, Math.round(size * 0.07));
|
|
2388
|
+
g.beginPath();
|
|
2389
|
+
g.roundRect(wx, base2 + size * 0.16, wordW * u, uh, uh / 2);
|
|
2390
|
+
g.fill();
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
g.restore();
|
|
2394
|
+
}
|
|
2395
|
+
function paintCard(g, w, h, look) {
|
|
2396
|
+
const { theme } = look;
|
|
2397
|
+
const tx = welcomeTexts(look.locale);
|
|
2398
|
+
const shape = shapeOf(w, h);
|
|
2399
|
+
const pad = Math.round(Math.min(w, h) * 0.08);
|
|
2400
|
+
const mark = shape === "wide" ? Math.round(h * 0.42) : shape === "tall" ? Math.round(w * 0.5) : Math.round(Math.min(w * 0.3, h * 0.28));
|
|
2401
|
+
const gap = Math.round(pad * 0.8);
|
|
2402
|
+
const mx = shape === "wide" ? pad + Math.round(mark * 0.1) : Math.round((w - mark) / 2);
|
|
2403
|
+
const bx = shape === "wide" ? mx + mark + Math.round(mark * 0.35) : pad;
|
|
2404
|
+
const bw = w - bx - pad;
|
|
2405
|
+
const bh = shape === "wide" ? h - 2 * pad : h - 2 * pad - mark - gap;
|
|
2406
|
+
const bold = theme.fonts.sansBold;
|
|
2407
|
+
const sans = theme.fonts.sans;
|
|
2408
|
+
const mono = theme.fonts.monoBold;
|
|
2409
|
+
const center = shape !== "wide";
|
|
2410
|
+
const layout = (k2) => {
|
|
2411
|
+
const body = Math.max(9, Math.round(k2 * 0.5));
|
|
2412
|
+
const chip = Math.max(9, Math.round(k2 * 0.5));
|
|
2413
|
+
const hint = Math.max(8, Math.round(k2 * 0.34));
|
|
2414
|
+
const title = wrapLines(g, tx.running, bw, 2, { size: k2, family: bold });
|
|
2415
|
+
const open2 = wrapLines(g, tx.open, bw, 3, { size: body, family: sans });
|
|
2416
|
+
const cmd = "kiosko editor";
|
|
2417
|
+
const cmdW = measureTracked(g, cmd, { size: chip, family: mono }) + chip * 1.1;
|
|
2418
|
+
const orW = measureTracked(g, tx.or, { size: body, family: sans });
|
|
2419
|
+
const urlW = measureTracked(g, look.url, { size: chip, family: mono });
|
|
2420
|
+
const oneLine = cmdW + body * 0.6 + orW + body * 0.6 + urlW <= bw;
|
|
2421
|
+
const hints = hint >= 10 ? wrapLines(g, tx.hint, bw, 2, { size: hint, family: sans }) : [];
|
|
2422
|
+
const lineH = (s) => Math.round(s * 1.3);
|
|
2423
|
+
const height = title.length * lineH(k2) + k2 * 0.25 + open2.length * lineH(body) + body * 0.35 + (oneLine ? chip * 1.9 : chip * 1.9 * 2 + lineH(body)) + hint * 0.6 + hints.length * lineH(hint);
|
|
2424
|
+
const fits = urlW <= bw && cmdW <= bw && title.length === 1;
|
|
2425
|
+
return { k: k2, body, chip, hint, title, open: open2, cmd, cmdW, orW, urlW, oneLine, hints, height, fits, lineH };
|
|
2426
|
+
};
|
|
2427
|
+
let k = Math.round(shape === "wide" ? h * 0.17 : shape === "tall" ? w * 0.12 : Math.min(w * 0.085, h * 0.11));
|
|
2428
|
+
let L = layout(k);
|
|
2429
|
+
while (k > 12 && (L.height > bh || !L.fits)) L = layout(--k);
|
|
2430
|
+
const my = shape === "wide" ? Math.round((h - mark) / 2) : Math.max(pad, Math.round((h - mark - gap - L.height) / 2));
|
|
2431
|
+
paintBackground(g, w, h, theme, mx + mark / 2, my + mark / 2, 1);
|
|
2432
|
+
paintMark(g, mx, my, mark, theme);
|
|
2433
|
+
let y = shape === "wide" ? pad + Math.max(0, Math.round((bh - L.height) / 2)) : my + mark + gap;
|
|
2434
|
+
const ax = center ? w / 2 : bx;
|
|
2435
|
+
const align = center ? "center" : "left";
|
|
2436
|
+
for (const line of L.title) {
|
|
2437
|
+
drawTracked(g, line, ax, y + L.k * 0.95, { size: L.k, family: bold, color: theme.colors.ink, align });
|
|
2438
|
+
y += L.lineH(L.k);
|
|
2439
|
+
}
|
|
2440
|
+
y += L.k * 0.25;
|
|
2441
|
+
for (const line of L.open) {
|
|
2442
|
+
drawTracked(g, line, ax, y + L.body * 0.95, { size: L.body, family: sans, color: theme.colors.inkDim, align });
|
|
2443
|
+
y += L.lineH(L.body);
|
|
2444
|
+
}
|
|
2445
|
+
y += L.body * 0.35;
|
|
2446
|
+
const chipH = Math.round(L.chip * 1.6);
|
|
2447
|
+
const drawChip = (x, text2, cw) => {
|
|
2448
|
+
g.fillStyle = theme.colors.surface;
|
|
2449
|
+
g.strokeStyle = theme.colors.surfaceEdge;
|
|
2450
|
+
g.lineWidth = 1;
|
|
2451
|
+
g.beginPath();
|
|
2452
|
+
g.roundRect(x, y, cw, chipH, chipH / 3);
|
|
2453
|
+
g.fill();
|
|
2454
|
+
g.stroke();
|
|
2455
|
+
drawTracked(g, text2, x + cw / 2, y + chipH / 2 + L.chip * 0.36, { size: L.chip, family: mono, color: theme.colors.ink, align: "center" });
|
|
2456
|
+
};
|
|
2457
|
+
const drawUrl = (x) => drawTracked(g, look.url, x, y + chipH / 2 + L.chip * 0.36, { size: L.chip, family: mono, color: theme.colors.accent });
|
|
2458
|
+
if (L.oneLine) {
|
|
2459
|
+
const total = L.cmdW + L.body * 0.6 + L.orW + L.body * 0.6 + L.urlW;
|
|
2460
|
+
let x = center ? Math.round((w - total) / 2) : bx;
|
|
2461
|
+
drawChip(x, L.cmd, L.cmdW);
|
|
2462
|
+
x += L.cmdW + L.body * 0.6;
|
|
2463
|
+
drawTracked(g, tx.or, x, y + chipH / 2 + L.body * 0.36, { size: L.body, family: sans, color: theme.colors.inkDim });
|
|
2464
|
+
x += L.orW + L.body * 0.6;
|
|
2465
|
+
drawUrl(x);
|
|
2466
|
+
y += L.chip * 1.9;
|
|
2467
|
+
} else {
|
|
2468
|
+
drawChip(center ? Math.round((w - L.cmdW) / 2) : bx, L.cmd, L.cmdW);
|
|
2469
|
+
y += L.chip * 1.9;
|
|
2470
|
+
drawTracked(g, tx.or, ax, y + L.body * 0.95, { size: L.body, family: sans, color: theme.colors.inkDim, align });
|
|
2471
|
+
y += L.lineH(L.body);
|
|
2472
|
+
drawUrl(center ? Math.round((w - L.urlW) / 2) : bx);
|
|
2473
|
+
y += L.chip * 1.9;
|
|
2474
|
+
}
|
|
2475
|
+
y += L.hint * 0.6;
|
|
2476
|
+
for (const line of L.hints) {
|
|
2477
|
+
drawTracked(g, line, ax, y + L.hint * 0.95, { size: L.hint, family: sans, color: theme.colors.inkFaint, align });
|
|
2478
|
+
y += L.lineH(L.hint);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2216
2482
|
// packages/core/src/frame-stats.ts
|
|
2217
2483
|
var FPS_WINDOW_MS = 5e3;
|
|
2218
2484
|
var round = (ms) => Math.round(ms * 10) / 10;
|
|
@@ -2305,6 +2571,12 @@ var ScreenRunner = class {
|
|
|
2305
2571
|
alertKey = null;
|
|
2306
2572
|
/** Real fps, paint and encode times (see frame-stats.ts). */
|
|
2307
2573
|
stats = new FrameStats();
|
|
2574
|
+
/** The start went by (the boot animation played, or wasn't due). */
|
|
2575
|
+
booted = false;
|
|
2576
|
+
/** The first run's card: the last slot it was shown in, and until when it stays. */
|
|
2577
|
+
cardSlot = -1;
|
|
2578
|
+
cardUntil = 0;
|
|
2579
|
+
cardKey = null;
|
|
2308
2580
|
screen;
|
|
2309
2581
|
rt;
|
|
2310
2582
|
/** `device`: one already open for this screen (handed over by a thread that stopped). */
|
|
@@ -2387,6 +2659,7 @@ var ScreenRunner = class {
|
|
|
2387
2659
|
const play = this.wantedPlay;
|
|
2388
2660
|
this.wanted = null;
|
|
2389
2661
|
this.wantedPlay = false;
|
|
2662
|
+
if (!this.off && !asked && await this.maybeWelcome(now)) return;
|
|
2390
2663
|
if (!this.off && await this.maybeInterlude(now, asked ?? void 0, play)) return;
|
|
2391
2664
|
const page = this.currentPage(now);
|
|
2392
2665
|
if (page?.id !== this.page?.id) {
|
|
@@ -2432,7 +2705,7 @@ var ScreenRunner = class {
|
|
|
2432
2705
|
log: this.rt.log,
|
|
2433
2706
|
demo: this.rt.demoMode,
|
|
2434
2707
|
cache: this.tiles,
|
|
2435
|
-
rotate: screen
|
|
2708
|
+
rotate: paintTurn(screen)
|
|
2436
2709
|
});
|
|
2437
2710
|
canvas = result.canvas;
|
|
2438
2711
|
this.animatable = result.animatable;
|
|
@@ -2443,7 +2716,8 @@ var ScreenRunner = class {
|
|
|
2443
2716
|
this.rt.paintTime(t2.shown, type, t2.renderMs, now);
|
|
2444
2717
|
}
|
|
2445
2718
|
} else {
|
|
2446
|
-
const
|
|
2719
|
+
const turn = paintTurn(screen);
|
|
2720
|
+
const swap = turn === 90 || turn === 270;
|
|
2447
2721
|
canvas = CANVAS.createCanvas(swap ? screen.height : screen.width, swap ? screen.width : screen.height);
|
|
2448
2722
|
this.animatable = [];
|
|
2449
2723
|
this.nextAt = now + 6e4;
|
|
@@ -2459,7 +2733,7 @@ var ScreenRunner = class {
|
|
|
2459
2733
|
}
|
|
2460
2734
|
const kind = encodeFor(screen.device, screen.jpegQuality);
|
|
2461
2735
|
const out = await this.fit(canvas, kind, screen.jpegQuality, screen, performance.now() - t0);
|
|
2462
|
-
this.lastInfo = { screenId: screen.id, pageId: page?.id ?? null, at: now, image: lazyJpeg(canvas, screen
|
|
2736
|
+
this.lastInfo = { screenId: screen.id, pageId: page?.id ?? null, at: now, image: lazyJpeg(canvas, paintTurn(screen)), tiles: result?.tiles ?? [], interlude: null, sleeping };
|
|
2463
2737
|
this.rt.frame(this.lastInfo);
|
|
2464
2738
|
if (this.last?.equals(out)) return;
|
|
2465
2739
|
this.last = out;
|
|
@@ -2488,7 +2762,7 @@ var ScreenRunner = class {
|
|
|
2488
2762
|
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
2489
2763
|
paintAlert(canvas.getContext("2d"), screen.width, screen.height, shown, { intensity, fonts: this.rt.theme().fonts, minPx, sinceText, shift });
|
|
2490
2764
|
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
2491
|
-
const turned = rotateCanvas(canvas, screen
|
|
2765
|
+
const turned = rotateCanvas(canvas, paintTurn(screen));
|
|
2492
2766
|
const out = await this.fit(turned, kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
2493
2767
|
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: now, image: lazyJpeg(canvas), tiles: [], interlude: null, alert: a.id, sleeping: false };
|
|
2494
2768
|
this.rt.frame(this.lastInfo);
|
|
@@ -2496,6 +2770,95 @@ var ScreenRunner = class {
|
|
|
2496
2770
|
this.last = out;
|
|
2497
2771
|
await this.send(out);
|
|
2498
2772
|
}
|
|
2773
|
+
/**
|
|
2774
|
+
* The boot animation and the first run's card (welcome.ts), before
|
|
2775
|
+
* anything else but an alert. True while one has the screen.
|
|
2776
|
+
*/
|
|
2777
|
+
async maybeWelcome(now) {
|
|
2778
|
+
if (!this.rt.welcome || this.rt.demoMode) return false;
|
|
2779
|
+
const cfg = this.rt.config;
|
|
2780
|
+
if (this.cardUntil) {
|
|
2781
|
+
if (now < this.cardUntil && offersSetup(cfg)) {
|
|
2782
|
+
await this.paintWelcomeCard(now);
|
|
2783
|
+
return true;
|
|
2784
|
+
}
|
|
2785
|
+
this.cardUntil = 0;
|
|
2786
|
+
this.cardKey = null;
|
|
2787
|
+
this.last = null;
|
|
2788
|
+
this.dirty = true;
|
|
2789
|
+
return false;
|
|
2790
|
+
}
|
|
2791
|
+
const due = welcomeDue(cfg, { sinceStartMs: now - this.rt.startedAt, now, booted: this.booted, cardSlot: this.cardSlot });
|
|
2792
|
+
const first = !this.booted;
|
|
2793
|
+
this.booted = true;
|
|
2794
|
+
if (!due) return false;
|
|
2795
|
+
if (due === "boot") {
|
|
2796
|
+
await this.playBoot();
|
|
2797
|
+
if (!offersSetup(cfg)) {
|
|
2798
|
+
this.last = null;
|
|
2799
|
+
this.dirty = true;
|
|
2800
|
+
return true;
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
this.cardSlot = Math.floor(Date.now() / CARD_EVERY_MS);
|
|
2804
|
+
this.cardUntil = Date.now() + (first ? FIRST_CARD_MS : CARD_MS);
|
|
2805
|
+
await this.paintWelcomeCard(Date.now());
|
|
2806
|
+
return true;
|
|
2807
|
+
}
|
|
2808
|
+
welcomeLook() {
|
|
2809
|
+
const cfg = this.rt.config;
|
|
2810
|
+
return { theme: this.rt.theme(), locale: resolveLocale(cfg), url: cardUrl(this.rt.editorUrl, cfg) };
|
|
2811
|
+
}
|
|
2812
|
+
/** The boot animation, at the screen's fps (at most BOOT_FPS): a slower panel plays fewer frames, never longer. */
|
|
2813
|
+
async playBoot() {
|
|
2814
|
+
const { screen } = this;
|
|
2815
|
+
const look = this.welcomeLook();
|
|
2816
|
+
registerFonts();
|
|
2817
|
+
setFontLocale(look.locale);
|
|
2818
|
+
const fps = Math.max(1, Math.min(BOOT_FPS, screen.maxFps));
|
|
2819
|
+
const frames = Math.max(1, Math.round(BOOT_MS / 1e3 * fps));
|
|
2820
|
+
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
2821
|
+
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
2822
|
+
const g = canvas.getContext("2d");
|
|
2823
|
+
const start = Date.now();
|
|
2824
|
+
for (let i = 0; i < frames && !this.alert && !this.closed; i++) {
|
|
2825
|
+
const ms = Math.min(BOOT_MS, Date.now() - start);
|
|
2826
|
+
if (ms >= BOOT_MS) break;
|
|
2827
|
+
const t0 = performance.now();
|
|
2828
|
+
g.save();
|
|
2829
|
+
paintBoot(g, screen.width, screen.height, ms, look);
|
|
2830
|
+
g.restore();
|
|
2831
|
+
const out = await this.fit(rotateCanvas(canvas, paintTurn(screen)), kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
2832
|
+
await this.send(out);
|
|
2833
|
+
if (i % 4 === 0) {
|
|
2834
|
+
const snap = CANVAS.createCanvas(canvas.width, canvas.height);
|
|
2835
|
+
snap.getContext("2d").drawImage(canvas, 0, 0);
|
|
2836
|
+
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: Date.now(), image: lazyJpeg(snap), tiles: [], interlude: "kiosko/boot", sleeping: false };
|
|
2837
|
+
this.rt.frame(this.lastInfo);
|
|
2838
|
+
}
|
|
2839
|
+
const wait = start + (i + 1) * 1e3 / fps - Date.now();
|
|
2840
|
+
await new Promise((r) => wait > 0 ? setTimeout(r, wait) : setImmediate(r));
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
/** The first run's card: a still frame, sent again only when it changes (the theme, the language, the address). */
|
|
2844
|
+
async paintWelcomeCard(now) {
|
|
2845
|
+
const { screen } = this;
|
|
2846
|
+
const look = this.welcomeLook();
|
|
2847
|
+
const key = JSON.stringify([look.theme.id, look.locale, look.url, screen.width, screen.height, screen.rotate]);
|
|
2848
|
+
if (key === this.cardKey) return;
|
|
2849
|
+
this.cardKey = key;
|
|
2850
|
+
const t0 = performance.now();
|
|
2851
|
+
registerFonts();
|
|
2852
|
+
setFontLocale(look.locale);
|
|
2853
|
+
const canvas = CANVAS.createCanvas(screen.width, screen.height);
|
|
2854
|
+
paintCard(canvas.getContext("2d"), screen.width, screen.height, look);
|
|
2855
|
+
const kind = encodeFor(screen.device, screen.jpegQuality || 85);
|
|
2856
|
+
const out = await this.fit(rotateCanvas(canvas, paintTurn(screen)), kind, screen.jpegQuality || 85, screen, performance.now() - t0);
|
|
2857
|
+
this.lastInfo = { screenId: screen.id, pageId: this.page?.id ?? null, at: now, image: lazyJpeg(canvas), tiles: [], interlude: "kiosko/welcome", sleeping: false };
|
|
2858
|
+
this.rt.frame(this.lastInfo);
|
|
2859
|
+
this.last = out;
|
|
2860
|
+
await this.send(out);
|
|
2861
|
+
}
|
|
2499
2862
|
/**
|
|
2500
2863
|
* Plays an interlude if one is due. Returns true while it played (no normal paint this tick).
|
|
2501
2864
|
* `play`: someone plays it from the Play page (an interlude with `input`): it gets their
|
|
@@ -2566,7 +2929,7 @@ var ScreenRunner = class {
|
|
|
2566
2929
|
} finally {
|
|
2567
2930
|
g.restore();
|
|
2568
2931
|
}
|
|
2569
|
-
const turned = rotateCanvas(canvas, this.screen
|
|
2932
|
+
const turned = rotateCanvas(canvas, paintTurn(this.screen));
|
|
2570
2933
|
const out = await this.fit(turned, kind, this.screen.jpegQuality || 85, this.screen, performance.now() - t0);
|
|
2571
2934
|
await this.send(out);
|
|
2572
2935
|
if (i % 3 === 0) {
|
|
@@ -2664,7 +3027,7 @@ var ScreenRunner = class {
|
|
|
2664
3027
|
demo: this.rt.demoMode,
|
|
2665
3028
|
cache: this.tiles,
|
|
2666
3029
|
animate,
|
|
2667
|
-
rotate: screen
|
|
3030
|
+
rotate: paintTurn(screen)
|
|
2668
3031
|
});
|
|
2669
3032
|
sent.push({ out: this.fit(result.canvas, kind, screen.jpegQuality || 85, screen, performance.now() - t02), snap: s % 3 === 1 ? result.canvas : null });
|
|
2670
3033
|
await new Promise((r) => setImmediate(r));
|
|
@@ -2681,7 +3044,7 @@ var ScreenRunner = class {
|
|
|
2681
3044
|
await this.send(outs[k]);
|
|
2682
3045
|
const snap = sent[k].snap;
|
|
2683
3046
|
if (snap) {
|
|
2684
|
-
this.lastInfo = { screenId: screen.id, pageId: page.id, at: Date.now(), image: lazyJpeg(snap, screen
|
|
3047
|
+
this.lastInfo = { screenId: screen.id, pageId: page.id, at: Date.now(), image: lazyJpeg(snap, paintTurn(screen)), tiles: [], interlude: null, animation: items.map((x) => x.animatable.type).join(", "), sleeping: false };
|
|
2685
3048
|
this.rt.frame(this.lastInfo);
|
|
2686
3049
|
}
|
|
2687
3050
|
if (hold && k === holdAt) {
|
|
@@ -3281,6 +3644,9 @@ var Host = class {
|
|
|
3281
3644
|
demoMode;
|
|
3282
3645
|
maxConcurrent;
|
|
3283
3646
|
playIdleMs;
|
|
3647
|
+
welcome;
|
|
3648
|
+
startedAt;
|
|
3649
|
+
editorUrl;
|
|
3284
3650
|
rnd = Math.random;
|
|
3285
3651
|
data = /* @__PURE__ */ new Map();
|
|
3286
3652
|
sources = /* @__PURE__ */ new Map();
|
|
@@ -3297,6 +3663,9 @@ var Host = class {
|
|
|
3297
3663
|
this.demoMode = init.demo;
|
|
3298
3664
|
this.maxConcurrent = init.maxConcurrent;
|
|
3299
3665
|
this.playIdleMs = init.playIdleMs;
|
|
3666
|
+
this.welcome = init.welcome;
|
|
3667
|
+
this.startedAt = init.startedAt;
|
|
3668
|
+
this.editorUrl = init.editorUrl;
|
|
3300
3669
|
this.post = post;
|
|
3301
3670
|
this.device = new RelayDevice(post);
|
|
3302
3671
|
}
|
|
@@ -3466,6 +3835,9 @@ async function runScreenThread(builtins = []) {
|
|
|
3466
3835
|
// packages/core/src/store/tar.ts
|
|
3467
3836
|
var MAX_TARBALL_BYTES = 20 * 1024 * 1024;
|
|
3468
3837
|
|
|
3838
|
+
// packages/core/src/remote/ops.ts
|
|
3839
|
+
var CHUNK = 16 * 1024;
|
|
3840
|
+
|
|
3469
3841
|
// plugins/core/src/index.ts
|
|
3470
3842
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
3471
3843
|
import { join as join6 } from "node:path";
|
|
@@ -3830,7 +4202,7 @@ var image = defineWidget({
|
|
|
3830
4202
|
var src_default = definePlugin({
|
|
3831
4203
|
id: "core",
|
|
3832
4204
|
name: { en: "Essentials", es: "B\xE1sicos", de: "Grundlagen", "zh-Hant": "\u57FA\u672C\u5DE5\u5177", "zh-Hans": "\u57FA\u7840\u7EC4\u4EF6" },
|
|
3833
|
-
version: "0.2.
|
|
4205
|
+
version: "0.2.10",
|
|
3834
4206
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
3835
4207
|
sdk: "^0.2.0",
|
|
3836
4208
|
// The picture widget reads the image (or folder, or URL) you give it.
|
|
@@ -3926,7 +4298,7 @@ var module2 = defineWidget({
|
|
|
3926
4298
|
var src_default2 = definePlugin({
|
|
3927
4299
|
id: "legacy",
|
|
3928
4300
|
name: { en: "aimonitor compatibility", es: "Compatibilidad aimonitor", de: "aimonitor-Kompatibilit\xE4t", "zh-Hant": "aimonitor \u76F8\u5BB9\u6027", "zh-Hans": "aimonitor \u517C\u5BB9" },
|
|
3929
|
-
version: "0.2.
|
|
4301
|
+
version: "0.2.10",
|
|
3930
4302
|
languages: ["en", "es", "de", "zh-Hant", "zh-Hans"],
|
|
3931
4303
|
sdk: "^0.2.0",
|
|
3932
4304
|
// Runs the aimonitor modules you point it at, and reads their folder.
|
|
@@ -3940,7 +4312,7 @@ var src_default2 = definePlugin({
|
|
|
3940
4312
|
|
|
3941
4313
|
// packages/server/src/official.ts
|
|
3942
4314
|
var BUNDLED_PLUGIN_IDS = ["agents", "cats", "system", "vitals", "usage", "weather", "calendar", "news", "mirror", "gitlab", "github", "calls", "timesheet", "llm", "gpu", "homeassistant"];
|
|
3943
|
-
var OPTIONAL_PLUGIN_IDS = ["doom", "video", "fractals", "gaming", "logs", "hazards"];
|
|
4315
|
+
var OPTIONAL_PLUGIN_IDS = ["doom", "video", "fractals", "gaming", "logs", "hazards", "batteries"];
|
|
3944
4316
|
var OFFICIAL_PLUGINS = [
|
|
3945
4317
|
...BUNDLED_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: true })),
|
|
3946
4318
|
...OPTIONAL_PLUGIN_IDS.map((id) => ({ id, npm: `kiosko-plugin-${id}`, bundled: false }))
|
package/sdk.js
CHANGED
|
@@ -14,7 +14,7 @@ var CATEGORIES = [
|
|
|
14
14
|
];
|
|
15
15
|
var ALERT_LEVELS = ["info", "warn", "critical"];
|
|
16
16
|
var PAD_KEYS = ["up", "down", "left", "right", "a", "b", "x", "y", "l", "r", "start", "select"];
|
|
17
|
-
var SDK_VERSION = "0.2.
|
|
17
|
+
var SDK_VERSION = "0.2.10";
|
|
18
18
|
function defineWidget(w) {
|
|
19
19
|
return w;
|
|
20
20
|
}
|