class TabletopObject extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); } connectedCallback() { const type = this.getAttribute('type'); const title = this.getAttribute('title'); const color = this.getAttribute('color') || 'blue'; const image = this.getAttribute('image'); this.shadowRoot.innerHTML = `
${this.renderObject(type, title, color, image)}
`; this.setupInteractions(); } getColorShades(color) { const colorMap = { blue: ['#3b82f6', '#1d4ed8'], purple: ['#8b5cf6', '#6d28d9'], green: ['#10b981', '#047857'], red: ['#ef4444', '#dc2626'], orange: ['#f97316', '#ea580c'], pink: ['#ec4899', '#db2777'], yellow: ['#f59e0b', '#d97706'] }; return colorMap[color] || colorMap.blue; } renderObject(type, title, color, image) { switch(type) { case 'magazine': return `
${title}
`; case 'resource': return `
${title}
`; case 'art': return `
${title}
${title}
`; case 'demo': return `
${title}
${title}
`; default: return '
Unknown object type
'; } } setupInteractions() { this.addEventListener('click', (e) => { this.dispatchEvent(new CustomEvent('object-click', { detail: { id: this.getAttribute('object-id'), type: this.getAttribute('type'), title: this.getAttribute('title') }, bubbles: true })); }); // Adding hover preview this.addEventListener('mouseenter', () => { this.dispatchEvent(new CustomEvent('object-hover', { detail: { id: this.getAttribute('object-id'), type: this.getAttribute('type'), title: this.getAttribute('title') }, bubbles: true })); }); this.addEventListener('mouseleave', () => { this.dispatchEvent(new CustomEvent('object-unhover', { detail: { id: this.getAttribute('object-id') }, bubbles: true })); }); } } customElements.define('tabletop-object', TabletopObject);