comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
39 lines (38 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const filterEmpty = (children) => {
const res = [];
children.forEach((child) => {
if (Array.isArray(child)) {
res.push(...child);
} else if (child.type === vue.Fragment) {
res.push(...child.children);
} else {
res.push(child);
}
});
return res.filter((c) => !isEmptyElement(c));
};
const isEmptyElement = (c) => {
return c && (c.type === Comment || c.type === vue.Fragment && c.children.length === 0 || c.type === Text && c.children.trim() === "");
};
function hasClass(el, className) {
const reg = new RegExp(`(^|\\s)${className}(\\s|$)`);
return reg.test(el.className);
}
const addClass = (el, className) => {
if (hasClass(el, className)) return;
const newClass = el.className.split(/\s+/);
newClass.push(className);
el.className = newClass.join(" ");
};
const removeClass = (el, className) => {
if (hasClass(el, className)) {
const newClass = el.className.split(/\s+/).filter((name) => name !== className);
el.className = newClass.join(" ");
}
};
exports.addClass = addClass;
exports.filterEmpty = filterEmpty;
exports.removeClass = removeClass;