@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
48 lines (47 loc) • 1.38 kB
JavaScript
var m = Object.defineProperty;
var _ = (s, e, t) => e in s ? m(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
var n = (s, e, t) => (_(s, typeof e != "symbol" ? e + "" : e, t), t);
class d {
constructor(e) {
n(this, "_items", []);
n(this, "_triggerEnqueue");
this._triggerEnqueue = e;
}
// Add item to queue with priority (lower number = higher priority)
enqueue(e, t, i = 0) {
const r = { id: e, data: t, priority: i }, u = this._items.findIndex((h) => h.priority > i);
u === -1 ? this._items.push(r) : this._items.splice(u, 0, r), this._triggerEnqueue(t);
}
// Remove and return highest priority item
dequeue() {
return this._items.shift();
}
// Remove item by id
removeQueue(e) {
const t = this._items.findIndex((i) => i.id === e);
return t !== -1 ? (this._items.splice(t, 1), !0) : !1;
}
// Change priority of item by id
changePagePriority(e, t) {
const i = this._items.find((r) => new RegExp(e).test(r.id));
return i ? (this.removeQueue(i.id), this.enqueue(i.id, i.data, t), !0) : !1;
}
peekAll() {
return this._items;
}
// Check if queue is empty
isEmpty() {
return this._items.length === 0;
}
// Get current size of queue
size() {
return this._items.length;
}
// Clear all items
clear() {
this._items = [];
}
}
export {
d as Queue
};