) {
super.firstUpdated(changedProperties);
this.checkSlottedContent();
}
private updateCustomSize() {
// Handle custom size (numeric or CSS value)
if (this.size && !['small', 'medium', 'large'].includes(this.size)) {
const sizeValue = this.size.includes('px') || this.size.includes('rem') || this.size.includes('em') || this.size.includes('%')
? this.size
: `${this.size}px`;
this.style.width = sizeValue;
this.style.height = sizeValue;
// Adjust font size for custom sizes
const numericSize = parseInt(this.size);
if (!isNaN(numericSize)) {
this.style.fontSize = `${Math.max(numericSize * 0.4, 12)}px`;
}
} else {
this.style.removeProperty('width');
this.style.removeProperty('height');
this.style.removeProperty('font-size');
}
}
private checkSlottedContent() {
const slot = this.shadowRoot?.querySelector('slot');
if (slot) {
const assignedNodes = slot.assignedNodes();
this.hasSlottedContent = assignedNodes.length > 0;
}
}
private handleImageLoad() {
this.imageError = false;
}
private handleImageError() {
this.imageError = true;
}
private handleSlotChange(e: Event) {
this.checkSlottedContent();
}
private getInitials(text: string): string {
if (!text) return '';
const words = text.trim().split(/\s+/).filter(word => word.length > 0);
if (words.length === 0) return '';
if (words.length === 1) {
return words[0].charAt(0).toUpperCase();
}
return (words[0].charAt(0) + words[words.length - 1].charAt(0)).toUpperCase();
}
private renderContent() {
// Priority 1: Valid image source without error
if (this.src && !this.imageError) {
return html`
`;
}
// Priority 2: Slotted content (icons, custom elements)
if (this.hasSlottedContent) {
return html`
this.handleSlotChange(e)}">
`;
}
// Priority 3: Initials from alt text
const initials = this.getInitials(this.alt);
if (initials) {
return html`
${initials}
`;
}
// Priority 4: Default person icon
return html`
`;
}
render() {
return html`
${this.renderContent()}
this.handleSlotChange(e)}" style="display: none;">
`;
}
}