{"ast":null,"code":"function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n(function (global, factory) {\n  (typeof exports === \"undefined\" ? \"undefined\" : _typeof(exports)) === \"object\" && typeof module !== \"undefined\" ? factory(exports) : typeof define === \"function\" && define.amd ? define([\"exports\"], factory) : factory(global.ActiveStorage = {});\n})(this, function (exports) {\n  \"use strict\";\n\n  function createCommonjsModule(fn, module) {\n    return module = {\n      exports: {}\n    }, fn(module, module.exports), module.exports;\n  }\n\n  var sparkMd5 = createCommonjsModule(function (module, exports) {\n    (function (factory) {\n      {\n        module.exports = factory();\n      }\n    })(function (undefined) {\n      var hex_chr = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n\n      function md5cycle(x, k) {\n        var a = x[0],\n            b = x[1],\n            c = x[2],\n            d = x[3];\n        a += (b & c | ~b & d) + k[0] - 680876936 | 0;\n        a = (a << 7 | a >>> 25) + b | 0;\n        d += (a & b | ~a & c) + k[1] - 389564586 | 0;\n        d = (d << 12 | d >>> 20) + a | 0;\n        c += (d & a | ~d & b) + k[2] + 606105819 | 0;\n        c = (c << 17 | c >>> 15) + d | 0;\n        b += (c & d | ~c & a) + k[3] - 1044525330 | 0;\n        b = (b << 22 | b >>> 10) + c | 0;\n        a += (b & c | ~b & d) + k[4] - 176418897 | 0;\n        a = (a << 7 | a >>> 25) + b | 0;\n        d += (a & b | ~a & c) + k[5] + 1200080426 | 0;\n        d = (d << 12 | d >>> 20) + a | 0;\n        c += (d & a | ~d & b) + k[6] - 1473231341 | 0;\n        c = (c << 17 | c >>> 15) + d | 0;\n        b += (c & d | ~c & a) + k[7] - 45705983 | 0;\n        b = (b << 22 | b >>> 10) + c | 0;\n        a += (b & c | ~b & d) + k[8] + 1770035416 | 0;\n        a = (a << 7 | a >>> 25) + b | 0;\n        d += (a & b | ~a & c) + k[9] - 1958414417 | 0;\n        d = (d << 12 | d >>> 20) + a | 0;\n        c += (d & a | ~d & b) + k[10] - 42063 | 0;\n        c = (c << 17 | c >>> 15) + d | 0;\n        b += (c & d | ~c & a) + k[11] - 1990404162 | 0;\n        b = (b << 22 | b >>> 10) + c | 0;\n        a += (b & c | ~b & d) + k[12] + 1804603682 | 0;\n        a = (a << 7 | a >>> 25) + b | 0;\n        d += (a & b | ~a & c) + k[13] - 40341101 | 0;\n        d = (d << 12 | d >>> 20) + a | 0;\n        c += (d & a | ~d & b) + k[14] - 1502002290 | 0;\n        c = (c << 17 | c >>> 15) + d | 0;\n        b += (c & d | ~c & a) + k[15] + 1236535329 | 0;\n        b = (b << 22 | b >>> 10) + c | 0;\n        a += (b & d | c & ~d) + k[1] - 165796510 | 0;\n        a = (a << 5 | a >>> 27) + b | 0;\n        d += (a & c | b & ~c) + k[6] - 1069501632 | 0;\n        d = (d << 9 | d >>> 23) + a | 0;\n        c += (d & b | a & ~b) + k[11] + 643717713 | 0;\n        c = (c << 14 | c >>> 18) + d | 0;\n        b += (c & a | d & ~a) + k[0] - 373897302 | 0;\n        b = (b << 20 | b >>> 12) + c | 0;\n        a += (b & d | c & ~d) + k[5] - 701558691 | 0;\n        a = (a << 5 | a >>> 27) + b | 0;\n        d += (a & c | b & ~c) + k[10] + 38016083 | 0;\n        d = (d << 9 | d >>> 23) + a | 0;\n        c += (d & b | a & ~b) + k[15] - 660478335 | 0;\n        c = (c << 14 | c >>> 18) + d | 0;\n        b += (c & a | d & ~a) + k[4] - 405537848 | 0;\n        b = (b << 20 | b >>> 12) + c | 0;\n        a += (b & d | c & ~d) + k[9] + 568446438 | 0;\n        a = (a << 5 | a >>> 27) + b | 0;\n        d += (a & c | b & ~c) + k[14] - 1019803690 | 0;\n        d = (d << 9 | d >>> 23) + a | 0;\n        c += (d & b | a & ~b) + k[3] - 187363961 | 0;\n        c = (c << 14 | c >>> 18) + d | 0;\n        b += (c & a | d & ~a) + k[8] + 1163531501 | 0;\n        b = (b << 20 | b >>> 12) + c | 0;\n        a += (b & d | c & ~d) + k[13] - 1444681467 | 0;\n        a = (a << 5 | a >>> 27) + b | 0;\n        d += (a & c | b & ~c) + k[2] - 51403784 | 0;\n        d = (d << 9 | d >>> 23) + a | 0;\n        c += (d & b | a & ~b) + k[7] + 1735328473 | 0;\n        c = (c << 14 | c >>> 18) + d | 0;\n        b += (c & a | d & ~a) + k[12] - 1926607734 | 0;\n        b = (b << 20 | b >>> 12) + c | 0;\n        a += (b ^ c ^ d) + k[5] - 378558 | 0;\n        a = (a << 4 | a >>> 28) + b | 0;\n        d += (a ^ b ^ c) + k[8] - 2022574463 | 0;\n        d = (d << 11 | d >>> 21) + a | 0;\n        c += (d ^ a ^ b) + k[11] + 1839030562 | 0;\n        c = (c << 16 | c >>> 16) + d | 0;\n        b += (c ^ d ^ a) + k[14] - 35309556 | 0;\n        b = (b << 23 | b >>> 9) + c | 0;\n        a += (b ^ c ^ d) + k[1] - 1530992060 | 0;\n        a = (a << 4 | a >>> 28) + b | 0;\n        d += (a ^ b ^ c) + k[4] + 1272893353 | 0;\n        d = (d << 11 | d >>> 21) + a | 0;\n        c += (d ^ a ^ b) + k[7] - 155497632 | 0;\n        c = (c << 16 | c >>> 16) + d | 0;\n        b += (c ^ d ^ a) + k[10] - 1094730640 | 0;\n        b = (b << 23 | b >>> 9) + c | 0;\n        a += (b ^ c ^ d) + k[13] + 681279174 | 0;\n        a = (a << 4 | a >>> 28) + b | 0;\n        d += (a ^ b ^ c) + k[0] - 358537222 | 0;\n        d = (d << 11 | d >>> 21) + a | 0;\n        c += (d ^ a ^ b) + k[3] - 722521979 | 0;\n        c = (c << 16 | c >>> 16) + d | 0;\n        b += (c ^ d ^ a) + k[6] + 76029189 | 0;\n        b = (b << 23 | b >>> 9) + c | 0;\n        a += (b ^ c ^ d) + k[9] - 640364487 | 0;\n        a = (a << 4 | a >>> 28) + b | 0;\n        d += (a ^ b ^ c) + k[12] - 421815835 | 0;\n        d = (d << 11 | d >>> 21) + a | 0;\n        c += (d ^ a ^ b) + k[15] + 530742520 | 0;\n        c = (c << 16 | c >>> 16) + d | 0;\n        b += (c ^ d ^ a) + k[2] - 995338651 | 0;\n        b = (b << 23 | b >>> 9) + c | 0;\n        a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;\n        a = (a << 6 | a >>> 26) + b | 0;\n        d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;\n        d = (d << 10 | d >>> 22) + a | 0;\n        c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;\n        c = (c << 15 | c >>> 17) + d | 0;\n        b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;\n        b = (b << 21 | b >>> 11) + c | 0;\n        a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;\n        a = (a << 6 | a >>> 26) + b | 0;\n        d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;\n        d = (d << 10 | d >>> 22) + a | 0;\n        c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;\n        c = (c << 15 | c >>> 17) + d | 0;\n        b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;\n        b = (b << 21 | b >>> 11) + c | 0;\n        a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;\n        a = (a << 6 | a >>> 26) + b | 0;\n        d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;\n        d = (d << 10 | d >>> 22) + a | 0;\n        c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;\n        c = (c << 15 | c >>> 17) + d | 0;\n        b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;\n        b = (b << 21 | b >>> 11) + c | 0;\n        a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;\n        a = (a << 6 | a >>> 26) + b | 0;\n        d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;\n        d = (d << 10 | d >>> 22) + a | 0;\n        c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;\n        c = (c << 15 | c >>> 17) + d | 0;\n        b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;\n        b = (b << 21 | b >>> 11) + c | 0;\n        x[0] = a + x[0] | 0;\n        x[1] = b + x[1] | 0;\n        x[2] = c + x[2] | 0;\n        x[3] = d + x[3] | 0;\n      }\n\n      function md5blk(s) {\n        var md5blks = [],\n            i;\n\n        for (i = 0; i < 64; i += 4) {\n          md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);\n        }\n\n        return md5blks;\n      }\n\n      function md5blk_array(a) {\n        var md5blks = [],\n            i;\n\n        for (i = 0; i < 64; i += 4) {\n          md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);\n        }\n\n        return md5blks;\n      }\n\n      function md51(s) {\n        var n = s.length,\n            state = [1732584193, -271733879, -1732584194, 271733878],\n            i,\n            length,\n            tail,\n            tmp,\n            lo,\n            hi;\n\n        for (i = 64; i <= n; i += 64) {\n          md5cycle(state, md5blk(s.substring(i - 64, i)));\n        }\n\n        s = s.substring(i - 64);\n        length = s.length;\n        tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\n        for (i = 0; i < length; i += 1) {\n          tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);\n        }\n\n        tail[i >> 2] |= 128 << (i % 4 << 3);\n\n        if (i > 55) {\n          md5cycle(state, tail);\n\n          for (i = 0; i < 16; i += 1) {\n            tail[i] = 0;\n          }\n        }\n\n        tmp = n * 8;\n        tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n        lo = parseInt(tmp[2], 16);\n        hi = parseInt(tmp[1], 16) || 0;\n        tail[14] = lo;\n        tail[15] = hi;\n        md5cycle(state, tail);\n        return state;\n      }\n\n      function md51_array(a) {\n        var n = a.length,\n            state = [1732584193, -271733879, -1732584194, 271733878],\n            i,\n            length,\n            tail,\n            tmp,\n            lo,\n            hi;\n\n        for (i = 64; i <= n; i += 64) {\n          md5cycle(state, md5blk_array(a.subarray(i - 64, i)));\n        }\n\n        a = i - 64 < n ? a.subarray(i - 64) : new Uint8Array(0);\n        length = a.length;\n        tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\n        for (i = 0; i < length; i += 1) {\n          tail[i >> 2] |= a[i] << (i % 4 << 3);\n        }\n\n        tail[i >> 2] |= 128 << (i % 4 << 3);\n\n        if (i > 55) {\n          md5cycle(state, tail);\n\n          for (i = 0; i < 16; i += 1) {\n            tail[i] = 0;\n          }\n        }\n\n        tmp = n * 8;\n        tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n        lo = parseInt(tmp[2], 16);\n        hi = parseInt(tmp[1], 16) || 0;\n        tail[14] = lo;\n        tail[15] = hi;\n        md5cycle(state, tail);\n        return state;\n      }\n\n      function rhex(n) {\n        var s = \"\",\n            j;\n\n        for (j = 0; j < 4; j += 1) {\n          s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];\n        }\n\n        return s;\n      }\n\n      function hex(x) {\n        var i;\n\n        for (i = 0; i < x.length; i += 1) {\n          x[i] = rhex(x[i]);\n        }\n\n        return x.join(\"\");\n      }\n\n      if (hex(md51(\"hello\")) !== \"5d41402abc4b2a76b9719d911017c592\") ;\n\n      if (typeof ArrayBuffer !== \"undefined\" && !ArrayBuffer.prototype.slice) {\n        (function () {\n          function clamp(val, length) {\n            val = val | 0 || 0;\n\n            if (val < 0) {\n              return Math.max(val + length, 0);\n            }\n\n            return Math.min(val, length);\n          }\n\n          ArrayBuffer.prototype.slice = function (from, to) {\n            var length = this.byteLength,\n                begin = clamp(from, length),\n                end = length,\n                num,\n                target,\n                targetArray,\n                sourceArray;\n\n            if (to !== undefined) {\n              end = clamp(to, length);\n            }\n\n            if (begin > end) {\n              return new ArrayBuffer(0);\n            }\n\n            num = end - begin;\n            target = new ArrayBuffer(num);\n            targetArray = new Uint8Array(target);\n            sourceArray = new Uint8Array(this, begin, num);\n            targetArray.set(sourceArray);\n            return target;\n          };\n        })();\n      }\n\n      function toUtf8(str) {\n        if (/[\\u0080-\\uFFFF]/.test(str)) {\n          str = unescape(encodeURIComponent(str));\n        }\n\n        return str;\n      }\n\n      function utf8Str2ArrayBuffer(str, returnUInt8Array) {\n        var length = str.length,\n            buff = new ArrayBuffer(length),\n            arr = new Uint8Array(buff),\n            i;\n\n        for (i = 0; i < length; i += 1) {\n          arr[i] = str.charCodeAt(i);\n        }\n\n        return returnUInt8Array ? arr : buff;\n      }\n\n      function arrayBuffer2Utf8Str(buff) {\n        return String.fromCharCode.apply(null, new Uint8Array(buff));\n      }\n\n      function concatenateArrayBuffers(first, second, returnUInt8Array) {\n        var result = new Uint8Array(first.byteLength + second.byteLength);\n        result.set(new Uint8Array(first));\n        result.set(new Uint8Array(second), first.byteLength);\n        return returnUInt8Array ? result : result.buffer;\n      }\n\n      function hexToBinaryString(hex) {\n        var bytes = [],\n            length = hex.length,\n            x;\n\n        for (x = 0; x < length - 1; x += 2) {\n          bytes.push(parseInt(hex.substr(x, 2), 16));\n        }\n\n        return String.fromCharCode.apply(String, bytes);\n      }\n\n      function SparkMD5() {\n        this.reset();\n      }\n\n      SparkMD5.prototype.append = function (str) {\n        this.appendBinary(toUtf8(str));\n        return this;\n      };\n\n      SparkMD5.prototype.appendBinary = function (contents) {\n        this._buff += contents;\n        this._length += contents.length;\n        var length = this._buff.length,\n            i;\n\n        for (i = 64; i <= length; i += 64) {\n          md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));\n        }\n\n        this._buff = this._buff.substring(i - 64);\n        return this;\n      };\n\n      SparkMD5.prototype.end = function (raw) {\n        var buff = this._buff,\n            length = buff.length,\n            i,\n            tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n            ret;\n\n        for (i = 0; i < length; i += 1) {\n          tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);\n        }\n\n        this._finish(tail, length);\n\n        ret = hex(this._hash);\n\n        if (raw) {\n          ret = hexToBinaryString(ret);\n        }\n\n        this.reset();\n        return ret;\n      };\n\n      SparkMD5.prototype.reset = function () {\n        this._buff = \"\";\n        this._length = 0;\n        this._hash = [1732584193, -271733879, -1732584194, 271733878];\n        return this;\n      };\n\n      SparkMD5.prototype.getState = function () {\n        return {\n          buff: this._buff,\n          length: this._length,\n          hash: this._hash\n        };\n      };\n\n      SparkMD5.prototype.setState = function (state) {\n        this._buff = state.buff;\n        this._length = state.length;\n        this._hash = state.hash;\n        return this;\n      };\n\n      SparkMD5.prototype.destroy = function () {\n        delete this._hash;\n        delete this._buff;\n        delete this._length;\n      };\n\n      SparkMD5.prototype._finish = function (tail, length) {\n        var i = length,\n            tmp,\n            lo,\n            hi;\n        tail[i >> 2] |= 128 << (i % 4 << 3);\n\n        if (i > 55) {\n          md5cycle(this._hash, tail);\n\n          for (i = 0; i < 16; i += 1) {\n            tail[i] = 0;\n          }\n        }\n\n        tmp = this._length * 8;\n        tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);\n        lo = parseInt(tmp[2], 16);\n        hi = parseInt(tmp[1], 16) || 0;\n        tail[14] = lo;\n        tail[15] = hi;\n        md5cycle(this._hash, tail);\n      };\n\n      SparkMD5.hash = function (str, raw) {\n        return SparkMD5.hashBinary(toUtf8(str), raw);\n      };\n\n      SparkMD5.hashBinary = function (content, raw) {\n        var hash = md51(content),\n            ret = hex(hash);\n        return raw ? hexToBinaryString(ret) : ret;\n      };\n\n      SparkMD5.ArrayBuffer = function () {\n        this.reset();\n      };\n\n      SparkMD5.ArrayBuffer.prototype.append = function (arr) {\n        var buff = concatenateArrayBuffers(this._buff.buffer, arr, true),\n            length = buff.length,\n            i;\n        this._length += arr.byteLength;\n\n        for (i = 64; i <= length; i += 64) {\n          md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));\n        }\n\n        this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);\n        return this;\n      };\n\n      SparkMD5.ArrayBuffer.prototype.end = function (raw) {\n        var buff = this._buff,\n            length = buff.length,\n            tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n            i,\n            ret;\n\n        for (i = 0; i < length; i += 1) {\n          tail[i >> 2] |= buff[i] << (i % 4 << 3);\n        }\n\n        this._finish(tail, length);\n\n        ret = hex(this._hash);\n\n        if (raw) {\n          ret = hexToBinaryString(ret);\n        }\n\n        this.reset();\n        return ret;\n      };\n\n      SparkMD5.ArrayBuffer.prototype.reset = function () {\n        this._buff = new Uint8Array(0);\n        this._length = 0;\n        this._hash = [1732584193, -271733879, -1732584194, 271733878];\n        return this;\n      };\n\n      SparkMD5.ArrayBuffer.prototype.getState = function () {\n        var state = SparkMD5.prototype.getState.call(this);\n        state.buff = arrayBuffer2Utf8Str(state.buff);\n        return state;\n      };\n\n      SparkMD5.ArrayBuffer.prototype.setState = function (state) {\n        state.buff = utf8Str2ArrayBuffer(state.buff, true);\n        return SparkMD5.prototype.setState.call(this, state);\n      };\n\n      SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;\n      SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;\n\n      SparkMD5.ArrayBuffer.hash = function (arr, raw) {\n        var hash = md51_array(new Uint8Array(arr)),\n            ret = hex(hash);\n        return raw ? hexToBinaryString(ret) : ret;\n      };\n\n      return SparkMD5;\n    });\n  });\n\n  var classCallCheck = function classCallCheck(instance, Constructor) {\n    if (!(instance instanceof Constructor)) {\n      throw new TypeError(\"Cannot call a class as a function\");\n    }\n  };\n\n  var createClass = function () {\n    function defineProperties(target, props) {\n      for (var i = 0; i < props.length; i++) {\n        var descriptor = props[i];\n        descriptor.enumerable = descriptor.enumerable || false;\n        descriptor.configurable = true;\n        if (\"value\" in descriptor) descriptor.writable = true;\n        Object.defineProperty(target, descriptor.key, descriptor);\n      }\n    }\n\n    return function (Constructor, protoProps, staticProps) {\n      if (protoProps) defineProperties(Constructor.prototype, protoProps);\n      if (staticProps) defineProperties(Constructor, staticProps);\n      return Constructor;\n    };\n  }();\n\n  var fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;\n\n  var FileChecksum = function () {\n    createClass(FileChecksum, null, [{\n      key: \"create\",\n      value: function create(file, callback) {\n        var instance = new FileChecksum(file);\n        instance.create(callback);\n      }\n    }]);\n\n    function FileChecksum(file) {\n      classCallCheck(this, FileChecksum);\n      this.file = file;\n      this.chunkSize = 2097152;\n      this.chunkCount = Math.ceil(this.file.size / this.chunkSize);\n      this.chunkIndex = 0;\n    }\n\n    createClass(FileChecksum, [{\n      key: \"create\",\n      value: function create(callback) {\n        var _this = this;\n\n        this.callback = callback;\n        this.md5Buffer = new sparkMd5.ArrayBuffer();\n        this.fileReader = new FileReader();\n        this.fileReader.addEventListener(\"load\", function (event) {\n          return _this.fileReaderDidLoad(event);\n        });\n        this.fileReader.addEventListener(\"error\", function (event) {\n          return _this.fileReaderDidError(event);\n        });\n        this.readNextChunk();\n      }\n    }, {\n      key: \"fileReaderDidLoad\",\n      value: function fileReaderDidLoad(event) {\n        this.md5Buffer.append(event.target.result);\n\n        if (!this.readNextChunk()) {\n          var binaryDigest = this.md5Buffer.end(true);\n          var base64digest = btoa(binaryDigest);\n          this.callback(null, base64digest);\n        }\n      }\n    }, {\n      key: \"fileReaderDidError\",\n      value: function fileReaderDidError(event) {\n        this.callback(\"Error reading \" + this.file.name);\n      }\n    }, {\n      key: \"readNextChunk\",\n      value: function readNextChunk() {\n        if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {\n          var start = this.chunkIndex * this.chunkSize;\n          var end = Math.min(start + this.chunkSize, this.file.size);\n          var bytes = fileSlice.call(this.file, start, end);\n          this.fileReader.readAsArrayBuffer(bytes);\n          this.chunkIndex++;\n          return true;\n        } else {\n          return false;\n        }\n      }\n    }]);\n    return FileChecksum;\n  }();\n\n  function getMetaValue(name) {\n    var element = findElement(document.head, 'meta[name=\"' + name + '\"]');\n\n    if (element) {\n      return element.getAttribute(\"content\");\n    }\n  }\n\n  function findElements(root, selector) {\n    if (typeof root == \"string\") {\n      selector = root;\n      root = document;\n    }\n\n    var elements = root.querySelectorAll(selector);\n    return toArray$1(elements);\n  }\n\n  function findElement(root, selector) {\n    if (typeof root == \"string\") {\n      selector = root;\n      root = document;\n    }\n\n    return root.querySelector(selector);\n  }\n\n  function dispatchEvent(element, type) {\n    var eventInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n    var disabled = element.disabled;\n    var bubbles = eventInit.bubbles,\n        cancelable = eventInit.cancelable,\n        detail = eventInit.detail;\n    var event = document.createEvent(\"Event\");\n    event.initEvent(type, bubbles || true, cancelable || true);\n    event.detail = detail || {};\n\n    try {\n      element.disabled = false;\n      element.dispatchEvent(event);\n    } finally {\n      element.disabled = disabled;\n    }\n\n    return event;\n  }\n\n  function toArray$1(value) {\n    if (Array.isArray(value)) {\n      return value;\n    } else if (Array.from) {\n      return Array.from(value);\n    } else {\n      return [].slice.call(value);\n    }\n  }\n\n  var BlobRecord = function () {\n    function BlobRecord(file, checksum, url) {\n      var _this = this;\n\n      classCallCheck(this, BlobRecord);\n      this.file = file;\n      this.attributes = {\n        filename: file.name,\n        content_type: file.type,\n        byte_size: file.size,\n        checksum: checksum\n      };\n      this.xhr = new XMLHttpRequest();\n      this.xhr.open(\"POST\", url, true);\n      this.xhr.responseType = \"json\";\n      this.xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n      this.xhr.setRequestHeader(\"Accept\", \"application/json\");\n      this.xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n      var csrfToken = getMetaValue(\"csrf-token\");\n\n      if (csrfToken != undefined) {\n        this.xhr.setRequestHeader(\"X-CSRF-Token\", csrfToken);\n      }\n\n      this.xhr.addEventListener(\"load\", function (event) {\n        return _this.requestDidLoad(event);\n      });\n      this.xhr.addEventListener(\"error\", function (event) {\n        return _this.requestDidError(event);\n      });\n    }\n\n    createClass(BlobRecord, [{\n      key: \"create\",\n      value: function create(callback) {\n        this.callback = callback;\n        this.xhr.send(JSON.stringify({\n          blob: this.attributes\n        }));\n      }\n    }, {\n      key: \"requestDidLoad\",\n      value: function requestDidLoad(event) {\n        if (this.status >= 200 && this.status < 300) {\n          var response = this.response;\n          var direct_upload = response.direct_upload;\n          delete response.direct_upload;\n          this.attributes = response;\n          this.directUploadData = direct_upload;\n          this.callback(null, this.toJSON());\n        } else {\n          this.requestDidError(event);\n        }\n      }\n    }, {\n      key: \"requestDidError\",\n      value: function requestDidError(event) {\n        this.callback('Error creating Blob for \"' + this.file.name + '\". Status: ' + this.status);\n      }\n    }, {\n      key: \"toJSON\",\n      value: function toJSON() {\n        var result = {};\n\n        for (var key in this.attributes) {\n          result[key] = this.attributes[key];\n        }\n\n        return result;\n      }\n    }, {\n      key: \"status\",\n      get: function get$$1() {\n        return this.xhr.status;\n      }\n    }, {\n      key: \"response\",\n      get: function get$$1() {\n        var _xhr = this.xhr,\n            responseType = _xhr.responseType,\n            response = _xhr.response;\n\n        if (responseType == \"json\") {\n          return response;\n        } else {\n          return JSON.parse(response);\n        }\n      }\n    }]);\n    return BlobRecord;\n  }();\n\n  var BlobUpload = function () {\n    function BlobUpload(blob) {\n      var _this = this;\n\n      classCallCheck(this, BlobUpload);\n      this.blob = blob;\n      this.file = blob.file;\n      var _blob$directUploadDat = blob.directUploadData,\n          url = _blob$directUploadDat.url,\n          headers = _blob$directUploadDat.headers;\n      this.xhr = new XMLHttpRequest();\n      this.xhr.open(\"PUT\", url, true);\n      this.xhr.responseType = \"text\";\n\n      for (var key in headers) {\n        this.xhr.setRequestHeader(key, headers[key]);\n      }\n\n      this.xhr.addEventListener(\"load\", function (event) {\n        return _this.requestDidLoad(event);\n      });\n      this.xhr.addEventListener(\"error\", function (event) {\n        return _this.requestDidError(event);\n      });\n    }\n\n    createClass(BlobUpload, [{\n      key: \"create\",\n      value: function create(callback) {\n        this.callback = callback;\n        this.xhr.send(this.file.slice());\n      }\n    }, {\n      key: \"requestDidLoad\",\n      value: function requestDidLoad(event) {\n        var _xhr = this.xhr,\n            status = _xhr.status,\n            response = _xhr.response;\n\n        if (status >= 200 && status < 300) {\n          this.callback(null, response);\n        } else {\n          this.requestDidError(event);\n        }\n      }\n    }, {\n      key: \"requestDidError\",\n      value: function requestDidError(event) {\n        this.callback('Error storing \"' + this.file.name + '\". Status: ' + this.xhr.status);\n      }\n    }]);\n    return BlobUpload;\n  }();\n\n  var id = 0;\n\n  var DirectUpload = function () {\n    function DirectUpload(file, url, delegate) {\n      classCallCheck(this, DirectUpload);\n      this.id = ++id;\n      this.file = file;\n      this.url = url;\n      this.delegate = delegate;\n    }\n\n    createClass(DirectUpload, [{\n      key: \"create\",\n      value: function create(callback) {\n        var _this = this;\n\n        FileChecksum.create(this.file, function (error, checksum) {\n          if (error) {\n            callback(error);\n            return;\n          }\n\n          var blob = new BlobRecord(_this.file, checksum, _this.url);\n          notify(_this.delegate, \"directUploadWillCreateBlobWithXHR\", blob.xhr);\n          blob.create(function (error) {\n            if (error) {\n              callback(error);\n            } else {\n              var upload = new BlobUpload(blob);\n              notify(_this.delegate, \"directUploadWillStoreFileWithXHR\", upload.xhr);\n              upload.create(function (error) {\n                if (error) {\n                  callback(error);\n                } else {\n                  callback(null, blob.toJSON());\n                }\n              });\n            }\n          });\n        });\n      }\n    }]);\n    return DirectUpload;\n  }();\n\n  function notify(object, methodName) {\n    if (object && typeof object[methodName] == \"function\") {\n      for (var _len = arguments.length, messages = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {\n        messages[_key - 2] = arguments[_key];\n      }\n\n      return object[methodName].apply(object, messages);\n    }\n  }\n\n  var DirectUploadController = function () {\n    function DirectUploadController(input, file) {\n      classCallCheck(this, DirectUploadController);\n      this.input = input;\n      this.file = file;\n      this.directUpload = new DirectUpload(this.file, this.url, this);\n      this.dispatch(\"initialize\");\n    }\n\n    createClass(DirectUploadController, [{\n      key: \"start\",\n      value: function start(callback) {\n        var _this = this;\n\n        var hiddenInput = document.createElement(\"input\");\n        hiddenInput.type = \"hidden\";\n        hiddenInput.name = this.input.name;\n        this.input.insertAdjacentElement(\"beforebegin\", hiddenInput);\n        this.dispatch(\"start\");\n        this.directUpload.create(function (error, attributes) {\n          if (error) {\n            hiddenInput.parentNode.removeChild(hiddenInput);\n\n            _this.dispatchError(error);\n          } else {\n            hiddenInput.value = attributes.signed_id;\n          }\n\n          _this.dispatch(\"end\");\n\n          callback(error);\n        });\n      }\n    }, {\n      key: \"uploadRequestDidProgress\",\n      value: function uploadRequestDidProgress(event) {\n        var progress = event.loaded / event.total * 100;\n\n        if (progress) {\n          this.dispatch(\"progress\", {\n            progress: progress\n          });\n        }\n      }\n    }, {\n      key: \"dispatch\",\n      value: function dispatch(name) {\n        var detail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n        detail.file = this.file;\n        detail.id = this.directUpload.id;\n        return dispatchEvent(this.input, \"direct-upload:\" + name, {\n          detail: detail\n        });\n      }\n    }, {\n      key: \"dispatchError\",\n      value: function dispatchError(error) {\n        var event = this.dispatch(\"error\", {\n          error: error\n        });\n\n        if (!event.defaultPrevented) {\n          alert(error);\n        }\n      }\n    }, {\n      key: \"directUploadWillCreateBlobWithXHR\",\n      value: function directUploadWillCreateBlobWithXHR(xhr) {\n        this.dispatch(\"before-blob-request\", {\n          xhr: xhr\n        });\n      }\n    }, {\n      key: \"directUploadWillStoreFileWithXHR\",\n      value: function directUploadWillStoreFileWithXHR(xhr) {\n        var _this2 = this;\n\n        this.dispatch(\"before-storage-request\", {\n          xhr: xhr\n        });\n        xhr.upload.addEventListener(\"progress\", function (event) {\n          return _this2.uploadRequestDidProgress(event);\n        });\n      }\n    }, {\n      key: \"url\",\n      get: function get$$1() {\n        return this.input.getAttribute(\"data-direct-upload-url\");\n      }\n    }]);\n    return DirectUploadController;\n  }();\n\n  var inputSelector = \"input[type=file][data-direct-upload-url]:not([disabled])\";\n\n  var DirectUploadsController = function () {\n    function DirectUploadsController(form) {\n      classCallCheck(this, DirectUploadsController);\n      this.form = form;\n      this.inputs = findElements(form, inputSelector).filter(function (input) {\n        return input.files.length;\n      });\n    }\n\n    createClass(DirectUploadsController, [{\n      key: \"start\",\n      value: function start(callback) {\n        var _this = this;\n\n        var controllers = this.createDirectUploadControllers();\n\n        var startNextController = function startNextController() {\n          var controller = controllers.shift();\n\n          if (controller) {\n            controller.start(function (error) {\n              if (error) {\n                callback(error);\n\n                _this.dispatch(\"end\");\n              } else {\n                startNextController();\n              }\n            });\n          } else {\n            callback();\n\n            _this.dispatch(\"end\");\n          }\n        };\n\n        this.dispatch(\"start\");\n        startNextController();\n      }\n    }, {\n      key: \"createDirectUploadControllers\",\n      value: function createDirectUploadControllers() {\n        var controllers = [];\n        this.inputs.forEach(function (input) {\n          toArray$1(input.files).forEach(function (file) {\n            var controller = new DirectUploadController(input, file);\n            controllers.push(controller);\n          });\n        });\n        return controllers;\n      }\n    }, {\n      key: \"dispatch\",\n      value: function dispatch(name) {\n        var detail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n        return dispatchEvent(this.form, \"direct-uploads:\" + name, {\n          detail: detail\n        });\n      }\n    }]);\n    return DirectUploadsController;\n  }();\n\n  var processingAttribute = \"data-direct-uploads-processing\";\n  var submitButtonsByForm = new WeakMap();\n  var started = false;\n\n  function start() {\n    if (!started) {\n      started = true;\n      document.addEventListener(\"click\", didClick, true);\n      document.addEventListener(\"submit\", didSubmitForm);\n      document.addEventListener(\"ajax:before\", didSubmitRemoteElement);\n    }\n  }\n\n  function didClick(event) {\n    var target = event.target;\n\n    if ((target.tagName == \"INPUT\" || target.tagName == \"BUTTON\") && target.type == \"submit\" && target.form) {\n      submitButtonsByForm.set(target.form, target);\n    }\n  }\n\n  function didSubmitForm(event) {\n    handleFormSubmissionEvent(event);\n  }\n\n  function didSubmitRemoteElement(event) {\n    if (event.target.tagName == \"FORM\") {\n      handleFormSubmissionEvent(event);\n    }\n  }\n\n  function handleFormSubmissionEvent(event) {\n    var form = event.target;\n\n    if (form.hasAttribute(processingAttribute)) {\n      event.preventDefault();\n      return;\n    }\n\n    var controller = new DirectUploadsController(form);\n    var inputs = controller.inputs;\n\n    if (inputs.length) {\n      event.preventDefault();\n      form.setAttribute(processingAttribute, \"\");\n      inputs.forEach(disable);\n      controller.start(function (error) {\n        form.removeAttribute(processingAttribute);\n\n        if (error) {\n          inputs.forEach(enable);\n        } else {\n          submitForm(form);\n        }\n      });\n    }\n  }\n\n  function submitForm(form) {\n    var button = submitButtonsByForm.get(form) || findElement(form, \"input[type=submit], button[type=submit]\");\n\n    if (button) {\n      var _button = button,\n          disabled = _button.disabled;\n      button.disabled = false;\n      button.focus();\n      button.click();\n      button.disabled = disabled;\n    } else {\n      button = document.createElement(\"input\");\n      button.type = \"submit\";\n      button.style.display = \"none\";\n      form.appendChild(button);\n      button.click();\n      form.removeChild(button);\n    }\n\n    submitButtonsByForm[\"delete\"](form);\n  }\n\n  function disable(input) {\n    input.disabled = true;\n  }\n\n  function enable(input) {\n    input.disabled = false;\n  }\n\n  function autostart() {\n    if (window.ActiveStorage) {\n      start();\n    }\n  }\n\n  setTimeout(autostart, 1);\n  exports.start = start;\n  exports.DirectUpload = DirectUpload;\n  Object.defineProperty(exports, \"__esModule\", {\n    value: true\n  });\n});","map":null,"metadata":{},"sourceType":"module"}