{"version":3,"file":"vendors-536eaa00.f584a1446b2fc034d810.bundle.js","mappings":"AAAA","sources":["webpack://lernplattform-admin-frontend/./node_modules/detect-browser/es/index.js","webpack://lernplattform-admin-frontend/./node_modules/dijkstrajs/dijkstra.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/helpers/crc.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/helpers/unfilter.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/helpers/applyUnfilter.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/helpers/decodeInterlaceAdam7.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/helpers/decodeInterlaceNull.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/helpers/signature.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/helpers/text.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/internalTypes.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/PngDecoder.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/PngEncoder.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/types.js","webpack://lernplattform-admin-frontend/./node_modules/fast-png/lib-esm/index.js"],"sourcesContent":["var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {\n    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n        if (ar || !(i in from)) {\n            if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n            ar[i] = from[i];\n        }\n    }\n    return to.concat(ar || Array.prototype.slice.call(from));\n};\nvar BrowserInfo = /** @class */ (function () {\n    function BrowserInfo(name, version, os) {\n        this.name = name;\n        this.version = version;\n        this.os = os;\n        this.type = 'browser';\n    }\n    return BrowserInfo;\n}());\nexport { BrowserInfo };\nvar NodeInfo = /** @class */ (function () {\n    function NodeInfo(version) {\n        this.version = version;\n        this.type = 'node';\n        this.name = 'node';\n        this.os = process.platform;\n    }\n    return NodeInfo;\n}());\nexport { NodeInfo };\nvar SearchBotDeviceInfo = /** @class */ (function () {\n    function SearchBotDeviceInfo(name, version, os, bot) {\n        this.name = name;\n        this.version = version;\n        this.os = os;\n        this.bot = bot;\n        this.type = 'bot-device';\n    }\n    return SearchBotDeviceInfo;\n}());\nexport { SearchBotDeviceInfo };\nvar BotInfo = /** @class */ (function () {\n    function BotInfo() {\n        this.type = 'bot';\n        this.bot = true; // NOTE: deprecated test name instead\n        this.name = 'bot';\n        this.version = null;\n        this.os = null;\n    }\n    return BotInfo;\n}());\nexport { BotInfo };\nvar ReactNativeInfo = /** @class */ (function () {\n    function ReactNativeInfo() {\n        this.type = 'react-native';\n        this.name = 'react-native';\n        this.version = null;\n        this.os = null;\n    }\n    return ReactNativeInfo;\n}());\nexport { ReactNativeInfo };\n// tslint:disable-next-line:max-line-length\nvar SEARCHBOX_UA_REGEX = /alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/;\nvar SEARCHBOT_OS_REGEX = /(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\\ Jeeves\\/Teoma|ia_archiver)/;\nvar REQUIRED_VERSION_PARTS = 3;\nvar userAgentRules = [\n    ['aol', /AOLShield\\/([0-9\\._]+)/],\n    ['edge', /Edge\\/([0-9\\._]+)/],\n    ['edge-ios', /EdgiOS\\/([0-9\\._]+)/],\n    ['yandexbrowser', /YaBrowser\\/([0-9\\._]+)/],\n    ['kakaotalk', /KAKAOTALK\\s([0-9\\.]+)/],\n    ['samsung', /SamsungBrowser\\/([0-9\\.]+)/],\n    ['silk', /\\bSilk\\/([0-9._-]+)\\b/],\n    ['miui', /MiuiBrowser\\/([0-9\\.]+)$/],\n    ['beaker', /BeakerBrowser\\/([0-9\\.]+)/],\n    ['edge-chromium', /EdgA?\\/([0-9\\.]+)/],\n    [\n        'chromium-webview',\n        /(?!Chrom.*OPR)wv\\).*Chrom(?:e|ium)\\/([0-9\\.]+)(:?\\s|$)/,\n    ],\n    ['chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\\/([0-9\\.]+)(:?\\s|$)/],\n    ['phantomjs', /PhantomJS\\/([0-9\\.]+)(:?\\s|$)/],\n    ['crios', /CriOS\\/([0-9\\.]+)(:?\\s|$)/],\n    ['firefox', /Firefox\\/([0-9\\.]+)(?:\\s|$)/],\n    ['fxios', /FxiOS\\/([0-9\\.]+)/],\n    ['opera-mini', /Opera Mini.*Version\\/([0-9\\.]+)/],\n    ['opera', /Opera\\/([0-9\\.]+)(?:\\s|$)/],\n    ['opera', /OPR\\/([0-9\\.]+)(:?\\s|$)/],\n    ['pie', /^Microsoft Pocket Internet Explorer\\/(\\d+\\.\\d+)$/],\n    ['pie', /^Mozilla\\/\\d\\.\\d+\\s\\(compatible;\\s(?:MSP?IE|MSInternet Explorer) (\\d+\\.\\d+);.*Windows CE.*\\)$/],\n    ['netfront', /^Mozilla\\/\\d\\.\\d+.*NetFront\\/(\\d.\\d)/],\n    ['ie', /Trident\\/7\\.0.*rv\\:([0-9\\.]+).*\\).*Gecko$/],\n    ['ie', /MSIE\\s([0-9\\.]+);.*Trident\\/[4-7].0/],\n    ['ie', /MSIE\\s(7\\.0)/],\n    ['bb10', /BB10;\\sTouch.*Version\\/([0-9\\.]+)/],\n    ['android', /Android\\s([0-9\\.]+)/],\n    ['ios', /Version\\/([0-9\\._]+).*Mobile.*Safari.*/],\n    ['safari', /Version\\/([0-9\\._]+).*Safari/],\n    ['facebook', /FB[AS]V\\/([0-9\\.]+)/],\n    ['instagram', /Instagram\\s([0-9\\.]+)/],\n    ['ios-webview', /AppleWebKit\\/([0-9\\.]+).*Mobile/],\n    ['ios-webview', /AppleWebKit\\/([0-9\\.]+).*Gecko\\)$/],\n    ['curl', /^curl\\/([0-9\\.]+)$/],\n    ['searchbot', SEARCHBOX_UA_REGEX],\n];\nvar operatingSystemRules = [\n    ['iOS', /iP(hone|od|ad)/],\n    ['Android OS', /Android/],\n    ['BlackBerry OS', /BlackBerry|BB10/],\n    ['Windows Mobile', /IEMobile/],\n    ['Amazon OS', /Kindle/],\n    ['Windows 3.11', /Win16/],\n    ['Windows 95', /(Windows 95)|(Win95)|(Windows_95)/],\n    ['Windows 98', /(Windows 98)|(Win98)/],\n    ['Windows 2000', /(Windows NT 5.0)|(Windows 2000)/],\n    ['Windows XP', /(Windows NT 5.1)|(Windows XP)/],\n    ['Windows Server 2003', /(Windows NT 5.2)/],\n    ['Windows Vista', /(Windows NT 6.0)/],\n    ['Windows 7', /(Windows NT 6.1)/],\n    ['Windows 8', /(Windows NT 6.2)/],\n    ['Windows 8.1', /(Windows NT 6.3)/],\n    ['Windows 10', /(Windows NT 10.0)/],\n    ['Windows ME', /Windows ME/],\n    ['Windows CE', /Windows CE|WinCE|Microsoft Pocket Internet Explorer/],\n    ['Open BSD', /OpenBSD/],\n    ['Sun OS', /SunOS/],\n    ['Chrome OS', /CrOS/],\n    ['Linux', /(Linux)|(X11)/],\n    ['Mac OS', /(Mac_PowerPC)|(Macintosh)/],\n    ['QNX', /QNX/],\n    ['BeOS', /BeOS/],\n    ['OS/2', /OS\\/2/],\n];\nexport function detect(userAgent) {\n    if (!!userAgent) {\n        return parseUserAgent(userAgent);\n    }\n    if (typeof document === 'undefined' &&\n        typeof navigator !== 'undefined' &&\n        navigator.product === 'ReactNative') {\n        return new ReactNativeInfo();\n    }\n    if (typeof navigator !== 'undefined') {\n        return parseUserAgent(navigator.userAgent);\n    }\n    return getNodeVersion();\n}\nfunction matchUserAgent(ua) {\n    // opted for using reduce here rather than Array#first with a regex.test call\n    // this is primarily because using the reduce we only perform the regex\n    // execution once rather than once for the test and for the exec again below\n    // probably something that needs to be benchmarked though\n    return (ua !== '' &&\n        userAgentRules.reduce(function (matched, _a) {\n            var browser = _a[0], regex = _a[1];\n            if (matched) {\n                return matched;\n            }\n            var uaMatch = regex.exec(ua);\n            return !!uaMatch && [browser, uaMatch];\n        }, false));\n}\nexport function browserName(ua) {\n    var data = matchUserAgent(ua);\n    return data ? data[0] : null;\n}\nexport function parseUserAgent(ua) {\n    var matchedRule = matchUserAgent(ua);\n    if (!matchedRule) {\n        return null;\n    }\n    var name = matchedRule[0], match = matchedRule[1];\n    if (name === 'searchbot') {\n        return new BotInfo();\n    }\n    // Do not use RegExp for split operation as some browser do not support it (See: http://blog.stevenlevithan.com/archives/cross-browser-split)\n    var versionParts = match[1] && match[1].split('.').join('_').split('_').slice(0, 3);\n    if (versionParts) {\n        if (versionParts.length < REQUIRED_VERSION_PARTS) {\n            versionParts = __spreadArray(__spreadArray([], versionParts, true), createVersionParts(REQUIRED_VERSION_PARTS - versionParts.length), true);\n        }\n    }\n    else {\n        versionParts = [];\n    }\n    var version = versionParts.join('.');\n    var os = detectOS(ua);\n    var searchBotMatch = SEARCHBOT_OS_REGEX.exec(ua);\n    if (searchBotMatch && searchBotMatch[1]) {\n        return new SearchBotDeviceInfo(name, version, os, searchBotMatch[1]);\n    }\n    return new BrowserInfo(name, version, os);\n}\nexport function detectOS(ua) {\n    for (var ii = 0, count = operatingSystemRules.length; ii < count; ii++) {\n        var _a = operatingSystemRules[ii], os = _a[0], regex = _a[1];\n        var match = regex.exec(ua);\n        if (match) {\n            return os;\n        }\n    }\n    return null;\n}\nexport function getNodeVersion() {\n    var isNode = typeof process !== 'undefined' && process.version;\n    return isNode ? new NodeInfo(process.version.slice(1)) : null;\n}\nfunction createVersionParts(count) {\n    var output = [];\n    for (var ii = 0; ii < count; ii++) {\n        output.push('0');\n    }\n    return output;\n}\n","'use strict';\n\n/******************************************************************************\n * Created 2008-08-19.\n *\n * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.\n *\n * Copyright (C) 2008\n *   Wyatt Baldwin <self@wyattbaldwin.com>\n *   All rights reserved\n *\n * Licensed under the MIT license.\n *\n *   http://www.opensource.org/licenses/mit-license.php\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n *****************************************************************************/\nvar dijkstra = {\n  single_source_shortest_paths: function(graph, s, d) {\n    // Predecessor map for each node that has been encountered.\n    // node ID => predecessor node ID\n    var predecessors = {};\n\n    // Costs of shortest paths from s to all nodes encountered.\n    // node ID => cost\n    var costs = {};\n    costs[s] = 0;\n\n    // Costs of shortest paths from s to all nodes encountered; differs from\n    // `costs` in that it provides easy access to the node that currently has\n    // the known shortest path from s.\n    // XXX: Do we actually need both `costs` and `open`?\n    var open = dijkstra.PriorityQueue.make();\n    open.push(s, 0);\n\n    var closest,\n        u, v,\n        cost_of_s_to_u,\n        adjacent_nodes,\n        cost_of_e,\n        cost_of_s_to_u_plus_cost_of_e,\n        cost_of_s_to_v,\n        first_visit;\n    while (!open.empty()) {\n      // In the nodes remaining in graph that have a known cost from s,\n      // find the node, u, that currently has the shortest path from s.\n      closest = open.pop();\n      u = closest.value;\n      cost_of_s_to_u = closest.cost;\n\n      // Get nodes adjacent to u...\n      adjacent_nodes = graph[u] || {};\n\n      // ...and explore the edges that connect u to those nodes, updating\n      // the cost of the shortest paths to any or all of those nodes as\n      // necessary. v is the node across the current edge from u.\n      for (v in adjacent_nodes) {\n        if (adjacent_nodes.hasOwnProperty(v)) {\n          // Get the cost of the edge running from u to v.\n          cost_of_e = adjacent_nodes[v];\n\n          // Cost of s to u plus the cost of u to v across e--this is *a*\n          // cost from s to v that may or may not be less than the current\n          // known cost to v.\n          cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;\n\n          // If we haven't visited v yet OR if the current known cost from s to\n          // v is greater than the new cost we just found (cost of s to u plus\n          // cost of u to v across e), update v's cost in the cost list and\n          // update v's predecessor in the predecessor list (it's now u).\n          cost_of_s_to_v = costs[v];\n          first_visit = (typeof costs[v] === 'undefined');\n          if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {\n            costs[v] = cost_of_s_to_u_plus_cost_of_e;\n            open.push(v, cost_of_s_to_u_plus_cost_of_e);\n            predecessors[v] = u;\n          }\n        }\n      }\n    }\n\n    if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {\n      var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');\n      throw new Error(msg);\n    }\n\n    return predecessors;\n  },\n\n  extract_shortest_path_from_predecessor_list: function(predecessors, d) {\n    var nodes = [];\n    var u = d;\n    var predecessor;\n    while (u) {\n      nodes.push(u);\n      predecessor = predecessors[u];\n      u = predecessors[u];\n    }\n    nodes.reverse();\n    return nodes;\n  },\n\n  find_path: function(graph, s, d) {\n    var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);\n    return dijkstra.extract_shortest_path_from_predecessor_list(\n      predecessors, d);\n  },\n\n  /**\n   * A very naive priority queue implementation.\n   */\n  PriorityQueue: {\n    make: function (opts) {\n      var T = dijkstra.PriorityQueue,\n          t = {},\n          key;\n      opts = opts || {};\n      for (key in T) {\n        if (T.hasOwnProperty(key)) {\n          t[key] = T[key];\n        }\n      }\n      t.queue = [];\n      t.sorter = opts.sorter || T.default_sorter;\n      return t;\n    },\n\n    default_sorter: function (a, b) {\n      return a.cost - b.cost;\n    },\n\n    /**\n     * Add a new item to the queue and ensure the highest priority element\n     * is at the front of the queue.\n     */\n    push: function (value, cost) {\n      var item = {value: value, cost: cost};\n      this.queue.push(item);\n      this.queue.sort(this.sorter);\n    },\n\n    /**\n     * Return the highest priority element in the queue.\n     */\n    pop: function () {\n      return this.queue.shift();\n    },\n\n    empty: function () {\n      return this.queue.length === 0;\n    }\n  }\n};\n\n\n// node.js module exports\nif (typeof module !== 'undefined') {\n  module.exports = dijkstra;\n}\n","const crcTable = [];\nfor (let n = 0; n < 256; n++) {\n    let c = n;\n    for (let k = 0; k < 8; k++) {\n        if (c & 1) {\n            c = 0xedb88320 ^ (c >>> 1);\n        }\n        else {\n            c = c >>> 1;\n        }\n    }\n    crcTable[n] = c;\n}\nconst initialCrc = 0xffffffff;\nfunction updateCrc(currentCrc, data, length) {\n    let c = currentCrc;\n    for (let n = 0; n < length; n++) {\n        c = crcTable[(c ^ data[n]) & 0xff] ^ (c >>> 8);\n    }\n    return c;\n}\nfunction crc(data, length) {\n    return (updateCrc(initialCrc, data, length) ^ initialCrc) >>> 0;\n}\nexport function checkCrc(buffer, crcLength, chunkName) {\n    const expectedCrc = buffer.readUint32();\n    const actualCrc = crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - crcLength - 4, crcLength), crcLength); // \"- 4\" because we already advanced by reading the CRC\n    if (actualCrc !== expectedCrc) {\n        throw new Error(`CRC mismatch for chunk ${chunkName}. Expected ${expectedCrc}, found ${actualCrc}`);\n    }\n}\nexport function writeCrc(buffer, length) {\n    buffer.writeUint32(crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - length, length), length));\n}\n//# sourceMappingURL=crc.js.map","export function unfilterNone(currentLine, newLine, bytesPerLine) {\n    for (let i = 0; i < bytesPerLine; i++) {\n        newLine[i] = currentLine[i];\n    }\n}\nexport function unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel) {\n    let i = 0;\n    for (; i < bytesPerPixel; i++) {\n        // just copy first bytes\n        newLine[i] = currentLine[i];\n    }\n    for (; i < bytesPerLine; i++) {\n        newLine[i] = (currentLine[i] + newLine[i - bytesPerPixel]) & 0xff;\n    }\n}\nexport function unfilterUp(currentLine, newLine, prevLine, bytesPerLine) {\n    let i = 0;\n    if (prevLine.length === 0) {\n        // just copy bytes for first line\n        for (; i < bytesPerLine; i++) {\n            newLine[i] = currentLine[i];\n        }\n    }\n    else {\n        for (; i < bytesPerLine; i++) {\n            newLine[i] = (currentLine[i] + prevLine[i]) & 0xff;\n        }\n    }\n}\nexport function unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {\n    let i = 0;\n    if (prevLine.length === 0) {\n        for (; i < bytesPerPixel; i++) {\n            newLine[i] = currentLine[i];\n        }\n        for (; i < bytesPerLine; i++) {\n            newLine[i] = (currentLine[i] + (newLine[i - bytesPerPixel] >> 1)) & 0xff;\n        }\n    }\n    else {\n        for (; i < bytesPerPixel; i++) {\n            newLine[i] = (currentLine[i] + (prevLine[i] >> 1)) & 0xff;\n        }\n        for (; i < bytesPerLine; i++) {\n            newLine[i] =\n                (currentLine[i] + ((newLine[i - bytesPerPixel] + prevLine[i]) >> 1)) &\n                    0xff;\n        }\n    }\n}\nexport function unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {\n    let i = 0;\n    if (prevLine.length === 0) {\n        for (; i < bytesPerPixel; i++) {\n            newLine[i] = currentLine[i];\n        }\n        for (; i < bytesPerLine; i++) {\n            newLine[i] = (currentLine[i] + newLine[i - bytesPerPixel]) & 0xff;\n        }\n    }\n    else {\n        for (; i < bytesPerPixel; i++) {\n            newLine[i] = (currentLine[i] + prevLine[i]) & 0xff;\n        }\n        for (; i < bytesPerLine; i++) {\n            newLine[i] =\n                (currentLine[i] +\n                    paethPredictor(newLine[i - bytesPerPixel], prevLine[i], prevLine[i - bytesPerPixel])) &\n                    0xff;\n        }\n    }\n}\nfunction paethPredictor(a, b, c) {\n    const p = a + b - c;\n    const pa = Math.abs(p - a);\n    const pb = Math.abs(p - b);\n    const pc = Math.abs(p - c);\n    if (pa <= pb && pa <= pc)\n        return a;\n    else if (pb <= pc)\n        return b;\n    else\n        return c;\n}\n//# sourceMappingURL=unfilter.js.map","import { unfilterAverage, unfilterNone, unfilterPaeth, unfilterSub, unfilterUp, } from './unfilter';\n/**\n * Apllies filter on scanline based on the filter type.\n * @param filterType - The filter type to apply.\n * @param currentLine - The current line of pixel data.\n * @param newLine - The new line of pixel data.\n * @param prevLine - The previous line of pixel data.\n * @param passLineBytes - The number of bytes in the pass line.\n * @param bytesPerPixel - The number of bytes per pixel.\n */\nexport function applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel) {\n    switch (filterType) {\n        case 0:\n            unfilterNone(currentLine, newLine, passLineBytes);\n            break;\n        case 1:\n            unfilterSub(currentLine, newLine, passLineBytes, bytesPerPixel);\n            break;\n        case 2:\n            unfilterUp(currentLine, newLine, prevLine, passLineBytes);\n            break;\n        case 3:\n            unfilterAverage(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);\n            break;\n        case 4:\n            unfilterPaeth(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);\n            break;\n        default:\n            throw new Error(`Unsupported filter: ${filterType}`);\n    }\n}\n//# sourceMappingURL=applyUnfilter.js.map","import { applyUnfilter } from './applyUnfilter';\nconst uint16 = new Uint16Array([0x00ff]);\nconst uint8 = new Uint8Array(uint16.buffer);\nconst osIsLittleEndian = uint8[0] === 0xff;\n/**\n * Decodes the Adam7 interlaced PNG data.\n *\n * @param params - DecodeInterlaceNullParams\n * @returns - array of pixel data.\n */\nexport function decodeInterlaceAdam7(params) {\n    const { data, width, height, channels, depth } = params;\n    // Adam7 interlacing pattern\n    const passes = [\n        { x: 0, y: 0, xStep: 8, yStep: 8 }, // Pass 1\n        { x: 4, y: 0, xStep: 8, yStep: 8 }, // Pass 2\n        { x: 0, y: 4, xStep: 4, yStep: 8 }, // Pass 3\n        { x: 2, y: 0, xStep: 4, yStep: 4 }, // Pass 4\n        { x: 0, y: 2, xStep: 2, yStep: 4 }, // Pass 5\n        { x: 1, y: 0, xStep: 2, yStep: 2 }, // Pass 6\n        { x: 0, y: 1, xStep: 1, yStep: 2 }, // Pass 7\n    ];\n    const bytesPerPixel = Math.ceil(depth / 8) * channels;\n    const resultData = new Uint8Array(height * width * bytesPerPixel);\n    let offset = 0;\n    // Process each pass\n    for (let passIndex = 0; passIndex < 7; passIndex++) {\n        const pass = passes[passIndex];\n        // Calculate pass dimensions\n        const passWidth = Math.ceil((width - pass.x) / pass.xStep);\n        const passHeight = Math.ceil((height - pass.y) / pass.yStep);\n        if (passWidth <= 0 || passHeight <= 0)\n            continue;\n        const passLineBytes = passWidth * bytesPerPixel;\n        const prevLine = new Uint8Array(passLineBytes);\n        // Process each scanline in this pass\n        for (let y = 0; y < passHeight; y++) {\n            // First byte is the filter type\n            const filterType = data[offset++];\n            const currentLine = data.subarray(offset, offset + passLineBytes);\n            offset += passLineBytes;\n            // Create a new line for the unfiltered data\n            const newLine = new Uint8Array(passLineBytes);\n            // Apply the appropriate unfilter\n            applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);\n            prevLine.set(newLine);\n            for (let x = 0; x < passWidth; x++) {\n                const outputX = pass.x + x * pass.xStep;\n                const outputY = pass.y + y * pass.yStep;\n                if (outputX >= width || outputY >= height)\n                    continue;\n                for (let i = 0; i < bytesPerPixel; i++) {\n                    resultData[(outputY * width + outputX) * bytesPerPixel + i] =\n                        newLine[x * bytesPerPixel + i];\n                }\n            }\n        }\n    }\n    if (depth === 16) {\n        const uint16Data = new Uint16Array(resultData.buffer);\n        if (osIsLittleEndian) {\n            for (let k = 0; k < uint16Data.length; k++) {\n                // PNG is always big endian. Swap the bytes.\n                uint16Data[k] = swap16(uint16Data[k]);\n            }\n        }\n        return uint16Data;\n    }\n    else {\n        return resultData;\n    }\n}\nfunction swap16(val) {\n    return ((val & 0xff) << 8) | ((val >> 8) & 0xff);\n}\n//# sourceMappingURL=decodeInterlaceAdam7.js.map","import { unfilterAverage, unfilterNone, unfilterPaeth, unfilterSub, unfilterUp, } from './unfilter';\nconst uint16 = new Uint16Array([0x00ff]);\nconst uint8 = new Uint8Array(uint16.buffer);\nconst osIsLittleEndian = uint8[0] === 0xff;\nconst empty = new Uint8Array(0);\nexport function decodeInterlaceNull(params) {\n    const { data, width, height, channels, depth } = params;\n    const bytesPerPixel = Math.ceil(depth / 8) * channels;\n    const bytesPerLine = Math.ceil((depth / 8) * channels * width);\n    const newData = new Uint8Array(height * bytesPerLine);\n    let prevLine = empty;\n    let offset = 0;\n    let currentLine;\n    let newLine;\n    for (let i = 0; i < height; i++) {\n        currentLine = data.subarray(offset + 1, offset + 1 + bytesPerLine);\n        newLine = newData.subarray(i * bytesPerLine, (i + 1) * bytesPerLine);\n        switch (data[offset]) {\n            case 0:\n                unfilterNone(currentLine, newLine, bytesPerLine);\n                break;\n            case 1:\n                unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel);\n                break;\n            case 2:\n                unfilterUp(currentLine, newLine, prevLine, bytesPerLine);\n                break;\n            case 3:\n                unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);\n                break;\n            case 4:\n                unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);\n                break;\n            default:\n                throw new Error(`Unsupported filter: ${data[offset]}`);\n        }\n        prevLine = newLine;\n        offset += bytesPerLine + 1;\n    }\n    if (depth === 16) {\n        const uint16Data = new Uint16Array(newData.buffer);\n        if (osIsLittleEndian) {\n            for (let k = 0; k < uint16Data.length; k++) {\n                // PNG is always big endian. Swap the bytes.\n                uint16Data[k] = swap16(uint16Data[k]);\n            }\n        }\n        return uint16Data;\n    }\n    else {\n        return newData;\n    }\n}\nfunction swap16(val) {\n    return ((val & 0xff) << 8) | ((val >> 8) & 0xff);\n}\n//# sourceMappingURL=decodeInterlaceNull.js.map","// https://www.w3.org/TR/PNG/#5PNG-file-signature\nconst pngSignature = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);\nexport function writeSignature(buffer) {\n    buffer.writeBytes(pngSignature);\n}\nexport function checkSignature(buffer) {\n    if (!hasPngSignature(buffer.readBytes(pngSignature.length))) {\n        throw new Error('wrong PNG signature');\n    }\n}\nexport function hasPngSignature(array) {\n    if (array.length < pngSignature.length) {\n        return false;\n    }\n    for (let i = 0; i < pngSignature.length; i++) {\n        if (array[i] !== pngSignature[i]) {\n            return false;\n        }\n    }\n    return true;\n}\n//# sourceMappingURL=signature.js.map","import { writeCrc } from './crc';\n// https://www.w3.org/TR/png/#11tEXt\nexport const textChunkName = 'tEXt';\nconst NULL = 0;\nconst latin1Decoder = new TextDecoder('latin1');\nfunction validateKeyword(keyword) {\n    validateLatin1(keyword);\n    if (keyword.length === 0 || keyword.length > 79) {\n        throw new Error('keyword length must be between 1 and 79');\n    }\n}\n// eslint-disable-next-line no-control-regex\nconst latin1Regex = /^[\\u0000-\\u00FF]*$/;\nfunction validateLatin1(text) {\n    if (!latin1Regex.test(text)) {\n        throw new Error('invalid latin1 text');\n    }\n}\nexport function decodetEXt(text, buffer, length) {\n    const keyword = readKeyword(buffer);\n    text[keyword] = readLatin1(buffer, length - keyword.length - 1);\n}\nexport function encodetEXt(buffer, keyword, text) {\n    validateKeyword(keyword);\n    validateLatin1(text);\n    const length = keyword.length + 1 /* NULL */ + text.length;\n    buffer.writeUint32(length);\n    buffer.writeChars(textChunkName);\n    buffer.writeChars(keyword);\n    buffer.writeByte(NULL);\n    buffer.writeChars(text);\n    writeCrc(buffer, length + 4);\n}\n// https://www.w3.org/TR/png/#11keywords\nexport function readKeyword(buffer) {\n    buffer.mark();\n    while (buffer.readByte() !== NULL) {\n        /* advance */\n    }\n    const end = buffer.offset;\n    buffer.reset();\n    const keyword = latin1Decoder.decode(buffer.readBytes(end - buffer.offset - 1));\n    // NULL\n    buffer.skip(1);\n    validateKeyword(keyword);\n    return keyword;\n}\nexport function readLatin1(buffer, length) {\n    return latin1Decoder.decode(buffer.readBytes(length));\n}\n//# sourceMappingURL=text.js.map","export const ColorType = {\n    UNKNOWN: -1,\n    GREYSCALE: 0,\n    TRUECOLOUR: 2,\n    INDEXED_COLOUR: 3,\n    GREYSCALE_ALPHA: 4,\n    TRUECOLOUR_ALPHA: 6,\n};\nexport const CompressionMethod = {\n    UNKNOWN: -1,\n    DEFLATE: 0,\n};\nexport const FilterMethod = {\n    UNKNOWN: -1,\n    ADAPTIVE: 0,\n};\nexport const InterlaceMethod = {\n    UNKNOWN: -1,\n    NO_INTERLACE: 0,\n    ADAM7: 1,\n};\nexport const DisposeOpType = {\n    NONE: 0,\n    BACKGROUND: 1,\n    PREVIOUS: 2,\n};\nexport const BlendOpType = {\n    SOURCE: 0,\n    OVER: 1,\n};\n//# sourceMappingURL=internalTypes.js.map","import { IOBuffer } from 'iobuffer';\nimport { inflate, Inflate as Inflator } from 'pako';\nimport { checkCrc } from './helpers/crc';\nimport { decodeInterlaceAdam7 } from './helpers/decodeInterlaceAdam7';\nimport { decodeInterlaceNull } from './helpers/decodeInterlaceNull';\nimport { checkSignature } from './helpers/signature';\nimport { decodetEXt, readKeyword, textChunkName } from './helpers/text';\nimport { ColorType, CompressionMethod, DisposeOpType, FilterMethod, InterlaceMethod, BlendOpType, } from './internalTypes';\nexport default class PngDecoder extends IOBuffer {\n    _checkCrc;\n    _inflator;\n    _png;\n    _apng;\n    _end;\n    _hasPalette;\n    _palette;\n    _hasTransparency;\n    _transparency;\n    _compressionMethod;\n    _filterMethod;\n    _interlaceMethod;\n    _colorType;\n    _isAnimated;\n    _numberOfFrames;\n    _numberOfPlays;\n    _frames;\n    _writingDataChunks;\n    constructor(data, options = {}) {\n        super(data);\n        const { checkCrc = false } = options;\n        this._checkCrc = checkCrc;\n        this._inflator = new Inflator();\n        this._png = {\n            width: -1,\n            height: -1,\n            channels: -1,\n            data: new Uint8Array(0),\n            depth: 1,\n            text: {},\n        };\n        this._apng = {\n            width: -1,\n            height: -1,\n            channels: -1,\n            depth: 1,\n            numberOfFrames: 1,\n            numberOfPlays: 0,\n            text: {},\n            frames: [],\n        };\n        this._end = false;\n        this._hasPalette = false;\n        this._palette = [];\n        this._hasTransparency = false;\n        this._transparency = new Uint16Array(0);\n        this._compressionMethod = CompressionMethod.UNKNOWN;\n        this._filterMethod = FilterMethod.UNKNOWN;\n        this._interlaceMethod = InterlaceMethod.UNKNOWN;\n        this._colorType = ColorType.UNKNOWN;\n        this._isAnimated = false;\n        this._numberOfFrames = 1;\n        this._numberOfPlays = 0;\n        this._frames = [];\n        this._writingDataChunks = false;\n        // PNG is always big endian\n        // https://www.w3.org/TR/PNG/#7Integers-and-byte-order\n        this.setBigEndian();\n    }\n    decode() {\n        checkSignature(this);\n        while (!this._end) {\n            const length = this.readUint32();\n            const type = this.readChars(4);\n            this.decodeChunk(length, type);\n        }\n        this.decodeImage();\n        return this._png;\n    }\n    decodeApng() {\n        checkSignature(this);\n        while (!this._end) {\n            const length = this.readUint32();\n            const type = this.readChars(4);\n            this.decodeApngChunk(length, type);\n        }\n        this.decodeApngImage();\n        return this._apng;\n    }\n    // https://www.w3.org/TR/PNG/#5Chunk-layout\n    decodeChunk(length, type) {\n        const offset = this.offset;\n        switch (type) {\n            // 11.2 Critical chunks\n            case 'IHDR': // 11.2.2 IHDR Image header\n                this.decodeIHDR();\n                break;\n            case 'PLTE': // 11.2.3 PLTE Palette\n                this.decodePLTE(length);\n                break;\n            case 'IDAT': // 11.2.4 IDAT Image data\n                this.decodeIDAT(length);\n                break;\n            case 'IEND': // 11.2.5 IEND Image trailer\n                this._end = true;\n                break;\n            // 11.3 Ancillary chunks\n            case 'tRNS': // 11.3.2.1 tRNS Transparency\n                this.decodetRNS(length);\n                break;\n            case 'iCCP': // 11.3.3.3 iCCP Embedded ICC profile\n                this.decodeiCCP(length);\n                break;\n            case textChunkName: // 11.3.4.3 tEXt Textual data\n                decodetEXt(this._png.text, this, length);\n                break;\n            case 'pHYs': // 11.3.5.3 pHYs Physical pixel dimensions\n                this.decodepHYs();\n                break;\n            default:\n                this.skip(length);\n                break;\n        }\n        if (this.offset - offset !== length) {\n            throw new Error(`Length mismatch while decoding chunk ${type}`);\n        }\n        if (this._checkCrc) {\n            checkCrc(this, length + 4, type);\n        }\n        else {\n            this.skip(4);\n        }\n    }\n    decodeApngChunk(length, type) {\n        const offset = this.offset;\n        if (type !== 'fdAT' && type !== 'IDAT' && this._writingDataChunks) {\n            this.pushDataToFrame();\n        }\n        switch (type) {\n            case 'acTL':\n                this.decodeACTL();\n                break;\n            case 'fcTL':\n                this.decodeFCTL();\n                break;\n            case 'fdAT':\n                this.decodeFDAT(length);\n                break;\n            default:\n                this.decodeChunk(length, type);\n                this.offset = offset + length;\n                break;\n        }\n        if (this.offset - offset !== length) {\n            throw new Error(`Length mismatch while decoding chunk ${type}`);\n        }\n        if (this._checkCrc) {\n            checkCrc(this, length + 4, type);\n        }\n        else {\n            this.skip(4);\n        }\n    }\n    // https://www.w3.org/TR/PNG/#11IHDR\n    decodeIHDR() {\n        const image = this._png;\n        image.width = this.readUint32();\n        image.height = this.readUint32();\n        image.depth = checkBitDepth(this.readUint8());\n        const colorType = this.readUint8();\n        this._colorType = colorType;\n        let channels;\n        switch (colorType) {\n            case ColorType.GREYSCALE:\n                channels = 1;\n                break;\n            case ColorType.TRUECOLOUR:\n                channels = 3;\n                break;\n            case ColorType.INDEXED_COLOUR:\n                channels = 1;\n                break;\n            case ColorType.GREYSCALE_ALPHA:\n                channels = 2;\n                break;\n            case ColorType.TRUECOLOUR_ALPHA:\n                channels = 4;\n                break;\n            // Kept for exhaustiveness.\n            // eslint-disable-next-line unicorn/no-useless-switch-case\n            case ColorType.UNKNOWN:\n            default:\n                throw new Error(`Unknown color type: ${colorType}`);\n        }\n        this._png.channels = channels;\n        this._compressionMethod = this.readUint8();\n        if (this._compressionMethod !== CompressionMethod.DEFLATE) {\n            throw new Error(`Unsupported compression method: ${this._compressionMethod}`);\n        }\n        this._filterMethod = this.readUint8();\n        this._interlaceMethod = this.readUint8();\n    }\n    decodeACTL() {\n        this._numberOfFrames = this.readUint32();\n        this._numberOfPlays = this.readUint32();\n        this._isAnimated = true;\n    }\n    decodeFCTL() {\n        const image = {\n            sequenceNumber: this.readUint32(),\n            width: this.readUint32(),\n            height: this.readUint32(),\n            xOffset: this.readUint32(),\n            yOffset: this.readUint32(),\n            delayNumber: this.readUint16(),\n            delayDenominator: this.readUint16(),\n            disposeOp: this.readUint8(),\n            blendOp: this.readUint8(),\n            data: new Uint8Array(0),\n        };\n        this._frames.push(image);\n    }\n    // https://www.w3.org/TR/PNG/#11PLTE\n    decodePLTE(length) {\n        if (length % 3 !== 0) {\n            throw new RangeError(`PLTE field length must be a multiple of 3. Got ${length}`);\n        }\n        const l = length / 3;\n        this._hasPalette = true;\n        const palette = [];\n        this._palette = palette;\n        for (let i = 0; i < l; i++) {\n            palette.push([this.readUint8(), this.readUint8(), this.readUint8()]);\n        }\n    }\n    // https://www.w3.org/TR/PNG/#11IDAT\n    decodeIDAT(length) {\n        this._writingDataChunks = true;\n        const dataLength = length;\n        const dataOffset = this.offset + this.byteOffset;\n        this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength));\n        if (this._inflator.err) {\n            throw new Error(`Error while decompressing the data: ${this._inflator.err}`);\n        }\n        this.skip(length);\n    }\n    decodeFDAT(length) {\n        this._writingDataChunks = true;\n        let dataLength = length;\n        let dataOffset = this.offset + this.byteOffset;\n        dataOffset += 4;\n        dataLength -= 4;\n        this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength));\n        if (this._inflator.err) {\n            throw new Error(`Error while decompressing the data: ${this._inflator.err}`);\n        }\n        this.skip(length);\n    }\n    // https://www.w3.org/TR/PNG/#11tRNS\n    decodetRNS(length) {\n        switch (this._colorType) {\n            case ColorType.GREYSCALE:\n            case ColorType.TRUECOLOUR: {\n                if (length % 2 !== 0) {\n                    throw new RangeError(`tRNS chunk length must be a multiple of 2. Got ${length}`);\n                }\n                if (length / 2 > this._png.width * this._png.height) {\n                    throw new Error(`tRNS chunk contains more alpha values than there are pixels (${length / 2} vs ${this._png.width * this._png.height})`);\n                }\n                this._hasTransparency = true;\n                this._transparency = new Uint16Array(length / 2);\n                for (let i = 0; i < length / 2; i++) {\n                    this._transparency[i] = this.readUint16();\n                }\n                break;\n            }\n            case ColorType.INDEXED_COLOUR: {\n                if (length > this._palette.length) {\n                    throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${length} vs ${this._palette.length})`);\n                }\n                let i = 0;\n                for (; i < length; i++) {\n                    const alpha = this.readByte();\n                    this._palette[i].push(alpha);\n                }\n                for (; i < this._palette.length; i++) {\n                    this._palette[i].push(255);\n                }\n                break;\n            }\n            // Kept for exhaustiveness.\n            /* eslint-disable unicorn/no-useless-switch-case */\n            case ColorType.UNKNOWN:\n            case ColorType.GREYSCALE_ALPHA:\n            case ColorType.TRUECOLOUR_ALPHA:\n            default: {\n                throw new Error(`tRNS chunk is not supported for color type ${this._colorType}`);\n            }\n            /* eslint-enable unicorn/no-useless-switch-case */\n        }\n    }\n    // https://www.w3.org/TR/PNG/#11iCCP\n    decodeiCCP(length) {\n        const name = readKeyword(this);\n        const compressionMethod = this.readUint8();\n        if (compressionMethod !== CompressionMethod.DEFLATE) {\n            throw new Error(`Unsupported iCCP compression method: ${compressionMethod}`);\n        }\n        const compressedProfile = this.readBytes(length - name.length - 2);\n        this._png.iccEmbeddedProfile = {\n            name,\n            profile: inflate(compressedProfile),\n        };\n    }\n    // https://www.w3.org/TR/PNG/#11pHYs\n    decodepHYs() {\n        const ppuX = this.readUint32();\n        const ppuY = this.readUint32();\n        const unitSpecifier = this.readByte();\n        this._png.resolution = { x: ppuX, y: ppuY, unit: unitSpecifier };\n    }\n    decodeApngImage() {\n        this._apng.width = this._png.width;\n        this._apng.height = this._png.height;\n        this._apng.channels = this._png.channels;\n        this._apng.depth = this._png.depth;\n        this._apng.numberOfFrames = this._numberOfFrames;\n        this._apng.numberOfPlays = this._numberOfPlays;\n        this._apng.text = this._png.text;\n        this._apng.resolution = this._png.resolution;\n        for (let i = 0; i < this._numberOfFrames; i++) {\n            const newFrame = {\n                sequenceNumber: this._frames[i].sequenceNumber,\n                delayNumber: this._frames[i].delayNumber,\n                delayDenominator: this._frames[i].delayDenominator,\n                data: this._apng.depth === 8\n                    ? new Uint8Array(this._apng.width * this._apng.height * this._apng.channels)\n                    : new Uint16Array(this._apng.width * this._apng.height * this._apng.channels),\n            };\n            const frame = this._frames.at(i);\n            if (frame) {\n                frame.data = decodeInterlaceNull({\n                    data: frame.data,\n                    width: frame.width,\n                    height: frame.height,\n                    channels: this._apng.channels,\n                    depth: this._apng.depth,\n                });\n                if (this._hasPalette) {\n                    this._apng.palette = this._palette;\n                }\n                if (this._hasTransparency) {\n                    this._apng.transparency = this._transparency;\n                }\n                if (i === 0 ||\n                    (frame.xOffset === 0 &&\n                        frame.yOffset === 0 &&\n                        frame.width === this._png.width &&\n                        frame.height === this._png.height)) {\n                    newFrame.data = frame.data;\n                }\n                else {\n                    const prevFrame = this._apng.frames.at(i - 1);\n                    this.disposeFrame(frame, prevFrame, newFrame);\n                    this.addFrameDataToCanvas(newFrame, frame);\n                }\n                this._apng.frames.push(newFrame);\n            }\n        }\n        return this._apng;\n    }\n    disposeFrame(frame, prevFrame, imageFrame) {\n        switch (frame.disposeOp) {\n            case DisposeOpType.NONE:\n                break;\n            case DisposeOpType.BACKGROUND:\n                for (let row = 0; row < this._png.height; row++) {\n                    for (let col = 0; col < this._png.width; col++) {\n                        const index = (row * frame.width + col) * this._png.channels;\n                        for (let channel = 0; channel < this._png.channels; channel++) {\n                            imageFrame.data[index + channel] = 0;\n                        }\n                    }\n                }\n                break;\n            case DisposeOpType.PREVIOUS:\n                imageFrame.data.set(prevFrame.data);\n                break;\n            default:\n                throw new Error('Unknown disposeOp');\n        }\n    }\n    addFrameDataToCanvas(imageFrame, frame) {\n        const maxValue = 1 << this._png.depth;\n        const calculatePixelIndices = (row, col) => {\n            const index = ((row + frame.yOffset) * this._png.width + frame.xOffset + col) *\n                this._png.channels;\n            const frameIndex = (row * frame.width + col) * this._png.channels;\n            return { index, frameIndex };\n        };\n        switch (frame.blendOp) {\n            case BlendOpType.SOURCE:\n                for (let row = 0; row < frame.height; row++) {\n                    for (let col = 0; col < frame.width; col++) {\n                        const { index, frameIndex } = calculatePixelIndices(row, col);\n                        for (let channel = 0; channel < this._png.channels; channel++) {\n                            imageFrame.data[index + channel] =\n                                frame.data[frameIndex + channel];\n                        }\n                    }\n                }\n                break;\n            // https://www.w3.org/TR/png-3/#13Alpha-channel-processing\n            case BlendOpType.OVER:\n                for (let row = 0; row < frame.height; row++) {\n                    for (let col = 0; col < frame.width; col++) {\n                        const { index, frameIndex } = calculatePixelIndices(row, col);\n                        for (let channel = 0; channel < this._png.channels; channel++) {\n                            const sourceAlpha = frame.data[frameIndex + this._png.channels - 1] / maxValue;\n                            const foregroundValue = channel % (this._png.channels - 1) === 0\n                                ? 1\n                                : frame.data[frameIndex + channel];\n                            const value = Math.floor(sourceAlpha * foregroundValue +\n                                (1 - sourceAlpha) * imageFrame.data[index + channel]);\n                            imageFrame.data[index + channel] += value;\n                        }\n                    }\n                }\n                break;\n            default:\n                throw new Error('Unknown blendOp');\n        }\n    }\n    decodeImage() {\n        if (this._inflator.err) {\n            throw new Error(`Error while decompressing the data: ${this._inflator.err}`);\n        }\n        const data = this._isAnimated\n            ? (this._frames?.at(0)).data\n            : this._inflator.result;\n        if (this._filterMethod !== FilterMethod.ADAPTIVE) {\n            throw new Error(`Filter method ${this._filterMethod} not supported`);\n        }\n        if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {\n            this._png.data = decodeInterlaceNull({\n                data: data,\n                width: this._png.width,\n                height: this._png.height,\n                channels: this._png.channels,\n                depth: this._png.depth,\n            });\n        }\n        else if (this._interlaceMethod === InterlaceMethod.ADAM7) {\n            this._png.data = decodeInterlaceAdam7({\n                data: data,\n                width: this._png.width,\n                height: this._png.height,\n                channels: this._png.channels,\n                depth: this._png.depth,\n            });\n        }\n        else {\n            throw new Error(`Interlace method ${this._interlaceMethod} not supported`);\n        }\n        if (this._hasPalette) {\n            this._png.palette = this._palette;\n        }\n        if (this._hasTransparency) {\n            this._png.transparency = this._transparency;\n        }\n    }\n    pushDataToFrame() {\n        const result = this._inflator.result;\n        const lastFrame = this._frames.at(-1);\n        if (lastFrame) {\n            lastFrame.data = result;\n        }\n        else {\n            this._frames.push({\n                sequenceNumber: 0,\n                width: this._png.width,\n                height: this._png.height,\n                xOffset: 0,\n                yOffset: 0,\n                delayNumber: 0,\n                delayDenominator: 0,\n                disposeOp: DisposeOpType.NONE,\n                blendOp: BlendOpType.SOURCE,\n                data: result,\n            });\n        }\n        this._inflator = new Inflator();\n        this._writingDataChunks = false;\n    }\n}\nfunction checkBitDepth(value) {\n    if (value !== 1 &&\n        value !== 2 &&\n        value !== 4 &&\n        value !== 8 &&\n        value !== 16) {\n        throw new Error(`invalid bit depth: ${value}`);\n    }\n    return value;\n}\n//# sourceMappingURL=PngDecoder.js.map","import { IOBuffer } from 'iobuffer';\nimport { deflate } from 'pako';\nimport { writeCrc } from './helpers/crc';\nimport { writeSignature } from './helpers/signature';\nimport { encodetEXt } from './helpers/text';\nimport { InterlaceMethod, ColorType, CompressionMethod, FilterMethod, } from './internalTypes';\nconst defaultZlibOptions = {\n    level: 3,\n};\nexport default class PngEncoder extends IOBuffer {\n    _png;\n    _zlibOptions;\n    _colorType;\n    _interlaceMethod;\n    constructor(data, options = {}) {\n        super();\n        this._colorType = ColorType.UNKNOWN;\n        this._zlibOptions = { ...defaultZlibOptions, ...options.zlib };\n        this._png = this._checkData(data);\n        this._interlaceMethod =\n            (options.interlace === 'Adam7'\n                ? InterlaceMethod.ADAM7\n                : InterlaceMethod.NO_INTERLACE) ?? InterlaceMethod.NO_INTERLACE;\n        this.setBigEndian();\n    }\n    encode() {\n        writeSignature(this);\n        this.encodeIHDR();\n        if (this._png.palette) {\n            this.encodePLTE();\n            if (this._png.palette[0].length === 4) {\n                this.encodeTRNS();\n            }\n        }\n        this.encodeData();\n        if (this._png.text) {\n            for (const [keyword, text] of Object.entries(this._png.text)) {\n                encodetEXt(this, keyword, text);\n            }\n        }\n        this.encodeIEND();\n        return this.toArray();\n    }\n    // https://www.w3.org/TR/PNG/#11IHDR\n    encodeIHDR() {\n        this.writeUint32(13);\n        this.writeChars('IHDR');\n        this.writeUint32(this._png.width);\n        this.writeUint32(this._png.height);\n        this.writeByte(this._png.depth);\n        this.writeByte(this._colorType);\n        this.writeByte(CompressionMethod.DEFLATE);\n        this.writeByte(FilterMethod.ADAPTIVE);\n        this.writeByte(this._interlaceMethod);\n        writeCrc(this, 17);\n    }\n    // https://www.w3.org/TR/PNG/#11IEND\n    encodeIEND() {\n        this.writeUint32(0);\n        this.writeChars('IEND');\n        writeCrc(this, 4);\n    }\n    encodePLTE() {\n        const paletteLength = this._png.palette?.length * 3;\n        this.writeUint32(paletteLength);\n        this.writeChars('PLTE');\n        for (const color of this._png.palette) {\n            this.writeByte(color[0]);\n            this.writeByte(color[1]);\n            this.writeByte(color[2]);\n        }\n        writeCrc(this, 4 + paletteLength);\n    }\n    encodeTRNS() {\n        const alpha = this._png.palette.filter((color) => {\n            return color.at(-1) !== 255;\n        });\n        this.writeUint32(alpha.length);\n        this.writeChars('tRNS');\n        for (const el of alpha) {\n            this.writeByte(el.at(-1));\n        }\n        writeCrc(this, 4 + alpha.length);\n    }\n    // https://www.w3.org/TR/PNG/#11IDAT\n    encodeIDAT(data) {\n        this.writeUint32(data.length);\n        this.writeChars('IDAT');\n        this.writeBytes(data);\n        writeCrc(this, data.length + 4);\n    }\n    encodeData() {\n        const { width, height, channels, depth, data } = this._png;\n        const slotsPerLine = depth <= 8\n            ? Math.ceil((width * depth) / 8) * channels\n            : Math.ceil((((width * depth) / 8) * channels) / 2);\n        const newData = new IOBuffer().setBigEndian();\n        let offset = 0;\n        if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {\n            for (let i = 0; i < height; i++) {\n                newData.writeByte(0); // no filter\n                if (depth === 16) {\n                    offset = writeDataUint16(data, newData, slotsPerLine, offset);\n                }\n                else {\n                    offset = writeDataBytes(data, newData, slotsPerLine, offset);\n                }\n            }\n        }\n        else if (this._interlaceMethod === InterlaceMethod.ADAM7) {\n            // Adam7 interlacing\n            offset = writeDataInterlaced(this._png, data, newData, offset);\n        }\n        const buffer = newData.toArray();\n        const compressed = deflate(buffer, this._zlibOptions);\n        this.encodeIDAT(compressed);\n    }\n    _checkData(data) {\n        const { colorType, channels, depth } = getColorType(data, data.palette);\n        const png = {\n            width: checkInteger(data.width, 'width'),\n            height: checkInteger(data.height, 'height'),\n            channels,\n            data: data.data,\n            depth,\n            text: data.text,\n            palette: data.palette,\n        };\n        this._colorType = colorType;\n        const expectedSize = depth < 8\n            ? Math.ceil((png.width * depth) / 8) * png.height * channels\n            : png.width * png.height * channels;\n        if (png.data.length !== expectedSize) {\n            throw new RangeError(`wrong data size. Found ${png.data.length}, expected ${expectedSize}`);\n        }\n        return png;\n    }\n}\nfunction checkInteger(value, name) {\n    if (Number.isInteger(value) && value > 0) {\n        return value;\n    }\n    throw new TypeError(`${name} must be a positive integer`);\n}\nfunction getColorType(data, palette) {\n    const { channels = 4, depth = 8 } = data;\n    if (channels !== 4 && channels !== 3 && channels !== 2 && channels !== 1) {\n        throw new RangeError(`unsupported number of channels: ${channels}`);\n    }\n    const returnValue = {\n        channels,\n        depth,\n        colorType: ColorType.UNKNOWN,\n    };\n    switch (channels) {\n        case 4:\n            returnValue.colorType = ColorType.TRUECOLOUR_ALPHA;\n            break;\n        case 3:\n            returnValue.colorType = ColorType.TRUECOLOUR;\n            break;\n        case 1:\n            if (palette) {\n                returnValue.colorType = ColorType.INDEXED_COLOUR;\n            }\n            else {\n                returnValue.colorType = ColorType.GREYSCALE;\n            }\n            break;\n        case 2:\n            returnValue.colorType = ColorType.GREYSCALE_ALPHA;\n            break;\n        default:\n            throw new Error('unsupported number of channels');\n    }\n    return returnValue;\n}\nfunction writeDataBytes(data, newData, slotsPerLine, offset) {\n    for (let j = 0; j < slotsPerLine; j++) {\n        newData.writeByte(data[offset++]);\n    }\n    return offset;\n}\nfunction writeDataInterlaced(imageData, data, newData, offset) {\n    const passes = [\n        { x: 0, y: 0, xStep: 8, yStep: 8 },\n        { x: 4, y: 0, xStep: 8, yStep: 8 },\n        { x: 0, y: 4, xStep: 4, yStep: 8 },\n        { x: 2, y: 0, xStep: 4, yStep: 4 },\n        { x: 0, y: 2, xStep: 2, yStep: 4 },\n        { x: 1, y: 0, xStep: 2, yStep: 2 },\n        { x: 0, y: 1, xStep: 1, yStep: 2 },\n    ];\n    const { width, height, channels, depth } = imageData;\n    let pixelSize = 0;\n    if (depth === 16) {\n        pixelSize = (channels * depth) / 8 / 2;\n    }\n    else {\n        pixelSize = (channels * depth) / 8;\n    }\n    // Process each pass\n    for (let passIndex = 0; passIndex < 7; passIndex++) {\n        const pass = passes[passIndex];\n        const passWidth = Math.floor((width - pass.x + pass.xStep - 1) / pass.xStep);\n        const passHeight = Math.floor((height - pass.y + pass.yStep - 1) / pass.yStep);\n        if (passWidth <= 0 || passHeight <= 0)\n            continue;\n        const passLineBytes = passWidth * pixelSize;\n        // For each scanline in this pass\n        for (let y = 0; y < passHeight; y++) {\n            const imageY = pass.y + y * pass.yStep;\n            // Extract raw scanline data\n            const rawScanline = depth <= 8\n                ? new Uint8Array(passLineBytes)\n                : new Uint16Array(passLineBytes);\n            let rawOffset = 0;\n            for (let x = 0; x < passWidth; x++) {\n                const imageX = pass.x + x * pass.xStep;\n                if (imageX < width && imageY < height) {\n                    const srcPos = (imageY * width + imageX) * pixelSize;\n                    for (let i = 0; i < pixelSize; i++) {\n                        rawScanline[rawOffset++] = data[srcPos + i];\n                    }\n                }\n            }\n            newData.writeByte(0); // no filter\n            if (depth === 8) {\n                newData.writeBytes(rawScanline);\n            }\n            else if (depth === 16) {\n                for (const value of rawScanline) {\n                    newData.writeByte((value >> 8) & 0xff); // High byte\n                    newData.writeByte(value & 0xff);\n                }\n            }\n        }\n    }\n    return offset;\n}\nfunction writeDataUint16(data, newData, slotsPerLine, offset) {\n    for (let j = 0; j < slotsPerLine; j++) {\n        newData.writeUint16(data[offset++]);\n    }\n    return offset;\n}\n//# sourceMappingURL=PngEncoder.js.map","export var ResolutionUnitSpecifier;\n(function (ResolutionUnitSpecifier) {\n    /**\n     * Unit is unknown\n     */\n    ResolutionUnitSpecifier[ResolutionUnitSpecifier[\"UNKNOWN\"] = 0] = \"UNKNOWN\";\n    /**\n     * Unit is the metre\n     */\n    ResolutionUnitSpecifier[ResolutionUnitSpecifier[\"METRE\"] = 1] = \"METRE\";\n})(ResolutionUnitSpecifier || (ResolutionUnitSpecifier = {}));\n//# sourceMappingURL=types.js.map","import PngDecoder from './PngDecoder';\nimport PngEncoder from './PngEncoder';\nexport { hasPngSignature } from './helpers/signature';\nexport * from './types';\nfunction decodePng(data, options) {\n    const decoder = new PngDecoder(data, options);\n    return decoder.decode();\n}\nfunction encodePng(png, options) {\n    const encoder = new PngEncoder(png, options);\n    return encoder.encode();\n}\nfunction decodeApng(data, options) {\n    const decoder = new PngDecoder(data, options);\n    return decoder.decodeApng();\n}\nexport { decodePng as decode, encodePng as encode, decodeApng };\nexport { convertIndexedToRgb } from './convertIndexedToRgb';\n//# sourceMappingURL=index.js.map"],"names":[],"sourceRoot":""}