ng-thermal-print
Version:
An angular module to add thermal printing capabilities.
16 lines (14 loc) • 25 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("rxjs")):"function"==typeof define&&define.amd?define("ng-thermal-print",["exports","@angular/core","rxjs"],e):e((t=t||self)["ng-thermal-print"]={},t.ng.core,t.rxjs)}(this,(function(t,e,r){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function i(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function s(t,e,r,n){return new(r||(r=Promise))((function(i,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}Object.create;Object.create;var u=function(){},a=function(){function t(t){void 0===t&&(t=1024),this.buffer=new Uint8Array(t),this.size=0}return t.prototype.clear=function(){this.size=0},t.prototype.flush=function(){var t=new Uint8Array(this.buffer.slice(0,this.size));return this.size=0,t},t.prototype.write=function(t){return this.resize(t.length),this.buffer.set(t,this.size),this.size+=t.length,this},t.prototype.writeUInt8=function(t){return this.resize(1),this.buffer[this.size++]=255&t,this},t.prototype.resize=function(t){var e=this.buffer.length-this.size;if(e<t){var r=this.buffer,n=Math.ceil((t-e)/r.length)+1;this.buffer=new Uint8Array(r.length*n),this.buffer.set(r,0)}},t}(),c=function(t){function e(){var e=t.call(this)||this;return e.encoder=new TextEncoder,e}return i(e,t),e.prototype.init=function(){return this.buffer=new a,this.write(27),this.write("@"),this},e.prototype.flush=function(){return this.buffer.flush()},e.prototype.feed=function(t){return void 0===t&&(t=1),this.write(27),this.write("a"),this.write(t),this},e.prototype.cut=function(t){return void 0===t&&(t="full"),this.write(27),this.write("d"),this.write("full"===t?2:3),this},e.prototype.writeLine=function(t){return this.write(t+"\n")},e.prototype.setInverse=function(t){return void 0===t&&(t=!0),this.write(27),t?this.write("4"):this.write("5"),this},e.prototype.setUnderline=function(t){return void 0===t&&(t=!0),this.write(27),this.write("-"),this.write(t?1:0),this},e.prototype.setJustification=function(t){var e;switch(t){case"center":e=1;break;case"right":e=2;break;default:e=0}return this.write(27),this.write(29),this.write("a"),this.write(e),this},e.prototype.setBold=function(t){return void 0===t&&(t=!0),this.write(27),t?this.write("E"):this.write("F"),this},e.prototype.setSize=function(t){return this.write(27),this.write("i"),this.write("normal"===t?0:1),this.write("normal"===t?0:1),this},e.prototype.write=function(t){return"number"==typeof t?this.buffer.writeUInt8(t):"string"==typeof t?this.buffer.write(this.encoder.encode(t)):this.buffer.write(t),this},e}(u),l=function(){};l.prototype.createAlignmentElement=function(t){var e="<alignment";return null!=t&&(e+=this._analysisEnumAttribute("position",t.position,/^(left|center|right)$/)),e+"/>"},l.prototype.createBarcodeElement=function(t){var e;if(null==t)throw Error("Argument is undefined.");if(e="<barcode"+this._analysisEnumAttribute("symbology",t.symbology,/^(UPCE|UPCA|JAN8|JAN13|Code39|ITF|Code128|Code93|NW7)$/),e+=this._analysisEnumAttribute("width",t.width,/^(width[2-4]|width_mode[1-9])$/),e+=this._analysisEnumAttribute("hri",t.hri,/^(false|true)$/),e+=this._analysisValueAttribute("height",t.height,1,255),null==t.data)throw Error('Argument "data" is undefined.');return(e=e+">"+this._encodeEscapeSequenceBinary(t.data))+"</barcode>"},l.prototype.createBitImageElement=function(t){var e="<bitimage";if(null==t)throw Error("Argument is undefined.");var r=0,n=0,i=0,s=0;if(null!=t.x&&(r=t.x),null!=t.y&&(n=t.y),null!=t.width&&(i=t.width),null!=t.height&&(s=t.height),this._analysisValueAttribute("x",r,0,65535),this._analysisValueAttribute("y",n,0,65535),e+=this._analysisValueAttribute("width",i,0,65535),e+=this._analysisValueAttribute("height",s,0,65535),null==t.context)throw Error('Argument "context" is undefined.');return(e=e+">"+this._encodeRasterImage(t.context.getImageData(r,n,i,s).data,i,s))+"</bitimage>"},l.prototype.createCutPaperElement=function(t){var e="<cutpaper";return null!=t&&(e+=this._analysisEnumAttribute("feed",t.feed,/^(false|true)$/),e+=this._analysisEnumAttribute("type",t.type,/^(full|partial)$/)),e+"/>"},l.prototype.createFeedElement=function(t){var e;if(null==t)throw Error("Argument is undefined.");if(null==t.line&&null==t.unit)throw Error('Argument "line / unit" is undefined.');return e="<feed"+this._analysisValueAttribute("line",t.line,1,255),(e+=this._analysisValueAttribute("unit",t.unit,1,255))+"/>"},l.prototype.createInitializationElement=function(t){var e="<initialization";return null!=t&&(e+=this._analysisEnumAttribute("reset",t.reset,/^(false|true)$/),e+=this._analysisEnumAttribute("print",t.print,/^(false|true)$/)),e+"/>"},l.prototype.createLogoElement=function(t){var e="<logo";return null!=t&&(e+=this._analysisEnumAttribute("width",t.width,/^(single|double)$/),e+=this._analysisEnumAttribute("height",t.height,/^(single|double)$/),e+=this._analysisValueAttribute("number",t.number,1,255)),e+"/>"},l.prototype.createPdf417Element=function(t){var e;if(null==t)throw Error("Argument is undefined.");if(e="<pdf417"+this._analysisEnumAttribute("level",t.level,/^(level[0-8])$/),null!=t.line&&(e=0!=t.line?e+this._analysisValueAttribute("line",t.line,3,90):e+' line="0"'),e+=this._analysisValueAttribute("column",t.column,0,30),e+=this._analysisValueAttribute("module",t.module,1,8),e+=this._analysisValueAttribute("aspect",t.aspect,1,8),null==t.data)throw Error('Argument "data" is undefined.');return(e=e+">"+this._encodeEscapeSequenceBinary(t.data))+"</pdf417>"},l.prototype.createPeripheralElement=function(t){var e="<peripheral";return null!=t&&(e+=this._analysisValueAttribute("channel",t.channel,1,2),e+=this._analysisValueAttribute("on",t.on,1,65535),e+=this._analysisValueAttribute("off",t.off,1,65535)),e+"/>"},l.prototype.createQrCodeElement=function(t){var e;if(null==t)throw Error("Argument is undefined.");if(e="<qrcode"+this._analysisEnumAttribute("model",t.model,/^(model[12])$/),e+=this._analysisEnumAttribute("level",t.level,/^(level_[lmqh])$/),e+=this._analysisValueAttribute("cell",t.cell,1,8),null==t.data)throw Error('Argument "data" is undefined.');return(e=e+">"+this._encodeEscapeSequenceBinary(t.data))+"</qrcode>"},l.prototype.createRawDataElement=function(t){if(null==t)throw Error("Argument is undefined.");if(null==t.data)throw Error('Argument "data" is undefined.');return(t="<rawdata>"+this._encodeBase64Binary(t.data))+"</rawdata>"},l.prototype.createRuledLineElement=function(t){var e="<ruledline";return null!=t&&(e+=this._analysisEnumAttribute("thickness",t.thickness,/^(thin|medium|thick|double_(thin|medium|thick))$/),e+=this._analysisValueAttribute("width",t.width,1,65535)),e+"/>"},l.prototype.createSoundElement=function(t){var e="<sound";return null!=t&&(e+=this._analysisValueAttribute("channel",t.channel,1,2),e+=this._analysisValueAttribute("repeat",t.repeat,1,20)),e+"/>"},l.prototype.createTextElement=function(t){var e;if(null==t)throw Error("Argument is undefined.");return e="<text"+this._analysisEnumAttribute("emphasis",t.emphasis,/^(false|true)$/),e+=this._analysisEnumAttribute("invert",t.invert,/^(false|true)$/),e+=this._analysisEnumAttribute("linespace",t.linespace,/^(24|32)$/),e+=this._analysisEnumAttribute("font",t.font,/^(font_[ab])$/),e+=this._analysisEnumAttribute("underline",t.underline,/^(false|true)$/),e+=this._analysisValueAttribute("characterspace",t.characterspace,0,7),e+=this._analysisValueAttribute("width",t.width,1,6),e+=this._analysisValueAttribute("height",t.height,1,6),e+=this._analysisEnumAttribute("codepage",t.codepage,/^(cp(437|737|772|774|851|852|855|857|858|860|861|862|863|864|865|866|869|874|928|932|998|999|1001|1250|1251|1252|2001|3001|3002|3011|3012|3021|3041|3840|3841|3843|3844|3845|3846|3847|3848)|utf8|blank|utf8|shift_jis|gb18030|gb2312|big5|korea)$/),e+=this._analysisEnumAttribute("international",t.international,/^(usa|france|germany|uk|denmark|sweden|italy|spain|japan|norway|denmark2|spain2|latin_america|korea|ireland|legal)$/),null!=t.data?(e+=">",e=1==t.binary?e+this._encodeEscapeSequenceBinary(t.data):e+this._encodeEscapeSequence(t.data),e+="</text>"):e+="/>",e},l.prototype.createHoldPrintElement=function(t){var e="<holdprint";return null!=t&&(e+=this._analysisEnumAttribute("type",t.type,/^(valid|invalid|default)$/)),e+"/>"},l.prototype._analysisEnumAttribute=function(t,e,r){if(null!=e){if(!r.test(e))throw Error('Argument "'+t+'" is invalid.');return" "+t+'="'+e+'"'}return""},l.prototype._analysisValueAttribute=function(t,e,r,n){if(null!=e){if(e<r||e>n)throw Error('Argument "'+t+'" is invalid.');return" "+t+'="'+e+'"'}return""},l.prototype._encodeEscapeSequence=function(t){var e=/[\\\x00-\x20\x26\x3c\x3e\x7f]/g;return e.test(t)&&(t=t.replace(e,(function(t){return"\\"==t?"\\\\":"\\x"+("0"+t.charCodeAt(0).toString(16)).slice(-2)}))),t},l.prototype._encodeEscapeSequenceBinary=function(t){var e=/[\\\x00-\x20\x26\x3c\x3e\x7f-\xff]/g;return e.test(t)&&(t=t.replace(e,(function(t){return"\\"==t?"\\\\":"\\x"+("0"+t.charCodeAt(0).toString(16)).slice(-2)}))),t},l.prototype._encodeBase64Binary=function(t){var e="",r=t.length;t+="\0\0";for(var n=0;n<r;n+=3){var i=t.charCodeAt(n)<<16|t.charCodeAt(n+1)<<8|t.charCodeAt(n+2);e=e+("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(63&i))}switch(r%3){case 1:return e.slice(0,-2)+"==";case 2:return e.slice(0,-1)+"="}return e},l.prototype._encodeRasterImage=function(t,e,r){for(var n=[[-254,-126,-222,-94,-246,-118,-214,-86],[-62,-190,-30,-158,-54,-182,-22,-150],[-206,-78,-238,-110,-198,-70,-230,-102],[-14,-142,-46,-174,-6,-134,-38,-166],[-242,-114,-210,-82,-250,-122,-218,-90],[-50,-178,-18,-146,-58,-186,-26,-154],[-194,-66,-226,-98,-202,-74,-234,-106],[-2,-130,-34,-162,-10,-138,-42,-170]],i="",s=0,o=0;o<r;o++){for(var u=0,a=128,c=0;c<e;c++)((30*t[s]+59*t[s+1]+11*t[s+2])*t[s+3]+12800)/25500-t[s+3]<n[7&o][7&c]&&(u|=a),s+=4,0==(a>>=1)&&(i+=String.fromCharCode(u),u=0,a=128);128!=a&&(i+=String.fromCharCode(u))}for(t=i,i="",e=t.length,t+="\0\0",o=0;o<e;o+=3)r=t.charCodeAt(o)<<16|t.charCodeAt(o+1)<<8|t.charCodeAt(o+2),i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(63&r);switch(e%3){case 1:return i.slice(0,-2)+"==";case 2:return i.slice(0,-1)+"="}return i};var h=function(t){function e(){var e=t.call(this)||this;return e.builder=new l,e}return i(e,t),e.prototype.init=function(){return this.request+=this.builder.createInitializationElement(),this},e.prototype.setJustification=function(t){return void 0===t&&(t="left"),this.request+=this.builder.createAlignmentElement({position:t}),this},e.prototype.setBold=function(t){return void 0===t&&(t=!0),this.request+=this.builder.createTextElement({emphasis:t}),this},e.prototype.setUnderline=function(t){return void 0===t&&(t=!0),this.request+=this.builder.createTextElement({underline:t}),this},e.prototype.setInverse=function(t){return void 0===t&&(t=!0),this.request+=this.builder.createTextElement({invert:t}),this},e.prototype.writeLine=function(t){return this.request+=this.builder.createTextElement({data:t+"\n"}),this},e.prototype.setSize=function(t){var e;switch(void 0===t&&(t="normal"),t){case"large":e=2;break;default:e=1}return this.request+=this.builder.createTextElement({width:e,height:e}),this},e.prototype.cut=function(t){return void 0===t&&(t="full"),this.request+=this.builder.createCutPaperElement({feed:!0,type:t}),this},e.prototype.feed=function(t){return void 0===t&&(t=1),this.request+=this.builder.createFeedElement({line:t}),this},e.prototype.flush=function(){return this.request},e}(u),p=function(t){function e(){var e=t.call(this)||this;return e.encoder=new TextEncoder,e}return i(e,t),e.prototype.init=function(){return this.buffer=new a,this.write(27),this.write("@"),this},e.prototype.flush=function(){return this.buffer.flush()},e.prototype.feed=function(t){return void 0===t&&(t=1),this.write(27),this.write("d"),this.write(t),this},e.prototype.cut=function(t){return void 0===t&&(t="full"),this.write(29),this.write("V"),this.write("full"===t?1:0),this},e.prototype.writeLine=function(t){return this.write(t+"\n")},e.prototype.setInverse=function(t){return void 0===t&&(t=!0),this.write(29),this.write("B"),this.write(t?1:0),this},e.prototype.setUnderline=function(t){return void 0===t&&(t=!0),this.write(27),this.write("-"),this.write(t?1:0),this},e.prototype.setJustification=function(t){var e;switch(void 0===t&&(t="left"),t){case"center":e=1;break;case"right":e=2;break;default:e=0}return this.write(27),this.write("a"),this.write(e),this},e.prototype.setBold=function(t){return void 0===t&&(t=!0),this.write(27),this.write("E"),this.write(t?1:0),this},e.prototype.setSize=function(t){return void 0===t&&(t="normal"),this.write(27),this.write("!"),this.write("normal"===t?0:48),this},e.prototype.write=function(t){return"number"==typeof t?this.buffer.writeUInt8(t):"string"==typeof t?this.buffer.write(this.encoder.encode(t)):this.buffer.write(t),this},e}(u),d=function(t){function e(){var e=t.call(this)||this;return e.isConnected=new r.BehaviorSubject(!1),e}return i(e,t),e.prototype.setDriver=function(t,e){var r=this;return void 0===e&&(e="ESC/POS"),this.driver=t,this.printLanguage=e,this.driver.connect(),this.driver.isConnected.subscribe((function(t){r.isConnected.next(t)})),this},e.prototype.init=function(){if(!this.driver)throw"Cannot initiate the print service. No connection detected.";switch(this.printLanguage){case"WebPRNT":this.builder=new h;break;case"StarPRNT":this.builder=new c;break;default:this.builder=new p}return this.builder.init(),this},e.prototype.cut=function(t){return void 0===t&&(t="full"),this.builder.cut(t),this},e.prototype.feed=function(t){return void 0===t&&(t=1),this.builder.feed(t),this},e.prototype.setInverse=function(t){return void 0===t&&(t=!0),this.builder.setInverse(t),this},e.prototype.setBold=function(t){return void 0===t&&(t=!0),this.builder.setBold(t),this},e.prototype.setUnderline=function(t){return void 0===t&&(t=!0),this.builder.setUnderline(t),this},e.prototype.setJustification=function(t){return void 0===t&&(t="left"),this.builder.setJustification(t),this},e.prototype.setSize=function(t){return void 0===t&&(t="normal"),this.builder.setSize(t),this},e.prototype.writeLine=function(t){return void 0===t&&(t=""),this.builder.writeLine(t),this},e.prototype.flush=function(){this.driver.write(this.builder.flush())},e}(u);d.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new d},token:d,providedIn:"root"}),d.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],d.ctorParameters=function(){return[]};var f=function(){},y=function(t){this.papertype=this.checkedblock=this.url=null,this.timeout=9e4,this.onTimeout=this.onError=this.onReceive=null,this.holdprint_timeout=void 0,this._json=this._url=null,null!=t&&(null!=t.url&&(this.url=t.url),null!=t.checkedblock&&(this.checkedblock=t.checkedblock),null!=t.papertype&&(this.papertype=t.papertype),null!=t.timeout&&(this.timeout=t.timeout),null!=t.holdprint_timeout&&(this.holdprint_timeout=t.holdprint_timeout))},b={};y.prototype._callMessageHandler=function(){var t=this;null==b[t._url]?(b[t._url]=t,webkit.messageHandlers.sendMessageHandler.postMessage(t._json)):setTimeout((function(){t._callMessageHandler()}),500)},y.prototype.sendMessage=function(t){var e="<root";null!=t.checkedblock?0==t.checkedblock&&(e+=' checkedblock="false"'):0==this.checkedblock&&(e+=' checkedblock="false"'),null!=t.papertype?"normal"==t.papertype?e+=' papertype="normal"':"black_mark"==t.papertype?e+=' papertype="black_mark"':"black_mark_and_detect_at_power_on"==t.papertype&&(e+=' papertype="black_mark_and_detect_at_power_on"'):"normal"==this.papertype?e+=' papertype="normal"':"black_mark"==this.papertype?e+=' papertype="black_mark"':"black_mark_and_detect_at_power_on"==this.papertype&&(e+=' papertype="black_mark_and_detect_at_power_on"'),null!=t.holdprint_timeout?e+=' holdprint_timeout="'+t.holdprint_timeout+'"':null!=this.holdprint_timeout&&(e+=' holdprint_timeout="'+this.holdprint_timeout+'"');var r;e=e+">"+t.request+"</root>";if(r='<StarWebPrint xmlns="http://www.star-m.jp" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Request>',r+=this._encodeEscapeSequence(e),r+="</Request>",r+="</StarWebPrint>",e="",e=null!=t.url?t.url:this.url,/^https?:\/\/(localhost|127\.0\.0\.1):8001\//.test(e.toLowerCase())&&-1!=navigator.userAgent.indexOf("webPRNTSupportMessageHandler"))this._json=JSON.stringify({url:e,body:r}),this._url=e,this._callMessageHandler();else{var n=null;if(window.XMLHttpRequest)n=new XMLHttpRequest;else{if(!window.ActiveXObject)return void(this.onError&&this.onError({status:10001,responseText:"XMLHttpRequest is not supported."}));n=new ActiveXObject("Microsoft.XMLHTTP")}-1==navigator.userAgent.indexOf("iPad;")&&-1==navigator.userAgent.indexOf("iPhone;")&&-1==navigator.userAgent.indexOf("iPod touch;")&&-1==navigator.userAgent.indexOf("Android")||-1!=navigator.userAgent.indexOf("WebPRNTSupportHTTPS")||0!=e.toLowerCase().indexOf("https://localhost")&&0!=e.toLowerCase().indexOf("https://127.0.0.1")||(e="http://"+e.substring(8));try{n.open("POST",e,!0)}catch(t){return void(this.onError&&this.onError({status:10002,responseText:t.message}))}try{null!=t.timeout?n.timeout=t.timeout:this.timeout&&(n.timeout=this.timeout)}catch(t){}n.setRequestHeader("Content-Type","text/xml; charset=UTF-8");var i=this;n.onreadystatechange=function(){if(4==n.readyState)try{if(200==n.status){var t=n.responseXML.getElementsByTagName("Response");if(0<t.length){if(i.onReceive){var e=t[0].childNodes[0].nodeValue;i.onReceive({traderSuccess:e.slice(e.indexOf("<success>")+9,e.indexOf("</success>")),traderCode:e.slice(e.indexOf("<code>")+6,e.indexOf("</code>")),traderStatus:e.slice(e.indexOf("<status>")+8,e.indexOf("</status>")),status:n.status,responseText:n.responseText})}}else i.onError&&i.onError({status:n.status,responseText:n.responseText})}else i.onError&&i.onError({status:n.status,responseText:n.responseText})}catch(t){i.onError&&i.onError({status:0,responseText:"Connection timeout occurred."})}};try{n.ontimeout=function(){i.onTimeout&&i.onTimeout()}}catch(t){}try{n.send(r)}catch(t){this.onError&&this.onError({status:10003,responseText:t.message})}}},y.prototype._onHandlerSuccess=function(t){trader.onReceive&&trader.onReceive(t)},y.prototype._onHandlerError=function(t){trader.onError&&trader.onError(t)},y.prototype.isCoverOpen=function(t){return!!(32&parseInt(t.traderStatus.substr(4,2),16))},y.prototype.isOffLine=function(t){return!!(8&parseInt(t.traderStatus.substr(4,2),16))},y.prototype.isCompulsionSwitchClose=function(t){return!!(4&parseInt(t.traderStatus.substr(4,2),16))},y.prototype.isEtbCommandExecute=function(t){return!!(2&parseInt(t.traderStatus.substr(4,2),16))},y.prototype.isHighTemperatureStop=function(t){return!!(64&parseInt(t.traderStatus.substr(6,2),16))},y.prototype.isNonRecoverableError=function(t){return!!(32&parseInt(t.traderStatus.substr(6,2),16))},y.prototype.isAutoCutterError=function(t){return!!(8&parseInt(t.traderStatus.substr(6,2),16))},y.prototype.isBlackMarkError=function(t){return!!(8&parseInt(t.traderStatus.substr(8,2),16))},y.prototype.isPaperEnd=function(t){return!!(8&parseInt(t.traderStatus.substr(10,2),16))},y.prototype.isPaperNearEnd=function(t){return!!(4&parseInt(t.traderStatus.substr(10,2),16))},y.prototype.isPaperPresent=function(t){return!!(2&parseInt(t.traderStatus.substr(12,2),16))},y.prototype.extractionEtbCounter=function(t){var e=0;return 64&parseInt(t.traderStatus.substr(14,2),16)&&(e|=16),32&parseInt(t.traderStatus.substr(14,2),16)&&(e|=8),8&parseInt(t.traderStatus.substr(14,2),16)&&(e|=4),4&parseInt(t.traderStatus.substr(14,2),16)&&(e|=2),2&parseInt(t.traderStatus.substr(14,2),16)&&(e|=1),e},y.prototype._encodeEscapeSequence=function(t){var e=/[<>&]/g;return e.test(t)&&(t=t.replace(e,(function(t){switch(t){case"<":return"<";case">":return">"}return"&"}))),t};var v=function(t){function e(e,n){void 0===n&&(n=!1);var i=t.call(this)||this;return i.isConnected=new r.BehaviorSubject(!1),i.useSecure=!1,i.isStarPrinter=!1,i.url=e,i.useSecure=n,i}return i(e,t),e.prototype.connect=function(){var t=this,e=this.useSecure?"s":"";this.trader=new y({url:"http"+e+"://"+this.url+"/StarWebPRNT/SendMessage"}),this.trader.onReceive=function(e){t.isConnected.next(!0)},this.trader.onError=function(e){t.isConnected.next(!1)},this.trader.sendMessage("")},e.prototype.write=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){return this.trader.sendMessage({request:t}),[2]}))}))},e}(f),m=function(t){function e(e,n){var i=t.call(this)||this;return i.isConnected=new r.BehaviorSubject(!1),i.vendorId=e,i.productId=n,i}return i(e,t),e.prototype.connect=function(){var t=this;navigator.usb.getDevices().then((function(e){return t.device=e.find((function(e){return e.vendorId===t.vendorId&&e.productId===t.productId})),console.log(t.device),t.device.open()})).then((function(){return t.device.selectConfiguration(1)})).then((function(){return t.device.claimInterface(0)})).then((function(e){var r=t.device.configuration.interfaces[0].alternate.endpoints;t.endPoint=r.find((function(t){return"out"===t.direction})),t.isConnected.next(!0),t.listenForUsbConnections()})).catch((function(e){t.isConnected.next(!1)}))},e.prototype.requestUsb=function(){var t=this;return new r.Observable((function(e){navigator.usb.requestDevice({filters:[]}).then((function(r){return t.vendorId=r.vendorId,t.productId=r.productId,e.next(r)})).catch((function(t){return e.error(t)}))}))},e.prototype.write=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){return this.device.transferOut(this.endPoint.endpointNumber,t),[2]}))}))},e.prototype.listenForUsbConnections=function(){var t=this;navigator.usb.addEventListener("disconnect",(function(){t.isConnected.next(!1)})),navigator.usb.addEventListener("connect",(function(){t.isConnected.next(!0)}))},e}(f),w=function(){};w.decorators=[{type:e.NgModule,args:[{imports:[],declarations:[],exports:[]}]}],t.PrintService=d,t.ThermalPrintModule=w,t.UsbDriver=m,t.WebPrintDriver=v,t.ɵa=u,t.ɵb=f,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-thermal-print.umd.min.js.map