Skip to content

Instantly share code, notes, and snippets.

@lindell
Created August 9, 2016 13:03
Show Gist options
  • Save lindell/1fa73de1f9aa113982feef4e67396a23 to your computer and use it in GitHub Desktop.
Save lindell/1fa73de1f9aa113982feef4e67396a23 to your computer and use it in GitHub Desktop.
!function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,e,n){Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var n=t&&t.__esModule?function(){return t["default"]}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=15)}([function(t,e){"use strict";function n(t,e){var n,r={};for(n in t)t.hasOwnProperty(n)&&(r[n]=t[n]);for(n in e)e.hasOwnProperty(n)&&"undefined"!=typeof e[n]&&(r[n]=e[n]);return r}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n={width:2,height:100,format:"auto",displayValue:!0,fontOptions:"",font:"monospace",text:void 0,textAlign:"center",textPosition:"bottom",textMargin:2,fontSize:20,background:"#ffffff",lineColor:"#000000",margin:10,marginTop:void 0,marginBottom:void 0,marginLeft:void 0,marginRight:void 0,valid:function(){}};e["default"]=n},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var o=function(t){function e(i,o){n(this,e);var a=r(this,t.call(this));return a.name="InvalidInputException",a.symbology=i,a.input=o,a.message='"'+a.input+'" is not a valid input for '+a.symbology,a}return i(e,t),e}(Error),a=function(t){function e(){n(this,e);var i=r(this,t.call(this));return i.name="InvalidElementException",i.message="Not supported type to render on",i}return i(e,t),e}(Error),s=function(t){function e(){n(this,e);var i=r(this,t.call(this));return i.name="NoElementException",i.message="No element to render on.",i}return i(e,t),e}(Error);e.InvalidInputException=o,e.InvalidElementException=a,e.NoElementException=s},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){return e.height+(e.displayValue&&t.text.length>0?e.fontSize+e.textMargin:0)+e.marginTop+e.marginBottom}function o(t,e,n){if(n.displayValue&&e<t){if("center"==n.textAlign)return Math.floor((t-e)/2);if("left"==n.textAlign)return 0;if("right"==n.textAlign)return Math.floor(t-e)}return 0}function a(t,e,n){for(var r=0;r<t.length;r++){var a=t[r],s=(0,c["default"])(e,a.options),u=d(a.text,s,n),f=a.data.length*s.width;a.width=Math.ceil(Math.max(u,f)),a.height=i(a,s),a.barcodePadding=o(u,f,s)}}function s(t){for(var e=0,n=0;n<t.length;n++)e+=t[n].width;return e}function u(t){for(var e=0,n=0;n<t.length;n++)t[n].height>e&&(e=t[n].height);return e}function d(t,e,n){var r;r="undefined"==typeof n?document.createElement("canvas").getContext("2d"):n,r.font=e.fontOptions+" "+e.fontSize+"px "+e.font;var i=r.measureText(t).width;return i}Object.defineProperty(e,"__esModule",{value:!0}),e.getTotalWidthOfEncodings=e.calculateEncodingAttributes=e.getBarcodePadding=e.getEncodingHeight=e.getMaximumHeightOfEncodings=void 0;var f=n(0),c=r(f);e.getMaximumHeightOfEncodings=u,e.getEncodingHeight=i,e.getBarcodePadding=o,e.calculateEncodingAttributes=a,e.getTotalWidthOfEncodings=s},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(9);e["default"]={CODE39:r.CODE39}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(e){n(this,t),this.api=e}return t.prototype.handleCatch=function(t){if("InvalidInputException"!==t.name)throw t;if(this.api._options.valid===this.api._defaults.valid)throw t.message;this.api._options.valid(!1),this.api.render=function(){}},t.prototype.wrapBarcodeCall=function(t){try{var e=t.apply(void 0,arguments);return this.api._options.valid(!0),e}catch(n){return this.handleCatch(n),this.api}},t}();e["default"]=r},function(t,e){"use strict";function n(t){return t.marginTop=t.marginTop||t.margin,t.marginBottom=t.marginBottom||t.margin,t.marginRight=t.marginRight||t.margin,t.marginLeft=t.marginLeft||t.margin,t}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t){if("string"==typeof t)return o(t);if(Array.isArray(t)){for(var e=[],n=0;n<t.length;n++)e.push(i(t[n]));return e}if("undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLImageElement)return a(t);if("undefined"!=typeof SVGElement&&t instanceof SVGElement)return{element:t,options:(0,u["default"])(t),renderer:(0,d.getRendererClass)("svg")};if("undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement)return{element:t,options:(0,u["default"])(t),renderer:(0,d.getRendererClass)("canvas")};if(t.getContext)return{element:t,renderer:(0,d.getRendererClass)("canvas")};throw new f.InvalidElementException}function o(t){var e=document.querySelectorAll(t);if(0===e.length)throw new f.NoElementException;for(var n=[],r=0;r<e.length;r++)n.push(i(e[r]));return n}function a(t){var e=document.createElement("canvas");return{element:e,options:(0,u["default"])(t),renderer:(0,d.getRendererClass)("canvas"),afterRender:function(){t.setAttribute("src",e.toDataURL())}}}Object.defineProperty(e,"__esModule",{value:!0});var s=n(10),u=r(s),d=n(13),f=n(2);e["default"]=i},function(t,e){"use strict";function n(t){function e(t){if(Array.isArray(t))for(var r=0;r<t.length;r++)e(t[r]);else t.text=t.text||"",t.data=t.data||"",n.push(t)}var n=[];return e(t),n}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(e,r){n(this,t),this.string=e.toUpperCase(),this.mod43Enabled=r.mod43||!1,this.characters=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","-","."," ","$","/","+","%","*"],this.encodings=[20957,29783,23639,30485,20951,29813,23669,20855,29789,23645,29975,23831,30533,22295,30149,24005,21623,29981,23837,22301,30023,23879,30545,22343,30161,24017,21959,30065,23921,22385,29015,18263,29141,17879,29045,18293,17783,29021,18269,17477,17489,17681,20753,35770]}return t.prototype.getEncoding=function(t){return this.getBinary(this.characterValue(t))},t.prototype.getBinary=function(t){return this.encodings[t].toString(2)},t.prototype.getCharacter=function(t){return this.characters[t]},t.prototype.characterValue=function(t){return this.characters.indexOf(t)},t.prototype.encode=function(){for(var t=this.string,e=this.getEncoding("*"),n=0;n<this.string.length;n++)e+=this.getEncoding(this.string[n])+"0";if(this.mod43Enabled){var r=this.mod43checksum();e+=this.getBinary(r)+"0",t+=this.getCharacter(r)}return e+=this.getEncoding("*"),{data:e,text:t}},t.prototype.valid=function(){return this.string.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/)!==-1},t.prototype.mod43checksum=function(){for(var t=0,e=0;e<this.string.length;e++)t+=this.characterValue(this.string[e]);return t%=43},t}();e.CODE39=r},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t){var e={};for(var n in u["default"])u["default"].hasOwnProperty(n)&&(t.hasAttribute("jsbarcode-"+n.toLowerCase())&&(e[n]=t.getAttribute("jsbarcode-"+n.toLowerCase())),t.hasAttribute("data-"+n.toLowerCase())&&(e[n]=t.getAttribute("data-"+n.toLowerCase())));return e.value=t.getAttribute("jsbarcode-value")||t.getAttribute("data-value"),e=(0,a["default"])(e)}Object.defineProperty(e,"__esModule",{value:!0});var o=n(11),a=r(o),s=n(1),u=r(s);e["default"]=i},function(t,e){"use strict";function n(t){var e=["width","height","textMargin","fontSize","margin","marginTop","marginBottom","marginLeft","marginRight"];for(var n in e)e.hasOwnProperty(n)&&(n=e[n],"string"==typeof t[n]&&(t[n]=parseInt(t[n],10)));return"string"==typeof t.displayValue&&(t.displayValue="false"!=t.displayValue),t}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=n(0),a=r(o),s=n(3),u=function(){function t(e,n,r){i(this,t),this.canvas=e,this.encodings=n,this.options=r}return t.prototype.render=function(){if(!this.canvas.getContext)throw new Error("The browser does not support canvas.");this.prepareCanvas();for(var t=0;t<this.encodings.length;t++){var e=(0,a["default"])(this.options,this.encodings[t].options);this.drawCanvasBarcode(e,this.encodings[t]),this.drawCanvasText(e,this.encodings[t]),this.moveCanvasDrawing(this.encodings[t])}this.restoreCanvas()},t.prototype.prepareCanvas=function(){var t=this.canvas.getContext("2d");t.save(),(0,s.calculateEncodingAttributes)(this.encodings,this.options,t);var e=(0,s.getTotalWidthOfEncodings)(this.encodings),n=(0,s.getMaximumHeightOfEncodings)(this.encodings);this.canvas.width=e+this.options.marginLeft+this.options.marginRight,this.canvas.height=n,t.clearRect(0,0,this.canvas.width,this.canvas.height),this.options.background&&(t.fillStyle=this.options.background,t.fillRect(0,0,this.canvas.width,this.canvas.height)),t.translate(this.options.marginLeft,0)},t.prototype.drawCanvasBarcode=function(t,e){var n,r=this.canvas.getContext("2d"),i=e.data;n="top"==t.textPosition?t.marginTop+t.fontSize+t.textMargin:t.marginTop,r.fillStyle=t.lineColor;for(var o=0;o<i.length;o++){var a=o*t.width+e.barcodePadding;"1"===i[o]?r.fillRect(a,n,t.width,t.height):i[o]&&r.fillRect(a,n,t.width,t.height*i[o])}},t.prototype.drawCanvasText=function(t,e){var n=this.canvas.getContext("2d"),r=t.fontOptions+" "+t.fontSize+"px "+t.font,i=t.text||e.text;if(t.displayValue){var o,a;a="top"==t.textPosition?t.marginTop+t.fontSize-t.textMargin:t.height+t.textMargin+t.marginTop+t.fontSize,n.font=r,"left"==t.textAlign||e.barcodePadding>0?(o=0,n.textAlign="left"):"right"==t.textAlign?(o=e.width-1,n.textAlign="right"):(o=e.width/2,n.textAlign="center"),n.fillText(i,o,a)}},t.prototype.moveCanvasDrawing=function(t){var e=this.canvas.getContext("2d");e.translate(t.width,0)},t.prototype.restoreCanvas=function(){var t=this.canvas.getContext("2d");t.restore()},t}();e["default"]=u},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t){switch(t){case"canvas":return a["default"];case"svg":return u["default"];default:throw new Error("Invalid rederer")}}Object.defineProperty(e,"__esModule",{value:!0}),e.getRendererClass=void 0;var o=n(12),a=r(o),s=n(14),u=r(s);e.getRendererClass=i},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e,n){var r=document.createElementNS(c,"g");return r.setAttribute("transform","translate("+t+", "+e+")"),n.appendChild(r),r}function a(t,e){t.setAttribute("style","fill:"+e.lineColor+";")}function s(t,e,n,r,i){var o=document.createElementNS(c,"rect");o.setAttribute("x",t),o.setAttribute("y",e),o.setAttribute("width",n),o.setAttribute("height",r),i.appendChild(o)}Object.defineProperty(e,"__esModule",{value:!0});var u=n(0),d=r(u),f=n(3),c="http://www.w3.org/2000/svg",l=function(){function t(e,n,r){i(this,t),this.svg=e,this.encodings=n,this.options=r}return t.prototype.render=function(){var t=this.options.marginLeft;this.prepareSVG();for(var e=0;e<this.encodings.length;e++){var n=this.encodings[e],r=(0,d["default"])(this.options,n.options),i=o(t,r.marginTop,this.svg);a(i,r),this.drawSvgBarcode(i,r,n),this.drawSVGText(i,r,n),t+=n.width}},t.prototype.prepareSVG=function(){for(;this.svg.firstChild;)this.svg.removeChild(this.svg.firstChild);(0,f.calculateEncodingAttributes)(this.encodings,this.options);var t=(0,f.getTotalWidthOfEncodings)(this.encodings),e=(0,f.getMaximumHeightOfEncodings)(this.encodings),n=t+this.options.marginLeft+this.options.marginRight;this.setSvgAttributes(n,e)},t.prototype.drawSvgBarcode=function(t,e,n){var r,i=n.data;r="top"==e.textPosition?e.fontSize+e.textMargin:0;for(var o=0,a=0,u=0;u<i.length;u++)a=u*e.width+n.barcodePadding,"1"===i[u]?o++:o>0&&(s(a-e.width*o,r,e.width*o,e.height,t),o=0);o>0&&s(a-e.width*(o-1),r,e.width*o,e.height,t)},t.prototype.drawSVGText=function(t,e,n){var r=document.createElementNS(c,"text"),i=e.text||n.text;if(e.displayValue){var o,a;r.setAttribute("style","font:"+e.fontOptions+" "+e.fontSize+"px "+e.font),a="top"==e.textPosition?e.fontSize-e.textMargin:e.height+e.textMargin+e.fontSize,"left"==e.textAlign||n.barcodePadding>0?(o=0,r.setAttribute("text-anchor","start")):"right"==e.textAlign?(o=n.width-1,r.setAttribute("text-anchor","end")):(o=n.width/2,r.setAttribute("text-anchor","middle")),r.setAttribute("x",o),r.setAttribute("y",a),r.appendChild(document.createTextNode(i)),t.appendChild(r)}},t.prototype.setSvgAttributes=function(t,e){var n=this.svg;n.setAttribute("width",t+"px"),n.setAttribute("height",e+"px"),n.setAttribute("x","0px"),n.setAttribute("y","0px"),n.setAttribute("viewBox","0 0 "+t+" "+e),n.setAttribute("xmlns",c),n.setAttribute("version","1.1"),n.style.transform="translate(0,0)",this.options.background&&(n.style.background=this.options.background)},t}();e["default"]=l},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){E.prototype[e]=E.prototype[e.toUpperCase()]=E.prototype[e.toLowerCase()]=function(n,r){var i=this;return i._errorHandler.wrapBarcodeCall(function(){var a=(0,c["default"])(i._options,r),s=t[e],u=o(n,s,a);return i._encodings.push(u),i})}}function o(t,e,n){t=""+t;var r=new e(t,n);if(!r.valid())throw new x.InvalidInputException(r.constructor.name,t);var i=r.encode();i=(0,h["default"])(i);for(var o=0;o<i.length;o++)i[o].options=(0,c["default"])(n,i[o].options);return i}function a(){return d["default"].CODE128?"CODE128":Object.keys(d["default"])[0]}function s(t,e,n){e=(0,h["default"])(e);for(var r=0;r<e.length;r++)e[r].options=(0,c["default"])(n,e[r].options),(0,g["default"])(e[r].options);(0,g["default"])(n);var i=t.renderer,o=new i(t.element,e,n);o.render(),t.afterRender&&t.afterRender()}var u=n(4),d=r(u),f=n(0),c=r(f),l=n(8),h=r(l),p=n(6),g=r(p),v=n(7),m=r(v),y=n(5),w=r(y),x=n(2),b=n(1),_=r(b),E=function(){},C=function(t,e,n){var r=new E;if("undefined"==typeof t)throw Error("No element to render on was provided.");return r._renderProperties=(0,m["default"])(t),r._encodings=[],r._options=_["default"],r._errorHandler=new w["default"](r),"undefined"!=typeof e&&(n=n||{},n.format||(n.format=a()),r.options(n)[n.format](e,n).render()),r};C.getModule=function(t){return d["default"][t]};for(var A in d["default"])d["default"].hasOwnProperty(A)&&i(d["default"],A);E.prototype.options=function(t){return this._options=(0,c["default"])(this._options,t),this},E.prototype.blank=function(t){var e="0".repeat(t);return this._encodings.push({data:e}),this},E.prototype.init=function(){Array.isArray(this._renderProperties)||(this._renderProperties=[this._renderProperties]);var t;for(var e in this._renderProperties){t=this._renderProperties[e];var n=(0,c["default"])(this._options,t.options);"auto"==n.format&&(n.format=a());var r=n.value,i=d["default"][n.format.toUpperCase()],u=o(r,i,n);s(t,u,n)}},E.prototype.render=function(){if(Array.isArray(this._renderProperties))for(var t in this._renderProperties)s(this._renderProperties[t],this._encodings,this._options);else s(this._renderProperties,this._encodings,this._options);return this},E.prototype._defaults=_["default"],"undefined"!=typeof window&&(window.JsBarcode=C),"undefined"!=typeof jQuery&&(jQuery.fn.JsBarcode=function(t,e){var n=[];return jQuery(this).each(function(){n.push(this)}),C(n,t,e)}),t.exports=C}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment