/**
 * @file utils.ts
 * @author DothanTech (hudianxing@dothantech.com)
 * @brief PC JavaScript 版本 相关接口类型及方法定义。
 * @version 2.1
 * @date 2022-05-16
 *
 * @copyright Copyright (c) 2022
 *
 */
var e,t,n,r,i,o,a,s,u,l,c,h,g,p,d,f,m,y,v,_,b,N,T="GET",E="127.0.0.1",P=15216,I=35216,A=2e3,O=5e3,R=40,w=30,D="黑体",L=3.5,C=.35,B=[.5,.5],x=1.5,S=5,W=20,M=192,j=4096,q="lpapi",k="local",F="Version",U="SetSupportedPrinters",K="GetDefaultPrinter",V="SetDefaultPrinter",H="DiscoveryPrinters",J="GetPrinters",G="OpenPrinter",$="ClosePrinter",X="IsPrinterOpened",Y="IsPrinterOnline",z="GetPrinterName",Q="ShowProperty",Z="PrintImageD",ee="Print",te="GetParam",ne="SetParam",re="GetPrinterDPI",ie="SetItemOrientation",oe="SetItemHorizontalAlignment",ae="SetItemVerticalAlignment",se="StartJob",ue="AbortJob",le="CommitJob",ce="GetJobID",he="GetJobInfo",ge="GetPageInfo",pe="GetPageImage",de="StartPage",fe="EndPage",me="ReturnDrawResult",ye="DrawText",ve="Draw1DBarcode",_e="Draw2DQRCode",be="Draw2DPdf417",Ne="Draw2DDataMatrix",Te="DrawRectangle",Ee="DrawRoundRectangle",Pe="DrawEllipse",Ie="DrawLine",Ae="DrawDashLine",Oe="DrawImage",Re="DrawImageD",we="ServerInfo",De="application/x-www-form-urlencoded;charset=UTF-8",Le="application/octet-stream;encoding=base64",Ce="application/json;charset:utf-8",Be="";!function(e){e[e.GapType=1]="GapType",e[e.PrintDarkness=2]="PrintDarkness",e[e.PrintSpeed=3]="PrintSpeed",e[e.PrinterDPIx=4]="PrinterDPIx",e[e.PrinterDPIy=5]="PrinterDPIy"}(e||(e={})),function(e){e[e.Unset=255]="Unset",e[e.None=0]="None",e[e.Hole=1]="Hole",e[e.Gap=2]="Gap",e[e.Black=3]="Black"}(t||(t={})),function(e){e[e.Unset=255]="Unset",e[e.Min=0]="Min",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Max=4]="Max"}(n||(n={})),function(e){e[e.Unset=255]="Unset",e[e.Min=0]="Min",e[e.Low=3]="Low",e[e.Normal=5]="Normal",e[e.High=9]="High",e[e.Max=14]="Max"}(r||(r={})),function(e){e[e.Start=0]="Start",e[e.Center=1]="Center",e[e.End=2]="End",e[e.Stretch=3]="Stretch",e[e.Expand=4]="Expand"}(i||(i={})),function(e){e[e.Regular=0]="Regular",e[e.Bold=1]="Bold",e[e.Italic=2]="Italic",e[e.BoldItalic=3]="BoldItalic",e[e.Underline=4]="Underline",e[e.Strikeout=8]="Strikeout"}(o||(o={})),function(e){e[e.None=0]="None",e[e.Char=1]="Char",e[e.Word=2]="Word"}(a||(a={})),function(e){e[e.LPA_1DBT_UPC_A=20]="LPA_1DBT_UPC_A",e[e.LPA_1DBT_UPC_E=21]="LPA_1DBT_UPC_E",e[e.LPA_1DBT_EAN13=22]="LPA_1DBT_EAN13",e[e.LPA_1DBT_EAN8=23]="LPA_1DBT_EAN8",e[e.LPA_1DBT_CODE39=24]="LPA_1DBT_CODE39",e[e.LPA_1DBT_ITF25=25]="LPA_1DBT_ITF25",e[e.LPA_1DBT_CODABAR=26]="LPA_1DBT_CODABAR",e[e.LPA_1DBT_CODE93=27]="LPA_1DBT_CODE93",e[e.LPA_1DBT_CODE128=28]="LPA_1DBT_CODE128",e[e.LPA_1DBT_ISBN=29]="LPA_1DBT_ISBN",e[e.LPA_1DBT_ECODE39=30]="LPA_1DBT_ECODE39",e[e.LPA_1DBT_AUTO=60]="LPA_1DBT_AUTO"}(s||(s={})),function(e){e.Preview="#!#Preview#!#",e.Transparent="#!#Transparent#!#",e.Print="dtpweb"}(u||(u={})),function(e){e[e.PrintData=1]="PrintData",e[e.PrevBase64=2]="PrevBase64",e[e.PrevUrl=4]="PrevUrl",e[e.Transparent=128]="Transparent",e[e.TransBase64=130]="TransBase64",e[e.Print=4096]="Print"}(l||(l={})),function(e){e[e.Print=0]="Print",e[e.White=1]="White",e[e.Transparent=2]="Transparent"}(c||(c={})),function(e){e[e.WAIT_FOR_ASYNC=-1]="WAIT_FOR_ASYNC",e[e.OK=0]="OK",e[e.PARAM_ERROR=1]="PARAM_ERROR",e[e.SYSTEM_ERROR=2]="SYSTEM_ERROR",e[e.NO_SUPPORTED_PRINTER=3]="NO_SUPPORTED_PRINTER",e[e.UNSUPPORTED_PRINTER=4]="UNSUPPORTED_PRINTER",e[e.NO_PRINT_DATA=5]="NO_PRINT_DATA",e[e.NO_PAGE_DIMENSION=6]="NO_PAGE_DIMENSION",e[e.INVALID_FILE=7]="INVALID_FILE",e[e.ERROR_START_JOB=8]="ERROR_START_JOB",e[e.UNSUPPORTED_FUNCTION=9]="UNSUPPORTED_FUNCTION",e[e.INVALID_FONT_NAME=10]="INVALID_FONT_NAME",e[e.NETWORK_FAILED=90]="NETWORK_FAILED",e[e.NETWORK_TIMEOUT=91]="NETWORK_TIMEOUT",e[e.NETWORK_ERROR=92]="NETWORK_ERROR",e[e.NETWORK_ABORT=93]="NETWORK_ABORT",e[e.NETWORK_UNSUPPORTED=94]="NETWORK_UNSUPPORTED",e[e.NETWORK_EXCEPTION=95]="NETWORK_EXCEPTION"}(h||(h={})),function(e){e[e.ShowReadNone=0]="ShowReadNone",e[e.ShowReadDown=1]="ShowReadDown",e[e.ShowReadUp=2]="ShowReadUp",e[e.ShowStartStop=4]="ShowStartStop",e[e.EanCheckCode=8]="EanCheckCode"}(g||(g={})),function(e){e[e.Unicode=0]="Unicode",e[e.Ansi=1]="Ansi",e[e.UTF8=2]="UTF8"}(p||(p={})),function(e){e[e.ModeNum=0]="ModeNum",e[e.ModeAn=1]="ModeAn",e[e.Mode8Bit=2]="Mode8Bit",e[e.ModeKanji=3]="ModeKanji",e[e.ModeStructure=4]="ModeStructure",e[e.ModeEci=5]="ModeEci",e[e.ModeFnc1First=6]="ModeFnc1First",e[e.ModeFnc1Second=7]="ModeFnc1Second"}(d||(d={})),function(e){e[e.EccLevel_L=0]="EccLevel_L",e[e.EccLevel_M=1]="EccLevel_M",e[e.EccLevel_Q=2]="EccLevel_Q",e[e.EccLevel_H=3]="EccLevel_H"}(f||(f={})),function(e){e[e.Unicode=0]="Unicode",e[e.Ansi=1]="Ansi",e[e.UTF8=2]="UTF8"}(m||(m={})),function(e){e[e.ModeAuto=0]="ModeAuto",e[e.ModeNumeric=1]="ModeNumeric",e[e.ModeText=2]="ModeText",e[e.ModeBinary=3]="ModeBinary"}(y||(y={})),function(e){e[e.EccLevel_Auto=0]="EccLevel_Auto",e[e.EccLevel_1=1]="EccLevel_1",e[e.EccLevel_2=2]="EccLevel_2",e[e.EccLevel_3=3]="EccLevel_3",e[e.EccLevel_4=4]="EccLevel_4",e[e.EccLevel_5=5]="EccLevel_5",e[e.EccLevel_6=6]="EccLevel_6",e[e.EccLevel_7=7]="EccLevel_7",e[e.EccLevel_8=8]="EccLevel_8"}(v||(v={})),function(e){e[e.LPASIF_RAWDATA=0]="LPASIF_RAWDATA",e[e.LPASIF_BPP_1=1]="LPASIF_BPP_1",e[e.LPASIF_BPP_1N=2]="LPASIF_BPP_1N",e[e.LPASIF_32_RGBA=32]="LPASIF_32_RGBA",e[e.LPASIF_32_BGRA=33]="LPASIF_32_BGRA",e[e.LPASIF_32_RGB=34]="LPASIF_32_RGB",e[e.LPASIF_32_BGR=35]="LPASIF_32_BGR",e[e.LPASIF_PACKAGE=90]="LPASIF_PACKAGE",e[e.LPASIF_IMAGEDATA=93]="LPASIF_IMAGEDATA"}(_||(_={})),function(e){e[e.UrlEncoded=0]="UrlEncoded",e[e.Base64=1]="Base64",e[e.Json=2]="Json",e[e.Blob=3]="Blob"}(b||(b={})),function(e){e.Text="text",e.Barcode="barcode",e.QRCode="qrcode",e.Pdf417="pdf417",e.DataMatrix="dataMatrix",e.Image="image",e.Rect="rectangle",e.RoundRect="roundRectangle",e.Ellipse="ellipse",e.Line="line",e.DashLine="dashLine"}(N||(N={}));var xe={scaleUnit:0,getJobAction:function(e){var t=e||"";return t.startsWith("#!#Prev")?2:t.startsWith("#!#Trans")?130:4096},assignValue:function(e,t){var n=e||{};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(this.isPlainObject(n[r])&&this.isPlainObject(t[r])?this.assignValue(n[r],t[r]):this.isPlainObject(t[r])?n[r]=this.assignValue({},t[r]):Array.isArray(t[r])?n[r]=t[r].slice():n[r]=t[r]);return n},merge:function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=e||{};if(!t)return r;for(var i=0;i<t.length;i++)r=this.assignValue(r,t[i]);return r},isObject:function(e){return null!==e&&"object"==typeof e},isPlainObject:function(e){if("[object Object]"!==toString.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype},isArrayBuffer:function(e){return"[object ArrayBuffer]"===toString.call(e)},isArray:function(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)},isHttpsRequest:function(e){return/https:?/.test(e)},isNumberString:function(e){return!!e&&(!!(e=e.trim()).match(/^[-+]?[0-9]*\.?[0-9]+$/)||!!e.match(/^(0x)?[0-9a-f]+$/i))},isBooleanString:function(e){return!!e&&!!(e=e.trim()).match(/^(yes)|(no)|(true)|(false)$/i)},getNumber:function(e,t){return e=(e||"").trim(),this.isNumberString(e)?Number(e):t||0},getBoolean:function(e,t){return!!(e=(e||"").trim()).match(/^(yes)|(true)$/i)||!e.match(/^(no)|(false)$/i)&&(t||!1)},parseArray:function(e,t){void 0===t&&(t=1);var n=[];if(xe.isArray(e))return e;if("string"==typeof e)return e.split(",");if("number"==typeof e)for(var r=0;r<t;r++)n.push(e);return n},parseMargin:function(e){var t,n,r,i,o=[];if(e.margin&&(1===(o=xe.parseArray(e.margin,4)).length?o=[o[0],o[0],o[0],o[0]]:2===o.length?o=[o[0],o[1],o[0],o[1]]:3===o.length&&o.push(o[1])),e.marginH){var a=xe.parseArray(e.marginH,2);o[1]=null!==(t=a[0])&&void 0!==t?t:0,o[3]=null!==(n=a[1])&&void 0!==n?n:a[0]}if(e.marginV){a=xe.parseArray(e.marginV,2);o[0]=null!==(r=a[0])&&void 0!==r?r:0,o[2]=null!==(i=a[1])&&void 0!==i?i:a[0]}return o},getParamString:function(e){e=e||{};var t=[];for(var n in e){var r=e[n];null!=r&&("object"!=typeof r&&"function"!=typeof r&&t.push("".concat(n,"=").concat(encodeURIComponent(r))))}return t.length>0?t.join("&"):""},getRequestData:function(e,t){if(null==t?t=[]:"object"!=typeof t&&(t=[t]),t.length&&"object"==typeof t[0])return t[0];var n={};if("string"==typeof e&&(e=[e]),e.length<1||!e[0])return n;for(var r=0;r<e.length;r++)n[e[r]]=t[r];return n},filterRecord:function(e,t){return Object.keys(e).filter((function(n){return t(n,e[n])})).reduce((function(t,n){return t[n]=e[n],t}),{})},processResult:function(e,t,n){t&&t(e),n&&n(e)},buildURL:function(e,t){var n="string"==typeof t?t:this.getParamString(t);return n?"".concat(e,":").concat(n):e},request:function(e,t){"undefined"!=typeof XMLHttpRequest?this.requestXMLHttp(e,t):"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process)?this.requestNodeHttp(e,t):t({statusCode:h.NETWORK_UNSUPPORTED,resultInfo:"not supported http request environment!"})},requestXMLHttp:function(e,t){var n,r=new XMLHttpRequest,i=e.host||E,o=e.port||P,a=e.baseUrl||"http://".concat(i,":").concat(o),s=e.data,u=e.headers;e.url&&"/"===e.url[0]&&(e.url=e.url.substring(1));var l="".concat(a,"/").concat(e.url);try{r.open(e.method||T,l,!e.sync),e.timeout&&!e.sync&&(r.timeout=e.timeout);var c=function(){r&&(n=200===r.status?JSON.parse(r.responseText):{statusCode:h.NETWORK_FAILED,resultInfo:r.responseText},t(n),r=null)};if("onloadend"in r?r.onloadend=c:r.onreadystatechange=function(){r&&4===r.readyState&&(0!==r.status||r.responseURL&&0===r.responseURL.indexOf("file:"))&&setTimeout(c)},r.onabort=function(){r&&(t({statusCode:h.NETWORK_ABORT,resultInfo:"Request aborted!"}),r=null)},r.onerror=function(){t({statusCode:h.NETWORK_ERROR,resultInfo:"Network Error"}),r=null},r.ontimeout=function(){t({statusCode:h.NETWORK_TIMEOUT,resultInfo:e.timeout?"timeout of ".concat(e.timeout,"ms exceeded"):"timeout exceeded"}),r=null},u&&"setRequestHeader"in r)for(var g in u)void 0===s&&"content-type"===g.toLowerCase()?delete u[g]:r.setRequestHeader(g,u[g]);r.send(s)}catch(e){t({statusCode:h.NETWORK_EXCEPTION,resultInfo:e})}},requestNodeHttp:function(e,t){var n=require("http");e.url&&"/"!==e.url[0]&&(e.url="/".concat(e.url));var r={host:e.host||E,port:e.port||P,method:e.method||T,path:e.url,headers:e.headers},i="",o=n.request(r,(function(e){e.on("data",(function(e){i+=e})),e.on("end",(function(){var e={statusCode:h.NETWORK_EXCEPTION,resultInfo:i};try{e=JSON.parse(i)}catch(e){console.log(e)}t(e)})),e.on("error",(function(e){n.aborted||t({statusCode:h.NETWORK_ERROR,resultInfo:e})}))}));if(o.on("error",(function(e){t({statusCode:h.NETWORK_FAILED,resultInfo:e})})),o.on("socket",(function(e){e.setKeepAlive(!0,6e4)})),e.timeout){var a=e.timeout;o.setTimeout(a,(function(){o.destroy(),t({statusCode:h.NETWORK_TIMEOUT,resultInfo:e.timeout?"timeout of ".concat(e.timeout,"ms exceeded"):"timeout exceeded"})}))}o.end(e.data)},unitConvert:function(e){return 1===this.scaleUnit&&e?100*e:e},poundToMm:function(e){return 25.4*e/72},mmToPound:function(e){return 72*e/25.4},unitConvertOfDrawBase:function(e,t){e=e||{};var n=t||[],r=n[3]||0,i=n[0]||0,o=n[4]||0,a=n[5]||0,s=e.x||0,u=e.y||0;return e.x=this.unitConvert(s+r+o),e.y=this.unitConvert(u+i+a),e.width=this.unitConvert(e.width),e.height=this.unitConvert(e.height),e.orientation&&e.orientation>3&&(e.orientation=e.orientation/90),e},unitConvertOfDrawRect:function(e,t){return(e=this.unitConvertOfDrawBase(e,t)).width=e.width||this.unitConvert(W),e.height=e.height||e.width,e.cornerWidth=this.unitConvert(e.cornerWidth),e.cornerHeight=this.unitConvert(e.cornerHeight)||e.cornerWidth,e.lineWidth=this.unitConvert(e.lineWidth||C),e},unitConvertOfLine:function(e,t){var n,r;e=e||{};var i=t||[],o=i[3]||0,a=i[0]||0,s=i[4]||0,u=i[5]||0,l=e.x1||0,c=e.y1||0,h=null!==(n=e.x2)&&void 0!==n?n:l,g=null!==(r=e.y2)&&void 0!==r?r:c;if(e.x1=this.unitConvert(l+o+s),e.y1=this.unitConvert(c+a+u),e.x2=this.unitConvert(h+o+s),e.y2=this.unitConvert(g+a+u),e.lineWidth=this.unitConvert(e.lineWidth||C),!e.dashLens&&xe.isArray(e.dashLen)?(e.dashLens=e.dashLen,e.dashLen=void 0):e.dashLen||"string"!=typeof e.dashLens||(e.dashLen=e.dashLens,e.dashLens=void 0),"string"==typeof e.dashLen&&(e.dashLens=e.dashLen.split(",")),e.dashLens&&e.dashLens.length>0){1===e.dashLens.length&&e.dashLens.push(e.dashLens[0]);for(var p=0;p<e.dashLens.length;p++)e.dashLens[p]=this.unitConvert(e.dashLens[p]);e.dashLen=e.dashLens.join(","),delete e.dashLens}return e.orientation&&e.orientation>3&&(e.orientation=e.orientation/90),e},checkTextOptions:function(e){if(e.fontHeight=xe.unitConvert(e.fontHeight),e.charSpace=xe.unitConvert(e.charSpace),"number"==typeof e.lineSpace&&(e.lineSpace=xe.unitConvert(e.lineSpace)),e.leadingIndent||(e.leadingIndentChars?(e.leadingIndent=10*e.leadingIndentChars,delete e.leadingIndentChars):e.leadingIndentMM?(e.leadingIndentMM>=.01?e.leadingIndent=100*e.leadingIndentMM+1e3:e.leadingIndentMM<=-.01&&(e.leadingIndent=100*e.leadingIndentMM-1e3),delete e.leadingIndentMM):e.leadingIndentColon&&(e.leadingIndent=1e3,delete e.leadingIndentColon)),0===e.leadingIndent&&delete e.leadingIndent,Array.isArray(e.regionCorners)){for(var t=0;t<e.regionCorners.length;t++)e.regionCorners[t]=xe.unitConvert(e.regionCorners[t]);e.regionCorners=e.regionCorners.join(",")}if(!e.regionCorners){var n=[];if(e.regionLeftUpCorner&&(n[0]=e.regionLeftUpCorner,delete e.regionLeftUpCorner),e.regionRightUpCorner&&(n[1]=e.regionRightUpCorner,delete e.regionRightUpCorner),e.regionRightBottomCorner&&(n[2]=e.regionRightBottomCorner,delete e.regionRightBottomCorner),e.regionLeftBottomCorner&&(n[3]=e.regionLeftBottomCorner,delete e.regionLeftBottomCorner),n.length>0){var r=[];for(t=0;t<4;t++){var i=n[t];if("string"==typeof i&&(i=i.split(",")),r[t]="0,0",Array.isArray(i)){i.length>2&&(i=i.slice(0,2));for(var o=0;o<2;o++)i[o]=xe.unitConvert(i[o]||0);r[t]=i.join(",")}}e.regionCorners=r.join(",")}}if(e.regionLeftBorders){var a=e.regionLeftBorders;if("string"==typeof e.regionLeftBorders&&(a=e.regionLeftBorders.split(",")),Array.isArray(a)&&a.length>2){for(t=0;t<a.length;t++)a[t]=xe.unitConvert(a[t]);e.regionLeftBorders=a.join(",")}else delete e.regionLeftBorders}if(e.regionRightBorders)if("string"==typeof(a=e.regionRightBorders)&&(a=a.split(",")),Array.isArray(a)&&a.length>2){for(t=0;t<a.length;t++)a[t]=xe.unitConvert(a[t]);e.regionRightBorders=a.join(",")}else delete e.regionRightBorders;return void 0!==e.text&&null!==e.text||(Array.isArray(e.texts)?e.text=e.texts.join("\n"):void 0!==e.texts&&null!==e.texts&&(e.text=e.texts)),e},getAgent:function(){return navigator.userAgent.toLowerCase()||""},isWin32:function(){var e=this.getAgent();return e.indexOf("win32")||e.indexOf("wow32")},isWin64:function(){var e=this.getAgent();return e.indexOf("win64")||e.indexOf("wow64")},isWindows:function(){var e=this.getAgent();return e.indexOf("win")>=0||e.indexOf("wow")>=0},isMac:function(){return/macintosh|mac os x/i.test(this.getAgent())},formatDate:function(e,t){var n,r=e||"HH:mm:ss.SSS",i={"y+":(t=t||new Date).getFullYear(),"M+":t.getMonth()+1,"d+":t.getDate(),"h+":t.getHours(),"H+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),"S+":t.getMilliseconds()};for(var o in i)if(n=new RegExp("(".concat(o,")")).exec(r)){var a="".concat(i[o]),s="00".concat(a),u=n[1].length>s.length?0:s.length-n[1].length;r=r.replace(n[1],1===n[1].length?a:s.substring(u))}return r},arrayBufferToDataUrl:function(e){return btoa(new Uint8Array(e).reduce((function(e,t){return e+String.fromCharCode(t)}),""))},downloadDtpweb:function(e){var t=document.createElement("a");return t.href=e,t.click(),!0},parseXmlDocument:function(e){try{return e?(new DOMParser).parseFromString(e,"text/xml"):void 0}catch(e){console.warn("xml parse error:"),console.warn(e)}},getElementsByTagName:function(e,t,n){if(!e||!t||e.childElementCount<=0)return[];if(n){for(var r=[],i=0;i<e.childElementCount;i++){var o=e.children[i];o.tagName.toLowerCase()===t.toLocaleLowerCase()&&r.push(o)}return r}return e.getElementsByTagName(t)},getElementByTagName:function(e,t,n){return this.getElementsByTagName(e,t,n)[0]},getElementValue:function(e){try{return e.childNodes[0].nodeValue||""}catch(e){return""}},getElementValueByTagName:function(e,t){if(!t)return"";for(var n=t.split(";"),r=0;r<n.length;r++){var i=n[r];if(i){var o=this.getElementsByTagName(e,i);return o.length>0?this.getElementValue(o[0]):""}}},parseWdfxString:function(e){var t=this.parseXmlDocument(e),n=t?t.getElementsByTagName("LPAPI"):void 0;return n&&n.length>0?n[0]:void 0}},Se=function(){function e(){}return e.parseEmbeddedImg=function(e){if(!e)return e;var t="*****",n=e.indexOf(t);if(n<0)return e;var r=e.substring(0,n).trim();return e=e.substring(n+5),"data:image/".concat(r,";base64,").concat(e)},e.parseBaseElement=function(e,t){var n=t||{},r=xe.getElementValueByTagName(e,"x"),i=xe.getElementValueByTagName(e,"y"),o=xe.getElementValueByTagName(e,"width"),a=xe.getElementValueByTagName(e,"height"),s=xe.getElementValueByTagName(e,"orientation;direction");return xe.isNumberString(r)&&(n.x=Number(r)),xe.isNumberString(i)&&(n.y=Number(i)),xe.isNumberString(o)&&(n.width=Number(o)),xe.isNumberString(a)&&(n.height=Number(a)),n.orientation=xe.getNumber(s),n},e.parseBorderElement=function(e,t){var n=this.parseBaseElement(e,t),r=xe.getElementValueByTagName(e,"filled"),i=xe.getElementValueByTagName(e,"lineWidth");return xe.isBooleanString(r)&&(n.fill=xe.getBoolean(r)),n.fill||(n.lineWidth=xe.getNumber(i,.5)),n},e.parseContentElement=function(e,t){var n=this.parseBaseElement(e,t),r=xe.getElementValueByTagName(e,"content"),i=xe.getElementValueByTagName(e,"contentType"),o=xe.getElementValueByTagName(e,"verAlignment"),a=xe.getElementValueByTagName(e,"horAlignment"),s=xe.getElementValueByTagName(e,"dataColumnName;dataName");return 2===xe.getNumber(i)?n.text=s?"[".concat(s,"]"):r||n.text||"":r&&(n.text=r),n.horizontalAlignment=xe.getNumber(a),n.verticalAlignment=xe.getNumber(o),n},e.parseFontTextElement=function(e,t){var n=this.parseContentElement(e,t),r=xe.getElementValueByTagName(e,"fontName"),i=xe.getElementValueByTagName(e,"fontHeight"),o=xe.getElementValueByTagName(e,"fontStyle");return r&&(n.fontName=r),xe.isNumberString(i)&&(n.fontHeight=Number(i)),xe.isNumberString(o)&&(n.fontStyle=Number(o)),n},e.parseTextElement=function(e,t){var n=this.parseFontTextElement(e),r=xe.getElementValueByTagName(e,"charSpace"),i=xe.getElementValueByTagName(e,"lineSpace"),o=xe.getElementValueByTagName(e,"autoReturn"),a={type:"text",text:"",autoReturn:xe.getNumber(o),lineSpace:i,charSpace:xe.getNumber(r)};return t.push(Object.assign(a,n)),a},e.parseDateTimeElement=function(e,t){var n=this.parseTextElement(e,t),r=xe.getElementValueByTagName(e,"dateFormat"),i=xe.getElementValueByTagName(e,"dateOffset;dateDiff"),o=xe.getElementValueByTagName(e,"timeFormat"),a=xe.getElementValueByTagName(e,"hourOffset;hourDiff"),s=xe.getElementValueByTagName(e,"minuteOffset;minuteDiff"),u=xe.getElementValueByTagName(e,"secondOffset;secondDiff"),l=xe.getNumber(i),c=xe.getNumber(a),h=xe.getNumber(s),g=xe.getNumber(u),p=new Date;if(l>0||c>0||h>0||g>0){var d=p.getTime();l>0&&(d+=864e5*l),c>0&&(d+=36e5*c),h>0&&(d+=6e4*h),g>0&&(d+=1e3*g),p.setTime(d)}return n.text=r&&o?xe.formatDate("".concat(r," ").concat(o)):r||o?xe.formatDate(r||o,p):xe.formatDate("yyyy年MM月dd日"),!0},e.parseArchTextElement=function(e,t){return!1},e.parse1DBarcodeElement=function(e,t){var n=this.parseFontTextElement(e),r=xe.getElementValueByTagName(e,"type;barcodeType"),i=xe.getElementValueByTagName(e,"textAlignment"),o=xe.getElementValueByTagName(e,"flags;barcodeFlags"),a=xe.getElementValueByTagName(e,"horAlignment"),u=xe.getNumber(r);void 0===n.text&&(u===s.LPA_1DBT_EAN13?n.text="690123456789":u===s.LPA_1DBT_EAN8?n.text="6901234":u===s.LPA_1DBT_UPC_A?n.text="69012345678":u===s.LPA_1DBT_UPC_E?n.text="0123456":u===s.LPA_1DBT_ISBN?n.text="978012345678":n.text="12345678");var l=xe.getNumber(o,2),c={type:"barcode",barcodeType:u>=20&&u<=30?u:s.LPA_1DBT_AUTO,textAlignment:xe.getNumber(i),textHeight:0===l?0:n.fontHeight,barcodeFlags:1===l?2:2===l?1:l};return t.push(Object.assign(c,n,{horizontalAlignment:xe.getNumber(a,1)})),!0},e.parse2DBarcodeElement=function(e,t){var n=this.parseContentElement(e,{text:"http://detonger.com/wdbq"}),r=xe.getElementValueByTagName(e,"eccLevel"),i=xe.getElementValueByTagName(e,"type;barcodeType"),o=xe.getElementValueByTagName(e,"pdf417EccLevel"),a=xe.getElementValueByTagName(e,"pdf417Cols"),s=xe.getElementValueByTagName(e,"dmCodeShape"),u=xe.getNumber(i);if(1===u){var l={type:"pdf417",eccLevel:xe.getNumber(o),codeColumns:xe.getNumber(a)};t.push(Object.assign(l,n))}else if(2===u){l={type:"dataMatrix",symbolShape:xe.getNumber(s)};t.push(Object.assign(l,n))}else{l={type:"qrcode",eccLevel:xe.getNumber(r)};t.push(Object.assign(l,n))}return!0},e.parseImageElement=function(e,t){var n=this.parseContentElement(e),r=xe.getElementValueByTagName(e,"threshold"),i=this.parseEmbeddedImg(n.text||"");n.text="";var o={type:"image",imageFile:i,threshold:xe.getNumber(r,192)};return t.push(Object.assign(o,n)),!0},e.parseRectangleElement=function(e,t){var n=this.parseBorderElement(e);if(!n.width||!n.height)return!1;var r,i=xe.getElementValueByTagName(e,"type;rectangleType"),o=xe.getElementValueByTagName(e,"cornerWidth"),a=xe.getNumber(i);return 1===a?(xe.isNumberString(o)&&(n.cornerWidth=Number(o)),r={type:"roundRectangle"}):2===a?r={type:"ellipse"}:3===a?(n.width&&n.height&&n.width>n.height?(n.x=(n.x||0)+.5*(n.width-n.height),n.width=n.height):(n.y=(n.y||0)+.5*(n.height-n.width),n.height=n.width),r={type:"ellipse"}):r={type:"rectangle"},t.push(Object.assign(r,n)),!0},e.parseLineElement=function(e,t){var n=this.parseBaseElement(e),r=xe.getElementValueByTagName(e,"x1"),i=xe.getElementValueByTagName(e,"x2"),o=xe.getElementValueByTagName(e,"y1"),a=xe.getElementValueByTagName(e,"y2"),s=xe.getElementValueByTagName(e,"type;lineType"),u=xe.getElementValueByTagName(e,"dashGap"),l=n.x||0,c=n.y||0,h=n.width||0,g=n.height||0;(r||i)&&(o||a)&&(l=xe.getNumber(r),h=xe.getNumber(i)-l,c=xe.getNumber(o),g=xe.getNumber(a)-c);var p,d={lineWidth:Math.min(h,g)};if(h>g?(d.x1=l,d.x2=l+h,d.y1=d.y2=c+.5*g):(d.y1=c,d.y2=c+g,d.x1=d.x2=l+.5*h),1===xe.getNumber(s)){var f=xe.getNumber(u,1);d.dashLens=[f,f],p={type:"dashLine"}}else p={type:"line"};return t.push(Object.assign(p,d)),!0},e.isInnerRect=function(e,t){return e.x>=t.x&&e.x+e.width<=t.x+t.width&&e.y>=t.y&&e.y+e.height<=t.y+t.height},e.parseTableElement=function(e,t){var n=this,r=this.parseBorderElement(e),i=r.x||0,o=r.y||0,a=r.lineWidth||.5,s=xe.getElementValueByTagName(e,"rows;row;rowCount"),u=xe.getElementValueByTagName(e,"cols;col;colCount"),l=xe.getElementValueByTagName(e,"rowHeight")||"",c=xe.getElementValueByTagName(e,"colWidth")||"",h=xe.getElementValueByTagName(e,"group")||"",g=xe.getNumber(s),p=xe.getNumber(u),d=l.split(",").map((function(e){return xe.getNumber(e)})),f=c.split(",").map((function(e){return xe.getNumber(e)})),m=h.split(";").map((function(e){var t=e.split(",").map((function(e){return xe.getNumber(e)}));return{x:t[1],y:t[0],width:t[3]-t[1],height:t[2]-t[0]}}));this.parseRectangleElement(e,t);var y=xe.getElementByTagName(e,"Cells");if(y&&y.children.length>0)for(var v=0;v<g;v++)for(var _=function(e){var s=y.children[v*p+e],u={x:e+1,y:v+1,width:0,height:0},l=m.filter((function(e){return n.isInnerRect(u,e)}));l.length>0&&(u.x===l[0].x&&u.y===l[0].y?(u.width=l[0].width,u.height=l[0].height):u.x=u.y=0);var c=function(e,t){return(e||0)+t};if(u.x>0&&u.y>0){var h={x:i+(u.x>1?f.slice(0,u.x-1).reduce(c,0)+a*e:0),y:o+(u.y>1?d.slice(0,u.y-1).reduce(c,0)+a*v:0),width:u.width>0?f.slice(u.x-1,u.x+u.width).reduce(c,0)+(u.width+1)*a:f[u.x-1],height:u.height>0?d.slice(u.y-1,u.y+u.height).reduce(c,0)+(u.height+1)*a:d[u.y-1],lineWidth:r.lineWidth};if(u.x>1){var g={type:"line",x1:h.x,y1:h.y,x2:h.x,y2:(h.y||0)+(h.height||0),lineWidth:r.lineWidth};t.push(g)}if(u.y>1){var _={type:"line",x1:h.x,y1:h.y,x2:(h.x||0)+(h.width||0),y2:h.y,lineWidth:r.lineWidth};t.push(_)}if("Text"===s.tagName){var N=b.parseTextElement(s,t);Object.assign(N,h)}}},b=this,N=0;N<p;N++)_(N)},e.parseLPAPIElement=function(e,t){var n=xe.getElementValueByTagName(e,"labelWidth;width"),r=xe.getElementValueByTagName(e,"labelHeight;height"),i=xe.getElementValueByTagName(e,"printOrientation;orientation;direction"),o=xe.getElementValueByTagName(e,"printHorOffset;horizontalOffset"),a=xe.getElementValueByTagName(e,"printVerOffset;verticalOffset"),s=xe.getElementValueByTagName(e,"gapType"),u=xe.getElementValueByTagName(e,"gapLength"),l=xe.getElementValueByTagName(e,"printDarkness;printStrength"),c=xe.getElementValueByTagName(e,"printSpeed"),h=xe.getElementValueByTagName(e,"background"),g=xe.getElementValueByTagName(e,"horFlip"),p={jobWidth:xe.getNumber(n),jobHeight:xe.getNumber(r),orientation:xe.getNumber(i),horizontalOffset:xe.getNumber(o),verticalOffset:xe.getNumber(a),horizontalFlip:xe.getNumber(g),printDarkness:xe.getNumber(l,255),printSpeed:xe.getNumber(c,255),gapType:xe.getNumber(s,255),gapLength:xe.getNumber(u,0)},d=[];if(!(p.jobWidth<=0||p.jobHeight<=0)){if(h){var f={type:"image",imageFile:this.parseEmbeddedImg(h),x:0,y:0,width:p.jobWidth,height:p.jobHeight};d.push(f)}var m=xe.getElementByTagName(e,"Page");if(m&&!(m.childElementCount<=0)){for(var y=0;y<m.children.length;y++){var v=m.children[y];"Text"===v.tagName||"String"===v.tagName?this.parseTextElement(v,d):"Barcode"===v.tagName?this.parse1DBarcodeElement(v,d):"Qrcode"===v.tagName?this.parse2DBarcodeElement(v,d):"Time"===v.tagName||"Date"===v.tagName?this.parseDateTimeElement(v,d):"Image"===v.tagName||"Photo"===v.tagName||"Logo"===v.tagName?this.parseImageElement(v,d):"Rectangle"===v.tagName||"Rect"===v.tagName||"Circle"===v.tagName||"Ellipse"===v.tagName?this.parseRectangleElement(v,d):"Line"===v.tagName?this.parseLineElement(v,d):"Table"===v.tagName?this.parseTableElement(v,d):"ArcText"===v.tagName?this.parseArchTextElement(v,d):console.warn("----不支持的绘制内容：".concat(v.tagName))}return{jobInfo:p,jobPages:[d]}}}},e}(),We=void 0,Me=function(){function t(){this._labelWidth=0,this._labelHeight=0,this._margins=[],this._localIPs=new Set,this._version=""}return t.checkServer=function(e){var t,n="function"==typeof e?{callback:e}:e||{},r=this.getInstance(n);return r.checkPlugin({clientType:n.clientType,callback:function(e){t=e.statusCode===h.OK?r:void 0,n.callback&&n.callback(t,e)}}),t},t.getInstance=function(e){var n=We||(We=new t);return n.init(e),n},t.readAsDataURL=function(e,t){try{if(e instanceof Blob){var n=new FileReader;return n.onload=function(){t&&t(n.result)},n.onerror=function(e){console.warn(e),t&&t("")},n.readAsDataURL(e),!0}if(e instanceof ArrayBuffer){var r=xe.arrayBufferToDataUrl(e);return t(r)}return t(r="string"==typeof e?e:"")}catch(e){return console.warn(e),t("")}},t.isTransPrevJob=function(e){return!!e&&e.toUpperCase().startsWith("#!#trans")},t.isWhitePrevJob=function(e){return!!e&&e.toLowerCase().startsWith("#!#prev")},t.isPreviewJob=function(e){return!!e&&((e=e.toLowerCase()).startsWith("#!#trans")||e.startsWith("#!#prev"))},Object.defineProperty(t.prototype,"LastResponse",{get:function(){return this._Response},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"IsJsonMode",{get:function(){return this._jsonMode||!1},enumerable:!1,configurable:!0}),t.prototype.getIpAddress=function(e){return e||this._ip||this._initIp},t.prototype.getPort=function(e){return e||this._port||this._initPort},t.prototype.getTimeout=function(e,t){return e&&e>0?e:this._timeout&&this._timeout>0?this._timeout:this.isLocalPrinter(t)?A:O},t.prototype.getDeviceType=function(e){return e||this._deviceType},t.prototype.getFontName=function(e){return e||this._fontName||D},t.prototype.getFontHeight=function(e){return e||this._fontHeight||L},t.prototype.getLineWidth=function(e){return e||this._lineWidth||C},t.prototype.getRadius=function(e){return e||this._radius||S},t.prototype.getCornerWidth=function(e){return e||this._cornerWidth||x},t.prototype.parseMargin=function(e){this._margins.splice(0);for(var t=xe.parseMargin(e),n=0;n<4;n++)this._margins[n]=1*(t[n]||0);return this._margins},t.prototype.setFontName=function(e){this._fontName=e},t.prototype.setOffsetX=function(e){this._margins[4]=e},t.prototype.setOffsetY=function(e){this._margins[5]=e},t.prototype.init=function(e){var t=e||{};t.ip&&(this._initIp=t.ip),t.port&&(this._initPort=t.port),t.timeout&&(this._timeout=t.timeout),this._downloadUrl=t.downloadUrl,t.fontName&&(this._fontName=t.fontName),t.fontHeight&&(this._fontHeight=t.fontHeight),t.lineWidth&&(this._lineWidth=t.lineWidth),t.radius&&(this._radius=t.radius),this._showAlert="boolean"!=typeof t.showAlert||t.showAlert,this._jsonMode="boolean"!=typeof t.jsonMode||t.jsonMode,this._showLog="boolean"!=typeof t.showLog||t.showLog},t.prototype.logMsg=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(this._showLog){var r=xe.formatDate();console.log("[".concat(r,"]: ").concat(e)),console.log.apply(console,t)}},t.prototype.logObj=function(e){this._showLog&&console.log(e)},t.prototype.setServerInfo=function(e){var t;if(e){if((null===(t=e.selfIps)||void 0===t?void 0:t.length)>0)for(var n=0,r=e.selfIps;n<r.length;n++){var i=r[n];this._localIPs.add(i)}var o=(e.version||"").split("/");o.length>1&&(this._version=o[1])}},t.prototype.isLocalPrinter=function(e){var t="number"==typeof e?e:(null==e?void 0:e.type)||0;return this._version&&this._version>="2.3.2023.621"?t<10:t<=1},t.prototype.checkPlugin=function(e){var n=this,r="function"==typeof e?{callback:e}:e||{},i=function(e){if(e.statusCode===h.OK)console.log("★★★ 打印助手运行正常 ★★★");else if((null==e?void 0:e.statusCode)===h.NETWORK_ERROR&&"http:"===window.location.protocol)console.log("★★★ 不安全网络[http]环境下需要禁用对本地服务的拦截操作 ★★★"),n._showAlert&&window.prompt("检测到不安全的网络环境，如果需要在 http 环境下继续使用打印助手，请打开浏览器，然后在浏览器的地址栏输入下列链接，然后将浏览器的 [Block insecure private network requests] 标志切换到【disable】:",t.URL_BLOCK_PRIVATE_NETWORK);else{console.log("★★★ 未检测到打印助手 ★★★");var i=n._downloadUrl||t.URL_DTPWEB_DOWNLOAD;n._showAlert&&window.confirm("未检测到打印助手，是否要下载最新版本的打印助手？")&&window.open("".concat(i,"?protocol=").concat(window.location.protocol),"")}r.callback&&r.callback(e)},o={clientType:r.clientType};this.checkPort({port:P,params:o,callback:function(e){e.statusCode!==h.OK?e.statusCode===h.NETWORK_ERROR&&"http:"===window.location.protocol?i(e):n.checkPort({port:I,params:o,callback:i}):i(e)}})},t.prototype.checkPort=function(e){var t=this;this.logMsg("$$$$ DTPWEB request: checkPort(".concat(e.port,") $$$$"));var n=this._initIp||E,r=xe.getParamString(e.params||{}),i=r?"?".concat(r):"";We||(We=this),xe.request({host:n,port:e.port||this._port,url:"".concat(k,"/").concat(we).concat(i),sync:!1,timeout:this.getTimeout(0)},(function(r){if(t.logMsg("#### onResponse: checkPort(".concat(e.port,") ####"),r),r.statusCode<h.NETWORK_FAILED){var i=r.resultInfo;t._initIp||(t._initIp=n),e.port&&(t._initPort=e.port),t.setServerInfo(i)}e.callback&&e.callback(r)}))},t.prototype.requestApi=function(e,t){var n=this,r=xe.getRequestData(["action"],[e]);this.logMsg("$$$$ DTPWEB request: ".concat(r.action," $$$$"),r),t&&this.logObj(t),t=t||{};var i=r.data||t.data;t.data&&(t.data=void 0);var o=xe.getParamString(r.params||t),a=o?"?".concat(o):"",s=r.control||q,u=this.getDeviceType(r.deviceType);this._Response=void 0,r.contentType===b.Json?i=JSON.stringify(i||t):r.contentType||(i=o);var l=De;r.contentType===b.Json?l=Ce:r.contentType===b.Base64?l=Le:r.contentType===b.Blob&&(l=Be);var c=this.isLocalPrinter(u)?void 0:r.ip,g={statusCode:h.WAIT_FOR_ASYNC,resultInfo:void 0};return xe.request({method:"POST",host:this.getIpAddress(c),port:this.getPort(r.port),url:"".concat(s,"/").concat(r.action).concat(a),params:t,headers:{"Content-type":l},data:i,sync:!r.async,timeout:this.getTimeout(r.timeout,u)},(function(e){n.logMsg("#### onResponse: ".concat(r.action," ####"),e),n._Response=e,r.callback&&r.callback(e),g=e})),g},t.prototype.getVersion=function(e){var t="number"==typeof e?{clientType:e}:{},n=this.requestApi(F,t);return n.statusCode===h.OK?n.resultInfo:void 0},t.prototype.getServerInfo=function(e){var t="number"==typeof e?{clientType:e}:{},n=this.requestApi(we,t);return n.statusCode===h.OK?n.resultInfo:void 0},t.prototype.setSupportedPrinters=function(e){if(xe.isWindows())return this.requestApi(U,{supportedPrinters:e}).statusCode===h.OK},t.prototype.getDefaultPrinter=function(){if(xe.isWindows()){var e=this.requestApi(K);return e.statusCode===h.OK?e.resultInfo:void 0}},t.prototype.setDefaultPrinter=function(e){xe.isWindows()&&this.requestApi(V,{printerName:e})},t.prototype.discoveryPrinters=function(e){return this.requestApi(H,{mode:null!=e?e:1}).statusCode===h.OK},t.prototype.getPrinters=function(e,t){var n;(e=xe.getRequestData(["onlyOnline"],[e])).onlyOnline="boolean"!=typeof e.onlyOnline||e.onlyOnline,e.onlySupported=!0;var r=this.requestApi({action:J,timeout:t||5e3},e);return this._deviceList=null===(n=r.resultInfo)||void 0===n?void 0:n.printers,this._deviceList||[]},t.prototype.getDeviceInfo=function(e){var t=this.requestApi("GetDeviceInfo",{printerName:e});return t.statusCode===h.OK?t.resultInfo:{}},t.prototype.openPrinter=function(e,t){var n,r=this;"function"==typeof(n="string"==typeof e?/^\s*([A-Z]+[0-9]+)-([A-Z]?[0-9]{8,})\s*/.test(e)?{deviceName:e}:{name:e}:"function"==typeof e?{callback:e}:e||{}).callback&&(t=n.callback);var i=this.requestApi({action:G,ip:n.ip||this._initIp,port:n.port||this._initPort,deviceType:n.type,timeout:n.timeout||8e3,async:"boolean"!=typeof n.async||n.async,callback:function(e){if(e.statusCode===h.OK){r.isLocalPrinter(n.type)?(r._ip=void 0,r._port=void 0):(r._ip=n.ip,r._port=n.port);var i=n.name||n.deviceName||n.printerName;n.type&&(r._deviceType=n.type),i&&(r._deviceName=i)}t&&t(e.statusCode===h.OK)}},n);return i.statusCode===h.OK||i.statusCode===h.WAIT_FOR_ASYNC},t.prototype.getPrinterName=function(){return this.requestApi(z).resultInfo},t.prototype.isPrinterOpened=function(){return this.requestApi(X).statusCode===h.OK},t.prototype.isPrinterOnline=function(){var e;return!!xe.isWindows()&&(null===(e=this.requestApi(Y))||void 0===e?void 0:e.statusCode)===h.OK},t.prototype.closePrinter=function(){return this.requestApi($).statusCode===h.OK},t.prototype.showProperty=function(e){return!!xe.isWindows()&&(e.showDocument="boolean"!=typeof e.showDocument||e.showDocument,this.requestApi(Q,e).statusCode===h.OK)},t.prototype.getParam=function(e){var t=xe.getRequestData(["id"],[e]),n=this.requestApi(te,t);return n.statusCode===h.OK?n.resultInfo:-1},t.prototype.setParam=function(e){return e=xe.getRequestData(["id","value"],arguments),this.requestApi(ne,e).statusCode===h.OK},t.prototype.getGapType=function(){return this.getParam(e.GapType)},t.prototype.setGapType=function(t){return this.setParam({id:e.GapType,value:t})},t.prototype.getPrintDarkness=function(){return this.getParam(e.PrintDarkness)},t.prototype.setPrintDarkness=function(t){return this.setParam({id:e.PrintDarkness,value:t})},t.prototype.getPrintSpeed=function(){return this.getParam(e.PrintSpeed)},t.prototype.setPrintSpeed=function(t){return this.setParam({id:e.PrintSpeed,value:t})},t.prototype.getPrinterDPI=function(){var e=this.requestApi(re);return e.statusCode===h.OK?e.resultInfo:void 0},t.prototype.startJob=function(e){var t=this;e=xe.getRequestData(["width","height","orientation","jobName"],arguments);var n=this.parseMargin(e);this._labelWidth=e.width||R,this._labelHeight=e.height||w,this._pageStartedFunc=e.pageStarted,this._pageEndedFunc=e.pageEnded,xe.scaleUnit=this.IsJsonMode?0:1,e.scaleUnit=1,e.width=xe.unitConvert(e.width+n[1]+n[3]),e.height=xe.unitConvert(e.height+n[0]+n[2]),e.jobName=e.jobName||u.Print;var r=e.printerName||this._deviceName;if(!r&&this._deviceList&&this._deviceList.length>0)for(var i=0,o=this._deviceList;i<o.length;i++){var a=o[i];if(this.isLocalPrinter(a)){r=a.name;break}}if(this.jobPrintResult=void 0,this.jobStartInfo={action:xe.getJobAction(e.jobName),jobPages:[],jobInfo:{jobWidth:e.width,jobHeight:e.height,orientation:e.orientation,jobName:e.jobName},printerInfo:{printerName:r}},this.IsJsonMode)return this.startPage();var s=this.requestApi({action:se,callback:function(e){e.statusCode===h.OK&&(t.pageInfo=[],t._pageStartedFunc&&t._pageStartedFunc(t))}},e);return s.statusCode===h.OK||s.statusCode===h.WAIT_FOR_ASYNC},t.prototype.startPrintJob=function(e,n){var r=this,i=e.jobName;if("function"==typeof e.callback&&(n=e.callback),t.isPreviewJob(i)){var o=this.startJob(e);return n&&n(o),o}var a="string"==typeof e.printer?{name:e.printer}:e.printer,s=this.openPrinter(a,(function(t){t&&r.startJob(e)?n&&n(!0):n&&n(!1)}));return!!s||(n&&n(s),!1)},t.prototype.abortJob=function(){this.IsJsonMode||this.requestApi(ue)},t.prototype.commitJob=function(e){var n=this,r="function"==typeof e?{callback:e}:e||{};if(!this.jobStartInfo)return console.warn("===== 调用错误，未创建打印任务！====="),void(r.callback&&r.callback(void 0));Object.assign(this.jobStartInfo.jobInfo,xe.filterRecord(r,(function(e,t){return"function"!=typeof t})));var i=this.jobStartInfo,o=i.jobInfo,a=t.isPreviewJob(o.jobName);if("number"==typeof r.darkness&&(o.printDarkness=r.darkness),"number"==typeof r.speed&&(o.printSpeed=r.speed),a||("number"==typeof o.gapType&&this.setGapType(o.gapType),"number"==typeof o.printDarkness&&this.setPrintDarkness(o.printDarkness),"number"==typeof o.printSpeed&&this.setPrintSpeed(o.printSpeed)),this.IsJsonMode)return this.endPage(),this.print(Object.assign(i,{async:r.async,callback:function(e){n.jobPrintResult=e,r.callback&&r.callback(e)}}));var s={},u=this.requestApi({action:le,timeout:6e4,async:r.async,callback:function(e){if(n.pageInfo&&(n.pageInfo=void 0,n._pageEndedFunc&&n._pageEndedFunc(n)),e.statusCode!==h.OK)r.callback&&r.callback(void 0);else{if(a){var t=n.getPageInfo();if(t){s.width=t.width,s.height=t.height,s.previewData=[];for(var i=0;i<t.pages;i++){var o=n.getPageImage({page:i});s.previewData.push(o.data)}}}n.jobPrintResult=s,r.callback&&r.callback(s)}}},r);return u.statusCode===h.OK||u.statusCode===h.WAIT_FOR_ASYNC?s:void 0},t.prototype.setItemHorizontalAlignment=function(e){return this.requestApi(oe,{alignment:e})},t.prototype.setItemVerticalAlignment=function(e){return this.requestApi(ae,{alignment:e})},t.prototype.setItemOrientation=function(e){return this.requestApi(ie,{orientation:e})},t.prototype.getJobID=function(){return xe.isWindows()?this.requestApi(ce).resultInfo:0},t.prototype.getJobInfo=function(e){if(xe.isWindows()){var t=this.requestApi(he,e);return t.statusCode===h.OK?t.resultInfo:void 0}},t.prototype.getPageInfo=function(){return this.jobPrintResult&&this.jobPrintResult.previewData?{width:this.jobPrintResult.width||0,height:this.jobPrintResult.height||0,pages:this.jobPrintResult.previewData.length||0}:this.IsJsonMode?{width:0,height:0,pages:0}:this.requestApi(ge).resultInfo},t.prototype.getPageImage=function(e){var t=(e=xe.getRequestData(["page","format"],arguments)).page||0,n=this.jobPrintResult||{};return n.previewData&&n.previewData[t]?{page:t,data:n.previewData[t]}:this.IsJsonMode?{page:t,data:""}:this.requestApi(pe,e).resultInfo},t.prototype.startPage=function(){if(!this.jobStartInfo)return!1;if(this.pageInfo&&this.pageInfo.length<=0)return!0;if(this.pageInfo&&this.pageInfo.length>0&&this.endPage(),this.pageInfo=[],this.IsJsonMode)return this._pageStartedFunc&&this._pageStartedFunc(this),!0;var e=this.requestApi(de);return this._pageStartedFunc&&this._pageStartedFunc(this),e.statusCode===h.OK},t.prototype.endPage=function(){if(!this.jobStartInfo||!this.pageInfo)return!1;if(this.pageInfo.length>0&&this.jobStartInfo.jobPages.push(this.pageInfo),this.pageInfo=void 0,this.IsJsonMode)return this._pageEndedFunc&&this._pageEndedFunc(this),!0;var e=this.requestApi(fe);return this._pageEndedFunc&&this._pageEndedFunc(this),e.statusCode===h.OK},t.prototype.returnDrawResult=function(e){var t,n=xe.getRequestData(["returnDrawResult"],[e]);return n.returnDrawResult=null===(t=n.returnDrawResult)||void 0===t||t,this.requestApi(me,n).statusCode===h.OK},t.prototype.mm2Pound=function(e){return xe.mmToPound(e)},t.prototype.pound2Mm=function(e){return xe.poundToMm(e)},t.prototype.drawText=function(e){return e=xe.getRequestData(["text","x","y","width","height","fontHeight","fontStyle"],arguments),!(!this.pageInfo||!e.text)&&(e.fontHeight=this.getFontHeight(e.fontHeight||e.height),e.fontName=this.getFontName(e.fontName),e=xe.unitConvertOfDrawBase(e,this._margins),xe.checkTextOptions(e),this.pageInfo.push(Object.assign(e,{type:N.Text})),!!this.IsJsonMode||this.requestApi(ye,e).statusCode===h.OK)},t.prototype.draw1DBarcode=function(e){return e=xe.getRequestData(["text","x","y","width","height","textHeight"],arguments),!(!this.pageInfo||!e.text)&&((e=xe.unitConvertOfDrawBase(e,this._margins)).textHeight=xe.unitConvert(e.textHeight),e.textBarSpace=xe.unitConvert(e.textBarSpace),e.fontName=this.getFontName(e.fontName),this.pageInfo.push(Object.assign(e,{type:N.Barcode})),!!this.IsJsonMode||this.requestApi(ve,e).statusCode===h.OK)},t.prototype.draw2DQRCode=function(e){return e=xe.getRequestData(["text","x","y","width","height","eccLevel"],arguments),!(!this.pageInfo||!e.text)&&((e=xe.unitConvertOfDrawBase(e,this._margins)).height||(e.height=e.width),this.pageInfo.push(Object.assign(e,{type:N.QRCode})),!!this.IsJsonMode||this.requestApi(_e,e).statusCode===h.OK)},t.prototype.draw2DPdf417=function(e){return e=xe.getRequestData(["text","x","y","width","height"],arguments),!(!this.pageInfo||!e.text)&&(e=xe.unitConvertOfDrawBase(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.Pdf417})),!!this.IsJsonMode||this.requestApi(be,e).statusCode===h.OK)},t.prototype.draw2DDataMatrix=function(e){return e=xe.getRequestData(["text","x","y","width","height"],arguments),!(!this.pageInfo||!e.text)&&(e=xe.unitConvertOfDrawBase(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.DataMatrix})),!!this.IsJsonMode||this.requestApi(Ne,e).statusCode===h.OK)},t.prototype.drawRectangle=function(e){return!!this.pageInfo&&((e=xe.getRequestData(["x","y","width","height","lineWidth"],arguments)).cornerWidth||e.cornerHeight?this.drawRoundRectangle(e):(e.lineWidth=this.getLineWidth(e.lineWidth),e=xe.unitConvertOfDrawRect(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.Rect})),!!this.IsJsonMode||this.requestApi(Te,e).statusCode===h.OK))},t.prototype.drawRoundRectangle=function(e){return!!this.pageInfo&&((e=xe.getRequestData(["x","y","width","height","cornerWidth","lineWidth"],arguments)).cornerWidth=this.getCornerWidth(e.cornerWidth||e.cornerHeight),e.lineWidth=this.getLineWidth(e.lineWidth),e=xe.unitConvertOfDrawRect(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.RoundRect})),!!this.IsJsonMode||this.requestApi(Ee,e).statusCode===h.OK)},t.prototype.drawEllipse=function(e){return!!this.pageInfo&&((e=xe.getRequestData(["x","y","width","height","lineWidth"],arguments)).lineWidth=this.getLineWidth(e.lineWidth),e=xe.unitConvertOfDrawRect(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.Ellipse})),!!this.IsJsonMode||this.requestApi(Pe,e).statusCode===h.OK)},t.prototype.drawCircle=function(e){e=xe.getRequestData(["x","y","radius","lineWidth"],arguments);var t=this.getRadius(e.radius),n=2*t;delete e.radius;var r=e;return r.x=(e.x||0)-t,r.y=(e.y||0)-t,r.width=r.height=n,this.drawEllipse(r)},t.prototype.drawLine=function(e){return!!this.pageInfo&&(((e=xe.getRequestData(["x1","y1","x2","y2","lineWidth"],arguments)).dashLens||e.dashLen||[]).length>0?this.drawDashLine(e):(e.lineWidth=this.getLineWidth(e.lineWidth),e=xe.unitConvertOfLine(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.Line})),!!this.IsJsonMode||this.requestApi(Ie,e).statusCode===h.OK))},t.prototype.drawDashLine=function(e){return!!this.pageInfo&&(((e=xe.getRequestData(["x1","y1","x2","y2","dashLen","lineWidth"],arguments)).dashLen||e.dashLens||[]).length<1&&(e.dashLens=B),e.lineWidth=this.getLineWidth(e.lineWidth),e=xe.unitConvertOfLine(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.DashLine})),!!this.IsJsonMode||this.requestApi(Ae,e).statusCode===h.OK)},t.prototype.drawImage=function(e){return!!this.pageInfo&&(e=xe.getRequestData(["imageFile","x","y","width","height"],arguments),e=xe.unitConvertOfDrawBase(e,this._margins),this.pageInfo.push(Object.assign(e,{type:N.Image})),!!this.IsJsonMode||this.requestApi(Oe,e).statusCode===h.OK)},t.prototype.drawImageD=function(e){var n,r=this;return!!this.pageInfo&&((e=xe.getRequestData(["data","x","y","drawWidth","drawWidth"],arguments)).threshold=null!==(n=e.threshold)&&void 0!==n?n:M,e.width||(e.width=e.drawWidth),e.height||(e.height=e.drawHeight),e.drawWidth||(e.drawWidth=e.width),e.drawHeight||(e.drawHeight=e.height),(e=xe.unitConvertOfDrawBase(e,this._margins)).drawWidth=xe.unitConvert(e.drawWidth||this._labelWidth),e.drawHeight=xe.unitConvert(e.drawHeight||this._labelHeight),t.readAsDataURL(e.data,(function(t){return e.data=t,!(!t||!r.pageInfo)&&(e.imageFile=t,delete e.data,r.pageInfo.push(Object.assign(e,{type:N.Image})),r.IsJsonMode?!!r.pageInfo:r.requestApi({action:Re,contentType:b.Base64,data:t},e).statusCode===h.OK)})))},t.prototype.printImage=function(e){var n=this;return(e=xe.getRequestData(["data","printerName"],arguments)).data?t.readAsDataURL(e.data,(function(t){var r;if(t){e.data=t,e.scaleUnit=1,e.printWidth=xe.unitConvert(e.printWidth),e.printHeight=xe.unitConvert(e.printHeight),e.threshold=null!==(r=e.threshold)&&void 0!==r?r:M,e.jobName=e.jobName||u.Print;var i=n.requestApi({action:Z,contentType:b.Base64,data:t,timeout:18e4,callback:function(t){e.callback&&e.callback(t.statusCode===h.OK)}},e);return i.statusCode===h.OK||i.statusCode===h.WAIT_FOR_ASYNC}return e.callback&&e.callback(!1),!1})):(e.callback&&e.callback(!1),!1)},t.prototype.print=function(e){var t,n;(e=e||{}).content&&delete(e=Object.assign({},JSON.parse(e.content),e)).content;var r=e.action||j,i=e.jobInfo||{};if(e.action&&delete e.action,i.copies&&i.copies>1){var o=e.jobPages.slice(0);if(!i.autoPage&&o.length>1){e.jobPages.splice(0);for(var a=0,s=o;a<s.length;a++){var u=s[a];(t=e.jobPages).push.apply(t,Array(i.copies).fill(u))}}else for(var l=1;l<i.copies;l++)(n=e.jobPages).push.apply(n,o)}var c=this.requestApi({action:ee,timeout:6e4,contentType:b.Json,params:{action:r},data:e,async:e.async,callback:function(t){var n=(null==t?void 0:t.statusCode)===h.OK?t.resultInfo:void 0;e.callback&&e.callback(n)}});return c.statusCode===h.OK?c.resultInfo:void 0},t.prototype.printWdfx=function(e){var t=e||{},n=t.action||0,r=xe.parseWdfxString(e.content);if(!r)return console.warn("---- wdfx内容解析错误："),console.warn(e.content),void(e.callback&&e.callback(void 0));var i=Se.parseLPAPIElement(r,!!(2&n)),o=t.jobInfo||{};Object.keys(o).forEach((function(e){null!==o[e]&&void 0!==o[e]||delete o[e]})),i?this.print({action:t.action,printerInfo:t.printerInfo,jobInfo:Object.assign(i.jobInfo||{},o),jobPages:i.jobPages,callback:t.callback}):(console.log("---- 数据解析失败！"),t.callback&&t.callback(void 0))},t.URL_DTPWEB_DOWNLOAD="https://weida.dothantech.com/assets/dtpweb/index.html",t.URL_BLOCK_PRIVATE_NETWORK="chrome://flags/#block-insecure-private-network-requests",t}();function je(e){return Me.getInstance(e)}function qe(e){return Me.checkServer(e)}export{Me as DTPWeb,N as LPA_DrawType,o as LPA_FontStyle,t as LPA_GapType,i as LPA_ItemAlignment,u as LPA_JobNames,e as LPA_ParamID,l as LPA_PrintActions,r as LPA_PrintDarkness,n as LPA_PrintSpeed,h as LPA_Result,qe as checkServer,je as getInstance};
