kiosko 0.2.3 → 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 +5 -1
- package/cli.js +643 -42
- package/kit.js +30 -3
- package/package.json +1 -1
- package/sdk.js +1 -1
- package/web/assets/app.js +3 -3
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