UNPKG

ll-package

Version:

2 lines (1 loc) 3.38 kB
"use strict";const v=require("../../../../_virtual/svg.js");require("../help/merge.js");require("./shared.js");const c=require("../../../../_virtual/shared.js"),g=require("../../../../_virtual/merge.js");Object.defineProperty(v.__exports,"__esModule",{value:!0});var o=function(){function u(s,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(s,e.key,e)}}return function(s,r,t){return r&&u(s.prototype,r),t&&u(s,t),s}}(),x=g.__exports,b=m(x),f=c.__exports;function m(u){return u&&u.__esModule?u:{default:u}}function w(u,s){if(!(u instanceof s))throw new TypeError("Cannot call a class as a function")}var l="http://www.w3.org/2000/svg",A=function(){function u(s,r,t){w(this,u),this.svg=s,this.encodings=r,this.options=t,this.document=t.xmlDocument||document}return o(u,[{key:"render",value:function(){var r=this.options.marginLeft;this.prepareSVG();for(var t=0;t<this.encodings.length;t++){var e=this.encodings[t],i=(0,b.default)(this.options,e.options),n=this.createGroup(r,i.marginTop,this.svg);this.setGroupOptions(n,i),this.drawSvgBarcode(n,i,e),this.drawSVGText(n,i,e),r+=e.width}}},{key:"prepareSVG",value:function(){for(;this.svg.firstChild;)this.svg.removeChild(this.svg.firstChild);(0,f.calculateEncodingAttributes)(this.encodings,this.options);var r=(0,f.getTotalWidthOfEncodings)(this.encodings),t=(0,f.getMaximumHeightOfEncodings)(this.encodings),e=r+this.options.marginLeft+this.options.marginRight;this.setSvgAttributes(e,t),this.options.background&&this.drawRect(0,0,e,t,this.svg).setAttribute("style","fill:"+this.options.background+";")}},{key:"drawSvgBarcode",value:function(r,t,e){var i=e.data,n;t.textPosition=="top"?n=t.fontSize+t.textMargin:n=0;for(var a=0,d=0,h=0;h<i.length;h++)d=h*t.width+e.barcodePadding,i[h]==="1"?a++:a>0&&(this.drawRect(d-t.width*a,n,t.width*a,t.height,r),a=0);a>0&&this.drawRect(d-t.width*(a-1),n,t.width*a,t.height,r)}},{key:"drawSVGText",value:function(r,t,e){var i=this.document.createElementNS(l,"text");if(t.displayValue){var n,a;i.setAttribute("style","font:"+t.fontOptions+" "+t.fontSize+"px "+t.font),t.textPosition=="top"?a=t.fontSize-t.textMargin:a=t.height+t.textMargin+t.fontSize,t.textAlign=="left"||e.barcodePadding>0?(n=0,i.setAttribute("text-anchor","start")):t.textAlign=="right"?(n=e.width-1,i.setAttribute("text-anchor","end")):(n=e.width/2,i.setAttribute("text-anchor","middle")),i.setAttribute("x",n),i.setAttribute("y",a),i.appendChild(this.document.createTextNode(e.text)),r.appendChild(i)}}},{key:"setSvgAttributes",value:function(r,t){var e=this.svg;e.setAttribute("width",r+"px"),e.setAttribute("height",t+"px"),e.setAttribute("x","0px"),e.setAttribute("y","0px"),e.setAttribute("viewBox","0 0 "+r+" "+t),e.setAttribute("xmlns",l),e.setAttribute("version","1.1"),e.setAttribute("style","transform: translate(0,0)")}},{key:"createGroup",value:function(r,t,e){var i=this.document.createElementNS(l,"g");return i.setAttribute("transform","translate("+r+", "+t+")"),e.appendChild(i),i}},{key:"setGroupOptions",value:function(r,t){r.setAttribute("style","fill:"+t.lineColor+";")}},{key:"drawRect",value:function(r,t,e,i,n){var a=this.document.createElementNS(l,"rect");return a.setAttribute("x",r),a.setAttribute("y",t),a.setAttribute("width",e),a.setAttribute("height",i),n.appendChild(a),a}}]),u}();v.__exports.default=A;