@qier-player/danmaku
Version:
Powerful danmaku, support many features.
51 lines • 1.4 kB
JavaScript
import { isString, isHTMLElement } from './is';
export function getEle(el) {
if (!el)
return null;
if (isString(el))
return document.querySelector(el);
if (isHTMLElement(el))
return el;
return null;
}
export function camel2line(str) {
return str.replace(/([A-Z])/g, '-$1').toLowerCase();
}
export function setStyle(el, style) {
var cssText = ';';
for (var key in style) {
cssText += camel2line(key) + ": " + style[key] + ";";
}
el.style.cssText = cssText;
}
export function removeEle(el) {
if (!el)
return;
if (el.remove) {
el.remove();
}
else if (el.parentNode) {
el.parentNode.removeChild(el);
}
}
var DomListener = /** @class */ (function () {
function DomListener(node, type, handler, options) {
this.node = node;
this.type = type;
this.handler = handler;
this.options = options;
// 对于 options 的支持暂未判断
node.addEventListener(type, handler, this.options);
}
DomListener.prototype.dispose = function () {
if (!this.handler)
return;
this.node.removeEventListener(this.type, this.handler, this.options);
this.node = null;
this.handler = null;
this.options = null;
};
return DomListener;
}());
export { DomListener };
//# sourceMappingURL=dom.js.map