UNPKG

makedrive-client

Version:

Webmaker cloud-syncing filesystem client-side API

3 lines 289 kB
/*! makedrive 0.0.25 2014-08-13 */ !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.MakeDrive=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};a[g][0].call(j.exports,function(b){var c=a[g][1][b];return e(c?c:b)},j,j.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){(function(a){a.WebSocket.prototype.on=a.WebSocket.prototype.on||function(a,b){this.addEventListener(a,b)},a.WebSocket.prototype.removeListener=a.WebSocket.prototype.removeListener||function(a,b){this.removeEventListener(a,b)},a.WebSocket.prototype.once=a.WebSocket.prototype.once||function(a,b){var c=this;this.addEventListener(a,function d(){c.removeEventListener(a,d),b.apply(null,arguments)})},b.exports=a.WebSocket}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(a,b){(function(c){function d(a){a.manual=a.manual===!0,a.memory=a.memory===!0;var b;b=a.provider?a.provider:a.memory?new g.FileSystem.providers.Memory("makedrive"):new g.FileSystem.providers.Fallback("makedrive");var d,j,k,l=new g.FileSystem({provider:b}),m=new f(l),n=m.sync=new h;return n.SYNC_DISCONNECTED=0,n.SYNC_CONNECTING=1,n.SYNC_CONNECTED=2,n.SYNC_SYNCING=3,n.SYNC_ERROR=4,n.state=n.SYNC_DISCONNECTED,n.auto=function(a){var b=a|!1?0|a:6e4;j&&clearInterval(j),j=setInterval(n.request,b)},n.manual=function(){j&&(clearInterval(j),j=null)},n.onError=function(a){m.pathToSync=k,n.state=n.SYNC_ERROR,n.emit("error",a)},n.onDisconnected=function(){n.state=n.SYNC_DISCONNECTED,n.emit("disconnected")},n.request=function(){return n.state===n.SYNC_DISCONNECTED||n.state===n.SYNC_ERROR?void n.emit("error",new Error("Invalid state. Expected "+n.SYNC_CONNECTED+", got "+n.state)):void(m.pathToSync&&(k=m.pathToSync,m.pathToSync=null,d.syncPath(k)))},n.connect=function(b,f){function g(){n.onSyncing=function(){n.state=n.SYNC_SYNCING,n.emit("syncing")},n.onCompleted=function(a){function b(){n.state=n.SYNC_CONNECTED,n.emit("completed")}return a?void d.resetUnsynced(a,function(a){return a?n.onError(a):void b()}):b()},n.state=n.SYNC_CONNECTED,a.manual?n.manual():n.auto(a.interval),n.emit("connected")}function h(a){d=new e(n,l),d.init(b,a,function(a){return a?void n.onError(a):("onbeforeunload"in c&&(n.cleanupFn=function(){d&&(d.close(),d=null)},c.addEventListener("beforeunload",n.cleanupFn)),n.onSyncing=function(){},void(n.onCompleted=function(){g()}))})}if(n.state!==n.SYNC_DISCONNECTED&&n.state!==n.ERROR)return void n.emit("error",new Error('MakeDrive: Attempted to connect to "'+b+'", but a connection already exists!'));if(!d)if(n.state=n.SYNC_CONNECTING,f)h(f);else{var j=b.replace(/^([^\/]*\/\/)?/,function(a,b){return"wss://"===b?"https://":"http://"});j=j.replace(/\/?$/,"/api/sync"),i({url:j,method:"GET",json:!0,withCredentials:!0},function(a,b,c){var d,e;d=b&&b.statusCode,e=200!==d?{message:a||"Unable to get token",code:d}:null,e?n.onError(e):h(c)})}},n.disconnect=function(){return"onbeforeunload"in c&&n.cleanupFn&&(c.removeEventListener("beforeunload",n.cleanupFn),n.cleanupFn=null),n.state===n.SYNC_DISCONNECTED||n.state===n.ERROR?void n.emit("error",new Error("MakeDrive: Attempted to disconnect, but no server connection exists!")):(d&&(d.close(),d=null),j&&(clearInterval(j),j=null,m.pathToSync=null),void n.onDisconnected())},m}var e=a("./sync-manager.js"),f=a("./sync-filesystem.js"),g=a("../../lib/filer.js"),h=(a("../../lib/sync-path-resolver").resolve,a("events").EventEmitter),i=a("request"),j={};b.exports=j;var k;j.fs=function(a){return a=a||{},a.forceCreate?d(a):(k||(k=d(a)),k)},j.Buffer=g.Buffer,j.Path=g.Path,j.Errors=g.Errors}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../../lib/filer.js":72,"../../lib/sync-path-resolver":75,"./sync-filesystem.js":4,"./sync-manager.js":5,events:120,request:81}],3:[function(a,b){function c(a,b){a.session.step=n.FAILED,a.sync.onError(b)}function d(a,b){function d(){var d=b.content.srcList;l.path=b.content.path,g.onSyncing(),i.checksums(f,l.path,d,j,function(b,d){if(b)return c(a,b);l.step=n.PATCH;var e=h.request.diffs;e.content={checksums:d},m.send(e.stringify())})}function e(){i.diff(f,l.path,b.content.checksums,j,function(b,d){if(b)return c(a,b);l.step=n.PATCH;var e=h.response.diffs;e.content={diffs:k(d)},m.send(e.stringify())})}var f=a.fs,g=a.sync,l=a.session,m=a.socket;b.is.chksum&&l.is.ready&&(l.is.synced||l.is.failed)?d():b.is.diffs&&l.is.syncing&&l.is.diffs?e():c(a,new Error(b.content))}function e(a,b){function d(){p.state=m.SYNCING,p.step=n.INIT,p.path=b.content.path,o.onSyncing(),i.sourceList(k,p.path,j,function(b,d){if(b)return c(a,b);p.step=n.DIFFS;var e=h.request.chksum;e.content={srcList:d},q.send(e.stringify())})}function e(){p.state=m.READY,p.step=n.SYNCED,o.onCompleted(b.content.syncedPaths)}function f(){var d=b.content.diffs;d=l(d),i.patch(k,p.path,d,j,function(b,d){if(b)return c(a,b);var e=j.size||5;i.pathChecksums(k,d.synced,e,function(b,d){if(b)return c(a,b);var f=h.response.patch;f.content={checksums:d,size:e},q.send(f.stringify())})})}function g(){p.step=n.SYNCED,o.onCompleted()}var k=a.fs,o=a.sync,p=a.session,q=a.socket;b.is.sync?d():b.is.patch&&p.is.syncing&&p.is.patch?e():b.is.diffs&&p.is.ready&&p.is.patch?f():b.is.verification&&p.is.ready&&p.is.patch?g():c(a,new Error(b.content))}function f(a,b){var d=(a.sync,a.session),e=a.socket;if((b.is.srclist&&d.is.synced||b.is.verification&&d.is.synced)&&d.is.ready||b.is.diffs&&d.is.patch&&(d.is.ready||d.is.syncing)){d.state=m.READY,d.step=n.SYNCED;var f=h.request.reset;e.send(f.stringify()),c(a,new Error("Could not sync filesystem from server... trying again"))}else b.is.locked&&d.is.ready&&d.is.synced?c(a,new Error("Current sync in progress! Try again later!")):(b.is.chksum&&d.is.diffs||b.is.patch&&d.is.patch)&&d.is.syncing?c(a,new Error("Fatal error: Failed to sync to server")):c(a,new Error(b.content))}function g(a,b){try{b=JSON.parse(b),b=h.parse(b)}catch(g){return c(a,g)}b.is.request?d(a,b):b.is.response?e(a,b):b.is.error?f(a,b):c(a,new Error("Cannot handle message"))}var h=a("../../lib/syncmessage"),i=a("../../lib/rsync"),j=a("../../lib/constants").rsyncDefaults,k=a("../../lib/diff").serialize,l=a("../../lib/diff").deserialize,m=a("./sync-states"),n=a("./sync-steps");b.exports=g},{"../../lib/constants":69,"../../lib/diff":70,"../../lib/rsync":74,"../../lib/syncmessage":76,"./sync-states":6,"./sync-steps":7}],4:[function(a,b){function c(a){function b(b,c){g.fsetUnsynced(a,b,c)}function c(b,c){g.setUnsynced(a,b,c)}function d(b,c,d,e){return function(){var g=Array.prototype.slice.call(arguments,0),h=g.length-1,i=g[h],j=g[c];j=e?f.dirname(j):j,a.openFiles[j]||(k.pathToSync=j),g[h]=function(){var a=Array.prototype.slice.call(arguments,0);return a[0]?i(a[0]):void d(j,function(b){return b?i(b):void i.apply(null,a)})},a[b].apply(a,g)}}var j,k=this;Object.defineProperty(k,"pathToSync",{get:function(){return j},set:function(a){j=a?i(j,a):null}}),["stat","fstat","lstat","exists","readlink","realpath","readdir","open","close","fsync","read","readFile","setxattr","fsetxattr","getxattr","fgetxattr","removexattr","fremovexattr","watch"].forEach(function(b){k[b]=function(){a[b].apply(a,arguments)}}),["truncate","mknod","mkdir","utimes","writeFile","appendFile"].forEach(function(a){k[a]=d(a,0,c)}),["rename","link","symlink"].forEach(function(a){k[a]=d(a,1,c)}),["ftruncate","futimes","write"].forEach(function(a){k[a]=d(a,0,b)}),["rmdir","unlink"].forEach(function(a){k[a]=d(a,0,c,!0)});var l=k.rename;k.rename=function(b,c,d){l(b,c,function(b){return b?d(b):void h.isConflictedCopy(a,c,function(b,e){return b?d(b):void(e?h.removeFileConflict(a,c,d):d())})})},k.Shell=function(a){return new e(k,a)},k.getUnsynced=function(b,c){g.getUnsynced(a,b,c)},k.fgetUnsynced=function(b,c){g.fgetUnsynced(a,b,c)}}var d=a("../../lib/filer.js"),e=a("../../lib/filer-shell.js"),f=d.Path,g=a("../../lib/fs-utils.js"),h=a("../../lib/conflict.js"),i=(a("../../lib/constants.js"),a("../../lib/sync-path-resolver.js").resolve);b.exports=c},{"../../lib/conflict.js":68,"../../lib/constants.js":69,"../../lib/filer-shell.js":71,"../../lib/filer.js":72,"../../lib/fs-utils.js":73,"../../lib/sync-path-resolver.js":75}],5:[function(a,b){function c(a,b){var c=this;c.sync=a,c.fs=b,c.session={state:f.CLOSED,step:g.SYNCED,path:"/",is:Object.create(Object.prototype,{syncing:{get:function(){return c.session.state===f.SYNCING}},ready:{get:function(){return c.session.state===f.READY}},error:{get:function(){return c.session.state===f.ERROR}},closed:{get:function(){return c.session.state===f.CLOSED}},init:{get:function(){return c.session.step===g.INIT}},chksum:{get:function(){return c.session.step===g.CHKSUM}},diffs:{get:function(){return c.session.step===g.DIFFS}},patch:{get:function(){return c.session.step===g.PATCH}},synced:{get:function(){return c.session.step===g.SYNCED}},failed:{get:function(){return c.session.step===g.FAILED}}})}}var d=a("../../lib/syncmessage"),e=a("./message-handler"),f=a("./sync-states"),g=a("./sync-steps"),h=a("ws"),i=a("../../lib/fs-utils"),j=a("async");c.prototype.init=function(a,b,c){function i(a){var b=a.data||a;try{b=JSON.parse(b),b=d.parse(b)}catch(h){return c(h)}b.is.response&&b.is.authz?(l.state=f.READY,l.step=g.SYNCED,n.onmessage=function(a){var b=a.data||a;e(k,b)},n.send(d.response.authz.stringify()),c()):c(new Error("Cannot handle message"))}function j(a){var b=a.reason||"WebSocket closed unexpectedly",c=new Error(a.code+": "+b);k.close(),k.socket=null,m.onError(c),m.onDisconnected()}var k=this,l=k.session,m=k.sync,n=k.socket=new h(a);n.onmessage=i,n.onclose=j,n.onopen=function(){n.send(JSON.stringify({token:b}))}},c.prototype.syncPath=function(a){var b,c=this;if(!c.socket)throw new Error("sync called before init");b=d.request.sync,b.content={path:a},c.socket.send(b.stringify())},c.prototype.resetUnsynced=function(a,b){function c(a,b){i.removeUnsynced(d,a,function(a){return a&&"ENOENT"!==a.code?b(a):void b()})}var d=this.fs;j.eachSeries(a,c,function(a){return a?b(a):void b()})},c.prototype.close=function(){var a=this,b=a.socket;b&&(b.onmessage=function(){},b.onopen=function(){},1===b.readyState?(b.onclose=function(){a.socket=null},b.close()):a.socket=null)},b.exports=c},{"../../lib/fs-utils":73,"../../lib/syncmessage":76,"./message-handler":3,"./sync-states":6,"./sync-steps":7,async:80,ws:1}],6:[function(a,b){b.exports={SYNCING:"SYNC IN PROGRESS",READY:"READY",ERROR:"ERROR",CLOSED:"CLOSED"}},{}],7:[function(a,b){b.exports={INIT:"SYNC INITIALIZED",CHKSUM:"CHECKSUM",DIFFS:"DIFFS",PATCH:"PATCH",SYNCED:"SYNCED",FAILED:"FAILED"}},{}],8:[function(b,c){(function(b){!function(){function d(a){var b=!1;return function(){if(b)throw new Error("Callback was already called.");b=!0,a.apply(e,arguments)}}var e,f,g={};e=this,null!=e&&(f=e.async),g.noConflict=function(){return e.async=f,g};var h=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c+=1)b(a[c],c,a)},i=function(a,b){if(a.map)return a.map(b);var c=[];return h(a,function(a,d,e){c.push(b(a,d,e))}),c},j=function(a,b,c){return a.reduce?a.reduce(b,c):(h(a,function(a,d,e){c=b(c,a,d,e)}),c)},k=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b};"undefined"!=typeof b&&b.nextTick?(g.nextTick=b.nextTick,g.setImmediate="undefined"!=typeof setImmediate?function(a){setImmediate(a)}:g.nextTick):"function"==typeof setImmediate?(g.nextTick=function(a){setImmediate(a)},g.setImmediate=g.nextTick):(g.nextTick=function(a){setTimeout(a,0)},g.setImmediate=g.nextTick),g.each=function(a,b,c){if(c=c||function(){},!a.length)return c();var e=0;h(a,function(f){b(f,d(function(b){b?(c(b),c=function(){}):(e+=1,e>=a.length&&c(null))}))})},g.forEach=g.each,g.eachSeries=function(a,b,c){if(c=c||function(){},!a.length)return c();var d=0,e=function(){b(a[d],function(b){b?(c(b),c=function(){}):(d+=1,d>=a.length?c(null):e())})};e()},g.forEachSeries=g.eachSeries,g.eachLimit=function(a,b,c,d){var e=l(b);e.apply(null,[a,c,d])},g.forEachLimit=g.eachLimit;var l=function(a){return function(b,c,d){if(d=d||function(){},!b.length||0>=a)return d();var e=0,f=0,g=0;!function h(){if(e>=b.length)return d();for(;a>g&&f<b.length;)f+=1,g+=1,c(b[f-1],function(a){a?(d(a),d=function(){}):(e+=1,g-=1,e>=b.length?d():h())})}()}},m=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[g.each].concat(b))}},n=function(a,b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[l(a)].concat(c))}},o=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[g.eachSeries].concat(b))}},p=function(a,b,c,d){var e=[];b=i(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c,d){e[a.index]=d,b(c)})},function(a){d(a,e)})};g.map=m(p),g.mapSeries=o(p),g.mapLimit=function(a,b,c,d){return q(b)(a,c,d)};var q=function(a){return n(a,p)};g.reduce=function(a,b,c,d){g.eachSeries(a,function(a,d){c(b,a,function(a,c){b=c,d(a)})},function(a){d(a,b)})},g.inject=g.reduce,g.foldl=g.reduce,g.reduceRight=function(a,b,c,d){var e=i(a,function(a){return a}).reverse();g.reduce(e,b,c,d)},g.foldr=g.reduceRight;var r=function(a,b,c,d){var e=[];b=i(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c&&e.push(a),b()})},function(){d(i(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};g.filter=m(r),g.filterSeries=o(r),g.select=g.filter,g.selectSeries=g.filterSeries;var s=function(a,b,c,d){var e=[];b=i(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c||e.push(a),b()})},function(){d(i(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};g.reject=m(s),g.rejectSeries=o(s);var t=function(a,b,c,d){a(b,function(a,b){c(a,function(c){c?(d(a),d=function(){}):b()})},function(){d()})};g.detect=m(t),g.detectSeries=o(t),g.some=function(a,b,c){g.each(a,function(a,d){b(a,function(a){a&&(c(!0),c=function(){}),d()})},function(){c(!1)})},g.any=g.some,g.every=function(a,b,c){g.each(a,function(a,d){b(a,function(a){a||(c(!1),c=function(){}),d()})},function(){c(!0)})},g.all=g.every,g.sortBy=function(a,b,c){g.map(a,function(a,c){b(a,function(b,d){b?c(b):c(null,{value:a,criteria:d})})},function(a,b){if(a)return c(a);var d=function(a,b){var c=a.criteria,d=b.criteria;return d>c?-1:c>d?1:0};c(null,i(b.sort(d),function(a){return a.value}))})},g.auto=function(a,b){b=b||function(){};var c=k(a);if(!c.length)return b(null);var d={},e=[],f=function(a){e.unshift(a)},i=function(a){for(var b=0;b<e.length;b+=1)if(e[b]===a)return void e.splice(b,1)},l=function(){h(e.slice(0),function(a){a()})};f(function(){k(d).length===c.length&&(b(null,d),b=function(){})}),h(c,function(c){var e=a[c]instanceof Function?[a[c]]:a[c],m=function(a){var e=Array.prototype.slice.call(arguments,1);if(e.length<=1&&(e=e[0]),a){var f={};h(k(d),function(a){f[a]=d[a]}),f[c]=e,b(a,f),b=function(){}}else d[c]=e,g.setImmediate(l)},n=e.slice(0,Math.abs(e.length-1))||[],o=function(){return j(n,function(a,b){return a&&d.hasOwnProperty(b)},!0)&&!d.hasOwnProperty(c)};if(o())e[e.length-1](m,d);else{var p=function(){o()&&(i(p),e[e.length-1](m,d))};f(p)}})},g.waterfall=function(a,b){if(b=b||function(){},a.constructor!==Array){var c=new Error("First argument to waterfall must be an array of functions");return b(c)}if(!a.length)return b();var d=function(a){return function(c){if(c)b.apply(null,arguments),b=function(){};else{var e=Array.prototype.slice.call(arguments,1),f=a.next();e.push(f?d(f):b),g.setImmediate(function(){a.apply(null,e)})}}};d(g.iterator(a))()};var u=function(a,b,c){if(c=c||function(){},b.constructor===Array)a.map(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},c);else{var d={};a.each(k(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}};g.parallel=function(a,b){u({map:g.map,each:g.each},a,b)},g.parallelLimit=function(a,b,c){u({map:q(b),each:l(b)},a,c)},g.series=function(a,b){if(b=b||function(){},a.constructor===Array)g.mapSeries(a,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},b);else{var c={};g.eachSeries(k(a),function(b,d){a[b](function(a){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),c[b]=e,d(a)})},function(a){b(a,c)})}},g.iterator=function(a){var b=function(c){var d=function(){return a.length&&a[c].apply(null,arguments),d.next()};return d.next=function(){return c<a.length-1?b(c+1):null},d};return b(0)},g.apply=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b.concat(Array.prototype.slice.call(arguments)))}};var v=function(a,b,c,d){var e=[];a(b,function(a,b){c(a,function(a,c){e=e.concat(c||[]),b(a)})},function(a){d(a,e)})};g.concat=m(v),g.concatSeries=o(v),g.whilst=function(a,b,c){a()?b(function(d){return d?c(d):void g.whilst(a,b,c)}):c()},g.doWhilst=function(a,b,c){a(function(d){return d?c(d):void(b()?g.doWhilst(a,b,c):c())})},g.until=function(a,b,c){a()?c():b(function(d){return d?c(d):void g.until(a,b,c)})},g.doUntil=function(a,b,c){a(function(d){return d?c(d):void(b()?c():g.doUntil(a,b,c))})},g.queue=function(a,b){function c(a,c,d,e){c.constructor!==Array&&(c=[c]),h(c,function(c){var f={data:c,callback:"function"==typeof e?e:null};d?a.tasks.unshift(f):a.tasks.push(f),a.saturated&&a.tasks.length===b&&a.saturated(),g.setImmediate(a.process)})}void 0===b&&(b=1);var e=0,f={tasks:[],concurrency:b,saturated:null,empty:null,drain:null,push:function(a,b){c(f,a,!1,b)},unshift:function(a,b){c(f,a,!0,b)},process:function(){if(e<f.concurrency&&f.tasks.length){var b=f.tasks.shift();f.empty&&0===f.tasks.length&&f.empty(),e+=1;var c=function(){e-=1,b.callback&&b.callback.apply(b,arguments),f.drain&&f.tasks.length+e===0&&f.drain(),f.process()},g=d(c);a(b.data,g)}},length:function(){return f.tasks.length},running:function(){return e}};return f},g.cargo=function(a,b){var c=!1,d=[],e={tasks:d,payload:b,saturated:null,empty:null,drain:null,push:function(a,c){a.constructor!==Array&&(a=[a]),h(a,function(a){d.push({data:a,callback:"function"==typeof c?c:null}),e.saturated&&d.length===b&&e.saturated()}),g.setImmediate(e.process)},process:function f(){if(!c){if(0===d.length)return void(e.drain&&e.drain());var g="number"==typeof b?d.splice(0,b):d.splice(0),j=i(g,function(a){return a.data});e.empty&&e.empty(),c=!0,a(j,function(){c=!1;var a=arguments;h(g,function(b){b.callback&&b.callback.apply(null,a)}),f()})}},length:function(){return d.length},running:function(){return c}};return e};var w=function(a){return function(b){var c=Array.prototype.slice.call(arguments,1);b.apply(null,c.concat([function(b){var c=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(b?console.error&&console.error(b):console[a]&&h(c,function(b){console[a](b)}))}]))}};g.log=w("log"),g.dir=w("dir"),g.memoize=function(a,b){var c={},d={};b=b||function(a){return a};var e=function(){var e=Array.prototype.slice.call(arguments),f=e.pop(),g=b.apply(null,e);g in c?f.apply(null,c[g]):g in d?d[g].push(f):(d[g]=[f],a.apply(null,e.concat([function(){c[g]=arguments;var a=d[g];delete d[g];for(var b=0,e=a.length;e>b;b++)a[b].apply(null,arguments)}])))};return e.memo=c,e.unmemoized=a,e},g.unmemoize=function(a){return function(){return(a.unmemoized||a).apply(null,arguments)}},g.times=function(a,b,c){for(var d=[],e=0;a>e;e++)d.push(e);return g.map(d,b,c)},g.timesSeries=function(a,b,c){for(var d=[],e=0;a>e;e++)d.push(e);return g.mapSeries(d,b,c)},g.compose=function(){var a=Array.prototype.reverse.call(arguments);return function(){var b=this,c=Array.prototype.slice.call(arguments),d=c.pop();g.reduce(a,c,function(a,c,d){c.apply(b,a.concat([function(){var a=arguments[0],b=Array.prototype.slice.call(arguments,1);d(a,b)}]))},function(a,c){d.apply(b,[a].concat(c))})}};var x=function(a,b){var c=function(){var c=this,d=Array.prototype.slice.call(arguments),e=d.pop();return a(b,function(a,b){a.apply(c,d.concat([b]))},e)};if(arguments.length>2){var d=Array.prototype.slice.call(arguments,2);return c.apply(this,d)}return c};g.applyEach=m(x),g.applyEachSeries=o(x),g.forever=function(a,b){function c(d){if(d){if(b)return b(d);throw d}a(c)}c()},"undefined"!=typeof a&&a.amd?a([],function(){return g}):"undefined"!=typeof c&&c.exports?c.exports=g:e.async=g}()}).call(this,b("FWaASH"))},{FWaASH:85}],9:[function(a,b){function c(a,b){for(var c=b.length-1;c>=0;c--)b[c]===a&&b.splice(c,1);return b}var d=function(){};d.createInterface=function(a){var b={};return b.on=function(b,c){"undefined"==typeof this[a]&&(this[a]={}),this[a].hasOwnProperty(b)||(this[a][b]=[]),this[a][b].push(c)},b.off=function(b,d){"undefined"!=typeof this[a]&&this[a].hasOwnProperty(b)&&c(d,this[a][b])},b.trigger=function(b){if("undefined"!=typeof this[a]&&this[a].hasOwnProperty(b))for(var c=Array.prototype.slice.call(arguments,1),d=0;d<this[a][b].length;d++)this[a][b][d].apply(this[a][b][d],c)},b.removeAllListeners=function(b){if("undefined"!=typeof this[a]){var c=this;c[a][b].forEach(function(a){c.off(b,a)})}},b};var e=d.createInterface("_handlers");d.prototype._on=e.on,d.prototype._off=e.off,d.prototype._trigger=e.trigger;var f=d.createInterface("handlers");d.prototype.on=function(){f.on.apply(this,arguments),Array.prototype.unshift.call(arguments,"on"),this._trigger.apply(this,arguments)},d.prototype.off=f.off,d.prototype.trigger=f.trigger,d.prototype.removeAllListeners=f.removeAllListeners,b.exports=d},{}],10:[function(a,b){(function(c){function d(a,b){var c=0;return function(){var d=Date.now();d-c>a&&(c=d,b.apply(this,arguments))}}function e(a,b){if("undefined"!=typeof a&&a||(a={}),"object"==typeof b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function f(){var a=this,b=Date.now();this.origin=h(),this.lastMessage=b,this.receivedIDs={},this.previousValues={};var d=function(){a._onStorageEvent.apply(a,arguments)};"undefined"!=typeof document&&(document.attachEvent?document.attachEvent("onstorage",d):c.addEventListener("storage",d,!1))}var g=a("./eventemitter.js"),h=a("../src/shared.js").guid,i=function(a){return"undefined"==typeof a||"undefined"==typeof a.localStorage?{getItem:function(){},setItem:function(){},removeItem:function(){}}:a.localStorage}(c);f.prototype._transaction=function(a){function b(){if(!g){var k=Date.now(),m=0|i.getItem(l);if(m&&d>k-m)return h||(f._on("storage",b),h=!0),void(j=setTimeout(b,e));g=!0,i.setItem(l,k),a(),c()}}function c(){h&&f._off("storage",b),j&&clearTimeout(j),i.removeItem(l)}var d=1e3,e=20,f=this,g=!1,h=!1,j=null;b()},f.prototype._cleanup_emit=d(100,function(){var a=this;a._transaction(function(){var a,b=Date.now(),c=b-m,d=0;try{a=JSON.parse(i.getItem(j)||"[]")}catch(e){a=[]}for(var f=a.length-1;f>=0;f--)a[f].timestamp<c&&(a.splice(f,1),d++);d>0&&i.setItem(j,JSON.stringify(a))})}),f.prototype._cleanup_once=d(100,function(){var a=this;a._transaction(function(){var b,c,d=(Date.now(),0);try{c=JSON.parse(i.getItem(k)||"{}")}catch(e){c={}}for(b in c)a._once_expired(b,c)&&(delete c[b],d++);d>0&&i.setItem(k,JSON.stringify(c))})}),f.prototype._once_expired=function(a,b){if(!b)return!0;if(!b.hasOwnProperty(a))return!0;if("object"!=typeof b[a])return!0;var c=b[a].ttl||n,d=Date.now(),e=b[a].timestamp;return d-c>e},f.prototype._localStorageChanged=function(a,b){if(a&&a.key)return a.key===b;var c=i.getItem(b);return c===this.previousValues[b]?!1:(this.previousValues[b]=c,!0)},f.prototype._onStorageEvent=function(a){a=a||c.event;var b=this;this._localStorageChanged(a,j)&&this._transaction(function(){var a,c=Date.now(),d=i.getItem(j);try{a=JSON.parse(d||"[]")}catch(e){a=[]}for(var f=0;f<a.length;f++)if(a[f].origin!==b.origin&&!(a[f].timestamp<b.lastMessage)){if(a[f].id){if(b.receivedIDs.hasOwnProperty(a[f].id))continue;b.receivedIDs[a[f].id]=!0}b.trigger(a[f].name,a[f].payload)}b.lastMessage=c}),this._trigger("storage",a)},f.prototype._emit=function(a,b,c){if(c="string"==typeof c||"number"==typeof c?String(c):null,c&&c.length){if(this.receivedIDs.hasOwnProperty(c))return;this.receivedIDs[c]=!0}var d={id:c,name:a,origin:this.origin,timestamp:Date.now(),payload:b},e=this;this._transaction(function(){var c=i.getItem(j)||"[]",f="[]"===c?"":",";c=[c.substring(0,c.length-1),f,JSON.stringify(d),"]"].join(""),i.setItem(j,c),e.trigger(a,b),setTimeout(function(){e._cleanup_emit()},50)})},f.prototype.emit=function(a,b){this._emit.apply(this,arguments),this._trigger("emit",a,b)},f.prototype.once=function(a,b,c){if(f.supported){var d=this;this._transaction(function(){var e;try{e=JSON.parse(i.getItem(k)||"{}")}catch(f){e={}}d._once_expired(a,e)&&(e[a]={},e[a].timestamp=Date.now(),"number"==typeof c&&(e[a].ttl=1e3*c),i.setItem(k,JSON.stringify(e)),b(),setTimeout(function(){d._cleanup_once()},50))})}},e(f.prototype,g.prototype),f.supported="undefined"!=typeof i;var j="intercom",k="intercom_once",l="intercom_lock",m=5e4,n=36e5;f.destroy=function(){i.removeItem(l),i.removeItem(j),i.removeItem(k)},f.getInstance=function(){var a;return function(){return a||(a=new f),a}}(),b.exports=f}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../src/shared.js":62,"./eventemitter.js":9}],11:[function(a,b){function c(a,b){return p.call(a,b)}function d(a){return null==a?0:a.length===+a.length?a.length:s(a).length}function e(a){return a}function f(a,b,c){var d,e;if(null!=a)if(l&&a.forEach===l)a.forEach(b,c);else if(a.length===+a.length){for(d=0,e=a.length;e>d;d++)if(b.call(c,a[d],d,a)===r)return}else{var f=f(a);for(d=0,e=f.length;e>d;d++)if(b.call(c,a[f[d]],f[d],a)===r)return}}function g(a,b,c){b||(b=e);var d=!1;return null==a?d:n&&a.some===n?a.some(b,c):(f(a,function(a,e,f){return d||(d=b.call(c,a,e,f))?r:void 0}),!!d)}function h(a,b){return null==a?!1:m&&a.indexOf===m?-1!=a.indexOf(b):g(a,function(a){return a===b})}function i(a){this.value=a}function j(a){return a&&"object"==typeof a&&!Array.isArray(a)&&p.call(a,"__wrapped__")?a:new i(a)}var k=Array.prototype,l=k.forEach,m=k.indexOf,n=k.some,o=Object.prototype,p=o.hasOwnProperty,q=Object.keys,r={},s=q||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var d in a)c(a,d)&&b.push(d);return b};i.prototype.has=function(a){return c(this.value,a)},i.prototype.contains=function(a){return h(this.value,a)},i.prototype.size=function(){return d(this.value)},b.exports=j},{}],12:[function(a,b){(function(a){function c(a,b){if("function"!=typeof b)throw new Error("Bad callback given: "+b);if(!a)throw new Error("No options given");var g=a.onResponse;if(a="string"==typeof a?{uri:a}:JSON.parse(JSON.stringify(a)),a.onResponse=g,a.verbose&&(c.log=f()),a.url&&(a.uri=a.url,delete a.url),!a.uri&&""!==a.uri)throw new Error("options.uri is a required argument");if("string"!=typeof a.uri)throw new Error("options.uri must be a string");for(var h=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],j=0;j<h.length;j++)if(a[h[j]])throw new Error("options."+h[j]+" is not supported");if(a.callback=b,a.method=a.method||"GET",a.headers=a.headers||{},a.body=a.body||null,a.timeout=a.timeout||c.DEFAULT_TIMEOUT,a.headers.host)throw new Error("Options.headers.host is not supported");a.json&&(a.headers.accept=a.headers.accept||"application/json","GET"!==a.method&&(a.headers["content-type"]="application/json"),"boolean"!=typeof a.json?a.body=JSON.stringify(a.json):"string"!=typeof a.body&&(a.body=JSON.stringify(a.body)));var k=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")};if(a.qs){var l="string"==typeof a.qs?a.qs:k(a.qs);a.uri=-1!==a.uri.indexOf("?")?a.uri+"&"+l:a.uri+"?"+l}var m=function(a){var b={};b.boundry="-------------------------------"+Math.floor(1e9*Math.random());var c=[];for(var d in a)a.hasOwnProperty(d)&&c.push("--"+b.boundry+'\nContent-Disposition: form-data; name="'+d+'"\n\n'+a[d]+"\n");return c.push("--"+b.boundry+"--"),b.body=c.join(""),b.length=b.body.length,b.type="multipart/form-data; boundary="+b.boundry,b};if(a.form){if("string"==typeof a.form)throw"form name unsupported";if("POST"===a.method){var n=(a.encoding||"application/x-www-form-urlencoded").toLowerCase();switch(a.headers["content-type"]=n,n){case"application/x-www-form-urlencoded":a.body=k(a.form).replace(/%20/g,"+");break;case"multipart/form-data":var o=m(a.form);a.body=o.body,a.headers["content-type"]=o.type;break;default:throw new Error("unsupported encoding:"+n)}}}return a.onResponse=a.onResponse||e,a.onResponse===!0&&(a.onResponse=b,a.callback=e),!a.headers.authorization&&a.auth&&(a.headers.authorization="Basic "+i(a.auth.username+":"+a.auth.password)),d(a)}function d(b){function d(){m=!0;var a=new Error("ETIMEDOUT");return a.code="ETIMEDOUT",a.duration=b.timeout,c.log.error("Timeout",{id:k._id,milliseconds:b.timeout}),b.callback(a,k)}function e(){if(m)return c.log.debug("Ignoring timed out state change",{state:k.readyState,id:k.id});if(c.log.debug("State change",{state:k.readyState,id:k.id,timed_out:m}),k.readyState===j.OPENED){c.log.debug("Request started",{id:k.id});for(var a in b.headers)k.setRequestHeader(a,b.headers[a])}else k.readyState===j.HEADERS_RECEIVED?f():k.readyState===j.LOADING?(f(),g()):k.readyState===j.DONE&&(f(),g(),i())}function f(){if(!q.response){if(q.response=!0,c.log.debug("Got response",{id:k.id,status:k.status}),clearTimeout(k.timeoutTimer),k.statusCode=k.status,n&&0==k.statusCode){var a=new Error("CORS request rejected: "+b.uri);return a.cors="rejected",q.loading=!0,q.end=!0,b.callback(a,k)}b.onResponse(null,k)}}function g(){q.loading||(q.loading=!0,c.log.debug("Response body loading",{id:k.id}))}function i(){if(!q.end){if(q.end=!0,c.log.debug("Request done",{id:k.id}),null===b.encoding)k.body=new a(new Uint8Array(k.response));else if(k.body=k.responseText,b.json)try{k.body=JSON.parse(k.responseText)}catch(d){return b.callback(d,k)}b.callback(null,k,k.body)}}var k=new j,m=!1,n=h(b.uri),o="withCredentials"in k;if(l+=1,k.seq_id=l,k.id=l+": "+b.method+" "+b.uri,k._id=k.id,n&&!o){var p=new Error("Browser does not support cross-origin request: "+b.uri);return p.cors="unsupported",b.callback(p,k)}k.timeoutTimer=setTimeout(d,b.timeout);var q={response:!1,loading:!1,end:!1};return k.onreadystatechange=e,k.open(b.method,b.uri,!0),null===b.encoding&&(k.responseType="arraybuffer"),n&&(k.withCredentials=!!b.withCredentials),k.send(b.body),k}function e(){}function f(){var a,b,c={},d=["trace","debug","info","warn","error"];for(b=0;b<d.length;b++)a=d[b],c[a]=e,"undefined"!=typeof console&&console&&console[a]&&(c[a]=g(console,a));return c}function g(a,b){function c(c,d){return"object"==typeof d&&(c+=" "+JSON.stringify(d)),a[b].call(a,c)}return c}function h(a){var b,c=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/;try{b=location.href}catch(d){b=document.createElement("a"),b.href="",b=b.href}var e=c.exec(b.toLowerCase())||[],f=c.exec(a.toLowerCase()),g=!(!f||f[1]==e[1]&&f[2]==e[2]&&(f[3]||("http:"===f[1]?80:443))==(e[3]||("http:"===e[1]?80:443)));return g}function i(a){var b,c,d,e,f,g,h,i,j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",k=0,l=0,m="",n=[];if(!a)return a;do b=a.charCodeAt(k++),c=a.charCodeAt(k++),d=a.charCodeAt(k++),i=b<<16|c<<8|d,e=i>>18&63,f=i>>12&63,g=i>>6&63,h=63&i,n[l++]=j.charAt(e)+j.charAt(f)+j.charAt(g)+j.charAt(h);while(k<a.length);switch(m=n.join(""),a.length%3){case 1:m=m.slice(0,-2)+"==";break;case 2:m=m.slice(0,-1)+"="}return m}var j=XMLHttpRequest;if(!j)throw new Error("missing XMLHttpRequest");c.log={trace:e,debug:e,info:e,warn:e,error:e};var k=18e4,l=0; c.withCredentials=!1,c.DEFAULT_TIMEOUT=k,c.defaults=function(a){var b=function(b){var c=function(c,d){c="string"==typeof c?{uri:c}:JSON.parse(JSON.stringify(c));for(var e in a)void 0===c[e]&&(c[e]=a[e]);return b(c,d)};return c},d=b(c);return d.get=b(c.get),d.post=b(c.post),d.put=b(c.put),d.head=b(c.head),d};var m=["get","put","post","head"];m.forEach(function(a){var b=a.toUpperCase(),d=a.toLowerCase();c[d]=function(a){"string"==typeof a?a={method:b,uri:a}:(a=JSON.parse(JSON.stringify(a)),a.method=b);var d=[a].concat(Array.prototype.slice.apply(arguments,[1]));return c.apply(this,d)}}),c.couch=function(a,b){function d(a,c,d){if(a)return b(a,c,d);if((c.statusCode<200||c.statusCode>299)&&d.error){a=new Error("CouchDB error: "+(d.error.reason||d.error.error));for(var e in d)a[e]=d[e];return b(a,c,d)}return b(a,c,d)}"string"==typeof a&&(a={uri:a}),a.json=!0,a.body&&(a.json=a.body),delete a.body,b=b||e;var f=c(a,d);return f},b.exports=c}).call(this,a("buffer").Buffer)},{buffer:82}],13:[function(a,b,c){"use strict";var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";c.encode=function(a){for(var b,c,e,f,g,h,i,j="",k=0;k<a.length;)b=a.charCodeAt(k++),c=a.charCodeAt(k++),e=a.charCodeAt(k++),f=b>>2,g=(3&b)<<4|c>>4,h=(15&c)<<2|e>>6,i=63&e,isNaN(c)?h=i=64:isNaN(e)&&(i=64),j=j+d.charAt(f)+d.charAt(g)+d.charAt(h)+d.charAt(i);return j},c.decode=function(a){var b,c,e,f,g,h,i,j="",k=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");k<a.length;)f=d.indexOf(a.charAt(k++)),g=d.indexOf(a.charAt(k++)),h=d.indexOf(a.charAt(k++)),i=d.indexOf(a.charAt(k++)),b=f<<2|g>>4,c=(15&g)<<4|h>>2,e=(3&h)<<6|i,j+=String.fromCharCode(b),64!=h&&(j+=String.fromCharCode(c)),64!=i&&(j+=String.fromCharCode(e));return j}},{}],14:[function(a,b){"use strict";function c(){this.compressedSize=0,this.uncompressedSize=0,this.crc32=0,this.compressionMethod=null,this.compressedContent=null}c.prototype={getContent:function(){return null},getCompressedContent:function(){return null}},b.exports=c},{}],15:[function(a,b,c){"use strict";c.STORE={magic:"\x00\x00",compress:function(a){return a},uncompress:function(a){return a},compressInputType:null,uncompressInputType:null},c.DEFLATE=a("./flate")},{"./flate":18}],16:[function(a,b){"use strict";function c(){this.data=null,this.length=0,this.index=0}var d=a("./utils");c.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length<a||0>a)throw new Error("End of data reached (data length = "+this.length+", asked index = "+a+"). Corrupted zip ?")},setIndex:function(a){this.checkIndex(a),this.index=a},skip:function(a){this.setIndex(this.index+a)},byteAt:function(){},readInt:function(a){var b,c=0;for(this.checkOffset(a),b=this.index+a-1;b>=this.index;b--)c=(c<<8)+this.byteAt(b);return this.index+=a,c},readString:function(a){return d.transformTo("string",this.readData(a))},readData:function(){},lastIndexOfSignature:function(){},readDate:function(){var a=this.readInt(4);return new Date((a>>25&127)+1980,(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1)}},b.exports=c},{"./utils":28}],17:[function(a,b,c){"use strict";c.base64=!1,c.binary=!1,c.dir=!1,c.date=null,c.compression=null},{}],18:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,e=a("pako");c.uncompressInputType=d?"uint8array":"array",c.compressInputType=d?"uint8array":"array",c.magic="\b\x00",c.compress=function(a){return e.deflateRaw(a)},c.uncompress=function(a){return e.inflateRaw(a)}},{pako:31}],19:[function(a,b){"use strict";function c(a,b){return this instanceof c?(this.files={},this.root="",a&&this.load(a,b),void(this.clone=function(){var a=new c;for(var b in this)"function"!=typeof this[b]&&(a[b]=this[b]);return a})):new c(a,b)}c.prototype=a("./object"),c.prototype.load=a("./load"),c.support=a("./support"),c.defaults=a("./defaults"),c.utils=a("./utils"),c.base64=a("./base64"),c.compressions=a("./compressions"),b.exports=c},{"./base64":13,"./compressions":15,"./defaults":17,"./load":20,"./object":23,"./support":26,"./utils":28}],20:[function(a,b){"use strict";var c=a("./base64"),d=a("./zipEntries");b.exports=function(a,b){var e,f,g,h;for(b=b||{},b.base64&&(a=c.decode(a)),f=new d(a,b),e=f.files,g=0;g<e.length;g++)h=e[g],this.file(h.fileName,h.decompressed,{binary:!0,optimizedBinaryString:!0,date:h.date,dir:h.dir});return this}},{"./base64":13,"./zipEntries":29}],21:[function(a,b){(function(a){"use strict";b.exports=function(b,c){return new a(b,c)},b.exports.test=function(b){return a.isBuffer(b)}}).call(this,a("buffer").Buffer)},{buffer:82}],22:[function(a,b){"use strict";function c(a){this.data=a,this.length=this.data.length,this.index=0}var d=a("./uint8ArrayReader");c.prototype=new d,c.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./uint8ArrayReader":27}],23:[function(a,b){"use strict";var c,d,e=a("./support"),f=a("./utils"),g=a("./signature"),h=a("./defaults"),i=a("./base64"),j=a("./compressions"),k=a("./compressedObject"),l=a("./nodeBuffer");e.uint8array&&"function"==typeof TextEncoder&&"function"==typeof TextDecoder&&(c=new TextEncoder("utf-8"),d=new TextDecoder("utf-8"));var m=function(a){if(a._data instanceof k&&(a._data=a._data.getContent(),a.options.binary=!0,a.options.base64=!1,"uint8array"===f.getTypeOf(a._data))){var b=a._data;a._data=new Uint8Array(b.length),0!==b.length&&a._data.set(b,0)}return a._data},n=function(a){var b=m(a),d=f.getTypeOf(b);if("string"===d){if(!a.options.binary){if(c)return c.encode(b);if(e.nodebuffer)return l(b,"utf-8")}return a.asBinary()}return b},o=function(a){var b=m(this);return null===b||"undefined"==typeof b?"":(this.options.base64&&(b=i.decode(b)),b=a&&this.options.binary?z.utf8decode(b):f.transformTo("string",b),a||this.options.binary||(b=z.utf8encode(b)),b)},p=function(a,b,c){this.name=a,this._data=b,this.options=c};p.prototype={asText:function(){return o.call(this,!0)},asBinary:function(){return o.call(this,!1)},asNodeBuffer:function(){var a=n(this);return f.transformTo("nodebuffer",a)},asUint8Array:function(){var a=n(this);return f.transformTo("uint8array",a)},asArrayBuffer:function(){return this.asUint8Array().buffer}};var q=function(a,b){var c,d="";for(c=0;b>c;c++)d+=String.fromCharCode(255&a),a>>>=8;return d},r=function(){var a,b,c={};for(a=0;a<arguments.length;a++)for(b in arguments[a])arguments[a].hasOwnProperty(b)&&"undefined"==typeof c[b]&&(c[b]=arguments[a][b]);return c},s=function(a){return a=a||{},a.base64!==!0||null!==a.binary&&void 0!==a.binary||(a.binary=!0),a=r(a,h),a.date=a.date||new Date,null!==a.compression&&(a.compression=a.compression.toUpperCase()),a},t=function(a,b,c){var d=f.getTypeOf(b);if(c=s(c),c.dir||null===b||"undefined"==typeof b)c.base64=!1,c.binary=!1,b=null;else if("string"===d)c.binary&&!c.base64&&c.optimizedBinaryString!==!0&&(b=f.string2binary(b));else{if(c.base64=!1,c.binary=!0,!(d||b instanceof k))throw new Error("The data of '"+a+"' is in an unsupported format !");"arraybuffer"===d&&(b=f.transformTo("uint8array",b))}var e=new p(a,b,c);return this.files[a]=e,e},u=function(a){return"/"!=a.slice(-1)&&(a+="/"),this.files[a]||t.call(this,a,null,{dir:!0}),this.files[a]},v=function(a,b){var c,d=new k;return a._data instanceof k?(d.uncompressedSize=a._data.uncompressedSize,d.crc32=a._data.crc32,0===d.uncompressedSize||a.options.dir?(b=j.STORE,d.compressedContent="",d.crc32=0):a._data.compressionMethod===b.magic?d.compressedContent=a._data.getCompressedContent():(c=a._data.getContent(),d.compressedContent=b.compress(f.transformTo(b.compressInputType,c)))):(c=n(a),(!c||0===c.length||a.options.dir)&&(b=j.STORE,c=""),d.uncompressedSize=c.length,d.crc32=this.crc32(c),d.compressedContent=b.compress(f.transformTo(b.compressInputType,c))),d.compressedSize=d.compressedContent.length,d.compressionMethod=b.magic,d},w=function(a,b,c,d){var e,f,h=(c.compressedContent,this.utf8encode(b.name)),i=h!==b.name,j=b.options,k="",l="";e=j.date.getHours(),e<<=6,e|=j.date.getMinutes(),e<<=5,e|=j.date.getSeconds()/2,f=j.date.getFullYear()-1980,f<<=4,f|=j.date.getMonth()+1,f<<=5,f|=j.date.getDate(),i&&(l=q(1,1)+q(this.crc32(h),4)+h,k+="up"+q(l.length,2)+l);var m="";m+="\n\x00",m+=i?"\x00\b":"\x00\x00",m+=c.compressionMethod,m+=q(e,2),m+=q(f,2),m+=q(c.crc32,4),m+=q(c.compressedSize,4),m+=q(c.uncompressedSize,4),m+=q(h.length,2),m+=q(k.length,2);var n=g.LOCAL_FILE_HEADER+m+h+k,o=g.CENTRAL_FILE_HEADER+"\x00"+m+"\x00\x00\x00\x00\x00\x00"+(b.options.dir===!0?"\x00\x00\x00":"\x00\x00\x00\x00")+q(d,4)+h+k;return{fileRecord:n,dirRecord:o,compressedObject:c}},x=function(){this.data=[]};x.prototype={append:function(a){a=f.transformTo("string",a),this.data.push(a)},finalize:function(){return this.data.join("")}};var y=function(a){this.data=new Uint8Array(a),this.index=0};y.prototype={append:function(a){0!==a.length&&(a=f.transformTo("uint8array",a),this.data.set(a,this.index),this.index+=a.length)},finalize:function(){return this.data}};var z={load:function(){throw new Error("Load method is not defined. Is the file jszip-load.js included ?")},filter:function(a){var b,c,d,e,f=[];for(b in this.files)this.files.hasOwnProperty(b)&&(d=this.files[b],e=new p(d.name,d._data,r(d.options)),c=b.slice(this.root.length,b.length),b.slice(0,this.root.length)===this.root&&a(c,e)&&f.push(e));return f},file:function(a,b,c){if(1===arguments.length){if(f.isRegExp(a)){var d=a;return this.filter(function(a,b){return!b.options.dir&&d.test(a)})}return this.filter(function(b,c){return!c.options.dir&&b===a})[0]||null}return a=this.root+a,t.call(this,a,b,c),this},folder:function(a){if(!a)return this;if(f.isRegExp(a))return this.filter(function(b,c){return c.options.dir&&a.test(b)});var b=this.root+a,c=u.call(this,b),d=this.clone();return d.root=c.name,d},remove:function(a){a=this.root+a;var b=this.files[a];if(b||("/"!=a.slice(-1)&&(a+="/"),b=this.files[a]),b&&!b.options.dir)delete this.files[a];else for(var c=this.filter(function(b,c){return c.name.slice(0,a.length)===a}),d=0;d<c.length;d++)delete this.files[c[d].name];return this},generate:function(a){a=r(a||{},{base64:!0,compression:"STORE",type:"base64"}),f.checkSupport(a.type);var b,c,d=[],e=0,h=0;for(var k in this.files)if(this.files.hasOwnProperty(k)){var l=this.files[k],m=l.options.compression||a.compression.toUpperCase(),n=j[m];if(!n)throw new Error(m+" is not a valid compression method !");var o=v.call(this,l,n),p=w.call(this,k,l,o,e);e+=p.fileRecord.length+o.compressedSize,h+=p.dirRecord.length,d.push(p)}var s="";s=g.CENTRAL_DIRECTORY_END+"\x00\x00\x00\x00"+q(d.length,2)+q(d.length,2)+q(h,4)+q(e,4)+"\x00\x00";var t=a.type.toLowerCase();for(b="uint8array"===t||"arraybuffer"===t||"blob"===t||"nodebuffer"===t?new y(e+h+s.length):new x(e+h+s.length),c=0;c<d.length;c++)b.append(d[c].fileRecord),b.append(d[c].compressedObject.compressedContent);for(c=0;c<d.length;c++)b.append(d[c].dirRecord);b.append(s);var u=b.finalize();switch(a.type.toLowerCase()){case"uint8array":case"arraybuffer":case"nodebuffer":return f.transformTo(a.type.toLowerCase(),u);case"blob":return f.arrayBuffer2Blob(f.transformTo("arraybuffer",u));case"base64":return a.base64?i.encode(u):u;default:return u}},crc32:function(a,b){if("undefined"==typeof a||!a.length)return 0;var c="string"!==f.getTypeOf(a),d=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"==typeof b&&(b=0);var e=0,g=0,h=0;b=-1^b;for(var i=0,j=a.length;j>i;i++)h=c?a[i]:a.charCodeAt(i),g=255&(b^h),e=d[g],b=b>>>8^e;return-1^b},utf8encode:function(a){if(c){var b=c.encode(a);return f.transformTo("string",b)}if(e.nodebuffer)return f.transformTo("string",l(a,"utf-8"));for(var d=[],g=0,h=0;h<a.length;h++){var i=a.charCodeAt(h);128>i?d[g++]=String.fromCharCode(i):i>127&&2048>i?(d[g++]=String.fromCharCode(i>>6|192),d[g++]=String.fromCharCode(63&i|128)):(d[g++]=String.fromCharCode(i>>12|224),d[g++]=String.fromCharCode(i>>6&63|128),d[g++]=String.fromCharCode(63&i|128))}return d.join("")},utf8decode:function(a){var b=[],c=0,g=f.getTypeOf(a),h="string"!==g,i=0,j=0,k=0,l=0;if(d)return d.decode(f.transformTo("uint8array",a));if(e.nodebuffer)return f.transformTo("nodebuffer",a).toString("utf-8");for(;i<a.length;)j=h?a[i]:a.charCodeAt(i),128>j?(b[c++]=String.fromCharCode(j),i++):j>191&&224>j?(k=h?a[i+1]:a.charCodeAt(i+1),b[c++]=String.fromCharCode((31&j)<<6|63&k),i+=2):(k=h?a[i+1]:a.charCodeAt(i+1),l=h?a[i+2]:a.charCodeAt(i+2),b[c++]=String.fromCharCode((15&j)<<12|(63&k)<<6|63&l),i+=3);return b.join("")}};b.exports=z},{"./base64":13,"./compressedObject":14,"./compressions":15,"./defaults":17,"./nodeBuffer":21,"./signature":24,"./support":26,"./utils":28}],24:[function(a,b,c){"use strict";c.LOCAL_FILE_HEADER="PK",c.CENTRAL_FILE_HEADER="PK",c.CENTRAL_DIRECTORY_END="PK",c.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",c.ZIP64_CENTRAL_DIRECTORY_END="PK",c.DATA_DESCRIPTOR="PK\b"},{}],25:[function(a,b){"use strict";function c(a,b){this.data=a,b||(this.data=e.string2binary(this.data)),this.length=this.data.length,this.index=0}var d=a("./dataReader"),e=a("./utils");c.prototype=new d,c.prototype.byteAt=function(a){return this.data.charCodeAt(a)},c.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)},c.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./dataReader":16,"./utils":28}],26:[function(a,b,c){(function(a){"use strict";if(c.base64=!0,c.array=!0,c.string=!0,c.arraybuffer="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array,c.nodebuffer="undefined"!=typeof a,c.uint8array="undefined"!=typeof Uint8Array,"undefined"==typeof ArrayBuffer)c.blob=!1;else{var b=new ArrayBuffer(0);try{c.blob=0===new Blob([b],{type:"application/zip"}).size}catch(d){try{var e=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,f=new e;f.append(b),c.blob=0===f.getBlob("application/zip").size}catch(d){c.blob=!1}}}}).call(this,a("buffer").Buffer)},{buffer:82}],27:[function(a,b){"use strict";function c(a){a&&(this.data=a,this.length=this.data.length,this.index=0)}var d=a("./dataReader");c.prototype=new d,c.prototype.byteAt=function(a){return this.data[a]},c.prototype.lastIndexOfSignature=function(a){for(var b=a.charCodeAt(0),c=a.charCodeAt(1),d=a.charCodeAt(2),e=a.charCodeAt(3),f=this.length-4;f>=0;--f)if(this.data[f]===b&&this.data[f+1]===c&&this.data[f+2]===d&&this.data[f+3]===e)return f;return-1},c.prototype.readData=function(a){this.checkOffset(a);var b=this.data.subarray(this.index,this.index+a);return this.index+=a,b},b.exports=c},{"./dataReader":16}],28:[function(a,b,c){"use strict";function d(a){return a}function e(a,b){for(var c=0;c<a.length;++c)b[c]=255&a.charCodeAt(c);return b}function f(a){var b=65536,d=[],e=a.length,f=c.getTypeOf(a),g=0,h=!0;try{switch(f){case"uint8array":String.fromCharCode.apply(null,new Uint8Array(0));break;case"nodebuffer":String.fromCharCode.apply(null,j(0))}}catch(i){h=!1}if(!h){for(var k="",l=0;l<a.length;l++)k+=String.fromCharCode(a[l]);return k}for(;e>g&&b>1;)try{d.push("array"===f||"nodebuffer"===f?String.fromCharCode.apply(null,a.slice(g,Math.min(g+b,e))):String.fromCharCode.apply(null,a.subarray(g,Math.min(g+b,e)))),g+=b}catch(i){b=Mat