@roukara/nodo
Version:
A class designed to facilitate the manipulation of DOM elements within web pages.
2 lines (1 loc) • 937 B
JavaScript
(function(s,t){typeof exports=="object"&&typeof module<"u"?module.exports=t():typeof define=="function"&&define.amd?define(t):(s=typeof globalThis<"u"?globalThis:s||self,s.Nodo=t())})(this,function(){"use strict";var r=Object.defineProperty;var d=(s,t,e)=>t in s?r(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var i=(s,t,e)=>d(s,typeof t!="symbol"?t+"":t,e);class s{constructor(e,n={}){i(this,"el");i(this,"props");i(this,"refs",{});if(typeof e=="string"){if(this.el=document.querySelector(`[data-el="${e}"]`),!this.el)throw new Error(`Element not found with data-el attribute: ${e}`)}else if(e instanceof HTMLElement)this.el=e;else throw new Error(`Invalid type for el: ${e}`);this.props=n,this.findRefs()}findRefs(){const e=this.el.querySelectorAll("[data-ref]"),n={};e.forEach(f=>{const o=f.dataset.ref;o&&(n[o]||(n[o]=[]),n[o].push(f))});for(const f in n){const o=n[f];this.refs[f]=o.length>1?o:o[0]}}}return s});