UNPKG

@idmwx/idmui-gl4

Version:

idm webgl4

93 lines (92 loc) 3.25 kB
import { l as b } from "./index-1599be89.js"; function M(e) { return typeof e == "string" && /^data:image\/svg\+xml/i.test(e); } function C(e) { let r = e.indexOf(","); return r >= 0 ? decodeURIComponent(e.slice(r + 1)) : ""; } function v(e) { return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`; } function F(e) { let r = [], t = "", i = 0; for (let o = 0; o < e.length; o++) { let n = e[o]; n === "(" && i++, n === ")" && (i = Math.max(0, i - 1)), n === ";" && i === 0 ? (r.push(t), t = "") : t += n; } return t.trim() && r.push(t), r.map((o) => o.trim()).filter(Boolean); } function k(e) { let r = [], t = "", i = 0; for (let n = 0; n < e.length; n++) { let s = e[n]; s === "(" && i++, s === ")" && (i = Math.max(0, i - 1)), s === "," && i === 0 ? (r.push(t.trim()), t = "") : t += s; } t.trim() && r.push(t.trim()); let o = []; for (let n of r) { if (/\binset\b/i.test(n)) continue; let s = n.match(/-?\d+(?:\.\d+)?px/gi) || [], [l = "0px", a = "0px", m = "0px"] = s, u = n.replace(/-?\d+(?:\.\d+)?px/gi, "").replace(/\binset\b/ig, "").trim().replace(/\s{2,}/g, " "), d = !!u && u !== ","; o.push(`drop-shadow(${l} ${a} ${m}${d ? ` ${u}` : ""})`); } return o.join(" "); } function y(e) { let r = F(e), t = null, i = null, o = null, n = []; for (let l of r) { let a = l.indexOf(":"); if (a < 0) continue; let m = l.slice(0, a).trim().toLowerCase(), u = l.slice(a + 1).trim(); m === "box-shadow" ? o = u : m === "filter" ? t = u : m === "-webkit-filter" ? i = u : n.push([m, u]); } if (o) { let l = k(o); l && (t = t ? `${t} ${l}` : l, i = i ? `${i} ${l}` : l); } let s = [...n]; return t && s.push(["filter", t]), i && s.push(["-webkit-filter", i]), s.map(([l, a]) => `${l}:${a}`).join(";"); } function I(e) { return e.replace(/([^{}]+)\{([^}]*)\}/g, (r, t, i) => `${t}{${y(i)}}`); } function N(e) { return e = e.replace(/<style[^>]*>([\s\S]*?)<\/style>/gi, (r, t) => r.replace(t, I(t))), e = e.replace(/style=(['"])([\s\S]*?)\1/gi, (r, t, i) => `style=${t}${y(i)}${t}`), e; } function S(e) { if (!b() || !M(e)) return e; try { let r = C(e), t = N(r); return v(t); } catch { return e; } } async function R(e, r) { let { width: t, height: i, scale: o = 1, dpr: n = 1, meta: s = {}, backgroundColor: l } = r; e = S(e); let a = new Image(); a.loading = "eager", a.decoding = "sync", a.crossOrigin = "anonymous", a.src = e, await a.decode(); let m = a.naturalWidth, u = a.naturalHeight, d = Number.isFinite(s.w0) ? s.w0 : m, x = Number.isFinite(s.h0) ? s.h0 : u, c, f, $ = Number.isFinite(t), w = Number.isFinite(i); if ($ && w) c = Math.max(1, t), f = Math.max(1, i); else if ($) { let g = t / Math.max(1, d); c = t, f = x * g; } else if (w) { let g = i / Math.max(1, x); f = i, c = d * g; } else c = m, f = u; c = c * o, f = f * o; let h = document.createElement("canvas"); h.width = c * n, h.height = f * n, h.style.width = `${c}px`, h.style.height = `${f}px`; let p = h.getContext("2d"); return n !== 1 && p.scale(n, n), l && (p.save(), p.fillStyle = l, p.fillRect(0, 0, c, f), p.restore()), p.drawImage(a, 0, 0, c, f), h; } export { R as W };