UNPKG

rivet-stickers

Version:

Stickers for Indiana University's Rivet Design System

92 lines (91 loc) 2.75 kB
var u = (n, e, t) => { if (!e.has(n)) throw TypeError("Cannot " + t); }; var r = (n, e, t) => (u(n, e, "read from private field"), t ? t.call(n) : e.get(n)), a = (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); }, g = (n, e, t, i) => (u(n, e, "write to private field"), i ? i.call(n, t) : e.set(n, t), t); var b = (n, e, t) => (u(n, e, "access private method"), t); /*! * Copyright (C) 2024 The Trustees of Indiana University * SPDX-License-Identifier: BSD-3-Clause */ const d = "Rivet Stickers", w = "rvt-sticker", v = "name", m = "rvtStickerRegistered"; const h = /* @__PURE__ */ new Map(); function S(n, e) { var t, i; (i = (t = window.customElements.get(w)).register) == null || i.call(t, n, e); } var o, s, l, E; class C extends window.HTMLElement { constructor() { super(...arguments); a(this, l); a(this, o, void 0); a(this, s, N(b(this, l, E).bind(this))); } static get observedAttributes() { return [v]; } static register(t, i) { if (!t || typeof t != "string") throw new Error(`${d}: Name must be a string.`); const c = document.createElement("template"); if (c.innerHTML = i, c.content.children.length !== 1) throw new Error(`${d} (${t}): Content must contain one SVG element.`); const f = c.content.firstChild; if (f.nodeName.toLowerCase() !== "svg") throw new Error(`${d} (${t}): Content must be a SVG element.`); A(f, { "aria-hidden": "true", fill: "currentColor", focusable: "false", height: "100%", viewBox: "0 0 80 80", width: "100%", xmlns: "http://www.w3.org/2000/svg" }), h.set(t, c); const p = new CustomEvent(m, { detail: { name: t } }); document.dispatchEvent(p); } attributeChangedCallback() { r(this, s).call(this); } connectedCallback() { document.addEventListener(m, r(this, s)), r(this, s).call(this); } disconnectedCallback() { document.removeEventListener(m, r(this, s)); } } o = new WeakMap(), s = new WeakMap(), l = new WeakSet(), E = function() { const t = this.getAttribute(v); if (!h.has(t) || r(this, o) === t) return; const i = h.get(t).content.cloneNode(!0); this.replaceChildren(i), g(this, o, t); }; window.customElements.get(w) || window.customElements.define(w, C); function k(n, e, t) { n.hasAttribute(e) || n.setAttribute(e, t); } function A(n, e) { Object.entries(e).forEach(([t, i]) => { k(n, t, i); }); } function N(n) { let e = !1; return function(...t) { e || (e = !0, window.requestAnimationFrame(() => { n.call(this, ...t), e = !1; })); }; } export { S as registerSticker };