UNPKG

favicon-badge-notify

Version:
29 lines (28 loc) 1.01 kB
const g = ({ src: i, backgroundColor: l = "red", textColor: s = "white" }) => { let n = 96; const a = (document == null ? void 0 : document.createElement("canvas")) || {}; a.width = n, a.height = n; const e = a == null ? void 0 : a.getContext("2d"), t = document == null ? void 0 : document.createElement("img"); let o = () => { }; const c = (d) => { e.drawImage(t, 0, 0, n, n), e.beginPath(), e.arc(a.width - n / 3, n / 3, n / 3, 0, 2 * Math.PI), e.fillStyle = l, e.fill(), e.font = '55px "helvetica", sans-serif', e.textAlign = "center", e.textBaseline = "middle", e.fillStyle = s, e.fillText(d, a.width - n / 3, n / 3); }; return { drawBadge: (d) => (t == null || t.setAttribute("src", i), new Promise((r) => { o = () => { d && e ? (c(d), r(a.toDataURL("image/png"))) : r(i); }, t == null || t.addEventListener("load", o); })), destroyBadge: () => { t == null || t.removeEventListener("load", o); } }; }; export { g as default };