UNPKG

pangu

Version:

Opinionated paranoid text spacing: automatically inserts whitespace between CJK (Chinese, Japanese, Korean) and ANS (alphabetical letters, numerical digits and symbols)

48 lines (47 loc) • 1.18 kB
//#region src/browser/scheduling/task-scheduler.ts var TaskQueue = class { queue = []; isProcessing = false; add(task) { this.queue.push(task); this.scheduleProcessing(); } clear() { this.queue.length = 0; } get length() { return this.queue.length; } scheduleProcessing() { if (!this.isProcessing && this.queue.length > 0) { this.isProcessing = true; requestIdleCallback((deadline) => this.process(deadline), { timeout: 5e3 }); } } process(deadline) { try { while (deadline.timeRemaining() > 0 && this.queue.length > 0) this.queue.shift()?.(); } finally { this.isProcessing = false; if (this.queue.length > 0) this.scheduleProcessing(); } } }; /** * Runs queued text spacing work during browser idle time to avoid blocking the UI. * Tasks execute via requestIdleCallback when the browser has spare time, * ensuring smooth user experience even when processing large amounts of text. */ var TaskScheduler = class { config = { enabled: true, timeout: 2e3 }; taskQueue = new TaskQueue(); get queue() { return this.taskQueue; } }; //#endregion export { TaskQueue, TaskScheduler }; //# sourceMappingURL=task-scheduler.js.map