@twobirds/microcomponents
Version:
Micro Components Organization Class
71 lines • 1.96 kB
JavaScript
;
var isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
let nativeEventNames = new Set();
if (isBrowser()) {
Object.keys(HTMLElement.prototype).filter(key => /^on/.test(key)).forEach(eventName => nativeEventNames.add(eventName));
}
function isDOM(element) {
return element && element instanceof HTMLElement;
}
class McEvent {
#type;
#stopped = false;
#immediateStopped = false;
constructor(type, data = {}, bubble = 'l') {
this.#type = type;
this.data = data;
this.bubble = bubble;
}
get type() {
return this.#type;
}
get stopped() {
return this.#stopped;
}
get immediateStopped() {
return this.#immediateStopped;
}
stopPropagation() {
this.#stopped = true;
}
stopImmediatePropagation() {
this.stopPropagation();
this.#immediateStopped = true;
}
}
function getMicroComponents(elements, search) {
let mcValues = [];
elements.forEach(e => {
if (e) {
if (e instanceof HTMLElement) {
const _mc = e?._mc;
if (!search && _mc) {
mcValues = mcValues.concat(Object.values(e._mc));
}
else if (search && _mc && _mc[search]) {
mcValues.push(_mc[search]);
}
}
}
});
return mcValues;
}
function traverseNodes(node, search, firstonly = true) {
let mcValues = [];
while (node) {
if (node._mc) {
if (!search) {
mcValues = mcValues.concat(Object.values(node._mc));
}
else if (search && node._mc[search]) {
mcValues.push(node._mc[search]);
}
if (firstonly)
return mcValues;
}
node = node.parentNode;
}
return mcValues;
}
export { McEvent };
//# sourceMappingURL=McEvent.js.map