!function(e, n) { "object" == typeof exports && "undefined" != typeof module ? n(exports, require("crlf-normalize"), require("split-smartly2")) : "function" == typeof define && define.amd ? define([ "exports", "crlf-normalize", "split-smartly2" ], n) : n((e = "undefined" != typeof globalThis ? globalThis : e || self).BlueloversAuto1111Pnginfo = {}, e.crlfNormalize, e.splitSmartly2); }(this, (function(e, n, r) { "use strict"; function inputToBytes(e) { return "undefined" != typeof Buffer && Buffer.isBuffer(e) || e instanceof Uint8Array ? e : Uint8Array.from(atob(e.slice(0, 8192)), (e => e.charCodeAt(0))); } function i32(e, n) { return new Uint32Array(new Uint8Array([ ...e.slice(n, n + 4) ].reverse()).buffer)[0]; } function _normalizeInputRaw(e) { return n.crlf(e).replace(/[ \t\xa0]+(?=\n)/g, "").replace(/\n{3,}/g, "\n\n").replace(/^[\r\n]+|[\s\r\n]+$/g, ""); } const t = /\r?\n/, o = /(?:\x00\x00\x00|\u200b\u200b\u200b)\r?\n/; function _splitRawToLines(e) { return e.split(_isRawVersionPlus(e) ? o : t); } function _isRawVersionPlus(e) { return o.test(e); } function _parseLine(e) { const [, n, r] = e.match(/^([^:]+)\s*:\s*(.*)$/); return [ n, r ]; } function* _parseInfoLineGenerator(e) { e = _normalizeInputRaw(e); const n = r.splitSmartly(e, [ "," ], { brackets: !0, trimSeparators: !0 }); for (let e of n) if (null != e && e.length) { const n = _parseLine(e); yield n; } } function extractPromptAndInfoFromRaw(e) { const n = _isRawVersionPlus(e = _normalizeInputRaw(e)); let r = _splitRawToLines(e), t = "", o = "", i = ""; const a = r.slice(); if (r.length) { if (n) { var s, f; if (r.length > 3) throw new TypeError; let e = r.pop(); if (e.startsWith("Steps: ") && (i = e, e = void 0), null !== (s = e) && void 0 !== s || (e = r.pop()), e.startsWith("Negative prompt: ") && (o = e.slice(17), e = void 0), null !== (f = e) && void 0 !== f || (e = r.pop()), t = e, r.length) throw new TypeError; } else { let e = r[r.length - 1]; if (e.startsWith("Steps: ") && (i = r.pop(), e = void 0), r.length) { let n = -1; for (let t = r.length - 1; t >= 0; t--) if (e = r[t], e.startsWith("Negative prompt: ")) { n = t, r[t] = e.slice(17); break; } -1 !== n && (o = r.splice(n).join("\n")), t = r.join("\n"); } } t = t.replace(/\x00\x00\x00/g, ""), o = o.replace(/\x00\x00\x00/g, ""); } return { prompt: t, negative_prompt: o, infoline: i, infoline_extra: [], lines_raw: a }; } const i = "137,80,78,71,13,10,26,10", a = /*#__PURE__*/ Uint8Array.from("tEXt", (e => e.charCodeAt(0))).join(","), s = 11; function uint8arrayToString(e) { return (new TextDecoder).decode(e); } function extractRawFromBytes(e) { if (e.slice(0, 8).join(",") !== i) return; const [n, r, t] = [ i32(e, 8), i32(e, 16), i32(e, 20) ], o = 8 + n + 12; if (e.slice(o + 4, o + 8).join(",") !== a) return; const f = i32(e, o); return { width: r, height: t, raw_info: uint8arrayToString(e.slice(o + 8 + s, o + 8 + f)) }; } function keyToSnakeStyle1(e) { return e.toLowerCase().replace(/ /g, "_"); } function* handleInfoEntriesGenerator(e, n) { for (const r of e) yield handleInfoEntry(r, n); } function handleInfoEntry(e, n) { const r = null == n ? void 0 : n.cast_to_snake; let [t, o] = e; const i = parseFloat(o), a = /^0\d/.test(o) || isNaN(i) || o - i != 0; return r && (t = keyToSnakeStyle1(t)), [ t, a ? o : i ]; } var f; function parseFromRawInfo(e, n) { return Object.fromEntries([ ...parseFromRawInfoGenerator(e, n) ]); } function* parseFromRawInfoGenerator(e, n) { if (null != n && n.isIncludePrompts) { const {prompt: n, negative_prompt: r, infoline: t} = extractPromptAndInfoFromRaw(e); yield [ "prompt", n ], yield [ "negative_prompt", r ], e = t; } yield* handleInfoEntriesGenerator(_parseInfoLineGenerator(e), n); } function parseFromImageBuffer(e, n = !1) { const r = extractRawFromBytes(inputToBytes(e)); if (!r) return; const {raw_info: t, width: o, height: i} = r, {prompt: a, negative_prompt: s, infoline: f, infoline_extra: p} = extractPromptAndInfoFromRaw(t); return { metadata: { width: o, height: i, extra: p, raw_info: t }, pnginfo: { prompt: a, negative_prompt: s, ...parseFromRawInfo(f, { cast_to_snake: n }) } }; } e.EnumInfoKey = void 0, (f = e.EnumInfoKey || (e.EnumInfoKey = {})).prompt = "prompt", f.negative_prompt = "negative_prompt", e.RE_LINE_SPLIT_BASE = t, e.RE_LINE_SPLIT_PLUS = o, e._isRawVersionPlus = _isRawVersionPlus, e._normalizeInputRaw = _normalizeInputRaw, e._parseInfoLine = function _parseInfoLine(e) { return [ ..._parseInfoLineGenerator(e) ]; }, e._parseInfoLineGenerator = _parseInfoLineGenerator, e._parseLine = _parseLine, e._splitRawToLines = _splitRawToLines, e.default = parseFromImageBuffer, e.extractPromptAndInfoFromRaw = extractPromptAndInfoFromRaw, e.extractRawFromBytes = extractRawFromBytes, e.handleInfoEntries = function handleInfoEntries(e, n) { return [ ...handleInfoEntriesGenerator(e, n) ]; }, e.handleInfoEntriesGenerator = handleInfoEntriesGenerator, e.handleInfoEntry = handleInfoEntry, e.i32 = i32, e.inputToBytes = inputToBytes, e.keyToSnakeStyle1 = keyToSnakeStyle1, e.parseFromImageBuffer = parseFromImageBuffer, e.parseFromRawInfo = parseFromRawInfo, e.parseFromRawInfoGenerator = parseFromRawInfoGenerator, e.stringToUint8Array = function stringToUint8Array(e) { return (new TextEncoder).encode(e); }, e.uint8arrayToString = uint8arrayToString, Object.defineProperty(e, "__esModule", { value: !0 }); })); //# sourceMappingURL=index.umd.production.min.cjs.map