UNPKG

qzprinty

Version:

A simple utility to print html or pdf using qz tray

10 lines 39 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.qzPrinty=t():e.qzPrinty=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){"use strict";var r,o,i=function(){Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)});var e={VERSION:"2.0.8",DEBUG:!1,log:{trace:function(){e.DEBUG&&console.log.apply(console,arguments)},info:function(){console.info.apply(console,arguments)},warn:function(){e.DEBUG&&console.warn.apply(console,arguments)},error:function(){console.error.apply(console,arguments)}},streams:{serial:"SERIAL",usb:"USB",hid:"HID"},websocket:{connection:null,connectConfig:{host:["localhost","localhost.qz.io"],hostIndex:0,usingSecure:!0,protocol:{secure:"wss://",insecure:"ws://"},port:{secure:[8181,8282,8383,8484],insecure:[8182,8283,8384,8485],portIndex:0},keepAlive:60,retries:0,delay:0},setup:{findConnection:function(t,n,r){if(t.port.secure.length)t.port.insecure.length||t.usingSecure||(e.log.trace("No insecure ports specified - forcing secure connection"),t.usingSecure=!0);else{if(!t.port.insecure.length)return void r(new Error("No ports have been specified to connect over"));t.usingSecure&&(e.log.error("No secure ports specified - forcing insecure connection"),t.usingSecure=!1)}var o,s=function(){if(t.port.portIndex++,t.usingSecure&&t.port.portIndex>=t.port.secure.length||!t.usingSecure&&t.port.portIndex>=t.port.insecure.length){if(t.hostIndex>=t.host.length-1)return void r(new Error("Unable to establish connection with QZ"));t.hostIndex++,t.port.portIndex=0}e.websocket.setup.findConnection(t,n,r)};o=t.usingSecure?t.protocol.secure+t.host[t.hostIndex]+":"+t.port.secure[t.port.portIndex]:t.protocol.insecure+t.host[t.hostIndex]+":"+t.port.insecure[t.port.portIndex];try{e.log.trace("Attempting connection",o),e.websocket.connection=new e.tools.ws(o)}catch(t){return e.log.error(t),void s()}null!=e.websocket.connection?(e.websocket.connection.established=!1,e.websocket.connection.onopen=function(s){if(!e.websocket.connection.established&&(e.log.trace(s),e.log.info("Established connection with QZ Tray on "+o),e.websocket.setup.openConnection({resolve:n,reject:r}),t.keepAlive>0))var c=setInterval(function(){i.websocket.isActive()?e.websocket.connection.send("ping"):clearInterval(c)},1e3*t.keepAlive)},e.websocket.connection.onclose=function(){e.websocket.connection&&"undefined"!=typeof navigator&&-1!=navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("Chrome")&&e.websocket.connection.onerror()},e.websocket.connection.onerror=function(t){e.log.trace(t),e.websocket.connection=null,s()}):r(new Error("Unable to create a websocket connection"))},openConnection:function(t){function n(n){void 0===n&&(n=null),e.websocket.connection.sendData({certificate:n,promise:t})}e.websocket.connection.established=!0,e.websocket.connection.onclose=function(t){for(var n in e.log.trace(t),e.log.info("Closed connection with QZ Tray"),null!=e.websocket.connection.promise&&e.websocket.connection.promise.resolve(),e.websocket.callClose(t),e.websocket.connection=null,e.websocket.pendingCalls)e.websocket.pendingCalls.hasOwnProperty(n)&&e.websocket.pendingCalls[n].reject(new Error("Connection closed before response received"))},e.websocket.connection.onerror=function(t){e.websocket.callError(t)},e.websocket.connection.sendData=function(t){e.log.trace("Preparing object for websocket",t),null==t.timestamp&&(t.timestamp=Date.now(),"number"!=typeof t.timestamp&&(t.timestamp=(new Date).getTime())),null!=t.promise&&(t.uid=e.websocket.setup.newUID(),e.websocket.pendingCalls[t.uid]=t.promise),t.position={x:screen?(screen.availWidth||screen.width)/2+(screen.left||screen.availLeft):0,y:screen?(screen.availHeight||screen.height)/2+(screen.top||screen.availTop):0};try{if(null!=t.call&&null==t.signature){var n={call:t.call,params:t.params,timestamp:t.timestamp},r=e.tools.hash(e.tools.stringify(n));r.then||(r=e.tools.promise(function(e){e(r)})),r.then(function(t){return e.security.callSign(t)}).then(function(n){e.log.trace("Signature for call",n),t.signature=n,e.signContent=void 0,e.websocket.connection.send(e.tools.stringify(t))})}else e.log.trace("Signature for call",t.signature),e.websocket.connection.send(e.tools.stringify(t))}catch(n){e.log.error(n),null!=t.promise&&(t.promise.reject(n),delete e.websocket.pendingCalls[t.uid])}},e.websocket.connection.onmessage=function(t){var n=JSON.parse(t.data);if(null!=n.uid){e.log.trace("Received response from websocket",n);var r=e.websocket.pendingCalls[n.uid];null==r?e.log.warn("No promise found for returned response"):null!=n.error?r.reject(new Error(n.error)):r.resolve(n.result),delete e.websocket.pendingCalls[n.uid]}else if(null==n.type)e.websocket.connection.close(4003,"Connected to incompatible QZ Tray version");else switch(n.type){case e.streams.serial:n.event||(n.event=JSON.stringify({portName:n.key,output:n.data})),e.serial.callSerial(JSON.parse(n.event));break;case e.streams.usb:n.event||(n.event=JSON.stringify({vendorId:n.key[0],productId:n.key[1],output:n.data})),e.usb.callUsb(JSON.parse(n.event));break;case e.streams.hid:e.hid.callHid(JSON.parse(n.event));break;default:e.log.warn("Cannot determine stream type for callback",n)}},e.security.callCert().then(n).catch(n)},newUID:function(){return(new Array(7).join("0")+(Math.random()*Math.pow(36,6)<<0).toString(36)).slice(-6)}},dataPromise:function(t,n,r,o){return e.tools.promise(function(i,s){var c={call:t,promise:{resolve:i,reject:s},params:n,signature:r,timestamp:o};e.websocket.connection.sendData(c)})},pendingCalls:{},errorCallbacks:[],callError:function(t){if(Array.isArray(e.websocket.errorCallbacks))for(var n=0;n<e.websocket.errorCallbacks.length;n++)e.websocket.errorCallbacks[n](t);else e.websocket.errorCallbacks(t)},closedCallbacks:[],callClose:function(t){if(Array.isArray(e.websocket.closedCallbacks))for(var n=0;n<e.websocket.closedCallbacks.length;n++)e.websocket.closedCallbacks[n](t);else e.websocket.closedCallbacks(t)}},printing:{defaultConfig:{colorType:"color",copies:1,density:0,duplex:!1,fallbackDensity:null,interpolation:"bicubic",jobName:null,legacy:!1,margins:0,orientation:null,paperThickness:null,printerTray:null,rasterize:!0,rotation:0,scaleContent:!0,size:null,units:"in",altPrinting:!1,encoding:null,endOfDoc:null,perSpool:1}},serial:{serialCallbacks:[],callSerial:function(t){if(Array.isArray(e.serial.serialCallbacks))for(var n=0;n<e.serial.serialCallbacks.length;n++)e.serial.serialCallbacks[n](t);else e.serial.serialCallbacks(t)}},usb:{usbCallbacks:[],callUsb:function(t){if(Array.isArray(e.usb.usbCallbacks))for(var n=0;n<e.usb.usbCallbacks.length;n++)e.usb.usbCallbacks[n](t);else e.usb.usbCallbacks(t)}},hid:{hidCallbacks:[],callHid:function(t){if(Array.isArray(e.hid.hidCallbacks))for(var n=0;n<e.hid.hidCallbacks.length;n++)e.hid.hidCallbacks[n](t);else e.hid.hidCallbacks(t)}},security:{certPromise:function(e,t){t()},callCert:function(){return e.tools.promise(e.security.certPromise)},signaturePromise:function(){return function(e){e()}},callSign:function(t){return e.tools.promise(e.security.signaturePromise(t))}},tools:{promise:function(e){return new RSVP.Promise(e)},stringify:function(e){var t=Array.prototype.toJSON;delete Array.prototype.toJSON;var n=JSON.stringify(e);return t&&(Array.prototype.toJSON=t),n},hash:function(e){return Sha256.hash(e)},ws:"undefined"!=typeof WebSocket?WebSocket:null,absolute:function(e){if("undefined"!=typeof window&&"function"==typeof document.createElement){var t=document.createElement("a");return t.href=e,t.href}return e},extend:function(t){"object"!=typeof t&&(t={});for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var o in r)if(r.hasOwnProperty(o)){if(t===r[o])continue;var i;if(r[o]&&r[o].constructor&&r[o].constructor===Object)i=Array.isArray(r[o])?t[o]||[]:t[o]||{},t[o]=e.tools.extend(i,r[o]);else void 0!==r[o]&&(t[o]=r[o])}}return t}}};function t(t,n){this.setPrinter=function(e){"string"==typeof e&&(e={name:e}),this.printer=e},this.getPrinter=function(){return this.printer},this.reconfigure=function(t){e.tools.extend(this.config,t)},this.getOptions=function(){return this.config},this.setPrinter(t),this.config=n}return t.prototype.print=function(e,t,n){i.print(this,e,t,n)},{websocket:{isActive:function(){return null!=e.websocket.connection&&e.websocket.connection.established},connect:function(t){return e.tools.promise(function(n,r){if(i.websocket.isActive())r(new Error("An open connection with QZ Tray already exists"));else if(null==e.websocket.connection)if(e.tools.ws)if(e.tools.ws.CLOSED&&2!=e.tools.ws.CLOSED){null==t&&(t={}),"undefined"!=typeof location&&"https:"===location.protocol||void 0===t.usingSecure&&(e.log.trace("Disabling secure ports due to insecure page"),t.usingSecure=!1),void 0===t.host||Array.isArray(t.host)||(t.host=[t.host]);var o=function(i){var s=!1,c=function(){s||(s=!0,t&&i<t.retries?o(i+1):r.apply(null,arguments))},a=function(){var r=e.tools.extend({},e.websocket.connectConfig,t);e.websocket.setup.findConnection(r,n,c)};0==i?a():setTimeout(a,1e3*t.delay)};o(0)}else r(new Error("Unsupported WebSocket version detected: HyBi-00/Hixie-76"));else r(new Error("WebSocket not supported by this browser"));else r(new Error("The current connection attempt has not returned yet"))})},disconnect:function(){return e.tools.promise(function(t,n){i.websocket.isActive()?(e.websocket.connection.close(),e.websocket.connection.promise={resolve:t,reject:n}):n(new Error("No open connection with QZ Tray"))})},setErrorCallbacks:function(t){e.websocket.errorCallbacks=t},setClosedCallbacks:function(t){e.websocket.closedCallbacks=t},getNetworkInfo:function(t,n){return e.websocket.dataPromise("websocket.getNetworkInfo",{hostname:t,port:n})},getConnectionInfo:function(){if(e.websocket.connection){var t=e.websocket.connection.url.split(/[:\/]+/g);return{socket:t[0],host:t[1],port:+t[2]}}throw new Error("A connection to QZ has not been established yet")}},printers:{getDefault:function(){return e.websocket.dataPromise("printers.getDefault")},find:function(t){return e.websocket.dataPromise("printers.find",{query:t})}},configs:{setDefaults:function(t){e.tools.extend(e.printing.defaultConfig,t)},create:function(n,r){return new t(n,e.tools.extend({},e.printing.defaultConfig,r))}},print:function(t,n,r,o){for(var i=0;i<n.length;i++)n[i].constructor===Object&&((!n[i].format&&n[i].type&&"RAW"!==n[i].type.toUpperCase()&&"DIRECT"!==n[i].type.toUpperCase()||n[i].format&&("FILE"===n[i].format.toUpperCase()||"IMAGE"===n[i].format.toUpperCase()&&(0!==n[i].data.indexOf("data:image/")||0===n[i].data.indexOf(";base64,"))||"XML"===n[i].format.toUpperCase()))&&(n[i].data=e.tools.absolute(n[i].data)),n[i].options&&"string"==typeof n[i].options.overlay&&(n[i].options.overlay=e.tools.absolute(n[i].options.overlay)));var s={printer:t.getPrinter(),options:t.getOptions(),data:n};return e.websocket.dataPromise("print",s,r,o)},serial:{findPorts:function(){return e.websocket.dataPromise("serial.findPorts")},setSerialCallbacks:function(t){e.serial.serialCallbacks=t},openPort:function(t,n){var r={port:t,options:n};return e.websocket.dataPromise("serial.openPort",r)},sendData:function(t,n,r){null!=r&&e.log.warn("Properties object is deprecated on sendData calls, use openPort instead.");var o={port:t,data:n,properties:r};return e.websocket.dataPromise("serial.sendData",o)},closePort:function(t){return e.websocket.dataPromise("serial.closePort",{port:t})}},usb:{listDevices:function(t){return e.websocket.dataPromise("usb.listDevices",{includeHubs:t})},listInterfaces:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1]}),e.websocket.dataPromise("usb.listInterfaces",t)},listEndpoints:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],interface:arguments[2]}),e.websocket.dataPromise("usb.listEndpoints",t)},setUsbCallbacks:function(t){e.usb.usbCallbacks=t},claimDevice:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],interface:arguments[2]}),e.websocket.dataPromise("usb.claimDevice",t)},isClaimed:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1]}),e.websocket.dataPromise("usb.isClaimed",t)},sendData:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],endpoint:arguments[2],data:arguments[3]}),e.websocket.dataPromise("usb.sendData",t)},readData:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],endpoint:arguments[2],responseSize:arguments[3]}),e.websocket.dataPromise("usb.readData",t)},openStream:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],endpoint:arguments[2],responseSize:arguments[3],interval:arguments[4]}),e.websocket.dataPromise("usb.openStream",t)},closeStream:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],endpoint:arguments[2]}),e.websocket.dataPromise("usb.closeStream",t)},releaseDevice:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1]}),e.websocket.dataPromise("usb.releaseDevice",t)}},hid:{listDevices:function(){return e.websocket.dataPromise("hid.listDevices")},startListening:function(){return e.websocket.dataPromise("hid.startListening")},stopListening:function(){return e.websocket.dataPromise("hid.stopListening")},setHidCallbacks:function(t){e.hid.hidCallbacks=t},claimDevice:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1]}),e.websocket.dataPromise("hid.claimDevice",t)},isClaimed:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1]}),e.websocket.dataPromise("hid.isClaimed",t)},sendData:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],data:arguments[2],endpoint:arguments[3]}),e.websocket.dataPromise("hid.sendData",t)},readData:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],responseSize:arguments[2]}),e.websocket.dataPromise("hid.readData",t)},openStream:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1],responseSize:arguments[2],interval:arguments[3]}),e.websocket.dataPromise("hid.openStream",t)},closeStream:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1]}),e.websocket.dataPromise("hid.closeStream",t)},releaseDevice:function(t){return"object"!=typeof t&&(t={vendorId:arguments[0],productId:arguments[1]}),e.websocket.dataPromise("hid.releaseDevice",t)}},security:{setCertificatePromise:function(t){e.security.certPromise=t},setSignaturePromise:function(t){e.security.signaturePromise=t}},api:{showDebug:function(t){e.DEBUG=t},getVersion:function(){return e.websocket.dataPromise("getVersion")},setPromiseType:function(t){e.tools.promise=t},setSha256Type:function(t){e.tools.hash=t},setWebSocketType:function(t){e.tools.ws=t}},version:e.VERSION}}();void 0===(o="function"==typeof(r=i)?r.call(t,n,t,e):r)||(e.exports=o)},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function c(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var a,u=[],l=!1,f=-1;function p(){l&&a&&(l=!1,a.length?u=a.concat(u):f=-1,u.length&&d())}function d(){if(!l){var e=c(p);l=!0;for(var t=u.length;t;){for(a=u,u=[];++f<t;)a&&a[f].run();f=-1,t=u.length}a=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function h(e,t){this.fun=e,this.array=t}function b(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];u.push(new h(e,t)),1!==u.length||l||c(d)},h.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=b,o.addListener=b,o.once=b,o.off=b,o.removeListener=b,o.removeAllListeners=b,o.emit=b,o.prependListener=b,o.prependOnceListener=b,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";(function(e,r){ /*! * @overview RSVP - a tiny implementation of Promises/A+. * @copyright Copyright (c) 2016 Yehuda Katz, Tom Dale, Stefan Penner and contributors * @license Licensed under MIT license * See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE * @version 4.7.0+2254ba40 */ function o(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}var i={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(e,t){if("function"!=typeof t)throw new TypeError("Callback must be a function");var n=o(this),r=void 0;(r=n[e])||(r=n[e]=[]),r.indexOf(t)&&r.push(t)},off:function(e,t){var n,r=o(this),i=void 0;t?-1!==(n=(i=r[e]).indexOf(t))&&i.splice(n,1):r[e]=[]},trigger:function(e,t,n){var r;if(r=o(this)[e])for(var i=0;i<r.length;i++)(0,r[i])(t,n)}},s={instrument:!1};function c(e,t){if(2!==arguments.length)return s[e];s[e]=t}i.mixin(s);var a=[];function u(e,t,n){1===a.push({name:e,payload:{key:t._guidKey,id:t._id,eventName:e,detail:t._result,childId:n&&n._id,label:t._label,timeStamp:Date.now(),error:s["instrument-with-stack"]?new Error(t._label):null}})&&setTimeout(function(){for(var e=0;e<a.length;e++){var t=a[e],n=t.payload;n.guid=n.key+n.id,n.childGuid=n.key+n.childId,n.error&&(n.stack=n.error.stack),s.trigger(t.name,t.payload)}a.length=0},50)}function l(e,t){if(e&&"object"==typeof e&&e.constructor===this)return e;var n=new this(f,t);return _(n,e),n}function f(){}var p=void 0,d=1,h=2,b={error:null};function y(e){try{return e.then}catch(e){return b.error=e,b}}var m=void 0;function v(){try{var e=m;return m=null,e.apply(this,arguments)}catch(e){return b.error=e,b}}function w(e){return m=e,v}function g(e,t,n){if(t.constructor===e.constructor&&n===I&&e.constructor.resolve===l)!function(e,t){t._state===d?T(e,t._result):t._state===h?(t._onError=null,S(e,t._result)):C(t,void 0,function(n){t===n?T(e,n):_(e,n)},function(t){return S(e,t)})}(e,t);else if(n===b){var r=b.error;b.error=null,S(e,r)}else"function"==typeof n?function(e,t,n){s.async(function(e){var r=!1,o=w(n).call(t,function(n){r||(r=!0,t===n?T(e,n):_(e,n))},function(t){r||(r=!0,S(e,t))},"Settle: "+(e._label||" unknown promise"));if(!r&&o===b){r=!0;var i=b.error;b.error=null,S(e,i)}},e)}(e,t,n):T(e,t)}function _(e,t){var n,r;e===t?T(e,t):(r=typeof(n=t),null===n||"object"!==r&&"function"!==r?T(e,t):g(e,t,y(t)))}function k(e){e._onError&&e._onError(e._result),j(e)}function T(e,t){e._state===p&&(e._result=t,e._state=d,0===e._subscribers.length?s.instrument&&u("fulfilled",e):s.async(j,e))}function S(e,t){e._state===p&&(e._state=h,e._result=t,s.async(k,e))}function C(e,t,n,r){var o=e._subscribers,i=o.length;e._onError=null,o[i]=t,o[i+d]=n,o[i+h]=r,0===i&&e._state&&s.async(j,e)}function j(e){var t=e._subscribers,n=e._state;if(s.instrument&&u(n===d?"fulfilled":"rejected",e),0!==t.length){for(var r=void 0,o=void 0,i=e._result,c=0;c<t.length;c+=3)r=t[c],o=t[c+n],r?P(n,r,o,i):o(i);e._subscribers.length=0}}function P(e,t,n,r){var o="function"==typeof n,i=void 0;if(i=o?w(n)(r):r,t._state!==p);else if(i===t)S(t,new TypeError("A promises callback cannot return that same promise."));else if(i===b){var s=b.error;b.error=null,S(t,s)}else o?_(t,i):e===d?T(t,i):e===h&&S(t,i)}function I(e,t,n){var r=this._state;if(r===d&&!e||r===h&&!t)return s.instrument&&u("chained",this,this),this;this._onError=null;var o=new this.constructor(f,n),i=this._result;if(s.instrument&&u("chained",this,o),r===p)C(this,o,e,t);else{var c=r===d?e:t;s.async(function(){return P(r,o,c,i)})}return o}var A=function(){function e(e,t,n,r){this._instanceConstructor=e,this.promise=new e(f,r),this._abortOnReject=n,this._isUsingOwnPromise=e===D,this._isUsingOwnResolve=e.resolve===l,this._init.apply(this,arguments)}return e.prototype._init=function(e,t){var n=t.length||0;this.length=n,this._remaining=n,this._result=new Array(n),this._enumerate(t)},e.prototype._enumerate=function(e){for(var t=this.length,n=this.promise,r=0;n._state===p&&r<t;r++)this._eachEntry(e[r],r,!0);this._checkFullfillment()},e.prototype._checkFullfillment=function(){0===this._remaining&&T(this.promise,this._result)},e.prototype._settleMaybeThenable=function(e,t,n){var r=this._instanceConstructor;if(this._isUsingOwnResolve){var o=y(e);if(o===I&&e._state!==p)e._onError=null,this._settledAt(e._state,t,e._result,n);else if("function"!=typeof o)this._settledAt(d,t,e,n);else if(this._isUsingOwnPromise){var i=new r(f);g(i,e,o),this._willSettleAt(i,t,n)}else this._willSettleAt(new r(function(t){return t(e)}),t,n)}else this._willSettleAt(r.resolve(e),t,n)},e.prototype._eachEntry=function(e,t,n){null!==e&&"object"==typeof e?this._settleMaybeThenable(e,t,n):this._setResultAt(d,t,e,n)},e.prototype._settledAt=function(e,t,n,r){var o=this.promise;o._state===p&&(this._abortOnReject&&e===h?S(o,n):(this._setResultAt(e,t,n,r),this._checkFullfillment()))},e.prototype._setResultAt=function(e,t,n,r){this._remaining--,this._result[t]=n},e.prototype._willSettleAt=function(e,t,n){var r=this;C(e,void 0,function(e){return r._settledAt(d,t,e,n)},function(e){return r._settledAt(h,t,e,n)})},e}();function O(e,t,n){this._remaining--,this._result[t]=e===d?{state:"fulfilled",value:n}:{state:"rejected",reason:n}}var E="rsvp_"+Date.now()+"-",x=0;var D=function(){function e(t,n){this._id=x++,this._label=n,this._state=void 0,this._result=void 0,this._subscribers=[],s.instrument&&u("created",this),f!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof e?function(e,t){var n=!1;try{t(function(t){n||(n=!0,_(e,t))},function(t){n||(n=!0,S(e,t))})}catch(t){S(e,t)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return e.prototype._onError=function(e){var t=this;s.after(function(){t._onError&&s.trigger("error",e,t._label)})},e.prototype.catch=function(e,t){return this.then(void 0,e,t)},e.prototype.finally=function(e,t){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){throw t})},t)},e}();function R(e,t){return{then:function(n,r){return e.call(t,n,r)}}}function N(e,t,n,r){if(w(n).apply(r,t)===b){var o=b.error;b.error=null,S(e,o)}return e}function U(e){return null!==e&&"object"==typeof e&&(e.constructor===D||y(e))}D.all=function(e,t){return Array.isArray(e)?new A(this,e,!0,t).promise:this.reject(new TypeError("Promise.all must be called with an array"),t)},D.race=function(e,t){var n=new this(f,t);if(!Array.isArray(e))return S(n,new TypeError("Promise.race must be called with an array")),n;for(var r=0;n._state===p&&r<e.length;r++)C(this.resolve(e[r]),void 0,function(e){return _(n,e)},function(e){return S(n,e)});return n},D.resolve=l,D.reject=function(e,t){var n=new this(f,t);return S(n,e),n},D.prototype._guidKey=E,D.prototype.then=I;var M=function(e){function t(t,n,r){return function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,t,n,!1,r))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t}(A);M.prototype._setResultAt=O;var L=Object.prototype.hasOwnProperty,F=function(e){function t(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=arguments[3];return function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,t,n,r,o))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype._init=function(e,t){this._result={},this._enumerate(t),0===this._remaining&&T(this.promise,this._result)},t.prototype._enumerate=function(e){var t=this.promise,n=[];for(var r in e)L.call(e,r)&&n.push({position:r,entry:e[r]});var o=n.length;this._remaining=o;for(var i=void 0,s=0;t._state===p&&s<o;s++)i=n[s],this._eachEntry(i.entry,i.position)},t}(A);var H=function(e){function t(t,n,r){return function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,t,n,!1,r))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t}(F);H.prototype._setResultAt=O;var B=function(e){function t(t,n,r,o){return function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,t,n,!0,o,r))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype._init=function(e,t,n,r,o){var i=t.length||0;this.length=i,this._remaining=i,this._result=new Array(i),this._mapFn=o,this._enumerate(t)},t.prototype._setResultAt=function(e,t,n,r){if(r){var o=w(this._mapFn)(n,t);o===b?this._settledAt(h,t,o.error,!1):this._eachEntry(o,t,!1)}else this._remaining--,this._result[t]=n},t}(A);var V={},Z=function(e){function t(t,n,r,o){return function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,t,n,!0,o,r))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype._init=function(e,t,n,r,o){var i=t.length||0;this.length=i,this._remaining=i,this._result=new Array(i),this._filterFn=o,this._enumerate(t)},t.prototype._checkFullfillment=function(){0===this._remaining&&(this._result=this._result.filter(function(e){return e!==V}),T(this.promise,this._result))},t.prototype._setResultAt=function(e,t,n,r){if(r){this._result[t]=n;var o=w(this._filterFn)(n,t);o===b?this._settledAt(h,t,o.error,!1):this._eachEntry(o,t,!1)}else this._remaining--,n||(this._result[t]=V)},t}(A);var J=0,z=void 0;function W(e,t){Y[J]=e,Y[J+1]=t,2===(J+=2)&&ae()}var Q="undefined"!=typeof window?window:void 0,G=Q||{},q=G.MutationObserver||G.WebKitMutationObserver,K="undefined"==typeof self&&void 0!==e&&"[object process]"==={}.toString.call(e),$="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function X(){return function(){return setTimeout(ee,1)}}var Y=new Array(1e3);function ee(){for(var e=0;e<J;e+=2){(0,Y[e])(Y[e+1]),Y[e]=void 0,Y[e+1]=void 0}J=0}var te,ne,re,oe,ie,se,ce,ae=void 0;function ue(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}K?(ie=e.nextTick,se=e.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/),Array.isArray(se)&&"0"===se[1]&&"10"===se[2]&&(ie=r),ae=function(){return ie(ee)}):q?(ne=0,re=new q(ee),oe=document.createTextNode(""),re.observe(oe,{characterData:!0}),ae=function(){return oe.data=ne=++ne%2}):$?((te=new MessageChannel).port1.onmessage=ee,ae=function(){return te.port2.postMessage(0)}):ae=void 0===Q?function(){try{var e=n(8);return void 0!==(z=e.runOnLoop||e.runOnContext)?function(){z(ee)}:X()}catch(e){return X()}}():X(),s.async=W,s.after=function(e){return setTimeout(e,0)};function le(){s.on.apply(s,arguments)}if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var fe=window.__PROMISE_INSTRUMENTATION__;for(var pe in c("instrument",!0),fe)fe.hasOwnProperty(pe)&&le(pe,fe[pe])}var de=(ue(ce={asap:W,Promise:D,EventTarget:i,all:function(e,t){return D.all(e,t)},allSettled:function(e,t){return Array.isArray(e)?new M(D,e,t).promise:D.reject(new TypeError("Promise.allSettled must be called with an array"),t)},race:function(e,t){return D.race(e,t)},hash:function(e,t){return null===e||"object"!=typeof e?D.reject(new TypeError("Promise.hash must be called with an object"),t):new F(D,e,t).promise},hashSettled:function(e,t){return null===e||"object"!=typeof e?D.reject(new TypeError("RSVP.hashSettled must be called with an object"),t):new H(D,e,!1,t).promise},rethrow:function(e){throw setTimeout(function(){throw e}),e},defer:function(e){var t={resolve:void 0,reject:void 0};return t.promise=new D(function(e,n){t.resolve=e,t.reject=n},e),t},denodeify:function(e,t){var n=function(){for(var n=arguments.length,r=new Array(n+1),o=!1,i=0;i<n;++i){var s=arguments[i];if(!o){if((o=U(s))===b){var c=b.error;b.error=null;var a=new D(f);return S(a,c),a}o&&!0!==o&&(s=R(o,s))}r[i]=s}var u=new D(f);return r[n]=function(e,n){e?S(u,e):void 0===t?_(u,n):!0===t?_(u,function(e){for(var t=e.length,n=new Array(t-1),r=1;r<t;r++)n[r-1]=e[r];return n}(arguments)):Array.isArray(t)?_(u,function(e,t){for(var n={},r=e.length,o=new Array(r),i=0;i<r;i++)o[i]=e[i];for(var s=0;s<t.length;s++)n[t[s]]=o[s+1];return n}(arguments,t)):_(u,n)},o?function(e,t,n,r){return D.all(t).then(function(t){return N(e,t,n,r)})}(u,r,e,this):N(u,r,e,this)};return n.__proto__=e,n},configure:c,on:le,off:function(){s.off.apply(s,arguments)},resolve:function(e,t){return D.resolve(e,t)},reject:function(e,t){return D.reject(e,t)},map:function(e,t,n){return Array.isArray(e)?"function"!=typeof t?D.reject(new TypeError("RSVP.map expects a function as a second argument"),n):new B(D,e,t,n).promise:D.reject(new TypeError("RSVP.map must be called with an array"),n)}},"async",function(e,t){return s.async(e,t)}),ue(ce,"filter",function(e,t,n){return"function"!=typeof t?D.reject(new TypeError("RSVP.filter expects function as a second argument"),n):D.resolve(e,n).then(function(e){if(!Array.isArray(e))throw new TypeError("RSVP.filter must be called with an array");return new Z(D,e,t,n).promise})}),ce);t.a=de}).call(this,n(1),n(6).setImmediate)},function(e,t,n){!function(t){"use strict";var r={};e.exports?(r.bytesToHex=n(9).bytesToHex,r.convertString=n(10),e.exports=u):(r.bytesToHex=t.convertHex.bytesToHex,r.convertString=t.convertString,t.sha256=u);var o=[];!function(){function e(e){for(var t=Math.sqrt(e),n=2;n<=t;n++)if(!(e%n))return!1;return!0}function t(e){return 4294967296*(e-(0|e))|0}for(var n=2,r=0;r<64;)e(n)&&(o[r]=t(Math.pow(n,1/3)),r++),n++}();var i=function(e){for(var t=[],n=0,r=0;n<e.length;n++,r+=8)t[r>>>5]|=e[n]<<24-r%32;return t},s=function(e){for(var t=[],n=0;n<32*e.length;n+=8)t.push(e[n>>>5]>>>24-n%32&255);return t},c=[],a=function(e,t,n){for(var r=e[0],i=e[1],s=e[2],a=e[3],u=e[4],l=e[5],f=e[6],p=e[7],d=0;d<64;d++){if(d<16)c[d]=0|t[n+d];else{var h=c[d-15],b=(h<<25|h>>>7)^(h<<14|h>>>18)^h>>>3,y=c[d-2],m=(y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10;c[d]=b+c[d-7]+m+c[d-16]}var v=r&i^r&s^i&s,w=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),g=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&l^~u&f)+o[d]+c[d];p=f,f=l,l=u,u=a+g|0,a=s,s=i,i=r,r=g+(w+v)|0}e[0]=e[0]+r|0,e[1]=e[1]+i|0,e[2]=e[2]+s|0,e[3]=e[3]+a|0,e[4]=e[4]+u|0,e[5]=e[5]+l|0,e[6]=e[6]+f|0,e[7]=e[7]+p|0};function u(e,t){e.constructor===String&&(e=r.convertString.UTF8.stringToBytes(e));var n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],o=i(e),c=8*e.length;o[c>>5]|=128<<24-c%32,o[15+(c+64>>9<<4)]=c;for(var u=0;u<o.length;u+=16)a(n,o,u);var l=s(n);return t&&t.asBytes?l:t&&t.asString?r.convertString.bytesToString(l):r.bytesToHex(l)}u.x2=function(e,t){return u(u(e,{asBytes:!0}),t)}}(this)},function(e,t,n){"use strict";n.r(t),n.d(t,"default",function(){return u});var r=n(3),o=n(4),i=n.n(o),s=n(0),c=n.n(s);window.RSVP=r.a;const a={printer:"Zebra-Technologies-ZTC-ZT230-200dpi-ZP",settings:{}};class u{constructor(e){return this.options=Object.assign({},a,e),this.init(),{print:this.print.bind(this)}}init(){this.config||(c.a.api.setSha256Type(function(e){return i()(e)}),this.config=c.a.configs.create(this.options.printer,this.options.settings))}print(e,t="html"){let n=this,r="plain";if("pdf"===t&&(r="file"),c.a.websocket.isActive())if(Array.isArray(e))e.forEach(async e=>{let n=[{type:t,format:r,data:e}];await c.a.print(this.config,n).catch(function(e){console.error(e)})});else{let n=[{type:t,format:r,data:e}];c.a.print(this.config,n).catch(function(e){console.error(e)})}else c.a.websocket.connect().then(function(){n.print(e,t)}).catch(function(e){console.log(e)})}}},function(e,t,n){(function(e){var r=void 0!==e&&e||"undefined"!=typeof self&&self||window,o=Function.prototype.apply;function i(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new i(o.call(setTimeout,r,arguments),clearTimeout)},t.setInterval=function(){return new i(o.call(setInterval,r,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(r,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},n(7),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n(2))},function(e,t,n){(function(e,t){!function(e,n){"use strict";if(!e.setImmediate){var r,o,i,s,c,a=1,u={},l=!1,f=e.document,p=Object.getPrototypeOf&&Object.getPrototypeOf(e);p=p&&p.setTimeout?p:e,"[object process]"==={}.toString.call(e.process)?r=function(e){t.nextTick(function(){h(e)})}:!function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?e.MessageChannel?((i=new MessageChannel).port1.onmessage=function(e){h(e.data)},r=function(e){i.port2.postMessage(e)}):f&&"onreadystatechange"in f.createElement("script")?(o=f.documentElement,r=function(e){var t=f.createElement("script");t.onreadystatechange=function(){h(e),t.onreadystatechange=null,o.removeChild(t),t=null},o.appendChild(t)}):r=function(e){setTimeout(h,0,e)}:(s="setImmediate$"+Math.random()+"$",c=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(s)&&h(+t.data.slice(s.length))},e.addEventListener?e.addEventListener("message",c,!1):e.attachEvent("onmessage",c),r=function(t){e.postMessage(s+t,"*")}),p.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var o={callback:e,args:t};return u[a]=o,r(a),a++},p.clearImmediate=d}function d(e){delete u[e]}function h(e){if(l)setTimeout(h,0,e);else{var t=u[e];if(t){l=!0;try{!function(e){var t=e.callback,r=e.args;switch(r.length){case 0:t();break;case 1:t(r[0]);break;case 2:t(r[0],r[1]);break;case 3:t(r[0],r[1],r[2]);break;default:t.apply(n,r)}}(t)}finally{d(e),l=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n(2),n(1))},function(e,t){},function(e,t,n){!function(t){"use strict";var n={bytesToHex:function(e){return function(e){return e.map(function(e){return t=e.toString(16),n=2,t.length>n?t:Array(n-t.length+1).join("0")+t;var t,n}).join("")}(e)},hexToBytes:function(e){if(e.length%2==1)throw new Error("hexToBytes can't have a string with an odd number of characters.");return 0===e.indexOf("0x")&&(e=e.slice(2)),e.match(/../g).map(function(e){return parseInt(e,16)})}};e.exports?e.exports=n:t.convertHex=n}(this)},function(e,t,n){!function(t){"use strict";var n={bytesToString:function(e){return e.map(function(e){return String.fromCharCode(e)}).join("")},stringToBytes:function(e){return e.split("").map(function(e){return e.charCodeAt(0)})}};n.UTF8={bytesToString:function(e){return decodeURIComponent(escape(n.bytesToString(e)))},stringToBytes:function(e){return n.stringToBytes(unescape(encodeURIComponent(e)))}},e.exports?e.exports=n:t.convertString=n}(this)}])}); //# sourceMappingURL=build.js.map