@nysds/nys-avatar
Version:
The Avatar component from the NYS Design System.
744 lines (734 loc) • 26.6 kB
JavaScript
import { css as ht, LitElement as lt, html as w } from "lit";
/*!
* ▒█▄░▒█ ▒█░░▒█ ▒█▀▀▀█ ▒█▀▀▄ ▒█▀▀▀█
* ▒█▒█▒█ ▒█▄▄▄█ ░▀▀▀▄▄ ▒█░▒█ ░▀▀▀▄▄
* ▒█░░▀█ ░░▒█░░ ▒█▄▄▄█ ▒█▄▄▀ ▒█▄▄▄█
*
* Avatar Component
* Part of the New York State Design System
* A design system for New York State's digital products.
* Repository: https://github.com/its-hcd/nysds
* License: MIT
*/
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const M = globalThis, B = M.ShadowRoot && (M.ShadyCSS === void 0 || M.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, it = Symbol(), J = /* @__PURE__ */ new WeakMap();
let ct = class {
constructor(t, e, s) {
if (this._$cssResult$ = !0, s !== it) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
this.cssText = t, this.t = e;
}
get styleSheet() {
let t = this.o;
const e = this.t;
if (B && t === void 0) {
const s = e !== void 0 && e.length === 1;
s && (t = J.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), s && J.set(e, t));
}
return t;
}
toString() {
return this.cssText;
}
};
const pt = (r) => new ct(typeof r == "string" ? r : r + "", void 0, it), dt = (r, t) => {
if (B) r.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet);
else for (const e of t) {
const s = document.createElement("style"), i = M.litNonce;
i !== void 0 && s.setAttribute("nonce", i), s.textContent = e.cssText, r.appendChild(s);
}
}, K = B ? (r) => r : (r) => r instanceof CSSStyleSheet ? ((t) => {
let e = "";
for (const s of t.cssRules) e += s.cssText;
return pt(e);
})(r) : r;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const { is: ut, defineProperty: _t, getOwnPropertyDescriptor: $t, getOwnPropertyNames: yt, getOwnPropertySymbols: ft, getPrototypeOf: vt } = Object, g = globalThis, Z = g.trustedTypes, gt = Z ? Z.emptyScript : "", D = g.reactiveElementPolyfillSupport, C = (r, t) => r, z = { toAttribute(r, t) {
switch (t) {
case Boolean:
r = r ? gt : null;
break;
case Object:
case Array:
r = r == null ? r : JSON.stringify(r);
}
return r;
}, fromAttribute(r, t) {
let e = r;
switch (t) {
case Boolean:
e = r !== null;
break;
case Number:
e = r === null ? null : Number(r);
break;
case Object:
case Array:
try {
e = JSON.parse(r);
} catch {
e = null;
}
}
return e;
} }, V = (r, t) => !ut(r, t), F = { attribute: !0, type: String, converter: z, reflect: !1, hasChanged: V };
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), g.litPropertyMetadata ?? (g.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
class x extends HTMLElement {
static addInitializer(t) {
this._$Ei(), (this.l ?? (this.l = [])).push(t);
}
static get observedAttributes() {
return this.finalize(), this._$Eh && [...this._$Eh.keys()];
}
static createProperty(t, e = F) {
if (e.state && (e.attribute = !1), this._$Ei(), this.elementProperties.set(t, e), !e.noAccessor) {
const s = Symbol(), i = this.getPropertyDescriptor(t, s, e);
i !== void 0 && _t(this.prototype, t, i);
}
}
static getPropertyDescriptor(t, e, s) {
const { get: i, set: o } = $t(this.prototype, t) ?? { get() {
return this[e];
}, set(n) {
this[e] = n;
} };
return { get() {
return i == null ? void 0 : i.call(this);
}, set(n) {
const h = i == null ? void 0 : i.call(this);
o.call(this, n), this.requestUpdate(t, h, s);
}, configurable: !0, enumerable: !0 };
}
static getPropertyOptions(t) {
return this.elementProperties.get(t) ?? F;
}
static _$Ei() {
if (this.hasOwnProperty(C("elementProperties"))) return;
const t = vt(this);
t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
}
static finalize() {
if (this.hasOwnProperty(C("finalized"))) return;
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(C("properties"))) {
const e = this.properties, s = [...yt(e), ...ft(e)];
for (const i of s) this.createProperty(i, e[i]);
}
const t = this[Symbol.metadata];
if (t !== null) {
const e = litPropertyMetadata.get(t);
if (e !== void 0) for (const [s, i] of e) this.elementProperties.set(s, i);
}
this._$Eh = /* @__PURE__ */ new Map();
for (const [e, s] of this.elementProperties) {
const i = this._$Eu(e, s);
i !== void 0 && this._$Eh.set(i, e);
}
this.elementStyles = this.finalizeStyles(this.styles);
}
static finalizeStyles(t) {
const e = [];
if (Array.isArray(t)) {
const s = new Set(t.flat(1 / 0).reverse());
for (const i of s) e.unshift(K(i));
} else t !== void 0 && e.push(K(t));
return e;
}
static _$Eu(t, e) {
const s = e.attribute;
return s === !1 ? void 0 : typeof s == "string" ? s : typeof t == "string" ? t.toLowerCase() : void 0;
}
constructor() {
super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
}
_$Ev() {
var t;
this._$ES = new Promise((e) => this.enableUpdating = e), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), (t = this.constructor.l) == null || t.forEach((e) => e(this));
}
addController(t) {
var e;
(this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(t), this.renderRoot !== void 0 && this.isConnected && ((e = t.hostConnected) == null || e.call(t));
}
removeController(t) {
var e;
(e = this._$EO) == null || e.delete(t);
}
_$E_() {
const t = /* @__PURE__ */ new Map(), e = this.constructor.elementProperties;
for (const s of e.keys()) this.hasOwnProperty(s) && (t.set(s, this[s]), delete this[s]);
t.size > 0 && (this._$Ep = t);
}
createRenderRoot() {
const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
return dt(t, this.constructor.elementStyles), t;
}
connectedCallback() {
var t;
this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (t = this._$EO) == null || t.forEach((e) => {
var s;
return (s = e.hostConnected) == null ? void 0 : s.call(e);
});
}
enableUpdating(t) {
}
disconnectedCallback() {
var t;
(t = this._$EO) == null || t.forEach((e) => {
var s;
return (s = e.hostDisconnected) == null ? void 0 : s.call(e);
});
}
attributeChangedCallback(t, e, s) {
this._$AK(t, s);
}
_$EC(t, e) {
var o;
const s = this.constructor.elementProperties.get(t), i = this.constructor._$Eu(t, s);
if (i !== void 0 && s.reflect === !0) {
const n = (((o = s.converter) == null ? void 0 : o.toAttribute) !== void 0 ? s.converter : z).toAttribute(e, s.type);
this._$Em = t, n == null ? this.removeAttribute(i) : this.setAttribute(i, n), this._$Em = null;
}
}
_$AK(t, e) {
var o;
const s = this.constructor, i = s._$Eh.get(t);
if (i !== void 0 && this._$Em !== i) {
const n = s.getPropertyOptions(i), h = typeof n.converter == "function" ? { fromAttribute: n.converter } : ((o = n.converter) == null ? void 0 : o.fromAttribute) !== void 0 ? n.converter : z;
this._$Em = i, this[i] = h.fromAttribute(e, n.type), this._$Em = null;
}
}
requestUpdate(t, e, s) {
if (t !== void 0) {
if (s ?? (s = this.constructor.getPropertyOptions(t)), !(s.hasChanged ?? V)(this[t], e)) return;
this.P(t, e, s);
}
this.isUpdatePending === !1 && (this._$ES = this._$ET());
}
P(t, e, s) {
this._$AL.has(t) || this._$AL.set(t, e), s.reflect === !0 && this._$Em !== t && (this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Set())).add(t);
}
async _$ET() {
this.isUpdatePending = !0;
try {
await this._$ES;
} catch (e) {
Promise.reject(e);
}
const t = this.scheduleUpdate();
return t != null && await t, !this.isUpdatePending;
}
scheduleUpdate() {
return this.performUpdate();
}
performUpdate() {
var s;
if (!this.isUpdatePending) return;
if (!this.hasUpdated) {
if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
for (const [o, n] of this._$Ep) this[o] = n;
this._$Ep = void 0;
}
const i = this.constructor.elementProperties;
if (i.size > 0) for (const [o, n] of i) n.wrapped !== !0 || this._$AL.has(o) || this[o] === void 0 || this.P(o, this[o], n);
}
let t = !1;
const e = this._$AL;
try {
t = this.shouldUpdate(e), t ? (this.willUpdate(e), (s = this._$EO) == null || s.forEach((i) => {
var o;
return (o = i.hostUpdate) == null ? void 0 : o.call(i);
}), this.update(e)) : this._$EU();
} catch (i) {
throw t = !1, this._$EU(), i;
}
t && this._$AE(e);
}
willUpdate(t) {
}
_$AE(t) {
var e;
(e = this._$EO) == null || e.forEach((s) => {
var i;
return (i = s.hostUpdated) == null ? void 0 : i.call(s);
}), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
}
_$EU() {
this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
}
get updateComplete() {
return this.getUpdateComplete();
}
getUpdateComplete() {
return this._$ES;
}
shouldUpdate(t) {
return !0;
}
update(t) {
this._$Ej && (this._$Ej = this._$Ej.forEach((e) => this._$EC(e, this[e]))), this._$EU();
}
updated(t) {
}
firstUpdated(t) {
}
}
x.elementStyles = [], x.shadowRootOptions = { mode: "open" }, x[C("elementProperties")] = /* @__PURE__ */ new Map(), x[C("finalized")] = /* @__PURE__ */ new Map(), D == null || D({ ReactiveElement: x }), (g.reactiveElementVersions ?? (g.reactiveElementVersions = [])).push("2.0.4");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const mt = { attribute: !0, type: String, converter: z, reflect: !1, hasChanged: V }, At = (r = mt, t, e) => {
const { kind: s, metadata: i } = e;
let o = globalThis.litPropertyMetadata.get(i);
if (o === void 0 && globalThis.litPropertyMetadata.set(i, o = /* @__PURE__ */ new Map()), o.set(e.name, r), s === "accessor") {
const { name: n } = e;
return { set(h) {
const a = t.get.call(this);
t.set.call(this, h), this.requestUpdate(n, a, r);
}, init(h) {
return h !== void 0 && this.P(n, void 0, r), h;
} };
}
if (s === "setter") {
const { name: n } = e;
return function(h) {
const a = this[n];
t.call(this, h), this.requestUpdate(n, a, r);
};
}
throw Error("Unsupported decorator location: " + s);
};
function $(r) {
return (t, e) => typeof e == "object" ? At(r, t, e) : ((s, i, o) => {
const n = i.hasOwnProperty(o);
return i.constructor.createProperty(o, n ? { ...s, wrapped: !0 } : s), n ? Object.getOwnPropertyDescriptor(i, o) : void 0;
})(r, t, e);
}
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
function St(r) {
return $({ ...r, state: !0, attribute: !1 });
}
const bt = ht`
:host {
/* Global Avatar Styles */
--_nys-avatar-shape: var(--nys-radius-round, 1776px);
--_nys-avatar-border: var(--nys-font-size-6xl, 36px);
--_nys-avatar-size: var(--nys-font-size-6xl, 36px);
}
.nys-avatar {
display: inline-block;
}
.nys-avatar__component {
display: flex;
justify-content: center;
align-items: center;
border-radius: var(--_nys-avatar-shape);
width: var(--_nys-avatar-size);
height: var(--_nys-avatar-size);
font-size: var(--_nys-avatar-size);
overflow: hidden;
box-sizing: border-box;
color: white;
}
/* Shape */
:host([shape="square"]) {
--_nys-avatar-shape: var(--nys-radius-xs, var(--nys-space-1px, 1px));
}
:host([shape="rounded"]) {
--_nys-avatar-shape: var(--nys-radius-md, var(--nys-space-50, 4px));
}
:host([shape="circle"]) {
--_nys-avatar-shape: var(--nys-radius-round, 1776px);
}
div[part="nys-avatar__icon"] {
display: flex;
align-items: center;
justify-content: center;
}
/* Content styles */
.nys-avatar__initials {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
font-size: calc(var(--_nys-avatar-size) * 0.5);
font-weight: bold;
text-transform: uppercase;
}
.nys-avatar__image {
width: 100%;
height: 100%;
object-fit: cover;
}
.nys-avatar__icon {
width: 100%;
height: 100%;
fill: currentColor;
}
`;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const U = globalThis, R = U.trustedTypes, G = R ? R.createPolicy("lit-html", { createHTML: (r) => r }) : void 0, rt = "$lit$", v = `lit$${Math.random().toFixed(9).slice(2)}$`, nt = "?" + v, Et = `<${nt}>`, b = document, L = () => b.createComment(""), H = (r) => r === null || typeof r != "object" && typeof r != "function", W = Array.isArray, wt = (r) => W(r) || typeof (r == null ? void 0 : r[Symbol.iterator]) == "function", I = `[
\f\r]`, P = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, X = /-->/g, Q = />/g, A = RegExp(`>|${I}(?:([^\\s"'>=/]+)(${I}*=${I}*(?:[^
\f\r"'\`<>=]|("|')|))|$)`, "g"), Y = /'/g, tt = /"/g, ot = /^(?:script|style|textarea|title)$/i, N = Symbol.for("lit-noChange"), c = Symbol.for("lit-nothing"), et = /* @__PURE__ */ new WeakMap(), S = b.createTreeWalker(b, 129);
function at(r, t) {
if (!W(r) || !r.hasOwnProperty("raw")) throw Error("invalid template strings array");
return G !== void 0 ? G.createHTML(t) : t;
}
const xt = (r, t) => {
const e = r.length - 1, s = [];
let i, o = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", n = P;
for (let h = 0; h < e; h++) {
const a = r[h];
let p, d, l = -1, _ = 0;
for (; _ < a.length && (n.lastIndex = _, d = n.exec(a), d !== null); ) _ = n.lastIndex, n === P ? d[1] === "!--" ? n = X : d[1] !== void 0 ? n = Q : d[2] !== void 0 ? (ot.test(d[2]) && (i = RegExp("</" + d[2], "g")), n = A) : d[3] !== void 0 && (n = A) : n === A ? d[0] === ">" ? (n = i ?? P, l = -1) : d[1] === void 0 ? l = -2 : (l = n.lastIndex - d[2].length, p = d[1], n = d[3] === void 0 ? A : d[3] === '"' ? tt : Y) : n === tt || n === Y ? n = A : n === X || n === Q ? n = P : (n = A, i = void 0);
const f = n === A && r[h + 1].startsWith("/>") ? " " : "";
o += n === P ? a + Et : l >= 0 ? (s.push(p), a.slice(0, l) + rt + a.slice(l) + v + f) : a + v + (l === -2 ? h : f);
}
return [at(r, o + (r[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), s];
};
class O {
constructor({ strings: t, _$litType$: e }, s) {
let i;
this.parts = [];
let o = 0, n = 0;
const h = t.length - 1, a = this.parts, [p, d] = xt(t, e);
if (this.el = O.createElement(p, s), S.currentNode = this.el.content, e === 2 || e === 3) {
const l = this.el.content.firstChild;
l.replaceWith(...l.childNodes);
}
for (; (i = S.nextNode()) !== null && a.length < h; ) {
if (i.nodeType === 1) {
if (i.hasAttributes()) for (const l of i.getAttributeNames()) if (l.endsWith(rt)) {
const _ = d[n++], f = i.getAttribute(l).split(v), T = /([.?@])?(.*)/.exec(_);
a.push({ type: 1, index: o, name: T[2], strings: f, ctor: T[1] === "." ? Ct : T[1] === "?" ? Ut : T[1] === "@" ? Ht : k }), i.removeAttribute(l);
} else l.startsWith(v) && (a.push({ type: 6, index: o }), i.removeAttribute(l));
if (ot.test(i.tagName)) {
const l = i.textContent.split(v), _ = l.length - 1;
if (_ > 0) {
i.textContent = R ? R.emptyScript : "";
for (let f = 0; f < _; f++) i.append(l[f], L()), S.nextNode(), a.push({ type: 2, index: ++o });
i.append(l[_], L());
}
}
} else if (i.nodeType === 8) if (i.data === nt) a.push({ type: 2, index: o });
else {
let l = -1;
for (; (l = i.data.indexOf(v, l + 1)) !== -1; ) a.push({ type: 7, index: o }), l += v.length - 1;
}
o++;
}
}
static createElement(t, e) {
const s = b.createElement("template");
return s.innerHTML = t, s;
}
}
function E(r, t, e = r, s) {
var n, h;
if (t === N) return t;
let i = s !== void 0 ? (n = e._$Co) == null ? void 0 : n[s] : e._$Cl;
const o = H(t) ? void 0 : t._$litDirective$;
return (i == null ? void 0 : i.constructor) !== o && ((h = i == null ? void 0 : i._$AO) == null || h.call(i, !1), o === void 0 ? i = void 0 : (i = new o(r), i._$AT(r, e, s)), s !== void 0 ? (e._$Co ?? (e._$Co = []))[s] = i : e._$Cl = i), i !== void 0 && (t = E(r, i._$AS(r, t.values), i, s)), t;
}
class Pt {
constructor(t, e) {
this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = e;
}
get parentNode() {
return this._$AM.parentNode;
}
get _$AU() {
return this._$AM._$AU;
}
u(t) {
const { el: { content: e }, parts: s } = this._$AD, i = ((t == null ? void 0 : t.creationScope) ?? b).importNode(e, !0);
S.currentNode = i;
let o = S.nextNode(), n = 0, h = 0, a = s[0];
for (; a !== void 0; ) {
if (n === a.index) {
let p;
a.type === 2 ? p = new j(o, o.nextSibling, this, t) : a.type === 1 ? p = new a.ctor(o, a.name, a.strings, this, t) : a.type === 6 && (p = new Nt(o, this, t)), this._$AV.push(p), a = s[++h];
}
n !== (a == null ? void 0 : a.index) && (o = S.nextNode(), n++);
}
return S.currentNode = b, i;
}
p(t) {
let e = 0;
for (const s of this._$AV) s !== void 0 && (s.strings !== void 0 ? (s._$AI(t, s, e), e += s.strings.length - 2) : s._$AI(t[e])), e++;
}
}
class j {
get _$AU() {
var t;
return ((t = this._$AM) == null ? void 0 : t._$AU) ?? this._$Cv;
}
constructor(t, e, s, i) {
this.type = 2, this._$AH = c, this._$AN = void 0, this._$AA = t, this._$AB = e, this._$AM = s, this.options = i, this._$Cv = (i == null ? void 0 : i.isConnected) ?? !0;
}
get parentNode() {
let t = this._$AA.parentNode;
const e = this._$AM;
return e !== void 0 && (t == null ? void 0 : t.nodeType) === 11 && (t = e.parentNode), t;
}
get startNode() {
return this._$AA;
}
get endNode() {
return this._$AB;
}
_$AI(t, e = this) {
t = E(this, t, e), H(t) ? t === c || t == null || t === "" ? (this._$AH !== c && this._$AR(), this._$AH = c) : t !== this._$AH && t !== N && this._(t) : t._$litType$ !== void 0 ? this.$(t) : t.nodeType !== void 0 ? this.T(t) : wt(t) ? this.k(t) : this._(t);
}
O(t) {
return this._$AA.parentNode.insertBefore(t, this._$AB);
}
T(t) {
this._$AH !== t && (this._$AR(), this._$AH = this.O(t));
}
_(t) {
this._$AH !== c && H(this._$AH) ? this._$AA.nextSibling.data = t : this.T(b.createTextNode(t)), this._$AH = t;
}
$(t) {
var o;
const { values: e, _$litType$: s } = t, i = typeof s == "number" ? this._$AC(t) : (s.el === void 0 && (s.el = O.createElement(at(s.h, s.h[0]), this.options)), s);
if (((o = this._$AH) == null ? void 0 : o._$AD) === i) this._$AH.p(e);
else {
const n = new Pt(i, this), h = n.u(this.options);
n.p(e), this.T(h), this._$AH = n;
}
}
_$AC(t) {
let e = et.get(t.strings);
return e === void 0 && et.set(t.strings, e = new O(t)), e;
}
k(t) {
W(this._$AH) || (this._$AH = [], this._$AR());
const e = this._$AH;
let s, i = 0;
for (const o of t) i === e.length ? e.push(s = new j(this.O(L()), this.O(L()), this, this.options)) : s = e[i], s._$AI(o), i++;
i < e.length && (this._$AR(s && s._$AB.nextSibling, i), e.length = i);
}
_$AR(t = this._$AA.nextSibling, e) {
var s;
for ((s = this._$AP) == null ? void 0 : s.call(this, !1, !0, e); t && t !== this._$AB; ) {
const i = t.nextSibling;
t.remove(), t = i;
}
}
setConnected(t) {
var e;
this._$AM === void 0 && (this._$Cv = t, (e = this._$AP) == null || e.call(this, t));
}
}
class k {
get tagName() {
return this.element.tagName;
}
get _$AU() {
return this._$AM._$AU;
}
constructor(t, e, s, i, o) {
this.type = 1, this._$AH = c, this._$AN = void 0, this.element = t, this.name = e, this._$AM = i, this.options = o, s.length > 2 || s[0] !== "" || s[1] !== "" ? (this._$AH = Array(s.length - 1).fill(new String()), this.strings = s) : this._$AH = c;
}
_$AI(t, e = this, s, i) {
const o = this.strings;
let n = !1;
if (o === void 0) t = E(this, t, e, 0), n = !H(t) || t !== this._$AH && t !== N, n && (this._$AH = t);
else {
const h = t;
let a, p;
for (t = o[0], a = 0; a < o.length - 1; a++) p = E(this, h[s + a], e, a), p === N && (p = this._$AH[a]), n || (n = !H(p) || p !== this._$AH[a]), p === c ? t = c : t !== c && (t += (p ?? "") + o[a + 1]), this._$AH[a] = p;
}
n && !i && this.j(t);
}
j(t) {
t === c ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
}
}
class Ct extends k {
constructor() {
super(...arguments), this.type = 3;
}
j(t) {
this.element[this.name] = t === c ? void 0 : t;
}
}
class Ut extends k {
constructor() {
super(...arguments), this.type = 4;
}
j(t) {
this.element.toggleAttribute(this.name, !!t && t !== c);
}
}
class Ht extends k {
constructor(t, e, s, i, o) {
super(t, e, s, i, o), this.type = 5;
}
_$AI(t, e = this) {
if ((t = E(this, t, e, 0) ?? c) === N) return;
const s = this._$AH, i = t === c && s !== c || t.capture !== s.capture || t.once !== s.once || t.passive !== s.passive, o = t !== c && (s === c || i);
i && this.element.removeEventListener(this.name, this, s), o && this.element.addEventListener(this.name, this, t), this._$AH = t;
}
handleEvent(t) {
var e;
typeof this._$AH == "function" ? this._$AH.call(((e = this.options) == null ? void 0 : e.host) ?? this.element, t) : this._$AH.handleEvent(t);
}
}
class Nt {
constructor(t, e, s) {
this.element = t, this.type = 6, this._$AN = void 0, this._$AM = e, this.options = s;
}
get _$AU() {
return this._$AM._$AU;
}
_$AI(t) {
E(this, t);
}
}
const q = U.litHtmlPolyfillSupport;
q == null || q(O, j), (U.litHtmlVersions ?? (U.litHtmlVersions = [])).push("3.2.1");
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const st = (r) => r ?? c;
var Ot = Object.defineProperty, Tt = Object.getOwnPropertyDescriptor, y = (r, t, e, s) => {
for (var i = s > 1 ? void 0 : s ? Tt(t, e) : t, o = r.length - 1, n; o >= 0; o--)
(n = r[o]) && (i = (s ? n(t, e, i) : n(i)) || i);
return s && i && Ot(t, e, i), i;
};
let Mt = 0;
var m;
const u = (m = class extends lt {
constructor() {
super(...arguments), this.id = "", this.ariaLabel = "", this.image = "", this.initials = "", this.icon = "", this.color = "#555", this.lazy = !1, this._shape = "circle", this._slotHasContent = !0;
}
get shape() {
return this._shape;
}
// Setter for the `shape` property.
set shape(t) {
this._shape = m.VALID_SHAPES.includes(
t
) ? t : "circle", this.requestUpdate("shape");
}
/******************** Functions ********************/
// Generate a unique ID if one is not provided
connectedCallback() {
super.connectedCallback(), this.id || (this.id = `nys-avatar-${Date.now()}-${Mt++}`);
}
firstUpdated() {
this._checkSlotContent();
}
async _checkSlotContent() {
var s;
const t = (s = this.shadowRoot) == null ? void 0 : s.querySelector("slot");
if (!t) {
this._slotHasContent = !1;
return;
}
await Promise.resolve();
const e = t.assignedNodes({ flatten: !0 }).filter(
(i) => {
var o;
return i.nodeType === Node.ELEMENT_NODE || i.nodeType === Node.TEXT_NODE && ((o = i.textContent) == null ? void 0 : o.trim());
}
);
this._slotHasContent = e.length > 0;
}
render() {
var t, e, s, i;
return w`
<label class="nys-avatar" id=${this.id}>
<div class="nys-avatar__content">
<div
part="nys-avatar"
class="nys-avatar__component"
style="background-color: ${((t = this.color) == null ? void 0 : t.length) > 0 ? this.color : "#555"};"
role=${st(this.image ? void 0 : "img")}
aria-label=${st(
this.image ? void 0 : this.ariaLabel ? this.ariaLabel : "avatar"
)}
>
${((e = this.image) == null ? void 0 : e.length) > 0 ? w`<img
part="nys-avatar__image"
class="nys-avatar__image"
src=${this.image}
alt=${this.ariaLabel || "avatar"}
loading=${this.lazy ? "lazy" : "eager"}
/>` : ((s = this.initials) == null ? void 0 : s.length) > 0 ? w`<span
part="nys-avatar__initials"
class="nys-avatar__initials"
aria-hidden="true"
>${this.initials}</span
>` : this._slotHasContent ? w`<div part="nys-avatar__icon">
<slot></slot>
</div>` : w`<div part="nys-avatar__icon">
<nys-icon
label="nys-avatar__icon"
name=${((i = this.icon) == null ? void 0 : i.length) > 0 ? this.icon : "account_circle"}
size="xl"
></nys-icon>
</div>`}
</div>
</div>
</label>
`;
}
}, m.styles = bt, m.VALID_SHAPES = [
"square",
"rounded",
"circle"
], m);
y([
$({ type: String })
], u.prototype, "id", 2);
y([
$({ type: String })
], u.prototype, "ariaLabel", 2);
y([
$({ type: String })
], u.prototype, "image", 2);
y([
$({ type: String })
], u.prototype, "initials", 2);
y([
$({ type: String })
], u.prototype, "icon", 2);
y([
$({ type: String })
], u.prototype, "color", 2);
y([
$({ type: Boolean, reflect: !0 })
], u.prototype, "lazy", 2);
y([
$({ reflect: !0 })
], u.prototype, "shape", 1);
y([
St()
], u.prototype, "_slotHasContent", 2);
let zt = u;
customElements.get("nys-avatar") || customElements.define("nys-avatar", zt);
export {
zt as NysAvatar
};
//# sourceMappingURL=nys-avatar.js.map