feat(notices): add animations to notices

This commit is contained in:
SethBurkart123
2024-12-02 12:17:39 +11:00
parent 4bf5420140
commit a999e4384b
3 changed files with 49 additions and 26 deletions
+17
View File
@@ -46,10 +46,27 @@ class EventManager {
}
const unregister = () => this.unregisterById(event, id);
this.listeners.get(event)!.push({ id, options, callback, unregister });
this.scanExistingElements(options, callback);
this.startObserving(options.parentElement);
return { unregister };
}
private async scanExistingElements(options: EventListenerOptions, callback: (element: Element) => void): Promise<void> {
const root = options.parentElement || document.documentElement;
const elements = Array.from(root.getElementsByTagName('*'));
elements.unshift(root);
for (let i = 0; i < elements.length; i += this.chunkSize) {
const chunk = elements.slice(i, i + this.chunkSize);
const filteredChunk = chunk.filter(element => this.matchesOptions(element, options));
for (const element of filteredChunk) {
callback(element);
}
}
}
public unregister(event: string): void {
if (this.listeners.has(event)) {
this.listeners.delete(event);