| 1 | {"ast":null,"code":"/**\n * Estimate decoded byte length of a data:// URL *without* allocating large buffers.\n * - For base64: compute exact decoded size using length and padding;\n * handle %XX at the character-count level (no string allocation).\n * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.\n *\n * @param {string} url\n * @returns {number}\n */\nexport default function estimateDataURLDecodedBytes(url) {\n if (!url || typeof url !== 'string') return 0;\n if (!url.startsWith('data:')) return 0;\n const comma = url.indexOf(',');\n if (comma < 0) return 0;\n const meta = url.slice(5, comma);\n const body = url.slice(comma + 1);\n const isBase64 = /;base64/i.test(meta);\n if (isBase64) {\n let effectiveLen = body.length;\n const len = body.length; // cache length\n\n for (let i = 0; i < len; i++) {\n if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {\n const a = body.charCodeAt(i + 1);\n const b = body.charCodeAt(i + 2);\n const isHex = (a >= 48 && a <= 57 || a >= 65 && a <= 70 || a >= 97 && a <= 102) && (b >= 48 && b <= 57 || b >= 65 && b <= 70 || b >= 97 && b <= 102);\n if (isHex) {\n effectiveLen -= 2;\n i += 2;\n }\n }\n }\n let pad = 0;\n let idx = len - 1;\n const tailIsPct3D = j => j >= 2 && body.charCodeAt(j - 2) === 37 &&\n // '%'\n body.charCodeAt(j - 1) === 51 && (\n // '3'\n body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'\n\n if (idx >= 0) {\n if (body.charCodeAt(idx) === 61 /* '=' */) {\n pad++;\n idx--;\n } else if (tailIsPct3D(idx)) {\n pad++;\n idx -= 3;\n }\n }\n if (pad === 1 && idx >= 0) {\n if (body.charCodeAt(idx) === 61 /* '=' */) {\n pad++;\n } else if (tailIsPct3D(idx)) {\n pad++;\n }\n }\n const groups = Math.floor(effectiveLen / 4);\n const bytes = groups * 3 - (pad || 0);\n return bytes > 0 ? bytes : 0;\n }\n if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {\n return Buffer.byteLength(body, 'utf8');\n }\n\n // Compute UTF-8 byte length directly from UTF-16 code units without allocating\n // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).\n // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit\n // but 3 UTF-8 bytes).\n let bytes = 0;\n for (let i = 0, len = body.length; i < len; i++) {\n const c = body.charCodeAt(i);\n if (c < 0x80) {\n bytes += 1;\n } else if (c < 0x800) {\n bytes += 2;\n } else if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) {\n const next = body.charCodeAt(i + 1);\n if (next >= 0xdc00 && next <= 0xdfff) {\n bytes += 4;\n i++;\n } else {\n bytes += 3;\n }\n } else {\n bytes += 3;\n }\n }\n return bytes;\n}","map":{"version":3,"names":["estimateDataURLDecodedBytes","url","startsWith","comma","indexOf","meta","slice","body","isBase64","test","effectiveLen","length","len","i","charCodeAt","a","b","isHex","pad","idx","tailIsPct3D","j","groups","Math","floor","bytes","Buffer","byteLength","c","next"],"sources":["C:/Users/User/Downloads/medora5/frontend/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js"],"sourcesContent":["/**\n * Estimate decoded byte length of a data:// URL *without* allocating large buffers.\n * - For base64: compute exact decoded size using length and padding;\n * handle %XX at the character-count level (no string allocation).\n * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.\n *\n * @param {string} url\n * @returns {number}\n */\nexport default function estimateDataURLDecodedBytes(url) {\n if (!url || typeof url !== 'string') return 0;\n if (!url.startsWith('data:')) return 0;\n\n const comma = url.indexOf(',');\n if (comma < 0) return 0;\n\n const meta = url.slice(5, comma);\n const body = url.slice(comma + 1);\n const isBase64 = /;base64/i.test(meta);\n\n if (isBase64) {\n let effectiveLen = body.length;\n const len = body.length; // cache length\n\n for (let i = 0; i < len; i++) {\n if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {\n const a = body.charCodeAt(i + 1);\n const b = body.charCodeAt(i + 2);\n const isHex =\n ((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&\n ((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));\n\n if (isHex) {\n effectiveLen -= 2;\n i += 2;\n }\n }\n }\n\n let pad = 0;\n let idx = len - 1;\n\n const tailIsPct3D = (j) =>\n j >= 2 &&\n body.charCodeAt(j - 2) === 37 && // '%'\n body.charCodeAt(j - 1) === 51 && // '3'\n (body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'\n\n if (idx >= 0) {\n if (body.charCodeAt(idx) === 61 /* '=' */) {\n pad++;\n idx--;\n } else if (tailIsPct3D(idx)) {\n pad++;\n idx -= 3;\n }\n }\n\n if (pad === 1 && idx >= 0) {\n if (body.charCodeAt(idx) === 61 /* '=' */) {\n pad++;\n } else if (tailIsPct3D(idx)) {\n pad++;\n }\n }\n\n const groups = Math.floor(effectiveLen / 4);\n const bytes = groups * 3 - (pad || 0);\n return bytes > 0 ? bytes : 0;\n }\n\n if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {\n return Buffer.byteLength(body, 'utf8');\n }\n\n // Compute UTF-8 byte length directly from UTF-16 code units without allocating\n // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).\n // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit\n // but 3 UTF-8 bytes).\n let bytes = 0;\n for (let i = 0, len = body.length; i < len; i++) {\n const c = body.charCodeAt(i);\n if (c < 0x80) {\n bytes += 1;\n } else if (c < 0x800) {\n bytes += 2;\n } else if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) {\n const next = body.charCodeAt(i + 1);\n if (next >= 0xdc00 && next <= 0xdfff) {\n bytes += 4;\n i++;\n } else {\n bytes += 3;\n }\n } else {\n bytes += 3;\n }\n }\n return bytes;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,2BAA2BA,CAACC,GAAG,EAAE;EACvD,IAAI,CAACA,GAAG,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE,OAAO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