edo-htqw
Version:
A easier HTML element's dom operation libary.
54 lines (53 loc) • 1.56 kB
JavaScript
var _a;
import basic from './basic';
import listen from './listen';
import style from './style';
import errors from './error/main';
class edoElement {
constructor(val) {
this[_a] = 'edoElement';
this.el = document.createElement('div');
if (typeof val === 'string') {
try {
if (document.querySelector(val) === null) {
throw new errors.edoHTMLElementIsNotFoundError(`The element "${val}" is not found!!!`);
}
else {
this.el = document.querySelector(val);
}
}
catch (e) {
if (!e.name.startsWith('edo')) {
throw new errors.edoCssSelectorError(`This Css Selector "${val}" is error`);
}
else {
throw e;
}
}
}
else if (val instanceof HTMLElement) {
this.el = val;
}
else {
throw new errors.edoTypeError(`This type should is HTMLElement or string, fault ${Object.prototype.toString.call(val).split(' ')[1].replace(']', '')}`);
}
this.el;
}
}
_a = Symbol.toStringTag;
const edo = function (val) {
return new edoElement(val);
};
edo.proto = function (name, value) {
try {
edoElement.prototype[name] = value;
return true;
}
catch (_b) {
return false;
}
};
basic(edo);
listen(edo);
style(edo);
export default edo;