'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const fetchAssets=require('../../_virtual/fetch-assets.cjs'),require$$0=require('picocolors'),fetchRetry=require('./fetch-retry.cjs'),require$$2=require('foxts/wait'),require$$6=require('foxts/guard'),textLineTransformStream=require('./text-line-transform-stream.cjs'),processLine=require('./process-line.cjs');var hasRequiredFetchAssets; function requireFetchAssets () { if (hasRequiredFetchAssets) return fetchAssets.__exports; hasRequiredFetchAssets = 1; (function (exports) { Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { CustomAbortError: function() { return CustomAbortError; }, fetchAssets: function() { return fetchAssets; } }); const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0); const _fetchretry = /*@__PURE__*/ fetchRetry.__require(); const _wait = require$$2; const _guard = require$$6; const _textlinetransformstream = /*@__PURE__*/ textLineTransformStream.__require(); const _processline = /*@__PURE__*/ processLine.__require(); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class CustomAbortError extends Error { name = 'AbortError'; digest = 'AbortError'; } const reusedCustomAbortError = new CustomAbortError(); async function fetchAssets(url, fallbackUrls, processLine = false) { const controller = new AbortController(); const createFetchFallbackPromise = async (url, index)=>{ if (index >= 0) { // Most assets can be downloaded within 250ms. To avoid wasting bandwidth, we will wait for 500ms before downloading from the fallback URL. try { await (0, _wait.waitWithAbort)(50 + (index + 1) * 100, controller.signal); } catch { console.log(_picocolors.default.gray('[fetch cancelled early]'), _picocolors.default.gray(url)); throw reusedCustomAbortError; } } if (controller.signal.aborted) { console.log(_picocolors.default.gray('[fetch cancelled]'), _picocolors.default.gray(url)); throw reusedCustomAbortError; } const res = await (0, _fetchretry.$$fetch)(url, { signal: controller.signal, ..._fetchretry.defaultRequestInit }); let stream = (0, _guard.nullthrow)(res.body).pipeThrough(new TextDecoderStream()).pipeThrough(new _textlinetransformstream.TextLineStream()); if (processLine) { stream = stream.pipeThrough(new _processline.ProcessLineStream()); } const arr = await Array.fromAsync(stream); if (arr.length < 1) { throw new _fetchretry.ResponseError(res, url, 'empty response w/o 304'); } controller.abort(); return arr; }; if (!fallbackUrls || fallbackUrls.length === 0) { return createFetchFallbackPromise(url, -1); } return Promise.any([ createFetchFallbackPromise(url, -1), ...fallbackUrls.map(createFetchFallbackPromise) ]); } } (fetchAssets.__exports)); return fetchAssets.__exports; }exports.__require=requireFetchAssets;