svgedit/editor/jspdf/jspdf.min.js

170 lines
108 KiB
JavaScript
Raw Normal View History

/**
* jsPDF - PDF Document creation from JavaScript
* Version 1.0.138-git Built on 2014-05-18T18:42
* CommitID 99b632ed34
*
* Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
* 2010 Aaron Spike, https://github.com/acspike
* 2012 Willow Systems Corporation, willow-systems.com
* 2012 Pablo Hess, https://github.com/pablohess
* 2012 Florian Jenett, https://github.com/fjenett
* 2013 Warren Weckesser, https://github.com/warrenweckesser
* 2013 Youssef Beddad, https://github.com/lifof
* 2013 Lee Driscoll, https://github.com/lsdriscoll
* 2013 Stefan Slonevskiy, https://github.com/stefslon
* 2013 Jeremy Morel, https://github.com/jmorel
* 2013 Christoph Hartmann, https://github.com/chris-rock
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 James Makes, https://github.com/dollaruw
* 2014 Diego Casorran, https://github.com/diegocr
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Contributor(s):
* siefkenj, ahwolf, rickygu, Midnith, saintclair, eaparango,
* kim3er, mfo, alnorth,
*/
/**
* jsPDF addHTML PlugIn
* Copyright (c) 2014 Diego Casorran
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/**
* jsPDF addImage plugin
* Copyright (c) 2012 Jason Siefken, https://github.com/siefkenj/
* 2013 Chris Dowling, https://github.com/gingerchris
* 2013 Trinh Ho, https://github.com/ineedfat
* 2013 Edwin Alejandro Perez, https://github.com/eaparango
* 2013 Norah Smith, https://github.com/burnburnrocket
* 2014 Diego Casorran, https://github.com/diegocr
* 2014 James Robb, https://github.com/jamesbrobb
*/
/**
* jsPDF Cell plugin
* Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
* 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
* 2013 Lee Driscoll, https://github.com/lsdriscoll
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 James Hall, james@parall.ax
* 2014 Diego Casorran, https://github.com/diegocr
*/
/**
* jsPDF fromHTML plugin. BETA stage. API subject to change. Needs browser
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
* 2014 Diego Casorran, https://github.com/diegocr
* 2014 Daniel Husar, https://github.com/danielhusar
*/
/**
* jsPDF JavaScript plugin
* Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
*/
/**
* jsPDF PNG PlugIn
* Copyright (c) 2014 James Robb, https://github.com/jamesbrobb
*/
/**
jsPDF Silly SVG plugin
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
*/
/**
* jsPDF split_text_to_size plugin - MIT license.
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
* 2014 Diego Casorran, https://github.com/diegocr
*/
/**
jsPDF standard_fonts_metrics plugin
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
MIT license.
*/
/**
* jsPDF total_pages plugin
* Copyright (c) 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
*/
/* Blob.js
* A Blob implementation.
* 2013-12-27
* By Eli Grey, http://eligrey.com
* By Devin Samarin, https://github.com/eboyjr
* License: X11/MIT
* See LICENSE.md
*/
/*! FileSaver.js
* A saveAs() FileSaver implementation.
* 2014-01-24
* By Eli Grey, http://eligrey.com
* License: X11/MIT
* See LICENSE.md
*/
/*
* Copyright (c) 2012 chick307 <chick307@gmail.com>
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
/*
Deflate.js - https://github.com/gildas-lormeau/zip.js
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
# PNG.js
# Copyright (c) 2011 Devon Govett
# MIT LICENSE
#
*/
/*
* Extracted from pdf.js
* https://github.com/andreasgal/pdf.js
* Copyright (c) 2011 Mozilla Foundation
* Contributors: Andreas Gal <gal@mozilla.com>
* Chris G Jones <cjones@mozilla.com>
* Shaon Barman <shaon.barman@gmail.com>
* Vivien Nicolas <21@vingtetun.org>
* Justin D'Arcangelo <justindarc@gmail.com>
* Yury Delendik
*/
/**
* JavaScript Polyfill functions for jsPDF
* Collected from public resources by
* https://github.com/diegocr
*/
!function(t,e){e["true"]=t;var r=function(t){"use strict";function e(e){var r={};this.subscribe=function(t,e,n){if("function"!=typeof e)return!1;r.hasOwnProperty(t)||(r[t]={});var s=Math.random().toString(35);return r[t][s]=[e,!!n],s},this.unsubscribe=function(t){for(var e in r)if(r[e][t])return delete r[e][t],!0;return!1},this.publish=function(n){if(r.hasOwnProperty(n)){var s=Array.prototype.slice.call(arguments,1),o=[];for(var i in r[n]){var a=r[n][i];try{a[0].apply(e,s)}catch(u){t.console&&console.error("jsPDF PubSub Error",u.message,u)}a[1]&&o.push(i)}o.length&&o.forEach(this.unsubscribe)}}}function r(a,u,c,l){var f={};"object"==typeof a&&(f=a,a=f.orientation,u=f.unit||u,c=f.format||c,l=f.compress||f.compressPdf||l),u=u||"mm",c=c||"a4",a=(""+(a||"P")).toLowerCase();var d,h,p,m,w,y=(""+c).toLowerCase(),g=!!l&&"function"==typeof Uint8Array,v=f.textColor||"0 g",b=f.drawColor||"0 G",q=f.fontSize||16,x=f.lineHeight||1.15,k=f.lineWidth||.200025,_=2,A=!1,C=[],S={},z={},E=0,I=[],B=[],T=0,O=0,P=0,R={title:"",subject:"",author:"",keywords:"",creator:""},U={},D=new e(U),F=function(t){return t.toFixed(2)},L=function(t){return t.toFixed(3)},j=function(t){return("0"+parseInt(t)).slice(-2)},N=function(t){A?I[E].push(t):(P+=t.length+1,B.push(t))},M=function(){return _++,C[_]=P,N(_+" 0 obj"),_},H=function(t){N("stream"),N(t),N("endstream")},G=function(){var e,n,o,i,a,u,c,l=m*h,f=w*h;for(c=t.adler32cs||r.adler32cs,g&&"undefined"==typeof c&&(g=!1),e=1;E>=e;e++){if(M(),N("<</Type /Page"),N("/Parent 1 0 R"),N("/Resources 2 0 R"),N("/Contents "+(_+1)+" 0 R>>"),N("endobj"),n=I[e].join("\n"),M(),g){for(o=[],i=n.length;i--;)o[i]=n.charCodeAt(i);u=c.from(n),a=new s(6),a.append(new Uint8Array(o)),n=a.flush(),o=new Uint8Array(n.length+6),o.set(new Uint8Array([120,156])),o.set(n,2),o.set(new Uint8Array([255&u,u>>8&255,u>>16&255,u>>24&255]),n.length+2),n=String.fromCharCode.apply(null,o),N("<</Length "+n.length+" /Filter [/FlateDecode]>>")}else N("<</Length "+n.length+">>");H(n),N("endobj")}C[1]=P,N("1 0 obj"),N("<</Type /Pages");var d="/Kids [";for(i=0;E>i;i++)d+=3+2*i+" 0 R ";N(d+"]"),N("/Count "+E),N("/MediaBox [0 0 "+F(l)+" "+F(f)+"]"),N(">>"),N("endobj")},J=function(t){t.objectNumber=M(),N("<</BaseFont/"+t.PostScriptName+"/Type/Font"),"string"==typeof t.encoding&&N("/Encoding/"+t.encoding),N("/Subtype/Type1>>"),N("endobj")},W=function(){for(var t in S)S.hasOwnProperty(t)&&J(S[t])},V=function(){D.publish("putXobjectDict")},X=function(){N("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]"),N("/Font <<");for(var t in S)S.hasOwnProperty(t)&&N("/"+t+" "+S[t].objectNumber+" 0 R");N(">>"),N("/XObject <<"),V(),N(">>")},Y=function(){W(),D.publish("putResources"),C[2]=P,N("2 0 obj"),N("<<"),X(),N(">>"),N("endobj"),D.publish("postPutResources")},K=function(t,e,r){z.hasOwnProperty(e)||(z[e]={}),z[e][r]=t},Q=function(t,e,r,n){var s="F"+(Object.keys(S).length+1).toString(10),o=S[s]={id:s,PostScriptName:t,fontName:e,fontStyle:r,encoding:n,metadata:{}};return K(s,e,r),D.publish("addFont",o),s},$=function(){for(var t="helvetica",e="times",r="courier",n="normal",s="bold",o="italic",i="bolditalic",a="StandardEncoding",u=[["Helvetica",t,n],["Helvetica-Bold",t,s],["Helvetica-Oblique",t,o],["Helvetica-BoldOblique",t,i],["Courier",r,n],["Courier-Bold",r,s],["Courier-Oblique",r,o],["Courier-BoldOblique",r,i],["Times-Roman",e,n],["Times-Bold",e,s],["Times-Italic",e,o],["Times-BoldItalic",e,i]],c=0,l=u.length;l>c;c++){var f=Q(u[c][0],u[c][1],u[c][2],a),d=u[c][0].split("-");K(f,d[0],d[1]||"")}D.publish("addFonts",{fonts:S,dictionary:z})},Z=function(e){return e.foo=function(){try{return e.apply(this,arguments)}catch(r){var n=r.stack||"";~n.indexOf(" at ")&&(n=n.split(" at ")[1]);var s="Error in function "+n.split("\n")[0].split("<")[0]+": "+r.message;if(!t.console)throw new Error(s);console.log(s,r),t.alert&&alert(s),console.trace()}},e.foo.bar=e,e.foo},te=function(t,e){var r,n,s,o,i,a,u,c,l;if(e=e||{},s=e.sourceEncoding||"Unicode",i=e.outputEncoding,(e.autoencode||i)&&S[d].metadata&&S[d].metadata[s]&&S[d].metadata[s].encoding&&(o=S[d].metadata[s].encoding,!i&&S[d].encod
},u.prototype.init=function(){return this.paragraph={text:[],style:[]},this.pdf.internal.write("q")},u.prototype.dispose=function(){return this.pdf.internal.write("Q"),{x:this.x,y:this.y}},u.prototype.splitFragmentsIntoLines=function(t,r){var n,s,o,i,a,u,c,l,f,d,h,p,m,w,y;for(s=12,h=this.pdf.internal.scaleFactor,a={},o=void 0,d=void 0,i=void 0,u=void 0,y=void 0,f=void 0,l=void 0,c=void 0,p=[],m=[p],n=0,w=this.settings.width;t.length;)if(u=t.shift(),y=r.shift(),u)if(o=y["font-family"],d=y["font-style"],i=a[o+d],i||(i=this.pdf.internal.getFont(o,d).metadata.Unicode,a[o+d]=i),f={widths:i.widths,kerning:i.kerning,fontSize:y["font-size"]*s,textIndent:n},l=this.pdf.getStringUnitWidth(u,f)*f.fontSize/h,n+l>w){for(c=this.pdf.splitTextToSize(u,w,f),p.push([c.shift(),y]);c.length;)p=[[c.shift(),y]],m.push(p);n=this.pdf.getStringUnitWidth(p[0][0],f)*f.fontSize/h}else p.push([u,y]),n+=l;if(void 0!==y["text-align"]&&("center"===y["text-align"]||"right"===y["text-align"]||"justify"===y["text-align"]))for(var g=0;g<m.length;++g){var v=this.pdf.getStringUnitWidth(m[g][0][0],f)*f.fontSize/h;g>0&&(m[g][0][1]=e(m[g][0][1]));var b=w-v;if("right"===y["text-align"])m[g][0][1]["margin-left"]=b;else if("center"===y["text-align"])m[g][0][1]["margin-left"]=b/2;else if("justify"===y["text-align"]){var q=m[g][0][0].split(" ").length-1;m[g][0][1]["word-spacing"]=b/q,g===m.length-1&&(m[g][0][1]["word-spacing"]=0)}}return m},u.prototype.RenderTextFragment=function(t,e){var r,n;this.pdf.internal.pageSize.height-this.pdf.margins_doc.bottom<this.y+this.pdf.internal.getFontSize()&&(this.pdf.internal.write("ET","Q"),this.pdf.addPage(),this.y=this.pdf.margins_doc.top,this.pdf.internal.write("q","BT",this.pdf.internal.getCoordinateString(this.x),this.pdf.internal.getVerticalCoordinateString(this.y),"Td")),r=12,n=this.pdf.internal.getFont(e["font-family"],e["font-style"]),void 0!==e["word-spacing"]&&e["word-spacing"]>0&&this.pdf.internal.write(e["word-spacing"].toFixed(2),"Tw"),this.pdf.internal.write("/"+n.id,(r*e["font-size"]).toFixed(2),"Tf","("+this.pdf.internal.pdfEscape(t)+") Tj"),void 0!==e["word-spacing"]&&this.pdf.internal.write(0,"Tw")},u.prototype.renderParagraph=function(t){var e,r,n,s,o,i,u,c,l,f,d,h,p,m,w;if(s=a(this.paragraph.text),m=this.paragraph.style,e=this.paragraph.blockstyle,p=this.paragraph.blockstyle||{},this.paragraph={text:[],style:[],blockstyle:{},priorblockstyle:e},s.join("").trim()){c=this.splitFragmentsIntoLines(s,m),u=void 0,l=void 0,r=12,n=r/this.pdf.internal.scaleFactor,h=(Math.max((e["margin-top"]||0)-(p["margin-bottom"]||0),0)+(e["padding-top"]||0))*n,d=((e["margin-bottom"]||0)+(e["padding-bottom"]||0))*n,f=this.pdf.internal.write,o=void 0,i=void 0,this.y+=h,f("q","BT",this.pdf.internal.getCoordinateString(this.x),this.pdf.internal.getVerticalCoordinateString(this.y),"Td");for(var y=0;c.length;){for(u=c.shift(),l=0,o=0,i=u.length;o!==i;)u[o][0].trim()&&(l=Math.max(l,u[o][1]["line-height"],u[o][1]["font-size"]),w=7*u[o][1]["font-size"]),o++;var g=0;for(void 0!==u[0][1]["margin-left"]&&u[0][1]["margin-left"]>0&&(wantedIndent=this.pdf.internal.getCoordinateString(u[0][1]["margin-left"]),g=wantedIndent-y,y=wantedIndent),f(g,(-1*r*l).toFixed(2),"Td"),o=0,i=u.length;o!==i;)u[o][0]&&this.RenderTextFragment(u[o][0],u[o][1]),o++;this.y+=l*n}return t&&"function"==typeof t&&t.call(this,this.x-9,this.y-w/2),f("ET","Q"),this.y+=d}},u.prototype.setBlockBoundary=function(t){return this.renderParagraph(t)},u.prototype.setBlockStyle=function(t){return this.paragraph.blockstyle=t},u.prototype.addText=function(t,e){return this.paragraph.text.push(t),this.paragraph.style.push(e)},n={helvetica:"helvetica","sans-serif":"helvetica",serif:"times",times:"times","times new roman":"times",monospace:"courier",courier:"courier"},o={100:"normal",200:"normal",300:"normal",400:"normal",500:"bold",600:"bold",700:"bold",800:"bold",900:"bold",normal:"normal",bold:"bold",bolder:"bold",lighter:"normal"},s={normal:"normal",italic:"italic",oblique:"italic"},TextAlignMap={left:"left",right:"right",center:"center",justify:"justify"},f={normal:1},t.fromHTML=functio
return _.initMouseEvent("click",!0,!1,t,0,0,0,0,0,!1,!1,!1,!1,0,null),s.dispatchEvent(_),w.readyState=w.DONE,b(),void 0}return t.chrome&&y&&y!==c&&(m=n.slice||n.webkitSlice,n=m.call(n,0,n.size,c),g=!0),i&&"download"!==u&&(u+=".download"),(y===c||i)&&(p=t),a?(l+=n.size,a(t.TEMPORARY,l,x(function(t){t.root.getDirectory("saved",k,x(function(t){var e=function(){t.getFile(u,k,x(function(t){t.createWriter(x(function(e){e.onwriteend=function(e){p.location.href=t.toURL(),f.push(t),w.readyState=w.DONE,h(w,"writeend",e)},e.onerror=function(){var t=e.error;t.code!==t.ABORT_ERR&&q()},"writestart progress write abort".split(" ").forEach(function(t){e["on"+t]=w["on"+t]}),e.write(n),w.abort=function(){e.abort(),w.readyState=w.DONE},w.readyState=w.WRITING}),q)}),q)};t.getFile(u,{create:!1},x(function(t){t.remove(),e()}),x(function(t){t.code===t.NOT_FOUND_ERR?e():q()}))}),q)}),q),void 0):(q(),void 0)},m=p.prototype,w=function(t,e){return new p(t,e)};return m.abort=function(){var t=this;t.readyState=t.DONE,h(t,"abort")},m.readyState=m.INIT=0,m.WRITING=1,m.DONE=2,m.error=m.onwritestart=m.onprogress=m.onwrite=m.onabort=m.onerror=m.onwriteend=null,t.addEventListener("unload",d,!1),w.unload=function(){d(),t.removeEventListener("unload",d,!1)},w}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);"undefined"!=typeof module&&null!==module?module.exports=n:"undefined"!=typeof define&&null!==define&&null!=define.amd&&define([],function(){return n}),void function(t,e){"object"==typeof module?module.exports=e():t.adler32cs=e()}(r,function(){var t="function"==typeof ArrayBuffer&&"function"==typeof Uint8Array,e=null,r=function(){if(!t)return function(){return!1};try{var r=require("buffer");"function"==typeof r.Buffer&&(e=r.Buffer)}catch(n){}return function(t){return t instanceof ArrayBuffer||null!==e&&t instanceof e}}(),n=function(){return null!==e?function(t){return new e(t,"utf8").toString("binary")}:function(t){return unescape(encodeURIComponent(t))}}(),s=65521,o=function(t,e){for(var r=65535&t,n=t>>>16,o=0,i=e.length;i>o;o++)r=(r+(255&e.charCodeAt(o)))%s,n=(n+r)%s;return(n<<16|r)>>>0},i=function(t,e){for(var r=65535&t,n=t>>>16,o=0,i=e.length;i>o;o++)r=(r+e[o])%s,n=(n+r)%s;return(n<<16|r)>>>0},a={},u=a.Adler32=function(){var e=function(t){if(!(this instanceof e))throw new TypeError("Constructor cannot called be as a function.");if(!isFinite(t=null==t?1:+t))throw new Error("First arguments needs to be a finite number.");this.checksum=t>>>0},s=e.prototype={};return s.constructor=e,e.from=function(t){return t.prototype=s,t}(function(t){if(!(this instanceof e))throw new TypeError("Constructor cannot called be as a function.");if(null==t)throw new Error("First argument needs to be a string.");this.checksum=o(1,t.toString())}),e.fromUtf8=function(t){return t.prototype=s,t}(function(t){if(!(this instanceof e))throw new TypeError("Constructor cannot called be as a function.");if(null==t)throw new Error("First argument needs to be a string.");var r=n(t.toString());this.checksum=o(1,r)}),t&&(e.fromBuffer=function(t){return t.prototype=s,t}(function(t){if(!(this instanceof e))throw new TypeError("Constructor cannot called be as a function.");if(!r(t))throw new Error("First argument needs to be ArrayBuffer.");var n=new Uint8Array(t);return this.checksum=i(1,n)})),s.update=function(t){if(null==t)throw new Error("First argument needs to be a string.");return t=t.toString(),this.checksum=o(this.checksum,t)},s.updateUtf8=function(t){if(null==t)throw new Error("First argument needs to be a string.");var e=n(t.toString());return this.checksum=o(this.checksum,e)},t&&(s.updateBuffer=function(t){if(!r(t))throw new Error("First argument needs to be ArrayBuffer.");var e=new Uint8Array(t);return this.checksum=i(this.checksum,e)}),s.clone=function(){return new u(this.checksum)},e}();return a.from=function(t){if(null==t)throw new Error("First argument needs to be a string.");return o(1,t.toString())},a.fromUtf8=function(t){if(null==t)throw new Error("First argument needs to be a string.");var e=n(t.toString());return o(1,e)},t&&(a.fromBuffe
return e.prototype=Object.create(o.prototype),e.prototype.getBits=function(e){for(var r,n=this.codeSize,s=this.codeBuf,o=this.bytes,i=this.bytesPos;e>n;)"undefined"==typeof(r=o[i++])&&t("Bad encoding in flate stream"),s|=r<<n,n+=8;return r=s&(1<<e)-1,this.codeBuf=s>>e,this.codeSize=n-=e,this.bytesPos=i,r},e.prototype.getCode=function(e){for(var r=e[0],n=e[1],s=this.codeSize,o=this.codeBuf,i=this.bytes,a=this.bytesPos;n>s;){var u;"undefined"==typeof(u=i[a++])&&t("Bad encoding in flate stream"),o|=u<<s,s+=8}var c=r[o&(1<<n)-1],l=c>>16,f=65535&c;return(0==s||l>s||0==l)&&t("Bad encoding in flate stream"),this.codeBuf=o>>l,this.codeSize=s-l,this.bytesPos=a,f},e.prototype.generateHuffmanTable=function(t){for(var e=t.length,r=0,n=0;e>n;++n)t[n]>r&&(r=t[n]);for(var s=1<<r,o=new Uint32Array(s),i=1,a=0,u=2;r>=i;++i,a<<=1,u<<=1)for(var c=0;e>c;++c)if(t[c]==i){for(var l=0,f=a,n=0;i>n;++n)l=l<<1|1&f,f>>=1;for(var n=l;s>n;n+=u)o[n]=i<<16|c;++a}return[o,r]},e.prototype.readBlock=function(){function e(t,e,r,n,s){for(var o=t.getBits(r)+n;o-->0;)e[k++]=s}var o=this.getBits(3);if(1&o&&(this.eof=!0),o>>=1,0==o){var u,c=this.bytes,l=this.bytesPos;"undefined"==typeof(u=c[l++])&&t("Bad block header in flate stream");var f=u;"undefined"==typeof(u=c[l++])&&t("Bad block header in flate stream"),f|=u<<8,"undefined"==typeof(u=c[l++])&&t("Bad block header in flate stream");var d=u;"undefined"==typeof(u=c[l++])&&t("Bad block header in flate stream"),d|=u<<8,d!=(65535&~f)&&t("Bad uncompressed block length in flate stream"),this.codeBuf=0,this.codeSize=0;var h=this.bufferLength,p=this.ensureBuffer(h+f),m=h+f;this.bufferLength=m;for(var w=h;m>w;++w){if("undefined"==typeof(u=c[l++])){this.eof=!0;break}p[w]=u}return this.bytesPos=l,void 0}var y,g;if(1==o)y=i,g=a;else if(2==o){for(var v=this.getBits(5)+257,b=this.getBits(5)+1,q=this.getBits(4)+4,x=Array(r.length),k=0;q>k;)x[r[k++]]=this.getBits(3);for(var _=this.generateHuffmanTable(x),A=0,k=0,C=v+b,S=new Array(C);C>k;){var z=this.getCode(_);16==z?e(this,S,2,3,A):17==z?e(this,S,3,3,A=0):18==z?e(this,S,7,11,A=0):S[k++]=A=z}y=this.generateHuffmanTable(S.slice(0,v)),g=this.generateHuffmanTable(S.slice(v,C))}else t("Unknown block type in flate stream");for(var p=this.buffer,E=p?p.length:0,I=this.bufferLength;;){var B=this.getCode(y);if(256>B)I+1>=E&&(p=this.ensureBuffer(I+1),E=p.length),p[I++]=B;else{if(256==B)return this.bufferLength=I,void 0;B-=257,B=n[B];var T=B>>16;T>0&&(T=this.getBits(T));var A=(65535&B)+T;B=this.getCode(g),B=s[B],T=B>>16,T>0&&(T=this.getBits(T));var O=(65535&B)+T;I+A>=E&&(p=this.ensureBuffer(I+A),E=p.length);for(var P=0;A>P;++P,++I)p[I]=p[I-O]}}},e}();!function(t){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";"undefined"==typeof t.btoa&&(t.btoa=function(t){var r,n,s,o,i,a,u,c,l=0,f=0,d="",h=[];if(!t)return t;do r=t.charCodeAt(l++),n=t.charCodeAt(l++),s=t.charCodeAt(l++),c=r<<16|n<<8|s,o=c>>18&63,i=c>>12&63,a=c>>6&63,u=63&c,h[f++]=e.charAt(o)+e.charAt(i)+e.charAt(a)+e.charAt(u);while(l<t.length);d=h.join("");var p=t.length%3;return(p?d.slice(0,p-3):d)+"===".slice(p||3)}),"undefined"==typeof t.atob&&(t.atob=function(t){var r,n,s,o,i,a,u,c,l=0,f=0,d="",h=[];if(!t)return t;t+="";do o=e.indexOf(t.charAt(l++)),i=e.indexOf(t.charAt(l++)),a=e.indexOf(t.charAt(l++)),u=e.indexOf(t.charAt(l++)),c=o<<18|i<<12|a<<6|u,r=c>>16&255,n=c>>8&255,s=255&c,h[f++]=64==a?String.fromCharCode(r):64==u?String.fromCharCode(r,n):String.fromCharCode(r,n,s);while(l<t.length);return d=h.join("")}),Array.prototype.map||(Array.prototype.map=function(t){if(void 0===this||null===this||"function"!=typeof t)throw new TypeError;for(var e=Object(this),r=e.length>>>0,n=new Array(r),s=arguments.length>1?arguments[1]:void 0,o=0;r>o;o++)o in e&&(n[o]=t.call(s,e[o],o,e));return n}),Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),Array.prototype.forEach||(Array.prototype.forEach=function(t,e){"use strict";if(void 0===this||null===this||"function"!=typeof t)throw new TypeError;for(var r=Object(this),n=r.length>>>0,s=0;n>s;s++)s in r&&t.call(e,r[s],s,r