"use strict";var pluginName=null,EAN13=function(){function t(t,i,e,s){if(this.canvas=t,this.ratio=i,this.number=e,this.settings={width:200,height:100,number:!0,prefix:!0,color:"black",debug:!1,onValid:function(){},onInvalid:function(){},onSuccess:function(){},onError:function(){}},s)for(var n in s)this.settings[n]=s[n];this._name=pluginName,this.init()}return t.prototype.settings={},t.prototype.init=function(){var t;return 12===this.number.length&&(t=this.generateCheckDigit(this.number),this.number+=t),13===this.number.length?((this.validate()?this.settings.onValid:this.settings.onInvalid).call(),t=this.getCode(),this.draw(t)):this.settings.onError.call()},t.prototype.getCode=function(){for(var t=["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],i=["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],e=["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],s="",n=["xxxxxx","xxyxyy","xxyyxy","xxyyyx","xyxxyy","xyyxxy","xyyyxx","xyxyxy","xyxyyx","xyyxyx"][parseInt(this.number.substr(0,1),10)].split(""),r=this.number.substr(1).split(""),h=0;h<6;)"x"===n[h]?s+=t[r[h]]:s+=i[r[h]],h++;for(h=6;h<12;)s+=e[r[h]],h++;return s},t.prototype.clear=function(t){return t.clearRect(0,0,this.settings.width,this.settings.height)},t.prototype.draw=function(t){var e,i,s,n,r,h,o,f,l={prefix_offset:.06,font_stretch:.073,border_line_height_number:.9,border_line_height:1,line_height:.9,font_size:.15,font_y:1.03,text_offset:4.5},g=this.settings.prefix?this.settings.width-this.settings.width*l.prefix_offset:this.settings.width,u=this.settings.number?(e=l.border_line_height_number*this.settings.height,l.line_height*e):e=l.border_line_height*this.settings.height,c=g/95;if(this.canvas){var a=this.canvas.getContext("2d"),x=this.ratio||1,p=this.settings.width*x,y=this.settings.height*x;for(this.canvas.width=p,this.canvas.height=y,a.scale(x,x),a.fillRect(0,0,this.settings.width,this.settings.height),this.clear(a),a.fillStyle=this.settings.color,s=this.settings.number&&this.settings.prefix?this.settings.width*l.prefix_offset:0,n=t.split(""),a.fillRect(s,0,c,e),a.fillRect(s+=2*c,0,c,e),s+=c,i=0;i<42;)"1"===n[i]&&a.fillRect(s,0,Math.floor(c)+1,u),s+=c,i++;for(a.fillRect(s+=c,0,c,e),a.fillRect(s+=2*c,0,c,e),s+=2*c,i=42;i<84;)"1"===n[i]&&a.fillRect(s,0,Math.floor(c)+1,u),s+=c,i++;if(a.fillRect(s,0,c,e),a.fillRect(s+=2*c,0,c,e),this.settings.number&&(a.font=l.font_size*u+"px monospace",p=this.number.substr(0,1),this.settings.prefix&&a.fillText(p,0,e*l.font_y),r=c*l.text_offset+(this.settings.prefix?l.prefix_offset*this.settings.width:0),this.number.substr(1,6).split("").forEach(function(t,i){return a.fillText(t,r,e*l.font_y),r+=l.font_stretch*g}),r=49*c+(this.settings.prefix?l.prefix_offset*this.settings.width:0)+l.text_offset,this.number.substr(7).split("").forEach(function(t,i){return a.fillText(t,r,e*l.font_y),r+=l.font_stretch*g})),this.settings.debug)for(h=o=0,f=2*c;0<f?o<=g:g<=o;h=o+=f)a.beginPath(),a.rect(h,.4*u,c,.1*u),a.fillStyle="red",a.fill();return this.settings.onSuccess.call()}return this.settings.onError.call()},t.prototype.generateCheckDigit=function(t){var e=0;return t.split("").forEach(function(t,i){return e+=i%2==0?parseInt(t,10):3*parseInt(t,10)}),10-e%10%10},t.prototype.validate=function(){return parseInt(this.number.slice(-1),10)===this.generateCheckDigit(this.number.slice(0,-1))},t}();"undefined"!=typeof module&&void 0!==module.exports&&(module.exports=EAN13);