-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathha-biofects-fullmenu.js
More file actions
265 lines (244 loc) · 8.63 KB
/
Copy pathha-biofects-fullmenu.js
File metadata and controls
265 lines (244 loc) · 8.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
class HABiofectsFullMenu extends HTMLElement {
constructor() {
super();
this.defaults = {
particleCount: 40,
backgroundColor: '#0a192f',
gridColor: 'rgba(0, 255, 255, 0.1)',
lineColor: 'rgba(0, 255, 255, 0.5)',
orbColor: 'rgba(0,255,255,1)',
particleColor: 'rgba(0, 255, 255, 0.5)',
glowColor: '#0ff',
textColor: '#fff',
itemBorderColor: 'rgba(0, 255, 255, 0.5)',
hoverGlowColor: 'rgba(0, 255, 255, 0.8)',
defaultItemColor: '#1a3a5a'
};
this.config = {};
}
set hass(hass) {
this._hass = hass;
}
setConfig(config) {
if (!config.items || !Array.isArray(config.items)) {
throw new Error("You need to define an array of items");
}
// Reset config to defaults before applying new configuration
this.config = { ...this.defaults };
// Only apply values from config that are explicitly set
Object.keys(config).forEach(key => {
if (config[key] !== undefined && config[key] !== null) {
this.config[key] = config[key];
}
});
this.render();
}
render() {
if (this.shadowRoot) {
this.shadowRoot.innerHTML = ''; // Clear existing content
}
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
const container = document.createElement('div');
container.classList.add('menu');
shadow.appendChild(container);
// Create the blueprint background
const background = document.createElement('div');
background.classList.add('background');
container.appendChild(background);
// Create the rotating dashed lines
const dashedLine1 = document.createElement('div');
dashedLine1.classList.add('dashed-line', 'dashed-line-1');
container.appendChild(dashedLine1);
const dashedLine2 = document.createElement('div');
dashedLine2.classList.add('dashed-line', 'dashed-line-2');
container.appendChild(dashedLine2);
// Create the glowing orb
const glowingOrb = document.createElement('div');
glowingOrb.classList.add('glowing-orb');
container.appendChild(glowingOrb);
// Create floating particles
for (let i = 0; i < this.config.particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
particle.style.width = `${Math.random() * 6 + 2}px`;
particle.style.height = particle.style.width;
particle.style.left = `${Math.random() * 100}%`;
particle.style.top = `${Math.random() * 100}%`;
particle.style.animationDuration = `${Math.random() * 10 + 10}s`;
container.appendChild(particle);
}
// Create a container for the menu items
const itemsContainer = document.createElement('div');
itemsContainer.classList.add('items-container');
container.appendChild(itemsContainer);
// Generate menu items based on configuration
const validItems = this.config.items.filter(item => item.label && item.url);
const itemCount = validItems.length;
validItems.forEach((item, index) => {
const angle = (360 / itemCount) * index;
const itemWrapper = document.createElement('div');
itemWrapper.classList.add('menu-item-wrapper');
itemWrapper.style.transform = `rotate(${angle}deg)`;
const itemElement = document.createElement('div');
itemElement.classList.add('menu-item');
itemElement.innerHTML = `
<div class="item-content" style="background-color: ${item.color || this.config.defaultItemColor};">
<span class="item-text">${item.label}</span>
</div>
`;
itemWrapper.appendChild(itemElement);
itemsContainer.appendChild(itemWrapper);
itemElement.addEventListener('click', (e) => {
e.preventDefault();
this.handleClick(item.url);
});
});
const style = document.createElement('style');
style.textContent = `
.menu {
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
background-color: ${this.config.backgroundColor};
}
.background {
position: absolute;
width: 100%;
height: 100%;
background-image:
radial-gradient(circle, ${this.config.gridColor} 2px, transparent 2px),
linear-gradient(${this.config.gridColor} 1px, transparent 1px),
linear-gradient(90deg, ${this.config.gridColor} 1px, transparent 1px);
background-size: 50px 50px, 20px 20px, 20px 20px;
opacity: 0.3;
animation: backgroundShift 30s linear infinite;
}
.dashed-line {
position: absolute;
border-radius: 50%;
border: 4px dashed ${this.config.lineColor};
}
.dashed-line-1 {
width: 80vmin;
height: 80vmin;
animation: rotate 30s linear infinite;
}
.dashed-line-2 {
width: 90vmin;
height: 90vmin;
border: 2px dashed ${this.config.lineColor};
animation: rotate 40s linear infinite reverse;
}
.glowing-orb {
position: absolute;
width: 20vmin;
height: 20vmin;
background: radial-gradient(circle, ${this.config.orbColor} 0%, ${this.config.orbColor.replace('1)', '0)')} 70%);
border-radius: 50%;
animation: glow 2s ease-in-out infinite alternate, pulse 4s ease-in-out infinite;
z-index: 10;
}
.particle {
position: absolute;
background: ${this.config.particleColor};
border-radius: 50%;
animation: float 20s infinite linear;
}
.items-container {
position: absolute;
width: 70vmin;
height: 70vmin;
animation: rotate 20s linear infinite;
}
.menu-item-wrapper {
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
}
.menu-item {
position: absolute;
transform: translate(-50%, -50%) translateX(35vmin);
width: 15vmin;
height: 15vmin;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.menu-item:hover {
transform: translate(-50%, -50%) translateX(35vmin) scale(1.2);
box-shadow: 0 0 25px ${this.config.hoverGlowColor};
}
.item-content {
width: 12vmin;
height: 12vmin;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
border: 2px solid ${this.config.itemBorderColor};
animation: pulse 2s ease-in-out infinite;
}
.item-text {
color: ${this.config.textColor};
font-weight: bold;
text-align: center;
display: inline-block;
font-size: 2vmin;
transform: rotate(90deg);
}
@keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@keyframes glow {
from {
box-shadow: 0 0 2vmin ${this.config.glowColor}, 0 0 4vmin ${this.config.glowColor}, 0 0 6vmin ${this.config.glowColor};
background: radial-gradient(circle, ${this.config.orbColor} 0%, ${this.config.orbColor.replace('1)', '0)')} 80%);
}
to {
box-shadow: 0 0 4vmin ${this.config.glowColor}, 0 0 8vmin ${this.config.glowColor}, 0 0 12vmin ${this.config.glowColor};
background: radial-gradient(circle, ${this.config.orbColor} 0%, ${this.config.orbColor.replace('1)', '0)')} 90%);
}
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
@keyframes float {
0% { transform: translate(0, 0); }
25% { transform: translate(10vw, 10vh); }
50% { transform: translate(20vw, 0); }
75% { transform: translate(10vw, -10vh); }
100% { transform: translate(0, 0); }
}
@keyframes backgroundShift {
0% { background-position: 0 0; }
100% { background-position: 10vmin 10vmin; }
}
`;
shadow.appendChild(style);
}
handleClick(url) {
console.log('Navigating to:', url); // Debugging log
if (this._hass && this._hass.navigate) {
console.log('Using Home Assistant navigation');
this._hass.navigate(url);
} else if (window.history && window.history.pushState) {
console.log('Using HTML5 History API');
window.history.pushState(null, '', url);
window.dispatchEvent(new Event('location-changed'));
} else {
console.log('Fallback: changing location directly');
window.location.href = url;
}
}
}
customElements.define('ha-biofects-fullmenu', HABiofectsFullMenu);