UNPKG

@aotearoan/neon

Version:

Neon is a lightweight design library of Vue 3 components with minimal dependencies.

74 lines (73 loc) 3.66 kB
var C = Object.defineProperty; var N = (g, e, t) => e in g ? C(g, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : g[e] = t; var b = (g, e, t) => (N(g, typeof e != "symbol" ? e + "" : e, t), t); import { NeonRandomUtils as d } from "./NeonRandomUtils.es.js"; const r = class r { /** * Returns base-64 encoded data URI * @param palette the color palettes to use when generating the Jazzicon * @param name used for random seed * @param size size in pixels to generate */ static genSvg(e, t, n) { return r.generateIdenticon(e, n, d.rand(t)).outerHTML; } static generateIdenticon(e, t, n) { const o = r.hueShift(e.slice(), n), l = document.createElementNS(r.svgns, "svg"); l.setAttribute("xmlns", r.svgns), l.setAttributeNS(null, "x", "0"), l.setAttributeNS(null, "y", "0"), l.setAttributeNS(null, "width", `${t}`), l.setAttributeNS(null, "height", `${t}`), r.genShape( [r.genColor(o, n)], t, 0, r.shapeCount - 1, l, () => 0 ); for (let c = 0; c < r.shapeCount - 1; c++) r.genShape(o, t, c, r.shapeCount - 1, l, n); return l; } static genShape(e, t, n, o, l, c) { const u = t / 2, s = document.createElementNS(r.svgns, "rect"); s.setAttributeNS(null, "x", "0"), s.setAttributeNS(null, "y", "0"), s.setAttributeNS(null, "width", `${t}`), s.setAttributeNS(null, "height", `${t}`); const a = c(), i = Math.PI * 2 * a, h = t / o * c() + n * t / o, S = Math.cos(i) * h, f = Math.sin(i) * h, x = `translate(${S} ${f})`, M = c(), m = "rotate(" + (a * 360 + M * 180).toFixed(1) + " " + u + " " + u + ")", A = x + " " + m; s.setAttributeNS(null, "transform", A); const v = r.genColor(e, c); s.setAttributeNS(null, "fill", v), l.appendChild(s); } static genColor(e, t) { const n = Math.floor(e.length * t()); return e.splice(n, 1)[0]; } static hueShift(e, t) { const n = t() * 30 - r.wobble / 2, o = (l) => r.colorRotate(l, n); return e.map(o); } static colorRotate(e, t) { const n = r.hexToHSL(e); let o = n.h; return o = (o + t) % 360, o = o < 0 ? 360 + o : o, n.h = o, r.hslToHex(n); } static hexToHSL(e) { let t = +("0x" + e[1] + e[2]), n = +("0x" + e[3] + e[4]), o = +("0x" + e[5] + e[6]); t /= 255, n /= 255, o /= 255; const l = Math.min(t, n, o), c = Math.max(t, n, o), u = c - l; let s = 0, a = 0, i = 0; return u === 0 ? s = 0 : c === t ? s = (n - o) / u % 6 : c === n ? s = (o - t) / u + 2 : s = (t - n) / u + 4, s = Math.round(s * 60), s < 0 && (s += 360), i = (c + l) / 2, a = u === 0 ? 0 : u / (1 - Math.abs(2 * i - 1)), a = +(a * 100).toFixed(1), i = +(i * 100).toFixed(1), { h: s, s: a, l: i }; } static hslToHex(e) { const t = e.h; let { s: n, l: o } = e; n /= 100, o /= 100; const l = (1 - Math.abs(2 * o - 1)) * n, c = l * (1 - Math.abs(t / 60 % 2 - 1)), u = o - l / 2; let s = 0, a = 0, i = 0; t >= 0 && t < 60 ? (s = l, a = c, i = 0) : t >= 60 && t < 120 ? (s = c, a = l, i = 0) : t >= 120 && t < 180 ? (s = 0, a = l, i = c) : t >= 180 && t < 240 ? (s = 0, a = c, i = l) : t >= 240 && t < 300 ? (s = c, a = 0, i = l) : t >= 300 && t < 360 && (s = l, a = 0, i = c); let h = Math.round((s + u) * 255).toString(16), S = Math.round((a + u) * 255).toString(16), f = Math.round((i + u) * 255).toString(16); return h.length === 1 && (h = "0" + s), S.length === 1 && (S = "0" + a), f.length === 1 && (f = "0" + i), "#" + h + S + f; } }; b(r, "shapeCount", 4), b(r, "svgns", "http://www.w3.org/2000/svg"), b(r, "wobble", 30); let p = r; export { p as NeonJazziconUtils }; //# sourceMappingURL=NeonJazziconUtils.es.js.map