nsd-ble 0.2.0 → 0.2.2

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.
@@ -0,0 +1 @@
1
+ "use strict";const A=require("./enums.cjs");let F=!1,U=[],M,ct,T=new Map;async function wt(e){try{if(M=await navigator.bluetooth.requestDevice(e),M.gatt===void 0)throw new Error("Device does not support GATT");ct=await M.gatt.connect(),M.addEventListener("gattserverdisconnected",Ct),F=!0}catch(c){throw c}}function Ct(){T.clear(),F=!1,U.forEach(e=>e())}function mt(e){U.push(e)}function At(e){U=U.filter(c=>c!==e)}async function H(e,c){if(T.has(c)){const d=T.get(c);if(d===void 0)throw new Error("Characteristic not found");return d}const h=await(await ct.getPrimaryService(e)).getCharacteristic(c);return T.set(c,h),h}async function bt(e,c){return await(await H(e,c)).readValue()}async function St(e,c,r){const h=new DataView(new ArrayBuffer(r.length));for(let l=0;l<r.length;l++)h.setUint8(l,r[l]);await(await H(e,c)).writeValue(h)}async function qt(e,c,r){const h=await H(e,c);h.addEventListener("characteristicvaluechanged",d=>{let l=d.target.value;l===void 0&&(l=new DataView(new ArrayBuffer(0))),r(l)}),await h.startNotifications()}function X(){return{connected:F,connect:wt,readCharacteristic:bt,writeCharacteristic:St,subscribe:qt,setDisconnectCallback:mt,removeDisconnectCallback:At}}const ht="19b10000-e8f2-537e-4f6c-d104768a1214",Ot="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",Dt="998ff920-81af-42a9-a915-f88025f9647d",Pt={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[ht]};function G(){return{serviceUuid:ht,messageCharUuid:Ot,handshakeCharUuid:Dt,options:Pt}}var b={},O={},x;function V(){if(x)return O;x=1,Object.defineProperty(O,"__esModule",{value:!0}),O.BaseEvent=void 0;var e=(function(){function c(){}return c.prototype.attach=function(r,h){return this._attach(r,h,!1)},c.prototype.once=function(r,h){return this._attach(r,h,!0)},c.prototype._attach=function(r,h,d){var l=this,u,o,i,a;if(typeof r=="function")o=r,a=function(){return l.detach(o)};else if(!h&&typeof r.post=="function")i=r,a=function(){return l.detach(i)};else{if(typeof r!="object"||r===void 0)throw new Error("Expect a function or object as first argument");if(typeof h!="function")throw new Error("Expect a function as second argument");u=r,o=h,a=function(){return l.detach(u,o)}}return this._listeners?this._listeners=this._listeners.slice():this._listeners=[],this._listeners.push({deleted:!1,boundTo:u,handler:o,event:i,once:d}),a},c.prototype.detach=function(){for(var r=[],h=0;h<arguments.length;h++)r[h]=arguments[h];this._detach.apply(this,r)},c.prototype._detach=function(){for(var r=[],h=0;h<arguments.length;h++)r[h]=arguments[h];if(!(!this._listeners||this._listeners.length===0)){var d,l,u;r.length>=1&&(typeof r[0]=="function"?l=r[0]:r.length===1&&typeof r[0].post=="function"?u=r[0]:d=r[0]),r.length>=2&&(l=r[1]),this._listeners=this._listeners.filter(function(o){return(typeof l>"u"||o.handler===l)&&(typeof u>"u"||o.event===u)&&(typeof d>"u"||o.boundTo===d)?(o.deleted=!0,!1):!0}),this._listeners.length===0&&delete this._listeners}},c.prototype.post=function(r){throw new Error("abstract")},c.prototype.listenerCount=function(){return this._listeners?this._listeners.length:0},c.prototype._call=function(r,h){this._listeners&&(r.deleted||(r.once&&(r.deleted=!0,this._listeners=this._listeners.filter(function(d){return d!==r}),this._listeners.length===0&&delete this._listeners),r.event?r.event.post.apply(r.event,h):r.handler&&r.handler.apply(typeof r.boundTo=="object"?r.boundTo:this,h)))},c})();return O.BaseEvent=e,O}var E={},tt;function Q(){if(tt)return E;tt=1;var e=E&&E.__extends||(function(){var l=function(u,o){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,a){i.__proto__=a}||function(i,a){for(var n in a)a.hasOwnProperty(n)&&(i[n]=a[n])},l(u,o)};return function(u,o){l(u,o);function i(){this.constructor=u}u.prototype=o===null?Object.create(o):(i.prototype=o.prototype,new i)}})();Object.defineProperty(E,"__esModule",{value:!0}),E.ErrorSyncEvent=E.VoidSyncEvent=E.SyncEvent=void 0;var c=V(),r=(function(l){e(u,l);function u(){var o=l!==null&&l.apply(this,arguments)||this;return o._recursion=0,o}return Object.defineProperty(u.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new h),this._listenersChanged},enumerable:!1,configurable:!0}),u.prototype.post=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];if(!(!this._listeners||this._listeners.length===0)){if(this._recursion++,typeof u.MAX_RECURSION_DEPTH=="number"&&Number.isInteger(u.MAX_RECURSION_DEPTH)&&u.MAX_RECURSION_DEPTH>0&&this._recursion>u.MAX_RECURSION_DEPTH)throw new Error("event fired recursively");for(var a=this._listeners,n=0;n<a.length;++n){var t=a[n];this._call(t,o)}this._recursion--}},u.prototype._attach=function(o,i,a){var n,t,s,f,v=(t=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&t!==void 0?t:0,y=l.prototype._attach.call(this,o,i,a);return this.evtListenersChanged&&v!==((f=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&f!==void 0?f:0)&&this.evtListenersChanged.post(),y},u.prototype._detach=function(){for(var o,i,a,n,t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];var f=(i=(o=this._listeners)===null||o===void 0?void 0:o.length)!==null&&i!==void 0?i:0,v=l.prototype._detach.apply(this,t);return this.evtListenersChanged&&f!==((n=(a=this._listeners)===null||a===void 0?void 0:a.length)!==null&&n!==void 0?n:0)&&this.evtListenersChanged.post(),v},u.MAX_RECURSION_DEPTH=10,u})(c.BaseEvent);E.SyncEvent=r;var h=(function(l){e(u,l);function u(){return l!==null&&l.apply(this,arguments)||this}return u.prototype.post=function(){l.prototype.post.call(this,void 0)},u})(r);E.VoidSyncEvent=h;var d=(function(l){e(u,l);function u(){return l!==null&&l.apply(this,arguments)||this}return u.prototype.post=function(o){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+o.message);l.prototype.post.call(this,o)},u})(r);return E.ErrorSyncEvent=d,E}var w={},B={},et;function k(){if(et)return B;et=1,Object.defineProperty(B,"__esModule",{value:!0});var e=Q(),c=(function(){function r(){this.evtFilled=new e.SyncEvent,this.evtDrained=new e.SyncEvent,this._queue=[],this._flushing=!1}return r.global=function(){return r._instance||r.resetGlobal(),r._instance},r.resetGlobal=function(){r._instance=new r},r.prototype.empty=function(){return this._queue.length===0},r.prototype.add=function(h){this._queue.push(h),this._queue.length===1&&!this._flushing&&this.evtFilled.post(this)},r.prototype.flushOnce=function(){var h=this._queue.length===0,d=this._flushing;this._flushing=!0;try{var l=this._queue;this._queue=[];for(var u=0;u<l.length;++u)l[u]()}finally{this._flushing=d,!h&&!d&&this._queue.length===0&&this.evtDrained.post(this)}},r.prototype.flush=function(h){h===void 0&&(h=10);var d=this._queue.length===0,l=this._flushing;this._flushing=!0;try{for(var u=0;this._queue.length>0;){if(typeof h=="number"&&u>=h)throw this._queue=[],new Error("unable to flush the queue due to recursively added event. Clearing queue now");this.flushOnce(),++u}}finally{this._flushing=l,!d&&!l&&this._queue.length===0&&this.evtDrained.post(this)}},r})();return B.default=c,B}var nt;function lt(){if(nt)return w;nt=1;var e=w&&w.__extends||(function(){var o=function(i,a){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var s in t)t.hasOwnProperty(s)&&(n[s]=t[s])},o(i,a)};return function(i,a){o(i,a);function n(){this.constructor=i}i.prototype=a===null?Object.create(a):(n.prototype=a.prototype,new n)}})();Object.defineProperty(w,"__esModule",{value:!0}),w.ErrorQueuedEvent=w.VoidQueuedEvent=w.QueuedEvent=void 0;var c=V(),r=k(),h=Q(),d=(function(o){e(i,o);function i(a){a===void 0&&(a={});var n=o.call(this)||this;return n._queued=!1,n.options=a,typeof a.condensed=="boolean"?n._condensed=a.condensed:n._condensed=!1,typeof a.queue=="object"&&a.queue!==null&&(n._queue=a.queue),n}return Object.defineProperty(i.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new h.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),i.prototype.post=function(){for(var a=this,n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(!(!this._listeners||this._listeners.length===0)){var s=this._queue?this._queue:r.default.global();if(this._condensed){if(this._queuedData=n,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,s.add(function(){a._queued=!1;for(var v=a._queuedData,y=a._queuedListeners,p=0;p<y.length;++p){var g=y[p];a._call(g,v)}})}else{var f=this._listeners;s.add(function(){for(var v=0;v<f.length;++v){var y=f[v];a._call(y,n)}})}}},i.prototype._attach=function(a,n,t){var s,f,v,y,p=(f=(s=this._listeners)===null||s===void 0?void 0:s.length)!==null&&f!==void 0?f:0,g=o.prototype._attach.call(this,a,n,t);return this.evtListenersChanged&&p!==((y=(v=this._listeners)===null||v===void 0?void 0:v.length)!==null&&y!==void 0?y:0)&&this.evtListenersChanged.post(),g},i.prototype._detach=function(){for(var a,n,t,s,f=[],v=0;v<arguments.length;v++)f[v]=arguments[v];var y=(n=(a=this._listeners)===null||a===void 0?void 0:a.length)!==null&&n!==void 0?n:0,p=o.prototype._detach.apply(this,f);return this.evtListenersChanged&&y!==((s=(t=this._listeners)===null||t===void 0?void 0:t.length)!==null&&s!==void 0?s:0)&&this.evtListenersChanged.post(),p},i})(c.BaseEvent);w.QueuedEvent=d;var l=(function(o){e(i,o);function i(){return o!==null&&o.apply(this,arguments)||this}return i.prototype.post=function(){o.prototype.post.call(this,void 0)},i})(d);w.VoidQueuedEvent=l;var u=(function(o){e(i,o);function i(){return o!==null&&o.apply(this,arguments)||this}return i.prototype.post=function(a){if(!this._listeners||this._listeners.length===0)throw new Error("error event posted while no listeners attached. Error: "+a.message);o.prototype.post.call(this,a)},i})(d);return w.ErrorQueuedEvent=u,w}var C={},rt;function ft(){if(rt)return C;rt=1;var e=C&&C.__extends||(function(){var u=function(o,i){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,n){a.__proto__=n}||function(a,n){for(var t in n)n.hasOwnProperty(t)&&(a[t]=n[t])},u(o,i)};return function(o,i){u(o,i);function a(){this.constructor=o}o.prototype=i===null?Object.create(i):(a.prototype=i.prototype,new a)}})();Object.defineProperty(C,"__esModule",{value:!0}),C.ErrorAsyncEvent=C.VoidAsyncEvent=C.AsyncEvent=void 0;var c=V(),r=Q(),h=(function(u){e(o,u);function o(i){i===void 0&&(i={});var a=u.call(this)||this;return a._queued=!1,a.options=i,typeof i.condensed=="boolean"?a._condensed=i.condensed:a._condensed=!1,a}return Object.defineProperty(o.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new r.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),o.defaultScheduler=function(i){typeof window<"u"?setTimeout(i,0):setImmediate(i)},o.setScheduler=function(i){o._scheduler=i},o.prototype.post=function(){for(var i=this,a=[],n=0;n<arguments.length;n++)a[n]=arguments[n];if(!(!this._listeners||this._listeners.length===0))if(this._condensed){if(this._queuedData=a,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,o._scheduler(function(){i._queued=!1;for(var s=i._queuedData,f=i._queuedListeners,v=0;v<f.length;++v){var y=f[v];i._call(y,s)}})}else{var t=this._listeners;o._scheduler(function(){for(var s=0;s<t.length;++s){var f=t[s];i._call(f,a)}})}},o.prototype._call=function(i,a){i.event&&i.event instanceof o?i.event._postDirect(a):u.prototype._call.call(this,i,a)},o.prototype._postDirect=function(i){if(!(!this._listeners||this._listeners.length===0))for(var a=this._listeners,n=0;n<a.length;++n){var t=a[n];this._call(t,i)}},o.prototype._attach=function(i,a,n){var t,s,f,v,y=(s=(t=this._listeners)===null||t===void 0?void 0:t.length)!==null&&s!==void 0?s:0,p=u.prototype._attach.call(this,i,a,n);return this.evtListenersChanged&&y!==((v=(f=this._listeners)===null||f===void 0?void 0:f.length)!==null&&v!==void 0?v:0)&&this.evtListenersChanged.post(),p},o.prototype._detach=function(){for(var i,a,n,t,s=[],f=0;f<arguments.length;f++)s[f]=arguments[f];var v=(a=(i=this._listeners)===null||i===void 0?void 0:i.length)!==null&&a!==void 0?a:0,y=u.prototype._detach.apply(this,s);return this.evtListenersChanged&&v!==((t=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&t!==void 0?t:0)&&this.evtListenersChanged.post(),y},o._scheduler=o.defaultScheduler,o})(c.BaseEvent);C.AsyncEvent=h;var d=(function(u){e(o,u);function o(){return u!==null&&u.apply(this,arguments)||this}return o.prototype.post=function(){u.prototype.post.call(this,void 0)},o})(h);C.VoidAsyncEvent=d;var l=(function(u){e(o,u);function o(){return u!==null&&u.apply(this,arguments)||this}return o.prototype.post=function(i){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+i.message);u.prototype.post.call(this,i)},o})(h);return C.ErrorAsyncEvent=l,C}var D={},P={},st;function Lt(){if(st)return P;st=1,Object.defineProperty(P,"__esModule",{value:!0}),P.shallowEquals=void 0;function e(c,r){if(c===r)return!0;if(typeof c!=typeof r)return!1;switch(typeof c){case"boolean":case"number":case"string":case"function":case"symbol":case"undefined":return!1;case"object":if(c===null||r===null)return!1;if(Array.isArray(c)||Array.isArray(r)){if(!Array.isArray(c)||!Array.isArray(r)||c.length!==r.length)return!1;for(var h=0;h<c.length;++h)if(c[h]!==r[h])return!1;return!0}var d=[],l=[];for(var u in c)c.hasOwnProperty(u)&&d.push(u);for(var o in r)r.hasOwnProperty(o)&&l.push(o);if(d.sort(),l.sort(),d.join(",")!==l.join(","))return!1;for(var h=0;h<d.length;++h)if(c[d[h]]!==r[d[h]])return!1;return!0;default:return!1}}return P.shallowEquals=e,P}var it;function jt(){return it||(it=1,(function(e){var c=D&&D.__extends||(function(){var n=function(t,s){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(f,v){f.__proto__=v}||function(f,v){for(var y in v)v.hasOwnProperty(y)&&(f[y]=v[y])},n(t,s)};return function(t,s){n(t,s);function f(){this.constructor=t}t.prototype=s===null?Object.create(s):(f.prototype=s.prototype,new f)}})();Object.defineProperty(e,"__esModule",{value:!0}),e.ErrorAnyEvent=e.VoidAnyEvent=e.AnyEvent=e.EventType=void 0;var r=Lt(),h=Q(),d=ft(),l=lt(),u;(function(n){n[n.Sync=0]="Sync",n[n.Async=1]="Async",n[n.Queued=2]="Queued"})(u=e.EventType||(e.EventType={}));var o=(function(){function n(t){this._events=[],t&&t.monitorAttach&&(this.evtFirstAttached=new i,this.evtLastDetached=new i)}return Object.defineProperty(n.prototype,"evtListenersChanged",{get:function(){return this._listenersChanged||(this._listenersChanged=new h.VoidSyncEvent),this._listenersChanged},enumerable:!1,configurable:!0}),n.prototype.attach=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];var f=u.Sync;t.length>0&&typeof t[0]=="number"&&(f=t.shift());var v=this,y,p,g;return typeof t[0]=="function"||t[0]&&typeof t[0]=="object"&&typeof t[0].post=="function"?(typeof t[0]=="function"?y=t[0]:g=t[0],p=t[1]):(v=t[0],y=t[1],p=t[2]),this._attach(f,v,y,g,p,!1)},n.prototype.once=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];var f=u.Sync;t.length>0&&typeof t[0]=="number"&&(f=t.shift());var v=this,y,p,g;return typeof t[0]=="function"||t[0]&&typeof t[0]=="object"&&typeof t[0].post=="function"?(typeof t[0]=="function"?y=t[0]:g=t[0],p=t[1]):(v=t[0],y=t[1],p=t[2]),this._attach(f,v,y,g,p,!0)},n.prototype._attach=function(t,s,f,v,y,p){var g=this,z=this.evtFirstAttached?this.listenerCount():0,_;switch(t){case u.Sync:{for(var R=0,K=this._events;R<K.length;R++){var m=K[R];m instanceof h.SyncEvent&&(_=m)}_||(_=new h.SyncEvent,this._events.push(_))}break;case u.Async:{for(var I=0,W=this._events;I<W.length;I++){var m=W[I];m instanceof d.AsyncEvent&&r.shallowEquals(m.options,y)&&(_=m)}_||(_=new d.AsyncEvent(y),this._events.push(_))}break;case u.Queued:{for(var N=0,Z=this._events;N<Z.length;N++){var m=Z[N];m instanceof l.QueuedEvent&&r.shallowEquals(m.options,y)&&(_=m)}_||(_=new l.QueuedEvent(y),this._events.push(_))}break;default:throw new Error("unknown EventType")}var q;return p?v?q=_.once(v):q=_.once(s,f):v?q=_.attach(v):q=_.attach(s,f),this.evtFirstAttached&&z===0&&this.evtFirstAttached.post(),this.evtListenersChanged&&z!==this.listenerCount()&&this.evtListenersChanged.post(),function(){var J=g.evtLastDetached?g.listenerCount():0;q(),g.evtLastDetached&&J>0&&g.listenerCount()===0&&g.evtLastDetached.post(),g.evtListenersChanged&&J!==g.listenerCount()&&g.evtListenersChanged.post()}},n.prototype.attachSync=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];return t.unshift(u.Sync),this.attach.apply(this,t)},n.prototype.onceSync=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];return t.unshift(u.Sync),this.once.apply(this,t)},n.prototype.attachAsync=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];return t.unshift(u.Async),this.attach.apply(this,t)},n.prototype.onceAsync=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];return t.unshift(u.Async),this.once.apply(this,t)},n.prototype.attachQueued=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];return t.unshift(u.Queued),this.attach.apply(this,t)},n.prototype.onceQueued=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];return t.unshift(u.Queued),this.once.apply(this,t)},n.prototype.detach=function(){for(var t=[],s=0;s<arguments.length;s++)t[s]=arguments[s];for(var f=this.listenerCount(),v=0;v<this._events.length;++v)this._events[v].detach.apply(this._events[v],t);this.evtListenersChanged&&f!==this.listenerCount()&&this.evtListenersChanged.post(),this.evtLastDetached&&f>0&&this.listenerCount()===0&&this.evtLastDetached.post()},n.prototype.post=function(t){for(var s=[],f=0;f<this._events.length;++f)s.push(this._events[f]);for(var f=0;f<s.length;++f)s[f].post(t)},n.prototype.listenerCount=function(){for(var t=0,s=0;s<this._events.length;++s)t+=this._events[s].listenerCount();return t},n})();e.AnyEvent=o;var i=(function(n){c(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.post=function(){n.prototype.post.call(this,void 0)},t})(o);e.VoidAnyEvent=i;var a=(function(n){c(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.post=function(s){if(this.listenerCount()===0)throw new Error("error event posted while no listeners attached. Error: "+s.message);n.prototype.post.call(this,s)},t})(o);e.ErrorAnyEvent=a})(D)),D}var ot;function Qt(){return ot||(ot=1,(function(e){var c=b&&b.__createBinding||(Object.create?(function(i,a,n,t){t===void 0&&(t=n),Object.defineProperty(i,t,{enumerable:!0,get:function(){return a[n]}})}):(function(i,a,n,t){t===void 0&&(t=n),i[t]=a[n]})),r=b&&b.__exportStar||function(i,a){for(var n in i)n!=="default"&&!a.hasOwnProperty(n)&&c(a,i,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.flush=e.flushOnce=e.queue=void 0,r(V(),e),r(Q(),e),r(lt(),e),r(ft(),e),r(jt(),e);var h=k(),d=k();Object.defineProperty(e,"EventQueue",{enumerable:!0,get:function(){return d.default}});function l(){return h.default.global()}e.queue=l;function u(){h.default.global().flushOnce()}e.flushOnce=u;function o(i){i===void 0&&(i=10),h.default.global().flush(i)}e.flush=o})(b)),b}var S=Qt();class vt{id;data;constructor(c,r){this.id=c,this.data=r}}const{serviceUuid:Mt,messageCharUuid:Bt}=G(),dt=new S.SyncEvent,yt=new S.SyncEvent,pt=new S.SyncEvent,gt=new S.SyncEvent;function Tt(){return new Promise((e,c)=>{X().subscribe(Mt,Bt,Ut).then(()=>e()).catch(r=>c(r))})}function Ut(e){e!==void 0&&(e.getUint8(A.Data.TYPE)===A.DataType.BUTTON_PRESS&&Vt(e),e.getUint8(A.Data.TYPE)===A.DataType.MESSAGE_DONE&&gt.post(e.getUint8(A.Data.DATA)))}function Vt(e){const c=e.getUint8(A.Data.DATA),r=new vt(e.getUint8(A.Data.ID),Rt(e));c===A.Button.MINUS&&yt.post(r),c===A.Button.PLUS&&dt.post(r),c===A.Button.EITHER&&pt.post(r)}function Rt(e){const c=e.buffer,r=7,h=e.byteLength-7;return Array.from(new Uint8Array(c,r,h)).map(d=>String.fromCharCode(d)).join("").replace(/\0/g,"").trim()}function _t(){return{subscribe:Tt,onPlusButton:dt,onMinButton:yt,onEitherButton:pt,onMessageDone:gt}}const j=[];function It(){let e=Math.floor(Math.random()*256);for(;j.includes(e);)e=Math.floor(Math.random()*256);return e}function Nt(e){j.push(e),kt()}function kt(){j.length<=20||j.splice(0,j.length-20)}function $t(){const e=It();return Nt(e),e}function Ft(){return{create:$t}}const{serviceUuid:Ht,messageCharUuid:Xt}=G(),{onMessageDone:Gt}=_t(),Yt=X(),Et=[],$=new Map;let L=!1;Gt.attach(Kt);function zt(e){return e.packets.forEach(c=>Et.push(c)),new Promise(c=>{$.set(e.cache,c),L||Y()})}function Y(){if(L)return;const e=Et.shift();if(e==null){L=!1;return}L=!0,Yt.writeCharacteristic(Ht,Xt,e).catch(c=>console.log(c)).finally(()=>{L=!1,Y()})}function Kt(e){$.get(e)?.(),$.delete(e),Y()}function Wt(){return{write:zt}}const at=10,ut=15;function Zt(e){if(e.data==null){let d=[e.id,e.cache,at,0,2,e.type,0];return[new Uint8Array(d)]}const c=new Uint8Array(2+e.data.length),r=e.data.length+2,h=[];c.set([e.type,r],0),c.set(e.data,2);for(let d=0;d<r;d+=ut){const l=Math.min(ut,r-d),u=new Uint8Array(l),o=[e.id,e.cache,at,d,r];u.set(c.subarray(d,d+l),0),h.push(new Uint8Array([...o,...u]))}return h}class Jt{cache=Ft().create();type;id;data;packets=[];constructor(c,r,h){this.type=c,this.id=r,this.data=h,this.packets=Zt(this)}send(){return Wt().write(this)}}class xt{id;elements=[];onPlus=new S.SyncEvent;onMin=new S.SyncEvent;constructor(c){this.id=c}name(){return this.id.toString(16).padStart(2,"0")}}exports.Buffer=Jt;exports.ButtonResult=vt;exports.Standee=xt;exports.libExports=S;exports.useBluetooth=X;exports.useBluetoothSettings=G;exports.useMessageCharacteristic=_t;