{“ast”:null,“code”:“function _typeof(obj) { 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); }nn(function (global, factory) {n (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(, factory) : factory(global.ActiveStorage = {});n})(this, function (exports) {n "use strict";nn function createCommonjsModule(fn, module) {n return module = {n exports: {}n }, fn(module, module.exports), module.exports;n }nn 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"];nn function md5cycle(x, k) {n var a = x,n b = x,n c = x,n d = x;n a += (b & c | ~b & d) + k - 680876936 | 0;n a = (a << 7 | a >>> 25) + b | 0;n d += (a & b | ~a & c) + k - 389564586 | 0;n d = (d << 12 | d >>> 20) + a | 0;n c += (d & a | ~d & b) + k + 606105819 | 0;n c = (c << 17 | c >>> 15) + d | 0;n b += (c & d | ~c & a) + k - 1044525330 | 0;n b = (b << 22 | b >>> 10) + c | 0;n a += (b & c | ~b & d) + k - 176418897 | 0;n a = (a << 7 | a >>> 25) + b | 0;n d += (a & b | ~a & c) + k + 1200080426 | 0;n d = (d << 12 | d >>> 20) + a | 0;n c += (d & a | ~d & b) + k - 1473231341 | 0;n c = (c << 17 | c >>> 15) + d | 0;n b += (c & d | ~c & a) + k - 45705983 | 0;n b = (b << 22 | b >>> 10) + c | 0;n a += (b & c | ~b & d) + k + 1770035416 | 0;n a = (a << 7 | a >>> 25) + b | 0;n d += (a & b | ~a & c) + k - 1958414417 | 0;n d = (d << 12 | d >>> 20) + a | 0;n c += (d & a | ~d & b) + k - 42063 | 0;n c = (c << 17 | c >>> 15) + d | 0;n b += (c & d | ~c & a) + k - 1990404162 | 0;n b = (b << 22 | b >>> 10) + c | 0;n a += (b & c | ~b & d) + k + 1804603682 | 0;n a = (a << 7 | a >>> 25) + b | 0;n d += (a & b | ~a & c) + k - 40341101 | 0;n d = (d << 12 | d >>> 20) + a | 0;n c += (d & a | ~d & b) + k - 1502002290 | 0;n c = (c << 17 | c >>> 15) + d | 0;n b += (c & d | ~c & a) + k + 1236535329 | 0;n b = (b << 22 | b >>> 10) + c | 0;n a += (b & d | c & ~d) + k - 165796510 | 0;n a = (a << 5 | a >>> 27) + b | 0;n d += (a & c | b & ~c) + k - 1069501632 | 0;n d = (d << 9 | d >>> 23) + a | 0;n c += (d & b | a & ~b) + k + 643717713 | 0;n c = (c << 14 | c >>> 18) + d | 0;n b += (c & a | d & ~a) + k - 373897302 | 0;n b = (b << 20 | b >>> 12) + c | 0;n a += (b & d | c & ~d) + k - 701558691 | 0;n a = (a << 5 | a >>> 27) + b | 0;n d += (a & c | b & ~c) + k + 38016083 | 0;n d = (d << 9 | d >>> 23) + a | 0;n c += (d & b | a & ~b) + k - 660478335 | 0;n c = (c << 14 | c >>> 18) + d | 0;n b += (c & a | d & ~a) + k - 405537848 | 0;n b = (b << 20 | b >>> 12) + c | 0;n a += (b & d | c & ~d) + k + 568446438 | 0;n a = (a << 5 | a >>> 27) + b | 0;n d += (a & c | b & ~c) + k - 1019803690 | 0;n d = (d << 9 | d >>> 23) + a | 0;n c += (d & b | a & ~b) + k - 187363961 | 0;n c = (c << 14 | c >>> 18) + d | 0;n b += (c & a | d & ~a) + k + 1163531501 | 0;n b = (b << 20 | b >>> 12) + c | 0;n a += (b & d | c & ~d) + k - 1444681467 | 0;n a = (a << 5 | a >>> 27) + b | 0;n d += (a & c | b & ~c) + k - 51403784 | 0;n d = (d << 9 | d >>> 23) + a | 0;n c += (d & b | a & ~b) + k + 1735328473 | 0;n c = (c << 14 | c >>> 18) + d | 0;n b += (c & a | d & ~a) + k - 1926607734 | 0;n b = (b << 20 | b >>> 12) + c | 0;n a += (b ^ c ^ d) + k - 378558 | 0;n a = (a << 4 | a >>> 28) + b | 0;n d += (a ^ b ^ c) + k - 2022574463 | 0;n d = (d << 11 | d >>> 21) + a | 0;n c += (d ^ a ^ b) + k + 1839030562 | 0;n c = (c << 16 | c >>> 16) + d | 0;n b += (c ^ d ^ a) + k - 35309556 | 0;n b = (b << 23 | b >>> 9) + c | 0;n a += (b ^ c ^ d) + k - 1530992060 | 0;n a = (a << 4 | a >>> 28) + b | 0;n d += (a ^ b ^ c) + k + 1272893353 | 0;n d = (d << 11 | d >>> 21) + a | 0;n c += (d ^ a ^ b) + k - 155497632 | 0;n c = (c << 16 | c >>> 16) + d | 0;n b += (c ^ d ^ a) + k - 1094730640 | 0;n b = (b << 23 | b >>> 9) + c | 0;n a += (b ^ c ^ d) + k + 681279174 | 0;n a = (a << 4 | a >>> 28) + b | 0;n d += (a ^ b ^ c) + k - 358537222 | 0;n d = (d << 11 | d >>> 21) + a | 0;n c += (d ^ a ^ b) + k - 722521979 | 0;n c = (c << 16 | c >>> 16) + d | 0;n b += (c ^ d ^ a) + k + 76029189 | 0;n b = (b << 23 | b >>> 9) + c | 0;n a += (b ^ c ^ d) + k - 640364487 | 0;n a = (a << 4 | a >>> 28) + b | 0;n d += (a ^ b ^ c) + k - 421815835 | 0;n d = (d << 11 | d >>> 21) + a | 0;n c += (d ^ a ^ b) + k + 530742520 | 0;n c = (c << 16 | c >>> 16) + d | 0;n b += (c ^ d ^ a) + k - 995338651 | 0;n b = (b << 23 | b >>> 9) + c | 0;n a += (c ^ (b | ~d)) + k - 198630844 | 0;n a = (a << 6 | a >>> 26) + b | 0;n d += (b ^ (a | ~c)) + k + 1126891415 | 0;n d = (d << 10 | d >>> 22) + a | 0;n c += (a ^ (d | ~b)) + k - 1416354905 | 0;n c = (c << 15 | c >>> 17) + d | 0;n b += (d ^ (c | ~a)) + k - 57434055 | 0;n b = (b << 21 | b >>> 11) + c | 0;n a += (c ^ (b | ~d)) + k + 1700485571 | 0;n a = (a << 6 | a >>> 26) + b | 0;n d += (b ^ (a | ~c)) + k - 1894986606 | 0;n d = (d << 10 | d >>> 22) + a | 0;n c += (a ^ (d | ~b)) + k - 1051523 | 0;n c = (c << 15 | c >>> 17) + d | 0;n b += (d ^ (c | ~a)) + k - 2054922799 | 0;n b = (b << 21 | b >>> 11) + c | 0;n a += (c ^ (b | ~d)) + k + 1873313359 | 0;n a = (a << 6 | a >>> 26) + b | 0;n d += (b ^ (a | ~c)) + k - 30611744 | 0;n d = (d << 10 | d >>> 22) + a | 0;n c += (a ^ (d | ~b)) + k - 1560198380 | 0;n c = (c << 15 | c >>> 17) + d | 0;n b += (d ^ (c | ~a)) + k + 1309151649 | 0;n b = (b << 21 | b >>> 11) + c | 0;n a += (c ^ (b | ~d)) + k - 145523070 | 0;n a = (a << 6 | a >>> 26) + b | 0;n d += (b ^ (a | ~c)) + k - 1120210379 | 0;n d = (d << 10 | d >>> 22) + a | 0;n c += (a ^ (d | ~b)) + k + 718787259 | 0;n c = (c << 15 | c >>> 17) + d | 0;n b += (d ^ (c | ~a)) + k - 343485551 | 0;n b = (b << 21 | b >>> 11) + c | 0;n x = a + x | 0;n x = b + x | 0;n x = c + x | 0;n x = d + x | 0;n }nn function md5blk(s) {n var md5blks = [],n i;nn 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 }nn return md5blks;n }nn function md5blk_array(a) {n var md5blks = [],n i;nn for (i = 0; i < 64; i += 4) {n md5blks[i >> 2] = a + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);n }nn return md5blks;n }nn 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;nn for (i = 64; i <= n; i += 64) {n md5cycle(state, md5blk(s.substring(i - 64, i)));n }nn 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];nn for (i = 0; i < length; i += 1) {n tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);n }nn tail[i >> 2] |= 128 << (i % 4 << 3);nn if (i > 55) {n md5cycle(state, tail);nn for (i = 0; i < 16; i += 1) {n tail = 0;n }n }nn tmp = n * 8;n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);n lo = parseInt(tmp, 16);n hi = parseInt(tmp, 16) || 0;n tail = lo;n tail = hi;n md5cycle(state, tail);n return state;n }nn 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;nn for (i = 64; i <= n; i += 64) {n md5cycle(state, md5blk_array(a.subarray(i - 64, i)));n }nn 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];nn for (i = 0; i < length; i += 1) {n tail[i >> 2] |= a << (i % 4 << 3);n }nn tail[i >> 2] |= 128 << (i % 4 << 3);nn if (i > 55) {n md5cycle(state, tail);nn for (i = 0; i < 16; i += 1) {n tail = 0;n }n }nn tmp = n * 8;n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);n lo = parseInt(tmp, 16);n hi = parseInt(tmp, 16) || 0;n tail = lo;n tail = hi;n md5cycle(state, tail);n return state;n }nn function rhex(n) {n var s = "",n j;nn for (j = 0; j < 4; j += 1) {n s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];n }nn return s;n }nn function hex(x) {n var i;nn for (i = 0; i < x.length; i += 1) {n x = rhex(x);n }nn return x.join("");n }nn if (hex(md51("hello")) !== "5d41402abc4b2a76b9719d911017c592") ;nn if (typeof ArrayBuffer !== "undefined" && !ArrayBuffer.prototype.slice) {n (function () {n function clamp(val, length) {n val = val | 0 || 0;nn if (val < 0) {n return Math.max(val + length, 0);n }nn return Math.min(val, length);n }nn 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;nn if (to !== undefined) {n end = clamp(to, length);n }nn if (begin > end) {n return new ArrayBuffer(0);n }nn 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 }nn function toUtf8(str) {n if (/[\u0080-\uFFFF]/.test(str)) {n str = unescape(encodeURIComponent(str));n }nn return str;n }nn function utf8Str2ArrayBuffer(str, returnUInt8Array) {n var length = str.length,n buff = new ArrayBuffer(length),n arr = new Uint8Array(buff),n i;nn for (i = 0; i < length; i += 1) {n arr = str.charCodeAt(i);n }nn return returnUInt8Array ? arr : buff;n }nn function arrayBuffer2Utf8Str(buff) {n return String.fromCharCode.apply(null, new Uint8Array(buff));n }nn 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 }nn function hexToBinaryString(hex) {n var bytes = [],n length = hex.length,n x;nn for (x = 0; x < length - 1; x += 2) {n bytes.push(parseInt(hex.substr(x, 2), 16));n }nn return String.fromCharCode.apply(String, bytes);n }nn function SparkMD5() {n this.reset();n }nn SparkMD5.prototype.append = function (str) {n this.appendBinary(toUtf8(str));n return this;n };nn SparkMD5.prototype.appendBinary = function (contents) {n this._buff += contents;n this._length += contents.length;n var length = this._buff.length,n i;nn for (i = 64; i <= length; i += 64) {n md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));n }nn this._buff = this._buff.substring(i - 64);n return this;n };nn 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;nn for (i = 0; i < length; i += 1) {n tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);n }nn this._finish(tail, length);nn ret = hex(this._hash);nn if (raw) {n ret = hexToBinaryString(ret);n }nn this.reset();n return ret;n };nn SparkMD5.prototype.reset = function () {n this._buff = "";n this._length = 0;n this._hash = [1732584193, -271733879, -1732584194, 271733878];n return this;n };nn SparkMD5.prototype.getState = function () {n return {n buff: this._buff,n length: this._length,n hash: this._hashn };n };nn SparkMD5.prototype.setState = function (state) {n this._buff = state.buff;n this._length = state.length;n this._hash = state.hash;n return this;n };nn SparkMD5.prototype.destroy = function () {n delete this._hash;n delete this._buff;n delete this._length;n };nn SparkMD5.prototype._finish = function (tail, length) {n var i = length,n tmp,n lo,n hi;n tail[i >> 2] |= 128 << (i % 4 << 3);nn if (i > 55) {n md5cycle(this._hash, tail);nn for (i = 0; i < 16; i += 1) {n tail = 0;n }n }nn tmp = this._length * 8;n tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);n lo = parseInt(tmp, 16);n hi = parseInt(tmp, 16) || 0;n tail = lo;n tail = hi;n md5cycle(this._hash, tail);n };nn SparkMD5.hash = function (str, raw) {n return SparkMD5.hashBinary(toUtf8(str), raw);n };nn SparkMD5.hashBinary = function (content, raw) {n var hash = md51(content),n ret = hex(hash);n return raw ? hexToBinaryString(ret) : ret;n };nn SparkMD5.ArrayBuffer = function () {n this.reset();n };nn 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;nn for (i = 64; i <= length; i += 64) {n md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));n }nn this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);n return this;n };nn 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;nn for (i = 0; i < length; i += 1) {n tail[i >> 2] |= buff << (i % 4 << 3);n }nn this._finish(tail, length);nn ret = hex(this._hash);nn if (raw) {n ret = hexToBinaryString(ret);n }nn this.reset();n return ret;n };nn 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 };nn SparkMD5.ArrayBuffer.prototype.getState = function () {n var state = SparkMD5.prototype.getState.call(this);n state.buff = arrayBuffer2Utf8Str(state.buff);n return state;n };nn SparkMD5.ArrayBuffer.prototype.setState = function (state) {n state.buff = utf8Str2ArrayBuffer(state.buff, true);n return SparkMD5.prototype.setState.call(this, state);n };nn SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;n SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;nn 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 };nn return SparkMD5;n });n });nn var classCallCheck = function classCallCheck(instance, Constructor) {n if (!(instance instanceof Constructor)) {n throw new TypeError("Cannot call a class as a function");n }n };nn var createClass = function () {n function defineProperties(target, props) {n for (var i = 0; i < props.length; i++) {n var descriptor = props;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 }nn return function (Constructor, protoProps, staticProps) {n if (protoProps) defineProperties(Constructor.prototype, protoProps);n if (staticProps) defineProperties(Constructor, staticProps);n return Constructor;n };n }();nn var fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;nn 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 }]);nn 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 }nn createClass(FileChecksum, [{n key: "create",n value: function create(callback) {n var _this = this;nn 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);nn 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 }();nn function getMetaValue(name) {n var element = findElement(document.head, 'meta[name="' + name + '"]');nn if (element) {n return element.getAttribute("content");n }n }nn function findElements(root, selector) {n if (typeof root == "string") {n selector = root;n root = document;n }nn var elements = root.querySelectorAll(selector);n return toArray$1(elements);n }nn function findElement(root, selector) {n if (typeof root == "string") {n selector = root;n root = document;n }nn return root.querySelector(selector);n }nn function dispatchEvent(element, type) {n var eventInit = arguments.length > 2 && arguments !== undefined ? arguments : {};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 || {};nn try {n element.disabled = false;n element.dispatchEvent(event);n } finally {n element.disabled = disabled;n }nn return event;n }nn 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 }nn var BlobRecord = function () {n function BlobRecord(file, checksum, url) {n var _this = this;nn 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: checksumn };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");nn if (csrfToken != undefined) {n this.xhr.setRequestHeader("X-CSRF-Token", csrfToken);n }nn 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 }nn createClass(BlobRecord, [{n key: "create",n value: function create(callback) {n this.callback = callback;n this.xhr.send(JSON.stringify({n blob: this.attributesn }));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 = {};nn for (var key in this.attributes) {n result = this.attributes;n }nn 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;nn if (responseType == "json") {n return response;n } else {n return JSON.parse(response);n }n }n }]);n return BlobRecord;n }();nn var BlobUpload = function () {n function BlobUpload(blob) {n var _this = this;nn 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";nn for (var key in headers) {n this.xhr.setRequestHeader(key, headers);n }nn 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 }nn 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;nn 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 }();nn var id = 0;nn 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 }nn createClass(DirectUpload, [{n key: "create",n value: function create(callback) {n var _this = this;nn FileChecksum.create(this.file, function (error, checksum) {n if (error) {n callback(error);n return;n }nn 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 }();nn function notify(object, methodName) {n if (object && typeof object == "function") {n for (var _len = arguments.length, messages = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {n messages[_key - 2] = arguments;n }nn return object.apply(object, messages);n }n }nn 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 }nn createClass(DirectUploadController, [{n key: "start",n value: function start(callback) {n var _this = this;nn 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);nn _this.dispatchError(error);n } else {n hiddenInput.value = attributes.signed_id;n }nn _this.dispatch("end");nn callback(error);n });n }n }, {n key: "uploadRequestDidProgress",n value: function uploadRequestDidProgress(event) {n var progress = event.loaded / event.total * 100;nn if (progress) {n this.dispatch("progress", {n progress: progressn });n }n }n }, {n key: "dispatch",n value: function dispatch(name) {n var detail = arguments.length > 1 && arguments !== undefined ? arguments : {};n detail.file = this.file;n detail.id = this.directUpload.id;n return dispatchEvent(this.input, "direct-upload:" + name, {n detail: detailn });n }n }, {n key: "dispatchError",n value: function dispatchError(error) {n var event = this.dispatch("error", {n error: errorn });nn 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: xhrn });n }n }, {n key: "directUploadWillStoreFileWithXHR",n value: function directUploadWillStoreFileWithXHR(xhr) {n var _this2 = this;nn this.dispatch("before-storage-request", {n xhr: xhrn });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 }();nn var inputSelector = "input[type=file][data-direct-upload-url]:not()";nn 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 }nn createClass(DirectUploadsController, [{n key: "start",n value: function start(callback) {n var _this = this;nn var controllers = this.createDirectUploadControllers();nn var startNextController = function startNextController() {n var controller = controllers.shift();nn if (controller) {n controller.start(function (error) {n if (error) {n callback(error);nn _this.dispatch("end");n } else {n startNextController();n }n });n } else {n callback();nn _this.dispatch("end");n }n };nn 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 !== undefined ? arguments : {};n return dispatchEvent(this.form, "direct-uploads:" + name, {n detail: detailn });n }n }]);n return DirectUploadsController;n }();nn var processingAttribute = "data-direct-uploads-processing";n var submitButtonsByForm = new WeakMap();n var started = false;nn 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 }nn function didClick(event) {n var target = event.target;nn if ((target.tagName == "INPUT" || target.tagName == "BUTTON") && target.type == "submit" && target.form) {n submitButtonsByForm.set(target.form, target);n }n }nn function didSubmitForm(event) {n handleFormSubmissionEvent(event);n }nn function didSubmitRemoteElement(event) {n if (event.target.tagName == "FORM") {n handleFormSubmissionEvent(event);n }n }nn function handleFormSubmissionEvent(event) {n var form = event.target;nn if (form.hasAttribute(processingAttribute)) {n event.preventDefault();n return;n }nn var controller = new DirectUploadsController(form);n var inputs = controller.inputs;nn if (inputs.length) {n event.preventDefault();n form.setAttribute(processingAttribute, "");n inputs.forEach(disable);n controller.start(function (error) {n form.removeAttribute(processingAttribute);nn if (error) {n inputs.forEach(enable);n } else {n submitForm(form);n }n });n }n }nn function submitForm(form) {n var button = submitButtonsByForm.get(form) || findElement(form, "input[type=submit], button");nn 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 }nn submitButtonsByForm(form);n }nn function disable(input) {n input.disabled = true;n }nn function enable(input) {n input.disabled = false;n }nn function autostart() {n if (window.ActiveStorage) {n start();n }n }nn setTimeout(autostart, 1);n exports.start = start;n exports.DirectUpload = DirectUpload;n Object.defineProperty(exports, "__esModule", {n value: truen });n});”,“map”:null,“metadata”:{},“sourceType”:“module”}