vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
97 lines (96 loc) • 2.65 kB
JavaScript
function o() {
this.__rules__ = [], this.__cache__ = null;
}
o.prototype.__find__ = function(_) {
for (let e = 0; e < this.__rules__.length; e++)
if (this.__rules__[e].name === _)
return e;
return -1;
};
o.prototype.__compile__ = function() {
const _ = this, e = [""];
_.__rules__.forEach(function(n) {
n.enabled && n.alt.forEach(function(t) {
e.indexOf(t) < 0 && e.push(t);
});
}), _.__cache__ = {}, e.forEach(function(n) {
_.__cache__[n] = [], _.__rules__.forEach(function(t) {
t.enabled && (n && t.alt.indexOf(n) < 0 || _.__cache__[n].push(t.fn));
});
});
};
o.prototype.at = function(_, e, n) {
const t = this.__find__(_), r = n || {};
if (t === -1)
throw new Error("Parser rule not found: " + _);
this.__rules__[t].fn = e, this.__rules__[t].alt = r.alt || [], this.__cache__ = null;
};
o.prototype.before = function(_, e, n, t) {
const r = this.__find__(_), i = t || {};
if (r === -1)
throw new Error("Parser rule not found: " + _);
this.__rules__.splice(r, 0, {
name: e,
enabled: !0,
fn: n,
alt: i.alt || []
}), this.__cache__ = null;
};
o.prototype.after = function(_, e, n, t) {
const r = this.__find__(_), i = t || {};
if (r === -1)
throw new Error("Parser rule not found: " + _);
this.__rules__.splice(r + 1, 0, {
name: e,
enabled: !0,
fn: n,
alt: i.alt || []
}), this.__cache__ = null;
};
o.prototype.push = function(_, e, n) {
const t = n || {};
this.__rules__.push({
name: _,
enabled: !0,
fn: e,
alt: t.alt || []
}), this.__cache__ = null;
};
o.prototype.enable = function(_, e) {
Array.isArray(_) || (_ = [_]);
const n = [];
return _.forEach(function(t) {
const r = this.__find__(t);
if (r < 0) {
if (e)
return;
throw new Error("Rules manager: invalid rule name " + t);
}
this.__rules__[r].enabled = !0, n.push(t);
}, this), this.__cache__ = null, n;
};
o.prototype.enableOnly = function(_, e) {
Array.isArray(_) || (_ = [_]), this.__rules__.forEach(function(n) {
n.enabled = !1;
}), this.enable(_, e);
};
o.prototype.disable = function(_, e) {
Array.isArray(_) || (_ = [_]);
const n = [];
return _.forEach(function(t) {
const r = this.__find__(t);
if (r < 0) {
if (e)
return;
throw new Error("Rules manager: invalid rule name " + t);
}
this.__rules__[r].enabled = !1, n.push(t);
}, this), this.__cache__ = null, n;
};
o.prototype.getRules = function(_) {
return this.__cache__ === null && this.__compile__(), this.__cache__[_] || [];
};
export {
o as default
};
//# sourceMappingURL=ruler.mjs.map