storybook
Version:
Storybook: Develop, document, and test UI components in isolation
169 lines (164 loc) • 4.26 kB
JavaScript
import CJS_COMPAT_NODE_URL_q99y7iqlbzn from 'node:url';
import CJS_COMPAT_NODE_PATH_q99y7iqlbzn from 'node:path';
import CJS_COMPAT_NODE_MODULE_q99y7iqlbzn from "node:module";
var __filename = CJS_COMPAT_NODE_URL_q99y7iqlbzn.fileURLToPath(import.meta.url);
var __dirname = CJS_COMPAT_NODE_PATH_q99y7iqlbzn.dirname(__filename);
var require = CJS_COMPAT_NODE_MODULE_q99y7iqlbzn.createRequire(import.meta.url);
// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
__name
} from "./chunk-MB5KTO7X.js";
// ../node_modules/yocto-queue/index.js
var Node = class {
static {
__name(this, "Node");
}
value;
next;
constructor(value) {
this.value = value;
}
};
var Queue = class {
static {
__name(this, "Queue");
}
#head;
#tail;
#size;
constructor() {
this.clear();
}
enqueue(value) {
const node = new Node(value);
if (this.#head) {
this.#tail.next = node;
this.#tail = node;
} else {
this.#head = node;
this.#tail = node;
}
this.#size++;
}
dequeue() {
const current = this.#head;
if (!current) {
return;
}
this.#head = this.#head.next;
this.#size--;
return current.value;
}
peek() {
if (!this.#head) {
return;
}
return this.#head.value;
}
clear() {
this.#head = void 0;
this.#tail = void 0;
this.#size = 0;
}
get size() {
return this.#size;
}
*[Symbol.iterator]() {
let current = this.#head;
while (current) {
yield current.value;
current = current.next;
}
}
*drain() {
while (this.#head) {
yield this.dequeue();
}
}
};
// ../node_modules/p-limit/index.js
function pLimit(concurrency) {
validateConcurrency(concurrency);
const queue = new Queue();
let activeCount = 0;
const resumeNext = /* @__PURE__ */ __name(() => {
if (activeCount < concurrency && queue.size > 0) {
queue.dequeue()();
activeCount++;
}
}, "resumeNext");
const next = /* @__PURE__ */ __name(() => {
activeCount--;
resumeNext();
}, "next");
const run = /* @__PURE__ */ __name(async (function_, resolve, arguments_) => {
const result = (async () => function_(...arguments_))();
resolve(result);
try {
await result;
} catch {
}
next();
}, "run");
const enqueue = /* @__PURE__ */ __name((function_, resolve, arguments_) => {
new Promise((internalResolve) => {
queue.enqueue(internalResolve);
}).then(
run.bind(void 0, function_, resolve, arguments_)
);
(async () => {
await Promise.resolve();
if (activeCount < concurrency) {
resumeNext();
}
})();
}, "enqueue");
const generator = /* @__PURE__ */ __name((function_, ...arguments_) => new Promise((resolve) => {
enqueue(function_, resolve, arguments_);
}), "generator");
Object.defineProperties(generator, {
activeCount: {
get: /* @__PURE__ */ __name(() => activeCount, "get")
},
pendingCount: {
get: /* @__PURE__ */ __name(() => queue.size, "get")
},
clearQueue: {
value() {
queue.clear();
}
},
concurrency: {
get: /* @__PURE__ */ __name(() => concurrency, "get"),
set(newConcurrency) {
validateConcurrency(newConcurrency);
concurrency = newConcurrency;
queueMicrotask(() => {
while (activeCount < concurrency && queue.size > 0) {
resumeNext();
}
});
}
}
});
return generator;
}
__name(pLimit, "pLimit");
function limitFunction(function_, option) {
const { concurrency } = option;
const limit = pLimit(concurrency);
return (...arguments_) => limit(() => function_(...arguments_));
}
__name(limitFunction, "limitFunction");
function validateConcurrency(concurrency) {
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
}
}
__name(validateConcurrency, "validateConcurrency");
export {
pLimit as default,
limitFunction
};