kiosko 0.2.4 → 0.2.5
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 +1 -1
- package/cli.js +147 -26
- package/kit.js +30 -3
- package/package.json +1 -1
- package/sdk.js +1 -1
package/README.md
CHANGED
|
@@ -165,7 +165,7 @@ can run in PowerShell.
|
|
|
165
165
|
silently, with the tasks "start when I sign in" and "add `kiosko` to PATH":
|
|
166
166
|
|
|
167
167
|
```powershell
|
|
168
|
-
.\Kiosko-Setup-0.2.
|
|
168
|
+
.\Kiosko-Setup-0.2.5-x64.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /TASKS=service,path
|
|
169
169
|
```
|
|
170
170
|
|
|
171
171
|
Open a new terminal afterwards so `kiosko` is on the `PATH` (or use
|
package/cli.js
CHANGED
|
@@ -346,19 +346,39 @@ function setDefaultFamily(family) {
|
|
|
346
346
|
defaultFamily = family;
|
|
347
347
|
}
|
|
348
348
|
function registerFontFiles(fonts) {
|
|
349
|
+
widths.clear();
|
|
349
350
|
return Object.entries(fonts).filter(([family, path]) => !GlobalFonts.registerFromPath(path, family)).map(([, path]) => path);
|
|
350
351
|
}
|
|
352
|
+
function widthOf(ctx, font, ch) {
|
|
353
|
+
let byChar = widths.get(font);
|
|
354
|
+
if (!byChar) {
|
|
355
|
+
if (widths.size >= MAX_FONTS) widths.clear();
|
|
356
|
+
byChar = /* @__PURE__ */ new Map();
|
|
357
|
+
widths.set(font, byChar);
|
|
358
|
+
}
|
|
359
|
+
let w = byChar.get(ch);
|
|
360
|
+
if (w === void 0) {
|
|
361
|
+
if (ctx.font !== font) ctx.font = font;
|
|
362
|
+
w = ctx.measureText(ch).width;
|
|
363
|
+
byChar.set(ch, w);
|
|
364
|
+
}
|
|
365
|
+
return w;
|
|
366
|
+
}
|
|
367
|
+
function clearTextCache() {
|
|
368
|
+
widths.clear();
|
|
369
|
+
}
|
|
351
370
|
function glyphs(ctx, text2, o) {
|
|
352
371
|
const family = o.family ?? defaultFamily;
|
|
353
372
|
const small = o.smallCaps === true;
|
|
354
373
|
const capSize = o.size * (o.capRatio ?? 0.76);
|
|
355
374
|
const out = [];
|
|
375
|
+
const font = `${o.size}px "${family}"`;
|
|
376
|
+
const capFont = `${capSize}px "${family}"`;
|
|
356
377
|
for (const ch of text2) {
|
|
357
378
|
const isLower = small && ch !== ch.toUpperCase() && ch === ch.toLowerCase();
|
|
358
379
|
const size = isLower ? capSize : o.size;
|
|
359
380
|
const draw = small ? ch.toUpperCase() : ch;
|
|
360
|
-
|
|
361
|
-
out.push({ ch: draw, size, width: ctx.measureText(draw).width });
|
|
381
|
+
out.push({ ch: draw, size, width: widthOf(ctx, isLower ? capFont : font, draw) });
|
|
362
382
|
}
|
|
363
383
|
return out;
|
|
364
384
|
}
|
|
@@ -377,8 +397,12 @@ function drawTracked(ctx, text2, x, y, o) {
|
|
|
377
397
|
let cursor = o.align === "right" ? x - total : o.align === "center" ? x - total / 2 : x;
|
|
378
398
|
if (o.color) ctx.fillStyle = o.color;
|
|
379
399
|
ctx.textBaseline = "alphabetic";
|
|
400
|
+
let size = -1;
|
|
380
401
|
for (const g of gs) {
|
|
381
|
-
|
|
402
|
+
if (g.size !== size) {
|
|
403
|
+
ctx.font = `${g.size}px "${family}"`;
|
|
404
|
+
size = g.size;
|
|
405
|
+
}
|
|
382
406
|
ctx.fillText(g.ch, cursor, y);
|
|
383
407
|
cursor += g.width + tracking;
|
|
384
408
|
}
|
|
@@ -433,11 +457,13 @@ function wrapLines(ctx, text2, maxWidth, maxLines, o) {
|
|
|
433
457
|
}
|
|
434
458
|
return lines;
|
|
435
459
|
}
|
|
436
|
-
var defaultFamily;
|
|
460
|
+
var defaultFamily, widths, MAX_FONTS;
|
|
437
461
|
var init_text = __esm({
|
|
438
462
|
"packages/lcd-canvas-kit/src/text.ts"() {
|
|
439
463
|
"use strict";
|
|
440
464
|
defaultFamily = "sans-serif";
|
|
465
|
+
widths = /* @__PURE__ */ new Map();
|
|
466
|
+
MAX_FONTS = 400;
|
|
441
467
|
}
|
|
442
468
|
});
|
|
443
469
|
|
|
@@ -750,6 +776,7 @@ __export(src_exports, {
|
|
|
750
776
|
TAU: () => TAU,
|
|
751
777
|
bezierPts: () => bezierPts,
|
|
752
778
|
clamp: () => clamp3,
|
|
779
|
+
clearTextCache: () => clearTextCache,
|
|
753
780
|
css: () => css,
|
|
754
781
|
drawClipped: () => drawClipped,
|
|
755
782
|
drawMoonPhase: () => drawMoonPhase,
|
|
@@ -791,7 +818,7 @@ __export(testing_exports, {
|
|
|
791
818
|
renderWidget: () => renderWidget,
|
|
792
819
|
widgetState: () => widgetState
|
|
793
820
|
});
|
|
794
|
-
import { createCanvas as
|
|
821
|
+
import { createCanvas as createCanvas5, loadImage as loadImage4 } from "@napi-rs/canvas";
|
|
795
822
|
function resolve3(w, o) {
|
|
796
823
|
const now = o.now ?? Date.UTC(2026, 10, 5, 9, 42);
|
|
797
824
|
const locale = o.locale ?? "en";
|
|
@@ -808,7 +835,7 @@ function renderWidget(w, o = {}) {
|
|
|
808
835
|
const theme = typeof o.theme === "object" ? o.theme : themeById(o.theme);
|
|
809
836
|
const texts = [];
|
|
810
837
|
const spy = { ...src_exports, drawTracked: (...a) => (texts.push(a[1]), drawTracked(...a)) };
|
|
811
|
-
const canvas =
|
|
838
|
+
const canvas = createCanvas5(size.w + 2 * MARGIN, size.h + 2 * MARGIN);
|
|
812
839
|
const g = canvas.getContext("2d");
|
|
813
840
|
const box = { x: MARGIN, y: MARGIN, w: size.w, h: size.h };
|
|
814
841
|
const ctx = {
|
|
@@ -821,7 +848,7 @@ function renderWidget(w, o = {}) {
|
|
|
821
848
|
theme,
|
|
822
849
|
fonts: theme.fonts,
|
|
823
850
|
kit: spy,
|
|
824
|
-
canvas: { createCanvas:
|
|
851
|
+
canvas: { createCanvas: createCanvas5, loadImage: loadImage4 },
|
|
825
852
|
preview: !!o.preview
|
|
826
853
|
};
|
|
827
854
|
const t0 = performance.now();
|
|
@@ -849,7 +876,7 @@ function renderWidget(w, o = {}) {
|
|
|
849
876
|
ms,
|
|
850
877
|
...error !== void 0 ? { error } : {},
|
|
851
878
|
png() {
|
|
852
|
-
const out =
|
|
879
|
+
const out = createCanvas5(box.w, box.h);
|
|
853
880
|
out.getContext("2d").drawImage(canvas, -box.x, -box.y);
|
|
854
881
|
return out.toBuffer("image/png");
|
|
855
882
|
}
|
|
@@ -1110,7 +1137,7 @@ var CATEGORIES = [
|
|
|
1110
1137
|
{ id: "scene", label: { en: "Scenes", es: "Escenas" } },
|
|
1111
1138
|
{ id: "fun", label: { en: "Fun", es: "Diversi\xF3n" } }
|
|
1112
1139
|
];
|
|
1113
|
-
var SDK_VERSION = "0.2.
|
|
1140
|
+
var SDK_VERSION = "0.2.5";
|
|
1114
1141
|
function defineWidget(w) {
|
|
1115
1142
|
return w;
|
|
1116
1143
|
}
|
|
@@ -2720,13 +2747,106 @@ function pickPage(pages, now, pinned) {
|
|
|
2720
2747
|
|
|
2721
2748
|
// packages/core/src/compositor.ts
|
|
2722
2749
|
init_src();
|
|
2723
|
-
import { createCanvas as
|
|
2750
|
+
import { createCanvas as createCanvas4, loadImage as loadImage3 } from "@napi-rs/canvas";
|
|
2724
2751
|
|
|
2725
2752
|
// packages/core/src/env.ts
|
|
2726
2753
|
init_src();
|
|
2727
2754
|
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
2755
|
+
import { createCanvas as createCanvas3, loadImage as loadImage2 } from "@napi-rs/canvas";
|
|
2756
|
+
|
|
2757
|
+
// packages/core/src/scaled-images.ts
|
|
2758
|
+
import { createRequire } from "node:module";
|
|
2759
|
+
import { Worker } from "node:worker_threads";
|
|
2728
2760
|
import { createCanvas as createCanvas2, loadImage } from "@napi-rs/canvas";
|
|
2729
|
-
|
|
2761
|
+
function scaledSize(w, h, size) {
|
|
2762
|
+
const sx = size.width / w, sy = size.height / h;
|
|
2763
|
+
const s = Math.min(1, (size.fit ?? "cover") === "cover" ? Math.max(sx, sy) : Math.min(sx, sy));
|
|
2764
|
+
return { width: Math.max(1, Math.round(w * s)), height: Math.max(1, Math.round(h * s)) };
|
|
2765
|
+
}
|
|
2766
|
+
var WORKER = `
|
|
2767
|
+
const { parentPort, workerData } = require('node:worker_threads');
|
|
2768
|
+
const { readFile } = require('node:fs/promises');
|
|
2769
|
+
const { createCanvas, loadImage } = require(workerData.canvas);
|
|
2770
|
+
const scaledSize = ${scaledSize.toString()};
|
|
2771
|
+
parentPort.on('message', async (job) => {
|
|
2772
|
+
try {
|
|
2773
|
+
const src = typeof job.src === 'string' ? await readFile(job.src) : Buffer.from(job.src);
|
|
2774
|
+
const img = await loadImage(src);
|
|
2775
|
+
const to = scaledSize(img.width, img.height, job.size);
|
|
2776
|
+
if (to.width >= img.width && to.height >= img.height) {
|
|
2777
|
+
// Already small enough: the bytes as they are.
|
|
2778
|
+
parentPort.postMessage({ id: job.id, ok: true, same: true });
|
|
2779
|
+
return;
|
|
2780
|
+
}
|
|
2781
|
+
const c = createCanvas(to.width, to.height);
|
|
2782
|
+
const g = c.getContext('2d');
|
|
2783
|
+
g.imageSmoothingQuality = 'high';
|
|
2784
|
+
g.drawImage(img, 0, 0, to.width, to.height);
|
|
2785
|
+
const png = src[0] === 0x89 && src[1] === 0x50;
|
|
2786
|
+
const out = png ? await c.encode('png') : await c.encode('jpeg', 90);
|
|
2787
|
+
const ab = out.buffer.slice(out.byteOffset, out.byteOffset + out.byteLength);
|
|
2788
|
+
parentPort.postMessage({ id: job.id, ok: true, bytes: ab }, [ab]);
|
|
2789
|
+
} catch (err) {
|
|
2790
|
+
parentPort.postMessage({ id: job.id, ok: false, error: err && err.message ? err.message : String(err) });
|
|
2791
|
+
}
|
|
2792
|
+
});
|
|
2793
|
+
`;
|
|
2794
|
+
var worker = null;
|
|
2795
|
+
var broken = false;
|
|
2796
|
+
var nextId = 1;
|
|
2797
|
+
var pending = /* @__PURE__ */ new Map();
|
|
2798
|
+
function startWorker() {
|
|
2799
|
+
if (worker) return worker;
|
|
2800
|
+
if (broken) return null;
|
|
2801
|
+
try {
|
|
2802
|
+
const canvas = createRequire(import.meta.url).resolve("@napi-rs/canvas");
|
|
2803
|
+
const w = new Worker(WORKER, { eval: true, workerData: { canvas } });
|
|
2804
|
+
w.on("message", (m) => {
|
|
2805
|
+
const p = pending.get(m.id);
|
|
2806
|
+
if (!p) return;
|
|
2807
|
+
pending.delete(m.id);
|
|
2808
|
+
if (!pending.size) w.unref();
|
|
2809
|
+
if (m.ok) p.resolve(m);
|
|
2810
|
+
else p.reject(new Error(m.error ?? "could not scale the image"));
|
|
2811
|
+
});
|
|
2812
|
+
const gone = (err) => {
|
|
2813
|
+
if (worker === w) worker = null;
|
|
2814
|
+
for (const [id, p] of pending) {
|
|
2815
|
+
pending.delete(id);
|
|
2816
|
+
p.reject(err ?? new Error("the image thread stopped"));
|
|
2817
|
+
}
|
|
2818
|
+
};
|
|
2819
|
+
w.on("error", gone);
|
|
2820
|
+
w.on("exit", () => gone());
|
|
2821
|
+
w.unref();
|
|
2822
|
+
worker = w;
|
|
2823
|
+
return w;
|
|
2824
|
+
} catch {
|
|
2825
|
+
broken = true;
|
|
2826
|
+
return null;
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
function warm(img) {
|
|
2830
|
+
const w = Math.max(1, Math.round(img.width / 3)), h = Math.max(1, Math.round(img.height / 3));
|
|
2831
|
+
createCanvas2(w, h).getContext("2d").drawImage(img, 0, 0, w, h);
|
|
2832
|
+
return img;
|
|
2833
|
+
}
|
|
2834
|
+
async function loadImageScaled(src, size) {
|
|
2835
|
+
if (!(size.width > 0) || !(size.height > 0)) throw new Error("loadImageScaled: width and height must be over 0");
|
|
2836
|
+
const w = startWorker();
|
|
2837
|
+
if (!w) return warm(await loadImage(src));
|
|
2838
|
+
const id = nextId++;
|
|
2839
|
+
const job = typeof src === "string" ? src : src.buffer.slice(src.byteOffset, src.byteOffset + src.byteLength);
|
|
2840
|
+
const r = await new Promise((resolve8, reject) => {
|
|
2841
|
+
pending.set(id, { resolve: resolve8, reject });
|
|
2842
|
+
w.ref();
|
|
2843
|
+
w.postMessage({ id, src: job, size });
|
|
2844
|
+
});
|
|
2845
|
+
return warm(await loadImage(r.same || !r.bytes ? src : Buffer.from(r.bytes)));
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
// packages/core/src/env.ts
|
|
2849
|
+
var CANVAS = { createCanvas: createCanvas3, loadImage: loadImage2, loadImageScaled };
|
|
2730
2850
|
function systemLocale() {
|
|
2731
2851
|
try {
|
|
2732
2852
|
return Intl.DateTimeFormat().resolvedOptions().locale || "en";
|
|
@@ -2772,10 +2892,10 @@ function baseContext(cfg, plugin, log, now) {
|
|
|
2772
2892
|
|
|
2773
2893
|
// packages/core/src/fonts.ts
|
|
2774
2894
|
import { existsSync as existsSync3 } from "node:fs";
|
|
2775
|
-
import { createRequire } from "node:module";
|
|
2895
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
2776
2896
|
import { dirname as dirname2, join as join3 } from "node:path";
|
|
2777
2897
|
import { GlobalFonts as GlobalFonts2 } from "@napi-rs/canvas";
|
|
2778
|
-
var require2 =
|
|
2898
|
+
var require2 = createRequire2(import.meta.url);
|
|
2779
2899
|
var done = false;
|
|
2780
2900
|
function ttfDir() {
|
|
2781
2901
|
try {
|
|
@@ -2806,7 +2926,7 @@ var images = /* @__PURE__ */ new Map();
|
|
|
2806
2926
|
function backgroundImage(path) {
|
|
2807
2927
|
if (!images.has(path)) {
|
|
2808
2928
|
images.set(path, null);
|
|
2809
|
-
|
|
2929
|
+
loadImage3(path).then((img) => images.set(path, img)).catch(() => void 0);
|
|
2810
2930
|
}
|
|
2811
2931
|
return images.get(path) ?? null;
|
|
2812
2932
|
}
|
|
@@ -2941,7 +3061,7 @@ function paintTile(g, input, tile, rect2, out, nextAt, idles, animatable) {
|
|
|
2941
3061
|
if (hit.error) out.error = hit.error;
|
|
2942
3062
|
return;
|
|
2943
3063
|
}
|
|
2944
|
-
const canvas =
|
|
3064
|
+
const canvas = createCanvas4(rect2.w, rect2.h);
|
|
2945
3065
|
const tg = canvas.getContext("2d");
|
|
2946
3066
|
tg.translate(-rect2.x, -rect2.y);
|
|
2947
3067
|
draw(tg);
|
|
@@ -3004,7 +3124,7 @@ function drawTileContent(g, input, r, rect2, chrome, out, anim) {
|
|
|
3004
3124
|
function composePage(input) {
|
|
3005
3125
|
registerFonts();
|
|
3006
3126
|
const { screen, page, theme, now } = input;
|
|
3007
|
-
const canvas =
|
|
3127
|
+
const canvas = createCanvas4(screen.width, screen.height);
|
|
3008
3128
|
const g = canvas.getContext("2d");
|
|
3009
3129
|
g.fillStyle = page.background.color || theme.colors.bg;
|
|
3010
3130
|
g.fillRect(0, 0, screen.width, screen.height);
|
|
@@ -3038,7 +3158,7 @@ function composePage(input) {
|
|
|
3038
3158
|
function rotateCanvas(src, rotate) {
|
|
3039
3159
|
if (!rotate) return src;
|
|
3040
3160
|
const swap = rotate === 90 || rotate === 270;
|
|
3041
|
-
const out =
|
|
3161
|
+
const out = createCanvas4(swap ? src.height : src.width, swap ? src.width : src.height);
|
|
3042
3162
|
const g = out.getContext("2d");
|
|
3043
3163
|
g.translate(out.width / 2, out.height / 2);
|
|
3044
3164
|
g.rotate(rotate * Math.PI / 180);
|
|
@@ -5555,6 +5675,7 @@ function placeImage(box, w, h, fit3, position) {
|
|
|
5555
5675
|
const fy = position === "top" ? 0 : position === "bottom" ? 1 : 0.5;
|
|
5556
5676
|
return { x: box.x + (box.w - dw) * fx, y: box.y + (box.h - dh) * fy, w: dw, h: dh };
|
|
5557
5677
|
}
|
|
5678
|
+
var load = (canvas, src) => canvas.loadImageScaled ? canvas.loadImageScaled(src, { width: 1920, height: 1080, fit: "cover" }) : canvas.loadImage(src);
|
|
5558
5679
|
var image = defineWidget({
|
|
5559
5680
|
id: "image",
|
|
5560
5681
|
name: { en: "Picture", es: "Imagen" },
|
|
@@ -5595,11 +5716,11 @@ var image = defineWidget({
|
|
|
5595
5716
|
if (/^https?:/.test(options2.src)) {
|
|
5596
5717
|
const res = await fetch(imageUrl(options2.src, Date.now(), options2.addTimestamp), { signal });
|
|
5597
5718
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
5598
|
-
return { img: await canvas
|
|
5719
|
+
return { img: await load(canvas, Buffer.from(await res.arrayBuffer())) };
|
|
5599
5720
|
}
|
|
5600
5721
|
const path = (await stat(options2.src)).isDirectory() ? await nextInFolder(options2.src) : options2.src;
|
|
5601
5722
|
if (!path) throw new Error(`no pictures in ${options2.src}`);
|
|
5602
|
-
return { img: await canvas
|
|
5723
|
+
return { img: await load(canvas, path) };
|
|
5603
5724
|
},
|
|
5604
5725
|
render(g, { box, data, options: options2, theme, kit, t: tr }) {
|
|
5605
5726
|
const img = data?.img;
|
|
@@ -5625,7 +5746,7 @@ var image = defineWidget({
|
|
|
5625
5746
|
var src_default = definePlugin({
|
|
5626
5747
|
id: "core",
|
|
5627
5748
|
name: { en: "Essentials", es: "B\xE1sicos" },
|
|
5628
|
-
version: "0.2.
|
|
5749
|
+
version: "0.2.5",
|
|
5629
5750
|
sdk: "^0.2.0",
|
|
5630
5751
|
// The picture widget reads the image (or folder, or URL) you give it.
|
|
5631
5752
|
permissions: { files: ["user"], network: ["user"] },
|
|
@@ -5649,7 +5770,7 @@ function resolveModule(name, dir) {
|
|
|
5649
5770
|
}
|
|
5650
5771
|
return null;
|
|
5651
5772
|
}
|
|
5652
|
-
async function
|
|
5773
|
+
async function load2(path) {
|
|
5653
5774
|
const hit = loaded.get(path);
|
|
5654
5775
|
if (hit) return hit;
|
|
5655
5776
|
const m = (await import(pathToFileURL3(path).href)).default;
|
|
@@ -5691,7 +5812,7 @@ var module2 = defineWidget({
|
|
|
5691
5812
|
if (!options2.module) throw new Error("no module set");
|
|
5692
5813
|
const path = resolveModule(options2.module, options2.dir);
|
|
5693
5814
|
if (!path) throw new Error(`module "${options2.module}" not found in ${options2.dir}`);
|
|
5694
|
-
const mod = await
|
|
5815
|
+
const mod = await load2(path);
|
|
5695
5816
|
if (options2.json.trim()) JSON.parse(options2.json);
|
|
5696
5817
|
const data = mod.fetch ? await mod.fetch({ config: moduleConfig(mod, options2), now, log, canvas }) : void 0;
|
|
5697
5818
|
return { path, data };
|
|
@@ -5720,7 +5841,7 @@ var module2 = defineWidget({
|
|
|
5720
5841
|
var src_default2 = definePlugin({
|
|
5721
5842
|
id: "legacy",
|
|
5722
5843
|
name: { en: "aimonitor compatibility", es: "Compatibilidad aimonitor" },
|
|
5723
|
-
version: "0.2.
|
|
5844
|
+
version: "0.2.5",
|
|
5724
5845
|
sdk: "^0.2.0",
|
|
5725
5846
|
// Runs the aimonitor modules you point it at, and reads their folder.
|
|
5726
5847
|
permissions: { exec: ["user"], files: ["user"] },
|
|
@@ -6751,7 +6872,7 @@ function runService(action, plan) {
|
|
|
6751
6872
|
// packages/server/src/server.ts
|
|
6752
6873
|
import { existsSync as existsSync12, readFileSync as readFileSync7, statSync as statSync3 } from "node:fs";
|
|
6753
6874
|
import { createServer } from "node:http";
|
|
6754
|
-
import { createRequire as
|
|
6875
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
6755
6876
|
import { dirname as dirname6, extname, join as join15, normalize as normPath, resolve as resolve7 } from "node:path";
|
|
6756
6877
|
|
|
6757
6878
|
// packages/server/src/plugins-manage.ts
|
|
@@ -7270,7 +7391,7 @@ var HomeAssistantBridge = class {
|
|
|
7270
7391
|
};
|
|
7271
7392
|
|
|
7272
7393
|
// packages/server/src/server.ts
|
|
7273
|
-
var require3 =
|
|
7394
|
+
var require3 = createRequire3(import.meta.url);
|
|
7274
7395
|
var MIME = {
|
|
7275
7396
|
".html": "text/html; charset=utf-8",
|
|
7276
7397
|
".js": "text/javascript; charset=utf-8",
|
|
@@ -7623,7 +7744,7 @@ function starterConfig(registry2, o = {}) {
|
|
|
7623
7744
|
}
|
|
7624
7745
|
|
|
7625
7746
|
// packages/server/src/cli.ts
|
|
7626
|
-
var VERSION = "0.2.
|
|
7747
|
+
var VERSION = "0.2.5";
|
|
7627
7748
|
var USAGE2 = `Kiosko ${VERSION}: a widget mosaic for USB LCD panels
|
|
7628
7749
|
|
|
7629
7750
|
kiosko start [--port 7420] [--host 127.0.0.1] [--config file] [--open] [--demo]
|
package/kit.js
CHANGED
|
@@ -7,19 +7,41 @@ function setDefaultFamily(family) {
|
|
|
7
7
|
defaultFamily = family;
|
|
8
8
|
}
|
|
9
9
|
function registerFontFiles(fonts) {
|
|
10
|
+
widths.clear();
|
|
10
11
|
return Object.entries(fonts).filter(([family, path]) => !GlobalFonts.registerFromPath(path, family)).map(([, path]) => path);
|
|
11
12
|
}
|
|
13
|
+
var widths = /* @__PURE__ */ new Map();
|
|
14
|
+
var MAX_FONTS = 400;
|
|
15
|
+
function widthOf(ctx, font, ch) {
|
|
16
|
+
let byChar = widths.get(font);
|
|
17
|
+
if (!byChar) {
|
|
18
|
+
if (widths.size >= MAX_FONTS) widths.clear();
|
|
19
|
+
byChar = /* @__PURE__ */ new Map();
|
|
20
|
+
widths.set(font, byChar);
|
|
21
|
+
}
|
|
22
|
+
let w = byChar.get(ch);
|
|
23
|
+
if (w === void 0) {
|
|
24
|
+
if (ctx.font !== font) ctx.font = font;
|
|
25
|
+
w = ctx.measureText(ch).width;
|
|
26
|
+
byChar.set(ch, w);
|
|
27
|
+
}
|
|
28
|
+
return w;
|
|
29
|
+
}
|
|
30
|
+
function clearTextCache() {
|
|
31
|
+
widths.clear();
|
|
32
|
+
}
|
|
12
33
|
function glyphs(ctx, text, o) {
|
|
13
34
|
const family = o.family ?? defaultFamily;
|
|
14
35
|
const small = o.smallCaps === true;
|
|
15
36
|
const capSize = o.size * (o.capRatio ?? 0.76);
|
|
16
37
|
const out = [];
|
|
38
|
+
const font = `${o.size}px "${family}"`;
|
|
39
|
+
const capFont = `${capSize}px "${family}"`;
|
|
17
40
|
for (const ch of text) {
|
|
18
41
|
const isLower = small && ch !== ch.toUpperCase() && ch === ch.toLowerCase();
|
|
19
42
|
const size = isLower ? capSize : o.size;
|
|
20
43
|
const draw = small ? ch.toUpperCase() : ch;
|
|
21
|
-
|
|
22
|
-
out.push({ ch: draw, size, width: ctx.measureText(draw).width });
|
|
44
|
+
out.push({ ch: draw, size, width: widthOf(ctx, isLower ? capFont : font, draw) });
|
|
23
45
|
}
|
|
24
46
|
return out;
|
|
25
47
|
}
|
|
@@ -38,8 +60,12 @@ function drawTracked(ctx, text, x, y, o) {
|
|
|
38
60
|
let cursor = o.align === "right" ? x - total : o.align === "center" ? x - total / 2 : x;
|
|
39
61
|
if (o.color) ctx.fillStyle = o.color;
|
|
40
62
|
ctx.textBaseline = "alphabetic";
|
|
63
|
+
let size = -1;
|
|
41
64
|
for (const g of gs) {
|
|
42
|
-
|
|
65
|
+
if (g.size !== size) {
|
|
66
|
+
ctx.font = `${g.size}px "${family}"`;
|
|
67
|
+
size = g.size;
|
|
68
|
+
}
|
|
43
69
|
ctx.fillText(g.ch, cursor, y);
|
|
44
70
|
cursor += g.width + tracking;
|
|
45
71
|
}
|
|
@@ -373,6 +399,7 @@ export {
|
|
|
373
399
|
TAU,
|
|
374
400
|
bezierPts,
|
|
375
401
|
clamp,
|
|
402
|
+
clearTextCache,
|
|
376
403
|
css,
|
|
377
404
|
drawClipped,
|
|
378
405
|
drawMoonPhase,
|
package/package.json
CHANGED
package/sdk.js
CHANGED