Skip to content

Commit a01c6ec

Browse files
committed
update pixel font plugin
1 parent 97dfb9f commit a01c6ec

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

public/litecanvas.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,42 +2213,44 @@
22132213
window.pluginFrameRateMeter = E;
22142214
})();
22152215
(() => {
2216-
var S = [[24, 60, 60, 24, 24, , 24], [54, 54, , , , , ,], [54, 54, 127, 54, 127, 54, 54], [12, 62, 3, 30, 48, 31, 12], [, 99, 51, 24, 12, 102, 99], [28, 54, 28, 110, 59, 51, 110], [6, 6, 3, , , , ,], [24, 12, 6, 6, 6, 12, 24], [6, 12, 24, 24, 24, 12, 6], [, 102, 60, 255, 60, 102, ,], [, 12, 12, 63, 12, 12, ,], [, , , , , 12, 12, 6], [, , , 63, , , ,], [, , , , , 12, 12], [96, 48, 24, 12, 6, 3, 1], [62, 99, 115, 123, 111, 103, 62], [12, 14, 12, 12, 12, 12, 63], [30, 51, 48, 28, 6, 51, 63], [30, 51, 48, 28, 48, 51, 30], [56, 60, 54, 51, 127, 48, 120], [63, 3, 31, 48, 48, 51, 30], [28, 6, 3, 31, 51, 51, 30], [63, 51, 48, 24, 12, 12, 12], [30, 51, 51, 30, 51, 51, 30], [30, 51, 51, 62, 48, 24, 14], [, 12, 12, , , 12, 12], [, 12, 12, , , 12, 12, 6], [24, 12, 6, 3, 6, 12, 24], [, , 63, , , 63, ,], [6, 12, 24, 48, 24, 12, 6], [30, 51, 48, 24, 12, , 12], [62, 99, 123, 123, 123, 3, 30], [12, 30, 51, 51, 63, 51, 51], [63, 102, 102, 62, 102, 102, 63], [60, 102, 3, 3, 3, 102, 60], [31, 54, 102, 102, 102, 54, 31], [127, 70, 22, 30, 22, 70, 127], [127, 70, 22, 30, 22, 6, 15], [60, 102, 3, 3, 115, 102, 124], [51, 51, 51, 63, 51, 51, 51], [30, 12, 12, 12, 12, 12, 30], [120, 48, 48, 48, 51, 51, 30], [103, 102, 54, 30, 54, 102, 103], [15, 6, 6, 6, 70, 102, 127], [99, 119, 127, 127, 107, 99, 99], [99, 103, 111, 123, 115, 99, 99], [28, 54, 99, 99, 99, 54, 28], [63, 102, 102, 62, 6, 6, 15], [30, 51, 51, 51, 59, 30, 56], [63, 102, 102, 62, 54, 102, 103], [30, 51, 7, 14, 56, 51, 30], [63, 45, 12, 12, 12, 12, 30], [51, 51, 51, 51, 51, 51, 63], [51, 51, 51, 51, 51, 30, 12], [99, 99, 99, 107, 127, 119, 99], [99, 99, 54, 28, 28, 54, 99], [51, 51, 51, 30, 12, 12, 30], [127, 99, 49, 24, 76, 102, 127], [30, 6, 6, 6, 6, 6, 30], [3, 6, 12, 24, 48, 96, 64], [30, 24, 24, 24, 24, 24, 30], [8, 28, 54, 99, , , ,], [, , , , , , , 255], [12, 12, 24, , , , ,], [, , 30, 48, 62, 51, 110], [7, 6, 6, 62, 102, 102, 59], [, , 30, 51, 3, 51, 30], [56, 48, 48, 62, 51, 51, 110], [, , 30, 51, 63, 3, 30], [28, 54, 6, 15, 6, 6, 15], [, , 110, 51, 51, 62, 48, 31], [7, 6, 54, 110, 102, 102, 103], [12, , 14, 12, 12, 12, 30], [48, , 48, 48, 48, 51, 51, 30], [7, 6, 102, 54, 30, 54, 103], [14, 12, 12, 12, 12, 12, 30], [, , 51, 127, 127, 107, 99], [, , 31, 51, 51, 51, 51], [, , 30, 51, 51, 51, 30], [, , 59, 102, 102, 62, 6, 15], [, , 110, 51, 51, 62, 48, 120], [, , 59, 110, 102, 6, 15], [, , 62, 3, 30, 48, 31], [8, 12, 62, 12, 12, 44, 24], [, , 51, 51, 51, 51, 110], [, , 51, 51, 51, 30, 12], [, , 99, 107, 127, 127, 54], [, , 99, 54, 28, 54, 99], [, , 51, 51, 51, 62, 48, 31], [, , 63, 25, 12, 38, 63], [56, 12, 12, 7, 12, 12, 56], [24, 24, 24, , 24, 24, 24], [7, 12, 12, 56, 12, 12, 7], [110, 59, , , , , ,]], w = { id: "basic", chars: S, first: 33, w: 8 };
2217-
var g = plugin = (e, { cache: o = true } = {}) => {
2218-
let y = e.text, _ = e.textsize, A = e.textalign, E = e.textfont, z = w, c = o ? /* @__PURE__ */ new Map() : null, p = 5 * 60, s = 1, n = null, b = (t) => {
2219-
s = Math.round(t / n.w);
2220-
}, C = () => console.warn("[litecanvas/plugin-pixel-font] textalign() has not yet been implemented for pixel fonts"), d = (t, l, x, i = 3) => {
2221-
for (let a = 0; a < n.w; a++) for (let r = 0; r < n.w; r++) (x[a] | 0) & 1 << r && e.rectfill(t + r * s, l + a * s, s, s, i);
2222-
}, T = (t, l, x, i = 3) => {
2223-
if (x += "", !s || !x.length) return;
2224-
let a = s * n.w;
2225-
for (let r = 0; r < x.length; r++) {
2226-
let m = x[r], v = m.charCodeAt(), u = n.chars[v - n.first];
2227-
if (u) if (o) {
2228-
let f = `${n.id}:${m}:${~~i}:${a}`;
2229-
c.has(f) || c.set(f, e.paint(a, a, () => {
2230-
d(0, 0, u, ~~i);
2216+
var k = [[24, 60, 60, 24, 24, , 24], [54, 54, , , , , ,], [54, 54, 127, 54, 127, 54, 54], [12, 62, 3, 30, 48, 31, 12], [, 99, 51, 24, 12, 102, 99], [28, 54, 28, 110, 59, 51, 110], [6, 6, 3, , , , ,], [24, 12, 6, 6, 6, 12, 24], [6, 12, 24, 24, 24, 12, 6], [, 102, 60, 255, 60, 102, ,], [, 12, 12, 63, 12, 12, ,], [, , , , , 12, 12, 6], [, , , 63, , , ,], [, , , , , 12, 12], [96, 48, 24, 12, 6, 3, 1], [62, 99, 115, 123, 111, 103, 62], [12, 14, 12, 12, 12, 12, 63], [30, 51, 48, 28, 6, 51, 63], [30, 51, 48, 28, 48, 51, 30], [56, 60, 54, 51, 127, 48, 120], [63, 3, 31, 48, 48, 51, 30], [28, 6, 3, 31, 51, 51, 30], [63, 51, 48, 24, 12, 12, 12], [30, 51, 51, 30, 51, 51, 30], [30, 51, 51, 62, 48, 24, 14], [, 12, 12, , , 12, 12], [, 12, 12, , , 12, 12, 6], [24, 12, 6, 3, 6, 12, 24], [, , 63, , , 63, ,], [6, 12, 24, 48, 24, 12, 6], [30, 51, 48, 24, 12, , 12], [62, 99, 123, 123, 123, 3, 30], [12, 30, 51, 51, 63, 51, 51], [63, 102, 102, 62, 102, 102, 63], [60, 102, 3, 3, 3, 102, 60], [31, 54, 102, 102, 102, 54, 31], [127, 70, 22, 30, 22, 70, 127], [127, 70, 22, 30, 22, 6, 15], [60, 102, 3, 3, 115, 102, 124], [51, 51, 51, 63, 51, 51, 51], [30, 12, 12, 12, 12, 12, 30], [120, 48, 48, 48, 51, 51, 30], [103, 102, 54, 30, 54, 102, 103], [15, 6, 6, 6, 70, 102, 127], [99, 119, 127, 127, 107, 99, 99], [99, 103, 111, 123, 115, 99, 99], [28, 54, 99, 99, 99, 54, 28], [63, 102, 102, 62, 6, 6, 15], [30, 51, 51, 51, 59, 30, 56], [63, 102, 102, 62, 54, 102, 103], [30, 51, 7, 14, 56, 51, 30], [63, 45, 12, 12, 12, 12, 30], [51, 51, 51, 51, 51, 51, 63], [51, 51, 51, 51, 51, 30, 12], [99, 99, 99, 107, 127, 119, 99], [99, 99, 54, 28, 28, 54, 99], [51, 51, 51, 30, 12, 12, 30], [127, 99, 49, 24, 76, 102, 127], [30, 6, 6, 6, 6, 6, 30], [3, 6, 12, 24, 48, 96, 64], [30, 24, 24, 24, 24, 24, 30], [8, 28, 54, 99, , , ,], [, , , , , , , 255], [12, 12, 24, , , , ,], [, , 30, 48, 62, 51, 110], [7, 6, 6, 62, 102, 102, 59], [, , 30, 51, 3, 51, 30], [56, 48, 48, 62, 51, 51, 110], [, , 30, 51, 63, 3, 30], [28, 54, 6, 15, 6, 6, 15], [, , 110, 51, 51, 62, 48, 31], [7, 6, 54, 110, 102, 102, 103], [12, , 14, 12, 12, 12, 30], [48, , 48, 48, 48, 51, 51, 30], [7, 6, 102, 54, 30, 54, 103], [14, 12, 12, 12, 12, 12, 30], [, , 51, 127, 127, 107, 99], [, , 31, 51, 51, 51, 51], [, , 30, 51, 51, 51, 30], [, , 59, 102, 102, 62, 6, 15], [, , 110, 51, 51, 62, 48, 120], [, , 59, 110, 102, 6, 15], [, , 62, 3, 30, 48, 31], [8, 12, 62, 12, 12, 44, 24], [, , 51, 51, 51, 51, 110], [, , 51, 51, 51, 30, 12], [, , 99, 107, 127, 127, 54], [, , 99, 54, 28, 54, 99], [, , 51, 51, 51, 62, 48, 31], [, , 63, 25, 12, 38, 63], [56, 12, 12, 7, 12, 12, 56], [24, 24, 24, , 24, 24, 24], [7, 12, 12, 56, 12, 12, 7], [110, 59, , , , , ,]], w = { id: "basic", chars: k, first: 33, w: 8, h: 8 };
2217+
var D = [[2, 2, 2, , 2], [5, 5], [5, 7, 5, 7, 5], [6, 3, 6, 7, 2], [5, 4, 2, 1, 5], [6, 3, 6, 5, 6], [2, 2, , , ,], [2, 1, 1, 1, 2], [2, 4, 4, 4, 2], [5, 2, 5], [, 2, 7, 2], [, , , , 2, 1], [, , 7], [, , , , 1], [4, 4, 2, 1, 1], [7, 5, 5, 5, 7], [3, 2, 2, 2, 7], [7, 4, 7, 1, 7], [7, 4, 7, 4, 7], [5, 5, 7, 4, 4], [7, 1, 7, 4, 7], [7, 1, 7, 5, 7], [7, 4, 4, 4, 4], [7, 5, 7, 5, 7], [7, 5, 7, 4, 7], [, , 2, , 2], [, , 2, , 2, 1], [4, 2, 1, 2, 4], [, 7, , 7], [1, 2, 4, 2, 1], [7, 4, 6, , 2], [2, 5, 5, 1, 6], [2, 5, 7, 5, 5], [3, 5, 3, 5, 3], [6, 1, 1, 1, 6], [3, 5, 5, 5, 3], [7, 1, 3, 1, 7], [7, 1, 3, 1, 1], [6, 1, 5, 5, 6], [5, 5, 7, 5, 5], [7, 2, 2, 2, 7], [4, 4, 4, 5, 2], [5, 5, 3, 5, 5], [1, 1, 1, 1, 7], [5, 7, 7, 5, 5], [7, 5, 5, 5, 5], [2, 5, 5, 5, 2], [7, 5, 7, 1, 1], [6, 5, 5, 3, 6], [3, 5, 3, 5, 5], [6, 1, 7, 4, 3], [7, 2, 2, 2, 2], [5, 5, 5, 5, 7], [5, 5, 5, 2, 2], [5, 5, 7, 7, 5], [5, 5, 2, 5, 5], [5, 5, 2, 2, 2], [7, 4, 2, 1, 7], [6, 2, 2, 2, 6], [1, 1, 2, 4, 4], [3, 2, 2, 2, 3], [2, 5], [, , , , 7], [1, 2], [, 6, 5, 5, 6], [1, 3, 5, 5, 3], [, 6, 1, 1, 6], [4, 6, 5, 5, 6], [, 2, 5, 3, 6], [4, 2, 7, 2, 2], [, 2, 5, 6, 4, 2], [1, 1, 3, 5, 5], [, 2, , 2, 2], [, 2, , 2, 2, 1], [1, 5, 3, 5, 5], [2, 2, 2, 2, 4], [, 5, 7, 5, 5], [, 3, 5, 5, 5], [, 2, 5, 5, 2], [, 3, 5, 5, 3, 1], [, 6, 5, 5, 6, 4], [, 2, 5, 1, 1], [, 6, 1, 4, 3], [2, 7, 2, 2, 4], [, 5, 5, 5, 6], [, 5, 5, 2, 2], [, 5, 5, 7, 5], [, 5, 2, 2, 5], [, 5, 5, 6, 4, 2], [, 7, 4, 1, 7], [6, 2, 1, 2, 6], [2, 2, 2, 2, 2], [3, 2, 4, 2, 3], [, 3, 6]], g = { id: "mini", chars: D, first: 33, w: 4, h: 6 };
2218+
var y = plugin = (e, { cache: m = true } = {}) => {
2219+
let _ = e.text, A = e.textsize, E = e.textalign, z = e.textfont, C = w, T = g, c = m ? /* @__PURE__ */ new Map() : null, b = 300, a = 1, t = null, d = (x) => {
2220+
a = ~~Math.round(x);
2221+
}, F = () => console.warn("[litecanvas/plugin-pixel-font] textalign() has not yet been implemented for pixel fonts"), v = (x, o, r, s = 3) => {
2222+
let l = t.h || t.w;
2223+
for (let i = 0; i < l; i++) for (let n = 0; n < t.w; n++) (r[i] | 0) & 1 << n && e.rectfill(x + n * a, o + i * a, a, a, s);
2224+
}, I = (x, o, r, s = 3) => {
2225+
if (r += "", !a || !r.length) return;
2226+
let l = a * t.w, i = a * (t.h || t.w);
2227+
for (let n = 0; n < r.length; n++) {
2228+
let u = r[n], S = u.charCodeAt(), f = t.chars[S - t.first];
2229+
if (f) if (m) {
2230+
let p = `${t.id}:${u}:${~~s}:${l}`;
2231+
c.has(p) || c.set(p, e.paint(l, i, () => {
2232+
v(0, 0, f, ~~s);
22312233
}));
2232-
let h = c.get(f);
2233-
h._ = e.T + p, e.image(t, l, h);
2234-
} else d(t, l, u, i);
2235-
t += a;
2234+
let h = c.get(p);
2235+
h._ = e.T + b, e.image(x, o, h);
2236+
} else v(x, o, f, s);
2237+
x += l;
22362238
}
22372239
};
2238-
if (o) {
2239-
let t = setInterval(() => {
2240-
let l = performance.now();
2241-
for (let [x, i] of c) e.T > i._ && c.delete(x);
2242-
}, 1e3 * (p / 5));
2240+
if (m) {
2241+
let x = setInterval(() => {
2242+
let o = performance.now();
2243+
for (let [r, s] of c) e.T > s._ && c.delete(r);
2244+
}, 1e3 * (b / 5));
22432245
e.listen("quit", () => {
2244-
clearInterval(t), c.clear();
2246+
clearInterval(x), c.clear();
22452247
});
22462248
}
2247-
return { PIXEL_FONT_BASIC: z, textfont: (t) => {
2248-
typeof t == "object" ? (e.def("text", T), e.def("textsize", b), e.def("textalign", C), n = t, b(n.w)) : (e.def("text", y), e.def("textsize", _), e.def("textalign", A), E(t));
2249+
return { PIXEL_FONT_BASIC: C, PIXEL_FONT_MINI: T, textfont: (x) => {
2250+
typeof x == "object" ? (e.def("text", I), e.def("textsize", d), e.def("textalign", F), t = x, d(a || 1)) : (e.def("text", _), e.def("textsize", A), e.def("textalign", E), z(x));
22492251
} };
22502252
};
2251-
window.pluginPixelFont = g;
2253+
window.pluginPixelFont = y;
22522254
})();
22532255
})();
22542256
/*! @litecanvas/utils by Luiz Bills | MIT Licensed */

public/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "2025.7.22.0";
2+
const version = "2025.7.22.1";
33

44
const precacheResources = [
55
"/",

0 commit comments

Comments
 (0)