@mmote/niimbluelib
Version:
Library for the communication with NIIMBOT printers
1 lines • 95.4 kB
JavaScript
"use strict";var niimbluelib=(()=>{var Wt=Object.create;var ae=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var Ht=Object.getOwnPropertyNames,ft=Object.getOwnPropertySymbols,Gt=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable;var bt=(a,e,t)=>e in a?ae(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,Ye=(a,e)=>{for(var t in e||(e={}))mt.call(e,t)&&bt(a,t,e[t]);if(ft)for(var t of ft(e))Vt.call(e,t)&&bt(a,t,e[t]);return a};var Ne=(a,e)=>()=>(a&&(e=a(a=0)),e);var yt=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),wt=(a,e)=>{for(var t in e)ae(a,t,{get:e[t],enumerable:!0})},vt=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ht(e))!mt.call(a,r)&&r!==t&&ae(a,r,{get:()=>e[r],enumerable:!(i=Ct(e,r))||i.enumerable});return a};var Xe=(a,e,t)=>(t=a!=null?Wt(Gt(a)):{},vt(e||!a||!a.__esModule?ae(t,"default",{value:a,enumerable:!0}):t,a)),$t=a=>vt(ae({},"__esModule",{value:!0}),a);var s=(a,e,t)=>new Promise((i,r)=>{var n=c=>{try{u(t.next(c))}catch(p){r(p)}},o=c=>{try{u(t.throw(c))}catch(p){r(p)}},u=c=>c.done?i(c.value):Promise.resolve(c.value).then(n,o);u((t=t.apply(a,e)).next())});var Pt=yt((fi,qe)=>{"use strict";var Rt=Object.prototype.hasOwnProperty,O="~";function se(){}Object.create&&(se.prototype=Object.create(null),new se().__proto__||(O=!1));function jt(a,e,t){this.fn=a,this.context=e,this.once=t||!1}function gt(a,e,t,i,r){if(typeof t!="function")throw new TypeError("The listener must be a function");var n=new jt(t,i||a,r),o=O?O+e:e;return a._events[o]?a._events[o].fn?a._events[o]=[a._events[o],n]:a._events[o].push(n):(a._events[o]=n,a._eventsCount++),a}function Ue(a,e){--a._eventsCount===0?a._events=new se:delete a._events[e]}function N(){this._events=new se,this._eventsCount=0}N.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)Rt.call(t,i)&&e.push(O?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};N.prototype.listeners=function(e){var t=O?O+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var r=0,n=i.length,o=new Array(n);r<n;r++)o[r]=i[r].fn;return o};N.prototype.listenerCount=function(e){var t=O?O+e:e,i=this._events[t];return i?i.fn?1:i.length:0};N.prototype.emit=function(e,t,i,r,n,o){var u=O?O+e:e;if(!this._events[u])return!1;var c=this._events[u],p=arguments.length,P,w;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),p){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,i),!0;case 4:return c.fn.call(c.context,t,i,r),!0;case 5:return c.fn.call(c.context,t,i,r,n),!0;case 6:return c.fn.call(c.context,t,i,r,n,o),!0}for(w=1,P=new Array(p-1);w<p;w++)P[w-1]=arguments[w];c.fn.apply(c.context,P)}else{var _=c.length,g;for(w=0;w<_;w++)switch(c[w].once&&this.removeListener(e,c[w].fn,void 0,!0),p){case 1:c[w].fn.call(c[w].context);break;case 2:c[w].fn.call(c[w].context,t);break;case 3:c[w].fn.call(c[w].context,t,i);break;case 4:c[w].fn.call(c[w].context,t,i,r);break;default:if(!P)for(g=1,P=new Array(p-1);g<p;g++)P[g-1]=arguments[g];c[w].fn.apply(c[w].context,P)}}return!0};N.prototype.on=function(e,t,i){return gt(this,e,t,i,!1)};N.prototype.once=function(e,t,i){return gt(this,e,t,i,!0)};N.prototype.removeListener=function(e,t,i,r){var n=O?O+e:e;if(!this._events[n])return this;if(!t)return Ue(this,n),this;var o=this._events[n];if(o.fn)o.fn===t&&(!r||o.once)&&(!i||o.context===i)&&Ue(this,n);else{for(var u=0,c=[],p=o.length;u<p;u++)(o[u].fn!==t||r&&!o[u].once||i&&o[u].context!==i)&&c.push(o[u]);c.length?this._events[n]=c.length===1?c[0]:c:Ue(this,n)}return this};N.prototype.removeAllListeners=function(e){var t;return e?(t=O?O+e:e,this._events[t]&&Ue(this,t)):(this._events=new se,this._eventsCount=0),this};N.prototype.off=N.prototype.removeListener;N.prototype.addListener=N.prototype.on;N.prefixed=O;N.EventEmitter=N;typeof qe!="undefined"&&(qe.exports=N)});var Z,oe,Yt,Xt,qt,K,Oe,ee,kt,Tt,tt,vi,Zt,ei,ti,ii,it,gi,ce=Ne(()=>{(function(a){a.Unimplemented="UNIMPLEMENTED",a.Unavailable="UNAVAILABLE"})(Z||(Z={}));oe=class extends Error{constructor(e,t,i){super(e),this.message=e,this.code=t,this.data=i}},Yt=a=>{var e,t;return a!=null&&a.androidBridge?"android":!((t=(e=a==null?void 0:a.webkit)===null||e===void 0?void 0:e.messageHandlers)===null||t===void 0)&&t.bridge?"ios":"web"},Xt=a=>{let e=a.CapacitorCustomPlatform||null,t=a.Capacitor||{},i=t.Plugins=t.Plugins||{},r=()=>e!==null?e.name:Yt(a),n=()=>r()!=="web",o=w=>{let _=p.get(w);return!!(_!=null&&_.platforms.has(r())||u(w))},u=w=>{var _;return(_=t.PluginHeaders)===null||_===void 0?void 0:_.find(g=>g.name===w)},c=w=>a.console.error(w),p=new Map,P=(w,_={})=>{let g=p.get(w);if(g)return console.warn(`Capacitor plugin "${w}" already registered. Cannot register plugins twice.`),g.proxy;let L=r(),W=u(w),V,Ke=()=>s(null,null,function*(){return!V&&L in _?V=typeof _[L]=="function"?V=yield _[L]():V=_[L]:e!==null&&!V&&"web"in _&&(V=typeof _.web=="function"?V=yield _.web():V=_.web),V}),Qe=(A,m)=>{var T,S;if(W){let B=W==null?void 0:W.methods.find(F=>m===F.name);if(B)return B.rtype==="promise"?F=>t.nativePromise(w,m.toString(),F):(F,Me)=>t.nativeCallback(w,m.toString(),F,Me);if(A)return(T=A[m])===null||T===void 0?void 0:T.bind(A)}else{if(A)return(S=A[m])===null||S===void 0?void 0:S.bind(A);throw new oe(`"${w}" plugin is not implemented on ${L}`,Z.Unimplemented)}},ne=A=>{let m,T=(...S)=>{let B=Ke().then(F=>{let Me=Qe(F,A);if(Me){let Le=Me(...S);return m=Le==null?void 0:Le.remove,Le}else throw new oe(`"${w}.${A}()" is not implemented on ${L}`,Z.Unimplemented)});return A==="addListener"&&(B.remove=()=>s(null,null,function*(){return m()})),B};return T.toString=()=>`${A.toString()}() { [capacitor code] }`,Object.defineProperty(T,"name",{value:A,writable:!1,configurable:!1}),T},Be=ne("addListener"),Ee=ne("removeListener"),Je=(A,m)=>{let T=Be({eventName:A},m),S=()=>s(null,null,function*(){let F=yield T;Ee({eventName:A,callbackId:F},m)}),B=new Promise(F=>T.then(()=>F({remove:S})));return B.remove=()=>s(null,null,function*(){console.warn("Using addListener() without 'await' is deprecated."),yield S()}),B},y=new Proxy({},{get(A,m){switch(m){case"$$typeof":return;case"toJSON":return()=>({});case"addListener":return W?Je:Be;case"removeListener":return Ee;default:return ne(m)}}});return i[w]=y,p.set(w,{name:w,proxy:y,platforms:new Set([...Object.keys(_),...W?[L]:[]])}),y};return t.convertFileSrc||(t.convertFileSrc=w=>w),t.getPlatform=r,t.handleError=c,t.isNativePlatform=n,t.isPluginAvailable=o,t.registerPlugin=P,t.Exception=oe,t.DEBUG=!!t.DEBUG,t.isLoggingEnabled=!!t.isLoggingEnabled,t},qt=a=>a.Capacitor=Xt(a),K=qt(typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:typeof window!="undefined"?window:typeof global!="undefined"?global:{}),Oe=K.registerPlugin,ee=class{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(e,t){let i=!1;this.listeners[e]||(this.listeners[e]=[],i=!0),this.listeners[e].push(t);let n=this.windowListeners[e];n&&!n.registered&&this.addWindowListener(n),i&&this.sendRetainedArgumentsForEvent(e);let o=()=>s(this,null,function*(){return this.removeListener(e,t)});return Promise.resolve({remove:o})}removeAllListeners(){return s(this,null,function*(){this.listeners={};for(let e in this.windowListeners)this.removeWindowListener(this.windowListeners[e]);this.windowListeners={}})}notifyListeners(e,t,i){let r=this.listeners[e];if(!r){if(i){let n=this.retainedEventArguments[e];n||(n=[]),n.push(t),this.retainedEventArguments[e]=n}return}r.forEach(n=>n(t))}hasListeners(e){return!!this.listeners[e].length}registerWindowListener(e,t){this.windowListeners[t]={registered:!1,windowEventName:e,pluginEventName:t,handler:i=>{this.notifyListeners(t,i)}}}unimplemented(e="not implemented"){return new K.Exception(e,Z.Unimplemented)}unavailable(e="not available"){return new K.Exception(e,Z.Unavailable)}removeListener(e,t){return s(this,null,function*(){let i=this.listeners[e];if(!i)return;let r=i.indexOf(t);this.listeners[e].splice(r,1),this.listeners[e].length||this.removeWindowListener(this.windowListeners[e])})}addWindowListener(e){window.addEventListener(e.windowEventName,e.handler),e.registered=!0}removeWindowListener(e){e&&(window.removeEventListener(e.windowEventName,e.handler),e.registered=!1)}sendRetainedArgumentsForEvent(e){let t=this.retainedEventArguments[e];t&&(delete this.retainedEventArguments[e],t.forEach(i=>{this.notifyListeners(e,i)}))}},kt=a=>encodeURIComponent(a).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),Tt=a=>a.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),tt=class extends ee{getCookies(){return s(this,null,function*(){let e=document.cookie,t={};return e.split(";").forEach(i=>{if(i.length<=0)return;let[r,n]=i.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");r=Tt(r).trim(),n=Tt(n).trim(),t[r]=n}),t})}setCookie(e){return s(this,null,function*(){try{let t=kt(e.key),i=kt(e.value),r=`; expires=${(e.expires||"").replace("expires=","")}`,n=(e.path||"/").replace("path=",""),o=e.url!=null&&e.url.length>0?`domain=${e.url}`:"";document.cookie=`${t}=${i||""}${r}; path=${n}; ${o};`}catch(t){return Promise.reject(t)}})}deleteCookie(e){return s(this,null,function*(){try{document.cookie=`${e.key}=; Max-Age=0`}catch(t){return Promise.reject(t)}})}clearCookies(){return s(this,null,function*(){try{let e=document.cookie.split(";")||[];for(let t of e)document.cookie=t.replace(/^ +/,"").replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(e){return Promise.reject(e)}})}clearAllCookies(){return s(this,null,function*(){try{yield this.clearCookies()}catch(e){return Promise.reject(e)}})}},vi=Oe("CapacitorCookies",{web:()=>new tt}),Zt=a=>s(null,null,function*(){return new Promise((e,t)=>{let i=new FileReader;i.onload=()=>{let r=i.result;e(r.indexOf(",")>=0?r.split(",")[1]:r)},i.onerror=r=>t(r),i.readAsDataURL(a)})}),ei=(a={})=>{let e=Object.keys(a);return Object.keys(a).map(r=>r.toLocaleLowerCase()).reduce((r,n,o)=>(r[n]=a[e[o]],r),{})},ti=(a,e=!0)=>a?Object.entries(a).reduce((i,r)=>{let[n,o]=r,u,c;return Array.isArray(o)?(c="",o.forEach(p=>{u=e?encodeURIComponent(p):p,c+=`${n}=${u}&`}),c.slice(0,-1)):(u=e?encodeURIComponent(o):o,c=`${n}=${u}`),`${i}&${c}`},"").substr(1):null,ii=(a,e={})=>{let t=Object.assign({method:a.method||"GET",headers:a.headers},e),r=ei(a.headers)["content-type"]||"";if(typeof a.data=="string")t.body=a.data;else if(r.includes("application/x-www-form-urlencoded")){let n=new URLSearchParams;for(let[o,u]of Object.entries(a.data||{}))n.set(o,u);t.body=n.toString()}else if(r.includes("multipart/form-data")||a.data instanceof FormData){let n=new FormData;if(a.data instanceof FormData)a.data.forEach((u,c)=>{n.append(c,u)});else for(let u of Object.keys(a.data))n.append(u,a.data[u]);t.body=n;let o=new Headers(t.headers);o.delete("content-type"),t.headers=o}else(r.includes("application/json")||typeof a.data=="object")&&(t.body=JSON.stringify(a.data));return t},it=class extends ee{request(e){return s(this,null,function*(){let t=ii(e,e.webFetchExtra),i=ti(e.params,e.shouldEncodeUrlParams),r=i?`${e.url}?${i}`:e.url,n=yield fetch(r,t),o=n.headers.get("content-type")||"",{responseType:u="text"}=n.ok?e:{};o.includes("application/json")&&(u="json");let c,p;switch(u){case"arraybuffer":case"blob":p=yield n.blob(),c=yield Zt(p);break;case"json":c=yield n.json();break;case"document":case"text":default:c=yield n.text()}let P={};return n.headers.forEach((w,_)=>{P[_]=w}),{data:c,headers:P,status:n.status,url:n.url}})}get(e){return s(this,null,function*(){return this.request(Object.assign(Object.assign({},e),{method:"GET"}))})}post(e){return s(this,null,function*(){return this.request(Object.assign(Object.assign({},e),{method:"POST"}))})}put(e){return s(this,null,function*(){return this.request(Object.assign(Object.assign({},e),{method:"PUT"}))})}patch(e){return s(this,null,function*(){return this.request(Object.assign(Object.assign({},e),{method:"PATCH"}))})}delete(e){return s(this,null,function*(){return this.request(Object.assign(Object.assign({},e),{method:"DELETE"}))})}},gi=Oe("CapacitorHttp",{web:()=>new it})});var nt=yt(rt=>{var Dt;(function(a){typeof DO_NOT_EXPORT_CRC=="undefined"?typeof rt=="object"?a(rt):typeof define=="function"&&define.amd?define(function(){var e={};return a(e),e}):a(Dt={}):a(Dt={})})(function(a){a.version="1.2.2";function e(){for(var y=0,A=new Array(256),m=0;m!=256;++m)y=m,y=y&1?-306674912^y>>>1:y>>>1,y=y&1?-306674912^y>>>1:y>>>1,y=y&1?-306674912^y>>>1:y>>>1,y=y&1?-306674912^y>>>1:y>>>1,y=y&1?-306674912^y>>>1:y>>>1,y=y&1?-306674912^y>>>1:y>>>1,y=y&1?-306674912^y>>>1:y>>>1,y=y&1?-306674912^y>>>1:y>>>1,A[m]=y;return typeof Int32Array!="undefined"?new Int32Array(A):A}var t=e();function i(y){var A=0,m=0,T=0,S=typeof Int32Array!="undefined"?new Int32Array(4096):new Array(4096);for(T=0;T!=256;++T)S[T]=y[T];for(T=0;T!=256;++T)for(m=y[T],A=256+T;A<4096;A+=256)m=S[A]=m>>>8^y[m&255];var B=[];for(T=1;T!=16;++T)B[T-1]=typeof Int32Array!="undefined"?S.subarray(T*256,T*256+256):S.slice(T*256,T*256+256);return B}var r=i(t),n=r[0],o=r[1],u=r[2],c=r[3],p=r[4],P=r[5],w=r[6],_=r[7],g=r[8],L=r[9],W=r[10],V=r[11],Ke=r[12],Qe=r[13],ne=r[14];function Be(y,A){for(var m=A^-1,T=0,S=y.length;T<S;)m=m>>>8^t[(m^y.charCodeAt(T++))&255];return~m}function Ee(y,A){for(var m=A^-1,T=y.length-15,S=0;S<T;)m=ne[y[S++]^m&255]^Qe[y[S++]^m>>8&255]^Ke[y[S++]^m>>16&255]^V[y[S++]^m>>>24]^W[y[S++]]^L[y[S++]]^g[y[S++]]^_[y[S++]]^w[y[S++]]^P[y[S++]]^p[y[S++]]^c[y[S++]]^u[y[S++]]^o[y[S++]]^n[y[S++]]^t[y[S++]];for(T+=15;S<T;)m=m>>>8^t[(m^y[S++])&255];return~m}function Je(y,A){for(var m=A^-1,T=0,S=y.length,B=0,F=0;T<S;)B=y.charCodeAt(T++),B<128?m=m>>>8^t[(m^B)&255]:B<2048?(m=m>>>8^t[(m^(192|B>>6&31))&255],m=m>>>8^t[(m^(128|B&63))&255]):B>=55296&&B<57344?(B=(B&1023)+64,F=y.charCodeAt(T++)&1023,m=m>>>8^t[(m^(240|B>>8&7))&255],m=m>>>8^t[(m^(128|B>>2&63))&255],m=m>>>8^t[(m^(128|F>>6&15|(B&3)<<4))&255],m=m>>>8^t[(m^(128|F&63))&255]):(m=m>>>8^t[(m^(224|B>>12&15))&255],m=m>>>8^t[(m^(128|B>>6&63))&255],m=m>>>8^t[(m^(128|B&63))&255]);return~m}a.table=t,a.bstr=Be,a.buf=Ee,a.str=Je})});function oi(a){return new DataView(Uint8Array.from(a).buffer)}function ci(a){return Array.from(new Uint8Array(a.buffer,a.byteOffset,a.byteLength))}function li(a){return`0000${a.toString(16).padStart(4,"0")}-0000-1000-8000-00805f9b34fb`}function re(a){let e=[],t,i,r=1,n=0;for(t=0;t<a.length;t++)i=a.charCodeAt(t),(i>47&&i<58||i>64&&i<71||i>96&&i<103)&&(n=n<<4^(i>64?i+9:i)&15,(r^=1)&&e.push(n&255));return oi(e)}function Re(a){return ci(a).map(e=>{let t=e.toString(16);return t.length==1&&(t="0"+t),t}).join("")}function Lt(a){if(typeof a=="string")return a;if(typeof a=="number")return li(a);throw new Error("Invalid UUID")}function dt(a){let e={};if(a)return a.forEach((t,i)=>{e[i.toString()]=t}),e}var je=Ne(()=>{});function Nt(a,e,t){return s(this,null,function*(){let i;return Promise.race([a,new Promise((r,n)=>{i=setTimeout(()=>n(t),e)})]).finally(()=>clearTimeout(i))})}var Ut=Ne(()=>{});var Ft={};wt(Ft,{BluetoothLeWeb:()=>pt});var pt,Ot=Ne(()=>{ce();je();Ut();pt=class extends ee{constructor(){super(...arguments),this.deviceMap=new Map,this.discoveredDevices=new Map,this.scan=null,this.DEFAULT_CONNECTION_TIMEOUT=1e4,this.onAdvertisementReceivedCallback=this.onAdvertisementReceived.bind(this),this.onDisconnectedCallback=this.onDisconnected.bind(this),this.onCharacteristicValueChangedCallback=this.onCharacteristicValueChanged.bind(this)}initialize(){return s(this,null,function*(){if(typeof navigator=="undefined"||!navigator.bluetooth)throw this.unavailable("Web Bluetooth API not available in this browser.");if(!(yield navigator.bluetooth.getAvailability()))throw this.unavailable("No Bluetooth radio available.")})}isEnabled(){return s(this,null,function*(){return{value:!0}})}requestEnable(){return s(this,null,function*(){throw this.unavailable("requestEnable is not available on web.")})}enable(){return s(this,null,function*(){throw this.unavailable("enable is not available on web.")})}disable(){return s(this,null,function*(){throw this.unavailable("disable is not available on web.")})}startEnabledNotifications(){return s(this,null,function*(){})}stopEnabledNotifications(){return s(this,null,function*(){})}isLocationEnabled(){return s(this,null,function*(){throw this.unavailable("isLocationEnabled is not available on web.")})}openLocationSettings(){return s(this,null,function*(){throw this.unavailable("openLocationSettings is not available on web.")})}openBluetoothSettings(){return s(this,null,function*(){throw this.unavailable("openBluetoothSettings is not available on web.")})}openAppSettings(){return s(this,null,function*(){throw this.unavailable("openAppSettings is not available on web.")})}setDisplayStrings(){return s(this,null,function*(){})}requestDevice(e){return s(this,null,function*(){let t=this.getFilters(e),i=yield navigator.bluetooth.requestDevice({filters:t.length?t:void 0,optionalServices:e==null?void 0:e.optionalServices,acceptAllDevices:t.length===0});return this.deviceMap.set(i.id,i),this.getBleDevice(i)})}requestLEScan(e){return s(this,null,function*(){this.requestBleDeviceOptions=e;let t=this.getFilters(e);yield this.stopLEScan(),this.discoveredDevices=new Map,navigator.bluetooth.removeEventListener("advertisementreceived",this.onAdvertisementReceivedCallback),navigator.bluetooth.addEventListener("advertisementreceived",this.onAdvertisementReceivedCallback),this.scan=yield navigator.bluetooth.requestLEScan({filters:t.length?t:void 0,acceptAllAdvertisements:t.length===0,keepRepeatedDevices:e==null?void 0:e.allowDuplicates})})}onAdvertisementReceived(e){var t,i;let r=e.device.id;if(this.deviceMap.set(r,e.device),!this.discoveredDevices.has(r)||!((t=this.requestBleDeviceOptions)===null||t===void 0)&&t.allowDuplicates){this.discoveredDevices.set(r,!0);let o=this.getBleDevice(e.device),u={device:o,localName:o.name,rssi:e.rssi,txPower:e.txPower,manufacturerData:dt(e.manufacturerData),serviceData:dt(e.serviceData),uuids:(i=e.uuids)===null||i===void 0?void 0:i.map(Lt)};this.notifyListeners("onScanResult",u)}}stopLEScan(){return s(this,null,function*(){var e;!((e=this.scan)===null||e===void 0)&&e.active&&this.scan.stop(),this.scan=null})}getDevices(e){return s(this,null,function*(){return{devices:(yield navigator.bluetooth.getDevices()).filter(r=>e.deviceIds.includes(r.id)).map(r=>(this.deviceMap.set(r.id,r),this.getBleDevice(r)))}})}getConnectedDevices(e){return s(this,null,function*(){return{devices:(yield navigator.bluetooth.getDevices()).filter(r=>{var n;return(n=r.gatt)===null||n===void 0?void 0:n.connected}).map(r=>(this.deviceMap.set(r.id,r),this.getBleDevice(r)))}})}getBondedDevices(){return s(this,null,function*(){return{}})}connect(e){return s(this,null,function*(){var t,i;let r=this.getDeviceFromMap(e.deviceId);r.removeEventListener("gattserverdisconnected",this.onDisconnectedCallback),r.addEventListener("gattserverdisconnected",this.onDisconnectedCallback);let n=Symbol();if(r.gatt===void 0)throw new Error("No gatt server available.");try{let o=(t=e.timeout)!==null&&t!==void 0?t:this.DEFAULT_CONNECTION_TIMEOUT;yield Nt(r.gatt.connect(),o,n)}catch(o){throw yield(i=r.gatt)===null||i===void 0?void 0:i.disconnect(),o===n?new Error("Connection timeout"):o}})}onDisconnected(e){let i=`disconnected|${e.target.id}`;this.notifyListeners(i,null)}createBond(e){return s(this,null,function*(){throw this.unavailable("createBond is not available on web.")})}isBonded(e){return s(this,null,function*(){throw this.unavailable("isBonded is not available on web.")})}disconnect(e){return s(this,null,function*(){var t;(t=this.getDeviceFromMap(e.deviceId).gatt)===null||t===void 0||t.disconnect()})}getServices(e){return s(this,null,function*(){var t,i;let r=(i=yield(t=this.getDeviceFromMap(e.deviceId).gatt)===null||t===void 0?void 0:t.getPrimaryServices())!==null&&i!==void 0?i:[],n=[];for(let o of r){let u=yield o.getCharacteristics(),c=[];for(let p of u)c.push({uuid:p.uuid,properties:this.getProperties(p),descriptors:yield this.getDescriptors(p)});n.push({uuid:o.uuid,characteristics:c})}return{services:n}})}getDescriptors(e){return s(this,null,function*(){try{return(yield e.getDescriptors()).map(i=>({uuid:i.uuid}))}catch(t){return[]}})}getProperties(e){return{broadcast:e.properties.broadcast,read:e.properties.read,writeWithoutResponse:e.properties.writeWithoutResponse,write:e.properties.write,notify:e.properties.notify,indicate:e.properties.indicate,authenticatedSignedWrites:e.properties.authenticatedSignedWrites,reliableWrite:e.properties.reliableWrite,writableAuxiliaries:e.properties.writableAuxiliaries}}getCharacteristic(e){return s(this,null,function*(){var t;let i=yield(t=this.getDeviceFromMap(e.deviceId).gatt)===null||t===void 0?void 0:t.getPrimaryService(e==null?void 0:e.service);return i==null?void 0:i.getCharacteristic(e==null?void 0:e.characteristic)})}getDescriptor(e){return s(this,null,function*(){let t=yield this.getCharacteristic(e);return t==null?void 0:t.getDescriptor(e==null?void 0:e.descriptor)})}discoverServices(e){return s(this,null,function*(){throw this.unavailable("discoverServices is not available on web.")})}getMtu(e){return s(this,null,function*(){throw this.unavailable("getMtu is not available on web.")})}requestConnectionPriority(e){return s(this,null,function*(){throw this.unavailable("requestConnectionPriority is not available on web.")})}readRssi(e){return s(this,null,function*(){throw this.unavailable("readRssi is not available on web.")})}read(e){return s(this,null,function*(){let t=yield this.getCharacteristic(e);return{value:yield t==null?void 0:t.readValue()}})}write(e){return s(this,null,function*(){let t=yield this.getCharacteristic(e),i;typeof e.value=="string"?i=re(e.value):i=e.value,yield t==null?void 0:t.writeValueWithResponse(i)})}writeWithoutResponse(e){return s(this,null,function*(){let t=yield this.getCharacteristic(e),i;typeof e.value=="string"?i=re(e.value):i=e.value,yield t==null?void 0:t.writeValueWithoutResponse(i)})}readDescriptor(e){return s(this,null,function*(){let t=yield this.getDescriptor(e);return{value:yield t==null?void 0:t.readValue()}})}writeDescriptor(e){return s(this,null,function*(){let t=yield this.getDescriptor(e),i;typeof e.value=="string"?i=re(e.value):i=e.value,yield t==null?void 0:t.writeValue(i)})}startNotifications(e){return s(this,null,function*(){let t=yield this.getCharacteristic(e);t==null||t.removeEventListener("characteristicvaluechanged",this.onCharacteristicValueChangedCallback),t==null||t.addEventListener("characteristicvaluechanged",this.onCharacteristicValueChangedCallback),yield t==null?void 0:t.startNotifications()})}onCharacteristicValueChanged(e){var t,i;let r=e.target,n=`notification|${(t=r.service)===null||t===void 0?void 0:t.device.id}|${(i=r.service)===null||i===void 0?void 0:i.uuid}|${r.uuid}`;this.notifyListeners(n,{value:r.value})}stopNotifications(e){return s(this,null,function*(){let t=yield this.getCharacteristic(e);yield t==null?void 0:t.stopNotifications()})}getFilters(e){var t,i;let r=[];for(let n of(t=e==null?void 0:e.services)!==null&&t!==void 0?t:[])r.push({services:[n],name:e==null?void 0:e.name,namePrefix:e==null?void 0:e.namePrefix});(e!=null&&e.name||e!=null&&e.namePrefix)&&r.length===0&&r.push({name:e.name,namePrefix:e.namePrefix});for(let n of(i=e==null?void 0:e.manufacturerData)!==null&&i!==void 0?i:[])r.push({manufacturerData:[n]});return r}getDeviceFromMap(e){let t=this.deviceMap.get(e);if(t===void 0)throw new Error('Device not found. Call "requestDevice", "requestLEScan" or "getDevices" first.');return t}getBleDevice(e){var t;return{deviceId:e.id,name:(t=e.name)!==null&&t!==void 0?t:void 0}}}});var pi={};wt(pi,{AbstractPrintTask:()=>H,Abstraction:()=>_e,AutoShutdownTime:()=>At,B1PrintTask:()=>Pe,B21V1PrintTask:()=>xe,BatteryChargeLevel:()=>It,ConnectEvent:()=>Q,ConnectResult:()=>ie,D110MV4PrintTask:()=>De,D110PrintTask:()=>ke,DisconnectEvent:()=>j,FirmwareProgressEvent:()=>ve,HeartbeatEvent:()=>me,HeartbeatFailedEvent:()=>ye,HeartbeatType:()=>Ce,ImageEncoder:()=>de,LabelType:()=>ue,NIIMBOT_CLIENT_DEFAULTS:()=>$e,NiimbotAbstractClient:()=>z,NiimbotBluetoothClient:()=>Se,NiimbotCapacitorBleClient:()=>Ae,NiimbotCrc32Packet:()=>G,NiimbotEvent:()=>C,NiimbotPacket:()=>E,NiimbotSerialClient:()=>Ie,OldD11PrintTask:()=>Te,PacketGenerator:()=>b,PacketParser:()=>pe,PacketReceivedEvent:()=>he,PacketSentEvent:()=>fe,PrintError:()=>X,PrintProgressEvent:()=>$,PrinterErrorCode:()=>He,PrinterInfoFetchedEvent:()=>we,PrinterInfoType:()=>st,PrinterModel:()=>ct,RawPacketReceivedEvent:()=>be,RawPacketSentEvent:()=>J,RequestCommandId:()=>le,ResponseCommandId:()=>te,SequentialDataReader:()=>Y,SoundSettingsItemType:()=>St,SoundSettingsType:()=>ot,Utils:()=>v,Validators:()=>I,commandsMap:()=>at,findPrintTask:()=>ut,firmwareExchangePackets:()=>We,getPrinterMetaById:()=>lt,getPrinterMetaByModel:()=>ri,instantiateClient:()=>di,modelPrintTasks:()=>Ge,modelsLibrary:()=>ge,printTaskNames:()=>ai,printTasks:()=>Ve});var Ze=Xe(Pt(),1);var mi=new Error("timeout while waiting for mutex to become available"),yi=new Error("mutex already locked"),zt=new Error("request for lock canceled"),Kt=function(a,e,t,i){function r(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function u(P){try{p(i.next(P))}catch(w){o(w)}}function c(P){try{p(i.throw(P))}catch(w){o(w)}}function p(P){P.done?n(P.value):r(P.value).then(u,c)}p((i=i.apply(a,e||[])).next())})},et=class{constructor(e,t=zt){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((i,r)=>{let n={resolve:i,reject:r,weight:e,priority:t},o=xt(this._queue,u=>t<=u.priority);o===-1&&e<=this._value?this._dispatchItem(n):this._queue.splice(o+1,0,n)})}runExclusive(e){return Kt(this,arguments,void 0,function*(t,i=1,r=0){let[n,o]=yield this.acquire(i,r);try{return yield t(n)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(i=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Qt(this._weightedWaiters[e-1],{resolve:i,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){let t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){let t=this._weightedWaiters[e-1];t&&(t.forEach(i=>i.resolve()),this._weightedWaiters[e-1]=[])}else{let e=this._queue[0].priority;for(let t=this._value;t>0;t--){let i=this._weightedWaiters[t-1];if(!i)continue;let r=i.findIndex(n=>n.priority<=e);(r===-1?i:i.splice(0,r)).forEach(n=>n.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}};function Qt(a,e){let t=xt(a,i=>e.priority<=i.priority);a.splice(t+1,0,e)}function xt(a,e){for(let t=a.length-1;t>=0;t--)if(e(a[t]))return t;return-1}var Jt=function(a,e,t,i){function r(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function u(P){try{p(i.next(P))}catch(w){o(w)}}function c(P){try{p(i.throw(P))}catch(w){o(w)}}function p(P){P.done?n(P.value):r(P.value).then(u,c)}p((i=i.apply(a,e||[])).next())})},Fe=class{constructor(e){this._semaphore=new et(1,e)}acquire(){return Jt(this,arguments,void 0,function*(e=0){let[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}};ce();var v=class a{static numberToHex(e){let t=e.toString(16);return t.length===1?`0${t}`:t}static bufToHex(e,t=" "){return(e instanceof DataView?this.dataViewToNumberArray(e):Array.from(e)).map(r=>a.numberToHex(r)).join(t)}static hexToBuf(e){let t=e.match(/[\da-f]{2}/gi);return t?new Uint8Array(t.map(i=>parseInt(i,16))):new Uint8Array}static dataViewToNumberArray(e){let t=[];for(let i=0;i<e.byteLength;i++)t.push(e.getUint8(i));return t}static dataViewToU8Array(e){return Uint8Array.from(this.dataViewToNumberArray(e))}static u8ArrayToString(e){return new TextDecoder().decode(e)}static countPixelsForBitmapPacket(e,t,i="auto"){let r=0,n=[0,0,0],o=Math.floor(t/8/3),u=e.byteLength<=o*3;if(i==="total"?u=!1:i==="split"&&(e.byteLength>o*3?console.warn(`Can't use split mode: buffer size (${e.byteLength}) is large than chunk size * 3 (${o*3}), maybe printheadPixels is set incorrectly`):u=!0),e.forEach((P,w)=>{let _=Math.floor(w/o);for(let g=0;g<8;g++)if((P&1<<g)!==0){if(r++,!u)continue;if(_>2){console.warn(`Overflow (chunk index ${_})`);continue}n[_]++,n[_]>255&&console.warn("Pixel count overflow")}}),u)return{total:r,parts:n};let[c,p]=this.u16ToBytes(r);return{total:r,parts:[0,p,c]}}static u16ToBytes(e){let t=e>>8&255,i=e%256&255;return[t,i]}static u32ToBytes(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}static bytesToI16(e){return I.u8ArrayLengthEquals(e,2),new DataView(e.buffer).getInt16(0,!1)}static bytesToI32(e){return I.u8ArrayLengthEquals(e,4),new DataView(e.buffer).getInt32(0,!1)}static u8ArraysEqual(e,t){return e.length===t.length&&e.every((i,r)=>i===t[r])}static u8ArrayAppend(e,t){let i=new Uint8Array(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}static sleep(e){return new Promise(t=>setTimeout(t,e))}static isBluetoothSupported(){var e;return typeof((e=navigator.bluetooth)==null?void 0:e.requestDevice)!="undefined"}static isSerialSupported(){var e;return typeof((e=navigator.serial)==null?void 0:e.requestPort)!="undefined"}static getAvailableTransports(){var e,t;return{capacitorBle:K.getPlatform()!=="web",webBluetooth:typeof((e=navigator.bluetooth)==null?void 0:e.requestDevice)!="undefined",webSerial:typeof((t=navigator.serial)==null?void 0:t.requestPort)!="undefined"}}static hasSubarrayAtPos(e,t,i){if(i>e.length-t.length)return!1;for(let r=0;r<t.length;r++)if(e[i+r]!==t[r])return!1;return!0}},I=class{static u8ArraysEqual(e,t,i){if(!v.u8ArraysEqual(e,t))throw new Error(i!=null?i:"Arrays must be equal")}static u8ArrayLengthEquals(e,t,i){if(e.length!==t)throw new Error(i!=null?i:`Array length must be ${t}`)}static u8ArrayLengthAtLeast(e,t,i){if(e.length<t)throw new Error(i!=null?i:`Array length must be at least ${t}`)}};var _t=Xe(nt()),U=class U{constructor(e,t,i=[]){this._command=e,this._data=t instanceof Uint8Array?t:new Uint8Array(t),this._validResponseIds=i,this._oneWay=!1}get dataLength(){return this._data.length}get length(){return U.HEAD.length+1+1+this.dataLength+1+U.TAIL.length}set oneWay(e){this._oneWay=e}get oneWay(){return this._oneWay}get validResponseIds(){return this._validResponseIds}set validResponseIds(e){this._validResponseIds=e}get command(){return this._command}get data(){return this._data}get checksum(){let e=0;return e^=this._command,e^=this._data.length,this._data.forEach(t=>e^=t),e}toBytes(){let e=new ArrayBuffer(U.HEAD.length+1+1+this._data.length+1+U.TAIL.length),t=new Uint8Array(e),i=0;return t.set(U.HEAD,i),i+=U.HEAD.length,t[i]=this._command,i+=1,t[i]=this._data.length,i+=1,t.set(this._data,i),i+=this._data.length,t[i]=this.checksum,i+=1,t.set(U.TAIL,i),this._command===193?new Uint8Array([3,...t]):t}static fromBytes(e){let t=new Uint8Array(e.slice(0,2)),i=new Uint8Array(e.slice(e.length-2)),r=U.HEAD.length+1+1+1+U.TAIL.length;if(e.length<r)throw new Error(`Packet is too small (${e.length} < ${r})`);I.u8ArraysEqual(t,U.HEAD,"Invalid packet head"),I.u8ArraysEqual(i,U.TAIL,"Invalid packet tail");let n=e[2],o=e[3];if(e.length!==r+o)throw new Error(`Invalid packet size (${e.length} < ${r+o})`);let u=e.slice(4,4+o),c=e[4+o],p=new U(n,u);if(p.checksum!==c)throw new Error(`Invalid packet checksum (${p.checksum} !== ${c})`);return p}};U.HEAD=new Uint8Array([85,85]),U.TAIL=new Uint8Array([170,170]);var E=U,G=class a extends E{constructor(e,t,i,r=[]){super(e,i,r),this._chunkNumber=t}get chunkNumber(){return this._chunkNumber}get checksum(){let e=[this._command,...v.u16ToBytes(this._chunkNumber),this._data.length,...this._data];return _t.default.buf(e)}static fromBytes(e){let t=new Uint8Array(e.slice(0,2)),i=new Uint8Array(e.slice(e.length-2)),r=E.HEAD.length+1+2+1+4+E.TAIL.length;if(e.length<r)throw new Error(`Packet is too small (${e.length} < ${r})`);I.u8ArraysEqual(t,E.HEAD,"Invalid packet head"),I.u8ArraysEqual(i,E.TAIL,"Invalid packet tail");let n=e[2],o=v.bytesToI16(e.slice(3,5)),u=e[5];if(e.length!==r+u)throw new Error(`Invalid packet size (${e.length} < ${r+u})`);let c=e.slice(6,6+u),p=v.bytesToI32(e.slice(6+u,6+u+4)),P=new a(n,o,c);if(P.checksum!==p)throw new Error(`Invalid packet checksum (${P.checksum} !== ${p})`);return P}toBytes(){let e=new ArrayBuffer(E.HEAD.length+1+2+1+this._data.length+4+E.TAIL.length),t=new Uint8Array(e),i=0;t.set(E.HEAD,i),i+=E.HEAD.length,t[i]=this._command,i+=1;let[r,n]=v.u16ToBytes(this._chunkNumber);t[i]=r,i+=1,t[i]=n,i+=1,t[i]=this._data.length,i+=1,t.set(this._data,i),i+=this._data.length;let o=this.checksum;return t[i]=o>>24&255,i+=1,t[i]=o>>16&255,i+=1,t[i]=o>>8&255,i+=1,t[i]=o&255,i+=1,t.set(E.TAIL,i),t}};var le=(d=>(d[d.Invalid=-1]="Invalid",d[d.Connect=193]="Connect",d[d.CancelPrint=218]="CancelPrint",d[d.CalibrateHeight=89]="CalibrateHeight",d[d.Heartbeat=220]="Heartbeat",d[d.LabelPositioningCalibration=142]="LabelPositioningCalibration",d[d.PageEnd=227]="PageEnd",d[d.PrinterLog=5]="PrinterLog",d[d.PageStart=3]="PageStart",d[d.PrintBitmapRow=133]="PrintBitmapRow",d[d.PrintBitmapRowIndexed=131]="PrintBitmapRowIndexed",d[d.PrintClear=32]="PrintClear",d[d.PrintEmptyRow=132]="PrintEmptyRow",d[d.PrintEnd=243]="PrintEnd",d[d.PrinterInfo=64]="PrinterInfo",d[d.PrinterConfig=175]="PrinterConfig",d[d.PrinterStatusData=165]="PrinterStatusData",d[d.PrinterReset=40]="PrinterReset",d[d.PrintQuantity=21]="PrintQuantity",d[d.PrintStart=1]="PrintStart",d[d.PrintStatus=163]="PrintStatus",d[d.RfidInfo=26]="RfidInfo",d[d.RfidInfo2=28]="RfidInfo2",d[d.RfidSuccessTimes=84]="RfidSuccessTimes",d[d.SetAutoShutdownTime=39]="SetAutoShutdownTime",d[d.SetDensity=33]="SetDensity",d[d.SetLabelType=35]="SetLabelType",d[d.SetPageSize=19]="SetPageSize",d[d.SoundSettings=88]="SoundSettings",d[d.AntiFake=11]="AntiFake",d[d.WriteRFID=112]="WriteRFID",d[d.PrintTestPage=90]="PrintTestPage",d[d.StartFirmwareUpgrade=245]="StartFirmwareUpgrade",d[d.FirmwareCrc=145]="FirmwareCrc",d[d.FirmwareCommit=146]="FirmwareCommit",d[d.FirmwareChunk=155]="FirmwareChunk",d[d.FirmwareNoMoreChunks=156]="FirmwareNoMoreChunks",d[d.PrinterCheckLine=134]="PrinterCheckLine",d[d.GetCurrentTimeFormat=18]="GetCurrentTimeFormat",d[d.PrinterConfig2=7]="PrinterConfig2",d[d.GetKeyFunction=9]="GetKeyFunction",d[d.GetPrintQuality=13]="GetPrintQuality",d[d.GetPrinterConfigurationWifi=162]="GetPrinterConfigurationWifi",d))(le||{}),te=(l=>(l[l.In_Invalid=-1]="In_Invalid",l[l.In_NotSupported=0]="In_NotSupported",l[l.In_Connect=194]="In_Connect",l[l.In_CalibrateHeight=105]="In_CalibrateHeight",l[l.In_CancelPrint=208]="In_CancelPrint",l[l.In_AntiFake=12]="In_AntiFake",l[l.In_HeartbeatAdvanced1=221]="In_HeartbeatAdvanced1",l[l.In_HeartbeatBasic=222]="In_HeartbeatBasic",l[l.In_HeartbeatUnknown=223]="In_HeartbeatUnknown",l[l.In_HeartbeatAdvanced2=217]="In_HeartbeatAdvanced2",l[l.In_LabelPositioningCalibration=143]="In_LabelPositioningCalibration",l[l.In_PageStart=4]="In_PageStart",l[l.In_PrintClear=48]="In_PrintClear",l[l.In_PrinterCheckLine=211]="In_PrinterCheckLine",l[l.In_PrintEnd=244]="In_PrintEnd",l[l.In_PrinterConfig=191]="In_PrinterConfig",l[l.In_PrinterLog=6]="In_PrinterLog",l[l.In_PrinterInfoAutoShutDownTime=71]="In_PrinterInfoAutoShutDownTime",l[l.In_PrinterInfoBluetoothAddress=77]="In_PrinterInfoBluetoothAddress",l[l.In_PrinterInfoSpeed=66]="In_PrinterInfoSpeed",l[l.In_PrinterInfoDensity=65]="In_PrinterInfoDensity",l[l.In_PrinterInfoLanguage=70]="In_PrinterInfoLanguage",l[l.In_PrinterInfoChargeLevel=74]="In_PrinterInfoChargeLevel",l[l.In_PrinterInfoHardWareVersion=76]="In_PrinterInfoHardWareVersion",l[l.In_PrinterInfoLabelType=67]="In_PrinterInfoLabelType",l[l.In_PrinterInfoPrinterCode=72]="In_PrinterInfoPrinterCode",l[l.In_PrinterInfoSerialNumber=75]="In_PrinterInfoSerialNumber",l[l.In_PrinterInfoSoftWareVersion=73]="In_PrinterInfoSoftWareVersion",l[l.In_PrinterInfoArea=79]="In_PrinterInfoArea",l[l.In_PrinterStatusData=181]="In_PrinterStatusData",l[l.In_PrinterReset=56]="In_PrinterReset",l[l.In_PrintStatus=179]="In_PrintStatus",l[l.In_PrintError=219]="In_PrintError",l[l.In_PrintQuantity=22]="In_PrintQuantity",l[l.In_PrintStart=2]="In_PrintStart",l[l.In_RfidInfo=27]="In_RfidInfo",l[l.In_RfidInfo2=29]="In_RfidInfo2",l[l.In_RfidSuccessTimes=100]="In_RfidSuccessTimes",l[l.In_SetAutoShutdownTime=55]="In_SetAutoShutdownTime",l[l.In_SetDensity=49]="In_SetDensity",l[l.In_SetLabelType=51]="In_SetLabelType",l[l.In_SetPageSize=20]="In_SetPageSize",l[l.In_SoundSettings=104]="In_SoundSettings",l[l.In_PageEnd=228]="In_PageEnd",l[l.In_PrinterPageIndex=224]="In_PrinterPageIndex",l[l.In_PrintTestPage=106]="In_PrintTestPage",l[l.In_WriteRFID=113]="In_WriteRFID",l[l.In_StartFirmwareUpgrade=246]="In_StartFirmwareUpgrade",l[l.In_RequestFirmwareCrc=144]="In_RequestFirmwareCrc",l[l.In_RequestFirmwareChunk=154]="In_RequestFirmwareChunk",l[l.In_FirmwareCheckResult=157]="In_FirmwareCheckResult",l[l.In_FirmwareResult=158]="In_FirmwareResult",l[l.In_ResetTimeout=198]="In_ResetTimeout",l[l.In_GetCurrentTimeFormat=17]="In_GetCurrentTimeFormat",l[l.In_PrinterConfig2=8]="In_PrinterConfig2",l[l.In_GetKeyFunction=10]="In_GetKeyFunction",l[l.In_GetPrintQuality=13]="In_GetPrintQuality",l[l.In_GetPrinterConfigurationWifi=178]="In_GetPrinterConfigurationWifi",l))(te||{}),k=le,x=te,at={[k.Invalid]:null,[k.PrintBitmapRow]:null,[k.PrintBitmapRowIndexed]:null,[k.PrintEmptyRow]:null,[k.Connect]:[x.In_Connect],[k.CancelPrint]:[x.In_CancelPrint],[k.CalibrateHeight]:[x.In_CalibrateHeight],[k.Heartbeat]:[x.In_HeartbeatBasic,x.In_HeartbeatUnknown,x.In_HeartbeatAdvanced1,x.In_HeartbeatAdvanced2],[k.LabelPositioningCalibration]:[x.In_LabelPositioningCalibration],[k.PageEnd]:[x.In_PageEnd],[k.PrinterLog]:[x.In_PrinterLog],[k.PageStart]:[x.In_PageStart],[k.PrintClear]:[x.In_PrintClear],[k.PrintEnd]:[x.In_PrintEnd],[k.PrinterInfo]:[x.In_PrinterInfoArea,x.In_PrinterInfoAutoShutDownTime,x.In_PrinterInfoBluetoothAddress,x.In_PrinterInfoChargeLevel,x.In_PrinterInfoDensity,x.In_PrinterInfoHardWareVersion,x.In_PrinterInfoLabelType,x.In_PrinterInfoLanguage,x.In_PrinterInfoPrinterCode,x.In_PrinterInfoSerialNumber,x.In_PrinterInfoSoftWareVersion,x.In_PrinterInfoSpeed],[k.PrinterConfig]:[x.In_PrinterConfig],[k.PrinterStatusData]:[x.In_PrinterStatusData],[k.PrinterReset]:[x.In_PrinterReset],[k.PrintQuantity]:[x.In_PrintQuantity],[k.PrintStart]:[x.In_PrintStart],[k.PrintStatus]:[x.In_PrintStatus],[k.RfidInfo]:[x.In_RfidInfo],[k.RfidInfo2]:[x.In_RfidInfo2],[k.RfidSuccessTimes]:[x.In_RfidSuccessTimes],[k.SetAutoShutdownTime]:[x.In_SetAutoShutdownTime],[k.SetDensity]:[x.In_SetDensity],[k.SetLabelType]:[x.In_SetLabelType],[k.SetPageSize]:[x.In_SetPageSize],[k.SoundSettings]:[x.In_SoundSettings],[k.AntiFake]:[x.In_AntiFake],[k.WriteRFID]:[x.In_WriteRFID],[k.PrintTestPage]:[x.In_PrintTestPage],[k.StartFirmwareUpgrade]:[x.In_StartFirmwareUpgrade],[k.FirmwareCrc]:null,[k.FirmwareChunk]:null,[k.FirmwareNoMoreChunks]:null,[k.FirmwareCommit]:null,[k.PrinterCheckLine]:[x.In_PrinterCheckLine],[k.GetCurrentTimeFormat]:[x.In_GetCurrentTimeFormat],[k.PrinterConfig2]:[x.In_PrinterConfig2],[k.GetKeyFunction]:[x.In_GetKeyFunction],[k.GetPrintQuality]:[x.In_GetPrintQuality],[k.GetPrinterConfigurationWifi]:[x.In_GetPrinterConfigurationWifi]},We={tx:[k.FirmwareChunk,k.FirmwareCrc,k.FirmwareNoMoreChunks,k.FirmwareCommit],rx:[x.In_RequestFirmwareCrc,x.In_RequestFirmwareChunk,x.In_FirmwareCheckResult,x.In_FirmwareResult]};var st=(g=>(g[g.Density=1]="Density",g[g.Speed=2]="Speed",g[g.LabelType=3]="LabelType",g[g.Language=6]="Language",g[g.AutoShutdownTime=7]="AutoShutdownTime",g[g.PrinterModelId=8]="PrinterModelId",g[g.SoftWareVersion=9]="SoftWareVersion",g[g.BatteryChargeLevel=10]="BatteryChargeLevel",g[g.SerialNumber=11]="SerialNumber",g[g.HardWareVersion=12]="HardWareVersion",g[g.BluetoothAddress=13]="BluetoothAddress",g[g.PrintMode=14]="PrintMode",g[g.Area=15]="Area",g))(st||{}),ot=(t=>(t[t.SetSound=1]="SetSound",t[t.GetSoundState=2]="GetSoundState",t))(ot||{}),St=(t=>(t[t.BluetoothConnectionSound=1]="BluetoothConnectionSound",t[t.PowerSound=2]="PowerSound",t))(St||{}),ue=(p=>(p[p.Invalid=0]="Invalid",p[p.WithGaps=1]="WithGaps",p[p.Black=2]="Black",p[p.Continuous=3]="Continuous",p[p.Perforated=4]="Perforated",p[p.Transparent=5]="Transparent",p[p.PvcTag=6]="PvcTag",p[p.BlackMarkGap=10]="BlackMarkGap",p[p.HeatShrinkTube=11]="HeatShrinkTube",p))(ue||{}),Ce=(r=>(r[r.Advanced1=1]="Advanced1",r[r.Basic=2]="Basic",r[r.Unknown=3]="Unknown",r[r.Advanced2=4]="Advanced2",r))(Ce||{}),At=(r=>(r[r.ShutdownTime1=1]="ShutdownTime1",r[r.ShutdownTime2=2]="ShutdownTime2",r[r.ShutdownTime3=3]="ShutdownTime3",r[r.ShutdownTime4=4]="ShutdownTime4",r))(At||{}),It=(n=>(n[n.Charge0=0]="Charge0",n[n.Charge25=1]="Charge25",n[n.Charge50=2]="Charge50",n[n.Charge75=3]="Charge75",n[n.Charge100=4]="Charge100",n))(It||{}),ie=(n=>(n[n.Disconnect=0]="Disconnect",n[n.Connected=1]="Connected",n[n.ConnectedNew=2]="ConnectedNew",n[n.ConnectedV3=3]="ConnectedV3",n[n.FirmwareErrors=90]="FirmwareErrors",n))(ie||{}),He=(h=>(h[h.CoverOpen=1]="CoverOpen",h[h.LackPaper=2]="LackPaper",h[h.LowBattery=3]="LowBattery",h[h.BatteryException=4]="BatteryException",h[h.UserCancel=5]="UserCancel",h[h.DataError=6]="DataError",h[h.Overheat=7]="Overheat",h[h.PaperOutException=8]="PaperOutException",h[h.PrinterBusy=9]="PrinterBusy",h[h.NoPrinterHead=10]="NoPrinterHead",h[h.TemperatureLow=11]="TemperatureLow",h[h.PrinterHeadLoose=12]="PrinterHeadLoose",h[h.NoRibbon=13]="NoRibbon",h[h.WrongRibbon=14]="WrongRibbon",h[h.UsedRibbon=15]="UsedRibbon",h[h.WrongPaper=16]="WrongPaper",h[h.SetPaperFail=17]="SetPaperFail",h[h.SetPrintModeFail=18]="SetPrintModeFail",h[h.SetPrintDensityFail=19]="SetPrintDensityFail",h[h.WriteRfidFail=20]="WriteRfidFail",h[h.SetMarginFail=21]="SetMarginFail",h[h.CommunicationException=22]="CommunicationException",h[h.Disconnect=23]="Disconnect",h[h.CanvasParameterError=24]="CanvasParameterError",h[h.RotationParameterException=25]="RotationParameterException",h[h.JsonParameterException=26]="JsonParameterException",h[h.B3sAbnormalPaperOutput=27]="B3sAbnormalPaperOutput",h[h.ECheckPaper=28]="ECheckPaper",h[h.RfidTagNotWritten=29]="RfidTagNotWritten",h[h.SetPrintDensityNoSupport=30]="SetPrintDensityNoSupport",h[h.SetPrintModeNoSupport=31]="SetPrintModeNoSupport",h[h.SetPrintLabelMaterialError=32]="SetPrintLabelMaterialError",h[h.SetPrintLabelMaterialNoSupport=33]="SetPrintLabelMaterialNoSupport",h[h.NotSupportWrittenRfid=34]="NotSupportWrittenRfid",h[h.IllegalPage=50]="IllegalPage",h[h.IllegalRibbonPage=51]="IllegalRibbonPage",h[h.ReceiveDataTimeout=52]="ReceiveDataTimeout",h[h.NonDedicatedRibbon=53]="NonDedicatedRibbon",h))(He||{});var de=class a{static encodeCanvas(e,t="left"){let r=e.getContext("2d").getImageData(0,0,e.width,e.height),n=[],o=e.width,u=e.height;if(t==="left"&&(o=e.height,u=e.width),o%8!==0)throw new Error("Column count must be multiple of 8");for(let c=0;c<u;c++){let p=!0,P=0,w=new Uint8Array(o/8);for(let g=0;g<o/8;g++){let L=0;for(let W=0;W<8;W++)a.isPixelNonWhite(r,g*8+W,c,t)&&(L|=1<<7-W,p=!1,P++);w[g]=L}let _={dataType:p?"void":"pixels",rowNumber:c,repeat:1,rowData:p?void 0:w,blackPixelsCount:P};if(n.length===0)n.push(_);else{let g=n[n.length-1],L=_.dataType===g.dataType;L&&_.dataType==="pixels"&&(L=v.u8ArraysEqual(_.rowData,g.rowData)),L?g.repeat++:n.push(_),c%200===199&&n.push({dataType:"check",rowNumber:c,repeat:0,rowData:void 0,blackPixelsCount:0})}}return{cols:o,rows:u,rowsData:n}}static isPixelNonWhite(e,t,i,r="left"){let n=i*e.width+t;return r==="left"&&(n=(e.height-1-t)*e.width+i),n*=4,e.data[n]!==255||e.data[n+1]!==255||e.data[n+2]!==255}static indexPixels(e){let t=[];for(let i=0;i<e.byteLength;i++){let r=e[i];for(let n=0;n<8;n++)r&1<<7-n&&t.push(...v.u16ToBytes(i*8+n))}return new Uint8Array(t)}};var b=class{static mapped(e,t=[1]){let i=at[e];if(i===null){let r=new E(e,t);return r.oneWay=!0,r}return new E(e,t,i)}static connect(){return this.mapped(193)}static getPrinterStatusData(){return this.mapped(165)}static rfidInfo(){return this.mapped(26)}static rfidInfo2(){return this.mapped(28)}static antiFake(e){return this.mapped(11,[e])}static setAutoShutDownTime(e){return this.mapped(39,[e])}static getPrinterInfo(e){return this.mapped(64,[e])}static setSoundSettings(e,t){return this.mapped(88,[1,e,t?1:0])}static getSoundSettings(e){return this.mapped(88,[2,e,1])}static heartbeat(e){return this.mapped(220,[e])}static setDensity(e){return this.mapped(33,[e])}static setLabelType(e){return this.mapped(35,[e])}static setPageSize2b(e){return this.mapped(19,[...v.u16ToBytes(e)])}static setPageSize4b(e,t){return this.mapped(19,[...v.u16ToBytes(e),...v.u16ToBytes(t)])}static setPageSize6b(e,t,i){return this.mapped(19,[...v.u16ToBytes(e),...v.u16ToBytes(t),...v.u16ToBytes(i)])}static setPageSize13b(e,t,i,r=0,n=0,o=0,u=0){return this.mapped(19,[...v.u16ToBytes(e),...v.u16ToBytes(t),...v.u16ToBytes(i),...v.u16ToBytes(r),n,0,o,...v.u16ToBytes(u)])}static setPrintQuantity(e){return this.mapped(21,[...v.u16ToBytes(e)])}static printStatus(){return this.mapped(163)}static printerReset(){return this.mapped(40)}static printStart1b(){return this.mapped(1)}static printStart2b(e){return this.mapped(1,[...v.u16ToBytes(e)])}static printStart7b(e,t=0){return this.mapped(1,[...v.u16ToBytes(e),0,0,0,0,t])}static printStart9b(e,t=0,i=0,r=!1){return this.mapped(1,[...v.u16ToBytes(e),0,0,0,0,t,i,r?1:0])}static printEnd(){return this.mapped(243)}static pageStart(){return this.mapped(3)}static pageEnd(){return this.mapped(227)}static printEmptySpace(e,t){return this.mapped(132,[...v.u16ToBytes(e),t])}static printBitmapRow(e,t,i,r,n="auto"){let o=v.countPixelsForBitmapPacket(i,r,n);return this.mapped(133,[...v.u16ToBytes(e),...o.parts,t,...i])}static printBitmapRowIndexed(e,t,i,r,n="auto"){let o=v.countPixelsForBitmapPacket(i,r!=null?r:0,n),u=de.indexPixels(i);if(o.total>6)throw new Error(`Black pixel count > 6 (${o.total})`);return this.mapped(131,[...v.u16ToBytes(e),...o.parts,t,...u])}static printClear(){return this.mapped(32)}static writeRfid(e){return this.mapped(112,e)}static checkLine(e){return this.mapped(134,[...v.u16ToBytes(e),1])}static writeImageData(e,t){var r,n,o,u;let i=[];for(let c of e.rowsData){if(c.dataType==="pixels"){c.blackPixelsCount<=6&&!(t!=null&&t.noIndexPacket)?i.push(this.printBitmapRowIndexed(c.rowNumber,c.repeat,c.rowData,(r=t==null?void 0:t.printheadPixels)!=null?r:0,(n=t==null?void 0:t.countsMode)!=null?n:"auto")):i.push(this.printBitmapRow(c.rowNumber,c.repeat,c.rowData,(o=t==null?void 0:t.printheadPixels)!=null?o:0,(u=t==null?void 0:t.countsMode)!=null?u:"auto"));continue}if(c.dataType==="check"&&(t!=null&&t.enableCheckLine)){i.push(this.checkLine(c.rowNumber));continue}c.dataType==="void"&&i.push(this.printEmptySpace(c.rowNumber,c.repeat))}return i}static printTestPage(){return this.mapped(90)}static labelPositioningCalibration(e){return this.mapped(142,[e])}static startFirmwareUpgrade(e){if(!/^\d+\.\d+$/.test(e))throw new Error("Invalid version format (x.x expected)");let[t,i]=e.split(".").map(r=>parseInt(r));return this.mapped(245,[t,i])}static sendFirmwareChecksum(e){let t=new G(145,0,[...v.u32ToBytes(e)]);return t.oneWay=!0,t}static sendFirmwareChunk(e,t){let i=new G(155,e,t);return i.oneWay=!0,i}static firmwareNoMoreChunks(){let e=new G(156,0,[1]);return e.oneWay=!0,e}static firmwareCommit(){let e=new G(146,0,[1]);return e.oneWay=!0,e}};var pe=class{static parsePacketBundle(e){let t=[],i=e.byteLength;for(;e.byteLength>0&&!(!v.hasSubarrayAtPos(e,E.HEAD,0)||e.byteLength<3);){let n=e[2],o=E,u=3,c=1;if((We.rx.includes(n)||We.tx.includes(n))&&(o=G,u=5,c=4),e.byteLength<=u)break;let p=e[u];if(e.byteLength<=u+p+c+E.TAIL.byteLength)break;let P=u+p+c+1;if(!v.hasSubarrayAtPos(e,E.TAIL,P)){console.warn("Invalid tail");break}let w=P+E.TAIL.byteLength;t.push({cls:o,raw:e.slice(0,w)}),e=e.slice(w)}let r=t.reduce((n,o)=>n+o.raw.length,0);if(i!==r)throw new Error(`Splitted chunks data length not equals buffer length (${i} !== ${r})`);return t.map(n=>n.cls.fromBytes(n.raw))}};var C=class{constructor(e){this.type=e}},Q=class extends C{constructor(e){super("connect"),this.info=e}},j=class extends C{constructor(){super("disconnect")}},he=class extends C{constructor(e){super("packetreceived"),this.packet=e}},fe=class extends C{constructor(e){super("packetsent"),this.packet=e}},J=class extends C{constructor(e){super("rawpacketsent"),this.data=e}},be=class extends C{constructor(e){super("rawpacketreceived"),this.data=e}},me=class extends C{constructor(e){super("heartbeat"),this.data=e}},ye=class extends C{constructor(e){super("heartbeatfailed"),this.failedAttempts=e}},we=class extends C{constructor(e){super("printerinfofetched"),this.info=e}},$=class extends C{constructor(e,t,i,r){super("printprogress"),this.page=e,this.pagesTotal=t,this.pagePrintProgress=i,this.pageFeedProgress=r}},ve=class extends C{c