UNPKG

@tonyptang/unocss-config

Version:

unocss-config

423 lines (417 loc) 13.1 kB
import { Fi, Mn, On, br, dt, le, ut, ye } from "./chunk-C7IPHR2B.mjs"; import { withBase, withQuery } from "./chunk-SDWIKQ7Y.mjs"; import "./chunk-TTFRSOOU.mjs"; // node_modules/.pnpm/ofetch@1.3.4/node_modules/ofetch/dist/node.mjs import http from "node:http"; import https from "node:https"; // node_modules/.pnpm/node-fetch-native@1.6.4/node_modules/node-fetch-native/dist/index.mjs var a = Object.defineProperty; var t = (e, r) => a(e, "name", { value: r, configurable: true }); var f = Object.defineProperty; var g = t((e, r) => f(e, "name", { value: r, configurable: true }), "e"); var o = !!globalThis.process?.env?.FORCE_NODE_FETCH; function l() { return !o && globalThis.fetch ? globalThis.fetch : Fi; } t(l, "p"), g(l, "_getFetch"); var s = l(); var T = !o && globalThis.Blob || ut; var R = !o && globalThis.File || On; var u = !o && globalThis.FormData || br; var d = !o && globalThis.Headers || ye; var $ = !o && globalThis.Request || dt; var C = !o && globalThis.Response || le; var A = !o && globalThis.AbortController || Mn; // node_modules/.pnpm/destr@2.0.3/node_modules/destr/dist/index.mjs var suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/; var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/; var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/; function jsonParseTransform(key, value) { if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) { warnKeyDropped(key); return; } return value; } function warnKeyDropped(key) { console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`); } function destr(value, options = {}) { if (typeof value !== "string") { return value; } const _value = value.trim(); if ( // eslint-disable-next-line unicorn/prefer-at value[0] === '"' && value.endsWith('"') && !value.includes("\\") ) { return _value.slice(1, -1); } if (_value.length <= 9) { const _lval = _value.toLowerCase(); if (_lval === "true") { return true; } if (_lval === "false") { return false; } if (_lval === "undefined") { return void 0; } if (_lval === "null") { return null; } if (_lval === "nan") { return Number.NaN; } if (_lval === "infinity") { return Number.POSITIVE_INFINITY; } if (_lval === "-infinity") { return Number.NEGATIVE_INFINITY; } } if (!JsonSigRx.test(value)) { if (options.strict) { throw new SyntaxError("[destr] Invalid JSON"); } return value; } try { if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) { if (options.strict) { throw new Error("[destr] Possible prototype pollution"); } return JSON.parse(value, jsonParseTransform); } return JSON.parse(value); } catch (error) { if (options.strict) { throw error; } return value; } } // node_modules/.pnpm/ofetch@1.3.4/node_modules/ofetch/dist/shared/ofetch.37386b05.mjs var FetchError = class extends Error { constructor(message, opts) { super(message, opts); this.name = "FetchError"; if (opts?.cause && !this.cause) { this.cause = opts.cause; } } }; function createFetchError(ctx) { const errorMessage = ctx.error?.message || ctx.error?.toString() || ""; const method = ctx.request?.method || ctx.options?.method || "GET"; const url = ctx.request?.url || String(ctx.request) || "/"; const requestStr = `[${method}] ${JSON.stringify(url)}`; const statusStr = ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>"; const message = `${requestStr}: ${statusStr}${errorMessage ? ` ${errorMessage}` : ""}`; const fetchError = new FetchError( message, ctx.error ? { cause: ctx.error } : void 0 ); for (const key of ["request", "options", "response"]) { Object.defineProperty(fetchError, key, { get() { return ctx[key]; } }); } for (const [key, refKey] of [ ["data", "_data"], ["status", "status"], ["statusCode", "status"], ["statusText", "statusText"], ["statusMessage", "statusText"] ]) { Object.defineProperty(fetchError, key, { get() { return ctx.response && ctx.response[refKey]; } }); } return fetchError; } var payloadMethods = new Set( Object.freeze(["PATCH", "POST", "PUT", "DELETE"]) ); function isPayloadMethod(method = "GET") { return payloadMethods.has(method.toUpperCase()); } function isJSONSerializable(value) { if (value === void 0) { return false; } const t2 = typeof value; if (t2 === "string" || t2 === "number" || t2 === "boolean" || t2 === null) { return true; } if (t2 !== "object") { return false; } if (Array.isArray(value)) { return true; } if (value.buffer) { return false; } return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function"; } var textTypes = /* @__PURE__ */ new Set([ "image/svg", "application/xml", "application/xhtml", "application/html" ]); var JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i; function detectResponseType(_contentType = "") { if (!_contentType) { return "json"; } const contentType = _contentType.split(";").shift() || ""; if (JSON_RE.test(contentType)) { return "json"; } if (textTypes.has(contentType) || contentType.startsWith("text/")) { return "text"; } return "blob"; } function mergeFetchOptions(input, defaults, Headers2 = globalThis.Headers) { const merged = { ...defaults, ...input }; if (defaults?.params && input?.params) { merged.params = { ...defaults?.params, ...input?.params }; } if (defaults?.query && input?.query) { merged.query = { ...defaults?.query, ...input?.query }; } if (defaults?.headers && input?.headers) { merged.headers = new Headers2(defaults?.headers || {}); for (const [key, value] of new Headers2(input?.headers || {})) { merged.headers.set(key, value); } } return merged; } var retryStatusCodes = /* @__PURE__ */ new Set([ 408, // Request Timeout 409, // Conflict 425, // Too Early 429, // Too Many Requests 500, // Internal Server Error 502, // Bad Gateway 503, // Service Unavailable 504 // Gateway Timeout ]); var nullBodyResponses = /* @__PURE__ */ new Set([101, 204, 205, 304]); function createFetch(globalOptions = {}) { const { fetch: fetch2 = globalThis.fetch, Headers: Headers2 = globalThis.Headers, AbortController: AbortController2 = globalThis.AbortController } = globalOptions; async function onError(context) { const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false; if (context.options.retry !== false && !isAbort) { let retries; if (typeof context.options.retry === "number") { retries = context.options.retry; } else { retries = isPayloadMethod(context.options.method) ? 0 : 1; } const responseCode = context.response && context.response.status || 500; if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) { const retryDelay = context.options.retryDelay || 0; if (retryDelay > 0) { await new Promise((resolve) => setTimeout(resolve, retryDelay)); } return $fetchRaw(context.request, { ...context.options, retry: retries - 1 }); } } const error = createFetchError(context); if (Error.captureStackTrace) { Error.captureStackTrace(error, $fetchRaw); } throw error; } const $fetchRaw = async function $fetchRaw2(_request, _options = {}) { const context = { request: _request, options: mergeFetchOptions(_options, globalOptions.defaults, Headers2), response: void 0, error: void 0 }; context.options.method = context.options.method?.toUpperCase(); if (context.options.onRequest) { await context.options.onRequest(context); } if (typeof context.request === "string") { if (context.options.baseURL) { context.request = withBase(context.request, context.options.baseURL); } if (context.options.query || context.options.params) { context.request = withQuery(context.request, { ...context.options.params, ...context.options.query }); } } if (context.options.body && isPayloadMethod(context.options.method)) { if (isJSONSerializable(context.options.body)) { context.options.body = typeof context.options.body === "string" ? context.options.body : JSON.stringify(context.options.body); context.options.headers = new Headers2(context.options.headers || {}); if (!context.options.headers.has("content-type")) { context.options.headers.set("content-type", "application/json"); } if (!context.options.headers.has("accept")) { context.options.headers.set("accept", "application/json"); } } else if ( // ReadableStream Body "pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || // Node.js Stream Body typeof context.options.body.pipe === "function" ) { if (!("duplex" in context.options)) { context.options.duplex = "half"; } } } let abortTimeout; if (!context.options.signal && context.options.timeout) { const controller = new AbortController2(); abortTimeout = setTimeout( () => controller.abort(), context.options.timeout ); context.options.signal = controller.signal; } try { context.response = await fetch2( context.request, context.options ); } catch (error) { context.error = error; if (context.options.onRequestError) { await context.options.onRequestError(context); } return await onError(context); } finally { if (abortTimeout) { clearTimeout(abortTimeout); } } const hasBody = context.response.body && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD"; if (hasBody) { const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || ""); switch (responseType) { case "json": { const data = await context.response.text(); const parseFunction = context.options.parseResponse || destr; context.response._data = parseFunction(data); break; } case "stream": { context.response._data = context.response.body; break; } default: { context.response._data = await context.response[responseType](); } } } if (context.options.onResponse) { await context.options.onResponse(context); } if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) { if (context.options.onResponseError) { await context.options.onResponseError(context); } return await onError(context); } return context.response; }; const $fetch2 = async function $fetch22(request, options) { const r = await $fetchRaw(request, options); return r._data; }; $fetch2.raw = $fetchRaw; $fetch2.native = (...args) => fetch2(...args); $fetch2.create = (defaultOptions = {}) => createFetch({ ...globalOptions, defaults: { ...globalOptions.defaults, ...defaultOptions } }); return $fetch2; } // node_modules/.pnpm/ofetch@1.3.4/node_modules/ofetch/dist/node.mjs function createNodeFetch() { const useKeepAlive = JSON.parse(process.env.FETCH_KEEP_ALIVE || "false"); if (!useKeepAlive) { return s; } const agentOptions = { keepAlive: true }; const httpAgent = new http.Agent(agentOptions); const httpsAgent = new https.Agent(agentOptions); const nodeFetchOptions = { agent(parsedURL) { return parsedURL.protocol === "http:" ? httpAgent : httpsAgent; } }; return function nodeFetchWithKeepAlive(input, init) { return s(input, { ...nodeFetchOptions, ...init }); }; } var fetch = globalThis.fetch || createNodeFetch(); var Headers = globalThis.Headers || d; var AbortController = globalThis.AbortController || A; var ofetch = createFetch({ fetch, Headers, AbortController }); var $fetch = ofetch; export { $fetch, AbortController, FetchError, Headers, createFetch, createFetchError, createNodeFetch, fetch, ofetch };