UNPKG

rivet-icons

Version:

Icons for Indiana University's Rivet Design System

99 lines (98 loc) 3.19 kB
var m = (n, e, t) => { if (!e.has(n)) throw TypeError("Cannot " + t); }; var r = (n, e, t) => (m(n, e, "read from private field"), t ? t.call(n) : e.get(n)), o = (n, e, t) => { if (e.has(n)) throw TypeError("Cannot add the same private member more than once"); e instanceof WeakSet ? e.add(n) : e.set(n, t); }, C = (n, e, t, s) => (m(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t); var w = (n, e, t) => (m(n, e, "access private method"), t); const g = "Rivet Icons", c = "rvt-icon", f = "name", p = "rvtIconRegistered", $ = "transitionrun"; const A = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), v = document.createElement("style"); v.setAttribute(`data-${c}`, ""); document.head.appendChild(v); function I(n, e) { var t, s; (s = (t = window.customElements.get(c)).register) == null || s.call(t, n, e); } var a, i, l, N, h, x; class L extends window.HTMLElement { constructor() { super(...arguments); o(this, l); o(this, h); o(this, a, void 0); o(this, i, S(w(this, h, x).bind(this))); } static get observedAttributes() { return [f]; } static register(t, s) { if (!t || typeof t != "string") throw new Error(`${g}: Name must be a string.`); const u = document.createElement("template"); if (u.innerHTML = s, u.content.children.length !== 1) throw new Error(`${g} (${t}): Content must contain one SVG element.`); const E = u.content.firstChild; if (E.nodeName.toLowerCase() !== "svg") throw new Error(`${g} (${t}): Content must be a SVG element.`); M(E, { "aria-hidden": "true", fill: "currentColor", focusable: "false", height: 16, viewBox: "0 0 16 16", width: 16, xmlns: "http://www.w3.org/2000/svg" }), d.set(t, u); const b = d.size; A.set(b, t), v.sheet.insertRule(`${c} { --${t}: ${b}; }`); const y = new CustomEvent(p, { detail: { name: t } }); document.dispatchEvent(y); } attributeChangedCallback() { r(this, i).call(this); } connectedCallback() { document.addEventListener(p, r(this, i)), this.addEventListener($, r(this, i)), r(this, i).call(this); } disconnectedCallback() { document.removeEventListener(p, r(this, i)), this.removeEventListener($, r(this, i)); } } a = new WeakMap(), i = new WeakMap(), l = new WeakSet(), N = function() { const t = this.querySelector("svg"); if (!t) return; const s = window.getComputedStyle(t).getPropertyValue(`--${f}`); return A.get(parseInt(s)); }, h = new WeakSet(), x = function() { const t = w(this, l, N).call(this) || this.getAttribute(f); if (!d.has(t) || r(this, a) === t) return; const s = d.get(t).content.cloneNode(!0); this.replaceChildren(s), C(this, a, t); }; window.customElements.get(c) || window.customElements.define(c, L); function z(n, e, t) { n.hasAttribute(e) || n.setAttribute(e, t); } function M(n, e) { Object.entries(e).forEach(([t, s]) => { z(n, t, s); }); } function S(n) { let e = !1; return function(...t) { e || (e = !0, window.requestAnimationFrame(() => { n.call(this, ...t), e = !1; })); }; } export { I as registerIcon };