diff --git a/bower.json b/bower.json index 0fec7db..92e234f 100644 --- a/bower.json +++ b/bower.json @@ -1,8 +1,8 @@ { "name": "angular-barcode", - "version": "0.0.4", + "version": "0.0.5", "main": [ - "./dist/angular-barcode.min.js" + "./dist/angular-barcode.js" ], "description": "Barcode generator for AngularJS apps", "repository": { diff --git a/dist/angular-barcode.js b/dist/angular-barcode.js index 28e090a..0de1c0c 100644 --- a/dist/angular-barcode.js +++ b/dist/angular-barcode.js @@ -1,6 +1,6 @@ /** * angular barcode - * @version v0.0.4 - 2016-02-11 * @link https://github.com/ryanmc2033/angular-barcode + * @version v0.0.5 - 2017-12-06 * @link https://github.com/ryanmc2033/angular-barcode * @author Ryan McLaughlin * @license MIT License, http://www.opensource.org/licenses/MIT */ diff --git a/dist/angular-barcode.min.js b/dist/angular-barcode.min.js index 00bf597..87a3aa1 100644 --- a/dist/angular-barcode.min.js +++ b/dist/angular-barcode.min.js @@ -1,7 +1,9 @@ /** * angular barcode - * @version v0.0.4 - 2016-02-11 * @link https://github.com/ryanmc2033/angular-barcode + * @version v0.0.5 - 2017-12-06 * @link https://github.com/ryanmc2033/angular-barcode * @author Ryan McLaughlin * @license MIT License, http://www.opensource.org/licenses/MIT */ - angular.module("barcode",[]).directive("barcode",["BarcodeService","Code39Service","Code128BService","Code128CService","EanService","Itf14NumberService","ItfNumberService","UpcService",function(a,b,c,d,e,f,g,h){function i(i,j,k){var l={width:2,height:100,quite:10,displayValue:!1,font:"monospace",textAlign:"center",fontSize:12,backgroundColor:"",lineColor:"#000"},m=[];m=a.merge(l,i.options);var n=j.find("canvas")[0];if("img"==k.render&&(n=document.createElement("canvas")),!n.getContext)return null;var o="";switch(k.type){case"upc":o=h;break;case"ean":o=e;break;case"code39":o=b;break;case"code128b":o=c;break;case"code128c":o=d;break;case"itf":o=g;break;case"itf14":o=f}if(""!==o){var p=o.encoded(k.string);if(!angular.isUndefined(p)){var q=function(a){var b,c;c=m.height,r.font=m.fontSize+"px "+m.font,r.textBaseline="bottom",r.textBaseline="top","left"==m.textAlign?(b=m.quite,r.textAlign="left"):"right"==m.textAlign?(b=n.width-m.quite,r.textAlign="right"):(b=n.width/2,r.textAlign="center"),r.fillText(a,b,c)},r=n.getContext("2d");n.width=p.length*m.width+2*m.quite,n.height=m.height+(m.displayValue?1.3*m.fontSize:0),r.clearRect(0,0,n.width,n.height),m.backgroundColor&&(r.fillStyle=m.backgroundColor,r.fillRect(0,0,n.width,n.height)),r.fillStyle=m.lineColor;for(var s=0;s"),a.append(c),{post:j}}return{restrict:"E",scope:{options:"=options"},compile:k}}]),angular.module("barcode").factory("BarcodeService",[function(){"use strict";var a={};return a.merge=function(a,b){var c={};for(var d in a)c[d]=a[d];for(var e in b)c[e]=b[e];return c},a}]),angular.module("barcode").factory("Code128Service",[function(){"use strict";var a={},b=[[" ","11011001100",0],["!","11001101100",1],['"',"11001100110",2],["#","10010011000",3],["$","10010001100",4],["%","10001001100",5],["&","10011001000",6],["'","10011000100",7],["(","10001100100",8],[")","11001001000",9],["*","11001000100",10],["+","11000100100",11],[",","10110011100",12],["-","10011011100",13],[".","10011001110",14],["/","10111001100",15],["0","10011101100",16],["1","10011100110",17],["2","11001110010",18],["3","11001011100",19],["4","11001001110",20],["5","11011100100",21],["6","11001110100",22],["7","11101101110",23],["8","11101001100",24],["9","11100101100",25],[":","11100100110",26],[";","11101100100",27],["<","11100110100",28],["=","11100110010",29],[">","11011011000",30],["?","11011000110",31],["@","11000110110",32],["A","10100011000",33],["B","10001011000",34],["C","10001000110",35],["D","10110001000",36],["E","10001101000",37],["F","10001100010",38],["G","11010001000",39],["H","11000101000",40],["I","11000100010",41],["J","10110111000",42],["K","10110001110",43],["L","10001101110",44],["M","10111011000",45],["N","10111000110",46],["O","10001110110",47],["P","11101110110",48],["Q","11010001110",49],["R","11000101110",50],["S","11011101000",51],["T","11011100010",52],["U","11011101110",53],["V","11101011000",54],["W","11101000110",55],["X","11100010110",56],["Y","11101101000",57],["Z","11101100010",58],["[","11100011010",59],["\\","11101111010",60],["]","11001000010",61],["^","11110001010",62],["_","10100110000",63],["`","10100001100",64],["a","10010110000",65],["b","10010000110",66],["c","10000101100",67],["d","10000100110",68],["e","10110010000",69],["f","10110000100",70],["g","10011010000",71],["h","10011000010",72],["i","10000110100",73],["j","10000110010",74],["k","11000010010",75],["l","11001010000",76],["m","11110111010",77],["n","11000010100",78],["o","10001111010",79],["p","10100111100",80],["q","10010111100",81],["r","10010011110",82],["s","10111100100",83],["t","10011110100",84],["u","10011110010",85],["v","11110100100",86],["w","11110010100",87],["x","11110010010",88],["y","11011011110",89],["z","11011110110",90],["{","11110110110",91],["|","10101111000",92],["}","10100011110",93],["~","10001011110",94],[String.fromCharCode(127),"10111101000",95],[String.fromCharCode(128),"10111100010",96],[String.fromCharCode(129),"11110101000",97],[String.fromCharCode(130),"11110100010",98],[String.fromCharCode(131),"10111011110",99],[String.fromCharCode(132),"10111101110",100],[String.fromCharCode(133),"11101011110",101],[String.fromCharCode(134),"11110101110",102],[String.fromCharCode(135),"11010000100",103],[String.fromCharCode(136),"11010010000",104],[String.fromCharCode(137),"11010011100",105]],c="1100011101011",d=/^[!-~ ]+$/;return a.valid=function(a){return-1==a.search(d)?!1:!0},a.calculateCode128=function(b,d,e,f){var g="";return g+=a.encodingById(e),g+=d(b),g+=a.encodingById(f(b,e)),g+=c},a.encodingById=function(a){for(var c=0;cc;c+=2)b+=parseInt(a[c]);for(var d=1;12>d;d+=2)b+=3*parseInt(a[d]);return(10-b%10)%10}function d(a){return-1==a.search(m)?!1:a[12]==c(a)}var e={};e.valid=function(a){return d(a)},e.encoded=function(b){return d(b)?a(b):""};var f={0:"0001101",1:"0011001",2:"0010011",3:"0111101",4:"0100011",5:"0110001",6:"0101111",7:"0111011",8:"0110111",9:"0001011"},g={0:"0100111",1:"0110011",2:"0011011",3:"0100001",4:"0011101",5:"0111001",6:"0000101",7:"0010001",8:"0001001",9:"0010111"},h={0:"1110010",1:"1100110",2:"1101100",3:"1000010",4:"1011100",5:"1001110",6:"1010000",7:"1000100",8:"1001000",9:"1110100"},i={0:"LLLLLL",1:"LLGLGG",2:"LLGGLG",3:"LLGGGL",4:"LGLLGG",5:"LGGLLG",6:"LGGGLL",7:"LGLGLG",8:"LGLGGL",9:"LGGLGL"},j="101",k="101",l="01010",m=/^[0-9]{13}$/;return e}]),angular.module("barcode").factory("Itf14NumberService",[function(){"use strict";function a(a){var d="";13==a.length&&(a+=c(a)),d+=g;for(var e=0;14>e;e+=2)d+=b(a.substr(e,2));return d+=h}function b(a){for(var b="",c=f[a[0]],d=f[a[1]],e=0;5>e;e++)b+="1"==c[e]?"111":"1",b+="1"==d[e]?"000":"0";return b}function c(a){for(var b=0,c=0;13>c;c++)b+=parseInt(a[c])*(3-c%2*2);return 10-b%10}function d(a){return-1==a.search(i)?!1:14==a.length?a[13]==c(a):!0}var e={};e.valid=function(a){return d(a)},e.encoded=function(b){return d(b)?a(b):""};var f={0:"00110",1:"10001",2:"01001",3:"11000",4:"00101",5:"10100",6:"01100",7:"00011",8:"10010",9:"01010"},g="1010",h="11101",i=/^[0-9]{13,14}$/;return e}]),angular.module("barcode").factory("ItfNumberService",[function(){"use strict";function a(a){var c="";c+=f;for(var d=0;df;f++)b+="1"==c[f]?"111":"1",b+="1"==d[f]?"000":"0";return b}function c(a){return-1!==a.search(h)}var d={};d.valid=function(a){return c(a)},d.encoded=function(b){return c(b)?a(b):""};var e={0:"00110",1:"10001",2:"01001",3:"11000",4:"00101",5:"10100",6:"01100",7:"00011",8:"10010",9:"01010"},f="1010",g="11101",h=/^([0-9][0-9])+$/;return d}]),angular.module("barcode").factory("UpcService",[function(){"use strict";function a(a){var c="",d=a[0],e=a.substr(1,7),f=a.substr(7,6);return c+=j,c+=b(e,i[d]),c+=l,c+=b(f,"RRRRRR"),c+=k}function b(a,b){for(var c="",d=0;dc;c+=2)b+=parseInt(a[c]);for(var d=1;12>d;d+=2)b+=3*parseInt(a[d]);return(10-b%10)%10}function d(a){return-1==a.search(m)?!1:a[12]==c(a)}var e={};e.valid=function(a){return d("0"+a)},e.encoded=function(b){return d("0"+b)?a("0"+b):""};var f={0:"0001101",1:"0011001",2:"0010011",3:"0111101",4:"0100011",5:"0110001",6:"0101111",7:"0111011",8:"0110111",9:"0001011"},g={0:"0100111",1:"0110011",2:"0011011",3:"0100001",4:"0011101",5:"0111001",6:"0000101",7:"0010001",8:"0001001",9:"0010111"},h={0:"1110010",1:"1100110",2:"1101100",3:"1000010",4:"1011100",5:"1001110",6:"1010000",7:"1000100",8:"1001000",9:"1110100"},i={0:"LLLLLL",1:"LLGLGG",2:"LLGGLG",3:"LLGGGL",4:"LGLLGG",5:"LGGLLG",6:"LGGGLL",7:"LGLGLG",8:"LGLGGL",9:"LGGLGL"},j="101",k="101",l="01010",m=/^[0-9]{13}$/;return e}]); \ No newline at end of file + + +angular.module("barcode",[]).directive("barcode",["BarcodeService","Code39Service","Code128BService","Code128CService","EanService","Itf14NumberService","ItfNumberService","UpcService",function(r,e,n,t,o,i,a,u){function c(c,f,d){d.$observe("string",function(){!function(c,f,d){var l=[];l=r.merge({width:2,height:100,quite:10,displayValue:!1,font:"monospace",textAlign:"center",fontSize:12,backgroundColor:"",lineColor:"#000"},c.options);var v=f.find("canvas")[0];if("img"==d.render&&(v=document.createElement("canvas")),!v.getContext)return null;var g="";switch(d.type){case"upc":g=u;break;case"ean":g=o;break;case"code39":g=e;break;case"code128b":g=n;break;case"code128c":g=t;break;case"itf":g=a;break;case"itf14":g=i}if(""!==g){var s=g.encoded(d.string);if(!angular.isUndefined(s)){var L=v.getContext("2d");v.width=s.length*l.width+2*l.quite,v.height=l.height+(l.displayValue?1.3*l.fontSize:0),L.clearRect(0,0,v.width,v.height),l.backgroundColor&&(L.fillStyle=l.backgroundColor,L.fillRect(0,0,v.width,v.height)),L.fillStyle=l.lineColor;for(var h=0;h"),r.append(n),{post:c}}}}]),angular.module("barcode").factory("BarcodeService",[function(){"use strict";var r={};return r.merge=function(r,e){var n={};for(var t in r)n[t]=r[t];for(var o in e)n[o]=e[o];return n},r}]),angular.module("barcode").factory("Code128Service",[function(){"use strict";var r={},e=[[" ","11011001100",0],["!","11001101100",1],['"',"11001100110",2],["#","10010011000",3],["$","10010001100",4],["%","10001001100",5],["&","10011001000",6],["'","10011000100",7],["(","10001100100",8],[")","11001001000",9],["*","11001000100",10],["+","11000100100",11],[",","10110011100",12],["-","10011011100",13],[".","10011001110",14],["/","10111001100",15],["0","10011101100",16],["1","10011100110",17],["2","11001110010",18],["3","11001011100",19],["4","11001001110",20],["5","11011100100",21],["6","11001110100",22],["7","11101101110",23],["8","11101001100",24],["9","11100101100",25],[":","11100100110",26],[";","11101100100",27],["<","11100110100",28],["=","11100110010",29],[">","11011011000",30],["?","11011000110",31],["@","11000110110",32],["A","10100011000",33],["B","10001011000",34],["C","10001000110",35],["D","10110001000",36],["E","10001101000",37],["F","10001100010",38],["G","11010001000",39],["H","11000101000",40],["I","11000100010",41],["J","10110111000",42],["K","10110001110",43],["L","10001101110",44],["M","10111011000",45],["N","10111000110",46],["O","10001110110",47],["P","11101110110",48],["Q","11010001110",49],["R","11000101110",50],["S","11011101000",51],["T","11011100010",52],["U","11011101110",53],["V","11101011000",54],["W","11101000110",55],["X","11100010110",56],["Y","11101101000",57],["Z","11101100010",58],["[","11100011010",59],["\\","11101111010",60],["]","11001000010",61],["^","11110001010",62],["_","10100110000",63],["`","10100001100",64],["a","10010110000",65],["b","10010000110",66],["c","10000101100",67],["d","10000100110",68],["e","10110010000",69],["f","10110000100",70],["g","10011010000",71],["h","10011000010",72],["i","10000110100",73],["j","10000110010",74],["k","11000010010",75],["l","11001010000",76],["m","11110111010",77],["n","11000010100",78],["o","10001111010",79],["p","10100111100",80],["q","10010111100",81],["r","10010011110",82],["s","10111100100",83],["t","10011110100",84],["u","10011110010",85],["v","11110100100",86],["w","11110010100",87],["x","11110010010",88],["y","11011011110",89],["z","11011110110",90],["{","11110110110",91],["|","10101111000",92],["}","10100011110",93],["~","10001011110",94],[String.fromCharCode(127),"10111101000",95],[String.fromCharCode(128),"10111100010",96],[String.fromCharCode(129),"11110101000",97],[String.fromCharCode(130),"11110100010",98],[String.fromCharCode(131),"10111011110",99],[String.fromCharCode(132),"10111101110",100],[String.fromCharCode(133),"11101011110",101],[String.fromCharCode(134),"11110101110",102],[String.fromCharCode(135),"11010000100",103],[String.fromCharCode(136),"11010010000",104],[String.fromCharCode(137),"11010011100",105]],n=/^[!-~ ]+$/;return r.valid=function(r){return-1!=r.search(n)},r.calculateCode128=function(e,n,t,o){var i="";return i+=r.encodingById(t),i+=n(e),i+=r.encodingById(o(e,t)),i+="1100011101011"},r.encodingById=function(r){for(var n=0;n