ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
269 lines (268 loc) • 8.11 kB
JavaScript
import { n as v } from "./chunk-Y2CYZVJY-0JxdZxki.js";
import { m as w } from "./src-DtRLxcYO.js";
import { b as A, z as P } from "./chunk-WYO6CB5R-DDHkKowO.js";
var z = Object.freeze({
left: 0,
top: 0,
width: 16,
height: 16
}), x = Object.freeze({
rotate: 0,
vFlip: !1,
hFlip: !1
}), $ = Object.freeze({
...z,
...x
}), C = Object.freeze({
...$,
body: "",
hidden: !1
}), G = Object.freeze({
width: null,
height: null
}), V = Object.freeze({
...G,
...x
}), R = (t, n, i, r = "") => {
const e = t.split(":");
if (t.slice(0, 1) === "@") {
if (e.length < 2 || e.length > 3) return null;
r = e.shift().slice(1);
}
if (e.length > 3 || !e.length) return null;
if (e.length > 1) {
const l = e.pop(), f = e.pop(), u = {
provider: e.length > 0 ? e[0] : r,
prefix: f,
name: l
};
return n && !m(u) ? null : u;
}
const o = e[0], s = o.split("-");
if (s.length > 1) {
const l = {
provider: r,
prefix: s.shift(),
name: s.join("-")
};
return n && !m(l) ? null : l;
}
if (i && r === "") {
const l = {
provider: r,
prefix: "",
name: o
};
return n && !m(l, i) ? null : l;
}
return null;
}, m = (t, n) => t ? !!((n && t.prefix === "" || t.prefix) && t.name) : !1;
function H(t, n) {
const i = {};
!t.hFlip != !n.hFlip && (i.hFlip = !0), !t.vFlip != !n.vFlip && (i.vFlip = !0);
const r = ((t.rotate || 0) + (n.rotate || 0)) % 4;
return r && (i.rotate = r), i;
}
function D(t, n) {
const i = H(t, n);
for (const r in C) r in x ? r in t && !(r in i) && (i[r] = x[r]) : r in n ? i[r] = n[r] : r in t && (i[r] = t[r]);
return i;
}
function L(t, n) {
const i = t.icons, r = t.aliases || /* @__PURE__ */ Object.create(null), e = /* @__PURE__ */ Object.create(null);
function o(s) {
if (i[s]) return e[s] = [];
if (!(s in e)) {
e[s] = null;
const l = r[s] && r[s].parent, f = l && o(l);
f && (e[s] = [l].concat(f));
}
return e[s];
}
return (n || Object.keys(i).concat(Object.keys(r))).forEach(o), e;
}
function O(t, n, i) {
const r = t.icons, e = t.aliases || /* @__PURE__ */ Object.create(null);
let o = {};
function s(l) {
o = D(r[l] || e[l], o);
}
return s(n), i.forEach(s), D(t, o);
}
function B(t, n) {
if (t.icons[n]) return O(t, n, []);
const i = L(t, [n])[n];
return i ? O(t, n, i) : null;
}
var W = /(-?[0-9.]*[0-9]+[0-9.]*)/g, _ = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
function E(t, n, i) {
if (n === 1) return t;
if (i = i || 100, typeof t == "number") return Math.ceil(t * n * i) / i;
if (typeof t != "string") return t;
const r = t.split(W);
if (r === null || !r.length) return t;
const e = [];
let o = r.shift(), s = _.test(o);
for (; ; ) {
if (s) {
const l = parseFloat(o);
isNaN(l) ? e.push(o) : e.push(Math.ceil(l * n * i) / i);
} else e.push(o);
if (o = r.shift(), o === void 0) return e.join("");
s = !s;
}
}
function K(t, n = "defs") {
let i = "";
const r = t.indexOf("<" + n);
for (; r >= 0; ) {
const e = t.indexOf(">", r), o = t.indexOf("</" + n);
if (e === -1 || o === -1) break;
const s = t.indexOf(">", o);
if (s === -1) break;
i += t.slice(e + 1, o).trim(), t = t.slice(0, r).trim() + t.slice(s + 1);
}
return {
defs: i,
content: t
};
}
function U(t, n) {
return t ? "<defs>" + t + "</defs>" + n : n;
}
function q(t, n, i) {
const r = K(t);
return U(r.defs, n + r.content + i);
}
var J = (t) => t === "unset" || t === "undefined" || t === "none";
function N(t, n) {
const i = {
...$,
...t
}, r = {
...V,
...n
}, e = {
left: i.left,
top: i.top,
width: i.width,
height: i.height
};
let o = i.body;
[i, r].forEach((g) => {
const a = [], T = g.hFlip, k = g.vFlip;
let h = g.rotate;
T ? k ? h += 2 : (a.push("translate(" + (e.width + e.left).toString() + " " + (0 - e.top).toString() + ")"), a.push("scale(-1 1)"), e.top = e.left = 0) : k && (a.push("translate(" + (0 - e.left).toString() + " " + (e.height + e.top).toString() + ")"), a.push("scale(1 -1)"), e.top = e.left = 0);
let c;
switch (h < 0 && (h -= Math.floor(h / 4) * 4), h = h % 4, h) {
case 1:
c = e.height / 2 + e.top, a.unshift("rotate(90 " + c.toString() + " " + c.toString() + ")");
break;
case 2:
a.unshift("rotate(180 " + (e.width / 2 + e.left).toString() + " " + (e.height / 2 + e.top).toString() + ")");
break;
case 3:
c = e.width / 2 + e.left, a.unshift("rotate(-90 " + c.toString() + " " + c.toString() + ")");
break;
}
h % 2 === 1 && (e.left !== e.top && (c = e.left, e.left = e.top, e.top = c), e.width !== e.height && (c = e.width, e.width = e.height, e.height = c)), a.length && (o = q(o, '<g transform="' + a.join(" ") + '">', "</g>"));
});
const s = r.width, l = r.height, f = e.width, u = e.height;
let p, d;
s === null ? (d = l === null ? "1em" : l === "auto" ? u : l, p = E(d, f / u)) : (p = s === "auto" ? f : s, d = l === null ? E(p, u / f) : l === "auto" ? u : l);
const I = {}, b = (g, a) => {
J(a) || (I[g] = a.toString());
};
b("width", p), b("height", d);
const y = [
e.left,
e.top,
f,
u
];
return I.viewBox = y.join(" "), {
attributes: I,
viewBox: y,
body: o
};
}
var Q = /\sid="(\S+)"/g, F = /* @__PURE__ */ new Map();
function X(t) {
t = t.replace(/[0-9]+$/, "") || "a";
const n = F.get(t) || 0;
return F.set(t, n + 1), n ? `${t}${n}` : t;
}
function Y(t) {
const n = [];
let i;
for (; i = Q.exec(t); ) n.push(i[1]);
if (!n.length) return t;
const r = "suffix" + (Math.random() * 16777216 | Date.now()).toString(16);
return n.forEach((e) => {
const o = X(e), s = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
t = t.replace(new RegExp('([#;"])(' + s + ')([")]|\\.[a-z])', "g"), "$1" + o + r + "$3");
}), t = t.replace(new RegExp(r, "g"), ""), t;
}
function Z(t, n) {
let i = t.indexOf("xlink:") === -1 ? "" : ' xmlns:xlink="http://www.w3.org/1999/xlink"';
for (const r in n) i += " " + r + '="' + n[r] + '"';
return '<svg xmlns="http://www.w3.org/2000/svg"' + i + ">" + t + "</svg>";
}
var tt = {
body: '<g><rect width="80" height="80" style="fill: #087ebf; stroke-width: 0px;"/><text transform="translate(21.16 64.67)" style="fill: #fff; font-family: ArialMT, Arial; font-size: 67.75px;"><tspan x="0" y="0">?</tspan></text></g>',
height: 80,
width: 80
}, S = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), it = /* @__PURE__ */ v((t) => {
for (const n of t) {
if (!n.name) throw new Error('Invalid icon loader. Must have a "name" property with non-empty string value.');
if (w.debug("Registering icon pack:", n.name), "loader" in n) M.set(n.name, n.loader);
else if ("icons" in n) S.set(n.name, n.icons);
else
throw w.error("Invalid icon loader:", n), new Error('Invalid icon loader. Must have either "icons" or "loader" property.');
}
}, "registerIconPacks"), j = /* @__PURE__ */ v(async (t, n) => {
const i = R(t, !0, n !== void 0);
if (!i) throw new Error(`Invalid icon name: ${t}`);
const r = i.prefix || n;
if (!r) throw new Error(`Icon name must contain a prefix: ${t}`);
let e = S.get(r);
if (!e) {
const s = M.get(r);
if (!s) throw new Error(`Icon set not found: ${i.prefix}`);
try {
e = {
...await s(),
prefix: r
}, S.set(r, e);
} catch (l) {
throw w.error(l), new Error(`Failed to load icon set: ${i.prefix}`);
}
}
const o = B(e, i.name);
if (!o) throw new Error(`Icon not found: ${t}`);
return o;
}, "getRegisteredIconData"), ot = /* @__PURE__ */ v(async (t) => {
try {
return await j(t), !0;
} catch {
return !1;
}
}, "isIconAvailable"), st = /* @__PURE__ */ v(async (t, n, i) => {
let r;
try {
r = await j(t, n?.fallbackPrefix);
} catch (o) {
w.error(o), r = tt;
}
const e = N(r, n);
return P(Z(Y(e.body), {
...e.attributes,
...i
}), A());
}, "getIconSVG");
export {
tt as i,
ot as n,
it as r,
st as t
};