@danidoble/webserial 4.3.2 → 4.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var I=u=>{throw TypeError(u)};var R=(u,n,e)=>n in u?L(u,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[n]=e;var P=(u,n,e)=>R(u,typeof n!="symbol"?n+"":n,e),x=(u,n,e)=>n.has(u)||I("Cannot "+e);var g=(u,n,e)=>(x(u,n,"read from private field"),e?e.call(u):n.get(u)),B=(u,n,e)=>n.has(u)?I("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(u):n.set(u,e),E=(u,n,e,s)=>(x(u,n,"write to private field"),s?s.call(u,e):n.set(u,e),e),a=(u,n,e)=>(x(u,n,"access private method"),e);const f=require("./webserial-core-DlH0cFSH.cjs");function j(u=100){return new Promise(n=>setTimeout(()=>n(),u))}function q(){return"serial"in navigator}function J(){return"geolocation"in navigator}function H(){return"crypto"in window}function K(u=1){return u*1e3}function W(u){return u==null||u===""}var k,M,r,N,U,o,F,m,h,C,l,T,S;const t=class t{static status(n=null){var s,i;if(!a(s=t,r,o).call(s,n))return!1;let e=[];switch(g(t,k)){case"locker":e=["0","8"];break;case"boardroid":e=["2",(5+g(t,M)).toString(16).toUpperCase()];break;case"jofemar":e=["6"];break;default:return!1}a(i=t,r,l).call(i,e)}static dispensed(n=null){var s,i;if(!a(s=t,r,o).call(s,n))return!1;let e=[];switch(g(t,k)){case"locker":e=["0","7","4","4","4"];break;case"boardroid":e=["2","D7","A","0","0","0","0","0","0","0","0","0","F2"];break;case"jofemar":e=["6","30"];break;default:return!1}a(i=t,r,l).call(i,e)}static notDispensed(n=null){var s,i;if(!a(s=t,r,o).call(s,n))return!1;let e=[];switch(g(t,k)){case"locker":e=["0","7","5","5","5"];break;case"boardroid":e=["2","D7","A","0","0","1","0","0","0","0","0","0","F2"];break;case"jofemar":e=["6","34"];break;default:return!1}a(i=t,r,l).call(i,e)}static gateInactive(n=null){var e;if(!a(e=t,r,o).call(e,n)||!a(this,r,F).call(this))return!1;a(this,r,l).call(this,["0","7","5","5","5"])}static gateConfigured(n=null){var e;if(!a(e=t,r,o).call(e,n)||!a(this,r,F).call(this))return!1;a(this,r,l).call(this,["0","6"])}static keyPressed(n=null){var c,b,p;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,h).call(b))return!1;const e=["30","31","32","33","34","35","36","37","38","39","2A","23","41","42","43","44"],s=(128+g(t,M)).toString(16),i=Math.floor(Math.random()*15);a(p=t,r,l).call(p,["2",s,"54",e[i]])}static doorOpened(n=null){var i,c;if(!a(i=t,r,o).call(i,n)||!a(this,r,C).call(this))return!1;let e=[];const s=(128+g(t,M)).toString(16);switch(g(t,k)){case"boardroid":e=["2","D8","dc"];break;case"jofemar":e=["2",s,"50","4F"];break}a(c=t,r,l).call(c,e)}static doorClosed(n=null){var i,c;if(!a(i=t,r,o).call(i,n)||!a(this,r,C).call(this))return!1;let e=[];const s=(128+g(t,M)).toString(16);switch(g(t,k)){case"boardroid":e=["2","D8","db"];break;case"jofemar":e=["2",s,"50","43"];break}a(c=t,r,l).call(c,e)}static channelDisconnected(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","43","43","FD"])}static channelConnected(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","43","43","FC"])}static channelEmpty(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","43","43","FF"])}static workingTemperature(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","54","16"])}static currentTemperature(n=null){var i,c,b;if(!a(i=t,r,o).call(i,n)||!a(c=t,r,C).call(c))return!1;let e=[];const s=(128+g(t,M)).toString(16);switch(g(t,k)){case"boardroid":e=["2","D9","44","30"];break;case"jofemar":e=["2",s,"43","74","2B","30","39","2E","31","7F","43"];break}a(b=t,r,l).call(b,e)}static ready(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","30"])}static busy(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","31"])}static invalidTray(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","32"])}static invalidChannel(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","33"])}static emptyChannel(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","34"])}static elevatorJam(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","35"])}static elevatorMalfunction(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","36"])}static phototransistorFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","37"])}static allChannelsEmpty(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","38"])}static productDetectorFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","39"])}static displayDisconnected(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","41"])}static productUnderElevator(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","42"])}static elevatorSettingAlarm(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","43"])}static buttonPanelFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","44"])}static errorWritingEeprom(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","45"])}static errorControlTemperature(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","46"])}static thermometerDisconnected(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","47"])}static thermometerMisconfigured(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","48"])}static thermometerFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","49"])}static errorExtractorConsumption(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4A"])}static channelSearchError(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4B"])}static productExitMouthSearchError(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4C"])}static elevatorInteriorLocked(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4D"])}static productDetectorVerifierError(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4E"])}static waitingForProductRecall(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4F"])}static productExpiredByTemperature(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","50"])}static faultyAutomaticDoor(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","51"])}static rejectLever(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","A0","1"])}static resetCoinPurse(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","A0","2"])}static coinInsertedBox(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["40","41","42","43","44","45"],i=a(p=t,r,T).call(p,s,e);a(d=t,r,l).call(d,["2","A0",i])}static coinInsertedTube(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["50","51","52","53","54","55"],i=a(p=t,r,T).call(p,s,e);a(d=t,r,l).call(d,["2","A0",i])}static banknoteInsertedStacker(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["80","81","82","83","84"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteInsertedEscrow(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["90","91","92","93","94"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteEjected(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["A0","A1","A2","A3","A4"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteInsertedRecycler(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["B0","B1","B2","B3","B4"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteTaken(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","B0","2a"])}static coinPurseEnabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D0","1"])}static coinPurseDisabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D0","0"])}static billPurseDisabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D1","0","0"])}static billPurseEnabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D1","1","1"])}static readTubes(n=null){var y,D,w;if(!a(y=t,r,o).call(y,n)||!a(D=t,r,m).call(D))return!1;const e=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f"],[s,i,c,b,p,d]=[e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)]];a(w=t,r,l).call(w,["2","D2",s,i,c,b,p,d])}static readBillPurse(n=null,e=null){var i,c,b,p;if(!a(i=t,r,o).call(i,n)||!a(c=t,r,m).call(c))return!1;let s=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c"];if(n._recycler.ict){const d=s[Math.floor(Math.random()*31)];let y="0",D="0",w="0",v="0",_="0";if(e!==null&&!isNaN(parseInt(e)))switch(e.toString()){case"20":y=d;break;case"50":D=d;break;case"100":w=d;break;case"200":v=d;break;case"500":_=d;break}else switch(n._recycler.bill){case 0:y=d;break;case 1:D=d;break;case 2:w=d;break;case 3:v=d;break;case 4:_=d;break}a(b=t,r,l).call(b,["2","D3",y,D,w,v,_,"0"])}else{const[d,y,D,w,v,_]=[s[Math.floor(Math.random()*30)],s[Math.floor(Math.random()*30)],s[Math.floor(Math.random()*30)],s[Math.floor(Math.random()*2)],s[Math.floor(Math.random())],s[Math.floor(Math.random())]];a(p=t,r,l).call(p,["2","D3",d,y,D,w,v,_])}}static banknoteAccepted(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D4","1"])}static banknoteRejected(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D4","0"])}static banknotesDispensed(n=null){var s,i,c,b;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,m).call(i))return!1;let e=["1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c"];if(n._recycler.ict){const p=e[Math.floor(Math.random()*30)];let d="0",y="0",D="0",w="0",v="0";switch(n._recycler.bill){case 0:d=p;break;case 1:y=p;break;case 2:D=p;break;case 3:w=p;break;case 4:v=p;break}a(c=t,r,l).call(c,["2","D5",d,y,D,w,v,"0"])}else{const[p,d,y,D,w,v]=[e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*2)],e[Math.floor(Math.random())],e[Math.floor(Math.random())]];a(b=t,r,l).call(b,["2","D5",p,d,y,D,w,v])}}static coinsDispensed(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D6"])}static relayOn(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DA","1"])}static relayOff(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DA","0"])}static nayaxEnabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","1"])}static nayaxDisabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","0"])}static nayaxPreCreditAuthorized(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","3"])}static nayaxCancelRequest(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","4"])}static nayaxSellApproved(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","5"])}static nayaxSellDenied(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","6"])}static nayaxEndSession(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","7"])}static nayaxCancelled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","8"])}static nayaxDispensed(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","A","0"])}static nayaxNotDispensed(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","A","1"])}static fullTray(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4F"])}static setConnection(n=null){var e;if(!a(e=t,r,o).call(e,n))return!1;n.__internal__.serial.connected=!0}};k=new WeakMap,M=new WeakMap,r=new WeakSet,N=function(){if(t.enable===!1)throw new Error("Emulator is disabled");return t.enable},U=function(n){if(typeof n!="object"||!(n instanceof O))throw new Error(`Type ${n.typeDevice} is not supported`);return t.instance=n,E(t,k,n.typeDevice),E(t,M,n.deviceNumber),!0},o=function(n=null){var e,s;return!a(e=t,r,N).call(e)||n===null&&t.instance===null?!1:(t.instance===null&&a(s=t,r,U).call(s,n),!0)},F=function(){if(g(t,k)!=="locker")throw new Error("This function is only available for Locker devices");return!0},m=function(){if(g(t,k)!=="boardroid")throw new Error("This function is only available for Boardroid devices");return!0},h=function(){if(g(t,k)!=="jofemar")throw new Error("This function is only available for Jofemar devices");return!0},C=function(){if(g(t,k)==="locker")throw new Error("This function is not available for Locker devices");return!0},l=function(n){t.instance.__emulate({code:n})},T=function(n,e=null){let s=n[Math.floor(Math.random()*5)];if(e!==null&&!isNaN(parseFloat(e)))switch(e.toString()){case"0.5":s=n[1];break;case"1":s=n[2];break;case"2":s=n[3];break;case"5":s=n[4];break;case"10":s=n[5];break}return s},S=function(n,e=null){let s=n[Math.floor(Math.random()*4)];if(e!==null&&!isNaN(parseFloat(e)))switch(e.toString()){case"20":s=n[0];break;case"50":s=n[1];break;case"100":s=n[2];break;case"200":s=n[3];break;case"500":s=n[4];break}return s},B(t,r),P(t,"enable",!1),P(t,"instance",null),B(t,k,null),B(t,M,1);let A=t;f.h.instance||(f.h.instance=new f.h);const G={relay:[],locker:[],jofemar:[],boardroid:[],arduino:[],pinpad:[],pinpax:[],hopper:[]};f.h.devices={...f.h.devices,...G};f.h.addCustom=(u,n)=>{f.h.registerType(u),f.h.add(n)};f.h.getCustomByUuid=(u,n)=>f.h.get(u,n);f.h.getJofemarByUuid=u=>f.h.get("jofemar",u);f.h.getLockerByUuid=u=>f.h.get("locker",u);f.h.getRelayByUuid=u=>f.h.get("relay",u);f.h.getBoardroidByUuid=u=>f.h.get("boardroid",u);f.h.getArduinoByUuid=u=>f.h.get("arduino",u);f.h.getPinPadByUuid=u=>f.h.get("pinpad",u);f.h.getPinPaxByUuid=u=>f.h.get("pinpax",u);f.h.getHopperByUuid=u=>f.h.get("hopper",u);f.h.getJofemar=(u=1)=>f.h.getByNumber("jofemar",u);f.h.getBoardroid=(u=1)=>f.h.getByNumber("boardroid",u);f.h.getLocker=(u=1)=>f.h.getByNumber("locker",u);f.h.getRelay=(u=1)=>f.h.getByNumber("relay",u);f.h.getArduino=(u=1)=>f.h.getByNumber("arduino",u);f.h.getPinPad=(u=1)=>f.h.getByNumber("pinpad",u);f.h.getPinPax=(u=1)=>f.h.getByNumber("pinpax",u);f.h.getHopper=(u=1)=>f.h.getByNumber("hopper",u);class O extends f.K{constructor(n){super(n),this.__internal__=structuredClone(this.__internal__),this.getResponseAsArrayHex(),this.__internal__.device.door_open=!1,this.__internal__.time.response_engines=2e3,this.__internal__.time.sense=100,this.__internal__.interval.waiting_sense=0,this.__internal__.dispense={must_response:!1,dispensing:!1,status:null,counter:0,limit_counter:20,custom_limit_counter:null,backup_dispense:{}}}get isDoorOpen(){return this.__internal__.device.door_open}get isDispensing(){return this.__internal__.interval.waiting_sense||this.__internal__.dispense.dispensing}async timeout(n,e){await super.timeout(n,e),e==="dispense"&&(this.__internal__.dispense.status="no-response")}async serialPortsSaved(n){const e=this.serialFilters;if(this.__internal__.aux_port_connector<n.length){const s=this.__internal__.aux_port_connector;this.__internal__.serial.port=n[s]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:e});if(!this.__internal__.serial.port)throw new Error("Select another port please")}internalClearSensing(){this.__internal__.interval.waiting_sense&&clearInterval(this.__internal__.interval.waiting_sense),this.__internal__.interval.waiting_sense=0,this.__internal__.dispense.status=null,this.__internal__.dispense.counter=0,this.__internal__.dispense.dispensing=!1}internalDispensingProcess(){let n=this.__internal__.dispense.limit_counter;return this.__internal__.dispense.custom_limit_counter&&(n=this.__internal__.dispense.custom_limit_counter),n+=Math.ceil(n*.6),this.__internal__.dispense.counter>=n?(this.internalClearSensing(),this.__internal__.dispense.status=!1,this.__internal__.dispense.dispensing=!1,!1):(this.__internal__.dispense.counter=parseFloat((.1+this.__internal__.dispense.counter).toFixed(1)),this.__internal__.dispense.counter%1===0&&this.dispatch("dispensing",{status:this.__internal__.dispense.status,counter:this.__internal__.dispense.counter,limit:n}),null)}async internalDispenseStatus(){if(this.__internal__.dispense.must_response&&(await j(this.__internal__.time.response_engines+10),this.__internal__.dispense.status==="no-response"))return this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-response"}),{status:!1,error:"no-response"};this.__internal__.dispense.status=null,this.__internal__.dispense.dispensing=!0,this.dispatch("internal:dispense:running",{});const n=this;return new Promise(e=>{this.__internal__.interval.waiting_sense=setInterval(()=>{switch(n.__internal__.dispense.status){case null:n.internalDispensingProcess()===!1&&(n.internalClearSensing(),n.dispatch("not-dispensed",{reason:"timeout"}),e({status:!1,error:"timeout"}));break;case!0:n.internalClearSensing(),n.__internal__.dispense.status=!0,n.dispatch("dispensed",{}),e({status:!0,error:null});break;case!1:n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"no-stock"}),e({status:!1,error:null});break;case"elevator-locked":n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"elevator-locked"}),e({status:!1,error:"elevator-locked"});break;case"no-response":n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"no-response"}),e({status:!1,error:"no-response"});break}},this.__internal__.time.sense)})}async internalDispense(n){if(this.isDispensing)throw new Error("Another dispensing process is running");if(!A.enable&&!this.__internal__.serial.connected&&(await this.serialConnect(),!this.__internal__.serial.connected))throw new Error("Serial device not connected");return this.__internal__.serial.queue.length===0?(await this.appendToQueue(n,"dispense"),await this.internalDispenseStatus()):new Promise(e=>{const s=setInterval(async()=>{if(this.__internal__.serial.queue.length>0)return;clearInterval(s),await this.appendToQueue(n,"dispense");const i=await this.internalDispenseStatus();e(i)},100)})}__emulate(n){if(typeof n.code!="object"){console.error("Invalid data to make an emulation");return}this.__internal__.serial.connected||(this.__internal__.serial.connected=!0,this.dispatch("serial:connected"),f.h.instance.dispatch("change"),this.__internal__.interval.reconnection&&(clearInterval(this.__internal__.interval.reconnection),this.__internal__.interval.reconnection=0)),this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0);const e=[];for(const s in n.code)e.push(n.code[s].toString().padStart(2,"0").toLowerCase());this.serialMessage(e)}set listenOnPort(n){this.listenOnChannel=n}get listenOnPort(){return this.__internal__.device.listen_on_port??1}}exports.Emulator=A;exports.Kernel=O;exports.getSeconds=K;exports.isEmpty=W;exports.supportCrypto=H;exports.supportGeolocation=J;exports.supportWebSerial=q;exports.wait=j;
1
+ "use strict";var L=Object.defineProperty;var I=u=>{throw TypeError(u)};var R=(u,n,e)=>n in u?L(u,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[n]=e;var x=(u,n,e)=>R(u,typeof n!="symbol"?n+"":n,e),A=(u,n,e)=>n.has(u)||I("Cannot "+e);var g=(u,n,e)=>(A(u,n,"read from private field"),e?e.call(u):n.get(u)),B=(u,n,e)=>n.has(u)?I("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(u):n.set(u,e),E=(u,n,e,s)=>(A(u,n,"write to private field"),s?s.call(u,e):n.set(u,e),e),a=(u,n,e)=>(A(u,n,"access private method"),e);const f=require("./webserial-core-5B5nYtyR.cjs");function j(u=100){return new Promise(n=>setTimeout(()=>n(),u))}function q(){return"serial"in navigator}function J(){return"geolocation"in navigator}function H(){return"crypto"in window}function K(u=1){return u*1e3}function W(u){return u==null||u===""}var k,M,r,N,O,o,F,m,h,C,l,T,S;const t=class t{static status(n=null){var s,i;if(!a(s=t,r,o).call(s,n))return!1;let e=[];switch(g(t,k)){case"locker":e=["0","8"];break;case"boardroid":e=["2",(5+g(t,M)).toString(16).toUpperCase()];break;case"jofemar":e=["6"];break;default:return!1}a(i=t,r,l).call(i,e)}static dispensed(n=null){var s,i;if(!a(s=t,r,o).call(s,n))return!1;let e=[];switch(g(t,k)){case"locker":e=["0","7","4","4","4"];break;case"boardroid":e=["2","D7","A","0","0","0","0","0","0","0","0","0","F2"];break;case"jofemar":e=["6","30"];break;default:return!1}a(i=t,r,l).call(i,e)}static notDispensed(n=null){var s,i;if(!a(s=t,r,o).call(s,n))return!1;let e=[];switch(g(t,k)){case"locker":e=["0","7","5","5","5"];break;case"boardroid":e=["2","D7","A","0","0","1","0","0","0","0","0","0","F2"];break;case"jofemar":e=["6","34"];break;default:return!1}a(i=t,r,l).call(i,e)}static gateInactive(n=null){var e;if(!a(e=t,r,o).call(e,n)||!a(this,r,F).call(this))return!1;a(this,r,l).call(this,["0","7","5","5","5"])}static gateConfigured(n=null){var e;if(!a(e=t,r,o).call(e,n)||!a(this,r,F).call(this))return!1;a(this,r,l).call(this,["0","6"])}static keyPressed(n=null){var c,b,p;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,h).call(b))return!1;const e=["30","31","32","33","34","35","36","37","38","39","2A","23","41","42","43","44"],s=(128+g(t,M)).toString(16),i=Math.floor(Math.random()*15);a(p=t,r,l).call(p,["2",s,"54",e[i]])}static doorOpened(n=null){var i,c;if(!a(i=t,r,o).call(i,n)||!a(this,r,C).call(this))return!1;let e=[];const s=(128+g(t,M)).toString(16);switch(g(t,k)){case"boardroid":e=["2","D8","dc"];break;case"jofemar":e=["2",s,"50","4F"];break}a(c=t,r,l).call(c,e)}static doorClosed(n=null){var i,c;if(!a(i=t,r,o).call(i,n)||!a(this,r,C).call(this))return!1;let e=[];const s=(128+g(t,M)).toString(16);switch(g(t,k)){case"boardroid":e=["2","D8","db"];break;case"jofemar":e=["2",s,"50","43"];break}a(c=t,r,l).call(c,e)}static channelDisconnected(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","43","43","FD"])}static channelConnected(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","43","43","FC"])}static channelEmpty(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","43","43","FF"])}static workingTemperature(n=null){var s,i,c;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,h).call(i))return!1;const e=(128+g(t,M)).toString(16);a(c=t,r,l).call(c,["2",e,"43","54","16"])}static currentTemperature(n=null){var i,c,b;if(!a(i=t,r,o).call(i,n)||!a(c=t,r,C).call(c))return!1;let e=[];const s=(128+g(t,M)).toString(16);switch(g(t,k)){case"boardroid":e=["2","D9","44","30"];break;case"jofemar":e=["2",s,"43","74","2B","30","39","2E","31","7F","43"];break}a(b=t,r,l).call(b,e)}static ready(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","30"])}static busy(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","31"])}static invalidTray(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","32"])}static invalidChannel(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","33"])}static emptyChannel(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","34"])}static elevatorJam(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","35"])}static elevatorMalfunction(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","36"])}static phototransistorFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","37"])}static allChannelsEmpty(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","38"])}static productDetectorFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","39"])}static displayDisconnected(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","41"])}static productUnderElevator(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","42"])}static elevatorSettingAlarm(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","43"])}static buttonPanelFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","44"])}static errorWritingEeprom(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","45"])}static errorControlTemperature(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","46"])}static thermometerDisconnected(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","47"])}static thermometerMisconfigured(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","48"])}static thermometerFailure(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","49"])}static errorExtractorConsumption(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4A"])}static channelSearchError(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4B"])}static productExitMouthSearchError(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4C"])}static elevatorInteriorLocked(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4D"])}static productDetectorVerifierError(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4E"])}static waitingForProductRecall(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4F"])}static productExpiredByTemperature(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","50"])}static faultyAutomaticDoor(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","51"])}static rejectLever(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","A0","1"])}static resetCoinPurse(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","A0","2"])}static coinInsertedBox(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["40","41","42","43","44","45"],i=a(p=t,r,T).call(p,s,e);a(d=t,r,l).call(d,["2","A0",i])}static coinInsertedTube(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["50","51","52","53","54","55"],i=a(p=t,r,T).call(p,s,e);a(d=t,r,l).call(d,["2","A0",i])}static banknoteInsertedStacker(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["80","81","82","83","84"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteInsertedEscrow(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["90","91","92","93","94"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteEjected(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["A0","A1","A2","A3","A4"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteInsertedRecycler(n=null,e=null){var c,b,p,d;if(!a(c=t,r,o).call(c,n)||!a(b=t,r,m).call(b))return!1;const s=["B0","B1","B2","B3","B4"],i=a(p=t,r,S).call(p,s,e);a(d=t,r,l).call(d,["2","B0",i])}static banknoteTaken(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","B0","2a"])}static coinPurseEnabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D0","1"])}static coinPurseDisabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D0","0"])}static billPurseDisabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D1","0","0"])}static billPurseEnabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D1","1","1"])}static readTubes(n=null){var y,D,w;if(!a(y=t,r,o).call(y,n)||!a(D=t,r,m).call(D))return!1;const e=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f"],[s,i,c,b,p,d]=[e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)]];a(w=t,r,l).call(w,["2","D2",s,i,c,b,p,d])}static readBillPurse(n=null,e=null){var i,c,b,p;if(!a(i=t,r,o).call(i,n)||!a(c=t,r,m).call(c))return!1;let s=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c"];if(n._recycler.ict){const d=s[Math.floor(Math.random()*31)];let y="0",D="0",w="0",v="0",_="0";if(e!==null&&!isNaN(parseInt(e)))switch(e.toString()){case"20":y=d;break;case"50":D=d;break;case"100":w=d;break;case"200":v=d;break;case"500":_=d;break}else switch(n._recycler.bill){case 0:y=d;break;case 1:D=d;break;case 2:w=d;break;case 3:v=d;break;case 4:_=d;break}a(b=t,r,l).call(b,["2","D3",y,D,w,v,_,"0"])}else{const[d,y,D,w,v,_]=[s[Math.floor(Math.random()*30)],s[Math.floor(Math.random()*30)],s[Math.floor(Math.random()*30)],s[Math.floor(Math.random()*2)],s[Math.floor(Math.random())],s[Math.floor(Math.random())]];a(p=t,r,l).call(p,["2","D3",d,y,D,w,v,_])}}static banknoteAccepted(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D4","1"])}static banknoteRejected(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D4","0"])}static banknotesDispensed(n=null){var s,i,c,b;if(!a(s=t,r,o).call(s,n)||!a(i=t,r,m).call(i))return!1;let e=["1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c"];if(n._recycler.ict){const p=e[Math.floor(Math.random()*30)];let d="0",y="0",D="0",w="0",v="0";switch(n._recycler.bill){case 0:d=p;break;case 1:y=p;break;case 2:D=p;break;case 3:w=p;break;case 4:v=p;break}a(c=t,r,l).call(c,["2","D5",d,y,D,w,v,"0"])}else{const[p,d,y,D,w,v]=[e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*30)],e[Math.floor(Math.random()*2)],e[Math.floor(Math.random())],e[Math.floor(Math.random())]];a(b=t,r,l).call(b,["2","D5",p,d,y,D,w,v])}}static coinsDispensed(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","D6"])}static relayOn(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DA","1"])}static relayOff(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DA","0"])}static nayaxEnabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","1"])}static nayaxDisabled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","0"])}static nayaxPreCreditAuthorized(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","3"])}static nayaxCancelRequest(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","4"])}static nayaxSellApproved(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","5"])}static nayaxSellDenied(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","6"])}static nayaxEndSession(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","7"])}static nayaxCancelled(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","8"])}static nayaxDispensed(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","A","0"])}static nayaxNotDispensed(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,m).call(s))return!1;a(i=t,r,l).call(i,["2","DD","A","1"])}static fullTray(n=null){var e,s,i;if(!a(e=t,r,o).call(e,n)||!a(s=t,r,h).call(s))return!1;a(i=t,r,l).call(i,["6","4F"])}static setConnection(n=null){var e;if(!a(e=t,r,o).call(e,n))return!1;n.__internal__.serial.connected=!0}};k=new WeakMap,M=new WeakMap,r=new WeakSet,N=function(){if(t.enable===!1)throw new Error("Emulator is disabled");return t.enable},O=function(n){if(typeof n!="object"||!(n instanceof U))throw new Error(`Type ${n.typeDevice} is not supported`);return t.instance=n,E(t,k,n.typeDevice),E(t,M,n.deviceNumber),!0},o=function(n=null){var e,s;return!a(e=t,r,N).call(e)||n===null&&t.instance===null?!1:(t.instance===null&&a(s=t,r,O).call(s,n),!0)},F=function(){if(g(t,k)!=="locker")throw new Error("This function is only available for Locker devices");return!0},m=function(){if(g(t,k)!=="boardroid")throw new Error("This function is only available for Boardroid devices");return!0},h=function(){if(g(t,k)!=="jofemar")throw new Error("This function is only available for Jofemar devices");return!0},C=function(){if(g(t,k)==="locker")throw new Error("This function is not available for Locker devices");return!0},l=function(n){t.instance.__emulate({code:n})},T=function(n,e=null){let s=n[Math.floor(Math.random()*5)];if(e!==null&&!isNaN(parseFloat(e)))switch(e.toString()){case"0.5":s=n[1];break;case"1":s=n[2];break;case"2":s=n[3];break;case"5":s=n[4];break;case"10":s=n[5];break}return s},S=function(n,e=null){let s=n[Math.floor(Math.random()*4)];if(e!==null&&!isNaN(parseFloat(e)))switch(e.toString()){case"20":s=n[0];break;case"50":s=n[1];break;case"100":s=n[2];break;case"200":s=n[3];break;case"500":s=n[4];break}return s},B(t,r),x(t,"enable",!1),x(t,"instance",null),B(t,k,null),B(t,M,1);let P=t;f.h.instance||(f.h.instance=new f.h);const G={relay:[],locker:[],jofemar:[],boardroid:[],pinpad:[],pinpax:[],hopper:[]};f.h.devices={...f.h.devices,...G};f.h.addCustom=(u,n)=>{f.h.registerType(u),f.h.add(n)};f.h.getCustomByUuid=(u,n)=>f.h.get(u,n);f.h.getJofemarByUuid=u=>f.h.get("jofemar",u);f.h.getLockerByUuid=u=>f.h.get("locker",u);f.h.getRelayByUuid=u=>f.h.get("relay",u);f.h.getBoardroidByUuid=u=>f.h.get("boardroid",u);f.h.getPinPadByUuid=u=>f.h.get("pinpad",u);f.h.getPinPaxByUuid=u=>f.h.get("pinpax",u);f.h.getHopperByUuid=u=>f.h.get("hopper",u);f.h.getJofemar=(u=1)=>f.h.getByNumber("jofemar",u);f.h.getBoardroid=(u=1)=>f.h.getByNumber("boardroid",u);f.h.getLocker=(u=1)=>f.h.getByNumber("locker",u);f.h.getRelay=(u=1)=>f.h.getByNumber("relay",u);f.h.getPinPad=(u=1)=>f.h.getByNumber("pinpad",u);f.h.getPinPax=(u=1)=>f.h.getByNumber("pinpax",u);f.h.getHopper=(u=1)=>f.h.getByNumber("hopper",u);class U extends f.K{constructor(n){super(n),this.__internal__=structuredClone(this.__internal__),this.getResponseAsArrayHex(),this.__internal__.device.door_open=!1,this.__internal__.time.response_engines=2e3,this.__internal__.time.sense=100,this.__internal__.interval.waiting_sense=0,this.__internal__.dispense={must_response:!1,dispensing:!1,status:null,counter:0,limit_counter:20,custom_limit_counter:null,backup_dispense:{}}}get isDoorOpen(){return this.__internal__.device.door_open}get isDispensing(){return this.__internal__.interval.waiting_sense||this.__internal__.dispense.dispensing}async timeout(n,e){await super.timeout(n,e),e==="dispense"&&(this.__internal__.dispense.status="no-response")}async serialPortsSaved(n){const e=this.serialFilters;if(this.__internal__.aux_port_connector<n.length){const s=this.__internal__.aux_port_connector;this.__internal__.serial.port=n[s]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:e});if(!this.__internal__.serial.port)throw new Error("Select another port please")}internalClearSensing(){this.__internal__.interval.waiting_sense&&clearInterval(this.__internal__.interval.waiting_sense),this.__internal__.interval.waiting_sense=0,this.__internal__.dispense.status=null,this.__internal__.dispense.counter=0,this.__internal__.dispense.dispensing=!1}internalDispensingProcess(){let n=this.__internal__.dispense.limit_counter;return this.__internal__.dispense.custom_limit_counter&&(n=this.__internal__.dispense.custom_limit_counter),n+=Math.ceil(n*.6),this.__internal__.dispense.counter>=n?(this.internalClearSensing(),this.__internal__.dispense.status=!1,this.__internal__.dispense.dispensing=!1,!1):(this.__internal__.dispense.counter=parseFloat((.1+this.__internal__.dispense.counter).toFixed(1)),this.__internal__.dispense.counter%1===0&&this.dispatch("dispensing",{status:this.__internal__.dispense.status,counter:this.__internal__.dispense.counter,limit:n}),null)}async internalDispenseStatus(){if(this.__internal__.dispense.must_response&&(await j(this.__internal__.time.response_engines+10),this.__internal__.dispense.status==="no-response"))return this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-response"}),{status:!1,error:"no-response"};this.__internal__.dispense.status=null,this.__internal__.dispense.dispensing=!0,this.dispatch("internal:dispense:running",{});const n=this;return new Promise(e=>{this.__internal__.interval.waiting_sense=setInterval(()=>{switch(n.__internal__.dispense.status){case null:n.internalDispensingProcess()===!1&&(n.internalClearSensing(),n.dispatch("not-dispensed",{reason:"timeout"}),e({status:!1,error:"timeout"}));break;case!0:n.internalClearSensing(),n.__internal__.dispense.status=!0,n.dispatch("dispensed",{}),e({status:!0,error:null});break;case!1:n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"no-stock"}),e({status:!1,error:null});break;case"elevator-locked":n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"elevator-locked"}),e({status:!1,error:"elevator-locked"});break;case"no-response":n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"no-response"}),e({status:!1,error:"no-response"});break}},this.__internal__.time.sense)})}async internalDispense(n){if(this.isDispensing)throw new Error("Another dispensing process is running");if(!P.enable&&!this.__internal__.serial.connected&&(await this.serialConnect(),!this.__internal__.serial.connected))throw new Error("Serial device not connected");return this.__internal__.serial.queue.length===0?(await this.appendToQueue(n,"dispense"),await this.internalDispenseStatus()):new Promise(e=>{const s=setInterval(async()=>{if(this.__internal__.serial.queue.length>0)return;clearInterval(s),await this.appendToQueue(n,"dispense");const i=await this.internalDispenseStatus();e(i)},100)})}__emulate(n){if(typeof n.code!="object"){console.error("Invalid data to make an emulation");return}this.__internal__.serial.connected||(this.__internal__.serial.connected=!0,this.dispatch("serial:connected"),f.h.instance.dispatch("change"),this.__internal__.interval.reconnection&&(clearInterval(this.__internal__.interval.reconnection),this.__internal__.interval.reconnection=0)),this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0);const e=[];for(const s in n.code)e.push(n.code[s].toString().padStart(2,"0").toLowerCase());this.serialMessage(e)}set listenOnPort(n){this.listenOnChannel=n}get listenOnPort(){return this.__internal__.device.listen_on_port??1}}exports.Emulator=P;exports.Kernel=U;exports.getSeconds=K;exports.isEmpty=W;exports.supportCrypto=H;exports.supportGeolocation=J;exports.supportWebSerial=q;exports.wait=j;
package/dist/kernel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-DlsHh4AG.cjs"),r=require("./webserial-core-DlH0cFSH.cjs");/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-CzkmE_OW.cjs"),r=require("./webserial-core-5B5nYtyR.cjs");/**
2
2
  * @license Webserial
3
3
  * webserial
4
4
  *
package/dist/kernel.js CHANGED
@@ -1,5 +1,5 @@
1
- import { K as s } from "./kernel-IUeiZp8d.js";
2
- import { h as n } from "./webserial-core-DGKQCs5a.js";
1
+ import { K as s } from "./kernel-BblykfpT.js";
2
+ import { h as n } from "./webserial-core-ByrJ7tlu.js";
3
3
  /**
4
4
  * @license Webserial
5
5
  * webserial
package/dist/locker.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var y=l=>{throw TypeError(l)};var w=(l,c,e)=>c.has(l)||y("Cannot "+e);var r=(l,c,e)=>(w(l,c,"read from private field"),e?e.call(l):c.get(l)),u=(l,c,e)=>c.has(l)?y("Cannot add the same private member more than once"):c instanceof WeakSet?c.add(l):c.set(l,e),i=(l,c,e,s)=>(w(l,c,"write to private field"),s?s.call(l,e):c.set(l,e),e),n=(l,c,e)=>(w(l,c,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./kernel-DlsHh4AG.cjs"),d=require("./relay-BsUsBpOv.cjs"),v=require("./webserial-core-DlH0cFSH.cjs");var h,a,o,t,C,_,f,g,b,k,T;class A extends m.Kernel{constructor({filters:e=null,config_port:s=null,no_device:p=1,device_listen_on_port:q=3}={}){super({filters:e,config_port:s,no_device:p,device_listen_on_port:q});u(this,t);u(this,h,!1);u(this,a,0);u(this,o,0);if(this.__internal__.device.type="locker",v.h.getCustom(this.typeDevice,p))throw new Error(`Device ${this.typeDevice} ${p} already exists`);this.__internal__.time.response_engines=1e3,this.__internal__.device.milliseconds=666,this.__internal__.dispense.limit_counter=1,v.h.add(this),n(this,t,C).call(this)}serialMessage(e){const s={code:e,name:null,description:null,request:null,no_code:0};switch(e[1]){case"08":s.name="Connection with the serial device completed.",s.description="Your connection with the serial device was successfully completed.",s.request="connect",s.no_code=100;break;case"07":switch(e[4]){case"00":s.name="Cell closed.",s.description="The selected cell is closed.",s.request="dispense",s.no_code=1102,this.__internal__.dispense.status=!1,this.dispatch("dispensed",{}),r(this,h)&&r(this,a)>=89?(s.finished_test=!0,i(this,h,!1),i(this,a,0)):r(this,h)&&(s.finished_test=!1);break;case"01":case"04":s.name="Cell open.",s.description="The selected cell was open successfully.",s.request="dispense",s.no_code=102,this.__internal__.dispense.status=!0,this.dispatch("dispensed",{}),r(this,h)&&r(this,a)>=89?(s.finished_test=!0,i(this,h,!1),i(this,a,0)):r(this,h)&&(s.finished_test=!1);break;case"05":s.name="Cell inactive.",s.description="The selected cell is inactive or doesn't exist.",s.request="dispense",s.no_code=101,this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{}),r(this,h)&&r(this,a)>=89?(s.finished_test=!0,i(this,h,!1),i(this,a,0)):r(this,h)&&(s.finished_test=!1);break}break;case"06":s.name="Configuration applied.",s.description="The configuration was successfully applied.",s.request="configure cell",s.no_code=103;break;default:s.request="undefined",s.name="Response unrecognized",s.description="The response of application was received, but dont identify with any of current parameters",s.no_code=400;break}this.dispatch("serial:message",s)}serialSetConnectionConstant(e=3){return d.u.connection({channel:e})}async dispense({cell:e=1,status:s=!0}={}){return setTimeout(()=>{s===!0?n(this,t,k).call(this):n(this,t,T).call(this)},this.__internal__.time.response_engines/2),await this.internalDispense(d.u.openCell({cell:e,channel:this.__internal__.device.listen_on_port}))}async status({cell:e=1}={}){return await this.appendToQueue(d.u.statusCell({cell:e,channel:this.__internal__.device.listen_on_port}),"status")}async lightScan({since:e=0,until:s=10}={}){return await this.appendToQueue(d.u.lightScan({channel:this.__internal__.device.listen_on_port,since:e,until:s}),"light-scan")}async enable({cell:e=1}={}){return await this.appendToQueue(d.u.enableCell({cell:e,channel:this.__internal__.device.listen_on_port}),"activate")}async disable({cell:e=1}={}){await this.appendToQueue(d.u.disableCell({cell:e,channel:this.__internal__.device.listen_on_port}),"disable")}async openAll(){if(this.isDispensing)throw new Error("Another dispensing process is running");n(this,t,_).call(this),i(this,h,!0),n(this,t,f).call(this);const e=[];for(let s=1;s<=80;s++){const p=await this.dispense({cell:s,status:!0});e.push(p),i(this,a,s),n(this,t,f).call(this)}i(this,a,80),n(this,t,f).call(this,e),n(this,t,_).call(this)}async enableAll(){n(this,t,_).call(this),i(this,h,!0),n(this,t,g).call(this);for(let e=1;e<=80;e++)await this.enable({cell:e}),await m.wait(100),i(this,a,e),n(this,t,g).call(this);i(this,a,80),n(this,t,g).call(this),n(this,t,_).call(this)}async disableAll(){n(this,t,_).call(this),i(this,h,!0),n(this,t,b).call(this);for(let e=1;e<=80;e++)await this.disable({cell:e}),await m.wait(100),i(this,a,e),n(this,t,b).call(this);i(this,a,80),n(this,t,b).call(this),n(this,t,_).call(this)}}h=new WeakMap,a=new WeakMap,o=new WeakMap,t=new WeakSet,C=function(){const e=["percentage:disable","percentage:enable","percentage:open"];for(const s of e)this.serialRegisterAvailableListener(s)},_=function(){i(this,h,!1),i(this,a,0),i(this,o,0)},f=function(e=null){i(this,o,Math.round(r(this,a)*100/80)),this.dispatch("percentage:open",{percentage:r(this,o),dispensed:e})},g=function(){i(this,o,Math.round(r(this,a)*100/80)),this.dispatch("percentage:enable",{percentage:r(this,o)})},b=function(){i(this,o,Math.round(r(this,a)*100/80)),this.dispatch("percentage:disable",{percentage:r(this,o)})},k=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)},T=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)};exports.Locker=A;
1
+ "use strict";var y=l=>{throw TypeError(l)};var w=(l,c,e)=>c.has(l)||y("Cannot "+e);var r=(l,c,e)=>(w(l,c,"read from private field"),e?e.call(l):c.get(l)),u=(l,c,e)=>c.has(l)?y("Cannot add the same private member more than once"):c instanceof WeakSet?c.add(l):c.set(l,e),i=(l,c,e,s)=>(w(l,c,"write to private field"),s?s.call(l,e):c.set(l,e),e),n=(l,c,e)=>(w(l,c,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./kernel-CzkmE_OW.cjs"),d=require("./relay-DGFymXOw.cjs"),v=require("./webserial-core-5B5nYtyR.cjs");var h,a,o,t,C,_,f,g,b,k,T;class A extends m.Kernel{constructor({filters:e=null,config_port:s=null,no_device:p=1,device_listen_on_port:q=3}={}){super({filters:e,config_port:s,no_device:p,device_listen_on_port:q});u(this,t);u(this,h,!1);u(this,a,0);u(this,o,0);if(this.__internal__.device.type="locker",v.h.getCustom(this.typeDevice,p))throw new Error(`Device ${this.typeDevice} ${p} already exists`);this.__internal__.time.response_engines=1e3,this.__internal__.device.milliseconds=666,this.__internal__.dispense.limit_counter=1,v.h.add(this),n(this,t,C).call(this)}serialMessage(e){const s={code:e,name:null,description:null,request:null,no_code:0};switch(e[1]){case"08":s.name="Connection with the serial device completed.",s.description="Your connection with the serial device was successfully completed.",s.request="connect",s.no_code=100;break;case"07":switch(e[4]){case"00":s.name="Cell closed.",s.description="The selected cell is closed.",s.request="dispense",s.no_code=1102,this.__internal__.dispense.status=!1,this.dispatch("dispensed",{}),r(this,h)&&r(this,a)>=89?(s.finished_test=!0,i(this,h,!1),i(this,a,0)):r(this,h)&&(s.finished_test=!1);break;case"01":case"04":s.name="Cell open.",s.description="The selected cell was open successfully.",s.request="dispense",s.no_code=102,this.__internal__.dispense.status=!0,this.dispatch("dispensed",{}),r(this,h)&&r(this,a)>=89?(s.finished_test=!0,i(this,h,!1),i(this,a,0)):r(this,h)&&(s.finished_test=!1);break;case"05":s.name="Cell inactive.",s.description="The selected cell is inactive or doesn't exist.",s.request="dispense",s.no_code=101,this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{}),r(this,h)&&r(this,a)>=89?(s.finished_test=!0,i(this,h,!1),i(this,a,0)):r(this,h)&&(s.finished_test=!1);break}break;case"06":s.name="Configuration applied.",s.description="The configuration was successfully applied.",s.request="configure cell",s.no_code=103;break;default:s.request="undefined",s.name="Response unrecognized",s.description="The response of application was received, but dont identify with any of current parameters",s.no_code=400;break}this.dispatch("serial:message",s)}serialSetConnectionConstant(e=3){return d.u.connection({channel:e})}async dispense({cell:e=1,status:s=!0}={}){return setTimeout(()=>{s===!0?n(this,t,k).call(this):n(this,t,T).call(this)},this.__internal__.time.response_engines/2),await this.internalDispense(d.u.openCell({cell:e,channel:this.__internal__.device.listen_on_port}))}async status({cell:e=1}={}){return await this.appendToQueue(d.u.statusCell({cell:e,channel:this.__internal__.device.listen_on_port}),"status")}async lightScan({since:e=0,until:s=10}={}){return await this.appendToQueue(d.u.lightScan({channel:this.__internal__.device.listen_on_port,since:e,until:s}),"light-scan")}async enable({cell:e=1}={}){return await this.appendToQueue(d.u.enableCell({cell:e,channel:this.__internal__.device.listen_on_port}),"activate")}async disable({cell:e=1}={}){await this.appendToQueue(d.u.disableCell({cell:e,channel:this.__internal__.device.listen_on_port}),"disable")}async openAll(){if(this.isDispensing)throw new Error("Another dispensing process is running");n(this,t,_).call(this),i(this,h,!0),n(this,t,f).call(this);const e=[];for(let s=1;s<=80;s++){const p=await this.dispense({cell:s,status:!0});e.push(p),i(this,a,s),n(this,t,f).call(this)}i(this,a,80),n(this,t,f).call(this,e),n(this,t,_).call(this)}async enableAll(){n(this,t,_).call(this),i(this,h,!0),n(this,t,g).call(this);for(let e=1;e<=80;e++)await this.enable({cell:e}),await m.wait(100),i(this,a,e),n(this,t,g).call(this);i(this,a,80),n(this,t,g).call(this),n(this,t,_).call(this)}async disableAll(){n(this,t,_).call(this),i(this,h,!0),n(this,t,b).call(this);for(let e=1;e<=80;e++)await this.disable({cell:e}),await m.wait(100),i(this,a,e),n(this,t,b).call(this);i(this,a,80),n(this,t,b).call(this),n(this,t,_).call(this)}}h=new WeakMap,a=new WeakMap,o=new WeakMap,t=new WeakSet,C=function(){const e=["percentage:disable","percentage:enable","percentage:open"];for(const s of e)this.serialRegisterAvailableListener(s)},_=function(){i(this,h,!1),i(this,a,0),i(this,o,0)},f=function(e=null){i(this,o,Math.round(r(this,a)*100/80)),this.dispatch("percentage:open",{percentage:r(this,o),dispensed:e})},g=function(){i(this,o,Math.round(r(this,a)*100/80)),this.dispatch("percentage:enable",{percentage:r(this,o)})},b=function(){i(this,o,Math.round(r(this,a)*100/80)),this.dispatch("percentage:disable",{percentage:r(this,o)})},k=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)},T=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)};exports.Locker=A;
package/dist/locker.js CHANGED
@@ -3,9 +3,9 @@ var w = (l) => {
3
3
  };
4
4
  var b = (l, c, e) => c.has(l) || w("Cannot " + e);
5
5
  var r = (l, c, e) => (b(l, c, "read from private field"), e ? e.call(l) : c.get(l)), u = (l, c, e) => c.has(l) ? w("Cannot add the same private member more than once") : c instanceof WeakSet ? c.add(l) : c.set(l, e), i = (l, c, e, s) => (b(l, c, "write to private field"), s ? s.call(l, e) : c.set(l, e), e), n = (l, c, e) => (b(l, c, "access private method"), e);
6
- import { K as D, w as v } from "./kernel-IUeiZp8d.js";
7
- import { u as p } from "./relay-Dop4mFk-.js";
8
- import { h as y } from "./webserial-core-DGKQCs5a.js";
6
+ import { K as D, w as v } from "./kernel-BblykfpT.js";
7
+ import { u as p } from "./relay-CsdB0FSa.js";
8
+ import { h as y } from "./webserial-core-ByrJ7tlu.js";
9
9
  var h, a, o, t, C, _, f, g, m, T, k;
10
10
  class Q extends D {
11
11
  constructor({ filters: e = null, config_port: s = null, no_device: d = 1, device_listen_on_port: A = 3 } = {}) {
package/dist/pinpad.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var gn=Object.defineProperty;var Te=n=>{throw TypeError(n)};var mn=(n,i,t)=>i in n?gn(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var Ce=(n,i,t)=>mn(n,typeof i!="symbol"?i+"":i,t),yn=(n,i,t)=>i.has(n)||Te("Cannot "+t);var Ae=(n,i,t)=>i.has(n)?Te("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t);var f=(n,i,t)=>(yn(n,i,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./kernel-DlsHh4AG.cjs"),Re=require("./webserial-core-DlH0cFSH.cjs");var bn="0123456789abcdefghijklmnopqrstuvwxyz";function $(n){return bn.charAt(n)}function Pn(n,i){return n&i}function Et(n,i){return n|i}function Oe(n,i){return n^i}function xe(n,i){return n&~i}function vn(n){if(n==0)return-1;var i=0;return(n&65535)==0&&(n>>=16,i+=16),(n&255)==0&&(n>>=8,i+=8),(n&15)==0&&(n>>=4,i+=4),(n&3)==0&&(n>>=2,i+=2),(n&1)==0&&++i,i}function wn(n){for(var i=0;n!=0;)n&=n-1,++i;return i}var at="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ze="=";function Vt(n){var i,t,e="";for(i=0;i+3<=n.length;i+=3)t=parseInt(n.substring(i,i+3),16),e+=at.charAt(t>>6)+at.charAt(t&63);for(i+1==n.length?(t=parseInt(n.substring(i,i+1),16),e+=at.charAt(t<<2)):i+2==n.length&&(t=parseInt(n.substring(i,i+2),16),e+=at.charAt(t>>2)+at.charAt((t&3)<<4));(e.length&3)>0;)e+=Ze;return e}function De(n){var i="",t,e=0,r=0;for(t=0;t<n.length&&n.charAt(t)!=Ze;++t){var s=at.indexOf(n.charAt(t));s<0||(e==0?(i+=$(s>>2),r=s&3,e=1):e==1?(i+=$(r<<2|s>>4),r=s&15,e=2):e==2?(i+=$(r),i+=$(s>>2),r=s&3,e=3):(i+=$(r<<2|s>>4),i+=$(s&15),e=0))}return e==1&&(i+=$(r<<2)),i}var rt,En={decode:function(n){var i;if(rt===void 0){var t="0123456789ABCDEF",e=` \f
1
+ "use strict";var gn=Object.defineProperty;var Te=n=>{throw TypeError(n)};var mn=(n,i,t)=>i in n?gn(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var Ce=(n,i,t)=>mn(n,typeof i!="symbol"?i+"":i,t),yn=(n,i,t)=>i.has(n)||Te("Cannot "+t);var Ae=(n,i,t)=>i.has(n)?Te("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t);var f=(n,i,t)=>(yn(n,i,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./kernel-CzkmE_OW.cjs"),Re=require("./webserial-core-5B5nYtyR.cjs");var bn="0123456789abcdefghijklmnopqrstuvwxyz";function $(n){return bn.charAt(n)}function Pn(n,i){return n&i}function Et(n,i){return n|i}function Oe(n,i){return n^i}function xe(n,i){return n&~i}function vn(n){if(n==0)return-1;var i=0;return(n&65535)==0&&(n>>=16,i+=16),(n&255)==0&&(n>>=8,i+=8),(n&15)==0&&(n>>=4,i+=4),(n&3)==0&&(n>>=2,i+=2),(n&1)==0&&++i,i}function wn(n){for(var i=0;n!=0;)n&=n-1,++i;return i}var at="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ze="=";function Vt(n){var i,t,e="";for(i=0;i+3<=n.length;i+=3)t=parseInt(n.substring(i,i+3),16),e+=at.charAt(t>>6)+at.charAt(t&63);for(i+1==n.length?(t=parseInt(n.substring(i,i+1),16),e+=at.charAt(t<<2)):i+2==n.length&&(t=parseInt(n.substring(i,i+2),16),e+=at.charAt(t>>2)+at.charAt((t&3)<<4));(e.length&3)>0;)e+=Ze;return e}function De(n){var i="",t,e=0,r=0;for(t=0;t<n.length&&n.charAt(t)!=Ze;++t){var s=at.indexOf(n.charAt(t));s<0||(e==0?(i+=$(s>>2),r=s&3,e=1):e==1?(i+=$(r<<2|s>>4),r=s&15,e=2):e==2?(i+=$(r),i+=$(s>>2),r=s&3,e=3):(i+=$(r<<2|s>>4),i+=$(s&15),e=0))}return e==1&&(i+=$(r<<2)),i}var rt,En={decode:function(n){var i;if(rt===void 0){var t="0123456789ABCDEF",e=` \f
2
2
  \r  \u2028\u2029`;for(rt={},i=0;i<16;++i)rt[t.charAt(i)]=i;for(t=t.toLowerCase(),i=10;i<16;++i)rt[t.charAt(i)]=i;for(i=0;i<e.length;++i)rt[e.charAt(i)]=-1}var r=[],s=0,a=0;for(i=0;i<n.length;++i){var o=n.charAt(i);if(o=="=")break;if(o=rt[o],o!=-1){if(o===void 0)throw new Error("Illegal character at offset "+i);s|=o,++a>=2?(r[r.length]=s,s=0,a=0):s<<=4}}if(a)throw new Error("Hex encoding incomplete: 4 bits missing");return r}},Y,Yt={decode:function(n){var i;if(Y===void 0){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=`= \f
3
3
  \r  \u2028\u2029`;for(Y=Object.create(null),i=0;i<64;++i)Y[t.charAt(i)]=i;for(Y["-"]=62,Y._=63,i=0;i<e.length;++i)Y[e.charAt(i)]=-1}var r=[],s=0,a=0;for(i=0;i<n.length;++i){var o=n.charAt(i);if(o=="=")break;if(o=Y[o],o!=-1){if(o===void 0)throw new Error("Illegal character at offset "+i);s|=o,++a>=4?(r[r.length]=s>>16,r[r.length]=s>>8&255,r[r.length]=s&255,s=0,a=0):s<<=6}}switch(a){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:r[r.length]=s>>10;break;case 3:r[r.length]=s>>16,r[r.length]=s>>8&255;break}return r},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(n){var i=Yt.re.exec(n);if(i)if(i[1])n=i[1];else if(i[2])n=i[2];else throw new Error("RegExp out of sync");return Yt.decode(n)}},st=1e13,ft=function(){function n(i){this.buf=[+i||0]}return n.prototype.mulAdd=function(i,t){var e=this.buf,r=e.length,s,a;for(s=0;s<r;++s)a=e[s]*i+t,a<st?t=0:(t=0|a/st,a-=t*st),e[s]=a;t>0&&(e[s]=t)},n.prototype.sub=function(i){var t=this.buf,e=t.length,r,s;for(r=0;r<e;++r)s=t[r]-i,s<0?(s+=st,i=1):i=0,t[r]=s;for(;t[t.length-1]===0;)t.pop()},n.prototype.toString=function(i){if((i||10)!=10)throw new Error("only base 10 is supported");for(var t=this.buf,e=t[t.length-1].toString(),r=t.length-2;r>=0;--r)e+=(st+t[r]).toString().substring(1);return e},n.prototype.valueOf=function(){for(var i=this.buf,t=0,e=i.length-1;e>=0;--e)t=t*st+i[e];return t},n.prototype.simplify=function(){var i=this.buf;return i.length==1?i[0]:this},n}(),Ye="…",Sn=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,Tn=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function ct(n,i){return n.length>i&&(n=n.substring(0,i)+Ye),n}var zt=function(){function n(i,t){this.hexDigits="0123456789ABCDEF",i instanceof n?(this.enc=i.enc,this.pos=i.pos):(this.enc=i,this.pos=t)}return n.prototype.get=function(i){if(i===void 0&&(i=this.pos++),i>=this.enc.length)throw new Error("Requesting byte offset ".concat(i," on a stream of length ").concat(this.enc.length));return typeof this.enc=="string"?this.enc.charCodeAt(i):this.enc[i]},n.prototype.hexByte=function(i){return this.hexDigits.charAt(i>>4&15)+this.hexDigits.charAt(i&15)},n.prototype.hexDump=function(i,t,e){for(var r="",s=i;s<t;++s)if(r+=this.hexByte(this.get(s)),e!==!0)switch(s&15){case 7:r+=" ";break;case 15:r+=`
4
4
  `;break;default:r+=" "}return r},n.prototype.isASCII=function(i,t){for(var e=i;e<t;++e){var r=this.get(e);if(r<32||r>176)return!1}return!0},n.prototype.parseStringISO=function(i,t){for(var e="",r=i;r<t;++r)e+=String.fromCharCode(this.get(r));return e},n.prototype.parseStringUTF=function(i,t){for(var e="",r=i;r<t;){var s=this.get(r++);s<128?e+=String.fromCharCode(s):s>191&&s<224?e+=String.fromCharCode((s&31)<<6|this.get(r++)&63):e+=String.fromCharCode((s&15)<<12|(this.get(r++)&63)<<6|this.get(r++)&63)}return e},n.prototype.parseStringBMP=function(i,t){for(var e="",r,s,a=i;a<t;)r=this.get(a++),s=this.get(a++),e+=String.fromCharCode(r<<8|s);return e},n.prototype.parseTime=function(i,t,e){var r=this.parseStringISO(i,t),s=(e?Sn:Tn).exec(r);return s?(e&&(s[1]=+s[1],s[1]+=+s[1]<70?2e3:1900),r=s[1]+"-"+s[2]+"-"+s[3]+" "+s[4],s[5]&&(r+=":"+s[5],s[6]&&(r+=":"+s[6],s[7]&&(r+="."+s[7]))),s[8]&&(r+=" UTC",s[8]!="Z"&&(r+=s[8],s[9]&&(r+=":"+s[9]))),r):"Unrecognized time: "+r},n.prototype.parseInteger=function(i,t){for(var e=this.get(i),r=e>127,s=r?255:0,a,o="";e==s&&++i<t;)e=this.get(i);if(a=t-i,a===0)return r?-1:0;if(a>4){for(o=e,a<<=3;((+o^s)&128)==0;)o=+o<<1,--a;o="("+a+` bit)
package/dist/pinpad.js CHANGED
@@ -6,8 +6,8 @@ var bn = (n, i, t) => i in n ? yn(n, i, { enumerable: !0, configurable: !0, writ
6
6
  var Ce = (n, i, t) => bn(n, typeof i != "symbol" ? i + "" : i, t), Pn = (n, i, t) => i.has(n) || Te("Cannot " + t);
7
7
  var Ae = (n, i, t) => i.has(n) ? Te("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(n) : i.set(n, t);
8
8
  var p = (n, i, t) => (Pn(n, i, "access private method"), t);
9
- import { K as vn, a as wn, i as G, b as Re, w as Oe } from "./kernel-IUeiZp8d.js";
10
- import { h as xe } from "./webserial-core-DGKQCs5a.js";
9
+ import { K as vn, a as wn, i as G, b as Re, w as Oe } from "./kernel-BblykfpT.js";
10
+ import { h as xe } from "./webserial-core-ByrJ7tlu.js";
11
11
  var En = "0123456789abcdefghijklmnopqrstuvwxyz";
12
12
  function $(n) {
13
13
  return En.charAt(n);
package/dist/pinpax.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var R=Object.defineProperty;var d=r=>{throw TypeError(r)};var E=(r,i,s)=>i in r?R(r,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[i]=s;var y=(r,i,s)=>E(r,typeof i!="symbol"?i+"":i,s),I=(r,i,s)=>i.has(r)||d("Cannot "+s);var f=(r,i,s)=>i.has(r)?d("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(r):i.set(r,s);var o=(r,i,s)=>(I(r,i,"access private method"),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./kernel-DlsHh4AG.cjs"),n=require("./relay-BsUsBpOv.cjs"),w=require("./webserial-core-DlH0cFSH.cjs");var t,m,_,l,g,v,b,x,T;class A extends C.Kernel{constructor({filters:s=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:a=1,device_listen_on_channel:c=1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,device_listen_on_channel:1}){super({filters:s,config_port:e,no_device:a,device_listen_on_channel:c});f(this,t);y(this,"__pinpax__",{server:"DEV",bussinessId:null,encriptionKey:null,apiKey:null,asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1}});if(this.__internal__.device.type="pinpax",w.h.getCustom(this.typeDevice,a))throw new Error(`Device ${this.typeDevice} ${a} already exists`);this.__internal__.time.response_connection=4e3,this.__internal__.time.response_general=3e3,this.__internal__.serial.delay_first_connection=1e3,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
1
+ "use strict";var R=Object.defineProperty;var d=r=>{throw TypeError(r)};var E=(r,i,s)=>i in r?R(r,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[i]=s;var y=(r,i,s)=>E(r,typeof i!="symbol"?i+"":i,s),I=(r,i,s)=>i.has(r)||d("Cannot "+s);var f=(r,i,s)=>i.has(r)?d("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(r):i.set(r,s);var o=(r,i,s)=>(I(r,i,"access private method"),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./kernel-CzkmE_OW.cjs"),n=require("./relay-DGFymXOw.cjs"),w=require("./webserial-core-5B5nYtyR.cjs");var t,m,_,l,g,v,b,x,T;class A extends C.Kernel{constructor({filters:s=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:a=1,device_listen_on_channel:c=1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,device_listen_on_channel:1}){super({filters:s,config_port:e,no_device:a,device_listen_on_channel:c});f(this,t);y(this,"__pinpax__",{server:"DEV",bussinessId:null,encriptionKey:null,apiKey:null,asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1}});if(this.__internal__.device.type="pinpax",w.h.getCustom(this.typeDevice,a))throw new Error(`Device ${this.typeDevice} ${a} already exists`);this.__internal__.time.response_connection=4e3,this.__internal__.time.response_general=3e3,this.__internal__.serial.delay_first_connection=1e3,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
2
2
  `,o(this,t,m).call(this),w.h.add(this),this.getResponseAsString()}set bussinessId(s){this.__pinpax__.bussinessId=s}get bussinessId(){return this.__pinpax__.bussinessId}set encriptionKey(s){this.__pinpax__.encriptionKey=s}get encriptionKey(){return this.__pinpax__.encriptionKey}set apiKey(s){this.__pinpax__.apiKey=s}get apiKey(){return this.__pinpax__.apiKey}set server(s){this.__pinpax__.server=s}get server(){return this.__pinpax__.server}serialMessage(s){let e=null;try{e=JSON.parse(s)}catch(a){console.error("Error parsing response",a,s),this.dispatch("serial:message",s);return}switch(e.response){case"INITAPP":this.dispatch("init-app",{status:"started"}),o(this,t,b).call(this).then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{status:"connected"}),o(this,t,x).call(this).then(()=>{});break;case"LOGIN":this.dispatch("login",e);break;case"LASTVOUCHER":this.dispatch("voucher",e),this.__pinpax__.waiting.voucher&&(this.__pinpax__.asyncResponses.voucher=e,this.__pinpax__.waiting.voucher=!1);break;case"DEVICEINFO":this.dispatch("info",e);break;case"KEEPALIVE":this.dispatch("keep-alive",{status:"alive"});break;case"RESETAPP":this.dispatch("reset-app",{status:"accepted"});break;case"GETCONFIG":this.dispatch("get-config",e);break;case"HIDEBUTTONS":this.dispatch("buttons-status",{hidden:!0});break;case"SHOWBUTTONS":this.dispatch("buttons-status",{hidden:!1});break;case"PAYMENT_PROCESS":this.dispatch("payment",{status:"starting",amount:e.amount,reference:e.referecence});break;case"INSERT_CARD":this.dispatch("payment",{status:"insert card"});break;case"CARD_DATA":this.dispatch("payment",{status:"card data",amount:e.amount,cardHolderName:e.cardHolderName,ccMark:e.ccMark,ccType:e.ccType,currency:e.currency,maskedPan:e.maskedPan,readingType:e.readingType});break;case"MERCHANT":this.dispatch("payment",{status:"merchant",afiliation:e.afiliation,alias:e.alias,amountCashBackCommission:e.amountCashBackCommission,currency:e.currency,description:e.description,hasCashBack:e.hasCashBack,limitCashBackAmount:e.limitCashBackAmount,merchant:e.merchant,months:e.months,name:e.name});break;case"TRANSACTION_RESULT":o(this,t,T).call(this,{status:"result",approved:e.approved,acquirer:e.acquirer,address:e.address,amount:e.amount,amountCashback:e.amountCashback,appIDLabel:e.appIDLabel,appId:e.appId,arqc:e.arqc,auth:e.auth,ccBin:e.ccBin,ccExpirationDate:e.ccExpirationDate,ccName:e.ccName,ccNumber:e.ccNumber,ccType:e.ccType,comissionCashback:e.comissionCashback,currency:e.currency,date:e.date,errorCode:e.errorCode,errorDescription:e.errorDescription,folio:e.folio,id:e.id,merchantName:e.merchantName,msiLabel:e.msiLabel,operation:e.operation,pin:e.pin,qps:e.qps,reference:e.reference,response:e.response,source:e.source,sourceLabel:e.sourceLabel,time:e.time});break;case"ERROR":this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{status:"error",response:e}),this.dispatch("payment",{status:"error",response:e});break;case"REFUND":this.dispatch("refund",{status:"refund",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(s=1){return n.s.connection(s)}softReload(){super.softReload(),this.__pinpax__.waiting.sale=!1,this.__pinpax__.waiting.voucher=!1,this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.asyncResponses.voucher=null}async sendCustomCode(s={}){if(typeof s!="object")throw new Error("Invalid object");if(s.constructor!==Object)throw new Error("Invalid object");if(Object.keys(s).length===0)throw new Error("Empty object");if(s.action===void 0||s.action===null)throw new Error("Invalid object add action");const e=JSON.stringify(s),a=this.parseStringToBytes(e,`\r
3
3
  `);await this.appendToQueue(this.stringArrayToUint8Array(a),"custom")}async connectMessage(){await this.appendToQueue(n.s.connect(),"connect:message")}async makeSale({amount:s=0,reference:e=null}={}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.sale)throw new Error("Already waiting for sale response");const a=n.s.makeSale({amount:s,reference:e});this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await o(this,t,_).call(this);const c=this;return await this.appendToQueue(a,"make-sale"),new Promise(p=>{const h=setInterval(()=>{if(c.__pinpax__.asyncResponses.sale){const u=c.__pinpax__.asyncResponses.sale;c.__pinpax__.asyncResponses.sale=null,c.__pinpax__.waiting.sale=!1,clearInterval(h),p(u.approved)}},100)})}async getVoucher({folio:s=null}={}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.voucher)throw new Error("Already waiting for voucher");if(!s)throw new Error("Folio is required");this.__pinpax__.waiting.voucher=!0,this.__pinpax__.asyncResponses.voucher=null;const e=n.s.getVoucher({folio:s});this.queue.length>0&&await o(this,t,_).call(this),await this.appendToQueue(e,"get-voucher");const a=this;return new Promise((c,p)=>{const h=setTimeout(()=>{a.__pinpax__.waiting.voucher=!1,p("Timeout")},1e4),u=setInterval(()=>{if(a.__pinpax__.asyncResponses.voucher){const k=a.__pinpax__.asyncResponses.voucher;a.__pinpax__.asyncResponses.voucher=null,a.__pinpax__.waiting.voucher=!1,clearInterval(u),clearTimeout(h),c(k.voucher)}},100)})}async info(){await this.appendToQueue(n.s.info(),"info")}async keepAlive(){await this.appendToQueue(n.s.keepAlive(),"keep-alive")}async restartApp(){await this.appendToQueue(n.s.restartApp(),"reset-app")}async getConfig(){return await this.appendToQueue(n.s.getConfig(),"get-config")}async hideButtons(){return await this.appendToQueue(n.s.hideButtons(),"hide-buttons"),await o(this,t,g).call(this)}async showButtons(){return await this.appendToQueue(n.s.showButtons(),"show-buttons"),await o(this,t,v).call(this)}async demo(){return console.warn("RUNNING DEMO APP, BE CAREFUL"),await this.appendToQueue(n.s.demo(),"demo")}async refund({amount:s=0,folio:e=null,auth:a=null}={}){return await this.appendToQueue(n.s.refund({amount:s,folio:e,auth:a}),"refund")}async readProductionQR(){return await o(this,t,l).call(this,{type:"production"})}async readQualityAssuranceQR(){return o(this,t,l).call(this,{type:"QA"})}async exit(){return await this.appendToQueue(n.s.exit(),"exit-app")}async init(){await this.appendToQueue(n.s.init(),"init-app")}async login(){if(!this.apiKey||!this.bussinessId||!this.encriptionKey||!this.server)throw new Error("Invalid data to login check apiKey, bussinessId, encriptionKey, server");const s=JSON.stringify({action:"LOGIN_MIT",server:this.__pinpax__.server,bussiness_id:this.__pinpax__.bussinessId,encription_key:this.__pinpax__.encriptionKey,api_key:this.__pinpax__.apiKey}),e=this.parseStringToBytes(s,`\r
4
4
  `);await this.appendToQueue(e,"login")}}t=new WeakSet,m=function(){const s=["buttons-status","init-app","connectMessage","voucher","info","keep-alive","reset-app","get-config","payment","error","refund","login"];for(const e of s)this.serialRegisterAvailableListener(e)},_=async function(){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.queue.length===0)return!0;const s=this;return new Promise(e=>{let a=setInterval(()=>{s.queue.length===0&&(clearInterval(a),e(!0))},500)})},l=async function({type:s="production"}={}){const e=n.s.readQR({type:s});return await this.appendToQueue(e,"read-qr")},g=async function(){await this.appendToQueue(n.s.forceHide(),"force-hide")},v=async function(){await this.appendToQueue(n.s.forceShow(),"force-show")},b=async function(){await this.connectMessage()},x=async function(){await this.hideButtons()},T=function(s){this.dispatch("payment",s),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=s)};exports.PinPax=A;
package/dist/pinpax.js CHANGED
@@ -6,9 +6,9 @@ var E = (r, i, s) => i in r ? R(r, i, { enumerable: !0, configurable: !0, writab
6
6
  var y = (r, i, s) => E(r, typeof i != "symbol" ? i + "" : i, s), I = (r, i, s) => i.has(r) || d("Cannot " + s);
7
7
  var f = (r, i, s) => i.has(r) ? d("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(r) : i.set(r, s);
8
8
  var o = (r, i, s) => (I(r, i, "access private method"), s);
9
- import { K as C } from "./kernel-IUeiZp8d.js";
10
- import { s as n } from "./relay-Dop4mFk-.js";
11
- import { h as m } from "./webserial-core-DGKQCs5a.js";
9
+ import { K as C } from "./kernel-BblykfpT.js";
10
+ import { s as n } from "./relay-CsdB0FSa.js";
11
+ import { h as m } from "./webserial-core-ByrJ7tlu.js";
12
12
  var t, w, _, l, g, v, b, x, T;
13
13
  class S extends C {
14
14
  constructor({
@@ -1333,7 +1333,6 @@ let x = R;
1333
1333
  x.instance = new x();
1334
1334
  export {
1335
1335
  x as e,
1336
- k as i,
1337
1336
  N as l,
1338
1337
  D as o,
1339
1338
  U as s,
@@ -1,3 +1,3 @@
1
- "use strict";const g=i=>{if(i instanceof Uint8Array)return i;if(Array.isArray(i))return new Uint8Array(i);if(typeof i=="string")return new TextEncoder().encode(i);if(i instanceof ArrayBuffer)return new Uint8Array(i);throw new Error("Unsupported data type")},P=({data:i,asString:e=!0})=>e?Array.from(i).map(n=>n.toString(16).padStart(2,"0")).join(" "):Array.from(i).map(n=>n.toString(16).padStart(2,"0"));var F=Object.defineProperty,L=(i,e,n)=>e in i?F(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,T=(i,e,n)=>L(i,typeof e!="symbol"?e+"":e,n);const f=class d{build(e){return g(e+d.append)}static connection(){return d.instance.build("CONNECT")}static connect(){return d.connection()}static credits(){return d.instance.build("CREDITS")}static hi(){return d.instance.build("HI")}static ara(){return d.instance.build("ARA")}static custom(e){return d.instance.build(e)}};T(f,"append",`
2
- `),T(f,"instance");let b=f;b.instance=new b;var H=Object.defineProperty,B=(i,e,n)=>e in i?H(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,$=(i,e,n)=>B(i,typeof e!="symbol"?e+"":e,n);const w=class c{build(e){return c.asHex?P({data:e,asString:!1}):g(e)}serialBoardroidSumHex(e){let n=0;for(let a=0;a<e.length;a++)a===0||a===11||(n+=e[a]);return n}boardroidCheckSum(e){return e[11]=this.serialBoardroidSumHex(e),e}static connection({channel:e=1}={}){const n=c.instance.boardroidCheckSum(new Uint8Array([241,5+e,0,0,0,0,0,0,0,0,242,248]));return c.instance.build(n)}static coinPurseConfiguration({enable:e=!1,high:n=255,low:a=255}={}){const t=c.instance.boardroidCheckSum(new Uint8Array([241,193,e?1:0,n,a,0,0,0,0,0,242,0]));return c.instance.build(t)}static coinPurseDispense({$50c:e=0,$1:n=0,$2:a=0,$5:t=0,$10:s=0}={}){if([e,n,a,t,s].some(u=>isNaN(u)||typeof u=="string"))throw new Error("One of the values is not a number");if(e<1&&n<1&&a<1&&t<1&&s<1)throw new Error("No coins to dispense");const o=c.instance.boardroidCheckSum(new Uint8Array([241,198,e,n,a,t,s,0,0,0,242,0]));return c.instance.build(o)}static coinPurseReadTubes(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,194,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static banknotePurseICTConfigure({enable:e=!1,scrow:n=!1}={}){const a=e?255:0,t=n?255:0,s=c.instance.boardroidCheckSum(new Uint8Array([241,192,a,a,t,t,0,0,0,0,242,0]));return c.instance.build(s)}static banknotePurseOtherConfigure({enable:e=!1,scrow:n=!1}={}){const a=e?1:0,t=n?1:0,s=c.instance.boardroidCheckSum(new Uint8Array([241,192,a,t,0,0,0,0,0,0,242,0]));return c.instance.build(s)}static banknotePurseICTDispense({quantity:e=1,denomination:n=20}){if(e<1)throw new Error("No banknotes to dispense");if([20,50,100,200,500].indexOf(n)===-1)throw new Error("Invalid denomination");const a=[20,50,100,200,500].indexOf(n),t=c.instance.boardroidCheckSum(new Uint8Array([241,197,a,e,0,0,0,0,0,0,242,0]));return c.instance.build(t)}static banknotePurseOtherDispense({$20:e=0,$50:n=0,$100:a=0,$200:t=0,$500:s=0,$1000:o=0}={}){if([e,n,a,t,s,o].some(m=>isNaN(m)||typeof m=="string"))throw new Error("One of the values is not a number");if(e<1&&n<1&&a<1&&t<1&&s<1&&o<1)throw new Error("No banknotes to dispense");const u=c.instance.boardroidCheckSum(new Uint8Array([241,197,e,n,a,t,s,o,0,0,242,0]));return c.instance.build(u)}static banknotePurseAcceptInScrow(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,196,1,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static banknotePurseRejectInScrow(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,196,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static banknotePurseSaveMemory({channel:e=null,$20:n=null,$50:a=null,$100:t=null,$200:s=null,$500:o=null,$1000:u=null}={channel:null,$20:null,$50:null,$100:null,$200:null,$500:null,$1000:null}){if(e===null||n===null||a===null||t===null||s===null||o===null||u===null)throw new Error("One of the values is not defined: "+JSON.stringify({channel:e,$20:n,$50:a,$100:t,$200:s,$500:o,$1000:u}));const m=c.instance.boardroidCheckSum(new Uint8Array([241,200,e,0,n,a,t,s,o,u,242,0]));return c.instance.build(m)}static banknotePurseReadRecycler(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,195,0,0,0,0,0,0,0,0,242,181]));return c.instance.build(e)}static cardReaderDisable(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,205,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static cardReaderDispense({selection:e=1,second_selection:n=null,sensor:a=!0,seconds:t=null,price:s=0}={selection:1,second_selection:null,sensor:!0,seconds:null,price:0}){const o=s/256,u=s%256,m=e+9;let p=0;n&&(p=n+9);let D=0;a||(t||(t=1.5),D=Math.round(t*6.2));const M=c.instance.boardroidCheckSum(new Uint8Array([241,205,1,m,p,D,o,u,0,0,242,0]));return c.instance.build(M)}static coolingRelayConfigure({enable:e=!0}={}){const n=c.instance.boardroidCheckSum(new Uint8Array([241,204,e?1:0,0,0,0,0,0,0,0,242,0]));return c.instance.build(n)}static readTemperature(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,203,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static dispense({selection:e=1,second_selection:n=null,sensor:a=!0,seconds:t=null}={selection:1,second_selection:null,sensor:!0,seconds:null}){e+=9;const s=e;let o=0;n&&(n+=9,o=n);let u=0;a||(t||(t=1.5),u=Math.round(t*6.2));const m=c.instance.boardroidCheckSum(new Uint8Array([241,199,s,o,u,0,0,0,0,0,242,0]));return c.instance.build(m)}static customCode(e){typeof e[0]=="string"&&(e=e.map(a=>parseInt(a,16)));const n=c.instance.boardroidCheckSum(new Uint8Array(e));return c.instance.build(n)}};$(w,"asHex",!1),$(w,"instance");let y=w;y.instance=new y;var J=Object.defineProperty,G=(i,e,n)=>e in i?J(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,O=(i,e,n)=>G(i,typeof e!="symbol"?e+"":e,n);const v=class r{build(e){const n=this.jofemarCheckSum(e);return r.asHex?P({data:new Uint8Array(n),asString:!1}):g(n)}calcCheckSums(e){const n=[];return n.push(e&255|240),n.push(e&255|15),n}jofemarCheckSum(e){let n=0;for(let t=0;t<e.length;t++)n+=e[t];const a=this.calcCheckSums(n);return e.push(a[0]),e.push(a[1]),e.push(3),new Uint8Array(e)}getTrayAndChannelBySelection(e){if(e=parseInt(e)+109,e=e.toString(),e.length!==3)throw new Error("Invalid selection");const n=(parseInt(e.substring(0,2))+128).toString(16).padStart(2,"0"),a=(parseInt(e.substring(2,3))+128).toString(16).padStart(2,"0");return{channel:parseInt(a,16),tray:parseInt(n,16)}}makeDisplayMessage(e=""){e=e.padEnd(32," ");const n=[];for(let a=0;a<32;a++)n.push(e.charCodeAt(a));return n}makeTimeFormat(e){if(!(e instanceof Date))throw new Error("Invalid date, must be an instance of Date");const n=e.getHours().toString().padStart(2,"0"),a=e.getMinutes().toString().padStart(2,"0"),t=e.getDate().toString().padStart(2,"0"),s=(e.getMonth()+1).toString().padStart(2,"0"),o=e.getFullYear().toString().substring(2,4),u=`${n}:${a} ${t}-${s}-${o}`,m=[];for(let p=0;p<14;p++)m.push(u.charCodeAt(p));return m}static connection({channel:e=1}={}){return r.instance.build([2,48,48,128+e,83,255,255])}static dispense({machineChannel:e=1,selection:n=1,cart:a=!1}={machineChannel:1,selection:1,cart:!1}){if(n=parseInt(n),isNaN(n)||n<1||n>130)throw new Error("Invalid selection");const{channel:t,tray:s}=r.instance.getTrayAndChannelBySelection(n);return r.instance.build([2,48,48,128+e,a?77:86,s,t])}static endCartDispense({machineChannel:e=1}={}){return r.instance.build([2,48,48,128+e,77,128,128])}static collect({machineChannel:e=1}={}){return r.instance.build([2,48,48,128+e,78,255,255])}static reset({machineChannel:e=1,type:n="soldOut"}={}){let a=128;return n==="waiting"?a=129:n==="machine"&&(a=255),r.instance.build([2,48,48,128+e,82,a,255])}static status({machineChannel:e=1}={}){return r.instance.build([2,48,48,128+e,83,255,255])}static lights({machineChannel:e=1,type:n="on"}={}){const a=n==="on"?129:128;return r.instance.build([2,48,48,128+e,76,a,255])}static program({machineChannel:e=1,param1:n=255,param2:a=255}={}){return r.instance.build([2,48,48,128+e,80,n,a])}static programDisplayLanguage({machineChannel:e=1,language:n="spanish"}={}){const a={spanish:48,english:49,french:50};if(!a[n])throw new Error("Invalid language");return r.program({machineChannel:e,param1:73,param2:a[n]})}static programBeeper({machineChannel:e=1,enable:n=!0}){return r.program({machineChannel:e,param1:90,param2:n?49:48})}static programDisableWorkingTemperature({machineChannel:e=1}){return r.program({machineChannel:e,param1:84,param2:128})}static programDisableThermometer({machineChannel:e=1}){return r.programDisableWorkingTemperature({machineChannel:e})}static programWorkingTemperature({machineChannel:e=1,degrees:n=.5,machineType:a="esplus"}={}){typeof n=="string"&&(n=parseFloat(n));const t=a==="iceplus"?6.5:32,s=a==="iceplus"?-25:.5;if(isNaN(n)||n<s||n>t||n%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32");let o=n*2+128;return a==="iceplus"&&(o+=51),o=Math.ceil(o),r.program({param1:84,param2:o,machineChannel:e})}static programIsolationTray({machineChannel:e=1,tray:n=0}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<0||n>12)throw new Error("Invalid tray, valid range is 0 to 12");const a=n===0?128:n+139;return r.program({param1:66,param2:a,machineChannel:e})}static programTimeToStandbyAfterCollect({machineChannel:e=1,seconds:n=15}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<15||n>120)throw new Error("Invalid seconds, valid range is 15 to 120");const a=128+n;return r.program({param1:70,param2:a,machineChannel:e})}static programTimeToStandbyWithoutCollect({machineChannel:e=1,minutes:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>10)throw new Error("Invalid minutes, valid range is 1 to 10");const a=128+n;return r.program({param1:72,param2:a,machineChannel:e})}static programElevatorSpeed({machineChannel:e=1,speed:n="high"}={}){const a={high:49,low:48};if(!a[n])throw new Error("Invalid speed, valid speeds are 'high' and 'low'");return r.program({param1:118,param2:a[n],machineChannel:e})}static programTemperatureExpiration({machineChannel:e=1,enable:n=!1}){return r.program({machineChannel:e,param1:99,param2:n?49:48})}static programMachineAddress({machineChannel:e=1,address:n=1}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>31)throw new Error("Invalid address, valid range is 1 to 31");return r.program({param1:100,param2:128+n,machineChannel:e})}static programTemperatureBeforeExpiration({machineChannel:e=1,degrees:n=.5}){if(typeof n=="string"&&(n=parseFloat(n)),isNaN(n)||n<.5||n>30||n%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30");const a=128+n*2;return r.program({param1:101,param2:a,machineChannel:e})}static programTimeBeforeExpirationByTemperature({machineChannel:e=1,minutes:n=1}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>120)throw new Error("Invalid minutes, valid range is 1 to 120");const a=128+n;return r.program({param1:102,param2:a,machineChannel:e})}static programTemperatureScale({machineChannel:e=1,scale:n="celsius"}={}){const a={celsius:67,fahrenheit:70};if(!a[n])throw new Error("Invalid scale, valid scales are 'celsius' and 'fahrenheit'");return r.program({param1:103,param2:a[n],machineChannel:e})}static programVoltageEngine({machineChannel:e=1,selection:n=1,voltage:a=5}={}){if(typeof a=="string"&&(a=parseFloat(a)),typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");if(isNaN(a)||a<5||a>9.5||a%.5!==0)throw new Error("Invalid voltage, valid range is 5 to 9.5");const t=109+n,s=128+(a-5)*2;return r.instance.build([2,48,48,128+e,71,t,s])}static programPushOverProducts({machineChannel:e=1,selection:n=1,enable:a=!0}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");const t=109+n,s=a?49:48;return r.instance.build([2,48,48,128+e,79,t,s])}static programChannelRunningAfterDispense({machineChannel:e=1,selection:n=1,seconds:a=0}={}){if(typeof n=="string"&&(n=parseInt(n)),typeof a=="string"&&(a=parseFloat(a)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");if(isNaN(a)||a<0||a>10||a%.1!==0)throw new Error("Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1");const t=109+n;a=10*parseFloat(a.toFixed(1));const s=128+a;return r.instance.build([2,48,48,128+e,69,t,s])}static checkData({machineChannel:e=1,type:n=255,aux:a=255}){return r.instance.build([2,48,48,128+e,67,n,a])}static getDisplayLanguage({machineChannel:e=1}){return r.checkData({machineChannel:e,type:73})}static getBeeper({machineChannel:e=1}){return r.checkData({machineChannel:e,type:90})}static getWorkingTemperature({machineChannel:e=1}){return r.checkData({machineChannel:e,type:84})}static getIsolationTray({machineChannel:e=1}){return r.checkData({machineChannel:e,type:66})}static getProgramVersion({machineChannel:e=1}){return r.checkData({machineChannel:e,type:80})}static getFaults({machineChannel:e=1}){return r.checkData({machineChannel:e,type:83})}static getMachineId({machineChannel:e=1}){return r.checkData({machineChannel:e,type:78})}static getCurrentTemperature({machineChannel:e=1}){return r.checkData({machineChannel:e,type:116})}static getTimeToStandbyAfterCollect({machineChannel:e=1}){return r.checkData({machineChannel:e,type:70})}static getTimeToStandbyWithoutCollect({machineChannel:e=1}){return r.checkData({machineChannel:e,type:72})}static getElevatorSpeed({machineChannel:e=1}){return r.checkData({machineChannel:e,type:118})}static getTemperatureExpiration({machineChannel:e=1}){return r.checkData({machineChannel:e,type:99})}static getTemperatureBeforeExpiration({machineChannel:e=1}){return r.checkData({machineChannel:e,type:101})}static getTimeBeforeExpirationByTemperature({machineChannel:e=1}){return r.checkData({machineChannel:e,type:102})}static getTemperatureScale({machineChannel:e=1}){return r.checkData({machineChannel:e,type:103})}static getClockRegisters({machineChannel:e=1}){return r.checkData({machineChannel:e,type:114})}static getMachineActivity({machineChannel:e=1}){return r.checkData({machineChannel:e,type:65})}static getVoltageEngine({machineChannel:e=1,selection:n=1}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:71,aux:109+n})}static getChannelPresence({machineChannel:e=1,selection:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:67,aux:109+n})}static getPushOverProducts({machineChannel:e=1,selection:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:79,aux:109+n})}static getChannelRunningAfterDispense({machineChannel:e=1,selection:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:69,aux:109+n})}static displayConfig({machineChannel:e=1,type:n=128,param2:a=[]}={}){return r.instance.build([2,48,48,128+e,68,n,...a])}static setDisplayStandbyMessage({machineChannel:e=1,message:n=""}={}){n=n.substring(0,32);const a=r.instance.makeDisplayMessage(n);return r.displayConfig({machineChannel:e,type:128,param2:a})}static setDisplayMessageTemporarily({machineChannel:e=1,message:n="",seconds:a=1}){if(n=n.substring(0,32),typeof a=="string"&&(a=parseInt(a)),isNaN(a)||a<1||a>125)throw new Error("Invalid seconds, valid range is 1 to 125");const t=r.instance.makeDisplayMessage(n),s=128+a;return r.displayConfig({machineChannel:e,type:s,param2:t})}static setDisplayMessageUnlimited({machineChannel:e=1,message:n=""}){n=n.substring(0,32);const a=r.instance.makeDisplayMessage(n);return r.displayConfig({machineChannel:e,type:255,param2:a})}static programClock({machineChannel:e=1,date:n=new Date}={}){if(!(n instanceof Date))throw new Error("Invalid date, must be an instance of Date");return r.instance.build([2,48,48,128+e,114,...r.instance.makeTimeFormat(n)])}static eventsConfig({machineChannel:e=1,event:n=null,enable:a=!0}={}){if(n===null)throw new Error("Invalid event");const t=a?49:48;return r.instance.build([2,48,48,128+e,65,n,t])}static eventEnable({machineChannel:e=1,event:n=null}={}){if(n===null)throw new Error("Invalid event");const a=parseInt(n,16);if(isNaN(a)||a<38||a>100)throw new Error("Invalid event");return r.eventsConfig({machineChannel:e,event:n,enable:!0})}static eventDisable({machineChannel:e=1,event:n=null}={}){if(n===null)throw new Error("Invalid event");const a=parseInt(n,16);if(isNaN(a)||a<38||a>100)throw new Error("Invalid event");return r.eventsConfig({machineChannel:e,event:n,enable:!1})}static sendCustomCode({code:e=[]}={}){if(e.length<5)throw new Error("Invalid code, minimum length is 5");return r.instance.build(e)}};O(v,"asHex",!1),O(v,"instance");let E=v;E.instance=new E;var j=Object.defineProperty,W=(i,e,n)=>e in i?j(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,U=(i,e,n)=>W(i,typeof e!="symbol"?e+"":e,n);const S=class h{serialLockerCmdMaker(e){let n;try{n=new Uint8Array(e.length+8),n.set(e,2),n[0]=2,n[1]=e.length+4,n[n.length-2]=3;let a=0;for(let o=1;o<e.length;o++)a+=e[o],a*=parseInt(Math.pow(2,o-1).toString());n[e.length+2]=a%256,n[e.length+3]=666*3%256,n[e.length+4]=666*8%256;let t=0;for(let o=3;o<e.length+5;o++)t+=n[o];n[e.length+5]=t%256;let s=0;for(let o=0;o<n.length-1;o++)s^=n[o];n[n.length-1]=s}catch(a){throw n=new Uint8Array(0),a instanceof Error?new Error(`Error generating command: ${a.message}`):new Error("Error generating command: Unknown error")}return n}serialLockerHexCmd(e){const n=this.serialLockerCmdMaker(e),a=[];for(let t=0;t<n.length;t++){const s=n[t].toString(16).padStart(2,"0");a.push(s)}return a}validateCell(e=1){let n;if(typeof e=="string"?n=parseInt(e):n=e,isNaN(n)||n<1||n>90)throw new Error("Invalid cell number");return n}serialLockerGetStatusCellCmd({cell:e=1,channel:n=1}={}){return e=this.validateCell(e),this.build(new Uint8Array([16,n,e]))}serialLockerGetLightScanCmd({since:e=0,until:n=10,channel:a=1}={}){return this.build(new Uint8Array([32,a,e,n]))}parseCellToColumnRow(e){const n=Math.floor((e-1)/10)+1;let a=e%8;return a===0&&(a=8),[n,a]}serialLockerGetConfigureCellCmd({enable:e=!0,column:n=0,row:a=10,channel:t=1}={}){if(n<0||n>8)throw new Error("Invalid column number");if(a<0||a>10)throw new Error("Invalid row number");let s=1;return e||(s=0),this.build(new Uint8Array([48,t,n,a,s]))}serialLockerGetOpenCmd({cell:e=1,channel:n=1}={}){e=this.validateCell(e);const a=666,t=a%256,s=Math.floor(a/3)%256;return this.build(new Uint8Array([64,n,e,t,s]))}build(e){return h.asHex?this.serialLockerHexCmd(e):g(this.serialLockerCmdMaker(e))}static connection({channel:e=1}={}){return h.instance.build(new Uint8Array([0,e]))}static openCell({cell:e=1,channel:n=1}={}){return e=h.instance.validateCell(e),h.instance.serialLockerGetOpenCmd({cell:e,channel:n})}static statusCell({cell:e=1,channel:n=1}={}){return e=h.instance.validateCell(e),h.instance.serialLockerGetStatusCellCmd({cell:e,channel:n})}static lightScan({since:e=0,until:n=10,channel:a=1}={}){if(e<0||e>10)throw new Error("Invalid since number");if(n<0||n>10)throw new Error("Invalid until number");return h.instance.serialLockerGetLightScanCmd({since:e,until:n,channel:a})}static enableCell({cell:e=1,channel:n=1}={}){e=h.instance.validateCell(e);const[a,t]=h.instance.parseCellToColumnRow(e);return h.instance.serialLockerGetConfigureCellCmd({enable:!0,column:a,row:t,channel:n})}static disableCell({cell:e=1,channel:n=1}={}){e=h.instance.validateCell(e);const[a,t]=h.instance.parseCellToColumnRow(e);return h.instance.serialLockerGetConfigureCellCmd({enable:!1,column:a,row:t,channel:n})}};U(S,"asHex",!1),U(S,"instance");let k=S;k.instance=new k;var V=Object.defineProperty,Q=(i,e,n)=>e in i?V(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,x=(i,e,n)=>Q(i,typeof e!="symbol"?e+"":e,n);const I=class l{build(e){return g(e+l.append)}static connection(){const e=JSON.stringify({action:"CONNECT"});return l.instance.build(e)}static connect(){return l.connection()}static custom(e){if(typeof e!="string")throw new Error("Invalid string");return l.instance.build(e)}static readQR({type:e="production"}={type:"production"}){const n=JSON.stringify({action:"READQR",server:e==="production"?"PROD":"QA"});return l.instance.build(n)}static forceHide(){const e=JSON.stringify({action:"FORCEHIDE"});return l.instance.build(e)}static forceShow(){const e=JSON.stringify({action:"FORCESHOW"});return l.instance.build(e)}static makeSale({amount:e=0,reference:n=null}={}){if(e<=0)throw new Error("Invalid amount");if(typeof e!="number"&&(e=parseFloat(e)),isNaN(e))throw new Error("Invalid amount");if(n&&!/^[A-Z-a-z0-9_\s]+$/g.test(n))throw new Error("Reference must be alphanumeric and the only symbol allowed is midlescore or underscore (- _) or null");const a=e.toFixed(2),t=JSON.stringify({action:"PAYMENT",amount:a,reference:n});return l.instance.build(t)}static getVoucher({folio:e=null}={}){if(!e)throw new Error("Folio must be a number");const n=JSON.stringify({action:"GETVOUCHER",folio:e});return l.instance.build(n)}static info(){const e=JSON.stringify({action:"DEVICEINFO"});return l.instance.build(e)}static keepAlive(){const e=JSON.stringify({action:"KEEPALIVE"});return l.instance.build(e)}static restartApp(){const e=JSON.stringify({action:"RESETAPP"});return l.instance.build(e)}static getConfig(){const e=JSON.stringify({action:"GETCONFIG"});return l.instance.build(e)}static hideButtons(){const e=JSON.stringify({action:"HIDEBUTTONS"});return l.instance.build(e)}static showButtons(){const e=JSON.stringify({action:"SHOWBUTTONS"});return l.instance.build(e)}static demo(){const e=JSON.stringify({action:"DEMO"});return l.instance.build(e)}static refund({amount:e=0,folio:n=null,auth:a=null}={}){if(e<=0)throw new Error("Invalid amount");if(typeof e!="number"&&(e=parseFloat(e)),isNaN(e))throw new Error("Invalid amount");if(!n)throw new Error("Folio must be a number");if(!a)throw new Error("Auth must be a number");const t=e.toFixed(2),s=JSON.stringify({action:"REFUND",amount:t,folio:n,auth:a});return l.instance.build(s)}static exit(){const e=JSON.stringify({action:"EXIT"});return l.instance.build(e)}static init(){const e=JSON.stringify({action:"INIT"});return l.instance.build(e)}};x(I,"append",`\r
3
- `),x(I,"instance");let N=I;N.instance=new N;var Y=Object.defineProperty,q=(i,e,n)=>e in i?Y(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,z=(i,e,n)=>q(i,e+"",n);const R=class C{build(e){return e[3]=this.withChecksum(e),g(e)}withChecksum(e){let n=0;return e.forEach((a,t)=>{t!==3&&(n+=a)}),n}static connection(e=1){return C.instance.build([160,e,0,161])}static deactivate(e=1){return C.connection(e)}static activate(){return C.instance.build([160,1,1,162])}static custom(e){return C.instance.build(e)}};z(R,"instance");let A=R;A.instance=new A;exports.e=A;exports.i=b;exports.l=y;exports.o=E;exports.s=N;exports.u=k;
1
+ "use strict";const g=i=>{if(i instanceof Uint8Array)return i;if(Array.isArray(i))return new Uint8Array(i);if(typeof i=="string")return new TextEncoder().encode(i);if(i instanceof ArrayBuffer)return new Uint8Array(i);throw new Error("Unsupported data type")},P=({data:i,asString:e=!0})=>e?Array.from(i).map(n=>n.toString(16).padStart(2,"0")).join(" "):Array.from(i).map(n=>n.toString(16).padStart(2,"0"));var F=Object.defineProperty,L=(i,e,n)=>e in i?F(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,D=(i,e,n)=>L(i,typeof e!="symbol"?e+"":e,n);const f=class d{build(e){return g(e+d.append)}static connection(){return d.instance.build("CONNECT")}static connect(){return d.connection()}static credits(){return d.instance.build("CREDITS")}static hi(){return d.instance.build("HI")}static ara(){return d.instance.build("ARA")}static custom(e){return d.instance.build(e)}};D(f,"append",`
2
+ `),D(f,"instance");let T=f;T.instance=new T;var H=Object.defineProperty,B=(i,e,n)=>e in i?H(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,$=(i,e,n)=>B(i,typeof e!="symbol"?e+"":e,n);const b=class c{build(e){return c.asHex?P({data:e,asString:!1}):g(e)}serialBoardroidSumHex(e){let n=0;for(let a=0;a<e.length;a++)a===0||a===11||(n+=e[a]);return n}boardroidCheckSum(e){return e[11]=this.serialBoardroidSumHex(e),e}static connection({channel:e=1}={}){const n=c.instance.boardroidCheckSum(new Uint8Array([241,5+e,0,0,0,0,0,0,0,0,242,248]));return c.instance.build(n)}static coinPurseConfiguration({enable:e=!1,high:n=255,low:a=255}={}){const t=c.instance.boardroidCheckSum(new Uint8Array([241,193,e?1:0,n,a,0,0,0,0,0,242,0]));return c.instance.build(t)}static coinPurseDispense({$50c:e=0,$1:n=0,$2:a=0,$5:t=0,$10:s=0}={}){if([e,n,a,t,s].some(u=>isNaN(u)||typeof u=="string"))throw new Error("One of the values is not a number");if(e<1&&n<1&&a<1&&t<1&&s<1)throw new Error("No coins to dispense");const o=c.instance.boardroidCheckSum(new Uint8Array([241,198,e,n,a,t,s,0,0,0,242,0]));return c.instance.build(o)}static coinPurseReadTubes(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,194,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static banknotePurseICTConfigure({enable:e=!1,scrow:n=!1}={}){const a=e?255:0,t=n?255:0,s=c.instance.boardroidCheckSum(new Uint8Array([241,192,a,a,t,t,0,0,0,0,242,0]));return c.instance.build(s)}static banknotePurseOtherConfigure({enable:e=!1,scrow:n=!1}={}){const a=e?1:0,t=n?1:0,s=c.instance.boardroidCheckSum(new Uint8Array([241,192,a,t,0,0,0,0,0,0,242,0]));return c.instance.build(s)}static banknotePurseICTDispense({quantity:e=1,denomination:n=20}){if(e<1)throw new Error("No banknotes to dispense");if([20,50,100,200,500].indexOf(n)===-1)throw new Error("Invalid denomination");const a=[20,50,100,200,500].indexOf(n),t=c.instance.boardroidCheckSum(new Uint8Array([241,197,a,e,0,0,0,0,0,0,242,0]));return c.instance.build(t)}static banknotePurseOtherDispense({$20:e=0,$50:n=0,$100:a=0,$200:t=0,$500:s=0,$1000:o=0}={}){if([e,n,a,t,s,o].some(m=>isNaN(m)||typeof m=="string"))throw new Error("One of the values is not a number");if(e<1&&n<1&&a<1&&t<1&&s<1&&o<1)throw new Error("No banknotes to dispense");const u=c.instance.boardroidCheckSum(new Uint8Array([241,197,e,n,a,t,s,o,0,0,242,0]));return c.instance.build(u)}static banknotePurseAcceptInScrow(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,196,1,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static banknotePurseRejectInScrow(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,196,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static banknotePurseSaveMemory({channel:e=null,$20:n=null,$50:a=null,$100:t=null,$200:s=null,$500:o=null,$1000:u=null}={channel:null,$20:null,$50:null,$100:null,$200:null,$500:null,$1000:null}){if(e===null||n===null||a===null||t===null||s===null||o===null||u===null)throw new Error("One of the values is not defined: "+JSON.stringify({channel:e,$20:n,$50:a,$100:t,$200:s,$500:o,$1000:u}));const m=c.instance.boardroidCheckSum(new Uint8Array([241,200,e,0,n,a,t,s,o,u,242,0]));return c.instance.build(m)}static banknotePurseReadRecycler(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,195,0,0,0,0,0,0,0,0,242,181]));return c.instance.build(e)}static cardReaderDisable(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,205,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static cardReaderDispense({selection:e=1,second_selection:n=null,sensor:a=!0,seconds:t=null,price:s=0}={selection:1,second_selection:null,sensor:!0,seconds:null,price:0}){const o=s/256,u=s%256,m=e+9;let p=0;n&&(p=n+9);let A=0;a||(t||(t=1.5),A=Math.round(t*6.2));const M=c.instance.boardroidCheckSum(new Uint8Array([241,205,1,m,p,A,o,u,0,0,242,0]));return c.instance.build(M)}static coolingRelayConfigure({enable:e=!0}={}){const n=c.instance.boardroidCheckSum(new Uint8Array([241,204,e?1:0,0,0,0,0,0,0,0,242,0]));return c.instance.build(n)}static readTemperature(){const e=c.instance.boardroidCheckSum(new Uint8Array([241,203,0,0,0,0,0,0,0,0,242,0]));return c.instance.build(e)}static dispense({selection:e=1,second_selection:n=null,sensor:a=!0,seconds:t=null}={selection:1,second_selection:null,sensor:!0,seconds:null}){e+=9;const s=e;let o=0;n&&(n+=9,o=n);let u=0;a||(t||(t=1.5),u=Math.round(t*6.2));const m=c.instance.boardroidCheckSum(new Uint8Array([241,199,s,o,u,0,0,0,0,0,242,0]));return c.instance.build(m)}static customCode(e){typeof e[0]=="string"&&(e=e.map(a=>parseInt(a,16)));const n=c.instance.boardroidCheckSum(new Uint8Array(e));return c.instance.build(n)}};$(b,"asHex",!1),$(b,"instance");let w=b;w.instance=new w;var J=Object.defineProperty,G=(i,e,n)=>e in i?J(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,O=(i,e,n)=>G(i,typeof e!="symbol"?e+"":e,n);const y=class r{build(e){const n=this.jofemarCheckSum(e);return r.asHex?P({data:new Uint8Array(n),asString:!1}):g(n)}calcCheckSums(e){const n=[];return n.push(e&255|240),n.push(e&255|15),n}jofemarCheckSum(e){let n=0;for(let t=0;t<e.length;t++)n+=e[t];const a=this.calcCheckSums(n);return e.push(a[0]),e.push(a[1]),e.push(3),new Uint8Array(e)}getTrayAndChannelBySelection(e){if(e=parseInt(e)+109,e=e.toString(),e.length!==3)throw new Error("Invalid selection");const n=(parseInt(e.substring(0,2))+128).toString(16).padStart(2,"0"),a=(parseInt(e.substring(2,3))+128).toString(16).padStart(2,"0");return{channel:parseInt(a,16),tray:parseInt(n,16)}}makeDisplayMessage(e=""){e=e.padEnd(32," ");const n=[];for(let a=0;a<32;a++)n.push(e.charCodeAt(a));return n}makeTimeFormat(e){if(!(e instanceof Date))throw new Error("Invalid date, must be an instance of Date");const n=e.getHours().toString().padStart(2,"0"),a=e.getMinutes().toString().padStart(2,"0"),t=e.getDate().toString().padStart(2,"0"),s=(e.getMonth()+1).toString().padStart(2,"0"),o=e.getFullYear().toString().substring(2,4),u=`${n}:${a} ${t}-${s}-${o}`,m=[];for(let p=0;p<14;p++)m.push(u.charCodeAt(p));return m}static connection({channel:e=1}={}){return r.instance.build([2,48,48,128+e,83,255,255])}static dispense({machineChannel:e=1,selection:n=1,cart:a=!1}={machineChannel:1,selection:1,cart:!1}){if(n=parseInt(n),isNaN(n)||n<1||n>130)throw new Error("Invalid selection");const{channel:t,tray:s}=r.instance.getTrayAndChannelBySelection(n);return r.instance.build([2,48,48,128+e,a?77:86,s,t])}static endCartDispense({machineChannel:e=1}={}){return r.instance.build([2,48,48,128+e,77,128,128])}static collect({machineChannel:e=1}={}){return r.instance.build([2,48,48,128+e,78,255,255])}static reset({machineChannel:e=1,type:n="soldOut"}={}){let a=128;return n==="waiting"?a=129:n==="machine"&&(a=255),r.instance.build([2,48,48,128+e,82,a,255])}static status({machineChannel:e=1}={}){return r.instance.build([2,48,48,128+e,83,255,255])}static lights({machineChannel:e=1,type:n="on"}={}){const a=n==="on"?129:128;return r.instance.build([2,48,48,128+e,76,a,255])}static program({machineChannel:e=1,param1:n=255,param2:a=255}={}){return r.instance.build([2,48,48,128+e,80,n,a])}static programDisplayLanguage({machineChannel:e=1,language:n="spanish"}={}){const a={spanish:48,english:49,french:50};if(!a[n])throw new Error("Invalid language");return r.program({machineChannel:e,param1:73,param2:a[n]})}static programBeeper({machineChannel:e=1,enable:n=!0}){return r.program({machineChannel:e,param1:90,param2:n?49:48})}static programDisableWorkingTemperature({machineChannel:e=1}){return r.program({machineChannel:e,param1:84,param2:128})}static programDisableThermometer({machineChannel:e=1}){return r.programDisableWorkingTemperature({machineChannel:e})}static programWorkingTemperature({machineChannel:e=1,degrees:n=.5,machineType:a="esplus"}={}){typeof n=="string"&&(n=parseFloat(n));const t=a==="iceplus"?6.5:32,s=a==="iceplus"?-25:.5;if(isNaN(n)||n<s||n>t||n%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32");let o=n*2+128;return a==="iceplus"&&(o+=51),o=Math.ceil(o),r.program({param1:84,param2:o,machineChannel:e})}static programIsolationTray({machineChannel:e=1,tray:n=0}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<0||n>12)throw new Error("Invalid tray, valid range is 0 to 12");const a=n===0?128:n+139;return r.program({param1:66,param2:a,machineChannel:e})}static programTimeToStandbyAfterCollect({machineChannel:e=1,seconds:n=15}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<15||n>120)throw new Error("Invalid seconds, valid range is 15 to 120");const a=128+n;return r.program({param1:70,param2:a,machineChannel:e})}static programTimeToStandbyWithoutCollect({machineChannel:e=1,minutes:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>10)throw new Error("Invalid minutes, valid range is 1 to 10");const a=128+n;return r.program({param1:72,param2:a,machineChannel:e})}static programElevatorSpeed({machineChannel:e=1,speed:n="high"}={}){const a={high:49,low:48};if(!a[n])throw new Error("Invalid speed, valid speeds are 'high' and 'low'");return r.program({param1:118,param2:a[n],machineChannel:e})}static programTemperatureExpiration({machineChannel:e=1,enable:n=!1}){return r.program({machineChannel:e,param1:99,param2:n?49:48})}static programMachineAddress({machineChannel:e=1,address:n=1}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>31)throw new Error("Invalid address, valid range is 1 to 31");return r.program({param1:100,param2:128+n,machineChannel:e})}static programTemperatureBeforeExpiration({machineChannel:e=1,degrees:n=.5}){if(typeof n=="string"&&(n=parseFloat(n)),isNaN(n)||n<.5||n>30||n%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30");const a=128+n*2;return r.program({param1:101,param2:a,machineChannel:e})}static programTimeBeforeExpirationByTemperature({machineChannel:e=1,minutes:n=1}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>120)throw new Error("Invalid minutes, valid range is 1 to 120");const a=128+n;return r.program({param1:102,param2:a,machineChannel:e})}static programTemperatureScale({machineChannel:e=1,scale:n="celsius"}={}){const a={celsius:67,fahrenheit:70};if(!a[n])throw new Error("Invalid scale, valid scales are 'celsius' and 'fahrenheit'");return r.program({param1:103,param2:a[n],machineChannel:e})}static programVoltageEngine({machineChannel:e=1,selection:n=1,voltage:a=5}={}){if(typeof a=="string"&&(a=parseFloat(a)),typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");if(isNaN(a)||a<5||a>9.5||a%.5!==0)throw new Error("Invalid voltage, valid range is 5 to 9.5");const t=109+n,s=128+(a-5)*2;return r.instance.build([2,48,48,128+e,71,t,s])}static programPushOverProducts({machineChannel:e=1,selection:n=1,enable:a=!0}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");const t=109+n,s=a?49:48;return r.instance.build([2,48,48,128+e,79,t,s])}static programChannelRunningAfterDispense({machineChannel:e=1,selection:n=1,seconds:a=0}={}){if(typeof n=="string"&&(n=parseInt(n)),typeof a=="string"&&(a=parseFloat(a)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");if(isNaN(a)||a<0||a>10||a%.1!==0)throw new Error("Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1");const t=109+n;a=10*parseFloat(a.toFixed(1));const s=128+a;return r.instance.build([2,48,48,128+e,69,t,s])}static checkData({machineChannel:e=1,type:n=255,aux:a=255}){return r.instance.build([2,48,48,128+e,67,n,a])}static getDisplayLanguage({machineChannel:e=1}){return r.checkData({machineChannel:e,type:73})}static getBeeper({machineChannel:e=1}){return r.checkData({machineChannel:e,type:90})}static getWorkingTemperature({machineChannel:e=1}){return r.checkData({machineChannel:e,type:84})}static getIsolationTray({machineChannel:e=1}){return r.checkData({machineChannel:e,type:66})}static getProgramVersion({machineChannel:e=1}){return r.checkData({machineChannel:e,type:80})}static getFaults({machineChannel:e=1}){return r.checkData({machineChannel:e,type:83})}static getMachineId({machineChannel:e=1}){return r.checkData({machineChannel:e,type:78})}static getCurrentTemperature({machineChannel:e=1}){return r.checkData({machineChannel:e,type:116})}static getTimeToStandbyAfterCollect({machineChannel:e=1}){return r.checkData({machineChannel:e,type:70})}static getTimeToStandbyWithoutCollect({machineChannel:e=1}){return r.checkData({machineChannel:e,type:72})}static getElevatorSpeed({machineChannel:e=1}){return r.checkData({machineChannel:e,type:118})}static getTemperatureExpiration({machineChannel:e=1}){return r.checkData({machineChannel:e,type:99})}static getTemperatureBeforeExpiration({machineChannel:e=1}){return r.checkData({machineChannel:e,type:101})}static getTimeBeforeExpirationByTemperature({machineChannel:e=1}){return r.checkData({machineChannel:e,type:102})}static getTemperatureScale({machineChannel:e=1}){return r.checkData({machineChannel:e,type:103})}static getClockRegisters({machineChannel:e=1}){return r.checkData({machineChannel:e,type:114})}static getMachineActivity({machineChannel:e=1}){return r.checkData({machineChannel:e,type:65})}static getVoltageEngine({machineChannel:e=1,selection:n=1}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:71,aux:109+n})}static getChannelPresence({machineChannel:e=1,selection:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:67,aux:109+n})}static getPushOverProducts({machineChannel:e=1,selection:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:79,aux:109+n})}static getChannelRunningAfterDispense({machineChannel:e=1,selection:n=1}={}){if(typeof n=="string"&&(n=parseInt(n)),isNaN(n)||n<1||n>130)throw new Error("Invalid selection, valid range is 1 to 130");return r.checkData({machineChannel:e,type:69,aux:109+n})}static displayConfig({machineChannel:e=1,type:n=128,param2:a=[]}={}){return r.instance.build([2,48,48,128+e,68,n,...a])}static setDisplayStandbyMessage({machineChannel:e=1,message:n=""}={}){n=n.substring(0,32);const a=r.instance.makeDisplayMessage(n);return r.displayConfig({machineChannel:e,type:128,param2:a})}static setDisplayMessageTemporarily({machineChannel:e=1,message:n="",seconds:a=1}){if(n=n.substring(0,32),typeof a=="string"&&(a=parseInt(a)),isNaN(a)||a<1||a>125)throw new Error("Invalid seconds, valid range is 1 to 125");const t=r.instance.makeDisplayMessage(n),s=128+a;return r.displayConfig({machineChannel:e,type:s,param2:t})}static setDisplayMessageUnlimited({machineChannel:e=1,message:n=""}){n=n.substring(0,32);const a=r.instance.makeDisplayMessage(n);return r.displayConfig({machineChannel:e,type:255,param2:a})}static programClock({machineChannel:e=1,date:n=new Date}={}){if(!(n instanceof Date))throw new Error("Invalid date, must be an instance of Date");return r.instance.build([2,48,48,128+e,114,...r.instance.makeTimeFormat(n)])}static eventsConfig({machineChannel:e=1,event:n=null,enable:a=!0}={}){if(n===null)throw new Error("Invalid event");const t=a?49:48;return r.instance.build([2,48,48,128+e,65,n,t])}static eventEnable({machineChannel:e=1,event:n=null}={}){if(n===null)throw new Error("Invalid event");const a=parseInt(n,16);if(isNaN(a)||a<38||a>100)throw new Error("Invalid event");return r.eventsConfig({machineChannel:e,event:n,enable:!0})}static eventDisable({machineChannel:e=1,event:n=null}={}){if(n===null)throw new Error("Invalid event");const a=parseInt(n,16);if(isNaN(a)||a<38||a>100)throw new Error("Invalid event");return r.eventsConfig({machineChannel:e,event:n,enable:!1})}static sendCustomCode({code:e=[]}={}){if(e.length<5)throw new Error("Invalid code, minimum length is 5");return r.instance.build(e)}};O(y,"asHex",!1),O(y,"instance");let v=y;v.instance=new v;var j=Object.defineProperty,W=(i,e,n)=>e in i?j(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,U=(i,e,n)=>W(i,typeof e!="symbol"?e+"":e,n);const E=class h{serialLockerCmdMaker(e){let n;try{n=new Uint8Array(e.length+8),n.set(e,2),n[0]=2,n[1]=e.length+4,n[n.length-2]=3;let a=0;for(let o=1;o<e.length;o++)a+=e[o],a*=parseInt(Math.pow(2,o-1).toString());n[e.length+2]=a%256,n[e.length+3]=666*3%256,n[e.length+4]=666*8%256;let t=0;for(let o=3;o<e.length+5;o++)t+=n[o];n[e.length+5]=t%256;let s=0;for(let o=0;o<n.length-1;o++)s^=n[o];n[n.length-1]=s}catch(a){throw n=new Uint8Array(0),a instanceof Error?new Error(`Error generating command: ${a.message}`):new Error("Error generating command: Unknown error")}return n}serialLockerHexCmd(e){const n=this.serialLockerCmdMaker(e),a=[];for(let t=0;t<n.length;t++){const s=n[t].toString(16).padStart(2,"0");a.push(s)}return a}validateCell(e=1){let n;if(typeof e=="string"?n=parseInt(e):n=e,isNaN(n)||n<1||n>90)throw new Error("Invalid cell number");return n}serialLockerGetStatusCellCmd({cell:e=1,channel:n=1}={}){return e=this.validateCell(e),this.build(new Uint8Array([16,n,e]))}serialLockerGetLightScanCmd({since:e=0,until:n=10,channel:a=1}={}){return this.build(new Uint8Array([32,a,e,n]))}parseCellToColumnRow(e){const n=Math.floor((e-1)/10)+1;let a=e%8;return a===0&&(a=8),[n,a]}serialLockerGetConfigureCellCmd({enable:e=!0,column:n=0,row:a=10,channel:t=1}={}){if(n<0||n>8)throw new Error("Invalid column number");if(a<0||a>10)throw new Error("Invalid row number");let s=1;return e||(s=0),this.build(new Uint8Array([48,t,n,a,s]))}serialLockerGetOpenCmd({cell:e=1,channel:n=1}={}){e=this.validateCell(e);const a=666,t=a%256,s=Math.floor(a/3)%256;return this.build(new Uint8Array([64,n,e,t,s]))}build(e){return h.asHex?this.serialLockerHexCmd(e):g(this.serialLockerCmdMaker(e))}static connection({channel:e=1}={}){return h.instance.build(new Uint8Array([0,e]))}static openCell({cell:e=1,channel:n=1}={}){return e=h.instance.validateCell(e),h.instance.serialLockerGetOpenCmd({cell:e,channel:n})}static statusCell({cell:e=1,channel:n=1}={}){return e=h.instance.validateCell(e),h.instance.serialLockerGetStatusCellCmd({cell:e,channel:n})}static lightScan({since:e=0,until:n=10,channel:a=1}={}){if(e<0||e>10)throw new Error("Invalid since number");if(n<0||n>10)throw new Error("Invalid until number");return h.instance.serialLockerGetLightScanCmd({since:e,until:n,channel:a})}static enableCell({cell:e=1,channel:n=1}={}){e=h.instance.validateCell(e);const[a,t]=h.instance.parseCellToColumnRow(e);return h.instance.serialLockerGetConfigureCellCmd({enable:!0,column:a,row:t,channel:n})}static disableCell({cell:e=1,channel:n=1}={}){e=h.instance.validateCell(e);const[a,t]=h.instance.parseCellToColumnRow(e);return h.instance.serialLockerGetConfigureCellCmd({enable:!1,column:a,row:t,channel:n})}};U(E,"asHex",!1),U(E,"instance");let S=E;S.instance=new S;var V=Object.defineProperty,Q=(i,e,n)=>e in i?V(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,x=(i,e,n)=>Q(i,typeof e!="symbol"?e+"":e,n);const k=class l{build(e){return g(e+l.append)}static connection(){const e=JSON.stringify({action:"CONNECT"});return l.instance.build(e)}static connect(){return l.connection()}static custom(e){if(typeof e!="string")throw new Error("Invalid string");return l.instance.build(e)}static readQR({type:e="production"}={type:"production"}){const n=JSON.stringify({action:"READQR",server:e==="production"?"PROD":"QA"});return l.instance.build(n)}static forceHide(){const e=JSON.stringify({action:"FORCEHIDE"});return l.instance.build(e)}static forceShow(){const e=JSON.stringify({action:"FORCESHOW"});return l.instance.build(e)}static makeSale({amount:e=0,reference:n=null}={}){if(e<=0)throw new Error("Invalid amount");if(typeof e!="number"&&(e=parseFloat(e)),isNaN(e))throw new Error("Invalid amount");if(n&&!/^[A-Z-a-z0-9_\s]+$/g.test(n))throw new Error("Reference must be alphanumeric and the only symbol allowed is midlescore or underscore (- _) or null");const a=e.toFixed(2),t=JSON.stringify({action:"PAYMENT",amount:a,reference:n});return l.instance.build(t)}static getVoucher({folio:e=null}={}){if(!e)throw new Error("Folio must be a number");const n=JSON.stringify({action:"GETVOUCHER",folio:e});return l.instance.build(n)}static info(){const e=JSON.stringify({action:"DEVICEINFO"});return l.instance.build(e)}static keepAlive(){const e=JSON.stringify({action:"KEEPALIVE"});return l.instance.build(e)}static restartApp(){const e=JSON.stringify({action:"RESETAPP"});return l.instance.build(e)}static getConfig(){const e=JSON.stringify({action:"GETCONFIG"});return l.instance.build(e)}static hideButtons(){const e=JSON.stringify({action:"HIDEBUTTONS"});return l.instance.build(e)}static showButtons(){const e=JSON.stringify({action:"SHOWBUTTONS"});return l.instance.build(e)}static demo(){const e=JSON.stringify({action:"DEMO"});return l.instance.build(e)}static refund({amount:e=0,folio:n=null,auth:a=null}={}){if(e<=0)throw new Error("Invalid amount");if(typeof e!="number"&&(e=parseFloat(e)),isNaN(e))throw new Error("Invalid amount");if(!n)throw new Error("Folio must be a number");if(!a)throw new Error("Auth must be a number");const t=e.toFixed(2),s=JSON.stringify({action:"REFUND",amount:t,folio:n,auth:a});return l.instance.build(s)}static exit(){const e=JSON.stringify({action:"EXIT"});return l.instance.build(e)}static init(){const e=JSON.stringify({action:"INIT"});return l.instance.build(e)}};x(k,"append",`\r
3
+ `),x(k,"instance");let I=k;I.instance=new I;var Y=Object.defineProperty,q=(i,e,n)=>e in i?Y(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n,z=(i,e,n)=>q(i,e+"",n);const R=class C{build(e){return e[3]=this.withChecksum(e),g(e)}withChecksum(e){let n=0;return e.forEach((a,t)=>{t!==3&&(n+=a)}),n}static connection(e=1){return C.instance.build([160,e,0,161])}static deactivate(e=1){return C.connection(e)}static activate(){return C.instance.build([160,1,1,162])}static custom(e){return C.instance.build(e)}};z(R,"instance");let N=R;N.instance=new N;exports.e=N;exports.l=w;exports.o=v;exports.s=I;exports.u=S;
package/dist/relay.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./kernel-DlsHh4AG.cjs"),i=require("./relay-BsUsBpOv.cjs"),r=require("./webserial-core-DlH0cFSH.cjs");class o extends a.Kernel{constructor({filters:t=null,config_port:e=null,no_device:n=1}={}){if(super({filters:t,config_port:e,no_device:n}),this.__internal__.device.type="relay",this.__internal__.auto_response=!0,r.h.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} already exists`);r.h.add(this)}serialMessage(t){const e={code:t,name:null,description:null,request:null,no_code:0};switch(t[1].toString()){case"dd":e.name="Connection with the serial device completed.",e.description="Your connection with the serial device was successfully completed.",e.request="connect",e.no_code=100;break;case"de":break;default:e.name="Unrecognized response",e.description="The response of application was received, but dont identify with any of current parameters",e.request="undefined",e.no_code=400;break}this.dispatch("serial:message",e)}serialRelaySumHex(t){let e=0;return t.forEach((n,s)=>{s!==3&&(e+=n)}),e}serialSetConnectionConstant(t=1){return i.e.connection(t)}async turnOn(){const t=i.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=i.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await a.wait(e),await this.turnOff();return}await this.turnOff(),await a.wait(e),await this.turnOn()}}exports.Relay=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./kernel-CzkmE_OW.cjs"),i=require("./relay-DGFymXOw.cjs"),r=require("./webserial-core-5B5nYtyR.cjs");class o extends a.Kernel{constructor({filters:t=null,config_port:e=null,no_device:n=1}={}){if(super({filters:t,config_port:e,no_device:n}),this.__internal__.device.type="relay",this.__internal__.auto_response=!0,r.h.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} already exists`);r.h.add(this)}serialMessage(t){const e={code:t,name:null,description:null,request:null,no_code:0};switch(t[1].toString()){case"dd":e.name="Connection with the serial device completed.",e.description="Your connection with the serial device was successfully completed.",e.request="connect",e.no_code=100;break;case"de":break;default:e.name="Unrecognized response",e.description="The response of application was received, but dont identify with any of current parameters",e.request="undefined",e.no_code=400;break}this.dispatch("serial:message",e)}serialRelaySumHex(t){let e=0;return t.forEach((n,s)=>{s!==3&&(e+=n)}),e}serialSetConnectionConstant(t=1){return i.e.connection(t)}async turnOn(){const t=i.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=i.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await a.wait(e),await this.turnOff();return}await this.turnOff(),await a.wait(e),await this.turnOn()}}exports.Relay=o;
package/dist/relay.js CHANGED
@@ -1,6 +1,6 @@
1
- import { K as o, w as i } from "./kernel-IUeiZp8d.js";
2
- import { e as a } from "./relay-Dop4mFk-.js";
3
- import { h as s } from "./webserial-core-DGKQCs5a.js";
1
+ import { K as o, w as i } from "./kernel-BblykfpT.js";
2
+ import { e as a } from "./relay-CsdB0FSa.js";
3
+ import { h as s } from "./webserial-core-ByrJ7tlu.js";
4
4
  class p extends o {
5
5
  constructor({ filters: t = null, config_port: e = null, no_device: n = 1 } = {}) {
6
6
  if (super({ filters: t, config_port: e, no_device: n }), this.__internal__.device.type = "relay", this.__internal__.auto_response = !0, s.getCustom(this.typeDevice, n))
@@ -0,0 +1,4 @@
1
+ "use strict";var j=Object.defineProperty,B=i=>{throw TypeError(i)},F=(i,e,t)=>e in i?j(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,g=(i,e,t)=>F(i,typeof e!="symbol"?e+"":e,t),W=(i,e,t)=>e.has(i)||B("Cannot "+t),Q=(i,e,t)=>e.has(i)?B("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),l=(i,e,t)=>(W(i,e,"access private method"),t);class x extends CustomEvent{constructor(e,t){super(e,t)}}class P extends EventTarget{constructor(){super(...arguments),g(this,"__listeners__",{debug:!1}),g(this,"__debug__",!1),g(this,"__listenersCallbacks__",[])}dispatch(e,t=null){const n=new x(e,{detail:t});this.dispatchEvent(n),this.__debug__&&this.dispatchEvent(new x("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,n=100){const s=this;setTimeout(()=>{s.dispatch(e,t)},n)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.__listenersCallbacks__.push({key:e,callback:t}),this.addEventListener(e,t)}off(e,t){this.__listenersCallbacks__=this.__listenersCallbacks__.filter(n=>!(n.key===e&&n.callback===t)),this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(e=>({type:e,listening:this.__listeners__[e]}))}removeAllListeners(){for(const e of this.__listenersCallbacks__)this.removeEventListener(e.key,e.callback);this.__listenersCallbacks__=[],this.__listeners__={debug:!1}}}const w=class a extends P{constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(e=null){e&&e.$checkAndDispatchConnection(),a.instance.dispatch("change",{devices:a.devices,dispatcher:e})}static typeError(e){const t=new Error;throw t.message=`Type ${e} is not supported`,t.name="DeviceTypeError",t}static registerType(e){typeof a.devices[e]>"u"&&(a.devices={...a.devices,[e]:{}})}static add(e){const t=e.typeDevice;typeof a.devices[t]>"u"&&a.registerType(t);const n=e.uuid;if(typeof a.devices[t]>"u"&&a.typeError(t),a.devices[t][n])throw new Error(`Device with id ${n} already exists`);return a.devices[t][n]=e,a.$dispatchChange(e),Object.keys(a.devices[t]).indexOf(n)}static get(e,t){return typeof a.devices[e]>"u"&&a.registerType(e),typeof a.devices[e]>"u"&&a.typeError(e),a.devices[e][t]}static getAll(e=null){return e===null?a.devices:(typeof a.devices[e]>"u"&&a.typeError(e),a.devices[e])}static getList(){return Object.values(a.devices).map(e=>Object.values(e)).flat()}static getByNumber(e,t){return typeof a.devices[e]>"u"&&a.typeError(e),Object.values(a.devices[e]).find(n=>n.deviceNumber===t)??null}static getCustom(e,t=1){return typeof a.devices[e]>"u"&&a.typeError(e),Object.values(a.devices[e]).find(n=>n.deviceNumber===t)??null}static async connectToAll(){const e=a.getList();for(const t of e)t.isConnected||await t.connect().catch(console.warn);return Promise.resolve(a.areAllConnected())}static async disconnectAll(){const e=a.getList();for(const t of e)t.isDisconnected||await t.disconnect().catch(console.warn);return Promise.resolve(a.areAllDisconnected())}static async areAllConnected(){const e=a.getList();for(const t of e)if(!t.isConnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async areAllDisconnected(){const e=a.getList();for(const t of e)if(!t.isDisconnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async getAllConnected(){const e=a.getList();return Promise.resolve(e.filter(t=>t.isConnected))}static async getAllDisconnected(){const e=a.getList();return Promise.resolve(e.filter(t=>t.isDisconnected))}};g(w,"instance"),g(w,"devices",{});let _=w;_.instance||(_.instance=new _);function U(i=100){return new Promise(e=>setTimeout(()=>e(),i))}function V(){return"serial"in navigator}const b={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};var r,p,y,$,v,T,u,R,E,S,A,k,I,f,M,q,N,L,D,O,H;class z extends P{constructor({filters:e=null,config_port:t=b,no_device:n=1,device_listen_on_channel:s=1,bypassSerialBytesConnection:o=!1}={filters:null,config_port:b,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){if(super(),Q(this,r),g(this,"__internal__",{bypassSerialBytesConnection:!1,auto_response:!1,device_number:1,aux_port_connector:0,last_error:{message:null,action:null,code:null,no_code:0},serial:{aux_connecting:"idle",connecting:!1,connected:!1,port:null,last_action:null,response:{length:null,buffer:new Uint8Array([]),as:"uint8",replacer:/[\n\r]+/g,limiter:null,prefixLimiter:!1,sufixLimiter:!0,delimited:!1},reader:null,input_done:null,output_done:null,input_stream:null,output_stream:null,keep_reading:!0,time_until_send_bytes:void 0,delay_first_connection:200,bytes_connection:null,filters:[],config_port:b,queue:[],auto_response:["DD","DD"],free_timeout_ms:50,useRTSCTS:!1},device:{type:"unknown",id:window.crypto.randomUUID(),listen_on_port:null},time:{response_connection:500,response_general:2e3},timeout:{until_response:0},interval:{reconnection:0}}),!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),o&&(this.__internal__.bypassSerialBytesConnection=o),n&&l(this,r,O).call(this,n),s&&["number","string"].includes(typeof s)&&(this.listenOnChannel=s),l(this,r,q).call(this),l(this,r,N).call(this)}set listenOnChannel(e){if(typeof e=="string"&&(e=parseInt(e)),isNaN(e)||e<1||e>255)throw new Error("Invalid port number");this.__internal__.device.listen_on_port=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}get lastAction(){return this.__internal__.serial.last_action}get listenOnChannel(){return this.__internal__.device.listen_on_port??1}set serialFilters(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.filters=e}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.config_port=e}get serialConfigPort(){return this.__internal__.serial.config_port}get useRTSCTS(){return this.__internal__.serial.useRTSCTS}set useRTSCTS(e){this.__internal__.serial.useRTSCTS=e}get isConnected(){const e=this.__internal__.serial.connected,t=l(this,r,p).call(this,this.__internal__.serial.port);return e&&!t&&l(this,r,y).call(this,{error:"Port is closed, not readable or writable."}),this.__internal__.serial.connected=t,this.__internal__.serial.connected}get isConnecting(){return this.__internal__.serial.connecting}get isDisconnected(){const e=this.__internal__.serial.connected,t=l(this,r,p).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),l(this,r,f).call(this,!1),_.$dispatchChange(this)),this.__internal__.serial.connected=t,!this.__internal__.serial.connected}get deviceNumber(){return this.__internal__.device_number}get uuid(){return this.__internal__.device.id}get typeDevice(){return this.__internal__.device.type}get queue(){return this.__internal__.serial.queue}get responseDelimited(){return this.__internal__.serial.response.delimited}set responseDelimited(e){if(typeof e!="boolean")throw new Error("responseDelimited must be a boolean");this.__internal__.serial.response.delimited=e}get responsePrefixLimited(){return this.__internal__.serial.response.prefixLimiter}set responsePrefixLimited(e){if(typeof e!="boolean")throw new Error("responsePrefixLimited must be a boolean");this.__internal__.serial.response.prefixLimiter=e}get responseSufixLimited(){return this.__internal__.serial.response.sufixLimiter}set responseSufixLimited(e){if(typeof e!="boolean")throw new Error("responseSufixLimited must be a boolean");this.__internal__.serial.response.sufixLimiter=e}get responseLimiter(){return this.__internal__.serial.response.limiter}set responseLimiter(e){if(typeof e!="string"&&!(e instanceof RegExp))throw new Error("responseLimiter must be a string or a RegExp");this.__internal__.serial.response.limiter=e}get fixedBytesMessage(){return this.__internal__.serial.response.length}set fixedBytesMessage(e){if(e!==null&&(typeof e!="number"||e<1))throw new Error("Invalid length for fixed bytes message");this.__internal__.serial.response.length=e}get timeoutBeforeResponseBytes(){return this.__internal__.serial.free_timeout_ms||50}set timeoutBeforeResponseBytes(e){if(e!==void 0&&(typeof e!="number"||e<1))throw new Error("Invalid timeout for response bytes");this.__internal__.serial.free_timeout_ms=e??50}get bypassSerialBytesConnection(){return this.__internal__.bypassSerialBytesConnection}set bypassSerialBytesConnection(e){if(typeof e!="boolean")throw new Error("bypassSerialBytesConnection must be a boolean");this.__internal__.bypassSerialBytesConnection=e}async timeout(e,t){this.__internal__.last_error.message="Operation response timed out.",this.__internal__.last_error.action=t,this.__internal__.last_error.code=e,this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),t==="connect"?(this.__internal__.serial.connected=!1,this.dispatch("serial:reconnect",{}),_.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,_.$dispatchChange(this),await this.serialConnect()),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),l(this,r,y).call(this,e)}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{V()||t("Web Serial not supported");const n=l(this,r,$).bind(this);this.on("serial:connecting",n);const s=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(s),this.__internal__.serial.aux_connecting="idle",this.off("serial:connecting",n),this.isConnected?e(!0):t(`${this.typeDevice} device ${this.deviceNumber} not connected`)):this.__internal__.serial.aux_connecting==="connecting"&&(this.__internal__.serial.aux_connecting="idle",this.dispatch("serial:connecting",{active:!0}))},100);this.serialConnect()}))}async serialDisconnect(){try{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(n=>this.serialErrors(n)),await this.__internal__.serial.input_done),t&&(await t.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&this.__internal__.serial.port&&await this.__internal__.serial.port.close()}catch(e){this.serialErrors(e)}finally{this.__internal__.serial.reader=null,this.__internal__.serial.input_done=null,this.__internal__.serial.output_stream=null,this.__internal__.serial.output_done=null,this.__internal__.serial.connected=!1,this.__internal__.serial.port=null,_.$dispatchChange(this)}}getResponseAsArrayBuffer(){this.__internal__.serial.response.as="arraybuffer"}getResponseAsArrayHex(){this.__internal__.serial.response.as="hex"}getResponseAsUint8Array(){this.__internal__.serial.response.as="uint8"}getResponseAsString(){this.__internal__.serial.response.as="string"}async serialPortsSaved(e){const t=this.serialFilters;if(this.__internal__.aux_port_connector<e.length){const n=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[n]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:t});if(!this.__internal__.serial.port)throw new Error("Select another port please")}serialErrors(e){const t=e.toString().toLowerCase();switch(!0){case t.includes("must be handling a user gesture to show a permission request"):case t.includes("the port is closed."):case t.includes("the port is closed or is not writable"):case t.includes("the port is closed or is not readable"):case t.includes("the port is closed or is not readable/writable"):case t.includes("select another port please"):case t.includes("no port selected by the user"):case t.includes("this readable stream reader has been released and cannot be used to cancel its previous owner stream"):this.dispatch("serial:need-permission",{}),_.$dispatchChange(this);break;case t.includes("the port is already open."):case t.includes("failed to open serial port"):this.serialDisconnect().then(async()=>{this.__internal__.aux_port_connector+=1,await this.serialConnect()});break;case t.includes("cannot read properties of undefined (reading 'writable')"):case t.includes("cannot read properties of null (reading 'writable')"):case t.includes("cannot read property 'writable' of null"):case t.includes("cannot read property 'writable' of undefined"):this.serialDisconnect().then(async()=>{await this.serialConnect()});break;case t.includes("'close' on 'serialport': a call to close() is already in progress."):break;case t.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):break;case t.includes("the port is already closed."):break;case t.includes("the device has been lost"):this.dispatch("serial:lost",{}),_.$dispatchChange(this);break;case t.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(e);break}this.dispatch("serial:error",e)}async serialConnect(){try{l(this,r,f).call(this,!0);const e=await l(this,r,R).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const s=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:s})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const n=this;t.onconnect=s=>{var o;n.dispatch("serial:connected",s),l(o=n,r,f).call(o,!1),_.$dispatchChange(this),n.__internal__.serial.queue.length>0&&n.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await n.disconnect()},await U(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await n.timeout(n.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await l(this,r,v).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&l(this,r,u).call(this,this.__internal__.serial.auto_response),await l(this,r,I).call(this)}catch(e){l(this,r,f).call(this,!1),this.serialErrors(e)}}async serialForget(){return await l(this,r,M).call(this)}decToHex(e){return typeof e=="string"&&(e=parseInt(e,10)),e.toString(16)}hexToDec(e){return parseInt(e,16)}hexMaker(e="00",t=2){return e.toString().padStart(t,"0").toLowerCase()}add0x(e){const t=[];return e.forEach((n,s)=>{t[s]="0x"+n}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}validateBytes(e){let t=new Uint8Array(0);if(e instanceof Uint8Array)t=e;else if(typeof e=="string")t=this.parseStringToTextEncoder(e);else if(Array.isArray(e)&&typeof e[0]=="string")t=this.stringArrayToUint8Array(e);else if(Array.isArray(e)&&typeof e[0]=="number")t=new Uint8Array(e);else throw new Error("Invalid data type");return t}async appendToQueue(e,t){const n=this.validateBytes(e);if(["connect","connection:start"].includes(t)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:n,action:t}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(e=1){if(this.__internal__.bypassSerialBytesConnection)return this.__internal__.serial.bytes_connection;throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`)}serialMessage(e){throw console.log(e),this.dispatch("serial:message",{code:e}),new Error("Method not implemented 'serialMessage'")}serialCorruptMessage(e){throw console.log(e),this.dispatch("serial:corrupt-message",{code:e}),new Error("Method not implemented 'serialCorruptMessage'")}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(e){let t=0;return e.forEach(n=>{t+=parseInt(n,16)}),t.toString(16)}toString(){return JSON.stringify({__class:this.typeDevice,device_number:this.deviceNumber,uuid:this.uuid,connected:this.isConnected,connection:this.__internal__.serial.bytes_connection})}softReload(){l(this,r,H).call(this),this.dispatch("serial:soft-reload",{})}async sendConnect(){if(!this.__internal__.serial.bytes_connection)throw new Error("No connection bytes defined");await this.appendToQueue(this.__internal__.serial.bytes_connection,"connect")}async sendCustomCode({code:e=[]}={code:[]}){if(!e)throw new Error("No data to send");this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.validateBytes(e)),await this.appendToQueue(e,"custom")}stringToArrayHex(e){return Array.from(e).map(t=>t.charCodeAt(0).toString(16))}stringToArrayBuffer(e,t=`
2
+ `){return this.parseStringToTextEncoder(e,t).buffer}parseStringToTextEncoder(e="",t=`
3
+ `){const n=new TextEncoder;return e+=t,n.encode(e)}parseStringToBytes(e="",t=`
4
+ `){const n=this.parseStringToTextEncoder(e,t);return Array.from(n).map(s=>s.toString(16))}parseUint8ToHex(e){return Array.from(e).map(t=>t.toString(16))}parseHexToUint8(e){return new Uint8Array(e.map(t=>parseInt(t,16)))}stringArrayToUint8Array(e){const t=[];return typeof e=="string"?this.parseStringToTextEncoder(e).buffer:(e.forEach(n=>{const s=n.replace("0x","");t.push(parseInt(s,16))}),new Uint8Array(t))}parseUint8ArrayToString(e){let t=new Uint8Array(0);e instanceof Uint8Array?t=e:t=this.stringArrayToUint8Array(e),e=this.parseUint8ToHex(t);const n=e.map(s=>parseInt(s,16));return this.__internal__.serial.response.replacer?String.fromCharCode(...n).replace(this.__internal__.serial.response.replacer,""):String.fromCharCode(...n)}hexToAscii(e){const t=e.toString();let n="";for(let s=0;s<t.length;s+=2)n+=String.fromCharCode(parseInt(t.substring(s,2),16));return n}asciiToHex(e){const t=[];for(let n=0,s=e.length;n<s;n++){const o=Number(e.charCodeAt(n)).toString(16);t.push(o)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}r=new WeakSet,p=function(i){return!!(i&&i.readable&&i.writable)},y=function(i=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",i),_.$dispatchChange(this)},$=function(i){this.__internal__.serial.aux_connecting=i.detail.active?"connecting":"finished"},v=async function(i){const e=this.__internal__.serial.port;if(!e||e&&(!e.readable||!e.writable))throw l(this,r,y).call(this,{error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const t=this.validateBytes(i);if(this.useRTSCTS&&await l(this,r,T).call(this,e,5e3),e.writable===null)return;const n=e.writable.getWriter();await n.write(t),n.releaseLock()},T=async function(i,e=5e3){const t=Date.now();for(;;){if(Date.now()-t>e)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:n}=await i.getSignals();if(n)return;await U(100)}},u=function(i=new Uint8Array([]),e=!1){if(i&&i.length>0){const t=this.__internal__.serial.connected;if(this.__internal__.serial.connected=l(this,r,p).call(this,this.__internal__.serial.port),_.$dispatchChange(this),!t&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),l(this,r,f).call(this,!1)),this.__internal__.interval.reconnection&&(clearInterval(this.__internal__.interval.reconnection),this.__internal__.interval.reconnection=0),this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),this.__internal__.serial.response.as==="hex")e?this.serialCorruptMessage(this.parseUint8ToHex(i)):this.serialMessage(this.parseUint8ToHex(i));else if(this.__internal__.serial.response.as==="uint8")e?this.serialCorruptMessage(i):this.serialMessage(i);else if(this.__internal__.serial.response.as==="string"){const n=this.parseUint8ArrayToString(i);if(this.__internal__.serial.response.limiter!==null){const s=n.split(this.__internal__.serial.response.limiter);for(const o in s)s[o]&&(e?this.serialCorruptMessage(s[o]):this.serialMessage(s[o]))}else e?this.serialCorruptMessage(n):this.serialMessage(n)}else{const n=this.stringToArrayBuffer(this.parseUint8ArrayToString(i));e?this.serialCorruptMessage(n):this.serialMessage(n)}}this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},R=async function(){const i=this.serialFilters,e=await navigator.serial.getPorts({filters:i});return i.length===0?e:e.filter(t=>{const n=t.getInfo();return i.some(s=>n.usbProductId===s.usbProductId&&n.usbVendorId===s.usbVendorId)}).filter(t=>!l(this,r,p).call(this,t))},E=function(i){if(i){const e=this.__internal__.serial.response.buffer,t=new Uint8Array(e.length+i.byteLength);t.set(e,0),t.set(new Uint8Array(i),e.length),this.__internal__.serial.response.buffer=t}},S=async function(){this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.__internal__.serial.response.buffer&&l(this,r,u).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)},A=async function(){const i=this.__internal__.serial.response.length;let e=this.__internal__.serial.response.buffer;if(this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),!(i===null||!e||e.length===0)){for(;e.length>=i;){const t=e.slice(0,i);l(this,r,u).call(this,t),e=e.slice(i)}this.__internal__.serial.response.buffer=e,e.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{l(this,r,u).call(this,this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}},k=async function(){const{limiter:i,prefixLimiter:e=!1,sufixLimiter:t=!0}=this.__internal__.serial.response;if(!i)throw new Error("No limiter defined for delimited serial response");const n=this.__internal__.serial.response.buffer;if(!i||!n||n.length===0)return;this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0);let s=new TextDecoder().decode(n);const o=[];if(typeof i=="string"){let c;if(e&&t)c=new RegExp(`${i}([^${i}]+)${i}`,"g");else if(e)c=new RegExp(`${i}([^${i}]*)`,"g");else if(t)c=new RegExp(`([^${i}]+)${i}`,"g");else return;let d,h=0;for(;(d=c.exec(s))!==null;)o.push(new TextEncoder().encode(d[1])),h=c.lastIndex;s=s.slice(h)}else if(i instanceof RegExp){let c,d=0;if(e&&t){const h=new RegExp(`${i.source}(.*?)${i.source}`,"g");for(;(c=h.exec(s))!==null;)o.push(new TextEncoder().encode(c[1])),d=h.lastIndex}else if(t)for(;(c=i.exec(s))!==null;){const h=c.index,m=s.slice(d,h);o.push(new TextEncoder().encode(m)),d=i.lastIndex}else if(e){const h=s.split(i);h.shift();for(const m of h)o.push(new TextEncoder().encode(m));s=""}s=s.slice(d)}for(const c of o)l(this,r,u).call(this,c);const C=new TextEncoder().encode(s);this.__internal__.serial.response.buffer=C,C.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{l(this,r,u).call(this,this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))},I=async function(){const i=this.__internal__.serial.port;if(!i||!i.readable)throw new Error("Port is not readable");const e=i.readable.getReader();this.__internal__.serial.reader=e;try{for(;this.__internal__.serial.keep_reading;){const{value:t,done:n}=await e.read();if(n)break;l(this,r,E).call(this,t),this.__internal__.serial.response.delimited?await l(this,r,k).call(this):this.__internal__.serial.response.length===null?await l(this,r,S).call(this):await l(this,r,A).call(this)}}catch(t){this.serialErrors(t)}finally{e.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}},f=function(i){i!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=i,i?this.dispatch("serial:connecting",{active:!0}):this.dispatch("serial:connecting",{active:!1}))},M=async function(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in SerialPort.prototype&&this.__internal__.serial.port?(await this.__internal__.serial.port.forget(),!0):!1},q=function(){["serial:connected","serial:connecting","serial:reconnect","serial:timeout","serial:disconnected","serial:sent","serial:soft-reload","serial:message","serial:corrupt-message","unknown","serial:need-permission","serial:lost","serial:unsupported","serial:error","debug"].forEach(i=>{this.serialRegisterAvailableListener(i)})},N=function(){const i=this;this.on("internal:queue",async()=>{var e;await l(e=i,r,D).call(e)}),l(this,r,L).call(this)},L=function(){const i=this;navigator.serial.addEventListener("connect",async()=>{i.isDisconnected&&await i.serialConnect().catch(()=>{})})},D=async function(){if(!l(this,r,p).call(this,this.__internal__.serial.port)){l(this,r,y).call(this,{error:"Port is closed, not readable or writable."}),await this.serialConnect();return}if(this.__internal__.timeout.until_response||this.__internal__.serial.queue.length===0)return;const i=this.__internal__.serial.queue[0];let e=this.__internal__.time.response_general;if(i.action==="connect"&&(e=this.__internal__.time.response_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(i.bytes,i.action)},e),this.__internal__.serial.last_action=i.action??"unknown",await l(this,r,v).call(this,i.bytes),this.dispatch("serial:sent",{action:i.action,bytes:i.bytes}),this.__internal__.auto_response){let n=new Uint8Array(0);try{n=this.validateBytes(this.__internal__.serial.auto_response)}catch(s){this.serialErrors(s)}l(this,r,u).call(this,n)}const t=[...this.__internal__.serial.queue];this.__internal__.serial.queue=t.splice(1)},O=function(i=1){this.__internal__.device_number=i,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(i))},H=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}};exports.K=z;exports.h=_;