-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbarcode.min.js
More file actions
2 lines (2 loc) · 2.37 KB
/
barcode.min.js
File metadata and controls
2 lines (2 loc) · 2.37 KB
1
2
/** https://github.com/datalog/barcode-svg under MIT license */
'use strict';function BARCode(e){function n(e){return(e=e.charCodeAt(0))>126?128==e?0:e-50:e>32?e-32:0}function t(e){return 106<e&&(console.warn("BCode: {bad char} was used and it was replaced by X"),e=56,C=1),[1740,1644,1638,1176,1164,1100,1224,1220,1124,1608,1604,1572,1436,1244,1230,1484,1260,1254,1650,1628,1614,1764,1652,1902,1868,1836,1830,1892,1844,1842,1752,1734,1590,1304,1112,1094,1416,1128,1122,1672,1576,1570,1464,1422,1134,1496,1478,1142,1910,1678,1582,1768,1762,1774,1880,1862,1814,1896,1890,1818,1914,1602,1930,1328,1292,1200,1158,1068,1062,1424,1412,1232,1218,1076,1074,1554,1616,1978,1556,1146,1340,1212,1182,1508,1268,1266,1956,1940,1938,1758,1782,1974,1400,1310,1118,1512,1506,1960,1954,1502,1518,1886,1966,1668,1680,1692,6379][e].toString(2)}function r(e){return Math.abs(parseInt(e))||0}function o(e){return/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i.test(e)}var a,i="string"==typeof e?{msg:e}:e||{},d=i.msg,s=0,u=i.dim||[320,80],c=i.pad||[20,16],l=i.pal||["#000"],f=r(u[0]),h=r(u[1]),p=r(c[0]),g=r(c[1]),v=l[0],m=l[1],w=1,b=1,C=0;return d&&"string"==typeof d||(console.warn("BCode: Expected {msg} should be not empty string!"),d="error!",C=1),d=function(e){for(var r=[],o=e.length;o;)r[--o]=t(n(e[o]));return function(e){for(var n=[],t=e.length;t;)n[--t]=parseInt(e[t]);return n}(t(104)+r.join("")+t(function(e){for(var t=0,r=e.length;r;)t+=r--*n(e[r]);return t%103}(e)+1)+t(106))}(d),a=d.length,0==f&&0==h&&(g=16,f=2*(a+(p=20)),h=80),s=h>f,0==f&&(f=2*(a+p),s=0),0==h&&(h=2*(a+g),s=1),f<p&&(p=f,console.warn("BCode: Expected {pad} value could not be bigger than {dim} value")),h<g&&(g=h,console.warn("BCode: Expected {pad} value could not be bigger than {dim} value")),s?b=a:w=a,w=((f-2*p)/w).toFixed(4),b=((h-2*g)/b).toFixed(4),(C||!o(v)||m&&!o(m))&&(v="#b11",m="#fee",console.warn("BCode: Please, double check barcode params")),function(){function e(e,n){for(var r in e=document.createElementNS(t,e),n||{})e.setAttribute(r,n[r]);return e}for(var n,t="http://www.w3.org/2000/svg",r="",o=a,i=0;o;)d[--o]&&++i&&!d[o-1]&&(r+=s?"M1,"+o+"H0v"+i+"h1v-"+i+"z":"M"+o+",1h"+i+"V0h-"+i+"v1z",i=0);return n=e("svg",{viewBox:[0,0,f,h].join(" "),width:f,height:h,fill:v,"shape-rendering":"crispEdges",xmlns:t,version:"1.1"}),m&&n.appendChild(e("path",{fill:m,d:"M0,0V"+h+"H"+f+"V0H0Z"})),n.appendChild(e("path",{transform:"matrix("+[w,0,0,b,p,g]+")",d:r})),n}()}