nsd-ble 0.2.2 → 0.3.0
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/{Objects-RyXOt964.js → Objects-CyxYK6wR.js} +7 -1
- package/dist/{Objects-CS29rf_8.cjs → Objects-wXbKCjWg.cjs} +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.js +1 -1
- package/dist/objects.cjs +1 -1
- package/dist/objects.js +1 -1
- package/dist/types/ble/Buffer.d.ts +2 -0
- package/package.json +1 -1
|
@@ -796,7 +796,9 @@ let D = !1;
|
|
|
796
796
|
ze.attach(Ze);
|
|
797
797
|
function We(t) {
|
|
798
798
|
return t.packets.forEach((c) => Ee.push(c)), new Promise((c) => {
|
|
799
|
-
F.set(t.cache,
|
|
799
|
+
F.set(t.cache, () => {
|
|
800
|
+
t.resolve?.(), c();
|
|
801
|
+
}), D || G();
|
|
800
802
|
});
|
|
801
803
|
}
|
|
802
804
|
function G() {
|
|
@@ -837,12 +839,16 @@ class tt {
|
|
|
837
839
|
id;
|
|
838
840
|
data;
|
|
839
841
|
packets = [];
|
|
842
|
+
resolve;
|
|
840
843
|
constructor(c, r, h) {
|
|
841
844
|
this.type = c, this.id = r, this.data = h, this.packets = xe(this);
|
|
842
845
|
}
|
|
843
846
|
send() {
|
|
844
847
|
return Je().write(this);
|
|
845
848
|
}
|
|
849
|
+
then(c) {
|
|
850
|
+
return this.resolve = c, this;
|
|
851
|
+
}
|
|
846
852
|
}
|
|
847
853
|
class nt {
|
|
848
854
|
id;
|
|
@@ -1 +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&>.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;
|
|
1
|
+
"use strict";const A=require("./enums.cjs");let F=!1,U=[],M,ce,T=new Map;async function we(t){try{if(M=await navigator.bluetooth.requestDevice(t),M.gatt===void 0)throw new Error("Device does not support GATT");ce=await M.gatt.connect(),M.addEventListener("gattserverdisconnected",Ce),F=!0}catch(c){throw c}}function Ce(){T.clear(),F=!1,U.forEach(t=>t())}function me(t){U.push(t)}function Ae(t){U=U.filter(c=>c!==t)}async function H(t,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 ce.getPrimaryService(t)).getCharacteristic(c);return T.set(c,h),h}async function be(t,c){return await(await H(t,c)).readValue()}async function Se(t,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(t,c)).writeValue(h)}async function qe(t,c,r){const h=await H(t,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:we,readCharacteristic:be,writeCharacteristic:Se,subscribe:qe,setDisconnectCallback:me,removeDisconnectCallback:Ae}}const he="19b10000-e8f2-537e-4f6c-d104768a1214",Oe="6b061bdc-9bc1-4952-a96f-c6ed551b2c3e",De="998ff920-81af-42a9-a915-f88025f9647d",Pe={filters:[{namePrefix:"BLE-STANDEE"}],optionalServices:[he]};function G(){return{serviceUuid:he,messageCharUuid:Oe,handshakeCharUuid:De,options:Pe}}var b={},O={},x;function V(){if(x)return O;x=1,Object.defineProperty(O,"__esModule",{value:!0}),O.BaseEvent=void 0;var t=(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=t,O}var E={},ee;function Q(){if(ee)return E;ee=1;var t=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){t(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 e=a[n];this._call(e,o)}this._recursion--}},u.prototype._attach=function(o,i,a){var n,e,s,f,v=(e=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&e!==void 0?e: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,e=[],s=0;s<arguments.length;s++)e[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,e);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){t(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){t(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={},te;function k(){if(te)return B;te=1,Object.defineProperty(B,"__esModule",{value:!0});var t=Q(),c=(function(){function r(){this.evtFilled=new t.SyncEvent,this.evtDrained=new t.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 ne;function le(){if(ne)return w;ne=1;var t=w&&w.__extends||(function(){var o=function(i,a){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,e){n.__proto__=e}||function(n,e){for(var s in e)e.hasOwnProperty(s)&&(n[s]=e[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){t(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=[],e=0;e<arguments.length;e++)n[e]=arguments[e];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,e){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,e);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,e,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=(e=this._listeners)===null||e===void 0?void 0:e.length)!==null&&s!==void 0?s:0)&&this.evtListenersChanged.post(),p},i})(c.BaseEvent);w.QueuedEvent=d;var l=(function(o){t(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){t(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={},re;function fe(){if(re)return C;re=1;var t=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 e in n)n.hasOwnProperty(e)&&(a[e]=n[e])},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){t(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 e=this._listeners;o._scheduler(function(){for(var s=0;s<e.length;++s){var f=e[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 e=a[n];this._call(e,i)}},o.prototype._attach=function(i,a,n){var e,s,f,v,y=(s=(e=this._listeners)===null||e===void 0?void 0:e.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,e,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!==((e=(n=this._listeners)===null||n===void 0?void 0:n.length)!==null&&e!==void 0?e:0)&&this.evtListenersChanged.post(),y},o._scheduler=o.defaultScheduler,o})(c.BaseEvent);C.AsyncEvent=h;var d=(function(u){t(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){t(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={},se;function Le(){if(se)return P;se=1,Object.defineProperty(P,"__esModule",{value:!0}),P.shallowEquals=void 0;function t(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=t,P}var ie;function je(){return ie||(ie=1,(function(t){var c=D&&D.__extends||(function(){var n=function(e,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(e,s)};return function(e,s){n(e,s);function f(){this.constructor=e}e.prototype=s===null?Object.create(s):(f.prototype=s.prototype,new f)}})();Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorAnyEvent=t.VoidAnyEvent=t.AnyEvent=t.EventType=void 0;var r=Le(),h=Q(),d=fe(),l=le(),u;(function(n){n[n.Sync=0]="Sync",n[n.Async=1]="Async",n[n.Queued=2]="Queued"})(u=t.EventType||(t.EventType={}));var o=(function(){function n(e){this._events=[],e&&e.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 e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];var f=u.Sync;e.length>0&&typeof e[0]=="number"&&(f=e.shift());var v=this,y,p,g;return typeof e[0]=="function"||e[0]&&typeof e[0]=="object"&&typeof e[0].post=="function"?(typeof e[0]=="function"?y=e[0]:g=e[0],p=e[1]):(v=e[0],y=e[1],p=e[2]),this._attach(f,v,y,g,p,!1)},n.prototype.once=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];var f=u.Sync;e.length>0&&typeof e[0]=="number"&&(f=e.shift());var v=this,y,p,g;return typeof e[0]=="function"||e[0]&&typeof e[0]=="object"&&typeof e[0].post=="function"?(typeof e[0]=="function"?y=e[0]:g=e[0],p=e[1]):(v=e[0],y=e[1],p=e[2]),this._attach(f,v,y,g,p,!0)},n.prototype._attach=function(e,s,f,v,y,p){var g=this,z=this.evtFirstAttached?this.listenerCount():0,_;switch(e){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 e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(u.Sync),this.attach.apply(this,e)},n.prototype.onceSync=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(u.Sync),this.once.apply(this,e)},n.prototype.attachAsync=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(u.Async),this.attach.apply(this,e)},n.prototype.onceAsync=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(u.Async),this.once.apply(this,e)},n.prototype.attachQueued=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(u.Queued),this.attach.apply(this,e)},n.prototype.onceQueued=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];return e.unshift(u.Queued),this.once.apply(this,e)},n.prototype.detach=function(){for(var e=[],s=0;s<arguments.length;s++)e[s]=arguments[s];for(var f=this.listenerCount(),v=0;v<this._events.length;++v)this._events[v].detach.apply(this._events[v],e);this.evtListenersChanged&&f!==this.listenerCount()&&this.evtListenersChanged.post(),this.evtLastDetached&&f>0&&this.listenerCount()===0&&this.evtLastDetached.post()},n.prototype.post=function(e){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(e)},n.prototype.listenerCount=function(){for(var e=0,s=0;s<this._events.length;++s)e+=this._events[s].listenerCount();return e},n})();t.AnyEvent=o;var i=(function(n){c(e,n);function e(){return n!==null&&n.apply(this,arguments)||this}return e.prototype.post=function(){n.prototype.post.call(this,void 0)},e})(o);t.VoidAnyEvent=i;var a=(function(n){c(e,n);function e(){return n!==null&&n.apply(this,arguments)||this}return e.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)},e})(o);t.ErrorAnyEvent=a})(D)),D}var oe;function Qe(){return oe||(oe=1,(function(t){var c=b&&b.__createBinding||(Object.create?(function(i,a,n,e){e===void 0&&(e=n),Object.defineProperty(i,e,{enumerable:!0,get:function(){return a[n]}})}):(function(i,a,n,e){e===void 0&&(e=n),i[e]=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(t,"__esModule",{value:!0}),t.flush=t.flushOnce=t.queue=void 0,r(V(),t),r(Q(),t),r(le(),t),r(fe(),t),r(je(),t);var h=k(),d=k();Object.defineProperty(t,"EventQueue",{enumerable:!0,get:function(){return d.default}});function l(){return h.default.global()}t.queue=l;function u(){h.default.global().flushOnce()}t.flushOnce=u;function o(i){i===void 0&&(i=10),h.default.global().flush(i)}t.flush=o})(b)),b}var S=Qe();class ve{id;data;constructor(c,r){this.id=c,this.data=r}}const{serviceUuid:Me,messageCharUuid:Be}=G(),de=new S.SyncEvent,ye=new S.SyncEvent,pe=new S.SyncEvent,ge=new S.SyncEvent;function Te(){return new Promise((t,c)=>{X().subscribe(Me,Be,Ue).then(()=>t()).catch(r=>c(r))})}function Ue(t){t!==void 0&&(t.getUint8(A.Data.TYPE)===A.DataType.BUTTON_PRESS&&Ve(t),t.getUint8(A.Data.TYPE)===A.DataType.MESSAGE_DONE&&ge.post(t.getUint8(A.Data.DATA)))}function Ve(t){const c=t.getUint8(A.Data.DATA),r=new ve(t.getUint8(A.Data.ID),Re(t));c===A.Button.MINUS&&ye.post(r),c===A.Button.PLUS&&de.post(r),c===A.Button.EITHER&&pe.post(r)}function Re(t){const c=t.buffer,r=7,h=t.byteLength-7;return Array.from(new Uint8Array(c,r,h)).map(d=>String.fromCharCode(d)).join("").replace(/\0/g,"").trim()}function _e(){return{subscribe:Te,onPlusButton:de,onMinButton:ye,onEitherButton:pe,onMessageDone:ge}}const j=[];function Ie(){let t=Math.floor(Math.random()*256);for(;j.includes(t);)t=Math.floor(Math.random()*256);return t}function Ne(t){j.push(t),ke()}function ke(){j.length<=20||j.splice(0,j.length-20)}function $e(){const t=Ie();return Ne(t),t}function Fe(){return{create:$e}}const{serviceUuid:He,messageCharUuid:Xe}=G(),{onMessageDone:Ge}=_e(),Ye=X(),Ee=[],$=new Map;let L=!1;Ge.attach(Ke);function ze(t){return t.packets.forEach(c=>Ee.push(c)),new Promise(c=>{$.set(t.cache,()=>{t.resolve?.(),c()}),L||Y()})}function Y(){if(L)return;const t=Ee.shift();if(t==null){L=!1;return}L=!0,Ye.writeCharacteristic(He,Xe,t).catch(c=>console.log(c)).finally(()=>{L=!1,Y()})}function Ke(t){$.get(t)?.(),$.delete(t),Y()}function We(){return{write:ze}}const ae=10,ue=15;function Ze(t){if(t.data==null){let d=[t.id,t.cache,ae,0,2,t.type,0];return[new Uint8Array(d)]}const c=new Uint8Array(2+t.data.length),r=t.data.length+2,h=[];c.set([t.type,r],0),c.set(t.data,2);for(let d=0;d<r;d+=ue){const l=Math.min(ue,r-d),u=new Uint8Array(l),o=[t.id,t.cache,ae,d,r];u.set(c.subarray(d,d+l),0),h.push(new Uint8Array([...o,...u]))}return h}class Je{cache=Fe().create();type;id;data;packets=[];resolve;constructor(c,r,h){this.type=c,this.id=r,this.data=h,this.packets=Ze(this)}send(){return We().write(this)}then(c){return this.resolve=c,this}}class xe{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=Je;exports.ButtonResult=ve;exports.Standee=xe;exports.libExports=S;exports.useBluetooth=X;exports.useBluetoothSettings=G;exports.useMessageCharacteristic=_e;
|
package/dist/main.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./Objects-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./Objects-wXbKCjWg.cjs"),o=require("./enums.cjs"),w=require("./elements.cjs"),{serviceUuid:S,handshakeCharUuid:b}=a.useBluetoothSettings(),E=new a.libExports.SyncEvent,D=new a.libExports.SyncEvent;function R(){return new Promise((t,e)=>{a.useBluetooth().subscribe(S,b,v).then(()=>t()).catch(n=>e(n))})}function v(t){t.getUint8(o.Data.TYPE)===o.HandshakeType.CONNECT&&E.post(t),t.getUint8(o.Data.TYPE)===o.HandshakeType.DISCONNECT&&D.post(t)}function m(){return{subscribe:R,onConnected:E,onDisconnected:D}}const{onConnected:_}=m(),{onDisconnected:M}=m(),{onPlusButton:N,onMinButton:P,onEitherButton:L}=a.useMessageCharacteristic();function k(){return new Promise((t,e)=>{a.useBluetooth().connect(a.useBluetoothSettings().options).then(()=>Promise.all([m().subscribe(),a.useMessageCharacteristic().subscribe()]).then(()=>{t()})).catch(n=>e(n))})}function U(){return{connect:k,onConnected:_,onDisconnected:M,onPlusButton:N,onMinButton:P,onEitherButton:L}}function H(t){return{upload:(e,n)=>{const r=new Uint8Array(n.length+1);return r.set([e],0),r.set(n,1),new a.Buffer(o.DataType.UPLOAD,t.id,r)},clear:()=>new a.Buffer(o.DataType.CLEAR_GRAPHICS,t.id)}}class O{id;buffers;totalPackets=0;constructor(e,n){this.id=n,this.buffers=e,this.buffers.forEach(r=>this.totalPackets+=r.packets.length)}async send(){const e=new Uint8Array([this.totalPackets]);await new a.Buffer(o.DataType.LOADER,this.id,e).send(),await Promise.all(this.buffers.map(r=>r.send()))}}function $(t){return{load:e=>new O(e,t.id)}}const{onConnected:G,onDisconnected:V}=U();G.attach(W);V.attach(q);const d=[],T=new a.libExports.SyncEvent;function W(t){const e=new Uint8Array(t.buffer,6);for(const n of e)j(n);T.post(d)}function q(t){const e=t.getUint8(2);Y(e),T.post(d)}function j(t){d.some(e=>e.id===t)||d.push(new a.Standee(t))}function Y(t){const e=d.findIndex(n=>n.id===t);e!==-1&&d.splice(e,1)}function z(){return{standees:d,onChange:T}}function F(t){const e=()=>{let r=Math.floor(Math.random()*256);return n(r)?e():r},n=r=>t.some(s=>s.id===r);return{generate:e}}function K(t){return{add:r=>(r.id=F(t.elements).generate(),t.elements.push(r),r),remove:r=>{t.elements=t.elements.filter(s=>s.id!==r)}}}function X(t){return new a.Buffer(o.DataType.CLEAR_SCREEN,t.id)}function J(t){let e=new Uint8Array;for(const n of t.elements)n.dirty!==!1&&(n instanceof w.Image&&(e=A(e,Q(n))),n instanceof w.Rectangle&&(e=A(e,Z(n))),n instanceof w.Text&&(e=A(e,tt(n))),n.dirty=!1);return new a.Buffer(o.DataType.ALL,t.id,e)}function A(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function Q(t){return new Uint8Array([o.DataType.DRAW_IMAGE,7,t.id,t.show?1:0,t.x,t.y,t.width,t.height,t.data])}function Z(t){return new Uint8Array([o.DataType.DRAW_RECTANGLE,9,t.id,t.show?1:0,t.x,t.y,t.width,t.height,t.radius,t.fill?1:0,t.colorBlack?0:1])}function tt(t){const e=new TextEncoder().encode(t.text),n=new Uint8Array(9+e.length);return n.set([o.DataType.DRAW_TEXT,7+e.length,t.id,t.show?1:0,t.x,t.y,t.font,t.colorBlack?0:1,t.center?1:0],0),n.set(e,9),n}function et(){return{clear:X,draw:J}}function nt(t,e){const n=Math.ceil(t.length/e),r=Math.ceil(e/8),s=new Uint8Array(r*n);for(let i=0;i<n;i++)for(let c=0;c<r;c++){let h=0;for(let l=0;l<8;l++){const y=c*8+l,g=i*e+y;y<e&&g<t.length&&t[g]&&(h|=1<<7-l)}s[i*r+c]=x(h)}return s}function x(t){return t=(t&240)>>4|(t&15)<<4,t=(t&204)>>2|(t&51)<<2,t=(t&170)>>1|(t&85)<<1,t}function rt(t){const e=t.reduce((s,i)=>s+i.length,0),n=new Uint8Array(e);let r=0;for(const s of t)n.set(s,r),r+=s.length;return n}function p(){return{pixelsToBytes:nt,bitswap:x,flattenUint8Arrays:rt}}const{flattenUint8Arrays:B}=p();class f{element_id;property;constructor(e,n){this.element_id=e,this.property=n}}class u{target;constructor(e){this.target=e}format(){return new Uint8Array}}class st extends u{format(){return new Uint8Array([o.ActionType.INCREMENT,2,this.target.element_id,this.target.property])}}class ot extends u{format(){return new Uint8Array([o.ActionType.DECREMENT,2,this.target.element_id,this.target.property])}}class it extends u{format(){return new Uint8Array([o.ActionType.SHOW,1,this.target.element_id])}}class at extends u{format(){return new Uint8Array([o.ActionType.HIDE,1,this.target.element_id])}}class ct extends u{value;constructor(e,n){super(e),this.value=n}format(){const e=this.dataType(),n=this.convertValue(e),r=new Uint8Array(5+n.length),s=[o.ActionType.SET,n.length+3,e,this.target.element_id,this.target.property];return r.set(s,0),r.set(n,5),r}dataType(){return typeof this.value==="string"?o.ActionDataType.STRING:o.ActionDataType.NUMBER}convertValue(e){return e===o.ActionDataType.STRING?new TextEncoder().encode(this.value):e===o.ActionDataType.NUMBER?new Uint8Array([this.value]):new Uint8Array}}class ut extends u{format(){return this.target.element_id!==0&&this.target.property!==0?new Uint8Array([o.ActionType.BROADCAST,2,this.target.element_id,this.target.property]):new Uint8Array([o.ActionType.BROADCAST,0])}}class ht extends u{format(){return new Uint8Array([o.ActionType.BREAK,0])}}class ft extends u{fromLow;fromHigh;toLow;toHigh;value;constructor(e,n,r,s,i,c){super(c),this.value=e,this.fromLow=n,this.fromHigh=r,this.toLow=s,this.toHigh=i}format(){return new Uint8Array([o.ActionType.MAP,8,this.value.element_id,this.value.property,this.fromLow,this.fromHigh,this.toLow,this.toHigh,this.target.element_id,this.target.property])}}class dt extends u{deciseconds;resetable;onComplete;constructor(e,n,r){super(new f(0,0)),this.deciseconds=e,this.resetable=n,this.onComplete=r}format(){const e=B(this.onComplete.map(s=>s.format())),n=new Uint8Array(4+e.length),r=[o.ActionType.TIMER,e.length+2,this.resetable?1:0,this.deciseconds];return n.set(r,0),e.forEach((s,i)=>n.set([s],i+4)),n}}class lt extends u{left;operator;right;actions;constructor(e,n,r,s){super(new f(0,0)),this.actions=s,this.left=e,this.operator=n,this.right=r}convertValue(e){if(typeof e=="number")return new Uint8Array([o.ActionDataType.NUMBER,1,e]);if(typeof e=="string"){const n=new TextEncoder().encode(e);return new Uint8Array([o.ActionDataType.STRING,n.length,...n])}return e instanceof f?new Uint8Array([o.ActionDataType.ELEMENT,2,e.element_id,e.property]):new Uint8Array}format(){const e=B(this.actions.map(h=>h.format())),n=this.convertValue(this.left),r=this.convertValue(this.right),s=4+n.length+r.length+e.length,i=new Uint8Array(s),c=[o.ActionType.CONDITION,s-2,n.length+r.length+1];return i.set(c,0),i.set([this.operator],3),i.set(n,4),i.set(r,4+n.length),i.set(e,4+n.length+r.length),i}}function yt(){return{target(t,e){return new f(t,e)},increment(t){return new st(t)},decrement(t){return new ot(t)},show(t){return new it(new f(t,0))},hide(t){return new at(new f(t,0))},set(t,e){return new ct(t,e)},broadcast(t){return new ut(t||new f(0,0))},timer(t,e,n){return new dt(t,e,n)},stop(){return new ht(new f(0,0))},condition(t,e,n,r){return new lt(t,e,n,r)},map(t,e,n,r,s,i){return new ft(t,e,n,r,s,i)}}}const{flattenUint8Arrays:gt}=p();function pt(t){return{setButton(e,n){const r=gt(n.map(i=>i.format())),s=new Uint8Array(1+r.length);return s.set([e],0),r.forEach((i,c)=>s.set([i],c+1)),new a.Buffer(o.DataType.ACTIONS,t.id,s)}}}function wt(t){return new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=n,r.src=t})}function At(t){const e=document.createElement("canvas"),n=e.getContext("2d");if(e.width=t.width,e.height=t.height,!n)throw new Error("Failed to get 2D context for image data.");return n.drawImage(t,0,0),n.getImageData(0,0,t.width,t.height)}function mt(t){const e=[],n=t.data,r=t.width,s=t.height;for(let i=0;i<s;i++)for(let c=0;c<r;c++){const h=(i*r+c)*4,l=n[h],y=n[h+1],g=n[h+2],I=.2126*l+.7152*y+.0722*g;e.push(I<128?0:1)}return{width:r,height:s,pixels:e}}function C(){return{createImage:wt,getImageData:At,imageDataToPixels:mt}}const{createImage:Tt,getImageData:Et,imageDataToPixels:Dt}=C(),{pixelsToBytes:Ut}=p();function xt(t){return new Promise((e,n)=>{Tt(t).then(r=>Et(r)).then(r=>Dt(r)).then(r=>Ut(r.pixels,r.width)).then(r=>e(r)).catch(r=>n(r))})}function Bt(){return{imageToBytes:xt}}function Ct(t,e,n,r,s){return(t-e)/(n-e)*(s-r)+r}function It(){return{map:Ct}}exports.useActions=yt;exports.useBinary=p;exports.useButtons=pt;exports.useConverter=Bt;exports.useDisplay=et;exports.useGraphics=H;exports.useImage=C;exports.useLoader=$;exports.useMesh=U;exports.useStandeeElements=K;exports.useStandees=z;exports.useUtils=It;
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as A, u as I, a as D, b as B, B as w, S as b } from "./Objects-
|
|
1
|
+
import { l as A, u as I, a as D, b as B, B as w, S as b } from "./Objects-CyxYK6wR.js";
|
|
2
2
|
import { Data as T, HandshakeType as C, DataType as u, ActionType as a, ActionDataType as d } from "./enums.js";
|
|
3
3
|
import { Image as P, Rectangle as M, Text as L } from "./elements.js";
|
|
4
4
|
const { serviceUuid: k, handshakeCharUuid: H } = D(), R = new A.SyncEvent(), S = new A.SyncEvent();
|
package/dist/objects.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Objects-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Objects-wXbKCjWg.cjs");exports.Buffer=e.Buffer;exports.ButtonResult=e.ButtonResult;exports.Standee=e.Standee;
|
package/dist/objects.js
CHANGED