(function(k,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@barcode-bakery/barcode-common")):typeof define=="function"&&define.amd?define(["exports","@barcode-bakery/barcode-common"],i):(k=typeof globalThis<"u"?globalThis:k||self,i(k["barcode-bakery-1d"]={},k["barcode-bakery-common"]))})(this,function(k,i){"use strict";var M=Object.defineProperty;var z=(k,i,G)=>i in k?M(k,i,{enumerable:!0,configurable:!0,writable:!0,value:G}):k[i]=G;var a=(k,i,G)=>(z(k,typeof i!="symbol"?i+"":i,G),G);class G extends i.BCGBarcode1D{constructor(){super(),this.keys=["0","1","2","3","4","5","6","7","8","9","-","",":","/",".","+","A","B","C","D"],this.code=["00000110","00001100","00010010","11000000","00100100","10000100","01000010","01001000","01100000","10010000","00011000","00110000","10001010","10100010","10101000","00111110","00110100","01010010","00010110","00011100"]}parse(r){super.parse(r.toUpperCase())}draw(r){const t=this.text.length;for(let e=0;e0;l--,n++){let c=l%r[e];c===0&&(c=r[e]),h+=this.findIndex(t[n])*c}this.checksumValue[e]=h%11,t+=this.keys[this.checksumValue[e]]}}processChecksum(){if(this.checksumValue===null&&this.calculateChecksum(),this.checksumValue!==null){let r="";const t=this.checksumValue.length;for(let e=0;e=1&&e<=26?"$"+String.fromCharCode(e+64):e>=33&&e<=44||e===47||e===48?"/"+String.fromCharCode(e+32):e>=97&&e<=122?"+"+String.fromCharCode(e-32):e>=27&&e<=31?"%"+String.fromCharCode(e+38):e>=59&&e<=63?"%"+String.fromCharCode(e+11):e>=91&&e<=95?"%"+String.fromCharCode(e-16):e>=123&&e<=127?"%"+String.fromCharCode(e-43):e===64?"%V":e===96?"%W":e>127?null:t}};a(x,"EXTENDED_1",39),a(x,"EXTENDED_2",40),a(x,"EXTENDED_3",41),a(x,"EXTENDED_4",42);let X=x;const B=class B extends i.BCGBarcode1D{constructor(){super();a(this,"starting");a(this,"ending");a(this,"data",null);a(this,"indcheck",null);this.starting=this.ending=47,this.keys=["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.code=["020001","000102","000201","000300","010002","010101","010200","000003","020100","030000","100002","100101","100200","110001","110100","120000","001002","001101","001200","011001","021000","000012","000111","000210","010011","020010","101001","101100","100011","100110","110010","111000","001011","001110","011010","012000","010020","200001","200100","210000","001020","002010","100020","010110","201000","200010","011100","000030"]}parse(t){this.text=t;const e=[],s=[],h=this.text.length;for(let l=0;l0;l--,n++){let c=l%t[s];c===0&&(c=t[s]),h+=e[n]*c}this.checksumValue[s]=h%47,e.push(this.checksumValue[s])}}processChecksum(){if(this.checksumValue===null&&this.calculateChecksum(),this.checksumValue!==null){let t="";const e=this.checksumValue.length;for(let s=0;s=1&&e<=26?"$"+String.fromCharCode(e+64):e>=33&&e<=44||e===47||e===48?"/"+String.fromCharCode(e+32):e>=97&&e<=122?"+"+String.fromCharCode(e-32):e>=27&&e<=31?"%"+String.fromCharCode(e+38):e>=59&&e<=63?"%"+String.fromCharCode(e+11):e>=91&&e<=95?"%"+String.fromCharCode(e-16):e>=123&&e<=127?"%"+String.fromCharCode(e-43):e===64?"%V":e===96?"%W":e>127?null:t}};a(B,"EXTENDED_1",43),a(B,"EXTENDED_2",44),a(B,"EXTENDED_3",45),a(B,"EXTENDED_4",46);let O=B;const u=class u extends i.BCGBarcode1D{constructor(t){super();a(this,"keysA");a(this,"keysB");a(this,"keysC");a(this,"startingText",null);a(this,"data",null);a(this,"indcheck",null);a(this,"lastTable",null);a(this,"tilde",!1);a(this,"shift");a(this,"latch");a(this,"fnc");a(this,"METHOD");this.keysA=` !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`;for(let e=0;e<32;e++)this.keysA+=String.fromCharCode(e);this.keysB=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.keysC="0123456789",this.code=["101111","111011","111110","010112","010211","020111","011102","011201","021101","110102","110201","120101","001121","011021","011120","002111","012011","012110","112100","110021","110120","102101","112001","201020","200111","210011","210110","201101","211001","211100","101012","101210","121010","000212","020012","020210","001202","021002","021200","100202","120002","120200","001022","001220","021020","002012","002210","022010","202010","100220","120020","102002","102200","102020","200012","200210","220010","201002","201200","221000","203000","110300","320000","000113","000311","010013","010310","030011","030110","001103","001301","011003","011300","031001","031100","130100","110003","302000","130001","023000","000131","010031","010130","003101","013001","013100","300101","310001","310100","101030","103010","301010","000032","000230","020030","003002","003200","300002","300200","002030","003020","200030","300020","100301","100103","100121","122000"],this.setStart(t||null),this.setTilde(!0),this.latch=[[-1,u.KEYA_CODEB,u.KEYA_CODEC],[u.KEYB_CODEA,-1,u.KEYB_CODEC],[u.KEYC_CODEA,u.KEYC_CODEB,-1]],this.shift=[[-1,u.KEYA_SHIFT],[u.KEYB_SHIFT,-1]],this.fnc=[[u.KEYA_FNC1,u.KEYA_FNC2,u.KEYA_FNC3,u.KEYA_FNC4],[u.KEYB_FNC1,u.KEYB_FNC2,u.KEYB_FNC3,u.KEYB_FNC4],[u.KEYC_FNC1,-1,-1,-1]],this.METHOD={[u.Code.Auto]:"#",[u.Code.A]:"A",[u.Code.B]:"B",[u.Code.C]:"C"}}setStart(t){if(t!=="A"&&t!=="B"&&t!=="C"&&t!==null)throw new i.BCGArgumentException("The starting table must be A, B, C or null.","table");this.startingText=t}getTilde(){return this.tilde}setTilde(t){this.tilde=!!t}parse(t){let e;typeof t=="string"?e=[new i.BCGDataInput(u.Code.Auto,t)]:Array.isArray(t)?e=t:e=[t],this.setStartFromText(e[0].mode,e[0].data),this.text="";let s="",h=this.startingText;for(const l of e)if(l.mode===u.Code.Auto)s+=this.getSequence(l.data,h),this.text+=l.data;else{const n=this.invokeSetParse(l.mode,l.data,h);s+=n.value,h=n.currentMode,this.text+=l.data}if(s!==""){const l=this.createBinaryStream(this.text,s);this.setData(l)}this.addDefaultLabel()}invokeSetParse(t,e,s){switch(t){case u.Code.A:return this.setParseA(e,s);case u.Code.B:return this.setParseB(e,s);case u.Code.C:return this.setParseC(e,s);default:throw new Error}}draw(t){if(this.data===null)throw new Error;const e=this.data.length;for(let s=0;s=4&&e.substring(0,4).match(l)!==null?this.startingText="C":h>0&&this.keysB.indexOf(e[0])>=0?this.startingText="B":this.startingText="A"}}extractTilde(t,e){if(t[e]==="~")if(t[e+1]!==void 0){if(t[e+1]==="~")return"~~";if(t[e+1]==="F")if(t[e+2]!==void 0){const s=parseInt(t[e+2],10);if(s>=1&&s<=4)return"~F"+s;throw new i.BCGParseException("Code128","Bad ~F. You must provide a number from 1 to 4.")}else throw new i.BCGParseException("Code128","Bad ~F. You must provide a number from 1 to 4.");else throw new i.BCGParseException("Code128","Wrong code after the ~.")}else throw new i.BCGParseException("Code128","Wrong code after the ~.");else throw new i.BCGParseException("Code128","There is no ~ at this location.")}getSequenceParsed(t,e){let s;if(this.tilde){let h="",l=0,n=0;for(;(n=t.indexOf("~",l))!==-1;){const c=this.extractTilde(t,n),o=c==="~~";if(o&&e!=="B")throw new i.BCGParseException("Code128","The Table "+e+" doesn't contain the character ~.");if(c!=="~F1"&&e==="C")throw new i.BCGParseException("Code128","The Table C doesn't contain the function "+c+".");if(s=n-l,e==="C"&&s%2===1)throw new i.BCGParseException("Code128",'The text "'+t+'" must have an even number of character to be encoded in Table C.');h+=i.Utility.strRepeat(".",s),h+=".",h+=o?"":"F",l=n+c.length}if(s=t.length-l,e==="C"&&s%2===1)throw new i.BCGParseException("Code128",'The text "'+t+'" must have an even number of character to be encoded in Table C.');return h+=i.Utility.strRepeat(".",s),h}else return i.Utility.strRepeat(".",t.length)}setParseA(t,e){let s=i.Utility.regexpQuote(this.keysA);this.tilde&&(s+="~");let h;const l=new RegExp("[^"+s+"]");if((h=t.match(l))!==null)throw new i.BCGParseException("Code128",'The text "'+t+`" can't be parsed with the Table A. The character "`+h[0]+'" is not allowed.');{const n=e==="A"?"":"0";return e="A",{value:n+this.getSequenceParsed(t,e),currentMode:e}}}setParseB(t,e){const s=i.Utility.regexpQuote(this.keysB);let h;const l=new RegExp("[^"+s+"]");if((h=t.match(l))!==null)throw new i.BCGParseException("Code128",'The text "'+t+`" can't be parsed with the Table B. The character "`+h[0]+'" is not allowed.');{const n=e==="B"?"":"1";return e="B",{value:n+this.getSequenceParsed(t,e),currentMode:e}}}setParseC(t,e){let s=i.Utility.regexpQuote(this.keysC);this.tilde&&(s+="~F");let h;const l=new RegExp("[^"+s+"]");if((h=t.match(l))!==null)throw new i.BCGParseException("Code128",'The text "'+t+`" can't be parsed with the Table C. The character "`+h[0]+'" is not allowed.');{const n=e==="C"?"":"2";return e="C",{value:n+this.getSequenceParsed(t,e),currentMode:e}}}getSequence(t,e){const h=[[0,1,1],[1,0,1],[1,1,0]],l=[[1e4,1,1e4],[1,1e4,1e4],[1e4,1e4,1e4]],n=[2,2,1];let c=1e4,o=1e4,d=1e4;e==="A"&&(c=0),e==="B"&&(o=0),e==="C"&&(d=0);const p=[c,o,d],C=["","",""];let b=!1,E=0;const A=t.length;for(E=0;E="A"&&C<="B"){const E=C.charCodeAt(0)-65,A=this.shift[c][E];n.push(A),l.push(this.code[A]),o===-1&&(o=c),c=E}else if(b>=0&&b<3){o=-1;const E=this.latch[c][b];E!==null&&(n.push(E),this.lastTable=String.fromCharCode(65+b),l.push(this.code[E]),c=b)}}return[n,l]}encodeChar(t,e,s,h,l,n,c){if(s[l+1]!==void 0&&s[l+1]==="F"){if(h[n+1]==="F"){const o=parseInt(h[n+2],10),d=this.fnc[e][o-1];c.push(d),t.push(this.code[d]),n+=2}l++}else if(e===2){const o=parseInt(h.substring(n,n+2),10);c.push(o),t.push(this.code[o]),n++,l++}else{const d=(e===0?this.keysA:this.keysB).indexOf(h[n]);c.push(d),t.push(this.code[d])}return n++,{data:t,i:l,counter:n,indcheck:c}}setData(t){if(this.indcheck=t[0],this.data=t[1],this.calculateChecksum(),this.checksumValue===null)throw new Error;this.data.push(this.code[this.checksumValue[0]]),this.data.push(this.code[u.KEY_STOP])}};a(u,"KEYA_FNC3",96),a(u,"KEYA_FNC2",97),a(u,"KEYA_SHIFT",98),a(u,"KEYA_CODEC",99),a(u,"KEYA_CODEB",100),a(u,"KEYA_FNC4",101),a(u,"KEYA_FNC1",102),a(u,"KEYB_FNC3",96),a(u,"KEYB_FNC2",97),a(u,"KEYB_SHIFT",98),a(u,"KEYB_CODEC",99),a(u,"KEYB_FNC4",100),a(u,"KEYB_CODEA",101),a(u,"KEYB_FNC1",102),a(u,"KEYC_CODEB",100),a(u,"KEYC_CODEA",101),a(u,"KEYC_FNC1",102),a(u,"KEY_STARTA",103),a(u,"KEY_STARTB",104),a(u,"KEY_STARTC",105),a(u,"KEY_STOP",106);let V=u;(D=>{(r=>{r[r.Auto=0]="Auto",r[r.A=1]="A",r[r.B=2]="B",r[r.C=3]="C"})(D.Code||(D.Code={}))})(V||(V={}));class j extends i.BCGBarcode1D{constructor(){super();a(this,"labelLeft",null);a(this,"labelRight",null);this.keys=["0","1","2","3","4","5","6","7","8","9"],this.code=["2100","1110","1011","0300","0021","0120","0003","0201","0102","2001"]}draw(t){if(this.calculateChecksum(),this.checksumValue===null)throw new Error;const e=this.text+this.keys[this.checksumValue[0]];this.drawChar(t,"000",!0);for(let s=0;s<4;s++)this.drawChar(t,this.findCode(e[s]),!1);this.drawChar(t,"00000",!1);for(let s=4;s<8;s++)this.drawChar(t,this.findCode(e[s]),!0);if(this.drawChar(t,"000",!0),this.drawText(t,0,0,this.positionX,this.thickness),this.isDefaultEanLabelEnabled()){if(this.labelRight===null)throw new Error;const s=this.labelRight.getDimension(t.createSurface);this.drawExtendedBars(t,s[1]-2)}}getDimension(t,e,s){var o;if(s){if(this.labelLeft){const d=this.labelLeft.getDimension(s);(o=this.labelLeft)==null||o.setOffset((this.scale*30-d[0])/2+this.scale*2)}if(this.labelRight){const d=this.labelRight.getDimension(s);this.labelRight.setOffset((this.scale*30-d[0])/2+this.scale*34)}}return t+=67,e+=this.thickness,super.getDimension(t,e,s)}addDefaultLabel(){if(this.isDefaultEanLabelEnabled()){if(this.processChecksum(),this.checksumValue===null)throw new Error;const t=this.getLabel();if(t===null)throw new Error;const e=this.font;this.labelLeft=new i.BCGLabel(t.substring(0,4),e,i.BCGLabel.Position.Bottom,i.BCGLabel.Alignment.Left),this.labelRight=new i.BCGLabel(t.substring(4,7)+this.keys[this.checksumValue[0]],e,i.BCGLabel.Position.Bottom,i.BCGLabel.Alignment.Left),this.addLabel(this.labelLeft),this.addLabel(this.labelRight)}}isDefaultEanLabelEnabled(){const t=this.getLabel(),e=this.font;return t!==null&&t!==""&&e!==null&&this.defaultLabel!==null}validate(){const t=this.text.length;if(t===0)throw new i.BCGParseException("Ean8","No data has been entered.");for(let e=0;e0;h--){if(t===!0?(s=3,t=!1):(s=1,t=!0),i.Utility.arraySearch(this.keys,this.text[h-1])===-1)return;const l=parseInt(this.text[h-1],10),n=parseInt(this.keys[l],10);this.checksumValue[0]+=n*s}this.checksumValue[0]=(10-this.checksumValue[0]%10)%10}processChecksum(){return this.checksumValue===null&&this.calculateChecksum(),this.checksumValue!==null?this.keys[this.checksumValue[0]]:null}drawExtendedBars(t,e){const s=this.positionX,h=this.thickness;this.thickness=this.thickness+parseInt((e/this.scale).toString(),10),this.positionX=0,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=30,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=30,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX=s,this.thickness=h}}class P extends i.BCGBarcode1D{constructor(){super();a(this,"codeParity");a(this,"labelLeft",null);a(this,"labelCenter1",null);a(this,"labelCenter2",null);a(this,"alignLabel",!1);a(this,"handleLabel",!0);this.keys=["0","1","2","3","4","5","6","7","8","9"],this.code=["2100","1110","1011","0300","0021","0120","0003","0201","0102","2001"],this.codeParity=[[0,0,0,0,0],[0,1,0,1,1],[0,1,1,0,1],[0,1,1,1,0],[1,0,0,1,1],[1,1,0,0,1],[1,1,1,0,0],[1,0,1,0,1],[1,0,1,1,0],[1,1,0,1,0]],this.alignDefaultLabel(!0)}alignDefaultLabel(t){this.alignLabel=!!t}draw(t){if(this.drawBars(t),this.drawText(t,0,0,this.positionX,this.thickness),this.isDefaultEanLabelEnabled()){if(this.labelCenter1===null)throw new Error;const e=this.labelCenter1.getDimension(t.createSurface);this.drawExtendedBars(t,e[1]-2)}}getDimension(t,e,s){if(this.handleLabel&&s&&this.labelLeft&&this.labelCenter1&&this.labelCenter2){const o=this.labelCenter1.getDimension(s);if(this.labelCenter1.setOffset((this.scale*44-o[0])/2+this.scale*2),this.labelCenter2.setOffset((this.scale*44-o[0])/2+this.scale*48),this.alignLabel){const d=this.labelCenter1.getDimension(s);this.labelLeft.setOffset(d[1])}else{const d=this.labelLeft.getDimension(s);this.labelLeft.setOffset(d[1]/2)}}return t+=95,e+=this.thickness,super.getDimension(t,e,s)}addDefaultLabel(){if(this.isDefaultEanLabelEnabled()){if(this.processChecksum(),this.checksumValue===null)throw new Error;const t=this.getLabel();if(t===null)throw new Error;const e=this.font;this.labelLeft=new i.BCGLabel(t.substring(0,1),e,i.BCGLabel.Position.Left,i.BCGLabel.Alignment.Bottom),this.labelLeft.setSpacing(4*this.scale),this.labelCenter1=new i.BCGLabel(t.substring(1,7),e,i.BCGLabel.Position.Bottom,i.BCGLabel.Alignment.Left),this.labelCenter2=new i.BCGLabel(t.substring(7,12)+this.keys[this.checksumValue[0]],e,i.BCGLabel.Position.Bottom,i.BCGLabel.Alignment.Left),this.addLabel(this.labelLeft),this.addLabel(this.labelCenter1),this.addLabel(this.labelCenter2)}}isDefaultEanLabelEnabled(){const t=this.getLabel(),e=this.font;return t!==null&&t!==""&&e!==null&&this.defaultLabel!==null}validate(){if(this.text.length===0)throw new i.BCGParseException("Ean13","No data has been entered.");this.checkCharsAllowed(),this.checkCorrectLength(),super.validate()}checkCharsAllowed(){const t=this.text.length;for(let e=0;e0;h--){if(t===!0?(s=3,t=!1):(s=1,t=!0),i.Utility.arraySearch(this.keys,this.text[h-1])===-1)return;const l=parseInt(this.text[h-1],10),n=parseInt(this.keys[l],10);this.checksumValue[0]+=n*s}this.checksumValue[0]=(10-this.checksumValue[0]%10)%10}processChecksum(){return this.checksumValue===null&&this._calculateChecksum(),this.checksumValue!==null?this.keys[this.checksumValue[0]]:null}drawBars(t){if(this._calculateChecksum(),this.checksumValue===null)throw new Error;const e=this.text+this.keys[this.checksumValue[0]];this.drawChar(t,"000",!0),this.drawChar(t,this.findCode(e[1]),!1);for(let s=0;s<5;s++)this.drawChar(t,P.inverse(this.findCode(e[s+2]),this.codeParity[parseInt(e[0],10)][s]),!1);this.drawChar(t,"00000",!1);for(let s=7;s<13;s++)this.drawChar(t,this.findCode(e[s]),!0);this.drawChar(t,"000",!0)}drawExtendedBars(t,e){const s=this.positionX,h=this.thickness;this.thickness=this.thickness+parseInt((e/this.scale).toString(),10),this.positionX=0,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=44,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=44,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX=s,this.thickness=h}static inverse(t,e){return e===1&&(t=i.Utility.strrev(t)),t}}class q extends i.BCGBarcode1D{constructor(){super();a(this,"checksum",!1);a(this,"ratio",2);this.keys=["0","1","2","3","4","5","6","7","8","9"],this.code=["00110","10001","01001","11000","00101","10100","01100","00011","10010","01010"]}setChecksum(t){this.checksum=!!t}setRatio(t){this.ratio=parseInt(t.toString(),10)}draw(t){let e=this.text;if(this.checksum===!0){if(this._calculateChecksum(),this.checksumValue===null)throw new Error;e+=this.keys[this.checksumValue[0]]}this.drawChar(t,"0000",!0);const s=e.length;for(let h=0;h0;h--){t===!0?(s=3,t=!1):(s=1,t=!0);const l=parseInt(this.text[h-1],10),n=parseInt(this.keys[l],10);this.checksumValue[0]+=n*s}this.checksumValue[0]=(10-this.checksumValue[0]%10)%10}processChecksum(){return this.checksumValue===null&&this._calculateChecksum(),this.checksumValue!==null?this.keys[this.checksumValue[0]]:null}changeBars(t){const e=t.split("");if(this.ratio>1){const s=e.length;for(let h=0;h=2;h--)s+=parseInt(this.text[10-h],10)*h;s=11-s%11,t="ISBN "+this.text.substring(0,9)+"-"+(s===10?"X":s)}}return t}}(D=>{(r=>{r[r.Auto=0]="Auto",r[r.PREFIX978=1]="PREFIX978",r[r.PREFIX979=2]="PREFIX979"})(D.GS1||(D.GS1={}))})(L||(L={}));class _ extends i.BCGBarcode1D{constructor(){super();a(this,"checksum",0);this.keys=["0","1","2","3","4","5","6","7","8","9"],this.code=["01010101","01010110","01011001","01011010","01100101","01100110","01101001","01101010","10010101","10010110"]}setChecksum(t){if(t=parseInt(t.toString(),10),t<0&&t>2)throw new i.BCGArgumentException("The checksum must be between 0 and 2 included.","checksum");this.checksum=t}draw(t){if(this.calculateChecksum(),this.checksumValue===null)throw new Error;this.drawChar(t,"10",!0);let e=this.text.length;for(let s=0;s0;h--){t===!0?(s=3,t=!1):(s=1,t=!0);let l=parseInt(this.text[h-1],10),n=parseInt(this.keys[l],10);this.checksumValue[0]+=n*s}this.checksumValue[0]=(10-this.checksumValue[0]%10)%10}processChecksum(){return this.checksumValue===null&&this.calculateChecksum(),this.checksumValue!==null?this.keys[this.checksumValue[0]]:null}}class $ extends P{constructor(){super();a(this,"labelRight",null)}draw(t){this.text="0"+this.text,super.draw(t),this.text=this.text.substring(1)}drawExtendedBars(t,e){if(this.checksumValue===null)throw new Error;const s=this.text+this.keys[this.checksumValue[0]],h=this.positionX,l=this.thickness;this.thickness=this.thickness+parseInt((e/this.scale).toString(),10),this.positionX=0,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=1;let n=this.findCode(s[1]);this.drawChar(t,n,!1),this.positionX+=36,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=37,n=this.findCode(s[12]),this.drawChar(t,n,!0),this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX=h,this.thickness=l}getDimension(t,e,s){if(this.handleLabel=!1,s&&this.labelLeft&&this.labelCenter1&&this.labelCenter2&&this.labelRight){const h=this.labelCenter1.getDimension(s);this.labelCenter1.setOffset((this.scale*44-h[0])/2+this.scale*6),this.labelCenter2.setOffset((this.scale*44-h[0])/2+this.scale*45);let l;this.alignLabel?(l=this.labelCenter1.getDimension(s),this.labelLeft.setOffset(l[1]),this.labelRight.setOffset(l[1])):(l=this.labelLeft.getDimension(s),this.labelLeft.setOffset(l[1]/2),l=this.labelLeft.getDimension(s),this.labelRight.setOffset(l[1]/2))}return super.getDimension(t,e,s)}addDefaultLabel(){if(this.isDefaultEanLabelEnabled()){if(this.processChecksum(),this.checksumValue===null)throw new Error;const t=this.getLabel();if(t===null)throw new Error;const e=this.font;this.labelLeft=new i.BCGLabel(t.substring(0,1),e,i.BCGLabel.Position.Left,i.BCGLabel.Alignment.Bottom),this.labelLeft.setSpacing(4*this.scale),this.labelCenter1=new i.BCGLabel(t.substring(1,6),e,i.BCGLabel.Position.Bottom,i.BCGLabel.Alignment.Left),this.labelCenter2=new i.BCGLabel(t.substring(6,11),e,i.BCGLabel.Position.Bottom,i.BCGLabel.Alignment.Left),this.labelRight=new i.BCGLabel(this.keys[this.checksumValue[0]],e,i.BCGLabel.Position.Right,i.BCGLabel.Alignment.Bottom),this.labelRight.setSpacing(4*this.scale),this.addLabel(this.labelLeft),this.addLabel(this.labelCenter1),this.addLabel(this.labelCenter2),this.addLabel(this.labelRight)}}checkCorrectLength(){const t=this.text.length;if(t===12)this.text=this.text.substring(0,11);else if(t!==11)throw new i.BCGParseException("Upca","Must contain 11 digits, the 12th digit is automatically added.")}}class R extends i.BCGBarcode1D{constructor(){super();a(this,"codeParity");a(this,"upce",null);a(this,"labelLeft",null);a(this,"labelCenter",null);a(this,"labelRight",null);this.codeParity=[],this.labelLeft=null,this.labelCenter=null,this.labelRight=null,this.keys=["0","1","2","3","4","5","6","7","8","9"],this.code=["2100","1110","1011","0300","0021","0120","0003","0201","0102","2001"],this.codeParity=[[[1,1,1,0,0,0],[1,1,0,1,0,0],[1,1,0,0,1,0],[1,1,0,0,0,1],[1,0,1,1,0,0],[1,0,0,1,1,0],[1,0,0,0,1,1],[1,0,1,0,1,0],[1,0,1,0,0,1],[1,0,0,1,0,1]],[[0,0,0,1,1,1],[0,0,1,0,1,1],[0,0,1,1,0,1],[0,0,1,1,1,0],[0,1,0,0,1,1],[0,1,1,0,0,1],[0,1,1,1,0,0],[0,1,0,1,0,1],[0,1,0,1,1,0],[0,1,1,0,1,0]]]}draw(t){if(this.calculateChecksum(),this.checksumValue===null)throw new Error;this.drawChar(t,"000",!0);const e=this.upce.length;for(let s=0;s=5&&s<=9&&(this.upce=this.text.substring(1,6)+this.text.substring(10,11))}}else this.upce=this.text;if(this.upce==="")throw new i.BCGParseException("Upce","Your UPC-A can't be converted to UPC-E.");if(t===6){let e="";this.text[5]==="0"||this.text[5]==="1"||this.text[5]==="2"?e=this.text.substring(0,2)+this.text[5]+"0000"+this.text.substring(2,5):this.text[5]==="3"?e=this.text.substring(0,3)+"00000"+this.text.substring(3,5):this.text[5]==="4"?e=this.text.substring(0,4)+"00000"+this.text[4]:e=this.text.substring(0,5)+"0000"+this.text[5],this.text="0"+e}super.validate()}calculateChecksum(){let t=!0;this.checksumValue=[0];const e=this.text.length;let s;for(let h=e;h>0;h--){if(t===!0?(s=3,t=!1):(s=1,t=!0),i.Utility.arraySearch(this.keys,this.text[h-1])===-1)return;const l=parseInt(this.text[h-1],10),n=parseInt(this.keys[l],10);this.checksumValue[0]+=n*s}this.checksumValue[0]=(10-this.checksumValue[0]%10)%10}processChecksum(){return this.checksumValue===null&&this.calculateChecksum(),this.checksumValue!==null?this.keys[this.checksumValue[0]]:null}drawExtendedBars(t,e){const s=this.positionX,h=this.thickness;this.thickness=this.thickness+parseInt((e/this.scale).toString(),10),this.positionX=0,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=46,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX+=2,this.drawSingleBar(t,i.BCGBarcode.COLOR_FG),this.positionX=s,this.thickness=h}static inverse(t,e){return e===1&&(t=i.Utility.strrev(t)),t}}class v extends i.BCGBarcode1D{constructor(){super();a(this,"codeParity");this.keys=["0","1","2","3","4","5","6","7","8","9"],this.code=["2100","1110","1011","0300","0021","0120","0003","0201","0102","2001"],this.codeParity=[[0,0],[0,1],[1,0],[1,1]]}draw(t){this.drawChar(t,"001",!0);for(let e=0;e<2;e++)this.drawChar(t,v.inverse(this.findCode(this.text[e]),this.codeParity[parseInt(this.text,10)%4][e]),!1),e===0&&this.drawChar(t,"00",!1);this.drawText(t,0,0,this.positionX,this.thickness)}getDimension(t,e,s){return t+=20,e+=this.thickness,super.getDimension(t,e,s)}addDefaultLabel(){super.addDefaultLabel(),this.defaultLabel!==null&&this.defaultLabel.setPosition(i.BCGLabel.Position.Top)}validate(){const t=this.text.length;if(t===0)throw new i.BCGParseException("Upcext2","No data has been entered.");for(let e=0;e0;h--){if(t===!0?(s=3,t=!1):(s=9,t=!0),i.Utility.arraySearch(this.keys,this.text[h-1])===-1)return;const l=parseInt(this.text[h-1],10),n=parseInt(this.keys[l],10);this.checksumValue[0]+=n*s}this.checksumValue[0]=this.checksumValue[0]%10}processChecksum(){return this.checksumValue===null&&this.calculateChecksum(),this.checksumValue!==null?this.keys[this.checksumValue[0]]:null}static inverse(t,e){return e===1&&(t=i.Utility.strrev(t)),t}}k.BCGcodabar=G,k.BCGcode11=H,k.BCGcode128=V,k.BCGcode39=F,k.BCGcode39extended=X,k.BCGcode93=O,k.BCGean13=P,k.BCGean8=j,k.BCGi25=q,k.BCGisbn=L,k.BCGmsi=_,k.BCGothercode=Q,k.BCGs25=W,k.BCGupca=$,k.BCGupce=R,k.BCGupcext2=v,k.BCGupcext5=I,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});