@danidoble/webserial 4.4.3 → 4.4.5
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.
- package/dist/boardroid.cjs +1 -1
- package/dist/boardroid.js +1 -1
- package/dist/hopper.cjs +1 -1
- package/dist/hopper.js +1 -1
- package/dist/jofemar.cjs +1 -1
- package/dist/jofemar.js +27 -27
- package/dist/{kernel-BZzs36vi.js → kernel-DAorOZat.js} +1 -1
- package/dist/{kernel-7ObJp74F.cjs → kernel-g4zSg1Ll.cjs} +1 -1
- package/dist/kernel.cjs +1 -1
- package/dist/kernel.js +1 -1
- package/dist/locker.cjs +1 -1
- package/dist/locker.js +1 -1
- package/dist/pinpad.cjs +1 -1
- package/dist/pinpad.js +2 -2
- package/dist/pinpax.cjs +1 -1
- package/dist/pinpax.js +1 -1
- package/dist/relay.cjs +1 -1
- package/dist/relay.js +1 -1
- package/dist/types/serial/jofemar.d.ts.map +1 -1
- package/dist/{webserial-core-Zwd9L-Y9.js → webserial-core-CiU9IcKf.js} +1 -9
- package/dist/webserial-core-D49c459A.cjs +4 -0
- package/dist/webserial.cjs +1 -1
- package/dist/webserial.js +3 -3
- package/package.json +6 -6
- package/dist/webserial-core-Co8HLQvu.cjs +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const p=require("./webserial-core-Co8HLQvu.cjs");function u(o=100){return new Promise(n=>setTimeout(()=>n(),o))}function b(){return"serial"in navigator}function g(){return"geolocation"in navigator}function k(){return"crypto"in window}function y(o=1){return o*1e3}function w(o){return o==null||o===""}class e{static enable=!1;static instance=null;static#i=null;static#r=1;static#d(){if(e.enable===!1)throw new Error("Emulator is disabled");return e.enable}static#o(n){return e.instance=n,e.#i=n.typeDevice,e.#r=n.deviceNumber,!0}static#n(n=null){return!e.#d()||n===null&&e.instance===null?!1:(e.instance===null&&n!==null&&e.#o(n),!0)}static#l(){if(e.#i!=="locker")throw new Error("This function is only available for Locker devices");return!0}static#s(){if(e.#i!=="boardroid")throw new Error("This function is only available for Boardroid devices");return!0}static#t(){if(e.#i!=="jofemar")throw new Error("This function is only available for Jofemar devices");return!0}static#c(){if(e.#i==="locker")throw new Error("This function is not available for Locker devices");return!0}static#e(n){e.instance!==null&&e.instance.__emulate({code:n})}static status(n=null){if(!e.#n(n))return!1;let t=[];switch(e.#i){case"locker":t=["0","8"];break;case"boardroid":t=["2",(5+e.#r).toString(16).toUpperCase()];break;case"jofemar":t=["6"];break;default:return!1}e.#e(t)}static dispensed(n=null){if(!e.#n(n))return!1;let t=[];switch(e.#i){case"locker":t=["0","7","4","4","4"];break;case"boardroid":t=["2","D7","A","0","0","0","0","0","0","0","0","0","F2"];break;case"jofemar":t=["6","30"];break;default:return!1}e.#e(t)}static notDispensed(n=null){if(!e.#n(n))return!1;let t=[];switch(e.#i){case"locker":t=["0","7","5","5","5"];break;case"boardroid":t=["2","D7","A","0","0","1","0","0","0","0","0","0","F2"];break;case"jofemar":t=["6","34"];break;default:return!1}e.#e(t)}static gateInactive(n=null){if(!e.#n(n)||!this.#l())return!1;this.#e(["0","7","5","5","5"])}static gateConfigured(n=null){if(!e.#n(n)||!this.#l())return!1;this.#e(["0","6"])}static keyPressed(n=null){if(!e.#n(n)||!e.#t())return!1;const t=["30","31","32","33","34","35","36","37","38","39","2A","23","41","42","43","44"],s=(128+e.#r).toString(16),i=Math.floor(Math.random()*15);e.#e(["2",s,"54",t[i]])}static doorOpened(n=null){if(!e.#n(n)||!this.#c())return!1;let t=[];const s=(128+e.#r).toString(16);switch(e.#i){case"boardroid":t=["2","D8","dc"];break;case"jofemar":t=["2",s,"50","4F"];break}e.#e(t)}static doorClosed(n=null){if(!e.#n(n)||!this.#c())return!1;let t=[];const s=(128+e.#r).toString(16);switch(e.#i){case"boardroid":t=["2","D8","db"];break;case"jofemar":t=["2",s,"50","43"];break}e.#e(t)}static channelDisconnected(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","43","43","FD"])}static channelConnected(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","43","43","FC"])}static channelEmpty(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","43","43","FF"])}static workingTemperature(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","54","16"])}static currentTemperature(n=null){if(!e.#n(n)||!e.#c())return!1;let t=[];const s=(128+e.#r).toString(16);switch(e.#i){case"boardroid":t=["2","D9","44","30"];break;case"jofemar":t=["2",s,"43","74","2B","30","39","2E","31","7F","43"];break}e.#e(t)}static ready(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","30"])}static busy(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","31"])}static invalidTray(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","32"])}static invalidChannel(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","33"])}static emptyChannel(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","34"])}static elevatorJam(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","35"])}static elevatorMalfunction(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","36"])}static phototransistorFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","37"])}static allChannelsEmpty(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","38"])}static productDetectorFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","39"])}static displayDisconnected(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","41"])}static productUnderElevator(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","42"])}static elevatorSettingAlarm(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","43"])}static buttonPanelFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","44"])}static errorWritingEeprom(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","45"])}static errorControlTemperature(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","46"])}static thermometerDisconnected(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","47"])}static thermometerMisconfigured(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","48"])}static thermometerFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","49"])}static errorExtractorConsumption(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4A"])}static channelSearchError(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4B"])}static productExitMouthSearchError(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4C"])}static elevatorInteriorLocked(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4D"])}static productDetectorVerifierError(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4E"])}static waitingForProductRecall(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4F"])}static productExpiredByTemperature(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","50"])}static faultyAutomaticDoor(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","51"])}static rejectLever(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","A0","1"])}static resetCoinPurse(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","A0","2"])}static#f(n,t=null){let s=n[Math.floor(Math.random()*5)];if(t!==null&&!isNaN(parseFloat(t)))switch(t.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}static coinInsertedBox(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["40","41","42","43","44","45"],i=e.#f(s,t);e.#e(["2","A0",i])}static coinInsertedTube(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["50","51","52","53","54","55"],i=e.#f(s,t);e.#e(["2","A0",i])}static#a(n,t=null){let s=n[Math.floor(Math.random()*4)];if(t!==null&&!isNaN(parseFloat(t)))switch(t.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}static banknoteInsertedStacker(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["80","81","82","83","84"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteInsertedEscrow(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["90","91","92","93","94"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteEjected(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["A0","A1","A2","A3","A4"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteInsertedRecycler(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["B0","B1","B2","B3","B4"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteTaken(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","B0","2a"])}static coinPurseEnabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D0","1"])}static coinPurseDisabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D0","0"])}static billPurseDisabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D1","0","0"])}static billPurseEnabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D1","1","1"])}static readTubes(n=null){if(!e.#n(n)||!e.#s())return!1;const t=["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,a,c,l,f]=[t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)]];e.#e(["2","D2",s,i,a,c,l,f])}static readBillPurse(n=null,t=null){if(!e.#n(n)||!e.#s()||e.instance===null)return!1;const s=e.instance,i=["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(s.__banknote_purse.recycler.ict){const a=i[Math.floor(Math.random()*31)];let c="0",l="0",f="0",d="0",h="0";if(t!==null&&!isNaN(parseInt(t)))switch(t.toString()){case"20":c=a;break;case"50":l=a;break;case"100":f=a;break;case"200":d=a;break;case"500":h=a;break}else switch(s.__banknote_purse.recycler.banknote){case 0:c=a;break;case 1:l=a;break;case 2:f=a;break;case 3:d=a;break;case 4:h=a;break}e.#e(["2","D3",c,l,f,d,h,"0"])}else{const[a,c,l,f,d,h]=[i[Math.floor(Math.random()*30)],i[Math.floor(Math.random()*30)],i[Math.floor(Math.random()*30)],i[Math.floor(Math.random()*2)],i[Math.floor(Math.random())],i[Math.floor(Math.random())]];e.#e(["2","D3",a,c,l,f,d,h])}}static banknoteAccepted(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D4","1"])}static banknoteRejected(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D4","0"])}static banknotesDispensed(n=null){if(!e.#n(n)||!e.#s()||e.instance===null)return!1;const t=e.instance,s=["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(t.__banknote_purse.recycler.ict){const i=s[Math.floor(Math.random()*30)];let a="0",c="0",l="0",f="0",d="0";switch(t.__banknote_purse.recycler.banknote){case 0:a=i;break;case 1:c=i;break;case 2:l=i;break;case 3:f=i;break;case 4:d=i;break}e.#e(["2","D5",a,c,l,f,d,"0"])}else{const[i,a,c,l,f,d]=[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())]];e.#e(["2","D5",i,a,c,l,f,d])}}static coinsDispensed(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D6"])}static relayOn(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DA","1"])}static relayOff(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DA","0"])}static nayaxEnabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","1"])}static nayaxDisabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","0"])}static nayaxPreCreditAuthorized(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","3"])}static nayaxCancelRequest(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","4"])}static nayaxSellApproved(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","5"])}static nayaxSellDenied(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","6"])}static nayaxEndSession(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","7"])}static nayaxCancelled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","8"])}static nayaxDispensed(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","A","0"])}static nayaxNotDispensed(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","A","1"])}static fullTray(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4F"])}static setConnection(n=null){if(!e.#n(n)||e.instance===null)return!1;e.instance.__internal__.serial.connected=!0}}class r extends p.s{constructor(){super(),r.registerType("boardroid"),r.registerType("hopper"),r.registerType("jofemar"),r.registerType("locker"),r.registerType("pinpad"),r.registerType("pinpax"),r.registerType("relay")}static addCustom(n,t){r.registerType(n),r.add(t)}static getCustomByUuid(n,t){return r.get(n,t)}static getJofemarByUuid(n){return r.get("jofemar",n)}static getLockerByUuid(n){return r.get("locker",n)}static getRelayByUuid(n){return r.get("relay",n)}static getBoardroidByUuid(n){return r.get("boardroid",n)}static getPinPadByUuid(n){return r.get("pinpad",n)}static getPinPaxByUuid(n){return r.get("pinpax",n)}static getHopperByUuid(n){return r.get("hopper",n)}static getJofemar(n=1){return r.getByNumber("jofemar",n)}static getBoardroid(n=1){return r.getByNumber("boardroid",n)}static getLocker(n=1){return r.getByNumber("locker",n)}static getRelay(n=1){return r.getByNumber("relay",n)}static getPinPad(n=1){return r.getByNumber("pinpad",n)}static getPinPax(n=1){return r.getByNumber("pinpax",n)}static getHopper(n=1){return r.getByNumber("hopper",n)}}r.instance=new r;class M extends p.S{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,t){await super.timeout(n,t),t==="dispense"&&(this.__internal__.dispense.status="no-response")}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(){return this.__internal__.dispense.must_response&&(await u(this.__internal__.time.response_engines+10),this.__internal__.dispense.status==="no-response")?(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",{}),new Promise(n=>{this.__internal__.interval.waiting_sense=setInterval(()=>{switch(this.__internal__.dispense.status){case null:this.internalDispensingProcess()===!1&&(this.internalClearSensing(),this.dispatch("not-dispensed",{reason:"timeout"}),n({status:!1,error:"timeout"}));break;case!0:this.internalClearSensing(),this.__internal__.dispense.status=!0,this.dispatch("dispensed",{}),n({status:!0,error:null});break;case!1:this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-stock"}),n({status:!1,error:null});break;case"elevator-locked":this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"elevator-locked"}),n({status:!1,error:"elevator-locked"});break;case"no-response":this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-response"}),n({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(this.__internal__.dispense.dispensing=!0,!e.enable&&!this.__internal__.serial.connected&&(await this.serialConnect(),!this.__internal__.serial.connected))throw this.__internal__.dispense.dispensing=!1,new Error("Serial device not connected");return this.__internal__.serial.queue.length===0?(await this.appendToQueue(n,"dispense"),await this.internalDispenseStatus()):new Promise(t=>{const s=setInterval(async()=>{if(this.__internal__.serial.queue.length>0)return;clearInterval(s),await this.appendToQueue(n,"dispense");const i=await this.internalDispenseStatus();t(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"),r.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 t=[];for(const s in n.code)t.push(n.code[s].toString().padStart(2,"0").toLowerCase());this.serialMessage(t)}set listenOnPort(n){this.listenOnChannel=n}get listenOnPort(){return this.__internal__.device.listen_on_port??1}fixHexArray(n){return n.map(t=>typeof t=="string"?t.padStart(2,"0").toLowerCase():t.toString(16).padStart(2,"0").toLowerCase())}}exports.Devices=r;exports.Emulator=e;exports.Kernel=M;exports.getSeconds=y;exports.isEmpty=w;exports.supportCrypto=k;exports.supportGeolocation=g;exports.supportWebSerial=b;exports.wait=u;
|
|
1
|
+
"use strict";const p=require("./webserial-core-D49c459A.cjs");function u(o=100){return new Promise(n=>setTimeout(()=>n(),o))}function b(){return"serial"in navigator}function g(){return"geolocation"in navigator}function k(){return"crypto"in window}function y(o=1){return o*1e3}function w(o){return o==null||o===""}class e{static enable=!1;static instance=null;static#i=null;static#r=1;static#d(){if(e.enable===!1)throw new Error("Emulator is disabled");return e.enable}static#o(n){return e.instance=n,e.#i=n.typeDevice,e.#r=n.deviceNumber,!0}static#n(n=null){return!e.#d()||n===null&&e.instance===null?!1:(e.instance===null&&n!==null&&e.#o(n),!0)}static#l(){if(e.#i!=="locker")throw new Error("This function is only available for Locker devices");return!0}static#s(){if(e.#i!=="boardroid")throw new Error("This function is only available for Boardroid devices");return!0}static#t(){if(e.#i!=="jofemar")throw new Error("This function is only available for Jofemar devices");return!0}static#c(){if(e.#i==="locker")throw new Error("This function is not available for Locker devices");return!0}static#e(n){e.instance!==null&&e.instance.__emulate({code:n})}static status(n=null){if(!e.#n(n))return!1;let t=[];switch(e.#i){case"locker":t=["0","8"];break;case"boardroid":t=["2",(5+e.#r).toString(16).toUpperCase()];break;case"jofemar":t=["6"];break;default:return!1}e.#e(t)}static dispensed(n=null){if(!e.#n(n))return!1;let t=[];switch(e.#i){case"locker":t=["0","7","4","4","4"];break;case"boardroid":t=["2","D7","A","0","0","0","0","0","0","0","0","0","F2"];break;case"jofemar":t=["6","30"];break;default:return!1}e.#e(t)}static notDispensed(n=null){if(!e.#n(n))return!1;let t=[];switch(e.#i){case"locker":t=["0","7","5","5","5"];break;case"boardroid":t=["2","D7","A","0","0","1","0","0","0","0","0","0","F2"];break;case"jofemar":t=["6","34"];break;default:return!1}e.#e(t)}static gateInactive(n=null){if(!e.#n(n)||!this.#l())return!1;this.#e(["0","7","5","5","5"])}static gateConfigured(n=null){if(!e.#n(n)||!this.#l())return!1;this.#e(["0","6"])}static keyPressed(n=null){if(!e.#n(n)||!e.#t())return!1;const t=["30","31","32","33","34","35","36","37","38","39","2A","23","41","42","43","44"],s=(128+e.#r).toString(16),i=Math.floor(Math.random()*15);e.#e(["2",s,"54",t[i]])}static doorOpened(n=null){if(!e.#n(n)||!this.#c())return!1;let t=[];const s=(128+e.#r).toString(16);switch(e.#i){case"boardroid":t=["2","D8","dc"];break;case"jofemar":t=["2",s,"50","4F"];break}e.#e(t)}static doorClosed(n=null){if(!e.#n(n)||!this.#c())return!1;let t=[];const s=(128+e.#r).toString(16);switch(e.#i){case"boardroid":t=["2","D8","db"];break;case"jofemar":t=["2",s,"50","43"];break}e.#e(t)}static channelDisconnected(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","43","43","FD"])}static channelConnected(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","43","43","FC"])}static channelEmpty(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","43","43","FF"])}static workingTemperature(n=null){if(!e.#n(n)||!e.#t())return!1;const t=(128+e.#r).toString(16);e.#e(["2",t,"43","54","16"])}static currentTemperature(n=null){if(!e.#n(n)||!e.#c())return!1;let t=[];const s=(128+e.#r).toString(16);switch(e.#i){case"boardroid":t=["2","D9","44","30"];break;case"jofemar":t=["2",s,"43","74","2B","30","39","2E","31","7F","43"];break}e.#e(t)}static ready(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","30"])}static busy(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","31"])}static invalidTray(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","32"])}static invalidChannel(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","33"])}static emptyChannel(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","34"])}static elevatorJam(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","35"])}static elevatorMalfunction(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","36"])}static phototransistorFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","37"])}static allChannelsEmpty(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","38"])}static productDetectorFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","39"])}static displayDisconnected(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","41"])}static productUnderElevator(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","42"])}static elevatorSettingAlarm(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","43"])}static buttonPanelFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","44"])}static errorWritingEeprom(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","45"])}static errorControlTemperature(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","46"])}static thermometerDisconnected(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","47"])}static thermometerMisconfigured(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","48"])}static thermometerFailure(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","49"])}static errorExtractorConsumption(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4A"])}static channelSearchError(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4B"])}static productExitMouthSearchError(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4C"])}static elevatorInteriorLocked(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4D"])}static productDetectorVerifierError(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4E"])}static waitingForProductRecall(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4F"])}static productExpiredByTemperature(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","50"])}static faultyAutomaticDoor(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","51"])}static rejectLever(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","A0","1"])}static resetCoinPurse(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","A0","2"])}static#f(n,t=null){let s=n[Math.floor(Math.random()*5)];if(t!==null&&!isNaN(parseFloat(t)))switch(t.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}static coinInsertedBox(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["40","41","42","43","44","45"],i=e.#f(s,t);e.#e(["2","A0",i])}static coinInsertedTube(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["50","51","52","53","54","55"],i=e.#f(s,t);e.#e(["2","A0",i])}static#a(n,t=null){let s=n[Math.floor(Math.random()*4)];if(t!==null&&!isNaN(parseFloat(t)))switch(t.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}static banknoteInsertedStacker(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["80","81","82","83","84"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteInsertedEscrow(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["90","91","92","93","94"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteEjected(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["A0","A1","A2","A3","A4"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteInsertedRecycler(n=null,t=null){if(!e.#n(n)||!e.#s())return!1;const s=["B0","B1","B2","B3","B4"],i=e.#a(s,t);e.#e(["2","B0",i])}static banknoteTaken(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","B0","2a"])}static coinPurseEnabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D0","1"])}static coinPurseDisabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D0","0"])}static billPurseDisabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D1","0","0"])}static billPurseEnabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D1","1","1"])}static readTubes(n=null){if(!e.#n(n)||!e.#s())return!1;const t=["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,a,c,l,f]=[t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)],t[Math.floor(Math.random()*30)]];e.#e(["2","D2",s,i,a,c,l,f])}static readBillPurse(n=null,t=null){if(!e.#n(n)||!e.#s()||e.instance===null)return!1;const s=e.instance,i=["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(s.__banknote_purse.recycler.ict){const a=i[Math.floor(Math.random()*31)];let c="0",l="0",f="0",d="0",h="0";if(t!==null&&!isNaN(parseInt(t)))switch(t.toString()){case"20":c=a;break;case"50":l=a;break;case"100":f=a;break;case"200":d=a;break;case"500":h=a;break}else switch(s.__banknote_purse.recycler.banknote){case 0:c=a;break;case 1:l=a;break;case 2:f=a;break;case 3:d=a;break;case 4:h=a;break}e.#e(["2","D3",c,l,f,d,h,"0"])}else{const[a,c,l,f,d,h]=[i[Math.floor(Math.random()*30)],i[Math.floor(Math.random()*30)],i[Math.floor(Math.random()*30)],i[Math.floor(Math.random()*2)],i[Math.floor(Math.random())],i[Math.floor(Math.random())]];e.#e(["2","D3",a,c,l,f,d,h])}}static banknoteAccepted(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D4","1"])}static banknoteRejected(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D4","0"])}static banknotesDispensed(n=null){if(!e.#n(n)||!e.#s()||e.instance===null)return!1;const t=e.instance,s=["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(t.__banknote_purse.recycler.ict){const i=s[Math.floor(Math.random()*30)];let a="0",c="0",l="0",f="0",d="0";switch(t.__banknote_purse.recycler.banknote){case 0:a=i;break;case 1:c=i;break;case 2:l=i;break;case 3:f=i;break;case 4:d=i;break}e.#e(["2","D5",a,c,l,f,d,"0"])}else{const[i,a,c,l,f,d]=[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())]];e.#e(["2","D5",i,a,c,l,f,d])}}static coinsDispensed(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","D6"])}static relayOn(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DA","1"])}static relayOff(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DA","0"])}static nayaxEnabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","1"])}static nayaxDisabled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","0"])}static nayaxPreCreditAuthorized(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","3"])}static nayaxCancelRequest(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","4"])}static nayaxSellApproved(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","5"])}static nayaxSellDenied(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","6"])}static nayaxEndSession(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","7"])}static nayaxCancelled(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","8"])}static nayaxDispensed(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","A","0"])}static nayaxNotDispensed(n=null){if(!e.#n(n)||!e.#s())return!1;e.#e(["2","DD","A","1"])}static fullTray(n=null){if(!e.#n(n)||!e.#t())return!1;e.#e(["6","4F"])}static setConnection(n=null){if(!e.#n(n)||e.instance===null)return!1;e.instance.__internal__.serial.connected=!0}}class r extends p.s{constructor(){super(),r.registerType("boardroid"),r.registerType("hopper"),r.registerType("jofemar"),r.registerType("locker"),r.registerType("pinpad"),r.registerType("pinpax"),r.registerType("relay")}static addCustom(n,t){r.registerType(n),r.add(t)}static getCustomByUuid(n,t){return r.get(n,t)}static getJofemarByUuid(n){return r.get("jofemar",n)}static getLockerByUuid(n){return r.get("locker",n)}static getRelayByUuid(n){return r.get("relay",n)}static getBoardroidByUuid(n){return r.get("boardroid",n)}static getPinPadByUuid(n){return r.get("pinpad",n)}static getPinPaxByUuid(n){return r.get("pinpax",n)}static getHopperByUuid(n){return r.get("hopper",n)}static getJofemar(n=1){return r.getByNumber("jofemar",n)}static getBoardroid(n=1){return r.getByNumber("boardroid",n)}static getLocker(n=1){return r.getByNumber("locker",n)}static getRelay(n=1){return r.getByNumber("relay",n)}static getPinPad(n=1){return r.getByNumber("pinpad",n)}static getPinPax(n=1){return r.getByNumber("pinpax",n)}static getHopper(n=1){return r.getByNumber("hopper",n)}}r.instance=new r;class M extends p.S{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,t){await super.timeout(n,t),t==="dispense"&&(this.__internal__.dispense.status="no-response")}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(){return this.__internal__.dispense.must_response&&(await u(this.__internal__.time.response_engines+10),this.__internal__.dispense.status==="no-response")?(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",{}),new Promise(n=>{this.__internal__.interval.waiting_sense=setInterval(()=>{switch(this.__internal__.dispense.status){case null:this.internalDispensingProcess()===!1&&(this.internalClearSensing(),this.dispatch("not-dispensed",{reason:"timeout"}),n({status:!1,error:"timeout"}));break;case!0:this.internalClearSensing(),this.__internal__.dispense.status=!0,this.dispatch("dispensed",{}),n({status:!0,error:null});break;case!1:this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-stock"}),n({status:!1,error:null});break;case"elevator-locked":this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"elevator-locked"}),n({status:!1,error:"elevator-locked"});break;case"no-response":this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-response"}),n({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(this.__internal__.dispense.dispensing=!0,!e.enable&&!this.__internal__.serial.connected&&(await this.serialConnect(),!this.__internal__.serial.connected))throw this.__internal__.dispense.dispensing=!1,new Error("Serial device not connected");return this.__internal__.serial.queue.length===0?(await this.appendToQueue(n,"dispense"),await this.internalDispenseStatus()):new Promise(t=>{const s=setInterval(async()=>{if(this.__internal__.serial.queue.length>0)return;clearInterval(s),await this.appendToQueue(n,"dispense");const i=await this.internalDispenseStatus();t(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"),r.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 t=[];for(const s in n.code)t.push(n.code[s].toString().padStart(2,"0").toLowerCase());this.serialMessage(t)}set listenOnPort(n){this.listenOnChannel=n}get listenOnPort(){return this.__internal__.device.listen_on_port??1}fixHexArray(n){return n.map(t=>typeof t=="string"?t.padStart(2,"0").toLowerCase():t.toString(16).padStart(2,"0").toLowerCase())}}exports.Devices=r;exports.Emulator=e;exports.Kernel=M;exports.getSeconds=y;exports.isEmpty=w;exports.supportCrypto=k;exports.supportGeolocation=g;exports.supportWebSerial=b;exports.wait=u;
|
package/dist/kernel.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-g4zSg1Ll.cjs"),r="4.1.9";exports.Devices=e.Devices;exports.Kernel=e.Kernel;exports.version=r;
|
package/dist/kernel.js
CHANGED
package/dist/locker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-g4zSg1Ll.cjs"),i=require("./relay-E3NCcSjS.cjs");class r extends n.Kernel{#s=!1;#e=0;#t=0;_default_fallback_listen_on_channel=3;constructor({filters:s=null,config_port:e,no_device:t=1,device_listen_on_channel:a=3,socket:l=!1}={}){if(super({filters:s,config_port:e,no_device:t,device_listen_on_channel:a,socket:l}),this.__internal__.device.type="locker",n.Devices.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} already exists`);this.__internal__.time.response_engines=1e3,this.__internal__.dispense.limit_counter=1,n.Devices.add(this),this.#r()}#r(){const s=["percentage:disable","percentage:enable","percentage:open"];for(const e of s)this.serialRegisterAvailableListener(e)}serialMessage(s){s=this.fixHexArray(s);const e={code:s,name:null,description:null,request:null,no_code:0};switch(s[1]){case"08":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"07":switch(s[4]){case"00":e.name="Cell closed.",e.description="The selected cell is closed.",e.request="dispense",e.no_code=1102,this.__internal__.dispense.status=!1,this.dispatch("dispensed",{}),this.#s&&this.#e>=89?(e.finished_test=!0,this.#s=!1,this.#e=0):this.#s&&(e.finished_test=!1);break;case"01":case"04":e.name="Cell open.",e.description="The selected cell was open successfully.",e.request="dispense",e.no_code=102,this.__internal__.dispense.status=!0,this.dispatch("dispensed",{}),this.#s&&this.#e>=89?(e.finished_test=!0,this.#s=!1,this.#e=0):this.#s&&(e.finished_test=!1);break;case"05":e.name="Cell inactive.",e.description="The selected cell is inactive or doesn't exist.",e.request="dispense",e.no_code=101,this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{}),this.#s&&this.#e>=89?(e.finished_test=!0,this.#s=!1,this.#e=0):this.#s&&(e.finished_test=!1);break}break;case"06":e.name="Configuration applied.",e.description="The configuration was successfully applied.",e.request="configure cell",e.no_code=103;break;default:e.request="undefined",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400;break}this.dispatch("serial:message",e)}serialSetConnectionConstant(s=3){return i.u.connection({channel:s})}#i(){this.#s=!1,this.#e=0,this.#t=0}#n(s=null){this.#t=Math.round(this.#e*100/80),this.dispatch("percentage:open",{percentage:this.#t,dispensed:s})}#a(){this.#t=Math.round(this.#e*100/80),this.dispatch("percentage:enable",{percentage:this.#t})}#l(){this.#t=Math.round(this.#e*100/80),this.dispatch("percentage:disable",{percentage:this.#t})}async dispense({cell:s=1,status:e=!0}={}){return setTimeout(()=>{e===!0?this.#h():this.#c()},this.__internal__.time.response_engines/2),await this.internalDispense(i.u.openCell({cell:s,channel:this.__internal__.device.listen_on_port||this._default_fallback_listen_on_channel}))}#h(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)}#c(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)}async status({cell:s=1}={}){return await this.appendToQueue(i.u.statusCell({cell:s,channel:this.__internal__.device.listen_on_port||this._default_fallback_listen_on_channel}),"status")}async lightScan({since:s=0,until:e=10}={}){return await this.appendToQueue(i.u.lightScan({channel:this.__internal__.device.listen_on_port||this._default_fallback_listen_on_channel,since:s,until:e}),"light-scan")}async enable({cell:s=1}={}){return await this.appendToQueue(i.u.enableCell({cell:s,channel:this.__internal__.device.listen_on_port||this._default_fallback_listen_on_channel}),"activate")}async disable({cell:s=1}={}){await this.appendToQueue(i.u.disableCell({cell:s,channel:this.__internal__.device.listen_on_port||this._default_fallback_listen_on_channel}),"disable")}async openAll(){if(this.isDispensing)throw new Error("Another dispensing process is running");this.#i(),this.#s=!0,this.#n();const s=[];for(let e=1;e<=80;e++){const t=await this.dispense({cell:e,status:!0});s.push(t),this.#e=e,this.#n()}this.#e=80,this.#n(s),this.#i()}async enableAll(){this.#i(),this.#s=!0,this.#a();for(let s=1;s<=80;s++)await this.enable({cell:s}),await n.wait(100),this.#e=s,this.#a();this.#e=80,this.#a(),this.#i()}async disableAll(){this.#i(),this.#s=!0,this.#l();for(let s=1;s<=80;s++)await this.disable({cell:s}),await n.wait(100),this.#e=s,this.#l();this.#e=80,this.#l(),this.#i()}}exports.Locker=r;
|
package/dist/locker.js
CHANGED
package/dist/pinpad.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("./kernel-g4zSg1Ll.cjs");var di="0123456789abcdefghijklmnopqrstuvwxyz";function G(n){return di.charAt(n)}function _i(n,t){return n&t}function St(n,t){return n|t}function le(n,t){return n^t}function fe(n,t){return n&~t}function gi(n){if(n==0)return-1;var t=0;return(n&65535)==0&&(n>>=16,t+=16),(n&255)==0&&(n>>=8,t+=8),(n&15)==0&&(n>>=4,t+=4),(n&3)==0&&(n>>=2,t+=2),(n&1)==0&&++t,t}function mi(n){for(var t=0;n!=0;)n&=n-1,++t;return t}var ht="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ke="=";function yt(n){var t,e,i="";for(t=0;t+3<=n.length;t+=3)e=parseInt(n.substring(t,t+3),16),i+=ht.charAt(e>>6)+ht.charAt(e&63);for(t+1==n.length?(e=parseInt(n.substring(t,t+1),16),i+=ht.charAt(e<<2)):t+2==n.length&&(e=parseInt(n.substring(t,t+2),16),i+=ht.charAt(e>>2)+ht.charAt((e&3)<<4));(i.length&3)>0;)i+=ke;return i}function pe(n){var t="",e,i=0,r=0;for(e=0;e<n.length&&n.charAt(e)!=ke;++e){var s=ht.indexOf(n.charAt(e));s<0||(i==0?(t+=G(s>>2),r=s&3,i=1):i==1?(t+=G(r<<2|s>>4),r=s&15,i=2):i==2?(t+=G(r),t+=G(s>>2),r=s&3,i=3):(t+=G(r<<2|s>>4),t+=G(s&15),i=0))}return i==1&&(t+=G(r<<2)),t}var ct,yi={decode:function(n){var t;if(ct===void 0){var e="0123456789ABCDEF",i=` \f
|
|
2
2
|
\r \u2028\u2029`;for(ct={},t=0;t<16;++t)ct[e.charAt(t)]=t;for(e=e.toLowerCase(),t=10;t<16;++t)ct[e.charAt(t)]=t;for(t=0;t<i.length;++t)ct[i.charAt(t)]=-1}var r=[],s=0,a=0;for(t=0;t<n.length;++t){var o=n.charAt(t);if(o=="=")break;if(o=ct[o],o!=-1){if(o===void 0)throw new Error("Illegal character at offset "+t);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}},et,Jt={decode:function(n){var t;if(et===void 0){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=`= \f
|
|
3
3
|
\r \u2028\u2029`;for(et=Object.create(null),t=0;t<64;++t)et[e.charAt(t)]=t;for(et["-"]=62,et._=63,t=0;t<i.length;++t)et[i.charAt(t)]=-1}var r=[],s=0,a=0;for(t=0;t<n.length;++t){var o=n.charAt(t);if(o=="=")break;if(o=et[o],o!=-1){if(o===void 0)throw new Error("Illegal character at offset "+t);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 t=Jt.re.exec(n);if(t)if(t[1])n=t[1];else if(t[2])n=t[2];else throw new Error("RegExp out of sync");return Jt.decode(n)}},ut=1e13,mt=(function(){function n(t){this.buf=[+t||0]}return n.prototype.mulAdd=function(t,e){var i=this.buf,r=i.length,s,a;for(s=0;s<r;++s)a=i[s]*t+e,a<ut?e=0:(e=0|a/ut,a-=e*ut),i[s]=a;e>0&&(i[s]=e)},n.prototype.sub=function(t){var e=this.buf,i=e.length,r,s;for(r=0;r<i;++r)s=e[r]-t,s<0?(s+=ut,t=1):t=0,e[r]=s;for(;e[e.length-1]===0;)e.pop()},n.prototype.toString=function(t){if((t||10)!=10)throw new Error("only base 10 is supported");for(var e=this.buf,i=e[e.length-1].toString(),r=e.length-2;r>=0;--r)i+=(ut+e[r]).toString().substring(1);return i},n.prototype.valueOf=function(){for(var t=this.buf,e=0,i=t.length-1;i>=0;--i)e=e*ut+t[i];return e},n.prototype.simplify=function(){var t=this.buf;return t.length==1?t[0]:this},n})(),Fe="…",bi=/^(\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)?)?$/,Pi=/^(\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 lt(n,t){return n.length>t&&(n=n.substring(0,t)+Fe),n}var Ht=(function(){function n(t,e){this.hexDigits="0123456789ABCDEF",t instanceof n?(this.enc=t.enc,this.pos=t.pos):(this.enc=t,this.pos=e)}return n.prototype.get=function(t){if(t===void 0&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset ".concat(t," on a stream of length ").concat(this.enc.length));return typeof this.enc=="string"?this.enc.charCodeAt(t):this.enc[t]},n.prototype.hexByte=function(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(t&15)},n.prototype.hexDump=function(t,e,i){for(var r="",s=t;s<e;++s)if(r+=this.hexByte(this.get(s)),i!==!0)switch(s&15){case 7:r+=" ";break;case 15:r+=`
|
|
4
4
|
`;break;default:r+=" "}return r},n.prototype.isASCII=function(t,e){for(var i=t;i<e;++i){var r=this.get(i);if(r<32||r>176)return!1}return!0},n.prototype.parseStringISO=function(t,e){for(var i="",r=t;r<e;++r)i+=String.fromCharCode(this.get(r));return i},n.prototype.parseStringUTF=function(t,e){for(var i="",r=t;r<e;){var s=this.get(r++);s<128?i+=String.fromCharCode(s):s>191&&s<224?i+=String.fromCharCode((s&31)<<6|this.get(r++)&63):i+=String.fromCharCode((s&15)<<12|(this.get(r++)&63)<<6|this.get(r++)&63)}return i},n.prototype.parseStringBMP=function(t,e){for(var i="",r,s,a=t;a<e;)r=this.get(a++),s=this.get(a++),i+=String.fromCharCode(r<<8|s);return i},n.prototype.parseTime=function(t,e,i){var r=this.parseStringISO(t,e),s=(i?bi:Pi).exec(r);return s?(i&&(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(t,e){for(var i=this.get(t),r=i>127,s=r?255:0,a,o="";i==s&&++t<e;)i=this.get(t);if(a=e-t,a===0)return r?-1:0;if(a>4){for(o=i,a<<=3;((+o^s)&128)==0;)o=+o<<1,--a;o="("+a+` bit)
|
package/dist/pinpad.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as mi, a as yi, D as le, i as z, b as fe, w as pe } from "./kernel-
|
|
1
|
+
import { K as mi, a as yi, D as le, i as z, b as fe, w as pe } from "./kernel-DAorOZat.js";
|
|
2
2
|
var bi = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
3
3
|
function G(n) {
|
|
4
4
|
return bi.charAt(n);
|
|
@@ -2678,7 +2678,7 @@ const nr = l.toObjectSet([
|
|
|
2678
2678
|
`).forEach(function(a) {
|
|
2679
2679
|
r = a.indexOf(":"), e = a.substring(0, r).trim().toLowerCase(), i = a.substring(r + 1).trim(), !(!e || t[e] && nr[e]) && (e === "set-cookie" ? t[e] ? t[e].push(i) : t[e] = [i] : t[e] = t[e] ? t[e] + ", " + i : i);
|
|
2680
2680
|
}), t;
|
|
2681
|
-
}, De = Symbol("internals");
|
|
2681
|
+
}, De = /* @__PURE__ */ Symbol("internals");
|
|
2682
2682
|
function gt(n) {
|
|
2683
2683
|
return n && String(n).trim().toLowerCase();
|
|
2684
2684
|
}
|
package/dist/pinpax.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-g4zSg1Ll.cjs"),s=require("./relay-E3NCcSjS.cjs");class p extends c.Kernel{__pinpax__={server:"DEV",businessId:null,encryptionKey:null,apiKey:null,asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1,sale_init:"idle",sale_login:"idle"}};constructor({filters:i=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:t=1,device_listen_on_channel:a=1,socket:n=!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,socket:!1}){if(super({filters:i,config_port:e,no_device:t,device_listen_on_channel:a,socket:n}),this.__internal__.device.type="pinpax",c.Devices.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} 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
|
`,this.#t(),c.Devices.add(this),this.getResponseAsString()}#t(){const i=["buttons-status","init-app","connectMessage","voucher","info","keep-alive","reset-app","get-config","payment","error","refund","login"];for(const e of i)this.serialRegisterAvailableListener(e)}set businessId(i){this.__pinpax__.businessId=i}get businessId(){return this.__pinpax__.businessId}set encryptionKey(i){this.__pinpax__.encryptionKey=i}get encryptionKey(){return this.__pinpax__.encryptionKey}set apiKey(i){this.__pinpax__.apiKey=i}get apiKey(){return this.__pinpax__.apiKey}set server(i){this.__pinpax__.server=i}get server(){return this.__pinpax__.server}serialMessage(i){let e=null;try{e=JSON.parse(i),e.request||(e.request=this.lastAction),e.name||(e.name=this.lastAction)}catch(t){console.error("Error parsing response",t,i),this.dispatch("serial:message",i);return}switch(e.response){case"INIT":this.dispatch("init",{name:"INIT",request:this.lastAction,status:"ok"}),this.__pinpax__.waiting.sale_init==="waiting"&&(this.__pinpax__.waiting.sale_init="received");break;case"INITAPP":this.dispatch("init-app",{name:"INITAPP",request:this.lastAction,status:"started"}),this.__pinpax__.waiting.sale_init==="waiting"?this.__pinpax__.waiting.sale_init="received":this.#n().then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{name:"CONNECT",request:this.lastAction,status:"connected"}),this.#r().then(()=>{});break;case"LOGIN":e.name||(e.name="LOGIN"),this.__pinpax__.waiting.sale_login==="waiting"&&(this.__pinpax__.waiting.sale_login="received"),this.dispatch("login",e);break;case"LASTVOUCHER":e.name||(e.name="LASTVOUCHER"),this.dispatch("voucher",e),this.__pinpax__.waiting.voucher&&(this.__pinpax__.asyncResponses.voucher=e,this.__pinpax__.waiting.voucher=!1);break;case"DEVICEINFO":e.name||(e.name="DEVICEINFO"),this.dispatch("info",e);break;case"KEEPALIVE":this.dispatch("keep-alive",{name:"KEEPALIVE",request:this.lastAction,status:"alive"});break;case"RESETAPP":this.dispatch("reset-app",{name:"RESETAPP",request:this.lastAction,status:"accepted"});break;case"GETCONFIG":e.name||(e.name="GETCONFIG"),this.dispatch("get-config",e);break;case"HIDEBUTTONS":this.dispatch("buttons-status",{name:"HIDEBUTTONS",request:this.lastAction,hidden:!0});break;case"SHOWBUTTONS":this.dispatch("buttons-status",{name:"SHOWBUTTONS",request:this.lastAction,hidden:!1});break;case"PAYMENT_PROCESS":e.name||(e.name="PAYMENT_PROCESS"),this.dispatch("payment",{name:"PAYMENT_PROCESS",request:this.lastAction,status:"starting",amount:e.amount,reference:e.referecence});break;case"INSERT_CARD":this.dispatch("payment",{name:"INSERT_CARD",request:this.lastAction,status:"insert card"});break;case"CARD_DATA":e.name||(e.name="CARD_DATA"),this.dispatch("payment",{name:"CARD_DATA",request:this.lastAction,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":e.name||(e.name="MERCHANT"),this.dispatch("payment",{request:this.lastAction,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":e.name||(e.name="TRANSACTION_RESULT"),this.#o({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":e.name||(e.name="ERROR"),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{name:"ERROR",request:this.lastAction,status:"error",response:e}),this.dispatch("payment",{name:"ERROR",request:this.lastAction,status:"error",response:e});break;case"REFUND":this.dispatch("refund",{name:"ERROR",request:this.lastAction,status:"refund",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(){return s.s.connection()}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(i={}){if(typeof i!="object")throw new Error("Invalid object");if(i.constructor!==Object)throw new Error("Invalid object");if(Object.keys(i).length===0)throw new Error("Empty object");if(i.action===void 0||i.action===null)throw new Error("Invalid object add action");const e=JSON.stringify(i),t=this.parseStringToBytes(e,`\r
|
|
3
3
|
`);await this.appendToQueue(this.stringArrayToUint8Array(t),"custom")}async connectMessage(){await this.appendToQueue(s.s.connect(),"connect:message")}async#e(){if(this.isDisconnected)throw new Error("Device is disconnected");return this.queue.length===0?!0:new Promise(i=>{const e=setInterval(()=>{this.queue.length===0&&(clearInterval(e),i(!0))},500)})}async#i({type:i="production"}={}){const e=s.s.readQR({type:i});return await this.appendToQueue(e,"read-qr")}async#s(){await this.appendToQueue(s.s.forceHide(),"force-hide")}async#a(){await this.appendToQueue(s.s.forceShow(),"force-show")}async#n(){await this.connectMessage()}async#r(){await this.hideButtons()}#o(i){this.dispatch("payment",i),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=i)}cancelSaleRequestInProcess(){this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:{}})}async#c(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_login==="waiting"&&(this.__pinpax__.waiting.sale_login="timeout",e(new Error("Login timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_login==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async#p(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_init==="waiting"&&(this.__pinpax__.waiting.sale_init="timeout",e(new Error("Init timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_init==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async makeSale({amount:i=0,reference:e=null}={amount:0,reference:null}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.sale)throw new Error("Already waiting for sale response");const t=s.s.makeSale({amount:i,reference:e});this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await this.#e();let a=!1;try{this.__pinpax__.waiting.sale_login="waiting",await this.login(),await this.#c(),this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="waiting",await this.init(),await this.#p(),this.__pinpax__.waiting.sale_init="idle"}catch(n){a=!0,this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="idle",this.__pinpax__.waiting.sale=!1,this.dispatch("error",{name:"ERROR",request:this.lastAction,status:"error",response:"Error during login/init before sale",error:n})}return a?!1:(await this.appendToQueue(t,"make-sale"),new Promise(n=>{const r=setInterval(()=>{if(this.__pinpax__.asyncResponses.sale){const o=this.__pinpax__.asyncResponses.sale;this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.waiting.sale=!1,clearInterval(r),n(o.approved)}},100)}))}async getVoucher({folio:i=null}={}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.voucher)throw new Error("Already waiting for voucher");if(!i)throw new Error("Folio is required");this.__pinpax__.waiting.voucher=!0,this.__pinpax__.asyncResponses.voucher=null;const e=s.s.getVoucher({folio:i});return this.queue.length>0&&await this.#e(),await this.appendToQueue(e,"get-voucher"),new Promise((t,a)=>{const n=setTimeout(()=>{this.__pinpax__.waiting.voucher=!1,a("Timeout")},1e4),r=setInterval(()=>{if(this.__pinpax__.asyncResponses.voucher){const o=this.__pinpax__.asyncResponses.voucher;this.__pinpax__.asyncResponses.voucher=null,this.__pinpax__.waiting.voucher=!1,clearInterval(r),clearTimeout(n),t(o.voucher)}},100)})}async info(){await this.appendToQueue(s.s.info(),"info")}async keepAlive(){await this.appendToQueue(s.s.keepAlive(),"keep-alive")}async restartApp(){await this.appendToQueue(s.s.restartApp(),"reset-app")}async getConfig(){return await this.appendToQueue(s.s.getConfig(),"get-config")}async hideButtons(){return await this.appendToQueue(s.s.hideButtons(),"hide-buttons"),await this.#s()}async showButtons(){return await this.appendToQueue(s.s.showButtons(),"show-buttons"),await this.#a()}async demo(){return console.warn("RUNNING DEMO APP, BE CAREFUL"),await this.appendToQueue(s.s.demo(),"demo")}async refund({amount:i=0,folio:e=null,auth:t=null}={}){return await this.appendToQueue(s.s.refund({amount:i,folio:e,auth:t}),"refund")}async readProductionQR(){return await this.#i({type:"production"})}async readQualityAssuranceQR(){return this.#i({type:"QA"})}async exit(){return await this.appendToQueue(s.s.exit(),"exit-app")}async init(){await this.appendToQueue(s.s.init(),"init-app")}async login(){if(!this.apiKey||!this.businessId||!this.encryptionKey||!this.server)throw new Error("Invalid data to login check apiKey, businessId, encryptionKey, server");const i=JSON.stringify({action:"LOGIN_MIT",server:this.__pinpax__.server,business_id:this.__pinpax__.businessId,encryption_key:this.__pinpax__.encryptionKey,api_key:this.__pinpax__.apiKey}),e=this.parseStringToBytes(i,`\r
|
|
4
4
|
`);await this.appendToQueue(e,"login")}}exports.PinPax=p;
|
package/dist/pinpax.js
CHANGED
package/dist/relay.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-g4zSg1Ll.cjs"),a=require("./relay-E3NCcSjS.cjs");class r extends n.Kernel{constructor({filters:t=null,config_port:e,no_device:s=1,socket:i=!1}={}){if(super({filters:t,config_port:e,no_device:s,socket:i}),this.__internal__.device.type="relay",this.__internal__.auto_response=!1,this.__internal__.serial.auto_response=[2,6,221,221,240,207,3],n.Devices.getCustom(this.typeDevice,s))throw new Error(`Device ${this.typeDevice} ${s} already exists`);n.Devices.add(this)}serialMessage(t){t=this.fixHexArray(t);const e={code:t,name:null,description:null,request:null,no_code:0};t[0]==="a0"&&t[2]=="00"?(e.name="Relay turned off",e.description="The relay has been turned off successfully.",e.request=this.lastAction,e.no_code=101):t[0]==="a0"&&t[2]=="01"?(e.name="Relay turned on",e.description="The relay has been turned on successfully.",e.request=this.lastAction,e.no_code=102):(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),this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){return a.e.connection(t)}async turnOn(){const t=a.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=a.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await n.wait(e),await this.turnOff();return}await this.turnOff(),await n.wait(e),await this.turnOn()}}exports.Relay=r;
|
package/dist/relay.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as o, D as a, w as i } from "./kernel-
|
|
1
|
+
import { K as o, D as a, w as i } from "./kernel-DAorOZat.js";
|
|
2
2
|
import { e as n } from "./relay-DP8PLsDP.js";
|
|
3
3
|
class f extends o {
|
|
4
4
|
constructor({ filters: t = null, config_port: e, no_device: s = 1, socket: r = !1 } = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jofemar.d.ts","sourceRoot":"","sources":["../../../lib/serial/jofemar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAK/D,KAAK,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEvC,UAAU,wBAAyB,SAAQ,iBAAiB;IAC1D,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,UAAU,eAAgB,SAAQ,QAAQ;IACxC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG;QAC3B,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,OAAO,CAAC;QACtB,QAAQ,EAAE;YACR,UAAU,EAAE,OAAO,CAAC;YACpB,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,IAAI,EAAE;YACJ,UAAU,EAAE,OAAO,CAAC;SACrB,CAAC;QACF,QAAQ,EAAE;YACR,YAAY,EAAE;gBACZ,KAAK,IAAI,IAAI,CAAC;gBACd,OAAO,EAAE,OAAO,CAAC;gBACjB,KAAK,EAAE,MAAM,CAAC;gBACd,GAAG,EAAE,MAAM,CAAC;gBACZ,OAAO,EAAE,MAAM,CAAC;gBAChB,QAAQ,EAAE;oBAAE,SAAS,EAAE,MAAM,CAAC;oBAAC,MAAM,EAAE,OAAO,CAAA;iBAAE,EAAE,CAAC;aACpD,CAAC;SACH,CAAC;QACF,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,OAAO,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG;QAC/B,QAAQ,EAAE;YACR,YAAY,EAAE,MAAM,CAAC;YACrB,gBAAgB,EAAE,MAAM,CAAC;YACzB,UAAU,EAAE,OAAO,CAAC;SACrB,CAAC;QACF,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AA+DD,UAAU,aAAa;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE;QACR,UAAU,EAAE,OAAO,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,IAAI,EAAE;QACJ,UAAU,EAAE,OAAO,CAAC;KACrB,CAAC;IACF,QAAQ,EAAE;QACR,YAAY,EAAE;YACZ,KAAK,IAAI,IAAI,CAAC;YACd,OAAO,EAAE,OAAO,CAAC;YACjB,KAAK,EAAE,MAAM,CAAC;YACd,GAAG,EAAE,MAAM,CAAC;YACZ,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE;gBAAE,SAAS,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,OAAO,CAAA;aAAE,EAAE,CAAC;SACpD,CAAC;KACH,CAAC;CACH;AAED,qBAAa,OAAQ,SAAQ,MAAM;;IACzB,YAAY,EAAE,eAAe,CAAC;IAEtC,QAAQ,EAAE,aAAa,CAyBrB;gBAEU,EACV,OAAc,EACd,WAAW,EACX,SAAa,EACb,wBAA4B,EAC5B,IAAe,EACf,YAAmB,EACnB,MAAc,GACf,GAAE,wBAA6B;IA4BhC,IAAI,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAKlD;IAED,IAAI,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAKhD;IAED,IAAI,eAAe,CAAC,OAAO,EAAE,MAAM,EAMlC;IAED;;;OAGG;IACH,IAAI,YAAY,CAAC,OAAO,EAAE,MAAM,EAE/B;IAED,IAAI,UAAU,CAAC,IAAI,EAAE,UAAU,EAG9B;IAED,IAAI,WAAW,CAAC,YAAY,EAAE,OAAO,EAGpC;IA8CD,2BAA2B,CAAC,cAAc,SAAI;IA4+B9C,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,GAAG,WAAW;
|
|
1
|
+
{"version":3,"file":"jofemar.d.ts","sourceRoot":"","sources":["../../../lib/serial/jofemar.ts"],"names":[],"mappings":"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"}
|
|
@@ -62,15 +62,7 @@ const ye = (n) => {
|
|
|
62
62
|
return ie(t, e);
|
|
63
63
|
} else
|
|
64
64
|
return { base64: !0, data: n };
|
|
65
|
-
}, ie = (n, e) => {
|
|
66
|
-
switch (e) {
|
|
67
|
-
case "blob":
|
|
68
|
-
return n instanceof Blob ? n : new Blob([n]);
|
|
69
|
-
case "arraybuffer":
|
|
70
|
-
default:
|
|
71
|
-
return n instanceof ArrayBuffer ? n : n.buffer;
|
|
72
|
-
}
|
|
73
|
-
}, re = "", we = (n, e) => {
|
|
65
|
+
}, ie = (n, e) => e === "blob" ? n instanceof Blob ? n : new Blob([n]) : n instanceof ArrayBuffer ? n : n.buffer, re = "", we = (n, e) => {
|
|
74
66
|
const t = n.length, s = new Array(t);
|
|
75
67
|
let i = 0;
|
|
76
68
|
n.forEach((r, o) => {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";const w=Object.create(null);w.open="0";w.close="1";w.ping="2";w.pong="3";w.message="4";w.upgrade="5";w.noop="6";const S=Object.create(null);Object.keys(w).forEach(n=>{S[w[n]]=n});const q={type:"error",data:"parser error"},te=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",se=typeof ArrayBuffer=="function",ne=n=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(n):n&&n.buffer instanceof ArrayBuffer,H=({type:n,data:e},t,s)=>te&&e instanceof Blob?t?s(e):J(e,s):se&&(e instanceof ArrayBuffer||ne(e))?t?s(e):J(new Blob([e]),s):s(w[n]+(e||"")),J=(n,e)=>{const t=new FileReader;return t.onload=function(){const s=t.result.split(",")[1];e("b"+(s||""))},t.readAsDataURL(n)};function Q(n){return n instanceof Uint8Array?n:n instanceof ArrayBuffer?new Uint8Array(n):new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}let P;function pe(n,e){if(te&&n.data instanceof Blob)return n.data.arrayBuffer().then(Q).then(e);if(se&&(n.data instanceof ArrayBuffer||ne(n.data)))return e(Q(n.data));H(n,!1,t=>{P||(P=new TextEncoder),e(P.encode(t))})}const X="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",C=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let n=0;n<X.length;n++)C[X.charCodeAt(n)]=n;const ye=n=>{let e=n.length*.75,t=n.length,s,i=0,r,o,l,c;n[n.length-1]==="="&&(e--,n[n.length-2]==="="&&e--);const f=new ArrayBuffer(e),u=new Uint8Array(f);for(s=0;s<t;s+=4)r=C[n.charCodeAt(s)],o=C[n.charCodeAt(s+1)],l=C[n.charCodeAt(s+2)],c=C[n.charCodeAt(s+3)],u[i++]=r<<2|o>>4,u[i++]=(o&15)<<4|l>>2,u[i++]=(l&3)<<6|c&63;return f},ge=typeof ArrayBuffer=="function",W=(n,e)=>{if(typeof n!="string")return{type:"message",data:ie(n,e)};const t=n.charAt(0);return t==="b"?{type:"message",data:me(n.substring(1),e)}:S[t]?n.length>1?{type:S[t],data:n.substring(1)}:{type:S[t]}:q},me=(n,e)=>{if(ge){const t=ye(n);return ie(t,e)}else return{base64:!0,data:n}},ie=(n,e)=>e==="blob"?n instanceof Blob?n:new Blob([n]):n instanceof ArrayBuffer?n:n.buffer,re="",we=(n,e)=>{const t=n.length,s=new Array(t);let i=0;n.forEach((r,o)=>{H(r,!1,l=>{s[o]=l,++i===t&&e(s.join(re))})})},be=(n,e)=>{const t=n.split(re),s=[];for(let i=0;i<t.length;i++){const r=W(t[i],e);if(s.push(r),r.type==="error")break}return s};function ve(){return new TransformStream({transform(n,e){pe(n,t=>{const s=t.length;let i;if(s<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,s);else if(s<65536){i=new Uint8Array(3);const r=new DataView(i.buffer);r.setUint8(0,126),r.setUint16(1,s)}else{i=new Uint8Array(9);const r=new DataView(i.buffer);r.setUint8(0,127),r.setBigUint64(1,BigInt(s))}n.data&&typeof n.data!="string"&&(i[0]|=128),e.enqueue(i),e.enqueue(t)})}})}let N;function T(n){return n.reduce((e,t)=>e+t.length,0)}function A(n,e){if(n[0].length===e)return n.shift();const t=new Uint8Array(e);let s=0;for(let i=0;i<e;i++)t[i]=n[0][s++],s===n[0].length&&(n.shift(),s=0);return n.length&&s<n[0].length&&(n[0]=n[0].slice(s)),t}function Ee(n,e){N||(N=new TextDecoder);const t=[];let s=0,i=-1,r=!1;return new TransformStream({transform(o,l){for(t.push(o);;){if(s===0){if(T(t)<1)break;const c=A(t,1);r=(c[0]&128)===128,i=c[0]&127,i<126?s=3:i===126?s=1:s=2}else if(s===1){if(T(t)<2)break;const c=A(t,2);i=new DataView(c.buffer,c.byteOffset,c.length).getUint16(0),s=3}else if(s===2){if(T(t)<8)break;const c=A(t,8),f=new DataView(c.buffer,c.byteOffset,c.length),u=f.getUint32(0);if(u>Math.pow(2,21)-1){l.enqueue(q);break}i=u*Math.pow(2,32)+f.getUint32(4),s=3}else{if(T(t)<i)break;const c=A(t,i);l.enqueue(W(r?c:N.decode(c),e)),s=0}if(i===0||i>n){l.enqueue(q);break}}}})}const oe=4;function _(n){if(n)return ke(n)}function ke(n){for(var e in _.prototype)n[e]=_.prototype[e];return n}_.prototype.on=_.prototype.addEventListener=function(n,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+n]=this._callbacks["$"+n]||[]).push(e),this};_.prototype.once=function(n,e){function t(){this.off(n,t),e.apply(this,arguments)}return t.fn=e,this.on(n,t),this};_.prototype.off=_.prototype.removeListener=_.prototype.removeAllListeners=_.prototype.removeEventListener=function(n,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+n];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+n],this;for(var s,i=0;i<t.length;i++)if(s=t[i],s===e||s.fn===e){t.splice(i,1);break}return t.length===0&&delete this._callbacks["$"+n],this};_.prototype.emit=function(n){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),t=this._callbacks["$"+n],s=1;s<arguments.length;s++)e[s-1]=arguments[s];if(t){t=t.slice(0);for(var s=0,i=t.length;s<i;++s)t[s].apply(this,e)}return this};_.prototype.emitReserved=_.prototype.emit;_.prototype.listeners=function(n){return this._callbacks=this._callbacks||{},this._callbacks["$"+n]||[]};_.prototype.hasListeners=function(n){return!!this.listeners(n).length};const O=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,t)=>t(e,0),p=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Ce="arraybuffer";function ae(n,...e){return e.reduce((t,s)=>(n.hasOwnProperty(s)&&(t[s]=n[s]),t),{})}const Te=p.setTimeout,Ae=p.clearTimeout;function L(n,e){e.useNativeTimers?(n.setTimeoutFn=Te.bind(p),n.clearTimeoutFn=Ae.bind(p)):(n.setTimeoutFn=p.setTimeout.bind(p),n.clearTimeoutFn=p.clearTimeout.bind(p))}const Se=1.33;function xe(n){return typeof n=="string"?Re(n):Math.ceil((n.byteLength||n.size)*Se)}function Re(n){let e=0,t=0;for(let s=0,i=n.length;s<i;s++)e=n.charCodeAt(s),e<128?t+=1:e<2048?t+=2:e<55296||e>=57344?t+=3:(s++,t+=4);return t}function ce(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Be(n){let e="";for(let t in n)n.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(n[t]));return e}function Oe(n){let e={},t=n.split("&");for(let s=0,i=t.length;s<i;s++){let r=t[s].split("=");e[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return e}class Le extends Error{constructor(e,t,s){super(e),this.description=t,this.context=s,this.type="TransportError"}}class K extends _{constructor(e){super(),this.writable=!1,L(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,s){return super.emitReserved("error",new Le(e,t,s)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=W(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){const e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){const t=Be(e);return t.length?"?"+t:""}}class Pe extends K{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(e){this.readyState="pausing";const t=()=>{this.readyState="paused",e()};if(this._polling||!this.writable){let s=0;this._polling&&(s++,this.once("pollComplete",function(){--s||t()})),this.writable||(s++,this.once("drain",function(){--s||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){const t=s=>{if(this.readyState==="opening"&&s.type==="open"&&this.onOpen(),s.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(s)};be(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,we(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(t[this.opts.timestampParam]=ce()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}}let le=!1;try{le=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const Ne=le;function Ie(){}class De extends Pe{constructor(e){if(super(e),typeof location<"u"){const t=location.protocol==="https:";let s=location.port;s||(s=t?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||s!==e.port}}doWrite(e,t){const s=this.request({method:"POST",data:e});s.on("success",t),s.on("error",(i,r)=>{this.onError("xhr post error",i,r)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,s)=>{this.onError("xhr poll error",t,s)}),this.pollXhr=e}}class m extends _{constructor(e,t,s){super(),this.createRequest=e,L(this,s),this._opts=s,this._method=s.method||"GET",this._uri=t,this._data=s.data!==void 0?s.data:null,this._create()}_create(){var e;const t=ae(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;const s=this._xhr=this.createRequest(t);try{s.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){s.setDisableHeaderCheck&&s.setDisableHeaderCheck(!0);for(let i in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(i)&&s.setRequestHeader(i,this._opts.extraHeaders[i])}}catch{}if(this._method==="POST")try{s.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{s.setRequestHeader("Accept","*/*")}catch{}(e=this._opts.cookieJar)===null||e===void 0||e.addCookies(s),"withCredentials"in s&&(s.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(s.timeout=this._opts.requestTimeout),s.onreadystatechange=()=>{var i;s.readyState===3&&((i=this._opts.cookieJar)===null||i===void 0||i.parseCookies(s.getResponseHeader("set-cookie"))),s.readyState===4&&(s.status===200||s.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof s.status=="number"?s.status:0)},0))},s.send(this._data)}catch(i){this.setTimeoutFn(()=>{this._onError(i)},0);return}typeof document<"u"&&(this._index=m.requestsCount++,m.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=Ie,e)try{this._xhr.abort()}catch{}typeof document<"u"&&delete m.requests[this._index],this._xhr=null}}_onLoad(){const e=this._xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}m.requestsCount=0;m.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",j);else if(typeof addEventListener=="function"){const n="onpagehide"in p?"pagehide":"unload";addEventListener(n,j,!1)}}function j(){for(let n in m.requests)m.requests.hasOwnProperty(n)&&m.requests[n].abort()}const qe=(function(){const n=he({xdomain:!1});return n&&n.responseType!==null})();class Ue extends De{constructor(e){super(e);const t=e&&e.forceBase64;this.supportsBinary=qe&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new m(he,this.uri(),e)}}function he(n){const e=n.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||Ne))return new XMLHttpRequest}catch{}if(!e)try{return new p[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const ue=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Me extends K{get name(){return"websocket"}doOpen(){const e=this.uri(),t=this.opts.protocols,s=ue?{}:ae(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,s)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const s=e[t],i=t===e.length-1;H(s,this.supportsBinary,r=>{try{this.doWrite(s,r)}catch{}i&&O(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=ce()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}}const I=p.WebSocket||p.MozWebSocket;class Fe extends Me{createSocket(e,t,s){return ue?new I(e,t,s):t?new I(e,t):new I(e)}doWrite(e,t){this.ws.send(t)}}class $e extends K{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{const t=Ee(Number.MAX_SAFE_INTEGER,this.socket.binaryType),s=e.readable.pipeThrough(t).getReader(),i=ve();i.readable.pipeTo(e.writable),this._writer=i.writable.getWriter();const r=()=>{s.read().then(({done:l,value:c})=>{l||(this.onPacket(c),r())}).catch(l=>{})};r();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const s=e[t],i=t===e.length-1;this._writer.write(s).then(()=>{i&&O(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}}const Ve={websocket:Fe,webtransport:$e,polling:Ue},He=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,We=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function U(n){if(n.length>8e3)throw"URI too long";const e=n,t=n.indexOf("["),s=n.indexOf("]");t!=-1&&s!=-1&&(n=n.substring(0,t)+n.substring(t,s).replace(/:/g,";")+n.substring(s,n.length));let i=He.exec(n||""),r={},o=14;for(;o--;)r[We[o]]=i[o]||"";return t!=-1&&s!=-1&&(r.source=e,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=Ke(r,r.path),r.queryKey=ze(r,r.query),r}function Ke(n,e){const t=/\/{2,9}/g,s=e.replace(t,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&s.splice(0,1),e.slice(-1)=="/"&&s.splice(s.length-1,1),s}function ze(n,e){const t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(s,i,r){i&&(t[i]=r)}),t}const M=typeof addEventListener=="function"&&typeof removeEventListener=="function",x=[];M&&addEventListener("offline",()=>{x.forEach(n=>n())},!1);class b extends _{constructor(e,t){if(super(),this.binaryType=Ce,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e=="object"&&(t=e,e=null),e){const s=U(e);t.hostname=s.host,t.secure=s.protocol==="https"||s.protocol==="wss",t.port=s.port,s.query&&(t.query=s.query)}else t.host&&(t.hostname=U(t.host).host);L(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},t.transports.forEach(s=>{const i=s.prototype.name;this.transports.push(i),this._transportsByName[i]=s}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Oe(this.opts.query)),M&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},x.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=oe,t.transport=e,this.id&&(t.sid=this.id);const s=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](s)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const e=this.opts.rememberUpgrade&&b.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const t=this.createTransport(e);t.open(),this.setTransport(t)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",b.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const t=new Error("server error");t.code=e.data,this._onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},e),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this._getWritablePackets();this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s<this.writeBuffer.length;s++){const i=this.writeBuffer[s].data;if(i&&(t+=xe(i)),s>0&&t>this._maxPayload)return this.writeBuffer.slice(0,s);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,O(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),e}write(e,t,s){return this._sendPacket("message",e,t,s),this}send(e,t,s){return this._sendPacket("message",e,t,s),this}_sendPacket(e,t,s,i){if(typeof t=="function"&&(i=t,t=void 0),typeof s=="function"&&(i=s,s=null),this.readyState==="closing"||this.readyState==="closed")return;s=s||{},s.compress=s.compress!==!1;const r={type:e,data:t,options:s};this.emitReserved("packetCreate",r),this.writeBuffer.push(r),i&&this.once("flush",i),this.flush()}close(){const e=()=>{this._onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},s=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?s():e()}):this.upgrading?s():e()),this}_onError(e){if(b.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),M&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const s=x.indexOf(this._offlineEventListener);s!==-1&&x.splice(s,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}}b.protocol=oe;class Ye extends b{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),s=!1;b.priorWebsocketSuccess=!1;const i=()=>{s||(t.send([{type:"ping",data:"probe"}]),t.once("packet",d=>{if(!s)if(d.type==="pong"&&d.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;b.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{s||this.readyState!=="closed"&&(u(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{const E=new Error("probe error");E.transport=t.name,this.emitReserved("upgradeError",E)}}))};function r(){s||(s=!0,u(),t.close(),t=null)}const o=d=>{const E=new Error("probe error: "+d);E.transport=t.name,r(),this.emitReserved("upgradeError",E)};function l(){o("transport closed")}function c(){o("socket closed")}function f(d){t&&d.name!==t.name&&r()}const u=()=>{t.removeListener("open",i),t.removeListener("error",o),t.removeListener("close",l),this.off("close",c),this.off("upgrading",f)};t.once("open",i),t.once("error",o),t.once("close",l),this.once("close",c),this.once("upgrading",f),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{s||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){const t=[];for(let s=0;s<e.length;s++)~this.transports.indexOf(e[s])&&t.push(e[s]);return t}}let Je=class extends Ye{constructor(e,t={}){const s=typeof e=="object"?e:t;(!s.transports||s.transports&&typeof s.transports[0]=="string")&&(s.transports=(s.transports||["polling","websocket","webtransport"]).map(i=>Ve[i]).filter(i=>!!i)),super(e,s)}};function Qe(n,e="",t){let s=n;t=t||typeof location<"u"&&location,n==null&&(n=t.protocol+"//"+t.host),typeof n=="string"&&(n.charAt(0)==="/"&&(n.charAt(1)==="/"?n=t.protocol+n:n=t.host+n),/^(https?|wss?):\/\//.test(n)||(typeof t<"u"?n=t.protocol+"//"+n:n="https://"+n),s=U(n)),s.port||(/^(http|ws)$/.test(s.protocol)?s.port="80":/^(http|ws)s$/.test(s.protocol)&&(s.port="443")),s.path=s.path||"/";const r=s.host.indexOf(":")!==-1?"["+s.host+"]":s.host;return s.id=s.protocol+"://"+r+":"+s.port+e,s.href=s.protocol+"://"+r+(t&&t.port===s.port?"":":"+s.port),s}const Xe=typeof ArrayBuffer=="function",je=n=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(n):n.buffer instanceof ArrayBuffer,_e=Object.prototype.toString,Ge=typeof Blob=="function"||typeof Blob<"u"&&_e.call(Blob)==="[object BlobConstructor]",Ze=typeof File=="function"||typeof File<"u"&&_e.call(File)==="[object FileConstructor]";function z(n){return Xe&&(n instanceof ArrayBuffer||je(n))||Ge&&n instanceof Blob||Ze&&n instanceof File}function R(n,e){if(!n||typeof n!="object")return!1;if(Array.isArray(n)){for(let t=0,s=n.length;t<s;t++)if(R(n[t]))return!0;return!1}if(z(n))return!0;if(n.toJSON&&typeof n.toJSON=="function"&&arguments.length===1)return R(n.toJSON(),!0);for(const t in n)if(Object.prototype.hasOwnProperty.call(n,t)&&R(n[t]))return!0;return!1}function et(n){const e=[],t=n.data,s=n;return s.data=F(t,e),s.attachments=e.length,{packet:s,buffers:e}}function F(n,e){if(!n)return n;if(z(n)){const t={_placeholder:!0,num:e.length};return e.push(n),t}else if(Array.isArray(n)){const t=new Array(n.length);for(let s=0;s<n.length;s++)t[s]=F(n[s],e);return t}else if(typeof n=="object"&&!(n instanceof Date)){const t={};for(const s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=F(n[s],e));return t}return n}function tt(n,e){return n.data=$(n.data,e),delete n.attachments,n}function $(n,e){if(!n)return n;if(n&&n._placeholder===!0){if(typeof n.num=="number"&&n.num>=0&&n.num<e.length)return e[n.num];throw new Error("illegal attachments")}else if(Array.isArray(n))for(let t=0;t<n.length;t++)n[t]=$(n[t],e);else if(typeof n=="object")for(const t in n)Object.prototype.hasOwnProperty.call(n,t)&&(n[t]=$(n[t],e));return n}const st=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],nt=5;var h;(function(n){n[n.CONNECT=0]="CONNECT",n[n.DISCONNECT=1]="DISCONNECT",n[n.EVENT=2]="EVENT",n[n.ACK=3]="ACK",n[n.CONNECT_ERROR=4]="CONNECT_ERROR",n[n.BINARY_EVENT=5]="BINARY_EVENT",n[n.BINARY_ACK=6]="BINARY_ACK"})(h||(h={}));class it{constructor(e){this.replacer=e}encode(e){return(e.type===h.EVENT||e.type===h.ACK)&&R(e)?this.encodeAsBinary({type:e.type===h.EVENT?h.BINARY_EVENT:h.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return(e.type===h.BINARY_EVENT||e.type===h.BINARY_ACK)&&(t+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(t+=e.nsp+","),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){const t=et(e),s=this.encodeAsString(t.packet),i=t.buffers;return i.unshift(s),i}}function G(n){return Object.prototype.toString.call(n)==="[object Object]"}class Y extends _{constructor(e){super(),this.reviver=e}add(e){let t;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);const s=t.type===h.BINARY_EVENT;s||t.type===h.BINARY_ACK?(t.type=s?h.EVENT:h.ACK,this.reconstructor=new rt(t),t.attachments===0&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else if(z(e)||e.base64)if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let t=0;const s={type:Number(e.charAt(0))};if(h[s.type]===void 0)throw new Error("unknown packet type "+s.type);if(s.type===h.BINARY_EVENT||s.type===h.BINARY_ACK){const r=t+1;for(;e.charAt(++t)!=="-"&&t!=e.length;);const o=e.substring(r,t);if(o!=Number(o)||e.charAt(t)!=="-")throw new Error("Illegal attachments");s.attachments=Number(o)}if(e.charAt(t+1)==="/"){const r=t+1;for(;++t&&!(e.charAt(t)===","||t===e.length););s.nsp=e.substring(r,t)}else s.nsp="/";const i=e.charAt(t+1);if(i!==""&&Number(i)==i){const r=t+1;for(;++t;){const o=e.charAt(t);if(o==null||Number(o)!=o){--t;break}if(t===e.length)break}s.id=Number(e.substring(r,t+1))}if(e.charAt(++t)){const r=this.tryParse(e.substr(t));if(Y.isPayloadValid(s.type,r))s.data=r;else throw new Error("invalid payload")}return s}tryParse(e){try{return JSON.parse(e,this.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case h.CONNECT:return G(t);case h.DISCONNECT:return t===void 0;case h.CONNECT_ERROR:return typeof t=="string"||G(t);case h.EVENT:case h.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&st.indexOf(t[0])===-1);case h.ACK:case h.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class rt{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const t=tt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const ot=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Y,Encoder:it,get PacketType(){return h},protocol:nt},Symbol.toStringTag,{value:"Module"}));function y(n,e,t){return n.on(e,t),function(){n.off(e,t)}}const at=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class fe extends _{constructor(e,t,s){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,s&&s.auth&&(this.auth=s.auth),this._opts=Object.assign({},s),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[y(e,"open",this.onopen.bind(this)),y(e,"packet",this.onpacket.bind(this)),y(e,"error",this.onerror.bind(this)),y(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){var s,i,r;if(at.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const o={type:h.EVENT,data:t};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof t[t.length-1]=="function"){const u=this.ids++,d=t.pop();this._registerAckCallback(u,d),o.id=u}const l=(i=(s=this.io.engine)===null||s===void 0?void 0:s.transport)===null||i===void 0?void 0:i.writable,c=this.connected&&!(!((r=this.io.engine)===null||r===void 0)&&r._hasPingExpired());return this.flags.volatile&&!l||(c?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(e,t){var s;const i=(s=this.flags.timeout)!==null&&s!==void 0?s:this._opts.ackTimeout;if(i===void 0){this.acks[e]=t;return}const r=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let l=0;l<this.sendBuffer.length;l++)this.sendBuffer[l].id===e&&this.sendBuffer.splice(l,1);t.call(this,new Error("operation has timed out"))},i),o=(...l)=>{this.io.clearTimeoutFn(r),t.apply(this,l)};o.withError=!0,this.acks[e]=o}emitWithAck(e,...t){return new Promise((s,i)=>{const r=(o,l)=>o?i(o):s(l);r.withError=!0,t.push(r),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]=="function"&&(t=e.pop());const s={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((i,...r)=>s!==this._queue[0]?void 0:(i!==null?s.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(i)):(this._queue.shift(),t&&t(null,...r)),s.pending=!1,this._drainQueue())),this._queue.push(s),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;const t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:h.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(e=>{if(!this.sendBuffer.some(s=>String(s.id)===e)){const s=this.acks[e];delete this.acks[e],s.withError&&s.call(this,new Error("socket has been disconnected"))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case h.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case h.EVENT:case h.BINARY_EVENT:this.onevent(e);break;case h.ACK:case h.BINARY_ACK:this.onack(e);break;case h.DISCONNECT:this.ondisconnect();break;case h.CONNECT_ERROR:this.destroy();const s=new Error(e.data.message);s.data=e.data.data,this.emitReserved("connect_error",s);break}}onevent(e){const t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const s of t)s.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let s=!1;return function(...i){s||(s=!0,t.packet({type:h.ACK,id:e,data:i}))}}onack(e){const t=this.acks[e.id];typeof t=="function"&&(delete this.acks[e.id],t.withError&&e.data.unshift(null),t.apply(this,e.data))}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:h.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let s=0;s<t.length;s++)if(e===t[s])return t.splice(s,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const t=this._anyOutgoingListeners;for(let s=0;s<t.length;s++)if(e===t[s])return t.splice(s,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const t=this._anyOutgoingListeners.slice();for(const s of t)s.apply(this,e.data)}}}function v(n){n=n||{},this.ms=n.min||100,this.max=n.max||1e4,this.factor=n.factor||2,this.jitter=n.jitter>0&&n.jitter<=1?n.jitter:0,this.attempts=0}v.prototype.duration=function(){var n=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*n);n=(Math.floor(e*10)&1)==0?n-t:n+t}return Math.min(n,this.max)|0};v.prototype.reset=function(){this.attempts=0};v.prototype.setMin=function(n){this.ms=n};v.prototype.setMax=function(n){this.max=n};v.prototype.setJitter=function(n){this.jitter=n};class V extends _{constructor(e,t){var s;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,L(this,t),this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((s=t.randomizationFactor)!==null&&s!==void 0?s:.5),this.backoff=new v({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;const i=t.parser||ot;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=t.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new Je(this.uri,this.opts);const t=this.engine,s=this;this._readyState="opening",this.skipReconnect=!1;const i=y(t,"open",function(){s.onopen(),e&&e()}),r=l=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",l),e?e(l):this.maybeReconnectOnOpen()},o=y(t,"error",r);if(this._timeout!==!1){const l=this._timeout,c=this.setTimeoutFn(()=>{i(),r(new Error("timeout")),t.close()},l);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}return this.subs.push(i),this.subs.push(o),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(y(e,"ping",this.onping.bind(this)),y(e,"data",this.ondata.bind(this)),y(e,"error",this.onerror.bind(this)),y(e,"close",this.onclose.bind(this)),y(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(t){this.onclose("parse error",t)}}ondecoded(e){O(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let s=this.nsps[e];return s?this._autoConnect&&!s.active&&s.connect():(s=new fe(this,e,t),this.nsps[e]=s),s}_destroy(e){const t=Object.keys(this.nsps);for(const s of t)if(this.nsps[s].active)return;this._close()}_packet(e){const t=this.encoder.encode(e);for(let s=0;s<t.length;s++)this.engine.write(t[s],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(e,t){var s;this.cleanup(),(s=this.engine)===null||s===void 0||s.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();this._reconnecting=!0;const s=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(i=>{i?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",i)):e.onreconnect()}))},t);this.opts.autoUnref&&s.unref(),this.subs.push(()=>{this.clearTimeoutFn(s)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const k={};function B(n,e){typeof n=="object"&&(e=n,n=void 0),e=e||{};const t=Qe(n,e.path||"/socket.io"),s=t.source,i=t.id,r=t.path,o=k[i]&&r in k[i].nsps,l=e.forceNew||e["force new connection"]||e.multiplex===!1||o;let c;return l?c=new V(s,e):(k[i]||(k[i]=new V(s,e)),c=k[i]),t.query&&!e.query&&(e.query=t.queryKey),c.socket(t.path,e)}Object.assign(B,{Manager:V,Socket:fe,io:B,connect:B});class Z extends CustomEvent{constructor(e,t){super(e,t)}}class de extends EventTarget{__listeners__={debug:!1};__debug__=!1;__listenersCallbacks__=[];dispatch(e,t=null){const s=new Z(e,{detail:t});this.dispatchEvent(s),this.__debug__&&this.dispatchEvent(new Z("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,s=100){const i=this;setTimeout(()=>{i.dispatch(e,t)},s)}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(s=>!(s.key===e&&s.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__)["internal:queue"].includes(e.key)||(this.__listenersCallbacks__=this.__listenersCallbacks__.filter(t=>!(t.key===e.key&&t.callback===e.callback)),this.removeEventListener(e.key,e.callback));for(const e of Object.keys(this.__listeners__))this.__listeners__[e]=!1}}class a extends de{static instance;static devices={};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 s=e.uuid;if(typeof a.devices[t]>"u"&&a.typeError(t),a.devices[t][s])throw new Error(`Device with id ${s} already exists`);return a.devices[t][s]=e,a.$dispatchChange(e),Object.keys(a.devices[t]).indexOf(s)}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(s=>s.deviceNumber===t)??null}static getCustom(e,t=1){return typeof a.devices[e]>"u"&&a.typeError(e),Object.values(a.devices[e]).find(s=>s.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))}}a.instance||(a.instance=new a);function ee(n=100){return new Promise(e=>setTimeout(()=>e(),n))}class ct{#s="http://localhost:3000";#n={transports:["websocket"]};#e=null;#i=!1;#a=!1;#t;constructor(){this.#t={onResponse:this.onResponse.bind(this),onDisconnect:()=>{this.#i=!1,window.dispatchEvent(new Event("serial:socket:disconnected"))},onConnect:()=>{this.#i=!0,window.dispatchEvent(new Event("serial:socket:connected"))},onConnectError:e=>{console.debug("Socket connection error",e),this.#i=!1,window.dispatchEvent(new Event("serial:socket:disconnected"))}}}set uri(e){const t=new URL(e);if(!["http:","https:","ws:","wss:"].includes(t.protocol))throw new Error("URI must start with http://, https://, ws://, or wss://");this.#s=e}get uri(){return this.#s}set options(e){if(typeof e!="object")throw new Error("Options must be an object");this.#n=e}get options(){return this.#n}get socketId(){return this.#e&&this.#e.id?this.#e.id:null}disconnect(){this.#e&&(this.#e.off("response",this.#t.onResponse),this.#e.off("disconnect",this.#t.onDisconnect),this.#e.off("connect",this.#t.onConnect),this.#e.off("connect_error",this.#t.onConnectError),this.#e.disconnect(),this.#e=null,this.#a=!1),this.#i=!1}prepare(){this.#i||this.#a||(this.#e=B(this.#s,this.#n),this.#a=!0,this.#e.on("disconnect",this.#t.onDisconnect),this.#e.on("response",this.#t.onResponse),this.#e.on("connect",this.#t.onConnect),this.#e.on("connect_error",this.#t.onConnectError))}connectDevice(e){if(!this.#e)throw new Error("Socket not connected. Call prepare() first.");this.#e.emit("connectDevice",{config:e})}disconnectDevice(e){if(!this.#e)throw new Error("Socket not connected. Call prepare() first.");this.#e.emit("disconnectDevice",{config:e})}disconnectAllDevices(){if(!this.#e)throw new Error("Socket not connected. Call prepare() first.");this.#e.emit("disconnectAll")}write(e){if(!this.#e)throw new Error("Socket not connected. Call prepare() first.");this.#e.emit("cmd",e)}onResponse(e){let t=a.get(e.name,e.uuid);t||(t=a.getByNumber(e.name,e.deviceNumber)),t&&t.socketResponse(e)}isConnected(){return this.#i}isDisconnected(){return!this.#i}}const g=new ct,D={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class lt extends de{__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:{socket:!1,portInfo:{path:null,vendorId:null,productId:null,parser:{name:"inter-byte-timeout",interval:50}},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:D,queue:[],running_queue:!1,auto_response:null,free_timeout_ms:50,useRTSCTS:!1},device:{type:"unknown",id:window.crypto.randomUUID(),listen_on_port:null},time:{response_connection:500,response_engines:2e3,response_general:2e3},timeout:{until_response:0},interval:{reconnection:0}};#s=null;constructor({filters:e=null,config_port:t=D,no_device:s=1,device_listen_on_channel:i=1,bypassSerialBytesConnection:r=!1,socket:o=!1}={filters:null,config_port:D,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1,socket:!1}){if(super(),!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),r&&(this.__internal__.bypassSerialBytesConnection=r),s&&this.#b(s),i&&["number","string"].includes(typeof i)&&(this.listenOnChannel=i),this.__internal__.serial.socket=o,this.#y(),this.#g()}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=this.#n(this.__internal__.serial.port);return e&&!t&&this.#e({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=this.#n(this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),this.#o(!1),a.$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}get useSocket(){return this.__internal__.serial.socket}get connectionBytes(){const e=this.__internal__.serial.bytes_connection;return e instanceof Uint8Array?e:typeof e=="string"?this.stringArrayToUint8Array(this.parseStringToBytes(e,"")):Array.isArray(e)&&typeof e[0]=="string"?this.stringArrayToUint8Array(e):Array.isArray(e)&&typeof e[0]=="number"?new Uint8Array(e):new Uint8Array([])}set portPath(e){if(this.isConnected)throw new Error("Cannot change port path while connected");if(typeof e!="string"&&e!==null)throw new TypeError("vendorId must be string or null");this.__internal__.serial.portInfo.path=e}get portPath(){return this.__internal__.serial.portInfo.path}set portVendorId(e){if(this.isConnected)throw new Error("Cannot change port vendorId while connected");if(typeof e=="number"&&typeof e!="string"&&e!==null)throw new TypeError("vendorId must be a number, string or null");this.__internal__.serial.portInfo.vendorId=e}get portVendorId(){return this.__internal__.serial.portInfo.vendorId}set portProductId(e){if(this.isConnected)throw new Error("Cannot change port productId while connected");if(typeof e=="number"&&typeof e!="string"&&e!==null)throw new TypeError("productId must be a number, string or null");this.__internal__.serial.portInfo.productId=e}get portProductId(){return this.__internal__.serial.portInfo.productId}set socketPortParser(e){if(["byte-length","inter-byte-timeout"].includes(e))throw new TypeError("socketPortParser must be a string, either 'byte-length' or 'inter-byte-timeout'");this.__internal__.serial.portInfo.parser.name=e}get socketPortParser(){return this.__internal__.serial.portInfo.parser.name}set socketPortParserInterval(e){if(typeof e!="number"||e<1)throw new TypeError("Interval must be a positive number");this.__internal__.serial.portInfo.parser.interval=e}get socketPortParserInterval(){return this.__internal__.serial.portInfo.parser.interval||50}set socketPortParserLength(e){if(typeof e!="number"||e<1)throw new TypeError("Length must be a positive number or null");this.__internal__.serial.portInfo.parser.length=e}get socketPortParserLength(){return this.__internal__.serial.portInfo.parser.length||14}get parserForSocket(){return this.socketPortParser==="byte-length"?{name:this.socketPortParser,length:this.socketPortParserLength}:{name:this.socketPortParser,interval:this.socketPortParserInterval}}get configDeviceSocket(){return{uuid:this.uuid,name:this.typeDevice,deviceNumber:this.deviceNumber,connectionBytes:Array.from(this.connectionBytes),config:{baudRate:this.__internal__.serial.config_port.baudRate,dataBits:this.__internal__.serial.config_port.dataBits,stopBits:this.__internal__.serial.config_port.stopBits,parity:this.__internal__.serial.config_port.parity,bufferSize:this.__internal__.serial.config_port.bufferSize,flowControl:this.__internal__.serial.config_port.flowControl},info:{vendorId:this.portVendorId,productId:this.portProductId,portName:this.portPath},response:{automatic:this.__internal__.auto_response,autoResponse:this.__internal__.serial.auto_response,parser:this.parserForSocket,timeout:{general:this.__internal__.time.response_general,engines:this.__internal__.time.response_engines,connection:this.__internal__.time.response_connection}}}}#n(e){return this.useSocket?this.__internal__.serial.connected&&g.isConnected():!!(e&&e.readable&&e.writable)}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",{}),a.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,a.$dispatchChange(this),await this.serialConnect()),this.__internal__.serial.queue.length>0&&this.dispatch("internal:queue",{}),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),this.#e(e)}#e(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),a.$dispatchChange(this)}#i(e){this.__internal__.serial.aux_connecting=e.detail.active?"connecting":"finished"}socketResponse(e){const t=this.__internal__.serial.connected;if(e.type==="disconnect"||e.type==="error"&&e.data==="DISCONNECTED"?this.__internal__.serial.connected=!1:e.type==="success"&&(this.__internal__.serial.connected=!0),a.$dispatchChange(this),!t&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),this.#o(!1)),e.type==="success")this.#r(new Uint8Array(e.data));else if(e.type==="error"){const s=new Error("The port is closed or is not readable/writable");this.serialErrors(s)}else e.type==="timeout"&&this.timeout(e.data.bytes??[],this.lastAction||"unknown");this.__internal__.serial.last_action=null}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{this.#s||(this.#s=this.#i.bind(this)),this.on("internal:connecting",this.#s);const s=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(s),this.__internal__.serial.aux_connecting="idle",this.#s!==null&&this.off("internal:connecting",this.#s),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("internal:connecting",{active:!0}),this.dispatch("serial:connecting",{active:!0}))},100);this.serialConnect()}))}async serialDisconnect(){try{if(this.useSocket)g.isConnected()&&g.disconnectDevice(this.configDeviceSocket);else{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(s=>this.serialErrors(s)),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,a.$dispatchChange(this)}}async#a(e){if(g.isDisconnected())throw this.#e({error:"Socket is disconnected."}),new Error("The socket is disconnected");if(this.isDisconnected)throw this.#e({error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const t=this.validateBytes(e);g.write({config:this.configDeviceSocket,bytes:Array.from(t)})}async#t(e){if(this.useSocket){await this.#a(e);return}const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw this.#e({error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const s=this.validateBytes(e);if(this.useRTSCTS&&await this.#c(t,5e3),t.writable===null)return;const i=t.writable.getWriter();await i.write(s),i.releaseLock()}async#c(e,t=5e3){const s=Date.now();for(;;){if(Date.now()-s>t)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:i}=await e.getSignals();if(i)return;await ee(100)}}#r(e=new Uint8Array([]),t=!1){if(e&&e.length>0){const s=this.__internal__.serial.connected;if(this.__internal__.serial.connected=this.#n(this.__internal__.serial.port),a.$dispatchChange(this),!s&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),this.#o(!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")t?this.serialCorruptMessage(this.parseUint8ToHex(e)):this.serialMessage(this.parseUint8ToHex(e));else if(this.__internal__.serial.response.as==="uint8")t?this.serialCorruptMessage(e):this.serialMessage(e);else if(this.__internal__.serial.response.as==="string"){const i=this.parseUint8ArrayToString(e);if(this.__internal__.serial.response.limiter!==null){const r=i.split(this.__internal__.serial.response.limiter);for(const o in r)r[o]&&(t?this.serialCorruptMessage(r[o]):this.serialMessage(r[o]))}else t?this.serialCorruptMessage(i):this.serialMessage(i)}else{const i=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));t?this.serialCorruptMessage(i):this.serialMessage(i)}}if(this.__internal__.serial.queue.length===0){this.__internal__.serial.running_queue=!1;return}this.dispatch("internal:queue",{})}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#l(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(s=>{const i=s.getInfo();return e.some(r=>i.usbProductId===r.usbProductId&&i.usbVendorId===r.usbVendorId)}).filter(s=>!this.#n(s))}async serialPortsSaved(e){const t=this.serialFilters;if(this.__internal__.aux_port_connector<e.length){const s=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[s]}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",{}),a.$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",{}),a.$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)}#h(e){if(e){const t=this.__internal__.serial.response.buffer,s=new Uint8Array(t.length+e.byteLength);s.set(t,0),s.set(new Uint8Array(e),t.length),this.__internal__.serial.response.buffer=s}}async#u(){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&&this.#r(this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)}async#_(){const e=this.__internal__.serial.response.length;let t=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),!(e===null||!t||t.length===0)){for(;t.length>=e;){const s=t.slice(0,e);this.#r(s),t=t.slice(e)}this.__internal__.serial.response.buffer=t,t.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.#r(this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}}async#f(){const{limiter:e,prefixLimiter:t=!1,sufixLimiter:s=!0}=this.__internal__.serial.response;if(!e)throw new Error("No limiter defined for delimited serial response");const i=this.__internal__.serial.response.buffer;if(!e||!i||i.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 r=new TextDecoder().decode(i);const o=[];if(typeof e=="string"){let c;if(t&&s)c=new RegExp(`${e}([^${e}]+)${e}`,"g");else if(t)c=new RegExp(`${e}([^${e}]*)`,"g");else if(s)c=new RegExp(`([^${e}]+)${e}`,"g");else return;let f,u=0;for(;(f=c.exec(r))!==null;)o.push(new TextEncoder().encode(f[1])),u=c.lastIndex;r=r.slice(u)}else if(e instanceof RegExp){let c,f=0;if(t&&s){const u=new RegExp(`${e.source}(.*?)${e.source}`,"g");for(;(c=u.exec(r))!==null;)o.push(new TextEncoder().encode(c[1])),f=u.lastIndex}else if(s)for(;(c=e.exec(r))!==null;){const u=c.index,d=r.slice(f,u);o.push(new TextEncoder().encode(d)),f=e.lastIndex}else if(t){const u=r.split(e);u.shift();for(const d of u)o.push(new TextEncoder().encode(d));r=""}r=r.slice(f)}for(const c of o)this.#r(c);const l=new TextEncoder().encode(r);this.__internal__.serial.response.buffer=l,l.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.#r(this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))}async#d(){const e=this.__internal__.serial.port;if(!e||!e.readable)throw new Error("Port is not readable");const t=e.readable.getReader();this.__internal__.serial.reader=t;try{for(;this.__internal__.serial.keep_reading;){const{value:s,done:i}=await t.read();if(i)break;this.#h(s),this.__internal__.serial.response.delimited?await this.#f():this.__internal__.serial.response.length===null?await this.#u():await this.#_()}}catch(s){this.serialErrors(s)}finally{t.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}}#o(e){e!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=e,this.dispatch("serial:connecting",{active:e}),this.dispatch("internal:connecting",{active:e}))}async serialConnect(){try{if(this.#o(!0),this.useSocket){if(g.prepare(),this.__internal__.serial.last_action="connect",this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(this.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),g.isDisconnected())return;g.connectDevice(this.configDeviceSocket),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection})}else{const e=await this.#l();if(e.length>0)await this.serialPortsSaved(e);else{const i=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:i})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const s=this;t.onconnect=i=>{s.dispatch("serial:connected",i),s.#o(!1),a.$dispatchChange(this),s.__internal__.serial.queue.length>0?s.dispatch("internal:queue",{}):s.__internal__.serial.running_queue=!1},t.ondisconnect=async()=>{await s.disconnect()},await ee(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await s.timeout(s.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await this.#t(this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&this.#r(this.__internal__.serial.auto_response),await this.#d()}}catch(e){this.#o(!1),this.serialErrors(e)}}async#p(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in SerialPort.prototype&&this.__internal__.serial.port?(await this.__internal__.serial.port.forget(),!0):!1}async serialForget(){return await this.#p()}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((s,i)=>{t[i]="0x"+s}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}#y(){["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(e=>{this.serialRegisterAvailableListener(e)})}#g(){const e=this;this.on("internal:queue",async()=>{await e.#w()});const t=()=>{e.isConnected&&e.#e({error:"Socket disconnected."})},s=()=>{e.isDisconnected&&!e.isConnecting&&e.serialConnect().catch(()=>{})};this.useSocket&&(window.addEventListener("serial:socket:disconnected",t),window.addEventListener("serial:socket:connected",s)),this.#m()}#m(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})}async#w(){if(this.useSocket&&g.isDisconnected())return;if(!this.#n(this.__internal__.serial.port)){this.#e({error:"Port is closed, not readable or writable."}),await this.serialConnect();return}if(this.__internal__.timeout.until_response)return;if(this.__internal__.serial.queue.length===0){this.__internal__.serial.running_queue=!1;return}this.__internal__.serial.running_queue=!0;const e=this.__internal__.serial.queue[0];let t=this.__internal__.time.response_general;if(e.action==="connect"&&(t=this.__internal__.time.response_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(e.bytes,e.action)},t),this.__internal__.serial.last_action=e.action??"unknown",await this.#t(e.bytes),this.dispatch("serial:sent",{action:e.action,bytes:e.bytes}),this.__internal__.auto_response){let i=new Uint8Array(0);try{i=this.validateBytes(this.__internal__.serial.auto_response)}catch(r){this.serialErrors(r)}this.#r(i)}const s=[...this.__internal__.serial.queue];this.__internal__.serial.queue=s.splice(1),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.running_queue=!0)}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 s=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:s,action:t}),this.dispatch("internal:queue",{})}#b(e=1){this.__internal__.device_number=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}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'")}#v(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(e){let t=0;return e.forEach(s=>{t+=parseInt(s,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(){this.#v(),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 s=new TextEncoder;return e+=t,s.encode(e)}parseStringToBytes(e="",t=`
|
|
4
|
+
`){const s=this.parseStringToTextEncoder(e,t);return Array.from(s).map(i=>i.toString(16))}parseUint8ToHex(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0").toLowerCase())}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(s=>{const i=s.replace("0x","");t.push(parseInt(i,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 s=e.map(i=>parseInt(i,16));return this.__internal__.serial.response.replacer?String.fromCharCode(...s).replace(this.__internal__.serial.response.replacer,""):String.fromCharCode(...s)}hexToAscii(e){const t=e.toString();let s="";for(let i=0;i<t.length;i+=2)s+=String.fromCharCode(parseInt(t.substring(i,2),16));return s}asciiToHex(e){const t=[];for(let s=0,i=e.length;s<i;s++){const r=Number(e.charCodeAt(s)).toString(16);t.push(r)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}exports.S=lt;exports.c=g;exports.s=a;
|
package/dist/webserial.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-g4zSg1Ll.cjs"),r=require("./relay.cjs"),o=require("./locker.cjs"),i=require("./pinpad.cjs"),t=require("./pinpax.cjs"),n=require("./jofemar.cjs"),a=require("./boardroid.cjs"),s=require("./hopper.cjs"),c=require("./webserial-core-D49c459A.cjs"),u={wait:e.wait,getSeconds:e.getSeconds,supportWebSerial:e.supportWebSerial},l="4.1.9";exports.Devices=e.Devices;exports.Emulator=e.Emulator;exports.Kernel=e.Kernel;exports.Relay=r.Relay;exports.Locker=o.Locker;exports.PinPad=i.PinPad;exports.PinPax=t.PinPax;exports.Jofemar=n.Jofemar;exports.Boardroid=a.Boardroid;exports.Hopper=s.Hopper;exports.Socket=c.c;exports.utils=u;exports.version=l;
|
package/dist/webserial.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as o, g as r, w as e } from "./kernel-
|
|
2
|
-
import { D as f, E as x, K as i } from "./kernel-
|
|
1
|
+
import { s as o, g as r, w as e } from "./kernel-DAorOZat.js";
|
|
2
|
+
import { D as f, E as x, K as i } from "./kernel-DAorOZat.js";
|
|
3
3
|
import { Relay as n } from "./relay.js";
|
|
4
4
|
import { Locker as d } from "./locker.js";
|
|
5
5
|
import { PinPad as u } from "./pinpad.js";
|
|
@@ -7,7 +7,7 @@ import { PinPax as g } from "./pinpax.js";
|
|
|
7
7
|
import { Jofemar as v } from "./jofemar.js";
|
|
8
8
|
import { Boardroid as D } from "./boardroid.js";
|
|
9
9
|
import { Hopper as K } from "./hopper.js";
|
|
10
|
-
import { c as y } from "./webserial-core-
|
|
10
|
+
import { c as y } from "./webserial-core-CiU9IcKf.js";
|
|
11
11
|
const a = {
|
|
12
12
|
wait: e,
|
|
13
13
|
getSeconds: r,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danidoble/webserial",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.5",
|
|
4
4
|
"author": "danidoble",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
"types": "./dist/types/main.d.ts",
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@danidoble/webserial-vending-commands": "^1.0.3",
|
|
14
|
-
"@eslint/js": "^9.39.
|
|
14
|
+
"@eslint/js": "^9.39.2",
|
|
15
15
|
"@types/w3c-web-serial": "^1.0.8",
|
|
16
|
-
"autoprefixer": "^10.4.
|
|
16
|
+
"autoprefixer": "^10.4.23",
|
|
17
17
|
"axios": "^1.13.2",
|
|
18
|
-
"eslint": "^9.39.
|
|
18
|
+
"eslint": "^9.39.2",
|
|
19
19
|
"globals": "^16.5.0",
|
|
20
20
|
"jsencrypt": "^3.5.4",
|
|
21
21
|
"postcss": "^8.5.6",
|
|
22
22
|
"prettier": "^3.7.4",
|
|
23
23
|
"typescript": "^5.9.3",
|
|
24
|
-
"typescript-eslint": "^8.
|
|
24
|
+
"typescript-eslint": "^8.50.0",
|
|
25
25
|
"uuid": "^13.0.0",
|
|
26
|
-
"vite": "^7.
|
|
26
|
+
"vite": "^7.3.0",
|
|
27
27
|
"webserial-core": "^1.1.4"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|